ReadCmdline.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  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 YES 1
  45. #define NO 0
  46. #define AUTORUN_STEP1_TIME_START 140 // Minutes
  47. #define AUTORUN_STEP1_TIME_END 150
  48. #define AUTORUN_STEP2_TIME_START 210
  49. #define AUTORUN_STEP2_TIME_END 410
  50. #define AUTORUN_END_TIME 480
  51. #define AUTORUN_CYCLE_COUNT 30
  52. #define TTY_PATH "/dev/tty"
  53. #define STTY_US "stty raw -echo -F "
  54. #define STTY_DEF "stty -raw echo -F "
  55. byte _curAutoRunCount = 0;
  56. byte _usingAutoRun = 0;
  57. struct timeval _autoTime;
  58. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  59. struct StatusCodeData *ShmStatusCodeData;
  60. struct PrimaryMcuData *ShmPrimaryMcuData;
  61. struct CHAdeMOData *ShmCHAdeMOData;
  62. struct CcsData *ShmCcsData;
  63. struct GBTData *ShmGBTData;
  64. struct FanModuleData *ShmFanModuleData;
  65. struct RelayModuleData *ShmRelayModuleData;
  66. struct LedModuleData *ShmLedModuleData;
  67. struct PsuData *ShmPsuData;
  68. struct DcCommonInformation *ShmDcCommonData;
  69. struct OCPP16Data *ShmOCPP16Data;
  70. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  71. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  72. char *msg = "state : get gun state (index) \n"
  73. "card : scanning card (x) : \n"
  74. "gun : get gun plugit state (index) \n"
  75. "lock : get gun locked state (index) \n"
  76. "self : self test state (x) \n"
  77. "ver : ver of board (407 or index or rb or fan) \n"
  78. "ac : get ac relay state (x) \n";
  79. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  80. {
  81. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  82. {
  83. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  84. {
  85. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  86. return true;
  87. }
  88. }
  89. for (byte index = 0; index < CCS_QUANTITY; index++)
  90. {
  91. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  92. {
  93. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  94. return true;
  95. }
  96. }
  97. for (byte index = 0; index < GB_QUANTITY; index++)
  98. {
  99. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  100. {
  101. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  108. {
  109. if (target < AC_QUANTITY)
  110. {
  111. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  112. return true;
  113. }
  114. return false;
  115. }
  116. int InitShareMemory()
  117. {
  118. int result = PASS;
  119. int MeterSMId;
  120. //initial ShmSysConfigAndInfo
  121. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  122. {
  123. result = FAIL;
  124. }
  125. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  126. {
  127. result = FAIL;
  128. }
  129. //initial ShmStatusCodeData
  130. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  131. {
  132. result = FAIL;
  133. }
  134. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  135. {
  136. result = FAIL;
  137. }
  138. if (CHAdeMO_QUANTITY > 0) {
  139. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  140. IPC_CREAT | 0777)) < 0) {
  141. result = FAIL;
  142. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  143. == (void *) -1) {
  144. result = FAIL;
  145. } else {
  146. }
  147. }
  148. if (CCS_QUANTITY > 0) {
  149. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  150. IPC_CREAT | 0777)) < 0) {
  151. result = FAIL;
  152. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  153. result = FAIL;
  154. } else {
  155. }
  156. }
  157. if (GB_QUANTITY > 0) {
  158. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  159. IPC_CREAT | 0777)) < 0) {
  160. return 0;
  161. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  162. return 0;
  163. }
  164. }
  165. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  166. {
  167. result = FAIL;
  168. }
  169. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  170. {
  171. result = FAIL;
  172. }
  173. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  174. {
  175. result = FAIL;
  176. }
  177. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  178. {
  179. result = FAIL;
  180. }
  181. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  182. {
  183. result = FAIL;
  184. }
  185. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  186. {
  187. result = FAIL;
  188. }
  189. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  190. {
  191. result = FAIL;
  192. }
  193. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  194. {
  195. result = FAIL;
  196. }
  197. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  198. {
  199. result = FAIL;
  200. }
  201. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  202. {
  203. result = FAIL;
  204. }
  205. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  206. {
  207. result = FAIL;
  208. }
  209. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  210. {
  211. result = FAIL;
  212. }
  213. if ((MeterSMId = shmget(ShmCommonKey, sizeof(struct DcCommonInformation), IPC_CREAT | 0777)) < 0)
  214. {
  215. result = FAIL;
  216. }
  217. else if ((ShmDcCommonData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  218. {
  219. result = FAIL;
  220. }
  221. return result;
  222. }
  223. unsigned long GetTimeoutValue(struct timeval _sour_time)
  224. {
  225. struct timeval _end_time;
  226. gettimeofday(&_end_time, NULL);
  227. return (_end_time.tv_sec - _sour_time.tv_sec);
  228. }
  229. void RunStatusProc(char *v1, char *v2)
  230. {
  231. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  232. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  233. if (strcmp(v1, "ac") == 0)
  234. {
  235. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  236. {
  237. printf("FindChargingInfoData (AC) false \n");
  238. }
  239. printf("AC Status = %d \n", ac_chargingInfo[0]->SystemStatus);
  240. printf("AC ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  241. return;
  242. }
  243. int _index = atoi(v1);
  244. if (_index <= 1)
  245. {
  246. if (!FindChargingInfoData(_index, &_chargingData[0]))
  247. {
  248. printf ("FindChargingInfoData error\n");
  249. return;
  250. }
  251. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  252. {
  253. // get
  254. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  255. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  256. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  257. printf ("SOC = %d \n", _chargingData[_index]->EvBatterySoc);
  258. printf ("Maximum battery Voltage = %f \n", _chargingData[_index]->EvBatteryMaxVoltage);
  259. printf("Charging mode = %d \n", ShmSysConfigAndInfo->SysInfo.MainChargingMode);
  260. printf("maxTemp = %d, temp-I = %d, temp-II = %d \n",
  261. _chargingData[_index]->ConnectorTemp - 60,
  262. ShmDcCommonData->ConnectorTemp1[_index] - 60,
  263. ShmDcCommonData->ConnectorTemp2[_index] - 60);
  264. }
  265. else
  266. {
  267. // set
  268. _chargingData[_index]->SystemStatus = atoi(v2);
  269. }
  270. }
  271. else
  272. {
  273. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  274. {
  275. printf("FindChargingInfoData (AC) false \n");
  276. }
  277. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  278. {
  279. // get
  280. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  281. }
  282. else
  283. {
  284. // set
  285. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  286. }
  287. }
  288. }
  289. void RunCardProc(char *v1, char *v2)
  290. {
  291. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  292. {
  293. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  294. {
  295. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  296. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  297. }
  298. else
  299. {
  300. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  301. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  302. }
  303. }
  304. else
  305. {
  306. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  307. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  308. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  309. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  310. }
  311. }
  312. void RunGunPlugitProc(char *v1, char *v2)
  313. {
  314. if (strcmp(v1, "ac") == 0)
  315. {
  316. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  317. {
  318. printf("FindChargingInfoData (AC) false \n");
  319. }
  320. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  321. {
  322. // get
  323. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  324. }
  325. else
  326. {
  327. // set
  328. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  329. }
  330. return;
  331. }
  332. int _index = atoi(v1);
  333. if (!FindChargingInfoData(_index, &_chargingData[0]))
  334. {
  335. printf("FindChargingInfoData error\n");
  336. return;
  337. }
  338. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  339. {
  340. // get
  341. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  342. }
  343. else
  344. {
  345. // set
  346. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  347. }
  348. }
  349. void GetGunLockStatusProc(char *v1, char *v2)
  350. {
  351. int _index = atoi(v1);
  352. if (!FindChargingInfoData(_index, &_chargingData[0]))
  353. {
  354. printf("FindChargingInfoData error\n");
  355. return;
  356. }
  357. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  358. {
  359. _chargingData[_index]->GunLocked = atoi(v2);
  360. }
  361. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  362. }
  363. void SetSystemIDProc()
  364. {
  365. char *systemId = "Alston_Test";
  366. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  367. }
  368. void RunSelfProc()
  369. {
  370. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  371. }
  372. void GetFwVerProc(char *v1)
  373. {
  374. if (strcmp(v1, "407") == 0)
  375. {
  376. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  377. }
  378. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0)
  379. {
  380. int _index = atoi(v1);
  381. if (_index == 0)
  382. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  383. else if (_index == 1)
  384. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  385. }
  386. else if (strcmp(v1, "rb") == 0)
  387. {
  388. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  389. }
  390. else if (strcmp(v1, "fan") == 0)
  391. {
  392. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  393. }
  394. else if (strcmp(v1, "dc") == 0)
  395. {
  396. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  397. }
  398. else if (strcmp(v1, "led") == 0)
  399. {
  400. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  401. }
  402. else if (strcmp(v1, "ac") == 0)
  403. {
  404. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  405. {
  406. printf("FindChargingInfoData (AC) false \n");
  407. }
  408. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  409. }
  410. else if (strcmp(v1, "all") == 0)
  411. {
  412. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  413. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  414. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  415. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  416. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  417. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  418. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  419. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  420. {
  421. printf("FindChargingInfoData (AC) false \n");
  422. }
  423. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  424. }
  425. }
  426. void CreateOneError()
  427. {
  428. for (byte i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  429. {
  430. printf("(%d). %s \n", i, &ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  431. }
  432. }
  433. void GetAuthorizeFlag(char *v1)
  434. {
  435. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  436. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  437. else
  438. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  439. }
  440. void GetRelayStatus(char *v1)
  441. {
  442. int _index = atoi(v1);
  443. if (!FindChargingInfoData(_index, &_chargingData[0]))
  444. {
  445. printf("FindChargingInfoData error\n");
  446. return;
  447. }
  448. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  449. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  450. }
  451. void GetSOC(char *v1)
  452. {
  453. int _index = atoi(v1);
  454. if (!FindChargingInfoData(_index, &_chargingData[0]))
  455. {
  456. printf("FindChargingInfoData error\n");
  457. return;
  458. }
  459. printf("Soc = %d \n", _chargingData[_index]->EvBatterySoc);
  460. }
  461. void FwUpdateFlagProc()
  462. {
  463. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  464. }
  465. void CheckAcStatus(char *v1)
  466. {
  467. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  468. {
  469. printf("AC 1Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  470. printf("AC 2Status = %d \n", ShmPrimaryMcuData->InputDet.bits.AcContactorDetec);
  471. printf("AC 3Status = %d \n", ShmDcCommonData->psuKeepCommunication);
  472. printf("AC EmergencyButton = %d \n", ShmPrimaryMcuData->InputDet.bits.EmergencyButton);
  473. printf("AC acContactSwitch = %d \n", ShmDcCommonData->acContactSwitch);
  474. }
  475. else
  476. ShmSysConfigAndInfo->SysInfo.AcContactorStatus = atoi(v1);
  477. }
  478. void SetCableChkStatus(char *v1, char *v2)
  479. {
  480. int _index = atoi(v1);
  481. if (!FindChargingInfoData(_index, &_chargingData[0]))
  482. {
  483. printf ("FindChargingInfoData error\n");
  484. return;
  485. }
  486. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  487. }
  488. void SetChargingInfoCCID(char *v1, char* v2)
  489. {
  490. int _index = atoi(v1);
  491. if (!FindChargingInfoData(_index, &_chargingData[0]))
  492. {
  493. printf ("FindChargingInfoData error\n");
  494. return;
  495. }
  496. memcpy(_chargingData[_index]->EVCCID, v2, strlen(v2));
  497. _chargingData[_index]->EVCCID[strlen(v2)] = '\0';
  498. }
  499. void GetGunTemp(char *v1)
  500. {
  501. int _index = atoi(v1);
  502. if (!FindChargingInfoData(_index, &_chargingData[0]))
  503. {
  504. printf ("FindChargingInfoData error\n");
  505. return;
  506. }
  507. printf("Gun_%d, maxTemp = %d, temp 1 = %d, temp 2 = %d \n",
  508. _index,
  509. _chargingData[_index]->ConnectorTemp - 60,
  510. ShmDcCommonData->ConnectorTemp1[_index] - 60,
  511. ShmDcCommonData->ConnectorTemp2[_index] - 60);
  512. }
  513. void GetOffered(char *v1)
  514. {
  515. int _index = atoi(v1);
  516. if (!FindChargingInfoData(_index, &_chargingData[0]))
  517. {
  518. printf ("FindChargingInfoData error\n");
  519. return;
  520. }
  521. printf("Gun_%d, PowerOffered = %f, CurrentOffered = %f \n",
  522. _index,
  523. _chargingData[_index]->PowerOffered,
  524. _chargingData[_index]->CurrentOffered);
  525. }
  526. void GetEvStatus(char *v1)
  527. {
  528. int _index = atoi(v1);
  529. if (!FindChargingInfoData(_index, &_chargingData[0]))
  530. {
  531. printf ("FindChargingInfoData error\n");
  532. return;
  533. }
  534. if (_chargingData[_index]->Type == _Type_Chademo)
  535. printf ("Chademo status= %d \n", ShmCHAdeMOData->evse[_chargingData[_index]->type_index].EvboardStatus);
  536. else if (_chargingData[_index]->Type == _Type_CCS)
  537. printf ("CCS status= %d \n", ShmCcsData->V2GMessage_DIN70121[_chargingData[_index]->type_index].PresentMsgFlowStatus);
  538. else if (_chargingData[_index]->Type == _Type_GB)
  539. printf ("GBT status = %d \n", ShmGBTData->evse[_chargingData[_index]->type_index].EvboardStatus);
  540. }
  541. void GetDcMeterInfor(char *v1)
  542. {
  543. int _index = atoi(v1);
  544. if (!FindChargingInfoData(_index, &_chargingData[0]))
  545. {
  546. printf ("FindChargingInfoData error\n");
  547. return;
  548. }
  549. printf("Index = %d, LinkStatus = %d presetVoltage = %f, presentCurrent = %f, presentPower = %f, totlizeImportEnergy = %f, totlizeExportEnergy = %f \n",
  550. _index,
  551. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].LinkStatus,
  552. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presetVoltage,
  553. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentCurrent,
  554. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].presentPower,
  555. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeImportEnergy,
  556. ShmSysConfigAndInfo->SysInfo.DcMeterInfo[_index].totlizeExportEnergy);
  557. }
  558. void GetPowerValue()
  559. {
  560. for (byte index = 0; index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; index++)
  561. {
  562. if (!FindChargingInfoData(index, &_chargingData[0]))
  563. {
  564. printf ("FindChargingInfoData error\n");
  565. return;
  566. }
  567. printf ("index = %d, PresentChargingPower = %f \n", index, _chargingData[index]->PresentChargingPower);
  568. }
  569. }
  570. void GetSystemInfo()
  571. {
  572. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  573. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  574. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  575. printf ("PSU : MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  576. ShmPsuData->SystemAvailablePower / 10,
  577. ShmPsuData->SystemAvailableCurrent / 10
  578. );
  579. printf ("Config : ChargingPower = %d, ChargingCurrent = %d \n",
  580. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  581. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  582. }
  583. void ChangeGunNum()
  584. {
  585. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  586. {
  587. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  588. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  589. }
  590. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  591. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  592. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  593. else
  594. {
  595. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  596. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  597. }
  598. }
  599. void GetGunSelectedNum(char *v1)
  600. {
  601. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  602. {
  603. if (AC_QUANTITY > 0 &&
  604. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  605. {
  606. printf("connector select changed = AC \n");
  607. }
  608. else
  609. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  610. }
  611. else
  612. {
  613. int _index = atoi(v1);
  614. if (_index <= 1)
  615. {
  616. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  617. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  618. printf("connector select changed = %d \n", _index);
  619. }
  620. else if (AC_QUANTITY > 0)
  621. {
  622. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  623. printf("connector select changed = AC \n");
  624. }
  625. }
  626. }
  627. void SetFanSpeed(char *v1)
  628. {
  629. int speed = atoi(v1);
  630. ShmFanModuleData->TestFanSpeed = speed;
  631. }
  632. void ShowSysInformation()
  633. {
  634. if (!ShmSysConfigAndInfo->SysConfig.ShowInformation)
  635. ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x01;
  636. else
  637. ShmSysConfigAndInfo->SysConfig.ShowInformation = 0x00;
  638. printf("Show inform = %d \n", ShmSysConfigAndInfo->SysConfig.ShowInformation);
  639. }
  640. void GetFanSpeed()
  641. {
  642. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  643. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  644. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  645. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  646. }
  647. void SetDebugMode(char *v1)
  648. {
  649. int mode = atoi(v1);
  650. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  651. }
  652. void SetGFDMode(char *v1)
  653. {
  654. int mode = atoi(v1);
  655. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  656. }
  657. void GetPsuTemp()
  658. {
  659. char _ex_maxTemp = 0;
  660. char _cr_maxTemp = 0;
  661. for (byte index = 0; index < ShmPsuData->GroupCount; index++)
  662. {
  663. _ex_maxTemp = 0;
  664. _cr_maxTemp = 0;
  665. for (byte count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++)
  666. {
  667. if (ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp > _ex_maxTemp)
  668. _ex_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp;
  669. if (ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1 > _cr_maxTemp)
  670. _cr_maxTemp = ShmPsuData->PsuGroup[index].PsuModule[count].CriticalTemp1;
  671. }
  672. printf("D.D. Temp = %d ------ Env Temp = %d \n", _ex_maxTemp, _cr_maxTemp);
  673. }
  674. }
  675. void GetAcInputVol()
  676. {
  677. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  678. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  679. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  680. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  681. }
  682. void GetPsuInformation(char *v1, char *v2, char *v3)
  683. {
  684. printf("**********************AC Contact needed*************************\n");
  685. if(strcmp(v1, "count") == 0)
  686. {
  687. for (int i = 0; i < 4; i++)
  688. {
  689. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  690. }
  691. }
  692. else if(strcmp(v1, "ver") == 0)
  693. {
  694. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  695. {
  696. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  697. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  698. }
  699. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  700. {
  701. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  702. {
  703. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  704. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  705. }
  706. }
  707. }
  708. else if(strcmp(v1, "cap") == 0)
  709. {
  710. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  711. {
  712. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  713. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  714. }
  715. }
  716. else if(strcmp(v1, "input") == 0)
  717. {
  718. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  719. {
  720. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  721. {
  722. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  723. i, count,
  724. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  725. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  726. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  727. }
  728. }
  729. }
  730. else if (strcmp(v1, "output") == 0)
  731. {
  732. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  733. {
  734. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  735. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  736. }
  737. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++)
  738. {
  739. if (!FindChargingInfoData(i, &_chargingData[0]))
  740. {
  741. printf ("FindChargingInfoData error\n");
  742. continue;
  743. }
  744. printf("From RB : Group Index = %d, OutputV = %f \n",
  745. i, _chargingData[i]->FireChargingVoltage);
  746. }
  747. }
  748. else if (strcmp(v1, "test") == 0)
  749. {
  750. int mode = atoi(v2);
  751. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  752. {
  753. ShmPsuData->Work_Step = mode;
  754. }
  755. }
  756. else if (strcmp(v1, "out") == 0)
  757. {
  758. float vol = atof(v2);
  759. float cur = atof(v3);
  760. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  761. {
  762. if (!FindChargingInfoData(0, &_chargingData[0]))
  763. {
  764. printf ("FindChargingInfoData error\n");
  765. return;
  766. }
  767. _chargingData[0]->EvBatterytargetVoltage = vol;
  768. _chargingData[0]->EvBatterytargetCurrent = cur;
  769. }
  770. }
  771. printf("*************************************************\n");
  772. }
  773. void GetConnectorCapInfo(char *v1)
  774. {
  775. int _GunIndex = atoi(v1);
  776. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  777. {
  778. printf ("FindChargingInfoData error\n");
  779. return;
  780. }
  781. printf ("Charger Max Current = %d, Max Power = %d \n",
  782. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  783. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  784. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  785. _GunIndex,
  786. _chargingData[_GunIndex]->RealMaxPower,
  787. _chargingData[_GunIndex]->RealMaxVoltage,
  788. _chargingData[_GunIndex]->RealMaxCurrent);
  789. }
  790. static void get_char(char *word)
  791. {
  792. fd_set rfds;
  793. struct timeval tv;
  794. FD_ZERO(&rfds);
  795. FD_SET(0, &rfds);
  796. tv.tv_sec = 0;
  797. tv.tv_usec = 10; //wait input timout time
  798. //if input
  799. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  800. {
  801. fgets(word, 128, stdin);
  802. }
  803. }
  804. void AverageCharging(char *g1_vol, char *g1_cur, char *g2_vol, char *g2_cur)
  805. {
  806. float _Voltage[2];
  807. float _Current[2];
  808. _Voltage[0] = atof(g1_vol);
  809. _Current[0] = atof(g1_cur);
  810. _Voltage[1] = atof(g2_vol);
  811. _Current[1] = atof(g2_cur);
  812. printf ("g1_vol = %f, g1_cur = %f pow1 = %f (KW) \n", _Voltage[0], _Current[0], (_Voltage[0] * _Current[0]) / 1000);
  813. printf ("g2_vol = %f, g2_cur = %f pow2 = %f (KW) \n", _Voltage[1], _Current[1], (_Voltage[1] * _Current[1]) / 1000);
  814. if(_Voltage[0] > 1000 || _Voltage[0] < 50 ||
  815. _Voltage[1] > 1000 || _Voltage[1] < 50)
  816. {
  817. printf ("Input Voltage over range\n");
  818. return;
  819. }
  820. for (byte _index = 0; _index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; _index++)
  821. {
  822. if (!FindChargingInfoData(_index, &_chargingData[0]))
  823. {
  824. printf("AverageCharging : FindChargingInfoData false \n");
  825. return;
  826. }
  827. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  828. _chargingData[_index]->Type = 9;
  829. }
  830. sleep(1);
  831. system("killall Module_EvComm");
  832. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  833. bool isComplete[2] = {false, false};
  834. while(1)
  835. {
  836. for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
  837. {
  838. switch(_chargingData[gun_index]->SystemStatus)
  839. {
  840. case SYS_MODE_IDLE:
  841. {
  842. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  843. {
  844. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  845. printf ("[AverageCharging (%d) - SYS_MODE_IDLE] \n", gun_index);
  846. }
  847. ShmDcCommonData->StartToChargingFlag[gun_index] = 0x01;
  848. _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARING;
  849. }
  850. break;
  851. case SYS_MODE_PREPARING:
  852. {
  853. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  854. {
  855. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  856. printf ("[AverageCharging (%d) - S_PREPARNIN] \n", gun_index);
  857. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  858. printf ("wait find module\n");
  859. }
  860. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  861. //清除 main timeout 機制
  862. _chargingData[gun_index]->TimeoutFlag = 0;
  863. }
  864. break;
  865. case SYS_MODE_PREPARE_FOR_EV:
  866. {
  867. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  868. {
  869. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  870. printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EV] \n", gun_index);
  871. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[gun_index] * 10, _Current[gun_index] * 10);
  872. }
  873. //清除 main timeout 機制
  874. _chargingData[gun_index]->TimeoutFlag = 0;
  875. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  876. _chargingData[gun_index]->Type = 9;
  877. //充電電壓電流
  878. _chargingData[gun_index]->EvBatterySoc = 50;
  879. _chargingData[gun_index]->EvBatterytargetVoltage = 500;
  880. _chargingData[gun_index]->EvBatterytargetCurrent = 2;
  881. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  882. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  883. //確定模組己升壓完成
  884. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  885. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  886. {
  887. printf ("Preparing Done = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
  888. //EV done
  889. _chargingData[gun_index]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
  890. }
  891. }
  892. break;
  893. case SYS_MODE_PREPARE_FOR_EVSE:
  894. {
  895. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  896. {
  897. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  898. printf ("[AverageCharging (%d) - SYS_MODE_PREPARE_FOR_EVSE]\n", gun_index);
  899. }
  900. //printf ("tar vol = %d \n", _Voltage);
  901. //printf ("tar cur = %d \n", _Current);
  902. //清除 main timeout 機制
  903. _chargingData[gun_index]->TimeoutFlag = 0;
  904. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  905. _chargingData[gun_index]->Type = 9;
  906. //充電電壓電流
  907. _chargingData[gun_index]->EvBatterySoc = 50;
  908. _chargingData[gun_index]->EvBatterytargetVoltage = 500;
  909. _chargingData[gun_index]->EvBatterytargetCurrent = 2;
  910. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  911. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  912. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  913. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  914. //確定模組己升壓完成
  915. if(_chargingData[gun_index]->GroundFaultStatus == 0x01 ||
  916. _chargingData[gun_index]->GroundFaultStatus == 0x03)
  917. {
  918. printf ("First Ground Fault State (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  919. printf ("Wait K1K2 = %f \n", _chargingData[gun_index]->PresentChargingVoltage);
  920. sleep(5);
  921. //EV done
  922. _chargingData[gun_index]->SystemStatus = SYS_MODE_CHARGING;
  923. }
  924. else if (_chargingData[gun_index]->GroundFaultStatus > 0x02)
  925. {
  926. printf ("First Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  927. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  928. }
  929. }
  930. break;
  931. case SYS_MODE_CHARGING:
  932. {
  933. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  934. {
  935. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  936. //充電電壓電流
  937. _chargingData[gun_index]->EvBatterytargetVoltage = _Voltage[gun_index];
  938. _chargingData[gun_index]->EvBatterytargetCurrent = _Current[gun_index];
  939. _chargingData[gun_index]->EvBatterySoc = 50;
  940. _chargingData[gun_index]->AvailableChargingCurrent = 1000;
  941. printf ("[AverageCharging (%d) - SYS_MODE_CHARGING]\n", gun_index);
  942. }
  943. //ev task do this
  944. _chargingData[gun_index]->PresentChargingPower =
  945. ((float)((_chargingData[gun_index]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  946. if (_chargingData[gun_index]->GroundFaultStatus == 0x02)
  947. {
  948. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[gun_index]->GroundFaultStatus);
  949. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  950. }
  951. }
  952. break;
  953. case SYS_MODE_TERMINATING:
  954. {
  955. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  956. {
  957. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  958. printf ("[AverageCharging (%d) - SYS_MODE_TERMINATING] \n", gun_index);
  959. //無阻塞偵測 keybaord 結束
  960. system(STTY_DEF TTY_PATH);
  961. }
  962. sleep(3);
  963. _chargingData[gun_index]->SystemStatus = SYS_MODE_COMPLETE;
  964. }
  965. break;
  966. case SYS_MODE_COMPLETE:
  967. {
  968. if(PreviousSystemStatus[gun_index] != _chargingData[gun_index]->SystemStatus)
  969. {
  970. PreviousSystemStatus[gun_index] = _chargingData[gun_index]->SystemStatus;
  971. printf ("[AverageCharging (%d) - SYS_MODE_COMPLETE] \n", gun_index);
  972. }
  973. _chargingData[gun_index]->PresentChargingPower = 0;
  974. isComplete[gun_index] = true;
  975. sleep(3);
  976. }
  977. break;
  978. }
  979. }
  980. if (isComplete[0] == true && isComplete[1] == true)
  981. return;
  982. char word[128];
  983. char newString[7][10];
  984. int i,j,ctr;
  985. memset(word, 0x00, sizeof(word));
  986. get_char(word);
  987. if (strlen(word) == 0)
  988. continue;
  989. j=0; ctr=0;
  990. strcpy(newString[1], "-1");
  991. strcpy(newString[2], "-1");
  992. for (i = 0; i <= (strlen(word)); i++)
  993. {
  994. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  995. {
  996. newString[ctr][j] = '\0';
  997. ctr++;
  998. j = 0;
  999. }
  1000. else
  1001. {
  1002. newString[ctr][j] = word[i];
  1003. j++;
  1004. }
  1005. }
  1006. if (strcmp(newString[0], "c") == 0)
  1007. {
  1008. for (byte gun_index = 0; gun_index < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; gun_index++)
  1009. {
  1010. ShmDcCommonData->StartToChargingFlag[gun_index] = 0x00;
  1011. _chargingData[gun_index]->SystemStatus = SYS_MODE_TERMINATING;
  1012. }
  1013. printf("stop \n\r");
  1014. }
  1015. usleep(100000);
  1016. }
  1017. }
  1018. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  1019. {
  1020. int _GunIndex;
  1021. float _Voltage;
  1022. float _Current;
  1023. if (strcmp(v1, "auto") == EQUAL)
  1024. {
  1025. _usingAutoRun = 0x01;
  1026. _GunIndex = atoi(v2);
  1027. _Voltage = 500;
  1028. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  1029. }
  1030. else
  1031. {
  1032. _usingAutoRun = 0x00;
  1033. _GunIndex = atoi(v1);
  1034. _Voltage = atof(v2);
  1035. _Current = atof(v3);
  1036. }
  1037. unsigned char PreviousSystemStatus = 0xff;
  1038. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1039. {
  1040. printf ("FindChargingInfoData error\n");
  1041. return;
  1042. }
  1043. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  1044. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  1045. if(_Voltage > 1000 || _Voltage < 50)
  1046. {
  1047. printf ("Input Voltage over range\n");
  1048. return;
  1049. }
  1050. // if(_Current > 100 || _Current < 2){
  1051. //
  1052. // printf ("Input Current over range\n");
  1053. // return;
  1054. // }
  1055. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1056. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1057. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1058. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1059. sleep(1);
  1060. //kill ev task
  1061. system("killall Module_EvComm");
  1062. //_Voltage = (_Voltage * 10);
  1063. //_Current = (_Current * 10);
  1064. //system(STTY_US TTY_PATH);
  1065. while(true)
  1066. {
  1067. //fix gun 1
  1068. switch(_chargingData[_GunIndex]->SystemStatus)
  1069. {
  1070. case SYS_MODE_IDLE:
  1071. {
  1072. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1073. {
  1074. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1075. printf ("[UnconditionalCharge - SYS_MODE_IDLE]\n");
  1076. }
  1077. ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x01;
  1078. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARING;
  1079. }
  1080. break;
  1081. case SYS_MODE_PREPARING:
  1082. {
  1083. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1084. {
  1085. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1086. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1087. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1088. printf ("wait find module\n");
  1089. }
  1090. //main 會在此階段判斷以下資料跳到下一個 state
  1091. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1092. //ShmPsuData->SystemPresentPsuQuantity;
  1093. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1094. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1095. //_chargingData[gun_index]->AvailableChargingPower;
  1096. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1097. //sleep(10);
  1098. //清除 main timeout 機制
  1099. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1100. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1101. _chargingData[_GunIndex]->Type = 9;
  1102. }
  1103. break;
  1104. case SYS_MODE_PREPARE_FOR_EV:
  1105. {
  1106. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1107. {
  1108. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1109. printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EV]\n");
  1110. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1111. }
  1112. //清除 main timeout 機制
  1113. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1114. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1115. _chargingData[_GunIndex]->Type = 9;
  1116. //充電電壓電流
  1117. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1118. _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
  1119. _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
  1120. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1121. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1122. //確定模組己升壓完成
  1123. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1124. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1125. {
  1126. printf ("Precharge Done = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
  1127. //EV done
  1128. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_PREPARE_FOR_EVSE;
  1129. }
  1130. }
  1131. break;
  1132. case SYS_MODE_PREPARE_FOR_EVSE:
  1133. {
  1134. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1135. {
  1136. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1137. printf ("[UnconditionalCharge - SYS_MODE_PREPARE_FOR_EVSE]\n");
  1138. }
  1139. //printf ("tar vol = %d \n", _Voltage);
  1140. //printf ("tar cur = %d \n", _Current);
  1141. //清除 main timeout 機制
  1142. _chargingData[_GunIndex]->TimeoutFlag = 0;
  1143. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1144. _chargingData[_GunIndex]->Type = 9;
  1145. //充電電壓電流
  1146. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1147. _chargingData[_GunIndex]->EvBatterytargetVoltage = 500;
  1148. _chargingData[_GunIndex]->EvBatterytargetCurrent = 2;
  1149. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1150. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1151. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1152. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1153. //確定模組己升壓完成
  1154. //#define GFD_WAIT 0
  1155. //#define GFD_PASS 1
  1156. //#define GFD_FAIL 2
  1157. //#define GFD_WARNING 3
  1158. if(_chargingData[_GunIndex]->GroundFaultStatus == 0x01 ||
  1159. _chargingData[_GunIndex]->GroundFaultStatus == 0x03)
  1160. {
  1161. printf ("First Ground Fault State (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1162. printf ("Wait K1K2 = %f \n", _chargingData[_GunIndex]->PresentChargingVoltage);
  1163. sleep(5);
  1164. //EV done
  1165. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_CHARGING;
  1166. }
  1167. else if (_chargingData[_GunIndex]->GroundFaultStatus > 0x02)
  1168. {
  1169. printf ("First Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1170. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1171. }
  1172. }
  1173. break;
  1174. case SYS_MODE_CHARGING:
  1175. {
  1176. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1177. {
  1178. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1179. if (_usingAutoRun == 0x00)
  1180. {
  1181. //充電電壓電流
  1182. _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
  1183. _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
  1184. }
  1185. else
  1186. {
  1187. _curAutoRunCount = 0;
  1188. gettimeofday(&_autoTime, NULL);
  1189. }
  1190. _chargingData[_GunIndex]->EvBatterySoc = 50;
  1191. _chargingData[_GunIndex]->AvailableChargingCurrent = 1000;
  1192. printf ("[UnconditionalCharge - SYS_MODE_CHARGING]\n");
  1193. }
  1194. if (_usingAutoRun == 0x01)
  1195. {
  1196. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  1197. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60))
  1198. {
  1199. _chargingData[_GunIndex]->EvBatterytargetVoltage = _Voltage;
  1200. _chargingData[_GunIndex]->EvBatterytargetCurrent = _Current;
  1201. }
  1202. else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60)
  1203. {
  1204. _curAutoRunCount++;
  1205. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT)
  1206. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1207. else
  1208. gettimeofday(&_autoTime, NULL);
  1209. }
  1210. else
  1211. {
  1212. _chargingData[_GunIndex]->EvBatterytargetVoltage = 0;
  1213. _chargingData[_GunIndex]->EvBatterytargetCurrent = 0;
  1214. }
  1215. }
  1216. // printf("out : vol = %f, cur = %f \n",
  1217. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  1218. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1219. //ev task do this
  1220. _chargingData[_GunIndex]->PresentChargingPower =
  1221. ((float)((_chargingData[_GunIndex]->PresentChargingVoltage) * (_chargingData[_GunIndex]->PresentChargingCurrent)) / 1000);
  1222. if (_chargingData[_GunIndex]->GroundFaultStatus == 0x02){
  1223. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[_GunIndex]->GroundFaultStatus);
  1224. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1225. }
  1226. }
  1227. break;
  1228. case SYS_MODE_TERMINATING:
  1229. {
  1230. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1231. {
  1232. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1233. system("/root/Module_EvComm &");
  1234. printf ("[UnconditionalCharge - SYS_MODE_TERMINATING]\n");
  1235. //無阻塞偵測 keybaord 結束
  1236. system(STTY_DEF TTY_PATH);
  1237. }
  1238. sleep(3);
  1239. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_COMPLETE;
  1240. return;
  1241. }
  1242. break;
  1243. case SYS_MODE_COMPLETE:
  1244. {
  1245. if(PreviousSystemStatus != _chargingData[_GunIndex]->SystemStatus)
  1246. {
  1247. PreviousSystemStatus = _chargingData[_GunIndex]->SystemStatus;
  1248. printf ("[UnconditionalCharge - SYS_MODE_COMPLETE]\n");
  1249. }
  1250. _chargingData[_GunIndex]->PresentChargingPower = 0;
  1251. sleep(3);
  1252. return;
  1253. }
  1254. break;
  1255. }
  1256. char word[128];
  1257. char newString[7][10];
  1258. int i,j,ctr;
  1259. memset(word, 0x00, sizeof(word));
  1260. get_char(word);
  1261. if (strlen(word) == 0)
  1262. continue;
  1263. j=0; ctr=0;
  1264. strcpy(newString[1], "-1");
  1265. strcpy(newString[2], "-1");
  1266. for (i = 0; i <= (strlen(word)); i++)
  1267. {
  1268. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1269. {
  1270. newString[ctr][j] = '\0';
  1271. ctr++;
  1272. j = 0;
  1273. }
  1274. else
  1275. {
  1276. newString[ctr][j] = word[i];
  1277. j++;
  1278. }
  1279. }
  1280. if(strcmp(newString[0], "chg") == 0)
  1281. {
  1282. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1283. continue;
  1284. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1285. continue;
  1286. float _vol = atof(newString[1]);
  1287. float _cur = atof(newString[2]);
  1288. if (_cur <= 0 || _cur <= 0)
  1289. continue;
  1290. printf("vol = %f, cur = %f \n", _vol, _cur);
  1291. _chargingData[_GunIndex]->EvBatterytargetVoltage = _vol;
  1292. _chargingData[_GunIndex]->EvBatterytargetCurrent = _cur;
  1293. }
  1294. else if (strcmp(newString[0], "c") == 0)
  1295. {
  1296. printf("stop \n\r");
  1297. ShmDcCommonData->StartToChargingFlag[_GunIndex] = 0x00;
  1298. _chargingData[_GunIndex]->SystemStatus = SYS_MODE_TERMINATING;
  1299. }
  1300. usleep(100000);
  1301. }
  1302. }
  1303. int main(void)
  1304. {
  1305. if(InitShareMemory() == FAIL)
  1306. {
  1307. printf ("InitShareMemory = FAIL \n");
  1308. if(ShmStatusCodeData != NULL)
  1309. {
  1310. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  1311. }
  1312. sleep(5);
  1313. return 0;
  1314. }
  1315. for(;;)
  1316. {
  1317. char word[128];
  1318. char newString[7][10];
  1319. int i,j,ctr;
  1320. fgets(word, sizeof(word), stdin);
  1321. j=0; ctr=0;
  1322. strcpy(newString[1], "-1");
  1323. strcpy(newString[2], "-1");
  1324. for (i = 0; i <= (strlen(word)); i++)
  1325. {
  1326. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1327. {
  1328. newString[ctr][j] = '\0';
  1329. ctr++;
  1330. j = 0;
  1331. }
  1332. else
  1333. {
  1334. newString[ctr][j] = word[i];
  1335. j++;
  1336. }
  1337. }
  1338. if(strcmp(newString[0], "state") == 0 || strcmp(newString[0], "st") == 0)
  1339. {
  1340. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1341. continue;
  1342. // 槍狀態
  1343. printf("=========================== \n");
  1344. RunStatusProc(newString[1], newString[2]);
  1345. printf("=========================== \n");
  1346. }
  1347. else if(strcmp(newString[0], "card") == 0)
  1348. {
  1349. // 刷卡狀態
  1350. RunCardProc(newString[1], newString[2]);
  1351. }
  1352. else if(strcmp(newString[0], "gun") == 0)
  1353. {
  1354. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1355. continue;
  1356. // 插槍狀態
  1357. RunGunPlugitProc(newString[1], newString[2]);
  1358. }
  1359. else if(strcmp(newString[0], "lock") == 0)
  1360. {
  1361. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1362. continue;
  1363. // 插槍狀態
  1364. GetGunLockStatusProc(newString[1], newString[2]);
  1365. }
  1366. else if(strcmp(newString[0], "sysid") == 0)
  1367. {
  1368. // 測試 sys id
  1369. SetSystemIDProc();
  1370. }
  1371. else if(strcmp(newString[0], "self") == 0)
  1372. {
  1373. // CSU 自我檢測狀態
  1374. RunSelfProc(newString[1]);
  1375. }
  1376. else if(strcmp(newString[0], "ver") == 0)
  1377. {
  1378. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1379. continue;
  1380. // 取 FW 版號
  1381. GetFwVerProc(newString[1]);
  1382. }
  1383. else if (strcmp(newString[0], "update") == 0)
  1384. {
  1385. // 更新
  1386. FwUpdateFlagProc(newString[1]);
  1387. }
  1388. else if (strcmp(newString[0], "ac") == 0)
  1389. {
  1390. // AC contactor 狀態
  1391. CheckAcStatus(newString[1]);
  1392. }
  1393. else if (strcmp(newString[0], "cable") == 0)
  1394. {
  1395. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1396. continue;
  1397. // cable check pass
  1398. SetCableChkStatus(newString[1], newString[2]);
  1399. }
  1400. else if (strcmp(newString[0], "pow") == 0)
  1401. {
  1402. // get output power
  1403. GetPowerValue();
  1404. }
  1405. else if (strcmp(newString[0], "model") == 0)
  1406. {
  1407. GetSystemInfo();
  1408. }
  1409. else if(strcmp(newString[0], "select") == 0)
  1410. {
  1411. // 取得 / 設定 當前選的槍號
  1412. GetGunSelectedNum(newString[1]);
  1413. }
  1414. else if(strcmp(newString[0], "change") == 0)
  1415. {
  1416. // 模擬按鈕改變選槍
  1417. ChangeGunNum();
  1418. }
  1419. else if(strcmp(newString[0], "fan") == 0)
  1420. {
  1421. // 設定風扇速度
  1422. SetFanSpeed(newString[1]);
  1423. }
  1424. else if(strcmp(newString[0], "show") == 0)
  1425. {
  1426. ShowSysInformation();
  1427. }
  1428. else if(strcmp(newString[0], "speed") == 0)
  1429. {
  1430. // 取得風扇速度
  1431. GetFanSpeed();
  1432. }
  1433. else if(strcmp(newString[0], "debug") == 0)
  1434. {
  1435. // 設定 debug mode
  1436. SetDebugMode(newString[1]);
  1437. }
  1438. else if (strcmp(newString[0], "gfd") == 0)
  1439. {
  1440. // 設定盲沖使用 GFD 功能
  1441. SetGFDMode(newString[1]);
  1442. }
  1443. else if(strcmp(newString[0], "temp") == 0)
  1444. {
  1445. // 取得 PSU 溫度
  1446. GetPsuTemp();
  1447. }
  1448. else if(strcmp(newString[0], "acin") == 0)
  1449. {
  1450. // 取得三向輸入電壓
  1451. GetAcInputVol();
  1452. }
  1453. else if(strcmp(newString[0], "psu") == 0)
  1454. {
  1455. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1456. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1457. {
  1458. printf ("PSU : Param fail..Please retry again......\n");
  1459. continue;
  1460. }
  1461. // 取得 PSU 資訊
  1462. GetPsuInformation(newString[1], newString[2], newString[3]);
  1463. }
  1464. else if (strcmp(newString[0], "cap") == 0)
  1465. {
  1466. GetConnectorCapInfo(newString[1]);
  1467. }
  1468. else if(strcmp(newString[0], "error") == 0)
  1469. {
  1470. CreateOneError();
  1471. }
  1472. else if (strcmp(newString[0], "auth") == 0)
  1473. {
  1474. GetAuthorizeFlag(newString[1]);
  1475. }
  1476. else if (strcmp(newString[0], "relay") == 0)
  1477. {
  1478. GetRelayStatus(newString[1]);
  1479. }
  1480. else if (strcmp(newString[0], "ccid") == 0)
  1481. {
  1482. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1483. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1484. {
  1485. printf ("Input ccid fail.\n");
  1486. continue;
  1487. }
  1488. SetChargingInfoCCID(newString[1], newString[2]);
  1489. }
  1490. else if (strcmp(newString[0], "guntemp") == 0)
  1491. {
  1492. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1493. {
  1494. printf ("Input guntemp fail.\n");
  1495. continue;
  1496. }
  1497. GetGunTemp(newString[1]);
  1498. }
  1499. else if (strcmp(newString[0], "offer") == 0)
  1500. {
  1501. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1502. {
  1503. printf ("offer fail.\n");
  1504. continue;
  1505. }
  1506. GetOffered(newString[1]);
  1507. }
  1508. else if (strcmp(newString[0], "evstate") == 0)
  1509. {
  1510. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1511. {
  1512. printf ("evstate fail.\n");
  1513. continue;
  1514. }
  1515. GetEvStatus(newString[1]);
  1516. }
  1517. else if (strcmp(newString[0], "meter") == 0)
  1518. {
  1519. // DC meter infor
  1520. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1521. {
  1522. printf ("meter cmd fail.\n");
  1523. continue;
  1524. }
  1525. GetDcMeterInfor(newString[1]);
  1526. }
  1527. else if (strcmp(newString[0], "soc") == 0)
  1528. {
  1529. GetSOC(newString[1]);
  1530. }
  1531. else if (strcmp(newString[0], "run") == 0)
  1532. {
  1533. if (ShmDcCommonData->_isAutoRunTest == YES)
  1534. ShmDcCommonData->_isAutoRunTest = NO;
  1535. else
  1536. ShmDcCommonData->_isAutoRunTest = YES;
  1537. printf ("_isAutoRunTest = %d \n", ShmDcCommonData->_isAutoRunTest);
  1538. }
  1539. else if (strcmp(newString[0], "test") == 0)
  1540. {
  1541. if (!FindChargingInfoData(1, &_chargingData[0]))
  1542. {
  1543. printf("FindChargingInfoData error\n");
  1544. }
  1545. // Test Command
  1546. memcpy(_chargingData[1]->EvConnAlarmCode, "023983", 6);
  1547. ShmStatusCodeData->InfoCode.InfoEvents.bits.Stop_by_EV_with_unknow_reason = YES;
  1548. }
  1549. else if(strcmp(newString[0], "strchg") == 0)
  1550. {
  1551. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1552. if (strcmp(newString[1], "auto") == 0)
  1553. {
  1554. newString[3][0] = 0;
  1555. }
  1556. else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1557. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1558. {
  1559. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1560. continue;
  1561. }
  1562. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1563. }
  1564. else if(strcmp(newString[0], "avechg") == 0)
  1565. {
  1566. // 雙槍同時忙充輸出
  1567. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1568. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  1569. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  1570. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  1571. {
  1572. printf ("Input cmd fail ------ avechg\n");
  1573. continue;
  1574. }
  1575. if (ShmSysConfigAndInfo->SysConfig.TotalConnectorCount < 2 ||
  1576. ShmSysConfigAndInfo->SysInfo.IsAlternatvieConf == 1)
  1577. {
  1578. printf ("Sorry, This is single gun system. \n");
  1579. continue;
  1580. }
  1581. AverageCharging(newString[1], newString[2], newString[3], newString[4]);
  1582. }
  1583. else
  1584. printf ("%s\n", msg);
  1585. usleep(100000);
  1586. }
  1587. return 0;
  1588. }