crc12

package
v1.0.10006 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const Size = 2

大小

Variables

View Source
var (
	// "CRC-12"
	CRC12 = Params{0x180D, 0x0000, false, false, 0x0000}
)

类型列表

Functions

func Checksum

func Checksum(data []byte, params Params) uint16

生成

func ChecksumCRC12

func ChecksumCRC12(data []byte) uint16

生成 CRC12 31303432 => 3CD

func ToBinString

func ToBinString(data uint16) string

输出二进制字符

func ToHexString

func ToHexString(data uint16) string

输出 16 进制字符

func ToHexStringFromBytes added in v1.0.10005

func ToHexStringFromBytes(data []byte) string

输出 16 进制字符

Types

type CRC added in v1.0.10006

type CRC struct {
	// contains filtered or unexported fields
}

表格

func NewCRC added in v1.0.10006

func NewCRC(params ...Params) *CRC

构造函数

func NewCRC12

func NewCRC12(params ...Params) *CRC

构造函数

func (*CRC) Checksum added in v1.0.10006

func (this *CRC) Checksum(data []byte) uint16

Checksum LSB-MSB,即低字节在前 Modbus,即高字节在前

func (*CRC) Complete added in v1.0.10006

func (this *CRC) Complete(crc uint16) uint16

完成

func (*CRC) GetParams added in v1.0.10006

func (this *CRC) GetParams() Params

获取参数

func (*CRC) GetTable added in v1.0.10006

func (this *CRC) GetTable() [256]uint16

获取数据

func (*CRC) Init added in v1.0.10006

func (this *CRC) Init() uint16

初始值

func (*CRC) MakeTable added in v1.0.10006

func (this *CRC) MakeTable() *CRC

生成数值

func (*CRC) Update added in v1.0.10006

func (this *CRC) Update(crc uint16, data []byte) uint16

更新

func (*CRC) WithParams added in v1.0.10006

func (this *CRC) WithParams(params Params) *CRC

设置参数

func (*CRC) WithTable added in v1.0.10006

func (this *CRC) WithTable(table [256]uint16) *CRC

设置数据

type Hash12

type Hash12 interface {
	hash.Hash
	Sum12() uint16
}

hash

func NewCRC12Hash

func NewCRC12Hash(params Params) Hash12

Hash

func NewHash

func NewHash(crc *CRC) Hash12

构造函数

type Params

type Params struct {
	// 生成项的简写,以16进制表示。
	// 例如:CRC-32 即是0x04C11DB7,
	// 忽略了最高位的"1",即完整的生成项是0x104C11DB7。
	Poly uint16

	// 这是算法开始时寄存器(crc)的初始化预置值,十六进制表示。
	Init uint16

	// 待测数据的每个字节是否按位反转,True或False。
	RefIn bool

	// 在计算后之后,异或输出之前,整个数据是否按位反转,True或False。
	RefOut bool

	// 计算结果与此参数异或后得到最终的CRC值。
	XorOut uint16
}

参数 NAME:参数模型名称。 WIDTH:宽度,即CRC比特数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL