summaryrefslogtreecommitdiff
path: root/gps.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gps.cpp')
-rw-r--r--gps.cpp40
1 files changed, 40 insertions, 0 deletions
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<Interrupt::USART3>() {
+ 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<P<GPSMsg>&>(complete_msg) = incomplete_msg;
+ incomplete_msg.reset();
+ complete = true;
+ }
+}