|
@@ -683,15 +683,17 @@ static void setDefaultAppDataInfo(void)
|
|
|
AppDataInfo.RelayControl = 0;
|
|
|
AppDataInfo.BattLock = 0;
|
|
|
AppDataInfo.BattStolenFlag = 0;
|
|
|
- memset(&AppDataInfo.blcv_Q_totalCpE, 0x00, 28);
|
|
|
- memset(&AppDataInfo.blcv_Q_reqCpE, 0x00, 28);
|
|
|
+ memset(AppDataInfo.blcv_Q_totalCpE, 0x00, 28);
|
|
|
+ memset(AppDataInfo.blcv_Q_reqCpE, 0x00, 28);
|
|
|
AppDataInfo.socd_pct_bcuSocE = 0;
|
|
|
AppDataInfo.socd_pct_battSocE = 0;
|
|
|
AppDataInfo.sohd_tm_chrgStartStatE = 0;
|
|
|
AppDataInfo.sohd_flg_chrgEndE = 0;
|
|
|
- memset(&AppDataInfo.sohv_V_chrgStartStatE, 0x00, 28);
|
|
|
+ memset(AppDataInfo.sohv_V_chrgStartStatE, 0x00, 28);
|
|
|
AppDataInfo. sohd_Q_chrgE = 0;
|
|
|
- memset(&AppDataInfo.sohv_Q_packCapArrE, 300, 10);
|
|
|
+ memset(AppDataInfo.sohv_Q_packCapArrE, 300, 10);
|
|
|
+ memset(AppDataInfo.VIN,0xFF,17);
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -3614,6 +3616,556 @@ BOOL VINCodeCompare(UINT8* saveVIN, UINT8* receivedVIN)
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /***********************************************************************************************************************
|
|
|
+ * UDS函数
|
|
|
+ * 输入:报文内容(含ID)
|
|
|
+ * 输出:--
|
|
|
+ * 处理:根据报文内容,进行包括读取版本号、读写SN、查询状态,用于完成下线检测和通过CAN接收升级包等操作
|
|
|
+***********************************************************************************************************************/
|
|
|
+void UDS_Service(CAN_Msg_Type* CanRxMsg)
|
|
|
+{
|
|
|
+ UINT8 i,j= 0;
|
|
|
+ UINT32 k=0;
|
|
|
+ INT8 ret,errorCount = 0;
|
|
|
+ BOOL boolRet = false;
|
|
|
+ static UINT8 snFlag = 0;
|
|
|
+ static UINT32 sliceCounterFlag = 0;
|
|
|
+ UINT32 tempSliceCounter=0;
|
|
|
+ static UINT8 counter=0;
|
|
|
+ CAN_Msg_Type UDSAnswer ={0};
|
|
|
+ UINT32 posCode,negCode;
|
|
|
+ UINT32 updateDifferDataByteLen = 0;
|
|
|
+ static UINT8 updateDataBuffer[100];
|
|
|
+ UINT8 nvmTemp[100];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ static UINT32 updateDifferDataSliceCounter = 0;
|
|
|
+ static UINT8 UDSSwitch = 0;
|
|
|
+ static UINT8 UDSDialogMode = 01;
|
|
|
+ static UINT8 UDSBattSN[BATT_SN_LEN];
|
|
|
+
|
|
|
+ for(i=0; i<2; i++)
|
|
|
+ {
|
|
|
+ UDSAnswer.DLC = 8;
|
|
|
+ memset(UDSAnswer.Data, 0, UDSAnswer.DLC);
|
|
|
+ UDSService[i] = CanRxMsg[i].Data[0];
|
|
|
+ UDSSubService[i] = CanRxMsg[i].Data[1];
|
|
|
+ UDSSubServiceActionCode[i] = CanRxMsg[i].Data[2];
|
|
|
+ if(CanRxMsg[i].Id == 0x7A0)
|
|
|
+ {
|
|
|
+ switch (UDSService[i])
|
|
|
+ {
|
|
|
+ case 0x10:
|
|
|
+ if(UDSSubService[i] == 0x01)
|
|
|
+ {
|
|
|
+ if((UDSDialogMode == 0x01 || UDSDialogMode==0x02)||UDSSwitch == 0)
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
|
+ UDSSwitch = 0;
|
|
|
+ UDSDialogMode = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x02)
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
|
+ UDSSwitch = 1;
|
|
|
+ UDSDialogMode = 2;
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x03)
|
|
|
+ {
|
|
|
+ if(UDSSwitch == 1)
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
|
+ UDSSwitch = 1;
|
|
|
+ UDSDialogMode = 3;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x11) //make NB software reset
|
|
|
+ {
|
|
|
+ if(UDSDialogMode == 2)
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x04,i,0x00);
|
|
|
+ osDelay(100);
|
|
|
+ SaveAppConfig();
|
|
|
+ appSetCFUN(0);
|
|
|
+ osDelay(1000);
|
|
|
+ EC_SystemReset();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x22:
|
|
|
+ if(UDSDialogMode == 2)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x01) //check the sw of NB
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x08,i,APPSWVERSION);
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x02) //check the hw of NB
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x06,i,HWVERSION);
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x03) //check the SN number
|
|
|
+ {
|
|
|
+ switch(UDSSubServiceActionCode[i])
|
|
|
+ {
|
|
|
+ case 00:
|
|
|
+ UDSAnswer.Id = 0x7B0;
|
|
|
+ CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 01:
|
|
|
+ UDSAnswer.Id = 0x7B1;
|
|
|
+ CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 02:
|
|
|
+ UDSAnswer.Id = 0x7B2;
|
|
|
+ CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
|
|
|
+ ret = HAL_Can_Transmit(UDSAnswer);
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ else if(UDSSubService[i] == 0x06) //check the tcp link of NB
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x06,i,TcpSendLen); //TcpconnectStatus
|
|
|
+ }
|
|
|
+ else if(UDSSubService[i] == 0x07) //check the GPS link of NB
|
|
|
+ {
|
|
|
+ posCode =(UINT32) GpsData[1];
|
|
|
+ UDSPositiveAnswer(0x05,i,posCode); //gps satellite num(uint8), should be modified
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //the service is not surpported in current dialog mode
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x2E: //write service
|
|
|
+ if(UDSDialogMode == 2)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x0F) //write the update config:updateDifferDataByteLen
|
|
|
+ {
|
|
|
+ updateDifferDataByteLen = (CanRxMsg[i].Data[2]<<16)|(CanRxMsg[i].Data[3]<<8)|CanRxMsg[i].Data[4];
|
|
|
+ UDSPositiveAnswer(0x04,i,00);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x31: //clear the flash service
|
|
|
+ if(UDSDialogMode == 3)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x0F) //clear the fota flash
|
|
|
+ {
|
|
|
+ if(UDSSubServiceActionCode[i] == 0x01)
|
|
|
+ {
|
|
|
+ //Clear the Flash
|
|
|
+ boolRet = UDSClearFotaDownloadRegion();
|
|
|
+ //if ok
|
|
|
+ UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x06,i,UDSSubServiceActionCode[i]<<8|0xFF); //重点测试
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE); //the subservice is not surpported
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF); //the survie is not surpported in current dialog mode
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x34: //prepare for some one process
|
|
|
+ if(UDSDialogMode == 3)
|
|
|
+ {
|
|
|
+ if(UDSSubService[i] == 0x0F) //ask for download update data
|
|
|
+ {
|
|
|
+ boolRet = UDSAskforDownLoadData();
|
|
|
+ //if ok
|
|
|
+ UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 0x36: //download the update data
|
|
|
+ if(UDSDialogMode == 3)
|
|
|
+ {
|
|
|
+ if(downloadReady == TRUE)
|
|
|
+ {
|
|
|
+ counter++; //记录报文数量
|
|
|
+ tempSliceCounter = (CanRxMsg[i].Data[1]<<16)|(CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
|
|
|
+
|
|
|
+ if(tempSliceCounter < (updateDifferDataPackageCounter+1)*25 && tempSliceCounter>=updateDifferDataPackageCounter*25)
|
|
|
+ {
|
|
|
+ updateDifferDataSliceCounter = tempSliceCounter % 25;
|
|
|
+ #ifdef USING_PRINTF2
|
|
|
+ printf("tempSliceCounter-updateDifferDataSliceCounter: %x-%x %02X %02X %02X %02X\n",tempSliceCounter,updateDifferDataSliceCounter,CanRxMsg[i].Data[4],CanRxMsg[i].Data[5],CanRxMsg[i].Data[6],CanRxMsg[i].Data[7]);
|
|
|
+ #endif
|
|
|
+
|
|
|
+ for(j=0;j<4;j++)
|
|
|
+ {
|
|
|
+ updateDataBuffer[updateDifferDataSliceCounter*4+j] = CanRxMsg[i].Data[4+j];
|
|
|
+ }
|
|
|
+ #ifdef USING_PRINTF2
|
|
|
+ printf("updateDataBuffer[updateDifferDataSliceCounter*4+j]: %02X %02X %02X %02X\n",updateDataBuffer[updateDifferDataSliceCounter*4+0],updateDataBuffer[updateDifferDataSliceCounter*4+1],updateDataBuffer[updateDifferDataSliceCounter*4+2],updateDataBuffer[updateDifferDataSliceCounter*4+3]);
|
|
|
+ #endif
|
|
|
+ if(updateDifferDataSliceCounter>0)
|
|
|
+ {
|
|
|
+ sliceCounterFlag = sliceCounterFlag |(0x01<<updateDifferDataSliceCounter);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ sliceCounterFlag = sliceCounterFlag |0x01;
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("sliceCounterFlag = %x counter=%d\n",sliceCounterFlag,counter);
|
|
|
+ #endif
|
|
|
+ */
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ counter--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(counter == 25)
|
|
|
+ {
|
|
|
+ counter = 0;
|
|
|
+ if(sliceCounterFlag == 0x1FFFFFF) //received all the 25 message of current package
|
|
|
+ {
|
|
|
+ //write the buffer(100 byte) to flash
|
|
|
+ #ifdef USING_PRINTF2
|
|
|
+ for(int jjj =0;jjj<100;jjj++)
|
|
|
+ printf("%02X ",updateDataBuffer[jjj]);
|
|
|
+ printf("\n");
|
|
|
+ #endif
|
|
|
+ ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*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)*100,100);
|
|
|
+ ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
|
|
|
+ }
|
|
|
+ memset(nvmTemp, 0, 100);
|
|
|
+ BSP_QSPI_Read_Safe(nvmTemp, FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100, 100);
|
|
|
+ //printf("addr = %X\n",FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100);
|
|
|
+ for(int ii=0;ii<100;ii++)
|
|
|
+ {
|
|
|
+ if(nvmTemp[ii]==updateDataBuffer[ii])
|
|
|
+ {
|
|
|
+ #ifdef USING_PRINTF2
|
|
|
+ printf("%02X ",nvmTemp[ii]);
|
|
|
+ #endif
|
|
|
+ ret = QSPI_OK;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ret = QSPI_ERROR;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //printf("\n");
|
|
|
+ if(ret == QSPI_OK) // write successed
|
|
|
+ {
|
|
|
+ UDSPositiveAnswer(0x08,i,tempSliceCounter);
|
|
|
+ memset(updateDataBuffer,0, 100);
|
|
|
+ sliceCounterFlag = 0x0;
|
|
|
+ updateDifferDataPackageCounter++;
|
|
|
+ }
|
|
|
+ else //write fail
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x08,i,0xFFFFFFFF); //failed to write this package to flash
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xEF); //the download process is not ready
|
|
|
+ counter = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UDSNegtiveAnswer(0x05,i,0xFF); //the service is not surpported in current dialog mode
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ 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;
|
|
|
+ default:
|
|
|
+ UDSNegtiveAnswer(0x04,i,0xFF); //the service is not surpported
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(i=0; i<2; i++)
|
|
|
+ {
|
|
|
+ UDSService[i] = 0;
|
|
|
+ UDSSubService[i] = 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/***********************************************************************************************************************
|
|
|
+ * UDS肯定响应
|
|
|
+ * 输入:应答数据长度、应答的报文指数、响应代码
|
|
|
+ * 输出:响应报文发送成功/失败
|
|
|
+ * 处理:发送肯定响应报文
|
|
|
+***********************************************************************************************************************/
|
|
|
+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;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/***********************************************************************************************************************
|
|
|
+ * UDS否定响应
|
|
|
+ * 输入:应答数据长度、应答的报文指数、响应代码
|
|
|
+ * 输出:响应报文发送成功/失败
|
|
|
+ * 处理:发送否定响应报文
|
|
|
+***********************************************************************************************************************/
|
|
|
+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 UDSAskforDownLoadData()
|
|
|
+{
|
|
|
+ updateDifferDataPackageCounter = 0;
|
|
|
+ downloadReady = true;
|
|
|
+ return TRUE;
|
|
|
+}
|
|
|
+
|
|
|
+/***********************************************************************************************************************
|
|
|
+ * 清除数据接收的flash区域
|
|
|
+ * 输入:--
|
|
|
+ * 输出:--
|
|
|
+ * 处理:清除数据接收的flash区域
|
|
|
+***********************************************************************************************************************/
|
|
|
+BOOL UDSClearFotaDownloadRegion()
|
|
|
+{
|
|
|
+ UINT8 ret = FALSE;
|
|
|
+ ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x46000); //512k-32k -200k = 280k -> 0x46000
|
|
|
+
|
|
|
+ if(ret == QSPI_OK)
|
|
|
+ {
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/***********************************************************************************************************************
|
|
|
+ * 周期性报文组包
|
|
|
+ * 输入:报文ID、can报文数据(指针)
|
|
|
+ * 输出:--
|
|
|
+ * 处理:根据不同的ID,进行组包,并放入指针中
|
|
|
+***********************************************************************************************************************/
|
|
|
+
|
|
|
+void CANEncodeFunction(UINT32 ID,UINT8* msgData)
|
|
|
+{
|
|
|
+ memset(msgData, 0xFF, 8);
|
|
|
+ switch (ID)
|
|
|
+ {
|
|
|
+ case 0x7B0:
|
|
|
+ *(UINT8*)(msgData +0) = (AppNVMData.battSN[0])&0xFF;
|
|
|
+ *(UINT8*)(msgData +1) = (AppNVMData.battSN[1])&0xFF;
|
|
|
+ *(UINT8*)(msgData +2) = (AppNVMData.battSN[2])&0xFF;
|
|
|
+ *(UINT8*)(msgData +3) = (AppNVMData.battSN[3])&0xFF;
|
|
|
+ *(UINT8*)(msgData +4) = (AppNVMData.battSN[4])&0xFF;
|
|
|
+ *(UINT8*)(msgData +5) = (AppNVMData.battSN[5])&0xFF;
|
|
|
+ *(UINT8*)(msgData +6) = (AppNVMData.battSN[6])&0xFF;
|
|
|
+ *(UINT8*)(msgData +7) = (AppNVMData.battSN[7])&0xFF;
|
|
|
+ break;
|
|
|
+ case 0x7B1:
|
|
|
+ *(UINT8*)(msgData +0) = (AppNVMData.battSN[8])&0xFF;
|
|
|
+ *(UINT8*)(msgData +1) = (AppNVMData.battSN[9])&0xFF;
|
|
|
+ *(UINT8*)(msgData +2) = (AppNVMData.battSN[10])&0xFF;
|
|
|
+ *(UINT8*)(msgData +3) = (AppNVMData.battSN[11])&0xFF;
|
|
|
+ *(UINT8*)(msgData +4) = (AppNVMData.battSN[12])&0xFF;
|
|
|
+ *(UINT8*)(msgData +5) = (AppNVMData.battSN[13])&0xFF;
|
|
|
+ *(UINT8*)(msgData +6) = (AppNVMData.battSN[14])&0xFF;
|
|
|
+ *(UINT8*)(msgData +7) = (AppNVMData.battSN[15])&0xFF;
|
|
|
+ break;
|
|
|
+ case 0x7B2:
|
|
|
+ *(UINT8*)(msgData +0) = (AppNVMData.battSN[16])&0xFF;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
void TcpDataAssemble(UINT8 Tcptype,UINT8 *SendBuffer,UTC8TimeType UTC8TimeTcp)
|