View Single Post
  #12   Report Post  
posted to rec.boats.electronics
Paul
 
Posts: n/a
Default how to read AIS data from encapsulated NMEA VDO sentence


wrote in message
oups.com...

Paul wrote:
wrote in message
oups.com...
Actually, I re-read what I posted and it didn't really make sense.

1. Start with the array of ascii characters
2. Convert to the 6 bit binary value.
3. Convert this byte array to a 6 bit bitstream.
4. Then just pull out the bits yuo want using the various bit
operators. I tried to use a bit-field, but it didn't seem to work in
Windows.

As I said, it all works until I get to character arrays (call sign
etc)


Here is a portion of the code i wrote to handle message type 5 (I'm only
handling the "Ship Static and Voyage Related Data
" variant for now). My comments follow the code. Pay attention to my
function H6StrToAsc, and how I manipulate the ascii.


I'll assume Paul's code is right He's skipping the intermediate step
which may be where the confusion lies. There are several layers of
things happening here.

0. Bits over the air: 9600bps GMSK data.
1. Demodulated bitstream, eg. 168 bits for a message 1.
2. Actual message content like Message ID, MMSI, Ship Name.
3. Serial output of bitstream using 6-bit encoding.

The data you see in the VDM sentence is a 6-bit encoded representation
of the raw bitstream, first bit on the left, last bit on the right (as
God intended things!).

To get the ship name you need to either skip ahead like Paul did, or
convert the 6-bit back to its bitstream. Then you grab the bits in the
name position and apply the m.1371 ASCII encoding rules to those bits.
BUT! That conversion is DIFFERENT from the 6-bit encode/decode. That is
probably what was tripping you up.

.cp


I hereby give you a full money-back guarantee that my code is correct. At
least it seems to usually kind of work. The only trouble I've seen is that
I get a spurious (or incorrectly encoded?) rate-of-turn value sometimes,
positive or negative full-scale, if I recall correctly. I haven't posted
that code, though.

As for the intermediate step of converting to a serial bitstream, there is
certainly nothing wrong with doing so, and it may indeed simplify some
operations. I found that with the lack of easy bit-field operators in
Visual Basic, it was just as simple to use the VDM message character string
directly. All the data is there, and I found no good reason to do an
additional conversion. If I were dong this in c, I probably would have gone
to the bitstream. And yes, the ASCII conversion is different than the 6-bit
encode/decode, which is why I directed the original poster to the H6StrToAsc
function in my code.

I was about to ask for help with my ROT problem, and in researching my
sources I just found a later spec than I had been using which shows that
+/-127 values have been taken over to indicate a heading-derived ROT, rather
than a turn-indicator-derived ROT (which uses the values between -126 and
+126). Problem solved! Now, I guarantee double your money back!

Regards,
Paul