AP_RCProtocol_SBUS.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "SoftSerial.h"
  20. class AP_RCProtocol_SBUS : public AP_RCProtocol_Backend {
  21. public:
  22. AP_RCProtocol_SBUS(AP_RCProtocol &_frontend, bool inverted);
  23. void process_pulse(uint32_t width_s0, uint32_t width_s1) override;
  24. void process_byte(uint8_t byte, uint32_t baudrate) override;
  25. private:
  26. void _process_byte(uint32_t timestamp_us, uint8_t byte);
  27. bool sbus_decode(const uint8_t frame[25], uint16_t *values, uint16_t *num_values,
  28. bool *sbus_failsafe, bool *sbus_frame_drop, uint16_t max_values);
  29. bool inverted;
  30. SoftSerial ss{100000, SoftSerial::SERIAL_CONFIG_8E2I};
  31. uint32_t saved_width;
  32. struct {
  33. uint8_t buf[25];
  34. uint8_t ofs;
  35. uint32_t last_byte_us;
  36. } byte_input;
  37. };