123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- #include <sys/time.h>
- #include <sys/timeb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <sys/socket.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/shm.h>
- #include <sys/mman.h>
- #include <linux/wireless.h>
- #include <arpa/inet.h>
- #include <netinet/in.h>
- #include <stdbool.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #include "../Log/log.h"
- #include "../Define/define.h"
- #include "../Config.h"
- #include "../ShareMemory/shmMem.h"
- #include "PrimaryComm.h"
- #include "Module_PrimaryComm.h"
- //------------------------------------------------------------------------------
- //struct SysConfigAndInfo *ShmSysConfigAndInfo;
- //struct StatusCodeData *ShmStatusCodeData;
- static struct SysConfigData *pSysConfig = NULL;
- static struct SysInfoData *pSysInfo = NULL;
- static struct AlarmCodeData *pAlarmCode = NULL;
- static struct FaultCodeData *pFaultCode = NULL;
- static struct PrimaryMcuData *ShmPrimaryMcuData;
- static DcCommonInfo *ShmDcCommonData = NULL;
- const char *priPortName = "/dev/ttyS1";
- uint8_t gun_count; //DS60-120 add
- uint8_t EmgBtn_count = 0;
- uint8_t Door_count = 0;
- uint8_t EmgBtn_flag = 0;
- uint8_t Door_flag = 0;
- //struct ChargingInfoData *ChargingData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
- //------------------------------------------------------------------------------
- /*int StoreLogMsg(const char *fmt, ...)
- {
- char Buf[4096 + 256];
- char buffer[4096];
- va_list args;
- struct timeb SeqEndTime;
- struct tm *tm;
- va_start(args, fmt);
- int rc = vsnprintf(buffer, sizeof(buffer), fmt, args);
- va_end(args);
- memset(Buf, 0, sizeof(Buf));
- ftime(&SeqEndTime);
- SeqEndTime.time = time(NULL);
- tm = localtime(&SeqEndTime.time);
- if (pSysConfig->SwitchDebugFlag == YES) {
- sprintf(Buf, "%02d:%02d:%02d:%03d - %s",
- tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm, buffer);
- printf("%s ", Buf);
- } else {
- sprintf(Buf, "echo \"%04d-%02d-%02d %02d:%02d:%02d:%03d - %s\" >> /Storage/SystemLog/[%04d.%02d]SystemLog",
- tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, SeqEndTime.millitm,
- buffer,
- tm->tm_year + 1900, tm->tm_mon + 1);
- system(Buf);
- }
- return rc;
- }
- */
- #if 0 //non use
- int DiffTimeb(struct timeb ST, struct timeb ET)
- {
- //return milli-second
- unsigned int StartTime, StopTime;
- StartTime = (unsigned int)ST.time;
- StopTime = (unsigned int)ET.time;
- return (StopTime - StartTime) * 1000 + ET.millitm - ST.millitm;
- }
- //=================================
- // Common routine
- //=================================
- char *getTimeString(void)
- {
- char *result = malloc(21);
- time_t timep;
- struct tm *p;
- time(&timep);
- p = gmtime(&timep);
- sprintf(result, "[%04d-%02d-%02d %02d:%02d:%02d]",
- (1900 + p->tm_year),
- (1 + p->tm_mon),
- p->tm_mday,
- p->tm_hour,
- p->tm_hour,
- p->tm_sec);
- return result;
- }
- #endif //0
- //==========================================
- // Init all share memory
- //==========================================
- /*int InitShareMemory()
- {
- int result = PASS;
- int MeterSMId;
- //creat ShmSysConfigAndInfo
- if ((MeterSMId = shmget(ShmSysConfigAndInfoKey, sizeof(struct SysConfigAndInfo), 0777)) < 0) {
- result = FAIL;
- } else if ((ShmSysConfigAndInfo = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- result = FAIL;
- }
- //creat ShmStatusCodeData
- if ((MeterSMId = shmget(ShmStatusCodeKey, sizeof(struct StatusCodeData), 0777)) < 0) {
- result = FAIL;
- } else if ((ShmStatusCodeData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- result = FAIL;
- }
- //creat ShmStatusCodeData
- if ((MeterSMId = shmget(ShmPrimaryMcuKey, sizeof(struct PrimaryMcuData), 0777)) < 0) {
- result = FAIL;
- } else if ((ShmPrimaryMcuData = shmat(MeterSMId, NULL, 0)) == (void *) - 1) {
- result = FAIL;
- }
- return result;
- }
- */
- //================================================
- // Function
- //================================================
- void GetFwAndHwVersion(int fd)
- {
- Ver ver = {0};
- if (Query_FW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS) {
- //log_info("Primary FW Rev = %s ", ver.Version_FW);
- strcpy((char *)ShmPrimaryMcuData->version, ver.Version_FW);
- strcpy((char *) pSysInfo->CsuPrimFwRev, ver.Version_FW);
- }
- //if (Query_HW_Ver(fd, OP_ADDR_IO_EXTEND, &ver) == PASS)
- // ;//log_info("Primary HW Rev = %s ", ver.Version_HW);
- }
- void GetInputGpioStatus(int fd)
- {
- uint8_t dispenserSwTmp = 0;
- Gpio_in gpio_in = {0};
- static uint8_t dispenserSw = 0;
- //log_info("GetInputGpioStatus ");
- if (Query_Gpio_Input(fd, OP_ADDR_IO_EXTEND, &gpio_in) != PASS) {
- return;
- }
- ShmPrimaryMcuData->InputDet.bits.SpdDetec = gpio_in.SPD;
- #ifdef DD360ComBox
- EmgBtn_flag = 0;
- #else
- if (gpio_in.Emergency_Btn && (EmgBtn_flag != gpio_in.Emergency_Btn))
- {
- EmgBtn_count++;
- if (EmgBtn_count > SensorTrigCount) {
- EmgBtn_flag = 1;
- EmgBtn_count = 0; // Avoid Overflow
- }
- } else if (EmgBtn_flag != gpio_in.Emergency_Btn ) {
- EmgBtn_count++;
- if (EmgBtn_count > SensorTrigCount) {
- EmgBtn_flag = 0;
- EmgBtn_count = 0;
- }
- }
- #endif
- ShmPrimaryMcuData->InputDet.bits.EmergencyButton = EmgBtn_flag;
- dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key0);
- dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key1 << 1);
- dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key2 << 2);
- dispenserSwTmp |= (ShmPrimaryMcuData->InputDet.bits.Key3 << 3);
- if (dispenserSwTmp != dispenserSw) {
- dispenserSw = dispenserSwTmp;
- log_info("Dispenser switch number = %d, bit = %d, %d, %d, %d",
- dispenserSw,
- ShmPrimaryMcuData->InputDet.bits.Key3,
- ShmPrimaryMcuData->InputDet.bits.Key2,
- ShmPrimaryMcuData->InputDet.bits.Key1,
- ShmPrimaryMcuData->InputDet.bits.Key0);
- }
- ShmPrimaryMcuData->InputDet.bits.Button1 = gpio_in.Button[0];
- ShmPrimaryMcuData->InputDet.bits.Button2 = gpio_in.Button[1];
- #if defined DD360 || defined DD360Audi || defined DD360ComBox
- if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)
- ) {
- pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = ~gpio_in.AC_Connector;
- pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = ~gpio_in.AC_MainBreaker;
- } else {
- pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning = gpio_in.AC_Connector;
- pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault = gpio_in.AC_MainBreaker;
- }
- #if defined DD360ComBox
- Door_flag = 0;
- #else
- if (Door_flag == gpio_in.Door_Open) {
- Door_count++;
- if (Door_count == 3 ) {
- Door_count = 0;
- Door_flag = gpio_in.Door_Open;
- }
- } else {
- Door_flag = gpio_in.Door_Open;
- Door_count = 0;
- }
- /*
- if (gpio_in.Door_Open == 0 && (Door_flag == gpio_in.Door_Open))
- {
- Door_count++;
- if (Door_count > SensorTrigCount) {
- Door_flag = 1;
- Door_count = 0; // Avoid Overflow
- }
- } else if (gpio_in.Door_Open && Door_flag) {
- Door_count++;
- if (Door_count > SensorTrigCount) {
- Door_flag = 0;
- Door_count = 0;
- }
- }
- */
- #endif
- #if defined DD360ComBox
- ShmPrimaryMcuData->InputDet.bits.DoorOpen = Door_flag;
- #else
- ShmPrimaryMcuData->InputDet.bits.DoorOpen = ~Door_flag;
- #endif
- /*
- log_info("Emergency Button Count = %d , Emergency flag = %d",
- EmgBtn_count,EmgBtn_flag);
- log_info("Door Sensor Count = %d , Door Sensor flag = %d",
- Door_count,Door_flag);
- */
- ShmPrimaryMcuData->InputDet.bits.Key0 = ~gpio_in.Key[0] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.Key1 = ~gpio_in.Key[1] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.Key2 = ~gpio_in.Key[2] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.Key3 = ~gpio_in.Key[3] & 0x01;
- return;
- #endif //defined DD360 || defined DD360Audi || defined DD360ComBox
- static uint8_t _curDeviceStatus[3] = {0};
- static uint8_t _reCheckCount[3] = {0};
- //DS60-120 add
- if (_curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] != gpio_in.AC_Connector) {
- if (_reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] >= 3) {
- _curDeviceStatus[_PRIMARY_CHECK_TAG_AC_CONTACT] = gpio_in.AC_Connector;
- pSysInfo->AcContactorStatus =
- ShmPrimaryMcuData->InputDet.bits.AcContactorDetec =
- gpio_in.AC_Connector;
- } else {
- _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT]++;
- }
- } else {
- _reCheckCount[_PRIMARY_CHECK_TAG_AC_CONTACT] = 0;
- }
- if (_curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] != gpio_in.AC_MainBreaker) {
- if (_reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] >= 3) {
- _curDeviceStatus[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = gpio_in.AC_MainBreaker;
- ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
- } else {
- _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER]++;
- }
- } else {
- _reCheckCount[_PRIMARY_CHECK_TAG_MAIN_BREAKER] = 0;
- }
- //pSysInfo->AcContactorStatus = ShmPrimaryMcuData->InputDet.bits.AcContactorDetec = gpio_in.AC_Connector;
- //ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec = gpio_in.AC_MainBreaker;
- ShmPrimaryMcuData->InputDet.bits.Key0 = gpio_in.Key[0] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.Key1 = gpio_in.Key[1] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.Key2 = gpio_in.Key[2] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.Key3 = gpio_in.Key[3] & 0x01;
- ShmPrimaryMcuData->InputDet.bits.DoorOpen = gpio_in.Door_Open;
- /*printf(" gpio_in.Key[0]~ gpio_in.Key[3]=%d, %d, %d, %d",
- ShmPrimaryMcuData->InputDet.bits.Key0 , ShmPrimaryMcuData->InputDet.bits.Key1,
- ShmPrimaryMcuData->InputDet.bits.Key2,ShmPrimaryMcuData->InputDet.bits.Key3);
- printf("pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning=%d", pAlarmCode->AlarmEvents.bits.CcsLiquidChillerWaterLevelWarning);
- printf("pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault=%d", pFaultCode->FaultEvents.bits.CcsLiquidChillerWaterLevelFault);
- */
- //log_info("left = %d ", ShmPrimaryMcuData->InputDet.bits.Button1);
- //log_info("right = %d ", ShmPrimaryMcuData->InputDet.bits.Button2);
- //log_info("pSysInfo->AcContactorStatus = %d ", pSysInfo->AcContactorStatus);
- if (ShmPrimaryMcuData->InputDet.bits.AcMainBreakerDetec == YES) {
- log_error("AC Mainbreaker occur. ");
- }
- }
- static void checkChillerStatus(Gpio_out *gpio)
- {
- uint8_t gunIndex = 0;
- uint8_t chillerCount = 0;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- static ChillerInfo fChillerInfo[2] = {0}, *pChillerInfo = NULL;
- static ChillerInfo _chiller;
- struct FanModuleData* ShmFanModuleData = (struct FanModuleData*)GetShmFanModuleData();;
- Gpio_out *pGpio = (Gpio_out *)gpio;
- if ((strncmp((char *)&pSysConfig->ModelName[7], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[7], "F", 1) == 0)) {
- chillerCount++;
- ShmDcCommonData->pGunInfo[0].withChiller = TRUE;
- }
- if ((strncmp((char *)&pSysConfig->ModelName[9], "V", 1) == 0) ||
- (strncmp((char *)&pSysConfig->ModelName[9], "F", 1) == 0)) {
- chillerCount++;
- ShmDcCommonData->pGunInfo[1].withChiller = TRUE;
- }
- if (chillerCount == 0) {
- pGpio->AC_Connector = 0x00;
- return;
- }
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++) {
- if (!ShmDcCommonData->pGunInfo[gunIndex].withChiller)
- continue;
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(gunIndex);
- pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
- if((pDcChargingInfo->SystemStatus > S_IDLE && pDcChargingInfo->SystemStatus < S_TERMINATING) ||
- (pDcChargingInfo->SystemStatus >= S_CCS_PRECHARGE_ST0 && pDcChargingInfo->SystemStatus <= S_CCS_PRECHARGE_ST1)) {
- pChillerInfo->ChillerSwitch = YES;
- pChillerInfo->ChillerOnTime = time((time_t *)NULL);
- } else {
- if(pChillerInfo->ChillerSwitch == YES) {
- //10分鐘後停止
- if ((time((time_t *)NULL) - pChillerInfo->ChillerOnTime) >= 600) {
- pChillerInfo->ChillerSwitch = NO;
- }
- } else {
- pChillerInfo->ChillerSwitch = NO;
- }
- }
- }
- uint8_t _chillerNeedOn = NO;
- for (gunIndex = 0; gunIndex < pSysConfig->TotalConnectorCount; gunIndex++)
- {
- pChillerInfo = (ChillerInfo *)&fChillerInfo[gunIndex];
- if(pChillerInfo->ChillerSwitch == YES) {
- _chillerNeedOn = YES;
- }
- }
- /*
- if (ShmDcCommonData->debugflag == YES)
- _chillerNeedOn = ShmDcCommonData->chillerCtrl;
- */
- if(_chiller.ChillerSwitch != _chillerNeedOn) {
- log_info("Chiller Need Turn %s", _chillerNeedOn == YES ? "ON" : "OFF");
- }
- _chiller.ChillerSwitch = _chillerNeedOn;
- pGpio->AC_Connector = _chiller.ChillerSwitch;//Chiller ON/OFF Control, "0: Chiller disable, 1: Chiller enable"
- }
- void SetOutputGpio(int fd, uint8_t outputValue)
- {
- Gpio_out gpio;
- LedConfig *pLedConfig = (LedConfig *)&outputValue;
- static uint8_t flash = NO;
- if (strcmp((char *)pSysInfo->LcmHwRev, " ") == 0x00) {
- if (flash == NO) {
- flash = YES;
- } else {
- flash = NO;
- }
- } else {
- if (flash == NO) {
- flash = YES;
- }
- }
- pLedConfig->LeftButtonLed = flash;
- pLedConfig->RightButtonLed = flash;
- gpio.Button_LED[0] = pLedConfig->LeftButtonLed;
- gpio.Button_LED[1] = pLedConfig->RightButtonLed;
- gpio.System_LED[0] = pLedConfig->GreenLED;
- gpio.System_LED[1] = pLedConfig->YellowLED;
- gpio.System_LED[2] = pLedConfig->RedLED;
- gpio.System_LED[3] = 0x00;
- checkChillerStatus(&gpio);
- gpio.AC_Breaker = 0x00;
- Config_Gpio_Output(fd, OP_ADDR_IO_EXTEND, &gpio);
- }
- void SetRtcData(int fd)
- {
- Rtc rtc = {0};
- struct timeb csuTime;
- struct tm *tmCSU;
- ftime(&csuTime);
- tmCSU = localtime(&csuTime.time);
- //log_info("Time : %04d-%02d-%02d %02d:%02d:%02d ",
- // tmCSU->tm_year + 1900,
- // tmCSU->tm_mon + 1,
- // tmCSU->tm_mday,
- // tmCSU->tm_hour,
- // tmCSU->tm_min,
- // tmCSU->tm_sec);
- rtc.RtcData[0] = '0' + (tmCSU->tm_year + 1900) / 1000 % 10;
- rtc.RtcData[1] = '0' + (tmCSU->tm_year + 1900) / 100 % 10;
- rtc.RtcData[2] = '0' + (tmCSU->tm_year + 1900) / 10 % 10;
- rtc.RtcData[3] = '0' + (tmCSU->tm_year + 1900) / 1 % 10;
- rtc.RtcData[4] = '0' + (tmCSU->tm_mon + 1) / 10 % 10;
- rtc.RtcData[5] = '0' + (tmCSU->tm_mon + 1) / 1 % 10;
- rtc.RtcData[6] = '0' + (tmCSU->tm_mday) / 10 % 10;
- rtc.RtcData[7] = '0' + (tmCSU->tm_mday) / 1 % 10;
- rtc.RtcData[8] = '0' + (tmCSU->tm_hour) / 10 % 10;
- rtc.RtcData[9] = '0' + (tmCSU->tm_hour) / 1 % 10;
- rtc.RtcData[10] = '0' + (tmCSU->tm_min) / 10 % 10;
- rtc.RtcData[11] = '0' + (tmCSU->tm_min) / 1 % 10;
- rtc.RtcData[12] = '0' + (tmCSU->tm_sec) / 10 % 10;
- rtc.RtcData[13] = '0' + (tmCSU->tm_sec) / 1 % 10;
- if (Config_Rtc_Data(fd, OP_ADDR_IO_EXTEND, &rtc) == PASS) {
- //log_info("SetRtc sucessfully. ");
- } else {
- //log_info("SetRtc fail. ");
- }
- }
- void SetModelName(int fd)
- {
- if (Config_Model_Name(fd, OP_ADDR_IO_EXTEND, pSysConfig->ModelName) == PASS) {
- }
- }
- //================================================
- // Main process
- //================================================
- int InitComPort()
- {
- int fd;
- struct termios tios;
- fd = open(priPortName, O_RDWR);
- if (fd <= 0) {
- #ifdef SystemLogMessage
- log_error("open 407 Communication port NG ");
- #endif
- return -1;
- }
- ioctl (fd, TCGETS, &tios);
- tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
- tios.c_lflag = 0;
- tios.c_iflag = 0;
- tios.c_oflag = 0;
- tios.c_cc[VMIN] = 0;
- tios.c_cc[VTIME] = (uint8_t)1;
- tios.c_lflag = 0;
- tcflush(fd, TCIFLUSH);
- ioctl (fd, TCSETS, &tios);
- return fd;
- }
- unsigned long GetTimeoutValue(struct timeval _sour_time)
- {
- struct timeval _end_time;
- gettimeofday(&_end_time, NULL);
- return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
- }
- //int FindChargingInfoData(uint8_t target, struct ChargingInfoData **chargingData)
- //{
- // for (uint8_t index = 0; index < CHAdeMO_QUANTITY; index++) {
- // if (pSysInfo->ChademoChargingData[index].Index == target) {
- // chargingData[target] = &pSysInfo->ChademoChargingData[index];
- // return 1;
- // }
- // }
- //
- // for (uint8_t index = 0; index < CCS_QUANTITY; index++) {
- // if (pSysInfo->CcsChargingData[index].Index == target) {
- // chargingData[target] = &pSysInfo->CcsChargingData[index];
- // return 1;
- // }
- // }
- //
- // for (uint8_t index = 0; index < GB_QUANTITY; index++) {
- // if (pSysInfo->GbChargingData[index].Index == target) {
- // chargingData[target] = &pSysInfo->GbChargingData[index];
- // return 1;
- // }
- // }
- //
- // return 0;
- //}
- //void Initialization() //DS60-120 add
- //{
- // bool isPass = false;
- // while (!isPass) {
- // isPass = true;
- // for (uint8_t _index = 0; _index < gun_count; _index++) {
- // if (!FindChargingInfoData(_index, &ChargingData[0])) {
- // log_error("EvComm (main) : FindChargingInfoData false ");
- // isPass = false;
- // break;
- // }
- // }
- // sleep(1);
- // }
- //}
- static bool IsPrimaryProcessNeedPause(void)
- {
- bool _pause = false;
- static bool isPause = false;
- struct ChargingInfoData *pDcChargingInfo = NULL;
- for (uint8_t i = 0; i < pSysConfig->TotalConnectorCount; i++)
- {
- pDcChargingInfo = (struct ChargingInfoData *)GetDcChargingInfoData(i);
- if(pDcChargingInfo->SystemStatus == S_UPDATE)
- {
- _pause = true;
- }
- }
- if(isPause != _pause)
- {
- log_info("Primary Process Now Is %s ", _pause == true ? "Paused" : "Continued");
- }
- isPause = _pause;
- return _pause;
- }
- int main(void)
- {
- int Uart1Fd = -1;
- //if (InitShareMemory() == FAIL) {
- // log_error("InitShareMemory NG");
- // if (ShmStatusCodeData != NULL) {
- // pAlarmCode->AlarmEvents.bits.FailToCreateShareMemory = 1;
- // }
- // sleep(5);
- // return 0;
- //}
- if (CreateAllCsuShareMemory() == FAIL) {
- log_error("create share memory error");
- return FAIL;
- }
- MappingGunChargingInfo("Primary Task");
- pSysConfig = (struct SysConfigData *)GetShmSysConfigData();
- pSysInfo = (struct SysInfoData *)GetShmSysInfoData();
- pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
- pFaultCode = (struct FaultCodeData *)GetShmFaultCodeData();
- ShmPrimaryMcuData = (struct PrimaryMcuData *)GetShmPrimaryMcuData();
- ShmDcCommonData = (DcCommonInfo *)GetShmDcCommonData();
- Uart1Fd = InitComPort();
- //log_info("407 Port id = %d ", Uart1Fd);
- if (Uart1Fd < 0) {
- log_error("InitComPort (Uart1 : AM3352 - STM32) NG");
- if (pAlarmCode != NULL) {
- pAlarmCode->AlarmEvents.bits.CsuInitFailed = 1;
- }
- sleep(5);
- return 0;
- }
- SetRtcData(Uart1Fd);
- SetModelName(Uart1Fd);
- gun_count = pSysConfig->TotalConnectorCount;
- //Initialization();
- for (;;) {
- // 程序開始之前~ 必須先確定 FW 版本與硬體版本,確認後!!~ 該模組才算是真正的 Initial Comp.
- // 模組更新 FW 後,需重新做
- if(IsPrimaryProcessNeedPause() == true)
- {
- sleep(1);
- continue;
- }
- if (ShmPrimaryMcuData->SelfTest_Comp != PASS) {
- //log_info("(407) Get Fw and Hw Ver. ");
- GetFwAndHwVersion(Uart1Fd);
- sleep(1);
- ShmPrimaryMcuData->SelfTest_Comp = PASS;
- } else {
- SetOutputGpio(Uart1Fd, ShmPrimaryMcuData->OutputDrv.OutputDrvValue[0]);
- GetInputGpioStatus(Uart1Fd);
- }
- usleep(50000);
- }
- return FAIL;
- }
|