EasyManuals Logo

Embedded Systems LM5p-GSMC User Manual

Default Icon
291 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #249 background imageLoading...
Page #249 background image
249
8.
comport
='ttyUSB2'
9.
-- open serial port
10.
modem
=
AT:init
('/dev/'
.. comport
)
11.
-- command parser
12.
parser
=function(
cmd, sender
)
13.
local
find, pos, name, mode, offset, value, jvalue, obj
14.
cmd
=
cmd:trim
()
15.
mode
=
cmd:sub
(
1, 1
)
:upper
()
16.
if
mode
=='W'or
mode
=='R'then
17.
cmd
=
cmd:sub
(3)
:trim
()
18.
-- parse object name/address
19.
find
=
cmd:sub
(1
,
1)=='"'and'"'or' '
20.
offset
=
find
=='"'and
1
or0
21.
-- pad with space when in read mode
22.
if
mode
=='R'and
find
==' 'then
23.
cmd
=
cmd ..
' '
24.
end
25.
-- find name
26.
pos
=
cmd:find
(
find, 1 + offset,
true)
27.
-- name end not found, stop
28.
ifnot
pos
then
29.
returnfalse
30.
end
31.
-- get name part
32.
name
=
cmd:sub
(
1 + offset, pos - offset
)
:trim
()
33.
if
mode
=='W'then
34.
value
=
cmd:sub
(
pos + offset
)
:trim
()
35.
ifnot
value
then
36.
returnfalse
37.
end
38.
-- try decoding value
39.
jvalue
=
json.pdecode
(
value
)
40.
value
=
jvalue ~
=niland
jvalue
or
value
41.
-- send to bus
42.
grp.
write(
name, value
)
43.
-- read request
44.
else
45.
obj
=
grp.find
(
name
)
46.
-- send read request and wait for update
47.
if
obj
then
48.
obj:
read()
49.
os
.sleep
(1)
50.
-- read new value
51.
value
=
grp.getvalue
(
name
)
52.
-- got value, send response
53.
if
value ~
=nilthen
54.
jvalue
=
json.pencode
(
value
)
55.
if
obj.name
then
56.
name
=string.format('%s (%s)'
, obj.name, obj.address
)
57.
end

Table of Contents

Other manuals for Embedded Systems LM5p-GSMC

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Embedded Systems LM5p-GSMC and is the answer not in the manual?

Embedded Systems LM5p-GSMC Specifications

General IconGeneral
BrandEmbedded Systems
ModelLM5p-GSMC
CategoryDimmer
LanguageEnglish

Related product manuals