123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <string.h>
- #include <stdint.h>
- #include <termios.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/timeb.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #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;
- }
|