Infypwr_PsuCommObj.h 6.1 KB

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