|
@@ -21,17 +21,23 @@
|
|
#include "MainTask.h"
|
|
#include "MainTask.h"
|
|
#include "app.h"
|
|
#include "app.h"
|
|
#include "CANTask.h"
|
|
#include "CANTask.h"
|
|
|
|
+#include "flash_ec616_rt.h"
|
|
|
|
+
|
|
#include "UDSService.h"
|
|
#include "UDSService.h"
|
|
|
|
|
|
|
|
|
|
//
|
|
//
|
|
extern UartReadMsgType UartReadMsg;
|
|
extern UartReadMsgType UartReadMsg;
|
|
extern osMutexId_t UartMutex;
|
|
extern osMutexId_t UartMutex;
|
|
|
|
+extern AppSocketConnectionContext socContext;
|
|
|
|
+extern UINT8 GpsData[16];
|
|
|
|
|
|
void UDS_Service(void);
|
|
void UDS_Service(void);
|
|
void UDS_CAN_Update(void);
|
|
void UDS_CAN_Update(void);
|
|
BOOL UDSClearFotaDownloadRegion(void);
|
|
BOOL UDSClearFotaDownloadRegion(void);
|
|
BOOL UDSAskforDownLoadData(void);
|
|
BOOL UDSAskforDownLoadData(void);
|
|
|
|
+UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode);
|
|
|
|
+UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode);
|
|
extern void appSaveConfigValue(void);
|
|
extern void appSaveConfigValue(void);
|
|
|
|
|
|
|
|
|
|
@@ -39,34 +45,37 @@ UINT8 UDSService[2];
|
|
UINT8 UDSSubService[2];
|
|
UINT8 UDSSubService[2];
|
|
UINT8 UDSSubServiceActionCode[2];
|
|
UINT8 UDSSubServiceActionCode[2];
|
|
UINT8 UDSSwitch = 0;
|
|
UINT8 UDSSwitch = 0;
|
|
-UINT8 UDSDialogMode = 0;
|
|
|
|
|
|
+UINT8 UDSDialogMode = 01;
|
|
UINT8 UDSBattSN[BATT_SN_LEN];
|
|
UINT8 UDSBattSN[BATT_SN_LEN];
|
|
|
|
|
|
-UINT16 updateDifferDataByteLen = 0;
|
|
|
|
|
|
+UINT32 updateDifferDataByteLen = 0;
|
|
|
|
|
|
//each package means 100 bytes, max PackageCounter = updateDifferDataByteLen%100 + 1
|
|
//each package means 100 bytes, max PackageCounter = updateDifferDataByteLen%100 + 1
|
|
UINT16 updateDifferDataPackageCounter = 0;
|
|
UINT16 updateDifferDataPackageCounter = 0;
|
|
|
|
|
|
//each slice means 4 bytes, max SliceCounter = 25;
|
|
//each slice means 4 bytes, max SliceCounter = 25;
|
|
-UINT16 updateDifferDataSliceCounter = 0;
|
|
|
|
-
|
|
|
|
|
|
+UINT32 updateDifferDataSliceCounter = 0;
|
|
|
|
+static BOOL downloadReady = FALSE;
|
|
|
|
|
|
UINT8 updateDataBuffer[100];
|
|
UINT8 updateDataBuffer[100];
|
|
|
|
|
|
-extern UINT8 BattSN[BATT_SN_LEN];
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
void UDS_Service()
|
|
void UDS_Service()
|
|
{
|
|
{
|
|
- UINT8 i,j,k = 0;
|
|
|
|
- INT8 ret = 0;
|
|
|
|
|
|
+ UINT8 i,j= 0;
|
|
|
|
+ UINT32 k=0;
|
|
|
|
+ INT8 ret,errorCount = 0;
|
|
BOOL boolRet = false;
|
|
BOOL boolRet = false;
|
|
static UINT8 snFlag = 0;
|
|
static UINT8 snFlag = 0;
|
|
static UINT32 sliceCounterFlag = 0;
|
|
static UINT32 sliceCounterFlag = 0;
|
|
- UINT16 tempSliceCounter=0;
|
|
|
|
|
|
+ UINT32 tempSliceCounter=0;
|
|
static UINT8 counter=0;
|
|
static UINT8 counter=0;
|
|
CAN_Msg_Type UDSAnswer ={0};
|
|
CAN_Msg_Type UDSAnswer ={0};
|
|
static UINT8 battInfo[8*14] = {0};
|
|
static UINT8 battInfo[8*14] = {0};
|
|
|
|
+ UINT32 posCode,negCode;
|
|
|
|
|
|
//UartReadMsg Uart_Recv_Msg;
|
|
//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};
|
|
//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};
|
|
@@ -85,102 +94,42 @@ void UDS_Service()
|
|
case 0x10:
|
|
case 0x10:
|
|
if(UDSSubService[i] == 0x01)
|
|
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);
|
|
|
|
|
|
+ if((UDSDialogMode == 0x01 || UDSDialogMode==0x02)||UDSSwitch == 0)
|
|
|
|
+ {
|
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
UDSSwitch = 0;
|
|
UDSSwitch = 0;
|
|
UDSDialogMode = 1;
|
|
UDSDialogMode = 1;
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x02)
|
|
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;
|
|
|
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
UDSSwitch = 1;
|
|
UDSSwitch = 1;
|
|
- UDSDialogMode = 2;
|
|
|
|
- ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
|
|
|
+ UDSDialogMode = 2;
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x03)
|
|
else if(UDSSubService[i] == 0x03)
|
|
{
|
|
{
|
|
if(UDSSwitch == 1)
|
|
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);
|
|
|
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
UDSSwitch = 1;
|
|
UDSSwitch = 1;
|
|
UDSDialogMode = 3;
|
|
UDSDialogMode = 3;
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x11) //make NB software reset
|
|
else if(UDSSubService[i] == 0x11) //make NB software reset
|
|
{
|
|
{
|
|
- if(UDSDialogMode = 2)
|
|
|
|
|
|
+ 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);
|
|
|
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
osDelay(100);
|
|
osDelay(100);
|
|
appSaveNVMData();
|
|
appSaveNVMData();
|
|
appSetCFUN(0);
|
|
appSetCFUN(0);
|
|
@@ -189,32 +138,12 @@ void UDS_Service()
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case 0x22:
|
|
case 0x22:
|
|
@@ -222,31 +151,11 @@ void UDS_Service()
|
|
{
|
|
{
|
|
if(UDSSubService[i] == 0x01) //check the sw of NB
|
|
if(UDSSubService[i] == 0x01) //check the sw 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] = APPSWVERSION>>24;
|
|
|
|
- UDSAnswer.Data[5] = APPSWVERSION>>16;
|
|
|
|
- UDSAnswer.Data[6] = APPSWVERSION>>8;
|
|
|
|
- UDSAnswer.Data[7] = APPSWVERSION;
|
|
|
|
- ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
|
|
|
+ UDSPositiveAnswer(0x08,i,APPSWVERSION);
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x02) //check the hw of NB
|
|
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);
|
|
|
|
|
|
+ UDSPositiveAnswer(0x06,i,HWVERSION);
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x03) //check the SN number
|
|
else if(UDSSubService[i] == 0x03) //check the SN number
|
|
{
|
|
{
|
|
@@ -281,42 +190,23 @@ void UDS_Service()
|
|
ret = HAL_Can_Transmit(UDSAnswer);
|
|
ret = HAL_Can_Transmit(UDSAnswer);
|
|
break;
|
|
break;
|
|
default:
|
|
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
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x04) //check the batt message
|
|
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);
|
|
osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
|
|
if(CanRxMsg[i].Data[2] == 0x00)
|
|
if(CanRxMsg[i].Data[2] == 0x00)
|
|
{
|
|
{
|
|
- memcpy(battInfo,UartReadMsg.data,14*8);
|
|
|
|
|
|
+ MEMCPY(battInfo,UartReadMsg.data,14*8);
|
|
|
|
+ /*
|
|
#ifdef USING_PRINTF
|
|
#ifdef USING_PRINTF
|
|
printf("battInfo=\n");
|
|
printf("battInfo=\n");
|
|
for(int jj = 0;jj<14*8;jj++)
|
|
for(int jj = 0;jj<14*8;jj++)
|
|
printf("%x ",battInfo[jj]);
|
|
printf("%x ",battInfo[jj]);
|
|
printf("\n");
|
|
printf("\n");
|
|
#endif
|
|
#endif
|
|
|
|
+ */
|
|
}
|
|
}
|
|
osMutexRelease(UartMutex);
|
|
osMutexRelease(UartMutex);
|
|
|
|
|
|
@@ -324,95 +214,35 @@ void UDS_Service()
|
|
UDSAnswer.DLC = 8;
|
|
UDSAnswer.DLC = 8;
|
|
|
|
|
|
MEMCPY(UDSAnswer.Data, &(battInfo[UDSSubServiceActionCode[i]*8]),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
|
|
|
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x05) //check the enviroment temp of NB
|
|
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);
|
|
|
|
-
|
|
|
|
|
|
+ UDSPositiveAnswer(0x08,i,0x00); //ntcvalue
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x06) //check the tcp link of NB
|
|
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);
|
|
|
|
|
|
+ UDSPositiveAnswer(0x06,i,socContext.status); //TcpconnectStatus
|
|
}
|
|
}
|
|
else if(UDSSubService[i] == 0x07) //check the GPS link of NB
|
|
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);
|
|
|
|
|
|
+ posCode =(UINT32) GpsData[1];
|
|
|
|
+ UDSPositiveAnswer(0x05,i,posCode); //gps satellite num(uint8), should be modified
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else //当前会话模式错误
|
|
|
|
|
|
+ else //the service is not surpported in current dialog mode
|
|
{
|
|
{
|
|
- 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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case 0x2E:
|
|
|
|
|
|
+ case 0x2E: //write service
|
|
if(UDSDialogMode == 2)
|
|
if(UDSDialogMode == 2)
|
|
{
|
|
{
|
|
- if(UDSSubService[i] == 0x03)
|
|
|
|
|
|
+ if(UDSSubService[i] == 0x03) // write the battSN
|
|
{
|
|
{
|
|
if(UDSSubServiceActionCode[i] == 0x00 && snFlag == 0x00)
|
|
if(UDSSubServiceActionCode[i] == 0x00 && snFlag == 0x00)
|
|
{
|
|
{
|
|
@@ -449,19 +279,10 @@ void UDS_Service()
|
|
|
|
|
|
if(snFlag == 0x0F)
|
|
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;
|
|
snFlag = 0;
|
|
-
|
|
|
|
- MEMCPY(AppNVMData.battSN, UDSBattSN, BATT_SN_LEN);
|
|
|
|
|
|
+ UDSPositiveAnswer(0x04,i,00);
|
|
|
|
+ MEMCPY(AppNVMData.battSN, UDSBattSN, BATT_SN_LEN);
|
|
|
|
+ AppNVMData.EOLState = 1; //SN号写入完成,表明已经进行过下线配置
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -475,330 +296,201 @@ void UDS_Service()
|
|
UDSAnswer.Data[5] = 0x00;
|
|
UDSAnswer.Data[5] = 0x00;
|
|
UDSAnswer.Data[6] = 0x00;
|
|
UDSAnswer.Data[6] = 0x00;
|
|
UDSAnswer.Data[7] = 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);
|
|
|
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- break;
|
|
|
|
- }
|
|
|
|
- else if(UDSDialogMode==3)
|
|
|
|
- {
|
|
|
|
- if(UDSSubService[i] == 0x0F) //程序更新配置信息写入
|
|
|
|
|
|
+ else if(UDSSubService[i] == 0x0F) //write the update config:updateDifferDataByteLen
|
|
{
|
|
{
|
|
- 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);
|
|
|
|
|
|
+ updateDifferDataByteLen = (CanRxMsg[i].Data[2]<<16)|(CanRxMsg[i].Data[3]<<8)|CanRxMsg[i].Data[4];
|
|
|
|
+ UDSPositiveAnswer(0x04,i,00);
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
|
|
+
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
- break;
|
|
|
|
- case 0x31:
|
|
|
|
- if(UDSDialogMode == 3)
|
|
|
|
|
|
+ break;
|
|
|
|
+ case 0x31: //clear the flash service
|
|
|
|
+ if(UDSDialogMode == 3)
|
|
{
|
|
{
|
|
- if(UDSSubService[i] == 0x0F)
|
|
|
|
|
|
+ if(UDSSubService[i] == 0x0F) //clear the fota flash
|
|
{
|
|
{
|
|
if(UDSSubServiceActionCode[i] == 0x01)
|
|
if(UDSSubServiceActionCode[i] == 0x01)
|
|
{
|
|
{
|
|
//Clear the Flash
|
|
//Clear the Flash
|
|
boolRet = UDSClearFotaDownloadRegion();
|
|
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);
|
|
|
|
|
|
+ //if ok
|
|
|
|
+ UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x06,i,UDSSubServiceActionCode[i]<<8|0xFF); //重点测试
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE); //the subservice is not surpported
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
-
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF); //the survie is not surpported in current dialog mode
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
- case 0x34: //ask for download update data
|
|
|
|
|
|
+ case 0x34: //prepare for some one process
|
|
if(UDSDialogMode == 3)
|
|
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);
|
|
|
|
|
|
+ if(UDSSubService[i] == 0x0F) //ask for download update data
|
|
|
|
+ {
|
|
|
|
+ boolRet = UDSAskforDownLoadData();
|
|
|
|
+ //if ok
|
|
|
|
+ UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
-
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case 0x36: //download the update data
|
|
case 0x36: //download the update data
|
|
- if(UDSSubService[i] == 0x0F)
|
|
|
|
|
|
+ if(UDSDialogMode == 3)
|
|
{
|
|
{
|
|
- 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)
|
|
|
|
|
|
+ if(downloadReady == TRUE)
|
|
{
|
|
{
|
|
- 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)
|
|
|
|
|
|
+ counter++; //记录报文数量
|
|
|
|
+ tempSliceCounter = (CanRxMsg[i].Data[1]<<16)|(CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
|
|
|
|
+ /*
|
|
|
|
+ #ifdef USING_PRINTF
|
|
|
|
+ printf("tempSliceCounter = %x\n",tempSliceCounter);
|
|
|
|
+ #endif
|
|
|
|
+ */
|
|
|
|
+ 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];
|
|
|
|
+ }
|
|
|
|
|
|
- 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++)
|
|
|
|
|
|
+ if(updateDifferDataSliceCounter>0)
|
|
{
|
|
{
|
|
- printf("%x ",updateDataBuffer[k]);
|
|
|
|
|
|
+ sliceCounterFlag = sliceCounterFlag |(0x01<<updateDifferDataSliceCounter);
|
|
}
|
|
}
|
|
- //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
|
|
|
|
+ {
|
|
|
|
+ sliceCounterFlag = sliceCounterFlag |0x01;
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
+ #ifdef USING_PRINTF
|
|
|
|
+ printf("sliceCounterFlag = %x counter=%d\n",sliceCounterFlag,counter);
|
|
|
|
+ #endif
|
|
|
|
+ */
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ if(counter == 25)
|
|
{
|
|
{
|
|
- 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);
|
|
|
|
|
|
+ counter = 0;
|
|
|
|
|
|
- printf("updateDataBuffer\n");
|
|
|
|
- for(k=0;k<100;k++)
|
|
|
|
|
|
+ if(sliceCounterFlag == 0x1FFFFFF) //received all the 25 message of current package
|
|
|
|
+ {
|
|
|
|
+ sliceCounterFlag = 0x0;
|
|
|
|
+ updateDifferDataPackageCounter++;
|
|
|
|
+ /*
|
|
|
|
+ #ifdef USING_PRINTF
|
|
|
|
+ printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
|
|
|
|
+
|
|
|
|
+ printf("updateDataBuffer\n");
|
|
|
|
+ for(k=0;k<100;k++)
|
|
|
|
+ {
|
|
|
|
+ printf("%x ",updateDataBuffer[k]);
|
|
|
|
+ }
|
|
|
|
+ printf("\n");
|
|
|
|
+
|
|
|
|
+ printf("startAddr = 0x%x,endAddr = 0x%x\n",
|
|
|
|
+ FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,FLASH_FOTA_REGION_START+updateDifferDataPackageCounter*100-1);
|
|
|
|
+ #endif
|
|
|
|
+ */
|
|
|
|
+ //write the buffer(100 byte) to flash
|
|
|
|
+ ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
|
|
|
|
+ errorCount = 0;
|
|
|
|
+ while(ret != QSPI_OK && errorCount<3) //try to write most 3 times
|
|
|
|
+ {
|
|
|
|
+ errorCount++;
|
|
|
|
+ BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
|
|
|
|
+ ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
|
|
|
|
+ }
|
|
|
|
+ if(ret == QSPI_OK)
|
|
|
|
+ {
|
|
|
|
+ UDSPositiveAnswer(0x08,i,tempSliceCounter);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ UDSNegtiveAnswer(0x08,i,0xFFFFFFFF); //failed to write this package to flash
|
|
|
|
+ }
|
|
|
|
+ memset(updateDataBuffer,0, 100);
|
|
|
|
+ sliceCounterFlag = 0x0;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- printf("%x ",updateDataBuffer[k]);
|
|
|
|
|
|
+ //received 25 messages, but lose one or more messages
|
|
|
|
+ //in this case, updater will try to send the package again(most 4 times)
|
|
|
|
+ UDSNegtiveAnswer(0x08,i,sliceCounterFlag);
|
|
|
|
+ //sliceCounterFlag = 0x0;
|
|
|
|
+ /*
|
|
|
|
+ #ifdef USING_PRINTF
|
|
|
|
+ printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter+1);
|
|
|
|
+ printf("updateDataBuffer:\n");
|
|
|
|
+ for(k=0;k<100;k++)
|
|
|
|
+ {
|
|
|
|
+ printf("%x ",updateDataBuffer[k]);
|
|
|
|
+ }
|
|
|
|
+ printf("\n");
|
|
|
|
+ #endif
|
|
|
|
+ */
|
|
|
|
+ //memset(updateDataBuffer,0, 100);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEF); //the download process is not ready
|
|
|
|
+ }
|
|
}
|
|
}
|
|
else
|
|
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);
|
|
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF); //the service is not surpported in current dialog mode
|
|
}
|
|
}
|
|
break;
|
|
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);
|
|
|
|
|
|
+ case 0x37: //exit some one process
|
|
|
|
+ if(UDSDialogMode == 3)
|
|
|
|
+ {
|
|
|
|
+ if(UDSSubService[i] == 0x0F) // exit the download
|
|
|
|
+ {
|
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
|
|
+ downloadReady = FALSE;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
}
|
|
}
|
|
-
|
|
|
|
break;
|
|
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);
|
|
|
|
|
|
+ default:
|
|
|
|
+ UDSNegtiveAnswer(0x04,i,0xFF); //the service is not surpported
|
|
break;
|
|
break;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -814,22 +506,125 @@ void UDS_Service()
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-void UDS_CAN_Update()
|
|
|
|
|
|
+UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode)
|
|
{
|
|
{
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ CAN_Msg_Type UDSAnswer;
|
|
|
|
+ UINT8 ret;
|
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
|
+ UDSAnswer.Data[0] = answerLen;
|
|
|
|
+ UDSAnswer.Data[1] = 0x78;
|
|
|
|
+ UDSAnswer.Data[2] = UDSService[messageIndex];
|
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[messageIndex];
|
|
|
|
+ if(answerLen == 4)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==5)
|
|
|
|
+ { UDSAnswer.Data[4] = posCode;
|
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==6)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = posCode>>8;
|
|
|
|
+ UDSAnswer.Data[5] = posCode;
|
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==7)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = posCode>>16;
|
|
|
|
+ UDSAnswer.Data[5] = posCode>>8;
|
|
|
|
+ UDSAnswer.Data[6] = posCode;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==8)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = posCode>>24;
|
|
|
|
+ UDSAnswer.Data[5] = posCode>>16;
|
|
|
|
+ UDSAnswer.Data[6] = posCode>>8;
|
|
|
|
+ UDSAnswer.Data[7] = posCode;
|
|
|
|
+ }
|
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
|
|
|
|
+UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode)
|
|
|
|
+{
|
|
|
|
+ CAN_Msg_Type UDSAnswer;
|
|
|
|
+ UINT8 ret;
|
|
|
|
+ UDSAnswer.Id = 0x7A8;
|
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
|
+ UDSAnswer.Data[0] = answerLen;
|
|
|
|
+ UDSAnswer.Data[1] = 0x7F;
|
|
|
|
+ UDSAnswer.Data[2] = UDSService[messageIndex];
|
|
|
|
+ UDSAnswer.Data[3] = UDSSubService[messageIndex];
|
|
|
|
+ if(answerLen==4)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[3] = negCode;
|
|
|
|
+ UDSAnswer.Data[4] = 0x00;
|
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ if(answerLen==5)
|
|
|
|
+ { UDSAnswer.Data[4] = negCode;
|
|
|
|
+ UDSAnswer.Data[5] = 0x00;
|
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==6)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = negCode>>8;
|
|
|
|
+ UDSAnswer.Data[5] = negCode;
|
|
|
|
+ UDSAnswer.Data[6] = 0x00;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==7)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = negCode>>16;
|
|
|
|
+ UDSAnswer.Data[5] = negCode>>8;
|
|
|
|
+ UDSAnswer.Data[6] = negCode;
|
|
|
|
+ UDSAnswer.Data[7] = 0x00;
|
|
|
|
+ }
|
|
|
|
+ else if(answerLen==8)
|
|
|
|
+ {
|
|
|
|
+ UDSAnswer.Data[4] = negCode>>24;
|
|
|
|
+ UDSAnswer.Data[5] = negCode>>16;
|
|
|
|
+ UDSAnswer.Data[6] = negCode>>8;
|
|
|
|
+ UDSAnswer.Data[7] = negCode;
|
|
|
|
+ }
|
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
-BOOL UDSClearFotaDownloadRegion()
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+BOOL UDSAskforDownLoadData()
|
|
{
|
|
{
|
|
|
|
+ updateDifferDataPackageCounter = 0;
|
|
|
|
+ downloadReady = true;
|
|
|
|
|
|
return TRUE;
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
-BOOL UDSAskforDownLoadData()
|
|
|
|
|
|
+BOOL UDSClearFotaDownloadRegion()
|
|
{
|
|
{
|
|
|
|
+ UINT8 ret = FALSE;
|
|
|
|
+ ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x78000); //512k-32k = 480k -> 0x75300
|
|
|
|
+
|
|
|
|
+ if(ret == QSPI_OK)
|
|
|
|
+ {
|
|
|
|
+ return TRUE;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return FALSE;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- return TRUE;
|
|
|
|
-}
|
|
|