ReadCmdline.c 67 KB

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