ReadCmdline.c 65 KB

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