Developing lightweight computation at the DSG edge
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Quick Mesh Project
qMp packages
Commits
76002a9c
Commit
76002a9c
authored
Oct 22, 2012
by
p4u
Browse files
Improved debug, util and model libraries. Modified wifi to be compatible with new changes
parent
102b990b
Changes
4
Hide whitespace changes
Inline
Side-by-side
packages/qmp-small-node/files/etc/qmp/qmplua/debug.lua
View file @
76002a9c
...
...
@@ -21,13 +21,40 @@
--]]
debug
=
{}
local
namespace
=
"Main"
local
stdout
=
"-s"
local
priority
=
"-p 7"
function
debug
.
set_namespace
(
t
)
if
t
~=
nil
then
namespace
=
t
end
end
function
debug
.
set_priotiry
(
n
)
if
n
then
priority
=
"-p "
..
n
else
priotiry
=
""
end
end
function
debug
.
set_stdout
(
b
)
if
b
then
stdout
=
"-s"
else
stdout
=
""
end
end
--- Add one line to the system log file with the tag qMp
-- @class function
-- @name logger
-- @param msg string
function
debug
.
logger
(
msg
)
os.execute
(
'logger -t qMp '
..
msg
)
local
logger
=
string.format
(
"logger %s %s -t qMp[%s] '"
,
stdout
,
priority
,
namespace
)
local
status
,
c
=
pcall
(
os.execute
,
logger
..
msg
..
"'"
)
return
status
end
return
debug
packages/qmp-small-node/files/etc/qmp/qmplua/model.lua
View file @
76002a9c
...
...
@@ -191,20 +191,22 @@ end
-- @param option UCI option (optional)
-- @return Table or UCI value
function
model
.
get_type
(
type
,
index
,
option
)
local
typeout
=
nil
if
index
then
if
option
then
return
model
.
get_type_option
(
type
,
index
,
option
)
typeout
=
model
.
get_type_option
(
type
,
index
,
option
)
else
return
model
.
get_type_index
(
type
,
index
)
typeout
=
model
.
get_type_index
(
type
,
index
)
end
else
return
model
.
get_all_type
(
type
)
typeout
=
model
.
get_all_type
(
type
)
end
return
typeout
end
--- Get a table with all the sections of a given type
-- @param type UCI section type
-- @return
Table
-- @return Table
function
model
.
get_all_type
(
type
)
local
status
,
c
=
pcall
(
model
.
raw
)
if
not
status
then
...
...
@@ -220,23 +222,25 @@ function model.get_all_type(type)
end
end
---
G
et a table with the information of the section of a given type and index
---
R
et
urns
a table with the information of the section of a given type and index
-- @param type UCI section type
-- @param index UCI section type index
-- @return
Table
-- @return Table
function
model
.
get_type_index
(
type
,
index
)
local
status
,
c
=
pcall
(
model
.
raw
)
if
not
status
then
debug
.
logger
(
c
)
return
nil
else
local
gt
=
{}
if
c
:
foreach
(
model
.
get_file
(),
type
,
function
(
t
)
if
t
[
'.index'
]
==
tostring
(
index
)
then
table.insert
(
gt
,
t
)
end
end
)
then
return
gt
else
return
false
end
end
local
typeout
=
nil
c
:
foreach
(
model
.
get_file
(),
type
,
function
(
t
)
if
t
[
'.index'
]
==
index
then
typeout
=
t
return
end
end
)
return
typeout
end
--- Get an option of the section of a given type and index
...
...
@@ -244,7 +248,7 @@ end
-- @param type UCI section type
-- @param index UCI section type index
-- @param option UCI option
-- @return
UCI value
-- @return UCI value
function
model
.
get_type_option
(
type
,
index
,
option
)
local
status
,
c
=
pcall
(
model
.
raw
)
if
not
status
then
...
...
@@ -252,7 +256,7 @@ function model.get_type_option(type, index, option)
return
nil
else
local
gt
=
{}
if
c
:
foreach
(
model
.
get_file
(),
type
,
function
(
t
)
if
t
[
'.index'
]
==
tostring
(
index
)
then
table.insert
(
gt
,
t
)
end
end
)
then
if
c
:
foreach
(
model
.
get_file
(),
type
,
function
(
t
)
if
t
[
'.index'
]
==
index
then
table.insert
(
gt
,
t
)
end
end
)
then
return
gt
[
option
]
else
return
false
...
...
@@ -260,6 +264,33 @@ function model.get_type_option(type, index, option)
end
end
-- Return the index number from the given type
-- if option and value are specified then it only returns the section types with option=value
-- if not specified it returns all indexes
-- This index number can be used to call other functions like get_type_option(type,index,option)
-- @return array
function
model
.
get_indextype
(
type
,
option
,
value
)
local
status
,
c
=
pcall
(
model
.
raw
)
if
not
status
then
debug
.
logger
(
c
)
return
nil
end
local
index
=
{}
c
:
foreach
(
model
.
get_file
(),
type
,
function
(
t
)
if
option
==
nil
then
table.insert
(
index
,
t
[
'.index'
])
elseif
t
[
option
]
==
value
then
table.insert
(
index
,
t
[
'.index'
])
end
end
)
return
index
end
--- Commit the changed done with a UCI-Cursor
-- @class function
-- @name commit
...
...
packages/qmp-small-node/files/etc/qmp/qmplua/util.lua
View file @
76002a9c
...
...
@@ -24,12 +24,33 @@ luciutil = require "luci.util"
util
=
{}
util
.
luci
=
luciutil
-- Replace p1 for p2
-- Replace p1 for p2
, p1 might be an array
function
util
.
replace
(
s
,
p1
,
p2
)
return
string.gsub
(
s
,
p1
,
p2
)
if
s
==
nil
then
return
nil
end
local
sout
if
type
(
p1
)
==
"table"
then
local
i
,
p
sout
=
s
for
i
,
p
in
ipairs
(
p1
)
do
sout
=
string.gsub
(
sout
,
p
,
p2
)
end
else
sout
=
string.gsub
(
s
,
p1
,
p2
)
end
return
sout
end
function
util
.
find
(
s
,
p
)
return
string.find
(
s
,
p
)
end
function
util
.
printf
(
...
)
local
s
,
c
=
pcall
(
string.format
,
...
)
if
not
s
then
c
=
""
end
return
c
end
return
util
packages/qmp-small-node/files/etc/qmp/qmplua/wifi.lua
View file @
76002a9c
...
...
@@ -29,22 +29,40 @@ wifi = {}
wifi
.
info
=
{}
function
wifi
.
apply
(
dev
)
local
wdev
=
model
.
get_type_by_option
(
'wireless'
,
'device'
,
dev
)
debug
.
set_namespace
(
"WiFi"
)
debug
.
logger
(
util
.
printf
(
"Executing wifi.apply(%s)"
,
dev
))
local
index
=
model
.
get_indextype
(
"wireless"
,
"device"
,
dev
)[
1
]
local
wdev
=
model
.
get_type
(
"wireless"
,
index
)
if
wdev
==
nil
then
debug
.
logger
(
util
.
printf
(
"Device %s cannot be found!"
,
dev
))
end
if
wdev
.
mode
==
"none"
then
debug
.
logger
(
"Device "
..
dev
..
" mode is none, qMp wont configure it"
)
debug
.
logger
(
"Device "
..
dev
..
" mode is none, qMp won
'
t configure it"
)
return
true
end
debug
.
logger
(
util
.
printf
(
"From model: index=%s wdev=%s"
,
index
,
wdev
))
-- Getting all parameters and checking no one is nil
local
mode
=
wdev
.
mode
||
return
nil
local
channel
=
util
.
replace
(
wdev
.
channel
,
''
,(
'+'
,
'-'
))
||
return
nil
local
channel_mode
=
util
.
replace
(
wdev
.
channel
,
''
,
"[0-9]"
)
||
return
nil
local
name
=
wdev
.
name
||
return
nil
local
mac
=
wdev
.
mac
||
return
nil
local
device
=
wdev
.
device
||
return
nil
local
mode
=
wdev
.
mode
local
channel
=
util
.
replace
(
wdev
.
channel
,{
'+'
,
'-'
},
''
)
local
channel_mode
=
util
.
replace
(
wdev
.
channel
,
"[0-9]"
,
''
)
local
name
=
wdev
.
name
local
mac
=
wdev
.
mac
local
device
=
wdev
.
device
if
not
(
mode
and
channel
and
channel_mode
and
name
and
mac
and
device
)
then
debug
.
logger
(
"Some missing parameter, cannot apply"
)
return
false
end
local
template
=
nil
debug
.
logger
(
"Channel is "
..
channel
)
debug
.
logger
(
"Channel mode is "
..
channel_mode
)
-- chnanel_mode: HT40 = 10+/- | 802.11b = 10b | 802.11ag or HT20 = 10
if
channel_mode
~=
"b"
then
if
#
channel_mode
~=
0
and
wifi
.
info
.
modes
(
dev
).
n
then
...
...
@@ -55,7 +73,7 @@ function wifi.apply(dev)
else
template
=
mode
..
"-b"
end
debug
.
logger
(
"Selected template is "
..
template
)
end
function
wifi
.
info
.
modes
(
dev
)
...
...
@@ -66,4 +84,3 @@ function wifi.info.modes(dev)
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment