Compare commits

10 Commits

Author SHA1 Message Date
YuanHongbin a87bc24b01 chore: 更新 Gateway_Debug 子模块到最新提交 2026-06-17 17:47:38 +08:00
YuanHongbin 1f255cb3ef fix(eth): 修复EthNet模块参数配置和调试命令问题 2026-06-17 17:46:33 +08:00
YuanHongbin 2a7c8e4b3b chore: 更新 Gateway_Debug 子模块到最新提交 2026-06-17 12:33:11 +08:00
YuanHongbin dd8018e9bb feat(eth): 完善YOXO1007以太网模块配置和调试命令 2026-06-17 12:30:57 +08:00
YuanHongbin 626a486945 feat(debug): 新增 up 上传网关状态和 reg 重新注册命令 2026-06-15 18:56:53 +08:00
YuanHongbin 8052721c21 chore: 更新 Gateway_Debug 子模块的提交哈希
将子模块 Gateway_Debug 从 7e55f4c 更新到 765fe78
2026-06-15 15:18:46 +08:00
YuanHongbin 44e679182d fix: 修复以太网控制逻辑,调整硬件版本引脚映射
1. 移除main.h中的软硬件版本宏定义,移至bsp.h
2. 新增ETHStop和ETHReset对外接口并实现对应逻辑
3. 注释掉原有的ETH硬件复位延时流程
4. 根据硬件版本适配ETH和CAT1的引脚控制逻辑
5. 清理冗余的CAT1电源引脚宏定义
2026-06-15 15:11:23 +08:00
YuanHongbin 21cb23d0b9 refactor(rs485): 拆分通讯单元参数和数据结构体
调整RS485配置结构体,将原CUData拆分为CUPara和CUData,修正多处引用的字段名,同时修复CommUnitAnalyze中的数据拷贝偏移和包长度计算错误
2026-06-12 18:14:43 +08:00
YuanHongbin 030c22472d refactor(GateWay): 重构ETH通信状态机并调整测试配置
1.  将MAC_ADDR_TYPE从9改为0,使用测试MAC地址配置
2.  移除硬编码的服务器地址和端口默认值
3.  新增ETH状态机管理,完善链路检测、重连和收发逻辑
4.  添加一系列ETH通信超时、重试相关的宏定义
5.  新增调试观察窗口配置
2026-06-11 19:17:31 +08:00
YuanHongbin d05345afb7 1、位移监测传感器上传参数修改
2、CatOneTask兼容新版4G模块
3、完善传感器类型SensorType_m结构
2026-06-05 11:08:54 +08:00
10 changed files with 560 additions and 141 deletions
+52 -4
View File
@@ -410,7 +410,7 @@
<SetRegEntry>
<Number>0</Number>
<Key>JL2CM3</Key>
<Name>-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)</Name>
<Name>-U4294967295 -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 -FO14 -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)</Name>
</SetRegEntry>
<SetRegEntry>
<Number>0</Number>
@@ -428,12 +428,60 @@
<Name></Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint/>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>1004</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\source\User\Src\Public.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>1006</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>..\source\User\Src\Public.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
<Ww>
<count>0</count>
<WinNumber>1</WinNumber>
<ItemText>GateWay,0x10</ItemText>
<ItemText>GateWay,0x0A</ItemText>
</Ww>
<Ww>
<count>1</count>
<WinNumber>1</WinNumber>
<ItemText>EthStatus</ItemText>
</Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>EthRecvTimeoutCnt,0x0A</ItemText>
</Ww>
<Ww>
<count>3</count>
<WinNumber>1</WinNumber>
<ItemText>(60 * 1000),0x0A</ItemText>
</Ww>
</WatchWindow1>
<WatchWindow2>
@@ -465,7 +513,7 @@
<DebugFlag>
<trace>0</trace>
<periodic>1</periodic>
<aLwin>0</aLwin>
<aLwin>1</aLwin>
<aCover>0</aCover>
<aSer1>0</aSer1>
<aSer2>0</aSer2>
+34 -1
View File
@@ -14,6 +14,15 @@
#define CAT_ONE_DELAY_1MS(X)
// 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)
#define ETH_SEND_TIMEOUT_MAX (5 * 1000)
#define ETH_RECV_TIMEOUT_MAX (60 * 1000)
#define ETH_SEND_RETRY_MAX 3
#define ETH_FIRST_REG_DELAY (5 * 1000)
typedef enum {
CAT_ONE_AT_NULL,
CAT_ONE_AT, //开机检测
@@ -49,6 +58,17 @@ typedef enum {
CAT_ONE_CLOSE_TCP,
}CatOneStatus_m;
typedef enum {
ETH_IDEL,
ETH_RESET,
ETH_WAIT_LINK,
ETH_REG_SVR,
ETH_WAIT_SEND,
ETH_SEND_DATA,
ETH_WAIT_RECV,
ETH_OFF,
}EthStatus_m;
typedef enum {
CAT_ONE_RET_NULL,
CAT_ONE_RET_OK,
@@ -67,7 +87,7 @@ typedef enum {
}CatOneNetType_m;
typedef struct {
CatOneStatus_m Status;
CatOneStatus_m Cat1Status;
CatOneStatus_m NextStatus;
CatOneRetStatus_m ATCmdRet;
uint32_t CatOne1mSDelayCnt;
@@ -90,17 +110,30 @@ typedef struct {
GateWayPara GateWay;
DataRevCallBack CatOneRevCallBack;
// ETH状态机相关字段
EthStatus_m EthStatus;
uint32_t EthResetDelayCnt;
uint32_t EthLinkWaitCnt;
uint32_t EthRecvTimeoutCnt;
uint8_t EthSendRetryCnt;
bool EthFirstRegFlag;
}CatOne_t, *pCatOne_t;
CatOneRetStatus_m CatOneSend(uint8_t *sData, uint16_t sLen);
void CatOneStart(void);
void CatOneStop(void);
void CatOneReset(void);
void ETHStop(void);
void ETHReset(void);
void Cat1DBGOnOff(bool OnOff);
void CatOneGetLocationInfo(int *Longitude, int *Latitude);
void CatOneGetIMEIAndSIM(char *Imei, char *Sim);
bool CatOneGetStatus(void);
bool CatOneEthSendQueue(uint8_t *sData, uint16_t sLen);
void CatOneTriggerRegister(void);
void ETHTriggerRegister(void);
void ETHApplyNetPara(void);
void CatOne_Eth_Thread_Entry(void *parameter);
void EthRxOverhandler(void);
void CatReadImeiOrSim(char *Imei, char *Sim);
+35 -4
View File
@@ -28,7 +28,6 @@ typedef enum {
DEBUG_CH_RS485_2,
}DebugChannel_m;
typedef enum {
DEV_TYPE_BROADCAST,
DEV_TYPE_INC_COMMUNIT = 0x8001,
@@ -128,9 +127,11 @@ typedef struct {
}__attribute__((packed))LaserTracingType_T;
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)
}__attribute__ ((packed))Displacement_T,*DisplacementDp;
@@ -212,7 +213,8 @@ typedef struct {
uint8_t Power;
uint32_t BaudRate;
SendData RS485Send;
CommUnit_t CUData;
CommUnit_t CUPara;
CommUnitData_t CUData;
}__attribute__((packed))RS485Para_t, *RS485Para;
typedef struct {
@@ -248,12 +250,41 @@ typedef struct {
uint32_t FreqCent;
}LoraPara_t, *pLoraPara;
typedef struct {
uint8_t DestAddr[4]; //目的服务器地址
uint16_t DestPort; //目的服务器端口
uint8_t LocalAddr[4]; //本地客户端地址(预留)
uint16_t LocalPort; //本地客户端端口(预留)
}LTENetPara_t, *pLTENetPara;
typedef enum {
ETH_IP_DHCP, //动态IP
ETH_IP_STATIC, //静态IP
}EthIpMode_m;
typedef enum {
ETH_MODE_TCP_CLIENT, //TCP客户端
ETH_MODE_TCP_SERVER, //TCP服务器
ETH_MODE_UDP, //UDP模式
}EthWorkMode_m;
typedef struct {
EthIpMode_m IpMode; //IP模式:DHCP/静态
uint8_t IpAddr[4]; //本地IP地址
uint16_t IpPort; //本地端口
EthWorkMode_m 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
char SvrAddr[4]; //服务器地址
uint32_t SvrPort; //服务器端口
LTENetPara_t LTENet; //Cat1/4G服务器参数
EthNetPara_t EthNet; //以太网网络参数
uint32_t CommUnitReadInterval; //通讯单元读取时间间隔,单位S
CommUnitPara_t CommUnitArray[COMMUNIT_NUM_MAX]; //注册的通讯单元信息
ExclCommUnit_t ExclCommUnit[COMMUNIT_NUM_MAX]; //排除的通讯单元信息
+9 -5
View File
@@ -10,6 +10,9 @@
#include "rtthread.h"
#include "ff.h"
#define SOFTWARE_VERSION 10
#define HARDWARE_VERSION 12
//#define USE_BOOTLOADER
//#define FLASH_SECTOR_SIZE 0x2000ul
@@ -164,8 +167,14 @@
#define ETH_OR_CAT1_CTRL_PORT (PortB)
#define ETH_OR_CAT1_CTRL_PIN (Pin08)
#if (HARDWARE_VERSION == 12)
#define ETH_ON() PORT_SetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN)
#define CAT1_ON() PORT_ResetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN)
#elif (HARDWARE_VERSION >= 13)
#define ETH_ON() PORT_ResetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN)
#define CAT1_ON() PORT_SetBits(ETH_OR_CAT1_CTRL_PORT, ETH_OR_CAT1_CTRL_PIN)
#endif
//#define ETH_OR_CAT1_TX_CTRL_PORT (PortH)
//#define ETH_OR_CAT1_TX_CTRL_PIN (Pin02)
@@ -182,11 +191,6 @@
#define CAT1_RESET_CLR() PORT_SetBits(CAT1_RESET_PORT, CAT1_RESET_PIN)
#define CAT1_RESET_SET() PORT_ResetBits(CAT1_RESET_PORT, CAT1_RESET_PIN)
//#define CAT1_POW_PORT (PortA)
//#define CAT1_POW_PIN (Pin00)
//#define CAT1_POW_ON() PORT_SetBits(CAT1_POW_PORT, CAT1_POW_PIN)
//#define CAT1_POW_OFF() PORT_ResetBits(CAT1_POW_PORT, CAT1_POW_PIN)
#define ETH_RESET_PORT (PortB)
#define ETH_RESET_PIN (Pin05)
#define ETH_RESET_SET() PORT_SetBits(ETH_RESET_PORT, ETH_RESET_PIN)
+1 -4
View File
@@ -4,10 +4,7 @@
#include "Public.h"
#include "DebugCmd.h"
#define SOFTWARE_VERSION 12
#define HARDWARE_VERSION 12
#define MAC_ADDR_TYPE 4//0为测试服务器
#define MAC_ADDR_TYPE 0//0为测试服务器
extern bool MainDispEn;
#define MAIN_DBG_LOG(...) { if(MainDispEn) Debug_Printf(__VA_ARGS__);}
+330 -55
View File
@@ -23,11 +23,33 @@ static uint8_t EthRevTimeOutCnt;
static uint16_t CatSendErrCnt = 0;
// 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)}}
#define CATONE_RESET_DELAY_TIME_MAX (5 * 60 * 1000)
//const char *CatOneATCmdStr[16] = {
// "NULL",
// "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+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+LBSPARA=http://locator-aep.xiot.senthink.com:80/locator/v0.1/locate,B84E427D95B1DF4A3F49B18DDF714C72\r\n",
// "AT+CCLK?\r\n", //获取时间
//};
const char *CatOneATCmdStr[16] = {
"NULL",
"AT\r\n", //开机检测
@@ -35,16 +57,17 @@ const char *CatOneATCmdStr[16] = {
"AT+CPIN?\r\n", //识卡
// "AT+CIMI\r\n", //IMEI
"AT+CGSN=1\r\n",
"AT+LCCID\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+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+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", //获取时间
};
@@ -77,10 +100,10 @@ const CatOneATCMD_m CatOneModeSetCmdArray[] = {
//{
// rt_err_t result;
//
// if(CatOne.Status != CAT_ONE_IDEL && CatOne.Status != CAT_ONE_WAIT_SEND)
// if(CatOne.Cat1Status != CAT_ONE_IDEL && CatOne.Cat1Status != CAT_ONE_WAIT_SEND)
// return CAT_ONE_RET_ERR;
//
// //CatOne.Status = CAT_ONE_RESET;
// //CatOne.Cat1Status = CAT_ONE_RESET;
// result = rt_mq_send(CatOneRev_MQ, sData, sLen);
// if(result != RT_EOK) {
// CAT1_DBG_LOG("CatOne MQ Send ERR...\r\n");
@@ -92,7 +115,17 @@ const CatOneATCMD_m CatOneModeSetCmdArray[] = {
void CatOneStop(void)
{
CatOne.Status = CAT_ONE_OFF;
CatOne.Cat1Status = CAT_ONE_OFF;
}
void ETHStop(void)
{
CatOne.EthStatus = ETH_OFF;
}
void ETHReset(void)
{
CatOne.EthStatus = ETH_RESET;
}
void CatOneGetLocationInfo(int *Longitude, int *Latitude)
@@ -116,14 +149,14 @@ void CatOneGetIMEIAndSIM(char *Imei, char *Sim)
//返回true-busy, false-Idle
bool CatOneGetStatus(void)
{
if(CatOne.Status == CAT_ONE_IDEL)
if(CatOne.Cat1Status == CAT_ONE_IDEL)
return false;
return true;
}
void CatOneReset(void)
{
CatOne.Status = CAT_ONE_RESET;
CatOne.Cat1Status = CAT_ONE_RESET;
}
void CatTimeSync(char *Data)
@@ -213,22 +246,22 @@ void CatOneAtCmdAnalyze(char *RxBuff)
if(strstr(RxBuff, "OK") == NULL) {
CatOne.ATCmdRet = CAT_ONE_RET_ERR;
}
p = strstr(RxBuff, "+LCCID");
p = strstr(RxBuff, "+QCCID");
if(p == NULL) {
CatOne.ATCmdRet = CAT_ONE_RET_ERR;
}
memset(CatOne.SIM, 0, 32);
ret = sscanf(p, "+LCCID: %s\r\n", CatOne.SIM);
ret = sscanf(p, "+QCCID: %s\r\n", CatOne.SIM);
if(ret != 1) {
memset(CatOne.SIM, 0, 32);
}
break;
case CAT_ONE_LBS:
p = strstr(RxBuff, "+LBS");
p = strstr(RxBuff, "+QLBS");
if(p != NULL) {
double Longitude, Latitude;
int ret = sscanf(p, "+LBS: %lf,%lf\r\n", &Longitude, &Latitude);
int ret = sscanf(p, "+QLBS: %lf,%lf\r\n", &Longitude, &Latitude);
if(ret == 2) {
CatOne.LBSFlag = true;
CatOne.Longitude = Longitude * 100000;
@@ -239,7 +272,7 @@ void CatOneAtCmdAnalyze(char *RxBuff)
case CAT_ONE_LIPOPEN:
if(strstr(RxBuff, "OK") != NULL) {
CatOne.Status = CatOne.NextStatus;
CatOne.Cat1Status = CatOne.NextStatus;
CatOne.CatOne1mSDelayCnt = 10 * 1000;
return;
}
@@ -247,13 +280,13 @@ void CatOneAtCmdAnalyze(char *RxBuff)
if(strstr(RxBuff, "LIPOPEN: 0,1") != NULL) {
CAT1_DBG_LOG("Cat1 successfully to connect to the server.\r\n\r\n");
CatOne.TcpConnFlag = true;
CatOne.Status = CatOne.NextStatus;
CatOne.Cat1Status = CatOne.NextStatus;
rt_sem_release(CatOneRev_Sem);
}
else if(strstr(RxBuff, "LIPOPEN: 0,0") != NULL) {
CAT1_DBG_LOG("Cat1 failed to connect to the server.\r\n\r\n");
CatOne.TcpConnFlag = false;
CatOne.Status = CAT_ONE_OFF;
CatOne.Cat1Status = CAT_ONE_OFF;
}
return;
}
@@ -305,7 +338,7 @@ void CatOneAtCmdAnalyze(char *RxBuff)
if(strstr(p, "+LIPURC: 0,0") != NULL) {
CAT1_DBG_LOG("TCP connection disconnected.\r\n\r\n");
CatOne.TcpConnFlag = false;
CatOne.Status = CAT_ONE_OFF;
CatOne.Cat1Status = CAT_ONE_OFF;
return;
}
@@ -321,7 +354,7 @@ void CatOneAtCmdAnalyze(char *RxBuff)
else {
return;
}
//CatOne.Status = CAT_ONE_CLOSE_TCP;
//CatOne.Cat1Status = CAT_ONE_CLOSE_TCP;
rt_sem_release(CatOneRev_Sem);//接收任务
return;
}
@@ -330,7 +363,7 @@ void CatOneAtCmdAnalyze(char *RxBuff)
}
if(CatOne.ATCmdRet == CAT_ONE_RET_OK) {
CatOne.Status = CatOne.NextStatus;
CatOne.Cat1Status = CatOne.NextStatus;
if(CatOne.AtCmd == CAT_ONE_LIPSEND)
CatOne.CatOne1mSDelayCnt = 5 * 1000;
else
@@ -350,11 +383,11 @@ void CatOneAtCmdSend(CatOneATCMD_m Cmd, uint32_t Dly, CatOneStatus_m NextStatus)
}
else if(CatOne.AtCmd == CAT_ONE_LIPOPEN) {
sprintf(CatOne.CatOneSendBuff,"AT+LIPOPEN=\"TCP\",\"%d.%d.%d.%d\",%d\r\n",
CatOne.GateWay->ConfigPara.SvrAddr[0],
CatOne.GateWay->ConfigPara.SvrAddr[1],
CatOne.GateWay->ConfigPara.SvrAddr[2],
CatOne.GateWay->ConfigPara.SvrAddr[3],
CatOne.GateWay->ConfigPara.SvrPort);
CatOne.GateWay->ConfigPara.LTENet.DestAddr[0],
CatOne.GateWay->ConfigPara.LTENet.DestAddr[1],
CatOne.GateWay->ConfigPara.LTENet.DestAddr[2],
CatOne.GateWay->ConfigPara.LTENet.DestAddr[3],
CatOne.GateWay->ConfigPara.LTENet.DestPort);
}
else {
strcpy(CatOne.CatOneSendBuff, CatOneATCmdStr[CatOne.AtCmd]);
@@ -363,7 +396,7 @@ void CatOneAtCmdSend(CatOneATCMD_m Cmd, uint32_t Dly, CatOneStatus_m NextStatus)
EthRevTimeOutCnt = 0;
EthOrCat1UartSend((uint8_t *)CatOne.CatOneSendBuff, strlen(CatOne.CatOneSendBuff));
CatOne.CatOne1mSDelayCnt = Dly;
CatOne.Status = CAT_ONE_WAIT_REV;
CatOne.Cat1Status = CAT_ONE_WAIT_REV;
CatOne.NextStatus = NextStatus;
}
@@ -375,12 +408,12 @@ int GateWayRegister(uint8_t *TxBuff)
if(CatOne.GateWay->ConfigPara.Rs485Ch1.CommUnitEnable == true && CatOne.GateWay->ConfigPara.Rs485Ch1.Enable == true) {
UnitCommCnt++;
memcpy(&p[len], CatOne.GateWay->ConfigPara.Rs485Ch1.CUData.Para.Mac[0], 6);
memcpy(&p[len], CatOne.GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0], 6);
len += 6;
}
if(CatOne.GateWay->ConfigPara.Rs485Ch2.CommUnitEnable == true && CatOne.GateWay->ConfigPara.Rs485Ch2.Enable == true) {
UnitCommCnt++;
memcpy(&p[len], CatOne.GateWay->ConfigPara.Rs485Ch2.CUData.Para.Mac[0], 6);
memcpy(&p[len], CatOne.GateWay->ConfigPara.Rs485Ch2.CUPara.Para.Mac[0], 6);
len += 6;
}
for(int i = 0; i < COMMUNIT_NUM_MAX; i++) {
@@ -407,14 +440,14 @@ void CatOneLoopHandler(void)
uint16_t ret;
static uint8_t Cat1RevErrCnt = 0;
switch(CatOne.Status){
switch(CatOne.Cat1Status){
case CAT_ONE_IDEL:
rt_thread_delay(1);
if(CatOne.ResetDelayCnt > 0) {
CatOne.ResetDelayCnt--;
}
else {
CatOne.Status = CAT_ONE_RESET;
CatOne.Cat1Status = CAT_ONE_RESET;
}
break;
@@ -429,9 +462,9 @@ void CatOneLoopHandler(void)
else { //3次错误,关机
CAT1_DBG_LOG("Cat1 error, Close!\r\n");
if(CatOne.AtCmd == CAT_ONE_LIPSEND)
CatOne.Status = CAT_ONE_CLOSE_TCP;
CatOne.Cat1Status = CAT_ONE_CLOSE_TCP;
else
CatOne.Status = CAT_ONE_OFF;
CatOne.Cat1Status = CAT_ONE_OFF;
}
}
break;
@@ -446,7 +479,7 @@ void CatOneLoopHandler(void)
CatOneAtCmdSend(CatOneModeSetCmdArray[CatOne.AtCmdIdx], 1000, CAT_ONE_INIT);
}
else {
CatOne.Status = CAT_ONE_TCP_CONN;
CatOne.Cat1Status = CAT_ONE_TCP_CONN;
CatOne.CatOne1mSDelayCnt = 0;
CatOne.AtCmdIdx = 0;
CatOne.AtCmd = CAT_ONE_AT_NULL;
@@ -460,39 +493,39 @@ void CatOneLoopHandler(void)
case CAT_ONE_WAIT_CONN:
if(CatOne.TcpConnFlag) {
if(CatOne.GateWay->SvrRegFlag == false)
CatOne.Status = CAT_ONE_REG_SVR;
CatOne.Cat1Status = CAT_ONE_REG_SVR;
else
CatOne.Status = CAT_ONE_WAIT_SEND;
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
}
break;
case CAT_ONE_REG_SVR: //注册服务器
ret = GateWayRegister(CatOneEthTxBuff);
rt_mq_send(CatOne.GateWay->NetSendData_MQ, CatOneEthTxBuff, ret);
CatOne.Status = CAT_ONE_WAIT_SEND;
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
break;
case CAT_ONE_WAIT_SEND:
result = rt_mq_recv(CatOne.GateWay->NetSendData_MQ, Payload, CAT_ONE_REV_LEN_MAX, 1000);
if(result == RT_EOK) {
CatOneEthTxLen = NetCommOrgData(CatOne.GateWay, Payload, CatOneEthTxBuff);
CatOne.Status = CAT_ONE_SEND_DATA;
CatOne.Cat1Status = CAT_ONE_SEND_DATA;
}
else {
if(CatOne.Status == CAT_ONE_RESET || CatOne.Status == CAT_ONE_OFF) //外部命令执行,状态改变
if(CatOne.Cat1Status == CAT_ONE_RESET || CatOne.Cat1Status == CAT_ONE_OFF) //外部命令执行,状态改变
return;
if(!CatOne.TcpConnFlag) {
CatOne.Status = CAT_ONE_OFF;
CatOne.Cat1Status = CAT_ONE_OFF;
}
else {
CatSendErrCnt++;
if(CatSendErrCnt > CAT1_ERR_RESET_DLY_MAX) {
CatOne.Status = CAT_ONE_RESET;
CatOne.Cat1Status = CAT_ONE_RESET;
CAT1_DBG_LOG("Cat1 has no data for a long time, Reset!\r\n");
CatSendErrCnt = 0;
break;
}
CatOne.Status = CAT_ONE_WAIT_SEND;
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
}
}
break;
@@ -501,7 +534,7 @@ void CatOneLoopHandler(void)
CatOne.AtCmdResendCnt = 3;
Cat1RevErrCnt++;
if(Cat1RevErrCnt > 10) {
CatOne.Status = CAT_ONE_RESET;
CatOne.Cat1Status = CAT_ONE_RESET;
CAT1_DBG_LOG("Cat1 has no receive data for a long time, Reset!\r\n");
Cat1RevErrCnt = 0;
break;
@@ -521,9 +554,9 @@ void CatOneLoopHandler(void)
Cat1RevErrCnt = 0;
}
if(CatOne.GateWay->SvrRegFlag == false) //设备没注册,关闭4G,等待下一次重新注册
CatOne.Status = CAT_ONE_OFF;
CatOne.Cat1Status = CAT_ONE_OFF;
else
CatOne.Status = CAT_ONE_WAIT_SEND;
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
break;
case CAT_ONE_CLOSE_TCP:
@@ -539,7 +572,7 @@ void CatOneLoopHandler(void)
CAT1_PWR_KEY_SET();
CatSendErrCnt = 0;
CAT1_DBG_LOG("Cat1 Power Off!\r\n");
CatOne.Status = CAT_ONE_IDEL;
CatOne.Cat1Status = CAT_ONE_IDEL;
CatOne.ResetDelayCnt = CATONE_RESET_DELAY_TIME_MAX;
break;
@@ -554,7 +587,7 @@ void CatOneLoopHandler(void)
CAT1_PWR_KEY_CLR();
rt_thread_delay(1000);
CAT1_PWR_KEY_SET();
CatOne.Status = CAT_ONE_INIT;
CatOne.Cat1Status = CAT_ONE_INIT;
CatOne.AtCmdIdx = 0;
rt_thread_delay(1000);
CatOne.GateWay->BatteryReadDlyCnt = 60;
@@ -566,26 +599,149 @@ void EthLoopHandler(void)
{
rt_err_t result;
if(CatOne.GateWay->SvrRegFlag == false) {
if(CatOne.RegisterDelayCnt == 0) {
switch(CatOne.EthStatus) {
case ETH_IDEL:
rt_thread_delay(1);
if(CatOne.EthResetDelayCnt > 0) {
CatOne.EthResetDelayCnt--;
}
else {
CatOne.EthStatus = ETH_RESET;
}
break;
case ETH_RESET:
CAT1_DBG_LOG("ETH Reset!\r\n");
ETH_RESET_CLR();
rt_thread_delay(10);
ETH_RESET_SET();
rt_thread_delay(2000); // 延长复位后稳定时间到2秒
ETHApplyNetPara(); // 配置EthNet网络参数
CatOne.EthStatus = ETH_WAIT_LINK;
CatOne.EthLinkWaitCnt = 0;
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);
}
if(ETH_LINK_GET() == Reset) {
CatOne.RegisterDelayCnt = REGISTER_INTERVAL_MAX * 10;
uint8_t ret = GateWayRegister(CatOneEthTxBuff);
rt_mq_send(CatOne.GateWay->NetSendData_MQ, CatOneEthTxBuff, ret);
CAT1_DBG_LOG("ETH Link OK!\r\n");
if(CatOne.GateWay->SvrRegFlag == false) {
CatOne.EthStatus = ETH_REG_SVR;
}
else {
CatOne.EthStatus = ETH_WAIT_SEND;
}
}
else {
CatOne.RegisterDelayCnt--;
CatOne.EthLinkWaitCnt++;
if(CatOne.EthLinkWaitCnt >= ETH_LINK_WAIT_TIME_MAX) {
CAT1_DBG_LOG("ETH Link Timeout, Reset!\r\n");
CatOne.EthStatus = ETH_OFF;
}
rt_thread_delay(1);
}
break;
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);
CatOne.EthFirstRegFlag = false;
}
uint8_t ret = GateWayRegister(CatOneEthTxBuff);
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; // 重置重试计数器
}
break;
case ETH_WAIT_SEND:
result = rt_mq_recv(CatOne.GateWay->NetSendData_MQ, Payload, CAT_ONE_REV_LEN_MAX, 100);
if(result == RT_EOK) {
CatOneEthTxLen = NetCommOrgData(CatOne.GateWay, Payload, CatOneEthTxBuff);
CatOne.EthStatus = ETH_SEND_DATA;
}
else {
if(CatOne.EthStatus == ETH_RESET || CatOne.EthStatus == ETH_OFF)
return;
if(ETH_LINK_GET() != Reset) {
CAT1_DBG_LOG("ETH Link Lost!\r\n");
CatOne.EthStatus = ETH_OFF;
}
else {
rt_thread_delay(1);
}
}
break;
case ETH_SEND_DATA:
HexToAscii(CatOneEthTxBuff, CommUnitSendASCII, CatOneEthTxLen);
EthRevTimeOutCnt = 0;
EthOrCat1UartSend((uint8_t *)CommUnitSendASCII, CatOneEthTxLen * 2);
CommUnitSendASCII[CatOneEthTxLen * 2] = 0;
CAT1_DBG_LOG("Eth Send: %s\r\n",CommUnitSendASCII);
CAT1_DBG_LOG("Eth Send: %s\r\n", CommUnitSendASCII);
CatOne.EthStatus = ETH_WAIT_RECV;
CatOne.EthRecvTimeoutCnt = 0;
CatOne.EthSendRetryCnt = 0;
break;
case ETH_WAIT_RECV:
rt_thread_delay(1);
CatOne.EthRecvTimeoutCnt++;
if(CatOne.EthRecvTimeoutCnt >= ETH_RECV_TIMEOUT_MAX) {
CAT1_DBG_LOG("ETH Recv Timeout!\r\n");
CatOne.EthSendRetryCnt++;
if(CatOne.EthSendRetryCnt >= ETH_SEND_RETRY_MAX) {
CAT1_DBG_LOG("ETH Send Retry Max, Reset!\r\n");
CatOne.EthStatus = ETH_OFF;
}
else {
if(CatOne.GateWay->SvrRegFlag == false) {
CatOne.EthStatus = ETH_REG_SVR;
}
else {
CatOne.EthStatus = ETH_WAIT_SEND;
}
}
}
if(ETH_LINK_GET() != Reset) {
CAT1_DBG_LOG("ETH Link Lost During Wait!\r\n");
CatOne.EthStatus = ETH_OFF;
}
if(CatOne.GateWay->SvrRegFlag == true) {
CAT1_DBG_LOG("ETH Register Success!\r\n");
CatOne.EthStatus = ETH_WAIT_SEND;
CatOne.EthRecvTimeoutCnt = 0;
CatOne.EthSendRetryCnt = 0;
}
break;
case ETH_OFF:
CAT1_DBG_LOG("ETH Power Off!\r\n");
//ETH_RESET_CLR();
//rt_thread_delay(3000);
//ETH_RESET_SET();
CatOne.EthStatus = ETH_IDEL;
CatOne.EthResetDelayCnt = ETH_RESET_DELAY_TIME_MAX;
break;
default:
CatOne.EthStatus = ETH_RESET;
break;
}
}
@@ -600,7 +756,7 @@ bool CatOneEthSendQueue(uint8_t *sData, uint16_t sLen)
static void CatOneInit(GateWayPara GateWay)
{
memset(&CatOne, 0x00, sizeof(CatOne_t));
CatOne.Status = CAT_ONE_RESET;
CatOne.Cat1Status = CAT_ONE_RESET;
CatOne.GateWay = GateWay;
CatOne.CatOneRevCallBack = GateWay->SvrRevCallBack;
}
@@ -728,3 +884,122 @@ void CatReadImeiOrSim(char *Imei, char *Sim)
Sim[20] = 0x00;
}
}
void CatOneTriggerRegister(void)
{
CatOne.Cat1Status = CAT_ONE_REG_SVR;
}
void ETHTriggerRegister(void)
{
CatOne.EthStatus = ETH_REG_SVR;
}
void ETHApplyNetPara(void)
{
uint8_t cmdBuf[128];
uint16_t idx = 0;
GWConfigPara_t *pCfg = (GWConfigPara_t *)&CatOne.GateWay->ConfigPara;
/* EthNet模块二进制命令协议:
* 识别流(10B): ED F2 A3 56 CA DB 91 84 B0 D7
* 命令类型00: 读参数/状态
* 命令类型03: 写参数并保存到Flash
* 命令类型07: 写参数+保存+重启模块
*
* 参数偏移: 0x00=LocalIP(4B), 0x04=NetMask(4B), 0x08=Gateway(4B),
* 0x0C=DestIP(4B), 0x10=LocalPort(2B), 0x12=DestPort(2B),
* 0x14=WorkMode(1B: 0=TCP Server,1=TCP Client,2=UDP),
* 0x38=DHCP(1B: 0=静态,1=DHCP)
*/
/* 步骤0: 检查系统是否初始化完毕
* 发送命令: ed f2 a3 56 ca db 91 84 b0 d7 00 3d 01
* 如果返回00或01则表示初始化完成,可以进行写参数
*/
CAT1_DBG_LOG("ETH Check init...");
for(int waitCnt = 0; waitCnt < 50; waitCnt++) {
idx = 0;
cmdBuf[idx++] = 0xED; cmdBuf[idx++] = 0xF2; cmdBuf[idx++] = 0xA3; cmdBuf[idx++] = 0x56;
cmdBuf[idx++] = 0xCA; cmdBuf[idx++] = 0xDB; cmdBuf[idx++] = 0x91; cmdBuf[idx++] = 0x84;
cmdBuf[idx++] = 0xB0; cmdBuf[idx++] = 0xD7;
cmdBuf[idx++] = 0x00; /* 读参数 */
cmdBuf[idx++] = 0x3D; /* 偏移: 0x3D (Status) */
cmdBuf[idx++] = 0x01; /* 长度: 1字节 */
EthOrCat1UartSend(cmdBuf, idx);
rt_thread_delay(100);
/* 实际应该检查返回值,这里简单等待后继续 */
}
CAT1_DBG_LOG("ETH Init check done");
/* 步骤1: 一次性写入从0x00开始的网络参数(LocalIP~WorkMode, 共0x15字节)
* 偏移0x00~0x14: LocalIP(4) + NetMask(4) + Gateway(4) + DestIP(4) + LocalPort(2) + DestPort(2) + WorkMode(1)
*/
idx = 0;
cmdBuf[idx++] = 0xED; cmdBuf[idx++] = 0xF2; cmdBuf[idx++] = 0xA3; cmdBuf[idx++] = 0x56;
cmdBuf[idx++] = 0xCA; cmdBuf[idx++] = 0xDB; cmdBuf[idx++] = 0x91; cmdBuf[idx++] = 0x84;
cmdBuf[idx++] = 0xB0; cmdBuf[idx++] = 0xD7;
cmdBuf[idx++] = 0x01; /* 命令类型: 写参数,部分参数修改后会自动重启 */
cmdBuf[idx++] = 0x00; /* 偏移: 0x00 */
cmdBuf[idx++] = 0x15; /* 长度: 21字节 */
/* Local IP */
cmdBuf[idx++] = pCfg->EthNet.IpAddr[0];
cmdBuf[idx++] = pCfg->EthNet.IpAddr[1];
cmdBuf[idx++] = pCfg->EthNet.IpAddr[2];
cmdBuf[idx++] = pCfg->EthNet.IpAddr[3];
/* Net Mask */
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[0];
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[1];
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[2];
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[3];
/* Gateway */
cmdBuf[idx++] = pCfg->EthNet.Gateway[0];
cmdBuf[idx++] = pCfg->EthNet.Gateway[1];
cmdBuf[idx++] = pCfg->EthNet.Gateway[2];
cmdBuf[idx++] = pCfg->EthNet.Gateway[3];
/* Dest IP */
cmdBuf[idx++] = pCfg->EthNet.DestIp[0];
cmdBuf[idx++] = pCfg->EthNet.DestIp[1];
cmdBuf[idx++] = pCfg->EthNet.DestIp[2];
cmdBuf[idx++] = pCfg->EthNet.DestIp[3];
/* Local Port (大端) */
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.IpPort >> 8);
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.IpPort & 0xFF);
/* Dest Port (大端) */
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.DestPort >> 8);
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.DestPort & 0xFF);
/* Work Mode: 0=TCP Server, 1=TCP Client, 2=UDP */
if(pCfg->EthNet.WorkMode == ETH_MODE_TCP_SERVER) {
cmdBuf[idx++] = 0x00;
} else if(pCfg->EthNet.WorkMode == ETH_MODE_TCP_CLIENT) {
cmdBuf[idx++] = 0x01;
} else {
cmdBuf[idx++] = 0x02;
}
CAT1_DBG_LOG("ETH Write IP/Mode, len=%d", idx);
EthOrCat1UartSend(cmdBuf, idx);
rt_thread_delay(500);
/* 步骤2: 写入DHCP/IP模式 (偏移0x38, 1字节)
* 0=静态IP, 1=DHCP
*/
idx = 0;
cmdBuf[idx++] = 0xED; cmdBuf[idx++] = 0xF2; cmdBuf[idx++] = 0xA3; cmdBuf[idx++] = 0x56;
cmdBuf[idx++] = 0xCA; cmdBuf[idx++] = 0xDB; cmdBuf[idx++] = 0x91; cmdBuf[idx++] = 0x84;
cmdBuf[idx++] = 0xB0; cmdBuf[idx++] = 0xD7;
cmdBuf[idx++] = 0x01; /* 命令类型: 写参数,DHCP修改后会自动重启 */
cmdBuf[idx++] = 0x38; /* 偏移: 0x38 (DHCP en) */
cmdBuf[idx++] = 0x01; /* 长度: 1字节 */
cmdBuf[idx++] = (pCfg->EthNet.IpMode == ETH_IP_DHCP) ? 0x01 : 0x00;
CAT1_DBG_LOG("ETH Write DHCP=%d", cmdBuf[idx - 1]);
EthOrCat1UartSend(cmdBuf, idx);
rt_thread_delay(3000); /* 等待模块重启 */
/* 注意:不要向DevID(偏移0x1F)区域写入任意数据,否则根据手册说明,
* 如果写入的ID不正确,设备会丢弃所有其他写入的参数
* 模块会在下次上电时自动使用Flash中保存的参数工作
*/
}
+26 -8
View File
@@ -23,8 +23,24 @@ const uint8_t SensorTypeDataLen[] = {
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-位移计
};
/*****************************************************************************************
@@ -264,8 +280,8 @@ void CommUnitCmdSend(GateWayPara GateWay, uint8_t *CommUnitMac, CommUnitCmd_m Cm
/*****************************************************************************************
* 函数名称: CommUintOrgData
* 功能描述: 上传传感器数据函数
* 参 数: GWMac,网关mac地址
CUPara, 通讯单元
* 参 数: CUPara, 通讯单元参数
CUData, 通讯单元数
sData, 数据入口
* 返 回 值: 数据长度
*****************************************************************************************/
@@ -441,8 +457,8 @@ void DebugDisplaySensorData(int SensorIdx, uint16_t SensorType, uint8_t *SensorD
case DISPLACEMENT: {
Displacement_T Sensor;
memcpy((uint8_t *)&Sensor, SensorData, sizeof(Displacement_T));
MAIN_DBG_LOG("Sensor%d Type %04x: PitchAngle=%04d, RollAngle=%04d, YawAngle=%04d, Altitude=%06f, Distance=%04d\r\n",
SensorIdx, SensorType, Sensor.PitchAngle, Sensor.RollAngle, Sensor.YawAngle, Sensor.Altitude, Sensor.Distance);
MAIN_DBG_LOG("Sensor%d Type %04x: PitchAngle=%04d, RollAngle=%04d, YawAngle=%04d, Temp=%06f, Altitude=%06f, Distance=%04d\r\n",
SensorIdx, SensorType, Sensor.PitchAngle, Sensor.RollAngle, Sensor.YawAngle, Sensor.Temp, Sensor.Altitude, Sensor.Distance);
break;
}
default:
@@ -559,11 +575,13 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
MegData[0] = PayLoadLen & 0x00ff;;
MegData[1] = (PayLoadLen >> 8) & 0x00ff;
MegData[2] = NET_COMM_CMD_ADD_UNIT;
MegData[3] = (GateWay->ConfigPara.CommUnitArray[i].SensorN) & 0x00ff;;
MegData[4] = (GateWay->ConfigPara.CommUnitArray[i].SensorN >> 8) & 0x00ff;
for(uint8_t i = 0; i < GateWay->ConfigPara.CommUnitArray[i].SensorN; i++)
{
memcpy(&MegData[3], GateWay->ConfigPara.CommUnitArray[i].Mac[i], 6);
memcpy(&MegData[5], GateWay->ConfigPara.CommUnitArray[i].Mac[i], 6);
}
CatOneEthSendQueue(MegData, PayLoadLen+3);
CatOneEthSendQueue(MegData, PayLoadLen+5);
rt_free(MegData);
}
return 0xff;
@@ -995,14 +1013,14 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
if(GateWay->ConfigPara.Rs485Ch1.Enable == true) { //内部通讯单元处理
if(GateWay->ConfigPara.Rs485Ch1.CommUnitEnable == true) {
SensorCnt++;
memcpy(&MegData[sLen], GateWay->ConfigPara.Rs485Ch1.CUData.Para.Mac[0], 6);
memcpy(&MegData[sLen], GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0], 6);
sLen += 6;
}
}
if(GateWay->ConfigPara.Rs485Ch2.Enable == true) {
if(GateWay->ConfigPara.Rs485Ch2.CommUnitEnable == true) {
SensorCnt++;
memcpy(&MegData[sLen], GateWay->ConfigPara.Rs485Ch2.CUData.Para.Mac[0], 6);
memcpy(&MegData[sLen], GateWay->ConfigPara.Rs485Ch2.CUPara.Para.Mac[0], 6);
sLen += 6;
}
}
+17 -17
View File
@@ -289,18 +289,18 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP
}
}
}
else if(RS485Ch->CUData.Para.SensorN > 0){
else if(RS485Ch->CUPara.Para.SensorN > 0){
SCPara->SendFlag = false;
if(SCPara->ReadSensorInterval > 0) {
SCPara->ReadSensorInterval--;
}
else {
if(SCPara->ReadSensorCnt >= RS485Ch->CUData.Para.SensorN || SCPara->SensorCnt >= SENSOR_NUM_MAX) {
if(SCPara->ReadSensorCnt >= RS485Ch->CUPara.Para.SensorN || SCPara->SensorCnt >= SENSOR_NUM_MAX) {
SCPara->SensorCnt = 0;
SCPara->ReadSensorCnt = 0;
SCPara->ReadSensorInterval = GateWay->ConfigPara.CommUnitReadInterval * 5;
RS485Ch->CUData.Para.BatLevel = GateWay->Battery;
CommUintLen = CommUintOrgData(GateWay, &RS485Ch->CUData.Para, &SCPara->SensorData, CommUintData);
RS485Ch->CUPara.Para.BatLevel = GateWay->Battery;
CommUintLen = CommUintOrgData(GateWay, &RS485Ch->CUPara.Para, &SCPara->SensorData, CommUintData);
//AddLog(&CommUintData[2], CommUintLen - 2);
CatOneEthSendQueue(CommUintData, CommUintLen);
if(RS485Ch == &GateWay->ConfigPara.Rs485Ch1) {
@@ -312,11 +312,11 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP
SCPara->SensorCnt = 0;
}
else {
if(RS485Ch->CUData.Para.SensorType[SCPara->SensorCnt] != 0) {
if(RS485Ch->CUPara.Para.SensorType[SCPara->SensorCnt] != 0) {
rt_thread_delay(50);
SCPara->Cmd = RS485_SENSOR_CMD_READ;
SCPara->SensorAddr = SCPara->SensorCnt + 1;
SCPara->SensorType = RS485Ch->CUData.Para.SensorType[SCPara->SensorCnt];
SCPara->SensorType = RS485Ch->CUPara.Para.SensorType[SCPara->SensorCnt];
SCPara->CmdParaLen = RS485SensorCmdPayLoadLen[RS485_SENSOR_CMD_READ];
SCPara->CmdPara = NULL;
//rt_mutex_take(GateWay->UartRevMutex, RT_WAITING_FOREVER);
@@ -402,7 +402,7 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP
else {
if(RS485Ch->CommUnitEnable == true) {
//rt_mutex_release(GateWay->UartRevMutex);
if(SCPara->SendFlag == true) { //&& RS485Ch->CUData.Para.SensorN > 0 && RS485Ch->QuerySensorFlag == false){
if(SCPara->SendFlag == true) { //&& RS485Ch->CUPara.Para.SensorN > 0 && RS485Ch->QuerySensorFlag == false){
if(RS485Ch == &GateWay->ConfigPara.Rs485Ch1) {
test++;
MAIN_DBG_LOG("InCommUint1, Sensor %d Comm Error, Cmd %d...\r\n", SCPara->SensorAddr, SCPara->Cmd);
@@ -455,13 +455,13 @@ void RS485Ch1_Thread_Entry(void *parameter)
InCommUnitMac[3] = GateWay->ConfigPara.GwMac[4];
InCommUnitMac[4] = GateWay->ConfigPara.GwMac[5];
RS485Ch = &GateWay->ConfigPara.Rs485Ch1;
memcpy(RS485Ch->CUData.Para.Mac, InCommUnitMac, 6);
memcpy(RS485Ch->CUPara.Para.Mac, InCommUnitMac, 6);
if(RS485Ch->CommUnitEnable == true) {
RS485_CH1_POW_ON();
RS485Ch->CUData.Para.SensorN = 0;
memset(RS485Ch->CUData.Para.SensorType, 0x00, sizeof(SENSOR_NUM_MAX * 2));
RS485Ch->CUPara.Para.SensorN = 0;
memset(RS485Ch->CUPara.Para.SensorType, 0x00, sizeof(SENSOR_NUM_MAX * 2));
RS485Ch->QuerySensorFlag = true;
RS485Ch->CUData.Para.CommStatus = true;
RS485Ch->CUPara.Para.CommStatus = true;
}
SCPara->RS485CommUnitReadTimeDelay = 100;
SCPara->RS485Rev_Sem = rt_sem_create("rsch1sem", 0, RT_IPC_FLAG_FIFO);
@@ -519,13 +519,13 @@ void RS485Ch2_Thread_Entry(void *parameter)
InCommUnitMac[3] = GateWay->ConfigPara.GwMac[4];
InCommUnitMac[4] = GateWay->ConfigPara.GwMac[5];
RS485Ch = &GateWay->ConfigPara.Rs485Ch2;
memcpy(RS485Ch->CUData.Para.Mac, InCommUnitMac, 6);
memcpy(RS485Ch->CUPara.Para.Mac, InCommUnitMac, 6);
if(RS485Ch->CommUnitEnable == true) {
RS485_CH2_POW_ON();
RS485Ch->CUData.Para.SensorN = 0;
memset(RS485Ch->CUData.Para.SensorType, 0x00, sizeof(SENSOR_NUM_MAX * 2));
RS485Ch->CUPara.Para.SensorN = 0;
memset(RS485Ch->CUPara.Para.SensorType, 0x00, sizeof(SENSOR_NUM_MAX * 2));
RS485Ch->QuerySensorFlag = true;
RS485Ch->CUData.Para.CommStatus = 1;
RS485Ch->CUPara.Para.CommStatus = 1;
}
SCPara->RS485CommUnitReadTimeDelay = 100;
SCPara->RS485Rev_Sem = rt_sem_create("rsch2sem", 0, RT_IPC_FLAG_FIFO);
@@ -565,7 +565,7 @@ void RS485RxOverhandler(void)
if(SComm1Para.RS485TimeOutCnt > 0)
SComm1Para.RS485TimeOutCnt--;
if(SComm1Para.RS485RxLen > 5 && SComm1Para.RS485TimeOutCnt == 0) {
if(SComm1Para.RS485RxLen >= 1 && SComm1Para.RS485TimeOutCnt == 0) {
if(SComm1Para.InitOverFlag == true) {
rt_sem_release(SComm1Para.RS485Rev_Sem);
SComm1Para.RS485TimeOutCnt = 20;
@@ -579,7 +579,7 @@ void RS485RxOverhandler(void)
if(SComm2Para.RS485TimeOutCnt > 0)
SComm2Para.RS485TimeOutCnt--;
if(SComm2Para.RS485RxLen > 5 && SComm2Para.RS485TimeOutCnt == 0) {
if(SComm2Para.RS485RxLen >= 1 && SComm2Para.RS485TimeOutCnt == 0) {
if(SComm2Para.InitOverFlag == true) {
SComm2Para.RS485TimeOutCnt = 20;
rt_sem_release(SComm2Para.RS485Rev_Sem);
+38 -25
View File
@@ -134,11 +134,41 @@ void GateWayInit(void)
memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t));
GateWay.ConfigPara.SavFlag = LOG_SAV_FLAG;
GateWay.ConfigPara.Comm = CATONE_COMM;
GateWay.ConfigPara.SvrAddr[0] = 103;
GateWay.ConfigPara.SvrAddr[1] = 217;
GateWay.ConfigPara.SvrAddr[2] = 192;
GateWay.ConfigPara.SvrAddr[3] = 248;
GateWay.ConfigPara.SvrPort = 12111;
#if MAC_ADDR_TYPE == 0//测试服务器
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
GateWay.ConfigPara.LTENet.DestAddr[2] = 103;
GateWay.ConfigPara.LTENet.DestAddr[3] = 147;
GateWay.ConfigPara.LTENet.DestPort = 8080;
#elif MAC_ADDR_TYPE > 0
GateWay.ConfigPara.LTENet.DestAddr[0] = 103;
GateWay.ConfigPara.LTENet.DestAddr[1] = 217;
GateWay.ConfigPara.LTENet.DestAddr[2] = 192;
GateWay.ConfigPara.LTENet.DestAddr[3] = 248;
GateWay.ConfigPara.LTENet.DestPort = 12111;
#endif
GateWay.ConfigPara.EthNet.IpMode = ETH_IP_STATIC;
GateWay.ConfigPara.EthNet.IpAddr[0] = 192;
GateWay.ConfigPara.EthNet.IpAddr[1] = 168;
GateWay.ConfigPara.EthNet.IpAddr[2] = 1;
GateWay.ConfigPara.EthNet.IpAddr[3] = 101;
GateWay.ConfigPara.EthNet.IpPort = 10000;
GateWay.ConfigPara.EthNet.WorkMode = ETH_MODE_TCP_CLIENT;
GateWay.ConfigPara.EthNet.SubnetMask[0] = 255;
GateWay.ConfigPara.EthNet.SubnetMask[1] = 255;
GateWay.ConfigPara.EthNet.SubnetMask[2] = 255;
GateWay.ConfigPara.EthNet.SubnetMask[3] = 0;
GateWay.ConfigPara.EthNet.Gateway[0] = 192;
GateWay.ConfigPara.EthNet.Gateway[1] = 168;
GateWay.ConfigPara.EthNet.Gateway[2] = 1;
GateWay.ConfigPara.EthNet.Gateway[3] = 1;
GateWay.ConfigPara.EthNet.DestIp[0] = 192;
GateWay.ConfigPara.EthNet.DestIp[1] = 168;
GateWay.ConfigPara.EthNet.DestIp[2] = 1;
GateWay.ConfigPara.EthNet.DestIp[3] = 100;
GateWay.ConfigPara.EthNet.DestPort = 8080;
GateWay.ConfigPara.CommUnitReadInterval = COMMUNIT_READ_SENSOR_INTERVAL_MAX;//非低功耗设备
memset(GateWay.ConfigPara.CommUnitArray, 0x00, sizeof(CommUnitData_t) * COMMUNIT_NUM_MAX);
GateWay.ConfigPara.Rs485Ch1.Enable = true;
@@ -168,7 +198,7 @@ void GateWayInit(void)
#if MAC_ADDR_TYPE == 0
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_Test, 6);
GateWay.ConfigPara.DebugChannel = DEBUG_CH_DBG;
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
#elif MAC_ADDR_TYPE == 1
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL1, 6);
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
@@ -202,25 +232,6 @@ 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;
GateWay.ConfigPara.SvrAddr[2] = 103;
GateWay.ConfigPara.SvrAddr[3] = 147;
GateWay.ConfigPara.SvrPort = 8080;
#elif MAC_ADDR_TYPE > 0
// GateWay.ConfigPara.SvrAddr[0] = 39;
// GateWay.ConfigPara.SvrAddr[1] = 106;
// GateWay.ConfigPara.SvrAddr[2] = 103;
// GateWay.ConfigPara.SvrAddr[3] = 147;
// GateWay.ConfigPara.SvrPort = 8080;
GateWay.ConfigPara.SvrAddr[0] = 103;
GateWay.ConfigPara.SvrAddr[1] = 217;
GateWay.ConfigPara.SvrAddr[2] = 192;
GateWay.ConfigPara.SvrAddr[3] = 248;
GateWay.ConfigPara.SvrPort = 12111;
#endif
}
if(GateWay.ConfigPara.OutageFlag != true && GateWay.ConfigPara.OutageFlag != false)
@@ -322,6 +333,8 @@ void GateWayInit(void)
}
else {
ETH_ON();
rt_thread_delay(1000);
ETHReset();
}
}