NbusLoopEsp32.h 701 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef _NBUS_APP_DRIVER_H_
  2. #define _NBUS_APP_DRIVER_H_
  3. #include <cinttypes>
  4. #include <Stream.h>
  5. #include <esp32-hal.h>
  6. #define NBUS_APP_DRIVER_PAYLOAD_MIN 4
  7. #define NBUS_APP_DRIVER_PAYLOAD_MAX 127
  8. class NbusLoopEsp32
  9. {
  10. public:
  11. NbusLoopEsp32(Stream &stream_obj, int32_t timeout);
  12. void setData(uint8_t *data, int16_t size);
  13. Stream& accessStream();
  14. int16_t receiveData();
  15. bool isReceiving();
  16. private:
  17. bool _checkTimeout();
  18. void _resetRxState();
  19. Stream &_stream_obj;
  20. uint8_t *_data{nullptr};
  21. int16_t _size{0};
  22. int32_t _timeout{0};
  23. int64_t _time0{INT64_MAX};
  24. int16_t _rx_index{0};
  25. int16_t _rx_size{0};
  26. };
  27. #endif // _NBUS_APP_DRIVER_H_