ReadCmdline.c 52 KB

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