This shows you the differences between two versions of the page.
| sdk:scripts:gps-upd-client-compat [2015/05/05 15:04] – external edit 127.0.0.1 | sdk:scripts:gps-upd-client-compat [2016/06/29 13:41] (current) – removed juraschek | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== SDK Script gps-upd-client-compat.are ====== | ||
| - | <code c gps-upd-client-compat.are> | ||
| - | /* DESC: This script sends the local GPS NMEA stream to a remote UDP server (incl. device identity). | ||
| - | * Copyright (C) 2013 NetModule AG, Switzerland | ||
| - | */ | ||
| - | |||
| - | void usage() | ||
| - | { | ||
| - | nb_syslog(" | ||
| - | exit(1); | ||
| - | } | ||
| - | |||
| - | if (argc < 2) { | ||
| - | usage(); | ||
| - | } | ||
| - | |||
| - | SERVER = trim((string) argv[1]); | ||
| - | PORT = (int) argv[2]; | ||
| - | |||
| - | /* connect to gpsd */ | ||
| - | gpsd = socket(AF_INET, | ||
| - | if (gpsd < 0) { | ||
| - | nb_syslog(" | ||
| - | exit(1); | ||
| - | } | ||
| - | |||
| - | if (connect(gpsd, | ||
| - | nb_syslog(" | ||
| - | close(gpsd); | ||
| - | exit(1); | ||
| - | } | ||
| - | |||
| - | nb_syslog(" | ||
| - | send(gpsd, " | ||
| - | |||
| - | /* open UDP server socket */ | ||
| - | server = socket(AF_INET, | ||
| - | if (server < 0) { | ||
| - | nb_syslog(" | ||
| - | close(gpsd); | ||
| - | exit(1); | ||
| - | } | ||
| - | |||
| - | /* process NMEA stream */ | ||
| - | nb_syslog(" | ||
| - | |||
| - | while(1) { | ||
| - | /* wait for client socket data */ | ||
| - | rv = select(gpsd, | ||
| - | if (rv == -1) { | ||
| - | nb_syslog(" | ||
| - | break; | ||
| - | } else if (rv == 0) { | ||
| - | / | ||
| - | continue; | ||
| - | } | ||
| - | data = recv(gpsd); | ||
| - | status = nb_status(" | ||
| - | serial = struct_get(status, | ||
| - | sentence = strcat(" | ||
| - | sentenceLength = strlen(sentence); | ||
| - | sentenceArray = explode(sentence); | ||
| - | checksum = 0; | ||
| - | for (i = 0; i < sentenceLength; | ||
| - | currentChar = ord(sentenceArray[i]); | ||
| - | checksum ^= currentChar; | ||
| - | } | ||
| - | |||
| - | checksum = sprintf(" | ||
| - | nmsentence = strcat(" | ||
| - | data = strcat(data, | ||
| - | |||
| - | len = strlen(data); | ||
| - | if (len <= 0) continue; | ||
| - | |||
| - | sent = sendto(server, | ||
| - | if (sent != len) { | ||
| - | nb_syslog(" | ||
| - | } | ||
| - | } | ||
| - | |||
| - | close(gpsd); | ||
| - | close(server); | ||
| - | |||
| - | exit(0); | ||
| - | </ | ||