37 #include "receive_pdo_mapping.h"
38 #include "transmit_pdo_mapping.h"
39 #include "access_method.h"
40 #include "eds_library.h"
41 #include "eds_reader.h"
44 #include <unordered_map>
88 using Operation = std::function<Value(Device&,const Value&)>;
151 bool has_entry(
const std::string& entry_name);
157 bool has_entry(
const uint16_t index,
const uint8_t subindex = 0);
169 Type
get_entry_type(
const uint16_t index,
const uint8_t subindex = 0);
179 const Value&
get_entry(
const std::string& entry_name,
const ReadAccessMethod access_method = ReadAccessMethod::use_default);
190 const Value&
get_entry(
const uint16_t index,
const uint8_t subindex = 0,
const ReadAccessMethod access_method = ReadAccessMethod::use_default);
201 void set_entry(
const std::string& entry_name,
const Value& value,
const WriteAccessMethod access_method = WriteAccessMethod::use_default);
213 void set_entry(
const uint16_t index,
const uint8_t subindex,
const Value& value,
const WriteAccessMethod access_method = WriteAccessMethod::use_default);
222 void add_entry(
const uint16_t index,
const uint8_t subindex,
const std::string& name,
const Type type,
const AccessType access_type);
235 Value execute(
const std::string& operation_name,
const Value& argument = m_dummy_value);
267 void add_transmit_pdo_mapping(uint16_t cob_id,
const std::vector<Mapping>& mappings, TransmissionType transmission_type=TransmissionType::ON_CHANGE, std::chrono::milliseconds repeat_time=std::chrono::milliseconds(0));
292 Value get_entry_via_sdo(uint32_t index, uint8_t subindex, Type type);
302 void set_entry_via_sdo(uint32_t index, uint8_t subindex,
const Value& value);
307 void load_cia_dictionary();
309 void pdo_received_callback(
const ReceivePDOMapping& mapping, std::vector<uint8_t> data);
311 static const bool debug =
false;
316 std::unordered_map<Address, Entry> m_dictionary;
317 std::unordered_map<std::string, Address> m_name_to_address;
319 std::unordered_map<std::string, Operation> m_operations;
320 std::unordered_map<std::string, Value> m_constants;
321 std::forward_list<ReceivePDOMapping> m_receive_pdo_mappings;
322 std::mutex m_receive_pdo_mappings_mutex;
323 std::forward_list<TransmitPDOMapping> m_transmit_pdo_mappings;
324 std::mutex m_transmit_pdo_mappings_mutex;
325 static const Value m_dummy_value;
void print_dictionary() const
Prints the dictionary together with currently cached values to command line.
void add_transmit_pdo_mapping(uint16_t cob_id, const std::vector< Mapping > &mappings, TransmissionType transmission_type=TransmissionType::ON_CHANGE, std::chrono::milliseconds repeat_time=std::chrono::milliseconds(0))
Adds a transmit PDO mapping. This means values from the dictionary cache are sent to the device...
const Value & get_entry(const std::string &entry_name, const ReadAccessMethod access_method=ReadAccessMethod::use_default)
Gets the value of a dictionary entry by name internally. If there is no cached value or the entry is ...
void add_operation(const std::string &coperation_name, const Operation &operation)
Adds a convenience operation.
void add_entry(const uint16_t index, const uint8_t subindex, const std::string &name, const Type type, const AccessType access_type)
Adds an entry to the dictionary. You have to take care that exactly this entry exists on the device f...
void start()
Starts the node via NMT protocol and loads mandatory entries, operations, and constants.
void add_receive_pdo_mapping(uint16_t cob_id, const std::string &entry_name, uint8_t offset)
Adds a receive PDO mapping. This means values sent by the device via PDO are saved into the dictionar...
uint16_t get_device_profile_number()
Returns the CiA profile number.
void add_constant(const std::string &constant_name, const Value &constant)
Adds a constant.
This class implements the Core of KaCanOpen It communicates with the CAN driver, sends CAN messages a...
uint8_t get_node_id() const
Returns the node ID of the device.
Value execute(const std::string &operation_name, const Value &argument=m_dummy_value)
Executes a convenience operation. It must exist due to a previous load_operations() or add_operation(...
std::string load_dictionary_from_library()
Tries to load the most specific EDS file available in KaCanOpen's internal EDS library. This is either device specific, CiA profile specific, or mandatory CiA 301.
This struct represents a mapping from one receive PDO to one dictionary entry. There may be multiple ...
This class represents a CanOpen slave device in the network.
This class provides access to KaCanOpen's EDS library. It manages device specific as well as generic ...
bool load_operations()
Loads convenience operations associated with the device profile.
void set_entry(const std::string &entry_name, const Value &value, const WriteAccessMethod access_method=WriteAccessMethod::use_default)
Sets the value of a dictionary entry by name internally. If the entry is configured to send an SDO on...
const Value & get_constant(const std::string &constant_name) const
Returns a constant. It must exist due to a previous load_constants() or add_constant() call...
Type get_entry_type(const std::string &entry_name)
Returns the type of a dictionary entry identified by name as it is defined in the local dictionary...
void read_complete_dictionary()
Fetches all dictionary entries from the device. Afterwards, all values exist in cache and can for exa...
void load_dictionary_from_eds(const std::string &path)
Loads the dictionary from a custom EDS file.
bool has_entry(const std::string &entry_name)
Returns true if the entry is contained in the device dictionary.
Device(Core &core, uint8_t node_id)
Constructor.
std::function< Value(Device &, const Value &)> Operation
Type of a operation. See Profiles::Operation in profiles.h.
bool load_constants()
Loads constants associated with the device profile.
This class contains a value to be stored in the object dictionary. The value can have one of the type...