Hi,
I’m using BGM113 and I’m trying to understand how to parse the headers for proper processing using the BLE112 as reference (here).
The library class has a function dedicated to parsing the header, but I’m not understanding it completely. This is the section I need to understand from parse_packet(), starting in line 594:
event.msg_type ← (buffer[0] & 0x80);
event.tech_type ← (buffer[0] & 0x78) >> 3;
event.length ← ((buffer[0] & 0x07) << 8) + buffer[1];
event.cid ← buffer[2];
event.cmd ← buffer[3];
I want to choose the 4 bytes a header has, but the code is indexing (?) some other stuff I don’t truly know, because this is what I would’ve done:
event.msg_type ← buffer[0];
event.lenght ← buffer[1];
event.cid ← buffer[2];
event.cmd ← buffer[3];
Why are they doing it differently? This is a screenshot of the reported values in this order (the first one is the result for server.log(buffer)):
- event.msg_type ← (buffer[0] & 0x80);
- event.tech_type ← (buffer[0] & 0x78) >> 3;
- event.length ← ((buffer[0] & 0x07) << 8) + buffer[1];
- event.cid ← buffer[2];
- event.cmd ← buffer[3];
- event.msg_type ← buffer[0];
- event.lenght ← buffer[1];
- event.cid ← buffer[2];
- event.cmd ← buffer[3];
Any help would be appreciated!