InfyGroup_PsuCommObj.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 <linux/can/raw.h>
  21. #include <sys/ipc.h>
  22. #include <sys/shm.h>
  23. #include <sys/time.h>
  24. #include <stdbool.h>
  25. #include <unistd.h>
  26. #include <stdarg.h>
  27. #include <stdio.h> /*標準輸入輸出定義*/
  28. #include <stdlib.h> /*標準函數庫定義*/
  29. #include <unistd.h> /*Unix 標準函數定義*/
  30. #include <fcntl.h> /*檔控制定義*/
  31. #include <termios.h> /*PPSIX 終端控制定義*/
  32. #include <errno.h> /*錯誤號定義*/
  33. #include <errno.h>
  34. #include <string.h>
  35. #include <time.h>
  36. #include <ctype.h>
  37. #include <ifaddrs.h>
  38. #include <math.h>
  39. #define SYSTEM_CMD 0x3F
  40. #define DEVICE_NO_SINGLE_MODULE 0x0A
  41. #define DEVICE_NO_GROUP_MODULE 0x0B
  42. #define INFY_ADD_BROADCAST 0x3F
  43. #define INFY_ADD_CSU 0xF0
  44. #define NEXTON_ADD 0xFF
  45. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  46. #define CMD_DELAY_TIME 25000
  47. #define FAN_SPEED_CMD 0x1201
  48. #define TEMP_DC_CMD 0x1107
  49. #define TEMP_PFC_CMD 0x1108
  50. typedef unsigned char byte;
  51. typedef unsigned short word;
  52. typedef unsigned int unit;
  53. int CanFd;
  54. pid_t recFork;
  55. typedef union
  56. {
  57. unsigned int PwrMessage;
  58. struct
  59. {
  60. unsigned int SourceAddress:8; // source address
  61. unsigned int DestinationAddress:8; // destination address
  62. unsigned int CmdValue:6; // command value
  63. unsigned int DeviceValue:4; // 0x0A: for module command, 0x0B group command
  64. unsigned int Error:3; // error code
  65. unsigned int res:3;
  66. }InfyBits;
  67. struct
  68. {
  69. unsigned int SourceAddress:8; // source address
  70. unsigned int DestinationAddress:8; // destination address
  71. unsigned int CmdValue:13; // command value
  72. unsigned int res:3;
  73. }NextonBits;
  74. }PwrFrame;
  75. enum PSU_POWER_CMD
  76. {
  77. PSU_POWER_ON = 0,
  78. PSU_POWER_OFF = 1,
  79. };
  80. enum PSU_SLEEP_MODE_CMD
  81. {
  82. PSU_SLEEP_MODE_WAKE_UP = 0,
  83. PSU_SLEEP_MODE_SLEEP = 1,
  84. };
  85. enum PSU_FLASH_CMD
  86. {
  87. PSU_FLASH_NORMAL = 0,
  88. PSU_FLASH_ON = 1,
  89. };
  90. enum PSU_FAN_NOISE_CMD
  91. {
  92. PSU_FAN_NOISE_BY_POWER = 0xA0, // power poriority mode
  93. PSU_FAN_NOISE_BY_DENOISE = 0xA1, // denoise mode
  94. PSU_FAN_NOISE_BY_QUIET = 0xA2, // quiet mode
  95. };
  96. typedef enum
  97. {
  98. Infy_MsgErr_Normal = 0x00,
  99. Infy_MsgErr_Reserved1 = 0x01,
  100. Infy_MsgErr_CmdInvalid = 0x02,
  101. Infy_MsgErr_DataInvalid = 0x03,
  102. Infy_MsgErr_InvalidAdd = 0x04,
  103. Infy_MsgErr_Reserved2 = 0x05,
  104. Infy_MsgErr_Reserved3 = 0x06,
  105. Infy_MsgErr_StartProcess = 0x07,
  106. }InfyMessageError;
  107. typedef enum
  108. {
  109. PSU_RCmd_SysOutputVolCur_F = 0x01,
  110. PSU_RCmd_SysModuleCount = 0x02,
  111. PSU_RCmd_ModuleOutputVolCur_F = 0x03, // no use
  112. PSU_RCmd_ModuleStatus = 0x04,
  113. PSU_RCmd_ModuleInputVoltage = 0x06,
  114. PSU_RCmd_ModuleVersion = 0x07,
  115. PSU_RCmd_SysOutputVolCur = 0x08,
  116. PSU_RCmd_ModuleOutputVolCur = 0x09, // no use
  117. PSU_RCmd_ModuleCapability = 0x0A,
  118. PSU_RCmd_ModuleBarcode = 0x0B,
  119. PSU_RCmd_ModuleIAvailable = 0x0C,
  120. PSU_RCmd_ModuleMiscInfo = 0x0E,
  121. PSU_WCmd_ModuleSetMiscInfo = 0x0F,
  122. PSU_WCmd_ModuleWalkIn = 0x13,
  123. PSU_WCmd_ModuleFlashLed = 0x14,
  124. PSU_WCmd_ModuleSetGroup = 0x16,
  125. PSU_WCmd_ModuleSleepMode = 0x19,
  126. PSU_WCmd_ModulePowerOnOff = 0x1A,
  127. PSU_WCmd_SetOutput = 0x1B,
  128. PSU_WCmd_ModuleSetOutput = 0x1C,
  129. PSU_WCmd_DipSwitchMode = 0x1F,
  130. }InfyPwrCommand;
  131. typedef enum
  132. {
  133. Nexton_PSU_ChargingRequest = 0x1801,
  134. Nexton_PSU_DcOutputValue = 0x1901,
  135. Nexton_PSU_StatusEvent = 0x1902,
  136. Nexton_PSU_AcInputValue = 0x1903,
  137. }NextonPwrCommand;
  138. typedef enum
  139. {
  140. GetMiscInfo_DcTemperature = 0x1107,
  141. GetMiscInfo_PfcTemperature = 0x1108,
  142. GetMiscInfo_FanSpeed = 0x1201,
  143. }GetMiscInfoCommand;
  144. typedef enum
  145. {
  146. SetMiscInfo_FanMode = 0x1113,
  147. SetMiscInfo_FanSpeed = 0x1201,
  148. SetMiscInfo_CurrentLimit = 0x1205,
  149. SetMiscInfo_SendTemperature = 0x1301,
  150. }SetMiscInfoCommand;
  151. /*Initialization*/
  152. pid_t InitialCommunication(void);
  153. /*Set Cmd*/
  154. void SwitchPower(byte group, byte value);
  155. void SinglePsuPower(byte address, byte value);
  156. void SwitchPower_On(byte group);
  157. void SwitchPower_Off(byte group);
  158. void SinglePsuPower_On(byte address);
  159. void SinglePsuPower_Off(byte address);
  160. void SleepMode(byte group, byte value);
  161. void FlashLed(byte group, byte value);
  162. void SingleFlashLed(byte address, byte value);
  163. void FlashLed_Static(byte group);
  164. void FlashLed_Blinking(byte group);
  165. void SingleFlashLed_Static(byte address);
  166. void SingleFlashLed_Blinking(byte address);
  167. void PresentOutputVol(byte group, int voltage, int current);
  168. void SingleOutputVol(byte address, int voltage, int current);
  169. void FanNoiseInfo(byte group, byte value);
  170. void SetWalkInConfig(byte group, byte enable, byte sec);
  171. void SetDipSwitchMode();
  172. void UnlockPsuAlarm(byte full_address);
  173. /*Ver : 9.06 used*/
  174. void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay);
  175. /*Get Cmd*/
  176. void GetStatus(byte group);
  177. void GetFanSpeed(byte group);
  178. void GetDcTemperature(byte group);
  179. void GetPfcTemperature(byte group);
  180. void GetModuleCount(byte group);
  181. void GetSysModuleCount(void);
  182. void GetModuleVer(byte group, byte type);
  183. void GetAllModuleVer(byte group);
  184. void GetModuleCap(byte group);
  185. void GetModuleBarCode(byte group);
  186. void GetModuleInputVol(byte group);
  187. void GetModuleInputCur(byte group);
  188. void GetModuleIavailable(byte group, unsigned short voltage);
  189. void GetModuleOutput(byte group);
  190. void GetModuleOutputF(byte group);
  191. void GetErrorRecord(byte group);
  192. /*Upgrade*/
  193. void ChangePsuBaudrate(short baudrate);
  194. /* Callback Function */
  195. void RefreshPsuIndex(int (*func)(byte group, byte gIndex));
  196. int (*return_psuIndex)(byte group, byte gIndex);
  197. void RefreshGroup(void *func);
  198. void (*return_group)(byte group, byte psu_index, unsigned short full_address);
  199. void RefreshInfyPwrAlarmFlag(void *func);
  200. void (*return_infy_pwr_alarm_flag)(byte address, byte state_2, byte state_1, byte state_0);
  201. void RefreshPhPwrAlarmFlag(void *func);
  202. void (*return_ph_pwr_alarm_flag)(byte address, unsigned int status, unsigned int alarm_1, unsigned int alarm_0);
  203. void RefreshAlarmStatus(void *func);
  204. void (*return_alarm_status)(byte address, unsigned int status);
  205. void RefreshAmbient(void *func);
  206. void (*return_ambient)(byte address, char temp);
  207. void RefreshModuleCount(void *func);
  208. void (*return_module_count)(byte group, byte count, bool summation);
  209. void RefreshSysModuleCount(void *func);
  210. void (*return_sys_module_count)(byte group, byte count);
  211. void RefreshAvailableCap(void *func);
  212. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  213. void RefreshFwDcVersion(void *func);
  214. void (*return_fw_dc_version)(byte address, char *dcSwVer);
  215. void RefreshFwPfcVersion(void *func);
  216. void (*return_fw_pfc_version)(byte address, char *pfcSwVer);
  217. void RefreshInputVol(void *func);
  218. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  219. void RefreshInputCur(void *func);
  220. void (*return_input_cur)(byte address, unsigned short cur1, unsigned short cur2, unsigned short cur3);
  221. void RefreshGetOutput(void *func);
  222. void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
  223. void RefreshGetOutputF(void *func);
  224. void (*return_get_output_float)(byte group, float outVol, float outCur);
  225. void RefreshGetModuleOutput(void *func);
  226. void (*return_module_output)(byte address, float outVol, float outCur);
  227. void RefreshGetErrorRecord(void *func);
  228. void (*return_error_record)(byte address, byte count_down, byte *error_record);
  229. void RefreshFanSpeedInfo(void *func);
  230. void (*return_fan_speed)(byte address, unsigned int fanSpeed);
  231. void RefreshInletTemp(void *func);
  232. void (*return_inlet_temp)(byte address, char temp);
  233. void RefreshExletTemp(void *func);
  234. void (*return_exlet_temp)(byte address, char temp);
  235. void RefreshOutletTemp(void *func);
  236. void (*return_outlet_temp)(byte address, char temp);
  237. void RefreshOtherTemp(void *func);
  238. void (*return_other_temp)(byte address, char temp1, char temp2, char temp3, char temp4);
  239. void RefreshIavailable(void *func);
  240. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  241. /*Test mode used*/
  242. void AutoMode_RefreshOutputAndTemp(void *func);
  243. void (*return_output_temp)(byte address, unsigned short outputVol,
  244. unsigned short outputCur, unsigned short outputPower, unsigned char Temperature);
  245. void AutoMode_RefreshModuleStatus(void *func);
  246. void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
  247. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  248. void AutoMode_RefreshModuleInput(void *func);
  249. void (*return_module_input)(byte address, unsigned short inputR,
  250. unsigned short inputS, unsigned short inputT);
  251. /* Callback Function end */
  252. #endif /* INFYPWR_PSUCOMMOBJ_H_ */