-
Notifications
You must be signed in to change notification settings - Fork 12
3.1 Slave Description
The slave descriptions represents all variables and capabilities of the slave. There are two possible ways to define a slave description. First by defining it in code. Second by defining it in XML and reads the slave description object from it.
Every element in the slave description can be created by calling a make_ElementName() function. Mandatory attribute has to be passed to this function. Optional attributes will be set to its default values according to the dcpx schema files.
SlaveDescription_t slaveDescription = make_SlaveDescription(
1, 0, "dcpslave", "b5279485-720d-4542-9f29-bee4d9a75ef9");
If a element is optional in the schema definition it will be used as a std::shared_ptr object. In this case the make function has a _ptr suffix.
slaveDescription.TransportProtocols.UDP_IPv4 = make_UDP_ptr();
If a attribute is optional in the dcpx schema files and has no default value it will be used as a std::shared_ptr. In this case the default value is the nullptr object.
std::shared_ptr<Output_t> output_y = make_Output_ptr<float64_t>();
output_y->Float64->start = std::make_shared<std::vector<float64_t>>();
output_y->Float64->start.push_back(3.1);
slaveDescription.Variables.push_back(make_Variable_output("y", y_vr, caus_y));
A std::shared_ptr of a slave description can be retrieved by calling readSlaveDescription. If the file passed to the function is a invalid an exception is raised.
#include <dcp/xml/DcpSlaveDescriptionReader.hpp>
[...]
std::shared_ptr<SlaveDescription_t> slaveDescription =
readSlaveDescription("Example-Slave-Description.xml");
if(slaveDescription != nullptr){
// Slave description is valid
}
To use this function in the CMakeList.txt the binaries has to be linked against DCPLib::Xml. In addition also the Xerxes-C library has to be found on the system.
[...]
find_package(DCPLib REQUIRED)
find_package(Threads REQUIRED)
find_package(XercesC REQUIRED)
[...]
target_link_libraries(dcpmaster DCPLib::Ethernet DCPLib::Master DCPLib::Xml)
[...]
A slave description can be written to file by using the writeDcpSlaveDescription function. To use this function the DCPLib::Xml package is not needed. It can be used without any XML processor like Xerces-C.
bool status = writeDcpSlaveDescription(slaveDescription, "Test.xml");
if(status){
// Slave description successfully written to file
}
A std::shared_ptr of a slave description can be retrieved by calling getSlaveDescriptionFromDcpFile. If the file passed to the function is a invalid an exception is raised.
#include <dcp/zip/DcpSlaveReader.hpp>
[...]
std::shared_ptr<SlaveDescription_t> slaveDescription =
getSlaveDescriptionFromDcpFile(1 /* major version */, 0 /* minor version */, "Example-Slave.zip");
To use this function in the CMakeList.txt the binaries has to be linked against DCPLib::Xml. In addition also the Xerxes-C library has to be found on the system.
[...]
find_package(DCPLib REQUIRED)
find_package(Threads REQUIRED)
find_package(XercesC REQUIRED)
find_package(Zip REQUIRED)
[...]
target_link_libraries(dcpmaster DCPLib::Ethernet DCPLib::Master DCPLib::Zip)
[...]
A slave description can be written to file by using the writeDcpSlaveFile function.
#include <dcp/zip/DcpSlaveWriter.hpp>
writeDcpSlaveFile(slaveDescription, "Test.zip");