-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (79 loc) · 2.01 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (79 loc) · 2.01 KB
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
/**
* @file main.cpp
* @author sj728
*
* @brief The entry point for the program
*/
#include <cstdio>
#include "pico/stdlib.h"
#include "pins.hpp"
#include "tusb.h"
#include "sd.hpp"
#include "telemetry.hpp"
#include "radio.hpp"
#include "ublox_mx.hpp"
#include "ublox_nav_pvt.hpp"
#include "hardware/i2c.h"
#include "vector"
int main()
{
stdio_init_all();
Radio radio;
if (!radio.start())
{
#ifdef RATS_VERBOSE
printf("Radio failed to start\n");
#endif
return 1;
}
// Initialize GNSS module
// GNSS gnss(i2c0);
// if (!gnss.begin_PVT(100))
// {
// printf("GNSS failed to start\n");
// return 1;
// }
// Initialize SD card module
SD sd;
if (!sd.begin())
{
#ifdef RATS_VERBOSE
printf("SD card failed to start\n");
#endif
return 1;
}
#ifdef MOVER
// Iniatialize Motor controller
#endif
int LED = 25;
gpio_init(LED);
gpio_set_dir(LED, GPIO_OUT);
bool on = true;
const int WAIT_TIME_MS = 2;
while (true)
{
gpio_put(LED, on);
std::vector<Telemetry> telemetry_packets;
bool success = radio.read(telemetry_packets);
// Untested for now, but this is how data will be transferred serially
// to the external software component (RATS proxy)
if (success)
{
// Write the entire struct's raw memory to stdout in one call,
// sending it serially to the external software component
const int num_elements = 1;
for (const Telemetry &telemetry : telemetry_packets)
{
sd.log_telemetry(telemetry);
tud_cdc_write(&telemetry, sizeof(telemetry));
tud_cdc_write_flush(); // Make sure the data is sent immediately
sleep_ms(WAIT_TIME_MS);
}
on = !on;
}
#ifdef MOVER
// Move motors based on data from radio module
#endif
}
return 0;
}