Skip to content

Commit

Permalink
Prepare for publishing on NPM.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Runte committed Feb 18, 2017
1 parent 8e263d9 commit 3207476
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
# AisParser
A Parser for NMEA0183 AIS messages.
The parser is written using [flow](https://flowtype.org/). It can be run from the src directory with babel-node or in the transpiled version from the index.js file or the lib directory. The code should get transpiled into the lib diretory at install (I am working on that currently). Otherwise it can be transpiled calling

## Installation
The parser is written using [flow](https://flowtype.org/). It can be run from the src directory with babel-node or in the transpiled version from the index.js file or the lib directory. If you are using the NPM package you do not have to worry about transpiling, it has been done for you allready. If you are using the github package you will need to take care of transpiling by calling the following commands:
```
cd <package-dir>
npm install
npm run-script prepublish
```
The modules approach to parsing AIS messages is 'on demand'. A message is merely stored and only parsed partially when data is requested. For instance when the aisType is read only one byte of the message is actually translated and parsed. So it makes sense to only read the values that are really needed. Although some common values are cached in the result object once they have been requested, most values are not - meaning that they are parsed every time they are requested.

## How it works
The modules approach to parsing AIS messages is 'on demand'. A message is merely stored and some basic checks are done by the **parse** function. When data is requested only as much of the message is parsed as is needed to decode the requested data. For instance when the aisType is read only one byte of the message is actually translated and parsed. So it makes sense to only read the values that are really needed. Although some common values are cached in the result object once they have been requested, most values are not - meaning that they are parsed every time they are requested.

The Module parses AIS messages of types 1,2,3.4.5,18,19,21 and 24. These are the common message types, most other types are related to inter vessel or vessel to shore communication.

The author takes no responsability for the correctness of returned values. Please always keep a good watch and an eye on the traffic while commanding a vessel.
Although the parser has been thoroughly checked against AIS logs from AISHub and AIS recordings from the Panama Canal, the author takes no responsibility for the correctness of returned values. Please always keep a good watch and an eye on the traffic while commanding a vessel.

The result object obtained from the parse function has a variable **supportedValues** which returns an array of valid field names that can be retrieved from the result object. The list is specific to the message type, it list values that may be present in the message. Retrieving these values may still return NaN or '' values, if value is set to empty or undefined in the actual message.
The result object obtained from the parse function has a variable **supportedValues** which returns an array of valid field names that can be retrieved from the result object. The list is specific to the message type, it lists values that may be present in the message. Retrieving these values may still return NaN or '' values, if the value is set to empty or undefined in the actual message.

The instance variables of the result object are implemented as getter functions: The parsing is done while the instance variables are accessed and they can throw exceptions when parsing fails. This should only happen when badly maformed (too short) messages are being processed. Having the checksum checked should make sure that this does not happen as long as the device producing the messages does not emmit faulty messages. Otherwise use a try catch block around the data retrieval to catch parse exceptions.
The instance variables of the result object are implemented as getter functions: The parsing is done while the instance variables are accessed and they can throw exceptions when parsing fails. This should only happen when maformed (too short) messages are being processed. Having the checksum checked should make sure that this does not happen as long as the device producing the messages does not emmit faulty messages. Otherwise use a try catch block around the data retrieval to catch parse exceptions.

## API

Expand Down
Empty file added lib/.npmignore
Empty file.
39 changes: 27 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
{
"name": "AisParser",
"name": "aisparser",
"version": "0.0.1",
"private": false,
"description" : "parser for NMEA0183 AIS messages",
"keywords" : "parser AIS NMEA NMEA0183",
"repository" : "https://github.com/samothx/AisParser.git",
"bugs" : {
"url" : "https://github.com/samothx/AisParser/issues",
"email" : "[email protected]" },
"description": "parser for NMEA0183 AIS messages",
"keywords": [
"parser AIS NMEA NMEA0183"
],
"repository": {
"type": "git",
"url": "git+https://github.com/samothx/AisParser.git"
},
"bugs": {
"url": "https://github.com/samothx/AisParser/issues",
"email": "[email protected]"
},
"license": "Apache-2.0",
"main" : "index.js",
"engines" : {"node" : ">=6.4.0"},
"main": "index.js",
"engines": {
"node": ">=6.4.0"
},
"scripts": {
"prepublish" : "cd src;babel -d ../lib *.js;cd ..",
"prepublish": "cd src;babel -d ../lib *.js;cd ..",
"flow": "flow; test $? -eq 0 -o $? -eq 2"
},
"devDependencies": {
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-es2015": "^6.22.0",
"flow-bin": "^0.38.0"
}
}
},
"homepage": "https://github.com/samothx/AisParser#readme",
"directories": {
"doc": "docs",
"test": "test"
},
"dependencies": {},
"author": "Thomas Runte <[email protected]> (http://www.etnur.net)"
}
2 changes: 1 addition & 1 deletion samples/Sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sentences.forEach(function(sentence) {
console.log('error message: :' + result.errMsg);
break;
case 'INCOMPLETE':
console.log('incomlete message, waiting for more');
console.log('incomplete message, waiting for more');
break;
}
});

0 comments on commit 3207476

Please sign in to comment.