项目作者: mbj4668

项目描述 :
Erlang NMEA 2000 decoder
高级语言: Erlang
项目地址: git://github.com/mbj4668/n2k.git
创建时间: 2019-09-27T08:42:30Z
项目社区:https://github.com/mbj4668/n2k

开源协议:MIT License

下载


NMEA 2000 decoder in Erlang

An NMEA 2000 decoder in Erlang. Decodes the following formats:

  • Yacht Device’s RAW format
  • Yacht Device’s DAT format
  • Yacht Device’s CAN format
  • CANBOAT’s PLAIN format (CSV)

The program bin/n2k can be used from the command line to convert or
pretty print files with NMEA 2000 frames or messages in one of the
supported formats.

The functions n2k_raw:decode_raw/1 and n2k_csv:decode_csv/1 can be
used to decode captured packets into NMEA 2000 frames. The frames can
be decoded into messages by calling n2k:decode_nmea/2.

Build

Handling of PGNs

At build time, src/canboat.xml and any user-defined PGNs XML files are
first compiled into src/pgns.term and then
src/pgns.term is compiled to src/n2k_pgn.erl, which contains code
for decoding NMEA 2000 binary messages into Erlang terms.

Here’s an example of the generated code:

  1. decode(130306,
  2. <<Sid:8/little-unsigned,
  3. WindSpeed:16/little-unsigned,
  4. WindAngle:16/little-unsigned,
  5. _6:5, % reserved
  6. Reference:3/little-unsigned,
  7. _/bitstring>>) ->
  8. {windData,
  9. [{sid,chk_exception2(255,Sid)},
  10. {windSpeed,chk_exception2(65535,WindSpeed)},
  11. {windAngle,chk_exception2(65535,WindAngle)},
  12. {reference,chk_exception1(7,Reference)}]};
  13. %% {int, Resolution, Decimals, Unit}
  14. type_info(windData,windAngle) ->
  15. {int, 0.0001, 4, rad};
  16. type_info(windData,windSpeed) ->
  17. {int, 0.01, 2, 'm/s'};

User-defined PGNs

Custom PGNs (or proprietary PGNs that are not part of canboat’s
XML) are defined in the same XML format as canboat uses.

For some PGNs, we can’t decode with only the canboat.xml definitions,
but we need additional code to perform the decoding. If this is the
case, write an erlang module that implements the behavior
n2k_pgn_callback (see that module for details).

In order to compile the custom PGN definition files, add a file
system-config.mk to the top directory, and define the following
variable:

  1. CUSTOM_DIR = path/to/dir

Place custom PGN definition files and erlang files in this directory.
The custom PGN definition files must be on the form *-pgns.xml.

If some PGN needs an additional erlang module, set CUSTOM_PGN_ERL:

  1. CUSTOM_PGN_ERL = <pgnid>:<erlangmodule>(,<pgnid>:<erlangmodule)*

For example:

  1. CUSTOM_PGN_ERL = garminCustomChannel:x_n2k_garmin

Control the size of the generated code

By default, all manufacturer proprietary PGNs are compiled into
n2k_pgn.erl. By setting the variable MANUFACTURER_CODES in
system-config.mk, this behaviour can be tweaked. The variable must
be on the form all | none | <integer>,<integer>,.... For example,
to generate code for Airmar and Garmin only:

  1. MANUFACTURER_CODES = 135,229