添加任意位置读取功能,以及批量读取结束指示

This commit is contained in:
Kinchin Fong 2023-09-15 18:29:08 +08:00
parent 73ff32ae38
commit 5d95ffc2f5
2 changed files with 12 additions and 4 deletions

View File

@ -47,7 +47,7 @@
|------|--------|---------|-------|-------|
| AT | AT | OK | OK | 测试串口是否连通 |
| AT+MSGREAD=? | AT+MSGREAD=? | `index`,`len`,`data` * 100/ERROR | 25,10,00AA02F556789098783E * 100 | 读取队头最多 100 条数据,并删除这些数据 |
| AT+MSGREAD=1 | AT+MSGREAD=1 | `index`,`len`,`data` * 100/ERROR | 25,10,00AA02F556789098783E * 100 | 从 Flash Index 0 的位置读 100 条数据 |
| AT+MSGREAD=`index` | AT+MSGREAD=100 | `index`,`len`,`data` * 100/ERROR | 25,10,00AA02F556789098783E * 100 | 从 Flash 的指定位置开始读 100 条数据,不影响队列指针 |
| AT+DEVIDREAD=? | AT+DEVIDREAD=? | `ID`/ERROR | NHND02458821 | 读取设备唯一序列号 |
| AT+DEVIDSET=`ID` | AT+DEVIDSET=NHND12222333 | OK/ERROR | OK | 写入设备唯一序列号 |
| AT+SYSCFGREAD=? | AT+SYSCFGREAD=? | `config`/ERROR | 0,9,6 | 读取配置 |

View File

@ -100,7 +100,9 @@ void UpperSerial::ParseCmd(String cmd)
int index = 0;
int ret = rec->PopData(index, dataLen, dataBuf);
if (ret != 0) {
if (ret != -4) {
if (ret == -4) {
Serial.printf("END\r\n");
} else {
Serial.printf("ERROR\r\n");
}
return;
@ -119,8 +121,14 @@ void UpperSerial::ParseCmd(String cmd)
Serial.printf("%s\r\n", result.c_str());
}
} else if (cmd == "MSGREAD=1") {
for (int i = 0; i < 100; i++) {
} else if (cmd.startsWith("MSGREAD") && cmd[strlen("MSGREAD")] == '=') {
String value = cmd.substring(strlen("MSGREAD") + 1);
int startIndex = (int)value.toInt();
if (startIndex >= RECORD_COUNT - 100 || startIndex < 0) {
Serial.printf("ERROR\r\n");
return;
}
for (int i = startIndex; i < startIndex + 100; i++) {
uint8_t dataBuf[RECORD_DATA_SIZE] = {0};
uint8_t dataLen = 0;
int ret;