RT-Thread 軟件包-軟件包分類-IoT-AT device①
# AT device #
中文頁 | 英文頁
1. 簡介
AT device 軟件包是由 RT-Thread AT 組件針對不同 AT 設備的移植文件和示例代碼組成,目前支持的 AT 設備有:ESP8266、ESP32、M26、MC20、RW007、MW31、SIM800C、W60X 、SIM76XX、A9/A9G、BC26 、AIR720、ME3616、M6315、BC28、EC200X、M5311、L610系列設備等,目前上述設備都完成對 AT socket
功能的移植,及設備通過 AT 命令實現標準 socket 編程接口,完成 socket 通訊的功能,具體功能介紹可參考 《RT-Thread 編程指南》AT 命令章節(jié) 。
1.1. 目錄結構
名稱 | 說明 |
---|---|
src | AT device 實現源碼目錄 |
inc | AT device 頭文件目錄 |
sample | 不同設備示例文件目錄 |
class | 不同設備針對 AT 組件的移植適配目錄 |
class/esp8266 | ESP8266 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/esp32 | ESP32 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/rw007 | RW007 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/sim800c | SIM800C 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/sim76xx | SIM76XX 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/m26 | M26/MC20 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/ec20 | EC20 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/mw31 | MW31 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/w60x | W60X 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/a9g | A9G 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/bc26 | bc26 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/air720 | air720 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/me3616 | me3616 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/m6315 | m6315 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/bc28 | bc28 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/ec200x | EC200T、EC200S 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/n21 | N21 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/n58 | N58 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/m5311 | M5311 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/l610 | L610 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
class/ml305 | ML305 設備針對 AT 組件的移植目錄,實現 AT Socket 功能 |
1.2 許可證
詳見 LICENSE
文件。
1.3 依賴
- RT_Thread 4.0.2+
- RT_Thread AT 組件 1.3.0+
- RT_Thread SAL 組件
- RT-Thread netdev 組件
2. 獲取方式
AT device 軟件包是對 AT 組件和 AT socket 功能的移植,需開啟 AT 組件庫和 AT socket 功能來獲取 AT device 軟件包。
版本號說明
AT device 軟件包目前已經發(fā)布多個版本,各個版本之間選項配置方式和其對應的系統版本有所不同,下面主要列出當前可使用的軟件包版本信息:
- V1.2.0:適用于 RT-Thread 版本小于 V3.1.3,AT 組件版本等于 V1.0.0;
- V1.3.0:適用于 RT-Thread 版本小于 V3.1.3,AT 組件版本等于 V1.1.0;
- V1.4.0:適用于 RT-Thread 版本小于 V3.1.3或等于 V4.0.0, AT 組件版本等于 V1.2.0;
- V1.5.0:適用于 RT-Thread 版本小于 V3.1.3 或等于 V4.0.0, AT 組件版本等于 V1.2.0;
- V1.6.0:適用于 RT-Thread 版本等于 V3.1.3 或等于 V4.0.1, AT 組件版本等于 V1.2.0;
- V2.0.0/V2.0.1:適用于 RT-Thread 版本大于 V4.0.1 或者大于 3.1.3, AT 組件版本等于 V1.3.0;
- latest:只適用于 RT-Thread 版本大于 V4.0.1 或者大于 3.1.3, AT 組件版本等于 V1.3.0;
上述 版本判斷在 menuconfig 中自動完成,at_device 軟件包選擇版本時會根據當前系統環(huán)境給出最佳版本支持,這里版本介紹作為運行環(huán)境參考。
針對不同的版本號,在 ENV 中的選項配置也有所不同,主要分為如下幾部分:
V1.X.X 版本配置選項介紹
開啟 AT device 軟件包,該版本只支持同時開啟一種 AT 設備, 配置選項具體如下所示:
RT-Thread online packages --->
IoT - internet of things --->
-*- AT DEVICE: RT-Thread AT component porting or samples for different device
[ ] Enable at device init by thread
AT socket device modules (Not selected, please select) --->
Version (V1.6.0) --->
- Enable at device init by thread: 配置開啟設備網絡初始化是否通過創(chuàng)建線程完成;
- AT socket device modules: AT 設備選擇,目前僅支持 RW007、ESP8266、M26/MC20、EC20、SIM800C、SIM76XX;更多的設備支持請選擇 V2.X.X 分支。
- Version: 下載軟件包版本;
V2.X.X (latest) 版本配置選項介紹
開啟 AT device 軟件包,該版本支持同時開啟多種 AT 設備配置選項具體如下所示:
RT-Thread online packages --->
IoT - internet of things --->
-*- AT DEVICE: RT-Thread AT component porting or samples for different device
[*] Quectel M26/MC20 --->
[*] Enable initialize by thread
[*] Enable sample
(-1) Power pin
(-1) Power status pin
(uart3) AT client device name
(512) The maximum length of receive line buffer
[ ] Quectel EC20 --->
[ ] Espressif ESP32 --->
[*] Espressif ESP8266 --->
[*] Enable initialize by thread
[*] Enable sample
(realthread) WIFI ssid
(12345678) WIFI password
(uart2) AT client device name
(512) The maximum length of receive line buffer
[ ] Realthread RW007 --->
[ ] SIMCom SIM800C --->
[ ] SIMCom SIM76XX --->
[ ] Notion MW31 --->
[ ] WinnerMicro W60X --->
[ ] AiThink A9/A9G --->
[ ] Quectel BC26 --->
[ ] Luat air720 --->
[ ] GOSUNCN ME3616 --->
[ ] ChinaMobile M6315 --->
[ ] Quectel BC28 --->
[ ] Quectel ec200x --->
[ ] Neoway N21 --->
[ ] Neoway N58 --->
[ ] ChinaMobile M5311 --->
[ ] ChinaMobile ML305 --->
Version (latest) --->
-
Quectel M26/MC20:開啟 M20/MC20(2G 模塊)設備支持;
- Enable initialize by thread:開啟使用線程進行設備初始化功能(非阻塞模式初始化);
- Enable sample:開啟示例代碼,該示例代碼中有對示例設備的注冊;
- Power pin:配置該示例設備上電引腳;
- Power status pin:配置該示例設備上電狀態(tài)引腳;
- AT client device name:配置該示例設備使用的串口設備名稱;
- The maximum length of receive line buffer:配置該示例設備最大一行接收的數據長度;
- Quectel EC20:開啟 EC20(4G 模塊)設備支持;
-
Espressif ESP8266:開啟 ESP8266 (WIFI 模塊)設備支持;
- Enable initialize by thread:開啟使用線程進行設備初始化功能(非阻塞模式初始化);
- Enable sample:開啟示例代碼,該示例代碼中有對示例設備的注冊;
- WIFI ssid:配置該示例設備連接的 WIFI 用戶名;
- WIFI password:配置該示例設備連接的 WIFI 密碼;
- AT client device name:配置該示例設備使用的串口設備名稱;
- The maximum length of receive line buffer:配置該示例設備最大一行接收的數據長度;
- Espressif ESP32:開啟 ESP32 (WIFI 模塊)設備支持;
- Realthread RW007:開啟 RW007 (WIFI 模塊)設備支持;
- SIMCom SIM800C:開啟 SIM800C (2G 模塊)設備支持;
- SIMCom SIM76XX:開啟 SIM76XX (4G 模塊)設備支持;
- Notion MW31:開啟 MW31 (WIFI 模塊)設備支持;
- WinnerMicro W60X:開啟 W60X (WIFI 模塊)設備支持;
- AiThink A9/A9G:開啟 A9/A9G (2G 模塊)設備支持;
- Quectel BC26:開啟 BC26(NB-IOT 模塊)設備支持;
- Luat Air720:開啟 air720(4g 模塊)設備支持;
- GOSUNCN ME3616:開啟 ME3616(NB-IOT 模塊)設備支持;
- ChinaMobile M6315:開啟 M6315 (2G 模塊)設備支持;
- Quectel BC28:開啟 BC28(NB-IoT 模塊)設備支持;
- Quectel EC200X:開啟 EC200T、EC200S(4G 模塊)設備支持;
- Neoway N21:開啟 N21(NB-IoT 模塊)設備支持;
- Neoway N58:開啟 N58(4G 模塊)設備支持;
- ChinaMobile M5311:開啟 M5311(NB-IoT 模塊)設備支持;
- ChinaMobile ML305:開啟 ML305(4G 模塊)設備支持;
- Version 下載軟件包版本;
上面配置選項以 2G 模塊和 WIFI 模塊選項為例,介紹了V2.X.X
版本 AT device 軟件包配置方式,如下幾點值得注意:
-
V2.X.X
版本支持同時開啟多個 AT 設備,可以在 FinSH 中通過ifocnfig
命令查看開啟的設備信息; -
V2.X.X
版本設備需要注冊之后才可使用,目前在 samples 目錄文件中完成設備注冊,用戶也可以在應用層自定義設備注冊。 -
Power pin
和Power status pin
等引腳選項根據具體設備硬件連接情況配置,如果不使用硬件上電功能,可以配置為-1
; - 一個 AT 設備對應一個串口名稱,及每個設備配置的
AT client device name
應該都不相同。
AT 組件相關配置選項介紹
選中 AT device 軟件包并開啟相關設備支持之后,會默認選中 AT 組件的客戶端功能,下面是 AT 組件配置選項,
RT-Thread Components --->
Network --->
AT commands --->
[ ] Enable debug log output
[ ] Enable AT commands server
-*- Enable AT commands client
(1) The maximum number of supported clients
-*- Enable BSD Socket API support by AT commnads
[*] Enable CLI(Command-Line Interface) for AT commands
[ ] Enable print RAW format AT command communication data
(128) The maximum lenght of AT Commonds buffe
其中和 AT device 軟件包相關的配置選項:文章來源:http://www.zghlxwxcb.cn/news/detail-812398.html
- The maximum number of supported clients:最大支持的同時開啟的 AT 客戶端數量(AT device 軟件包中選中多個設備需要配置該選項為對應數值);
- Enable BSD Socket API support by AT commnads:開啟 AT Socket 功能支持,選中 AT device 軟件包默認選中該選項;
- The maximum lenght of AT Commonds buffe:最大支持的發(fā)送命令數據的長度。
3. 注意事項
- AT device 軟件包適配的模塊暫時不支持作為 TCP Server 完成服務器相關操作(如 accept 等);
- AT device 軟件包默認設備類型為未選擇,使用時需要指定使用設備型號;
-
latest
版本支持多個選中多個 AT 設備接入實現 AT Socket 功能,V1.X.X
版本只支持單個 AT 設備接入。 - AT device 軟件包目前多個版本主要用于適配 AT 組件和系統的改動,推薦使用最新版本 RT-Thread 系統,并在 menuconfig 選項中選擇
latest
版本; - 請參考
at_sample_xxx.c
中說明,部分功能需要增加AT_CMD_MAX_LEN
、RT_SERIAL_RB_BUFSZ
設定值大小。
4. 相關文檔
- AT 組件編程指南
- 應用 AT 組件連接 ESP8266 模塊
示例代碼
…\src\at_device.c文章來源地址http://www.zghlxwxcb.cn/news/detail-812398.html
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-05-08 chenyong first version
*/
#include <stdlib.h>
#include <string.h>
#include <at_device.h>
#define DBG_TAG "at.dev"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
/* The global list of at device */
static rt_slist_t at_device_list = RT_SLIST_OBJECT_INIT(at_device_list);
/* The global list of at device class */
static rt_slist_t at_device_class_list = RT_SLIST_OBJECT_INIT(at_device_class_list);
/**
* This function will get the first initialized AT device.
*
* @return the AT device structure pointer
*/
struct at_device *at_device_get_first_initialized(void)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct at_device *device = RT_NULL;
level = rt_hw_interrupt_disable();
rt_slist_for_each(node, &at_device_list)
{
device = rt_slist_entry(node, struct at_device, list);
if (device && device->is_init == RT_TRUE)
{
rt_hw_interrupt_enable(level);
return device;
}
}
rt_hw_interrupt_enable(level);
return RT_NULL;
}
/**
* This function will get AT device by device name.
*
* @param type the name type
* @param name the device name or the client name
*
* @return the AT device structure pointer
*/
struct at_device *at_device_get_by_name(int type, const char *name)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct at_device *device = RT_NULL;
RT_ASSERT(name);
level = rt_hw_interrupt_disable();
rt_slist_for_each(node, &at_device_list)
{
device = rt_slist_entry(node, struct at_device, list);
if (device)
{
if (((type == AT_DEVICE_NAMETYPE_DEVICE) || (type == AT_DEVICE_NAMETYPE_NETDEV)) &&
(rt_strncmp(device->name, name, rt_strlen(name)) == 0))
{
rt_hw_interrupt_enable(level);
return device;
}
else if ((type == AT_DEVICE_NAMETYPE_CLIENT) &&
(rt_strncmp(device->client->device->parent.name, name, rt_strlen(name)) == 0))
{
rt_hw_interrupt_enable(level);
return device;
}
}
}
rt_hw_interrupt_enable(level);
return RT_NULL;
}
#ifdef AT_USING_SOCKET
/**
* This function will get AT device by ip address.
*
* @param ip_addr input ip address
* network
* @return != NULL: network interface device object
* NULL: get failed
*/
struct at_device *at_device_get_by_ipaddr(ip_addr_t *ip_addr)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct at_device *device = RT_NULL;
level = rt_hw_interrupt_disable();
rt_slist_for_each(node, &at_device_list)
{
device = rt_slist_entry(node, struct at_device, list);
if (device && ip_addr_cmp(ip_addr, &(device->netdev->ip_addr)))
{
rt_hw_interrupt_enable(level);
return device;
}
}
rt_hw_interrupt_enable(level);
return RT_NULL;
}
#endif /* AT_USING_SOCKET */
/**
* This function will perform a variety of control functions on AT devices.
*
* @param device the pointer of AT device structure
* @param cmd the command sent to AT device
* @param arg the argument of command
*
* @return = 0: perform successfully
* < 0: perform failed
*/
int at_device_control(struct at_device *device, int cmd, void *arg)
{
if (device->class->device_ops->control)
{
return device->class->device_ops->control(device, cmd, arg);
}
else
{
LOG_W("AT device(%s) not support control operations.", device->name);
return RT_EOK;
}
}
/**
* This function registers an AT device class with specified device class ID.
*
* @param class the pointer of AT device class structure
* @param class_id AT device class ID
*
* @return 0: register successfully
*/
int at_device_class_register(struct at_device_class *class, uint16_t class_id)
{
rt_base_t level;
RT_ASSERT(class);
/* Fill AT device class */
class->class_id = class_id;
/* Initialize current AT device class single list */
rt_slist_init(&(class->list));
level = rt_hw_interrupt_disable();
/* Add current AT device class to list */
rt_slist_append(&at_device_class_list, &(class->list));
rt_hw_interrupt_enable(level);
return RT_EOK;
}
/* Get AT device class by client ID */
static struct at_device_class *at_device_class_get(uint16_t class_id)
{
rt_base_t level;
rt_slist_t *node = RT_NULL;
struct at_device_class *class = RT_NULL;
level = rt_hw_interrupt_disable();
/* Get AT device class by class ID */
rt_slist_for_each(node, &at_device_class_list)
{
class = rt_slist_entry(node, struct at_device_class, list);
if (class && class->class_id == class_id)
{
rt_hw_interrupt_enable(level);
return class;
}
}
rt_hw_interrupt_enable(level);
return RT_NULL;
}
/**
* This function registers an AT device with specified device name and AT client name.
*
* @param device the pointer of AT device structure
* @param device_name AT device name
* @param at_client_name AT device client name
* @param class_id AT device class ID
* @param user_data user-specific data
*
* @return = 0: register successfully
* < 0: register failed
*/
int at_device_register(struct at_device *device, const char *device_name,
const char *at_client_name, uint16_t class_id, void *user_data)
{
rt_base_t level;
int result = 0;
static int device_counts = 0;
char name[RT_NAME_MAX] = {0};
struct at_device_class *class = RT_NULL;
RT_ASSERT(device);
RT_ASSERT(device_name);
RT_ASSERT(at_client_name);
class = at_device_class_get(class_id);
if (class == RT_NULL)
{
LOG_E("get AT device class(%d) failed.", class_id);
result = -RT_ERROR;
goto __exit;
}
/* Fill AT device object*/
#ifdef AT_USING_SOCKET
device->sockets = (struct at_socket *) rt_calloc(class->socket_num, sizeof(struct at_socket));
if (device->sockets == RT_NULL)
{
LOG_E("no memory for AT Socket number(%d) create.", class->socket_num);
result = -RT_ENOMEM;
goto __exit;
}
/* create AT device socket event */
rt_snprintf(name, RT_NAME_MAX, "at_se%d", device_counts++);
device->socket_event = rt_event_create(name, RT_IPC_FLAG_FIFO);
if (device->socket_event == RT_NULL)
{
LOG_E("no memory for AT device(%s) socket event create.", device_name);
result = -RT_ENOMEM;
goto __exit;
}
#endif /* AT_USING_SOCKET */
rt_memcpy(device->name, device_name, rt_strlen(device_name));
device->class = class;
device->user_data = user_data;
/* Initialize current AT device single list */
rt_slist_init(&(device->list));
level = rt_hw_interrupt_disable();
/* Add current AT device to device list */
rt_slist_append(&at_device_list, &(device->list));
rt_hw_interrupt_enable(level);
/* Initialize AT device */
result = class->device_ops->init(device);
if (result < 0)
{
goto __exit;
}
__exit:
if (result < 0)
{
device->is_init = RT_FALSE;
}
else
{
device->is_init = RT_TRUE;
}
return result;
}
維護人:
- 華為奮斗者精神, 郵箱:1992152446@qq.com
到了這里,關于RT-Thread 軟件包-軟件包分類-IoT-AT device①的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!