This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sdk:gps2serial [2020/03/25 10:02] – fachet | 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 |
| + | GPS must be enabled and in RAW mode. | ||
| The default serial parameters for GPS are 4800 8N1 (8 databit, no parity, 1 stop bit, no flow controll). This parameter can be configured at the begining of the script. | The default serial parameters for GPS are 4800 8N1 (8 databit, no parity, 1 stop bit, no flow controll). This parameter can be configured at the begining of the script. | ||
| Please use if possible a higher data rate e.g. 115200. | Please use if possible a higher data rate e.g. 115200. | ||
| Line 25: | 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 4800, 9600, 19200, 38400, 57600, 115200 */ | + | |
| - | SER_SPEED=4800; | + | |
| - | /* 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 69: | 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*/ | ||
| SER_SPEED = 4800; /* Serial Baud Rate 4800, 9600, 19200, 38400, 57600, 115200 */ | SER_SPEED = 4800; /* Serial Baud Rate 4800, 9600, 19200, 38400, 57600, 115200 */ | ||
| Line 82: | Line 38: | ||
| SER_FLOW = 0; | SER_FLOW = 0; | ||
| DEV = " | DEV = " | ||
| - | | + | |
| /* GPS Deamon Parameters */ | /* GPS Deamon Parameters */ | ||
| HOST = " | HOST = " | ||
| - | PORT = nb_config_get(" | + | PORT = (int) nb_config_get(" |
| - | + | ||
| - | void usage() | + | void usage() { |
| - | { | + | nb_syslog(" |
| - | nb_syslog(" | + | |
| exit(1); | exit(1); | ||
| } | } | ||
| + | |||
| int start_serial() { | int start_serial() { | ||
| - | | + | if (nb_config_get(" |
| + | nb_syslog(" | ||
| + | exit(2); | ||
| + | } | ||
| + | | ||
| if ((rc = nb_serial_setattr(DEV, | if ((rc = nb_serial_setattr(DEV, | ||
| - | nb_syslog(" | + | nb_syslog(" |
| return -1; | return -1; | ||
| } | } | ||
| - | /* open serial port */ | + | // nb_syslog(" |
| if ((fd = nb_serial_open(DEV)) < 0) { | if ((fd = nb_serial_open(DEV)) < 0) { | ||
| - | nb_syslog(" | + | nb_syslog(" |
| return -1; | return -1; | ||
| + | } | ||
| return fd; | return fd; | ||
| } | } | ||
| - | + | ||
| - | int connect_gpsd() /* tries infinetively to connect to gpsd - socket returned */ | + | int connect_gpsd() |
| { | { | ||
| + | if (nb_config_get(" | ||
| + | nb_syslog(" | ||
| + | exit(3); | ||
| + | } | ||
| while (1) { | while (1) { | ||
| sock = socket(AF_INET, | sock = socket(AF_INET, | ||
| if (sock < 0) | if (sock < 0) | ||
| - | nb_syslog(" | + | nb_syslog(" |
| else if (connect(sock, | else if (connect(sock, | ||
| - | nb_syslog(" | + | nb_syslog(" |
| close(sock); | close(sock); | ||
| } else { | } else { | ||
| - | nb_syslog(" | + | nb_syslog(" |
| return sock; | return sock; | ||
| } | } | ||
| Line 123: | Line 87: | ||
| /* no return */ | /* no return */ | ||
| } | } | ||
| - | + | ||
| + | |||
| 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(); | ||
| - | nb_syslog(" | ||
| + | // printf(" | ||
| while (1) { | while (1) { | ||
| - | /* wait for socket | + | // printf(" |
| - | if ((rv = select(gpsd, | + | if ((rv = select(gpsd, |
| + | // printf(" | ||
| continue; | continue; | ||
| - | | + | } |
| - | nb_syslog(" | + | |
| + | nb_syslog(" | ||
| + | close(gpsd); | ||
| if ((gpsd = connect_gpsd()) < 0) | if ((gpsd = connect_gpsd()) < 0) | ||
| - | exit(3); /* can't connect */ | + | exit(5); /* can't connect */ |
| continue; | continue; | ||
| } | } | ||
| - | data = recv(gpsd); | ||
| len = strlen(data); | len = strlen(data); | ||
| + | // printf(" | ||
| if (write(serial_fd, | if (write(serial_fd, | ||
| - | | + | |
| } | } | ||
| + | |||
| close(gpsd); | close(gpsd); | ||
| close(serial_fd); | close(serial_fd); | ||
| - | exit(4); | + | exit(6); |
| </ | </ | ||