ReadCmdline.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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 SetFanSpeed(char *v1)
  445. {
  446. int speed = atoi(v1);
  447. ShmFanModuleData->TestFanSpeed = speed;
  448. }
  449. void GetFanSpeed()
  450. {
  451. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  452. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  453. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  454. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  455. }
  456. void SetDebugMode(char *v1)
  457. {
  458. int mode = atoi(v1);
  459. pSysConfig->SwitchDebugFlag = mode;
  460. }
  461. void SetGFDMode(char *v1)
  462. {
  463. int mode = atoi(v1);
  464. pSysConfig->AlwaysGfdFlag = mode;
  465. }
  466. void GetPsuTemp()
  467. {
  468. for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
  469. for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
  470. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  471. }
  472. }
  473. }
  474. void GetAcInputVol()
  475. {
  476. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  477. pSysInfo->InputVoltageR,
  478. pSysInfo->InputVoltageS,
  479. pSysInfo->InputVoltageT);
  480. }
  481. void GetPsuInformation(char *v1, char *v2, char *v3)
  482. {
  483. printf("**********************AC Contact needed*************************\n");
  484. if (strcmp(v1, "count") == 0) {
  485. for (int i = 0; i < 4; i++) {
  486. printf("Group Index = %d, Module Count = %d \n",
  487. i,
  488. ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  489. }
  490. } else if (strcmp(v1, "ver") == 0) {
  491. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
  492. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  493. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion,
  494. ShmPsuData->PsuVersion[i].FwSecondVersion);
  495. }
  496. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  497. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
  498. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  499. i,
  500. j,
  501. ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  502. }
  503. }
  504. } else if (strcmp(v1, "cap") == 0) {
  505. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  506. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  507. i,
  508. ShmPsuData->PsuGroup[i].GroupAvailableCurrent,
  509. ShmPsuData->PsuGroup[i].GroupAvailablePower);
  510. }
  511. } else if (strcmp(v1, "input") == 0) {
  512. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  513. for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
  514. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  515. i,
  516. count,
  517. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  518. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  519. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  520. }
  521. }
  522. } else if (strcmp(v1, "output") == 0) {
  523. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  524. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  525. i,
  526. ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage,
  527. ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  528. }
  529. for (int i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  530. //if (!FindChargingInfoData(i, &_chargingData[0])) {
  531. // printf ("FindChargingInfoData error\n");
  532. // continue;
  533. //}
  534. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  535. printf("Form RB : Group Index = %d, OutputV = %f \n",
  536. i,
  537. pDcChargingInfo->FireChargingVoltage);
  538. }
  539. } else if (strcmp(v1, "test") == 0) {
  540. int mode = atoi(v2);
  541. if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
  542. ShmPsuData->Work_Step = mode;
  543. }
  544. } else if (strcmp(v1, "out") == 0) {
  545. float vol = atof(v2);
  546. float cur = atof(v3);
  547. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  548. //if (!FindChargingInfoData(0, &_chargingData[0])) {
  549. // printf ("FindChargingInfoData error\n");
  550. // return;
  551. //}
  552. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(0);
  553. pDcChargingInfo->EvBatterytargetVoltage = vol;
  554. pDcChargingInfo->EvBatterytargetCurrent = cur;
  555. }
  556. }
  557. printf("*************************************************\n");
  558. }
  559. void GetConnectorCapInfo(char *v1)
  560. {
  561. int _GunIndex = atoi(v1);
  562. //if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
  563. // printf ("FindChargingInfoData error\n");
  564. // return;
  565. //}
  566. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  567. printf ("Charger Max Current = %d, Max Power = %d \n",
  568. pSysConfig->MaxChargingCurrent * 10,
  569. pSysConfig->MaxChargingPower * 10);
  570. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  571. _GunIndex,
  572. pDcChargingInfo->RealMaxPower,
  573. pDcChargingInfo->RealMaxVoltage,
  574. pDcChargingInfo->RealMaxCurrent);
  575. }
  576. static void setConfirmSelGun(uint8_t selGun)
  577. {
  578. if (selGun == LEFT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
  579. ShmSelectGunInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  580. //printf("confirmSelGun left\r\n");
  581. } else if (selGun == RIGHT_GUN_NUM && ShmSelectGunInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
  582. ShmSelectGunInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  583. //printf("confirmSelGun right\r\n");
  584. }
  585. }
  586. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  587. {
  588. int _GunIndex;
  589. uint8_t gunIndex = 0;
  590. uint8_t stopChg = 0;
  591. uint8_t curGun = 0;
  592. int isContinue = 1;
  593. float _Voltage;
  594. float _Current;
  595. uint8_t PreviousSystemStatus[2] = {0xff};
  596. char *usageMsg = "Usage:\n"
  597. " strchg <index> <voltage> <current> ex: strchg 0 150 2\n"
  598. " chg <voltage> <current> ex: chg 500 100\n"
  599. " c <index> ex: c 0\n"
  600. " help | ? | h\n"
  601. "\r\n";
  602. if (strcmp(v1, "auto") == EQUAL) {
  603. _usingAutoRun = 0x01;
  604. _GunIndex = 0;
  605. _Voltage = 500;
  606. _Current = (pSysConfig->MaxChargingPower * 1000) / _Voltage;
  607. } else {
  608. _usingAutoRun = 0x00;
  609. _GunIndex = atoi(v1);
  610. _Voltage = atof(v2);
  611. _Current = atof(v3);
  612. }
  613. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  614. printf("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  615. pSysConfig->MaxChargingPower,
  616. _Voltage,
  617. _Current);
  618. if (_Voltage > 1000 || _Voltage < 50) {
  619. printf ("Input Voltage over range\n");
  620. return;
  621. }
  622. //kill ev task
  623. system("killall Module_EvComm");
  624. pSysInfo->CurGunSelected = _GunIndex;
  625. while (isContinue) {
  626. curGun = pSysInfo->CurGunSelected;
  627. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
  628. //fix gun 1
  629. switch (pDcChargingInfo->SystemStatus) {
  630. case S_IDLE:
  631. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  632. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  633. #if defined DD360Audi
  634. setConfirmSelGun(curGun);
  635. #endif //defined DD360Audi
  636. strcpy((char *)pSysConfig->UserId, "AutoStartCharging");
  637. pDcChargingInfo->ConnectorPlugIn = 1;
  638. printf ("[UnconditionalCharge - S_IDLE]\n");
  639. pDcChargingInfo->Type = 9;
  640. }
  641. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
  642. pSysInfo->StartToChargingFlag = 0x01;
  643. pDcChargingInfo->SystemStatus = S_PREPARNING;
  644. }
  645. break;
  646. case S_PREPARNING:
  647. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  648. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  649. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  650. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  651. printf ("wait find module\n");
  652. }
  653. //main 會在此階段判斷以下資料跳到下一個 state
  654. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  655. //ShmPsuData->SystemPresentPsuQuantity;
  656. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  657. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  658. //_chargingData[gun_index]->AvailableChargingPower;
  659. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  660. //sleep(10);
  661. //清除 main timeout 機制
  662. pDcChargingInfo->TimeoutFlag = 0;
  663. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  664. pDcChargingInfo->Type = 9;
  665. break;
  666. case S_PREPARING_FOR_EV:
  667. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  668. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  669. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  670. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
  671. }
  672. //清除 main timeout 機制
  673. pDcChargingInfo->TimeoutFlag = 0;
  674. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  675. pDcChargingInfo->Type = 9;
  676. //充電電壓電流
  677. pDcChargingInfo->EvBatterySoc = 50;
  678. pDcChargingInfo->EvBatterytargetVoltage = 500;
  679. pDcChargingInfo->EvBatterytargetCurrent = 2;
  680. pDcChargingInfo->AvailableChargingCurrent = 1000;
  681. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  682. //確定模組己升壓完成
  683. //if(pDcChargingInfo->PresentChargingVoltage <= (3000+500) &&
  684. // pDcChargingInfo->PresentChargingVoltage >= (3000-500) )
  685. {
  686. printf ("Precharge Done = %f \n",
  687. pDcChargingInfo->PresentChargingVoltage);
  688. //EV done
  689. pDcChargingInfo->SystemStatus = S_PREPARING_FOR_EVSE;
  690. }
  691. break;
  692. case S_PREPARING_FOR_EVSE:
  693. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  694. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  695. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  696. }
  697. //printf ("tar vol = %d \n", _Voltage);
  698. //printf ("tar cur = %d \n", _Current);
  699. //清除 main timeout 機制
  700. pDcChargingInfo->TimeoutFlag = 0;
  701. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  702. pDcChargingInfo->Type = 9;
  703. //充電電壓電流
  704. pDcChargingInfo->EvBatterySoc = 50;
  705. pDcChargingInfo->EvBatterytargetVoltage = 500;
  706. pDcChargingInfo->EvBatterytargetCurrent = 2;
  707. pDcChargingInfo->AvailableChargingCurrent = 1000;
  708. //printf ("tar vol_ = %d \n", pDcChargingInfo->EvBatterytargetVoltage);
  709. // printf ("tar cur_ = %d \n", pDcChargingInfo->EvBatterytargetCurrent);
  710. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  711. //確定模組己升壓完成
  712. if (pDcChargingInfo->GroundFaultStatus == 0x01 ||
  713. pDcChargingInfo->GroundFaultStatus == 0x03) {
  714. printf ("First Ground Fault State (%d)\n",
  715. pDcChargingInfo->GroundFaultStatus);
  716. printf ("Wait K1K2 = %f \n", pDcChargingInfo->PresentChargingVoltage);
  717. sleep(5);
  718. //EV done
  719. pDcChargingInfo->SystemStatus = S_CHARGING;
  720. } else if (pDcChargingInfo->GroundFaultStatus > 0x02) {
  721. printf ("First Ground Fault check Fail (%d)\n",
  722. pDcChargingInfo->GroundFaultStatus);
  723. pDcChargingInfo->SystemStatus = S_TERMINATING;
  724. }
  725. break;
  726. case S_CHARGING:
  727. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  728. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  729. if (_usingAutoRun == 0x00) {
  730. //充電電壓電流
  731. pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
  732. pDcChargingInfo->EvBatterytargetCurrent = _Current;
  733. } else {
  734. _curAutoRunCount = 0;
  735. gettimeofday(&_autoTime, NULL);
  736. }
  737. pDcChargingInfo->EvBatterySoc = 50;
  738. pDcChargingInfo->AvailableChargingCurrent = 1000;
  739. printf ("[UnconditionalCharge - S_CHARGING]\n");
  740. }
  741. if (_usingAutoRun == 0x01) {
  742. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 &&
  743. (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  744. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 &&
  745. (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)
  746. ) {
  747. pDcChargingInfo->EvBatterytargetVoltage = _Voltage;
  748. pDcChargingInfo->EvBatterytargetCurrent = _Current;
  749. } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
  750. _curAutoRunCount++;
  751. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
  752. pDcChargingInfo->SystemStatus = S_TERMINATING;
  753. } else {
  754. gettimeofday(&_autoTime, NULL);
  755. }
  756. } else {
  757. pDcChargingInfo->EvBatterytargetVoltage = 0;
  758. pDcChargingInfo->EvBatterytargetCurrent = 0;
  759. }
  760. }
  761. // printf("out : vol = %f, cur = %f \n",
  762. // pDcChargingInfo->EvBatterytargetVoltage,
  763. // pDcChargingInfo->EvBatterytargetCurrent);
  764. //ev task do this
  765. pDcChargingInfo->PresentChargingPower =
  766. ((float)((pDcChargingInfo->PresentChargingVoltage) *
  767. (pDcChargingInfo->PresentChargingCurrent)) / 1000);
  768. if (pDcChargingInfo->GroundFaultStatus == 0x02) {
  769. printf ("Charging Ground Fault check Fail (%d)\n",
  770. pDcChargingInfo->GroundFaultStatus);
  771. pDcChargingInfo->SystemStatus = S_TERMINATING;
  772. }
  773. break;
  774. case S_TERMINATING:
  775. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  776. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  777. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  778. //無阻塞偵測 keybaord 結束
  779. system(STTY_DEF TTY_PATH);
  780. }
  781. pDcChargingInfo->SystemStatus = S_COMPLETE;
  782. break;
  783. case S_COMPLETE:
  784. if (PreviousSystemStatus[curGun] != pDcChargingInfo->SystemStatus) {
  785. PreviousSystemStatus[curGun] = pDcChargingInfo->SystemStatus;
  786. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  787. }
  788. PreviousSystemStatus[curGun] = 0xFF;
  789. stopChg = 0;
  790. for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
  791. if (PreviousSystemStatus[gunIndex] == 0xFF) {
  792. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
  793. pDcChargingInfo->SystemStatus = S_IDLE;
  794. } else {
  795. pSysInfo->CurGunSelected = gunIndex;
  796. }
  797. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
  798. if (pDcChargingInfo->SystemStatus == S_IDLE) {
  799. stopChg++;
  800. }
  801. }
  802. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(curGun);
  803. pDcChargingInfo->PresentChargingPower = 0;
  804. if (stopChg == pSysConfig->TotalConnectorCount) {
  805. system("/root/Module_EvComm &");
  806. sleep(3);
  807. for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
  808. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  809. pDcChargingInfo->SystemStatus = S_IDLE;
  810. }
  811. return;
  812. }
  813. break;
  814. }
  815. if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
  816. continue;
  817. }
  818. if (strcmp(newString[0], "strchg") == 0) {
  819. if (strcmp(newString[1], "-1") == 0 ||
  820. strcmp(newString[1], "") == 0 ||
  821. strcmp(newString[2], "-1") == 0 ||
  822. strcmp(newString[2], "") == 0
  823. ) {
  824. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  825. continue;
  826. }
  827. if (atoi(newString[1]) == pSysInfo->CurGunSelected) {
  828. continue;
  829. }
  830. _GunIndex = atoi((char *)newString[1]);
  831. _Voltage = atof((char *)newString[2]);
  832. _Current = atof((char *)newString[3]);
  833. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  834. pSysConfig->MaxChargingPower,
  835. _Voltage,
  836. _Current);
  837. if (_Voltage > 1000 || _Voltage < 50) {
  838. _Voltage = 200;
  839. printf ("Input Voltage over range\n");
  840. continue;
  841. }
  842. pSysInfo->CurGunSelected = _GunIndex;
  843. strcpy((char *)pSysConfig->UserId, "");
  844. } else if (strcmp(newString[0], "chg") == 0) {
  845. if (strcmp(newString[1], "-1") == 0) {
  846. continue;
  847. }
  848. if (strcmp(newString[2], "-1") == 0 ||
  849. strcmp(newString[2], "") == 0) {
  850. continue;
  851. }
  852. if (strcmp(newString[3], "-1") == 0 ||
  853. strcmp(newString[3], "") == 0) {
  854. continue;
  855. }
  856. _GunIndex = atoi((char *)newString[1]);
  857. float _vol = atof(newString[2]);
  858. float _cur = atof(newString[3]);
  859. if (_cur <= 0 || _cur <= 0) {
  860. continue;
  861. }
  862. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  863. printf("reset vol = %f, cur = %f \n", _vol, _cur);
  864. pDcChargingInfo->EvBatterytargetVoltage = _vol;
  865. pDcChargingInfo->EvBatterytargetCurrent = _cur;
  866. } else if (strcmp(newString[0], "c") == 0) {
  867. if (strcmp(newString[1], "-1") == 0 ||
  868. strcmp(newString[1], "") == 0) {
  869. printf("argc 1 is error parameter\r\n");
  870. continue;
  871. }
  872. if (atoi((char *)newString[1]) != -1) {
  873. pSysInfo->CurGunSelected = atoi((char *)newString[1]);
  874. }
  875. printf("stop \n\r");
  876. pSysInfo->StartToChargingFlag = 0x00;
  877. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData( pSysInfo->CurGunSelected);
  878. pDcChargingInfo->SystemStatus = S_TERMINATING;
  879. } else if (helpCmd() == YES) {
  880. printf("%s\n", usageMsg);
  881. }
  882. usleep(100000);
  883. }
  884. }
  885. int printTimeMsg(const char *fmt, ...)
  886. {
  887. char Buf[4096 + 256] = {0};
  888. char buffer[4096] = {0};
  889. int rc = -1;
  890. va_list args;
  891. struct timeb SeqEndTime;
  892. struct tm *tm;
  893. struct SysConfigData *pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  894. va_start(args, fmt);
  895. rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
  896. va_end(args);
  897. ftime(&SeqEndTime);
  898. SeqEndTime.time = time(NULL);
  899. tm = localtime(&SeqEndTime.time);
  900. sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
  901. tm->tm_hour,
  902. tm->tm_min,
  903. tm->tm_sec,
  904. SeqEndTime.millitm,
  905. buffer);
  906. printf("%s", Buf);
  907. return rc;
  908. }
  909. static void resdGunAndChillerTemp(void)
  910. {
  911. int isContinue = 1;
  912. uint8_t i = 0;
  913. uint32_t sleepTime = 500000;
  914. uint32_t loopTime = 1000;
  915. struct timeb showTime;
  916. struct timeb nowTime;
  917. char *usageMsg = "Usage:\n"
  918. " t <index>: loop time, ex: t 1\n"
  919. " exit | c | C: exit test\n"
  920. " h | help | ?: show usage message\n"
  921. "\r\n";
  922. ftime(&showTime);
  923. while (isContinue) {
  924. ftime(&nowTime);
  925. if (DiffTimeb(showTime, nowTime) > loopTime ||
  926. DiffTimeb(showTime, nowTime) < 0) {
  927. for (i = 0; i < pSysConfig->TotalConnectorCount; i++) {
  928. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
  929. printTimeMsg("get gun %d temp = %3d, chiller = %3d, ConnTemp = %3d, %3d,SysTemp = %3d, %3d, %3d, %3d\r\n",
  930. i,
  931. pDcChargingInfo->ConnectorTemp,
  932. pDcChargingInfo->ChillerTemp,
  933. ShmDcCommonData->ConnectorTemp[i][0],
  934. ShmDcCommonData->ConnectorTemp[i][1],
  935. ShmDcCommonData->SystemTemp[0],
  936. ShmDcCommonData->SystemTemp[1],
  937. ShmDcCommonData->SystemTemp[2],
  938. ShmDcCommonData->SystemTemp[3]);
  939. }//for
  940. ftime(&showTime);
  941. }
  942. if (readCmdKey(CMD_KEY_DONT_WAIT) == NO) {
  943. usleep(sleepTime);
  944. continue;
  945. }
  946. if (strcmp(newString[0], "t") == 0) {
  947. if (strcmp(newString[1], "-1") == 0 ||
  948. strcmp(newString[1], "") == 0 ||
  949. atoi((char *)newString[1]) > 255
  950. ) {
  951. printf("argc 1 is error parameter\r\n");
  952. continue;
  953. }
  954. loopTime = ((atoi((char *)newString[1])) * 1000);
  955. printf("loopTime = %d\r\n", loopTime);
  956. ftime(&showTime);
  957. continue;
  958. } else if (exitCmd() == YES) {
  959. return;
  960. } else if (helpCmd() == YES) {
  961. printf ("%s\n", usageMsg);
  962. }
  963. usleep(sleepTime);
  964. }//while
  965. }
  966. static void writeGunAndChillerTemp(void)
  967. {
  968. uint8_t _GunIndex = 0;
  969. int isContinue = 1;
  970. uint32_t sleepTime = 500000;
  971. char *usageMsg = "Usage:\n"
  972. " conn <index> <temp>, ex: conn 0 150\n"
  973. " chiller <index> <temp>, ex: chiller 0 150\n"
  974. " tempR\n"
  975. " exit | c | C\n"
  976. " help | ? | h\n"
  977. "\r\n";
  978. ShmDcCommonData->TestTemperature = YES;
  979. while (isContinue) {
  980. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  981. sleep(sleepTime);
  982. continue;
  983. }
  984. if (helpCmd() == YES) {
  985. printf ("%s\n", usageMsg);
  986. continue;
  987. } else if (exitCmd() == YES) {
  988. ShmDcCommonData->TestTemperature = NO;
  989. sleep(1);
  990. return;
  991. } else if (strcmp(newString[0], "tempR") == 0) {
  992. resdGunAndChillerTemp();
  993. }
  994. if ((strcmp(newString[0], "chiller") != 0) &&
  995. (strcmp(newString[1], "-1") == 0 ||
  996. strcmp(newString[1], "") == 0)
  997. ) {
  998. printf("argc 1 is error parameter\r\n");
  999. continue;
  1000. }
  1001. if (atoi(newString[2]) > 255 ||
  1002. atoi(newString[2]) == -1) {
  1003. printf("temperature value overflow\r\n");
  1004. continue;
  1005. }
  1006. _GunIndex = atoi((char *)newString[1]);
  1007. if (_GunIndex >= pSysConfig->TotalConnectorCount) {
  1008. printf("gun index over total connector\r\n");
  1009. continue;
  1010. }
  1011. if (strcmp(newString[0], "chiller") == 0) {//修改水冷機溫度值
  1012. if (_GunIndex >= 1) {
  1013. _GunIndex = 0; //只會有一個水冷機
  1014. }
  1015. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  1016. pDcChargingInfo->ChillerTemp = atoi(newString[2]);
  1017. printf("set %d chiller temperature = %d\r\n",
  1018. _GunIndex,
  1019. pDcChargingInfo->ChillerTemp);
  1020. } else if (strcmp(newString[0], "conn") == 0) {//修改槍頭溫度值
  1021. pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  1022. pDcChargingInfo->ConnectorTemp = atoi(newString[2]);
  1023. printf("set %d connector temp = %d\r\n",
  1024. _GunIndex,
  1025. pDcChargingInfo->ConnectorTemp);
  1026. }
  1027. usleep(sleepTime);
  1028. }//while
  1029. }
  1030. int main(void)
  1031. {
  1032. uint8_t _GunIndex = 0;
  1033. int isContinue = 1;
  1034. char *usageMsg = "Usage:\n"
  1035. " state <index> : get gun state\n"
  1036. " card : scanning card (x)\n"
  1037. " gun <index> : get gun plugit state\n"
  1038. " lock <index> : get gun locked state\n"
  1039. " sysid : test system ID\n"
  1040. " self : self test state (x)\n"
  1041. " version | v | -v : version of board (407 or relay or other)\n"
  1042. " update : update firmware\n"
  1043. " ac : get ac relay state (x) \n"
  1044. " cable <index> <state> : set ground fault state\n"
  1045. " pow <index> <power> : set power value\n"
  1046. " model : get system information\n"
  1047. " temp : get PSU temperature\n"
  1048. " fan <speed> : set fan board speed\n"
  1049. " strchg <auto> : auto test charging\n"
  1050. " strchg <index> <voltage <current> : select gun test charging\n"
  1051. " tempW : write connector header and Chiller temperature\r\n"
  1052. " tempR : print connector header and chiller temperature\r\n"
  1053. " btnl : press left button\n"
  1054. " btnr : press right button\n"
  1055. "\r\n";
  1056. if (CreateAllCsuShareMemory() == FAIL) {
  1057. printf("create share memory error\r\n");
  1058. return FAIL;
  1059. }
  1060. MappingGunChargingInfo("ReadCmdline Task");
  1061. pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
  1062. pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
  1063. pSysWarning = (struct WARNING_CODE_INFO *)GetShmSysWarningInfo();
  1064. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  1065. ShmCHAdeMOData = (struct CHAdeMOData *)GetShmCHAdeMOData();
  1066. ShmGBTData = (struct GBTData *)GetShmGBTData();
  1067. ShmCcsData = (struct CcsData *)GetShmCcsData();
  1068. ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
  1069. ShmFanModuleData = (struct FanModuleData *)GetShmFanModuleData();
  1070. ShmRelayModuleData = (struct RelayModuleData *)GetShmRelayModuleData();
  1071. ShmLedModuleData = (struct LedModuleData *)GetShmLedModuleData();
  1072. ShmPsuData = (struct PsuData *)GetShmPsuData();
  1073. ShmOCPP16Data = (struct OCPP16Data *)GetShmOCPP16Data();
  1074. ShmSelectGunInfo = (SelectGunInfo *)GetShmSelectGunInfo();
  1075. ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
  1076. // for (_GunIndex = 0; _GunIndex < pSysConfig->TotalConnectorCount; _GunIndex++) {
  1077. // pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(_GunIndex);
  1078. // pDcChargingInfo->SystemStatus = S_IDLE;
  1079. // }
  1080. while (isContinue) {
  1081. if (readCmdKey(CMD_KEY_WAIT) == NO) {
  1082. continue;
  1083. }
  1084. if (strcmp(newString[0], "state") == 0) {
  1085. if (strcmp(newString[1], "-1") == 0 ||
  1086. strcmp(newString[1], "") == 0) {
  1087. continue;
  1088. }
  1089. // 槍狀態
  1090. RunStatusProc(newString[1], newString[2]);
  1091. } else if (strcmp(newString[0], "card") == 0) {
  1092. // 刷卡狀態
  1093. RunCardProc(newString[1], newString[2]);
  1094. } else if (strcmp(newString[0], "gun") == 0) {
  1095. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1096. continue;
  1097. }
  1098. // 插槍狀態
  1099. RunGunPlugitProc(newString[1], newString[2]);
  1100. } else if (strcmp(newString[0], "lock") == 0) {
  1101. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1102. continue;
  1103. }
  1104. // 插槍狀態
  1105. GetGunLockStatusProc(newString[1], newString[2]);
  1106. } else if (strcmp(newString[0], "sysid") == 0) {
  1107. // 測試 sys id
  1108. SetSystemIDProc();
  1109. } else if (strcmp(newString[0], "self") == 0) {
  1110. // CSU 自我檢測狀態
  1111. RunSelfProc(newString[1]);
  1112. } else if (strcmp(newString[0], "version") == 0 ||
  1113. strcmp(newString[0], "v") == 0 ||
  1114. strcmp(newString[0], "-v") == 0) {
  1115. //if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1116. // continue;
  1117. //}
  1118. // 取 FW 版號
  1119. GetFwVerProc();
  1120. } else if (strcmp(newString[0], "update") == 0) {
  1121. // 更新
  1122. FwUpdateFlagProc(newString[1]);
  1123. } else if (strcmp(newString[0], "ac") == 0) {
  1124. // AC contactor 狀態
  1125. CheckAcStatus(newString[1]);
  1126. } else if (strcmp(newString[0], "cable") == 0) {
  1127. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  1128. continue;
  1129. }
  1130. // cable check pass
  1131. SetCableChkStatus(newString[1], newString[2]);
  1132. } else if (strcmp(newString[0], "pow") == 0) {
  1133. if (strcmp(newString[1], "-1") == 0 ||
  1134. strcmp(newString[1], "") == 0) {
  1135. continue;
  1136. }
  1137. // cable check pass
  1138. SetPowerValue(newString[1], newString[2]);
  1139. } else if (strcmp(newString[0], "model") == 0) {
  1140. GetSystemInfo();
  1141. } else if (strcmp(newString[0], "select") == 0) {
  1142. // 取得 / 設定 當前選的槍號
  1143. GetGunSelectedNum(newString[1]);
  1144. } else if (strcmp(newString[0], "change") == 0) {
  1145. // 模擬按鈕改變選槍
  1146. ChangeGunNum();
  1147. } else if (strcmp(newString[0], "fan") == 0) {
  1148. // 設定風扇速度
  1149. SetFanSpeed(newString[1]);
  1150. } else if (strcmp(newString[0], "speed") == 0) {
  1151. // 取得風扇速度
  1152. GetFanSpeed();
  1153. } else if (strcmp(newString[0], "debug") == 0) {
  1154. // 設定 debug mode
  1155. SetDebugMode(newString[1]);
  1156. } else if (strcmp(newString[0], "gfd") == 0) {
  1157. // 設定盲沖使用 GFD 功能
  1158. SetGFDMode(newString[1]);
  1159. } else if (strcmp(newString[0], "temp") == 0) {
  1160. // 取得 PSU 溫度
  1161. GetPsuTemp();
  1162. } else if (strcmp(newString[0], "acin") == 0) {
  1163. // 取得三向輸入電壓
  1164. GetAcInputVol();
  1165. } else if (strcmp(newString[0], "psu") == 0) {
  1166. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1167. if (strcmp(newString[1], "-1") == 0 ||
  1168. strcmp(newString[1], "") == 0) {
  1169. printf ("PSU : Param fail..Please retry again......\n");
  1170. continue;
  1171. }
  1172. // 取得 PSU 資訊
  1173. GetPsuInformation(newString[1], newString[2], newString[3]);
  1174. } else if (strcmp(newString[0], "cap") == 0) {
  1175. GetConnectorCapInfo(newString[1]);
  1176. } else if (strcmp(newString[0], "error") == 0) {
  1177. CreateOneError(newString[1]);
  1178. } else if (strcmp(newString[0], "auth") == 0) {
  1179. GetAuthorizeFlag(newString[1]);
  1180. } else if (strcmp(newString[0], "relay") == 0) {
  1181. GetRelayStatus(newString[1]);
  1182. } else if (strcmp(newString[0], "ccid") == 0) {
  1183. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  1184. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
  1185. printf ("Input ccid fail.\n");
  1186. continue;
  1187. }
  1188. SetChargingInfoCCID(newString[1], newString[2]);
  1189. } else if (strcmp(newString[0], "strchg") == 0) {
  1190. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  1191. if (strcmp(newString[1], "auto") == 0) {
  1192. newString[2][0] = 0;
  1193. newString[3][0] = 0;
  1194. } else if (strcmp(newString[1], "-1") == 0 ||
  1195. strcmp(newString[1], "") == 0 ||
  1196. strcmp(newString[2], "-1") == 0 ||
  1197. strcmp(newString[2], "") == 0) {
  1198. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  1199. continue;
  1200. }
  1201. // 槍狀態
  1202. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  1203. } else if (strcmp(newString[0], "tempW") == 0) { //測試槍頭和水冷機溫度
  1204. writeGunAndChillerTemp();
  1205. } else if (strcmp(newString[0], "tempR") == 0) { //讀取槍頭和水冷機溫度
  1206. resdGunAndChillerTemp();
  1207. } else if (strcmp(newString[0], "btnl") == 0) {
  1208. ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_PRESS;
  1209. sleep(1);
  1210. ShmPrimaryMcuData->InputDet.bits.Button1 = BTN_RELEASE;
  1211. } else if (strcmp(newString[0], "btnr") == 0) {
  1212. ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_PRESS;
  1213. sleep(1);
  1214. ShmPrimaryMcuData->InputDet.bits.Button2 = BTN_RELEASE;
  1215. } else {
  1216. printf("%s\n", usageMsg);
  1217. }
  1218. sleep(1);
  1219. }//while
  1220. return 0;
  1221. }