forked from OpenIPC/PixelPilot_rk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgsmenu.sh
More file actions
executable file
·674 lines (640 loc) · 24.4 KB
/
gsmenu.sh
File metadata and controls
executable file
·674 lines (640 loc) · 24.4 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/bin/bash
set -o pipefail
# Configuration
REMOTE_IP="10.5.0.10"
SSH_PASS="12345"
CACHE_DIR="/tmp/gsmenu_cache"
CACHE_TTL=10 # seconds
MAJESTIC_YAML="/etc/majestic.yaml"
WFB_YAML="/etc/wfb.yaml"
PRESET_DIR="/etc/presets"
# SSH command setup
SSH="timeout -k 1 11 sshpass -p $SSH_PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/run/ssh_control:%h:%p:%r -o ControlPersist=15s -o ServerAliveInterval=3 -o ServerAliveCountMax=2 root@$REMOTE_IP"
SCP="timeout -k 1 11 sshpass -p $SSH_PASS scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o ControlMaster=auto -o ControlPath=/run/ssh_control:%h:%p:%r -o ControlPersist=15s -o ServerAliveInterval=3 -o ServerAliveCountMax=2"
# Create cache directory if it doesn't exist
mkdir -p "$CACHE_DIR"
# Function to refresh cached files
refresh_cache() {
local current_time=$(date +%s)
local last_refresh=$((current_time - CACHE_TTL))
# Check if we need to refresh
if [[ ! -f "$CACHE_DIR/last_refresh" ]] || [[ $(cat "$CACHE_DIR/last_refresh") -lt $last_refresh ]]; then
# Copy the YAML configuration files
$SCP root@$REMOTE_IP:$MAJESTIC_YAML root@$REMOTE_IP:$WFB_YAML $CACHE_DIR 2>/dev/null
# Update refresh timestamp
echo "$current_time" > "$CACHE_DIR/last_refresh"
fi
}
# Function to get value from majestic.yaml using yaml-cli
get_majestic_value() {
local key="$1"
yaml-cli -i "$CACHE_DIR/majestic.yaml" -g "$key" 2>/dev/null
}
# Function to get value from wfb.yaml using yaml-cli
get_wfb_value() {
local key="$1"
yaml-cli -i "$CACHE_DIR/wfb.yaml" -g "$key" 2>/dev/null
}
# Refresh cache for get
case "$@" in
"get air"*)
[ "$3" != "presets" ] && refresh_cache
;;
esac
case "$@" in
"values air presets preset")
if [ -d $PRESET_DIR ]; then
for dir in $PRESET_DIR/presets/*; do
echo $(basename $dir)
done
fi
;;
"values air wfbng mcs_index")
echo -n 0 10
;;
"values air wfbng fec_k")
echo -n 0 15
;;
"values air wfbng fec_n")
echo -n 0 15
;;
"values air wfbng mlink")
echo -n -e "1500\n1600\n1700\n1800\n1900\n2000\n2100\n2200\n2300\n2400\n2500\n2600\n2700\n2800\n2900\n3000\n3100\n3200\n3300\n3400\n3500\n3600\n3700\n3800\n3900\n4000"
;;
"values air camera contrast")
echo -n 0 100
;;
"values air camera hue")
echo -n 0 100
;;
"values air camera saturation")
echo -n 0 100
;;
"values air camera luminace")
echo -n 0 100
;;
"values air camera gopsize")
echo -n 0 10
;;
"values air camera rec_split")
echo -n 0 60
;;
"values air camera rec_maxusage")
echo -n 0 100
;;
"values air camera exposure")
echo -n 5 50
;;
"values air camera noiselevel")
echo -n 0 1
;;
"values air telemetry osd_fps")
echo -n 0 60
;;
"values air wfbng power")
echo -n -e "1\n20\n25\n30\n35\n40\n45\n50\n55\n58"
;;
"values air wfbng air_channel")
iw list | grep MHz | grep -v disabled | grep -v "radar detection" | grep \* | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | grep '^[1-9]' | sort -n | uniq | sed -z '$ s/\n$//'
;;
"values air wfbng width")
echo -n -e "20\n40"
;;
"values air camera size")
echo -n -e "1280x720\n1456x816\n1920x1080\n1440x1080\n1920x1440\n2104x1184\n2208x1248\n2240x1264\n2312x1304\n2436x1828\n2512x1416\n2560x1440\n2560x1920\n2720x1528\n2944x1656\n3200x1800\n3840x2160"
;;
"values air camera fps")
echo -n -e "60\n90\n120"
;;
"values air camera bitrate")
echo -n -e "1024\n2048\n3072\n4096\n5120\n6144\n7168\n8192\n9216\n10240\n11264\n12288\n13312\n14336\n15360\n16384\n17408\n18432\n19456\n20480\n21504\n22528\n23552\n24576\n25600\n26624\n27648\n28672\n29692\n30720"
;;
"values air camera codec")
echo -n -e "h264\nh265"
;;
"values air camera rc_mode")
echo -n -e "vbr\navbr\ncbr"
;;
"values air camera antiflicker")
echo -n -e "disabled\n50\n60"
;;
"values air camera sensor_file")
echo -n -e "/etc/sensors/imx307.bin\n/etc/sensors/imx335.bin\n/etc/sensors/imx335_fpv.bin\n/etc/sensors/imx415_fpv.bin\n/etc/sensors/imx415_fpv.bin\n/etc/sensors/imx415_milos10.bin\n/etc/sensors/imx415_milos15.bin\n/etc/sensors/imx335_milos12tweak.bin\n/etc/sensors/imx335_greg15.bin\n/etc/sensors/imx335_spike5.bin\n/etc/sensors/gregspike05.bin"
;;
"values air telemetry serial")
echo -n -e "ttyS0\nttyS1\nttyS2"
;;
"values air telemetry router")
echo -n -e "mavfwd\nmsposd"
;;
"get air presets info"*)
if [ "$5" == "" ] ; then
echo ""
else
echo "Name: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .name)"
echo "Author: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .author)"
echo "Description: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .description)"
echo "Category: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .category)"
echo "Sensor: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .sensor)"
echo "Status: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .status)"
echo "Tags: $(yaml-cli -i $PRESET_DIR/presets/$5/preset-config.yaml -g .tags)"
fi
;;
"get air presets update")
mkdir -p $PRESET_DIR
if [ -d "$PRESET_DIR/.git" ]; then
# If it's already a git repo, force reset and pull
cd $PRESET_DIR
git fetch --all
git reset --hard origin/master
git pull origin master --force
else
# If not a git repo yet, clone fresh
git clone https://github.com/OpenIPC/fpv-presets.git $PRESET_DIR
fi
;;
"get air camera mirror")
[ "$(get_majestic_value '.image.mirror')" = "true" ] && echo 1 || echo 0
;;
"get air camera flip")
[ "$(get_majestic_value '.image.flip')" = "true" ] && echo 1 || echo 0
;;
"get air camera contrast")
get_majestic_value '.image.contrast'
;;
"get air camera hue")
get_majestic_value '.image.hue'
;;
"get air camera saturation")
get_majestic_value '.image.saturation'
;;
"get air camera luminace")
get_majestic_value '.image.luminance'
;;
"get air camera size")
get_majestic_value '.video0.size'
;;
"get air camera fps")
get_majestic_value '.video0.fps'
;;
"get air camera bitrate")
get_majestic_value '.video0.bitrate'
;;
"get air camera codec")
get_majestic_value '.video0.codec'
;;
"get air camera gopsize")
get_majestic_value '.video0.gopSize'
;;
"get air camera rc_mode")
get_majestic_value '.video0.rcMode'
;;
"get air camera rec_enable")
[ "$(get_majestic_value '.records.enabled')" = "true" ] && echo 1 || echo 0
;;
"get air camera rec_split")
get_majestic_value '.records.split'
;;
"get air camera rec_maxusage")
get_majestic_value '.records.maxUsage'
;;
"get air camera exposure")
get_majestic_value '.isp.exposure'
;;
"get air camera antiflicker")
get_majestic_value '.isp.antiFlicker'
;;
"get air camera sensor_file")
get_majestic_value '.isp.sensorConfig'
;;
"get air camera fpv_enable")
get_majestic_value '.fpv.enabled' | grep -q true && echo 1 || echo 0
;;
"get air camera noiselevel")
get_majestic_value '.fpv.noiseLevel'
;;
"set air presets "*)
PRESET="$PRESET_DIR/presets/$4/preset-config.yaml"
# Create a temporary script file
REMOTE_SCRIPT=$(mktemp)
echo "#!/bin/sh" > "$REMOTE_SCRIPT"
echo "# Auto-generated configuration script" >> "$REMOTE_SCRIPT"
echo "echo 'Applying configuration...'" >> "$REMOTE_SCRIPT"
# Process config files
FILES=$(yq e '.files | keys | .[]' "$PRESET")
for FILE in $FILES; do
# Generate CLI commands for each key-value pair
while IFS= read -r LINE; do
KEY="${LINE%% *}" # Get everything before first space
VALUE="${LINE#* }" # Get everything after first space
# Escape single quotes in values for bash
VALUE=${VALUE//\'/\'\\\'\'}
echo "echo \"Setting $KEY to $VALUE in $FILE\"" >> "$REMOTE_SCRIPT"
echo "cli -i '/etc/$FILE' -s '$KEY' '$VALUE'" >> "$REMOTE_SCRIPT"
done < <(yq e ".files[\"$FILE\"] | to_entries | .[] | \".\" + .key + \" \" + .value" "$PRESET")
done
# Add additional file copies
yq e '.additional_files // [] | .[]' "$PRESET" | while read -r ADDITIONAL_FILE; do
LOCAL_FILE="$PRESET_DIR/presets/$4/$ADDITIONAL_FILE"
if [ -f "$LOCAL_FILE" ]; then
# Transfer the file first
$SCP "$LOCAL_FILE" "root@$REMOTE_IP:/etc/"
echo "echo 'Copied additional file: $ADDITIONAL_FILE'"
else
echo "echo 'Warning: Additional file not found: $ADDITIONAL_FILE'"
fi
done
# Add service restart commands
echo "echo 'Restarting services...'" >> "$REMOTE_SCRIPT"
echo "(wifibroadcast stop; wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &" >> "$REMOTE_SCRIPT"
echo "killall -1 majestic" >> "$REMOTE_SCRIPT"
echo "echo 'Configuration applied successfully'" >> "$REMOTE_SCRIPT"
# Transfer and execute the script
$SCP "$REMOTE_SCRIPT" "root@$REMOTE_IP:/tmp/apply_config.sh"
$SSH "sh /tmp/apply_config.sh"
# Cleanup
rm "$REMOTE_SCRIPT"
;;
"set air camera mirror"*)
if [ "$5" = "on" ]
then
$SSH 'cli -s .image.mirror true && killall -1 majestic'
else
$SSH 'cli -s .image.mirror false && killall -1 majestic'
fi
;;
"set air camera flip"*)
if [ "$5" = "on" ]
then
$SSH 'cli -s .image.flip true && killall -1 majestic'
else
$SSH 'cli -s .image.flip false && killall -1 majestic'
fi
;;
"set air camera contrast"*)
$SSH "cli -s .image.contrast $5 && killall -1 majestic"
;;
"set air camera hue"*)
$SSH "cli -s .image.hue $5 && killall -1 majestic"
;;
"set air camera saturation"*)
$SSH "cli -s .image.saturation $5 && killall -1 majestic"
;;
"set air camera luminace"*)
$SSH "cli -s .image.luminance $5 && killall -1 majestic"
;;
"set air camera size"*)
$SSH "cli -s .video0.size $5 && killall -1 majestic"
;;
"set air camera fps"*)
$SSH "cli -s .video0.fps $5 && killall -1 majestic"
;;
"set air camera bitrate"*)
$SSH "cli -s .video0.bitrate $5 && killall -1 majestic"
;;
"set air camera codec"*)
$SSH "cli -s .video0.codec $5 && killall -1 majestic"
;;
"set air camera gopsize"*)
$SSH "cli -s .video0.gopSize $5 && killall -1 majestic"
;;
"set air camera rc_mode"*)
$SSH "cli -s .video0.rcMode $5 && killall -1 majestic"
;;
"set air camera rec_enable"*)
if [ "$5" = "on" ]
then
$SSH 'cli -s .records.enable true && killall -1 majestic'
else
$SSH 'cli -s .records.enable false && killall -1 majestic'
fi
;;
"set air camera rec_split"*)
$SSH "cli -s .records.split $5 && killall -1 majestic"
;;
"set air camera rec_maxusage"*)
$SSH "cli -s .records.maxUsage $5 && killall -1 majestic"
;;
"set air camera exposure"*)
$SSH "cli -s .isp.exposure $5 && killall -1 majestic"
;;
"set air camera antiflicker"*)
$SSH "cli -s .isp.antiFlicker $5 && killall -1 majestic"
;;
"set air camera sensor_file"*)
$SSH "cli -s .isp.sensorConfig $5 && killall -1 majestic"
;;
"set air camera fpv_enable"*)
if [ "$5" = "on" ]
then
$SSH 'cli -s .fpv.enabled true && killall -1 majestic'
else
$SSH 'cli -s .fpv.enabled false && killall -1 majestic'
fi
;;
"set air camera noiselevel"*)
$SSH "cli -s .fpv.noiseLevel $5 && killall -1 majestic"
;;
"get air telemetry serial")
$SSH wifibroadcast cli -g .telemetry.serial
;;
"get air telemetry router")
$SSH wifibroadcast cli -g .telemetry.router
;;
"get air telemetry osd_fps")
$SSH wifibroadcast cli -g .telemetry.osd_fps
;;
"get air telemetry gs_rendering")
$SSH 'grep "\-z \"\$size\"" /usr/bin/wifibroadcast' | grep -q size && echo 0 || echo 1
;;
"set air telemetry serial"*)
$SSH wifibroadcast cli -s .telemetry.serial $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air telemetry router"*)
$SSH wifibroadcast cli -s .telemetry.router $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air telemetry osd_fps"*)
$SSH wifibroadcast cli -s .telemetry.osd_fps $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air telemetry gs_rendering"*)
if [ "$5" = "on" ]
then -o 127.0.0.1:"$port_tx" -z "$size"
$SSH 'sed -i "s/-o 127\.0\.0\.1:\"\$port_tx\" -z \"\$size\"/-o 10\.5\.0\.1:\"\$port_tx\"/" /usr/bin/wifibroadcast'
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
else
$SSH 'sed -i "s/-o 10\.5\.0\.1:\"\$port_tx\"/-o 127\.0\.0\.1:\"\$port_tx\" -z \"\$size\"/" /usr/bin/wifibroadcast'
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
fi
;;
"get air wfbng power")
get_wfb_value '.wireless.txpower'
;;
"get air wfbng air_channel")
channel=$(get_wfb_value '.wireless.channel' | tr -d '\n')
iw list | grep "\[$channel\]" | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | sort -n | uniq | tr -d '\n'
;;
"get air wfbng width")
get_wfb_value '.wireless.width'
;;
"get air wfbng mcs_index")
get_wfb_value '.broadcast.mcs_index'
;;
"get air wfbng stbc")
get_wfb_value '.broadcast.stbc'
;;
"get air wfbng ldpc")
get_wfb_value '.broadcast.ldpc'
;;
"get air wfbng fec_k")
get_wfb_value '.broadcast.fec_k'
;;
"get air wfbng fec_n")
get_wfb_value '.broadcast.fec_n'
;;
"get air wfbng mlink")
get_wfb_value '.wireless.mlink'
;;
"get air wfbng adaptivelink")
$SSH grep ^alink_drone /etc/rc.local | grep -q 'alink_drone' && echo 1 || echo 0
;;
"set air wfbng power"*)
$SSH wifibroadcast cli -s .wireless.txpower $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng air_channel"*)
channel=$(echo $5 | awk '{print $1}')
$SSH wifibroadcast cli -s .wireless.channel $channel
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
sed -i "s/^wifi_channel =.*/wifi_channel = $channel/" /etc/wifibroadcast.cfg
systemctl restart wifibroadcast.service
;;
"set air wfbng width"*)
$SSH wifibroadcast cli -s .wireless.width $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng mcs_index"*)
$SSH wifibroadcast cli -s .broadcast.mcs_index $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng stbc"*)
if [ "$5" = "on" ]
then
$SSH wifibroadcast cli -s .broadcast.stbc 1
else
$SSH wifibroadcast cli -s .broadcast.stbc 0
fi
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng ldpc"*)
if [ "$5" = "on" ]
then
$SSH wifibroadcast cli -s .broadcast.ldpc 1
else
$SSH wifibroadcast cli -s .broadcast.ldpc 0
fi
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng fec_k"*)
$SSH wifibroadcast cli -s .broadcast.fec_k $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng fec_n"*)
$SSH wifibroadcast cli -s .broadcast.fec_n $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng mlink"*)
$SSH wifibroadcast cli -s .wireless.mlink $5
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
;;
"set air wfbng adaptivelink"*)
if [ "$5" = "on" ]
then
$SSH 'sed -i "/alink_drone &/d" /etc/rc.local && sed -i -e "\$i alink_drone &" /etc/rc.local && cli -s .video0.qpDelta -12 && killall -1 majestic && (nohup alink_drone >/dev/null 2>&1 &)'
else
$SSH 'killall -q -9 alink_drone; sed -i "/alink_drone &/d" /etc/rc.local ; cli -d .video0.qpDelta && killall -1 majestic'
fi
;;
"values gs wfbng gs_channel")
iw list | grep MHz | grep -v disabled | grep -v "radar detection" | grep \* | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | grep '^[1-9]' | sort -n | uniq | sed -z '$ s/\n$//'
;;
"values gs wfbng bandwidth")
echo -n -e "20\n40"
;;
"values gs system resolution")
drm_info -j /dev/dri/card0 2>/dev/null | jq -r '."/dev/dri/card0".connectors[1].modes[] | select(.name | contains("i") | not) | .name + "@" + (.vrefresh|tostring)' | sort | uniq | sed -z '$ s/\n$//'
;;
"values gs system rec_fps")
echo -n -e "60\n90\n120"
;;
"get gs system gs_rendering")
[ "$(grep ^osd /config/setup.txt | cut -d ' ' -f 3)" = "ground" ] && echo 1 || echo 0
;;
"get gs system resolution")
drm_info -j /dev/dri/card0 2>/dev/null | jq -r '."/dev/dri/card0".crtcs[0].mode| .name + "@" + (.vrefresh|tostring)'
;;
"get gs system rec_fps")
grep ^rec_fps /config/setup.txt | cut -d ' ' -f 3
;;
"set gs system gs_rendering"*)
if [ "$5" = "off" ]
then
sed -i 's/^osd =.*/osd = air/' /config/setup.txt
killall -q msposd_rockchip
else
sed -i 's/^osd =.*/osd = ground/' /config/setup.txt
msposd_rockchip --osd --ahi 0 --matrix 11 -v -r 5 --master 0.0.0.0:14551 &
fi
;;
"set gs system resolution"*)
sed -i "s/^screen_mode =.*/screen_mode = $5/" /config/setup.txt
;;
"set gs system rec_fps"*)
sed -i "s/^rec_fps =.*/rec_fps = $5/" /config/setup.txt
;;
"set gs system rec_enabled"*)
if [ "$5" = "off" ]
then
: #noop
else
: #noop
fi
;;
"get gs wifi hotspot")
nmcli connection show --active | grep -q "Hotspot" && echo 1 || echo 0
;;
"get gs wifi wlan")
connection=$(nmcli -t connection show --active | grep wlan0 | cut -d : -f1)
[ -z "${connection}" ] && echo 0 || echo 1
;;
"get gs wifi ssid")
if [ -d /sys/class/net/wlan0 ]; then
nmcli -t connection show --active | grep wlan0 | cut -d : -f1
else
echo -n ""
fi
;;
"get gs wifi password")
if [ -d /sys/class/net/wlan0 ]; then
connection=$(nmcli -t connection show --active | grep wlan0 | cut -d : -f1)
nmcli -t connection show $connection --show-secrets | grep 802-11-wireless-security.psk: | cut -d : -f2
else
echo -n ""
fi
;;
"get gs wifi IP")
WIFI_DEV=$(nmcli -t connection show --active | grep wlan0 | cut -d : -f4)
ip -4 addr show "$WIFI_DEV" | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
;;
"set gs wifi wlan"*)
[ ! -d /sys/class/net/wlan0 ] && exit 0 # we have no wifi
if [ "$5" = "on" ]
then
# Check if connection already exists
if nmcli connection show | grep -q "$6"; then
echo "$6 connection exists. Starting it..."
nmcli con up "$6"
else
echo "Creating new "$6" connection..."
nmcli device wifi connect "$6" password "$7"
echo "Starting Wlan..."
nmcli con up "$6"
fi
else
nmcli con down "$6"
fi
;;
"set gs wifi hotspot"*)
[ ! -d /sys/class/net/wlan0 ] && exit 0 # we have no wifi
if [ "$5" = "on" ]
then
# Check if connection already exists
if nmcli connection show | grep -q "Hotspot"; then
echo "Hotspot connection exists. Starting it..."
nmcli con up Hotspot
else
echo "Creating new Hotspot connection..."
nmcli con add type wifi ifname wlan0 con-name Hotspot autoconnect no ssid "OpenIPC GS"
nmcli con modify Hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared
nmcli con modify Hotspot wifi-sec.key-mgmt wpa-psk
nmcli con modify Hotspot wifi-sec.psk "openipcgs"
nmcli con modify Hotspot ipv4.addresses 192.168.4.1/24
echo "Starting Hotspot..."
nmcli con up Hotspot
fi
else
nmcli con down Hotspot
fi
;;
"get gs wfbng adaptivelink")
systemctl is-active --quiet alink_gs.service && echo 1 || echo 0
;;
"get gs wfbng gs_channel")
channel=$(grep wifi_channel /etc/wifibroadcast.cfg | cut -d ' ' -f 3)
iw list | grep "\[$channel\]" | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | sort -n | uniq
;;
"get gs wfbng bandwidth")
grep ^bandwidth /etc/wifibroadcast.cfg | cut -d ' ' -f 3
;;
"set gs wfbng adaptivelink"*)
if [ "$5" = "on" ]
then
systemctl start alink_gs.service
systemctl enable alink_gs.service
else
systemctl stop alink_gs.service
systemctl disable alink_gs.service
fi
;;
"set gs wfbng gs_channel"*)
channel=$(echo $5 | awk '{print $1}')
if [ "$GSMENU_VTX_DETECTED" -eq "1" ]; then
$SSH wifibroadcast cli -s .wireless.channel $channel
$SSH "(wifibroadcast stop ;wifibroadcast stop; sleep 1; wifibroadcast start) >/dev/null 2>&1 &"
fi
sed -i "s/^wifi_channel =.*/wifi_channel = $channel/" /etc/wifibroadcast.cfg
systemctl restart wifibroadcast.service
;;
"set gs wfbng bandwidth"*)
sed -i "s/^bandwidth = .*/bandwidth = $5/" /etc/wifibroadcast.cfg
systemctl restart wifibroadcast.service
;;
"get gs main Channel")
gsmenu.sh get gs wfbng gs_channel
;;
"get gs main HDMI-OUT")
gsmenu.sh get gs system resolution
;;
"get gs main Version")
cat /config/version.md
;;
"get gs main Disk")
read -r size avail pcent <<< $(df -h / | awk 'NR==2 {print $2, $4, $5}')
echo -e "\n Size: $size\n Available: $avail\n Pct: $pcent\c"
;;
"get gs main WFB_NICS")
grep ^WFB_NICS /etc/default/wifibroadcast | cut -d \" -f 2
;;
"search channel")
echo "Not implmented"
echo "Not implmented" >&2
exit 1
;;
"button air actions Reboot")
$SSH 'reboot &'
;;
"button gs actions Reboot")
reboot
;;
*)
echo "Unknown $@"
exit 1
;;
esac
case $? in
0) ;;
1) exit 0 ;;
*) exit $? ;;
esac