AP_Module.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. /*
  14. support for external modules
  15. ******************************************************************
  16. PLEASE NOTE: module hooks are called synchronously from
  17. ArduPilot. They must not block or make any IO calls. If anything
  18. could take more than a few 10s of microseconds then you must defer
  19. it to another thread. Modules are responsible for their own thread
  20. handling
  21. ******************************************************************
  22. */
  23. #pragma once
  24. #include <AP_HAL/AP_HAL.h>
  25. #if AP_MODULE_SUPPORTED
  26. #include <AP_AHRS/AP_AHRS.h>
  27. #ifndef AP_MODULE_DEFAULT_DIRECTORY
  28. #define AP_MODULE_DEFAULT_DIRECTORY "/usr/lib/ardupilot/modules"
  29. #endif
  30. class AP_Module {
  31. public:
  32. // initialise AP_Module, looking for shared libraries in the given module path
  33. static void init(const char *module_path);
  34. // call any setup_start hooks
  35. static void call_hook_setup_start(void);
  36. // call any setup_complete hooks
  37. static void call_hook_setup_complete(void);
  38. // call any AHRS_update hooks
  39. static void call_hook_AHRS_update(const AP_AHRS_NavEKF &ahrs);
  40. // call any gyro_sample hooks
  41. static void call_hook_gyro_sample(uint8_t instance, float dt, const Vector3f &gyro);
  42. // call any accel_sample hooks
  43. static void call_hook_accel_sample(uint8_t instance, float dt, const Vector3f &accel, bool fsync_set);
  44. private:
  45. enum ModuleHooks {
  46. HOOK_SETUP_START = 0,
  47. HOOK_SETUP_COMPLETE,
  48. HOOK_AHRS_UPDATE,
  49. HOOK_GYRO_SAMPLE,
  50. HOOK_ACCEL_SAMPLE,
  51. NUM_HOOKS
  52. };
  53. // singly linked list per hook
  54. struct hook_list {
  55. struct hook_list *next;
  56. void *symbol; // from dlsym()
  57. };
  58. // currently installed hooks
  59. static struct hook_list *hooks[NUM_HOOKS];
  60. // table giving the name of the hooks in the external
  61. // modules. These are passed to dlsym(). The table order must
  62. // match the ModuleHooks enum
  63. static const char *hook_names[NUM_HOOKS];
  64. // scan a module for hooks
  65. static void module_scan(const char *path);
  66. };
  67. #endif // AP_MODULE_SUPPORTED