48 #define pipe(X) _pipe(X, 4096, O_BINARY) 49 #define fileno _fileno 54 std::vector<std::string> &
split(
const std::string &s,
char delim, std::vector<std::string> &elems)
56 std::stringstream ss(s);
58 while (std::getline(ss, item, delim))
60 elems.push_back(item);
66 std::vector<std::string>
split(
const std::string &s,
char delim)
68 std::vector<std::string> elems;
69 split(s, delim, elems);
74 main(
int argc,
char** argv)
78 if (argc < 2 || argc > 3)
81 "usage: getID /dev/ttyACM? [quiet]\nOutputs the device ID of a hokuyo at /dev/ttyACM? or IP address" 82 " (specified as 192.168.1.6:10940). Add a second argument for script friendly output.\n");
86 bool verbose = (argc == 2);
88 int save_stdout = dup(STDOUT_FILENO);
102 res = dup2(fds[1], so);
107 bool publish_intensity =
false;
108 bool publish_multiecho =
false;
109 bool synchronize_time =
false;
110 int serial_baud = 115200;
112 std::string ip_address =
"";
113 std::string serial_port =
"";
115 std::vector<std::string> ip_split =
split(argv[1],
':');
116 if (ip_split.size() < 2)
118 serial_port = argv[1];
120 else if (ip_split.size() == 2)
122 ip_address = ip_split[0];
123 ip_port = atoi(ip_split[1].c_str());
129 printf(
"getID failed due to invalid specifier.\n");
136 for (
int retries = 10; retries; retries--)
141 if (ip_address !=
"")
144 publish_intensity, publish_multiecho, synchronize_time));
149 publish_intensity, publish_multiecho, synchronize_time));
151 std::string device_id = urg_->getDeviceID();
154 if (ip_address !=
"")
156 printf(
"Device at %s:%i has ID ", ip_address.c_str(), ip_port);
160 printf(
"Device at %s has ID ", serial_port.c_str());
165 dup2(save_stdout, STDOUT_FILENO);
166 printf(
"%s\n", device_id.c_str());
169 catch (std::runtime_error& e)
171 printf(
"getID failed: %s\n", e.what());
178 printf(
"getID failed for 10 seconds. Giving up.\n");
179 if (ip_address !=
"")
181 printf(
"Device at %s:%i\n", ip_address.c_str(), ip_port);
185 printf(
"Device at %s\n", serial_port.c_str());
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
int main(int argc, char **argv)