ReadCmdline.c 51 KB

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