Module_FactoryConfig.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. #include <sys/time.h>
  2. #include <sys/timeb.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/socket.h>
  8. #include <sys/ipc.h>
  9. #include <sys/shm.h>
  10. #include <sys/shm.h>
  11. #include <sys/mman.h>
  12. #include <linux/wireless.h>
  13. #include <arpa/inet.h>
  14. #include <netinet/in.h>
  15. #include <unistd.h>
  16. #include <stdarg.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <unistd.h>
  20. #include <fcntl.h>
  21. #include <termios.h>
  22. #include <errno.h>
  23. #include <errno.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include <ctype.h>
  27. #include <ifaddrs.h>
  28. #include "define.h"
  29. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  30. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  31. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, __FILE__, __LINE__, __FUNCTION__, ##args)
  32. #define Debug
  33. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  34. #define PASS 1
  35. #define FAIL -1
  36. #define OUTPUT_FLASH 0x01
  37. #define OUTPUT_FILE 0x02
  38. struct SysConfigData SysConfig;
  39. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  40. struct StatusCodeData *ShmStatusCodeData;
  41. struct FanModuleData *ShmFanModuleData;
  42. void trim(char *s);
  43. int mystrcmp(char *p1,char *p2);
  44. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt);
  45. void split(char **arr, char *str, const char *del);
  46. int StoreLogMsg(const char *fmt, ...)
  47. {
  48. char Buf[4096+256];
  49. char buffer[4096];
  50. time_t CurrentTime;
  51. struct tm *tm;
  52. struct timeval tv;
  53. va_list args;
  54. va_start(args, fmt);
  55. int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  56. va_end(args);
  57. memset(Buf,0,sizeof(Buf));
  58. CurrentTime = time(NULL);
  59. tm=localtime(&CurrentTime);
  60. gettimeofday(&tv, NULL); // get microseconds, 10^-6
  61. sprintf(Buf,"echo -n \"[%04d.%02d.%02d %02d:%02d:%02d.%06ld]-%s\" >> /Storage/SystemLog/[%04d.%02d]Module_FactoryConfig",
  62. tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec,
  63. buffer,
  64. tm->tm_year+1900,tm->tm_mon+1);
  65. #ifdef SystemLogMessage
  66. system(Buf);
  67. #endif
  68. #ifdef ConsloePrintLog
  69. printf("[%04d.%02d.%02d %02d:%02d:%02d.%06ld] - %s", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec,tv.tv_usec, buffer);
  70. #endif
  71. return rc;
  72. }
  73. int DiffTimeb(struct timeb ST, struct timeb ET)
  74. {
  75. //return milli-second
  76. unsigned int StartTime,StopTime;
  77. StartTime=(unsigned int)ST.time;
  78. StopTime=(unsigned int)ET.time;
  79. return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  80. }
  81. //=================================
  82. // Common routine
  83. //=================================
  84. void trim(char *s)
  85. {
  86. int i=0, j, k, l=0;
  87. while((s[i]==' ')||(s[i]=='\t')||(s[i]=='\n'))
  88. i++;
  89. j = strlen(s)-1;
  90. while((s[j]==' ')||(s[j]=='\t')||(s[j]=='\n'))
  91. j--;
  92. if(i==0 && j==strlen(s)-1) { }
  93. else if(i==0) s[j+1] = '\0';
  94. else {
  95. for(k=i; k<=j; k++) s[l++] = s[k];
  96. s[l] = '\0';
  97. }
  98. }
  99. int mystrcmp(char *p1,char *p2)
  100. {
  101. while(*p1==*p2)
  102. {
  103. if(*p1=='\0' || *p2=='\0')
  104. break;
  105. p1++;
  106. p2++;
  107. }
  108. if(*p1=='\0' && *p2=='\0')
  109. return(PASS);
  110. else
  111. return(FAIL);
  112. }
  113. void substr(char *dest, const char* src, unsigned int start, unsigned int cnt)
  114. {
  115. strncpy(dest, src + start, cnt);
  116. dest[cnt] = 0;
  117. }
  118. void split(char **arr, char *str, const char *del)
  119. {
  120. char *s = strtok(str, del);
  121. while(s != NULL)
  122. {
  123. *arr++ = s;
  124. s = strtok(NULL, del);
  125. }
  126. }
  127. int runShellCmd(const char*cmd)
  128. {
  129. int result = FAIL;
  130. char buf[256];
  131. FILE *fp;
  132. fp = popen(cmd, "r");
  133. if(fp != NULL)
  134. {
  135. while(fgets(buf, sizeof(buf), fp) != NULL)
  136. {
  137. DEBUG_INFO("%s\n", buf);
  138. }
  139. result = PASS;
  140. }
  141. pclose(fp);
  142. return result;
  143. }
  144. //==========================================
  145. // Init all share memory
  146. //==========================================
  147. int InitShareMemory()
  148. {
  149. int result = PASS;
  150. int MeterSMId;
  151. //creat ShmSysConfigAndInfo
  152. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  153. {
  154. DEBUG_ERROR("shmget ShmSysConfigAndInfo NG\n");
  155. result = FAIL;
  156. }
  157. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  158. {
  159. DEBUG_ERROR("shmat ShmSysConfigAndInfo NG\n");
  160. result = FAIL;
  161. }
  162. else
  163. {}
  164. //creat ShmStatusCodeData
  165. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  166. {
  167. DEBUG_ERROR("shmget ShmStatusCodeData NG\n");
  168. result = FAIL;
  169. }
  170. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  171. {
  172. DEBUG_ERROR("shmat ShmStatusCodeData NG\n");
  173. result = FAIL;
  174. }
  175. else
  176. {}
  177. return result;
  178. }
  179. void helpOutput(void)
  180. {
  181. printf("Usage: Module_FactoryConfig [OPTION]...\n\n");
  182. printf("Generate factory default configuration value\n\n");
  183. printf("OPTION:\n");
  184. printf(" -a Write to file(/mnt) & flash\n");
  185. printf(" -f Write to file(/mnt)\n");
  186. printf(" -m Write to flash\n");
  187. }
  188. //================================================
  189. // Main process
  190. //================================================
  191. int main(int argc, char *argv[])
  192. {
  193. unsigned char outType=0;
  194. unsigned int i,Chk,MtdBlockSize=0x300000;
  195. unsigned char *ptr;
  196. int fd,wrd;
  197. ptr=malloc(MtdBlockSize);
  198. if(ptr==NULL)
  199. {
  200. #ifdef SystemLogMessage
  201. StoreLogMsg("[FactoryConfig]main: malloc for SysConfigData NG");
  202. #endif
  203. return 0;
  204. }
  205. memset(ptr,0,MtdBlockSize);
  206. memset(&SysConfig,0,sizeof(struct SysConfigData));
  207. /*
  208. * TODO: Set factory default configuration
  209. */
  210. // System configuration
  211. time_t t = time(NULL);
  212. struct tm tm = *localtime(&t);
  213. // Initial Share Memory
  214. if(InitShareMemory() == FAIL)
  215. {
  216. DEBUG_ERROR("InitShareMemory NG\n");
  217. strcpy((char*)SysConfig.ModelName, "");
  218. strcpy((char*)SysConfig.SerialNumber, "");
  219. sleep(5);
  220. }
  221. else
  222. {
  223. memcpy((char*)SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.ModelName, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.ModelName));
  224. memcpy((char*)SysConfig.SerialNumber, ShmSysConfigAndInfo->SysConfig.SerialNumber, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.SerialNumber));
  225. memcpy((char*)SysConfig.CsuBootLoadFwRev, ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev, ARRAY_SIZE(ShmSysConfigAndInfo->SysConfig.CsuBootLoadFwRev));
  226. DEBUG_INFO("InitShareMemory OK.\n");
  227. }
  228. sprintf((char*)SysConfig.SystemId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  229. sprintf((char*)SysConfig.SystemDateTime, "%d-%d-%d %d:%d:%d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  230. SysConfig.AuthorisationMode = 0; // 0: enable, 1: disable
  231. SysConfig.DefaultLanguage = 0; // 0: English 1: Big5 2: GB 3: JN 4: Français 5: Italiano 6: Español 7: Deutsch 8: Nederland 9: Norsk 10: Suomalainen 11: Svenska 12: Pусский 13: ไทย
  232. SysConfig.RfidCardNumEndian = 0; // 0: Little endian 1: Big endian
  233. SysConfig.BillingData.isBilling = 0; // 0: not for business 1: for business
  234. SysConfig.isQRCode = 1; // for AuthorisationMode = 0; 0:false, 1:true
  235. SysConfig.isRFID = 1; // for AuthorisationMode = 0; 0:false, 1:true
  236. SysConfig.isAPP = 0; // for AuthorisationMode = 0; 0:false, 1:true
  237. // Charging configuration
  238. SysConfig.MaxChargingEnergy = 0; // 0: No limit Other: 1~65536 KWH
  239. SysConfig.MaxChargingPower = 0; // 0: No limit Other: 1~65536 KW
  240. SysConfig.MaxChargingCurrent = 0; // 0: Rating value Other: 1~Rating A
  241. SysConfig.MaxChargingDuration = 0; // 0: No limit Other: 1~65536 Minute
  242. SysConfig.PhaseLossPolicy = 0; // 0: Charging 1: Stop charging
  243. SysConfig.AcPhaseCount = 1; // 1: One phase 3: Three phase
  244. // Network configuration
  245. strcpy((char*)SysConfig.FtpServer, "");
  246. SysConfig.Eth0Interface.EthDhcpClient = 0;
  247. strcpy((char*)SysConfig.Eth0Interface.EthIpAddress, "192.168.1.10");
  248. strcpy((char*)SysConfig.Eth0Interface.EthSubmaskAddress, "255.255.255.0");
  249. strcpy((char*)SysConfig.Eth0Interface.EthGatewayAddress, "192.168.1.254");
  250. SysConfig.Eth1Interface.EthDhcpClient = 0;
  251. strcpy((char*)SysConfig.Eth1Interface.EthIpAddress, "192.168.0.10");
  252. strcpy((char*)SysConfig.Eth1Interface.EthSubmaskAddress, "255.255.255.0");
  253. strcpy((char*)SysConfig.Eth1Interface.EthGatewayAddress, "192.168.0.254");
  254. // Wifi configuration
  255. SysConfig.AthInterface.WifiMode = 2; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  256. SysConfig.AthInterface.WifiRssi = 0; // Wifi rssi value
  257. strcpy((char *) SysConfig.AthInterface.WifiSsid, ""); // default: Null
  258. strcpy((char *) SysConfig.AthInterface.WifiPassword, ""); // default: Null
  259. SysConfig.AthInterface.WifiDhcpServer = 0; // 0: Enable 1: Disable
  260. SysConfig.AthInterface.WifiDhcpClient = 0; // 0: Enable 1: Disable
  261. SysConfig.AthInterface.WifiBroadcastSsid = 1; // 0: hidden 1: broadcast
  262. // Telecom configuration
  263. strcpy((char*)SysConfig.TelecomInterface.TelcomApn, ""); // default: Null
  264. SysConfig.TelecomInterface.TelcomEnabled = 1; // 0: disable, 1: enable
  265. SysConfig.TelecomInterface.TelcomRssi = 0; // default: 0
  266. SysConfig.TelecomInterface.TelcomSimStatus = 0; // SIM card status
  267. SysConfig.TelecomInterface.TelcomModemMode = 0; // 0: No services 1: CDMA 2: GSM/GPRS 3: WCDMA 4: GSM/WCDMA 5: TD_SCDMA 6: Unknown
  268. strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapId, ""); // default: Null
  269. strcpy((char *) SysConfig.TelecomInterface.TelcomChapPapPwd, ""); // default: Null
  270. strcpy((char *) SysConfig.TelecomInterface.TelcomModemImei, ""); // default: Null
  271. strcpy((char *) SysConfig.TelecomInterface.TelcomSimImsi, ""); // default: Null
  272. strcpy((char *) SysConfig.TelecomInterface.TelcomSimIccid, ""); // default: Null
  273. // Backend configuration
  274. strcpy((char*)SysConfig.OcppServerURL, "");
  275. sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  276. strcpy((char *)SysConfig.chargePointVendor, ""); // default: Null
  277. strcpy((char*)SysConfig.MaintainServerURL, "");
  278. SysConfig.BackendConnTimeout=300; // 300 seconds
  279. SysConfig.OfflinePolicy = 2; // 0: local list, 1: Phihong RFID tag, 2: free charging, 3: no charging
  280. SysConfig.OfflineMaxChargeEnergy = 0; // 0: Same as MaxChargeEnergy Other: 1~65535KWH
  281. SysConfig.OfflineMaxChargeDuration = 0; // 0: Same as MaxChargeDuration Other: 1~65535 minutes
  282. SysConfig.isReqFirstUpgrade = 1; // 0: Skip first upgrade, 1: Process first upgrade
  283. // Other configuration
  284. SysConfig.isEnable15118 = 0; // 0: Disable 1: Enable
  285. // Customization configuration item
  286. if(SysConfig.ModelName[11] == 'S')
  287. {
  288. if(SysConfig.ModelName[12] == 'P')
  289. {
  290. /*
  291. * SHELL AX-48 customization configuration
  292. * 1. AXLU111001DSP4-RW
  293. */
  294. SysConfig.AuthorisationMode = 0; // 0: enable, 1: disable
  295. SysConfig.AthInterface.WifiMode = 0; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  296. SysConfig.TelecomInterface.TelcomEnabled = 1; // 0: disable, 1: enable
  297. strcpy((char*)SysConfig.TelecomInterface.TelcomApn, "ESEYE1");
  298. strcpy((char*)SysConfig.OcppServerURL, "wss://charge.greenlots.com:9092/greenlots/ocpp");
  299. strcpy((char*)SysConfig.ChargeBoxId, "");
  300. strcpy((char *)SysConfig.chargePointVendor, "SRS-Zerova");
  301. strcpy((char*)SysConfig.MaintainServerURL, "");
  302. }
  303. else if(SysConfig.ModelName[12] == 'Z')
  304. {
  305. /*
  306. * AMAZON AX-48 customization configuration
  307. * 1. AXLU111001DSZ4-RW
  308. */
  309. SysConfig.AuthorisationMode = 1; // 0: enable, 1: disable
  310. SysConfig.AthInterface.WifiMode = 0; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  311. SysConfig.TelecomInterface.TelcomEnabled = 1; // 0: disable, 1: enable
  312. strcpy((char*)SysConfig.TelecomInterface.TelcomApn, "ESEYE1");
  313. strcpy((char*)SysConfig.OcppServerURL, "wss://charge.greenlots.com:9092/greenlots/ocpp");
  314. strcpy((char*)SysConfig.ChargeBoxId, "");
  315. strcpy((char *)SysConfig.chargePointVendor, "Amazon");
  316. strcpy((char*)SysConfig.MaintainServerURL, "");
  317. }
  318. else
  319. {}
  320. }
  321. else
  322. {
  323. if(SysConfig.ModelName[12] == 'P')
  324. {
  325. // PHIHONG standard configuration
  326. strcpy((char*)SysConfig.OcppServerURL, ""); // default: Null
  327. sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  328. strcpy((char *)SysConfig.chargePointVendor, ""); // default: Null
  329. strcpy((char*)SysConfig.MaintainServerURL, ""); // default: Null
  330. }
  331. else if(SysConfig.ModelName[12] == 'T')
  332. {
  333. if(SysConfig.ModelName[13] == 'C')
  334. {
  335. /*
  336. * Taiwan Cement AX-48 customization configuration
  337. * 1. AXSC111001W1TC-RW
  338. */
  339. strcpy((char*)SysConfig.OcppServerURL, ""); // default: Null
  340. sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  341. strcpy((char *)SysConfig.chargePointVendor, ""); // default: Null
  342. strcpy((char*)SysConfig.MaintainServerURL, ""); // default: Null
  343. }
  344. else
  345. {
  346. /*
  347. * TOG AX-48 customization configuration
  348. * 1. AXLU111001D1T1-RW
  349. * 2. AXLU111001W1T1-RW
  350. */
  351. SysConfig.AuthorisationMode = 0; // 0: enable, 1: disable
  352. SysConfig.RfidCardNumEndian = 1; // 0: Little endian 1: Big endian
  353. SysConfig.QRCodeMadeMode = 1; // for isQRCode=1 ; 0: default 1:customized
  354. strcpy((char*)SysConfig.QRCodeContent, "NA"); // for QRCodeMadeMode=1
  355. SysConfig.AthInterface.WifiMode = 1; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  356. strcpy((char*)SysConfig.AthInterface.WifiSsid, "ChargeLab-EVC");
  357. strcpy((char*)SysConfig.AthInterface.WifiPassword, "evc-pwd-default-21");
  358. strcpy((char*)SysConfig.TelecomInterface.TelcomApn, "m2minternet.apn");
  359. strcpy((char*)SysConfig.OcppServerURL, "wss://ocpp.io");
  360. sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  361. strcpy((char*)SysConfig.chargePointVendor, "ChargeLab");
  362. SysConfig.OfflinePolicy = 0; // 0: local list, 1: Phihong RFID tag, 2: free charging, 3: no charging
  363. }
  364. }
  365. else if(SysConfig.ModelName[12] == 'Z')
  366. {
  367. /*
  368. * AMAZON AX-48 customization configuration
  369. * 1. AXLU111001D1Z4-RW
  370. */
  371. SysConfig.AuthorisationMode = 1; // 0: enable, 1: disable
  372. SysConfig.AthInterface.WifiMode = 0; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  373. SysConfig.TelecomInterface.TelcomEnabled = 1; // 0: disable, 1: enable
  374. strcpy((char*)SysConfig.TelecomInterface.TelcomApn, "ESEYE1");
  375. strcpy((char*)SysConfig.OcppServerURL, "wss://charge.greenlots.com:9092/greenlots/ocpp");
  376. strcpy((char*)SysConfig.ChargeBoxId, "");
  377. strcpy((char *)SysConfig.chargePointVendor, "Amazon");
  378. strcpy((char*)SysConfig.MaintainServerURL, "");
  379. }
  380. else if(SysConfig.ModelName[12] == 'S')
  381. {
  382. if((SysConfig.ModelName[4] == '1') &&
  383. (SysConfig.ModelName[5] == '1') &&
  384. (SysConfig.ModelName[6] == '1'))
  385. {
  386. /* SWTCH AX-48 customization configuration
  387. * 1. AXLU111001D1S1-RW
  388. * 2. AXLU111001W1S1-RW
  389. */
  390. SysConfig.RfidCardNumEndian = 1; // 0: Little endian 1: Big endian
  391. SysConfig.QRCodeMadeMode = 1; // for isQRCode=1 ; 0: default 1:customized
  392. strcpy((char*)SysConfig.QRCodeContent, "https://charge.swtchenergy.com"); // for QRCodeMadeMode=1
  393. SysConfig.AthInterface.WifiMode = 1; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  394. strcpy((char*)SysConfig.AthInterface.WifiSsid, "SWTCH");
  395. strcpy((char*)SysConfig.AthInterface.WifiPassword, "Swtch456!");
  396. strcpy((char*)SysConfig.OcppServerURL, "ws://ocpp.swtchev.com/Zerova");
  397. sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  398. strcpy((char *)SysConfig.chargePointVendor, "Zerova AX48");
  399. strcpy((char*)SysConfig.MaintainServerURL, "");
  400. }
  401. else if((SysConfig.ModelName[4] == '1') &&
  402. (SysConfig.ModelName[5] == '9') &&
  403. (SysConfig.ModelName[6] == '1'))
  404. {
  405. /* SWTCH AX-80 customization configuration
  406. * 1. AXLU191001W1S1-RW
  407. * 2. AXLU191001D1S1-RW
  408. * 3. AXLU191001W1S1-RW
  409. * 4. AXLU191001D1S1-RW
  410. */
  411. SysConfig.RfidCardNumEndian = 1; // 0: Little endian 1: Big endian
  412. SysConfig.QRCodeMadeMode = 1; // for isQRCode=1 ; 0: default 1:customized
  413. strcpy((char*)SysConfig.QRCodeContent, "https://charge.swtchenergy.com"); // for QRCodeMadeMode=1
  414. SysConfig.AthInterface.WifiMode = 1; // 0: Disable 1: Infrastructure client 2: Infrastructure server 3: Ad-Hoc
  415. strcpy((char*)SysConfig.AthInterface.WifiSsid, "SWTCH");
  416. strcpy((char*)SysConfig.AthInterface.WifiPassword, "Swtch456!");
  417. strcpy((char*)SysConfig.OcppServerURL, "ws://ocpp.swtchev.com/Zerova");
  418. sprintf((char*)SysConfig.ChargeBoxId, "%s%s", SysConfig.ModelName, SysConfig.SerialNumber);
  419. strcpy((char *)SysConfig.chargePointVendor, "Zerova AX80");
  420. strcpy((char*)SysConfig.MaintainServerURL, "");
  421. }
  422. else
  423. {}
  424. }
  425. else
  426. {}
  427. }
  428. // Copy default configuration to pointer
  429. memcpy(ptr,&SysConfig,sizeof(struct SysConfigData));
  430. // Calculate CRC
  431. Chk=0;
  432. for(i=ARRAY_SIZE(SysConfig.CsuBootLoadFwRev);i<(MtdBlockSize-4);i++)
  433. {
  434. Chk+=*(ptr+i);
  435. }
  436. memcpy(ptr+MtdBlockSize-4, &Chk, 4);
  437. /*
  438. * Parameter process
  439. */
  440. if(argc>1)
  441. {
  442. char *arg = argv[1];
  443. switch(arg[0])
  444. {
  445. case '-':
  446. switch(arg[1])
  447. {
  448. case 'a':
  449. outType |= OUTPUT_FILE;
  450. outType |= OUTPUT_FLASH;
  451. break;
  452. case 'f':
  453. outType |= OUTPUT_FILE;
  454. break;
  455. case 'm':
  456. outType |= OUTPUT_FLASH;
  457. break;
  458. default:
  459. helpOutput();
  460. break;
  461. }
  462. break;
  463. default:
  464. helpOutput();
  465. break;
  466. }
  467. }
  468. else
  469. {
  470. helpOutput();
  471. }
  472. /*
  473. * Configuration bin file generate
  474. */
  475. // Save factory default setting value to file
  476. fd = open("/mnt/FactoryDefaultConfig.bin", O_RDWR|O_CREAT|O_TRUNC);
  477. if (fd < 0)
  478. {
  479. DEBUG_ERROR("open /mnt/FactoryDefaultConfig.bin NG\n");
  480. free(ptr);
  481. return 0;
  482. }
  483. wrd=write(fd, ptr, MtdBlockSize);
  484. close(fd);
  485. if(wrd<MtdBlockSize)
  486. {
  487. DEBUG_ERROR("write /mnt/FactoryDefaultConfig.bin NG\n");
  488. free(ptr);
  489. return 0;
  490. }
  491. DEBUG_INFO("FactoryConfig write to file in /mnt OK.\n");
  492. /*
  493. * Flash memory write
  494. */
  495. if((outType&OUTPUT_FLASH)>0)
  496. {
  497. DEBUG_INFO("Erase /dev/mtd10.\n");
  498. runShellCmd("flash_erase /dev/mtd10 0 0");
  499. DEBUG_INFO("Write /dev/mtd10.\n");
  500. runShellCmd("nandwrite -p /dev/mtd10 /mnt/FactoryDefaultConfig.bin");
  501. DEBUG_INFO("Erase /dev/mtd11.\n");
  502. runShellCmd("flash_erase /dev/mtd11 0 0");
  503. DEBUG_INFO("Write /dev/mtd11.\n");
  504. runShellCmd("nandwrite -p /dev/mtd11 /mnt/FactoryDefaultConfig.bin");
  505. DEBUG_INFO("Erase /dev/mtd12.\n");
  506. runShellCmd("flash_erase /dev/mtd12 0 0");
  507. DEBUG_INFO("Write /dev/mtd12.\n");
  508. runShellCmd("nandwrite -p /dev/mtd12 /mnt/FactoryDefaultConfig.bin");
  509. system("rm -f /mnt/FactoryDefaultConfig.bin");
  510. DEBUG_INFO("FactoryConfig write to flash OK\n");
  511. }
  512. free(ptr);
  513. return PASS;
  514. }