You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
4.3 KiB
C++
147 lines
4.3 KiB
C++
// 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 <fastdds/dds/log/Log.hpp>
|
|
|
|
#include "Subscriber.hpp"
|
|
#include "Publisher.hpp"
|
|
|
|
#include "msg.hpp"
|
|
#include "DEBUG.hpp"
|
|
|
|
using eprosima::fastdds::dds::Log;
|
|
|
|
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<WeighingSystem::BarUpdate> DdsMsgData::BarUpdate_queue_;
|
|
std::queue<WeighingSystem::LightsUpdate> DdsMsgData::LightsUpdate_queue_;
|
|
std::queue<WeighingSystem::InfraredUpdate> DdsMsgData::InfraredUpdate_queue_;
|
|
std::queue<WeighingSystem::InfraredCommandUpdate> DdsMsgData::InfraredCommandUpdate_queue_;
|
|
std::queue<WeighingSystem::LicenseSnapUpdate> DdsMsgData::LicenseSnapUpdate_queue_;
|
|
std::queue<WeighingSystem::ScaleInfo> DdsMsgData::ScaleInfo_queue_;
|
|
std::queue<WeighingSystem::WeightInfoOk> DdsMsgData::WeightInfoOk_queue_;
|
|
std::queue<WeighingSystem::WeightInfoError> DdsMsgData::WeightInfoError_queue_;
|
|
std::mutex DdsMsgData::queue_cv_mtx_;
|
|
std::mutex DdsMsgData::infrared_mtx_;
|
|
WeighingSystem::InfraredUpdate DdsMsgData::latest_infrared_;
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
auto ret = EXIT_SUCCESS;
|
|
std::shared_ptr<SubscriberApp> sub;
|
|
std::shared_ptr<PublisherApp> pub;
|
|
|
|
int domain_id = 0;
|
|
|
|
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], "--version") == 0)
|
|
{
|
|
std::cout << "Vesrion: " << PROGRAM_VERSION << "\n";
|
|
return EXIT_SUCCESS;
|
|
}
|
|
else if (strcmp(argv[i], "--help") == 0)
|
|
{
|
|
std::cout << "Usage: [options]\n"
|
|
<< "Options:\n"
|
|
<< " --domain Set domain ID\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"
|
|
<< " --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);
|
|
|
|
std::thread sub_thread(&SubscriberApp::run, sub);
|
|
std::thread pub_thread(&PublisherApp::run, pub);
|
|
|
|
DEBUG("Program is running. Please press Ctrl+C to stop at any time.");
|
|
|
|
stop_handler = [&](int signum)
|
|
{
|
|
std::cout << "\n" << parse_signal(signum) << " received, stopping " << argv[1]
|
|
<< " execution." << std::endl;
|
|
sub->stop();
|
|
pub->stop();
|
|
};
|
|
|
|
signal(SIGINT, signal_handler);
|
|
signal(SIGTERM, signal_handler);
|
|
#ifndef _WIN32
|
|
signal(SIGQUIT, signal_handler);
|
|
signal(SIGHUP, signal_handler);
|
|
#endif // _WIN32
|
|
|
|
sub_thread.join();
|
|
pub_thread.join();
|
|
|
|
Log::Reset();
|
|
return ret;
|
|
}
|