ReadCmdline.c 54 KB

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