test_board.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, James Jackson and Daniel Koch, BYU MAGICC Lab
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the copyright holder nor the names of its
17  * contributors may be used to endorse or promote products derived from
18  * this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef ROSFLIGHT_FIRMWARE_TEST_BOARD_H
33 #define ROSFLIGHT_FIRMWARE_TEST_BOARD_H
34 
35 #include "board.h"
36 #include "sensors.h"
37 
38 namespace rosflight_firmware
39 {
40 class testBoard : public Board
41 {
42 private:
43  uint16_t rc_values[8] = {1500, 1500, 1000, 1500, 1500, 1500, 1500, 1500};
44  uint64_t time_us_ = 0;
45  bool rc_lost_ = false;
46  float acc_[3] = {0, 0, 0};
47  float gyro_[3] = {0, 0, 0};
48  bool new_imu_ = false;
49  static constexpr size_t BACKUP_MEMORY_SIZE{1024};
51 
52 public:
53  // setup
54  void init_board() override;
55  void board_reset(bool bootloader) override;
56 
57  // clock
58  uint32_t clock_millis() override;
59  uint64_t clock_micros() override;
60  void clock_delay(uint32_t milliseconds) override;
61 
62  // serial
63  void serial_init(uint32_t baud_rate, uint32_t dev) override;
64  void serial_write(const uint8_t *src, size_t len) override;
65  uint16_t serial_bytes_available() override;
66  uint8_t serial_read() override;
67  void serial_flush() override;
68 
69  // sensors
70  void sensors_init() override;
71  uint16_t num_sensor_errors();
72 
73  bool new_imu_data() override;
74  bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time) override;
75  void imu_not_responding_error() override;
76 
77  bool mag_present() override;
78  void mag_update() override;
79  void mag_read(float mag[3]) override;
80 
81  bool baro_present() override;
82  void baro_update() override;
83  void baro_read(float *pressure, float *temperature) override;
84 
85  bool diff_pressure_present() override;
86  void diff_pressure_update() override;
87  void diff_pressure_read(float *diff_pressure, float *temperature) override;
88 
89  bool sonar_present() override;
90  void sonar_update() override;
91  float sonar_read() override;
92 
93  bool gnss_present() override { return false; }
94  void gnss_update() override {}
95  GNSSData gnss_read() override;
96  GNSSFull gnss_full_read() override;
97  bool gnss_has_new_data() override;
98 
99  bool battery_voltage_present() const override;
100  float battery_voltage_read() const override;
101  void battery_voltage_set_multiplier(double multiplier) override;
102 
103  bool battery_current_present() const override;
104  float battery_current_read() const override;
105  void battery_current_set_multiplier(double multiplier) override;
106 
107  // RC
108  void rc_init(rc_type_t rc_type) override;
109  bool rc_lost() override;
110  float rc_read(uint8_t channel) override;
111 
112  // PWM
113  void pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) override;
114  void pwm_disable() override;
115  void pwm_write(uint8_t channel, float value) override;
116 
117  // non-volatile memory
118  void memory_init() override;
119  bool memory_read(void *dest, size_t len) override;
120  bool memory_write(const void *src, size_t len) override;
121 
122  // LEDs
123  void led0_on() override;
124  void led0_off() override;
125  void led0_toggle() override;
126 
127  void led1_on() override;
128  void led1_off() override;
129  void led1_toggle() override;
130 
131  // Backup memory
132  void backup_memory_init() override {}
133  bool backup_memory_read(void *dest, size_t len) override;
134  void backup_memory_write(const void *src, size_t len) override;
135  void backup_memory_clear(size_t len) override;
136  void backup_memory_clear(); // Not an override
137 
138  void set_imu(float *acc, float *gyro, uint64_t time_us);
139  void set_rc(uint16_t *values);
140  void set_time(uint64_t time_us);
141  void set_pwm_lost(bool lost);
142 };
143 
144 } // namespace rosflight_firmware
145 
146 #endif // ROSLFIGHT_FIRMWARE_TEST_BOARD_H
uint32_t clock_millis() override
Definition: test_board.cpp:76
void pwm_write(uint8_t channel, float value) override
Definition: test_board.cpp:243
static volatile int16_t gyro[3]
Definition: drv_mpu6050.c:277
bool gnss_present() override
Definition: test_board.h:93
void board_reset(bool bootloader) override
Definition: test_board.cpp:73
void serial_init(uint32_t baud_rate, uint32_t dev) override
Definition: test_board.cpp:87
float pressure
Definition: ms4525.c:41
void mag_read(float mag[3]) override
Definition: test_board.cpp:162
float temperature
Definition: ms4525.c:41
void backup_memory_write(const void *src, size_t len) override
Definition: test_board.cpp:140
static constexpr size_t BACKUP_MEMORY_SIZE
Definition: test_board.h:49
void set_imu(float *acc, float *gyro, uint64_t time_us)
Definition: test_board.cpp:57
bool diff_pressure_present() override
Definition: test_board.cpp:171
uint16_t serial_bytes_available() override
Definition: test_board.cpp:89
uint64_t clock_micros() override
Definition: test_board.cpp:80
void rc_init(rc_type_t rc_type) override
Definition: test_board.cpp:234
void set_rc(uint16_t *values)
Definition: test_board.cpp:39
bool backup_memory_read(void *dest, size_t len) override
Definition: test_board.cpp:128
float rc_read(uint8_t channel) override
Definition: test_board.cpp:239
static volatile int16_t accel[3]
Definition: drv_mpu6050.c:276
float battery_voltage_read() const override
Definition: test_board.cpp:192
GNSSFull gnss_full_read() override
Definition: test_board.cpp:221
uint8_t serial_read() override
Definition: test_board.cpp:93
void baro_read(float *pressure, float *temperature) override
Definition: test_board.cpp:169
void serial_flush() override
Definition: test_board.cpp:97
void gnss_update() override
Definition: test_board.h:94
bool gnss_has_new_data() override
Definition: test_board.cpp:227
void diff_pressure_read(float *diff_pressure, float *temperature) override
Definition: test_board.cpp:176
void battery_voltage_set_multiplier(double multiplier) override
Definition: test_board.cpp:196
void set_time(uint64_t time_us)
Definition: test_board.cpp:47
bool battery_voltage_present() const override
Definition: test_board.cpp:188
void backup_memory_init() override
Definition: test_board.h:132
bool memory_read(void *dest, size_t len) override
Definition: test_board.cpp:249
void diff_pressure_update() override
Definition: test_board.cpp:175
bool battery_current_present() const override
Definition: test_board.cpp:201
bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time) override
Definition: test_board.cpp:116
void clock_delay(uint32_t milliseconds) override
Definition: test_board.cpp:84
void imu_not_responding_error() override
Definition: test_board.cpp:155
GNSSData gnss_read() override
Definition: test_board.cpp:215
void set_pwm_lost(bool lost)
Definition: test_board.cpp:52
void serial_write(const uint8_t *src, size_t len) override
Definition: test_board.cpp:88
void battery_current_set_multiplier(double multiplier) override
Definition: test_board.cpp:209
float battery_current_read() const override
Definition: test_board.cpp:205
bool memory_write(const void *src, size_t len) override
Definition: test_board.cpp:253
void pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) override
Definition: test_board.cpp:244
uint8_t backup_memory_[BACKUP_MEMORY_SIZE]
Definition: test_board.h:50


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Sat May 9 2020 03:16:54