1、增加ExclCommUint_t结构体,用于排除指定通讯单元的MAC

2、修复了复位后重复定义各项参数的bug。只有从flash读取到的出厂标志位错误时,才会进入配置默认参数判断,否则会以从flash读取到的数据为配置参数
3、增加CheckCommUnitExcl函数,用于查询mac是否被排除

GateWay_Debug:
1、rs485配置函数增加了boot升级使能功能
2、增加了excu、exdel、exls命令,用于配置排除设备的增、删、查
3、para命令增加显示LpCfg参数

sx127x:
1、lora通道选择取消,通过修改频率来修改通道
This commit is contained in:
2026-05-21 17:30:35 +08:00
parent 37d8152227
commit 7103c8ddfb
9 changed files with 95 additions and 143 deletions
+7
View File
@@ -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
+1 -1
View File
@@ -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);
}
+27 -7
View File
@@ -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) {
+26 -41
View File
@@ -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");