• part 3 of 5 of: GPS Module, Extensions, and u-blox NEO-6M

    Example C_ shows - finally - extensions with two line handlers in addition the to reused defaultLineHandler() of the GPS module:

    1. transforming line handler implementation for the NMEA $GPRMC sentence
    2. raw line handler - handling all sentences not handled by transforming line handlers

      // C) for enhanced use: gpsHandlerObjectDefaultAndOther reusing basic function as in A and other extensions
      var gpsHandlerObjectDefaultAndOther = { 
      // GGA (default): tag, time, lat[deg], lon[deg], fix, satellites, altitude[m]
      // GSA:
      // GSV (multiples):
      // GLL
      // RMC // NMEA's pvs - position, velocity, and speed (plus other things: true angle, date and time, mag var)
      includesDefaultLineHandler: true,
      handle: true,
      lineHandler: function(line, handler) {
      if (handler.handle) {
        var tag = line.substr(3,3);
        if/*sel*/ (tag=="GGA") {
          handler.defaultLineHandler(line,changeHa­ndler);
        } else if (tag=="RMC") {
          handler.handleRMC(line,gpsHandlerFunctio­n);
        } else {
          gpsHandlerFunction({"raw":line});
        }
      }
      },
      handleRMC: function(line,callback) {
      var d = line.split(",");
      callback({ tag:"RMC",
        timec: d[1].substr(0,6),
        latc: d[3].substr(0,2) + "_" + d[3].substr(2) + "_" + d[4],
        lonc: d[5].substr(0,3) + "_" + d[5].substr(3) + "_" + d[6],
        velo: d[7],
        angl: d[8],
        date: d[9]
      });
      }
      };
      

    Use the related goEnhancedWithDefaultAndOther() function to run the example.

    function goEnhancedWithDefaultAndOther() {
       gps.connect(Serial4, gpsHandlerObjectDefaultAndOther);
    }
    

    The raw handler shows the line 'as is' in the console for the purpose of exploring all the sentences the GPS receiver sends on serial data event, creating the following out put:

    >echo(0);
    =undefined
    >goEnhancedWithDefaultAndOther()
    =undefined
    {
      "raw": "1\r"
     }
    {
      "tag": "GGA",
      "time": "09:11:24",
      "lat": 41.22417566666, "lon": -102.87468133333, "fix": 2, "satellites": 11, "altitude": 70.3 }
    {
      "raw": "$GPGSA,A,3,13,51,07,20,46,16,08,10,09,2­7,23,,2.73,1.11,2.49*08\r"
     }
    {
      "raw": "$GPGSV,5,1,17,02,02,309,,03,22,042,,06,­09,273,,07,45,265,27*7F\r"
     }
    {
      "raw": "$GPGSV,5,2,17,08,65,279,41,09,62,328,22­,10,30,309,28,13,57,326,26*7E\r"
     }
    {
      "raw": "$GPGSV,5,3,17,16,46,059,31,19,02,135,,2­0,41,182,34,23,71,061,45*74\r"
     }
    {
      "raw": "$GPGSV,5,4,17,27,12,106,18,30,16,250,,3­2,06,155,,46,42,142,34*77\r"
     }
    {
      "raw": "$GPGSV,5,5,17,51,44,156,32*48\r"
     }
    {
      "raw": "$GPGLL,4113.45054,N,10252.48088,W,09112­4.00,A,D*7E\r"
     }
    {
      "tag": "RMC",
      "timec": "091120",
      "latc": "41_13.45054_N",
      "lonc": "102_52.48076_W",
      "velo": "0.035",
      "angl": "",
      "date": "270914"
     }
    {
      "raw": "$GPVTG,,T,,M,0.035,N,0.066,K,D*20\r"
     }
    {
      "tag": "GGA",
    .....
    ...
    .
    

    part 3 of 5 of: GPS Module, Extensions, and u-blox NEO-6M

About

Avatar for allObjects @allObjects started