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 
40 void testBoard::set_rc(uint16_t *values)
41 {
42  for (int i = 0; i < 8; i++)
43  {
44  rc_values[i] = values[i];
45  }
46 }
47 
48 void testBoard::set_time(uint64_t time_us)
49 {
50  time_us_ = time_us;
51 }
52 
53 void testBoard::set_pwm_lost(bool lost)
54 {
55  rc_lost_ = lost;
56 }
57 
58 void testBoard::set_imu(float *acc, float *gyro, uint64_t time_us)
59 {
60  time_us_ = time_us;
61  for (int i = 0; i < 3; i++)
62  {
63  acc_[i] = acc[i];
64  gyro_[i] = gyro[i];
65  }
66  new_imu_ = true;
67 }
68 
69 
70 // setup
72 void testBoard::board_reset(bool bootloader) {}
73 
74 // clock
75 uint32_t testBoard::clock_millis() { return time_us_/1000; }
76 uint64_t testBoard::clock_micros() { return time_us_; }
77 void testBoard::clock_delay(uint32_t milliseconds) {}
78 
79 // serial
80 void testBoard::serial_init(uint32_t baud_rate, uint32_t dev) {}
81 void testBoard::serial_write(const uint8_t *src, size_t len) {}
82 uint16_t testBoard::serial_bytes_available() { return 0; }
83 uint8_t testBoard::serial_read() { return 0; }
85 
86 // sensors
88 uint16_t testBoard::num_sensor_errors() { return 0; }
89 
91 {
92  if (new_imu_)
93  {
94  new_imu_ = false;
95  return true;
96  }
97  return false;
98 }
99 
100 
101 bool testBoard::imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time)
102 {
103  for (int i = 0; i < 3; i++)
104  {
105  accel[i] = acc_[i];
106  gyro[i] = gyro_[i];
107  }
108  *temperature = 25.0;
109  *time = time_us_;
110  return true;
111 }
112 
114 
115 bool testBoard::mag_present() { return false; }
117 void testBoard::mag_read(float mag[3]) {}
118 
119 bool testBoard::baro_present() { return false; }
122 
123 bool testBoard::diff_pressure_present() { return false; }
125 void testBoard::diff_pressure_read(float *diff_pressure, float *temperature) {}
126 
127 bool testBoard::sonar_present() { return false; }
129 float testBoard::sonar_read() { return 0; }
130 
131 //GNSS is not supported on the test board
133 
134 //GNSS is not supported on the test board
136 
137 //GNSS is not supported on the test board
138 bool testBoard::gnss_has_new_data() { return false; }
139 
140 
141 // PWM
142 // TODO make these deal in normalized (-1 to 1 or 0 to 1) values (not pwm-specific)
144 bool testBoard::rc_lost() { return rc_lost_; }
145 float testBoard::rc_read(uint8_t channel)
146 {
147  return static_cast<float>(rc_values[channel] - 1000)/1000.0 ;
148 }
149 void testBoard::pwm_write(uint8_t channel, float value) {}
150 void testBoard::pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) {}
152 
153 // non-volatile memory
155 bool testBoard::memory_read(void *dest, size_t len) { return false; }
156 bool testBoard::memory_write(const void *src, size_t len) { return false; }
157 
158 // LEDs
162 
166 
167 //Backup memory
168 bool testBoard::has_backup_data() { return false; }
170 {
171 #pragma GCC diagnostic push //Ignore blank fields in struct
172 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
173  BackupData blank_data = {0};
174 #pragma GCC diagnostic pop
175  return blank_data;
176 }
177 
178 } // namespace rosflight_firmware
179 
180 #pragma GCC diagnostic pop
uint32_t clock_millis() override
Definition: test_board.cpp:75
void pwm_write(uint8_t channel, float value) override
Definition: test_board.cpp:149
static volatile int16_t gyro[3]
Definition: drv_mpu6050.c:277
void board_reset(bool bootloader) override
Definition: test_board.cpp:72
void serial_init(uint32_t baud_rate, uint32_t dev) override
Definition: test_board.cpp:80
float pressure
Definition: ms4525.c:41
void mag_read(float mag[3]) override
Definition: test_board.cpp:117
float temperature
Definition: ms4525.c:41
bool new_imu_data() override
Definition: test_board.cpp:90
void set_imu(float *acc, float *gyro, uint64_t time_us)
Definition: test_board.cpp:58
bool diff_pressure_present() override
Definition: test_board.cpp:123
uint16_t serial_bytes_available() override
Definition: test_board.cpp:82
void sensors_init() override
Definition: test_board.cpp:87
uint64_t clock_micros() override
Definition: test_board.cpp:76
void rc_init(rc_type_t rc_type) override
Definition: test_board.cpp:143
void set_rc(uint16_t *values)
Definition: test_board.cpp:40
bool has_backup_data() override
Definition: test_board.cpp:168
float rc_read(uint8_t channel) override
Definition: test_board.cpp:145
static volatile int16_t accel[3]
Definition: drv_mpu6050.c:276
GNSSRaw gnss_raw_read() override
Definition: test_board.cpp:135
uint8_t serial_read() override
Definition: test_board.cpp:83
void baro_read(float *pressure, float *temperature) override
Definition: test_board.cpp:121
void serial_flush() override
Definition: test_board.cpp:84
bool gnss_has_new_data() override
Definition: test_board.cpp:138
void diff_pressure_read(float *diff_pressure, float *temperature) override
Definition: test_board.cpp:125
void set_time(uint64_t time_us)
Definition: test_board.cpp:48
BackupData get_backup_data() override
Definition: test_board.cpp:169
bool memory_read(void *dest, size_t len) override
Definition: test_board.cpp:155
void diff_pressure_update() override
Definition: test_board.cpp:124
bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time) override
Definition: test_board.cpp:101
void clock_delay(uint32_t milliseconds) override
Definition: test_board.cpp:77
void imu_not_responding_error() override
Definition: test_board.cpp:113
GNSSData gnss_read() override
Definition: test_board.cpp:132
void set_pwm_lost(bool lost)
Definition: test_board.cpp:53
void serial_write(const uint8_t *src, size_t len) override
Definition: test_board.cpp:81
bool memory_write(const void *src, size_t len) override
Definition: test_board.cpp:156
void pwm_init(uint32_t refresh_rate, uint16_t idle_pwm) override
Definition: test_board.cpp:150


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19