ReadCmdline.c 54 KB

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