Skip to content

Commit 137d9fc

Browse files
committed
optimize loading
1 parent d919938 commit 137d9fc

File tree

2 files changed

+80
-31
lines changed

2 files changed

+80
-31
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Specific widgets expect quite concrete facts as input:
183183
The menu provides options to modify air and ground settings.
184184
Navigation is controlled via a GPIO button, adhering to Ruby wiring conventions.
185185
PixelPilot_rk will take ownership of the needed gpios.
186+
The provided gsmenu.sh script needs https://github.com/openipc/yaml-cli/
186187

187188
### Navigation
188189
Up/Down – Cycles through menu items (wraps around at the top and bottom of the page/sections).

gsmenu.sh

+79-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
11
#!/bin/bash
22
set -o pipefail
3-
SSH='timeout -k 1 11 sshpass -p 12345 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@10.5.0.10 '
3+
4+
# Configuration
5+
REMOTE_IP="10.5.0.10"
6+
SSH_PASS="12345"
7+
CACHE_DIR="/tmp/gsmenu_cache"
8+
CACHE_TTL=10 # seconds
9+
MAJESTIC_YAML="/etc/majestic.yaml"
10+
WFB_YAML="/etc/wfb.yaml"
11+
12+
# SSH command setup
13+
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"
14+
15+
# Create cache directory if it doesn't exist
16+
mkdir -p "$CACHE_DIR"
17+
18+
# Function to refresh cached files
19+
refresh_cache() {
20+
local current_time=$(date +%s)
21+
local last_refresh=$((current_time - CACHE_TTL))
22+
23+
# Check if we need to refresh
24+
if [[ ! -f "$CACHE_DIR/last_refresh" ]] || [[ $(cat "$CACHE_DIR/last_refresh") -lt $last_refresh ]]; then
25+
# Copy the YAML configuration files
26+
$SSH "cat $MAJESTIC_YAML" > "$CACHE_DIR/majestic.yaml" 2>/dev/null
27+
$SSH "cat $WFB_YAML" > "$CACHE_DIR/wfb.yaml" 2>/dev/null
28+
29+
# Update refresh timestamp
30+
echo "$current_time" > "$CACHE_DIR/last_refresh"
31+
fi
32+
}
33+
34+
# Function to get value from majestic.yaml using yaml-cli
35+
get_majestic_value() {
36+
local key="$1"
37+
yaml-cli -i "$CACHE_DIR/majestic.yaml" -g "$key" 2>/dev/null
38+
}
39+
40+
# Function to get value from wfb.yaml using yaml-cli
41+
get_wfb_value() {
42+
local key="$1"
43+
yaml-cli -i "$CACHE_DIR/wfb.yaml" -g "$key" 2>/dev/null
44+
}
45+
46+
# Refresh cache for get
47+
case "$1" in
48+
"get air"*)
49+
refresh_cache
50+
;;
51+
esac
452

553
case "$@" in
654
"values air wfbng mcs_index")
@@ -83,64 +131,64 @@ case "$@" in
83131
;;
84132

85133
"get air camera mirror")
86-
[ "true" = $($SSH cli -g .image.mirror) ] && echo 1 || echo 0
134+
[ "$(get_majestic_value '.image.mirror')" = "true" ] && echo 1 || echo 0
87135
;;
88136
"get air camera flip")
89-
[ "true" = $($SSH cli -g .image.flip) ] && echo 1 || echo 0
137+
[ "$(get_majestic_value '.image.flip')" = "true" ] && echo 1 || echo 0
90138
;;
91139
"get air camera contrast")
92-
$SSH cli -g .image.contrast
140+
get_majestic_value '.image.contrast'
93141
;;
94142
"get air camera hue")
95-
$SSH cli -g .image.hue
143+
get_majestic_value '.image.hue'
96144
;;
97145
"get air camera saturation")
98-
$SSH cli -g .image.saturation
146+
get_majestic_value '.image.saturation'
99147
;;
100148
"get air camera luminace")
101-
$SSH cli -g .image.luminance
149+
get_majestic_value '.image.luminance'
102150
;;
103151
"get air camera size")
104-
$SSH cli -g .video0.size
152+
get_majestic_value '.video0.size'
105153
;;
106154
"get air camera fps")
107-
$SSH cli -g .video0.fps
155+
get_majestic_value '.video0.fps'
108156
;;
109157
"get air camera bitrate")
110-
$SSH cli -g .video0.bitrate
158+
get_majestic_value '.video0.bitrate'
111159
;;
112160
"get air camera codec")
113-
$SSH cli -g .video0.codec
161+
get_majestic_value '.video0.codec'
114162
;;
115163
"get air camera gopsize")
116-
$SSH cli -g .video0.gopSize
164+
get_majestic_value '.video0.gopSize'
117165
;;
118166
"get air camera rc_mode")
119-
$SSH cli -g .video0.rcMode
167+
get_majestic_value '.video0.rcMode'
120168
;;
121169
"get air camera rec_enable")
122-
[ "true" = $($SSH cli -g .records.enabled) ] && echo 1 || echo 0
170+
[ "$(get_majestic_value '.records.enabled')" = "true" ] && echo 1 || echo 0
123171
;;
124172
"get air camera rec_split")
125-
$SSH cli -g .records.split
173+
get_majestic_value '.records.split'
126174
;;
127175
"get air camera rec_maxusage")
128-
$SSH cli -g .records.maxUsage
176+
get_majestic_value '.records.maxUsage'
129177
;;
130178
"get air camera exposure")
131-
$SSH cli -g .isp.exposure
179+
get_majestic_value '.isp.exposure'
132180
;;
133181
"get air camera antiflicker")
134-
$SSH cli -g .isp.antiFlicker
182+
get_majestic_value '.isp.antiFlicker'
135183
;;
136184
"get air camera sensor_file")
137-
$SSH cli -g .isp.sensorConfig
185+
get_majestic_value '.isp.sensorConfig'
138186
;;
139187
"get air camera fpv_enable")
140-
$SSH cli -g .fpv.enabled | grep -q true && echo 1 || echo 0
188+
get_majestic_value '.fpv.enabled' | grep -q true && echo 1 || echo 0
141189
;;
142190
"get air camera noiselevel")
143-
$SSH cli -g .fpv.noiseLevel
191+
get_majestic_value '.fpv.noiseLevel'
144192
;;
145193

146194
"set air camera mirror"*)
@@ -261,32 +309,32 @@ case "$@" in
261309
;;
262310

263311
"get air wfbng power")
264-
$SSH wifibroadcast cli -g .wireless.txpower
312+
get_wfb_value '.wireless.txpower'
265313
;;
266314
"get air wfbng air_channel")
267-
channel=$($SSH wifibroadcast cli -g .wireless.channel | tr -d '\n')
268-
iw list | grep "\[$channel\]" | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | sort -n | uniq | tr -d '\n'
315+
channel=$(get_wfb_value '.wireless.channel' | tr -d '\n')
316+
iw list | grep "\[$channel\]" | tr -d '[]' | awk '{print $4 " (" $2 " " $3 ")"}' | sort -n | uniq | tr -d '\n'
269317
;;
270318
"get air wfbng width")
271-
$SSH wifibroadcast cli -g .wireless.width
319+
get_wfb_value '.wireless.width'
272320
;;
273321
"get air wfbng mcs_index")
274-
$SSH wifibroadcast cli -g .broadcast.mcs_index
322+
get_wfb_value '.broadcast.mcs_index'
275323
;;
276324
"get air wfbng stbc")
277-
$SSH wifibroadcast cli -g .broadcast.stbc
325+
get_wfb_value '.broadcast.stbc'
278326
;;
279327
"get air wfbng ldpc")
280-
$SSH wifibroadcast cli -g .broadcast.ldpc
328+
get_wfb_value '.broadcast.ldpc'
281329
;;
282330
"get air wfbng fec_k")
283-
$SSH wifibroadcast cli -g .broadcast.fec_k
331+
get_wfb_value '.broadcast.fec_k'
284332
;;
285333
"get air wfbng fec_n")
286-
$SSH wifibroadcast cli -g .broadcast.fec_n
334+
get_wfb_value '.broadcast.fec_n'
287335
;;
288336
"get air wfbng mlink")
289-
$SSH wifibroadcast cli -g .wireless.mlink
337+
get_wfb_value '.wireless.mlink'
290338
;;
291339
"get air wfbng adaptivelink")
292340
$SSH grep ^alink_drone /etc/rc.local | grep -q 'alink_drone' && echo 1 || echo 0

0 commit comments

Comments
 (0)