Infypwr_PsuCommObj.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 INFYPWR_CMD 0x02000000
  39. #define INFYPWR_BROADCAST 0x00003F00
  40. #define INFYPWR_DEFAULT 0x000000F0
  41. #define INFYPWR_GROUP_SHIFT 0x00400000
  42. #define SYSTEM_CMD 0x3F
  43. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  44. #define CMD_DELAY_TIME 25000
  45. #define FAN_SPEED_CMD 0x1201
  46. typedef unsigned char byte;
  47. typedef unsigned short word;
  48. typedef unsigned int unit;
  49. int CanFd;
  50. pid_t recFork;
  51. enum PSU_POWER_CMD
  52. {
  53. PSU_POWER_ON = 0,
  54. PSU_POWER_OFF = 1,
  55. };
  56. enum PSU_SLEEP_MODE_CMD
  57. {
  58. PSU_SLEEP_MODE_WAKE_UP = 0,
  59. PSU_SLEEP_MODE_SLEEP = 1,
  60. };
  61. enum PSU_FLASH_CMD
  62. {
  63. PSU_FLASH_NORMAL = 0,
  64. PSU_FLASH_ON = 1,
  65. };
  66. enum PSU_FAN_NOISE_CMD
  67. {
  68. PSU_FAN_NOISE_BY_POWER = 0xA0,
  69. PSU_FAN_NOISE_BY_DENOISE = 0xA1,
  70. PSU_FAN_NOISE_BY_QUIET = 0xA2
  71. };
  72. enum PSU_SET_CMD
  73. {
  74. MIS_INFO = 0x008F0000, // 現在只能改變降噪模式
  75. FLASH_LED = 0x00940000,
  76. WALK_IN_MODE = 0x00930000,
  77. SLEEP_MODE = 0x00990000, // 當 SWITCH POWER 打開時,可透過該指令讓模塊休眠 (風扇會停)
  78. SWITCH_POWER = 0x009A0000, // 打開,則模塊依照設定的輸出功率輸出
  79. PRESENT_OUT_VOL = 0x009B0000,
  80. /*Ver : 9.06 used*/
  81. TEST_PRESENT_OUT = 0x180100E5,
  82. /*Upgrade*/
  83. CHANGE_BAUDRATE = 0x028F0000
  84. };
  85. enum PSU_GET_CMD
  86. {
  87. MODULE_OUTPUT_VOL_CUR_FLOAT = 0x00810000, // 取得當前輸出電壓電流 (float)
  88. MODULE_COUNT = 0x00820000, // 取得模塊數量
  89. STATUS = 0x00840000, // 取得溫度、狀態
  90. MODULE_INPUT = 0x00860000, // 取得三向輸入電壓
  91. MODULE_VER = 0x00870000, // 取得版號
  92. MODULE_OUTPUT_VOL_CUR = 0x00880000, // 取得當前輸出電壓電流
  93. MODULE_CAP = 0x008A0000, // 取得當前 Group 的最大電壓、最大電流、最小電壓、額定功率
  94. MODULE_BARCODE = 0x008B0000, // 取得 BarCode
  95. MODULE_IAVAILABLE = 0x008C0000, // 取得實際模塊可輸出的電流能力 (降載)
  96. MODULE_MIS_INFO = 0x008E0000, // 取得模塊資訊 (Tdc、Tpfc、風扇速度)
  97. /*Ver : 9.06 used*/
  98. AUTO_OUTPUT_TEMP = 0x00010000,
  99. AUTO_MODULE_STATUS = 0x00020000,
  100. AUTO_MODULE_INPUT = 0x00030000,
  101. };
  102. union FloatingPointIEEE754
  103. {
  104. struct
  105. {
  106. unsigned int mantissa : 23;
  107. unsigned int exponent : 8;
  108. unsigned int sign : 1;
  109. } raw;
  110. float f;
  111. } number;
  112. /*Initialization*/
  113. bool InitialCommunication();
  114. /*Set Cmd*/
  115. void SwitchPower(byte group, byte value);
  116. void SleepMode(byte group, byte value);
  117. void FlashLed(byte group, byte value);
  118. void PresentOutputVol(byte group, int voltage, int current);
  119. void FanNoiseInfo(byte group, byte value);
  120. void SetWalkInConfig(byte group, byte enable, byte sec);
  121. /*Ver : 9.06 used*/
  122. void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch);
  123. /*Get Cmd*/
  124. void GetStatus(byte group);
  125. void GetFanSpeed(byte group);
  126. void GetModuleCount(byte group);
  127. void GetModuleVer(byte group);
  128. void GetModuleCap(byte group);
  129. void GetModuleBarCode(byte group);
  130. void GetModuleInput(byte group);
  131. void GetModuleIavailable(byte group);
  132. void GetModuleOutput(byte group);
  133. void GetModuleOutputF(byte group);
  134. /*Upgrade*/
  135. void ChangePsuBaudrate(short baudrate);
  136. /* Callback Function */
  137. void RefreshStatus(void *func);
  138. void (*return_status)(byte group, byte address, byte temp, int status);
  139. void RefreshModuleCount(void *func);
  140. void (*return_module_count)(byte group, byte count);
  141. void RefreshAvailableCap(void *func);
  142. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  143. void RefreshFwVersion(void *func);
  144. void (*return_fw_version)(byte address, short dcSwVer, short pfcSwVer, short hwVer);
  145. void RefreshInputVol(void *func);
  146. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  147. void RefreshGetOutput(void *func);
  148. void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
  149. void RefreshGetOutputF(void *func);
  150. void (*return_get_output_float)(byte group, float outVol, float outCur);
  151. void RefreshFanInfo(void *func);
  152. void (*return_fanspeed_info)(byte address, unsigned int fanSpeed);
  153. void RefreshIavailable(void *func);
  154. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  155. /*Test mode used*/
  156. void AutoMode_RefreshOutputAndTemp(void *func);
  157. void (*return_output_temp)(byte address, unsigned short outputVol,
  158. unsigned short outputCur, unsigned short outputPower, unsigned char Temperature);
  159. void AutoMode_RefreshModuleStatus(void *func);
  160. void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
  161. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  162. void AutoMode_RefreshModuleInput(void *func);
  163. void (*return_module_input)(byte address, unsigned short inputR,
  164. unsigned short inputS, unsigned short inputT);
  165. /* Callback Function end */
  166. #endif /* INFYPWR_PSUCOMMOBJ_H_ */