UUpwr_PsuCommObj.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * UUpwr_PsuCommObj.h
  3. *
  4. * Created on: 2022年3月30日
  5. * Author: 7564
  6. */
  7. #ifndef UUPWR_PSUCOMMOBJ_H_
  8. #define UUPWR_PSUCOMMOBJ_H_
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdbool.h>
  12. #include <signal.h>
  13. #include <string.h>
  14. #include <fcntl.h>
  15. #include <unistd.h>
  16. #include <sys/socket.h>
  17. #include <sys/ioctl.h>
  18. #include <linux/wireless.h>
  19. #include <linux/can.h>
  20. #include <sys/ipc.h>
  21. #include <sys/shm.h>
  22. #include <sys/time.h>
  23. #include <stdbool.h>
  24. #include <unistd.h>
  25. #include <stdarg.h>
  26. #include <stdio.h> /*標準輸入輸出定義*/
  27. #include <stdlib.h> /*標準函數庫定義*/
  28. #include <unistd.h> /*Unix 標準函數定義*/
  29. #include <fcntl.h> /*檔控制定義*/
  30. #include <termios.h> /*PPSIX 終端控制定義*/
  31. #include <errno.h> /*錯誤號定義*/
  32. #include <errno.h>
  33. #include <string.h>
  34. #include <time.h>
  35. #include <ctype.h>
  36. #include <ifaddrs.h>
  37. #include <math.h>
  38. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  39. #define PSU_PROTOCOL_TYPE 1
  40. #define SYSTEM_CMD 0x3F
  41. #define LIB_START 1
  42. #define LIB_STOP 0
  43. #define LIB_IN_USE 1
  44. #define LIB_NO_USE 0
  45. #define LIB_PSU_MIN_CUR 10 // 1A
  46. #define LIB_PSU_MAX_CUR 1000 // 100A
  47. #define LIB_PSU_MAX_VOL 10000 // 1000V
  48. #define LIB_PSU_MIN_VOL 1500 // 150V
  49. #define LIB_UU_HW_VERSIION 0
  50. typedef unsigned char byte;
  51. typedef unsigned short word;
  52. typedef unsigned int unit;
  53. struct UuPowerInformation ShmUuPowerData;
  54. struct TimelineInfor ShmTimelineData;
  55. int CanFd;
  56. pid_t recFork;
  57. pid_t callbackFunc;
  58. typedef union
  59. {
  60. unsigned int PwrMessage;
  61. struct
  62. {
  63. unsigned int SerialNumberLowPart:9; // SerialNumber Low Part
  64. unsigned int ProductionDay:5; // Production Day
  65. unsigned int ModuleAddress:7; // Module Address
  66. unsigned int MonitorAddress:4; // Monitor Address
  67. unsigned int Protocol:4; // Protocol
  68. unsigned int res:3; // reserved
  69. }UUBits;
  70. }PwrFrame;
  71. struct UU_PSU_INFO
  72. {
  73. byte targetNumber;
  74. unsigned short dc2dcVersion;
  75. unsigned short pfcVersion;
  76. float maxVoltage;
  77. unsigned short powerCap;
  78. unsigned short currentCap;
  79. float outputVol;
  80. float outputCur;
  81. unsigned short inputVolL12;
  82. unsigned short inputVolL23;
  83. unsigned short inputVolL31;
  84. };
  85. struct UU_POW_MODULE_INFO
  86. {
  87. struct UU_PSU_INFO psuInfo[12];
  88. byte psuCount;
  89. float presentVol;
  90. float presentCur;
  91. };
  92. struct TimelineInfor
  93. {
  94. bool _getCountChk;
  95. struct timespec _getCount_time;
  96. };
  97. struct UuPowerInformation
  98. {
  99. bool _getCountIndexComp;
  100. // 2 Group
  101. struct UU_POW_MODULE_INFO uu_pow_info[2];
  102. byte totalPsuCount;
  103. };
  104. enum PSU_VOLTAGE_MODE
  105. {
  106. PSU_VOLTAGE_HIGH = 0x01,
  107. PSU_VOLTAGE_LOW = 0x02,
  108. PSU_VOLTAGE_AUTO = 0x03
  109. };
  110. enum PSU_POWER_CMD
  111. {
  112. PSU_POWER_ON = 0,
  113. PSU_POWER_OFF = 1,
  114. };
  115. enum PSU_MONITOR_ID
  116. {
  117. PSU_MONITOR_BROADCAST = 0x00,
  118. PSU_MONITOR_DEFAULT = 0x01,
  119. };
  120. enum PSU_MODULE_ID
  121. {
  122. PSU_MODULE_BROADCAST = 0x00
  123. };
  124. enum PSU_MSG_CMD
  125. {
  126. PSU_MSG_CMD_SET_PARAM = 0x00, // Send
  127. PSU_MSG_CMD_SET_RES = 0x01, // Response
  128. PSU_MSG_CMD_READ_MSG = 0x02, // Send
  129. PSU_MSG_CMD_READ_RES = 0x03, // Response
  130. PSU_MSG_CMD_READ_SERIAL_RES = 0x04,
  131. };
  132. enum PSU_CTRL_CMD
  133. {
  134. PSU_R_MODULE_COUNT = 0x00, // Get module count ( Get output voltage )
  135. PSU_R_OUTPUT_CUR = 0x01, // Get output current
  136. PSU_W_OUTPUT_VOL = 0x02, // Set output voltage
  137. PSU_W_OUTPUT_CUR = 0x03, // Set output current
  138. PSU_W_SWITCH_POW = 0x04, // Set PSU power - on/off
  139. PSU_R_SERIAL_NUM = 0x05, // Get PSU serial number
  140. PSU_R_STATUS = 0x08, // Get status
  141. PSU_R_OUTPUT_POW_CAP = 0x0A, // Get Output power Cap
  142. PSU_R_MAX_VOL = 0x0C, // Get max voltage
  143. PSU_R_VIN_L12 = 0x14, // Get L12 of Vin
  144. PSU_R_VIN_L23 = 0x15, // Get L23 of Vin
  145. PSU_R_VIN_L31 = 0x16, // Get L31 of Vin
  146. PSU_R_TEMP = 0x1E, // Get PSU temperature
  147. PSU_R_FAST_OUTPUT_CUR = 0x2F, // Get output current (Fast)
  148. PSU_RW_GROUP = 0x59, // Get/Set PSU group
  149. PSU_W_HIGH_LOW_VOL_MODE = 0x5F, // Set PSU high/low voltage mode
  150. PSU_R_HIGH_LOW_VOL_MODE = 0x60, // Get PSU high/low voltage mode
  151. PSU_R_FAST_OUTPUT_VOL = 0x62, // Get output voltage (Fast)
  152. PSU_R_DD_VERSION = 0x63, // Get DC to DC version
  153. PSU_R_PFC_VERSION = 0x64, // Get PFC version
  154. PSU_R_OUTPUT_CUR_CAP = 0x68, // Get output current cap.
  155. PSU_R_IAVAILABLE = 0x72, // Get iavailable current
  156. };
  157. enum PSU_INFORMATION_TARGET
  158. {
  159. PSU_INFORMATION_OUTPUT_POW = 0x01,
  160. PSU_INFORMATION_OUTPUT_CUR = 0x02,
  161. };
  162. enum PSU_FLASH_CMD
  163. {
  164. PSU_FLASH_NORMAL = 0,
  165. PSU_FLASH_ON = 1,
  166. };
  167. /*Initialization*/
  168. bool InitialCommunication();
  169. void GetStatus(byte group, byte param);
  170. void GetGroup(byte address);
  171. void GetModuleVoltageMode(byte group);
  172. void SetGroup(byte group, byte sourceAddr, byte targetAddr);
  173. void SetModuleVoltageMode(byte group, byte value);
  174. void SwitchPower(byte group, byte value);
  175. void SetWalkInConfig(byte group, byte enable, byte sec);
  176. void GetModuleCount(byte group);
  177. void GetModuleCap(byte group);
  178. void GetModuleVer(byte group);
  179. void GetModuleOutputF(byte group);
  180. void GetModuleIavailable(byte group);
  181. void GetDcTemperature(byte group);
  182. void PresentOutputVol(byte group, int voltage, int current, byte psuCount);
  183. void FlashLed(byte group, byte value);
  184. // none used
  185. void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay);
  186. /* Callback Function */
  187. void RefreshStatus(void *func);
  188. void (*return_status)(byte group, byte address, byte temp, int status, byte type,
  189. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  190. void RefreshModuleCount(void *func);
  191. void (*return_module_count)(byte group, byte count);
  192. void RefreshAvailableCap(void *func);
  193. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  194. void RefreshFwVersion(void *func);
  195. void (*return_fw_version)(byte address, short dcSwVer, short pfcSwVer, short hwVer, byte type);
  196. void RefreshInputVol(void *func);
  197. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  198. void RefreshGetOutput(void *func);
  199. void (*return_get_output)(byte address, float outVol, float outCur);
  200. void RefreshGetOutputF(void *func);
  201. void (*return_get_output_float)(byte group, float outVol, float outCur, byte type);
  202. void RefreshMisInfo(void *func);
  203. void (*return_mis_info)(byte address, unsigned int fanSpeed, byte type);
  204. void RefreshIavailable(void *func);
  205. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  206. /*Test mode used*/
  207. void AutoMode_RefreshOutputAndTemp(void *func);
  208. void (*return_output_temp)(byte address, unsigned short outputVol,
  209. unsigned short outputCur, unsigned short outputPower, unsigned char Temperature, byte type);
  210. void AutoMode_RefreshModuleStatus(void *func);
  211. void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
  212. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  213. void AutoMode_RefreshModuleInput(void *func);
  214. void (*return_module_input)(byte address, unsigned short inputR,
  215. unsigned short inputS, unsigned short inputT);
  216. #endif /* UUPWR_PSUCOMMOBJ_H_ */