summaryrefslogtreecommitdiff
path: root/robot
diff options
context:
space:
mode:
Diffstat (limited to 'robot')
-rw-r--r--robot/bin.c64
-rw-r--r--robot/bin.h52
-rw-r--r--robot/consts.h17
-rw-r--r--robot/errcatch.c1
-rw-r--r--robot/errcatch.h2
-rw-r--r--robot/makefile1
-rw-r--r--robot/sercomm.c2
-rw-r--r--robot/sercomm.h4
-rw-r--r--robot/setup.c4
-rw-r--r--robot/sim.c2
10 files changed, 8 insertions, 141 deletions
diff --git a/robot/bin.c b/robot/bin.c
deleted file mode 100644
index a2c91a4..0000000
--- a/robot/bin.c
+++ /dev/null
@@ -1,64 +0,0 @@
-#include <stdlib.h>
-
-#include "bin.h"
-
-#define W2_ENDIAN_LITTLE (1)
-#define W2_ENDIAN_BIG (0)
-
-#define _SHIFT_0B (8 * 0)
-#define _SHIFT_1B (8 * 1)
-#define _SHIFT_2B (8 * 2)
-#define _SHIFT_3B (8 * 3)
-#define _BYTE_0 ((uint32_t)(0xff << (_SHIFT_0B)))
-#define _BYTE_1 ((uint32_t)(0xff << (_SHIFT_1B)))
-#define _BYTE_2 ((uint32_t)(0xff << (_SHIFT_2B)))
-#define _BYTE_3 ((uint32_t)(0xff << (_SHIFT_3B)))
-
-const uint8_t W2_STRUCT_T_SIZES[] = {sizeof(uint8_t), sizeof(uint16_t), sizeof(uint32_t)};
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshift-count-overflow"
-w2_s_bin *w2_bin_from_uint8_t(uint8_t data) {
- size_t size = 1;
- w2_s_bin *ret = malloc(sizeof(w2_s_bin) + sizeof(uint8_t) * size);
- ret->bytes = size;
- ret->data[0] = data;
- return ret;
-}
-
-w2_s_bin *w2_bin_from_uint16_t(uint16_t data) {
- size_t size = 2;
- w2_s_bin *ret = malloc(sizeof(w2_s_bin) + sizeof(uint8_t) * size);
- data = w2_bin_hton16(data);
- ret->bytes = size;
- ret->data[0] = (data & _BYTE_1) >> _SHIFT_1B;
- ret->data[1] = (data & _BYTE_0) >> _SHIFT_0B;
- return ret;
-}
-
-w2_s_bin *w2_bin_from_uint32_t(uint32_t data) {
- size_t size = 4;
- w2_s_bin *ret = malloc(sizeof(w2_s_bin) + sizeof(uint8_t) * size);
- data = w2_bin_hton32(data);
- ret->bytes = size;
- ret->data[0] = (data & _BYTE_3) >> _SHIFT_3B;
- ret->data[1] = (data & _BYTE_2) >> _SHIFT_2B;
- ret->data[2] = (data & _BYTE_1) >> _SHIFT_1B;
- ret->data[3] = (data & _BYTE_0) >> _SHIFT_0B;
- return ret;
-}
-
-uint32_t w2_bin_hton32(uint32_t h32) {
- if (g_w2_endianness == W2_ENDIAN_BIG) return h32;
- return ((h32 & _BYTE_0) << _SHIFT_3B) | ((h32 & _BYTE_1) << _SHIFT_1B) |
- ((h32 & _BYTE_2) >> _SHIFT_1B) | ((h32 & _BYTE_3) >> _SHIFT_3B);
-}
-#pragma GCC diagnostic pop
-
-uint16_t w2_bin_hton16(uint16_t h16) {
- if (g_w2_endianness == W2_ENDIAN_BIG) return h16;
- return ((h16 & _BYTE_0) << _SHIFT_1B) | ((h16 & _BYTE_1) >> _SHIFT_1B);
-}
-
-uint32_t w2_bin_ntoh32(uint32_t n32) { return w2_bin_hton32(n32); }
-uint16_t w2_bin_ntoh16(uint16_t n16) { return w2_bin_hton16(n16); }
diff --git a/robot/bin.h b/robot/bin.h
deleted file mode 100644
index 1c9b951..0000000
--- a/robot/bin.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma once
-/**
- * helper file for binary data
- *
- * - fix endianness with functions inspired by UNIX arpa/inet.h
- * - convert uint16_t and uint32_t to w2_s_bin
- */
-
-#include <stdint.h>
-
-extern uint8_t g_w2_endianness;
-
-#define W2_T_UINT8_T (0)
-#define W2_T_UINT16_T (1)
-#define W2_T_UINT32_T (2)
-
-enum w2_e_struct_types {
- W2_ST_UINT8_T,
- W2_ST_UINT16_T,
- W2_ST_UINT32_T,
-};
-
-extern const uint8_t W2_STRUCT_T_SIZES[];
-
-typedef struct {
- uint16_t bytes;
- uint8_t data[];
-} w2_s_bin;
-
-typedef struct {
- enum w2_e_struct_types type;
- uint16_t length;
- const uint8_t *data;
-} w2_s_struct_property;
-
-typedef struct {
- uint16_t length;
- w2_s_struct_property *properties[];
-} w2_s_property_list;
-
-w2_s_bin *w2_bin_from_uint8_t(uint8_t data);
-w2_s_bin *w2_bin_from_uint16_t(uint16_t data);
-w2_s_bin *w2_bin_from_uint32_t(uint32_t data);
-
-/** convert 32-bit value from host endian to network (big-endian) */
-uint32_t w2_bin_hton32(uint32_t h32);
-/** convert 16-bit value from host endian to network (big-endian) */
-uint16_t w2_bin_hton16(uint16_t h16);
-/** convert 32-bit value from network (big-endian) to host endian */
-uint32_t w2_bin_ntoh32(uint32_t n32);
-/** convert 16-bit value from network (big-endian) to host endian */
-uint16_t w2_bin_ntoh16(uint16_t n16);
diff --git a/robot/consts.h b/robot/consts.h
deleted file mode 100644
index 70efcac..0000000
--- a/robot/consts.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#ifndef W2_BUILD_STR
-// is defined by CFLAGS += -DW2_BUILD_STR in makefile
-#define W2_BUILD_STR ("????????")
-#endif
-
-/** max logic module execution time in milliseconds */
-#define W2_MAX_MODULE_CYCLE_MS (20)
-/** serial baud rate (bit/s) */
-#define W2_SERIAL_BAUD (9600)
-/** size of the error handling buffer (in errors, not bytes) */
-#define W2_ERROR_BUFFER_SIZE (16)
-/** size of the serial communication buffer (in messages, not bytes) */
-#define W2_SERCOMM_BUFFER_SIZE (16)
-/** size of input (receive) buffer (in bytes) */
-#define W2_SERIAL_READ_BUFFER_SIZE (255)
diff --git a/robot/errcatch.c b/robot/errcatch.c
index 2a59d3d..4bdbaef 100644
--- a/robot/errcatch.c
+++ b/robot/errcatch.c
@@ -1,7 +1,6 @@
#include <stdlib.h>
#include <string.h>
-#include "consts.h"
#include "errcatch.h"
#include "halt.h"
#include "modes.h"
diff --git a/robot/errcatch.h b/robot/errcatch.h
index f0e25d9..1e273bd 100644
--- a/robot/errcatch.h
+++ b/robot/errcatch.h
@@ -2,7 +2,7 @@
#include <stdint.h>
-#include "consts.h"
+#include "../shared/consts.h"
#define W2_E_TYPE_MASK (0b11 << 6)
diff --git a/robot/makefile b/robot/makefile
index 53010dd..cd5c032 100644
--- a/robot/makefile
+++ b/robot/makefile
@@ -12,6 +12,7 @@ LDFLAGS=-Wl,-gc-sections -Wl,-relax
SOURCES := $(filter-out sim.c, $(wildcard *.c))
HEADERS := $(filter-out sim.h, $(wildcard *.h))
+include ../shared/makefile
# simulation
SIM = true
diff --git a/robot/sercomm.c b/robot/sercomm.c
index d1bb3b3..7072f9e 100644
--- a/robot/sercomm.c
+++ b/robot/sercomm.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include <string.h>
-#include "bin.h"
+#include "../shared/bin.h"
#include "orangutan_shim.h"
#include "sercomm.h"
diff --git a/robot/sercomm.h b/robot/sercomm.h
index bc9fc1e..44fdf08 100644
--- a/robot/sercomm.h
+++ b/robot/sercomm.h
@@ -1,7 +1,7 @@
#pragma once
-#include "bin.h"
-#include "consts.h"
+#include "../shared/bin.h"
+#include "../shared/consts.h"
#define W2_CMDDIR_RX (0)
#define W2_CMDDIR_TX (1)
diff --git a/robot/setup.c b/robot/setup.c
index 36c5da1..6af1a05 100644
--- a/robot/setup.c
+++ b/robot/setup.c
@@ -1,7 +1,7 @@
#include <stdlib.h>
-#include "bin.h"
-#include "consts.h"
+#include "../shared/bin.h"
+#include "../shared/consts.h"
#include "halt.h"
#include "modes.h"
#include "orangutan_shim.h"
diff --git a/robot/sim.c b/robot/sim.c
index 47c0c78..b061c9a 100644
--- a/robot/sim.c
+++ b/robot/sim.c
@@ -6,7 +6,7 @@
#include <unistd.h>
#include "sim.h"
-#include "consts.h"
+#include "../shared/consts.h"
#include "sercomm.h"
struct timespec reference_time; // NOLINT