PX4 Firmware
PX4 Autopilot Software http://px4.io
send_event.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2017 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 #pragma once
35 
36 #include "subscriber_handler.h"
37 #include "status_display.h"
38 #include "rc_loss_alarm.h"
39 
40 #include <px4_platform_common/workqueue.h>
41 #include <px4_platform_common/module.h>
42 #include <px4_platform_common/module_params.h>
46 
47 namespace events
48 {
49 
50 extern "C" __EXPORT int send_event_main(int argc, char *argv[]);
51 
52 /** @class SendEvent The SendEvent class manages the RC loss audible alarm, LED status display, and thermal calibration. */
53 class SendEvent : public ModuleBase<SendEvent>, public ModuleParams
54 {
55 public:
56 
57  SendEvent();
58 
59  ~SendEvent();
60 
61  /**
62  * @see ModuleBase
63  * @brief Recognizes custom startup commands, called from the main() function entry.
64  * @param argc The task argument count.
65  * @param argc Pointer to the task argument variable array.
66  * @return Returns 0 iff successful, otherwise < 0 on error.
67  */
68  static int custom_command(int argc, char *argv[]);
69 
70  /**
71  * @see ModuleBase
72  * @brief Prints usage options to the console.
73  * @param reason The requested usage reason for printing to console.
74  * @return Returns 0 iff successful, -1 otherwise.
75  */
76  static int print_usage(const char *reason = nullptr);
77 
78  /**
79  * @brief Spawns and initializes the class in the same context as the
80  * work queue and starts the background listener.
81  * @param argc The input argument count.
82  * @param argv Pointer to the input argument array.
83  * @return Returns 0 iff successful, -1 otherwise.
84  */
85  static int task_spawn(int argc, char *argv[]);
86 
87 private:
88 
89  /**
90  * @brief Returns an ACK to a vehicle_command.
91  * @param cmd The vehicle command struct being referenced.
92  * @param result The command acknowledgement result.
93  */
94  void answer_command(const vehicle_command_s &cmd, unsigned result);
95 
96  /**
97  * @brief Process cycle trampoline for the work queue.
98  * @param arg Pointer to the task startup arguments.
99  */
100  static void cycle_trampoline(void *arg);
101 
102  /**
103  * @brief Calls process_commands() and schedules the next cycle.
104  */
105  void cycle();
106 
107  /**
108  * @brief Trampoline for initialisation.
109  * @param arg Pointer to the task startup arguments.
110  */
111  static void initialize_trampoline(void *arg);
112 
113  /**
114  * @brief Checks for new commands and processes them.
115  */
116  void process_commands();
117 
118  /**
119  * @brief Starts background task listening for commands.
120  * @return Returns 0 iff successful, otherwise < 0 on error.
121  */
122  int start();
123 
124  /** @struct _work The work queue struct. */
125  static struct work_s _work;
126 
127  /** @var _subscriber_handler The uORB subscriber handler. */
129 
130  /** @var _status_display Pointer to the status display object. */
132 
133  /** @var _rc_loss_alarm Pointer to the RC loss alarm object. */
135 
136  /** @note Declare local parameters using defined parameters. */
137  DEFINE_PARAMETERS(
138  /** @var _param_status_display Parameter to enable/disable the LED status display. */
139  (ParamBool<px4::params::EV_TSK_STAT_DIS>) _param_ev_tsk_stat_dis,
140 
141  /** @var _param_rc_loss The RC comms loss status flag. */
142  (ParamBool<px4::params::EV_TSK_RC_LOSS>) _param_ev_tsk_rc_loss
143  )
144 };
145 
146 } // namespace events
Contains a list of uORB subscriptions and maintains their update state.
void answer_command(const vehicle_command_s &cmd, unsigned result)
Returns an ACK to a vehicle_command.
Definition: send_event.cpp:190
static int task_spawn(int argc, char *argv[])
Spawns and initializes the class in the same context as the work queue and starts the background list...
Definition: send_event.cpp:52
int send_event_main(int argc, char *argv[])
Definition: send_event.cpp:292
rc_loss::RC_Loss_Alarm * _rc_loss_alarm
Definition: send_event.h:134
Definition: I2C.hpp:51
Status Display decouples LED and tunes from commander.
void process_commands()
Checks for new commands and processes them.
Definition: send_event.cpp:147
int start()
Starts background task listening for commands.
Definition: send_event.cpp:88
void cycle()
Calls process_commands() and schedules the next cycle.
Definition: send_event.cpp:123
static int print_usage(const char *reason=nullptr)
Prints usage options to the console.
Definition: send_event.cpp:266
status::StatusDisplay * _status_display
Definition: send_event.h:131
static int custom_command(int argc, char *argv[])
Recognizes custom startup commands, called from the main() function entry.
Definition: send_event.cpp:204
queue struct.
SubscriberHandler _subscriber_handler
Definition: send_event.h:128
static void cycle_trampoline(void *arg)
Process cycle trampoline for the work queue.
Definition: send_event.cpp:116
Tone alarm in the event of RC loss.
static void initialize_trampoline(void *arg)
Trampoline for initialisation.
Definition: send_event.cpp:103