
FlirBosonCamera C++ library
v3.0.2
Table of contents
- Overview
- Versions
- Library files
- FlirBosonCamera class description
- FlirBosonCamera class declaration
- getVersion method
- openCamera method
- initCamera method
- closeCamera method
- isCameraOpen method
- isCameraConnected method
- setParam method
- getParam method
- getParams method
- executeCommand method
- decodeAndExecuteCommand method
- encodeSetParamCommand method of Camera class
- encodeCommand method of Camera class
- decodeCommand method of Camera class
- Data structures
- CameraParams class description
- Build and connect to your project
- Simple example
- Test application
- Portability
Overview
The FlirBosonCamera C++ library is a software controller for the FLIR Boson camera. The FlirBosonCamera library inherits the Camera interface. It depends on the following libraries: Camera (provides interface and data structures to control cameras), Logger (provides functions to print log information in console and files), BosonProtocol (implements the Boson serial command protocol and the command client, a folder of this repository) and SerialPort (provides functions to work with serial ports). The Camera library depends on the ConfigReader library. The FlirBosonCamera library provides a simple interface to be integrated into any C++ project. The library repository (folder) is provided as source code and doesn’t have third-party dependencies that need to be specially installed in the OS. The repository doesn’t contain sub-repositories: the ConfigReader, Camera, Logger and SerialPort repositories are placed next to it (see Build and connect to your project). It is developed with the C++17 standard. The library builds on Linux only: a check in src/CMakeLists.txt stops the configure step on any other system. Only the “USBBOSON” keyword of the initialization string uses a Linux device name (/dev/ttyACM0); any other initialization string passes its device name to the SerialPort library unchanged.
FlirBosonCamera 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 camera.
Versions
Table 1 - Library versions.
| Version | Release date | What’s new |
|---|---|---|
| 1.0.0 | 30.05.2023 | - First version |
| 2.0.0 | 07.03.2024 | - Interface updated. - Test application updated. - Documentation updated. |
| 2.0.1 | 11.03.2024 | - Code review and documentation update. |
| 2.0.2 | 23.05.2024 | - Documentation updated. - Submodules updated. |
| 2.0.3 | 07.08.2024 | - CMake structure updated. |
| 2.0.4 | 10.09.2024 | - Fix auto NUC interval units. |
| 2.0.5 | 03.12.2024 | - DDE Level supporting. |
| 2.0.6 | 10.12.2024 | - Added new supported parameters. |
| 2.0.7 | 24.01.2025 | - Added initialization preset. |
| 2.0.8 | 17.02.2025 | - Updated initialization procedure. |
| 2.0.9 | 03.04.2025 | - Logger submodule update. |
| 2.0.10 | 13.05.2025 | - Updated initialization procedure. |
| 2.1.0 | 28.05.2025 | - Updated initialization procedure. |
| 2.1.1 | 17.08.2025 | - Fix test application name. - Test application update. - Example update. |
| 2.1.2 | 18.11.2025 | - Updated initialization procedure. |
| 2.1.3 | 27.05.2026 | - Fixes for AUTO_NUC_INTERVAL_MSEC parameter. - Fix documentation. - Fix getParam for IS_CONNECTED and IS_OPEN params. - Clean test application. - Clean up code. - Fix small typos. |
| 2.1.4 | 20.07.2026 | - Set the colour format of the digital video output to fix the output image. |
| 3.0.0 | 03.09.2026 | - Camera communication reimplemented on BosonProtocol and SerialPort. - Every setParam that writes to the camera is now confirmed by reading the value back from it. LOG_MODE and CUSTOM_1 are controller-side settings and are stored locally; DDE_MODE shares one camera register with DDE_LEVEL, so it is stored as written rather than re-read, and DDE_LEVEL is re-read only while DDE_MODE is 1. - Test application reaches every implemented parameter and command and every method of the interface, and prints the value read back after each write. - Example reduced to a linear program; the code in this document is that file verbatim. - Documentation corrected against the implementation. |
| 3.0.1 | 12.10.2026 | - Submodules updated. |
| 3.0.2 | 17.10.2026 | - The repository contains no sub-repositories and no 3rdparty folder: ConfigReader, Camera, Logger and SerialPort are expected next to the repository when it is built stand alone. BosonProtocol is the folder src/BosonProtocol of the repository. - setParam rejects NaN, infinity and out-of-range values before anything is written to the camera, including AUTO_NUC_INTERVAL_MSEC and DIGITAL_ZOOM; an invalid LOG_MODE is not stored. - decodeAndExecuteCommand rejects a null pointer. - No exception leaves a method of the interface. - BosonProtocol: the frame parser resynchronises when a start byte follows an escape byte; the client writes a request in pieces if the port takes it in pieces, pauses when the port fails at once and limits the size of a request; generated commands reject a null pointer; the unused functionName is removed. - Warning and hardening flags in every target; no warnings with GCC 11, GCC 12 and the aarch64 cross compiler. - Test application and example restyled; the test application is a terminal program without video and without any other user interface. - initCamera keeps the open state of the controller (an open port is no longer left open when it fails) and replaces the fields that setParam would reject before they are stored or written. - BosonProtocol: a reply is accepted only on the command channel; a request of any allowed size is written to the end when the port takes it in pieces; the threshold of the flat field correction is documented in seconds. - Documentation corrected. |
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). The repository structure is shown below:
CMakeLists.txt ------------------- Main CMake file of the library.
example -------------------------- Folder with example application.
CMakeLists.txt --------------- CMake file for example application.
main.cpp --------------------- Source code file of example application.
src ------------------------------ Folder with source code of the library.
CMakeLists.txt --------------- CMake file of the library.
FlirBosonCamera.cpp ---------- Source code file of the library.
FlirBosonCamera.h ------------ Header file which includes the main class declaration.
FlirBosonCameraVersion.h ----- Header file which includes the version of the library.
FlirBosonCameraVersion.h.in -- CMake service file to generate version file.
BosonProtocol ---------------- Folder with BosonProtocol library source code.
CMakeLists.txt ----------- CMake file of the BosonProtocol library.
src ---------------------- Folder with source code of the BosonProtocol library.
static --------------------------- Folder with the logo of the library.
test ----------------------------- Folder with test application.
CMakeLists.txt --------------- CMake file for test application.
main.cpp --------------------- Source code file of test application.
FlirBosonCamera class description
FlirBosonCamera class declaration
The FlirBosonCamera interface class is declared in the FlirBosonCamera.h file. The FlirBosonCamera class inherits from the Camera interface. Class declaration:
class FlirBosonCamera : public rapidpixel::Camera
{
public:
/// Class constructor.
FlirBosonCamera();
/// Class destructor.
~FlirBosonCamera() override;
/// Copy constructor. Deleted: the object owns a serial port.
FlirBosonCamera(const FlirBosonCamera&) = delete;
/// Copy assignment. Deleted.
FlirBosonCamera& operator=(const FlirBosonCamera&) = delete;
/// Move constructor. Deleted.
FlirBosonCamera(FlirBosonCamera&&) = delete;
/// Move assignment. Deleted.
FlirBosonCamera& operator=(FlirBosonCamera&&) = delete;
/// Get FlirBosonCamera class version.
static std::string getVersion();
/// Open camera controller.
bool openCamera(std::string initString) override;
/// Initialize camera controller by parameters class.
bool initCamera(CameraParams& params) override;
/// Close camera controller.
void closeCamera() override;
/// Get camera open status.
bool isCameraOpen() override;
/// Get camera connection status.
bool isCameraConnected() override;
/// Set the camera controller param.
bool setParam(CameraParam id, float value) override;
/// Get the camera controller param.
float getParam(CameraParam id) override;
/// Get the camera controller params.
void getParams(CameraParams& params) override;
/// Execute camera controller action command.
bool executeCommand(CameraCommand id) override;
/// Decode and execute command.
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
};
getVersion method
The getVersion() method returns the FlirBosonCamera class version string. Method declaration:
static std::string getVersion();
The method can be used without a FlirBosonCamera class instance:
std::cout << "FlirBosonCamera class version: " << rapidpixel::FlirBosonCamera::getVersion() << std::endl;
Console output:
FlirBosonCamera class version: 3.0.2
openCamera method
The openCamera(…) method opens the camera controller. Besides opening the port it puts the camera into a known state: it switches the gain mode to automatic (and fails if the camera does not accept that write), then restores the factory defaults from flash, waits 400 ms while the camera reloads its settings, switches off the rows of camera data added to the video, enables the indicators drawn over the video and enables the analog video output. A camera configured by other means is therefore reset by this call. A camera that is open is closed first. The method blocks for at least 400 ms. Method declaration:
bool openCamera(std::string initString) override;
| Parameter | Value |
|---|---|
| initString | String for initialization, format: <device>;<baudrate> where device is a serial port name such as “/dev/ttyACM0” or “/dev/serial/by-id/…” and baudrate is a positive number (the digits are read as a number, text after them is ignored). The camera’s command port runs at 921600 baud by default. In case of connection via USB, the initialization string can also be the keyword “USBBOSON”, which opens the first USB camera (/dev/ttyACM0) at that baudrate; a string that contains the keyword anywhere selects that camera, whatever else it contains. |
Returns: TRUE if the camera controller is initialized or FALSE if not (invalid initialization string, the port can’t be opened or the camera did not acknowledge the automatic gain mode). If FALSE is returned the camera is closed.
initCamera method
The initCamera(…) method initializes the controller and sets camera params (Camera interface). The method will first set logMode, then call the openCamera(…) method and will then set palette, nucMode, autoNucIntervalMsec and, depending on custom1, either a high-contrast preset (custom1 == 0) or the agcMode, gain, ddeMode, ddeLevel, noiseReductionMode and gainMode fields, with the setParam(…) method. The high-contrast preset writes its own values of gainMode, gain, agcMode, ddeMode, ddeLevel and noiseReductionMode. A field that setParam(…) would reject (for example a mode out of its range or a NaN level) is replaced by a default before anything is stored or written, and an unknown custom1 means “no preset”. isOpen and isConnected of the structure are not used. digitalZoom is not applied. Method declaration:
bool initCamera(CameraParams& params) override;
| Parameter | Value |
|---|---|
| params | CameraParams class object. Params include a string for initialization, format: <device>;<baudrate> where device is a serial port name such as “/dev/ttyACM0” or “/dev/serial/by-id/…”. The camera’s command port runs at 921600 baud by default. In case of connection via USB, the initialization string can also be the keyword “USBBOSON”. |
Returns: TRUE if the controller was opened or FALSE if not. The parameter writes that follow are attempted on a best-effort basis: a write the camera rejects is logged and does not make the method return FALSE.
closeCamera method
The closeCamera() method closes the camera controller. Method declaration:
void closeCamera() override;
isCameraOpen method
The isCameraOpen() method returns the camera controller open status. Method declaration:
bool isCameraOpen() override;
Returns: TRUE if the controller is initialized or FALSE if not.
isCameraConnected method
The isCameraConnected() method returns camera connection status. Method declaration:
bool isCameraConnected() override;
Returns: TRUE if the connection with the camera was established (the flag is set when the camera answered during openCamera(…) and cleared by closeCamera(); the traffic with the camera does not change it) or FALSE if not.
setParam method
The setParam(…) method sets a new camera controller parameter value. The method is thread-safe. A mode or an index (every parameter except GAIN, DDE_LEVEL, DIGITAL_ZOOM and AUTO_NUC_INTERVAL_MSEC) is truncated toward zero (1.7 is 1). NaN, infinity and values outside the range of the parameter are rejected before anything is written to the camera. For DIGITAL_ZOOM the limit of the camera is checked before the fraction is dropped. Method declaration:
bool setParam(CameraParam id, float value) override;
| Parameter | Description |
|---|---|
| id | Camera controller parameter ID according to CameraParam enum. |
| value | Parameter value. Value depends on parameter ID. |
Returns: TRUE if the parameter was set or FALSE if not (unsupported parameter ID, value out of range or NaN, no answer from the camera or, for a parameter that is read back, the value could not be read back; in the last case the camera may still have adopted the value).
getParam method
The getParam(…) method is intended to obtain a Camera parameter value. Method declaration:
float getParam(CameraParam id) override;
| Parameter | Description |
|---|---|
| id | Camera controller parameter ID according to CameraParam enum. |
Returns: parameter value, or -1 if the parameter is not supported or could not be read from the camera.
getParams method
The getParams(…) method is intended to obtain the Camera parameters structure. The method does not talk to the camera: it copies the values the controller stored last (see getParam(…) to read a value from the camera). Method declaration:
void getParams(CameraParams& params) override;
| Parameter | Description |
|---|---|
| params | Reference to CameraParams class object. |
executeCommand method
The executeCommand(…) method is intended to execute a Camera action command. Method declaration:
bool executeCommand(CameraCommand id) override;
| Parameter | Description |
|---|---|
| id | Camera controller command ID according to CameraCommand enum. |
Returns: TRUE if the command was executed or FALSE if not (unsupported command ID or the camera did not acknowledge the command).
decodeAndExecuteCommand method
The decodeAndExecuteCommand(…) method decodes and executes a command on the controller side. The method will decode commands which are encoded by encodeCommand(…) and encodeSetParamCommand(…) methods of the Camera interface class. If a command is decoded, the method will call setParam(…) or executeCommand(…) methods for camera interfaces. This method is thread-safe. This means that the method can be safely called from any thread. Method declaration:
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
| Parameter | Description |
|---|---|
| data | Pointer to input command data. Must not be nullptr. The method can’t check that the pointer is valid for size bytes: this is the contract of the method. |
| size | Size of command. Must be 11 bytes for SET_PARAM and 7 bytes for COMMAND. |
Returns: TRUE if the command was decoded (SET_PARAM or COMMAND) and executed (action command or set param command) or FALSE if not (null pointer, a command that is not valid or a command that failed).
encodeSetParamCommand method of Camera class
encodeSetParamCommand(…) is a static method of the Camera interface class that encodes a command to change any remote camera parameter value. To control a camera remotely, the developer has to design their 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(…) is 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 and must have size >= 11. The method can’t check that the buffer is valid: this is the contract of the method. |
| size | Size of encoded data. Will be 11 bytes (0 if data is nullptr). |
| id | Parameter ID according to CameraParam enum. |
| value | Parameter value. |
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 Little-endian format. |
| 4 | id | Parameter ID int32_t in Little-endian format. |
| 5 | id | Parameter ID int32_t in Little-endian format. |
| 6 | id | Parameter ID int32_t in Little-endian format. |
| 7 | value | Parameter value float in Little-endian format. |
| 8 | value | Parameter value float in Little-endian format. |
| 9 | value | Parameter value float in Little-endian format. |
| 10 | value | Parameter value float in Little-endian format. |
encodeSetParamCommand(…) is static and used without a Camera class instance. This method is used on the client side (control system). Command encoding example:
// Buffer for encoded data.
uint8_t data[11];
// Size of encoded data.
int size = 0;
// Parameter value. The value is not checked: it is transported as is.
const float outValue = 12.0f;
// Encode command.
Camera::encodeSetParamCommand(data, size, CameraParam::ROI_X0, outValue);
encodeCommand method of Camera class
encodeCommand(…) is a static method of the Camera interface class that encodes a command for camera remote control. To control a camera remotely, the developer has to design their 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(…) is designed to encode 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 and must have size >= 7. The method can’t check that the buffer is valid: this is the contract of the method. |
| size | Size of encoded data. Will be 7 bytes (0 if data is nullptr). |
| 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 Little-endian format. |
| 4 | id | Command ID int32_t in Little-endian format. |
| 5 | id | Command ID int32_t in Little-endian format. |
| 6 | id | Command ID int32_t in Little-endian format. |
encodeCommand(…) is static and used without a Camera class instance. This method is used on the client side (control system). Command encoding example:
// Buffer for encoded data.
uint8_t data[7];
// Size of encoded data.
int size = 0;
// Encode command.
Camera::encodeCommand(data, size, CameraCommand::NUC);
decodeCommand method of Camera class
decodeCommand(…) is a static method of the Camera interface class that decodes a command on the camera controller side. The method checks the pointer, the size, the version and the ID (the ID must be inside the range of the CameraParam or CameraCommand enum). The output arguments are changed only if the command was decoded. 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. |
| 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 a SET_PARAM command, the method will return the parameter ID. |
| commandId | Camera command ID according to CameraCommand enum. After decoding a COMMAND, the method will return the command ID. |
| value | Camera parameter value (after decoding a SET_PARAM command). |
Returns: 0 - in case of decoding COMMAND, 1 - in case of decoding SET_PARAM command or -1 in case of errors (null pointer, wrong size, version or ID).
Data structures
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. The last value of the enum.
DEFREEZE
};
Table 2 - Camera commands description.
| Command | Description |
|---|---|
| RESTART | Not supported by FlirBosonCamera library. |
| NUC | NUC command. |
| APPLY_PARAMS | Not supported by FlirBosonCamera library. |
| SAVE_PARAMS | Not supported by FlirBosonCamera library. |
| MENU_ON | Not supported by FlirBosonCamera library. |
| MENU_OFF | Not supported by FlirBosonCamera library. |
| MENU_SET | Not supported by FlirBosonCamera library. |
| MENU_UP | Not supported by FlirBosonCamera library. |
| MENU_DOWN | Not supported by FlirBosonCamera library. |
| MENU_LEFT | Not supported by FlirBosonCamera library. |
| MENU_RIGHT | Not supported by FlirBosonCamera library. |
| FREEZE | Not supported by FlirBosonCamera library. |
| DEFREEZE | Not supported by FlirBosonCamera 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 response from 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. The last value of the enum.
CUSTOM_3
};
The values of the enum are consecutive: the first value of CameraParam is WIDTH and the last one is CUSTOM_3, the first value of CameraCommand is RESTART and the last one is DEFREEZE. The decodeCommand(…) method uses them to check the ID.
Table 3 - Camera params description.
| Parameter | Access | Description |
|---|---|---|
| WIDTH | read / write | Not supported by FlirBosonCamera library. |
| HEIGHT | read / write | Not supported by FlirBosonCamera library. |
| DISPLAY_MODE | read / write | Not supported by FlirBosonCamera library. |
| VIDEO_OUTPUT | read / write | Not supported by FlirBosonCamera library. |
| LOG_MODE | read / write | Logging mode. Values: 0 - Disable, 1 - Only file, 2 - Only terminal (console), 3 - File and terminal. |
| EXPOSURE_MODE | read / write | Not supported by FlirBosonCamera library. |
| EXPOSURE_TIME | read / write | Not supported by FlirBosonCamera library. |
| WHITE_BALANCE_MODE | read / write | Not supported by FlirBosonCamera library. |
| WHITE_BALANCE_AREA | read / write | Not supported by FlirBosonCamera library. |
| WIDE_DYNAMIC_RANGE_MODE | read / write | Not supported by FlirBosonCamera library. |
| STABILIZATION_MODE | read / write | Not supported by FlirBosonCamera library. |
| ISO_SENSITIVITY | read / write | Not supported by FlirBosonCamera library. |
| SCENE_MODE | read / write | Not supported by FlirBosonCamera library. |
| FPS | read / write | Not supported by FlirBosonCamera library. |
| BRIGHTNESS_MODE | read / write | Not supported by FlirBosonCamera library. |
| BRIGHTNESS | read / write | Not supported by FlirBosonCamera library. |
| CONTRAST | read / write | Not supported by FlirBosonCamera library. |
| GAIN_MODE | read / write | Gain mode. Values: 0 - Manual. 1 - Auto. 2 - Low gain. 3 - High gain. |
| GAIN | read / write | Gain level. Values: 0 - 100. |
| SHARPENING_MODE | read / write | Not supported by FlirBosonCamera library. |
| SHARPENING | read / write | Not supported by FlirBosonCamera library. |
| PALETTE | read / write | Palette. Values: 0 - White hot. 1 - Black hot. 2 - Rainbow. 3 - RainHC. 4 - Ironbow. 5 - Lava. 6 - Arctic. 7 - Glowbow. 8 - Graded Fire. 9 - Hottest. |
| AGC_MODE | read / write | AGC mode, content-weighted contrast: 0 - OFF, 1 - ON. |
| SHUTTER_MODE | read / write | Not supported by FlirBosonCamera library. |
| SHUTTER_POSITION | read / write | Not supported by FlirBosonCamera library. |
| SHUTTER_SPEED | read / write | Not supported by FlirBosonCamera library. |
| DIGITAL_ZOOM_MODE | read / write | Not supported by FlirBosonCamera library. |
| DIGITAL_ZOOM | read / write | Digital zoom level. Values 10 (1x) - 48 (4.8x). Upper limit depends on the particular camera. |
| EXPOSURE_COMPENSATION_MODE | read only | Not supported by FlirBosonCamera library. |
| EXPOSURE_COMPENSATION_POSITION | read / write | Not supported by FlirBosonCamera library. |
| DEFOG_MODE | read / write | Not supported by FlirBosonCamera library. |
| DEHAZE_MODE | read / write | Not supported by FlirBosonCamera library. |
| NOISE_REDUCTION_MODE | read / write | Noise reduction mode: 0 - OFF, 1 - ON. |
| BLACK_WHITE_FILTER_MODE | read only | Not supported by FlirBosonCamera library. |
| FILTER_MODE | read / write | Not supported by FlirBosonCamera library. |
| NUC_MODE | read / write | NUC mode for camera. Values: 0 - Manual, 1 - Auto. |
| AUTO_NUC_INTERVAL_MSEC | read / write | Auto NUC interval for thermal cameras. Value in milliseconds. Value < 1000 will be interpreted as OFF value. The value is divided by 1000 and sent to the camera as the interval of its automatic correction in seconds, so 1500 ms becomes an interval of 1 s; read-back multiplies the interval by 1000 again. Values below -999, NaN and values that do not fit the interval of the camera are rejected. |
| IMAGE_FLIP | read / write | Not supported by FlirBosonCamera library. |
| DDE_MODE | read / write | Digital Detail Enhancement mode: 0 - OFF, 1 - ON. |
| DDE_LEVEL | read / write | Digital Detail Enhancement. Values: 0 - 100. The value only reaches the camera while DDE_MODE is 1; written while the mode is 0 it is remembered and applied when the mode is switched on, so set DDE_MODE first. |
| ROI_X0 | read / write | Not supported by FlirBosonCamera library. |
| ROI_Y0 | read / write | Not supported by FlirBosonCamera library. |
| ROI_X1 | read / write | Not supported by FlirBosonCamera library. |
| ROI_Y1 | read / write | Not supported by FlirBosonCamera library. |
| TEMPERATURE | read only | Not supported by FlirBosonCamera library. |
| ALC_GATE | read / write | Not supported by FlirBosonCamera library. |
| SENSITIVITY | read / write | Not supported by FlirBosonCamera library. |
| CHANGING_MODE | read / write | Not supported by FlirBosonCamera library. |
| CHANGING_LEVEL | read / write | Not supported by FlirBosonCamera library. |
| CHROMA_LEVEL | read / write | Not supported by FlirBosonCamera library. |
| DETAIL | read / write | Not supported by FlirBosonCamera library. |
| PROFILE | read / write | Not supported by FlirBosonCamera library. |
| IS_CONNECTED | read only | Connection status. |
| IS_OPEN | read only | Controller initialization status. |
| TYPE | read / write | Not supported by FlirBosonCamera library. |
| CUSTOM_1 | read / write | Video preset on initialization procedure. Values: 0 - High contrast preset. 1 - No preset. |
| CUSTOM_2 | read / write | Not supported by FlirBosonCamera library. |
| CUSTOM_3 | read / write | Not supported by FlirBosonCamera library. |
CameraParams class description
CameraParams class is used for camera controller initialization or to get all actual params. Also CameraParams provides structure to write/read params from JSON files (JSON_READABLE macro) and provides method to encode and decode params.
CameraParams class declaration
CameraParams class is declared in the Camera.h file. The class is not thread-safe: an object must not be accessed from several threads at the same time without external synchronization. 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 params. The method doesn't encode initString.
bool encode(uint8_t* data, int bufferSize, int& size,
CameraParamsMask* mask = nullptr);
/// Decode params. The method doesn't decode initString.
bool decode(uint8_t* data, int dataSize);
};
Table 4 - CameraParams class fields description is equivalent to CameraParam enum description.
| Field | type | Description |
|---|---|---|
| initString | string | The same format as openCamera(…) method initString parameter. |
| width | int | Not supported by FlirBosonCamera library. |
| height | int | Not supported by FlirBosonCamera library. |
| displayMode | int | Not supported by FlirBosonCamera library. |
| videoOutput | int | Not supported by FlirBosonCamera library. |
| logMode | int | Logging mode. Values: 0 - Disable 1 - Only file 2 - Only terminal (console) 3 - File and terminal |
| exposureMode | int | Not supported by FlirBosonCamera library. |
| exposureTime | int | Not supported by FlirBosonCamera library. |
| whiteBalanceMode | int | Not supported by FlirBosonCamera library. |
| whiteBalanceArea | int | Not supported by FlirBosonCamera library. |
| wideDynamicRangeMode | int | Not supported by FlirBosonCamera library. |
| stabilizationMode | int | Not supported by FlirBosonCamera library. |
| isoSensitivity | int | Not supported by FlirBosonCamera library. |
| sceneMode | int | Not supported by FlirBosonCamera library. |
| fps | float | Not supported by FlirBosonCamera library. |
| brightnessMode | int | Not supported by FlirBosonCamera library. |
| brightness | int | Not supported by FlirBosonCamera library. |
| contrast | int | Not supported by FlirBosonCamera library. |
| gainMode | int | Gain mode. Values: 0 - Manual. 1 - Auto. 2 - Low gain. 3 - High gain. |
| gain | int | Gain level. Values: 0 - 100. |
| sharpeningMode | int | Not supported by FlirBosonCamera library. |
| sharpening | int | Not supported by FlirBosonCamera library. |
| palette | int | Palette. Values: 0 - White hot. 1 - Black hot. 2 - Rainbow. 3 - RainHC. 4 - Ironbow. 5 - Lava. 6 - Arctic. 7 - Glowbow. 8 - Graded Fire. 9 - Hottest. |
| agcMode | int | AGC mode: 0 - OFF, 1 - ON. |
| shutterMode | int | Not supported by FlirBosonCamera library. |
| shutterPos | int | Not supported by FlirBosonCamera library. |
| shutterSpeed | int | Not supported by FlirBosonCamera library. |
| digitalZoomMode | int | Not supported by FlirBosonCamera library. |
| digitalZoom | float | Digital zoom level. Values 10 (1x) - 48 (4.8x). Upper limit depends on the particular camera. |
| exposureCompensationMode | int | Not supported by FlirBosonCamera library. |
| exposureCompensationPosition | int | Not supported by FlirBosonCamera library. |
| defogMode | int | Not supported by FlirBosonCamera library. |
| dehazeMode | int | Not supported by FlirBosonCamera library. |
| noiseReductionMode | int | Noise reduction mode: 0 - OFF, 1 - ON. |
| blackAndWhiteFilterMode | int | Not supported by FlirBosonCamera library. |
| filterMode | int | Not supported by FlirBosonCamera library. |
| nucMode | int | NUC mode for camera. Values: 0 - Manual, 1 - Auto. |
| autoNucIntervalMsec | int | Auto NUC interval for thermal cameras. Value in milliseconds. Value < 1000 will be interpreted as OFF value. The value is divided by 1000 and sent to the camera as the interval of its automatic correction in seconds. |
| imageFlip | int | Not supported by FlirBosonCamera library. |
| ddeMode | int | Digital Detail Enhancement mode: 0 - OFF, 1 - ON. |
| ddeLevel | float | Digital Detail Enhancement. Values: 0 - 100. |
| roiX0 | int | Not supported by FlirBosonCamera library. |
| roiY0 | int | Not supported by FlirBosonCamera library. |
| roiX1 | int | Not supported by FlirBosonCamera library. |
| roiY1 | int | Not supported by FlirBosonCamera library. |
| temperature | float | Not supported by FlirBosonCamera library. |
| alcGate | int | Not supported by FlirBosonCamera library. |
| sensitivity | float | Not supported by FlirBosonCamera library. |
| changingMode | int | Not supported by FlirBosonCamera library. |
| changingLevel | float | Not supported by FlirBosonCamera library. |
| chromaLevel | int | Not supported by FlirBosonCamera library. |
| detail | int | Not supported by FlirBosonCamera library. |
| profile | int | Not supported by FlirBosonCamera library. |
| isConnected | bool | Connection status. |
| isOpen | bool | Controller initialization status. |
| type | int | Not supported by FlirBosonCamera library. |
| custom1 | float | Video preset on initialization procedure. Values: 0 - High contrast preset. 1 - No preset. |
| custom2 | float | Not supported by FlirBosonCamera library. |
| custom3 | float | Not supported by FlirBosonCamera library. |
Note: CameraParams class fields listed above reflect params set/get by methods setParam(…) and getParam(…).
Serialize camera params
CameraParams class provides the method encode(…) to serialize camera params. Serialization of camera params is necessary in case when you have to send camera params via communication channels. The method doesn’t encode the initString field. The method provides options to exclude particular parameters from serialization. To do this, the method inserts a binary mask (8 bytes) where each bit represents a particular parameter and the 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. Buffer size must be >= 237 bytes. The method can’t check that the buffer is valid for bufferSize bytes: this is the contract of the method. |
| bufferSize | Data buffer size. Buffer size must be >= 237 bytes (the size of the data with all fields selected). |
| size | Size of encoded data. Set to 0 if the method returns FALSE. |
| 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 user wants to exclude a particular parameter from serialization, he should set the corresponding flag in the CameraParamsMask structure. |
Returns: TRUE if params are encoded (serialized) or FALSE if not (data is nullptr or bufferSize is too small).
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.
CameraParams in;
in.profile = 10;
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size))
{
std::cout << "Can't encode params" << std::endl;
return false;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;
Example with parameters mask:
// Prepare params.
CameraParams in;
in.profile = 3;
// Prepare mask.
CameraParamsMask mask;
mask.profile = false; // Exclude profile. Others by default.
// Encode.
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size, &mask))
{
std::cout << "Can't encode params" << std::endl;
return false;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;
Deserialize camera params
CameraParams class provides the method decode(…) to deserialize camera params (fields of CameraParams class, see Table 4). Deserialization of camera params is necessary in case when you need to receive params via communication channels. The method automatically recognizes which parameters were serialized by the encode(…) method. The method checks the data type, the version and the size of the data before reading each field. A field that is not selected by the mask of the encoded data is set to zero and initString is set to an empty string. Values of the fields are not checked against any range. 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 serialized data. Must be >= 11 (the size of the data without fields). |
Returns: TRUE if params are decoded (deserialized) or FALSE if not. If FALSE is returned the object is not changed.
Example:
// Encode data.
CameraParams in;
uint8_t data[1024];
int size = 0;
if (!in.encode(data, 1024, size))
{
std::cout << "Can't encode params" << std::endl;
return false;
}
std::cout << "Encoded data size: " << size << " bytes" << std::endl;
// Decode data.
CameraParams out;
if (!out.decode(data, size))
{
std::cout << "Can't decode data" << std::endl;
return false;
}
Read and write camera params to JSON file
The Camera library depends on the ConfigReader library which provides methods to read params from JSON file and to write params to JSON file. Example of writing and reading params to JSON file:
// Write params to file.
CameraParams in;
rapidpixel::ConfigReader inConfig;
if (!inConfig.set(in, "cameraParams") ||
!inConfig.writeToFile("TestCameraParams.json"))
{
std::cout << "Can't write config file" << std::endl;
return false;
}
// Read params from file.
rapidpixel::ConfigReader outConfig;
if (!outConfig.readFromFile("TestCameraParams.json"))
{
std::cout << "Can't open config file" << std::endl;
return false;
}
CameraParams out;
if (!outConfig.get(out, "cameraParams"))
{
std::cout << "Can't read params from config file" << std::endl;
return false;
}
TestCameraParams.json will look like:
{
"cameraParams": {
"initString": "dfhglsjirhuhjfb",
"width": 150,
"height": 219,
"displayMode": 2,
"videoOutput": 18,
"logMode": 252,
"exposureMode": 192,
"exposureTime": 16,
"whiteBalanceMode": 30,
"whiteBalanceArea": 236,
"wideDynamicRangeMode": 21,
"stabilizationMode": 170,
"isoSensitivity": 32,
"sceneMode": 195,
"fps": 19.0,
"brightnessMode": 206,
"brightness": 67,
"contrast": 65,
"gainMode": 130,
"gain": 111,
"sharpeningMode": 49,
"sharpening": 196,
"palette": 115,
"agcMode": 252,
"shutterMode": 101,
"shutterPos": 157,
"shutterSpeed": 117,
"digitalZoomMode": 157,
"digitalZoom": 47.0,
"exposureCompensationMode": 213,
"exposureCompensationPosition": 183,
"defogMode": 155,
"dehazeMode": 239,
"noiseReductionMode": 79,
"blackAndWhiteFilterMode": 68,
"filterMode": 251,
"nucMode": 228,
"autoNucIntervalMsec": 47,
"imageFlip": 211,
"ddeMode": 221,
"ddeLevel": 25.0,
"roiX0": 93,
"roiY0": 98,
"roiX1": 135,
"roiY1": 206,
"alcGate": 125,
"sensitivity": 70.0,
"changingMode": 239,
"changingLevel": 84.0,
"chromaLevel": 137,
"detail": 128,
"profile": 108,
"type": 55,
"custom1": 216.0,
"custom2": 32.0,
"custom3": 125.0
}
}
Build and connect to your project
Build stand alone
The repository does not contain sub-repositories. The libraries FlirBosonCamera depends on (ConfigReader, Camera, Logger and SerialPort) must be cloned into the same folder as FlirBosonCamera. The folder structure must be:
<work folder>
FlirBosonCamera
ConfigReader
Camera
Logger
SerialPort
Typical commands to build the library, the test application and the example (use the URLs of the repositories provided to you):
git clone <FlirBosonCamera repository URL>
git clone <ConfigReader repository URL>
git clone <Camera repository URL>
git clone <Logger repository URL>
git clone <SerialPort repository URL>
cd FlirBosonCamera
mkdir build
cd build
cmake ..
make
If FlirBosonCamera is the top-level CMake project, the main CMakeLists.txt file adds the folders ../ConfigReader, ../Camera, ../Logger and ../SerialPort (in this order) before the library itself. If a folder does not exist CMake stops with an error. The BosonProtocol folder (src/BosonProtocol) is a part of the repository: the main CMakeLists.txt file adds it in every mode. It is not a part of the public interface: FlirBosonCamera.h does not include its headers.
CMake options
Table 5 - CMake options of the repository. In the options below ${PARENT} is the prefix defined by the top-level project (empty if FlirBosonCamera is the top-level project).
| Option | Default | Description |
|---|---|---|
| ${PARENT}_FLIR_BOSON_CAMERA | ON | Build the library. |
| ${PARENT}_FLIR_BOSON_CAMERA_TEST | ON (stand alone), OFF (included in other project) | Build the test application. |
| ${PARENT}_FLIR_BOSON_CAMERA_EXAMPLE | ON (stand alone), OFF (included in other project) | Build the example. |
| ${PARENT}_BOSON_PROTOCOL | ON | Build the BosonProtocol library. If the BosonProtocol folder is the top-level project it adds the folder ../../../SerialPort. |
| ${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 FlirBosonCamera as a sub-repository. |
| CMAKE_BUILD_TYPE | Release (if not specified) | Build type. |
Connect to your project
If you want to connect the FlirBosonCamera 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 folder 3rdparty and copy the folders of the FlirBosonCamera repository and of the repositories it depends on (ConfigReader, Camera, Logger and SerialPort) there. New structure of your repository:
CMakeLists.txt
src
CMakeLists.txt
yourLib.h
yourLib.cpp
3rdparty
ConfigReader
Camera
Logger
SerialPort
FlirBosonCamera
FlirBosonCamera does not add its dependencies when it is included in another project: your project must add ConfigReader, Camera, Logger and SerialPort. The order of the folders matters for the dependencies themselves (ConfigReader before Camera); FlirBosonCamera can be added before or after them. If a dependency is missing the build stops with an error like “Camera.h: No such file or directory”.
Create CMakeLists.txt file in 3rdparty folder. CMakeLists.txt 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_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_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_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_FLIR_BOSON_CAMERA ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_FLIR_BOSON_CAMERA)
SET(${PARENT}_FLIR_BOSON_CAMERA ON CACHE BOOL "" FORCE)
SET(${PARENT}_FLIR_BOSON_CAMERA_TEST OFF CACHE BOOL "" FORCE)
SET(${PARENT}_FLIR_BOSON_CAMERA_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_CONFIG_READER)
add_subdirectory(ConfigReader)
endif()
if (${PARENT}_SUBMODULE_CAMERA)
add_subdirectory(Camera)
endif()
if (${PARENT}_SUBMODULE_LOGGER)
add_subdirectory(Logger)
endif()
if (${PARENT}_SUBMODULE_SERIAL_PORT)
add_subdirectory(SerialPort)
endif()
if (${PARENT}_SUBMODULE_FLIR_BOSON_CAMERA)
add_subdirectory(FlirBosonCamera)
endif()
File 3rdparty/CMakeLists.txt adds the folders of the dependencies and the folder FlirBosonCamera to your project and excludes test applications and examples from compiling (by default the test application is excluded from compiling if FlirBosonCamera is included as sub-repository). The new structure of your repository:
CMakeLists.txt
src
CMakeLists.txt
yourLib.h
yourLib.cpp
3rdparty
CMakeLists.txt
ConfigReader
Camera
Logger
SerialPort
FlirBosonCamera
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 FlirBosonCamera library in your src/CMakeLists.txt file:
target_link_libraries(${PROJECT_NAME} FlirBosonCamera)
Done!
Simple example
The example below is the whole of example/main.cpp. It opens the camera, reads a parameter from it, looks at the controller’s own view of the parameter set, writes a parameter, runs a command and closes the camera. It is deliberately short: initCamera(…), decodeAndExecuteCommand(…), isCameraOpen() and isCameraConnected() are left to the test application, which exercises all of them.
#include <iostream>
#include "FlirBosonCamera.h"
/// Palette 4 is Ironbow. The full list is in the PALETTE row of the
/// documentation.
const float IRONBOW_PALETTE = 4.0f;
/// Entry point.
int main()
{
std::cout << "FlirBosonCamera v"
<< rapidpixel::FlirBosonCamera::getVersion() << std::endl;
// Create the camera controller and open the camera. The init string is
// either "USBBOSON" for the first USB camera, or "<device>;<baudrate>",
// for example "/dev/ttyACM0;921600".
rapidpixel::FlirBosonCamera camera;
if (!camera.openCamera("USBBOSON"))
{
std::cout << "Can't open camera" << std::endl;
return -1;
}
// getParam(...) asks the camera for PALETTE. For the parameters the
// controller keeps on its own side - LOG_MODE, DDE_MODE, DDE_LEVEL,
// CUSTOM_1, IS_OPEN, IS_CONNECTED - it answers from its own copy. It
// returns -1 when the value is not available, so a reading is worth
// checking before it is used.
const float palette = camera.getParam(rapidpixel::CameraParam::PALETTE);
if (palette < 0.0f)
{
std::cout << "Palette is not available" << std::endl;
}
else
{
std::cout << "Palette from the camera: " << palette << std::endl;
}
// getParams(...) does not talk to the camera: it copies the controller's
// own view of it, which is what the last read or write left there.
rapidpixel::CameraParams params;
camera.getParams(params);
std::cout << "Gain mode known to the controller: "
<< params.gainMode << std::endl;
// Write one parameter. For PALETTE the controller reads the value back
// from the camera, so the next getParam(...) reports what the camera
// adopted rather than what was asked for.
if (!camera.setParam(rapidpixel::CameraParam::PALETTE, IRONBOW_PALETTE))
{
std::cout << "Can't set palette" << std::endl;
}
std::cout << "Palette after the write: "
<< camera.getParam(rapidpixel::CameraParam::PALETTE) << std::endl;
// Run a command.
if (!camera.executeCommand(rapidpixel::CameraCommand::NUC))
{
std::cout << "Can't run NUC" << std::endl;
}
camera.closeCamera();
return 0;
}
Test application
The FlirBosonCamera/test folder contains a test application which demonstrates how to use the FlirBosonCamera library. The application is controlled from the terminal only: it shows no video and has no user interface other than the terminal. It gives access to every parameter and command the library implements, and to every method of the interface: setParam(…), getParam(…), getParams(…), executeCommand(…), decodeAndExecuteCommand(…), openCamera(…), initCamera(…), closeCamera(), isCameraOpen() and isCameraConnected().
After a successful write the application prints the value the controller holds afterwards. For a parameter the controller re-reads from the camera it says Set, camera reports …, so the operator sees what the camera adopted rather than what was asked for; the two differ whenever the camera clamps or ignores a write. For LOG_MODE, CUSTOM_1, DDE_MODE and DDE_LEVEL it says Set, controller stored … instead and claims nothing about the camera: the first three are kept on the controller’s own side, and DDE_LEVEL reaches the camera only while DDE_MODE is 1.
If the camera cannot be opened at startup the application reports it and still enters the menu, so that LOG_MODE can be raised to see the library’s own diagnostics and the connection menu can retry.
The test application output will look like:
================================================
FlirBosonCamera tester v3.0.2
================================================
Init string (USBBOSON or <device>;<baudrate>, empty line for USBBOSON):
Choose option:
1 - Set camera param
2 - Get camera param
3 - Get all camera params
4 - Execute camera command
5 - Send encoded command
6 - Connection state
7 - Reopen with initCamera(...)
-1 - Exit
Choose option: 1
Camera params:
5 - LOG_MODE | 18 - GAIN_MODE
19 - GAIN | 22 - PALETTE
23 - AGC_MODE | 28 - DIGITAL_ZOOM
33 - NOISE_REDUCTION_MODE | 36 - NUC_MODE
37 - AUTO_NUC_INTERVAL_MSEC | 39 - DDE_MODE
40 - DDE_LEVEL | 56 - CUSTOM_1
0 - any other ID, to see how the library rejects it
Choose param (-1 to exit to main menu): 22
Set palette: 0 - White hot, 1 - Black hot, 2 - Rainbow, 3 - RainHC, 4 - Ironbow, 5 - Lava, 6 - Arctic, 7 - Glowbow, 8 - Graded fire, 9 - Hottest: 4
Set, camera reports 4
Option 3 prints the whole parameter set twice, once value by value through getParam(…) and once as a structure through getParams(…):
getParam(...):
LOG_MODE = 0
GAIN_MODE = 3
GAIN = 18.7097
PALETTE = 4
AGC_MODE = 1
DIGITAL_ZOOM = 0
NOISE_REDUCTION_MODE = 1
NUC_MODE = 1
AUTO_NUC_INTERVAL_MSEC = 300000
DDE_MODE = 0
DDE_LEVEL = 0
CUSTOM_1 = 0
IS_OPEN = 1
IS_CONNECTED = 1
getParams(...):
initString = /dev/serial/by-id/usb-FLIR_Boson_386477-if02;921600
logMode = 0
gainMode = 3
gain = 18
palette = 4
agcMode = 1
digitalZoom = 0
noiseReductionMode = 1
nucMode = 1
autoNucIntervalMsec = 300000
ddeMode = 0
ddeLevel = 0
custom1 = 0
isOpen = 1
isConnected = 1
A parameter the camera does not provide is printed as -1 followed by (not available), so a missing reading is never mistaken for a real one.
Portability
The library builds on Linux only: a check in src/CMakeLists.txt stops the configure step on any other system. The code doesn’t depend on Linux, except the “USBBOSON” keyword of the initialization string, which opens the Linux device /dev/ttyACM0 (any other initialization string passes its device name to the SerialPort library unchanged). The code uses standard C++17 only (compiler extensions are switched off) and has no code that depends on a particular instruction set. The protocol of the camera is encoded byte by byte, most significant byte first, so it does not depend on the byte order of the host. The code was built with GCC 11 and GCC 12 for x86-64 and with the GCC 11 aarch64 cross compiler; the library produced the same bytes for the camera on x86-64 and on aarch64 (run under qemu).