Skip to content

Commit

Permalink
Release "alpha" (#10)
Browse files Browse the repository at this point in the history
* Change directory structure (not verified yet)
- arn/
- arn/device/
- arn/device/mngr.lua
- arn/device/uhf.lua
- arn/device/hal/
- arn/device/hal/hal_raw.lua
- arn/utils/
- arn/utils/cache.lua
- arn/utils/ccff.lua
- arn/utils/debug.lua
- arn/utils/rarp.lua
- arn/utils/serialize.lua
* Update ARN-Mngr
* Upgrade for "ARN OMC Agent", add function ccff.file.exists()
* Try Makefile
* 2017.10.19 Continue ARN-Scripts (v2.0)
- Add "radio query lock";
- Handle "dead-lock";
- Add "banner";
- No error on GWS5Kv2, need more tests.
* Co-work with ARN-Proto (+arn-agent-omc)
* Import "JSON.Encode()"
* Assign default region value, and check its type before compare
* "rarp": return ip only; let cache valid in next hour
  • Loading branch information
qigezhao committed Dec 8, 2017
1 parent 0027c1f commit 5c997a5
Show file tree
Hide file tree
Showing 20 changed files with 432 additions and 64 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 6Harmonics Inc
# maintainer: Qige Zhao <[email protected]>
# updated on: 2017.10.19

all:

clean:
5 changes: 3 additions & 2 deletions bin/arn
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
# 2017.10.19 continue ARN-Scripts
# TODO: JSON not supported yet

VERSION="ARN-Scripts v1.0-170821Q"
VERSION="ARN-Scripts v2.0-191017Q"
ARN_MNGR=/usr/sbin/arn-mngr
#ARN_MNGR_JSON=/usr/sbin/arn-mngr-json

version() {
echo "$VERSION"
Expand Down
2 changes: 1 addition & 1 deletion bin/arn-hal-raw
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-- Provide unified commands
-- by Qige <[email protected]>

local gws_hal = require 'arn.hal_raw'
local gws_hal = require 'arn.device.hal.hal_raw'
local sfmt = string.format

local arg_key = tostring(arg[1])
Expand Down
29 changes: 22 additions & 7 deletions bin/arn-mngr
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,28 @@ Tasks:
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
5. "qutil.rarp" provide RARP (+rarp-client +rarp-server)
Maintainer:
by Qige <[email protected]>
2017.08.18|2017.08.22
2017.08.18|2017.08.22 v1.0
2017.08.29 v1.1
2017.10.19 v2.0 continue ARN-Scripts; plan to add ARN-iOMC3-Agent
]]--

--local DBG = print
local function DBG(msg) end

local mngr = require 'arn.mngr'
local rarp = require 'qutil.rarp'
local ccff = require 'qutil.ccff'
local mngr = require 'arn.device.mngr'
local rarp = require 'arn.utils.rarp'
local ccff = require 'arn.utils.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 VERSION = 'ARN-Scripts (+HAL +Cache +5Kv2) v2.0-191017Q'

local arg_key = tostring(arg[1]) -- nil > 'nil'
local arg_val = tostring(arg[2]) -- nil > 'nil'
Expand Down Expand Up @@ -121,9 +123,22 @@ local function format_radio(key, obj)
return result .. '\n'
end

local function format_thrpt(val)
local thrpt = '0.00 Kbps'
if (val) then
local bps = tonumber(val)
if (bps > 1024 * 1024) then
thrpt = sfmt("%.2f Mbps", (bps / 1024 / 1024))
else
thrpt = sfmt("%.2f Kbps", (bps / 1024))
end
end
return thrpt
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')
format_thrpt(obj.rx), format_thrpt(obj.tx))
return result
end

Expand Down
16 changes: 16 additions & 0 deletions files/banner.failsafe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
================= FAILSAFE MODE active ===================
Thank you for choosing
__ _ _ _
/ /_ | | | | __ _ _ __ _ __ ___ ___ _ __ (_) ___ ___
| '_ \| |_| |/ _` | '__| '_ ` _ \ / _ \| '_ \| |/ __/ __|
| (_) | _ | (_| | | | | | | | | (_) | | | | | (__\__ \
\___/|_| |_|\__,_|_| |_| |_| |_|\___/|_| |_|_|\___|___/

---------------------------------------------------------
ARN Beijing Firmware
---------------------------------------------------------
* Kernel Dawen Zhang, Yaoyang Wang
* Application Yu Zhou, Qige Zhao
---------------------------------------------------------
==========================================================

13 changes: 13 additions & 0 deletions files/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Thank you for choosing
__ _ _ _
/ /_ | | | | __ _ _ __ _ __ ___ ___ _ __ (_) ___ ___
| '_ \| |_| |/ _` | '__| '_ ` _ \ / _ \| '_ \| |/ __/ __|
| (_) | _ | (_| | | | | | | | | (_) | | | | | (__\__ \
\___/|_| |_|\__,_|_| |_| |_| |_|\___/|_| |_|_|\___|___/

---------------------------------------------------------
ARN Beijing Firmware
---------------------------------------------------------
* Kernel Dawen Zhang, Yaoyang Wang
* Application Yu Zhou, Qige Zhao
---------------------------------------------------------
45 changes: 28 additions & 17 deletions lib/arn/gws_4k.lua → lib/arn/device/hal/gws_3k.lua
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
--[[
Note:
Although GWS4K share the same methods and functions,
Although GWS3K share the same methods and functions,
this copy will let maintainer handle 2 types of hardware.
by Qige <[email protected]>
2017.08.16 update_rt
2017.08.16 update_rt, copied from gws_4k.lua
2017.10.19 dismiss error, function and data not verified
]]--

local DBG = print
--local function DBG(msg) end

local ccff = require 'qutil.ccff'
local uhf = require 'arn.uhf'
local ccff = require 'arn.utils.ccff'
local uhf = require 'arn.device.uhf'

local exec = ccff.execute
local vint = ccff.val.n
Expand All @@ -25,11 +26,11 @@ gws_radio.conf = {}
gws_radio.conf.val_length_max = 8

gws_radio.cmd = {}
gws_radio.cmd.rfinfo_clean = 'echo > /tmp/.GWS4K.tmp'
gws_radio.cmd.rfinfo = 'rfinfo 2>/dev/null > /tmp/.GWS4K.tmp'
gws_radio.cmd.region = 'cat /tmp/.GWS4K.tmp 2> /dev/null | grep Region -A1 | grep [01]* -o'
gws_radio.cmd.channel = 'cat /tmp/.GWS4K.tmp 2> /dev/null | grep Channel -A1 | grep [0-9]* -o'
gws_radio.cmd.txpower = 'cat /tmp/.GWS4K.tmp 2> /dev/null | grep ^Tx | grep Power | grep [0-9\.]* -o'
gws_radio.cmd.rfinfo_clean = 'echo > /tmp/.GWS3K.tmp'
gws_radio.cmd.rfinfo = 'rfinfo 2>/dev/null > /tmp/.GWS3K.tmp'
gws_radio.cmd.region = 'cat /tmp/.GWS3K.tmp 2> /dev/null | grep Region -A1 | grep [01]* -o'
gws_radio.cmd.channel = 'cat /tmp/.GWS3K.tmp 2> /dev/null | grep Channel -A1 | grep [0-9]* -o'
gws_radio.cmd.txpower = 'cat /tmp/.GWS3K.tmp 2> /dev/null | grep ^Tx | grep Power | grep [0-9\.]* -o'
gws_radio.cmd.chanbw = 'uci get wireless.radio0.chanbw'

gws_radio.cmd.region_set = 'setregion %s 2> /dev/null '
Expand All @@ -39,10 +40,14 @@ gws_radio.cmd.chanbw_set = 'setchanbw %s 2> /dev/null '
gws_radio.cmd.rxgain_set = 'setrxgain %s 2> /dev/null '

function gws_radio.update_init()
DBG(sfmt("GWS4K----> update_init()"))
DBG(sfmt("GWS3K----> update_init()"))
exec(gws_radio.cmd.rfinfo)
end

function gws_radio.rfinfo_clean()
exec(gws_radio.cmd.rfinfo_clean)
end

--[[
Tasks:
1. Return each value by key;
Expand Down Expand Up @@ -73,40 +78,46 @@ Tasks:
2. Fetch each parameters from tmp file.
]]--
function gws_radio.UPDATE_RT()
DBG(sfmt("GWS4K> update_rt (@%d)", os.time()))
DBG(sfmt("GWS3K> update_rt (@%d)", os.time()))
local result = {}

gws_radio.update_init()

DBG(sfmt("GWS4K----> update_item() region"))
DBG(sfmt("GWS3K----> update_item() region"))
result.region = gws_radio.update_item('region')

DBG(sfmt("GWS4K----> update_item() channel"))
DBG(sfmt("GWS3K----> update_item() channel"))
result.channo = gws_radio.update_item('channel')
result.freq = uhf.channel_to_freq(result.region, result.channo)

DBG(sfmt("GWS4K----> update_item() txpower"))
DBG(sfmt("GWS3K----> update_item() txpower"))
result.txpwr = gws_radio.update_item('txpower')

DBG(sfmt("GWS4K----> update_item() chanbw"))
DBG(sfmt("GWS3K----> update_item() chanbw"))
result.chanbw = gws_radio.update_item('chanbw')

--result.ts = os.time()
return result
end

function gws_radio.SET_RT(key, value)
DBG(sfmt("GWS4K> set_rt k=%s,value=%s (@%d)", key or '-', value or '-', os.time()))
local result = true
DBG(sfmt("GWS3K> set_rt k=%s,value=%s (@%d)", key or '-', value or '-', os.time()))
if (key == 'region') then
exec(sfmt(gws_radio.cmd.region_set, value))
result = false
elseif (key == 'channel' or key == 'channo') then
exec(sfmt(gws_radio.cmd.channel_set, value))
result = false
elseif (key == 'txpower' or key == 'txpwr') then
exec(sfmt(gws_radio.cmd.txpower_set, value))
result = false
elseif (key == 'rxgain') then
exec(sfmt(gws_radio.cmd.rxgain_set, value))
result = false
end
exec(gws_radio.cmd.rfinfo_clean)
gws_radio.rfinfo_clean()
return result
end

return gws_radio
147 changes: 147 additions & 0 deletions lib/arn/device/hal/gws_4k.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
--[[
Note:
Although GWS4K share the same methods and functions,
this copy will let maintainer handle 2 types of hardware.
by Qige <[email protected]>
2017.08.16 update_rt
]]--

local DBG = print
--local function DBG(msg) end

local ccff = require 'arn.utils.ccff'
local uhf = require 'arn.device.uhf'

local exec = ccff.execute
local vint = ccff.val.n
local sfmt = string.format
local ssub = string.sub
local slen = string.len

local gws_radio = {}

gws_radio.conf = {}
gws_radio.conf.val_length_max = 8

gws_radio.cmd = {}
gws_radio.cmd.rfinfo_clean = 'echo > /tmp/.GWS4Kv2.tmp'
gws_radio.cmd.rfinfo_lock = '/tmp/.GWS4Kv2.lock'
gws_radio.cmd.rfinfo_wait = 'sleep 2'
gws_radio.cmd.rfinfo = 'rfinfo 2>/dev/null > /tmp/.GWS4K.tmp'
gws_radio.cmd.region = 'cat /tmp/.GWS4K.tmp 2> /dev/null | grep Region -A1 | grep [01]* -o'
gws_radio.cmd.channel = 'cat /tmp/.GWS4K.tmp 2> /dev/null | grep Channel -A1 | grep [0-9]* -o'
gws_radio.cmd.txpower = 'cat /tmp/.GWS4K.tmp 2> /dev/null | grep ^Tx | grep Power | grep [0-9\.]* -o'
gws_radio.cmd.chanbw = 'uci get wireless.radio0.chanbw'

gws_radio.cmd.region_set = 'setregion %s 2> /dev/null '
gws_radio.cmd.channel_set = 'setchan %s 2> /dev/null '
gws_radio.cmd.txpower_set = 'settxpwr %s 2> /dev/null '
gws_radio.cmd.chanbw_set = 'setchanbw %s 2> /dev/null '
gws_radio.cmd.rxgain_set = 'setrxgain %s 2> /dev/null '

function gws_radio.update_init()
DBG(sfmt("GWS4K----> update_init()"))
-- v2.0 2017.10.19 enable read lock
rfinfo_lock = fread(gws_radio.cmd.rfinfo_lock)
if (rfinfo_lock ~= 'lock' and rfinfo_lock ~= 'lock\n') then
print(sfmt('%80s', '> updating radio <'))
DBG('note> updating device < lock:', rfinfo_lock)
fwrite(gws_radio.cmd.rfinfo_lock, 'lock')
exec(gws_radio.cmd.rfinfo)
fwrite(gws_radio.cmd.rfinfo_lock, 'unlock')
DBG('note> updated')
else
print(sfmt('%80s', '> device busy <'))
lock_counts = 3
while(rfinfo_lock == 'lock' or rfinfo_lock == 'lock\n') do
exec(gws_radio.cmd.rfinfo_wait)
rfinfo_lock = fread(gws_radio.cmd.rfinfo_lock)
lock_counts = lock_counts - 1
if (lock_counts < 0) then
print(sfmt('%80s', 'solving dead-lock'))
break
end
end
fwrite(gws_radio.cmd.rfinfo_lock, 'unlock') -- FIXME
end
--print(exec(gws_radio.cmd.rfinfo_all))
end

function gws_radio.rfinfo_clean()
exec(gws_radio.cmd.rfinfo_clean)
end

--[[
Tasks:
1. Return each value by key;
2. If result is too long, return first 8 chars.
]]--
function gws_radio.update_item(key)
local result
if (key == 'region') then
result = exec(gws_radio.cmd.region)
elseif (key == 'channel' or key == 'channo') then
result = exec(gws_radio.cmd.channel)
elseif (key == 'txpower' or key == 'txpwr') then
result = exec(gws_radio.cmd.txpower)
elseif (key == 'chanbw') then
result = exec(gws_radio.cmd.chanbw)
end
-- limit return length
local lmax = gws_radio.conf.val_length_max
if (result and slen(result) > lmax) then
result = ssub(result, 1, lmax)
end
return vint(result)
end

--[[
Tasks:
1. Do cli call;
2. Fetch each parameters from tmp file.
]]--
function gws_radio.UPDATE_RT()
DBG(sfmt("GWS4K> update_rt (@%d)", os.time()))
local result = {}

gws_radio.update_init()

DBG(sfmt("GWS4K----> update_item() region"))
result.region = gws_radio.update_item('region')

DBG(sfmt("GWS4K----> update_item() channel"))
result.channo = gws_radio.update_item('channel')
result.freq = uhf.channel_to_freq(result.region, result.channo)

DBG(sfmt("GWS4K----> update_item() txpower"))
result.txpwr = gws_radio.update_item('txpower')

DBG(sfmt("GWS4K----> update_item() chanbw"))
result.chanbw = gws_radio.update_item('chanbw')

--result.ts = os.time()
return result
end

function gws_radio.SET_RT(key, value)
local result = true
DBG(sfmt("GWS4K> set_rt k=%s,value=%s (@%d)", key or '-', value or '-', os.time()))
if (key == 'region') then
exec(sfmt(gws_radio.cmd.region_set, value))
result = false
elseif (key == 'channel' or key == 'channo') then
exec(sfmt(gws_radio.cmd.channel_set, value))
result = false
elseif (key == 'txpower' or key == 'txpwr') then
exec(sfmt(gws_radio.cmd.txpower_set, value))
result = false
elseif (key == 'rxgain') then
exec(sfmt(gws_radio.cmd.rxgain_set, value))
result = false
end
gws_radio.rfinfo_clean()
return result
end

return gws_radio
14 changes: 14 additions & 0 deletions lib/arn/device/hal/gws_5kv1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--[[
Note:
Although GWS5Kv1 & GWS5Kv2 share the same methods and functions,
this copy will let maintainer handle 2 types of hardware.
by Qige <[email protected]>
almost same as GWS5Kv2, it's a wrapper
]]--

--local DBG = print
local function DBG(msg) end

local gws_radio = require 'arn.device.hal.gws_5kv2'
return gws_radio
Loading

0 comments on commit 5c997a5

Please sign in to comment.