Cruisers Forum
 


Reply
  This discussion is proudly sponsored by:
Please support our sponsors and let them know you heard about their products on Cruisers Forums. Advertise Here
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 23-07-2012, 04:09   #1
Registered User

Join Date: Jul 2012
Posts: 20
Connecting IP AIS on OSX

I'm getting nmea via the pilot plug on a SAAB R4 AIS. Pilot plug (rs-422) output goes via a serial-to-ethernet server (cable and WiFi).

On Windows it is easy to use a virtual COM driver and then configure OpenCPN to use this COM port for AIS (and AIS Port for GPS).

It is not so easy on OSX because the virtual device created (using socat) is not in the list of devices under the AIS tab. I can enter the name of the device and then go to the GPS tab and select AIS Port... everyting is then fine. But next time OpenCPN is started, the configuration is lost and have to be entered again... it appears as OpenCPN erase configuration thought to be wrong...

It would be really nice if data could be read directly of a serial-to-ethernet server.

Have I overlooked other ways of getting "IP AIS data" into OpenCPN?

Btw. Nice way of showing CPA. On the ECDIS I have tracked targets from the radar. Do you support nmea TTM to show radar aquired targets as well?
baerentp is offline   Reply With Quote
Old 23-07-2012, 06:49   #2
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 7,401
Re: Connecting IP AIS on OSX

baerentp....

You are correct. The AIS data source, if typed in manually, will be lost on restart.

However, there is a back door.

If the AIS data source contains the string "fifo", then it will be retained.

Code:
    /*
     A special test for a user defined FIFO
     To use this method, do the following:
     a.  Create a fifo            $mkfifo /tmp/aisfifo
     b.  netcat into the fifo     $nc {ip} {port} > /tmp/aisfifo
                     sample {ip} {port} could be  nc a.b.c.d 6401 > /tmp/aisfifo
     c.  hand edit opencpn.conf and make AIS data source like this:
          [Settings/AISPort]
          Port=Serial:/tmp/aisfifo

    This also works if you have an ascii ais log
    for which you can simply $cat ais.log > /tmp/aisfifo
    */
    if(m_pPortName->Contains(_T("fifo")))
          goto port_ready;
So, try this:
$mkfifo /tmp/aisfifo
$socat {blah} >/tmp/aisfifo (or nc {blah} > /tmp/aisfifo)

Set the OCPN AIS data source manually to /tmp/aisfifo

This is how I typically do log replays for debugging.

Good Luck
Dave
bdbcat is offline   Reply With Quote
Old 23-07-2012, 11:50   #3
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

Quote:
Originally Posted by bdbcat View Post
baerentp....

You are correct. The AIS data source, if typed in manually, will be lost on restart.

However, there is a back door.

If the AIS data source contains the string "fifo", then it will be retained.

Code:
    /*
     A special test for a user defined FIFO
     To use this method, do the following:
     a.  Create a fifo            $mkfifo /tmp/aisfifo
     b.  netcat into the fifo     $nc {ip} {port} > /tmp/aisfifo
                     sample {ip} {port} could be  nc a.b.c.d 6401 > /tmp/aisfifo
     c.  hand edit opencpn.conf and make AIS data source like this:
          [Settings/AISPort]
          Port=Serial:/tmp/aisfifo

    This also works if you have an ascii ais log
    for which you can simply $cat ais.log > /tmp/aisfifo
    */
    if(m_pPortName->Contains(_T("fifo")))
          goto port_ready;
So, try this:
$mkfifo /tmp/aisfifo
$socat {blah} >/tmp/aisfifo (or nc {blah} > /tmp/aisfifo)

Set the OCPN AIS data source manually to /tmp/aisfifo

This is how I typically do log replays for debugging.

Good Luck
Dave
Goodmorning Dave,

Thanks - that is a help... that is, if it helped :-(

On OSX serial devices are checked by ValidateSerialPortName() and that don't catch the fifo back-door. It will need something like this before the last line (return bPortFound):

if(strstr(pPortSubName, "fifo"))
return true;

If their are no other ways to pipe in IP AIS, I really hope you could make a fix for a future release...

Peter
baerentp is offline   Reply With Quote
Old 23-07-2012, 13:13   #4
mrm
Registered User

Join Date: Feb 2011
Location: Poland, EU
Boat: crew on Bavaria 38 Cruiser
Posts: 654
Re: Connecting IP AIS on OSX

Peter,

some time ago I had a need to replay AIS data to OpenCPN from a text file. At that time I was not aware of this backdoor (yeah, read the Source, Luke) so I wrote a small utility to do just that. The program opens a master/slave pseudoTTY pair and feeds the master with data from a file.

I have no access to Mac environment, so I can not do any testing, but as OS-X kernel has very close ties to BSD, I assume it is POSIX compliant and the code should compile and run. You would have to modify the source slightly, to take input from stdin and remove sleep in main loop, but it should work if my assumption is correct. Anyway, here is the code, hope it will help get you going.

Code:
#define _XOPEN_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char *argv[]) 
{
  int ttymaster, datafile;
  FILE *datafd;
  char *line = NULL;
  size_t len = 0;
  ssize_t read = 0;

  if (argc != 2) {
    printf("missing argument\n");
    printf("usage: %s file\n", *argv);
    exit(0);
  }    

  if ((datafile = open(argv[1], O_RDONLY)) == -1) {
    printf ("failed to open %s\n", argv[1]);
    exit(1);
  }

  if ((ttymaster = posix_openpt(O_RDWR|O_NOCTTY)) == -1) {
    perror("ptty open failed\n");
    exit(1);
  } else {
    printf("name of tty slave is: %s\n", ptsname(ttymaster));
    grantpt(ttymaster);
    unlockpt(ttymaster);
    printf("ttyfeed online\n");
  }

  if ((datafd = fdopen(datafile, "r")) == NULL) {
    close(ttymaster);
    perror("fdopen");
    exit(1);
  }

  printf("configure input as needed and press enter");
  getline(&line, &len, stdin);

  while((read = getline(&line, &len, datafd)) != -1) {
    printf("%zu bytes: %s", read, line);
    write(ttymaster, line, read);
    fsync(ttymaster);
    sleep(1);
  }

  if(line) free(line);

  printf("data feed finished\n");
  close(ttymaster);
  close(datafile);

  return 0;
}
Marius
mrm is offline   Reply With Quote
Old 24-07-2012, 04:57   #5
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

Quote:
Originally Posted by mrm View Post
Peter,

some time ago I had a need to replay AIS data to OpenCPN from a text file. At that time I was not aware of this backdoor (yeah, read the Source, Luke) so I wrote a small utility to do just that. The program opens a master/slave pseudoTTY pair and feeds the master with data from a file.

I have no access to Mac environment, so I can not do any testing, but as OS-X kernel has very close ties to BSD, I assume it is POSIX compliant and the code should compile and run. You would have to modify the source slightly, to take input from stdin and remove sleep in main loop, but it should work if my assumption is correct. Anyway, here is the code, hope it will help get you going.

Code:
#define _XOPEN_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char *argv[]) 
{
  int ttymaster, datafile;
  FILE *datafd;
  char *line = NULL;
  size_t len = 0;
  ssize_t read = 0;

  if (argc != 2) {
    printf("missing argument\n");
    printf("usage: %s file\n", *argv);
    exit(0);
  }    

  if ((datafile = open(argv[1], O_RDONLY)) == -1) {
    printf ("failed to open %s\n", argv[1]);
    exit(1);
  }

  if ((ttymaster = posix_openpt(O_RDWR|O_NOCTTY)) == -1) {
    perror("ptty open failed\n");
    exit(1);
  } else {
    printf("name of tty slave is: %s\n", ptsname(ttymaster));
    grantpt(ttymaster);
    unlockpt(ttymaster);
    printf("ttyfeed online\n");
  }

  if ((datafd = fdopen(datafile, "r")) == NULL) {
    close(ttymaster);
    perror("fdopen");
    exit(1);
  }

  printf("configure input as needed and press enter");
  getline(&line, &len, stdin);

  while((read = getline(&line, &len, datafd)) != -1) {
    printf("%zu bytes: %s", read, line);
    write(ttymaster, line, read);
    fsync(ttymaster);
    sleep(1);
  }

  if(line) free(line);

  printf("data feed finished\n");
  close(ttymaster);
  close(datafile);

  return 0;
}
Marius
Hello Marius,

Thanks - my problem is not so much getting data in as to having OpenCPN remember settings... it's not so fancy you have to make setup-settings on every start of OpenCPN :-(

Peter
baerentp is offline   Reply With Quote
Old 24-07-2012, 05:02   #6
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

Hi Dave,

Actually, it looks like the ValidateSerialPortName() also make life diffecult for us poor ones on OSX... this time in the GPS settings... Setting the port to "AIS Port (Shared)" is also cleaned out by that function on every startup.

I guess this should be classified as a bug... or?


Rgs,
Peter
baerentp is offline   Reply With Quote
Old 24-07-2012, 06:05   #7
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 7,401
Re: Connecting IP AIS on OSX

Peter...

I'd call it a bug, for sure. We have had precious little real-life testing of the Mac platform build, and we are glad to get it from you. Not so glad to see bugs, but that's life.....

Are you able to build from source? If so, I can quick fix this bug for the next Beta and you may have the source now, if you like.

Dave
bdbcat is offline   Reply With Quote
Old 24-07-2012, 06:22   #8
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

Dave,

Sure, if you have some specific need for OSX testing, lets look into that. You are welcome to contact me.

Yes, I can build from source (at least the 3.02... the beta 3.1 does compile but wil not run - problem finding styles in uidata).

Peter
baerentp is offline   Reply With Quote
Old 24-07-2012, 07:29   #9
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 7,401
Re: Connecting IP AIS on OSX

Peter....

OK, lets get your 3.1 build running.

The styles are put into the correct location on install. If you have not ever installed OpenCPN 3.1, then they are not found.

There is a back door, to allow running without installation.

Simply copy the following 4 files to your home directory:

src/bitmaps/styles.xml
src/bitmaps/toolicons*.png

Then 3.1 should run.

Lets take it from there.

Thanks
Dave
bdbcat is offline   Reply With Quote
Old 24-07-2012, 07:42   #10
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

Dave,

That got it working - sort of. I get everything on screen for a second or so and then a segmentation fault 11.

Here is the log:
16:36:04 CEST: 2012-07-24
16:36:04 CEST: -------Starting opencpn-------
16:36:04 CEST: Version 3.1.714 Build 2012-07-14
16:36:04 CEST: MemoryStatus: mem_total: 0 mb, mem_initial: 0 mb
16:36:04 CEST: SData_Locn is /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/SharedSupport/
16:36:04 CEST: Using existing Config_File: /Users/peter/Library/Preferences/opencpn.ini
16:36:04 CEST: Styles loading from /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/SharedSupport/uidata/styles.xml
16:36:04 CEST: No styles found at: /Users/peter/Library/Preferences/opencpn/
16:36:04 CEST: No styles found at: /Users/peter/Library/Preferences/opencpn/.opencpn/
16:36:04 CEST: Setting Viewpoint Lat/Lon 55.9232, 11.825
16:36:04 CEST: Setting Ownship Lat/Lon 55.8672, 12.0709
16:36:04 CEST: System default Language: da_DK
16:36:04 CEST: Opencpn language set to: en_US
16:36:10 CEST: ChartSymbols loaded from /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/SharedSupport/s57data/chartsymbols.xml
16:36:11 CEST: Using s57data in /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/SharedSupport/s57data
16:36:11 CEST: Setting Viewpoint Lat/Lon 55.9232, 11.825
16:36:11 CEST: Setting Ownship Lat/Lon 55.8672, 12.0709
16:36:11 CEST: NMEA Data Source is....NONE
16:36:11 CEST: AIS Data Source is....NONE
16:36:11 CEST: Using WVSChart datafile: /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/SharedSupport/wvsdata/wvs43.dat
16:36:11 CEST: NMEA AutoPilot Port is....None
16:36:11 CEST: PlugInManager searching for PlugIns in location /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/PlugIns
16:36:11 CEST: Directory /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/PlugIns does not exist.
16:36:11 CEST: ChartDB Cache policy: Max open chart limit is 20.
16:36:11 CEST: Loading chart db version: V016
16:36:11 CEST: Chartdb: Chart directory list follows
16:36:11 CEST: Chart directory #0: /Users/peter/Documents/Søkort/CM93
16:36:11 CEST: Chart directory #1: /Users/peter/Documents/Søkort/S57
16:36:11 CEST: GPS Watchdog Timeout is: 6 sec.
16:36:11 CEST: Initializing Chart /Users/peter/Documents/Søkort/S57/DK/DK4IFROF/32/0/DK4IFROF.000
16:36:11 CEST: Initializing Chart /Users/peter/Documents/Søkort/S57/DK/DK2KATGS/24/0/DK2KATGS.000
baerentp is offline   Reply With Quote
Old 24-07-2012, 08:26   #11
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

The error is after map is shown and after the Welcome to version 3.1.714 message.

Starting program: /Users/peter/Kildekode/OpenCPN.beta31/OpenCPN.app/Contents/MacOS/OpenCPN
Reading symbols for shared libraries +++++++++++++++++++++++++++++.. done
Reading symbols for shared libraries ++ done
Reading symbols for shared libraries + done
Reading symbols for shared libraries + done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0xbf7ffffc
0x9522cd89 in _CFRuntimeCreateInstance ()
(gdb)
baerentp is offline   Reply With Quote
Old 24-07-2012, 09:29   #12
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 7,401
Re: Connecting IP AIS on OSX

Peter...

OK, see what you can do with gdb backtrace, etc...

I'll bring up my Hackintosh and give it a try, too.

Dave
bdbcat is offline   Reply With Quote
Old 25-07-2012, 18:46   #13
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 7,401
Re: Connecting IP AIS on OSX

Peter...

OK, we had lots of trouble with 3.1.714 on Mac.
Fixed now, and code pushed to github master.

If you fetch and build the current github master, you should be able to run 3.1.

Then, if you want to use a fifo for AIS data entry, you should try the quick hack you mentioned before:

in bool ValidateSerialPortName(char* pPortName, int iMaxNamestoSearch)

add

Code:
if(strstr(pPortSubName, "fifo"))
        return true;
I'm not going to do this in the github master, since we are in the process of rebuilding the comms stuff as we speak, and the change will bolux up our thinking.

Let me know how this works out for you in the meantime. We will have a much cleaner solution for the 3.2 Release due later this fall.

Thanks
Dave
bdbcat is offline   Reply With Quote
Old 26-07-2012, 12:15   #14
Registered User

Join Date: Jul 2012
Posts: 20
Re: Connecting IP AIS on OSX

Dave,

I pulled the master, compiled it... and it runs!

I agree - dont waste time on that "fifo" thing - I fix it for now and wait for the new revised setup in the next release.

Thanks,
Peter

I have a couple of other issues with OpenCPN giving up life and aborting - you said you wanted some OSX feedback - do you want it on the beta or on the current release? Also, do you have "required info form" for reporting bugs?


Peter
baerentp is offline   Reply With Quote
Old 26-07-2012, 15:24   #15
Marine Service Provider
 
bdbcat's Avatar

Join Date: Mar 2008
Posts: 7,401
Re: Connecting IP AIS on OSX

Peter...
Thanks for the report.

I would very much like to get real detailed feedback regarding OSX issues.
The best, most trackable method is to use our Bug Tracker (Flyspray).
OpenCPN::Tracker All Projects: Tasklist

I think its best to consider the most recent 3.1 Beta, since you can compile and run it locally.

Thanks
Dave
bdbcat is offline   Reply With Quote
Reply

Tags
ais


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Advertise Here


All times are GMT -7. The time now is 09:02.


Google+
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Social Knowledge Networks
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.

ShowCase vBulletin Plugins by Drive Thru Online, Inc.