ReadCmdline.c 58 KB

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