ReadCmdline.c 53 KB

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