zhao006 10 달 전
부모
커밋
d5eacf5be0
5개의 변경된 파일53개의 추가작업 그리고 17988개의 파일을 삭제
  1. 14 3
      app/MDKProject/lora_gateway.uvprojx
  2. 0 17832
      app/OBJ/lora_gateway.hex
  3. 0 4
      app/System/includes/json_queue.h
  4. 1 21
      app/System/source/sys_mqtt.c
  5. 38 128
      app/System/source/task.c

+ 14 - 3
app/MDKProject/lora_gateway.uvprojx

@@ -16,8 +16,8 @@
         <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>
@@ -1189,4 +1191,13 @@
     <files/>
   </RTE>
 
+  <LayerInfo>
+    <Layers>
+      <Layer>
+        <LayName>lora_gateway</LayName>
+        <LayPrjMark>1</LayPrjMark>
+      </Layer>
+    </Layers>
+  </LayerInfo>
+
 </Project>

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 17832
app/OBJ/lora_gateway.hex


+ 0 - 4
app/System/includes/json_queue.h

@@ -5,11 +5,7 @@
 void creat_queue(void);
 typedef struct {
     uint32_t stringLength;
-<<<<<<< HEAD
     char *p;
-=======
-     char *p;
->>>>>>> 841e7987800910a57cf5275c331a8acbfec24198
 } StringInfo;
 
 

+ 1 - 21
app/System/source/sys_mqtt.c

@@ -71,31 +71,10 @@ void mqtt_outputMsg(MQTTString *name, uint8_t *msgbuf, int msglen, uint16_t id,
 {
 	int lenght=msglen;
 	MQTT_PRINTF("receive a msg: id=%d qos=%d topic=%s msg=%s \r\n", id, qos, name->lenstring.data, msgbuf);
-<<<<<<< HEAD
 	StringInfo message;
 	message.p=mymalloc(SRAMEX ,msglen);
 	memcpy(message.p,msgbuf,msglen);
 	OSMboxPost(mqtt_recvMseeageMbox,(void*)&message);
-=======
-	StringInfo *message=mymalloc(SRAMIN ,sizeof(StringInfo));
-	message->stringLength=msglen;
-	message->p=mymalloc(SRAMIN ,msglen+1);
-	memcpy(message->p,msgbuf,msglen);
-	uint8_t err;
-	OSTimeDly(1500);
-	err=OSQPost(JsonQ,message);
-	commd = 0;
-	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;
-	}
->>>>>>> 841e7987800910a57cf5275c331a8acbfec24198
 }	
 
 /************************************************************
@@ -178,6 +157,7 @@ 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;

+ 38 - 128
app/System/source/task.c

@@ -24,15 +24,14 @@
 char string[512];
 /*
 *********************************************************************************************************
-*	锟斤拷 锟斤拷 锟斤拷: void data_task(void *pdata)
-*	锟斤拷锟斤拷说锟斤拷: 锟斤拷要锟斤拷data_task锟斤拷锟斤拷锟竭程o拷锟斤拷锟饺硷拷锟竭★拷锟斤拷锟斤拷锟斤拷锟竭硷拷锟角斤拷nandflash锟叫碉拷锟斤拷锟捷斤拷锟斤拷锟斤拷锟斤拷锟斤拷询锟斤拷锟斤拷锟斤拷锟斤拷
-*	锟斤拷    锟轿o拷锟斤拷
-*	锟斤拷 锟斤拷 值: 锟斤拷
+*	函 数 名: void data_task(void *pdata)
+*	功能说明: 主要是data_task处理线程,优先级高。其运行逻辑是将nandflash中的数据解析出来轮询发送数据
+*	形    参:无
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void data_task(void *pdata)
 {
-<<<<<<< HEAD
 		OS_CPU_SR cpu_sr;
 		pdata = pdata;
 		dlt645_init(100);
@@ -48,12 +47,12 @@ void data_task(void *pdata)
 		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);
-		char *buf = mymalloc(SRAMEX, 9 * 1024);	// 锟斤拷锟秸讹拷取锟斤拷锟斤拷锟斤拷
+		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);								//锟斤拷锟斤拷锟斤拷锟斤拷
+				read_device_data(current_device, buf);	//读取数据	
+				send_mqtt(buf, jsonCunt);								//发送数据
 				jsonCunt = 0;		
 				memset(buf,0,strlen(buf));	
 				current_device=get->device_params;		
@@ -63,10 +62,10 @@ void data_task(void *pdata)
 }	
 /*
 *********************************************************************************************************
-*	锟斤拷 锟斤拷 锟斤拷: void mqtt_to_device()
-*	锟斤拷锟斤拷说锟斤拷: 锟斤拷锟斤拷锟秸碉拷锟斤拷锟斤拷锟捷凤拷锟斤拷锟斤拷锟借
-*	锟斤拷    锟斤拷:
-*	锟斤拷 锟斤拷 值:  
+*	函 数 名: void mqtt_to_device()
+*	功能说明: 将接收到的数据发送至设
+*	形    参:
+*	返 回 值:  
 *********************************************************************************************************
 */
 void mqtt_to_device(){
@@ -74,109 +73,20 @@ void mqtt_to_device(){
 		StringInfo *message;
 		message	= (StringInfo*)OSMboxPend(mqtt_recvMseeageMbox, 1000, &err);	
 		
-		if(message != NULL)	//锟斤拷锟斤拷锟斤拷
+		if(message != NULL)	//包含消
 		{
-				write_modbus_data(message->p);	//写锟斤拷锟斤拷锟斤拷
-				myfree(SRAMEX ,message->p);//锟酵凤拷锟节诧拷锟斤拷锟斤拷
+				write_modbus_data(message->p);	//写入数据
+				myfree(SRAMEX ,message->p);//释放内部数据
 				//OSTimeDly(1000);
 		}	
-=======
-	OS_CPU_SR cpu_sr;
-	pdata = pdata;
-	mmodbus_init(1);
-	char buf[1000];	// 锟斤拷锟斤拷modbus锟斤拷取锟斤拷锟斤拷锟斤拷	
-	
-	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();
-	int deviceIndex=0;
-	DEVICE_PARAMS *current_device=get->device_params;
-//	Config_485_Port(get->baudrate, get->dataBits, get->stopBit, get->parity, get->flowControl);
-	while (current_device!=NULL)
-	{
-		uint8_t err;
-		StringInfo *message=NULL;
-		message=OSQPend(JsonQ,1000,&err);
-		if(message==NULL)//娌℃湁娑堟伅
-		{
-			OSTimeDly(1000);
-		}
-		else							//鍖呭惈娑堟伅
-		{
-			myfree(SRAMIN ,message->p);//閲婃斁鍐呴儴鏁版嵁
-			myfree(SRAMIN,message);
-			OSTimeDly(1000);
-		}
-			
-//		uint8_t err;
-//		StringInfo *message=NULL; //锟斤拷锟秸讹拷锟斤拷锟斤拷息锟结构锟斤拷
-//		message=OSQPend(JsonQ,1000,&err);
-//		if(message==NULL)
-//		{			
-//			READ_DATA(current_device, buf);		
-//			if(current_device->nextDevice!=NULL) 
-//			{
-//				current_device=current_device->nextDevice;		
-//			}
-//			else
-//			{		 
-//				sprintf(buf + strlen(buf) - 1, "}");
-//					time1 = OSTimeGet();
-//					if( jsoncunt || time2  <= time1 - 20000)
-//					{
-//						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_PUBLISHQOS2;	
-//						if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);
-//						current_device=get->device_params;
-//						jsoncunt = 0;
-//						time2 = OSTimeGet();
-//					}//20s锟斤拷锟斤拷一锟斤拷
-//					
-//					else
-//					{
-//						if(strcmp(buf,pubJsonStringCopy))
-//						{
-//							memset(string, 0 , strlen(string));
-//							findDifference(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_PUBLISHQOS2;	
-//							if(mqtt_connectFlag==1) OSMboxPost(mqtt_sendMseeageMbox, &msg);	
-//						}
-//				}	
-//				memset(buf,0,strlen(buf));	
-//				current_device=get->device_params;
-//			}			
-//		}
-//		else
-//		{			
-//			WRITE_MODBUS_DATA(message->p);
-//			printf("sx1278_task_recv : %s",message->p);
-//			myfree(SRAMIN ,message->p);
-//			myfree(SRAMIN,message);
-//			
-//			commd = 1;	 
-//		}	
-//				OSTimeDly(1000); 
-	}
->>>>>>> 841e7987800910a57cf5275c331a8acbfec24198
 }
 
 /*
 *********************************************************************************************************
-*	锟斤拷 锟斤拷 锟斤拷: int READ_MODBUS_DATA(DEVICE_PARAMS *device)
-*	锟斤拷锟斤拷说锟斤拷: 锟斤拷取锟斤拷前锟节碉拷锟较碉拷modbus锟斤拷锟斤拷
-*	锟斤拷    锟斤拷: DEVICE_PARAMS *device  锟斤拷前锟借
-*	锟斤拷 锟斤拷 值: 1: 锟缴癸拷 0:失锟斤拷
+*	函 数 名: int READ_MODBUS_DATA(DEVICE_PARAMS *device)
+*	功能说明: 读取当前节点上的modbus数据
+*	形    参: DEVICE_PARAMS *device  当前设备
+*	返 回 值: 1: 成功 0:失败
 *********************************************************************************************************
 */
 int read_device_data(DEVICE_PARAMS *device, char* buf)
@@ -190,7 +100,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 				if (current_device->protocol == MODBUS_READ)
 				{
 						protocol_485=1;
-						uint16_t data[currentModbusParams->registerByteNum /2]; // modbus锟侥达拷锟斤拷锟斤拷锟斤拷
+						uint16_t data[currentModbusParams->registerByteNum /2]; // modbus寄存器长度
 						mmodbus_set16bitOrder(current_device->MDBbigLittleFormat);
 						if (currentModbusParams->functionCode == 0x03 | currentModbusParams->functionCode == 0x01)
 						{
@@ -230,7 +140,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 										return 0;
 								}
 								
-								/* 每锟斤拷锟斤拷一锟斤拷锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷message锟叫讹拷 */
+								/* 每读完一个寄存器,进行message判断 */
 								mqtt_to_device();
 								
 								currentModbusParams = currentModbusParams->nextParams;
@@ -246,7 +156,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 								}												
 						}					
 				}
-				 else if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
+				 if (current_device->protocol == DLT645_2007 || current_device->protocol == DLT645_97)
 				{
 						protocol_485=2;
 						uint8_t read_buf[10];
@@ -295,7 +205,7 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 //								currentDLT645Params->rxLen = 0;
 //								printf("read DLT current data fail\n");
 //						}
-								/* 每锟斤拷锟斤拷一锟斤拷锟侥达拷锟斤拷锟斤拷锟斤拷锟斤拷message锟叫讹拷 */
+								/* 每读完一个寄存器,进行message判断 */
 								mqtt_to_device();
 					
 								currentDLT645Params = currentDLT645Params->nextParams;		
@@ -316,10 +226,10 @@ int read_device_data(DEVICE_PARAMS *device, char* buf)
 }
 /*
 *********************************************************************************************************
-*	锟斤拷 锟斤拷 锟斤拷:void WRITE_MODBUS_DATA(char* cJSONstring)
-*	锟斤拷锟斤拷说锟斤拷: 锟斤拷锟斤拷mqtt锟斤拷锟捷诧拷写锟斤拷modbus锟侥达拷锟斤拷
-*	锟斤拷    锟轿o拷char* cJSONstring mqtt锟斤拷锟秸碉拷锟斤拷锟斤拷锟斤拷
-*	锟斤拷 锟斤拷 值: 锟斤拷
+*	函 数 名:void WRITE_MODBUS_DATA(char* cJSONstring)
+*	功能说明: 接收mqtt数据并写入modbus寄存器
+*	形    参:char* cJSONstring mqtt接收到的数据
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void write_modbus_data(char* cJSONstring)
@@ -384,10 +294,10 @@ void write_modbus_data(char* cJSONstring)
 
 /*
 *********************************************************************************************************
-*	锟斤拷 锟斤拷 锟斤拷: void find_difference(char* buf, char* pubJsonStringCopy, char* string)
-*	锟斤拷锟斤拷说锟斤拷: 锟饺较筹拷锟斤拷锟斤拷1锟酵诧拷锟斤拷2锟侥诧拷同锟斤拷
-*	��    ��: ����1:������ ����2:������ ����3���������
-*	锟斤拷 锟斤拷 值: 锟斤拷
+*	函 数 名: void find_difference(char* buf, char* pubJsonStringCopy, char* string)
+*	功能说明: 比较出参数1和参数2的不同处
+*	形    参: 参数1:新数据 参数2:旧数据 参数3:输出参数
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void find_difference(char* buf, char* pubJsonStringCopy, char* string) 
@@ -400,7 +310,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
 		
 		memcpy(data1, buf, strlen(buf));
 		memcpy(data2, pubJsonStringCopy, strlen(pubJsonStringCopy));
-     // 锟斤拷锟斤拷strtok_r锟斤拷锟斤拷锟街革拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟饺斤拷
+     // 利用strtok_r函数分割字符串,并逐一比较
     char* token1 = strtok_r((char*)data1, delimiter, &saveptr1);
     char* token2 = strtok_r((char*)data2, delimiter, &saveptr2);
 
@@ -414,7 +324,7 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
         token2 = strtok_r(NULL, delimiter, &saveptr2);
     }
 
-//     // 锟斤拷锟斤拷锟绞o拷锟斤拷址锟斤拷锟轿达拷冉希锟斤拷锟斤拷印剩锟斤拷锟街凤拷锟斤拷
+//     // 如果有剩余字符串未比较,则打印剩余字符串
 //    while (token1 != NULL) {
 //        sprintf(string + strlen(string),"%s,", token1);
 //        token1 = strtok_r(NULL, delimiter, &saveptr1);
@@ -430,10 +340,10 @@ void find_difference(char* buf, char* pubJsonStringCopy, char* string)
 
 /*
 *********************************************************************************************************
-*	锟斤拷 锟斤拷 锟斤拷: void send_mqtt(char*buf, int jsonCunt)
-*	锟斤拷锟斤拷说锟斤拷: 锟斤拷锟斤拷锟捷凤拷锟酵碉拷mqtt
-*	锟斤拷    锟斤拷: 锟斤拷锟斤拷1:锟斤拷取锟斤拷锟斤拷 锟斤拷锟斤拷2:锟斤拷一锟轿凤拷锟酵憋拷
-*	锟斤拷 锟斤拷 值: 锟斤拷
+*	函 数 名: void send_mqtt(char*buf, int jsonCunt)
+*	功能说明: 将数据发送到mqtt
+*	形    参: 参数1:读取数据 参数2:第一次发送标
+*	返 回 值: 无
 *********************************************************************************************************
 */
 void send_mqtt(char*buf, int jsonCunt){
@@ -441,10 +351,10 @@ void send_mqtt(char*buf, int jsonCunt){
 		get= get_gateway_config_params();
 		time1 = GetCurrentTime();
 		
-		if(jsonCunt || time2  <= time1 - (3 * 1000)) // 20s锟斤拷锟斤拷一锟斤拷
+		if(jsonCunt || time2  <= time1 - (3 * 1000)) // 20s进行一次
 		{
 				memset(pubJsonStringCopy,0, strlen(pubJsonStringCopy));
-				memcpy(pubJsonStringCopy + strlen(pubJsonStringCopy), buf, strlen(buf));//锟斤拷锟斤拷锟斤拷一锟轿碉拷锟斤拷锟斤拷
+				memcpy(pubJsonStringCopy + strlen(pubJsonStringCopy), buf, strlen(buf));//备份上一次的数据
 				sprintf(pubJsonString,"{\"DEVICEID\":\"%s\",\"data\":[%s]",get->deviceId, buf);									
 				
 				int msg = MBOX_USER_PUBLISHQOS0;