Added different levels of debug output

master
David Högborg 9 years ago
parent 6dab423eef
commit 99117bef4a

@ -6,6 +6,7 @@ import (
var (
DEBUG bool
LEVEL int
)
var (
@ -15,6 +16,7 @@ var (
)
// Tell the package to print debug data
func SetDebug(d bool) {
func SetDebug(d bool, verbosity int) {
DEBUG = d
LEVEL = verbosity
}

@ -18,10 +18,11 @@ func ReadWav(path string) *bytes.Buffer {
return nil
}
if DEBUG {
samplecount := int(wavdata.Subchunk2Size / uint32(wavdata.BitsPerSample/8))
seconds := float32(samplecount) / float32(wavdata.SampleRate)
if DEBUG {
fmt.Printf("Samplerate: %d\n", wavdata.SampleRate)
fmt.Printf("Samples: %d\n", samplecount)
fmt.Printf("Seconds: %0.3f\n", seconds)
}

@ -46,7 +46,7 @@ func ParsePOCSAG(bits []datatypes.Bit, messagetype MessageType) {
return
}
if DEBUG {
if DEBUG && LEVEL > 1 {
for i, batch := range batches {
println("")
println("Batch: ", i)
@ -96,7 +96,7 @@ func (p *POCSAG) ParseBatches(bits []datatypes.Bit) ([]*Batch, error) {
batchbits := bits[a : a+POCSAG_BATCH_LEN+32]
stream := utils.MSBBitsToBytes(batchbits, 8)
if DEBUG {
if DEBUG && LEVEL > 2 {
out, err := os.Create(fmt.Sprintf("batches/batch-%d.bin", batchno))
if err != nil {
return nil, err

@ -55,10 +55,13 @@ func (s *StreamReader) StartScan(bitstream chan []datatypes.Bit) {
transmission := s.ReadTransmission(stream[start:])
bits := utils.StreamToBits(transmission, bitlength)
bitstream <- bits
if DEBUG && LEVEL > 2 {
utils.PrintBitstream(bits)
}
time.Sleep(3 * time.Millisecond)
bitstream <- bits
}
}
}
@ -81,6 +84,10 @@ func (s *StreamReader) ReadTransmission(beginning []int16) []int16 {
stream = append(stream, bstr...)
if s.isNoise(bstr) {
if DEBUG && LEVEL > 1 {
print("\n")
println("Transmission end (high noise level)")
}
break
}
}
@ -223,7 +230,13 @@ func (s *StreamReader) isNoise(stream []int16) bool {
prevsamp = sample
}
return switches > 100
switchrate := float32(switches) / float32(len(stream))
if DEBUG && LEVEL > 1 {
fmt.Printf("%0.0f ", switchrate*100)
}
return switchrate > 0.15
}
// bToInt16 converts bytes to int16

@ -10,6 +10,7 @@ import (
var (
DEBUG bool
LEVEL int
)
var (
@ -18,8 +19,10 @@ var (
blue = color.New(color.FgBlue)
)
func SetDebug(d bool) {
// Tell the package to print debug data
func SetDebug(d bool, verbosity int) {
DEBUG = d
LEVEL = verbosity
}
// StreamToBits converts samples to bits using the bitlength specified.
@ -182,6 +185,7 @@ func PrintStream(samples []int16) {
for _, sample := range samples {
PrintSample(sample)
}
println("")
}
// PrintBitstream, used for debugging of streams
@ -189,6 +193,7 @@ func PrintBitstream(bits []datatypes.Bit) {
for _, b := range bits {
PrintSample(int16(b.Int()))
}
println("")
}
// PrintSample, used for debugging of streams

@ -27,6 +27,7 @@ type Config struct {
baud int
debug bool
messagetype pocsag.MessageType
verbosity int
}
func main() {
@ -39,7 +40,12 @@ func main() {
cli.StringFlag{
Name: "input,i",
Value: "",
Usage: "wav file or data dump with signed 16 bit ints",
Usage: "wav file with signed 16 bit ints, - for sttdin",
},
cli.IntFlag{
Name: "verbosity",
Value: 0,
Usage: "Verbosity level, 0 lowest level",
},
cli.IntFlag{
Name: "baud,b",
@ -48,7 +54,7 @@ func main() {
},
cli.BoolFlag{
Name: "debug",
Usage: "Debug mode",
Usage: "Output debug information",
},
cli.StringFlag{
Name: "type,t",
@ -62,11 +68,12 @@ func main() {
input: c.String("input"),
baud: c.Int("baud"),
debug: c.Bool("debug"),
verbosity: c.Int("verbosity"),
messagetype: pocsag.MessageType(c.String("type")),
}
utils.SetDebug(config.debug)
pocsag.SetDebug(config.debug)
utils.SetDebug(config.debug, config.verbosity)
pocsag.SetDebug(config.debug, config.verbosity)
Run()
@ -79,7 +86,7 @@ func Run() {
var source io.Reader
if config.input == "-" {
if config.input == "-" || config.input == "" {
source = os.Stdin
} else { // file reading
source = pocsag.ReadWav(config.input)

Loading…
Cancel
Save