Skip to content

Commit

Permalink
Merge branch 'Feature_Add_Callback_for_Datastream_Messages' of https:…
Browse files Browse the repository at this point in the history
…//github.com/Tympan/Tympan_Library into Feature_Add_Callback_for_Datastream_Messages
  • Loading branch information
eyuan-creare committed Jun 15, 2022
2 parents 9b6ebeb + 9751b9c commit 69ddd94
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/SerialManagerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void SerialManagerBase::respondToByte(char c) {
case STREAM_LENGTH:
if (c == DATASTREAM_SEPARATOR) {
// Get the datastream length:
stream_length = *((int*)(stream_data));
memcpy(&stream_length, &stream_data[0], 4);
serial_read_state = STREAM_DATA;
stream_chars_received = 0;
Serial.print("SerialManagerBase: RespondToByte: Stream length = ");
Expand Down
34 changes: 32 additions & 2 deletions src/SerialManagerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,39 @@
inadvertently invoking these modes, never send characters such as 0x02, 0x03, 0x04.
In fact, you should generally avoid any non-printable character or you risk seeing
unexpected behavior.
License: MIT License. Use at your own risk. Have fun!
Datastreams expect the following message protocol. Note that the message length and payload are sent as little endian (LSB, MSB):
1. DATASTREAM_START_CHAR (0x02)
2. Message Length (int32): number of bytes including parts-4 thru part-6
3. DATASTREAM_SEPARATOR (0x03)
4. Message Type (char): Avoid using the special characters 0x03 or 0x04. (if set to ‘test’, it will print out the payload as an int, then a float)
5. DATASTREAM_SEPARATOR (0x03)
6. Payload
7. DATASTREAM_END_CHAR (0x04)
Use RealTerm to send a 'test' message:
0x02 0x0D 0x00 0x00 0x00 0x03 0x74 0x65 0x73 0x74 0x03 0xD2 0x02 0x96 0x49 0xD2 0x02 0x96 0x49 0x04
1. DATASTREAM_START_CHAR (0x02)
2. Message Length (int32): (0x000D) = 13
3. DATASTREAM_SEPARATOR (0x03)
4. Message Type (char): (0x74657374) = 'test'
5. DATASTREAM_SEPARATOR (0x03)
6. Payload (0x499602D2, 0x499602D2) = [1234567890, 1234567890]
7. DATASTREAM_END_CHAR (0x04)
- Expected output
- SerialManagerBase: RespondToByte: Start data stream.
- SerialManagerBase: RespondToByte: Stream length = 13
- SerialManagerBase: RespondToByte: Time to process stream!
- Stream is of type 'test'.
- int is 1234567890
- float is 1228890.25
To register a callback when a datastream message is received, use setDataStreamCallback() and set a unique message type (i.e. not 'gha', 'dsl', afc', or 'test'):
- `serialManager.setDataStreamCallback(&dataStreamCallback);`
- `void dataStreamCallback(char* payload_p, String *msgType_p, int numBytes)`
License: MIT License. Use at your own risk. Have fun!
*/


Expand Down

0 comments on commit 69ddd94

Please sign in to comment.