ReadCmdline.c 51 KB

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