APM:Libraries
AP_Module.h
Go to the documentation of this file.
1 /*
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License as published by
4  the Free Software Foundation, either version 3 of the License, or
5  (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 /*
17  support for external modules
18 
19  ******************************************************************
20  PLEASE NOTE: module hooks are called synchronously from
21  ArduPilot. They must not block or make any IO calls. If anything
22  could take more than a few 10s of microseconds then you must defer
23  it to another thread. Modules are responsible for their own thread
24  handling
25  ******************************************************************
26 
27  */
28 #pragma once
29 
30 #include <AP_HAL/AP_HAL.h>
31 
32 #if AP_MODULE_SUPPORTED
33 
34 #include <AP_AHRS/AP_AHRS.h>
35 
36 #ifndef AP_MODULE_DEFAULT_DIRECTORY
37 #define AP_MODULE_DEFAULT_DIRECTORY "/usr/lib/ardupilot/modules"
38 #endif
39 
40 class AP_Module {
41 public:
42 
43  // initialise AP_Module, looking for shared libraries in the given module path
44  static void init(const char *module_path);
45 
46  // call any setup_start hooks
47  static void call_hook_setup_start(void);
48 
49  // call any setup_complete hooks
50  static void call_hook_setup_complete(void);
51 
52  // call any AHRS_update hooks
53  static void call_hook_AHRS_update(const AP_AHRS_NavEKF &ahrs);
54 
55  // call any gyro_sample hooks
56  static void call_hook_gyro_sample(uint8_t instance, float dt, const Vector3f &gyro);
57 
58  // call any accel_sample hooks
59  static void call_hook_accel_sample(uint8_t instance, float dt, const Vector3f &accel, bool fsync_set);
60 
61 
62 private:
63 
64  enum ModuleHooks {
65  HOOK_SETUP_START = 0,
66  HOOK_SETUP_COMPLETE,
67  HOOK_AHRS_UPDATE,
68  HOOK_GYRO_SAMPLE,
69  HOOK_ACCEL_SAMPLE,
70  NUM_HOOKS
71  };
72 
73  // singly linked list per hook
74  struct hook_list {
75  struct hook_list *next;
76  void *symbol; // from dlsym()
77  };
78 
79  // currently installed hooks
80  static struct hook_list *hooks[NUM_HOOKS];
81 
82  // table giving the name of the hooks in the external
83  // modules. These are passed to dlsym(). The table order must
84  // match the ModuleHooks enum
85  static const char *hook_names[NUM_HOOKS];
86 
87  // scan a module for hooks
88  static void module_scan(const char *path);
89 };
90 
91 #endif // AP_MODULE_SUPPORTED
AP_AHRS_NavEKF & ahrs
Definition: AHRS_Test.cpp:39
void init()
Generic board initialization function.
Definition: system.cpp:136