pelcodparser_web_logo

PelcoDParser C++ library

v1.0.0

Table of contents

Overview

The PelcoDParser is a C++ library for encoding and decoding PelcoD responses and commands. The library includes basic methods for preparing commands (encoding) and interpreting the camera responses (decoding). It uses C++17 standard. The library provides simple interface and doesn’t have third party dependencies to be installed in OS. Also, the library provides test application to check communication with cameras via serial ports. Test application depends on SerialPort (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 14.03.2025 - First version.

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.
    PelcoDParser.h ------------ Main library header file.
    PelcoDParserVersion.h ----- Header file with library version.
    PelcoDParserVersion.h.in -- Service CMake file to generate version header.
    PelcoDParser.cpp ---------- C++ implementation file.
test -------------------------- Folder for test application files.
    3rdparty ------------------ Folder with third-party libraries for test application.
        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.

PelcoDParser class description

PelcoDParser class declaration

namespace cr
{
namespace pelcod
{
class PelcoDParser
{
public:

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

    /// Encode standard command.
    bool getStandardCommand(
        uint8_t *message,
        uint8_t addr,
        bool sense,
        bool autoScan,
        bool cameraOn,
        bool irisOpen,
        bool irisClose,
        bool focusNear,
        bool focusFar,
        bool zoomWide,
        bool zoomTele,
        bool up,
        bool down,
        bool left,
        bool right,
        uint8_t panSpeed = 0x00,
        uint8_t tiltSpeed = 0x00);

    /// Encode extended command.
    bool getExtendedCommand(
        uint8_t *message,
        uint8_t addr,
        PelcoDCommand id,
        int data1,
        int data2);

    /// Encode response.
    bool getResponse(   
        uint8_t *message,
        uint8_t addr,
        PelcoDResponse id,
        uint8_t &responseSize,
        int data1,
        int data2);

    /// Decode response.
    PelcoDResponse decodeResponse(
        uint8_t byte,
        int &data1,
        int &data2);

    /// Decode standard and extended command.
    PelcoDCommand decodeCommand(
        uint8_t byte, 
        int& address,
        int& data1,
        int& data2,
        bool& sense,
        bool& autoScan,
        bool& cameraOn,
        bool& irisOpen,
        bool& irisClose,
        bool& focusNear,
        bool& focusFar,
        bool& zoomWide,
        bool& zoomTele,
        bool& up,
        bool& down,
        bool& left,
        bool& right,
        uint8_t& panSpeed,
        uint8_t& tiltSpeed);
};
}
}

getVersion method

The getVersion() method returns string of current PelcoDParser class version. Method declaration:

static std::string getVersion();

Method can be used without PelcoDParser class instance:

std::cout << "PelcoDParser version: " << PelcoDParser::getVersion();

Console output:

PelcoDParser version: 1.0.0

getStandardCommand method

The getStandardCommand(…) method encodes (prepares data) standard control command. Method declaration:

bool getStandardCommand(
    uint8_t *message,
    uint8_t addr,
    bool sense,
    bool autoScan,
    bool cameraOn,
    bool irisOpen,
    bool irisClose,
    bool focusNear,
    bool focusFar,
    bool zoomWide,
    bool zoomTele,
    bool up,
    bool down,
    bool left,
    bool right,
    uint8_t panSpeed = 0x00,
    uint8_t tiltSpeed = 0x00);
Parameter Value
message Pointer to the buffer where the command will be encoded. The buffer must be at least 7 bytes long.
addr Camera address (1-255).
sense Sense bit. If set to true the command will be sent with sense bit.
autoScan Auto scan bit. If set to true the command will be sent with auto scan bit.
cameraOn Camera on bit. If set to true the command will be sent with camera on bit.
irisOpen Iris open bit. If set to true the command will be sent with iris open bit.
irisClose Iris close bit. If set to true the command will be sent with iris close bit.
focusNear Focus near bit. If set to true the command will be sent with focus near bit.
focusFar Focus far bit. If set to true the command will be sent with focus far bit.
zoomWide Zoom wide bit. If set to true the command will be sent with zoom wide bit.
zoomTele Zoom tele bit. If set to true the command will be sent with zoom tele bit.
up Up bit. If set to true the command will be sent with up bit.
down Down bit. If set to true the command will be sent with down bit.
left Left bit. If set to true the command will be sent with left bit.
right Right bit. If set to true the command will be sent with right bit.
panSpeed Pan speed. The value of the parameter is from 0x00 to 0x3F.
tiltSpeed Tilt speed. The value of the parameter is from 0x00 to 0x3F

Returns: TRUE if command was successfully encoded, otherwise FALSE.

getExtendedCommand method

The getExtendedCommand(…) method encodes (prepares data) extended control command for camera. Method declaration:

bool getExtendedCommand(
    uint8_t *message,
    uint8_t addr,
    PelcoDCommand id,
    int data1,
    int data2);

| Parameter | Value | | ——— | ———————————————————– | | message | Pointer to the buffer where the command will be encoded. The buffer must be at least 7 bytes long. | | addr | Camera address (1-255). | | id | Command ID (see PelcoDCommand enum). | | data1 | Command argument 1. The value of argument depends on command ID (see PelcoDCommand enum). Some commands don’t have arguments. | | data2 | Command argument 2. The value of argument depends on command ID (see PelcoDCommand enum). Some commands don’t have arguments. |

*Returns: TRUE if command was successfully encoded, otherwise FALSE.

getResponse method

The getResponse(…) method encodes (prepares data) response buffer. Method declaration:

bool getResponse(
    uint8_t *message,
    uint8_t addr,
    PelcoDResponse id,
    uint8_t &responseSize,
    int data1,
    int data2);
Parameter Value
message Pointer to the buffer where the response will be encoded. The buffer must be at least 7 bytes long.
addr Camera address (1-255).
id Response ID (see PelcoDResponse enum).
responseSize Size of the response. The size of the response depends on the response ID (see PelcoDResponse enum).
data1 Response argument 1. The value of argument depends on response ID (see PelcoDResponse enum). Some responses don’t have arguments.
data2 Response argument 2. The value of argument depends on response ID (see PelcoDResponse enum). Some responses don’t have arguments.

Returns: TRUE if response was successfully encoded, otherwise FALSE.

decodeResponse method

The decodeResponse(…) method decodes (interprets) response buffer. Method declaration:

PelcoDResponse decodeResponse(
    uint8_t byte,
    int &data1,
    int &data2);
Parameter Value
byte Next byte of response buffer.
data1 Response argument 1. The value of argument depends on response ID (see PelcoDResponse enum). Some responses don’t have arguments.
data2 Response argument 2. The value of argument depends on response ID (see PelcoDResponse enum). Some responses don’t have arguments.

Returns: Response ID (see PelcoDResponse enum). If no response was detected, the method returns PelcoDResponse::NONE.

decodeCommand method

The decodeCommand(…) method decodes (interprets) command buffer. Method declaration:

PelcoDCommand decodeCommand(
    uint8_t byte, 
    int& address,
    int& data1,
    int& data2,
    bool& sense,
    bool& autoScan,
    bool& cameraOn,
    bool& irisOpen,
    bool& irisClose,
    bool& focusNear,
    bool& focusFar,
    bool& zoomWide,
    bool& zoomTele,
    bool& up,
    bool& down,
    bool& left,
    bool& right,
    uint8_t& panSpeed,
    uint8_t& tiltSpeed);
Parameter Value
byte Next byte from command buffer.
address Reference a variable to store camera address.
data1 Reference a variable to store command argument 1. The value of argument depends on command ID (see PelcoDCommand enum). Some commands don’t have arguments.
data2 Reference a variable to store command argument 2. The value of argument depends on command ID (see PelcoDCommand enum). Some commands don’t have arguments.
sense Reference a variable to store sense bit.
autoScan Reference a variable to store auto scan bit.
cameraOn Reference a variable to store camera on bit.
irisOpen Reference a variable to store iris open bit.
irisClose Reference a variable to store iris close bit.
focusNear Reference a variable to store focus near bit.
focusFar Reference a variable to store focus far bit.
zoomWide Reference a variable to store zoom wide bit.
zoomTele Reference a variable to store zoom tele bit.
up Reference a variable to store up bit.
down Reference a variable to store down bit.
left Reference a variable to store left bit.
right Reference a variable to store right bit.
panSpeed Reference a variable to store pan speed. The value of the parameter is from 0x00 to 0x3F.
tiltSpeed Reference a variable to store tilt speed. The value of the parameter is from 0x00 to 0x3F.

Returns: Command ID (see PelcoDCommand enum). If no command was detected, the method returns PelcoDCommand::NONE.

Data structures

PelcoDCommand enum

The command IDs are described in the PelcoDCommand structure in the PelcoDCommand.h file. The definition of the structure is as follows:

namespace cr
{
namespace pelcod
{
enum class PelcoDCommand
{
    /** 
     * @brief Set preset. Command generates "General Reply".
     * @param data1 - PresetID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    SET_PRESET,

    /**
     * @brief Clear preset. Command generates "General Reply".
     * @param data1 - PresetID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    CLEAR_PRESET,

    /**
     * @brief Call preset. Command generates "General Reply".
     * @param data1 - PresetID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    CALL_PRESET,

    /**
     * @brief Set auxiliary. Command generates "General Reply".
     * @param data1 - AuxiliaryID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    SET_AUXILIARY,

    /**
     * @brief Set indicator. Command generates "General Reply".
     * @param data1 - AuxiliaryID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    SET_INDICATOR,

    /**
     * @brief Clear auxiliary. Command generates "General Reply".
     * @param data1 - AuxiliaryID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    CLEAR_AUXILIARY,

    /**
     * @brief Clear indicator. Command generates "General Reply".
     * @param data1 - AuxiliaryID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    CLEAR_INDICATOR,

    /**
     * @brief Originally an unused command. 
     * Command generates "General Reply".
     * @param data1 - Sub-device ID.
     * @param data2 - ON/OFF/TEMP.
     */
    DUMMY,

    /**
     * @brief Reset camera. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    REMOTE_RESET,

    /**
     * @brief Set zone start. Command generates "General Reply".
     * @param data1 - ZoneID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    SET_ZONE_START,

    /**
     * @brief Set zone end. Command generates "General Reply".
     * @param data1 - ZoneID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    SET_ZONE_END,

    /**
     * @brief Write character to screen. 
     * Command generates "General Reply".
     * @param data1 - Screen column: 0x00 - 0x28.
     * @param data2 - ASCII char: 0x00 - 0xFF.
     */
    WRITE_CHARACTER_TO_SCREEN,

    /**
     * @brief Clear screen. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    CLEAR_SCREEN,

    /**
     * @brief Alarm acknowledge. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    ALARM_ACKNOWLEDGE,

    /**
     * @brief Zone scan on. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    ZONE_SCAN_ON,

    /**
     * @brief Zone scan off. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    ZONE_SCAN_OFF,

    /**
     * @brief Pattern start. Command generates "General Reply".
     * @param data1 - PatternID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    RECORD_PATTERN_START,

    /**
     * @brief Pattern end. Command generates "General Reply".
     * @param data1 - PatternID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    RECORD_PATTERN_END,

    /**
     * @brief Run pattern. Command generates "General Reply".
     * @param data1 - PatternID: 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    RUN_PATTERN,

    /**
     * @brief Set zoom speed. Command generates "General Reply".
     * @param data1 - Zoom speed: 0x00 - 0x03.
     * @param data2 - Not used.
     */
    SET_ZOOM_SPEED,

    /**
     * @brief Set focus speed. Command generates "General Reply".
     * @param data1 - Focus speed: 0x00 - 0x03.
     * @param data2 - Not used.
     */
    SET_FOCUS_SPEED,

    /**
     * @brief Reset camera to default. 
     * Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    RESET_CAMERA_TO_DEFAULT,

    /**
     * @brief Auto focus. Command generates "General Reply".
     * @param data1 - 0x00 - Automatic operation.
     *                0x01 - Auto focus is off.
     * @param data2 - Not used.
     */
    AUTO_FOCUS,

    /**
     * @brief Auto iris. Command generates "General Reply".
     * @param data1 - 0x00 - Automatic operation.
     *                0x01 - Auto iris is off.
     * @param data2 - Not used.
     */
    AUTO_IRIS,

    /**
     * @brief AGC. Command generates "General Reply".
     * @param data1 - 0x00 - Automatic operation.
     *                0x01 - AGC is off.
     * @param data2 - Not used.
     */
    AGC,

    /**
     * @brief Backlight compensation. 
     * Command generates "General Reply".
     * @param data1 - 0x00 - BLC is off "Spectra IV". 
     *                0x01 - BLC is off / BLC is on "Spectra IV".
     *                0x02 - BLC is on.
     * @param data2 - Not used.
     */
    BACKLIGHT_COMPENSATION,

    /**
     * @brief Auto white balance. Command generates "General Reply".
     * @param data1 - 0x00 - AWB is on "Spectra IV".
     *                0x01 - AWB is on / AWB is off "Spectra IV".
     *                0x02 - AWB is off.
     * @param data2 - Not used.
     */
    AUTO_WHITE_BALANCE,

    /**
     * @brief Enable device phase delay mode. 
     * Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    ENABLE_DEVICE_PHASE_DELAY_MODE,

    /**
     * @brief Set shutter speed. 
     * Command generates "General Reply".
     * @param data1 - Shutter speed code: uint16_t value depends on particular device.
     * @param data2 - Not used.
     */
    SET_SHUTTER_SPEED,

    /**
     * @brief Set line lock phase delay. 
     * Command generates "General Reply".
     * @param data1 - uint16_t phase delay value 0x0000 - 0xffff.
     * @param data2 - Not used.             
     */
    ADJUST_LINE_LOCK_PHASE_DELAY_ABSOLUTE,

    /**
     * @brief Adjust line lock phase delay relative. 
     * Command generates "General Reply".
     * @param data1 - int16_t phase delay change -0x7f - 0x7f.
     * @param data2 - Not used.
     */
    ADJUST_LINE_LOCK_PHASE_DELAY_RELATIVE,
    
    /**
     * @brief Adjust white balance R/B. 
     * Command generates "General Reply".
     * @param data1 - R/B value: 0x0000 - 0xffff
     * @param data2 - Not used.
     */
    ADJUST_WHITE_BALANCE_R_B_ABSOLUTE,

    /**
     * @brief Adjust white balance R/B relative. 
     * Command generates "General Reply".
     * @param data1 - R/B change: -0x7fff - 0x7fff.
     * @param data2 - Not used.
     */
    ADJUST_WHITE_BALANCE_R_B_RELATIVE,

    /**
     * @brief Adjust white balance M/G. 
     * Command generates "General Reply".
     * @param data1 - M/G value: 0x0000 - 0xffff.
     * @param data2 - Not used.
     */
    ADJUST_WHITE_BALANCE_M_G_ABSOLUTE,

    /**
     * @brief Adjust white balance M/G relative. 
     * Command generates "General Reply".
     * @param data1 - M/G change: -0x7fff - 0x7fff.
     * @param data2 - Not used.
     */
    ADJUST_WHITE_BALANCE_M_G_RELATIVE,

    /**
     * @brief Adjust gain. Command generates "General Reply".
     * @param data1 - Gain value: 0x0000 - 0xffff.
     * @param data2 - Not used.
     */
    ADJUST_GAIN_ABSOLUTE,

    /**
     * @brief Adjust gain relative. 
     * Command generates "General Reply".
     * @param data1 - Gain change: -0x7fff - +0x7fff.
     * @param data2 - Not used.
     */
    ADJUST_GAIN_RELATIVE,

    /**
     * @brief Adjust auto iris level. 
     * Command generates "General Reply".
     * @param data1 - Iris level: 0x0000 - 0xffff. 
     * @param data2 - Not used.
     */
    ADJUST_AUTO_IRIS_LEVEL_ABSOLUTE,

    /**
     * @brief Adjust auto iris level relative. 
     * Command generates "General Reply".
     * @param data1 - Iris change: -0x7fff - 0x7fff.
     * @param data2 - Not used.
     */
    ADJUST_AUTO_IRIS_LEVEL_RELATIVE,

    /**
     * @brief Adjust auto iris peak value. 
     * Command generates "General Reply".
     * @param data1 - Iris peak value 0x0000 - 0xffff.
     * @param data2 - Not used.
     */
    ADJUST_AUTO_IRIS_PEAK_VALUE_ABSOLUTE,

    /**
     * @brief Adjust auto iris peak value relative. 
     * Command generates "General Reply".
     * @param data1 - Iris peak value change: -0x7fff - 0x7fff.
     * @param data2 - Not used.
     */
    ADJUST_AUTO_IRIS_PEAK_VALUE_RELATIVE,

    /**
     * @brief Query. Command generates "Query Reply".
     * @param data1 - Query type.
     * @param data2 - Not used.
     */
    QUERY,

    /**
     * @brief Set preset scan. Visit every preset for a given delay. 
     * Command generates "General Reply".
     * @param data1 - Delay (s): 0x00 - 0xFF.
     * @param data2 - Not used.
     */
    PRESET_SCAN,

    /**
     * @brief Set zero position. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    SET_ZERO_POSITION,

    /**
     * @brief Set pan position. Command generates "General Reply".
     * @param data1 - Pan position: 0 - 35999. 
     * @param data2 - Not used.
     */
    SET_PAN_POSITION,

    /**
     * @brief Set tilt position. Command generates "General Reply".
     * @param data1 - Tilt position: 0 - 35999. 
     * Zero position means horizontal. Ninety degrees indicates that the device 
     * is pointed straight down.
     * @param data2 - Not used.
     */
    SET_TILT_POSITION,

    /**
     * @brief Set zoom position. Command generates "General Reply".
     * @param data1 - Zoom position: 0 - 65535.
     * @param data2 - Not used.
     */
    SET_ZOOM_POSITION,

    /**
     * @brief Query pan position. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    QUERY_PAN_POSITION,

    /**
     * @brief Query tilt position. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    QUERY_TILT_POSITION,

    /**
     * @brief Query zoom position. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    QUERY_ZOOM_POSITION,

    /**
     * @brief Prepare for download. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    PREPARE_FOR_DOWNLOAD,

    /**
     * @brief Set magnification absolute. 
     * Command generates "General Reply".
     * @param data1 - Magnification value: 0x0000 - 0xFFFF.
     * @param data2 - Not used.
     */
    SET_MAGNIFICATION_ABSOLUTE,

    /**
     * @brief Set magnification relative. 
     * Command generates "General Reply".
     * @param data1 - int16_t Magnification value change -0x7f - 0x7f.
     * @param data2 - Not used.
     */
    SET_MAGNIFICATION_RELATIVE,

    /**
     * @brief Query magnification. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    QUERY_MAGNIFICATION,

    /**
     * @brief Activate echo mode. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    ACTIVATE_ECHO_MODE,

    /**
     * @brief Set remote baudrate. Command generates "General Reply".
     * @param data1 - 0x00 - 2400.
     *                0x01 - 4800.
     *                0x02 - 9600.
     *                0x03 - 19200.
     *                0x04 - 38400.
     *                0x05 - 115200.
     * @param data2 - Not used.
     */
    SET_BAUDRATE_REMOTE,

    /**
     * @brief Set local baudrate. Command generates "General Reply".
     * @param data1 - 0x00 - 2400.
     *                0x01 - 4800.
     *                0x02 - 9600.
     *                0x03 - 19200.
     *                0x04 - 38400.
     *                0x05 - 115200.
     * @param data2 - Not used.
     */
    SET_BAUDRATE_LOCAL,

    /**
     * @brief Start download. Command generates "General Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    START_DOWNLOAD,

    /**
     * @brief Query device type. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    QUERY_DEVICE_TYPE,

    /**
     * @brief Query diagnostic information. 
     * Command generates "Extended Reply" or "Super Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    QUERY_DIAGNOSTIC_INFORMATION,

    /**
     * @brief Version Information Macro Opcode. SW version.
     * Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    VERSION_INFORMATION_MACRO_SW_VERSION,

    /**
     * @brief Version Information Macro Opcode. Build version.
     * Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    VERSION_INFORMATION_MACRO_BUILD,

    /**
     * @brief Query pan offset. Command generates "Extended Reply".
     * @param data1 - not used.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_QUERY_PAN_OFFSET,

    /**
     * @brief Set zoom limit. Command generates "General Reply".
     * @param data1 - Zoom limit: 0 - 65535.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_SET_ZOOM_LIMIT,

    /**
     * @brief Query zoom limit. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_QUERY_ZOOM_LIMIT,

    /**
     * @brief Query alarms. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_QUERY_ALARMS,

    /**
     * @brief Delete pattern. Command generates "General Reply".
     * @param data1 - Pattern ID: 0x01 - 0xFF.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_DELETE_PATTERN,

    /**
     * @brief Set pan limit. Command generates "General Reply".
     * @param data1 - Limit type: 0x00 - Manual pan left limit.
     *                            0x01 - Manual pan right limit.
     *                            0x02 - Scan pan left limit.
     *                            0x03 - Scan pan right limit.
     * @param data2 - Pan limit: 0 - 35999.
     */
    EVEREST_MACRO_SET_PAN_LIMIT,

    /**
     * @brief Query manual pan right limit.
     * Command generates "ExtendedReply".
     * @param data1 - Limit type: 0x00 - Manual pan left limit.
     *                            0x01 - Manual pan right limit.
     *                            0x02 - Scan pan left limit.
     *                            0x03 - Scan pan right limit.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_QUERY_PAN_LIMIT,

    /**
     * @brief Set Enable/Disable limits. 
     * Command generates "General Reply".
     * @param data1 - Limit type: 0x00 - Disable limits.
     *                            0x01 - Enable limits.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_ENABLE_LIMITS,
    
    /**
     * @brief Query defined presets. 
     * Command generates "Extended Reply".
     * @param data1 - Preset group: 0x00 - 0x0F (probably 0x00 - 0xFF).
     * @param data2 - Not used.
     */
    EVEREST_MACRO_QUERY_DEFINED_PRESETS,

    /**
     * @brief Query defined patterns. 
     * Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_QUERY_DEFINED_PATTERNS,

    /**
     * @brief Set seconds and synchronize time.
     * Command generates "General Reply".
     * @param data1 - Seconds: 0x00 - 0x3B.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_SET_SECONDS_AND_SYNC,

    /**
     * @brief Query seconds. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_QUERY_SECONDS,

    /**
     * @brief Set hour and minute. Command generates "General Reply".
     * @param data1 - Hour: 0x00 - 0x17.
     * @param data2 - Minute: 0x00 - 0x3B.
     */
    TIMESET_MACRO_SET_HOUR_AND_MINUTE,

    /**
     * @brief Query hour and minute. 
     * Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_QUERY_HOUR_AND_MINUTE,

    /**
     * @brief Set month and day. Command generates "General Reply".
     * @param data1 - Month: 0x01 - 0x0C.
     * @param data2 - Day: 0x01 - 0x1F.
     */
    TIMESET_MACRO_SET_MONTH_AND_DAY,

    /**
     * @brief Query month and day. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_QUERY_MONTH_AND_DAY,

    /**
     * @brief Set year. Command generates "General Reply".
     * @param data1 - Year + 2000: 0x0000 - 0xFFFF.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_SET_YEAR,

    /**
     * @brief Query year. Command generates "Extended Reply".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_QUERY_YEAR,

    /**
     * @brief Screen move absolute. Pan/tilt positions are percentage 
     * of distance from center of screen to the corresponding edge.
     * Command generates "General Reply".
     * @param data1 - Pan:  -50 - 50. Negative values move left, positive right.
     * @param data2 - Tilt: -50 - 50. Negative values move down, positive up.
     */
    SCREEN_MOVE_ABSOLUTE,

    /**
     * @brief Screen move relative. Pan/tilt positions are percentage 
     * of distance from center of screen to the corresponding edge.
     * Command generates "General Reply".
     * @param data1 - Pan:  -100 - 100. Negative values move left, positive right.
     * @param data2 - Tilt: -100 - 100. Negative values move down, positive up.
     */
    SCREEN_MOVE_RELATIVE,

    /// COMMANDS TYPES FOR DECODE COMMANDS ONLY
    
    /**
     * @brief "No command". Used for decode command.
     */
    NONE,

    /**
     * @brief General command.
     */
    GENERAL_COMMAND,

    /**
     * @brief Unknown command type.
     * in case detected Pelco-D packet. Need to check extended command set.
     * @param data1 - command field. data[2]*256 + data[3].
     * @param data2 - data field. data[4]*256 + data[5].
     */
    UNKNOWN_COMMAND
};
}
}

PelcoDResponse enum

The response IDs are described in the PelcoDResponse structure in the PelcoDResponse.h file. The definition of the structure is as follows:

namespace cr
{
namespace pelcod
{
enum PelcoDResponse
{
    /**
     * @brief "No response". Used for decode response.
     */
    NONE,

    /**
     * @brief "General Reply".
     * This is a response to a command that does not have a specific response.
     * Size of the message is 4 bytes.
     * @param data1 - Alarm code: bit 0 - Alarm 1, bit 1 - Alarm - 2, etc.
     * @param data2 - Checksum of the command that caused this reply.
     */
    GEN,

    /**
     * @brief "Standard extended response".
     * Size of the message is 7 bytes.
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    ACK,

    /**
     * @brief "Standard extended response".
     * Size of the message is 7 bytes.
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    NAK,

    /**
     * @brief "Standard extended response".
     * @param data1 - Not used.
     * @param data2 - Not used.
     */
    STANDARD_EXTENDED,

    /**
     * @brief "Extended Reply" Pan position response. 
     * @param data1 - Pan position: 0 - 35999.
     * @param data2 - Not used.
     */
    PAN_POSITION_RESPONSE,

    /**
     * @brief "Extended Reply" Tilt position response.
     * @param data1 - Tilt position: 0 - 35999.
     * Zero position means horizontal. Ninety degrees indicates that the device 
     * is pointed straight down.
     * @param data2 - Not used.
     */
    TILT_POSITION_RESPONSE,

    /**
     * @brief "Extended Reply" Zoom position response.
     * @param data1 - Zoom position: 0 - 65535.
     * @param data2 - Not used.
     */
    ZOOM_POSITION_RESPONSE,

    /**
     * @brief "Extended Reply" Magnification response.
     * @param data1 - Magnification value.
     * @param data2 - Not used.
     */
    MAGNIFICATION_RESPONSE,

    /**
     * @brief "Extended Reply" Device type response.
     * @param data1 - Hard type.
     * @param data2 - Soft type.
     */
    DEVICE_TYPE_RESPONSE,

    /**
     * @brief "Extended Reply" Diagnostic information response.
     * @param data1 - Temp.
     * @param data2 - Sensor ID.
     */
    DIAGNOSTIC_INFORMATION_RESPONSE,

    /**
     * @brief "Extended Reply" Version information response.
     * @param data1 - Version number.
     * @param data2 - Not used.
     */
    INFORMATION_MACRO_SW_VERSION_RESPONSE,

    /**
     * @brief "Extended Reply" Version information response.
     * @param data1 - Build number.
     * @param data2 - Not used.
     */
    INFORMATION_MACRO_BUILD_RESPONSE,

    /**
     * @brief "Extended Reply" Pan offset response.
     * @param data1 - Pan offset. Value: 0 - 35999.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_PAN_OFFSET_RESPONSE,

    /**
     * @brief "Extended Reply" Zoom limit response.
     * @param data1 - Zoom limit in hundredths. Value: 0 - 65535.
     *                Example: 1600 means x16 zoom. 
     * @param data2 - Not used.
     */
    EVEREST_MACRO_ZOOM_LIMIT_RESPONSE,

    /**
     * @brief "Extended Reply" Alarms.
     * @param data1 - Alarm bit mask. 
     * @param data2 - Not used.
     */
    EVEREST_MACRO_ALARMS_RESPONSE,

    /**
     * @brief "Extended Reply" Pan limit response. 
     * Limit type depends on LIMIT ID that is being responded to.
     * @param data1 - Pan limit. Value: 0 - 35999.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_LIMITS_RESPONSE,

    /**
     * @brief "Extended Reply" Defined presets response.
     * @param data1 - BITMASK.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_DEFINED_PRESETS_RESPONSE,

    /**
     * @brief "Extended Reply" Defined patterns response.
     * @param data1 - BITMASK.
     * @param data2 - Not used.
     */
    EVEREST_MACRO_DEFINED_PATTERNS_RESPONSE,

    /**
     * @brief "Extended Reply" Seconds response.
     * @param data1 - Seconds: 0x00 - 0x3C.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_SECONDS_RESPONSE,

    /**
     * @brief "Extended Reply" Hour and minute response.
     * @param data1 - Hour: 0x00 - 0x17.
     * @param data2 - Minute: 0x00 - 0x3B.
     */
    TIMESET_MACRO_HOUR_MINUTE_RESPONSE,

    /**
     * @brief "Extended Reply" Month and day response.
     * @param data1 - Month: 0x01 - 0x0C.
     * @param data2 - Day: 0x01 - 0x1F.
     */
    TIMESET_MACRO_MONTH_DAY_RESPONSE,

    /**
     * @brief "Extended Reply" Year response.
     * @param data1 - Year + 2000: 0x0000 - 0xFFFF.
     * @param data2 - Not used.
     */
    TIMESET_MACRO_YEAR_RESPONSE
};
}
}

Build and connect to your project

Typical commands to build PelcoDParser library:

cd PelcoDParser
mkdir build
cd build
cmake ..
make

If you want connect PelcoDParser 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 in your repository folder and copy PelcoDParser repository folder there. New structure of your repository:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    PelcoDParser

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)

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

File 3rdparty/CMakeLists.txt adds folder PelcoDParser to your project and excludes test application from compiling (by default test applications and example are excluded from compiling if PelcoDParser is included as sub-repository). The new structure of your repository:

CMakeLists.txt
src
    CMakeList.txt
    yourLib.h
    yourLib.cpp
3rdparty
    CMakeLists.txt
    PelcoDParser

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 PelcoDParser library in your src/CMakeLists.txt file:

target_link_libraries(${PROJECT_NAME} PelcoDParser)

Done!

Test application

Folder PelcoDParser/test contains the test application files. The test application allows you to generate any command, send it to the camera over the serial port, receive and decode 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) and camera address (default 7):

================================================
PelcoDParser tester v1.0.0
================================================

Set serial port name: /dev/ttyUSB0
Set baudrate (default : 9600): 9600
Enter the camera address (default 1): 1

After user can choose command (enter command ID). If no necessary command has been displayed user can set ID according to PelcodCommand enum (test application supports all commands, but shown few, if your need all commands you can set necessary ID):

-1 - exit
0  - sense
1  - auto scan
2  - camera on
3  - iris open/close
4  - focus near/far
5  - zoom wide/tele
6  - up/down
7  - left/right
8  - pan speed
9  - tilt speed
10 - Other commands (see PelcoDCommand enum for IDs)

Table of contents