func TestNewRandSCM(t *testing.T) { bch := crc.NewCRC("BCH", 0, 0x6F63, 0) for i := 0; i < 512; i++ { scm, err := NewRandSCM() if err != nil { t.Fatal(err) } checksum := bch.Checksum(scm[2:]) if checksum != 0 { t.Fatalf("Failed checksum: %04X\n", checksum) } } }
func NewRandSCM() (pkt []byte, err error) { bch := crc.NewCRC("BCH", 0, 0x6F63, 0) pkt = make([]byte, 12) _, err = rand.Read(pkt) if err != nil { return nil, err } pkt[0] = 0xF9 pkt[1] = 0x53 pkt[2] &= 0x07 checksum := bch.Checksum(pkt[2:10]) pkt[10] = uint8(checksum >> 8) pkt[11] = uint8(checksum & 0xFF) return }
func NewParser(symbolLength, decimation int, fastMag bool) (p Parser) { p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation, fastMag) p.CRC = crc.NewCRC("BCH", 0, 0x6F63, 0) return }
func NewParser(symbolLength int, fastMag bool) (p Parser) { p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), fastMag) p.CRC = crc.NewCRC("CCITT", 0xFFFF, 0x1021, 0x1D0F) return }
func NewParser(chipLength, decimation int) (p parse.Parser) { return &Parser{ decode.NewDecoder(NewPacketConfig(chipLength), decimation), crc.NewCRC("BCH", 0, 0x6F63, 0), } }
func NewParser(symbolLength, decimation int) (p parse.Parser) { return &Parser{ decode.NewDecoder(NewPacketConfig(symbolLength), decimation), crc.NewCRC("CCITT", 0xFFFF, 0x1021, 0x1D0F), } }
func NewParser(symbolLength, decimation int) (p Parser) { p.Decoder = decode.NewDecoder(NewPacketConfig(symbolLength), decimation) p.CRC = crc.NewCRC("CCITT", 0xFFFF, 0x1021, 0x1D0F) return }