-
Notifications
You must be signed in to change notification settings - Fork 8
/
helpers.go
93 lines (78 loc) · 1.72 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"math"
)
type jsonUint8s []uint8
func (u jsonUint8s) MarshalJSON() ([]byte, error) {
buf := bytes.NewBufferString("")
enc := base64.NewEncoder(base64.StdEncoding, buf)
_, err := enc.Write(u)
if err != nil {
panic(err)
}
enc.Close()
return json.Marshal(buf.String())
}
//type jsonInt16s []int16
//
//func (u jsonInt16s) MarshalJSON() ([]byte, error) {
// var result string
// if u == nil {
// result = "null"
// } else {
// result = strings.Join(strings.Fields(fmt.Sprintf("%d", u)), ",")
// }
// return []byte(result), nil
//}
type fftMessage struct {
MessageType string
DemodOutputLevel float32
FFTData jsonUint8s
}
type dataMessage struct {
MessageType string
Data interface{}
}
type deviceMessage struct {
MessageType string
DeviceName string
DisplayBandwidth uint32
DisplayCenterFrequency uint32
DisplayOffset int32
DisplayRange int32
DisplayPixels uint32
ChannelCenterFrequency uint32
CurrentSampleRate uint32
Gain uint32
OutputRate uint32
FilterBandwidth uint32
DemodulatorMode string
DemodulatorParams interface{}
StationName string
WebCanControl bool
TCPCanControl bool
IsMuted bool
}
func makeFFTMessage(data []uint8, level float32) fftMessage {
if math.IsInf(float64(level), 0) {
level = 0
}
return fftMessage{
MessageType: "fft",
DemodOutputLevel: level,
FFTData: data,
}
}
func makeDataMessage(data interface{}) dataMessage {
return dataMessage{
MessageType: "data",
Data: data,
}
}
func makeDeviceMessage(d deviceMessage) deviceMessage {
d.MessageType = "device"
return d
}