g5camera_web_logo

G5Camera C++ library

v2.7.0

Table of contents

Overview

The G5Camera C++ library is a software controller for G5 cameras. G5 cameras combine a lens and a camera (image sensor) and provide a single control interface (serial port). The G5Camera library inherits from the Lens and Camera interfaces. It depends on the following libraries: Lens (provides interface and data structures to control lenses), Camera (provides interface and data structures to control cameras), Logger (provides functions to print logs), SerialPort (provides functions to work with serial ports) and G5ProtocolParser library (provides functions to encode control commands for G5 cameras; it is a part of this repository: folder src/parser, see src/parser/README.md). The Lens library depends on the Frame and ConfigReader libraries, the Camera library depends on the ConfigReader library. The other dependencies are separate repositories: the G5Camera repository does not contain them (see Build and connect to your project). The G5Camera library provides a simple interface to be integrated into any C++ project. The library is supplied as source code and has no third-party dependencies that need to be specially installed in the OS. It is developed with the C++17 standard and is compatible with Linux and Windows.

G5Camera is general-purpose software: it is not tied to any sector or application, and the developer of a program decides what the program does with it.

The library code was developed by reverse engineering the serial port communication protocol of the cameras.

Versions

Table 1 - Library versions.

Version Release date What’s new
1.0.0 03.04.2023 - First version.
2.0.0 10.01.2024 - Parser updated.
- Documentation added.
2.0.1 23.04.2024 - Documentation updated.
- Code optimized.
2.0.2 24.05.2024 - Documentation updated.
- Submodules updated.
2.0.3 07.08.2024 - CMake structure updated.
2.0.4 10.09.2024 - Add SCENE_MODE parameter to control AGC ROI.
2.0.5 29.09.2024 - Add vertical FOV calculation.
- Fixed camera overlay auto off.
2.0.6 21.10.2024 - Fix auto NUC interval control.
2.0.7 25.11.2024 - Update supporting camera params.
- Add turbulence mitigation parameters control.
2.0.8 16.01.2025 - Add new mechanism of camera reconnection.
2.1.0 28.03.2025 - General clean up. Fix vertical FOV calculation.
2.1.1 07.05.2025 - Fix gain range conversion.
2.2.0 21.06.2025 - Add commands to control time constant for AGC and focusing distance.
- G5ProtocolParser submodule update.
2.2.1 19.09.2025 - Add default scene mode value 1.
2.2.2 25.10.2025 - Documentation fixes.
- G5ProtocolParser submodules update.
- SerialPort submodules update.
2.2.3 02.12.2025 - Add continuous auto focus.
2.3.0 11.03.2026 - Add AGC ROI control commands.
- Fixed mistakes in documentation.
2.4.0 17.03.2026 - Add focus hardware position report.
2.5.0 23.05.2026 - Send zoom/focus commands (ZOOM_TELE/WIDE/STOP/TO_POS, FOCUS_FAR/NEAR/STOP/TO_POS) immediately, bypassing the outgoing command buffer.
- Added a dedicated mutex to protect all serial port writes.
- Fixed thread-safety: initLens() now updates fovPoints under the lens-params mutex.
2.5.1 30.06.2026 - Added protection for sending command to camera before camera initialization.
2.6.0 30.06.2026 - Critical bugs fixed.
2.6.1 09.07.2026 - Added timeout after camera restart command.
2.6.2 10.07.2026 - Added the ability to restart the lens controller.
- Added gain level synchronization.
2.6.3 28.07.2026 - Removed auto AGC ROI position apply to prevent unexpected behavior.
2.6.4 10.09.2026 - Fixed auto NUC control: AUTOCALINT is now sent before AUTOCAL:ON and auto calibration is re-armed when AUTO_NUC_INTERVAL_MSEC changes.
2.6.5 21.09.2026 - Allow changing the ROI without modifying all four parameters.
- Fixed the ROI X and Y parameters.
- Allow selecting a custom ROI via SCENE_MODE.
2.6.6 24.09.2026 - Fixed AF mode restoration.
2.6.7 09.10.2026 - Added <INIT response check as a valid response of an initialized device.
- Added BRIGHTNESS parameter (manual level control, MLC).
- Extended AUTO_NUC_INTERVAL_MSEC range to 1000-32767000 ms.
- Fixed GAIN restoring on initialization: it is restored when AGC_MODE is 0 (Manual).
- GAIN_MODE and AGC_MODE are now handled identically (both send AGLC and stay in sync).
- CUSTOM_1 (TM ROI) defaults to 1 on first initialization.
- FOCUS_HW_FAR_LIMIT (focusing distance) minimum value is 1.
2.6.8 12.10.2026 - Submodules updated.
- Added missing standard library includes.
2.6.9 13.10.2026 - Set initial focus and zoom speeds to 100.
2.6.10 19.10.2026 - Git sub-repositories removed: the dependencies are cloned next to the repository.
- Float values of setParam(…) and executeCommand(…) are converted to integers with a check: NaN, infinity and values outside of the int range are rejected (this includes SCENE_MODE).
- Added range check of the zoom, focus, FOV, distance, gain, brightness and working hours values received from the camera: a value outside of the range is ignored.
- decodeAndExecuteCommand(…) rejects a null pointer.
- Serial port is accessed under one mutex (reading and writing from different threads).
- openCamera(…), openLens(…) and the close methods are executed one after another; a failed start of the communication thread is reported (FALSE is returned).
- The baudrate of the init string must be positive; the serial port name must not contain the NUL character.
- A command which decodeAndExecuteCommand(…) can not decode is written to the log in accordance with the log mode.
- The communication thread stops without waiting for the end of its pauses; the periodic working hours request does not depend on the system clock.
- Unnamed parameter of addVideoFrame(…), deleted copy and move operations of G5Camera.
- Added compiler warnings and exploit mitigation options to the CMake files.
- Test application: fixed memory leak, the end of the input, wrong values and the sensitivity option, added exit option.
- Documentation updated.
2.6.11 25.10.2026 - The library links the thread library (CMake target Threads::Threads): programs built on a C library older than glibc 2.34 no longer need -pthread.
2.7.0 29.10.2026 - The G5ProtocolParser library is a part of the repository (folder src/parser) and is not a separate dependency any more.

Library files

The library is supplied as source code only. The user is provided with a set of files in the form of a CMake project (repository). Except the protocol parser G5ProtocolParser (folder src/parser), the repository does not contain the source code of the libraries it depends on (see Build and connect to your project). The repository structure is shown below:

CMakeLists.txt ----------------------------- Main CMake file of the library.
static ------------------------------------- Folder with images of this document.
test --------------------------------------- Folder with test application.
    CMakeLists.txt ------------------------- CMake file for test application.
    main.cpp ------------------------------- Source code file of test application.
src ---------------------------------------- Folder with source code of the library.
    CMakeLists.txt ------------------------- CMake file of the library.
    G5Camera.cpp --------------------------- C++ implementation file.
    G5Camera.h ----------------------------- Header file which includes G5Camera class declaration.
    G5CameraVersion.h ---------------------- Header file which includes version of the library.
    G5CameraVersion.h.in ------------------- CMake service file to generate version file.
    parser --------------------------------- Protocol parser library (former G5ProtocolParser repository).
        .gitignore ------------------------- Git ignore rules of the parser folder.
        CMakeLists.txt --------------------- Main CMake file of the parser library.
        README.md -------------------------- Documentation of the parser library.
        docs ------------------------------- Folder with notes on the camera commands.
            Commands.txt ------------------- Notes on the camera commands.
        src -------------------------------- Folder with source code of the parser library.
            CMakeLists.txt ----------------- CMake file of the parser library.
            G5ProtocolParser.cpp ----------- C++ implementation file of the parser library.
            G5ProtocolParser.h ------------- Header file which includes G5ProtocolParser class declaration.
            G5ProtocolParserVersion.h ------ Header file which includes version of the parser library.
            G5ProtocolParserVersion.h.in --- CMake service file to generate version file.
        static ----------------------------- Folder with images of the parser documentation.
            g5protocolparser_web_logo.png -- Logo of the parser library.
        test ------------------------------- Folder with test application of the parser (not built by the library).
            CMakeLists.txt ----------------- CMake file for test application of the parser.
            main.cpp ----------------------- Source code file of test application of the parser.

G5Camera class description

G5Camera class declaration

The G5Camera class is declared in the G5Camera.h file. The G5Camera class inherits the Lens and Camera interfaces, so it includes a set of similar methods (for lens and camera control). Both interfaces use one serial port, one connection state and one output command buffer. The class is thread-safe: all methods can be called from any number of threads at the same time (the open, init and close methods are executed one after another). Class declaration:

class G5Camera : public rapidpixel::Camera, public rapidpixel::Lens
{
public:

    /// Class constructor.
    G5Camera();

    /// Class destructor. Stops the communication thread and closes the
    /// serial port.
    ~G5Camera() override;

    /// Copy and move operations are deleted.
    G5Camera(const G5Camera&) = delete;
    G5Camera(G5Camera&&) = delete;
    G5Camera& operator=(const G5Camera&) = delete;
    G5Camera& operator=(G5Camera&&) = delete;

    /// Get class version.
    static std::string getVersion();

    /// Decode and execute command.
    bool decodeAndExecuteCommand(uint8_t* data, int size) override;

    // #######################################
    // CAMERA CONTROL INTERFACE
    // #######################################

    /// Open controller serial port.
    bool openCamera(std::string initString) override;

    /// Init camera by parameters structure.
    bool initCamera(rapidpixel::CameraParams& params) override;

    /// Method closes serial port and stops communication thread.
    void closeCamera() override;

    /// Get serial port status.
    bool isCameraOpen() override;

    /// Get camera connection status.
    bool isCameraConnected() override;

    /// Set the camera parameter.
    bool setParam(rapidpixel::CameraParam id, float value) override;

    /// Get the camera parameter.
    float getParam(rapidpixel::CameraParam id) override;

    /// Get the camera params.
    void getParams(rapidpixel::CameraParams& params) override;

    /// Execute camera command.
    bool executeCommand(rapidpixel::CameraCommand id) override;

    // #######################################
    // LENS CONTROL INTERFACE
    // #######################################

    /// Open controller serial port.
    bool openLens(std::string initString) override;

    /// Init lens by parameters structure.
    bool initLens(rapidpixel::LensParams& params) override;

    /// Closes serial port and stops communication thread.
    void closeLens() override;

    /// Get serial port status.
    bool isLensOpen() override;

    /// Get lens connection status.
    bool isLensConnected() override;

    /// Set a lens parameter.
    bool setParam(rapidpixel::LensParam id, float value) override;

    /// Get a lens parameter.
    float getParam(rapidpixel::LensParam id) override;

    /// Get the lens parameters.
    void getParams(rapidpixel::LensParams& params) override;

    /// Execute a lens command.
    bool executeCommand(rapidpixel::LensCommand id, float arg = 0) override;

    /// Add video frame for auto focus purposes. Not supported.
    void addVideoFrame(rapidpixel::Frame&) override;
};

getVersion method

The getVersion() method returns a string with the G5Camera class version. Method declaration:

static std::string getVersion();

Method can be used without G5Camera class instance:

std::cout << "G5Camera class version: " << rapidpixel::G5Camera::getVersion();

Console output:

G5Camera class version: 2.7.0

openLens method

openLens(…) opens a serial port to communicate with the G5 camera and starts the communication thread. To initialize the serial port, the user can call openCamera(…) or openLens(…) method (it doesn’t matter which). If the serial port is already open, the method does nothing and returns TRUE. The method does not wait for the camera: the communication thread repeats the readiness request until the camera answers, after that isCameraConnected(…) returns TRUE. Method declaration:

bool openLens(std::string initString) override;
Parameter Value
initString Initialization string. Format: [serial port name];[baudrate];[timeout]. Example: /dev/ttyUSB0;115200;100. Empty items are ignored, at least three items are required, the items after the third one are ignored. The baudrate must be a positive integer. The timeout item is not used (the serial port is read without waiting) but it must be present. The serial port name is passed to the operating system as is, it must not contain the NUL character and must come from a trusted configuration.

Returns: TRUE if the controller is initialized or FALSE if not (the init string is not valid, the serial port can not be opened or the communication thread can not be started). If FALSE is returned the controller is closed.

openCamera method

openCamera(…) opens a serial port to communicate with the G5 camera and starts the communication thread. To initialize the serial port, the user can call openCamera(…) or openLens(…) method (it doesn’t matter which). If the serial port is already open, the method does nothing and returns TRUE. The method does not wait for the camera: the communication thread repeats the readiness request until the camera answers, after that isCameraConnected(…) returns TRUE. Method declaration:

bool openCamera(std::string initString) override;
Parameter Value
initString Initialization string. Format: [serial port name];[baudrate];[timeout]. Example: /dev/ttyUSB0;115200;100. Empty items are ignored, at least three items are required, the items after the third one are ignored. The baudrate must be a positive integer. The timeout item is not used (the serial port is read without waiting) but it must be present. The serial port name is passed to the operating system as is, it must not contain the NUL character and must come from a trusted configuration.

Returns: TRUE if the controller is initialized or FALSE if not (the init string is not valid, the serial port can not be opened or the communication thread can not be started). If FALSE is returned the controller is closed.

initLens method

The initLens(…) method initializes the controller and sets lens params (Lens interface). The method sets the log mode, calls the openLens(…) method and sets the zoom speed, the focus speed and the focus mode in the same way as setParam(…) does (the results of these calls are not checked: a parameter with an invalid value is not set). The FOV points are copied. The method does not initialize camera params (Camera interface). To initialize camera params, the user should call the initCamera(…) method. After successful initialization, the library will run the communication thread (a thread to communicate with the equipment via the serial port) if it is not already running. Method declaration:

bool initLens(rapidpixel::LensParams& params) override;
Parameter Value
params LensParams class object. LensParams class includes initString which used in openLens(…) method. Only initString, logMode, zoomSpeed, focusSpeed, focusMode and fovPoints are used.

Returns: TRUE if the controller initialized or FALSE if not (see openLens(…)).

initCamera method

The initCamera(…) method initializes the controller and sets camera params (Camera interface). The method sets the log mode, calls the openCamera(…) method and sets the other camera params in the same way as setParam(…) does (the results of these calls are not checked: a parameter with an invalid value is not set). gain and brightness are set only if agcMode is 0. The method does not initialize lens params (Lens interface). To initialize lens params, the user should call the initLens(…) method. After successful initialization, the library will run the communication thread (a thread to communicate with the equipment via the serial port) if it is not already running. autoNucIntervalMsec is always applied before nucMode: the camera latches the auto calibration period at the moment auto NUC is switched on. Method declaration:

bool initCamera(CameraParams& params) override;
Parameter Value
params CameraParams class object. CameraParams class includes initString which used in openCamera(…) method. If alcGate is outside of 0-10, sceneMode is outside of 0-7 or custom1 is 0, the method replaces the value in the structure with the default value 4, 1 and 1 respectively.

Returns: TRUE if the controller initialized or FALSE if not (see openCamera(…)).

closeLens method

closeLens() closes the serial port and stops the communication thread. The result of the method is the same as the closeCamera(…) method (the user can use either of them). Method declaration:

void closeLens() override;

closeCamera method

closeCamera() closes the serial port and stops the communication thread. The result of the method is the same as the closeLens(…) method (the user can use either of them). Method declaration:

void closeCamera() override;

isLensOpen method

isLensOpen() method returns the controller initialization status. The open status shows if the controller is initialized (serial port open) but doesn’t show if the controller has communication with the equipment. For example, if the serial port is open (opens a serial port file in the OS) but the equipment may not be active (no power). In this case the open status just shows that the serial port is open. This method is equivalent to the isCameraOpen(…) method. Method declaration:

bool isLensOpen() override;

Returns: TRUE if the controller is initialized (serial port open) or FALSE if not.

isCameraOpen method

isCameraOpen() method returns the controller initialization status. The open status shows if the controller is initialized (serial port open) but doesn’t show if the controller has communication with the equipment. For example, if the serial port is open (opens a serial port file in the OS) but the equipment may not be active (no power). In this case the open status just shows that the serial port is open. This method is equivalent to the isLensOpen(…) method. Method declaration:

bool isCameraOpen() override;

Returns: TRUE if the controller is initialized (serial port open) or FALSE if not.

isLensConnected method

isLensConnected() shows if the controller receives responses from the equipment (camera). For example, if the serial port is open but the equipment is not active (no power). In this case the isLensOpen(…) and isCameraOpen(…) methods will return TRUE but the isLensConnected() method will return FALSE. This method is equivalent to the isCameraConnected(…) method (the user can use either of them). Method declaration:

bool isLensConnected() override;

Returns: TRUE if the controller has data exchange with equipment or FALSE if not.

isCameraConnected method

isCameraConnected() shows if the controller receives responses from the equipment (camera). For example, if the serial port is open but the equipment is not active (no power). In this case the isLensOpen(…) and isCameraOpen(…) methods will return TRUE but the isCameraConnected() method will return FALSE. This method is equivalent to the isLensConnected(…) method (the user can use either of them). Method declaration:

bool isCameraConnected() override;

Returns: TRUE if the controller has data exchange with the equipment or FALSE if not.

setParam method

setParam(…) is an overloaded method. The method is intended to set a Camera or Lens parameter value. Method declaration:

bool setParam(LensParam id, float value) override;
bool setParam(CameraParam id, float value) override;
Parameter Description
id Lens parameter ID according to the LensParam enum or camera parameter ID according to the CameraParam enum.
value Camera or Lens parameter value. Valid values depend on the parameter ID.

Returns: TRUE if the parameter is set or FALSE if not (the parameter is not supported or the value is not valid).

For an integer parameter the value is converted to an integer (the fractional part is dropped) and checked against the range of the parameter; SCENE_MODE and the FOV parameters are compared with the limits as floating-point numbers (for example 8.5 is not valid for SCENE_MODE). NaN, infinity and values outside of the int range are rejected. The method stores the parameter value and adds the command to the output buffer of the controller (50 commands: if the buffer is full the oldest command is dropped). The communication thread writes the commands to the camera after the camera has answered the readiness request. If the command cannot be encoded the method returns FALSE and the stored value is kept. This happens for DIGITAL_ZOOM values below 2.5 and above 20.0 (the DZOOM command accepts the zoom factor from 1 to 8: the value 20 corresponds to the factor 8 and the value 2.5 to the factor 1), for GAIN and BRIGHTNESS values above 100.05 (the commands accept the value multiplied by 10 up to 1000) and for Y_FOV_DEG values above about 102.4 degrees (the FOV command accepts up to 180 degrees multiplied by 100 for the horizontal FOV; the vertical FOV is converted to the horizontal one with the ratio 1.757). The supported camera parameters:

CameraParam Valid values
DISPLAY_MODE 0 - 1.
LOG_MODE 0 - 3 (0 - disabled, 1 - file, 2 - console, 3 - console and file). Sets the log mode of the lens too.
DIGITAL_ZOOM 1 - 20.
PALETTE 0 - 7.
SENSITIVITY -1 - 1.
GAIN_MODE, AGC_MODE 0 - 2. Both parameters set the same mode.
SCENE_MODE 1 - 8. The value 8 (custom ROI) is accepted only after ROI_X0, ROI_Y0, ROI_X1 and ROI_Y1 were set (otherwise the method returns FALSE).
GAIN 0 - 100.
BRIGHTNESS 0 - 100.
NUC_MODE 0 - 1.
AUTO_NUC_INTERVAL_MSEC 1000 - 32767000.
DEHAZE_MODE 0 - 5.
STABILIZATION_MODE 0 - 1.
SHARPENING_MODE 0 - 5.
CONTRAST 0 - 3.
FILTER_MODE 0 - 10.
ALC_GATE 0 - 10.
CUSTOM_1 1 - 7 (turbulence mitigation ROI mode).
CUSTOM_2 0 - 5 (turbulence mitigation quality).
CUSTOM_3 0 - 5 (turbulence mitigation motion).
ROI_X0, ROI_Y0, ROI_X1, ROI_Y1 0 - 2048. The custom ROI is applied when all four coordinates are set.

The supported lens parameters:

LensParam Valid values
LOG_MODE 0 - 3 (see CameraParam LOG_MODE).
ZOOM_POS 0 - 65535.
ZOOM_HW_POS 0 - 1000.
ZOOM_SPEED 1 - 100.
FOCUS_MODE exactly 0, 1 or 2 (2 - continuous auto focus).
FOCUS_POS 0 - 65535.
FOCUS_HW_POS 0 - 1000.
FOCUS_HW_FAR_LIMIT 1 - 1000000 (focusing distance, meters).
FOCUS_SPEED 1 - 100.
X_FOV_DEG 0 - 180 (degrees).
Y_FOV_DEG 0 - 180 (degrees).

The parameters ZOOM_HW_TELE_LIMIT, ZOOM_HW_WIDE_LIMIT and FOCUS_HW_NEAR_LIMIT are not supported.

getParam method

getParam(…) is an overloaded method. The method is intended to obtain a Camera or Lens parameter value. Method declaration:

float getParam(LensParam id) override;
float getParam(CameraParam id) override;
Parameter Description
id Lens parameter ID according to the LensParam enum or camera parameter ID according to the CameraParam enum.

Returns: parameter value or -1 if the parameter is not supported. The zoom and focus positions, the focusing distance (FOCUS_HW_FAR_LIMIT) and the FOV are updated from the responses of the camera, the gain and the brightness are synchronized with the camera.

getParams method

getParams(…) is an overloaded method. The method is intended to obtain a Camera or Lens parameters structure. Method declaration:

void getParams(LensParams& params) override;
void getParams(CameraParams& params) override;
Parameter Description
params Reference to a LensParams class object or CameraParams class object.

executeCommand method

executeCommand(…) is an overloaded method. The method is intended to execute a Camera or Lens action command. Method declaration:

bool executeCommand(LensCommand id, float arg = 0) override;
bool executeCommand(CameraCommand id) override;
Parameter Description
id Camera command ID according to CameraCommand enum or lens command ID according to LensCommand enum.
arg Only for lens interface. Lens command argument. Valid values depend on command ID.

Returns: TRUE if the command is executed (accepted by controller) or FALSE if not.

The camera commands NUC, RESTART, FREEZE and DEFREEZE are added to the output buffer. The lens commands ZOOM_TELE, ZOOM_WIDE, ZOOM_STOP, ZOOM_TO_POS (argument 0 - 65535), FOCUS_FAR, FOCUS_NEAR, FOCUS_STOP and FOCUS_TO_POS (argument 0 - 65535) are written to the serial port immediately, they bypass the output buffer: while the camera has not answered the readiness request the method returns FALSE for them. The lens commands AF_START and RESTART are added to the output buffer. The argument of the lens commands is converted in the same way as the value of setParam(…): NaN, infinity and values outside of the range are rejected. The other commands (including AF_STOP) are not supported, the method returns FALSE.

addVideoFrame method

The addVideoFrame(…) method is declared by the Lens interface to pass video frame data to the lens controller for autofocus algorithms. It is not supported by G5Camera (the implementation is a no-op). Method declaration:

void addVideoFrame(rapidpixel::Frame& frame) override;
Parameter Description
frame Frame class object.

decodeAndExecuteCommand method

The decodeAndExecuteCommand(…) method decodes and executes a command on the controller side. It decodes commands encoded by the encodeSetParamCommand(…) and encodeCommand(…) methods of the Lens interface class or by the encodeSetParamCommand(…) and encodeCommand(…) methods of the Camera interface class. If the command is decoded successfully, the method calls setParam(…) or executeCommand(…) of the Lens or Camera interface. This method is thread-safe and can be safely called from any thread. Method declaration:

bool decodeAndExecuteCommand(uint8_t* data, int size) override;
Parameter Description
data Pointer to input command. Must not be nullptr and must be valid for size bytes.
size Size of command. 11 bytes for Lens commands (SET_PARAM and COMMAND) and Camera SET_PARAM; 7 bytes for Camera COMMAND.

Returns: TRUE if the command is decoded (SET_PARAM or COMMAND) and executed (action command or set-param command), FALSE otherwise (the pointer is nullptr, the size, the version or the ID is not valid, or the command is not executed). A command which cannot be decoded is written to the log in accordance with the log mode.

encodeSetParamCommand method of Lens class

encodeSetParamCommand(…) static method of Lens interface class designed to encode command to change any remote lens parameter. To control a lens remotely, the developer has to develop his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Lens class contains static methods for encoding the control command. The Lens class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeSetParamCommand(…) designed to encode SET_PARAM command. Method declaration:

static void encodeSetParamCommand(uint8_t* data, int& size, LensParam id, float value);
Parameter Description
data Pointer to data buffer for encoded command. Must not be nullptr. Buffer size must be >= 11 bytes.
size Size of encoded data. Will be 11 bytes. If data is nullptr nothing is encoded and the size will be 0.
id Parameter ID according to LensParam enum.
value Parameter value. The value is encoded as is.

SET_PARAM command format:

Byte Value Description
0 0x01 SET_PARAM command header value.
1 Major Major version of Lens class.
2 Minor Minor version of Lens class.
3 id Parameter ID int32_t in host byte order.
4 id Parameter ID int32_t in host byte order.
5 id Parameter ID int32_t in host byte order.
6 id Parameter ID int32_t in host byte order.
7 value Parameter value float in host byte order.
8 value Parameter value float in host byte order.
9 value Parameter value float in host byte order.
10 value Parameter value float in host byte order.

The ID and the value are written in the byte order of the host (Little-endian on x86-64 and ARM Linux systems).

encodeSetParamCommand(…) is static and used without Lens class instance. This method used on client side (control system). Example:

// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Parameter value.
float outValue = 10.0f;
// Encode command.
rapidpixel::Lens::encodeSetParamCommand(
    data, size, rapidpixel::LensParam::AF_ROI_X0, outValue);
std::cout << "Encoded command size: " << size << " bytes" << std::endl;

encodeCommand method of Lens class

encodeCommand(…) static method of Lens interface class designed to encode lens action command. To control a lens remotely, the developer has to develop his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Lens class contains static methods for encoding the control command. The Lens class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeCommand(…) designed to encode COMMAND command (action command). Method declaration:

static void encodeCommand(uint8_t* data, int& size, LensCommand id, float arg = 0.0f);
Parameter Description
data Pointer to data buffer for encoded command. Must not be nullptr. Buffer size must be >= 11 bytes.
size Size of encoded data. Will be 11 bytes. If data is nullptr nothing is encoded and the size will be 0.
id Command ID according to LensCommand enum.
arg Command argument value (value depends on command ID). The value is encoded as is. Default value is 0.0f.

COMMAND format:

Byte Value Description
0 0x00 COMMAND header value.
1 Major Major version of Lens class.
2 Minor Minor version of Lens class.
3 id Command ID int32_t in host byte order.
4 id Command ID int32_t in host byte order.
5 id Command ID int32_t in host byte order.
6 id Command ID int32_t in host byte order.
7 arg Command argument value float in host byte order.
8 arg Command argument value float in host byte order.
9 arg Command argument value float in host byte order.
10 arg Command argument value float in host byte order.

The ID and the argument are written in the byte order of the host (Little-endian on x86-64 and ARM Linux systems).

encodeCommand(…) is static and used without Lens class instance. This method used on client side (control system). Encoding example:

// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Command argument value (zoom position).
float outValue = 1000.0f;
// Encode command.
rapidpixel::Lens::encodeCommand(
    data, size, rapidpixel::LensCommand::ZOOM_TO_POS, outValue);
std::cout << "Encoded command size: " << size << " bytes" << std::endl;

decodeCommand method of Lens class

decodeCommand(…) static method of Lens interface class designed to decode command on lens controller side. To control a lens remotely, the developer has to develop his own protocol and according to it decode the command on lens controller side. To simplify this, the Lens interface class contains static method to decode input command (commands should be encoded by methods encodeSetParamCommand(…) or encodeCommand(…)). The Lens class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). Method declaration:

static int decodeCommand(uint8_t* data, int size, LensParam& paramId, LensCommand& commandId, float& value);
Parameter Description
data Pointer to input command. Must not be nullptr and must be valid for size bytes.
size Size of command. Must be exactly 11 bytes.
paramId Lens parameter ID according to LensParam enum. After decoding SET_PARAM command the method will return parameter ID. Not changed in other cases.
commandId Lens command ID according to LensCommand enum. After decoding COMMAND the method will return command ID. Not changed in other cases.
value Lens parameter value (after decoding SET_PARAM command) or lens command argument (after decoding COMMAND). Not changed in case of error.

Returns: 0 - in case decoding COMMAND, 1 - in case decoding SET_PARAM command or -1 in case errors.

The method returns -1 (the output arguments are not changed) if data is nullptr, size is not 11, Major or Minor version in the command (bytes 1 and 2) is not equal to the version of the Lens class, the first byte is neither 0x00 (COMMAND) nor 0x01 (SET_PARAM) or the ID is outside the range of the enum: 1-16 for LensCommand and 1-50 for LensParam. The value is not checked against any range: the lens controller must validate it before use.

encodeSetParamCommand method of Camera class

encodeSetParamCommand(…) static method of Camera interface class encodes command to change any remote camera parameter value. To control a camera remotely, the developer has to design his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Camera class contains static methods for encoding the control command. The Camera class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeSetParamCommand(…) designed to encode SET_PARAM command. Method declaration:

static void encodeSetParamCommand(uint8_t* data, int& size, CameraParam id, float value);
Parameter Description
data Pointer to data buffer for encoded command. Must not be nullptr. The method can’t check the buffer size: the buffer size must be >= 11 bytes.
size Size of encoded data. Will be 11 bytes. If data is nullptr nothing is encoded and the size will be 0.
id Parameter ID according to CameraParam enum.
value Parameter value. The value is encoded as is (also NaN and infinity).

SET_PARAM command format:

Byte Value Description
0 0x01 SET_PARAM command header value.
1 Major Major version of Camera class.
2 Minor Minor version of Camera class.
3 id Parameter ID int32_t in host byte order.
4 id Parameter ID int32_t in host byte order.
5 id Parameter ID int32_t in host byte order.
6 id Parameter ID int32_t in host byte order.
7 value Parameter value float in host byte order.
8 value Parameter value float in host byte order.
9 value Parameter value float in host byte order.
10 value Parameter value float in host byte order.

The ID and the value are written in the byte order of the host (Little-endian on x86-64 and ARM Linux systems).

encodeSetParamCommand(…) is static and used without Camera class instance. This method used on client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Parameter value.
float outValue = 100.0f;
// Encode command.
rapidpixel::Camera::encodeSetParamCommand(
    data, size, rapidpixel::CameraParam::ROI_X0, outValue);
std::cout << "Encoded command size: " << size << " bytes" << std::endl;

encodeCommand method of Camera class

encodeCommand(…) static method of Camera interface class encodes command for camera remote control. To control a camera remotely, the developer has to design his own protocol and according to it encode the command and deliver it over the communication channel. To simplify this, the Camera class contains static methods for encoding the control command. The Camera class provides two types of commands: a parameter change command (SET_PARAM) and an action command (COMMAND). encodeCommand(…) designed to encode COMMAND command (action command). Method declaration:

static void encodeCommand(uint8_t* data, int& size, CameraCommand id);
Parameter Description
data Pointer to data buffer for encoded command. Must not be nullptr. The method can’t check the buffer size: the buffer size must be >= 7 bytes.
size Size of encoded data. Will be 7 bytes. If data is nullptr nothing is encoded and the size will be 0.
id Command ID according to CameraCommand enum.

COMMAND format:

Byte Value Description
0 0x00 COMMAND header value.
1 Major Major version of Camera class.
2 Minor Minor version of Camera class.
3 id Command ID int32_t in host byte order.
4 id Command ID int32_t in host byte order.
5 id Command ID int32_t in host byte order.
6 id Command ID int32_t in host byte order.

The ID is written in the byte order of the host (Little-endian on x86-64 and ARM Linux systems).

encodeCommand(…) is static and used without Camera class instance. This method used on client side (control system). Command encoding example:

// Buffer for encoded data.
uint8_t data[7];
// Size of encoded data.
int size = 0;
// Encode command.
rapidpixel::Camera::encodeCommand(
    data, size, rapidpixel::CameraCommand::NUC);
std::cout << "Encoded command size: " << size << " bytes" << std::endl;

decodeCommand method of Camera class

decodeCommand(…) static method of Camera interface class decodes command on camera controller side. Method declaration:

static int decodeCommand(uint8_t* data, int size, CameraParam& paramId, CameraCommand& commandId, float& value);
Parameter Description
data Pointer to input command. Must not be nullptr. The method can’t check the buffer size: the buffer must be valid for size bytes.
size Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND.
paramId Camera parameter ID according to CameraParam enum. After decoding SET_PARAM command the method will return parameter ID. Not changed in other cases.
commandId Camera command ID according to CameraCommand enum. After decoding COMMAND the method will return command ID. Not changed in other cases.
value Camera parameter value (after decoding SET_PARAM command) or 0 (after decoding COMMAND). Not changed in case of error.

Returns: 0 - in case decoding COMMAND, 1 - in case decoding SET_PARAM command or -1 in case errors.

The method returns -1 (the output arguments are not changed) if data is nullptr, size is less than 7, Major or Minor version in the command (bytes 1 and 2) is not equal to the version of the Camera class, the first byte is neither 0x00 (COMMAND) nor 0x01 (SET_PARAM), the size does not match the command type (7 bytes for COMMAND, 11 bytes for SET_PARAM) or the ID is outside the range of the enum: 1-13 for CameraCommand and 1-58 for CameraParam. The value is not checked against any range: the camera controller must validate it before use.

Data structures

LensCommand enum

Enum declaration:

enum class LensCommand
{
    /// Move zoom tele (in).
    ZOOM_TELE = 1,
    /// Move zoom wide (out).
    ZOOM_WIDE,
    /// Move zoom to position.
    ZOOM_TO_POS,
    /// Stop zoom moving including stop zoom to position command.
    ZOOM_STOP,
    /// Move focus far.
    FOCUS_FAR,
    /// Move focus near.
    FOCUS_NEAR,
    /// Move focus to position.
    FOCUS_TO_POS,
    /// Stop focus moving including stop focus to position command.
    FOCUS_STOP,
    /// Move iris open.
    IRIS_OPEN,
    /// Move iris close.
    IRIS_CLOSE,
    /// Move iris to position.
    IRIS_TO_POS,
    /// Stop iris moving including stop iris to position command.
    IRIS_STOP,
    /// Start autofocus.
    AF_START,
    /// Stop autofocus.
    AF_STOP,
    /// Restart lens controller.
    RESTART,
    /// Detect zoom and focus hardware ranges.
    DETECT_HW_RANGES
};

Table 2 - Lens commands description.

Command Description
ZOOM_TELE Move zoom tele (in). Command doesn’t have arguments.
ZOOM_WIDE Move zoom wide (out). Command doesn’t have arguments.
ZOOM_TO_POS Move zoom to position. Lens controller should have zoom range from 0 (full wide) to 65535 (full tele) regardless of the hardware value of the zoom position. If the minimum and maximum zoom position limits are set by the user in the lens parameters, the range of the hardware zoom position must be scaled to the user space 0-65535 range. Command argument: zoom position 0-65535.
ZOOM_STOP Stop zoom moving including stop zoom to position command.
FOCUS_FAR Move focus far. Command doesn’t have arguments.
FOCUS_NEAR Move focus near. Command doesn’t have arguments.
FOCUS_TO_POS Move focus to position. Lens controller should have focus range from 0 (full near) to 65535 (full far) regardless of the hardware value of the focus position. If the minimum and maximum focus position limits are set by the user in the lens parameters, the range of the hardware focus position must be scaled to the 0-65535 user space range. Command argument: focus position 0-65535.
FOCUS_STOP Stop focus moving including stop focus to position command.
IRIS_OPEN Not supported by G5Camera library.
IRIS_CLOSE Not supported by G5Camera library.
IRIS_TO_POS Not supported by G5Camera library.
IRIS_STOP Not supported by G5Camera library.
AF_START Start autofocus. Command doesn’t have arguments.
AF_STOP Not supported by G5Camera library.
RESTART Restart lens controller.
DETECT_HW_RANGES Not supported by G5Camera library.

CameraCommand enum

Enum declaration:

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 image.
    FREEZE,
    /// Disable freeze.
    DEFREEZE
};

Table 3 - Camera commands description.

Command Description
RESTART Restart camera controller.
NUC Do NUC. For thermal cameras.
APPLY_PARAMS Not supported by G5Camera library.
SAVE_PARAMS Not supported by G5Camera library.
MENU_ON Not supported by G5Camera library.
MENU_OFF Not supported by G5Camera library.
MENU_SET Not supported by G5Camera library.
MENU_UP Not supported by G5Camera library.
MENU_DOWN Not supported by G5Camera library.
MENU_LEFT Not supported by G5Camera library.
MENU_RIGHT Not supported by G5Camera library.
FREEZE Freeze image.
DEFREEZE Defreeze image.

LensParam enum

Enum declaration:

enum class LensParam
{
    /// Zoom position.
    ZOOM_POS = 1,
    /// Hardware zoom position.
    ZOOM_HW_POS,
    /// Focus position.
    FOCUS_POS,
    /// Hardware focus position. 
    FOCUS_HW_POS,
    /// Iris position.
    IRIS_POS,
    /// Hardware iris position.
    IRIS_HW_POS,
    /// Focus mode.
    FOCUS_MODE,
    /// Filter mode.
    FILTER_MODE,
    /// Autofocus ROI top-left corner horizontal position in pixels.
    AF_ROI_X0,
    /// Autofocus ROI top-left corner vertical position in pixels.
    AF_ROI_Y0,
    /// Autofocus ROI bottom-right corner horizontal position in pixels.
    AF_ROI_X1,
    /// Autofocus ROI bottom-right corner vertical position in pixels.
    AF_ROI_Y1,
    /// Zoom speed.
    ZOOM_SPEED,
    /// Zoom hardware speed. 
    ZOOM_HW_SPEED,
    /// Maximum zoom hardware speed. 
    ZOOM_HW_MAX_SPEED,
    /// Focus speed.
    FOCUS_SPEED,
    /// Focus hardware speed. 
    FOCUS_HW_SPEED,
    /// Maximum focus hardware speed. 
    FOCUS_HW_MAX_SPEED,
    /// Iris speed.
    IRIS_SPEED,
    /// Iris hardware speed. 
    IRIS_HW_SPEED,
    /// Maximum iris hardware speed. 
    IRIS_HW_MAX_SPEED,
    /// Zoom hardware tele limit. 
    ZOOM_HW_TELE_LIMIT,
    /// Zoom hardware wide limit. 
    ZOOM_HW_WIDE_LIMIT,
    /// Focus hardware far limit. 
    FOCUS_HW_FAR_LIMIT,
    /// Focus hardware near limit. 
    FOCUS_HW_NEAR_LIMIT,
    /// Iris hardware open limit.
    IRIS_HW_OPEN_LIMIT,
    /// Iris hardware close limit.
    IRIS_HW_CLOSE_LIMIT,
    /// Focus factor if it was calculated.
    FOCUS_FACTOR,
    /// Lens connection status.
    IS_CONNECTED,
    /// Focus hardware speed in autofocus mode. 
    FOCUS_HW_AF_SPEED,
    /// Threshold for changes of focus factor to start refocus.
    FOCUS_FACTOR_THRESHOLD,
    /// Timeout for automatic refocus in seconds.
    REFOCUS_TIMEOUT_SEC,
    /// Flag about active autofocus algorithm.
    AF_IS_ACTIVE,
    /// Iris mode.
    IRIS_MODE,
    /// ROI width (pixels).
    AUTO_AF_ROI_WIDTH,
    /// ROI height (pixels).
    AUTO_AF_ROI_HEIGHT,
    /// Video frame border size (along vertical and horizontal axes).
    AUTO_AF_ROI_BORDER,
    /// AF ROI mode (write/read). Value: 0 - Manual position, 1 - Auto position.
    AF_ROI_MODE,
    /// Lens extender mode.
    EXTENDER_MODE,
    /// Lens stabilization mode.
    STABILIZER_MODE,
    /// Autofocus range.
    AF_RANGE,
    /// Current horizontal Field of view, degree.
    X_FOV_DEG,
    /// Current vertical Field of view, degree.
    Y_FOV_DEG,
    /// Logging mode.
    LOG_MODE,
    /// Lens temperature, degree.
    TEMPERATURE,
    /// Lens controller initialization status.
    IS_OPEN,
    /// Lens type.
    TYPE,
    /// Lens custom parameter.
    CUSTOM_1,
    /// Lens custom parameter.
    CUSTOM_2,
    /// Lens custom parameter.
    CUSTOM_3
};

Table 4 - Lens params description.

Parameter Access Description
ZOOM_POS read / write Zoom position. Setting a parameter is equivalent to the command ZOOM_TO_POS. Lens controller should have zoom range from 0 (full wide) to 65535 (full tele) regardless of the hardware value of the zoom position. If the minimum and maximum zoom position limits are set by the user in the lens parameters, the range of the hardware zoom position must be scaled to the user space 0-65535 range. Parameter value: zoom position 0-65535.
ZOOM_HW_POS read / write Hardware zoom position. Supported values: 0-1000.
FOCUS_POS read / write Focus position. Setting a parameter is equivalent to the command FOCUS_TO_POS. Lens controller should have focus range from 0 (full near) to 65535 (full far) regardless of the hardware value of the focus position. If the minimum and maximum focus position limits are set by the user in the lens parameters, the range of the hardware focus position must be scaled to the user space 0-65535 range. Parameter value: focus position 0-65535.
FOCUS_HW_POS read / write Hardware focus position. Supported values: 0-1000.
IRIS_POS read / write Not supported by G5Camera library.
IRIS_HW_POS read / write Not supported by G5Camera library.
FOCUS_MODE read / write Focus mode. Value: 0 - manual. 1 - auto. 2 - continuous auto.
FILTER_MODE read / write Not supported by G5Camera library.
AF_ROI_X0 read / write Not supported by G5Camera library.
AF_ROI_Y0 read / write Not supported by G5Camera library.
AF_ROI_X1 read / write Not supported by G5Camera library.
AF_ROI_Y1 read / write Not supported by G5Camera library.
ZOOM_SPEED read / write Zoom speed. Supported values: 1-100%.
ZOOM_HW_SPEED read / write Not supported by G5Camera library.
ZOOM_HW_MAX_SPEED read / write Not supported by G5Camera library.
FOCUS_SPEED read / write Focus speed. Supported values: 1-100%.
FOCUS_HW_SPEED read / write Not supported by G5Camera library.
FOCUS_HW_MAX_SPEED read / write Not supported by G5Camera library.
IRIS_SPEED read / write Not supported by G5Camera library.
IRIS_HW_SPEED read / write Not supported by G5Camera library.
IRIS_HW_MAX_SPEED read / write Not supported by G5Camera library.
ZOOM_HW_TELE_LIMIT read / write Not supported by G5Camera library.
ZOOM_HW_WIDE_LIMIT read / write Not supported by G5Camera library.
FOCUS_HW_FAR_LIMIT read / write Focusing distance (distance to object in focus): 1-1000000. Note: for other cameras this parameter means focus far position limit but for G5Camera it represents the focusing distance.
FOCUS_HW_NEAR_LIMIT read / write Not supported by G5Camera library.
IRIS_HW_OPEN_LIMIT read / write Not supported by G5Camera library.
IRIS_HW_CLOSE_LIMIT read / write Not supported by G5Camera library.
FOCUS_FACTOR read only Not supported by G5Camera library.
IS_CONNECTED read only Lens connection status. Value: 0 - not connected. 1 - connected.
FOCUS_HW_AF_SPEED read / write Not supported by G5Camera library.
FOCUS_FACTOR_THRESHOLD read / write Not supported by G5Camera library.
REFOCUS_TIMEOUT_SEC read / write Not supported by G5Camera library.
AF_IS_ACTIVE read only Not supported by G5Camera library.
IRIS_MODE read / write Not supported by G5Camera library.
AUTO_AF_ROI_WIDTH read / write Not supported by G5Camera library.
AUTO_AF_ROI_HEIGHT read / write Not supported by G5Camera library.
AUTO_AF_ROI_BORDER read / write Not supported by G5Camera library.
AF_ROI_MODE read / write Not supported by G5Camera library.
EXTENDER_MODE read / write Not supported by G5Camera library.
STABILIZER_MODE read / write Not supported by G5Camera library.
AF_RANGE read / write Not supported by G5Camera library.
X_FOV_DEG read / write Current horizontal Field of view, degree. Field of view calculated by lens controller according to initial params or by reading directly from lens hardware.
Y_FOV_DEG read / write Current vertical Field of view, degree. Field of view calculated by lens controller according to initial params or by reading directly from lens hardware.
LOG_MODE read / write Logging mode. Default values:
0 - Disable.
1 - Only file.
2 - Only terminal.
3 - File and terminal. Note: for G5Camera getParam(…) returns -1 for this lens parameter, the value is available in the structure returned by getParams(…).
TEMPERATURE read only Not supported by G5Camera.
IS_OPEN read only Controller initialization status. The open status shows if the controller is initialized or not but doesn’t show if the controller has communication with the equipment. For example, if the serial port is open but the equipment may not be active (no power). In this case the open status just shows that the controller has opened the serial port. Values: 0 - not open (not initialized), 1 - open (initialized). Note: for G5Camera getParam(…) returns -1 for this lens parameter, the value is available in the structure returned by getParams(…).
TYPE read / write Not supported by G5Camera library.
CUSTOM_1 read / write Not supported by G5Camera library.
CUSTOM_2 read / write Not supported by G5Camera library.
CUSTOM_3 read / write Not supported by G5Camera library.

CameraParam enum

Enum declaration:

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.
    DISPLAY_MODE,
    /// Video output type.
    VIDEO_OUTPUT,
    /// Logging mode.
    LOG_MODE,
    /// Exposure mode.
    EXPOSURE_MODE,
    /// Exposure time of the camera sensor.
    EXPOSURE_TIME,
    /// White balance mode.
    WHITE_BALANCE_MODE,
    /// White balance area.
    WHITE_BALANCE_AREA,
    /// White dynamic range mode.
    WIDE_DYNAMIC_RANGE_MODE,
    /// Image stabilization mode.
    STABILIZATION_MODE,
    /// ISO sensitivity.
    ISO_SENSITIVITY,
    /// Scene mode.
    SCENE_MODE,
    /// FPS.
    FPS,
    /// Brightness mode.
    BRIGHTNESS_MODE,
    /// Brightness. Value 0 - 100%.
    BRIGHTNESS,
    /// Contrast. Value 1 - 100%.
    CONTRAST,
    /// Gain mode.
    GAIN_MODE,
    /// Gain. Value 1 - 100%.
    GAIN,
    /// Sharpening mode.
    SHARPENING_MODE,
    /// Sharpening. Value 1 - 100%.
    SHARPENING,
    /// Palette.
    PALETTE,
    /// Analog gain control mode.
    AGC_MODE,
    /// Shutter mode.
    SHUTTER_MODE,
    /// Shutter position. 0 (full close) - 65535 (full open).
    SHUTTER_POSITION,
    /// Shutter speed. Value: 0 - 100%.
    SHUTTER_SPEED,
    /// Digital zoom mode.
    DIGITAL_ZOOM_MODE,
    /// Digital zoom. Value 1.0 (x1) - 20.0 (x20).
    DIGITAL_ZOOM,
    /// Exposure compensation mode.
    EXPOSURE_COMPENSATION_MODE,
    /// Exposure compensation position. 
    EXPOSURE_COMPENSATION_POSITION,
    /// Defog mode.
    DEFOG_MODE,
    /// Dehaze mode.
    DEHAZE_MODE,
    /// Noise reduction mode.
    NOISE_REDUCTION_MODE,
    /// Black and white filter mode.
    BLACK_WHITE_FILTER_MODE,
    /// Filter mode.
    FILTER_MODE,
    /// NUC mode for thermal cameras.
    NUC_MODE,
    /// Auto NUC interval for thermal cameras. 
    AUTO_NUC_INTERVAL_MSEC,
    /// Image flip mode.
    IMAGE_FLIP,
    /// DDE mode.
    DDE_MODE,
    /// DDE level.
    DDE_LEVEL,
    /// ROI top-left horizontal position, pixels.
    ROI_X0,
    /// ROI top-left vertical position, pixels.
    ROI_Y0,
    /// ROI bottom-right horizontal position, pixels.
    ROI_X1,
    /// ROI bottom-right vertical position, pixels.
    ROI_Y1,
    /// Camera temperature, degree.
    TEMPERATURE,
    /// ALC gate.
    ALC_GATE,
    /// Sensor sensitivity.
    SENSITIVITY,
    /// Changing mode (day / night).
    CHANGING_MODE,
    /// Changing level (day / night).
    CHANGING_LEVEL,
    /// Chroma level. Values: 0 - 100%.
    CHROMA_LEVEL,
    /// Details, enhancement. Values: 0 - 100%.
    DETAIL,
    /// Camera settings profile.
    PROFILE,
    /// Connection status (read only). Shows if we have a response from the camera.
    /// Value: 0 - not connected, 1 - connected.
    IS_CONNECTED,
    /// Open status (read only):
    /// 1 - camera control port open, 0 - not open.
    IS_OPEN,
    /// Camera type.
    TYPE,
    /// Camera custom param.
    CUSTOM_1,
    /// Camera custom param.
    CUSTOM_2,
    /// Camera custom param.
    CUSTOM_3
};

Table 5 - Camera params description.

Parameter Access Description
WIDTH read / write Not supported by G5Camera library.
HEIGHT read / write Not supported by G5Camera library.
DISPLAY_MODE read / write Image overlay mode. Supported values:
0 - All image overlays turned off.
1 - All image overlays turned on.
The red ROI border has visible padding.
VIDEO_OUTPUT read / write Not supported by G5Camera library.
LOG_MODE read / write Logging mode. Supported values:
0 - Disable.
1 - Only file.
2 - Only terminal.
3 - File and terminal.
EXPOSURE_MODE read / write Not supported by G5Camera library.
EXPOSURE_TIME read / write Not supported by G5Camera library.
WHITE_BALANCE_MODE read / write Not supported by G5Camera library.
WHITE_BALANCE_AREA read / write Not supported by G5Camera library.
WIDE_DYNAMIC_RANGE_MODE read / write Not supported by G5Camera library.
STABILIZATION_MODE read / write Stabilization mode. Default values:
0 - Off.
1 - On.
ISO_SENSITIVITY read / write Not supported by G5Camera library.
SCENE_MODE read / write AGC ROI mode. Default values:
1 - ¼ of image.
2 - ½ of image
3 - ¾ of image
4 - whole image
5 - top 1/3 of image
6 - middle 1/3 of image
7 - bottom 1/3 of image.
8 - custom. Check ROI_X0, ROI_Y0, ROI_X1, ROI_Y1.
FPS read / write Not supported by G5Camera library.
BRIGHTNESS_MODE read / write Not supported by G5Camera library.
BRIGHTNESS read / write Level (MLC). Supported values: 0-100%. With AGC_MODE 0 (Manual) it is the absolute manual level, with 1 (Normal) or 2 (Linear) it is the auto level bias. Restored on initialization only when AGC_MODE is 0.
CONTRAST read / write Local area contrast enhancement mode. Default values:
0 - Off.
1 - Low.
2 - Medium.
3 - High.
GAIN_MODE read / write Gain mode. Supported values:
0 - Turn off Auto Gain Control.
1 - Set the Auto Gain Control to Normal mode.
2 - Set the Auto Gain Control to Linear mode.
Same as AGC_MODE: both parameters send the same AGLC command and are kept in sync.
GAIN read / write Gain (MGC). Supported values: 0-100%. With AGC_MODE 0 (Manual) it is the absolute manual gain, with 1 (Normal) or 2 (Linear) it is the auto gain bias. Restored on initialization only when AGC_MODE is 0.
SHARPENING_MODE read / write Turbulence mitigation sharpness mode. Default values:
0 - Off.
1 - Minimum.
2 - Low.
3 - Medium.
4 - High.
5 - Maximum.
SHARPENING read / write Not supported by G5Camera library.
PALETTE read / write Palette. Supported values 0-7:
0 - White hot.
1 - Black hot.
2-6 - Color palettes.
7 - User-defined palette.
AGC_MODE read / write Agc mode. Supported values:
0 - Turn off Auto Gain Control.
1 - Set the Auto Gain Control to Normal mode.
2 - Set the Auto Gain Control to Linear mode.
Same as GAIN_MODE: both parameters send the same AGLC command and are kept in sync.
SHUTTER_MODE read / write Not supported by G5Camera library.
SHUTTER_POSITION read / write Not supported by G5Camera library.
SHUTTER_SPEED read / write Not supported by G5Camera library.
DIGITAL_ZOOM_MODE read / write Not supported by G5Camera library.
DIGITAL_ZOOM read / write Digital zoom. Value x1.0 to x20.0.
EXPOSURE_COMPENSATION_MODE read / write Not supported by G5Camera library.
EXPOSURE_COMPENSATION_POSITION read / write Not supported by G5Camera library.
DEFOG_MODE read / write Not supported by G5Camera library.
DEHAZE_MODE read / write Dehaze mode (Turbulence mitigation). Supported values:
0 - Off.
1 - Minimum.
2 - Low.
3 - Medium.
4 - High.
5 - Maximum.
NOISE_REDUCTION_MODE read / write Not supported by G5Camera library.
BLACK_WHITE_FILTER_MODE read / write Not supported by G5Camera library.
FILTER_MODE read / write Filter mode. Supported values 0-10:
0 - Off.
1 - Makes the image appear slightly sharper.
5 - Makes the image appear very sharp with enhanced edges.
Intermediate values gradually increase the sharpening strength between 1 and 10.
NUC_MODE read / write NUC mode for thermal cameras. Default values:
0 - Manual (AUTOCAL:OFF).
1 - Auto (AUTOCAL:ON). When set to 1 the library first sends the currently stored AUTO_NUC_INTERVAL_MSEC value so that auto calibration never starts with the interval saved in the camera.
AUTO_NUC_INTERVAL_MSEC read / write Auto NUC interval for thermal cameras. Value in milliseconds starting from 1000 to 32767000 (1-32767 seconds, the AUTOCALINT range). The value is sent to the camera in seconds (AUTOCALINT). If NUC_MODE is 1, auto calibration is re-armed (AUTOCAL:ON) so that the set interval takes effect immediately. Default: 900000 (camera factory default).
IMAGE_FLIP read / write Not supported by G5Camera library.
DDE_MODE read / write Not supported by G5Camera library.
DDE_LEVEL read / write Not supported by G5Camera library.
ROI_X0 read / write AGC ROI top-left X position. The AGC ROI will be applied to camera only when all ROI parameters are set (ROI_X0, ROI_Y0, ROI_X1, ROI_Y1).
ROI_Y0 read / write AGC ROI top-left Y position. The AGC ROI will be applied to camera only when all ROI parameters are set (ROI_X0, ROI_Y0, ROI_X1, ROI_Y1).
ROI_X1 read / write AGC ROI bottom-right X position. The AGC ROI will be applied to camera only when all ROI parameters are set (ROI_X0, ROI_Y0, ROI_X1, ROI_Y1).
ROI_Y1 read / write AGC ROI bottom-right Y position. The AGC ROI will be applied to camera only when all ROI parameters are set (ROI_X0, ROI_Y0, ROI_X1, ROI_Y1).
TEMPERATURE read only Camera working hours (RUNTIME). The library reuses the temperature field of CameraParams to expose the RUNTIME value reported by the camera (in hours).
ALC_GATE read / write Analog gain and level time constant: 0-10. Default 4. Decreasing the value will cause the AGC to react quicker. A value of 0 tends to cause the image flicker occasionally.
SENSITIVITY read / write Sensor sensitivity. Supported values: -1, 0, 1.
CHANGING_MODE read / write Not supported by G5Camera library.
CHANGING_LEVEL read / write Not supported by G5Camera library.
CHROMA_LEVEL read / write Not supported by G5Camera library.
DETAIL read / write Not supported by G5Camera library.
PROFILE read / write Not supported by G5Camera library.
IS_CONNECTED read only Connection status. Value: 0 - no camera responses, 1 - connected.
IS_OPEN read only Controller initialization status. The open status shows if the controller is initialized but doesn’t show if the controller has communication with the equipment. Values: 0 - not open (not initialized), 1 - open (initialized).
TYPE read / write Not supported by G5Camera library.
CUSTOM_1 read / write Turbulence mitigation ROI. Default 1 (applied on initialization if 0). Supported values:
1 - ¼ of image
2 - ½ of image
3 - ¾ of image
4 - whole image
5 - top 1/3 of image
6 - middle 1/3 of image
7 - bottom 1/3 of image
CUSTOM_2 read / write Turbulence mitigation quality mode. Default value 2 (40%):
0 - 0 (%).
1 - 20 (%).
2 - 40 (%).
3 - 60 (%).
4 - 80 (%).
5 - 100 (%).
CUSTOM_3 read / write Turbulence mitigation level. Default value 0 (100%):
0 - 100 (%).
1 - 80 (%).
2 - 60 (%).
3 - 40 (%).
4 - 20 (%).
5 - 0 (%).

LensParams class description

LensParams class is used for lens initialization or to get all actual parameters. Also LensParams provides structure to write/read parameters from JSON files (JSON_READABLE macro) and provides methods to encode and decode parameters.

LensParams class declaration

LensParams interface class declared in Lens.h file. Class declaration:

class LensParams
{
public:
    /// Initialization string.
    std::string initString{"/dev/ttyUSB0;9600;20"};
    /// Zoom position.
    int zoomPos{0};
    /// Hardware zoom position.
    int zoomHwPos{0};
    /// Focus position.
    int focusPos{0};
    /// Hardware focus position.
    int focusHwPos{0};
    /// Iris position.
    int irisPos{0};
    /// Hardware iris position.
    int irisHwPos{0};
    /// Focus mode.
    int focusMode{0};
    /// Filter mode.
    int filterMode{0};
    /// Autofocus ROI top-left corner horizontal position in pixels.
    int afRoiX0{0};
    /// Autofocus ROI top-left corner vertical position in pixels.
    int afRoiY0{0};
    /// Autofocus ROI bottom-right corner horizontal position in pixels.
    int afRoiX1{0};
    /// Autofocus ROI bottom-right corner vertical position in pixels.
    int afRoiY1{0};
    /// Zoom speed.
    int zoomSpeed{50};
    /// Zoom hardware speed.
    int zoomHwSpeed{50};
    /// Maximum zoom hardware speed.
    int zoomHwMaxSpeed{50};
    /// Focus speed.
    int focusSpeed{50};
    /// Focus hardware speed.
    int focusHwSpeed{50};
    /// Maximum focus hardware speed.
    int focusHwMaxSpeed{50};
    /// Iris speed.
    int irisSpeed{50};
    /// Iris hardware speed.
    int irisHwSpeed{50};
    /// Maximum iris hardware speed.
    int irisHwMaxSpeed{50};
    /// Zoom hardware tele limit.
    int zoomHwTeleLimit{65535};
    /// Zoom hardware wide limit.
    int zoomHwWideLimit{0};
    /// Focus hardware far limit.
    int focusHwFarLimit{65535};
    /// Focus hardware near limit.
    int focusHwNearLimit{0};
    /// Iris hardware open limit.
    int irisHwOpenLimit{65535};
    /// Iris hardware close limit.
    int irisHwCloseLimit{0};
    /// Focus factor if it was calculated.
    float focusFactor{0.0f};
    /// Lens connection status.
    bool isConnected{false};
    /// Focus hardware speed in autofocus mode.
    int afHwSpeed{50};
    /// Threshold for changes of focus factor to start refocus.
    float focusFactorThreshold{0.0f};
    /// Timeout for automatic refocus in seconds.
    int refocusTimeoutSec{0};
    /// Flag about active autofocus algorithm.
    bool afIsActive{false};
    /// Iris mode.
    int irisMode{0};
    /// ROI width (pixels) for autofocus algorithm.
    int autoAfRoiWidth{150};
    /// ROI height (pixels) for autofocus algorithm.
    int autoAfRoiHeight{150};
    /// Video frame border size (along vertical and horizontal axes).
    int autoAfRoiBorder{100};
    /// AF ROI mode (write/read).
    int afRoiMode{0};
    /// Lens extender mode.
    int extenderMode{0};
    /// Lens stabilization mode.
    int stabiliserMode{0};
    /// Autofocus range.
    int afRange{0};
    /// Current horizontal Field of view, degree.
    float xFovDeg{1.0f};
    /// Current vertical Field of view, degree.
    float yFovDeg{1.0f};
    /// Logging mode.
    int logMode{0};
    /// Lens temperature, degree (read only).
    float temperature{0.0f};
    /// Lens controller initialization status.
    bool isOpen{false};
    /// Lens type.
    int type{0};
    /// Lens custom parameter.
    float custom1{0.0f};
    /// Lens custom parameter.
    float custom2{0.0f};
    /// Lens custom parameter.
    float custom3{0.0f};
    /// List of points to calculate field of view.
    std::vector<FovPoint> fovPoints{std::vector<FovPoint>()};

    JSON_READABLE(LensParams, initString, focusMode, filterMode,
                  afRoiX0, afRoiY0, afRoiX1, afRoiY1, zoomHwMaxSpeed,
                  focusHwMaxSpeed, irisHwMaxSpeed, zoomHwTeleLimit,
                  zoomHwWideLimit, focusHwFarLimit, focusHwNearLimit,
                  irisHwOpenLimit, irisHwCloseLimit, afHwSpeed,
                  focusFactorThreshold, refocusTimeoutSec, irisMode,
                  autoAfRoiWidth, autoAfRoiHeight, autoAfRoiBorder,
                  afRoiMode, extenderMode, stabiliserMode, afRange,
                  logMode, type, custom1, custom2, custom3, fovPoints)

    /// Default constructor.
    LensParams() = default;

    /// Copy constructor.
    LensParams(const LensParams& src) = default;

    /// Move constructor.
    LensParams(LensParams&& src) = default;

    /// Copy assignment operator.
    LensParams& operator= (const LensParams& src) = default;

    /// Move assignment operator.
    LensParams& operator= (LensParams&& src) = default;

    /// Encode (serialize) params. The method doesn't encode initString and
    /// fovPoints.
    bool encode(uint8_t* data, int bufferSize, int& size,
                LensParamsMask* mask = nullptr);

    /// Decode (deserialize) params encoded by encode(...) method. The method
    /// doesn't decode initString and fovPoints.
    bool decode(uint8_t* data, int dataSize);
};

FovPoint class (declared in Lens.h file) describes a point of the field of view table: the hardware zoom position and the horizontal and vertical field of view in this position. Class declaration:

class FovPoint
{
public:
    /// Hardware zoom pos.
    int hwZoomPos{0};
    /// Horizontal field of view, degree.
    float xFovDeg{0.0f};
    /// Vertical field of view, degree.
    float yFovDeg{0.0f};

    JSON_READABLE(FovPoint, hwZoomPos, xFovDeg, yFovDeg)

    /// Default constructor.
    FovPoint() = default;

    /// Copy constructor.
    FovPoint(const FovPoint& src) = default;

    /// Move constructor.
    FovPoint(FovPoint&& src) = default;

    /// Copy assignment operator.
    FovPoint& operator= (const FovPoint& src) = default;

    /// Move assignment operator.
    FovPoint& operator= (FovPoint&& src) = default;
};

LensParams class fields description is equivalent to LensParam enum description except initString and fovPoints. initString : [serial port name];[baudrate];[timeout].

Serialize lens params

LensParams class provides method encode(…) to serialize lens params. Serialization of lens params necessary in case when you need to send lens params via communication channels. Method doesn’t encode initString string field and fovPoints. Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask (7 bytes) where each bit represents particular parameter and decode(…) method recognizes it. Method declaration:

bool encode(uint8_t* data, int bufferSize, int& size, LensParamsMask* mask = nullptr);
Parameter Value
data Pointer to data buffer. Must not be nullptr and must be valid for bufferSize bytes.
bufferSize Data buffer size. Buffer size must be >= 201 bytes (the size of data with all params encoded), regardless of the mask.
size Size of encoded data, bytes. Will be 0 if params are not encoded.
mask Parameters mask - pointer to LensParamsMask structure. LensParamsMask (declared in Lens.h file) determines flags for each field (parameter) declared in LensParams class. If the user wants to exclude any parameters from serialization, he can put a pointer to the mask. If the pointer is nullptr, all params are encoded. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the LensParamsMask structure to false (all flags are true by default).

Returns: TRUE if params encoded (serialized) or FALSE if not (data is nullptr or bufferSize is less than 201).

Encoded data format:

Byte Value Description
0 0x02 Params data type header value.
1 Major Major version of Lens class.
2 Minor Minor version of Lens class.
3-9 mask Params mask (7 bytes). Each bit represents one field of LensParamsMask in the order of the declaration: the first field is the most significant bit of byte 3, the 8th field is the least significant bit of byte 3, the 9th field is the most significant bit of byte 4 and so on. The bit is set if the param is encoded. The 6 least significant bits of byte 9 are not used and always 0.
10-N values Values of the encoded params in the order of the LensParamsMask fields. int and float params use 4 bytes in host byte order (Little-endian on x86-64 and ARM Linux systems). bool params (isConnected, afIsActive, isOpen) use 1 byte: 0x01 - true, 0x00 - false.

The size of encoded data is 10 bytes if no params are encoded and 201 bytes if all params are encoded.

LensParamsMask structure declaration:

typedef struct LensParamsMask
{
    bool zoomPos{true};
    bool zoomHwPos{true};
    bool focusPos{true};
    bool focusHwPos{true};
    bool irisPos{true};
    bool irisHwPos{true};
    bool focusMode{true};
    bool filterMode{true};
    bool afRoiX0{true};
    bool afRoiY0{true};
    bool afRoiX1{true};
    bool afRoiY1{true};
    bool zoomSpeed{true};
    bool zoomHwSpeed{true};
    bool zoomHwMaxSpeed{true};
    bool focusSpeed{true};
    bool focusHwSpeed{true};
    bool focusHwMaxSpeed{true};
    bool irisSpeed{true};
    bool irisHwSpeed{true};
    bool irisHwMaxSpeed{true};
    bool zoomHwTeleLimit{true};
    bool zoomHwWideLimit{true};
    bool focusHwFarLimit{true};
    bool focusHwNearLimit{true};
    bool irisHwOpenLimit{true};
    bool irisHwCloseLimit{true};
    bool focusFactor{true};
    bool isConnected{true};
    bool afHwSpeed{true};
    bool focusFactorThreshold{true};
    bool refocusTimeoutSec{true};
    bool afIsActive{true};
    bool irisMode{true};
    bool autoAfRoiWidth{true};
    bool autoAfRoiHeight{true};
    bool autoAfRoiBorder{true};
    bool afRoiMode{true};
    bool extenderMode{true};
    bool stabiliserMode{true};
    bool afRange{true};
    bool xFovDeg{true};
    bool yFovDeg{true};
    bool logMode{true};
    bool temperature{true};
    bool isOpen{true};
    bool type{true};
    bool custom1{true};
    bool custom2{true};
    bool custom3{true};
} LensParamsMask;

Example without parameters mask:

// Encode data.
rapidpixel::LensParams in;
in.logMode = 3;
uint8_t data[201];
int size = 0;
if (!in.encode(data, 201, size))
{
    std::cout << "Can't encode params" << std::endl;
    return 1;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

The example prints “Encoded data size: 201 bytes”.

Example with parameters mask:

// Prepare params.
rapidpixel::LensParams in;
in.logMode = 3;

// Prepare mask.
rapidpixel::LensParamsMask mask;
mask.logMode = false; // Exclude logMode. Others by default.

// Encode.
uint8_t data[201];
int size = 0;
if (!in.encode(data, 201, size, &mask))
{
    std::cout << "Can't encode params" << std::endl;
    return 1;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

The example prints “Encoded data size: 197 bytes”.

Deserialize lens params

LensParams class provides method decode(…) to deserialize lens params. Deserialization of lens params necessary in case when you need to receive lens params via communication channels. Method automatically recognizes which parameters were serialized by encode(…) method. Method doesn’t decode fields: initString and fovPoints (after decoding initString is an empty string and fovPoints is empty). Parameters which were not serialized are set to 0 (false for bool parameters), not to the default values. Method declaration:

bool decode(uint8_t* data, int dataSize);
Parameter Value
data Pointer to data buffer with serialized params. Must not be nullptr and must be valid for dataSize bytes.
dataSize Size of data, bytes.

Returns: TRUE if data decoded (deserialized) or FALSE if not. If FALSE is returned the object is not changed.

The method returns FALSE if data is nullptr, dataSize is less than 10 (the size of the header), the first byte is not 0x02, Major or Minor version in the data (bytes 1 and 2) is not equal to the version of the Lens class, the 6 least significant bits of byte 9 (the unused bits of the mask) are not 0 or the data is too short for the params selected by the mask. Bytes after the last encoded param are ignored. Values of params are not checked against any range: the lens controller must validate them before use.

Example:

// Encode data.
rapidpixel::LensParams in;
uint8_t data[201];
int size = 0;
if (!in.encode(data, 201, size))
{
    std::cout << "Can't encode params" << std::endl;
    return 1;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

// Decode data.
rapidpixel::LensParams out;
if (!out.decode(data, size))
{
    std::cout << "Can't decode data" << std::endl;
    return 1;
}

Read and write lens params to JSON file

Lens interface class library depends on the ConfigReader library which provides methods to read parameters from a JSON file and to write parameters to a JSON file. Only the fields listed in the JSON_READABLE macro of LensParams class are stored in the JSON file (for example zoomPos, zoomSpeed, isConnected, isOpen, xFovDeg, yFovDeg and temperature are not stored). Example of writing and reading parameters to a JSON file:

// Prepare params.
rapidpixel::LensParams in;
in.initString = "/dev/ttyUSB0;9600;100";
in.logMode = 3;
rapidpixel::FovPoint wide;
wide.hwZoomPos = 0;
wide.xFovDeg = 60.5f;
wide.yFovDeg = 40.0f;
in.fovPoints.push_back(wide);
rapidpixel::FovPoint tele;
tele.hwZoomPos = 1000;
tele.xFovDeg = 2.5f;
tele.yFovDeg = 1.5f;
in.fovPoints.push_back(tele);

// Write params to file.
rapidpixel::ConfigReader inConfig;
if (!inConfig.set(in, "lensParams") ||
    !inConfig.writeToFile("TestLensParams.json"))
{
    std::cout << "Can't write config file" << std::endl;
    return 1;
}

// Read params from file.
rapidpixel::ConfigReader outConfig;
if (!outConfig.readFromFile("TestLensParams.json"))
{
    std::cout << "Can't open config file" << std::endl;
    return 1;
}
rapidpixel::LensParams out;
if (!outConfig.get(out, "lensParams"))
{
    std::cout << "Can't read lens params" << std::endl;
    return 1;
}

TestLensParams.json will look like:

{
    "lensParams": {
        "initString": "/dev/ttyUSB0;9600;100",
        "focusMode": 0,
        "filterMode": 0,
        "afRoiX0": 0,
        "afRoiY0": 0,
        "afRoiX1": 0,
        "afRoiY1": 0,
        "zoomHwMaxSpeed": 50,
        "focusHwMaxSpeed": 50,
        "irisHwMaxSpeed": 50,
        "zoomHwTeleLimit": 65535,
        "zoomHwWideLimit": 0,
        "focusHwFarLimit": 65535,
        "focusHwNearLimit": 0,
        "irisHwOpenLimit": 65535,
        "irisHwCloseLimit": 0,
        "afHwSpeed": 50,
        "focusFactorThreshold": 0.0,
        "refocusTimeoutSec": 0,
        "irisMode": 0,
        "autoAfRoiWidth": 150,
        "autoAfRoiHeight": 150,
        "autoAfRoiBorder": 100,
        "afRoiMode": 0,
        "extenderMode": 0,
        "stabiliserMode": 0,
        "afRange": 0,
        "logMode": 3,
        "type": 0,
        "custom1": 0.0,
        "custom2": 0.0,
        "custom3": 0.0,
        "fovPoints": [
            {
                "hwZoomPos": 0,
                "xFovDeg": 60.5,
                "yFovDeg": 40.0
            },
            {
                "hwZoomPos": 1000,
                "xFovDeg": 2.5,
                "yFovDeg": 1.5
            }
        ]
    }
}

CameraParams class description

CameraParams class is used for camera controller initialization or to get all actual parameters. Also CameraParams provides structure to write/read parameters from JSON files (JSON_READABLE macro) and provides methods to encode and decode parameters.

CameraParams Class declaration

CameraParams interface class declared in Camera.h file. Class declaration:

class CameraParams
{
public:
    /// Initialization string.
    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. 
    int displayMode{0};
    /// Video output type.
    int videoOutput{0};
    /// Logging mode.
    int logMode{0};
    /// Exposure mode. 
    int exposureMode{1};
    /// Exposure time of the camera sensor.
    int exposureTime{0};
    /// White balance mode. 
    int whiteBalanceMode{1};
    /// White balance area.
    int whiteBalanceArea{0};
    /// White dynamic range mode.
    int wideDynamicRangeMode{0};
    /// Image stabilization mode.
    int stabilizationMode{0};
    /// ISO sensitivity.
    int isoSensitivity{0};
    /// Scene mode.
    int sceneMode{0};
    /// FPS.
    float fps{0.0f};
    /// Brightness mode.
    int brightnessMode{1};
    /// Brightness. Value 0 - 100%.
    int brightness{0};
    /// Contrast. Value 1 - 100%.
    int contrast{0};
    /// Gain mode.
    int gainMode{1};
    /// Gain. Value 1 - 100%.
    int gain{0};
    /// Sharpening mode.
    int sharpeningMode{0};
    /// Sharpening. Value 1 - 100%.
    int sharpening{0};
    /// Palette.
    int palette{0};
    /// Analog gain control mode.
    int agcMode{1};
    /// Shutter mode.
    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.
    int digitalZoomMode{0};
    /// Digital zoom. Value 1.0 (x1) - 20.0 (x20).
    float digitalZoom{1.0f};
    /// Exposure compensation mode.
    int exposureCompensationMode{0};
    /// Exposure compensation position.
    int exposureCompensationPosition{0};
    /// Defog mode. 
    int defogMode{0};
    /// Dehaze mode.
    int dehazeMode{0};
    /// Noise reduction mode.
    int noiseReductionMode{0};
    /// Black and white filter mode.
    int blackAndWhiteFilterMode{0};
    /// Filter mode.
    int filterMode{0};
    /// NUC mode for thermal cameras.
    int nucMode{0};
    /// Auto NUC interval for thermal cameras.
    int autoNucIntervalMsec{0};
    /// Image flip mode. 
    int imageFlip{0};
    /// DDE mode.
    int ddeMode{0};
    /// DDE level.
    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.
    int alcGate{0};
    /// Sensor sensitivity.
    float sensitivity{0};
    /// Changing mode (day / night).
    int changingMode{0};
    /// Changing level (day / night).
    float changingLevel{0.0f};
    /// Chroma level. Values: 0 - 100%.
    int chromaLevel{0};
    /// Details, enhancement. Values: 0 - 100%.
    int detail{0};
    /// Camera settings profile.
    int profile{0};
    /// Connection status (read only).
    bool isConnected{false};
    /// Open status (read only).
    bool isOpen{false};
    /// Camera type.
    int type{0};
    /// Camera custom param.
    float custom1{0.0f};
    /// Camera custom param.
    float custom2{0.0f};
    /// Camera custom param.
    float custom3{0.0f};

    // JSON read / write of the fields. The fields temperature, isConnected and
    // isOpen are not stored in JSON.
    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)

    /// Default constructor. All fields have default values.
    CameraParams() = default;

    /// Copy constructor.
    CameraParams(const CameraParams& src) = default;

    /// Move constructor.
    CameraParams(CameraParams&& src) = default;

    /// Copy assignment operator.
    CameraParams& operator= (const CameraParams& src) = default;

    /// Move assignment operator.
    CameraParams& operator= (CameraParams&& src) = default;

    /// Encode (serialize) params. The method doesn't encode initString.
    bool encode(uint8_t* data, int bufferSize, int& size,
                CameraParamsMask* mask = nullptr);

    /// Decode (deserialize) params encoded by encode(...) method. The method
    /// doesn't decode initString.
    bool decode(uint8_t* data, int dataSize);
};

CameraParams class fields description is equivalent to CameraParam enum description except initString. initString :
- [serial port name];[baudrate];[timeout].

Serialize camera params

CameraParams class provides method encode(…) to serialize camera params. Serialization of camera params necessary in case when you have to send camera params via communication channels. Method doesn’t encode initString field. Method provides options to exclude particular parameters from serialization. To do this method inserts binary mask (8 bytes) where each bit represents particular parameter and decode(…) method recognizes it. Method declaration:

bool encode(uint8_t* data, int bufferSize, int& size, CameraParamsMask* mask = nullptr);
Parameter Value
data Pointer to data buffer. Must not be nullptr. The method can’t check the buffer size: the buffer must be valid for bufferSize bytes.
bufferSize Data buffer size. Buffer size must be >= 237 bytes (the size of data with all params encoded), regardless of the mask.
size Size of encoded data, bytes. Will be 0 if params are not encoded.
mask Parameters mask - pointer to CameraParamsMask structure. CameraParamsMask (declared in Camera.h file) determines flags for each field (parameter) declared in CameraParams class. If the user wants to exclude any parameters from serialization, he can put a pointer to the mask. If the pointer is nullptr, all params are encoded. If the user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the CameraParamsMask structure to false (all flags are true by default).

Returns: TRUE if params encoded (serialized) or FALSE if not (data is nullptr or bufferSize is less than 237).

Encoded data format:

Byte Value Description
0 0x02 Params data type header value.
1 Major Major version of Camera class.
2 Minor Minor version of Camera class.
3-10 mask Params mask (8 bytes). Each bit represents one field of CameraParamsMask in the order of the declaration: the first field is the most significant bit of byte 3, the 8th field is the least significant bit of byte 3, the 9th field is the most significant bit of byte 4 and so on. The bit is set if the param is encoded. The 6 least significant bits of byte 10 are not used and always 0.
11-N values Values of the encoded params in the order of the CameraParamsMask fields. int and float params use 4 bytes in host byte order (Little-endian on x86-64 and ARM Linux systems). bool params (isConnected, isOpen) use 1 byte: 0x01 - true, 0x00 - false.

The size of encoded data is 11 bytes if no params are encoded and 237 bytes if all params are encoded.

CameraParamsMask structure declaration:

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;

Example without parameters mask:

// Encode data.
rapidpixel::CameraParams in;
in.profile = 10;
uint8_t data[237];
int size = 0;
if (!in.encode(data, 237, size))
{
    std::cout << "Can't encode params" << std::endl;
    return 1;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

The example prints “Encoded data size: 237 bytes”.

Example with parameters mask:

// Prepare params.
rapidpixel::CameraParams in;
in.profile = 3;

// Prepare mask.
rapidpixel::CameraParamsMask mask;
mask.profile = false; // Exclude profile. Others by default.

// Encode.
uint8_t data[237];
int size = 0;
if (!in.encode(data, 237, size, &mask))
{
    std::cout << "Can't encode params" << std::endl;
    return 1;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

The example prints “Encoded data size: 233 bytes”.

Deserialize camera params

CameraParams class provides method decode(…) to deserialize camera params (fields of CameraParams class, see Table 5). Deserialization of camera params necessary in case when you need to receive params via communication channels. Method automatically recognizes which parameters were serialized by encode(…) method. Method doesn’t decode initString field (after decoding initString is an empty string). Parameters which were not serialized are set to 0 (false for bool parameters), not to the default values. Method declaration:

bool decode(uint8_t* data, int dataSize);
Parameter Value
data Pointer to data buffer with serialized camera params. Must not be nullptr.
dataSize Size of data, bytes. Must be >= 11 (the size of data without params).

Returns: TRUE if params decoded (deserialized) or FALSE if not. If FALSE is returned the object is not changed.

The method returns FALSE if data is nullptr, dataSize is less than 11 (the size of the header), the first byte is not 0x02, Major or Minor version in the data (bytes 1 and 2) is not equal to the version of the Camera class or the data is too short for the params selected by the mask. The unused bits of the mask (the 6 least significant bits of byte 10) and the bytes after the last encoded param are ignored. Values of params are not checked against any range: the camera controller must validate them before use.

Example:

// Encode data.
rapidpixel::CameraParams in;
uint8_t data[237];
int size = 0;
if (!in.encode(data, 237, size))
{
    std::cout << "Can't encode params" << std::endl;
    return 1;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;

// Decode data.
rapidpixel::CameraParams out;
if (!out.decode(data, size))
{
    std::cout << "Can't decode data" << std::endl;
    return 1;
}

Read and write camera params to JSON file

Camera library depends on the ConfigReader library which provides methods to read parameters from a JSON file and to write parameters to a JSON file. The fields temperature, isConnected and isOpen of CameraParams class are not stored in the JSON file. Example of writing and reading parameters to a JSON file:

// Prepare params.
rapidpixel::CameraParams in;
in.initString = "/dev/ttyUSB0;9600;100";
in.logMode = 3;

// Write params to file.
rapidpixel::ConfigReader inConfig;
if (!inConfig.set(in, "cameraParams") ||
    !inConfig.writeToFile("TestCameraParams.json"))
{
    std::cout << "Can't write config file" << std::endl;
    return 1;
}

// Read params from file.
rapidpixel::ConfigReader outConfig;
if (!outConfig.readFromFile("TestCameraParams.json"))
{
    std::cout << "Can't open config file" << std::endl;
    return 1;
}
rapidpixel::CameraParams out;
if (!outConfig.get(out, "cameraParams"))
{
    std::cout << "Can't read camera params" << std::endl;
    return 1;
}

TestCameraParams.json will look like:

{
    "cameraParams": {
        "initString": "/dev/ttyUSB0;9600;100",
        "width": 0,
        "height": 0,
        "displayMode": 0,
        "videoOutput": 0,
        "logMode": 3,
        "exposureMode": 1,
        "exposureTime": 0,
        "whiteBalanceMode": 1,
        "whiteBalanceArea": 0,
        "wideDynamicRangeMode": 0,
        "stabilizationMode": 0,
        "isoSensitivity": 0,
        "sceneMode": 0,
        "fps": 0.0,
        "brightnessMode": 1,
        "brightness": 0,
        "contrast": 0,
        "gainMode": 1,
        "gain": 0,
        "sharpeningMode": 0,
        "sharpening": 0,
        "palette": 0,
        "agcMode": 1,
        "shutterMode": 1,
        "shutterPos": 0,
        "shutterSpeed": 0,
        "digitalZoomMode": 0,
        "digitalZoom": 1.0,
        "exposureCompensationMode": 0,
        "exposureCompensationPosition": 0,
        "defogMode": 0,
        "dehazeMode": 0,
        "noiseReductionMode": 0,
        "blackAndWhiteFilterMode": 0,
        "filterMode": 0,
        "nucMode": 0,
        "autoNucIntervalMsec": 0,
        "imageFlip": 0,
        "ddeMode": 0,
        "ddeLevel": 0.0,
        "roiX0": 0,
        "roiY0": 0,
        "roiX1": 0,
        "roiY1": 0,
        "alcGate": 0,
        "sensitivity": 0.0,
        "changingMode": 0,
        "changingLevel": 0.0,
        "chromaLevel": 0,
        "detail": 0,
        "profile": 0,
        "type": 0,
        "custom1": 0.0,
        "custom2": 0.0,
        "custom3": 0.0
    }
}

Build and connect to your project

Build stand alone

The repository does not contain sub-repositories. The protocol parser library G5ProtocolParser is a part of the repository (folder src/parser, see src/parser/README.md): the main CMakeLists.txt file of the library adds it before the library itself in every build (stand alone and included in another project), so it is not cloned and not added separately; its test application (src/parser/test) is not built. The other libraries G5Camera depends on (Frame, ConfigReader, Camera, Lens, SerialPort and Logger) must be cloned into the same folder as G5Camera. The folder structure must be:

<work folder>
    G5Camera
    Frame
    ConfigReader
    Camera
    Lens
    SerialPort
    Logger

Typical commands to build the library and the test application (use the URLs of the repositories provided to you):

git clone <G5Camera repository URL>
git clone <Frame repository URL>
git clone <ConfigReader repository URL>
git clone <Camera repository URL>
git clone <Lens repository URL>
git clone <SerialPort repository URL>
git clone <Logger repository URL>
cd G5Camera
mkdir build
cd build
cmake ..
make

On Windows use cmake --build . --config Release instead of make. The test application is built to the bin folder of the build folder. If G5Camera is the top-level CMake project, the main CMakeLists.txt file adds the folders ../Frame, ../ConfigReader, ../Camera, ../Lens, ../SerialPort and ../Logger (in this order) before the library itself. If a folder does not exist CMake stops with an error.

CMake options

Table 6 - CMake options of the repository. In the options below ${PARENT} is the prefix defined by the top-level project (empty if G5Camera is the top-level project).

Option Default Description
${PARENT}_G5_CAMERA ON Build the library.
${PARENT}_G5_CAMERA_TEST ON (stand alone), OFF (included in other project) Build the test application.
${PARENT}_SUBMODULE_CACHE_OVERWRITE ON Forced rewriting of the options above in the CMake cache. The top-level project sets it to OFF when it includes G5Camera as a sub-repository.
CMAKE_BUILD_TYPE Release (if not specified) Build type.

Connect to your project

If you want to connect the G5Camera library to your CMake project as source code, you can do the following. For example, if your repository has the structure:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp

Create a 3rdparty folder in your repository folder and clone there the G5Camera repository and the repositories of all libraries it depends on. The new structure of your repository:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp
3rdparty
    G5Camera
    Frame
    ConfigReader
    Camera
    Lens
    SerialPort
    Logger

Create a CMakeLists.txt file in the 3rdparty folder. The CMakeLists.txt adds the libraries in the order of their mutual dependencies and the G5Camera library after them. It should contain:

cmake_minimum_required(VERSION 3.13)

################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)

################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)

################################################################################
## CONFIGURATION
## 3rd-party submodules configuration
################################################################################
SET(${PARENT}_SUBMODULE_FRAME                           ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_FRAME)
    SET(${PARENT}_FRAME                                 ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_FRAME_TEST                            OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_CONFIG_READER                   ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_CONFIG_READER)
    SET(${PARENT}_CONFIG_READER                         ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_EXAMPLES                OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_CONFIG_READER_TESTS                   OFF CACHE BOOL "" FORCE)
endif()

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()

SET(${PARENT}_SUBMODULE_LENS                            ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_LENS)
    SET(${PARENT}_LENS                                  ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_LENS_TEST                             OFF CACHE BOOL "" FORCE)
    SET(${PARENT}_LENS_EXAMPLE                          OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_SERIAL_PORT                     ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_SERIAL_PORT)
    SET(${PARENT}_SERIAL_PORT                           ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_SERIAL_PORT_EXAMPLES                  OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_LOGGER                          ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_LOGGER)
    SET(${PARENT}_LOGGER                                ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_LOGGER_EXAMPLE                        OFF CACHE BOOL "" FORCE)
endif()

SET(${PARENT}_SUBMODULE_G5_CAMERA                       ON  CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_G5_CAMERA)
    SET(${PARENT}_G5_CAMERA                             ON  CACHE BOOL "" FORCE)
    SET(${PARENT}_G5_CAMERA_TEST                        OFF CACHE BOOL "" FORCE)
endif()

################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_FRAME)
    add_subdirectory(Frame)
endif()

if (${PARENT}_SUBMODULE_CONFIG_READER)
    add_subdirectory(ConfigReader)
endif()

if (${PARENT}_SUBMODULE_CAMERA)
    add_subdirectory(Camera)
endif()

if (${PARENT}_SUBMODULE_LENS)
    add_subdirectory(Lens)
endif()

if (${PARENT}_SUBMODULE_SERIAL_PORT)
    add_subdirectory(SerialPort)
endif()

if (${PARENT}_SUBMODULE_LOGGER)
    add_subdirectory(Logger)
endif()

if (${PARENT}_SUBMODULE_G5_CAMERA)
    add_subdirectory(G5Camera)
endif()

The 3rdparty/CMakeLists.txt file adds the G5Camera folder and its dependencies to your project and excludes the test application from compiling (by default, the test application is excluded from compiling if G5Camera is included as a sub-repository). When G5Camera is included in another project it does not add its dependencies: the project must add them (before or after G5Camera, the order does not matter). If a dependency is not added the compilation stops with an error such as SerialPort.h: No such file or directory. The new structure of your repository:

CMakeLists.txt
src
    CMakeLists.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    G5Camera
    Frame
    ConfigReader
    Camera
    Lens
    SerialPort
    Logger

Next, you need to include the 3rdparty folder in the main CMakeLists.txt file of your repository. Add the following line at the end of your main CMakeLists.txt:

add_subdirectory(3rdparty)

Next, you have to include the G5Camera library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} G5Camera)

Done!

Simple example

The simple example is an application that initializes the controller and provides the user with a few options to control the camera.

#include <iostream>
#include "G5Camera.h"

int main()
{
    // Init camera controller.
    rapidpixel::G5Camera controller;
    if (!controller.openCamera("/dev/ttyUSB0;115200;100"))
    {
        std::cout << "Can't open serial port." << std::endl;
        return 1;
    }

    // Main loop. It ends by the option 0 or at the end of the input.
    while (true)
    {
        // Main dialog.
        int option = -1;
        std::cout << "Options (0:Exit, 1:Zoom tele, 2:Zoom wide, " <<
        "3:Zoom stop, 4:Contrast+1, 5:Contrast-1) : ";
        if (!(std::cin >> option))
        {
            break;
        }

        // Get all camera params.
        rapidpixel::CameraParams cameraParams;
        controller.getParams(cameraParams);

        bool isExecuted = true;
        switch (option)
        {
        case 0: // Exit.
            controller.closeCamera();
            return 0;
        case 1: // Zoom tele.
            isExecuted = controller.executeCommand(
                rapidpixel::LensCommand::ZOOM_TELE);
            break;
        case 2: // Zoom wide.
            isExecuted = controller.executeCommand(
                rapidpixel::LensCommand::ZOOM_WIDE);
            break;
        case 3: // Zoom stop.
            isExecuted = controller.executeCommand(
                rapidpixel::LensCommand::ZOOM_STOP);
            break;
        case 4: // Contrast + 1.
            isExecuted = controller.setParam(
                rapidpixel::CameraParam::CONTRAST,
                static_cast<float>(cameraParams.contrast + 1));
            break;
        case 5: // Contrast - 1.
            isExecuted = controller.setParam(
                rapidpixel::CameraParam::CONTRAST,
                static_cast<float>(cameraParams.contrast - 1));
            break;
        default:
            std::cout << "Wrong option." << std::endl;
            break;
        }

        if (!isExecuted)
        {
            std::cout << "Can't execute command." << std::endl;
        }
    }

    controller.closeCamera();
    return 0;
}

Test application

The G5Camera/test folder contains a test application that demonstrates how to use the G5Camera library. The test application allows the user to connect to a camera, set and get camera parameters, and execute commands.

The test application shows an introduction message and prompts the user for the camera port name and baudrate. After connecting to the camera, it displays the main menu, which allows setting/getting camera parameters and executing commands. The option 0 closes the camera and exits the application (the application also exits at the end of the input).

The test application output will look like:

================================================
G5 camera controller v2.7.0 test
================================================
Set serial port name (1 - /dev/ttyUSB0): 1
Set baudrate: 115200
Serial port open!

Choose command:
0 - Exit
1 - Zoom tele
2 - Zoom wide
3 - Zoom stop
4 - Focus near
5 - Focus far
6 - Focus stop
7 - Get zoom position
8 - Get focus position
9 - Start AF
11 - RunNuc
12 - DZoom
13 - Freeze/Defreeze
14 - Palette
15 - Sensitivity
16 - Gain mode
17 - Gain
18 - Agc mode
19 - Dehaze mode
20 - Stabilization mode
21 - Sharpening mode
22 - Filter
23 - Turbulence roi mode
24 - Turbulence quality
25 - Turbulence motion
26 - Display mode
27 - FOV angle

Table of contents