flight-plan-converter
Advanced tools
Comparing version 0.0.5 to 0.0.6
45
cli.js
'use strict'; | ||
// TODO: write cli | ||
const fs = require( 'fs' ) | ||
const lib = require( './lib' ) | ||
const { formatSuffixes, formatTypes } = lib | ||
if( process.argv.length < 4 ) { | ||
console.error( `usage: ${process.argv[1]} [source] [dest]` ) | ||
process.exit() | ||
} | ||
const ifn = process.argv[ 2 ] | ||
const isuffix = ifn.slice( ( ifn.lastIndexOf( '.' ) - 1 >>> 0 ) + 2 ) | ||
const ikey = Object.keys( formatSuffixes ).find( key => formatSuffixes[ key ] === isuffix ) | ||
const itype = formatTypes[ ikey ] | ||
const ofn = process.argv[ 3 ] | ||
const osuffix = ofn.slice( ( ofn.lastIndexOf( '.' ) - 1 >>> 0 ) + 2 ) | ||
const okey = Object.keys( formatSuffixes ).find( key => formatSuffixes[ key ] === osuffix ) | ||
const otype = formatTypes[ okey ] | ||
if( !itype || !otype ) { | ||
console.error( `unsupported type ${itype} ${otype}` ) | ||
process.exit() | ||
} | ||
const ifs = fs.readFileSync( ifn, 'utf8' ) | ||
fs.writeFileSync( ofn, | ||
// converts parsed/normalized flight plan to specifique format | ||
lib.convert( | ||
// parsed/normalized flight plan | ||
lib.parse( | ||
// raw input flight plan | ||
ifs, | ||
// input format | ||
itype // -> 'ms_fpl' | ||
), | ||
// output format | ||
otype, // lib.formats.XPLANE_FMS // -> 'xplane_fms' | ||
{ fmsVersion: '1100' } | ||
) + '\n', | ||
'utf8' | ||
); | ||
@@ -14,3 +14,3 @@ 'use strict'; | ||
*/ | ||
module.exports = function (flightPlan, format) { | ||
module.exports = function (flightPlan, format, options) { | ||
var converter = converters[format] || null; | ||
@@ -22,3 +22,3 @@ | ||
return converter(flightPlan); | ||
return converter(flightPlan, options); | ||
}; |
'use strict'; | ||
var types = require('../types'); | ||
var typeMap = require('../typeMap'); | ||
var reverseTypeMap = Object.keys( typeMap ).reduce( ( r, k ) => ( { ...r, ...k && typeMap[ k ] && { [ typeMap[ k ] ]: k } } ), {} ) | ||
var typeMap = { | ||
'airport': 1, | ||
'ndb': 2, | ||
'vor': 3, | ||
'fix': 11, | ||
'gps': 28 | ||
}; | ||
function getWaypointName( waypoint ) { | ||
switch( waypoint.type ) { | ||
case types.AIRPORT: | ||
return waypoint.airport.icao | ||
break; | ||
case types.NDB: | ||
case types.VOR: | ||
return waypoint[waypoint.type].identifier | ||
break; | ||
case types.FIX: | ||
return waypoint.fix.name | ||
break; | ||
case types.GPS: | ||
default: | ||
return waypoint.identifier || 'NONAME' | ||
break | ||
} | ||
} | ||
function lineFromWaypoint(waypoint) { | ||
var line = [typeMap[waypoint.type] || typeMap[types.GPS]]; | ||
function lineFromWaypoint(waypoint, index, length, fmsVersion) { | ||
var line = [reverseTypeMap[waypoint.type] || reverseTypeMap[types.GPS]]; | ||
@@ -27,4 +40,26 @@ switch(waypoint.type) { | ||
break; | ||
case types.GPS: | ||
default: | ||
// FMS takes all five entries per line, even for older v3 version, so should consider adding it even without v1100 | ||
// (leaving out to avoid intruding on anyone's compatbility) | ||
// And most parsers allow the identifier here for locations (instead of weird +000_-000), including X-Plane | ||
if( fmsVersion === '1100' ) { | ||
line.push( waypoint.identifier || 'NONAME' ) | ||
} | ||
break | ||
} | ||
if( fmsVersion === '1100' ) { | ||
// v1100 needs VIA entry, using direct for enroute segments for now (except for departing and arriving airports) | ||
let via | ||
if( waypoint.type === types.AIRPORT && index === 0 ) { | ||
via = 'ADEP' | ||
} else if( waypoint.type === types.AIRPORT && index === length - 1 ) { | ||
via = 'ADES' | ||
} else { | ||
via = 'DRCT' | ||
} | ||
line.push( via ) | ||
} | ||
line.push(waypoint.elevation); | ||
@@ -37,8 +72,3 @@ line.push(waypoint.lat); | ||
/** | ||
* Converts normalized flight plan to XPlanes fms format | ||
* @param {Object} flightPlan normalized flight plan | ||
* @return {String} FMS flight plan | ||
*/ | ||
module.exports = function (flightPlan) { | ||
function getV3Header( flightPlan ) { | ||
return [ | ||
@@ -50,8 +80,38 @@ 'I', | ||
] | ||
} | ||
function getDeX( suffix, waypoint ) { | ||
const name = getWaypointName( waypoint ) | ||
const line = waypoint.type === types.AIRPORT ? `A${suffix} ${name}` : `${suffix} ${name}` | ||
return line | ||
} | ||
function getV1100Header( flightPlan ) { | ||
const dep = getDeX( 'DEP', flightPlan.waypoints[ 0 ] ) | ||
const des = getDeX( 'DES', flightPlan.waypoints[ flightPlan.waypoints.length - 1 ] ) | ||
return [ | ||
'I', | ||
'1100 version', | ||
'CYCLE 1708', // could get real AIRAC cycle, using this for now just to match X-Plane | ||
dep, | ||
des, | ||
`NUMENR ${flightPlan.waypoints.length}` | ||
] | ||
} | ||
/** | ||
* Converts normalized flight plan to XPlanes fms format | ||
* @param {Object} flightPlan normalized flight plan | ||
* @return {String} FMS flight plan | ||
*/ | ||
module.exports = function (flightPlan, options = {}) { | ||
const { fmsVersion } = options | ||
const header = fmsVersion === '1100' ? getV1100Header( flightPlan) : getV3Header( flightPlan ) | ||
return header | ||
.concat( | ||
flightPlan | ||
.waypoints | ||
.map(lineFromWaypoint) | ||
.map( ( wp, i ) => lineFromWaypoint( wp, i, flightPlan.waypoints.length, fmsVersion )) | ||
) | ||
.join('\r\n'); | ||
}; |
@@ -50,2 +50,8 @@ 'use strict'; | ||
}); | ||
it('should convert complex.json into V1100', () => { | ||
expect(converter(getFlightPlan('complex.json'), { fmsVersion: '1100' })) | ||
.to | ||
.eql(getFms('complex_cleaned_v1100.fms')); | ||
}); | ||
}); |
'use strict'; | ||
// module file names for converters and parsers | ||
const types = require( './formatTypes' ) | ||
const { FPL } = types | ||
module.exports = { | ||
XPLANE_FMS: 'xplane_fms', | ||
KML: 'kml' | ||
KML: 'kml', | ||
[ FPL ]: 'fpl' | ||
}; |
@@ -6,4 +6,6 @@ 'use strict'; | ||
parse: require('./parse'), | ||
formatTypes: require('./formatTypes'), | ||
formats: require('./formats'), | ||
formatSuffixes: require('./formatSuffixes'), | ||
types: require('./types') | ||
}; |
'use strict'; | ||
const formatTypes = require( '../formatTypes' ) | ||
const { FPL } = formatTypes | ||
var parsers = { | ||
xplane_fms: require('./xplane_fms') | ||
xplane_fms: require('./xplane_fms'), | ||
[ FPL ]: require( './fpl' ) | ||
}; | ||
@@ -6,0 +10,0 @@ |
@@ -7,12 +7,4 @@ 'use strict'; | ||
var normalizeLineBreaks = require('../utils/normalizeLineBreaks'); | ||
var typeMap = require('../typeMap'); | ||
var typeMap = { | ||
1: types.AIRPORT, | ||
2: types.NDB, | ||
3: types.VOR, | ||
11: types.FIX, | ||
28: types.GPS, | ||
9999: types.ERROR | ||
}; | ||
var fmsVersion = 3; | ||
@@ -19,0 +11,0 @@ |
{ | ||
"name": "flight-plan-converter", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Converts Flight Plans from and to various file formats.", | ||
"bin": "cli.js", | ||
"bin": "flight-plan-converter", | ||
"main": "index.js", | ||
"scripts": { | ||
"convert": "node cli.js @$", | ||
"convert": "node cli.js", | ||
"test": "node node_modules/.bin/mocha lib/*.test.js lib/**/*.test.js" | ||
@@ -31,3 +31,6 @@ }, | ||
"mocha": "^2.5.3" | ||
}, | ||
"dependencies": { | ||
"libxmljs": "^0.19.5" | ||
} | ||
} |
@@ -12,2 +12,3 @@ # Flight-Plan converter | ||
- [X-Planes](http://www.x-plane.com) `.fms` V1100 | ||
- [ForeFlight](https://plan.foreflight.com) `.fpl` (import only) | ||
- KML (export only) | ||
@@ -25,2 +26,9 @@ | ||
or bypassing npm to use directly: | ||
```bash | ||
$ npm install | ||
$ flight-plan-converter [source] [dest] | ||
``` | ||
or programatically: | ||
@@ -27,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43475
46
1102
100
1
11
+ Addedlibxmljs@^0.19.5
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbindings@1.3.1(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlibxmljs@0.19.10(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedms@2.1.3(transitive)
+ Addednan@2.14.2(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyallist@4.0.0(transitive)