C++ API

C++ DEVICE INTERFACE

group Device Interfaces

Device interface definitions for the CPP API.

This group includes device interface definitions that are shared across modules.

Functions

virtual void setAllDigitalPortsDirections(uint32_t direction_mask) = 0

Configure the direction of all digital ports at once.

Parameters:

direction_mask[in] A bitmask representing the direction of each port. A 0 bit indicates PORT_INPUT, a 1 bit indicates PORT_OUTPUT. The least significant bit corresponds to port 0.

Returns:

ADDIDATA_SUCCESS_CODE on success. Otherwise, see Common Error Codes.

class CounterInterface
#include <counter_interface.hpp>

Interface for counter operations.

This class provides an interface for managing device counters

Public Functions

virtual void initCounter(uint8_t counter_id, uint32_t reload_value, uint32_t options) = 0

CounterInterface constructor.

virtual void startCounter(uint8_t counter_id) = 0

Start the counter.

virtual void stopCounter(uint8_t counter_id) = 0

Stop the counter.

virtual uint32_t readCounterValue(uint8_t counter_id) = 0

Read the current value of the counter.

virtual void readCounterStatus(uint8_t counter_id, uint32_t &read_value, uint8_t &is_started, uint8_t &software_trigger, uint8_t &has_expired) = 0

Read the status of the counter.

virtual void enableCounterInterrupt(uint8_t counter_id) = 0

Enable counter interrupts.

virtual void disableCounterInterrupt(uint8_t counter_id) = 0

Disable counter interrupts.

class Device
#include <device.hpp>

Main device class providing access to all hardware interfaces.

Through this class, users can access all available interfaces, such as timers, counters, digital I/O, watchdogs, and interrupts.

Example usage:

auto device = DeviceDiscoverySingleton::getInstance().getDeviceFromID("device_id");
device->timer()->initTimer(0, TIMEBASE_MS, 1000, 0); // Access TimerInterface via Device

Public Functions

Device()

Device constructor.

virtual ~Device() = default

Device destructor.

virtual AddiDataDeviceStruct getDeviceInformation() = 0

Get device information.

TimerInterface *timer()

Get the Timer Interface TimerInterface.

CounterInterface *counter()

Get the Counter Interface CounterInterface.

DigitalIOInterface *digitalIo()

Get the Digital I/O Interface DigitalIOInterface.

DigitalIOPortsInterface *digitalIoPorts()

Get the Digital I/O Ports Interface DigitalIOPortsInterface.

WatchdogInterface *watchdog()

Get the Watchdog Interface WatchdogInterface.

InterruptInterface *interrupt()

Get the Interrupt Interface InterruptInterface.

class DeviceDiscovery
#include <device_discovery.hpp>

Interface for device discovery.

This class provides methods to discover and access connected devices

Public Static Functions

static std::vector<std::shared_ptr<Device>> getDevices()

Get a list of all connected devices.

static std::shared_ptr<Device> getDeviceFromId(const std::string &device_id)

Get a device from its ID.

class DigitalIOInterface : public DigitalIOCommonInterface
#include <digital_io_interface.hpp>

Interface for digital I/O operations.

This class provides an interface for managing device Digio

Public Functions

virtual bool readSingleDigitalInput(uint8_t channel) = 0

Will read a single digital input at the specified channel.

Parameters:

channel – which channel to read

Returns:

true if the value is 1

Returns:

false if the value is 0

virtual uint32_t readAllDigitalInput() = 0

Read all 32 channels and return the values as an integer.

Returns:

int the values of each channel

virtual void writeSingleDigitalOutput(uint8_t channel, bool value) = 0

Will write a single value at the specified channel.

Parameters:
  • channel

  • value – The value to be written, 1 (true) or 0 (false)

virtual void writeAllDigitalOutput(uint32_t channels, bool value) = 0

Write all channels.

Parameters:

value – to write to masked channels

virtual uint32_t getDigitalOutputStatus() = 0

Get current output values.

virtual void setInterruptEventForInputs(uint32_t channels, DIGITAL_EVENT_TYPE event_type) = 0

Set the interrupt behaviour For Inputs, Old values should be kept and not erased, so multiple calls can be made to set each channels.

Parameters:
  • channels – Channels mask. A 1 will represent a channel to modify the value.

  • event_type – type of event that will trigger an interrupt in the masked channels

virtual void setInterruptEventForOneInput(uint8_t channel, DIGITAL_EVENT_TYPE event_type) = 0

Set the interrupt behaviour for a single input. Old values should be kept and not erased.

Parameters:
  • channel – channel to set the interrupt

  • event_type – type of event that will trigger an interrupt

virtual void setInterruptLogicForPort(uint8_t port_number, DIGITAL_EVENT_LOGIC event_logic) = 0

Set the Interrupt Logic For given Port number.

Parameters:
  • port_number

  • event_logic – AND or OR

virtual void setOutputInterrupt(bool enable_vcc, bool enable_cc) = 0

Configure digital output interrupts.

Parameters:
  • enable_vcc – Enable VCC interrupt

  • enable_cc – Enable CC interrupt

virtual void enableDigitalInterrupt() = 0

Enable digital interrupts.

virtual void disableDigitalInterrupt() = 0

Disable digital interrupts.

virtual void setOutputMemoryOn() = 0

Clear digital interrupt status.

virtual void setOutputMemoryOff() = 0

Clear digital interrupt status.

class DigitalIOPortsInterface : public DigitalIOCommonInterface
#include <digital_io_interface.hpp>

Interface for digital I/O operations using Ports configuration.

This class provides an interface for managing device Digio with Ports configuration, allowing up to 96 channels (e.g., for APCI-1696)

Public Functions

virtual uint32_t getAllDigitalPortDirections() = 0

Get the direction of all digital ports at once.

Returns:

A 32 bitmask representing the direction of each port. A 0 bit indicates PORT_INPUT, a 1 bit indicates PORT_OUTPUT. The least significant bit corresponds to port 0.

virtual uint8_t readAllDigitalInputsFromPort(uint8_t port_number) = 0

Read all channels of a port and return the values as an integer.

Parameters:

port_number – which port to read

Returns:

8 bitmask representing the value of each channel of the port, where a 1 indicates a high value and a 0 indicates a low value

virtual void writeSingleDigitalOutputOnPort(uint8_t channel, uint8_t value, uint8_t port_number) = 0

Will write a single value at the specified channel of a port.

Parameters:
  • channel – which channel to write

  • value – The value to be written, 1 (true) or 0 (false)

  • port_number – which port to write

virtual void writeAllDigitalOutputsOnPort(uint8_t channels_mask, uint8_t value, uint8_t port_number) = 0

Write all channels of a port. Only channels with a corresponding 1 in the channels_mas will be modified.

Parameters:
  • channels_mask – A 8 bitmask representing the channels to modify, where a 1 indicates a channel to modify and a 0 indicates a channel to keep unchanged

  • value – The value to write to the masked channels, 1 (true) or 0 (false)

virtual uint8_t getDigitalOutputsStatusOnPort(uint8_t port_number) = 0

Get current output values of a port. Only channels with a corresponding 1 in the channels_mask will be returned.

Parameters:

port_number – which port to query

Returns:

8 bitmask representing the value of each masked channel of the port, where a 1 indicates a high value and a 0 indicates a low value

virtual void enableDigitalInterrupt() = 0

Enable digital interrupts.

virtual void disableDigitalInterrupt() = 0

Disable digital interrupts.

virtual void setOutputMemoryOn() = 0

Clear digital interrupt status.

virtual void setOutputMemoryOff() = 0

Clear digital interrupt status.

class InterruptInterface
#include <interrupt_interface.hpp>

Interrupt Interface class.

This class provides an interface for managing device interrupts.

Public Functions

~InterruptInterface() = default

InterruptInterface constructor.

virtual void setDeviceInterruptCallback(std::function<void(const AddiDataDeviceStruct&, const InterruptData&)> interrupt_callback) = 0

Set the Device Interrupt Callback.

virtual void enableDeviceInterrupts() = 0

Enable device interrupts.

virtual void disableDeviceInterrupts() noexcept = 0

Disable device interrupts.

virtual void clearInterruptFifo() = 0

Clear the interrupt FIFO.

virtual bool isInterruptActive() = 0

Check if an interrupt is active.

class TimerInterface
#include <timer_interface.hpp>

Interface for Timer operations.

This class provides methods to for managing device timers

Public Functions

virtual ~TimerInterface() = default

TimerInterface destructor.

virtual void initTimer(uint8_t timer_id, TIMEBASE_UNITS timebase, uint16_t reload_value, uint32_t options) = 0

Initialize the timer with specified parameters.

virtual void setCustomTimerFrequency(uint32_t frequency) = 0

Set a custom frequency for cards that support it.

Parameters:

frequency – in Hz to set

virtual void startTimer(uint8_t timer_id) = 0

Start the timer.

virtual void stopTimer(uint8_t timer_id) = 0

Stop the timer.

virtual uint32_t readTimerValue(uint8_t timer_id) = 0

Read the current value of the timer.

virtual void readTimerStatus(uint8_t timer_id, uint32_t &read_value, uint8_t &is_started, uint8_t &software_trigger, uint8_t &has_expired) = 0

Read the status of the timer.

virtual void triggerTimer(uint8_t timer_id) = 0

Trigger the timer via software.

virtual void enableTimerInterrupt(uint8_t timer_id) = 0

Enable timer interrupts.

virtual void disableTimerInterrupt(uint8_t timer_id) = 0

Disable timer interrupts.

class WatchdogInterface
#include <watchdog_interface.hpp>

Interface for Watchdog operations.

This class provides methods to for managing device watchdogs

Public Functions

virtual void initWatchdog(uint8_t watchdog_id, TIMEBASE_UNITS timebase, uint16_t reload_value, uint32_t options) = 0

Init the watchdog.

virtual void startWatchdog(uint8_t watchdog_id) = 0

Start the watchdog.

virtual void stopWatchdog(uint8_t watchdog_id) = 0

Stop the watchdog.

virtual uint32_t readWatchdogValue(uint8_t watchdog_id) = 0

Read the current value of the watchdog.

virtual void readWatchdogStatus(uint8_t watchdog_id, uint32_t &read_value, uint8_t &is_started, uint8_t &software_trigger, uint8_t &has_expired) = 0

Read the status of the watchdog.

virtual void triggerWatchdog(uint8_t watchdog_id) = 0

Trigger the watchdog via software.

virtual void enableWatchdogInterrupt(uint8_t watchdog_id) = 0

Enable watchdog interrupts.

virtual void disableWatchdogInterrupt(uint8_t watchdog_id) = 0

Disable watchdog interrupts.

C++ ERROR CODES

group Error Codes

Error codes and definitions for the CPP API.

This group includes error codes and definitions that are shared across modules.

class AddiPackException : public exception, public exception
#include <addi_pack_exceptions.hpp>

Custom exception class for AddiPack-related errors.

This class extends the standard std::exception to provide detailed error handling specific to the AddiPack library. It includes error codes, messages, and methods to extract error information.

Public Functions

AddiPackException()

Default constructor for AddiPackException.

AddiPackException(const std::string &message, uint32_t code)

Constructs an AddiPackException with an optional message and error code.

Parameters:
  • message – A descriptive error message.

  • code – An integer error code.

const char *what() const noexcept override

Returns a C-style string describing the error.

uint32_t getCode() const noexcept

Retrieves the error code associated with the exception.

Returns:

The integer error code.

AddiDataSource getSource(uint32_t code)

Extracts the source from the given error code.

Parameters:

code – The error code to extract the source from.

Returns:

The extracted AddiDataSource.

AddiDataDomain getDomain(uint32_t code)

Extracts the domain from the given error code.

Parameters:

code – The error code to extract the domain from.

Returns:

The extracted AddiDataDomain.

AddiDataFunction getFunction(uint32_t code)

Extracts the function from the given error code.

Parameters:

code – The error code to extract the function from.

Returns:

The extracted AddiDataFunction.

AddiDataReason getReason(uint32_t code)

Extracts the reason from the given error code.

Parameters:

code – The error code to extract the reason from.

Returns:

The extracted AddiDataReason.

void setMessage(const std::string &message)

Sets the error message for the exception.

Parameters:

message – The error message to set.

void setErrorCode(uint32_t code)

Sets the error code for the exception.

Parameters:

code – The error code to set.

Public Static Functions

static std::string getAddiDataLastError()

Retrieves the last error message from the AddiData library.

Returns:

The last error message as a string.

C++ UTILS

group Utilities

Utilities and helper functions for the CPP API.

This group includes utility functions and helper methods that are shared across modules.

class ArgParser
#include <arg_parser.hpp>

Argument Parser for command line options.

This class provides methods to parse and manage command line arguments

Public Functions

ArgParser() = delete

ArgParser constructor is deleted to prevent instantiation.

Public Static Functions

static void init()

Initialize the argument parser.

static void clear()

Clear all registered options and flags.

static void addOption(const std::string &name, char short_option, const std::string &description, bool has_value = true)

Add an option with a name, short option, description, and whether it requires a value.

static void addFlag(const std::string &name, char short_option, const std::string &description)

Add a flag with a name, short option, and description.

static void parse(int argc, char *argv[])

Parse command line arguments.

static bool isFlagSet(const std::string &name)

Check if a flag is set.

static bool isOptionSet(const std::string &name)

Check if an option is set.

static std::string getOptionValue(const std::string &name)

Get the value of an option.

User I/O

group User I/O

Input/Output User utilities for the CPP API.

I/O related utilities and helper functions.

Functions

void printAvailableOptions(unsigned int valid_mask, std::vector<int> &option_index)

Utility functions for samples and user interaction.

unsigned int getTcwOptionsFromUser(unsigned int valid_mask)

Prompt the user to select options based on a valid mask.

std::string promptString(const std::string &message, const std::vector<std::string> &accepted = {})

Prompt the user to input a string, with optional accepted values and default.

int promptInt(const std::string &message, int min, int max)

Prompt the user to input an integer within a specified range, with an optional default value.

std::string getValidString(const std::string &name, const std::string &message, const std::vector<std::string> &accepted = {})

Get a valid string from the user, ensuring it is within accepted values if provided.

int getValidInt(const std::string &name, const std::string &message, int min, int max)

Get a valid integer from the user within a specified range.

void exitOnUserInput(int exit_code)

Wait for user input before exiting, then exit with the specified code.

void displayAllPortsConfigurations(std::uint16_t direction_mask, const std::uint8_t *input_values, const std::uint8_t *output_values, std::uint8_t max_port)

Display the configuration of all ports in a formatted table.

Parameters:
  • direction_mask – A bitmask representing the direction of each port, where a 1 indicates output and a 0 indicates input

  • input_values – An array of input values for each port

  • output_values – An array of output values for each port

  • max_port – The maximum number of ports on the card

Device

group Device Utils

Device utilities for the CPP API.

Device related utilities and helper functions.

Functions

std::shared_ptr<Device> selectDeviceByCapability(const std::vector<std::shared_ptr<Device>> &devices, const std::string &name, bool (*predicate)(const std::shared_ptr<Device>&), const std::string &label)

Select a device from a list based on a capability predicate.

std::string selectMode(const std::string &name, const std::vector<std::string> &modes, const std::vector<std::string> &descriptions = {})

Select a mode from a list of modes with optional descriptions.

std::vector<std::string> getValidTimebaseList(const std::shared_ptr<Device> &device)

Get the list of valid timebases supported by a device.

Timer Interruptions

group Timer Interruptions Utils

Timer Interruption utilities for the CPP API.

Timer interruption related utilities and helper functions.

Functions

TIMEBASE_UNITS parseTimebase(const std::string &timebase)

Parse a timebase string into TIMEBASE_UNITS.

void interruptCallback(AddiDataDeviceStruct, InterruptData data)

Callback function to handle interrupts and set a flag.

void resetInterruptFlag()

Reset the interrupt flag.

bool hasInterruptHappened()

Check if an interrupt has occurred.