123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- /********************************************************************************
- * File Name: ProductPara.c
- * Function Describe:
- * Explain:
- * Writer: ShiLiangWen
- * Date: 2015-7-6
- *******************************************************************************/
- #define THIS_FILE_ID 6
- //-----------------------------------------------------------------------------
- #include "includes.h"
- const unsigned char POC_SERVER_IP[4]={183,131,13,10};
- const unsigned char GPS_SERVER_IP[4]={183,131,13,6};
- const unsigned char DEFAULT_LOAD_IP[4]={122,224,240,106};
- const unsigned char DEFAULT_CONFIG_IP[4]={122,224,240,106};
- SUT_PRODUCT_PARA sutProductPara;
- SUT_NEW_SEGMENT_PARA sutNewSegmentPara;
- unsigned char startFlashPro=0;
- //HGS_PRODUCTDATA sutProductPara;
- //读取指定地址的半字(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<NumToRead;i++)
- {
- pBuffer[i]=STMFLASH_ReadHalfWord(ReadAddr);//读取2个字节.
- ReadAddr+=2;//偏移2个字节.
- }
- }
- /**********************************************************************************************************
- *写页数据,擦除整页1024字节,并写入Byte数据,数据可少于1024Btye,但必须是偶数。
- ************************************************************************************************************/
- void WritePageData(unsigned long WriteAddr,unsigned char *pData,unsigned short DataLen)
- {
- unsigned short i;
- unsigned short temp;
- FLASH_Status status;
-
- RunMake(THIS_FILE_ID);
-
- if(WriteAddr<STM32_FLASH_BASE || (WriteAddr>=(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);
- 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);
- }
- /**********************************************************************************************************
- ************************************************************************************************************/
- void ReadFlashData(unsigned long ReadAddr,unsigned char *pData,unsigned short DataLen)
- {
- #if 0
- int i,j;
- unsigned short temp;
- j=0;
- for(i=0;i<DataLen;i+=2){
- temp=STMFLASH_ReadHalfWord(ReadAddr+i);
- pData[j++]=(unsigned char)(temp&0xff);
- pData[j++]=(temp>>8)&0xff;
- }
- #else
- unsigned short temp;
- unsigned short i,j;
- j=0;
- for(i=0;i<DataLen;i+=2)
- {
- temp=*(vu16*)(ReadAddr+i);
- pData[j++]=(unsigned char)(temp&0xff);
- if(j<DataLen)
- pData[j++]=(temp>>8)&0xff;
- }
-
- #endif
- }
- /**********************************************************************************************************
- SaveProductParaToFlash
- ************************************************************************************************************/
- void SaveProductParaToFlash(void)
- {
- PWR_EN_HIGH;
- WritePageData(APP_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA));
- PWR_EN_LOW;
- }
- void SaveNewSegmentToFlash()
- {
- PWR_EN_HIGH;
- WritePageData(NEW_CONFIG_ADDR,(unsigned char *)&sutNewSegmentPara,sizeof(SUT_NEW_SEGMENT_PARA));
- PWR_EN_LOW;
- }
- /********************************************************************
- *SaveParaToFlash
- 将sutNetPara重要参数保存到FLASH
- *********************************************************************/
- void ReadProductParaFromFlash(void)
- {
- unsigned char Rand;
- Rand=GetRandBySTM32ID();
- ReadFlashData(APP_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA));
- ReadFlashData(NEW_CONFIG_ADDR,(unsigned char *)&sutNewSegmentPara,sizeof(SUT_NEW_SEGMENT_PARA));
- //soc ID替代IMEI
-
- if(MCU_FLAG!=sutProductPara.McuFlag || Rand!=sutProductPara.Rand \
- ){
- SlwTrace(INF,"Reset Config Param!",1);
- memset((unsigned char *)&sutProductPara,0,sizeof(SUT_PRODUCT_PARA));
- sutProductPara.McuFlag=MCU_FLAG; //MCU标识
- sutProductPara.ModemType=MODEM_TYPE_M9507;
- sutProductPara.GpsType=GPS_TYPE;
- sutProductPara.Rand=GetRandBySTM32ID(); //伪随机数,此数值和STM32硬件ID关联,每个不同的IC数值将不同
- strcpy(sutProductPara.ProductName,PRODUCT_NAME);
- sutProductPara.ProductVersion=PRODUCT_VERSION;
- sutProductPara.PSN=150000000;//未写号情况下PSN为150000000
-
-
- strcpy(sutProductPara.APNApn, APN_APN);
- strcpy(sutProductPara.MEID,"00000000000000");
- strcpy(sutProductPara.APNName,APN_NAME);
- strcpy(sutProductPara.APNPass,APN_PASSWORD);
- WritePageData(APP_CONFIG_ADDR,(unsigned char *)&sutProductPara,sizeof(SUT_PRODUCT_PARA));
- ////////////////////////////////////////////
- memset((unsigned char *)&sutNewSegmentPara,0,sizeof(SUT_NEW_SEGMENT_PARA));
- sutNewSegmentPara.flashCheckWord = FLASH_FIXED_WORD;
- memcpy(sutNewSegmentPara.ManagerIP,DEFAULT_LOAD_IP,4);
- sutNewSegmentPara.ManagerPort = DEFAULT_LOAD_PORT;
- ///////////////////////////////////////////
- memcpy(sutNewSegmentPara.ConfigSerIP,DEFAULT_CONFIG_IP,4);
- sutNewSegmentPara.ConfigSerPort = DEFAULT_CONFIG_PORT;
- //////////////////////////////////////
- memcpy(sutNewSegmentPara.GIP,GPS_SERVER_IP,sizeof(sutNewSegmentPara.GIP));
- sutNewSegmentPara.GpsPort=GPS_SERVER_PORT;
- memcpy(sutNewSegmentPara.PIP,POC_SERVER_IP,sizeof(sutNewSegmentPara.PIP));
- sutNewSegmentPara.PocPort=POC_SERVER_PORT;
- SaveNewSegmentToFlash();
- }
- else if(PRODUCT_VERSION!=sutProductPara.ProductVersion){
- strcpy(sutProductPara.ProductName,PRODUCT_NAME);// 每次都会去匹配产品名
- sutProductPara.ProductVersion=PRODUCT_VERSION;
- sutProductPara.g_net=0;
- SaveProductParaToFlash();
- if((sutNewSegmentPara.ManagerIP[0] == 0xFF &&
- sutNewSegmentPara.ManagerIP[1] == 0xFF &&
- sutNewSegmentPara.ManagerIP[2] == 0xFF &&
- sutNewSegmentPara.ManagerIP[3] == 0xFF) ||
- sutNewSegmentPara.ManagerPort == 0xFFFF)
- {
- memcpy(sutNewSegmentPara.ManagerIP,DEFAULT_LOAD_IP,4);
- sutNewSegmentPara.ManagerPort = DEFAULT_LOAD_PORT;
- }
-
- if((sutNewSegmentPara.ConfigSerIP[0] == 0xFF &&
- sutNewSegmentPara.ConfigSerIP[1] == 0xFF &&
- sutNewSegmentPara.ConfigSerIP[2] == 0xFF &&
- sutNewSegmentPara.ConfigSerIP[3] == 0xFF) ||
- sutNewSegmentPara.ConfigSerPort == 0xFFFF)
- {
- memcpy(sutNewSegmentPara.ConfigSerIP,DEFAULT_CONFIG_IP,4);
- sutNewSegmentPara.ConfigSerPort = DEFAULT_CONFIG_PORT;
- }
-
- sutNewSegmentPara.flashCheckWord = FLASH_FIXED_WORD;
- SaveNewSegmentToFlash();
- }
- startFlashPro=1;
- ReadFlashData(NEW_CONFIG_ADDR,(unsigned char *)&sutNewSegmentPara,sizeof(SUT_NEW_SEGMENT_PARA));
- GetUniStringByID(sutNewSegmentPara.HARDID);
- startFlashPro=0;
- if(FLASH_FIXED_WORD != sutNewSegmentPara.flashCheckWord)
- {
- while(1)
- {
- printf("FlashSizeCheck failed:%x\r\n",sutNewSegmentPara.flashCheckWord);
- IWDG_ReloadCounter();
- os_dly_wait(300);
- }
- }
- #if 0
- //166000014
- sutProductPara.AutH[0] = 0xd3;
- sutProductPara.AutH[1] = 0xe9;
- sutProductPara.AutH[2] = 0x67;
- sutProductPara.AutH[3] = 0x93;
- sutProductPara.AutH[4] = 0x4e;
- sutProductPara.AutH[5] = 0x90;
- sutProductPara.AutH[6] = 0xd6;
- #elif 0
- sutProductPara.AutH[0] = 0x5d;
- sutProductPara.AutH[1] = 0x8c;
- sutProductPara.AutH[2] = 0xef;
- sutProductPara.AutH[3] = 0xb3;
- sutProductPara.AutH[4] = 0xf2;
- sutProductPara.AutH[5] = 0x07;
- sutProductPara.AutH[6] = 0x5f;
- #endif
- }
- /************************************file begin*******************************/
|