commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8630 - in usrp2/branches/features/host-ng/host-ng: ap


From: jcorgan
Subject: [Commit-gnuradio] r8630 - in usrp2/branches/features/host-ng/host-ng: apps include/usrp2 lib
Date: Thu, 19 Jun 2008 14:49:52 -0600 (MDT)

Author: jcorgan
Date: 2008-06-19 14:49:44 -0600 (Thu, 19 Jun 2008)
New Revision: 8630

Added:
   usrp2/branches/features/host-ng/host-ng/include/usrp2/strtod_si.h
   usrp2/branches/features/host-ng/host-ng/lib/strtod_si.c
Modified:
   usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc
   usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am
   usrp2/branches/features/host-ng/host-ng/lib/Makefile.am
Log:
Correctly parse frequency

Modified: usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc  2008-06-19 
20:48:14 UTC (rev 8629)
+++ usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc  2008-06-19 
20:49:44 UTC (rev 8630)
@@ -22,6 +22,7 @@
 
 #include <usrp2/usrp2.h>
 #include <usrp2/tune_result.h>
+#include <usrp2/strtod_si.h>
 #include <gr_realtime.h>
 #include <iostream>
 #include <string.h>
@@ -54,7 +55,7 @@
   
   int ch;
 
-  while ((ch = getopt(argc, argv, "he:m:")) != EOF){
+  while ((ch = getopt(argc, argv, "he:m:f:")) != EOF){
     switch (ch){
 
     case 'e':
@@ -66,7 +67,11 @@
       break;
 
     case 'f':
-      freq = optarg;
+      if (!strtod_si(optarg, &freq)) {
+        std::cerr << "invalid number: " << optarg << std::endl;
+       usage(argv[0]);
+       exit(1);
+      }
       break;
 
     case 'h':
@@ -86,7 +91,7 @@
     exit(1);
 
   usrp2::tune_result tr;
-  if (!u2->set_rx_freq(16e6, &tr))
+  if (!u2->set_rx_freq(freq, &tr))
     exit(1);
 
   printf("baseband_freq=%f\n", tr.baseband_freq);

Modified: usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am
===================================================================
--- usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am   
2008-06-19 20:48:14 UTC (rev 8629)
+++ usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am   
2008-06-19 20:49:44 UTC (rev 8630)
@@ -24,5 +24,6 @@
 usrp2include_HEADERS = \
        copy_handler.h \
        data_handler.h \
+       strtod_si.h \
        tune_result.h \
        usrp2.h

Copied: usrp2/branches/features/host-ng/host-ng/include/usrp2/strtod_si.h (from 
rev 8625, usrp2/branches/features/host-ng/host/lib/strtod_si.h)
===================================================================
--- usrp2/branches/features/host-ng/host-ng/include/usrp2/strtod_si.h           
                (rev 0)
+++ usrp2/branches/features/host-ng/host-ng/include/usrp2/strtod_si.h   
2008-06-19 20:49:44 UTC (rev 8630)
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_STRTOD_SI_H
+#define INCLUDED_STRTOD_SI_H
+
+#include "usrp2_cdefs.h"
+__U2_BEGIN_DECLS
+
+
+/*!
+ * \brief convert string at s to double honoring any trailing SI suffixes
+ *
+ * \param[in]  s is the string to convert
+ * \param[out] result is the converted value
+ * \returns non-zero iff conversion was successful.
+ */
+int strtod_si(const char *s, double *result);
+
+__U2_END_DECLS
+
+
+#endif /* INCLUDED_STRTOD_SI_H */
+

Modified: usrp2/branches/features/host-ng/host-ng/lib/Makefile.am
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/Makefile.am     2008-06-19 
20:48:14 UTC (rev 8629)
+++ usrp2/branches/features/host-ng/host-ng/lib/Makefile.am     2008-06-19 
20:49:44 UTC (rev 8630)
@@ -30,6 +30,7 @@
        ethernet.cc \
        find.cc \
        pktfilter.cc \
+       strtod_si.c \
        usrp2.cc \
        usrp2_impl.cc \
        usrp2_thread.cc

Copied: usrp2/branches/features/host-ng/host-ng/lib/strtod_si.c (from rev 8625, 
usrp2/branches/features/host-ng/host/lib/strtod_si.c)
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/strtod_si.c                     
        (rev 0)
+++ usrp2/branches/features/host-ng/host-ng/lib/strtod_si.c     2008-06-19 
20:49:44 UTC (rev 8630)
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <usrp2/strtod_si.h>
+#include <stdlib.h>
+
+#define true  1
+#define false 0
+
+int
+strtod_si(const char *s, double *result)
+{
+  *result = 0;
+
+  char *endptr;
+  double r = strtod(s, &endptr);
+  if (s == endptr)
+    return false;
+
+  switch (*endptr){
+  case 'p': r *= 1e-12; break;
+  case 'n': r *= 1e-9;  break;
+  case 'u': r *= 1e-6;  break;
+  case 'm': r *= 1e-3;  break;
+  case 'k': r *= 1e3;   break;
+  case 'M': r *= 1e6;   break;
+  case 'G': r *= 1e9;   break;
+  case 'T': r *= 1e12;  break;
+  default:
+    // ignore. FIXME could be more robust
+    break;
+  }
+
+  *result = r;
+  return true;
+}
+
+





reply via email to

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