-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelemetry.cpp
105 lines (86 loc) · 3.37 KB
/
telemetry.cpp
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
// STAY: Solid fuel propelled rocket
// Copyright (C) 2024 Liftorbit
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Arduino.h>
#include <HardwareSerial.h>
#include "telemetry.h"
#define TRANSCEIVER_UART 2
#define TRANSCEIVER_BAUD_RATE 2400
HardwareSerial Transceiver(TRANSCEIVER_UART);
void Telemetry::begin() {
Transceiver.begin(TRANSCEIVER_BAUD_RATE);
};
void Telemetry::sendLog(String log) {
// 0x1C as log start
Transceiver.print('\x1C');
Transceiver.print(log);
// 0x1B as log end
Transceiver.print('\x1B');
};
void Telemetry::send(String message) {
Transceiver.println(message);
};
void Telemetry::send(char code) {
Transceiver.write(code);
};
bool Telemetry::dataAvailable() {
return Transceiver.available() != 0;
};
String Telemetry::receive() {
String data = Transceiver.readString();
data.trim();
return data;
};
void Telemetry::telemetry(bool engine, float temp, float alt, float ps, float acce, float lat, float lon) {
// advanced telemetry
byte motorStatus[sizeof(bool)];
byte temperature[sizeof(float)];
byte altitude[sizeof(float)];
byte pressure[sizeof(float)];
byte acceleration[sizeof(float)];
byte latitude[sizeof(float)];
byte longitude[sizeof(float)];
memcpy(motorStatus, &engine, sizeof(bool));
memcpy(temperature, &temp, sizeof(float));
memcpy(altitude, &alt, sizeof(float));
memcpy(pressure, &ps, sizeof(float));
memcpy(acceleration, &acce, sizeof(float));
memcpy(latitude, &lat, sizeof(float));
memcpy(longitude, &lon, sizeof(float));
Transceiver.write('\x02');
Transceiver.write(motorStatus, sizeof(motorStatus));
Transceiver.write(temperature, sizeof(temperature));
Transceiver.write(altitude, sizeof(altitude));
Transceiver.write(pressure, sizeof(pressure));
Transceiver.write(acceleration, sizeof(acceleration));
Transceiver.write(latitude, sizeof(latitude));
Transceiver.write(longitude, sizeof(longitude));
};
void Telemetry::telemetry(bool engine, float temp, float alt, float ps, float acce) {
// basic telemetry
byte motorStatus[sizeof(bool)];
byte temperature[sizeof(float)];
byte altitude[sizeof(float)];
byte pressure[sizeof(float)];
byte acceleration[sizeof(float)];
memcpy(motorStatus, &engine, sizeof(bool));
memcpy(temperature, &temp, sizeof(float));
memcpy(altitude, &alt, sizeof(float));
memcpy(pressure, &ps, sizeof(float));
memcpy(acceleration, &acce, sizeof(float));
Transceiver.write('\x02');
Transceiver.write(motorStatus, sizeof(motorStatus));
Transceiver.write(temperature, sizeof(temperature));
Transceiver.write(altitude, sizeof(altitude));
Transceiver.write(pressure, sizeof(pressure));
Transceiver.write(acceleration, sizeof(acceleration));
};