forked from lmatte7/meshtastic-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
354 lines (348 loc) · 9.59 KB
/
Copy pathcli.go
File metadata and controls
354 lines (348 loc) · 9.59 KB
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package main
import (
"os"
"github.com/urfave/cli/v2"
)
// Init starts the CLI and determines flags
func Init() {
app := &cli.App{
Name: "meshtastic-go",
Version: "v0.2",
Authors: []*cli.Author{
{
Name: "Lucas Matte",
},
},
Usage: "Interface with meshtastic radios",
Commands: []*cli.Command{
{
Name: "info",
Usage: "Show radio information",
UsageText: "info [command] - Show radio information",
Description: "Show node, preference and channel information for radio",
ArgsUsage: "",
Action: showAllRadioInfo,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "json",
Usage: "Output data in JSON",
Required: false,
},
},
Subcommands: []*cli.Command{
{
Name: "radio",
Aliases: []string{"r"},
Usage: "Show radio information",
Action: showRadioInfo,
},
{
Name: "channels",
Aliases: []string{"c"},
Usage: "Show all channel information",
Action: showChannelInfo,
},
{
Name: "nodes",
Aliases: []string{"n"},
Usage: "Show all nodes on the mesh",
Action: showNodeInfo,
},
{
Name: "position",
Aliases: []string{"p"},
Usage: "Show position settings",
Action: showPositionInfo,
},
{
Name: "metrics",
Aliases: []string{"m"},
Usage: "Display node metrics",
Action: showMetricInfo,
},
},
},
{
Name: "message",
Usage: "Interact with radio messaging functionality",
UsageText: "message [command]",
Description: "Send messages to other radios or wait for new messages",
ArgsUsage: "",
Subcommands: []*cli.Command{
{
Name: "send",
Usage: "Send a text message",
UsageText: "text - Sends a text message to a node",
Description: "Sends a text message to a Node, or to all nodes if no address is provided",
Action: sendText,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "message",
Aliases: []string{"m"},
Usage: "Message to send, must be under 237 characters",
Required: true,
},
&cli.Int64Flag{
Name: "to",
Aliases: []string{"t"},
Usage: "Address to send to. Leave blank for broadcast",
Value: 0,
},
&cli.Int64Flag{
Name: "channel",
Aliases: []string{"c"},
Usage: "Channel to send the message on",
Value: 0,
},
},
},
{
Name: "recv",
Usage: "Wait for new messages",
Description: "Waits for new messages and displays them as received until cancelled. Only shows messages on TEXT_MESSAGE port. Doesn't work over TCP",
Action: getReceivedMessages,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "channel",
Aliases: []string{"c"},
Usage: "Channel to listen for messages on",
Value: 0,
},
&cli.BoolFlag{
Name: "json",
Usage: "Output messages in JSON with a newline between each message",
Required: false,
},
&cli.BoolFlag{
Name: "exit",
Aliases: []string{"e"},
Usage: "Exit after receiving a message from the mesh",
Required: false,
Value: false,
},
},
},
},
},
{
Name: "channel",
Usage: "Update channel information",
UsageText: "channel [command] - Update channel parameters",
Description: "Add, delete and update channel settings",
ArgsUsage: "",
Action: showChannelInfo,
Subcommands: []*cli.Command{
{
Name: "url",
Usage: "Change settings with a url",
UsageText: "url - change settings with url",
Description: "Set channel settings on radio using a meshtastic URL",
Action: setUrl,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "url",
Aliases: []string{"u"},
Usage: "Meshtastic channel URL to use",
Required: true,
},
},
},
{
Name: "add",
Usage: "Adds a channel",
UsageText: "add - Add a channel to the radio",
Description: "Add a channel to the radio with a random PSK",
Action: addChannel,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "index",
Aliases: []string{"i"},
Usage: "Index for the channel to be added. If a channel is added at 0 it will become the Primary channel",
Value: 1,
DefaultText: "1",
Required: true,
},
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "Name of the chanel",
Required: true,
},
},
},
{
Name: "delete",
Usage: "Deletes a channel",
UsageText: "delete - Delete a channel to the radio",
Description: "Delete a channel from the radio. Cannot delete a PRIMARY channel",
Action: deleteChannel,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "index",
Aliases: []string{"i"},
Usage: "Index for the channel to be added. If a channel is added at 0 it will become the Primary channel",
Required: true,
},
},
},
{
Name: "set",
Usage: "Set a channel parameter",
Description: "Sets channel parameters for the specified channel index",
Action: setChannel,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "index",
Aliases: []string{"i"},
Usage: "Index for the channel to be added. If a channel is added at 0 it will become the Primary channel",
Required: true,
Value: 1,
DefaultText: "1",
},
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Key of the channel parameter to be changed",
Required: true,
},
&cli.StringFlag{
Name: "value",
Aliases: []string{"v"},
Usage: "Value of the parameter",
Required: true,
},
},
},
{
Name: "options",
Usage: "Show channel options",
Description: "Show all avaible channel options that can be set",
Action: showChannelOptions,
},
},
},
{
Name: "config",
Usage: "Update radio config",
UsageText: "config [command] - Update radio config",
Description: "Update radio config",
ArgsUsage: "",
Action: showRadioConfig,
Subcommands: []*cli.Command{
{
Name: "set",
Usage: "Set a user preference",
Description: "Sets a user preference using the provided key/value combination",
Action: setConfig,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "key",
Aliases: []string{"k"},
Usage: "Key of the user preferences to be changed",
Required: true,
},
&cli.StringFlag{
Name: "value",
Aliases: []string{"v"},
Usage: "Value of the parameter",
Required: true,
},
},
},
{
Name: "owner",
Usage: "Set the radio owner",
Description: "Sets the owner of the radio that is sent out over the network",
Action: setOwner,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Usage: "The owner name",
Required: true,
},
},
},
},
},
{
Name: "location",
Usage: "Set location",
UsageText: "location [command] - Set location",
Description: "Manually set GPS coordinates using int values for lat, long, and alt",
ArgsUsage: "",
Subcommands: []*cli.Command{
{
Name: "set",
Usage: "Set a location",
Description: "Manually set GPS coordinates using int values for lat, long, and alt",
Action: setLocation,
Flags: []cli.Flag{
&cli.Int64Flag{
Name: "lat",
Usage: "Latitude",
Required: true,
},
&cli.Int64Flag{
Name: "long",
Usage: "Longitude",
Required: true,
},
&cli.IntFlag{
Name: "alt",
Usage: "Altitude",
Required: true,
},
},
},
},
},
{
Name: "reset",
Usage: "Factory reset the radio",
UsageText: "reset - Factory reset the radio",
Description: "Reset the radio to default settings",
ArgsUsage: "",
Action: factoryResetRadio,
},
{
Name: "modem",
Usage: "Set the modem mode",
UsageText: "modem [command] - set modem mode",
Description: "Set the modem mode for the radio",
ArgsUsage: "",
Action: factoryResetRadio,
Subcommands: []*cli.Command{
{
Name: "options",
Usage: "show modem options",
Description: "Show available modem options",
Action: showModemOptions,
},
{
Name: "set",
Usage: "set a modem option",
Description: "Set the modem",
Action: setModemOption,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "option",
Aliases: []string{"o"},
Usage: "The modem option",
Required: true,
},
},
},
},
},
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "port",
Aliases: []string{"p"},
Usage: "specify a port",
},
},
}
app.Run(os.Args)
}