-
Notifications
You must be signed in to change notification settings - Fork 0
/
flocklab2KPI.py
executable file
·118 lines (102 loc) · 3.14 KB
/
flocklab2KPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python
import sys, os, getopt
from struct import *
def usage():
print "Usage: flocklab2KPI.py <serial-input> <powersummary>"
print ""
print " <serial-input>: serial file generated by FlockLab"
print " <powersummary>: optional. 'powerprofilingstats.csv' from FlockLab"
##############################################################################
#
# Main
#
##############################################################################
def main(argv):
serialfile = None
powerfile = None
nodes = [1,2,3,4,6,8,15,16,22,28,31,32,33]
sinknode = 1 # this node is not included in power assesment
if len(argv) < 1:
usage()
sys.exit()
serialfile = argv[0]
inf = open(serialfile, "r")
if len(argv) > 1:
powerfile = argv[1]
ppf = open(powerfile, "r")
sources={}
line = inf.readline()
while line != '':
if line[0]=='#':
line = inf.readline()
continue
#print line
(ts, obs, id, dir, pck) = line[0:-1].split(',', 5)
pck = pck.decode("hex")
#header
#nx_uint16_t: H
#nx_uint32_t: I
#nx_uint8_t: B
#00 ffff ff21 05 3f 06
if int(obs) == 1:
header = unpack('!BHHBBB', pck[0:8])
if header[5]==6: # group project data packet
(src, seq, data) = unpack('!HBH', pck[8:])
if src in nodes:
if not src in sources:
sources[src] = {}
sources[src][seq] = data
line = inf.readline()
#inf.close()
datayield = 0
for src in sources:
pk_ok = check_data(src, sources[src])
print "%d: %d (%d ok) packets" % (src, len(sources[src]), pk_ok)
datayield = datayield + pk_ok
datayield = float(datayield) / (13.0 * 200.0)
kpi_datayield = datayield
print "data yield %0.2f %% (%0.2f)" % (100 * datayield, kpi_datayield)
if powerfile is not None:
sumcurrent = 0.0
numnodes = 0
line = ppf.readline()
while line != '':
if line[0]=='#':
line = ppf.readline()
continue
(obs, id, current) = line[0:-1].split(',', 3)
if int(obs) in nodes and int(obs)!=sinknode:
numnodes = numnodes + 1
sumcurrent = sumcurrent + float(current)
line = ppf.readline()
avg_current = sumcurrent / float(numnodes)
kpi_current = 1 - (avg_current / 25.0)
print "average current dissipation %0.2f mA (%0.2f)" % (avg_current, kpi_current)
print "Key performance indicator (KPI): %0.2f" % (kpi_current * 0.5 + kpi_datayield * 0.5)
def check_data(src, pktlist):
seed = src + 1
rnd_seq = 0
pk_ok = 0
for seq in sorted(pktlist):
if seq > 200:
break
while rnd_seq < seq:
seed = random32(seed)
rnd_seq = rnd_seq + 1
#print " %d:%d %d %d" % (seq, pktlist[seq], seed & 0xffff, seed & 0xffff == pktlist[seq])
if seed & 0xffff == pktlist[seq]:
pk_ok = pk_ok + 1
return pk_ok
# TinyOS random implementation
def random32(seed):
tmpseed = 33614 * seed
q = tmpseed & 0xFFFFFFFF
q = q >> 1
p = (tmpseed >> 32) & 0xFFFFFFFF
mlcg = (p + q) & 0xFFFFFFFF
if (mlcg & 0x80000000) > 0:
mlcg = mlcg & 0x7FFFFFFF
mlcg = mlcg + 1
return mlcg & 0xFFFFFFFF
if __name__ == "__main__":
main(sys.argv[1:])