37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <sys/types.h>
40 #include <arpa/inet.h>
67 ROS_ERROR(
"Error creating/binding socket: %s", strerror(errno));
124 uint8_t supported_registers[] = { 0x7F, 0x06, 0x05, 0x04, 0x03, 0 };
125 uint16_t init_value[] = { 0 , 0x2D, 0x5E, 0x2F0, 0x1E0, 0x1311 };
126 for (
unsigned int i = 0; i <
sizeof(supported_registers) /
sizeof(*supported_registers); i++)
132 uint8_t tolerated_registers[] = { 0x18, 0x15, 0x20, 0x21, 0x01, 0x02, 0x0D, 0x70, 0x71, 0x1C, 0xAF, 0x0B, 0x47, 0x48, 0x4C, 0xA5, 0x35, 0xBD };
134 for (
unsigned int i = 0; i <
sizeof(tolerated_registers) /
sizeof(*tolerated_registers); i++)
140 if ((x + 1) / 2 + y < 500)
172 if (sleeptime < -period)
189 for (
int y = 0; y <
height_; y++)
194 for (
int x = 0; x <
width_; x++)
197 for (
int x = 0; x <
width_; x++)
202 for (
int x = 0; x <
width_; x++)
220 sendto(
socket_, &peof,
sizeof(peof), 0,
228 unsigned char buff[100];
232 ssize_t len = recv(
socket_, buff, 100, MSG_DONTWAIT);
238 if (len == 1 && buff[0] == 0xFF)
244 ROS_INFO(
"Got a packet with a bad magic number or type."); \
248 #define CAST_AND_CHK(type) \
249 if (len != sizeof(type)) \
251 ROS_INFO("Got a "#type" with incorrect length"); \
254 if (false) ROS_INFO("Got a "#type""); \
255 type *pkt = (type *) buff;
281 unsigned int new_mode = htons(pkt->trig_state);
286 ROS_ERROR(
"Tried to set to trigger mode %i.", new_mode);
295 uint32_t mode = htonl(pkt->mode);
318 unsigned int new_width = htons(pkt->horizontal);
319 unsigned int new_height = htons(pkt->vertical);
320 if (new_width > 752 || new_height > 640)
322 ROS_ERROR(
"Tried to set resolution to out of range %ix%i", new_width, new_height);
343 data_addr_.sin_addr.s_addr = pkt->receiver.addr;
371 ROS_WARN(
"Reading uninitialized imager register 0x%02X.", pkt->address);
373 ROS_WARN(
"Reading unsupported imager register 0x%02X.", pkt->address);
382 ROS_ERROR(
"Writing unsupported imager register 0x%02X.", pkt->address);
397 ROS_ERROR(
"Got an unknown message type: %i", ntohl(hdr->
type));
404 #define FILL_HDR(pkttype, pktid) \
405 if (false) ROS_INFO("Sending a "#pkttype" packet."); \
406 Packet##pkttype rsp; \
407 rsp.hdr.magic_no = htonl(WG_MAGIC_NO); \
408 strncpy(rsp.hdr.hrt, #pkttype, sizeof(rsp.hdr.hrt)); \
409 rsp.hdr.type = htonl(pktid);
413 sockaddr_in rsp_addr; \
414 bzero(&rsp_addr, sizeof(rsp_addr)); \
415 rsp_addr.sin_family = AF_INET; \
416 rsp_addr.sin_addr.s_addr = hdr->reply_to.addr; \
417 rsp_addr.sin_port = hdr->reply_to.port; \
418 sendto(socket_, &rsp, sizeof(rsp), 0, \
419 (struct sockaddr *) &rsp_addr, sizeof(rsp_addr));
424 bzero(rsp.mac,
sizeof(rsp.mac));
427 strncpy(rsp.product_name,
"WGE100_camera_simulator.",
sizeof(rsp.product_name));
428 rsp.hw_version = htonl(0x2041);
429 rsp.fw_version = htonl(0x0112);
430 strncpy(rsp.camera_name,
"WGE100_camera_simulator.",
sizeof(rsp.camera_name));
439 rsp.status_type = htonl(type);
440 rsp.status_code = htonl(code);
447 rsp.address = address;
448 bzero(rsp.data,
sizeof(rsp.data));
456 rsp.data = htons(value);
472 int main(
int argc,
char **argv)