Skip to content

Commit

Permalink
Merge pull request #16 from giannello/bugfix/wrong-panid-scan-response
Browse files Browse the repository at this point in the history
Wrong PanID in scan responses
  • Loading branch information
giannello authored Feb 12, 2023
2 parents 9a741bc + cec8733 commit cfe439f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
15 changes: 10 additions & 5 deletions features/networkManagement.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@ Feature: Network management

Scenario: Send scan request
When I ask the stick to scan the network for panId "ABCD"
Then the stick responds without errors
Then the stick sends a scan request for panId "ABCD"
And the stick responds without errors

Scenario: Send scan request - force stick timeout
When I ask the stick to scan the network for panId "DED1"
Then the stick responds negatively
Then the stick sends a scan request for panId "DED1"
And the stick responds negatively

Scenario: Send scan response
When I ask the stick to respond to a scan for panId "ABCD" from device "ABCDEF"
Then the stick responds without errors
Then the stick sends a scan response for panId "ABCD" from device "ABCDEF"
And the stick responds without errors

Scenario: Send scan response - force stick timeout
When I ask the stick to respond to a scan for panId "ABCD" from device "DEAD01"
Then the stick responds negatively
Then the stick sends a scan response for panId "ABCD" from device "DEAD01"
And the stick responds negatively

Scenario: Send scan response - force network timeout
When I ask the stick to respond to a scan for panId "ABCD" from device "DEAD02"
Then the stick responds negatively
Then the stick sends a scan response for panId "ABCD" from device "DEAD02"
And the stick responds negatively

Scenario: Network join request
When the device "ABCDEF" sends a network join request for channel 12 and panId "BEEF" with encryption key "12345678123456781234567812345678"
Expand Down
6 changes: 6 additions & 0 deletions features/support/WaremaWMSMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class WaremaWMSMock {
}
}

async getLastSentMessage(): Promise<string|undefined> {
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
await delay(500);
return this.mockedPort.port?.lastWrite?.toString();
}

mockResponse(): void {
const receivedFrame = this.mockedPort.port?.lastWrite?.toString();
if (!receivedFrame) {
Expand Down
12 changes: 12 additions & 0 deletions features/support/networkManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ When('I ask the stick to scan the network for panId {string}', async function (p
}
})

Then('the stick sends a scan request for panId {string}', async function (panId) {
const expectedResponse = `{R04FFFFFF7020${panId}02}`;
const actualResponse = await this['wmsMock'].getLastSentMessage();
assert.strictEqual(actualResponse, expectedResponse);
});

Then('the stick sends a scan response for panId {string} from device {string}', async function (panId, serial) {
const expectedResponse = `{R01${serial}7021${panId}02}`;
const actualResponse = await this['wmsMock'].getLastSentMessage();
assert.strictEqual(actualResponse, expectedResponse);
});

When('the device {string} of type {int} sends a scan response for panId {string}', async function (serial, deviceType, panId) {
this['wmsMock'].mockReceivedScanResponse(serial, deviceType, panId);
})
Expand Down
2 changes: 1 addition & 1 deletion lib/WaremaWMSFrameHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class WaremaWMSFrameHandler extends EventEmitter {
frame = `${WaremaWMSFrameHandler.FRAME_TYPE_MESSAGE_REQUEST}04FFFFFF${WaremaWMSFrameHandler.MESSAGE_TYPE_SCAN_REQUEST}${payload!.panId}${DEVICE_TYPE_STICK.toString().padStart(2, '0')}`;
break;
case WaremaWMSFrameHandler.MESSAGE_TYPE_SCAN_RESPONSE:
frame = `${WaremaWMSFrameHandler.FRAME_TYPE_MESSAGE_REQUEST}01${payload!.serial!}${WaremaWMSFrameHandler.MESSAGE_TYPE_SCAN_RESPONSE}FFFF02`;
frame = `${WaremaWMSFrameHandler.FRAME_TYPE_MESSAGE_REQUEST}01${payload!.serial!}${WaremaWMSFrameHandler.MESSAGE_TYPE_SCAN_RESPONSE}${payload!.panId}02`;
break;
case WaremaWMSFrameHandler.MESSAGE_TYPE_WAVE_REQUEST:
frame = `${WaremaWMSFrameHandler.FRAME_TYPE_MESSAGE_REQUEST}06${payload!.serial!}${WaremaWMSFrameHandler.MESSAGE_TYPE_WAVE_REQUEST}`;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wms-js",
"version": "0.0.2",
"version": "0.0.3",
"description": "Interface to a Warema WMS network using a Warema WMS stick",
"keywords": [
"warema",
Expand Down

0 comments on commit cfe439f

Please sign in to comment.