38 #ifndef WIN32_LEAN_AND_MEAN 39 #define WIN32_LEAN_AND_MEAN 1 47 #include <sys/socket.h> 48 #include <netinet/in.h> 49 #include <arpa/inet.h> 70 void usage(
const char *programNameP)
72 fprintf(stderr,
"USAGE: %s [<options>]\n", programNameP);
73 fprintf(stderr,
"Where <options> are:\n");
74 fprintf(stderr,
"\t-a <current_address> : CURRENT IPV4 address (default=10.66.171.21)\n");
75 fprintf(stderr,
"\t-A <new_address> : NEW IPV4 address (default=10.66.171.21)\n");
76 fprintf(stderr,
"\t-G <new_gateway> : NEW IPV4 gateway (default=10.66.171.1)\n");
77 fprintf(stderr,
"\t-N <new_netmask> : NEW IPV4 address (default=255.255.240.0)\n");
79 fprintf(stderr,
"\t-b <interface> : send broadcast packet to specified network interface (requires root)\n");
81 fprintf(stderr,
"\t-y : disable confirmation prompt\n");
86 bool decodeIpv4(
const std::string& addr,
93 4 != sscanf(addr.c_str(),
"%3u.%3u.%3u.%3u",
94 &p1, &p2, &p3, &p4) ||
95 (p1 > 255 || p2 > 255 || p3 > 255 || p4 > 255)) {
96 fprintf(stderr,
"Unable to decode \"%s\" as IPV4 dotted-quad \n",
111 std::string currentAddress =
"10.66.171.21";
112 std::string desiredAddress =
"10.66.171.21";
113 std::string desiredGateway =
"10.66.171.1";
114 std::string desiredNetmask =
"255.255.240.0";
115 std::string iface =
"eth0";
124 while(-1 != (c =
getopt(argc, argvPP,
"a:A:G:N:b:y")))
126 case 'a': currentAddress = std::string(
optarg);
break;
127 case 'A': desiredAddress = std::string(
optarg);
break;
128 case 'G': desiredGateway = std::string(
optarg);
break;
129 case 'N': desiredNetmask = std::string(
optarg);
break;
130 case 'b': blind =
true; iface = std::string(
optarg);
break;
131 case 'y': prompt =
false;
break;
132 default:
usage(*argvPP);
break;
146 if (!decodeIpv4(desiredAddress, a1, a2, a3, a4))
158 if (NULL == channelP) {
159 fprintf(stderr,
"Failed to establish communications with \"%s\"\n",
160 currentAddress.c_str());
171 fprintf(stderr,
"failed to query sensor version: %s\n",
179 fprintf(stderr,
"failed to query device info %s\n",
185 192 == a1 && 168 == a2 && 0 == a3)
187 fprintf(stderr,
"MultiSense SL units use the 192.168.0 subnet to talk to the Hokuyo ");
188 fprintf(stderr,
"laser. Setting the IP address of the MultiSense to 192.168.0.X will ");
189 fprintf(stderr,
"interfere with the networking configuration.\n");
190 fprintf(stderr,
"\n");
191 fprintf(stderr,
"Aborting IP Change.\n");
199 perror (
"broadcast is not yet supported on Windows");
204 if (192 == a1 && 168 == a2 && 0 == a3)
206 fprintf(stderr,
"MultiSense SL units use the 192.168.0 subnet to talk to the Hokuyo ");
207 fprintf(stderr,
"laser. Setting the IP address of the MultiSense to 192.168.0.X will ");
208 fprintf(stderr,
"interfere with the networking configuration. This unit may be a ");
209 fprintf(stderr,
"MultiSense SL as in broadcast mode this tool cannot query the device.\n");
210 fprintf(stderr,
"\n");
211 fprintf(stderr,
"Aborting IP Change.\n");
217 sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
219 perror(
"socket() failed");
224 if (setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,reinterpret_cast<char const*>(&broadcast),
sizeof(broadcast))==-1) {
225 perror(
"setsockopt(...SO_BROADCAST) failed");
231 if (setsockopt(sockfd,SOL_SOCKET,SO_BINDTODEVICE,iface.c_str(),iface.size()+1)==-1) {
232 perror(
"setsockopt(...SO_BINDTODEVICE) failed (are you root?)");
241 fprintf(stdout,
"NEW address: %s\n", desiredAddress.c_str());
242 fprintf(stdout,
"NEW gateway: %s\n", desiredGateway.c_str());
243 fprintf(stdout,
"NEW netmask: %s\n\n", desiredNetmask.c_str());
246 fprintf(stdout,
"** WARNING: All MultiSense devices attached to interface '%s' will have their addresses changed **\n\n", iface.c_str());
249 fprintf(stdout,
"Really update network configuration? (y/n): ");
253 if (
'Y' != c &&
'y' != c) {
254 fprintf(stdout,
"Aborting\n");
270 fprintf(stderr,
"Failed to set the network configuration: %s\n",
273 fprintf(stdout,
"Network parameters changed successfully\n");
278 struct sockaddr_in si;
281 memset(&si,0,
sizeof(si));
282 si.sin_family = AF_INET;
283 si.sin_port = htons(9001);
284 si.sin_addr.s_addr = htonl(INADDR_BROADCAST);
309 header.sequenceIdentifier = 0;
311 header.byteOffset = 0;
314 if(sendto(sockfd,reinterpret_cast<char const*>(buffer.
data()),buffer.
tell(),0,
reinterpret_cast<sockaddr*
>(&si),
sizeof(si)) == -1) {
315 perror(
"sendto() failed");
319 fprintf(stdout,
"Successfully transmitted network parameter change command\n");
virtual Status setNetworkConfig(const system::NetworkConfig &c)=0
static CRL_CONSTEXPR uint32_t HARDWARE_REV_MULTISENSE_SL
static CRL_CONSTEXPR IdType ID
static const char * statusString(Status status)
static Channel * Create(const std::string &sensorAddress)
std_msgs::Header * header(M &m)
void serialize(Archive &message, const VersionType version)
static CRL_CONSTEXPR uint16_t HEADER_VERSION
int getopt(int argc, char **argv, char *opts)
static CRL_CONSTEXPR VersionType VERSION
void seek(std::size_t idx)
uint32_t hardwareRevision
static CRL_CONSTEXPR Status Status_Ok
static CRL_CONSTEXPR uint16_t HEADER_MAGIC
virtual Status getDeviceInfo(system::DeviceInfo &info)=0
static void Destroy(Channel *instanceP)
static CRL_CONSTEXPR uint16_t HEADER_GROUP
int main(int argc, char **argvPP)
virtual Status getSensorVersion(VersionType &version)=0