ReadCmdline.c 56 KB

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