Skip to content

Commit

Permalink
Remove decimation functionality.
Browse files Browse the repository at this point in the history
Builds produced on go1.9.2 and above are efficient enough on RPi3 and friends to
make the decimation functionality obsolete.
  • Loading branch information
bemasher committed Jan 14, 2018
1 parent 50292b1 commit bac8031
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 63 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Available command-line flags are as follows:

```
Usage of rtlamr:
-decimation=1: integer decimation factor, keep every nth sample
-duration=0s: time to run for, 0 for infinite, ex. 1h5m10s
-filterid=: display only messages matching an id in a comma-separated list of ids.
-filtertype=: display only messages matching a type in a comma-separated list of types.
Expand Down
47 changes: 2 additions & 45 deletions decode/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,7 @@ type PacketConfig struct {
CenterFreq uint32
}

func (cfg PacketConfig) Decimate(decimation int) PacketConfig {
cfg.BlockSize /= decimation
cfg.BlockSize2 /= decimation
cfg.ChipLength /= decimation
cfg.SymbolLength /= decimation
cfg.SampleRate /= decimation
cfg.DataRate /= decimation

cfg.PreambleLength /= decimation
cfg.PacketLength /= decimation

cfg.BufferLength /= decimation

return cfg
}

func (d Decoder) Log() {
if d.Decimation != 1 {
log.Printf("BlockSize: %d|%d\n", d.Cfg.BlockSize, d.DecCfg.BlockSize)
log.Println("CenterFreq:", d.Cfg.CenterFreq)
log.Printf("SampleRate: %d|%d\n", d.Cfg.SampleRate, d.DecCfg.SampleRate)
log.Printf("DataRate: %d|%d\n", d.Cfg.DataRate, d.DecCfg.DataRate)
log.Printf("ChipLength: %d|%d\n", d.Cfg.ChipLength, d.DecCfg.ChipLength)
log.Println("PreambleSymbols:", d.Cfg.PreambleSymbols)
log.Printf("PreambleLength: %d|%d\n", d.Cfg.PreambleLength, d.DecCfg.PreambleLength)
log.Println("PacketSymbols:", d.Cfg.PacketSymbols)
log.Printf("PacketLength: %d|%d\n", d.Cfg.PacketLength, d.DecCfg.PacketLength)
log.Println("Preamble:", d.Cfg.Preamble)

if d.Cfg.ChipLength%d.Decimation != 0 {
log.Println("Warning: decimated symbol length is non-integral, sensitivity may be poor")
}

if d.DecCfg.ChipLength < 3 {
log.Fatal("Error: illegal decimation factor, choose a smaller factor")
}

return
}

log.Println("CenterFreq:", d.Cfg.CenterFreq)
log.Println("SampleRate:", d.Cfg.SampleRate)
log.Println("DataRate:", d.Cfg.DataRate)
Expand All @@ -94,8 +55,7 @@ func (d Decoder) Log() {
type Decoder struct {
Cfg PacketConfig

Decimation int
DecCfg PacketConfig
DecCfg PacketConfig

Signal []float64
Filtered []float64
Expand All @@ -113,7 +73,7 @@ type Decoder struct {
}

// Create a new decoder with the given packet configuration.
func NewDecoder(cfg PacketConfig, decimation int) (d Decoder) {
func NewDecoder(cfg PacketConfig) (d Decoder) {
d.Cfg = cfg

d.Cfg.SymbolLength = d.Cfg.ChipLength << 1
Expand All @@ -127,9 +87,6 @@ func NewDecoder(cfg PacketConfig, decimation int) (d Decoder) {

d.Cfg.BufferLength = d.Cfg.PacketLength + d.Cfg.BlockSize

d.Decimation = decimation
d.DecCfg = d.Cfg.Decimate(d.Decimation)

// Allocate necessary buffers.
d.Signal = make([]float64, d.DecCfg.BlockSize+d.DecCfg.SymbolLength)
d.Filtered = make([]float64, d.DecCfg.BlockSize)
Expand Down
3 changes: 0 additions & 3 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ var msgType = flag.String("msgtype", "scm", "message type to receive: scm, scm+,

var symbolLength = flag.Int("symbollength", 72, "symbol length in samples")

var decimation = flag.Int("decimation", 1, "integer decimation factor, keep every nth sample")

var timeLimit = flag.Duration("duration", 0, "time to run for, 0 for infinite, ex. 1h5m10s")
var meterID MeterIDFilter
var meterType MeterTypeFilter
Expand All @@ -64,7 +62,6 @@ func RegisterFlags() {
"samplefile": true,
"msgtype": true,
"symbollength": true,
"decimation": true,
"duration": true,
"filterid": true,
"filtertype": true,
Expand Down
4 changes: 2 additions & 2 deletions idm/idm.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (p *Parser) Cfg() *decode.PacketConfig {
return &p.Decoder.Cfg
}

func NewParser(chipLength, decimation int) (p parse.Parser) {
func NewParser(chipLength int) (p parse.Parser) {
return &Parser{
decode.NewDecoder(NewPacketConfig(chipLength), decimation),
decode.NewDecoder(NewPacketConfig(chipLength)),
crc.NewCRC("CCITT", 0xFFFF, 0x1021, 0x1D0F),
}
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Receiver struct {

func (rcvr *Receiver) NewReceiver() {
var err error
if rcvr.p, err = parse.NewParser(strings.ToLower(*msgType), *symbolLength, *decimation); err != nil {
if rcvr.p, err = parse.NewParser(strings.ToLower(*msgType), *symbolLength); err != nil {
log.Fatal(err)
}

Expand Down
6 changes: 3 additions & 3 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
parsers = make(map[string]NewParserFunc)
)

type NewParserFunc func(symbolLength, decimation int) Parser
type NewParserFunc func(symbolLength int) Parser

func Register(name string, parserFn NewParserFunc) {
parserMutex.Lock()
Expand All @@ -35,12 +35,12 @@ func Register(name string, parserFn NewParserFunc) {
parsers[name] = parserFn
}

func NewParser(name string, symbolLength, decimation int) (Parser, error) {
func NewParser(name string, symbolLength int) (Parser, error) {
parserMutex.Lock()
defer parserMutex.Unlock()

if parserFn, exists := parsers[name]; exists {
return parserFn(symbolLength, decimation), nil
return parserFn(symbolLength), nil
} else {
return nil, fmt.Errorf("invalid message type: %q\n", name)
}
Expand Down
4 changes: 2 additions & 2 deletions r900/r900.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ type Parser struct {
quantized []byte
}

func NewParser(chipLength, decimation int) parse.Parser {
func NewParser(chipLength int) parse.Parser {
p := new(Parser)

p.Decoder = decode.NewDecoder(NewPacketConfig(chipLength), decimation)
p.Decoder = decode.NewDecoder(NewPacketConfig(chipLength))

// GF of order 32, polynomial 37, generator 2.
p.field = gf.NewField(32, 37, 2)
Expand Down
4 changes: 2 additions & 2 deletions r900bcd/r900bcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ type Parser struct {
parse.Parser
}

func NewParser(ChipLength, decimation int) parse.Parser {
return Parser{r900.NewParser(ChipLength, decimation)}
func NewParser(ChipLength int) parse.Parser {
return Parser{r900.NewParser(ChipLength)}
}

// Parse messages using r900 parser and convert consumption from BCD to int.
Expand Down
4 changes: 2 additions & 2 deletions scm/scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ type Parser struct {
crc.CRC
}

func NewParser(chipLength, decimation int) (p parse.Parser) {
func NewParser(chipLength int) (p parse.Parser) {
return &Parser{
decode.NewDecoder(NewPacketConfig(chipLength), decimation),
decode.NewDecoder(NewPacketConfig(chipLength)),
crc.NewCRC("BCH", 0, 0x6F63, 0),
}
}
Expand Down
4 changes: 2 additions & 2 deletions scmplus/scmplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (p *Parser) Cfg() *decode.PacketConfig {
return &p.Decoder.Cfg
}

func NewParser(chipLength, decimation int) (p parse.Parser) {
func NewParser(chipLength int) (p parse.Parser) {
return &Parser{
decode.NewDecoder(NewPacketConfig(chipLength), decimation),
decode.NewDecoder(NewPacketConfig(chipLength)),
crc.NewCRC("CCITT", 0xFFFF, 0x1021, 0x1D0F),
}
}
Expand Down

0 comments on commit bac8031

Please sign in to comment.