From 31f6f4af9a6f3350c02742fd161007c40057f9ac Mon Sep 17 00:00:00 2001
From: YuanHongbin <975559679@qq.com>
Date: Tue, 28 Jul 2026 16:25:32 +0800
Subject: [PATCH] =?UTF-8?q?feat(channel):=206=E9=80=9A=E9=81=93=E7=8B=AC?=
=?UTF-8?q?=E7=AB=8B=E8=B0=83=E5=BA=A6+MQueue/DEBUG=5FPrintf=E9=87=8D?=
=?UTF-8?q?=E6=9E=84/=E5=86=97=E4=BD=99=E6=B8=85=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
通道系统:
- 新增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
---
Netlist_GETWAY_V1.2_2026-07-21.tel | 294 ++++++++++++++
Project/GateWay/MDK/GateWay.uvoptx | 12 +-
Project/GateWay/MDK/RTE/RTOS/board.c | 19 +-
.../source/Module/GateWay_Debug/DebugCmd.c | 375 +++++++++++-------
Project/GateWay/source/User/Inc/CatOneTask.h | 2 +-
Project/GateWay/source/User/Inc/EthTask.h | 5 +-
Project/GateWay/source/User/Inc/Public.h | 57 ++-
Project/GateWay/source/User/Src/CatOneTask.c | 48 ++-
Project/GateWay/source/User/Src/EthTask.c | 58 ++-
Project/GateWay/source/User/Src/LoraTask.c | 15 +-
Project/GateWay/source/User/Src/Public.c | 57 ++-
Project/GateWay/source/User/Src/RS485Task.c | 35 +-
Project/GateWay/source/User/Src/bsp.c | 10 +-
Project/GateWay/source/User/Src/main.c | 168 ++------
14 files changed, 771 insertions(+), 384 deletions(-)
create mode 100644 Netlist_GETWAY_V1.2_2026-07-21.tel
diff --git a/Netlist_GETWAY_V1.2_2026-07-21.tel b/Netlist_GETWAY_V1.2_2026-07-21.tel
new file mode 100644
index 0000000..ce84714
--- /dev/null
+++ b/Netlist_GETWAY_V1.2_2026-07-21.tel
@@ -0,0 +1,294 @@
+$PACKAGES
+bq25306rter ! bq25306rter ! '{Value}' ; U26
+c0402m ! c0402m ! 100nF ; C9 C28 C39
+c0402m ! c0402m ! 100pF ; C11 C40 C41
+c0402m ! c0402m ! 10nF ; C10
+c0402m ! c0402m ! 33pF ; C31 C32 C33 C34
+C0603 ! C0603 ! '2.2uF' ; C58 C59 C68
+C0603 ! C0603 ! '4.7uF' ; C65
+C0603 ! C0603 ! 100nF ; C5 C13 C15 C21 C23 C25 C29 C36 C38 C44 C46 C48 C50 C52 ,
+ C53 C54 C56 C60 C63 C64 C66 C70 C72 C76 C78 C79 C80 C83 C84 C85 C86 ,
+ C88 C89 C92 C95 C97
+C0603 ! C0603 ! 10uF ; C30 C55 C57 C62
+C0603 ! C0603 ! 15pF ; C73 C77
+C0603 ! C0603 ! 1uF ; C69 C71 C75
+C0603 ! C0603 ! 22pF ; C67 C74 C81 C82
+C0603 ! C0603 ! 22uF ; C61
+C0603 ! C0603 ! 470pF ; C93
+C0603 ! C0603 ! 47nF ; C94
+C0805 ! C0805 ! '2.2uF' ; C90
+C0805 ! C0805 ! 10nF ; C27
+C0805 ! C0805 ! 22uF ; C8 C12 C14 C22 C24 C37 C45 C47 C49 C51 C91 C98
+C1206 ! C1206 ! 22uF ; C35 C96
+CAP-SMD_BD6.3-L6.6-W6.6-FD ! CAP-SMD_BD6.3-L6.6-W6.6-FD ! 470uF ; C6 C7
+CAP-SMD_BD6.3-L6.6-W6.6-LS7.3-FD ! CAP-SMD_BD6.3-L6.6-W6.6-LS7.3-FD ! 220uF ; ,
+ C26
+CONN-TH_2P-P2.50_HX25003-2A ! CONN-TH_2P-P2.50_HX25003-2A ! '{Value}' ; CN3
+CONN-TH_2P-P3.81_L7.4-W7.6 ! CONN-TH_2P-P3.81_L7.4-W7.6 ! '{Value}' ; U2 U11 ,
+ U13 U14 U17
+,
+ CONN-TH_7P-P1.25_HCTL_HC-1.25-7A ! CONN-TH_7P-P1.25_HCTL_HC-1.25-7A ! '{Value}' ,
+ ; CN2
+CRYSTAL-SMD_4P-L3.2-W2.5-BL-2 ! CRYSTAL-SMD_4P-L3.2-W2.5-BL-2 ! '{Value}' ; ,
+ U23
+E32-400M30S ! E32-400M30S ! '{Value}' ; U15
+,
+ ESOP-8_L4.9-W3.9-P1.27-LS6.0-TL-EP ! ESOP-8_L4.9-W3.9-P1.27-LS6.0-TL-EP ! '{Value}' ,
+ ; U6
+FC-135R_L3.2-W1.5 ! FC-135R_L3.2-W1.5 ! '32.768kHz' ; X1
+HDR-TH_2P-P2.54-V-M ! HDR-TH_2P-P2.54-V-M ! '{Value}' ; H3
+HDR-TH_3P-P2.54-V-M ! HDR-TH_3P-P2.54-V-M ! '{Value}' ; H4 H5
+IND-SMD_L4.8-W4.5 ! IND-SMD_L4.8-W4.5 ! '2.2uH' ; L7
+IND-SMD_L7.0-W6.6_FXL0630 ! IND-SMD_L7.0-W6.6_FXL0630 ! 15uH ; L4 L5
+IPEX-SMD_BWIPX-1-001E ! IPEX-SMD_BWIPX-1-001E ! '{Value}' ; RF1
+L0603 ! L0603 ! '{Value}' ; L6
+L2520 ! L2520 ! '{Value}' ; L1 L3
+LED0603-FD_BLUE ! LED0603-FD_BLUE ! '{Value}' ; LORA
+LED0603-RD ! LED0603-RD ! '{Value}' ; 充电 LAN LED3
+LED0603-RD-YELLOW ! LED0603-RD-YELLOW ! '{Value}' ; 4G
+,
+ LQFP-64_L10.0-W10.0-P0.50-LS12.0-BL ! LQFP-64_L10.0-W10.0-P0.50-LS12.0-BL ! '{Value}' ,
+ ; U22
+NANO-SIM-SMD_SMN-305-ARP7 ! NANO-SIM-SMD_SMN-305-ARP7 ! '{Value}' ; CARD1
+NT26E ! NT26E ! '{Value}' ; U19
+OSC-SMD_4P-L3.2-W2.5-BL ! OSC-SMD_4P-L3.2-W2.5-BL ! 16MHz ; X2
+,
+ QFN-48_L5.0-W5.0-P0.35-EP3.7_UC8288 ! QFN-48_L5.0-W5.0-P0.35-EP3.7_UC8288 ! '{Value}' ,
+ ; U20
+R0402 ! R0402 ! '100kΩ' ; R25 R33 R34
+R0402 ! R0402 ! '10kΩ' ; R8 R14 R26 R29 R30 R31 R32 R35
+R0402 ! R0402 ! '1kΩ' ; R12
+R0402 ! R0402 ! '22Ω' ; R16 R18 R19
+R0603 ! R0603 ! '100kΩ' ; R11 R71 R74
+R0603 ! R0603 ! '100Ω' ; R42
+R0603 ! R0603 ! '10kΩ' ; R10 R37 R39 R40 R41 R45 R48 R49 R50 R51 R52 R53 R80 ,
+ R81
+R0603 ! R0603 ! '120kΩ' ; R57
+R0603 ! R0603 ! '120Ω' ; R64 R65
+R0603 ! R0603 ! '12kΩ' ; R7 R15
+R0603 ! R0603 ! '169kΩ' ; R27 R28
+R0603 ! R0603 ! '1kΩ' ; R13 R54 R55 R70 R75 R78 R79
+R0603 ! R0603 ! '1MΩ' ; R83
+R0603 ! R0603 ! '2.7kΩ' ; R58 R59
+R0603 ! R0603 ! '200kΩ' ; R56 R82
+R0603 ! R0603 ! '24kΩ' ; R36
+R0603 ! R0603 ! '3.24kΩ' ; R21
+R0603 ! R0603 ! '3.3kΩ' ; R76 R77
+R0603 ! R0603 ! '30kΩ' ; R85
+R0603 ! R0603 ! '330kΩ' ; R84
+R0603 ! R0603 ! '4.7kΩ' ; R46 R47
+R0603 ! R0603 ! '64kΩ' ; R23 R24
+R0805 ! R0805 ! '10kΩ' ; R17 R22
+R0805 ! R0805 ! '1kΩ' ; R38
+R0805 ! R0805 ! '20kΩ' ; R20
+RJ45-TH_HR915310A ! RJ45-TH_HR915310A ! '{Value}' ; D7
+,
+ SC-70-6_L2.2-W1.3-P0.65-LS2.1-BL ! SC-70-6_L2.2-W1.3-P0.65-LS2.1-BL ! '{Value}' ,
+ ; U24 U25
+SMA_L4.3-W2.6-LS5.1-RD ! SMA_L4.3-W2.6-LS5.1-RD ! '{Value}' ; D3 D4
+SOD-106_L2.0-W1.3-RD ! SOD-106_L2.0-W1.3-RD ! '{Value}' ; D9
+SOIC-8_L5.0-W4.0-P1.27-LS6.0-BL ! SOIC-8_L5.0-W4.0-P1.27-LS6.0-BL ! '{Value}' ,
+ ; U12 U16
+SOIC-8_L5.3-W5.3-P1.27-LS8.0-BL ! SOIC-8_L5.3-W5.3-P1.27-LS8.0-BL ! '{Value}' ,
+ ; U21
+,
+ SOT-223-3_L6.5-W3.4-P2.30-LS7.0-BR ! SOT-223-3_L6.5-W3.4-P2.30-LS7.0-BR ! '{Value}' ,
+ ; U10
+SOT-23 ! SOT-23 ! '{Value}' ; D5 D6
+SOT-23_L2.9-W1.3-P1.90-LS2.4-BR ! SOT-23_L2.9-W1.3-P1.90-LS2.4-BR ! '{Value}' ,
+ ; Q14 Q15 Q16 Q18
+,
+ SOT-23-3_L2.9-W1.6-P1.90-LS2.8-BR ! SOT-23-3_L2.9-W1.6-P1.90-LS2.8-BR ! '{Value}' ,
+ ; Q19
+,
+ SOT-23-3_L3.0-W1.7-P0.95-LS2.9-BR ! SOT-23-3_L3.0-W1.7-P0.95-LS2.9-BR ! '{Value}' ,
+ ; Q11
+sot-23-3p ! sot-23-3p ! '{Value}' ; Q5 Q6 Q7 Q8 Q9 Q10
+,
+ SOT-23-6_L2.9-W1.6-P0.95-LS2.8-BL ! SOT-23-6_L2.9-W1.6-P0.95-LS2.8-BL ! '{Value}' ,
+ ; U3 U4
+,
+ SOT-23-6_L2.9-W1.6-P0.95-LS2.8-BR ! SOT-23-6_L2.9-W1.6-P0.95-LS2.8-BR ! '{Value}' ,
+ ; U9
+,
+ SOT-363_L2.0-W1.3-P0.65-LS2.1-BR ! SOT-363_L2.0-W1.3-P0.65-LS2.1-BR ! '{Value}' ,
+ ; D2
+SOT323-6L_L2.0-W1.3-LS2.1-BL ! SOT323-6L_L2.0-W1.3-LS2.1-BL ! '{Value}' ; U18
+TF-SMD_XKTF-1307-18 ! TF-SMD_XKTF-1307-18 ! '{Value}' ; CARD2
+,
+ TO-263-5_L10.2-W9.9-P1.70-LS14.4-TL ! TO-263-5_L10.2-W9.9-P1.70-LS14.4-TL ! '{Value}' ,
+ ; U5
+$A_PROPERTIES
+$NETS
+'$1N14156' ; R20.1 R22.1 U5.5
+'$1N15120' ; C5.2 L1.1 U3.6
+'$1N15124' ; C5.1 U3.1
+'$1N156708' ; R59.2 U22.56
+'$1N156972' ; R58.2 U22.55
+'$1N157215' ; 4G.2 R59.1
+'$1N157217' ; LORA.2 R58.1
+'$1N219298' ; Q14.1 R77.2
+'$1N219301' ; Q15.1 R76.2
+'$1N219302' ; Q15.2 Q16.3
+'$1N219303' ; Q19.3 R11.2 R78.1
+'$1N219304' ; D9.1 R10.1 R79.1
+'$1N219315' ; Q18.1 R78.2
+'$1N219321' ; 充电.1 R13.1
+'$1N219322' ; R80.2 R81.2 U26.7
+'$1N219324' ; R82.2 U26.8
+'$1N219325' ; C93.1 R82.1 R84.2 U26.9
+'$1N219326' ; R83.1 R84.1
+'$1N219329' ; C94.1 L7.1 U26.13 U26.14
+'$1N219330' ; C93.2 C95.2 C96.2 CN3.1 L7.2 Q15.3 R83.2 U26.10
+'$1N219335' ; 充电.2 C90.2 R80.1 U26.2
+'$1N219388' ; Q14.3 U14.2
+'$1N219660' ; Q19.1 R10.2
+'$1N219673' ; C89.2 Q14.2 Q18.2 Q19.2 R79.2
+'$1N219967' ; H3.2 R70.2 R71.2 U24.6 U25.6
+'$1N220294' ; C91.2 C92.2 Q18.3 R75.1 U26.1
+'$1N220337' ; Q16.1 R74.2 R75.2
+'$1N220644' ; H4.2 R7.2 U3.3
+'$1N220659' ; H4.1 R23.1
+'$1N220661' ; H4.3 R27.2
+'$1N220812' ; H5.1 R24.2
+'$1N220814' ; H5.3 R28.2
+'$1N220820' ; H5.2 R15.2 U4.3
+'$1N232424' ; R13.2 U26.3
+'$1N232426' ; C94.2 U26.15
+'$1N232428' ; R85.2 U26.4
+'$1N25321' ; C27.1 U6.1
+'$1N25347' ; C27.2 D3.1 L4.1 U6.8
+'$1N25981' ; R17.1 R21.2 U6.4
+'$1N27457' ; C21.1 U4.1
+'$1N27465' ; C21.2 L3.1 U4.6
+'$1N27856' ; D4.2 L5.2 U9.1
+'$1N27899' ; R36.1 R38.2 U9.3
+'$1N35056' ; Q7.1 R32.1 R33.2
+'$1N35060' ; Q7.3 U19.20
+'$1N35062' ; R18.2 U19.12
+'$1N35065' ; R19.2 U19.13
+'$1N35068' ; R16.2 U19.11
+'$1N35087' ; LED3.1 Q5.3
+'$1N35088' ; Q5.1 R8.1
+'$1N35089' ; LED3.2 R12.2
+'$1N35110' ; Q6.1 R25.2 R26.1
+'$1N35118' ; Q10.1 R34.2 R35.1
+'$1N35136' ; C41.2 Q9.1 R30.2
+'$1N35141' ; C40.1 Q8.1 R29.1
+'$1N36133' ; LAN.2 U20.21
+'$1N36222' ; C68.2 U20.33
+'$1N36366' ; C58.1 L6.1 U20.1 U20.2
+'$1N36373' ; C66.2 L6.2 U20.35
+'$1N36810' ; C67.2 U20.32 U23.3
+'$1N36815' ; C74.2 U20.31 U23.1
+'$1N37705' ; Q11.1 U18.3
+'$1N39412' ; C80.2 U22.30
+'$1N45053' ; LAN.1 R47.2
+'$1N46192' ; R46.1 U22.60
+'$1N88506' ; D7.10 R54.1
+'$1N88557' ; D7.11 R55.1
+'$1N99689' ; RF1.1 U19.37
+'ADC_VBAT' ; C84.2 R56.1 R57.2 U22.15
+'CAT1_NETSTATUS' ; R8.2 U19.17
+'CAT1_PWRKEY' ; R26.2 U22.17
+'CAT1_RESET' ; R35.2 U22.14
+'CAT1_UART_RX' ; Q8.3 U19.18
+'CAT1_UART_TX' ; Q9.2 U19.19
+'CAT1_WAKEUP' ; R32.2 U22.16
+'E32_INT' ; U15.20 U22.20
+'E32_NRST' ; U15.21 U22.21
+'E32_PXEN' ; U15.6 U22.26
+'E32_TXEN' ; U15.7 U22.27
+'LAN/~4G' ; R70.1 U22.61
+'MCU_SWCLK' ; CN2.3 U22.49
+'MCU_SWDIO' ; CN2.4 U22.46
+'NT26E_RX' ; Q9.3 R31.1 U24.3
+'NT26E_TX' ; Q8.2 U25.3
+'RD-' ; D7.7 U20.12
+'RD+' ; D7.6 U20.11
+'RS485_1_A' ; D5.1 R39.2 R64.1 U11.1 U12.6
+'RS485_1_B' ; D5.2 R37.2 R64.2 U11.2 U12.7
+'RS485_1_CTRL' ; U12.2 U12.3 U22.38
+'RS485_2_A' ; D6.1 R41.2 R65.1 U2.1 U16.6
+'RS485_2_B' ; D6.2 R40.2 R65.2 U2.2 U16.7
+'RS485_2_CTRL' ; U16.2 U16.3 U22.34
+'SD1_CLK' ; CARD2.5 R50.1 U22.53
+'SD1_CMD' ; CARD2.3 R51.1 U22.54
+'SD1_DAT0' ; CARD2.7 R49.1 U22.39
+'SD1_DAT1' ; CARD2.8 R48.1 U22.40
+'SD1_DAT2' ; CARD2.1 R53.1 U22.42
+'SD1_DAT3' ; CARD2.2 R52.1 U22.52
+'SIM_CLK' ; C31.2 CARD1.3 D2.4 R19.1
+'SIM_DATA' ; C33.2 CARD1.7 D2.6 R14.2 R16.1
+'SIM_RST' ; C32.2 CARD1.2 D2.5 R18.1
+'SIM_VDD' ; C34.1 C39.2 CARD1.1 CARD1.6 D2.3 R14.1 U19.15
+'SPI1_MISO' ; U21.2 U22.9
+'SPI1_MOSI' ; U21.5 U22.11
+'SPI1_SCK' ; U21.6 U22.10
+'SPI1_SS0' ; U21.1 U22.8
+'SPI2_MISO' ; U15.22 U22.22
+'SPI2_MOSI' ; U15.23 U22.23
+'SPI2_SCK' ; U15.24 U22.24
+'SPI2_SS0' ; U15.25 U22.25
+'TD-' ; D7.2 U20.14
+'TD+' ; D7.1 U20.13
+'UART1_RX' ; CN2.6 U22.44
+'UART1_TX' ; CN2.5 U22.45
+'UART2_RX' ; U12.1 U22.43
+'UART2_TX' ; U12.4 U22.41
+'UART3_RX' ; U16.1 U22.35
+'UART3_TX' ; U16.4 U22.33
+'UART4_RX' ; U22.62 U24.4
+'UART4_TX' ; U22.2 U25.4
+'V_RS4851_5/12V' ; C14.2 C15.2 L1.2 R23.2 R27.1 U13.2
+'V_RS4851_ON/~OFF' ; U3.4 U22.51
+'V_RS4852_5/12V' ; C24.2 C25.2 L3.2 R24.1 R28.1 U17.2
+'V_RS4852_ON/~OFF' ; U4.4 U22.28
+'VCC_15V' ; C12.2 C13.2 C22.2 C23.2 C51.1 C52.2 D4.1 R36.2 U3.5 U4.5
+'VCC_33' ; C59.1 C60.1 C69.2 D7.3 D7.5 D7.9 D7.12 Q11.3 R42.2 U20.3
+'VCC_3V3' ; C40.2 C46.2 C47.2 C48.2 C53.2 C61.2 C62.2 C63.1 C64.1 C65.1 C71.1 ,
+ C72.1 C75.1 C76.1 C78.1 C79.2 C83.2 C85.2 C86.2 CARD2.4 CN2.7 Q11.2 ,
+ R29.2 R31.2 R39.1 R41.1 R45.1 R46.2 R48.2 R49.2 R50.2 R51.2 R52.2 ,
+ R53.2 R71.1 U10.2 U10.4 U12.8 U16.8 U18.5 U21.3 U21.7 U21.8 U22.13 ,
+ U22.19 U22.32 U22.48 U22.64 U24.5 U25.5
+'VCC_3V8' ; C6.1 C7.1 C8.1 C9.2 C10.2 C11.2 C37.2 C38.2 C54.2 C55.2 C56.2 ,
+ C57.2 R12.1 R20.2 U5.4 U15.9 U15.10 U19.45 U19.46
+'VCC_5V' ; C26.1 C35.2 C36.2 C44.2 C45.2 C88.2 L4.2 R17.2 U5.1 U5.2 U10.3
+'VCC_7V4' ; C29.2 C30.2 C49.1 C50.2 C97.2 C98.2 L5.1 Q16.2 R56.2 U6.7 U9.4 ,
+ U9.5 U26.16
+'VDD_EXT' ; C28.2 C41.1 R30.1 U19.26
+'XTAL_IN' ; C81.2 U22.5 X2.1
+'XTAL_OUT' ; C82.2 U22.6 X2.3
+'XTAL32_IN' ; C77.1 U22.4 X1.2
+'XTAL32_OUT' ; C73.1 U22.3 X1.1
+'YOXO_100MLINK' ; U20.23 U22.58
+'YOXO_DEF' ; U20.22 U22.59
+'YOXO_NRST' ; U20.25 U22.57
+'YOXO_RX' ; U20.37 U24.1
+'YOXO_TX' ; U20.36 U25.1
+ACT ; R55.2 U20.27
+CAT1PWRKEY ; Q6.3 U19.7
+CAT1RESET ; Q10.3 U19.16
+GND ; 4G.1 C6.2 C7.2 C8.2 C9.1 C10.1 C11.1 C12.1 C13.1 C14.1 C15.1 C22.1 C23.1 ,
+ C24.1 C25.1 C26.2 C28.1 C29.1 C30.1 C31.1 C32.1 C33.1 C34.2 C35.1 ,
+ C36.1 C37.1 C38.1 C39.1 C44.1 C45.1 C46.1 C47.1 C48.1 C49.2 C50.1 ,
+ C51.2 C52.1 C53.1 C54.1 C55.1 C56.1 C57.1 C58.2 C59.2 C60.2 C61.1 ,
+ C62.1 C63.2 C64.2 C65.2 C66.1 C67.1 C68.1 C69.1 C70.1 C71.2 C72.2 ,
+ C73.2 C74.1 C75.2 C76.2 C77.2 C78.2 C79.1 C80.1 C81.1 C82.1 C83.1 ,
+ C84.1 C85.1 C86.1 C88.1 C89.1 C90.1 C91.1 C92.1 C95.1 C96.1 C97.1 ,
+ C98.1 CARD1.5 CARD1.9 CARD1.10 CARD1.11 CARD2.6 CARD2.9 CARD2.10 ,
+ CARD2.11 CARD2.12 CN2.1 CN3.2 D2.2 D3.2 D5.3 D6.3 D9.2 H3.1 LORA.1 ,
+ Q5.2 Q6.2 Q7.2 Q10.2 R7.1 R11.1 R15.1 R21.1 R22.2 R25.1 R33.1 R34.1 ,
+ R37.1 R38.1 R40.1 R42.1 R47.1 R57.1 R74.1 R76.1 R77.1 R81.1 R85.1 ,
+ RF1.2 RF1.3 U3.2 U4.2 U5.3 U5.6 U6.6 U6.9 U9.2 U10.1 U12.5 U13.1 U14.1 ,
+ U15.1 U15.2 U15.3 U15.4 U15.5 U15.11 U15.12 U15.17 U15.18 U15.26 ,
+ U15.28 U16.5 U17.1 U18.2 U19.1 U19.10 U19.29 U19.36 U19.39 U19.40 ,
+ U19.43 U19.44 U19.50 U19.51 U19.52 U19.53 U19.81 U19.82 U19.83 U19.85 ,
+ U19.103 U19.107 U19.108 U19.109 U19.110 U19.111 U19.112 U20.49 U21.4 ,
+ U22.12 U22.18 U22.31 U22.47 U22.63 U23.2 U23.4 U24.2 U25.2 U26.11 ,
+ U26.12 X2.2 X2.4
+LINK ; R54.2 U20.28
+NRST ; C70.2 CN2.2 R45.2 U22.7
+PGND ; D7.8 D7.13 D7.14
+$SCHEDULE
+$END
diff --git a/Project/GateWay/MDK/GateWay.uvoptx b/Project/GateWay/MDK/GateWay.uvoptx
index 82ab462..e30c9d0 100644
--- a/Project/GateWay/MDK/GateWay.uvoptx
+++ b/Project/GateWay/MDK/GateWay.uvoptx
@@ -450,6 +450,16 @@
1
(60 * 1000),0x0A
+
+ 4
+ 1
+ GateWay.ConfigPara
+
+
+ 5
+ 1
+ cat1Active
+
@@ -1068,7 +1078,7 @@
::RTOS
- 1
+ 0
0
0
1
diff --git a/Project/GateWay/MDK/RTE/RTOS/board.c b/Project/GateWay/MDK/RTE/RTOS/board.c
index 4252c91..8773370 100644
--- a/Project/GateWay/MDK/RTE/RTOS/board.c
+++ b/Project/GateWay/MDK/RTE/RTOS/board.c
@@ -12,6 +12,7 @@
#include
#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();
}
diff --git a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c
index 6fa0799..d18acc5 100644
--- a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c
+++ b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c
@@ -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,
diff --git a/Project/GateWay/source/User/Inc/CatOneTask.h b/Project/GateWay/source/User/Inc/CatOneTask.h
index d7356f3..399278a 100644
--- a/Project/GateWay/source/User/Inc/CatOneTask.h
+++ b/Project/GateWay/source/User/Inc/CatOneTask.h
@@ -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);
diff --git a/Project/GateWay/source/User/Inc/EthTask.h b/Project/GateWay/source/User/Inc/EthTask.h
index b86544c..45c9c81 100644
--- a/Project/GateWay/source/User/Inc/EthTask.h
+++ b/Project/GateWay/source/User/Inc/EthTask.h
@@ -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
diff --git a/Project/GateWay/source/User/Inc/Public.h b/Project/GateWay/source/User/Inc/Public.h
index 4b3e0aa..e32a64e 100644
--- a/Project/GateWay/source/User/Inc/Public.h
+++ b/Project/GateWay/source/User/Inc/Public.h
@@ -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);
diff --git a/Project/GateWay/source/User/Src/CatOneTask.c b/Project/GateWay/source/User/Src/CatOneTask.c
index 4615825..8ad7c13 100644
--- a/Project/GateWay/source/User/Src/CatOneTask.c
+++ b/Project/GateWay/source/User/Src/CatOneTask.c
@@ -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();
}
diff --git a/Project/GateWay/source/User/Src/EthTask.c b/Project/GateWay/source/User/Src/EthTask.c
index 11d98fd..7ba5821 100644
--- a/Project/GateWay/source/User/Src/EthTask.c
+++ b/Project/GateWay/source/User/Src/EthTask.c
@@ -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;
}
diff --git a/Project/GateWay/source/User/Src/LoraTask.c b/Project/GateWay/source/User/Src/LoraTask.c
index f099278..ecbbb9d 100644
--- a/Project/GateWay/source/User/Src/LoraTask.c
+++ b/Project/GateWay/source/User/Src/LoraTask.c
@@ -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;
diff --git a/Project/GateWay/source/User/Src/Public.c b/Project/GateWay/source/User/Src/Public.c
index dcde891..af6baa3 100644
--- a/Project/GateWay/source/User/Src/Public.c
+++ b/Project/GateWay/source/User/Src/Public.c
@@ -7,6 +7,20 @@
#include
#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);
+}
diff --git a/Project/GateWay/source/User/Src/RS485Task.c b/Project/GateWay/source/User/Src/RS485Task.c
index 1cc28f4..fac9433 100644
--- a/Project/GateWay/source/User/Src/RS485Task.c
+++ b/Project/GateWay/source/User/Src/RS485Task.c
@@ -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);
}
diff --git a/Project/GateWay/source/User/Src/bsp.c b/Project/GateWay/source/User/Src/bsp.c
index 0b1dea2..67019bb 100644
--- a/Project/GateWay/source/User/Src/bsp.c
+++ b/Project/GateWay/source/User/Src/bsp.c
@@ -1,5 +1,6 @@
#include
#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);
diff --git a/Project/GateWay/source/User/Src/main.c b/Project/GateWay/source/User/Src/main.c
index 7dc1a94..99029cb 100644
--- a/Project/GateWay/source/User/Src/main.c
+++ b/Project/GateWay/source/User/Src/main.c
@@ -1,5 +1,3 @@
-#include
-#include
#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