Преглед на файлове

1.增加充电状态30min数据持续发送不休眠
2.Uart接收超时时间降低为2s
3.根据1.7协议更改,增加了控制状态上报

CHENJIE-PC\QiXiang_CHENJIE преди 4 години
родител
ревизия
a7df30f05e
променени са 6 файла, в които са добавени 119 реда и са изтрити 77 реда
  1. 22 1
      inc/TcpTask.h
  2. 2 0
      inc/UartTask.h
  3. 7 67
      src/CANTask.c
  4. 8 2
      src/MainTask.c
  5. 70 5
      src/TcpTask.c
  6. 10 2
      src/UartTask.c

+ 22 - 1
inc/TcpTask.h

@@ -8,7 +8,6 @@
  ****************************************************************************/
 #include "app.h"
 extern UINT32 TcpService;
-
 #define PROC_TCP_TASK_STACK_SIZE           (2048)
 #define QMSG_ID_BASE               (0x160) 
 #define QMSG_ID_NW_IP_READY        (QMSG_ID_BASE)
@@ -47,6 +46,7 @@ extern UINT32 TcpService;
 //message type mark 0x02上报数据单元定义区
 #define BATTMSG				0x80
 #define GPSMSG				0x82
+#define STATESMSG			0x85
 #define VERSIONMSG			0x86
 
 typedef struct BattInfoType
@@ -139,6 +139,27 @@ typedef struct VersionMsgtoTcpType
 	VerInfoType VerInfo;	
 	UINT8	CRC;
 }VersionMsgtoTcpType;
+typedef struct _StatesInfoType
+{
+	UINT8	sendTimeUTC[6];
+	UINT8	msgMark;
+	UINT8	msgCollectionTimeUTC[6];
+	UINT8 	ResetStates;
+	UINT8	BattLockStates;
+	UINT8	HeatSwitchStates;
+	UINT8	BuzzerStatus;
+}StatesInfoType;
+typedef struct _StatesMsgtoTcpType
+{
+	UINT8 	startSymbol[2];
+	UINT8	cmdSymbol;
+	UINT8	ansSymbol;
+	UINT8	SN[BATT_SN_LEN];
+	UINT8	encryptMethod;
+	UINT8	dataLength[2];	
+	StatesInfoType StatesInfo;	
+	UINT8	CRC;
+}StatesMsgtoTcpType;
 /*---------------------------------------------------------------------------*/
 typedef enum
 {

+ 2 - 0
inc/UartTask.h

@@ -6,6 +6,8 @@
  * History:      2021-03-05
  *
  ****************************************************************************/
+#include "commontypedef.h"
+extern UINT8 BattChrgEndFlag;
 typedef struct _UartRedMsg
 {
 	bool UartFlag;

+ 7 - 67
src/CANTask.c

@@ -23,11 +23,11 @@
 #include "CANTask.h"
 #include "UDSService.h"
 
-CAN_Msg_Type CanRxMsg[2];
-
 
 
+extern volatile bool Sleep_flag;
 
+CAN_Msg_Type CanRxMsg[2];
 /*线程声明*/
 #define 			PROC_CAN_RX_TASK_STACK_SIZE			(1024)
 static StaticTask_t gProcess_Can_Rx_Task_t;
@@ -84,7 +84,10 @@ static void Can_Receive()
 			
 			case PROCESS_CAN_STATE_WORK:
 				{
-					
+					if(Sleep_flag)
+					{
+						PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
+					}
 					HAL_Can_Receive(CanRxMsg);
 					for(i=0; i<2; i++)
 					{								
@@ -107,70 +110,7 @@ static void Can_Receive()
 					{	
 						UDS_Service();
 						udsFlag = 0;							
-					}
-					else
-					{
-						//osDelay(2000);
-					}
-/*********************************************/
-#if 0
-					UINT32 NTCR2,NTCR3,NTCR4,NTCR5,Vbat = 0;
-					INT32 ret1 = 0;
-					ret1 = AdcSendReq(ADC_REQ_BITMAP_CH1,&NTCR2,01,ADC_GET_RESULT_TIMOUT);
-					//if(ret1==0)
-					{	
-						printf("ret1 = %d\n",ret1);
-						printf("NTCR2 = %d\n",NTCR2);
-
-					}
-					osDelay(1000);
-					ret1 = AdcSendReq(ADC_REQ_BITMAP_CH2,&NTCR3,01,ADC_GET_RESULT_TIMOUT);
-					//if(ret1==0)
-					{	
-					
-						printf("ret1 = %d\n",ret1);
-						printf("NTCR3 = %d\n",NTCR3);
-
-					}
-					osDelay(1000);
-					ret1 = AdcSendReq(ADC_REQ_BITMAP_CH31,&NTCR4,01,ADC_GET_RESULT_TIMOUT);
-					//if(ret1==0)
-					{	
-					
-						printf("ret1 = %d\n",ret1);
-						printf("NTCR4 = %d\n",NTCR4);
-
-					}
-					osDelay(1000);
-					ret1 = AdcSendReq(ADC_REQ_BITMAP_CH30,&NTCR5,01,ADC_GET_RESULT_TIMOUT);
-					//if(ret1==0)
-					{	
-					
-						printf("ret1 = %d\n",ret1);
-						printf("NTCR5 = %d\n",NTCR5);
-
-					}
-					osDelay(1000);
-					ret1 = AdcSendReq(ADC_REQ_BITMAP_CH4,&Vbat,01,ADC_GET_RESULT_TIMOUT);
-					//if(ret1==0)
-					{	
-					
-						printf("ret1 = %d\n",ret1);
-						printf("Vbat = %d\n",Vbat);
-
-					}
-					osDelay(1000);
-
-
-
-
-#endif
-/*********************************************/
-
-
-
-
-					
+					}		
 				break;
 			}
 	        case PROCESS_CAN_STATE_SLEEP:

+ 8 - 2
src/MainTask.c

@@ -30,14 +30,17 @@
 #include "MainTask.h"
 #include "TcpTask.h"
 #include "Fota.h"
+#include "UartTask.h"
 extern volatile bool Fota_update_flag;
 CHAR BattSN[BATT_SN_LEN] = "GYTEST00000000003";//SN仍在测试
 //全局变量
 UINT32 Timer_count;//每100ms加1
 volatile bool Sleep_flag = false;//睡眠标志位
 extern UINT32 TcpService;
+extern UINT8 BattChrgEndFlag;
 AppNVMDataType AppNVMData;
 
+
 //主线程堆栈声明区
 static StaticTask_t           gProcess_Main_Task_t;
 static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
@@ -118,8 +121,6 @@ static void MainTask(void* arg)
     montior_timer = xTimerCreate("montior_timer", 100 / portTICK_RATE_MS, pdTRUE, NULL, montior_timer_callback);
     work_timer = xTimerCreate("work_timer", AppNVMData.wakeupWorkTime*60*1000 / portTICK_RATE_MS, pdTRUE, NULL, work_timer_callback);
 
-	
-	
     PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
     while(true)
     {
@@ -149,6 +150,11 @@ static void MainTask(void* arg)
                 {
                     xTimerReset(work_timer,0);
                 }
+                if(BattChrgEndFlag)
+                {
+                    xTimerChangePeriod(work_timer,AppNVMData.chargEndWorkTime*60*1000 / portTICK_RATE_MS,0);
+                    xTimerReset(work_timer,0);
+                }
                 break;
             }
             case PROCESS_STATE_SLEEP:

+ 70 - 5
src/TcpTask.c

@@ -405,8 +405,6 @@ static void TcpDataInfoAssembleSend()
     {
         send_counter++;
     }
-
-    
 }
 //Tcp数据接收处理函数
 static void TcpDataInfoRecvHandle()
@@ -415,6 +413,9 @@ static void TcpDataInfoRecvHandle()
     osMessageQueueGet(TcpRecvHandle,&TcpRecvData,0,0);
     osDelay(100);
     Uart_Write_Data_Type UartWriteCmd;
+    StatesMsgtoTcpType StatesMsg;
+    OsaUtcTimeTValue TimeStracture;
+    UINT8 DataLen;
     UINT8 Tcp_Cmd;
     UINT8 Control_Cmd;
     UINT8 *Ptr;
@@ -446,6 +447,7 @@ static void TcpDataInfoRecvHandle()
                 }
                 else if(*(Ptr+30)==0x80)//远程锁定命令
                 {
+                    osMutexAcquire(UartMutex, osWaitForever);
                     if(*(Ptr+31)==0x01)//0x01代表锁定
                     {
                         AppNVMData.appDataModify = TRUE;
@@ -453,7 +455,18 @@ static void TcpDataInfoRecvHandle()
                         UartWriteCmd.WriteCmd = 0x01;
                         UartWriteCmd.Data[0] = 0x00;
                         UartWriteCmd.Data[1] = 0x00;
-                        //osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
+                        if((UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03)==0x00)
+                        {
+                            osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
+                        }
+                        TcpCmdAnswer[3] = 0x01;
+                        memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
+                        TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
+                        TcpCmdAnswer[22] = 0x00;
+                        TcpCmdAnswer[23] = 0x06;
+                        memcpy(&TcpCmdAnswer[24],(Ptr+24),6);
+                        TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
+                        tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                     }
                     else                //0x02代表解锁
                     {
@@ -463,9 +476,61 @@ static void TcpDataInfoRecvHandle()
                         UartWriteCmd.Data[0] = 0x00;
                         UartWriteCmd.Data[1] = 0x03;
                         osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
+                        TcpCmdAnswer[3] = 0x01;
+                        memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
+                        TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
+                        TcpCmdAnswer[22] = 0x00;
+                        TcpCmdAnswer[23] = 0x06;
+                        memcpy(&TcpCmdAnswer[24],(Ptr+24),6);
+                        TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
+                        tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
+                    }
+                    osDelay(1000);
+                    appGetSystemTimeUtcSync(&TimeStracture);
+                    DataLen= (UINT16)sizeof(StatesMsg.StatesInfo);
+                    StatesMsg.startSymbol[0] = TCP_START_SYM1;
+                    StatesMsg.startSymbol[1] = TCP_START_SYM2;
+                    StatesMsg.cmdSymbol = TCP_CMD_SYM;
+                    StatesMsg.ansSymbol = TCP_ANS_SYM;
+                    memcpy(StatesMsg.SN, AppNVMData.battSN,BATT_SN_LEN);
+                    StatesMsg.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+                    StatesMsg.dataLength[0] = (DataLen>>8) & 0xFF;
+                    StatesMsg.dataLength[1] = DataLen & 0xFF;
+                    StatesMsg.StatesInfo.sendTimeUTC[0] = ((((TimeStracture.UTCtimer1) >> 16) & 0xFFFF) - 0x07D0) & 0xFF; 	//year
+                    StatesMsg.StatesInfo.sendTimeUTC[1] = ((TimeStracture.UTCtimer1) >> 8 ) & 0xFF;							//month
+                    StatesMsg.StatesInfo.sendTimeUTC[2] = (TimeStracture.UTCtimer1) & 0xFF;									//day
+                    StatesMsg.StatesInfo.sendTimeUTC[3] = ((TimeStracture.UTCtimer2) >> 24 ) & 0xFF; 						    //hour
+                    StatesMsg.StatesInfo.sendTimeUTC[4] = ((TimeStracture.UTCtimer2) >> 16 ) & 0xFF;						    //mins
+                    StatesMsg.StatesInfo.sendTimeUTC[5] = ((TimeStracture.UTCtimer2) >> 8 ) & 0xFF;							//sec
+                    StatesMsg.StatesInfo.msgMark = STATESMSG;
+                    StatesMsg.StatesInfo.msgCollectionTimeUTC[0] = ((((TimeStracture.UTCtimer1) >> 16) & 0xFFFF) - 0x07D0) & 0xFF; 	//year
+                    StatesMsg.StatesInfo.msgCollectionTimeUTC[1] = ((TimeStracture.UTCtimer1) >> 8 ) & 0xFF;							//month
+                    StatesMsg.StatesInfo.msgCollectionTimeUTC[2] = (TimeStracture.UTCtimer1) & 0xFF;									//day
+                    StatesMsg.StatesInfo.msgCollectionTimeUTC[3] = ((TimeStracture.UTCtimer2) >> 24 ) & 0xFF; 						    //hour
+                    StatesMsg.StatesInfo.msgCollectionTimeUTC[4] = ((TimeStracture.UTCtimer2) >> 16 ) & 0xFF;						    //mins
+                    StatesMsg.StatesInfo.msgCollectionTimeUTC[5] = ((TimeStracture.UTCtimer2) >> 8 ) & 0xFF;
+                    StatesMsg.StatesInfo.ResetStates = 0;
+                    if((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1]==0x00)&&(AppNVMData.isBattLocked == TRUE))
+                    {
+                        StatesMsg.StatesInfo.BattLockStates = 1;
+                    }
+                    else if((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1]!=0x00)&&(AppNVMData.isBattLocked == FALSE))
+                    {
+                        StatesMsg.StatesInfo.BattLockStates = 0;
                     }
-                    
-                    TcpCmdAnswer[3] = 0x01;
+                    else if((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1]!=0x00)&&(AppNVMData.isBattLocked == TRUE))
+                    {
+                        StatesMsg.StatesInfo.BattLockStates = 2;
+                    }
+                    StatesMsg.StatesInfo.HeatSwitchStates = UartReadMsg.data[(0x1C+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1];
+                    StatesMsg.StatesInfo.BuzzerStatus = 0;
+                    StatesMsg.CRC = bcc_chk((UINT8 *)&StatesMsg, sizeof(StatesMsgtoTcpType)-1 );
+                    tcpipConnectionSend(socContext.id, (UINT8 *)&StatesMsg, sizeof(StatesMsgtoTcpType), 0, 0, 0);
+                    osMutexRelease(UartMutex);
+                }
+                else
+                {
+                    TcpCmdAnswer[3] = 0x0f;
                     memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
                     TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
                     TcpCmdAnswer[22] = 0x00;

+ 10 - 2
src/UartTask.c

@@ -37,6 +37,7 @@ extern AppNVMDataType AppNVMData;
 UartReadMsgType UartReadMsg;
 osMutexId_t UartMutex = NULL;//Uart数据锁
 QueueHandle_t UartWriteCmdHandle = NULL;
+UINT8 BattChrgEndFlag;
 //
 
 extern ARM_DRIVER_USART Driver_USART1;
@@ -137,6 +138,14 @@ static void UartTask(void* arg)
                 Uart_Recv_LEN = Uart_Transmit_func((UINT8 *)&Uart_Read_Msg,UartReadMsg.Header);
                 UartReadMsg.len = Uart_Recv_LEN;
                 PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
+                if((UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03)==0x02)
+                {
+                    BattChrgEndFlag=TRUE;
+                }
+                else
+                {
+                    BattChrgEndFlag=FALSE;
+                }
                 osMutexRelease(UartMutex);
                 break;
             }
@@ -155,7 +164,6 @@ static void UartTask(void* arg)
                 }
                 break;
             }
-
         }
     }
 }
@@ -260,7 +268,7 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
     {
         timeout++;
         osDelay(100);
-        if (timeout>=50)
+        if (timeout>=10)
         {
             timeout =0;
             isRecvTimeout = true;