peary/interfaces/Interface.hpp

Peary Interface. More…

Namespaces

Name
peary
peary::device Forward declaration of CaribouDevice, Board, and Carboard classes.
peary::hal
peary::board
peary::board::carboard
peary::interface

Classes

Name
class peary::interface::Interface Abstract base class for communication interfaces.

Defines

Name
FRIEND(FN)
TEMPLATEFRIEND(FN)
GENERATE_FRIENDS() Macro to generate friend declarations for specific classes.

Detailed Description

Peary Interface.

Copyright: Copyright (c) 2016-2025 CERN and the Peary Caribou authors. This software is distributed under the terms of the LGPL-3.0-only License, copied verbatim in the file “LICENSE.md”. SPDX-License-Identifier: LGPL-3.0-only

Macros Documentation

define FRIEND

  #define FRIEND(
    FN
)
friend class FN;
  

define TEMPLATEFRIEND

  #define TEMPLATEFRIEND(
    FN
)
template <typename B, typename SCI, typename DRI> friend class FN;
  

define GENERATE_FRIENDS

  #define GENERATE_FRIENDS(
    
)
    TEMPLATEFRIEND(peary::device::CaribouDevice)                                                                            \
    FRIEND(peary::hal::Board) FRIEND(peary::board::carboard::Carboard)
  

Macro to generate friend declarations for specific classes.

Source code

  
#pragma once

#define FRIEND(FN) friend class FN;
#define TEMPLATEFRIEND(FN) template <typename B, typename SCI, typename DRI> friend class FN;

#include <cstdint>
#include <string>
#include <utility>
#include <vector>

#include "peary/config/configuration.hpp"
#include "peary/interfaces/exceptions.hpp"
#include "peary/log/log.hpp"
#include "peary/utils/utils.hpp"

#include "interfaceConfiguration.hpp"

// forward declaration required by the GENERATE_FRIENDS macro
namespace peary::device {
    template <typename B, typename SCI, typename DRI> class CaribouDevice;
}
namespace peary::hal {
    class Board;
}
namespace peary::board::carboard {
    class Carboard;
}

#define GENERATE_FRIENDS()                                                                                                  \
    TEMPLATEFRIEND(peary::device::CaribouDevice)                                                                            \
    FRIEND(peary::hal::Board) FRIEND(peary::board::carboard::Carboard)

namespace peary::interface {

    // Abstract class for all interfaces
    //@param ADDRESS_T : type for a device address
    //@param REG_T : type for register addresses
    //@param DATA_T : type for data
    template <typename REG_T = uint8_t, typename DATA_T = REG_T, typename CONFIG_T = InterfaceConfiguration>
    class Interface {
    public:
        using reg_type = REG_T;
        using data_type = DATA_T;
        using configuration_type = CONFIG_T;
        using dataVector_type = std::vector<data_type>;

        std::string devicePath() const { return _devicePath; }

    private:
        // Path of the device
        const std::string _devicePath;

    protected:
        explicit Interface(const InterfaceConfiguration& config) : _devicePath(config._devpath) {};

        virtual ~Interface() = default;

        virtual DATA_T write(const DATA_T&) { throw CommunicationError("Functionality not provided by this interface"); };

        virtual dataVector_type write(const dataVector_type&) {
            throw CommunicationError("Functionality not provided by this interface");
        };

        virtual std::pair<REG_T, DATA_T> write(const std::pair<REG_T, DATA_T>&) {
            throw CommunicationError("Functionality not provided by this interface");
        };

        virtual dataVector_type write(const REG_T&, const dataVector_type&) {
            throw CommunicationError("Functionality not provided by this interface");
        };

        virtual std::vector<std::pair<REG_T, DATA_T>> write(const std::vector<std::pair<REG_T, DATA_T>>&) {
            throw CommunicationError("Functionality not provided by this interface");
        };

        virtual DATA_T read() { throw CommunicationError("Functionality not provided by this interface"); };

        virtual dataVector_type read(const unsigned int) {
            throw CommunicationError("Functionality not provided by this interface");
        };

        virtual dataVector_type read(const REG_T&, const unsigned int) {
            throw CommunicationError("Functionality not provided by this interface");
        };
    };

} // namespace peary::interface
  

Updated on 2025-11-14 at 11:31:23 +0100