This commit is contained in:
xzb 2023-10-26 17:36:33 +08:00
parent 7b23b7090e
commit 771f444b8d

View File

@ -25,6 +25,39 @@ func (s *SectionCmdMsg) Decode(buf byte) {
s.Pdrst = buf&(0x01<<2) != 0
}
// SectionCmdMsgPack CI系统发送区段操作命令数据包
type SectionCmdMsgPack struct {
//检查字节固定0x80
Ck byte
//区段命令表,注意顺序要与协商一致
Scs []*SectionCmdMsg
}
func (s *SectionCmdMsgPack) Encode() []byte {
buf := make([]byte, 0, 1+len(s.Scs))
buf = append(buf, s.Ck)
for _, msg := range s.Scs {
buf = append(buf, msg.Encode())
}
return buf
}
func (s *SectionCmdMsgPack) Decode(buf []byte) error {
if len(buf) < 1 {
return fmt.Errorf("buf 没有足够的数据")
}
s.Ck = buf[0]
var scs []*SectionCmdMsg
for i := 1; i < len(buf); i++ {
msg := &SectionCmdMsg{}
msg.Decode(buf[i])
scs = append(scs, msg)
}
s.Scs = scs
return nil
}
///////////////////////////////////////////////
// SectionStatusMsg 发送给CI系统的区段当前的状态
type SectionStatusMsg struct {
//0-bit7 计轴出清
@ -70,3 +103,33 @@ func (s *SectionStatusMsg) Decode(buf []byte) error {
s.Rjt = buf[1]&(0x01<<4) != 0
return nil
}
type SectionStatusMsgPack struct {
//检查字节,CI系统暂时不使用
Ck byte
//区段状态表,注意顺序要与协商一致
Sms []*SectionStatusMsg
}
func (s *SectionStatusMsgPack) Encode() []byte {
buf := make([]byte, 0, 1+2*len(s.Sms))
buf = append(buf, s.Ck)
for _, msg := range s.Sms {
buf = append(buf, msg.Encode()...)
}
return buf
}
func (s *SectionStatusMsgPack) Decode(buf []byte) error {
if len(buf)%2 != 1 {
return fmt.Errorf("buf的长度须为奇数")
}
s.Ck = buf[0]
var sms []*SectionStatusMsg
for i := 1; i < len(buf)-1; i += 2 {
msg := &SectionStatusMsg{}
msg.Decode(buf[i : i+2])
sms = append(sms, msg)
}
s.Sms = sms
return nil
}