-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ARN Utils - ARN HAL - ARN Scripts
- Loading branch information
Showing
17 changed files
with
2,245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/sh | ||
|
||
VERSION="ARN-Scripts v1.0-170821Q" | ||
ARN_MNGR=/usr/sbin/arn-mngr | ||
#ARN_MNGR_JSON=/usr/sbin/arn-mngr-json | ||
|
||
version() { | ||
echo "$VERSION" | ||
} | ||
|
||
help() { | ||
echo "usage: " | ||
echo " arn [-a] [-m]" | ||
echo " arn [-R 0|1] [-C n] [-F n] [-B 6|8|16|24] [-P n]" | ||
echo " arn [-T 1|0] [-M car|ear|mesh]" | ||
} | ||
|
||
arn_mode() { | ||
local MODE=$1 | ||
if [ "$MODE" == "mesh" ]; then | ||
/usr/sbin/arn-mode mesh | ||
elif [ "$MODE" == "car" ]; then | ||
/usr/sbin/arn-mode car | ||
else | ||
/usr/sbin/arn-mode ear | ||
fi | ||
} | ||
|
||
monitor() { | ||
while true; do | ||
arn -a | ||
sleep 1 | ||
clear | ||
done | ||
} | ||
|
||
|
||
# FIXME: add all common commands | ||
# break when got a valid option | ||
# JSON/all/monitor/Mode/help | ||
# TODO: channel/region/chanbw/txpower/freq | ||
while getopts "jamM:cC:rR:bB:pP:fF:hT:v" OPT; do | ||
case "$OPT" in | ||
j) | ||
$ARN_MNGR json | ||
break | ||
;; | ||
f) | ||
$ARN_MNGR freq | ||
break | ||
;; | ||
F) | ||
$ARN_MNGR freq $OPTARG | ||
break | ||
;; | ||
c) | ||
$ARN_MNGR channel | ||
break | ||
;; | ||
C) | ||
$ARN_MNGR channel $OPTARG | ||
break | ||
;; | ||
r) | ||
$ARN_MNGR region | ||
break | ||
;; | ||
R) | ||
$ARN_MNGR region $OPTARG | ||
break | ||
;; | ||
p) | ||
$ARN_MNGR txpower | ||
break | ||
;; | ||
P) | ||
$ARN_MNGR txpower $OPTARG | ||
break | ||
;; | ||
b) | ||
$ARN_MNGR chanbw | ||
break | ||
;; | ||
B) | ||
$ARN_MNGR chanbw $OPTARG | ||
break | ||
;; | ||
T) | ||
$ARN_MNGR tx $OPTARG | ||
break | ||
;; | ||
M) | ||
arn_mode $OPTARG | ||
break | ||
;; | ||
m) | ||
monitor | ||
;; | ||
a) | ||
date; echo '----------------------------' | ||
$ARN_MNGR all 2>/dev/null | ||
break | ||
;; | ||
v|h|?) | ||
version; echo '------------------------' | ||
help; break | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/lua | ||
-- ARN Device HAL Layer | ||
-- Donot filter anything | ||
-- Provide unified commands | ||
-- by Qige <qigezhao@gmail.com> | ||
|
||
local gws_hal = require 'arn.hal_raw' | ||
local sfmt = string.format | ||
|
||
local arg_key = tostring(arg[1]) | ||
local arg_val = tostring(arg[2]) | ||
|
||
local function help() | ||
print "usage: " | ||
print " arn-hal-raw [c|channo|r|region|rfinfo|p|txpower|b|chanbw]" | ||
print " arn-hal-raw [c|channo|r|region|rfinfo|p|txpower|b|chanbw] [value]" | ||
end | ||
|
||
local function format_item(key, value) | ||
return sfmt("%s=%s", key, value or -1) | ||
end | ||
|
||
local function format_all(obj) | ||
local result = '' | ||
for i,v in pairs(obj) do | ||
if (result ~= '') then result = result .. '\n' end | ||
result = result .. sfmt("%s=%s", i, v) | ||
end | ||
return result | ||
end | ||
|
||
-- print each item from HAL | ||
local function format(key) | ||
local gws_raw = gws_hal.HAL_GET_RADIO_RT() | ||
local result = '' | ||
if (key and key ~= 'all' and key ~= 'rfinfo') then | ||
if (key == 'r' or key == 'region') then | ||
result = format_item('region', gws_raw.region or -1) | ||
elseif (key == 'c' or key == 'channo' or key == 'channel') then | ||
result = format_item('region', gws_raw.channo or gws_raw.channel or -1) | ||
elseif (key == 'p' or key == 'txpower') then | ||
result = format_item('region', gws_raw.txpwr or gws_raw.txpower or -1) | ||
elseif (key == 'b' or key == 'chanbw') then | ||
result = format_item('region', gws_raw.chanbw or -1) | ||
else | ||
result = format_all(gws_raw) | ||
end | ||
else | ||
result = format_all(gws_raw) | ||
end | ||
return result | ||
end | ||
|
||
-- FIXME: add all common commands | ||
if (arg_key ~= 'nil') then | ||
if (arg_val ~= 'nil') then | ||
print(sfmt("arn-hal-raw: set %s=%s", arg_key, arg_val)) | ||
gws_hal.HAL_SET_RT(arg_key, arg_val) | ||
else | ||
--print(sfmt("> %s", arg_key)) | ||
print(format(arg_key)) | ||
end | ||
else | ||
help() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
#!/usr/bin/lua | ||
--[[ | ||
Desc: | ||
ARN Device Manager | ||
Tasks: | ||
1. call "arn.mngr", filter all input | ||
2. read limits from "/etc/config/arn-spec" | ||
3. finally, set via "arn.hal_raw" | ||
4. "arn.mngr" provide CACHE | ||
5. "qutil.rarp" provide RARP | ||
Maintainer: | ||
by Qige <qigezhao@gmail.com> | ||
2017.08.18|2017.08.22 | ||
]]-- | ||
|
||
--local DBG = print | ||
local function DBG(msg) end | ||
|
||
local mngr = require 'arn.mngr' | ||
local rarp = require 'qutil.rarp' | ||
local ccff = require 'qutil.ccff' | ||
local is_array = ccff.val.is_array | ||
local sfmt = string.format | ||
local ssub = string.sub | ||
local slen = string.len | ||
local exec = ccff.execute | ||
|
||
local VERSION = 'ARN-Scripts (+HAL +Cache +5K/+4K) v2017.08.18 ' | ||
|
||
local arg_key = tostring(arg[1]) -- nil > 'nil' | ||
local arg_val = tostring(arg[2]) -- nil > 'nil' | ||
|
||
local function help() | ||
print "usage: " | ||
print " arn-mngr [a|all]" | ||
print " arn-mngr [c|channel|r|region|p|txpower|b|chanbw|f|freq] [value]" | ||
end | ||
|
||
local function concat_items(obj) | ||
local result = '' | ||
local cnt = 0 | ||
if (is_array(obj)) then | ||
table.sort(obj) | ||
for i,v in pairs(obj) do | ||
-- in case v is 'table' | ||
if (v and type(v) ~= 'table') then | ||
if (i ~= 'timeout' and i ~= 'elapsed') then | ||
if (cnt % 4 == 0) then | ||
result = result .. '\n' | ||
else | ||
if (result ~= '') then result = result .. ' | ' end | ||
end | ||
if (slen(i) > 7) then | ||
i = ssub(i, 1, 7) | ||
end | ||
if (slen(v) > 8) then | ||
v = ssub(v, 1, 8) | ||
end | ||
result = result .. sfmt('%7s: %-8s', i, v) | ||
cnt = cnt + 1 | ||
end | ||
end | ||
end | ||
end | ||
return result | ||
end | ||
|
||
local function valid_signal(signal, noise) | ||
if (signal and noise and signal > noise) then | ||
return signal | ||
end | ||
return '---' | ||
end | ||
|
||
local function calc_snr(signal, noise) | ||
if (signal and noise and signal > noise) then | ||
return signal - noise | ||
end | ||
return '---' | ||
end | ||
|
||
local function format_abb(obj) | ||
local result = '' | ||
|
||
local s1, s2 | ||
s1 = sfmt(' SSID: %s (%s)\n', obj.ssid or '---', obj.mode) | ||
result = result .. s1 | ||
|
||
s2 = sfmt(' BSSID: %-28s\n', obj.bssid or '---') | ||
result = result .. s2 | ||
|
||
s1 = sfmt(' Noise: %-4s dBm | Signal: %-4s dBm | SNR: %-8s\n', | ||
obj.noise, valid_signal(obj.signal, obj.noise), | ||
calc_snr(obj.signal, obj.noise)) | ||
result = result .. s1 | ||
|
||
result = result .. '\n' | ||
|
||
local peers = obj.peers | ||
if (peers and type(peers) == 'table' and #peers > 0) then | ||
for idx,peer in pairs(peers) do | ||
s2 = sfmt('link#%02d: %-23s | %s/%s/%s | Rx %s/%s | Tx %s/%s | %.2fs\n', | ||
idx, rarp.FETCH_IP(peer.wmac), | ||
valid_signal(peer.signal, peer.noise), peer.noise, | ||
calc_snr(peer.signal, peer.noise), peer.rx_mcs, peer.rx_br, | ||
peer.tx_mcs, peer.tx_br, | ||
peer.inactive/1000) | ||
result = result .. s2 | ||
end | ||
else | ||
s2 = sfmt(' Links: (not connected)\n') | ||
result = result .. s2 | ||
end | ||
|
||
return result | ||
end | ||
local function format_radio(key, obj) | ||
local result = sfmt("%s", concat_items(obj)) | ||
return result .. '\n' | ||
end | ||
|
||
local function format_nw(key, obj) | ||
local result = sfmt(' thrpt: Rx %s, Tx %s ("arn -m" ONLY, not accurate)', | ||
obj.rx or '0.00 Kbps', obj.tx or '0.00 Kbps') | ||
return result | ||
end | ||
|
||
local function format_ts(elapsed, timeout) | ||
local result = sfmt('%80s\n', VERSION) | ||
result = result .. sfmt("%79s", sfmt("> %s/%s <", (elapsed or 0), (timeout or 0))) | ||
return result | ||
end | ||
|
||
--[[ | ||
TODO: | ||
1. re-design display format; | ||
2. encode result with 'JSON' module. | ||
Tasks: | ||
1. get gws raw table via "arn.mngr" | ||
2. decide what to display by user input; | ||
]]-- | ||
local function print_with_filter(key) | ||
local result = '' | ||
|
||
local gws_safe_raw = mngr.SAFE_GET('with_unit') | ||
local safe_abb = gws_safe_raw.abb_safe | ||
local safe_radio = gws_safe_raw.radio_safe | ||
local safe_nw = gws_safe_raw.nw_thrpt | ||
|
||
result = result .. format_ts(safe_radio.elapsed, safe_radio.timeout) .. '\n' | ||
result = result .. format_abb(safe_abb) .. '\n' | ||
result = result .. format_radio(key, safe_radio) .. '\n' | ||
result = result .. format_nw(key, safe_nw) | ||
|
||
print(result) | ||
end | ||
|
||
local function print_set_result(k, v) | ||
--print(sfmt("set %s=%s", k, v)) | ||
end | ||
|
||
-- SAFE_SET() will call SAFE_SAVE() automatically | ||
if (arg_key ~= 'nil') then | ||
if (arg_val ~= 'nil') then | ||
local k,v = mngr.SAFE_SET(arg_key, arg_val) | ||
print_set_result(k, v) | ||
else | ||
DBG(sfmt("> %s", arg_key)) | ||
print_with_filter(arg_key) | ||
end | ||
else | ||
help() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/bin/sh | ||
|
||
arn_wds_car() { | ||
echo " set mode to car" | ||
uci set wireless.@wifi-iface[0].mode='ap' | ||
uci set wireless.@wifi-iface[0].ssid='GWS5000_BJWDS' | ||
uci set wireless.@wifi-iface[0].wds=1 | ||
uci del wireless.@wifi-iface[0].mesh_id 2>/dev/null | ||
uci commit wireless | ||
wifi | ||
} | ||
|
||
arn_wds_ear() { | ||
echo " set mode to ear" | ||
uci set wireless.@wifi-iface[0].mode='sta' | ||
uci set wireless.@wifi-iface[0].ssid='GWS5000_BJWDS' | ||
uci set wireless.@wifi-iface[0].wds=1 | ||
uci del wireless.@wifi-iface[0].mesh_id 2>/dev/null | ||
uci commit wireless | ||
wifi | ||
} | ||
|
||
arn_wds_mesh() { | ||
echo " set mode to mesh" | ||
uci set wireless.@wifi-iface[0].mode='mesh' | ||
uci set wireless.@wifi-iface[0].mesh_id='GWS5000_BJMesh' | ||
uci set wireless.@wifi-iface[0].wds=1 | ||
uci del wireless.@wifi-iface[0].ssid 2>/dev/null | ||
uci commit wireless | ||
wifi | ||
} | ||
|
||
[ -n "$1" ] && { | ||
if [ "$1" == "car" ] || [ "$1" == "CAR" ]; then | ||
arn_wds_car | ||
elif [ "$1" == "ear" ] || [ "$1" == "EAR" ]; then | ||
arn_wds_ear | ||
elif [ "$1" == "mesh" ] || [ "$1" == "MESH" ]; then | ||
arn_wds_mesh | ||
else | ||
echo " unknown mode" | ||
fi | ||
} |
Oops, something went wrong.