Line data Source code
1 : /* File: BK1150.h 2 : * This file is part of the program ethercatcpp-core 3 : * Program description : EtherCAT driver libraries for UNIX 4 : * Copyright (C) 2017-2024 - Robin Passama (LIRMM / CNRS) Arnaud Meline 5 : * (LIRMM / CNRS) Benjamin Navarro (LIRMM / CNRS). All Right reserved. 6 : * 7 : * This software is free software: you can redistribute it and/or modify 8 : * it under the terms of the CeCILL-C license as published by 9 : * the CEA CNRS INRIA, either version 1 10 : * of the License, or (at your option) any later version. 11 : * This software is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * CeCILL-C License for more details. 15 : * 16 : * You should have received a copy of the CeCILL-C License 17 : * along with this software. If not, it can be found on the official 18 : * website of the CeCILL licenses family (http://www.cecill.info/index.en.html). 19 : */ 20 : /** 21 : * @file beckhoff_terminals/BK1150.h 22 : * @author Robin Passama 23 : * @brief EtherCAT driver for a generic beckhoff BK1150 device. 24 : * @date February 2020. 25 : * @ingroup ethercatcpp-core 26 : * @example beckhoff_BK1150_KL2284_example.cpp 27 : */ 28 : #pragma once 29 : 30 : #include <ethercatcpp/beckhoff_terminals/KL_extensions.h> 31 : #include <ethercatcpp/core.h> 32 : #include <memory> 33 : 34 : /*! \namespace ethercatcpp 35 : * 36 : */ 37 : namespace ethercatcpp { 38 : 39 : /** @brief This class describe the EtherCAT driver for a beckhoff BK1150 slave 40 : * 41 : * @details This driver allows to communicate with a beckhoff BK1150 through an 42 : * EtherCAT bus. The BK1150 EtherCAT Terminal is a generic ethercat slave whose 43 : * capabilities depend on extensions plugged on its internal real-time BUS. It 44 : * can be specialized whenever a set of specific KL extensions are plugged on 45 : * its internal BUS or it can also be created dynamically by adding KL 46 : * extensions. 47 : * @see KLExtensionCard 48 : */ 49 : class BK1150 : public SlaveDevice { 50 : public: 51 : /** 52 : * @brief Constructor of BK1150 class 53 : */ 54 : BK1150(); 55 0 : ~BK1150() = default; 56 : 57 : /** 58 : * @brief get the module present on BK1150 internal bus at given index 59 : * 60 : * @param index the index of the extension module 61 : * @return a shared pointer to the extension module 62 : */ 63 : const std::shared_ptr<KLExtensionCard>& extension(unsigned int index) const; 64 : 65 : /** 66 : * @brief get the module present on BK1150 internal bus at given index 67 : * @tparam KLType the type of the module 68 : * @param index the index of the extension module 69 : * @return a shared pointer to the extension module with specialized type 70 : */ 71 : template <typename KLType> 72 : const std::shared_ptr<KLType>& extension(unsigned int index) const { 73 : return (std::dynamic_pointer_cast<KLType>(extension(index))); 74 : } 75 : 76 : /** 77 : * @brief Adding an extension module to the internal bus 78 : * 79 : * @tparam Extension type of the extension module 80 : * @tparam Args types of arguments to pass at module construction time 81 : * @param args arguments to pass at module construction time 82 : * @return a specialized shared pointer to the extension created 83 : */ 84 : template <typename Extension, typename... Args> 85 : std::shared_ptr<Extension> add_Extension(Args&&... args) { 86 : auto ext = std::make_shared<Extension>(args...); 87 : ext->set_holder(this, extensions_.size()); 88 : if (ext->digital()) { 89 : digital_extensions_.push_back(ext); 90 : } else { 91 : non_digital_extensions_.push_back(ext); 92 : } 93 : extensions_.push_back( 94 : ext); // Note: usefull for end user to get extension 95 : // in same order as in the physical K BUS 96 : return (ext); 97 : } 98 : 99 : /** 100 : * @brief initialize the internal bus. 101 : * 102 : */ 103 : void init(); 104 : 105 : private: 106 : friend class KLExtensionCard; 107 : 108 : std::vector<std::shared_ptr<KLExtensionCard>> extensions_; 109 : std::vector<std::shared_ptr<KLExtensionCard>> digital_extensions_; 110 : std::vector<std::shared_ptr<KLExtensionCard>> non_digital_extensions_; 111 : 112 : void update_command_buffer(); 113 : void unpack_status_buffer(); 114 : 115 : uint8_t* output(uint8_t index, uint8_t& bit_shift); 116 : uint8_t* input(uint8_t index, uint8_t& bit_shift); 117 : }; 118 : 119 : } // namespace ethercatcpp