/******************************************************************************** * File Name: ProductPara.c * Function Describe: * Explain: * Writer: ShiLiangWen * Date: 2015-7-6 *******************************************************************************/ #define THIS_FILE_ID 6 //----------------------------------------------------------------------------- #include "includes.h" SUT_PRODUCT_PARA sutProductPara; SUT_DEVICE_CONFIG sutDeviceConfig; SUT_SERVER_IP sutServerIp; //SUT_DEVICE_INFO sutDeviceInfo; //读取指定地址的半字(16位数据) //faddr:读地址(此地址必须为2的倍数!!) //返回值:对应数据. u16 STMFLASH_ReadHalfWord(u32 faddr) { return *(vu16*)faddr; } //从指定地址开始读出指定长度的数据 //ReadAddr:起始地址 //pBuffer:数据指针 //NumToWrite:半字(16位)数 void STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead) { u16 i; for(i=0;i=(STM32_FLASH_BASE+1024*STM32_FLASH_SIZE)))return;//非法地址 if(WriteAddr&0x0000003ff)return;//非页首地址 RunMake(THIS_FILE_ID); FLASH_Unlock(); //解锁 RunMake(THIS_FILE_ID); status=FLASH_ErasePage(WriteAddr);//擦除这个扇区 if(status!=FLASH_COMPLETE){ RunMake(THIS_FILE_ID); __enable_irq() ; return; } RunMake(THIS_FILE_ID); //写入 for(i = 0; i < DataLen; i+=2) { //数据8位融合为16位 temp = (((unsigned short)pData[i+1])<<8) + ((unsigned short)pData[i]); FLASH_ProgramHalfWord((WriteAddr+i),temp); } RunMake(THIS_FILE_ID); FLASH_Lock();//上锁 RunMake(THIS_FILE_ID); __enable_irq() ; } /********************************************************************************************************** ************************************************************************************************************/ void ReadFlashData(unsigned long ReadAddr,unsigned char *pData,unsigned short DataLen) { int i,j; unsigned short temp; j=0; for(i=0;i>8)&0xff; } } /***************************** 根据PSN生成MAC *******************************/ void getNetMacByPSN(unsigned char *MAC,unsigned long PSN) { SUTDL DL; DL.Data.ulData=PSN; MAC[0]=0xab; MAC[1]=0xcd; MAC[2]=DL.Data.ucData.b4; MAC[3]=DL.Data.ucData.b3; MAC[4]=DL.Data.ucData.b2; MAC[5]=DL.Data.ucData.b1; } /******************************************************** 10进制转BCD ********************************************************/ void DecToBCD(unsigned int Dec, unsigned char *Bcd, int length) { int i; int temp; for(i=length-1; i>=0; i--) { temp = Dec%100; Bcd[i] = ((temp/10)<<4) + ((temp%10) & 0x0F); Dec /= 100; } } /******************************************************************** *ReadProductParaFromFlash *********************************************************************/ void ReadProductParaFromFlash(void) { ReadFlashData(PRODUCT_PARA_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA)); if(MCU_FLAG!=sutProductPara.McuFlag || PRODUCT_PARA_MARK!=sutProductPara.Mark) { memset((unsigned char *)&sutProductPara,0,sizeof(SUT_PRODUCT_PARA)); sutProductPara.McuFlag=MCU_FLAG; snprintf(sutProductPara.ProductName,sizeof(sutProductPara.ProductName),"%s",PRODUCT_NAME); sutProductPara.SoftwareVer=SOFTWARE_VERSION; sutProductPara.HardwareVer=HARDWARE_VERSION; sutProductPara.ModemType=MODEM_TYPE; sutProductPara.GNSSType=GNSS_TYPE; sutProductPara.SensorType=SENSOR_TYPE; snprintf(sutProductPara.AppServer,sizeof(sutProductPara.AppServer),"%s",APP_SERVER); sutProductPara.AppPort=APP_SPORT; snprintf(sutProductPara.FotaServer,sizeof(sutProductPara.FotaServer),"%s",FOTA_SERVER); sutProductPara.FotaPort=FOTA_SPORT; snprintf(sutProductPara.CardAPN,sizeof(sutProductPara.CardAPN),"%s",CARD_APN); snprintf(sutProductPara.CardUsrName,sizeof(sutProductPara.CardUsrName),"%s",CARD_USER); snprintf(sutProductPara.CardUsrPass,sizeof(sutProductPara.CardUsrPass),"%s",CARD_PASS); sutProductPara.Mark=PRODUCT_PARA_MARK; WritePageData(PRODUCT_PARA_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA)); strcpy(sutProductPara.proName, "ZRK"); strcpy(sutProductPara.devName, "M20"); } snprintf(sutProductPara.ProductName,sizeof(sutProductPara.ProductName),"%s",PRODUCT_NAME); sutProductPara.SoftwareVer=SOFTWARE_VERSION; sutProductPara.HardwareVer=HARDWARE_VERSION; } /********************************************************************************************************** SaveProductParaToFlash ************************************************************************************************************/ void SaveProductParaToFlash(void) { //tsk_lock (); __set_PRIMASK(1);//关闭总中断 WritePageData(PRODUCT_PARA_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA)); __set_PRIMASK(0);//打开总中断 //tsk_unlock (); } /******************************************************************** *ReadDeviceConfigFromFlash *********************************************************************/ void ReadDeviceConfigFromFlash(void) { if(DEVICE_CONFIG_ADDR