Browse Source

ublox6: switch to using new mraa_uart_get_dev_path()

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Jon Trulson 10 years ago
parent
commit
809292630f
4 changed files with 18 additions and 36 deletions
  1. 2
    17
      examples/javascript/ublox6.js
  2. 2
    12
      examples/ublox6.cxx
  3. 13
    5
      src/ublox6/ublox6.cxx
  4. 1
    2
      src/ublox6/ublox6.h

+ 2
- 17
examples/javascript/ublox6.js View File

@@ -27,23 +27,8 @@
27 27
 
28 28
 var GPSSensor = require('jsupm_ublox6');
29 29
 
30
-// Instantiate a Ublox6 GPS device on uart 0 (/dev/ttyS0).  This
31
-// works for the galileo G2.  
32
-
33
-// The Edison uses a different serial port, /dev/ttyMFD1, so if you
34
-// are using this example on an Edison board, specify the proper
35
-// port on the command line, eg: 'node ublox6.js /dev/ttyMFD1'
36
-// process.argv.length contains all command-line strings
37
-// argument 0 is "node"
38
-// argument 1 is "ublox6.js"
39
-// argument 2, if it exists, will be the override port,
40
-//    such as /dev/ttyMFD1 on Edison
41
-
42
-var defaultPort = "/dev/ttyS0";
43
-if (process.argv.length > 2)
44
-	defaultPort = process.argv[2];
45
-
46
-var myGPSSensor = new GPSSensor.Ublox6(0, defaultPort);
30
+// Instantiate a Ublox6 GPS device on uart 0.
31
+var myGPSSensor = new GPSSensor.Ublox6(0);
47 32
 
48 33
 if (!myGPSSensor.setupTty(GPSSensor.int_B9600))
49 34
 {

+ 2
- 12
examples/ublox6.cxx View File

@@ -44,18 +44,8 @@ int main (int argc, char **argv)
44 44
   signal(SIGINT, sig_handler);
45 45
 
46 46
 //! [Interesting]
47
-  // Instantiate a Ublox6 GPS device on uart 0 (/dev/ttyS0).  This
48
-  // works for the galileo G2.  
49
-
50
-  // The Edison uses a different serial port, /dev/ttyMFD1, so if you
51
-  // are using this example on an Edison board, specify the proper
52
-  // port on the command line, eg: './ublox6-example /dev/ttyMFD1' 
53
-
54
-  const char *defaultPort = "/dev/ttyS0";
55
-  if (argc > 1)
56
-    defaultPort = argv[1];
57
-
58
-  upm::Ublox6* nmea = new upm::Ublox6(0, defaultPort);
47
+  // Instantiate a Ublox6 GPS device on uart 0.
48
+  upm::Ublox6* nmea = new upm::Ublox6(0);
59 49
 
60 50
   // make sure port is initialized properly.  9600 baud is the default.
61 51
   if (!nmea->setupTty(B9600))

+ 13
- 5
src/ublox6/ublox6.cxx View File

@@ -29,10 +29,9 @@
29 29
 using namespace upm;
30 30
 using namespace std;
31 31
 
32
-Ublox6::Ublox6(int uart, const char *tty) :
33
-  m_ttyFd(-1)
32
+Ublox6::Ublox6(int uart)
34 33
 {
35
-  mraa_init();
34
+  m_ttyFd = -1;
36 35
 
37 36
   if ( !(m_uart = mraa_uart_init(uart)) )
38 37
     {
@@ -40,10 +39,19 @@ Ublox6::Ublox6(int uart, const char *tty) :
40 39
       return;
41 40
     }
42 41
 
42
+  // This requires a recent MRAA (1/2015)
43
+  char *devPath = mraa_uart_get_dev_path(m_uart);
44
+
45
+  if (!devPath)
46
+    {
47
+      cerr << __FUNCTION__ << ": mraa_uart_get_dev_path() failed" << endl;
48
+      return;
49
+    }
50
+
43 51
   // now open the tty
44
-  if ( (m_ttyFd = open(tty, O_RDWR)) == -1)
52
+  if ( (m_ttyFd = open(devPath, O_RDWR)) == -1)
45 53
     {
46
-      cerr << __FUNCTION__ << ": open of " << tty << " failed: " 
54
+      cerr << __FUNCTION__ << ": open of " << devPath << " failed: " 
47 55
            << strerror(errno) << endl;
48 56
       return;
49 57
     }

+ 1
- 2
src/ublox6/ublox6.h View File

@@ -58,9 +58,8 @@ namespace upm {
58 58
      * U-BLOX 6 GPS module constructor
59 59
      *
60 60
      * @param uart defualt uart to use (0 or 1)
61
-     * @param tty tty device to use
62 61
      */
63
-    Ublox6(int uart, const char *tty);
62
+    Ublox6(int uart);
64 63
 
65 64
     /**
66 65
      * U-BLOX 6 GPS module Destructor