-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.go
207 lines (188 loc) · 4.67 KB
/
response.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
204
205
206
207
package protocol
import (
"strconv"
)
type HamlibError string
func (e HamlibError) Error() string {
message, ok := HamlibErrorMessages[string(e)]
if ok {
return message
}
return "unknown hamlib error: " + string(e)
}
const (
InvalidParameter HamlibError = "-1"
InvalidConfiguration HamlibError = "-2"
MemoryShortage HamlibError = "-3"
FeatureNotImplemented HamlibError = "-4"
CommunicationTimedOut HamlibError = "-5"
IOError HamlibError = "-6"
InternalHamlibError HamlibError = "-7"
ProtocolError HamlibError = "-8"
CommandRejectedByTheRig HamlibError = "-9"
CommandPerformedButTruncated HamlibError = "-10"
FeatureNotAvailable HamlibError = "-11"
TargetVFOUnaccessible HamlibError = "-12"
CommunicationBusError HamlibError = "-13"
CommunicationBusCollision HamlibError = "-14"
NullRigHandle HamlibError = "-15"
InvalidVFO HamlibError = "-16"
ArgumentOutOfDomain HamlibError = "-17"
FunctionDeprecated HamlibError = "-18"
SecurityError HamlibError = "-19"
RigNotPoweredOn HamlibError = "-20"
)
var HamlibErrorMessages = map[string]string{
"0": "Command completed successfully",
"-1": "Invalid parameter",
"-2": "Invalid configuration",
"-3": "Memory shortage",
"-4": "Feature not implemented",
"-5": "Communication timed out",
"-6": "IO error",
"-7": "Internal Hamlib error",
"-8": "Protocol error",
"-9": "Command rejected by the rig",
"-10": "Command performed, but arg truncated, result not guaranteed",
"-11": "Feature not available",
"-12": "Target VFO unaccessible",
"-13": "Communication bus error",
"-14": "Communication bus collision",
"-15": "NULL RIG handle or invalid pointer parameter",
"-16": "Invalid VFO",
"-17": "Argument out of domain of func",
"-18": "Function deprecated",
"-19": "Security error password not provided or crypto failure",
"-20": "Rig is not powered on",
}
func OKResponse(cmd CommandKey) Response {
return Response{Command: cmd, Result: "0"}
}
func ErrorResponse(cmd CommandKey, err HamlibError) Response {
return Response{Command: cmd, Result: string(err)}
}
func GetFreqResponse(frequency int) Response {
return Response{
Command: "get_freq",
Data: []string{strconv.Itoa(frequency)},
Keys: []string{"Frequency"},
Result: "0",
}
}
func GetVFOResponse(vfo string) Response {
return Response{
Command: "get_vfo",
Data: []string{vfo},
Keys: []string{"VFO"},
Result: "0",
}
}
func GetModeResponse(mode string, passband int) Response {
return Response{
Command: "get_mode",
Data: []string{mode, strconv.Itoa(passband)},
Keys: []string{"Mode", "Passband"},
Result: "0",
}
}
func GetSplitFreqResponse(frequency int) Response {
return Response{
Command: "get_split_freq",
Data: []string{strconv.Itoa(frequency)},
Keys: []string{"TX Frequency"},
Result: "0",
}
}
func GetSplitVFOResponse(enabled bool, txVFO string) Response {
splitEnabled := "0"
if enabled {
splitEnabled = "1"
}
return Response{
Command: "get_split_vfo",
Data: []string{splitEnabled, txVFO},
Keys: []string{"Split", "TX VFO"},
Result: "0",
}
}
func GetSplitModeResponse(mode string, passband int) Response {
return Response{
Command: "get_split_mode",
Data: []string{mode, strconv.Itoa(passband)},
Keys: []string{"TX Mode", "TX Passband"},
Result: "0",
}
}
func GetPTTResponse(enabled bool) Response {
pttEnabled := "0"
if enabled {
pttEnabled = "1"
}
return Response{
Command: "get_ptt",
Data: []string{pttEnabled},
Keys: []string{"PTT"},
Result: "0",
}
}
func GetLevelKeyspdResponse(wpm int) Response {
return Response{
Command: "get_level_keyspd",
Data: []string{strconv.Itoa(wpm)},
Keys: []string{"KEYSPD"},
Result: "0",
}
}
func GetLockModeResponse(enabled bool) Response {
lockModeEnabled := "0"
if enabled {
lockModeEnabled = "1"
}
return Response{
Command: "get_lock_mode",
Data: []string{lockModeEnabled},
Keys: []string{"Locked"},
Result: "0",
}
}
var NoResponse = Response{}
var ChkVFOResponse = Response{
Command: "chk_vfo",
Data: []string{"0"},
Keys: []string{""},
Result: "0",
}
var DumpStateResponse = Response{
Command: "dump_state",
Data: []string{`0
1
2
150000.000000 1500000000.000000 0x1ff -1 -1 0x10000003 0x3
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0x1ff 1
0x1ff 0
0 0
0x1e 2400
0x2 500
0x1 8000
0x1 2400
0x20 15000
0x20 8000
0x40 230000
0 0
9990
9990
10000
0
10
10 20 30
0xffffffffffffffff
0xffffffffffffffff
0xfffffffff7ffffff
0xffffffff83ffffff
0xffffffffffffffff
0xffffffffffffffbf
`},
Result: "0",
}