feat(update): 升级链路打通(0x7D+DevMac协议)+Boot参数配置迁移(MAC/服务器/Lora频率/通道)+清理死代码(SD/FatFS/utils/protocol/ringbuffer等) 软件版本V1.1

This commit is contained in:
2026-09-01 11:14:07 +08:00
parent 8bcc2c41d0
commit 68a5a185fc
134 changed files with 278 additions and 39180 deletions
+29 -106
View File
@@ -4,6 +4,7 @@
#include "LoraTask.h"
#include "RS485Task.h"
#include "DebugCmd.h"
#include "Update.h"
#include "spiflash.h"
@@ -18,17 +19,7 @@
// 81-00-00-06-00-09
// 81-00-00-06-00-0A
static const uint8_t GateWayMac_Test[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x00};
static const uint8_t GateWayMac_BL1[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x01};
static const uint8_t GateWayMac_BL2[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x02};
static const uint8_t GateWayMac_BL3[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x03};
static const uint8_t GateWayMac_BL4[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x04};
static const uint8_t GateWayMac_BL5[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x05};
static const uint8_t GateWayMac_BL6[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x06};
static const uint8_t GateWayMac_BL7[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x07};
static const uint8_t GateWayMac_BL8[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x08};
static const uint8_t GateWayMac_BL9[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x09};
static const uint8_t GateWayMac_BL10[6] = {0x81, 0x00, 0x00, 0x06, 0x00, 0x0A};
//网关MAC编码由Boot程序固定在0x4000(协议规定: VerInfo(1)+PrjNum(3)+GwNum(2))
bool MainDispEn = true;
static rt_thread_t Lora_Thread = RT_NULL;
@@ -83,11 +74,14 @@ void GateWayInit(void)
memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t));
boot_para_t bootParam;
dev_boot_read_param(&bootParam);
rt_kprintf("AppFlag: 0x%08x\r\n", bootParam.AppFlag);
if(bootParam.AppFlag == APP_BOOT_UPGRADE_FLAG) {
rt_kprintf("AppFlag: 0x%08x\r\n", bootParam.AppFlag);
/*升级完成后Boot会设AppFlag=APP_START_FLAG并清UpdateFlag=0,
检测到升级异常(UpdateFlag仍为APP_UPDATE_FLAG 或 非首次且AppFlag无效)时擦外置Flash*/
if(bootParam.UpdateFlag == APP_UPDATE_FLAG
|| (bootParam.FirstRunFlag == 0 && bootParam.AppFlag != APP_START_FLAG)) {
rt_kprintf("Boot upgrade detected, erasing external Flash...\r\n");
SpiFlashEraseChip();
bootParam.AppFlag = 0;
bootParam.UpdateFlag = 0;
dev_boot_write_param(bootParam);
}
@@ -95,72 +89,16 @@ void GateWayInit(void)
if(GateWay.ConfigPara.SavFlag != LOG_SAV_FLAG) {
memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t));
GateWay.ConfigPara.SavFlag = LOG_SAV_FLAG;
GateWay.ConfigPara.Much = CH_ETH;
GateWay.ConfigPara.Auch = CH_NULL;
GateWay.ConfigPara.Duch = CH_CAT1;
GateWay.ConfigPara.CuchMask = CUCH_LORA;
#if MAC_ADDR_TYPE == 0//测试服务器
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8080;
#elif MAC_ADDR_TYPE == 1
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8081;
#elif MAC_ADDR_TYPE == 2
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8082;
#elif MAC_ADDR_TYPE == 3
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8083;
#elif MAC_ADDR_TYPE == 4
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8084;
#elif MAC_ADDR_TYPE == 5
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8085;
#elif MAC_ADDR_TYPE == 6
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8086;
#elif MAC_ADDR_TYPE == 7
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8087;
#elif MAC_ADDR_TYPE == 8
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8088;
#elif MAC_ADDR_TYPE == 9
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8089;
#endif
/*通道/服务器等默认参数全部从Boot参数区(BootPara_t)获取, 由Boot直接配置*/
GateWay.ConfigPara.Much = (Channel_m)bootParam.Much;
GateWay.ConfigPara.Auch = (Channel_m)bootParam.Auch;
GateWay.ConfigPara.Duch = (Channel_m)bootParam.Duch;
GateWay.ConfigPara.CuchMask = bootParam.CuchMask;
GateWay.ConfigPara.LTENet.DestAddr[0] = bootParam.SvrAddr[0];
GateWay.ConfigPara.LTENet.DestAddr[1] = bootParam.SvrAddr[1];
GateWay.ConfigPara.LTENet.DestAddr[2] = bootParam.SvrAddr[2];
GateWay.ConfigPara.LTENet.DestAddr[3] = bootParam.SvrAddr[3];
GateWay.ConfigPara.LTENet.DestPort = bootParam.SvrPort;
GateWay.ConfigPara.CommUnitReadInterval = COMMUNIT_READ_SENSOR_INTERVAL_MAX;//非低功耗设备
memset(GateWay.ConfigPara.CommUnitArray, 0x00, sizeof(CommUnitData_t) * COMMUNIT_NUM_MAX);
GateWay.ConfigPara.Rs485Ch1.Enable = true;
@@ -183,34 +121,19 @@ void GateWayInit(void)
GateWay.ConfigPara.Lora.SpreadFactor = 9;
GateWay.ConfigPara.Lora.ErrorCoding = 2;
GateWay.ConfigPara.Lora.RegPreamble = 10;
GateWay.ConfigPara.Lora.FreqCent = FREQ_CENT;
GateWay.ConfigPara.Lora.FreqCent = bootParam.LoraFreq;
GateWay.ConfigPara.OutageFlag = false;
#if MAC_ADDR_TYPE == 0
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_Test, 6);
#elif MAC_ADDR_TYPE == 1
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL1, 6);
#elif MAC_ADDR_TYPE == 2
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL2, 6);
#elif MAC_ADDR_TYPE == 3
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL3, 6);
#elif MAC_ADDR_TYPE == 4
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL4, 6);
#elif MAC_ADDR_TYPE == 5
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL5, 6);
#elif MAC_ADDR_TYPE == 6
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL6, 6);
#elif MAC_ADDR_TYPE == 7
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL7, 6);
#elif MAC_ADDR_TYPE == 8
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL8, 6);
#elif MAC_ADDR_TYPE == 9
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL9, 6);
#elif MAC_ADDR_TYPE == 10
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL10, 6);
#endif
}
/*网关MAC编码从Boot参数区(BootPara_t.GwMac)获取, 由Boot从固定地址0x4000同步
(协议规定: Mac[0]=VerInfo, Mac[1:3]=PrjNum, Mac[4:5]=GwNum)*/
for(int i = 0; i < 6; i++) {
GateWay.ConfigPara.GwMac[i] = bootParam.GwMac[i];
}
/*参照hc32l170_app UpdateInit: 保证AppFlag=APP_START_FLAG, 使Boot下次直接跳转App*/
UpdateInit();
if(GateWay.ConfigPara.OutageFlag != true && GateWay.ConfigPara.OutageFlag != false)
GateWay.ConfigPara.OutageFlag = false;
@@ -539,7 +462,7 @@ int main(void)
if(SystemRseetDlyCnt > (24 * 60 * 60 * 1000)) {
SystemRseetDlyCnt = 0;
Debug_Printf("The system resets periodically.\r\n");
rt_thread_delay(10);
rt_thread_delay(3000);
NVIC_SystemReset();
}
rt_thread_delay(1);