Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
f-interop-contributors
agent
Commits
3d8a32e9
Commit
3d8a32e9
authored
Sep 04, 2017
by
Federico Sismondi
Browse files
now serial listener uses messages library
parent
06faaefb
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/serial_listener.py
View file @
3d8a32e9
...
@@ -4,7 +4,7 @@ import json
...
@@ -4,7 +4,7 @@ import json
import
serial
import
serial
import
logging
import
logging
import
sys
import
sys
from
utils
import
messages
from
kombu
import
Exchange
from
kombu
import
Exchange
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
utils
import
arrow_down
,
arrow_up
,
finterop_banner
from
utils
import
arrow_down
,
arrow_up
,
finterop_banner
...
@@ -43,15 +43,46 @@ class SerialListener(object):
...
@@ -43,15 +43,46 @@ class SerialListener(object):
self
.
frame_slip
=
''
self
.
frame_slip
=
''
log
.
info
(
"opening serial reader.."
)
log
.
info
(
"opening serial reader.."
)
self
.
ser
=
serial
.
Serial
(
port
=
self
.
dev
,
try
:
baudrate
=
int
(
self
.
br
),
self
.
ser
=
serial
.
Serial
(
port
=
self
.
dev
,
timeout
=
0.001
baudrate
=
int
(
self
.
br
),
)
timeout
=
0.001
self
.
ser
.
flushInput
()
)
except
serial
.
serialutil
.
SerialException
as
e
:
log
.
error
(
e
)
log
.
error
(
'Does dev %s exist?'
%
serial_port
)
sys
.
exit
(
1
)
try
:
self
.
ser
.
close
()
except
Exception
as
e
:
log
.
debug
(
e
)
try
:
self
.
ser
.
open
()
except
Exception
as
e
:
log
.
debug
(
e
)
try
:
self
.
ser
.
flushInput
()
except
Exception
as
e
:
log
.
debug
(
e
)
self
.
mrkey
=
"data.serial.fromAgent.%s"
%
self
.
agent_name
self
.
data_plane_mrkey
=
"data.serial.fromAgent.%s"
%
self
.
agent_name
self
.
control_plane_mrkey
=
"data.serial.fromAgent.%s"
%
self
.
agent_name
self
.
message_read_count
=
0
self
.
message_read_count
=
0
# notify interface is opened
m
=
messages
.
MsgAgentSerialStarted
(
name
=
self
.
agent_name
,
port
=
self
.
dv
,
boudrate
=
self
.
br
)
self
.
producer
.
publish
(
m
.
to_json
(),
exchange
=
self
.
exchange
,
routing_key
=
self
.
control_plane_mrkey
)
def
close
(
self
):
def
close
(
self
):
self
.
_stop
=
True
self
.
_stop
=
True
...
@@ -122,21 +153,22 @@ class SerialListener(object):
...
@@ -122,21 +153,22 @@ class SerialListener(object):
return
ia
return
ia
def
send_amqp
(
self
,
data
,
data_slip
):
def
send_amqp
(
self
,
data
,
data_slip
):
body
=
OrderedDict
()
body
[
'_type'
]
=
'packet.sniffed.raw'
m
=
messages
.
MsgPacketSniffedRaw
(
body
[
'interface_name'
]
=
'serial'
interface_name
=
'serial'
,
body
[
'data'
]
=
self
.
convert_bytearray_to_intarray
(
bytearray
.
fromhex
(
data
))
data
=
self
.
convert_bytearray_to_intarray
(
bytearray
.
fromhex
(
data
)),
body
[
'data_slip'
]
=
self
.
convert_bytearray_to_intarray
(
bytearray
.
fromhex
(
data_slip
))
data_slip
=
self
.
convert_bytearray_to_intarray
(
bytearray
.
fromhex
(
data_slip
)),
)
self
.
frame_slip
=
''
self
.
frame_slip
=
''
self
.
producer
.
publish
(
body
,
self
.
producer
.
publish
(
m
.
to_json
()
,
exchange
=
self
.
exchange
,
exchange
=
self
.
exchange
,
routing_key
=
self
.
mrkey
)
routing_key
=
self
.
data_plane_
mrkey
)
print
(
arrow_up
)
print
(
arrow_up
)
log
.
info
(
'
\n
# # # # # # # # # # # # SERIAL INTERFACE # # # # # # # # # # # # '
+
log
.
info
(
'
\n
# # # # # # # # # # # # SERIAL INTERFACE # # # # # # # # # # # # '
+
'
\n
data packet Serial -> EventBus'
+
'
\n
data packet Serial -> EventBus'
+
'
\n
'
+
json
.
dumps
(
body
)
+
'
\n
'
+
m
.
to_json
(
)
+
'
\n
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # '
'
\n
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # '
)
)
...
...
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