Skip to content

Commit

Permalink
🐛 fixes create and build
Browse files Browse the repository at this point in the history
  • Loading branch information
acarrou committed Oct 1, 2023
1 parent d3c6f61 commit 21a11d2
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 96 deletions.
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@ cmake_minimum_required(VERSION 3.15)

project(telemetry-recorder VERSION 0.0.1 LANGUAGES CXX)


find_package(libhal REQUIRED CONFIG)
find_package(libhal-util REQUIRED CONFIG)
find_package(libhal-icm REQUIRED CONFIG)
find_package(libhal-neo REQUIRED CONFIG)
find_package(libhal-mpl REQUIRED CONFIG)
find_package(libhal-microsd REQUIRED CONFIG)
find_package(libhal-xbee REQUIRED CONFIG)


add_library(telemetry-recorder src/telemetry-recorder.cpp)

target_include_directories(telemetry-recorder PUBLIC include)
target_include_directories(telemetry-recorder PUBLIC include
)

target_compile_features(telemetry-recorder PRIVATE cxx_std_20)
target_compile_options(telemetry-recorder PRIVATE -Wall -Wextra)
target_link_libraries(telemetry-recorder PRIVATE
libhal::libhal
libhal::util
libhal::icm
libhal::neo
libhal::mpl
libhal::microsd
libhal::xbee
)

if(NOT BUILD_TESTING STREQUAL OFF)
Expand Down
82 changes: 44 additions & 38 deletions demos/applications/telemetry-recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

#include <libhal-util/serial.hpp>
#include <libhal-util/steady_clock.hpp>
#include <libhal/libhal-icm.hpp>
#include <libhal/libhal-microsd.hpp>
#include <libhal/libhal-mpl.hpp>
#include <libhal/libhal-neo.hpp>
#include <libhal/libhal-xbee.hpp>

#include <libhal-lpc40/output_pin.hpp>
#include <libhal-lpc40/spi.hpp>
#include <libhal-util/spi.hpp>

#include "../hardware_map.hpp"
#include<telemetry-recorder/telemetry-recorder.hpp>

hal::status application(hardware_map& p_map)
{
Expand All @@ -29,8 +29,8 @@ hal::status application(hardware_map& p_map)

auto& clock = *p_map.clock;
auto& console = *p_map.console;
auto& gps = *p_map.gps;
auto& xbee = *p_map.xbee;
auto& gps = *p_map.gps;
auto& i2c = *p_map.i2c;

auto spi2 = HAL_CHECK(hal::lpc40::spi::get(2));
Expand All @@ -56,51 +56,57 @@ hal::status application(hardware_map& p_map)
while (true) {
hal::delay(clock, 500ms);
hal::print(console, "\n=================== Data ===================\n");

auto data = hal::print<512>(console,
"G-Accel Values: x = %fg, y = %fg, z = %fg\n
Gyro Values: x = %f, y = %f, z = %f\n
IMU Temperature: %f°C\n
Barometer Temperature: % f°C\n
Measured Pressure: %fPa\n
Barometer Measured Altitude: %fm\n
Latitude: %f\n
Longitude: %f\n
Number of satellites seen: %d\n
Altitude: %f meters\n
Time: %f\n",
telemetry_recorder.accel_x,
telemetry_recorder.accel_y,
telemetry_recorder.accel_z,
telemetry_recorder.gyro_x,
telemetry_recorder.gyro_y,
telemetry_recorder.gyro_z,
telemetry_recorder.imu_temp,
telemetry_recorder.baro_temp,
telemetry_recorder.baro_pressure,
telemetry_recorder.baro_altitude,
telemetry_recorder.gps_lat,
telemetry_recorder.gps_long,
telemetry_recorder.gps_sats,
telemetry_recorder.gps_alt,
telemetry_recorder.gps_time);
auto telemetry_recorder_data = HAL_CHECK(telemetry_recorder.record());

char telem_data[512];
snprintf(telem_data, sizeof(telem_data),
"G-Accel Values: x = %fg, y = %fg, z = %fg\n"
"Gyro Values: x = %f, y = %f, z = %f\n"
"IMU Temperature: %f°C\n"
"Barometer Temperature: % f°C\n"
"Measured Pressure: %fPa\n"
"Barometer Measured Altitude: %fm\n"
"Latitude: %f\n"
"Longitude: %f\n"
"Number of satellites seen: %d\n"
"Altitude: %f meters\n"
"Time: %f\n",
telemetry_recorder_data.accel_x,
telemetry_recorder_data.accel_y,
telemetry_recorder_data.accel_z,
telemetry_recorder_data.gyro_x,
telemetry_recorder_data.gyro_y,
telemetry_recorder_data.gyro_z,
telemetry_recorder_data.imu_temp,
telemetry_recorder_data.baro_temp,
telemetry_recorder_data.baro_pressure,
telemetry_recorder_data.baro_altitude,
telemetry_recorder_data.gps_lat,
telemetry_recorder_data.gps_long,
telemetry_recorder_data.gps_sats,
telemetry_recorder_data.gps_alt,
telemetry_recorder_data.gps_time
);


hal::print<512>(console, telem_data);

hal::print(console, "============================================\n\n");
}

hal::print(console, "Transmitting Data to Ground Station...\n\n");
telemetry_recorder.transmit("Here is some data!\n");
telemetry_recorder.transmit(data);
telemetry_recorder.transmit(telem_data);

hal::print(console, "Storing Data to SD Card...\n\n");
telemetry_recorder.store(data);
telemetry_recorder.store(telem_data);
hal::delay(clock, 500ms);

hal::print(console, "Recieveing Data from Ground Station...\n\n");
auto recieved_data = HAL_CHECK(telemetry_recorder.recieve());
hal::print(console, "\n=================== RECIEVED DATA ===================\n");
hal::print(console, recieved_data);
hal::print(console, "======================================================\n\n");

}

return hal::success();
}
2 changes: 2 additions & 0 deletions demos/hardware_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
#pragma once

#include <libhal/functional.hpp>
#include <libhal/i2c.hpp>
#include <libhal/serial.hpp>
#include <libhal/steady_clock.hpp>

struct hardware_map
{
hal::serial* console;
hal::serial* xbee;
hal::serial* gps;
hal::steady_clock* clock;
hal::i2c* i2c;
hal::callback<void()> reset;
Expand Down
12 changes: 11 additions & 1 deletion demos/platforms/lpc4078.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <libhal-armcortex/startup.hpp>
#include <libhal-armcortex/system_control.hpp>
#include <libhal-lpc40/clock.hpp>
#include <libhal-lpc40/i2c.hpp>
#include <libhal-lpc40/constants.hpp>
#include <libhal-lpc40/uart.hpp>
#include <libhal-util/as_bytes.hpp>
Expand All @@ -41,15 +42,23 @@ hal::result<hardware_map> initialize_platform()
static hal::cortex_m::dwt_counter counter(cpu_frequency);

static std::array<hal::byte, 64> uart0_buffer{};
static std::array<hal::byte, 812> uart1_buffer{};
static std::array<hal::byte, 812> uart2_buffer{};
// Get and initialize UART0 for UART based logging
static auto uart0 = HAL_CHECK(hal::lpc40::uart::get(0,
uart0_buffer,
hal::serial::settings{
.baud_rate = 115200,
}));

static auto uart1 = HAL_CHECK(hal::lpc40::uart::get(1,
static auto uart1 = HAL_CHECK(hal::lpc40::uart::get(1,
uart1_buffer,
hal::serial::settings{
.baud_rate = 9600,
}));

static auto uart2 = HAL_CHECK(hal::lpc40::uart::get(2,
uart2_buffer,
hal::serial::settings{
.baud_rate = 38400,
}));
Expand All @@ -62,6 +71,7 @@ hal::result<hardware_map> initialize_platform()
return hardware_map{
.console = &uart0,
.xbee = &uart1,
.gps = &uart2,
.clock = &counter,
.i2c = &i2c,
.reset = []() { hal::cortex_m::reset(); },
Expand Down
33 changes: 23 additions & 10 deletions include/telemetry-recorder/telemetry-recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@

#pragma once

#include <libhal/libhal-icm.hpp>
#include <libhal/libhal-neo.hpp>
#include <libhal/libhal-mpl.hpp>
#include <libhal/libhal-microsd.hpp>
#include <libhal/libhal-xbee.hpp>
#include <libhal/functional.hpp>
#include <libhal/serial.hpp>

#include <libhal/timeout.hpp>
#include <libhal/units.hpp>


#include <libhal-icm/icm20948.hpp>
#include <libhal-neo/neo.hpp>
#include <libhal-mpl/mpl3115a2.hpp>
#include <libhal-microsd/microsd.hpp>
#include <libhal-xbee/xbee.hpp>


namespace hal::telemetry_recorder {
Expand All @@ -43,20 +50,26 @@ struct telemetry_data{
float baro_temp;
float baro_pressure;
float baro_altitude;
}


};

[[nodiscard]] static result<telemetry_recorder> create(hal::icm::icm20948& p_imu, hal::neo::neo_GPS& p_gps, hal::mpl::mpl3115a2& p_baro, hal::microsd::microsd_card& p_microsd, hal::xbee::xbee_radio& p_xbee);

hal::result<telemetry_data> record();
hal::result<std::span<hal::byte>> recieve();
hal::status<void> transmit(std::string_view message);
hal::status<void> store(std::string_view message);
hal::status transmit(std::string_view message);
hal::status store(std::string_view message);



private:

hal::icm::icm20948* m_icm;
hal::neo::neo_GPS* m_gps;
hal::mpl::mpl3115a2* m_mpl;
hal::microsd::microsd_card* m_microsd;
hal::xbee::xbee_radio* m_xbee;


explicit telemetry_recorder(hal::icm::icm20948& p_imu, hal::neo::neo_GPS& p_gps, hal::mpl::mpl3115a2& p_baro, hal::microsd::microsd_card& p_microsd, hal::xbee::xbee_radio& p_xbee)
: m_icm(&p_imu)
, m_gps(&p_gps)
Expand Down
99 changes: 54 additions & 45 deletions src/telemetry-recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,64 +16,73 @@

namespace hal::telemetry_recorder {

result<telemetry_recorder> telemetry_recorder::create(hal::icm::icm20948& p_imu, hal::neo::neo_GPS& p_gps, hal::mpl::mpl3115a2& p_baro, hal::microsd::microsd_card& p_microsd, hal::xbee::xbee_radio& p_xbee)
result<telemetry_recorder> telemetry_recorder::create(
hal::icm::icm20948& p_imu,
hal::neo::neo_GPS& p_gps,
hal::mpl::mpl3115a2& p_baro,
hal::microsd::microsd_card& p_microsd,
hal::xbee::xbee_radio& p_xbee)
{
return telemetry_recorder(p_imu, p_gps, p_baro, p_microsd, p_xbee);
telemetry_recorder recorder{ p_imu, p_gps, p_baro, p_microsd, p_xbee };
return recorder;
}

hal::result<telemetry_data> telemetry_recorder::record()
hal::result<telemetry_recorder::telemetry_data> telemetry_recorder::record()
{
auto accel = m_icm.read_acceleration();
auto gyro = m_icm.read_gyroscope();
auto imu_temp = m_icm.read_temperature();

auto gps = m_gps.read();

auto baro_temp = m_baro.read_temperature().temperature;
auto pressure = m_baro.read_pressure().pressure;
auto altitude = m_baro.read_altitude().altitude;


m_data.accel_x = accel.x;
m_data.accel_y = accel.y;
m_data.accel_z = accel.z;
m_data.gyro_x = gyro.x;
m_data.gyro_y = gyro.y;
m_data.gyro_z = gyro.z;
m_data.imu_temp = imu_temp;

m_data.gps_time = gps.time;
m_data.gps_lat = gps.latitude;
m_data.gps_long = gps.longitude;
m_data.gps_sats = gps.satellites_used;
m_data.gps_alt = gps.altitude;

m_data.baro_temp = baro_temp;
m_data.baro_pressure = pressure;
m_data.baro_altitude = altitude;


hal::result<telemetry_data>{m_data};
auto accel_result = m_icm->read_acceleration();
auto gyro_result = m_icm->read_gyroscope();
auto imu_temp_result = m_icm->read_temperature();

auto gps = HAL_CHECK(m_gps->read());

auto baro_temp_result = m_mpl->read_temperature();
auto pressure_result = m_mpl->read_pressure();
auto altitude_result = m_mpl->read_altitude();

auto accel = *accel_result;
auto gyro = *gyro_result;
auto imu_temp = *imu_temp_result;
auto baro_temp = *baro_temp_result;
auto pressure = *pressure_result;
auto altitude = *altitude_result;

m_data.accel_x = accel.x;
m_data.accel_y = accel.y;
m_data.accel_z = accel.z;
m_data.gyro_x = gyro.x;
m_data.gyro_y = gyro.y;
m_data.gyro_z = gyro.z;
m_data.imu_temp = imu_temp.temp;

m_data.gps_time = gps.time;
m_data.gps_lat = gps.latitude;
m_data.gps_long = gps.longitude;
m_data.gps_sats = gps.satellites_used;
m_data.gps_alt = gps.altitude;

m_data.baro_temp = baro_temp.temperature;
m_data.baro_pressure = pressure.pressure;
m_data.baro_altitude = altitude.altitude;

return hal::result<telemetry_recorder::telemetry_data>{ m_data };
}


hal::result<std::span<hal::byte>> telemetry_recorder::recieve()
{
auto data = HAL_CHECK(m_xbee.read());
return data;
auto data = HAL_CHECK(m_xbee->read());
return data;
}

hal::status<void> telemetry_recorder::transmit(std::string_view message)
hal::status telemetry_recorder::transmit(std::string_view message)
{
m_xbee.write(hal::as_bytes(message));
return hal::success();
m_xbee->write(hal::as_bytes(message));
return hal::success();
}

hal::status<void> telemetry_recorder::store(std::string_view message)
hal::status telemetry_recorder::store(std::string_view message)
{
m_microsd.write(hal::as_bytes(message));
return hal::success();
// m_microsd->write(hal::as_bytes(message));
return hal::success();
}


} // namespace hal::elemetry_recorder
} // namespace hal::telemetry_recorder
3 changes: 2 additions & 1 deletion test_package/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

int main()
{
hal::telemetry_recorder::telemetry_recorder_replace_me bar;
// hal::telemetry_recorder::telemetry_recorder;
return 0;
}

namespace boost {
Expand Down
Loading

0 comments on commit 21a11d2

Please sign in to comment.