1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
/*      File: EL1018.cpp
*       This file is part of the program ethercatcpp-core
*       Program description : EtherCAT driver libraries for UNIX
*       Copyright (C) 2017-2024 -  Robin Passama (LIRMM / CNRS) Arnaud Meline (LIRMM / CNRS) Benjamin Navarro (LIRMM / CNRS). All Right reserved.
*
*       This software is free software: you can redistribute it and/or modify
*       it under the terms of the CeCILL-C license as published by
*       the CEA CNRS INRIA, either version 1
*       of the License, or (at your option) any later version.
*       This software is distributed in the hope that it will be useful,
*       but WITHOUT ANY WARRANTY without even the implied warranty of
*       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*       CeCILL-C License for more details.
*
*       You should have received a copy of the CeCILL-C License
*       along with this software. If not, it can be found on the official website
*       of the CeCILL licenses family (http://www.cecill.info/index.en.html).
*/
/**
 * @file beckhoff_terminals/EL1018.cpp
 * @author Robin Passama
 * @brief source file for EL1018 class
 *
 */
#include <ethercatcpp/beckhoff_terminals/EL1018.h>

#include <pid/log/ethercatcpp-core_ethercatcpp-core.h>

namespace ethercatcpp {

namespace {
struct [[gnu::packed]] buffer_in_cyclic_status_t {
    uint8_t data;<--- struct member 'buffer_in_cyclic_status_t::data' is never used.
};

} // namespace

EL1018::EL1018() : SlaveDevice(), data_{0} {
    set_id("EL1018", 0x00000002, 0x03fa3052);

    // Input buffer config
    define_physical_buffer<buffer_in_cyclic_status_t>(SYNCHROS_IN, 0x1000,
                                                      0x00010000);

    //----------------------------------------------------------------------------//
    //                     R U N S     S T E P S //
    //----------------------------------------------------------------------------//

    add_run_step([]() {},
                 [this]() { unpack_status_buffer(); }); // add_Run_Step end

} // constructor end

EL1018::~EL1018() = default;

void EL1018::unpack_status_buffer() {
    auto buff = input_buffer<buffer_in_cyclic_status_t>(0x1000);
    data_ = buff->data;
}

bool EL1018::channel_state(channel_id_t channel) const {
    switch (channel) {
    case channel_1:
        return (data_ >> 0) & 1U;
        break;
    case channel_2:
        return (data_ >> 1) & 1U;
        break;
    case channel_3:
        return (data_ >> 2) & 1U;
        break;
    case channel_4:
        return (data_ >> 3) & 1U;
        break;
    case channel_5:
        return (data_ >> 4) & 1U;
        break;
    case channel_6:
        return (data_ >> 5) & 1U;
        break;
    case channel_7:
        return (data_ >> 6) & 1U;
        break;
    case channel_8:
        return (data_ >> 7) & 1U;
        break;
    default:
        return false;
    }
}

void EL1018::print_all_channels() const {

    std::vector<channel_id_t> all_channel{channel_1, channel_2, channel_3,
                                          channel_4, channel_5, channel_6,
                                          channel_7, channel_8};

    for (auto& channel : all_channel) {
        pid_log << pid::info << "Channel " << channel + 1
                << " state :" << channel_state(channel) << "\n";
    }
    pid_log << pid::flush; // flush all cout
}

} // namespace ethercatcpp