Infypwr_PsuCommObj.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. SLEEP_MODE = 0x00990000, // 當 SWITCH POWER 打開時,可透過該指令讓模塊休眠 (風扇會停)
  77. SWITCH_POWER = 0x009A0000, // 打開,則模塊依照設定的輸出功率輸出
  78. PRESENT_OUT_VOL = 0x009B0000,
  79. };
  80. enum PSU_GET_CMD
  81. {
  82. MODULE_COUNT = 0x00820000, // 取得模塊數量
  83. STATUS = 0x00840000, // 取得溫度、狀態
  84. MODULE_INPUT = 0x00860000, // 取得三向輸入電壓
  85. MODULE_VER = 0x00870000, // 取得版號
  86. MODULE_OUTPUT_VOL_CUR = 0x00880000, // 取得當前輸出電壓電流
  87. MODULE_CAP = 0x008A0000, // 取得當前 Group 的最大電壓、最大電流、最小電壓、額定功率
  88. MODULE_BARCODE = 0x008B0000, // 取得 BarCode
  89. MODULE_IAVAILABLE = 0x008C0000, // 取得實際模塊可輸出的電流能力 (降載)
  90. MODULE_MIS_INFO = 0x008E0000 // 取得模塊資訊 (Tdc、Tpfc、風扇速度)
  91. };
  92. union FloatingPointIEEE754
  93. {
  94. struct
  95. {
  96. unsigned int mantissa : 23;
  97. unsigned int exponent : 8;
  98. unsigned int sign : 1;
  99. } raw;
  100. float f;
  101. } number;
  102. /*Initialization*/
  103. bool InitialCommunication();
  104. /*Set Cmd*/
  105. void SwitchPower(byte group, byte value);
  106. void SleepMode(byte group, byte value);
  107. void FlashLed(byte group, byte value);
  108. void PresentOutputVol(byte group, int voltage, int current);
  109. void FanNoiseInfo(byte group, byte value);
  110. /*Get Cmd*/
  111. void GetStatus(byte group);
  112. void GetFanSpeed(byte group);
  113. void GetModuleCount(byte group);
  114. void GetModuleVer(byte group);
  115. void GetModuleCap(byte group);
  116. void GetModuleBarCode(byte group);
  117. void GetModuleInput(byte group);
  118. void GetModuleIavailable(byte group);
  119. void GetModuleOutput(byte group);
  120. /* Callback Function */
  121. void RefreshStatus(void *func);
  122. void (*return_status)(byte group, byte address, byte temp, int status);
  123. void RefreshModuleCount(void *func);
  124. void (*return_module_count)(byte group, byte count);
  125. void RefreshAvailableCap(void *func);
  126. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  127. void RefreshFwVersion(void *func);
  128. void (*return_fw_version)(byte address, short dcSwVer, short pfcSwVer, short hwVer);
  129. void RefreshInputVol(void *func);
  130. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  131. void RefreshGetOutput(void *func);
  132. void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
  133. void RefreshFanInfo(void *func);
  134. void (*return_fanspeed_info)(byte address, unsigned int fanSpeed);
  135. void RefreshIavailable(void *func);
  136. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  137. /* Callback Function end */
  138. #endif /* INFYPWR_PSUCOMMOBJ_H_ */