test_board.cpp
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 #include "test_board.h"
33 
34 #pragma GCC diagnostic push
35 #pragma GCC diagnostic ignored "-Wunused-parameter"
36 
37 namespace rosflight_firmware
38 {
39 void testBoard::set_rc(uint16_t *values)
40 {
41  for (int i = 0; i < 8; i++)
42  {
43  rc_values[i] = values[i];
44  }
45 }
46 
47 void testBoard::set_time(uint64_t time_us)
48 {
49  time_us_ = time_us;
50 }
51 
52 void testBoard::set_pwm_lost(bool lost)
53 {
54  rc_lost_ = lost;
55 }
56 
57 void testBoard::set_imu(float *acc, float *gyro, uint64_t time_us)
58 {
59  time_us_ = time_us;
60  for (int i = 0; i < 3; i++)
61  {
62  acc_[i] = acc[i];
63  gyro_[i] = gyro[i];
64  }
65  new_imu_ = true;
66 }
67 
68 // setup
70 {
72 }
73 void testBoard::board_reset(bool bootloader) {}
74 
75 // clock
77 {
78  return time_us_ / 1000;
79 }
81 {
82  return time_us_;
83 }
84 void testBoard::clock_delay(uint32_t milliseconds) {}
85 
86 // serial
87 void testBoard::serial_init(uint32_t baud_rate, uint32_t dev) {}
88 void testBoard::serial_write(const uint8_t *src, size_t len) {}
90 {
91  return 0;
92 }
94 {
95  return 0;
96 }
98 
99 // sensors
102 {
103  return 0;
104 }
105 
107 {
108  if (new_imu_)
109  {
110  new_imu_ = false;
111  return true;
112  }
113  return false;
114 }
115 
116 bool testBoard::imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time)
117 {
118  for (int i = 0; i < 3; i++)
119  {
120  accel[i] = acc_[i];
121  gyro[i] = gyro_[i];
122  }
123  *temperature = 25.0;
124  *time = time_us_;
125  return true;
126 }
127 
128 bool testBoard::backup_memory_read(void *dest, size_t len)
129 {
130  bool success = true;
131  if (len > BACKUP_MEMORY_SIZE)
132  {
133  len = BACKUP_MEMORY_SIZE;
134  success = false;
135  }
136  memcpy(dest, backup_memory_, len);
137  return success;
138 }
139 
140 void testBoard::backup_memory_write(const void *src, size_t len)
141 {
142  if (len > BACKUP_MEMORY_SIZE)
143  len = BACKUP_MEMORY_SIZE;
144  memcpy(backup_memory_, src, len);
145 }
147 {
148  memset(backup_memory_, 0, len);
149 }
151 {
153 }
154 
156 
158 {
159  return false;
160 }
162 void testBoard::mag_read(float mag[3]) {}
163 
165 {
166  return false;
167 }
170 
172 {
173  return false;
174 }
176 void testBoard::diff_pressure_read(float *diff_pressure, float *temperature) {}
177 
179 {
180  return false;
181 }
184 {
185  return 0;
186 }
187 
189 {
190  return false;
191 }
193 {
194  return 0;
195 }
197 {
198  (void)multiplier;
199 }
200 
202 {
203  return false;
204 }
206 {
207  return 0;
208 }
210 {
211  (void)multiplier;
212 }
213 
214 // GNSS is not supported on the test board
216 {
217  return {};
218 }
219 
220 // GNSS is not supported on the test board
222 {
223  return {};
224 }
225 
226 // GNSS is not supported on the test board
228 {
229  return false;
230 }
231 
232 // PWM
233 // TODO make these deal in normalized (-1 to 1 or 0 to 1) values (not pwm-specific)
236 {
237  return rc_lost_;
238 }
239 float testBoard::rc_read(uint8_t channel)
240 {
241  return static_cast<float>(rc_values[channel] - 1000) / 1000.0;
242 }
243 void testBoard::pwm_write(uint8_t channel, float value) {}
244 void testBoard::pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) {}
246 
247 // non-volatile memory
249 bool testBoard::memory_read(void *dest, size_t len)
250 {
251  return false;
252 }
253 bool testBoard::memory_write(const void *src, size_t len)
254 {
255  return false;
256 }
257 
258 // LEDs
262 
266 
267 } // namespace rosflight_firmware
268 
269 #pragma GCC diagnostic pop
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
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
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
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 Thu Apr 15 2021 05:07:49