TCPServerDevice.h 728 B

1234567891011121314151617181920212223242526
  1. #pragma once
  2. #include "SerialDevice.h"
  3. #include <AP_HAL/utility/Socket.h>
  4. class TCPServerDevice: public SerialDevice {
  5. public:
  6. TCPServerDevice(const char *ip, uint16_t port, bool wait);
  7. virtual ~TCPServerDevice();
  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 listener{false};
  16. SocketAPM *sock = nullptr;
  17. const char *_ip;
  18. uint16_t _port;
  19. bool _wait;
  20. bool _blocking = false;
  21. uint32_t _last_bind_warning = 0;
  22. };