ReadCmdline.c 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117
  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 NO_DEFINE 255
  42. #define OPTION_CNT 3
  43. #define STR_OPTION '-'
  44. #define OPTION_REFLASH 0x00000001
  45. #define OPTION_LOOP 0x00000002
  46. #define OPTION_TIME 0x00000004
  47. #define STR_OPT_REFLASH 'f'
  48. #define STR_OPT_LOOP 'l'
  49. #define STR_OPT_TIME 't'
  50. #define TTY_PATH "/dev/tty"
  51. #define STTY_US "stty raw -echo -F "
  52. #define STTY_DEF "stty -raw echo -F "
  53. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  54. struct StatusCodeData *ShmStatusCodeData;
  55. struct PrimaryMcuData *ShmPrimaryMcuData;
  56. struct CHAdeMOData *ShmCHAdeMOData;
  57. struct CcsData *ShmCcsData;
  58. struct GBTData *ShmGBTData;
  59. struct FanModuleData *ShmFanModuleData;
  60. struct RelayModuleData *ShmRelayModuleData;
  61. struct LedModuleData *ShmLedModuleData;
  62. struct PsuData *ShmPsuData;
  63. ChargerInfoData *ShmChargerInfo;
  64. PsuPositionInfoData *ShmPsuPosition;
  65. PsuGroupingInfoData *ShmPsuGrouping;
  66. struct OCPP16Data *ShmOCPP16Data;
  67. struct OCPP20Data *ShmOCPP20Data;
  68. struct ChargingInfoData *_chargingData[CONNECTOR_QUANTITY];
  69. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  70. char *msg = "state : get gun state (index) \n"
  71. "card : scanning card (x) : \n"
  72. "gun : get gun plugit state (index) \n"
  73. "lock : get gun locked state (index) \n"
  74. "self : self test state (x) \n"
  75. "ver : ver of board (407 or index or rb or fan) \n"
  76. "ac : get ac relay state (x) \n"
  77. "gunchg: set gun start charging \n"
  78. "gunstp: set gun stop charging \n"
  79. "gunext: extend gun capability \n";
  80. bool FindChargingInfoData(byte target, struct ChargingInfoData **chargingData)
  81. {
  82. for (byte index = 0; index < CHAdeMO_QUANTITY; index++)
  83. {
  84. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target)
  85. {
  86. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  87. return true;
  88. }
  89. }
  90. for (byte index = 0; index < CCS_QUANTITY; index++)
  91. {
  92. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target)
  93. {
  94. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  95. return true;
  96. }
  97. }
  98. for (byte index = 0; index < GB_QUANTITY; index++)
  99. {
  100. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target)
  101. {
  102. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  103. return true;
  104. }
  105. }
  106. if(GENERAL_GUN_QUANTITY > 0 && target < GENERAL_GUN_QUANTITY)
  107. {
  108. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ConnectorInfo[target].GeneralChargingData;
  109. return true;
  110. }
  111. return false;
  112. }
  113. bool FindAcChargingInfoData(byte target, struct ChargingInfoData **acChargingData)
  114. {
  115. if (target < AC_QUANTITY)
  116. {
  117. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  118. return true;
  119. }
  120. return false;
  121. }
  122. int InitShareMemory()
  123. {
  124. int result = PASS;
  125. int MeterSMId;
  126. //initial ShmSysConfigAndInfo
  127. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0)
  128. {
  129. result = FAIL;
  130. }
  131. else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  132. {
  133. result = FAIL;
  134. }
  135. else
  136. {}
  137. //initial ShmStatusCodeData
  138. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0)
  139. {
  140. result = FAIL;
  141. }
  142. else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  143. {
  144. result = FAIL;
  145. }
  146. else
  147. {}
  148. if (CHAdeMO_QUANTITY > 0) {
  149. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  150. IPC_CREAT | 0777)) < 0) {
  151. result = FAIL;
  152. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  153. == (void *) -1) {
  154. result = FAIL;
  155. } else {
  156. }
  157. }
  158. if (CCS_QUANTITY > 0) {
  159. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  160. IPC_CREAT | 0777)) < 0) {
  161. result = FAIL;
  162. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  163. result = FAIL;
  164. } else {
  165. }
  166. }
  167. if (GB_QUANTITY > 0) {
  168. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  169. IPC_CREAT | 0777)) < 0) {
  170. return 0;
  171. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) -1) {
  172. return 0;
  173. }
  174. memset(ShmGBTData, 0, sizeof(struct GBTData));
  175. }
  176. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0)
  177. {
  178. result = FAIL;
  179. }
  180. else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  181. {
  182. result = FAIL;
  183. }
  184. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0)
  185. {
  186. result = FAIL;
  187. }
  188. else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  189. {
  190. result = FAIL;
  191. }
  192. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0)
  193. {
  194. result = FAIL;
  195. }
  196. else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  197. {
  198. result = FAIL;
  199. }
  200. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0)
  201. {
  202. result = FAIL;
  203. }
  204. else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  205. {
  206. result = FAIL;
  207. }
  208. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0)
  209. {
  210. result = FAIL;
  211. }
  212. else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  213. {
  214. result = FAIL;
  215. }
  216. if ((MeterSMId = shmget(SM_ChargerInfoKey, sizeof(ChargerInfoData), IPC_CREAT | 0777)) < 0)
  217. {
  218. result = FAIL;
  219. }
  220. else if ((ShmChargerInfo = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  221. {
  222. result = FAIL;
  223. }
  224. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), 0777)) < 0)
  225. {
  226. result = FAIL;
  227. }
  228. else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  229. {
  230. result = FAIL;
  231. }
  232. if ((MeterSMId = shmget(ShmOcpp20ModuleKey, sizeof(struct OCPP20Data), 0777)) < 0)
  233. {
  234. result = FAIL;
  235. }
  236. else if ((ShmOCPP20Data = shmat(MeterSMId, NULL, 0)) == (void *) -1)
  237. {
  238. result = FAIL;
  239. }
  240. if(result == PASS)
  241. {
  242. ShmPsuPosition = &ShmChargerInfo->PsuPosition;
  243. ShmPsuGrouping = &ShmChargerInfo->PsuGrouping;
  244. }
  245. return result;
  246. }
  247. void Get_Ocpp_TransactionId(int gun_index, char *transactionId)
  248. {
  249. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_16)
  250. {
  251. sprintf(transactionId, "%d", ShmOCPP16Data->StartTransaction[gun_index].ResponseTransactionId);
  252. return;
  253. }
  254. if(ShmSysConfigAndInfo->SysInfo.OcppRunningVer == OCPP_RUNNING_VERSION_20)
  255. {
  256. strcpy(transactionId, (char *)&ShmOCPP20Data->TransactionEvent [gun_index].transactionInfo.transactionId[0]);
  257. return;
  258. }
  259. sprintf(transactionId, "%d", 0);
  260. }
  261. static void get_char(char *word)
  262. {
  263. fd_set rfds;
  264. struct timeval tv;
  265. FD_ZERO(&rfds);
  266. FD_SET(0, &rfds);
  267. tv.tv_sec = 0;
  268. tv.tv_usec = 10; //wait input timout time
  269. //if input
  270. if (select(1, &rfds, NULL, NULL, &tv) > 0)
  271. {
  272. fgets(word, 128, stdin);
  273. }
  274. }
  275. // return command length
  276. int ParsingCmd(char *inputString, char *outputString)
  277. {
  278. bool valid = false, done = false;
  279. int len = 0, start = 0;
  280. for(int i = 0; i < strlen(inputString); i++)
  281. {
  282. if(!valid)
  283. {
  284. if(inputString[i] != ' ' && inputString[i] != '\0' && inputString[i] != '\r' && inputString[i] != '\n')
  285. {
  286. valid = true;
  287. start = i;
  288. }
  289. }
  290. else
  291. {
  292. if(inputString[i] == ' ' || inputString[i] == '\0' || inputString[i] == '\r' || inputString[i] == '\n' || len >= 32)
  293. {
  294. done = true;
  295. break;
  296. }
  297. }
  298. len = (valid && !done) ? len + 1 : len;
  299. }
  300. if(valid)
  301. {
  302. memcpy(outputString, &inputString[start], len);
  303. outputString[len] = '\0';
  304. }
  305. return len;
  306. }
  307. bool IsOption(char *strCmd, unsigned int *opt)
  308. {
  309. int len = 0;
  310. char str_opt[OPTION_CNT] = {STR_OPT_REFLASH, STR_OPT_LOOP, STR_OPT_TIME};
  311. unsigned int opt_value[OPTION_CNT] = {OPTION_REFLASH, OPTION_LOOP, OPTION_TIME};
  312. len = strlen(strCmd);
  313. if(len == 2)
  314. {
  315. if(strCmd[0] == STR_OPTION)
  316. {
  317. for(int i = 0; i < OPTION_CNT; i++)
  318. {
  319. if(strCmd[1] == str_opt[i])
  320. {
  321. *opt |= opt_value[i];
  322. return true;
  323. }
  324. }
  325. }
  326. }
  327. return false;
  328. }
  329. // inputCmdString: console input string
  330. // outputCmdString: input string parsed
  331. // return command quantity
  332. int InputStringNormalize(char *inputCmdString, char *outputCmdString, unsigned int *opt)
  333. {
  334. int len = 0, cnt = 0, start = 0;
  335. int cmdLen = 0, totalLen = 0;
  336. len = strlen(inputCmdString);
  337. *opt = 0;
  338. if(len > 0)
  339. {
  340. while(start < len)
  341. {
  342. if(inputCmdString[start] != ' ' && inputCmdString[start] != '\0' &&
  343. inputCmdString[start] != '\r' && inputCmdString[start] != '\n')
  344. {
  345. cmdLen = ParsingCmd(&inputCmdString[start], &outputCmdString[totalLen]);
  346. if(cmdLen > 0)
  347. {
  348. //printf("Find %d Cmd: %s\r\n", cnt + 1, &outputCmdString[totalLen]);
  349. if(!IsOption(&outputCmdString[totalLen], opt))
  350. {
  351. outputCmdString[totalLen + cmdLen] = ' ';
  352. cnt++;
  353. totalLen += cmdLen + 1;
  354. }
  355. start += cmdLen;
  356. }
  357. }
  358. else
  359. {
  360. start++;
  361. }
  362. }
  363. outputCmdString[totalLen - 1] = '\0';
  364. }
  365. return cnt;
  366. }
  367. int MainAndSubCommandParsing(char *normalCmd, char *mainCmd, char *subCmd)
  368. {
  369. int len = 0, totalLen = 0;
  370. strcpy(mainCmd, "");
  371. strcpy(subCmd, "");
  372. totalLen = strlen(normalCmd);
  373. if(totalLen > 0)
  374. {
  375. len = ParsingCmd(normalCmd, mainCmd);
  376. //printf("Find MainCmd: %s\r\n", mainCmd);
  377. if(len > 0 && totalLen > len)
  378. {
  379. strcpy(subCmd, &normalCmd[len + 1]);
  380. //printf("Find SubCmd: %s\r\n", subCmd);
  381. }
  382. }
  383. return 0;
  384. }
  385. int GetCommandSring(char *outputCmdString)
  386. {
  387. int len = 0, cnt = 0;
  388. int cmdLen = 0, totalLen = 0;
  389. char word[128];
  390. memset(word, 0x00, sizeof(word));
  391. get_char(word);
  392. len = strlen(word);
  393. if(len == 0)
  394. {
  395. return -1;
  396. }
  397. int start = 0;
  398. while(start < len - 1)
  399. {
  400. if(word[start] != ' ' && word[start] != '\0')
  401. {
  402. cmdLen = ParsingCmd(&word[start], &outputCmdString[totalLen]);
  403. char newCmd[32];
  404. memset(newCmd, 0x00, 32);
  405. memcpy(newCmd, &outputCmdString[totalLen], cmdLen);
  406. cnt = cmdLen > 0 ? cnt + 1 : cnt;
  407. totalLen += cmdLen + 1;
  408. start += cmdLen;
  409. }
  410. else
  411. {
  412. start++;
  413. }
  414. }
  415. return cnt;
  416. }
  417. bool IsLoopStopCmd(void)
  418. {
  419. bool stop = false;
  420. int cnt = 0;
  421. char cmd[256];
  422. char totalCmd[256];
  423. memset(cmd, 0x00, 256);
  424. memset(totalCmd, 0x00, 256);
  425. cnt = GetCommandSring(totalCmd);
  426. if(cnt > 0)
  427. {
  428. strcpy(&cmd[0], totalCmd);
  429. if(strcmp(&cmd[0], "c") == 0)
  430. {
  431. stop = true;
  432. }
  433. }
  434. return stop;
  435. }
  436. void ConsoleReflash(int groupCnt, int lineCnt)
  437. {
  438. for(int i = 0; i < groupCnt; i++)
  439. {
  440. for(int i = 0; i < lineCnt; i++)
  441. {
  442. printf("\033[1A");
  443. printf("\033[K");
  444. }
  445. }
  446. printf("\r");
  447. }
  448. void RunStatusProc(char *v1, char *v2)
  449. {
  450. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  451. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  452. if (strcmp(v1, "ac") == 0)
  453. {
  454. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  455. {
  456. printf("FindChargingInfoData (AC) false \n");
  457. }
  458. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  459. return;
  460. }
  461. int _index = atoi(v1);
  462. if (_index <= 1)
  463. {
  464. if (!FindChargingInfoData(_index, &_chargingData[0]))
  465. {
  466. printf ("FindChargingInfoData error\n");
  467. return;
  468. }
  469. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  470. {
  471. // get
  472. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  473. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  474. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  475. printf("ConnectorAlarmCode = %s \n", _chargingData[_index]->ConnectorAlarmCode);
  476. printf("EvConnAlarmCode = %s \n", _chargingData[_index]->EvConnAlarmCode);
  477. printf("RemotenAlarmCode = %s \n", ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].RemotenAlarmCode);
  478. }
  479. else
  480. {
  481. // set
  482. _chargingData[_index]->SystemStatus = atoi(v2);
  483. }
  484. }
  485. else
  486. {
  487. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  488. {
  489. printf("FindChargingInfoData (AC) false \n");
  490. }
  491. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  492. {
  493. // get
  494. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  495. }
  496. else
  497. {
  498. // set
  499. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  500. }
  501. }
  502. }
  503. void RunCardProc(char *v1, char *v2)
  504. {
  505. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  506. {
  507. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit)
  508. {
  509. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  510. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  511. }
  512. else
  513. {
  514. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  515. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  516. }
  517. }
  518. else
  519. {
  520. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  521. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  522. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  523. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  524. }
  525. }
  526. void RunGunPlugitProc(char *v1, char *v2)
  527. {
  528. if (strcmp(v1, "ac") == 0)
  529. {
  530. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0]))
  531. {
  532. printf("FindChargingInfoData (AC) false \n");
  533. }
  534. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  535. {
  536. // get
  537. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  538. }
  539. else
  540. {
  541. // set
  542. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  543. }
  544. return;
  545. }
  546. int _index = atoi(v1);
  547. if (!FindChargingInfoData(_index, &_chargingData[0]))
  548. {
  549. printf("FindChargingInfoData error\n");
  550. return;
  551. }
  552. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0)
  553. {
  554. // get
  555. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  556. }
  557. else
  558. {
  559. // set
  560. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  561. }
  562. }
  563. void GetGunLockStatusProc(char *v1, char *v2)
  564. {
  565. int _index = atoi(v1);
  566. if (!FindChargingInfoData(_index, &_chargingData[0]))
  567. {
  568. printf("FindChargingInfoData error\n");
  569. return;
  570. }
  571. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0)
  572. {
  573. _chargingData[_index]->GunLocked = atoi(v2);
  574. }
  575. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  576. }
  577. void SetSystemIDProc()
  578. {
  579. char *systemId = "Alston_Test";
  580. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  581. }
  582. void RunSelfProc()
  583. {
  584. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  585. }
  586. void ShowFwVer(void)
  587. {
  588. printf("\r\nPower Cabinet, Model Name: %s, SN: %s", ShmSysConfigAndInfo->SysConfig.ModelName, ShmSysConfigAndInfo->SysConfig.SerialNumber);
  589. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.CsuBootLoadFwRev);
  590. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev);
  591. printf("\r\n Csu Kernel: ");
  592. for(int i = 0; i < strlen((char *)ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev); i++)
  593. {
  594. if(ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\r' && ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i] != '\n')
  595. {
  596. printf("%c", ShmSysConfigAndInfo->SysInfo.CsuKernelFwRev[i]);
  597. }
  598. }
  599. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  600. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.CsuPrimFwRev);
  601. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  602. printf("\r\n Relay1 Module: %s", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  603. printf("\r\n Relay2 Module: %s", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  604. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  605. {
  606. printf("\r\n\r\nDispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  607. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  608. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  609. {
  610. printf(", Model Name: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName);
  611. printf("\r\n Csu Bootload: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuBootLoadFwRev);
  612. //printf("\r\n Csu Kernel: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev);
  613. printf("\r\n Csu Kernel: ");
  614. for(int j = 0; j < strlen((char *)ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev); j++)
  615. {
  616. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\r' &&
  617. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j] != '\n')
  618. {
  619. printf("%c", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuKernelFwRev[j]);
  620. }
  621. }
  622. printf("\r\n Csu Root Fs: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuRootFsFwRev);
  623. printf("\r\n Csu Primary: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].CsuPrimFwRev);
  624. printf("\r\n Fan Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].FanModuleFwRev);
  625. printf("\r\n Relay Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].RelayModuleFwRev);
  626. printf("\r\n Connector 1: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector1FwRev);
  627. printf("\r\n Connector 2: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].Connector2FwRev);
  628. printf("\r\n Led Module: %s", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LedModuleFwRev);
  629. }
  630. }
  631. printf("\r\n\r\n");
  632. }
  633. void GetFwVerProc(char *v1)
  634. {
  635. if (strcmp(v1, "407") == 0)
  636. {
  637. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  638. }
  639. else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0 || strcmp(v1, "2") == 0 || strcmp(v1, "3") == 0)
  640. {
  641. int _index = atoi(v1);
  642. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].Enable)
  643. {
  644. int dispenser = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].ParentDispensetIndex;
  645. int ParentIndex = ShmSysConfigAndInfo->SysInfo.ConnectorInfo[_index].GeneralChargingData.Index;
  646. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_None &&
  647. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].LocalStatus != _DS_Timeout)
  648. {
  649. if(ParentIndex == 0)
  650. {
  651. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  652. }
  653. else
  654. {
  655. printf("Gun %d FW Version = %s \n", _index, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser].Connector1FwRev);
  656. }
  657. }
  658. }
  659. else
  660. {
  661. printf("Gun %d is disable\r\n", _index);
  662. }
  663. }
  664. else if (strcmp(v1, "rb") == 0)
  665. {
  666. printf("RB1 Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  667. printf("RB2 Version = %s \n", ShmSysConfigAndInfo->SysInfo.Relay2ModuleFwRev);
  668. }
  669. else if (strcmp(v1, "fan") == 0)
  670. {
  671. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  672. }
  673. else if (strcmp(v1, "dc") == 0)
  674. {
  675. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  676. }
  677. else if (strcmp(v1, "led") == 0)
  678. {
  679. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  680. }
  681. }
  682. void CreateOneError(char *v1)
  683. {
  684. int value = atoi(v1);
  685. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.PrimaryStestFail = value;
  686. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  687. }
  688. void GetAuthorizeFlag(char *v1)
  689. {
  690. if (strcmp(v1, "-1") == 0|| strcmp(v1, "") == 0)
  691. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  692. else
  693. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  694. }
  695. void GetOrClearId(char *v1)
  696. {
  697. int _index = atoi(v1);
  698. if (!FindChargingInfoData(_index, &_chargingData[0]))
  699. {
  700. printf("FindChargingInfoData error\n");
  701. return;
  702. }
  703. printf("Card Number = %s \n", _chargingData[_index]->StartUserId);
  704. }
  705. void FwUpdateFlagProc()
  706. {
  707. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  708. }
  709. void CheckAcStatus(char *v1)
  710. {
  711. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0)
  712. {
  713. printf(" AC Contactor Ctrl: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactor);
  714. printf(" AC Off By Psu : %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu);
  715. printf(" AC Off ByEmergency: %d\r\n", ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency);
  716. printf("AC Contactor Status: %d\r\n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  717. }
  718. else
  719. {
  720. if(system("pidof -s main > /dev/null") != 0)
  721. {
  722. if(strcmp(v1, "0") == 0)
  723. {
  724. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = false;
  725. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  726. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  727. printf("Set AC Contactor Off\r\n");
  728. }
  729. else
  730. {
  731. ShmChargerInfo->Control.RelayCtrl.bits.AcContactor = true;
  732. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByPsu = false;
  733. ShmChargerInfo->Control.RelayCtrl.bits.AcContactorOffByEmergency = false;
  734. printf("Set AC Contactor On\r\n");
  735. }
  736. }
  737. else
  738. {
  739. printf("main task is running\r\n");
  740. }
  741. }
  742. }
  743. void SetCableChkStatus(char *v1, char *v2)
  744. {
  745. int _index = atoi(v1);
  746. if (!FindChargingInfoData(_index, &_chargingData[0]))
  747. {
  748. printf ("FindChargingInfoData error\n");
  749. return;
  750. }
  751. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  752. }
  753. void SetPowerValue(char *v1, char *v2)
  754. {
  755. int _index = atoi(v1);
  756. float _Current = atof(v2);
  757. // 盲沖的時候才允許使用~
  758. if (_chargingData[_index]->Type != 9)
  759. return;
  760. if (!FindChargingInfoData(_index, &_chargingData[0]))
  761. {
  762. printf ("FindChargingInfoData error\n");
  763. return;
  764. }
  765. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  766. }
  767. void GetSystemInfo()
  768. {
  769. printf ("\r\n ModelName = %s", ShmSysConfigAndInfo->SysConfig.ModelName);
  770. printf ("\r\nSerialNumber = %s", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  771. printf ("\r\nInternetConn = %d", ShmSysConfigAndInfo->SysInfo.InternetConn);
  772. printf ("\r\nMaxChargingPower = %d kW, MaxChargingCurrent = %d A",
  773. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  774. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  775. printf("\r\n\r\n");
  776. }
  777. void SetFanSpeed(char *v1)
  778. {
  779. int speed = atoi(v1);
  780. ShmFanModuleData->TestFanSpeed = speed;
  781. }
  782. void GetFanSpeed()
  783. {
  784. printf("Target Speed = %d \n", ShmFanModuleData->TestFanSpeed);
  785. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  786. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  787. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  788. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  789. }
  790. void SetDebugMode(char *v1)
  791. {
  792. int mode = atoi(v1);
  793. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  794. }
  795. void SetGFDMode(char *v1)
  796. {
  797. int mode = atoi(v1);
  798. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  799. }
  800. // PSU 0 PSU 1 PSU 2 ...
  801. // Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb
  802. // 1 XXX XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX XXX/XXX/XXX
  803. void GetTemperature(char *inputCmd, unsigned int opt)
  804. {
  805. bool keepRun = false;
  806. bool reflash = false;
  807. int time = 0;
  808. struct timespec _Loop_time;
  809. char strGunTemp[16], strChillerTemp[16];
  810. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  811. {
  812. keepRun = true;
  813. }
  814. printf("\r\n");
  815. printf(" PSU 0 PSU 1 PSU 2 .....\r\n");
  816. printf(" Gun Temp Chiller DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb DD/PFC/Amb\r\n");
  817. do
  818. {
  819. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  820. if(time >= 1000)
  821. {
  822. if(reflash)
  823. {
  824. ConsoleReflash(CONNECTOR_QUANTITY, 1);
  825. }
  826. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  827. {
  828. sprintf(strGunTemp, "N/A");
  829. sprintf(strChillerTemp, "N/A");
  830. if(_chargingData[i]->ConnectorTemp != 0 && _chargingData[i]->ConnectorTemp != 0xFF)
  831. {
  832. sprintf(strGunTemp, "%3d", _chargingData[i]->ConnectorTemp - 60);
  833. }
  834. if(_chargingData[i]->ChillerTemp != 0 && _chargingData[i]->ChillerTemp != 0xFF)
  835. {
  836. sprintf(strChillerTemp, "%3d", _chargingData[i]->ChillerTemp - 60);
  837. }
  838. printf(" %d %s %s ", i + 1, strGunTemp, strChillerTemp);
  839. for(int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  840. {
  841. printf(" %3d/%3d/%3d",
  842. ShmPsuData->PsuGroup[i].PsuModule[j].ExletTemp,
  843. ShmPsuData->PsuGroup[i].PsuModule[j].InletTemp,
  844. ShmPsuData->PsuGroup[i].PsuModule[j].CriticalTemp1);
  845. }
  846. printf("\r\n");
  847. }
  848. GetClockTime(&_Loop_time);
  849. if((opt & OPTION_REFLASH) > 0)
  850. {
  851. reflash = true;
  852. }
  853. }
  854. if(keepRun)
  855. {
  856. keepRun = IsLoopStopCmd() ? false : true;
  857. usleep(10000);
  858. }
  859. }while(keepRun);
  860. }
  861. void GetInputVol(char *inputCmd, unsigned int opt)
  862. {
  863. bool keepRun = false;
  864. bool reflash = false;
  865. int time = 0;
  866. struct timespec _Loop_time;
  867. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  868. {
  869. keepRun = true;
  870. }
  871. printf("\r\n");
  872. do
  873. {
  874. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  875. if(time >= 1000)
  876. {
  877. if(reflash)
  878. {
  879. ConsoleReflash(1, 1);
  880. }
  881. printf("L1N_L12 = %4.1f V, L2N_L23 = %4.1f V, L3N_L31 = %4.1f V, DC Input: %4.1f V\r\n",
  882. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  883. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  884. ShmSysConfigAndInfo->SysInfo.InputVoltageT,
  885. ShmSysConfigAndInfo->SysInfo.InputVoltageDc);
  886. GetClockTime(&_Loop_time);
  887. if((opt & OPTION_REFLASH) > 0)
  888. {
  889. reflash = true;
  890. }
  891. }
  892. if(keepRun)
  893. {
  894. keepRun = IsLoopStopCmd() ? false : true;
  895. usleep(10000);
  896. }
  897. }while(keepRun);
  898. printf("\r\n");
  899. }
  900. void GetPsuInformation(char *v1, char *v2, char *v3)
  901. {
  902. printf("**********************AC Contact needed*************************\n");
  903. if(strcmp(v1, "count") == 0)
  904. {
  905. for (int i = 0; i < 4; i++)
  906. {
  907. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  908. }
  909. }
  910. else if(strcmp(v1, "ver") == 0)
  911. {
  912. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++)
  913. {
  914. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  915. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  916. }
  917. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  918. {
  919. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++)
  920. {
  921. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  922. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  923. }
  924. }
  925. }
  926. else if(strcmp(v1, "cap") == 0)
  927. {
  928. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  929. {
  930. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  931. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  932. }
  933. }
  934. else if(strcmp(v1, "input") == 0)
  935. {
  936. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  937. {
  938. for (byte count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++)
  939. {
  940. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  941. i, count,
  942. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  943. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  944. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  945. }
  946. }
  947. }
  948. else if (strcmp(v1, "output") == 0)
  949. {
  950. for (int i = 0; i < ShmPsuData->GroupCount; i++)
  951. {
  952. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  953. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  954. }
  955. }
  956. else if (strcmp(v1, "test") == 0)
  957. {
  958. int mode = atoi(v2);
  959. if (mode >= _TEST_MODE && mode <= _TEST_MODE)
  960. {
  961. ShmPsuData->Work_Step = mode;
  962. }
  963. }
  964. else if (strcmp(v1, "out") == 0)
  965. {
  966. float vol = atof(v2);
  967. float cur = atof(v3);
  968. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE)
  969. {
  970. if (!FindChargingInfoData(0, &_chargingData[0]))
  971. {
  972. printf ("FindChargingInfoData error\n");
  973. return;
  974. }
  975. _chargingData[0]->EvBatterytargetVoltage = vol;
  976. _chargingData[0]->EvBatterytargetCurrent = cur;
  977. }
  978. }
  979. printf("*************************************************\n");
  980. }
  981. void GetConnectorCapInfo(char *v1)
  982. {
  983. int _GunIndex = atoi(v1);
  984. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  985. {
  986. printf ("FindChargingInfoData error\n");
  987. return;
  988. }
  989. printf ("Charger Max Current = %d, Max Power = %d \n",
  990. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  991. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  992. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  993. _GunIndex,
  994. _chargingData[_GunIndex]->RealMaxPower,
  995. _chargingData[_GunIndex]->RealMaxVoltage,
  996. _chargingData[_GunIndex]->RealMaxCurrent);
  997. }
  998. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  999. {
  1000. int _GunIndex = atoi(v1);
  1001. float _Voltage = atof(v2);
  1002. float _Current = atof(v3);
  1003. unsigned char PreviousSystemStatus = 0xff;
  1004. if (!FindChargingInfoData(_GunIndex, &_chargingData[0]))
  1005. {
  1006. printf ("FindChargingInfoData error\n");
  1007. return;
  1008. }
  1009. printf ("ReqVoltage = %f, ReqCurrent = %f\n", _Voltage, _Current);
  1010. if(_Voltage > 1000 || _Voltage < 50)
  1011. {
  1012. printf ("Input Voltage over range\n");
  1013. return;
  1014. }
  1015. // if(_Current > 100 || _Current < 2){
  1016. //
  1017. // printf ("Input Current over range\n");
  1018. // return;
  1019. // }
  1020. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  1021. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  1022. //kill ev task
  1023. system("killall Module_EvComm");
  1024. //_Voltage = (_Voltage * 10);
  1025. //_Current = (_Current * 10);
  1026. //system(STTY_US TTY_PATH);
  1027. while(true)
  1028. {
  1029. //fix gun 1
  1030. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  1031. switch(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1032. {
  1033. case S_IDLE:
  1034. {
  1035. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1036. {
  1037. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1038. printf ("[UnconditionalCharge - S_IDLE]\n");
  1039. }
  1040. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  1041. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  1042. }
  1043. break;
  1044. case S_PREPARNING:
  1045. {
  1046. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1047. {
  1048. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1049. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  1050. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1051. printf ("wait find module\n");
  1052. }
  1053. //main 會在此階段判斷以下資料跳到下一個 state
  1054. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  1055. //ShmPsuData->SystemPresentPsuQuantity;
  1056. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  1057. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  1058. //_chargingData[gun_index]->AvailableChargingPower;
  1059. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  1060. //sleep(10);
  1061. //清除 main timeout 機制
  1062. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1063. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1064. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1065. }
  1066. break;
  1067. case S_PREPARING_FOR_EV:
  1068. {
  1069. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1070. {
  1071. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1072. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  1073. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10,_Current * 10);
  1074. }
  1075. //清除 main timeout 機制
  1076. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1077. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1078. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1079. //充電電壓電流
  1080. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1081. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1082. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1083. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1084. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1085. //確定模組己升壓完成
  1086. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  1087. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  1088. {
  1089. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1090. //EV done
  1091. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  1092. }
  1093. }
  1094. break;
  1095. case S_PREPARING_FOR_EVSE:
  1096. {
  1097. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1098. {
  1099. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1100. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  1101. }
  1102. //printf ("tar vol = %d \n", _Voltage);
  1103. //printf ("tar cur = %d \n", _Current);
  1104. //清除 main timeout 機制
  1105. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  1106. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1107. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  1108. //充電電壓電流
  1109. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1110. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  1111. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  1112. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1113. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  1114. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  1115. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  1116. //確定模組己升壓完成
  1117. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  1118. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03)
  1119. //{
  1120. //printf ("First Ground Fault State (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1121. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  1122. sleep(5);
  1123. //EV done
  1124. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  1125. //}
  1126. //else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02)
  1127. //{
  1128. // printf ("First Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1129. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1130. //}
  1131. }
  1132. break;
  1133. case S_CHARGING:
  1134. {
  1135. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1136. {
  1137. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1138. //充電電壓電流
  1139. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  1140. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  1141. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  1142. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  1143. printf ("[UnconditionalCharge - S_CHARGING]\n");
  1144. }
  1145. //ev task do this
  1146. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  1147. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  1148. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02){
  1149. printf ("Charging Ground Fault check Fail (%d)\n",_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  1150. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1151. }
  1152. }
  1153. break;
  1154. case S_TERMINATING:
  1155. {
  1156. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1157. {
  1158. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1159. system("/root/Module_EvComm &");
  1160. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  1161. //無阻塞偵測 keybaord 結束
  1162. system(STTY_DEF TTY_PATH);
  1163. }
  1164. sleep(3);
  1165. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  1166. return;
  1167. }
  1168. break;
  1169. case S_COMPLETE:
  1170. {
  1171. if(PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus)
  1172. {
  1173. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  1174. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  1175. }
  1176. sleep(3);
  1177. return;
  1178. }
  1179. break;
  1180. }
  1181. char word[128];
  1182. char newString[7][10];
  1183. int i,j,ctr;
  1184. memset(word, 0x00, sizeof(word));
  1185. get_char(word);
  1186. if (strlen(word) == 0)
  1187. {
  1188. continue;
  1189. }
  1190. j=0; ctr=0;
  1191. strcpy(newString[1], "-1");
  1192. strcpy(newString[2], "-1");
  1193. for (i = 0; i <= (strlen(word)); i++)
  1194. {
  1195. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1196. {
  1197. newString[ctr][j] = '\0';
  1198. ctr++;
  1199. j = 0;
  1200. }
  1201. else
  1202. {
  1203. newString[ctr][j] = word[i];
  1204. j++;
  1205. }
  1206. }
  1207. if(strcmp(newString[0], "chg") == 0)
  1208. {
  1209. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1210. continue;
  1211. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1212. continue;
  1213. float _vol = atof(newString[1]);
  1214. float _cur = atof(newString[2]);
  1215. if (_cur <= 0 || _cur <= 0)
  1216. continue;
  1217. printf("vol = %f, cur = %f \n", _vol, _cur);
  1218. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  1219. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  1220. }
  1221. else if (strcmp(newString[0], "c") == 0)
  1222. {
  1223. printf("stop \n\r");
  1224. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  1225. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  1226. }
  1227. usleep(100000);
  1228. }
  1229. }
  1230. void RunUnconditionalCharge(char *v1, char *v2, char *v3, char *v4)
  1231. {
  1232. float _Voltage[2], _Current[2];
  1233. _Voltage[0] = atof(v1);
  1234. _Current[0] = atof(v2);
  1235. _Voltage[1] = atof(v3);
  1236. _Current[1] = atof(v4);
  1237. unsigned char PreviousSystemStatus[2] = {0xff, 0xff};
  1238. if(!FindChargingInfoData(0, &_chargingData[0]))
  1239. {
  1240. printf ("FindChargingInfoData 0 error\n");
  1241. return;
  1242. }
  1243. if(!FindChargingInfoData(1, &_chargingData[0]))
  1244. {
  1245. printf ("FindChargingInfoData 1 error\n");
  1246. return;
  1247. }
  1248. printf ("Gun 1: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[0], _Current[0]);
  1249. printf ("Gun 2: ReqVoltage = %f, ReqCurrent = %f\n", _Voltage[1], _Current[1]);
  1250. if(_Voltage[0] > 1000 || _Voltage[0] < 50 || _Voltage[1] > 1000 || _Voltage[1] < 50)
  1251. {
  1252. printf ("Input Voltage over range\n");
  1253. return;
  1254. }
  1255. //kill ev task
  1256. system("killall Module_EvComm");
  1257. while(true)
  1258. {
  1259. if(_chargingData[0]->SystemStatus == S_IDLE && _chargingData[1]->SystemStatus == S_IDLE)
  1260. {
  1261. _chargingData[0]->SystemStatus = S_REASSIGN_CHECK;
  1262. _chargingData[1]->SystemStatus = S_REASSIGN_CHECK;
  1263. ShmSysConfigAndInfo->SysInfo.MainChargingMode = _MAIN_CHARGING_MODE_AVER;
  1264. ShmSysConfigAndInfo->SysInfo.ReAssignedFlag = _REASSIGNED_NONE;
  1265. }
  1266. if(_chargingData[0]->SystemStatus == S_COMPLETE && _chargingData[1]->SystemStatus == S_COMPLETE)
  1267. {
  1268. system(STTY_DEF TTY_PATH);
  1269. sleep(5);
  1270. return;
  1271. }
  1272. for(int i = 0; i < 2; i++)
  1273. {
  1274. switch(_chargingData[i]->SystemStatus)
  1275. {
  1276. case S_IDLE:
  1277. {
  1278. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1279. {
  1280. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1281. printf ("[UnconditionalCharge (%d) - S_IDLE]\n", i);
  1282. }
  1283. }
  1284. break;
  1285. case S_PREPARNING:
  1286. {
  1287. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1288. {
  1289. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1290. printf ("[UnconditionalCharge (%d) - S_PREPARNIN]\n", i);
  1291. printf ("wait find module\n");
  1292. }
  1293. //清除 main timeout 機制
  1294. _chargingData[i]->TimeoutFlag = 0;
  1295. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1296. _chargingData[i]->Type = 9;
  1297. }
  1298. break;
  1299. case S_PREPARING_FOR_EV:
  1300. {
  1301. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1302. {
  1303. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1304. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EV]\n", i);
  1305. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage[i] * 10,_Current[i] * 10);
  1306. }
  1307. //清除 main timeout 機制
  1308. _chargingData[i]->TimeoutFlag = 0;
  1309. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1310. _chargingData[i]->Type = 9;
  1311. //充電電壓電流
  1312. _chargingData[i]->EvBatterySoc = 50;
  1313. _chargingData[i]->EvBatterytargetVoltage = 500;
  1314. _chargingData[i]->EvBatterytargetCurrent = 2;
  1315. _chargingData[i]->AvailableChargingCurrent = 1000;
  1316. printf ("Precharge Done = %f \n", _chargingData[i]->PresentChargingVoltage);
  1317. _chargingData[i]->SystemStatus = S_PREPARING_FOR_EVSE;
  1318. }
  1319. break;
  1320. case S_PREPARING_FOR_EVSE:
  1321. {
  1322. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1323. {
  1324. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1325. printf ("[UnconditionalCharge (%d) - S_PREPARING_FOR_EVSE]\n", i);
  1326. }
  1327. //清除 main timeout 機制
  1328. _chargingData[i]->TimeoutFlag = 0;
  1329. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  1330. _chargingData[i]->Type = 9;
  1331. //充電電壓電流
  1332. _chargingData[i]->EvBatterySoc = 50;
  1333. _chargingData[i]->EvBatterytargetVoltage = 500;
  1334. _chargingData[i]->EvBatterytargetCurrent = 2;
  1335. _chargingData[i]->AvailableChargingCurrent = 1000;
  1336. printf ("Wait K1K2 = %f \n", _chargingData[i]->PresentChargingVoltage);
  1337. sleep(5);
  1338. //EV done
  1339. _chargingData[i]->SystemStatus = S_CHARGING;
  1340. }
  1341. break;
  1342. case S_CHARGING:
  1343. {
  1344. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1345. {
  1346. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1347. //充電電壓電流
  1348. _chargingData[i]->EvBatterySoc = 50;
  1349. _chargingData[i]->EvBatterytargetVoltage = _Voltage[i];
  1350. _chargingData[i]->EvBatterytargetCurrent = _Current[i];
  1351. _chargingData[i]->AvailableChargingCurrent = 1000;
  1352. printf ("[UnconditionalCharge (%d) - S_CHARGING]\n", i);
  1353. }
  1354. }
  1355. break;
  1356. case S_TERMINATING:
  1357. {
  1358. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1359. {
  1360. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1361. system("/root/Module_EvComm &");
  1362. printf ("[UnconditionalCharge (%d) - S_TERMINATING]\n", i);
  1363. }
  1364. sleep(3);
  1365. _chargingData[i]->SystemStatus = S_COMPLETE;
  1366. }
  1367. break;
  1368. case S_COMPLETE:
  1369. {
  1370. if(PreviousSystemStatus[i] != _chargingData[i]->SystemStatus)
  1371. {
  1372. PreviousSystemStatus[i] = _chargingData[i]->SystemStatus;
  1373. printf ("[UnconditionalCharge (%d) - S_COMPLETE]\n", i);
  1374. }
  1375. }
  1376. break;
  1377. }
  1378. }
  1379. char word[128];
  1380. char newString[7][10];
  1381. int i,j,ctr;
  1382. memset(word, 0x00, sizeof(word));
  1383. get_char(word);
  1384. if (strlen(word) == 0)
  1385. {
  1386. continue;
  1387. }
  1388. j=0; ctr=0;
  1389. strcpy(newString[1], "-1");
  1390. strcpy(newString[2], "-1");
  1391. for (i = 0; i <= (strlen(word)); i++)
  1392. {
  1393. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  1394. {
  1395. newString[ctr][j] = '\0';
  1396. ctr++;
  1397. j = 0;
  1398. }
  1399. else
  1400. {
  1401. newString[ctr][j] = word[i];
  1402. j++;
  1403. }
  1404. }
  1405. if(strcmp(newString[0], "chg") == 0)
  1406. {
  1407. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  1408. continue;
  1409. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  1410. continue;
  1411. if (strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  1412. continue;
  1413. int _gun = atoi(newString[1]);
  1414. float _vol = atof(newString[2]);
  1415. float _cur = atof(newString[3]);
  1416. if(_gun >= 2 || _gun < 0)
  1417. continue;
  1418. if (_cur <= 0 || _cur <= 0)
  1419. continue;
  1420. printf("gun %d: vol = %f, cur = %f \n", _gun + 1, _vol, _cur);
  1421. _chargingData[_gun]->EvBatterytargetVoltage = _vol;
  1422. _chargingData[_gun]->EvBatterytargetCurrent = _cur;
  1423. }
  1424. else if (strcmp(newString[0], "c") == 0)
  1425. {
  1426. printf("stop \n\r");
  1427. _chargingData[0]->SystemStatus = S_TERMINATING;
  1428. _chargingData[1]->SystemStatus = S_TERMINATING;
  1429. }
  1430. usleep(100000);
  1431. }
  1432. }
  1433. void SetWiringInfo(char *v1, char *v2)
  1434. {
  1435. int dispenser = atoi(v1);
  1436. int connector = atoi(v2);
  1437. if(dispenser > 0 && dispenser <= GENERAL_GUN_QUANTITY && connector >= 0 && connector <= GENERAL_GUN_QUANTITY)
  1438. {
  1439. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence == (dispenser - 1))
  1440. {
  1441. printf("\r\n");
  1442. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1443. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1444. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence = dispenser;
  1445. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity += connector;
  1446. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1447. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1448. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1449. }
  1450. else if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > (dispenser - 1))
  1451. {
  1452. printf("\r\n");
  1453. printf("Set Dispenser %d, Connector Quantity = %d\r\n", dispenser, connector);
  1454. ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[dispenser - 1] = connector;
  1455. int quantity = 0;
  1456. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1457. {
  1458. quantity += ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i];
  1459. }
  1460. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity = quantity;
  1461. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1462. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence;
  1463. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity = ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity;
  1464. }
  1465. }
  1466. }
  1467. void ShowWiringInfo(void)
  1468. {
  1469. printf("\r\n");
  1470. printf("********** Wiring Info **********\r\n");
  1471. printf("Dispenser = %d, Connector = %d\r\n",
  1472. ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence,
  1473. ShmSysConfigAndInfo->SysConfig.WiringInfo.MaxConnectorQuantity);
  1474. if(ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence > 0)
  1475. {
  1476. for(int i = 0; i < ShmSysConfigAndInfo->SysConfig.WiringInfo.DispenserSequence; i++)
  1477. {
  1478. printf("Dispenser[%d] <=> %d\r\n", i, ShmSysConfigAndInfo->SysConfig.WiringInfo.WiringSetting[i]);
  1479. }
  1480. }
  1481. printf("\r\n");
  1482. }
  1483. void CleanWiringInfo(void)
  1484. {
  1485. printf("\r\n");
  1486. printf("******* Clean Wiring Info *******\r\n");
  1487. memset((char *)&ShmSysConfigAndInfo->SysConfig.WiringInfo, 0x00, sizeof(WiringInfoData));
  1488. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  1489. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.CleanWiringInfo = true;
  1490. printf("\r\n");
  1491. }
  1492. void SetSystemSoftRest(void)
  1493. {
  1494. printf("\r\n");
  1495. printf("********* Set Soft Reset ********\r\n\r\n");
  1496. ShmChargerInfo->Control.SysCtrl.bits.NeedSoftReset = true;
  1497. }
  1498. void SetSystemHardReboot(void)
  1499. {
  1500. printf("\r\n");
  1501. printf("******** Set Hard Reboot ********\r\n\r\n");
  1502. ShmChargerInfo->Control.SysCtrl.bits.NeedHardReset = true;
  1503. }
  1504. void SetGroupRole(byte group, byte role)
  1505. {
  1506. if(group < GENERAL_GUN_QUANTITY)
  1507. {
  1508. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != role)
  1509. {
  1510. //printf("\r\nSet Group %d Role = %d", group, role);
  1511. }
  1512. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role = role;
  1513. }
  1514. }
  1515. void SetGroupToIdle(byte group)
  1516. {
  1517. if(group < GENERAL_GUN_QUANTITY)
  1518. {
  1519. SetGroupRole(group, _GROLE_IDLE);
  1520. ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity = 0;
  1521. memset(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, 0x00, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1522. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = 0;
  1523. //printf("\r\n Reset Group %02X To Idle", group);
  1524. }
  1525. }
  1526. void SetGroupToMaster(byte group)
  1527. {
  1528. if(group < GENERAL_GUN_QUANTITY)
  1529. {
  1530. SetGroupRole(group, _GROLE_MASTER);
  1531. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = group + 1;
  1532. //printf("\r\n Set Group %02X As Master", group);
  1533. }
  1534. }
  1535. void SetGroupToSlave(byte group, byte target)
  1536. {
  1537. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1538. {
  1539. SetGroupRole(group, _GROLE_SLAVE);
  1540. ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup = target + 1;
  1541. //printf("\r\n Set Group %02X As Slave", group);
  1542. }
  1543. }
  1544. // group: group index, target: target index
  1545. // add group to target's member
  1546. void AddGroupCollection(byte group, byte target)
  1547. {
  1548. int ParallelConfig = 0;
  1549. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1550. {
  1551. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role != _GROLE_MASTER)
  1552. {
  1553. return;
  1554. }
  1555. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE &&
  1556. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_WAIT_IDLE &&
  1557. ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_PRECHARGE_READY)
  1558. {
  1559. return;
  1560. }
  1561. SetGroupToSlave(group, target);
  1562. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity++] = group;
  1563. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1564. if(ParallelConfig != 0)
  1565. {
  1566. ShmPsuGrouping->ParallelRelayConfig.CtrlValue |= (1 << (ParallelConfig - 1));
  1567. }
  1568. //printf("\r\n Add Group %02X To Gun %d (Quantity %d), Set Parallel Relay %d On", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1569. }
  1570. }
  1571. // group: group index, target: target index
  1572. // remove group out of target's member
  1573. void RemoveGroupCollection(byte group, byte target)
  1574. {
  1575. int location = 0, slave = 0;
  1576. bool find = false;
  1577. int ParallelConfig = 0;
  1578. if(group < GENERAL_GUN_QUANTITY && target < GENERAL_GUN_QUANTITY)
  1579. {
  1580. for(int i = 0; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1581. {
  1582. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i])
  1583. {
  1584. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1585. location = i;
  1586. find = true;
  1587. break;
  1588. }
  1589. }
  1590. if(find)
  1591. {
  1592. for(int i = location + 1; i < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity; i++)
  1593. {
  1594. slave = ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i];
  1595. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i] = 0;
  1596. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[i - 1] = slave;
  1597. }
  1598. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity--;
  1599. SetGroupToIdle(group);
  1600. ParallelConfig = ShmChargerInfo->PsuGrouping.GroupCollection[target].ParallelConfig[group];
  1601. if(ParallelConfig != 0)
  1602. {
  1603. ShmPsuGrouping->ParallelRelayConfig.CtrlValue &= ~(1 << (ParallelConfig - 1));
  1604. }
  1605. //printf("\r\n Remove Group %02X From Gun %d (Quantity %d), Clean Parallel Relay %d Off", group, target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ParallelConfig);
  1606. }
  1607. }
  1608. }
  1609. // Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay
  1610. // 1 (00) 00 3 00 [00] [00] [00] 0000 V 0000 A 0000 kW 0000 A 0000 A 00 XX
  1611. void ShowGroupingInfo(void)
  1612. {
  1613. byte target = 0;
  1614. printf("\r\n Gun(Status)(Ro)(Q) Master Member OutputVol OutputCur AvaiPower AvaiCur StabCur K1K2 ParaRelay");
  1615. for(int i = 0; i < 4; i++)
  1616. {
  1617. target = ShmPsuGrouping->Layout[i];
  1618. printf("\r\n %d (%2d) %2d %d %02X ",
  1619. target + 1, _chargingData[target]->SystemStatus, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role,
  1620. ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup);
  1621. for(int j = 0; j < 3; j++)
  1622. {
  1623. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].Role == 1 && j < ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity)
  1624. {
  1625. printf("[%02X] ", ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Member[j]);
  1626. }
  1627. else
  1628. {
  1629. printf(" ");
  1630. }
  1631. }
  1632. printf(" %4d V %4d A %4d kW %4d A %4d A ",
  1633. (int)_chargingData[target]->PresentChargingVoltage, (int)_chargingData[target]->PresentChargingCurrent,
  1634. (int)(_chargingData[target]->AvailableChargingPower / 10), (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  1635. (int)(_chargingData[target]->DeratingChargingCurrent / 10));
  1636. printf("%02X %02X",ShmPsuGrouping->OutputRelayConfig[target].CtrlValue, ShmPsuGrouping->ParallelRelayConfig.CtrlValue);
  1637. }
  1638. printf("\r\n\r\nSystem Capability Current = %4d.%01d A, Power = %3d.%01d kW",
  1639. (ShmPsuData->SystemAvailableCurrent / 10), (ShmPsuData->SystemAvailableCurrent % 10),
  1640. (ShmPsuData->SystemAvailablePower / 10), (ShmPsuData->SystemAvailablePower % 10));
  1641. printf("\r\n\r\n");
  1642. }
  1643. void PsuGroupSwitchToIdle(byte group)
  1644. {
  1645. int master = 0, quantity = 0, location = 0, total = 0;
  1646. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_SLAVE)
  1647. {
  1648. return;
  1649. }
  1650. master = ShmChargerInfo->PsuGrouping.GroupCollection[group].TargetGroup - 1;
  1651. quantity = ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Quantity;
  1652. //printf("\r\n Search Group %02X From Gun %d", group, master + 1);
  1653. for(int i = 0; i < quantity; i++)
  1654. {
  1655. if(total == 0)
  1656. {
  1657. if(group == ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i])
  1658. {
  1659. location = i;
  1660. total++;
  1661. //printf("\r\n Find Group %02X At Member Index = %d", group, location);
  1662. }
  1663. }
  1664. else
  1665. {
  1666. // find other group in the same direction
  1667. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] < ShmPsuGrouping->Location[master])
  1668. {
  1669. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] < ShmPsuGrouping->Location[master])
  1670. {
  1671. total++;
  1672. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1673. }
  1674. }
  1675. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[location]] > ShmPsuGrouping->Location[master])
  1676. {
  1677. if(ShmPsuGrouping->Location[ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]] > ShmPsuGrouping->Location[master])
  1678. {
  1679. total++;
  1680. //printf("\r\n Find Other Group %02X In The Same Direction", ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member[i]);
  1681. }
  1682. }
  1683. }
  1684. }
  1685. if(total > 0)
  1686. {
  1687. unsigned char collection[GENERAL_GUN_QUANTITY];
  1688. //printf("\r\n There are %d Group Need To Switch Idle:", total);
  1689. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[master].Partner.Member));
  1690. for(int i = 0; i < total; i++)
  1691. {
  1692. //printf(" %02X", collection[i + location]);
  1693. }
  1694. for(int i = 0; i < total; i++)
  1695. {
  1696. RemoveGroupCollection(collection[i + location], master);
  1697. }
  1698. }
  1699. }
  1700. void FindPsuGroupPartner(byte master, byte quantity, PsuGroupPartner *tPartner)
  1701. {
  1702. int slave = 0, location = 0;
  1703. PsuGroupPartner partner;
  1704. memset(&partner, 0x00, sizeof(PsuGroupPartner));
  1705. // search from left
  1706. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location - 1;
  1707. for(int i = location; i >= 0; i--)
  1708. {
  1709. if(partner.Quantity >= quantity)
  1710. {
  1711. break;
  1712. }
  1713. slave = ShmPsuGrouping->Layout[i];
  1714. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1715. {
  1716. //printf("\r\n Find Group %02X From Left", slave);
  1717. partner.Member[partner.Quantity++] = slave;
  1718. }
  1719. else
  1720. {
  1721. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1722. {
  1723. continue;
  1724. }
  1725. break;
  1726. }
  1727. }
  1728. // search from right
  1729. location = ShmChargerInfo->PsuGrouping.GroupCollection[master].Location + 1;
  1730. for(int i = location; i < 4; i++)
  1731. {
  1732. if(partner.Quantity >= quantity)
  1733. {
  1734. break;
  1735. }
  1736. slave = ShmPsuGrouping->Layout[i];
  1737. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1738. {
  1739. //printf("\r\n Find Group %02X From Right", slave);
  1740. partner.Member[partner.Quantity++] = slave;
  1741. }
  1742. else
  1743. {
  1744. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && master == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1745. {
  1746. continue;
  1747. }
  1748. break;
  1749. }
  1750. }
  1751. memcpy(tPartner, &partner, sizeof(PsuGroupPartner));
  1752. }
  1753. int GetPsuGroupAvailable(byte group)
  1754. {
  1755. //int slave = 0, location = 0, available = 0;
  1756. PsuGroupPartner partner;
  1757. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1758. //printf("\r\n Gun %d Available Quantity = %d", group + 1, partner.Quantity);
  1759. return partner.Quantity;
  1760. #if 0
  1761. // search from left
  1762. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1763. for(int i = location; i >= 0; i--)
  1764. {
  1765. slave = ShmPsuGrouping->Layout[i];
  1766. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1767. {
  1768. available++;
  1769. }
  1770. else
  1771. {
  1772. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1773. {
  1774. continue;
  1775. }
  1776. break;
  1777. }
  1778. }
  1779. // search from right
  1780. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1781. for(int i = location; i < 4; i++)
  1782. {
  1783. slave = ShmPsuGrouping->Layout[i];
  1784. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1785. {
  1786. available++;
  1787. }
  1788. else
  1789. {
  1790. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1791. {
  1792. continue;
  1793. }
  1794. break;
  1795. }
  1796. }
  1797. return available;
  1798. #endif
  1799. }
  1800. void PsuGroupShareCheck(byte group)
  1801. {
  1802. int slave = 0, target = 0, location = 0, share = 0, total = 0;
  1803. total = GetPsuGroupAvailable(group) + 1;
  1804. //printf("\r\n Gun %d Total Group = %d", group + 1, total);
  1805. // search from left
  1806. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1807. for(int i = location; i >= 0; i--)
  1808. {
  1809. slave = ShmPsuGrouping->Layout[i];
  1810. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1811. {
  1812. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1813. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1814. {
  1815. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1816. }
  1817. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1818. break;
  1819. }
  1820. else
  1821. {
  1822. break;
  1823. }
  1824. }
  1825. if(share == 0)
  1826. {
  1827. // search from right
  1828. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1829. for(int i = location; i < 4; i++)
  1830. {
  1831. slave = ShmPsuGrouping->Layout[i];
  1832. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE)
  1833. {
  1834. target = ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1;
  1835. if((ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1) > total)
  1836. {
  1837. share = (ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity + 1 - total) / 2;
  1838. }
  1839. //printf("\r\n Find Group %02X Have %d Resource Can Shared %d From Left", target, ShmChargerInfo->PsuGrouping.GroupCollection[target].Partner.Quantity, share);
  1840. break;
  1841. }
  1842. else
  1843. {
  1844. break;
  1845. }
  1846. }
  1847. }
  1848. if(share > 0)
  1849. {
  1850. //printf("\r\n Grab %02X", slave);
  1851. PsuGroupSwitchToIdle(slave);
  1852. }
  1853. else
  1854. {
  1855. //printf("\r\n No Need To Grab");
  1856. }
  1857. }
  1858. void SimplePsuGroupStartCharging(byte group)
  1859. {
  1860. //int slave = 0, location = 0;
  1861. int available = 0;
  1862. PsuGroupPartner partner;
  1863. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1864. {
  1865. return;
  1866. }
  1867. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_IDLE && ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1868. {
  1869. return;
  1870. }
  1871. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_IDLE)
  1872. {
  1873. SetGroupToMaster(group);
  1874. PsuGroupShareCheck(group);
  1875. }
  1876. else
  1877. {
  1878. available = GetPsuGroupAvailable(group);
  1879. //printf("\r\nGun %d is already master, there are %d available group", group + 1, available);
  1880. if(available == 0)
  1881. {
  1882. return;
  1883. }
  1884. }
  1885. FindPsuGroupPartner(group, MAX_GROUP_QUANTITY, &partner);
  1886. for(int i = 0; i < partner.Quantity; i++)
  1887. {
  1888. AddGroupCollection(partner.Member[i], group);
  1889. }
  1890. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = true;
  1891. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = true;
  1892. #if 0
  1893. // search from left
  1894. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location - 1;
  1895. for(int i = location; i >= 0; i--)
  1896. {
  1897. slave = ShmPsuGrouping->Layout[i];
  1898. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1899. {
  1900. //printf("\r\n Find %02X From Left", slave);
  1901. AddGroupCollection(slave, group);
  1902. }
  1903. else
  1904. {
  1905. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1906. {
  1907. continue;
  1908. }
  1909. break;
  1910. }
  1911. }
  1912. // search from right
  1913. location = ShmChargerInfo->PsuGrouping.GroupCollection[group].Location + 1;
  1914. for(int i = location; i < 4; i++)
  1915. {
  1916. slave = ShmPsuGrouping->Layout[i];
  1917. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_IDLE)
  1918. {
  1919. //printf("\r\n Find %02X From Right", slave);
  1920. AddGroupCollection(slave, group);
  1921. }
  1922. else
  1923. {
  1924. if(ShmChargerInfo->PsuGrouping.GroupCollection[slave].Role == _GROLE_SLAVE && group == (ShmChargerInfo->PsuGrouping.GroupCollection[slave].TargetGroup - 1))
  1925. {
  1926. continue;
  1927. }
  1928. break;
  1929. }
  1930. }
  1931. #endif
  1932. }
  1933. void PsuGroupStopCharging(byte group)
  1934. {
  1935. int total = 0;
  1936. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role != _GROLE_MASTER)
  1937. {
  1938. return;
  1939. }
  1940. total = ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity;
  1941. if(total > 0)
  1942. {
  1943. unsigned char collection[GENERAL_GUN_QUANTITY];
  1944. //printf("\r\n There are %d Group Need To Stop:", ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Quantity);
  1945. memcpy(collection, ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member, ARRAY_SIZE(ShmChargerInfo->PsuGrouping.GroupCollection[group].Partner.Member));
  1946. for(int i = 0; i < total; i++)
  1947. {
  1948. //printf(" %02X", collection[i]);
  1949. }
  1950. for(int i = 0; i < total; i++)
  1951. {
  1952. RemoveGroupCollection(collection[i], group);
  1953. }
  1954. }
  1955. SetGroupToIdle(group);
  1956. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_N = false;
  1957. ShmPsuGrouping->OutputRelayConfig[group].bits.Output_P = false;
  1958. }
  1959. void RunSimplePsuGrouping(char *v1, char *v2)
  1960. {
  1961. int group = 0, charging = 0;
  1962. group = atoi(v1);
  1963. charging = atoi(v2);
  1964. group -= 1;
  1965. if(group >= 0 && group < 4)
  1966. {
  1967. if(charging > 0)
  1968. {
  1969. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1970. {
  1971. //printf("\r\nGroup %02X Is In Use, Need To Stop Charging", group);
  1972. PsuGroupSwitchToIdle(group);
  1973. }
  1974. SimplePsuGroupStartCharging(group);
  1975. }
  1976. if(charging == 0)
  1977. {
  1978. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_MASTER)
  1979. {
  1980. PsuGroupStopCharging(group);
  1981. }
  1982. if(ShmChargerInfo->PsuGrouping.GroupCollection[group].Role == _GROLE_SLAVE)
  1983. {
  1984. PsuGroupSwitchToIdle(group);
  1985. }
  1986. }
  1987. ShowGroupingInfo();
  1988. }
  1989. }
  1990. void ShowCabinetInfo(void)
  1991. {
  1992. int ipAddress = 0;
  1993. printf("\r\n");
  1994. printf("Psu Work Step = %d, PsuComm: %d\r\n", ShmPsuData->Work_Step, ShmChargerInfo->Control.CommInfo.PsuComm.CommCnt);
  1995. printf("Psu RxCnt: %d\r\n", ShmChargerInfo->Control.CommInfo.PsuComm.RxCnt);
  1996. printf(" Dispenser: %d / %d, Connector: %d / %d\r\n",
  1997. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentDispenserQuantity,
  1998. ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity,
  1999. ShmSysConfigAndInfo->SysInfo.DispenserInfo.PresentConnectorQuantity,
  2000. ShmSysConfigAndInfo->SysInfo.DispenserInfo.TotalConnectorQuantity);
  2001. printf("\r\n");
  2002. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2003. {
  2004. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress;
  2005. printf(" Dispenser Connection[%d] Status: %d, DispenserIndex: %d, IP: %d.%d.%d.%d\r\n", i,
  2006. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status,
  2007. ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex,
  2008. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2009. }
  2010. printf("\r\n");
  2011. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2012. {
  2013. printf(" Connector[%d] Index: %2X, Status = %2d , %s\r\n", i, _chargingData[i]->Index, _chargingData[i]->SystemStatus,
  2014. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? "Enable" : "Disable");
  2015. }
  2016. for(int i = 0; i < ShmSysConfigAndInfo->SysInfo.DispenserInfo.DispenserQuantity; i++)
  2017. {
  2018. printf(" Dispenser[%d] Status: %d", i, ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus);
  2019. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_None &&
  2020. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].LocalStatus != _DS_Timeout)
  2021. {
  2022. ipAddress = 0;
  2023. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  2024. {
  2025. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].Status == _CNS_DispenserMatched &&
  2026. i == ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].DispenserIndex)
  2027. {
  2028. ipAddress = ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[j].IpAddress;
  2029. }
  2030. }
  2031. printf(", ModelName: %s, IP: %d.%d.%d.%d\r\n", ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ModelName,
  2032. ((ipAddress >> 0) & 0xFF), ((ipAddress >> 8) & 0xFF), ((ipAddress >> 16) & 0xFF), ((ipAddress >> 24) & 0xFF));
  2033. for(int j = 0; j < ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorQuantity; j++)
  2034. {
  2035. unsigned char gun = ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[i].ConnectorID[j];
  2036. printf(" - Connector[%d] Gun %d, %s\r\n", j, gun, _chargingData[gun - 1]->ConnectorPlugIn ? "Plugged" : "Unplugged");
  2037. }
  2038. }
  2039. else
  2040. {
  2041. printf(", No Information\r\n");
  2042. }
  2043. }
  2044. printf("\r\n");
  2045. }
  2046. void SetTestControl(char *v1, char *v2)
  2047. {
  2048. int testItem = 0;
  2049. int testItemLen = 4;
  2050. int enable = 0;
  2051. char strTest[32][32] = {"tbl", "tfsb", "chgsm", "fcre"};
  2052. char strItem[32][32] = {"Balance", "Fast Standby Time", "Charging Simulation", "FCharging Release Extend"};
  2053. enable = atoi(v2);
  2054. if(enable < 0)
  2055. {
  2056. return;
  2057. }
  2058. for(int i = 0; i < testItemLen; i++)
  2059. {
  2060. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2061. {
  2062. testItem = i + 1;
  2063. break;
  2064. }
  2065. }
  2066. if(testItem != 0)
  2067. {
  2068. if(enable)
  2069. {
  2070. ShmChargerInfo->Control.TestCtrl.CtrlValue |= (1 << (testItem - 1));
  2071. }
  2072. else
  2073. {
  2074. ShmChargerInfo->Control.TestCtrl.CtrlValue &= ~(1 << (testItem - 1));
  2075. }
  2076. printf("%s %s Test Item, Test Control Value = %08X\n",
  2077. enable ? "Enable" : "Disable", strItem[testItem - 1], ShmChargerInfo->Control.TestCtrl.CtrlValue);
  2078. }
  2079. else
  2080. {
  2081. printf("Test Item %s Not Found\n", v1);
  2082. for(int i = 0; i < testItemLen; i++)
  2083. {
  2084. printf(" [%s] -> %s Test\n", strTest[i], strItem[i]);
  2085. }
  2086. }
  2087. printf("\r\n");
  2088. }
  2089. // Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim
  2090. // 1 00 00 0 0000 V 000.0 A 0000 A XXX.XX XXX.XX XXX kw XXX kW XXX kW
  2091. void ShowGroupingDemand(void)
  2092. {
  2093. byte target = 0;
  2094. unsigned char k1k2 = 0;
  2095. printf("\r\n Gun Role Master K1K2 GTVoltage GTCurrent StableCurrent OutputLoading GunLoading DiffP_Ava DiffP_Cap DiffP_Lim");
  2096. for(int i = 0; i < 4; i++)
  2097. {
  2098. target = ShmPsuGrouping->Layout[i];
  2099. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup != 0)
  2100. {
  2101. k1k2 = _chargingData[ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup - 1]->RelayK1K2Status;
  2102. }
  2103. else
  2104. {
  2105. k1k2 = _chargingData[target]->RelayK1K2Status;
  2106. }
  2107. printf("\r\n %d %2d %02X %d %4d V %3d.%d A %4d A %3d.%02d",
  2108. target + 1, ShmChargerInfo->PsuGrouping.GroupCollection[target].Role, ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup, k1k2,
  2109. (ShmPsuGrouping->GroupOutput[target].GTargetVoltage / 10),
  2110. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent / 10),
  2111. (ShmPsuGrouping->GroupOutput[target].GTargetCurrent % 10),
  2112. (int)(_chargingData[target]->AvailableChargingCurrent / 10),
  2113. (ShmPsuGrouping->GroupOutput[target].OutputLoading / 100),
  2114. (ShmPsuGrouping->GroupOutput[target].OutputLoading % 100));
  2115. if(ShmChargerInfo->PsuGrouping.GroupCollection[target].TargetGroup == target + 1)
  2116. {
  2117. printf(" %3d.%02d", (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading / 100), (ShmChargerInfo->PsuGrouping.GroupCollection[target].GunLoading % 100));
  2118. printf(" %3d kW %3d kW %3d kW",
  2119. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Available,
  2120. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_Capability,
  2121. (int)ShmPsuGrouping->GroupCollection[target].DiffPower_PhysicalLimit);
  2122. }
  2123. }
  2124. printf("\r\n\r\n");
  2125. }
  2126. // v1: gun
  2127. // v2: voltage
  2128. // v3: current
  2129. void SetGunStartCharging(char *v1, char *v2, char *v3)
  2130. {
  2131. int gun = 0;
  2132. float _voltage = 0, _current = 0;
  2133. gun = atoi(v1);
  2134. _voltage = atof(v2);
  2135. _current = atof(v3);
  2136. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY || _voltage < 0 || _voltage > 1000 || _current < 0 || _current > 1200)
  2137. {
  2138. printf("\r\n");
  2139. printf("Gun Start Charging Input parameter %s, %s, %s over range\r\n", v1, v2, v3);
  2140. printf("\r\n");
  2141. return;
  2142. }
  2143. /*
  2144. if(_chargingData[gun - 1]->SystemStatus == S_IDLE)
  2145. {
  2146. printf("\r\nSet Gun %d Start Charging > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2147. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2148. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2149. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2150. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2151. }
  2152. else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2153. {
  2154. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2155. {
  2156. printf("\r\nSet Gun %d > Voltage: %4d, Current: %d", gun, (int)_voltage, (int)_current);
  2157. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2158. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2159. }
  2160. else
  2161. {
  2162. printf("\r\nGun %d Force Charging Is Disable", gun);
  2163. }
  2164. }
  2165. else
  2166. {
  2167. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2168. }
  2169. printf("\r\n\r\n");
  2170. */
  2171. bool wait = true;
  2172. int time = 0;
  2173. struct timespec _Wait_time;
  2174. unsigned char PreviousSystemStatus = 0xFF;
  2175. unsigned short _targetVoltage = 0, _targetCurrent = 0;
  2176. printf("\r\n");
  2177. while(wait)
  2178. {
  2179. switch(_chargingData[gun - 1]->SystemStatus)
  2180. {
  2181. case S_IDLE:
  2182. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2183. {
  2184. printf("Gun %d S_IDLE\r\n", gun);
  2185. printf("Set Gun %d Start Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  2186. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging = true;
  2187. ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.StartForceCharging = true;
  2188. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2189. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2190. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2191. }
  2192. break;
  2193. case S_REASSIGN_CHECK:
  2194. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2195. {
  2196. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2197. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2198. }
  2199. break;
  2200. case S_REASSIGN:
  2201. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2202. {
  2203. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2204. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2205. }
  2206. break;
  2207. case S_PREPARNING:
  2208. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2209. {
  2210. printf("Gun %d S_PREPARNING\r\n", gun);
  2211. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2212. }
  2213. break;
  2214. case S_PREPARING_FOR_EV:
  2215. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2216. {
  2217. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2218. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2219. }
  2220. break;
  2221. case S_PREPARING_FOR_EVSE:
  2222. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2223. {
  2224. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2225. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2226. }
  2227. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2228. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2229. {
  2230. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2231. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2232. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2233. }
  2234. break;
  2235. case S_CHARGING:
  2236. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2237. {
  2238. printf("Gun %d S_CHARGING\r\n", gun);
  2239. if(PreviousSystemStatus == 0xFF)
  2240. {
  2241. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2242. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2243. printf("Gun %d Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2244. if(ShmChargerInfo->Control.FCharging[gun - 1].FCtrl.bits.EnableForceCharging)
  2245. {
  2246. printf("Set Gun %d Force Charging > Voltage: %4d, Current: %d\r\n", gun, (int)_voltage, (int)_current);
  2247. ShmChargerInfo->Control.FCharging[gun - 1].FTargetVoltage = _voltage * 10;
  2248. ShmChargerInfo->Control.FCharging[gun - 1].FTargetCurrent = _current * 10;
  2249. }
  2250. }
  2251. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2252. GetClockTime(&_Wait_time);
  2253. }
  2254. if(_targetVoltage != (int)_chargingData[gun - 1]->EvBatterytargetVoltage ||
  2255. _targetCurrent != (int)_chargingData[gun - 1]->EvBatterytargetCurrent)
  2256. {
  2257. _targetVoltage = (int)_chargingData[gun - 1]->EvBatterytargetVoltage;
  2258. _targetCurrent = (int)_chargingData[gun - 1]->EvBatterytargetCurrent;
  2259. printf("Gun %d Set Voltage: %4d, Current: %d\r\n", gun, _targetVoltage, _targetCurrent);
  2260. }
  2261. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2262. if(time >= 1)
  2263. {
  2264. wait = false;
  2265. printf("Done\r\n");
  2266. }
  2267. break;
  2268. case S_TERMINATING:
  2269. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2270. {
  2271. printf("Gun %d S_TERMINATING\r\n", gun);
  2272. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2273. }
  2274. wait = false;
  2275. break;
  2276. case S_COMPLETE:
  2277. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2278. {
  2279. printf("Gun %d S_COMPLETE\r\n", gun);
  2280. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2281. }
  2282. wait = false;
  2283. break;
  2284. case S_ALARM:
  2285. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2286. {
  2287. printf("Gun %d S_ALARM\r\n", gun);
  2288. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2289. }
  2290. wait = false;
  2291. break;
  2292. default:
  2293. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2294. {
  2295. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2296. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2297. }
  2298. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2299. wait = false;
  2300. break;
  2301. }
  2302. char word[128];
  2303. char newString[7][10];
  2304. int i,j,ctr;
  2305. memset(word, 0x00, sizeof(word));
  2306. get_char(word);
  2307. if (strlen(word) == 0)
  2308. {
  2309. continue;
  2310. }
  2311. j=0; ctr=0;
  2312. strcpy(newString[1], "-1");
  2313. strcpy(newString[2], "-1");
  2314. for (i = 0; i <= (strlen(word)); i++)
  2315. {
  2316. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2317. {
  2318. newString[ctr][j] = '\0';
  2319. ctr++;
  2320. j = 0;
  2321. }
  2322. else
  2323. {
  2324. newString[ctr][j] = word[i];
  2325. j++;
  2326. }
  2327. }
  2328. if(strcmp(newString[0], "c") == 0)
  2329. {
  2330. printf("Stop\r\n");
  2331. wait = false;
  2332. }
  2333. usleep(100000);
  2334. }
  2335. printf("\r\n");
  2336. }
  2337. // v1: gun
  2338. void SetGunStopCharging(char *v1)
  2339. {
  2340. int gun = 0;
  2341. gun = atoi(v1);
  2342. if(gun <= 0 || gun > GENERAL_GUN_QUANTITY)
  2343. {
  2344. printf("\r\n");
  2345. printf("Gun Stop Charging Input parameter %s over range\r\n", v1);
  2346. printf("\r\n");
  2347. return;
  2348. }
  2349. /*
  2350. if(_chargingData[gun - 1]->SystemStatus >= S_REASSIGN_CHECK && _chargingData[gun - 1]->SystemStatus <= S_CHARGING)
  2351. {
  2352. printf("\r\nSet Gun %d Stop Charging(ManualStop)", gun);
  2353. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2354. }
  2355. else if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2356. {
  2357. printf("\r\nSet Group [%02X] Stop", gun - 1);
  2358. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2359. }
  2360. else
  2361. {
  2362. printf("\r\nGun %d SystemStatus(%d) Is Not Available", gun, _chargingData[gun - 1]->SystemStatus);
  2363. }
  2364. printf("\r\n\r\n");
  2365. */
  2366. bool wait = true;
  2367. int time = 0;
  2368. struct timespec _Wait_time;
  2369. unsigned char PreviousSystemStatus = 0xFF;
  2370. printf("\r\n");
  2371. while(wait)
  2372. {
  2373. switch(_chargingData[gun - 1]->SystemStatus)
  2374. {
  2375. case S_IDLE:
  2376. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2377. {
  2378. printf("Gun %d S_IDLE\r\n", gun);
  2379. if(PreviousSystemStatus == 0xFF)
  2380. {
  2381. if(ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_SLAVE)
  2382. {
  2383. printf("Set Group [%02X] Stop\r\n", gun - 1);
  2384. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.SlavePowerOffRequest = true;
  2385. }
  2386. }
  2387. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2388. GetClockTime(&_Wait_time);
  2389. }
  2390. time = GetTimeoutValue(_Wait_time) / uSEC_VAL;
  2391. if(time >= 1)
  2392. {
  2393. wait = false;
  2394. printf("Done\r\n");
  2395. }
  2396. break;
  2397. case S_REASSIGN_CHECK:
  2398. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2399. {
  2400. printf("Gun %d S_REASSIGN_CHECK, Wait For Request Charging\r\n", gun);
  2401. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2402. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2403. {
  2404. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2405. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2406. }
  2407. }
  2408. break;
  2409. case S_REASSIGN:
  2410. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2411. {
  2412. printf("Gun %d S_REASSIGN, Wait For Grouping\r\n", gun);
  2413. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2414. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2415. {
  2416. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2417. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2418. }
  2419. }
  2420. break;
  2421. case S_PREPARNING:
  2422. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2423. {
  2424. printf("Gun %d S_PREPARNING\r\n", gun);
  2425. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2426. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2427. {
  2428. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2429. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2430. }
  2431. }
  2432. break;
  2433. case S_PREPARING_FOR_EV:
  2434. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2435. {
  2436. printf("Gun %d S_PREPARING_FOR_EV\r\n", gun);
  2437. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2438. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2439. {
  2440. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2441. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2442. }
  2443. }
  2444. break;
  2445. case S_PREPARING_FOR_EVSE:
  2446. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2447. {
  2448. printf("Gun %d S_PREPARING_FOR_EVSE, Wait For EVSE\r\n", gun);
  2449. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2450. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2451. {
  2452. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2453. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2454. }
  2455. }
  2456. break;
  2457. case S_CHARGING:
  2458. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2459. {
  2460. printf("Gun %d S_CHARGING\r\n", gun);
  2461. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2462. if(!_chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop)
  2463. {
  2464. _chargingData[gun - 1]->ChargingStopFlag.bits.ManualStop = true;
  2465. printf("Set Gun %d Stop Charging(ManualStop)\r\n", gun);
  2466. }
  2467. }
  2468. break;
  2469. case S_TERMINATING:
  2470. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2471. {
  2472. printf("Gun %d S_TERMINATING\r\n", gun);
  2473. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2474. }
  2475. break;
  2476. case S_COMPLETE:
  2477. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2478. {
  2479. printf("Gun %d S_COMPLETE\r\n", gun);
  2480. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2481. }
  2482. break;
  2483. case S_ALARM:
  2484. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2485. {
  2486. printf("Gun %d S_ALARM\r\n", gun);
  2487. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2488. }
  2489. break;
  2490. default:
  2491. if(PreviousSystemStatus != _chargingData[gun - 1]->SystemStatus)
  2492. {
  2493. printf("Gun SystemStatus %d Unknown(%d)\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2494. PreviousSystemStatus = _chargingData[gun - 1]->SystemStatus;
  2495. }
  2496. printf("Gun %d SystemStatus(%d) Is Not Available\r\n", gun, _chargingData[gun - 1]->SystemStatus);
  2497. wait = false;
  2498. break;
  2499. }
  2500. char word[128];
  2501. char newString[7][10];
  2502. int i,j,ctr;
  2503. memset(word, 0x00, sizeof(word));
  2504. get_char(word);
  2505. if (strlen(word) == 0)
  2506. {
  2507. continue;
  2508. }
  2509. j=0; ctr=0;
  2510. strcpy(newString[1], "-1");
  2511. strcpy(newString[2], "-1");
  2512. for (i = 0; i <= (strlen(word)); i++)
  2513. {
  2514. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10)
  2515. {
  2516. newString[ctr][j] = '\0';
  2517. ctr++;
  2518. j = 0;
  2519. }
  2520. else
  2521. {
  2522. newString[ctr][j] = word[i];
  2523. j++;
  2524. }
  2525. }
  2526. if(strcmp(newString[0], "c") == 0)
  2527. {
  2528. printf("Stop\r\n");
  2529. wait = false;
  2530. }
  2531. usleep(100000);
  2532. }
  2533. printf("\r\n");
  2534. }
  2535. void SetGunExtend(char *v1)
  2536. {
  2537. int gun = 0;
  2538. gun = atoi(v1);
  2539. if(_chargingData[gun - 1]->SystemStatus == S_CHARGING && ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].Role == _GROLE_MASTER)
  2540. {
  2541. printf("\r\nSet Group [%02X] Extend Capability", gun - 1);
  2542. ShmChargerInfo->PsuGrouping.GroupCollection[gun - 1].GroupCtrl.bits.MorePowerRequest = true;
  2543. }
  2544. else
  2545. {
  2546. printf("\r\nGun %d Extend Capability Is Not Available, SystemStatus(%d)", gun, _chargingData[gun - 1]->SystemStatus);
  2547. }
  2548. printf("\r\n\r\n");
  2549. }
  2550. // 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 ...
  2551. // 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
  2552. void ShowGunOutput(void)
  2553. {
  2554. byte target = 0;
  2555. unsigned short voltage = 0, current = 0;
  2556. 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 ...");
  2557. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  2558. {
  2559. target = ShmPsuGrouping->Layout[i];
  2560. // "\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"
  2561. voltage = (unsigned short)(_chargingData[target]->EvBatterytargetVoltage * 10);
  2562. current = (unsigned short)(_chargingData[target]->EvBatterytargetCurrent * 10);
  2563. printf("\r\n %d %4d.%d V %3d.%d A", target + 1, (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2564. voltage = ShmPsuGrouping->GroupOutput[target].GTargetVoltage;
  2565. current = ShmPsuGrouping->GroupOutput[target].GTargetCurrent;
  2566. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2567. voltage = (unsigned short)(_chargingData[target]->PresentChargingVoltage * 10);
  2568. current = (unsigned short)(_chargingData[target]->PresentChargingCurrent * 10);
  2569. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2570. voltage = ShmPsuData->PsuGroup[target].GroupPresentOutputVoltage;
  2571. current = ShmPsuData->PsuGroup[target].GroupPresentOutputCurrent;
  2572. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2573. /*
  2574. for(int j = 0; j < ShmPsuData->PsuGroup[target].GroupPresentPsuQuantity; j++)
  2575. {
  2576. printf(" %4d.%d V %3d.%d A", (voltage / 10), (voltage % 10), (current / 10), (current % 10));
  2577. }
  2578. */
  2579. }
  2580. printf("\r\n\r\n");
  2581. }
  2582. void SetGpio(char *v1, char *v2)
  2583. {
  2584. int testItem = 0;
  2585. int testItemLen = 1;
  2586. int ioOutput = 0;
  2587. char strTest[32][32] = {"4g"};
  2588. char strItem[32][32] = {"4G Reset"};
  2589. ioOutput = atoi(v2);
  2590. if(ioOutput < 0)
  2591. {
  2592. return;
  2593. }
  2594. for(int i = 0; i < testItemLen; i++)
  2595. {
  2596. if(strcmp((char *)&strTest[i][0], v1) == 0)
  2597. {
  2598. testItem = i + 1;
  2599. break;
  2600. }
  2601. }
  2602. if(testItem != 0)
  2603. {
  2604. if(ioOutput)
  2605. {
  2606. system("echo 1 > /sys/class/gpio/gpio104/value");
  2607. }
  2608. else
  2609. {
  2610. system("echo 0 > /sys/class/gpio/gpio104/value");
  2611. }
  2612. printf("Set %s %s\n",
  2613. strItem[testItem - 1], ioOutput > 0 ? "High" : "Low");
  2614. }
  2615. else
  2616. {
  2617. printf("Gpio Item %s Not Found\n", v1);
  2618. }
  2619. printf("\r\n");
  2620. }
  2621. void ShowStatus(void)
  2622. {
  2623. char *str_cabinet_role[] = {STR_CABINET_ROLE_NONE, STR_CABINET_ROLE_MASTER, STR_CABINET_ROLE_SLAVE};
  2624. for(int i = 0; i < ShmChargerInfo->Control.MaxConnector; i++)
  2625. {
  2626. printf("\r\nGun %d Status = %d, IsAvailable = %d, GunEnable = %d",
  2627. i + 1,
  2628. _chargingData[i]->SystemStatus,
  2629. _chargingData[i]->IsAvailable,
  2630. ShmChargerInfo->Control.GunAvailable[i]);
  2631. printf("\r\nAlarmCode");
  2632. printf("\r\n Connector = %6s, EvConn = %6s, Remote = %6s, Vendor = %6s",
  2633. strncmp((char *)_chargingData[i]->ConnectorAlarmCode, "", 6) != 0 ?
  2634. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2635. strncmp((char *)_chargingData[i]->EvConnAlarmCode, "", 6) != 0 ?
  2636. (char *)_chargingData[i]->ConnectorAlarmCode : "No Err",
  2637. strncmp((char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode, "", 6) != 0 ?
  2638. (char *)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemotenAlarmCode : "No Err",
  2639. strncmp((char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode, "", 6) != 0 ?
  2640. (char *)ShmOCPP16Data->StatusNotification[i].VendorErrorCode : "No Err");
  2641. }
  2642. printf("\r\n");
  2643. printf("\r\nPower Cabinet Role: %s, Switch Value: %d",
  2644. ShmChargerInfo->Control.CabinetSwitch <= _CROLE_SLAVE ? str_cabinet_role[ShmChargerInfo->Control.CabinetSwitch] : "Unknown",
  2645. ShmChargerInfo->Control.CabinetSwitch);
  2646. printf("\r\nStatus Code Len = %d", ShmSysConfigAndInfo->SysWarningInfo.WarningCount);
  2647. if(ShmSysConfigAndInfo->SysWarningInfo.WarningCount > 0)
  2648. {
  2649. printf("\r\n WarningCode:");
  2650. for(int i = 0; i < ShmSysConfigAndInfo->SysWarningInfo.WarningCount; i++)
  2651. {
  2652. printf(" %s", (char *)&ShmSysConfigAndInfo->SysWarningInfo.WarningCode[i][0]);
  2653. }
  2654. }
  2655. printf("\r\n\r\n");
  2656. }
  2657. void ShowWhiteCardList(void)
  2658. {
  2659. printf("\r\nWhite Card List");
  2660. for(int i = 0; i < 10; i++)
  2661. {
  2662. printf("\r\n White Card [%2d]: %s", i + 1, (char *)ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[i]);
  2663. }
  2664. printf("\r\n\r\n");
  2665. }
  2666. void WriteWhiteCard(char *v1, char *v2)
  2667. {
  2668. int cardIndex = 0;
  2669. cardIndex = atoi(v1);
  2670. if(cardIndex < 1 || cardIndex > 10)
  2671. {
  2672. printf("\r\n White Card Index Fail\r\n\r\n");
  2673. return;
  2674. }
  2675. if(strlen(v2) == 0 || strlen(v2) > 31)
  2676. {
  2677. printf("\r\n White Card Fail\r\n\r\n");
  2678. return;
  2679. }
  2680. printf("\r\n Str Len = %d = %s", strlen(v2), v2);
  2681. printf("\r\n Set White Card Index %d = %s", cardIndex, v2);
  2682. memcpy((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], v2, strlen(v2));
  2683. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2684. printf("\r\n\r\n");
  2685. }
  2686. void EraseWhiteCard(char *v1)
  2687. {
  2688. int cardIndex = 0;
  2689. cardIndex = atoi(v1);
  2690. if(cardIndex < 1 || cardIndex > 10)
  2691. {
  2692. printf("\r\n White Card Index Fail\r\n\r\n");
  2693. return;
  2694. }
  2695. printf("\r\n Erase White Card Index = %d", cardIndex);
  2696. memset((char *)&ShmSysConfigAndInfo->SysConfig.LocalWhiteCard[cardIndex - 1][0], 0x00, 32);
  2697. ShmSysConfigAndInfo->SysInfo.CabinetSetting.bits.FlashConfigChanged = true;
  2698. printf("\r\n\r\n");
  2699. }
  2700. void ShowChargerLimit(void)
  2701. {
  2702. int limitPower = -1;
  2703. char *str_gun_type[] = {STR_GUN_TYPE_CHADEMO, STR_GUN_TYPE_CCS, STR_GUN_TYPE_GBT};
  2704. unsigned char inUsingCnt = 0;
  2705. printf("\r\nCharger Limit");
  2706. printf("\r\n System Psu Cnt: %2d", ShmPsuData->SystemPresentPsuQuantity);
  2707. printf("\r\n Charger Max ChargingProfile Power: %d kW", ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower == -1 ?
  2708. (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower : (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower / 1000);
  2709. printf("\r\n Max Total Current: %d A, Max Total Power: %d kW, Total Energy: %d kW, Total Duration %d",
  2710. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent, ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  2711. ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy, ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2712. printf("\r\n\r\n Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur");
  2713. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  2714. {
  2715. inUsingCnt = 0;
  2716. for(int j = 0; j < GENERAL_GUN_QUANTITY; j++)
  2717. {
  2718. if(ShmChargerInfo->PsuGrouping.GroupCollection[j].Role == _GROLE_MASTER)
  2719. {
  2720. inUsingCnt += ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity;
  2721. }
  2722. }
  2723. // Gun Enable Type Psu Phy_Vol Phy_Cur Config_Ocpp_MaxOcpp_Pow Config_Ocpp_MaxOcpp_Cur
  2724. // 1 0 CHAdeMO 00 0000 V 0000 A 0000 / 0000 / 0000 kW 0000 / 0000 A
  2725. // Gun 1 Enable, Type: CCS, Psu Cnt: 00, Max Physical Vol: 0000 V, Cur: 0000 A, Max Config Pow: 0000 kW, Cur: 0000 A
  2726. printf("\r\n %d %d ", i + 1, ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable);
  2727. if(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable)
  2728. {
  2729. printf(" %7s %2d",
  2730. _chargingData[i]->Type <= _Type_GB ? str_gun_type[_chargingData[i]->Type] : "???",
  2731. ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity);
  2732. printf(" %4d V %4d A",
  2733. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalVoltage / 10),
  2734. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].RemoteMaxPhysicalCurrent / 10));
  2735. if(ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower != -1)
  2736. {
  2737. limitPower = (int)ShmSysConfigAndInfo->SysInfo.MaxChargingProfilePower;
  2738. if(inUsingCnt > 0)
  2739. {
  2740. limitPower = (limitPower * ShmChargerInfo->PsuGrouping.GroupCollection[i].GunPsuQuantity) / inUsingCnt;
  2741. }
  2742. }
  2743. else
  2744. {
  2745. limitPower = -1;
  2746. }
  2747. printf(" %4d / %4d / %4d kW",
  2748. (ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingPower / 10),
  2749. _chargingData[i]->ChargingProfilePower == -1 ? (int)_chargingData[i]->ChargingProfilePower : ((int)_chargingData[i]->ChargingProfilePower / 1000),
  2750. limitPower == -1 ? limitPower : (limitPower / 1000));
  2751. printf(" %4d / %4d A",
  2752. ((int)ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].MaxTotalChargingCurrent / 10),
  2753. _chargingData[i]->ChargingProfileCurrent == -1 ? (int)_chargingData[i]->ChargingProfileCurrent : ((int)_chargingData[i]->ChargingProfileCurrent / 10));
  2754. }
  2755. }
  2756. printf("\r\n\r\n");
  2757. }
  2758. void SetGunCommand(char *v1, char *v2, char *v3)
  2759. {
  2760. int cmdItem = 0;
  2761. int cmdItemLen = 2;
  2762. int gunID = 0;
  2763. int enable = 0;
  2764. char strGunCmd[32][32] = {"enable", "operative"};
  2765. char strDescription[32][32] = {"Available", "Operative"};
  2766. gunID = atoi(v2);
  2767. enable = atoi(v3);
  2768. if(gunID <= 0 || gunID > CONNECTOR_QUANTITY || enable < 0)
  2769. {
  2770. return;
  2771. }
  2772. for(int i = 0; i < cmdItemLen; i++)
  2773. {
  2774. if(strcmp((char *)&strGunCmd[i][0], v1) == 0)
  2775. {
  2776. cmdItem = i + 1;
  2777. break;
  2778. }
  2779. }
  2780. if(cmdItem != 0)
  2781. {
  2782. switch(cmdItem)
  2783. {
  2784. case 1:
  2785. ShmChargerInfo->Control.GunAvailable[gunID - 1] = enable > 0 ? YES : NO;
  2786. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2787. break;
  2788. case 2:
  2789. _chargingData[gunID - 1]->IsAvailable = enable > 0 ? YES : NO;
  2790. ShmChargerInfo->ConnectorMiscReq[gunID - 1].bits.Availability = true;
  2791. break;
  2792. }
  2793. printf("Gun cmd [%s] [%s]\n", strDescription[cmdItem - 1], enable ? "Enable" : "Disable");
  2794. }
  2795. else
  2796. {
  2797. printf("Gun cmd %s not found\n", v1);
  2798. for(int i = 0; i < cmdItemLen; i++)
  2799. {
  2800. printf(" [%s] -> %s Test\n", strGunCmd[i], strDescription[i]);
  2801. }
  2802. }
  2803. printf("\r\n");
  2804. }
  2805. void ShowWebSystemInfo(void)
  2806. {
  2807. char *str_led_intensity[] = {STR_DARKEST, STR_MEDIUM, STR_BRIGHTEST};
  2808. char *str_qr_code_made[] = {STR_QR_DEFAULT, STR_QR_CUSTOMIZED, STR_QR_CHARGEBOXID};
  2809. char *str_rfid_endian[] = {STR_LITTLE_ENDIAN, STR_BIG_ENDIAN};
  2810. printf("\r\n");
  2811. printf("Web [System]\r\n");
  2812. printf(" *System ID: %s\r\n", ShmSysConfigAndInfo->SysConfig.SystemId);
  2813. printf(" *AuthorisationMode[%7s]\r\n",
  2814. ShmSysConfigAndInfo->SysConfig.AuthorisationMode == AUTH_MODE_ENABLE ? "Enable" : "Disable");
  2815. printf(" - APP [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAPP > 0 ? "Enable" : "Disable");
  2816. printf(" - QRCode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isQRCode > 0 ? "Enable" : "Disable");
  2817. printf(" - RFID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isRFID > 0 ? "Enable" : "Disable");
  2818. printf(" - EVCCID [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.isAuthrizeByEVCCID > 0 ? "Enable" : "Disable");
  2819. if(ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian <= RFID_ENDIAN_BIG)
  2820. {
  2821. printf(" *RfidCardNumEndian [%s]\r\n", str_rfid_endian[ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian]);
  2822. }
  2823. else
  2824. {
  2825. printf(" *RfidCardNumEndian: %d\r\n", ShmSysConfigAndInfo->SysConfig.RfidCardNumEndian);
  2826. }
  2827. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode <= _QR_MODE_Customized)
  2828. {
  2829. printf(" *QR Code Made [%s]\r\n", str_qr_code_made[ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode]);
  2830. }
  2831. else
  2832. {
  2833. printf(" *QR Code Made: %d\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode);
  2834. }
  2835. if(ShmSysConfigAndInfo->SysConfig.QRCodeMadeMode == _QR_MODE_Customized)
  2836. {
  2837. printf(" - QR Code Content: %s\r\n", ShmSysConfigAndInfo->SysConfig.QRCodeContent);
  2838. }
  2839. if(ShmChargerInfo->AuthInfo.QRCodeMode <= _QR_MODE_ChargeBoxId)
  2840. {
  2841. printf(" *QR Code Mode [%s]\r\n", str_qr_code_made[ShmChargerInfo->AuthInfo.QRCodeMode]);
  2842. }
  2843. else
  2844. {
  2845. printf(" *QR Code Mode: %d\r\n", ShmChargerInfo->AuthInfo.QRCodeMode);
  2846. }
  2847. if(ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity <= _LED_INTENSITY_BRIGHTEST)
  2848. {
  2849. printf(" *LED Intensity[%s]\r\n", str_led_intensity[ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity]);
  2850. }
  2851. else
  2852. {
  2853. printf(" *LED Intensity[%d]\r\n", ShmSysConfigAndInfo->SysConfig.LedInfo.Intensity);
  2854. }
  2855. }
  2856. void ShowWebChargingInfo(void)
  2857. {
  2858. printf("\r\n");
  2859. printf("Web [Charging]\r\n");
  2860. printf(" *Max Charging Energy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingEnergy);
  2861. printf(" *Max Charging Power : %4d kW\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingPower);
  2862. printf(" *Max Charging Current : %4d A\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  2863. printf(" *Max Charging Duration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.MaxChargingDuration);
  2864. printf(" *StopCharging By Button[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.StopChargingByButton > 0 ? "Enable" : "Disable");
  2865. printf(" *Billing[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.isBilling > 0 ? "Enable" : "Disable");
  2866. printf(" - Currency[%2d]\r\n", ShmSysConfigAndInfo->SysConfig.BillingData.Currency);
  2867. }
  2868. void ShowWebNetworkInfo(void)
  2869. {
  2870. char *str_wifi_mode[] = {"Disable", "Station", "AP Mode"};
  2871. printf("\r\n");
  2872. printf("Web [Network]\r\n");
  2873. printf(" *NetworkStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.InternetConn > 0 ? "Connected" : "Disconnected");
  2874. printf(" *DHCP Client[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.Eth0Interface.EthDhcpClient == 0 ? "Enable" : "Disable");
  2875. if(ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode <= _SYS_WIFI_MODE_AP)
  2876. {
  2877. printf(" *WiFi Mode [%7s]\r\n", str_wifi_mode[ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode]);
  2878. }
  2879. else
  2880. {
  2881. printf(" *WiFi Mode [%d]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiMode);
  2882. }
  2883. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.AthInterface.WifiNetworkConn == YES ? "Connected" : "Disconnected");
  2884. printf(" *3G/4G Mode [%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomEnabled == YES ? "Enable" : "Disable");
  2885. printf(" - ConnStatus[%s]\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomNetworkConn == YES ? "Connected" : "Disconnected");
  2886. printf(" - APN : %s\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomApn);
  2887. printf(" - RSSI: %d dBm\r\n", ShmSysConfigAndInfo->SysConfig.TelecomInterface.TelcomRssi);
  2888. }
  2889. void ShowWebBackendInfo(void)
  2890. {
  2891. char *str_offline_policy[] = {"Local List", "Phihong RFID", "Free Charging", "No Charging"};
  2892. char *str_security_profile[] = {
  2893. "None security",
  2894. "Unsecured Transport with Basic Atuentication",
  2895. "TLS with Basic Authentication",
  2896. "TLS with Client Side Certificates"
  2897. };
  2898. printf("\r\n");
  2899. printf("Web [Backend]\r\n");
  2900. printf(" *Common\r\n");
  2901. printf(" - Backend Timeout : %d s\r\n", ShmSysConfigAndInfo->SysConfig.BackendConnTimeout);
  2902. if(ShmSysConfigAndInfo->SysConfig.OfflinePolicy <= _OFFLINE_POLICY_NO_CHARGING)
  2903. {
  2904. printf(" - Offline Policy : %s\r\n", str_offline_policy[ShmSysConfigAndInfo->SysConfig.OfflinePolicy]);
  2905. }
  2906. else
  2907. {
  2908. printf(" - Offline Policy : %d\r\n", ShmSysConfigAndInfo->SysConfig.OfflinePolicy);
  2909. }
  2910. printf(" - OfflineMaxEnergy : %4d kWh\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeEnergy);
  2911. printf(" - OfflineMaxDuration: %4d Minutes\r\n", ShmSysConfigAndInfo->SysConfig.OfflineMaxChargeDuration);
  2912. printf(" *OCPP\r\n");
  2913. printf(" - OcppStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.OcppConnStatus == YES ? "Connected" : "Disconnected");
  2914. printf(" - OcppURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.OcppServerURL);
  2915. printf(" - ChargeBoxId: %s\r\n", ShmSysConfigAndInfo->SysConfig.ChargeBoxId);
  2916. printf(" - Vendor : %s\r\n", ShmSysConfigAndInfo->SysConfig.chargePointVendor);
  2917. if(ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile <= 3)
  2918. {
  2919. printf(" - Security : %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile]);
  2920. }
  2921. else
  2922. {
  2923. printf(" - Security : %d\r\n", ShmSysConfigAndInfo->SysConfig.OcppSecurityProfile);
  2924. }
  2925. printf(" - MaintainStatus[%s]\r\n", ShmSysConfigAndInfo->SysInfo.MaintainServerConnStatus == YES ? "Connected" : "Disconnected");
  2926. printf(" - MaintainURL : %s\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerURL);
  2927. if(ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile <= 3)
  2928. {
  2929. printf(" - MaintainSecurity: %s\r\n", str_security_profile[ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile]);
  2930. }
  2931. else
  2932. {
  2933. printf(" - MaintainSecurity: %d\r\n", ShmSysConfigAndInfo->SysConfig.MaintainServerSecurityProfile);
  2934. }
  2935. printf(" *TTIA[%7s]\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES ? "Enable" : "Disable");
  2936. if(ShmSysConfigAndInfo->SysConfig.TTIA_Info.isEnableTTIA == YES)
  2937. {
  2938. printf(" - ServerAddress: %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_addr);
  2939. printf(" - ServerPort : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.server_port);
  2940. printf(" - BusVenderId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.busVenderId);
  2941. printf(" - Provider : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.EquipmentProvider);
  2942. printf(" - CompanyNo : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.TransportationCompanyNo);
  2943. printf(" - ChargeBoxId : %d\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.ChargeBoxId);
  2944. printf(" - EVSEStation : %s\r\n", ShmSysConfigAndInfo->SysConfig.TTIA_Info.evseStation);
  2945. }
  2946. }
  2947. void ShowWebAllInfo(void)
  2948. {
  2949. ShowWebSystemInfo();
  2950. ShowWebChargingInfo();
  2951. ShowWebNetworkInfo();
  2952. ShowWebBackendInfo();
  2953. }
  2954. void ShowWebInfo(char *v1)
  2955. {
  2956. bool find = false;
  2957. int showItem = 0;
  2958. int itemLen = 5;
  2959. char strItem[32][32] = {"system", "charging", "network", "backend", "all"};
  2960. void *actionList[32] = {&ShowWebSystemInfo, &ShowWebChargingInfo, &ShowWebNetworkInfo, &ShowWebBackendInfo, &ShowWebAllInfo};
  2961. void (*ItemAction)();
  2962. for(showItem = 0; showItem < itemLen; showItem++)
  2963. {
  2964. if(strcmp((char *)&strItem[showItem][0], v1) == 0)
  2965. {
  2966. find = true;
  2967. break;
  2968. }
  2969. }
  2970. if(find)
  2971. {
  2972. ItemAction = actionList[showItem];
  2973. ItemAction();
  2974. }
  2975. else
  2976. {
  2977. printf("\r\n");
  2978. printf ("Input cmd fail ------ web [cmd]\r\n");
  2979. for(int i = 0; i < itemLen; i++)
  2980. {
  2981. printf(" [cmd] %s\r\n", (char *)&strItem[i][0]);
  2982. }
  2983. }
  2984. printf("\r\n");
  2985. }
  2986. // Gun 1 ( CCS ) Soc: XXX %, Energy: XXXXX.X kWh, IdTag [XXXXXXXXXXXXXXXX] Transaction [0]
  2987. // Gun 1 ( CCS ) IdTag: XXXXXXXXXXXXXXXX, Soc: XXX %, Energy: XXXX.X kWh
  2988. // (XX) (X) Target: XXXX V, XXXX A, Cap: XXXX A, XXXX kW
  2989. // Output: XXXX V, XXXX A, Limit: XXXX A, XXXX kW
  2990. void ShowGunInfo(int gun)
  2991. {
  2992. char *str_gun_type[] = {"CHAdeMO", " CCS ", " GBT "};
  2993. printf(" Gun %d (%s) Soc: %3d %s, Energy: %7.1f kWh, IdTag [%16s] Transaction [%d], TotalCost: %.2f\r\n",
  2994. gun + 1,
  2995. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].Enable ? str_gun_type[_chargingData[gun]->Type] : "Disable",
  2996. _chargingData[gun]->EvBatterySoc, "%",
  2997. _chargingData[gun]->PresentChargedEnergy,
  2998. _chargingData[gun]->StartUserId,
  2999. ShmChargerInfo->UserTransaction[gun].TransactionId,
  3000. ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].TotalCost);
  3001. //printf(" Gun %d (%s) IdTag [%16s] Soc: %3d %s, Energy: %4.1f kWh\r\n",
  3002. // i + 1,
  3003. // ShmSysConfigAndInfo->SysInfo.ConnectorInfo[i].Enable ? str_gun_type[_chargingData[i]->Type] : "Disable",
  3004. // _chargingData[i]->StartUserId,
  3005. // _chargingData[i]->EvBatterySoc, "%",
  3006. // _chargingData[i]->PresentChargedEnergy);
  3007. printf(" (%2d) (%s) Target: %4d V, %4d A, Cap: %4d A, %4d kW\r\n",
  3008. _chargingData[gun]->SystemStatus,
  3009. _chargingData[gun]->ConnectorPlugIn ? "O" : "X",
  3010. (int)_chargingData[gun]->EvBatterytargetVoltage,
  3011. (int)_chargingData[gun]->EvBatterytargetCurrent,
  3012. (int)(_chargingData[gun]->AvailableChargingCurrent / 10),
  3013. (int)(_chargingData[gun]->AvailableChargingPower / 10));
  3014. printf(" Output: %4d V, %4d A, Limit: %4d A, %4d kW\r\n",
  3015. (int)(_chargingData[gun]->PresentChargingVoltage),
  3016. (int)(_chargingData[gun]->PresentChargingCurrent),
  3017. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityCurrent / 10),
  3018. (int)(ShmSysConfigAndInfo->SysInfo.ConnectorInfo[gun].CapabilityPower / 10));
  3019. }
  3020. void ShowInfo(char *inputCmd, unsigned int opt)
  3021. {
  3022. bool keepRun = false;
  3023. bool reflash = false;
  3024. int time = 0;
  3025. struct timespec _Loop_time;
  3026. if((opt & OPTION_REFLASH) || (opt & OPTION_LOOP) > 0)
  3027. {
  3028. keepRun = true;
  3029. }
  3030. do
  3031. {
  3032. time = GetTimeoutValue(_Loop_time) / mSEC_VAL;
  3033. if(time >= 1000)
  3034. {
  3035. if(reflash)
  3036. {
  3037. ConsoleReflash(CONNECTOR_QUANTITY, 4);
  3038. }
  3039. for(int i = 0; i < GENERAL_GUN_QUANTITY; i++)
  3040. {
  3041. printf("\r\n");
  3042. ShowGunInfo(i);
  3043. }
  3044. GetClockTime(&_Loop_time);
  3045. if((opt & OPTION_REFLASH) > 0)
  3046. {
  3047. reflash = true;
  3048. }
  3049. }
  3050. if(keepRun)
  3051. {
  3052. keepRun = IsLoopStopCmd() ? false : true;
  3053. usleep(10000);
  3054. }
  3055. }while(keepRun);
  3056. printf("\r\n");
  3057. }
  3058. void RtcSyncCmd(char *inputCmd, unsigned int opt)
  3059. {
  3060. unsigned int paraOpt = 0;
  3061. int totalCnt = 0, parseCnt = 0, maxPara = 0;
  3062. char normalString[128];
  3063. char paraList[2][128];
  3064. char hostAdd[32];
  3065. int dispenser = 0, offset = 0;
  3066. memset(hostAdd, 0x00, sizeof(hostAdd));
  3067. maxPara = 2;
  3068. totalCnt = InputStringNormalize(inputCmd, normalString, &paraOpt);
  3069. if(totalCnt != 2)
  3070. {
  3071. printf("Input cmd fail ------ rtc [dispenser 1-4] [offset minute]\r\n\r\n");
  3072. return;
  3073. }
  3074. printf("\r\n");
  3075. if(totalCnt > 0)
  3076. {
  3077. totalCnt = totalCnt > maxPara ? maxPara : totalCnt;
  3078. int loopLimit = totalCnt > 1 ? totalCnt - 1 : 1;
  3079. for(int i = 0; i < loopLimit; i++)
  3080. {
  3081. memset(&paraList[parseCnt][0], 0x00, 128);
  3082. memset(&paraList[parseCnt + 1][0], 0x00, 128);
  3083. MainAndSubCommandParsing(normalString, &paraList[parseCnt][0], &paraList[parseCnt + 1][0]);
  3084. strcpy(normalString, &paraList[parseCnt + 1][0]);
  3085. parseCnt++;
  3086. }
  3087. }
  3088. dispenser = atoi(&paraList[0][0]);
  3089. offset = atoi(&paraList[1][0]);
  3090. if(dispenser <= 0 || dispenser > CONNECTOR_QUANTITY)
  3091. {
  3092. printf("dispenser %d over range\r\n\r\n", dispenser);
  3093. return;
  3094. }
  3095. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_None ||
  3096. ShmSysConfigAndInfo->SysInfo.DispenserInfo.Dispenser[dispenser - 1].LocalStatus == _DS_Timeout)
  3097. {
  3098. printf("dispenser %d is not available\r\n\r\n", dispenser);
  3099. return;
  3100. }
  3101. // find dispenser ip address
  3102. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3103. {
  3104. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].Status == _CNS_DispenserMatched)
  3105. {
  3106. if(ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].DispenserIndex == (dispenser - 1))
  3107. {
  3108. sprintf(hostAdd, "%d.%d.%d.%d",
  3109. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 0) &0xFF),
  3110. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 8) &0xFF),
  3111. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 16) &0xFF),
  3112. ((ShmSysConfigAndInfo->SysInfo.DispenserInfo.ConnectionInfo[i].IpAddress >> 24) &0xFF));
  3113. }
  3114. }
  3115. }
  3116. if(strlen(hostAdd) == 0)
  3117. {
  3118. printf("dispenser %d ip is not available\r\n\r\n", dispenser);
  3119. return;
  3120. }
  3121. printf("try sycn dispenser %d [%s] rtc, offset: %d minutes\r\n", dispenser, hostAdd, offset);
  3122. // get current time and create offset time
  3123. time_t timep;
  3124. struct tm *tm;
  3125. time(&timep);
  3126. tm = localtime(&timep);
  3127. printf(" NowTime: %d/%02d/%02d %02d:%02d:%02d\r\n",
  3128. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3129. if(offset != 0)
  3130. {
  3131. timep += (offset * 60);
  3132. tm = localtime(&timep);
  3133. printf("OffsetTime: %d/%02d/%02d %02d:%02d:%02d\r\n\r\n",
  3134. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3135. }
  3136. // create send socket
  3137. int rtcfd = 0;
  3138. struct sockaddr_in serverInfo;
  3139. struct timeval tv;
  3140. char rtcTxBuffer[64];
  3141. char rtcRxBuffer[64];
  3142. int txLen = 0, rxLen = 0;
  3143. unsigned char chksum = 0x00;
  3144. rtcfd = socket(AF_INET, SOCK_STREAM, 0);
  3145. if (rtcfd < 0)
  3146. {
  3147. printf("create rtc socket fail\r\n\r\n");
  3148. return;
  3149. }
  3150. memset(rtcTxBuffer, 0x00, sizeof(rtcTxBuffer));
  3151. memset(rtcRxBuffer, 0x00, sizeof(rtcRxBuffer));
  3152. tv.tv_sec = 3;
  3153. tv.tv_usec = 0;
  3154. setsockopt(rtcfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(struct timeval)); //設定等待3s
  3155. setsockopt(rtcfd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(struct timeval)); //設定傳送3s
  3156. bzero(&serverInfo,sizeof(serverInfo));
  3157. serverInfo.sin_family = AF_INET;
  3158. serverInfo.sin_addr.s_addr = inet_addr(hostAdd);
  3159. serverInfo.sin_port = htons(8234);
  3160. if(connect(rtcfd, (struct sockaddr *)&serverInfo, sizeof(serverInfo)) < 0)
  3161. {
  3162. printf("connect to host: %s fail\r\n\r\n", hostAdd);
  3163. close(rtcfd);
  3164. return;
  3165. }
  3166. // set tx header & data
  3167. rtcTxBuffer[0] = 0xAA; // Frame ID
  3168. rtcTxBuffer[1] = 0x00; // Master address
  3169. rtcTxBuffer[2] = 0xFF; // Slave address
  3170. rtcTxBuffer[3] = 0x87; // 0x87
  3171. rtcTxBuffer[4] = 0x0E; // Length_Low
  3172. rtcTxBuffer[5] = 0x00; // Length_High
  3173. sprintf(&rtcTxBuffer[6], "%04d%02d%02d%02d%02d%02d",
  3174. tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
  3175. txLen = rtcTxBuffer[4] + (rtcTxBuffer[5] << 8);
  3176. chksum = 0;
  3177. for(int i = 0; i < txLen; i++)
  3178. {
  3179. chksum ^= rtcTxBuffer[6 + i];
  3180. }
  3181. rtcTxBuffer[6 + txLen] = chksum;
  3182. send(rtcfd, rtcTxBuffer, txLen + 7, MSG_NOSIGNAL);
  3183. // receive
  3184. if(recv(rtcfd, &rtcRxBuffer[0], 6, MSG_WAITALL) < 0)
  3185. {
  3186. printf("read head fail\r\n\r\n");
  3187. close(rtcfd);
  3188. return;
  3189. }
  3190. rxLen = rtcRxBuffer[4] + (rtcRxBuffer[5] << 8);
  3191. if(recv(rtcfd, &rtcRxBuffer[6], rxLen + 1, MSG_WAITALL) < 0)
  3192. {
  3193. printf("read data fail\r\n\r\n");
  3194. close(rtcfd);
  3195. return;
  3196. }
  3197. chksum = 0;
  3198. for(int i = 0; i < rxLen; i++)
  3199. {
  3200. chksum ^= rtcRxBuffer[6 + i];
  3201. }
  3202. if(chksum == rtcRxBuffer[6 + rxLen])
  3203. {
  3204. printf("set %s rtc: ", hostAdd);
  3205. for(int i = 0; i < txLen; i++)
  3206. {
  3207. printf("%c", rtcTxBuffer[6 + i]);
  3208. }
  3209. printf(" %s\r\n\r\n", rtcRxBuffer[6] == 0x01 ? "success" : "fail");
  3210. }
  3211. else
  3212. {
  3213. printf("receive rtc checksum fail\r\n\r\n");
  3214. }
  3215. close(rtcfd);
  3216. }
  3217. int main(void)
  3218. {
  3219. char newString[32][32];
  3220. char inputString[128], normalCmd[128], mainCmd[128], subCmd[128], multiCmd[128];
  3221. int cmdCnt = 0, parseCnt = 0;
  3222. unsigned int option = 0;
  3223. if(InitShareMemory() == FAIL)
  3224. {
  3225. printf ("InitShareMemory = FAIL \n");
  3226. if(ShmStatusCodeData != NULL)
  3227. {
  3228. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory=1;
  3229. }
  3230. sleep(5);
  3231. return 0;
  3232. }
  3233. for(int i = 0; i < CONNECTOR_QUANTITY; i++)
  3234. {
  3235. if (!FindChargingInfoData(i, &_chargingData[0]))
  3236. {
  3237. return 0;
  3238. }
  3239. }
  3240. // clean command
  3241. memset(mainCmd, 0x00, sizeof(mainCmd));
  3242. memset(subCmd, 0x00, sizeof(subCmd));
  3243. for(int i = 0; i < 32; i++)
  3244. {
  3245. memset(&newString[i], 0x00, 32);
  3246. }
  3247. for(;;)
  3248. {
  3249. memset(inputString, 0x00, sizeof(inputString));
  3250. memset(normalCmd, 0x00, sizeof(normalCmd));
  3251. get_char(inputString);
  3252. cmdCnt = InputStringNormalize(inputString, normalCmd, &option);
  3253. if(cmdCnt > 0)
  3254. {
  3255. // clean command
  3256. memset(mainCmd, 0x00, sizeof(mainCmd));
  3257. memset(subCmd, 0x00, sizeof(subCmd));
  3258. for(int i = 0; i < 32; i++)
  3259. {
  3260. memset(&newString[i], 0x00, 32);
  3261. }
  3262. //printf("CmdCnt: %d\r\n", cmdCnt);
  3263. //printf("Input: %s", inputString);
  3264. //printf("Normalize: %s\r\n", normalCmd);
  3265. //printf("option: %08X\r\n", option);
  3266. MainAndSubCommandParsing(normalCmd, mainCmd, subCmd);
  3267. //printf("MainCmd: %s\r\n", mainCmd);
  3268. //printf("SubCmd: %s\r\n", subCmd);
  3269. parseCnt = 0;
  3270. strcpy(multiCmd, normalCmd);
  3271. do
  3272. {
  3273. MainAndSubCommandParsing(multiCmd, &newString[parseCnt][0], &newString[parseCnt + 1][0]);
  3274. strcpy(multiCmd, &newString[parseCnt + 1][0]);
  3275. //printf("MultiCmd Parse %d\r\n", parseCnt + 1);
  3276. //printf("MainCmd: %s\r\n", &newString[parseCnt][0]);
  3277. //printf("SubCmd: %s\r\n", &newString[parseCnt + 1][0]);
  3278. parseCnt++;
  3279. }while(parseCnt < cmdCnt - 1);
  3280. //printf("\r\n");
  3281. //for(int i = 0; i < cmdCnt; i++)
  3282. //{
  3283. // printf("MultiCmd %d: [%s]\r\n", i + 1, &newString[i][0]);
  3284. //}
  3285. }
  3286. else
  3287. {
  3288. usleep(100000);
  3289. continue;
  3290. }
  3291. if(strcmp(newString[0], "state") == 0)
  3292. {
  3293. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3294. continue;
  3295. // 槍狀態
  3296. RunStatusProc(newString[1], newString[2]);
  3297. }
  3298. else if(strcmp(newString[0], "card") == 0)
  3299. {
  3300. // 刷卡狀態
  3301. RunCardProc(newString[1], newString[2]);
  3302. }
  3303. else if(strcmp(newString[0], "gun") == 0)
  3304. {
  3305. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3306. continue;
  3307. // 插槍狀態
  3308. RunGunPlugitProc(newString[1], newString[2]);
  3309. }
  3310. else if(strcmp(newString[0], "lock") == 0)
  3311. {
  3312. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3313. continue;
  3314. // 插槍狀態
  3315. GetGunLockStatusProc(newString[1], newString[2]);
  3316. }
  3317. else if(strcmp(newString[0], "sysid") == 0)
  3318. {
  3319. // 測試 sys id
  3320. SetSystemIDProc();
  3321. }
  3322. else if(strcmp(newString[0], "self") == 0)
  3323. {
  3324. // CSU 自我檢測狀態
  3325. RunSelfProc(newString[1]);
  3326. }
  3327. else if(strcmp(newString[0], "ver") == 0)
  3328. {
  3329. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3330. // continue;
  3331. // 取 FW 版號
  3332. //GetFwVerProc(newString[1]);
  3333. ShowFwVer();
  3334. }
  3335. else if (strcmp(newString[0], "update") == 0)
  3336. {
  3337. // 更新
  3338. FwUpdateFlagProc(newString[1]);
  3339. }
  3340. else if (strcmp(newString[0], "ac") == 0)
  3341. {
  3342. // AC contactor 狀態
  3343. CheckAcStatus(newString[1]);
  3344. }
  3345. else if (strcmp(newString[0], "cable") == 0)
  3346. {
  3347. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3348. continue;
  3349. // cable check pass
  3350. SetCableChkStatus(newString[1], newString[2]);
  3351. }
  3352. else if (strcmp(newString[0], "pow") == 0)
  3353. {
  3354. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3355. continue;
  3356. // cable check pass
  3357. SetPowerValue(newString[1], newString[2]);
  3358. }
  3359. else if (strcmp(newString[0], "model") == 0)
  3360. {
  3361. GetSystemInfo();
  3362. }
  3363. else if(strcmp(newString[0], "fan") == 0)
  3364. {
  3365. // 設定風扇速度
  3366. SetFanSpeed(newString[1]);
  3367. }
  3368. else if(strcmp(newString[0], "speed") == 0)
  3369. {
  3370. // 取得風扇速度
  3371. GetFanSpeed();
  3372. }
  3373. else if(strcmp(newString[0], "debug") == 0)
  3374. {
  3375. // 設定 debug mode
  3376. SetDebugMode(newString[1]);
  3377. }
  3378. else if (strcmp(newString[0], "gfd") == 0)
  3379. {
  3380. // 設定盲沖使用 GFD 功能
  3381. SetGFDMode(newString[1]);
  3382. }
  3383. else if(strcmp(mainCmd, "temp") == 0)
  3384. {
  3385. // 取得溫度
  3386. GetTemperature(subCmd, option);
  3387. }
  3388. else if(strcmp(mainCmd, "acin") == 0)
  3389. {
  3390. // 取得三向輸入電壓
  3391. GetInputVol(subCmd, option);
  3392. }
  3393. else if(strcmp(newString[0], "psu") == 0)
  3394. {
  3395. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3396. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3397. {
  3398. printf ("PSU : Param fail..Please retry again......\n");
  3399. continue;
  3400. }
  3401. // 取得 PSU 資訊
  3402. GetPsuInformation(newString[1], newString[2], newString[3]);
  3403. }
  3404. else if (strcmp(newString[0], "cap") == 0)
  3405. {
  3406. GetConnectorCapInfo(newString[1]);
  3407. }
  3408. else if(strcmp(newString[0], "error") == 0)
  3409. {
  3410. CreateOneError(newString[1]);
  3411. }
  3412. else if (strcmp(newString[0], "auth") == 0)
  3413. {
  3414. GetAuthorizeFlag(newString[1]);
  3415. }
  3416. else if (strcmp(newString[0], "id") == 0)
  3417. {
  3418. GetOrClearId(newString[1]);
  3419. }
  3420. #if 0
  3421. else if(strcmp(newString[0], "strchg") == 0)
  3422. {
  3423. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3424. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3425. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3426. {
  3427. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  3428. continue;
  3429. }
  3430. // 槍狀態
  3431. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  3432. }
  3433. else if(strcmp(newString[0], "str2chg") == 0)
  3434. {
  3435. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  3436. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3437. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3438. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0 ||
  3439. strcmp(newString[4], "-1") == 0 || strcmp(newString[4], "") == 0)
  3440. {
  3441. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  3442. continue;
  3443. }
  3444. // 槍狀態
  3445. RunUnconditionalCharge(newString[1], newString[2], newString[3], newString[4]);
  3446. }
  3447. #endif
  3448. else if(strcmp(newString[0], "wiring") == 0)
  3449. {
  3450. if(strcmp(newString[1], "-1") != 0 && strcmp(newString[1], "") != 0 &&
  3451. strcmp(newString[2], "-1") != 0 && strcmp(newString[2], "") != 0)
  3452. {
  3453. SetWiringInfo(newString[1], newString[2]);
  3454. }
  3455. ShowWiringInfo();
  3456. }
  3457. else if(strcmp(newString[0], "cwiring") == 0)
  3458. {
  3459. CleanWiringInfo();
  3460. }
  3461. else if(strcmp(newString[0], "reset") == 0)
  3462. {
  3463. SetSystemSoftRest();
  3464. }
  3465. else if(strcmp(newString[0], "reboot") == 0)
  3466. {
  3467. SetSystemHardReboot();
  3468. }
  3469. else if(strcmp(newString[0], "sgroup") == 0)
  3470. {
  3471. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3472. {
  3473. ShowGroupingInfo();
  3474. continue;
  3475. }
  3476. RunSimplePsuGrouping(newString[1], newString[2]);
  3477. }
  3478. else if(strcmp(newString[0], "cabinet") == 0)
  3479. {
  3480. ShowCabinetInfo();
  3481. }
  3482. else if(strcmp(newString[0], "tctl") == 0)
  3483. {
  3484. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3485. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3486. {
  3487. printf("Test Control Value = %08X\n",ShmChargerInfo->Control.TestCtrl.CtrlValue);
  3488. printf ("Input cmd fail ------ tctl [tcmd] [value]\n\n");
  3489. continue;
  3490. }
  3491. SetTestControl(newString[1], newString[2]);
  3492. }
  3493. else if(strcmp(newString[0], "group") == 0)
  3494. {
  3495. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3496. {
  3497. ShowGroupingInfo();
  3498. continue;
  3499. }
  3500. }
  3501. else if(strcmp(newString[0], "gdmd") == 0)
  3502. {
  3503. ShowGroupingDemand();
  3504. }
  3505. else if(strcmp(newString[0], "gunchg") == 0)
  3506. {
  3507. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3508. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3509. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  3510. {
  3511. printf ("Input cmd fail ------ gunchg [gun 1-4] [voltage 0-1000] [current 0-100]\n\n");
  3512. continue;
  3513. }
  3514. SetGunStartCharging(newString[1], newString[2], newString[3]);
  3515. }
  3516. else if(strcmp(newString[0], "gunstp") == 0)
  3517. {
  3518. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3519. {
  3520. printf ("Input cmd fail ------ gunstp [gun 1-4]\n\n");
  3521. continue;
  3522. }
  3523. SetGunStopCharging(newString[1]);
  3524. }
  3525. else if(strcmp(newString[0], "gunext") == 0)
  3526. {
  3527. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3528. {
  3529. printf ("Input cmd fail ------ gunext [gun 1-4]\n\n");
  3530. continue;
  3531. }
  3532. SetGunExtend(newString[1]);
  3533. }
  3534. else if(strcmp(newString[0], "output") == 0)
  3535. {
  3536. ShowGunOutput();
  3537. }
  3538. else if(strcmp(newString[0], "gio") == 0)
  3539. {
  3540. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3541. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3542. {
  3543. printf ("Input cmd fail ------ gio [io] [on-off 0-1]\n\n");
  3544. continue;
  3545. }
  3546. SetGpio(newString[1], newString[2]);
  3547. }
  3548. else if(strcmp(newString[0], "status") == 0)
  3549. {
  3550. ShowStatus();
  3551. }
  3552. else if(strcmp(newString[0], "whiteR") == 0)
  3553. {
  3554. ShowWhiteCardList();
  3555. }
  3556. else if(strcmp(newString[0], "whiteW") == 0)
  3557. {
  3558. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3559. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0)
  3560. {
  3561. printf ("Input cmd fail ------ whiteW [index 1-10] [card id]\n\n");
  3562. continue;
  3563. }
  3564. WriteWhiteCard(newString[1], newString[2]);
  3565. }
  3566. else if(strcmp(newString[0], "whiteE") == 0)
  3567. {
  3568. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0)
  3569. {
  3570. printf ("Input cmd fail ------ whiteE [index 1-10]\n\n");
  3571. continue;
  3572. }
  3573. EraseWhiteCard(newString[1]);
  3574. }
  3575. else if(strcmp(newString[0], "limit") == 0)
  3576. {
  3577. ShowChargerLimit();
  3578. }
  3579. else if(strcmp(newString[0], "pcmd") == 0)
  3580. {
  3581. }
  3582. else if(strcmp(newString[0], "gcmd") == 0)
  3583. {
  3584. if(strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  3585. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0 ||
  3586. strcmp(newString[3], "-1") == 0 || strcmp(newString[3], "") == 0)
  3587. {
  3588. printf ("Input cmd fail ------ gcmd [cmd] [gun] [value]\n\n");
  3589. continue;
  3590. }
  3591. SetGunCommand(newString[1], newString[2], newString[3]);
  3592. }
  3593. else if(strcmp(newString[0], "web") == 0)
  3594. {
  3595. ShowWebInfo(newString[1]);
  3596. }
  3597. else if(strcmp(mainCmd, "info") == 0)
  3598. {
  3599. ShowInfo(subCmd, option);
  3600. }
  3601. else if(strcmp(mainCmd, "rtcsync") == 0)
  3602. {
  3603. RtcSyncCmd(subCmd, option);
  3604. }
  3605. else
  3606. {
  3607. printf ("%s\n", msg);
  3608. }
  3609. usleep(100000);
  3610. }
  3611. return 0;
  3612. }