Skip to content

Commit

Permalink
Simplify symbol decoding process.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasher committed Jan 23, 2015
1 parent 57e1be9 commit a88bbf1
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions r900/r900.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"math"
"strconv"

"github.com/bemasher/rtlamr/r900/gf"

"github.com/bemasher/gf"
"github.com/bemasher/rtlamr/decode"
"github.com/bemasher/rtlamr/parse"
)
Expand Down Expand Up @@ -172,39 +171,37 @@ func (p Parser) Parse(indices []int) (msgs []parse.Message) {

preambleLength := p.Decoder.Cfg.PreambleLength
symbolLength := p.Decoder.Cfg.SymbolLength

symbols := make([]byte, 21)
zeros := make([]byte, 5)

seen := make(map[string]bool)

for _, preambleIdx := range indices {
if preambleIdx > p.Decoder.Cfg.BlockSize {
break
}

payloadIdx := preambleIdx + preambleLength
var (
symbol string
bits string
symbols [21]byte
badSymbol bool
symbolIdx int
)
var digits string
for idx := 0; idx < PayloadSymbols*4*p.Decoder.Cfg.SymbolLength; idx += symbolLength * 4 {
qIdx := payloadIdx + idx

symbol += strconv.FormatInt(int64(p.quantized[qIdx]), 10)
if len(symbol) > 1 {
n, _ := strconv.ParseInt(symbol, 6, 64)
symbol = ""

bits += fmt.Sprintf("%05b", n)
digits += strconv.Itoa(int(p.quantized[qIdx]))
}

if n > 31 {
badSymbol = true
break
}
symbols[symbolIdx] = byte(n)
symbolIdx++
var (
bits string
badSymbol bool
)
for idx := 0; idx < len(digits); idx += 2 {
symbol, _ := strconv.ParseInt(digits[idx:idx+2], 6, 32)
if symbol > 31 {
badSymbol = true
break
}
symbols[idx>>1] = byte(symbol)
bits += fmt.Sprintf("%05b", symbol)
}

if badSymbol || seen[bits] {
Expand Down

0 comments on commit a88bbf1

Please sign in to comment.