#include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include #include #include #include #include #include #include #include #include "../Config.h" #include "../Log/log.h" #include "../ShareMemory/shmMem.h" #include "Module_InternalComm.h" //------------------------------------------------------------------------------ #define INTERNAL_COM_PORT ("/dev/ttyS5") //------------------------------------------------------------------------------ extern void RelayBoardTask(int uartFD); //extern void LEDBoardTask(int uartFD); //extern void FanBoardTask(int uartFD); extern void AcPlugTask(int uartFD); //------------------------------------------------------------------------------ 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; return (StopTime - StartTime); } uint32_t 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; } static int Init485ComPort(void) { int fd; struct termios tios; fd = open(INTERNAL_COM_PORT, O_RDWR); if (fd <= 0) { log_error("Module_InternalComm. InitComPort NG"); sleep(5); 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)0; // timeout 0.5 second tios.c_lflag = 0; tcflush(fd, TCIFLUSH); ioctl (fd, TCSETS, &tios); return fd; } int main(int argc, char *argv[]) { int fd = 0; int isContinue = 1; struct AlarmCodeData *pAlarmCode = NULL; if (CreateAllCsuShareMemory() == FAIL) { log_error("create share memory error"); return FAIL; } MappingGunChargingInfo("InternalComm Task"); fd = Init485ComPort(); if (fd == FAIL) { pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData(); pAlarmCode->AlarmEvents.bits.CsuInitFailed = YES; log_info("ModuleInternalComTask create port error..."); return FAIL; } RelayBoardTask(fd); usleep(100000); //LEDBoardTask(fd); //usleep(100000); //FanBoardTask(fd); while (isContinue) { if(AC_QUANTITY > 0) { AcPlugTask(fd); } usleep(100000); } return 0; }