MIP_SDK  latest-2-g34f3e39
MicroStrain Communications Library for embedded systems
connection.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <stddef.h>
7 #include <stdint.h>
8 
9 #if defined MICROSTRAIN_HAS_SPAN
10 #include <span>
11 #endif // MICROSTRAIN_HAS_SPAN
12 
13 namespace microstrain
14 {
24  class Connection
25  {
26  public:
27  static constexpr const char* TYPE = "None";
28 
30  virtual ~Connection() {}
31 
32  virtual bool sendToDevice(const uint8_t* data, size_t length) = 0;
33  virtual bool recvFromDevice(uint8_t* buffer, size_t max_length, unsigned int wait_time_ms, size_t* length_out, EmbeddedTimestamp* timestamp_out) = 0;
34 
35 #if defined MICROSTRAIN_HAS_SPAN
36  bool sendToDevice(std::span<const uint8_t> data) { return sendToDevice(data.data(), data.size()); }
37  bool recvFromDevice(std::span<uint8_t>& buffer, unsigned int wait_time_ms, EmbeddedTimestamp* timestamp_out)
38  {
39  size_t length = 0;
40  if (!recvFromDevice(buffer.data(), buffer.size(), wait_time_ms, &length, timestamp_out))
41  return false;
42 
43  buffer = buffer.first(length);
44  return true;
45  }
46 #endif // MICROSTRAIN_HAS_SPAN
47 
48  virtual bool isConnected() const = 0;
49  virtual bool connect() = 0;
50  virtual bool disconnect() = 0;
51 
52  const char* type() const { return mType; }
53 
54  virtual const char* interfaceName() const = 0;
55  virtual uint32_t parameter() const = 0;
56 
57  protected:
58  const char* mType;
59  };
60 } // namespace microstrain
microstrain::Connection::mType
const char * mType
Definition: connection.hpp:58
microstrain::Connection::TYPE
static constexpr const char * TYPE
Definition: connection.hpp:27
microstrain::Connection::type
const char * type() const
Definition: connection.hpp:52
microstrain::Connection::interfaceName
virtual const char * interfaceName() const =0
microstrain::Connection::sendToDevice
virtual bool sendToDevice(const uint8_t *data, size_t length)=0
Sends bytes to the device.
microstrain::Connection::parameter
virtual uint32_t parameter() const =0
microstrain::Connection::recvFromDevice
virtual bool recvFromDevice(uint8_t *buffer, size_t max_length, unsigned int wait_time_ms, size_t *length_out, EmbeddedTimestamp *timestamp_out)=0
Receives bytes from the device.
microstrain::Connection::Connection
Connection()
Definition: connection.hpp:29
microstrain::Connection::~Connection
virtual ~Connection()
Definition: connection.hpp:30
microstrain::EmbeddedTimestamp
C::microstrain_embedded_timestamp EmbeddedTimestamp
Definition: embedded_time.hpp:9
microstrain::Connection::disconnect
virtual bool disconnect()=0
platform.hpp
microstrain::Connection::isConnected
virtual bool isConnected() const =0
microstrain::Connection
Represents a type of connection.
Definition: connection.hpp:24
embedded_time.hpp
microstrain
Definition: embedded_time.h:8
microstrain::Connection::connect
virtual bool connect()=0