added a checksum of the data structure to the gyro board data
diff --git a/gyro_board/src/usb/Makefile b/gyro_board/src/usb/Makefile
index da8a4c5..e2f81f4 100644
--- a/gyro_board/src/usb/Makefile
+++ b/gyro_board/src/usb/Makefile
@@ -49,13 +49,15 @@
gyro.c \
LPCUSB/usbstdreq.c
+DATA_STRUCT_CHECKSUM=$(shell ./data_struct_checksum.sh)
+
all: $(NAME).hex
$(NAME).elf: Makefile $(SOURCES:.c=.o) $(LDSCRIPT)
$(CC) $(CFLAGS) -nostartfiles -nostdlib -T $(LDSCRIPT) -o $@ -L$(TOOLS_PREFIX)/lib/gcc/arm-eabi/4.5.1/ $(SOURCES:.c=.o) -Wa,-Map -Wa,main.map -lgcc
-%.o: %.c Makefile
- $(CC) $(CFLAGS) -nostartfiles -nostdlib -c -o $@ $< -Wall -std=gnu99
+%.o: %.c Makefile data_struct_checksum.sh
+ $(CC) $(CFLAGS) -nostartfiles -nostdlib -c -o $@ $< -Wall -std=gnu99 -DDATA_STRUCT_CHECKSUM=$(DATA_STRUCT_CHECKSUM)
run: deploy
$(FLASHER) -termonly -control $(NAME).hex $(PORT) $(SPEED) $(OSC)
diff --git a/gyro_board/src/usb/data_struct.h b/gyro_board/src/usb/data_struct.h
index 718d19c..50eb7a9 100644
--- a/gyro_board/src/usb/data_struct.h
+++ b/gyro_board/src/usb/data_struct.h
@@ -26,6 +26,11 @@
// dealing with it reset.
int32_t frame_number;
+ // Checksum of this file calculated with sum(1).
+ // The gyro board sets this and then the fitpc checks it to make sure that
+ // they're both using the same version of this file.
+ uint16_t checksum;
+
// Which robot (+version) the gyro board is sending out data for.
// We should keep this in the same place for all gyro board software
// versions so that the fitpc can detect when it's reading from a gyro
@@ -62,7 +67,9 @@
uint8_t unknown_frame : 1;
};
};
- uint64_t header;
+ struct {
+ uint64_t header0, header1;
+ };
};
// We are 64-bit aligned at this point.
diff --git a/gyro_board/src/usb/data_struct_checksum.sh b/gyro_board/src/usb/data_struct_checksum.sh
new file mode 100755
index 0000000..147a365
--- /dev/null
+++ b/gyro_board/src/usb/data_struct_checksum.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+sum $(dirname $0)/data_struct.h | sed 's/^\([0-9]*\) .*$/\1/'
diff --git a/gyro_board/src/usb/encoder.c b/gyro_board/src/usb/encoder.c
index 77344fb..ef5af7f 100644
--- a/gyro_board/src/usb/encoder.c
+++ b/gyro_board/src/usb/encoder.c
@@ -517,6 +517,8 @@
packet->timestamp = ((uint64_t)sensor_timing_wraps << 32) | TIM1->TC;
NVIC_EnableIRQ(TIMER1_IRQn);
+ packet->checksum = DATA_STRUCT_CHECKSUM;
+
packet->dip_switch0 = dip_switch(0);
packet->dip_switch1 = dip_switch(1);
packet->dip_switch2 = dip_switch(2);