Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
sdk:gps2serial [2020/03/25 12:08]
fachet [Script Summary]
sdk:gps2serial [2020/03/25 12:20]
fachet
Line 25: Line 25:
 Detailed step by step instructions how to install a sdk script can be found [[sdk:​testing-the-sms-send-script|on this wiki page]] Detailed step by step instructions how to install a sdk script can be found [[sdk:​testing-the-sms-send-script|on this wiki page]]
  
-Please combine this script with the **"​system-startup"​ trigger** to a job +Please combine this script with the **"​system-startup"​ trigger** to get a job.
- +
-This script does not need any configuration,​ but you can define the serial parameter to your needs: +
- +
-<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 = "​SERIAL1";​ +
- +
- +
-</​code>​ +
- +
-===== Testing ====== +
- +
-To be sure the script is running you can take a look on the [[http://​simulator.netmodule.com/​logs.php.html|System Log]] and watch for outputs like:  +
-<code bash> +
-Apr 23 00:53:41 NB2700 user.info sdkhost[2283]:​ testrun: starting serial +
-Apr 23 00:53:42 NB2700 user.info sdkhost[2283]:​ testrun: Connecting to GPS daemon +
-Apr 23 00:53:42 NB2700 user.info sdkhost[2283]:​ testrun: Requesting raw NMEA stream +
-Apr 23 00:53:42 NB2700 user.info sdkhost[2283]:​ testrun: Successfully connected to GPS daemon +
-Apr 23 00:53:42 NB2700 user.info sdkhost[2283]:​ testrun: Processing NMEA data +
-Apr 23 00:53:42 NB2700 user.info sdkhost[2283]:​ testrun: Unable to send message to via Serial +
-Apr 23 00:54:08 NB2700 user.info sdkhost[2283]:​ testrun: starting serial +
-Apr 23 00:54:09 NB2700 user.info sdkhost[2283]:​ testrun: Connecting to GPS daemon +
-Apr 23 00:54:09 NB2700 user.info sdkhost[2283]:​ testrun: Requesting raw NMEA stream +
-Apr 23 00:54:09 NB2700 user.info sdkhost[2283]:​ testrun: Successfully connected to GPS daemon +
-Apr 23 00:54:09 NB2700 user.info sdkhost[2283]:​ testrun: Processing NMEA data +
- +
-</​code>​+
  
 ===== The Script ===== ===== The Script =====
Line 87: Line 49:
    
 int start_serial() { int start_serial() {
 + if (nb_config_get("​serial.0.status"​) != "​2"​) {
 +    nb_syslog("​serial not assinged to SDK\n"​);​
 +        exit(2);
 +    }
     // printf("​set serial attributes\n"​);​     // printf("​set serial attributes\n"​);​
     if ((rc = nb_serial_setattr(DEV,​ SER_SPEED, SER_DATABIT,​ SER_STOPBIT,​ SER_PARITY, SER_FLOW)) != 0) {     if ((rc = nb_serial_setattr(DEV,​ SER_SPEED, SER_DATABIT,​ SER_STOPBIT,​ SER_PARITY, SER_FLOW)) != 0) {
Line 104: Line 70:
     if (nb_config_get("​gpsd.0.status"​) != "​1"​ || nb_config_get("​gpsd.0.cmode"​) != "​1"​) {     if (nb_config_get("​gpsd.0.status"​) != "​1"​ || nb_config_get("​gpsd.0.cmode"​) != "​1"​) {
     nb_syslog("​gpsd not enabled or not in RAW mode\n"​);​     nb_syslog("​gpsd not enabled or not in RAW mode\n"​);​
-        exit(2);+        exit(3);
     }     }
     while (1) {     while (1) {
Line 126: Line 92:
 if ((serial_fd = start_serial()) < 0 ) { if ((serial_fd = start_serial()) < 0 ) {
     nb_syslog("​Could not start serial, exiting\n"​);​     nb_syslog("​Could not start serial, exiting\n"​);​
-    exit(3);+    exit(4);
 } }
 // printf("​connect to gpsd\n"​);​ // printf("​connect to gpsd\n"​);​
Line 140: Line 106:
     if (rv < 0 || ( data = recv(gpsd)) == ""​) {     if (rv < 0 || ( data = recv(gpsd)) == ""​) {
         nb_syslog("​Select or recv failed, re-connecting to GPS daemon\n"​);​         nb_syslog("​Select or recv failed, re-connecting to GPS daemon\n"​);​
 + close(gpsd);​
         if ((gpsd = connect_gpsd()) < 0)         if ((gpsd = connect_gpsd()) < 0)
-            exit(4); /* can't connect */+            exit(5); /* can't connect */
         continue;         continue;
     }     }
Line 152: Line 119:
 close(gpsd);​ close(gpsd);​
 close(serial_fd);​ close(serial_fd);​
-exit(5); +exit(6);
 </​code>​ </​code>​