This commit is contained in:
weizhihong 2023-10-26 16:04:16 +08:00
commit 50281a0add
2 changed files with 85 additions and 4 deletions

View File

@ -19,6 +19,10 @@ type RsspHead struct {
Da uint16 Da uint16
} }
const (
RsspCrc16GX uint32 = 0b1_0000_1000_0001_0001 //生成多项式 G(X)=X16+X11+X4+1
)
func (h *RsspHead) Type() RsspType { func (h *RsspHead) Type() RsspType {
return h.Mc return h.Mc
} }
@ -64,6 +68,15 @@ type RsspRsd struct {
Crc16 uint16 Crc16 uint16
} }
const (
CRC32_G_C1 = (uint64(0x01) << 32) | uint64(0x100d4e63) //crc32生成多项式
CRC32_G_C2 = (uint64(0x01) << 32) | uint64(0x8ce56011) //crc32生成多项式
SCW_C1 = uint32(0xae390b5a) //SCW常
SCW_C2 = uint32(0xc103589c) //SCW常
SJC_C1 = uint32(0x0fc22f87) //时间戳生成多项式
SJC_C2 = uint32(0xc3e887e1) //时间戳生成多项式
)
func (r *RsspRsd) Encode() []byte { func (r *RsspRsd) Encode() []byte {
data := make([]byte, 0, 6+14+len(r.Sad)+2) data := make([]byte, 0, 6+14+len(r.Sad)+2)
//报文头 //报文头
@ -252,10 +265,6 @@ func ParseRsspPack(pack []byte) (Rssper, error) {
// //////////////////CRC循环冗余校验--移位寄存器/////////////////////////// // //////////////////CRC循环冗余校验--移位寄存器///////////////////////////
const (
RsspCrc16GX uint32 = 0b1_0000_1000_0001_0001 //生成多项式 G(X)=X16+X11+X4+1
)
type crc struct { type crc struct {
//生成多项式即二进制位数如生成多项式X4+X3+1对应二进制11001共5位生成的校验码长度为4 //生成多项式即二进制位数如生成多项式X4+X3+1对应二进制11001共5位生成的校验码长度为4
g uint64 g uint64

View File

@ -0,0 +1,72 @@
package message
import "fmt"
// SectionCmdMsg CI系统发送的区段操作命令
type SectionCmdMsg struct {
//bit5 计轴直接复位
Drst bool
//bit2 计轴预复位
Pdrst bool
}
func (s *SectionCmdMsg) Encode() byte {
buf := 0x00
if s.Drst {
buf = buf | (0x01 << 5)
}
if s.Pdrst {
buf = buf | (0x01 << 2)
}
return byte(buf)
}
func (s *SectionCmdMsg) Decode(buf byte) {
s.Drst = buf&(0x01<<5) != 0
s.Pdrst = buf&(0x01<<2) != 0
}
// SectionStatusMsg 发送给CI系统的区段当前的状态
type SectionStatusMsg struct {
//0-bit7 计轴出清
Clr bool
//0-bit6 计轴占用
Occ bool
//1-bit6 计轴复位反馈
Rac bool
//1-bit5 运营原因拒绝计轴复位
Rjo bool
//1-bit4 技术原因拒绝计轴复位
Rjt bool
}
func (s *SectionStatusMsg) Encode() []byte {
buf := []byte{0x00, 0x00}
if s.Clr {
buf[0] = buf[0] | (0x01 << 7)
}
if s.Occ {
buf[0] = buf[0] | (0x01 << 6)
}
//
if s.Rac {
buf[1] = buf[1] | (0x01 << 6)
}
if s.Rjo {
buf[1] = buf[1] | (0x01 << 5)
}
if s.Rjt {
buf[1] = buf[1] | (0x01 << 4)
}
return buf
}
func (s *SectionStatusMsg) Decode(buf []byte) error {
if len(buf) != 2 {
return fmt.Errorf("buf 长度须为2")
}
s.Clr = buf[0]&(0x01<<7) != 0
s.Occ = buf[0]&(0x01<<6) != 0
s.Rac = buf[1]&(0x01<<6) != 0
s.Rjo = buf[1]&(0x01<<5) != 0
s.Rjt = buf[1]&(0x01<<4) != 0
return nil
}