From 21a11d2f61d8bd4fabb5a138038a547358fb74f8 Mon Sep 17 00:00:00 2001 From: acarrou Date: Sun, 1 Oct 2023 11:48:03 -0700 Subject: [PATCH] :bug: fixes create and build --- CMakeLists.txt | 16 ++- demos/applications/telemetry-recorder.cpp | 82 ++++++++------- demos/hardware_map.hpp | 2 + demos/platforms/lpc4078.cpp | 12 ++- .../telemetry-recorder/telemetry-recorder.hpp | 33 +++++-- src/telemetry-recorder.cpp | 99 ++++++++++--------- test_package/main.cpp | 3 +- tests/CMakeLists.txt | 2 + 8 files changed, 153 insertions(+), 96 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc6144f..13889d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/demos/applications/telemetry-recorder.cpp b/demos/applications/telemetry-recorder.cpp index 39c79d7..b26349a 100644 --- a/demos/applications/telemetry-recorder.cpp +++ b/demos/applications/telemetry-recorder.cpp @@ -14,13 +14,13 @@ #include #include -#include -#include -#include -#include -#include + +#include +#include +#include #include "../hardware_map.hpp" +#include hal::status application(hardware_map& p_map) { @@ -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)); @@ -56,44 +56,49 @@ 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"); @@ -101,6 +106,7 @@ hal::status application(hardware_map& p_map) hal::print(console, "\n=================== RECIEVED DATA ===================\n"); hal::print(console, recieved_data); hal::print(console, "======================================================\n\n"); - + } + return hal::success(); } diff --git a/demos/hardware_map.hpp b/demos/hardware_map.hpp index e3b137b..e2ea928 100644 --- a/demos/hardware_map.hpp +++ b/demos/hardware_map.hpp @@ -15,6 +15,7 @@ #pragma once #include +#include #include #include @@ -22,6 +23,7 @@ struct hardware_map { hal::serial* console; hal::serial* xbee; + hal::serial* gps; hal::steady_clock* clock; hal::i2c* i2c; hal::callback reset; diff --git a/demos/platforms/lpc4078.cpp b/demos/platforms/lpc4078.cpp index 7d82ab1..d0ef3af 100644 --- a/demos/platforms/lpc4078.cpp +++ b/demos/platforms/lpc4078.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,8 @@ hal::result initialize_platform() static hal::cortex_m::dwt_counter counter(cpu_frequency); static std::array uart0_buffer{}; + static std::array uart1_buffer{}; + static std::array uart2_buffer{}; // Get and initialize UART0 for UART based logging static auto uart0 = HAL_CHECK(hal::lpc40::uart::get(0, uart0_buffer, @@ -48,8 +51,14 @@ hal::result initialize_platform() .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, })); @@ -62,6 +71,7 @@ hal::result initialize_platform() return hardware_map{ .console = &uart0, .xbee = &uart1, + .gps = &uart2, .clock = &counter, .i2c = &i2c, .reset = []() { hal::cortex_m::reset(); }, diff --git a/include/telemetry-recorder/telemetry-recorder.hpp b/include/telemetry-recorder/telemetry-recorder.hpp index e995820..81302f7 100644 --- a/include/telemetry-recorder/telemetry-recorder.hpp +++ b/include/telemetry-recorder/telemetry-recorder.hpp @@ -14,11 +14,18 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include + +#include +#include + + +#include +#include +#include +#include +#include namespace hal::telemetry_recorder { @@ -43,20 +50,26 @@ struct telemetry_data{ float baro_temp; float baro_pressure; float baro_altitude; -} - - +}; [[nodiscard]] static result 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 record(); hal::result> recieve(); -hal::status transmit(std::string_view message); -hal::status 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) diff --git a/src/telemetry-recorder.cpp b/src/telemetry-recorder.cpp index 9f4c330..4f75a50 100644 --- a/src/telemetry-recorder.cpp +++ b/src/telemetry-recorder.cpp @@ -16,64 +16,73 @@ namespace hal::telemetry_recorder { -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) +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) { - 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_recorder::record() +hal::result 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{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{ m_data }; } - hal::result> telemetry_recorder::recieve() { - auto data = HAL_CHECK(m_xbee.read()); - return data; + auto data = HAL_CHECK(m_xbee->read()); + return data; } -hal::status 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 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 diff --git a/test_package/main.cpp b/test_package/main.cpp index c17f0af..0c802bc 100644 --- a/test_package/main.cpp +++ b/test_package/main.cpp @@ -17,7 +17,8 @@ int main() { - hal::telemetry_recorder::telemetry_recorder_replace_me bar; + // hal::telemetry_recorder::telemetry_recorder; + return 0; } namespace boost { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b2448dc..d546a6d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -42,6 +42,7 @@ endif() find_package(ut REQUIRED CONFIG) find_package(libhal REQUIRED CONFIG) find_package(libhal-util REQUIRED CONFIG) +find_package(libhal-icm REQUIRED CONFIG) find_package(libhal-mock REQUIRED CONFIG) add_executable(${PROJECT_NAME} @@ -81,4 +82,5 @@ target_link_libraries(${PROJECT_NAME} PRIVATE boost-ext-ut::ut libhal::libhal libhal::util + libhal::icm libhal::mock)