### CMakeLists.txt for 3rdparty Directory Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Example CMakeLists.txt content for a 3rdparty directory when integrating the Camera library as a submodule. This sets up the project and basic settings. ```cmake cmake_minimum_required(VERSION 3.13) ################################################################################ ## 3RD-PARTY ## dependencies for the project ################################################################################ project(3rdparty LANGUAGES CXX) ################################################################################ ## SETTINGS ## basic 3rd-party settings before use ################################################################################ ``` -------------------------------- ### Serialize Camera Parameters Without Mask Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This example demonstrates how to serialize camera parameters without using a mask, encoding all fields by default. Ensure the data buffer is sufficiently large. ```cpp // Encode data. CameraParams in; in.profile = 10; uint8_t data[1024]; int size = 0; in.encode(data, 1024, size); cout << "Encoded data size: " << size << " bytes" << endl; ``` -------------------------------- ### Get Camera Class Version Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md The getVersion() method returns the current class version as a string. It can be called without an instance of the Camera class. ```cpp static std::string getVersion(); ``` ```cpp cout << "Camera class v: " << Camera::getVersion() << endl; ``` -------------------------------- ### CMakeLists.txt Configuration for Camera Submodule Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This CMake code configures the Camera submodule, enabling it and disabling its test and example applications by default when included as a third-party library. ```cmake SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY) SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE) ################################################################################ ## CONFIGURATION ## 3rd-party submodules configuration ################################################################################ SET(${PARENT}_SUBMODULE_CAMERA ON CACHE BOOL "" FORCE) if (${PARENT}_SUBMODULE_CAMERA) SET(${PARENT}_CAMERA ON CACHE BOOL "" FORCE) SET(${PARENT}_CAMERA_TEST OFF CACHE BOOL "" FORCE) SET(${PARENT}_CAMERA_EXAMPLE OFF CACHE BOOL "" FORCE) endif() ################################################################################ ## INCLUDING SUBDIRECTORIES ## Adding subdirectories according to the 3rd-party configuration ################################################################################ if (${PARENT}_SUBMODULE_CAMERA) add_subdirectory(Camera) endif() ``` -------------------------------- ### Serialize Camera Parameters With Mask Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This example shows how to serialize camera parameters while excluding specific fields using a CameraParamsMask. Set the corresponding boolean flag in the mask to 'false' to exclude a parameter. ```cpp // Prepare params. CameraParams in; in.profile = 3; // Prepare mask. CameraParamsMask mask; mask.profile = false; // Exclude profile. Others by default. // Encode. uint8_t data[1024]; int size = 0; in.encode(data, 1024, size, &mask); cout << "Encoded data size: " << size << " bytes" << endl; ``` -------------------------------- ### Get Camera Parameter Value Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md getParam retrieves the current value of a specified camera controller parameter. This method is thread-safe. It returns -1 if the parameter does not exist. ```cpp virtual float getParam(CameraParam id) = 0; ``` -------------------------------- ### Build Camera Library with CMake Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Standard CMake commands to build the Camera library. Navigate to the Camera directory, create a build folder, and run cmake and make. ```bash cd Camera mkdir build cd build cmake .. make ``` -------------------------------- ### Project Initialization and Version Source: https://github.com/constantrobotics-ltd/camera/blob/master/example/CMakeLists.txt Initializes the CMake project with a minimum version and sets the project name and version. ```cmake cmake_minimum_required(VERSION 3.13) ############################################################################### ## INTERFACE-PROJECT ## name and version ############################################################################### project(CustomCamera VERSION 1.0.0 LANGUAGES CXX) ``` -------------------------------- ### Recommended decodeAndExecuteCommand Implementation Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md A recommended implementation of the decodeAndExecuteCommand method, demonstrating how to decode commands and delegate execution to appropriate handlers. ```cpp bool cr::camera::CustomCamera::decodeAndExecuteCommand(uint8_t* data, int size) { // Decode command. CameraCommand commandId = CameraCommand::NUC; CameraParam paramId = CameraParam::NUC_MODE; float value = 0.0f; switch (Camera::decodeCommand(data, size, paramId, commandId, value)) { // COMMAND. case 0: return executeCommand(commandId); // SET_PARAM. case 1: return setParam(paramId, value); default: return false; } return false; } ``` -------------------------------- ### Initialize Camera with Custom Parameters Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Use initCamera to initialize the camera controller with specific parameters, overriding default settings. Ensure CameraParams object is properly configured. ```cpp virtual bool initCamera(CameraParams& params) = 0; ``` -------------------------------- ### initCamera Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Initializes the camera controller with a set of parameters. This method can be used instead of openCamera when non-default parameters are required. ```APIDOC ## initCamera ### Description Initializes the camera controller with a set of parameters. This method can be used instead of openCamera when non-default parameters are required. ### Method `virtual bool initCamera(CameraParams& params) = 0;` ### Parameters #### Path Parameters - **params** (CameraParams&) - Required - CameraParams class object. CameraParams class includes initString which used in openCamera method. ### Returns - **bool** - TRUE if the camera controller is initialized or FALSE if not. ``` -------------------------------- ### Include 3rdparty Directory in Main CMakeLists.txt Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Add this line to your main CMakeLists.txt to include the 3rdparty directory, which contains the Camera module configuration. ```cmake add_subdirectory(3rdparty) ``` -------------------------------- ### Open Camera Controller Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md The openCamera(...) method initializes the camera controller with default parameters. It can be used as an alternative to initCamera(...). ```cpp virtual bool openCamera(std::string initString) = 0; ``` -------------------------------- ### Build Settings Configuration Source: https://github.com/constantrobotics-ltd/camera/blob/master/test/CMakeLists.txt Configures essential build settings including include paths, C++ standard, and output directory structure. ```cmake set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # creating output directory architecture in accordance with GNU guidelines set(BINARY_DIR "${CMAKE_BINARY_DIR}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BINARY_DIR}/bin") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BINARY_DIR}/lib") ``` -------------------------------- ### Check Camera Initialization Status Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md isCameraOpen returns true if the camera controller has been initialized. This does not guarantee active communication with the camera hardware. ```cpp virtual bool isCameraOpen() = 0; ``` -------------------------------- ### Build Settings Configuration Source: https://github.com/constantrobotics-ltd/camera/blob/master/example/CMakeLists.txt Configures essential build settings including include directories, C++ standard, symbol export for Windows, and output directory structure. ```cmake set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Enabling export of all symbols to create a dynamic library set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) # creating output directory architecture in accordance with GNU guidelines set(BINARY_DIR "${CMAKE_BINARY_DIR}") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${BINARY_DIR}/bin") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${BINARY_DIR}/lib") ``` -------------------------------- ### Source File Globbing and Library Creation Source: https://github.com/constantrobotics-ltd/camera/blob/master/example/CMakeLists.txt Globally finds all .h and .cpp files, concatenates them, and creates a static library target if it doesn't already exist. ```cmake # create glob files for *.h, *.cpp file (GLOB_RECURSE H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) file (GLOB_RECURSE CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) # concatenate the results (glob files) to variable set (SOURCES ${CPP_FILES} ${H_FILES}) # create lib from src if (NOT TARGET ${PROJECT_NAME}) add_library(${PROJECT_NAME} STATIC ${SOURCES}) endif() target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### executeCommand Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Executes a camera controller action command. This method must be thread-safe. ```APIDOC ## executeCommand method ### Description Executes a camera controller action command. The implementation must provide a thread-safe `executeCommand(...)` method. ### Method Signature ```cpp virtual bool executeCommand(CameraCommand id) = 0; ``` ### Parameters #### Path Parameters - **id** (CameraCommand) - Required - Camera action command ID according to [CameraCommand](#cameracommand-enum) enum. ### Returns - **bool** - TRUE if the command was executed (accepted by controller) or FALSE if not. ``` -------------------------------- ### isCameraOpen Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Returns the camera initialization status. Open status indicates if the camera controller is initialized, but not necessarily if it has active communication with the camera equipment. ```APIDOC ## isCameraOpen ### Description Returns the camera initialization status. Open status indicates if the camera controller is initialized, but not necessarily if it has active communication with the camera equipment. ### Method `virtual bool isCameraOpen() = 0;` ### Returns - **bool** - TRUE if the camera controller is initialized or FALSE if not. ``` -------------------------------- ### Read and Write Camera Parameters to JSON Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Utilize the ConfigReader library to write Camera parameters to a JSON file and subsequently read them back. Ensure the file path is correct for reading operations. ```cpp // Write params to file. cr::utils::ConfigReader inConfig; inConfig.set(in, "cameraParams"); inConfig.writeToFile("TestCameraParams.json"); // Read params from file. cr::utils::ConfigReader outConfig; if(!outConfig.readFromFile("TestCameraParams.json")) { cout << "Can't open config file" << endl; return false; } ``` -------------------------------- ### Camera Command Execution Interface Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Defines the interface for executing camera controller actions. Implementations must be thread-safe. ```cpp virtual bool executeCommand(CameraCommand id) = 0; ``` -------------------------------- ### CameraParams Field: initString Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md The initialization string for a camera controller. It's recommended to use ';' to divide parts. For serial port controllers, a common format is '/dev/ttyUSB0;9600;100' (serial port, baudrate, timeout). ```markdown | Field | type | Description | | ---------------------------- | ------ | ------------------------------------------------------------ | | initString | string | Initialization string. Particular camera controller can have unique init string format. But it is recommended to use '**;**' symbol to divide part of initialization string. Recommended camera controller initialization string for controllers which uses serial port: **"/dev/ttyUSB0;9600;100"** ("/dev/ttyUSB0" - serial port name, "9600" - baudrate, "100" - serial port read timeout). | ``` -------------------------------- ### Camera::openCamera Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Initializes the camera controller with default parameters using an initialization string. This can be used as an alternative to initCamera. ```APIDOC ## Camera::openCamera ### Description Initializes the camera controller. All camera parameters will be initialized by default. This method can be used instead of initCamera(...). ### Method `virtual bool openCamera(std::string initString) = 0;` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### Parameters - **initString** (std::string) - Required - Initialization string. Particular camera controller can have unique initialization string format. But it is recommended to use '**;**' symbol to divide part of initialization string. Recommended camera controller initialization string for controllers which use serial port: "/dev/ttyUSB0;9600;100" ("/dev/ttyUSB0" - serial port name, "9600" - baudrate, "100" - serial port read timeout). ### Request Example ```cpp std::string init = "/dev/ttyUSB0;9600;100"; camera->openCamera(init); ``` ### Response #### Success Response (true) Returns TRUE if the camera controller is initialized. #### Error Response (false) Returns FALSE if the camera controller is not initialized. #### Response Example ```cpp bool success = camera->openCamera(init); ``` ``` -------------------------------- ### File Globbing and Configuration Source: https://github.com/constantrobotics-ltd/camera/blob/master/example/CMakeLists.txt Uses file globbing to find header files and configure them into a version header file. ```cmake file (GLOB_RECURSE IN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h.in) configure_file(${IN_FILES} ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Version.h) ``` -------------------------------- ### Abstract decodeAndExecuteCommand Method Signature Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This is the abstract method signature for decoding and executing commands. The camera controller implementation must ensure this method is thread-safe. ```cpp virtual bool decodeAndExecuteCommand(uint8_t* data, int size) = 0; ``` -------------------------------- ### Linking Libraries Source: https://github.com/constantrobotics-ltd/camera/blob/master/test/CMakeLists.txt Links the project's executable target with the 'Camera' library. ```cmake target_link_libraries(${PROJECT_NAME} Camera) ``` -------------------------------- ### Executable Target Creation Source: https://github.com/constantrobotics-ltd/camera/blob/master/test/CMakeLists.txt Creates an executable target by globbing source and header files and adding them to the target. ```cmake # create glob files for *.h, *.cpp file (GLOB H_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.h) file (GLOB CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) # concatenate the results (glob files) to variable set (SOURCES ${CPP_FILES} ${H_FILES}) if (NOT TARGET ${PROJECT_NAME}) add_executable(${PROJECT_NAME} ${SOURCES}) endif() ``` -------------------------------- ### Add Camera Library as a Git Submodule Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Integrate the Camera library into your CMake project by adding it as a Git submodule. Update the submodule after adding it. ```bash cd git submodule add https://github.com/ConstantRobotics-Ltd/Camera.git 3rdparty/Camera git submodule update --init --recursive ``` -------------------------------- ### Project Definition Source: https://github.com/constantrobotics-ltd/camera/blob/master/test/CMakeLists.txt Defines the project name and the primary programming language used. ```cmake cmake_minimum_required(VERSION 3.13) ################################################################################ ## EXECUTABLE-PROJECT ## name and version ################################################################################ project(CameraDataStructuresTest LANGUAGES CXX) ``` -------------------------------- ### CameraParams Class Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This C++ code declares the CameraParams class, which encapsulates a wide range of configurable parameters for camera devices. It includes settings for initialization, image dimensions, display modes, video output, logging, exposure, white balance, dynamic range, stabilization, ISO, scene mode, FPS, brightness, contrast, gain, sharpening, palette, AGC, shutter, digital zoom, exposure compensation, defog, dehaze, noise reduction, black and white filter, and NUC for thermal cameras. Default values are provided for many parameters. ```cpp namespace cr { namespace camera { class CameraParams { public: /// Initialization string. Formats depends on implementation. std::string initString{"/dev/ttyUSB0;9600;20"}; /// Video frame width. Value from 0 to 16384. int width{0}; /// Video frame height Value from 0 to 16384. int height{0}; /// Display menu mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Off. 1 - On. int displayMode{0}; /// Video output type. Value depends on implementation. int videoOutput{0}; /// Logging mode. Values: 0 - Disable, 1 - Only file, /// 2 - Only terminal (console), 3 - File and terminal. int logMode{0}; /// Exposure mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Manual, 1 - Auto (default), /// 2 - Shutter priority, 3 - Aperture priority. int exposureMode{1}; /// Exposure time of the camera sensor. The exposure time is limited by the /// frame interval. Camera controller should interpret the values as 100 µs /// units, where the value 1 stands for 1/10000th of a second, 10000 for /// 1 second and 100000 for 10 seconds. int exposureTime{0}; /// White balance mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Manual, 1 - Auto. int whiteBalanceMode{1}; /// White balance area. Value depends on implementation. int whiteBalanceArea{0}; /// White dynamic range mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. int wideDynamicRangeMode{0}; /// Image stabilization mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. int stabilizationMode{0}; /// ISO sensitivity. Value depends on implementation. int isoSensitivity{0}; /// Scene mode. Value depends on implementation. int sceneMode{0}; /// FPS. float fps{0.0f}; /// Brightness mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Manual, 1 - Auto. int brightnessMode{1}; /// Brightness. Value 0 - 100%. int brightness{0}; /// Contrast. Value 1 - 100%. int contrast{0}; /// Gain mode. Value depends on implementation but it is recommended to keep /// default values: 0 - Manual, 1 - Auto. int gainMode{1}; /// Gain. Value 1 - 100%. int gain{0}; /// Sharpening mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Manual, 1 - Auto. int sharpeningMode{0}; /// Sharpening. Value 1 - 100%. int sharpening{0}; /// Palette. Value depends on implementation but it is recommended to keep /// default values for thermal cameras: 0 - White hot, 1 - Black hot. int palette{0}; /// Analog gain control mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Manual, 1 - Auto. int agcMode{1}; /// Shutter mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Manual, 1 - Auto. int shutterMode{1}; /// Shutter position. 0 (full close) - 65535 (full open). int shutterPos{0}; /// Shutter speed. Value: 0 - 100%. int shutterSpeed{0}; /// Digital zoom mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Off, 1 - On. int digitalZoomMode{0}; /// Digital zoom. Value 1.0 (x1) - 20.0 (x20). float digitalZoom{1.0f}; /// Exposure compensation mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. int exposureCompensationMode{0}; /// Exposure compensation position. Value depends on particular camera /// controller. int exposureCompensationPosition{0}; /// Defog mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Off, 1 - On. int defogMode{0}; /// Dehaze mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Off, 1 - On. int dehazeMode{0}; /// Noise reduction mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - 2D, 3 - 3D. int noiseReductionMode{0}; /// Black and white filter mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. int blackAndWhiteFilterMode{0}; /// Filter mode. Value depends on implementation. int filterMode{0}; /// NUC mode for thermal cameras. Value depends on implementation but it is /// recommended to keep default values: 0 - Manual, 1 - Auto. int nucMode{0}; /// Auto NUC interval for thermal cameras. Value in milliseconds /// from 0 (Off) to 100000. }; } } ``` -------------------------------- ### Deserialize Camera Parameters Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Use the decode method to deserialize camera parameters from a byte buffer. Ensure the data buffer and size are correctly provided. This method does not decode the initString field. ```cpp bool decode(uint8_t* data, int dataSize); ``` ```cpp // Encode data. CameraParams in; uint8_t data[1024]; int size = 0; in.encode(data, 1024, size); cout << "Encoded data size: " << size << " bytes" << endl; // Decode data. CameraParams out; if (!out.decode(data, size)) cout << "Can't decode data" << endl; ``` -------------------------------- ### Encode Camera Action Command Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Encodes a command to perform an action on the remote camera. Used on the client side to prepare data for transmission. The buffer must be at least 7 bytes. ```cpp static void encodeCommand(uint8_t* data, int& size, CameraCommand id); ``` ```cpp // Buffer for encoded data. uint8_t data[7]; // Size of encoded data. int size = 0; // Encode command. Camera::encodeCommand(data, size, CameraCommand::NUC); ``` -------------------------------- ### encodeCommand Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Encodes an action command for camera remote control. Used on the client side. ```APIDOC ## encodeCommand method ### Description Encodes a COMMAND command (action command) for camera remote control. This static method is used on the client side to design a custom protocol for remote camera control. ### Method Signature ```cpp static void encodeCommand(uint8_t* data, int& size, CameraCommand id); ``` ### Parameters #### Path Parameters - **data** (uint8_t*) - Required - Pointer to data buffer for encoded command. Must have size >= 7. - **size** (int&) - Required - Size of encoded data. Will be 7 bytes. - **id** (CameraCommand) - Required - Command ID according to [CameraCommand](#cameracommand-enum) enum. ### Request Example ```cpp // Buffer for encoded data. uint8_t data[7]; // Size of encoded data. int size = 0; // Encode command. Camera::encodeCommand(data, size, CameraCommand::NUC); ``` ``` -------------------------------- ### Camera::getVersion Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Retrieves the version string of the Camera class. This is a static method and can be called without an instance of the Camera class. ```APIDOC ## Camera::getVersion ### Description Retrieves the version string of the current Camera class. ### Method `static std::string getVersion();` ### Usage This method can be called directly on the class without an instance. ### Example ```cpp cout << "Camera class v: " << Camera::getVersion() << endl; ``` ### Response Example ```bash Camera class v: 2.5.4 ``` ``` -------------------------------- ### CameraParams Field: logMode Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Configures the logging mode. Options include Disable (0), Only file (1), Only terminal (2), and File and terminal (3). ```markdown | Field | type | Description | | ---------------------------- | ------ | ------------------------------------------------------------ | | logMode | int | Logging mode. Values: **0** - Disable, **1** - Only file, **2** - Only terminal (console), **3** - File and terminal. | ``` -------------------------------- ### getParams Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Obtains camera parameters. This method is thread-safe and can be called from any thread. ```APIDOC ## getParams ### Description Obtains camera parameters. This method is thread-safe and can be called from any thread. ### Method `virtual void getParams(CameraParams& params) = 0;` ### Parameters #### Path Parameters - **params** (CameraParams&) - Output - CameraParams class object. ``` -------------------------------- ### decodeCommand Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Decodes a command on the camera controller side, which was encoded by encodeSetParamCommand or encodeCommand. ```APIDOC ## decodeCommand method ### Description Decodes a command on the camera controller side that was previously encoded by `encodeSetParamCommand(...)` or `encodeCommand(...)`. ### Method Signature ```cpp static int decodeCommand(uint8_t* data, int size, CameraParam& paramId, CameraCommand& commandId, float& value); ``` ### Parameters #### Path Parameters - **data** (uint8_t*) - Required - Pointer to input command. - **size** (int) - Required - Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND. - **paramId** (CameraParam&) - Output - Camera parameter ID according to [CameraParam](#cameraparam-enum) enum. After decoding SET_PARAM command, the method will return parameter ID. - **commandId** (CameraCommand&) - Output - Camera command ID according to [CameraCommand](#cameracommand-enum) enum. After decoding COMMAND, the method will return command ID. - **value** (float&) - Output - Camera parameter value (after decoding SET_PARAM command). ### Returns - **int** - **0** - in case decoding COMMAND, **1** - in case decoding SET_PARAM command or **-1** in case errors. ``` -------------------------------- ### CameraParams Field: displayMode Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Controls the display menu mode. Recommended default value is 0 (Off), with 1 (On) as an alternative. ```markdown | Field | type | Description | | ---------------------------- | ------ | ------------------------------------------------------------ | | displayMode | int | Display menu mode. Value depends on implementation but it is recommended to keep default values: **0** - Off. **1** - On. | ``` -------------------------------- ### isCameraConnected Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Returns the camera connection status. Connection status indicates if the camera controller has data exchange with the camera equipment. Returns FALSE if the controller is not initialized. ```APIDOC ## isCameraConnected ### Description Returns the camera connection status. Connection status indicates if the camera controller has data exchange with the camera equipment. Returns FALSE if the controller is not initialized. ### Method `virtual bool isCameraConnected() = 0;` ### Returns - **bool** - TRUE if the camera controller has data exchange with camera equipment or FALSE if not. ``` -------------------------------- ### CustomCamera Class Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This C++ code defines the structure for a custom camera controller. You must implement all methods of the base Camera interface class. ```cpp namespace cr { namespace camera { /** * @brief Custom camera controller class. */ class CustomCamera: public Camera { public: /// Class constructor. CustomCamera(); /// Class destructor. ~CustomCamera(); /// Get class version. static std::string getVersion(); /// Open camera controller. bool openCamera(std::string initString) override; /// Init camera controller by set of parameters. bool initCamera(CameraParams& params) override; /// Close camera connection. void closeCamera() override; /// Get camera open status. bool isCameraOpen() override; /// Get camera open status. bool isCameraConnected() override; /// Set the camera controller param. bool setParam(CameraParam id, float value) override; /// Get the camera controller param. float getParam(CameraParam id) override; /// Get the camera controller params. void getParams(CameraParams& params) override; /// Execute camera controller command. bool executeCommand(CameraCommand id) override; /// Decode and execute command. bool decodeAndExecuteCommand(uint8_t* data, int size) override; private: /// Parameters structure (default params). CameraParams m_params; }; } } ``` -------------------------------- ### CameraParams Field: width and height Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Specifies the video frame width and height. The allowed values range from 0 to 16384. ```markdown | Field | type | Description | | ---------------------------- | ------ | ------------------------------------------------------------ | | width | int | Video frame width. Value from 0 to 16384. | | height | int | Video frame height Value from 0 to 16384. | ``` -------------------------------- ### Retrieve All Camera Parameters Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md getParams populates a CameraParams object with all current camera controller parameters. This method is thread-safe and can be called from any thread. ```cpp virtual void getParams(CameraParams& params) = 0; ``` -------------------------------- ### encodeSetParamCommand Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Encodes a command to change a remote camera parameter. Used on the client side. ```APIDOC ## encodeSetParamCommand method ### Description Encodes a SET_PARAM command to change any remote camera parameter. This static method is used on the client side to design a custom protocol for remote camera control. ### Method Signature ```cpp static void encodeSetParamCommand(uint8_t* data, int& size, CameraParam id, float value); ``` ### Parameters #### Path Parameters - **data** (uint8_t*) - Required - Pointer to data buffer for encoded command. Must have size >= 11. - **size** (int&) - Required - Size of encoded data. Will be 11 bytes. - **id** (CameraParam) - Required - Parameter ID according to [CameraParam](#cameraparam-enum) enum. - **value** (float) - Required - Parameter value. ### Request Example ```cpp // Buffer for encoded data. uint8_t data[11]; // Size of encoded data. int size = 0; // Random parameter value. float outValue = (float)(rand() % 20); // Encode command. Camera::encodeSetParamCommand(data, size, CameraParam::ROI_X0, outValue); ``` ``` -------------------------------- ### Encode Camera Parameter Change Command Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Encodes a command to change a remote camera parameter. Used on the client side to prepare data for transmission. The buffer must be at least 11 bytes. ```cpp static void encodeSetParamCommand(uint8_t* data, int& size, CameraParam id, float value); ``` ```cpp // Buffer for encoded data. uint8_t data[11]; // Size of encoded data. int size = 0; // Random parameter value. float outValue = (float)(rand() % 20); // Encode command. Camera::encodeSetParamCommand(data, size, CameraParam::ROI_X0, outValue); ``` -------------------------------- ### Decode Camera Command Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Decodes commands on the camera controller side, whether they are parameter changes or actions. Returns 0 for COMMAND, 1 for SET_PARAM, and -1 for errors. ```cpp static int decodeCommand(uint8_t* data, int size, CameraParam& paramId, CameraCommand& commandId, float& value); ``` -------------------------------- ### CameraParam Enum Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Defines the enumeration for camera parameters. Each enum value corresponds to a specific camera setting with associated value ranges or modes described in comments. ```cpp namespace cr { namespace camera { enum class CameraParam { /// Video frame width. Value from 0 to 16384. WIDTH = 1, /// Video frame height Value from 0 to 16384. HEIGHT, /// Display menu mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Off. 1 - On. DISPLAY_MODE, /// Video output type. Value depends on implementation. VIDEO_OUTPUT, /// Logging mode. Values: 0 - Disable, 1 - Only file, /// 2 - Only terminal (console), 3 - File and terminal. LOG_MODE, /// Exposure mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Manual, 1 - Auto (default), /// 2 - Shutter priority, 3 - Aperture priority. EXPOSURE_MODE, /// Exposure time of the camera sensor. The exposure time is limited by the /// frame interval. Camera controller should interpret the values as 100 µs /// units, where the value 1 stands for 1/10000th of a second, 10000 for /// 1 second and 100000 for 10 seconds. EXPOSURE_TIME, /// White balance mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Manual, 1 - Auto. WHITE_BALANCE_MODE, /// White balance area. Value depends on implementation. WHITE_BALANCE_AREA, /// White dynamic range mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. WIDE_DYNAMIC_RANGE_MODE, /// Image stabilization mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. STABILIZATION_MODE, /// ISO sensitivity. Value depends on implementation. ISO_SENSITIVITY, /// Scene mode. Value depends on implementation. SCENE_MODE, /// FPS. FPS, /// Brightness mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Manual, 1 - Auto. BRIGHTNESS_MODE, /// Brightness. Value 0 - 100%. BRIGHTNESS, /// Contrast. Value 1 - 100%. CONTRAST, /// Gain mode. Value depends on implementation but it is recommended to keep /// default values: 0 - Manual, 1 - Auto. GAIN_MODE, /// Gain. Value 1 - 100%. GAIN, /// Sharpening mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Manual, 1 - Auto. SHARPENING_MODE, /// Sharpening. Value 1 - 100%. SHARPENING, /// Palette. Value depends on implementation but it is recommended to keep /// default values for thermal cameras: 0 - White hot, 1 - Black hot. PALETTE, /// Analog gain control mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Manual, 1 - Auto. AGC_MODE, /// Shutter mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Manual, 1 - Auto. SHUTTER_MODE, /// Shutter position. 0 (full close) - 65535 (full open). SHUTTER_POSITION, /// Shutter speed. Value: 0 - 100%. SHUTTER_SPEED, /// Digital zoom mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Off, 1 - On. DIGITAL_ZOOM_MODE, /// Digital zoom. Value 1.0 (x1) - 20.0 (x20). DIGITAL_ZOOM, /// Exposure compensation mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. EXPOSURE_COMPENSATION_MODE, /// Exposure compensation position. Value depends on particular camera /// controller. EXPOSURE_COMPENSATION_POSITION, /// Defog mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Off, 1 - On. DEFOG_MODE, /// Dehaze mode. Value depends on implementation but it is recommended to /// keep default values: 0 - Off, 1 - On. DEHAZE_MODE, /// Noise reduction mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - 2D, 3 - 3D. NOISE_REDUCTION_MODE, /// Black and white filter mode. Value depends on implementation but it is /// recommended to keep default values: 0 - Off, 1 - On. BLACK_WHITE_FILTER_MODE, /// Filter mode. Value depends on implementation. FILTER_MODE, /// NUC mode for thermal cameras. Value depends on implementation but it is /// recommended to keep default values: 0 - Manual, 1 - Auto. NUC_MODE, /// Auto NUC interval for thermal cameras. Value in milliseconds /// from 0 (Off) to 100000. AUTO_NUC_INTERVAL_MSEC, /// Image flip mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Off, 1 - Horizontal, 2 - Vertical, /// 3 - Horizontal and vertical. IMAGE_FLIP, /// DDE mode. Value depends on implementation but it is recommended to keep /// default values: 0 - Off, 1 - On. DDE_MODE, /// DDE level. Value depends on implementation. DDE_LEVEL }; } } ``` -------------------------------- ### Camera Class Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md The Camera interface class is declared in Camera.h. It defines methods for controlling camera operations. ```cpp namespace cr { namespace camera { /// Camera controller interface class. class Camera { public: /// Class destructor. virtual ~Camera(); /// Get Camera class version. static std::string getVersion(); /// Open camera controller. virtual bool openCamera(std::string initString) = 0; /// Init camera controller by set of parameters. virtual bool initCamera(CameraParams& params) = 0; /// Close camera connection. virtual void closeCamera() = 0; /// Get camera open status. virtual bool isCameraOpen() = 0; /// Get camera open status. virtual bool isCameraConnected() = 0; /// Set the camera controller parameter. virtual bool setParam(CameraParam id, float value) = 0; /// Get the camera controller parameter. virtual float getParam(CameraParam id) = 0; /// Get all camera controller parameters. virtual void getParams(CameraParams& params) = 0; /// Execute camera controller action command. virtual bool executeCommand(CameraCommand id) = 0; /// Encode set param command. static void encodeSetParamCommand( uint8_t* data, int& size, CameraParam id, float value); /// Encode command. static void encodeCommand( uint8_t* data, int& size, CameraCommand id); /// Decode command. static int decodeCommand(uint8_t* data, int size, CameraParam& paramId, CameraCommand& commandId, float& value); /// Decode and execute command. virtual bool decodeAndExecuteCommand(uint8_t* data, int size) = 0; }; } } ``` -------------------------------- ### CameraCommand Enum Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Declaration of the CameraCommand enumeration, which defines the various action commands that can be sent to the camera controller. ```cpp namespace cr { namespace camera { enum class CameraCommand { /// Restart camera controller. RESTART = 1, /// Do NUC. NUC, /// Apply settings. APPLY_PARAMS, /// Save params. SAVE_PARAMS, /// Menu on. MENU_ON, /// Menu off. MENU_OFF, /// Menu set. MENU_SET, /// Menu up. MENU_UP, /// Menu down. MENU_DOWN, /// Menu left. MENU_LEFT, /// Menu right. MENU_RIGHT, /// Freeze, Argument: time msec. FREEZE, /// Disable freeze. DEFREEZE }; } } ``` -------------------------------- ### getParam Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Returns the controller parameter value. This method is thread-safe and can be called from any thread. ```APIDOC ## getParam ### Description Returns the controller parameter value. This method is thread-safe and can be called from any thread. ### Method `virtual float getParam(CameraParam id) = 0;` ### Parameters #### Path Parameters - **id** (CameraParam) - Required - Camera controller parameter ID according to CameraParam enum. ### Returns - **float** - Parameter value or -1 if the parameters doesn't exist in the particular camera controller. ``` -------------------------------- ### CameraParams Field: exposureMode Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Sets the exposure mode. Recommended defaults are Manual (0) and Auto (1). Other options include Shutter priority (2) and Aperture priority (3). ```markdown | Field | type | Description | | ---------------------------- | ------ | ------------------------------------------------------------ | | exposureMode | int | Exposure mode. Value depends on implementation but it is recommended to keep default values: **0** - Manual, **1** - Auto (default), **2** - Shutter priority, **3** - Aperture priority. | ``` -------------------------------- ### CameraParams Structure Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md This structure defines the flags for each field within the CameraParams class, used to control which parameters are included during serialization. ```cpp typedef struct CameraParamsMask { bool width{true}; bool height{true}; bool displayMode{true}; bool videoOutput{true}; bool logMode{true}; bool exposureMode{true}; bool exposureTime{true}; bool whiteBalanceMode{true}; bool whiteBalanceArea{true}; bool wideDynamicRangeMode{true}; bool stabilizationMode{true}; bool isoSensitivity{true}; bool sceneMode{true}; bool fps{true}; bool brightnessMode{true}; bool brightness{true}; bool contrast{true}; bool gainMode{true}; bool gain{true}; bool sharpeningMode{true}; bool sharpening{true}; bool palette{true}; bool agcMode{true}; bool shutterMode{true}; bool shutterPos{true}; bool shutterSpeed{true}; bool digitalZoomMode{true}; bool digitalZoom{true}; bool exposureCompensationMode{true}; bool exposureCompensationPosition{true}; bool defogMode{true}; bool dehazeMode{true}; bool noiseReductionMode{true}; bool blackAndWhiteFilterMode{true}; bool filterMode{true}; bool nucMode{true}; bool autoNucIntervalMsec{true}; bool imageFlip{true}; bool ddeMode{true}; bool ddeLevel{true}; bool roiX0{true}; bool roiY0{true}; bool roiX1{true}; bool roiY1{true}; bool temperature{true}; bool alcGate{true}; bool sensitivity{true}; bool changingMode{true}; bool changingLevel{true}; bool chromaLevel{true}; bool detail{true}; bool profile{true}; bool isConnected{true}; bool isOpen{true}; bool type{true}; bool custom1{true}; bool custom2{true}; bool custom3{true}; } CameraParamsMask; ``` -------------------------------- ### CameraParams Class Declaration Source: https://github.com/constantrobotics-ltd/camera/blob/master/README.md Declaration of the CameraParams class, outlining its various member variables for camera configuration and status. ```cpp class CameraParams { int autoNucIntervalMsec{0}; /// Image flip mode. Value depends on implementation but it is recommended /// to keep default values: 0 - Off, 1 - Horizontal, 2 - Vertical, /// 3 - Horizontal and vertical. int imageFlip{0}; /// DDE mode. Value depends on implementation but it is recommended to keep /// default values: 0 - Off, 1 - On. int ddeMode{0}; /// DDE level. Value depends on implementation. float ddeLevel{0}; /// ROI top-left horizontal position, pixels. int roiX0{0}; /// ROI top-left vertical position, pixels. int roiY0{0}; /// ROI bottom-right horizontal position, pixels. int roiX1{0}; /// ROI bottom-right vertical position, pixels. int roiY1{0}; /// Camera temperature, degree. float temperature{0.0f}; /// ALC gate. Value depends on implementation. int alcGate{0}; /// Sensor sensitivity. Value depends on implementation. float sensitivity{0}; /// Changing mode (day / night). Value depends on implementation. int changingMode{0}; /// Changing level (day / night). Value depends on implementation. float changingLevel{0.0f}; /// Chroma level. Values: 0 - 100%. int chromaLevel{0}; /// Details, enhancement. Values: 0 - 100%. int detail{0}; /// Camera settings profile. Value depends on implementation. int profile{0}; /// Connection status (read only). Shows if we have response from camera. /// Value: false - not connected, true - connected. bool isConnected{false}; /// Open status (read only): /// true - camera control port open, false - not open. bool isOpen{false}; /// Camera type. Value depends on implementation. int type{0}; /// Camera custom param. Value depends on implementation. float custom1{0.0f}; /// Camera custom param. Value depends on implementation. float custom2{0.0f}; /// Camera custom param. Value depends on implementation. float custom3{0.0f}; JSON_READABLE(CameraParams, initString, width, height, displayMode, videoOutput, logMode, exposureMode, exposureTime, whiteBalanceMode, whiteBalanceArea, wideDynamicRangeMode, stabilizationMode, isoSensitivity, sceneMode, fps, brightnessMode, brightness, contrast, gainMode, gain, sharpeningMode, sharpening, palette, agcMode, shutterMode, shutterPos, shutterSpeed, digitalZoomMode, digitalZoom, exposureCompensationMode, exposureCompensationPosition, defogMode, dehazeMode, noiseReductionMode, blackAndWhiteFilterMode, filterMode, nucMode, autoNucIntervalMsec, imageFlip, ddeMode, ddeLevel, roiX0, roiY0, roiX1, roiY1, alcGate, sensitivity, changingMode, changingLevel, chromaLevel, detail, profile, type, custom1, custom2, custom3) /// operator = CameraParams& operator= (const CameraParams& src); /// Encode params. bool encode(uint8_t* data, int bufferSize, int& size, CameraParamsMask* mask = nullptr); /// Decode params. bool decode(uint8_t* data, int dataSize); }; ```