summaryrefslogtreecommitdiff
path: root/robot
diff options
context:
space:
mode:
Diffstat (limited to 'robot')
-rw-r--r--robot/consts.h3
-rw-r--r--robot/sercomm.c13
-rw-r--r--robot/sercomm.h5
-rw-r--r--robot/setup.c31
-rw-r--r--robot/sim.c11
-rw-r--r--robot/sim.h2
6 files changed, 37 insertions, 28 deletions
diff --git a/robot/consts.h b/robot/consts.h
index 94a161d..a8b8397 100644
--- a/robot/consts.h
+++ b/robot/consts.h
@@ -13,3 +13,6 @@
#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/sercomm.c b/robot/sercomm.c
index 723a231..d7dc7f1 100644
--- a/robot/sercomm.c
+++ b/robot/sercomm.c
@@ -5,11 +5,14 @@
#include "orangutan_shim.h"
#include "sercomm.h"
-w2_s_bin *g_w2_sercomm_buffer[W2_SERCOMM_BUFFER_SIZE] = {};
+w2_s_bin *g_w2_sercomm_buffer[W2_SERCOMM_BUFFER_SIZE] = {0};
uint8_t g_w2_sercomm_index = 0;
uint8_t g_w2_sercomm_offset = 0;
uint8_t g_w2_sercomm_buffer_full = 0;
+char g_w2_serial_buffer[W2_SERIAL_READ_BUFFER_SIZE] = {0};
+uint8_t g_w2_serial_buffer_index = 0;
+
void w2_sercomm_main() {
#ifdef W2_SIM
simprintfunc("w2_sercomm_main", "");
@@ -22,6 +25,14 @@ void w2_sercomm_main() {
serial_send(data_cast, data->bytes);
g_w2_sercomm_offset = (g_w2_sercomm_offset + 1) % W2_SERCOMM_BUFFER_SIZE;
}
+
+ while(serial_get_received_bytes() != g_w2_serial_buffer_index) {
+ uint8_t byte = g_w2_serial_buffer[g_w2_serial_buffer_index];
+#ifdef W2_SIM
+ simprintf("serial byte: %02x\n", byte);
+#endif
+ g_w2_serial_buffer_index = (g_w2_serial_buffer_index + 1) % W2_SERIAL_READ_BUFFER_SIZE;
+ }
}
void w2_sercomm_append_msg(w2_s_bin *data) {
diff --git a/robot/sercomm.h b/robot/sercomm.h
index dd17af8..f411374 100644
--- a/robot/sercomm.h
+++ b/robot/sercomm.h
@@ -44,6 +44,11 @@ extern uint8_t g_w2_sercomm_index;
/** stores start of ring buffer */
extern uint8_t g_w2_sercomm_offset;
+/** serial input (receive) buffer */
+extern char g_w2_serial_buffer[W2_SERIAL_READ_BUFFER_SIZE];
+/** serial input (receive) buffer current position */
+extern uint8_t g_w2_serial_buffer_index;
+
/**
* serial pc-robot communication module
*
diff --git a/robot/setup.c b/robot/setup.c
index fcac6d4..36c5da1 100644
--- a/robot/setup.c
+++ b/robot/setup.c
@@ -5,6 +5,7 @@
#include "halt.h"
#include "modes.h"
#include "orangutan_shim.h"
+#include "sercomm.h"
#include "setup.h"
// pointers for endianness check
@@ -25,33 +26,9 @@ void w2_setup_main() {
// clear lcd
clear();
+ // start serial input
+ serial_receive_ring(g_w2_serial_buffer, W2_SERIAL_READ_BUFFER_SIZE);
+
// indicate startup done
play("L50 c>c");
-
-#ifdef W2_SIM
-#include "sercomm.h"
- w2_s_bin *data = malloc(sizeof(w2_s_bin) + sizeof(uint8_t) * 20);
- data->bytes = 20;
- data->data[0] = 0x00;
- data->data[1] = 0x01;
- data->data[2] = 0x00;
- data->data[3] = 0x01;
- data->data[4] = 0x00;
- data->data[5] = 0x01;
- data->data[6] = 0x00;
- data->data[7] = 0x01;
- data->data[8] = 0xde;
- data->data[9] = 0xad;
- data->data[10] = 0xbe;
- data->data[11] = 0xef;
- data->data[12] = 0xff;
- data->data[13] = 0xff;
- data->data[14] = 0x00;
- data->data[15] = 0x00;
- data->data[16] = 0xff;
- data->data[17] = 0xff;
- data->data[18] = 0x00;
- data->data[19] = 0x69;
- w2_sercomm_append_msg(data);
-#endif
}
diff --git a/robot/sim.c b/robot/sim.c
index 1e88feb..554b174 100644
--- a/robot/sim.c
+++ b/robot/sim.c
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <time.h>
#include <string.h>
+#include <stdint.h>
#include "sim.h"
@@ -62,3 +63,13 @@ void serial_send(char* message, unsigned int length) {
return;
}
+void serial_receive_ring(char* buffer, unsigned char size) {
+ simprintfunc("serial_receive_ring", "0x%016lx, %u", (unsigned long) buffer, size);
+ return;
+}
+
+unsigned char serial_get_received_bytes() {
+ simprintfunc("serial_get_received_bytes", "");
+ return 0;
+}
+
diff --git a/robot/sim.h b/robot/sim.h
index c872dda..75f6a5c 100644
--- a/robot/sim.h
+++ b/robot/sim.h
@@ -44,3 +44,5 @@ void clear(); // NOLINT
void play(const char* melody); // NOLINT
void serial_set_baud_rate(unsigned int rate); // NOLINT
void serial_send(char* message, unsigned int length); // NOLINT
+void serial_receive_ring(char* buffer, unsigned char size); // NOLINT
+unsigned char serial_get_received_bytes(); // NOLINT