init
This commit is contained in:
32
trans_frame.go
Normal file
32
trans_frame.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
const ImageFrameHeadLength = 16
|
||||
const ImageFrameDataLength = 8176
|
||||
|
||||
// 智能载荷电箱与数传单机之间图像数据传输帧格式
|
||||
type TransFrame struct {
|
||||
Header [4]byte // 帧头 E77EE77E
|
||||
SNo uint32 // 序列号 大端序
|
||||
Reserved0 [2]byte // 保留字节
|
||||
KeyIndex uint16 // 密钥库索引号 大端序
|
||||
SecretFlag byte // 明密标志 0x55 明传 0xAA 密传
|
||||
FrameFlag byte // 帧类型 0x00:智能载荷电箱有效帧 0x55: 智能载荷电箱空帧
|
||||
FileNo byte // 文件编号
|
||||
Reserved1 byte // 保留字节 0x00
|
||||
Data [8176]byte
|
||||
}
|
||||
|
||||
func (t *TransFrame) Decode(frame []byte) {
|
||||
if len(frame) < ImageFrameHeadLength+ImageFrameDataLength {
|
||||
return
|
||||
}
|
||||
copy(t.Header[:], frame[:4])
|
||||
t.SNo = uint32(frame[4])<<24 | uint32(frame[5])<<16 | uint32(frame[6])<<8 | uint32(frame[7])
|
||||
copy(t.Reserved0[:], frame[8:10])
|
||||
t.KeyIndex = uint16(frame[10])<<8 | uint16(frame[11])
|
||||
t.SecretFlag = frame[12]
|
||||
t.FrameFlag = frame[13]
|
||||
t.FileNo = frame[14]
|
||||
t.Reserved1 = frame[15]
|
||||
copy(t.Data[:], frame[16:])
|
||||
}
|
||||
Reference in New Issue
Block a user