comm_manager.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_MANAGER_H
33 #define ROSFLIGHT_FIRMWARE_COMM_MANAGER_H
34 
35 #include <cstdint>
36 #include <functional>
37 
38 #include "comm_link.h"
39 #include "nanoprintf.h"
40 
41 namespace rosflight_firmware
42 {
43 
44 class ROSflight;
45 
47 {
48 private:
49  enum StreamId
50  {
53 
55 
61 
68  };
69 
71  {
76  };
77 
78  uint8_t sysid_;
84 
85  class Stream
86  {
87  public:
88  Stream(uint32_t period_us, std::function<void(void)> send_function);
89 
90  void stream(uint64_t now_us);
91  void set_rate(uint32_t rate_hz);
92 
93  uint32_t period_us_;
94  uint64_t next_time_us_;
95  std::function<void(void)> send_function_;
96  };
97 
98  void update_system_id(uint16_t param_id);
99 
100  void param_request_list_callback(uint8_t target_system);
101  void param_request_read_callback(uint8_t target_system, const char *const param_name, int16_t param_index);
102  void param_set_int_callback(uint8_t target_system, const char *const param_name, int32_t param_value);
103  void param_set_float_callback(uint8_t target_system, const char *const param_name, float param_value);
104  void command_callback(CommLink::Command command);
105  void timesync_callback(int64_t tc1, int64_t ts1);
108  void heartbeat_callback(void);
109 
110  void send_heartbeat(void);
111  void send_status(void);
112  void send_attitude(void);
113  void send_imu(void);
114  void send_output_raw(void);
115  void send_rc_raw(void);
116  void send_diff_pressure(void);
117  void send_baro(void);
118  void send_sonar(void);
119  void send_mag(void);
120  //The time of week stamp for the last sent GNSS message, to prevent re-sending
121  uint32_t last_sent_gnss_tow=0;
123  void send_gnss(void);
124  void send_gnss_raw(void);
125  void send_low_priority(void);
126  void send_error_data(void);
127 
128  // Debugging Utils
129  void send_named_value_int(const char *const name, int32_t value);
130  // void send_named_command_struct(const char *const name, control_t command_struct);
131 
132  void send_next_param(void);
133 
135  {
136  Stream(0, [this]{this->send_heartbeat();}),
137  Stream(0, [this]{this->send_status();}),
138  Stream(0, [this]{this->send_attitude();}),
139  Stream(0, [this]{this->send_imu();}),
140  Stream(0, [this]{this->send_diff_pressure();}),
141  Stream(0, [this]{this->send_baro();}),
142  Stream(0, [this]{this->send_sonar();}),
143  Stream(0, [this]{this->send_mag();}),
144  Stream(0, [this]{this->send_output_raw();}),
145  Stream(0, [this]{this->send_gnss();}),
146  Stream(0, [this]{this->send_gnss_raw();}),
147  Stream(0, [this]{this->send_rc_raw();}),
148  Stream(20000, [this]{this->send_low_priority();})
149  };
150 
151 public:
152 
153  CommManager(ROSflight &rf, CommLink &comm_link);
154 
155  void init();
156  void receive(void);
157  void stream();
158  void send_param_value(uint16_t param_id);
159  void set_streaming_rate(uint8_t stream_id, int16_t param_id);
160  void update_status();
161  void log(CommLink::LogSeverity severity, const char *fmt, ...);
162 
163  void send_parameter_list();
164  void send_named_value_float(const char *const name, float value);
165 };
166 
167 //CommManager *instance = nullptr;
168 } // namespace rosflight_firmware
169 
170 #endif // ROSFLIGHT_FIRMWARE_COMM_MANAGER_H
void command_callback(CommLink::Command command)
void set_streaming_rate(uint8_t stream_id, int16_t param_id)
void param_request_list_callback(uint8_t target_system)
void update_system_id(uint16_t param_id)
void param_set_int_callback(uint8_t target_system, const char *const param_name, int32_t param_value)
void send_named_value_int(const char *const name, int32_t value)
void send_param_value(uint16_t param_id)
Stream(uint32_t period_us, std::function< void(void)> send_function)
void param_set_float_callback(uint8_t target_system, const char *const param_name, float param_value)
CommManager(ROSflight &rf, CommLink &comm_link)
Stream streams_[STREAM_COUNT]
Definition: comm_manager.h:134
void log(CommLink::LogSeverity severity, const char *fmt,...)
void timesync_callback(int64_t tc1, int64_t ts1)
void param_request_read_callback(uint8_t target_system, const char *const param_name, int16_t param_index)
std::function< void(void)> send_function_
Definition: comm_manager.h:95
void send_named_value_float(const char *const name, float value)
void offboard_control_callback(const CommLink::OffboardControl &control)
void attitude_correction_callback(const turbomath::Quaternion &q)


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