diff --git a/Project/GateWay/MDK/GateWay.uvoptx b/Project/GateWay/MDK/GateWay.uvoptx index e30c9d0..1d3b626 100644 --- a/Project/GateWay/MDK/GateWay.uvoptx +++ b/Project/GateWay/MDK/GateWay.uvoptx @@ -1078,7 +1078,7 @@ ::RTOS - 0 + 1 0 0 1 diff --git a/Project/GateWay/MDK/RTE/RTOS/board.c b/Project/GateWay/MDK/RTE/RTOS/board.c index 8773370..9bbfa65 100644 --- a/Project/GateWay/MDK/RTE/RTOS/board.c +++ b/Project/GateWay/MDK/RTE/RTOS/board.c @@ -91,8 +91,8 @@ void rt_hw_console_output(const char *str) 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: + case CH_CAT1: DebugOrCat1UartSend((uint8_t *)str, strlen(str)); break; + case CH_DBG: DebugOrCat1UartSend((uint8_t *)str, strlen(str)); break; default: DebugOrCat1UartSend((uint8_t *)str, strlen(str)); break; } rt_exit_critical(); diff --git a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c index d18acc5..11fcaea 100644 --- a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c +++ b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c @@ -42,7 +42,21 @@ void Debug_Printf(char *format, ...) va_list args; va_start(args, format); vsprintf(&tempBuff[0], format, args); - rt_hw_console_output(tempBuff); + if(GateWay && GateWay->ConfigPara.Duch == CH_CAT1 + && GateWay->ConfigPara.Much != CH_CAT1 + && GateWay->ConfigPara.Auch != CH_CAT1 + && !(GateWay->ConfigPara.CuchMask & CUCH_CAT1)) { + char *line = tempBuff; + while(line && *line) { + char *end = strstr(line, "\r\n"); + uint16_t n = end ? (uint16_t)(end - line + 2) : (uint16_t)strlen(line); + if(n > 240) n = 240; + if(n > 0) Cat1DuchSend(line, n); + line = end ? end + 2 : NULL; + } + } else { + rt_kprintf(tempBuff); + } va_end(args); } /***************************************************************************************** diff --git a/Project/GateWay/source/User/Inc/CatOneTask.h b/Project/GateWay/source/User/Inc/CatOneTask.h index 399278a..152b70c 100644 --- a/Project/GateWay/source/User/Inc/CatOneTask.h +++ b/Project/GateWay/source/User/Inc/CatOneTask.h @@ -39,6 +39,7 @@ typedef enum { CAT_ONE_RESET, CAT_ONE_OFF, CAT_ONE_CLOSE_TCP, + CAT_ONE_DUCH_MODE, }CatOneStatus_m; typedef enum { @@ -96,4 +97,5 @@ void CatOne_Thread_Entry(void *parameter); void Cat1IrqCallback(uint8_t rData); void Cat1OverHandler(void); void CatReadImeiOrSim(char *Imei, char *Sim); +void Cat1DuchSend(const char *text, uint16_t len); #endif diff --git a/Project/GateWay/source/User/Src/CatOneTask.c b/Project/GateWay/source/User/Src/CatOneTask.c index 8ad7c13..5c43518 100644 --- a/Project/GateWay/source/User/Src/CatOneTask.c +++ b/Project/GateWay/source/User/Src/CatOneTask.c @@ -21,6 +21,24 @@ static char CommUnitSendASCII[CAT_ONE_REV_LEN_MAX * 2]; static uint8_t Cat1RevTimeOutCnt; static uint16_t CatSendErrCnt = 0; +bool Cat1DuchReady = false; +static char duchRing[8192]; +static uint16_t duchWr, duchRd; + +void Cat1DuchSend(const char *text, uint16_t len) +{ + if(len == 0 || len > 240) return; + if(duchWr + len <= 8192) { + memcpy(&duchRing[duchWr], text, len); + duchWr += len; + } else { + uint16_t part = 8192 - duchWr; + memcpy(&duchRing[duchWr], text, part); + memcpy(duchRing, text + part, len - part); + duchWr = len - part; + } +} + #define CAT1_DBG_LOG(...) { if(CAT1DispEn) Debug_Printf(__VA_ARGS__);} #define CATONE_RESET_DELAY_TIME_MAX (5 * 60 * 1000) @@ -434,13 +452,16 @@ void CatOneLoopHandler(void) case CAT_ONE_WAIT_CONN: if(CatOne.TcpConnFlag) { - if(CatOne.GateWay->ConfigPara.Much != CH_CAT1) { + if(CatOne.GateWay->ConfigPara.Much == CH_CAT1) { + CatOne.Cat1Status = CAT_ONE_REG_SVR; + } + else if(CatOne.GateWay->ConfigPara.Auch == CH_CAT1 || (CatOne.GateWay->ConfigPara.CuchMask & CUCH_CAT1)) { GateWayRegister(Payload); CatOneTxLen = NetCommOrgData(CatOne.GateWay, Payload, CatOneTxBuff); CatOne.Cat1Status = CAT_ONE_SEND_DATA; } else { - CatOne.Cat1Status = CAT_ONE_REG_SVR; + CatOne.Cat1Status = CAT_ONE_DUCH_MODE; } } break; @@ -515,6 +536,33 @@ void CatOneLoopHandler(void) CatOneAtCmdSend(CAT_ONE_LTPCLOSE, 1000, CAT_ONE_OFF); break; + case CAT_ONE_DUCH_MODE: + Cat1DuchReady = true; + while(ChannelIsActive(CatOne.GateWay->ConfigPara, CH_CAT1)) { + if(duchRd != duchWr) { + uint16_t avail = (duchWr - duchRd) & 0x1FFF; + uint16_t n = avail > 240 ? 240 : avail; + sprintf(CatOne.CatOneSendBuff, "AT+QISEND=0,%d\r\n", n); + DebugOrCat1UartSend((uint8_t *)CatOne.CatOneSendBuff, strlen(CatOne.CatOneSendBuff)); + rt_thread_delay(200); + if(duchRd + n <= 8192) { + DebugOrCat1UartSend((uint8_t *)&duchRing[duchRd], n); + } else { + uint16_t part = 8192 - duchRd; + DebugOrCat1UartSend((uint8_t *)&duchRing[duchRd], part); + DebugOrCat1UartSend((uint8_t *)duchRing, n - part); + } + DebugOrCat1UartSend((uint8_t *)"\x1A", 1); + rt_thread_delay(500); + duchRd = (duchRd + n) & 0x1FFF; + } else { + rt_thread_delay(50); + } + } + Cat1DuchReady = false; + CatOne.Cat1Status = CAT_ONE_IDEL; + break; + case CAT_ONE_OFF: CAT1_RESET_SET(); CAT1_PWR_KEY_CLR(); diff --git a/Project/GateWay/source/User/Src/main.c b/Project/GateWay/source/User/Src/main.c index 99029cb..5ae0210 100644 --- a/Project/GateWay/source/User/Src/main.c +++ b/Project/GateWay/source/User/Src/main.c @@ -95,9 +95,9 @@ 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.Much = CH_CAT1; + GateWay.ConfigPara.Much = CH_ETH; GateWay.ConfigPara.Auch = CH_NULL; - GateWay.ConfigPara.Duch = CH_ETH; + GateWay.ConfigPara.Duch = CH_CAT1; GateWay.ConfigPara.CuchMask = CUCH_LORA; #if MAC_ADDR_TYPE == 0//测试服务器 GateWay.ConfigPara.LTENet.DestAddr[0] = 39;