Browse Source

网络进行下行控制,进行电池锁定。

CHENJIE-PC\QiXiang_CHENJIE 4 năm trước cách đây
mục cha
commit
5ea2559545
5 tập tin đã thay đổi với 57 bổ sung13 xóa
  1. 4 4
      inc/TcpTask.h
  2. 1 1
      inc/UartTask.h
  3. 36 0
      src/TcpTask.c
  4. 15 7
      src/UartTask.c
  5. 1 1
      src/bsp_custom.c

+ 4 - 4
inc/TcpTask.h

@@ -23,10 +23,10 @@ extern UINT32 TcpService;
 // #define QX_TCP_IPADRRES				"47.97.127.222"
 // #define QX_TCP_PORT					8712
 /*---------------测试IP地址-----------------------------------*/
-#define QX_TCP_IPADRRES				"39.103.177.126"
-#define QX_TCP_PORT					8712
-// #define QX_TCP_IPADRRES				"120.26.68.165"
-// #define QX_TCP_PORT					14319
+// #define QX_TCP_IPADRRES				"39.103.177.126"
+// #define QX_TCP_PORT					8712
+#define QX_TCP_IPADRRES				"120.26.68.165"
+#define QX_TCP_PORT					14319
 /*---------------测试IP地址END-----------------------------------*/
 #define BATT_SN_LEN             17
 #define TCP_START_SYM1			0x23

+ 1 - 1
inc/UartTask.h

@@ -21,7 +21,7 @@ typedef struct Uart_Write_Data_Type
 //全局变量输出区
 extern UartReadMsgType UartReadMsg;
 extern osMutexId_t UartMutex;
-extern Uart_Write_Data_Type UartWriteData;
+extern QueueHandle_t UartWriteCmdHandle;
 //
 #define UART_WRITE_FLAG 0x01
 #define UART_READ_FLAG 0x00

+ 36 - 0
src/TcpTask.c

@@ -40,6 +40,7 @@ extern osMutexId_t UartMutex;
 extern osMutexId_t GpsMutex;
 extern UINT8 GpsData[16];
 extern AppNVMDataType AppNVMData;
+extern QueueHandle_t UartWriteCmdHandle;
 
 //局部变量申请
 AppSocketConnectionContext socContext = {-1, APP_SOCKET_CONNECTION_CLOSED};
@@ -413,9 +414,13 @@ static void TcpDataInfoRecvHandle()
     TcpipConnectionRecvDataInd *TcpRecvData;
     osMessageQueueGet(TcpRecvHandle,&TcpRecvData,0,0);
     osDelay(100);
+    Uart_Write_Data_Type UartWriteCmd;
     UINT8 Tcp_Cmd;
     UINT8 Control_Cmd;
     UINT8 *Ptr;
+    UINT8 TcpCmdAnswer[31];
+    TcpCmdAnswer[0] = TCP_START_SYM1;
+    TcpCmdAnswer[1] = TCP_START_SYM1;
     if(TcpRecvData != PNULL)
     {
         Ptr = TcpRecvData->data;
@@ -434,10 +439,41 @@ static void TcpDataInfoRecvHandle()
                 break;
             case TCP_CONCMD_SYM:
             {
+                TcpCmdAnswer[2] = TCP_CONCMD_SYM;
                 if(*(Ptr+30)==0x01)//远程升级命令
                 {
                     Fota_Func(Ptr,socContext.id);
                 }
+                else if(*(Ptr+30)==0x80)//远程锁定命令
+                {
+                    if(*(Ptr+31)==0x01)//0x01代表锁定
+                    {
+                        AppNVMData.appDataModify = TRUE;
+                        AppNVMData.isBattLocked = TRUE;
+                        UartWriteCmd.WriteCmd = 0x01;
+                        UartWriteCmd.Data[0] = 0x00;
+                        UartWriteCmd.Data[1] = 0x00;
+                        //osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
+                    }
+                    else                //0x02代表解锁
+                    {
+                        AppNVMData.appDataModify = TRUE;
+                        AppNVMData.isBattLocked = FALSE;
+                        UartWriteCmd.WriteCmd = 0x01;
+                        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);
+                }
                 break;
             }
             default:

+ 15 - 7
src/UartTask.c

@@ -34,10 +34,9 @@ extern UINT32 Timer_count;
 extern volatile bool Sleep_flag; 
 extern AppNVMDataType AppNVMData;
 //全局变量输出区
-UINT8 Uart_Write_Flag=0;
 UartReadMsgType UartReadMsg;
 osMutexId_t UartMutex = NULL;//Uart数据锁
-Uart_Write_Data_Type UartWriteData; //Uart控制命令
+QueueHandle_t UartWriteCmdHandle = NULL;
 //
 
 extern ARM_DRIVER_USART Driver_USART1;
@@ -73,12 +72,16 @@ static void UartTask(void* arg)
     UINT16  Uart_Uds_LEN;
     UINT16  Uart_Recv_LEN;
     Uart_Read_Msg_Type Uart_Read_Msg;
+    Uart_Write_Data_Type UartWriteData; //Uart控制命令
+    if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
+	{
+		UartWriteCmdHandle = osMessageQueueNew(3,sizeof(Uart_Write_Data_Type), NULL);
+	}
     if(UartMutex == NULL)
     {
         UartMutex = osMutexNew(NULL);
     }
     //上电起始控制区域
-    Uart_Write_Flag=UART_WRITE_FLAG;
     UartWriteData.WriteCmd = 0x01;
     if(AppNVMData.isBattLocked)
     {
@@ -90,6 +93,7 @@ static void UartTask(void* arg)
         UartWriteData.Data[0] = 0x00;
         UartWriteData.Data[1] = 0x03;
     }
+    osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
     while (1)
     {
         switch (gProcess_Uart_Task)
@@ -106,10 +110,15 @@ static void UartTask(void* arg)
                     #ifdef USING_PRINTF
                         printf("[%d]Uart Timer 5s:%d\n",__LINE__,Timer_count);
                     #endif
-                    if(Uart_Write_Flag==UART_READ_FLAG)
-                        PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
-                    else
+                    if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
+                    {
+                        #ifdef USING_PRINTF
+                            printf("[%d]UartWriteCmdHandle :%x\n",__LINE__,UartWriteData.WriteCmd);
+                        #endif
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
+                    }
+                    else
+                        PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
                 }
                 break;
             }
@@ -134,7 +143,6 @@ static void UartTask(void* arg)
             case PROCESS_UART_STATE_WRITE:
             {
                 Uart_WriteCmd_func(UartWriteData);
-                Uart_Write_Flag=UART_READ_FLAG;
                 PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
                 break;
             }

+ 1 - 1
src/bsp_custom.c

@@ -163,7 +163,7 @@ void BSP_CustomInit(void)
 	slpManGetPMUSettings();				
 
 	PMU_WakeupPadInit();
-	NVIC_EnableIRQ(PadWakeup0_IRQn);
+	NVIC_DisableIRQ(PadWakeup0_IRQn);
 	NVIC_EnableIRQ(PadWakeup1_IRQn);
 	NVIC_EnableIRQ(PadWakeup2_IRQn);
 	NVIC_DisableIRQ(PadWakeup3_IRQn);