ReadCmdline.c 138 KB

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