This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| sdk:gps2serial [2015/05/15 13:13] – created juraschek | sdk:gps2serial [2020/03/25 12:21] (current) – fachet | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ===== Script Summary | ===== Script Summary | ||
| - | This Script connects to the GPS server | + | This Script connects to the GPS server and forwards the data to the first serial interface. |
| - | + | GPS must be enabled and in RAW mode. | |
| - | The default serial | + | The default serial |
| + | Please use if possible a higher data rate e.g. 115200. | ||
| ===== Pre Requierments ===== | ===== Pre Requierments ===== | ||
| Line 13: | Line 14: | ||
| To use this script you need to enable the GNSS Interface on the Router to your needs. | To use this script you need to enable the GNSS Interface on the Router to your needs. | ||
| + | {{ : | ||
| Also assign the serial interface to the SDK | Also assign the serial interface to the SDK | ||
| + | |||
| + | {{ : | ||
| Line 22: | Line 25: | ||
| Detailed step by step instructions how to install a sdk script can be found [[sdk: | Detailed step by step instructions how to install a sdk script can be found [[sdk: | ||
| - | Please combine this script with the **" | + | Please combine this script with the **" |
| - | + | ||
| - | This script does not need any configuration, | + | |
| - | + | ||
| - | <code c> | + | |
| - | + | ||
| - | /* Serial Baud Rate 9600, 19200, 38400, 57600, 115200 */ | + | |
| - | SER_SPEED=115200; | + | |
| - | /* number of data bits (5, 6, 7, 8) */ | + | |
| - | SER_DATABIT=8; | + | |
| - | /* number of stop bits (1, 2) */ | + | |
| - | SER_STOPBIT=1; | + | |
| - | /* parity (0=no parity, 1=odd parity, 2=even parity) */ | + | |
| - | SER_PARITY=0; | + | |
| - | /* flow control (0=none, 1=xon/xoff, 2=hardware) */ | + | |
| - | SER_FLOW=0; | + | |
| - | /* name of the Serial Interface (Only changed if your device has more then one serial Interface (NB3710) */ | + | |
| - | DEV = " | + | |
| - | + | ||
| - | + | ||
| - | </ | + | |
| - | + | ||
| - | ===== Testing ====== | + | |
| - | + | ||
| - | To be sure the script is running you can take a look on the [[http:// | + | |
| - | <code bash> | + | |
| - | Apr 23 00:53:41 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:53:42 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:53:42 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:53:42 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:53:42 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:53:42 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:54:08 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:54:09 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:54:09 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:54:09 NB2700 user.info sdkhost[2283]: | + | |
| - | Apr 23 00:54:09 NB2700 user.info sdkhost[2283]: | + | |
| - | + | ||
| - | </ | + | |
| ===== The Script ===== | ===== The Script ===== | ||
| Line 66: | Line 31: | ||
| <code c gps-to-serial.are> | <code c gps-to-serial.are> | ||
| - | |||
| - | |||
| - | /* DESC: This script sends the local GPS NMEA stream (incl. serial/ | ||
| - | * Copyright (C) 2013-2015 NetModule AG, Switzerland | ||
| - | */ | ||
| - | |||
| /* Options to configure by user*/ | /* Options to configure by user*/ | ||
| - | /* Serial Baud Rate 9600, 19200, 38400, 57600, 115200 */ | + | SER_SPEED = 4800; /* Serial Baud Rate 4800, 9600, 19200, 38400, 57600, 115200 */ |
| - | SER_SPEED=115200; | + | SER_DATABIT |
| - | /* number of data bits (5, 6, 7, 8) */ | + | SER_STOPBIT |
| - | SER_DATABIT=8; | + | SER_PARITY |
| - | /* number of stop bits (1, 2) */ | + | SER_FLOW |
| - | SER_STOPBIT=1; | + | DEV = " |
| - | /* parity (0=no parity, 1=odd parity, 2=even parity) */ | + | |
| - | SER_PARITY=0; | + | /* GPS Deamon Parameters */ |
| - | /* flow control (0=none, 1=xon/xoff, 2=hardware) */ | + | HOST = "127.0.0.1"; /* local host */ |
| - | SER_FLOW=0; | + | PORT = (int) nb_config_get(" |
| - | /* name of the Serial Interface | + | |
| - | DEV = "SERIAL1"; | + | void usage() { |
| - | + | nb_syslog(" | |
| - | + | ||
| - | + | ||
| - | void usage() | + | |
| - | { | + | |
| - | nb_syslog(" | + | |
| exit(1); | exit(1); | ||
| } | } | ||
| - | + | ||
| int start_serial() { | int start_serial() { | ||
| - | + | if (nb_config_get(" | |
| - | /* check serial port config */ | + | nb_syslog(" |
| - | status = nb_config_get(" | + | |
| - | if (status | + | |
| - | nb_syslog(" | + | |
| - | | + | |
| } | } | ||
| - | + | | |
| - | | + | |
| - | rc = nb_serial_setattr(DEV, | + | nb_syslog(" |
| - | if (rc != 0) { | + | |
| - | nb_syslog(" | + | |
| return -1; | return -1; | ||
| } | } | ||
| - | + | | |
| - | | + | if ((fd = nb_serial_open(DEV)) |
| - | fd = nb_serial_open(DEV); | + | nb_syslog(" |
| - | if (fd < 0) { | + | |
| return -1; | return -1; | ||
| } | } | ||
| - | |||
| return fd; | return fd; | ||
| } | } | ||
| - | + | ||
| - | int connect_gpsd () | + | int connect_gpsd() |
| { | { | ||
| - | | + | |
| - | | + | nb_syslog(" |
| + | | ||
| + | } | ||
| + | while (1) { | ||
| sock = socket(AF_INET, | sock = socket(AF_INET, | ||
| - | if (sock < 0) { | + | if (sock < 0) |
| - | nb_syslog(" | + | nb_syslog(" |
| - | continue; | + | |
| - | } | + | nb_syslog(" |
| - | nb_syslog(" | + | |
| - | if (connect(sock, | + | |
| - | nb_syslog(" | + | |
| close(sock); | close(sock); | ||
| - | continue; | + | } else { |
| + | nb_syslog(" | ||
| + | return sock; | ||
| } | } | ||
| - | nb_syslog(" | + | sleep(10); |
| - | if (send(sock, " | + | |
| - | nb_syslog(" | + | |
| - | close(sock); | + | |
| - | continue; | + | |
| - | } | + | |
| - | + | ||
| - | nb_syslog(" | + | |
| - | return sock; | + | |
| } | } | ||
| - | + | /* no return | |
| - | | + | |
| } | } | ||
| - | + | ||
| - | + | ||
| - | SERVER = trim((string) argv[1]); | + | |
| - | PORT = (int) argv[2]; | + | |
| - | + | ||
| - | SERIAL = struct_get(nb_status(" | + | |
| - | if (SERIAL == "" | + | |
| - | nb_syslog(" | + | |
| - | exit(1); | + | |
| - | } | + | |
| nb_syslog(" | nb_syslog(" | ||
| - | serial_fd = start_serial(); | + | if ((serial_fd = start_serial()) < 0 ) { |
| - | if (serial_fd | + | nb_syslog(" |
| - | nb_syslog(" | + | exit(4); |
| - | exit(1); | + | |
| } | } | ||
| + | // printf(" | ||
| gpsd = connect_gpsd(); | gpsd = connect_gpsd(); | ||
| - | if (gpsd < 0) { | ||
| - | nb_syslog(" | ||
| - | exit(1); | ||
| - | } | ||
| - | |||
| - | /* process NMEA stream */ | ||
| - | nb_syslog(" | ||
| + | // printf(" | ||
| while (1) { | while (1) { | ||
| - | /* wait for socket | + | // printf(" |
| - | rv = select(gpsd, | + | |
| - | if (rv > 0) { | + | // printf(" |
| - | data = recv(gpsd); | + | |
| - | len = strlen(data); | + | } |
| - | | + | if (rv < 0 || ( data = recv(gpsd)) == "" |
| - | nb_syslog(" | + | nb_syslog(" |
| - | len = -1; | + | close(gpsd); |
| - | } else { | + | |
| - | /* nothing received | + | exit(5); /* can't connect |
| continue; | continue; | ||
| - | } | ||
| - | if (len <= 0) { | ||
| - | nb_syslog(" | ||
| - | close(gpsd); | ||
| - | gpsd = connect_gpsd(); | ||
| - | if (gpsd < 0) { | ||
| - | exit(1); | ||
| - | } | ||
| - | } else { | ||
| - | str = strcat(" | ||
| - | chars = explode(str); | ||
| - | |||
| - | checksum = 0; | ||
| - | for (i = 0; i < length(chars); | ||
| - | c = ord(chars[i]); | ||
| - | checksum ^= c; | ||
| - | } | ||
| - | sentence = sprintf(" | ||
| - | data = strcat(data, | ||
| - | len = strlen(data); | ||
| - | nb_syslog(" | ||
| - | if (len > 0) { | ||
| - | sent = write(serial_fd, | ||
| - | if (sent != len) { | ||
| - | nb_syslog(" | ||
| - | } | ||
| - | } | ||
| } | } | ||
| - | + | len = strlen(data); | |
| - | | + | // printf(" |
| + | | ||
| + | | ||
| } | } | ||
| + | |||
| close(gpsd); | close(gpsd); | ||
| close(serial_fd); | close(serial_fd); | ||
| - | + | exit(6); | |
| - | exit(0); | + | |
| - | + | ||
| </ | </ | ||