From fe891dc1501441d035fc8085ed5e3d90bc762e68 Mon Sep 17 00:00:00 2001 From: ConstantRobotics Date: Thu, 20 Jun 2024 10:31:26 +0200 Subject: [PATCH] Tests ready --- CMakeLists.txt | 4 +- example/CMakeLists.txt | 5 + example/CustomLrf.cpp | 648 ++--------------------------------- example/CustomLrf.h | 81 ++--- example/CustomLrfVersion.h | 7 + src/CMakeLists.txt | 5 + src/Lrf.cpp | 6 +- src/Lrf.h | 3 +- test/main.cpp | 675 +++++++------------------------------ 9 files changed, 209 insertions(+), 1225 deletions(-) create mode 100644 example/CustomLrfVersion.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f050f1..d91bd54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,8 @@ endif() ## project configuration ################################################################################ SET(${PARENT}_LRF ON CACHE BOOL "" ${REWRITE_FORCE}) -SET(${PARENT}_LRF_TEST OFF CACHE BOOL "" ${REWRITE_FORCE}) -SET(${PARENT}_LRF_EXAMPLE OFF CACHE BOOL "" ${REWRITE_FORCE}) +SET(${PARENT}_LRF_TEST ON CACHE BOOL "" ${REWRITE_FORCE}) +SET(${PARENT}_LRF_EXAMPLE ON CACHE BOOL "" ${REWRITE_FORCE}) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 404c930..b988e0d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -44,6 +44,11 @@ if (NOT TARGET ${PROJECT_NAME}) endif() target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +# Set default build type to Release +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (default Release)" FORCE) +endif() + ############################################################################### diff --git a/example/CustomLrf.cpp b/example/CustomLrf.cpp index c9be864..3a5b2bb 100644 --- a/example/CustomLrf.cpp +++ b/example/CustomLrf.cpp @@ -1,34 +1,30 @@ -#include "CustomLens.h" -#include "CustomLensVersion.h" +#include "CustomLrf.h" -cr::lens::CustomLens::CustomLens() +cr::lrf::CustomLrf::CustomLrf() { - // Reset connection flags. - m_params.isOpen = false; - m_params.isConnected = false; + } -cr::lens::CustomLens::~CustomLens() +cr::lrf::CustomLrf::~CustomLrf() { } -std::string cr::lens::CustomLens::getVersion() +std::string cr::lrf::CustomLrf::getVersion() { - return CUSTOM_LENS_VERSION; + return CUSTOM_LRF_VERSION; } -bool cr::lens::CustomLens::openLens(std::string initString) +bool cr::lrf::CustomLrf::openLrf(std::string initString) { - // Set connection flags. m_params.isOpen = true; m_params.isConnected = true; @@ -37,673 +33,75 @@ bool cr::lens::CustomLens::openLens(std::string initString) -bool cr::lens::CustomLens::initLens(cr::lens::LensParams& params) +bool cr::lrf::CustomLrf::initLrf(cr::lrf::LrfParams& params) { - // Copy params. m_params = params; - - // Set connection flags. - m_params.isOpen = true; - m_params.isConnected = true; - return true; } -void cr::lens::CustomLens::closeLens() +void cr::lrf::CustomLrf::closeLrf() { - // Reset connection flags. m_params.isOpen = false; m_params.isConnected = false; } -bool cr::lens::CustomLens::isLensOpen() +bool cr::lrf::CustomLrf::isLrfOpen() { return m_params.isOpen; } -bool cr::lens::CustomLens::isLensConnected() +bool cr::lrf::CustomLrf::isLrfConnected() { return m_params.isConnected; } -bool cr::lens::CustomLens::setParam(cr::lens::LensParam id, float value) +bool cr::lrf::CustomLrf::setParam(cr::lrf::LrfParam id, float value) { - // Check parameter ID. - switch (id) - { - case cr::lens::LensParam::ZOOM_POS: - { - // Save param. - m_params.zoomPos = (int)value; - return true; - } - case cr::lens::LensParam::ZOOM_HW_POS: - { - // Save param. - m_params.zoomHwPos = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_POS: - { - // Save param. - m_params.focusPos = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_HW_POS: - { - // Save param. - m_params.focusHwPos = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_POS: - { - // Save param. - m_params.irisPos = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_HW_POS: - { - // Save param. - m_params.irisHwPos = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_MODE: - { - // Save param. - m_params.focusMode = (int)value; - return true; - } - case cr::lens::LensParam::FILTER_MODE: - { - // Save param. - m_params.filterMode = (int)value; - return true; - } - case cr::lens::LensParam::AF_ROI_X0: - { - // Save param. - m_params.afRoiX0 = (int)value; - return true; - } - case cr::lens::LensParam::AF_ROI_Y0: - { - // Save param. - m_params.afRoiY0 = (int)value; - return true; - } - case cr::lens::LensParam::AF_ROI_X1: - { - // Save param. - m_params.afRoiX1 = (int)value; - return true; - } - case cr::lens::LensParam::AF_ROI_Y1: - { - // Save param. - m_params.afRoiY1 = (int)value; - return true; - } - case cr::lens::LensParam::ZOOM_SPEED: - { - // Save param. - m_params.zoomSpeed = (int)value; - return true; - } - case cr::lens::LensParam::ZOOM_HW_SPEED: - { - // Save param. - m_params.zoomHwSpeed = (int)value; - return true; - } - case cr::lens::LensParam::ZOOM_HW_MAX_SPEED: - { - // Save param. - m_params.zoomHwMaxSpeed = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_SPEED: - { - // Save param. - m_params.focusSpeed = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_HW_SPEED: - { - // Save param. - m_params.focusHwSpeed = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_HW_MAX_SPEED: - { - // Save param. - m_params.focusHwMaxSpeed = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_SPEED: - { - // Save param. - m_params.irisSpeed = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_HW_SPEED: - { - // Save param. - m_params.irisHwSpeed = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_HW_MAX_SPEED: - { - // Save param. - m_params.irisHwMaxSpeed = (int)value; - return true; - } - case cr::lens::LensParam::ZOOM_HW_TELE_LIMIT: - { - // Save param. - m_params.zoomHwTeleLimit = (int)value; - return true; - } - case cr::lens::LensParam::ZOOM_HW_WIDE_LIMIT: - { - // Save param. - m_params.zoomHwWideLimit = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_HW_FAR_LIMIT: - { - // Save param. - m_params.focusHwNearLimit = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_HW_NEAR_LIMIT: - { - // Save param. - m_params.focusHwNearLimit = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_HW_OPEN_LIMIT: - { - // Save param. - m_params.irisHwOpenLimit = (int)value; - return true; - } - case cr::lens::LensParam::IRIS_HW_CLOSE_LIMIT: - { - // Save param. - m_params.irisHwCloseLimit = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_FACTOR: - { - // Read only param. - return false; - } - case cr::lens::LensParam::IS_CONNECTED: - { - // Read only param. - return false; - } - case cr::lens::LensParam::FOCUS_HW_AF_SPEED: - { - // Save param. - m_params.afHwSpeed = (int)value; - return true; - } - case cr::lens::LensParam::FOCUS_FACTOR_THRESHOLD: - { - // Save param. - m_params.focusFactorThreshold = value; - return true; - } - case cr::lens::LensParam::REFOCUS_TIMEOUT_SEC: - { - // Save param. - m_params.refocusTimeoutSec = (int)value; - return true; - } - case cr::lens::LensParam::AF_IS_ACTIVE: - { - // Read only param. - return false; - } - case cr::lens::LensParam::IRIS_MODE: - { - // Save param. - m_params.irisMode = (int)value; - return true; - } - case cr::lens::LensParam::AUTO_AF_ROI_WIDTH: - { - // Save param. - m_params.autoAfRoiWidth = (int)value; - return true; - } - case cr::lens::LensParam::AUTO_AF_ROI_HEIGHT: - { - // Save param. - m_params.autoAfRoiHeight = (int)value; - return true; - } - case cr::lens::LensParam::AUTO_AF_ROI_BORDER: - { - // Save param. - m_params.autoAfRoiBorder = (int)value; - return true; - } - case cr::lens::LensParam::AF_ROI_MODE: - { - // Save param. - m_params.afRoiMode = (int)value; - return true; - } - case cr::lens::LensParam::EXTENDER_MODE: - { - // Save param. - m_params.extenderMode = (int)value; - return true; - } - case cr::lens::LensParam::STABILIZER_MODE: - { - // Save param. - m_params.stabiliserMode = (int)value; - return true; - } - case cr::lens::LensParam::AF_RANGE: - { - // Save param. - m_params.afRange = (int)value; - return true; - } - case cr::lens::LensParam::X_FOV_DEG: - { - // Read only param. - return false; - } - case cr::lens::LensParam::Y_FOV_DEG: - { - // Read only param. - return false; - } - case cr::lens::LensParam::LOG_MODE: - { - // Save param. - m_params.logMode = (int)value; - return true; - } - case cr::lens::LensParam::TEMPERATURE: - { - // Read only param. - return false; - } - case cr::lens::LensParam::IS_OPEN: - { - // Read only param. - return false; - } - case cr::lens::LensParam::TYPE: - { - // Save param. - m_params.type = (int)value; - return true; - } - case cr::lens::LensParam::CUSTOM_1: - { - // Save param. - m_params.custom1 = value; - return true; - } - case cr::lens::LensParam::CUSTOM_2: - { - // Save param. - m_params.custom2 = value; - return true; - } - case cr::lens::LensParam::CUSTOM_3: - { - // Save param. - m_params.custom3 = value; - return true; - } - default: - { - return false; - } - } - - return false; + return true; } -float cr::lens::CustomLens::getParam(cr::lens::LensParam id) +float cr::lrf::CustomLrf::getParam(cr::lrf::LrfParam id) { - // Check parameter ID. - switch (id) - { - case cr::lens::LensParam::ZOOM_POS: - { - return (float)m_params.zoomPos; - } - case cr::lens::LensParam::ZOOM_HW_POS: - { - return (float)m_params.zoomHwPos; - } - case cr::lens::LensParam::FOCUS_POS: - { - return (float)m_params.focusPos; - } - case cr::lens::LensParam::FOCUS_HW_POS: - { - return (float)m_params.focusHwPos; - } - case cr::lens::LensParam::IRIS_POS: - { - return (float)m_params.irisPos; - } - case cr::lens::LensParam::IRIS_HW_POS: - { - return (float)m_params.irisHwPos; - } - case cr::lens::LensParam::FOCUS_MODE: - { - return (float)m_params.focusMode; - } - case cr::lens::LensParam::FILTER_MODE: - { - return (float)m_params.filterMode; - } - case cr::lens::LensParam::AF_ROI_X0: - { - return (float)m_params.afRoiX0; - } - case cr::lens::LensParam::AF_ROI_Y0: - { - return (float)m_params.afRoiY0; - } - case cr::lens::LensParam::AF_ROI_X1: - { - return (float)m_params.afRoiX1; - } - case cr::lens::LensParam::AF_ROI_Y1: - { - return (float)m_params.afRoiY1; - } - case cr::lens::LensParam::ZOOM_SPEED: - { - return (float)m_params.zoomSpeed; - } - case cr::lens::LensParam::ZOOM_HW_SPEED: - { - return (float)m_params.zoomHwSpeed; - } - case cr::lens::LensParam::ZOOM_HW_MAX_SPEED: - { - return (float)m_params.zoomHwMaxSpeed; - } - case cr::lens::LensParam::FOCUS_SPEED: - { - return (float)m_params.focusSpeed; - } - case cr::lens::LensParam::FOCUS_HW_SPEED: - { - return (float)m_params.focusHwSpeed; - } - case cr::lens::LensParam::FOCUS_HW_MAX_SPEED: - { - return (float)m_params.focusHwMaxSpeed; - } - case cr::lens::LensParam::IRIS_SPEED: - { - return (float)m_params.irisSpeed; - } - case cr::lens::LensParam::IRIS_HW_SPEED: - { - return (float)m_params.irisHwSpeed; - } - case cr::lens::LensParam::IRIS_HW_MAX_SPEED: - { - return (float)m_params.irisHwMaxSpeed; - } - case cr::lens::LensParam::ZOOM_HW_TELE_LIMIT: - { - return (float)m_params.zoomHwTeleLimit; - } - case cr::lens::LensParam::ZOOM_HW_WIDE_LIMIT: - { - return (float)m_params.zoomHwWideLimit; - } - case cr::lens::LensParam::FOCUS_HW_FAR_LIMIT: - { - return (float)m_params.focusHwNearLimit; - } - case cr::lens::LensParam::FOCUS_HW_NEAR_LIMIT: - { - return (float)m_params.focusHwNearLimit; - } - case cr::lens::LensParam::IRIS_HW_OPEN_LIMIT: - { - return (float)m_params.irisHwOpenLimit; - } - case cr::lens::LensParam::IRIS_HW_CLOSE_LIMIT: - { - return (float)m_params.irisHwCloseLimit; - } - case cr::lens::LensParam::FOCUS_FACTOR: - { - return m_params.focusFactor; - } - case cr::lens::LensParam::IS_CONNECTED: - { - return m_params.isConnected ? 1.0f : 0.0f; - } - case cr::lens::LensParam::FOCUS_HW_AF_SPEED: - { - return (float)m_params.afHwSpeed; - } - case cr::lens::LensParam::FOCUS_FACTOR_THRESHOLD: - { - return m_params.focusFactorThreshold; - } - case cr::lens::LensParam::REFOCUS_TIMEOUT_SEC: - { - return (float)m_params.refocusTimeoutSec; - } - case cr::lens::LensParam::AF_IS_ACTIVE: - { - return m_params.afIsActive ? 1.0f : 0.0f; - } - case cr::lens::LensParam::IRIS_MODE: - { - return (float)m_params.irisMode; - } - case cr::lens::LensParam::AUTO_AF_ROI_WIDTH: - { - return (float)m_params.autoAfRoiWidth; - } - case cr::lens::LensParam::AUTO_AF_ROI_HEIGHT: - { - return (float)m_params.autoAfRoiHeight; - } - case cr::lens::LensParam::AUTO_AF_ROI_BORDER: - { - return (float)m_params.autoAfRoiBorder; - } - case cr::lens::LensParam::AF_ROI_MODE: - { - return (float)m_params.afRoiMode; - } - case cr::lens::LensParam::EXTENDER_MODE: - { - return (float)m_params.extenderMode; - } - case cr::lens::LensParam::STABILIZER_MODE: - { - return (float)m_params.stabiliserMode; - } - case cr::lens::LensParam::AF_RANGE: - { - return (float)m_params.afRange; - } - case cr::lens::LensParam::X_FOV_DEG: - { - return m_params.xFovDeg; - } - case cr::lens::LensParam::Y_FOV_DEG: - { - return m_params.yFovDeg; - } - case cr::lens::LensParam::LOG_MODE: - { - return (float)m_params.logMode; - } - case cr::lens::LensParam::TEMPERATURE: - { - return m_params.temperature; - } - case cr::lens::LensParam::IS_OPEN: - { - return m_params.isOpen ? 1.0f : 0.0f; - } - case cr::lens::LensParam::TYPE: - { - return (float)m_params.type; - } - case cr::lens::LensParam::CUSTOM_1: - { - return m_params.custom1; - } - case cr::lens::LensParam::CUSTOM_2: - { - return m_params.custom2; - } - case cr::lens::LensParam::CUSTOM_3: - { - return m_params.custom3; - } - default: - { - return -1.0f; - } - } - return -1.0f; } -void cr::lens::CustomLens::getParams(cr::lens::LensParams& params) +void cr::lrf::CustomLrf::getParams(cr::lrf::LrfParams& params) { params = m_params; } -bool cr::lens::CustomLens::executeCommand(cr::lens::LensCommand id, float arg) +bool cr::lrf::CustomLrf::executeCommand(LrfCommand id) { - // Check command ID. - switch (id) - { - case cr::lens::LensCommand::ZOOM_TELE: - { - return true; - } - case cr::lens::LensCommand::ZOOM_WIDE: - { - return true; - } - case cr::lens::LensCommand::ZOOM_TO_POS: - { - return true; - } - case cr::lens::LensCommand::ZOOM_STOP: - { - return true; - } - case cr::lens::LensCommand::FOCUS_FAR: - { - return true; - } - case cr::lens::LensCommand::FOCUS_NEAR: - { - return true; - } - case cr::lens::LensCommand::FOCUS_TO_POS: - { - return true; - } - case cr::lens::LensCommand::FOCUS_STOP: - { - return true; - } - case cr::lens::LensCommand::IRIS_OPEN: - { - return true; - } - case cr::lens::LensCommand::IRIS_CLOSE: - { - return true; - } - case cr::lens::LensCommand::IRIS_TO_POS: - { - return true; - } - case cr::lens::LensCommand::IRIS_STOP: - { - return true; - } - case cr::lens::LensCommand::AF_START: - { - return true; - } - case cr::lens::LensCommand::AF_STOP: - { - return true; - } - case cr::lens::LensCommand::RESTART: - { - return true; - } - case cr::lens::LensCommand::DETECT_HW_RANGES: - { - return true; - } - default: - { - return false; - } - } - - return false; -} - - - -void cr::lens::CustomLens::addVideoFrame(cr::video::Frame& frame) -{ - + return true; } -bool cr::lens::CustomLens::decodeAndExecuteCommand(uint8_t* data, int size) +bool cr::lrf::CustomLrf::decodeAndExecuteCommand(uint8_t* data, int size) { // Decode command. - LensCommand commandId = LensCommand::ZOOM_TELE; - LensParam paramId = LensParam::ZOOM_SPEED; + LrfCommand commandId = LrfCommand::ARM; + LrfParam paramId = LrfParam::CUSTOM_1; float value = 0.0f; - switch (Lens::decodeCommand(data, size, paramId, commandId, value)) + switch (Lrf::decodeCommand(data, size, paramId, commandId, value)) { // COMMAND. case 0: - // Executte command. + // Execute command. return executeCommand(commandId); // SET_PARAM. case 1: @@ -718,4 +116,4 @@ bool cr::lens::CustomLens::decodeAndExecuteCommand(uint8_t* data, int size) } return false; -} +} \ No newline at end of file diff --git a/example/CustomLrf.h b/example/CustomLrf.h index aab89f2..17e482d 100644 --- a/example/CustomLrf.h +++ b/example/CustomLrf.h @@ -1,105 +1,98 @@ #pragma once #include #include -#include "Lens.h" +#include "Lrf.h" +#include "CustomLrfVersion.h" namespace cr { -namespace lens +namespace lrf { /** - * @brief Custom lens controller interface class. + * @brief Custom lrf controller. */ -class CustomLens: public Lens +class CustomLrf: public Lrf { public: /** * @brief Class constructor. */ - CustomLens(); + CustomLrf(); /** * @brief Class destructor. */ - ~CustomLens(); + ~CustomLrf(); /** - * @brief Get lens class version. - * @return Lens class version string in format "Major.Minor.Patch". + * @brief Get class version. + * @return Class version string in format "Major.Minor.Patch". */ static std::string getVersion(); /** - * @brief Open lens controller. Can be used instead initLens(...) method. - * @param initString Init string. Format depends on lens controller. - * @return TRUE if the lens controller is init or FALSE. + * @brief Open lrf controller. Can be used instead initLrf(...) method. + * @param initString Init string. Format depends on lrf controller. + * @return TRUE if the lrf controller is init or FALSE. */ - bool openLens(std::string initString); + bool openLrf(std::string initString); /** - * @brief Init lens controller by structure. Can be used instead - * openLens(...) method. - * @param initString Init string. Format depends on lens controller. - * @return TRUE if the lens controller is init or FALSE. + * @brief Init lrf controller by structure. Can be used instead + * openLrf(...) method. + * @param params Lrf params class. + * @return TRUE if the lrf controller is init or FALSE. */ - bool initLens(LensParams& params); + bool initLrf(LrfParams& params); /** * @brief Close connection. */ - void closeLens(); + void closeLrf(); /** - * @brief Get lens open status. - * @return TRUE if the lens is open or FALSE. + * @brief Get lrf open status. + * @return TRUE if the lrf is open or FALSE. */ - bool isLensOpen(); + bool isLrfOpen(); /** - * @brief Get lens connection status. Lens can be open but no response from - * lens hardware. - * @return TRUE if the lens is open or FALSE. + * @brief Get lrf connection status. Lrf can be open but no response from + * lrf hardware. + * @return TRUE if the lrf is open or FALSE. */ - bool isLensConnected(); + bool isLrfConnected(); /** - * @brief Set the lens controller param. + * @brief Set the lrf controller param. * @param id Param ID. * @param value Param value. * @return TRUE if the property set or FALSE. */ - bool setParam(LensParam id, float value); + bool setParam(LrfParam id, float value); /** - * @brief Get the lens controller param. + * @brief Get the lrf controller param. * @param id Param ID. * @return float Param value or -1 of the param not exists. */ - float getParam(LensParam id); + float getParam(LrfParam id); /** - * @brief Get the lens controller params. - * @param params Reference to LensParams object. + * @brief Get the lrf controller params. + * @param params Reference to LrfParams object. */ - void getParams(LensParams& params); + void getParams(LrfParams& params); /** - * @brief Execute command. + * @brief Execute lrf command. * @param id Command ID. - * @param arg Command argument. * @return TRUE if the command executed or FALSE. */ - bool executeCommand(LensCommand id, float arg = 0); - - /** - * @brief Add video frame for auto focus purposes. Some lens controllers - * may not support this functions. - * @param frame Video frame object. - */ - void addVideoFrame(cr::video::Frame& frame); + bool executeCommand(LrfCommand id); /** * @brief Decode and execute command. @@ -111,8 +104,8 @@ class CustomLens: public Lens private: - /// Lens parameters structure (Default params). - LensParams m_params; + /// Lrf parameters. + LrfParams m_params; }; } } diff --git a/example/CustomLrfVersion.h b/example/CustomLrfVersion.h new file mode 100644 index 0000000..7e972aa --- /dev/null +++ b/example/CustomLrfVersion.h @@ -0,0 +1,7 @@ +#pragma once + +#define CUSTOM_LRF_MAJOR_VERSION 1 +#define CUSTOM_LRF_MINOR_VERSION 0 +#define CUSTOM_LRF_PATCH_VERSION 0 + +#define CUSTOM_LRF_VERSION "1.0.0" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 05a45de..6c0d4ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,6 +48,11 @@ if (NOT TARGET ${PROJECT_NAME}) endif() target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +# Set default build type to Release +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type (default Release)" FORCE) +endif() + ############################################################################### diff --git a/src/Lrf.cpp b/src/Lrf.cpp index 3c1ba87..28d7aa7 100644 --- a/src/Lrf.cpp +++ b/src/Lrf.cpp @@ -182,7 +182,7 @@ bool LrfParams::decode(uint8_t* data, int dataSize) data[2] != LRF_MINOR_VERSION) return false; - int pos = 10; + int pos = 6; if ((data[3] & (uint8_t)128) == (uint8_t)128) { if (dataSize < pos + 4) @@ -439,8 +439,8 @@ int Lrf::decodeCommand(uint8_t* data, int size, LrfParam& paramId, LrfCommand& c return -1; int id = 0; memcpy(&id, &data[3], 4); - paramId = (LrfParam)id; - return 1; + commandId = (LrfCommand)id; + return 0; } else if (data[0] == 0x01) { diff --git a/src/Lrf.h b/src/Lrf.h index 2218200..6cab1d2 100644 --- a/src/Lrf.h +++ b/src/Lrf.h @@ -250,10 +250,9 @@ class Lrf /** * @brief Execute lrf command. * @param id Command ID. - * @param arg Command argument. * @return TRUE if the command executed or FALSE. */ - virtual bool executeCommand(LrfCommand id, float arg = 0) = 0; + virtual bool executeCommand(LrfCommand id) = 0; /** * @brief Encode set param command. diff --git a/test/main.cpp b/test/main.cpp index 8e9a632..bb21961 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,14 +1,19 @@ #include -#include "Lens.h" +#include "Lrf.h" /// Link namespaces. -using namespace cr::lens; +using namespace cr::lrf; using namespace std; +/// Prepare random params. +void prepareRandomParams(LrfParams& params); + + + /// Copy test. bool copyTest(); @@ -18,7 +23,6 @@ bool encodeDecodeParamsTest(); /// Encode/decode test with params mask. bool encodeDecodeParamsWithMaskTest(); - /// Encode/decode commands test. bool encodeDecodeCommandsTest(); @@ -26,7 +30,7 @@ bool encodeDecodeCommandsTest(); bool jsonReadWriteTest(); /// Compare params. -bool compareParams(LensParams& in, LensParams& out, LensParamsMask& mask); +bool compareParams(LrfParams& in, LrfParams& out, LrfParamsMask& mask); @@ -35,7 +39,7 @@ int main(void) { cout << "#####################################" << endl; cout << "# #" << endl; - cout << "# Lens data structures test #" << endl; + cout << "# Lrf data structures test #" << endl; cout << "# #" << endl; cout << "#####################################" << endl; cout << endl; @@ -84,72 +88,14 @@ int main(void) bool copyTest() { // Prepare random params. - LensParams in; - in.initString = "dfhglsjirhuhjfb"; - in.zoomPos = rand() % 255; - in.zoomHwPos = rand() % 255; - in.focusPos = rand() % 255; - in.focusHwPos = rand() % 255; - in.irisPos = rand() % 255; - in.irisHwPos = rand() % 255; - in.focusMode = rand() % 255; - in.filterMode = rand() % 255; - in.afRoiX0 = rand() % 255; - in.afRoiY0 = rand() % 255; - in.afRoiX1 = rand() % 255; - in.afRoiY1 = rand() % 255; - in.zoomSpeed = rand() % 255; - in.zoomHwSpeed = rand() % 255; - in.zoomHwMaxSpeed = rand() % 255; - in.focusSpeed = rand() % 255; - in.focusHwSpeed = rand() % 255; - in.focusHwMaxSpeed = rand() % 255; - in.irisSpeed = rand() % 255; - in.irisHwSpeed = rand() % 255; - in.irisHwMaxSpeed = rand() % 255; - in.zoomHwTeleLimit = rand() % 255; - in.zoomHwWideLimit = rand() % 255; - in.focusHwFarLimit = rand() % 255; - in.focusHwNearLimit = rand() % 255; - in.irisHwOpenLimit = rand() % 255; - in.irisHwCloseLimit = rand() % 255; - in.focusFactor = rand() % 255; - in.isConnected = true; - in.afHwSpeed = rand() % 255; - in.focusFactorThreshold = rand() % 255; - in.refocusTimeoutSec = rand() % 255; - in.afIsActive = true; - in.irisMode = rand() % 255; - in.autoAfRoiWidth = rand() % 255; - in.autoAfRoiHeight = rand() % 255; - in.autoAfRoiBorder = rand() % 255; - in.afRoiMode = rand() % 255; - in.extenderMode = rand() % 255; - in.stabiliserMode = rand() % 255; - in.afRange = rand() % 255; - in.xFovDeg = rand() % 255; - in.yFovDeg = rand() % 255; - in.logMode = rand() % 255; - in.temperature = rand() % 255; - in.isOpen = true; - in.type = rand() % 255; - in.custom1 = rand() % 255; - in.custom2 = rand() % 255; - in.custom3 = rand() % 255; - for (int i = 0; i < 5; ++i) - { - FovPoint pt; - pt.hwZoomPos = rand() % 255; - pt.xFovDeg = rand() % 255; - pt.yFovDeg = rand() % 255; - in.fovPoints.push_back(pt); - } + LrfParams in; + prepareRandomParams(in); // Copy params. - LensParams out = in; + LrfParams out = in; // Compare params. - LensParamsMask mask; + LrfParamsMask mask; return compareParams(in, out, mask); } @@ -159,66 +105,8 @@ bool copyTest() bool encodeDecodeParamsTest() { // Prepare random params. - LensParams in; - in.initString = "dfhglsjirhuhjfb"; - in.zoomPos = rand() % 255; - in.zoomHwPos = rand() % 255; - in.focusPos = rand() % 255; - in.focusHwPos = rand() % 255; - in.irisPos = rand() % 255; - in.irisHwPos = rand() % 255; - in.focusMode = rand() % 255; - in.filterMode = rand() % 255; - in.afRoiX0 = rand() % 255; - in.afRoiY0 = rand() % 255; - in.afRoiX1 = rand() % 255; - in.afRoiY1 = rand() % 255; - in.zoomSpeed = rand() % 255; - in.zoomHwSpeed = rand() % 255; - in.zoomHwMaxSpeed = rand() % 255; - in.focusSpeed = rand() % 255; - in.focusHwSpeed = rand() % 255; - in.focusHwMaxSpeed = rand() % 255; - in.irisSpeed = rand() % 255; - in.irisHwSpeed = rand() % 255; - in.irisHwMaxSpeed = rand() % 255; - in.zoomHwTeleLimit = rand() % 255; - in.zoomHwWideLimit = rand() % 255; - in.focusHwFarLimit = rand() % 255; - in.focusHwNearLimit = rand() % 255; - in.irisHwOpenLimit = rand() % 255; - in.irisHwCloseLimit = rand() % 255; - in.focusFactor = rand() % 255; - in.isConnected = true; - in.afHwSpeed = rand() % 255; - in.focusFactorThreshold = rand() % 255; - in.refocusTimeoutSec = rand() % 255; - in.afIsActive = true; - in.irisMode = rand() % 255; - in.autoAfRoiWidth = rand() % 255; - in.autoAfRoiHeight = rand() % 255; - in.autoAfRoiBorder = rand() % 255; - in.afRoiMode = rand() % 255; - in.extenderMode = rand() % 255; - in.stabiliserMode = rand() % 255; - in.afRange = rand() % 255; - in.xFovDeg = rand() % 255; - in.yFovDeg = rand() % 255; - in.logMode = rand() % 255; - in.temperature = rand() % 255; - in.isOpen = true; - in.type = rand() % 255; - in.custom1 = rand() % 255; - in.custom2 = rand() % 255; - in.custom3 = rand() % 255; - for (int i = 0; i < 5; ++i) - { - FovPoint pt; - pt.hwZoomPos = rand() % 255; - pt.xFovDeg = rand() % 255; - pt.yFovDeg = rand() % 255; - in.fovPoints.push_back(pt); - } + LrfParams in; + prepareRandomParams(in); // Encode data. uint8_t data[1024]; @@ -228,7 +116,7 @@ bool encodeDecodeParamsTest() cout << "Encoded data size: " << size << " bytes" << endl; // Decode data. - LensParams out; + LrfParams out; out.isConnected = false; out.isOpen = false; if (!out.decode(data, size)) @@ -238,7 +126,7 @@ bool encodeDecodeParamsTest() } // Compare params. - LensParamsMask mask; + LrfParamsMask mask; return compareParams(in, out, mask); } @@ -250,47 +138,41 @@ bool encodeDecodeCommandsTest() // Encode command. uint8_t data[1024]; int size = 0; - float outValue = (float)(rand() % 20); - Lens::encodeCommand(data, size, LensCommand::AF_STOP, outValue); + Lrf::encodeCommand(data, size, LrfCommand::ARM); // Decode command. - LensCommand commandId; - LensParam paramId; + LrfCommand commandId; + LrfParam paramId; float value = 0.0f; - if (Lens::decodeCommand(data, size, paramId, commandId, value) != 0) + if (Lrf::decodeCommand(data, size, paramId, commandId, value) != 0) { cout << "Command not decoded" << endl; return false; } - // Checkk ID and value. - if (commandId != LensCommand::AF_STOP) + // Check ID and value. + if (commandId != LrfCommand::ARM) { - cout << "not a LensCommand::AF_STOP" << endl; - return false; - } - if (value != outValue) - { - cout << "not equal value" << endl; + cout << "not a LrfCommand::ARM" << endl; return false; } // Encode param. - outValue = (float)(rand() % 20); - Lens::encodeSetParamCommand(data, size, LensParam::AF_ROI_X0, outValue); + float outValue = (float)(rand() % 20); + Lrf::encodeSetParamCommand(data, size, LrfParam::ARM_MODE, outValue); // Decode command. value = 0.0f; - if (Lens::decodeCommand(data, size, paramId, commandId, value) != 1) + if (Lrf::decodeCommand(data, size, paramId, commandId, value) != 1) { cout << "Set param command not decoded" << endl; return false; } - // Checkk ID and value. - if (paramId != LensParam::AF_ROI_X0) + // Check ID and value. + if (paramId != LrfParam::ARM_MODE) { - cout << "not a LensParam::AF_ROI_X0" << endl; + cout << "not a LrfParam::ARM_MODE" << endl; return false; } if (value != outValue) @@ -308,108 +190,49 @@ bool encodeDecodeCommandsTest() bool jsonReadWriteTest() { // Prepare random params. - LensParams in; - in.initString = "dfhglsjirhuhjfb"; - in.zoomPos = rand() % 255; - in.zoomHwPos = rand() % 255; - in.focusPos = rand() % 255; - in.focusHwPos = rand() % 255; - in.irisPos = rand() % 255; - in.irisHwPos = rand() % 255; - in.focusMode = rand() % 255; - in.filterMode = rand() % 255; - in.afRoiX0 = rand() % 255; - in.afRoiY0 = rand() % 255; - in.afRoiX1 = rand() % 255; - in.afRoiY1 = rand() % 255; - in.zoomSpeed = rand() % 255; - in.zoomHwSpeed = rand() % 255; - in.zoomHwMaxSpeed = rand() % 255; - in.focusSpeed = rand() % 255; - in.focusHwSpeed = rand() % 255; - in.focusHwMaxSpeed = rand() % 255; - in.irisSpeed = rand() % 255; - in.irisHwSpeed = rand() % 255; - in.irisHwMaxSpeed = rand() % 255; - in.zoomHwTeleLimit = rand() % 255; - in.zoomHwWideLimit = rand() % 255; - in.focusHwFarLimit = rand() % 255; - in.focusHwNearLimit = rand() % 255; - in.irisHwOpenLimit = rand() % 255; - in.irisHwCloseLimit = rand() % 255; - in.focusFactor = rand() % 255; - in.isConnected = true; - in.afHwSpeed = rand() % 255; - in.focusFactorThreshold = rand() % 255; - in.refocusTimeoutSec = rand() % 255; - in.afIsActive = true; - in.irisMode = rand() % 255; - in.autoAfRoiWidth = rand() % 255; - in.autoAfRoiHeight = rand() % 255; - in.autoAfRoiBorder = rand() % 255; - in.afRoiMode = rand() % 255; - in.extenderMode = rand() % 255; - in.stabiliserMode = rand() % 255; - in.afRange = rand() % 255; - in.xFovDeg = rand() % 255; - in.yFovDeg = rand() % 255; - in.logMode = rand() % 255; - in.temperature = rand() % 255; - in.isOpen = true; - in.type = rand() % 255; - in.custom1 = rand() % 255; - in.custom2 = rand() % 255; - in.custom3 = rand() % 255; - for (int i = 0; i < 5; ++i) - { - FovPoint pt; - pt.hwZoomPos = rand() % 255; - pt.xFovDeg = rand() % 255; - pt.yFovDeg = rand() % 255; - in.fovPoints.push_back(pt); - } + LrfParams in; + prepareRandomParams(in); // Write params to file. cr::utils::ConfigReader inConfig; - inConfig.set(in, "lensParams"); - inConfig.writeToFile("TestLensParams.json"); + inConfig.set(in, "LrfParams"); + inConfig.writeToFile("TestLrfParams.json"); // Read params from file. cr::utils::ConfigReader outConfig; - if(!outConfig.readFromFile("TestLensParams.json")) + if(!outConfig.readFromFile("TestLrfParams.json")) { cout << "Can't open config file" << endl; return false; } - LensParams out; - if(!outConfig.get(out, "lensParams")) + LrfParams out; + if(!outConfig.get(out, "LrfParams")) { cout << "Can't read params from file" << endl; return false; } // Compare params. - LensParamsMask mask; - mask.zoomPos = false; - mask.zoomHwPos = false; - mask.focusPos = false; - mask.focusHwPos = false; - mask.irisPos = false; - mask.irisHwPos = false; - mask.zoomSpeed = false; - mask.zoomHwSpeed = false; - mask.focusSpeed = false; - mask.focusHwSpeed = false; - mask.irisSpeed = false; - mask.irisHwSpeed = false; - mask.focusFactor = false; - mask.isConnected = false; - mask.afIsActive = false; - mask.xFovDeg = false; - mask.yFovDeg = false; - mask.temperature = false; + LrfParamsMask mask; + mask.distance = false; + mask.timeFromLastMeasurementUs = false; + mask.lowPowerMode = true; + mask.pointerMode = false; + mask.pointerModeTimeoutSec = true; + mask.armMode = false; + mask.operatingMode = true; + mask.continuousMeasuringMode = false; + mask.continuousModeTimeoutSec = true; + mask.logMode = true; mask.isOpen = false; + mask.isConnected = false; + mask.minGateDistance = true; + mask.maxGateDistance = true; + mask.temperatureDeg = false; + mask.custom1 = true; + mask.custom2 = true; + mask.custom3 = true; return compareParams(in, out, mask); } @@ -420,116 +243,26 @@ bool jsonReadWriteTest() bool encodeDecodeParamsWithMaskTest() { // Prepare random params. - LensParams in; - in.initString = "dfhglsjirhuhjfb"; - in.zoomPos = rand() % 255; - in.zoomHwPos = rand() % 255; - in.focusPos = rand() % 255; - in.focusHwPos = rand() % 255; - in.irisPos = rand() % 255; - in.irisHwPos = rand() % 255; - in.focusMode = rand() % 255; - in.filterMode = rand() % 255; - in.afRoiX0 = rand() % 255; - in.afRoiY0 = rand() % 255; - in.afRoiX1 = rand() % 255; - in.afRoiY1 = rand() % 255; - in.zoomSpeed = rand() % 255; - in.zoomHwSpeed = rand() % 255; - in.zoomHwMaxSpeed = rand() % 255; - in.focusSpeed = rand() % 255; - in.focusHwSpeed = rand() % 255; - in.focusHwMaxSpeed = rand() % 255; - in.irisSpeed = rand() % 255; - in.irisHwSpeed = rand() % 255; - in.irisHwMaxSpeed = rand() % 255; - in.zoomHwTeleLimit = rand() % 255; - in.zoomHwWideLimit = rand() % 255; - in.focusHwFarLimit = rand() % 255; - in.focusHwNearLimit = rand() % 255; - in.irisHwOpenLimit = rand() % 255; - in.irisHwCloseLimit = rand() % 255; - in.focusFactor = rand() % 255; - in.isConnected = true; - in.afHwSpeed = rand() % 255; - in.focusFactorThreshold = rand() % 255; - in.refocusTimeoutSec = rand() % 255; - in.afIsActive = true; - in.irisMode = rand() % 255; - in.autoAfRoiWidth = rand() % 255; - in.autoAfRoiHeight = rand() % 255; - in.autoAfRoiBorder = rand() % 255; - in.afRoiMode = rand() % 255; - in.extenderMode = rand() % 255; - in.stabiliserMode = rand() % 255; - in.afRange = rand() % 255; - in.xFovDeg = rand() % 255; - in.yFovDeg = rand() % 255; - in.logMode = rand() % 255; - in.temperature = rand() % 255; - in.isOpen = true; - in.type = rand() % 255; - in.custom1 = rand() % 255; - in.custom2 = rand() % 255; - in.custom3 = rand() % 255; - for (int i = 0; i < 5; ++i) - { - FovPoint pt; - pt.hwZoomPos = rand() % 255; - pt.xFovDeg = rand() % 255; - pt.yFovDeg = rand() % 255; - in.fovPoints.push_back(pt); - } + LrfParams in; + prepareRandomParams(in); // Prepare mask. - LensParamsMask mask; - mask.zoomPos = true; - mask.zoomHwPos = false; - mask.focusPos = true; - mask.focusHwPos = false; - mask.irisPos = true; - mask.irisHwPos = false; - mask.focusMode = true; - mask.filterMode = false; - mask.afRoiX0 = true; - mask.afRoiY0 = false; - mask.afRoiX1 = true; - mask.afRoiY1 = false; - mask.zoomSpeed = true; - mask.zoomHwSpeed = false; - mask.zoomHwMaxSpeed = true; - mask.focusSpeed = false; - mask.focusHwSpeed = true; - mask.focusHwMaxSpeed = false; - mask.irisSpeed = true; - mask.irisHwSpeed = false; - mask.irisHwMaxSpeed = true; - mask.zoomHwTeleLimit = false; - mask.zoomHwWideLimit = true; - mask.focusHwFarLimit = false; - mask.focusHwNearLimit = true; - mask.irisHwOpenLimit = false; - mask.irisHwCloseLimit = true; - mask.focusFactor = false; - mask.isConnected = true; - mask.afHwSpeed = false; - mask.focusFactorThreshold = true; - mask.refocusTimeoutSec = false; - mask.afIsActive = true; - mask.irisMode = false; - mask.autoAfRoiWidth = true; - mask.autoAfRoiHeight = false; - mask.autoAfRoiBorder = true; - mask.afRoiMode = false; - mask.extenderMode = true; - mask.stabiliserMode = false; - mask.afRange = true; - mask.xFovDeg = false; - mask.yFovDeg = true; + LrfParamsMask mask; + mask.distance = true; + mask.timeFromLastMeasurementUs = true; + mask.lowPowerMode = false; + mask.pointerMode = true; + mask.pointerModeTimeoutSec = false; + mask.armMode = true; + mask.operatingMode = true; + mask.continuousMeasuringMode = false; + mask.continuousModeTimeoutSec = false; mask.logMode = false; - mask.temperature = true; mask.isOpen = true; - mask.type = true; + mask.isConnected = true; + mask.minGateDistance = false; + mask.maxGateDistance = true; + mask.temperatureDeg = false; mask.custom1 = false; mask.custom2 = true; mask.custom3 = false; @@ -542,167 +275,79 @@ bool encodeDecodeParamsWithMaskTest() cout << "Encoded data size: " << size << " bytes" << endl; // Decode data. - LensParams out; + LrfParams out; if (!out.decode(data, size)) { cout << "Can't decode data" << endl; return false; } - cout << (out.isOpen ? "lens is open" : "lens is closed") << endl; - cout << (out.isConnected ? "lens is connected" : "lens not connected") << endl; - // Compare params. return compareParams(in, out, mask); } -bool compareParams(LensParams& in, LensParams& out, LensParamsMask& mask) +bool compareParams(LrfParams& in, LrfParams& out, LrfParamsMask& mask) { bool result = true; if (in.initString != out.initString) { cout << "in.initString" << endl; } - if (in.zoomPos != out.zoomPos && mask.zoomPos) - { - cout << "in.zoomPos" << endl; - result = false; - } - if (in.zoomHwPos != out.zoomHwPos && mask.zoomHwPos) - { - cout << "in.zoomHwPos" << endl; - result = false; - } - if (in.focusPos != out.focusPos && mask.focusPos) - { - cout << "in.focusPos" << endl; - result = false; - } - if (in.focusHwPos != out.focusHwPos && mask.focusHwPos) - { - cout << "in.focusHwPos" << endl; - result = false; - } - if (in.irisPos != out.irisPos && mask.irisPos) - { - cout << "in.irisPos" << endl; - result = false; - } - if (in.irisHwPos != out.irisHwPos && mask.irisHwPos) - { - cout << "in.irisHwPos" << endl; - result = false; - } - if (in.focusMode != out.focusMode && mask.focusMode) - { - cout << "in.focusMode" << endl; - result = false; - } - if (in.filterMode != out.filterMode && mask.filterMode) - { - cout << "in.filterMode" << endl; - result = false; - } - if (in.afRoiX0 != out.afRoiX0 && mask.afRoiX0) - { - cout << "in.afRoiX0" << endl; - result = false; - } - if (in.afRoiY0 != out.afRoiY0 && mask.afRoiY0) - { - cout << "in.afRoiY0" << endl; - result = false; - } - if (in.afRoiX1 != out.afRoiX1 && mask.afRoiX1) - { - cout << "in.afRoiX1" << endl; - result = false; - } - if (in.afRoiY1 != out.afRoiY1 && mask.afRoiY1) - { - cout << "in.afRoiY1" << endl; - result = false; - } - if (in.zoomSpeed != out.zoomSpeed && mask.zoomSpeed) - { - cout << "in.zoomSpeed" << endl; - result = false; - } - if (in.zoomHwSpeed != out.zoomHwSpeed && mask.zoomHwSpeed) - { - cout << "in.zoomHwSpeed" << endl; - result = false; - } - if (in.zoomHwMaxSpeed != out.zoomHwMaxSpeed && mask.zoomHwMaxSpeed) - { - cout << "in.zoomHwMaxSpeed" << endl; - result = false; - } - if (in.focusSpeed != out.focusSpeed && mask.focusSpeed) + if (in.distance != out.distance && mask.distance) { - cout << "in.focusSpeed" << endl; + cout << "in.distance" << endl; result = false; } - if (in.focusHwSpeed != out.focusHwSpeed && mask.focusHwSpeed) + if (in.timeFromLastMeasurementUs != out.timeFromLastMeasurementUs && mask.timeFromLastMeasurementUs) { - cout << "in.focusHwSpeed" << endl; + cout << "in.timeFromLastMeasurementUs" << endl; result = false; } - if (in.focusHwMaxSpeed != out.focusHwMaxSpeed && mask.focusHwMaxSpeed) + if (in.lowPowerMode != out.lowPowerMode && mask.lowPowerMode) { - cout << "in.focusHwMaxSpeed" << endl; + cout << "in.lowPowerMode" << endl; result = false; } - if (in.irisSpeed != out.irisSpeed && mask.irisSpeed) + if (in.pointerMode != out.pointerMode && mask.pointerMode) { - cout << "in.irisSpeed" << endl; + cout << "in.pointerMode" << endl; result = false; } - if (in.irisHwSpeed != out.irisHwSpeed && mask.irisHwSpeed) + if (in.pointerModeTimeoutSec != out.pointerModeTimeoutSec && mask.pointerModeTimeoutSec) { - cout << "in.irisHwSpeed" << endl; + cout << "in.pointerModeTimeoutSec" << endl; result = false; } - if (in.irisHwMaxSpeed != out.irisHwMaxSpeed && mask.irisHwMaxSpeed) + if (in.armMode != out.armMode && mask.armMode) { - cout << "in.irisHwMaxSpeed" << endl; + cout << "in.armMode" << endl; result = false; } - if (in.zoomHwTeleLimit != out.zoomHwTeleLimit && mask.zoomHwTeleLimit) + if (in.operatingMode != out.operatingMode && mask.operatingMode) { - cout << "in.zoomHwTeleLimit" << endl; + cout << "in.operatingMode" << endl; result = false; } - if (in.zoomHwWideLimit != out.zoomHwWideLimit && mask.zoomHwWideLimit) + if (in.continuousMeasuringMode != out.continuousMeasuringMode && mask.continuousMeasuringMode) { - cout << "in.zoomHwWideLimit" << endl; + cout << "in.continuousMeasuringMode" << endl; result = false; } - if (in.focusHwFarLimit != out.focusHwFarLimit && mask.focusHwFarLimit) + if (in.continuousModeTimeoutSec != out.continuousModeTimeoutSec && mask.continuousModeTimeoutSec) { - cout << "in.focusHwFarLimit" << endl; + cout << "in.continuousModeTimeoutSec" << endl; result = false; } - if (in.focusHwNearLimit != out.focusHwNearLimit && mask.focusHwNearLimit) - { - cout << "in.focusHwNearLimit" << endl; - result = false; - } - if (in.irisHwOpenLimit != out.irisHwOpenLimit && mask.irisHwOpenLimit) - { - cout << "in.irisHwOpenLimit" << endl; - result = false; - } - if (in.irisHwCloseLimit != out.irisHwCloseLimit && mask.irisHwCloseLimit) + if (in.logMode != out.logMode && mask.logMode) { - cout << "in.irisHwCloseLimit" << endl; + cout << "in.logMode" << endl; result = false; } - if (in.focusFactor != out.focusFactor && mask.focusFactor) + if (in.isOpen != out.isOpen && mask.isOpen) { - cout << "in.focusFactor" << endl; + cout << "in.isOpen" << endl; result = false; } if (in.isConnected != out.isConnected && mask.isConnected) @@ -710,94 +355,19 @@ bool compareParams(LensParams& in, LensParams& out, LensParamsMask& mask) cout << "in.isConnected" << endl; result = false; } - if (in.afHwSpeed != out.afHwSpeed && mask.afHwSpeed) + if (in.minGateDistance != out.minGateDistance && mask.minGateDistance) { - cout << "in.afHwSpeed" << endl; + cout << "in.minGateDistance" << endl; result = false; } - if (in.focusFactorThreshold != out.focusFactorThreshold && mask.focusFactorThreshold) + if (in.maxGateDistance != out.maxGateDistance && mask.maxGateDistance) { - cout << "in.focusFactorThreshold" << endl; + cout << "in.maxGateDistance" << endl; result = false; } - if (in.refocusTimeoutSec != out.refocusTimeoutSec && mask.refocusTimeoutSec) + if (in.temperatureDeg != out.temperatureDeg && mask.temperatureDeg) { - cout << "in.refocusTimeoutSec" << endl; - result = false; - } - if (in.afIsActive != out.afIsActive && mask.afIsActive) - { - cout << "in.afIsActive" << endl; - result = false; - } - if (in.irisMode != out.irisMode && mask.irisMode) - { - cout << "in.irisMode" << endl; - result = false; - } - if (in.autoAfRoiWidth != out.autoAfRoiWidth && mask.autoAfRoiWidth) - { - cout << "in.autoAfRoiWidth" << endl; - result = false; - } - if (in.autoAfRoiHeight != out.autoAfRoiHeight && mask.autoAfRoiHeight) - { - cout << "in.autoAfRoiHeight" << endl; - result = false; - } - if (in.autoAfRoiBorder != out.autoAfRoiBorder && mask.autoAfRoiBorder) - { - cout << "in.autoAfRoiBorder" << endl; - result = false; - } - if (in.afRoiMode != out.afRoiMode && mask.afRoiMode) - { - cout << "in.afRoiMode" << endl; - result = false; - } - if (in.extenderMode != out.extenderMode && mask.extenderMode) - { - cout << "in.extenderMode" << endl; - result = false; - } - if (in.stabiliserMode != out.stabiliserMode && mask.stabiliserMode) - { - cout << "in.stabiliserMode" << endl; - result = false; - } - if (in.afRange != out.afRange && mask.afRange) - { - cout << "in.afRange" << endl; - result = false; - } - if (in.xFovDeg != out.xFovDeg && mask.xFovDeg) - { - cout << "in.xFovDeg" << endl; - result = false; - } - if (in.yFovDeg != out.yFovDeg && mask.yFovDeg) - { - cout << "in.yFovDeg" << endl; - result = false; - } - if (in.logMode != out.logMode && mask.logMode) - { - cout << "in.logMode" << endl; - result = false; - } - if (in.temperature != out.temperature && mask.temperature) - { - cout << "in.temperature" << endl; - result = false; - } - if (in.isOpen != out.isOpen && mask.isOpen) - { - cout << "in.isOpen" << endl; - result = false; - } - if (in.type != out.type && mask.type) - { - cout << "in.type" << endl; + cout << "in.temperatureDeg" << endl; result = false; } if (in.custom1 != out.custom1 && mask.custom1) @@ -815,24 +385,31 @@ bool compareParams(LensParams& in, LensParams& out, LensParamsMask& mask) cout << "in.custom3" << endl; result = false; } - if (in.fovPoints.size() != out.fovPoints.size()) - { - cout << "in.fovPoints.size()" << endl; - } - else - { - for (int i = 0; i < out.fovPoints.size(); ++i) - { - if (in.fovPoints[i].hwZoomPos != out.fovPoints[i].hwZoomPos) - result = false; - if (in.fovPoints[i].xFovDeg != out.fovPoints[i].xFovDeg) - result = false; - if (in.fovPoints[i].yFovDeg != out.fovPoints[i].yFovDeg) - result = false; - } - if (!result) - cout << "in.fovPoints" << endl; - } return result; +} + + + +void prepareRandomParams(LrfParams& params) +{ + params.initString = to_string(rand() % 255) + to_string(rand() % 255); + params.distance = (float)(rand() % 255) / 100.0f; + params.timeFromLastMeasurementUs = rand() % 255; + params.lowPowerMode = rand() % 255; + params.pointerMode = rand() % 255; + params.pointerModeTimeoutSec = rand() % 255; + params.armMode = rand() % 255; + params.operatingMode = rand() % 255; + params.continuousMeasuringMode = rand() % 255; + params.continuousModeTimeoutSec = rand() % 255; + params.logMode = rand() % 255; + params.isOpen = true; + params.isConnected = true; + params.minGateDistance = (float)(rand() % 255) / 100.0f; + params.maxGateDistance = (float)(rand() % 255) / 100.0f; + params.temperatureDeg = (float)(rand() % 255) / 100.0f; + params.custom1 = (float)(rand() % 255) / 100.0f; + params.custom2 = (float)(rand() % 255) / 100.0f; + params.custom3 = (float)(rand() % 255) / 100.0f; } \ No newline at end of file