Added different levels of debug output

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

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

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

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

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

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

@ -27,6 +27,7 @@ type Config struct {
baud int baud int
debug bool debug bool
messagetype pocsag.MessageType messagetype pocsag.MessageType
verbosity int
} }
func main() { func main() {
@ -39,7 +40,12 @@ func main() {
cli.StringFlag{ cli.StringFlag{
Name: "input,i", Name: "input,i",
Value: "", 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{ cli.IntFlag{
Name: "baud,b", Name: "baud,b",
@ -48,7 +54,7 @@ func main() {
}, },
cli.BoolFlag{ cli.BoolFlag{
Name: "debug", Name: "debug",
Usage: "Debug mode", Usage: "Output debug information",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "type,t", Name: "type,t",
@ -62,11 +68,12 @@ func main() {
input: c.String("input"), input: c.String("input"),
baud: c.Int("baud"), baud: c.Int("baud"),
debug: c.Bool("debug"), debug: c.Bool("debug"),
verbosity: c.Int("verbosity"),
messagetype: pocsag.MessageType(c.String("type")), messagetype: pocsag.MessageType(c.String("type")),
} }
utils.SetDebug(config.debug) utils.SetDebug(config.debug, config.verbosity)
pocsag.SetDebug(config.debug) pocsag.SetDebug(config.debug, config.verbosity)
Run() Run()
@ -79,7 +86,7 @@ func Run() {
var source io.Reader var source io.Reader
if config.input == "-" { if config.input == "-" || config.input == "" {
source = os.Stdin source = os.Stdin
} else { // file reading } else { // file reading
source = pocsag.ReadWav(config.input) source = pocsag.ReadWav(config.input)

Loading…
Cancel
Save