This repository was archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRadio.cpp
More file actions
70 lines (61 loc) · 3.53 KB
/
Radio.cpp
File metadata and controls
70 lines (61 loc) · 3.53 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
/*
* CanSat 2020-2021 Team Autonomeasure - Can
* Code written by: Joep van Dijk
* First mission:
* Our first mission is to be able to land properly, collect data from the BMP280 sensor and send that data to the groundstation at least one time per second.
*
* Second mission:
* Our second mission is to make a sustainable data collection station.
*
* Links:
* GitHub Autonomeasure: https://github.com/Autonomeasure
* GitHub Can repo: https://github.com/Autonomeasure/Can
* GitHub GroundStation repo: https://github.com/Autonomeasure/GroundStation
* Instagram: https://instagram.com/Autonomeasure/
*
* This project falls under the GNU GPL-3.0 license, see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt.
*/
#include "Radio.h"
// Write to the HardwareSerial::write method of the radio connection
static void Radio::write(uint8_t c) {
// Check if we can write at least one byte
// if (RADIO.availableForWrite() >= 1) {
// Serial.print("Radio::write ");
// Serial.println(c, DEC);
RADIO.write(c);
// return;
// }
// The Arduino was not able to send this message, maybe create an array of transmissions that are waiting to be transmitted?
}
// Convert a float to an integer
static int Radio::float_to_int(float input) {
// Multiply the input with 100 and convert it to a signed integer
return int(input * 100);
}
// Convert all the values that need to be converted to the correct data type and transmit all the data using the correct protocol
static uint8_t Radio::transmit(unsigned int transmission_id, float bmp_temperature, float mpu_temperature, float pressure, double latitude, double longitude, float altitude, char* time) {
// Convert all the values that need to be converted before the transmission can take place
int i_bmp_temperature = Radio::float_to_int(bmp_temperature); // Convert the bmp_temperature to an integer
int i_mpu_temperature = Radio::float_to_int(mpu_temperature); // Convert the mpu_temperature to an integer
int i_altitude = Radio::float_to_int(altitude); // Convert the altitude to an integer
// Convert everything to a signed int so we can transmit it correctly
uint16_t ui16_bmp_temperature = (uint16_t)(i_bmp_temperature + 32768);
// Serial.println(i_bmp_temperature, HEX);
// Serial.println(transmission_id);
// Start the transmission
Radio::write(SOH); // Start of header
if (transmission_id < 256) Radio::write(0x00); // If the value is below an 8 bits unsigned integer, HardwareSerial::write will only send an 8-bits unsigned integer but then the ground station will intepret the data incorrect so we need to send an nullbyte
Radio::write(transmission_id); // Transmission identifier
Radio::write(ui16_bmp_temperature); // BMP280 temperature
Radio::write(i_mpu_temperature); // MPU6050 temperature
Radio::write(pressure); // BMP280 air pressure
Radio::write(latitude); // The latitude received from the GPS module
Radio::write(longitude); // The longitude received from the GPS module
Radio::write(i_altitude); // The altitude received from the GPS module
Radio::write(time[0]); // The hour received from the GPS module
Radio::write(time[1]); // The minute received from the GPS module
Radio::write(time[2]); // The second received from the GPS module
Radio::write(time[3]); // The centisecond received from the GPS module
Radio::write(EOT); // End of transmission
return 0;
}