1、Algorithm文件的isAllZero函数改为可改对比参数的is_all_byte

2、针对旧版本boot程序的升级兼容
This commit is contained in:
2026-05-11 18:23:00 +08:00
parent 9b06145341
commit f3205e1cf7
5 changed files with 48 additions and 22 deletions
+4 -4
View File
@@ -157,18 +157,18 @@
<Bp> <Bp>
<Number>0</Number> <Number>0</Number>
<Type>0</Type> <Type>0</Type>
<LineNumber>43</LineNumber> <LineNumber>60</LineNumber>
<EnabledFlag>1</EnabledFlag> <EnabledFlag>1</EnabledFlag>
<Address>41708</Address> <Address>15478</Address>
<ByteObject>0</ByteObject> <ByteObject>0</ByteObject>
<HtxType>0</HtxType> <HtxType>0</HtxType>
<ManyObjects>0</ManyObjects> <ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject> <SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess> <BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount> <BreakIfRCount>1</BreakIfRCount>
<Filename>..\source\src\Update.c</Filename> <Filename>..\source\Src\main.c</Filename>
<ExecCommand></ExecCommand> <ExecCommand></ExecCommand>
<Expression>\\hc32l17x\../source/src/Update.c\43</Expression> <Expression>\\hc32l17x\../source/Src/main.c\60</Expression>
</Bp> </Bp>
</Breakpoint> </Breakpoint>
<WatchWindow1> <WatchWindow1>
+1 -1
View File
@@ -48,7 +48,7 @@ bool count_greater(int32_t *arr, uint8_t size, int32_t target);
bool count_smaller(int32_t *arr, uint8_t size, int32_t target); bool count_smaller(int32_t *arr, uint8_t size, int32_t target);
uint16_t CRC_Modbus(uint16_t wBase, uint8_t *para, uint16_t length); uint16_t CRC_Modbus(uint16_t wBase, uint8_t *para, uint16_t length);
uint8_t CRC_Sum(uint8_t *_pbuff, uint16_t _cmdLen); uint8_t CRC_Sum(uint8_t *_pbuff, uint16_t _cmdLen);
bool isAllZero(uint8_t *arr, int size); bool is_all_byte(const uint8_t *data, size_t len, uint8_t val);
#endif #endif
+13 -13
View File
@@ -729,23 +729,23 @@ uint8_t CRC_Sum(uint8_t *_pbuff, uint16_t _cmdLen)
return cmd_sum; return cmd_sum;
} }
/***************************************************************************************** /**
* 函数名称: isAllZero * @brief 检查缓冲区是否全部等于指定字节值
* 功能描述: 判断一个数组的值是否全部为0 * @param data : 待检查的数据指针
* : arr,数组 * @param len : 数据长度(字节数)
size,长度 * @param val : 期望的字节值 (0x00 ~ 0xFF)
* 返 回 值: true或false * @return true : 全部等于 val
*****************************************************************************************/ * false: 存在不等于 val 的字节
bool isAllZero(uint8_t *arr, int size) */
bool is_all_byte(const uint8_t *data, size_t len, uint8_t val)
{ {
for (int i = 0; i < size; i++) { for (size_t i = 0; i < len; i++) {
if (arr[i] != 0) { if (data[i] != val) {
return false; // 如果数组中有一个元素不为0,则返回false return false;
} }
} }
return true; // 遍历完数组后,若所有元素都为0,则返回true return true;
} }
/***************************************************************************************** /*****************************************************************************************
* 函数名称: HexToAscii * 函数名称: HexToAscii
* 功能描述: 16进制转ASCII码 * 功能描述: 16进制转ASCII码
+3 -3
View File
@@ -881,7 +881,7 @@ static void GWRevHandler(void)
if(memcmp(GFHeader->MDAddr, LocalMAC, sizeof(GFHeader->MDAddr)) != false) if(memcmp(GFHeader->MDAddr, LocalMAC, sizeof(GFHeader->MDAddr)) != false)
{ {
if(isAllZero(GFHeader->MDAddr, sizeof(GFHeader->MDAddr)) != true) if(is_all_byte(GFHeader->MDAddr, sizeof(GFHeader->MDAddr), 0x00) != true)
{ {
DBG_LOG("Gateway Master Device MAC Err...\r\n"); DBG_LOG("Gateway Master Device MAC Err...\r\n");
return; return;
@@ -1725,7 +1725,7 @@ void GwRevLoopHandler(void)
memcpy(&SGCP.DeviceData[SGCP.DeviceDataLen], &SGCP.DevData.LaserTracing.MasterDev, sizeof(SGCP.DevData.LaserTracing.MasterDev)); memcpy(&SGCP.DeviceData[SGCP.DeviceDataLen], &SGCP.DevData.LaserTracing.MasterDev, sizeof(SGCP.DevData.LaserTracing.MasterDev));
SGCP.DeviceDataLen += sizeof(SGCP.DevData.LaserTracing.MasterDev); SGCP.DeviceDataLen += sizeof(SGCP.DevData.LaserTracing.MasterDev);
if(isAllZero(LocalDataPack, LocalDataLen) == false) if(is_all_byte(LocalDataPack, LocalDataLen, 0x00) == false)
{ {
memcpy(&SGCP.DeviceData[SGCP.DeviceDataLen], LocalDataPack, sizeof(LocalDataPack)); memcpy(&SGCP.DeviceData[SGCP.DeviceDataLen], LocalDataPack, sizeof(LocalDataPack));
SGCP.DeviceDataLen = SGCP.DeviceDataLen + DevGetDataMess(LocalType, LocalDataPack);; SGCP.DeviceDataLen = SGCP.DeviceDataLen + DevGetDataMess(LocalType, LocalDataPack);;
@@ -1778,7 +1778,7 @@ void GwRevLoopHandler(void)
SGCP.DeviceMAC[SGCP.ReadDataAdd][0],SGCP.DeviceMAC[SGCP.ReadDataAdd][1],SGCP.DeviceMAC[SGCP.ReadDataAdd][2], SGCP.DeviceMAC[SGCP.ReadDataAdd][0],SGCP.DeviceMAC[SGCP.ReadDataAdd][1],SGCP.DeviceMAC[SGCP.ReadDataAdd][2],
SGCP.DeviceMAC[SGCP.ReadDataAdd][3],SGCP.DeviceMAC[SGCP.ReadDataAdd][4],SGCP.DeviceMAC[SGCP.ReadDataAdd][5]); SGCP.DeviceMAC[SGCP.ReadDataAdd][3],SGCP.DeviceMAC[SGCP.ReadDataAdd][4],SGCP.DeviceMAC[SGCP.ReadDataAdd][5]);
if(isAllZero(LocalDataPack, LocalDataLen) == false) if(is_all_byte(LocalDataPack, LocalDataLen, 0x00) == false)
{ {
memcpy(&SGCP.DeviceData[SGCP.DeviceDataLen], LocalDataPack, sizeof(LocalDataPack)); memcpy(&SGCP.DeviceData[SGCP.DeviceDataLen], LocalDataPack, sizeof(LocalDataPack));
SGCP.DeviceDataLen = DevGetDataMess(LocalType, LocalDataPack); SGCP.DeviceDataLen = DevGetDataMess(LocalType, LocalDataPack);
+27 -1
View File
@@ -57,6 +57,33 @@ static void AppInit(void)
CommWay = BLPara.DevMac[2]; //本机通讯方式 CommWay = BLPara.DevMac[2]; //本机通讯方式
DeviceSign = BLPara.DevMac[3] & 0x80; //本机设备标志 DeviceSign = BLPara.DevMac[3] & 0x80; //本机设备标志
AddNumber = ((BLPara.DevMac[3] << 16)+ (BLPara.DevMac[4] << 8) + BLPara.DevMac[5]) - 0x800000; //本机地址编号,数字部分对应唯一地址编号 AddNumber = ((BLPara.DevMac[3] << 16)+ (BLPara.DevMac[4] << 8) + BLPara.DevMac[5]) - 0x800000; //本机地址编号,数字部分对应唯一地址编号
if(is_all_byte(LocalMAC, 6, 0xFF) == true)/*针对旧版本boot程序的升级兼容*/
{
LocalType = LASER_TRACING; //本机设备类型
CommWay = LORA; //本机通讯方式
DeviceSign = MASTER; //本机设备标志
AddNumber = 0x000022 + DeviceSign;//本机地址编号,数字部分对应唯一地址编号
LocalMAC[0] = LocalType & 0xFF; //本机MAC地址
LocalMAC[1] = (LocalType >> 8) & 0xFF;
LocalMAC[2] = CommWay;
LocalMAC[3] = (AddNumber >> 16) & 0xFF;
LocalMAC[4] = (AddNumber >> 8) & 0xFF;
LocalMAC[5] = AddNumber & 0xFF;
if(AddNumber <= 0x14)
{
SX1276LoRaSetFreqHz(CH1); //Lora频率:433100000ul + 200000*N
BLPara.LoraFreq = CH1;
memcpy(&BLPara.DevMac[0], LocalMAC, 6);
}
else if(AddNumber > 0x14 && AddNumber < 0x23)
{
SX1276LoRaSetFreqHz(CH2); //Lora频率:433100000ul + 200000*N
BLPara.LoraFreq = CH2;
memcpy(&BLPara.DevMac[0], LocalMAC, 6);
}
}
if(App.Para.FactoryFlag != 0x00) if(App.Para.FactoryFlag != 0x00)
{ {
App.Para.FactoryFlag = 0x00; App.Para.FactoryFlag = 0x00;
@@ -64,7 +91,6 @@ static void AppInit(void)
App.Para.CaliPara.PitchZero = 0; App.Para.CaliPara.PitchZero = 0;
App.Para.CaliPara.RollZero = 0; App.Para.CaliPara.RollZero = 0;
App.Para.CaliPara.YawZero = 0; App.Para.CaliPara.YawZero = 0;
SAVE_APP_PARA((uint32_t *)&App.Para);
} }
#elif #elif
LocalType = LASER_TRACING; //本机设备类型 LocalType = LASER_TRACING; //本机设备类型