ReadCmdline.c 55 KB

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