diff --git a/Project/GateWay/MDK/GateWay.uvoptx b/Project/GateWay/MDK/GateWay.uvoptx index 3727ed7..8d9ab6e 100644 --- a/Project/GateWay/MDK/GateWay.uvoptx +++ b/Project/GateWay/MDK/GateWay.uvoptx @@ -410,7 +410,7 @@ 0 JL2CM3 - -U12345678 -O78 -S4 -ZTIFSpeedSel2000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8027 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO8 -FD1FFF8000 -FC1000 -FN2 -FF0HC32F460_otp.FLM -FS03000C00 -FL03FC -FP0($$Device:HC32F460KETA$FlashARM\HC32F460_otp.FLM) -FF1HC32F460_512K.FLM -FS10 -FL180000 -FP1($$Device:HC32F460KETA$FlashARM\HC32F460_512K.FLM) + -U12345678 -O78 -S4 -ZTIFSpeedSel2000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8027 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO11 -FD1FFF8000 -FC1000 -FN2 -FF0HC32F460_otp.FLM -FS03000C00 -FL03FC -FP0($$Device:HC32F460KETA$FlashARM\HC32F460_otp.FLM) -FF1HC32F460_512K.FLM -FS10 -FL180000 -FP1($$Device:HC32F460KETA$FlashARM\HC32F460_512K.FLM) 0 @@ -428,93 +428,12 @@ - - - 0 - 0 - 1598 - 1 -
83604
- 0 - 0 - 0 - 0 - 0 - 1 - ..\source\Module\DebugCmd\DebugCmd.c - - \\GateWay\../source/Module/DebugCmd/DebugCmd.c\1598 -
- - 1 - 0 - 460 - 1 -
59254
- 0 - 0 - 0 - 0 - 0 - 1 - ..\source\User\Src\Public.c - - \\GateWay\../source/User/Src/Public.c\460 -
- - 2 - 0 - 466 - 1 -
59314
- 0 - 0 - 0 - 0 - 0 - 1 - ..\source\User\Src\Public.c - - \\GateWay\../source/User/Src/Public.c\466 -
- - 3 - 0 - 416 - 1 -
109936
- 0 - 0 - 0 - 0 - 0 - 1 - ..\source\Module\SX127x\sx127x.c - - \\GateWay\../source/Module/SX127x/sx127x.c\416 -
- - 4 - 0 - 415 - 1 -
109924
- 0 - 0 - 0 - 0 - 0 - 1 - ..\source\Module\SX127x\sx127x.c - - \\GateWay\../source/Module/SX127x/sx127x.c\415 -
-
+ 0 1 - GateWay,0x0A + GateWay,0x10 @@ -977,7 +896,7 @@ - DebugCmd + GateWay_Debug 1 0 0 @@ -989,7 +908,7 @@ 0 0 0 - ..\source\Module\DebugCmd\DebugCmd.c + ..\source\Module\GateWay_Debug\DebugCmd.c DebugCmd.c 0 0 diff --git a/Project/GateWay/MDK/GateWay.uvprojx b/Project/GateWay/MDK/GateWay.uvprojx index e18a2db..e88e94b 100644 --- a/Project/GateWay/MDK/GateWay.uvprojx +++ b/Project/GateWay/MDK/GateWay.uvprojx @@ -341,7 +341,7 @@ --diag_suppress=186,66 __DEBUG,HC32F460,USE_DEVICE_DRIVER_LIB,JEUA - ..\..\..\driver\inc;..\..\..\mcu\common;..\source\User\Inc;..\source\Module\Debug;..\source\Module\SDCard;..\source\Module\FatFS\source;..\source\Module\SX127x + ..\..\..\driver\inc;..\..\..\mcu\common;..\source\User\Inc;..\source\Module\GateWay_Debug;..\source\Module\SDCard;..\source\Module\FatFS\source;..\source\Module\SX127x @@ -586,12 +586,12 @@ - DebugCmd + GateWay_Debug DebugCmd.c 1 - ..\source\Module\DebugCmd\DebugCmd.c + ..\source\Module\GateWay_Debug\DebugCmd.c @@ -1267,7 +1267,7 @@ --diag_suppress=186,66 __DEBUG,HC32F460,USE_DEVICE_DRIVER_LIB,JEUA,BOOT_ENABLE - ..\..\..\driver\inc;..\..\..\mcu\common;..\source\User\Inc;..\source\Module\Debug;..\source\Module\SDCard;..\source\Module\FatFS\source;..\source\Module\sx127x;..\source\Module\DebugCmd + ..\..\..\driver\inc;..\..\..\mcu\common;..\source\User\Inc;..\source\Module\Debug;..\source\Module\SDCard;..\source\Module\FatFS\source;..\source\Module\sx127x;..\source\Module\GateWay_Debug @@ -1512,12 +1512,12 @@ - DebugCmd + GateWay_Debug DebugCmd.c 1 - ..\source\Module\DebugCmd\DebugCmd.c + ..\source\Module\GateWay_Debug\DebugCmd.c diff --git a/Project/GateWay/MDK/RTE/_app_app/RTE_Components.h b/Project/GateWay/MDK/RTE/_app_app/RTE_Components.h new file mode 100644 index 0000000..9a32dcf --- /dev/null +++ b/Project/GateWay/MDK/RTE/_app_app/RTE_Components.h @@ -0,0 +1,21 @@ + +/* + * Auto generated Run-Time-Environment Configuration File + * *** Do not modify ! *** + * + * Project: 'GateWay' + * Target: 'app_app' + */ + +#ifndef RTE_COMPONENTS_H +#define RTE_COMPONENTS_H + + +/* + * Define the Device Header File: + */ +#define CMSIS_device_header "HC32F460KETA.h" + + + +#endif /* RTE_COMPONENTS_H */ diff --git a/Project/GateWay/source/Module/GateWay_Debug b/Project/GateWay/source/Module/GateWay_Debug index 7b80a04..28b612d 160000 --- a/Project/GateWay/source/Module/GateWay_Debug +++ b/Project/GateWay/source/Module/GateWay_Debug @@ -1 +1 @@ -Subproject commit 7b80a04f4f8fbf08d4910b89022fe08550e289e5 +Subproject commit 28b612dd2894afbe832ac901c143f010ea413e14 diff --git a/Project/GateWay/source/Module/sx127x b/Project/GateWay/source/Module/sx127x index e7f30c7..149f38b 160000 --- a/Project/GateWay/source/Module/sx127x +++ b/Project/GateWay/source/Module/sx127x @@ -1 +1 @@ -Subproject commit e7f30c751f76f3624276acf76997cd0dcaf49586 +Subproject commit 149f38bf3f387772f547f709aeb57dbcbd152245 diff --git a/Project/GateWay/source/User/Inc/Public.h b/Project/GateWay/source/User/Inc/Public.h index c4025e5..4a85ffb 100644 --- a/Project/GateWay/source/User/Inc/Public.h +++ b/Project/GateWay/source/User/Inc/Public.h @@ -191,6 +191,11 @@ typedef struct { uint8_t ERTime; //紧急上报时长 }__attribute__((packed))CommUnitPara_t, *CommUnitPara; +typedef struct { + bool ExclFlag; + uint8_t ExclMac[6];//需要排除的通讯单元MAC +}__attribute__((packed))ExclCommUnit_t, *ExclCommUnit; + typedef struct { uint8_t Data[SENSOR_NUM_MAX][SENSOR_DATA_LEN_MAX]; }__attribute__((packed))CommUnitData_t, *CommUnitData; @@ -251,6 +256,7 @@ typedef struct { uint32_t SvrPort; //服务器端口 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; //调试通道 @@ -286,6 +292,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData void DebugAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen); void CommUnitCmdSend(GateWayPara GateWay, uint8_t *CommUnitMac, CommUnitCmd_m Cmd, uint8_t *Payload, uint16_t PayloadLen, SendData Send); int CheckCommUnitReg(GateWayPara GateWay, uint8_t *CommUnitMac); +int CheckCommUnitExcl(GateWayPara GateWay, uint8_t *CommUnitMac); int CommUintOrgData(GateWayPara GateWay, CommUnitPara CUPara, CommUnitData CUData, uint8_t *sData); void DebugDisplaySensorData(int SensorIdx, uint16_t SensorType, uint8_t *SensorData); #endif diff --git a/Project/GateWay/source/User/Src/LoraTask.c b/Project/GateWay/source/User/Src/LoraTask.c index 9a6ae81..134a091 100644 --- a/Project/GateWay/source/User/Src/LoraTask.c +++ b/Project/GateWay/source/User/Src/LoraTask.c @@ -66,7 +66,7 @@ void LoraIRQ_Thread_Entry(void *parameter) static void LoRaSendBuffer(uint8_t* pucBuff, uint16_t ucLen) { - if(GateWay->ConfigPara.Lora.OnOff) + if(GateWay->ConfigPara.Lora.OnOff == true) Sx1276LoRaSendBuffer(pucBuff, ucLen); } diff --git a/Project/GateWay/source/User/Src/Public.c b/Project/GateWay/source/User/Src/Public.c index 421b5c3..048ef70 100644 --- a/Project/GateWay/source/User/Src/Public.c +++ b/Project/GateWay/source/User/Src/Public.c @@ -184,7 +184,7 @@ int NetCommOrgData(GateWayPara GateWay, uint8_t *MegData, uint8_t *OutData) * 功能描述: 检查设备是否注册 * 参 数: GateWay,网关句柄 CommUnitMac, 待检查的设备MAC -* 返 回 值: 已注册返回true,没注册返回false +* 返 回 值: 已注册返回非0,没注册返回-1 *****************************************************************************************/ int CheckCommUnitReg(GateWayPara GateWay, uint8_t *CommUnitMac) { @@ -196,8 +196,23 @@ int CheckCommUnitReg(GateWayPara GateWay, uint8_t *CommUnitMac) } return -1; } - - +/***************************************************************************************** +* 函数名称: CheckCommUnitExcl +* 功能描述: 检查设备是否排除 +* 参 数: GateWay,网关句柄 + CommUnitMac, 待检查的设备MAC +* 返 回 值: 已排除返回非0,没排除返回-1 +*****************************************************************************************/ +int CheckCommUnitExcl(GateWayPara GateWay, uint8_t *CommUnitMac) +{ + 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; + } + } + return -1; +} /***************************************************************************************** * 函数名称: CommUnitSendCmd * 功能描述: 网关下发通讯单元指令函数 @@ -445,7 +460,7 @@ void DebugDisplaySensorData(int SensorIdx, uint16_t SensorType, uint8_t *SensorD int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData Response) { uint16_t check, crc16; - int CommUnitIdx; + int CommUnitIdx, ExclCommUnit; uint16_t PayLoadLen; uint8_t *PayLoad; uint8_t *MegData; @@ -468,12 +483,17 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData if((CUHeader->Cmd != COMM_UNIT_CMD_REG) && (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) + if(CUHeader->Cmd != COMM_UNIT_CMD_REG){//判断是否是注册请求 return -1; + } + ExclCommUnit = CheckCommUnitExcl(GateWay, CUHeader->DevMac);//判断是否是被排除的设备 + if(ExclCommUnit > -1) { + return -1; + } } - + switch(CUHeader->Cmd) { case COMM_UNIT_CMD_REG:{ if(PayLoad[0] > SENSOR_NUM_MAX) { diff --git a/Project/GateWay/source/User/Src/main.c b/Project/GateWay/source/User/Src/main.c index ffbc81b..964e254 100644 --- a/Project/GateWay/source/User/Src/main.c +++ b/Project/GateWay/source/User/Src/main.c @@ -134,12 +134,11 @@ void GateWayInit(void) memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t)); GateWay.ConfigPara.SavFlag = LOG_SAV_FLAG; GateWay.ConfigPara.Comm = CATONE_COMM; -// memcpy(GateWay.ConfigPara.GwMac, GateWayMac, 6); - GateWay.ConfigPara.SvrAddr[0] = 8; - GateWay.ConfigPara.SvrAddr[1] = 137; - GateWay.ConfigPara.SvrAddr[2] = 104; - GateWay.ConfigPara.SvrAddr[3] = 4; - GateWay.ConfigPara.SvrPort = 8007; + GateWay.ConfigPara.SvrAddr[0] = 103; + GateWay.ConfigPara.SvrAddr[1] = 217; + GateWay.ConfigPara.SvrAddr[2] = 192; + GateWay.ConfigPara.SvrAddr[3] = 248; + GateWay.ConfigPara.SvrPort = 12111; GateWay.ConfigPara.CommUnitReadInterval = COMMUNIT_READ_SENSOR_INTERVAL_MAX;//非低功耗设备 memset(GateWay.ConfigPara.CommUnitArray, 0x00, sizeof(CommUnitData_t) * COMMUNIT_NUM_MAX); GateWay.ConfigPara.Rs485Ch1.Enable = true; @@ -151,7 +150,9 @@ void GateWayInit(void) GateWay.ConfigPara.Rs485Ch2.BaudRate = 500000; GateWay.ConfigPara.Rs485Ch2.UpgradeEnable = false; GateWay.ConfigPara.Rs485Ch2.CommUnitEnable = false; - GateWay.ConfigPara.Rs485Ch2.Power = true; + GateWay.ConfigPara.Rs485Ch2.Power = false; + GateWay.ConfigPara.Rs485Ch1.RS485Send = RS485Ch1UartSend; + GateWay.ConfigPara.Rs485Ch2.RS485Send = RS485Ch2UartSend; GateWay.ConfigPara.Lora.OnOff = true; GateWay.ConfigPara.Lora.ucChannel = 8; @@ -161,38 +162,10 @@ void GateWayInit(void) GateWay.ConfigPara.Lora.ErrorCoding = 2; GateWay.ConfigPara.Lora.RegPreamble = 10; GateWay.ConfigPara.Lora.FreqCent = FREQ_CENT; + GateWay.ConfigPara.OutageFlag = false; GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1; - } - - if(GateWay.ConfigPara.OutageFlag != true && GateWay.ConfigPara.OutageFlag != false) - GateWay.ConfigPara.OutageFlag = false; - - GateWay.SvrRegFlag = false; - memset(GateWay.SvrMac, 0x00, 6); - GateWay.ConfigPara.Rs485Ch1.RS485Send = RS485Ch1UartSend; - GateWay.ConfigPara.Rs485Ch2.RS485Send = RS485Ch2UartSend; - - GateWay.ConfigPara.Rs485Ch1.Enable = true; - GateWay.ConfigPara.Rs485Ch1.CommUnitEnable = false; - GateWay.ConfigPara.Rs485Ch1.UpgradeEnable = true; - GateWay.ConfigPara.Rs485Ch1.BaudRate = 500000; - GateWay.ConfigPara.Rs485Ch1.Power = false; - GateWay.ConfigPara.Rs485Ch2.Enable = true; - GateWay.ConfigPara.Rs485Ch2.BaudRate = 500000; - GateWay.ConfigPara.Rs485Ch2.CommUnitEnable = false; - GateWay.ConfigPara.Rs485Ch2.UpgradeEnable = false; - GateWay.ConfigPara.Rs485Ch2.Power = false; - - GateWay.ConfigPara.Lora.OnOff = true; - GateWay.ConfigPara.Lora.ucChannel = 8; - GateWay.ConfigPara.Lora.ucPower = 20; - GateWay.ConfigPara.Lora.SignalBw = 8; - GateWay.ConfigPara.Lora.SpreadFactor = 9; - GateWay.ConfigPara.Lora.ErrorCoding = 2; - GateWay.ConfigPara.Lora.RegPreamble = 10; - GateWay.ConfigPara.Lora.FreqCent = FREQ_CENT; - + #if MAC_ADDR_TYPE == 0 memcpy(GateWay.ConfigPara.GwMac, GateWayMac_Test, 6); GateWay.ConfigPara.DebugChannel = DEBUG_CH_DBG; @@ -229,7 +202,7 @@ void GateWayInit(void) memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL10, 6); GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1; #endif - + #if MAC_ADDR_TYPE == 0//测试服务器 GateWay.ConfigPara.SvrAddr[0] = 39; GateWay.ConfigPara.SvrAddr[1] = 106; @@ -248,7 +221,14 @@ void GateWayInit(void) GateWay.ConfigPara.SvrAddr[3] = 248; GateWay.ConfigPara.SvrPort = 12111; #endif - + } + + if(GateWay.ConfigPara.OutageFlag != true && GateWay.ConfigPara.OutageFlag != false) + GateWay.ConfigPara.OutageFlag = false; + + GateWay.SvrRegFlag = false; + memset(GateWay.SvrMac, 0x00, 6); + if(GateWay.ConfigPara.DebugChannel == DEBUG_CH_RS485_1) { GateWay.ConfigPara.Rs485Ch1.Enable = true; GateWay.ConfigPara.Rs485Ch1.BaudRate = 500000; @@ -289,6 +269,11 @@ void GateWayInit(void) LoraSetChannel(GateWay.ConfigPara.Lora.ucChannel); //WritePara((uint8_t *)&GateWay.ConfigPara, sizeof(GWConfigPara_t)); } + if(LoraSetFreqCent(GateWay.ConfigPara.Lora.FreqCent) == false) + { + GateWay.ConfigPara.Lora.FreqCent = 433100000; + LoraSetFreqCent(GateWay.ConfigPara.Lora.ucChannel); + } if(LoraSetPower(GateWay.ConfigPara.Lora.ucPower) == false) { GateWay.ConfigPara.Lora.ucPower = 20; LoraSetPower(GateWay.ConfigPara.Lora.ucPower); @@ -311,9 +296,9 @@ void GateWayInit(void) } if(GateWay.ConfigPara.Lora.RegPreamble > 0xFE) { GateWay.ConfigPara.Lora.RegPreamble = 10; + LoraSetRegPreamble(GateWay.ConfigPara.Lora.RegPreamble); //WritePara((uint8_t *)&GateWay.ConfigPara, sizeof(GWConfigPara_t)); } - LoraSetRegPreamble(GateWay.ConfigPara.Lora.RegPreamble); WritePara((uint8_t *)&GateWay.ConfigPara, sizeof(GWConfigPara_t)); @@ -373,7 +358,7 @@ int main(void) uint8_t AlarmType = 0; GateWayInit(); - + rt_kprintf("\r\n\r\n"); rt_kprintf("****************************************************\r\n"); rt_kprintf("** **\r\n");