/* * UUpwr_PsuCommObj.h * * Created on: 2022年3月30日 * Author: 7564 */ #ifndef UUPWR_PSUCOMMOBJ_H_ #define UUPWR_PSUCOMMOBJ_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /*標準輸入輸出定義*/ #include /*標準函數庫定義*/ #include /*Unix 標準函數定義*/ #include /*檔控制定義*/ #include /*PPSIX 終端控制定義*/ #include /*錯誤號定義*/ #include #include #include #include #include #include #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0])) #define PSU_PROTOCOL_TYPE 1 #define SYSTEM_CMD 0x3F #define LIB_START 1 #define LIB_STOP 0 #define LIB_IN_USE 1 #define LIB_NO_USE 0 #define LIB_PSU_MIN_CUR 10 // 1A #define LIB_PSU_MAX_CUR 1000 // 100A #define LIB_PSU_MAX_VOL 10000 // 1000V #define LIB_PSU_MIN_VOL 1500 // 150V #define LIB_UU_HW_VERSIION 0 typedef unsigned char byte; typedef unsigned short word; typedef unsigned int unit; struct UuPowerInformation ShmUuPowerData; struct TimelineInfor ShmTimelineData; int CanFd; pid_t recFork; pid_t callbackFunc; typedef union { unsigned int PwrMessage; struct { unsigned int SerialNumberLowPart:9; // SerialNumber Low Part unsigned int ProductionDay:5; // Production Day unsigned int ModuleAddress:7; // Module Address unsigned int MonitorAddress:4; // Monitor Address unsigned int Protocol:4; // Protocol unsigned int res:3; // reserved }UUBits; }PwrFrame; struct UU_PSU_INFO { byte targetNumber; unsigned short dc2dcVersion; unsigned short pfcVersion; float maxVoltage; unsigned short powerCap; unsigned short currentCap; float outputVol; float outputCur; unsigned short inputVolL12; unsigned short inputVolL23; unsigned short inputVolL31; }; struct UU_POW_MODULE_INFO { struct UU_PSU_INFO psuInfo[12]; byte psuCount; float presentVol; float presentCur; }; struct TimelineInfor { bool _getCountChk; struct timespec _getCount_time; }; struct UuPowerInformation { bool _getCountIndexComp; // 2 Group struct UU_POW_MODULE_INFO uu_pow_info[2]; byte totalPsuCount; }; enum PSU_VOLTAGE_MODE { PSU_VOLTAGE_HIGH = 0x01, PSU_VOLTAGE_LOW = 0x02, PSU_VOLTAGE_AUTO = 0x03 }; enum PSU_POWER_CMD { PSU_POWER_ON = 0, PSU_POWER_OFF = 1, }; enum PSU_MONITOR_ID { PSU_MONITOR_BROADCAST = 0x00, PSU_MONITOR_DEFAULT = 0x01, }; enum PSU_MODULE_ID { PSU_MODULE_BROADCAST = 0x00 }; enum PSU_MSG_CMD { PSU_MSG_CMD_SET_PARAM = 0x00, // Send PSU_MSG_CMD_SET_RES = 0x01, // Response PSU_MSG_CMD_READ_MSG = 0x02, // Send PSU_MSG_CMD_READ_RES = 0x03, // Response PSU_MSG_CMD_READ_SERIAL_RES = 0x04, }; enum PSU_CTRL_CMD { PSU_R_MODULE_COUNT = 0x00, // Get module count ( Get output voltage ) PSU_R_OUTPUT_CUR = 0x01, // Get output current PSU_W_OUTPUT_VOL = 0x02, // Set output voltage PSU_W_OUTPUT_CUR = 0x03, // Set output current PSU_W_SWITCH_POW = 0x04, // Set PSU power - on/off PSU_R_SERIAL_NUM = 0x05, // Get PSU serial number PSU_R_STATUS = 0x08, // Get status PSU_R_OUTPUT_POW_CAP = 0x0A, // Get Output power Cap PSU_R_MAX_VOL = 0x0C, // Get max voltage PSU_R_VIN_L12 = 0x14, // Get L12 of Vin PSU_R_VIN_L23 = 0x15, // Get L23 of Vin PSU_R_VIN_L31 = 0x16, // Get L31 of Vin PSU_R_TEMP = 0x1E, // Get PSU temperature PSU_R_FAST_OUTPUT_CUR = 0x2F, // Get output current (Fast) PSU_RW_GROUP = 0x59, // Get/Set PSU group PSU_W_HIGH_LOW_VOL_MODE = 0x5F, // Set PSU high/low voltage mode PSU_R_HIGH_LOW_VOL_MODE = 0x60, // Get PSU high/low voltage mode PSU_R_FAST_OUTPUT_VOL = 0x62, // Get output voltage (Fast) PSU_R_DD_VERSION = 0x63, // Get DC to DC version PSU_R_PFC_VERSION = 0x64, // Get PFC version PSU_R_OUTPUT_CUR_CAP = 0x68, // Get output current cap. PSU_R_IAVAILABLE = 0x72, // Get iavailable current }; enum PSU_INFORMATION_TARGET { PSU_INFORMATION_OUTPUT_POW = 0x01, PSU_INFORMATION_OUTPUT_CUR = 0x02, }; enum PSU_FLASH_CMD { PSU_FLASH_NORMAL = 0, PSU_FLASH_ON = 1, }; /*Initialization*/ bool InitialCommunication(); void GetStatus(byte group, byte param); void GetGroup(byte address); void GetModuleVoltageMode(byte group); void SetGroup(byte group, byte sourceAddr, byte targetAddr); void SetModuleVoltageMode(byte group, byte value); void SwitchPower(byte group, byte value); void SetWalkInConfig(byte group, byte enable, byte sec); void GetModuleCount(byte group); void GetModuleCap(byte group); void GetModuleVer(byte group); void GetModuleOutputF(byte group); void GetModuleIavailable(byte group); void GetDcTemperature(byte group); void PresentOutputVol(byte group, int voltage, int current, byte psuCount); void FlashLed(byte group, byte value); // none used void SetDirModulePresentOutput(byte group, int voltage, int current, byte _switch, byte _interRelay); /* Callback Function */ void RefreshStatus(void *func); void (*return_status)(byte group, byte address, byte temp, int status, byte type, unsigned char err1, unsigned char err2, unsigned char err3, unsigned char err4); void RefreshModuleCount(void *func); void (*return_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 RefreshFwVersion(void *func); void (*return_fw_version)(byte address, short dcSwVer, short pfcSwVer, short hwVer, byte type); void RefreshInputVol(void *func); void (*return_input_vol)(byte address, unsigned short vol1, unsigned short vol2, unsigned short vol3); void RefreshGetOutput(void *func); void (*return_get_output)(byte address, float outVol, float outCur); void RefreshGetOutputF(void *func); void (*return_get_output_float)(byte group, float outVol, float outCur, byte type); void RefreshMisInfo(void *func); void (*return_mis_info)(byte address, unsigned int fanSpeed, byte type); 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, byte type); 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); #endif /* UUPWR_PSUCOMMOBJ_H_ */