ReadCmdline.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  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 <stdint.h>
  26. #include <unistd.h> /*Unix 標準函數定義*/
  27. #include <fcntl.h> /*檔控制定義*/
  28. #include <termios.h> /*PPSIX 終端控制定義*/
  29. #include <errno.h> /*錯誤號定義*/
  30. #include <errno.h>
  31. #include <string.h>
  32. #include <time.h>
  33. #include <ctype.h>
  34. #include <ifaddrs.h>
  35. #include <math.h>
  36. #include <stdbool.h>
  37. #include "./ShareMemory/shmMem.h"
  38. #include "./Define/define.h"
  39. #include "./SelectGun/SelectGun.h"
  40. #include "Config.h"
  41. #include "./ModuleEvComm/Module_EvComm.h"
  42. //------------------------------------------------------------------------------
  43. #define CMD_KEY_WAIT (1)
  44. #define CMD_KEY_DONT_WAIT (0)
  45. #define DEFAULT_AC_INDEX (2)
  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. //------------------------------------------------------------------------------
  56. uint8_t _curAutoRunCount = 0;
  57. uint8_t _usingAutoRun = 0;
  58. struct timeval _autoTime;
  59. static struct SysConfigData *pSysConfig = NULL;
  60. static struct SysInfoData *pSysInfo = NULL;
  61. static struct WARNING_CODE_INFO *pSysWarning = NULL;
  62. static struct AlarmCodeData *pAlarmCode = NULL;
  63. static struct PrimaryMcuData *ShmPrimaryMcuData = NULL;
  64. static struct CHAdeMOData *ShmCHAdeMOData = NULL;
  65. static struct CcsData *ShmCcsData = NULL;
  66. static struct GBTData *ShmGBTData = NULL;
  67. static struct FanModuleData *ShmFanModuleData = NULL;
  68. static struct RelayModuleData *ShmRelayModuleData = NULL;
  69. static struct LedModuleData *ShmLedModuleData = NULL;
  70. static struct PsuData *ShmPsuData = NULL;
  71. static struct OCPP16Data *ShmOCPP16Data = NULL;
  72. static SelectGunInfo *ShmSelectGunInfo = NULL;
  73. static DcCommonInfo *ShmDcCommonData = NULL;
  74. static struct ChargingInfoData *pDcChargingInfo = NULL;
  75. static struct ChargingInfoData *pAcChargingInfo = NULL;
  76. static char newString[8][16] = {0};
  77. //------------------------------------------------------------------------------
  78. static int DiffTimeb(struct timeb ST, struct timeb ET)
  79. {
  80. //return milli-second
  81. unsigned int StartTime, StopTime;
  82. StartTime = (unsigned int)ST.time;
  83. StopTime = (unsigned int)ET.time;
  84. return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
  85. }
  86. static void get_char(char *word)
  87. {
  88. fd_set rfds;
  89. struct timeval tv;
  90. FD_ZERO(&rfds);
  91. FD_SET(0, &rfds);
  92. tv.tv_sec = 0;
  93. tv.tv_usec = 10; //wait input timout time
  94. //if input
  95. if (select(1, &rfds, NULL, NULL, &tv) > 0) {
  96. fgets(word, 128, stdin);
  97. }
  98. }
  99. static uint8_t helpCmd(void)
  100. {
  101. if (strcmp(newString[0], "?") == 0 ||
  102. strcmp(newString[0], "help") == 0 ||
  103. strcmp(newString[0], "h") == 0) {
  104. return YES;
  105. }
  106. return NO;
  107. }
  108. static uint8_t exitCmd(void)
  109. {
  110. if (strcmp(newString[0], "c") == EQUAL ||
  111. strcmp(newString[0], "C") == EQUAL ||
  112. strncmp(&newString[0][0], "exit", 4) == EQUAL
  113. ) {
  114. return YES;
  115. }
  116. return NO;
  117. }
  118. static uint8_t readCmdKey(uint8_t state)
  119. {
  120. char word[128] = {0};
  121. int i = 0, j = 0, ctr = 0;
  122. memset(word, 0, sizeof(word));
  123. if (state == CMD_KEY_WAIT) {
  124. fgets(word, sizeof(word), stdin);
  125. } else if (state == CMD_KEY_DONT_WAIT) {
  126. get_char(word);
  127. if (strlen(word) == 0) {
  128. //usleep(50000);
  129. return NO;
  130. }
  131. }
  132. memset(newString, 0, sizeof(newString));
  133. strcpy(newString[1], "-1");
  134. strcpy(newString[2], "-1");
  135. for (i = 0; i <= (strlen(word)); i++) {
  136. if (word[i] == ' ' ||
  137. word[i] == '\0' ||
  138. word[i] == '\r' ||
  139. word[i] == '\n' ||
  140. word[i] == 10) {
  141. newString[ctr][j] = '\0';
  142. ctr++;
  143. j = 0;
  144. } else {
  145. newString[ctr][j] = word[i];
  146. j++;
  147. }
  148. }
  149. return YES;
  150. }
  151. unsigned long GetTimeoutValue(struct timeval _sour_time)
  152. {
  153. struct timeval _end_time;
  154. gettimeofday(&_end_time, NULL);
  155. return (_end_time.tv_sec - _sour_time.tv_sec);
  156. }
  157. void RunStatusProc(char *v1, char *v2)
  158. {
  159. printf("OrderCharging = %d \n", pSysInfo->OrderCharging);
  160. printf("WaitForPlugit = %d \n", pSysInfo->WaitForPlugit);
  161. if (strcmp(v1, "ac") == 0) {
  162. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  163. //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  164. // printf("FindChargingInfoData (AC) false \n");
  165. //}
  166. printf("AC Status = %d \n", pAcChargingInfo->ConnectorPlugIn);
  167. return;
  168. }
  169. int _index = atoi(v1);
  170. if (_index <= 1) {
  171. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  172. // printf ("FindChargingInfoData error\n");
  173. // return;
  174. //}
  175. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  176. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  177. // get
  178. printf ("index = %x, status = %x (%d) Reservation is :%s\n",
  179. _index,
  180. pDcChargingInfo->SystemStatus,
  181. pDcChargingInfo->IsAvailable,
  182. ShmDcCommonData->pGunInfo[_index].ReservationStatus ? "trigger" : "expired");
  183. if (ShmDcCommonData->pGunInfo[_index].ReservationStatus)
  184. printf("Reservation idTag:%s\n", ShmDcCommonData->pGunInfo[_index].ReservationID);
  185. printf("SystemTimeoutFlag = %d, PageIndex = %d\n",
  186. pSysInfo->SystemTimeoutFlag, pSysInfo->PageIndex);
  187. } else {
  188. // set
  189. pDcChargingInfo->SystemStatus = atoi(v2);
  190. }
  191. } else {
  192. //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  193. // printf("FindChargingInfoData (AC) false \n");
  194. //}
  195. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  196. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  197. // get
  198. printf ("AC Type, status = %x (%d)\n",
  199. pAcChargingInfo->SystemStatus,
  200. pAcChargingInfo->IsAvailable);
  201. } else {
  202. // set
  203. pAcChargingInfo->SystemStatus = atoi(v2);
  204. }
  205. }
  206. }
  207. void RunCardProc(char *v1, char *v2)
  208. {
  209. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  210. if (pSysInfo->WaitForPlugit) {
  211. pSysInfo->WaitForPlugit = 0x00;
  212. printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
  213. } else {
  214. pSysInfo->WaitForPlugit = 0x01;
  215. printf ("SysInfo.WaitForPlugit = %x \n", pSysInfo->WaitForPlugit);
  216. }
  217. } else {
  218. strcpy((char *)pSysConfig->UserId, "");
  219. memcpy((char *)pSysConfig->UserId, v1, strlen(v1));
  220. pSysConfig->UserId[strlen(v1)] = '\0';
  221. printf("StartUserId = %s \n", pSysConfig->UserId);
  222. }
  223. }
  224. void RunGunPlugitProc(char *v1, char *v2)
  225. {
  226. if (strcmp(v1, "ac") == 0) {
  227. //if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  228. // printf("FindChargingInfoData (AC) false \n");
  229. //}
  230. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  231. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  232. // get
  233. printf("ConnectorPlugIn = %d \n", pAcChargingInfo->ConnectorPlugIn);
  234. } else {
  235. // set
  236. pAcChargingInfo->ConnectorPlugIn = atoi(v2);
  237. }
  238. return;
  239. }
  240. int _index = atoi(v1);
  241. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  242. // printf("FindChargingInfoData error\n");
  243. // return;
  244. //}
  245. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  246. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  247. // get
  248. printf("index = %x, plug it = %x\n",
  249. _index,
  250. pDcChargingInfo->ConnectorPlugIn);
  251. } else {
  252. // set
  253. pDcChargingInfo->ConnectorPlugIn = atoi(v2);
  254. }
  255. }
  256. void GetGunLockStatusProc(char *v1, char *v2)
  257. {
  258. int _index = atoi(v1);
  259. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  260. // printf("FindChargingInfoData error\n");
  261. // return;
  262. //}
  263. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  264. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
  265. pDcChargingInfo->GunLocked = atoi(v2);
  266. }
  267. printf("Gun Locked Status = %d \n", pDcChargingInfo->GunLocked);
  268. }
  269. void SetSystemIDProc()
  270. {
  271. char *systemId = "Alston_Test";
  272. memcpy(&pSysConfig->SystemId, systemId, strlen(systemId));
  273. }
  274. void RunSelfProc()
  275. {
  276. printf("self test status = %x\n", pSysInfo->SelfTestSeq);
  277. }
  278. void GetFwVerProc(void)
  279. {
  280. int _index = 0;
  281. int isContinue = 1;
  282. char *usageMsg = "Usage:\n"
  283. " model\n"
  284. " 407\n"
  285. " conn index, ex: conn 0 | 1\n"
  286. " relay\n"
  287. " fan\n"
  288. " dc\n"
  289. " led\n"
  290. " ac\n"
  291. " exit | c | C\n"
  292. " help | ? | h\n";
  293. printf("ModelName = %s\r\n", pSysConfig->ModelName);
  294. printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
  295. printf("DC Main Debug Version = %s \n", ShmDcCommonData->DebugVersion);
  296. printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
  297. printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
  298. printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
  299. printf("Relay Board Version = %s \n", pSysInfo->RelayModuleFwRev);
  300. printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
  301. printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
  302. printf("LCM FW Version = V.%03d \n", ShmDcCommonData->LcmFwVersion);
  303. printf("Dispenser Network Information checked: IP = % s Netmask = % s, Gateway = % s \n",
  304. pSysConfig->Eth0Interface.EthIpAddress,
  305. pSysConfig->Eth0Interface.EthSubmaskAddress,
  306. pSysConfig->Eth0Interface.EthGatewayAddress);
  307. /*
  308. while (isContinue) {
  309. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  310. continue;
  311. }
  312. if (strcmp(newString[0], "407") == 0) {
  313. printf("407 FW Version = %s\n", ShmPrimaryMcuData->version);
  314. } else if (strcmp(newString[0], "model") == 0) {
  315. printf("ModelName = %s\r\n", pSysConfig->ModelName);
  316. } else if (strcmp(newString[0], "conn") == 0) {
  317. if (strcmp(newString[1], "-1") == 0 ||
  318. strcmp(newString[1], "") == 0 ||
  319. atoi(newString[1]) >= pSysConfig->TotalConnectorCount
  320. ) {
  321. printf("index over flow\r\n");
  322. continue;
  323. }
  324. _index = atoi(newString[1]);
  325. if (_index == 0) {
  326. printf("Gun 0 FW Version = %s \n", pSysInfo->Connector1FwRev);
  327. } else if (_index == 1) {
  328. printf("Gun 1 FW Version = %s \n", pSysInfo->Connector2FwRev);
  329. }
  330. } else if (strcmp(newString[0], "relay") == 0) {
  331. printf("RB Version = %s \n", pSysInfo->RelayModuleFwRev);
  332. } else if (strcmp(newString[0], "fan") == 0) {
  333. printf("FAN Version = %s \n", pSysInfo->FanModuleFwRev);
  334. } else if (strcmp(newString[0], "dc") == 0) {
  335. printf("DC Main Version = %s \n", pSysInfo->CsuRootFsFwRev);
  336. } else if (strcmp(newString[0], "led") == 0) {
  337. printf("LED Version = %s \n", pSysInfo->LedModuleFwRev);
  338. } else if (strcmp(newString[0], "ac") == 0) {
  339. pAcChargingInfo = (struct ChargingInfoData *)GetAcChargingInfoData(0);
  340. printf("AC Version = %s \n", pAcChargingInfo->version);
  341. } else if (exitCmd() == YES) {
  342. return;
  343. } else if (helpCmd() == YES) {
  344. printf ("%s\n", usageMsg);
  345. }
  346. }//while
  347. */
  348. }
  349. void CreateOneError(char *v1)
  350. {
  351. int value = atoi(v1);
  352. pAlarmCode->AlarmEvents.bits.SystemL1InputOVP = value;
  353. pSysConfig->BillingData.isBilling = value;
  354. }
  355. void GetAuthorizeFlag(char *v1)
  356. {
  357. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  358. printf("AuthorizeFlag = %d \n", pSysInfo->AuthorizeFlag);
  359. } else {
  360. pSysInfo->AuthorizeFlag = atoi(v1);
  361. }
  362. }
  363. void GetRelayStatus(char *v1)
  364. {
  365. int _index = atoi(v1);
  366. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  367. // printf("FindChargingInfoData error\n");
  368. // return;
  369. //}
  370. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  371. printf("RelayK1K2Status = %d \n", pDcChargingInfo->RelayK1K2Status);
  372. printf("RelayKPK2Status = %d \n", pDcChargingInfo->RelayKPK2Status);
  373. }
  374. void FwUpdateFlagProc()
  375. {
  376. pSysInfo->FirmwareUpdate = 0x01;
  377. }
  378. void CheckAcStatus(char *v1)
  379. {
  380. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  381. printf("AC Status = %d \n", pSysInfo->AcContactorStatus);
  382. }
  383. }
  384. void SetCableChkStatus(char *v1, char *v2)
  385. {
  386. int _index = atoi(v1);
  387. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  388. // printf ("FindChargingInfoData error\n");
  389. // return;
  390. //}
  391. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  392. pDcChargingInfo->GroundFaultStatus = atoi(v2);
  393. }
  394. void SetChargingInfoCCID(char *v1, char *v2)
  395. {
  396. int _index = atoi(v1);
  397. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  398. // printf ("FindChargingInfoData error\n");
  399. // return;
  400. //}
  401. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  402. memcpy(pDcChargingInfo->EVCCID, v2, 8);
  403. pDcChargingInfo->EVCCID[8] = '\0';
  404. }
  405. void SetPowerValue(char *v1, char *v2)
  406. {
  407. int _index = atoi(v1);
  408. float _Current = atof(v2);
  409. //if (!FindChargingInfoData(_index, &_chargingData[0])) {
  410. // printf ("FindChargingInfoData error\n");
  411. // return;
  412. //}
  413. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_index);
  414. // 盲沖的時候才允許使用~
  415. if (pDcChargingInfo->Type != 9) {
  416. return;
  417. }
  418. pDcChargingInfo->EvBatterytargetCurrent = _Current;
  419. }
  420. void GetSystemInfo()
  421. {
  422. printf ("ModelName = %s \n", pSysConfig->ModelName);
  423. printf ("SerialNumber = %s \n", pSysConfig->SerialNumber);
  424. printf ("InternetConn = %d \n", pSysInfo->InternetConn);
  425. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  426. pSysConfig->MaxChargingPower,
  427. pSysConfig->MaxChargingCurrent);
  428. pSysConfig->ShowInformation = YES;
  429. }
  430. void ChangeGunNum()
  431. {
  432. if (pSysInfo->CurGunSelected + 1 < pSysConfig->TotalConnectorCount) {
  433. pSysInfo->CurGunSelected += 1;
  434. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  435. } else if (pSysConfig->AcConnectorCount > 0 &&
  436. pSysInfo->CurGunSelectedByAc == NO_DEFINE) {
  437. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  438. } else {
  439. pSysInfo->CurGunSelected = 0;
  440. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  441. }
  442. }
  443. void GetGunSelectedNum(char *v1)
  444. {
  445. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  446. if (AC_QUANTITY > 0 &&
  447. pSysInfo->CurGunSelectedByAc != NO_DEFINE) {
  448. printf("connector select changed = AC \n");
  449. } else {
  450. printf("connector selected = %d \n", pSysInfo->CurGunSelected);
  451. }
  452. } else {
  453. int _index = atoi(v1);
  454. if (_index <= 1) {
  455. pSysInfo->CurGunSelected = _index;
  456. pSysInfo->CurGunSelectedByAc = NO_DEFINE;
  457. printf("connector select changed = %d \n", _index);
  458. } else if (AC_QUANTITY > 0) {
  459. pSysInfo->CurGunSelectedByAc = DEFAULT_AC_INDEX;
  460. printf("connector select changed = AC \n");
  461. }
  462. }
  463. }
  464. void SetFanSpeed(char *v1)
  465. {
  466. int speed = atoi(v1);
  467. if(ShmDcCommonData->debugflag == YES) {
  468. ShmFanModuleData->TestFanSpeed = speed;
  469. printf("Set Fan speed: %d \n",ShmFanModuleData->TestFanSpeed);
  470. }
  471. else
  472. printf("Please open debug mode\n");
  473. }
  474. void GetFanSpeed()
  475. {
  476. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  477. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  478. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  479. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  480. }
  481. void SetDebugMode(char *v1)
  482. {
  483. int mode = atoi(v1);
  484. ShmDcCommonData->debugflag = mode;
  485. pSysConfig->ShowInformation = mode;
  486. printf("Set Debug Mode:%d\n" , ShmDcCommonData->debugflag);
  487. }
  488. void SetGFDMode(char *v1)
  489. {
  490. int mode = atoi(v1);
  491. pSysConfig->AlwaysGfdFlag = mode;
  492. }
  493. void GetPsuTemp()
  494. {
  495. for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
  496. for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
  497. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  498. }
  499. }
  500. }
  501. void GetAcInputVol()
  502. {
  503. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  504. pSysInfo->InputVoltageR,
  505. pSysInfo->InputVoltageS,
  506. pSysInfo->InputVoltageT);
  507. }
  508. void GetPsuInformation(char *v1, char *v2, char *v3)
  509. {
  510. printf("**********************AC Contact needed*************************\n");
  511. if (strcmp(v1, "count") == 0) {
  512. for (int i = 0; i < 4; i++) {
  513. printf("Group Index = %d, Module Count = %d \n",
  514. i,
  515. ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  516. }
  517. } else if (strcmp(v1, "ver") == 0) {
  518. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
  519. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  520. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion,
  521. ShmPsuData->PsuVersion[i].FwSecondVersion);
  522. }
  523. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  524. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
  525. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  526. i,
  527. j,
  528. ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  529. }
  530. }
  531. } else if (strcmp(v1, "cap") == 0) {
  532. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  533. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  534. i,
  535. ShmPsuData->PsuGroup[i].GroupAvailableCurrent,
  536. ShmPsuData->PsuGroup[i].GroupAvailablePower);
  537. }
  538. } else if (strcmp(v1, "input") == 0) {
  539. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  540. for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
  541. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  542. i,
  543. count,
  544. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  545. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  546. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  547. }
  548. }
  549. } else if (strcmp(v1, "output") == 0) {
  550. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  551. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  552. i,
  553. ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage,
  554. ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  555. }
  556. for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  557. //if (!FindChargingInfoData(i, &_chargingData[0])) {
  558. // printf ("FindChargingInfoData error\n");
  559. // continue;
  560. //}
  561. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  562. printf("Form RB : Group Index = %d, OutputV = %f \n",
  563. i,
  564. pDcChargingInfo->FireChargingVoltage);
  565. }
  566. } else if (strcmp(v1, "test") == 0) {
  567. int mode = atoi(v2);
  568. if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
  569. ShmPsuData->Work_Step = mode;
  570. }
  571. } else if (strcmp(v1, "out") == 0) {
  572. float vol = atof(v2);
  573. float cur = atof(v3);
  574. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  575. //if (!FindChargingInfoData(0, &_chargingData[0])) {
  576. // printf ("FindChargingInfoData error\n");
  577. // return;
  578. //}
  579. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  580. pDcChargingInfo->EvBatterytargetVoltage = vol;
  581. pDcChargingInfo->EvBatterytargetCurrent = cur;
  582. }
  583. }
  584. printf("*************************************************\n");
  585. }
  586. void GetConnectorCapInfo(char *v1)
  587. {
  588. int _GunIndex = atoi(v1);
  589. //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
  590. // printf ("FindChargingInfoData error\n");
  591. // return;
  592. //}
  593. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  594. printf ("Charger Max Current = %d, Max Power = %d \n",
  595. pSysConfig->MaxChargingCurrent * 10,
  596. pSysConfig->MaxChargingPower * 10);
  597. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  598. _GunIndex,
  599. pDcChargingInfo->RealMaxPower,
  600. pDcChargingInfo->RealMaxVoltage,
  601. pDcChargingInfo->RealMaxCurrent);
  602. }
  603. static void setConfirmSelGun(uint8_t selGun)
  604. {
  605. if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
  606. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  607. //printf("confirmSelGun left\r\n");
  608. } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
  609. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  610. //printf("confirmSelGun right\r\n");
  611. }
  612. }
  613. static float ReadAdcVolt(uint8_t AdcChannel)
  614. {
  615. //AIN0=CCS GUN Temp 1
  616. //AIN1=CCS GUN Temp 2
  617. //AIN2=CCS_Proximity/2
  618. //AIN3=pilot voltage
  619. int fd = -1;
  620. uint8_t str[64] = { 0 };
  621. uint8_t AdcValue[8] = { '\0' };
  622. if (AdcChannel > 7) {
  623. return -1;
  624. }
  625. sprintf((char*)str, "/sys/bus/iio/devices/iio\:device0/in_voltage%d_raw", AdcChannel);
  626. fd = open((char*)str, O_RDONLY);
  627. read(fd, AdcValue, 4);
  628. close(fd);
  629. return (1.8 * atoi((char*)&AdcValue[0])) / 4095;
  630. //return (1.8 * atoi((char *)&AdcValue)) / 4095;
  631. }
  632. static void getChillerTemperature(struct ChargingInfoData* chargingData)
  633. {
  634. uint8_t i = 0;
  635. float adcVoltage = 0.0;
  636. ChillerTemp pChillerTemp;
  637. uint8_t maxTemp;
  638. for (i = 0; i < 4; i++) {
  639. adcVoltage = 0.0;
  640. adcVoltage = ReadAdcVolt(i);
  641. ShmDcCommonData->TempVolt[i] = adcVoltage;
  642. if ((adcVoltage <= 0.9) && (adcVoltage >= 0.8)) { //0 ~ -40
  643. pChillerTemp.Temp[i] = ((adcVoltage - 0.908) * 500) + 60;
  644. //log_info("1 adcVoltage = %f", (adcVoltage - 0.9) * 500);
  645. } else if ((adcVoltage <= 1.07) && (adcVoltage > 0.9)) {
  646. pChillerTemp.Temp[i] = ((adcVoltage - 0.91) * 705.88) + 60;
  647. //log_info("2 adcVoltage = %f", (adcVoltage - 0.9) * 500);
  648. } else {
  649. pChillerTemp.Temp[i] = UNDEFINED_TEMP;
  650. }
  651. }
  652. maxTemp = pChillerTemp.Temp[0];
  653. memcpy((char*)ShmDcCommonData->SystemTemp, (char*)pChillerTemp.Temp, sizeof(ChillerTemp));
  654. for (i = 1; i < 4; i++) {
  655. if (pChillerTemp.Temp[i] > pChillerTemp.Temp[i - 1] && pChillerTemp.Temp[i] != UNDEFINED_TEMP) {
  656. maxTemp = pChillerTemp.Temp[i];
  657. }
  658. }
  659. chargingData->ChillerTemp = maxTemp;
  660. }
  661. void GetOtpPwrOrCurMethod(struct ChargingInfoData* chargingData, float* pow, float* cur)
  662. {
  663. for(int i = 0 ; i < 4 ; i++) {
  664. if (ShmDcCommonData->SystemTemp[i] >= STAGE1_GUN_DERATING_TEMP &&
  665. ShmDcCommonData->SystemTemp[i] < STAGE2_GUN_DERATING_TEMP &&
  666. chargingData->deratingByConnOtp.deratingIndex < 1) {
  667. chargingData->deratingByConnOtp.deratingIndex = 1;
  668. } else if (ShmDcCommonData->SystemTemp[i] >= STAGE2_GUN_DERATING_TEMP &&
  669. ShmDcCommonData->SystemTemp[i] != UNDEFINED_TEMP &&
  670. chargingData->deratingByConnOtp.deratingIndex < 2) {
  671. chargingData->deratingByConnOtp.deratingIndex = 2;
  672. }
  673. }
  674. /*
  675. if (((chargingData->ConnectorTemp >= STAGE1_GUN_DERATING_TEMP &&
  676. chargingData->ConnectorTemp < STAGE2_GUN_DERATING_TEMP) ||
  677. (chargingData->ChillerTemp >= STAGE1_GUN_DERATING_TEMP &&
  678. chargingData->ChillerTemp < STAGE2_GUN_DERATING_TEMP)) &&
  679. chargingData->deratingByConnOtp.deratingIndex < 1)
  680. {
  681. chargingData->deratingByConnOtp.deratingIndex = 1;
  682. } else if ((chargingData->ConnectorTemp >= STAGE2_GUN_DERATING_TEMP ||
  683. chargingData->ChillerTemp >= STAGE2_GUN_DERATING_TEMP) &&
  684. chargingData->ConnectorTemp != UNDEFINED_TEMP &&
  685. chargingData->ChillerTemp != UNDEFINED_TEMP &&
  686. chargingData->deratingByConnOtp.deratingIndex < 2)
  687. {
  688. chargingData->deratingByConnOtp.deratingIndex = 2;
  689. }
  690. */
  691. if (chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex] != 0)
  692. {
  693. *pow *= chargingData->deratingByConnOtp.deratingTargetRate[chargingData->deratingByConnOtp.deratingIndex];
  694. } else if (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex] != 0)
  695. {
  696. if (*cur > (chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10)) {
  697. *cur = chargingData->deratingByConnOtp.deratingTargetCurrent[chargingData->deratingByConnOtp.deratingIndex]/10;
  698. }
  699. }
  700. }
  701. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  702. {
  703. int _GunIndex;
  704. uint8_t gunIndex = 0;
  705. uint8_t stopChg = 0;
  706. uint8_t curGun = 0;
  707. int isContinue = 1;
  708. float _Voltage;
  709. float _Current;
  710. float deratingPower;
  711. float deratingCurrent;
  712. int derating_index = 0;
  713. uint8_t PreviousSystemStatus[2] = {0xff};
  714. int idx;
  715. char *usageMsg = "Usage:\n"
  716. " strchg <index> <voltage> <current> ex: strchg 0 150 2\n"
  717. " chg <voltage> <current> ex: chg 500 100\n"
  718. " c <index> ex: c 0\n"
  719. " help | ? | h\n"
  720. "\r\n";
  721. if (strcmp(v1, "auto") == EQUAL) {
  722. _usingAutoRun = 0x01;
  723. _GunIndex = 0;
  724. _Voltage = 500;
  725. _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
  726. } else {
  727. _usingAutoRun = 0x00;
  728. _GunIndex = atoi(v1);
  729. _Voltage = atof(v2);
  730. _Current = atof(v3);
  731. }
  732. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  733. printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  734. pSysConfig->MaxChargingPower,
  735. _Voltage,
  736. _Current);
  737. if (_Voltage > 1000 || _Voltage < 50) {
  738. printf ("Input Voltage over range\n");
  739. return;
  740. }
  741. //kill ev task
  742. ShmDcCommonData->debugflag = YES;
  743. system("killall Module_EvComm");
  744. pSysInfo->CurGunSelected = _GunIndex;
  745. while (isContinue) {
  746. curGun = pSysInfo->CurGunSelected;
  747. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
  748. //fix gun 1
  749. switch (pDcChargingInfo->SystemStatus) {
  750. case S_IDLE:
  751. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  752. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  753. #if defined DD360Audi
  754. setConfirmSelGun(curGun);
  755. #endif //defined DD360Audi
  756. strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
  757. pDcChargingInfo->ConnectorPlugIn = 1;
  758. printf ("[UnconditionalCharge - S_IDLE]\n");
  759. pDcChargingInfo->Type = 9;
  760. sleep(1);
  761. }
  762. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
  763. pSysInfo->StartToChargingFlag = 0x01;
  764. pDcChargingInfo->SystemStatus = S_PREPARNING;
  765. }
  766. break;
  767. case S_PREPARNING:
  768. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  769. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  770. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  771. ShmFanModuleData->TestFanSpeed = 7000;
  772. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  773. printf ("wait find module\n");
  774. }
  775. //main 會在此階段判斷以下資料跳到下一個 state
  776. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  777. //ShmPsuData->SystemPresentPsuQuantity;
  778. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  779. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  780. //_chargingData[gun_index]->AvailableChargingPower;
  781. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  782. //sleep(10);
  783. //清除 main timeout 機制
  784. pDcChargingInfo->TimeoutFlag = 0;
  785. pSysInfo->SystemTimeoutFlag = 0;
  786. pSysInfo->SystemPage = _LCM_NONE;
  787. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  788. pDcChargingInfo->Type = 9;
  789. break;
  790. case S_PREPARING_FOR_EV:
  791. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  792. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  793. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  794. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
  795. }
  796. //清除 main timeout 機制
  797. pDcChargingInfo->TimeoutFlag = 0;
  798. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  799. pDcChargingInfo->Type = 9;
  800. //充電電壓電流
  801. pDcChargingInfo->EvBatterySoc = 50;
  802. pDcChargingInfo->EvBatterytargetVoltage = 500;
  803. pDcChargingInfo->EvBatterytargetCurrent = 2;
  804. pDcChargingInfo->AvailableChargingCurrent = 1000;
  805. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  806. //確定模組己升壓完成
  807. //if(pDcChargingInfo->PresentChargingVoltage <= (3000+500) &&
  808. // pDcChargingInfo->PresentChargingVoltage >= (3000-500) )
  809. {
  810. printf ("Precharge Done = %f \n",
  811. pDcChargingInfo->PresentChargingVoltage);
  812. //EV done
  813. pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
  814. }
  815. break;
  816. case S_PREPARING_FOR_EVSE:
  817. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  818. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  819. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  820. }
  821. //printf ("tar vol = %d \n", _Voltage);
  822. //printf ("tar cur = %d \n", _Current);
  823. //清除 main timeout 機制
  824. pDcChargingInfo->TimeoutFlag = 0;
  825. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  826. pDcChargingInfo->Type = 9;
  827. //充電電壓電流
  828. pDcChargingInfo->EvBatterySoc = 50;
  829. pDcChargingInfo->EvBatterytargetVoltage = 500;
  830. pDcChargingInfo->EvBatterytargetCurrent = 2;
  831. pDcChargingInfo->AvailableChargingCurrent = 1000;
  832. //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage);
  833. // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent);
  834. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  835. //確定模組己升壓完成
  836. if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
  837. pDcChargingInfo->GroundFaultStatus == 0x03) {
  838. printf ("First Ground Fault State (%d)\n",
  839. pDcChargingInfo->GroundFaultStatus);
  840. printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
  841. sleep(5);
  842. //EV done
  843. pDcChargingInfo->SystemStatus = S_CHARGING;
  844. } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
  845. printf ("First Ground Fault check Fail (%d)\n",
  846. pDcChargingInfo->GroundFaultStatus);
  847. pDcChargingInfo->SystemStatus = S_TERMINATING;
  848. }
  849. break;
  850. case S_CHARGING:
  851. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  852. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  853. if (_usingAutoRun == 0x00) {
  854. //充電電壓電流
  855. pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
  856. pDcChargingInfo->EvBatterytargetCurrent = _Current;
  857. } else {
  858. _curAutoRunCount = 0;
  859. gettimeofday(&_autoTime, NULL);
  860. }
  861. pDcChargingInfo->EvBatterySoc = 50;
  862. pDcChargingInfo->AvailableChargingCurrent = 1000;
  863. printf ("[UnconditionalCharge - S_CHARGING]\n");
  864. }
  865. if (_usingAutoRun == 0x01) {
  866. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
  867. (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  868. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
  869. (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
  870. ) {
  871. pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
  872. pDcChargingInfo->EvBatterytargetCurrent = _Current;
  873. } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
  874. _curAutoRunCount++;
  875. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
  876. pDcChargingInfo->SystemStatus = S_TERMINATING;
  877. } else {
  878. gettimeofday(&_autoTime, NULL);
  879. }
  880. } else {
  881. pDcChargingInfo->EvBatterytargetVoltage = 0;
  882. pDcChargingInfo->EvBatterytargetCurrent = 0;
  883. }
  884. }
  885. // printf("out : vol = %f, cur = %f \n",
  886. // pDcChargingInfo->EvBatterytargetVoltage,
  887. // pDcChargingInfo->EvBatterytargetCurrent);
  888. //ev task do this
  889. for (idx = 0; idx < pSysConfig->TotalConnectorCount; idx++) {
  890. struct ChargingInfoData* pInfo = (struct ChargingInfoData*)GetDcChargingInfoData(idx);
  891. if (pInfo->deratingByConnOtp.isNeedDerating) {
  892. deratingCurrent = pInfo->EvBatterytargetCurrent;
  893. deratingPower = pInfo->AvailableChargingPower;
  894. getChillerTemperature(pInfo);
  895. GetOtpPwrOrCurMethod(pInfo, &deratingPower, &deratingCurrent);
  896. if (derating_index != pDcChargingInfo->deratingByConnOtp.deratingIndex) {
  897. printf("Change Derating Index:%d\n", pInfo->deratingByConnOtp.deratingIndex);
  898. derating_index = pInfo->deratingByConnOtp.deratingIndex;
  899. }
  900. if (pInfo->EvBatterytargetCurrent != deratingCurrent ||
  901. pInfo->AvailableChargingPower != deratingPower) {
  902. pInfo->EvBatterytargetCurrent = deratingCurrent;
  903. pInfo->AvailableChargingPower = deratingPower;
  904. printf("Derating Current:%.3f Power:%.3f\n", pInfo->EvBatterytargetCurrent, pInfo->AvailableChargingPower);
  905. }
  906. }
  907. } // for
  908. pDcChargingInfo->PresentChargingPower =
  909. ((float)((pDcChargingInfo->PresentChargingVoltage) *
  910. (pDcChargingInfo->PresentChargingCurrent)) / 1000);
  911. if (pDcChargingInfo->GroundFaultStatus == 0x02) {
  912. printf ("Charging Ground Fault check Fail (%d)\n",
  913. pDcChargingInfo->GroundFaultStatus);
  914. pDcChargingInfo->SystemStatus = S_TERMINATING;
  915. }
  916. break;
  917. case S_TERMINATING:
  918. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  919. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  920. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  921. //無阻塞偵測 keybaord 結束
  922. system(STTY_DEF TTY_PATH);
  923. }
  924. pDcChargingInfo->ConnectorPlugIn = 0;
  925. pDcChargingInfo->SystemStatus = S_COMPLETE;
  926. break;
  927. case S_COMPLETE:
  928. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  929. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  930. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  931. }
  932. PreviousSystemStatus[curGun] = 0xFF;
  933. stopChg = 0;
  934. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  935. if (PreviousSystemStatus[gunIndex] == 0xFF) {
  936. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
  937. pDcChargingInfo->SystemStatus = S_IDLE;
  938. } else {
  939. pSysInfo->CurGunSelected = gunIndex;
  940. }
  941. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  942. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  943. stopChg++;
  944. }
  945. }
  946. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
  947. pDcChargingInfo->PresentChargingPower = 0;
  948. if (stopChg == pSysConfig->TotalConnectorCount) {
  949. system("/root/Module_EvComm &");
  950. ShmFanModuleData->TestFanSpeed = 0;
  951. ShmDcCommonData->debugflag = NO;
  952. sleep(3);
  953. for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
  954. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  955. pDcChargingInfo->SystemStatus = S_IDLE;
  956. }
  957. return;
  958. }
  959. break;
  960. }
  961. if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
  962. continue;
  963. }
  964. if (strcmp(newString[0], "strchg") == 0) {
  965. if (strcmp(newString[1], "-1") == 0 ||
  966. strcmp(newString[1], "") == 0 ||
  967. strcmp(newString[2], "-1") == 0 ||
  968. strcmp(newString[2], "") == 0
  969. ) {
  970. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  971. continue;
  972. }
  973. if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
  974. continue;
  975. }
  976. _GunIndex = atoi((char *)newString[1]);
  977. _Voltage = atof((char *)newString[2]);
  978. _Current = atof((char *)newString[3]);
  979. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  980. pSysConfig->MaxChargingPower,
  981. _Voltage,
  982. _Current);
  983. if (_Voltage > 1000 || _Voltage < 50) {
  984. _Voltage = 200;
  985. printf ("Input Voltage over range\n");
  986. continue;
  987. }
  988. pSysInfo->CurGunSelected = _GunIndex;
  989. strcpy((char *)pSysConfig->UserId, "");
  990. } else if (strcmp(newString[0], "chg") == 0) {
  991. if (strcmp(newString[1], "-1") == 0) {
  992. continue;
  993. }
  994. if (strcmp(newString[2], "-1") == 0 ||
  995. strcmp(newString[2], "") == 0) {
  996. continue;
  997. }
  998. if (strcmp(newString[3], "-1") == 0 ||
  999. strcmp(newString[3], "") == 0) {
  1000. continue;
  1001. }
  1002. _GunIndex = atoi((char *)newString[1]);
  1003. float _vol = atof(newString[2]);
  1004. float _cur = atof(newString[3]);
  1005. if (_cur <= 0 || _cur <= 0) {
  1006. continue;
  1007. }
  1008. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  1009. printf("reset vol = %f, cur = %f \n", _vol, _cur);
  1010. pDcChargingInfo->EvBatterytargetVoltage = _vol;
  1011. pDcChargingInfo->EvBatterytargetCurrent = _cur;
  1012. } else if (strcmp(newString[0], "c") == 0) {
  1013. if (strcmp(newString[1], "-1") == 0 ||
  1014. strcmp(newString[1], "") == 0) {
  1015. printf("argc 1 is error parameter\r\n");
  1016. continue;
  1017. }
  1018. if (atoi((char *)newString[1]) != -1) {
  1019. pSysInfo->CurGunSelected = atoi((char *)newString[1]);
  1020. }
  1021. printf("stop \n\r");
  1022. pSysInfo->StartToChargingFlag = 0x00;
  1023. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
  1024. pDcChargingInfo->SystemStatus = S_TERMINATING;
  1025. } else if (helpCmd() == YES) {
  1026. printf("%s\n", usageMsg);
  1027. }
  1028. usleep(100000);
  1029. }
  1030. }
  1031. int printTimeMsg(const char *fmt, ...)
  1032. {
  1033. char Buf[4096 + 256] = {0};
  1034. char buffer[4096] = {0};
  1035. int rc = -1;
  1036. va_list args;
  1037. struct timeb SeqEndTime;
  1038. struct tm *tm;
  1039. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1040. va_start(args, fmt);
  1041. rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  1042. va_end(args);
  1043. ftime(&SeqEndTime);
  1044. SeqEndTime.time = time(NULL);
  1045. tm = localtime(&SeqEndTime.time);
  1046. sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  1047. tm->tm_hour,
  1048. tm->tm_min,
  1049. tm->tm_sec,
  1050. SeqEndTime.millitm,
  1051. buffer);
  1052. printf("%s", Buf);
  1053. return rc;
  1054. }
  1055. static void resdGunAndChillerTemp(void)
  1056. {
  1057. int isContinue = 1;
  1058. uint8_t i = 0;
  1059. uint32_t sleepTime = 500000;
  1060. uint32_t loopTime = 1000;
  1061. struct timeb showTime;
  1062. struct timeb nowTime;
  1063. char *usageMsg = "Usage:\n"
  1064. " t <index>: loop time, ex: t 1\n"
  1065. " exit | c | C: exit test\n"
  1066. " h | help | ?: show usage message\n"
  1067. "\r\n";
  1068. ftime(&showTime);
  1069. while (isContinue) {
  1070. ftime(&nowTime);
  1071. if (DiffTimeb(showTime, nowTime) > loopTime ||
  1072. DiffTimeb(showTime, nowTime) < 0) {
  1073. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  1074. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  1075. printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d(%.3f), %3d(%.3f), %3d(%.3f), %3d(%.3f)\r\n",
  1076. i,
  1077. pDcChargingInfo->ConnectorTemp,
  1078. pDcChargingInfo->ChillerTemp,
  1079. ShmDcCommonData->ConnectorTemp[i][0],
  1080. ShmDcCommonData->ConnectorTemp[i][1],
  1081. ShmDcCommonData->SystemTemp[0],
  1082. ShmDcCommonData->TempVolt[0],
  1083. ShmDcCommonData->SystemTemp[1],
  1084. ShmDcCommonData->TempVolt[1],
  1085. ShmDcCommonData->SystemTemp[2],
  1086. ShmDcCommonData->TempVolt[2],
  1087. ShmDcCommonData->SystemTemp[3],
  1088. ShmDcCommonData->TempVolt[3]);
  1089. }//for
  1090. ftime(&showTime);
  1091. }
  1092. if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
  1093. usleep(sleepTime);
  1094. continue;
  1095. }
  1096. if (strcmp(newString[0], "t") == 0) {
  1097. if (strcmp(newString[1], "-1") == 0 ||
  1098. strcmp(newString[1], "") == 0 ||
  1099. atoi((char *)newString[1]) > 255
  1100. ) {
  1101. printf("argc 1 is error parameter\r\n");
  1102. continue;
  1103. }
  1104. loopTime = ((atoi((char *)newString[1])) * 1000);
  1105. printf("loopTime = %d\r\n", loopTime);
  1106. ftime(&showTime);
  1107. continue;
  1108. } else if (exitCmd() == YES) {
  1109. return;
  1110. } else if (helpCmd() == YES) {
  1111. printf ("%s\n", usageMsg);
  1112. }
  1113. usleep(sleepTime);
  1114. }//while
  1115. }
  1116. static void writeOTPTemp(void)
  1117. {
  1118. uint8_t _GunIndex = 0;
  1119. int isContinue = 1;
  1120. uint32_t sleepTime = 500000;
  1121. char *usageMsg = "Usage:\n"
  1122. " OTP <temp_recovery> <temp>, ex: OTP 140 150\n"
  1123. " exit | c | C\n"
  1124. " help | ? | h\n"
  1125. "\r\n";
  1126. while (isContinue) {
  1127. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  1128. sleep(sleepTime);
  1129. continue;
  1130. }
  1131. if (helpCmd() == YES) {
  1132. printf ("%s\n", usageMsg);
  1133. continue;
  1134. } else if (exitCmd() == YES) {
  1135. sleep(1);
  1136. return;
  1137. }
  1138. if (strcmp(newString[0], "OTP") != 0) {
  1139. printf("argc 1 is error parameter\r\n");
  1140. continue;
  1141. }
  1142. if (atoi(newString[1]) > 255 ||
  1143. atoi(newString[1]) == -1) {
  1144. printf("Recovey temperature value overflow\r\n");
  1145. continue;
  1146. }
  1147. if (atoi(newString[2]) > 255 ||
  1148. atoi(newString[2]) == -1) {
  1149. printf("Recovey temperature value overflow\r\n");
  1150. continue;
  1151. }
  1152. pSysInfo->OTPTempR = atoi(newString[1]);
  1153. pSysInfo->OTPTemp = atoi(newString[2]);
  1154. printf("OTP Recovery Temp set:%d\n",pSysInfo->OTPTempR);
  1155. printf("OTP Temp set:%d\n",pSysInfo->OTPTemp);
  1156. usleep(sleepTime);
  1157. }//while
  1158. }
  1159. void writeChillerStatus(char *v1)
  1160. {
  1161. if (ShmDcCommonData->debugflag == YES) {
  1162. ShmDcCommonData->chillerCtrl = atoi(newString[1]);
  1163. if (ShmDcCommonData->chillerCtrl)
  1164. printf("Chiller set on\n");
  1165. else
  1166. printf("Chiller set off\n");
  1167. } else
  1168. printf("Please open Debug mode\n");
  1169. }
  1170. void showNetworkPage(char* v1)
  1171. {
  1172. ShmDcCommonData->showNetPackage = atoi(newString[1]);
  1173. if (ShmDcCommonData->showNetPackage)
  1174. printf("Show Network Package on\n");
  1175. else
  1176. printf("Show Network Package off\n");
  1177. }
  1178. void showCANBUSPage(char* v1)
  1179. {
  1180. ShmDcCommonData->showCanPackage = atoi(newString[1]);
  1181. if (ShmDcCommonData->showCanPackage)
  1182. printf("Show CAN Bus Package on\n");
  1183. else
  1184. printf("Show CAN Bus Package off\n");
  1185. }
  1186. void setSystemTime(char* date,char* time)
  1187. {
  1188. char _setTime[30];
  1189. char cmdBuf[50];
  1190. sprintf(_setTime, "%s %s", date, time);
  1191. printf("Set Timer:%s", _setTime);
  1192. sprintf((char*)cmdBuf, "date -u -s \"%s\" >> /dev/null &", _setTime);
  1193. system((char*)cmdBuf);
  1194. system("hwclock -w -u");
  1195. system("hwclock -s");
  1196. }
  1197. static void writeGunAndChillerTemp(void)
  1198. {
  1199. uint8_t _GunIndex = 0;
  1200. int isContinue = 1;
  1201. uint32_t sleepTime = 500000;
  1202. char *usageMsg = "Usage:\n"
  1203. " conn <index> <temp>, ex: conn 0 150\n"
  1204. " chiller <index> <temp>, ex: chiller 0 150\n"
  1205. " tempR\n"
  1206. " exit | c | C\n"
  1207. " help | ? | h\n"
  1208. "\r\n";
  1209. ShmDcCommonData->TestTemperature = YES;
  1210. while (isContinue) {
  1211. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  1212. sleep(sleepTime);
  1213. continue;
  1214. }
  1215. if (helpCmd() == YES) {
  1216. printf ("%s\n", usageMsg);
  1217. continue;
  1218. } else if (exitCmd() == YES) {
  1219. ShmDcCommonData->TestTemperature = NO;
  1220. sleep(1);
  1221. return;
  1222. } else if (strcmp(newString[0], "tempR") == 0) {
  1223. resdGunAndChillerTemp();
  1224. }
  1225. if ((strcmp(newString[0], "chiller") != 0) &&
  1226. (strcmp(newString[1], "-1") == 0 ||
  1227. strcmp(newString[1], "") == 0)
  1228. ) {
  1229. printf("argc 1 is error parameter\r\n");
  1230. continue;
  1231. }
  1232. if (atoi(newString[2]) > 255 ||
  1233. atoi(newString[2]) == -1) {
  1234. printf("temperature value overflow\r\n");
  1235. continue;
  1236. }
  1237. _GunIndex = atoi((char *)newString[1]);
  1238. if (_GunIndex >= pSysConfig->TotalConnectorCount) {
  1239. printf("gun index over total connector\r\n");
  1240. continue;
  1241. }
  1242. if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
  1243. if (ShmDcCommonData->pGunInfo[_GunIndex].withChiller) {
  1244. pDcChargingInfo = (struct ChargingInfoData*)GetDcChargingInfoData(_GunIndex);
  1245. memset((char*)ShmDcCommonData->SystemTemp, atoi(newString[2]), sizeof(ShmDcCommonData->SystemTemp));
  1246. pDcChargingInfo->ChillerTemp = atoi(newString[2]);
  1247. printf("set %d chiller temperature = %d\r\n",
  1248. _GunIndex,
  1249. pDcChargingInfo->ChillerTemp);
  1250. } else {
  1251. printf("This Gun without Chiller");
  1252. }
  1253. } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值
  1254. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  1255. pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
  1256. printf("set %d connector temp = %d\r\n",
  1257. _GunIndex,
  1258. pDcChargingInfo->ConnectorTemp);
  1259. }
  1260. usleep(sleepTime);
  1261. }//while
  1262. }
  1263. void setledcolor(int on_off)
  1264. {
  1265. if (on_off)
  1266. ShmDcCommonData->pTest.ledflag = TRUE;
  1267. else {
  1268. ShmDcCommonData->pTest.ledflag = FALSE;
  1269. return;
  1270. }
  1271. int isContinue = 1;
  1272. uint32_t sleepTime = 500000;
  1273. uint32_t color_value;
  1274. char* usageMsg = "Usage:\n"
  1275. " r 0~100\n"
  1276. " g 0~100\n"
  1277. " b 0~100\n"
  1278. " exit | c | C\n"
  1279. " help | ? | h\n"
  1280. "\r\n";
  1281. while (isContinue) {
  1282. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  1283. sleep(sleepTime);
  1284. continue;
  1285. }
  1286. if (helpCmd() == YES) {
  1287. printf("%s\n", usageMsg);
  1288. continue;
  1289. } else if (exitCmd() == YES) {
  1290. ShmDcCommonData->pTest.ledflag = FALSE;
  1291. return;
  1292. }
  1293. if ((strcmp(newString[0], "r") != 0) &&
  1294. (strcmp(newString[1], "-1") == 0 ||
  1295. strcmp(newString[1], "") == 0)
  1296. ) {
  1297. printf("argc 1 is error parameter\r\n");
  1298. continue;
  1299. }
  1300. if ((strcmp(newString[0], "g") != 0) &&
  1301. (strcmp(newString[1], "-1") == 0 ||
  1302. strcmp(newString[1], "") == 0)
  1303. ) {
  1304. printf("argc 1 is error parameter\r\n");
  1305. continue;
  1306. }
  1307. if ((strcmp(newString[0], "b") != 0) &&
  1308. (strcmp(newString[1], "-1") == 0 ||
  1309. strcmp(newString[1], "") == 0)
  1310. ) {
  1311. printf("argc 1 is error parameter\r\n");
  1312. continue;
  1313. }
  1314. if (atoi(newString[1]) < 0 || atoi(newString[1]) > 100) {
  1315. printf("argc 1 is error parameter range is 0~100\r\n");
  1316. continue;
  1317. }
  1318. if (strcmp(newString[0], "r") == EQUAL &&
  1319. atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
  1320. pSysConfig->LedInfo.Red[0] = atoi(newString[1]);
  1321. } else {
  1322. }
  1323. if (strcmp(newString[0], "g") == EQUAL &&
  1324. atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
  1325. pSysConfig->LedInfo.Green[0] = atoi(newString[1]);
  1326. }
  1327. if (strcmp(newString[0], "b") == EQUAL &&
  1328. atoi(newString[1]) >= 0 && atoi(newString[1]) <= 100) {
  1329. pSysConfig->LedInfo.Blue[0] = atoi(newString[1]);
  1330. }
  1331. printf("Color set red[%d] green[%d] blue[%d]\n", pSysConfig->LedInfo.Red[0], pSysConfig->LedInfo.Green[0], pSysConfig->LedInfo.Blue[0]);
  1332. usleep(sleepTime);
  1333. }//while
  1334. ShmDcCommonData->pTest.ledflag = FALSE;
  1335. }
  1336. void ShowPowerConsumption(char* v1)
  1337. {
  1338. printf("Dispenser Gun0 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[0].PowerConsumption);
  1339. printf("Dispenser Gun1 PowerConsumption:%.4f\n", ShmDcCommonData->pGunInfo[1].PowerConsumption);
  1340. printf("Power Consumption Gun1:%.4f, Gun2:%.4f, Gun3:%.4f, Gun4:%.4f", ShmDcCommonData->pConsumption.Gun1_Consumption,
  1341. ShmDcCommonData->pConsumption.Gun2_Consumption,
  1342. ShmDcCommonData->pConsumption.Gun3_Consumption,
  1343. ShmDcCommonData->pConsumption.Gun4_Consumption);
  1344. }
  1345. int main(void)
  1346. {
  1347. uint8_t _GunIndex = 0;
  1348. int isContinue = 1;
  1349. char *usageMsg = "Usage:\n"
  1350. " state <index> : get gun state\n"
  1351. " card : scanning card (x)\n"
  1352. " gun <index> : get gun plugit state\n"
  1353. " lock <index> : get gun locked state\n"
  1354. " sysid : test system ID\n"
  1355. " self : self test state (x)\n"
  1356. " ver| v | -v : version of board (407 or relay or other)\n"
  1357. " update : update firmware\n"
  1358. " ac : get ac relay state (x) \n"
  1359. " cable <index> <state> : set ground fault state\n"
  1360. " pow <index> <power> : set power value\n"
  1361. " model : get system information\n"
  1362. " temp : get PSU temperature\n"
  1363. " fan <speed> : set fan board speed\n"
  1364. " strchg <auto> : auto test charging\n"
  1365. " strchg <index> <voltage <current> : select gun test charging\n"
  1366. " tempW : write connector header and Chiller temperature\r\n"
  1367. " tempR : print connector header and chiller temperature\r\n"
  1368. " OTP : Write OTP temperature\r\n"
  1369. " chiller : set chiller on/off\r\n"
  1370. " netdump : show network package\r\n"
  1371. " candump : show can package\r\n"
  1372. " powerconsumption : Show Power Consumption\n"
  1373. " led : set led color\n"
  1374. "\r\n";
  1375. if (CreateAllCsuShareMemory() == FAIL) {
  1376. printf("create share memory error\r\n");
  1377. return FAIL;
  1378. }
  1379. MappingGunChargingInfo("ReadCmdline Task");
  1380. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1381. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1382. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1383. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1384. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  1385. ShmGBTData = (struct GBTData *)GetShmGBTData();
  1386. ShmCcsData = (struct CcsData *)GetShmCcsData();
  1387. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1388. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  1389. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  1390. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  1391. ShmPsuData = (struct PsuData *)GetShmPsuData();
  1392. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  1393. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1394. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1395. // for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
  1396. // pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  1397. // pDcChargingInfo->SystemStatus = S_IDLE;
  1398. // }
  1399. while (isContinue) {
  1400. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  1401. continue;
  1402. }
  1403. if (strcmp(newString[0], "state") == 0) {
  1404. if (strcmp(newString[1], "-1") == 0 ||
  1405. strcmp(newString[1], "") == 0) {
  1406. continue;
  1407. }
  1408. // 槍狀態
  1409. RunStatusProc(newString[1], newString[2]);
  1410. } else if (strcmp(newString[0], "card") == 0) {
  1411. // 刷卡狀態
  1412. RunCardProc(newString[1], newString[2]);
  1413. } else if (strcmp(newString[0], "gun") == 0) {
  1414. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1415. continue;
  1416. }
  1417. // 插槍狀態
  1418. RunGunPlugitProc(newString[1], newString[2]);
  1419. } else if (strcmp(newString[0], "lock") == 0) {
  1420. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1421. continue;
  1422. }
  1423. // 插槍狀態
  1424. GetGunLockStatusProc(newString[1], newString[2]);
  1425. } else if (strcmp(newString[0], "sysid") == 0) {
  1426. // 測試 sys id
  1427. SetSystemIDProc();
  1428. } else if (strcmp(newString[0], "self") == 0) {
  1429. // CSU 自我檢測狀態
  1430. RunSelfProc(newString[1]);
  1431. } else if (strcmp(newString[0], "ver") == 0 ||
  1432. strcmp(newString[0], "v") == 0 ||
  1433. strcmp(newString[0], "-v") == 0) {
  1434. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1435. // continue;
  1436. //}
  1437. // 取 FW 版號
  1438. GetFwVerProc();
  1439. } else if (strcmp(newString[0], "update") == 0) {
  1440. // 更新
  1441. FwUpdateFlagProc(newString[1]);
  1442. } else if (strcmp(newString[0], "ac") == 0) {
  1443. // AC contactor 狀態
  1444. CheckAcStatus(newString[1]);
  1445. } else if (strcmp(newString[0], "cable") == 0) {
  1446. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1447. continue;
  1448. }
  1449. // cable check pass
  1450. SetCableChkStatus(newString[1], newString[2]);
  1451. } else if (strcmp(newString[0], "pow") == 0) {
  1452. if (strcmp(newString[1], "-1") == 0 ||
  1453. strcmp(newString[1], "") == 0) {
  1454. continue;
  1455. }
  1456. // cable check pass
  1457. SetPowerValue(newString[1], newString[2]);
  1458. } else if (strcmp(newString[0], "model") == 0) {
  1459. GetSystemInfo();
  1460. } else if (strcmp(newString[0], "select") == 0) {
  1461. // 取得 / 設定 當前選的槍號
  1462. GetGunSelectedNum(newString[1]);
  1463. } else if (strcmp(newString[0], "change") == 0) {
  1464. // 模擬按鈕改變選槍
  1465. ChangeGunNum();
  1466. } else if (strcmp(newString[0], "fan") == 0) {
  1467. // 設定風扇速度
  1468. SetFanSpeed(newString[1]);
  1469. } else if (strcmp(newString[0], "speed") == 0) {
  1470. // 取得風扇速度
  1471. GetFanSpeed();
  1472. } else if (strcmp(newString[0], "debug") == 0) {
  1473. // 設定 debug mode
  1474. SetDebugMode(newString[1]);
  1475. } else if (strcmp(newString[0], "gfd") == 0) {
  1476. // 設定盲沖使用 GFD 功能
  1477. SetGFDMode(newString[1]);
  1478. } else if (strcmp(newString[0], "temp") == 0) {
  1479. // 取得 PSU 溫度
  1480. GetPsuTemp();
  1481. } else if (strcmp(newString[0], "acin") == 0) {
  1482. // 取得三向輸入電壓
  1483. GetAcInputVol();
  1484. } else if (strcmp(newString[0], "psu") == 0) {
  1485. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1486. if (strcmp(newString[1], "-1") == 0 ||
  1487. strcmp(newString[1], "") == 0) {
  1488. printf ("PSU : Param fail..Please retry again......\n");
  1489. continue;
  1490. }
  1491. // 取得 PSU 資訊
  1492. GetPsuInformation(newString[1], newString[2], newString[3]);
  1493. } else if (strcmp(newString[0], "cap") == 0) {
  1494. GetConnectorCapInfo(newString[1]);
  1495. } else if (strcmp(newString[0], "error") == 0) {
  1496. CreateOneError(newString[1]);
  1497. } else if (strcmp(newString[0], "auth") == 0) {
  1498. GetAuthorizeFlag(newString[1]);
  1499. } else if (strcmp(newString[0], "relay") == 0) {
  1500. GetRelayStatus(newString[1]);
  1501. } else if (strcmp(newString[0], "ccid") == 0) {
  1502. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1503. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
  1504. printf ("Input ccid fail.\n");
  1505. continue;
  1506. }
  1507. SetChargingInfoCCID(newString[1], newString[2]);
  1508. } else if (strcmp(newString[0], "strchg") == 0) {
  1509. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1510. if (strcmp(newString[1], "auto") == 0) {
  1511. newString[2][0] = 0;
  1512. newString[3][0] = 0;
  1513. } else if (strcmp(newString[1], "-1") == 0 ||
  1514. strcmp(newString[1], "") == 0 ||
  1515. strcmp(newString[2], "-1") == 0 ||
  1516. strcmp(newString[2], "") == 0) {
  1517. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1518. continue;
  1519. }
  1520. // 槍狀態
  1521. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1522. } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度
  1523. writeGunAndChillerTemp();
  1524. } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
  1525. resdGunAndChillerTemp();
  1526. } else if (strcmp(newString[0], "OTP") == 0) { //測試槍頭和水冷機溫度
  1527. writeOTPTemp();
  1528. } else if (strcmp(newString[0], "chiller") == 0) { //測試槍頭和水冷機溫度
  1529. writeChillerStatus(newString[1]);
  1530. } else if (strcmp(newString[0], "netdump") == 0) { //印出網路封包
  1531. showNetworkPage(newString[1]);
  1532. } else if (strcmp(newString[0], "candump") == 0) { //印出網路封包
  1533. showCANBUSPage(newString[1]);
  1534. } else if (strcmp(newString[0], "time") == 0) { //設定系統時間
  1535. setSystemTime(newString[1], newString[2]);
  1536. } else if (strcmp(newString[0], "powerconsumption") == 0) { // Power Consumption
  1537. ShowPowerConsumption(newString[1]);
  1538. } else if (strcmp(newString[0], "led") == 0) { // LED
  1539. setledcolor(newString[1]);
  1540. } else {
  1541. printf("%s\n", usageMsg);
  1542. }
  1543. sleep(1);
  1544. }//while
  1545. return 0;
  1546. }