-
Notifications
You must be signed in to change notification settings - Fork 1
/
protocol.go
203 lines (171 loc) · 3.97 KB
/
protocol.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package protocol
import (
"encoding/binary"
"fmt"
)
func (v *VersionData) AsString() string {
return fmt.Sprintf("%d.%d - %08x", v.Major, v.Minor, v.Hash)
}
func (v *VersionData) ToUint64() uint64 {
return GenProtocolVersion(*v)
}
func GenProtocolVersion(version VersionData) uint64 {
return uint64(((uint64(version.Major)) << 40) | ((uint64(version.Minor)) << 32) | (uint64(version.Hash)))
}
func SplitProtocolVersion(protocol uint64) VersionData {
major := uint32(((protocol & (0xFF << 40)) >> 40) & 0xFF)
minor := uint32(((protocol & (0xFF << 32)) >> 32) & 0xFF)
hash := uint32(protocol & 0xFFFFFFFF)
return VersionData{
Major: major,
Minor: minor,
Hash: hash,
}
}
var CurrentProtocolVersion = VersionData{
Major: 0,
Minor: 1,
Hash: 0,
}
const DefaultPort = 4050
// region Internal States
const (
GettingHeader = iota
ReadingData
)
// endregion
const (
Invalid = iota
OK
Error
)
// DeviceIds IDs
const (
DeviceInvalid = iota
DeviceTestSignal
DeviceAirspyOne
DeviceAirspyHf
DeviceRtlsdr
DeviceLimeSDRUSB
DeviceLimeSDRMini
DeviceSpyServer
DeviceHackRF
)
const (
TypeNone = iota
TypeDeviceInfo
TypeClientSync
TypePong
TypeReadSetting
TypeIQ
TypeSmartIQ
TypeCombined
TypeCommand
)
const (
CmdHello = 0
CmdGetSetting = 1
CmdSetSetting = 2
CmdPing = 3
)
const (
SettingStreamingMode = iota
SettingStreamingEnabled
SettingGains
SettingIqFrequency
SettingIqDecimation
SettingDigitalGain
SettingSmartFrequency
SettingSmartDecimation
)
// DeviceNames names of the device
const (
DeviceInvalidName = "Invalid Device"
DeviceTestSignalName = "Test Signal Generator"
DeviceAirspyOneName = "Airspy Mini / R2"
DeviceAirspyHFName = "Airspy HF / HF+"
DeviceRtlsdrName = "RTLSDR"
DeviceLimeSDRUSBName = "LimeSDR USB"
DeviceLimeSDRMiniName = "LimeSDR Mini"
DeviceHackRFName = "HackRF"
DeviceSpyserverName = "SpyServer"
)
// DeviceName list of device names by their ids
var DeviceName = map[uint32]string{
DeviceInvalid: DeviceInvalidName,
DeviceTestSignal: DeviceTestSignalName,
DeviceAirspyOne: DeviceAirspyOneName,
DeviceAirspyHf: DeviceAirspyHFName,
DeviceRtlsdr: DeviceRtlsdrName,
DeviceLimeSDRUSB: DeviceLimeSDRUSBName,
DeviceLimeSDRMini: DeviceLimeSDRMiniName,
DeviceHackRF: DeviceHackRFName,
DeviceSpyServer: DeviceSpyserverName,
}
// SettingNames list of device names by their ids
var SettingNames = map[uint32]string{
SettingStreamingMode: "Streaming Mode",
SettingStreamingEnabled: "Streaming Enabled",
SettingGains: "Gain",
SettingDigitalGain: "Digital Gain",
SettingIqFrequency: "IQ Frequency",
SettingIqDecimation: "IQ Decimation",
SettingSmartFrequency: "Smart Frequency",
SettingSmartDecimation: "Smart Decimation",
}
var PossibleSettings = []uint32{
SettingStreamingMode,
SettingStreamingEnabled,
SettingGains,
SettingDigitalGain,
SettingIqFrequency,
SettingIqDecimation,
SettingSmartFrequency,
SettingSmartDecimation,
}
var GlobalAffectedSettings = []uint32{
SettingGains,
}
func IsSettingPossible(setting uint32) bool {
for _, v := range PossibleSettings {
if setting == v {
return true
}
}
return false
}
func SettingAffectsGlobal(setting uint32) bool {
for _, v := range GlobalAffectedSettings {
if setting == v {
return true
}
}
return false
}
type MessageHeader struct {
PacketNumber uint32
ProtocolVersion uint64
MessageType uint32
Reserved uint32
BodySize uint32
}
type ClientSync struct {
AllowControl uint32
Gains [3]uint32
DeviceCenterFrequency uint32
IQCenterFrequency uint32
SmartCenterFrequency uint32
MinimumIQCenterFrequency uint32
MaximumIQCenterFrequency uint32
MinimumSmartFrequency uint32
MaximumSmartFrequency uint32
}
type PingPacket struct {
Timestamp int64
}
type ReadSettingPacket struct {
Setting uint32
BodySize uint32
}
var MessageHeaderSize = uint32(binary.Size(MessageHeader{}))
const MaxMessageBodySize = 1 << 20