AT command(V2) is an interactive component for managing AT command communication. It is suitable for Modem, WIFI module, Bluetooth and other scenarios that use AT command or ASCII command line communication. It covers most forms of AT communication, such as parameter setting, query, binary data sending, etc. It also supports interactive management of custom commands. Since each command request is asynchronous, it is also supported for non-operating system environments. Compared to the V1 version, the new version has a lot of optimization in command reception matching, URC variable length data capture, and memory security, allowing it to handle more complex product applications.
In order for AT commands to communicate properly, the target system must meet the following requirements:
The V1 version is divided into two modules, "at" module is only suitable for operating in the OS environment, while "at_chat" module is suitable for operating in the environment without an operating system. It adopts the way of pre-allocated memory to manage AT requests, and does not require dynamic memory support, which also limits its application scope. It also runs on the OS, but the support is not perfect. V2 version mainly optimizes the "at_chat" module as a whole, supports URC function, and also strengthens the support for OS environment. Since it uses dynamic memory to manage AT command requests, it has higher requirements on RAM resources, but it is more convenient to use.
If the platform RAM resources used (such as 8-bit microcontrollers) are limited and only used for simple AT communication, the V1 version is appropriate, while the V2 version is recommended if the RAM resources are sufficient.
The following is a brief introduction of how to use, 4 steps to complete:
/**
* @brief AT adapter
*/
static const at_adapter_t at_adapter = {
.lock = at_mutex_lock, //Multi-task lock (NULL for non-OS)
.unlock = at_mutex_unlock, //Multi-task unlock (NULL for non-OS)
.write = at_device_write, //Data write interface (non-blocking)
.read = at_device_read, //Data read interface (non-blocking)
.debug = at_debug, //Debug print interface (NULL if not needed)
.recv_bufsize = 256 //Receive buffer size (as required)
};
at_obj_t *at_obj;
//....
at_obj = at_obj_create(&at_adapter);
if (at_obj == NULL) {
printf("at object create failed\r\n");
}
//...
/**
* @brief Polling handler
*/
void at_device_process(void)
{
static unsigned int timer;
//To speed up the AT command processing response, you are advised to poll the AT command once within 5ms.
if (get_tick() - timer > 5) {
timer = get_tick();
at_obj_process(&at_obj);
}
}
After completing the above steps, you can run the AT command to request. The following uses querying the signal quality of the MODEM as an example to demonstrate how to send the AT command and parse the response content.
The command format is as follows:
=> AT+CSQ
<= +CSQ: <rssi>,<ber>
<= OK
Code:
/**
* @brief Command response handler
*/
static void csq_respose_callback(at_response_t *r)
{
int rssi, ber;
//+CSQ: <rssi>,<ber>
if (r->code == AT_RESP_OK) {
//After the command response is successful, extract rssi and ber
if (sscanf(r->prefix, "+CSQ:%d,%d", &rssi, &ber) == 2) {
printf("rssi:%d, ber:%d\r\n", rssi, ber);
}
} else {
printf("'CSQ' command response failed!\r\n");
}
}
/**
* @brief Send a read CSQ value request
*/
static void read_csq(void)
{
at_send_singlline(at_obj, csq_respose_callback, 1000, 0, "AT+CSQ");
}
Here is a rendering of it running on the M169 WIFI (example:at_chat/samples/none_os
)
For more application examples, check out the directory 'at_chat/samples', which provides examples of several typical platforms.
Take Linux as an example. You can run the AT communication emulator by running the following command:
cd ./at_chat/samples/linux
make clean & make
./output/demo
If you are using vscode, go directly to the samples/linux directory and press F5 to start running.
If the program runs properly, you will see the following information printed on the terminal:
*******************************************************
This is an asynchronous AT command framework.
Author:roger.luo, Mail:morro_luo@163.com
*******************************************************
Please input test item:
1:Display memory information.
2:Testing singlline command.
3:Testing multiline commands.
4:Testing variable parameter command.
5:Testing response timeout retry.
6:Testing response error retry.
7:Testing command abort.
8:Testing specific response prefix.
9:Testing custom command.
10:Testing buffer send.
11:Testing 'at_do_work' 1.
12:Testing read binary data via 'at work'.
13:Testing capture unsolicited binary data.
14:Testing at context interface.
*******************************************************
<=
+POWER:1
...
Device power on event detected!
Following the command line prompts, enter the serial number and press enter to verify the corresponding use case.
For more detailed instructions, please refer to:
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
Activity
Community
Health
Trend
Influence
:Code submit frequency
:React/respond to issue & PR etc.
:Well-balanced team members and collaboration
:Recent popularity of project
:Star counts, download counts etc.