mirror of
https://gitee.com/notrynohigh/BabyOS_Protocol.git
synced 2025-01-15 17:02:52 +08:00
1.支持固件升级的测试
This commit is contained in:
parent
badeee0abc
commit
bc915d6618
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.10.2, 2022-08-18T00:39:42. -->
|
||||
<!-- Written by QtCreator 4.10.2, 2022-08-21T16:58:29. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -18,7 +18,7 @@ extern "C" int Dispatch(bProtoID_t id, uint8_t cmd, uint8_t *param, bProtoLen_t
|
||||
*/
|
||||
#define CMD_TEST (0x1)
|
||||
#define CMD_SET_TIME (0x2)
|
||||
#define CMD_UPGRADE_START (0x3)
|
||||
#define CMD_FW_INFO (0x3)
|
||||
#define CMD_UPGRADE_DATA (0x4)
|
||||
#define CMD_UPGRADE_RESULT (0x5)
|
||||
|
||||
@ -109,7 +109,7 @@ void MainWindow::on_refreshButton_clicked()
|
||||
void MainWindow::TimerTimeout()
|
||||
{
|
||||
uint32_t len;
|
||||
uint8_t tmp_buf[1024];
|
||||
uint8_t tmp_buf[10240];
|
||||
len = uartModule.uartReadBuff(tmp_buf);
|
||||
tmp_buf[len] = '\0';
|
||||
if (len > 0)
|
||||
@ -195,6 +195,7 @@ int MainWindow::TransData(uint16_t num)
|
||||
((bin_file_len - index) >= 512) ? 512 : (bin_file_len - index));
|
||||
len = bProtocolPack(protocol_n, 0xFFFFFFFF, CMD_UPGRADE_DATA, (uint8_t *)&dat,
|
||||
sizeof(bUpgradeTransData_t), table);
|
||||
ui->recTEXT->append(hexToString(table, len));
|
||||
if (ui->encryptBox->isChecked() == true)
|
||||
{
|
||||
_bProtocolEncrypt(table, len);
|
||||
@ -213,6 +214,38 @@ int MainWindow::AckResult(uint8_t result)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief 返回固件信息
|
||||
*/
|
||||
int MainWindow::AckFwInfo()
|
||||
{
|
||||
bUpgradeStart_t info;
|
||||
uint8_t table[128];
|
||||
int len = 0;
|
||||
char *pfwname;
|
||||
memset(&info, 0, sizeof(bUpgradeStart_t));
|
||||
if (ui->filenameLable->text().isEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (ui->FwnamelineEdit->text().isEmpty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
pfwname = ui->FwnamelineEdit->text().toLatin1().data();
|
||||
info.file_size = bin_file_len;
|
||||
info.file_crc = bin_file_crc;
|
||||
memcpy(info.file_name, pfwname, (strlen(pfwname) > 63) ? 63 : strlen(pfwname));
|
||||
len = bProtocolPack(protocol_n, 0xFFFFFFFF, CMD_FW_INFO, (uint8_t *)&info,
|
||||
sizeof(bUpgradeStart_t), table);
|
||||
if (ui->encryptBox->isChecked() == true)
|
||||
{
|
||||
_bProtocolEncrypt(table, len);
|
||||
}
|
||||
uartModule.uartSendBuff(table, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief 协议解析的分发函数,在此函数,根据指令执行对应的操作
|
||||
*/
|
||||
@ -243,6 +276,11 @@ int Dispatch(bProtoID_t id, uint8_t cmd, uint8_t *param, bProtoLen_t param_len)
|
||||
tmpClass->AckResult(result);
|
||||
}
|
||||
break;
|
||||
case CMD_FW_INFO:
|
||||
{
|
||||
tmpClass->AckFwInfo();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -342,7 +380,7 @@ void MainWindow::on_upgradeBUTTON_clicked()
|
||||
info.file_size = bin_file_len;
|
||||
info.file_crc = bin_file_crc;
|
||||
memcpy(info.file_name, pfwname, (strlen(pfwname) > 63) ? 63 : strlen(pfwname));
|
||||
len = bProtocolPack(protocol_n, 0xFFFFFFFF, CMD_UPGRADE_START, (uint8_t *)&info,
|
||||
len = bProtocolPack(protocol_n, 0xFFFFFFFF, CMD_FW_INFO, (uint8_t *)&info,
|
||||
sizeof(bUpgradeStart_t), table);
|
||||
if (ui->encryptBox->isChecked() == true)
|
||||
{
|
||||
|
@ -22,6 +22,8 @@ public:
|
||||
int ShowLog(bProtoID_t id, uint8_t cmd, uint8_t *param, bProtoLen_t param_len);
|
||||
int TransData(uint16_t num);
|
||||
int AckResult(uint8_t result);
|
||||
int AckFwInfo(void);
|
||||
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
|
BIN
BearPi.bin
Normal file
BIN
BearPi.bin
Normal file
Binary file not shown.
48
README.md
48
README.md
@ -7,7 +7,9 @@
|
||||
| ----- | ------ | ------ | ----- | -------- | ----- |
|
||||
| 1Byte | 4Bytes | 2Bytes | 1Byte | 0~nBytes | 1Byte |
|
||||
|
||||
<!--上位机的设备ID为 0x1314-->
|
||||
`上位机的设备ID为 0x1314`
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
@ -17,6 +19,8 @@
|
||||
| ---- | ------------ |
|
||||
| 0x1 | "BabyOS" |
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
### 设置时间指令
|
||||
@ -25,63 +29,79 @@
|
||||
| ---- | ------------ |
|
||||
| 0x2 | UTC |
|
||||
|
||||
---
|
||||
|
||||
### 查询新固件信息
|
||||
|
||||
`(设备==>上位机)`
|
||||
|
||||
| 指令 | 参数(0Bytes) |
|
||||
| ---- | ------------ |
|
||||
| 0x3 | 无参数 |
|
||||
|
||||
|
||||
### 开始升级指令
|
||||
|
||||
<!--(上位机==>设备)-->
|
||||
### 新固件信息
|
||||
|
||||
`(上位机==>设备)`
|
||||
|
||||
| 指令 | 参数(72Bytes) |
|
||||
| ---- | ------------ |
|
||||
| 0x3 | 文件大小(4Bytes) CRC32校验值(4Bytes) 固件名(64Bytes)|
|
||||
<!--固件名长度不足64字节时,补0-->
|
||||
`固件名长度不足64字节时,补0`
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
### 请求分包数据指令
|
||||
|
||||
<!--(设备==>上位机)-->
|
||||
`(设备==>上位机)`
|
||||
|
||||
| 指令 | 参数(2Bytes) |
|
||||
| ---- | ------------ |
|
||||
| 0x4 | 分包序号(2Bytes)|
|
||||
<!--分包序号从0开始-->
|
||||
`分包序号从0开始`
|
||||
|
||||
|
||||
|
||||
### 回复分包数据指令
|
||||
|
||||
<!--(上位机==>设备)-->
|
||||
`(上位机==>设备)`
|
||||
|
||||
| 指令 | 参数(514Bytes) |
|
||||
| ---- | ------------ |
|
||||
| 0x4 | 分包序号(2Bytes) 数据长度(512Bytes)|
|
||||
<!--剩余长度不足512字节时,补0-->
|
||||
`剩余长度不足512字节时,补0`
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
||||
### 上报升级结果指令
|
||||
|
||||
<!--(设备==>上位机)-->
|
||||
`(设备==>上位机)`
|
||||
|
||||
| 指令 | 参数(1Bytes) |
|
||||
| ---- | ------------ |
|
||||
| 0x5 | 升级结果(1Bytes)|
|
||||
<!--校验成功:0-->
|
||||
<!--校验失败:1-->
|
||||
<!--固件名不匹配:2-->
|
||||
<!--文件长度不合理:3-->
|
||||
`校验成功:0`
|
||||
`校验失败:1`
|
||||
`固件名不匹配:2`
|
||||
`文件长度不合理:3`
|
||||
|
||||
|
||||
|
||||
### 确认升级结果指令
|
||||
|
||||
<!--(上位机==>设备)-->
|
||||
`(上位机==>设备)`
|
||||
|
||||
| 指令 | 参数(0Bytes) |
|
||||
| ---- | ------------ |
|
||||
| 0x5 | 无参数|
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user