123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- /*
- * Infypwr_PsuCommObj.h
- *
- * Created on: 2019年11月26日
- * Author: 7564
- */
- #ifndef INFYPWR_PSUCOMMOBJ_H_
- #define INFYPWR_PSUCOMMOBJ_H_
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <signal.h>
- #include <string.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/socket.h>
- #include <sys/ioctl.h>
- #include <linux/wireless.h>
- #include <linux/can.h>
- #include <linux/can/raw.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/time.h>
- #include <stdbool.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdio.h> /*標準輸入輸出定義*/
- #include <stdlib.h> /*標準函數庫定義*/
- #include <unistd.h> /*Unix 標準函數定義*/
- #include <fcntl.h> /*檔控制定義*/
- #include <termios.h> /*PPSIX 終端控制定義*/
- #include <errno.h> /*錯誤號定義*/
- #include <errno.h>
- #include <string.h>
- #include <time.h>
- #include <ctype.h>
- #include <ifaddrs.h>
- #include <math.h>
- #define SYSTEM_CMD 0x3F
- #define DEVICE_NO_SINGLE_MODULE 0x0A
- #define DEVICE_NO_GROUP_MODULE 0x0B
- #define INFY_ADD_BROADCAST 0x3F
- #define INFY_ADD_CSU 0xF0
- #define NEXTON_ADD 0xFF
- #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
- #define CMD_DELAY_TIME 25000
- #define FAN_SPEED_CMD 0x1201
- #define TEMP_DC_CMD 0x1107
- #define TEMP_PFC_CMD 0x1108
- typedef unsigned char byte;
- typedef unsigned short word;
- typedef unsigned int unit;
- int CanFd;
- pid_t recFork;
- typedef union
- {
- unsigned int PwrMessage;
- struct
- {
- unsigned int SourceAddress:8; // source address
- unsigned int DestinationAddress:8; // destination address
- unsigned int CmdValue:6; // command value
- unsigned int DeviceValue:4; // 0x0A: for module command, 0x0B group command
- unsigned int Error:3; // error code
- unsigned int res:3;
- }InfyBits;
- struct
- {
- unsigned int SourceAddress:8; // source address
- unsigned int DestinationAddress:8; // destination address
- unsigned int CmdValue:13; // command value
- unsigned int res:3;
- }NextonBits;
- }PwrFrame;
- enum PSU_POWER_CMD
- {
- PSU_POWER_ON = 0,
- PSU_POWER_OFF = 1,
- };
- enum PSU_SLEEP_MODE_CMD
- {
- PSU_SLEEP_MODE_WAKE_UP = 0,
- PSU_SLEEP_MODE_SLEEP = 1,
- };
- enum PSU_FLASH_CMD
- {
- PSU_FLASH_NORMAL = 0,
- PSU_FLASH_ON = 1,
- };
- enum PSU_FAN_NOISE_CMD
- {
- PSU_FAN_NOISE_BY_POWER = 0xA0, // power poriority mode
- PSU_FAN_NOISE_BY_DENOISE = 0xA1, // denoise mode
- PSU_FAN_NOISE_BY_QUIET = 0xA2, // quiet mode
- };
- typedef enum
- {
- Infy_MsgErr_Normal = 0x00,
- Infy_MsgErr_Reserved1 = 0x01,
- Infy_MsgErr_CmdInvalid = 0x02,
- Infy_MsgErr_DataInvalid = 0x03,
- Infy_MsgErr_InvalidAdd = 0x04,
- Infy_MsgErr_Reserved2 = 0x05,
- Infy_MsgErr_Reserved3 = 0x06,
- Infy_MsgErr_StartProcess = 0x07,
- }InfyMessageError;
- typedef enum
- {
- PSU_RCmd_SysOutputVolCur_F = 0x01,
- PSU_RCmd_SysModuleCount = 0x02,
- PSU_RCmd_ModuleOutputVolCur_F = 0x03, // no use
- PSU_RCmd_ModuleStatus = 0x04,
- PSU_RCmd_ModuleInputVoltage = 0x06,
- PSU_RCmd_ModuleVersion = 0x07,
- PSU_RCmd_SysOutputVolCur = 0x08,
- PSU_RCmd_ModuleOutputVolCur = 0x09, // no use
- PSU_RCmd_ModuleCapability = 0x0A,
- PSU_RCmd_ModuleBarcode = 0x0B,
- PSU_RCmd_ModuleIAvailable = 0x0C,
- PSU_RCmd_ModuleMiscInfo = 0x0E,
- PSU_WCmd_ModuleSetMiscInfo = 0x0F,
- PSU_WCmd_ModuleWalkIn = 0x13,
- PSU_WCmd_ModuleFlashLed = 0x14,
- PSU_WCmd_ModuleSetGroup = 0x16,
- PSU_WCmd_ModuleSleepMode = 0x19,
- PSU_WCmd_ModulePowerOnOff = 0x1A,
- PSU_WCmd_SetOutput = 0x1B,
- PSU_WCmd_ModuleSetOutput = 0x1C,
- PSU_WCmd_DipSwitchMode = 0x1F,
- }InfyPwrCommand;
- typedef enum
- {
- Nexton_PSU_ChargingRequest = 0x1801,
- Nexton_PSU_DcOutputValue = 0x1901,
- Nexton_PSU_StatusEvent = 0x1902,
- Nexton_PSU_AcInputValue = 0x1903,
- }NextonPwrCommand;
- typedef enum
- {
- GetMiscInfo_DcTemperature = 0x1107,
- GetMiscInfo_PfcTemperature = 0x1108,
- GetMiscInfo_FanSpeed = 0x1201,
- }GetMiscInfoCommand;
- typedef enum
- {
- SetMiscInfo_FanMode = 0x1113,
- SetMiscInfo_FanSpeed = 0x1201,
- SetMiscInfo_CurrentLimit = 0x1205,
- SetMiscInfo_SendTemperature = 0x1301,
- }SetMiscInfoCommand;
- /*Initialization*/
- pid_t InitialCommunication(void);
- /*Set Cmd*/
- void SwitchPower(byte group, byte value);
- void SinglePsuPower(byte address, byte value);
- void SwitchPower_On(byte group);
- void SwitchPower_Off(byte group);
- void SinglePsuPower_On(byte address);
- void SinglePsuPower_Off(byte address);
- void SleepMode(byte group, byte value);
- void FlashLed(byte group, byte value);
- void SingleFlashLed(byte address, byte value);
- void FlashLed_Static(byte group);
- void FlashLed_Blinking(byte group);
- void SingleFlashLed_Static(byte address);
- void SingleFlashLed_Blinking(byte address);
- void PresentOutputVol(byte group, int voltage, int current);
- void SingleOutputVol(byte address, int voltage, int current);
- void FanNoiseInfo(byte group, byte value);
- void SetWalkInConfig(byte group, byte enable, byte sec);
- void SetDipSwitchMode();
- void UnlockPsuAlarm(byte full_address);
- /*Ver : 9.06 used*/
- void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay);
- /*Get Cmd*/
- void GetStatus(byte group);
- void GetFanSpeed(byte group);
- void GetDcTemperature(byte group);
- void GetPfcTemperature(byte group);
- void GetModuleCount(byte group);
- void GetSysModuleCount(void);
- void GetModuleVer(byte group, byte type);
- void GetAllModuleVer(byte group);
- void GetModuleCap(byte group);
- void GetModuleBarCode(byte group);
- void GetModuleInputVol(byte group);
- void GetModuleInputCur(byte group);
- void GetModuleIavailable(byte group, unsigned short voltage);
- void GetModuleOutput(byte group);
- void GetModuleOutputF(byte group);
- void GetErrorRecord(byte group);
- /*Upgrade*/
- void ChangePsuBaudrate(short baudrate);
- /* Callback Function */
- void RefreshPsuIndex(int (*func)(byte group, byte gIndex));
- int (*return_psuIndex)(byte group, byte gIndex);
- void RefreshGroup(void *func);
- void (*return_group)(byte group, byte psu_index, unsigned short full_address);
- void RefreshInfyPwrAlarmFlag(void *func);
- void (*return_infy_pwr_alarm_flag)(byte address, byte state_2, byte state_1, byte state_0);
- void RefreshPhPwrAlarmFlag(void *func);
- void (*return_ph_pwr_alarm_flag)(byte address, unsigned int status, unsigned int alarm_1, unsigned int alarm_0);
- void RefreshAlarmStatus(void *func);
- void (*return_alarm_status)(byte address, unsigned int status);
- void RefreshAmbient(void *func);
- void (*return_ambient)(byte address, char temp);
- void RefreshModuleCount(void *func);
- void (*return_module_count)(byte group, byte count, bool summation);
- void RefreshSysModuleCount(void *func);
- void (*return_sys_module_count)(byte group, byte count);
- void RefreshAvailableCap(void *func);
- void (*return_available_cap)(byte address, short maxVol, short minVol, short maxCur, short totalPow);
- void RefreshFwDcVersion(void *func);
- void (*return_fw_dc_version)(byte address, char *dcSwVer);
- void RefreshFwPfcVersion(void *func);
- void (*return_fw_pfc_version)(byte address, char *pfcSwVer);
- void RefreshInputVol(void *func);
- void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3);
- void RefreshInputCur(void *func);
- void (*return_input_cur)(byte address, unsigned short cur1, unsigned short cur2, unsigned short cur3);
- void RefreshGetOutput(void *func);
- void (*return_get_output)(byte address, unsigned short outVol, unsigned short outCur);
- void RefreshGetOutputF(void *func);
- void (*return_get_output_float)(byte group, float outVol, float outCur);
- void RefreshGetModuleOutput(void *func);
- void (*return_module_output)(byte address, float outVol, float outCur);
- void RefreshGetErrorRecord(void *func);
- void (*return_error_record)(byte address, byte count_down, byte *error_record);
- void RefreshFanSpeedInfo(void *func);
- void (*return_fan_speed)(byte address, unsigned int fanSpeed);
- void RefreshInletTemp(void *func);
- void (*return_inlet_temp)(byte address, char temp);
- void RefreshExletTemp(void *func);
- void (*return_exlet_temp)(byte address, char temp);
- void RefreshOutletTemp(void *func);
- void (*return_outlet_temp)(byte address, char temp);
- void RefreshOtherTemp(void *func);
- void (*return_other_temp)(byte address, char temp1, char temp2, char temp3, char temp4);
- void RefreshIavailable(void *func);
- void (*return_iavail_info)(byte address, unsigned short Iavail, unsigned short Vext);
- /*Test mode used*/
- void AutoMode_RefreshOutputAndTemp(void *func);
- void (*return_output_temp)(byte address, unsigned short outputVol,
- unsigned short outputCur, unsigned short outputPower, unsigned char Temperature);
- void AutoMode_RefreshModuleStatus(void *func);
- void (*return_module_status)(byte address, unsigned char isErr, unsigned char status,
- unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4);
- void AutoMode_RefreshModuleInput(void *func);
- void (*return_module_input)(byte address, unsigned short inputR,
- unsigned short inputS, unsigned short inputT);
- /* Callback Function end */
- #endif /* INFYPWR_PSUCOMMOBJ_H_ */
|