ReadCmdline.c 42 KB

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