/
test_eevee.py
executable file
·88 lines (67 loc) · 3.07 KB
/
test_eevee.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
#!/usr/bin/python3
import sys
import eevee
import socket
import argparse
from random import randint
# Adapted from boilerplate code from the docs
parser = argparse.ArgumentParser(description='Exercise the EEVEE system')
parser.add_argument('-b',
dest='broadcast',
help='flag that the given address is a broadcast and attempt to discover boards',
action='store_true')
parser.add_argument('-p',
dest='udpsport',
metavar='udp source port',
default=None,
type=int,
help='explicitly specify the originating UDP port (e.g. useful for netcat/ssh tunnels)')
parser.add_argument('ip',
help='IP address of a specific board or subnet broadcast')
args = parser.parse_args()
# A place holder
boards = None
# Get some boards
if args.broadcast:
if not args.udpsport is None:
print("Broadcast, in general, will find multiple boards. It is unwise to control multiple boards from the same socket. Quitting.")
exit(1)
# Otherwise, find the boards
boards = eevee.discover(args.ip)
else:
boards = [eevee.board(args.ip, udpsport=args.udpsport)]
print("")
print("EEVEE Evolvable Embedded Vehicle for Execution and Egress: Python 3 test stub")
print("----------------------------------")
for myboard in boards:
print("Connected to board: %s @ %s\n-------------------------" % (myboard.dna.hex(), myboard.dest))
# Try to point it to google
myboard.aimNBIC(socket.gethostbyname("google.com"))
# It should be pointing to the gateway
maclow = myboard.peeknow(eevee.NBIC_OFFSET | eevee.REG_NBIC_DESTMAC_LOW)
machigh = myboard.peeknow(eevee.NBIC_OFFSET | eevee.REG_NBIC_DESTMAC_HIGH)
print("Board %s NBIC target MAC low: %s, high: %s" % (myboard.dna.hex(), hex(maclow), hex(machigh)))
input()
# Debug, so set a delay (1hr ;))
myboard.delay = 3600
# Run a register write (with readback, as its the default)
print(myboard.pokenow(eevee.INTERNAL_OFFSET | eevee.REG_INTERNAL_SCRATCH, 128))
# Run a register write without readback
print(myboard.pokenow(eevee.INTERNAL_OFFSET | eevee.REG_INTERNAL_SCRATCH, 256, readback=False))
print("\nOkay, now try pointing the boards at each other. This should mac resolve individuals.")
# Multiboard shenanegains
N = len(boards)
if N > 1:
for i in range(0,N):
success = False
while not success:
try:
boards[i].aimNBIC(boards[(i + 1) % N].dest)
success = True
except Exception:
print("Board %s failed to aim at board %s" % (boards[i].dna, boards[(i + 1) % N].dna))
# Verify that they are pointing at each other
for i in range(0,N):
maclow = boards[i].peeknow(eevee.NBIC_OFFSET | eevee.REG_NBIC_DESTMAC_LOW)
machigh = boards[i].peeknow(eevee.NBIC_OFFSET | eevee.REG_NBIC_DESTMAC_HIGH)
print("Board %s NBIC target MAC low: %s, high: %s" % (boards[i].dna.hex(), hex(maclow), hex(machigh)))