/* $Id$ * $URL$ * * gps plugin (nmea), code by michu / www.neophob.com, based on nmeap, http://sourceforge.net/projects/nmeap/ * * Copyright (C) 2007 Michu - http://www.neophob.com * Copyright (C) 2004, 2005, 2006, 2007 The LCD4Linux Team * * This file is part of LCD4Linux. * * LCD4Linux 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 2, or (at your option) * any later version. * * LCD4Linux 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, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ /* * GPS Plugin for lcd4linux, by michael vogt / http://www.neophob.com * contact: michu@neophob.com * * based on nmeap by daveh, http://www.dmh2000.com/ or http://sourceforge.net/projects/nmeap/ * you need a compiled libnmeap to compile this plugin. * * History: * v0.1 -initial release * v0.2 -fix include files, include and (embedded devices) * -fixed emulation mode (read only x bytes instead of the whole emulated nmea data) * -improved error handling (if there are no parameters defined, lcd4linx will display "GPS ARG ERR") * -display raw nmea string from the gps receiver * -added support for gps device with 9600 baud (env. variable) * -added the option that the widget graps data from the buffer and not from the gps device (usefull for multible widgets) * v0.3 -improved nmea parsing * -improved gps-emulator * -time is now updated with rmc and gga sentence * * TODO: * -update direction only when speed > 5 kmh * -add more data fields * -dump nmea string to external file * * Exported functions: * int plugin_init_gps (void) - default plugin initialisation * void parse(SHOW-OPTIONS, DISPLAY-OPTIONS) * display option define, what the plugin should display * * OPTION: EXAMPLE: * ------- -------- * * PARAMETER 1: * #define SHOW_ALTITUDE 0x000000001 alt:500 * #define SHOW_SPEED 0x000000010 spd:30 * #define SHOW_COURSE 0x000000100 dir:NO * #define SHOW_SATELLITES 0x000001000 sat:4 * #define SHOW_QUALITY 0x000010000 qua:1 * #define SHOW_STATUS 0x000100000 sta:V * #define SHOW_TIME_UTC 0x001000000 utc:113459 * #define SHOW_DATE 0x010000000 dat:190204 (19.02.2004) * * PARAMETER 2: * #define OPTION_NO_PREFIX 0x000000001 disable prefix (example, instead of "alt:500" it displays "500" * #define OPTION_SPEED_IN_KNOTS 0x000000010 when use the SHOW_SPEED option, display speed in knots instead in km/h * #define OPTION_RAW_NMEA 0x000000100 outputs the parsed nmea string, only valid when EMULATE is not defined! * #define OPTION_GET_BUFFERDATA 0x000001000 when you define more than 1 gps widget * each widget will get updates and cause some ugly side effects, specially when you display the time * by enabling this option, the widget will not read any nmea data from the serial port. * KEEP IN MIND that there must be ONE widget which get buffered data (means read data from the port) * * #define SHOW_NMEA_STATUS 0x010000000 OK:0033/Error:0002/Incomplete:0002 * * * Examples: * - gps::parse('0x011','0') will display the altitude and speed -> alt:500 spd:43 * - gps::parse('0x01100','0') will display the course and the numbers of satellites -> dir:NO sat:3 * - gps::parse('0x01','0x01') will display the speed without prefix -> 50 * - gp
arte:482000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:201:202:2
Phoenix:482000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:301:302:3
NDR RB:482000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:518:519:161
Das Erste RB:482000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_AUTO:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:261:262:160
hr-fernsehen:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4673:4674:65
MDR FERNSEHEN:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4657:4658:100
NDR FS NDS:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4625:4626:129
NDR FS HH *:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4625:4626:130
NDR FS SH *:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4625:4626:131
NDR FS MVP *:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4625:4626:132
WDR Köln:538000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_1_2:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:4641:4642:262
ZDF:562000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:545:546:514
Info/3sat:562000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:561:562:515
Doku/KiKa:562000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:593:594:517
RTL Television:642000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:337:338:16405
RTL2:642000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:353:354:16406
Super RTL:642000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:369:370:16407
VOX:642000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:545:546:16418
Eurosport:666000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:577:578:16420
TERRA NOVA:666000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:609:610:16422
TELE 5:666000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:465:466:16413
SAT.1:698000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:385:386:16408
N24:698000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:225:226:16398
ProSieben:698000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:305:306:16403
KABEL1:698000000:INVERSION_AUTO:BANDWIDTH_8_MHZ:FEC_2_3:FEC_2_3:QAM_16:TRANSMISSION_MODE_8K:GUARD_INTERVAL_1_4:HIERARCHY_NONE:161:162:16394
PGGA,175225.255,4657.3395,N,00726.2670,E,1,04,9.0,567.8,M,48.0,M,0.0,0000*77\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.7*38\r\n" "$GPRMC,175225.255,A,4657.3395,N,00726.2670,E,0.10,146.99,230507,,*0A\r\n" "$GPGGA,175226.255,465567.5,M,48.0,M,0.0,0000*7B\r\n" "$GPGSA,A,3,26,29,17,12$GPGGA,175227.255,4657.3397,N,00726.2671,E,1,04,9.0,567.1,M,48.0,M,0.0,0000*7F\r\n" "$.7*38\r\n" "$GPGSV,2,1,08,26,71,153,46,29,60,149,46,09,55,286,00,28,32,051$GPGGA,175228.254,4657.3399,N,00726.2672,E,1,04,9.0,566.8,M,48.0,M,0.0,0000*74\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.72,E,0.12,146.43,230507,,*0D\r\n" "$GPGGA,175229.254,4657.3400,N,00726.2673,E,1,04,9.0,566.4,M,48.0,M,0.0,0000*7F\r\n" "$GPGSA,A,3,26,29,17,1$GPGGA,175230.254,4657.3401,N,00726.2675,E,1,04,9.0,566.0,M,48.0,M,0.0,0000*74\r\n" "$GPGSA,A,3,26,29,17,12$GPGGA,175231.254,4657.3402,N,00726.2676,E,1,04,9.0,565.7,M,48.0,M,0.0,0000*71\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.7*38\r\n" "$GPRMC,175231.2$GPGGA,175232.254,4657.3404,N,00726.2677,E,1,04,9.,153,45,29,60,149,46,09,55,286,00,28,32,051,00*7F\r\n" "$GPGSV,2,2,08,17,32,102,38,18,28,298,00,12,12,21$GPGGA,175233.254,4657.3405,N,00726.2678,E,1,04,9.0,565.1,M,48.0,M,0.0,0000*7C\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$,*09\r\n" "$GPGGA,175234.254,4657.3406,N,00726.2679,E,1,04,9.0,564.9,M,48.0,M,0.0,0000*70\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,175234.254,A,4657.3$GPGGA,175235.254,4657.3408,N,00726.2680,E,1,04,9.00,M,0.0,0000*76\r\n" "$GPGSA,A,3,26,$GPGGA,175236.254,439\r\n" "$GPRMC,175236.254,A,4657.3409,N,00726.2681,E,0.14,142.56,230507,,*06\r\n" "$GPGGA,175237.254,4657.3410,N,00726.2682,E,1,04,9.0,564.5,M,48.0,M,0.0,0000*7C\r\n" "$GPGSA,A,3,26,29,17,12,,,,00,28,32,051,00*7F\r\n" "$GPGSV,2,2,08,17,32,102,39,18,28,298,00,12,12,218,35,22,09,3$GPGGA,175238.254,4657.3411,N,00726.2682,E,1,04$GPGGA,175239.254,4657.3412,N,00726.2683,E,1,04,9.0,564.7,M,48.0,M,0.0,0000*73\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,175239.254,A,4657.3412,N$GPGGA,175240.254,4657.3412,N,00726.2684,E,1,04,9.0,564.8,M,48.0,M,0.0,0000*75\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,$GPGGA,175241.254,4657.3413,N,00726.2684,E,1,04,9.0,565.1,M,48.0,M,0.0,0000*7D\r\n" ",,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,175241.254,A,4657.3413,N,00726.2684,E,0.$GPGGA,175242.254,4657.3413,N,00726.2684,E,1,04,9.0,565.3,M,48.0,M,0.0,0000*7C\r\n" "$GPGSA,A,3,26,29,179,60,149,46,09,55,286,00,28,32,051,00*7C\r\n" "$GPGS$GPGGA,175243.254,4657.3414,N,00726.2685,E,1,04,9.0,565.7,M,48.0,M,0.0,0000*7F\r\n" "$GPGSA,A,3$GPGGA,175244.253,4657.3414,N,00726.2685,E,1,04,9.0,566.0,M,48.0,M,0.0,0000*7B\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPGGA,175245.253,4657.3415,N,00726.2685,E,1,04,9.0,566.3,M,48.0,M,0.0,0000*78\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,175245.253,A,4657.3415,N,00726.2685,E,0.2$GPGGA,175246.253,4657.3415,N,00726.2686,E,1,04,9.0,566.5,M,48.0,M,0.0,0000*7E\r\n" ",175246.253,A,4657.3415,N,00726.2686,E,0.13,145$GPGGA,175247.253,4657.3416,N,00726.2686,E,1,04,9.0,566.8,M,48.0,M,0.0,0000*71\r\n" "$GPGSA,A,3,26,17,32,101,39*7D\r\n" "$GPGSV,2,2,08,28,32,051,00,18,$GPGGA,175248.253,4657.3417,N,00726.2686,E,1,04,9.0,567.0,M,48.0,M,0.0,0000*76\r\n" "$GPGSA,A,3,26,29$GPGGA,175249.253,4657.3417,N,00726.2686,E,1,04.3,M,48.0,M,0.0,0000*7$GPGGA,175250.253,4657.3418,N,00726.2686,E,1,04,9.0,567.4,M,48.0,M,0.0,0000*74\r\n" ".5,9.0,2.6*39\r\n" "$GPRMC,175250.253,A,4657.3$GPGGA,175251.253,4657.3418,N,00726.2687,E,1,04,9.0,567.5,M,48.0,M,0.0,0000*75\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" ".2687,E,0.14,146.26,230507,,*05\r\n" "$GPGGA,175252.253,4657.,00,18,28,298,00,12,12,218,36,22,09,326,00*7E\r\n" "$GPRMC,175252.253,A,4657.3419,N,04,9.0,567.9,M,48.0,M,0.0,0000*7A\r\n" "$GPGSA,A,3,26,29,17,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,175253.253,A,4657.$GPGGA,175254.253,4657.3420,N,00726.2687,E,1,0417,12,,,,,,,,,9.5,9.0,2.6*39\r\n" "$GPRMC,175254.253,A,4657.3420,N,00726.26$GPGGA,175255.253,4657.3421,N,00726.2688,E,1,04,9.0,568.4,M,48.0,M,0.0,0000*7A\r\n" "$GPGSA,A,,E,0.16,151.85,230507,,*09\r\n" }; #endif /*************************************************************************/ /* * open the specified serial port for read/write * @return port file descriptor or -1 */ #ifndef EMULATE static int openPort(const char *tty, int baud) { int status; int fd; struct termios newtio; /* open the tty */ fd = open(tty, O_RDWR | O_NOCTTY); if (fd < 0) { error("openPort: error open"); return fd; } /* flush serial port */ status = tcflush(fd, TCIFLUSH); if (status < 0) { error("openPort: error tcflush"); close(fd); return -1; } /* get current terminal state */ tcgetattr(fd, &newtio); /* set to raw terminal type */ newtio.c_cflag = baud | CS8 | CLOCAL | CREAD; newtio.c_iflag = IGNBRK | IGNPAR; newtio.c_oflag = 0; /* control parameters */ newtio.c_cc[VMIN] = 1; /* block for at least one charater */ /* set its new attrigutes */ status = tcsetattr(fd, TCSANOW, &newtio); if (status < 0) { //error("tcsetattr() failed: %s", strerror(errno)); error("tcsetattr() failed: __ERRNO removed due lazy coder"); close(fd); fd = -1; return fd; } return fd; } #endif /** called when a gpgga message is received and parsed */ static void gpgga_callout( __attribute__ ((unused)) nmeap_context_t * context, void *data, __attribute__ ((unused)) void *user_data) { nmeap_gga_t *gga = (nmeap_gga_t *) data; altitude = gga->altitude; satellites = gga->satellites; quality = gga->quality; gpsTime = gga->time; if (debug == 1) debug("gps:debug: get gga callout\n"); } //search a buffer for a string (forwards) int strLastOcc(char *theBuffer, char searchChar, int size) { int i, ret; ret = -1; for (i = size; i >= 0; i--) { if (theBuffer[i] == searchChar) { ret = i; break; } } return ret; } //search a buffer for a string (backwards) int strFirstOcc(char *theBuffer, char searchChar, int size) { int i, ret; ret = -1; for (i = 0; i < size; i++) { if (theBuffer[i] == searchChar) { ret = i; break; } } return ret; } /** called when a gprmc message is received and parsed */ static void gprmc_callout( __attribute__ ((unused)) nmeap_context_t * context, void *data, __attribute__ ((unused)) void *user_data) { nmeap_rmc_t *rmc = (nmeap_rmc_t *) data; speed = rmc->speed; gpsStatus = rmc->warn; gpsTime = rmc->time; gpsDate = rmc->date; if (debug == 1) debug("gps:debug: get rmc callout\n"); } static int prepare_gps_parser() { int status; char *port = "/dev/usb/tts/1"; char *test; int speed = 0; // 0 = default 4800 baud, 1 is 9600 baud if ((test = getenv("GPS_PORT"))) { /* define your port via env variable */ port = test; } if ((test = getenv("GPS_9600"))) { /* define your port via env variable */ speed = 1; } /* --------------------------------------- */ /* open the serial port device */ /* using default 4800 baud for most GPS */ /* --------------------------------------- */ #ifndef EMULATE if (speed == 0) fd_g = openPort(port, B4800); else fd_g = openPort(port, B9600); if (fd_g < 0) { /* open failed */ error("GPS PLUGIN, Error: openPort %d", fd_g); return fd_g; } #endif /* --------------------------------------- */ /*STEP 2 : initialize the nmea context */ /* --------------------------------------- */ status = nmeap_init(&nmea, (void *) &user_data); if (status != 0) { error("GPS PLUGIN, Error: nmeap_init %d", status); exit(1); } /* --------------------------------------- */ /*STEP 3 : add standard GPGGA parser */ /* -------------------------------------- */ status = nmeap_addParser(&nmea, "GPGGA", nmeap_gpgga, gpgga_callout, &gga); if (status != 0) { error("GPS PLUGIN, Error: nmeap_add GPGGA parser, error:%d", status); return -1; } /* --------------------------------------- */ /*STEP 4 : add standard GPRMC parser */ /* -------------------------------------- */ /* status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,gprmc_callout,&rmc); */ status = nmeap_addParser(&nmea, "GPRMC", nmeap_gprmc, gprmc_callout, &rmc); if (status != 0) { error("GPS PLUGIN, Error: nmeap_add GPRMC parser, error:%d", status); return -1; } return fd_g; } static void parse(RESULT * result, RESULT * theOptions, RESULT * displayOptions) { int rem; int offset; int status; int len; long options; long dispOptions; char buffer[BUFFER_SIZE]; char bufferTmp[BUFFER_SIZE]; int validStart, validEnd; options = R2N(theOptions); dispOptions = R2N(displayOptions); //error("options: %x\n",options); if (dispOptions & OPTION_DEBUG) debug = 1; if ((dispOptions & OPTION_GET_BUFFERDATA) == 0) { /* ---------------------------------------- */ /* STEP 6 : get a buffer of input */ /* --------------------------------------- */ memset(buffer, 0, BUFFER_SIZE); if (fndStr > BUFFER_SIZE) fndStr = 0; //copy unfinished nmea strings back if (fndStr > 0) { memcpy(buffer, backBuffer, fndStr); } #ifdef EMULATE memcpy(&buffer[fndStr], &test_vector[emu_read_ofs], BUFFER_SIZE - fndStr); len = rem = EMU_BUFFER_READ_SIZE; emu_read_ofs += EMU_BUFFER_READ_SIZE; if (emu_read_ofs > (sizeof(test_vector) - BUFFER_SIZE)) { emu_read_ofs = 0; memset(buffer, 0, BUFFER_SIZE); } #else len = rem = read(fd_g, buffer, BUFFER_SIZE - fndStr); if (len <= 0) { error("GPS Plugin, Error read from port, try using the GPS_PORT env variable (export GPS_PORT=/dev/mydev)"); //break; } if (debug == 1) debug("gps:debug: read %d bytes\n", len); #endif if (dispOptions & OPTION_RAW_NMEA) printf("\n__[%s]", buffer + '\0'); /* ---------------------------------------------- */ /* STEP 7 : process input until buffer is used up */ /* ---------------------------------------------- */ validStart = strFirstOcc(buffer, '$', len); validEnd = strLastOcc(buffer, '\n', len); if (validStart >= 0 && validEnd > 0 && validStart < validEnd) { //valid string found memcpy(bufferTmp, buffer, sizeof(buffer)); //save buffer memset(backBuffer, 0, sizeof(backBuffer)); //clear backup buffer memcpy(backBuffer, buffer + validEnd, len - validEnd); // save incomplete nmea string memset(buffer, 0, sizeof(buffer)); //clean buffer memcpy(buffer, bufferTmp + validStart, validEnd - validStart + 1); //copy valid name string fndStr = len - validEnd + validStart; //save the size of the buffer } else { //no valid nmea string found fndStr = 0; memset(buffer, 0, sizeof(buffer)); memset(backBuffer, 0, sizeof(backBuffer)); } offset = 0; if (debug == 1) debug("backBuffer: %s\n", backBuffer); //the nmeap_parseBuffer function needs whole nmea strings, combined string will NOT work! validStart = strFirstOcc(buffer, '$', len); validEnd = strFirstOcc(buffer, '\n', len); while (validStart >= 0 && validEnd > 0 && validStart < validEnd) { memset(bufferTmp, 0, sizeof(bufferTmp)); //empty temp buffer memcpy(bufferTmp, buffer + offset + validStart, validEnd - validStart + 1); //fill temp buffer if (debug == 1) debug("submit: %s\n", bufferTmp); rem = len - offset; status = nmeap_parseBuffer(&nmea, (const char *) &bufferTmp, &rem); //parse it if (status == -1) { errCounter++; error("parser error occured! (cnt: %i)\n", errCounter); } else if (status == 0) { incomplCounter++; } else if (status > 0) msgCounter++; offset += validEnd - validStart + 1; //update offset validStart = strFirstOcc(buffer + offset, '$', len - offset); //find next sentence validEnd = strFirstOcc(buffer + offset, '\n', len - offset); } /* while (rem > 0) { status = nmeap_parseBuffer(&nmea, &buffer[offset], &rem); debug("\nGPS::debug: remaining: %d bytes\n",rem); offset += (len - rem); }*/ } // end of OPTION get bufferdata /* --------------------------------------- */ /* DISPLAY stuff comes here... */ /* --------------------------------------- */ char *value = " "; char outputStr[80]; memset(outputStr, 0, 80); if (options & SHOW_ALTITUDE) { if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%.0f ", outputStr, altitude); else sprintf(outputStr, "%salt:%.0f ", outputStr, altitude); } if (options & SHOW_SPEED) { float knotsConvert = 1.852f; //default speed display=km/h if (dispOptions & OPTION_SPEED_IN_KNOTS) knotsConvert = 1.0f; //use knots if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%.0f ", outputStr, speed * knotsConvert); else sprintf(outputStr, "%sspd:%.0f ", outputStr, speed * knotsConvert); } if (options & SHOW_COURSE) { char courses[8][3] = { "N ", "NO", "O ", "SO", "S ", "SW", "W ", "NW" }; float degrees[8] = { 22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f }; int selectedDegree = 0; int n; for (n = 0; n < 8; n++) { if (course < degrees[n]) { selectedDegree = n; break; } } if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%s ", outputStr, courses[selectedDegree]); else sprintf(outputStr, "%sdir:%s ", outputStr, courses[selectedDegree]); } if (options & SHOW_SATELLITES) { if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%d ", outputStr, satellites); else sprintf(outputStr, "%ssat:%d ", outputStr, satellites); } if (options & SHOW_QUALITY) { if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%d ", outputStr, quality); else sprintf(outputStr, "%squa:%d ", outputStr, quality); } if (options & SHOW_STATUS) { if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%c ", outputStr, gpsStatus); else sprintf(outputStr, "%ssta:%c ", outputStr, gpsStatus); } if (options & SHOW_TIME_UTC) { char digitizer[9]; //01:34:67 sprintf(digitizer, "%.6ld", gpsTime); //<012345> digitizer[7] = digitizer[5]; digitizer[6] = digitizer[4]; digitizer[4] = digitizer[3]; digitizer[3] = digitizer[2]; digitizer[2] = ':'; digitizer[5] = ':'; digitizer[8] = '\0'; if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%s ", outputStr, digitizer); else sprintf(outputStr, "%sutc:%s ", outputStr, digitizer); } if (options & SHOW_DATE) { char digitizer[9]; //01:34:67 sprintf(digitizer, "%.6ld", gpsDate); //<012345> digitizer[7] = digitizer[5]; digitizer[6] = digitizer[4]; digitizer[4] = digitizer[3]; digitizer[3] = digitizer[2]; digitizer[2] = '/'; digitizer[5] = '/'; digitizer[8] = '\0'; if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%s ", outputStr, digitizer); else sprintf(outputStr, "%sdat:%s ", outputStr, digitizer); } if (dispOptions & SHOW_NMEA_STATUS) { if (dispOptions & OPTION_NO_PREFIX) sprintf(outputStr, "%s%04d/%04d/%04d ", outputStr, msgCounter, errCounter, incomplCounter); else sprintf(outputStr, "%sOK:%03d/Er:%03d/In:%03d ", outputStr, msgCounter, errCounter, incomplCounter); } if (options == 0 && dispOptions == 0) { //error, no parameter defined! error("gps::parse() ERROR, no parameter specified!"); value = strdup("GPS ARG ERR"); } else { value = strdup(outputStr); } SetResult(&result, R_STRING, value); free(value); } /* plugin initialization */ /* MUST NOT be declared 'static'! */ int plugin_init_gps(void) { info("%s: v%s", Name, "0.2"); prepare_gps_parser(); /* register all our cool functions */ /* the second parameter is the number of arguments */ /* -1 stands for variable argument list */ AddFunction("gps::parse", 2, parse); return 0; } void plugin_exit_gps(void) { info("%s: shutting down plugin.", Name); #ifndef EMULATE close(fd_g); #endif }