Merge branch '187-fake_lib-ecrt_master_deactivate-is-missing-for-testing-purposes' into 'stable-1.6'
Resolve "fake_lib: ecrt_master_deactivate() is missing for testing purposes" Closes #187 See merge request etherlab.org/ethercat!177
This commit is contained in:
commit
6489901521
|
|
@ -0,0 +1,93 @@
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: AlwaysBreak
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignConsecutiveMacros: false
|
||||||
|
AlignEscapedNewlines: DontAlign
|
||||||
|
AlignOperands: false
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: InlineOnly
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
AlwaysBreakTemplateDeclarations: No
|
||||||
|
BinPackArguments: false
|
||||||
|
BinPackParameters: false
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterStruct: true
|
||||||
|
AfterUnion: true
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: true
|
||||||
|
BeforeElse: true
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: false
|
||||||
|
SplitEmptyNamespace: false
|
||||||
|
BreakBeforeBinaryOperators: NonAssignment
|
||||||
|
BreakBeforeBraces: Custom # Same as 'BraceWrapping'
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: AfterColon
|
||||||
|
BreakInheritanceList: AfterColon
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 78
|
||||||
|
CompactNamespaces: true
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
IncludeBlocks: Preserve
|
||||||
|
IndentAccessModifiers: true
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 4
|
||||||
|
InsertBraces: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
MaxEmptyLinesToKeep: 2
|
||||||
|
NamespaceIndentation: None
|
||||||
|
PackConstructorInitializers: Never
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: false
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: true
|
||||||
|
SpaceBeforeCtorInitializerColon: false
|
||||||
|
SpaceBeforeInheritanceColon: false
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Auto
|
||||||
|
TabWidth: 2
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -35,194 +35,209 @@
|
||||||
|
|
||||||
struct Offset
|
struct Offset
|
||||||
{
|
{
|
||||||
int bytes;
|
int bytes;
|
||||||
int bits;
|
int bits;
|
||||||
|
|
||||||
constexpr Offset(int bytes,
|
constexpr Offset(int bytes, int bits):
|
||||||
int bits) : bytes(bytes), bits(bits) {}
|
bytes(bytes),
|
||||||
|
bits(bits)
|
||||||
|
{}
|
||||||
|
|
||||||
constexpr bool operator!=(const Offset &other) const noexcept
|
constexpr bool operator!=(const Offset &other) const noexcept
|
||||||
{
|
{
|
||||||
return bytes != other.bytes || bits != other.bits;
|
return bytes != other.bytes || bits != other.bits;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Offset NotFound(-1, -1);
|
constexpr Offset NotFound(-1, -1);
|
||||||
|
|
||||||
struct pdo
|
struct pdo
|
||||||
{
|
{
|
||||||
std::vector<ec_pdo_entry_info_t> entries;
|
std::vector<ec_pdo_entry_info_t> entries;
|
||||||
|
|
||||||
size_t sizeInBytes() const;
|
size_t sizeInBytes() const;
|
||||||
|
|
||||||
Offset findEntry(uint16_t idx, uint8_t subindex) const;
|
Offset findEntry(uint16_t idx, uint8_t subindex) const;
|
||||||
|
Offset findEntryByPos(unsigned int) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct syncManager
|
struct syncManager
|
||||||
{
|
{
|
||||||
ec_direction_t dir;
|
ec_direction_t dir;
|
||||||
std::map<uint16_t /* index */, pdo> pdos;
|
std::map<uint16_t /* index */, pdo> pdos;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ec_address
|
class ec_address
|
||||||
{
|
{
|
||||||
uint32_t value;
|
private:
|
||||||
|
uint32_t value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ec_address(uint16_t alias, /**< Slave alias. */
|
ec_address(
|
||||||
uint16_t position /**< Slave position. */)
|
uint16_t alias, /**< Slave alias. */
|
||||||
: value(static_cast<uint32_t>(alias) << 16 | position)
|
uint16_t position /**< Slave position. */):
|
||||||
{
|
value(static_cast<uint32_t>(alias) << 16 | position)
|
||||||
}
|
{}
|
||||||
|
|
||||||
uint16_t getAlias() const { return value >> 16; }
|
uint16_t getAlias() const { return value >> 16; }
|
||||||
uint16_t getPosition() const { return value & 0xFFFF; }
|
uint16_t getPosition() const { return value & 0xFFFF; }
|
||||||
uint32_t getCombined() const { return value; }
|
uint32_t getCombined() const { return value; }
|
||||||
|
|
||||||
bool operator<(const ec_address &other) const noexcept
|
bool operator<(const ec_address &other) const noexcept
|
||||||
{
|
{
|
||||||
return value < other.value;
|
return value < other.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const ec_address &other) const noexcept
|
bool operator==(const ec_address &other) const noexcept
|
||||||
{
|
{
|
||||||
return value == other.value;
|
return value == other.value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class sdo_address
|
class sdo_address
|
||||||
{
|
{
|
||||||
uint32_t value;
|
private:
|
||||||
|
uint32_t value;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
sdo_address(uint16_t index, /**< Slave alias. */
|
sdo_address(
|
||||||
uint8_t subindex /**< Slave position. */)
|
uint16_t index, /**< Slave alias. */
|
||||||
: value(static_cast<uint32_t>(index) << 8 | subindex)
|
uint8_t subindex /**< Slave position. */):
|
||||||
{
|
value(static_cast<uint32_t>(index) << 8 | subindex)
|
||||||
}
|
{}
|
||||||
|
|
||||||
uint16_t getIndex() const { return value >> 8; }
|
uint16_t getIndex() const { return value >> 8; }
|
||||||
uint8_t getSubIndex() const { return value & 0xFF; }
|
uint8_t getSubIndex() const { return value & 0xFF; }
|
||||||
uint32_t getCombined() const { return value; }
|
uint32_t getCombined() const { return value; }
|
||||||
|
|
||||||
bool operator<(const sdo_address &other) const noexcept
|
bool operator<(const sdo_address &other) const noexcept
|
||||||
{
|
{
|
||||||
return value < other.value;
|
return value < other.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const sdo_address &other) const noexcept
|
bool operator==(const sdo_address &other) const noexcept
|
||||||
{
|
{
|
||||||
return value == other.value;
|
return value == other.value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ec_slave_config
|
struct ec_slave_config
|
||||||
{
|
{
|
||||||
ec_address address;
|
ec_address address;
|
||||||
uint32_t vendor_id; /**< Expected vendor ID. */
|
uint32_t vendor_id; /**< Expected vendor ID. */
|
||||||
uint32_t product_code; /**< Expected product code. */
|
uint32_t product_code; /**< Expected product code. */
|
||||||
std::map<unsigned int, syncManager> sync_managers;
|
std::map<unsigned int, syncManager> sync_managers;
|
||||||
std::map<sdo_address, std::basic_string<uint8_t>> sdos;
|
std::map<sdo_address, std::basic_string<uint8_t>> sdos;
|
||||||
|
|
||||||
ec_slave_config(
|
ec_slave_config(
|
||||||
ec_address address,
|
ec_address address,
|
||||||
uint32_t vendor_id, /**< Expected vendor ID. */
|
uint32_t vendor_id, /**< Expected vendor ID. */
|
||||||
uint32_t product_code /**< Expected product code. */)
|
uint32_t product_code /**< Expected product code. */):
|
||||||
: address(address), vendor_id(vendor_id), product_code(product_code)
|
address(address),
|
||||||
{
|
vendor_id(vendor_id),
|
||||||
}
|
product_code(product_code)
|
||||||
|
{}
|
||||||
|
|
||||||
void dumpJson(std::ostream &out, int indent) const;
|
void dumpJson(std::ostream &out, int indent) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ec_domain
|
struct ec_domain
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
private:
|
struct PdoMap
|
||||||
struct PdoMap
|
|
||||||
{
|
|
||||||
size_t offset;
|
|
||||||
size_t size_bytes;
|
|
||||||
ec_address slave_address;
|
|
||||||
unsigned int syncManager;
|
|
||||||
uint16_t pdo_index;
|
|
||||||
ec_direction_t dir;
|
|
||||||
|
|
||||||
PdoMap(
|
|
||||||
size_t offset,
|
|
||||||
size_t size_bytes,
|
|
||||||
ec_address slave_address,
|
|
||||||
unsigned int syncManager,
|
|
||||||
uint16_t pdo_index,
|
|
||||||
ec_direction_t dir)
|
|
||||||
: offset(offset), size_bytes(size_bytes), slave_address(slave_address), syncManager(syncManager), pdo_index(pdo_index), dir(dir)
|
|
||||||
{
|
{
|
||||||
|
size_t offset;
|
||||||
|
size_t size_bytes;
|
||||||
|
ec_address slave_address;
|
||||||
|
unsigned int syncManager;
|
||||||
|
uint16_t pdo_index;
|
||||||
|
ec_direction_t dir;
|
||||||
|
|
||||||
|
PdoMap(size_t offset,
|
||||||
|
size_t size_bytes,
|
||||||
|
ec_address slave_address,
|
||||||
|
unsigned int syncManager,
|
||||||
|
uint16_t pdo_index,
|
||||||
|
ec_direction_t dir):
|
||||||
|
offset(offset),
|
||||||
|
size_bytes(size_bytes),
|
||||||
|
slave_address(slave_address),
|
||||||
|
syncManager(syncManager),
|
||||||
|
pdo_index(pdo_index),
|
||||||
|
dir(dir)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
std::vector<unsigned char> connected;
|
||||||
|
std::vector<PdoMap> mapped_pdos;
|
||||||
|
rtipc_group *rt_group;
|
||||||
|
const char *prefix;
|
||||||
|
ec_master_t *master;
|
||||||
|
bool activated_ = false;
|
||||||
|
size_t numSlaves = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ec_domain(
|
||||||
|
struct rtipc *rtipc,
|
||||||
|
const char *prefix,
|
||||||
|
ec_master_t *master);
|
||||||
|
|
||||||
|
uint8_t *getData() const
|
||||||
|
{
|
||||||
|
if (!activated_) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return const_cast<uint8_t *>(data.data());
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<uint8_t> data;
|
size_t getSize() const { return data.size(); }
|
||||||
std::vector<unsigned char> connected;
|
|
||||||
std::vector<PdoMap> mapped_pdos;
|
|
||||||
rtipc_group *rt_group;
|
|
||||||
const char *prefix;
|
|
||||||
ec_master_t *master;
|
|
||||||
bool activated_ = false;
|
|
||||||
size_t numSlaves = 0;
|
|
||||||
|
|
||||||
public:
|
int activate();
|
||||||
explicit ec_domain(struct rtipc *rtipc, const char *prefix, ec_master_t *master);
|
int process();
|
||||||
|
int queue();
|
||||||
|
|
||||||
uint8_t *getData() const
|
size_t getNumSlaves() const { return numSlaves; }
|
||||||
{
|
|
||||||
if (!activated_)
|
|
||||||
return nullptr;
|
|
||||||
return const_cast<uint8_t *>(data.data());
|
|
||||||
}
|
|
||||||
|
|
||||||
int activate();
|
ssize_t
|
||||||
int process();
|
map(ec_slave_config const &config,
|
||||||
int queue();
|
unsigned int syncManager,
|
||||||
|
uint16_t pdo_index);
|
||||||
|
|
||||||
size_t getNumSlaves() const { return numSlaves; }
|
ec_master_t *getMaster() const { return master; }
|
||||||
|
|
||||||
ssize_t map(ec_slave_config const &config, unsigned int syncManager,
|
|
||||||
uint16_t pdo_index);
|
|
||||||
|
|
||||||
ec_master_t *getMaster() const { return master; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ec_master
|
struct ec_master
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct RtIpcDeleter
|
struct RtIpcDeleter
|
||||||
{
|
|
||||||
void operator()(struct rtipc *r) const
|
|
||||||
{
|
{
|
||||||
rtipc_exit(r);
|
void operator()(struct rtipc *r) const { rtipc_exit(r); }
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
std::string rt_ipc_dir;
|
std::string rt_ipc_dir;
|
||||||
std::string rt_ipc_name;
|
std::string rt_ipc_name;
|
||||||
std::list<ec_domain> domains;
|
std::list<ec_domain> domains;
|
||||||
std::map<ec_address, ec_slave_config> slaves;
|
std::map<ec_address, ec_slave_config> slaves;
|
||||||
std::unique_ptr<struct rtipc, RtIpcDeleter> rt_ipc;
|
std::unique_ptr<struct rtipc, RtIpcDeleter> rt_ipc;
|
||||||
int id_;
|
int id_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ec_master(int id);
|
explicit ec_master(int id);
|
||||||
|
|
||||||
int activate();
|
int activate();
|
||||||
ec_domain *createDomain();
|
int deactivate();
|
||||||
|
|
||||||
int getNoSlaves() const { return slaves.size(); }
|
ec_domain *createDomain();
|
||||||
int getId() const { return id_; }
|
|
||||||
|
|
||||||
ec_slave_config_t *slave_config(
|
int getNoSlaves() const { return slaves.size(); }
|
||||||
uint16_t alias, /**< Slave alias. */
|
int getId() const { return id_; }
|
||||||
uint16_t position, /**< Slave position. */
|
|
||||||
uint32_t vendor_id, /**< Expected vendor ID. */
|
ec_slave_config_t *slave_config(
|
||||||
uint32_t product_code /**< Expected product code. */
|
uint16_t alias, /**< Slave alias. */
|
||||||
);
|
uint16_t position, /**< Slave position. */
|
||||||
|
uint32_t vendor_id, /**< Expected vendor ID. */
|
||||||
|
uint32_t product_code /**< Expected product code. */
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue