Skip to content

Commit

Permalink
SMSDK release 1.3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dbacher-linear committed Jul 23, 2019
1 parent a616e36 commit 38ce2af
Show file tree
Hide file tree
Showing 8 changed files with 602 additions and 338 deletions.
2 changes: 1 addition & 1 deletion PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: SmartMeshSDK
Version: 1.3.0.1
Version: 1.3.1.2
Summary: UNKNOWN
Home-page: UNKNOWN
Author: Linear Technology
Expand Down
18 changes: 13 additions & 5 deletions app/JsonServer/JsonServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@

pp = pprint.PrettyPrinter(indent=4)

def str2bool(v):
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')

#============================ classes =========================================

class JsonServer(object):
Expand Down Expand Up @@ -478,10 +486,10 @@ def main(args):

if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--tcpport', default=8080)
parser.add_argument('--autoaddmgr', default=True)
parser.add_argument('--autodeletemgr', default=True)
parser.add_argument('--serialport', default=None)
parser.add_argument('--configfilename', default='JsonServer.config')
parser.add_argument('--tcpport', default=8080)
parser.add_argument('--autoaddmgr', type=str2bool,default=True)
parser.add_argument('--autodeletemgr',type=str2bool,default=True)
parser.add_argument('--serialport', default=None)
parser.add_argument('--configfilename', default='JsonServer.config')
args = vars(parser.parse_args())
main(args)
140 changes: 73 additions & 67 deletions app/NetworkHealth/NetworkHealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
sys.path.insert(0, os.path.join(here, '..', '..','libs'))
sys.path.insert(0, os.path.join(here, '..', '..','external_libs'))

#============================ verify installation =============================

from SmartMeshSDK.utils import SmsdkInstallVerifier
(goodToGo,reason) = SmsdkInstallVerifier.verifyComponents(
[
SmsdkInstallVerifier.PYTHON,
SmsdkInstallVerifier.PYSERIAL,
]
)
if not goodToGo:
print "Your installation does not allow this application to run:\n"
print reason
raw_input("Press any button to exit")
sys.exit(1)

#============================ imports =========================================

# built-in
Expand All @@ -24,6 +39,7 @@
ConnectionError, \
CommandTimeoutError
from SmartMeshSDK.protocols.NetworkHealthAnalyzer import NetworkHealthAnalyzer
from SmartMeshSDK.protocols.Hr import HrParser

# DustCli
from dustCli import DustCli
Expand All @@ -33,11 +49,10 @@
#============================ globals =========================================

connector = None
notifThread = None
snapshotThread = None

#============================ helpers =========================================

def printExcAndQuit(err):

output = []
Expand All @@ -56,63 +71,37 @@ def printExcAndQuit(err):

#============================ threads =========================================

class NotifThread(object):
class SnapshotThread(threading.Thread):

SNAPSHOTDELAY_INITIAL_S = 5
DFLT_SNAPSHOTPERIOD = 3600

def __init__(self,connector):

# store params
self.connector = connector
self.connector = connector

# local variables
self.goOn = True
self.dataLock = threading.RLock()
self.delayCounter = self.SNAPSHOTDELAY_INITIAL_S
self.snapshotPeriod = self.DFLT_SNAPSHOTPERIOD
self.networkHealthAnalyzer = NetworkHealthAnalyzer.NetworkHealthAnalyzer()
self.hrParser = HrParser.HrParser()
self.lastResults = ""
self.dataForAnalyzer = {}
self.dataForAnalyzer['devicehr'] = {}

# subscriber
# subscribe
self.subscriber = IpMgrSubscribe.IpMgrSubscribe(self.connector)
self.subscriber.start()
self.subscriber.subscribe(
notifTypes = [
IpMgrSubscribe.IpMgrSubscribe.NOTIFHEALTHREPORT,
],
fun = self._notifHealthReportCb,
isRlbl = True,
isRlbl = False,
)
'''
self.subscriber.subscribe(
notifTypes = [
IpMgrSubscribe.IpMgrSubscribe.ERROR,
IpMgrSubscribe.IpMgrSubscribe.FINISH,
],
fun = self.disconnectedCallback,
isRlbl = True,
)
'''

#======================== public ==========================================

def disconnect(self):
self.connector.disconnect()

#======================== private =========================================

def _notifHealthReportCb(self, notifName, notifParams):
print notifName
print notifParams
print "TODO _notifHealthReportCb"

class SnapshotThread(threading.Thread):

SNAPSHOTDELAY_INITIAL_S = 5
DFLT_SNAPSHOTPERIOD = 3600

def __init__(self,connector):

# store params
self.connector = connector

# local variables
self.goOn = True
self.dataLock = threading.RLock()
self.delayCounter = self.SNAPSHOTDELAY_INITIAL_S
self.snapshotPeriod = self.DFLT_SNAPSHOTPERIOD
self.networkHealthAnalyzer = NetworkHealthAnalyzer.NetworkHealthAnalyzer()
self.lastResults = ""

# initialize parent
threading.Thread.__init__(self)
Expand All @@ -121,8 +110,6 @@ def __init__(self,connector):
# start itself
self.start()

#======================== thread ==========================================

def run(self):

try:
Expand Down Expand Up @@ -174,19 +161,39 @@ def close(self):

with self.dataLock:
self.goOn = False

#======================== private =========================================

def _notifHealthReportCb(self, notifName, notifParams):

try:
with self.dataLock:

assert notifName==IpMgrSubscribe.IpMgrSubscribe.NOTIFHEALTHREPORT

mac = notifParams.macAddress
hr = self.hrParser.parseHr(notifParams.payload)

if ('Device' in hr):

self.dataForAnalyzer['devicehr'][tuple(mac)] = hr['Device']

except Exception as err:
print type(err)
print err
raise

def _doSnapshot(self):

try:
with self.dataLock:

dataForAnalyzer = {}
motes = []

self.dataForAnalyzer['moteinfo'] = {}
self.dataForAnalyzer['networkpaths'] = {}
self.dataForAnalyzer['networkinfo'] = {}
motes = []

# getMoteConfig on all motes
dataForAnalyzer['moteinfo'] = {}
currentMac = (0,0,0,0,0,0,0,0) # start getMoteConfig() iteration with the 0 MAC address
continueAsking = True
while continueAsking:
Expand All @@ -197,16 +204,15 @@ def _doSnapshot(self):
else:
currentMac = res.macAddress
motes += [currentMac]
dataForAnalyzer['moteinfo'][tuple(currentMac)] = self._namedTupleToDict(res)

self.dataForAnalyzer['moteinfo'][tuple(currentMac)] = self._namedTupleToDict(res)
# getMoteInfo on all motes
for mac in motes:
res = self.connector.dn_getMoteInfo(mac)
for (k,v) in self._namedTupleToDict(res).items():
dataForAnalyzer['moteinfo'][tuple(mac)][k] = v
self.dataForAnalyzer['moteinfo'][tuple(mac)][k] = v

# get path info on all paths of all motes
dataForAnalyzer['networkpaths'] = {}
# getNextPathInfo on all paths of all motes
for mac in motes:
currentPathId = 0
continueAsking = True
Expand All @@ -215,16 +221,20 @@ def _doSnapshot(self):
res = self.connector.dn_getNextPathInfo(mac,0,currentPathId)
fromMAC = tuple(res.source)
toMAC = tuple(res.dest)
dataForAnalyzer['networkpaths'][(fromMAC,toMAC)] = self._namedTupleToDict(res)
self.dataForAnalyzer['networkpaths'][(fromMAC,toMAC)] = self._namedTupleToDict(res)
except APIError:
continueAsking = False
else:
currentPathId = res.pathId

# getNetworkInfo
res = self.connector.dn_getNetworkInfo()
self.dataForAnalyzer['networkinfo'] = self._namedTupleToDict(res)

print "running test at {0}".format(self._now())

# run NetworkHealthAnalyzer
results = self.networkHealthAnalyzer.analyze(dataForAnalyzer)
results = self.networkHealthAnalyzer.analyze(self.dataForAnalyzer)

# format the results
self.lastResults = self._formatResults(results)
Expand All @@ -234,7 +244,7 @@ def _doSnapshot(self):

except Exception as err:
printExcAndQuit(err)

def _formatResults(self,results):
output = []
output += ['']
Expand Down Expand Up @@ -288,17 +298,17 @@ def _namedTupleToDict(self,nt):
def _now(self):
return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())


#============================ CLI handlers ====================================

def connect_clicb(params):
global connector
global notifThread
global snapshotThread

# filter params
port = params[0]

# create a coonnector
# create a connector
connector = IpMgrConnectorSerial.IpMgrConnectorSerial()

# connect to the manager
Expand All @@ -310,7 +320,6 @@ def connect_clicb(params):
printExcAndQuit(err)

# start threads
notifThread = NotifThread(connector)
snapshotThread = SnapshotThread(connector)

def now_clicb(params):
Expand Down Expand Up @@ -339,13 +348,10 @@ def period_clicb(params):

def quit_clicb():
global connector
global notifThread
global snapshotThread

if connector:
connector.disconnect()
if notifThread:
notifThread.disconnect()
if snapshotThread:
snapshotThread.close()

Expand Down
10 changes: 8 additions & 2 deletions libs/SmartMeshSDK/ApiDefinition/ByteArraySerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ def serialize(self,commandArray,fieldsToFill):
raise SystemError('unknown field format='+field.format)

# padding
while len(thisFieldByteArray)<field.length:
thisFieldByteArray = [0x00]+thisFieldByteArray
if field.length :
numPadding = field.length - len(thisFieldByteArray)
if numPadding > 0 :
padding = [0] * numPadding
if field.format==ApiDefinition.FieldFormats.STRING:
thisFieldByteArray = thisFieldByteArray + padding
else :
thisFieldByteArray = padding + thisFieldByteArray

byteArray = byteArray+thisFieldByteArray

Expand Down
Loading

0 comments on commit 38ce2af

Please sign in to comment.