ReadCmdline.c 56 KB

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