ReadCmdline.c 52 KB

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