Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBus Network #218

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/emonhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def __init__(self, setup):
eha.auto_conf_enabled = self.autoconf.enabled
except eha.EmonHubAutoConfError as e:
logger.error(e)
sys.exit("Unable to load available.conf")
self._exit = True # Exit process if main thread cannot start

def run(self):
"""Launch the hub.

Expand Down
19 changes: 11 additions & 8 deletions src/emonhub_auto_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ def __init__(self,settings):

if self.enabled:
self._log.debug("Automatic configuration of nodes enabled")


# Initialize attribute settings as a ConfigObj instance
try:
result = ConfigObj(filename, file_error=True)
self.available = self.prepare_available(result['available'])
except Exception as e:
raise EmonHubAutoConfError(e)

else:
self._log.debug("Automatic configuration of nodes disabled")

# Initialize attribute settings as a ConfigObj instance
try:
result = ConfigObj(filename, file_error=True)
self.available = self.prepare_available(result['available'])
except Exception as e:
raise EmonHubAutoConfError(e)
self._log.debug("Automatic configuration of nodes disabled")
self.available = None

def prepare_available(self,nodes):
for n in nodes:
Expand Down
66 changes: 38 additions & 28 deletions src/emonhub_interfacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def __init__(self, name):
'nodeoffset': '0',
'pubchannels': [],
'subchannels': [],
'batchsize': '1',
'nodelistonly': False
}
'batchsize': '1'}

self.init_settings = {}
self._settings = {}
Expand Down Expand Up @@ -90,34 +88,54 @@ def __init__(self, name):
self.missed = {}
self.rx_msg = {}

def processRxc(self, rxc):
if rxc:
rxc = self._process_rx(rxc)
if rxc:
for channel in self._settings["pubchannels"]:
self._log.debug("%d Sent to channel(start)' : %s", rxc.uri, channel)

# Initialise channel if needed
if channel not in self._pub_channels:
self._pub_channels[channel] = []

# Add cargo item to channel
self._pub_channels[channel].append(rxc)

self._log.debug("%d Sent to channel(end)' : %s", rxc.uri, channel)

@log_exceptions_from_class_method
def run(self):
"""
Run the interfacer.
Any regularly performed tasks actioned here along with passing received values

"""
self._log.info("self: {}".format(self.name))

self._log.info("subs:")
for item in self._settings["subchannels"]:
self._log.info("sub: {}".format(item))

self._log.info("pubs:")
for item in self._settings["pubchannels"]:
self._log.info("pub: {}".format(item))

while not self.stop:

# Only read if there is a pub channel defined for the interfacer
if len(self._settings["pubchannels"]):
# Read the input and process data if available
rxc = self.read()
if rxc:
rxc = self._process_rx(rxc)
if rxc:
for channel in self._settings["pubchannels"]:
self._log.debug("%d Sent to channel(start)' : %s", rxc.uri, channel)

# Initialise channel if needed
if channel not in self._pub_channels:
self._pub_channels[channel] = []

# Add cargo item to channel
self._pub_channels[channel].append(rxc)

self._log.debug("%d Sent to channel(end)' : %s", rxc.uri, channel)

result = self.read()
if isinstance(result, list):
for rxc in result:
self.processRxc(rxc)
elif isinstance(result, dict):
for rxc in result:
self.processRxc(result[rxc])
else:
self.processRxc(result)

# Subscriber channels
for channel in self._settings["subchannels"]:
if channel in self._sub_channels:
Expand Down Expand Up @@ -289,13 +307,7 @@ def _process_rx(self, cargo):
if 'nodeids' in ehc.nodelist[node]:
del ehc.nodelist[node]['nodeids']
if 'datalength' in ehc.nodelist[node]:
del ehc.nodelist[node]['datalength']


# If not in nodelist and pass through disabled return false
if node not in ehc.nodelist and self._settings['nodelistonly']:
self._log.warning("%d Discarded RX frame not in nodelist, node:%s, length:%s bytes", cargo.uri, node, len(rxc.realdata))
return False
del ehc.nodelist[node]['datalength']

# Data whitening uses for ensuring rfm sync
if node in ehc.nodelist and 'rx' in ehc.nodelist[node] and 'whitening' in ehc.nodelist[node]['rx']:
Expand Down Expand Up @@ -636,8 +648,6 @@ def set(self, **kwargs):
setting = str(setting).lower() == "true"
elif key == 'targeted' and str(setting).lower() in ['true', 'false']:
setting = str(setting).lower() == "true"
elif key == 'nodelistonly' and str(setting).lower() in ['true', 'false','1','0']:
setting = str(setting).lower() == "true" or str(setting).lower() == "1"
elif key == 'pubchannels':
pass
elif key == 'subchannels':
Expand Down
Loading