add multi-master support to fakelib.

This commit is contained in:
Bjarne von Horn 2024-07-19 11:51:17 +02:00
parent b5c7527990
commit 45e8b098d7
3 changed files with 7 additions and 5 deletions

View File

@ -74,7 +74,7 @@ mkdir -p $FAKE_EC_HOMEDIR
Now it's time to simply launch your application.
You will notice that the PDO configuration will be dumped at stderr.
The path displayed is the path of the RtIPC variable in the following format:
`$FAKE_EC_PREFIX/$DOMAIN_ID/$ALIAS$POSITION/$PDO`.
`$FAKE_EC_PREFIX/$MASTER_ID/$DOMAIN_ID/$ALIAS$POSITION/$PDO`.
## How to emulate EtherCAT slaves

View File

@ -118,7 +118,7 @@ int ec_domain::activate(int domain_id)
slaves.insert(pdo.slave_address.getCombined());
void *rt_pdo = nullptr;
char buf[512];
const auto fmt = snprintf(buf, sizeof(buf), "%s/%d/%08X/%04X", prefix, domain_id, pdo.slave_address.getCombined(), pdo.pdo_index);
const auto fmt = snprintf(buf, sizeof(buf), "%s/%d/%d/%08X/%04X", prefix, master->getId(), domain_id, pdo.slave_address.getCombined(), pdo.pdo_index);
if (fmt < 0 || fmt >= (int)sizeof(buf))
{
return -ENOBUFS;
@ -384,7 +384,7 @@ ec_master_t *ecrt_request_master(
unsigned int master_index /**< Index of the master to request. */
)
{
return new ec_master();
return new ec_master(master_index);
}
static const char *getName()
@ -429,7 +429,7 @@ static std::vector<size_t> getPermutationVector(size_t count)
return ans;
}
ec_master::ec_master() : rt_ipc_dir(getRtIpcDir()), rt_ipc_name(getName()), rt_ipc(rtipc_create(rt_ipc_name.c_str(), rt_ipc_dir.c_str()))
ec_master::ec_master(int id) : rt_ipc_dir(getRtIpcDir()), rt_ipc_name(getName()), rt_ipc(rtipc_create(rt_ipc_name.c_str(), rt_ipc_dir.c_str())), id_(id)
{
}

View File

@ -208,14 +208,16 @@ private:
std::list<ec_domain> domains;
std::map<ec_address, ec_slave_config> slaves;
std::unique_ptr<struct rtipc, RtIpcDeleter> rt_ipc;
int id_;
public:
ec_master();
explicit ec_master(int id);
int activate();
ec_domain *createDomain();
int getNoSlaves() const { return slaves.size(); }
int getId() const { return id_; }
ec_slave_config_t *slave_config(
uint16_t alias, /**< Slave alias. */