PhGroup_PsuCommObj.h 7.9 KB

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