AT Commands Client
- Warning
- Some AT commands may conflict with Legato APIs; using both may cause problems that can be difficult to diagnose. AT commands should be avoided whenever possible, and should only be used with great care.
The AT Client Service handles the AT commands sent to the modem on a specified serial device. It also supports getting AT command responses (intermediate, final or unsolicited responses). This service can be subscribed to by several apps simultaneously.
IPC interfaces binding
All the functions of this API are provided by the atService.
Here's a code sample binding to the AT commands server:
bindings: { atClientTest.atClientTestComp.le_atClient -> atService.le_atClient }
Device Binding
le_atClient_Start() must be called to bind a specific device with the ATClient. Multiple devices can be bound. The app has to configured the device before using it with the ATClient. A device can be unbound using le_atClient_Stop().
Statement
An AT command statement is requested before sending it. The following steps have to be done for its declaration:
- create an AT command reference using le_atClient_Create().
- use le_atClient_SetCommand() to set the AT command to be sent to the modem.
- set the sending port to use le_atClient_SetDevice().
- can set a timeout value using le_atClient_SetTimeout(); default value is
30s
. - request expected final responses and set using le_atClient_SetFinalResponse().The final response is mandatory to detect the end of the AT command execution. If an AT command answers with a final response that doesn't belong to the final responses set, the AT command execution will end by timeout.
- can call le_atClient_SetIntermediateResponse() to set the intermediate responses filters. This is optional.
Command responses given in le_atClient_SetIntermediateResponse() and le_atClient_SetFinalResponse() are the first characters of the response lines. They are used as a filter of the received lines (a line are the characters received between receiving a <CR> and an <LF>). Other lines are dropped.
- text can be set using le_atClient_SetText(). This is used for commands that answers a '>' character to receive additional information. The given text is sent to the modem when '>' is detected. The character
CTRL-Z
is automatically sent.
Sending
When the AT command declaration is complete, it can be sent using le_atClient_Send(). This API is synchronous (blocking until final response is detected, or timeout reached).
le_atClient_SetCommandAndSend() is equivalent to le_atClient_Create(), le_atClient_SetCommand(), le_atClient_SetDevice(), le_atClient_SetTimeout(), le_atClient_SetIntermediateResponse() and le_atClient_SetFinalResponse(), in case of an Error le_atClient_Delete(), in one API call. The AT command reference is created and returned by this API. When an error occurs the command reference is deleted and is not a valid reference anymore
Responses
When the AT command has been sent correctly (i.e., le_atClient_Send() or le_atClient_SetCommandAndSend() execution is successful), the app gets these AT command responses:
- le_atClient_GetFinalResponse() is used to get the final responses
- le_atClient_GetFirstIntermediateResponse() is used to get the first intermediate result code. Other intermediate result codes can be obtained by calling le_atClient_GetNextIntermediateResponse().Returns LE_NOT_FOUND when there are no further results.
When a response has been set in the AT command declaration, the AT command response returned by these APIs start with the given pattern, and ends when a <CR><LF> is detected.
Deleting
When the AT command is over, the reference has to be deleted by calling le_atClient_Delete().
Unsolicited Responses
An app can subscribe to a specific, unsolicited response using le_atClient_AddUnsolicitedResponseHandler(), and can be removed using le_atClient_RemoveUnsolicitedResponseHandler(). The subscribed handler is called when the given pattern is detected. The handler receives a parameter with the complete line of the unsolicited response. The parameter lineCount
is used to set the unsolicited lines number. For example, +CMT
unsolicited response has the following syntax:
+CMT: ...<CR><LF><sms text>
In this case, lineCount
has to be set to 2
to receive both lines into the handler. +CREG
unsolicited response is sent only one line, so lineCount
is set to 1
.
Copyright (C) Sierra Wireless Inc.