summaryrefslogtreecommitdiff
path: root/drivers/gps.cpp
blob: cdbb7ada8fc44c3d6e1ce438a8abd3725dcbf443 (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.recv();
	
	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;
	}
}