Module_PowerSharing.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Module_PowerSharing.h
  3. *
  4. * Created on: 2020/12/07
  5. * Author: foluswen
  6. */
  7. #ifndef MODULE_POWERSHARING_H_
  8. #define MODULE_POWERSHARING_H_
  9. #include <sys/time.h>
  10. #include <sys/timeb.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <sys/types.h>
  14. #include <sys/ioctl.h>
  15. #include <sys/socket.h>
  16. #include <sys/ipc.h>
  17. #include <sys/shm.h>
  18. #include <sys/shm.h>
  19. #include <sys/mman.h>
  20. #include <linux/wireless.h>
  21. #include <arpa/inet.h>
  22. #include <netinet/in.h>
  23. #include <unistd.h>
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <unistd.h>
  28. #include <fcntl.h>
  29. #include <termios.h>
  30. #include <errno.h>
  31. #include <errno.h>
  32. #include <string.h>
  33. #include <time.h>
  34. #include <ctype.h>
  35. #include <ifaddrs.h>
  36. #include <sys/types.h>
  37. #include <sys/socket.h>
  38. #include <netinet/in.h>
  39. #include <netdb.h>
  40. #include <error.h>
  41. #include <signal.h>
  42. #include "define.h"
  43. #include "main.h"
  44. //#define DEBUG
  45. #define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L)
  46. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  47. #define PASS 1
  48. #define FAIL -1
  49. #define ON 1
  50. #define OFF 0
  51. #define YES 1
  52. #define NO 0
  53. #define true 1
  54. #define false 0
  55. #define LISTEN_PORT_TCP 118
  56. #define CONNECTION_LIMIT 5
  57. #define TIMEOUT_SPEC_HEARTBEAT 180
  58. #define TIMEOUT_SPEC_CHECK_CAPACITY 10
  59. #define ShmPowerShargingKey LISTEN_PORT_TCP+8000
  60. enum ROTARY_SWITCH_LIMIT
  61. {
  62. SWITCH_0_DEBUG=0,
  63. SWITCH_1_12A,
  64. SWITCH_2_16A,
  65. SWITCH_3_20A,
  66. SWITCH_4_24A,
  67. SWITCH_5_28A,
  68. SWITCH_6_32A,
  69. SWITCH_7_36A,
  70. SWITCH_8_40A,
  71. SWITCH_9_48A,
  72. SWITCH_A_56A,
  73. SWITCH_B_64A,
  74. SWITCH_C_72A,
  75. SWITCH_D_80A,
  76. SWITCH_E_RESERVE,
  77. SWITCH_F_SLAVE
  78. };
  79. enum SHARING_COMMAND
  80. {
  81. SHARING_CMD_GET_STATUS=0x01,
  82. SHARING_CMD_SET_CAPACITY=0x02,
  83. SHARING_CMD_CONNECTION_FULL=0xfd,
  84. SHARING_CMD_CHKSUM_ERROR=0xfe,
  85. SHARING_CMD_UNKNOWN=0xff
  86. };
  87. struct Message
  88. {
  89. int size;
  90. uint8_t buffer[2048];
  91. };
  92. struct CONNECTION_INFO
  93. {
  94. int socketFd; // Socket file description
  95. uint16_t availableSharingCurrent; // Each connection available sharing current, resolution: 1A
  96. uint16_t presentOutputCurrent; // Each connection preset output current, resolution: 1A
  97. uint8_t acPhase; // Each connection ac power phase
  98. uint16_t SOC; // Each connection preset SOC, resolution: 0.1%
  99. uint16_t remindTime; // Each connection remind charging time, resolution: 1min
  100. time_t lastHeartBeatTime; // Each connection latest get heart beat start time
  101. time_t lastGetStatusTime; // Each connection latest get status start time
  102. time_t lastSetCapacityTime; // Each connection latest set capacity start time
  103. time_t lastCheckCapacityTime; // Each connection latest check capacity start time
  104. uint8_t isSocketConnected:1; // Each connection socket connected flag
  105. uint8_t isGunConnected:1; // Each connection gun connected flag
  106. };
  107. struct POWER_SHARING
  108. {
  109. uint8_t connectedQty;
  110. uint16_t onHandCurrent;
  111. struct CONNECTION_INFO Connection_Info[CONNECTION_LIMIT];
  112. uint8_t hasNewConn:1;
  113. };
  114. #endif /* MODULE_POWERSHARING_H_ */