Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check return from NCP when setting channel #1450

Merged
merged 1 commit into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1083,11 +1083,12 @@ public ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel) {
}
if (networkStateUp) {
EmberNcp ncp = getEmberNcp();
ncp.setRadioChannel(channel);
return ncp.setRadioChannel(channel) == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS
: ZigBeeStatus.BAD_RESPONSE;
} else {
networkParameters.setRadioChannel(channel.getChannel());
return ZigBeeStatus.SUCCESS;
}
return ZigBeeStatus.SUCCESS;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,18 @@ public EmberNcp getEmberNcp() {
}

@Test
public void setZigBeeChannel() {
public void setZigBeeChannelOk() {
System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName());
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null);

assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03));
final EmberNcp ncp = Mockito.mock(EmberNcp.class);
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null) {
@Override
public EmberNcp getEmberNcp() {
return ncp;
}
};

Mockito.when(ncp.setRadioChannel(ArgumentMatchers.any())).thenReturn(EmberStatus.EMBER_SUCCESS);

assertEquals(ZigBeeStatus.SUCCESS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_11));
assertEquals(ZigBeeChannel.CHANNEL_11, dongle.getZigBeeChannel());
Expand All @@ -428,13 +435,31 @@ public void setZigBeeChannel() {
assertEquals(ZigBeeChannel.CHANNEL_24, dongle.getZigBeeChannel());
}

@Test
public void setZigBeeChannelError() throws Exception {
System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName());

final EmberNcp ncp = Mockito.mock(EmberNcp.class);
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null) {
@Override
public EmberNcp getEmberNcp() {
return ncp;
}
};

TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "networkStateUp", true);

Mockito.when(ncp.setRadioChannel(ArgumentMatchers.any())).thenReturn(EmberStatus.UNKNOWN);

assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03));
assertEquals(ZigBeeStatus.BAD_RESPONSE, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_24));
}

@Test
public void testEzspMessageSentHandler() throws Exception {
System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName());
ZigBeeTransportReceive transport = Mockito.mock(ZigBeeTransportReceive.class);

final EmberNcp ncp = Mockito.mock(EmberNcp.class);
Mockito.when(ncp.getNwkAddress()).thenReturn(1243);
ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null);
dongle.setZigBeeTransportReceive(transport);

Expand Down
Loading