| Line |
Branch |
Exec |
Source |
| 1 |
|
|
/***************************************************************************** |
| 2 |
|
|
* |
| 3 |
|
|
* This file is part of the ecapp library (EtherCAT application devices). |
| 4 |
|
|
* |
| 5 |
|
|
* Copyright (C) 2026 Florian Pose <fp@igh.de> |
| 6 |
|
|
* |
| 7 |
|
|
* The ecapp library is free software: you can redistribute it and/or |
| 8 |
|
|
* modify it under the terms of the GNU Lesser General Public License |
| 9 |
|
|
* as published by the Free Software Foundation, version 3 of the |
| 10 |
|
|
* License. |
| 11 |
|
|
* |
| 12 |
|
|
* The ecapp library is distributed in the hope that it will be useful, |
| 13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
|
|
* Lesser General Public License for more details. |
| 16 |
|
|
* |
| 17 |
|
|
* You should have received a copy of the GNU Lesser General Public |
| 18 |
|
|
* License along with the ecapp library. If not, see |
| 19 |
|
|
* <https://www.gnu.org/licenses/>. |
| 20 |
|
|
* |
| 21 |
|
|
* Festo bus node (fieldbus coupler for a modular valve terminal). |
| 22 |
|
|
* Unlike every other ecapp terminal, its channel count isn't fixed by |
| 23 |
|
|
* a catalog type -- how many of the 32 reserved output bits an |
| 24 |
|
|
* installation actually uses depends on how many valve modules are |
| 25 |
|
|
* physically attached, so it is set at runtime via the |
| 26 |
|
|
* ConfigurableChannelCount capability rather than baked into a Type |
| 27 |
|
|
* enum. The PDO layout itself is fixed regardless (always 32 bits |
| 28 |
|
|
* reserved); only vector sizes and pdserv wiring depend on the count. |
| 29 |
|
|
* |
| 30 |
|
|
****************************************************************************/ |
| 31 |
|
|
|
| 32 |
|
|
#ifndef ECAPP_FESTO_H |
| 33 |
|
|
#define ECAPP_FESTO_H |
| 34 |
|
|
|
| 35 |
|
|
/****************************************************************************/ |
| 36 |
|
|
|
| 37 |
|
|
#include "ecapp/Mode.h" |
| 38 |
|
|
|
| 39 |
|
|
#include <ecrt.h> // EtherCAT realtime interface |
| 40 |
|
|
#include <pdserv.h> |
| 41 |
|
|
#include <stdint.h> |
| 42 |
|
|
#include <string> |
| 43 |
|
|
#include <vector> |
| 44 |
|
|
|
| 45 |
|
|
/****************************************************************************/ |
| 46 |
|
|
|
| 47 |
|
|
namespace EcApp { |
| 48 |
|
|
|
| 49 |
|
|
class Master; |
| 50 |
|
|
class Domain; |
| 51 |
|
|
|
| 52 |
|
|
template <Mode mode> |
| 53 |
|
2 |
class Festo |
| 54 |
|
|
{ |
| 55 |
|
|
public: |
| 56 |
|
|
// 4 PDO entries of 8 bits each are reserved regardless of how |
| 57 |
|
|
// many are actually used as channels. |
| 58 |
|
|
static constexpr unsigned int MaxChannels = 32; |
| 59 |
|
|
|
| 60 |
|
|
Festo(pdserv *, |
| 61 |
|
|
pdtask *, |
| 62 |
|
|
const std::string &, |
| 63 |
|
|
Master *, |
| 64 |
|
|
uint16_t, |
| 65 |
|
|
uint16_t, |
| 66 |
|
|
Domain *); |
| 67 |
|
|
|
| 68 |
|
|
/** Resizes internal storage and registers pdserv signals for |
| 69 |
|
|
* exactly this many channels. Throws std::out_of_range if |
| 70 |
|
|
* count exceeds MaxChannels, or std::logic_error if called |
| 71 |
|
|
* more than once -- pdserv does not support registering the |
| 72 |
|
|
* same signal twice, so this is not idempotent. Call exactly |
| 73 |
|
|
* once, before the master is activated. */ |
| 74 |
|
|
void setChannelCount(unsigned int count); |
| 75 |
|
|
|
| 76 |
|
|
void setOutput(unsigned int, bool); |
| 77 |
|
|
bool getOutput(unsigned int) const; |
| 78 |
|
|
|
| 79 |
|
|
void updateOutputs(); |
| 80 |
|
|
|
| 81 |
|
|
unsigned int numChannels() const; |
| 82 |
|
|
|
| 83 |
|
|
private: |
| 84 |
|
|
pdserv *const serv; |
| 85 |
|
|
pdtask *const task; |
| 86 |
|
|
const std::string prefix; |
| 87 |
|
|
|
| 88 |
|
|
ec_slave_config_t *sc; |
| 89 |
|
|
Domain *const domainOut; |
| 90 |
|
|
|
| 91 |
|
|
bool channelCountSet; |
| 92 |
|
|
int offOut; |
| 93 |
|
|
std::vector<uint8_t> input; // value originating from setOutput() |
| 94 |
|
|
std::vector<uint8_t> prevInput; |
| 95 |
|
|
std::vector<unsigned int> toggle; |
| 96 |
|
|
std::vector<unsigned int> prevToggle; |
| 97 |
|
|
std::vector<uint8_t> autoValue; // toggled input value |
| 98 |
|
|
std::vector<uint8_t> enableForcing; |
| 99 |
|
|
std::vector<uint8_t> forcedValue; |
| 100 |
|
|
std::vector<uint8_t> output; // value sent to hardware |
| 101 |
|
|
}; |
| 102 |
|
|
|
| 103 |
|
|
} // namespace EcApp |
| 104 |
|
|
|
| 105 |
|
|
#endif // ECAPP_FESTO_H |
| 106 |
|
|
|
| 107 |
|
|
/****************************************************************************/ |
| 108 |
|
|
|