ReadCmdline.c 73 KB

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