G5ProtocolParser C++ library
v1.0.4
Table of contents
- Overview
- Versions
- Library files
- G5ProtocolParser class description
- Data structures
- Build and connect to your project
- Example
- Test application
Overview
The G5ProtocolParser C++ library is designed for encoding control commands for G5 infrared cameras. The library includes basic method for preparing commands (encoding). It utilizes C++17 standard. The library provides simple interface and doesn’t have any third party libraries to install on OS. Also, the library provides test application to check communication with the camera via serial ports. Test application depends on SerialPort library (provides methods to work with serial ports, source code included, Apache 2.0 license).
Versions
Table 1 - Library versions.
Version | Release date | What’s new |
---|---|---|
1.0.0 | 04.05.2023 | - First version. |
1.0.1 | 27.03.2024 | - Documentation added. - Code optimized. |
1.0.2 | 24.05.2024 | - Documentation updated. |
1.0.3 | 30.07.2024 | - CMake structure updated. |
1.0.4 | 20.11.2024 | - Add ATCOM image processing commands. |
Library files
The library is supplied only by source code. The user is given 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.
src ------------------------------ Folder with library source code.
CMakeLists.txt ---------------- CMake file of the library.
G5ProtocolParser.h ------------ Main library header file.
G5ProtocolParserVersion.h ----- Header file with library version.
G5ProtocolParserVersion.h.in -- File for CMake to generate version header.
G5ProtocolParser.cpp ---------- C++ implementation file.
test ------------------------------ Folder for test application files.
3rdparty ---------------------- Folder with third-party libraries.
CMakeLists.txt ------------ CMake file to include third-party libraries.
SerialPort ---------------- Folder with SerialPort library source code.
CMakeLists.txt ---------------- CMake file for test application.
main.cpp ---------------------- Source C++ file of test application.
G5ProtocolParser class description
Class declaration
class G5ProtocolParser
{
public:
/// Get class version.
static std::string getVersion();
/// Encode G5 command.
bool getCommand(uint8_t *data, int &size, G5Command id, int arg1 = 0, int arg2 = 0);
};
getVersion method
The getVersion() method return string of current G5ProtocolParser class version. Method declaration:
static std::string getVersion();
Method can be used without G5ProtocolParser class instance:
cout << "G5ProtocolParser version: " << cr::g5::G5ProtocolParser::getVersion();
Console output:
G5ProtocolParser version: 1.0.3
getCommand method
The getCommand(…) method encodes (prepares data) control command for camera. Example shows usage of command. Method declaration:
bool getCommand(uint8_t *data, int &size, G5Command id, int arg1 = 0, int arg2 = 0);
Parameter | Value |
---|---|
data | Address of buffer for encoded data (command). Size of buffer also depends on command id but it is better to give at least 20 bytes. |
size | Size of encoded command. |
id | Command id according to G5Command enum. |
arg1-arg2 | Arguments of command. The value of arguments depends on command id. |
Returns: TRUE if commands encoded or FALSE if not (invalid id or invalid parameters).
Data structures
G5Command enum
The command id’s are described in the G5Command enum in the G5ProtocolParser.h file. The definition of the enum is as follows:
enum class G5Command
{
/// Digital zoom command.
/// arg1: 0 - 1X.
/// 1 - 2X.
/// 2 - 4X.
DZOOM,
/// Filter command.
/// arg1: 0 to 10.
FILTER,
/// Freeze command.
/// arg1: 0 - OFF.
/// 1 - ON.
FREEZE,
/// Palette command.
/// arg1: 0 to 6.
PALETTE,
/// Palette plus command.
/// No arguments.
PALETTE_PLUS,
/// Palette minus command.
/// No arguments.
PALETTE_MINUS,
/// Polarity white command.
/// No arguments.
POL_WHT,
/// Polarity black command.
/// No arguments.
POL_BLK,
/// Sensitivity command.
/// arg1: -1 to +1.
SENS,
/// Nuc command.
/// No arguments.
NUC,
/// Auto gain level linear command.
/// No arguments.
AGLC_LIN,
/// Auto gain level normal command.
/// No arguments.
AGLC_NRM,
/// Auto gain level off command.
/// No arguments.
AGLC_OFF,
/// Manual gain level command.
/// arg1: 0 to 1000.
MGC,
/// Manual gain level plus command.
/// arg1: 1 to 1000.
MGC_PLUS,
/// Manual gain level minus command.
/// arg1: 1 to 1000.
MGC_MINUS,
/// Manual level control command.
/// arg1: 0 to 1000.
MLC,
/// Manual level control plus command.
/// arg1: 1 to 1000.
MLC_PLUS,
/// Manual level control minus command.
/// arg1: 1 to 1000.
MLC_MINUS,
/// Focus near command.
/// arg1: 1 to 100.
FOCUS_NEAR,
/// Focus far command.
/// arg1: 1 to 100.
FOCUS_FAR,
/// Focus stop command.
/// No arguments.
FOCUS_STOP,
/// Focus auto command.
/// No arguments.
FOCUS_AUTO,
/// Focus manual command.
/// arg1: 0 to 1000.
FOCUS,
/// Focus minus command.
/// arg1: 1 to 1000.
FOCUS_MINUS,
/// Focus plus command.
/// arg1: 1 to 1000.
FOCUS_PLUS,
/// EFL command.
/// arg1: 1 to 100 (EFL)
/// arg2: 1 to 100. (speed %)
EFL,
/// Field of view command.
/// arg1: 0 to 180 (FOV degrees).
/// arg2: 1 to 100. (speed %)
FOV,
/// Zoom in command.
/// arg1: 1 to 100. (speed %)
ZOOM_IN,
/// Zoom out command.
/// arg1: 1 to 100. (speed %)
ZOOM_OUT,
/// Zoom stop command.
/// No arguments.
ZOOM_STOP,
/// Zoom command.
/// arg1: 0 to 65535. (position)
/// arg2: 1 to 100. (speed %)
ZOOM_N,
/// Zoom minus command.
/// arg1: 1 to 1000.
ZOOM_MINUS,
/// Zoom plus command.
/// arg1: 1 to 1000.
ZOOM_PLUS,
/// PREDEF command.
/// arg1: 0 to 127.
PREDEF,
/// PRECLR command.
/// arg1: 0 to 127.
PRECLR,
/// PRESET command.
/// arg1: 0 to 127.
/// arg2: 1 to 100. (speed %)
PRESET,
/// Address command.
/// arg1: 0 to 31.
ADDR,
/// Auto calibration on command.
/// No arguments.
AUTOCAL_ON,
/// Auto calibration off command.
/// No arguments.
AUTOCAL_OFF,
/// Auto calibration interval command.
/// arg1: 0 to 32767.
AUTOCALINT,
/// Baud rate command.
/// arg1: baud rate. (2400, 4800, 9600, 19200, 38400, 57600, 115200)
BAUD,
/// DZOOM command.
/// arg1: 0 - LINK.
/// 1 - FREE.
DZOOM_S,
/// Model command.
/// No arguments.
MODEL,
/// OL command.
/// arg1: 0 - OFF.
/// 1 - ON.
OL,
/// OLROI command.
/// arg1: 0 - OFF.
/// 1 - ON.
OLROI,
/// OLTLN command.
/// arg1: 0 - OFF.
/// 1 - ON.
OLTLN,
/// OLGLC command.
/// arg1: 0 - OFF.
/// 1 - ON.
OLGLC,
/// RETICLE command.
/// arg1: 0 to 1.
RETICLE,
/// ROI command.
/// arg1: 1 to 7.
ROI,
/// WARN command.
/// arg1: 0 to 3.
WARN,
/// CONFIG command.
/// No arguments.
CONFIG,
/// AUTOSENS command.
/// arg1: 0 - OFF.
/// 1 - ON.
AUTOSENS,
/// CAMLINK command.
/// arg1: 0 - OFF.
/// 1 - ON.
CAMLINK,
/// COMM command.
/// arg1: 0 - RS422.
/// 1 - RS232.
/// 2 - CAMLINK.
COMM,
/// EIS command.
/// arg1: 0 - OFF.
/// 1 - ON.
EIS,
/// VIDEO command.
/// arg1: 0 - NTSC.
/// 1 - PAL.
VIDEO,
/// DATE command. (yyyy-mm-dd)
/// No arguments.
DATE,
/// GMT plus command.
/// No arguments.
GMT_PLUS,
/// GMT minus command.
/// No arguments.
GMT_MINUS,
/// TIME command. (hh:mm:ss)
/// Arg1: 0 - 60. (seconds)
TIME,
/// RESET command.
/// No arguments.
RESET,
/// RESETTIM command.
/// No arguments.
RESET_TIM,
/// RESETTLN command.
/// No arguments.
RESET_TLN,
/// RUNTIME command.
/// No arguments.
RUNTIME,
/// VERSION command.
/// No arguments.
VERSION,
/// QUERY Zoom position command (Pelco-D).
/// No arguments.
ZOOM_POSITION,
/// QUERY Focus position command (Pelco-D).
/// No arguments.
FOCUS_POSITION,
/// Level of Local Area Contrast Enhancement command.
/// arg1: 0 - OFF.
/// 1 - LOW.
/// 2 - MEDIUM.
/// 3 - HIGH.
TM_LACE,
/// Motion level. Default is 100.
/// arg1: 0 - 100.
/// 1 - 80.
/// 2 - 60.
/// 3 - 40.
/// 4 - 20.
/// 5 - 0.
TM_MOTION,
/// Quality of the turbulence mitigation. Default: 2(40).
/// arg1: 0 - 0.
/// 1 - 20.
/// 2 - 40.
/// 3 - 60.
/// 4 - 80.
/// 5 - 100.
TM_QUALITY,
/// Region of interest. Default is 0.
/// arg1: 1 - 7.
/// 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
TM_ROI,
/// Sharpness.
/// arg1: 0 - OFF.
/// 1 - MIN.
/// 2 - LOW.
/// 3 - MEDIUM.
/// 4 - HIGH.
/// 5 - MAX.
TM_SHARP,
/// Stabilize.
/// arg1: 0 - OFF.
/// 1 - ON.
TM_STABILIZE,
/// Turbulence.
/// arg1: 0 - OFF.
/// 1 - MIN.
/// 2 - LOW.
/// 3 - MEDIUM.
/// 4 - HIGH.
/// 5 - MAX.
TM_TURBULENCE
};
Build and connect to your project
Typical commands to build G5ProtocolParser library:
cd G5ProtocolParser
mkdir build
cd build
cmake ..
make
If you want to connect G5ProtocolParser library to your CMake project as source code you can make follow. For example, if your repository has structure:
CMakeLists.txt
src
CMakeList.txt
yourLib.h
yourLib.cpp
Create folder 3rdparty and copy folder of G5ProtocolParser repository there. New structure of your repository:
CMakeLists.txt
src
CMakeList.txt
yourLib.h
yourLib.cpp
3rdparty
G5ProtocolParser
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_G5_PROTOCOL_PARSER ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_G5_PROTOCOL_PARSER)
SET(${PARENT}_G5_PROTOCOL_PARSER ON CACHE BOOL "" FORCE)
SET(${PARENT}_G5_PROTOCOL_PARSER_TEST OFF CACHE BOOL "" FORCE)
endif()
################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_G5_PROTOCOL_PARSER)
add_subdirectory(G5ProtocolParser)
endif()
File 3rdparty/CMakeLists.txt adds folder G5ProtocolParser to your project and excludes test application and example from compiling (by default test applications and example are excluded from compiling if G5ProtocolParser is included as sub-repository). The new structure of your repository:
CMakeLists.txt
src
CMakeList.txt
yourLib.h
yourLib.cpp
3rdparty
CMakeLists.txt
G5ProtocolParser
Next you need include folder 3rdparty in main CMakeLists.txt file of your repository. Add string at the end of your main CMakeLists.txt:
add_subdirectory(3rdparty)
Next you have to include Lens library in your src/CMakeLists.txt file:
target_link_libraries(${PROJECT_NAME} G5ProtocolParser)
Done!
Example
Below is an example of encoding command.
// Init variables.
uint8_t buffer[24];
int size;
int focusSpeed = 50;
parser.getCommand(buffer, size, G5Command::FOCUS_NEAR, focusSpeed);
// Send data.
if (serialPort.write(buffer, size) != size)
{
cout << "ERROR: Can't send data" << endl;
continue;
}
Test application
Folder G5ProtocolParser/test contains the test application files. The test application allows you to generate any command, send it to the camera over the serial port and then receive and prints the response. Once started, the user must enter the serial port name (full name for Linux or just the port number for Windows), baud rate (default 9600):
================================================
G5ProtocolParser tester v1.0.4
================================================
Set serial port name: /dev/serial/by-id/usb-FTDI_USB-RS232_Cable_AV0JVLA1-if00-port0
Set baudrate (default : 9600): 9600
After user can choose command (enter command ID). If no necessary command has been displayed use can set ID according to G5Command enum (test application supports all commands):
Commands:
0 DZOOM 1 FILTER
2 FREEZE 3 PALETTE
4 PALETTE_PLUS 5 PALETTE_MINUS
6 POL_WHT 7 POL_BLK
8 SENS 9 NUC
10 AGLC_LIN 11 AGLC_NRM
12 AGLC_OFF 13 MGC
14 MGC_PLUS 15 MGC_MINUS
16 MLC 17 MLC_PLUS
18 MLC_MINUS 19 FOCUS_NEAR
20 FOCUS_FAR 21 FOCUS_STOP
22 FOCUS_AUTO 23 FOCUS
24 FOCUS_MINUS 25 FOCUS_PLUS
26 EFL 27 FOV
28 ZOOM_IN 29 ZOOM_OUT
30 ZOOM_STOP 31 ZOOM_N
32 ZOOM_MINUS
33 ZOOM_PLUS 34 PREDEF
35 PRECLR 36 PRESET
37 ADDR 38 AUTOCAL_ON
39 AUTOCAL_OFF 40 AUTOCALINT
41 BAUD 42 DZOOM_S
43 MODEL 44 OL
45 OLROI 46 OLTLN
47 OLGLC 48 RETICLE
49 ROI 50 WARN
51 CONFIG 52 AUTOSENS
53 CAMLINK 54 COMM
55 EIS 56 VIDEO
57 DATE 58 GMT_PLUS
59 GMT_MINUS 60 TIME
61 RESET 62 RESET_TIM
63 RESET_TLN
64 RUNTIME 65 VERSION
66 QUERY_ZOOM_POSITION 67 QUERY_FOCUS_POSITION
67 TM_LACE 68 TM_ROI
69 TM_SHARP 70 TM_STABILIZE
71 TM_TURBULENCE
Choose command:
Then, corresponding command will be generated and sent to camera. Camera will return related response and this response will be printed.