From d08ca726df245df184a6d216d838f54a72cf8c99 Mon Sep 17 00:00:00 2001 From: YuanHongbin <975559679@qq.com> Date: Mon, 20 Jul 2026 14:27:37 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=BA=90=E7=A0=81=E7=BC=96=E7=A0=81GB?= =?UTF-8?q?2312=E7=BB=9F=E4=B8=80=E8=BD=AC=E6=8D=A2=E4=B8=BAUTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 25个含有中文注释的.c/.h文件编码格式从GB2312转为UTF-8(无BOM)。中文字符从2字节编码变为3字节编码,注释内容保持不变。 --- .../source/Module/GateWay_Debug/DebugCmd.c | 362 ++++++------- .../GateWay/source/Module/SDCard/sdmmc_cmd.h | 2 +- Project/GateWay/source/Module/sx127x/sx127x.c | 6 +- Project/GateWay/source/Module/sx127x/sx127x.h | 14 +- Project/GateWay/source/User/Inc/CatOneTask.h | 30 +- Project/GateWay/source/User/Inc/Public.h | 228 ++++---- Project/GateWay/source/User/Inc/RS485Task.h | 2 +- Project/GateWay/source/User/Inc/bsp.h | 10 +- Project/GateWay/source/User/Inc/main.h | 2 +- Project/GateWay/source/User/Inc/protocol.h | 6 +- Project/GateWay/source/User/Inc/ringbuffer.h | 14 +- Project/GateWay/source/User/Inc/spiflash.h | 12 +- Project/GateWay/source/User/Src/CatOneTask.c | 74 +-- Project/GateWay/source/User/Src/Encryption.c | 18 +- Project/GateWay/source/User/Src/LoraTask.c | 24 +- Project/GateWay/source/User/Src/Public.c | 294 +++++------ Project/GateWay/source/User/Src/RS485Task.c | 116 ++--- Project/GateWay/source/User/Src/app_comm.c | 14 +- Project/GateWay/source/User/Src/bsp.c | 492 +++++++++--------- Project/GateWay/source/User/Src/main.c | 40 +- Project/GateWay/source/User/Src/protocol.c | 22 +- Project/GateWay/source/User/Src/ringbuffer.c | 36 +- Project/GateWay/source/User/Src/spiflash.c | 102 ++-- Project/GateWay/source/User/Src/utils.c | 16 +- 24 files changed, 968 insertions(+), 968 deletions(-) diff --git a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c index fccbfcb..772cdc8 100644 --- a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c +++ b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c @@ -52,10 +52,10 @@ void vcom_Print(uint8_t sLen) } /***************************************************************************************** -* : Debug_Printf -* : RS485ͨ1 -* : -* ֵ: +* 函数名称: Debug_Printf +* 功能描述: RS485通道1任务函数 +* 参 数: 任务参数入口 +* 返 回 值: 无 *****************************************************************************************/ void Debug_Printf(char *format, ...) { @@ -92,10 +92,10 @@ void Debug_Printf(char *format, ...) va_end(args); } /***************************************************************************************** -* : RS485Ch2_Thread_Entry -* : RS485ͨ1 -* : -* ֵ: +* 函数名称: RS485Ch2_Thread_Entry +* 功能描述: RS485通道1任务函数 +* 参 数: 任务参数入口 +* 返 回 值: 无 *****************************************************************************************/ void Debug_Thread_Entry(void *parameter) { @@ -106,7 +106,7 @@ void Debug_Thread_Entry(void *parameter) if(DebugRev_Sem == RT_NULL) { rt_kprintf("DebugRev Sem Create Failed!\r\n"); } - rt_kprintf("DebugRev Thread is running\r\n"); + rt_kprintf("DebugRev Thread is running!\r\n"); while(1) { result = rt_sem_take(DebugRev_Sem, RT_WAITING_FOREVER); @@ -119,10 +119,10 @@ void Debug_Thread_Entry(void *parameter) } /***************************************************************************************** -* : RS485Ch2RxIrqCallback -* : RS485ͨ1жϴص -* : rData յ -* ֵ: +* 函数名称: RS485Ch2RxIrqCallback +* 功能描述: RS485通道1中断处理回调函数 +* 参 数: rData 接收到的数据 +* 返 回 值: 无 *****************************************************************************************/ void DbgRxIrqCallback(uint8_t rData) { @@ -148,12 +148,12 @@ void DebugRxOverhandler(void) } /***************************************************************************************** -* : DebugAnalyze -* : ָ -* : GateWay, ز - rData, - rLen, ݳ -* ֵ: +* 函数名称: DebugAnalyze +* 功能描述: 调试指令解析 +* 参 数: GateWay, 网关参数句柄 + rData,输入数据 + rLen, 输入数据长度 +* 返 回 值: 无 *****************************************************************************************/ void DebugAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) { @@ -186,17 +186,17 @@ void DebugAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) for(int i = 0; i < DEBUG_CMD_CNT; i++) { if(strcmp(argv[0], DebugFun[i].DBGCmd) == 0) { DebugFun[i].DBGExec(argc, argv); - break; // breakƥ + break; // 添加break避免继续匹配 } } } /***************************************************************************************** -* : DebugCmdMainOnOff -* : Ϣ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdMainOnOff +* 功能描述: 主调试信息开关 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdMainOnOff(int argc, char *argv[]) { @@ -220,11 +220,11 @@ void DebugCmdMainOnOff(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdCat1OnOff -* : CAT1Ϣ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdCat1OnOff +* 功能描述: CAT1调试信息开关 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdCat1OnOff(int argc, char *argv[]) { @@ -248,11 +248,11 @@ void DebugCmdCat1OnOff(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdCat1OnOff -* : CAT1Ϣ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdCat1OnOff +* 功能描述: CAT1调试信息开关 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdRS485Ctrl(int argc, char *argv[]) { @@ -408,11 +408,11 @@ void DebugCmdRS485Ctrl(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdDelCommUnit -* : ɾעͨѶԪ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdDelCommUnit +* 功能描述: 删除已注册的通讯单元 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdDelCommUnit(int argc, char *argv[]) { @@ -459,11 +459,11 @@ void DebugCmdDelCommUnit(int argc, char *argv[]) WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); } /***************************************************************************************** -* : DebugCmdLsCommUnit -* : 鿴ͨѶԪϢ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdLsCommUnit +* 功能描述: 查看通讯单元信息 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdLsCommUnit(int argc, char *argv[]) { @@ -525,11 +525,11 @@ void DebugCmdLsCommUnit(int argc, char *argv[]) } } /***************************************************************************************** -* : DebugCmdExclCommUnit -* : ųָͨѶԪMAC -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdExclCommUnit +* 功能描述: 排除指定的通讯单元MAC +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdExclCommUnit(int argc, char *argv[]) { @@ -560,7 +560,7 @@ void DebugCmdExclCommUnit(int argc, char *argv[]) return; } - for(int i = 0; i < COMMUNIT_NUM_MAX; i++) {//Ѱҿλ + for(int i = 0; i < COMMUNIT_NUM_MAX; i++) {//寻找空位 if(GateWay->ConfigPara.ExclCommUnit[i].ExclFlag == false){ GateWay->ConfigPara.ExclCommUnit[i].ExclFlag = true; memcpy(&GateWay->ConfigPara.ExclCommUnit[i].ExclMac, &mac[0], 6); @@ -568,7 +568,7 @@ void DebugCmdExclCommUnit(int argc, char *argv[]) } } - ret = CheckCommUnitReg(GateWay, mac);//ɾעϢ + ret = CheckCommUnitReg(GateWay, mac);//删除注册信息 if(ret > -1) { GateWay->ConfigPara.CommUnitArray[ret].RegFlag = false; } @@ -577,11 +577,11 @@ void DebugCmdExclCommUnit(int argc, char *argv[]) WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); } /***************************************************************************************** -* : DebugCmdDelExclCommUnit -* : ɾָıųͨŵԪMAC -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdDelExclCommUnit +* 功能描述: 删除指定的被排除的通信单元MAC +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdDelExclCommUnit(int argc, char *argv[]) { @@ -628,11 +628,11 @@ void DebugCmdDelExclCommUnit(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdLsExclCommUnit -* : 鿴ųͨѶԪϢ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdLsExclCommUnit +* 功能描述: 查看被排除的通讯单元信息 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdLsExclCommUnit(int argc, char *argv[]) { @@ -662,11 +662,11 @@ void DebugCmdLsExclCommUnit(int argc, char *argv[]) DBG_LOG("\r\n\r\n"); } /***************************************************************************************** -* : DebugCmdSetComm -* : ͨѶʽ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdSetComm +* 功能描述: 设置网关与服务通讯方式 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdSetComm(int argc, char *argv[]) { @@ -707,11 +707,11 @@ void DebugCmdSetComm(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdSetCollTime -* : ݲɼ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdSetCollTime +* 功能描述: 设置数据采集间隔 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdSetCollTime(int argc, char *argv[]) { @@ -737,11 +737,11 @@ void DebugCmdSetCollTime(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdReadHisData -* : ȡʷ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdReadHisData +* 功能描述: 读取历史数据 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdReadHisData(int argc, char *argv[]) { @@ -816,11 +816,11 @@ void DebugCmdReadHisData(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdDelHisData -* : ɾʷ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdDelHisData +* 功能描述: 删除历史数据 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdDelHisData(int argc, char *argv[]) { @@ -836,11 +836,11 @@ void DebugCmdDelHisData(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdGetHisInfo -* : ȡʷϢ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdGetHisInfo +* 功能描述: 获取历史数据信息 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdGetHisInfo(int argc, char *argv[]) { @@ -877,11 +877,11 @@ void DebugCmdGetHisInfo(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdRestoreFactory -* : ָ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdRestoreFactory +* 功能描述: 恢复出厂设置 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdRestoreFactory(int argc, char *argv[]) { @@ -907,11 +907,11 @@ void DebugCmdRestoreFactory(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdUpload -* : ϴǰ״̬ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdUpload +* 功能描述: 上传当前网关状态 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdUpload(int argc, char *argv[]) { @@ -946,11 +946,11 @@ static void DebugCmdUpload(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdRegister -* : λע -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdRegister +* 功能描述: 重新向上位机发起注册 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdRegister(int argc, char *argv[]) { @@ -977,11 +977,11 @@ static void DebugCmdRegister(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdRestoreFactory -* : ָ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdRestoreFactory +* 功能描述: 恢复出厂设置 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdReboot(int argc, char *argv[]) { @@ -999,11 +999,11 @@ void DebugCmdReboot(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdSetSensorCollectTime -* : òɼʱ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdSetSensorCollectTime +* 功能描述: 设置采集时间 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdSetCollectTime(int argc, char *argv[]) { @@ -1065,11 +1065,11 @@ void DebugCmdSetCollectTime(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdTimeSync -* : ʱͬ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdTimeSync +* 功能描述: 时间同步 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdTimeSync(int argc, char *argv[]) { @@ -1107,11 +1107,11 @@ void DebugCmdTimeSync(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdTimeSync -* : ѯͨѶԪ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdTimeSync +* 功能描述: 查询内置通讯单元传感器 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ extern SensorCommPara_t SComm1Para; extern SensorCommPara_t SComm2Para; @@ -1142,11 +1142,11 @@ void DebugCmdQuerySensor(int argc, char *argv[]) /***************************************************************************************** -* : DebugCmdSelDebugChannel -* : ѡϢͨ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdSelDebugChannel +* 功能描述: 选择调试信息输出通道, +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdSelDebugChannel(int argc, char *argv[]) { @@ -1198,11 +1198,11 @@ void DebugCmdSelDebugChannel(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdSetLTENet -* : Cat1/4GĵַͶ˿ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdSetLTENet +* 功能描述: 设置Cat1/4G服务器的地址和端口 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdSetLTENet(int argc, char *argv[]) { @@ -1249,11 +1249,11 @@ static void DebugCmdSetLTENet(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdSetMac -* : MACַ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdSetMac +* 功能描述: 设置MAC地址 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdSetMac(int argc, char *argv[]) { @@ -1291,11 +1291,11 @@ static void DebugCmdSetMac(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdGetPara -* : 鿴 -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdGetPara +* 功能描述: 查看参数 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdGetPara(int argc, char *argv[]) { @@ -1366,11 +1366,11 @@ static void DebugCmdGetPara(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdCali -* : У׼ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdCali +* 功能描述: 校准传感器 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdCali(int argc, char *argv[]) { @@ -1423,12 +1423,12 @@ static void DebugCmdCali(int argc, char *argv[]) } } - for(int i = 0; i < COMMUNIT_NUM_MAX; i++)// + for(int i = 0; i < COMMUNIT_NUM_MAX; i++)//参数遍历 { if(GateWay->ConfigPara.CommUnitArray[i].RegFlag == true) - GateWay->ConfigPara.CommUnitArray[i].CailFlag = true;//У׼λȴ´δMAC豸ϴʱ·У׼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[i].CailFlag = true;//校准置位,等待下次此MAC主设备上传数据时下发校准指令(低功耗) } - //Sx1276LoRaSendBuffer(CommUnitCmd, sizeof(CommUnitFrameHeader_t) + 2);//͹ģʽ²· + //Sx1276LoRaSendBuffer(CommUnitCmd, sizeof(CommUnitFrameHeader_t) + 2);//低功耗模式下不用下发 DBG_LOG("Calibrate all communication units.\r\n"); return; @@ -1471,14 +1471,14 @@ static void DebugCmdCali(int argc, char *argv[]) CommUnitCmd[sizeof(CommUnitFrameHeader_t)] = crc16 & 0x00ff; CommUnitCmd[sizeof(CommUnitFrameHeader_t) + 1] = (crc16 >> 8) & 0x00ff; - if(mac[2] == 0x01) { //LORAͨѶ + if(mac[2] == 0x01) { //LORA通讯 if(GateWay->ConfigPara.CommUnitArray[ret].RegFlag == true) - GateWay->ConfigPara.CommUnitArray[ret].CailFlag = true;//У׼λȴ´δMAC豸ϴʱ·У׼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[ret].CailFlag = true;//校准置位,等待下次此MAC主设备上传数据时下发校准指令(低功耗) DBG_LOG("Wait for the device to respond. Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CUFrame->DevMac[0], CUFrame->DevMac[1], CUFrame->DevMac[2], CUFrame->DevMac[3], CUFrame->DevMac[4], CUFrame->DevMac[5]); //Sx1276LoRaSendBuffer(CommUnitCmd, sizeof(CommUnitFrameHeader_t) + 2); } - else if(mac[2] == 0x02) { //RS485ͨѶ + else if(mac[2] == 0x02) { //RS485通讯 if(GateWay->ConfigPara.Rs485Ch1.Enable == true && !GateWay->ConfigPara.Rs485Ch1.CommUnitEnable) { GateWay->ConfigPara.Rs485Ch1.RS485Send(Rs485Cmd, sizeof(CommUnitFrameHeader_t) + 2); DBG_LOG("Calibrate CommUnit: %s!\r\n", argv[1]); @@ -1493,11 +1493,11 @@ static void DebugCmdCali(int argc, char *argv[]) } } /***************************************************************************************** -* : DebugLaserConfig -* : -* : argc, - argv, -* ֵ: +* 函数名称: DebugLaserConfig +* 功能描述: 激光控制 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugLaserConfig(int argc, char *argv[]) { @@ -1588,12 +1588,12 @@ static void DebugLaserConfig(int argc, char *argv[]) CommUnitCmd[len++] = crc16 & 0x00ff; CommUnitCmd[len++] = (crc16 >> 8) & 0x00ff; - if(mac[2] == 0x01) { //LORAͨѶ͹ģʽ· + if(mac[2] == 0x01) { //LORA通讯,低功耗模式不用主动下发 if(GateWay->ConfigPara.CommUnitArray[ret].RegFlag == true) { if(onoff == true) { - GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//λȴ´δMAC豸ϴʱ·У׼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//控制置位,等待下次此MAC主设备上传数据时下发校准指令(低功耗) DBG_LOG("Wait for the device to respond. Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CUFrame->DevMac[0], CUFrame->DevMac[1], CUFrame->DevMac[2], CUFrame->DevMac[3], CUFrame->DevMac[4], CUFrame->DevMac[5]); GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = onoff; @@ -1602,11 +1602,11 @@ static void DebugLaserConfig(int argc, char *argv[]) { GateWay->ConfigPara.CommUnitArray[ret].ContLaser = false; GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = onoff; - Sx1276LoRaSendBuffer(CommUnitCmd, len);//ֱӷ + Sx1276LoRaSendBuffer(CommUnitCmd, len);//直接发 } } } - else if(mac[2] == 0x02) { //RS485ͨѶ + else if(mac[2] == 0x02) { //RS485通讯 if(GateWay->ConfigPara.Rs485Ch1.Enable == true && !GateWay->ConfigPara.Rs485Ch1.CommUnitEnable) { GateWay->ConfigPara.Rs485Ch1.RS485Send(Rs485Cmd, len); DBG_LOG("Control RS485 laser CommUnit: %s!\r\n", argv[1]); @@ -1622,19 +1622,19 @@ static void DebugLaserConfig(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdLPConfig -* : ͹IJ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdLPConfig +* 功能描述: 低功耗参数配置 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugCmdLPConfig(int argc, char *argv[]) { DBG_LOG("\r\n"); - uint16_t CollectInterval; //ɼʱ - uint16_t ReportInterval; //ϱʱ - uint8_t ERInterval; //ϱʱ - uint8_t ERTime; //ϱʱ + uint16_t CollectInterval; //采集时间间隔 + uint16_t ReportInterval; //上报时间间隔 + uint8_t ERInterval; //紧急上报时间间隔 + uint8_t ERTime; //紧急上报时长 if(strcmp(argv[1], "?") == 0) { DBG_LOG("Debug Cmd: lpcfg arg1 arg2 arg3 arg4\r\n"); @@ -1688,11 +1688,11 @@ static void DebugCmdLPConfig(int argc, char *argv[]) } /***************************************************************************************** -* : DebugCmdLPConfig -* : Lora -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdLPConfig +* 功能描述: Lora参数配置 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ static void DebugLoraConfig(int argc, char *argv[]) { @@ -1819,11 +1819,11 @@ static void DebugLoraConfig(int argc, char *argv[]) /***************************************************************************************** -* : DebugCmdHelp -* : Ϣ -* : argc, - argv, -* ֵ: +* 函数名称: DebugCmdHelp +* 功能描述: 调试命令帮助信息 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 *****************************************************************************************/ void DebugCmdHelp(int argc, char *argv[]) { diff --git a/Project/GateWay/source/Module/SDCard/sdmmc_cmd.h b/Project/GateWay/source/Module/SDCard/sdmmc_cmd.h index 9890e53..d0632a1 100644 --- a/Project/GateWay/source/Module/SDCard/sdmmc_cmd.h +++ b/Project/GateWay/source/Module/SDCard/sdmmc_cmd.h @@ -102,7 +102,7 @@ typedef struct stc_sdmmc_resp_card_status uint32_t ERASE_SEQ_ERR :1; ///< An error in the sequence of erase commands occurred. uint32_t BLOCK_LEN_ERR :1; ///< The transferred block length is not allowed for this card, or the number of transferred bytes does not match the block length. uint32_t ADDRESS_ERROR :1; ///< A misaligned address which did not match the block length was used in the command. - uint32_t OUT_OF_RANGE :1; ///< The command’s argument was out of the allowed range for this card. + uint32_t OUT_OF_RANGE :1; ///< The command鈥檚 argument was out of the allowed range for this card. } stc_sdmmc_resp_card_status_t; /******************************************************************************* diff --git a/Project/GateWay/source/Module/sx127x/sx127x.c b/Project/GateWay/source/Module/sx127x/sx127x.c index b63bff2..5fbc8be 100644 --- a/Project/GateWay/source/Module/sx127x/sx127x.c +++ b/Project/GateWay/source/Module/sx127x/sx127x.c @@ -314,7 +314,7 @@ void Sx1276LoRaInit(DataRevCallBack RxCallBack) } else{ SX1276LoRaSetNbTrigPeaks(3); - SX1276LoRaSetLowDatarateOptimize(false); // + SX1276LoRaSetLowDatarateOptimize(false); //低数据速率设置 } LoRaPara.RegBuff.RegModemConfig2 = (LoRaPara.RegBuff.RegModemConfig2 & RFLR_MODEMCONFIG2_SF_MASK ) | LoRaPara.SpreadFactor; //PacketCrcOn @@ -463,8 +463,8 @@ void Sx1276LoRaWakeup(void) } //////////////////////////////////////// -//ñĺ -//Ƶ +//配置本层参数的函数 +//频道表 const uint32_t gdwSx1276ChannelTbl[SX1276_CHANNEL_MAX]={ FREQ_CENT-FREQ_DEV*8, FREQ_CENT-FREQ_DEV*7, FREQ_CENT-FREQ_DEV*6, FREQ_CENT-FREQ_DEV*5, FREQ_CENT-FREQ_DEV*4, FREQ_CENT-FREQ_DEV*3, FREQ_CENT-FREQ_DEV*2, FREQ_CENT-FREQ_DEV*1, diff --git a/Project/GateWay/source/Module/sx127x/sx127x.h b/Project/GateWay/source/Module/sx127x/sx127x.h index 6a6f701..788c8b2 100644 --- a/Project/GateWay/source/Module/sx127x/sx127x.h +++ b/Project/GateWay/source/Module/sx127x/sx127x.h @@ -638,7 +638,7 @@ typedef enum{ SX1276_IH_ON= (1) }Sx1276ImplicitHeaderOnType; -//ɱ +//可变速率 typedef struct _AutoSfType{ Sx1276SpreadFactorType Sf; uint8_t ucRssiMin, ucRssiMax; @@ -747,20 +747,20 @@ typedef struct { //Down Link: //CH0-47:500.3-509.7MHz -#define USE_915MHZ 0//=1ʹ915 =0ʹ433 +#define USE_915MHZ 0//=1使用915 =0使用433 #if (USE_915MHZ == 1) - //ƵʣĬΪ449000000Hz + //中心频率,不定义则默认为449000000Hz #define FREQ_CENT 915000000ul - //860MHz-1GHzʹPAţĬϲʹ - //SX127x壬HOPERFģҪ + //860MHz-1GHz使用PA功放,不定义则默认不使用 + //SX127x不定义,HOPERF模块需要定义 #define USE_LORA_860_PA #endif /* -Ƶã433100000ul + 200000*N +中心频率配置:433100000ul + 200000*N */ -#define CH0 (433100000ul + 0) //Ƶ +#define CH0 (433100000ul + 0) //测试频率 #define CH1 (433100000ul + 200000) #define CH2 (433100000ul + 400000) #define CH3 (433100000ul + 600000) diff --git a/Project/GateWay/source/User/Inc/CatOneTask.h b/Project/GateWay/source/User/Inc/CatOneTask.h index 3e00414..adf5b77 100644 --- a/Project/GateWay/source/User/Inc/CatOneTask.h +++ b/Project/GateWay/source/User/Inc/CatOneTask.h @@ -14,7 +14,7 @@ #define CAT_ONE_DELAY_1MS(X) -// ETH״̬غ궨 +// ETH状态机相关宏定义 #define ETH_RESET_DELAY_TIME_MAX (5 * 60 * 1000) #define ETH_LINK_WAIT_TIME_MAX (10 * 1000) #define ETH_REG_TIMEOUT_MAX (30 * 1000) @@ -25,21 +25,21 @@ typedef enum { CAT_ONE_AT_NULL, - CAT_ONE_AT, // - CAT_ONE_ATE0, //ػ - CAT_ONE_CPIN, //ʶ + CAT_ONE_AT, //开机检测 + CAT_ONE_ATE0, //关回显 + CAT_ONE_CPIN, //识卡 CAT_ONE_IMEI, - CAT_ONE_LCCID, // - CAT_ONE_CEREG, //ѯע״̬ - CAT_ONE_CGPADDR, //ѯIPַ - CAT_ONE_CSQ, //ѯźǿ - CAT_ONE_LDNSGIP, // - CAT_ONE_LBS, //ȡվλϢ - CAT_ONE_LIPOPEN, //TCPַͶ˿ - CAT_ONE_LIPSEND, // - CAT_ONE_LTPCLOSE, //Ͽ + CAT_ONE_LCCID, //读卡 + CAT_ONE_CEREG, //查询注册状态 + CAT_ONE_CGPADDR, //查询IP地址 + CAT_ONE_CSQ, //查询信号强度 + CAT_ONE_LDNSGIP, //域名解析 + CAT_ONE_LBS, //获取基站定位信息 + CAT_ONE_LIPOPEN, //设置TCP服务器地址和端口 + CAT_ONE_LIPSEND, //发送数据 + CAT_ONE_LTPCLOSE, //断开连接 CAT_ONE_LBSPARA, - CAT_ONE_CCLK, //ȡʱ + CAT_ONE_CCLK, //获取时间 CAT_ONE_AT_CMD_END, }CatOneATCMD_m; @@ -111,7 +111,7 @@ typedef struct { GateWayPara GateWay; DataRevCallBack CatOneRevCallBack; - // ETH״ֶ̬ + // ETH状态机相关字段 EthStatus_m EthStatus; uint32_t EthResetDelayCnt; uint32_t EthLinkWaitCnt; diff --git a/Project/GateWay/source/User/Inc/Public.h b/Project/GateWay/source/User/Inc/Public.h index d2a1ae9..4b3e0aa 100644 --- a/Project/GateWay/source/User/Inc/Public.h +++ b/Project/GateWay/source/User/Inc/Public.h @@ -3,7 +3,7 @@ #include "bsp.h" -#define LORA_LOWPOWER //LORA͹豸ϱʽ +#define LORA_LOWPOWER //LORA低功耗设备,采用主动上报方式 #define SENSOR_DATA_LEN_MAX 50 #define SENSOR_NUM_MAX 16 @@ -12,8 +12,8 @@ #define REGISTER_INTERVAL_MAX (2 * 60) #define COMMUNIT_READ_SENSOR_INTERVAL_MAX (1 * 60) -#define LORA_ERR_RESET_DLY_MAX (10 * 60) //LORAճʱλʱλ -#define CAT1_ERR_RESET_DLY_MAX (60 * 60) //CAT1ճʱλʱλ +#define LORA_ERR_RESET_DLY_MAX (10 * 60) //LORA接收超时复位延时,单位秒 +#define CAT1_ERR_RESET_DLY_MAX (60 * 60) //CAT1接收超时复位延时,单位秒 typedef struct GateWay_t GateWayPara_t, *GateWayPara; @@ -55,8 +55,8 @@ typedef enum { COMM_UNIT_CMD_READ, COMM_UNIT_CMD_SET_SENSOR_COLL_TIME = 5, COMM_UNIT_CMD_TIME_SYNC, - COMM_UNIT_CMD_CONT_LASER = 8,//ָ - COMM_UNIT_CMD_GET_SIGNAL, //0x09 ѯLoraź + COMM_UNIT_CMD_CONT_LASER = 8,//激光独有指令 + COMM_UNIT_CMD_GET_SIGNAL, //0x09 查询Lora信号质量 COMM_UNIT_CMD_END, }CommUnitCmd_m; @@ -71,41 +71,41 @@ typedef enum { NET_COMM_CMD_ADD_UNIT, NET_COMM_CMD_LP_DEV_CONFIG, NET_COMM_CMD_ALARM, - NET_COMM_CMD_CONT_LASER,//ָ + NET_COMM_CMD_CONT_LASER,//激光独有指令 NET_COMM_CMD_END, }NetCommCmd_m; typedef enum { - SENSOR_TYPE_NULL, //0x0000 豸 - FORCE_6D, //0x0001 άӦ - OSMOTIC_PRESSURE, //0x0002 ͸ѹ - ELASTIC_WAVEGUIDE, //0x0003 Բ - DIELECTRIC_MASS, //0x0004 - VIBRATE_SENSOR, //0x0005 ΢񶯴 - CONT_DEFOR_3D, //0x0006 ά - COMM_UNIT, //0x0007 ͨѶԪ - FORCE_3D, //0x0008 άӦ - LASER_TRACING, //0x0009 ʾ - WATER_LEVEL, //0x000A ˮλ - _0x000B, //0x000B - _0x000C, //0x000C - MULTI_PARAMETER_FUSION, //0x000D ں - CRACK_DETECTION, //0x000E ѷ - _0x000F, //0x000F - ATTITUDE_MONITOR, //0x0010 ̬ - LASER_DISPLACE, //0x0011 λ - REBAR_STRESS, //0x0012 ֽӦ - ANCHOR_ROD_STRESS, //0x0013 ê - SURFACE_STRESS, //0x0014 Ӧ - PRESSURE, //0x0015 ѹ - MICROWAVE_DISPLACE, //0x0016 ΢λ - DISPLACEMENT = 0x0020, //0x0020 λƼ⴫ + SENSOR_TYPE_NULL, //0x0000 空设备 + FORCE_6D, //0x0001 六维应力 + OSMOTIC_PRESSURE, //0x0002 渗透压 + ELASTIC_WAVEGUIDE, //0x0003 弹性波导 + DIELECTRIC_MASS, //0x0004 介电质普 + VIBRATE_SENSOR, //0x0005 微振动传感器 + CONT_DEFOR_3D, //0x0006 三维连续变形 + COMM_UNIT, //0x0007 通讯单元 + FORCE_3D, //0x0008 三维应力 + LASER_TRACING, //0x0009 激光示踪 + WATER_LEVEL, //0x000A 水位计 + _0x000B, //0x000B 保留 + _0x000C, //0x000C 保留 + MULTI_PARAMETER_FUSION, //0x000D 多参数融合 + CRACK_DETECTION, //0x000E 裂缝仪 + _0x000F, //0x000F 保留 + ATTITUDE_MONITOR, //0x0010 姿态检测 + LASER_DISPLACE, //0x0011 激光位移 + REBAR_STRESS, //0x0012 钢筋应力 + ANCHOR_ROD_STRESS, //0x0013 锚杆轴力 + SURFACE_STRESS, //0x0014 表面应力 + PRESSURE, //0x0015 压力 + MICROWAVE_DISPLACE, //0x0016 微波位移 + DISPLACEMENT = 0x0020, //0x0020 位移监测传感器 }SensorType_m; -typedef struct {//豸̶ͷ - uint8_t BatLevel; //ص - int8_t RSSI; //źǿ - int8_t Nsr; // +typedef struct {//主设备固定包头 + uint8_t BatLevel; //电池电量 + int8_t RSSI; //信号强度 + int8_t Nsr; //信噪比 }__attribute__ ((packed))MasterDev_T,*MasterDevDp; typedef struct { @@ -122,19 +122,19 @@ typedef struct { typedef struct { MasterDev_T MasterDev; - int16_t PitchAngle; //ƫб Χ900λ0.1 - int16_t RollAngle; //ƫб Χ900λ0.1 - int16_t YawAngle; //ƫƫб Χ0~3600λ0.1 + int16_t PitchAngle; //俯仰角偏斜 (范围±900)单位0.1° + int16_t RollAngle; //横滚角偏斜 (范围±900)单位0.1° + int16_t YawAngle; //偏航角偏斜 (范围0~3600)单位0.1° }__attribute__((packed))LaserTracingType_T; -typedef struct {//0x0020 λƼ +typedef struct {//0x0020 位移计 MasterDev_T MasterDev; - int16_t PitchAngle; //ƫбΧ900λ0.1 - int16_t RollAngle; //ƫбΧ900λ0.1 - int16_t YawAngle; //ƫƫбΧ0~3600λ0.1 - float Temp; //¶ - float Altitude; //Σλcm - int16_t Distance; //1ӦֵתλƣΧ300,λ0.1mm + int16_t PitchAngle; //俯仰角偏斜(范围±900)单位0.1° + int16_t RollAngle; //横滚角偏斜(范围±900)单位0.1° + int16_t YawAngle; //偏航角偏斜(范围0~3600)单位0.1° + float Temp; //温度 + float Altitude; //海拔()单位cm + int16_t Distance; //1轴应力值转位移(范围±300,单位0.1mm) }__attribute__ ((packed))Displacement_T,*DisplacementDp; typedef struct { @@ -142,11 +142,11 @@ typedef struct { }__attribute__((packed))LaserDistanceSensorType_t; typedef struct { - uint8_t CommDevAddr[6]; //ͨѶԪַ - uint16_t CollectInterval; //ɼʱ - uint16_t ReportInterval; //ϱʱ - uint8_t ERInterval; //ϱʱ - uint8_t ERTime; //ϱʱ + uint8_t CommDevAddr[6]; //通讯单元地址 + uint16_t CollectInterval; //采集时间间隔 + uint16_t ReportInterval; //上报时间间隔 + uint8_t ERInterval; //紧急上报时间间隔 + uint8_t ERTime; //紧急上报时长 }__attribute__((packed))SvrDownLPDevConfigPara_t; typedef struct { @@ -155,47 +155,47 @@ typedef struct { uint8_t AlarmPara; }__attribute__((packed))GateWayAlarmType_t; -#define LW_DEV_COLLECT_INTERVAL_MAX 300//Ĭ300 -#define LW_DEV_REPORT_INTERVAL_MAX 20//20 -#define LW_DEV_ER_INTERVAL_MAX 2//2 -#define LW_DEV_ER_TIME_MAX 20//20 +#define LW_DEV_COLLECT_INTERVAL_MAX 300//默认300秒 +#define LW_DEV_REPORT_INTERVAL_MAX 20//20分钟 +#define LW_DEV_ER_INTERVAL_MAX 2//2分钟 +#define LW_DEV_ER_TIME_MAX 20//20分钟 typedef struct { - uint16_t CollectInterval; //ɼʱ - uint16_t ReportInterval; //ϱʱ - uint8_t ERInterval; //ϱʱ - uint8_t ERTime; //ϱʱ - uint32_t TimeStamp; //ʱ + uint16_t CollectInterval; //采集时间间隔 + uint16_t ReportInterval; //上报时间间隔 + uint8_t ERInterval; //紧急上报时间间隔 + uint8_t ERTime; //紧急上报时长 + uint32_t TimeStamp; //时间戳 }__attribute__((packed))LPDevConfigPara_t; typedef struct { bool RegFlag; bool RevNewDataFlag; - bool CommStatus; //ͨѶ״̬1-ߣ0- - bool CailFlag; //У׼־͹ģ - bool TimeSyncFlag; //ʱͬ־͹ģ - bool ContLaser; //Ʊ־͹ģ - bool LaserOnOff; //״̬͹ģ + bool CommStatus; //通讯状态,1-在线,0-离线 + bool CailFlag; //校准标志(低功耗) + bool TimeSyncFlag; //时间同步标志(低功耗) + bool ContLaser; //激光控制标志(低功耗) + bool LaserOnOff; //激光状态(低功耗) uint32_t CommErrCnt; uint8_t MasterMac[6]; - uint8_t Mac[SENSOR_NUM_MAX][6];//һλ豸ȫ豸 + uint8_t Mac[SENSOR_NUM_MAX][6];//第一位是主设备,后面全是子设备 uint8_t BatLevel; - int8_t RSSI; //źǿ - int8_t Nsr; // + int8_t RSSI; //信号强度 + int8_t Nsr; //信噪比 uint16_t CUType; uint8_t SensorN; uint16_t SensorType[SENSOR_NUM_MAX]; - //͹豸Ϣ - bool ConfigFlag; //ñ־Ϊ1ʾãӦ͹豸ʱҪ - uint16_t CollectInterval; //ɼʱ - uint16_t ReportInterval; //ϱʱ - uint8_t ERInterval; //ϱʱ - uint8_t ERTime; //ϱʱ + //低功耗设备配置信息 + bool ConfigFlag; //配置标志,为1表示有新配置,应答低功耗设备时需要附带发送 + uint16_t CollectInterval; //采集时间间隔 + uint16_t ReportInterval; //上报时间间隔 + uint8_t ERInterval; //紧急上报时间间隔 + uint8_t ERTime; //紧急上报时长 }__attribute__((packed))CommUnitPara_t, *CommUnitPara; typedef struct { bool ExclFlag; - uint8_t ExclMac[6];//ҪųͨѶԪMAC + uint8_t ExclMac[6];//需要排除的通讯单元MAC }__attribute__((packed))ExclCommUnit_t, *ExclCommUnit; typedef struct { @@ -207,10 +207,10 @@ typedef struct { }__attribute__((packed))CommUnit_t, *CommUnit; typedef struct { - bool Enable; //ʹ - bool CommUnitEnable; //ͨѶԪʹܣʹڲͨѶԪܣֱӺʹͨѶرգֱӺRS485͵ͨѶԪͨѶ - bool QuerySensorFlag; //ѯ־ - bool UpgradeEnable;//ʹ + bool Enable; //串口使能 + bool CommUnitEnable; //通讯单元使能,开启(使用内部通讯单元功能,直接和传感器通讯),关闭(直接和RS485类型的通讯单元通讯) + bool QuerySensorFlag; //查询传感器标志 + bool UpgradeEnable;//升级功能使能 uint8_t Power; uint32_t BaudRate; SendData RS485Send; @@ -252,56 +252,56 @@ typedef struct { }LoraPara_t, *pLoraPara; typedef struct { - uint8_t DestAddr[4]; //Ŀķַ - uint16_t DestPort; //Ŀķ˿ - uint8_t LocalAddr[4]; //ؿͻ˵ַ(Ԥ) - uint16_t LocalPort; //ؿͻ˶˿(Ԥ) + uint8_t DestAddr[4]; //目的服务器地址 + uint16_t DestPort; //目的服务器端口 + uint8_t LocalAddr[4]; //本地客户端地址(预留) + uint16_t LocalPort; //本地客户端端口(预留) }LTENetPara_t, *pLTENetPara; typedef struct { - uint8_t IpMode; //IPģʽDHCP/̬ - uint8_t IpAddr[4]; //IPַ - uint16_t IpPort; //ض˿ - uint8_t WorkMode; //ģʽ - uint8_t SubnetMask[4]; // - uint8_t Gateway[4]; // - uint8_t DestIp[4]; //ĿIPַ - uint16_t DestPort; //ĿĶ˿ + uint8_t IpMode; //IP模式:DHCP/静态 + uint8_t IpAddr[4]; //本地IP地址 + uint16_t IpPort; //本地端口 + uint8_t WorkMode; //工作模式 + uint8_t SubnetMask[4]; //子网掩码 + uint8_t Gateway[4]; //网关 + uint8_t DestIp[4]; //目的IP地址 + uint16_t DestPort; //目的端口 }EthNetPara_t, *pEthNetPara; typedef struct { - uint32_t SavFlag; //洢־ - CommType_m Comm; //ͨѶʽ - uint8_t GwMac[6]; //mac - LTENetPara_t LTENet; //Cat1/4G - EthNetPara_t EthNet; //̫ - uint32_t CommUnitReadInterval; //ͨѶԪȡʱ,λS - CommUnitPara_t CommUnitArray[COMMUNIT_NUM_MAX]; //עͨѶԪϢ - ExclCommUnit_t ExclCommUnit[COMMUNIT_NUM_MAX]; //ųͨѶԪϢ - RS485Para_t Rs485Ch1; //RS485ͨ1 - RS485Para_t Rs485Ch2; //RS485ͨ2 - uint8_t DebugChannel; //ͨ - LoraPara_t Lora; //Lora - bool OutageFlag; //ϵ籨־ + uint32_t SavFlag; //存储标志 + CommType_m Comm; //网关通讯方式 + uint8_t GwMac[6]; //网关mac + LTENetPara_t LTENet; //Cat1/4G服务器参数 + EthNetPara_t EthNet; //以太网网络参数 + uint32_t CommUnitReadInterval; //通讯单元读取时间间隔,单位S + CommUnitPara_t CommUnitArray[COMMUNIT_NUM_MAX]; //注册的通讯单元信息 + ExclCommUnit_t ExclCommUnit[COMMUNIT_NUM_MAX]; //排除的通讯单元信息 + RS485Para_t Rs485Ch1; //RS485通道1配置 + RS485Para_t Rs485Ch2; //RS485通道2配置 + uint8_t DebugChannel; //调试通道 + LoraPara_t Lora; //Lora配置 + bool OutageFlag; //断电报警标志 uint16_t crc16; }__attribute__((packed))GWConfigPara_t, *GWConfigPara; struct GateWay_t{ - bool TimeSyncFlag; //ʱͬ־ - bool SvrRegFlag; //ע־ - uint8_t SvrMac[6]; //mac - GWConfigPara_t ConfigPara; //ò + bool TimeSyncFlag; //时间同步标志 + bool SvrRegFlag; //服务器注册标志 + uint8_t SvrMac[6]; //服务器mac + GWConfigPara_t ConfigPara; //配置参数 CommUnitData_t CUDataArray[COMMUNIT_NUM_MAX]; - uint8_t Battery; //ص - uint16_t UploadInterval; //ϴ - uint32_t HistoryNum; //ʷ - DataRevCallBack SvrRevCallBack; //յص - DataRevResCallBack CommUnitRevCallBack; //ͨѶԪջص - rt_mq_t NetSendData_MQ; //緢ݶУһֽڴ洢Ϣ, ڶֽڴ洢֣Ϊ - rt_mq_t LoraRev_MQ; //LoraϢУһֽڴ洢ϢȣΪ + uint8_t Battery; //电池电量 + uint16_t UploadInterval; //上传间隔 + uint32_t HistoryNum; //历史数据数量 + DataRevCallBack SvrRevCallBack; //接收到服务器回调 + DataRevResCallBack CommUnitRevCallBack; //通讯单元接收回调 + rt_mq_t NetSendData_MQ; //网络发送数据队列,第一个字节用于存储消息长度, 第二字节存储命令字,后为数据 + rt_mq_t LoraRev_MQ; //Lora接收消息队列,第一个字节用于存储消息长度,后为数据 rt_mutex_t UartRevMutex; - uint8_t BatteryReadDlyCnt; //ȡѹʱλ룬ֹ4G͵صѹɶϵ + uint8_t BatteryReadDlyCnt; //读取电压延时,单位秒,防止4G发送拉低电池电压,造成断电误报 }; int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen); diff --git a/Project/GateWay/source/User/Inc/RS485Task.h b/Project/GateWay/source/User/Inc/RS485Task.h index 46b7c1c..e0dd5b0 100644 --- a/Project/GateWay/source/User/Inc/RS485Task.h +++ b/Project/GateWay/source/User/Inc/RS485Task.h @@ -36,7 +36,7 @@ typedef enum { RS485_SENSOR_CMD_END, }RS485SensorCmd_m; -//ݷͽṹ +//传感器数据发送结构体 typedef struct { bool SendFlag; uint8_t SensorCnt; diff --git a/Project/GateWay/source/User/Inc/bsp.h b/Project/GateWay/source/User/Inc/bsp.h index d64274c..e65b691 100644 --- a/Project/GateWay/source/User/Inc/bsp.h +++ b/Project/GateWay/source/User/Inc/bsp.h @@ -30,7 +30,7 @@ //#define BOOT_PARA_ADDRESS (FLASH_SIZE - FLASH_SECTOR_SIZE) //#define BOOT_PARA_SIZE (FLASH_SECTOR_SIZE) -/* flash rom map 洢*/ +/* flash rom map 存储分区*/ //boot 16k #define FLASH_BASE ((uint32_t)0x00000000) #define FLASH_SECTOR_SIZE 0x2000ul @@ -337,7 +337,7 @@ bool SDCardWriteBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t #define BAT_COLL_ADC_CH (ADC1_CH1) -//֡ͷṹ +//帧头结构体 typedef struct { uint8_t Header; uint8_t SlvAddr; @@ -345,20 +345,20 @@ typedef struct { uint8_t PayloadLen; }update_protocol_hd_t; -//·غɽṹ +//主机下发升级请求载荷结构体 typedef struct { uint16_t PackageNum; uint32_t AppSize; uint32_t AppCrc32; }__attribute__ ((packed))update_protocol_req_t; -//ӻ·ṹ +//从机请求下发结构体 typedef struct { uint16_t PackageIndex; uint32_t PackageNum; }__attribute__ ((packed))update_protocol_get_t; -//Ӧ·ݽṹ +//主机应答下发数据结构体 typedef struct { uint16_t PackageIndex; uint16_t PackageNum; diff --git a/Project/GateWay/source/User/Inc/main.h b/Project/GateWay/source/User/Inc/main.h index dc13cee..c0f4740 100644 --- a/Project/GateWay/source/User/Inc/main.h +++ b/Project/GateWay/source/User/Inc/main.h @@ -4,7 +4,7 @@ #include "Public.h" #include "DebugCmd.h" -#define MAC_ADDR_TYPE 0//0ΪԷ +#define MAC_ADDR_TYPE 0//0为测试服务器 extern bool MainDispEn; #define MAIN_DBG_LOG(...) { if(MainDispEn) Debug_Printf(__VA_ARGS__);} diff --git a/Project/GateWay/source/User/Inc/protocol.h b/Project/GateWay/source/User/Inc/protocol.h index 168205a..d3bdc41 100644 --- a/Project/GateWay/source/User/Inc/protocol.h +++ b/Project/GateWay/source/User/Inc/protocol.h @@ -8,10 +8,10 @@ #define PROTOCOL_HEAD (0x527A) -#define PROTOCOL_FRAME_HEAD_SIZE (7) // С֡ͷ(2) + ַ(2) + (1) + (2) + CRC(2) +#define PROTOCOL_FRAME_HEAD_SIZE (7) // 最小帧长:头(2) + 地址(2) + 命令(1) + 长度(2) + CRC(2) -#define PROTOCOL_FRAME_MIN_SIZE (9) // С֡ͷ(2) + ַ(2) + (1) + (2) + CRC(2) -// 붨 +#define PROTOCOL_FRAME_MIN_SIZE (9) // 最小帧长:头(2) + 地址(2) + 命令(1) + 长度(2) + CRC(2) +// 错误码定义 typedef enum { PROTOCOL_SUCCESS = 0, PROTOCOL_ERR_INVALID_PARAM, diff --git a/Project/GateWay/source/User/Inc/ringbuffer.h b/Project/GateWay/source/User/Inc/ringbuffer.h index b517e6c..bbb6512 100644 --- a/Project/GateWay/source/User/Inc/ringbuffer.h +++ b/Project/GateWay/source/User/Inc/ringbuffer.h @@ -1,5 +1,5 @@ /****************************************************************************** - * @brief λ(οlinux/kfifo) + * @brief 环形缓冲区管理(参考linux/kfifo) * * Copyright (c) 2016~2020, * @@ -7,7 +7,7 @@ * * Change Logs: * Date Author Notes - * 2016-05-30 Morro + * 2016-05-30 Morro 初版完成 ******************************************************************************/ #ifndef _RING_BUF_H_ @@ -19,12 +19,12 @@ extern "C" { #endif -/*λ*/ +/*环形缓冲区管理器*/ typedef struct { - unsigned char *buf; /*λ */ - unsigned int size; /*λ */ - unsigned int front; /*ͷָ */ - unsigned int rear; /*βָ */ + unsigned char *buf; /*环形缓冲区 */ + unsigned int size; /*环形缓冲区 */ + unsigned int front; /*头指针 */ + unsigned int rear; /*尾指针 */ }ring_buf_t; bool ring_buf_init(ring_buf_t *r,unsigned char *buf,unsigned int size); diff --git a/Project/GateWay/source/User/Inc/spiflash.h b/Project/GateWay/source/User/Inc/spiflash.h index cbfcd1c..4228fed 100644 --- a/Project/GateWay/source/User/Inc/spiflash.h +++ b/Project/GateWay/source/User/Inc/spiflash.h @@ -42,20 +42,20 @@ uint32_t SpiFlashReadId(void); //#if (LORA_MODULE == WH_LR36_L) //#define LOG_SAV_SIZE 78 -//#define LOG_SAV_NUM_SECTOR 52 //ÿ洢 +//#define LOG_SAV_NUM_SECTOR 52 //每扇区存储数量 //#else //#define LOG_SAV_SIZE 78 //150 -//#define LOG_SAV_NUM_SECTOR 52 //27 //ÿ洢 +//#define LOG_SAV_NUM_SECTOR 52 //27 //每扇区存储数量 //#endif #define LOG_SAV_SIZE_MAX 256 #define LOG_SAV_NUM_MAX ((SPIFLASH_SECTOR_NUM - LOG_SAV_START_SECTOR) * LOG_SAV_NUM_SECTOR) typedef struct { - uint32_t LogSavFlag; //־洢־ - uint32_t LogIdx; //־ - uint32_t LogEndAddr; //־ַ - uint32_t TimeStamp; //洢ʱ + uint32_t LogSavFlag; //日志存储标志 + uint32_t LogIdx; //日志序号 + uint32_t LogEndAddr; //日志结束地址 + uint32_t TimeStamp; //存储时间 }LogHeader_t, *LogHeader; void SavMMC5983Calib(uint8_t *wData, uint32_t wLen); diff --git a/Project/GateWay/source/User/Src/CatOneTask.c b/Project/GateWay/source/User/Src/CatOneTask.c index 2595576..b31a2c0 100644 --- a/Project/GateWay/source/User/Src/CatOneTask.c +++ b/Project/GateWay/source/User/Src/CatOneTask.c @@ -23,7 +23,7 @@ static uint8_t EthRevTimeOutCnt; static uint16_t CatSendErrCnt = 0; -// ETH״̬ر CatOne_t ṹ +// ETH状态机相关变量已移至 CatOne_t 结构体中 #define CAT1_DBG_LOG(...) { if(CAT1DispEn) Debug_Printf(__VA_ARGS__);} //#define CAT1_DBG_ARRAY(ARRAY, SIZE) { if(CAT1DispEn) {DBG_ARRAY(ARRAY,SIZE)}} @@ -32,43 +32,43 @@ static uint16_t CatSendErrCnt = 0; //const char *CatOneATCmdStr[16] = { // "NULL", -// "AT\r\n", // -// "ATE0\r\n", //ػ -// "AT+CPIN?\r\n", //ʶ +// "AT\r\n", //开机检测 +// "ATE0\r\n", //关回显 +// "AT+CPIN?\r\n", //识卡 //// "AT+CIMI\r\n", //IMEI // "AT+CGSN=1\r\n", -// "AT+LCCID\r\n", // -// "AT+CEREG?\r\n", //ѯע״̬ -// "AT+CGPADDR=1\r\n", //ѯIPַ -// "AT+CSQ\r\n", //ѯźǿ +// "AT+LCCID\r\n", //读卡号 +// "AT+CEREG?\r\n", //查询注册状态 +// "AT+CGPADDR=1\r\n", //查询IP地址 +// "AT+CSQ\r\n", //查询信号强度 // "AT+LDNSGIP=gxjt.cui635.cn\r\n", -// "AT+LBS=0\r\n", //ȡվλϢ -// "AT+LIPOPEN=", //TCPַͶ˿ڣAT+LIPOPEN="TCP","114.55.52.96",6803 -// "AT+LIPSEND=", //, AT+LIPSEND=0,1,20,"31313131313131323232323232" -// "AT+LIPCLOSE=0\r\n",//Ͽ +// "AT+LBS=0\r\n", //获取基站定位信息 +// "AT+LIPOPEN=", //设置TCP服务器地址和端口,AT+LIPOPEN="TCP","114.55.52.96",6803 +// "AT+LIPSEND=", //发送数据, AT+LIPSEND=0,1,20,"31313131313131323232323232" +// "AT+LIPCLOSE=0\r\n",//断开连接 // "AT+LBSPARA=http://locator-aep.xiot.senthink.com:80/locator/v0.1/locate,B84E427D95B1DF4A3F49B18DDF714C72\r\n", -// "AT+CCLK?\r\n", //ȡʱ +// "AT+CCLK?\r\n", //获取时间 //}; const char *CatOneATCmdStr[16] = { "NULL", - "AT\r\n", // - "ATE0\r\n", //ػ - "AT+CPIN?\r\n", //ʶ + "AT\r\n", //开机检测 + "ATE0\r\n", //关回显 + "AT+CPIN?\r\n", //识卡 // "AT+CIMI\r\n", //IMEI "AT+CGSN=1\r\n", - "AT+QCCID\r\n", // - "AT+CEREG?\r\n", //ѯע״̬ - "AT+CGPADDR=1\r\n", //ѯIPַ - "AT+CSQ\r\n", //ѯźǿ + "AT+QCCID\r\n", //读卡号 + "AT+CEREG?\r\n", //查询注册状态 + "AT+CGPADDR=1\r\n", //查询IP地址 + "AT+CSQ\r\n", //查询信号强度 "AT+LDNSGIP=gxjt.cui635.cn\r\n", - "AT+QLBS\r\n", //ȡվλϢ - "AT+QIOPEN=", //TCPַͶ˿ڣAT+LIPOPEN="TCP","114.55.52.96",6803 - "AT+QISEND=", //, AT+LIPSEND=0,1,20,"31313131313131323232323232" - "AT+QICLOSE=0\r\n",//Ͽ + "AT+QLBS\r\n", //获取基站定位信息 + "AT+QIOPEN=", //设置TCP服务器地址和端口,AT+LIPOPEN="TCP","114.55.52.96",6803 + "AT+QISEND=", //发送数据, AT+LIPSEND=0,1,20,"31313131313131323232323232" + "AT+QICLOSE=0\r\n",//断开连接 "AT+QLBSCFG=\"server\",http://locator-aep.xiot.senthink.com:80/locator/v0.1/locate\r\n", "AT+QLBSCFG=\"token\",45B516D3078467E84DD2CFBF3532A4CB\r\n", - "AT+CCLK?\r\n", //ȡʱ + "AT+CCLK?\r\n", //获取时间 }; void Cat1DBGOnOff(bool OnOff) @@ -146,7 +146,7 @@ void CatOneGetIMEIAndSIM(char *Imei, char *Sim) memcpy(Sim, CatOne.SIM, 20); } -//true-busy, false-Idle +//返回true-busy, false-Idle bool CatOneGetStatus(void) { if(CatOne.Cat1Status == CAT_ONE_IDEL) @@ -355,7 +355,7 @@ void CatOneAtCmdAnalyze(char *RxBuff) return; } //CatOne.Cat1Status = CAT_ONE_CLOSE_TCP; - rt_sem_release(CatOneRev_Sem);// + rt_sem_release(CatOneRev_Sem);//接收任务 return; } default: @@ -459,7 +459,7 @@ void CatOneLoopHandler(void) CatOneAtCmdSend(CatOne.AtCmd, 2000, CatOne.NextStatus); CAT1_DBG_LOG("Cat1 Ret TimeOut, ReSend(%d)...\r\n", CatOne.AtCmdResendCnt); } - else { //3δ󣬹ػ + else { //3次错误,关机 CAT1_DBG_LOG("Cat1 error, Close!\r\n"); if(CatOne.AtCmd == CAT_ONE_LIPSEND) CatOne.Cat1Status = CAT_ONE_CLOSE_TCP; @@ -499,7 +499,7 @@ void CatOneLoopHandler(void) } break; - case CAT_ONE_REG_SVR: //ע + case CAT_ONE_REG_SVR: //注册服务器 ret = GateWayRegister(CatOneEthTxBuff); rt_mq_send(CatOne.GateWay->NetSendData_MQ, CatOneEthTxBuff, ret); CatOne.Cat1Status = CAT_ONE_WAIT_SEND; @@ -513,7 +513,7 @@ void CatOneLoopHandler(void) CatOne.Cat1Status = CAT_ONE_SEND_DATA; } else { - if(CatOne.Cat1Status == CAT_ONE_RESET || CatOne.Cat1Status == CAT_ONE_OFF) //ⲿִУ״̬ı + if(CatOne.Cat1Status == CAT_ONE_RESET || CatOne.Cat1Status == CAT_ONE_OFF) //外部命令执行,状态改变 return; if(!CatOne.TcpConnFlag) { CatOne.Cat1Status = CAT_ONE_OFF; @@ -554,7 +554,7 @@ void CatOneLoopHandler(void) else { Cat1RevErrCnt = 0; } - if(CatOne.GateWay->SvrRegFlag == false) //豸ûעᣬر4Gȴһע + if(CatOne.GateWay->SvrRegFlag == false) //设备没注册,关闭4G,等待下一次重新注册 CatOne.Cat1Status = CAT_ONE_OFF; else CatOne.Cat1Status = CAT_ONE_WAIT_SEND; @@ -618,15 +618,15 @@ void EthLoopHandler(void) ETH_RESET_CLR(); rt_thread_delay(10); ETH_RESET_SET(); - rt_thread_delay(2000); // ӳλȶʱ䵽2 + rt_thread_delay(2000); // 延长复位后稳定时间到2秒 CatOne.EthStatus = ETH_WAIT_LINK; CatOne.EthLinkWaitCnt = 0; - CatOne.EthFirstRegFlag = true; // ״ע־ + CatOne.EthFirstRegFlag = true; // 重置首次注册标志 break; case ETH_WAIT_LINK: if(CatOne.EthLinkWaitCnt == 0) { - /* ״νȴ·״̬,ȴģȫ */ + /* 首次进入等待链路状态,等待模块完全启动 */ CAT1_DBG_LOG("ETH Waiting for module ready...\r\n"); rt_thread_delay(2000); } @@ -651,7 +651,7 @@ void EthLoopHandler(void) case ETH_REG_SVR: { - // ״עʱӳ٣ȴϵͳȶ + // 首次注册时添加延迟,等待系统稳定 if(CatOne.EthFirstRegFlag) { CAT1_DBG_LOG("ETH First Register, waiting for system stable...\r\n"); rt_thread_delay(ETH_FIRST_REG_DELAY); @@ -662,7 +662,7 @@ void EthLoopHandler(void) rt_mq_send(CatOne.GateWay->NetSendData_MQ, CatOneEthTxBuff, ret); CAT1_DBG_LOG("ETH Register Server...\r\n"); CatOne.EthStatus = ETH_WAIT_SEND; - CatOne.EthSendRetryCnt = 0; // Լ + CatOne.EthSendRetryCnt = 0; // 重置重试计数器 } break; @@ -835,7 +835,7 @@ void CatOne_Eth_Thread_Entry(void *parameter) rt_kprintf("CatOneRev Thread Create Failed! Exit...\r\n"); return; } - rt_kprintf("CatOne Thread is running\r\n"); + rt_kprintf("CatOne Thread is running!\r\n"); while(1) { //rt_mutex_take(GateWay->UartRevMutex, RT_WAITING_FOREVER); diff --git a/Project/GateWay/source/User/Src/Encryption.c b/Project/GateWay/source/User/Src/Encryption.c index daca8b5..748bd79 100644 --- a/Project/GateWay/source/User/Src/Encryption.c +++ b/Project/GateWay/source/User/Src/Encryption.c @@ -1,6 +1,6 @@ #include "encryption.h" -//ӻܱ +//从机加密表 const unsigned char EPT_Table[32][6] = { {1, 6, 4, 2, 3, 5}, {2, 4, 6, 3, 5, 1}, {3, 5, 6, 2, 1, 4}, {5, 3, 2, 1, 4, 6}, {4, 2, 3, 1, 5, 6}, {6, 3, 5, 1, 4, 2}, {3, 5, 2, 6, 4, 1}, {2, 5, 4, 3, 1, 6}, @@ -12,7 +12,7 @@ const unsigned char EPT_Table[32][6] = { {3, 6, 5, 4, 2, 1}, {1, 2, 6, 3, 5, 4}, {4, 6, 5, 3, 2, 1}, {5, 3, 4, 2, 6, 1} }; -//ӻܱ +//从机解密表: const unsigned char DPT_Table[32][5] ={ {1, 4, 2, 3, 5}, {2, 4, 3, 5, 1}, {3, 5, 2, 1, 4}, {5, 3, 2, 1, 4}, {4, 2, 3, 1, 5}, {3, 5, 1, 4, 2}, {3, 5, 2, 4, 1}, {2, 5, 4, 3, 1}, @@ -24,7 +24,7 @@ const unsigned char DPT_Table[32][5] ={ {3, 5, 4, 2, 1}, {1, 2, 3, 5, 4}, {4, 5, 3, 2, 1}, {5, 3, 4, 2, 1} }; -//λܱ +//数据位加密表: const unsigned char EPT_D[32] = { 0x23, 0x4c, 0x92, 0x38, 0x52, 0xa4, 0x9a, 0x61, 0x86, 0xc8, 0x70, 0x16, 0x32, 0x58, 0x62, 0x83, @@ -33,11 +33,11 @@ const unsigned char EPT_D[32] = { }; /****************************************************************/ -/* ܺ */ +/* 加密函数 */ /* */ -/*: *data,δܵͨЭ */ +/*函数入口: *data,未加密的普通协议数据 */ /* */ -/*: *EPT_dataɵļЭ */ +/*函数出口: *EPT_data,生成的加密协议 */ /****************************************************************/ void Encrypt_Code(unsigned char *data, unsigned char *EPT_data) { unsigned char Edata[6]; @@ -60,11 +60,11 @@ void Encrypt_Code(unsigned char *data, unsigned char *EPT_data) { } /****************************************************************/ -/* ܺ */ +/* 解密函数 */ /* */ -/*ڣ *EPT_dataҪܵļЭ */ +/*函数入口: *EPT_data,需要解密的加密协议 */ /* */ -/*ڣ *DPT_dataɵͨЭ */ +/*函数出口: *DPT_data,生成的普通协议 */ /****************************************************************/ void Decrypt_Code(unsigned char *EPT_data,unsigned char *DPT_data) { unsigned char data[5]; diff --git a/Project/GateWay/source/User/Src/LoraTask.c b/Project/GateWay/source/User/Src/LoraTask.c index 9ad546a..05c32d9 100644 --- a/Project/GateWay/source/User/Src/LoraTask.c +++ b/Project/GateWay/source/User/Src/LoraTask.c @@ -3,7 +3,7 @@ #include "CatOneTask.h" #include "DebugCmd.h" -#define UC_OFFLINE_TIME_INTERVAL_MAX (2 * 60 * 60)//жʱλ +#define UC_OFFLINE_TIME_INTERVAL_MAX (2 * 60 * 60)//离线判断最大时间间隔,单位秒 static rt_sem_t LoraDioIRQ_Sem = RT_NULL; static rt_thread_t LoraIRQ_Thread = RT_NULL; @@ -14,7 +14,7 @@ void LoraSend(uint8_t* pucBuff, uint8_t ucLen) Sx1276LoRaSendBuffer(pucBuff, ucLen); } -//LoraϢͳһŵϢУɽ +//Lora接收消息统一放到消息队列,由接收任务处理 int LoraRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) { uint8_t *sData; @@ -41,7 +41,7 @@ void LoraIRQ_Thread_Entry(void *parameter) rt_err_t result; static uint16_t LoraErrCnt = 0; - Debug_Printf("LoraRev Thread is running\r\n"); + Debug_Printf("LoraRev Thread is running!\r\n"); while(1) { if(GateWay->ConfigPara.Lora.OnOff == false) { rt_thread_delay(100); @@ -55,9 +55,9 @@ void LoraIRQ_Thread_Entry(void *parameter) } else { LoraErrCnt++; - if(LoraErrCnt > LORA_ERR_RESET_DLY_MAX) { //15ûյloraloraģ + if(LoraErrCnt > LORA_ERR_RESET_DLY_MAX) { //15分钟内没有收到lora数据重启lora模块 LoraErrCnt = 0; - Debug_Printf("Lora Reset\r\n"); + Debug_Printf("Lora Reset!\r\n"); Sx1276LoRaInit(LoraRevCallBack); } } @@ -97,7 +97,7 @@ void Lora_Thread_Entry(void *parameter) rt_thread_startup(LoraIRQ_Thread); Sx1276LoRaInit(LoraRevCallBack); - Debug_Printf("Lora Thread is running\r\n"); + Debug_Printf("Lora Thread is running!\r\n"); #ifdef LORA_LOWPOWER while(1) { if(GateWay->ConfigPara.Lora.OnOff == false) { @@ -108,10 +108,10 @@ void Lora_Thread_Entry(void *parameter) result = rt_mq_recv(GateWay->LoraRev_MQ, Payload, 256, 1000); if(result == RT_EOK) { int ret = GateWay->CommUnitRevCallBack(GateWay, &Payload[1], Payload[0], LoRaSendBuffer); - if(ret == 0xff) //עϢ + if(ret == 0xff) //注册信息 continue; } - else { //ж + else { //离线判断 for(int i = 0; i < COMMUNIT_NUM_MAX; i++) { if(GateWay->ConfigPara.CommUnitArray[i].RegFlag == true) { if(GateWay->ConfigPara.CommUnitArray[i].CommErrCnt < UC_OFFLINE_TIME_INTERVAL_MAX) { @@ -131,7 +131,7 @@ void Lora_Thread_Entry(void *parameter) GateWay->ConfigPara.CommUnitArray[i].Mac[0][3], GateWay->ConfigPara.CommUnitArray[i].Mac[0][4], GateWay->ConfigPara.CommUnitArray[i].Mac[0][5]); - CatOneEthSendQueue(MegData, 10); //Ϣ + CatOneEthSendQueue(MegData, 10); //发送离线消息 } } } @@ -171,7 +171,7 @@ void Lora_Thread_Entry(void *parameter) result = rt_mq_recv(GateWay->LoraRev_MQ, Payload, 256, 1000); if(result == RT_EOK) { int ret = GateWay->CommUnitRevCallBack(GateWay, &Payload[1], Payload[0], Sx1276LoRaSendBuffer); - if(ret == 0xff) //עϢ + if(ret == 0xff) //注册信息 continue; if(UnitCommSendFlag && GateWay->ConfigPara.CommUnitArray[SendUnitCommIdx].RevNewDataFlag) { @@ -179,7 +179,7 @@ void Lora_Thread_Entry(void *parameter) SendUnitCommIdx++; } } - else if(UnitCommSendFlag) { //ж + else if(UnitCommSendFlag) { //离线判断 GateWay->ConfigPara.CommUnitArray[SendUnitCommIdx].CommErrCnt++; if(GateWay->ConfigPara.CommUnitArray[SendUnitCommIdx].CommErrCnt == 10) { GateWay->ConfigPara.CommUnitArray[SendUnitCommIdx].CommErrCnt = 0; @@ -190,7 +190,7 @@ void Lora_Thread_Entry(void *parameter) MegData[2] = COMM_UNIT_CMD_READ; memcpy(&MegData[3], GateWay->ConfigPara.CommUnitArray[SendUnitCommIdx].Mac[0], 6); MegData[9] = GateWay->ConfigPara.CommUnitArray[SendUnitCommIdx].CommStatus; - CatOneEthSendQueue(MegData, 10); //Ϣ + CatOneEthSendQueue(MegData, 10); //发送离线消息 } } UnitCommSendFlag = false; diff --git a/Project/GateWay/source/User/Src/Public.c b/Project/GateWay/source/User/Src/Public.c index 66d4d0b..da72f67 100644 --- a/Project/GateWay/source/User/Src/Public.c +++ b/Project/GateWay/source/User/Src/Public.c @@ -7,50 +7,50 @@ #include #include "sx127x.h" -//Ӧݳ +//传感器对应的数据长度 const uint8_t SensorTypeDataLen[] = { - 0, //0x0000- - 30, //0x0001-ӦⵥԪ - 12, //0x0002-͸ѹⵥԪ - 14, //0x0003-ԲⵥԪ - 10, //0x0004-ռⵥԪ - 6, //0x0005-΢ - 6, //0x0006-άμⵥԪ - 3, //0x0007-ͨѶԪ - 18, //0x0008-άӦⵥԪ - 9, //0x0009-ʾ(豸) - 12, //0x000A-ˮλ - 0, //0x000B- - 0, //0x000C- - 14, //0x000D-άӦⵥԪ - 9, //0x000E-ѷⵥԪ - 0, //0x000F-Ԥ - 8, //0x0010-̬ⵥԪ - 4, //0x0011-λƼⵥԪ - 4, //0x0012-Ӧ - 4, //0x0013-ѹ - 4, //0x0014-΢ഫ - 0, //0x0015-ʽ - 0, //0x0016-ʽ - 4, //0x0017-ֽͨӦ - 4, //0x0018-ͨê - 32, //0x0019-8ֽͨѹ - 32, //0x001A-8ͨê - 0, //0x001B-16ֽͨӦ - 0, //0x001C-16ͨê - 0, //0x001D-ը - 0, //0x001E-֧ܴ - 0, //0x001F-ѭ - 19, //0x0020-λƼ + 0, //0x0000-保留 + 30, //0x0001-应力场检测单元 + 12, //0x0002-渗透压检测单元 + 14, //0x0003-弹性波导检测单元 + 10, //0x0004-介电质普检测单元 + 6, //0x0005-微振动 + 6, //0x0006-三维连续变形检测单元 + 3, //0x0007-通讯单元 + 18, //0x0008-三维应力检测单元 + 9, //0x0009-激光示踪(主设备) + 12, //0x000A-水位计 + 0, //0x000B-保留 + 0, //0x000C-保留 + 14, //0x000D-二维应力场检测单元 + 9, //0x000E-裂缝检测单元 + 0, //0x000F-预留 + 8, //0x0010-姿态检测单元 + 4, //0x0011-激光位移检测单元 + 4, //0x0012-表面应力传感器 + 4, //0x0013-压力传感器 + 4, //0x0014-微波测距传感器 + 0, //0x0015-表贴式结冰传感器 + 0, //0x0016-埋入式结冰传感器 + 4, //0x0017-单通道钢筋应力传感器 + 4, //0x0018-单通道锚杆轴力传感器 + 32, //0x0019-8通道钢筋拉压力传感器 + 32, //0x001A-8通道锚杆轴力传感器 + 0, //0x001B-16通道钢筋应力传感器 + 0, //0x001C-16通道锚杆轴力传感器 + 0, //0x001D-爆炸冲击传感器 + 0, //0x001E-随行支架传感器 + 0, //0x001F-冻融循环传感器 + 19, //0x0020-位移计 }; /***************************************************************************************** -* : CRC_Modbus -* : CRC16㺯 -* : wBase, ʽ - ParaУ - Data, Уݳ -* ֵ: crc16Уֵ +* 函数名称: CRC_Modbus +* 功能描述: CRC16计算函数 +* 参 数: wBase, 多项式 + Para,校验数据入口 + Data, 校验数据长度入口 +* 返 回 值: crc16校验值 *****************************************************************************************/ uint16_t CRC_Modbus(uint16_t wBase, __IO uint8_t *para, uint16_t length) { @@ -73,12 +73,12 @@ uint16_t CRC_Modbus(uint16_t wBase, __IO uint8_t *para, uint16_t length) } /***************************************************************************************** -* : HexToAscii -* : HEXתΪASCIIַ -* : HexData, 16 - ASCDataתASCII - sLen, Ҫת16ݳ -* ֵ: +* 函数名称: HexToAscii +* 功能描述: HEX转换为ASCII字符串函数 +* 参 数: HexData, 16进制数据入口 + ASCData,转换后的ASCII数据 + sLen, 需要转的16进制数据长度 +* 返 回 值: 无 *****************************************************************************************/ void HexToAscii(uint8_t *HexData, char *ASCData, uint8_t sLen) { @@ -105,12 +105,12 @@ void HexToAscii(uint8_t *HexData, char *ASCData, uint8_t sLen) } /***************************************************************************************** -* : AsciiToHex -* : AscIIַתΪ16 -* : ASCData, AscIIַ - HexDataת - sLen, Ҫתַ -* ֵ: +* 函数名称: AsciiToHex +* 功能描述: AscII字符串转换为16进制数组 +* 参 数: ASCData, AscII字符串入口 + HexData,转换后的数据 + sLen, 需要转的字符串长度 +* 返 回 值: 无 *****************************************************************************************/ uint8_t AsciiToHex(char *ASCData, uint8_t *HexData, uint8_t sLen) { @@ -142,11 +142,11 @@ uint8_t AsciiToHex(char *ASCData, uint8_t *HexData, uint8_t sLen) } /***************************************************************************************** -* : ReadHistoryData -* : ȡʷ -* : rData, - rLen, ݳ -* ֵ: +* 函数名称: ReadHistoryData +* 功能描述: 读取历史数据 +* 参 数: rData,输入数据 + rLen, 输入数据长度 +* 返 回 值: 无 *****************************************************************************************/ int ReadHistoryData(LogHeader LogH, uint8_t **Data, int Idx) { @@ -154,11 +154,11 @@ int ReadHistoryData(LogHeader LogH, uint8_t **Data, int Idx) } /***************************************************************************************** -* : NetCommOrgData -* : ϱ֯ -* : MegData, Ϣ - OutData, ݳ -* ֵ: ݳ +* 函数名称: NetCommOrgData +* 功能描述: 上报数据组织 +* 参 数: MegData, 消息队列数据 + OutData, 输出数据出口 +* 返 回 值: 数据长度 *****************************************************************************************/ int NetCommOrgData(GateWayPara GateWay, uint8_t *MegData, uint8_t *OutData) { @@ -197,11 +197,11 @@ int NetCommOrgData(GateWayPara GateWay, uint8_t *MegData, uint8_t *OutData) } /***************************************************************************************** -* : CheckCommUnitReg -* : 豸Ƿע -* : GateWay,ؾ - CommUnitMac, 豸MAC -* ֵ: ע᷵ط0,ûע᷵-1 +* 函数名称: CheckCommUnitReg +* 功能描述: 检查设备是否注册 +* 参 数: GateWay,网关句柄 + CommUnitMac, 待检查的设备MAC +* 返 回 值: 已注册返回非0,没注册返回-1 *****************************************************************************************/ int CheckCommUnitReg(GateWayPara GateWay, uint8_t *CommUnitMac) { @@ -214,15 +214,15 @@ int CheckCommUnitReg(GateWayPara GateWay, uint8_t *CommUnitMac) return -1; } /***************************************************************************************** -* : CheckCommUnitExcl -* : 豸Ƿų -* : GateWay,ؾ - CommUnitMac, 豸MAC -* ֵ: ųط0,ûų-1 +* 函数名称: CheckCommUnitExcl +* 功能描述: 检查设备是否排除 +* 参 数: GateWay,网关句柄 + CommUnitMac, 待检查的设备MAC +* 返 回 值: 已排除返回非0,没排除返回-1 *****************************************************************************************/ int CheckCommUnitExcl(GateWayPara GateWay, uint8_t *CommUnitMac) { - for(int i = 0; i < COMMUNIT_NUM_MAX; i++) {//жǷų + for(int i = 0; i < COMMUNIT_NUM_MAX; i++) {//判断是否被排除 if(memcmp(GateWay->ConfigPara.ExclCommUnit[i].ExclMac, CommUnitMac, 6) == 0) { if(GateWay->ConfigPara.ExclCommUnit[i].ExclFlag == true) return i; @@ -231,14 +231,14 @@ int CheckCommUnitExcl(GateWayPara GateWay, uint8_t *CommUnitMac) return -1; } /***************************************************************************************** -* : CommUnitSendCmd -* : ·ͨѶԪָ -* : GateWay, ؾ - CommUnitMacͨѶԪMACַ - Cmd, - Payload, · - PayloadLen ·ݳ -* ֵ: +* 函数名称: CommUnitSendCmd +* 功能描述: 网关下发通讯单元指令函数 +* 参 数: GateWay, 网关句柄 + CommUnitMac,通讯单元MAC地址 + Cmd, 命令字 + Payload, 下发数据 + PayloadLen, 下发数据长度 +* 返 回 值: 无 *****************************************************************************************/ void CommUnitCmdSend(GateWayPara GateWay, uint8_t *CommUnitMac, CommUnitCmd_m Cmd, uint8_t *Payload, uint16_t PayloadLen, SendData Send) { @@ -279,12 +279,12 @@ void CommUnitCmdSend(GateWayPara GateWay, uint8_t *CommUnitMac, CommUnitCmd_m Cm } /***************************************************************************************** -* : CommUintOrgData -* : ϴݺ -* : CUPara, ͨѶԪ - CUData, ͨѶԪ - sData, -* ֵ: ݳ +* 函数名称: CommUintOrgData +* 功能描述: 上传传感器数据函数 +* 参 数: CUPara, 通讯单元参数 + CUData, 通讯单元数据 + sData, 数据入口 +* 返 回 值: 数据长度 *****************************************************************************************/ int CommUintOrgData(GateWayPara GateWay, CommUnitPara CUPara, CommUnitData CUData, uint8_t *sData) { @@ -468,11 +468,11 @@ void DebugDisplaySensorData(int SensorIdx, uint16_t SensorType, uint8_t *SensorD } /***************************************************************************************** -* : CommUnitAnalyze -* : ͨѶԪݽʹLORARS485ͨѶ -* : rData, - rLen, ݳ -* ֵ: ؽյͨѶԪţ󷵻-1 +* 函数名称: CommUnitAnalyze +* 功能描述: 通讯单元数据解析,使用于LORA和RS485通讯 +* 参 数: rData,输入数据 + rLen, 输入数据长度 +* 返 回 值: 返回接收到的通讯单元序号,错误返回-1 *****************************************************************************************/ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData Response) { @@ -500,12 +500,12 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData if((CUHeader->Cmd != COMM_UNIT_CMD_REG && CUHeader->Cmd != COMM_UNIT_CMD_GET_SIGNAL) && (memcmp(GateWay->ConfigPara.GwMac, CUHeader->GWMac, 6) != 0)) return -1; - CommUnitIdx = CheckCommUnitReg(GateWay, CUHeader->DevMac);//жǷע豸 + CommUnitIdx = CheckCommUnitReg(GateWay, CUHeader->DevMac);//判断是否是已注册的设备 if(CommUnitIdx < 0) { - if(CUHeader->Cmd != COMM_UNIT_CMD_REG && CUHeader->Cmd != COMM_UNIT_CMD_GET_SIGNAL){//жǷע + if(CUHeader->Cmd != COMM_UNIT_CMD_REG && CUHeader->Cmd != COMM_UNIT_CMD_GET_SIGNAL){//判断是否是注册请求 return -1; } - ExclCommUnit = CheckCommUnitExcl(GateWay, CUHeader->DevMac);//жǷDZų豸 + ExclCommUnit = CheckCommUnitExcl(GateWay, CUHeader->DevMac);//判断是否是被排除的设备 if(ExclCommUnit > -1) { return -1; } @@ -520,7 +520,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData // if(CUHeader->PayloadLen < 2) // return -1; - if(CommUnitIdx >= 0) { //豸 + if(CommUnitIdx >= 0) { //设备存在 MAIN_DBG_LOG("\r\nCommUnit has already been registered! Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CUHeader->DevMac[0], CUHeader->DevMac[1], CUHeader->DevMac[2], CUHeader->DevMac[3], CUHeader->DevMac[4], CUHeader->DevMac[5]); uint8_t ret = 1; @@ -544,7 +544,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData GateWay->ConfigPara.CommUnitArray[i].ContLaser = false; GateWay->ConfigPara.CommUnitArray[i].LaserOnOff = false; - GateWay->ConfigPara.CommUnitArray[i].CUType = DEV_TYPE_EXT_COMMUNIT;//ͨѶԪ + GateWay->ConfigPara.CommUnitArray[i].CUType = DEV_TYPE_EXT_COMMUNIT;//外置通讯单元 MAIN_DBG_LOG("\r\nCommUnit register succeed!\r\n"); memcpy(GateWay->ConfigPara.CommUnitArray[i].MasterMac, &PayLoad[1], 6); @@ -570,7 +570,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData uint8_t ret = 1; CommUnitCmdSend(GateWay, CUHeader->DevMac, COMM_UNIT_CMD_REG, &ret, 1, Response); - if(GateWay->SvrRegFlag) { //עᣬ豸ָ + if(GateWay->SvrRegFlag) { //网关已注册,向服务发送新设备添加指令 PayLoadLen = (GateWay->ConfigPara.CommUnitArray[i].SensorN * 6) + 2; MegData = rt_malloc(PayLoadLen + 3); MegData[0] = PayLoadLen & 0x00ff;; @@ -618,7 +618,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData else if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].ContLaser == true) { if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff == true) - {//򿪼 + {//打开激光 CommUnitCmdSend(GateWay, CUHeader->DevMac, COMM_UNIT_CMD_CONT_LASER, (uint8_t *)&GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff, 1, Response); } MAIN_DBG_LOG("Issue laser control commands.\r\n"); @@ -653,7 +653,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData // int16_t Rssi; // int8_t Snr; // SX1276LoCalcRssiSnr(&Rssi, &Snr); - MAIN_DBG_LOG("\r\nCUMac:%02X-%02X-%02X-%02X-%02X-%02X, Bat: %d%, SN: %dRssi:%d, Snr:%d\r\n", + MAIN_DBG_LOG("\r\nCUMac:%02X-%02X-%02X-%02X-%02X-%02X, Bat: %d%, SN: %d,Rssi:%d, Snr:%d\r\n", CUHeader->DevMac[0], CUHeader->DevMac[1], CUHeader->DevMac[2], CUHeader->DevMac[3], CUHeader->DevMac[4], CUHeader->DevMac[5], GateWay->ConfigPara.CommUnitArray[CommUnitIdx].BatLevel, GateWay->ConfigPara.CommUnitArray[CommUnitIdx].SensorN, @@ -661,7 +661,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData GateWay->ConfigPara.CommUnitArray[CommUnitIdx].Nsr); for(int i = 0; i < GateWay->ConfigPara.CommUnitArray[CommUnitIdx].SensorN; i++) { memcpy(GateWay->CUDataArray[CommUnitIdx].Data[i], &PayLoad[0], SensorTypeDataLen[GateWay->ConfigPara.CommUnitArray[CommUnitIdx].SensorType[i]]); - //ʾ + //显示传感器数据 DebugDisplaySensorData(i, GateWay->ConfigPara.CommUnitArray[CommUnitIdx].SensorType[i], GateWay->CUDataArray[CommUnitIdx].Data[i]); len += SensorTypeDataLen[GateWay->ConfigPara.CommUnitArray[CommUnitIdx].SensorType[i]]; } @@ -701,7 +701,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData else if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].ContLaser == true) { if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff == true) - {//򿪼 + {//打开激光 CommUnitCmdSend(GateWay, CUHeader->DevMac, COMM_UNIT_CMD_CONT_LASER, (uint8_t *)&GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff, 1, Response); } MAIN_DBG_LOG("Issue laser control commands.\r\n"); @@ -753,7 +753,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData else if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].ContLaser == true) { if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff == true) - {//򿪼 + {//打开激光 CommUnitCmdSend(GateWay, CUHeader->DevMac, COMM_UNIT_CMD_CONT_LASER, (uint8_t *)&GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff, 1, Response); } MAIN_DBG_LOG("Issue laser control commands.\r\n"); @@ -773,7 +773,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData case COMM_UNIT_CMD_CONT_LASER:{ if(PayLoad[0] == 0) { - //Ӧ + //应答服务器 MegData = rt_malloc(10); MegData[0] = 7; MegData[1] = 0; @@ -792,7 +792,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData CUHeader->DevMac[0], CUHeader->DevMac[1], CUHeader->DevMac[2], CUHeader->DevMac[3], CUHeader->DevMac[4], CUHeader->DevMac[5]); } else if(PayLoad[0] == 1){ - //Ӧ + //应答服务器 MegData = rt_malloc(10); MegData[0] = 7; MegData[1] = 0; @@ -825,7 +825,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData else if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].ContLaser == true) { if(GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff == true) - {//򿪼 + {//打开激光 CommUnitCmdSend(GateWay, CUHeader->DevMac, COMM_UNIT_CMD_CONT_LASER, (uint8_t *)&GateWay->ConfigPara.CommUnitArray[CommUnitIdx].LaserOnOff, 1, Response); } MAIN_DBG_LOG("Issue laser control commands.\r\n"); @@ -863,11 +863,11 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData } /***************************************************************************************** -* : Cat1RevCallBack -* : 4Gջص -* : rDataӿ - rLen, ݳӿ -* ֵ: +* 函数名称: Cat1RevCallBack +* 功能描述: 4G接收回调函数 +* 参 数: rData,数据输入接口 + rLen, 数据长度输入接口 +* 返 回 值: 无 *****************************************************************************************/ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) { @@ -909,7 +909,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) memcpy(&CommUintMac[0], Data, 6); - if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //ڲͨѶԪ + if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //内部通讯单元处理 if(GateWay->ConfigPara.Rs485Ch1.CommUnitEnable == true) CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_TIME_SYNC, (uint8_t *)&NCHeader->Timestamp, 4, GateWay->ConfigPara.Rs485Ch1.RS485Send); else @@ -921,18 +921,18 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) else RS485CmdSend(GateWay, 2, &SCPara); } - for(int i = 0; i < COMMUNIT_NUM_MAX; i++)// + for(int i = 0; i < COMMUNIT_NUM_MAX; i++)//参数遍历 { if(GateWay->ConfigPara.CommUnitArray[i].RegFlag == true) - GateWay->ConfigPara.CommUnitArray[i].TimeSyncFlag = true;//Уʱλȴ´δMAC豸ϴʱ·У׼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[i].TimeSyncFlag = true;//校时置位,等待下次此MAC主设备上传数据时下发校准指令(低功耗) } - //У׼ͨѶ + //校准其他通讯网关 //CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_TIME_SYNC, &rData[14], 4, Sx1276LoRaSendBuffer); } switch(NCHeader->Cmd) { case NET_COMM_CMD_REG:{ - if(*Data == 1) { //עɹ + if(*Data == 1) { //注册成功 GateWay->SvrRegFlag = true; //memcpy(GateWay->SvrMac, NCHeader->SvrMac, 6); memset(GateWay->SvrMac, 0x00, 6); @@ -947,7 +947,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) break;} case NET_COMM_CMD_CAIL:{ - //Ӧ + //应答服务器 MegData = rt_malloc(4); MegData[0] = 1; MegData[1] = 0; @@ -956,16 +956,16 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) sLen = 4; CatOneEthSendQueue(MegData, sLen); rt_free(MegData); - //ʼУ׼ + //开始校准 memcpy(&CommUintMac[0], Data, 6); - if(memcmp(CommUintMac, Data, 6) == 0) { //У׼д + if(memcmp(CommUintMac, Data, 6) == 0) { //校准所有传感器 SensorCommPara_t SCPara; SCPara.Cmd = RS485_SENSOR_CMD_CAIL; SCPara.SensorAddr = 0x00; //SCPara.SensorType = 0x00; SCPara.CmdParaLen = 0; SCPara.CmdPara = NULL; - if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //ڲͨѶԪ + if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //内部通讯单元处理 if(GateWay->ConfigPara.Rs485Ch1.CommUnitEnable == true) RS485CmdSend(GateWay, 1, &SCPara); else @@ -978,12 +978,12 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_CAIL, NULL, 0, GateWay->ConfigPara.Rs485Ch2.RS485Send); } - for(int i = 0; i < COMMUNIT_NUM_MAX; i++)// + for(int i = 0; i < COMMUNIT_NUM_MAX; i++)//参数遍历 { if(GateWay->ConfigPara.CommUnitArray[i].RegFlag == true) - GateWay->ConfigPara.CommUnitArray[i].CailFlag = true;//У׼λȴ´δMAC豸ϴʱ·У׼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[i].CailFlag = true;//校准置位,等待下次此MAC主设备上传数据时下发校准指令(低功耗) } - //У׼ͨѶ + //校准其他通讯网关 //CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_CAIL, NULL, 0, Sx1276LoRaSendBuffer); MAIN_DBG_LOG("Calibrate all device.\r\n"); } @@ -993,15 +993,15 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) return -1; if(GateWay->ConfigPara.CommUnitArray[ret].CUType != DEV_TYPE_EXT_COMMUNIT) return -1; - if((GateWay->ConfigPara.CommUnitArray[ret].Mac[0][3] / 0x80) != 1) {//жǷΪͨѶԪ豸 - if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 1)//жͨѶ + if((GateWay->ConfigPara.CommUnitArray[ret].Mac[0][3] / 0x80) != 1) {//判断是否为通讯单元(主设备) + if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 1)//判断通讯类型 { - GateWay->ConfigPara.CommUnitArray[ret].CailFlag = true;//У׼λȴ´δMAC豸ϴʱ·У׼ָ͹ģ - //CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_CAIL, NULL, 0, Sx1276LoRaSendBuffer);//ѯģʽ + GateWay->ConfigPara.CommUnitArray[ret].CailFlag = true;//校准置位,等待下次此MAC主设备上传数据时下发校准指令(低功耗) + //CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_CAIL, NULL, 0, Sx1276LoRaSendBuffer);//查询模式 MAIN_DBG_LOG("Calibrate Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CommUintMac[0], CommUintMac[1], CommUintMac[2], CommUintMac[3], CommUintMac[4], CommUintMac[5]); } - else if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 2)//жͨѶ + else if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 2)//判断通讯类型 { if(GateWay->ConfigPara.Rs485Ch1.Enable == true && !GateWay->ConfigPara.Rs485Ch1.CommUnitEnable) { @@ -1024,7 +1024,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) MegData = rt_malloc(512); uint16_t SensorCnt = 0; sLen = 5; - if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //ڲͨѶԪ + if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //内部通讯单元处理 if(GateWay->ConfigPara.Rs485Ch1.CommUnitEnable == true) { SensorCnt++; memcpy(&MegData[sLen], GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0], 6); @@ -1055,9 +1055,9 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) MegData[sLen++] = (GateWay->HistoryNum >> 8) & 0x00ff; MegData[sLen++] = (GateWay->HistoryNum >> 16) & 0x00ff; MegData[sLen++] = (GateWay->HistoryNum >> 24) & 0x00ff; - MegData[0] = (sLen - 3) & 0x00ff;//峤 - MegData[1] = ((sLen - 3) >> 8) & 0x00ff;//峤 - MegData[2] = NET_COMM_CMD_READ_GW_INFO;//ָ + MegData[0] = (sLen - 3) & 0x00ff;//数据体长度 + MegData[1] = ((sLen - 3) >> 8) & 0x00ff;//数据体长度 + MegData[2] = NET_COMM_CMD_READ_GW_INFO;//指令 MegData[3] = SensorCnt&0xFF; MegData[4] = (SensorCnt >> 8)&0xFF; CatOneEthSendQueue(MegData, sLen); @@ -1066,7 +1066,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) } case NET_COMM_CMD_GW_PARA_CONFIG:{ - //Ӧ + //应答服务器 MegData = rt_malloc(4); MegData[0] = 1; MegData[1] = 0; @@ -1116,7 +1116,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) break; case NET_COMM_CMD_ADD_UNIT:{ - if(*Data == 1) { //¼ɹ + if(*Data == 1) { //录入成功 MAIN_DBG_LOG("Adding CommUnit succeeded...\r\n"); } else { @@ -1125,7 +1125,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) break;} case NET_COMM_CMD_LP_DEV_CONFIG: { - //ʼ + //开始配置 SvrDownLPDevConfigPara_t *LPDevConfig; LPDevConfig = (SvrDownLPDevConfigPara_t *)Data; int ret = memcmp(CommUintMac, LPDevConfig->CommDevAddr, 6); @@ -1156,7 +1156,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) MAIN_DBG_LOG("Main equipment parameter configuration. Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CommUintMac[0], CommUintMac[1], CommUintMac[2], CommUintMac[3], CommUintMac[4], CommUintMac[5]); } - //Ӧ + //应答服务器 MegData = rt_malloc(4); MegData[0] = 1; MegData[1] = 0; @@ -1174,32 +1174,32 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) return -1; if(GateWay->ConfigPara.CommUnitArray[ret].CUType != DEV_TYPE_EXT_COMMUNIT) return -1; - if((GateWay->ConfigPara.CommUnitArray[ret].Mac[0][3] / 0x80) != 1) {//жǷΪͨѶԪ豸 - if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 1)//жͨѶ + if((GateWay->ConfigPara.CommUnitArray[ret].Mac[0][3] / 0x80) != 1) {//判断是否为通讯单元(主设备) + if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 1)//判断通讯类型 { - GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = Data[6];//·򿪻߹رռ + GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = Data[6];//服务器下发打开或者关闭激光 if(GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff == true) { - GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//Ƽ⣬ȴ´δMAC豸ϴʱ·򿪼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//控制激光,等待下次此MAC主设备上传数据时下发打开激光指令(低功耗) MAIN_DBG_LOG("Waiting for the laser response. Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CommUintMac[0], CommUintMac[1], CommUintMac[2], CommUintMac[3], CommUintMac[4], CommUintMac[5]); } else if(GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff == false) - {//ֱӷ + {//直接发送 MAIN_DBG_LOG("Waiting for the laser response. Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n", CommUintMac[0], CommUintMac[1], CommUintMac[2], CommUintMac[3], CommUintMac[4], CommUintMac[5]); GateWay->ConfigPara.CommUnitArray[ret].ContLaser = false; - CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_CONT_LASER, (uint8_t *)&GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff, 1, Sx1276LoRaSendBuffer);//ѯģʽ + CommUnitCmdSend(GateWay, CommUintMac, COMM_UNIT_CMD_CONT_LASER, (uint8_t *)&GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff, 1, Sx1276LoRaSendBuffer);//查询模式 } } - else if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 2)//жͨѶ + else if(GateWay->ConfigPara.CommUnitArray[ret].Mac[0][2] == 2)//判断通讯类型 { if(GateWay->ConfigPara.Rs485Ch1.Enable == true && !GateWay->ConfigPara.Rs485Ch1.CommUnitEnable) { - GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = Data[6];//·򿪻߹رռ + GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = Data[6];//服务器下发打开或者关闭激光 if(GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff == true) { - GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//Ƽ⣬ȴ´δMAC豸ϴʱ·򿪼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//控制激光,等待下次此MAC主设备上传数据时下发打开激光指令(低功耗) } else if(GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff == false) { @@ -1208,10 +1208,10 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) } else if(GateWay->ConfigPara.Rs485Ch2.Enable == true && !GateWay->ConfigPara.Rs485Ch2.CommUnitEnable) { - GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = Data[6];//·򿪻߹رռ + GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff = Data[6];//服务器下发打开或者关闭激光 if(GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff == true) { - GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//Ƽ⣬ȴ´δMAC豸ϴʱ·򿪼ָ͹ģ + GateWay->ConfigPara.CommUnitArray[ret].ContLaser = true;//控制激光,等待下次此MAC主设备上传数据时下发打开激光指令(低功耗) } else if(GateWay->ConfigPara.CommUnitArray[ret].LaserOnOff == false) { diff --git a/Project/GateWay/source/User/Src/RS485Task.c b/Project/GateWay/source/User/Src/RS485Task.c index bf6efd9..1cc28f4 100644 --- a/Project/GateWay/source/User/Src/RS485Task.c +++ b/Project/GateWay/source/User/Src/RS485Task.c @@ -17,13 +17,13 @@ SensorCommPara_t SComm2Para; const uint8_t RS485SensorCmdPayLoadLen[RS485_SENSOR_CMD_END] = {0, 0, 0, 1, 0}; /***************************************************************************************** -* : SavSensorData -* : ¼ -* : SensorIdx, - Paraṹָ - Data, - Len, ݳ -* ֵ: +* 函数名称: SavSensorData +* 功能描述: 记录传感器数据 +* 参 数: SensorIdx, 传感器序号 + Para,传感器结构指针 + Data, 传感器数据 + Len, 传感器数据长度 +* 返 回 值: 无 *****************************************************************************************/ static void SavSensorData(uint8_t SensorIdx, CommUnitData CUData, uint8_t *Data, uint8_t Len) { @@ -36,13 +36,13 @@ static void SavSensorData(uint8_t SensorIdx, CommUnitData CUData, uint8_t *Data, } /***************************************************************************************** -* : RS485Analyze -* : 485ݽ -* : SCPara, Ͳ - Para, ṹָ - rData, - rLen, ݳ -* ֵ: +* 函数名称: RS485Analyze +* 功能描述: 485数据解析 +* 参 数: SCPara, 传感器发送参数 + Para, 传感器结构指针 + rData, 传感器数据入口 + rLen, 传感器数据长度 +* 返 回 值: 无 *****************************************************************************************/ void RS485Analyze(GateWayPara GateWay, SensorCommPara SCPara, CommUnit Para, uint8_t *rData, uint8_t rLen) { @@ -121,13 +121,13 @@ static void update_on_start(uint8_t* frame, int len, uint8_t* pload, int size) cfg.PackageNum = pReq->PackageNum; cfg.AppSize = pReq->AppSize; /** - FALSH д + 操作FALSH ,写升级参数 **/ dev_boot_write_param(cfg); update_send_cmd(0x01, 1, pReq->PackageNum); - //BOOT + //重启进入BOOT NVIC_SystemReset(); } @@ -179,10 +179,10 @@ static int update_process(void* frame, int len) /***************************************************************************************** -* : RS485SensorCmdSend -* : ·ָ -* : Para,ͨѶ -* ֵ: +* 函数名称: RS485SensorCmdSend +* 功能描述: 下发传感器指令函数 +* 参 数: Para,通讯参数入口 +* 返 回 值: 无 *****************************************************************************************/ static void RS485SensorCmdSend(GateWayPara GateWay, SensorCommPara SensorComm) { @@ -217,11 +217,11 @@ static void RS485SensorCmdSend(GateWayPara GateWay, SensorCommPara SensorComm) } /***************************************************************************************** -* : RS485SensorCmdSend -* : ·ָ -* : CommUintAddr ͨѶԪַ - Para,ͨѶ -* ֵ: +* 函数名称: RS485SensorCmdSend +* 功能描述: 下发传感器指令函数 +* 参 数: CommUintAddr, 通讯单元地址 + Para,通讯参数入口 +* 返 回 值: 无 *****************************************************************************************/ void RS485CmdSend(GateWayPara GateWay, uint8_t CommUintAddr, SensorCommPara SensorComm) { @@ -243,12 +243,12 @@ void RS485CmdSend(GateWayPara GateWay, uint8_t CommUintAddr, SensorCommPara Sens /***************************************************************************************** -* : RS485LoopHandler -* : RS485ѭ -* : GateWay, ز - RS485Ch, RS485ͨ - SCPara RS485ͨѶ -* ֵ: +* 函数名称: RS485LoopHandler +* 功能描述: RS485循环处理函数 +* 参 数: GateWay, 网关参数句柄 + RS485Ch, RS485通道句柄 + SCPara, RS485通讯句柄 +* 返 回 值: 无 *****************************************************************************************/ static uint8_t CommUintData[512]; int test = 0; @@ -266,8 +266,8 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP return; } - if(RS485Ch->CommUnitEnable == true) { //ʹͨѶԪ - if(RS485Ch->QuerySensorFlag == true) { //Ҵ + if(RS485Ch->CommUnitEnable == true) { //使用内置通讯单元 + if(RS485Ch->QuerySensorFlag == true) { //开机查找传感器 if(SCPara->SensorCnt < SENSOR_NUM_MAX) { rt_thread_delay(50); SCPara->Cmd = RS485_SENSOR_CMD_QUERY; @@ -328,7 +328,7 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP } } } - else { //ȡͨѶԪ + else { //读取外置通讯单元 if(SCPara->RS485CommUnitReadTimeDelay >= (GateWay->ConfigPara.CommUnitReadInterval * 5) && SCPara->SendFlag == false) { if(SCPara->SendUnitCommIdx < COMMUNIT_NUM_MAX) { if(GateWay->ConfigPara.CommUnitArray[SCPara->SendUnitCommIdx].RegFlag && @@ -365,10 +365,10 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP RxLenTemp = SCPara->RS485RxLen; // memset(SCPara->RS485RxBuff, 0x00, RS485_RX_BUFF_LEN_MAX); SCPara->RS485RxLen = 0; - if(RxBuffTemp[0] == 0x7A && RS485Ch->UpgradeEnable == true) { // + if(RxBuffTemp[0] == 0x7A && RS485Ch->UpgradeEnable == true) { //升级 update_process(RxBuffTemp,RxLenTemp); } - else if(RxBuffTemp[0] == 0x7A && RS485Ch->CommUnitEnable == true) { //ͨѶԪݽ + else if(RxBuffTemp[0] == 0x7A && RS485Ch->CommUnitEnable == true) { //内置通讯单元数据解析 if(SCPara->SendFlag == false) { SCPara->RS485RxLen = 0; return; @@ -376,12 +376,12 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP RS485Analyze(GateWay, SCPara, &RS485Ch->CUData, RxBuffTemp, RxLenTemp); //rt_mutex_release(GateWay->UartRevMutex); } - else if(RxBuffTemp[0] == 0x7B && RS485Ch->CommUnitEnable == false){ //ȡⲿͨѶԪݽ + else if(RxBuffTemp[0] == 0x7B && RS485Ch->CommUnitEnable == false){ //读取外部通讯单元数据解析 if(SCPara == &SComm1Para) ret = GateWay->CommUnitRevCallBack(GateWay, RxBuffTemp, RxLenTemp, GateWay->ConfigPara.Rs485Ch1.RS485Send); else ret = GateWay->CommUnitRevCallBack(GateWay, RxBuffTemp, RxLenTemp, GateWay->ConfigPara.Rs485Ch2.RS485Send); - if(ret == 0xff) { //עϢ + if(ret == 0xff) { //注册信息 SCPara->RS485RxLen = 0; return; } @@ -393,7 +393,7 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP return; } } - else { // + else { //调试命令解析 DebugAnalyze(GateWay, RxBuffTemp, RxLenTemp); } SCPara->RS485RxLen = 0; @@ -426,7 +426,7 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP MegData[2] = COMM_UNIT_CMD_READ; memcpy(&MegData[3], GateWay->ConfigPara.CommUnitArray[SCPara->SendUnitCommIdx].Mac[0], 6); MegData[9] = GateWay->ConfigPara.CommUnitArray[SCPara->SendUnitCommIdx].CommStatus; - CatOneEthSendQueue(MegData, 10); //Ϣ + CatOneEthSendQueue(MegData, 10); //发送离线消息 } } SCPara->SendUnitCommIdx++; @@ -436,10 +436,10 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP } /***************************************************************************************** -* : RS485Ch1_Thread_Entry -* : RS485ͨ1 -* : -* ֵ: +* 函数名称: RS485Ch1_Thread_Entry +* 功能描述: RS485通道1任务函数 +* 参 数: 任务参数入口 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch1_Thread_Entry(void *parameter) { @@ -469,7 +469,7 @@ void RS485Ch1_Thread_Entry(void *parameter) if(SCPara->RS485Rev_Sem == RT_NULL) { Debug_Printf("RS485Ch1Rev Sem Create Failed!\r\n"); } - Debug_Printf("RS485Ch1Rev Thread is running\r\n"); + Debug_Printf("RS485Ch1Rev Thread is running!\r\n"); rt_thread_delay(3000); SCPara->InitOverFlag = true; @@ -483,10 +483,10 @@ void RS485Ch1_Thread_Entry(void *parameter) } /***************************************************************************************** -* : RS485Ch1RxIrqCallback -* : RS485ͨ1жϴص -* : rData յ -* ֵ: +* 函数名称: RS485Ch1RxIrqCallback +* 功能描述: RS485通道1中断处理回调函数 +* 参 数: rData 接收到的数据 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch1RxIrqCallback(uint8_t rData) { @@ -500,10 +500,10 @@ void RS485Ch1RxIrqCallback(uint8_t rData) } /***************************************************************************************** -* : RS485Ch2_Thread_Entry -* : RS485ͨ1 -* : -* ֵ: +* 函数名称: RS485Ch2_Thread_Entry +* 功能描述: RS485通道1任务函数 +* 参 数: 任务参数入口 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch2_Thread_Entry(void *parameter) { @@ -533,7 +533,7 @@ void RS485Ch2_Thread_Entry(void *parameter) if(SCPara->RS485Rev_Sem == RT_NULL) { Debug_Printf("RS485Ch2Rev Sem Create Failed!\r\n"); } - Debug_Printf("RS485Ch2Rev Thread is running\r\n"); + Debug_Printf("RS485Ch2Rev Thread is running!\r\n"); rt_thread_delay(3000); SCPara->InitOverFlag = true; while(1) { @@ -543,10 +543,10 @@ void RS485Ch2_Thread_Entry(void *parameter) } /***************************************************************************************** -* : RS485Ch2RxIrqCallback -* : RS485ͨ1жϴص -* : rData յ -* ֵ: +* 函数名称: RS485Ch2RxIrqCallback +* 功能描述: RS485通道1中断处理回调函数 +* 参 数: rData 接收到的数据 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch2RxIrqCallback(uint8_t rData) { diff --git a/Project/GateWay/source/User/Src/app_comm.c b/Project/GateWay/source/User/Src/app_comm.c index eb391f2..e9b38d0 100644 --- a/Project/GateWay/source/User/Src/app_comm.c +++ b/Project/GateWay/source/User/Src/app_comm.c @@ -1,5 +1,5 @@ /* -ͨ +数据通信任务 */ #include "bsp.h" @@ -31,7 +31,7 @@ static void rs485_rx_cb(uint8_t data) } /** -ֵ:ɹ:len,ʧ: 0 +返回值:成功:len,失败: 0 ***/ static int recive_frame(void) { @@ -76,7 +76,7 @@ static void update_on_start(uint8_t* frame, int len, uint8_t* pload, int size) update_send_cmd(0x01, 1, pReq->PackageNum); - //BOOT + //重启进入BOOT NVIC_SystemReset(); } @@ -144,7 +144,7 @@ static void comm_process(uint8_t* frame, int len) uint8_t frame_data[64] = {0}; uint16_t frame_data_len = 0; - /***ݽ***/ + /***数据解码***/ int err = -1; err= protocol_unpack_frame(frame, len, &slave_addr, &frame_cmd, frame_data, &frame_data_len); @@ -152,7 +152,7 @@ static void comm_process(uint8_t* frame, int len) if (err != PROTOCOL_SUCCESS) return ; - //TODO:ȡַ + //TODO:获取本机地址 uint8_t local_addr = 0; dev_cfg_get_devid(&local_addr); @@ -209,7 +209,7 @@ static void comm_process(uint8_t* frame, int len) memcpy( &tp_data,&tp_info.tp_datas,sizeof(tp_data)); - //ݾЭ,ûõͨЧ + //兼容旧协议,没有用到的通道,填充无效数据 for(int i=0; i <8-TP_SENSOR_NUM; i++){ tp_data.channels[i+TP_SENSOR_NUM].status =1; @@ -244,7 +244,7 @@ static void comm_process(uint8_t* frame, int len) app_collect_ad_get(&ad_data); - //ݾЭ,ûõͨЧ + //兼容旧协议,没有用到的通道,填充无效数据 for(int i=0; i <8-YB_SENSOR_NUM; i++){ ad_data.channels[i+5].status =1; diff --git a/Project/GateWay/source/User/Src/bsp.c b/Project/GateWay/source/User/Src/bsp.c index 1de06a4..a4e66a9 100644 --- a/Project/GateWay/source/User/Src/bsp.c +++ b/Project/GateWay/source/User/Src/bsp.c @@ -16,10 +16,10 @@ static uint16_t m_au16Adc1SaValue; static stc_sdcard_init_t stcCardInitCfg; static stc_sdcard_dma_init_t stcDmaInitCfg; /***************************************************************************************** -* : SdioInit -* : Sdioʼ -* : -* ֵ: +* 函数名称: SdioInit +* 功能描述: Sdio初始化函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ en_result_t SdioInit(void) { @@ -50,11 +50,11 @@ en_result_t SdioInit(void) } /***************************************************************************************** -* : SDCardErase -* : SDCard10 -* : u32BlkStartAddr ʼ - u32BlkEndAddr -* ֵ: ɹtrueʧܷfalse +* 函数名称: SDCardErase +* 功能描述: SDCard扇区擦除函数,最大擦除扇区数10 +* 参 数: u32BlkStartAddr 起始扇区 + u32BlkEndAddr 结束扇区 +* 返 回 值: 操作成功返回true,失败返回false *****************************************************************************************/ bool SDCardErase(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr) { @@ -67,11 +67,11 @@ bool SDCardErase(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr) } /***************************************************************************************** -* : SDCardReadBlocks -* : SDCardȡȡ10 -* : u32BlkStartAddr ʼ - u32BlkEndAddr -* ֵ: ɹtrueʧܷfalse +* 函数名称: SDCardReadBlocks +* 功能描述: SDCard扇区读取函数,最大读取扇区数10 +* 参 数: u32BlkStartAddr 起始扇区 + u32BlkEndAddr 结束扇区 +* 返 回 值: 操作成功返回true,失败返回false *****************************************************************************************/ bool SDCardReadBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t *ReadBuff) { @@ -84,11 +84,11 @@ bool SDCardReadBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t } /***************************************************************************************** -* : SDCardWriteBlocks -* : SDCardд뺯д10 -* : u32BlkStartAddr ʼ - u32BlkEndAddr -* ֵ: ɹtrueʧܷfalse +* 函数名称: SDCardWriteBlocks +* 功能描述: SDCard扇区写入函数,最大写入扇区数10 +* 参 数: u32BlkStartAddr 起始扇区 + u32BlkEndAddr 结束扇区 +* 返 回 值: 操作成功返回true,失败返回false *****************************************************************************************/ bool SDCardWriteBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t *WriteBuff) { @@ -106,10 +106,10 @@ bool SDCardWriteBlocks(uint32_t u32BlkStartAddr, uint32_t u32BlkEndAddr, uint8_t ****************************************************************************************/ /***************************************************************************************** -* : SystemClockConfig -* : ϵͳʱ -* : -* ֵ: +* 函数名称: SystemClockConfig +* 功能描述: 系统时钟设置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void SystemClockConfig(void) { @@ -178,10 +178,10 @@ static void SystemClockConfig(void) } /***************************************************************************************** -* : Xtal32_ClockConfig -* : ϵͳʱ -* : -* ֵ: +* 函数名称: Xtal32_ClockConfig +* 功能描述: 系统低速时钟配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void Xtal32_ClockConfig(void) { @@ -209,10 +209,10 @@ static void Xtal32_ClockConfig(void) ****************************************************************************************/ /***************************************************************************************** -* : DbgUartRec -* : Դڽպ -* : -* ֵ: յַ +* 函数名称: DbgUartRec +* 功能描述: 调试串口接收函数 +* 参 数: 无 +* 返 回 值: 返回收到的字符 *****************************************************************************************/ static uint8_t DbgUartRec(void) { @@ -222,10 +222,10 @@ static uint8_t DbgUartRec(void) /***************************************************************************************** -* : DBGUsartErrIrqCallback -* : Դڴжϻص -* : -* ֵ: +* 函数名称: DBGUsartErrIrqCallback +* 功能描述: 调试串口错误中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void DBGUsartErrIrqCallback(void) { @@ -242,10 +242,10 @@ static void DBGUsartErrIrqCallback(void) } /***************************************************************************************** -* : DbgUsartRxIrqCallback -* : Դڽжϻص -* : -* ֵ: +* 函数名称: DbgUsartRxIrqCallback +* 功能描述: 调试串口接收中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void DbgUsartRxIrqCallback(void) { @@ -254,10 +254,10 @@ static void DbgUsartRxIrqCallback(void) } /***************************************************************************************** -* : DbgUart_Config -* : Դú -* : BaudRate ڲ -* ֵ: +* 函数名称: DbgUart_Config +* 功能描述: 调试串口配置函数 +* 参 数: BaudRate 串口波特率 +* 返 回 值: 无 *****************************************************************************************/ void DbgUart_Config(uint32_t BaudRate) { @@ -339,11 +339,11 @@ void DbgUart_Config(uint32_t BaudRate) } /***************************************************************************************** -* : DebugUartSend -* : Դڷͺ -* : sData ָ - sLen ݳ -* ֵ: +* 函数名称: DebugUartSend +* 功能描述: 调试串口发送函数 +* 参 数: sData 发送数据入口指针 + sLen 发送数据长度 +* 返 回 值: 无 *****************************************************************************************/ void DebugUartSend(uint8_t *sData, uint16_t sLen) { @@ -359,10 +359,10 @@ void DebugUartSend(uint8_t *sData, uint16_t sLen) ****************************************************************************************/ /***************************************************************************************** -* : RS485Ch1UartRec -* : RS485ͨ1ڽպ -* : -* ֵ: յַ +* 函数名称: RS485Ch1UartRec +* 功能描述: RS485通道1串口接收函数 +* 参 数: 无 +* 返 回 值: 返回收到的字符 *****************************************************************************************/ static uint8_t RS485Ch1UartRec(void) { @@ -371,10 +371,10 @@ static uint8_t RS485Ch1UartRec(void) } /***************************************************************************************** -* : RS485Ch1UsartErrIrqCallback -* : RS485ͨ1ڴжϻص -* : -* ֵ: +* 函数名称: RS485Ch1UsartErrIrqCallback +* 功能描述: RS485通道1串口错误中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void RS485Ch1UsartErrIrqCallback(void) { @@ -391,10 +391,10 @@ static void RS485Ch1UsartErrIrqCallback(void) } /***************************************************************************************** -* : RS485Ch1UsartRxIrqCallback -* : RS485ͨ1ڽжϻص -* : -* ֵ: +* 函数名称: RS485Ch1UsartRxIrqCallback +* 功能描述: RS485通道1串口接收中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void RS485Ch1UsartRxIrqCallback(void) { @@ -404,10 +404,10 @@ static void RS485Ch1UsartRxIrqCallback(void) /***************************************************************************************** -* : RS485Ch1_Config -* : RS485ͨ1ú -* : BaudRate ڲ -* ֵ: +* 函数名称: RS485Ch1_Config +* 功能描述: RS485通道1配置函数 +* 参 数: BaudRate 串口波特率 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch1_Config(uint32_t BaudRate) { @@ -489,11 +489,11 @@ void RS485Ch1_Config(uint32_t BaudRate) } /***************************************************************************************** -* : RS485Ch1UartSend -* : RS485ͨ1ڷͺ -* : sData ָ - sLen ݳ -* ֵ: +* 函数名称: RS485Ch1UartSend +* 功能描述: RS485通道1串口发送函数 +* 参 数: sData 发送数据入口指针 + sLen 发送数据长度 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch1UartSend(uint8_t *sData, uint16_t sLen) { @@ -510,10 +510,10 @@ void RS485Ch1UartSend(uint8_t *sData, uint16_t sLen) ****************************************************************************************/ /***************************************************************************************** -* : RS485Ch1UartRec -* : RS485ͨ1ڽպ -* : -* ֵ: յַ +* 函数名称: RS485Ch1UartRec +* 功能描述: RS485通道1串口接收函数 +* 参 数: 无 +* 返 回 值: 返回收到的字符 *****************************************************************************************/ static uint8_t RS485Ch2UartRec(void) { @@ -522,10 +522,10 @@ static uint8_t RS485Ch2UartRec(void) } /***************************************************************************************** -* : RS485Ch1UsartErrIrqCallback -* : RS485ͨ1ڴжϻص -* : -* ֵ: +* 函数名称: RS485Ch1UsartErrIrqCallback +* 功能描述: RS485通道1串口错误中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void RS485Ch2UsartErrIrqCallback(void) { @@ -542,10 +542,10 @@ static void RS485Ch2UsartErrIrqCallback(void) } /***************************************************************************************** -* : RS485Ch1UsartRxIrqCallback -* : RS485ͨ1ڽжϻص -* : -* ֵ: +* 函数名称: RS485Ch1UsartRxIrqCallback +* 功能描述: RS485通道1串口接收中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void RS485Ch2UsartRxIrqCallback(void) { @@ -554,10 +554,10 @@ static void RS485Ch2UsartRxIrqCallback(void) } /***************************************************************************************** -* : RS485Ch1_Config -* : RS485ͨ1ú -* : BaudRate ڲ -* ֵ: +* 函数名称: RS485Ch1_Config +* 功能描述: RS485通道1配置函数 +* 参 数: BaudRate 串口波特率 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch2_Config(uint32_t BaudRate) { @@ -639,11 +639,11 @@ void RS485Ch2_Config(uint32_t BaudRate) } /***************************************************************************************** -* : RS485Ch1UartSend -* : RS485ͨ1ڷͺ -* : sData ָ - sLen ݳ -* ֵ: +* 函数名称: RS485Ch1UartSend +* 功能描述: RS485通道1串口发送函数 +* 参 数: sData 发送数据入口指针 + sLen 发送数据长度 +* 返 回 值: 无 *****************************************************************************************/ void RS485Ch2UartSend(uint8_t *sData, uint16_t sLen) { @@ -662,10 +662,10 @@ void RS485Ch2UartSend(uint8_t *sData, uint16_t sLen) ****************************************************************************************/ /***************************************************************************************** -* : EthOrCat1UartRec -* : cat1ethڽպ -* : -* ֵ: յַ +* 函数名称: EthOrCat1UartRec +* 功能描述: cat1和eth串口接收函数 +* 参 数: 无 +* 返 回 值: 返回收到的字符 *****************************************************************************************/ static uint8_t EthOrCat1UartRec(void) { @@ -674,10 +674,10 @@ static uint8_t EthOrCat1UartRec(void) } /***************************************************************************************** -* : RS485Ch1UsartErrIrqCallback -* : cat1ethڴжϻص -* : -* ֵ: +* 函数名称: RS485Ch1UsartErrIrqCallback +* 功能描述: cat1和eth串口错误中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void EthOrCat1UsartErrIrqCallback(void) { @@ -694,10 +694,10 @@ static void EthOrCat1UsartErrIrqCallback(void) } /***************************************************************************************** -* : RS485Ch1UsartRxIrqCallback -* : cat1ethڽжϻص -* : -* ֵ: +* 函数名称: RS485Ch1UsartRxIrqCallback +* 功能描述: cat1和eth串口接收中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void EthOrCat1UsartRxIrqCallback(void) { @@ -707,10 +707,10 @@ static void EthOrCat1UsartRxIrqCallback(void) /***************************************************************************************** -* : RS485Ch1_Config -* : cat1ethú -* : BaudRate ڲ -* ֵ: +* 函数名称: RS485Ch1_Config +* 功能描述: cat1和eth串口配置函数 +* 参 数: BaudRate 串口波特率 +* 返 回 值: 无 *****************************************************************************************/ void EthOrCat1_Config(uint32_t BaudRate) { @@ -792,11 +792,11 @@ void EthOrCat1_Config(uint32_t BaudRate) } /***************************************************************************************** -* : EthOrCat1UartSend -* : cat1ethڷͺ -* : sData ָ - sLen ݳ -* ֵ: +* 函数名称: EthOrCat1UartSend +* 功能描述: cat1和eth串口发送函数 +* 参 数: sData 发送数据入口指针 + sLen 发送数据长度 +* 返 回 值: 无 *****************************************************************************************/ void EthOrCat1UartSend(uint8_t *sData, uint16_t sLen) { @@ -813,10 +813,10 @@ void EthOrCat1UartSend(uint8_t *sData, uint16_t sLen) ****************************************************************************************/ /***************************************************************************************** -* : LoraDio0IrqCallback -* : LORA DIO0жϻص -* : -* ֵ: +* 函数名称: LoraDio0IrqCallback +* 功能描述: LORA DIO0中断回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void LoraDio0IrqCallback(void) { @@ -825,10 +825,10 @@ static void LoraDio0IrqCallback(void) } /***************************************************************************************** -* : GPIO_Config -* : GPIOú -* : -* ֵ: +* 函数名称: GPIO_Config +* 功能描述: GPIO配置函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void GPIO_Config(void) { @@ -941,10 +941,10 @@ static void GPIO_Config(void) ****************************************************************************************/ /***************************************************************************************** -* : Spi1_Config -* : SPI1ú -* : -* ֵ: +* 函数名称: Spi1_Config +* 功能描述: SPI1配置函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void Spi1_Config(void) { @@ -1013,10 +1013,10 @@ static void Spi1_Config(void) } /***************************************************************************************** -* : Spi1SendReceive -* : SPI1ͽպ -* : sData ͵Ŷ -* ֵ: յ +* 函数名称: Spi1SendReceive +* 功能描述: SPI1发送接收函数 +* 参 数: sData 发送的数据入库哦 +* 返 回 值: 接收到的数据 *****************************************************************************************/ uint16_t Spi1SendReceive(uint16_t sData) { @@ -1052,10 +1052,10 @@ uint16_t Spi1SendReceive(uint16_t sData) ****************************************************************************************/ /***************************************************************************************** -* : Spi2_Config -* : SPI2ú -* : -* ֵ: +* 函数名称: Spi2_Config +* 功能描述: SPI2配置函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void Spi2_Config(void) { @@ -1126,10 +1126,10 @@ static void Spi2_Config(void) } /***************************************************************************************** -* : Spi2SendReceive -* : SPI2ͽպ -* : sData ͵Ŷ -* ֵ: յ +* 函数名称: Spi2SendReceive +* 功能描述: SPI2发送接收函数 +* 参 数: sData 发送的数据入库哦 +* 返 回 值: 接收到的数据 *****************************************************************************************/ uint16_t Spi2SendReceive(uint16_t sData) { @@ -1160,10 +1160,10 @@ uint16_t Spi2SendReceive(uint16_t sData) } /***************************************************************************************** -* : Rtc_Config -* : RTC -* : -* ֵ: +* 函数名称: Rtc_Config +* 功能描述: RTC配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void Rtc_Config(void) { @@ -1206,10 +1206,10 @@ static void Rtc_Config(void) /***************************************************************************************** -* : AdcInitConfig -* : ADCʼ -* : -* ֵ: +* 函数名称: AdcInitConfig +* 功能描述: ADC初始化配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void AdcInitConfig(void) { @@ -1229,10 +1229,10 @@ static void AdcInitConfig(void) } /***************************************************************************************** -* : AdcSetChannelPinMode -* : ADCͨ -* : -* ֵ: +* 函数名称: AdcSetChannelPinMode +* 功能描述: ADC通道引脚配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void AdcSetChannelPinMode(uint32_t u32Channel) { @@ -1268,10 +1268,10 @@ static void AdcSetChannelPinMode(uint32_t u32Channel) } /***************************************************************************************** -* : AdcChannelConfig -* : ADCͨ -* : -* ֵ: +* 函数名称: AdcChannelConfig +* 功能描述: ADC通道配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void AdcChannelConfig(void) { @@ -1290,17 +1290,17 @@ static void AdcChannelConfig(void) ADC_AddAdcChannel(M4_ADC1, &stcChCfg); /* 3. Configure the average channel if you need. */ - ADC_ConfigAvg(M4_ADC1, AdcAvcnt_256); //ƽͨãβƽֵ + ADC_ConfigAvg(M4_ADC1, AdcAvcnt_256); //平均通道配置,多次采样后输出平均值 /* 4. Add average channel if you need. */ ADC_AddAvgChannel(M4_ADC1, BAT_COLL_ADC_CH); } /***************************************************************************************** -* : Adc1_Config -* : ADC1 -* : -* ֵ: +* 函数名称: Adc1_Config +* 功能描述: ADC1配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void Adc1_Config(void) { @@ -1311,10 +1311,10 @@ static void Adc1_Config(void) /***************************************************************************************** -* : AdcDmaConfig -* : ADC DMA -* : -* ֵ: +* 函数名称: AdcDmaConfig +* 功能描述: ADC DMA配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void AdcDmaConfig(void) { @@ -1357,11 +1357,11 @@ static void AdcDmaConfig(void) } /***************************************************************************************** -* : DmaIrqRegister -* : DMAжϼĴ -* : pstcCfg жϲ - u32Priority жȼ -* ֵ: +* 函数名称: DmaIrqRegister +* 功能描述: DMA中断寄存器配置 +* 参 数: pstcCfg, 中断参数 + u32Priority, 中断优先级 +* 返 回 值: 无 *****************************************************************************************/ static void DmaIrqRegister(stc_irq_regi_conf_t *pstcCfg, uint32_t u32Priority) { @@ -1383,10 +1383,10 @@ static void DmaIrqRegister(stc_irq_regi_conf_t *pstcCfg, uint32_t u32Priority) } /***************************************************************************************** -* : DmaIrqRegister -* : DMAж -* : -* ֵ: +* 函数名称: DmaIrqRegister +* 功能描述: DMA中断配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void DmaIrqConfig(void) { @@ -1400,10 +1400,10 @@ static void DmaIrqConfig(void) } /***************************************************************************************** -* : DmaIrqRegister -* : DMA -* : -* ֵ: +* 函数名称: DmaIrqRegister +* 功能描述: DMA配置 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ static void Dma_Config(void) { @@ -1412,10 +1412,10 @@ static void Dma_Config(void) } /***************************************************************************************** -* : ReadAdcValue -* : ȡADֵ -* : -* ֵ: ADֵ +* 函数名称: ReadAdcValue +* 功能描述: 读取AD值 +* 参 数: 无 +* 返 回 值: AD值 *****************************************************************************************/ uint16_t GetADCBuffPoint(void) { @@ -1423,10 +1423,10 @@ uint16_t GetADCBuffPoint(void) } /***************************************************************************************** -* : ADC_Start -* : ADCת -* : -* ֵ: ADֵ +* 函数名称: ADC_Start +* 功能描述: 启动ADC转换 +* 参 数: 无 +* 返 回 值: AD值 *****************************************************************************************/ void ADC_Start(void) { @@ -1438,10 +1438,10 @@ void ADC_Start(void) //} /***************************************************************************************** -* : TimeGet -* : ȡϵͳʱ -* : tm ȡʱ -* ֵ: +* 函数名称: TimeGet +* 功能描述: 获取系统时间 +* 参 数: tm 读取时间入口 +* 返 回 值: 无 *****************************************************************************************/ void TimeGet(struct tm *cTime) { @@ -1458,10 +1458,10 @@ void TimeGet(struct tm *cTime) } /***************************************************************************************** -* : TimeTs -* : ϵͳʱתʱ -* : -* ֵ: ʱ +* 函数名称: TimeTs +* 功能描述: 系统时间转换时间戳 +* 参 数: 无 +* 返 回 值: 返回时间戳 *****************************************************************************************/ int TimeTs(void) { @@ -1474,10 +1474,10 @@ int TimeTs(void) } /***************************************************************************************** -* : TimeShow -* : ʱDBG -* : -* ֵ: +* 函数名称: TimeShow +* 功能描述: 将时间输出到DBG串口 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ void TimeShow(uint32_t dwStamp) { @@ -1492,10 +1492,10 @@ void TimeShow(uint32_t dwStamp) } /***************************************************************************************** -* : TimeSync -* : ͨʱͬ -* : ts ʱ -* ֵ: +* 函数名称: TimeSync +* 功能描述: 通过时间戳同步 +* 参 数: ts 时间入口 +* 返 回 值: 无 *****************************************************************************************/ void TimeSync(time_t ts) { @@ -1516,15 +1516,15 @@ void TimeSync(time_t ts) } /***************************************************************************************** -* : TimeSync2 -* : ͨͬ -* : Year - Month - Day - Hour ʱ - Min - Sec -* ֵ: +* 函数名称: TimeSync2 +* 功能描述: 通过年月日同步 +* 参 数: Year 年 + Month 月 + Day 日 + Hour 时 + Min 分 + Sec 秒 +* 返 回 值: 无 *****************************************************************************************/ void TimeSync2(uint8_t Year, uint8_t Month, uint8_t Day, uint8_t Hour, uint8_t Min, uint8_t Sec) { @@ -1599,10 +1599,10 @@ int dev_boot_write_param(boot_para_t Param) } /***************************************************************************************** -* : EnterStop -* : ͹״̬ -* : SleepStatus 豸͹״̬ -* ֵ: +* 函数名称: EnterStop +* 功能描述: 进入低功耗状态 +* 参 数: SleepStatus 设备低功耗状态 +* 返 回 值: 无 *****************************************************************************************/ //void EnterStop(void) //{ @@ -1641,10 +1641,10 @@ int dev_boot_write_param(boot_para_t Param) //} /***************************************************************************************** -* : Wakeup -* : 豸 -* : -* ֵ: +* 函数名称: Wakeup +* 功能描述: 设备唤醒 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ //void Wakeup(void) //{ @@ -1668,10 +1668,10 @@ void Error_Handler(void) ****************************************************************************************/ /***************************************************************************************** -* : FeedDog -* : Źι -* : -* ֵ: +* 函数名称: FeedDog +* 功能描述: 看门狗喂狗函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ void FeedDog(void) { @@ -1735,20 +1735,20 @@ void BSP_Init(void) ****************************************************************************************/ /***************************************************************************************** -* : LoraTxRxIrqCallback -* : LORAշжⲿضص -* : -* ֵ: +* 函数名称: LoraTxRxIrqCallback +* 功能描述: LORA收发中断外部重定向回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ __weak void LoraTxRxIrqCallback(void) { } /***************************************************************************************** -* : DbgRxIrqCallback -* : Դڽжⲿضص -* : -* ֵ: +* 函数名称: DbgRxIrqCallback +* 功能描述: 调试串口接收中断外部重定向回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ __weak void DbgRxIrqCallback(uint8_t rData) { @@ -1756,10 +1756,10 @@ __weak void DbgRxIrqCallback(uint8_t rData) } /***************************************************************************************** -* : RS485Ch1RxIrqCallback -* : RS485ͨ1ڽжⲿضص -* : -* ֵ: +* 函数名称: RS485Ch1RxIrqCallback +* 功能描述: RS485通道1串口接收中断外部重定向回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ __weak void RS485Ch1RxIrqCallback(uint8_t rData) { @@ -1767,10 +1767,10 @@ __weak void RS485Ch1RxIrqCallback(uint8_t rData) } /***************************************************************************************** -* : RS485Ch2RxIrqCallback -* : RS485ͨ1ڽжⲿضص -* : -* ֵ: +* 函数名称: RS485Ch2RxIrqCallback +* 功能描述: RS485通道1串口接收中断外部重定向回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ __weak void RS485Ch2RxIrqCallback(uint8_t rData) { @@ -1778,10 +1778,10 @@ __weak void RS485Ch2RxIrqCallback(uint8_t rData) } /***************************************************************************************** -* : EthOrCat1RxIrqCallback -* : EthCat1ڽжⲿضص -* : -* ֵ: +* 函数名称: EthOrCat1RxIrqCallback +* 功能描述: Eth和Cat1串口接收中断外部重定向回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ __weak void EthOrCat1RxIrqCallback(uint8_t rData) { @@ -1789,10 +1789,10 @@ __weak void EthOrCat1RxIrqCallback(uint8_t rData) } /***************************************************************************************** -* : RtcPeriod_IrqCallback -* : RTCжϻص -* : -* ֵ: +* 函数名称: RtcPeriod_IrqCallback +* 功能描述: RTC中断回调 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ //__weak void RtcPeriod_IrqCallback(void) //{ @@ -1800,10 +1800,10 @@ __weak void EthOrCat1RxIrqCallback(uint8_t rData) //} /***************************************************************************************** -* : Dma1Btc0_IrqHandler -* : DMAжⲿضص -* : -* ֵ: +* 函数名称: Dma1Btc0_IrqHandler +* 功能描述: DMA中断外部重定向回调函数 +* 参 数: 无 +* 返 回 值: 无 *****************************************************************************************/ __weak void Dma1Btc0_IrqHandler(void) { diff --git a/Project/GateWay/source/User/Src/main.c b/Project/GateWay/source/User/Src/main.c index 6f99366..cd7f46b 100644 --- a/Project/GateWay/source/User/Src/main.c +++ b/Project/GateWay/source/User/Src/main.c @@ -9,7 +9,7 @@ #include "spiflash.h" -//£ 81-00-00-06-00-01 +//雅下: 81-00-00-06-00-01 // 81-00-00-06-00-02 // 81-00-00-06-00-03 // 81-00-00-06-00-04 @@ -60,10 +60,10 @@ int toPercentage(int voltage) } /***************************************************************************************** -* : MainDBGOnOff -* : Ϣغ -* : OnOff, -* ֵ: +* 函数名称: MainDBGOnOff +* 功能描述: 主调试信息开关函数 +* 参 数: OnOff,开关 +* 返 回 值: 无 *****************************************************************************************/ void MainDBGOnOff(bool OnOff) { @@ -143,7 +143,7 @@ void GateWayInit(void) memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t)); GateWay.ConfigPara.SavFlag = LOG_SAV_FLAG; GateWay.ConfigPara.Comm = CATONE_COMM; -#if MAC_ADDR_TYPE == 0//Է +#if MAC_ADDR_TYPE == 0//测试服务器 GateWay.ConfigPara.LTENet.DestAddr[0] = 39; GateWay.ConfigPara.LTENet.DestAddr[1] = 106; GateWay.ConfigPara.LTENet.DestAddr[2] = 103; @@ -157,7 +157,7 @@ void GateWayInit(void) GateWay.ConfigPara.LTENet.DestPort = 12111; #endif - GateWay.ConfigPara.CommUnitReadInterval = COMMUNIT_READ_SENSOR_INTERVAL_MAX;//ǵ͹豸 + GateWay.ConfigPara.CommUnitReadInterval = COMMUNIT_READ_SENSOR_INTERVAL_MAX;//非低功耗设备 memset(GateWay.ConfigPara.CommUnitArray, 0x00, sizeof(CommUnitData_t) * COMMUNIT_NUM_MAX); GateWay.ConfigPara.Rs485Ch1.Enable = true; GateWay.ConfigPara.Rs485Ch1.CommUnitEnable = false; @@ -340,16 +340,16 @@ void OutageUpdate(uint8_t AlarmType, bool AlarmState, uint8_t Batt) Alarm->AlarmType = AlarmType; Alarm->AlarmState = AlarmState; Alarm->AlarmPara = Batt; - CatOneEthSendQueue(MegData, 6); //ͱϢ + CatOneEthSendQueue(MegData, 6); //发送报警信息 } /***************************************************************************************** -* : main -* : -* : -* ֵ: д󷵻-1 +* 函数名称: main +* 功能描述: 主函数 +* 参 数: 无 +* 返 回 值: 运行错误返回-1 *****************************************************************************************/ -static uint8_t LastBattery = 0xff; //һεصѹ +static uint8_t LastBattery = 0xff; //上一次电池电压 int main(void) { uint16_t OneSecondDlyCnt = 0; @@ -456,15 +456,15 @@ int main(void) uint16_t ADValue = GetADCBuffPoint(); //V = (AD * 3.3 / 4096) * (R1+R2) / R1; R1 = 200, R2 = 120 - //Ϊ0.00214843751000 + //计算出常数为0.0021484375,扩大1000倍 float Voltage = ADValue * 2.1484375; GateWay.Battery = toPercentage(Voltage); - //ϵжϵ + //上电判断电量 if(LastBattery == 0xff) { LastBattery = GateWay.Battery; - if(GateWay.ConfigPara.OutageFlag == true) { //б + if(GateWay.ConfigPara.OutageFlag == true) { //有报警 AlarmType = 1; } else { @@ -474,7 +474,7 @@ int main(void) BatteryUpdateDlyCnt = 10; } else { - if(GateWay.ConfigPara.OutageFlag == false) { //ûи澯жϵصѹǷ񽵵 + if(GateWay.ConfigPara.OutageFlag == false) { //没有告警,判断电池电压是否降低 if(GateWay.Battery <= LastBattery) { if(LastBattery <= 5) { GateWay.ConfigPara.OutageFlag = true; @@ -495,7 +495,7 @@ int main(void) BatteryUpdateDlyCnt = 20 * 60; } } - else { //磬һεصѹ + else { //充电,更新上一次电池电压 LastBattery = GateWay.Battery; } } @@ -522,14 +522,14 @@ int main(void) AlarmType = 0; } } - else { //ؼŵ磬һεصѹ + else { //电池继续放电,更新上一次电池电压 LastBattery = GateWay.Battery; } } } BatteryUpdateDlyCnt--; if(BatteryUpdateDlyCnt == 0) { - if(GateWay.ConfigPara.OutageFlag) { //б + if(GateWay.ConfigPara.OutageFlag) { //有报警 BatteryUpdateDlyCnt = 20 * 60; } else { diff --git a/Project/GateWay/source/User/Src/protocol.c b/Project/GateWay/source/User/Src/protocol.c index 2656b71..e9543ec 100644 --- a/Project/GateWay/source/User/Src/protocol.c +++ b/Project/GateWay/source/User/Src/protocol.c @@ -11,7 +11,7 @@ int protocol_pack_frame( uint16_t *packed_len) { - // ֡ͷ + // 构建基础帧头 buffer[0] = PROTOCOL_HEAD & 0xFF; buffer[1] = (PROTOCOL_HEAD >> 8) & 0xFF; @@ -23,21 +23,21 @@ int protocol_pack_frame( buffer[5] = payload_len & 0xFF; buffer[6] = (payload_len >> 8) & 0xFF; - // ЧغɣС˸ʽ + // 复制有效载荷(保持小端格式) if (payload_len > 0 && payload != NULL) { memcpy(buffer + PROTOCOL_FRAME_HEAD_SIZE , payload, payload_len); } - // ʵʳ + // 设置实际长度 int fram_len = PROTOCOL_FRAME_MIN_SIZE + payload_len; - // CRCǵַȺЧغɣ + // 计算CRC(覆盖地址、命令、长度和有效载荷) uint16_t crc = 0xFFFF; crc = modbus_crc16(buffer,fram_len -2); - // дCRCС˸ʽ + // 写入CRC(保持小端格式) buffer[fram_len-2] = (uint8_t)(crc & 0xFF); buffer[fram_len-1] = (uint8_t)(crc >> 8); @@ -56,7 +56,7 @@ int protocol_unpack_frame( uint8_t *payload, uint16_t *payload_len ) { - // У + // 参数校验 if (frame == NULL || slave_addr == NULL || command == NULL || payload_len == NULL) { return PROTOCOL_ERR_INVALID_PARAM; } @@ -68,7 +68,7 @@ int protocol_unpack_frame( return PROTOCOL_ERR_INVALID_PARAM; } - // ֡ͷУ + // 帧头校验 uint16_t header = (frame[0] | frame[1] <<8); if (header != PROTOCOL_HEAD) { @@ -76,7 +76,7 @@ int protocol_unpack_frame( return PROTOCOL_ERR_INVALID_PARAM; } - // ֶν + // 基础字段解析 *slave_addr = (frame[2] | frame[3] << 8); @@ -85,7 +85,7 @@ int protocol_unpack_frame( *payload_len = (frame[5] | frame[6] << 8); - // У + // 数据完整性校验 if (*payload_len > (frame_len - PROTOCOL_FRAME_MIN_SIZE)) { return PROTOCOL_ERR_BUFFER_OVERFLOW; @@ -97,7 +97,7 @@ int protocol_unpack_frame( calc_crc = modbus_crc16((uint8_t *)frame, frame_size -2 ); - // УCRCС˸ʽ + // 校验CRC(保持小端格式) union{ uint16_t value; @@ -115,7 +115,7 @@ int protocol_unpack_frame( return PROTOCOL_ERR_CRC; } - // ЧغɣС˸ʽ + // 复制有效载荷(保持小端格式) if (*payload_len > 0 && payload != NULL) { memcpy(payload, frame + PROTOCOL_FRAME_HEAD_SIZE, *payload_len); } diff --git a/Project/GateWay/source/User/Src/ringbuffer.c b/Project/GateWay/source/User/Src/ringbuffer.c index 225076b..c4fa578 100644 --- a/Project/GateWay/source/User/Src/ringbuffer.c +++ b/Project/GateWay/source/User/Src/ringbuffer.c @@ -1,5 +1,5 @@ /****************************************************************************** - * @brief λ(οlinux/kfifo) + * @brief 环形缓冲区管理(参考linux/kfifo) * * Copyright (c) 2016~2020, * @@ -7,7 +7,7 @@ * * Change Logs: * Date Author Notes - * 2016-05-30 Morro + * 2016-05-30 Morro 初版完成 ******************************************************************************/ #include "ringbuffer.h" #include @@ -16,10 +16,10 @@ #define min(a,b) ( (a) < (b) )? (a):(b) /* - *@brief һջλ - *@param[in] r - λ - *@param[in] buf - ݻ - *@param[in] len - buf(2N) + *@brief 构造一个空环形缓冲区 + *@param[in] r - 环形缓冲区管理器 + *@param[in] buf - 数据缓冲区 + *@param[in] len - buf长度(必须是2的N次幂) *@retval bool */ bool ring_buf_init(ring_buf_t *r,unsigned char *buf, unsigned int len) @@ -31,8 +31,8 @@ bool ring_buf_init(ring_buf_t *r,unsigned char *buf, unsigned int len) } /* - *@brief ջλ - *@param[in] r - յĻλ + *@brief 清空环形缓冲区 + *@param[in] r - 待清空的环形缓冲区 *@retval none */ void ring_buf_clr(ring_buf_t *r) @@ -41,8 +41,8 @@ void ring_buf_clr(ring_buf_t *r) } /* - *@brief ȡλݳ - *@retval λЧֽ + *@brief 获取环形缓冲区数据长度 + *@retval 环形缓冲区中有效字节数 */ int ring_buf_len(ring_buf_t *r) { @@ -50,10 +50,10 @@ int ring_buf_len(ring_buf_t *r) } /* - *@brief ָȵݷŵλ - *@param[in] buf - ݻ - * len - - *@retval ʵʷŵе + *@brief 将指定长度的数据放到环形缓冲区中 + *@param[in] buf - 数据缓冲区 + * len - 缓冲区长度 + *@retval 实际放到中的数据 */ int ring_buf_put(ring_buf_t *r,unsigned char *buf,unsigned int len) { @@ -70,10 +70,10 @@ int ring_buf_put(ring_buf_t *r,unsigned char *buf,unsigned int len) } /* - *@brief ӻλжȡָȵ - *@param[in] len - ȡ - *@param[out] buf - ݻ - *@retval ʵʶȡ + *@brief 从环形缓冲区中读取指定长度的数据 + *@param[in] len - 读取长度 + *@param[out] buf - 输出数据缓冲区 + *@retval 实际读取长度 */ int ring_buf_get(ring_buf_t *r,unsigned char *buf,unsigned int len) { diff --git a/Project/GateWay/source/User/Src/spiflash.c b/Project/GateWay/source/User/Src/spiflash.c index 15226d8..9ea928f 100644 --- a/Project/GateWay/source/User/Src/spiflash.c +++ b/Project/GateWay/source/User/Src/spiflash.c @@ -39,7 +39,7 @@ static void SpiFlashWaitForWriteEnd(void) SpiFlashSetNss(); } -// +//扇区擦除 void SpiFlashEraseSector(uint32_t SectorAddr) { #ifdef FLASH_TEST @@ -57,7 +57,7 @@ void SpiFlashEraseSector(uint32_t SectorAddr) #endif } -//Ƭ +//整片擦除 void SpiFlashEraseChip(void) { SpiFlashWriteEnable(); @@ -67,7 +67,7 @@ void SpiFlashEraseChip(void) SpiFlashWaitForWriteEnd(); } -//д +//写数据 void SpiFlashWriteData(uint8_t* wData, uint32_t wAddr, uint16_t wLen) { #ifdef FLASH_TEST @@ -89,15 +89,15 @@ void SpiFlashWriteData(uint8_t* wData, uint32_t wAddr, uint16_t wLen) void SpiFlashWriteAnyLengthData(uint8_t* wData, uint32_t wAddr, uint16_t wLen) { - uint16_t PageCnt; //Ҫдҳ - uint16_t FirstPageWriteSize; //ʼַΪҳʼַ£д뵱ǰҳʣռ - uint16_t LastPageWriteSize; //һҳд볤 + uint16_t PageCnt; //需要写入页数 + uint16_t FirstPageWriteSize; //在起始地址不为页起始地址的情况下,先写入当前页剩余空间 + uint16_t LastPageWriteSize; //最后一页写入长度 uint32_t AddrOffset = 0; uint32_t WriteAddr; LogHeader LogH; WriteAddr = wAddr; - //дijȳռ䣬ʼʼд + //写入的长度超出最大空间,从起始开始写起 if((WriteAddr + wLen) > SPIFLASH_SIZE) { LogH = (LogHeader)wData; WriteAddr = LOG_SAV_START_SECTOR * SPIFLASH_SECTORSIZE; @@ -106,21 +106,21 @@ void SpiFlashWriteAnyLengthData(uint8_t* wData, uint32_t wAddr, uint16_t wLen) uint16_t FirstPageRemainSpace = SPIFLASH_PAGESIZE - (WriteAddr % SPIFLASH_PAGESIZE); -// //жǷҪȲһ +// //判断是否跨扇区,跨扇区需要先擦除下一扇区 CheckDelSecter(wAddr, wLen); if(wLen < FirstPageRemainSpace) { - FirstPageWriteSize = wLen; //ҳд볤 + FirstPageWriteSize = wLen; //计算首页写入长度 PageCnt = 0; LastPageWriteSize = 0; } else { // FirstPageWriteSize = FirstPageRemainSpace % SPIFLASH_PAGESIZE; -// PageCnt = (wLen - (FirstPageWriteSize % SPIFLASH_PAGESIZE)) / SPIFLASH_PAGESIZE; //Ҫдҳ -// LastPageWriteSize = (wLen - (FirstPageWriteSize % SPIFLASH_PAGESIZE)) % SPIFLASH_PAGESIZE; //ʣҪдij +// PageCnt = (wLen - (FirstPageWriteSize % SPIFLASH_PAGESIZE)) / SPIFLASH_PAGESIZE; //计算需要写入多少整页 +// LastPageWriteSize = (wLen - (FirstPageWriteSize % SPIFLASH_PAGESIZE)) % SPIFLASH_PAGESIZE; //计算剩余需要写入的长度 FirstPageWriteSize = FirstPageRemainSpace; - PageCnt = (wLen - FirstPageWriteSize) / SPIFLASH_PAGESIZE; //Ҫдҳ - LastPageWriteSize = (wLen - FirstPageWriteSize) % SPIFLASH_PAGESIZE; //ʣҪдij + PageCnt = (wLen - FirstPageWriteSize) / SPIFLASH_PAGESIZE; //计算需要写入多少整页 + LastPageWriteSize = (wLen - FirstPageWriteSize) % SPIFLASH_PAGESIZE; //计算剩余需要写入的长度 } if(FirstPageWriteSize > 0) { @@ -170,17 +170,17 @@ uint32_t SpiFlashReadId(void) typedef struct { uint16_t Flag; - uint16_t LoopSavFlag; //ѭ洢־ - uint32_t LogCnt; //־ - uint32_t FirstLogStartAddr; //һݵʼַ - uint32_t LastLogEndAddr; //һݵĽַ + uint16_t LoopSavFlag; //循环存储标志 + uint32_t LogCnt; //日志最大数量 + uint32_t FirstLogStartAddr; //第一个数据的起始地址 + uint32_t LastLogEndAddr; //最后一个数据的结束地址 }LogNumSav_t; static LogNumSav_t LogNumArray[256]; static __IO uint32_t gLogCnt = 0; -static __IO uint32_t FirstLogStartAddr = 0; //һ־ʼַ -static __IO uint32_t LastLogEndAddr = 0; //һ־ַ -static __IO uint16_t LoopSavFlag = 0; //ѭ洢־ +static __IO uint32_t FirstLogStartAddr = 0; //第一个日志起始地址 +static __IO uint32_t LastLogEndAddr = 0; //最后一个日志结束地址 +static __IO uint16_t LoopSavFlag = 0; //循环存储标志 static uint16_t LogNumIdx; uint16_t ReadLoopSavFlag(void) @@ -235,7 +235,7 @@ void LogInit(void) break; } } - if(LogNumIdx == 0xffff) { //256¼һ¼ + if(LogNumIdx == 0xffff) { //256条记录满,读最后一条记录 LogNumIdx = 0; SetLogNum(LogNumArray[255].LogCnt); SetLoopSavFlag(LogNumArray[255].LoopSavFlag); @@ -243,7 +243,7 @@ void LogInit(void) SetLastLogEndAddr(LogNumArray[255].LastLogEndAddr); return; } - if(LogNumIdx == 0) { //ûм¼ + if(LogNumIdx == 0) { //没有记录 LogNumIdx = 0; SetLogNum(0); SetLoopSavFlag(0); @@ -286,17 +286,17 @@ void SavLogNum(uint32_t LogNum) } /***************************************************************************************** -* : CheckDelSecter -* : Ҫɾɾһɾһѭʼ -* : wAddr, дַ - wLen, д볤 -* ֵ: дʼַ +* 函数名称: CheckDelSecter +* 功能描述: 检查需要删除的扇区,跨扇区删除下一扇区,如果到了删除最后一个扇区,循环到起始扇区 +* 参 数: wAddr, 写入地址 + wLen, 写入长度 +* 返 回 值: 返回写入起始地址 *****************************************************************************************/ uint8_t LogBuff[LOG_SAV_SIZE_MAX]; const uint8_t SavFlag[4] ={0xAA, 0x55, 0x55, 0xAA}; void CheckDelSecter(uint32_t wAddr, uint16_t wLen) { - uint32_t DelOffsetAddr, FindFirstLogAddr; //洢ʼַ + uint32_t DelOffsetAddr, FindFirstLogAddr; //存储起始地址 uint32_t DelSectorNum = 0; uint32_t SurplusSpace = SPIFLASH_SECTORSIZE - (wAddr % SPIFLASH_SECTORSIZE); @@ -308,7 +308,7 @@ void CheckDelSecter(uint32_t wAddr, uint16_t wLen) FindFirstLogAddr = DelOffsetAddr + SPIFLASH_SECTORSIZE; } else { - if(wLen < SurplusSpace) { //ûгʣ + if(wLen < SurplusSpace) { //长度没有超过扇区剩余容量 SetLastLogEndAddr(wAddr + wLen); return; } @@ -340,7 +340,7 @@ void CheckDelSecter(uint32_t wAddr, uint16_t wLen) } if(i == LOG_SAV_SIZE_MAX) { ReadAddr += LOG_SAV_SIZE_MAX; - if(ReadAddr >= SPIFLASH_SIZE) { //Ҳһݣflash + if(ReadAddr >= SPIFLASH_SIZE) { //找不到下一条数据,重置flash Debug_Printf("Add LOG Error, Next Data No Find!\r\n"); SetLogNum(0); SetLoopSavFlag(0); @@ -381,7 +381,7 @@ void AddLog(uint8_t *wData, uint32_t wLen) LogH->TimeStamp = TimeTs(); memcpy(&LogBuffTemp[sizeof(LogHeader_t)], wData, wLen); - //жǷҪȲһ + //判断是否跨扇区,跨扇区需要先擦除下一扇区 CheckDelSecter(LLEndAddr, LogSize); if(LogH->LogEndAddr > SPIFLASH_SIZE) { LLEndAddr = LOG_SAV_START_SECTOR * SPIFLASH_SECTORSIZE; @@ -395,13 +395,13 @@ void AddLog(uint8_t *wData, uint32_t wLen) /***************************************************************************************** -* : ReadLog -* : ȡ־ -* : Header, һ־ͷϢȡʱһϢ־ʱ䣬 - Header->LogEndAddrΪ0ȡһ,LogIdxЧ - rData, ־ڣҪͷ - LogIdx, ȡ־ţΪ0ȡHeader->LogEndAddrӦ־ -* ֵ: ݳ +* 函数名称: ReadLog +* 功能描述: 读取日志 +* 参 数: Header, 上一包日志头信息,连续读取时传入上一包数据信息,缩短日志遍历时间, + Header->LogEndAddr为0读取第一包数据,LogIdx数据无效 + rData, 日志出口,需要释放 + LogIdx, 读取的日志的序号,为0读取Header->LogEndAddr对应日志 +* 返 回 值: 返回数据长度 *****************************************************************************************/ int ReadLog(LogHeader Header, uint8_t **rData, uint32_t LogIdx) { @@ -426,7 +426,7 @@ int ReadLog(LogHeader Header, uint8_t **rData, uint32_t LogIdx) while(1) { SpiFlashReadAnyLengthData((uint8_t *)Header, FSAddr, sizeof(LogHeader_t)); if(Header->LogSavFlag != LOG_SAV_FLAG) { - if((SPIFLASH_SIZE - FSAddr) < LOG_SAV_SIZE_MAX) { //жǷƬβ + if((SPIFLASH_SIZE - FSAddr) < LOG_SAV_SIZE_MAX) { //判断是否到片尾 FSAddr = LOG_SAV_START_SECTOR * SPIFLASH_SECTOR_NUM; continue; } @@ -461,15 +461,15 @@ int ReadLog(LogHeader Header, uint8_t **rData, uint32_t LogIdx) /***************************************************************************************** -* : ReadPara -* : ȡ -* : Para, ز - ParaLen, -* ֵ: +* 函数名称: ReadPara +* 功能描述: 读取参数 +* 参 数: Para, 网关参数 + ParaLen, 参数长度 +* 返 回 值: 无 *****************************************************************************************/ int ReadPara(uint8_t *Para, uint32_t ParaLen) { - SpiFlashReadAnyLengthData(Para, GATEWEY_PARA_SAV_ADDR, ParaLen); //ȡƬβ + SpiFlashReadAnyLengthData(Para, GATEWEY_PARA_SAV_ADDR, ParaLen); //读取片尾数据 uint16_t Check = CRC_Modbus(0xA001, Para, ParaLen - 2); GWConfigPara CfgPara = (GWConfigPara)Para; if(CfgPara->crc16 != Check) @@ -478,11 +478,11 @@ int ReadPara(uint8_t *Para, uint32_t ParaLen) } /***************************************************************************************** -* : WritePara -* : д -* : Para, ز - ParaLen, -* ֵ: +* 函数名称: WritePara +* 功能描述: 写入参数 +* 参 数: Para, 网关参数 + ParaLen, 参数长度 +* 返 回 值: 无 *****************************************************************************************/ int WritePara(uint8_t *Para, uint32_t ParaLen) { @@ -491,7 +491,7 @@ int WritePara(uint8_t *Para, uint32_t ParaLen) uint16_t Check = CRC_Modbus(0xA001, Para, ParaLen - 2); GWConfigPara CfgPara = (GWConfigPara)Para; CfgPara->crc16 = Check; - SpiFlashWriteAnyLengthData(Para, GATEWEY_PARA_SAV_ADDR, ParaLen); //ȡƬβ + SpiFlashWriteAnyLengthData(Para, GATEWEY_PARA_SAV_ADDR, ParaLen); //读取片尾数据 return 0; } diff --git a/Project/GateWay/source/User/Src/utils.c b/Project/GateWay/source/User/Src/utils.c index c04477f..4276991 100644 --- a/Project/GateWay/source/User/Src/utils.c +++ b/Project/GateWay/source/User/Src/utils.c @@ -1,16 +1,16 @@ #include "utils.h" /* -生成多项式 (x^16 + x^15 + x^2 + 1) +鐢熸垚澶氶」寮?(x^16 + x^15 + x^2 + 1锛? */ uint16_t modbus_crc16(uint8_t* data, int length) { - uint16_t crc = 0xFFFF; // 初始值FFFF - uint16_t polynomial = 0x8005; // 多项式8005 + uint16_t crc = 0xFFFF; // 鍒濆鍊糉FFF + uint16_t polynomial = 0x8005; // 澶氶」寮?005 for (int i = 0; i < length; i++) { - // 输入反转(REFIN):对每个字节进行位反转 + // 杈撳叆鍙嶈浆(REFIN)锛氬姣忎釜瀛楄妭杩涜浣嶅弽杞? uint8_t byte = data[i]; uint8_t reversed_byte = 0; @@ -19,10 +19,10 @@ uint16_t modbus_crc16(uint8_t* data, int length) byte >>= 1; } - crc ^= (reversed_byte << 8); // 与高字节异或 + crc ^= (reversed_byte << 8); // 涓庨珮瀛楄妭寮傛垨 for (int j = 0; j < 8; j++) { - if (crc & 0x8000) { // 检查最高位 + if (crc & 0x8000) { // 妫€鏌ユ渶楂樹綅 crc = (crc << 1) ^ polynomial; } else { crc <<= 1; @@ -30,7 +30,7 @@ uint16_t modbus_crc16(uint8_t* data, int length) } } - // 输出反转(REFOUT):对16位CRC结果进行位反转 + // 杈撳嚭鍙嶈浆(REFOUT)锛氬16浣岰RC缁撴灉杩涜浣嶅弽杞? uint16_t reversed_crc = 0; for (int i = 0; i < 16; i++) { @@ -38,6 +38,6 @@ uint16_t modbus_crc16(uint8_t* data, int length) crc >>= 1; } - // 结果异或值(XOROUT):0000(实际不变) + // 缁撴灉寮傛垨鍊?XOROUT)锛?000锛堝疄闄呬笉鍙橈級 return reversed_crc ^ 0x0000; }