ReadCmdline.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  1. /*
  2. * Main.c
  3. *
  4. * Created on: 2019年8月6日
  5. * Author: 7564
  6. */
  7. #include <sys/time.h>
  8. #include <sys/timeb.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <sys/types.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/socket.h>
  14. #include <sys/ipc.h>
  15. #include <sys/shm.h>
  16. #include <sys/shm.h>
  17. #include <sys/mman.h>
  18. #include <linux/wireless.h>
  19. #include <arpa/inet.h>
  20. #include <netinet/in.h>
  21. #include <unistd.h>
  22. #include <stdarg.h>
  23. #include <stdio.h> /*標準輸入輸出定義*/
  24. #include <stdlib.h> /*標準函數庫定義*/
  25. #include <unistd.h> /*Unix 標準函數定義*/
  26. #include <fcntl.h> /*檔控制定義*/
  27. #include <termios.h> /*PPSIX 終端控制定義*/
  28. #include <errno.h> /*錯誤號定義*/
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <time.h>
  32. #include <ctype.h>
  33. #include <ifaddrs.h>
  34. #include <math.h>
  35. #include <stdbool.h>
  36. #include "../../define.h"
  37. typedef unsigned char byte;
  38. #define PASS 1
  39. #define FAIL -1
  40. #define EQUAL 0
  41. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  42. #define NO_DEFINE 255
  43. #define DEFAULT_AC_INDEX 2
  44. #define AUTORUN_STEP1_TIME_START 140 // Minutes
  45. #define AUTORUN_STEP1_TIME_END 150
  46. #define AUTORUN_STEP2_TIME_START 210
  47. #define AUTORUN_STEP2_TIME_END 410
  48. #define AUTORUN_END_TIME 480
  49. #define AUTORUN_CYCLE_COUNT 30
  50. #define TTY_PATH "/dev/tty"
  51. #define STTY_US "stty raw -echo -F "
  52. #define STTY_DEF "stty -raw echo -F "
  53. byte _curAutoRunCount = 0;
  54. byte _usingAutoRun = 0;
  55. struct timeval _autoTime;
  56. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  57. struct StatusCodeData *ShmStatusCodeData;
  58. struct PrimaryMcuData *ShmPrimaryMcuData;
  59. struct CHAdeMOData *ShmCHAdeMOData;
  60. struct CcsData *ShmCcsData;
  61. struct GBTData *ShmGBTData;
  62. struct FanModuleData *ShmFanModuleData;
  63. struct RelayModuleData *ShmRelayModuleData;
  64. struct LedModuleData *ShmLedModuleData;
  65. struct PsuData *ShmPsuData;
  66. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  67. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  68. char *msg = "\n"
  69. "state : get/set gun state (index)\n"
  70. " Example:\n"
  71. " state ac , get AC status, AC not support set command.\n"
  72. " state 0 , get DC connector 1 status\n"
  73. " state 1 , get DC connector 2 status\n"
  74. " state 0 0 , set DC connector 1 to state 0\n"
  75. " state 1 5 , set DC connector 2 to state 5\n"
  76. "\n"
  77. "card : swiping card simulation (card number), if parameter 1 is empty, means execute\n"
  78. " virtual swiping action \n"
  79. " Example:\n"
  80. " card , virtual swiping card (start or stop charging).\n"
  81. " card abcdef , write virtual card ID 'abcdef'.\n"
  82. "\n"
  83. "gun : get gun plugit state (index) \n"
  84. " Example:\n"
  85. " gun ac , get AC connector/socket plug status\n"
  86. " gun ac 1 , set AC connector/socket plug status to pluged\n"
  87. " gun ac 0 , set AC connector/socket plug status to unpluged\n"
  88. " gun 0 , get DC connector 1 plug status\n"
  89. " gun 0 1 , set DC connector 1 plug status to pluged\n"
  90. " gun 1 0 , set DC connector 2 plug status to unpluged\n"
  91. "\n"
  92. "lock : get gun locked state (index) \n"
  93. " Example:\n"
  94. " lock 0 , get DC connector 1 lock status\n"
  95. " lock 0 1 , set DC connector 1 lock status to locked\n"
  96. " lock 1 0 , set DC connector 2 lock status to unlocked\n"
  97. "\n"
  98. "self : self test state (x) \n"
  99. " Example:\n"
  100. " self , get present self status\n"
  101. "\n"
  102. "ver : ver of board (407 or index or rb or fan) \n"
  103. " Example:\n"
  104. " ver 0 , get firmware version of DC connector 1's EV board\n"
  105. " ver 1 , get firmware version of DC connector 2's EV board\n"
  106. " ver 407 , get firmware version of stm32f407 in DC main board\n"
  107. " ver rb , get firmware version of relay board\n"
  108. " ver fan , get firmware version of fan board\n"
  109. " ver dc , get firmware version of am3352 in DC main board\n"
  110. " ver led , get firmware version of LED board\n"
  111. " ver ac , get firmware version of AC charger\n"
  112. "\n"
  113. "ac : get ac contactor state (x) \n"
  114. " Example:\n"
  115. " ac , get AC contactor status (1 is close, 0 is open)\n"
  116. "\n"
  117. "cable : set cable check (IMD) result, 1: pass, 2: failed, 3: warning\n"
  118. " Example:\n"
  119. " cable 0 1 , set DC connector 1 IMD result to pass\n"
  120. " cable 1 2 , set DC connector 2 IMD result to failed\n"
  121. "\n"
  122. "pow : set target charging current, only for force charging use!!!\n"
  123. " Example:\n"
  124. " pow 20 , set target charging current to 20 A \n"
  125. " pow 10.5 , set target charging current to 10.5 A\n"
  126. "\n"
  127. "model : get model name, serial number and misc system information\n"
  128. " Example:\n"
  129. " model , get information\n"
  130. "\n"
  131. "select : get/set present selected connector\n"
  132. " Example:\n"
  133. " select , get present select connector number\n"
  134. " select 0 , set present select connector to connector 1\n"
  135. " select 1 , set present select connector to connector 2\n"
  136. "\n"
  137. "change : vitural gun select button press\n"
  138. " Example:\n"
  139. " change , simulate the gun select button pressed\n"
  140. "\n"
  141. "fan : set fan speed\n"
  142. " Example:\n"
  143. " fan 3000 , set fan speed to 3000 rpm\n"
  144. " fan 14000 , set fan speed to 14000 rpm\n"
  145. "\n"
  146. "speed : get fan speed\n"
  147. " Example:\n"
  148. " speed , get present fan speed\n"
  149. "\n"
  150. "debug : set debug mode\n"
  151. " Example:\n"
  152. " debug 1 , enable debug mode, print debug log to console\n"
  153. " debug 0 , disable debug mode, print debug log to log file\n"
  154. "\n"
  155. "gfd : set gfd(IMD) enable/disable in force charging\n"
  156. " Example:\n"
  157. " gfd 1 , enable IMD test in force charging mode\n"
  158. " gfd 0 , disable IMD test in force charging mode\n"
  159. "\n"
  160. "temp : get temperature from PSU\n"
  161. " Example:\n"
  162. " temp , display the present temperature of PSU\n"
  163. "\n"
  164. "acin : get 3 phase voltage of AC input\n"
  165. " Example:\n"
  166. " acin , display R(L1) S(L2) T(L3) voltage\n"
  167. "\n"
  168. "psu : get psu information and psu test command\n"
  169. " Example:\n"
  170. " psu count , display present PSU quantity\n"
  171. " psu ver , display primary and secondly firmware version of all PSU\n"
  172. " psu cap , display available current and power of all PSU group\n"
  173. " psu input , display 3 phase voltage of AC input which sensing by PSU\n"
  174. " psu output , display present DC output voltage and current of all PSU group\n"
  175. " psu test 1 , enable PSU test mode, for D to D and PFC firmware version 9.06 up\n"
  176. " after PSU test finish, please reboot charger to exit PSU test mode\n"
  177. " psu out 500 5 , need enable mode first, command PSU output 500V and 5A\n"
  178. " psu out 200.5 7.5 , need enable mode first, command PSU output 200.5V and 7.5A\n"
  179. "\n"
  180. "cap : get maximum output capacities\n"
  181. " Example:\n"
  182. " cap 0 , get initial and real maximum output power, voltage and current of connector 1\n"
  183. " cap 1 , get initial and real maximum output power, voltage and current of connector 2\n"
  184. "\n"
  185. "error : triggering error event\n"
  186. " Example:\n"
  187. " error 1 , virtual trigging L1 input OVP\n"
  188. " error 0 , cancel trigging L1 input OVP\n"
  189. "\n"
  190. "auth : setup authorize flag, it is for charging permission\n"
  191. " Example:\n"
  192. " auth 1 , setup authorize flag to vaild\n"
  193. "\n"
  194. "relay : get present output and pre-charge relay status\n"
  195. " Example:\n"
  196. " relay 0 , get present output relay status of connector 1\n"
  197. " relay 1 , get present output relay status of connector 2\n"
  198. "\n"
  199. "ccid : set EVCC ID\n"
  200. " Example:\n"
  201. " ccid 0 1a2b3c4d , setup EVCC ID '1a2b3c4d' to connector 1\n"
  202. " ccid 1 qwerasdf , setup EVCC ID 'qwerasdf' to connector 2\n"
  203. "\n"
  204. "strchg : command charger to start force charging procedure\n"
  205. " 1st parameter for select using connector\n"
  206. " 2nd parameter for command output voltage, range: 150V~1000V\n"
  207. " 3th parameter for command output current, range: 2A~100A\n"
  208. " Example:\n"
  209. " strchg 0 200 2 , command force charging output 200V and 2A from connector 1\n"
  210. " strchg 1 450.5 10.5 , command force charging output 450.5V and 10.5A from connector 2\n"
  211. ;
  212. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  213. {
  214. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  215. {
  216. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  217. {
  218. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  219. return true;
  220. }
  221. }
  222. for (byte index = 0; index < CCS_QUANTITY; index++)
  223. {
  224. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  225. {
  226. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  227. return true;
  228. }
  229. }
  230. for (byte index = 0; index < GB_QUANTITY; index++)
  231. {
  232. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  233. {
  234. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  235. return true;
  236. }
  237. }
  238. return false;
  239. }
  240. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  241. {
  242. if (target < AC_QUANTITY)
  243. {
  244. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  245. return true;
  246. }
  247. return false;
  248. }
  249. int InitShareMemory()
  250. {
  251. int result = PASS;
  252. int MeterSMId;
  253. //initial ShmSysConfigAndInfo
  254. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  255. {
  256. result = FAIL;
  257. }
  258. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  259. {
  260. result = FAIL;
  261. }
  262. else
  263. {}
  264. //initial ShmStatusCodeData
  265. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  266. {
  267. result = FAIL;
  268. }
  269. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  270. {
  271. result = FAIL;
  272. }
  273. else
  274. {}
  275. if (CHAdeMO_QUANTITY > 0) {
  276. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData), IPC_CREAT | 0777)) < 0)
  277. {
  278. result = FAIL;
  279. }
  280. else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  281. result = FAIL;
  282. }
  283. else
  284. {
  285. //NULL
  286. }
  287. }
  288. if (CCS_QUANTITY > 0)
  289. {
  290. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData), IPC_CREAT | 0777)) < 0)
  291. {
  292. result = FAIL;
  293. }
  294. else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  295. {
  296. result = FAIL;
  297. }
  298. else
  299. {
  300. //NULL
  301. }
  302. }
  303. if (GB_QUANTITY > 0)
  304. {
  305. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData), IPC_CREAT | 0777)) < 0)
  306. {
  307. return 0;
  308. }
  309. else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  310. {
  311. return 0;
  312. }
  313. memset(ShmGBTData, 0, sizeof(struct GBTData));
  314. }
  315. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  316. {
  317. result = FAIL;
  318. }
  319. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  320. {
  321. result = FAIL;
  322. }
  323. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  324. {
  325. result = FAIL;
  326. }
  327. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  328. {
  329. result = FAIL;
  330. }
  331. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  332. {
  333. result = FAIL;
  334. }
  335. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  336. {
  337. result = FAIL;
  338. }
  339. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  340. {
  341. result = FAIL;
  342. }
  343. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  344. {
  345. result = FAIL;
  346. }
  347. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  348. {
  349. result = FAIL;
  350. }
  351. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  352. {
  353. result = FAIL;
  354. }
  355. return result;
  356. }
  357. unsigned long GetTimeoutValue(struct timeval _sour_time)
  358. {
  359. struct timeval _end_time;
  360. gettimeofday(&_end_time, NULL);
  361. return (_end_time.tv_sec - _sour_time.tv_sec);
  362. }
  363. void RunStatusProc(char *v1, char *v2)
  364. {
  365. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  366. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  367. if (strcmp(v1, "ac") == 0)
  368. {
  369. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  370. {
  371. printf("FindChargingInfoData (AC) false \n");
  372. }
  373. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  374. return;
  375. }
  376. int _index = atoi(v1);
  377. if (_index <= 1)
  378. {
  379. if (!FindChargingInfoData(_index, &_chargingData[0]))
  380. {
  381. printf ("FindChargingInfoData error\n");
  382. return;
  383. }
  384. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  385. {
  386. // get
  387. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  388. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  389. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  390. }
  391. else
  392. {
  393. // set
  394. _chargingData[_index]->SystemStatus = atoi(v2);
  395. }
  396. }
  397. else
  398. {
  399. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  400. {
  401. printf("FindChargingInfoData (AC) false \n");
  402. }
  403. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  404. {
  405. // get
  406. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  407. }
  408. else
  409. {
  410. // set
  411. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  412. }
  413. }
  414. }
  415. void RunCardProc(char *v1, char *v2)
  416. {
  417. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  418. {
  419. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  420. {
  421. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  422. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  423. }
  424. else
  425. {
  426. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  427. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  428. }
  429. }
  430. else
  431. {
  432. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  433. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  434. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  435. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  436. }
  437. }
  438. void RunGunPlugitProc(char *v1, char *v2)
  439. {
  440. if (strcmp(v1, "ac") == 0)
  441. {
  442. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  443. {
  444. printf("FindChargingInfoData (AC) false \n");
  445. }
  446. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  447. {
  448. // get
  449. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  450. }
  451. else
  452. {
  453. // set
  454. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  455. }
  456. return;
  457. }
  458. int _index = atoi(v1);
  459. if (!FindChargingInfoData(_index, &_chargingData[0]))
  460. {
  461. printf("FindChargingInfoData error\n");
  462. return;
  463. }
  464. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  465. {
  466. // get
  467. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  468. }
  469. else
  470. {
  471. // set
  472. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  473. }
  474. }
  475. void GetGunLockStatusProc(char *v1, char *v2)
  476. {
  477. int _index = atoi(v1);
  478. if (!FindChargingInfoData(_index, &_chargingData[0]))
  479. {
  480. printf("FindChargingInfoData error\n");
  481. return;
  482. }
  483. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  484. {
  485. _chargingData[_index]->GunLocked = atoi(v2);
  486. }
  487. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  488. }
  489. void SetSystemIDProc()
  490. {
  491. char *systemId = "Alston_Test";
  492. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  493. }
  494. void RunSelfProc()
  495. {
  496. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  497. }
  498. void GetFwVerProc(char *v1)
  499. {
  500. if (strcmp(v1, "407") == 0)
  501. {
  502. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  503. }
  504. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
  505. {
  506. int _index = atoi(v1);
  507. if (_index == 0)
  508. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  509. else if (_index == 1)
  510. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  511. }
  512. else if (strcmp(v1, "rb") == 0)
  513. {
  514. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  515. }
  516. else if (strcmp(v1, "fan") == 0)
  517. {
  518. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  519. }
  520. else if (strcmp(v1, "dc") == 0)
  521. {
  522. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  523. }
  524. else if (strcmp(v1, "led") == 0)
  525. {
  526. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  527. }
  528. else if (strcmp(v1, "ac") == 0)
  529. {
  530. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  531. {
  532. printf("FindChargingInfoData (AC) false \n");
  533. }
  534. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  535. }
  536. }
  537. void CreateOneError(char *v1)
  538. {
  539. int value = atoi(v1);
  540. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = value;
  541. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  542. }
  543. void GetAuthorizeFlag(char *v1)
  544. {
  545. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  546. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  547. else
  548. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  549. }
  550. void GetRelayStatus(char *v1)
  551. {
  552. int _index = atoi(v1);
  553. if (!FindChargingInfoData(_index, &_chargingData[0]))
  554. {
  555. printf("FindChargingInfoData error\n");
  556. return;
  557. }
  558. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  559. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  560. }
  561. void FwUpdateFlagProc()
  562. {
  563. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  564. }
  565. void CheckAcStatus(char *v1)
  566. {
  567. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  568. {
  569. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  570. }
  571. }
  572. void SetCableChkStatus(char *v1, char *v2)
  573. {
  574. int _index = atoi(v1);
  575. if (!FindChargingInfoData(_index, &_chargingData[0]))
  576. {
  577. printf ("FindChargingInfoData error\n");
  578. return;
  579. }
  580. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  581. }
  582. void SetChargingInfoCCID(char *v1, char* v2)
  583. {
  584. int _index = atoi(v1);
  585. if (!FindChargingInfoData(_index, &_chargingData[0]))
  586. {
  587. printf ("FindChargingInfoData error\n");
  588. return;
  589. }
  590. memcpy(_chargingData[_index]->EVCCID, v2, 8);
  591. _chargingData[_index]->EVCCID[8] = '\0';
  592. }
  593. void SetPowerValue(char *v1, char *v2)
  594. {
  595. int _index = atoi(v1);
  596. float _Current = atof(v2);
  597. // 盲沖的時候才允許使用~
  598. if (_chargingData[_index]->Type != 9)
  599. return;
  600. if (!FindChargingInfoData(_index, &_chargingData[0]))
  601. {
  602. printf ("FindChargingInfoData error\n");
  603. return;
  604. }
  605. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  606. }
  607. void GetSystemInfo()
  608. {
  609. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  610. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  611. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  612. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  613. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  614. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  615. }
  616. void ChangeGunNum()
  617. {
  618. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  619. {
  620. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  621. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  622. }
  623. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  624. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  625. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  626. else
  627. {
  628. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  629. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  630. }
  631. }
  632. void GetGunSelectedNum(char *v1)
  633. {
  634. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  635. {
  636. if (AC_QUANTITY > 0 &&
  637. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  638. {
  639. printf("connector select changed = AC \n");
  640. }
  641. else
  642. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  643. }
  644. else
  645. {
  646. int _index = atoi(v1);
  647. if (_index <= 1)
  648. {
  649. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  650. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  651. printf("connector select changed = %d \n", _index);
  652. }
  653. else if (AC_QUANTITY > 0)
  654. {
  655. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  656. printf("connector select changed = AC \n");
  657. }
  658. }
  659. }
  660. void SetFanSpeed(char *v1)
  661. {
  662. int speed = atoi(v1);
  663. ShmFanModuleData->TestFanSpeed = speed;
  664. }
  665. void GetFanSpeed()
  666. {
  667. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  668. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  669. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  670. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  671. }
  672. void SetDebugMode(char *v1)
  673. {
  674. int mode = atoi(v1);
  675. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  676. }
  677. void SetGFDMode(char *v1)
  678. {
  679. int mode = atoi(v1);
  680. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  681. }
  682. void GetPsuTemp()
  683. {
  684. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  685. {
  686. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  687. {
  688. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  689. }
  690. }
  691. }
  692. void GetAcInputVol()
  693. {
  694. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  695. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  696. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  697. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  698. }
  699. void GetPsuInformation(char *v1, char *v2, char *v3)
  700. {
  701. printf("**********************AC Contact needed*************************\n");
  702. if(strcmp(v1, "count") == 0)
  703. {
  704. for (int i = 0; i < 4; i++)
  705. {
  706. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  707. }
  708. }
  709. else if(strcmp(v1, "ver") == 0)
  710. {
  711. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  712. {
  713. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  714. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  715. }
  716. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  717. {
  718. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  719. {
  720. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  721. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  722. }
  723. }
  724. }
  725. else if(strcmp(v1, "cap") == 0)
  726. {
  727. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  728. {
  729. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  730. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  731. }
  732. }
  733. else if(strcmp(v1, "input") == 0)
  734. {
  735. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  736. {
  737. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  738. {
  739. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  740. i, count,
  741. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  742. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  743. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  744. }
  745. }
  746. }
  747. else if (strcmp(v1, "output") == 0)
  748. {
  749. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  750. {
  751. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  752. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  753. }
  754. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  755. {
  756. if (!FindChargingInfoData(i, &_chargingData[0]))
  757. {
  758. printf ("FindChargingInfoData error\n");
  759. continue;
  760. }
  761. printf("Form RB : Group Index = %d, OutputV = %f \n",
  762. i, _chargingData[i]->FireChargingVoltage);
  763. }
  764. }
  765. else if (strcmp(v1, "test") == 0)
  766. {
  767. int mode = atoi(v2);
  768. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  769. {
  770. ShmPsuData->Work_Step = mode;
  771. }
  772. }
  773. else if (strcmp(v1, "out") == 0)
  774. {
  775. float vol = atof(v2);
  776. float cur = atof(v3);
  777. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  778. {
  779. if (!FindChargingInfoData(0, &_chargingData[0]))
  780. {
  781. printf ("FindChargingInfoData error\n");
  782. return;
  783. }
  784. _chargingData[0]->EvBatterytargetVoltage = vol;
  785. _chargingData[0]->EvBatterytargetCurrent = cur;
  786. }
  787. }
  788. printf("*************************************************\n");
  789. }
  790. void GetConnectorCapInfo(char *v1)
  791. {
  792. int _GunIndex = atoi(v1);
  793. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  794. {
  795. printf ("FindChargingInfoData error\n");
  796. return;
  797. }
  798. printf ("Charger Max Current = %d, Max Power = %d \n",
  799. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  800. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  801. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  802. _GunIndex,
  803. _chargingData[_GunIndex]->RealMaxPower,
  804. _chargingData[_GunIndex]->RealMaxVoltage,
  805. _chargingData[_GunIndex]->RealMaxCurrent);
  806. }
  807. static void get_char(char *word)
  808. {
  809. fd_set rfds;
  810. struct timeval tv;
  811. FD_ZERO(&rfds);
  812. FD_SET(0, &rfds);
  813. tv.tv_sec = 0;
  814. tv.tv_usec = 10; //wait input timout time
  815. //if input
  816. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  817. {
  818. fgets(word, 128, stdin);
  819. }
  820. }
  821. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  822. {
  823. int _GunIndex;
  824. float _Voltage;
  825. float _Current;
  826. if (strcmp(v1, "auto") == EQUAL)
  827. {
  828. _usingAutoRun = 0x01;
  829. _GunIndex = 0;
  830. _Voltage = 500;
  831. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  832. }
  833. else
  834. {
  835. _usingAutoRun = 0x00;
  836. _GunIndex = atoi(v1);
  837. _Voltage = atof(v2);
  838. _Current = atof(v3);
  839. }
  840. unsigned char PreviousSystemStatus = 0xff;
  841. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  842. {
  843. printf ("FindChargingInfoData error\n");
  844. return;
  845. }
  846. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  847. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  848. if(_Voltage > 1000 || _Voltage < 50)
  849. {
  850. printf ("Input Voltage over range\n");
  851. return;
  852. }
  853. // if(_Current > 100 || _Current < 2){
  854. //
  855. // printf ("Input Current over range\n");
  856. // return;
  857. // }
  858. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  859. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  860. //kill ev task
  861. system("killall Module_EvComm");
  862. //_Voltage = (_Voltage * 10);
  863. //_Current = (_Current * 10);
  864. //system(STTY_US TTY_PATH);
  865. while(true)
  866. {
  867. //fix gun 1
  868. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  869. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  870. {
  871. case S_IDLE:
  872. {
  873. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  874. {
  875. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  876. printf ("[UnconditionalCharge - S_IDLE]\n");
  877. }
  878. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  879. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  880. }
  881. break;
  882. case S_PREPARNING:
  883. {
  884. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  885. {
  886. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  887. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  888. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  889. printf ("wait find module\n");
  890. }
  891. //main 會在此階段判斷以下資料跳到下一個 state
  892. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  893. //ShmPsuData->SystemPresentPsuQuantity;
  894. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  895. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  896. //_chargingData[gun_index]->AvailableChargingPower;
  897. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  898. //sleep(10);
  899. //清除 main timeout 機制
  900. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  901. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  902. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  903. }
  904. break;
  905. case S_PREPARING_FOR_EV:
  906. {
  907. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  908. {
  909. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  910. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  911. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  912. }
  913. //清除 main timeout 機制
  914. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  915. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  916. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  917. //充電電壓電流
  918. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  919. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  920. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  921. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  922. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  923. //確定模組己升壓完成
  924. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  925. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  926. {
  927. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  928. //EV done
  929. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  930. }
  931. }
  932. break;
  933. case S_PREPARING_FOR_EVSE:
  934. {
  935. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  936. {
  937. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  938. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  939. }
  940. //printf ("tar vol = %d \n", _Voltage);
  941. //printf ("tar cur = %d \n", _Current);
  942. //清除 main timeout 機制
  943. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  944. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  945. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  946. //充電電壓電流
  947. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  948. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  949. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  950. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  951. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  952. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  953. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  954. //確定模組己升壓完成
  955. if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  956. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  957. {
  958. printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  959. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  960. sleep(5);
  961. //EV done
  962. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  963. }
  964. else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  965. {
  966. printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  967. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  968. }
  969. }
  970. break;
  971. case S_CHARGING:
  972. {
  973. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  974. {
  975. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  976. if (_usingAutoRun == 0x00)
  977. {
  978. //充電電壓電流
  979. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  980. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  981. }
  982. else
  983. {
  984. _curAutoRunCount = 0;
  985. gettimeofday(&_autoTime, NULL);
  986. }
  987. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  988. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  989. printf ("[UnconditionalCharge - S_CHARGING]\n");
  990. }
  991. if (_usingAutoRun == 0x01)
  992. {
  993. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  994. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  995. {
  996. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  997. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  998. }
  999. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  1000. {
  1001. _curAutoRunCount++;
  1002. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  1003. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1004. else
  1005. gettimeofday(&_autoTime, NULL);
  1006. }
  1007. else
  1008. {
  1009. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
  1010. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
  1011. }
  1012. }
  1013. // printf("out : vol = %f, cur = %f \n",
  1014. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  1015. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1016. //ev task do this
  1017. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  1018. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  1019. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02)
  1020. {
  1021. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1022. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1023. }
  1024. }
  1025. break;
  1026. case S_TERMINATING:
  1027. {
  1028. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1029. {
  1030. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1031. system("/root/Module_EvComm &");
  1032. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  1033. //無阻塞偵測 keybaord 結束
  1034. system(STTY_DEF TTY_PATH);
  1035. }
  1036. sleep(3);
  1037. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  1038. return;
  1039. }
  1040. break;
  1041. case S_COMPLETE:
  1042. {
  1043. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1044. {
  1045. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1046. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  1047. }
  1048. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
  1049. sleep(3);
  1050. return;
  1051. }
  1052. break;
  1053. }
  1054. char word[128];
  1055. char newString[7][10];
  1056. int i,j,ctr;
  1057. memset(word, 0x00, sizeof(word));
  1058. get_char(word);
  1059. if (strlen(word) == 0)
  1060. continue;
  1061. j=0; ctr=0;
  1062. strcpy(newString[1], "-1");
  1063. strcpy(newString[2], "-1");
  1064. for (i = 0; i <= (strlen(word)); i++)
  1065. {
  1066. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1067. {
  1068. newString[ctr][j] = '\0';
  1069. ctr++;
  1070. j = 0;
  1071. }
  1072. else
  1073. {
  1074. newString[ctr][j] = word[i];
  1075. j++;
  1076. }
  1077. }
  1078. if(strcmp(newString[0], "chg") == 0)
  1079. {
  1080. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1081. continue;
  1082. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1083. continue;
  1084. float _vol = atof(newString[1]);
  1085. float _cur = atof(newString[2]);
  1086. if (_cur <= 0 || _cur <= 0)
  1087. continue;
  1088. printf("vol = %f, cur = %f \n", _vol, _cur);
  1089. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  1090. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  1091. }
  1092. else if (strcmp(newString[0], "c") == 0)
  1093. {
  1094. printf("stop \n\r");
  1095. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  1096. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1097. }
  1098. usleep(100000);
  1099. }
  1100. }
  1101. int main(void)
  1102. {
  1103. if(InitShareMemory() == FAIL)
  1104. {
  1105. printf ("InitShareMemory = FAIL \n");
  1106. if(ShmStatusCodeData != NULL)
  1107. {
  1108. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1109. }
  1110. sleep(5);
  1111. return 0;
  1112. }
  1113. printf ("%s\n", msg);
  1114. for(;;)
  1115. {
  1116. char word[128];
  1117. char newString[7][10];
  1118. int i,j,ctr;
  1119. fgets(word, sizeof(word), stdin);
  1120. j=0; ctr=0;
  1121. strcpy(newString[1], "-1");
  1122. strcpy(newString[2], "-1");
  1123. for (i = 0; i <= (strlen(word)); i++)
  1124. {
  1125. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1126. {
  1127. newString[ctr][j] = '\0';
  1128. ctr++;
  1129. j = 0;
  1130. }
  1131. else
  1132. {
  1133. newString[ctr][j] = word[i];
  1134. j++;
  1135. }
  1136. }
  1137. if(strcmp(newString[0], "state") == 0)
  1138. {
  1139. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1140. continue;
  1141. // 槍狀態
  1142. RunStatusProc(newString[1], newString[2]);
  1143. }
  1144. else if(strcmp(newString[0], "card") == 0)
  1145. {
  1146. // 刷卡狀態
  1147. RunCardProc(newString[1], newString[2]);
  1148. }
  1149. else if(strcmp(newString[0], "gun") == 0)
  1150. {
  1151. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1152. continue;
  1153. // 插槍狀態
  1154. RunGunPlugitProc(newString[1], newString[2]);
  1155. }
  1156. else if(strcmp(newString[0], "lock") == 0)
  1157. {
  1158. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1159. continue;
  1160. // 插槍狀態
  1161. GetGunLockStatusProc(newString[1], newString[2]);
  1162. }
  1163. else if(strcmp(newString[0], "sysid") == 0)
  1164. {
  1165. // 測試 sys id
  1166. SetSystemIDProc();
  1167. }
  1168. else if(strcmp(newString[0], "self") == 0)
  1169. {
  1170. // CSU 自我檢測狀態
  1171. RunSelfProc(newString[1]);
  1172. }
  1173. else if(strcmp(newString[0], "ver") == 0)
  1174. {
  1175. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1176. continue;
  1177. // 取 FW 版號
  1178. GetFwVerProc(newString[1]);
  1179. }
  1180. else if (strcmp(newString[0], "update") == 0)
  1181. {
  1182. // 更新
  1183. FwUpdateFlagProc(newString[1]);
  1184. }
  1185. else if (strcmp(newString[0], "ac") == 0)
  1186. {
  1187. // AC contactor 狀態
  1188. CheckAcStatus(newString[1]);
  1189. }
  1190. else if (strcmp(newString[0], "cable") == 0)
  1191. {
  1192. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1193. continue;
  1194. // cable check pass
  1195. SetCableChkStatus(newString[1], newString[2]);
  1196. }
  1197. else if (strcmp(newString[0], "pow") == 0)
  1198. {
  1199. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1200. continue;
  1201. // cable check pass
  1202. SetPowerValue(newString[1], newString[2]);
  1203. }
  1204. else if (strcmp(newString[0], "model") == 0)
  1205. {
  1206. GetSystemInfo();
  1207. }
  1208. else if(strcmp(newString[0], "select") == 0)
  1209. {
  1210. // 取得 / 設定 當前選的槍號
  1211. GetGunSelectedNum(newString[1]);
  1212. }
  1213. else if(strcmp(newString[0], "change") == 0)
  1214. {
  1215. // 模擬按鈕改變選槍
  1216. ChangeGunNum();
  1217. }
  1218. else if(strcmp(newString[0], "fan") == 0)
  1219. {
  1220. // 設定風扇速度
  1221. SetFanSpeed(newString[1]);
  1222. }
  1223. else if(strcmp(newString[0], "speed") == 0)
  1224. {
  1225. // 取得風扇速度
  1226. GetFanSpeed();
  1227. }
  1228. else if(strcmp(newString[0], "debug") == 0)
  1229. {
  1230. // 設定 debug mode
  1231. SetDebugMode(newString[1]);
  1232. }
  1233. else if (strcmp(newString[0], "gfd") == 0)
  1234. {
  1235. // 設定盲沖使用 GFD 功能
  1236. SetGFDMode(newString[1]);
  1237. }
  1238. else if(strcmp(newString[0], "temp") == 0)
  1239. {
  1240. // 取得 PSU 溫度
  1241. GetPsuTemp();
  1242. }
  1243. else if(strcmp(newString[0], "acin") == 0)
  1244. {
  1245. // 取得三向輸入電壓
  1246. GetAcInputVol();
  1247. }
  1248. else if(strcmp(newString[0], "psu") == 0)
  1249. {
  1250. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1251. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1252. {
  1253. printf ("PSU : Param fail..Please retry again......\n");
  1254. continue;
  1255. }
  1256. // 取得 PSU 資訊
  1257. GetPsuInformation(newString[1], newString[2], newString[3]);
  1258. }
  1259. else if (strcmp(newString[0], "cap") == 0)
  1260. {
  1261. GetConnectorCapInfo(newString[1]);
  1262. }
  1263. else if(strcmp(newString[0], "error") == 0)
  1264. {
  1265. CreateOneError(newString[1]);
  1266. }
  1267. else if (strcmp(newString[0], "auth") == 0)
  1268. {
  1269. GetAuthorizeFlag(newString[1]);
  1270. }
  1271. else if (strcmp(newString[0], "relay") == 0)
  1272. {
  1273. GetRelayStatus(newString[1]);
  1274. }
  1275. else if (strcmp(newString[0], "ccid") == 0)
  1276. {
  1277. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1278. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1279. {
  1280. printf ("Input ccid fail.\n");
  1281. continue;
  1282. }
  1283. SetChargingInfoCCID(newString[1], newString[2]);
  1284. }
  1285. else if(strcmp(newString[0], "strchg") == 0)
  1286. {
  1287. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1288. if (strcmp(newString[1], "auto") == 0)
  1289. {
  1290. newString[2][0] = 0;
  1291. newString[3][0] = 0;
  1292. }
  1293. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1294. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1295. {
  1296. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1297. continue;
  1298. }
  1299. // 槍狀態
  1300. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1301. }
  1302. else
  1303. printf ("%s\n", msg);
  1304. usleep(100000);
  1305. }
  1306. return 0;
  1307. }