// 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 #include #include #include #include #include #include #include "Subscriber.hpp" #include "Publisher.hpp" #include "SerialMsgHandler.hpp" #include "msg.hpp" #define VERSION "v1.0" using eprosima::fastdds::dds::Log; std::function 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 MsgData::WeighReq_queue_; std::mutex MsgData::queue_cv_mtx_; int main(int argc, char** argv) { auto ret = EXIT_SUCCESS; std::shared_ptr sub; std::shared_ptr pub; std::shared_ptr dev; int domain_id = 0; const char* interface = "serial"; const char* port = "ttyS1"; const char* baudrate = "9600"; const char* device = "Toledo"; 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], "--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., serial)\n" << " --baudrate Set baudrate (e.g., 9600)\n" << " --port Set port name (e.g., ttyS1)\n" << " --device Set device name (e.g., Toledo)\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., serial)\n" << " --baudrate Set baudrate (e.g., 9600)\n" << " --port Set port name (e.g., ttyS1)\n" << " --device Set device name (e.g., Toledo)\n" << " --version Show software Version\n" << " --help Show this help message\n"; return EXIT_FAILURE; } } sub = std::make_shared(domain_id); pub = std::make_shared(domain_id); dev = std::make_shared(); dev->OpenPort(port, baudrate); dev->SetDevice(device); 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; }