ReadCmdline.c 60 KB

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