19 Commits 674713f78f ... c10715ae86

Autor SHA1 Mensagem Data
  haitao c10715ae86 Merge commit 'd2b00294f64b161364915ae9082f104a2f26e39c' 8 meses atrás
  zhao006 d2b00294f6 提交 9 meses atrás
  zhao006 e5185a7b3c 提交 9 meses atrás
  zhao006 78dafe30bd 提交 9 meses atrás
  zhaoxia d12097fdeb 更新 'app/System/source/task.c' 10 meses atrás
  zhao006 d5eacf5be0 dlt 10 meses atrás
  zhao006 7b45d95e71 dlt 10 meses atrás
  zhao006 a324aa218b dlt 10 meses atrás
  haitao 841e798780 ½â¾ö½ÓÊնÓÁÐbug 10 meses atrás
  zhao006 b1c5710f29 提交 10 meses atrás
  zhao006 1a1818e64f Merge branch 'test' of http://git.ringzle.com:3000/haitaowang1001/dtu_lan_gateway into test 10 meses atrás
  zhao006 85b3182b74 提交 10 meses atrás
  zhaoxia a918534a9b 更新 'app/System/source/task.c' 10 meses atrás
  zhao006 0c4865c49d 修改后 10 meses atrás
  zhao006 bfd21668ce 提交 10 meses atrás
  zhao006 4c02b83a1a 提交 10 meses atrás
  zhao006 e79cbd1474 提交 10 meses atrás
  zhao006 d40e679f70 提交 10 meses atrás
  zhao006 7208afaabc 提交 10 meses atrás

+ 6 - 2
app/HARDWARE/includes/log.h

@@ -12,6 +12,10 @@
 
 #define LOG_LEN_MAX 256
 
+#define _LOG_DEBUG
+#define _LOG_WARN
+#define _LOG_INFO
+
 typedef enum LOG_LEVEL_U
 {
 	LOG_NONE = 0,
@@ -22,7 +26,7 @@ typedef enum LOG_LEVEL_U
 	LOG_MAX,
 }logLevel_t;
 
-void LogPrint(logLevel_t logLevel, const char *func, const int line, char * fmt, ...);
-
+void LogPrint(logLevel_t logLevel,const char *file, const char *func, const int line, char * fmt, ...);
+void log_init(void);
 #define LOG_PRINT(logLevel, fmt, ...) LogPrint(logLevel, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
 #endif /* INC_LOG_H_ */

+ 5 - 0
app/HARDWARE/includes/tcp_server.h

@@ -0,0 +1,5 @@
+#ifndef TCP_SERVER_H
+#define TCP_SERVER_H
+void tcp_server_init();
+void tcp_server_task(void *Parameters);
+#endif

+ 11 - 0
app/HARDWARE/includes/udp_send.h

@@ -0,0 +1,11 @@
+#ifndef __UDP__H
+#define __UDP__H
+
+/* function declarations */
+/* initialize the tcp_client application */
+
+int udp_log_start(void);
+void udp_log_close(void);
+int udp_send_printf(char *p);
+
+#endif

+ 4 - 1
app/HARDWARE/includes/usart.h

@@ -57,7 +57,7 @@
 //485多신땍屢
 #define USART_485                             USART3
 #define USART_485_CLK                         RCC_APB1Periph_USART3 
-#define USART_485_BAUDRATE                    9600  //눔왯꺼景쪽
+#define USART_485_BAUDRATE                    9600 //눔왯꺼景쪽
 
 #define USART_485_RX_GPIO_PORT                GPIOC
 #define USART_485_RX_GPIO_CLK                 RCC_AHB1Periph_GPIOC
@@ -88,6 +88,9 @@ void DEBUG_USART_Config(void);
 void USART_232_config(void);
 void Usart_SendHex( USART_TypeDef * pUSARTx, uint8_t *str,uint16_t hexLength);
 void USART_485_config(void);
+void USART_485_DE_TX(void);
+void USART_485_DE_RX(void);
+void Config_485_Port(uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity, uint8_t flowcontrol);
 
 extern uint8_t UART6_RX_BUF[BUFF_SIZE];
 extern uint8_t UART6_RX_STAT;

+ 53 - 46
app/HARDWARE/sources/log.c

@@ -5,57 +5,64 @@
  *      Author: tangm
  */
 #include "log.h"
+#include "usart.h"
 #include <stdarg.h>
 #include <stdio.h>
-#include "usart.h"
-///重定向c库函数printf到串口,重定向后可使用printf函数
-int fputc(int ch, FILE *f)
-{
-		/* 发送一个字节数据到串口 */
-		USART_SendData(USART_232, (uint8_t) ch);
-		
-		/* 等待发送完毕 */
-		while (USART_GetFlagStatus(USART_232, USART_FLAG_TXE) == RESET);	
-		return (ch);
-}
+#include "ucos_ii.h"
 
-///重定向c库函数scanf到串口,重写向后可使用scanf、getchar等函数
-int fgetc(FILE *f)
-{
-		/* 等待串口输入数据 */
-		while (USART_GetFlagStatus(USART_232, USART_FLAG_RXNE) == RESET);
+#include "main.h"
+#include "udp_send.h"
+#include "stdlib.h"
+#include "malloc.h"
 
-		return (int)USART_ReceiveData(USART_232);
+static OS_EVENT  *logMutex;
+uint8_t perr;
+void LogPrint(logLevel_t logLevel,const char *file, const char *func, const int line, char * fmt, ...)
+{
+	
+	OSMutexPend(logMutex, 5000, &perr);
+	if(perr == OS_ERR_NONE)
+	{	
+			udp_log_start();
+			va_list args;
+			va_start(args, fmt);
+			char buf[LOG_LEN_MAX];
+			vsnprintf(buf, sizeof(buf), fmt, args);
+			va_end(args);
+			char *p=mymalloc(SRAMEX, 1024);
+			switch (logLevel)
+			{
+				#ifdef _LOG_INFO
+						case LOG_INFO:
+							sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "INFO", file, func, line, buf);
+							break;
+				#endif
+				#ifdef _LOG_DEBUG
+						case LOG_DEBUG:
+							sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "DEBUG",file, func, line, buf);
+							break;
+				#endif
+				#ifdef _LOG_WARN
+						case LOG_WARN:
+							sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "WARN", file, func, line, buf);
+							break;
+				#endif
+						case LOG_ERROR:
+							sprintf(p,"[%s][%s][%s:%4d] %s\r\n", "ERROR",file, func, line, buf);
+							break;
+						default:
+							break;
+			}
+			udp_send_printf(p);
+			myfree(SRAMEX, p);
+			udp_log_close();
+			perr = OSMutexPost(logMutex);
+		}
 }
 
-void LogPrint(logLevel_t logLevel, const char *func, const int line, char * fmt, ...)
+void log_init()
 {
-	va_list args;
-	va_start(args, fmt);
-	char buf[LOG_LEN_MAX];
-	vsnprintf(buf, sizeof(buf), fmt, args);
-	va_end(args);
-	switch (logLevel)
-	{
-#ifdef _LOG_INFO
-		case LOG_INFO:
-			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "INFO", func, line, buf);
-			break;
-#endif
-#ifdef _LOG_DEBUG
-		case LOG_DEBUG:
-			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "DEBUG", func, line, buf);
-			break;
-#endif
-#ifdef _LOG_WARN
-		case LOG_WARN:
-			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "WARN", func, line, buf);
-			break;
-#endif
-		case LOG_ERROR:
-			printf("LOG[%-5s][%-20s:%4d] %s\r\n", "ERROR", func, line, buf);
-			break;
-		default:
-			break;
-	}
+	
+	logMutex = OSMutexCreate (0, &perr);//创建一个log互斥量
+	OSTimeDly(100);
 }

+ 71 - 0
app/HARDWARE/sources/tcp_server.c

@@ -0,0 +1,71 @@
+#include <string.h>
+#include <stdio.h>
+#include "tcp_server.h"
+#include "stm32f2xx.h"
+#include "main.h"
+#include "log.h"
+
+#include "lwip/tcp.h"
+#include "lwip/memp.h"
+#include "lwip/api.h"
+#include "lwip/sockets.h"
+#include "lwip/opt.h"
+#include "lwip/sys.h"
+
+
+void tcp_server_task(void *Parameters)
+{
+    int ret,sockfd;
+    struct sockaddr_in tcpServerSock;
+    struct sockaddr_in client_sock;
+    tcpServerSock.sin_family = AF_INET;
+		inet_aton("192.168.2.212",&(tcpServerSock.sin_addr));
+//    tcpServerSock.sin_addr.s_addr = htonl(IPADDR_ANY);
+    tcpServerSock.sin_port = htons(8080);
+tcp_server_begin:
+    sockfd = socket(AF_INET, SOCK_STREAM, 0);
+    if (sockfd < 0)
+    {
+        goto tcp_server_begin;
+    }
+    ret = bind(sockfd, (struct sockaddr *)&tcpServerSock, sizeof(tcpServerSock));
+    if (ret < 0)
+    {
+        lwip_close(sockfd);
+        sockfd = -1;
+        goto tcp_server_begin;
+    }
+    ret = listen(sockfd, 10);
+    if (ret < 0)
+    {
+        lwip_close(sockfd);
+        sockfd = -1;
+        goto tcp_server_begin;
+    }
+		
+    while (1)
+    {
+				OSTimeDly(1000);
+        socklen_t len = sizeof(client_sock);
+        int client_socket = accept(sockfd, (struct sockaddr*)&client_sock,&len);
+				LogPrint(LOG_INFO,__FILE__,__FUNCTION__,__LINE__,"ÉÏλ»ú³É¹¦Á¬½Ó%s");
+        if (client_socket<0)
+        {
+            printf("error");
+        }
+    }
+    
+}
+/*!
+    \brief      initialize the tcp_client application
+    \param[in]  none
+    \param[out] none
+    \retval     none
+*/
+#define  TCP_TASK_PRIO     9
+#define  TCP_STK_SIZE  	 	1024
+OS_STK 	 TCP_TASK_STK[TCP_STK_SIZE];
+void tcp_server_init(void)
+{ 
+		OSTaskCreate(tcp_server_task,(void*)0,(OS_STK*)&TCP_TASK_STK[TCP_STK_SIZE - 1],TCP_TASK_PRIO);
+}

+ 74 - 0
app/HARDWARE/sources/udp_send.c

@@ -0,0 +1,74 @@
+
+#include "udp_send.h" 
+#include "main.h"
+#include <string.h>
+#include <stdio.h>
+#include "stm32f2xx.h"
+#include "lwip/opt.h"
+#include "lwip/tcp.h"
+#include "lwip/sys.h"
+#include "lwip/memp.h"
+#include "lwip/api.h"
+
+#include "lwip/sockets.h"
+
+volatile int8_t sockfd=-1;
+#define UDP_LOCAL_PORT 12345
+#define UDP_REMOTE_PORT 54321
+#define SERCER_IP_ADDRESS "192.168.2.211"       //接收服务器ip
+struct sockaddr_in remote_addr;
+
+int udp_log_start()
+{
+	int ret;
+	struct sockaddr_in local_addr;
+	// 创建UDP套接字
+  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+  if (sockfd < -1) {
+    perror("Error creating socket");
+		goto exit;
+  }
+	local_addr.sin_family=AF_INET;
+	local_addr.sin_port=htons(UDP_LOCAL_PORT);
+	local_addr.sin_addr.s_addr=INADDR_ANY;
+	ret = bind(sockfd, (struct sockaddr *)&local_addr, sizeof(local_addr));
+  if(ret < 0)
+	{ 
+    lwip_close(sockfd);
+    sockfd = -1;
+    goto exit;
+  }
+	//设置远程服务器地址 TODO:服务器地址配置后自动获取
+	remote_addr.sin_family=AF_INET;
+	remote_addr.sin_port=htons(UDP_REMOTE_PORT);
+	inet_aton(SERCER_IP_ADDRESS,&(remote_addr.sin_addr));
+	return 1;
+	
+exit:
+			return -1;
+}
+
+void udp_log_close()
+{
+	lwip_close(sockfd);
+	sockfd=-1;
+}
+
+int fputc(int ch, FILE *f)
+{
+	if(sockfd>=0)
+	{
+		sendto(sockfd, &ch, 1, 0, (struct sockaddr *)&remote_addr,sizeof(remote_addr));
+    return ch;
+	}
+	return 1;
+}
+
+int udp_send_printf(char *p)
+{
+	if(sockfd>=0)
+	{
+		 sendto(sockfd, p, strlen(p), 0, (struct sockaddr *)&remote_addr,sizeof(remote_addr));
+	}
+	return 1;
+}

+ 12 - 1
app/HARDWARE/sources/usart.c

@@ -1,4 +1,7 @@
 #include "usart.h"
+#include "mmodbus.h"
+#include "dlt645.h"
+#include "gateway_message.h"
 
 uint8_t UART6_RX_BUF[BUFF_SIZE];
 uint8_t UART6_RX_STAT=0;
@@ -281,6 +284,7 @@ void USART_485_config()
 	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
 	NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
 	NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
+
 	NVIC_Init(&NVIC_InitStruct);
 }
 /*
@@ -448,6 +452,13 @@ void Usart_SendHalfWord( USART_TypeDef * pUSARTx, uint16_t ch)
 	USART_SendData(pUSARTx,temp_l);	
 	while (USART_GetFlagStatus(pUSARTx, USART_FLAG_TXE) == RESET);	
 }
-
+void USART3_IRQHandler(){
+			GATEWAY_PARAMS *get;
+			get= get_gateway_config_params();
+			if(get->device_params->protocol == 3)
+			mmodbus_callback();
+			else if(get->device_params->protocol == 1 || get->device_params->protocol == 2)
+			dlt_callback();
+}
 
 /*********************************************END OF FILE**********************/

+ 135 - 93
app/MDKProject/lora_gateway.uvoptx

@@ -125,7 +125,11 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
+<<<<<<< HEAD
           <Name>-U69405423 -O111 -S6 -ZTIFSpeedSel500 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM)</Name>
+=======
+          <Name>-U69407005 -O111 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM)</Name>
+>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -153,6 +157,7 @@
           <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F2xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F207ZGTx$CMSIS\Flash\STM32F2xx_1024.FLM))</Name>
         </SetRegEntry>
       </TargetDriverDllRegistry>
+<<<<<<< HEAD
       <Breakpoint>
         <Bp>
           <Number>0</Number>
@@ -171,6 +176,9 @@
           <Expression>\\lora_gateway\../System/source/task.c\41</Expression>
         </Bp>
       </Breakpoint>
+=======
+      <Breakpoint/>
+>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
       <WatchWindow1>
         <Ww>
           <count>0</count>
@@ -185,14 +193,24 @@
         <Ww>
           <count>2</count>
           <WinNumber>1</WinNumber>
-          <ItemText>"0:"</ItemText>
+          <ItemText>"0:",0x0A</ItemText>
+        </Ww>
+        <Ww>
+          <count>3</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>mqtt_connectFlag,0x0A</ItemText>
+        </Ww>
+        <Ww>
+          <count>4</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>read_modbus_command</ItemText>
         </Ww>
       </WatchWindow1>
       <MemoryWindow1>
         <Mm>
           <WinNumber>1</WinNumber>
           <SubType>8</SubType>
-          <ItemText>http_data</ItemText>
+          <ItemText>buf</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>
@@ -220,7 +238,7 @@
         <aPa1>0</aPa1>
         <AscS4>0</AscS4>
         <aSer4>0</aSer4>
-        <StkLoc>0</StkLoc>
+        <StkLoc>1</StkLoc>
         <TrcWin>0</TrcWin>
         <newCpu>0</newCpu>
         <uProt>0</uProt>
@@ -958,6 +976,30 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
+    <File>
+      <GroupNumber>5</GroupNumber>
+      <FileNumber>57</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\HARDWARE\sources\tcp_server.c</PathWithFileName>
+      <FilenameWithoutPath>tcp_server.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>5</GroupNumber>
+      <FileNumber>58</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\HARDWARE\sources\udp_send.c</PathWithFileName>
+      <FilenameWithoutPath>udp_send.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
 
   <Group>
@@ -968,7 +1010,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>57</FileNumber>
+      <FileNumber>59</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -980,7 +1022,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>58</FileNumber>
+      <FileNumber>60</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -992,7 +1034,7 @@
     </File>
     <File>
       <GroupNumber>6</GroupNumber>
-      <FileNumber>59</FileNumber>
+      <FileNumber>61</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1012,7 +1054,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>60</FileNumber>
+      <FileNumber>62</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1024,7 +1066,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>61</FileNumber>
+      <FileNumber>63</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1036,7 +1078,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>62</FileNumber>
+      <FileNumber>64</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1048,7 +1090,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>63</FileNumber>
+      <FileNumber>65</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1060,7 +1102,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>64</FileNumber>
+      <FileNumber>66</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1072,7 +1114,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>65</FileNumber>
+      <FileNumber>67</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1084,7 +1126,7 @@
     </File>
     <File>
       <GroupNumber>7</GroupNumber>
-      <FileNumber>66</FileNumber>
+      <FileNumber>68</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1104,7 +1146,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>67</FileNumber>
+      <FileNumber>69</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1116,7 +1158,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>68</FileNumber>
+      <FileNumber>70</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1128,7 +1170,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>69</FileNumber>
+      <FileNumber>71</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1140,7 +1182,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>70</FileNumber>
+      <FileNumber>72</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1152,7 +1194,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>71</FileNumber>
+      <FileNumber>73</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1164,7 +1206,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>72</FileNumber>
+      <FileNumber>74</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1176,7 +1218,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>73</FileNumber>
+      <FileNumber>75</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1188,7 +1230,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>74</FileNumber>
+      <FileNumber>76</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1200,7 +1242,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>75</FileNumber>
+      <FileNumber>77</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1212,7 +1254,7 @@
     </File>
     <File>
       <GroupNumber>8</GroupNumber>
-      <FileNumber>76</FileNumber>
+      <FileNumber>78</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1232,7 +1274,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>77</FileNumber>
+      <FileNumber>79</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1244,7 +1286,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>78</FileNumber>
+      <FileNumber>80</FileNumber>
       <FileType>2</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1256,7 +1298,7 @@
     </File>
     <File>
       <GroupNumber>9</GroupNumber>
-      <FileNumber>79</FileNumber>
+      <FileNumber>81</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1276,7 +1318,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>10</GroupNumber>
-      <FileNumber>80</FileNumber>
+      <FileNumber>82</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1288,7 +1330,7 @@
     </File>
     <File>
       <GroupNumber>10</GroupNumber>
-      <FileNumber>81</FileNumber>
+      <FileNumber>83</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1308,7 +1350,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>82</FileNumber>
+      <FileNumber>84</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1320,7 +1362,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>83</FileNumber>
+      <FileNumber>85</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1332,7 +1374,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>84</FileNumber>
+      <FileNumber>86</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1344,7 +1386,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>85</FileNumber>
+      <FileNumber>87</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1356,7 +1398,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>86</FileNumber>
+      <FileNumber>88</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1368,7 +1410,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>87</FileNumber>
+      <FileNumber>89</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1380,7 +1422,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>88</FileNumber>
+      <FileNumber>90</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1392,7 +1434,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>89</FileNumber>
+      <FileNumber>91</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1404,7 +1446,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>90</FileNumber>
+      <FileNumber>92</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1416,7 +1458,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>91</FileNumber>
+      <FileNumber>93</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1428,7 +1470,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>92</FileNumber>
+      <FileNumber>94</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1440,7 +1482,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>93</FileNumber>
+      <FileNumber>95</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1452,7 +1494,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>94</FileNumber>
+      <FileNumber>96</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1464,7 +1506,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>95</FileNumber>
+      <FileNumber>97</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1476,7 +1518,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>96</FileNumber>
+      <FileNumber>98</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1488,7 +1530,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>97</FileNumber>
+      <FileNumber>99</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1500,7 +1542,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>98</FileNumber>
+      <FileNumber>100</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1512,7 +1554,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>99</FileNumber>
+      <FileNumber>101</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1524,7 +1566,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>100</FileNumber>
+      <FileNumber>102</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1536,7 +1578,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>101</FileNumber>
+      <FileNumber>103</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1548,7 +1590,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>102</FileNumber>
+      <FileNumber>104</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1560,7 +1602,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>103</FileNumber>
+      <FileNumber>105</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1572,7 +1614,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>104</FileNumber>
+      <FileNumber>106</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1584,7 +1626,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>105</FileNumber>
+      <FileNumber>107</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1596,7 +1638,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>106</FileNumber>
+      <FileNumber>108</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1608,7 +1650,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>107</FileNumber>
+      <FileNumber>109</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1620,7 +1662,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>108</FileNumber>
+      <FileNumber>110</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1632,7 +1674,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>109</FileNumber>
+      <FileNumber>111</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1644,7 +1686,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>110</FileNumber>
+      <FileNumber>112</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1656,7 +1698,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>111</FileNumber>
+      <FileNumber>113</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1668,7 +1710,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>112</FileNumber>
+      <FileNumber>114</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1680,7 +1722,7 @@
     </File>
     <File>
       <GroupNumber>11</GroupNumber>
-      <FileNumber>113</FileNumber>
+      <FileNumber>115</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1700,7 +1742,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>114</FileNumber>
+      <FileNumber>116</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1712,7 +1754,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>115</FileNumber>
+      <FileNumber>117</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1724,7 +1766,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>116</FileNumber>
+      <FileNumber>118</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1736,7 +1778,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>117</FileNumber>
+      <FileNumber>119</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1748,7 +1790,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>118</FileNumber>
+      <FileNumber>120</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1760,7 +1802,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>119</FileNumber>
+      <FileNumber>121</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1772,7 +1814,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>120</FileNumber>
+      <FileNumber>122</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1784,7 +1826,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>121</FileNumber>
+      <FileNumber>123</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1796,7 +1838,7 @@
     </File>
     <File>
       <GroupNumber>12</GroupNumber>
-      <FileNumber>122</FileNumber>
+      <FileNumber>124</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1816,7 +1858,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>123</FileNumber>
+      <FileNumber>125</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1828,7 +1870,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>124</FileNumber>
+      <FileNumber>126</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1840,7 +1882,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>125</FileNumber>
+      <FileNumber>127</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1852,7 +1894,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>126</FileNumber>
+      <FileNumber>128</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1864,7 +1906,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>127</FileNumber>
+      <FileNumber>129</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1876,7 +1918,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>128</FileNumber>
+      <FileNumber>130</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1888,7 +1930,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>129</FileNumber>
+      <FileNumber>131</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1900,7 +1942,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>130</FileNumber>
+      <FileNumber>132</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1912,7 +1954,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>131</FileNumber>
+      <FileNumber>133</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1924,7 +1966,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>132</FileNumber>
+      <FileNumber>134</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1936,7 +1978,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>133</FileNumber>
+      <FileNumber>135</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1948,7 +1990,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>134</FileNumber>
+      <FileNumber>136</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1960,7 +2002,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>135</FileNumber>
+      <FileNumber>137</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1972,7 +2014,7 @@
     </File>
     <File>
       <GroupNumber>13</GroupNumber>
-      <FileNumber>136</FileNumber>
+      <FileNumber>138</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -1992,7 +2034,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>14</GroupNumber>
-      <FileNumber>137</FileNumber>
+      <FileNumber>139</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2004,7 +2046,7 @@
     </File>
     <File>
       <GroupNumber>14</GroupNumber>
-      <FileNumber>138</FileNumber>
+      <FileNumber>140</FileNumber>
       <FileType>5</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2018,13 +2060,13 @@
 
   <Group>
     <GroupName>DLT645</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>139</FileNumber>
+      <FileNumber>141</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2036,7 +2078,7 @@
     </File>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>140</FileNumber>
+      <FileNumber>142</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2048,9 +2090,9 @@
     </File>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>141</FileNumber>
+      <FileNumber>143</FileNumber>
       <FileType>1</FileType>
-      <tvExp>0</tvExp>
+      <tvExp>1</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
       <bDave2>0</bDave2>
       <PathWithFileName>..\dlt\src\dlt645_2007.c</PathWithFileName>
@@ -2060,7 +2102,7 @@
     </File>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>142</FileNumber>
+      <FileNumber>144</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2072,7 +2114,7 @@
     </File>
     <File>
       <GroupNumber>15</GroupNumber>
-      <FileNumber>143</FileNumber>
+      <FileNumber>145</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>
@@ -2092,7 +2134,7 @@
     <RteFlg>0</RteFlg>
     <File>
       <GroupNumber>16</GroupNumber>
-      <FileNumber>144</FileNumber>
+      <FileNumber>146</FileNumber>
       <FileType>1</FileType>
       <tvExp>0</tvExp>
       <tvExpOptDlg>0</tvExpOptDlg>

+ 25 - 4
app/MDKProject/lora_gateway.uvprojx

@@ -10,14 +10,14 @@
       <TargetName>Target 1</TargetName>
       <ToolsetNumber>0x4</ToolsetNumber>
       <ToolsetName>ARM-ADS</ToolsetName>
-      <pCCUsed>5060750::V5.06 update 6 (build 750)::ARMCC</pCCUsed>
+      <pCCUsed>5060960::V5.06 update 7 (build 960)::.\ARMCC</pCCUsed>
       <uAC6>0</uAC6>
       <TargetOption>
         <TargetCommonOption>
           <Device>STM32F207ZGTx</Device>
           <Vendor>STMicroelectronics</Vendor>
-          <PackID>Keil.STM32F2xx_DFP.2.9.0</PackID>
-          <PackURL>http://www.keil.com/pack</PackURL>
+          <PackID>Keil.STM32F2xx_DFP.2.10.0</PackID>
+          <PackURL>http://www.keil.com/pack/</PackURL>
           <Cpu>IRAM(0x20000000,0x00020000) IROM(0x08000000,0x00100000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE</Cpu>
           <FlashUtilSpec></FlashUtilSpec>
           <StartupFile></StartupFile>
@@ -185,6 +185,8 @@
             <uocXRam>0</uocXRam>
             <RvdsVP>0</RvdsVP>
             <RvdsMve>0</RvdsMve>
+            <RvdsCdeCp>0</RvdsCdeCp>
+            <nBranchProt>0</nBranchProt>
             <hadIRAM2>0</hadIRAM2>
             <hadIROM2>0</hadIROM2>
             <StupSel>8</StupSel>
@@ -351,7 +353,7 @@
             <NoWarn>0</NoWarn>
             <uSurpInc>0</uSurpInc>
             <useXO>0</useXO>
-            <uClangAs>0</uClangAs>
+            <ClangAsOpt>4</ClangAsOpt>
             <VariousControls>
               <MiscControls></MiscControls>
               <Define></Define>
@@ -682,6 +684,16 @@
               <FileType>1</FileType>
               <FilePath>..\HARDWARE\sources\malloc.c</FilePath>
             </File>
+            <File>
+              <FileName>tcp_server.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\HARDWARE\sources\tcp_server.c</FilePath>
+            </File>
+            <File>
+              <FileName>udp_send.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\HARDWARE\sources\udp_send.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>
@@ -1189,4 +1201,13 @@
     <files/>
   </RTE>
 
+  <LayerInfo>
+    <Layers>
+      <Layer>
+        <LayName>lora_gateway</LayName>
+        <LayPrjMark>1</LayPrjMark>
+      </Layer>
+    </Layers>
+  </LayerInfo>
+
 </Project>

Diferenças do arquivo suprimidas por serem muito extensas
+ 18715 - 0
app/OBJ/lora_gateway.hex


+ 78 - 50
app/System/includes/gateway_message.h

@@ -2,89 +2,68 @@
 #define __GATEWAY_MESSAGE_H
 #include "stm32f2xx.h"
 
-
-
-
-
-// 节点所存储的modbus写命令
-typedef struct _NODE_WRITE_MODBUS_COMMAND
+// 网关所存储的modbus写命令
+typedef struct _GATEWAY_WRITE_MODBUS_COMMAND
 {
+	uint16_t registerByteNum;
 	uint8_t slaveAddress;
 	uint8_t functionCode;
 	uint8_t dataType;          //数据类型
-	uint8_t slaveAdress;
 	uint8_t keyword[20]; // 所写属性的名称
 	uint8_t bigLittleFormat;
 	uint16_t registerAddress;	// 寄存器地址
 	uint8_t write_command_flag; // 是否成功写入的标志
-	struct _NODE_WRITE_MODBUS_COMMAND *nextParams;
-} NODE_WRITE_MODBUS_COMMAND;
-// 节点所存储的modbus读命令
-typedef struct _NODE_READ_MODBUS_COMMAND
+	struct _GATEWAY_WRITE_MODBUS_COMMAND *nextParams;
+} GATEWAY_WRITE_MODBUS_COMMAND;
+
+// 网关所存储的modbus读命令
+typedef struct _GATEWAY_READ_MODBUS_COMMAND
 {
 	uint8_t slaveAddress;
 	uint8_t functionCode;
 	uint8_t keyword[20]; // 所读属性的名称
 	uint16_t registerAddress;  // 寄存器地址
 	uint8_t read_command_flag; // 是否成功读取到的标志
-	uint8_t value[4];          //读取到的数据值
+	uint32_t value;          //读取到的数据值
 	uint16_t registerByteNum;
 	uint8_t decimalPoint;
-	struct _NODE_READ_MODBUS_COMMAND *nextParams;
-} NODE_READ_MODBUS_COMMAND;
+	struct _GATEWAY_READ_MODBUS_COMMAND *nextParams;
+} GATEWAY_READ_MODBUS_COMMAND;
+
+
 // 节点所存储都DLT645读指令
-typedef struct _NODE_READ_DLT645_COMMAND
+typedef struct _GATEWAY_READ_DLT645_COMMAND
 {
 	uint8_t deviceID645[6];
 	uint8_t keyword[20];   // 所读属性的名称
 	uint32_t Identification; // 645数据标识
 	uint8_t data[9];	   // 读到的数据
 	uint8_t rxLen;		   // 从机应答值的长度
-	struct _NODE_READ_DLT645_COMMAND *nextParams;
-} NODE_READ_DLT645_COMMAND;
+	struct _GATEWAY_READ_DLT645_COMMAND *nextParams;
+} GATEWAY_READ_DLT645_COMMAND;
 
 typedef struct _PARAMS_PROTOCOL_COMMAND
 {
-	NODE_READ_MODBUS_COMMAND   *node_read_modbus_command;
-	NODE_WRITE_MODBUS_COMMAND  *node_write_modbus_command;
-	NODE_READ_DLT645_COMMAND   *node_read_dlt645_command;
+	GATEWAY_READ_MODBUS_COMMAND   *gateway_read_modbus_command;
+	GATEWAY_WRITE_MODBUS_COMMAND  *gateway_write_modbus_command;
+	GATEWAY_READ_DLT645_COMMAND   *gateway_read_dlt645_command;
 }PARAMS_PROTOCOL_COMMAND;
 
+
 // 节点包含的设备信息
 typedef struct _DEVICE_PARAMS
 {
 	uint8_t aliveflag; // 存活证明(由轮询来进行保证,当有轮询回应是确定其存活,当链路变化时立即上报设备已经死去,当轮询有相应的相应值时去上报已经存活)
 	uint8_t deviceID[20];
-	uint8_t protocol;  // 所属协议类型                  1:modbus read 2:modbus write     3:dlt97  4:dlt07            一个设备只能存在一个协议
-	
+	uint8_t protocol;  // 所属协议类型   1:modbus read 2:modbus write 3:dlt97  4:dlt07    一个设备只能存在一个协议	
 	uint8_t MDBbigLittleFormat;
-	uint8_t MDBdataType;
-	
-	
+	uint8_t MDBdataType;	
 	PARAMS_PROTOCOL_COMMAND	*params;
 	struct _DEVICE_PARAMS *nextDevice; // 指向下一个设备地址
 } DEVICE_PARAMS;
 
-typedef struct _NODE_PARAMS
-{                    
-	uint8_t node_address[3];
-	// 外设的串口工作属性仅只有一个
-	uint32_t baudrate;	 // 波特率
-	uint8_t dataBits;	 // 数据位
-	uint8_t checkBit;	 // 校验位
-	uint8_t stopBit;	 // 停止位
-	uint8_t flowControl; // 流控制
-	// lora通信的属性设置
-	uint8_t RFFrequency;        //载波频率
-	uint8_t SignalBw;           //信号带宽
-	uint8_t SpreadingFactor;    //扩频因子
-	uint8_t ErrorCoding;        //编码率
-	// 包含的设备结构体
-	uint8_t deviceCount;
-	DEVICE_PARAMS *device_params;
-	struct _NODE_PARAMS *nextNode; // 下一个设备所存地址如果没有下一个设备指向NULL
-} NODE_PARAMS;
 
+// 网关包含的设备信息
 typedef struct _GATEWAY_PARAMS
 {
 	uint8_t data_valid_flag;  // 数据有效标志  0xF1:有效  其它:无效
@@ -92,21 +71,70 @@ typedef struct _GATEWAY_PARAMS
 	uint16_t port;			  // MQTT服务器端口号
 	uint8_t messageTopic[50]; // MQTT消息主题
 	uint8_t commandTopic[50]; // MQTT指令主题
+	uint8_t username[20];			//MQTT用户名
+	uint8_t passwd[20];				// MQTT用户密码
 	uint8_t deviceId[25];	  // 设备ID
 	uint8_t dataSource;		  // 协议类型                 0 保留 1 表示645协议 2表示modbus协议
-	uint8_t dataType645;	  // 645协议数据类型          0保留  1 表示07版本  2表示97版本
+	uint8_t dataType645;	  // 645协议数据类型          0 保留 1 表示07版本  2表示97版本
 	uint32_t pollTime;		  // 轮询时间
 	uint32_t inboundTime;
 	uint8_t state;			 // 检测是否上位机配置过当上位机配置过该状态位,则以后均不走http获取相应配置 置位值为0xF1
 	uint8_t gatewayId[10];	 // 固化信息
 	uint8_t gatewayMode[10]; // 工作模式、后续版本迭代使用
-	// 网关相关信息
-	uint8_t gateName[10];
+		uint8_t gateName[10];		// 网关相关信息
 
-	// 附属设备相关信息
-	NODE_PARAMS *node_params;
+	// 包含的设备结构体
+	uint8_t deviceCount;
+	DEVICE_PARAMS *device_params;
+		// 外设的串口工作属性仅只有一个
+	uint32_t baudrate;	 // 波特率
+	uint8_t dataBits;	 // 数据位
+	uint8_t checkBit;	 // 校验位
+	uint8_t stopBit;	 // 停止位
+	uint8_t flowControl; // 流控制
+	uint8_t parity;				//校验位
+	uint8_t bandwidth;	
 } GATEWAY_PARAMS;
 
 void addGatewayParams(char *gatewayString);
-GATEWAY_PARAMS *get_gateway_config_params();
+int parseIntField(const char *data, const char *field);
+void parseStringField(const char *data, const char *field, char *value);
+GATEWAY_PARAMS *get_gateway_config_params(void);
+int extract_substring(const char *input_string, const char *start_token, const char *end_token, char *result);
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void analysis_read_data(DEVICE_PARAMS *device, char* buf);
+
+typedef struct _MODBUS_READ_DATA
+{
+	uint8_t deviceId[20];
+	// modbus读出的数据名
+	uint8_t power;	
+	uint8_t temp;
+	uint8_t mode;
+	uint8_t fan;
+	uint8_t roomTemp;
+	uint8_t fault;
+	
+	struct _MODBUS_READ_DATA *nextParams;
+} MODBUS_READ_DATA;
+
+typedef struct _DLT_READ_DATA
+{
+	uint8_t deviceId[20];
+	// dlt读出的数据名
+	uint8_t deviceID645[6];
+	uint8_t keyword[20];   // 所读属性的名称
+	uint32_t Identification; // 645数据标识
+	uint8_t data[9];
+	
+	struct _DLT_READ_DATA *nextParams;
+} DLT_READ_DATA;
+
+typedef struct _READ_DATA
+{
+	MODBUS_READ_DATA   *read_modbus_data;
+	DLT_READ_DATA  		 *read_dlt645_data;
+}READ_DATA;
 #endif

+ 2 - 2
app/System/includes/json_queue.h

@@ -4,10 +4,10 @@
 #include "string.h"
 void creat_queue(void);
 typedef struct {
-    char *p;
     uint32_t stringLength;
+    char *p;
 } StringInfo;
 
 
 
-#endif
+#endif

+ 2 - 2
app/System/includes/myFile.h

@@ -9,6 +9,6 @@
 
 void write_file(const char* filename, const char* data, uint32_t length);
 void read_file(const char* filename, char* data);
-void ViewRootDir();
+void ViewRootDir(void);
 void DeleteDirFile(const char* filename);
-#endif
+#endif

+ 6 - 1
app/System/includes/node_data_acquisition.h

@@ -5,5 +5,10 @@
 #include "dlt645_port.h"
 void data_acquisition(void);
 extern uint8_t protocol_485;
+<<<<<<< HEAD
 void rs_485_test();
-#endif
+#endif
+=======
+void rs_485_test(void);
+#endif
+>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c

+ 3 - 3
app/System/includes/node_message.h

@@ -60,9 +60,9 @@ typedef struct _NODE_DEVICE_PARAMS
     PARAMS params[20];              
 }NODE_DEVICE_PARAMS;
 
-NODE_DEVICE_PARAMS *get_node_receive_params();
-void free_all_node_params();
+NODE_DEVICE_PARAMS *get_node_receive_params(void);
+void free_all_node_params(void);
 extern uint8_t protocol_485;
 #endif
 
-#endif
+#endif

+ 1 - 1
app/System/includes/protocol.h

@@ -11,4 +11,4 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size);
 uint8_t SlaveProtocolAnalysis(uint8_t *buff, uint16_t len);
 void nodeSendReaddValue(uint8_t *string,uint16_t *size);
 int GatewayProtocolAnalysis(uint8_t *string, uint16_t len);
-#endif
+#endif

+ 0 - 1
app/System/includes/sys_http.h

@@ -1,7 +1,6 @@
 #ifndef SYS_HTTP_H
 #define SYS_HTTP_H
 
-
 void http_getDemo(void);
 
 void http_postDemo(void);

+ 12 - 8
app/System/includes/sys_mqtt.h

@@ -2,7 +2,9 @@
 #define SYS_MQTT_H
 
 #include "ucos_ii.h"
+#include "gateway_message.h"
 #include "json_queue.h"
+
 #define  MBOX_NETWORK_ERROR     0xf0000000
 
 #define  MBOX_MQTT_QOS1PUBACK   0x10000001
@@ -18,31 +20,33 @@
 
 //#define  MQTT_SERVER_ADDR  "192.168.0.116"
 //#define  MQTT_SERVER_ADDR  "192.168.0.183"
-#define  MQTT_SERVER_ADDR  "36.134.23.11"
-#define  MQTT_SERVER_PORT  1883
+//#define  MQTT_SERVER_ADDR  "36.134.23.11"
+//#define  MQTT_SERVER_PORT  1883
 
 #define  CLIENT_ID     "stm32f207test"       //
 //#define  USER_NAME     "emqxxx"     
 //#define  PASSWORD      "123456" 
-#define  USER_NAME     NULL  
-#define  PASSWORD      NULL
+//#define  USER_NAME     NULL  
+//#define  PASSWORD      NULL
 #define  KEEPLIVE_TIME   120
 #define  MQTT_VERSION    4
 
-#define  TOPICSTM32    "test/stm32"
-#define  TOPICPC       "test/pc"
+//#define  TOPICSTM32    "test/stm32"
+//#define  TOPICPC       "test/pc"
 //#define  TOPICTEST     "/device/cxw0817111032"
 
 
 
 extern int mqtt_connectFlag;
 extern OS_EVENT *mqtt_sendMseeageMbox;
+extern OS_EVENT *mqtt_recvMseeageMbox;
 extern OS_EVENT *JsonQ;
 void mqtt_threadCreate(void);
 
-#define jsonMaxSize 1000
-extern char pubJsonString[jsonMaxSize];
 
+#define jsonMaxSize 2 * 1024
+extern char pubJsonString[jsonMaxSize];
+extern char pubJsonStringCopy[jsonMaxSize];
 #endif 
 
 

+ 3 - 1
app/System/includes/sys_sx1278.h

@@ -1,8 +1,10 @@
 #ifndef SYS_SX1278_H
 #define SYS_SX1278_H
 
-#define SX1278_TASK_PRIO 8
+#define SX1278_TASK_PRIO 11
 #define SX1278_STK_SIZE  1024
 
+
+
 extern void sx1278_send_task(void *pdata);
 #endif

+ 8 - 2
app/System/includes/task.h

@@ -3,12 +3,18 @@
 #include "includes.h"
 #include "stm32f2xx.h"
 #include "radio.h"
+#include "gateway_message.h"
 //Ö÷ÒªµÄÊý¾Ý´¦ÀíÏß³Ì
 #define DATA_TASK_PRIO 8
 #define DATA_STK_SIZE  2*1024
-
+#define   GetCurrentTime()  OSTimeGet()
 extern void data_task(void *pdata);
-
 extern tRadioDriver *Radio;
 
+void write_modbus_data(char* buf);
+void send_mqtt(char*buf);
+void find_difference(char* data1, char* data2, char* string);
+int read_device_data1(DEVICE_PARAMS *current_device,char* buf);
+int read_device_data2(DEVICE_PARAMS *current_device,char* buf);
+
 #endif

+ 7 - 0
app/System/includes/time_count.h

@@ -0,0 +1,7 @@
+#ifndef __TIME_COUNT_H
+#define __TIME_COUNT_H
+
+int time1;
+int time2;
+
+#endif

+ 137 - 96
app/System/source/gateway_message.c

@@ -3,8 +3,10 @@
 #include <stdlib.h>
 #include "protocol.h"
 #include "malloc.h"
+#include <stdio.h>   
 #include "gateway_message.h"
 
+
 GATEWAY_PARAMS gateway_config_params = {0};
 
 GATEWAY_PARAMS *get_gateway_config_params()
@@ -14,120 +16,74 @@ GATEWAY_PARAMS *get_gateway_config_params()
 
 void parseStringField(const char *data, const char *field, char *value);
 int parseIntField(const char *data, const char *field);
-void addNode(char *nodestring);
-void addDevice(char *string, NODE_PARAMS *node);
+//void addNode(char *nodestring);
+void addDevice(char *string);
 int extract_substring(const char *input_string, const char *start_token, const char *end_token, char *result);
 void addSensorListParams(char *paramString, DEVICE_PARAMS *device);
 void addCommandListParams(char *paramString, DEVICE_PARAMS *device);
 /**
  * @brief  解析输入字符串网关结构体信息,将数据保存
- * @param  char *nodestring 输入字符串的数据
+ * @param  char *gatewayString 输入字符串的数据
  * @retval 无
  */
-void addGatewayParams(char *gatewayString)
+	void addGatewayParams(char *gatewayString)
 {
-    parseStringField(gatewayString, "\"commandTopic\":\"", (char *)&gateway_config_params.commandTopic);
-    parseStringField(gatewayString, "\"messageTopic\":\"", (char *)&gateway_config_params.messageTopic);
-    parseStringField(gatewayString, "\"deviceId\":\"", (char *)&gateway_config_params.deviceId);
-    parseStringField(gatewayString, "\"host\":\"", (char *)&gateway_config_params.host);
-    gateway_config_params.port = parseIntField(gatewayString, "\"port\":");
-    gateway_config_params.node_params = NULL;
-    gateway_config_params.pollTime = parseIntField(gatewayString, "\"pollTime\":");
-	  char *nodeString = strstr(gatewayString,"nodeList");  //移位置到节点数据开始处    
+		//gateway_config_params.device_params = NULL;
+		gateway_config_params.port = parseIntField(gatewayString, "\"port\":");
+		gateway_config_params.stopBit = parseIntField(gatewayString, "\"stopBit\":");
+		gateway_config_params.dataBits = parseIntField(gatewayString, "\"dataBit\":");
+		gateway_config_params.baudrate = parseIntField(gatewayString, "\"baudrate\":");
+		gateway_config_params.checkBit = parseIntField(gatewayString, "\"checkBit\":");
+		gateway_config_params.inboundTime= parseIntField(gatewayString, "\"inboundTime\":");
+		
+		parseStringField(gatewayString, "\"host\":\"", (char *)&gateway_config_params.host);
+		parseStringField(gatewayString, "\"deviceId\":\"", (char *)&gateway_config_params.deviceId);
+		parseStringField(gatewayString, "\"commandTopic\":\"", (char *)&gateway_config_params.commandTopic);
+		parseStringField(gatewayString, "\"messageTopic\":\"", (char *)&gateway_config_params.messageTopic);
+		parseStringField(gatewayString, "\"username\":\"", (char *)&gateway_config_params.username);
+		parseStringField(gatewayString, "\"password\":\"", (char *)&gateway_config_params.passwd);
+	
+		char *deviceString = strstr(gatewayString,"deviceList");  //移位置到节点数据开始处
 		
-    while (1)
-    {
-      addNode(nodeString);
-			nodeString=nodeString;
-			nodeString=strstr(nodeString,"}");
-			nodeString[0]='A';
-			nodeString++;
-			if(nodeString[0]==']')//数组结束标志、
-			{
-				break;
-			}
-    }
-
-}
-
-/**
- * @brief  解析输入的字符串节点信息,并将此节点信息挂载在网关结构体的节点下面
- * @param  char *nodestring
- * @retval 无
-        注:node内包含的设备名称device_1在别的节点下也可能包含,所以在解析节点时要先将数据截取出来让匹配不会越界到别的节点
- */
-
-void addNode(char *nodestring)
-{
-    // 新增一个节点的设备并解析最外层的节点属性
-    char *deviceString = (char *)nodestring; // 用于移位解析device设备信息
-    NODE_PARAMS *newNode = malloc(sizeof(NODE_PARAMS));
-    newNode->device_params = NULL; // 先将其设备挂载为NULL
-    newNode->nextNode = NULL;      // 下一个设备的挂载为NULL
-	  char nodeIdString[5];
-    parseStringField(nodestring, "\"nodeId\":\"", (char *)&nodeIdString);
-    for (int j = 0; j < 2; j++)
-    {
-      uint8_t byte;
-      sscanf((const char *)&nodeIdString[j * 2], "%2hhx", &byte);
-      newNode->node_address[j]=byte;
-    }
-    newNode->RFFrequency = parseIntField(nodestring, "\"RFFrequency\":");
-    newNode->SignalBw = parseIntField(nodestring, "\"SignalBw\":");
-    newNode->SpreadingFactor = parseIntField(nodestring, "\"SpreadingFactor\":");
-    newNode->ErrorCoding = parseIntField(nodestring, "\"ErrorCoding\":");
 		
-		deviceString=strstr(nodestring,"deviceList");//移位置到设备数组起始处
-    while (1)
+		while (1)
     {
         if (deviceString)
         {
-           addDevice(deviceString, newNode); // 往此节点下挂载设备信息
+           addDevice(deviceString); // 往此地址下挂载设备信息
            deviceString=deviceString;//重新获取设备字符串的位置
 					 deviceString = strstr(deviceString, "}"); 
 					 deviceString[0]='A';
 					 deviceString++;
 					 if(deviceString[0]==']')
 					 {
-						 break;
+					 break;
 					 }
         }
         else
         {
             return;
         }
-        /* code */
-    }
- 
-
-    // 添加节点到网关链表中
-    if (gateway_config_params.node_params == NULL)
-    {
-        gateway_config_params.node_params = newNode;
-    }
-    else
-    {
-        NODE_PARAMS *current = gateway_config_params.node_params;
-        while (current->nextNode != NULL)
-        {
-            current = current->nextNode;
-        }
-        current->nextNode = newNode;
     }
 }
+
 /**
  * @brief  解析输入字段的字符串,解析出属于该节点下的设备信息
  * @param  uint8_t *string输入的字符串数据,NODE_PARAMS *node节点信息
  * @retval 无
  */
-void addDevice(char *deviceString, NODE_PARAMS *node)
+
+void addDevice(char *deviceString)
 {
     char *paramString = (char *)deviceString; // 属性指针
-    // 创建新设备页
-    DEVICE_PARAMS *newDevicePage = (DEVICE_PARAMS *)malloc(sizeof(DEVICE_PARAMS));
+		DEVICE_PARAMS *newDevicePage = (DEVICE_PARAMS *)malloc(sizeof(DEVICE_PARAMS));    // 创建新设备页
     newDevicePage->nextDevice = NULL;
-    parseStringField(deviceString, "\"deviceId\":\"", (char *)&newDevicePage->deviceID);
     newDevicePage->protocol = parseIntField(deviceString, "\"protocol\":");
+		newDevicePage->MDBdataType = parseIntField(deviceString, "\"dataType\":");
+		newDevicePage->MDBbigLittleFormat = parseIntField(deviceString, "\"bigLittleFormat\":");
+		
+		parseStringField(deviceString, "\"deviceId\":\"", (char *)&newDevicePage->deviceID);
+	
     newDevicePage->params = (PARAMS_PROTOCOL_COMMAND *)malloc(sizeof(PARAMS_PROTOCOL_COMMAND));
 
     paramString = strstr(paramString, "\"sensorData\":["); // 找到该节点的轮询上发属性
@@ -141,7 +97,7 @@ void addDevice(char *deviceString, NODE_PARAMS *node)
         if (paramString[0] == ']')
         {
             paramString = (char *)deviceString; // 复原指针位置
-            break;                              // 找到了结束符,跳出循环
+						break;                              // 找到了结束符,跳出循环
         }
     }
 		if(newDevicePage->protocol==MODBUS)  //如果为modbus的话解析写指令
@@ -160,8 +116,8 @@ void addDevice(char *deviceString, NODE_PARAMS *node)
 					paramString++;
 					if (paramString[0] == ']')
 					{
-						paramString = (char *)deviceString;
-						break;
+						paramString = (char *)deviceString;// 复原指针位置
+						break;														 // 找到了结束符,跳出循环
 					}
 				}
 			}
@@ -169,13 +125,13 @@ void addDevice(char *deviceString, NODE_PARAMS *node)
     // 解析下发的mqtt存储信息下发控制指令
 		
     // 添加设备页到链表末尾
-    if (node->device_params == NULL)
+    if (gateway_config_params.device_params == NULL)
     {
-        node->device_params = newDevicePage;
+        gateway_config_params.device_params = newDevicePage;
     }
     else
     {
-        DEVICE_PARAMS *current = node->device_params;
+        DEVICE_PARAMS *current = gateway_config_params.device_params;
         while (current->nextDevice != NULL)
         {
             current = current->nextDevice;
@@ -197,7 +153,7 @@ void addSensorListParams(char *paramString, DEVICE_PARAMS *device)
     case DLT645_97:
     case DLT645_07:
 		{
-        NODE_READ_DLT645_COMMAND *read_dlt645_command = malloc(sizeof(NODE_READ_DLT645_COMMAND));
+        GATEWAY_READ_DLT645_COMMAND *read_dlt645_command = malloc(sizeof(GATEWAY_READ_DLT645_COMMAND));
         read_dlt645_command->Identification = parseIntField(paramString, "\"identifier645\":");
         parseStringField(paramString, "\"identifier\":\"", (char *)&read_dlt645_command->keyword);
         char *string = mymalloc(SRAMIN, 13);
@@ -209,13 +165,13 @@ void addSensorListParams(char *paramString, DEVICE_PARAMS *device)
           read_dlt645_command->deviceID645[j]=byte;
         }
         myfree(SRAMIN, string);
-        if (device->params->node_read_dlt645_command == NULL)
+        if (device->params->gateway_read_dlt645_command == NULL)
         {
-            device->params->node_read_dlt645_command = read_dlt645_command;
+            device->params->gateway_read_dlt645_command = read_dlt645_command;
         }
         else
         {
-            NODE_READ_DLT645_COMMAND *current = device->params->node_read_dlt645_command;
+            GATEWAY_READ_DLT645_COMMAND *current = device->params->gateway_read_dlt645_command;
             while (current->nextParams != NULL)
             {
                 current = current->nextParams;
@@ -223,23 +179,25 @@ void addSensorListParams(char *paramString, DEVICE_PARAMS *device)
             current->nextParams = read_dlt645_command;
         }
 			}
+				
         break;
     case MODBUS:
 		{
-        NODE_READ_MODBUS_COMMAND *read_modbus_command = malloc(sizeof(NODE_READ_MODBUS_COMMAND));
+        GATEWAY_READ_MODBUS_COMMAND *read_modbus_command = malloc(sizeof(GATEWAY_READ_MODBUS_COMMAND));
 				parseStringField(paramString,"\"identifier\":\"",(char *)&read_modbus_command->keyword);
         read_modbus_command->decimalPoint = parseIntField(paramString, "\"precise\":");
         read_modbus_command->functionCode = parseIntField(paramString, "\"rFunctionCode\":");
         read_modbus_command->slaveAddress = parseIntField(paramString, "\"slaveAddress\":");
         read_modbus_command->registerAddress = parseIntField(paramString, "\"registerAddress\":");
         read_modbus_command->registerByteNum = parseIntField(paramString, "\"registerByteNum\":");
-        if (device->params->node_read_modbus_command == NULL)
+        
+			if (device->params->gateway_read_modbus_command== NULL)
         {
-            device->params->node_read_modbus_command = read_modbus_command;
+            device->params->gateway_read_modbus_command = read_modbus_command;
         }
         else
         {
-            NODE_READ_MODBUS_COMMAND *current = device->params->node_read_modbus_command;
+            GATEWAY_READ_MODBUS_COMMAND *current = device->params->gateway_read_modbus_command;
             while (current->nextParams != NULL)
             {
                 current = current->nextParams;
@@ -260,19 +218,20 @@ void addSensorListParams(char *paramString, DEVICE_PARAMS *device)
 void addCommandListParams(char *paramString, DEVICE_PARAMS *device)
 {
 	
- 	NODE_WRITE_MODBUS_COMMAND *write_modbus_command=malloc(sizeof(NODE_WRITE_MODBUS_COMMAND));
+ 	GATEWAY_WRITE_MODBUS_COMMAND *write_modbus_command=malloc(sizeof(GATEWAY_WRITE_MODBUS_COMMAND));
 	parseStringField(paramString,"\"identifier\":\"",(char *)&write_modbus_command->keyword);
 
 	write_modbus_command->functionCode=parseIntField(paramString, "\"wFunctionCode\":");
 	write_modbus_command->slaveAddress=parseIntField(paramString, "\"slaveAddress\":");
 	write_modbus_command->registerAddress = parseIntField(paramString, "\"registerAddress\":");
-	if(device->params->node_write_modbus_command == NULL)
+	write_modbus_command->registerByteNum = parseIntField(paramString, "\"registerByteNum\":");
+	if(device->params->gateway_write_modbus_command == NULL)
 	{
-		device->params->node_write_modbus_command=write_modbus_command;
+		device->params->gateway_write_modbus_command=write_modbus_command;
 	}
 	else
 	{
-		NODE_WRITE_MODBUS_COMMAND *current=device->params->node_write_modbus_command;
+		GATEWAY_WRITE_MODBUS_COMMAND *current=device->params->gateway_write_modbus_command;
     while (current->nextParams != NULL)
     {
       current = current->nextParams;
@@ -351,3 +310,85 @@ int extract_substring(const char *input_string, const char *start_token, const c
     }
     return 1;
 }
+
+//void addparams(DEVICE_PARAMS *device, char* pbuf){
+//	GATEWAY_PARAMS* get;
+//	get = get_gateway_config_params();
+//	switch (device->protocol)
+//	{
+////			case DLT645_97:
+////			case DLT645_07:
+////			{
+////					DLT_READ_DATA *read_dlt645_data= mymalloc(SRAMEX, sizeof(DLT_READ_DATA));
+////					read_dlt645_data->Identification = parseIntField(pbuf, "\"identifier645\":");
+////					parseStringField(pbuf, "\"identifier\":\"", (char *)&read_dlt645_data->keyword);
+////					char *string = mymalloc(SRAMIN, 13);
+////					parseStringField(pbuf, "\"deviceID645\":\"", string);
+////					for (int j = 0; j < 6; j++)
+////					{
+////							uint8_t byte;
+////							sscanf((const char *)&string[j * 2], "%2hhx", &byte);
+////							read_dlt645_data->deviceID645[j]=byte;
+////					}
+////					myfree(SRAMIN, string);
+////					if (readData->read_dlt645_data == NULL)
+////					{
+////							readData->read_dlt645_data = read_dlt645_data;
+////					}
+////					else
+////					{
+////							DLT_READ_DATA *current = readData->read_dlt645_data;
+////							while (current->nextParams != NULL)
+////							{
+////									current = current->nextParams;
+////							}
+////							current->nextParams = read_dlt645_data;
+////					}
+////				}
+////						
+////					break;
+//			case MODBUS:
+//			{
+//						parseStringField(pbuf,"\"deviceId\":\"",(char *)&get->device_params->deviceID);
+//						get->device_params->params->gateway_read_modbus_command->value = parseIntField(pbuf, "\"power\":");
+//				
+//						if (readData->read_modbus_data == NULL)
+//						{
+//								readData->read_modbus_data = read_modbus_command;
+//						}
+//						else
+//						{
+//								MODBUS_READ_DATA *current = readData->read_modbus_data;
+//								while (current->nextParams != NULL)
+//								{
+//										current = current->nextParams;
+//								}
+//								current->nextParams = read_modbus_command;
+//						}
+//					}
+//					break;
+//			default:
+//					break;
+//	}
+//}
+
+
+
+//void analysis_read_data(DEVICE_PARAMS *device, char* buf){	
+////		READ_DATA* readData = mymalloc(SRAMEX, sizeof(READ_DATA));
+//		char* pbuf = mymalloc(SRAMEX, strlen(buf));
+//		memcpy(pbuf,buf,strlen(buf));
+//		while(1)
+//		{				
+////			addparams(device, readData ,pbuf);
+//			addparams(device, pbuf);
+//			pbuf = strstr(pbuf, "}");
+//			pbuf[0]='A';
+//			pbuf++;
+//			if (pbuf[0] == ']')
+//			{
+//				myfree(SRAMEX, pbuf);
+//				break;														
+//			}
+//		}	
+//}

+ 19 - 40
app/System/source/protocol.c

@@ -66,19 +66,9 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 	GATEWAY_PARAMS *gateway;
 	gateway = get_gateway_config_params();
 
-	// 将当前的节点指针指到需要读取的节点位置
-	NODE_PARAMS *currentNode = gateway->node_params;
-	while (nodeIndex)
-	{
-		currentNode = currentNode->nextNode;
-		nodeIndex--;
-	}
-	memset(string, 0, 256); // 清除上一次数据
-	// 将首字符用nodeAdress
-	string[0] = currentNode->node_address[0];
-	string[1] = currentNode->node_address[1];
+
 	// 找到当前的设备结束位置
-	DEVICE_PARAMS *currentDevice = currentNode->device_params;
+	DEVICE_PARAMS *currentDevice = gateway->device_params;
 	while (nowDeviceNum)
 	{
 		currentDevice = currentDevice->nextDevice;
@@ -86,8 +76,8 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 	}
 
 	// 移动位置到结束位置属性的下一位
-	NODE_READ_MODBUS_COMMAND *currentModbusParams = currentDevice->params->node_read_modbus_command;
-	NODE_READ_DLT645_COMMAND *currentDlt645Params = currentDevice->params->node_read_dlt645_command;
+	GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = currentDevice->params->gateway_read_modbus_command;
+	GATEWAY_READ_DLT645_COMMAND *currentDlt645Params = currentDevice->params->gateway_read_dlt645_command;
 	switch (currentDevice->protocol)
 	{
 	case MODBUS:
@@ -113,7 +103,7 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 	// 最多进行20次循环组成下发数据
 	int i = 0;
 	int len;
-	len = strlen(string);
+	len = strlen((char*)string);
 	do
 	{
 		switch (currentDevice->protocol)
@@ -148,12 +138,13 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 					*size = len;
 					return 1;
 				}
-				currentModbusParams = currentDevice->params->node_read_modbus_command;
+				currentModbusParams = currentDevice->params->gateway_read_modbus_command;
 				nowDeviceNum++;
 				nowparamsNum = 0;
 			}
 			break;
 		}
+
 		case DLT645_07:
 		{
 			uint8_t protocolHexData = protocol_dlt645_07;
@@ -176,7 +167,7 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 					*size = len;
 					return 1;
 				}
-				currentDlt645Params = currentDevice->params->node_read_dlt645_command;
+				currentDlt645Params = currentDevice->params->gateway_read_dlt645_command;
 				nowDeviceNum++;
 				nowparamsNum = 0;
 			}
@@ -189,14 +180,16 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 			len++;
 			insertHexData(string, (uint8_t *)&currentDlt645Params->deviceID645, len, 6); // 插入dlt645_97地址域
 			len += 6;
-			insertHexData(string, (uint8_t *)&currentDlt645Params->Identification, len, 2); // 插入dlt645_97数据标识
-			len += 2;
+			insertHexData(string, (uint8_t *)&currentDlt645Params->Identification, len, 4); // 插入dlt645_97数据标识
+			len += 4;
+
 			// 属性读取完毕,移位到下一个属性
 			i++;
 			currentDlt645Params = currentDlt645Params->nextParams;
 			if (currentDlt645Params == NULL)
 			{
 				currentDevice = currentDevice->nextDevice;
+				currentDlt645Params = currentDevice->params->gateway_read_dlt645_command;
 				if (currentDlt645Params == NULL)
 				{
 					deviceNum = 0; // 将结束位置全部归0
@@ -204,12 +197,13 @@ int masterSendNodeString(uint8_t nodeIndex, uint8_t *string, uint16_t *size)
 					*size = len;
 					return 1;
 				}
-				currentDlt645Params = currentDevice->params->node_read_dlt645_command; // 还有属性则更新位置
+				currentDlt645Params = currentDevice->params->gateway_read_dlt645_command; // 还有属性则更新位置
 				nowDeviceNum++;
 				nowparamsNum = 0;
 			}
 			break;
 		}
+		
 		default:
 			goto end_while;
 		}
@@ -408,31 +402,16 @@ int GatewayProtocolAnalysis(uint8_t *string, uint16_t len)
 	int nowparamsNum = startParamsNum;
 	GATEWAY_PARAMS *gateway;
 	gateway = get_gateway_config_params();
-	uint16_t nodeId = string[0] << 8 | string[1];
-	// 将当前的节点指针指到需要读取的节点位置
-	NODE_PARAMS *currentNode = gateway->node_params;
-	uint16_t currentNodeId = currentNode->node_address[0] << 8 | currentNode->node_address[1];
-	while (currentNodeId != nodeId)
-	{
-		currentNode = currentNode->nextNode;
-		if (currentNode == NULL)
-		{
-			// 没有找到对应该节点信息不是给本机
-			
-			return 0;
-		}
-		currentNodeId = currentNode->node_address[0] << 8 | currentNode->node_address[1];
-	}
 	// 找到该节点进行轮询
-	DEVICE_PARAMS *currentDevice = currentNode->device_params;
+	DEVICE_PARAMS *currentDevice = gateway->device_params;
 	while (nowDeviceNum)
 	{
 		currentDevice = currentDevice->nextDevice;
 		nowDeviceNum--;
 	}
 	// 移动位置到开始属性
-	NODE_READ_MODBUS_COMMAND *currentModbusParams = currentDevice->params->node_read_modbus_command;
-	NODE_READ_DLT645_COMMAND *currentDlt645Params = currentDevice->params->node_read_dlt645_command;
+	GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = currentDevice->params->gateway_read_modbus_command;
+	GATEWAY_READ_DLT645_COMMAND *currentDlt645Params = currentDevice->params->gateway_read_dlt645_command;
 	switch (currentDevice->protocol)
 	{
 	case MODBUS:
@@ -550,7 +529,7 @@ int GatewayProtocolAnalysis(uint8_t *string, uint16_t len)
 						if (currentDlt645Params == NULL)
 						{
 							currentDevice = currentDevice->nextDevice;
-							currentDlt645Params=currentDevice->params->node_read_dlt645_command;
+							currentDlt645Params=currentDevice->params->gateway_read_dlt645_command;
 						}
 					break;
 				case MODBUS:
@@ -558,7 +537,7 @@ int GatewayProtocolAnalysis(uint8_t *string, uint16_t len)
 					if(currentModbusParams==NULL)
 					{
 						currentDevice=currentDevice->nextDevice;
-						currentDlt645Params=currentDevice->params->node_read_dlt645_command;
+						currentDlt645Params=currentDevice->params->gateway_read_dlt645_command;
 					}
 					break;
 			}

+ 5 - 2
app/System/source/sys_http.c

@@ -7,6 +7,7 @@
 #include "myFIle.h"
 #include "includes.h"
 #include "sys_http.h"
+#include "log.h"
 
 uint8_t load_http_config=0;
 //get请求  http://gpu.ringzle.com:8082/iot/transmit/getTransmitConfig/DT8pd3ac6h 端口8082
@@ -21,12 +22,14 @@ void http_getDemo(void)
 	ret = http_clientGet("gpu.ringzle.com", http, 8082, 0, http_data, &datalen);
 	if(ret==200) //获取成功
 	{
-		DeleteDirFile("lora_json.txt");
-		write_file("lora_json.txt",http_data,strlen(http_data));
+		DeleteDirFile("device.txt");
+		write_file("device.txt",http_data,strlen(http_data));
 		load_http_config=1;
 	}
 	HTTP_PRINTF("%s", (char *)http_data);
 	HTTP_PRINTF("\r\n ret=%d datalen=%d\r\n", ret, datalen);
+	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "%s", (char *)http_data);
+	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "\r\n ret=%d datalen=%d\r\n", ret, datalen);
 	myfree(SRAMEX,http_data);
 	myfree(SRAMEX,http);
 }

+ 49 - 37
app/System/source/sys_mqtt.c

@@ -10,12 +10,22 @@
 #include "led.h"
 #include "MQTTClient.h"
 #include "malloc.h"
+#include "mmodbus.h"
+#include "myFile.h"
+#include "gateway_message.h"
+#include "task.h"
+#include "log.h"
+
 /********************************************************
 * @brief  连接到服务器
 * @param  sock: sock编号
 *********************************************************/
 int mqtt_userConnect(void)
 {
+	GATEWAY_PARAMS* get;
+	get = get_gateway_config_params();
+	char* MQTT_SERVER_ADDR = (char*)get->host;
+	int MQTT_SERVER_PORT = get->port;
 	int sock = -1;
 	
 	//连接到tcp服务器
@@ -23,17 +33,20 @@ int mqtt_userConnect(void)
 	if(sock < 0) 
 	{
 		MQTT_PRINTF("connect tcp server error \r\n");
+//		LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "connect tcp server error");
 		return -1;
 	}
 	MQTT_PRINTF("connect tcp server success \r\n");
+//	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "connect tcp server success");
 	//连接到mqtt服务器
 	if(mqtt_connectToMqttServer(sock) <= 0) 
 	{
 		MQTT_PRINTF("connect mqtt server error \r\n");
+//		LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "connect mqtt server error");
 		return -1;
 	}
   MQTT_PRINTF("connect mqtt server success \r\n");
-	
+	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "connect mqtt server success");
 	return sock;
 }
 
@@ -44,6 +57,9 @@ int mqtt_userConnect(void)
 *************************************************************/
 int mqtt_userSubscribeTopic(int sock)
 {
+	GATEWAY_PARAMS* get;
+	get = get_gateway_config_params();
+	char* TOPICPC = (char*)get->commandTopic;
 	return mqtt_subscribeTopic(sock, TOPICPC, 2);
 }
 
@@ -52,28 +68,18 @@ int mqtt_userSubscribeTopic(int sock)
 *name MQTT主题相关信息
 */
 void *json_message[10];
-#define QUEUE_SIZE 10         //队列深度
+#define QUEUE_SIZE 10        //队列深度
 //消息队列指针
 OS_EVENT *JsonQ;
 void mqtt_outputMsg(MQTTString *name, uint8_t *msgbuf, int msglen, uint16_t id, int qos)
 {
 	int lenght=msglen;
 	MQTT_PRINTF("receive a msg: id=%d qos=%d topic=%s msg=%s \r\n", id, qos, name->lenstring.data, msgbuf);
+//	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "receive a msg: id=%d qos=%d topic=%s msg=%s \r\n", id, qos, name->lenstring.data, msgbuf);
 	StringInfo message;
 	message.p=mymalloc(SRAMEX ,msglen);
 	memcpy(message.p,msgbuf,msglen);
-	uint8_t err;
-	err=OSQPost(JsonQ,(void *)&message);
-	switch(err)
-	{
-		case OS_ERR_NONE: 
-			break;
-		case OS_ERR_Q_FULL: 
-			MQTT_PRINTF("receive a msg queue is full \r\n");
-			break;
-		default:
-			break;
-	}
+	OSMboxPost(mqtt_recvMseeageMbox,(void*)&message);
 }	
 
 /************************************************************
@@ -84,6 +90,7 @@ void mqtt_outputMsg(MQTTString *name, uint8_t *msgbuf, int msglen, uint16_t id,
 * @retval 1: 消息正常处理
 *        -2: 帧数据包错误
 *************************************************************/
+
 int mqtt_recvPublishMessage(int sock, uint8_t *pbuf, int buflen)
 {
 	uint8_t dup, retained;
@@ -92,10 +99,11 @@ int mqtt_recvPublishMessage(int sock, uint8_t *pbuf, int buflen)
 	MQTTString topicName;
 	uint8_t *payload;
 	int msg;
+
 	
   if(MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName, &payload, &payloadlen, pbuf, buflen) == 1)
 	{
-		mqtt_outputMsg(&topicName, payload, payloadlen, packetid, qos);
+		mqtt_outputMsg(&topicName, payload, payloadlen, packetid, qos);	
 	}
   else return -2;
 	
@@ -154,17 +162,21 @@ int mqtt_userReceiveMessage(int sock, int type, uint8_t *pbuf, int len)
 *        -2: 组建发送数据时发送错误
 *************************************************************/
 char pubJsonString[jsonMaxSize];
+//char pubJsonStringCopy[jsonMaxSize];
 int mqtt_userSendMessage(int sock, int boxMsg)
 {
+	GATEWAY_PARAMS* get;
+	get = get_gateway_config_params();
+	char* TOPIC = (char*)get->messageTopic;
 	int rc = 1;	
 	//用户发送的数据
 	if((boxMsg & 0xf0000000) == 0x20000000)
 	{
 		switch(boxMsg)
 		{
-			case MBOX_USER_PUBLISHQOS0: rc = mqtt_publishMessage_qos0(sock, TOPICSTM32, (uint8_t *)pubJsonString, strlen(pubJsonString)); break;
-			case MBOX_USER_PUBLISHQOS1: rc = mqtt_publishMessage_qos1(sock, TOPICSTM32, (uint8_t *)pubJsonString, strlen(pubJsonString)); break;
-			case MBOX_USER_PUBLISHQOS2: rc = mqtt_publishMessage_qos2(sock, TOPICSTM32, (uint8_t *)pubJsonString, strlen(pubJsonString)); break;
+			case MBOX_USER_PUBLISHQOS0: rc = mqtt_publishMessage_qos0(sock, TOPIC, (uint8_t *)pubJsonString, strlen(pubJsonString)); break;
+			case MBOX_USER_PUBLISHQOS1: rc = mqtt_publishMessage_qos1(sock, TOPIC, (uint8_t *)pubJsonString, strlen(pubJsonString)); break;
+			case MBOX_USER_PUBLISHQOS2: rc = mqtt_publishMessage_qos2(sock, TOPIC, (uint8_t *)pubJsonString, strlen(pubJsonString)); break;
 		}
 	}
 	//协议站使用的数据
@@ -183,6 +195,7 @@ int mqtt_userSendMessage(int sock, int boxMsg)
 
 
 OS_EVENT *mqtt_sendMseeageMbox;   //发送消息邮箱
+OS_EVENT *mqtt_recvMseeageMbox; 	//接收消息邮箱
 int mqtt_connectFlag;             //成功连接服务器标志   
 static int mysock;                //连接mqtt服务器的sock编号
 
@@ -191,6 +204,7 @@ static int mysock;                //连接mqtt服务器的sock编号
 * @param  arg: 未使用
 * @retval 
 *************************************************************/
+
 void mqtt_userManThread(void *arg)
 {
 	int rc;
@@ -198,7 +212,7 @@ void mqtt_userManThread(void *arg)
 	void *mboxMsg;
 
 	MQTT_PRINTF("mqtt mainthread start \r\n");
-	
+//	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "mqtt mainthread start");
 __MQTT_START:	
 	
 	//1.建立与服务器的连接
@@ -209,6 +223,7 @@ __MQTT_START:
 		mysock = mqtt_userConnect();
 		OSTimeDly(2000);
 	}
+//	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "mqtt connect success");
 	OSMboxAccept(mqtt_sendMseeageMbox); //清空mbox的数据
 	mqtt_connectFlag = 1;
 	
@@ -217,9 +232,14 @@ __MQTT_START:
 	if(rc <= 0)
 	{
 		MQTT_PRINTF("subscribe error \r\n");
+//		LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "subscribe error");
 		if(rc == -1) goto __MQTT_START;          //如果网络发生错误,重新建立连接
 	}
-	else MQTT_PRINTF("subscribe success \r\n");
+	else 
+	{
+		MQTT_PRINTF("subscribe success \r\n");
+//		LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "subscribe success");
+	}
 	
 	//3.循环发送数据
 	while(1)
@@ -232,7 +252,8 @@ __MQTT_START:
 			else               
 			{
 				if(mqtt_userSendMessage(mysock, *(unsigned int *)mboxMsg) == -1)
-					goto __MQTT_START;                                    
+					goto __MQTT_START;
+				memset(pubJsonString,0,strlen(pubJsonString));
 			}
 		}
 		else //超时没有发送数据包,发送心跳包
@@ -240,7 +261,7 @@ __MQTT_START:
 			rc = mqtt_pingReq(mysock);
 			if(rc == -1) goto __MQTT_START;
 		}
-		OSTimeDly(1);
+		OSTimeDly(100);
 	}
 }
 
@@ -254,9 +275,8 @@ void mqtt_userReceiveThread(void *arg)
 	int len;	
 	int packetType;
 	int msg;
-	
 	MQTT_PRINTF("mqtt receivethread start \r\n");
-	
+//	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "mqtt receivethread start");
 	while(1)
 	{
 		if(mqtt_connectFlag == 1)
@@ -267,11 +287,13 @@ void mqtt_userReceiveThread(void *arg)
 				if(len == EWOULDBLOCK)     //接收数据超时,重新接收
 				{
 					MQTT_PRINTF("receive data timeout \r\n");
+//					LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "receive data timeout");
 					continue;
 				}
 				else  //接收数据时,网络发生了异常,给主线程发送消息,重新建立连接
 				{
 					MQTT_PRINTF("sock close \r\n");
+//					LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "sock close");
 					transport_close(mysock);
 					
 					mqtt_connectFlag = 0;
@@ -284,7 +306,7 @@ void mqtt_userReceiveThread(void *arg)
 			packetType = MQTTPacket_read(mqtt_recvbuffer, len, transport_getdata);
 			mqtt_userReceiveMessage(mysock, packetType, mqtt_recvbuffer, len);
 		}
-		OSTimeDly(1);
+		OSTimeDly(100);
 	}
 }
 
@@ -305,18 +327,8 @@ void mqtt_threadCreate(void)
 {
 	mqtt_connectFlag = 0;
 	mqtt_sendMseeageMbox = OSMboxCreate(NULL);
+	mqtt_recvMseeageMbox = OSMboxCreate(NULL);
 	JsonQ = OSQCreate(json_message[0], QUEUE_SIZE);  //创建json队列
 	OSTaskCreate(mqtt_userManThread, NULL, &mqttmainTaskStack[APP_TASK_MQTTMAIN_STK_SIZE-1], APP_TASK_MQTTMAIN_PRIO);	
 	OSTaskCreate(mqtt_userReceiveThread, NULL, &mqttreceiveTaskStack[APP_TASK_MQTTRECEIVE_STK_SIZE-1], APP_TASK_MQTTRECEIVE_PRIO);		
-}
-
-
-
-
-
-
-
-
-
-
-
+}

+ 11 - 6
app/System/source/sys_sx1278.c

@@ -2,18 +2,23 @@
 #include "json_queue.h"
 #include "sys_mqtt.h"
 #include "malloc.h"
+#include "task.h"
 //sx1278发送线程,其可能存在两处数据源,即轮询发送的采集信息,一个是mqtt下发的数据源,从队列中读取出数据
 
 void sx1278_send_task(void *pdata)
 {
 	uint8_t err;
 	StringInfo *message=NULL; //接收队列消息结构体
-	int length;
+
 	while(1)
 	{
-		message=(StringInfo *)OSQPend(JsonQ,1000,&err);
-		length=message->stringLength;
-		printf("sx1278_task_recv : %s",message->p);
-		myfree(SRAMEX ,message->p);
+			message=(StringInfo *)OSQPend(JsonQ,1000,&err);
+			if(message != NULL)
+			{
+				write_modbus_data(message->p);
+			}
+			printf("sx1278_task_recv : %s",message->p);
+			myfree(SRAMEX ,message->p);
+		
 	}
-}
+}

+ 531 - 117
app/System/source/task.c

@@ -5,36 +5,37 @@
 #include "log.h"
 #include "malloc.h"
 #include "sx1276.h"
+#include "dlt645.h"
 
-#include "protocol.h"
 #include "usart.h"
 #include "node_data_acquisition.h"
 #include "sys_mqtt.h"
 #include "sys_http.h"
+#include "node_message.h"
+#include "usart.h"
+#include "mmodbus.h"
+#include "sys_mqtt.h"
+#include "gateway_message.h"
+#include "MQTTClient.h"
+#include "cJSON.h"
+#include "time_count.h"
+#include "dlt645_1997_private.h"
 
-void master_task(uint8_t *string,uint16_t stringlength);
-void slave_task();
-
-
-
-uint16_t BufferSize;
-uint8_t Buffer[256];
-
-uint32_t rx_num = 0;
-
-uint8_t PingMsg[] = "PING\0";
-uint8_t PongMsg[] = "PONG\0";
-tRadioDriver *Radio=NULL;
+char string[512];
+uint8_t read_cnt = 0;
+uint8_t count = 0;
+uint8_t jsonCunt = 1;	
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void data_task(void *pdata)
-*	¹¦ÄÜ˵Ã÷: Ö÷ÒªÊÇdata_task´¦ÀíỊ̈߳¬ÓÅÏȼ¶¸ß¡£ÆäÔËÐÐÂß¼­Êǽ«nandflashÖеÄÊý¾Ý½âÎö³öÀ´ÂÖѯ·¢ËÍÊý¾Ý
-*	ÐÎ    ²Î£ºÎÞ
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: void data_task(void *pdata)
+*	功能说明: 主�是data_task处�线程,优先级高。其�行逻辑是将nandflash中的数�解�出�轮询��数�
+*	形    �:无
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void data_task(void *pdata)
 {
+<<<<<<< HEAD
 	OS_CPU_SR cpu_sr;
 	pdata = pdata;
 	uint16_t data;
@@ -69,125 +70,538 @@ void data_task(void *pdata)
 			mqttRecv=malloc(250);
 			message=*(StringInfo *)OSQPend(JsonQ,0, &err);
 			while(Qnum.OSNMsgs!=0)
+=======
+		
+		OS_CPU_SR cpu_sr;
+		pdata = pdata;
+
+		dlt645_init(100);
+		mmodbus_init(1);
+		
+		
+		char *device_config_json = mymalloc(SRAMEX, 9 * 1024);
+		read_file("device.txt", device_config_json);
+		addGatewayParams(device_config_json);
+		myfree(SRAMEX, device_config_json);
+		
+		GATEWAY_PARAMS *get;
+		get= get_gateway_config_params();
+		DEVICE_PARAMS *current_device=get->device_params;
+//		Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
+<<<<<<< HEAD
+		char *buf = mymalloc(SRAMEX, 9 * 1024);	// ½ÓÊÕ¶ÁÈ¡µÄÊý¾Ý
+		memset(buf, 0, 9 * 1024);		
+		while (current_device!=NULL)
+		{		
+			time1 = GetCurrentTime();
+			if(mqtt_connectFlag)
+>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
 			{
-				sprintf(mqttRecv,"%s",message.p);
-			}
-		}
-		if(current_node->nextNode!=NULL)
-		{
-			current_node=current_node->nextNode;
-			nodeIndex++;
-		}
-		else
-		{
-			nodeIndex=0;
-			current_node=get->node_params;
+					if(jsonCunt || time2  <= time1 - (10 * 1000))// 10s½øÐÐÒ»´ÎÈ«Êý¾Ý·¢ËÍ
+					{
+							read_device_data1(current_device, buf);
+							send_mqtt(buf);
+							jsonCunt = 0;
+							memset(buf,0,strlen(buf));	
+							current_device=get->device_params;	
+							time2 = GetCurrentTime();
+//							LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "data for all");
+					}
+					else
+					{
+						read_device_data2(current_device, buf);
+						if(count > 0)// count¼ì²âbufÄÚÊÇ·ñº¬ÓÐÊý¾Ý
+						{
+							send_mqtt(buf);
+							memset(buf,0,strlen(buf));	
+							current_device=get->device_params;
+							count = 0;
+//							LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "different data");
+						}
+					}	
+			}		
+		OSTimeDly(100);
+=======
+		char *buf = mymalloc(SRAMEX, 9 * 1024);	// 接收读�的数�
+		memset(buf, 0, 9 * 1024);	
+		while (current_device!=NULL)
+		{						
+				read_device_data(current_device, buf);	//读�数�	
+				send_mqtt(buf, jsonCunt);								//��数�
+				jsonCunt = 0;		
+				memset(buf,0,strlen(buf));	
+				current_device=get->device_params;		
+				OSTimeDly(1);
+>>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
 		}
+		myfree(SRAMEX, buf);
+}	
+/*
+*********************************************************************************************************
+*	函 数 �: void mqtt_to_device()
+*	功能说明: 将接收到的数���至设备
+*	形    �:
+*	返 回 值:  
+*********************************************************************************************************
+*/
+void mqtt_to_device(){
+		uint8_t err;
+		StringInfo *message;
+		message	= (StringInfo*)OSMboxPend(mqtt_recvMseeageMbox, 1000, &err);	
 		
-	}
-#else
-	dlt645_init(100);
-	mmodbus_init(100);
-	Radio->StartRx();
-	while (1)
-	{
-		slave_task();
-		OSTimeDlyHMSM(0, 0, 0, 200);
-	}
-#endif
+		if(message != NULL)	//包�消�
+		{
+				write_modbus_data(message->p);	//写入数�
+				myfree(SRAMEX ,message->p);//释放内部数�
+				//OSTimeDly(1000);
+		}	
 }
 
+
+void find_diff(char* buf, char* string) {
+	
+}
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void master_task(char *string)
-*	¹¦ÄÜ˵Ã÷: Ö÷Íø¹Øsx1278ÂÖѯ·¢Ë͵÷Óýӿڣ¬·¢ËͽáÊøºó¾Í½«×´Ì¬Çл»µ½½ÓÊÕ״̬£¬µÈ´ý´Ó»úµÄÏìÓ¦Öµ£¬µ±´Ó»ú³¬Ê±»ò½ÓÊÕµ½Êý¾Ý½øÐкóÐøÊý¾Ý´¦ÀíµÄÁ÷³Ì
-*	ÐÎ    ²Î£ºÎÞ
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: int READ_MODBUS_DATA(DEVICE_PARAMS *device)
+*	功能说明: 读�当�节点上的modbus数�
+*	形    �: DEVICE_PARAMS *device  当�设备
+*	返 回 值: 1: �功 0:失败
 *********************************************************************************************************
 */
+int read_device_data1(DEVICE_PARAMS *device, char* buf)
+{
+		
+		DEVICE_PARAMS *current_device=device;	
+		GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = current_device->params->gateway_read_modbus_command;
+		GATEWAY_READ_DLT645_COMMAND *currentDLT645Params = current_device->params->gateway_read_dlt645_command;	
+
+		while(current_device->params != NULL)
+		{				
+				if (current_device->protocol == MODBUS_READ)
+				{
+						protocol_485=1;
+						uint16_t data[currentModbusParams->registerByteNum /2]; // modbus寄存器长度
+						mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
+						if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
+						{
+								bool success = mmodbus_readHoldingRegisters16i(currentModbusParams->slaveAddress,
+																		 currentModbusParams->registerAddress,
+																		 currentModbusParams->registerByteNum /2,
+																		 data);
+
+								if (success)
+								{
+										uint32_t value;
+										if (currentModbusParams->registerByteNum == 4)
+										{
+												value = (uint32_t)data[0] | data[1];
+										}
+										else if (currentModbusParams->registerByteNum == 2)
+										{
+												value = data[0];
+										}		
+										if (currentModbusParams->decimalPoint == 0)
+										{
+												currentModbusParams->value = value;
+
+										}
+										else
+										{
+												float convertedValue = (float)value / pow(10, currentModbusParams->decimalPoint);
+												currentModbusParams->value=convertedValue;
+										}
+										sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":%d},", 
+																							current_device->deviceID, currentModbusParams->keyword, value);									
+								}
+//								else
+//								{
+//										printf("read modbus register fail\n");
+//										return 0;
+//								}
+								
+								/* �读完一个寄存器,进行message判断 */
+								mqtt_to_device();
+								
+								currentModbusParams = currentModbusParams->nextParams;
+								if (currentModbusParams == NULL)	
+								{
+										current_device = current_device->nextDevice;
+										currentModbusParams = current_device->params->gateway_read_modbus_command;
+										if(current_device == NULL)
+										{
+												sprintf(buf + strlen(buf) - 1, ""); 
+												return 1;
+										}
+								}												
+						}					
+				}
+				else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
+				{
+						protocol_485=2;
+						uint8_t read_buf[10];
+						uint32_t dltValue;
+						
+						currentDLT645Params->rxLen = 0;
+						memset(read_buf, 0, 10);
+						memset(currentDLT645Params->data, 0, 10);
 
-volatile uint32_t startTime; // ¼Ç¼¿ªÊ¼µÄʱ¼äÇÒ¿ªÊ¼Ê±¼äµ½½áÊøʱ¼ä³¬¹ýÒ»¶¨·¶Î§ÔòÅж¨Îª³¬Ê±×´Ì¬£¬Õâʱ¶ÔÆä½øÐÐÔٴη¢ËÍ
-void master_task(uint8_t *string,uint16_t stringlength)
+						dlt645_set_addr(&dlt645, currentDLT645Params->deviceID645);
+						int8_t rs;
+						if (current_device->protocol == DLT645_2007)
+						{
+								rs = dlt645_read_data(&dlt645, currentDLT645Params->Identification, read_buf, DLT645_2007);
+						}
+						else if (current_device->protocol == DLT645_1997)
+						{
+								rs = dlt645_read_data(&dlt645, currentDLT645Params->Identification, read_buf, DLT645_1997);
+						}
+						if (rs != -1)
+						{
+								if (rs <= 4)
+								{
+										memcpy(currentDLT645Params->data, read_buf, 4);
+										currentDLT645Params->rxLen = 4;
+								}
+								else if (rs == 5)
+								{
+										memcpy(currentDLT645Params->data, read_buf, 5);
+										currentDLT645Params->rxLen = 5;
+								}
+							else if (rs > 5)
+								{
+										memcpy(currentDLT645Params->data, read_buf, 9);
+										currentDLT645Params->rxLen = 9;
+								}
+															
+								dltValue = currentDLT645Params->data[0] << 24 | currentDLT645Params->data[1] << 16|
+																		currentDLT645Params->data[2] << 8  | currentDLT645Params->data[3];
+					
+								sprintf(buf + strlen(buf), "{\"identifier\":\"%s\",\"deviceID645\":\"%02x%02x%02x%02x%02x%02x\",\"identifier645\":%d,\"value\":%X}",
+																				currentDLT645Params->keyword, currentDLT645Params->deviceID645[0],
+																				currentDLT645Params->deviceID645[1],currentDLT645Params->deviceID645[2],
+																				currentDLT645Params->deviceID645[3],currentDLT645Params->deviceID645[4],
+																				currentDLT645Params->deviceID645[5],currentDLT645Params->Identification,dltValue);
+								
+			
+						}
+//						else
+//						{
+//								currentDLT645Params->rxLen = 0;
+//								printf("read DLT current data fail\n");
+<<<<<<< HEAD
+//						}				
+=======
+//						}
+								/* �读完一个寄存器,进行message判断 */
+								mqtt_to_device();
+					
+>>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
+								currentDLT645Params = currentDLT645Params->nextParams;		
+								if (currentDLT645Params == NULL)	
+								{
+										current_device = current_device->nextDevice;
+										currentDLT645Params = current_device->params->gateway_read_dlt645_command;
+										if(current_device == NULL)
+										{
+												sprintf(buf + strlen(buf) - 1, ""); 
+												return 1;
+										}
+								}										
+				}			
+				
+		}		
+		return 1;
+}
+
+
+int read_device_data2(DEVICE_PARAMS *device, char* buf)
 {
-	int retry_count=0;                                    //·¢ËͼÆÊý£¬ÔÝʱ²»¿ªÆôʧ°ÜÖØ·¢»úÖÆ
-	while (1)
-	{
-		switch (Radio->Process())
+		DEVICE_PARAMS *current_device=device;	
+		GATEWAY_READ_MODBUS_COMMAND *currentModbusParams = current_device->params->gateway_read_modbus_command;
+		GATEWAY_READ_DLT645_COMMAND *currentDLT645Params = current_device->params->gateway_read_dlt645_command;	
+
+		while(current_device->params != NULL)
+		{				
+				if (current_device->protocol == MODBUS_READ)
+				{
+						protocol_485=1;
+						uint16_t data[currentModbusParams->registerByteNum /2]; // modbus¼Ä´æÆ÷³¤¶È
+						mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
+						if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
+						{
+								bool success = mmodbus_readHoldingRegisters16i(currentModbusParams->slaveAddress,
+																		 currentModbusParams->registerAddress,
+																		 currentModbusParams->registerByteNum /2,
+																		 data);
+
+								if (success)
+								{
+										uint32_t value;
+										if (currentModbusParams->registerByteNum == 4)
+										{
+												value = (uint32_t)data[0] | data[1];
+										}
+										else if (currentModbusParams->registerByteNum == 2)
+										{
+												value = data[0];
+										}
+										if((value - currentModbusParams->value) != 0)
+										{
+												sprintf(buf + strlen(buf), "{\"deviceId\":\"%s\",\"%s\":%d},", 
+																									current_device->deviceID, currentModbusParams->keyword, value);
+												count++;
+										}
+											if (currentModbusParams->decimalPoint == 0)
+										{
+												currentModbusParams->value = value;
+
+										}
+										else
+										{
+												float convertedValue = (float)value / pow(10, currentModbusParams->decimalPoint);
+												currentModbusParams->value=convertedValue;
+										}
+																	
+								}					
+								currentModbusParams = currentModbusParams->nextParams;
+								if (currentModbusParams == NULL)	
+								{
+										current_device = current_device->nextDevice;
+										currentModbusParams = current_device->params->gateway_read_modbus_command;
+										if(current_device == NULL)
+										{
+												sprintf(buf + strlen(buf) - 1, ""); 
+												return 1;
+										}
+								}												
+						}					
+				}
+				else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
+				{
+						protocol_485=2;
+						uint8_t read_buf[10];
+						uint32_t dltValue;
+						
+						currentDLT645Params->rxLen = 0;
+						memset(read_buf, 0, 10);
+						memset(currentDLT645Params->data, 0, 10);
+
+						dlt645_set_addr(&dlt645, currentDLT645Params->deviceID645);
+						int8_t rs;
+						if (current_device->protocol == DLT645_2007)
+						{
+								rs = dlt645_read_data(&dlt645, currentDLT645Params->Identification, read_buf, DLT645_2007);
+						}
+						else if (current_device->protocol == DLT645_1997)
+						{
+								rs = dlt645_read_data(&dlt645, currentDLT645Params->Identification, read_buf, DLT645_1997);
+						}
+						if (rs != -1)
+						{
+								if (rs <= 4)
+								{
+										memcpy(currentDLT645Params->data, read_buf, 4);
+										currentDLT645Params->rxLen = 4;
+								}
+								else if (rs == 5)
+								{
+										memcpy(currentDLT645Params->data, read_buf, 5);
+										currentDLT645Params->rxLen = 5;
+								}
+							else if (rs > 5)
+								{
+										memcpy(currentDLT645Params->data, read_buf, 9);
+										currentDLT645Params->rxLen = 9;
+								}
+															
+								dltValue = currentDLT645Params->data[0] << 24 | currentDLT645Params->data[1] << 16|
+																		currentDLT645Params->data[2] << 8  | currentDLT645Params->data[3];
+					
+								sprintf(buf + strlen(buf), "{\"identifier\":\"%s\",\"deviceID645\":\"%02x%02x%02x%02x%02x%02x\",\"identifier645\":%d,\"value\":%X}",
+																				currentDLT645Params->keyword, currentDLT645Params->deviceID645[0],
+																				currentDLT645Params->deviceID645[1],currentDLT645Params->deviceID645[2],
+																				currentDLT645Params->deviceID645[3],currentDLT645Params->deviceID645[4],
+																				currentDLT645Params->deviceID645[5],currentDLT645Params->Identification,dltValue);
+								
+			
+						}
+		
+								currentDLT645Params = currentDLT645Params->nextParams;		
+								if (currentDLT645Params == NULL)	
+								{
+										current_device = current_device->nextDevice;
+										currentDLT645Params = current_device->params->gateway_read_dlt645_command;
+										if(current_device == NULL)
+										{
+												sprintf(buf + strlen(buf) - 1, ""); 
+												return 1;
+										}
+								}										
+				}			
+				
+		}		
+		return 1;
+	
+}
+/*
+*********************************************************************************************************
+*	函 数 �:void WRITE_MODBUS_DATA(char* cJSONstring)
+*	功能说明: 接收mqtt数�并写入modbus寄存器
+*	形    �:char* cJSONstring mqtt接收到的数�
+*	返 回 值: 无
+*********************************************************************************************************
+*/
+void write_modbus_data(char* cJSONstring)
+{	
+		GATEWAY_PARAMS* get;
+		get = get_gateway_config_params();
+		DEVICE_PARAMS* current_device = get->device_params;
+		/* ÀûÓÃcJSOn_Parse½âÎöÊý¾Ý£¬»ñÈ¡¸÷ÀàÐÍÊý¾Ý */
+		cJSON *root = cJSON_Parse(cJSONstring);
+		const char *deviceId = cJSON_GetStringValue(cJSON_GetObjectItem(root, "deviceId"));	
+		const cJSON *power = cJSON_GetObjectItemCaseSensitive(root, "power");
+		const cJSON *temp = cJSON_GetObjectItemCaseSensitive(root, "temp");
+		const cJSON *mode = cJSON_GetObjectItemCaseSensitive(root, "mode");
+		const cJSON *fan = cJSON_GetObjectItemCaseSensitive(root, "fan");
+		
+		while(current_device)
 		{
-		case RF_RX_DONE:
-			Radio->GetRxPacket(Buffer, &BufferSize);
-			if(GatewayProtocolAnalysis(Buffer,BufferSize)==0)
-			{
-				//½ÓÊÕµÄÐÅÏ¢²»ÊôÓÚ½ÚµãÐÅÏ¢ÖØнøÈë½ÓÊÕģʽ
-				Radio->StartRx();
-			}
-			else //Íê³ÉÒ»´Î·¢ÉäÓ¦´ð¹ý³Ì
-			{
-				delay_ms(1000);
-				return;
-			}
-		case RF_TX_DONE:
-			Radio->StartRx();
-		case RF_BUSY:
-		case RF_IDLE:
-			if(retry_count==0)   //µÚÒ»´Î·¢ËÍ
-			{
-				startTime = OSTimeGet();
-				Radio->SetTxPacket(string, stringlength);
-				retry_count++;
-			}
-			if (OSTimeGet() - startTime > 10000) // ÿ´Î·¢ËÍÐźÅʱ¼Ç¼ÉÏÒ»´Î·¢Ë͵Äʱ¼äÈç¹û³¬¹ýÒ»¶Îʱ¼äûÓÐÏìÓ¦Ôò½øÐÐÏÂÒ»´Î·¢ËÍ
-			{
-				return;
-			}
-		default:
-			OSTimeDlyHMSM(0, 0, 0, 200);
-			break;
+				char* device_ID = (char*)current_device->deviceID;
+				GATEWAY_WRITE_MODBUS_COMMAND *currentModbusParams = current_device->params->gateway_write_modbus_command;
+				if(!strcmp(device_ID,deviceId)) //Æ¥ÅäID
+				{
+						OSTimeDly(100);
+					/* дÈë¼Ä´æÆ÷²Ù×÷ */
+						if(power)
+						{
+								mmodbus_writeHoldingRegister16i(currentModbusParams->slaveAddress, 
+																								currentModbusParams->registerAddress, 
+																								power->valueint);
+						}
+						OSTimeDly(100);
+						if(temp)
+						{
+								currentModbusParams = currentModbusParams->nextParams;
+								mmodbus_writeHoldingRegister16i(currentModbusParams->slaveAddress, 
+																								currentModbusParams->registerAddress, 
+																								temp->valueint);
+						}
+						OSTimeDly(100);
+						if(mode)
+						{
+								currentModbusParams = currentModbusParams->nextParams;
+								mmodbus_writeHoldingRegister16i(currentModbusParams->slaveAddress, 
+																								currentModbusParams->registerAddress, 
+																								mode->valueint);
+						}
+						OSTimeDly(100);
+						if(fan)
+						{
+								currentModbusParams = currentModbusParams->nextParams;
+								mmodbus_writeHoldingRegister16i(currentModbusParams->slaveAddress, 
+																									currentModbusParams->registerAddress, 
+																									fan->valueint);					
+						}
+				}
+				current_device = current_device->nextDevice;
 		}
-	}
+		cJSON_Delete(root);
 }
 
 /*
 *********************************************************************************************************
-*	º¯ Êý Ãû: void slave_task(char *string)
-*	¹¦ÄÜ˵Ã÷: ¸ºÔð´ÓÕ¾Êý¾Ý´¦Àí
-*	ÐÎ    ²Î£ºÎÞ
-*	·µ »Ø Öµ: ÎÞ
+*	函 数 �: void find_difference(char* buf, char* pubJsonStringCopy, char* string)
+*	功能说明: 比较出�数1和�数2的��处
+*	形    �: �数1:新数� �数2:旧数� �数3:输出�数
+*	返 回 值: 无
 *********************************************************************************************************
 */
-volatile bool rxflag = false;
-void slave_task()
+void find_difference(char* buf, char* pubJsonStringCopy, char* string) 
 {
-	switch (Radio->Process())
-	{
-	case RF_RX_DONE:
-		Radio->GetRxPacket(Buffer, &BufferSize);
-	  if(SlaveProtocolAnalysis(Buffer,BufferSize)==1)           //ÅжÏÊÇ·ñΪ¸Ã½ÚµãÐÅÏ¢
+    const char* delimiter = "{}";
+    char* saveptr1;
+    char* saveptr2;
+		char* data1 = mymalloc(SRAMEX, strlen(buf));	
+		char* data2 = mymalloc(SRAMEX, strlen(pubJsonStringCopy));
+		
+		memcpy(data1, buf, strlen(buf));
+		memcpy(data2, pubJsonStringCopy, strlen(pubJsonStringCopy));
+     // 利用strtok_r函数分割字符串,并�一比较
+    char* token1 = strtok_r((char*)data1, delimiter, &saveptr1);
+    char* token2 = strtok_r((char*)data2, delimiter, &saveptr2);
+
+    while (token1 != NULL && token2 != NULL) 
 		{
-			data_acquisition();
-		  uint8_t node_string[256];                     
-			uint16_t node_string_Length;
-			nodeSendReaddValue(node_string,&node_string_Length);   //×é×°»Ø´«°ü
-			Radio->SetTxPacket(node_string, node_string_Length);   //·¢Ëͻش«°ü
-		}
-		delay_ms(1000);
-		break;
-	case RF_TX_DONE:
-		Radio->StartRx();
-		break;
-	case RF_IDLE:
-	case RF_BUSY:
-	default:
-		OSTimeDlyHMSM(0, 0, 0, 200);
-	}
+        if (strcmp(token1, token2) != 0) 
+				{
+            memcpy(string + strlen(string), token1, strlen(token1));
+        }
+        token1 = strtok_r(NULL, delimiter, &saveptr1);
+        token2 = strtok_r(NULL, delimiter, &saveptr2);
+    }
+
+//     // 如果有剩余字符串未比较,则打�剩余字符串
+//    while (token1 != NULL) {
+//        sprintf(string + strlen(string),"%s,", token1);
+//        token1 = strtok_r(NULL, delimiter, &saveptr1);
+//    }
+
+//    while (token2 != NULL) {
+//        //sprintf(string + strlen(string),"{%s},", token2);
+//        token2 = strtok_r(NULL, delimiter, &saveptr2);
+//    }
+		myfree(SRAMEX, data1);
+		myfree(SRAMEX, data2);
 }
 
-	#if 0   //²âÊÔ´úÂë²»¾­¹ýת·¢Ö±½Ó½øÐÐÏàÓ¦µÄ½âÎö
-			SlaveProtocolAnalysis(string,bufferLength);
-			data_acquisition();
-			uint8_t node_string[256];
-			uint16_t node_string_Length;
-			nodeSendReaddValue(node_string,&node_string_Length);
-			GatewayProtocolAnalysis(node_string,node_string_Length);
-#endif			
- 	
+
+
+/*
+*********************************************************************************************************
+*	函 数 �: void send_mqtt(char*buf, int jsonCunt)
+*	功能说明: 将数���到mqtt
+*	形    �: �数1:读�数� �数2:第一次��标志
+*	返 回 值: 无
+*********************************************************************************************************
+*/
+void send_mqtt(char*buf){
+		GATEWAY_PARAMS *get;
+		get= get_gateway_config_params();
+<<<<<<< HEAD
+
+		sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]}",get->deviceId, buf);	// ×é³ÉÒª·¢Ë͵ÄjsonÓï¾ä							
+	
+		int msg = MBOX_USER_PUBLISHQOS0;	
+		if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
+
+=======
+		time1 = GetCurrentTime();
+		
+		if(jsonCunt || time2  <= time1 - (3 * 1000)) // 20s进行一次
+		{
+				memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
+				memcpy(pubJsonStringCopy + strlen(pubJsonStringCopy), buf, strlen(buf));//备份上一次的数�
+				sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]",get->deviceId, buf);									
+				
+				int msg = MBOX_USER_PUBLISHQOS0;	
+				if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
+				time2 = GetCurrentTime();			
+		}
+		else
+		{
+				if(strcmp(buf,pubJsonStringCopy))
+				{
+						memset(string, 0 , strlen(string));
+						find_difference(buf, pubJsonStringCopy, string);	
+						memset(pubJsonString,0, strlen(pubJsonString));
+						sprintf(pubJsonString,"{\"deviceId\":\"%s\",\"data\":[{%s}]}",get->deviceId, string);
+						memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
+						sprintf(pubJsonStringCopy, buf, strlen(buf));
+					
+						int msg = MBOX_USER_PUBLISHQOS0;	
+						if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);	
+				}
+		}	
+>>>>>>> d12097fdeb13131a2d24b22a2181d1fbd191264d
+}

+ 37 - 6
app/USER/main.c

@@ -17,6 +17,11 @@
 #include "task.h"
 #include "sys_sx1278.h"
 #include "node_data_acquisition.h"
+<<<<<<< HEAD
+=======
+#include "log.h"
+#include "tcp_server.h"
+>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
 
 
 #define UNIQUE_ID 0x1fff7a10
@@ -32,8 +37,8 @@
 *  5: 用于 ota升级
 *  6: 用于 MQTT数据发送线程  APP_TASK_MQTTMAIN_PRIO
 *  7: 用于 MQTT数据接收线程  APP_TASK_MQTTRECEIVE_PRIO
-*  8: 用于 sx1278发送/接收处理数据
-*  9: 用于 本机状态led显示      
+*  8: 用于 sx1278发送/接收处理数据	DATA_TASK_PRIO
+*  9: 用于 本机状态led显示      / 现用于tcpServer_init   TCP_TASK_PRIO /
 * 10:用于网络状态led显示
 * 11:用于轮询读出本机保存信息发送到sx1278发送接收线程
 * 12:用于管理所有线程
@@ -70,8 +75,9 @@ void load_unique(void);
 char  gatewayId[11];
 int main(void)
 {
+	int status;
 	load_unique();
-	sprintf(gatewayId,"DT8pd3ac6h");
+	sprintf(gatewayId,"DTtest0001");//DT8pd3ac6h  DTbma5ac6h  DTtest0001
 	NVIC_Configuration();
 	my_mem_init(SRAMEX);
 	my_mem_init(SRAMIN);
@@ -80,7 +86,9 @@ int main(void)
 	//nandflash并不用初始化,调用fafts时会初始化
 	NET_STATUS_LED_Config();
 	USART_485_config();	
+  USART_485_DE_TX();
   USART_232_config();	
+<<<<<<< HEAD
 	NAND_Init();
 	OSInit();
 
@@ -89,7 +97,22 @@ int main(void)
 	OSTaskCreate(led_taskFuntcion,(void*)0,(OS_STK*)&LED_TASK_STK[LED_STK_SIZE-1],LED_TASK_PRIO);
 
 	OSTaskCreate(data_task,(void*)0,(OS_STK*)&DATA_TASK_STK[DATA_STK_SIZE-1],DATA_TASK_PRIO);
+=======
+	status = NAND_Init();
+	while(status){
+		NAND_Format();
+		status = NAND_Init();
+	}
+	OSInit();
+	#if 0
+	//OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
+	OSTaskCreate(period_taskFuntcion,(void*)0,(OS_STK*)&PERIOD_TASK_STK[PERIOD_STK_SIZE-1],PERIOD_TASK_PRIO);
+	OSTaskCreate(led_taskFuntcion,(void*)0,(OS_STK*)&LED_TASK_STK[LED_STK_SIZE-1],LED_TASK_PRIO);
+>>>>>>> d2b00294f64b161364915ae9082f104a2f26e39c
 	OSTaskCreate(sx1278_send_task,(void *)0,(OS_STK*)&SX1278_TASK_STK[SX1278_STK_SIZE-1],SX1278_TASK_PRIO);
+	#endif
+	OSTaskCreate(period_taskFuntcion,(void*)0,(OS_STK*)&PERIOD_TASK_STK[PERIOD_STK_SIZE-1],PERIOD_TASK_PRIO);
+	OSTaskCreate(data_task,(void*)0,(OS_STK*)&DATA_TASK_STK[DATA_STK_SIZE-1],DATA_TASK_PRIO);
 	printf("system start \r\n");
 	OSStart(); //ucos启动
   /* Infinite loop */
@@ -107,9 +130,17 @@ void period_taskFuntcion(void *arg)
 #if OS_TASK_STAT_EN > 0u
   OSStatInit();
 #endif
-	
+
+	int time1,time2;
+	time1 = OSTimeGet();
 	lwIP_Init();
 
+	// 输出日志
+//	log_init();
+//	tcp_server_init();
+	
+//	LogPrint(LOG_INFO,__FILE__, __FUNCTION__, __LINE__, "system start");
+	time2 = OSTimeGet() - time1;
 	http_getDemo();
 	http_postDemo();
 
@@ -171,8 +202,8 @@ void assert_failed(uint8_t* file, uint32_t line)
      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
   /* Infinite loop */
-  while (1)
-  {}
+ // while (1)
+ //{}
 }
 #endif
 /*

+ 1 - 1
app/dlt/src/dlt645.c

@@ -29,7 +29,7 @@
 int dlt645_receive_msg(dlt645_t *ctx, uint8_t *msg, uint16_t len, uint32_t code, dlt645_protocal protocal)
 {
     int msg_len = ctx->read(ctx, msg, len);
-
+	
     if (protocal == DLT645_1997)
     {
         return dlt645_1997_recv_check(msg, msg_len, ctx->addr, code);

+ 13 - 13
app/modbus/mmodbus.c

@@ -62,7 +62,6 @@ uint16_t mmodbus_crc16(const uint8_t *nData, uint16_t wLength)
 // #####################################################################################################
 void mmodbus_callback(void)
 {
-	OSIntEnter();
   if (RESET != USART_GetFlagStatus(_MMODBUS_USART,USART_FLAG_RXNE))
   {
     if (mmodbus.rxIndex < _MMODBUS_RXSIZE - 1)
@@ -74,21 +73,22 @@ void mmodbus_callback(void)
       USART_ReceiveData(_MMODBUS_USART);
   }
 
-  if ((mmodbus.rxIndex > 0) && RESET != USART_GetFlagStatus(_MMODBUS_USART, USART_FLAG_IDLE))
-  {
-    USART_ReceiveData(_MMODBUS_USART);
-    mmodbus.done = 1;
-		
-    return;
-  }
-  else
-  {
-    USART_GetITStatus(_MMODBUS_USART, USART_FLAG_RXNE);
-  }
+	if ((mmodbus.rxIndex > 0) && RESET != USART_GetFlagStatus(_MMODBUS_USART, USART_FLAG_IDLE))
+	{	
+		uint8_t i;	
+		mmodbus.done = 1;			
+		i = _MMODBUS_USART->SR;
+		i = _MMODBUS_USART->DR;		
+		return;
+	}
+		else
+		{
+			USART_GetITStatus(_MMODBUS_USART, USART_FLAG_RXNE);
+		}
   mmodbus.rxTime = gettick();
-	OSIntExit();
 }
 
+
 // ##################################################################################################
 uint16_t mmodbus_receiveRaw(uint32_t timeout)
 {

+ 1 - 1
app/modbus/mmodbus.h

@@ -55,7 +55,7 @@
 #include  "cmsis_os.h"
 #define   mmodbus_delay(x)  osDelay(x)
 #else
-#define   mmodbus_delay(x)  delay_ms(x)
+#define   mmodbus_delay(x)  OSTimeDly(x)
 #endif
 
 /*

+ 4 - 30
app/mqtt/MQTTClient.c

@@ -49,11 +49,13 @@ int mqtt_connectToMqttServer(int sock)
 	int len;
 	int buflen = sizeof(mqtt_sendBuf);
 	MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
+	GATEWAY_PARAMS *get;
+	get= get_gateway_config_params();
 	
 	//配置连接参数
 	data.clientID.cstring = CLIENT_ID;
-	data.username.cstring = USER_NAME;
-	data.password.cstring = PASSWORD;
+	data.username.cstring = (char*)get->username;
+	data.password.cstring = (char*)get->passwd;
 	data.keepAliveInterval = KEEPLIVE_TIME;
 	data.MQTTVersion = MQTT_VERSION;     
 	data.cleansession = 1;
@@ -700,31 +702,3 @@ void mqtt_disconnectServer(int sock)
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+ 1 - 1
app/mqtt/MQTTClient.h

@@ -3,7 +3,7 @@
 
 #include "stdint.h"
 
-#define  MQTT_SENDBUF_LENGTH   1024
+#define  MQTT_SENDBUF_LENGTH   10 * 1024
 #define  MQTT_RECVBUF_LENTH   512
 
 extern uint8_t mqtt_sendBuf[MQTT_SENDBUF_LENGTH];   

+ 1 - 0
app/mqtt/MQTTPacket.c

@@ -17,6 +17,7 @@
 
 #include "StackTrace.h"
 #include "MQTTPacket.h"
+#include "gateway_message.h"
 
 #include <string.h>
 

+ 7 - 8
app/mqtt/transport.c

@@ -78,14 +78,13 @@ int transport_receive(int sock)
 	int       optval;
 	
 	rc = read(sock, transport_recvBuf, sizeof(transport_recvBuf));
-
-	if(rc > 0) transport_dataLength = rc;
-	else       
-	{
-		transport_dataLength  = 0;
-		getsockopt(sock, SOL_SOCKET, SO_ERROR, &optval, &optlen);
-		rc = optval;
-	}
+		if(rc > 0) transport_dataLength = rc;
+		else       
+		{
+			transport_dataLength  = 0;
+			getsockopt(sock, SOL_SOCKET, SO_ERROR, &optval, &optlen);
+			rc = optval;
+		}
 	transport_dataStart = 0;
 	
 	return rc;