Skip to content

Commit 38ce2af

Browse files
SMSDK release 1.3.1.2
1 parent a616e36 commit 38ce2af

File tree

8 files changed

+602
-338
lines changed

8 files changed

+602
-338
lines changed

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.0
22
Name: SmartMeshSDK
3-
Version: 1.3.0.1
3+
Version: 1.3.1.2
44
Summary: UNKNOWN
55
Home-page: UNKNOWN
66
Author: Linear Technology

app/JsonServer/JsonServer.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838

3939
pp = pprint.PrettyPrinter(indent=4)
4040

41+
def str2bool(v):
42+
if v.lower() in ('yes', 'true', 't', 'y', '1'):
43+
return True
44+
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
45+
return False
46+
else:
47+
raise argparse.ArgumentTypeError('Boolean value expected.')
48+
4149
#============================ classes =========================================
4250

4351
class JsonServer(object):
@@ -478,10 +486,10 @@ def main(args):
478486

479487
if __name__=="__main__":
480488
parser = argparse.ArgumentParser()
481-
parser.add_argument('--tcpport', default=8080)
482-
parser.add_argument('--autoaddmgr', default=True)
483-
parser.add_argument('--autodeletemgr', default=True)
484-
parser.add_argument('--serialport', default=None)
485-
parser.add_argument('--configfilename', default='JsonServer.config')
489+
parser.add_argument('--tcpport', default=8080)
490+
parser.add_argument('--autoaddmgr', type=str2bool,default=True)
491+
parser.add_argument('--autodeletemgr',type=str2bool,default=True)
492+
parser.add_argument('--serialport', default=None)
493+
parser.add_argument('--configfilename', default='JsonServer.config')
486494
args = vars(parser.parse_args())
487495
main(args)

app/NetworkHealth/NetworkHealth.py

Lines changed: 73 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@
99
sys.path.insert(0, os.path.join(here, '..', '..','libs'))
1010
sys.path.insert(0, os.path.join(here, '..', '..','external_libs'))
1111

12+
#============================ verify installation =============================
13+
14+
from SmartMeshSDK.utils import SmsdkInstallVerifier
15+
(goodToGo,reason) = SmsdkInstallVerifier.verifyComponents(
16+
[
17+
SmsdkInstallVerifier.PYTHON,
18+
SmsdkInstallVerifier.PYSERIAL,
19+
]
20+
)
21+
if not goodToGo:
22+
print "Your installation does not allow this application to run:\n"
23+
print reason
24+
raw_input("Press any button to exit")
25+
sys.exit(1)
26+
1227
#============================ imports =========================================
1328

1429
# built-in
@@ -24,6 +39,7 @@
2439
ConnectionError, \
2540
CommandTimeoutError
2641
from SmartMeshSDK.protocols.NetworkHealthAnalyzer import NetworkHealthAnalyzer
42+
from SmartMeshSDK.protocols.Hr import HrParser
2743

2844
# DustCli
2945
from dustCli import DustCli
@@ -33,11 +49,10 @@
3349
#============================ globals =========================================
3450

3551
connector = None
36-
notifThread = None
3752
snapshotThread = None
3853

3954
#============================ helpers =========================================
40-
55+
4156
def printExcAndQuit(err):
4257

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

5772
#============================ threads =========================================
5873

59-
class NotifThread(object):
74+
class SnapshotThread(threading.Thread):
75+
76+
SNAPSHOTDELAY_INITIAL_S = 5
77+
DFLT_SNAPSHOTPERIOD = 3600
6078

6179
def __init__(self,connector):
6280

6381
# store params
64-
self.connector = connector
82+
self.connector = connector
83+
84+
# local variables
85+
self.goOn = True
86+
self.dataLock = threading.RLock()
87+
self.delayCounter = self.SNAPSHOTDELAY_INITIAL_S
88+
self.snapshotPeriod = self.DFLT_SNAPSHOTPERIOD
89+
self.networkHealthAnalyzer = NetworkHealthAnalyzer.NetworkHealthAnalyzer()
90+
self.hrParser = HrParser.HrParser()
91+
self.lastResults = ""
92+
self.dataForAnalyzer = {}
93+
self.dataForAnalyzer['devicehr'] = {}
6594

66-
# subscriber
95+
# subscribe
6796
self.subscriber = IpMgrSubscribe.IpMgrSubscribe(self.connector)
6897
self.subscriber.start()
6998
self.subscriber.subscribe(
7099
notifTypes = [
71100
IpMgrSubscribe.IpMgrSubscribe.NOTIFHEALTHREPORT,
72101
],
73102
fun = self._notifHealthReportCb,
74-
isRlbl = True,
103+
isRlbl = False,
75104
)
76-
'''
77-
self.subscriber.subscribe(
78-
notifTypes = [
79-
IpMgrSubscribe.IpMgrSubscribe.ERROR,
80-
IpMgrSubscribe.IpMgrSubscribe.FINISH,
81-
],
82-
fun = self.disconnectedCallback,
83-
isRlbl = True,
84-
)
85-
'''
86-
87-
#======================== public ==========================================
88-
89-
def disconnect(self):
90-
self.connector.disconnect()
91-
92-
#======================== private =========================================
93-
94-
def _notifHealthReportCb(self, notifName, notifParams):
95-
print notifName
96-
print notifParams
97-
print "TODO _notifHealthReportCb"
98-
99-
class SnapshotThread(threading.Thread):
100-
101-
SNAPSHOTDELAY_INITIAL_S = 5
102-
DFLT_SNAPSHOTPERIOD = 3600
103-
104-
def __init__(self,connector):
105-
106-
# store params
107-
self.connector = connector
108-
109-
# local variables
110-
self.goOn = True
111-
self.dataLock = threading.RLock()
112-
self.delayCounter = self.SNAPSHOTDELAY_INITIAL_S
113-
self.snapshotPeriod = self.DFLT_SNAPSHOTPERIOD
114-
self.networkHealthAnalyzer = NetworkHealthAnalyzer.NetworkHealthAnalyzer()
115-
self.lastResults = ""
116105

117106
# initialize parent
118107
threading.Thread.__init__(self)
@@ -121,8 +110,6 @@ def __init__(self,connector):
121110
# start itself
122111
self.start()
123112

124-
#======================== thread ==========================================
125-
126113
def run(self):
127114

128115
try:
@@ -174,19 +161,39 @@ def close(self):
174161

175162
with self.dataLock:
176163
self.goOn = False
177-
164+
178165
#======================== private =========================================
179166

167+
def _notifHealthReportCb(self, notifName, notifParams):
168+
169+
try:
170+
with self.dataLock:
171+
172+
assert notifName==IpMgrSubscribe.IpMgrSubscribe.NOTIFHEALTHREPORT
173+
174+
mac = notifParams.macAddress
175+
hr = self.hrParser.parseHr(notifParams.payload)
176+
177+
if ('Device' in hr):
178+
179+
self.dataForAnalyzer['devicehr'][tuple(mac)] = hr['Device']
180+
181+
except Exception as err:
182+
print type(err)
183+
print err
184+
raise
185+
180186
def _doSnapshot(self):
181187

182188
try:
183189
with self.dataLock:
184190

185-
dataForAnalyzer = {}
186-
motes = []
187-
191+
self.dataForAnalyzer['moteinfo'] = {}
192+
self.dataForAnalyzer['networkpaths'] = {}
193+
self.dataForAnalyzer['networkinfo'] = {}
194+
motes = []
195+
188196
# getMoteConfig on all motes
189-
dataForAnalyzer['moteinfo'] = {}
190197
currentMac = (0,0,0,0,0,0,0,0) # start getMoteConfig() iteration with the 0 MAC address
191198
continueAsking = True
192199
while continueAsking:
@@ -197,16 +204,15 @@ def _doSnapshot(self):
197204
else:
198205
currentMac = res.macAddress
199206
motes += [currentMac]
200-
dataForAnalyzer['moteinfo'][tuple(currentMac)] = self._namedTupleToDict(res)
201-
207+
self.dataForAnalyzer['moteinfo'][tuple(currentMac)] = self._namedTupleToDict(res)
208+
202209
# getMoteInfo on all motes
203210
for mac in motes:
204211
res = self.connector.dn_getMoteInfo(mac)
205212
for (k,v) in self._namedTupleToDict(res).items():
206-
dataForAnalyzer['moteinfo'][tuple(mac)][k] = v
213+
self.dataForAnalyzer['moteinfo'][tuple(mac)][k] = v
207214

208-
# get path info on all paths of all motes
209-
dataForAnalyzer['networkpaths'] = {}
215+
# getNextPathInfo on all paths of all motes
210216
for mac in motes:
211217
currentPathId = 0
212218
continueAsking = True
@@ -215,16 +221,20 @@ def _doSnapshot(self):
215221
res = self.connector.dn_getNextPathInfo(mac,0,currentPathId)
216222
fromMAC = tuple(res.source)
217223
toMAC = tuple(res.dest)
218-
dataForAnalyzer['networkpaths'][(fromMAC,toMAC)] = self._namedTupleToDict(res)
224+
self.dataForAnalyzer['networkpaths'][(fromMAC,toMAC)] = self._namedTupleToDict(res)
219225
except APIError:
220226
continueAsking = False
221227
else:
222228
currentPathId = res.pathId
229+
230+
# getNetworkInfo
231+
res = self.connector.dn_getNetworkInfo()
232+
self.dataForAnalyzer['networkinfo'] = self._namedTupleToDict(res)
223233

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

226236
# run NetworkHealthAnalyzer
227-
results = self.networkHealthAnalyzer.analyze(dataForAnalyzer)
237+
results = self.networkHealthAnalyzer.analyze(self.dataForAnalyzer)
228238

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

235245
except Exception as err:
236246
printExcAndQuit(err)
237-
247+
238248
def _formatResults(self,results):
239249
output = []
240250
output += ['']
@@ -288,17 +298,17 @@ def _namedTupleToDict(self,nt):
288298
def _now(self):
289299
return time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
290300

301+
291302
#============================ CLI handlers ====================================
292303

293304
def connect_clicb(params):
294305
global connector
295-
global notifThread
296306
global snapshotThread
297307

298308
# filter params
299309
port = params[0]
300310

301-
# create a coonnector
311+
# create a connector
302312
connector = IpMgrConnectorSerial.IpMgrConnectorSerial()
303313

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

312322
# start threads
313-
notifThread = NotifThread(connector)
314323
snapshotThread = SnapshotThread(connector)
315324

316325
def now_clicb(params):
@@ -339,13 +348,10 @@ def period_clicb(params):
339348

340349
def quit_clicb():
341350
global connector
342-
global notifThread
343351
global snapshotThread
344352

345353
if connector:
346354
connector.disconnect()
347-
if notifThread:
348-
notifThread.disconnect()
349355
if snapshotThread:
350356
snapshotThread.close()
351357

libs/SmartMeshSDK/ApiDefinition/ByteArraySerializer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ def serialize(self,commandArray,fieldsToFill):
9696
raise SystemError('unknown field format='+field.format)
9797

9898
# padding
99-
while len(thisFieldByteArray)<field.length:
100-
thisFieldByteArray = [0x00]+thisFieldByteArray
99+
if field.length :
100+
numPadding = field.length - len(thisFieldByteArray)
101+
if numPadding > 0 :
102+
padding = [0] * numPadding
103+
if field.format==ApiDefinition.FieldFormats.STRING:
104+
thisFieldByteArray = thisFieldByteArray + padding
105+
else :
106+
thisFieldByteArray = padding + thisFieldByteArray
101107

102108
byteArray = byteArray+thisFieldByteArray
103109

0 commit comments

Comments
 (0)