Browse Source

100字节调试信息上传测试

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
fc78d7d886
6 changed files with 76 additions and 26 deletions
  1. 1 1
      inc/AppConfig.h
  2. 1 1
      inc/AppFunc.h
  3. 2 2
      src/AppFunc.c
  4. 55 2
      src/AppTaskTcp.c
  5. 16 19
      src/AppTaskUart.c
  6. 1 1
      src/app.c

+ 1 - 1
inc/AppConfig.h

@@ -12,7 +12,7 @@
 #define BMS_INFO                    (1)                 //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
 #define DATA_MODULE_TYPE            (1)                 //1表示NB模块,2表示4G cat1
 #define EOLSTATE                    (1)                 //1表示下线检测跳过,使用默认值,0表示使用下线检测
-#define DEFAULT_SN                  "RLTEST00000000001" //默认上传的SN编码
+#define DEFAULT_SN                  "RLTEST00000000002" //默认上传的SN编码
 #define	APPSWVERSION		        0x03000001          //数据模块软件版本号
 
 #define TCP_ADD                     "iotp.fast-fun.cn"  //数据上传的地址

+ 1 - 1
inc/AppFunc.h

@@ -26,7 +26,7 @@ typedef struct _Fota_Type
 
 }Fota_Type;
 void BattWorkDelayFunc(UINT8 battWorkCurrentState);
-UINT8 bcc_chk(UINT8* data, UINT8 length);
+UINT8 bcc_chk(UINT8* data, UINT16 length);
 void LEDDisplay(void);
 BOOL uartBattInfoDecode(UINT8* dataPtr);
 static UINT8 BmsErrorDecode(UINT32 battWarningState);

+ 2 - 2
src/AppFunc.c

@@ -134,10 +134,10 @@ UINT8 LookUpRTtable(UINT32 R_value)
 		}
 	}//R-2
 }
-UINT8 bcc_chk(UINT8* data, UINT8 length)
+UINT8 bcc_chk(UINT8* data, UINT16 length)
 {
     UINT8 bcc_chk_return = 0x00;
-    UINT8 count = 0;
+    UINT16 count = 0;
     while (count<length)
     {
         bcc_chk_return^=data[count];

+ 55 - 2
src/AppTaskTcp.c

@@ -117,6 +117,9 @@ static void TcpTask(void* arg)
                         osDelay(5000);
                         appSetCFUN(1);
                         osDelay(10000);
+                        #ifdef USING_PRINTF
+                            printf("Network restart\n");
+                        #endif
                     }
                     break;
                 case QMSG_ID_SOCK_SENDPKG:
@@ -171,6 +174,7 @@ static void TcpTask(void* arg)
                     }
                     else
                     {
+                        sendQueueMsg(QMSG_ID_NW_IP_NOREACHABLE, 0);
                         #ifdef USING_PRINTF
                             printf("connection %u or status invalid", socContext.id, socContext.status);
                         #endif
@@ -231,7 +235,7 @@ static void TcpDataInfoAssembleSend()
     UINT8 month,day,hour,minute,sec;
     UTC8TimeType UTC8TimeTcp;
 	UINT8 i = 0;
-	INT8 len = -1;
+	INT16 len = -1;
     UINT8 *SendBuffer = NULL;
     //电池工作模式的延迟转换由Maintask负责,发送频率调节由tcp负责
     switch (BattWorkStateDelay)
@@ -538,7 +542,56 @@ static void TcpDataInfoAssembleSend()
             }
         }
     }
-    if(send_counter==0)//调试信息暂时不发,需调整之后发送
+    if(send_counter%30==0)//调试信息暂时不发,需调整之后发送
+    {
+        DebugMsgtoTcpType DebugMsgInfo;
+        UINT16 BufferLen = 1000;
+        SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
+        memset(SendBuffer+sizeof(DebugMsgInfo)-1, 0x41,BufferLen);
+        appGetSystemTimeUtcSync(&TimeStracture);
+        year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
+        month=(TimeStracture.UTCtimer1&0xff00)>>8;
+        day=TimeStracture.UTCtimer1&0xff;
+        hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
+        minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
+        sec=(TimeStracture.UTCtimer2&0xff00)>>8;
+        UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
+        DataLen=sizeof(DebugMsgInfo.DebugInfo) + BufferLen;
+        DebugMsgInfo.startSymbol[0] = TCP_START_SYM1;
+	    DebugMsgInfo.startSymbol[1] = TCP_START_SYM2;
+	    DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
+	    DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
+        memcpy(DebugMsgInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
+        DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+	    DebugMsgInfo.dataLength[0] = (DataLen>>8) & 0xFF;
+	    DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
+        DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF;	//year
+        DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;								//month
+        DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
+        DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;  						    //hour
+        DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
+        DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;							//sec
+        DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
+        DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen>>8;
+        DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
+        memcpy(SendBuffer,(UINT8 *)&DebugMsgInfo,sizeof(DebugMsgInfo)-1);
+        DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
+        memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
+        len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
+        #ifdef USING_PRINTF
+            printf("DebugMsg-[%d]:\n",len);
+            for (int i = 0; i < BufferLen+sizeof(DebugMsgInfo); i++)
+            {
+                printf("%02x ",*(SendBuffer + i));
+            }
+        #endif
+        if(SendBuffer!=NULL)
+        {
+            free(SendBuffer);
+        }
+        SendBuffer=NULL;
+    }
+    if(FALSE)//调试信息暂时不发,需调整之后发送
     {
         DebugMsgtoTcpType DebugMsgInfo;
         UINT16 BufferLen = 0;

+ 16 - 19
src/AppTaskUart.c

@@ -124,6 +124,14 @@ static void UartTask(void* arg)
                 #ifdef USING_PRINTF
 					printf("[%d]Uart_Recv_buffer-%d: ",__LINE__,Uart_Recv_LEN);
                 #endif
+				#ifdef USING_PRINTF
+					printf("[%d]Uart_Recv_buffer-%d: ",__LINE__,Uart_Recv_LEN);
+					for(int i=0;i<Uart_Recv_LEN-5;i++)
+					{
+						printf("%2x - %x ",i,*((UINT8 *)&UartAnswerData.data+i));
+					}
+					printf("\n");
+				#endif
                 if(Uart_Recv_LEN>5)
                 {
                     UartRecvFlag = 1;
@@ -152,14 +160,6 @@ static void UartTask(void* arg)
 					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_INTI);
 					break;
 				}
-                #ifdef USING_PRINTF1
-					printf("[%d]Uart_Recv_buffer-%d: ",__LINE__,Uart_Recv_LEN);
-					for(int i=0;i<Uart_Recv_LEN;i++)
-					{
-						printf("%x ",*((UINT8 *)&UartAnswerData.Header+i));
-					}
-					printf("\n");
-				#endif
                 break;
             }
             case PROCESS_UART_STATE_WRITE:
@@ -228,9 +228,6 @@ static UINT8 Uart_WriteCmd_func(UartWriteData_S UartWriteData)
             CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
             Uart_Write_Msg.CRC_L = CRC_chk_buffer;
             Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
-			#ifdef USING_PRINTF
-				printf("try to lock or unlock\n");
-			#endif
             break;
         }
 		case 0x02://是否加热
@@ -247,9 +244,6 @@ static UINT8 Uart_WriteCmd_func(UartWriteData_S UartWriteData)
             CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
             Uart_Write_Msg.CRC_L = CRC_chk_buffer;
             Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
-			#ifdef USING_PRINTF
-				printf("try to heat or unheat\n");
-			#endif
             break;
 		}
 		case 0x04://是否继电器控制
@@ -266,9 +260,6 @@ static UINT8 Uart_WriteCmd_func(UartWriteData_S UartWriteData)
             CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
             Uart_Write_Msg.CRC_L = CRC_chk_buffer;
             Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
-			#ifdef USING_PRINTF
-				printf("try to relay control\n");
-			#endif
             break;
 		}
         default:
@@ -335,19 +326,25 @@ void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle,UartWriteData_S UartWrite
 		UartWriteData.Data[1] = HeatSwitch&0xFF;
 		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
 	}
-	if(battWorkState ==0x00 && AppDataInfo.BattLock==TRUE && ((UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1])&0x03)!=0x02)//try to lock lock the discharge 
+	if(battWorkState ==0x00 && AppDataInfo.BattLock==TRUE && ((UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1])&0x01)!=0x00)//try to lock lock the discharge 
 	{
 		UartWriteData.WriteCmd = 0x01;
 		UartWriteData.Data[0] = 0x00|(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2]);
 		UartWriteData.Data[1] = 0x02;
 		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		#ifdef USING_PRINTF
+            printf("try to lock %d,%d,%d,%d\n",AppDataInfo.BattLock,(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]),AppNVMData.BattCellCount,AppNVMData.BattTempCount);
+        #endif
 	}
-	else if (battWorkState ==0x00 && AppDataInfo.BattLock==FALSE && ((UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1])&0x03)!=0x03 ) // try to unlock
+	else if (battWorkState ==0x00 && AppDataInfo.BattLock==FALSE && ((UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1])&0x01)!=0x01 ) // try to unlock
 	{
 		UartWriteData.WriteCmd = 0x01;
 		UartWriteData.Data[0] = 0x00|(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2]);
 		UartWriteData.Data[1] = 0x03;
 		osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+		#ifdef USING_PRINTF
+            printf("try to unlock %d,%d,%d,%d\n",AppDataInfo.BattLock,(UartAnswerData.data[(0x1B+AppNVMData.BattCellCount + AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]),AppNVMData.BattCellCount,AppNVMData.BattTempCount);
+        #endif
 	}
 	if(AppDataInfo.RelayControl==TRUE && getbit((UartAnswerData.data[(0x09+AppNVMData.BattCellCount+AppNVMData.BattTempCount + BMS_OTHER_TEMP)*2+1]),0)==0x00)//继电器断开
 	{

+ 1 - 1
src/app.c

@@ -16,7 +16,7 @@ void appInit(void *arg)
     AppTaskGpsInit(arg);
     AppTaskUartInit(arg);
     AppTaskCanInit(arg);
-    AppTaskBcuInit(arg);
+    //AppTaskBcuInit(arg);
 }
 void main_entry(void) 
 {