forked from daveake/pico-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.c
executable file
·132 lines (114 loc) · 2.14 KB
/
tracker.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#include "types.h"
#include "misc.h"
#include "battery.h"
#include "led.h"
#include "bme280.h"
#include "gps.h"
#include "lora.h"
#include "prediction.h"
// Tracker configuration
// Variables
struct TGPS GPS;
int ProcessFieldCommand(char *Line)
{
int OK = 0;
if (Line[0] == 'P')
{
GPS.PreviousAltitude = GPS.Altitude;
sscanf(Line+1,"%f,%f,%ld", &GPS.Latitude, &GPS.Longitude, &GPS.Altitude);
GPS.UseHostPosition = 5;
GPS.AscentRate = GPS.AscentRate * 0.7 + (GPS.Altitude - GPS.PreviousAltitude) * 0.3;
OK = 1;
}
return OK;
}
void ProcessCommand(char *Line)
{
int OK = 0;
if (Line[0] == 'G')
{
// OK = ProcessGPSCommand(Line+1);
}
else if (Line[0] == 'C')
{
// OK = ProcessCommonCommand(Line+1);
}
else if (Line[0] == 'L')
{
// OK = ProcessLORACommand(Line+1);
}
else if (Line[0] == 'A')
{
// OK = ProcessAPRSCommand(Line+1);
}
else if (Line[0] == 'F')
{
OK = ProcessFieldCommand(Line+1);
}
if (OK)
{
printf("*\n");
}
else
{
printf("?\n");
}
}
void check_host(void)
{
static char Line[80];
static unsigned int Length=0;
char Character;
while (uart_is_readable(uart0))
{
char Character;
Character = uart_getc(uart0);
if (Character == '~')
{
Line[0] = Character;
Length = 1;
}
else if (Character == '\r')
{
Line[Length] = '\0';
ProcessCommand(Line+1);
Length = 0;
}
else if (Length >= sizeof(Line))
{
Length = 0;
}
else if (Length > 0)
{
Line[Length++] = Character;
}
}
}
int main()
{
setup_default_uart();
printf("\nPi Pico HAB Tracker V1.0");
printf("\n========================\n\n");
// Init modules
printf("Initialisation ...\n\n");
setup_adc();
setup_led();
setup_bme();
setup_gps();
setup_lora(434.450, 1, "SANTA");
setup_prediction(&GPS);
printf("\nTracker Running ...\n\n");
while (1)
{
check_adc(&GPS);
check_led(&GPS);
check_bme(&GPS);
check_gps(&GPS);
check_lora(&GPS);
check_host();
check_prediction(&GPS);
}
}