comm_link.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_COMM_LINK_H
33 #define ROSFLIGHT_FIRMWARE_COMM_LINK_H
34 
35 #include <cstdint>
36 #include <functional>
37 
38 #include <turbomath/turbomath.h>
39 
40 #include "param.h"
41 #include "board.h"
42 
43 namespace rosflight_firmware
44 {
45 
46 class CommLink
47 {
48 public:
49 
50  enum class LogSeverity
51  {
52  LOG_INFO,
54  LOG_ERROR,
56  };
57 
58  enum class Command
59  {
60  COMMAND_READ_PARAMS,
61  COMMAND_WRITE_PARAMS,
62  COMMAND_SET_PARAM_DEFAULTS,
63  COMMAND_ACCEL_CALIBRATION,
64  COMMAND_GYRO_CALIBRATION,
65  COMMAND_BARO_CALIBRATION,
66  COMMAND_AIRSPEED_CALIBRATION,
67  COMMAND_RC_CALIBRATION,
68  COMMAND_REBOOT,
69  COMMAND_REBOOT_TO_BOOTLOADER,
70  COMMAND_SEND_VERSION
71  };
72 
74  {
75  enum class Mode
76  {
77  PASS_THROUGH,
78  ROLLRATE_PITCHRATE_YAWRATE_THROTTLE,
79  ROLL_PITCH_YAWRATE_THROTTLE
80  };
81 
82  struct Channel
83  {
84  float value;
85  bool valid;
86  };
87 
93  };
94 
95  virtual void init(uint32_t baud_rate, uint32_t dev) = 0;
96  virtual void receive() = 0;
97 
98  // send functions
99 
100  virtual void send_attitude_quaternion(uint8_t system_id,
101  uint64_t timestamp_us,
102  const turbomath::Quaternion &attitude,
103  const turbomath::Vector &angular_velocity) = 0;
104  virtual void send_baro(uint8_t system_id, float altitude, float pressure, float temperature) = 0;
105  virtual void send_command_ack(uint8_t system_id, Command command, bool success) = 0;
106  virtual void send_diff_pressure(uint8_t system_id, float velocity, float pressure, float temperature) = 0;
107  virtual void send_heartbeat(uint8_t system_id, bool fixed_wing) = 0;
108  virtual void send_imu(uint8_t system_id,
109  uint64_t timestamp_us,
110  const turbomath::Vector &accel,
111  const turbomath::Vector &gyro,
112  float temperature) = 0;
113  virtual void send_log_message(uint8_t system_id, LogSeverity severity, const char *text) = 0;
114  virtual void send_mag(uint8_t system_id, const turbomath::Vector &mag) = 0;
115  virtual void send_named_value_int(uint8_t system_id, uint32_t timestamp_ms, const char *const name, int32_t value) = 0;
116  virtual void send_named_value_float(uint8_t system_id, uint32_t timestamp_ms, const char *const name, float value) = 0;
117  virtual void send_output_raw(uint8_t system_id, uint32_t timestamp_ms, const float raw_outputs[8]) = 0;
118  virtual void send_param_value_int(uint8_t system_id,
119  uint16_t index,
120  const char *const name,
121  int32_t value,
122  uint16_t param_count) = 0;
123  virtual void send_param_value_float(uint8_t system_id,
124  uint16_t index,
125  const char *const name,
126  float value,
127  uint16_t param_count) = 0;
128  virtual void send_rc_raw(uint8_t system_id, uint32_t timestamp_ms, const uint16_t channels[8]) = 0;
129  virtual void send_sonar(uint8_t system_id, /* TODO enum type*/uint8_t type, float range, float max_range,
130  float min_range) = 0;
131  virtual void send_status(uint8_t system_id,
132  bool armed,
133  bool failsafe,
134  bool rc_override,
135  bool offboard,
136  uint8_t error_code,
137  uint8_t control_mode,
138  int16_t num_errors,
139  int16_t loop_time_us) = 0;
140  virtual void send_timesync(uint8_t system_id, int64_t tc1, int64_t ts1) = 0;
141  virtual void send_version(uint8_t system_id, const char *const version) = 0;
142  virtual void send_gnss(uint8_t system_id, uint32_t time_of_week, uint8_t fix_type, uint64_t time, uint64_t nanos,
143  int32_t lat,
144  int32_t lon, int32_t height, int32_t vel_n, int32_t vel_e, int32_t vel_d, uint32_t h_acc, uint32_t v_acc,
145  int32_t ecef_x, int32_t ecef_y, int32_t ecef_z, uint32_t p_acc, int32_t ecef_v_x, int32_t ecef_v_y,
146  int32_t ecef_v_z, uint32_t s_acc, uint64_t rosflight_timestamp) = 0;
147  virtual void send_gnss_raw(uint8_t system_id, uint32_t time_of_week, uint16_t year, uint8_t month, uint8_t day,
148  uint8_t hour, uint8_t min, uint8_t sec, uint8_t valid, uint32_t t_acc,
149  int32_t nano, uint8_t fix_type, uint8_t num_sat,
150  int32_t lon, int32_t lat, int32_t height, int32_t height_msl,
151  uint32_t h_acc, uint32_t v_acc, int32_t vel_n, int32_t vel_e,
152  int32_t vel_d, int32_t g_speed, int32_t head_mot, uint32_t s_acc,
153  uint32_t head_acc, uint16_t p_dop, uint64_t rosflight_timestamp) = 0;
154  virtual void send_error_data(uint8_t system_id, const BackupData &error_data) = 0;
155 
156  // register callbacks
157 
158  void register_param_request_list_callback(std::function<void(uint8_t /* target_system */)> callback)
159  {
160  param_request_list_callback_ = callback;
161  }
162 
163  void register_param_request_read_callback(std::function<void(uint8_t /* target_system */,
164  const char *const /* param_name */,
165  uint16_t /* param_index */)> callback)
166  {
167  param_request_read_callback_ = callback;
168  }
169 
170  void register_param_set_int_callback(std::function<void(uint8_t /* target_system */,
171  const char *const /* param_name */,
172  int32_t /* param_value */)> callback)
173  {
174  param_set_int_callback_ = callback;
175  }
176 
177  void register_param_set_float_callback(std::function<void(uint8_t /* target_system */,
178  const char *const /* param_name */,
179  float /* param_value */)> callback)
180  {
181  param_set_float_callback_ = callback;
182  }
183 
184  void register_offboard_control_callback(std::function<void(const OffboardControl &)> callback)
185  {
186  offboard_control_callback_ = callback;
187  }
188 
189  void register_attitude_correction_callback(std::function<void(const turbomath::Quaternion)> callback)
190  {
192  }
193 
194  void register_command_callback(std::function<void(Command)> callback)
195  {
196  command_callback_ = callback;
197  }
198 
199  void register_timesync_callback(std::function<void(int64_t /* tc1 */, int64_t /* ts1 */)> callback)
200  {
201  timesync_callback_ = callback;
202  }
203  void register_heartbeat_callback(std::function<void()> callback)
204  {
205  heartbeat_callback_ = callback;
206  }
207 
208 protected:
209  std::function<void(uint8_t)> param_request_list_callback_;
210  std::function<void(uint8_t, const char *const, uint16_t)> param_request_read_callback_;
211  std::function<void(uint8_t, const char *const, int32_t)> param_set_int_callback_;
212  std::function<void(uint8_t, const char *const, float)> param_set_float_callback_;
213 
214  std::function<void(const OffboardControl)> offboard_control_callback_;
215  std::function<void(const turbomath::Quaternion)> attitude_correction_callback_;
216  std::function<void(Command)> command_callback_;
217  std::function<void(int64_t, int64_t)> timesync_callback_;
218  std::function<void(void)> heartbeat_callback_;
219 };
220 
221 } // namespace rosflight_firmware
222 
223 #endif // ROSFLIGHT_FIRMWARE_COMM_LINK_H
static volatile int16_t gyro[3]
Definition: drv_mpu6050.c:277
float altitude
Definition: ms4525.c:41
float pressure
Definition: ms4525.c:41
float temperature
Definition: ms4525.c:41
static volatile int16_t accel[3]
Definition: drv_mpu6050.c:276
static const channelConfig_t channels[CC_CHANNELS_PER_TIMER]
Definition: drv_timer.c:111


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:24