Parcourir la source

金茂科易:合并更改,优化GPS,解析了卫星数目和海拔

CHENJIE-PC\QiXiang_CHENJIE il y a 3 ans
Parent
commit
8679d9665e
10 fichiers modifiés avec 782 ajouts et 120 suppressions
  1. 3 3
      inc/AppConfig.h
  2. 6 0
      inc/AppFunc.h
  3. 9 0
      inc/AppSignal.h
  4. 556 4
      src/AppFunc.c
  5. 7 0
      src/AppSignal.c
  6. 46 4
      src/AppTaskCan.c
  7. 67 32
      src/AppTaskGps.c
  8. 25 22
      src/AppTaskMain.c
  9. 37 40
      src/AppTaskTcp.c
  10. 26 15
      src/hal_module_adapter.c

+ 3 - 3
inc/AppConfig.h

@@ -8,12 +8,12 @@
  ****************************************************************************/
 #ifndef  APPCONFIG_H
 #define  APPCONFIG_H
-#define BMS_MANUFACTURE             (3)                 //BMS制造商表示1-超力源,2-美顺
+#define BMS_MANUFACTURE             (3)                 //BMS制造商表示1-超力源,2-美顺,3-金茂卡车项目
 #define BMS_INFO                    (1)                 //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
 #define DATA_MODULE_TYPE            (1)                 //1表示NB模块,2表示4G cat1
 #define EOLSTATE                    (0)                 //1表示下线检测跳过,使用默认值,0表示使用下线检测
-#define DEFAULT_SN                  "RLTEST00000000001" //默认上传的SN编码
-#define	APPSWVERSION		        0x03000001          //数据模块软件版本号
+#define DEFAULT_SN                  "JMTEST00000000001" //默认上传的SN编码
+#define	APPSWVERSION		        0x03000000          //数据模块软件版本号
 
 #define TCP_ADD                     "iotp.fast-fun.cn"  //数据上传的地址
 #define TCP_PORT					8712                //数据上传的端口

+ 6 - 0
inc/AppFunc.h

@@ -45,6 +45,12 @@ void canRxDiagnose(void);
 UINT8 canCOMInTableIndexFind(UINT32 canID);
 void canRxMsgSetInvalidValue(UINT32 ID);
 BOOL snCodeCompare(UINT8* savedSN, UINT8* receivedSN);
+void UDS_Service(CAN_Msg_Type* CanRxMsg);
+UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode);
+UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode);
+BOOL UDSAskforDownLoadData();
+BOOL UDSClearFotaDownloadRegion();
+void CANEncodeFunction(UINT32 ID,UINT8* msgData);
 BOOL VINCodeCompare(UINT8* saveVIN, UINT8* receivedVIN);
 void canTxTest(void);
 

+ 9 - 0
inc/AppSignal.h

@@ -52,6 +52,15 @@ extern UINT8 canRxShortError[133];
 extern UINT8 canRxLongError[133];
 extern UINT8 canRxErrorCounter[133];
 extern UINT8 canRxFlag[133];
+extern UINT8	UDSService[2] ;           //uds 服务
+extern UINT8	UDSSubService[2] ;       // uds 子服务
+extern UINT8	UDSSubServiceActionCode[2] ;  // uds 子服务状态
+extern UINT8   GpsData[16] ;                  //GPS 数据缓存区
+extern UINT16  updateDifferDataPackageCounter;  //差分包升级计数器
+extern BOOL downloadReady;   
+extern UINT8 	UDSSwitch;              //下线检测标志位
+
+
 
 //declear the UINT8 vars
 extern  UINT8   csq;

+ 556 - 4
src/AppFunc.c

@@ -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)

+ 7 - 0
src/AppSignal.c

@@ -192,6 +192,13 @@ UINT8 canRxShortError[133] = {0};
 UINT8 canRxLongError[133] = {0};
 UINT8 canRxErrorCounter[133] = {0};
 UINT8 canRxFlag[133] = {0};
+UINT8	UDSService[2] = {0};           //uds 服务
+UINT8	UDSSubService[2]  = {0};       // uds 子服务
+UINT8	UDSSubServiceActionCode[2]  = {0};  // uds 子服务状态
+UINT8   GpsData[16] = {0};                  //GPS 数据缓存区
+UINT16  updateDifferDataPackageCounter = 0;  //差分包升级计数器
+BOOL downloadReady = FALSE; 
+UINT8 	UDSSwitch = 0;              //下线检测标志位
 
 
 

+ 46 - 4
src/AppTaskCan.c

@@ -62,7 +62,7 @@ static void CanTask()
 				ConvertCounter = 0;
 				while(TRUE)
 				{
-					osDelay(1);
+					osDelay(10);
 					ConvertCounter++;
 					if(gProcess_app!=WORK)
 					{
@@ -89,19 +89,61 @@ static void CanTask()
 					{
 						if(CanRxMsg[i].Id != 0x00 && CanRxMsg[i].DLC == 0x08)
 						{
-							DecodeFunction(CanRxMsg[i].Id,CanRxMsg[i].Data);
-							canRxFlag[canCOMInTableIndexFind(CanRxMsg[i].Id)] = 1;
+							if(CanRxMsg[i].Id == 0x7A0)
+							{	
+								udsFlag = 1;
+								UDSService[i] =  CanRxMsg[i].Data[0];
+								UDSSubService[i] = CanRxMsg[i].Data[1];
+								UDSSubServiceActionCode[i] = CanRxMsg[i].Data[2];
+								if(UDSService[i] == 0x10)
+								{
+									if(UDSSubService[i] == 0x02)
+									{
+										UDSSwitch = 1;
+									}								
+								}
+							}
+							else if(CanRxMsg[i].Id == 0x7A1)
+							{
+								UINT8 nvmTemp[100];
+								memset(nvmTemp, 0, 100);
+								for(int ii=0;ii<200;ii++)
+								{
+									BSP_QSPI_Read_Safe(nvmTemp, FLASH_FOTA_REGION_START+ii*100, 100);
+									for(int jj=0;jj<100;jj++)
+									{
+										printf("%02X ",nvmTemp[jj]);
+									}	
+									printf("\n");
+								}
+							}
+							else
+							{
+								DecodeFunction(CanRxMsg[i].Id,CanRxMsg[i].Data);
+								canRxFlag[canCOMInTableIndexFind(CanRxMsg[i].Id)] = 1;
+							}
+							
 						}
 						else
 						{
 							continue;
 						}
 					}
+
+					for(i=0; i<2; i++)
+					{								
+						
+					}	
+					if(udsFlag==1)
+					{	
+						UDS_Service(CanRxMsg);
+						udsFlag = 0;
+					}
 				}
 				else
 				{
 					delayconuter++;
-					osDelay(1);			
+					osDelay(2);			
 				}					
 				if(delayconuter>=1000)
 				{

+ 67 - 32
src/AppTaskGps.c

@@ -27,19 +27,20 @@ static void GpsTask(void* arg)
 
 	if(GpsRecvHandle == NULL)
 	{
-		GpsRecvHandle = osMessageQueueNew(2,sizeof(GPSInfo*), NULL);
+		GpsRecvHandle = osMessageQueueNew(1,sizeof(GPSInfo*), NULL);
 	}
 	gpsReqMsg msg;
 	GPSInfo *GpsInfoData; 
-	char *p=NULL;
+	CHAR *p=NULL;
+	CHAR *p2=NULL;
 	const char *delim = "\n";
-	char *databuffer[14];
+	char *databuffer[20];
 	UINT32 speedtemp;
     UINT32 latitude;
 	UINT32 longitude;
     UINT16 direction;
-	UINT8  	GpsNoDataCounter = 0;
-	UINT8	GpsResetCount = 0;
+	UINT16  GpsNoDataCounter = 0;
+	UINT8  index=0;	
 	PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_INIT);
     while(1)
     {
@@ -47,9 +48,9 @@ static void GpsTask(void* arg)
 		{
 			case PROCESS_GPS_STATE_INIT:
 			{
-				posGGAReset();
 				osDelay(100);
 				posGGAServiceStart(norGpsHandle);
+				posGGAReset();
 				PROC_GPS_STATE_SWITCH(PROCESS_GPS_STATE_WORK);
 				break;
 			}
@@ -71,13 +72,12 @@ static void GpsTask(void* arg)
 			}
 			case PROCESS_GPS_STATE_WORK:
 			{
-				if(GpsNoDataCounter>=10 && GpsResetCount<=3)
+				if(GpsNoDataCounter>=60*10)
 				{
-					posGGAReset();
-					GpsResetCount++;
 					GpsNoDataCounter = 0;
 					osDelay(100);
 					posGGAServiceStart(norGpsHandle);
+					posGGAReset();
 				}
 				osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, 1000);
 				if(ret==0)
@@ -88,32 +88,27 @@ static void GpsTask(void* arg)
 						GpsInfoData = malloc(sizeof(GPSInfo));
 						memset(GpsInfoData,0x00,sizeof(GPSInfo));
 						p = strtok(msg.dataPtr,delim);//将信息进行分割
+						p2 = strtok(NULL,delim);
 						#ifdef USING_PRINTF1
 							printf("\nP msgptr data:%s\r\n",p);
+							printf("\nP2 msgptr data:%s\r\n",p2);
 						#endif
 						p = strtok(p,",");//只取第1行的信息RMC
 						//p = strtok(temp,",");//模拟测试
 						if (strcmp(p,"$GNRMC")==0)
-						{
-							UINT8 i=0;			
+						{	
+							index = 0;	
 							while (p)
 							{	
-								databuffer[i]=p;
+								databuffer[index]=p;
 								p = strtok(NULL,",");
-								i++;;
-							}
-							if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
-							{
-								GpsFlag = 0;
-								memset(GpsInfoData,0x00,sizeof(GPSInfo));
-								GpsNoDataCounter++;
+								index++;
 							}
-							else if (strcmp(databuffer[2],"A")==0)
+							if (index>5&&strcmp(databuffer[2],"A")==0)
 							{
-								GpsResetCount = 0;
+								GpsNoDataCounter = 0;
 								GpsInfoData->locateMark = 0x01;//有效,东经,北纬写定
-								GpsInfoData->satelliteNum = 03;//卫星数目写入1
-								GpsFlag = GpsInfoData->satelliteNum;
+								GpsFlag = 3;
 								strdel(databuffer[3],'.');
 								strdel(databuffer[5],'.');
 								strdel(databuffer[7],'.');
@@ -130,9 +125,6 @@ static void GpsTask(void* arg)
 								GpsInfoData->longitude[1] = longitude>>16;
 								GpsInfoData->longitude[2] = longitude>>8;
 								GpsInfoData->longitude[3] = longitude;
-
-								GpsInfoData->altitude[0]  = 0x03;//海拔目前无输出
-								GpsInfoData->altitude[1]  = 0xE8;
 								if(speedtemp>=50)//大于5km/h才输出方位
 								{
 									direction = atol(databuffer[8]);
@@ -152,15 +144,58 @@ static void GpsTask(void* arg)
 									{
 										AppDataInfo.AccMileage = 0;
 									}
-
 								}
-								GpsInfoData->AccMileage[0] = AppDataInfo.AccMileage>>24;
-								GpsInfoData->AccMileage[1] = AppDataInfo.AccMileage>>16;
-								GpsInfoData->AccMileage[2] = AppDataInfo.AccMileage>>8;
-								GpsInfoData->AccMileage[3] = AppDataInfo.AccMileage;
+							}
+							else if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
+							{
+
+							}
+							GpsInfoData->AccMileage[0] = AppDataInfo.AccMileage>>24;
+							GpsInfoData->AccMileage[1] = AppDataInfo.AccMileage>>16;
+							GpsInfoData->AccMileage[2] = AppDataInfo.AccMileage>>8;
+							GpsInfoData->AccMileage[3] = AppDataInfo.AccMileage;
+						}
+						p2 = strtok(p2,",");//只取第2行的信息GGA
+						memset(databuffer,0x30,20);
+						if(strcmp(p2,"$GNGGA")==0)
+						{
+							index = 0;			
+							while (p2)
+							{	
+								databuffer[index]=p2;
+								p2 = strtok(NULL,",");
+								index++;
+							}
+							if(index>9&&(strcmp(databuffer[6],"1")==0||strcmp(databuffer[6],"2")==0))
+							{
+								GpsInfoData->satelliteNum = atol(databuffer[7]);//卫星数目写入
+								GpsFlag = GpsInfoData->satelliteNum;
+								strdel(databuffer[9],'.');
+								UINT16 alt = 0;
+								alt = atol(databuffer[9])/10 + 1000;
+								GpsInfoData->altitude[0]  = alt>>8;//海拔
+								GpsInfoData->altitude[1]  = alt;
+								strdel(databuffer[2],'.');
+								strdel(databuffer[4],'.');
+								latitude =location_handle(databuffer[2]);
+								GpsInfoData->latitude[0] = latitude>> 24;
+								GpsInfoData->latitude[1] = latitude>> 16;
+								GpsInfoData->latitude[2] = latitude>> 8;
+								GpsInfoData->latitude[3] = latitude;
+								longitude = location_handle(databuffer[4]);
+								GpsInfoData->longitude[0] = longitude>>24;
+								GpsInfoData->longitude[1] = longitude>>16;
+								GpsInfoData->longitude[2] = longitude>>8;
+								GpsInfoData->longitude[3] = longitude;
+							}
+							else
+							{
+								GpsFlag = 0;
+								memset(GpsInfoData,0x00,sizeof(GPSInfo));
+								GpsNoDataCounter++;
 							}
 						}
-						osMessageQueuePut(GpsRecvHandle,&GpsInfoData,0,1000);
+						osMessageQueuePut(GpsRecvHandle,&GpsInfoData,0,10);
 					}
 					if(msg.dataPtr)
 						free(msg.dataPtr);

+ 25 - 22
src/AppTaskMain.c

@@ -88,8 +88,7 @@ static void MainTask(void* arg)
                 {
                     //BattWorkDelayFunc(battWorkState);
                     #ifdef USING_PRINTF1
-                        printf("[%d]-%x",__LINE__,battWorkState);
-                        printf("[%d]%x - %x - %x - %x - %x\n",__LINE__,WorkTimerEnd,BMS_Fota_update_flag,TCPWorkState,BattWorkStateDelay,PadInterrupt);
+                        printf("[%d]%x - %x - %x\n",__LINE__,WorkTimerEnd,TCPWorkState,PadInterrupt);
                     #endif
                     //if(strcmp(AppNVMData.battSN,SN)!=0&&SN[0]!=0xFF&&SN[0]!=0x00&&SN[15]!=0xFF&&SN[15]!=0x00)
                     if(canSNMsgRxCmpltFlag == true && canSNMsgLostFlag == false)
@@ -129,13 +128,17 @@ static void MainTask(void* arg)
                 }
                 if((WorkTimerEnd==TRUE)&&(TCPWorkState==0x00)&&(PadInterrupt==0x00))//从工作转换为监听的条件
                 {
-                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
+                    #ifdef USING_PRINTF
+                        printf("[%d]sleep\n",__LINE__);
+                    #endif
+                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_LISTEN);
                     xTimerStop(work_timer,0);
                     xTimerStart(sleep_timer, 0);
                     WorkTimerEnd = FALSE;
                     NVIC_EnableIRQ(PadWakeup1_IRQn);
+                    break;
                 }
-                if(TcpErrorcount>=10)
+                if(TcpErrorcount>=10 && UDSSwitch ==0)
                 {
                     AppDataInfo.appDataModify = true;
                     AppDataInfo.SysReStartCount = AppDataInfo.SysReStartCount +1;
@@ -155,6 +158,20 @@ static void MainTask(void* arg)
                     osDelay(1000);
                     EC_SystemReset();
                 }
+                if(NB_Fota_update_flag)
+                {
+                    if(AppDataInfo.appDataModify)
+                    {
+                        SaveAppData();
+                    }
+                    if(AppNVMData.appDataModify)
+                    {
+                        SaveAppConfig();
+                    }
+                    appSetCFUN(0);
+                    osDelay(1000);
+                    EC_SystemReset();
+                }
                 break;
             }
             case PROCESS_STATE_LISTEN:
@@ -174,11 +191,11 @@ static void MainTask(void* arg)
                 {
                     SaveAppConfig();
                 }
-                #ifdef USING_PRINTF1
-                    printf("[%d]%x - %x - %x - %x\n",__LINE__,SleepTimerEnd,BMS_Fota_update_flag,TCPWorkState,PadInterrupt);
-                #endif
-                if((SleepTimerEnd)||(TCPWorkState==1)||(PadInterrupt_clrCounter>=3))//从监听转换为工作的条件
+                if((SleepTimerEnd)||(TCPWorkState==1)||(PadInterrupt_clrCounter>=1))//从监听转换为工作的条件
                 {
+                    #ifdef USING_PRINTF
+                        printf("[%d]wake up\n",__LINE__);
+                    #endif
                     PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
                     xTimerStop(sleep_timer,0);
                     SleepTimerEnd = FALSE;
@@ -187,20 +204,6 @@ static void MainTask(void* arg)
                     NVIC_DisableIRQ(PadWakeup1_IRQn);
                     break;
                 }
-                if(NB_Fota_update_flag)
-                {
-                    if(AppDataInfo.appDataModify)
-                    {
-                        SaveAppData();
-                    }
-                    if(AppNVMData.appDataModify)
-                    {
-                        SaveAppConfig();
-                    }
-                    appSetCFUN(0);
-                    osDelay(1000);
-                    EC_SystemReset();
-                }
                 break;
             }
             default:

+ 37 - 40
src/AppTaskTcp.c

@@ -361,6 +361,7 @@ static void TcpDataInfoAssembleSend()
     */
     if(send_counter%GpsSendFreq==0 && send_counter!=0)
     {
+        osMessageQueueReset(GpsRecvHandle);
         GPSInfo *GpsRecvData=NULL;
         GPSMsgtoTcpType GpsToTcpInfo;
         UINT16 tac = 0;
@@ -396,46 +397,42 @@ static void TcpDataInfoAssembleSend()
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; 						    //hour
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
-        osStatus_t ret = osMessageQueueGet(GpsRecvHandle,&GpsRecvData,0,0);
+        osStatus_t ret = osMessageQueueGet(GpsRecvHandle,&GpsRecvData,0,2000);
         if(ret == 0)
         {
             memcpy((UINT8 *)&GpsToTcpInfo.gpsInfo.locateMark, GpsRecvData,sizeof(GPSInfo));
-        }
-        else
-        {
-            memcpy((UINT8 *)&GpsToTcpInfo.gpsInfo.locateMark, 0x00,sizeof(GPSInfo));
-        }
-        GpsToTcpInfo.gpsInfo.Tac[0] = tac>>8;
-        GpsToTcpInfo.gpsInfo.Tac[1] = tac&0xFF;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>24;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>16;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>8;
-        GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
-        GpsToTcpInfo.CRC = bcc_chk((UINT8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType)-1 );
-        if(GpsRecvData!=NULL)
-            free(GpsRecvData);
-        GpsRecvData=NULL;
-        //if(GpsToTcpInfo.gpsInfo.locateMark==0x01)
-        if(1)
-        {
-            len = tcpipConnectionSend(socContext.id, (UINT8 *)&GpsToTcpInfo, sizeof(GpsToTcpInfo), 0, 0, 0);
-            #ifdef USING_PRINTF1
-                for (int i = 0; i < sizeof(GpsToTcpInfo); i++)
+            GpsToTcpInfo.gpsInfo.Tac[0] = tac>>8;
+            GpsToTcpInfo.gpsInfo.Tac[1] = tac&0xFF;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>24;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>16;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId>>8;
+            GpsToTcpInfo.gpsInfo.CellID[0] = cellId;
+            GpsToTcpInfo.CRC = bcc_chk((UINT8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType)-1 );
+            //if(GpsToTcpInfo.gpsInfo.locateMark==0x01)
+            if(1)
+            {
+                len = tcpipConnectionSend(socContext.id, (UINT8 *)&GpsToTcpInfo, sizeof(GpsToTcpInfo), 0, 0, 0);
+                #ifdef USING_PRINTF1
+                    for (int i = 0; i < sizeof(GpsToTcpInfo); i++)
+                    {
+                        printf("%02x ",*((UINT8 *)&GpsToTcpInfo+i));
+                    }
+                    printf("-[%d]-Gpslen:%d\n",__LINE__,len);
+                #endif
+                if(len>0)
                 {
-                    printf("%02x ",*((UINT8 *)&GpsToTcpInfo+i));
+                    TcpSendLen = 0x04 | TcpSendLen;
+                }
+                else
+                {
+                    TcpSendLen = 0xFB & TcpSendLen;
+                    sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
                 }
-                printf("-[%d]-Gpslen:%d\n",__LINE__,len);
-            #endif
-            if(len>0)
-            {
-                TcpSendLen = 0x04 | TcpSendLen;
-            }
-            else
-            {
-                TcpSendLen = 0xFB & TcpSendLen;
-                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
             }
         }
+        if(GpsRecvData!=NULL)
+            free(GpsRecvData);
+        GpsRecvData=NULL;
     }
     if(send_counter==1)//版本信息上报 上报频率为每次重启后上报或者每次更新后上报或者每天上报一次均可
     {
@@ -519,7 +516,7 @@ static void TcpDataInfoAssembleSend()
             }
         }
     }
-    if((send_counter)%10==0)//90发送
+    if((send_counter)%30==0)//90发送
     {
         appGetSystemTimeUtcSync(&TimeStracture);
         year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
@@ -534,7 +531,7 @@ static void TcpDataInfoAssembleSend()
         SendBuffer = malloc(BufferLen);
         TcpDataAssemble(Tcptype,SendBuffer,UTC8TimeTcp);
         len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen, 0, 0, 0);
-        #ifdef USING_PRINTF
+        #ifdef USING_PRINTF1
             printf("[%d]DebugMsg-[%d]:\n",__LINE__,len);
             for (UINT16 i = 0; i < BufferLen; i++)
             {
@@ -548,7 +545,7 @@ static void TcpDataInfoAssembleSend()
         }
         SendBuffer=NULL;
     }
-    if((send_counter+1)%10==0)//91发送
+    if((send_counter+1)%30==0)//91发送
     {
         appGetSystemTimeUtcSync(&TimeStracture);
         year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
@@ -559,11 +556,11 @@ static void TcpDataInfoAssembleSend()
         sec=(TimeStracture.UTCtimer2&0xff00)>>8;
         UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
         UINT8 Tcptype =0x91;
-        UINT16 BufferLen = 0x54 + numOfCells*2 + numOfCellTemp;
+        UINT16 BufferLen = 0x54 + CELL_NUM*2 + CELL_TEMP_NUM;
         SendBuffer = malloc(BufferLen);
         TcpDataAssemble(Tcptype,SendBuffer,UTC8TimeTcp);
         len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen, 0, 0, 0);
-        #ifdef USING_PRINTF
+        #ifdef USING_PRINTF1
             printf("[%d]DebugMsg-[%d]:\n",__LINE__,len);
             for (UINT16 i = 0; i < BufferLen; i++)
             {
@@ -577,7 +574,7 @@ static void TcpDataInfoAssembleSend()
         }
         SendBuffer=NULL;
     }
-    if((send_counter+2)%60==0)//92发送
+    if((send_counter+2)%120==0)//92发送
     {
         appGetSystemTimeUtcSync(&TimeStracture);
         year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
@@ -592,7 +589,7 @@ static void TcpDataInfoAssembleSend()
         SendBuffer = malloc(BufferLen);
         TcpDataAssemble(Tcptype,SendBuffer,UTC8TimeTcp);
         len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen, 0, 0, 0);
-        #ifdef USING_PRINTF
+        #ifdef USING_PRINTF1
             printf("[%d]DebugMsg-[%d]:\n",__LINE__,len);
             for (UINT16 i = 0; i < BufferLen; i++)
             {

+ 26 - 15
src/hal_module_adapter.c

@@ -783,7 +783,7 @@ INT32  HAL_Can_Reset(void)
 void HAL_Can_Init(Can_InitType param)
 {
 	UINT8 temp=0,temp1=0;
-      INT32 res = -1;
+    INT32 res = -1;
 	  
 	gpio_pin_config_t config;
 	config.pinDirection = GPIO_DirectionOutput;
@@ -968,16 +968,30 @@ INT8  HAL_Can_Transmit(CAN_Msg_Type Can_TxMsg)
 	CAN_ReadReg(TXB0CTRL, 1, &TXB0CTRLvalue);
 	CAN_ReadReg(TXB1CTRL, 1, &TXB1CTRLvalue);
 	CAN_ReadReg(TXB2CTRL, 1, &TXB2CTRLvalue);
-	TxBnEId0 = (Can_TxMsg.Id)&0xFF;
-	TxBnEId8 = ((Can_TxMsg.Id)>>8)&0xFF;
-	TxBnSIdL = (((((Can_TxMsg.Id)>>18)&0x07)<<5) | (1<<3) | (((Can_TxMsg.Id)>>16)&0x03))&0xFF;
-	TxBnSIdH = ((Can_TxMsg.Id)>>21)&0xFF;
-	
-/*
-	printf("TXB0CTRL = 0x%x,\tTXB1CTRL = 0x%x,\tTXB2CTRL = 0x%x\n",TXB0CTRL,TXB1CTRL,TXB2CTRL);
-	printf("ID = 0x%x\n",Can_TxMsg.Id);
+	if((Can_TxMsg.Id & 0xFFFF0000) != 0) //extern ID
+	{
+		printf("extern ID = 0x%x\n",Can_TxMsg.Id);
+		printf("extern ID_1 = 0x%x\n",Can_TxMsg.Id & 0xFFFF0000);
+		TxBnEId0 = (Can_TxMsg.Id)&0xFF;
+		TxBnEId8 = ((Can_TxMsg.Id)>>8)&0xFF;
+		TxBnSIdL = (((((Can_TxMsg.Id)>>18)&0x07)<<5) | (1<<3) | (((Can_TxMsg.Id)>>16)&0x03))&0xFF;
+		TxBnSIdH = ((Can_TxMsg.Id)>>21)&0xFF;
+	}
+	else
+	{
+		printf("standard ID = 0x%x\n",Can_TxMsg.Id);
+		TxBnEId0 = 0x00;
+		TxBnEId8 = 0x00;
+		TxBnSIdL = ((Can_TxMsg.Id)<<5) & 0xE0;
+		TxBnSIdH = ((Can_TxMsg.Id)>>3) & 0xFF;
+		
+	}
+		
+
+//	printf("TXB0CTRL = 0x%x,\tTXB1CTRL = 0x%x,\tTXB2CTRL = 0x%x\n",TXB0CTRL,TXB1CTRL,TXB2CTRL);
+	//printf("ID = 0x%x\n",Can_TxMsg.Id);
 	printf("TxBnEId0 = 0x%x,\tTxBnEId8 = 0x%x,\tTxBnSIdL = 0x%x,\tTxBnSIdH = 0x%x\n",TxBnEId0,TxBnEId8,TxBnSIdL,TxBnSIdH);
-*/
+
 	
 	if((TXB0CTRLvalue&TXREQ)==0)
 		TXBufferCase = 0;
@@ -1091,11 +1105,8 @@ INT8  HAL_Can_Transmit(CAN_Msg_Type Can_TxMsg)
 	SPI_CS_High();
 	if((TXB0CTRLvalue&0x20)||(TXB1CTRLvalue&0x20)||(TXB2CTRLvalue&0x20)||(CANINTFValue&0x80))
 	{
-		ret = -1;
-		
-	}
-	
-	
+		ret = -1;		
+	}	
 	return ret;
 }