ReadCmdline.c 53 KB

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