Skip to content

Commit

Permalink
Spread out AVR test command numbers
Browse files Browse the repository at this point in the history
This should make future expansion easier.
  • Loading branch information
argilo committed Mar 10, 2024
1 parent 3b3a6cb commit d03b42b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions test/avr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,38 @@ int main() {
case 0:
cont = 0;
break;
case 1:
case 21:
get_uint32(&rolling);
get_uint32(&fixed_v1);
err = encode_v1(rolling, fixed_v1, &buf[0], &buf[20]);
put_err(err);
put_bytes(buf, 40);
break;
case 2:
case 22:
get_uint32(&rolling);
get_uint64(&fixed_v2);
get_uint32(&data);
err = encode_v2(rolling, fixed_v2, data, 0, &buf[0], &buf[5]);
put_err(err);
put_bytes(buf, 10);
break;
case 3:
case 23:
get_uint32(&rolling);
get_uint64(&fixed_v2);
get_uint32(&data);
err = encode_v2(rolling, fixed_v2, data, 1, &buf[0], &buf[8]);
put_err(err);
put_bytes(buf, 16);
break;
case 4:
case 24:
get_uint32(&rolling);
get_uint64(&fixed_v2);
get_uint32(&data);
err = encode_wireline(rolling, fixed_v2, data, buf);
put_err(err);
put_bytes(buf, 19);
break;
case 5:
case 25:
get_uint32(&rolling);
get_uint64(&fixed_v2);
get_uint16(&command);
Expand All @@ -118,38 +118,38 @@ int main() {
put_err(err);
put_bytes(buf, 19);
break;
case 6:
case 41:
get_bytes(buf, 40);
err = decode_v1(&buf[0], &buf[20], &rolling, &fixed_v1);
put_err(err);
put_uint32(rolling);
put_uint32(fixed_v1);
break;
case 7:
case 42:
get_bytes(buf, 10);
err = decode_v2(0, &buf[0], &buf[5], &rolling, &fixed_v2, &data);
put_err(err);
put_uint32(rolling);
put_uint64(fixed_v2);
put_uint32(data);
break;
case 8:
case 43:
get_bytes(buf, 16);
err = decode_v2(1, &buf[0], &buf[8], &rolling, &fixed_v2, &data);
put_err(err);
put_uint32(rolling);
put_uint64(fixed_v2);
put_uint32(data);
break;
case 9:
case 44:
get_bytes(buf, 19);
err = decode_wireline(buf, &rolling, &fixed_v2, &data);
put_err(err);
put_uint32(rolling);
put_uint64(fixed_v2);
put_uint32(data);
break;
case 10:
case 45:
get_bytes(buf, 19);
err = decode_wireline_command(buf, &rolling, &fixed_v2, &command, &data);
put_err(err);
Expand Down
18 changes: 9 additions & 9 deletions test_secplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def encode(rolling, fixed):
if rolling >= 2**32:
raise ValueError("Rolling code must be less than 2^32")

sim.stdin.write(struct.pack("<BLL", 1, rolling, fixed))
sim.stdin.write(struct.pack("<BLL", 21, rolling, fixed))
sim.stdin.flush()
err = sim.stdout.read(1)[0]
symbols = sim.stdout.read(40)
Expand All @@ -898,7 +898,7 @@ def encode(rolling, fixed):
secplus.encode = encode

def decode(code):
sim.stdin.write(bytes([6]))
sim.stdin.write(bytes([41]))
sim.stdin.write(bytes(code))
sim.stdin.flush()
err, rolling, fixed = struct.unpack("<BLL", sim.stdout.read(9))
Expand All @@ -911,14 +911,14 @@ def decode(code):
def encode_v2(rolling, fixed, data=None):
if data is None:
packet_len = 10
command = 2
command = 22
data_c = 0
else:
if data >= 2**32:
raise ValueError("Data must be less than 2^32")

packet_len = 16
command = 3
command = 23
data_c = data

sim.stdin.write(struct.pack("<BLQL", command, rolling, fixed, data_c))
Expand All @@ -938,7 +938,7 @@ def encode_v2(rolling, fixed, data=None):
secplus.encode_v2 = encode_v2

def decode_v2(code):
command = 7 if len(code) == 80 else 8
command = 42 if len(code) == 80 else 43

code_bytes = []
for offset in range(0, len(code), 8):
Expand All @@ -963,7 +963,7 @@ def encode_wireline(rolling, fixed, data):
if data >= 2**32:
raise ValueError("Data must be less than 2^32")

sim.stdin.write(struct.pack("<BLQL", 4, rolling, fixed, data))
sim.stdin.write(struct.pack("<BLQL", 24, rolling, fixed, data))
sim.stdin.flush()
err = sim.stdout.read(1)[0]
packet = sim.stdout.read(19)
Expand All @@ -980,7 +980,7 @@ def decode_wireline(code):
if len(code) != 19:
raise ValueError("Input must be 19 bytes long")

sim.stdin.write(bytes([9]))
sim.stdin.write(bytes([44]))
sim.stdin.write(code)
sim.stdin.flush()
err, rolling, fixed, data = struct.unpack("<BLQL", sim.stdout.read(17))
Expand All @@ -992,7 +992,7 @@ def decode_wireline(code):
secplus.decode_wireline = decode_wireline

def encode_wireline_command(rolling, device_id, command, payload):
sim.stdin.write(struct.pack("<BLQHL", 5, rolling, device_id, command, payload))
sim.stdin.write(struct.pack("<BLQHL", 25, rolling, device_id, command, payload))
sim.stdin.flush()
err = sim.stdout.read(1)[0]
packet = sim.stdout.read(19)
Expand All @@ -1009,7 +1009,7 @@ def decode_wireline_command(code):
if len(code) != 19:
raise ValueError("Input must be 19 bytes long")

sim.stdin.write(bytes([10]))
sim.stdin.write(bytes([45]))
sim.stdin.write(code)
sim.stdin.flush()
err, rolling, device_id, command, payload = struct.unpack("<BLQHL", sim.stdout.read(19))
Expand Down

0 comments on commit d03b42b

Please sign in to comment.