ReadCmdline.c 55 KB

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