1.支持固件升级的测试

This commit is contained in:
yyds 2022-08-21 21:27:19 +08:00
parent badeee0abc
commit bc915d6618
6 changed files with 78 additions and 18 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -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_TEST (0x1)
#define CMD_SET_TIME (0x2) #define CMD_SET_TIME (0x2)
#define CMD_UPGRADE_START (0x3) #define CMD_FW_INFO (0x3)
#define CMD_UPGRADE_DATA (0x4) #define CMD_UPGRADE_DATA (0x4)
#define CMD_UPGRADE_RESULT (0x5) #define CMD_UPGRADE_RESULT (0x5)
@ -109,7 +109,7 @@ void MainWindow::on_refreshButton_clicked()
void MainWindow::TimerTimeout() void MainWindow::TimerTimeout()
{ {
uint32_t len; uint32_t len;
uint8_t tmp_buf[1024]; uint8_t tmp_buf[10240];
len = uartModule.uartReadBuff(tmp_buf); len = uartModule.uartReadBuff(tmp_buf);
tmp_buf[len] = '\0'; tmp_buf[len] = '\0';
if (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)); ((bin_file_len - index) >= 512) ? 512 : (bin_file_len - index));
len = bProtocolPack(protocol_n, 0xFFFFFFFF, CMD_UPGRADE_DATA, (uint8_t *)&dat, len = bProtocolPack(protocol_n, 0xFFFFFFFF, CMD_UPGRADE_DATA, (uint8_t *)&dat,
sizeof(bUpgradeTransData_t), table); sizeof(bUpgradeTransData_t), table);
ui->recTEXT->append(hexToString(table, len));
if (ui->encryptBox->isChecked() == true) if (ui->encryptBox->isChecked() == true)
{ {
_bProtocolEncrypt(table, len); _bProtocolEncrypt(table, len);
@ -213,6 +214,38 @@ int MainWindow::AckResult(uint8_t result)
return 0; 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 * \brief
*/ */
@ -243,6 +276,11 @@ int Dispatch(bProtoID_t id, uint8_t cmd, uint8_t *param, bProtoLen_t param_len)
tmpClass->AckResult(result); tmpClass->AckResult(result);
} }
break; break;
case CMD_FW_INFO:
{
tmpClass->AckFwInfo();
}
break;
} }
return 0; return 0;
} }
@ -342,7 +380,7 @@ void MainWindow::on_upgradeBUTTON_clicked()
info.file_size = bin_file_len; info.file_size = bin_file_len;
info.file_crc = bin_file_crc; info.file_crc = bin_file_crc;
memcpy(info.file_name, pfwname, (strlen(pfwname) > 63) ? 63 : strlen(pfwname)); 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); sizeof(bUpgradeStart_t), table);
if (ui->encryptBox->isChecked() == true) if (ui->encryptBox->isChecked() == true)
{ {

View File

@ -22,6 +22,8 @@ public:
int ShowLog(bProtoID_t id, uint8_t cmd, uint8_t *param, bProtoLen_t param_len); int ShowLog(bProtoID_t id, uint8_t cmd, uint8_t *param, bProtoLen_t param_len);
int TransData(uint16_t num); int TransData(uint16_t num);
int AckResult(uint8_t result); int AckResult(uint8_t result);
int AckFwInfo(void);
~MainWindow(); ~MainWindow();
private slots: private slots:

BIN
BearPi.bin Normal file

Binary file not shown.

View File

@ -7,7 +7,9 @@
| ----- | ------ | ------ | ----- | -------- | ----- | | ----- | ------ | ------ | ----- | -------- | ----- |
| 1Byte | 4Bytes | 2Bytes | 1Byte | 0~nBytes | 1Byte | | 1Byte | 4Bytes | 2Bytes | 1Byte | 0~nBytes | 1Byte |
<!--上位机的设备ID为 0x1314--> `上位机的设备ID为 0x1314`
---
@ -17,6 +19,8 @@
| ---- | ------------ | | ---- | ------------ |
| 0x1 | "BabyOS" | | 0x1 | "BabyOS" |
---
### 设置时间指令 ### 设置时间指令
@ -25,63 +29,79 @@
| ---- | ------------ | | ---- | ------------ |
| 0x2 | UTC | | 0x2 | UTC |
---
### 查询新固件信息
`(设备==>上位机)`
| 指令 | 参数(0Bytes) |
| ---- | ------------ |
| 0x3 | 无参数 |
### 开始升级指令
<!--(上位机==>设备)--> ### 新固件信息
`(上位机==>设备)`
| 指令 | 参数(72Bytes) | | 指令 | 参数(72Bytes) |
| ---- | ------------ | | ---- | ------------ |
| 0x3 | 文件大小4Bytes CRC32校验值(4Bytes) 固件名64Bytes| | 0x3 | 文件大小4Bytes CRC32校验值(4Bytes) 固件名64Bytes|
<!--固件名长度不足64字节时补0--> `固件名长度不足64字节时补0`
---
### 请求分包数据指令 ### 请求分包数据指令
<!--(设备==>上位机)--> `(设备==>上位机)`
| 指令 | 参数(2Bytes) | | 指令 | 参数(2Bytes) |
| ---- | ------------ | | ---- | ------------ |
| 0x4 | 分包序号2Bytes| | 0x4 | 分包序号2Bytes|
<!--分包序号从0开始--> `分包序号从0开始`
### 回复分包数据指令 ### 回复分包数据指令
<!--(上位机==>设备)--> `(上位机==>设备)`
| 指令 | 参数(514Bytes) | | 指令 | 参数(514Bytes) |
| ---- | ------------ | | ---- | ------------ |
| 0x4 | 分包序号2Bytes 数据长度512Bytes| | 0x4 | 分包序号2Bytes 数据长度512Bytes|
<!--剩余长度不足512字节时补0--> `剩余长度不足512字节时补0`
---
### 上报升级结果指令 ### 上报升级结果指令
<!--(设备==>上位机)--> `(设备==>上位机)`
| 指令 | 参数(1Bytes) | | 指令 | 参数(1Bytes) |
| ---- | ------------ | | ---- | ------------ |
| 0x5 | 升级结果1Bytes| | 0x5 | 升级结果1Bytes|
<!--校验成功0--> `校验成功0`
<!--校验失败1--> `校验失败1`
<!--固件名不匹配2--> `固件名不匹配2`
<!--文件长度不合理3--> `文件长度不合理3`
### 确认升级结果指令 ### 确认升级结果指令
<!--(上位机==>设备)--> `(上位机==>设备)`
| 指令 | 参数(0Bytes) | | 指令 | 参数(0Bytes) |
| ---- | ------------ | | ---- | ------------ |
| 0x5 | 无参数| | 0x5 | 无参数|
---

Binary file not shown.