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

Adding _Cellular_RegisterInputBufferCallback in common layer #137

Merged
merged 10 commits into from
May 23, 2023

Conversation

chinglee-iot
Copy link
Member

@chinglee-iot chinglee-iot commented Apr 9, 2023

Adding _Cellular_RegisterInputBufferCallback to handle data stream in URC response referenced in #123.

Cellular modem may return binary data in URC.
For example, BG96 allows to receive the socket data in URC with direct push mode.

+QIURC: "recv",0,4 //Receive data from remote server.
test   // URC DATA , it can be binary stream.

The binary data can't be handled by cellular pktio since it handles data in line. Binary stream can only be handled in AT command response not in URC.
This PR makes use of a callback function to pass the input buffer received to the port. The port can decide to handle the input buffer in the callback or return to pktio for further parsing.

Module porting callback can return the following value to the pktio:

  • CELLULAR_PKT_STATUS_PREFIX_MISMATCH : indicates the input buffer in not handled in the callback. pktio will continue to process the line in the input buffer.
+CREG:2    // Cellular interface is able to handle URC +CREG. 
           // The input buffer callback can returns CELLULAR_PKT_STATUS_PREFIX_MISMATCH to pktio for further processing.
  • CELLULAR_PKT_STATUS_SIZE_MISMATCH : indicates the input buffer is handled in the callback but more data is expected. pktio will stop processing this input buffer. The callback function will be called again when more data is received.
+QIURC: "recv",0,4
te    // In previous example, the URC expect 4 bytes of binary data but only 2 bytes received
      // The input buffer callback can returns CELLULAR_PKT_STATUS_SIZE_MISMATCH.
      // It will be called again when more data received ( "st" is received )
  • CELLULAR_PKT_STATUS_OK : indicates that the input buffer is handled in the callback successfully. The pktio will keep processing the line after.
+QIURC: "recv",0,4
test
+CREG:2           // The +QIURC is handled in the callback function. The callback function returns CELLULAR_PKT_STATUS_OK.
                  // pktio will continue to process the "+CREG:2"
  • Other errors : indicates that modem returns unexpected error.

Description

  • Adding _Cellular_RegisterInputBufferCallback in common layer for porting to handle the input buffer before pktio.
  • Module porting can make use of this API in common layer to handle data in URC. Reference the example in BG96 for usage.

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@chinglee-iot chinglee-iot force-pushed the dev-urc-data-prefix branch 2 times, most recently from 92ae20f to 37de419 Compare April 9, 2023 09:27
* Adding _Cellular_RegisterUrcDataCallback to handle data stream in URC
  response
@chinglee-iot chinglee-iot changed the title Adding _Cellular_RegisterUrcDataCallback in common layer Adding _Cellular_RegisterInputBufferCallback in common layer May 22, 2023
@hubert-melchert
Copy link

I've just today found out about your _Cellular_RegisterUrcDataCallback function. through #123
I'm trying to use it for receiving data from MQTT stack embedded in Quectel's EG915N. I got to the point that I believe that won't work for all types of received data. For text it's okay but I want to receive binary data when 0 byte or \r\n can be a part of data and cannot be skipped. For example in firmware update. Callback registered by _Cellular_RegisterUrcDataCallback is called by _handleAllReceived in cellular_pktio.c and just before calling prepreocessInputBuffer there is a while loop to skip every \r, \n, \0 in input data. It may be (I hope so) that I'm just wrong and tired and tommorow I will make it work but maybe you can spare me some pain.

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.

4 participants