FreeRTOS: FreeRTOS Cellular Library v1.4.0
FreeRTOS Cellular Library
 
Loading...
Searching...
No Matches
Sending binary data with Cellular Common APIs

Send binary data command is split into two steps:

  • Send the AT command
  • Send the binary data

Take the socket send command of reference port BG96 for example:

AT+QISEND=0,5 //Send fixed length data and the data length is 5 bytes
> test2
SEND OK

The first step sends the command "AT+QISEND=0,5" and waiting for the response "> ".

AT+QISEND=0,5
>

">" is a result code in the port to indicate that modem is ready to accept the binary data.

The second step send the binary data "test2" to the modem and waits for the response "SEND OK".

test2
SEND OK

"SEND OK" is a result code in the port to indicate the modem successfully receives the data.

‍One thing to mentioned in the example is that cellular interface processes the response in line. The respone "> " does not contain line ending char. Cellular interface passes the response to the port through data send prefix callback function. The port may fix the input stream in the callback function. In this example, the response is fixed to ">\n" in the callback. Cellular interface can process the fixed input stream.

_Cellular_AtcmdDataSend is the general cellular common API to send binary data to cellular modem. BG96 port make use of this API to send binary data with the following parameters:

/* The structure to send the AT command. Mapping to the first step of send binary data. */
CellularAtReq_t atReqSocketSend =
{
.pAtCmd = cmdBuf, /* In this example, "AT+QISEND=0,5". */
.atCmdType = CELLULAR_AT_NO_RESULT, /* The command expects only result code to indicate status from modem. */
.pAtRspPrefix = NULL, /* No prefix for the result since the type is CELLULAR_AT_NO_RESULT. */
.respCallback = NULL, /* No response callback since the type is CELLULAR_AT_NO_RESULT. */
.pData = NULL, /* No data since the type is CELLULAR_AT_NO_RESULT. */
.dataLen = 0, /* Data length is 0. */
};
/* The structure to send the binary data. Mapping to the second step of send binary data. */
CellularAtDataReq_t atDataReqSocketSend =
{
.pData = pData, /* Point to the data to send. */
.dataLen = dataLength, /* The length of the data to send. */
.pSentDataLength = pSentDataLength, /* The actual data sent to the modem. */
.pEndPattern = NULL, /* The end pattern to send after the binary data. */
.endPatternLen = 0 /* The length of the end pattern. */
};
/* The send binary data send API in cellular common layer. */
pktStatus = _Cellular_AtcmdDataSend( pContext, /* The cellular context. */
atReqSocketSend, /* Send AT command request. */
atDataReqSocketSend, /* Send binary data. */
socketSendDataPrefix, /* Data prefix callback. BG96 port fix the input stream "> " in this function. */
NULL, /* Data prefix callback context. Not used in this example. */
PACKET_REQ_TIMEOUT_MS, /* AT command send timeout. */
sendTimeout, /* Binary data send timeout. */
0U ); /* The delay between AT command and binary data. */
CellularPktStatus_t _Cellular_AtcmdDataSend(CellularContext_t *pContext, CellularAtReq_t atReq, CellularAtDataReq_t dataReq, CellularATCommandDataSendPrefixCallback_t pktDataSendPrefixCallback, void *pCallbackContext, uint32_t atTimeoutMS, uint32_t dataTimeoutMS, uint32_t interDelayMS)
Send the AT command to cellular modem with send data.
Definition: cellular_pkthandler.c:668
@ CELLULAR_AT_NO_RESULT
Definition: cellular_types.h:361
The data command request structure.
Definition: cellular_common.h:76
const uint8_t * pData
Definition: cellular_common.h:77
The AT command request structure.
Definition: cellular_common.h:62
const char * pAtCmd
Definition: cellular_common.h:63

To adapt with various cellular modems AT command, cellular interface provides the following APIs in common layer to send binary stream to modem:

HL7802 socket send command reference port example

AT+KTCPSND=1,18
CONNECT // CONNECT is considered a success result code only when sending the AT+KTCPSND command
// _Cellular_TimeoutAtcmdDataSendSuccessToken can be used in this case.
...Data send...
--EOF--Pattern-- // Modem required the end pattern sent after the binary data.
// The pEndPattern of CellularAtDataReq_t can be used in this case.
OK

SARA-R4 socket send command reference port example

AT+USOWR=3,16
@16 bytes of data // "@" is not a new line. SARA-R4 port fixes the input stream in the callback.
// SARA-R4 requires to wait for a minimum of 50 ms before sending data.
// The interDelayMS parameter of _Cellular_AtcmdDataSend can be used in this case.
+USOWR: 3,16
OK