commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10989 - gnuradio/branches/developers/eb/vrt/vrt/apps


From: eb
Subject: [Commit-gnuradio] r10989 - gnuradio/branches/developers/eb/vrt/vrt/apps
Date: Thu, 7 May 2009 10:43:30 -0600 (MDT)

Author: eb
Date: 2009-05-07 10:43:30 -0600 (Thu, 07 May 2009)
New Revision: 10989

Modified:
   gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
Log:
checkpoint

Modified: gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc
===================================================================
--- gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-07 15:59:44 UTC (rev 10988)
+++ gnuradio/branches/developers/eb/vrt/vrt/apps/simple_rx_samples.cc   
2009-05-07 16:43:30 UTC (rev 10989)
@@ -32,33 +32,83 @@
 #define        MIN_IP_LOCAL_PORT       32768
 #define        MAX_IP_LOCAL_PORT       61000
 
+#if 0
 static void
 pdie(const char *msg)
 {
   perror(msg);
   exit(1);
 }
+#endif
 
-
-int
-main(int argc, char **argv)
+static bool
+open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port,
+            int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr,
+            int *data_fd_ptr, int *data_port_ptr)
 {
-  const char *quad_radio_ip = "192.168.123.123";
-  int quad_radio_ctrl_port = 790;
-
+  int  ctrl_fd;        // socket for control
   int  data_fd;        // socket fd for data
   int  data_port;      // our port number
-  int  ctrl_fd;        // socket for control
 
   //
+  // create a udp socket and connect it to the quad radio control port
+  //
+
+  ctrl_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+  if (ctrl_fd == -1){
+    perror("socket: ctrl_fd");
+    return false;
+  }
+
+  struct sockaddr_in si_other;
+  memset(&si_other, 0, sizeof(si_other));
+  si_other.sin_family = AF_INET;
+  si_other.sin_port = htons(quad_radio_ctrl_port);
+  if (inet_pton(AF_INET, quad_radio_ip, &si_other.sin_addr) <= 0){
+    perror("inet_pton");
+    return false;
+  }
+
+  if (connect(ctrl_fd, (struct sockaddr *) &si_other, sizeof(si_other)) != 0){
+    perror("connect");
+    return false;
+  }
+
+  // get our ip address associated with the interface connected to the control 
port
+
+  struct sockaddr_in si_me;
+  memset(&si_me, 0, sizeof(si_me));
+  socklen_t sockname_len = sizeof(si_me);
+  if (getsockname(ctrl_fd, (struct sockaddr *) &si_me, &sockname_len) != 0){
+    perror("getsockname");
+  }
+  
+  *ctrl_port_inaddr = si_other.sin_addr;
+
+  if (1){
+    char buf[128];
+    const char *s = inet_ntop(si_me.sin_family, &si_me.sin_addr, buf, 
sizeof(buf));
+    if (s == 0){
+      perror("inet_ntop");
+      return false;
+    }
+    printf("our ip addr associated with ctrl port: %s\n", s);
+  }
+  
+  //
   // create a udp socket to use to receive data
   //
 
   data_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-  if (data_fd == -1)
-    pdie("socket: data_fd");
+  if (data_fd == -1){
+    perror("socket: data_fd");
+    return false;
+  }
 
-  // bind it to a local port (we don't care what the value is)
+  // bind it to a local port on the interface that connects to the ctrl port.
+  // FIXME this assumes that interface connected to the control port and the
+  //   interface connected to the data port are the same.  If we're using
+  //   both ethernet ports on the quad radio, this may not be the case.
 
   data_port = -1;
   for (int port = MIN_IP_LOCAL_PORT; port <= MAX_IP_LOCAL_PORT; port++){
@@ -76,28 +126,34 @@
 
   if (data_port == -1){
     fprintf(stderr, "failed to bind to a local port\n");
-    exit(1);
+    return false;
   }
 
-  printf("data port = %d\n", data_port);
+  printf("our data port = %d\n", data_port);
 
-  //
-  // create a udp socket and connect it to the quad radio control port
-  //
+  return true;
+}
 
-  ctrl_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-  if (ctrl_fd == -1)
-    pdie("socket: ctrl_fd");
 
-  struct sockaddr_in si_other;
-  memset(&si_other, 0, sizeof(si_other));
-  si_other.sin_family = AF_INET;
-  si_other.sin_port = htons(quad_radio_ctrl_port);
-  if (inet_pton(AF_INET, quad_radio_ip, &si_other.sin_addr) <= 0)
-    pdie("inet_pton");
+int
+main(int argc, char **argv)
+{
+  const char *quad_radio_ip = "192.168.123.123";
+  int quad_radio_ctrl_port = 790;
 
-  if (connect(ctrl_fd, (struct sockaddr *) &si_other, sizeof(si_other)) != 0)
-    pdie("connect");
+  int           ctrl_fd;           // socket for control
+  struct in_addr ctrl_port_inaddr;  // our ip addr
+  int           data_fd;           // socket for data
+  int           data_port;         // our data port number
 
+  if (!open_sockets(quad_radio_ip, quad_radio_ctrl_port,
+                   &ctrl_fd, &ctrl_port_inaddr, &data_fd, &data_port))
+    return 1;
+
+
+  // send_start_command(ctrl_fd, data_port,
+                    
+  
+
   return 0;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]