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:
transforming line handler implementation for the NMEA $GPRMC sentence
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,changeHandler);
} else if (tag=="RMC") {
handler.handleRMC(line,gpsHandlerFunction);
} 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:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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:
raw line handler - handling all sentences not handled by transforming line handlers
Use the related goEnhancedWithDefaultAndOther() function to run the example.
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:
part 3 of 5 of: GPS Module, Extensions, and u-blox NEO-6M