ReadCmdline.c 53 KB

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