Module_PowerSharing.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_UDP 8421
  56. #define LISTEN_PORT_TCP 8422
  57. #define CONNECTION_LIMIT 8
  58. #define ShmPowerShargingKey LISTEN_PORT_TCP
  59. enum ROTARY_SWITCH_LIMIT
  60. {
  61. SWITCH_0_DEBUG=0,
  62. SWITCH_1_12A,
  63. SWITCH_2_16A,
  64. SWITCH_3_20A,
  65. SWITCH_4_24A,
  66. SWITCH_5_28A,
  67. SWITCH_6_32A,
  68. SWITCH_7_36A,
  69. SWITCH_8_40A,
  70. SWITCH_9_48A,
  71. SWITCH_A_56A,
  72. SWITCH_B_64A,
  73. SWITCH_C_72A,
  74. SWITCH_D_80A,
  75. SWITCH_E_RESERVE,
  76. SWITCH_F_SLAVE
  77. };
  78. enum SHARING_COMMAND
  79. {
  80. SHARING_CMD_QUERY_SHARING=0x01,
  81. SHARING_CMD_SYNC_INFO=0x81,
  82. SHARING_CMD_CONNECTION_FULL=0xfd,
  83. SHARING_CMD_CHKSUM_ERROR=0xfe,
  84. SHARING_CMD_UNKNOWN=0xff
  85. };
  86. struct Message
  87. {
  88. int size;
  89. uint8_t buffer[2048];
  90. };
  91. struct CONNECTION_INFO
  92. {
  93. int socketFd;
  94. uint16_t sharingCurrent;
  95. uint16_t actualCurrent;
  96. time_t lastHeartBeatTime;
  97. uint8_t isConnected:1;
  98. uint8_t isCharging:1;
  99. };
  100. struct POWER_SHARING
  101. {
  102. uint8_t connectedQty;
  103. struct CONNECTION_INFO Connection_Info[CONNECTION_LIMIT];
  104. };
  105. #endif /* MODULE_POWERSHARING_H_ */