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

Minor fixes to NotifReader #10

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions libs/SmartMeshSDK/HartMgrConnector/NotifReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NotifSeparator(object):
from the stream and treats the notification as a string.

In the HartMgrConnector, the notification XML string is parsed by
the HartMgrDefinition.
the HartMgrDefinition.
"""
NOTIF_TYPES = [ 'data', 'event', 'measurement', 'log', 'cli', 'stdMoteReport', 'vendorMoteReport' ]

Expand All @@ -45,7 +45,7 @@ def _parse_one(self):
if idx != -1 and idx < notif_start:
current_notif = nt
notif_start = idx

if current_notif:
end_el = '</%s>' % current_notif
notif_end = self.buffer.find(end_el)
Expand All @@ -63,8 +63,8 @@ def parse(self, input_str):
# Parse as many notifications as possible
while self._parse_one():
pass


def _handle_notif(self, notif_type, notif_str):
'Pass the notification to the callback handler and clean up'
log.debug('NOTIF: %s' % notif_str)
Expand Down Expand Up @@ -106,7 +106,7 @@ def connect(self):
log.info("Connected to notification channel")
# send authentication
log.debug("Sending notif authentication: %s" % self.notif_token)
self.notif_socket.send(self._build_auth())
self.notif_socket.send(self._build_auth().encode("utf8"))
self.connected = True
except socket.error as e:
log.error('Exception reading from notification channel: ' + str(e))
Expand All @@ -121,6 +121,7 @@ def run(self):
if not input_data:
log.info('Notification channel closed')
break
input_data = input_data.decode("utf-8")
msg = 'Notif input [%d]: %s' % (len(input_data), input_data)
log.debug(msg)
try:
Expand All @@ -146,12 +147,12 @@ def run(self):

DEFAULT_HOST = '10.10.16.126'
DEFAULT_PORT = 4445

pp = pprint.PrettyPrinter()

mgr = HartMgrConnectorInternal.HartMgrConnectorInternal()
mgr.connect({'host': DEFAULT_HOST, 'port': DEFAULT_PORT})

notif_token, notif_port = mgr.subscribe('data events')
print ('Subscribe')

Expand Down