1. 新建io控制识别程序。

main
baocm 9 months ago
parent f77169189b
commit 51e99c4e22

@ -41,6 +41,19 @@ target_link_libraries(Demo fastcdr fastdds
System_lib System_lib
) )
# IoCtrl Application.
add_executable(IoCtrl
ioctrl/main.cxx
ioctrl/Publisher.cxx
ioctrl/Subscriber.cxx
ioctrl/MsgHandler.cxx
common/CanMsgHandler.cxx
)
target_include_directories(IoCtrl PRIVATE ioctrl)
target_link_libraries(IoCtrl fastcdr fastdds
System_lib
)
# HttpServer Application. # HttpServer Application.
add_executable(HttpServer add_executable(HttpServer
httpserver/main.cxx httpserver/main.cxx

@ -0,0 +1,145 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <unistd.h>
#include <algorithm>
#include <fcntl.h>
#include <errno.h>
#include <iostream>
#include <iomanip>
#include <net/if.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include "CanMsgHandler.hpp"
CanMsgHandler::CanMsgHandler() {}
CanMsgHandler::~CanMsgHandler()
{
ClosePort();
}
// 打开CAN
bool CanMsgHandler::OpenPort(const std::string& port, const std::string& baudrate)
{
ClosePort();
// 创建SocketCAN套接字
fd = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (fd < 0) {
perror("Failed to create CAN socket");
return false;
}
// 获取接口索引
struct ifreq ifr;
strncpy(ifr.ifr_name, port.c_str(), IFNAMSIZ - 1);
ifr.ifr_name[IFNAMSIZ - 1] = '\0';
if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
perror("Failed to get interface index");
close(fd);
fd = -1;
return false;
}
// 绑定套接字到CAN接口
struct sockaddr_can addr;
memset(&addr, 0, sizeof(addr));
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Failed to bind CAN socket");
close(fd);
fd = -1;
return false;
}
// // 设置非阻塞模式
// int flags = fcntl(fd, F_GETFL, 0);
// fcntl(fd, F_SETFL, flags | O_NONBLOCK);
// 设置CAN波特率
// std::string cmd = "ip link set " + port + " down";
// std::cout << cmd << std::endl;
// if (system(cmd.c_str()) != 0) {
// return false;
// }
// cmd = "ip link set " + port + " type can bitrate " + baudrate + " dbitrate 1000000 fd on";
// std::cout << cmd << std::endl;
// if (system(cmd.c_str()) != 0) {
// return false;
// }
// cmd = "ip link set " + port + " up";
// std::cout << cmd << std::endl;
// if (system(cmd.c_str()) != 0) {
// return false;
// }
return true;
}
// 发送数据
int CanMsgHandler::SendDeviceMsg(std::vector<uint8_t> &data)
{
struct can_frame frame;
frame.can_id = data[0];
frame.can_id = frame.can_id << 12;
frame.can_id += data[1];
frame.can_id = frame.can_id << 8;
frame.can_id += data[2];
frame.can_id |= CAN_EFF_FLAG;
frame.can_dlc = data.size() - 3;
for (int i = 0; i < frame.can_dlc; i++)
{
frame.data[i] = data[i + 3];
}
for (int num : data) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< num << " ";
}
std::cout << std::endl;
int bytesWritten = SendMsg(&frame, sizeof(struct can_frame));
if (bytesWritten < 0) {
perror("发送数据失败");
}
return bytesWritten;
}
int CanMsgHandler::RecvDeviceMsg(std::vector<uint8_t>& data, int timeoutMs)
{
int bytesRead;
struct can_frame frame;
bytesRead = RecvMsg(&frame, sizeof(struct can_frame), timeoutMs);
if (bytesRead > 0)
{
data.insert(data.end(), (frame.can_id >> 20) & 0xFF);
data.insert(data.end(), (frame.can_id >> 8) & 0xFF);
data.insert(data.end(), frame.can_id & 0xFF);
data.insert(data.end(), frame.data, frame.data + frame.can_dlc);
}
return bytesRead;
}
uint32_t CanMsgHandler::GetCanId(uint32_t DeviceID, uint32_t CommandID, uint32_t BlockID)
{
uint32_t Canid = DeviceID << 20 + CommandID << 8 + BlockID;
return Canid;
}

@ -0,0 +1,27 @@
#ifndef _CANMSGHANDLER_HPP_
#define _CANMSGHANDLER_HPP_
#include <string>
#include <cstdint>
#include "MsgHandler.hpp"
class CanMsgHandler : public MsgHandler{
public:
CanMsgHandler();
~CanMsgHandler();
// 打开CAN
bool OpenPort(const std::string& port, const std::string& baudrate);
// 发送消息
int SendDeviceMsg(std::vector<uint8_t> &data);
// 接收消息
int RecvDeviceMsg(std::vector<uint8_t>& data, int timeoutMs);
private:
uint32_t GetCanId(uint32_t DeviceID, uint32_t CommandID, uint32_t BlockID);
};
#endif // _CANMSGHANDLER_HPP_

@ -0,0 +1,272 @@
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <thread>
#include <unistd.h>
#include <sys/ioctl.h>
#include "MsgHandler.hpp"
MsgHandler::MsgHandler() : fd(-1) {}
void MsgHandler::HandleDdsMsg(const std::map<std::string, std::string>& msg)
{
auto cmd = msg.find("cmd");
if (cmd != msg.end())
{
if (cmd->second == "config")
{
auto port = msg.find("port");
auto baudrate = msg.find("baudrate");
auto device = msg.find("device");
if ((port != msg.end()) && (baudrate != msg.end()) && (device != msg.end()))
{
OpenPort(port->second, baudrate->second);
this->device = device->second;
}
}
else if (cmd->second == "open")
{
if (this->device == "5serial")
{
std::vector<uint8_t> data;
data.insert(data.end(), {this->device_id, 0x50, 1, 1});
SendDeviceMsg(data);
}
}
else if (cmd->second == "write")
{
if (this->device == "5serial")
{
std::vector<uint8_t> data;
data.resize(8, 1);
data.insert(data.begin(), {this->device_id, 0x51, 1});
for (const auto &port : this->iomap.omap)
{
data[port.second.first+2] = port.second.second;
}
for (auto &m : msg)
{
auto port = this->iomap.omap.find(m.first);
if (port != this->iomap.omap.end())
{
if (m.second == "1")
{
port->second.second = 1;
}
else if (m.second == "0")
{
port->second.second = 0;
}
data[port->second.first+2] = port->second.second;
}
}
SendDeviceMsg(data);
}
}
else if (cmd->second == "pluse")
{
if (this->device == "5serial")
{
std::vector<uint8_t> data;
data.resize(8, 1);
data.insert(data.begin(), {this->device_id, 0x51, 1});
for (const auto &port : this->iomap.omap)
{
data[port.second.first+2] = port.second.second;
}
for (auto &m : msg)
{
auto port = this->iomap.omap.find(m.first);
if (port != this->iomap.omap.end())
{
if (m.second == "1")
{
port->second.second = 1;
}
else if (m.second == "0")
{
port->second.second = 0;
}
data[port->second.first+2] = port->second.second;
}
}
SendDeviceMsg(data);
std::this_thread::sleep_for(std::chrono::seconds(1));
for (auto &m : msg)
{
auto port = this->iomap.omap.find(m.first);
if (port != this->iomap.omap.end())
{
if (m.second == "1")
{
port->second.second = 0;
}
else if (m.second == "0")
{
port->second.second = 1;
}
data[port->second.first+2] = port->second.second;
}
}
SendDeviceMsg(data);
}
}
else if (cmd->second == "read")
{
if (this->device == "5serial")
{
std::vector<uint8_t> data;
data.insert(data.end(), {this->device_id, 0x52, 1});
data.insert(data.end(), 1);
SendDeviceMsg(data);
}
}
}
}
int MsgHandler::ParseDeviceMsg(std::vector<uint8_t>& data, IoCtrlRsp& rsp)
{
if (data[0] == this->device_id)
{
switch(data[1])
{
case 0x50:
rsp.msg()["open"] = std::to_string(data[3]);
break;
case 0x51:
rsp.msg()["write"] = std::to_string(data[3]);
break;
case 0x52:
rsp.msg()["read"] = "0";
for (auto &p : this->iomap.imap)
{
// if (p.second.second != data[p.second.first+2])
// {
p.second.second = data[p.second.first+2];
rsp.msg()[p.first] = std::to_string(p.second.second);
// }
}
break;
}
return 1;
}
return 0;
}
int MsgHandler::HandleDeviceMsg(IoCtrlRsp& rsp)
{
std::vector<uint8_t> m_RecvData;
if(RecvDeviceMsg(m_RecvData, 100) > 0)
{
for (int num : m_RecvData)
{
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< num << " ";
}
std::cout << std::endl;
return(ParseDeviceMsg(m_RecvData, rsp));
}
return 0;
}
bool MsgHandler::OpenPort(const std::string& port, const std::string& baudrate)
{
return true;
}
// 发送数据
int MsgHandler::SendMsg(const void *buf, size_t len)
{
if (fd == -1) {
perror("设备未打开");
return -1;
}
int bytesWritten = write(fd, buf, len);
if (bytesWritten < 0) {
perror("发送数据失败");
}
return bytesWritten;
}
int MsgHandler::RecvMsg(void *buf, size_t len, int timeoutMs)
{
if (fd == -1) {
perror("设备未打开");
return -1;
}
// 使用select实现超时
fd_set readfds;
struct timeval tv;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
tv.tv_sec = timeoutMs / 1000;
tv.tv_usec = (timeoutMs % 1000) * 1000;
int ret = select(fd + 1, &readfds, NULL, NULL, &tv);
if (ret == -1) {
perror("select错误");
return -1;
} else if (ret == 0) {
return 0;
}
// 有数据可读
int bytes;
if (len == 0)
{
if (ioctl(fd, FIONREAD, &bytes) < 0)
{
perror("ioctl FIONREAD失败");
return -1;
}
}
else
{
bytes = len;
}
int bytesRead = read(fd, buf, bytes);
if (bytesRead < 0) {
perror("读取数据失败");
return -1;
}
return bytesRead;
}
void MsgHandler::ClosePort()
{
if (fd != -1)
{
close(fd);
fd = -1;
}
}
int MsgHandler::SendDeviceMsg(std::vector<uint8_t>& data)
{
for (int num : data) {
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< num << " ";
}
std::cout << std::endl;
return SendMsg(data.data(), data.size());
}
int MsgHandler::RecvDeviceMsg(std::vector<uint8_t>& data, int timeoutMs)
{
return RecvMsg(data.data(), data.size(), timeoutMs);
}

@ -0,0 +1,45 @@
#ifndef _MSGHANDLER_HPP_
#define _MSGHANDLER_HPP_
#include <queue>
#include <mutex>
#include <vector>
#include <map>
#include "System.hpp"
struct iomap_t
{ //name, (port, value)
std::map<std::string, std::pair<uint8_t, uint8_t>> omap;
std::map<std::string, std::pair<uint8_t, uint8_t>> imap;
};
class MsgHandler
{
public:
int fd;
std::string device;
uint8_t device_id;
iomap_t iomap;
MsgHandler();
~MsgHandler() = default;
void HandleDdsMsg(const std::map<std::string, std::string>& msg);
int HandleDeviceMsg(IoCtrlRsp& rsp);
virtual bool OpenPort(const std::string& port, const std::string& baudrate);
virtual int SendDeviceMsg(std::vector<uint8_t>& data);
virtual int RecvDeviceMsg(std::vector<uint8_t>& data, int timeoutMs);
int SendMsg(const void *buf, size_t len);
int RecvMsg(void *buf, size_t len, int timeoutMs);
bool isOpen() const {
return fd != -1;
}
void ClosePort();
private:
int ParseDeviceMsg(std::vector<uint8_t>& data, IoCtrlRsp& rsp);
};
#endif

@ -0,0 +1,197 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file Publisher.cxx
* This file contains the implementation of the publisher functions.
*
* This file was generated by the tool fastddsgen.
*/
#include "Publisher.hpp"
#include <condition_variable>
#include <csignal>
#include <stdexcept>
#include <thread>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/log/Log.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
#include "SystemPubSubTypes.hpp"
#include "msg.hpp"
#include "MsgHandler.hpp"
using namespace eprosima::fastdds::dds;
PublisherApp::PublisherApp(
const int& domain_id)
: factory_(nullptr)
, participant_(nullptr)
, publisher_(nullptr)
, topic_(nullptr)
, writer_(nullptr)
, type_(new IoCtrlRspPubSubType())
, matched_(0)
, samples_sent_(0)
, stop_(false)
{
//
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("IoCtrl_pub_participant");
pqos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(60, 0);
pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(30, 0);
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("IoCtrlRsp Participant initialization failed");
}
// Register the type
type_.register_type(participant_);
// Create the publisher
PublisherQos pub_qos = PUBLISHER_QOS_DEFAULT;
participant_->get_default_publisher_qos(pub_qos);
publisher_ = participant_->create_publisher(pub_qos, nullptr, StatusMask::none());
if (publisher_ == nullptr)
{
throw std::runtime_error("IoCtrlRsp Publisher initialization failed");
}
// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic("IoCtrlRspTopic", type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
{
throw std::runtime_error("IoCtrlRsp Topic initialization failed");
}
// Create the data writer
DataWriterQos writer_qos = DATAWRITER_QOS_DEFAULT;
publisher_->get_default_datawriter_qos(writer_qos);
writer_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
writer_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
writer_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
writer_ = publisher_->create_datawriter(topic_, writer_qos, this, StatusMask::all());
if (writer_ == nullptr)
{
throw std::runtime_error("IoCtrlRsp DataWriter initialization failed");
}
}
PublisherApp::~PublisherApp()
{
if (nullptr != participant_)
{
// Delete DDS entities contained within the DomainParticipant
participant_->delete_contained_entities();
// Delete DomainParticipant
factory_->delete_participant(participant_);
}
}
void PublisherApp::on_publication_matched(
DataWriter* writer,
const PublicationMatchedStatus& info)
{
if (info.current_count_change == 1)
{
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << writer->get_topic()->get_name() << " Publisher matched." << std::endl;
cv_.notify_one();
}
else if (info.current_count_change == -1)
{
{
std::lock_guard<std::mutex> lock(mutex_);
matched_ = info.current_count;
}
std::cout << writer->get_topic()->get_name() << " Publisher unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for PublicationMatchedStatus current count change" << std::endl;
}
}
void PublisherApp::run(std::shared_ptr<MsgHandler> handler)
{
IoCtrlRsp rsp;
while (!is_stopped())
{
if(handler->isOpen() == true)
{
if(handler->HandleDeviceMsg(rsp))
{
writer_->write(&rsp);
rsp.msg().clear();
}
}
// Wait for period or stop event
std::unique_lock<std::mutex> period_lock(mutex_);
cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [this]()
{
return is_stopped();
});
}
}
bool PublisherApp::publish()
{
bool ret = false;
// Wait for the data endpoints discovery
std::unique_lock<std::mutex> matched_lock(mutex_);
cv_.wait(matched_lock, [&]()
{
// at least one has been discovered
return ((matched_ > 0) || is_stopped());
});
if (!is_stopped())
{
/* Initialize your structure here */
WeighRsp sample_;
ret = (RETCODE_OK == writer_->write(&sample_));
}
return ret;
}
bool PublisherApp::is_stopped()
{
return stop_.load();
}
void PublisherApp::stop()
{
stop_.store(true);
cv_.notify_one();
}

@ -0,0 +1,76 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file PublisherApp.hpp
* This header file contains the declaration of the publisher functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__PUBLISHERAPP_HPP
#define FAST_DDS_GENERATED__PUBLISHERAPP_HPP
#include <condition_variable>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>
#include "MsgHandler.hpp"
class PublisherApp : public eprosima::fastdds::dds::DataWriterListener
{
public:
PublisherApp(
const int& domain_id);
~PublisherApp();
//! Publisher matched method
void on_publication_matched(
eprosima::fastdds::dds::DataWriter* writer,
const eprosima::fastdds::dds::PublicationMatchedStatus& info) override;
//! Run publisher
void run(std::shared_ptr<MsgHandler> handler);
//! Trigger the end of execution
void stop();
private:
//! Return the current state of execution
bool is_stopped();
//! Publish a sample
bool publish();
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
eprosima::fastdds::dds::DomainParticipant* participant_;
eprosima::fastdds::dds::Publisher* publisher_;
eprosima::fastdds::dds::Topic* topic_;
eprosima::fastdds::dds::DataWriter* writer_;
eprosima::fastdds::dds::TypeSupport type_;
std::condition_variable cv_;
int32_t matched_;
std::mutex mutex_;
const uint32_t period_ms_ = 100; // in ms
uint16_t samples_sent_;
std::atomic<bool> stop_;
};
#endif // FAST_DDS_GENERATED__PUBLISHERAPP_HPP

@ -0,0 +1,189 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file Subscriber.cxx
* This file contains the implementation of the subscriber functions.
*
* This file was generated by the tool fastddsgen.
*/
#include "Subscriber.hpp"
#include <condition_variable>
#include <stdexcept>
#include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
#include <fastdds/dds/subscriber/SampleInfo.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include "SystemPubSubTypes.hpp"
#include "msg.hpp"
using namespace eprosima::fastdds::dds;
SubscriberApp::SubscriberApp(
const int& domain_id)
: factory_(nullptr)
, participant_(nullptr)
, subscriber_(nullptr)
, topic_(nullptr)
, reader_(nullptr)
, type_(new IoCtrlReqPubSubType())
, samples_received_(0)
, stop_(false)
{
// Create the participant
DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
pqos.name("IoCtrl_sub_participant");
pqos.wire_protocol().builtin.discovery_config.leaseDuration = Duration_t(60, 0);
pqos.wire_protocol().builtin.discovery_config.leaseDuration_announcementperiod = Duration_t(30, 0);
factory_ = DomainParticipantFactory::get_shared_instance();
participant_ = factory_->create_participant(domain_id, pqos, nullptr, StatusMask::none());
if (participant_ == nullptr)
{
throw std::runtime_error("IoCtrlReq Participant initialization failed");
}
// Register the type
type_.register_type(participant_);
// Create the subscriber
SubscriberQos sub_qos = SUBSCRIBER_QOS_DEFAULT;
participant_->get_default_subscriber_qos(sub_qos);
subscriber_ = participant_->create_subscriber(sub_qos, nullptr, StatusMask::none());
if (subscriber_ == nullptr)
{
throw std::runtime_error("IoCtrlReq Subscriber initialization failed");
}
// Create the topic
TopicQos topic_qos = TOPIC_QOS_DEFAULT;
participant_->get_default_topic_qos(topic_qos);
topic_ = participant_->create_topic("IoCtrlReqTopic", type_.get_type_name(), topic_qos);
if (topic_ == nullptr)
{
throw std::runtime_error("IoCtrlReq Topic initialization failed");
}
// Create the reader
DataReaderQos reader_qos = DATAREADER_QOS_DEFAULT;
subscriber_->get_default_datareader_qos(reader_qos);
reader_qos.reliability().kind = ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
reader_qos.durability().kind = DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
reader_qos.history().kind = HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
reader_ = subscriber_->create_datareader(topic_, reader_qos, this, StatusMask::all());
if (reader_ == nullptr)
{
throw std::runtime_error("IoCtrlReq DataReader initialization failed");
}
}
SubscriberApp::~SubscriberApp()
{
if (nullptr != participant_)
{
// Delete DDS entities contained within the DomainParticipant
participant_->delete_contained_entities();
// Delete DomainParticipant
factory_->delete_participant(participant_);
}
}
void SubscriberApp::on_subscription_matched(
DataReader* reader,
const SubscriptionMatchedStatus& info)
{
if (info.current_count_change == 1)
{
std::cout << reader->get_topicdescription()->get_name() << " Subscriber matched." << std::endl;
}
else if (info.current_count_change == -1)
{
std::cout << reader->get_topicdescription()->get_name() << " Subscriber unmatched." << std::endl;
}
else
{
std::cout << info.current_count_change
<< " is not a valid value for SubscriptionMatchedStatus current count change" << std::endl;
}
}
void SubscriberApp::on_data_available(
DataReader* reader)
{
SampleInfo info;
std::string topic_name = reader->get_topicdescription()->get_name();
std::cout << topic_name << std::endl;
if (topic_name == "IoCtrlReqTopic")
{
IoCtrlReq sample_;
while ((!is_stopped()) && (RETCODE_OK == reader->take_next_sample(&sample_, &info)))
{
if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data)
{
{
std::unique_lock<std::mutex> lock(MsgData::queue_cv_mtx_);
MsgData::IoCtrlReq_queue_.push(std::move(sample_));
lock.unlock();
}
}
}
}
}
void SubscriberApp::run(std::shared_ptr<MsgHandler> handler)
{
while (!is_stopped())
{
std::unique_lock<std::mutex> lock(MsgData::queue_cv_mtx_, std::try_to_lock);
if (lock.owns_lock())
{
if(!MsgData::IoCtrlReq_queue_.empty())
{
IoCtrlReq req = std::move(MsgData::IoCtrlReq_queue_.front());
MsgData::IoCtrlReq_queue_.pop();
lock.unlock();
handler->HandleDdsMsg(req.msg());
}
else
{
lock.unlock();
}
}
{
std::unique_lock<std::mutex> period_lock(terminate_cv_mtx_);
terminate_cv_.wait_for(period_lock, std::chrono::milliseconds(period_ms_), [this](){return is_stopped();});
}
}
}
bool SubscriberApp::is_stopped()
{
return stop_.load();
}
void SubscriberApp::stop()
{
stop_.store(true);
terminate_cv_.notify_all();
}

@ -0,0 +1,77 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file SubscriberApp.hpp
* This header file contains the declaration of the subscriber functions.
*
* This file was generated by the tool fastddsgen.
*/
#ifndef FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP
#define FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP
#include <condition_variable>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
#include <fastdds/dds/topic/TypeSupport.hpp>
#include "System.hpp"
#include "MsgHandler.hpp"
class SubscriberApp : public eprosima::fastdds::dds::DataReaderListener
{
public:
SubscriberApp(
const int& domain_id);
virtual ~SubscriberApp();
//! Subscription callback
void on_data_available(
eprosima::fastdds::dds::DataReader* reader) override;
//! Subscriber matched method
void on_subscription_matched(
eprosima::fastdds::dds::DataReader* reader,
const eprosima::fastdds::dds::SubscriptionMatchedStatus& info) override;
//! Run subscriber
void run(std::shared_ptr<MsgHandler> handler);
//! Trigger the end of execution
void stop();
private:
//! Return the current state of execution
bool is_stopped();
std::shared_ptr<eprosima::fastdds::dds::DomainParticipantFactory> factory_;
eprosima::fastdds::dds::DomainParticipant* participant_;
eprosima::fastdds::dds::Subscriber* subscriber_;
eprosima::fastdds::dds::Topic* topic_;
eprosima::fastdds::dds::DataReader* reader_;
eprosima::fastdds::dds::TypeSupport type_;
uint16_t samples_received_;
std::atomic<bool> stop_;
uint32_t period_ms_ = 100; // in ms
mutable std::mutex terminate_cv_mtx_;
std::condition_variable terminate_cv_;
};
#endif // FAST_DDS_GENERATED__SUBSCRIBERAPP_HPP

@ -0,0 +1,196 @@
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*!
* @file main.cxx
* This file acts as a main entry point to the application.
*
* This file was generated by the tool fastddsgen.
*/
#include <csignal>
#include <cstring>
#include <functional>
#include <iostream>
#include <stdexcept>
#include <thread>
#include <fstream>
#include <filesystem>
#include <limits.h>
#include <fastdds/dds/log/Log.hpp>
#include "Subscriber.hpp"
#include "Publisher.hpp"
#include "CanMsgHandler.hpp"
#include "msg.hpp"
#include "json.hpp"
#define VERSION "v1.0"
using eprosima::fastdds::dds::Log;
using json = nlohmann::json;
std::function<void(int)> stop_handler;
void signal_handler(
int signum)
{
stop_handler(signum);
}
std::string parse_signal(
const int& signum)
{
switch (signum)
{
case SIGINT:
return "SIGINT";
case SIGTERM:
return "SIGTERM";
#ifndef _WIN32
case SIGQUIT:
return "SIGQUIT";
case SIGHUP:
return "SIGHUP";
#endif // _WIN32
default:
return "UNKNOWN SIGNAL";
}
}
std::queue<IoCtrlReq> MsgData::IoCtrlReq_queue_;
std::mutex MsgData::queue_cv_mtx_;
std::filesystem::path getExeDir()
{
char buf[PATH_MAX] = {0};
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf)-1);
return std::filesystem::path(std::string(buf, len)).parent_path();
}
int main(int argc, char** argv)
{
auto ret = EXIT_SUCCESS;
json config;
std::shared_ptr<SubscriberApp> sub;
std::shared_ptr<PublisherApp> pub;
std::shared_ptr<MsgHandler> dev;
int domain_id = 0;
const char* interface = "can";
const char* port = "can0";
const char* baudrate = "500000";
const char* device = "5serial";
int device_id = 0;
auto exeDir = getExeDir();
auto configPath = exeDir / "config.json";
std::ifstream file(configPath);
file >> config;
file.close();
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], "--domain") == 0 && i + 1 < argc)
{
domain_id = atoi(argv[++i]);
}
else if (strcmp(argv[i], "--interface") == 0 && i + 1 < argc)
{
interface = argv[++i];
}
else if (strcmp(argv[i], "--port") == 0 && i + 1 < argc)
{
port = argv[++i];
}
else if (strcmp(argv[i], "--baudrate") == 0 && i + 1 < argc)
{
baudrate = argv[++i];
}
else if (strcmp(argv[i], "--device") == 0 && i + 1 < argc)
{
device = argv[++i];
}
else if (strcmp(argv[i], "--device_id") == 0 && i + 1 < argc)
{
device_id = atoi(argv[++i]);
}
else if (strcmp(argv[i], "--version") == 0)
{
std::cout << "Vesrion: " << VERSION << "\n";
return EXIT_SUCCESS;
}
else if (strcmp(argv[i], "--help") == 0)
{
std::cout << "Usage: [options]\n"
<< "Options:\n"
<< " --domain Set domain ID\n"
<< " --interface Set interface (e.g., can)\n"
<< " --baudrate Set baudrate (e.g., 9600)\n"
<< " --port Set port name (e.g., can0)\n"
<< " --device Set device name (e.g., 5serial)\n"
<< " --version Show software Version\n"
<< " --help Show this help message\n";
return EXIT_SUCCESS;
}
else
{
std::cerr << "Unknown option: " << argv[i] << "\n";
std::cout << "Usage: [options]\n"
<< "Options:\n"
<< " --domain Set domain ID\n"
<< " --interface Set interface (e.g., can)\n"
<< " --baudrate Set baudrate (e.g., 9600)\n"
<< " --port Set port name (e.g., can0)\n"
<< " --device Set device name (e.g., 5serial)\n"
<< " --version Show software Version\n"
<< " --help Show this help message\n";
return EXIT_FAILURE;
}
}
sub = std::make_shared<SubscriberApp>(domain_id);
pub = std::make_shared<PublisherApp>(domain_id);
dev = std::make_shared<CanMsgHandler>();
dev->OpenPort(port, baudrate);
dev->device = device;
dev->device_id = device_id;
dev->iomap.imap = config["ioctrl"]["iomap"]["in"].get<std::map<std::string, std::pair<uint8_t, uint8_t>>>();
dev->iomap.omap = config["ioctrl"]["iomap"]["out"].get<std::map<std::string, std::pair<uint8_t, uint8_t>>>();
std::thread pub_thread(&PublisherApp::run, pub, dev);
std::cout << "Program is running. Please press Ctrl+C to stop at any time." << std::endl;
stop_handler = [&](int signum)
{
std::cout << "\n" << parse_signal(signum) << " received, stopping " << argv[1]
<< " execution." << std::endl;
pub->stop();
};
signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);
#ifndef _WIN32
signal(SIGQUIT, signal_handler);
signal(SIGHUP, signal_handler);
#endif // _WIN32
pub_thread.join();
Log::Reset();
return ret;
}

@ -0,0 +1,14 @@
#ifndef _MSG_HPP_
#define _MSG_HPP_
#include <queue>
#include <mutex>
#include "System.hpp"
class MsgData {
public:
static std::queue<IoCtrlReq> IoCtrlReq_queue_;
static std::mutex queue_cv_mtx_;
};
#endif

@ -1098,6 +1098,346 @@ private:
float m_stable_weight{0.0}; float m_stable_weight{0.0};
float m_instantaneous_weight{0.0}; float m_instantaneous_weight{0.0};
};
/*!
* @brief This class represents the structure IoCtrlReq defined by the user in the IDL file.
* @ingroup System
*/
class IoCtrlReq
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport IoCtrlReq()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~IoCtrlReq()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object IoCtrlReq that will be copied.
*/
eProsima_user_DllExport IoCtrlReq(
const IoCtrlReq& x)
{
m_index = x.m_index;
m_msg = x.m_msg;
}
/*!
* @brief Move constructor.
* @param x Reference to the object IoCtrlReq that will be copied.
*/
eProsima_user_DllExport IoCtrlReq(
IoCtrlReq&& x) noexcept
{
m_index = x.m_index;
m_msg = std::move(x.m_msg);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object IoCtrlReq that will be copied.
*/
eProsima_user_DllExport IoCtrlReq& operator =(
const IoCtrlReq& x)
{
m_index = x.m_index;
m_msg = x.m_msg;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object IoCtrlReq that will be copied.
*/
eProsima_user_DllExport IoCtrlReq& operator =(
IoCtrlReq&& x) noexcept
{
m_index = x.m_index;
m_msg = std::move(x.m_msg);
return *this;
}
/*!
* @brief Comparison operator.
* @param x IoCtrlReq object to compare.
*/
eProsima_user_DllExport bool operator ==(
const IoCtrlReq& x) const
{
return (m_index == x.m_index &&
m_msg == x.m_msg);
}
/*!
* @brief Comparison operator.
* @param x IoCtrlReq object to compare.
*/
eProsima_user_DllExport bool operator !=(
const IoCtrlReq& x) const
{
return !(*this == x);
}
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
eProsima_user_DllExport void index(
uint32_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function copies the value in member msg
* @param _msg New value to be copied in member msg
*/
eProsima_user_DllExport void msg(
const std::map<std::string, std::string>& _msg)
{
m_msg = _msg;
}
/*!
* @brief This function moves the value in member msg
* @param _msg New value to be moved in member msg
*/
eProsima_user_DllExport void msg(
std::map<std::string, std::string>&& _msg)
{
m_msg = std::move(_msg);
}
/*!
* @brief This function returns a constant reference to member msg
* @return Constant reference to member msg
*/
eProsima_user_DllExport const std::map<std::string, std::string>& msg() const
{
return m_msg;
}
/*!
* @brief This function returns a reference to member msg
* @return Reference to member msg
*/
eProsima_user_DllExport std::map<std::string, std::string>& msg()
{
return m_msg;
}
private:
uint32_t m_index{0};
std::map<std::string, std::string> m_msg;
};
/*!
* @brief This class represents the structure IoCtrlRsp defined by the user in the IDL file.
* @ingroup System
*/
class IoCtrlRsp
{
public:
/*!
* @brief Default constructor.
*/
eProsima_user_DllExport IoCtrlRsp()
{
}
/*!
* @brief Default destructor.
*/
eProsima_user_DllExport ~IoCtrlRsp()
{
}
/*!
* @brief Copy constructor.
* @param x Reference to the object IoCtrlRsp that will be copied.
*/
eProsima_user_DllExport IoCtrlRsp(
const IoCtrlRsp& x)
{
m_index = x.m_index;
m_msg = x.m_msg;
}
/*!
* @brief Move constructor.
* @param x Reference to the object IoCtrlRsp that will be copied.
*/
eProsima_user_DllExport IoCtrlRsp(
IoCtrlRsp&& x) noexcept
{
m_index = x.m_index;
m_msg = std::move(x.m_msg);
}
/*!
* @brief Copy assignment.
* @param x Reference to the object IoCtrlRsp that will be copied.
*/
eProsima_user_DllExport IoCtrlRsp& operator =(
const IoCtrlRsp& x)
{
m_index = x.m_index;
m_msg = x.m_msg;
return *this;
}
/*!
* @brief Move assignment.
* @param x Reference to the object IoCtrlRsp that will be copied.
*/
eProsima_user_DllExport IoCtrlRsp& operator =(
IoCtrlRsp&& x) noexcept
{
m_index = x.m_index;
m_msg = std::move(x.m_msg);
return *this;
}
/*!
* @brief Comparison operator.
* @param x IoCtrlRsp object to compare.
*/
eProsima_user_DllExport bool operator ==(
const IoCtrlRsp& x) const
{
return (m_index == x.m_index &&
m_msg == x.m_msg);
}
/*!
* @brief Comparison operator.
* @param x IoCtrlRsp object to compare.
*/
eProsima_user_DllExport bool operator !=(
const IoCtrlRsp& x) const
{
return !(*this == x);
}
/*!
* @brief This function sets a value in member index
* @param _index New value for member index
*/
eProsima_user_DllExport void index(
uint32_t _index)
{
m_index = _index;
}
/*!
* @brief This function returns the value of member index
* @return Value of member index
*/
eProsima_user_DllExport uint32_t index() const
{
return m_index;
}
/*!
* @brief This function returns a reference to member index
* @return Reference to member index
*/
eProsima_user_DllExport uint32_t& index()
{
return m_index;
}
/*!
* @brief This function copies the value in member msg
* @param _msg New value to be copied in member msg
*/
eProsima_user_DllExport void msg(
const std::map<std::string, std::string>& _msg)
{
m_msg = _msg;
}
/*!
* @brief This function moves the value in member msg
* @param _msg New value to be moved in member msg
*/
eProsima_user_DllExport void msg(
std::map<std::string, std::string>&& _msg)
{
m_msg = std::move(_msg);
}
/*!
* @brief This function returns a constant reference to member msg
* @return Constant reference to member msg
*/
eProsima_user_DllExport const std::map<std::string, std::string>& msg() const
{
return m_msg;
}
/*!
* @brief This function returns a reference to member msg
* @return Reference to member msg
*/
eProsima_user_DllExport std::map<std::string, std::string>& msg()
{
return m_msg;
}
private:
uint32_t m_index{0};
std::map<std::string, std::string> m_msg;
}; };
#endif // _FAST_DDS_GENERATED_SYSTEM_HPP_ #endif // _FAST_DDS_GENERATED_SYSTEM_HPP_

@ -35,3 +35,16 @@ struct WeighRsp
float stable_weight; float stable_weight;
float instantaneous_weight; float instantaneous_weight;
}; };
// private
struct IoCtrlReq
{
unsigned long index;
map<string, string> msg;
};
struct IoCtrlRsp
{
unsigned long index;
map<string, string> msg;
};

@ -42,6 +42,12 @@ constexpr uint32_t PrintRsp_max_key_cdr_typesize {0UL};
constexpr uint32_t WeighRsp_max_cdr_typesize {16UL}; constexpr uint32_t WeighRsp_max_cdr_typesize {16UL};
constexpr uint32_t WeighRsp_max_key_cdr_typesize {0UL}; constexpr uint32_t WeighRsp_max_key_cdr_typesize {0UL};
constexpr uint32_t IoCtrlRsp_max_cdr_typesize {16UL};
constexpr uint32_t IoCtrlRsp_max_key_cdr_typesize {0UL};
constexpr uint32_t IoCtrlReq_max_cdr_typesize {16UL};
constexpr uint32_t IoCtrlReq_max_key_cdr_typesize {0UL};
namespace eprosima { namespace eprosima {
namespace fastcdr { namespace fastcdr {
@ -73,6 +79,14 @@ eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr, eprosima::fastcdr::Cdr& scdr,
const WeighRsp& data); const WeighRsp& data);
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const IoCtrlReq& data);
eProsima_user_DllExport void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const IoCtrlRsp& data);
} // namespace fastcdr } // namespace fastcdr
} // namespace eprosima } // namespace eprosima

@ -578,6 +578,184 @@ void serialize_key(
} }
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const IoCtrlReq& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.index(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.msg(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const IoCtrlReq& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.index()
<< eprosima::fastcdr::MemberId(1) << data.msg()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
IoCtrlReq& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.index();
break;
case 1:
dcdr >> data.msg();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const IoCtrlReq& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.index();
scdr << data.msg();
}
template<>
eProsima_user_DllExport size_t calculate_serialized_size(
eprosima::fastcdr::CdrSizeCalculator& calculator,
const IoCtrlRsp& data,
size_t& current_alignment)
{
static_cast<void>(data);
eprosima::fastcdr::EncodingAlgorithmFlag previous_encoding = calculator.get_encoding();
size_t calculated_size {calculator.begin_calculate_type_serialized_size(
eprosima::fastcdr::CdrVersion::XCDRv2 == calculator.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
current_alignment)};
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(0),
data.index(), current_alignment);
calculated_size += calculator.calculate_member_serialized_size(eprosima::fastcdr::MemberId(1),
data.msg(), current_alignment);
calculated_size += calculator.end_calculate_type_serialized_size(previous_encoding, current_alignment);
return calculated_size;
}
template<>
eProsima_user_DllExport void serialize(
eprosima::fastcdr::Cdr& scdr,
const IoCtrlRsp& data)
{
eprosima::fastcdr::Cdr::state current_state(scdr);
scdr.begin_serialize_type(current_state,
eprosima::fastcdr::CdrVersion::XCDRv2 == scdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR);
scdr
<< eprosima::fastcdr::MemberId(0) << data.index()
<< eprosima::fastcdr::MemberId(1) << data.msg()
;
scdr.end_serialize_type(current_state);
}
template<>
eProsima_user_DllExport void deserialize(
eprosima::fastcdr::Cdr& cdr,
IoCtrlRsp& data)
{
cdr.deserialize_type(eprosima::fastcdr::CdrVersion::XCDRv2 == cdr.get_cdr_version() ?
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2 :
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR,
[&data](eprosima::fastcdr::Cdr& dcdr, const eprosima::fastcdr::MemberId& mid) -> bool
{
bool ret_value = true;
switch (mid.id)
{
case 0:
dcdr >> data.index();
break;
case 1:
dcdr >> data.msg();
break;
default:
ret_value = false;
break;
}
return ret_value;
});
}
void serialize_key(
eprosima::fastcdr::Cdr& scdr,
const IoCtrlRsp& data)
{
static_cast<void>(scdr);
static_cast<void>(data);
scdr << data.index();
scdr << data.msg();
}
} // namespace fastcdr } // namespace fastcdr
} // namespace eprosima } // namespace eprosima

@ -1123,6 +1123,370 @@ void WeighRspPubSubType::register_type_object_representation()
register_WeighRsp_type_identifier(type_identifiers_); register_WeighRsp_type_identifier(type_identifiers_);
} }
IoCtrlReqPubSubType::IoCtrlReqPubSubType()
{
set_name("IoCtrlReq");
uint32_t type_size = IoCtrlReq_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = IoCtrlReq_max_key_cdr_typesize > 16 ? IoCtrlReq_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
IoCtrlReqPubSubType::~IoCtrlReqPubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool IoCtrlReqPubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const IoCtrlReq* p_type = static_cast<const IoCtrlReq*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool IoCtrlReqPubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
IoCtrlReq* p_type = static_cast<IoCtrlReq*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t IoCtrlReqPubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const IoCtrlReq*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* IoCtrlReqPubSubType::create_data()
{
return reinterpret_cast<void*>(new IoCtrlReq());
}
void IoCtrlReqPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<IoCtrlReq*>(data));
}
bool IoCtrlReqPubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
IoCtrlReq data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool IoCtrlReqPubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const IoCtrlReq* p_type = static_cast<const IoCtrlReq*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
IoCtrlReq_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || IoCtrlReq_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void IoCtrlReqPubSubType::register_type_object_representation()
{
register_IoCtrlReq_type_identifier(type_identifiers_);
}
IoCtrlRspPubSubType::IoCtrlRspPubSubType()
{
set_name("IoCtrlRsp");
uint32_t type_size = IoCtrlRsp_max_cdr_typesize;
type_size += static_cast<uint32_t>(eprosima::fastcdr::Cdr::alignment(type_size, 4)); /* possible submessage alignment */
max_serialized_type_size = type_size + 4; /*encapsulation*/
is_compute_key_provided = false;
uint32_t key_length = IoCtrlRsp_max_key_cdr_typesize > 16 ? IoCtrlRsp_max_key_cdr_typesize : 16;
key_buffer_ = reinterpret_cast<unsigned char*>(malloc(key_length));
memset(key_buffer_, 0, key_length);
}
IoCtrlRspPubSubType::~IoCtrlRspPubSubType()
{
if (key_buffer_ != nullptr)
{
free(key_buffer_);
}
}
bool IoCtrlRspPubSubType::serialize(
const void* const data,
SerializedPayload_t& payload,
DataRepresentationId_t data_representation)
{
const IoCtrlRsp* p_type = static_cast<const IoCtrlRsp*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.max_size);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 : eprosima::fastcdr::CdrVersion::XCDRv2);
payload.encapsulation = ser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
ser.set_encoding_flag(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR :
eprosima::fastcdr::EncodingAlgorithmFlag::DELIMIT_CDR2);
try
{
// Serialize encapsulation
ser.serialize_encapsulation();
// Serialize the object.
ser << *p_type;
ser.set_dds_cdr_options({0,0});
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
// Get the serialized length
payload.length = static_cast<uint32_t>(ser.get_serialized_data_length());
return true;
}
bool IoCtrlRspPubSubType::deserialize(
SerializedPayload_t& payload,
void* data)
{
try
{
// Convert DATA to pointer of your type
IoCtrlRsp* p_type = static_cast<IoCtrlRsp*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(payload.data), payload.length);
// Object that deserializes the data.
eprosima::fastcdr::Cdr deser(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN);
// Deserialize encapsulation.
deser.read_encapsulation();
payload.encapsulation = deser.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS ? CDR_BE : CDR_LE;
// Deserialize the object.
deser >> *p_type;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return false;
}
return true;
}
uint32_t IoCtrlRspPubSubType::calculate_serialized_size(
const void* const data,
DataRepresentationId_t data_representation)
{
try
{
eprosima::fastcdr::CdrSizeCalculator calculator(
data_representation == DataRepresentationId_t::XCDR_DATA_REPRESENTATION ?
eprosima::fastcdr::CdrVersion::XCDRv1 :eprosima::fastcdr::CdrVersion::XCDRv2);
size_t current_alignment {0};
return static_cast<uint32_t>(calculator.calculate_serialized_size(
*static_cast<const IoCtrlRsp*>(data), current_alignment)) +
4u /*encapsulation*/;
}
catch (eprosima::fastcdr::exception::Exception& /*exception*/)
{
return 0;
}
}
void* IoCtrlRspPubSubType::create_data()
{
return reinterpret_cast<void*>(new IoCtrlRsp());
}
void IoCtrlRspPubSubType::delete_data(
void* data)
{
delete(reinterpret_cast<IoCtrlRsp*>(data));
}
bool IoCtrlRspPubSubType::compute_key(
SerializedPayload_t& payload,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
IoCtrlRsp data;
if (deserialize(payload, static_cast<void*>(&data)))
{
return compute_key(static_cast<void*>(&data), handle, force_md5);
}
return false;
}
bool IoCtrlRspPubSubType::compute_key(
const void* const data,
InstanceHandle_t& handle,
bool force_md5)
{
if (!is_compute_key_provided)
{
return false;
}
const IoCtrlRsp* p_type = static_cast<const IoCtrlRsp*>(data);
// Object that manages the raw buffer.
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char*>(key_buffer_),
IoCtrlRsp_max_key_cdr_typesize);
// Object that serializes the data.
eprosima::fastcdr::Cdr ser(fastbuffer, eprosima::fastcdr::Cdr::BIG_ENDIANNESS, eprosima::fastcdr::CdrVersion::XCDRv2);
ser.set_encoding_flag(eprosima::fastcdr::EncodingAlgorithmFlag::PLAIN_CDR2);
eprosima::fastcdr::serialize_key(ser, *p_type);
if (force_md5 || IoCtrlRsp_max_key_cdr_typesize > 16)
{
md5_.init();
md5_.update(key_buffer_, static_cast<unsigned int>(ser.get_serialized_data_length()));
md5_.finalize();
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = md5_.digest[i];
}
}
else
{
for (uint8_t i = 0; i < 16; ++i)
{
handle.value[i] = key_buffer_[i];
}
}
return true;
}
void IoCtrlRspPubSubType::register_type_object_representation()
{
register_IoCtrlRsp_type_identifier(type_identifiers_);
}
// Include auxiliary functions like for serializing/deserializing. // Include auxiliary functions like for serializing/deserializing.
#include "SystemCdrAux.ipp" #include "SystemCdrAux.ipp"

@ -524,5 +524,167 @@ private:
}; };
/*!
* @brief This class represents the TopicDataType of the type IoCtrlReq defined by the user in the IDL file.
* @ingroup System
*/
class IoCtrlReqPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef IoCtrlReq type;
eProsima_user_DllExport IoCtrlReqPubSubType();
eProsima_user_DllExport ~IoCtrlReqPubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
/*!
* @brief This class represents the TopicDataType of the type IoCtrlRsp defined by the user in the IDL file.
* @ingroup System
*/
class IoCtrlRspPubSubType : public eprosima::fastdds::dds::TopicDataType
{
public:
typedef IoCtrlRsp type;
eProsima_user_DllExport IoCtrlRspPubSubType();
eProsima_user_DllExport ~IoCtrlRspPubSubType() override;
eProsima_user_DllExport bool serialize(
const void* const data,
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool deserialize(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
void* data) override;
eProsima_user_DllExport uint32_t calculate_serialized_size(
const void* const data,
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
eProsima_user_DllExport bool compute_key(
eprosima::fastdds::rtps::SerializedPayload_t& payload,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport bool compute_key(
const void* const data,
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
bool force_md5 = false) override;
eProsima_user_DllExport void* create_data() override;
eProsima_user_DllExport void delete_data(
void* data) override;
//Register TypeObject representation in Fast DDS TypeObjectRegistry
eProsima_user_DllExport void register_type_object_representation() override;
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
eProsima_user_DllExport inline bool is_bounded() const override
{
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_BOUNDED
#ifdef TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
eProsima_user_DllExport inline bool is_plain(
eprosima::fastdds::dds::DataRepresentationId_t data_representation) const override
{
static_cast<void>(data_representation);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_IS_PLAIN
#ifdef TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
eProsima_user_DllExport inline bool construct_sample(
void* memory) const override
{
static_cast<void>(memory);
return false;
}
#endif // TOPIC_DATA_TYPE_API_HAS_CONSTRUCT_SAMPLE
private:
eprosima::fastdds::MD5 md5_;
unsigned char* key_buffer_;
};
#endif // FAST_DDS_GENERATED__SYSTEM_PUBSUBTYPES_HPP #endif // FAST_DDS_GENERATED__SYSTEM_PUBSUBTYPES_HPP

@ -850,4 +850,332 @@ void register_WeighRsp_type_identifier(
} }
} }
} }
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_IoCtrlReq_type_identifier(
TypeIdentifierPair& type_ids_IoCtrlReq)
{
ReturnCode_t return_code_IoCtrlReq {eprosima::fastdds::dds::RETCODE_OK};
return_code_IoCtrlReq =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"IoCtrlReq", type_ids_IoCtrlReq);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_IoCtrlReq)
{
StructTypeFlag struct_flags_IoCtrlReq = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_IoCtrlReq = "IoCtrlReq";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_IoCtrlReq;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_IoCtrlReq;
CompleteTypeDetail detail_IoCtrlReq = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_IoCtrlReq, ann_custom_IoCtrlReq, type_name_IoCtrlReq.to_string());
CompleteStructHeader header_IoCtrlReq;
header_IoCtrlReq = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_IoCtrlReq);
CompleteStructMemberSeq member_seq_IoCtrlReq;
{
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_index);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_index = 0x00000000;
bool common_index_ec {false};
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
if (!common_index_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
ann_custom_IoCtrlReq.reset();
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_IoCtrlReq);
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
TypeObjectUtils::add_complete_struct_member(member_seq_IoCtrlReq, member_index);
}
{
TypeIdentifierPair type_ids_msg;
ReturnCode_t return_code_msg {eprosima::fastdds::dds::RETCODE_OK};
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
bool element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false};
TypeIdentifier* element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))};
if (!element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent element TypeIdentifier.");
return;
}
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
bool key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false};
TypeIdentifier* key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))};
if (!key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent key TypeIdentifier.");
return;
}
EquivalenceKind equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_BOTH;
if ((EK_COMPLETE == key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d()) ||
(TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().header().equiv_kind())) ||
(TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().header().equiv_kind())))
{
equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_COMPLETE;
}
CollectionElementFlag element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0;
CollectionElementFlag key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0;
PlainCollectionHeader header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded);
{
SBound bound = 0;
PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, bound,
eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded), key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded,
eprosima::fastcdr::external<TypeIdentifier>(key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded));
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_msg = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_msg = 0x00000001;
bool common_msg_ec {false};
CommonStructMember common_msg {TypeObjectUtils::build_common_struct_member(member_id_msg, member_flags_msg, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, common_msg_ec))};
if (!common_msg_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure msg member TypeIdentifier inconsistent.");
return;
}
MemberName name_msg = "msg";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_msg;
ann_custom_IoCtrlReq.reset();
CompleteMemberDetail detail_msg = TypeObjectUtils::build_complete_member_detail(name_msg, member_ann_builtin_msg, ann_custom_IoCtrlReq);
CompleteStructMember member_msg = TypeObjectUtils::build_complete_struct_member(common_msg, detail_msg);
TypeObjectUtils::add_complete_struct_member(member_seq_IoCtrlReq, member_msg);
}
CompleteStructType struct_type_IoCtrlReq = TypeObjectUtils::build_complete_struct_type(struct_flags_IoCtrlReq, header_IoCtrlReq, member_seq_IoCtrlReq);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_IoCtrlReq, type_name_IoCtrlReq.to_string(), type_ids_IoCtrlReq))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"IoCtrlReq already registered in TypeObjectRegistry for a different type.");
}
}
}
// TypeIdentifier is returned by reference: dependent structures/unions are registered in this same method
void register_IoCtrlRsp_type_identifier(
TypeIdentifierPair& type_ids_IoCtrlRsp)
{
ReturnCode_t return_code_IoCtrlRsp {eprosima::fastdds::dds::RETCODE_OK};
return_code_IoCtrlRsp =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"IoCtrlRsp", type_ids_IoCtrlRsp);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_IoCtrlRsp)
{
StructTypeFlag struct_flags_IoCtrlRsp = TypeObjectUtils::build_struct_type_flag(eprosima::fastdds::dds::xtypes::ExtensibilityKind::APPENDABLE,
false, false);
QualifiedTypeName type_name_IoCtrlRsp = "IoCtrlRsp";
eprosima::fastcdr::optional<AppliedBuiltinTypeAnnotations> type_ann_builtin_IoCtrlRsp;
eprosima::fastcdr::optional<AppliedAnnotationSeq> ann_custom_IoCtrlRsp;
CompleteTypeDetail detail_IoCtrlRsp = TypeObjectUtils::build_complete_type_detail(type_ann_builtin_IoCtrlRsp, ann_custom_IoCtrlRsp, type_name_IoCtrlRsp.to_string());
CompleteStructHeader header_IoCtrlRsp;
header_IoCtrlRsp = TypeObjectUtils::build_complete_struct_header(TypeIdentifier(), detail_IoCtrlRsp);
CompleteStructMemberSeq member_seq_IoCtrlRsp;
{
TypeIdentifierPair type_ids_index;
ReturnCode_t return_code_index {eprosima::fastdds::dds::RETCODE_OK};
return_code_index =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"_uint32_t", type_ids_index);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_index)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"index Structure member TypeIdentifier unknown to TypeObjectRegistry.");
return;
}
StructMemberFlag member_flags_index = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_index = 0x00000000;
bool common_index_ec {false};
CommonStructMember common_index {TypeObjectUtils::build_common_struct_member(member_id_index, member_flags_index, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_index, common_index_ec))};
if (!common_index_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure index member TypeIdentifier inconsistent.");
return;
}
MemberName name_index = "index";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_index;
ann_custom_IoCtrlRsp.reset();
CompleteMemberDetail detail_index = TypeObjectUtils::build_complete_member_detail(name_index, member_ann_builtin_index, ann_custom_IoCtrlRsp);
CompleteStructMember member_index = TypeObjectUtils::build_complete_struct_member(common_index, detail_index);
TypeObjectUtils::add_complete_struct_member(member_seq_IoCtrlRsp, member_index);
}
{
TypeIdentifierPair type_ids_msg;
ReturnCode_t return_code_msg {eprosima::fastdds::dds::RETCODE_OK};
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
bool element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false};
TypeIdentifier* element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))};
if (!element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent element TypeIdentifier.");
return;
}
return_code_msg =
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->type_object_registry().get_type_identifiers(
"anonymous_string_unbounded", type_ids_msg);
if (eprosima::fastdds::dds::RETCODE_OK != return_code_msg)
{
{
SBound bound = 0;
StringSTypeDefn string_sdefn = TypeObjectUtils::build_string_s_type_defn(bound);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_string_type_identifier(string_sdefn,
"anonymous_string_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_string_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
bool key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec {false};
TypeIdentifier* key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded {new TypeIdentifier(TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec))};
if (!key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded inconsistent key TypeIdentifier.");
return;
}
EquivalenceKind equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_BOTH;
if ((EK_COMPLETE == key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d()) ||
(TI_PLAIN_SEQUENCE_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_sdefn().header().equiv_kind()) ||
(TI_PLAIN_SEQUENCE_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->seq_ldefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_sdefn().header().equiv_kind()) ||
(TI_PLAIN_ARRAY_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->array_ldefn().header().equiv_kind()) ||
(TI_PLAIN_MAP_SMALL == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_sdefn().header().equiv_kind())) ||
(TI_PLAIN_MAP_LARGE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->_d() && (EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().key_identifier()->_d() || EK_COMPLETE == element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded->map_ldefn().header().equiv_kind())))
{
equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = EK_COMPLETE;
}
CollectionElementFlag element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0;
CollectionElementFlag key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = 0;
PlainCollectionHeader header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded = TypeObjectUtils::build_plain_collection_header(equiv_kind_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, element_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded);
{
SBound bound = 0;
PlainMapSTypeDefn map_sdefn = TypeObjectUtils::build_plain_map_s_type_defn(header_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded, bound,
eprosima::fastcdr::external<TypeIdentifier>(element_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded), key_flags_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded,
eprosima::fastcdr::external<TypeIdentifier>(key_identifier_anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded));
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_s_map_type_identifier(map_sdefn, "anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded", type_ids_msg))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"anonymous_map_anonymous_string_unbounded_anonymous_string_unbounded_unbounded already registered in TypeObjectRegistry for a different type.");
}
}
}
StructMemberFlag member_flags_msg = TypeObjectUtils::build_struct_member_flag(eprosima::fastdds::dds::xtypes::TryConstructFailAction::DISCARD,
false, false, false, false);
MemberId member_id_msg = 0x00000001;
bool common_msg_ec {false};
CommonStructMember common_msg {TypeObjectUtils::build_common_struct_member(member_id_msg, member_flags_msg, TypeObjectUtils::retrieve_complete_type_identifier(type_ids_msg, common_msg_ec))};
if (!common_msg_ec)
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION, "Structure msg member TypeIdentifier inconsistent.");
return;
}
MemberName name_msg = "msg";
eprosima::fastcdr::optional<AppliedBuiltinMemberAnnotations> member_ann_builtin_msg;
ann_custom_IoCtrlRsp.reset();
CompleteMemberDetail detail_msg = TypeObjectUtils::build_complete_member_detail(name_msg, member_ann_builtin_msg, ann_custom_IoCtrlRsp);
CompleteStructMember member_msg = TypeObjectUtils::build_complete_struct_member(common_msg, detail_msg);
TypeObjectUtils::add_complete_struct_member(member_seq_IoCtrlRsp, member_msg);
}
CompleteStructType struct_type_IoCtrlRsp = TypeObjectUtils::build_complete_struct_type(struct_flags_IoCtrlRsp, header_IoCtrlRsp, member_seq_IoCtrlRsp);
if (eprosima::fastdds::dds::RETCODE_BAD_PARAMETER ==
TypeObjectUtils::build_and_register_struct_type_object(struct_type_IoCtrlRsp, type_name_IoCtrlRsp.to_string(), type_ids_IoCtrlRsp))
{
EPROSIMA_LOG_ERROR(XTYPES_TYPE_REPRESENTATION,
"IoCtrlRsp already registered in TypeObjectRegistry for a different type.");
}
}
}

@ -109,6 +109,30 @@ eProsima_user_DllExport void register_WeighReq_type_identifier(
*/ */
eProsima_user_DllExport void register_WeighRsp_type_identifier( eProsima_user_DllExport void register_WeighRsp_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids); eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
/**
* @brief Register IoCtrlReq related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_IoCtrlReq_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
/**
* @brief Register IoCtrlRsp related TypeIdentifier.
* Fully-descriptive TypeIdentifiers are directly registered.
* Hash TypeIdentifiers require to fill the TypeObject information and hash it, consequently, the TypeObject is
* indirectly registered as well.
*
* @param[out] TypeIdentifier of the registered type.
* The returned TypeIdentifier corresponds to the complete TypeIdentifier in case of hashed TypeIdentifiers.
* Invalid TypeIdentifier is returned in case of error.
*/
eProsima_user_DllExport void register_IoCtrlRsp_type_identifier(
eprosima::fastdds::dds::xtypes::TypeIdentifierPair& type_ids);
#endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC #endif // DOXYGEN_SHOULD_SKIP_THIS_PUBLIC

Loading…
Cancel
Save