feat(channel): 6通道独立调度+MQueue/DEBUG_Printf重构/冗余清理
通道系统: - 新增Channel_m枚举(CH_NULL/DBG/CH1/CH2/ETH/LORA/CAT1) - Much/Auch/Duch/CuchMask替代旧Comm/DebugChannel - ChannelIsActive宏四重身份检查, ChannelMQ每通道独立队列 - much/auch/duch/cuch命令(互斥检查+USART1 pair冲突) - 各通道任务按ChannelIsActive休眠/活跃 双回调分离: - SvrRegFlag->MuchRegFlag+AuchRegFlag - _NetRevCallBack+pRegFlag实现Much/Auch回调复用 MQ重构: - ChMQ[6]每通道独立队列替代NetSendData_MQ - UploadSend无条件下发Much+Auch双队列 - Cat1/ETH/RS485/Lora各自消费ChMQ 注册流程: - 注册帧绕MQ直接发送(解决FIFO顺序冲突) - NetCommOrgData输入输出buffer分离(解决重叠bug) - Much首次连上必注册, Auch跳过注册直接发送 - ETH_REG_SVR SendRetryCnt首次清零(解决无限重试) - 状态机不再清零注册标志 调试通道: - Debug_Printf->rt_kprintf->rt_hw_console_output全ch路由 - rt_hw_console_output 6通道switch - EthTxMutex保护USART4多线程安全 - ETH接收线程非0x7A帧头->DebugAnalyze(网络debug指令) - EthOverHandler阈值>5->>0(短指令接收) 冗余清理: - 删Cat1UpdateCallback/Cat1SendRegister/ETHSendRegister - 删InfTest/FSInit/SDCardTest死代码 - 删unused includes/macros/variables - 删vcom_Print/buff/ir中间层 - DEBUG_CMD_CNT实际对齐 - 中文标点修正 - 默认: Much=ETH Auch=null Duch=ETH Cuch=LORA
This commit is contained in:
@@ -450,6 +450,16 @@
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>(60 * 1000),0x0A</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>4</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>GateWay.ConfigPara</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>5</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>cat1Active</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<WatchWindow2>
|
||||
<Ww>
|
||||
@@ -1068,7 +1078,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>::RTOS</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>1</RteFlg>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <rtthread.h>
|
||||
#include "bsp.h"
|
||||
#include "main.h"
|
||||
#include "sx127x.h"
|
||||
|
||||
extern GateWayPara_t GateWay;
|
||||
|
||||
@@ -20,7 +21,7 @@ extern GateWayPara_t GateWay;
|
||||
* Please modify RT_HEAP_SIZE if you enable RT_USING_HEAP
|
||||
* the RT_HEAP_SIZE max value = (sram size - ZI size), 1024 means 1024 bytes
|
||||
*/
|
||||
#define RT_HEAP_SIZE (32*1024)
|
||||
#define RT_HEAP_SIZE (48*1024)
|
||||
static rt_uint8_t rt_heap[RT_HEAP_SIZE];
|
||||
|
||||
RT_WEAK void *rt_heap_begin_get(void)
|
||||
@@ -85,14 +86,14 @@ INIT_BOARD_EXPORT(uart_init);
|
||||
void rt_hw_console_output(const char *str)
|
||||
{
|
||||
rt_enter_critical();
|
||||
if(GateWay.ConfigPara.DebugChannel == DEBUG_CH_RS485_1) {
|
||||
RS485Ch1UartSend((uint8_t *)str, strlen(str));
|
||||
}
|
||||
else if(GateWay.ConfigPara.DebugChannel == DEBUG_CH_RS485_2) {
|
||||
RS485Ch2UartSend((uint8_t *)str, strlen(str));
|
||||
}
|
||||
else {
|
||||
DebugOrCat1UartSend((uint8_t *)str, strlen(str));
|
||||
switch(GateWay.ConfigPara.Duch) {
|
||||
case CH_RS485_1: RS485Ch1UartSend((uint8_t *)str, strlen(str)); break;
|
||||
case CH_RS485_2: RS485Ch2UartSend((uint8_t *)str, strlen(str)); break;
|
||||
case CH_ETH: EthUartSend((uint8_t *)str, strlen(str)); break;
|
||||
case CH_LORA: Sx1276LoRaSendBuffer((uint8_t *)str, strlen(str)); break;
|
||||
case CH_DBG:
|
||||
case CH_CAT1:
|
||||
default: DebugOrCat1UartSend((uint8_t *)str, strlen(str)); break;
|
||||
}
|
||||
rt_exit_critical();
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@
|
||||
|
||||
#define DBG_RX_LEN_MAX 128
|
||||
//#define DBG_LOG(...) rt_kprintf(__VA_ARGS__)
|
||||
#define DEBUG_CMD_CNT 29
|
||||
#define DEBUG_CMD_CNT 32
|
||||
#define DEBUG_BUFF_SIZE_MAX 512
|
||||
|
||||
#define DEBUG_BUFSIZE 200
|
||||
#define DEBUG_BUFF_MAX 1024
|
||||
|
||||
void Debug_Printf(char *format, ...);
|
||||
extern void rt_hw_console_output(const char *str);
|
||||
|
||||
#define DBG_LOG(...) Debug_Printf(__VA_ARGS__)
|
||||
|
||||
@@ -30,66 +31,18 @@ typedef struct{
|
||||
const DBGFunType DebugFun[DEBUG_CMD_CNT];
|
||||
|
||||
static GateWayPara GateWay;
|
||||
static char buff[DBG_RX_LEN_MAX];
|
||||
static uint8_t DebugRxLen;
|
||||
static uint8_t DebugRxBuff[DBG_RX_LEN_MAX];
|
||||
static uint8_t DebugRxTimeOut1mSCnt;
|
||||
static rt_sem_t DebugRev_Sem;
|
||||
static uint16_t ir=0; /* buffer read index*/
|
||||
static char tempBuff[DEBUG_BUFF_MAX];
|
||||
|
||||
void vcom_Print(uint8_t sLen)
|
||||
{
|
||||
char* CurChar;
|
||||
ir = 0;
|
||||
while(ir < sLen)
|
||||
{
|
||||
CurChar = &buff[ir++];
|
||||
if(GateWay->ConfigPara.DebugChannel == DEBUG_CH_RS485_1)
|
||||
RS485Ch1UartSend((uint8_t*)CurChar, 1);
|
||||
else if(GateWay->ConfigPara.DebugChannel == DEBUG_CH_RS485_2)
|
||||
RS485Ch2UartSend((uint8_t*)CurChar, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: Debug_Printf
|
||||
* 功能描述: RS485通道1任务函数
|
||||
* 参 数: 任务参数入口
|
||||
* 返 回 值: 无
|
||||
*****************************************************************************************/
|
||||
void Debug_Printf(char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
uint16_t len;
|
||||
//uint32_t primask_bit;
|
||||
uint16_t offset = 0;
|
||||
//primask_bit = __get_PRIMASK();
|
||||
//__disable_irq();
|
||||
|
||||
/*convert into string at buff[0] of length iw*/
|
||||
len = vsprintf(&tempBuff[0], format, args);
|
||||
if(GateWay->ConfigPara.DebugChannel == DEBUG_CH_DBG) {
|
||||
rt_kprintf(tempBuff);
|
||||
}
|
||||
else {
|
||||
while(offset < len) {
|
||||
if((len - offset) < DEBUG_BUFSIZE) {
|
||||
memcpy(&buff[0], &tempBuff[offset], len - offset);
|
||||
vcom_Print(len - offset);
|
||||
offset = len;
|
||||
}
|
||||
else {
|
||||
memcpy(&buff[0], &tempBuff[offset], DEBUG_BUFSIZE);
|
||||
offset += DEBUG_BUFSIZE;
|
||||
vcom_Print(DEBUG_BUFSIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
//__set_PRIMASK(primask_bit);
|
||||
//__enable_irq();
|
||||
|
||||
vsprintf(&tempBuff[0], format, args);
|
||||
rt_hw_console_output(tempBuff);
|
||||
va_end(args);
|
||||
}
|
||||
/*****************************************************************************************
|
||||
@@ -127,7 +80,7 @@ void Debug_Thread_Entry(void *parameter)
|
||||
*****************************************************************************************/
|
||||
void DbgOrCat1RxIrqCallback(uint8_t rData)
|
||||
{
|
||||
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
|
||||
if(ChannelIsActive(GateWay->ConfigPara, CH_CAT1)) {
|
||||
Cat1IrqCallback(rData);
|
||||
return;
|
||||
}
|
||||
@@ -144,7 +97,7 @@ void DbgOrCat1RxIrqCallback(uint8_t rData)
|
||||
|
||||
void DebugOrCat1RxOverhandler(void)
|
||||
{
|
||||
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
|
||||
if(ChannelIsActive(GateWay->ConfigPara, CH_CAT1)) {
|
||||
Cat1OverHandler();
|
||||
return;
|
||||
}
|
||||
@@ -694,56 +647,171 @@ void DebugCmdLsExclCommUnit(int argc, char *argv[])
|
||||
DBG_LOG("\r\n\r\n");
|
||||
}
|
||||
/*****************************************************************************************
|
||||
* 函数名称: DebugCmdSetComm
|
||||
* 功能描述: 设置网关与服务通讯方式
|
||||
* 函数名称: ParseChannel
|
||||
* 功能描述: 解析通道字符串
|
||||
* 参 数: str, 通道名称字符串
|
||||
* 返 回 值: Channel_m通道枚举值
|
||||
*****************************************************************************************/
|
||||
static Channel_m ParseChannel(const char *str)
|
||||
{
|
||||
if(strcmp(str, "null") == 0) return CH_NULL;
|
||||
if(strcmp(str, "dbg") == 0) return CH_DBG;
|
||||
if(strcmp(str, "ch1") == 0) return CH_RS485_1;
|
||||
if(strcmp(str, "ch2") == 0) return CH_RS485_2;
|
||||
if(strcmp(str, "eth") == 0) return CH_ETH;
|
||||
if(strcmp(str, "lora") == 0) return CH_LORA;
|
||||
if(strcmp(str, "cat1") == 0) return CH_CAT1;
|
||||
return CH_NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: DebugCmdSetMuch
|
||||
* 功能描述: 设置主上报通道
|
||||
* 参 数: argc, 输入参数数量
|
||||
argv, 输入参数
|
||||
* 返 回 值: 无
|
||||
*****************************************************************************************/
|
||||
void DebugCmdSetComm(int argc, char *argv[])
|
||||
static void DebugCmdSetMuch(int argc, char *argv[])
|
||||
{
|
||||
DBG_LOG("\r\n");
|
||||
if(argc < 2)
|
||||
return;
|
||||
|
||||
if(strcmp(argv[1], "?") == 0) {
|
||||
DBG_LOG("Debug Cmd: comm arg1\r\n");
|
||||
DBG_LOG(" brief --> Set gateway and service communication methods.\r\n");
|
||||
DBG_LOG(" arg1 --> para: (cat1, eth),Cat1 or ETH communication.\r\n\r\n");
|
||||
DBG_LOG("Debug Cmd: much arg1\r\n");
|
||||
DBG_LOG(" brief --> Set main upstream channel.\r\n");
|
||||
DBG_LOG(" arg1 --> (dbg|ch1|ch2|eth|lora|cat1)\r\n\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1], "cat1") == 0) {
|
||||
if(GateWay->ConfigPara.DebugChannel == DEBUG_CH_DBG) {
|
||||
DBG_LOG("dch is dbg, USART1 occupied. Please switch dch to ch1/ch2 first.\r\n");
|
||||
Channel_m ch = ParseChannel(argv[1]);
|
||||
if(ch == CH_NULL && strcmp(argv[1], "null") != 0) {
|
||||
DBG_LOG("Invalid channel.\r\n");
|
||||
return;
|
||||
}
|
||||
if(ch != CH_NULL && (ChannelIsActive(GateWay->ConfigPara, ch)
|
||||
|| (ch == CH_DBG && ChannelIsActive(GateWay->ConfigPara, CH_CAT1))
|
||||
|| (ch == CH_CAT1 && ChannelIsActive(GateWay->ConfigPara, CH_DBG)))
|
||||
&& GateWay->ConfigPara.Much != ch) {
|
||||
DBG_LOG("Channel %s is occupied.\r\n", ChannelName(ch));
|
||||
return;
|
||||
}
|
||||
|
||||
GateWay->MuchRegFlag = false;
|
||||
GateWay->ConfigPara.Much = ch;
|
||||
if(ch == CH_CAT1) CatOneReset();
|
||||
if(ch == CH_ETH) ETHReset();
|
||||
DBG_LOG("Set Much to %s.\r\n", ChannelName(ch));
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: DebugCmdSetAuch
|
||||
* 功能描述: 设置辅助上报通道
|
||||
* 参 数: argc, 输入参数数量
|
||||
argv, 输入参数
|
||||
* 返 回 值: 无
|
||||
*****************************************************************************************/
|
||||
static void DebugCmdSetAuch(int argc, char *argv[])
|
||||
{
|
||||
DBG_LOG("\r\n");
|
||||
if(argc < 2)
|
||||
return;
|
||||
|
||||
if(strcmp(argv[1], "?") == 0) {
|
||||
DBG_LOG("Debug Cmd: auch arg1\r\n");
|
||||
DBG_LOG(" brief --> Set auxiliary upstream channel.\r\n");
|
||||
DBG_LOG(" arg1 --> (dbg|ch1|ch2|eth|lora|cat1)\r\n\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Channel_m ch = ParseChannel(argv[1]);
|
||||
if(ch == CH_NULL && strcmp(argv[1], "null") != 0) {
|
||||
DBG_LOG("Invalid channel.\r\n");
|
||||
return;
|
||||
}
|
||||
if(ch != CH_NULL && (ChannelIsActive(GateWay->ConfigPara, ch)
|
||||
|| (ch == CH_DBG && ChannelIsActive(GateWay->ConfigPara, CH_CAT1))
|
||||
|| (ch == CH_CAT1 && ChannelIsActive(GateWay->ConfigPara, CH_DBG)))
|
||||
&& GateWay->ConfigPara.Auch != ch) {
|
||||
DBG_LOG("Channel %s is occupied.\r\n", ChannelName(ch));
|
||||
return;
|
||||
}
|
||||
|
||||
GateWay->ConfigPara.Auch = ch;
|
||||
if(ch == CH_CAT1) CatOneReset();
|
||||
if(ch == CH_ETH) ETHReset();
|
||||
DBG_LOG("Set Auch to %s.\r\n", ChannelName(ch));
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
* 函数名称: DebugCmdSetCuch
|
||||
* 功能描述: 通讯单元通道位掩码管理
|
||||
* 参 数: argc, 输入参数数量
|
||||
argv, 输入参数
|
||||
* 返 回 值: 无
|
||||
*****************************************************************************************/
|
||||
static void DebugCmdSetCuch(int argc, char *argv[])
|
||||
{
|
||||
DBG_LOG("\r\n");
|
||||
if(argc < 2)
|
||||
return;
|
||||
|
||||
if(strcmp(argv[1], "?") == 0) {
|
||||
DBG_LOG("Debug Cmd: cuch arg1 arg2\r\n");
|
||||
DBG_LOG(" brief --> Manage communication unit channel mask.\r\n");
|
||||
DBG_LOG(" arg1 --> (add|del|ls) subcommand.\r\n");
|
||||
DBG_LOG(" arg2 --> (ch1|ch2|eth|lora|cat1) channel name.\r\n\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1], "ls") == 0) {
|
||||
DBG_LOG("Cuch: %s%s%s%s%s\r\n",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_CH1) ? "ch1 " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_CH2) ? "ch2 " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_ETH) ? "eth " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_LORA) ? "lora " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_CAT1) ? "cat1 " : "");
|
||||
DBG_LOG(" ch1: %s\r\n", (GateWay->ConfigPara.CuchMask & CUCH_CH1) ? "on" : "off");
|
||||
DBG_LOG(" ch2: %s\r\n", (GateWay->ConfigPara.CuchMask & CUCH_CH2) ? "on" : "off");
|
||||
DBG_LOG(" eth: %s\r\n", (GateWay->ConfigPara.CuchMask & CUCH_ETH) ? "on" : "off");
|
||||
DBG_LOG(" lora: %s\r\n", (GateWay->ConfigPara.CuchMask & CUCH_LORA) ? "on" : "off");
|
||||
DBG_LOG(" cat1: %s\r\n", (GateWay->ConfigPara.CuchMask & CUCH_CAT1) ? "on" : "off");
|
||||
return;
|
||||
}
|
||||
|
||||
if(argc < 3) {
|
||||
DBG_LOG("cuch Cmd Para Error!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Channel_m ch = ParseChannel(argv[2]);
|
||||
if(ch == CH_NULL) {
|
||||
DBG_LOG("cuch Cmd Para Error!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1], "add") == 0) {
|
||||
if(GateWay->ConfigPara.Much == ch || GateWay->ConfigPara.Auch == ch || GateWay->ConfigPara.Duch == ch
|
||||
|| (ch == CH_DBG && (GateWay->ConfigPara.Much == CH_CAT1 || GateWay->ConfigPara.Auch == CH_CAT1 || GateWay->ConfigPara.Duch == CH_CAT1))
|
||||
|| (ch == CH_CAT1 && (GateWay->ConfigPara.Much == CH_DBG || GateWay->ConfigPara.Auch == CH_DBG || GateWay->ConfigPara.Duch == CH_DBG))) {
|
||||
DBG_LOG("Channel %s occupied by Much/Auch/Duch.\r\n", ChannelName(ch));
|
||||
return;
|
||||
}
|
||||
GateWay->SvrRegFlag = false;
|
||||
GateWay->ConfigPara.Comm = CATONE_COMM;
|
||||
ETHStop();
|
||||
ETH_OFF();
|
||||
DbgOrCat1Uart_Config(115200);
|
||||
CAT1_ON();
|
||||
CatOneReset();
|
||||
DBG_LOG("Set the communication method to Cat1.\r\n");
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
GateWay->ConfigPara.CuchMask |= (1 << ch);
|
||||
DBG_LOG("Cuch add %s.\r\n", ChannelName(ch));
|
||||
}
|
||||
else if(strcmp(argv[1], "eth") == 0) {
|
||||
DBG_LOG("Set the communication method to Eth.\r\n");
|
||||
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
|
||||
CAT1_PWR_KEY_CLR();
|
||||
CatOneStop();
|
||||
rt_thread_delay(3000);
|
||||
CAT1_PWR_KEY_SET();
|
||||
DBG_ON();
|
||||
}
|
||||
GateWay->SvrRegFlag = false;
|
||||
GateWay->ConfigPara.Comm = ETH_COMM;
|
||||
DbgOrCat1Uart_Config(500000);
|
||||
ETH_ON();
|
||||
ETHReset();
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
else if(strcmp(argv[1], "del") == 0) {
|
||||
GateWay->ConfigPara.CuchMask &= ~(1 << ch);
|
||||
DBG_LOG("Cuch del %s.\r\n", ChannelName(ch));
|
||||
}
|
||||
else {
|
||||
DBG_LOG("cuch Cmd Para Error!\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
@@ -932,11 +1000,6 @@ static void DebugCmdUpload(int argc, char *argv[])
|
||||
return;
|
||||
}
|
||||
|
||||
if(GateWay->SvrRegFlag == false) {
|
||||
DBG_LOG("Server not registered, please register first.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t MegData[6];
|
||||
uint8_t len = sizeof(GateWayAlarmType_t);
|
||||
MegData[0] = len & 0x00ff;
|
||||
@@ -947,7 +1010,7 @@ static void DebugCmdUpload(int argc, char *argv[])
|
||||
MegData[4] = GateWay->ConfigPara.OutageFlag ? 1 : 0;
|
||||
MegData[5] = GateWay->Battery;
|
||||
|
||||
if(CatOneEthSendQueue(MegData, 6) == true) {
|
||||
if(UploadSend(MegData, 6) == true) {
|
||||
DBG_LOG("Gateway status uploaded.\r\n");
|
||||
}
|
||||
else {
|
||||
@@ -971,18 +1034,23 @@ static void DebugCmdRegister(int argc, char *argv[])
|
||||
return;
|
||||
}
|
||||
|
||||
GateWay->SvrRegFlag = false;
|
||||
GateWay->MuchRegFlag = false;
|
||||
|
||||
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
|
||||
if(GateWay->ConfigPara.Much == CH_CAT1) {
|
||||
CatOneTriggerRegister();
|
||||
DBG_LOG("Trigger Cat1 re-registration immediately.\r\n");
|
||||
DBG_LOG("Much Trigger Cat1 re-registration.\r\n");
|
||||
}
|
||||
else if(GateWay->ConfigPara.Comm == ETH_COMM) {
|
||||
else if(GateWay->ConfigPara.Auch == CH_CAT1) {
|
||||
CatOneTriggerRegister();
|
||||
DBG_LOG("Auch Trigger Cat1 re-registration.\r\n");
|
||||
}
|
||||
if(GateWay->ConfigPara.Much == CH_ETH) {
|
||||
ETHTriggerRegister();
|
||||
DBG_LOG("Trigger ETH re-registration immediately.\r\n");
|
||||
DBG_LOG("Much Trigger ETH re-registration.\r\n");
|
||||
}
|
||||
else {
|
||||
DBG_LOG("Unknown communication type.\r\n");
|
||||
else if(GateWay->ConfigPara.Auch == CH_ETH) {
|
||||
ETHTriggerRegister();
|
||||
DBG_LOG("Auch Trigger ETH re-registration.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1165,51 +1233,42 @@ void DebugCmdSelDebugChannel(int argc, char *argv[])
|
||||
return;
|
||||
|
||||
if(strcmp(argv[1], "?") == 0) {
|
||||
DBG_LOG("Debug Cmd: dch args\r\n");
|
||||
DBG_LOG("Debug Cmd: duch args\r\n");
|
||||
DBG_LOG(" brief --> Debug information output channel selection.\r\n");
|
||||
DBG_LOG(" args --> (dbg|ch1|ch2) default: dbg\r\n");
|
||||
DBG_LOG(" args --> (dbg|ch1|ch2|eth|lora|cat1)\r\n");
|
||||
DBG_LOG(" dbg: On board debugging serial port.\r\n");
|
||||
DBG_LOG(" ch1: RS485 channel 1 serial port.\r\n");
|
||||
DBG_LOG(" ch2: RS485 channel 2 serial port.\r\n");
|
||||
DBG_LOG(" note --> When selecting ch1 or ch2, the channel must enable an disable internal CommUnit function before it can be used.\r\n\r\n");
|
||||
DBG_LOG(" eth: ETH serial port.\r\n");
|
||||
DBG_LOG(" lora: LORA channel.\r\n");
|
||||
DBG_LOG(" cat1: CAT1 serial port.\r\n");
|
||||
DBG_LOG(" note --> Cannot select channel used by Much or Auch.\r\n\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(argv[1], "dbg") == 0) {
|
||||
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
|
||||
DBG_LOG("comm is cat1, USART1 occupied. Please switch comm to eth first.\r\n");
|
||||
return;
|
||||
}
|
||||
DBG_LOG("Select Debug Channel is dbg\r\n");
|
||||
Channel_m ch = ParseChannel(argv[1]);
|
||||
if(ch == CH_NULL) {
|
||||
DBG_LOG("Invalid channel.\r\n");
|
||||
return;
|
||||
}
|
||||
if((ch == CH_DBG && ChannelIsActive(GateWay->ConfigPara, CH_CAT1))
|
||||
|| (ch == CH_CAT1 && ChannelIsActive(GateWay->ConfigPara, CH_DBG))) {
|
||||
DBG_LOG("USART1 occupied by dbg/cat1 pair.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
GateWay->ConfigPara.Duch = ch;
|
||||
if(ch == CH_ETH) ETHReset();
|
||||
if(ch == CH_CAT1) {
|
||||
DbgOrCat1Uart_Config(115200);
|
||||
CAT1_ON();
|
||||
}
|
||||
else if(ch == CH_DBG) {
|
||||
DbgOrCat1Uart_Config(500000);
|
||||
GateWay->ConfigPara.DebugChannel = DEBUG_CH_DBG;
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
}
|
||||
else if(strcmp(argv[1], "ch1") == 0) {
|
||||
if (GateWay->ConfigPara.Rs485Ch1.CommUnitEnable == true){
|
||||
DBG_LOG("RS485 channel 1 CommUnit function is not disabled\r\n");
|
||||
return;
|
||||
}
|
||||
DBG_LOG("Select Debug Channel is RS485_CH1\r\n");
|
||||
GateWay->ConfigPara.Rs485Ch1.BaudRate = 500000;
|
||||
GateWay->ConfigPara.Rs485Ch1.Enable = true;
|
||||
RS485Ch1_Config(GateWay->ConfigPara.Rs485Ch1.BaudRate);
|
||||
GateWay->ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
}
|
||||
|
||||
else if(strcmp(argv[1], "ch2") == 0) {
|
||||
if (GateWay->ConfigPara.Rs485Ch2.CommUnitEnable == true){
|
||||
DBG_LOG("RS485 channel 2 CommUnit function is not disabled\r\n");
|
||||
return;
|
||||
}
|
||||
DBG_LOG("Select Debug Channel is RS485_CH2\r\n");
|
||||
GateWay->ConfigPara.Rs485Ch2.BaudRate = 500000;
|
||||
GateWay->ConfigPara.Rs485Ch2.Enable = true;
|
||||
RS485Ch2_Config(GateWay->ConfigPara.Rs485Ch2.BaudRate);
|
||||
GateWay->ConfigPara.DebugChannel = DEBUG_CH_RS485_2;
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
DBG_ON();
|
||||
}
|
||||
DBG_LOG("Set duch to %s.\r\n", ChannelName(ch));
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
@@ -1327,8 +1386,16 @@ static void DebugCmdGetPara(int argc, char *argv[])
|
||||
DBG_LOG("GateWay MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n",
|
||||
GateWay->ConfigPara.GwMac[0], GateWay->ConfigPara.GwMac[1], GateWay->ConfigPara.GwMac[2], GateWay->ConfigPara.GwMac[3], GateWay->ConfigPara.GwMac[4], GateWay->ConfigPara.GwMac[5]);
|
||||
DBG_LOG("Battery: %d%\r\n", GateWay->Battery);
|
||||
DBG_LOG("CommInf: %s\r\n", (GateWay->ConfigPara.Comm == CATONE_COMM) ? "Cat1" : "Eth");
|
||||
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
|
||||
DBG_LOG("Much: %s\r\n", ChannelName(GateWay->ConfigPara.Much));
|
||||
DBG_LOG("Auch: %s\r\n", ChannelName(GateWay->ConfigPara.Auch));
|
||||
DBG_LOG("Duch: %s\r\n", ChannelName(GateWay->ConfigPara.Duch));
|
||||
DBG_LOG("Cuch: %s%s%s%s%s\r\n",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_CH1) ? "ch1 " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_CH2) ? "ch2 " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_ETH) ? "eth " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_LORA) ? "lora " : "",
|
||||
(GateWay->ConfigPara.CuchMask & CUCH_CAT1) ? "cat1 " : "");
|
||||
if(ChannelIsActive(GateWay->ConfigPara, CH_CAT1)) {
|
||||
char Imei[20], Sim[32];
|
||||
CatReadImeiOrSim(Imei, Sim);
|
||||
DBG_LOG("Cat1 IMEI: %s\r\n", Imei);
|
||||
@@ -1337,7 +1404,9 @@ static void DebugCmdGetPara(int argc, char *argv[])
|
||||
DBG_LOG("CommUnitReadInterval: %d\r\n", GateWay->ConfigPara.CommUnitReadInterval);
|
||||
DBG_LOG("Svr MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n",
|
||||
GateWay->SvrMac[0], GateWay->SvrMac[1], GateWay->SvrMac[2], GateWay->SvrMac[3], GateWay->SvrMac[4], GateWay->SvrMac[5]);
|
||||
DBG_LOG("Register Status: %d\r\n", GateWay->SvrRegFlag);
|
||||
DBG_LOG("MuchReg: %d\r\n", GateWay->MuchRegFlag);
|
||||
DBG_LOG("AuchReg: %s\r\n", GateWay->ConfigPara.Auch == CH_NULL ? "null" :
|
||||
(GateWay->AuchRegFlag ? "true" : "false"));
|
||||
|
||||
/* LTENet (Cat1/4G) Parameters */
|
||||
DBG_LOG("=== LTENet (Cat1/4G) Parameters ===\r\n");
|
||||
@@ -1877,10 +1946,6 @@ void DebugCmdHelp(int argc, char *argv[])
|
||||
len = strlen("exls ?\r\n");
|
||||
memcpy(Data, "exls ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("comm ?\r\n");
|
||||
memcpy(Data, "comm ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("sct ?\r\n");
|
||||
memcpy(Data, "sct ?\r\n", len);
|
||||
@@ -1910,10 +1975,6 @@ void DebugCmdHelp(int argc, char *argv[])
|
||||
memcpy(Data, "qs ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("dch ?\r\n");
|
||||
memcpy(Data, "dch ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("ltenet ?\r\n");
|
||||
memcpy(Data, "ltenet ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
@@ -1957,6 +2018,22 @@ void DebugCmdHelp(int argc, char *argv[])
|
||||
len = strlen("eth ?\r\n");
|
||||
memcpy(Data, "eth ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("much ?\r\n");
|
||||
memcpy(Data, "much ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("auch ?\r\n");
|
||||
memcpy(Data, "auch ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("cuch ?\r\n");
|
||||
memcpy(Data, "cuch ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
|
||||
len = strlen("duch ?\r\n");
|
||||
memcpy(Data, "duch ?\r\n", len);
|
||||
DebugAnalyze(GateWay, Data, len);
|
||||
}
|
||||
|
||||
const DBGFunType DebugFun[DEBUG_CMD_CNT] = {
|
||||
@@ -1970,7 +2047,10 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = {
|
||||
"excu", DebugCmdExclCommUnit,
|
||||
"exdel", DebugCmdDelExclCommUnit,
|
||||
"exls", DebugCmdLsExclCommUnit,
|
||||
"comm", DebugCmdSetComm,
|
||||
"much", DebugCmdSetMuch,
|
||||
"auch", DebugCmdSetAuch,
|
||||
"cuch", DebugCmdSetCuch,
|
||||
"duch", DebugCmdSelDebugChannel,
|
||||
"sct", DebugCmdSetCollectTime,
|
||||
"his", DebugCmdReadHisData,
|
||||
"fmt", DebugCmdDelHisData,
|
||||
@@ -1978,7 +2058,6 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = {
|
||||
"res", DebugCmdRestoreFactory,
|
||||
"time", DebugCmdTimeSync,
|
||||
"qs", DebugCmdQuerySensor,
|
||||
"dch", DebugCmdSelDebugChannel,
|
||||
"ltenet", DebugCmdSetLTENet,
|
||||
"mac", DebugCmdSetMac,
|
||||
"para", DebugCmdGetPara,
|
||||
|
||||
@@ -90,7 +90,7 @@ 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);
|
||||
bool UploadSend(uint8_t *sData, uint16_t sLen);
|
||||
void CatOneTriggerRegister(void);
|
||||
void CatOne_Thread_Entry(void *parameter);
|
||||
void Cat1IrqCallback(uint8_t rData);
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#define ETH_RESET_DELAY_TIME_MAX (5 * 60 * 1000)
|
||||
#define ETH_LINK_WAIT_TIME_MAX (10 * 1000)
|
||||
#define ETH_RECV_TIMEOUT_MAX (60 * 1000)
|
||||
#define ETH_RECV_TIMEOUT_MAX (10 * 1000)
|
||||
#define ETH_SEND_RETRY_MAX 3
|
||||
#define ETH_FIRST_REG_DELAY (5 * 1000)
|
||||
#define ETH_FIRST_REG_DELAY (1 * 1000)
|
||||
|
||||
typedef enum {
|
||||
ETH_IDEL,
|
||||
@@ -44,4 +44,5 @@ void EthOverHandler(void);
|
||||
void ETHStop(void);
|
||||
void ETHReset(void);
|
||||
void ETHTriggerRegister(void);
|
||||
void ETHOnOff(bool OnOff);
|
||||
#endif
|
||||
|
||||
@@ -23,10 +23,31 @@ typedef int (*DataRevResCallBack)(GateWayPara GateWay, uint8_t *rData, uint16_t
|
||||
typedef int (*SendDataOrg)(uint8_t *sData);
|
||||
|
||||
typedef enum {
|
||||
DEBUG_CH_DBG,
|
||||
DEBUG_CH_RS485_1,
|
||||
DEBUG_CH_RS485_2,
|
||||
}DebugChannel_m;
|
||||
CH_NULL = -1,
|
||||
CH_DBG = 0,
|
||||
CH_RS485_1,
|
||||
CH_RS485_2,
|
||||
CH_ETH,
|
||||
CH_LORA,
|
||||
CH_CAT1,
|
||||
} Channel_m;
|
||||
|
||||
typedef enum {
|
||||
LORA_COMM,
|
||||
RS485CH1_COMM,
|
||||
RS485CH2_COMM
|
||||
} SensorComm_m;
|
||||
|
||||
#define CUCH_CH1 (1 << CH_RS485_1)
|
||||
#define CUCH_CH2 (1 << CH_RS485_2)
|
||||
#define CUCH_ETH (1 << CH_ETH)
|
||||
#define CUCH_LORA (1 << CH_LORA)
|
||||
#define CUCH_CAT1 (1 << CH_CAT1)
|
||||
|
||||
#define ChannelIsActive(cfg, ch) ((cfg).Much == (ch) || (cfg).Auch == (ch) || (cfg).Duch == (ch) || ((cfg).CuchMask & (1 << (ch))))
|
||||
#define ChannelMQ(gw, ch) ((gw).ChMQ[(ch)])
|
||||
|
||||
const char *ChannelName(Channel_m ch);
|
||||
|
||||
typedef enum {
|
||||
DEV_TYPE_BROADCAST,
|
||||
@@ -38,16 +59,6 @@ typedef enum {
|
||||
DEV_TYPE_RAIN_SENSOR,
|
||||
}DevType_m;
|
||||
|
||||
typedef enum {
|
||||
CATONE_COMM,
|
||||
ETH_COMM,
|
||||
}CommType_m;
|
||||
|
||||
typedef enum {
|
||||
LORA_COMM,
|
||||
RS485CH1_COMM,
|
||||
RS485CH2_COMM
|
||||
}SensorComm_m;
|
||||
|
||||
typedef enum {
|
||||
COMM_UNIT_CMD_REG,
|
||||
@@ -271,7 +282,10 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
uint32_t SavFlag; //存储标志
|
||||
CommType_m Comm; //网关通讯方式
|
||||
Channel_m Much; //主上报通道
|
||||
Channel_m Auch; //辅助上报通道
|
||||
Channel_m Duch; //调试打印/上送通道
|
||||
uint8_t CuchMask; //通讯单元通道位掩码
|
||||
uint8_t GwMac[6]; //网关mac
|
||||
LTENetPara_t LTENet; //Cat1/4G服务器参数
|
||||
EthNetPara_t EthNet; //以太网网络参数
|
||||
@@ -280,7 +294,6 @@ typedef struct {
|
||||
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;
|
||||
@@ -288,23 +301,27 @@ typedef struct {
|
||||
|
||||
struct GateWay_t{
|
||||
bool TimeSyncFlag; //时间同步标志
|
||||
bool SvrRegFlag; //服务器注册标志
|
||||
bool MuchRegFlag; //主上报注册标志
|
||||
bool AuchRegFlag; //辅助上报注册标志
|
||||
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; //接收到服务器回调
|
||||
DataRevCallBack MuchRevCallBack; //主上报接收回调
|
||||
DataRevCallBack AuchRevCallBack; //辅上报接收回调
|
||||
DataRevResCallBack CommUnitRevCallBack; //通讯单元接收回调
|
||||
rt_mq_t NetSendData_MQ; //网络发送数据队列,第一个字节用于存储消息长度, 第二字节存储命令字,后为数据
|
||||
rt_mq_t ChMQ[6]; //每个通道独立队列,索引=Channel_m
|
||||
rt_mq_t LoraRev_MQ; //Lora接收消息队列,第一个字节用于存储消息长度,后为数据
|
||||
rt_mutex_t UartRevMutex;
|
||||
rt_mutex_t EthTxMutex;
|
||||
|
||||
uint8_t BatteryReadDlyCnt; //读取电压延时,单位秒,防止4G发送拉低电池电压,造成断电误报
|
||||
};
|
||||
|
||||
int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
int MuchRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
int AuchRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen);
|
||||
uint16_t CRC_Modbus(uint16_t wBase, __IO uint8_t *para, uint16_t length);
|
||||
uint8_t AsciiToHex(char *ASCData, uint8_t *HexData, uint8_t sLen);
|
||||
void HexToAscii(uint8_t *HexData, char *ASCData, uint8_t sLen);
|
||||
|
||||
@@ -288,7 +288,10 @@ void CatOneAtCmdAnalyze(char *RxBuff)
|
||||
memset(hData, 0x00, 60);
|
||||
hLen = AsciiToHex(rData, hData, rLen);
|
||||
CatSendErrCnt = 0;
|
||||
CatOne.GateWay->SvrRevCallBack(CatOne.GateWay, hData, hLen);
|
||||
if(CatOne.GateWay->ConfigPara.Much == CH_CAT1)
|
||||
CatOne.GateWay->MuchRevCallBack(CatOne.GateWay, hData, hLen);
|
||||
else
|
||||
CatOne.GateWay->AuchRevCallBack(CatOne.GateWay, hData, hLen);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
@@ -338,6 +341,7 @@ void CatOneAtCmdSend(CatOneATCMD_m Cmd, uint32_t Dly, CatOneStatus_m NextStatus)
|
||||
CatOne.NextStatus = NextStatus;
|
||||
}
|
||||
|
||||
|
||||
static int GateWayRegister(uint8_t *TxBuff)
|
||||
{
|
||||
uint16_t UnitCommCnt = 0;
|
||||
@@ -430,21 +434,25 @@ void CatOneLoopHandler(void)
|
||||
|
||||
case CAT_ONE_WAIT_CONN:
|
||||
if(CatOne.TcpConnFlag) {
|
||||
if(CatOne.GateWay->SvrRegFlag == false)
|
||||
if(CatOne.GateWay->ConfigPara.Much != CH_CAT1) {
|
||||
GateWayRegister(Payload);
|
||||
CatOneTxLen = NetCommOrgData(CatOne.GateWay, Payload, CatOneTxBuff);
|
||||
CatOne.Cat1Status = CAT_ONE_SEND_DATA;
|
||||
}
|
||||
else {
|
||||
CatOne.Cat1Status = CAT_ONE_REG_SVR;
|
||||
else
|
||||
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CAT_ONE_REG_SVR:
|
||||
ret = GateWayRegister(CatOneTxBuff);
|
||||
rt_mq_send(CatOne.GateWay->NetSendData_MQ, CatOneTxBuff, ret);
|
||||
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
|
||||
GateWayRegister(Payload);
|
||||
CatOneTxLen = NetCommOrgData(CatOne.GateWay, Payload, CatOneTxBuff);
|
||||
CatOne.Cat1Status = CAT_ONE_SEND_DATA;
|
||||
break;
|
||||
|
||||
case CAT_ONE_WAIT_SEND:
|
||||
result = rt_mq_recv(CatOne.GateWay->NetSendData_MQ, Payload, CAT_ONE_REV_LEN_MAX, 1000);
|
||||
result = rt_mq_recv(ChannelMQ(*CatOne.GateWay, CH_CAT1), Payload, CAT_ONE_REV_LEN_MAX, 1000);
|
||||
if(result == RT_EOK) {
|
||||
CatSendErrCnt = 0;
|
||||
CatOneTxLen = NetCommOrgData(CatOne.GateWay, Payload, CatOneTxBuff);
|
||||
@@ -482,6 +490,10 @@ void CatOneLoopHandler(void)
|
||||
break;
|
||||
|
||||
case CAT_ONE_REV_DATA:
|
||||
if(CatOne.GateWay->ConfigPara.Much != CH_CAT1) {
|
||||
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
|
||||
break;
|
||||
}
|
||||
result = rt_sem_take(CatOneRev_Sem, CatOne.CatOne1mSDelayCnt);
|
||||
if(result != RT_EOK) {
|
||||
if(CatOne.TcpConnFlag == false) {
|
||||
@@ -492,7 +504,7 @@ void CatOneLoopHandler(void)
|
||||
else {
|
||||
Cat1RevErrCnt = 0;
|
||||
}
|
||||
if(CatOne.GateWay->SvrRegFlag == false)
|
||||
if(CatOne.GateWay->MuchRegFlag == false)
|
||||
CatOne.Cat1Status = CAT_ONE_OFF;
|
||||
else
|
||||
CatOne.Cat1Status = CAT_ONE_WAIT_SEND;
|
||||
@@ -509,7 +521,6 @@ void CatOneLoopHandler(void)
|
||||
rt_thread_delay(3000);
|
||||
CAT1_PWR_KEY_SET();
|
||||
CatSendErrCnt = 0;
|
||||
CatOne.GateWay->SvrRegFlag = false;
|
||||
CAT1_DBG_LOG("Cat1 Power Off!\r\n");
|
||||
CatOne.Cat1Status = CAT_ONE_IDEL;
|
||||
CatOne.ResetDelayCnt = CATONE_RESET_DELAY_TIME_MAX;
|
||||
@@ -518,8 +529,8 @@ void CatOneLoopHandler(void)
|
||||
|
||||
case CAT_ONE_RESET:
|
||||
CatSendErrCnt = 0;
|
||||
CatOne.GateWay->SvrRegFlag = false;
|
||||
CAT1_DBG_LOG("Cat1 Reset!\r\n");
|
||||
DbgOrCat1Uart_Config(115200);
|
||||
CAT1_ON();
|
||||
CAT1_RESET_CLR();
|
||||
CAT1_PWR_KEY_SET();
|
||||
@@ -536,11 +547,12 @@ void CatOneLoopHandler(void)
|
||||
}
|
||||
}
|
||||
|
||||
bool CatOneEthSendQueue(uint8_t *sData, uint16_t sLen)
|
||||
bool UploadSend(uint8_t *sData, uint16_t sLen)
|
||||
{
|
||||
if(CatOne.GateWay->SvrRegFlag == false)
|
||||
return false;
|
||||
rt_mq_send(CatOne.GateWay->NetSendData_MQ, sData, sLen);
|
||||
rt_mq_send(ChannelMQ(*CatOne.GateWay, CatOne.GateWay->ConfigPara.Much), sData, sLen);
|
||||
if(CatOne.GateWay->ConfigPara.Auch != CH_NULL && CatOne.GateWay->ConfigPara.Auch != CatOne.GateWay->ConfigPara.Much) {
|
||||
rt_mq_send(ChannelMQ(*CatOne.GateWay, CatOne.GateWay->ConfigPara.Auch), sData, sLen);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -549,7 +561,8 @@ static void CatOneInit(GateWayPara GateWay)
|
||||
memset(&CatOne, 0x00, sizeof(CatOne_t));
|
||||
CatOne.Cat1Status = CAT_ONE_RESET;
|
||||
CatOne.GateWay = GateWay;
|
||||
CatOne.CatOneRevCallBack = GateWay->SvrRevCallBack;
|
||||
CatOne.CatOneRevCallBack = (GateWay->ConfigPara.Much == CH_CAT1) ?
|
||||
GateWay->MuchRevCallBack : GateWay->AuchRevCallBack;
|
||||
}
|
||||
|
||||
void CatOneRev_Thread_Entry(void *parameter)
|
||||
@@ -600,7 +613,7 @@ void CatOne_Thread_Entry(void *parameter)
|
||||
rt_kprintf("CatOne Thread is running!\r\n");
|
||||
|
||||
while(1) {
|
||||
if(GateWay->ConfigPara.Comm != CATONE_COMM) {
|
||||
if(!ChannelIsActive(GateWay->ConfigPara, CH_CAT1)) {
|
||||
rt_thread_delay(100);
|
||||
continue;
|
||||
}
|
||||
@@ -646,6 +659,7 @@ void CatReadImeiOrSim(char *Imei, char *Sim)
|
||||
void CatOneTriggerRegister(void)
|
||||
{
|
||||
CatOneStop();
|
||||
DbgOrCat1Uart_Config(115200);
|
||||
CAT1_ON();
|
||||
CatOneReset();
|
||||
}
|
||||
|
||||
@@ -109,11 +109,19 @@ void EthLoopHandler(void)
|
||||
}
|
||||
if(ETH_LINK_GET() == Reset) {
|
||||
ETH_DBG_LOG("ETH Link OK!\r\n");
|
||||
if(Eth.GateWay->SvrRegFlag == false) {
|
||||
Eth.Status = ETH_REG_SVR;
|
||||
if(Eth.GateWay->ConfigPara.Much != CH_ETH) {
|
||||
GateWayRegister(Payload);
|
||||
Eth.TxLen = NetCommOrgData(Eth.GateWay, Payload, Eth.TxBuff);
|
||||
HexToAscii(Eth.TxBuff, CommUnitSendASCII, Eth.TxLen);
|
||||
CommUnitSendASCII[Eth.TxLen * 2] = 0;
|
||||
EthUartSend((uint8_t *)CommUnitSendASCII, Eth.TxLen * 2);
|
||||
ETH_DBG_LOG("Eth Send Reg: %s\r\n", CommUnitSendASCII);
|
||||
Eth.Status = ETH_WAIT_RECV;
|
||||
Eth.RecvTimeoutCnt = 0;
|
||||
Eth.SendRetryCnt = 0;
|
||||
}
|
||||
else {
|
||||
Eth.Status = ETH_WAIT_SEND;
|
||||
Eth.Status = ETH_REG_SVR;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -132,18 +140,22 @@ void EthLoopHandler(void)
|
||||
ETH_DBG_LOG("ETH First Register, waiting for system stable...\r\n");
|
||||
rt_thread_delay(ETH_FIRST_REG_DELAY);
|
||||
Eth.FirstRegFlag = false;
|
||||
Eth.SendRetryCnt = 0;
|
||||
}
|
||||
|
||||
uint8_t ret = GateWayRegister(Eth.TxBuff);
|
||||
rt_mq_send(Eth.GateWay->NetSendData_MQ, Eth.TxBuff, ret);
|
||||
ETH_DBG_LOG("ETH Register Server...\r\n");
|
||||
Eth.Status = ETH_WAIT_SEND;
|
||||
Eth.SendRetryCnt = 0;
|
||||
GateWayRegister(Payload);
|
||||
Eth.TxLen = NetCommOrgData(Eth.GateWay, Payload, Eth.TxBuff);
|
||||
HexToAscii(Eth.TxBuff, CommUnitSendASCII, Eth.TxLen);
|
||||
CommUnitSendASCII[Eth.TxLen * 2] = 0;
|
||||
EthUartSend((uint8_t *)CommUnitSendASCII, Eth.TxLen * 2);
|
||||
ETH_DBG_LOG("Eth Send Reg: %s\r\n", CommUnitSendASCII);
|
||||
Eth.Status = ETH_WAIT_RECV;
|
||||
Eth.RecvTimeoutCnt = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case ETH_WAIT_SEND:
|
||||
result = rt_mq_recv(Eth.GateWay->NetSendData_MQ, Payload, ETH_RX_LEN_MAX, 100);
|
||||
result = rt_mq_recv(ChannelMQ(*Eth.GateWay, CH_ETH), Payload, ETH_RX_LEN_MAX, 100);
|
||||
if(result == RT_EOK) {
|
||||
Eth.TxLen = NetCommOrgData(Eth.GateWay, Payload, Eth.TxBuff);
|
||||
Eth.Status = ETH_SEND_DATA;
|
||||
@@ -174,6 +186,10 @@ void EthLoopHandler(void)
|
||||
break;
|
||||
|
||||
case ETH_WAIT_RECV:
|
||||
if(Eth.GateWay->ConfigPara.Much != CH_ETH) {
|
||||
Eth.Status = ETH_WAIT_SEND;
|
||||
break;
|
||||
}
|
||||
rt_thread_delay(1);
|
||||
Eth.RecvTimeoutCnt++;
|
||||
|
||||
@@ -185,7 +201,7 @@ void EthLoopHandler(void)
|
||||
Eth.Status = ETH_OFF;
|
||||
}
|
||||
else {
|
||||
if(Eth.GateWay->SvrRegFlag == false) {
|
||||
if(Eth.GateWay->MuchRegFlag == false) {
|
||||
Eth.Status = ETH_REG_SVR;
|
||||
}
|
||||
else {
|
||||
@@ -199,7 +215,7 @@ void EthLoopHandler(void)
|
||||
Eth.Status = ETH_OFF;
|
||||
}
|
||||
|
||||
if(Eth.GateWay->SvrRegFlag == true) {
|
||||
if(Eth.GateWay->MuchRegFlag == true) {
|
||||
ETH_DBG_LOG("ETH Register Success!\r\n");
|
||||
Eth.Status = ETH_WAIT_SEND;
|
||||
Eth.RecvTimeoutCnt = 0;
|
||||
@@ -210,7 +226,6 @@ void EthLoopHandler(void)
|
||||
|
||||
case ETH_OFF:
|
||||
ETH_DBG_LOG("ETH Power Off!\r\n");
|
||||
Eth.GateWay->SvrRegFlag = false;
|
||||
Eth.Status = ETH_IDEL;
|
||||
Eth.ResetDelayCnt = ETH_RESET_DELAY_TIME_MAX;
|
||||
break;
|
||||
@@ -245,7 +260,7 @@ void EthOverHandler(void)
|
||||
if(EthRevTimeOutCnt > 0)
|
||||
EthRevTimeOutCnt--;
|
||||
|
||||
if(EthRxLen > 5 && EthRevTimeOutCnt == 0) {
|
||||
if(EthRxLen > 0 && EthRevTimeOutCnt == 0) {
|
||||
EthRevTimeOutCnt = 20;
|
||||
rt_sem_release(EthIRQ_Sem);
|
||||
}
|
||||
@@ -263,14 +278,21 @@ static void EthRev_Thread_Entry(void *parameter)
|
||||
|
||||
while(1) {
|
||||
result = rt_sem_take(EthIRQ_Sem, 500);
|
||||
if(result == RT_EOK) {
|
||||
if(result == RT_EOK || EthRxLen > 1) {
|
||||
if(EthRxLen == 0) continue;
|
||||
memcpy(RxBuffTemp, EthRxBuff, EthRxLen);
|
||||
RxBuffTemp[EthRxLen] = 0;
|
||||
ETH_DBG_LOG("Eth Rev: %s\r\n", RxBuffTemp);
|
||||
memset(HexData, 0x00, EthRxLen / 2);
|
||||
uint8_t ret = AsciiToHex(RxBuffTemp, HexData, EthRxLen);
|
||||
if(ret > 0)
|
||||
GateWay->SvrRevCallBack(GateWay, HexData, ret);
|
||||
if(ret > 0 && HexData[0] == 0x7A) {
|
||||
if(GateWay->ConfigPara.Much == CH_ETH)
|
||||
GateWay->MuchRevCallBack(GateWay, HexData, ret);
|
||||
else
|
||||
GateWay->AuchRevCallBack(GateWay, HexData, ret);
|
||||
}
|
||||
else if(EthRxLen > 1) {
|
||||
DebugAnalyze(GateWay, (uint8_t *)RxBuffTemp, EthRxLen);
|
||||
}
|
||||
memset(EthRxBuff, 0x00, ETH_RX_LEN_MAX);
|
||||
EthRxLen = 0;
|
||||
}
|
||||
@@ -302,7 +324,7 @@ void Eth_Thread_Entry(void *parameter)
|
||||
rt_kprintf("Eth Thread is running!\r\n");
|
||||
|
||||
while(1) {
|
||||
if(GateWay->ConfigPara.Comm != ETH_COMM) {
|
||||
if(!ChannelIsActive(GateWay->ConfigPara, CH_ETH)) {
|
||||
rt_thread_delay(100);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ void LoraIRQ_Thread_Entry(void *parameter)
|
||||
|
||||
Debug_Printf("LoraRev Thread is running!\r\n");
|
||||
while(1) {
|
||||
if(GateWay->ConfigPara.Lora.OnOff == false) {
|
||||
if(GateWay->ConfigPara.Lora.OnOff == false || !ChannelIsActive(GateWay->ConfigPara, CH_LORA)) {
|
||||
rt_thread_delay(100);
|
||||
continue;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ void Lora_Thread_Entry(void *parameter)
|
||||
Debug_Printf("Lora Thread is running!\r\n");
|
||||
#ifdef LORA_LOWPOWER
|
||||
while(1) {
|
||||
if(GateWay->ConfigPara.Lora.OnOff == false) {
|
||||
if(GateWay->ConfigPara.Lora.OnOff == false || !ChannelIsActive(GateWay->ConfigPara, CH_LORA)) {
|
||||
rt_thread_delay(100);
|
||||
continue;
|
||||
}
|
||||
@@ -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); //发送离线消息
|
||||
UploadSend(MegData, 10); //发送离线消息
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,6 +168,13 @@ void Lora_Thread_Entry(void *parameter)
|
||||
if(UnitCommReadDelayCnt < GateWay->ConfigPara.CommUnitReadInterval)
|
||||
UnitCommReadDelayCnt++;
|
||||
|
||||
{
|
||||
uint8_t sData[256];
|
||||
if(rt_mq_recv(ChannelMQ(*GateWay, CH_LORA), sData, 256, 0) == RT_EOK) {
|
||||
uint16_t len = (sData[0] | (sData[1] << 8)) + 3;
|
||||
Sx1276LoRaSendBuffer(sData, len);
|
||||
}
|
||||
}
|
||||
result = rt_mq_recv(GateWay->LoraRev_MQ, Payload, 256, 1000);
|
||||
if(result == RT_EOK) {
|
||||
int ret = GateWay->CommUnitRevCallBack(GateWay, &Payload[1], Payload[0], Sx1276LoRaSendBuffer);
|
||||
@@ -190,7 +197,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); //发送离线消息
|
||||
UploadSend(MegData, 10); //发送离线消息
|
||||
}
|
||||
}
|
||||
UnitCommSendFlag = false;
|
||||
|
||||
@@ -7,6 +7,20 @@
|
||||
#include <stdlib.h>
|
||||
#include "sx127x.h"
|
||||
|
||||
const char *ChannelName(Channel_m ch)
|
||||
{
|
||||
switch(ch) {
|
||||
case CH_NULL: return "null";
|
||||
case CH_DBG: return "dbg";
|
||||
case CH_RS485_1: return "ch1";
|
||||
case CH_RS485_2: return "ch2";
|
||||
case CH_ETH: return "eth";
|
||||
case CH_LORA: return "lora";
|
||||
case CH_CAT1: return "cat1";
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
||||
//传感器对应的数据长度
|
||||
const uint8_t SensorTypeDataLen[] = {
|
||||
0, //0x0000-保留
|
||||
@@ -570,7 +584,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->MuchRegFlag) { //网关已注册,向服务发送新设备添加指令
|
||||
PayLoadLen = (GateWay->ConfigPara.CommUnitArray[i].SensorN * 6) + 2;
|
||||
MegData = rt_malloc(PayLoadLen + 3);
|
||||
MegData[0] = PayLoadLen & 0x00ff;;
|
||||
@@ -582,7 +596,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
|
||||
{
|
||||
memcpy(&MegData[5], GateWay->ConfigPara.CommUnitArray[i].Mac[k], 6);
|
||||
}
|
||||
CatOneEthSendQueue(MegData, PayLoadLen+5);
|
||||
UploadSend(MegData, PayLoadLen+5);
|
||||
rt_free(MegData);
|
||||
}
|
||||
return 0xff;
|
||||
@@ -722,7 +736,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
|
||||
MegData = rt_malloc(512);
|
||||
CommUintLen = CommUintOrgData(GateWay, &GateWay->ConfigPara.CommUnitArray[CommUnitIdx], &GateWay->CUDataArray[CommUnitIdx], MegData);
|
||||
//AddLog(&MegData[2], CommUintLen);
|
||||
CatOneEthSendQueue(MegData, CommUintLen);
|
||||
UploadSend(MegData, CommUintLen);
|
||||
rt_free(MegData);
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
break;}
|
||||
@@ -785,7 +799,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
|
||||
MegData[7] = CUHeader->DevMac[4];
|
||||
MegData[8] = CUHeader->DevMac[5];
|
||||
MegData[9] = PayLoad[0];
|
||||
CatOneEthSendQueue(MegData, 10);
|
||||
UploadSend(MegData, 10);
|
||||
rt_free(MegData);
|
||||
GateWay->ConfigPara.CommUnitArray[CommUnitIdx].ContLaser = false;
|
||||
MAIN_DBG_LOG("CommUnit The laser has been turned off! Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n",
|
||||
@@ -804,7 +818,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
|
||||
MegData[7] = CUHeader->DevMac[4];
|
||||
MegData[8] = CUHeader->DevMac[5];
|
||||
MegData[9] = PayLoad[0];
|
||||
CatOneEthSendQueue(MegData, 10);
|
||||
UploadSend(MegData, 10);
|
||||
rt_free(MegData);
|
||||
GateWay->ConfigPara.CommUnitArray[CommUnitIdx].ContLaser = false;
|
||||
MAIN_DBG_LOG("CommUnit The laser has been activated! Mac:%02X-%02X-%02X-%02X-%02X-%02X\r\n",
|
||||
@@ -869,7 +883,7 @@ int CommUnitAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, SendData
|
||||
rLen, 数据长度输入接口
|
||||
* 返 回 值: 无
|
||||
*****************************************************************************************/
|
||||
int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
static int _NetRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen, bool *pRegFlag)
|
||||
{
|
||||
uint16_t check,crc16;
|
||||
uint8_t *Data;
|
||||
@@ -933,16 +947,17 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
switch(NCHeader->Cmd) {
|
||||
case NET_COMM_CMD_REG:{
|
||||
if(*Data == 1) { //注册成功
|
||||
GateWay->SvrRegFlag = true;
|
||||
//memcpy(GateWay->SvrMac, NCHeader->SvrMac, 6);
|
||||
*pRegFlag = true;
|
||||
memset(GateWay->SvrMac, 0x00, 6);
|
||||
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
|
||||
MAIN_DBG_LOG("Gateway Registered...\r\n");
|
||||
MAIN_DBG_LOG("Gateway %s Registered...\r\n",
|
||||
pRegFlag == &GateWay->MuchRegFlag ? "Much" : "Auch");
|
||||
}
|
||||
else {
|
||||
GateWay->SvrRegFlag = false;
|
||||
*pRegFlag = false;
|
||||
memset(GateWay->SvrMac, 0x00, 6);
|
||||
MAIN_DBG_LOG("Gateway Register Failed....\r\n");
|
||||
MAIN_DBG_LOG("Gateway %s Register Failed....\r\n",
|
||||
pRegFlag == &GateWay->MuchRegFlag ? "Much" : "Auch");
|
||||
}
|
||||
break;}
|
||||
|
||||
@@ -954,7 +969,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
MegData[2] = NET_COMM_CMD_CAIL;
|
||||
MegData[3] = 1;
|
||||
sLen = 4;
|
||||
CatOneEthSendQueue(MegData, sLen);
|
||||
UploadSend(MegData, sLen);
|
||||
rt_free(MegData);
|
||||
//开始校准
|
||||
memcpy(&CommUintMac[0], Data, 6);
|
||||
@@ -1060,7 +1075,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
MegData[2] = NET_COMM_CMD_READ_GW_INFO;//指令
|
||||
MegData[3] = SensorCnt&0xFF;
|
||||
MegData[4] = (SensorCnt >> 8)&0xFF;
|
||||
CatOneEthSendQueue(MegData, sLen);
|
||||
UploadSend(MegData, sLen);
|
||||
rt_free(MegData);
|
||||
break;
|
||||
}
|
||||
@@ -1073,7 +1088,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
MegData[2] = NET_COMM_CMD_GW_PARA_CONFIG;
|
||||
MegData[3] = 1;
|
||||
sLen = 4;
|
||||
CatOneEthSendQueue(MegData, sLen);
|
||||
UploadSend(MegData, sLen);
|
||||
rt_free(MegData);
|
||||
MAIN_DBG_LOG("AThe server sends down the gateway parameter configuration...\r\n");
|
||||
break;}
|
||||
@@ -1103,7 +1118,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
sLen += 6;
|
||||
memcpy(&MegData[sLen], &HisData[7], ret - 7);
|
||||
sLen += ret - 7;
|
||||
CatOneEthSendQueue(MegData, sLen);
|
||||
UploadSend(MegData, sLen);
|
||||
rt_free(MegData);
|
||||
rt_free(HisData);
|
||||
rt_thread_delay(10);
|
||||
@@ -1163,7 +1178,7 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
MegData[2] = NET_COMM_CMD_LP_DEV_CONFIG;
|
||||
MegData[3] = 1;
|
||||
sLen = 4;
|
||||
CatOneEthSendQueue(MegData, sLen);
|
||||
UploadSend(MegData, sLen);
|
||||
rt_free(MegData);
|
||||
break;}
|
||||
|
||||
@@ -1227,3 +1242,13 @@ int Cat1EthRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MuchRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
{
|
||||
return _NetRevCallBack(GateWay, rData, rLen, &GateWay->MuchRegFlag);
|
||||
}
|
||||
|
||||
int AuchRevCallBack(GateWayPara GateWay, uint8_t *rData, uint16_t rLen)
|
||||
{
|
||||
return _NetRevCallBack(GateWay, rData, rLen, &GateWay->AuchRegFlag);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ static void update_on_start(uint8_t* frame, int len, uint8_t* pload, int size)
|
||||
|
||||
boot_para_t cfg = {0};
|
||||
|
||||
cfg.AppFlag = 0;
|
||||
cfg.AppFlag = APP_BOOT_UPGRADE_FLAG;
|
||||
cfg.UpdateFlag = APP_UPDATE_FLAG;
|
||||
cfg.Crc32Check = pReq->AppCrc32;
|
||||
cfg.PackageNum = pReq->PackageNum;
|
||||
@@ -127,6 +127,7 @@ static void update_on_start(uint8_t* frame, int len, uint8_t* pload, int size)
|
||||
|
||||
update_send_cmd(0x01, 1, pReq->PackageNum);
|
||||
|
||||
Ddl_Delay1ms(1000);
|
||||
//重启进入BOOT
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
@@ -302,7 +303,7 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP
|
||||
RS485Ch->CUPara.Para.BatLevel = GateWay->Battery;
|
||||
CommUintLen = CommUintOrgData(GateWay, &RS485Ch->CUPara.Para, &SCPara->SensorData, CommUintData);
|
||||
//AddLog(&CommUintData[2], CommUintLen - 2);
|
||||
CatOneEthSendQueue(CommUintData, CommUintLen);
|
||||
UploadSend(CommUintData, CommUintLen);
|
||||
if(RS485Ch == &GateWay->ConfigPara.Rs485Ch1) {
|
||||
MAIN_DBG_LOG("InCommUint1 Send Meg...\r\n");
|
||||
}
|
||||
@@ -426,7 +427,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); //发送离线消息
|
||||
UploadSend(MegData, 10); //发送离线消息
|
||||
}
|
||||
}
|
||||
SCPara->SendUnitCommIdx++;
|
||||
@@ -469,7 +470,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;
|
||||
@@ -477,6 +478,18 @@ void RS485Ch1_Thread_Entry(void *parameter)
|
||||
|
||||
update_init(RS485Ch1UartSend);
|
||||
while(1) {
|
||||
if(!ChannelIsActive(GateWay->ConfigPara, CH_RS485_1)
|
||||
&& !GateWay->ConfigPara.Rs485Ch1.UpgradeEnable) {
|
||||
rt_thread_delay(100);
|
||||
continue;
|
||||
}
|
||||
{
|
||||
uint8_t sData[512];
|
||||
if(rt_mq_recv(ChannelMQ(*GateWay, CH_RS485_1), sData, 512, 0) == RT_EOK) {
|
||||
uint16_t len = (sData[0] | (sData[1] << 8)) + 3;
|
||||
RS485Ch1UartSend(sData, len);
|
||||
}
|
||||
}
|
||||
RS485LoopHandler(GateWay, RS485Ch, SCPara);
|
||||
//rt_thread_delay(10);
|
||||
}
|
||||
@@ -533,10 +546,22 @@ 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) {
|
||||
if(!ChannelIsActive(GateWay->ConfigPara, CH_RS485_2)
|
||||
&& !GateWay->ConfigPara.Rs485Ch2.UpgradeEnable) {
|
||||
rt_thread_delay(100);
|
||||
continue;
|
||||
}
|
||||
{
|
||||
uint8_t sData[512];
|
||||
if(rt_mq_recv(ChannelMQ(*GateWay, CH_RS485_2), sData, 512, 0) == RT_EOK) {
|
||||
uint16_t len = (sData[0] | (sData[1] << 8)) + 3;
|
||||
RS485Ch2UartSend(sData, len);
|
||||
}
|
||||
}
|
||||
RS485LoopHandler(GateWay, RS485Ch, SCPara);
|
||||
//rt_thread_delay(10);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "bsp.h"
|
||||
#include "main.h"
|
||||
#include "rtthread.h"
|
||||
#include "ff.h"
|
||||
|
||||
@@ -869,6 +870,9 @@ static void GPIO_Config(void)
|
||||
// PORT_Init(RS485_CH2_VOL_CTRL_PORT, RS485_CH2_VOL_CTRL_PIN, &stcPortInit);
|
||||
// RS485_CH1_VOL_5V();
|
||||
|
||||
PORT_Init(DBG_OR_CAT1_CTRL_PORT, DBG_OR_CAT1_CTRL_PIN, &stcPortInit);
|
||||
DBG_ON();
|
||||
|
||||
PORT_Init(CAT1_PWR_KEY_PORT, CAT1_PWR_KEY_PIN, &stcPortInit);
|
||||
CAT1_PWR_KEY_SET();
|
||||
|
||||
@@ -911,10 +915,6 @@ static void GPIO_Config(void)
|
||||
PORT_Init(LORA_POW_PORT, LORA_POW_PIN, &stcPortInit);
|
||||
LORA_POW_OFF();
|
||||
|
||||
//stcPortInit.enPullUp = Enable;
|
||||
PORT_Init(DBG_OR_CAT1_CTRL_PORT, DBG_OR_CAT1_CTRL_PIN, &stcPortInit);
|
||||
DBG_ON();
|
||||
|
||||
stcPortInit.enPullUp = Enable;
|
||||
stcPortInit.enPinMode = Pin_Mode_In;
|
||||
PORT_Init(ETH_LINK_PORT, ETH_LINK_PIN, &stcPortInit);
|
||||
@@ -1714,7 +1714,7 @@ void BSP_Init(void)
|
||||
SystemClockConfig();
|
||||
Xtal32_ClockConfig();
|
||||
|
||||
DbgOrCat1Uart_Config(500000);
|
||||
DbgOrCat1Uart_Config(115200);
|
||||
Eth_Config(115200);
|
||||
// RS485Ch1_Config(9600);
|
||||
// RS485Ch2_Config(9600);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "main.h"
|
||||
#include "CatOneTask.h"
|
||||
#include "EthTask.h"
|
||||
@@ -75,24 +73,6 @@ void MainDBGOnOff(bool OnOff)
|
||||
Debug_Printf("\r\nMain Display Disable!\r\n\r\n");
|
||||
}
|
||||
|
||||
#if 0
|
||||
uint32_t SDStartBlock;
|
||||
uint8_t TestData[10 * 512];
|
||||
uint8_t ADBuff[10 * 512];
|
||||
|
||||
void SDCardTest(void)
|
||||
{
|
||||
SDStartBlock = 0;
|
||||
SDCardReadBlocks(SDStartBlock, 10, TestData);
|
||||
if(TestData[0] != 0xAA) {
|
||||
SDCardErase(SDStartBlock, 10);
|
||||
memset(ADBuff, 0xAA, 10 * 512);
|
||||
SDCardWriteBlocks(SDStartBlock, 10, (uint8_t *)&ADBuff);
|
||||
}
|
||||
SDCardReadBlocks(SDStartBlock, 10, TestData);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void GateWayInit(void)
|
||||
{
|
||||
@@ -103,6 +83,7 @@ void GateWayInit(void)
|
||||
memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t));
|
||||
boot_para_t bootParam;
|
||||
dev_boot_read_param(&bootParam);
|
||||
rt_kprintf("AppFlag: 0x%08x\r\n", bootParam.AppFlag);
|
||||
if(bootParam.AppFlag == APP_BOOT_UPGRADE_FLAG) {
|
||||
rt_kprintf("Boot upgrade detected, erasing external Flash...\r\n");
|
||||
SpiFlashEraseChip();
|
||||
@@ -114,7 +95,10 @@ void GateWayInit(void)
|
||||
if(GateWay.ConfigPara.SavFlag != LOG_SAV_FLAG) {
|
||||
memset((uint8_t *)&GateWay.ConfigPara, 0x00, sizeof(GWConfigPara_t));
|
||||
GateWay.ConfigPara.SavFlag = LOG_SAV_FLAG;
|
||||
GateWay.ConfigPara.Comm = CATONE_COMM;
|
||||
GateWay.ConfigPara.Much = CH_CAT1;
|
||||
GateWay.ConfigPara.Auch = CH_NULL;
|
||||
GateWay.ConfigPara.Duch = CH_ETH;
|
||||
GateWay.ConfigPara.CuchMask = CUCH_LORA;
|
||||
#if MAC_ADDR_TYPE == 0//测试服务器
|
||||
GateWay.ConfigPara.LTENet.DestAddr[0] = 39;
|
||||
GateWay.ConfigPara.LTENet.DestAddr[1] = 106;
|
||||
@@ -154,53 +138,39 @@ void GateWayInit(void)
|
||||
GateWay.ConfigPara.Lora.FreqCent = FREQ_CENT;
|
||||
|
||||
GateWay.ConfigPara.OutageFlag = false;
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
|
||||
|
||||
#if MAC_ADDR_TYPE == 0
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_Test, 6);
|
||||
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;
|
||||
// GateWay.ConfigPara.DebugChannel = DEBUG_CH_DBG;
|
||||
#elif MAC_ADDR_TYPE == 2
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL2, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
// GateWay.ConfigPara.DebugChannel = DEBUG_CH_DBG;
|
||||
#elif MAC_ADDR_TYPE == 3
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL3, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 4
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL4, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 5
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL5, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 6
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL6, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 7
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL7, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 8
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL8, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 9
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL9, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#elif MAC_ADDR_TYPE == 10
|
||||
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL10, 6);
|
||||
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
|
||||
#endif
|
||||
}
|
||||
|
||||
if(GateWay.ConfigPara.OutageFlag != true && GateWay.ConfigPara.OutageFlag != false)
|
||||
GateWay.ConfigPara.OutageFlag = false;
|
||||
|
||||
GateWay.SvrRegFlag = false;
|
||||
GateWay.MuchRegFlag = false;
|
||||
memset(GateWay.SvrMac, 0x00, 6);
|
||||
|
||||
if(GateWay.ConfigPara.DebugChannel == DEBUG_CH_RS485_1) {
|
||||
if(ChannelIsActive(GateWay.ConfigPara, CH_RS485_1)) {
|
||||
GateWay.ConfigPara.Rs485Ch1.Enable = true;
|
||||
GateWay.ConfigPara.Rs485Ch1.BaudRate = 500000;
|
||||
}
|
||||
@@ -208,7 +178,7 @@ void GateWayInit(void)
|
||||
GateWay.ConfigPara.Rs485Ch1.BaudRate = 500000;
|
||||
RS485Ch1_Config(GateWay.ConfigPara.Rs485Ch1.BaudRate);
|
||||
|
||||
if(GateWay.ConfigPara.DebugChannel == DEBUG_CH_RS485_2) {
|
||||
if(ChannelIsActive(GateWay.ConfigPara, CH_RS485_2)) {
|
||||
GateWay.ConfigPara.Rs485Ch2.Enable = true;
|
||||
GateWay.ConfigPara.Rs485Ch2.BaudRate = 500000;
|
||||
}
|
||||
@@ -288,16 +258,11 @@ void GateWayInit(void)
|
||||
}
|
||||
else
|
||||
rt_kprintf("History Num: 0\r\n");
|
||||
if(GateWay.ConfigPara.Comm == CATONE_COMM) {
|
||||
DbgOrCat1Uart_Config(115200);
|
||||
CAT1_ON();
|
||||
}
|
||||
else {
|
||||
DBG_ON();
|
||||
ETH_ON();
|
||||
rt_thread_delay(1000);
|
||||
ETHReset();
|
||||
}
|
||||
bool cat1Active = ChannelIsActive(GateWay.ConfigPara, CH_CAT1);
|
||||
bool ethActive = ChannelIsActive(GateWay.ConfigPara, CH_ETH);
|
||||
if(cat1Active) { DbgOrCat1Uart_Config(115200); CAT1_ON(); }
|
||||
else { DBG_ON(); DbgOrCat1Uart_Config(500000); }
|
||||
if(ethActive) { ETH_ON(); rt_thread_delay(1000); ETHReset(); }
|
||||
}
|
||||
|
||||
void OutageUpdate(uint8_t AlarmType, bool AlarmState, uint8_t Batt)
|
||||
@@ -313,7 +278,7 @@ void OutageUpdate(uint8_t AlarmType, bool AlarmState, uint8_t Batt)
|
||||
Alarm->AlarmType = AlarmType;
|
||||
Alarm->AlarmState = AlarmState;
|
||||
Alarm->AlarmPara = Batt;
|
||||
CatOneEthSendQueue(MegData, 6); //发送报警信息
|
||||
UploadSend(MegData, 6); //发送报警信息
|
||||
}
|
||||
|
||||
/*****************************************************************************************
|
||||
@@ -346,19 +311,18 @@ int main(void)
|
||||
// TimeGet(&cTime);
|
||||
// TimeShow(TimeTs());
|
||||
FeedDog();
|
||||
//rt_thread_delay(500);
|
||||
//InfTest();
|
||||
//FeedDog();
|
||||
|
||||
//Cat1DBGOnOff(true);
|
||||
|
||||
|
||||
GateWay.CommUnitRevCallBack = CommUnitAnalyze;
|
||||
GateWay.SvrRevCallBack = Cat1EthRevCallBack;
|
||||
GateWay.MuchRevCallBack = MuchRevCallBack;
|
||||
GateWay.AuchRevCallBack = AuchRevCallBack;
|
||||
|
||||
GateWay.NetSendData_MQ = rt_mq_create("NetSendMQ", 512, 10, RT_IPC_FLAG_FIFO);
|
||||
if(GateWay.NetSendData_MQ == RT_NULL) {
|
||||
rt_kprintf("CatOne MQ Create Failed!\r\n");
|
||||
for(int i = 0; i < 6; i++) {
|
||||
char name[8];
|
||||
sprintf(name, "ChMQ%d", i);
|
||||
GateWay.ChMQ[i] = rt_mq_create(name, 256, 5, RT_IPC_FLAG_FIFO);
|
||||
}
|
||||
|
||||
GateWay.LoraRev_MQ = rt_mq_create("LoraRevMQ", 256, 10, RT_IPC_FLAG_FIFO);
|
||||
@@ -371,8 +335,11 @@ int main(void)
|
||||
rt_kprintf("UR Mutex Create Failed!\r\n");
|
||||
}
|
||||
|
||||
GateWay.SvrRevCallBack = Cat1EthRevCallBack;
|
||||
|
||||
GateWay.EthTxMutex = rt_mutex_create("ethtxmtx", RT_IPC_FLAG_FIFO);
|
||||
if(GateWay.EthTxMutex == RT_NULL) {
|
||||
rt_kprintf("EthTx Mutex Create Failed!\r\n");
|
||||
}
|
||||
|
||||
RS485Ch1_Thread = rt_thread_create("RS485Ch1", RS485Ch1_Thread_Entry, &GateWay, 2048, 3, 20);
|
||||
if (RS485Ch1_Thread != RT_NULL)
|
||||
rt_thread_startup(RS485Ch1_Thread);
|
||||
@@ -416,8 +383,10 @@ int main(void)
|
||||
POWER_LED_OFF();
|
||||
}
|
||||
}
|
||||
EthOverHandler();
|
||||
RS485RxOverhandler();
|
||||
if(ChannelIsActive(GateWay.ConfigPara, CH_ETH)) EthOverHandler();
|
||||
if(ChannelIsActive(GateWay.ConfigPara, CH_RS485_1) || ChannelIsActive(GateWay.ConfigPara, CH_RS485_2)
|
||||
|| GateWay.ConfigPara.Rs485Ch1.UpgradeEnable || GateWay.ConfigPara.Rs485Ch2.UpgradeEnable)
|
||||
RS485RxOverhandler();
|
||||
DebugOrCat1RxOverhandler();
|
||||
if(OneSecondDlyCnt % 200 == 0) {
|
||||
FeedDog();
|
||||
@@ -531,81 +500,4 @@ int main(void)
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
static FATFS SDFatFs;
|
||||
static FIL TestFile;
|
||||
static uint8_t u8WorkBuffer[FF_MAX_SS];
|
||||
|
||||
void FSInit(void)
|
||||
{
|
||||
FRESULT fRet;
|
||||
uint32_t u32WBNbr, u32RBNbr;
|
||||
char SDPath[] = "1:";
|
||||
MKFS_PARM opt;
|
||||
uint8_t u8ReadText[100];
|
||||
en_result_t enTestRet = Error;
|
||||
uint8_t u8WriteText[] = "This is a string used to test the FatFs";
|
||||
|
||||
if (FR_OK != f_mount(&SDFatFs, (TCHAR const*)SDPath, 0U)) {
|
||||
rt_kprintf("FatFs Initialization Error!\r\n");
|
||||
}
|
||||
else {
|
||||
memset(&opt, 0, sizeof(MKFS_PARM));
|
||||
opt.fmt = (BYTE)FM_FAT32;
|
||||
/* Create a FAT file system (format) on the logical drive */
|
||||
if (FR_OK != f_mkfs((TCHAR const*)SDPath, &opt, u8WorkBuffer, sizeof(u8WorkBuffer))) {
|
||||
rt_kprintf("FatFs Format Error!\r\n");
|
||||
}
|
||||
else {
|
||||
/* Create and Open a new text file object with write access */
|
||||
if (FR_OK != f_open(&TestFile, "1:Test.txt", ((BYTE)FA_CREATE_ALWAYS | (BYTE)FA_WRITE))) {
|
||||
rt_kprintf("\"Test.txt\" file Open for write Error!\r\n");
|
||||
}
|
||||
else {
|
||||
/* Write data to the text file */
|
||||
fRet = f_write(&TestFile, u8WriteText, sizeof(u8WriteText), (void *)&u32WBNbr);
|
||||
if ((0UL == u32WBNbr) || (FR_OK != fRet)) {
|
||||
rt_kprintf("\"Test.txt\" file Write or EOF Error!\r\n");
|
||||
else {
|
||||
/* Close the open text file */
|
||||
f_close(&TestFile);
|
||||
/* Open the text file object with read access */
|
||||
if (FR_OK != f_open(&TestFile, "1:Test.txt", (BYTE)FA_READ)) {
|
||||
rt_kprintf("\"Test.txt\" file Open for read Error!\r\n");
|
||||
}
|
||||
else {
|
||||
memset(u8ReadText, 0, sizeof(u8ReadText));
|
||||
/* Read data from the text file */
|
||||
fRet = f_read(&TestFile, u8ReadText, sizeof(u8ReadText), (UINT*)(uint32_t)&u32RBNbr);
|
||||
if ((0UL == u32RBNbr) || (FR_OK != fRet)) {
|
||||
rt_kprintf("\"Test.txt\" file Read or EOF Error!\r\n");
|
||||
}
|
||||
else {
|
||||
/* Close the open text file */
|
||||
f_close(&TestFile);
|
||||
/* Compare read data with the expected data */
|
||||
if (u32RBNbr == u32WBNbr) {
|
||||
/* Check data value */
|
||||
if (0 == memcmp(u8WriteText, u8ReadText, u32RBNbr)) {
|
||||
enTestRet = Ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Unlink the micro SD disk I/O driver */
|
||||
f_mount(NULL, (TCHAR const*)SDPath, 0U);
|
||||
|
||||
if(enTestRet != Ok) {
|
||||
rt_kprintf("Error!\r\n");
|
||||
}
|
||||
else {
|
||||
rt_kprintf("Ok!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user