Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Feature_Add_Callback... to Main #65

Merged
merged 2 commits into from
Jun 15, 2022

Conversation

eyuan-creare
Copy link
Contributor

@eyuan-creare eyuan-creare commented Jun 14, 2022

Added callback for multibyte serial messages. Tested using Realterm to send:

  • 'test' message: 0x02 0x0D 0x00 0x00 0x00 0x03 0x74 0x65 0x73 0x74 0x03 0xD2 0x02 0x96 0x49 0xD2 0x02 0x96 0x49 0x04
  • 'abcd' message: 0x02 0x0D 0x00 0x00 0x00 0x03 0x61 0x62 0x63 0x64 0x03 0xD2 0x02 0x96 0x49 0xD2 0x02 0x96 0x49 0x04

See attached script that modified an SD Card Writer example to register a callback function
DataStream_example.zip

Here is background info copied from SerialManagerBase.h

DataStreams: Besides the single-character and four-character modes, there are also
		     data streaming modes to support specialized communication.  These special modes
			 are not inteded to be invoked by a user's GUI, so they can be ignored.  To avoid
			 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.

			 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)`

@eyuan-creare
Copy link
Contributor Author

Here is a good article on misalignment and type punning

@eyuan-creare eyuan-creare reopened this Jun 15, 2022
@eyuan-creare eyuan-creare marked this pull request as draft June 15, 2022 14:15
@eyuan-creare
Copy link
Contributor Author

Sorry for all the shenanigans! I accidentally pushed to main instead. I'll reopen this pull request when everything is straightened out..

@eyuan-creare
Copy link
Contributor Author

Added checks to ensure buffer is not overrun and that the length is sent as 4-bytes. The latter was tested with a message that erroneously has a 3-byte length:
0x02 0x08 0x00 0x00 0x03 0x00 0x00 0x04

@eyuan-creare
Copy link
Contributor Author

@kxm-creare What other applications use this data stream? Should I test a hearing aid script to ensure I did not bugger up 4-character messages?

@eyuan-creare eyuan-creare marked this pull request as ready for review June 15, 2022 15:03
Copy link
Contributor

@kxm-creare kxm-creare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. @chipaudette when we switched to BLE, I believe we disabled the use of predefined pages (GHA, AFC, DSL). Do you recall this? I don't remember if this was something that @hgeithner-creare tested or not.

@eyuan-creare eyuan-creare merged commit e8bb8e3 into main Jun 15, 2022
@chipaudette
Copy link
Member

@kxm-creare, Hmm...I don't remember if we disabled the predefined pages or not. I'm pretty sure that we didn't expose them for any of our ASA participants. Yes, maybe the reason is because we disabled them!

I agree that I don't think that Haley tested any of that functionality. So, whether or not they are disabled, they are not tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants