Commit 3d8a32e9 authored by Federico Sismondi's avatar Federico Sismondi
Browse files

now serial listener uses messages library

parent 06faaefb
......@@ -4,7 +4,7 @@ import json
import serial
import logging
import sys
from utils import messages
from kombu import Exchange
from collections import OrderedDict
from utils import arrow_down, arrow_up, finterop_banner
......@@ -43,15 +43,46 @@ class SerialListener(object):
self.frame_slip = ''
log.info("opening serial reader..")
self.ser = serial.Serial(port=self.dev,
baudrate=int(self.br),
timeout=0.001
)
self.ser.flushInput()
try:
self.ser = serial.Serial(port=self.dev,
baudrate=int(self.br),
timeout=0.001
)
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
# 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):
self._stop = True
......@@ -122,21 +153,22 @@ class SerialListener(object):
return ia
def send_amqp(self, data, data_slip):
body = OrderedDict()
body['_type'] = 'packet.sniffed.raw'
body['interface_name'] = 'serial'
body['data'] = self.convert_bytearray_to_intarray(bytearray.fromhex(data))
body['data_slip'] = self.convert_bytearray_to_intarray(bytearray.fromhex(data_slip))
m = messages.MsgPacketSniffedRaw(
interface_name='serial',
data=self.convert_bytearray_to_intarray(bytearray.fromhex(data)),
data_slip=self.convert_bytearray_to_intarray(bytearray.fromhex(data_slip)),
)
self.frame_slip = ''
self.producer.publish(body,
self.producer.publish(m.to_json(),
exchange=self.exchange,
routing_key=self.mrkey)
routing_key=self.data_plane_mrkey)
print(arrow_up)
log.info('\n # # # # # # # # # # # # SERIAL INTERFACE # # # # # # # # # # # # ' +
'\n data packet Serial -> EventBus' +
'\n' + json.dumps(body) +
'\n' + m.to_json() +
'\n # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # '
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment