From 261e6be038754388212e7a7b69da1318d6a171d2 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 10 Oct 2011 01:13:52 +0200 Subject: Add GPS code. --- gps.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 gps.cpp (limited to 'gps.cpp') diff --git a/gps.cpp b/gps.cpp new file mode 100644 index 0000000..1ae3684 --- /dev/null +++ b/gps.cpp @@ -0,0 +1,40 @@ +#include "gps.h" + +GPS* GPS::self; + +template<> +void interrupt() { + GPS::self->irq(); +} + +void GPS::irq() { + + uint8_t c = USART3.DR; + + if(!incomplete_msg) { + incomplete_msg = msg_pool.create(); + + if(!incomplete_msg) { + return; + } + } + + if(incomplete_msg->n == 0 && c != '$') { + return; + } + + if(incomplete_msg->n >= 128) { + incomplete_msg->n = 0; + return; + } + + incomplete_msg->buf[incomplete_msg->n++] = c; + + if(c == '\n') { + GPIOB.ODR ^= 1 << 1; + + const_cast&>(complete_msg) = incomplete_msg; + incomplete_msg.reset(); + complete = true; + } +} -- cgit v1.2.3