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:
@@ -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