Merge branch 'master' of https://git.code.tencent.com/beijing-rtss-test/bj-rtsts-server-go
This commit is contained in:
commit
8598553359
4
third_party/message/rssp.go
vendored
4
third_party/message/rssp.go
vendored
@ -72,7 +72,7 @@ func RsspPackCrc16Check(pack []byte) bool {
|
|||||||
// RsspRsd 实时安全数据包
|
// RsspRsd 实时安全数据包
|
||||||
type RsspRsd struct {
|
type RsspRsd struct {
|
||||||
RsspHead
|
RsspHead
|
||||||
//安全校验域-序列号(4Byte)
|
//安全校验域-序列号(4Byte),可以是一个随时间周期变化的计数器
|
||||||
Sn uint32
|
Sn uint32
|
||||||
//安全校验域-安全数据长度(2Byte)
|
//安全校验域-安全数据长度(2Byte)
|
||||||
Sdl uint16
|
Sdl uint16
|
||||||
@ -325,3 +325,5 @@ func PackToString(pack []byte) string {
|
|||||||
}
|
}
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -7,11 +7,15 @@ var crc16Table []uint32 = nil
|
|||||||
var crc32C1Table []uint32 = nil
|
var crc32C1Table []uint32 = nil
|
||||||
var crc32C2Table []uint32 = nil
|
var crc32C2Table []uint32 = nil
|
||||||
|
|
||||||
const (
|
const ( //CRC生成多项式
|
||||||
RsspCrc16GX uint32 = 0b1_0000_1000_0001_0001 //生成多项式 G(X)=X16+X11+X4+1
|
RsspCrc16GX uint32 = 0b1_0000_1000_0001_0001 //生成多项式 G(X)=X16+X11+X4+1
|
||||||
RsspCrc32C1 uint32 = 0x100d4e63 //安全通道1 CRC32生成多项式
|
RsspCrc32C1 uint32 = 0x100d4e63 //安全通道1 CRC32生成多项式
|
||||||
RsspCrc32C2 uint32 = 0x8ce56011 //安全通道1 CRC32生成多项式
|
RsspCrc32C2 uint32 = 0x8ce56011 //安全通道1 CRC32生成多项式
|
||||||
)
|
)
|
||||||
|
const ( //时间戳生成多项式
|
||||||
|
RsspTsC1 uint32 = 0x0fc22f87
|
||||||
|
RsspTsC2 uint32 = 0xc3e887e1
|
||||||
|
)
|
||||||
|
|
||||||
// InitRsspCrcTable 初始化RSSP协议中需要的CRC表
|
// InitRsspCrcTable 初始化RSSP协议中需要的CRC表
|
||||||
func InitRsspCrcTable() {
|
func InitRsspCrcTable() {
|
||||||
@ -193,3 +197,47 @@ func Crc(data []byte,
|
|||||||
}
|
}
|
||||||
return (register1 ^ final_xor_value) & significant_mask
|
return (register1 ^ final_xor_value) & significant_mask
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// 线性反馈移位寄存器
|
||||||
|
type RsspLFSR struct {
|
||||||
|
polynomial uint32 //生成多项式
|
||||||
|
width int //寄存器宽度
|
||||||
|
register uint32 //寄存器
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRsspLFSR(polynomial uint32, width int, init_value uint32) *RsspLFSR {
|
||||||
|
var wd_msb_mask uint32 = 1 << (width - 1)
|
||||||
|
var wd_mask uint32 = 0xffffffff >> (32 - width)
|
||||||
|
polynomial &= wd_mask
|
||||||
|
polynomial = (polynomial >> 1) | wd_msb_mask
|
||||||
|
//
|
||||||
|
return &RsspLFSR{polynomial: polynomial, width: width, register: init_value}
|
||||||
|
}
|
||||||
|
func (r *RsspLFSR) move() {
|
||||||
|
var significant_mask uint32 = 0xffffffff >> (32 - r.width)
|
||||||
|
//
|
||||||
|
r.register &= significant_mask
|
||||||
|
cb := r.register & r.polynomial & significant_mask
|
||||||
|
out := bitXor(cb, r.width)
|
||||||
|
r.register >>= 1
|
||||||
|
r.register = r.register | (out << (r.width - 1))
|
||||||
|
r.register &= significant_mask
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RsspLFSR) GetAndMove() uint32 {
|
||||||
|
rt := r.register
|
||||||
|
r.move()
|
||||||
|
return rt
|
||||||
|
}
|
||||||
|
|
||||||
|
// return 0 或 1
|
||||||
|
func bitXor(data uint32, width int) uint32 {
|
||||||
|
var v uint32 = 0
|
||||||
|
var lsb_mask uint32 = 1
|
||||||
|
for i := 0; i < width; i++ {
|
||||||
|
v ^= data >> i
|
||||||
|
}
|
||||||
|
return v & lsb_mask
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user