1 Star 0 Fork 0

叶海丰/ipmi-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cmd_get_sensor_event_enable.go 4.77 KB
一键复制 编辑 原始数据 按行查看 历史
叶海丰 提交于 2024-08-02 08:43 . init
package ipmi
import (
"fmt"
"strings"
)
// 35.11 Get Sensor Event Enable Command
type GetSensorEventEnableRequest struct {
SensorNumber uint8
}
// For event , true means the event has enabled.
type GetSensorEventEnableResponse struct {
EventMessagesDisabled bool
SensorScanningDisabled bool
SensorEventFlag
}
func (req *GetSensorEventEnableRequest) Command() Command {
return CommandGetSensorEventEnable
}
func (req *GetSensorEventEnableRequest) Pack() []byte {
out := make([]byte, 1)
packUint8(req.SensorNumber, out, 0)
return out
}
func (res *GetSensorEventEnableResponse) Unpack(msg []byte) error {
if len(msg) < 1 {
return ErrUnpackedDataTooShortWith(len(msg), 1)
}
b1, _, _ := unpackUint8(msg, 0)
res.EventMessagesDisabled = !isBit7Set(b1)
res.SensorScanningDisabled = !isBit6Set(b1)
if len(msg) >= 2 {
b2, _, _ := unpackUint8(msg, 1)
res.SensorEvent_UNC_High_Assert = isBit7Set(b2)
res.SensorEvent_UNC_Low_Assert = isBit6Set(b2)
res.SensorEvent_LNR_High_Assert = isBit5Set(b2)
res.SensorEvent_LNR_Low_Assert = isBit4Set(b2)
res.SensorEvent_LCR_High_Assert = isBit3Set(b2)
res.SensorEvent_LCR_Low_Assert = isBit2Set(b2)
res.SensorEvent_LNC_High_Assert = isBit1Set(b2)
res.SensorEvent_LNC_Low_Assert = isBit0Set(b2)
res.SensorEvent_State_7_Assert = isBit7Set(b2)
res.SensorEvent_State_6_Assert = isBit6Set(b2)
res.SensorEvent_State_5_Assert = isBit5Set(b2)
res.SensorEvent_State_4_Assert = isBit4Set(b2)
res.SensorEvent_State_3_Assert = isBit3Set(b2)
res.SensorEvent_State_2_Assert = isBit2Set(b2)
res.SensorEvent_State_1_Assert = isBit1Set(b2)
res.SensorEvent_State_0_Assert = isBit0Set(b2)
}
if len(msg) >= 3 {
b3, _, _ := unpackUint8(msg, 2)
res.SensorEvent_UNR_High_Assert = isBit3Set(b3)
res.SensorEvent_UNR_Low_Assert = isBit2Set(b3)
res.SensorEvent_UCR_High_Assert = isBit1Set(b3)
res.SensorEvent_UCR_Low_Assert = isBit0Set(b3)
res.SensorEvent_State_14_Assert = isBit6Set(b3)
res.SensorEvent_State_13_Assert = isBit5Set(b3)
res.SensorEvent_State_12_Assert = isBit4Set(b3)
res.SensorEvent_State_11_Assert = isBit3Set(b3)
res.SensorEvent_State_10_Assert = isBit2Set(b3)
res.SensorEvent_State_9_Assert = isBit1Set(b3)
res.SensorEvent_State_8_Assert = isBit0Set(b3)
}
if len(msg) >= 4 {
b4, _, _ := unpackUint8(msg, 3)
res.SensorEvent_UNC_High_Deassert = isBit7Set(b4)
res.SensorEvent_UNC_Low_Deassert = isBit6Set(b4)
res.SensorEvent_LNR_High_Deassert = isBit5Set(b4)
res.SensorEvent_LNR_Low_Deassert = isBit4Set(b4)
res.SensorEvent_LCR_High_Deassert = isBit3Set(b4)
res.SensorEvent_LCR_Low_Deassert = isBit2Set(b4)
res.SensorEvent_LNC_High_Deassert = isBit1Set(b4)
res.SensorEvent_LNC_Low_Deassert = isBit0Set(b4)
res.SensorEvent_State_7_Deassert = isBit7Set(b4)
res.SensorEvent_State_6_Deassert = isBit6Set(b4)
res.SensorEvent_State_5_Deassert = isBit5Set(b4)
res.SensorEvent_State_4_Deassert = isBit4Set(b4)
res.SensorEvent_State_3_Deassert = isBit3Set(b4)
res.SensorEvent_State_2_Deassert = isBit2Set(b4)
res.SensorEvent_State_1_Deassert = isBit1Set(b4)
res.SensorEvent_State_0_Deassert = isBit0Set(b4)
}
if len(msg) >= 5 {
b5, _, _ := unpackUint8(msg, 4)
res.SensorEvent_UNR_High_Deassert = isBit3Set(b5)
res.SensorEvent_UNR_Low_Deassert = isBit2Set(b5)
res.SensorEvent_UCR_High_Deassert = isBit1Set(b5)
res.SensorEvent_UCR_Low_Deassert = isBit0Set(b5)
res.SensorEvent_State_14_Deassert = isBit6Set(b5)
res.SensorEvent_State_13_Deassert = isBit5Set(b5)
res.SensorEvent_State_12_Deassert = isBit4Set(b5)
res.SensorEvent_State_11_Deassert = isBit3Set(b5)
res.SensorEvent_State_10_Deassert = isBit2Set(b5)
res.SensorEvent_State_9_Deassert = isBit1Set(b5)
res.SensorEvent_State_8_Deassert = isBit0Set(b5)
}
return nil
}
func (r *GetSensorEventEnableResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetSensorEventEnableResponse) Format() string {
all := res.SensorEventFlag.TrueEvents()
asserted := SensorEvents(all).FilterAssert()
deasserted := SensorEvents(all).FilterDeassert()
var assertedStr = []string{}
var deassertedStr = []string{}
for _, v := range asserted {
assertedStr = append(assertedStr, v.String())
}
for _, v := range deasserted {
deassertedStr = append(deassertedStr, v.String())
}
return fmt.Sprintf(`Event Messages Disabled : %v
Sensor Scanning Disabled : %v
Enabled Assert Event : %s
Enabled Deassert Event : %s`,
res.EventMessagesDisabled,
res.SensorScanningDisabled,
strings.Join(assertedStr, "\n - "),
strings.Join(deassertedStr, "\n - "),
)
}
func (c *Client) GetSensorEventEnable(sensorNumber uint8) (response *GetSensorEventEnableResponse, err error) {
request := &GetSensorEventEnableRequest{
SensorNumber: sensorNumber,
}
response = &GetSensorEventEnableResponse{}
err = c.Exchange(request, response)
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/rogax/ipmi-go.git
git@gitee.com:rogax/ipmi-go.git
rogax
ipmi-go
ipmi-go
86ae46cfb58e

搜索帮助

0d507c66 1850385 C8b1a773 1850385