Browse Source

fiddling with filter

Keelan Lightfoot 7 years ago
parent
commit
6f7c154134
1 changed files with 58 additions and 37 deletions
  1. 58
    37
      examples/main.go

+ 58
- 37
examples/main.go View File

@@ -2,18 +2,19 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-	"time"
6 5
 
7 6
 	"github.com/naleek/openbaudot"
8 7
 )
9 8
 
10 9
 func main() {
11 10
 
12
-	s := openbaudot.ModemSettings{
13
-		Baud:       45.45,
11
+	s := &openbaudot.ModemSettings{
12
+		Baud:       45,
14 13
 		StopBits:   2,
15 14
 		DataBits:   5,
16 15
 		SampleRate: 8000,
16
+		OneFreq:    2125,
17
+		ZeroFreq:   2295,
17 18
 	}
18 19
 
19 20
 	charset := openbaudot.LoadCharset(&openbaudot.USTTY)
@@ -21,46 +22,66 @@ func main() {
21 22
 	encoderIn := make(chan rune)
22 23
 	modulatorIn := make(chan byte)
23 24
 	modulatorOut := make(chan int16)
24
-	demodulatorIn := make(chan int16)
25
-	decoderIn := make(chan byte)
26
-	decoderOut := make(chan rune)
27 25
 
28
-	done := make(chan struct{})
26
+	// demodulatorIn := make(chan int16)
27
+	// decoderIn := make(chan byte)
28
+	// decoderOut := make(chan rune)
29 29
 
30
-	encoder := openbaudot.NewEncoder(encoderIn, modulatorIn, charset)
31
-	modulator := openbaudot.NewModulator(s, modulatorIn, modulatorOut)
32
-
33
-	callback := func(event int, data interface{}) {
34
-		switch event {
35
-		case openbaudot.EventIdle:
36
-			fmt.Println("EventIdle")
37
-			encoder.EncodeString("Hello World")
30
+	//done := make(chan struct{})
38 31
 
32
+	sig := make(chan int)
33
+	encoder := openbaudot.NewEncoder(encoderIn, modulatorIn, charset)
34
+	openbaudot.NewModulator(s, modulatorIn, modulatorOut)
35
+	openbaudot.NewDumbDemodulator(s, modulatorOut, sig)
36
+
37
+	// go func() {
38
+	// 	for b := range modulatorOut {
39
+	// 		demodulatorIn <- b
40
+	// 		time.Sleep(125 * time.Microsecond)
41
+	// 	}
42
+	// }()
43
+
44
+	// callback := func(event int, data interface{}) {
45
+	// 	switch event {
46
+	// 	case openbaudot.EventIdle:
47
+	// 		//fmt.Println("EventIdle")
48
+	// 		encoder.EncodeString("r")
49
+	//
50
+	// 	}
51
+	//
52
+	// }
53
+	go encoder.EncodeString("ry")
54
+	c := 0
55
+	for b := range sig {
56
+
57
+		fmt.Println(b)
58
+		if c == s.SampleRate {
59
+			break
39 60
 		}
40
-
61
+		c++
41 62
 	}
42 63
 
43
-	modulator.SetCallback(callback)
44
-
45
-	go func() {
46
-		for b := range modulatorOut {
47
-			demodulatorIn <- b
48
-			time.Sleep(125 * time.Microsecond)
49
-		}
50
-	}()
51
-
52
-	openbaudot.NewDemodulator(s, demodulatorIn, decoderIn)
53
-	openbaudot.NewDecoder(decoderIn, decoderOut, charset)
54
-
55
-	running := true
56
-	for running {
57
-		select {
58
-		case r := <-decoderOut:
59
-			fmt.Printf("%c", r)
60
-		case <-done:
61
-			running = false
62
-		}
63
-	}
64
+	// modulator.SetCallback(callback)
65
+
66
+	// go func() {
67
+	// 	for b := range modulatorOut {
68
+	// 		demodulatorIn <- b
69
+	// 		time.Sleep(125 * time.Microsecond)
70
+	// 	}
71
+	// }()
72
+
73
+	// openbaudot.NewDemodulator(s, demodulatorIn, decoderIn)
74
+	// openbaudot.NewDecoder(decoderIn, decoderOut, charset)
75
+	//
76
+	// running := true
77
+	// for running {
78
+	// 	select {
79
+	// 	case r := <-decoderOut:
80
+	// 		fmt.Printf("%c", r)
81
+	// 	case <-done:
82
+	// 		running = false
83
+	// 	}
84
+	// }
64 85
 }
65 86
 
66 87
 // // NewOBL is fun