ReadCmdline.c 64 KB

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