Commit a33eeab5 authored by Federico Sismondi's avatar Federico Sismondi

small changes, enhaced error handling and logging

parent 34931c23
......@@ -38,7 +38,7 @@ class CoreConsumer(BaseConsumer):
routing_key=msg.routing_key
)
log.info("Agent READY, listening on the event bus for ctrl messages and data packets..")
log.info("Agent READY, listening on the event bus for ctrl messages and data packets...")
def _on_message(self, message):
self.log.warning(
......
# -*- coding: utf-8 -*-
import sys
import os
import json
import serial
......@@ -49,6 +49,15 @@ class SerialConsumer(BaseConsumer):
log.info('FINTEROP_CONNECTOR_SERIAL_PORT env var imported: %s' % self.serial_port)
log.info('FINTEROP_CONNECTOR_BAUDRATE env var imported: %s' % self.baudrate)
except KeyError as e:
logging.error(
'Cannot retrieve environment variables for serial connection: '
'FINTEROP_CONNECTOR_SERIAL_PORT/FINTEROP_CONNECTOR_BAUDRATE '
'please make sure these have been exported before starging agent'
)
sys.exit(1)
try:
# open a subprocess to listen the serialport
params = {
'agent_name': self.name,
......@@ -62,11 +71,11 @@ class SerialConsumer(BaseConsumer):
serial_listener_th.daemon = True
serial_listener_th.start()
except KeyError as e:
logging.warning(
'Cannot retrieve environment variables for serial connection: '
'FINTEROP_CONNECTOR_SERIAL_PORT/FINTEROP_CONNECTOR_BAUDRATE '
'If no sniffer/injector needed for test ignore this warning ')
except Exception as e:
log.error(e)
sys.exit(1)
log.info('%s bootstraped.' % self.name)
def handle_data(self, message):
"""
......
......@@ -83,7 +83,7 @@ class SerialListener(object):
self.state = STATE_OK
self.frame_slip = ''
log.info("opening serial reader..")
log.info("opening serial reader...")
try:
self.ser = serial.Serial(port=self.dev,
baudrate=int(self.br),
......@@ -206,7 +206,7 @@ class SerialListener(object):
)
def run(self):
log.info("starting serial reader thread..")
log.info("starting serial reader thread...")
try:
while not self.closed():
numbytes = self.ser.inWaiting()
......
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