I want to use FreeRTOS in my next project, it use a LTE Module to:
- Create Socket and connect to TCP Server (Receive / Send)
- SMS (Receive / Send)
- FTP (Download/ Upload)
- voice call
- other: NTP / …
I Read the Cellular Interface and tried the demo “Lab-Project-FreeRTOS-Cellular-Demo” (mqtt_mutual_auth_demo.sln)
I opened the project and connect to a SARA-R4 EVK board, after step into the code, I have some questions:
I ever use many 2/3/4G Modules and control it by 8 bit MCU, so I used to write a switch case as state machine. When I have job to do, I put it to queue, send CMD, receive ack from ISR, parse it and then do the next step.
When I use FreeRTOS, it looks so different, it seems I can do one job in a single function, for example:
A FTP download, it needs 4、5 AT commands to complete to job, so I need write 4、5 labels in switch case to deal with it. (and more for the ACK of OK, ERROR, timeout)
After using FreeRTOS Cellular Interface, I can send message, wait ACK( using xQueueReceive) and then do the next, it seems so convenient!
But I noticed that It just use a prefix table to decide the received message is ACK or URC message(event from module), as shown below:
const char * CellularUrcTokenWoPrefixTable[] ={ "RDY" };
cellular_pktio.c:
static _atRespType_t _getMsgType( const CellularContext_t * pContext,
const char * pLine,
const char * pRespPrefix )
{
_atRespType_t atRespType = AT_UNDEFINED;
CellularATError_t atStatus = CELLULAR_AT_SUCCESS;
bool inputWithPrefix = false;
bool inputWithSrcPrefix = false;
if( pContext->tokenTable.pCellularUrcTokenWoPrefixTable == NULL )
{
atStatus = CELLULAR_AT_ERROR;
atRespType = AT_UNDEFINED;
}
else if( urcTokenWoPrefix( pContext, pLine ) == true )
{
atRespType = AT_UNSOLICITED;
}
else
{
/* Check if prefix exist in pLine. */
( void ) Cellular_ATIsPrefixPresent( pLine, &inputWithPrefix );
if( ( inputWithPrefix == true ) && ( pRespPrefix != NULL ) )
{
/* Check if SRC prefix exist in pLine. */
atStatus = Cellular_ATStrStartWith( pLine, pRespPrefix, &inputWithSrcPrefix );
}
}
...
...
}
The demo project just define one URC prefix as ‘RDY’ (in cellular_r4.c)
I will have many URCs in real project, the problem is, not all URCs have so simple structure.
If I set CREG/ CEREG / CGREG = 2, then it will send URC when state changed, and message format is just the same as AT+CREG/CEREG/CGREG command ACK, is it can really tell the difference? (the received message is a command ack, or a URC from module?)
After opened a TCP Socket, when Server Send something to the module, it will send a URC with prefix header, a new line, and lots of data, how the incoming TCP data be received correctly?
Is there any demo project that do the TCP Socket Connection?
the Cellular interface looks so good, it can simplify the implementation if it works…, hope someone can give suggestions about how the interface parse general AT CMD ACK and URC message