Hi Tuna,
Sorry for lat reply. From your previous description, it looks like “^SISW: 0,1” has to be received before sending data through socket.
AT^SISO... // Open the internet service
^SISW: 0, 1 // URC to indicate the service is ready to accept data
AT^SISW=0,31 // Start to send data
^SISW: 0,31,0
< 31 bytes data >
OK
^SISW: 0, 1 // Wait for this URC again before sending data again
AT^SISW=0,31 // Send more data
^SISW: 0,31,0
< 31 bytes data >
OK
If that is the case, we can make use of FreeRTOS inter-task communication mechanism to wait for an event received before sending data. Here use event group as an example.
Create an event group for socket when module init.
CellularError_t Cellular_ModuleInit( ... )
{
...
pModuleContext->xSocketEventGroup = xEventGroupCreate();
if( pModuleContext->xSocketEventGroup == NULL )
{
/* The event group was not created because there was insufficient
FreeRTOS heap available. */
}
}
Register a URC handler to handle “^SISW: 0, 1”.
CellularAtParseTokenMap_t CellularUrcHandlerTable[] =
{
...
{ "SISW", prvProcessSISWUrc },
...
};
static void prvProcessSISWUrc( CellularContext_t * pContext,
char * pInputLine )
{
/* Set the socket event bit for corresponding socket when "^SISW: 0, 1" is received. */
xEventGroupSetBits( pModuleContext->xSocketEventGroup, ( 1 << uxSocketIndex ) );
}
In the socket send function, wait for the bit before start to send data.
CellularError_t Cellular_SocketSend( ... )
{
...
/* Wait the corresponding event groupt bit before start to send data. */
uxBits = xEventGroupWaitBits(
pModuleContext->xSocketEventGroup,
( 1 << uxSocketIndex ),
pdTRUE, /* Bit should be cleared before returning. */
pdFALSE, /* Don't wait for all bits. */
xTicksToWait );/* Wait a maximum timeout for bit to be set. */
if( ( uxBits & ( 1 << uxSocketIndex ) ) != 0 )
{
/* URC "^SISW" is received. Continue to send data through socket. */
}
else
{
/* This is the timeout case. Check the spec for error handling. */
}
}
The three reference modem ports make use of buffer access mode for socket send/receive. We don’t have reference port for transparent mode. If you have problem implementing this feature, please feedback your question. We will discuss with you here.