PhGroup_PsuCommObj.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Phihong_PsuCommObj.h
  3. PhGroup_PsuCommObj
  4. * Created on: 2022年02月22日
  5. * Author: 8274
  6. */
  7. #ifndef TESTONE_PSUCOMMOBJ_H_
  8. #define TESTONE_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 DIR_CSU_to_Slave 0x5
  41. #define DIR_CSU_to_GrpMaster 0x6
  42. #define DIR_GrpMaster_to_CSU 0xE
  43. #define DIR_Slave_to_CSU 0xD
  44. #define SlaveAdd_Position 0
  45. #define GroupAdd_Position 6
  46. #define ALL_Group 0x3F
  47. #define ALL_Slave 0x3F
  48. #define PUS_UNLOCK_CMD 0xA5
  49. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  50. #define CMD_DELAY_TIME 25000
  51. typedef unsigned char byte;
  52. typedef unsigned short word;
  53. typedef unsigned int unit;
  54. int CanFd;
  55. pid_t recFork;
  56. typedef union
  57. {
  58. unsigned int PwrMessage;
  59. struct
  60. {
  61. unsigned int SlaveAddress:6; // slave address
  62. unsigned int SlaveGroup:6; // slave group
  63. unsigned int DIR:4; // message direction
  64. unsigned int MessageID:8; // message ID type
  65. unsigned int Status:4; // PSU status
  66. unsigned int RDY:1; // PSU stanby
  67. }PHBits;
  68. }PH_PwrFrame; //onetry
  69. typedef enum //onetry
  70. {
  71. PH_PSU_POWER_ON = 0xA1,
  72. PH_PSU_POWER_OFF = 0x00,
  73. }PH_Pwr_POWER_CMD;
  74. typedef enum
  75. {
  76. PH_PSU_RCmd_GetGroupModuleCount = 0x03,
  77. PH_PSU_RCmd_GetAlarmFault = 0x04,
  78. PH_PSU_RCmd_GetModuleVersion = 0x05,
  79. PH_PSU_RCmd_GetTemperature = 0x06,
  80. PH_PSU_RCmd_GetACInputVoltage = 0x07,
  81. PH_PSU_RCmd_GetACInputCurrent = 0x08,
  82. PH_PSU_RCmd_GetPresentOutput = 0x09,
  83. PH_PSU_RCmd_GetErrorRecord = 0x0A,
  84. PH_PSU_WCmd_ModulePowerOnOff = 0x41,
  85. PH_PSU_WCmd_SetOutputCommand = 0x42,
  86. PH_PSU_WCmd_UnlockPsuCommand = 0x43,
  87. PH_PSU_Ack_Msg = 0x80,
  88. }PHPwrCommand;
  89. typedef enum
  90. {
  91. PH_FW_DD_App = 0x01,
  92. PH_FW_PFC_App = 0x02,
  93. PH_FW_DD_Bootloader = 0x03,
  94. PH_FW_PFC_Bootloader = 0x04,
  95. }PHPwrFwVer;
  96. /*Initialization*/
  97. pid_t InitialCommunication(void);
  98. /*Set Cmd*/
  99. void SwitchPower(byte group, byte value);
  100. void SinglePsuPower(byte address, byte value);
  101. void SwitchPower_On(byte group);
  102. void SwitchPower_Off(byte group);
  103. void SinglePsuPower_On(byte address);
  104. void SinglePsuPower_Off(byte address);
  105. void SleepMode(byte group, byte value);
  106. void FlashLed(byte group, byte value);
  107. void SingleFlashLed(byte address, byte value);
  108. void FlashLed_Static(byte group);
  109. void FlashLed_Blinking(byte group);
  110. void SingleFlashLed_Static(byte address);
  111. void SingleFlashLed_Blinking(byte address);
  112. void PresentOutputVol(byte group, int voltage, int current);
  113. void SingleOutputVol(byte address, int voltage, int current);
  114. void FanNoiseInfo(byte group, byte value);
  115. void SetWalkInConfig(byte group, byte enable, byte sec);
  116. void SetDipSwitchMode();
  117. void UnlockPsuAlarm(byte full_address);
  118. /*Ver : 9.06 used*/
  119. void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay);
  120. /*Get Cmd*/
  121. void GetStatus(byte group);
  122. void GetFanSpeed(byte group);
  123. void GetDcTemperature(byte group);
  124. void GetPfcTemperature(byte group);
  125. void GetModuleCount(byte group);
  126. void GetSysModuleCount(void);
  127. void GetModuleVer(byte group, byte type);
  128. void GetAllModuleVer(byte group);
  129. void GetModuleCap(byte group);
  130. void GetModuleBarCode(byte group);
  131. void GetModuleInputVol(byte group);
  132. void GetModuleInputCur(byte group);
  133. void GetModuleIavailable(byte group, unsigned short voltage);
  134. void GetModuleOutput(byte group);
  135. void GetModuleOutputF(byte group);
  136. void GetErrorRecord(byte group);
  137. /*Upgrade*/
  138. void ChangePsuBaudrate(short baudrate);
  139. /* Callback Function */
  140. void RefreshPsuIndex(int (*func)(byte group, byte gIndex));
  141. int (*return_psuIndex)(byte group, byte gIndex);
  142. void RefreshGroup(void *func);
  143. void (*return_group)(byte group, byte psu_index, unsigned short full_address);
  144. void RefreshInfyPwrAlarmFlag(void *func);
  145. void (*return_infy_pwr_alarm_flag)(byte address, byte state_2, byte state_1, byte state_0);
  146. void RefreshPhPwrAlarmFlag(void *func);
  147. void (*return_ph_pwr_alarm_flag)(byte address, unsigned int status, unsigned int alarm_1, unsigned int alarm_0);
  148. void RefreshAlarmStatus(void *func);
  149. void (*return_alarm_status)(byte address, unsigned int status);
  150. void RefreshAmbient(void *func);
  151. void (*return_ambient)(byte address, char temp);
  152. void RefreshModuleCount(void *func);
  153. void (*return_module_count)(byte group, byte count, bool summation);
  154. void RefreshSysModuleCount(void *func);
  155. void (*return_sys_module_count)(byte group, byte count);
  156. void RefreshAvailableCap(void *func);
  157. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  158. void RefreshFwDcVersion(void *func);
  159. void (*return_fw_dc_version)(byte address, char *dcSwVer);
  160. void RefreshFwPfcVersion(void *func);
  161. void (*return_fw_pfc_version)(byte address, char *pfcSwVer);
  162. void RefreshInputVol(void *func);
  163. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  164. void RefreshInputCur(void *func);
  165. void (*return_input_cur)(byte address, unsigned short cur1, unsigned short cur2, unsigned short cur3);
  166. void RefreshGetOutput(void *func);
  167. void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
  168. void RefreshGetOutputF(void *func);
  169. void (*return_get_output_float)(byte group, float outVol, float outCur);
  170. void RefreshGetModuleOutput(void *func);
  171. void (*return_module_output)(byte address, float outVol, float outCur);
  172. void RefreshGetErrorRecord(void *func);
  173. void (*return_error_record)(byte address, byte count_down, byte *error_record);
  174. void RefreshFanSpeedInfo(void *func);
  175. void (*return_fan_speed)(byte address, unsigned int fanSpeed);
  176. void RefreshInletTemp(void *func);
  177. void (*return_inlet_temp)(byte address, char temp);
  178. void RefreshExletTemp(void *func);
  179. void (*return_exlet_temp)(byte address, char temp);
  180. void RefreshOutletTemp(void *func);
  181. void (*return_outlet_temp)(byte address, char temp);
  182. void RefreshOtherTemp(void *func);
  183. void (*return_other_temp)(byte address, char temp1, char temp2, char temp3, char temp4);
  184. void RefreshIavailable(void *func);
  185. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  186. /*Test mode used*/
  187. void AutoMode_RefreshOutputAndTemp(void *func);
  188. void (*return_output_temp)(byte address, unsigned short outputVol,
  189. unsigned short outputCur, unsigned short outputPower, unsigned char Temperature);
  190. void AutoMode_RefreshModuleStatus(void *func);
  191. void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
  192. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  193. void AutoMode_RefreshModuleInput(void *func);
  194. void (*return_module_input)(byte address, unsigned short inputR,
  195. unsigned short inputS, unsigned short inputT);
  196. /* Callback Function end */
  197. #endif