Skip to content

Commit

Permalink
feat: add offsets up to 0xE92 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackholegalaxy authored Jan 26, 2020
1 parent 905fdc0 commit 82941e8
Show file tree
Hide file tree
Showing 79 changed files with 5,784 additions and 296 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/branch-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
- master

jobs:
test:
name: test
lint:
name: lint
runs-on: windows-latest
timeout-minutes: 5
steps:
Expand All @@ -36,6 +36,31 @@ jobs:
shell: bash
run: |
yarn tslint
test:
name: test
runs-on: windows-latest
timeout-minutes: 5
steps:
- name: setup:checkout
uses: actions/checkout@master
- name: setup:python3.7
uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: x64
- name: setup:cache:node
uses: actions/[email protected]
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}-api-test-node-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-api-test-node-
${{ runner.os }}-api-
- name: deps:install
shell: bash
run: |
yarn
- name: test:unit
shell: bash
run: |
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: release
on:
push:
tags:
- '*'

jobs:
build:
name: build
runs-on: windows-latest
timeout-minutes: 5
steps:
- name: setup:checkout
uses: actions/checkout@master
- name: setup:python3.7
uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: x64
- name: setup:cache
uses: actions/[email protected]
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}-api-build-node-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-api-build-node-
${{ runner.os }}-api-
- name: deps:install
shell: bash
run: |
yarn
- name: build:prod
shell: bash
run: |
yarn compile:prod
- name: build:upload:artifacts
uses: actions/upload-artifact@v1
with:
name: fsuipc-api-${{ github.ref }}
path: ${{ github.workspace }}/dist
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# @fsuipc/api - FSUIPC Node API

[![Coverage Status](https://coveralls.io/repos/github/fsuipc-node/api/badge.svg?branch=master)](https://coveralls.io/github/fsuipc-node/api?branch=master)
![branch-master](https://github.com/fsuipc-node/api/workflows/branch-master/badge.svg?branch=master)

Tooling to use FSUIPC external application interface, with nodeJS.

Expand Down
18 changes: 18 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Feature

## Offsets depending on others offset value to be converted:
- `0xBDC`: flaps levels
- `0xBE0`: flaps position indicator
- `0xBE4`: flaps position indicator
- `0xB50`: bleed air source control, value depending on aircraft model
- `0x892`, `0x92A`, `0x9C2`, `0xA5A`: engine 1-4 starter switch position value depending on propulsion type
- `0x898`: require engineRPMScaler for proper calculation
- `0xC52`: VOR or ILS depending value for signal strength percent?

## Write offsets

Convert should varies depending on write or read mode

## Offset missing mappings:
- `0xAF8`: fuel tank selected
- `0xE84`: cloud type
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fsuipc/api",
"version": "0.2.0",
"version": "0.3.0",
"author": {
"name": "FSUIPC-Node Opensource Team",
"url": "https://github.com/fsuipc-node"
Expand Down
20 changes: 13 additions & 7 deletions src/lib/convert/apply-conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ export const applyConversion = (offset: Offset, rawOffsetValue: RawOffsetValue):
return 'UNSUPPORTED_CONVERSION_EXPRESSION';
}

const convertExpression: string = offset.convert.replace(
new RegExp(/{VAL}/g),
Array.isArray(rawOffsetValue)
? `${JSON.stringify(rawOffsetValue)}`
: rawOffsetValue.toString()
return new VM().run(
replaceOffsetExpressionValue(offset, rawOffsetValue)
);

return new VM().run(convertExpression);
}
};

export const replaceOffsetExpressionValue = (offset: Offset, rawOffsetValue: RawOffsetValue): string => {
return offset.convert.replace(
new RegExp(/{VAL}/g),
Array.isArray(rawOffsetValue)
? `${JSON.stringify(rawOffsetValue)}`
: typeof rawOffsetValue === 'string'
? `'${rawOffsetValue}'`
: rawOffsetValue.toString()
);
};
14 changes: 14 additions & 0 deletions src/lib/convert/mappings/applied-brakes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Brakes } from '@shared/plane/brakes';

export const appliedBrakes = (value: number): Brakes => {
switch (value) {
case 1:
return Brakes.LEFT;
case 2:
return Brakes.RIGHT;
case 3:
return Brakes.BOTH;
default:
return null;
}
};
17 changes: 17 additions & 0 deletions src/lib/convert/mappings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { seasons } from './seasons';
import { ftsecToKt, ktToFtsec } from './units';
import { engineType } from './engine-type';
import { nearestAirportsIds } from './nearest-airports-ids';
import { appliedBrakes } from './applied-brakes';
import { spoilersControl } from './spoilers-control';
import { vorToFrom } from './vor-to-from';
import { navBackCourseFlags } from './nav-back-course-flags';
import { navCapabilities } from './nav-capabilities';

export const MAPPINGS: { [key: string]: (_: any) => any } = {
lightsMapping,
Expand All @@ -20,9 +25,16 @@ export const MAPPINGS: { [key: string]: (_: any) => any } = {

// plane
engineType,
appliedBrakes,
spoilersControl,

// environment
nearestAirportsIds,

// radios,
vorToFrom,
navBackCourseFlags,
navCapabilities,
};

export * from './lights';
Expand All @@ -31,3 +43,8 @@ export * from './precipitation-type';
export * from './seasons';
export * from './units';
export * from './engine-type';
export * from './applied-brakes';
export * from './spoilers-control';
export * from './vor-to-from';
export * from './nav-back-course-flags';
export * from './nav-capabilities';
22 changes: 22 additions & 0 deletions src/lib/convert/mappings/nav-back-course-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const BackCourseFlags = [
{ name: 'backCourseAvailable', index: 0 },
{ name: 'localiserTunedIn', index: 1 },
{ name: 'onBackCourse', index: 2 },
{ name: 'stationActive', index: 7 },
];

export const navBackCourseFlags = (values: number[]): { [key: string]: boolean } => {
const flags: { [key: string]: boolean } = {};

values.forEach((value, index) => {
const flagName = BackCourseFlags.find(flag => flag.index === index);

if (!flagName) {
return;
}

flags[flagName.name] = !!value;
});

return flags;
};
17 changes: 17 additions & 0 deletions src/lib/convert/mappings/nav-capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Capabilities = ['dme', 'tacan', 'voice', 'noSignal', 'dmeGlideslope', 'noBackCourse', 'glideslope', 'isLocaliser'];

export const navCapabilities = (values: number[]): { [key: string]: boolean } => {
const capabilities: { [key: string]: boolean } = {};

values.forEach((value, index) => {
const capability: string = Capabilities[index];

if (!capability) {
return;
}

capabilities[capability] = !!value;
});

return capabilities;
};
7 changes: 7 additions & 0 deletions src/lib/convert/mappings/spoilers-control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const spoilersControl = (value: number): number => {
if (value < 4800) {
return 0;
}

return Math.round((value - 4800) / (16383 - 4800) * 100);
};
12 changes: 12 additions & 0 deletions src/lib/convert/mappings/vor-to-from.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { VorToFrom } from '@shared/radios/vor-to-from';

export const vorToFrom = (value: number): VorToFrom => {
switch (value) {
case 0:
return VorToFrom.OFF;
case 1:
return VorToFrom.TO;
case 2:
return VorToFrom.FROM;
}
};
36 changes: 36 additions & 0 deletions src/lib/offsets/environment/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,40 @@ export const environment: OffsetList = {
type: Type.Single,
permission: 'r',
}),
towerLatitude: new Offset({
value: 0xD50,
name: 'towerLatitude',
category: OffsetCategory.ENVIRONMENT,
description: 'tower latitude',
convert: '{VAL} * 90 / (10001750 * 65536 * 65536)',
type: Type.Int64,
permission: 'r',
}),
towerLongitude: new Offset({
value: 0xD58,
name: 'towerLongitude',
category: OffsetCategory.ENVIRONMENT,
description: 'tower longitude',
convert: '{VAL} * 360 / (65536 * 65536 * 65536 * 65536)',
type: Type.Int64,
permission: 'r',
}),
towerAltitude: new Offset({
value: 0xD60,
name: 'towerAltitude',
category: OffsetCategory.ENVIRONMENT,
description: 'tower altitude',
convert: '+({VAL} * 3.28084 / (65536 * 65536)).toFixed(2)',
type: Type.Int64,
permission: 'r',
}),
nearestWeatherStationId: new Offset({
value: 0xE80,
name: 'nearestWeatherStationId',
category: OffsetCategory.ENVIRONMENT,
description: 'nearest weather station ICAO id',
type: Type.String,
length: 4,
permission: 'r',
}),
};
Loading

0 comments on commit 82941e8

Please sign in to comment.