mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 18:05:17 +02:00
v0.0.1-alpha (#6)
* Issue with windows paths solved. * Fixed issue when --merge-install is activated (Windows issue) * Updated to last version of Micoxrcedds Agent. (#3) * Restored removed code by accident (#4) * Refs #3842. Removes agent node.
This commit is contained in:
@@ -67,7 +67,7 @@ normalize_path(_DEFAULT_FASTRTPS_PROFILES_PATH "${_DEFAULT_FASTRTPS_PROFILES_PAT
|
|||||||
|
|
||||||
|
|
||||||
# Get colcon call dir
|
# Get colcon call dir
|
||||||
get_filename_component(_COLCON_CALL_DIR "${CMAKE_INSTALL_PREFIX}" DIRECTORY)
|
get_filename_component(_COLCON_CALL_DIR "${PROJECT_BINARY_DIR}" DIRECTORY)
|
||||||
get_filename_component(_COLCON_CALL_DIR "${_COLCON_CALL_DIR}" DIRECTORY)
|
get_filename_component(_COLCON_CALL_DIR "${_COLCON_CALL_DIR}" DIRECTORY)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+67
-116
@@ -28,6 +28,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -37,10 +38,15 @@ void showHelp()
|
|||||||
{
|
{
|
||||||
std::cout << "Usage: program <command>" << std::endl;
|
std::cout << "Usage: program <command>" << std::endl;
|
||||||
std::cout << "List of commands:" << std::endl;
|
std::cout << "List of commands:" << std::endl;
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::cout << " udp <local_port>" << std::endl;
|
||||||
|
std::cout << " tcp <local_port>" << std::endl;
|
||||||
|
#else
|
||||||
std::cout << " serial <device_name>" << std::endl;
|
std::cout << " serial <device_name>" << std::endl;
|
||||||
std::cout << " pseudo-serial" << std::endl;
|
std::cout << " pseudo-serial" << std::endl;
|
||||||
std::cout << " udp <local_port> [<discovery_port>]" << std::endl;
|
std::cout << " udp <local_port> [<discovery_port>]" << std::endl;
|
||||||
std::cout << " tcp <local_port> [<discovery_port>]" << std::endl;
|
std::cout << " tcp <local_port> [<discovery_port>]" << std::endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializationError()
|
void initializationError()
|
||||||
@@ -50,7 +56,7 @@ void initializationError()
|
|||||||
std::exit(EXIT_FAILURE);
|
std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t parsePort(const char* str_port)
|
uint16_t parsePort(const std::string& str_port)
|
||||||
{
|
{
|
||||||
uint16_t valid_port = 0;
|
uint16_t valid_port = 0;
|
||||||
try
|
try
|
||||||
@@ -70,73 +76,66 @@ uint16_t parsePort(const char* str_port)
|
|||||||
return valid_port;
|
return valid_port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class uros_agent : public rclcpp::Node
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
uros_agent() : Node("uROS_Agent")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~uros_agent()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
eprosima::uxr::Server* server = nullptr;
|
||||||
|
std::vector<std::string> cl(0);
|
||||||
|
|
||||||
#ifdef __unix__
|
if (1 == argc)
|
||||||
char exe_path[200];
|
{
|
||||||
ssize_t count = readlink("/proc/self/exe", exe_path, sizeof(exe_path));
|
showHelp();
|
||||||
if (count != -1) {
|
std::cout << std::endl;
|
||||||
chdir(dirname(exe_path));
|
std::cout << "Enter command: ";
|
||||||
|
|
||||||
|
std::string raw_cl;
|
||||||
|
std::getline(std::cin, raw_cl);
|
||||||
|
std::istringstream iss(raw_cl);
|
||||||
|
cl.insert(cl.begin(), std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>());
|
||||||
|
std::cout << raw_cl << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 1; i < argc; ++i)
|
||||||
|
{
|
||||||
|
cl.push_back(argv[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
bool initialized = false;
|
if((1 == cl.size()) && (("-h" == cl[0]) || ("--help" == cl[0])))
|
||||||
|
|
||||||
#ifdef __unix__
|
|
||||||
if(argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0))
|
|
||||||
{
|
{
|
||||||
showHelp();
|
showHelp();
|
||||||
}
|
}
|
||||||
else if(argc >= 3 && strcmp(argv[1], "udp") == 0)
|
else if((2 <= cl.size()) && ("udp" == cl[0]))
|
||||||
{
|
{
|
||||||
std::cout << "UDP agent initialization... ";
|
std::cout << "UDP agent initialization... ";
|
||||||
uint16_t port = parsePort(argv[2]);
|
uint16_t port = parsePort(cl[1]);
|
||||||
eprosima::uxr::UDPServer* udp_server = (argc == 4) //discovery port
|
#ifdef _WIN32
|
||||||
? new eprosima::uxr::UDPServer(port, parsePort(argv[3]))
|
server = new eprosima::uxr::UDPServer(port);
|
||||||
|
#else
|
||||||
|
server = (3 == cl.size()) //discovery port
|
||||||
|
? new eprosima::uxr::UDPServer(port, parsePort(cl[2]))
|
||||||
: new eprosima::uxr::UDPServer(port);
|
: new eprosima::uxr::UDPServer(port);
|
||||||
if (udp_server->run())
|
#endif
|
||||||
{
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
std::cout << ((!initialized) ? "ERROR" : "OK") << std::endl;
|
else if((2 <= cl.size()) && ("tcp" == cl[0]))
|
||||||
}
|
|
||||||
else if(argc >= 3 && strcmp(argv[1], "tcp") == 0)
|
|
||||||
{
|
{
|
||||||
std::cout << "TCP agent initialization... ";
|
std::cout << "TCP agent initialization... ";
|
||||||
uint16_t port = parsePort(argv[2]);
|
uint16_t port = parsePort(cl[1]);
|
||||||
eprosima::uxr::TCPServer* tcp_server = (argc == 4) //discovery port
|
#ifdef _WIN32
|
||||||
? new eprosima::uxr::TCPServer(port, parsePort(argv[3]))
|
server = new eprosima::uxr::TCPServer(port);
|
||||||
|
#else
|
||||||
|
server = (3 == cl.size()) //discovery port
|
||||||
|
? new eprosima::uxr::TCPServer(port, parsePort(cl[2]))
|
||||||
: new eprosima::uxr::TCPServer(port);
|
: new eprosima::uxr::TCPServer(port);
|
||||||
if (tcp_server->run())
|
#endif
|
||||||
{
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
std::cout << ((!initialized) ? "ERROR" : "OK") << std::endl;
|
#ifndef _WIN32
|
||||||
}
|
else if((2 == cl.size()) && ("serial" == cl[0]))
|
||||||
else if(argc == 3 && strcmp(argv[1], "serial") == 0)
|
|
||||||
{
|
{
|
||||||
std::cout << "Serial agent initialization... ";
|
std::cout << "Serial agent initialization... ";
|
||||||
|
|
||||||
/* Open serial device. */
|
/* Open serial device. */
|
||||||
int fd = open(argv[2], O_RDWR | O_NOCTTY);
|
int fd = open(cl[1].c_str(), O_RDWR | O_NOCTTY);
|
||||||
if (0 < fd)
|
if (0 < fd)
|
||||||
{
|
{
|
||||||
struct termios tty_config;
|
struct termios tty_config;
|
||||||
@@ -181,18 +180,12 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
if (0 == tcsetattr(fd, TCSANOW, &tty_config))
|
if (0 == tcsetattr(fd, TCSANOW, &tty_config))
|
||||||
{
|
{
|
||||||
eprosima::uxr::SerialServer* serial_server = new eprosima::uxr::SerialServer(fd, 0);
|
server = new eprosima::uxr::SerialServer(fd, 0);
|
||||||
if (serial_server->run())
|
|
||||||
{
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ((1 == cl.size()) && ("pseudo-serial" == cl[0]))
|
||||||
std::cout << ((!initialized) ? "ERROR" : "OK") << std::endl;
|
|
||||||
}
|
|
||||||
else if (argc == 2 && strcmp(argv[1], "pseudo-serial") == 0)
|
|
||||||
{
|
{
|
||||||
std::cout << "Pseudo-Serial initialization... ";
|
std::cout << "Pseudo-Serial initialization... ";
|
||||||
|
|
||||||
@@ -208,79 +201,37 @@ int main(int argc, char** argv)
|
|||||||
cfmakeraw(&attr);
|
cfmakeraw(&attr);
|
||||||
tcflush(fd, TCIOFLUSH);
|
tcflush(fd, TCIOFLUSH);
|
||||||
tcsetattr(fd, TCSANOW, &attr);
|
tcsetattr(fd, TCSANOW, &attr);
|
||||||
|
std::cout << "Device: " << dev << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
server = new eprosima::uxr::SerialServer(fd, 0x00);
|
||||||
/* Launch server. */
|
}
|
||||||
eprosima::uxr::SerialServer* serial_server = new eprosima::uxr::SerialServer(fd, 0x00);
|
#endif
|
||||||
if (serial_server->run())
|
else
|
||||||
{
|
{
|
||||||
initialized = true;
|
initializationError();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (initialized)
|
if (nullptr != server)
|
||||||
|
{
|
||||||
|
/* Launch server. */
|
||||||
|
if (server->run())
|
||||||
{
|
{
|
||||||
std::cout << "OK" << std::endl;
|
std::cout << "OK" << std::endl;
|
||||||
std::cout << "Device: " << dev << std::endl;
|
std::cin.clear();
|
||||||
|
char exit_flag = 0;
|
||||||
|
while ('q' != exit_flag)
|
||||||
|
{
|
||||||
|
std::cout << "Enter 'q' for exit" << std::endl;
|
||||||
|
std::cin >> exit_flag;
|
||||||
|
}
|
||||||
|
server->stop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "ERROR" << std::endl;
|
std::cout << "ERROR" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
initializationError();
|
|
||||||
}
|
|
||||||
#elif _WIN32
|
|
||||||
(void) argc;
|
|
||||||
(void) argv;
|
|
||||||
|
|
||||||
std::string server_type = "";
|
|
||||||
std::cout << "Select server type [udp|tcp]: ";
|
|
||||||
std::cin >> server_type;
|
|
||||||
|
|
||||||
if ("udp" == server_type)
|
|
||||||
{
|
|
||||||
uint16_t port = 0;
|
|
||||||
std::cout << "Select port: ";
|
|
||||||
std::cin >> port;
|
|
||||||
|
|
||||||
std::cout << "UDP agent initialization.... ";
|
|
||||||
eprosima::uxr::UDPServer* udp_server = new eprosima::uxr::UDPServer(port);
|
|
||||||
if (udp_server->run())
|
|
||||||
{
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
std::cout << ((!initialized) ? "ERROR" : "OK") << std::endl;
|
|
||||||
}
|
|
||||||
else if ("tcp" == server_type)
|
|
||||||
{
|
|
||||||
uint16_t port = 0;
|
|
||||||
std::cout << "Select port: ";
|
|
||||||
std::cin >> port;
|
|
||||||
|
|
||||||
std::cout << "UDP agent initialization.... ";
|
|
||||||
eprosima::uxr::TCPServer* tcp_server = new eprosima::uxr::TCPServer(port);
|
|
||||||
if (tcp_server->run())
|
|
||||||
{
|
|
||||||
initialized = true;
|
|
||||||
}
|
|
||||||
std::cout << ((!initialized) ? "ERROR" : "OK") << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Error server type" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(initialized)
|
|
||||||
{
|
|
||||||
rclcpp::init(argc, argv);
|
|
||||||
rclcpp::spin(std::make_shared<uros_agent>());
|
|
||||||
rclcpp::shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def GetPackage(Dir):
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
return found_package_path
|
return found_package_path.replace("\\", "/")
|
||||||
|
|
||||||
|
|
||||||
def GetPackageList(Dir):
|
def GetPackageList(Dir):
|
||||||
@@ -88,7 +88,7 @@ def GetInterfacePackageMsgs(package_path):
|
|||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith(".msg"):
|
if file.endswith(".msg"):
|
||||||
full_path = os.path.join(root, file)
|
full_path = os.path.join(root, file)
|
||||||
msg_list.append(full_path)
|
msg_list.append(full_path.replace("\\", "/"))
|
||||||
|
|
||||||
return msg_list
|
return msg_list
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ def GetInterfacePackageSrvs(package_path):
|
|||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith(".srv"):
|
if file.endswith(".srv"):
|
||||||
full_path = os.path.join(root, file)
|
full_path = os.path.join(root, file)
|
||||||
msg_list.append(full_path)
|
msg_list.append(full_path.replace("\\", "/"))
|
||||||
|
|
||||||
return msg_list
|
return msg_list
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user