ReadCmdline.c 57 KB

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