feat(at): add UART baud AT commands
This commit is contained in:
+45
-1
@@ -143,6 +143,12 @@ UART 记号约定:
|
|||||||
- `U0 = USART2`
|
- `U0 = USART2`
|
||||||
- `U1 = USART3`
|
- `U1 = USART3`
|
||||||
|
|
||||||
|
### 7.4 BAUD 默认值
|
||||||
|
|
||||||
|
```text
|
||||||
|
BAUD = U0,115200 / U1,115200
|
||||||
|
```
|
||||||
|
|
||||||
## 8. AT 命令定义
|
## 8. AT 命令定义
|
||||||
|
|
||||||
### 8.1 测试设备在线
|
### 8.1 测试设备在线
|
||||||
@@ -239,7 +245,45 @@ OK
|
|||||||
|
|
||||||
当MAC设置为全0时,固件将使用硬件MAC地址,此时通过AT+?查询到的MAC地址即为当前生效的硬件MAC地址。
|
当MAC设置为全0时,固件将使用硬件MAC地址,此时通过AT+?查询到的MAC地址即为当前生效的硬件MAC地址。
|
||||||
|
|
||||||
### 8.5 LINK 类命令
|
### 8.5 BAUD 类命令
|
||||||
|
|
||||||
|
#### 查询 UART 波特率
|
||||||
|
|
||||||
|
```text
|
||||||
|
AT+BAUD?\r\n
|
||||||
|
```
|
||||||
|
|
||||||
|
返回示例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
+BAUD:U0=115200,U1=115200
|
||||||
|
OK
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 设置 UART 波特率
|
||||||
|
|
||||||
|
```text
|
||||||
|
AT+BAUD=U0,115200\r\n
|
||||||
|
AT+BAUD=U1,38400\r\n
|
||||||
|
```
|
||||||
|
|
||||||
|
字段顺序:
|
||||||
|
|
||||||
|
```text
|
||||||
|
UART,BAUDRATE
|
||||||
|
```
|
||||||
|
|
||||||
|
字段说明:
|
||||||
|
|
||||||
|
- `UART`:`U0/U1`
|
||||||
|
- `BAUDRATE`:范围 `1200~921600`
|
||||||
|
|
||||||
|
说明:
|
||||||
|
|
||||||
|
- 该命令只更新当前运行配置记录,不会立即重初始化 `USART2/USART3`
|
||||||
|
- 执行 `AT+SAVE` 后再执行 `AT+RESET`,重启时按保存值生效
|
||||||
|
|
||||||
|
### 8.6 LINK 类命令
|
||||||
|
|
||||||
#### 设置单条 LINK 记录
|
#### 设置单条 LINK 记录
|
||||||
|
|
||||||
|
|||||||
+44
-2
@@ -365,8 +365,8 @@ static at_result_t handle_summary_query(char *response, uint16_t max_len)
|
|||||||
g_config.links[2].enabled, g_config.links[2].local_port, rip_str[2], g_config.links[2].remote_port, link_uart_to_str(g_config.links[2].uart),
|
g_config.links[2].enabled, g_config.links[2].local_port, rip_str[2], g_config.links[2].remote_port, link_uart_to_str(g_config.links[2].uart),
|
||||||
g_config.links[3].enabled, g_config.links[3].local_port, rip_str[3], g_config.links[3].remote_port, link_uart_to_str(g_config.links[3].uart),
|
g_config.links[3].enabled, g_config.links[3].local_port, rip_str[3], g_config.links[3].remote_port, link_uart_to_str(g_config.links[3].uart),
|
||||||
g_config.mux_mode,
|
g_config.mux_mode,
|
||||||
g_config.uart_baudrate[0],
|
(unsigned long)g_config.uart_baudrate[0],
|
||||||
g_config.uart_baudrate[1]);
|
(unsigned long)g_config.uart_baudrate[1]);
|
||||||
|
|
||||||
return AT_OK;
|
return AT_OK;
|
||||||
}
|
}
|
||||||
@@ -386,6 +386,16 @@ static at_result_t handle_net_query(char *response, uint16_t max_len)
|
|||||||
return AT_OK;
|
return AT_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static at_result_t handle_baud_query(char *response, uint16_t max_len)
|
||||||
|
{
|
||||||
|
snprintf(response,
|
||||||
|
max_len,
|
||||||
|
"+BAUD:U0=%lu,U1=%lu\r\nOK\r\n",
|
||||||
|
(unsigned long)g_config.uart_baudrate[0],
|
||||||
|
(unsigned long)g_config.uart_baudrate[1]);
|
||||||
|
return AT_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static at_result_t handle_link_query(uint32_t index, char *response, uint16_t max_len)
|
static at_result_t handle_link_query(uint32_t index, char *response, uint16_t max_len)
|
||||||
{
|
{
|
||||||
char rip_str[16];
|
char rip_str[16];
|
||||||
@@ -556,6 +566,38 @@ at_result_t config_process_at_cmd(const char *cmd, char *response, uint16_t max_
|
|||||||
snprintf(response, max_len, "OK\r\n");
|
snprintf(response, max_len, "OK\r\n");
|
||||||
return AT_NEED_REBOOT;
|
return AT_NEED_REBOOT;
|
||||||
}
|
}
|
||||||
|
if (equals_ignore_case(p, "BAUD?")) {
|
||||||
|
return handle_baud_query(response, max_len);
|
||||||
|
}
|
||||||
|
if (parse_command_with_value(p, "BAUD", &value)) {
|
||||||
|
char value_copy[32];
|
||||||
|
char *cursor;
|
||||||
|
char *token;
|
||||||
|
uint8_t uart;
|
||||||
|
uint32_t baudrate;
|
||||||
|
|
||||||
|
strncpy(value_copy, value, sizeof(value_copy) - 1u);
|
||||||
|
value_copy[sizeof(value_copy) - 1u] = '\0';
|
||||||
|
cursor = value_copy;
|
||||||
|
|
||||||
|
token = config_next_token(&cursor);
|
||||||
|
if (token == NULL || parse_link_uart(token, &uart) != 0) {
|
||||||
|
snprintf(response, max_len, "ERROR: Invalid route field\r\n");
|
||||||
|
return AT_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
token = config_next_token(&cursor);
|
||||||
|
if (token == NULL || parse_u32_value(token, 1200u, 921600u, &baudrate) != 0) {
|
||||||
|
snprintf(response, max_len, "ERROR: Invalid baudrate\r\n");
|
||||||
|
return AT_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
if (config_next_token(&cursor) != NULL) {
|
||||||
|
snprintf(response, max_len, "ERROR: Invalid value\r\n");
|
||||||
|
return AT_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_config.uart_baudrate[uart] = baudrate;
|
||||||
|
return handle_baud_query(response, max_len) == AT_OK ? AT_NEED_REBOOT : AT_ERROR;
|
||||||
|
}
|
||||||
if (equals_ignore_case(p, "NET?")) {
|
if (equals_ignore_case(p, "NET?")) {
|
||||||
return handle_net_query(response, max_len);
|
return handle_net_query(response, max_len);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user