MIP_SDK  v3.0.0
MicroStrain Communications Library for embedded systems
serial_connection.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../connection.hpp"
4 
6 
7 #include <string>
8 
9 namespace microstrain
10 {
11 namespace connections
12 {
13 
17 
22 {
23 public:
24 
25  static constexpr auto TYPE = "Serial";
26 
27  SerialConnection(std::string portName, uint32_t baudrate);
29 
30  bool recvFromDevice(uint8_t* buffer, size_t max_length, unsigned int wait_time_ms, size_t* length_out, EmbeddedTimestamp* timestamp_out) final;
31  bool sendToDevice(const uint8_t* data, size_t length) final;
32 
33  bool isConnected() const override;
34  bool connect() override;
35  bool disconnect() override;
36 
37  void connectionInfo(std::string &name, uint32_t &baudrate) const
38  {
39  name = mPortName;
40  baudrate = mBaudrate;
41  };
42 
43 private:
44  serial_port mPort;
45  std::string mPortName;
46  uint32_t mBaudrate;
47 
48 public:
49  const char* interfaceName() const override { return mPortName.c_str(); }
50  uint32_t parameter() const override { return mBaudrate; }
51 };
52 
53 
57 {
58 public:
59  static constexpr auto TYPE = "USB";
60 
61  UsbSerialConnection(const std::string& portName, uint32_t baudrate) : SerialConnection(portName, baudrate) { mType = TYPE; }
62 };
63 
66 
67 } // namespace connections
68 } // namespace microstrain
microstrain::Connection::mType
const char * mType
Definition: connection.hpp:59
microstrain::connections::SerialConnection::SerialConnection
SerialConnection(std::string portName, uint32_t baudrate)
Creates a Serial Connection that will communicate with a device over serial.
Definition: serial_connection.cpp:16
microstrain::connections::SerialConnection::TYPE
static constexpr auto TYPE
Definition: serial_connection.hpp:25
microstrain::connections::SerialConnection::interfaceName
const char * interfaceName() const override
Definition: serial_connection.hpp:49
serial_port.h
microstrain::connections::SerialConnection::connect
bool connect() override
Connect to the port.
Definition: serial_connection.cpp:38
serial_port
Definition: serial_port.h:42
microstrain::connections::UsbSerialConnection
A serial connection but indicates that it's actually a USB connection.
Definition: serial_connection.hpp:56
microstrain::connections::SerialConnection::recvFromDevice
bool recvFromDevice(uint8_t *buffer, size_t max_length, unsigned int wait_time_ms, size_t *length_out, EmbeddedTimestamp *timestamp_out) final
Receives bytes from the device.
Definition: serial_connection.cpp:58
microstrain::connections::SerialConnection
Can be used on Windows, OSX, or linux to communicate with a MIP device over serial.
Definition: serial_connection.hpp:21
microstrain::connections::UsbSerialConnection::TYPE
static constexpr auto TYPE
Definition: serial_connection.hpp:59
microstrain::EmbeddedTimestamp
C::microstrain_embedded_timestamp EmbeddedTimestamp
Definition: embedded_time.hpp:9
microstrain::connections::SerialConnection::sendToDevice
bool sendToDevice(const uint8_t *data, size_t length) final
Sends bytes to the device.
Definition: serial_connection.cpp:66
microstrain::Connection
Represents a type of connection.
Definition: connection.hpp:25
microstrain::connections::SerialConnection::connectionInfo
void connectionInfo(std::string &name, uint32_t &baudrate) const
Definition: serial_connection.hpp:37
microstrain::connections::SerialConnection::isConnected
bool isConnected() const override
Check if the port is connected.
Definition: serial_connection.cpp:32
microstrain::connections::UsbSerialConnection::UsbSerialConnection
UsbSerialConnection(const std::string &portName, uint32_t baudrate)
Definition: serial_connection.hpp:61
microstrain::connections::SerialConnection::~SerialConnection
~SerialConnection()
Closes the underlying serial port.
Definition: serial_connection.cpp:26
microstrain::connections::SerialConnection::disconnect
bool disconnect() override
Disconnect from the port.
Definition: serial_connection.cpp:47
microstrain::connections::SerialConnection::parameter
uint32_t parameter() const override
Definition: serial_connection.hpp:50
microstrain
Definition: embedded_time.h:8