From 7ebf4cae1177752cbb4a31dcf31332b7db63009e Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:43:44 -0500 Subject: [PATCH 01/20] Progress check-in --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e6d99555..c3b1e763f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,7 +165,7 @@ set(MIPDEF_SOURCES "${MIP_DIR}/definitions/data_shared.h" "${MIP_DIR}/definitions/data_system.c" "${MIP_DIR}/definitions/data_system.h" - ${INTDEF_SOURCES} + ${MIP_INTDEF_SOURCES} ) string(REGEX REPLACE "\.h(;|$)" ".hpp\\1" MIPDEF_HPP_SOURCES "${MIPDEF_SOURCES}") @@ -206,6 +206,7 @@ if(MIP_USE_EXTRAS) "${MIP_EXTRAS_DIR}/scope_helper.cpp" "${MIP_EXTRAS_DIR}/version.hpp" "${MIP_EXTRAS_DIR}/version.cpp" + ${MIP_INTDEF_EXTRAS} ) endif() From 6fb0cad0561113bbbf68e23c3c9026be11bd8ff9 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:18:10 -0500 Subject: [PATCH 02/20] Use target_include_directories to automatically propagate include paths via target_link_libraries. --- CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3b1e763f..e90396920 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,6 @@ set(SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src") set(EXT_DIR "${CMAKE_CURRENT_LIST_DIR}/ext") set(MIP_CMAKE_DIR "${CMAKE_CURRENT_LIST_DIR}/cmake") -include_directories( - "${SRC_DIR}" -) - if(WITH_INTERNAL) if(NOT DEFINED MIP_INTERNAL_DIR) set(MIP_INTERNAL_DIR "int" CACHE PATH "") @@ -235,6 +231,12 @@ endif() add_library(mip ${ALL_MIP_SOURCES}) +target_include_directories(mip PUBLIC $) + +if(WITH_INTERNAL) + target_include_directories(mip PUBLIC $) +endif() + # # Preprocessor definitions # From 569bb0827498df1e41e053d82057f31c42531a42 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:41:18 -0500 Subject: [PATCH 03/20] Add conversion from CompositeResult::Entry to CmdResult. --- src/mip/extras/composite_result.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mip/extras/composite_result.hpp b/src/mip/extras/composite_result.hpp index 82367e4f5..e67a5c1ac 100644 --- a/src/mip/extras/composite_result.hpp +++ b/src/mip/extras/composite_result.hpp @@ -26,6 +26,7 @@ namespace mip operator bool() const { return result; } bool operator!() const { return !result; } + operator CmdResult() const { return result; } Entry(bool r, DescriptorId d={}) : result(r ? CmdResult::ACK_OK : CmdResult::STATUS_ERROR), descriptor(d) {} Entry(CmdResult r, DescriptorId d={}) : result(r), descriptor(d) {} From 38af2f39e60893b3fa32c51a5edcf13de011e1ad Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:37:04 -0500 Subject: [PATCH 04/20] Add createConnectionFromInterfaceName. --- CMakeLists.txt | 4 ++ src/mip/platform/platform_connection.cpp | 80 ++++++++++++++++++++++++ src/mip/platform/platform_connection.hpp | 19 ++++++ 3 files changed, 103 insertions(+) create mode 100644 src/mip/platform/platform_connection.cpp create mode 100644 src/mip/platform/platform_connection.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e90396920..3e61cc563 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,6 +188,10 @@ if(MIP_USE_TCP) ) endif() if(MIP_USE_EXTRAS) + list(APPEND MIP_INTERFACE_SOURCES + "${MIP_DIR}/platform/platform_connection.hpp" + "${MIP_DIR}/platform/platform_connection.cpp" + ) list(APPEND MIP_DEFINES "MIP_USE_EXTRAS") set(MIP_EXTRAS_DIR "${MIP_DIR}/extras") set(MIP_EXTRA_SOURCES diff --git a/src/mip/platform/platform_connection.cpp b/src/mip/platform/platform_connection.cpp new file mode 100644 index 000000000..74faeb03b --- /dev/null +++ b/src/mip/platform/platform_connection.cpp @@ -0,0 +1,80 @@ +#pragma once + +#include "platform_connection.hpp" + +#if MIP_USE_SERIAL +#include "serial_connection.hpp" +#endif + +#if MIP_USE_TCP +#include "tcp_connection.hpp" +#endif + +#include + + +namespace mip +{ +namespace platform +{ + //////////////////////////////////////////////////////////////////////////////// + ///@brief Creates a connection object given the interface name and a parameter. + /// + ///@note This only creates the connection object; it does not open it. Call + /// `connection->connect()` to open it. + /// + ///@param interfaceName + /// This is the interface name - COM* (windows) or /dev/tty* (Linux) for + /// a serial port or anything else for a TCP socket. + /// + ///@param parameter + /// For serial ports, this is the baud rate. + /// For TCP sockets, this is the port number. + /// + std::unique_ptr createConnectionFromInterfaceName(std::string_view interface_name, uint32_t parameter) + { +#ifdef MIP_USE_SERIAL + // Todo: Detect USB connections (interface_name.find("ttyACM0") or similar) + if(isSerialInterfaceName(interface_name)) + return std::make_unique(interface_name, parameter); +#endif + +#ifdef MIP_USE_TCP + if(isNetworkInterfaceName(interface_name)) + return std::make_unique(interface_name, parameter); +#endif + + return nullptr; + } + + //////////////////////////////////////////////////////////////////////////////// + ///@brief Determines if the name corresponds to a serial port device. + /// + ///@param interface_name + /// + ///@returns True if the interface is likely a serial port. False otherwise. + /// + bool isSerialInterfaceName(std::string_view interface_name) + { +#ifdef WIN32 + return (interface_name.find("COM", 0) != std::string::npos; // todo: make case insensitive +#else + return interface_name.rfind("/dev/", 0) == 0; +#endif + } + + //////////////////////////////////////////////////////////////////////////////// + ///@brief Determines if the name corresponds to a URL or IP address. + /// + ///@param interface_name + /// + ///@returns True if the interface could be a URL or IP address. False otherwise. + /// + bool isNetworkInterfaceName(std::string_view interface) + { + return interface == "localhost" || interface.find('.') != std::string::npos; + } + + +} // namespace platform +} // namespace mip diff --git a/src/mip/platform/platform_connection.hpp b/src/mip/platform/platform_connection.hpp new file mode 100644 index 000000000..752619ab7 --- /dev/null +++ b/src/mip/platform/platform_connection.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "mip/mip_device.hpp" + +#include +#include + + +namespace mip +{ + namespace platform + { + std::unique_ptr createConnectionFromInterfaceName(std::string_view interface_name, uint32_t parameter); + + bool isNetworkInterfaceName(std::string_view interface_name); + bool isSerialInterfaceName(std::string_view interface_name); + + } // namespace platform +} // namespace mip From c544632be6c4792bec06db3fae883836123c4984 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:12:40 -0500 Subject: [PATCH 05/20] Fix typo --- src/mip/platform/platform_connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mip/platform/platform_connection.cpp b/src/mip/platform/platform_connection.cpp index 74faeb03b..8518a594b 100644 --- a/src/mip/platform/platform_connection.cpp +++ b/src/mip/platform/platform_connection.cpp @@ -57,7 +57,7 @@ namespace platform bool isSerialInterfaceName(std::string_view interface_name) { #ifdef WIN32 - return (interface_name.find("COM", 0) != std::string::npos; // todo: make case insensitive + return interface_name.find("COM", 0) != std::string::npos; // todo: make case insensitive #else return interface_name.rfind("/dev/", 0) == 0; #endif From ff4875b2209e7991596dd3f02e91895a1f5abcb5 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:30:01 -0500 Subject: [PATCH 06/20] Fix platform_connection. --- CMakeLists.txt | 2 ++ src/mip/platform/platform_connection.cpp | 6 +++--- src/mip/platform/platform_connection.hpp | 2 +- src/mip/platform/serial_connection.cpp | 4 ++-- src/mip/platform/serial_connection.hpp | 2 +- src/mip/platform/tcp_connection.cpp | 4 ++-- src/mip/platform/tcp_connection.hpp | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e61cc563..62efc8e16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,7 @@ string(REGEX REPLACE "\.h(;|$)" ".hpp\\1" MIPDEF_HPP_SOURCES "${MIPDEF_SOURCES}" string(REGEX REPLACE "\.c(;|$)" ".cpp\\1" MIPDEF_CPP_SOURCES "${MIPDEF_HPP_SOURCES}") if(MIP_USE_SERIAL) + list(APPEND MIP_DEFINES "MIP_USE_SERIAL") list(APPEND UTILS_SOURCES "${UTILS_DIR}/serial_port.c" "${UTILS_DIR}/serial_port.h" @@ -178,6 +179,7 @@ if(MIP_USE_SERIAL) ) endif() if(MIP_USE_TCP) + list(APPEND MIP_DEFINES "MIP_USE_TCP") list(APPEND UTILS_SOURCES "${UTILS_DIR}/tcp_socket.c" "${UTILS_DIR}/tcp_socket.h" diff --git a/src/mip/platform/platform_connection.cpp b/src/mip/platform/platform_connection.cpp index 8518a594b..2f9ade545 100644 --- a/src/mip/platform/platform_connection.cpp +++ b/src/mip/platform/platform_connection.cpp @@ -31,17 +31,17 @@ namespace platform /// For serial ports, this is the baud rate. /// For TCP sockets, this is the port number. /// - std::unique_ptr createConnectionFromInterfaceName(std::string_view interface_name, uint32_t parameter) + std::unique_ptr createConnectionFromInterfaceName(std::string interface_name, uint32_t parameter) { #ifdef MIP_USE_SERIAL // Todo: Detect USB connections (interface_name.find("ttyACM0") or similar) if(isSerialInterfaceName(interface_name)) - return std::make_unique(interface_name, parameter); + return std::make_unique(std::move(interface_name), parameter); #endif #ifdef MIP_USE_TCP if(isNetworkInterfaceName(interface_name)) - return std::make_unique(interface_name, parameter); + return std::make_unique(std::move(interface_name), parameter); #endif return nullptr; diff --git a/src/mip/platform/platform_connection.hpp b/src/mip/platform/platform_connection.hpp index 752619ab7..a1825cf8e 100644 --- a/src/mip/platform/platform_connection.hpp +++ b/src/mip/platform/platform_connection.hpp @@ -10,7 +10,7 @@ namespace mip { namespace platform { - std::unique_ptr createConnectionFromInterfaceName(std::string_view interface_name, uint32_t parameter); + std::unique_ptr createConnectionFromInterfaceName(std::string interface_name, uint32_t parameter); bool isNetworkInterfaceName(std::string_view interface_name); bool isSerialInterfaceName(std::string_view interface_name); diff --git a/src/mip/platform/serial_connection.cpp b/src/mip/platform/serial_connection.cpp index 22603e7a6..7b9380b66 100644 --- a/src/mip/platform/serial_connection.cpp +++ b/src/mip/platform/serial_connection.cpp @@ -13,9 +13,9 @@ namespace platform /// ///@param portName Path to the port to connect to. On Windows, this usually looks like "COM", on linux, "/dev/tty" ///@param baudrate Baud rate to open the device at. Note that the device needs to be configured to -SerialConnection::SerialConnection(const std::string& portName, uint32_t baudrate) +SerialConnection::SerialConnection(std::string portName, uint32_t baudrate) { - mPortName = portName; + mPortName = std::move(portName); mBaudrate = baudrate; mType = TYPE; diff --git a/src/mip/platform/serial_connection.hpp b/src/mip/platform/serial_connection.hpp index 6ecd6d5f1..6c6ce0727 100644 --- a/src/mip/platform/serial_connection.hpp +++ b/src/mip/platform/serial_connection.hpp @@ -23,7 +23,7 @@ class SerialConnection : public mip::Connection static constexpr auto TYPE = "Serial"; - SerialConnection(const std::string& portName, uint32_t baudrate); + SerialConnection(std::string portName, uint32_t baudrate); ~SerialConnection(); bool recvFromDevice(uint8_t* buffer, size_t max_length, Timeout wait_time, size_t* length_out, mip::Timestamp* timestamp) final; diff --git a/src/mip/platform/tcp_connection.cpp b/src/mip/platform/tcp_connection.cpp index 8131a465c..8b44cb335 100644 --- a/src/mip/platform/tcp_connection.cpp +++ b/src/mip/platform/tcp_connection.cpp @@ -14,9 +14,9 @@ namespace platform /// ///@param hostName Host name or IP address to connect to ///@param port Port on hostName to connect to -TcpConnection::TcpConnection(const std::string& hostname, uint16_t port) +TcpConnection::TcpConnection(std::string hostname, uint16_t port) { - mHostname = hostname; + mHostname = std::move(hostname); mPort = port; mType = TYPE; diff --git a/src/mip/platform/tcp_connection.hpp b/src/mip/platform/tcp_connection.hpp index a33bc9558..9e07245ec 100644 --- a/src/mip/platform/tcp_connection.hpp +++ b/src/mip/platform/tcp_connection.hpp @@ -24,7 +24,7 @@ class TcpConnection : public mip::Connection static constexpr auto TYPE = "TCP"; TcpConnection() = default; - TcpConnection(const std::string& hostname, uint16_t port); + TcpConnection(std::string hostname, uint16_t port); ~TcpConnection(); bool recvFromDevice(uint8_t* buffer, size_t max_length, Timeout wait_time, size_t* length_out, mip::Timestamp* timestamp) final; From 8c2549a31ea2ddd924510fbd3522c6d514aa966d Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Tue, 6 Feb 2024 13:17:48 -0500 Subject: [PATCH 07/20] Updates for new TypedResult. --- src/mip/definitions/descriptors.h | 1 + src/mip/mip_device.hpp | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/mip/definitions/descriptors.h b/src/mip/definitions/descriptors.h index 29ce8efb8..9dd18b622 100644 --- a/src/mip/definitions/descriptors.h +++ b/src/mip/definitions/descriptors.h @@ -129,6 +129,7 @@ struct TypedResult : public CmdResult // Same constructor as CmdResult. using CmdResult::CmdResult; + TypedResult(CmdResult existing) : CmdResult(existing) {} ///@brief The command descriptor. /// diff --git a/src/mip/mip_device.hpp b/src/mip/mip_device.hpp index 2034142c3..543e07508 100644 --- a/src/mip/mip_device.hpp +++ b/src/mip/mip_device.hpp @@ -127,10 +127,17 @@ struct PendingCmd : public C::mip_pending_cmd -template CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime=0); -template CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0); -template CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime); -template bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, Timeout additionalTime); +template +TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime=0); + +template +TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0); + +template +TypedResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime); + +template +bool startCommand(C::mip_interface& device, C::mip_pending_cmd& pending, const Cmd& cmd, Timeout additionalTime); //////////////////////////////////////////////////////////////////////////////// @@ -324,13 +331,13 @@ class DeviceInterface : public C::mip_interface // template - CmdResult runCommand(const Cmd& cmd, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, additionalTime); } + TypedResult runCommand(const Cmd& cmd, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, additionalTime); } template - CmdResult runCommand(Args&&... args, Timeout additionalTime=0) { return mip::runCommand(*this, std::forward(args)..., additionalTime); } + TypedResult runCommand(Args&&... args, Timeout additionalTime=0) { return mip::runCommand(*this, std::forward(args)..., additionalTime); } template - CmdResult runCommand(const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, response, additionalTime); } + TypedResult runCommand(const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, response, additionalTime); } template @@ -953,7 +960,7 @@ void DeviceInterface::registerExtractor(C::mip_dispatch_handler& handler, DataFi template -CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime) +TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime) { PacketBuf packet(cmd); @@ -964,14 +971,14 @@ CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additiona } template -CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime) +TypedResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime) { Cmd cmd{std::forward(args)...}; return runCommand(device, cmd, additionalTime); } template -CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime) +TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime) { PacketBuf packet(cmd); From 159bc170c7ef08465b67f9f8df4dc7b877ccefff Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:51:22 -0500 Subject: [PATCH 08/20] Organize and document model numbers. --- src/mip/extras/device_models.c | 17 ++++++++++++++++- src/mip/extras/device_models.h | 23 +++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/mip/extras/device_models.c b/src/mip/extras/device_models.c index 8566c0958..a881fcc57 100644 --- a/src/mip/extras/device_models.c +++ b/src/mip/extras/device_models.c @@ -12,6 +12,14 @@ namespace C { extern "C" { #endif// __cplusplus +//////////////////////////////////////////////////////////////////////////////// +///@brief Parses a string into a model number. +/// +///@param model_or_serial Device model or serial number. +/// +///@returns The model number. Note that it may not be listed in the enum (e.g. +/// if it's a new model released after this version of source code). +/// mip_model_number get_model_from_string(const char* model_or_serial) { unsigned int start_index = 0; @@ -44,6 +52,13 @@ mip_model_number get_model_from_string(const char* model_or_serial) return atoi(model_or_serial + start_index); } +//////////////////////////////////////////////////////////////////////////////// +///@brief Converts a model number to the product's model name. +/// +///@param model +/// +///@returns A string containing the (approximate) model name. +/// const char* get_model_name_from_number(mip_model_number model) { switch (model) @@ -85,7 +100,7 @@ const char* get_model_name_from_number(mip_model_number model) case MODEL_3DM_CV7_INS: return "3DM-CV7-INS"; default: - case MODEL_UNKNOWN: return ""; + case MODEL_UNKNOWN: return "Unknown"; } } diff --git a/src/mip/extras/device_models.h b/src/mip/extras/device_models.h index da22e542e..68ba05be8 100644 --- a/src/mip/extras/device_models.h +++ b/src/mip/extras/device_models.h @@ -10,26 +10,29 @@ extern "C" { enum mip_model_number { MODEL_UNKNOWN = 0, + // Gen 3 MODEL_3DM_DH3 = 6219,// 3DM-DH3 - MODEL_3DM_GX3_15 = 6227,// 3DM-GX3-15 MODEL_3DM_GX3_25 = 6223,// 3DM-GX3-25 MODEL_3DM_GX3_35 = 6225,// 3DM-GX3-35 + MODEL_3DM_GX3_15 = 6227,// 3DM-GX3-15 MODEL_3DM_GX3_45 = 6228,// 3DM-GX3-45 + // Gen 4 MODEL_3DM_RQ1_45_LT = 6232,// 3DM-RQ1-45-LT MODEL_3DM_GX4_15 = 6233,// 3DM-GX4-15 MODEL_3DM_GX4_25 = 6234,// 3DM-GX4-25 MODEL_3DM_GX4_45 = 6236,// 3DM-GX4-45 MODEL_3DM_RQ1_45_ST = 6239,// 3DM-RQ1-45-ST - MODEL_3DM_GX5_10 = 6255,// 3DM-GX5-10 - MODEL_3DM_GX5_15 = 6254,// 3DM-GX5-15 - MODEL_3DM_GX5_25 = 6253,// 3DM-GX5-25 - MODEL_3DM_GX5_35 = 6252,// 3DM-GX5-35 + MODEL_3DM_GQ4_45 = 6250,// 3DM-GQ4-45 + // Gen 5 MODEL_3DM_GX5_45 = 6251,// 3DM-GX5-45 - MODEL_3DM_CV5_10 = 6259,// 3DM-CV5-10 - MODEL_3DM_CV5_15 = 6258,// 3DM-CV5-15 - MODEL_3DM_CV5_25 = 6257,// 3DM-CV5-25 + MODEL_3DM_GX5_35 = 6252,// 3DM-GX5-35 + MODEL_3DM_GX5_25 = 6253,// 3DM-GX5-25 + MODEL_3DM_GX5_15 = 6254,// 3DM-GX5-15 + MODEL_3DM_GX5_10 = 6255,// 3DM-GX5-10 MODEL_3DM_CV5_45 = 6256,// 3DM-CV5-45 - MODEL_3DM_GQ4_45 = 6250,// 3DM-GQ4-45 + MODEL_3DM_CV5_25 = 6257,// 3DM-CV5-25 + MODEL_3DM_CV5_15 = 6258,// 3DM-CV5-15 + MODEL_3DM_CV5_10 = 6259,// 3DM-CV5-10 MODEL_3DM_CX5_45 = 6271,// 3DM-CX5-45 MODEL_3DM_CX5_35 = 6272,// 3DM-CX5-35 MODEL_3DM_CX5_25 = 6273,// 3DM-CX5-25 @@ -37,6 +40,7 @@ enum mip_model_number MODEL_3DM_CX5_10 = 6275,// 3DM-CX5-10 MODEL_3DM_CL5_15 = 6280,// 3DM-CL5-15 MODEL_3DM_CL5_25 = 6281,// 3DM-CL5-25 + // Gen 7 MODEL_3DM_GQ7 = 6284,// 3DM-GQ7 MODEL_3DM_RTK = 6285,// 3DM-RTK MODEL_3DM_CV7_AHRS = 6286,// 3DM-CV7-AHRS @@ -53,7 +57,6 @@ typedef enum mip_model_number mip_model_number; mip_model_number get_model_from_string(const char* model_or_serial); const char* get_model_name_from_number(mip_model_number model); - #ifdef __cplusplus } // extern "C" } // namespace C From 7eb254a38751facbb126a7081c2af0997cfc8e37 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:29:48 -0500 Subject: [PATCH 09/20] Fix PendingCmd constructor status initializing to ACK. --- src/mip/mip_device.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mip/mip_device.hpp b/src/mip/mip_device.hpp index 543e07508..8d97669de 100644 --- a/src/mip/mip_device.hpp +++ b/src/mip/mip_device.hpp @@ -63,7 +63,7 @@ struct PendingCmd : public C::mip_pending_cmd { ///@brief Create a null pending command in the CmdResult::NONE state. /// - PendingCmd() { std::memset(static_cast(this), 0, sizeof(C::mip_pending_cmd)); } + PendingCmd() { std::memset(static_cast(this), 0, sizeof(C::mip_pending_cmd)); this->_status = mip::C::MIP_STATUS_NONE; } ///@brief Create a pending command for the given descriptor pair. /// From d2a143e969306460717c0c3207d63467ca5880a6 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:31:40 -0500 Subject: [PATCH 10/20] Add set baudrate function to serial port. --- src/mip/platform/serial_connection.cpp | 11 +++++ src/mip/platform/serial_connection.hpp | 4 ++ src/mip/utils/serial_port.c | 58 ++++++++++++++++++++++++++ src/mip/utils/serial_port.h | 1 + 4 files changed, 74 insertions(+) diff --git a/src/mip/platform/serial_connection.cpp b/src/mip/platform/serial_connection.cpp index 7b9380b66..be4a7ff82 100644 --- a/src/mip/platform/serial_connection.cpp +++ b/src/mip/platform/serial_connection.cpp @@ -52,6 +52,17 @@ bool SerialConnection::disconnect() return serial_port_close(&mPort); } +///@brief Change the baudrate +bool SerialConnection::setBaudrate(uint32_t baud) +{ + bool ok = serial_port_set_baudrate(&mPort, baud); + + if(ok) + mBaudrate = baud; + + return ok; +} + ///@copydoc mip::Connection::recvFromDevice diff --git a/src/mip/platform/serial_connection.hpp b/src/mip/platform/serial_connection.hpp index 6c6ce0727..aefc5c900 100644 --- a/src/mip/platform/serial_connection.hpp +++ b/src/mip/platform/serial_connection.hpp @@ -39,6 +39,10 @@ class SerialConnection : public mip::Connection baudrate = mBaudrate; }; + uint32_t baudrate() const { return mBaudrate; } + + bool setBaudrate(uint32_t baud); + private: serial_port mPort; std::string mPortName; diff --git a/src/mip/utils/serial_port.c b/src/mip/utils/serial_port.c index bb045b7d4..efd90b7eb 100644 --- a/src/mip/utils/serial_port.c +++ b/src/mip/utils/serial_port.c @@ -255,6 +255,64 @@ bool serial_port_open(serial_port *port, const char *port_str, int baudrate) return true; } +bool serial_port_set_baudrate(serial_port* port, int baudrate) +{ + if(!serial_port_is_open(port)) + return false; + +#ifdef WIN32 + DCB dcb; + + if(GetCommState(port->handle, &dcb) == 0) + { + MIP_LOG_ERROR("GetCommState() failed with error code %d\n", GetLastError()); + return false; + } + + dcb.BaudRate = baudrate; + + if(SetCommState(port->handle, &dcb) == 0) + { + MIP_LOG_ERROR("SetCommState() failed with error code %d\n", GetLastError()); + return false; + } + +#elif defined __APPLE__ + + speed_t speed = baudrate; + if (ioctl(port->handle, IOSSIOSPEED, &speed) < 0) + { + MIP_LOG_ERROR("Unable to set baud rate (%d): %s\n", errno, strerror(errno)); + return false; + } + +#else // Linux + + // Get existing settings + struct termios serial_port_settings; + if (tcgetattr(port->handle, &serial_port_settings) < 0) + { + MIP_LOG_ERROR("Unable to get serial port settings (%d): %s\n", errno, strerror(errno)); + return false; + } + + if (cfsetispeed(&serial_port_settings, baud_rate_to_speed(baudrate)) < 0 || cfsetospeed(&serial_port_settings, baud_rate_to_speed(baudrate)) < 0) + { + MIP_LOG_ERROR("Unable to set baud rate (%d): %s\n", errno, strerror(errno)); + return false; + } + + // Persist the settings + if(tcsetattr(port->handle, TCSANOW, &serial_port_settings) < 0) + { + MIP_LOG_ERROR("Unable to save serial port settings (%d): %s\n", errno, strerror(errno)); + return false; + } +#endif + + return true; +} + bool serial_port_close(serial_port *port) { if(!serial_port_is_open(port)) diff --git a/src/mip/utils/serial_port.h b/src/mip/utils/serial_port.h index a56b0c259..c8dcf6b9b 100644 --- a/src/mip/utils/serial_port.h +++ b/src/mip/utils/serial_port.h @@ -48,6 +48,7 @@ typedef struct serial_port void serial_port_init(serial_port *port); bool serial_port_open(serial_port *port, const char *port_str, int baudrate); +bool serial_port_set_baudrate(serial_port *port, int baudrate); bool serial_port_close(serial_port *port); bool serial_port_write(serial_port *port, const void *buffer, size_t num_bytes, size_t *bytes_written); bool serial_port_read(serial_port *port, void *buffer, size_t num_bytes, int wait_time, size_t *bytes_read); From 237d7b3a7741cedfea5bd3cc324d5148f13948f4 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:38:03 -0500 Subject: [PATCH 11/20] Fix potential bug in FirmwareVersion::fromString due to std::isdigit() --- src/mip/extras/version.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mip/extras/version.cpp b/src/mip/extras/version.cpp index d5b63c57c..4e8e60bf9 100644 --- a/src/mip/extras/version.cpp +++ b/src/mip/extras/version.cpp @@ -24,7 +24,8 @@ void FirmwareVersion::toString(char* buffer, size_t buffer_size) const ///@brief Reads a standard-format string (X.Y.ZZ\0 or XYZZ\0). /// ///@param str Input string. Can be unterminated if length is specified. -///@param length Length of input string. Assumed to be NULL-terminated if -1. +///@param length Limits reading this many chars from str. Can be larger if str +/// is terminated. Use -1 if unknown and str is terminated. /// ///@return True if a valid version was parsed. /// @@ -35,7 +36,7 @@ bool FirmwareVersion::fromString(const char* str, size_t length) unsigned int digit = 0; for(unsigned int i=0; i Date: Fri, 1 Mar 2024 14:09:38 -0500 Subject: [PATCH 12/20] Update comparison operators of FirmwareVersion. --- src/mip/extras/version.hpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/mip/extras/version.hpp b/src/mip/extras/version.hpp index 23467e2b2..d59110f4e 100644 --- a/src/mip/extras/version.hpp +++ b/src/mip/extras/version.hpp @@ -5,6 +5,9 @@ #include +#if __cpp_impl_three_way_comparison +#include +#endif #if __cpp_lib_string_view >= 201606L #include #endif @@ -49,11 +52,21 @@ class FirmwareVersion uint8_t patch() const { return m_version % 100; } bool operator==(FirmwareVersion other) const { return m_version == other.m_version; } - bool operator!=(FirmwareVersion other) const { return m_version != other.m_version; } - bool operator<=(FirmwareVersion other) const { return m_version <= other.m_version; } - bool operator>=(FirmwareVersion other) const { return m_version >= other.m_version; } - bool operator< (FirmwareVersion other) const { return m_version < other.m_version; } - bool operator> (FirmwareVersion other) const { return m_version > other.m_version; } + bool operator!=(FirmwareVersion other) const { return !(*this == other); } +#ifndef __cpp_impl_three_way_comparison + bool operator<=(FirmwareVersion other) const { return !isNull() && major() == other.major() && m_version <= other.m_version; } + bool operator>=(FirmwareVersion other) const { return !isNull() && major() == other.major() && m_version >= other.m_version; } + bool operator< (FirmwareVersion other) const { return !isNull() && major() == other.major() && m_version < other.m_version; } + bool operator> (FirmwareVersion other) const { return !isNull() && major() == other.major() && m_version > other.m_version; } +#else // __cpp_impl_three_way_comparison + auto operator<=>(FirmwareVersion other) const + { + if(major() != other.major() || isNull()) + return std::partial_ordering::unordered; + else + return std::partial_ordering(m_version <=> other.m_version); + } +#endif // __cpp_impl_three_way_comparison void toString(char* buffer, size_t buffer_size) const; bool fromString(const char* str, size_t length=-1); From 9c53579028d4b23177700fdb0b52b1b7ee654715 Mon Sep 17 00:00:00 2001 From: microstrain-sam <105877710+microstrain-sam@users.noreply.github.com> Date: Fri, 15 Mar 2024 14:04:12 -0400 Subject: [PATCH 13/20] Fix warning. --- src/mip/mip.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mip/mip.hpp b/src/mip/mip.hpp index ab6c18711..e883534fe 100644 --- a/src/mip/mip.hpp +++ b/src/mip/mip.hpp @@ -173,7 +173,7 @@ class PacketRef : public C::mip_packet PacketLength bufferSize() const { return C::mip_packet_buffer_size(this); } ///<@copydoc mip::C::mip_packet_buffer_size RemainingCount remainingSpace() const { return C::mip_packet_remaining_space(this); } ///<@copydoc mip::C::mip_packet_remaining_space - bool addField(uint8_t fieldDescriptor, const uint8_t* payload, size_t payloadLength) { return C::mip_packet_add_field(this, fieldDescriptor, payload, payloadLength); } ///<@copydoc mip::C::mip_packet_add_field + bool addField(uint8_t fieldDescriptor, const uint8_t* payload, size_t payloadLength) { return C::mip_packet_add_field(this, fieldDescriptor, payload, static_cast(payloadLength)); } ///<@copydoc mip::C::mip_packet_add_field RemainingCount allocField(uint8_t fieldDescriptor, uint8_t payloadLength, uint8_t** payloadPtr_out) { return C::mip_packet_alloc_field(this, fieldDescriptor, payloadLength, payloadPtr_out); } ///<@copydoc mip::C::mip_packet_alloc_field RemainingCount reallocLastField(uint8_t* payloadPtr, uint8_t newPayloadLength) { return C::mip_packet_realloc_last_field(this, payloadPtr, newPayloadLength); } ///<@copydoc mip::C::mip_packet_realloc_last_field RemainingCount cancelLastField(uint8_t* payloadPtr) { return C::mip_packet_cancel_last_field(this, payloadPtr); } ///<@copydoc mip::C::mip_packet_cancel_last_field From cbb29a9a662f69b55f4ec24420f9f8dbf60b45d9 Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Tue, 26 Nov 2024 11:28:24 -0500 Subject: [PATCH 14/20] Moved new platform_connection logic to mip extras --- src/{mip/platform => cpp/mip/extras}/platform_connection.cpp | 0 src/{mip/platform => cpp/mip/extras}/platform_connection.hpp | 3 +++ 2 files changed, 3 insertions(+) rename src/{mip/platform => cpp/mip/extras}/platform_connection.cpp (100%) rename src/{mip/platform => cpp/mip/extras}/platform_connection.hpp (91%) diff --git a/src/mip/platform/platform_connection.cpp b/src/cpp/mip/extras/platform_connection.cpp similarity index 100% rename from src/mip/platform/platform_connection.cpp rename to src/cpp/mip/extras/platform_connection.cpp diff --git a/src/mip/platform/platform_connection.hpp b/src/cpp/mip/extras/platform_connection.hpp similarity index 91% rename from src/mip/platform/platform_connection.hpp rename to src/cpp/mip/extras/platform_connection.hpp index a1825cf8e..41a651afa 100644 --- a/src/mip/platform/platform_connection.hpp +++ b/src/cpp/mip/extras/platform_connection.hpp @@ -1,10 +1,13 @@ #pragma once +// TODO: Figure out if new... + #include "mip/mip_device.hpp" #include #include +// tsets namespace mip { From 1dbdfe51d6d1f7c3310ff1ab881b1433c3bee41a Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Tue, 26 Nov 2024 11:33:35 -0500 Subject: [PATCH 15/20] Updated connection include and call after merge --- src/cpp/mip/extras/platform_connection.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cpp/mip/extras/platform_connection.hpp b/src/cpp/mip/extras/platform_connection.hpp index 41a651afa..d8f2b11b3 100644 --- a/src/cpp/mip/extras/platform_connection.hpp +++ b/src/cpp/mip/extras/platform_connection.hpp @@ -1,8 +1,6 @@ #pragma once -// TODO: Figure out if new... - -#include "mip/mip_device.hpp" +#include "mip/mip_interface.hpp" #include #include @@ -13,7 +11,7 @@ namespace mip { namespace platform { - std::unique_ptr createConnectionFromInterfaceName(std::string interface_name, uint32_t parameter); + std::unique_ptr createConnectionFromInterfaceName(std::string interface_name, uint32_t parameter); bool isNetworkInterfaceName(std::string_view interface_name); bool isSerialInterfaceName(std::string_view interface_name); From 3eff10c060206c4211651e6a602e464dc71187f3 Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Tue, 26 Nov 2024 16:05:13 -0500 Subject: [PATCH 16/20] Fixed unresolved externals issue with platform_connection.hpp --- src/cpp/mip/extras/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cpp/mip/extras/CMakeLists.txt b/src/cpp/mip/extras/CMakeLists.txt index 679c89ac1..234e87889 100644 --- a/src/cpp/mip/extras/CMakeLists.txt +++ b/src/cpp/mip/extras/CMakeLists.txt @@ -6,6 +6,9 @@ add_library(${MIP_EXTRAS_LIBRARY} "${CMAKE_CURRENT_LIST_DIR}/descriptor_id.hpp" "${CMAKE_CURRENT_LIST_DIR}/firmware_version.cpp" "${CMAKE_CURRENT_LIST_DIR}/firmware_version.hpp" + "${CMAKE_CURRENT_LIST_DIR}/mip_extras_all.hpp" + "${CMAKE_CURRENT_LIST_DIR}/platform_connection.cpp" + "${CMAKE_CURRENT_LIST_DIR}/platform_connection.hpp" ) target_compile_features(${MIP_EXTRAS_LIBRARY} PUBLIC cxx_std_11) From bc9f4dd8f44ebe1f5967c795b5f73e516a78c96a Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Tue, 26 Nov 2024 16:09:51 -0500 Subject: [PATCH 17/20] Fixed template issue with Connection unique pointer after merge --- src/cpp/mip/extras/platform_connection.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cpp/mip/extras/platform_connection.cpp b/src/cpp/mip/extras/platform_connection.cpp index 2f9ade545..7806ceb58 100644 --- a/src/cpp/mip/extras/platform_connection.cpp +++ b/src/cpp/mip/extras/platform_connection.cpp @@ -1,6 +1,6 @@ #pragma once -#include "platform_connection.hpp" +#include "mip/extras/platform_connection.hpp" #if MIP_USE_SERIAL #include "serial_connection.hpp" @@ -10,6 +10,8 @@ #include "tcp_connection.hpp" #endif +#include + #include @@ -31,7 +33,7 @@ namespace platform /// For serial ports, this is the baud rate. /// For TCP sockets, this is the port number. /// - std::unique_ptr createConnectionFromInterfaceName(std::string interface_name, uint32_t parameter) + std::unique_ptr createConnectionFromInterfaceName(std::string interface_name, uint32_t parameter) { #ifdef MIP_USE_SERIAL // Todo: Detect USB connections (interface_name.find("ttyACM0") or similar) @@ -70,9 +72,9 @@ namespace platform /// ///@returns True if the interface could be a URL or IP address. False otherwise. /// - bool isNetworkInterfaceName(std::string_view interface) + bool isNetworkInterfaceName(std::string_view interface_name) { - return interface == "localhost" || interface.find('.') != std::string::npos; + return interface_name == "localhost" || interface_name.find('.') != std::string::npos; } From d1f9885002b59bb72f0dfc6e3eb2d7eef613a680 Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Wed, 27 Nov 2024 11:44:05 -0500 Subject: [PATCH 18/20] Fixed runCommand unresolved externals error --- src/cpp/mip/mip_interface.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cpp/mip/mip_interface.hpp b/src/cpp/mip/mip_interface.hpp index 661367994..280d9f4ea 100644 --- a/src/cpp/mip/mip_interface.hpp +++ b/src/cpp/mip/mip_interface.hpp @@ -201,13 +201,13 @@ class Interface : public C::mip_interface // template - TypedResult runCommand(const Cmd& cmd, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, additionalTime); } + CmdResult runCommand(const Cmd& cmd, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, additionalTime); } template - TypedResult runCommand(Args&&... args, Timeout additionalTime=0) { return mip::runCommand(*this, std::forward(args)..., additionalTime); } + CmdResult runCommand(Args&&... args, Timeout additionalTime=0) { return mip::runCommand(*this, std::forward(args)..., additionalTime); } template - TypedResult runCommand(const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, response, additionalTime); } + CmdResult runCommand(const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime=0) { return mip::runCommand(*this, cmd, response, additionalTime); } template @@ -834,7 +834,7 @@ void Interface::registerExtractor(C::mip_dispatch_handler& handler, DataField* f template -TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime) +CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout additionalTime) { PacketBuf packet(cmd); @@ -845,14 +845,14 @@ TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, Timeout ad } template -TypedResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime) +CmdResult runCommand(C::mip_interface& device, const Args&&... args, Timeout additionalTime) { Cmd cmd{std::forward(args)...}; return runCommand(device, cmd, additionalTime); } template -TypedResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime) +CmdResult runCommand(C::mip_interface& device, const Cmd& cmd, typename Cmd::Response& response, Timeout additionalTime) { PacketBuf packet(cmd); From 37272409be43446e1ccec3cadd05780a02ed1d3a Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Wed, 27 Nov 2024 15:21:34 -0500 Subject: [PATCH 19/20] Serial port fix after merge --- src/c/microstrain/connections/serial/serial_port.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/c/microstrain/connections/serial/serial_port.c b/src/c/microstrain/connections/serial/serial_port.c index 1537006f4..be117b81b 100644 --- a/src/c/microstrain/connections/serial/serial_port.c +++ b/src/c/microstrain/connections/serial/serial_port.c @@ -265,7 +265,7 @@ bool serial_port_set_baudrate(serial_port* port, int baudrate) if(GetCommState(port->handle, &dcb) == 0) { - MIP_LOG_ERROR("GetCommState() failed with error code %d\n", GetLastError()); + MICROSTRAIN_LOG_ERROR("GetCommState() failed with error code %d\n", GetLastError()); return false; } @@ -273,7 +273,7 @@ bool serial_port_set_baudrate(serial_port* port, int baudrate) if(SetCommState(port->handle, &dcb) == 0) { - MIP_LOG_ERROR("SetCommState() failed with error code %d\n", GetLastError()); + MICROSTRAIN_LOG_ERROR("SetCommState() failed with error code %d\n", GetLastError()); return false; } @@ -282,7 +282,7 @@ bool serial_port_set_baudrate(serial_port* port, int baudrate) speed_t speed = baudrate; if (ioctl(port->handle, IOSSIOSPEED, &speed) < 0) { - MIP_LOG_ERROR("Unable to set baud rate (%d): %s\n", errno, strerror(errno)); + MICROSTRAIN_LOG_ERROR("Unable to set baud rate (%d): %s\n", errno, strerror(errno)); return false; } @@ -292,20 +292,20 @@ bool serial_port_set_baudrate(serial_port* port, int baudrate) struct termios serial_port_settings; if (tcgetattr(port->handle, &serial_port_settings) < 0) { - MIP_LOG_ERROR("Unable to get serial port settings (%d): %s\n", errno, strerror(errno)); + MICROSTRAIN_LOG_ERROR("Unable to get serial port settings (%d): %s\n", errno, strerror(errno)); return false; } if (cfsetispeed(&serial_port_settings, baud_rate_to_speed(baudrate)) < 0 || cfsetospeed(&serial_port_settings, baud_rate_to_speed(baudrate)) < 0) { - MIP_LOG_ERROR("Unable to set baud rate (%d): %s\n", errno, strerror(errno)); + MICROSTRAIN_LOG_ERROR("Unable to set baud rate (%d): %s\n", errno, strerror(errno)); return false; } // Persist the settings if(tcsetattr(port->handle, TCSANOW, &serial_port_settings) < 0) { - MIP_LOG_ERROR("Unable to save serial port settings (%d): %s\n", errno, strerror(errno)); + MICROSTRAIN_LOG_ERROR("Unable to save serial port settings (%d): %s\n", errno, strerror(errno)); return false; } #endif From 9b159599336a4242f6dcca3737ec5f3fd0190b1a Mon Sep 17 00:00:00 2001 From: Alex Farrell Date: Thu, 5 Dec 2024 14:10:56 -0500 Subject: [PATCH 20/20] Fixed device model lookup issue when unknown model after merge --- src/c/mip/mip_device_models.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c/mip/mip_device_models.c b/src/c/mip/mip_device_models.c index 31a130665..f7807ad9f 100644 --- a/src/c/mip/mip_device_models.c +++ b/src/c/mip/mip_device_models.c @@ -101,7 +101,7 @@ const char* get_model_name_from_number(mip_model_number model) case MODEL_3DM_CV7_INS: return "3DM-CV7-INS"; default: - case MODEL_UNKNOWN: return "Unknown"; + case MODEL_UNKNOWN: return ""; } }