ReadCmdline.c 54 KB

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