Module_InternalComm.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <termios.h>
  6. #include <unistd.h>
  7. #include <fcntl.h>
  8. #include <sys/timeb.h>
  9. #include <sys/ioctl.h>
  10. #include <sys/time.h>
  11. #include "../Config.h"
  12. #include "../Log/log.h"
  13. #include "../ShareMemory/shmMem.h"
  14. #include "Module_InternalComm.h"
  15. //------------------------------------------------------------------------------
  16. #define INTERNAL_COM_PORT ("/dev/ttyS5")
  17. //------------------------------------------------------------------------------
  18. extern void RelayBoardTask(int uartFD);
  19. //extern void LEDBoardTask(int uartFD);
  20. //extern void FanBoardTask(int uartFD);
  21. extern void AcPlugTask(int uartFD);
  22. //------------------------------------------------------------------------------
  23. int DiffTimeb(struct timeb ST, struct timeb ET)
  24. {
  25. //return milli-second
  26. unsigned int StartTime, StopTime;
  27. StartTime = (unsigned int) ST.time;
  28. StopTime = (unsigned int) ET.time;
  29. //return (StopTime-StartTime)*1000+ET.millitm-ST.millitm;
  30. return (StopTime - StartTime);
  31. }
  32. uint32_t GetTimeoutValue(struct timeval _sour_time)
  33. {
  34. struct timeval _end_time;
  35. gettimeofday(&_end_time, NULL);
  36. return 1000000 * (_end_time.tv_sec - _sour_time.tv_sec) + _end_time.tv_usec - _sour_time.tv_usec;
  37. }
  38. static int Init485ComPort(void)
  39. {
  40. int fd;
  41. struct termios tios;
  42. fd = open(INTERNAL_COM_PORT, O_RDWR);
  43. if (fd <= 0) {
  44. log_error("Module_InternalComm. InitComPort NG");
  45. sleep(5);
  46. return -1;
  47. }
  48. ioctl (fd, TCGETS, &tios);
  49. tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
  50. tios.c_lflag = 0;
  51. tios.c_iflag = 0;
  52. tios.c_oflag = 0;
  53. tios.c_cc[VMIN] = 0;
  54. tios.c_cc[VTIME] = (uint8_t)0; // timeout 0.5 second
  55. tios.c_lflag = 0;
  56. tcflush(fd, TCIFLUSH);
  57. ioctl (fd, TCSETS, &tios);
  58. return fd;
  59. }
  60. int main(int argc, char *argv[])
  61. {
  62. int fd = 0;
  63. int isContinue = 1;
  64. struct AlarmCodeData *pAlarmCode = NULL;
  65. if (CreateAllCsuShareMemory() == FAIL) {
  66. log_error("create share memory error");
  67. return FAIL;
  68. }
  69. MappingGunChargingInfo("InternalComm Task");
  70. fd = Init485ComPort();
  71. if (fd == FAIL) {
  72. pAlarmCode = (struct AlarmCodeData *)GetShmAlarmCodeData();
  73. pAlarmCode->AlarmEvents.bits.CsuInitFailed = YES;
  74. log_info("ModuleInternalComTask create port error...");
  75. return FAIL;
  76. }
  77. RelayBoardTask(fd);
  78. usleep(100000);
  79. //LEDBoardTask(fd);
  80. //usleep(100000);
  81. //FanBoardTask(fd);
  82. while (isContinue) {
  83. if(AC_QUANTITY > 0)
  84. {
  85. AcPlugTask(fd);
  86. }
  87. usleep(100000);
  88. }
  89. return 0;
  90. }