ReadCmdline.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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 "./Define/define.h"
  38. #include "Config.h"
  39. #include "./SelectGun/SelectGun.h"
  40. #define DEFAULT_AC_INDEX 2
  41. #define AUTORUN_STEP1_TIME_START 140 // Minutes
  42. #define AUTORUN_STEP1_TIME_END 150
  43. #define AUTORUN_STEP2_TIME_START 210
  44. #define AUTORUN_STEP2_TIME_END 410
  45. #define AUTORUN_END_TIME 480
  46. #define AUTORUN_CYCLE_COUNT 30
  47. #define TTY_PATH "/dev/tty"
  48. #define STTY_US "stty raw -echo -F "
  49. #define STTY_DEF "stty -raw echo -F "
  50. uint8_t _curAutoRunCount = 0;
  51. uint8_t _usingAutoRun = 0;
  52. struct timeval _autoTime;
  53. struct SysConfigAndInfo *ShmSysConfigAndInfo;
  54. struct StatusCodeData *ShmStatusCodeData;
  55. struct PrimaryMcuData *ShmPrimaryMcuData;
  56. struct CHAdeMOData *ShmCHAdeMOData;
  57. struct CcsData *ShmCcsData;
  58. struct GBTData *ShmGBTData;
  59. struct FanModuleData *ShmFanModuleData;
  60. struct RelayModuleData *ShmRelayModuleData;
  61. struct LedModuleData *ShmLedModuleData;
  62. struct PsuData *ShmPsuData;
  63. struct OCPP16Data *ShmOCPP16Data;
  64. static SelectGunInfo *gAudiCustInfo = NULL; //Jerry add
  65. struct ChargingInfoData *_chargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
  66. struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];
  67. char *msg = "state : get gun state (index) \n"
  68. "card : scanning card (x) : \n"
  69. "gun : get gun plugit state (index) \n"
  70. "lock : get gun locked state (index) \n"
  71. "self : self test state (x) \n"
  72. "ver : ver of board (407 or index or rb or fan) \n"
  73. "ac : get ac relay state (x) \n";
  74. bool FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
  75. {
  76. for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
  77. if (ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index].Index == target) {
  78. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.ChademoChargingData[index];
  79. return true;
  80. }
  81. }
  82. for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
  83. if (ShmSysConfigAndInfo->SysInfo.CcsChargingData[index].Index == target) {
  84. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.CcsChargingData[index];
  85. return true;
  86. }
  87. }
  88. for (uint8_t index = 0; index < GB_QUANTITY; index++) {
  89. if (ShmSysConfigAndInfo->SysInfo.GbChargingData[index].Index == target) {
  90. chargingData[target] = &ShmSysConfigAndInfo->SysInfo.GbChargingData[index];
  91. return true;
  92. }
  93. }
  94. return false;
  95. }
  96. bool FindAcChargingInfoData(uint8_t target, struct ChargingInfoData **acChargingData)
  97. {
  98. if (target < AC_QUANTITY) {
  99. acChargingData[target] = &ShmSysConfigAndInfo->SysInfo.AcChargingData[target];
  100. return true;
  101. }
  102. return false;
  103. }
  104. int InitShareMemory()
  105. {
  106. int result = PASS;
  107. int MeterSMId;
  108. //initial ShmSysConfigAndInfo
  109. if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) {
  110. result = FAIL;
  111. } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  112. result = FAIL;
  113. } else
  114. {}
  115. //initial ShmStatusCodeData
  116. if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) {
  117. result = FAIL;
  118. } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  119. result = FAIL;
  120. } else
  121. {}
  122. if (CHAdeMO_QUANTITY > 0) {
  123. if ((MeterSMId = shmget(ShmCHAdeMOCommKey, sizeof(struct CHAdeMOData),
  124. IPC_CREAT | 0777)) < 0) {
  125. result = FAIL;
  126. } else if ((ShmCHAdeMOData = shmat(MeterSMId, NULL, 0))
  127. == (void *) - 1) {
  128. result = FAIL;
  129. } else {
  130. }
  131. }
  132. if (CCS_QUANTITY > 0) {
  133. if ((MeterSMId = shmget(ShmCcsCommKey, sizeof(struct CcsData),
  134. IPC_CREAT | 0777)) < 0) {
  135. result = FAIL;
  136. } else if ((ShmCcsData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  137. result = FAIL;
  138. } else {
  139. }
  140. }
  141. if (GB_QUANTITY > 0) {
  142. if ((MeterSMId = shmget(ShmGBTCommKey, sizeof(struct GBTData),
  143. IPC_CREAT | 0777)) < 0) {
  144. return 0;
  145. } else if ((ShmGBTData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  146. return 0;
  147. }
  148. memset(ShmGBTData, 0, sizeof(struct GBTData));
  149. }
  150. if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), IPC_CREAT | 0777)) < 0) {
  151. result = FAIL;
  152. } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  153. result = FAIL;
  154. }
  155. if ((MeterSMId = shmget(ShmFanBdKey, sizeof(struct FanModuleData), IPC_CREAT | 0777)) < 0) {
  156. result = FAIL;
  157. } else if ((ShmFanModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  158. result = FAIL;
  159. }
  160. if ((MeterSMId = shmget(ShmRelayBdKey, sizeof(struct RelayModuleData), IPC_CREAT | 0777)) < 0) {
  161. result = FAIL;
  162. } else if ((ShmRelayModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  163. result = FAIL;
  164. }
  165. if ((MeterSMId = shmget(ShmLedBdKey, sizeof(struct LedModuleData), 0777)) < 0) {
  166. result = FAIL;
  167. } else if ((ShmLedModuleData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  168. result = FAIL;
  169. }
  170. if ((MeterSMId = shmget(ShmPsuKey, sizeof(struct PsuData), IPC_CREAT | 0777)) < 0) {
  171. result = FAIL;
  172. } else if ((ShmPsuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  173. result = FAIL;
  174. }
  175. //creat ShmOCPP16Data
  176. if ((MeterSMId = shmget(ShmOcppModuleKey, sizeof(struct OCPP16Data), IPC_CREAT | 0777)) < 0) {
  177. return FAIL;
  178. } else if ((ShmOCPP16Data = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  179. return FAIL;
  180. }
  181. if ((MeterSMId = shmget(ShmSelectGunInfoKey, sizeof(SelectGunInfo), IPC_CREAT | 0777)) < 0) {
  182. return FAIL;
  183. } else if ((gAudiCustInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
  184. return FAIL;
  185. }
  186. return result;
  187. }
  188. unsigned long GetTimeoutValue(struct timeval _sour_time)
  189. {
  190. struct timeval _end_time;
  191. gettimeofday(&_end_time, NULL);
  192. return (_end_time.tv_sec - _sour_time.tv_sec);
  193. }
  194. void RunStatusProc(char *v1, char *v2)
  195. {
  196. printf("OrderCharging = %d \n", ShmSysConfigAndInfo->SysInfo.OrderCharging);
  197. printf("WaitForPlugit = %d \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  198. if (strcmp(v1, "ac") == 0) {
  199. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  200. printf("FindChargingInfoData (AC) false \n");
  201. }
  202. printf("AC Status = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  203. return;
  204. }
  205. int _index = atoi(v1);
  206. if (_index <= 1) {
  207. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  208. printf ("FindChargingInfoData error\n");
  209. return;
  210. }
  211. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  212. // get
  213. printf ("index = %x, status = %x (%d)\n", _index, _chargingData[_index]->SystemStatus, _chargingData[_index]->IsAvailable);
  214. printf ("SystemTimeoutFlag = %d, PageIndex = %d\n",
  215. ShmSysConfigAndInfo->SysInfo.SystemTimeoutFlag, ShmSysConfigAndInfo->SysInfo.PageIndex);
  216. } else {
  217. // set
  218. _chargingData[_index]->SystemStatus = atoi(v2);
  219. }
  220. } else {
  221. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  222. printf("FindChargingInfoData (AC) false \n");
  223. }
  224. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  225. // get
  226. printf ("AC Type, status = %x (%d)\n", ac_chargingInfo[0]->SystemStatus, ac_chargingInfo[0]->IsAvailable);
  227. } else {
  228. // set
  229. ac_chargingInfo[0]->SystemStatus = atoi(v2);
  230. }
  231. }
  232. }
  233. void RunCardProc(char *v1, char *v2)
  234. {
  235. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  236. if (ShmSysConfigAndInfo->SysInfo.WaitForPlugit) {
  237. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x00;
  238. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  239. } else {
  240. ShmSysConfigAndInfo->SysInfo.WaitForPlugit = 0x01;
  241. printf ("SysInfo.WaitForPlugit = %x \n", ShmSysConfigAndInfo->SysInfo.WaitForPlugit);
  242. }
  243. } else {
  244. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "");
  245. memcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, v1, strlen(v1));
  246. ShmSysConfigAndInfo->SysConfig.UserId[strlen(v1)] = '\0';
  247. printf("StartUserId = %s \n", ShmSysConfigAndInfo->SysConfig.UserId);
  248. }
  249. }
  250. void RunGunPlugitProc(char *v1, char *v2)
  251. {
  252. if (strcmp(v1, "ac") == 0) {
  253. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  254. printf("FindChargingInfoData (AC) false \n");
  255. }
  256. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  257. // get
  258. printf("ConnectorPlugIn = %d \n", ac_chargingInfo[0]->ConnectorPlugIn);
  259. } else {
  260. // set
  261. ac_chargingInfo[0]->ConnectorPlugIn = atoi(v2);
  262. }
  263. return;
  264. }
  265. int _index = atoi(v1);
  266. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  267. printf("FindChargingInfoData error\n");
  268. return;
  269. }
  270. if (strcmp(v2, "-1") == 0 || strcmp(v2, "") == 0) {
  271. // get
  272. printf("index = %x, plug it = %x\n", _index, _chargingData[_index]->ConnectorPlugIn);
  273. } else {
  274. // set
  275. _chargingData[_index]->ConnectorPlugIn = atoi(v2);
  276. }
  277. }
  278. void GetGunLockStatusProc(char *v1, char *v2)
  279. {
  280. int _index = atoi(v1);
  281. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  282. printf("FindChargingInfoData error\n");
  283. return;
  284. }
  285. if (strcmp(v2, "-1") != 0 && strcmp(v2, "") != 0) {
  286. _chargingData[_index]->GunLocked = atoi(v2);
  287. }
  288. printf("Gun Locked Status = %d \n", _chargingData[_index]->GunLocked);
  289. }
  290. void SetSystemIDProc()
  291. {
  292. char *systemId = "Alston_Test";
  293. memcpy(&ShmSysConfigAndInfo->SysConfig.SystemId, systemId, strlen(systemId));
  294. }
  295. void RunSelfProc()
  296. {
  297. printf("self test status = %x\n", ShmSysConfigAndInfo->SysInfo.SelfTestSeq);
  298. }
  299. void GetFwVerProc(char *v1)
  300. {
  301. if (strcmp(v1, "407") == 0) {
  302. printf("407 FW Version = %s \n", ShmPrimaryMcuData->version);
  303. } else if (strcmp(v1, "0") == 0 || strcmp(v1, "1") == 0) {
  304. int _index = atoi(v1);
  305. if (_index == 0) {
  306. printf("Gun 0 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector1FwRev);
  307. } else if (_index == 1) {
  308. printf("Gun 1 FW Version = %s \n", ShmSysConfigAndInfo->SysInfo.Connector2FwRev);
  309. }
  310. } else if (strcmp(v1, "rb") == 0) {
  311. printf("RB Version = %s \n", ShmSysConfigAndInfo->SysInfo.RelayModuleFwRev);
  312. } else if (strcmp(v1, "fan") == 0) {
  313. printf("FAN Version = %s \n", ShmSysConfigAndInfo->SysInfo.FanModuleFwRev);
  314. } else if (strcmp(v1, "dc") == 0) {
  315. printf("DC Main Version = %s \n", ShmSysConfigAndInfo->SysInfo.CsuRootFsFwRev);
  316. } else if (strcmp(v1, "led") == 0) {
  317. printf("LED Version = %s \n", ShmSysConfigAndInfo->SysInfo.LedModuleFwRev);
  318. } else if (strcmp(v1, "ac") == 0) {
  319. if (!FindAcChargingInfoData(0, &ac_chargingInfo[0])) {
  320. printf("FindChargingInfoData (AC) false \n");
  321. }
  322. printf("AC Version = %s \n", ac_chargingInfo[0]->version);
  323. }
  324. }
  325. void CreateOneError(char *v1)
  326. {
  327. int value = atoi(v1);
  328. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.SystemL1InputOVP = value;
  329. ShmSysConfigAndInfo->SysConfig.BillingData.isBilling = value;
  330. }
  331. void GetAuthorizeFlag(char *v1)
  332. {
  333. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  334. printf("AuthorizeFlag = %d \n", ShmSysConfigAndInfo->SysInfo.AuthorizeFlag);
  335. } else {
  336. ShmSysConfigAndInfo->SysInfo.AuthorizeFlag = atoi(v1);
  337. }
  338. }
  339. void GetRelayStatus(char *v1)
  340. {
  341. int _index = atoi(v1);
  342. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  343. printf("FindChargingInfoData error\n");
  344. return;
  345. }
  346. printf("RelayK1K2Status = %d \n", _chargingData[_index]->RelayK1K2Status);
  347. printf("RelayKPK2Status = %d \n", _chargingData[_index]->RelayKPK2Status);
  348. }
  349. void FwUpdateFlagProc()
  350. {
  351. ShmSysConfigAndInfo->SysInfo.FirmwareUpdate = 0x01;
  352. }
  353. void CheckAcStatus(char *v1)
  354. {
  355. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  356. printf("AC Status = %d \n", ShmSysConfigAndInfo->SysInfo.AcContactorStatus);
  357. }
  358. }
  359. void SetCableChkStatus(char *v1, char *v2)
  360. {
  361. int _index = atoi(v1);
  362. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  363. printf ("FindChargingInfoData error\n");
  364. return;
  365. }
  366. _chargingData[_index]->GroundFaultStatus = atoi(v2);
  367. }
  368. void SetChargingInfoCCID(char *v1, char *v2)
  369. {
  370. int _index = atoi(v1);
  371. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  372. printf ("FindChargingInfoData error\n");
  373. return;
  374. }
  375. memcpy(_chargingData[_index]->EVCCID, v2, 8);
  376. _chargingData[_index]->EVCCID[8] = '\0';
  377. }
  378. void SetPowerValue(char *v1, char *v2)
  379. {
  380. int _index = atoi(v1);
  381. float _Current = atof(v2);
  382. // 盲沖的時候才允許使用~
  383. if (_chargingData[_index]->Type != 9) {
  384. return;
  385. }
  386. if (!FindChargingInfoData(_index, &_chargingData[0])) {
  387. printf ("FindChargingInfoData error\n");
  388. return;
  389. }
  390. _chargingData[_index]->EvBatterytargetCurrent = _Current;
  391. }
  392. void GetSystemInfo()
  393. {
  394. printf ("ModelName = %s \n", ShmSysConfigAndInfo->SysConfig.ModelName);
  395. printf ("SerialNumber = %s \n", ShmSysConfigAndInfo->SysConfig.SerialNumber);
  396. printf ("InternetConn = %d \n", ShmSysConfigAndInfo->SysInfo.InternetConn);
  397. printf ("MaxChargingPower = %d, MaxChargingCurrent = %d \n",
  398. ShmSysConfigAndInfo->SysConfig.MaxChargingPower,
  399. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent);
  400. }
  401. void ChangeGunNum()
  402. {
  403. if (ShmSysConfigAndInfo->SysInfo.CurGunSelected + 1 < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount) {
  404. ShmSysConfigAndInfo->SysInfo.CurGunSelected += 1;
  405. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  406. } else if (ShmSysConfigAndInfo->SysConfig.AcConnectorCount > 0 &&
  407. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc == NO_DEFINE) {
  408. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  409. } else {
  410. ShmSysConfigAndInfo->SysInfo.CurGunSelected = 0;
  411. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  412. }
  413. }
  414. void GetGunSelectedNum(char *v1)
  415. {
  416. if (strcmp(v1, "-1") == 0 || strcmp(v1, "") == 0) {
  417. if (AC_QUANTITY > 0 &&
  418. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc != NO_DEFINE) {
  419. printf("connector select changed = AC \n");
  420. } else {
  421. printf("connector selected = %d \n", ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  422. }
  423. } else {
  424. int _index = atoi(v1);
  425. if (_index <= 1) {
  426. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _index;
  427. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = NO_DEFINE;
  428. printf("connector select changed = %d \n", _index);
  429. } else if (AC_QUANTITY > 0) {
  430. ShmSysConfigAndInfo->SysInfo.CurGunSelectedByAc = DEFAULT_AC_INDEX;
  431. printf("connector select changed = AC \n");
  432. }
  433. }
  434. }
  435. void SetFanSpeed(char *v1)
  436. {
  437. int speed = atoi(v1);
  438. ShmFanModuleData->TestFanSpeed = speed;
  439. }
  440. void GetFanSpeed()
  441. {
  442. printf("ShmFanModuleData->PresentFan1Speed = %d \n", ShmFanModuleData->PresentFan1Speed);
  443. printf("ShmFanModuleData->PresentFan2Speed = %d \n", ShmFanModuleData->PresentFan2Speed);
  444. printf("ShmFanModuleData->PresentFan3Speed = %d \n", ShmFanModuleData->PresentFan3Speed);
  445. printf("ShmFanModuleData->PresentFan4Speed = %d \n", ShmFanModuleData->PresentFan4Speed);
  446. }
  447. void SetDebugMode(char *v1)
  448. {
  449. int mode = atoi(v1);
  450. ShmSysConfigAndInfo->SysConfig.SwitchDebugFlag = mode;
  451. }
  452. void SetGFDMode(char *v1)
  453. {
  454. int mode = atoi(v1);
  455. ShmSysConfigAndInfo->SysConfig.AlwaysGfdFlag = mode;
  456. }
  457. void GetPsuTemp()
  458. {
  459. for (uint8_t index = 0; index < ShmPsuData->GroupCount; index++) {
  460. for (uint8_t count = 0; count < ShmPsuData->PsuGroup[index].GroupPresentPsuQuantity; count++) {
  461. printf("PSU Temp = %d \n", ShmPsuData->PsuGroup[index].PsuModule[count].ExletTemp);
  462. }
  463. }
  464. }
  465. void GetAcInputVol()
  466. {
  467. printf("L1N_L12 = %f, L2N_L23 = %f, L3N_L31 = %f \n",
  468. ShmSysConfigAndInfo->SysInfo.InputVoltageR,
  469. ShmSysConfigAndInfo->SysInfo.InputVoltageS,
  470. ShmSysConfigAndInfo->SysInfo.InputVoltageT);
  471. }
  472. void GetPsuInformation(char *v1, char *v2, char *v3)
  473. {
  474. printf("**********************AC Contact needed*************************\n");
  475. if (strcmp(v1, "count") == 0) {
  476. for (int i = 0; i < 4; i++) {
  477. printf("Group Index = %d, Module Count = %d \n", i, ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity);
  478. }
  479. } else if (strcmp(v1, "ver") == 0) {
  480. for (int i = 0; i < ShmPsuData->SystemPresentPsuQuantity; i++) {
  481. printf("Psu Index = %d, PriVersion = %s, SecVersion = %s \n",
  482. i, ShmPsuData->PsuVersion[i].FwPrimaryVersion, ShmPsuData->PsuVersion[i].FwSecondVersion);
  483. }
  484. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  485. for (int j = 0; j < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; j++) {
  486. printf("Group Index = %d, Psu Index = %d, Version = %s \n",
  487. i, j, ShmPsuData->PsuGroup[i].PsuModule[j].FwVersion);
  488. }
  489. }
  490. } else if (strcmp(v1, "cap") == 0) {
  491. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  492. printf("Group Index = %d, MaxCur = %d, Power = %d \n",
  493. i, ShmPsuData->PsuGroup[i].GroupAvailableCurrent, ShmPsuData->PsuGroup[i].GroupAvailablePower);
  494. }
  495. } else if (strcmp(v1, "input") == 0) {
  496. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  497. for (uint8_t count = 0; count < ShmPsuData->PsuGroup[i].GroupPresentPsuQuantity; count++) {
  498. printf("gp = %d, Index = %d, volR = %d, volS = %d, volT = %d \n",
  499. i, count,
  500. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL1,
  501. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL2,
  502. ShmPsuData->PsuGroup[i].PsuModule[count].InputVoltageL3);
  503. }
  504. }
  505. } else if (strcmp(v1, "output") == 0) {
  506. for (int i = 0; i < ShmPsuData->GroupCount; i++) {
  507. printf("Group Index = %d, OutputV = %d, OutputC = %d \n",
  508. i, ShmPsuData->PsuGroup[i].GroupPresentOutputVoltage, ShmPsuData->PsuGroup[i].GroupPresentOutputCurrent);
  509. }
  510. for (int i = 0; i < ShmSysConfigAndInfo->SysConfig.TotalConnectorCount; i++) {
  511. if (!FindChargingInfoData(i, &_chargingData[0])) {
  512. printf ("FindChargingInfoData error\n");
  513. continue;
  514. }
  515. printf("Form RB : Group Index = %d, OutputV = %f \n",
  516. i, _chargingData[i]->FireChargingVoltage);
  517. }
  518. } else if (strcmp(v1, "test") == 0) {
  519. int mode = atoi(v2);
  520. if (mode >= _TEST_MODE && mode <= _TEST_MODE) {
  521. ShmPsuData->Work_Step = mode;
  522. }
  523. } else if (strcmp(v1, "out") == 0) {
  524. float vol = atof(v2);
  525. float cur = atof(v3);
  526. if (ShmPsuData->Work_Step >= _TEST_MODE && ShmPsuData->Work_Step <= _TEST_MODE) {
  527. if (!FindChargingInfoData(0, &_chargingData[0])) {
  528. printf ("FindChargingInfoData error\n");
  529. return;
  530. }
  531. _chargingData[0]->EvBatterytargetVoltage = vol;
  532. _chargingData[0]->EvBatterytargetCurrent = cur;
  533. }
  534. }
  535. printf("*************************************************\n");
  536. }
  537. void GetConnectorCapInfo(char *v1)
  538. {
  539. int _GunIndex = atoi(v1);
  540. if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
  541. printf ("FindChargingInfoData error\n");
  542. return;
  543. }
  544. printf ("Charger Max Current = %d, Max Power = %d \n",
  545. ShmSysConfigAndInfo->SysConfig.MaxChargingCurrent * 10,
  546. ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 10);
  547. printf ("Index = %d, MaxPow = %f, MaxVol = %f, MaxCur = %f\n",
  548. _GunIndex,
  549. _chargingData[_GunIndex]->RealMaxPower,
  550. _chargingData[_GunIndex]->RealMaxVoltage,
  551. _chargingData[_GunIndex]->RealMaxCurrent);
  552. }
  553. static void get_char(char *word)
  554. {
  555. fd_set rfds;
  556. struct timeval tv;
  557. FD_ZERO(&rfds);
  558. FD_SET(0, &rfds);
  559. tv.tv_sec = 0;
  560. tv.tv_usec = 10; //wait input timout time
  561. //if input
  562. if (select(1, &rfds, NULL, NULL, &tv) > 0) {
  563. fgets(word, 128, stdin);
  564. }
  565. }
  566. static void setConfirmSelGun(uint8_t selGun)
  567. {
  568. if (selGun == LEFT_GUN_NUM && gAudiCustInfo->SelGunInfo.LeftGun == SEL_GUN_RELEASE) {
  569. gAudiCustInfo->SelGunInfo.LeftGun = SEL_GUN_CONFIRM;
  570. //printf("confirmSelGun left\r\n");
  571. } else if (selGun == RIGHT_GUN_NUM && gAudiCustInfo->SelGunInfo.RightGun == SEL_GUN_RELEASE) {
  572. gAudiCustInfo->SelGunInfo.RightGun = SEL_GUN_CONFIRM;
  573. //printf("confirmSelGun right\r\n");
  574. }
  575. }
  576. void RunUnconditionalChargeIndex1(char *v1, char *v2, char *v3)
  577. {
  578. int _GunIndex;
  579. float _Voltage;
  580. float _Current;
  581. if (strcmp(v1, "auto") == EQUAL) {
  582. _usingAutoRun = 0x01;
  583. _GunIndex = 0;
  584. _Voltage = 500;
  585. _Current = (ShmSysConfigAndInfo->SysConfig.MaxChargingPower * 1000) / _Voltage;
  586. } else {
  587. _usingAutoRun = 0x00;
  588. _GunIndex = atoi(v1);
  589. _Voltage = atof(v2);
  590. _Current = atof(v3);
  591. }
  592. uint8_t PreviousSystemStatus = 0xff;
  593. if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
  594. printf ("FindChargingInfoData error\n");
  595. return;
  596. }
  597. printf ("Power = %d, ReqVoltage = %f, ReqCurrent = %f\n",
  598. ShmSysConfigAndInfo->SysConfig.MaxChargingPower, _Voltage, _Current);
  599. if (_Voltage > 1000 || _Voltage < 50) {
  600. printf ("Input Voltage over range\n");
  601. return;
  602. }
  603. // if(_Current > 100 || _Current < 2){
  604. //
  605. // printf ("Input Current over range\n");
  606. // return;
  607. // }
  608. //測試期間先跳過自我測試 _STEST_COMPLETE = 0xfe
  609. //ShmSysConfigAndInfo->SysInfo.SelfTestSeq = 0xfe;
  610. //kill ev task
  611. system("killall Module_EvComm");
  612. //_Voltage = (_Voltage * 10);
  613. //_Current = (_Current * 10);
  614. //system(STTY_US TTY_PATH);
  615. while (true) {
  616. //fix gun 1
  617. ShmSysConfigAndInfo->SysInfo.CurGunSelected = _GunIndex;
  618. #if defined DD360Audi
  619. setConfirmSelGun(ShmSysConfigAndInfo->SysInfo.CurGunSelected);
  620. #endif //defined DD360Audi
  621. switch (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  622. case S_IDLE: {
  623. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  624. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  625. strcpy((char *)ShmSysConfigAndInfo->SysConfig.UserId, "AutoStartCharging");
  626. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->ConnectorPlugIn = 1;
  627. printf ("[UnconditionalCharge - S_IDLE]\n");
  628. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  629. }
  630. if (ShmOCPP16Data->SpMsg.bits.AuthorizeConf == 1) {
  631. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x01;
  632. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARNING;
  633. }
  634. }
  635. break;
  636. case S_PREPARNING: {
  637. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  638. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  639. printf ("[UnconditionalCharge - S_PREPARNIN]\n");
  640. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  641. printf ("wait find module\n");
  642. }
  643. //main 會在此階段判斷以下資料跳到下一個 state
  644. //用來得知 AC 是否有搭上 (搭上模組的資訊才會出來) 因為每次 AC_Contactor
  645. //ShmPsuData->SystemPresentPsuQuantity;
  646. //ShmPsuData->PsuGroup[gun_index].GroupPresentPsuQuantity;
  647. //ShmPsuData->PsuGroup[gun_index].GroupAvailablePower;
  648. //_chargingData[gun_index]->AvailableChargingPower;
  649. //等待 AC Relay 搭上且找到模組 (main 在此 statue 其它 task 會去做完)
  650. //sleep(10);
  651. //清除 main timeout 機制
  652. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  653. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  654. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  655. }
  656. break;
  657. case S_PREPARING_FOR_EV: {
  658. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  659. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  660. printf ("[UnconditionalCharge - S_PREPARING_FOR_EV]\n");
  661. printf ("ReqVoltage = %f, ReqCurrent = %f \n", _Voltage * 10, _Current * 10);
  662. }
  663. //清除 main timeout 機制
  664. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  665. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  666. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  667. //充電電壓電流
  668. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  669. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  670. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  671. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  672. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  673. //確定模組己升壓完成
  674. //if(_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage <= (3000+500) &&
  675. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage >= (3000-500) )
  676. {
  677. printf ("Precharge Done = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  678. //EV done
  679. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_PREPARING_FOR_EVSE;
  680. }
  681. }
  682. break;
  683. case S_PREPARING_FOR_EVSE: {
  684. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  685. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  686. printf ("[UnconditionalCharge - S_PREPARING_FOR_EVSE]\n");
  687. }
  688. //printf ("tar vol = %d \n", _Voltage);
  689. //printf ("tar cur = %d \n", _Current);
  690. //清除 main timeout 機制
  691. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->TimeoutFlag = 0;
  692. //不論是什麼 type 的槍都固意設成 Chademo 不跑 Prechage step
  693. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->Type = 9;
  694. //充電電壓電流
  695. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  696. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 500;
  697. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 2;
  698. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  699. //printf ("tar vol_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage);
  700. // printf ("tar cur_ = %d \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  701. //****** 注意~此行為是防止 K1K2 先開導到無法升壓 ( Relay Board 在此 state 還未搭上 K1K2 )
  702. //確定模組己升壓完成
  703. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x01 ||
  704. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x03) {
  705. printf ("First Ground Fault State (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  706. printf ("Wait K1K2 = %f \n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage);
  707. sleep(5);
  708. //EV done
  709. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_CHARGING;
  710. } else if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus > 0x02) {
  711. printf ("First Ground Fault check Fail (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  712. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  713. }
  714. }
  715. break;
  716. case S_CHARGING: {
  717. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  718. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  719. if (_usingAutoRun == 0x00) {
  720. //充電電壓電流
  721. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  722. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  723. } else {
  724. _curAutoRunCount = 0;
  725. gettimeofday(&_autoTime, NULL);
  726. }
  727. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterySoc = 50;
  728. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->AvailableChargingCurrent = 1000;
  729. printf ("[UnconditionalCharge - S_CHARGING]\n");
  730. }
  731. if (_usingAutoRun == 0x01) {
  732. if (((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP1_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP1_TIME_END * 60) ||
  733. ((GetTimeoutValue(_autoTime)) >= AUTORUN_STEP2_TIME_START * 60 && (GetTimeoutValue(_autoTime)) <= AUTORUN_STEP2_TIME_END * 60)) {
  734. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _Voltage;
  735. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _Current;
  736. } else if ((GetTimeoutValue(_autoTime)) >= AUTORUN_END_TIME * 60) {
  737. _curAutoRunCount++;
  738. if (_curAutoRunCount >= AUTORUN_CYCLE_COUNT) {
  739. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  740. } else {
  741. gettimeofday(&_autoTime, NULL);
  742. }
  743. } else {
  744. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = 0;
  745. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = 0;
  746. }
  747. }
  748. // printf("out : vol = %f, cur = %f \n",
  749. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage,
  750. // _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent);
  751. //ev task do this
  752. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower =
  753. ((float)((_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingVoltage) * (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingCurrent)) / 1000);
  754. if (_chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus == 0x02) {
  755. printf ("Charging Ground Fault check Fail (%d)\n", _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->GroundFaultStatus);
  756. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  757. }
  758. }
  759. break;
  760. case S_TERMINATING: {
  761. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  762. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  763. system("/root/Module_EvComm &");
  764. printf ("[UnconditionalCharge - S_TERMINATING]\n");
  765. //無阻塞偵測 keybaord 結束
  766. system(STTY_DEF TTY_PATH);
  767. }
  768. sleep(3);
  769. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_COMPLETE;
  770. return;
  771. }
  772. break;
  773. case S_COMPLETE: {
  774. if (PreviousSystemStatus != _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus) {
  775. PreviousSystemStatus = _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus;
  776. printf ("[UnconditionalCharge - S_COMPLETE]\n");
  777. }
  778. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->PresentChargingPower = 0;
  779. sleep(3);
  780. return;
  781. }
  782. break;
  783. }
  784. char word[128];
  785. char newString[7][10];
  786. int i, j, ctr;
  787. memset(word, 0x00, sizeof(word));
  788. get_char(word);
  789. if (strlen(word) == 0) {
  790. continue;
  791. }
  792. j = 0; ctr = 0;
  793. strcpy(newString[1], "-1");
  794. strcpy(newString[2], "-1");
  795. for (i = 0; i <= (strlen(word)); i++) {
  796. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10) {
  797. newString[ctr][j] = '\0';
  798. ctr++;
  799. j = 0;
  800. } else {
  801. newString[ctr][j] = word[i];
  802. j++;
  803. }
  804. }
  805. if (strcmp(newString[0], "chg") == 0) {
  806. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  807. continue;
  808. }
  809. if (strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
  810. continue;
  811. }
  812. float _vol = atof(newString[1]);
  813. float _cur = atof(newString[2]);
  814. if (_cur <= 0 || _cur <= 0) {
  815. continue;
  816. }
  817. printf("vol = %f, cur = %f \n", _vol, _cur);
  818. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetVoltage = _vol;
  819. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->EvBatterytargetCurrent = _cur;
  820. } else if (strcmp(newString[0], "c") == 0) {
  821. printf("stop \n\r");
  822. ShmSysConfigAndInfo->SysInfo.StartToChargingFlag = 0x00;
  823. _chargingData[ShmSysConfigAndInfo->SysInfo.CurGunSelected]->SystemStatus = S_TERMINATING;
  824. }
  825. usleep(100000);
  826. }
  827. }
  828. int main(void)
  829. {
  830. if (InitShareMemory() == FAIL) {
  831. printf ("InitShareMemory = FAIL \n");
  832. if (ShmStatusCodeData != NULL) {
  833. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.FailToCreateShareMemory = 1;
  834. }
  835. sleep(5);
  836. return 0;
  837. }
  838. for (;;) {
  839. char word[128];
  840. char newString[7][10];
  841. int i, j, ctr;
  842. fgets(word, sizeof(word), stdin);
  843. j = 0; ctr = 0;
  844. strcpy(newString[1], "-1");
  845. strcpy(newString[2], "-1");
  846. for (i = 0; i <= (strlen(word)); i++) {
  847. if (word[i] == ' ' || word[i] == '\0' || word[i] == 10) {
  848. newString[ctr][j] = '\0';
  849. ctr++;
  850. j = 0;
  851. } else {
  852. newString[ctr][j] = word[i];
  853. j++;
  854. }
  855. }
  856. if (strcmp(newString[0], "state") == 0) {
  857. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  858. continue;
  859. }
  860. // 槍狀態
  861. RunStatusProc(newString[1], newString[2]);
  862. } else if (strcmp(newString[0], "card") == 0) {
  863. // 刷卡狀態
  864. RunCardProc(newString[1], newString[2]);
  865. } else if (strcmp(newString[0], "gun") == 0) {
  866. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  867. continue;
  868. }
  869. // 插槍狀態
  870. RunGunPlugitProc(newString[1], newString[2]);
  871. } else if (strcmp(newString[0], "lock") == 0) {
  872. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  873. continue;
  874. }
  875. // 插槍狀態
  876. GetGunLockStatusProc(newString[1], newString[2]);
  877. } else if (strcmp(newString[0], "sysid") == 0) {
  878. // 測試 sys id
  879. SetSystemIDProc();
  880. } else if (strcmp(newString[0], "self") == 0) {
  881. // CSU 自我檢測狀態
  882. RunSelfProc(newString[1]);
  883. } else if (strcmp(newString[0], "ver") == 0) {
  884. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  885. continue;
  886. }
  887. // 取 FW 版號
  888. GetFwVerProc(newString[1]);
  889. } else if (strcmp(newString[0], "update") == 0) {
  890. // 更新
  891. FwUpdateFlagProc(newString[1]);
  892. } else if (strcmp(newString[0], "ac") == 0) {
  893. // AC contactor 狀態
  894. CheckAcStatus(newString[1]);
  895. } else if (strcmp(newString[0], "cable") == 0) {
  896. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  897. continue;
  898. }
  899. // cable check pass
  900. SetCableChkStatus(newString[1], newString[2]);
  901. } else if (strcmp(newString[0], "pow") == 0) {
  902. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  903. continue;
  904. }
  905. // cable check pass
  906. SetPowerValue(newString[1], newString[2]);
  907. } else if (strcmp(newString[0], "model") == 0) {
  908. GetSystemInfo();
  909. } else if (strcmp(newString[0], "select") == 0) {
  910. // 取得 / 設定 當前選的槍號
  911. GetGunSelectedNum(newString[1]);
  912. } else if (strcmp(newString[0], "change") == 0) {
  913. // 模擬按鈕改變選槍
  914. ChangeGunNum();
  915. } else if (strcmp(newString[0], "fan") == 0) {
  916. // 設定風扇速度
  917. SetFanSpeed(newString[1]);
  918. } else if (strcmp(newString[0], "speed") == 0) {
  919. // 取得風扇速度
  920. GetFanSpeed();
  921. } else if (strcmp(newString[0], "debug") == 0) {
  922. // 設定 debug mode
  923. SetDebugMode(newString[1]);
  924. } else if (strcmp(newString[0], "gfd") == 0) {
  925. // 設定盲沖使用 GFD 功能
  926. SetGFDMode(newString[1]);
  927. } else if (strcmp(newString[0], "temp") == 0) {
  928. // 取得 PSU 溫度
  929. GetPsuTemp();
  930. } else if (strcmp(newString[0], "acin") == 0) {
  931. // 取得三向輸入電壓
  932. GetAcInputVol();
  933. } else if (strcmp(newString[0], "psu") == 0) {
  934. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  935. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0) {
  936. printf ("PSU : Param fail..Please retry again......\n");
  937. continue;
  938. }
  939. // 取得 PSU 資訊
  940. GetPsuInformation(newString[1], newString[2], newString[3]);
  941. } else if (strcmp(newString[0], "cap") == 0) {
  942. GetConnectorCapInfo(newString[1]);
  943. } else if (strcmp(newString[0], "error") == 0) {
  944. CreateOneError(newString[1]);
  945. } else if (strcmp(newString[0], "auth") == 0) {
  946. GetAuthorizeFlag(newString[1]);
  947. } else if (strcmp(newString[0], "relay") == 0) {
  948. GetRelayStatus(newString[1]);
  949. } else if (strcmp(newString[0], "ccid") == 0) {
  950. if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  951. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
  952. printf ("Input ccid fail.\n");
  953. continue;
  954. }
  955. SetChargingInfoCCID(newString[1], newString[2]);
  956. } else if (strcmp(newString[0], "strchg") == 0) {
  957. //如果連一個參數都沒有 (此命令不理會) 加上判斷第二參數
  958. if (strcmp(newString[1], "auto") == 0) {
  959. newString[2][0] = 0;
  960. newString[3][0] = 0;
  961. } else if (strcmp(newString[1], "-1") == 0 || strcmp(newString[1], "") == 0 ||
  962. strcmp(newString[2], "-1") == 0 || strcmp(newString[2], "") == 0) {
  963. printf ("Input cmd fail ------ strchg [vol 150-1000] [cru 2-100]\n");
  964. continue;
  965. }
  966. // 槍狀態
  967. RunUnconditionalChargeIndex1(newString[1], newString[2], newString[3]);
  968. } else if (strcmp(newString[0], "tempT") == 0) {
  969. uint8_t _GunIndex = 0;
  970. if (!FindChargingInfoData(_GunIndex, &_chargingData[0])) {
  971. printf ("FindChargingInfoData error\n");
  972. return 0;
  973. }
  974. if (strcmp(newString[1], "0") == 0) {
  975. _chargingData[0]->ConnectorTemp = atoi(newString[2]);
  976. printf("ReadCmdline temp 0 = %d\r\n", _chargingData[0]->ConnectorTemp);
  977. } else if (strcmp(newString[1], "1") == 0) {
  978. _chargingData[1]->ConnectorTemp = atoi(newString[2]);
  979. printf("ReadCmdline temp 1 = %d\r\n", _chargingData[1]->ConnectorTemp);
  980. }
  981. } else {
  982. printf ("%s\n", msg);
  983. }
  984. usleep(100000);
  985. }
  986. return 0;
  987. }