MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
connection.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <stdint.h>
7 #include <stddef.h>
8 
9 #ifdef MICROSTRAIN_HAS_SPAN
10 #include <span>
11 #endif
12 
13 
14 namespace microstrain
15 {
16 
26 {
27 public:
28 
29  static constexpr auto TYPE = "None";
30 
31  Connection() { mType = TYPE; };
32  virtual ~Connection() {}
33 
34  virtual bool sendToDevice(const uint8_t* data, size_t length) = 0;
35  virtual bool recvFromDevice(uint8_t* buffer, size_t max_length, unsigned int wait_time_ms, size_t* length_out, EmbeddedTimestamp* timestamp_out) = 0;
36 
37 #ifdef MICROSTRAIN_HAS_SPAN
38  bool sendToDevice(std::span<const uint8_t> data) { return sendToDevice(data.data(), data.size()); }
39  bool recvFromDevice(std::span<uint8_t>& buffer, unsigned int wait_time_ms, EmbeddedTimestamp* timestamp_out) {
40  size_t length = 0;
41  if(!recvFromDevice(buffer.data(), buffer.size(), wait_time_ms, &length, timestamp_out))
42  return false;
43  buffer = buffer.first(length);
44  return true;
45  }
46 #endif
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 
59  const char *mType;
60 
61 };
62 
63 
64 } // namespace microstrain
microstrain::Connection::mType
const char * mType
Definition: connection.hpp:59
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:31
microstrain::Connection::TYPE
static constexpr auto TYPE
Definition: connection.hpp:29
microstrain::Connection::~Connection
virtual ~Connection()
Definition: connection.hpp:32
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:25
embedded_time.hpp
microstrain
Definition: embedded_time.h:8
microstrain::Connection::connect
virtual bool connect()=0