aboutsummaryrefslogtreecommitdiff
path: root/zumo/protocoltest
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-06-06 12:00:58 +0200
committerUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2023-06-06 12:00:58 +0200
commit077069b82a34bd5e0d51509eb751df9b44a5f6d3 (patch)
tree1753f1266c2837282c7a1f7ce8137161c85a1a0a /zumo/protocoltest
parentf2335307a26a8ab3e18d8990d2640a8de4cbd0e4 (diff)
parent0f764db3c3595e863a4949c67592451c7d65a2cf (diff)
Merge branch 'master' of https://github.com/unavailabledev/avans-dui
Diffstat (limited to 'zumo/protocoltest')
-rw-r--r--zumo/protocoltest/.gitignore1
-rw-r--r--zumo/protocoltest/makefile21
-rw-r--r--zumo/protocoltest/protocoltest.cpp35
3 files changed, 57 insertions, 0 deletions
diff --git a/zumo/protocoltest/.gitignore b/zumo/protocoltest/.gitignore
new file mode 100644
index 0000000..fb5d35f
--- /dev/null
+++ b/zumo/protocoltest/.gitignore
@@ -0,0 +1 @@
+protocoltest
diff --git a/zumo/protocoltest/makefile b/zumo/protocoltest/makefile
new file mode 100644
index 0000000..7a69352
--- /dev/null
+++ b/zumo/protocoltest/makefile
@@ -0,0 +1,21 @@
+CPP = g++
+LD = g++
+RM = rm -f
+CFLAGS =
+LFLAGS =
+TARGET = protocoltest
+
+SRCS := $(TARGET).cpp ../protocol.cpp
+OBJS := $(TARGET).o ../protocol.o
+
+all: $(TARGET)
+
+%.o: %.cpp
+ $(CPP) -c $(CFLAGS) $< -o $@
+
+$(TARGET): $(OBJS)
+ $(LD) $^ $(LFLAGS) -o $@
+
+clean:
+ $(RM) $(TARGET) $(OBJS)
+
diff --git a/zumo/protocoltest/protocoltest.cpp b/zumo/protocoltest/protocoltest.cpp
new file mode 100644
index 0000000..461221e
--- /dev/null
+++ b/zumo/protocoltest/protocoltest.cpp
@@ -0,0 +1,35 @@
+#include <cstdio>
+#include <random>
+
+#include "../protocol.h"
+
+void print_state(dui_state_t* s) {
+ printf("{ steer = %1.3f\n speed = %1.3f }\n", s->steer, s->speed);
+}
+
+void test_case(unsigned char cmd, dui_state_t* s) {
+ printf("\ncmd in = 0x%02x\n", cmd);
+ handle_cmd(cmd, s);
+ print_state(s);
+}
+
+int main() {
+ dui_state_t state = {
+ .steer = 0.f,
+ .speed = 1.f,
+ .current_sign = DUI_SIGN_NONE,
+ .speed_mod = 1.f,
+ };
+
+ test_case(0x00, &state);
+ test_case(0x01, &state);
+ test_case(0x02, &state);
+ test_case(0x10, &state);
+ test_case(0x15, &state);
+ test_case(0x1f, &state);
+ test_case(0x20, &state);
+ test_case(0x25, &state);
+ test_case(0x2f, &state);
+ test_case(0x88, &state);
+ test_case(0xff, &state);
+}