ReadCmdline.c 57 KB

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