Module_PowerSharing.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. //#define DEBUG
  44. #define DEBUG_INFO(format, args...) StoreLogMsg("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
  45. #define DEBUG_WARN(format, args...) StoreLogMsg("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
  46. #define DEBUG_ERROR(format, args...) StoreLogMsg("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
  47. #define DEBUG_INFO_CLIENT(format, args...) StoreLogMsgClient("[%s:%d][%s][Info] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
  48. #define DEBUG_WARN_CLIENT(format, args...) StoreLogMsgClient("[%s:%d][%s][Warn] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
  49. #define DEBUG_ERROR_CLIENT(format, args...) StoreLogMsgClient("[%s:%d][%s][Error] "format, (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)), __LINE__, __FUNCTION__, ##args)
  50. #define is_error(ptr) ((unsigned long)ptr > (unsigned long)-4000L)
  51. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  52. #define PASS 1
  53. #define FAIL -1
  54. #define ON 1
  55. #define OFF 0
  56. #define YES 1
  57. #define NO 0
  58. #define LISTEN_PORT_TCP 118
  59. #define CONNECTION_LIMIT 5
  60. #define TIMEOUT_SPEC_HEARTBEAT 180
  61. #define INTERVAL_SPEC_CHECK_CAPACITY 5
  62. #define INTERVAL_SPEC_POLLING_CMD 1
  63. #define SHARE_GAP_AC 2
  64. #define SHARE_MIN_AC 6
  65. #define SHARE_GAP_DC 10
  66. #define SHARE_MIN_DC 6
  67. #define ShmPowerShargingKey LISTEN_PORT_TCP+8000
  68. enum ROTARY_SWITCH_LIMIT
  69. {
  70. SWITCH_0_DEBUG=0,
  71. SWITCH_1_12A,
  72. SWITCH_2_16A,
  73. SWITCH_3_20A,
  74. SWITCH_4_24A,
  75. SWITCH_5_28A,
  76. SWITCH_6_32A,
  77. SWITCH_7_36A,
  78. SWITCH_8_40A,
  79. SWITCH_9_48A,
  80. SWITCH_A_56A,
  81. SWITCH_B_64A,
  82. SWITCH_C_72A,
  83. SWITCH_D_80A,
  84. SWITCH_E_RESERVE,
  85. SWITCH_F_SLAVE
  86. };
  87. enum SHARING_COMMAND
  88. {
  89. SHARING_CMD_GET_STATUS=0x01,
  90. SHARING_CMD_SET_CAPACITY=0x02,
  91. SHARING_CMD_CONNECTION_FULL=0xfd,
  92. SHARING_CMD_CHKSUM_ERROR=0xfe,
  93. SHARING_CMD_UNKNOWN=0xff
  94. };
  95. enum POWERSHARING_TIMER_IDX
  96. {
  97. POWERSHARING_TMR_IDX_HEARTBEAT,
  98. POWERSHARING_TMR_IDX_GET_STATUS,
  99. POWERSHARING_TMR_IDX_SET_CAPACITY,
  100. POWERSHARING_TMR_IDX_CNT
  101. };
  102. enum GUN_TYPE
  103. {
  104. GUN_TYPE_UNKNOWN=0,
  105. GUN_TYPE_CHAdeMO,
  106. GUN_TYPE_CCS,
  107. GUN_TYPE_GBT,
  108. GUN_TYPE_DO,
  109. GUN_TYPE_AC
  110. };
  111. enum CONNECTOR_TYPE
  112. {
  113. CONNECTOR_TYPE_AC=0,
  114. CONNECTOR_TYPE_DC
  115. };
  116. struct Message
  117. {
  118. int size;
  119. uint8_t buffer[2048];
  120. };
  121. typedef struct CONNECTOR_INFO
  122. {
  123. uint8_t connectorType;
  124. uint16_t availableSharingCurrent; // Each connector available sharing current, resolution: 1A
  125. uint16_t presentOutputCurrent; // Each connector preset output current, resolution: 1A
  126. uint16_t SOC; // Each connector preset SOC, resolution: 0.1%
  127. uint16_t remindTime; // Each connector remind charging time, resolution: 1min
  128. struct timespec tmrCheckCapacity; // Each connector check capacity timer
  129. uint8_t isGunConnected:1; // Each connection gun connected flag
  130. }Connector_Info;
  131. struct CONNECTION_INFO
  132. {
  133. int socketFd; // Socket file description
  134. int connectorCount; // Each connection connector count
  135. Connector_Info connectorInfo[4]; // Connector info
  136. struct timespec timer[POWERSHARING_TMR_IDX_CNT];
  137. uint8_t isSocketConnected:1; // Each connection socket connected flag
  138. };
  139. struct POWER_SHARING
  140. {
  141. uint8_t connectedConnectionQty;
  142. uint8_t connectedConnectorQty;
  143. int32_t onHandCurrent;
  144. struct CONNECTION_INFO Connection_Info[CONNECTION_LIMIT];
  145. uint8_t isDetectNewConnected:1;
  146. };
  147. #endif /* MODULE_POWERSHARING_H_ */