-
Notifications
You must be signed in to change notification settings - Fork 318
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
fix(modify): Repair the issue of channel updating #1280
Open
CubeZ2mDeveloper
wants to merge
4
commits into
Koenkk:master
Choose a base branch
from
CubeZ2mDeveloper:bugfix/change_channel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−44
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5a3afe5
fix(modify): Repair the issue of channel switching where some devices…
danyinhao 48ee5a7
eslint prettier fix
danyinhao e46ba7e
fix(modify): Extend the getNetworkParameters method to obtain the val…
danyinhao 629088f
eslint prettier fix
danyinhao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,44 @@ const mockLogger = { | |
error: vi.fn(), | ||
}; | ||
|
||
const mockDummyBackup: Models.Backup = { | ||
networkOptions: { | ||
panId: 6755, | ||
extendedPanId: Buffer.from('deadbeef01020304', 'hex'), | ||
channelList: [11], | ||
networkKey: Buffer.from('a1a2a3a4a5a6a7a8b1b2b3b4b5b6b7b8', 'hex'), | ||
networkKeyDistribute: false, | ||
}, | ||
coordinatorIeeeAddress: Buffer.from('0102030405060708', 'hex'), | ||
logicalChannel: 11, | ||
networkUpdateId: 0, | ||
securityLevel: 5, | ||
znp: { | ||
version: 1, | ||
}, | ||
networkKeyInfo: { | ||
sequenceNumber: 0, | ||
frameCounter: 10000, | ||
}, | ||
devices: [ | ||
{ | ||
networkAddress: 1001, | ||
ieeeAddress: Buffer.from('c1c2c3c4c5c6c7c8', 'hex'), | ||
isDirectChild: false, | ||
}, | ||
{ | ||
networkAddress: 1002, | ||
ieeeAddress: Buffer.from('d1d2d3d4d5d6d7d8', 'hex'), | ||
isDirectChild: false, | ||
linkKey: { | ||
key: Buffer.from('f8f7f6f5f4f3f2f1e1e2e3e4e5e6e7e8', 'hex'), | ||
rxCounter: 10000, | ||
txCounter: 5000, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const mockAdapterEvents = {}; | ||
const mockAdapterWaitFor = vi.fn(); | ||
const mockAdapterSupportsDiscoverRoute = vi.fn(); | ||
|
@@ -56,6 +94,7 @@ const mocksendZclFrameToGroup = vi.fn(); | |
const mocksendZclFrameToAll = vi.fn(); | ||
const mockAddInstallCode = vi.fn(); | ||
const mocksendZclFrameToEndpoint = vi.fn(); | ||
const mockApaterBackup = vi.fn().mockReturnValue(mockDummyBackup); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const mockAdapterBackup = vi.fn(() => Promise.resolve(mockDummyBackup)); should provide more accurate typing/testing (and fix typo). |
||
let sendZdoResponseStatus = Zdo.Status.SUCCESS; | ||
const mockAdapterSendZdo = vi | ||
.fn() | ||
|
@@ -318,44 +357,6 @@ const getCluster = (key) => { | |
return cluster; | ||
}; | ||
|
||
const mockDummyBackup: Models.Backup = { | ||
networkOptions: { | ||
panId: 6755, | ||
extendedPanId: Buffer.from('deadbeef01020304', 'hex'), | ||
channelList: [11], | ||
networkKey: Buffer.from('a1a2a3a4a5a6a7a8b1b2b3b4b5b6b7b8', 'hex'), | ||
networkKeyDistribute: false, | ||
}, | ||
coordinatorIeeeAddress: Buffer.from('0102030405060708', 'hex'), | ||
logicalChannel: 11, | ||
networkUpdateId: 0, | ||
securityLevel: 5, | ||
znp: { | ||
version: 1, | ||
}, | ||
networkKeyInfo: { | ||
sequenceNumber: 0, | ||
frameCounter: 10000, | ||
}, | ||
devices: [ | ||
{ | ||
networkAddress: 1001, | ||
ieeeAddress: Buffer.from('c1c2c3c4c5c6c7c8', 'hex'), | ||
isDirectChild: false, | ||
}, | ||
{ | ||
networkAddress: 1002, | ||
ieeeAddress: Buffer.from('d1d2d3d4d5d6d7d8', 'hex'), | ||
isDirectChild: false, | ||
linkKey: { | ||
key: Buffer.from('f8f7f6f5f4f3f2f1e1e2e3e4e5e6e7e8', 'hex'), | ||
rxCounter: 10000, | ||
txCounter: 5000, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
let dummyBackup; | ||
|
||
vi.mock('../src/adapter/z-stack/adapter/zStackAdapter', () => ({ | ||
|
@@ -368,9 +369,7 @@ vi.mock('../src/adapter/z-stack/adapter/zStackAdapter', () => ({ | |
getCoordinatorIEEE: mockAdapterGetCoordinatorIEEE, | ||
reset: mockAdapterReset, | ||
supportsBackup: mockAdapterSupportsBackup, | ||
backup: () => { | ||
return mockDummyBackup; | ||
}, | ||
backup: mockApaterBackup, | ||
getCoordinatorVersion: () => { | ||
return {type: 'zStack', meta: {version: 1}}; | ||
}, | ||
|
@@ -1558,6 +1557,28 @@ describe('Controller', () => { | |
it('Change channel on start', async () => { | ||
mockAdapterStart.mockReturnValueOnce('resumed'); | ||
mockAdapterGetNetworkParameters.mockReturnValueOnce({panID: 1, extendedPanID: '0x64c5fd698daf0c00', channel: 25}); | ||
// @ts-expect-error private | ||
const changeChannelSpy = vi.spyOn(controller, 'changeChannel'); | ||
await controller.start(); | ||
expect(mockAdapterGetNetworkParameters).toHaveBeenCalledTimes(1); | ||
const zdoPayload = Zdo.Buffalo.buildRequest(false, Zdo.ClusterId.NWK_UPDATE_REQUEST, [15], 0xfe, undefined, 1, undefined); | ||
expect(mockAdapterSendZdo).toHaveBeenCalledWith( | ||
ZSpec.BLANK_EUI64, | ||
ZSpec.BroadcastAddress.SLEEPY, | ||
Zdo.ClusterId.NWK_UPDATE_REQUEST, | ||
zdoPayload, | ||
true, | ||
); | ||
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: '0x64c5fd698daf0c00'}); | ||
expect(changeChannelSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Change channel on start when the nwkUpdateId increases to 0xFF', async () => { | ||
mockAdapterStart.mockReturnValueOnce('resumed'); | ||
mockAdapterGetNetworkParameters.mockReturnValueOnce({panID: 1, extendedPanID: '0x64c5fd698daf0c00', channel: 25}); | ||
mockAdapterSupportsBackup.mockReturnValueOnce(true); | ||
mockApaterBackup.mockReturnValueOnce(Object.assign({}, mockApaterBackup, {networkUpdateId: 0xff})); | ||
|
||
// @ts-expect-error private | ||
const changeChannelSpy = vi.spyOn(controller, 'changeChannel'); | ||
await controller.start(); | ||
|
@@ -1574,6 +1595,28 @@ describe('Controller', () => { | |
expect(changeChannelSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Change channel on start when the nwkUpdateId is undefinded', async () => { | ||
mockAdapterStart.mockReturnValueOnce('resumed'); | ||
mockAdapterGetNetworkParameters.mockReturnValueOnce({panID: 1, extendedPanID: '0x64c5fd698daf0c00', channel: 25}); | ||
mockAdapterSupportsBackup.mockReturnValueOnce(true); | ||
mockApaterBackup.mockReturnValueOnce({}); | ||
|
||
// @ts-expect-error private | ||
const changeChannelSpy = vi.spyOn(controller, 'changeChannel'); | ||
await controller.start(); | ||
expect(mockAdapterGetNetworkParameters).toHaveBeenCalledTimes(1); | ||
const zdoPayload = Zdo.Buffalo.buildRequest(false, Zdo.ClusterId.NWK_UPDATE_REQUEST, [15], 0xfe, undefined, 1, undefined); | ||
expect(mockAdapterSendZdo).toHaveBeenCalledWith( | ||
ZSpec.BLANK_EUI64, | ||
ZSpec.BroadcastAddress.SLEEPY, | ||
Zdo.ClusterId.NWK_UPDATE_REQUEST, | ||
zdoPayload, | ||
true, | ||
); | ||
expect(await controller.getNetworkParameters()).toEqual({panID: 1, channel: 15, extendedPanID: '0x64c5fd698daf0c00'}); | ||
expect(changeChannelSpy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('Does not change channel on start if not changed', async () => { | ||
mockAdapterStart.mockReturnValueOnce('resumed'); | ||
// @ts-expect-error private | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think making a new backup is necessary here? Can't we get the value from the existing backup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
Probably the property should be added to the adapter type NetworkParameters, since it's part of that, and then can be used throughout controller without issue (cached on start).
Remains to see if all adapters provide it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will try to change it to the implementation method you suggested.