diff --git a/BabyOS_Protocol/BabyOS_Protocol.pro.user b/BabyOS_Protocol/BabyOS_Protocol.pro.user index 0156a29..5776fe5 100644 --- a/BabyOS_Protocol/BabyOS_Protocol.pro.user +++ b/BabyOS_Protocol/BabyOS_Protocol.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/BabyOS_Protocol/mainwindow.cpp b/BabyOS_Protocol/mainwindow.cpp index 7c74736..fd6b92c 100644 --- a/BabyOS_Protocol/mainwindow.cpp +++ b/BabyOS_Protocol/mainwindow.cpp @@ -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) { diff --git a/BabyOS_Protocol/mainwindow.h b/BabyOS_Protocol/mainwindow.h index 3e2cbf9..e269d20 100644 --- a/BabyOS_Protocol/mainwindow.h +++ b/BabyOS_Protocol/mainwindow.h @@ -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: diff --git a/BearPi.bin b/BearPi.bin new file mode 100644 index 0000000..602c312 Binary files /dev/null and b/BearPi.bin differ diff --git a/README.md b/README.md index 6d49c32..6f7f126 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ | ----- | ------ | ------ | ----- | -------- | ----- | | 1Byte | 4Bytes | 2Bytes | 1Byte | 0~nBytes | 1Byte | - +`上位机的设备ID为 0x1314` + +--- @@ -17,6 +19,8 @@ | ---- | ------------ | | 0x1 | "BabyOS" | +--- + ### 设置时间指令 @@ -25,63 +29,79 @@ | ---- | ------------ | | 0x2 | UTC | +--- + +### 查询新固件信息 + +`(设备==>上位机)` + +| 指令 | 参数(0Bytes) | +| ---- | ------------ | +| 0x3 | 无参数 | -### 开始升级指令 - +### 新固件信息 + +`(上位机==>设备)` | 指令 | 参数(72Bytes) | | ---- | ------------ | | 0x3 | 文件大小(4Bytes) CRC32校验值(4Bytes) 固件名(64Bytes)| - +`固件名长度不足64字节时,补0` + +--- ### 请求分包数据指令 - +`(设备==>上位机)` | 指令 | 参数(2Bytes) | | ---- | ------------ | | 0x4 | 分包序号(2Bytes)| - +`分包序号从0开始` ### 回复分包数据指令 - +`(上位机==>设备)` | 指令 | 参数(514Bytes) | | ---- | ------------ | | 0x4 | 分包序号(2Bytes) 数据长度(512Bytes)| - +`剩余长度不足512字节时,补0` + +--- ### 上报升级结果指令 - +`(设备==>上位机)` | 指令 | 参数(1Bytes) | | ---- | ------------ | | 0x5 | 升级结果(1Bytes)| - - - - +`校验成功:0` +`校验失败:1` +`固件名不匹配:2` +`文件长度不合理:3` ### 确认升级结果指令 - +`(上位机==>设备)` | 指令 | 参数(0Bytes) | | ---- | ------------ | | 0x5 | 无参数| +--- + diff --git a/exe/BabyOS_Protocol.exe b/exe/BabyOS_Protocol.exe index 3ac124d..2299bf4 100644 Binary files a/exe/BabyOS_Protocol.exe and b/exe/BabyOS_Protocol.exe differ