Repository navigation
Expand file tree
/
Copy pathsdrpp-cli
More file actions
executable file
·187 lines (158 loc) · 4.72 KB
/
Copy pathsdrpp-cli
File metadata and controls
executable file
·187 lines (158 loc) · 4.72 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
#!/bin/bash
BUILD_DIR="/Users/san/Fun/SDRPlusPlus/cmake-build-debug"
#CONFIG_DIR="/tmp/sdrpp_config"
CONFIG_DIR="`pwd`/root_dev"
start() {
if pgrep -f "sdrpp" > /dev/null 2>&1; then
echo "Already running"
exit 1
fi
mkdir -p "$CONFIG_DIR"
LOG_FILE="$CONFIG_DIR/sdrpp.log"
cd "$BUILD_DIR"
nohup ./sdrpp -r "$CONFIG_DIR" --http 8080 > "$LOG_FILE" 2>&1 &
SPD=$!
for i in 1 2 3 4 5 6 7 8 9 10; do
sleep 1
if curl -s http://localhost:8080/status | grep -q 'mainLoopStarted.*true'; then
echo "Started"
exit 0
fi
done
echo "Start error"
pkill -f "sdrpp"
exit 1
}
status() {
if pgrep -f "sdrpp" > /dev/null 2>&1; then
echo "up"
else
echo "down"
fi
}
stop() {
if pgrep -f "sdrpp" > /dev/null 2>&1; then
pkill -f "sdrpp"
echo "Stopped"
else
echo "Was not running"
fi
}
build() {
LOG_FILE="/Users/san/Fun/SDRPlusPlus/build.log"
cd "$BUILD_DIR"
cmake .. \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-G "Unix Makefiles" \
-DOPT_BUILD_PLUTOSDR_SOURCE=OFF \
-DCMAKE_INSTALL_PREFIX=/Users/san/Fun/SDRPlusPlus/root_dev/inst \
-DOPT_BUILD_CH_EXTRAVHF_DECODER:BOOL=ON \
-DOPT_BUILD_CH_TETRA_DEMODULATOR:BOOL=ON > "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
tail -50 "$LOG_FILE"
exit 1
fi
make -j$(nproc) >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
tail -50 "$LOG_FILE"
exit 1
fi
make install >> "$LOG_FILE" 2>&1
if [ $? -ne 0 ]; then
tail -50 "$LOG_FILE"
exit 1
fi
WARNINGS=$(grep -ci "warning:" "$LOG_FILE" 2>/dev/null || true)
echo "$WARNINGS warnings, log saved in $LOG_FILE"
}
list-all() {
if ! pgrep -f "sdrpp" > /dev/null 2>&1; then
echo "SDR++ is not running. Start with: $0 start"
exit 1
fi
python3 << 'PYEOF'
import json
import subprocess
data = json.loads(subprocess.run(['curl', '-s', 'http://localhost:8080/ls'], capture_output=True, text=True).stdout)
for e in sorted(data, key=lambda x: x['path']):
print(f"{e['path']} = {e['value']} ({e['type']})")
PYEOF
}
set_value() {
if [ $# -ne 2 ]; then
echo "Usage: $0 set <path> <value>"
echo "Example: $0 set /source/type File"
exit 1
fi
if ! pgrep -f "sdrpp" > /dev/null 2>&1; then
echo "SDR++ is not running. Start with: $0 start"
exit 1
fi
local path="$1"
local value="$2"
python3 << PYEOF
import json
import subprocess
import sys
from urllib.parse import quote
path = "$path"
value = "$2"
# Get endpoint info to determine type
data = json.loads(subprocess.run(['curl', '-s', 'http://localhost:8080/ls'], capture_output=True, text=True).stdout)
endpoint = next((e for e in data if e['path'] == path), None)
if not endpoint:
print(f"Error: Endpoint {path} not found", file=sys.stderr)
sys.exit(1)
if not endpoint.get('writable', False):
print(f"Error: Endpoint {path} is not writable", file=sys.stderr)
sys.exit(1)
# Convert value to appropriate type based on endpoint type
endpoint_type = endpoint.get('type', 'string')
converted_value = value
if endpoint_type == 'bool':
if value.lower() in ('true', '1', 'yes'):
converted_value = 'true'
elif value.lower() in ('false', '0', 'no'):
converted_value = 'false'
else:
print(f"Error: Invalid boolean value: {value}", file=sys.stderr)
sys.exit(1)
elif endpoint_type == 'int':
try:
converted_value = str(int(value))
except ValueError:
print(f"Error: Invalid integer value: {value}", file=sys.stderr)
sys.exit(1)
elif endpoint_type == 'float':
try:
converted_value = str(float(value))
except ValueError:
print(f"Error: Invalid float value: {value}", file=sys.stderr)
sys.exit(1)
elif endpoint_type == 'string':
# Keep as-is, already a string
pass
else:
converted_value = value
# URL encode the path for the request
encoded_path = quote(path, safe='')
# Send POST request
result = subprocess.run(['curl', '-s', '-X', 'POST', f'http://localhost:8080/proc{encoded_path}', '-d', converted_value], capture_output=True, text=True)
if result.returncode != 0:
print(f"Error: Failed to set {path}", file=sys.stderr)
sys.exit(1)
if 'error' in result.stdout.lower():
print(f"Error: {result.stdout}", file=sys.stderr)
sys.exit(1)
print(f"Set {path} = {value} (converted to {endpoint_type}: {converted_value})")
PYEOF
}
case "$1" in
start) start ;;
stop) stop ;;
status) status ;;
build) build ;;
list-all) list-all ;;
set) set_value "$2" "$3" ;;
*) echo "Usage: $0 {start|stop|status|build|list-all|set}" ;;
esac