summaryrefslogtreecommitdiff
path: root/gps.cpp
blob: 1ae3684e7853be85d77c5c0f9dd02def16073a4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
	}
}