InfyGroup_PsuCommObj.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Infypwr_PsuCommObj.h
  3. *
  4. * Created on: 2019年11月26日
  5. * Author: 7564
  6. */
  7. #ifndef INFYPWR_PSUCOMMOBJ_H_
  8. #define INFYPWR_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 SYSTEM_CMD 0x3F
  39. #define DEVICE_NO_SINGLE_MODULE 0x0A
  40. #define DEVICE_NO_GROUP_MODULE 0x0B
  41. #define INFY_ADD_BROADCAST 0x3F
  42. #define INFY_ADD_CSU 0xF0
  43. #define NEXTON_ADD 0xFF
  44. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  45. #define CMD_DELAY_TIME 25000
  46. #define FAN_SPEED_CMD 0x1201
  47. #define TEMP_DC_CMD 0x1107
  48. #define TEMP_PFC_CMD 0x1108
  49. typedef unsigned char byte;
  50. typedef unsigned short word;
  51. typedef unsigned int unit;
  52. int CanFd;
  53. pid_t recFork;
  54. typedef union
  55. {
  56. unsigned int PwrMessage;
  57. struct
  58. {
  59. unsigned int SourceAddress:8; // source address
  60. unsigned int DestinationAddress:8; // destination address
  61. unsigned int CmdValue:6; // command value
  62. unsigned int DeviceValue:4; // 0x0A: for module command, 0x0B group command
  63. unsigned int Error:3; // error code
  64. unsigned int res:3;
  65. }InfyBits;
  66. struct
  67. {
  68. unsigned int SourceAddress:8; // source address
  69. unsigned int DestinationAddress:8; // destination address
  70. unsigned int CmdValue:13; // command value
  71. unsigned int res:3;
  72. }NextonBits;
  73. }PwrFrame;
  74. enum PSU_POWER_CMD
  75. {
  76. PSU_POWER_ON = 0,
  77. PSU_POWER_OFF = 1,
  78. };
  79. enum PSU_SLEEP_MODE_CMD
  80. {
  81. PSU_SLEEP_MODE_WAKE_UP = 0,
  82. PSU_SLEEP_MODE_SLEEP = 1,
  83. };
  84. enum PSU_FLASH_CMD
  85. {
  86. PSU_FLASH_NORMAL = 0,
  87. PSU_FLASH_ON = 1,
  88. };
  89. enum PSU_FAN_NOISE_CMD
  90. {
  91. PSU_FAN_NOISE_BY_POWER = 0xA0, // power poriority mode
  92. PSU_FAN_NOISE_BY_DENOISE = 0xA1, // denoise mode
  93. PSU_FAN_NOISE_BY_QUIET = 0xA2, // quiet mode
  94. };
  95. typedef enum
  96. {
  97. Infy_MsgErr_Normal = 0x00,
  98. Infy_MsgErr_Reserved1 = 0x01,
  99. Infy_MsgErr_CmdInvalid = 0x02,
  100. Infy_MsgErr_DataInvalid = 0x03,
  101. Infy_MsgErr_InvalidAdd = 0x04,
  102. Infy_MsgErr_Reserved2 = 0x05,
  103. Infy_MsgErr_Reserved3 = 0x06,
  104. Infy_MsgErr_StartProcess = 0x07,
  105. }InfyMessageError;
  106. typedef enum
  107. {
  108. PSU_RCmd_SysOutputVolCur_F = 0x01,
  109. PSU_RCmd_SysModuleCount = 0x02,
  110. PSU_RCmd_ModuleOutputVolCur_F = 0x03, // no use
  111. PSU_RCmd_ModuleStatus = 0x04,
  112. PSU_RCmd_ModuleInputVoltage = 0x06,
  113. PSU_RCmd_ModuleVersion = 0x07,
  114. PSU_RCmd_SysOutputVolCur = 0x08,
  115. PSU_RCmd_ModuleOutputVolCur = 0x09, // no use
  116. PSU_RCmd_ModuleCapability = 0x0A,
  117. PSU_RCmd_ModuleBarcode = 0x0B,
  118. PSU_RCmd_ModuleIAvailable = 0x0C,
  119. PSU_RCmd_ModuleMiscInfo = 0x0E,
  120. PSU_WCmd_ModuleSetMiscInfo = 0x0F,
  121. PSU_WCmd_ModuleWalkIn = 0x13,
  122. PSU_WCmd_ModuleFlashLed = 0x14,
  123. PSU_WCmd_ModuleSetGroup = 0x16,
  124. PSU_WCmd_ModuleSleepMode = 0x19,
  125. PSU_WCmd_ModulePowerOnOff = 0x1A,
  126. PSU_WCmd_SetOutput = 0x1B,
  127. PSU_WCmd_ModuleSetOutput = 0x1C,
  128. PSU_WCmd_DipSwitchMode = 0x1F,
  129. }InfyPwrCommand;
  130. typedef enum
  131. {
  132. Nexton_PSU_ChargingRequest = 0x1801,
  133. Nexton_PSU_DcOutputValue = 0x1901,
  134. Nexton_PSU_StatusEvent = 0x1902,
  135. Nexton_PSU_AcInputValue = 0x1903,
  136. }NextonPwrCommand;
  137. typedef enum
  138. {
  139. GetMiscInfo_DcTemperature = 0x1107,
  140. GetMiscInfo_PfcTemperature = 0x1108,
  141. GetMiscInfo_FanSpeed = 0x1201,
  142. }GetMiscInfoCommand;
  143. typedef enum
  144. {
  145. SetMiscInfo_FanMode = 0x1113,
  146. SetMiscInfo_FanSpeed = 0x1201,
  147. SetMiscInfo_CurrentLimit = 0x1205,
  148. SetMiscInfo_SendTemperature = 0x1301,
  149. }SetMiscInfoCommand;
  150. /*Initialization*/
  151. pid_t InitialCommunication();
  152. /*Set Cmd*/
  153. void SwitchPower(byte group, byte value);
  154. void SinglePsuPower(byte address, byte value);
  155. void SleepMode(byte group, byte value);
  156. void FlashLed(byte group, byte value);
  157. void SingleFlashLed(byte address, byte value);
  158. void PresentOutputVol(byte group, int voltage, int current);
  159. void SingleOutputVol(byte address, int voltage, int current);
  160. void FanNoiseInfo(byte group, byte value);
  161. void SetWalkInConfig(byte group, byte enable, byte sec);
  162. void SetDipSwitchMode();
  163. /*Ver : 9.06 used*/
  164. void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay);
  165. /*Get Cmd*/
  166. void GetStatus(byte group);
  167. void GetFanSpeed(byte group);
  168. void GetDcTemperature(byte group);
  169. void GetPfcTemperature(byte group);
  170. void GetFanSpeed(byte group);
  171. void GetModuleCount(byte group);
  172. void GetModuleVer(byte group);
  173. void GetModuleCap(byte group);
  174. void GetModuleBarCode(byte group);
  175. void GetModuleInput(byte group);
  176. void GetModuleIavailable(byte group);
  177. void GetModuleOutput(byte group);
  178. void GetModuleOutputF(byte group);
  179. /*Upgrade*/
  180. void ChangePsuBaudrate(short baudrate);
  181. /* Callback Function */
  182. void RefreshStatus(void *func);
  183. void (*return_status)(byte group, byte address, byte temp, int status);
  184. void RefreshModuleCount(void *func);
  185. void (*return_module_count)(byte group, byte count);
  186. void RefreshAvailableCap(void *func);
  187. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  188. void RefreshFwVersion(void *func);
  189. void (*return_fw_version)(byte address, short dcSwVer, short pfcSwVer, short hwVer);
  190. void RefreshInputVol(void *func);
  191. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  192. void RefreshGetOutput(void *func);
  193. void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
  194. void RefreshGetOutputF(void *func);
  195. void (*return_get_output_float)(byte group, float outVol, float outCur);
  196. void RefreshMisInfo(void *func);
  197. void (*return_mis_info)(byte address, unsigned int fanSpeed, byte type);
  198. void RefreshIavailable(void *func);
  199. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  200. /*Test mode used*/
  201. void AutoMode_RefreshOutputAndTemp(void *func);
  202. void (*return_output_temp)(byte address, unsigned short outputVol,
  203. unsigned short outputCur, unsigned short outputPower, unsigned char Temperature);
  204. void AutoMode_RefreshModuleStatus(void *func);
  205. void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
  206. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  207. void AutoMode_RefreshModuleInput(void *func);
  208. void (*return_module_input)(byte address, unsigned short inputR,
  209. unsigned short inputS, unsigned short inputT);
  210. /* Callback Function end */
  211. #endif /* INFYPWR_PSUCOMMOBJ_H_ */