ReadCmdline.c 53 KB

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