diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5ec57b0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/interface"] + path = test/interface + url = https://github.com/rosflight/rosflight_firmware-board-common.git diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a724554..a87cca9 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -32,7 +32,7 @@ set(CMAKE_CXX_FLAGS_DEBUG " ") if(NOT DEFINED ROSFLIGHT_SOURCES) include_directories( ../test - ../test/struct + ../test/interface ) set(ROSFLIGHT_SOURCES "../test/main.cpp") endif() diff --git a/test/board.h b/test/board.h deleted file mode 100644 index f7444eb..0000000 --- a/test/board.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ROSFLIGHT_FIRMWARE_BOARD_H -#define ROSFLIGHT_FIRMWARE_BOARD_H - -#include -#include -#include - -#include - -namespace rosflight_firmware -{ -class Board -{ -public: - typedef enum - { - RC_TYPE_PPM = 0, - RC_TYPE_SBUS = 1 - } rc_type_t; - - // setup - virtual void init_board() = 0; - virtual void board_reset(bool bootloader) = 0; - - virtual void sensors_init(void) = 0; - virtual uint16_t sensors_errors_count() = 0; - - virtual uint16_t sensors_init_message_count() = 0; - virtual bool sensors_init_message_good(uint16_t i) = 0; - virtual uint16_t sensors_init_message(char * message, uint16_t size, uint16_t i) = 0; - - // clock - virtual uint32_t clock_millis() = 0; - virtual uint64_t clock_micros() = 0; - virtual void clock_delay(uint32_t milliseconds) = 0; - - // serial - virtual void serial_init(uint32_t baud_rate, uint32_t dev) = 0; - // qos defines the 'priority' of the packet, with 0 being the highest - virtual void serial_write(const uint8_t * src, size_t len, uint8_t qos) = 0; - virtual uint16_t serial_bytes_available() = 0; - virtual uint8_t serial_read() = 0; - virtual void serial_flush() = 0; - - // IMU - virtual bool imu_read(rosflight_firmware::ImuStruct * imu) = 0; - - // Mag - virtual bool mag_read(rosflight_firmware::MagStruct * mag) = 0; - - // Baro - virtual bool baro_read(PressureStruct * diff_pressure) = 0; - - // Pitot - virtual bool diff_pressure_read(PressureStruct * diff_pressure) = 0; - - // Sonar - virtual bool sonar_read(RangeStruct * sonar) = 0; - - // GPS - virtual bool gnss_read(rosflight_firmware::GnssStruct * gnss) = 0; - // Battery - virtual bool battery_read(rosflight_firmware::BatteryStruct * bat) = 0; - virtual void battery_voltage_set_multiplier(double multiplier) = 0; - virtual void battery_current_set_multiplier(double multiplier) = 0; - - // RC - virtual void rc_init(rc_type_t rc_type) = 0; - virtual bool rc_read(rosflight_firmware::RcStruct * rc) = 0; - - // PWM - virtual void pwm_init(const float * rate, uint32_t channels) = 0; - virtual void pwm_disable() = 0; - virtual void pwm_write(float * value, uint32_t channels) = 0; - - // non-volatile memory - virtual void memory_init() = 0; - virtual bool memory_read(void * dest, size_t len) = 0; - virtual bool memory_write(const void * src, size_t len) = 0; - - // LEDs - virtual void led0_on() = 0; - virtual void led0_off() = 0; - virtual void led0_toggle() = 0; - - virtual void led1_on() = 0; - virtual void led1_off() = 0; - virtual void led1_toggle() = 0; - - // Backup memory - virtual void backup_memory_init() = 0; - virtual bool backup_memory_read(void * dest, size_t len) = 0; - virtual void backup_memory_write(const void * src, size_t len) = 0; - virtual void backup_memory_clear(size_t len) = 0; -}; - -} // namespace rosflight_firmware - -#endif // ROSLFIGHT_FIRMWARE_BOARD_H diff --git a/test/interface b/test/interface new file mode 160000 index 0000000..b94ab04 --- /dev/null +++ b/test/interface @@ -0,0 +1 @@ +Subproject commit b94ab0415292cd2dd46e30dd966d44c556998c24 diff --git a/test/rosflight_structs.h b/test/rosflight_structs.h deleted file mode 100644 index 9644f5c..0000000 --- a/test/rosflight_structs.h +++ /dev/null @@ -1,189 +0,0 @@ -/** - ****************************************************************************** - * File : rosflight_structs.h - * Date : Nov 20, 2024 - ****************************************************************************** - * - * Copyright (c) 2023, AeroVironment, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1.Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * 2.Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3.Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - **/ - -#ifndef INCLUDE_INTERFACE_ROSFLIGHT_STRUCTS_H_ -#define INCLUDE_INTERFACE_ROSFLIGHT_STRUCTS_H_ - -namespace rosflight_firmware -{ - -typedef struct //__attribute__((__packed__)) -{ - uint64_t timestamp; // us, time of data read complete - float voltage; - float current; - float temperature; // STM32 temperature, not batter temperature -} BatteryStruct; - -typedef struct //__attribute__((__packed__)) -{ - uint64_t timestamp; // us, time of data read complete - float accel[3]; // rad/s - float gyro[3]; // rad/s - float temperature; // K -} ImuStruct; - -typedef struct //__attribute__((__packed__)) -{ - uint64_t timestamp; // us, time of data read complete - float pressure; // Pa - float temperature; // K - union - { - float altitude; - float speed; - }; -} PressureStruct; - -enum class SensorRangeType // c.f., ROSFLIGHT_RANGE_TYPE -{ - ROSFLIGHT_RANGE_SONAR = 0, /* | */ - ROSFLIGHT_RANGE_LIDAR = 1, /* | */ - END = 2, /* | */ -}; - -typedef struct //__attribute__((__packed__)) -{ - uint64_t timestamp; // us, time of data read complete - float range; // m - float min_range; // m - float max_range; // m - SensorRangeType type; // ROSFLIGHT_RANGE_SONAR, ROSFLIGHT_RANGE_SONAR -} RangeStruct; - -typedef struct //__attribute__((packed)) -{ - uint64_t timestamp; // us, time of data read complete - float flux[3]; // T, magnetic flux density - float temperature; // K -} MagStruct; - -enum class GNSSFixType // quality from GGA -{ - GNSS_FIX_TYPE_NO_FIX = 0, - GNSS_FIX_TYPE_DEAD_RECKONING_ONLY = 1, - GNSS_FIX_TYPE_2D_FIX = 2, - GNSS_FIX_TYPE_3D_FIX = 3, - GNSS_FIX_TYPE_GNSS_PLUS_DEAD_RECKONING = 4, - GNSS_FIX_TYPE_TIME_FIX_ONLY = 5, - GNSS_FIX_RTK_FLOAT = 6, - GNSS_FIX_RTK_FIXED = 7, - END = 8 -}; - -typedef struct //__attribute__((__packed__)) -{ - uint64_t timestamp; // us, time of data read complete - uint64_t pps; // most recent pps timestamp - uint64_t time; // Unix time, in seconds (redundant) - // GPS Time - uint32_t time_of_week; // / PVT - uint16_t year; // RMC / PVT - uint8_t month; // RMC / PVT - uint8_t day; // RMC / PVT - uint8_t hour; // GGA RMC UTC Time / PVT - uint8_t min; // GGA RMC UTC Time / PVT - uint8_t sec; // GGA RMC UTC Time / PVT - uint32_t nano; // GGA RMC UTC Time (ms) / PVT nano - uint32_t t_acc; - int32_t lon; // GGA RMC / PVT - int32_t lat; // GGA RMC / PVT - int32_t height_ellipsoid; //GGA RMC (computed) / PVT - int32_t height_msl; // GGA / PVT - uint32_t h_acc; // GST (lat and lon) / PVT hAcc - uint32_t v_acc; // GST / PVT vAcc - int32_t ground_speed; // RMC / PVT gSpeed - int32_t course; // RMC / PVT headMot - int32_t course_accy; - int32_t vel_n; // no / PVT (RMC compute from ground velocity) - int32_t vel_e; // no / PVT (RMC compute from ground velocity) - int32_t vel_d; // no / PVT - uint32_t speed_accy; // no /PVT (sACC) speed accuracy - uint32_t mag_var; // RMC / PVT - // Fix - uint8_t fix_type; // RMC (posmode), compute from GGA(quality) /PVT flags - uint8_t valid; // RMC (status), compute from GGA (0 or 6) - uint8_t num_sat; // GGA - uint16_t dop; // GGA RMC / PVT (pdop) - struct - { - int32_t x; // cm // not available on NMEA - int32_t y; // cm - int32_t z; // cm - uint32_t p_acc; // cm - int32_t vx; // cm/s - int32_t vy; // cm/s - int32_t vz; // cm/s - uint32_t s_acc; // cm/s - } ecef; -} GnssStruct; - -typedef struct -{ - bool imu; - bool gnss; - bool gnss_full; - bool baro; - bool mag; - bool diff_pressure; - bool sonar; - bool battery; -} got_flags; - -// 16 analog + 8 digital MUST BE > 14 (Mavlink message size is hardware to 14) -#define RC_STRUCT_CHANNELS 24 -typedef struct //__attribute__((packed)) -{ - uint64_t timestamp; // us, time of data read complete - uint8_t nChan; - float chan[RC_STRUCT_CHANNELS]; - bool frameLost; - bool failsafeActivated; -} RcStruct; - - -typedef struct //__attribute__((__packed__)) -{ - uint64_t timestamp; // us, time of data read complete - float q[4]; // quaternions - float rate[3]; -} AttitudeStruct; - -} - - -#endif /* INCLUDE_INTERFACE_ROSFLIGHT_STRUCTS_H_ */