Daxbot / node-canopen

CANopen implementation for NodeJS
MIT License
32 stars 11 forks source link

Exception in src/Network.js if receiving an NMT command with a non-zero node ID #6

Closed dawn-minion closed 4 years ago

dawn-minion commented 4 years ago

We're currently sending NMT commands to specific nodes directly via node-can (So not using the lib, but on the same canopen interface this lib uses), and we're seeing the following exception happen if we send an NMT reset request to a non-zero node ID:

canopen/src/Network.js:88
                this.devices[target].state = state;
                                           ^

TypeError: Cannot set property 'state' of undefined
    at Network._onMessage (canopen/src/Network.js:88:44)

Messages we send are echoed back to us, so are picked up by _onMessage in Network.js. The code there then assumes we have a device registered with the node ID we received. Since we don't, it then throws the type error above.

This also means we can be crashed by receiving any NMT command with a non-zero ID.