No Description

main.go 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/naleek/gortty"
  6. )
  7. type TTYFrame struct {
  8. Seq uint32
  9. Len uint32
  10. Samples []byte
  11. }
  12. func main() {
  13. s := &gortty.ModemSettings{
  14. Baud: 45,
  15. StopBits: 2,
  16. DataBits: 5,
  17. SampleRate: 8000,
  18. OneFreq: 2125,
  19. ZeroFreq: 2295,
  20. }
  21. charset := gortty.LoadCharset(&gortty.USTTY)
  22. encoderIn := make(chan rune)
  23. modulatorIn := make(chan byte)
  24. //demodulatorIn := make(chan int16)
  25. // decoderIn := make(chan byte)
  26. // decoderOut := make(chan rune)
  27. chopperIn := make(chan int16)
  28. chopperOut := make(chan gortty.TimeSlice)
  29. done := make(chan struct{})
  30. //sig := make(chan [2]float64)
  31. encoder := gortty.NewEncoder(encoderIn, modulatorIn, charset)
  32. gortty.NewModulator(s, modulatorIn, chopperIn)
  33. // gortty.NewModulator(s, modulatorIn, demodulatorIn)
  34. //gortty.NewDemodulator(s, demodulatorIn, decoderIn)
  35. // gortty.NewDecoder(decoderIn, decoderOut, charset)
  36. gortty.NewChopper(s, chopperIn, chopperOut)
  37. go func() {
  38. encoder.EncodeString("hello world")
  39. time.Sleep(2000 * time.Millisecond)
  40. done <- struct{}{}
  41. }()
  42. running := true
  43. x := 0
  44. var buff byte
  45. var bits int
  46. for running {
  47. select {
  48. case r := <-chopperOut:
  49. x++
  50. if r.Carrier && x%10==0 {
  51. buff = buff << 1
  52. bits++
  53. if r.Marking {
  54. buff = buff | 0x01
  55. }
  56. if bits == 8 {
  57. fmt.Printf("%x",buff)
  58. bits = 0
  59. buff = 0
  60. }
  61. }
  62. case <-done:
  63. running = false
  64. }
  65. }
  66. }
  67. // // NewOBL is fun
  68. // func NewOBL(baud float64, callback Callback) *OBL {
  69. //
  70. // obl := new(OBL)
  71. //
  72. // obl.charset = USTTY.initialize()
  73. //
  74. // obl.callback = callback
  75. //
  76. // obl.mod.sinLutQ15 = make([]int16, 16384)
  77. // for i := 0; i < 16384; i++ {
  78. // obl.mod.sinLutQ15[i] = int16(32767 * math.Sin(2.0*math.Pi*float64(i)/float64(16384)))
  79. // }
  80. //
  81. // /* regular reset */
  82. // obl.autobaud.enabled = true
  83. // obl.Reset(baud)
  84. //
  85. // go func() {
  86. // portaudio.Initialize()
  87. // defer portaudio.Terminate()
  88. //
  89. // x := make(chan int16, 300)
  90. //
  91. // stream, _ := portaudio.OpenDefaultStream(0, 1, float64(sampleRate), 0, func(out []int16) {
  92. // for i := range out {
  93. // out[i] = <-x
  94. // }
  95. // })
  96. //
  97. // stream.Start()
  98. //
  99. // for {
  100. // s := <-obl.mod.output
  101. // //go func() {
  102. // obl.demod.input <- s
  103. // x <- s
  104. // //}()
  105. // // binary.Write(f, binary.LittleEndian, s)
  106. // }
  107. // }()
  108. //
  109. // go obl.Modulate()
  110. // go obl.Demodulate()
  111. //
  112. // return obl
  113. // }