ReadCmdline.c 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192
  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. #include "Config.h"
  38. #include "Module_EvComm.h"
  39. #include "Common.h"
  40. typedef unsigned char byte;
  41. #define PASS 1
  42. #define FAIL -1
  43. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  44. #define NO_DEFINE 255
  45. #define DEFAULT_AC_INDEX 2
  46. #define TTY_PATH "/dev/tty"
  47. #define STTY_US "stty raw -echo -F "
  48. #define STTY_DEF "stty -raw echo -F "
  49. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  50. struct StatusCodeData *ShmStatusCodeData;
  51. struct PrimaryMcuData *ShmPrimaryMcuData;
  52. struct CHAdeMOData *ShmCHAdeMOData;
  53. struct CcsData *ShmCcsData;
  54. struct GBTData *ShmGBTData;
  55. struct FanModuleData *ShmFanModuleData;
  56. struct RelayModuleData *ShmRelayModuleData;
  57. struct LedModuleData *ShmLedModuleData;
  58. struct PsuData *ShmPsuData;
  59. ChargerInfoData *ShmChargerInfo;
  60. PsuPositionInfoData *ShmPsuPosition;
  61. PsuGroupingInfoData *ShmPsuGrouping;
  62. PsuGroupCollectionData *ShmGroupCollection;
  63. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  64. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  65. char *msg = "state : get gun state (index) \n"
  66. "card : scanning card (x) : \n"
  67. "gun : get gun plugit state (index) \n"
  68. "lock : get gun locked state (index) \n"
  69. "self : self test state (x) \n"
  70. "ver : ver of board (407 or index or rb or fan) \n"
  71. "ac : get ac relay state (x) \n"
  72. "gunchg: set gun start charging \n"
  73. "gunstp: set gun stop charging \n"
  74. "gunext: extend gun capability \n";
  75. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  76. {
  77. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  78. {
  79. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  80. {
  81. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  82. return true;
  83. }
  84. }
  85. for (byte index = 0; index < CCS_QUANTITY; index++)
  86. {
  87. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  88. {
  89. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  90. return true;
  91. }
  92. }
  93. for (byte index = 0; index < GB_QUANTITY; index++)
  94. {
  95. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  96. {
  97. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  98. return true;
  99. }
  100. }
  101. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  102. {
  103. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  104. return true;
  105. }
  106. return false;
  107. }
  108. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  109. {
  110. if (target < AC_QUANTITY)
  111. {
  112. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  113. return true;
  114. }
  115. return false;
  116. }
  117. int InitShareMemory()
  118. {
  119. int result = PASS;
  120. int MeterSMId;
  121. //initial ShmSysConfigAndInfo
  122. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  123. {
  124. result = FAIL;
  125. }
  126. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  127. {
  128. result = FAIL;
  129. }
  130. else
  131. {}
  132. //initial ShmStatusCodeData
  133. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  134. {
  135. result = FAIL;
  136. }
  137. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  138. {
  139. result = FAIL;
  140. }
  141. else
  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. memset(ShmGBTData, 0, sizeof(struct GBTData));
  170. }
  171. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  172. {
  173. result = FAIL;
  174. }
  175. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  176. {
  177. result = FAIL;
  178. }
  179. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  180. {
  181. result = FAIL;
  182. }
  183. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  184. {
  185. result = FAIL;
  186. }
  187. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  188. {
  189. result = FAIL;
  190. }
  191. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  192. {
  193. result = FAIL;
  194. }
  195. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  196. {
  197. result = FAIL;
  198. }
  199. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  200. {
  201. result = FAIL;
  202. }
  203. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  204. {
  205. result = FAIL;
  206. }
  207. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  208. {
  209. result = FAIL;
  210. }
  211. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  212. {
  213. result = FAIL;
  214. }
  215. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  216. {
  217. result = FAIL;
  218. }
  219. if(result == PASS)
  220. {
  221. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  222. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  223. ShmGroupCollection = &ShmChargerInfo->PsuGrouping.GroupCollection[0];
  224. }
  225. return result;
  226. }
  227. void RunStatusProc(char *v1, char *v2)
  228. {
  229. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  230. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  231. if (strcmp(v1, "ac") == 0)
  232. {
  233. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  234. {
  235. printf("FindChargingInfoData (AC) false \n");
  236. }
  237. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  238. return;
  239. }
  240. int _index = atoi(v1);
  241. if (_index <= 1)
  242. {
  243. if (!FindChargingInfoData(_index, &_chargingData[0]))
  244. {
  245. printf ("FindChargingInfoData error\n");
  246. return;
  247. }
  248. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  249. {
  250. // get
  251. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  252. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  253. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  254. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  255. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  256. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  257. }
  258. else
  259. {
  260. // set
  261. _chargingData[_index]->SystemStatus = atoi(v2);
  262. }
  263. }
  264. else
  265. {
  266. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  267. {
  268. printf("FindChargingInfoData (AC) false \n");
  269. }
  270. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  271. {
  272. // get
  273. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  274. }
  275. else
  276. {
  277. // set
  278. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  279. }
  280. }
  281. }
  282. void RunCardProc(char *v1, char *v2)
  283. {
  284. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  285. {
  286. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  287. {
  288. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  289. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  290. }
  291. else
  292. {
  293. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  294. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  295. }
  296. }
  297. else
  298. {
  299. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  300. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  301. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  302. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  303. }
  304. }
  305. void RunGunPlugitProc(char *v1, char *v2)
  306. {
  307. if (strcmp(v1, "ac") == 0)
  308. {
  309. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  310. {
  311. printf("FindChargingInfoData (AC) false \n");
  312. }
  313. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  314. {
  315. // get
  316. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  317. }
  318. else
  319. {
  320. // set
  321. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  322. }
  323. return;
  324. }
  325. int _index = atoi(v1);
  326. if (!FindChargingInfoData(_index, &_chargingData[0]))
  327. {
  328. printf("FindChargingInfoData error\n");
  329. return;
  330. }
  331. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  332. {
  333. // get
  334. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  335. }
  336. else
  337. {
  338. // set
  339. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  340. }
  341. }
  342. void GetGunLockStatusProc(char *v1, char *v2)
  343. {
  344. int _index = atoi(v1);
  345. if (!FindChargingInfoData(_index, &_chargingData[0]))
  346. {
  347. printf("FindChargingInfoData error\n");
  348. return;
  349. }
  350. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  351. {
  352. _chargingData[_index]->GunLocked = atoi(v2);
  353. }
  354. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  355. }
  356. void SetSystemIDProc()
  357. {
  358. char *systemId = "Alston_Test";
  359. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  360. }
  361. void RunSelfProc()
  362. {
  363. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  364. }
  365. void ShowFwVer(void)
  366. {
  367. printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  368. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  369. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
  370. printf("\r\n Csu Kernel: ");
  371. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  372. {
  373. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  374. {
  375. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  376. }
  377. }
  378. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  379. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  380. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  381. printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  382. printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  383. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  384. {
  385. printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  386. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  387. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  388. {
  389. printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
  390. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
  391. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
  392. printf("\r\n Csu Kernel: ");
  393. for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
  394. {
  395. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
  396. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
  397. {
  398. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
  399. }
  400. }
  401. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
  402. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
  403. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
  404. printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
  405. printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
  406. printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
  407. printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
  408. }
  409. }
  410. printf("\r\n\r\n");
  411. }
  412. void GetFwVerProc(char *v1)
  413. {
  414. if (strcmp(v1, "407") == 0)
  415. {
  416. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  417. }
  418. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  419. {
  420. int _index = atoi(v1);
  421. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  422. {
  423. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  424. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  425. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  426. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  427. {
  428. if(ParentIndex == 0)
  429. {
  430. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  431. }
  432. else
  433. {
  434. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  435. }
  436. }
  437. }
  438. else
  439. {
  440. printf("Gun %d is disable\r\n", _index);
  441. }
  442. }
  443. else if (strcmp(v1, "rb") == 0)
  444. {
  445. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  446. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  447. }
  448. else if (strcmp(v1, "fan") == 0)
  449. {
  450. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  451. }
  452. else if (strcmp(v1, "dc") == 0)
  453. {
  454. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  455. }
  456. else if (strcmp(v1, "led") == 0)
  457. {
  458. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  459. }
  460. }
  461. void CreateOneError(char *v1)
  462. {
  463. int value = atoi(v1);
  464. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  465. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  466. }
  467. void GetAuthorizeFlag(char *v1)
  468. {
  469. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  470. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  471. else
  472. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  473. }
  474. void GetOrClearId(char *v1)
  475. {
  476. int _index = atoi(v1);
  477. if (!FindChargingInfoData(_index, &_chargingData[0]))
  478. {
  479. printf("FindChargingInfoData error\n");
  480. return;
  481. }
  482. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  483. }
  484. void FwUpdateFlagProc()
  485. {
  486. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  487. }
  488. void CheckAcStatus(char *v1)
  489. {
  490. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  491. {
  492. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  493. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  494. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  495. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  496. }
  497. else
  498. {
  499. if(system("pidof -s main > /dev/null") != 0)
  500. {
  501. if(strcmp(v1, "0") == 0)
  502. {
  503. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  504. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  505. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  506. printf("Set AC Contactor Off\r\n");
  507. }
  508. else
  509. {
  510. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  511. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  512. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  513. printf("Set AC Contactor On\r\n");
  514. }
  515. }
  516. else
  517. {
  518. printf("main task is running\r\n");
  519. }
  520. }
  521. }
  522. void SetCableChkStatus(char *v1, char *v2)
  523. {
  524. int _index = atoi(v1);
  525. if (!FindChargingInfoData(_index, &_chargingData[0]))
  526. {
  527. printf ("FindChargingInfoData error\n");
  528. return;
  529. }
  530. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  531. }
  532. void SetPowerValue(char *v1, char *v2)
  533. {
  534. int _index = atoi(v1);
  535. float _Current = atof(v2);
  536. // 盲沖的時候才允許使用~
  537. if (_chargingData[_index]->Type != 9)
  538. return;
  539. if (!FindChargingInfoData(_index, &_chargingData[0]))
  540. {
  541. printf ("FindChargingInfoData error\n");
  542. return;
  543. }
  544. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  545. }
  546. void GetSystemInfo()
  547. {
  548. printf ("\r\n ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  549. printf ("\r\nSerialNumber = %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  550. printf ("\r\nInternetConn = %d", ShmSysConfigAndInfo->SysInfo.InternetConn);
  551. printf ("\r\nMaxChargingPower = %d, MaxChargingCurrent = %d",
  552. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  553. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  554. printf("\r\n\r\n");
  555. }
  556. void ChangeGunNum()
  557. {
  558. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount)
  559. {
  560. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  561. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  562. }
  563. else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  564. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE)
  565. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  566. else
  567. {
  568. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  569. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  570. }
  571. }
  572. void GetGunSelectedNum(char *v1)
  573. {
  574. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  575. {
  576. if (AC_QUANTITY > 0 &&
  577. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE)
  578. {
  579. printf("connector select changed = AC \n");
  580. }
  581. else
  582. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  583. }
  584. else
  585. {
  586. int _index = atoi(v1);
  587. if (_index <= 1)
  588. {
  589. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  590. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  591. printf("connector select changed = %d \n", _index);
  592. }
  593. else if (AC_QUANTITY > 0)
  594. {
  595. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  596. printf("connector select changed = AC \n");
  597. }
  598. }
  599. }
  600. void SetFanSpeed(char *v1)
  601. {
  602. int speed = atoi(v1);
  603. ShmFanModuleData->TestFanSpeed = speed;
  604. }
  605. void GetFanSpeed()
  606. {
  607. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  608. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  609. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  610. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  611. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  612. }
  613. void SetDebugMode(char *v1)
  614. {
  615. int mode = atoi(v1);
  616. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  617. }
  618. void SetGFDMode(char *v1)
  619. {
  620. int mode = atoi(v1);
  621. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  622. }
  623. // Gun Temp Chiller PSU 0 PSU 1 PSU 2 ...
  624. // 1 XXX XXX XXX XXX XXX XXX
  625. void GetTemperature(char *v1)
  626. {
  627. bool show = false;
  628. char strGunTemp[16], strChillerTemp[16];
  629. if(strcmp(v1, "c") == 0)
  630. {
  631. printf("\r\n Get c Parameter");
  632. show = true;
  633. }
  634. do
  635. {
  636. printf("\r\n Gun Temp Chiller PSU 0 PSU 1 PSU 2 ...");
  637. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  638. {
  639. sprintf(strGunTemp, "N/A");
  640. sprintf(strChillerTemp, "N/A");
  641. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  642. {
  643. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  644. }
  645. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  646. {
  647. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  648. }
  649. printf("\r\n %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  650. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  651. {
  652. printf(" %3d ", ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp);
  653. }
  654. }
  655. printf("\r\n");
  656. if(show)
  657. {
  658. sleep(1);
  659. }
  660. }while(show);
  661. }
  662. void GetAcInputVol()
  663. {
  664. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  665. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  666. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  667. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  668. }
  669. void GetPsuInformation(char *v1, char *v2, char *v3)
  670. {
  671. printf("**********************AC Contact needed*************************\n");
  672. if(strcmp(v1, "count") == 0)
  673. {
  674. for (int i = 0; i < 4; i++)
  675. {
  676. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  677. }
  678. }
  679. else if(strcmp(v1, "ver") == 0)
  680. {
  681. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  682. {
  683. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  684. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  685. }
  686. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  687. {
  688. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  689. {
  690. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  691. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  692. }
  693. }
  694. }
  695. else if(strcmp(v1, "cap") == 0)
  696. {
  697. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  698. {
  699. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  700. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  701. }
  702. }
  703. else if(strcmp(v1, "input") == 0)
  704. {
  705. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  706. {
  707. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  708. {
  709. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  710. i, count,
  711. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  712. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  713. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  714. }
  715. }
  716. }
  717. else if (strcmp(v1, "output") == 0)
  718. {
  719. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  720. {
  721. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  722. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  723. }
  724. }
  725. else if (strcmp(v1, "test") == 0)
  726. {
  727. int mode = atoi(v2);
  728. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  729. {
  730. ShmPsuData->Work_Step = mode;
  731. }
  732. }
  733. else if (strcmp(v1, "out") == 0)
  734. {
  735. float vol = atof(v2);
  736. float cur = atof(v3);
  737. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  738. {
  739. if (!FindChargingInfoData(0, &_chargingData[0]))
  740. {
  741. printf ("FindChargingInfoData error\n");
  742. return;
  743. }
  744. _chargingData[0]->EvBatterytargetVoltage = vol;
  745. _chargingData[0]->EvBatterytargetCurrent = cur;
  746. }
  747. }
  748. printf("*************************************************\n");
  749. }
  750. void GetConnectorCapInfo(char *v1)
  751. {
  752. int _GunIndex = atoi(v1);
  753. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  754. {
  755. printf ("FindChargingInfoData error\n");
  756. return;
  757. }
  758. printf ("Charger Max Current = %d, Max Power = %d \n",
  759. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  760. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  761. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  762. _GunIndex,
  763. _chargingData[_GunIndex]->RealMaxPower,
  764. _chargingData[_GunIndex]->RealMaxVoltage,
  765. _chargingData[_GunIndex]->RealMaxCurrent);
  766. }
  767. static void get_char(char *word)
  768. {
  769. fd_set rfds;
  770. struct timeval tv;
  771. FD_ZERO(&rfds);
  772. FD_SET(0, &rfds);
  773. tv.tv_sec = 0;
  774. tv.tv_usec = 10; //wait input timout time
  775. //if input
  776. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  777. {
  778. fgets(word, 128, stdin);
  779. }
  780. }
  781. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  782. {
  783. int _GunIndex = atoi(v1);
  784. float _Voltage = atof(v2);
  785. float _Current = atof(v3);
  786. unsigned char PreviousSystemStatus = 0xff;
  787. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  788. {
  789. printf ("FindChargingInfoData error\n");
  790. return;
  791. }
  792. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  793. if(_Voltage > 1000 || _Voltage < 50)
  794. {
  795. printf ("Input Voltage over range\n");
  796. return;
  797. }
  798. // if(_Current > 100 || _Current < 2){
  799. //
  800. // printf ("Input Current over range\n");
  801. // return;
  802. // }
  803. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  804. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  805. //kill ev task
  806. system("killall Module_EvComm");
  807. //_Voltage = (_Voltage * 10);
  808. //_Current = (_Current * 10);
  809. //system(STTY_US TTY_PATH);
  810. while(true)
  811. {
  812. //fix gun 1
  813. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  814. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  815. {
  816. case S_IDLE:
  817. {
  818. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  819. {
  820. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  821. printf ("[UnconditionalCharge - S_IDLE]\n");
  822. }
  823. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  824. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  825. }
  826. break;
  827. case S_PREPARNING:
  828. {
  829. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  830. {
  831. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  832. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  833. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  834. printf ("wait find module\n");
  835. }
  836. //main 會在此階段判斷以下資料跳到下一個 state
  837. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  838. //ShmPsuData->SystemPresentPsuQuantity;
  839. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  840. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  841. //_chargingData[gun_index]->AvailableChargingPower;
  842. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  843. //sleep(10);
  844. //清除 main timeout 機制
  845. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  846. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  847. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  848. }
  849. break;
  850. case S_PREPARING_FOR_EV:
  851. {
  852. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  853. {
  854. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  855. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  856. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  857. }
  858. //清除 main timeout 機制
  859. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  860. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  861. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  862. //充電電壓電流
  863. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  864. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  865. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  866. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  867. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  868. //確定模組己升壓完成
  869. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  870. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  871. {
  872. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  873. //EV done
  874. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  875. }
  876. }
  877. break;
  878. case S_PREPARING_FOR_EVSE:
  879. {
  880. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  881. {
  882. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  883. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  884. }
  885. //printf ("tar vol = %d \n", _Voltage);
  886. //printf ("tar cur = %d \n", _Current);
  887. //清除 main timeout 機制
  888. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  889. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  890. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  891. //充電電壓電流
  892. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  893. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  894. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  895. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  896. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  897. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  898. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  899. //確定模組己升壓完成
  900. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  901. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  902. //{
  903. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  904. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  905. sleep(5);
  906. //EV done
  907. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  908. //}
  909. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  910. //{
  911. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  912. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  913. //}
  914. }
  915. break;
  916. case S_CHARGING:
  917. {
  918. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  919. {
  920. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  921. //充電電壓電流
  922. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  923. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  924. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  925. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  926. printf ("[UnconditionalCharge - S_CHARGING]\n");
  927. }
  928. //ev task do this
  929. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  930. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  931. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  932. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  933. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  934. }
  935. }
  936. break;
  937. case S_TERMINATING:
  938. {
  939. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  940. {
  941. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  942. system("/root/Module_EvComm &");
  943. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  944. //無阻塞偵測 keybaord 結束
  945. system(STTY_DEF TTY_PATH);
  946. }
  947. sleep(3);
  948. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  949. return;
  950. }
  951. break;
  952. case S_COMPLETE:
  953. {
  954. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  955. {
  956. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  957. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  958. }
  959. sleep(3);
  960. return;
  961. }
  962. break;
  963. }
  964. char word[128];
  965. char newString[7][10];
  966. int i,j,ctr;
  967. memset(word, 0x00, sizeof(word));
  968. get_char(word);
  969. if (strlen(word) == 0)
  970. {
  971. continue;
  972. }
  973. j=0; ctr=0;
  974. strcpy(newString[1], "-1");
  975. strcpy(newString[2], "-1");
  976. for (i = 0; i <= (strlen(word)); i++)
  977. {
  978. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  979. {
  980. newString[ctr][j] = '\0';
  981. ctr++;
  982. j = 0;
  983. }
  984. else
  985. {
  986. newString[ctr][j] = word[i];
  987. j++;
  988. }
  989. }
  990. if(strcmp(newString[0], "chg") == 0)
  991. {
  992. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  993. continue;
  994. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  995. continue;
  996. float _vol = atof(newString[1]);
  997. float _cur = atof(newString[2]);
  998. if (_cur <= 0 || _cur <= 0)
  999. continue;
  1000. printf("vol = %f, cur = %f \n", _vol, _cur);
  1001. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  1002. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  1003. }
  1004. else if (strcmp(newString[0], "c") == 0)
  1005. {
  1006. printf("stop \n\r");
  1007. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  1008. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1009. }
  1010. usleep(100000);
  1011. }
  1012. }
  1013. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  1014. {
  1015. float _Voltage[2], _Current[2];
  1016. _Voltage[0] = atof(v1);
  1017. _Current[0] = atof(v2);
  1018. _Voltage[1] = atof(v3);
  1019. _Current[1] = atof(v4);
  1020. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  1021. if(!FindChargingInfoData(0, &_chargingData[0]))
  1022. {
  1023. printf ("FindChargingInfoData 0 error\n");
  1024. return;
  1025. }
  1026. if(!FindChargingInfoData(1, &_chargingData[0]))
  1027. {
  1028. printf ("FindChargingInfoData 1 error\n");
  1029. return;
  1030. }
  1031. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  1032. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  1033. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  1034. {
  1035. printf ("Input Voltage over range\n");
  1036. return;
  1037. }
  1038. //kill ev task
  1039. system("killall Module_EvComm");
  1040. while(true)
  1041. {
  1042. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  1043. {
  1044. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  1045. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  1046. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1047. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1048. }
  1049. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  1050. {
  1051. system(STTY_DEF TTY_PATH);
  1052. sleep(5);
  1053. return;
  1054. }
  1055. for(int i = 0; i < 2; i++)
  1056. {
  1057. switch(_chargingData[i]->SystemStatus)
  1058. {
  1059. case S_IDLE:
  1060. {
  1061. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1062. {
  1063. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1064. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  1065. }
  1066. }
  1067. break;
  1068. case S_PREPARNING:
  1069. {
  1070. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1071. {
  1072. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1073. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1074. printf ("wait find module\n");
  1075. }
  1076. //清除 main timeout 機制
  1077. _chargingData[i]->TimeoutFlag = 0;
  1078. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1079. _chargingData[i]->Type = 9;
  1080. }
  1081. break;
  1082. case S_PREPARING_FOR_EV:
  1083. {
  1084. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1085. {
  1086. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1087. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1088. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1089. }
  1090. //清除 main timeout 機制
  1091. _chargingData[i]->TimeoutFlag = 0;
  1092. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1093. _chargingData[i]->Type = 9;
  1094. //充電電壓電流
  1095. _chargingData[i]->EvBatterySoc = 50;
  1096. _chargingData[i]->EvBatterytargetVoltage = 500;
  1097. _chargingData[i]->EvBatterytargetCurrent = 2;
  1098. _chargingData[i]->AvailableChargingCurrent = 1000;
  1099. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1100. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1101. }
  1102. break;
  1103. case S_PREPARING_FOR_EVSE:
  1104. {
  1105. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1106. {
  1107. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1108. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1109. }
  1110. //清除 main timeout 機制
  1111. _chargingData[i]->TimeoutFlag = 0;
  1112. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1113. _chargingData[i]->Type = 9;
  1114. //充電電壓電流
  1115. _chargingData[i]->EvBatterySoc = 50;
  1116. _chargingData[i]->EvBatterytargetVoltage = 500;
  1117. _chargingData[i]->EvBatterytargetCurrent = 2;
  1118. _chargingData[i]->AvailableChargingCurrent = 1000;
  1119. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1120. sleep(5);
  1121. //EV done
  1122. _chargingData[i]->SystemStatus = S_CHARGING;
  1123. }
  1124. break;
  1125. case S_CHARGING:
  1126. {
  1127. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1128. {
  1129. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1130. //充電電壓電流
  1131. _chargingData[i]->EvBatterySoc = 50;
  1132. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1133. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1134. _chargingData[i]->AvailableChargingCurrent = 1000;
  1135. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1136. }
  1137. }
  1138. break;
  1139. case S_TERMINATING:
  1140. {
  1141. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1142. {
  1143. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1144. system("/root/Module_EvComm &");
  1145. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1146. }
  1147. sleep(3);
  1148. _chargingData[i]->SystemStatus = S_COMPLETE;
  1149. }
  1150. break;
  1151. case S_COMPLETE:
  1152. {
  1153. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1154. {
  1155. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1156. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1157. }
  1158. }
  1159. break;
  1160. }
  1161. }
  1162. char word[128];
  1163. char newString[7][10];
  1164. int i,j,ctr;
  1165. memset(word, 0x00, sizeof(word));
  1166. get_char(word);
  1167. if (strlen(word) == 0)
  1168. {
  1169. continue;
  1170. }
  1171. j=0; ctr=0;
  1172. strcpy(newString[1], "-1");
  1173. strcpy(newString[2], "-1");
  1174. for (i = 0; i <= (strlen(word)); i++)
  1175. {
  1176. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1177. {
  1178. newString[ctr][j] = '\0';
  1179. ctr++;
  1180. j = 0;
  1181. }
  1182. else
  1183. {
  1184. newString[ctr][j] = word[i];
  1185. j++;
  1186. }
  1187. }
  1188. if(strcmp(newString[0], "chg") == 0)
  1189. {
  1190. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1191. continue;
  1192. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1193. continue;
  1194. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1195. continue;
  1196. int _gun = atoi(newString[1]);
  1197. float _vol = atof(newString[2]);
  1198. float _cur = atof(newString[3]);
  1199. if(_gun >= 2 || _gun < 0)
  1200. continue;
  1201. if (_cur <= 0 || _cur <= 0)
  1202. continue;
  1203. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1204. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1205. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1206. }
  1207. else if (strcmp(newString[0], "c") == 0)
  1208. {
  1209. printf("stop \n\r");
  1210. _chargingData[0]->SystemStatus = S_TERMINATING;
  1211. _chargingData[1]->SystemStatus = S_TERMINATING;
  1212. }
  1213. usleep(100000);
  1214. }
  1215. }
  1216. void SetWiringInfo(char *v1, char *v2)
  1217. {
  1218. int dispenser = atoi(v1);
  1219. int connector = atoi(v2);
  1220. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1221. {
  1222. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1223. {
  1224. printf("\r\n");
  1225. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1226. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1227. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1228. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1229. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1230. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1231. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1232. }
  1233. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1234. {
  1235. printf("\r\n");
  1236. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1237. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1238. int quantity = 0;
  1239. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1240. {
  1241. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1242. }
  1243. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1244. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1245. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1246. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1247. }
  1248. }
  1249. }
  1250. void ShowWiringInfo(void)
  1251. {
  1252. printf("\r\n");
  1253. printf("********** Wiring Info **********\r\n");
  1254. printf("Dispenser = %d, Connector = %d\r\n",
  1255. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1256. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1257. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1258. {
  1259. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1260. {
  1261. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1262. }
  1263. }
  1264. printf("\r\n");
  1265. }
  1266. void CleanWiringInfo(void)
  1267. {
  1268. printf("\r\n");
  1269. printf("******* Clean Wiring Info *******\r\n");
  1270. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1271. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1272. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
  1273. printf("\r\n");
  1274. }
  1275. void SetSystemSoftRest(void)
  1276. {
  1277. printf("********* Set Soft Reset ********\r\n");
  1278. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1279. }
  1280. void SetSystemHardReboot(void)
  1281. {
  1282. printf("******** Set Hard Reboot ********\r\n");
  1283. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1284. }
  1285. void SetGroupRole(byte group, byte role)
  1286. {
  1287. if(group < GENERAL_GUN_QUANTITY)
  1288. {
  1289. if(ShmGroupCollection[group].Role != role)
  1290. {
  1291. //printf("\r\nSet Group %d Role = %d", group, role);
  1292. }
  1293. ShmGroupCollection[group].Role = role;
  1294. }
  1295. }
  1296. void SetGroupToIdle(byte group)
  1297. {
  1298. if(group < GENERAL_GUN_QUANTITY)
  1299. {
  1300. SetGroupRole(group, _GROLE_IDLE);
  1301. ShmGroupCollection[group].Partner.Quantity = 0;
  1302. memset(ShmGroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
  1303. ShmGroupCollection[group].TargetGroup = 0;
  1304. //printf("\r\n Reset Group %02X To Idle", group);
  1305. }
  1306. }
  1307. void SetGroupToMaster(byte group)
  1308. {
  1309. if(group < GENERAL_GUN_QUANTITY)
  1310. {
  1311. SetGroupRole(group, _GROLE_MASTER);
  1312. ShmGroupCollection[group].TargetGroup = group + 1;
  1313. //printf("\r\n Set Group %02X As Master", group);
  1314. }
  1315. }
  1316. void SetGroupToSlave(byte group, byte target)
  1317. {
  1318. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1319. {
  1320. SetGroupRole(group, _GROLE_SLAVE);
  1321. ShmGroupCollection[group].TargetGroup = target + 1;
  1322. //printf("\r\n Set Group %02X As Slave", group);
  1323. }
  1324. }
  1325. // group: group index, target: target index
  1326. // add group to target's member
  1327. void AddGroupCollection(byte group, byte target)
  1328. {
  1329. int ParallelConfig = 0;
  1330. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1331. {
  1332. if(ShmGroupCollection[target].Role != _GROLE_MASTER)
  1333. {
  1334. return;
  1335. }
  1336. if(ShmGroupCollection[group].Role != _GROLE_IDLE &&
  1337. ShmGroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1338. ShmGroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1339. {
  1340. return;
  1341. }
  1342. SetGroupToSlave(group, target);
  1343. ShmGroupCollection[target].Partner.Member[ShmGroupCollection[target].Partner.Quantity++] = group;
  1344. ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
  1345. if(ParallelConfig != 0)
  1346. {
  1347. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1348. }
  1349. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
  1350. }
  1351. }
  1352. // group: group index, target: target index
  1353. // remove group out of target's member
  1354. void RemoveGroupCollection(byte group, byte target)
  1355. {
  1356. int location = 0, slave = 0;
  1357. bool find = false;
  1358. int ParallelConfig = 0;
  1359. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1360. {
  1361. for(int i = 0; i < ShmGroupCollection[target].Partner.Quantity; i++)
  1362. {
  1363. if(group == ShmGroupCollection[target].Partner.Member[i])
  1364. {
  1365. ShmGroupCollection[target].Partner.Member[i] = 0;
  1366. location = i;
  1367. find = true;
  1368. break;
  1369. }
  1370. }
  1371. if(find)
  1372. {
  1373. for(int i = location + 1; i < ShmGroupCollection[target].Partner.Quantity; i++)
  1374. {
  1375. slave = ShmGroupCollection[target].Partner.Member[i];
  1376. ShmGroupCollection[target].Partner.Member[i] = 0;
  1377. ShmGroupCollection[target].Partner.Member[i - 1] = slave;
  1378. }
  1379. ShmGroupCollection[target].Partner.Quantity--;
  1380. SetGroupToIdle(group);
  1381. ParallelConfig = ShmGroupCollection[target].ParallelConfig[group];
  1382. if(ParallelConfig != 0)
  1383. {
  1384. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1385. }
  1386. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmGroupCollection[target].Partner.Quantity, ParallelConfig);
  1387. }
  1388. }
  1389. }
  1390. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1391. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1392. void ShowGroupingInfo(void)
  1393. {
  1394. byte target = 0;
  1395. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1396. for(int i = 0; i < 4; i++)
  1397. {
  1398. target = ShmPsuGrouping->Layout[i];
  1399. printf("\r\n %d (%2d) %2d %d %02X ",
  1400. target + 1, _chargingData[target]->SystemStatus, ShmGroupCollection[target].Role,
  1401. ShmGroupCollection[target].Partner.Quantity, ShmGroupCollection[target].TargetGroup);
  1402. for(int j = 0; j < 3; j++)
  1403. {
  1404. if(ShmGroupCollection[target].Role == 1 && j < ShmGroupCollection[target].Partner.Quantity)
  1405. {
  1406. printf("[%02X] ", ShmGroupCollection[target].Partner.Member[j]);
  1407. }
  1408. else
  1409. {
  1410. printf(" ");
  1411. }
  1412. }
  1413. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1414. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1415. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1416. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1417. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1418. }
  1419. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1420. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1421. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1422. printf("\r\n\r\n");
  1423. }
  1424. void PsuGroupSwitchToIdle(byte group)
  1425. {
  1426. int master = 0, quantity = 0, location = 0, total = 0;
  1427. if(ShmGroupCollection[group].Role != _GROLE_SLAVE)
  1428. {
  1429. return;
  1430. }
  1431. master = ShmGroupCollection[group].TargetGroup - 1;
  1432. quantity = ShmGroupCollection[master].Partner.Quantity;
  1433. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1434. for(int i = 0; i < quantity; i++)
  1435. {
  1436. if(total == 0)
  1437. {
  1438. if(group == ShmGroupCollection[master].Partner.Member[i])
  1439. {
  1440. location = i;
  1441. total++;
  1442. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1443. }
  1444. }
  1445. else
  1446. {
  1447. // find other group in the same direction
  1448. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1449. {
  1450. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1451. {
  1452. total++;
  1453. //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
  1454. }
  1455. }
  1456. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1457. {
  1458. if(ShmPsuGrouping->Location[ShmGroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1459. {
  1460. total++;
  1461. //printf("\r\n Find Other Group %02X In The Same Direction", ShmGroupCollection[master].Partner.Member[i]);
  1462. }
  1463. }
  1464. }
  1465. }
  1466. if(total > 0)
  1467. {
  1468. unsigned char collection[GENERAL_GUN_QUANTITY];
  1469. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1470. memcpy(collection, ShmGroupCollection[master].Partner.Member, ARRAY_SIZE(ShmGroupCollection[master].Partner.Member));
  1471. for(int i = 0; i < total; i++)
  1472. {
  1473. //printf(" %02X", collection[i + location]);
  1474. }
  1475. for(int i = 0; i < total; i++)
  1476. {
  1477. RemoveGroupCollection(collection[i + location], master);
  1478. }
  1479. }
  1480. }
  1481. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1482. {
  1483. int slave = 0, location = 0;
  1484. PsuGroupPartner partner;
  1485. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1486. // search from left
  1487. location = ShmGroupCollection[master].Location - 1;
  1488. for(int i = location; i >= 0; i--)
  1489. {
  1490. if(partner.Quantity >= quantity)
  1491. {
  1492. break;
  1493. }
  1494. slave = ShmPsuGrouping->Layout[i];
  1495. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1496. {
  1497. //printf("\r\n Find Group %02X From Left", slave);
  1498. partner.Member[partner.Quantity++] = slave;
  1499. }
  1500. else
  1501. {
  1502. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
  1503. {
  1504. continue;
  1505. }
  1506. break;
  1507. }
  1508. }
  1509. // search from right
  1510. location = ShmGroupCollection[master].Location + 1;
  1511. for(int i = location; i < 4; i++)
  1512. {
  1513. if(partner.Quantity >= quantity)
  1514. {
  1515. break;
  1516. }
  1517. slave = ShmPsuGrouping->Layout[i];
  1518. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1519. {
  1520. //printf("\r\n Find Group %02X From Right", slave);
  1521. partner.Member[partner.Quantity++] = slave;
  1522. }
  1523. else
  1524. {
  1525. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmGroupCollection[slave].TargetGroup - 1))
  1526. {
  1527. continue;
  1528. }
  1529. break;
  1530. }
  1531. }
  1532. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1533. }
  1534. int GetPsuGroupAvailable(byte group)
  1535. {
  1536. //int slave = 0, location = 0, available = 0;
  1537. PsuGroupPartner partner;
  1538. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1539. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1540. return partner.Quantity;
  1541. #if 0
  1542. // search from left
  1543. location = ShmGroupCollection[group].Location - 1;
  1544. for(int i = location; i >= 0; i--)
  1545. {
  1546. slave = ShmPsuGrouping->Layout[i];
  1547. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1548. {
  1549. available++;
  1550. }
  1551. else
  1552. {
  1553. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1554. {
  1555. continue;
  1556. }
  1557. break;
  1558. }
  1559. }
  1560. // search from right
  1561. location = ShmGroupCollection[group].Location + 1;
  1562. for(int i = location; i < 4; i++)
  1563. {
  1564. slave = ShmPsuGrouping->Layout[i];
  1565. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1566. {
  1567. available++;
  1568. }
  1569. else
  1570. {
  1571. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1572. {
  1573. continue;
  1574. }
  1575. break;
  1576. }
  1577. }
  1578. return available;
  1579. #endif
  1580. }
  1581. void PsuGroupShareCheck(byte group)
  1582. {
  1583. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1584. total = GetPsuGroupAvailable(group) + 1;
  1585. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1586. // search from left
  1587. location = ShmGroupCollection[group].Location - 1;
  1588. for(int i = location; i >= 0; i--)
  1589. {
  1590. slave = ShmPsuGrouping->Layout[i];
  1591. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
  1592. {
  1593. target = ShmGroupCollection[slave].TargetGroup - 1;
  1594. if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
  1595. {
  1596. share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1597. }
  1598. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
  1599. break;
  1600. }
  1601. else
  1602. {
  1603. break;
  1604. }
  1605. }
  1606. if(share == 0)
  1607. {
  1608. // search from right
  1609. location = ShmGroupCollection[group].Location + 1;
  1610. for(int i = location; i < 4; i++)
  1611. {
  1612. slave = ShmPsuGrouping->Layout[i];
  1613. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE)
  1614. {
  1615. target = ShmGroupCollection[slave].TargetGroup - 1;
  1616. if((ShmGroupCollection[target].Partner.Quantity + 1) > total)
  1617. {
  1618. share = (ShmGroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1619. }
  1620. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmGroupCollection[target].Partner.Quantity, share);
  1621. break;
  1622. }
  1623. else
  1624. {
  1625. break;
  1626. }
  1627. }
  1628. }
  1629. if(share > 0)
  1630. {
  1631. //printf("\r\n Grab %02X", slave);
  1632. PsuGroupSwitchToIdle(slave);
  1633. }
  1634. else
  1635. {
  1636. //printf("\r\n No Need To Grab");
  1637. }
  1638. }
  1639. void SimplePsuGroupStartCharging(byte group)
  1640. {
  1641. //int slave = 0, location = 0;
  1642. int available = 0;
  1643. PsuGroupPartner partner;
  1644. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1645. {
  1646. return;
  1647. }
  1648. if(ShmGroupCollection[group].Role != _GROLE_IDLE && ShmGroupCollection[group].Role != _GROLE_MASTER)
  1649. {
  1650. return;
  1651. }
  1652. if(ShmGroupCollection[group].Role == _GROLE_IDLE)
  1653. {
  1654. SetGroupToMaster(group);
  1655. PsuGroupShareCheck(group);
  1656. }
  1657. else
  1658. {
  1659. available = GetPsuGroupAvailable(group);
  1660. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1661. if(available == 0)
  1662. {
  1663. return;
  1664. }
  1665. }
  1666. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1667. for(int i = 0; i < partner.Quantity; i++)
  1668. {
  1669. AddGroupCollection(partner.Member[i], group);
  1670. }
  1671. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1672. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1673. #if 0
  1674. // search from left
  1675. location = ShmGroupCollection[group].Location - 1;
  1676. for(int i = location; i >= 0; i--)
  1677. {
  1678. slave = ShmPsuGrouping->Layout[i];
  1679. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1680. {
  1681. //printf("\r\n Find %02X From Left", slave);
  1682. AddGroupCollection(slave, group);
  1683. }
  1684. else
  1685. {
  1686. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1687. {
  1688. continue;
  1689. }
  1690. break;
  1691. }
  1692. }
  1693. // search from right
  1694. location = ShmGroupCollection[group].Location + 1;
  1695. for(int i = location; i < 4; i++)
  1696. {
  1697. slave = ShmPsuGrouping->Layout[i];
  1698. if(ShmGroupCollection[slave].Role == _GROLE_IDLE)
  1699. {
  1700. //printf("\r\n Find %02X From Right", slave);
  1701. AddGroupCollection(slave, group);
  1702. }
  1703. else
  1704. {
  1705. if(ShmGroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmGroupCollection[slave].TargetGroup - 1))
  1706. {
  1707. continue;
  1708. }
  1709. break;
  1710. }
  1711. }
  1712. #endif
  1713. }
  1714. void PsuGroupStopCharging(byte group)
  1715. {
  1716. int total = 0;
  1717. if(ShmGroupCollection[group].Role != _GROLE_MASTER)
  1718. {
  1719. return;
  1720. }
  1721. total = ShmGroupCollection[group].Partner.Quantity;
  1722. if(total > 0)
  1723. {
  1724. unsigned char collection[GENERAL_GUN_QUANTITY];
  1725. //printf("\r\n There are %d Group Need To Stop:", ShmGroupCollection[group].Partner.Quantity);
  1726. memcpy(collection, ShmGroupCollection[group].Partner.Member, ARRAY_SIZE(ShmGroupCollection[group].Partner.Member));
  1727. for(int i = 0; i < total; i++)
  1728. {
  1729. //printf(" %02X", collection[i]);
  1730. }
  1731. for(int i = 0; i < total; i++)
  1732. {
  1733. RemoveGroupCollection(collection[i], group);
  1734. }
  1735. }
  1736. SetGroupToIdle(group);
  1737. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1738. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1739. }
  1740. void RunSimplePsuGrouping(char *v1, char *v2)
  1741. {
  1742. int group = 0, charging = 0;
  1743. group = atoi(v1);
  1744. charging = atoi(v2);
  1745. group -= 1;
  1746. if(group >= 0 && group < 4)
  1747. {
  1748. if(charging > 0)
  1749. {
  1750. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1751. {
  1752. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1753. PsuGroupSwitchToIdle(group);
  1754. }
  1755. SimplePsuGroupStartCharging(group);
  1756. }
  1757. if(charging == 0)
  1758. {
  1759. if(ShmGroupCollection[group].Role == _GROLE_MASTER)
  1760. {
  1761. PsuGroupStopCharging(group);
  1762. }
  1763. if(ShmGroupCollection[group].Role == _GROLE_SLAVE)
  1764. {
  1765. PsuGroupSwitchToIdle(group);
  1766. }
  1767. }
  1768. ShowGroupingInfo();
  1769. }
  1770. }
  1771. void ShowCabinetInfo(void)
  1772. {
  1773. int ipAddress = 0;
  1774. printf("\r\nPower Cabinet Charging Mode = %d, ReAssignedFlag = %d, Psu Work Step = %d",
  1775. ShmSysConfigAndInfo->SysInfo.MainChargingMode, ShmSysConfigAndInfo->SysInfo.ReAssignedFlag, ShmPsuData->Work_Step);
  1776. printf("\r\n Dispenser: %d / %d, Connector: %d / %d",
  1777. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1778. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1779. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  1780. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  1781. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  1782. {
  1783. printf("\r\n Connector[%d] Index: %2X, Status = %2d , %s", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
  1784. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? "Enable" : "Disable");
  1785. }
  1786. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  1787. {
  1788. printf("\r\n Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  1789. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  1790. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  1791. {
  1792. ipAddress = 0;
  1793. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  1794. {
  1795. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
  1796. i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
  1797. {
  1798. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
  1799. }
  1800. }
  1801. printf(", ModelName: %s, IP: %d.%d.%d.%d", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
  1802. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  1803. for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
  1804. {
  1805. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j];
  1806. printf("\r\n - Connector[%d] Gun %d, %s", j, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  1807. }
  1808. }
  1809. else
  1810. {
  1811. printf(", No Information");
  1812. }
  1813. }
  1814. printf("\r\n\r\n");
  1815. }
  1816. void SetTestControl(char *v1, char *v2)
  1817. {
  1818. int testItem = 0;
  1819. int testItemLen = 3;
  1820. int enable = 0;
  1821. char strTest[32][32] = {"tbl", "tfsb", "chgsm"};
  1822. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation"};
  1823. enable = atoi(v2);
  1824. if(enable < 0)
  1825. {
  1826. return;
  1827. }
  1828. for(int i = 0; i < testItemLen; i++)
  1829. {
  1830. if(strcmp((char *)&strTest[i][0], v1) == 0)
  1831. {
  1832. testItem = i + 1;
  1833. break;
  1834. }
  1835. }
  1836. if(testItem != 0)
  1837. {
  1838. if(enable)
  1839. {
  1840. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  1841. }
  1842. else
  1843. {
  1844. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  1845. }
  1846. printf("%s %s Test Item, Test Control Value = %08X\n",
  1847. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  1848. }
  1849. else
  1850. {
  1851. printf("Test Item %s Not Found\n", v1);
  1852. for(int i = 0; i < testItemLen; i++)
  1853. {
  1854. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  1855. }
  1856. }
  1857. printf("\r\n");
  1858. }
  1859. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading
  1860. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX
  1861. void ShowGroupingDemand(void)
  1862. {
  1863. byte target = 0;
  1864. unsigned char k1k2 = 0;
  1865. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading");
  1866. for(int i = 0; i < 4; i++)
  1867. {
  1868. target = ShmPsuGrouping->Layout[i];
  1869. if(ShmGroupCollection[target].TargetGroup != 0)
  1870. {
  1871. k1k2 = _chargingData[ShmGroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  1872. }
  1873. else
  1874. {
  1875. k1k2 = _chargingData[target]->RelayK1K2Status;
  1876. }
  1877. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  1878. target + 1, ShmGroupCollection[target].Role, ShmGroupCollection[target].TargetGroup, k1k2,
  1879. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  1880. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  1881. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  1882. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1883. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  1884. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  1885. if(ShmGroupCollection[target].TargetGroup == target + 1)
  1886. {
  1887. printf(" %3d.%02d", (ShmGroupCollection[target].GunLoading / 100), (ShmGroupCollection[target].GunLoading % 100));
  1888. }
  1889. }
  1890. printf("\r\n\r\n");
  1891. }
  1892. // v1: gun
  1893. // v2: voltage
  1894. // v3: current
  1895. void SetGunStartCharging(char *v1, char *v2, char *v3)
  1896. {
  1897. int gun = 0;
  1898. float _voltage = 0, _current = 0;
  1899. gun = atoi(v1);
  1900. _voltage = atof(v2);
  1901. _current = atof(v3);
  1902. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  1903. {
  1904. printf("\r\nGun Start Charging Input parameter %s, %s, %s over range", v1, v2, v3);
  1905. printf("\r\n\r\n");
  1906. return;
  1907. }
  1908. /*
  1909. if(_chargingData[gun - 1]->SystemStatus == S_IDLE)
  1910. {
  1911. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1912. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  1913. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  1914. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1915. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1916. }
  1917. else if(ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
  1918. {
  1919. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  1920. {
  1921. printf("\r\nSet Gun %d > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1922. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1923. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1924. }
  1925. else
  1926. {
  1927. printf("\r\nGun %d Force Charging Is Disable", gun);
  1928. }
  1929. }
  1930. else
  1931. {
  1932. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  1933. }
  1934. printf("\r\n\r\n");
  1935. */
  1936. bool wait = true;
  1937. int time = 0;
  1938. struct timespec _Wait_time;
  1939. unsigned char PreviousSystemStatus = 0xFF;
  1940. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  1941. while(wait)
  1942. {
  1943. switch(_chargingData[gun - 1]->SystemStatus)
  1944. {
  1945. case S_IDLE:
  1946. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1947. {
  1948. printf("\r\nGun %d S_IDLE", gun);
  1949. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  1950. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  1951. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  1952. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  1953. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  1954. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1955. }
  1956. break;
  1957. case S_REASSIGN_CHECK:
  1958. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1959. {
  1960. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  1961. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1962. }
  1963. break;
  1964. case S_REASSIGN:
  1965. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1966. {
  1967. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  1968. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1969. }
  1970. break;
  1971. case S_PREPARNING:
  1972. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1973. {
  1974. printf("\r\nGun %d S_PREPARNING", gun);
  1975. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1976. }
  1977. break;
  1978. case S_PREPARING_FOR_EV:
  1979. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1980. {
  1981. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  1982. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1983. }
  1984. break;
  1985. case S_PREPARING_FOR_EVSE:
  1986. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  1987. {
  1988. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  1989. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  1990. }
  1991. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  1992. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  1993. {
  1994. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  1995. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  1996. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  1997. }
  1998. break;
  1999. case S_CHARGING:
  2000. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2001. {
  2002. printf("\r\nGun %d S_CHARGING", gun);
  2003. if(PreviousSystemStatus == 0xFF)
  2004. {
  2005. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2006. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2007. printf("\r\nGun %d Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2008. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2009. {
  2010. printf("\r\nSet Gun %d Force Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2011. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2012. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2013. }
  2014. }
  2015. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2016. GetClockTime(&_Wait_time);
  2017. }
  2018. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2019. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2020. {
  2021. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2022. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2023. printf("\r\nGun %d Set Voltage: %4d, Current: %d", gun, _targetVoltage, _targetCurrent);
  2024. }
  2025. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2026. if(time >= 3)
  2027. {
  2028. wait = false;
  2029. printf("\r\nDone");
  2030. }
  2031. break;
  2032. case S_TERMINATING:
  2033. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2034. {
  2035. printf("\r\nGun %d S_TERMINATING", gun);
  2036. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2037. }
  2038. wait = false;
  2039. break;
  2040. case S_COMPLETE:
  2041. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2042. {
  2043. printf("\r\nGun %d S_COMPLETE", gun);
  2044. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2045. }
  2046. wait = false;
  2047. break;
  2048. case S_ALARM:
  2049. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2050. {
  2051. printf("\r\nGun %d S_ALARM", gun);
  2052. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2053. }
  2054. wait = false;
  2055. break;
  2056. default:
  2057. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2058. {
  2059. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2060. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2061. }
  2062. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2063. wait = false;
  2064. break;
  2065. }
  2066. char word[128];
  2067. char newString[7][10];
  2068. int i,j,ctr;
  2069. memset(word, 0x00, sizeof(word));
  2070. get_char(word);
  2071. if (strlen(word) == 0)
  2072. {
  2073. continue;
  2074. }
  2075. j=0; ctr=0;
  2076. strcpy(newString[1], "-1");
  2077. strcpy(newString[2], "-1");
  2078. for (i = 0; i <= (strlen(word)); i++)
  2079. {
  2080. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2081. {
  2082. newString[ctr][j] = '\0';
  2083. ctr++;
  2084. j = 0;
  2085. }
  2086. else
  2087. {
  2088. newString[ctr][j] = word[i];
  2089. j++;
  2090. }
  2091. }
  2092. if(strcmp(newString[0], "c") == 0)
  2093. {
  2094. printf("\r\nStop");
  2095. wait = false;
  2096. }
  2097. usleep(100000);
  2098. }
  2099. printf("\r\n\r\n");
  2100. }
  2101. // v1: gun
  2102. void SetGunStopCharging(char *v1)
  2103. {
  2104. int gun = 0;
  2105. gun = atoi(v1);
  2106. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2107. {
  2108. printf("\r\nGun Stop Charging Input parameter %s over range", v1);
  2109. printf("\r\n\r\n");
  2110. return;
  2111. }
  2112. /*
  2113. if(_chargingData[gun - 1]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[gun - 1]->SystemStatus <= S_CHARGING)
  2114. {
  2115. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2116. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2117. }
  2118. else if(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2119. {
  2120. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2121. ShmGroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2122. }
  2123. else
  2124. {
  2125. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2126. }
  2127. printf("\r\n\r\n");
  2128. */
  2129. bool wait = true;
  2130. int time = 0;
  2131. struct timespec _Wait_time;
  2132. unsigned char PreviousSystemStatus = 0xFF;
  2133. while(wait)
  2134. {
  2135. switch(_chargingData[gun - 1]->SystemStatus)
  2136. {
  2137. case S_IDLE:
  2138. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2139. {
  2140. printf("\r\nGun %d S_IDLE", gun);
  2141. if(PreviousSystemStatus == 0xFF)
  2142. {
  2143. if(ShmGroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2144. {
  2145. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2146. ShmGroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2147. }
  2148. }
  2149. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2150. GetClockTime(&_Wait_time);
  2151. }
  2152. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2153. if(time >= 3)
  2154. {
  2155. wait = false;
  2156. printf("\r\nDone");
  2157. }
  2158. break;
  2159. case S_REASSIGN_CHECK:
  2160. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2161. {
  2162. printf("\r\nGun %d S_REASSIGN_CHECK, Wait For Request Charging", gun);
  2163. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2164. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2165. {
  2166. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2167. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2168. }
  2169. }
  2170. break;
  2171. case S_REASSIGN:
  2172. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2173. {
  2174. printf("\r\nGun %d S_REASSIGN, Wait For Grouping", gun);
  2175. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2176. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2177. {
  2178. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2179. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2180. }
  2181. }
  2182. break;
  2183. case S_PREPARNING:
  2184. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2185. {
  2186. printf("\r\nGun %d S_PREPARNING", gun);
  2187. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2188. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2189. {
  2190. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2191. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2192. }
  2193. }
  2194. break;
  2195. case S_PREPARING_FOR_EV:
  2196. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2197. {
  2198. printf("\r\nGun %d S_PREPARING_FOR_EV", gun);
  2199. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2200. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2201. {
  2202. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2203. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2204. }
  2205. }
  2206. break;
  2207. case S_PREPARING_FOR_EVSE:
  2208. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2209. {
  2210. printf("\r\nGun %d S_PREPARING_FOR_EVSE, Wait For EVSE", gun);
  2211. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2212. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2213. {
  2214. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2215. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2216. }
  2217. }
  2218. break;
  2219. case S_CHARGING:
  2220. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2221. {
  2222. printf("\r\nGun %d S_CHARGING", gun);
  2223. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2224. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2225. {
  2226. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2227. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2228. }
  2229. }
  2230. break;
  2231. case S_TERMINATING:
  2232. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2233. {
  2234. printf("\r\nGun %d S_TERMINATING", gun);
  2235. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2236. }
  2237. break;
  2238. case S_COMPLETE:
  2239. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2240. {
  2241. printf("\r\nGun %d S_COMPLETE", gun);
  2242. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2243. }
  2244. break;
  2245. case S_ALARM:
  2246. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2247. {
  2248. printf("\r\nGun %d S_ALARM", gun);
  2249. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2250. }
  2251. break;
  2252. default:
  2253. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2254. {
  2255. printf("\r\nGun SystemStatus %d Unknown(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2256. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2257. }
  2258. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2259. wait = false;
  2260. break;
  2261. }
  2262. char word[128];
  2263. char newString[7][10];
  2264. int i,j,ctr;
  2265. memset(word, 0x00, sizeof(word));
  2266. get_char(word);
  2267. if (strlen(word) == 0)
  2268. {
  2269. continue;
  2270. }
  2271. j=0; ctr=0;
  2272. strcpy(newString[1], "-1");
  2273. strcpy(newString[2], "-1");
  2274. for (i = 0; i <= (strlen(word)); i++)
  2275. {
  2276. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2277. {
  2278. newString[ctr][j] = '\0';
  2279. ctr++;
  2280. j = 0;
  2281. }
  2282. else
  2283. {
  2284. newString[ctr][j] = word[i];
  2285. j++;
  2286. }
  2287. }
  2288. if(strcmp(newString[0], "c") == 0)
  2289. {
  2290. printf("\r\nStop");
  2291. wait = false;
  2292. }
  2293. usleep(100000);
  2294. }
  2295. printf("\r\n\r\n");
  2296. }
  2297. void SetGunExtend(char *v1)
  2298. {
  2299. int gun = 0;
  2300. gun = atoi(v1);
  2301. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmGroupCollection[gun - 1].Role == _GROLE_MASTER)
  2302. {
  2303. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2304. ShmGroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2305. }
  2306. else
  2307. {
  2308. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2309. }
  2310. printf("\r\n\r\n");
  2311. }
  2312. // Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...
  2313. // X XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A XXXX.X V XXX.X A
  2314. void ShowGunOutput(void)
  2315. {
  2316. byte target = 0;
  2317. unsigned short voltage = 0, current = 0;
  2318. printf("\r\n Gun TargetV TargetC GTargetV GTargetC OutputV OutputC G_Psu_V G_Psu_C Psu 0_V Psu 0_C Psu 1_V Psu 1_C Psu 2_V Psu 2_C ...");
  2319. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2320. {
  2321. target = ShmPsuGrouping->Layout[i];
  2322. // "\r\n %d %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A %4d.%d V %3d.%d A"
  2323. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2324. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2325. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2326. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2327. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2328. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2329. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2330. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2331. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2332. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2333. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2334. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2335. /*
  2336. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2337. {
  2338. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2339. }
  2340. */
  2341. }
  2342. printf("\r\n\r\n");
  2343. }
  2344. void SetGpio(char *v1, char *v2)
  2345. {
  2346. int testItem = 0;
  2347. int testItemLen = 1;
  2348. int ioOutput = 0;
  2349. char strTest[32][32] = {"4g"};
  2350. char strItem[32][32] = {"4G Reset"};
  2351. ioOutput = atoi(v2);
  2352. if(ioOutput < 0)
  2353. {
  2354. return;
  2355. }
  2356. for(int i = 0; i < testItemLen; i++)
  2357. {
  2358. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2359. {
  2360. testItem = i + 1;
  2361. break;
  2362. }
  2363. }
  2364. if(testItem != 0)
  2365. {
  2366. if(ioOutput)
  2367. {
  2368. system("echo 1 > /sys/class/gpio/gpio104/value");
  2369. }
  2370. else
  2371. {
  2372. system("echo 0 > /sys/class/gpio/gpio104/value");
  2373. }
  2374. printf("Set %s %s\n",
  2375. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2376. }
  2377. else
  2378. {
  2379. printf("Gpio Item %s Not Found\n", v1);
  2380. }
  2381. printf("\r\n");
  2382. }
  2383. void ShowStatus(void)
  2384. {
  2385. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2386. {
  2387. printf("\r\nGun %d Status = %d, Available = %d", i + 1, _chargingData[i]->SystemStatus, _chargingData[i]->IsAvailable);
  2388. printf("\r\nAlarmCode");
  2389. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s",
  2390. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2391. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2392. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2393. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2394. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2395. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err");
  2396. }
  2397. printf("\r\n");
  2398. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2399. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2400. {
  2401. printf("\r\n WarningCode:");
  2402. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2403. {
  2404. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2405. }
  2406. }
  2407. printf("\r\n\r\n");
  2408. }
  2409. void ShowWhiteCardList(void)
  2410. {
  2411. printf("\r\nWhite Card List");
  2412. for(int i = 0; i < 10; i++)
  2413. {
  2414. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2415. }
  2416. printf("\r\n\r\n");
  2417. }
  2418. void WriteWhiteCard(char *v1, char *v2)
  2419. {
  2420. int cardIndex = 0;
  2421. cardIndex = atoi(v1);
  2422. if(cardIndex < 1 || cardIndex > 10)
  2423. {
  2424. printf("\r\n White Card Index Fail\r\n\r\n");
  2425. return;
  2426. }
  2427. if(strlen(v2) == 0 || strlen(v2) > 31)
  2428. {
  2429. printf("\r\n White Card Fail\r\n\r\n");
  2430. return;
  2431. }
  2432. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2433. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2434. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2435. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2436. printf("\r\n\r\n");
  2437. }
  2438. void EraseWhiteCard(char *v1)
  2439. {
  2440. int cardIndex = 0;
  2441. cardIndex = atoi(v1);
  2442. if(cardIndex < 1 || cardIndex > 10)
  2443. {
  2444. printf("\r\n White Card Index Fail\r\n\r\n");
  2445. return;
  2446. }
  2447. printf("\r\n Erase White Card Index = %d", cardIndex);
  2448. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2449. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2450. printf("\r\n\r\n");
  2451. }
  2452. int main(void)
  2453. {
  2454. if(InitShareMemory() == FAIL)
  2455. {
  2456. printf ("InitShareMemory = FAIL \n");
  2457. if(ShmStatusCodeData != NULL)
  2458. {
  2459. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  2460. }
  2461. sleep(5);
  2462. return 0;
  2463. }
  2464. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2465. {
  2466. if (!FindChargingInfoData(i, &_chargingData[0]))
  2467. {
  2468. return 0;
  2469. }
  2470. }
  2471. /*
  2472. memset(&ShmGroupCollection[0], 0x00, sizeof(PsuGroupCollectionData));
  2473. memset(&ShmGroupCollection[1], 0x00, sizeof(PsuGroupCollectionData));
  2474. memset(&ShmGroupCollection[2], 0x00, sizeof(PsuGroupCollectionData));
  2475. memset(&ShmGroupCollection[3], 0x00, sizeof(PsuGroupCollectionData));
  2476. ShmGroupCollection[0].Index = 0;
  2477. ShmGroupCollection[1].Index = 1;
  2478. ShmGroupCollection[2].Index = 2;
  2479. ShmGroupCollection[3].Index = 3;
  2480. ShmGroupCollection[0].Location = 0;
  2481. ShmGroupCollection[1].Location = 3;
  2482. ShmGroupCollection[2].Location = 1;
  2483. ShmGroupCollection[3].Location = 2;
  2484. */
  2485. for(;;)
  2486. {
  2487. char word[128];
  2488. char newString[7][32];
  2489. int i,j,ctr;
  2490. fgets(word, sizeof(word), stdin);
  2491. j=0; ctr=0;
  2492. strcpy(newString[1], "-1");
  2493. strcpy(newString[2], "-1");
  2494. for (i = 0; i <= (strlen(word)); i++)
  2495. {
  2496. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2497. {
  2498. newString[ctr][j] = '\0';
  2499. ctr++;
  2500. j = 0;
  2501. }
  2502. else
  2503. {
  2504. newString[ctr][j] = word[i];
  2505. j++;
  2506. }
  2507. }
  2508. if(strcmp(newString[0], "state") == 0)
  2509. {
  2510. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2511. continue;
  2512. // 槍狀態
  2513. RunStatusProc(newString[1], newString[2]);
  2514. }
  2515. else if(strcmp(newString[0], "card") == 0)
  2516. {
  2517. // 刷卡狀態
  2518. RunCardProc(newString[1], newString[2]);
  2519. }
  2520. else if(strcmp(newString[0], "gun") == 0)
  2521. {
  2522. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2523. continue;
  2524. // 插槍狀態
  2525. RunGunPlugitProc(newString[1], newString[2]);
  2526. }
  2527. else if(strcmp(newString[0], "lock") == 0)
  2528. {
  2529. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2530. continue;
  2531. // 插槍狀態
  2532. GetGunLockStatusProc(newString[1], newString[2]);
  2533. }
  2534. else if(strcmp(newString[0], "sysid") == 0)
  2535. {
  2536. // 測試 sys id
  2537. SetSystemIDProc();
  2538. }
  2539. else if(strcmp(newString[0], "self") == 0)
  2540. {
  2541. // CSU 自我檢測狀態
  2542. RunSelfProc(newString[1]);
  2543. }
  2544. else if(strcmp(newString[0], "ver") == 0)
  2545. {
  2546. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2547. // continue;
  2548. // 取 FW 版號
  2549. //GetFwVerProc(newString[1]);
  2550. ShowFwVer();
  2551. }
  2552. else if (strcmp(newString[0], "update") == 0)
  2553. {
  2554. // 更新
  2555. FwUpdateFlagProc(newString[1]);
  2556. }
  2557. else if (strcmp(newString[0], "ac") == 0)
  2558. {
  2559. // AC contactor 狀態
  2560. CheckAcStatus(newString[1]);
  2561. }
  2562. else if (strcmp(newString[0], "cable") == 0)
  2563. {
  2564. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2565. continue;
  2566. // cable check pass
  2567. SetCableChkStatus(newString[1], newString[2]);
  2568. }
  2569. else if (strcmp(newString[0], "pow") == 0)
  2570. {
  2571. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2572. continue;
  2573. // cable check pass
  2574. SetPowerValue(newString[1], newString[2]);
  2575. }
  2576. else if (strcmp(newString[0], "model") == 0)
  2577. {
  2578. GetSystemInfo();
  2579. }
  2580. else if(strcmp(newString[0], "select") == 0)
  2581. {
  2582. // 取得 / 設定 當前選的槍號
  2583. GetGunSelectedNum(newString[1]);
  2584. }
  2585. else if(strcmp(newString[0], "change") == 0)
  2586. {
  2587. // 模擬按鈕改變選槍
  2588. ChangeGunNum();
  2589. }
  2590. else if(strcmp(newString[0], "fan") == 0)
  2591. {
  2592. // 設定風扇速度
  2593. SetFanSpeed(newString[1]);
  2594. }
  2595. else if(strcmp(newString[0], "speed") == 0)
  2596. {
  2597. // 取得風扇速度
  2598. GetFanSpeed();
  2599. }
  2600. else if(strcmp(newString[0], "debug") == 0)
  2601. {
  2602. // 設定 debug mode
  2603. SetDebugMode(newString[1]);
  2604. }
  2605. else if (strcmp(newString[0], "gfd") == 0)
  2606. {
  2607. // 設定盲沖使用 GFD 功能
  2608. SetGFDMode(newString[1]);
  2609. }
  2610. else if(strcmp(newString[0], "temp") == 0)
  2611. {
  2612. // 取得溫度
  2613. GetTemperature(newString[1]);
  2614. }
  2615. else if(strcmp(newString[0], "acin") == 0)
  2616. {
  2617. // 取得三向輸入電壓
  2618. GetAcInputVol();
  2619. }
  2620. else if(strcmp(newString[0], "psu") == 0)
  2621. {
  2622. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  2623. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2624. {
  2625. printf ("PSU : Param fail..Please retry again......\n");
  2626. continue;
  2627. }
  2628. // 取得 PSU 資訊
  2629. GetPsuInformation(newString[1], newString[2], newString[3]);
  2630. }
  2631. else if (strcmp(newString[0], "cap") == 0)
  2632. {
  2633. GetConnectorCapInfo(newString[1]);
  2634. }
  2635. else if(strcmp(newString[0], "error") == 0)
  2636. {
  2637. CreateOneError(newString[1]);
  2638. }
  2639. else if (strcmp(newString[0], "auth") == 0)
  2640. {
  2641. GetAuthorizeFlag(newString[1]);
  2642. }
  2643. else if (strcmp(newString[0], "id") == 0)
  2644. {
  2645. GetOrClearId(newString[1]);
  2646. }
  2647. #if 0
  2648. else if(strcmp(newString[0], "strchg") == 0)
  2649. {
  2650. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  2651. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2652. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2653. {
  2654. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  2655. continue;
  2656. }
  2657. // 槍狀態
  2658. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  2659. }
  2660. else if(strcmp(newString[0], "str2chg") == 0)
  2661. {
  2662. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  2663. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2664. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  2665. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  2666. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  2667. {
  2668. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  2669. continue;
  2670. }
  2671. // 槍狀態
  2672. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  2673. }
  2674. #endif
  2675. else if(strcmp(newString[0], "wiring") == 0)
  2676. {
  2677. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  2678. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  2679. {
  2680. SetWiringInfo(newString[1], newString[2]);
  2681. }
  2682. ShowWiringInfo();
  2683. }
  2684. else if(strcmp(newString[0], "cwiring") == 0)
  2685. {
  2686. CleanWiringInfo();
  2687. }
  2688. else if(strcmp(newString[0], "reset") == 0)
  2689. {
  2690. SetSystemSoftRest();
  2691. }
  2692. else if(strcmp(newString[0], "reboot") == 0)
  2693. {
  2694. SetSystemHardReboot();
  2695. }
  2696. else if(strcmp(newString[0], "sgroup") == 0)
  2697. {
  2698. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2699. {
  2700. ShowGroupingInfo();
  2701. continue;
  2702. }
  2703. RunSimplePsuGrouping(newString[1], newString[2]);
  2704. }
  2705. else if(strcmp(newString[0], "cabinet") == 0)
  2706. {
  2707. ShowCabinetInfo();
  2708. }
  2709. else if(strcmp(newString[0], "tctl") == 0)
  2710. {
  2711. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2712. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2713. {
  2714. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  2715. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  2716. continue;
  2717. }
  2718. SetTestControl(newString[1], newString[2]);
  2719. }
  2720. else if(strcmp(newString[0], "group") == 0)
  2721. {
  2722. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2723. {
  2724. ShowGroupingInfo();
  2725. continue;
  2726. }
  2727. }
  2728. else if(strcmp(newString[0], "gdmd") == 0)
  2729. {
  2730. ShowGroupingDemand();
  2731. }
  2732. else if(strcmp(newString[0], "gunchg") == 0)
  2733. {
  2734. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2735. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  2736. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  2737. {
  2738. printf ("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\n\n");
  2739. continue;
  2740. }
  2741. SetGunStartCharging(newString[1], newString[2], newString[3]);
  2742. }
  2743. else if(strcmp(newString[0], "gunstp") == 0)
  2744. {
  2745. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2746. {
  2747. printf ("Input cmd fail ------ gunstp [gun 1-4]\n\n");
  2748. continue;
  2749. }
  2750. SetGunStopCharging(newString[1]);
  2751. }
  2752. else if(strcmp(newString[0], "gunext") == 0)
  2753. {
  2754. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2755. {
  2756. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  2757. continue;
  2758. }
  2759. SetGunExtend(newString[1]);
  2760. }
  2761. else if(strcmp(newString[0], "output") == 0)
  2762. {
  2763. ShowGunOutput();
  2764. }
  2765. else if(strcmp(newString[0], "gio") == 0)
  2766. {
  2767. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2768. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2769. {
  2770. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  2771. continue;
  2772. }
  2773. SetGpio(newString[1], newString[2]);
  2774. }
  2775. else if(strcmp(newString[0], "status") == 0)
  2776. {
  2777. ShowStatus();
  2778. }
  2779. else if(strcmp(newString[0], "whiteR") == 0)
  2780. {
  2781. ShowWhiteCardList();
  2782. }
  2783. else if(strcmp(newString[0], "whiteW") == 0)
  2784. {
  2785. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  2786. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  2787. {
  2788. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  2789. continue;
  2790. }
  2791. WriteWhiteCard(newString[1], newString[2]);
  2792. }
  2793. else if(strcmp(newString[0], "whiteE") == 0)
  2794. {
  2795. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  2796. {
  2797. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  2798. continue;
  2799. }
  2800. EraseWhiteCard(newString[1]);
  2801. }
  2802. else
  2803. printf ("%s\n", msg);
  2804. usleep(100000);
  2805. }
  2806. return 0;
  2807. }