Commit 86e5974f authored by Robert Hartung's avatar Robert Hartung
Browse files

adds latest coordinator (cleaned up)

parent 2f4819b4
...@@ -56,18 +56,7 @@ def calculate_checksum(*args): ...@@ -56,18 +56,7 @@ def calculate_checksum(*args):
s += sum(bytes(a, 'utf-8')) s += sum(bytes(a, 'utf-8'))
return hex( s&0xFF )[2:].upper().zfill(2) return hex( s&0xFF )[2:].upper().zfill(2)
def handle_match_tx( src_id, ts, match_tx ):
def handle_serial_rx(d):
src_id = d['src']['id'][0]
ts = d['ts']
line = d['line'].strip()
match_ifconfig = re_ifconfig.match(line)
if match_ifconfig is not None:
return True
match_tx = re_tx.match(line)
if match_tx is not None:
seq_nr = match_tx.group("seq_nr") seq_nr = match_tx.group("seq_nr")
checksum = match_tx.group("checksum") checksum = match_tx.group("checksum")
...@@ -81,8 +70,8 @@ def handle_serial_rx(d): ...@@ -81,8 +70,8 @@ def handle_serial_rx(d):
else: else:
logger.debug("Corrupt Line") logger.debug("Corrupt Line")
return False return False
match_rx = re_rx.match(line)
if match_rx is not None: def handle_match_rx( src_id, ts, match_rx ):
node_id = match_rx.group("node_id") node_id = match_rx.group("node_id")
seq_nr = match_rx.group("seq_nr") seq_nr = match_rx.group("seq_nr")
rssi = match_rx.group('rssi') rssi = match_rx.group('rssi')
...@@ -93,15 +82,15 @@ def handle_serial_rx(d): ...@@ -93,15 +82,15 @@ def handle_serial_rx(d):
if expected_checksum == checksum: if expected_checksum == checksum:
session = Session() session = Session()
session.add(RX(serial_id = src_id, ts=ts, seq_nr = seq_nr, node_id = node_id, rssi = rssi, lqi = lqi)) session.add(RX(serial_id = src_id, ts=ts, seq_nr = seq_nr, node_id = node_id, rssi = rssi, lqi = lqi))
# TODO(rh): Add sqlite3.OperationalError
session.commit() session.commit()
#logger.log("[{}] RX: #{} from {}".format( src_id, node_id, seq_nr )) #logger.log("[{}] RX: #{} from {}".format( src_id, node_id, seq_nr ))
return True return True
else: else:
logger.debug("Corrupt Line {} != {}".format( expected_checksum, checksum) ) logger.debug("Corrupt Line {} != {}".format( expected_checksum, checksum) )
return False return False
return True
match_rx_corrupt = re_rx_corrupt.match(line) def handle_match_rx_corrupt( src_id, ts, match_rx_corrupt ):
if match_rx_corrupt is not None:
rssi = match_rx_corrupt.group('rssi') rssi = match_rx_corrupt.group('rssi')
lqi = match_rx_corrupt.group('lqi') lqi = match_rx_corrupt.group('lqi')
payload = match_rx_corrupt.group('payload').strip() payload = match_rx_corrupt.group('payload').strip()
...@@ -110,6 +99,24 @@ def handle_serial_rx(d): ...@@ -110,6 +99,24 @@ def handle_serial_rx(d):
session.add(Corrupt(serial_id = src_id, ts=ts, rssi = rssi, lqi = lqi, payload = payload)) session.add(Corrupt(serial_id = src_id, ts=ts, rssi = rssi, lqi = lqi, payload = payload))
session.commit() session.commit()
return True return True
def handle_serial_rx(d):
src_id = d['src']['id'][0]
ts = d['ts']
line = d['line'].strip()
match_ifconfig = re_ifconfig.match(line)
if match_ifconfig is not None:
return True
match_tx = re_tx.match(line)
if match_tx is not None:
return handle_match_tx( src_id, ts, match_tx )
match_rx = re_rx.match(line)
if match_rx is not None:
return handle_match_rx( src_id, ts, match_rx )
match_rx_corrupt = re_rx_corrupt.match(line)
if match_rx_corrupt is not None:
return handle_match_rx_corrupt( src_id, ts, match_rx_corrupt )
return False return False
class PRREvalClient(Client): class PRREvalClient(Client):
...@@ -130,10 +137,15 @@ class PRREvalClient(Client): ...@@ -130,10 +137,15 @@ class PRREvalClient(Client):
logger.log( "PAYLOAD={} ".format(payload) ) logger.log( "PAYLOAD={} ".format(payload) )
self.send_all( "payload {}\n".format( payload ) ) self.send_all( "payload {}\n".format( payload ) )
sleep( 0.5 ) sleep( 0.5 )
# TODO(rh) START ROUND:
# round = Round( channel=channel, power=power, payload=payload )
# session.add( round )
# sessionc.commit()
for sender in NODES: for sender in NODES:
self.send({'dst': {'id': sender}, 'type': 'serial_tx', 'line': 'tx 5 200000\n'}) self.send({'dst': {'id': sender}, 'type': 'serial_tx', 'line': 'tx 5 200000\n'})
# 5 packets, 200ms -> 1 second # 5 packets, 200ms -> 1 second
sleep( 1.5 ) sleep( 1.5 )
self.send({'dst': {'id': sender}, 'type': 'serial_tx', 'line': 'ifconfig 3 set state idle\n'})
def run(self): def run(self):
while True: while True:
...@@ -144,7 +156,7 @@ class PRREvalClient(Client): ...@@ -144,7 +156,7 @@ class PRREvalClient(Client):
break break
def set_channel(self, channel): def set_channel(self, channel):
self.send_all("ifconfig 3 set state idle\n") #self.send_all("ifconfig 3 set state idle\n")
self.send_all("ifconfig 3 set channel {}\n".format( channel )) self.send_all("ifconfig 3 set channel {}\n".format( channel ))
def set_txpower(self, power): def set_txpower(self, power):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment