Skip to content

Instantly share code, notes, and snippets.

@bemasher
Last active October 5, 2017 00:11
Show Gist options
  • Save bemasher/3b80133d977d3ab7cb5ea9f2df714788 to your computer and use it in GitHub Desktop.
Save bemasher/3b80133d977d3ab7cb5ea9f2df714788 to your computer and use it in GitHub Desktop.
package offline
import (
"io"
"log"
"math/rand"
"os"
"testing"
"time"
"github.com/bemasher/rtlamr/parse"
_ "github.com/bemasher/rtlamr/idm"
_ "github.com/bemasher/rtlamr/r900"
_ "github.com/bemasher/rtlamr/r900bcd"
_ "github.com/bemasher/rtlamr/scm"
_ "github.com/bemasher/rtlamr/scmplus"
)
const (
SampleRate = 2359296
DataRate = 32768
SymbolLength = SampleRate / DataRate
SampleFilename = "samples.bin"
)
func init() {
log.SetFlags(log.Lshortfile)
rand.Seed(time.Now().UnixNano())
}
func TestDecode(t *testing.T) {
for _, msgType := range []string{"scm", "scm+", "idm", "r900", "r900bcd"} {
func() {
log.Printf("Decoding %q messages...", msgType)
inputFile, err := os.Open(SampleFilename)
if err != nil {
t.Fatal(err)
}
defer inputFile.Close()
p, err := parse.NewParser(msgType, SymbolLength, 1)
if err != nil {
log.Fatal(err)
}
block := make([]byte, p.Cfg().BlockSize2)
atEof := false
for !atEof {
// Read new sample block.
_, err := inputFile.Read(block)
atEof = err == io.EOF
if err != nil && !atEof {
t.Fatal("Error reading samples: ", err)
}
offset, _ := inputFile.Seek(0, os.SEEK_CUR)
indices := p.Dec().Decode(block)
for _, pkt := range p.Parse(indices) {
t.Logf("%9d %+v\n", uint64(offset)>>1, pkt)
}
}
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment