Skip to content

Commit

Permalink
Merge pull request #82 from EvenAR/jetway-data
Browse files Browse the repository at this point in the history
Add the new requestJetwayData() function
  • Loading branch information
EvenAR authored Jun 28, 2023
2 parents 11b68cd + 681ad04 commit 2efbe09
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Prepar3D support and Prepar3D-only-features will not be prioritized.
| `requestFacilitiesListEx1` | n/a | n/a | ✅ |
| `requestFacilityData` | n/a | n/a | ✅ |
| `requestFacilityDataEx1` | n/a | n/a | ✅ |
| `requestJetwayData` | n/a | n/a | ✅ |
| `subscribeToFacilities` | ✅ | | |
| `subscribeToFacilitiesEx1` | n/a | n/a | ✅ |
| `unSubscribeToFacilities` | ✅ | | |
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-simconnect",
"version": "3.4.3",
"version": "3.5.0",
"description": "A SimConnect client library for Node.JS.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 4 additions & 0 deletions src/RawBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class RawBuffer {
return this.buffer.readInt32();
}

readUint32(): number {
return this.buffer.readUint32();
}

/** @deprecated use readInt32() instead */
readInt = this.readInt32;

Expand Down
23 changes: 23 additions & 0 deletions src/SimConnectConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
RecvFacilityDataEnd,
RecvFacilityMinimalList,
RecvEventEx1,
RecvJetwayData,
} from './recv';
import {
ClientDataDefinitionId,
Expand Down Expand Up @@ -127,6 +128,7 @@ interface SimConnectRecvEvents {
facilityData: (recvFacilityData: RecvFacilityData) => void;
facilityDataEnd: (recvFacilityDataEnd: RecvFacilityDataEnd) => void;
facilityMinimalList: (recvFacilityMinimalList: RecvFacilityMinimalList) => void;
jetwayData: (recvJetwayData: RecvJetwayData) => void;
}

type ConnectionOptions =
Expand Down Expand Up @@ -1460,6 +1462,24 @@ class SimConnectConnection extends EventEmitter {
);
}

requestJetwayData(airportIcao: string, parkingIndices?: number[]): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

const packet = this._beginPacket(0x4b)
.putString(airportIcao, 16)
.putInt32(parkingIndices?.length || 0);

if (parkingIndices === undefined || parkingIndices.length === 0) {
packet.putInt32(0);
} else {
parkingIndices.forEach(parkingIndex => {
packet.putInt32(parkingIndex);
});
}

return this._buildAndSend(packet);
}

close() {
if (this._openTimeout !== null) {
clearTimeout(this._openTimeout);
Expand Down Expand Up @@ -1585,6 +1605,9 @@ class SimConnectConnection extends EventEmitter {
case RecvID.ID_FACILITY_MINIMAL_LIST:
this.emit('facilityMinimalList', new RecvFacilityMinimalList(data));
break;
case RecvID.ID_JETWAY_DATA:
this.emit('jetwayData', new RecvJetwayData(data));
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/SimConnectSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum RecvID {
ID_FACILITY_DATA,
ID_FACILITY_DATA_END,
ID_FACILITY_MINIMAL_LIST,
ID_JETWAY_DATA,
}

interface SimConnectMessage {
Expand Down
26 changes: 26 additions & 0 deletions src/dto/PBH.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SimConnectData } from './SimConnectData';
import { RawBuffer } from '../RawBuffer';
import { SimConnectPacketBuilder } from '../SimConnectPacketBuilder';

class PBH implements SimConnectData {
pitch = 0;

bank = 0;

heading = 0;

readFrom(buffer: RawBuffer) {
this.pitch = buffer.readFloat32();
this.bank = buffer.readFloat32();
this.heading = buffer.readFloat32();
}

writeTo(packetBuilder: SimConnectPacketBuilder) {
packetBuilder //
.putFloat32(this.pitch)
.putFloat32(this.bank)
.putFloat32(this.heading);
}
}

export { PBH };
7 changes: 6 additions & 1 deletion src/dto/bufferHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Waypoint } from './Waypoint';
import { LatLonAlt } from './LatLonAlt';
import { XYZ } from './XYZ';
import { SimConnectData } from './SimConnectData';
import { PBH } from './PBH';

function readInitPosition(dataWrapper: RawBuffer): InitPosition {
return readData(dataWrapper, new InitPosition());
Expand All @@ -31,4 +32,8 @@ function readData<T extends SimConnectData>(dataWrapper: RawBuffer, obj: T): T {
return obj;
}

export { readInitPosition, readMarkerState, readWaypoint, readLatLonAlt, readXYZ };
function readPBH(dataWrapper: RawBuffer): PBH {
return readData(dataWrapper, new PBH());
}

export { readInitPosition, readMarkerState, readWaypoint, readLatLonAlt, readXYZ, readPBH };
1 change: 1 addition & 0 deletions src/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './Waypoint';
export * from './XYZ';
export * from './bufferHelpers';
export * from './icao';
export * from './PBH';
10 changes: 10 additions & 0 deletions src/enums/JetwayStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const enum JetwayStatus {
REST,
APPROACH_OUTSIDE,
APPROACH_DOOR,
HOOD_CONNECT,
HOOD_DISCONNECT,
RETRACT_OUTSIDE,
RETRACT_HOME,
FULLY_ATTACHED,
}
1 change: 1 addition & 0 deletions src/enums/SimConnectException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum SimConnectException {
OBJECT_AI,
OBJECT_ATC,
OBJECT_SCHEDULE,
JETWAY_DATA,
}

module.exports = {
Expand Down
48 changes: 48 additions & 0 deletions src/facility/JetwayData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { LatLonAlt } from '../dto/LatLonAlt';
import { PBH } from '../dto/PBH';
import { JetwayStatus } from '../enums/JetwayStatus';
import { XYZ } from '../dto/XYZ';
import { ObjectId } from '../Types';
import { RawBuffer } from '../RawBuffer';
import { readLatLonAlt, readPBH, readXYZ } from '../dto/bufferHelpers';

export class JetwayData {
airportIcao: string;

parkingIndex: number;

latLngAlt: LatLonAlt;

pbh: PBH;

status: JetwayStatus;

door: number;

exitDoorRelativePos: XYZ;

mainHandlePos: XYZ;

secondaryHandle: XYZ;

wheelGroundLock: XYZ;

jetwayObjectId: ObjectId;

attachedObjectId: ObjectId;

constructor(data: RawBuffer) {
this.airportIcao = data.readString(8);
this.parkingIndex = data.readInt32();
this.latLngAlt = readLatLonAlt(data);
this.pbh = readPBH(data);
this.status = data.readInt32();
this.door = data.readInt32();
this.exitDoorRelativePos = readXYZ(data);
this.mainHandlePos = readXYZ(data);
this.secondaryHandle = readXYZ(data);
this.wheelGroundLock = readXYZ(data);
this.jetwayObjectId = data.readUint32() as ObjectId;
this.attachedObjectId = data.readUint32() as ObjectId;
}
}
17 changes: 17 additions & 0 deletions src/recv/RecvJetwayData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RecvListTemplate } from './RecvListTemplate';
import { JetwayData } from '../facility/JetwayData';
import { RawBuffer } from '../RawBuffer';

export class RecvJetwayData extends RecvListTemplate {
jetways: JetwayData[];

constructor(data: RawBuffer) {
super(data);

this.jetways = [];

for (let i = 0; i < this.arraySize; i++) {
this.jetways.push(new JetwayData(data));
}
}
}
19 changes: 19 additions & 0 deletions src/recv/RecvListTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { RawBuffer } from '../RawBuffer';
import { DataRequestId } from '../Types';

export class RecvListTemplate {
requestID: DataRequestId;

arraySize: number;

entryNumber: number;

outOf: number;

constructor(data: RawBuffer) {
this.requestID = data.readInt32() as DataRequestId;
this.arraySize = data.readInt32();
this.entryNumber = data.readInt32();
this.outOf = data.readInt32();
}
}
1 change: 1 addition & 0 deletions src/recv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './RecvSystemState';
export * from './RecvVORList';
export * from './RecvWaypointList';
export * from './RecvWeatherObservation';
export * from './RecvJetwayData';

0 comments on commit 2efbe09

Please sign in to comment.