1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009 |
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <linux/termios.h>
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <stdlib.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/sockios.h>
- #include <linux/socket.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <math.h>//for pow
- #include <unistd.h>
- #include "define.h"
- #include "main.h"
- struct SysConfigAndInfo *ShmSysConfigAndInfo;
- struct StatusCodeData *ShmStatusCodeData;
- struct CcsData *ShmCcsData;
- struct InternalComm *ShmInternalComm;
- unsigned char buf_log_main[SIZE_OF_LOG_BUFFER];
- #if SAVE_SYS_LOG_MSG_MAIN_SWITCH == ENABLE
- int StoreLogMsg(unsigned char *DataString);
- #endif
- void System_Init();
- void CreateShareMemory_Init();
- void GPIO_Init();
- void PWM_Init();
- void Confinguration_Init();
- double DiffTimeb(struct timeb ST, struct timeb ET);
- int CreateShareMemory();
- int LoadSysConfigAndInfo(struct SysConfigData *ptr);
- int SpawnTask();
- int StoreUsrConfigData(struct SysConfigData *UsrData);
- unsigned int isKernelSupportNAT()
- {
- unsigned int result = 0;
- unsigned int version = 0;
- FILE *fp;
- char cmd[256];
- char buf[512];
-
- strcpy(cmd, "uname -v");
- fp = popen(cmd, "r");
- if(fp != NULL)
- {
- if(fgets(buf, sizeof(buf), fp) != NULL)
- {
- sscanf(buf, "#%d", &version);
-
- if(version >= 30)
- result = 1;
- }
- }
- pclose(fp);
- return result;
- }
- float ReadAdcVolt(unsigned char AdcChannel)
- {
-
-
-
-
- if(AdcChannel == 3)
- {
- int fd,count,AvgTimes;
- unsigned char SampleBuf[4];
- float TmpVolt, MinSample, AvgSample = 0;
- fd = open("/sys/bus/iio/devices/iio\:device0/in_voltage3_raw", O_RDONLY);
- if(fd > 0)
- {
-
- for(AvgTimes = 0; AvgTimes < 3; AvgTimes++)
- {
- count = 0;
- MinSample = 2306;
-
- while(count < 40)
- {
-
-
- read(fd, SampleBuf, 4);
-
- TmpVolt = atoi(SampleBuf);
-
- if((TmpVolt < 2306) && (TmpVolt > 0))
- {
- if(TmpVolt < MinSample)
- {
- MinSample = TmpVolt;
- }
- count++;
- }
- lseek(fd, 0, SEEK_SET);
- }
-
- AvgSample += MinSample;
- }
- AvgSample /= AvgTimes;
- close(fd);
-
- return ((0.954-(1.8*AvgSample/4095))/0.06);
- }
- else
- {
- return -1;
- }
- }
- else
- {
- FILE *fp;
- unsigned char str[64];
- unsigned char AdcValue[8];
- if(AdcChannel > 7)
- {
- return -1;
- }
- memset(str,0,sizeof(str));
- memset(AdcValue,0,sizeof(AdcValue));
- sprintf(str, "cat /sys/bus/iio/devices/iio\\:device0/in_voltage%d_raw", AdcChannel);
- fp=popen(str, "r");
- if(fgets(AdcValue,sizeof(AdcValue),fp) == NULL)
- {
- pclose(fp);
- return -1;
- }
- pclose(fp);
-
-
- return ((float)1.8*(float)atoi(AdcValue))/4095;
- }
- }
- int main(int argc, char *argv[])
- {
- #ifdef CONNECTOR_TEMP_DETECTION
- float CcsConnectorTemp1;
- int CcsConnectorTemp;
- #endif
- SAVE_SYS_LOG_MSG_MAIN("ccs: on");
- SAVE_SYS_LOG_MSG_MAIN("---------------------------------------------");
- SAVE_SYS_LOG_MSG_MAIN("-- MAIN --");
- SAVE_SYS_LOG_MSG_MAIN("---------------------------------------------\n");
-
-
-
-
-
- System_Init();
-
- SpawnTask();
- sleep(2);
- system("killall ntpd");
-
-
-
- while(1)
- {
-
- sleep(5);
- #ifdef CONNECTOR_TEMP_DETECTION
- CcsConnectorTemp=0;
- for(unsigned char i=0;i<=1;i++)
- {
- CcsConnectorTemp1 = ReadAdcVolt(i);
- if((CcsConnectorTemp1<=0.9)&&(CcsConnectorTemp1>=0.8))
- CcsConnectorTemp1=(CcsConnectorTemp1-0.9)*500;
- else if((CcsConnectorTemp1<=1.07)&&(CcsConnectorTemp1>0.9))
- CcsConnectorTemp1=(CcsConnectorTemp1-0.9)*705.88;
- else
- CcsConnectorTemp1=195;
- CcsConnectorTemp|=((unsigned int)(CcsConnectorTemp1+60)&0xFF)<<(i*8);
-
- }
- ShmSysConfigAndInfo->SysInfo.CcsConnectorTemp=CcsConnectorTemp;
-
- #endif
- }
- }
- int Eth0_PortSetting_Base(unsigned char addr)
- {
- SAVE_SYS_LOG_MSG_MAIN("[Eth0_PortSetting]start");
- unsigned char cmd[128];
- if ((addr >= 20) && (addr <= (255-20-1)))
- {
-
- #if 0
- SAVE_SYS_LOG_MSG_MAIN("[Eth0_PortSetting][eth0]down");
- system("/sbin/ifconfig eth0 down");
- sleep(1);
- #endif
-
- sprintf(buf_log_main,
- "[Eth0_PortSetting][eth0]IP >> 192.168.0.%d(up)",
- addr);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
- sprintf(cmd, "/sbin/ifconfig eth0 192.168.0.%d netmask 255.255.255.0 up", addr);
- system(cmd);
- memset(cmd, 0, sizeof(cmd));
- sleep(1);
-
- system("/sbin/route add default gw 192.168.0.1");
-
- sprintf(buf_log_main,
- "[Eth0_PortSetting]done");
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
- return PASS;
- }
- else
- {
- sprintf(buf_log_main,
- "[Eth0_PortSetting][Error]addr(%d) is out of range(20~234)",
- addr);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
- return FAIL;
- }
- }
- void System_Init()
- {
-
- time_t rtc_new;
- rtc_new = RTC_DEFAULT_TIME;
- stime(&rtc_new);
- system("date");
- sprintf(buf_log_main, "[RTC]%d (DEC)\n", rtc_new);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
-
-
- sprintf(buf_log_main, "\nLinux Image SHA1: %s\n", LINUX_IMAGE_VERSION);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
-
- sprintf(buf_log_main, "HW: %s\n", HARDWARE_VERSION);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
-
- sprintf(buf_log_main, "FW: %s\n", FIRMWARE_VERSION);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
- #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == ENABLE)
- {
-
- printf("\nLinux Image SHA1: %s\n", LINUX_IMAGE_VERSION);
-
- printf("HW: %s\n", HARDWARE_VERSION);
-
- printf("FW: %s\n", FIRMWARE_VERSION);
- }
- #endif
-
- Eth0_PortSetting_Base(ETH0_PORT_BASE);
-
- if(isKernelSupportNAT() == 1)
- system("/sbin/insmod /lib/qcaspi_nat.ko");
- else
- system("/sbin/insmod /lib/qcaspi.ko");
-
- sleep(2);
- system("/sbin/ifconfig eth1 192.168.0.11 netmask 255.255.255.0 up");
- sleep(1);
- printf("Starting SSH : \n");
- system("/sbin/dropbear &");
- printf("Starting FTPD : \n");
- system("/usr/bin/tcpsvd -vE 0.0.0.0 21 ftpd -w -t 30 / &");
-
-
-
- GPIO_Init();
-
- PWM_Init();
-
-
- CreateShareMemory_Init();
-
-
- SAVE_SYS_LOG_MSG_MAIN("--------------------------");
- SAVE_SYS_LOG_MSG_MAIN("System_Init(): DONE");
- }
- void CreateShareMemory_Init()
- {
- if(CreateShareMemory() == 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory_Init(): NG");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- else
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory_Init(): DONE");
- }
- }
- int CreateShareMemory()
- {
- int MeterSMId;
-
- if((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmget ShmSysConfigAndInfo NG");
- return 0;
- }
- else if((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmat ShmSysConfigAndInfo NG");
- return 0;
- }
- memset(ShmSysConfigAndInfo, 0, sizeof(struct SysConfigAndInfo));
-
- if((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmget ShmStatusCodeData NG");
- return 0;
- }
- else if((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmat ShmStatusCodeData NG");
- return 0;
- }
- memset(ShmStatusCodeData, 0, sizeof(struct StatusCodeData));
-
- if((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmget ShmCcsData NG");
- return 0;
- }
- else if((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmat ShmCcsData NG");
- return 0;
- }
- memset(ShmCcsData, 0, sizeof(struct CcsData));
-
- if((MeterSMId = shmget(ShmInternalCommKey, sizeof(struct InternalComm), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmget ShmInternalComm NG");
- return 0;
- }
- else if((ShmInternalComm = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmat ShmInternalComm NG");
- return 0;
- }
- memset(ShmInternalComm, 0, sizeof(struct InternalComm));
- #if 0
-
- if((MeterSMId = shmget(ShmInternalCommACKey, sizeof(struct InternalCommAC), IPC_CREAT | 0777)) < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmget ShmInternalCommAC NG");
- return 0;
- }
- else if((ShmInternalCommAC = shmat(MeterSMId, NULL, 0)) == (void *)-1)
- {
- SAVE_SYS_LOG_MSG_MAIN("CreateShareMemory:shmat ShmInternalCommAC NG");
- return 0;
- }
-
- memset(ShmInternalCommAC, 0, sizeof(struct InternalCommAC));
- #endif
- return 1;
- }
- void GPIO_Init()
- {
-
-
-
-
-
- system("echo 64 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio64/direction");
-
-
- system("echo 87 > /sys/class/gpio/export");
- system("echo \"in\" > /sys/class/gpio/gpio87/direction");
-
-
-
-
-
- system("echo 89 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio89/direction");
- system("echo 0 > /sys/class/gpio/gpio89/value");
-
-
- system("echo 88 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio88/direction");
- system("echo 0 > /sys/class/gpio/gpio88/value");
-
-
- system("echo 86 > /sys/class/gpio/export");
- system("echo \"out\" > /sys/class/gpio/gpio86/direction");
- system("echo 0 > /sys/class/gpio/gpio86/value");
- SAVE_SYS_LOG_MSG_MAIN("GPIO_Init(): DONE");
- }
- void PWM_Init()
- {
-
-
-
- system("echo 0 > /sys/class/pwm/pwmchip0/export");
- system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/period");
- system("echo 1000000 > /sys/class/pwm/pwmchip0/pwm0/duty_cycle");
- system("echo 1 > /sys/class/pwm/pwmchip0/pwm0/enable");
-
-
-
- SAVE_SYS_LOG_MSG_MAIN("PWM_Init(): DONE");
- }
- void Confinguration_Init()
- {
-
- LoadSysConfigAndInfo(&ShmSysConfigAndInfo->SysConfig);
- SAVE_SYS_LOG_MSG_MAIN("Confinguration_Init(): DONE");
- }
- #if SAVE_SYS_LOG_MSG_MAIN_SWITCH == ENABLE
- int StoreLogMsg(unsigned char *DataString)
- {
- static unsigned char Buf[1024];
- static time_t CurrentTime;
- static struct tm *tm;
- static struct timeval tv;
- memset(Buf, 0, sizeof(Buf));
- CurrentTime = time(NULL);
- tm = localtime(&CurrentTime);
- gettimeofday(&tv, NULL);
- sprintf(Buf, "echo \"[%04d%02d%02d: %02d:%02d:%02d.%06d][main]%s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year + 1900,
- tm->tm_mon + 1,
- tm->tm_mday,
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- tv.tv_usec,
- DataString,
- tm->tm_year + 1900,
- tm->tm_mon + 1);
- system(Buf);
- DEBUG_PRINTF_MAIN_SYSTEM_LOG("[%02d:%02d:%02d.%06d][main]%s \n",
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- tv.tv_usec,
- DataString);
-
- memset(buf_log_main, 0, SIZE_OF_LOG_BUFFER);
- }
- #endif
- double DiffTimeb(struct timeb ST, struct timeb ET)
- {
-
- double StartTime, EndTime;
- double t_diff;
- StartTime = ((double)ST.time)*1000 + (double)ST.millitm;
- EndTime = ((double)ET.time)*1000 + (double)ET.millitm;
- t_diff = EndTime - StartTime;
-
- if (t_diff < 0)
- {
- #if 0
- if (t_diff < -1000)
- {
- sprintf(buf_log_main,
- "[Warning]StartTime(%.02lf) > EndTime(%.02lf), d(%.02lf)",
- StartTime,
- EndTime,
- t_diff);
- SAVE_SYS_LOG_MSG_MAIN(buf_log_main);
- }
- #endif
- return -1;
- }
- return t_diff;
- }
- int SpawnTask()
- {
-
- system("/root/CsuComm &");
-
- usleep(50000);
-
-
- system("/root/SeccComm &");
- }
- int StoreUsrConfigData(struct SysConfigData *UsrData)
- {
- int fd, wrd;
- unsigned int i, Chk;
- unsigned char *ptr;
- Chk = 0;
- ptr = (unsigned char *)UsrData;
- for(i = 0; i < sizeof(struct SysConfigData) - 4; i++)
- {
- Chk += *(ptr + i);
- }
- UsrData->Checksum = Chk;
- fd = open("/dev/mtdblock10", O_RDWR);
- if(fd < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("StoreUsrConfigData: open /dev/mtdblock10 NG");
- return 0;
- }
- wrd = write(fd, UsrData, sizeof(struct SysConfigData));
- close(fd);
- if(wrd != (sizeof(struct SysConfigData)))
- {
- SAVE_SYS_LOG_MSG_MAIN("StoreUsrConfigData: write /dev/mtdblock10 NG");
- return 0;
- }
- fd = open("/dev/mtdblock11", O_RDWR);
- if(fd < 0)
- {
- SAVE_SYS_LOG_MSG_MAIN("StoreUsrConfigData: open /dev/mtdblock11(backup) NG");
- return 0;
- }
- wrd = write(fd, UsrData, sizeof(struct SysConfigData));
- close(fd);
- if(wrd != (sizeof(struct SysConfigData)))
- {
- SAVE_SYS_LOG_MSG_MAIN("StoreUsrConfigData: write /dev/mtdblock11(backup) NG");
- return 0;
- }
- return 1;
- }
- int LoadSysConfigAndInfo(struct SysConfigData *ptr)
- {
- int fd, wrd;
- struct SysConfigData *buf;
- unsigned char *PtrBuf;
- unsigned int ChkSum, ChkSumOrg;
- if((buf = malloc(sizeof(struct SysConfigData))) == NULL)
- {
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): malloc buffer NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, sizeof(struct SysConfigData));
- fd = open("/dev/mtdblock10", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo():open mtdblock10 NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- wrd = read(fd, buf, sizeof(struct SysConfigData));
- close(fd);
- if(wrd != (sizeof(struct SysConfigData)))
- {
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): read SysConfigData data NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- PtrBuf = (unsigned char *)buf;
- ChkSum = 0;
- for(wrd = 0; wrd < (sizeof(struct SysConfigData) - 4); wrd++)
- {
- ChkSum += PtrBuf[wrd];
- }
- ChkSumOrg = buf->Checksum;
- if(ChkSum != ChkSumOrg)
- {
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): Primary SysConfigData checksum NG, read backup");
- fd = open("/dev/mtdblock11", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): open mtdblock11 (backup) NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, sizeof(struct SysConfigData));
- wrd = read(fd, buf, sizeof(struct SysConfigData));
- close(fd);
- if(wrd != sizeof(struct SysConfigData))
- {
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): read backup SysConfigData data NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- PtrBuf = (unsigned char *)buf;
- ChkSum = 0;
- for(wrd = 0; wrd < (sizeof(struct SysConfigData) - 4); wrd++)
- {
- ChkSum += PtrBuf[wrd];
- }
- ChkSumOrg = buf->Checksum;
- if(ChkSum != ChkSumOrg)
- {
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): backup SysConfigData checksum NG, read Factory default");
- fd = open("/dev/mtdblock12", O_RDWR);
- if(fd < 0)
- {
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): open mtdblock12 (Factory default) NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- memset(buf, 0, sizeof(struct SysConfigData));
- wrd = read(fd, buf, sizeof(struct SysConfigData));
- close(fd);
- if(wrd != sizeof(struct SysConfigData))
- {
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): read factory default SysConfigData data NG,rebooting..");
- if(ShmStatusCodeData != NULL)
- {
- ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
- PtrBuf = (unsigned char *)buf;
- ChkSum = 0;
- for(wrd = 0; wrd < (sizeof(struct SysConfigData) - 4); wrd++)
- {
- ChkSum += PtrBuf[wrd];
- }
- ChkSumOrg = buf->Checksum;
- if(ChkSum != ChkSumOrg)
- {
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): factory default SysConfigData checksum NG, restore factory default");
- goto DefaultShm;
- }
- }
- }
-
- memcpy((struct SysConfigData *)ptr, (struct SysConfigData *)buf, sizeof(struct SysConfigData));
- free(buf);
- SAVE_SYS_LOG_MSG_MAIN("LoadSysConfigAndInfo(): Load SysConfigData OK");
- return 1;
- DefaultShm:
- system("cd /root;./FactoryConfig");
- #if (FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == DISABLE)
- {
- SAVE_SYS_LOG_MSG_MAIN("sync...");
- system("sync");
- }
- #endif
- sleep(5);
- system("reboot -f");
- sleep(5);
- system("reboot -f");
- }
|