AP_RCProtocol_Backend.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. * Code by Andrew Tridgell and Siddharth Bharat Purohit
  16. */
  17. #pragma once
  18. #include "AP_RCProtocol.h"
  19. class AP_RCProtocol_Backend {
  20. friend class AP_RCProtcol;
  21. public:
  22. AP_RCProtocol_Backend(AP_RCProtocol &_frontend);
  23. virtual ~AP_RCProtocol_Backend() {}
  24. virtual void process_pulse(uint32_t width_s0, uint32_t width_s1) {}
  25. virtual void process_byte(uint8_t byte, uint32_t baudrate) {}
  26. uint16_t read(uint8_t chan);
  27. bool new_input();
  28. uint8_t num_channels();
  29. // support for receivers that have FC initiated bind support
  30. virtual void start_bind(void) {}
  31. // allow for backends that need regular polling
  32. virtual void update(void) {}
  33. enum {
  34. PARSE_TYPE_SIGREAD,
  35. PARSE_TYPE_SERIAL
  36. };
  37. // get number of frames, ignoring failsafe
  38. uint32_t get_rc_frame_count(void) const {
  39. return rc_frame_count;
  40. }
  41. // get number of frames, honoring failsafe
  42. uint32_t get_rc_input_count(void) const {
  43. return rc_input_count;
  44. }
  45. protected:
  46. void add_input(uint8_t num_channels, uint16_t *values, bool in_failsafe);
  47. private:
  48. AP_RCProtocol &frontend;
  49. uint32_t rc_input_count;
  50. uint32_t last_rc_input_count;
  51. uint32_t rc_frame_count;
  52. uint16_t _pwm_values[MAX_RCIN_CHANNELS];
  53. uint8_t _num_channels;
  54. };