Building A Packet
computer guy
Posts: 1,113
I am waiting for a CC-Debugger to program a 8051 MCU, to get a Bluetooth Module working.
In the meantime as I am impatient, I have proceeded to try and write a driver object for the module based on the documentation and wanted to see if I am doing it right. (As I am new to byte manipulation).
The following code is supposed to build the header section of the packet.
Where message type is one of either:
techType is:
and len is the length of the payload.
It's just the first byte im not sure about. The ORing of the values together and shifting of the length.
Does it look right?
In the meantime as I am impatient, I have proceeded to try and write a driver object for the module based on the documentation and wanted to see if I am doing it right. (As I am new to byte manipulation).
'Packet Structure ' +------------+---------+--------+--------+--------+----------+------------+ ' | 0 | 0000 | 000 |00000000|00000000| 00000000 |00000000 ...| ' +------------+---------+--------+--------+--------+----------+------------+ ' |Message Type|Tech Type|Len High|Len Low |Class ID|Command ID| Payload | ' +------------+---------+--------+--------+--------+----------+------------+ ' | Header | Payload | ' +------------------------------------------------------------+------------+
' BUILD HEADER txHeader[0] := messageType txHeader[0] |= techType txHeader[0] |= len << 8 txHeader[1] := len txHeader[2] := class txHeader[3] := cmd
The following code is supposed to build the header section of the packet.
Where message type is one of either:
messageTypeCommand := %00000000 messageTypeEvent := %10000000
techType is:
techTypeBT4S := %00000000
and len is the length of the payload.
It's just the first byte im not sure about. The ORing of the values together and shifting of the length.
Does it look right?
Comments
to:
Since only the least significant byte would be used from "len" anyway.
(Not that it matters much.)
Edit: I see this is the way Computer Guy originally had it.