ReadCmdline.c 53 KB

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