ReadCmdline.c 72 KB

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