Infypwr_PsuCommObj.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 DEVICE_NO_SINGLE_MODULE 0x0A
  44. #define DEVICE_NO_GROUP_MODULE 0x0B
  45. #define INFY_ADD_BROADCAST 0x3F
  46. #define INFY_ADD_CSU 0xF0
  47. #define NEXTON_ADD 0xFF
  48. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  49. #define CMD_DELAY_TIME 25000
  50. #define FAN_SPEED_CMD 0x1201
  51. #define TEMP_DC_CMD 0x1107
  52. #define TEMP_PFC_CMD 0x1108
  53. typedef unsigned char byte;
  54. typedef unsigned short word;
  55. typedef unsigned int unit;
  56. int CanFd;
  57. pid_t recFork;
  58. typedef union
  59. {
  60. unsigned int PwrMessage;
  61. struct
  62. {
  63. unsigned int SourceAddress:8; // source address
  64. unsigned int DestinationAddress:8; // destination address
  65. unsigned int CmdValue:6; // command value
  66. unsigned int DeviceValue:4; // 0x0A: for module command, 0x0B group command
  67. unsigned int Error:3; // error code
  68. unsigned int res:3;
  69. }InfyBits;
  70. struct
  71. {
  72. unsigned int SourceAddress:8; // source address
  73. unsigned int DestinationAddress:8; // destination address
  74. unsigned int CmdValue:13; // command value
  75. unsigned int res:3;
  76. }NextonBits;
  77. }PwrFrame;
  78. enum PSU_POWER_CMD
  79. {
  80. PSU_POWER_ON = 0,
  81. PSU_POWER_OFF = 1,
  82. };
  83. enum PSU_SLEEP_MODE_CMD
  84. {
  85. PSU_SLEEP_MODE_WAKE_UP = 0,
  86. PSU_SLEEP_MODE_SLEEP = 1,
  87. };
  88. enum PSU_FLASH_CMD
  89. {
  90. PSU_FLASH_NORMAL = 0,
  91. PSU_FLASH_ON = 1,
  92. };
  93. enum PSU_FAN_NOISE_CMD
  94. {
  95. PSU_FAN_NOISE_BY_POWER = 0xA0, // power poriority mode
  96. PSU_FAN_NOISE_BY_DENOISE = 0xA1, // denoise mode
  97. PSU_FAN_NOISE_BY_QUIET = 0xA2, // quiet mode
  98. };
  99. enum PSU_SET_CMD
  100. {
  101. MIS_INFO = 0x008F0000, // 現在只能改變降噪模式
  102. FLASH_LED = 0x00940000,
  103. WALK_IN_MODE = 0x00930000,
  104. SLEEP_MODE = 0x00990000, // 當 SWITCH POWER 打開時,可透過該指令讓模塊休眠 (風扇會停)
  105. SWITCH_POWER = 0x009A0000, // 打開,則模塊依照設定的輸出功率輸出
  106. PRESENT_OUT_VOL = 0x009B0000,
  107. DIP_SWITCH_MODE = 0x009F0000, // 設定所有模塊的地址為撥碼方式
  108. /*Ver : 9.06 used*/
  109. TEST_PRESENT_OUT = 0x180100E5,
  110. /*Upgrade*/
  111. CHANGE_BAUDRATE = 0x028F0000
  112. };
  113. enum PSU_GET_CMD
  114. {
  115. MODULE_OUTPUT_VOL_CUR_FLOAT = 0x00810000, // 取得當前輸出電壓電流 (float)
  116. MODULE_COUNT = 0x00820000, // 取得模塊數量
  117. STATUS = 0x00840000, // 取得溫度、狀態
  118. MODULE_INPUT = 0x00860000, // 取得三向輸入電壓
  119. MODULE_VER = 0x00870000, // 取得版號
  120. MODULE_OUTPUT_VOL_CUR = 0x00880000, // 取得當前輸出電壓電流
  121. MODULE_CAP = 0x008A0000, // 取得當前 Group 的最大電壓、最大電流、最小電壓、額定功率
  122. MODULE_BARCODE = 0x008B0000, // 取得 BarCode
  123. MODULE_IAVAILABLE = 0x008C0000, // 取得實際模塊可輸出的電流能力 (降載)
  124. MODULE_MIS_INFO = 0x008E0000, // 取得模塊資訊 (Tdc、Tpfc、風扇速度)
  125. /*Ver : 9.06 used*/
  126. AUTO_OUTPUT_TEMP = 0x00010000,
  127. AUTO_MODULE_STATUS = 0x00020000,
  128. AUTO_MODULE_INPUT = 0x00030000,
  129. };
  130. typedef enum
  131. {
  132. Infy_MsgErr_Normal = 0x00,
  133. Infy_MsgErr_Reserved1 = 0x01,
  134. Infy_MsgErr_CmdInvalid = 0x02,
  135. Infy_MsgErr_DataInvalid = 0x03,
  136. Infy_MsgErr_InvalidAdd = 0x04,
  137. Infy_MsgErr_Reserved2 = 0x05,
  138. Infy_MsgErr_Reserved3 = 0x06,
  139. Infy_MsgErr_StartProcess = 0x07,
  140. }InfyMessageError;
  141. typedef enum
  142. {
  143. PSU_RCmd_SysOutputVolCur_F = 0x01,
  144. PSU_RCmd_SysModuleCount = 0x02,
  145. PSU_RCmd_ModuleOutputVolCur_F = 0x03, // no use
  146. PSU_RCmd_ModuleStatus = 0x04,
  147. PSU_RCmd_ModuleInputVoltage = 0x06,
  148. PSU_RCmd_ModuleVersion = 0x07,
  149. PSU_RCmd_SysOutputVolCur = 0x08,
  150. PSU_RCmd_ModuleOutputVolCur = 0x09, // no use
  151. PSU_RCmd_ModuleCapability = 0x0A,
  152. PSU_RCmd_ModuleBarcode = 0x0B,
  153. PSU_RCmd_ModuleIAvailable = 0x0C,
  154. PSU_RCmd_ModuleMiscInfo = 0x0E,
  155. PSU_WCmd_ModuleSetMiscInfo = 0x0F,
  156. PSU_WCmd_ModuleWalkIn = 0x13,
  157. PSU_WCmd_ModuleFlashLed = 0x14,
  158. PSU_WCmd_ModuleSetGroup = 0x16,
  159. PSU_WCmd_ModuleSleepMode = 0x19,
  160. PSU_WCmd_ModulePowerOnOff = 0x1A,
  161. PSU_WCmd_SetOutput = 0x1B,
  162. PSU_WCmd_ModuleSetOutput = 0x1C,
  163. PSU_WCmd_DipSwitchMode = 0x1F,
  164. }InfyPwrCommand;
  165. typedef enum
  166. {
  167. Nexton_PSU_ChargingRequest = 0x1801,
  168. Nexton_PSU_DcOutputValue = 0x1901,
  169. Nexton_PSU_StatusEvent = 0x1902,
  170. Nexton_PSU_AcInputValue = 0x1903,
  171. }NextonPwrCommand;
  172. typedef enum
  173. {
  174. GetMiscInfo_DcTemperature = 0x1107,
  175. GetMiscInfo_PfcTemperature = 0x1108,
  176. GetMiscInfo_FanSpeed = 0x1201,
  177. }GetMiscInfoCommand;
  178. typedef enum
  179. {
  180. SetMiscInfo_FanMode = 0x1113,
  181. SetMiscInfo_FanSpeed = 0x1201,
  182. SetMiscInfo_CurrentLimit = 0x1205,
  183. SetMiscInfo_SendTemperature = 0x1301,
  184. }SetMiscInfoCommand;
  185. union FloatingPointIEEE754
  186. {
  187. struct
  188. {
  189. unsigned int mantissa : 23;
  190. unsigned int exponent : 8;
  191. unsigned int sign : 1;
  192. } raw;
  193. float f;
  194. } number;
  195. struct INFY_POW_MODULE_INFO
  196. {
  197. byte serialNumber[12];
  198. byte targetNumber[12];
  199. byte psuCount;
  200. };
  201. struct INFY_POW_MODULE_INFO infy_pow_info[2];
  202. /*Initialization*/
  203. bool InitialCommunication();
  204. /*Set Cmd*/
  205. void SwitchPower(byte group, byte value);
  206. void SleepMode(byte group, byte value);
  207. void FlashLed(byte group, byte value);
  208. void PresentOutputVol(byte group, int voltage, int current);
  209. void FanNoiseInfo(byte group, byte value);
  210. void SetWalkInConfig(byte group, byte enable, byte sec);
  211. void SetDipSwitchMode();
  212. /*Ver : 9.06 used*/
  213. void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay);
  214. /*Get Cmd*/
  215. void GetStatus(byte group);
  216. void GetFanSpeed(byte group);
  217. void GetDcTemperature(byte group);
  218. void GetPfcTemperature(byte group);
  219. void GetFanSpeed(byte group);
  220. void GetModuleCount(byte group);
  221. void GetModuleVer(byte group);
  222. void GetModuleCap(byte group);
  223. void GetModuleBarCode(byte group);
  224. void GetModuleInput(byte group);
  225. void GetModuleIavailable(byte group);
  226. void GetModuleOutput(byte group);
  227. void GetModuleOutputF(byte group);
  228. /*Upgrade*/
  229. void ChangePsuBaudrate(short baudrate);
  230. /* Callback Function */
  231. void RefreshStatus(void *func);
  232. void (*return_status)(byte group, byte address, byte temp, int status);
  233. void RefreshModuleCount(void *func);
  234. void (*return_module_count)(byte group, byte count);
  235. void RefreshAvailableCap(void *func);
  236. void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
  237. void RefreshFwVersion(void *func);
  238. void (*return_fw_version)(byte address, short dcSwVer, short pfcSwVer, short hwVer);
  239. void RefreshInputVol(void *func);
  240. void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
  241. void RefreshGetOutput(void *func);
  242. void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
  243. void RefreshGetOutputF(void *func);
  244. void (*return_get_output_float)(byte group, float outVol, float outCur);
  245. void RefreshMisInfo(void *func);
  246. void (*return_mis_info)(byte address, unsigned int fanSpeed, byte type);
  247. void RefreshIavailable(void *func);
  248. void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
  249. /*Test mode used*/
  250. void AutoMode_RefreshOutputAndTemp(void *func);
  251. void (*return_output_temp)(byte address, unsigned short outputVol,
  252. unsigned short outputCur, unsigned short outputPower, unsigned char Temperature);
  253. void AutoMode_RefreshModuleStatus(void *func);
  254. void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
  255. unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
  256. void AutoMode_RefreshModuleInput(void *func);
  257. void (*return_module_input)(byte address, unsigned short inputR,
  258. unsigned short inputS, unsigned short inputT);
  259. /* Callback Function end */
  260. #endif /* INFYPWR_PSUCOMMOBJ_H_ */