Skip to content

Commit ecd219a

Browse files
committed
add support for lock mode and retrieving the KEYSPD
1 parent e58e862 commit ecd219a

2 files changed

Lines changed: 96 additions & 1 deletion

File tree

pkg/protocol/command.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,16 @@ var (
462462
Long: "set_vfo_opt",
463463
Args: 1,
464464
},
465+
{
466+
Short: 0xa2,
467+
Long: "set_lock_mode",
468+
Args: 1,
469+
},
470+
{
471+
Short: 0xa3,
472+
Long: "get_lock_mode",
473+
Cacheable: true,
474+
},
465475
{
466476
Short: 0xf1,
467477
Long: "halt",

pkg/protocol/response.go

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,74 @@
11
package protocol
22

3-
import "strconv"
3+
import (
4+
"strconv"
5+
)
6+
7+
type HamlibError string
8+
9+
func (e HamlibError) Error() string {
10+
message, ok := HamlibErrorMessages[string(e)]
11+
if ok {
12+
return message
13+
}
14+
return "unknown hamlib error: " + string(e)
15+
}
16+
17+
const (
18+
InvalidParameter HamlibError = "-1"
19+
InvalidConfiguration HamlibError = "-2"
20+
MemoryShortage HamlibError = "-3"
21+
FeatureNotImplemented HamlibError = "-4"
22+
CommunicationTimedOut HamlibError = "-5"
23+
IOError HamlibError = "-6"
24+
InternalHamlibError HamlibError = "-7"
25+
ProtocolError HamlibError = "-8"
26+
CommandRejectedByTheRig HamlibError = "-9"
27+
CommandPerformedButTruncated HamlibError = "-10"
28+
FeatureNotAvailable HamlibError = "-11"
29+
TargetVFOUnaccessible HamlibError = "-12"
30+
CommunicationBusError HamlibError = "-13"
31+
CommunicationBusCollision HamlibError = "-14"
32+
NullRigHandle HamlibError = "-15"
33+
InvalidVFO HamlibError = "-16"
34+
ArgumentOutOfDomain HamlibError = "-17"
35+
FunctionDeprecated HamlibError = "-18"
36+
SecurityError HamlibError = "-19"
37+
RigNotPoweredOn HamlibError = "-20"
38+
)
39+
40+
var HamlibErrorMessages = map[string]string{
41+
"0": "Command completed successfully",
42+
"-1": "Invalid parameter",
43+
"-2": "Invalid configuration",
44+
"-3": "Memory shortage",
45+
"-4": "Feature not implemented",
46+
"-5": "Communication timed out",
47+
"-6": "IO error",
48+
"-7": "Internal Hamlib error",
49+
"-8": "Protocol error",
50+
"-9": "Command rejected by the rig",
51+
"-10": "Command performed, but arg truncated, result not guaranteed",
52+
"-11": "Feature not available",
53+
"-12": "Target VFO unaccessible",
54+
"-13": "Communication bus error",
55+
"-14": "Communication bus collision",
56+
"-15": "NULL RIG handle or invalid pointer parameter",
57+
"-16": "Invalid VFO",
58+
"-17": "Argument out of domain of func",
59+
"-18": "Function deprecated",
60+
"-19": "Security error password not provided or crypto failure",
61+
"-20": "Rig is not powered on",
62+
}
463

564
func OKResponse(cmd CommandKey) Response {
665
return Response{Command: cmd, Result: "0"}
766
}
867

68+
func ErrorResponse(cmd CommandKey, err HamlibError) Response {
69+
return Response{Command: cmd, Result: string(err)}
70+
}
71+
972
func GetFreqResponse(frequency int) Response {
1073
return Response{
1174
Command: "get_freq",
@@ -77,6 +140,28 @@ func GetPTTResponse(enabled bool) Response {
77140
}
78141
}
79142

143+
func GetLevelKeyspdResponse(wpm int) Response {
144+
return Response{
145+
Command: "get_level_keyspd",
146+
Data: []string{strconv.Itoa(wpm)},
147+
Keys: []string{"KEYSPD"},
148+
Result: "0",
149+
}
150+
}
151+
152+
func GetLockModeResponse(enabled bool) Response {
153+
lockModeEnabled := "0"
154+
if enabled {
155+
lockModeEnabled = "1"
156+
}
157+
return Response{
158+
Command: "get_lock_mode",
159+
Data: []string{lockModeEnabled},
160+
Keys: []string{"Locked"},
161+
Result: "0",
162+
}
163+
}
164+
80165
var NoResponse = Response{}
81166

82167
var ChkVFOResponse = Response{

0 commit comments

Comments
 (0)