So if we pretend that we have the following data being streamed into Java from a microcontroller using Serial Port:
0x21 0x32 0xCC 0x00 0x3A 0x98 0x02 0x12 0x03 0x21 0x33 0x01 0xC2
I initially believed that the first byte was the Magic Number and the second byte was the Key. So wouldn't that make the numbers 0xCC 0x00 0x3A 0x98 0x02 0x12 0x03 0x21 0x33 0x01 0xC2
the value that we're reading from the microcontroller which we just combined all of the numbers in order to get the following reading in decimal value: 204058... and on
?
And for the time stamp don't we just convert the second byte which is 0x32
to decimal which is 50 unites of time
?
Quoting comment:
on the documentation it mentioned that the payload was a key-value pair and 0x32 was for "timestamp, 4-byte integer, milliseconds since reset" and 0x33 "potentiometer reading, 2-byte integer A/D counts" so does that mean the next time I hit 0x32 which is the second number and since its a 4-byte integer we concatonate 0xCC and 0x00 0x3A and 0x98?
Quoting example data from question:
0x21 0x32 0xCC 0x00 0x3A 0x98 0x02 0x12 0x03 0x21 0x33 0x01 0xC2
So, key/value pairs, where the key is a single byte, and each key has values of differing length.
0x32 was for "timestamp, 4-byte integer, milliseconds since reset"
0x21 0x32 0xCC 0x00 0x3A 0x98 0x02 0x12 0x03 0x21 0x33 0x01 0xC2
^^^^ ^^^^^^^^^^^^^^^^^^^
key 4-byte integer
Those 4 bytes can be big-endian or little-endian, but big-endian is more common for devices, so:
0xCC003A98 = 3422567064 ms = 39 days 14 hrs 42 mins 47.064 secs
0x33 "potentiometer reading, 2-byte integer A/D counts"
0x21 0x32 0xCC 0x00 0x3A 0x98 0x02 0x12 0x03 0x21 0x33 0x01 0xC2
^^^^ ^^^^^^^^^
key 2-byte integer
0x01C2 = 450
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加