UDPDevice.h 670 B

123456789101112131415161718192021222324
  1. #pragma once
  2. #include "SerialDevice.h"
  3. #include <AP_HAL/utility/Socket.h>
  4. class UDPDevice: public SerialDevice {
  5. public:
  6. UDPDevice(const char *ip, uint16_t port, bool bcast, bool input);
  7. virtual ~UDPDevice();
  8. virtual bool open() override;
  9. virtual bool close() override;
  10. virtual void set_blocking(bool blocking) override;
  11. virtual void set_speed(uint32_t speed) override;
  12. virtual ssize_t write(const uint8_t *buf, uint16_t n) override;
  13. virtual ssize_t read(uint8_t *buf, uint16_t n) override;
  14. private:
  15. SocketAPM socket{true};
  16. const char *_ip;
  17. uint16_t _port;
  18. bool _bcast;
  19. bool _input;
  20. bool _connected = false;
  21. };