ReadCmdline.c 71 KB

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