ReadCmdline.c 54 KB

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