ReadCmdline.c 77 KB

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