|
@@ -0,0 +1,835 @@
|
|
|
+#include "bsp.h"
|
|
|
+#include "bsp_custom.h"
|
|
|
+#include "osasys.h"
|
|
|
+#include "ostask.h"
|
|
|
+#include "queue.h"
|
|
|
+#include "ps_event_callback.h"
|
|
|
+#include "cmisim.h"
|
|
|
+#include "cmimm.h"
|
|
|
+#include "cmips.h"
|
|
|
+#include "sockets.h"
|
|
|
+#include "psifevent.h"
|
|
|
+#include "ps_lib_api.h"
|
|
|
+#include "lwip/netdb.h"
|
|
|
+#include <cis_def.h>
|
|
|
+#include "debug_log.h"
|
|
|
+#include "slpman_ec616.h"
|
|
|
+#include "plat_config.h"
|
|
|
+#include "ec_tcpip_api.h"
|
|
|
+#include "hal_module_adapter.h"
|
|
|
+#include "UartTask.h"
|
|
|
+#include "MainTask.h"
|
|
|
+#include "app.h"
|
|
|
+#include "CANTask.h"
|
|
|
+#include "UDSService.h"
|
|
|
+
|
|
|
+
|
|
|
+//
|
|
|
+extern UartReadMsgType UartReadMsg;
|
|
|
+extern osMutexId_t UartMutex;
|
|
|
+
|
|
|
+void UDS_Service(void);
|
|
|
+void UDS_CAN_Update(void);
|
|
|
+BOOL UDSClearFotaDownloadRegion(void);
|
|
|
+BOOL UDSAskforDownLoadData(void);
|
|
|
+extern void appSaveConfigValue(void);
|
|
|
+
|
|
|
+
|
|
|
+UINT8 UDSService[2];
|
|
|
+UINT8 UDSSubService[2];
|
|
|
+UINT8 UDSSubServiceActionCode[2];
|
|
|
+UINT8 UDSSwitch = 0;
|
|
|
+UINT8 UDSDialogMode = 0;
|
|
|
+UINT8 UDSBattSN[BATT_SN_LEN];
|
|
|
+
|
|
|
+UINT16 updateDifferDataByteLen = 0;
|
|
|
+
|
|
|
+//each package means 100 bytes, max PackageCounter = updateDifferDataByteLen%100 + 1
|
|
|
+UINT16 updateDifferDataPackageCounter = 0;
|
|
|
+
|
|
|
+//each slice means 4 bytes, max SliceCounter = 25;
|
|
|
+UINT16 updateDifferDataSliceCounter = 0;
|
|
|
+
|
|
|
+
|
|
|
+UINT8 updateDataBuffer[100];
|
|
|
+
|
|
|
+extern UINT8 BattSN[BATT_SN_LEN];
|
|
|
+
|
|
|
+
|
|
|
+void UDS_Service()
|
|
|
+{
|
|
|
+ UINT8 i,j,k = 0;
|
|
|
+ INT8 ret = 0;
|
|
|
+ BOOL boolRet = false;
|
|
|
+ static UINT8 snFlag = 0;
|
|
|
+ static UINT32 sliceCounterFlag = 0;
|
|
|
+ UINT16 tempSliceCounter=0;
|
|
|
+ static UINT8 counter=0;
|
|
|
+ CAN_Msg_Type UDSAnswer ={0};
|
|
|
+ static UINT8 battInfo[8*14] = {0};
|
|
|
+
|
|
|
+ //UartReadMsg Uart_Recv_Msg;
|
|
|
+ //UINT8 temp00[94] ={0x00,0x0E,0x00,0x05,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0x7A,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0E,0x42,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x13,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x00,0x24,0x00,0x26,0x00,0x22,0x00,0x24,0x00,0x00,0x00,0x00,0x6e,0x78,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x74,0x0E,0x42,0x0D,0x7A,0x00,0x00};
|
|
|
+ //MEMCPY(battInfo, temp00, 94);
|
|
|
+
|
|
|
+ //while(true)
|
|
|
+ //{
|
|
|
+ //if(UDSSwitch == 1)
|
|
|
+ {
|
|
|
+ for(i=0; i<2; i++)
|
|
|
+ {
|
|
|
+ if(CanRxMsg[i].Id == 0x7A0)
|
|
|
+ {
|
|
|
+ switch (UDSService[i])
|
|
|
+ {
|
|
|
+ case 0x10:
|
|
|
+ if(UDSSubService[i] == 0x01)
|
|
|
+ {
|
|
|
+ if(UDSDialogMode == 0x01 || UDSDialogMode==0x02)
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ UDSSwitch = 0;
|
|
|
+ UDSDialogMode = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x02)
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ UDSSwitch = 1;
|
|
|
+ UDSDialogMode = 2;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x03)
|
|
|
+ {
|
|
|
+ if(UDSSwitch == 1)
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ UDSSwitch = 1;
|
|
|
+ UDSDialogMode = 3;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF; //the dialog mode error
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x11) //make NB software reset
|
|
|
+ {
|
|
|
+ if(UDSDialogMode = 2)
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ osDelay(100);
|
|
|
+ appSaveNVMData();
|
|
|
+ appSetCFUN(0);
|
|
|
+ osDelay(1000);
|
|
|
+ EC_SystemReset();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF; //the dialog mode error
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x22:
|
|
|
+ if(UDSDialogMode == 2)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x01) //check the sw of NB
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x06;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = SWVERSION>>8;
|
|
|
+ UDSAnswer.Data[5] = SWVERSION;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x02) //check the hw of NB
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x06;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = HWVERSION>>8;
|
|
|
+ UDSAnswer.Data[5] = HWVERSION;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x03) //check the SN number
|
|
|
+ {
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ switch(UDSSubServiceActionCode[i])
|
|
|
+ {
|
|
|
+ case 00:
|
|
|
+ UDSAnswer.Id = 0x20;
|
|
|
+ for(k=0; k<8; k++)
|
|
|
+ {
|
|
|
+ UDSAnswer.Data[k] = AppNVMData.battSN[k+8*0];
|
|
|
+ }
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 01:
|
|
|
+ UDSAnswer.Id = 0x21;
|
|
|
+ for(k=0; k<8; k++)
|
|
|
+ {
|
|
|
+ UDSAnswer.Data[k] = AppNVMData.battSN[k+8*1];
|
|
|
+ }
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 02:
|
|
|
+ UDSAnswer.Id = 0x22;
|
|
|
+ UDSAnswer.Data[0] = AppNVMData.battSN[16];;
|
|
|
+ for(k=1; k<8; k++)
|
|
|
+ {
|
|
|
+ UDSAnswer.Data[k] = 0x00;
|
|
|
+ }
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("ID = %x\nData = ",UDSAnswer.Id);
|
|
|
+ for (int ii = 0; ii < 8; ii++)
|
|
|
+ {
|
|
|
+ printf("%x ", UDSAnswer.Data[ii]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x04) //check the batt message
|
|
|
+ {
|
|
|
+ /*
|
|
|
+ if(UDSSubService[i] == 0x00)
|
|
|
+ {
|
|
|
+ ret = xQueuePeek(UartReadQueueHandle,&Uart_Recv_Msg,1000);
|
|
|
+ }
|
|
|
+ if(ret)
|
|
|
+ {
|
|
|
+ //the uart_recv_msg.len = 5+(0x21+CellNum+TempNum)*2 = 5+(33+17+7)*2 = 5+ 114(max);114>112(14*8)
|
|
|
+ UINT8* p = (UINT8*)Uart_Recv_Msg.dataPtr+3;
|
|
|
+ MEMCPY(battInfo, p, 14*8);
|
|
|
+ }
|
|
|
+ */
|
|
|
+ osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
|
|
|
+ if(CanRxMsg[i].Data[2] == 0x00)
|
|
|
+ {
|
|
|
+ memcpy(battInfo,UartReadMsg.data,14*8);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("battInfo=\n");
|
|
|
+ for(int jj = 0;jj<14*8;jj++)
|
|
|
+ printf("%x ",battInfo[jj]);
|
|
|
+ printf("\n");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ osMutexRelease(UartMutex);
|
|
|
+
|
|
|
+ UDSAnswer.Id = 0x30+UDSSubServiceActionCode[i];
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+
|
|
|
+ MEMCPY(UDSAnswer.Data, &(battInfo[UDSSubServiceActionCode[i]*8]),8);
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("ID = %x\nData = ",UDSAnswer.Id);
|
|
|
+ for (int ij = 0; ij < 8; ij++)
|
|
|
+ {
|
|
|
+ printf("%x ", UDSAnswer.Data[ij]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ #endif
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x05) //check the enviroment temp of NB
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x08;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;//gNtcDev.NTCvalue[2+NTC_Channel2];
|
|
|
+ UDSAnswer.Data[5] = 0x00;//gNtcDev.NTCvalue[2+NTC_Channel3];
|
|
|
+ UDSAnswer.Data[6] = 0x00;//gNtcDev.NTCvalue[2+NTC_Channel4];
|
|
|
+ UDSAnswer.Data[7] = 0x00;//gNtcDev.NTCvalue[2+NTC_Channel5];
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x06) //check the tcp link of NB
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x06;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = socContext.status;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x07) //check the GPS link of NB
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = GpsData[1]; //gps satellite num(uint8), should be modified
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //当前会话模式错误
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x2E:
|
|
|
+ if(UDSDialogMode == 2)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x03)
|
|
|
+ {
|
|
|
+ if(UDSSubServiceActionCode[i] == 0x00 && snFlag == 0x00)
|
|
|
+ {
|
|
|
+ for(j=0; j<5; j++)
|
|
|
+ {
|
|
|
+ UDSBattSN[j+5*0] = CanRxMsg[i].Data[j+3];
|
|
|
+ }
|
|
|
+ snFlag = snFlag|0x01;
|
|
|
+ }
|
|
|
+ else if(UDSSubServiceActionCode[i] == 0x01 && snFlag == 0x01)
|
|
|
+ {
|
|
|
+ for(j=0; j<5; j++)
|
|
|
+ {
|
|
|
+ UDSBattSN[j+5*1] = CanRxMsg[i].Data[j+3];
|
|
|
+ }
|
|
|
+ snFlag = snFlag|0x02;
|
|
|
+ }
|
|
|
+ else if(UDSSubServiceActionCode[i] == 0x02 && snFlag == 0x03)
|
|
|
+ {
|
|
|
+ for(j=0; j<5; j++)
|
|
|
+ {
|
|
|
+ UDSBattSN[j+5*2] = CanRxMsg[i].Data[j+3];
|
|
|
+ }
|
|
|
+ snFlag = snFlag|0x04;
|
|
|
+ }
|
|
|
+ else if(UDSSubServiceActionCode[i] == 0x03 && snFlag == 0x07)
|
|
|
+ {
|
|
|
+ for(j=0; j<2; j++)
|
|
|
+ {
|
|
|
+ UDSBattSN[j+5*3] = CanRxMsg[i].Data[j+3];
|
|
|
+ }
|
|
|
+ snFlag = snFlag|0x08;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(snFlag == 0x0F)
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ snFlag = 0;
|
|
|
+
|
|
|
+ MEMCPY(AppNVMData.battSN, UDSBattSN, BATT_SN_LEN);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x3E;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = snFlag;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ }
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else if(UDSDialogMode==3)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x0F) //程序更新配置信息写入
|
|
|
+ {
|
|
|
+ updateDifferDataByteLen = (CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF; //the dialog mode error
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x31:
|
|
|
+ if(UDSDialogMode == 3)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x0F)
|
|
|
+ {
|
|
|
+ if(UDSSubServiceActionCode[i] == 0x01)
|
|
|
+ {
|
|
|
+ //Clear the Flash
|
|
|
+ boolRet = UDSClearFotaDownloadRegion();
|
|
|
+ //if ok
|
|
|
+
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = (UINT8)boolRet; // true:01, false: 00
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x06;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = UDSSubServiceActionCode[i];
|
|
|
+ UDSAnswer.Data[5] = 0xFF; //the uds subservice action code is not surpported
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surpported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF; //the dialog mode error
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x34: //ask for download update data
|
|
|
+ if(UDSDialogMode == 3)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x0F)
|
|
|
+ {
|
|
|
+ //ask for download the update data
|
|
|
+ boolRet = UDSAskforDownLoadData();
|
|
|
+ //if ok
|
|
|
+
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = (UINT8)boolRet; // true:01, false: 00
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xFF; //the dialog mode error
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x36: //download the update data
|
|
|
+ if(UDSSubService[i] == 0x0F)
|
|
|
+ {
|
|
|
+ counter++; //记录报文数量
|
|
|
+
|
|
|
+ tempSliceCounter = (CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
|
|
|
+ printf("tempSliceCounter = %x\n",tempSliceCounter);
|
|
|
+ // updateDifferDataByteLen
|
|
|
+ if(tempSliceCounter < (updateDifferDataPackageCounter+1)*25 && tempSliceCounter>=updateDifferDataPackageCounter*25)
|
|
|
+ {
|
|
|
+ updateDifferDataSliceCounter = tempSliceCounter % 25;
|
|
|
+ for(j=0;j<4;j++)
|
|
|
+ {
|
|
|
+ updateDataBuffer[updateDifferDataSliceCounter*4+j] = CanRxMsg[i].Data[4+j];
|
|
|
+ }
|
|
|
+
|
|
|
+ if(updateDifferDataSliceCounter>0)
|
|
|
+ {
|
|
|
+ sliceCounterFlag = sliceCounterFlag |(0x01<<updateDifferDataSliceCounter);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sliceCounterFlag = sliceCounterFlag |0x01;
|
|
|
+ }
|
|
|
+
|
|
|
+ printf("sliceCounterFlag = %x\n",sliceCounterFlag);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(counter == 25)
|
|
|
+ {
|
|
|
+ counter = 0;
|
|
|
+
|
|
|
+ if(sliceCounterFlag == 0x1FFFFFF)
|
|
|
+ {
|
|
|
+
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x06;
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = tempSliceCounter>>8;
|
|
|
+ UDSAnswer.Data[5] = tempSliceCounter;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ sliceCounterFlag = 0x0;
|
|
|
+ updateDifferDataPackageCounter++;
|
|
|
+ printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
|
|
|
+
|
|
|
+ printf("updateDataBuffer\n");
|
|
|
+ for(k=0;k<100;k++)
|
|
|
+ {
|
|
|
+ printf("%x ",updateDataBuffer[k]);
|
|
|
+ }
|
|
|
+ //BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
|
|
|
+ printf("startAddr = 0x%x,endAddr = 0x%x\n",
|
|
|
+ FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,FLASH_FOTA_REGION_START+updateDifferDataPackageCounter*100-1);
|
|
|
+ memset(updateDataBuffer,0, 100);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x08;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = sliceCounterFlag>>24;
|
|
|
+ UDSAnswer.Data[5] = sliceCounterFlag>>16;
|
|
|
+ UDSAnswer.Data[6] = sliceCounterFlag>>8;
|
|
|
+ UDSAnswer.Data[7] = sliceCounterFlag;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ printf("updateDataBuffer\n");
|
|
|
+ for(k=0;k<100;k++)
|
|
|
+ {
|
|
|
+ printf("%x ",updateDataBuffer[k]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x37: // exit the download
|
|
|
+ if(UDSSubService[i] == 0x0F)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x05;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i];
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[i];
|
|
|
+ UDSAnswer.Data[4] = 0xEE; //the sub service is not surported
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ UDSAnswer.Data[0] = 0x04;
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
+ UDSAnswer.Data[2] = UDSService[i]; //the serviece is not surpoted
|
|
|
+ UDSAnswer.Data[3] = 0xFF;
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //}
|
|
|
+ for(i=0; i<2; i++)
|
|
|
+ {
|
|
|
+ UDSService[i] = 0;
|
|
|
+ UDSSubService[i] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void UDS_CAN_Update()
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+BOOL UDSClearFotaDownloadRegion()
|
|
|
+{
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+BOOL UDSAskforDownLoadData()
|
|
|
+{
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
+}
|