So im writing this piece of code to maintain modules on a bus in NodeJs to replace older Delphi 4 code.
The module sends information in blocks, these blocks contain the encoded information and look like this:
{
sender_module_group: { name: 'Sensor', number: 3, hex: 0x03 },
receiver: <Buffer 01 03>,
type: 0,
data_type: { name: 'DATA_BLOCK', number: 33029, hex: 0x8105},
length: <Buffer 16>,
message: <Buffer 00 d5 23 13 ac ff fe a2 ba 53 a6 1b e7 aa d2 51 05 00 00 00 00 00>,
}
During the initialization of the module there are in total around 50 blocks of data each stating what page of memory needs to be read next.
Each block is processed and slowly an object is filled with the data. The first time around on bootup, it works like a charm and all the data gets filled.
The issue arises when a module is dropped(a module can drop due bad connection, CRC checks failing in data transfer, etc).
Modules are dropped in the following way:
modules.splice(index, 1)
Where index
is the index of the object in the array of objects modules
When I then try to re-add the module after the connection is reestablished it will start with the first few blocks, these are similar to the original. However, at an x number of blocks, the code will crash/stop running the next block
I narrowed it down to the array of objects, could there be a shadow copy and how can in cleanse that one"?