Skip to content

Commit

Permalink
Merge branch 'master' into issue-91-busy-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenAR authored Dec 9, 2023
2 parents b0a53d7 + 7c40e19 commit cd6934c
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/RawBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class RawBuffer {
return bytes.toBuffer();
}

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

readInt32(): number {
return this.buffer.readInt32();
}
Expand All @@ -49,6 +53,10 @@ class RawBuffer {
return this.buffer.readUint32();
}

writeInt16(value: number, offset?: number) {
this.buffer.writeInt16(value, offset);
}

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

Expand Down
28 changes: 22 additions & 6 deletions src/SimConnectConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { EventFlag } from './flags/EventFlag';
import { DataSetFlag } from './flags/DataSetFlag';
import { ClientDataRequestFlag } from './flags/ClientDataRequestFlag';
import { SimConnectConstants } from './SimConnectConstants';
import Timeout = NodeJS.Timeout;
import { SimConnectPacketBuilder } from './SimConnectPacketBuilder';
import {
RecvAirportList,
Expand All @@ -25,12 +24,17 @@ import {
RecvCustomAction,
RecvEvent,
RecvEventAddRemove,
RecvEventEx1,
RecvEventFilename,
RecvEventFrame,
RecvEventRaceEnd,
RecvEventRaceLap,
RecvEventWeatherMode,
RecvException,
RecvFacilityData,
RecvFacilityDataEnd,
RecvFacilityMinimalList,
RecvJetwayData,
RecvNDBList,
RecvOpen,
RecvReservedKey,
Expand All @@ -39,11 +43,6 @@ import {
RecvVORList,
RecvWaypointList,
RecvWeatherObservation,
RecvFacilityData,
RecvFacilityDataEnd,
RecvFacilityMinimalList,
RecvEventEx1,
RecvJetwayData,
} from './recv';
import {
ClientDataDefinitionId,
Expand All @@ -55,6 +54,8 @@ import {
NotificationGroupId,
ObjectId,
} from './Types';
import Timeout = NodeJS.Timeout;
import { RecvControllersList } from './recv/RecvControllersList';

type OpenPacketData = {
major: number;
Expand Down Expand Up @@ -129,6 +130,7 @@ interface SimConnectRecvEvents {
facilityDataEnd: (recvFacilityDataEnd: RecvFacilityDataEnd) => void;
facilityMinimalList: (recvFacilityMinimalList: RecvFacilityMinimalList) => void;
jetwayData: (recvJetwayData: RecvJetwayData) => void;
controllersList: (recvControllersList: RecvControllersList) => void;
}

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

/**
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
requestJetwayData(airportIcao: string, parkingIndices?: number[]): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

Expand All @@ -1480,6 +1486,13 @@ class SimConnectConnection extends EventEmitter {
return this._buildAndSend(packet);
}

enumerateControllers(): number {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

const packet = this._beginPacket(0x4c);
return this._buildAndSend(packet);
}

close() {
if (this._openTimeout !== null) {
clearTimeout(this._openTimeout);
Expand Down Expand Up @@ -1608,6 +1621,9 @@ class SimConnectConnection extends EventEmitter {
case RecvID.ID_JETWAY_DATA:
this.emit('jetwayData', new RecvJetwayData(data));
break;
case RecvID.ID_CONTROLLERS_LIST:
this.emit('controllersList', new RecvControllersList(data));
break;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/SimConnectPacketBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export class SimConnectPacketBuilder {
return this;
}

putInt16(value: number, offset?: number) {
this.packetContent.writeInt16(value, offset);
return this;
}

putInt32(value: number, offset?: number) {
this.packetContent.writeInt32(value, offset);
return this;
Expand Down
1 change: 1 addition & 0 deletions src/SimConnectSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum RecvID {
ID_FACILITY_DATA_END,
ID_FACILITY_MINIMAL_LIST,
ID_JETWAY_DATA,
ID_CONTROLLERS_LIST,
}

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

export class ControllerItem {
deviceName: string;

deviceId: number;

productId: number;

compositeId: number;

hardwareVersion: VersionBaseType;

constructor(data: RawBuffer) {
this.deviceName = data.readString256();
this.deviceId = data.readInt32();
this.productId = data.readInt32();
this.compositeId = data.readInt32();
this.hardwareVersion = new VersionBaseType(data);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions src/datastructures/VersionBaseType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RawBuffer } from '../RawBuffer';

export class VersionBaseType {
major: number;

minor: number;

revision: number;

build: number;

constructor(data: RawBuffer) {
this.major = data.readInt16();
this.minor = data.readInt16();
this.revision = data.readInt16();
this.build = data.readInt16();
}
}
1 change: 1 addition & 0 deletions src/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './XYZ';
export * from './bufferHelpers';
export * from './icao';
export * from './PBH';
export * from '../datastructures/VersionBaseType';
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export * from './flags/EventFlag';
export * from './flags/DataRequestFlag';
export * from './flags/DataSetFlag';
export * from './flags/ClientDataRequestFlag';
export * from './facility/FacilityAirport';
export * from './facility/FacilityNDB';
export * from './facility/FacilityVOR';
export * from './facility/FacilityWaypoint';
export * from './datastructures/FacilityAirport';
export * from './datastructures/FacilityNDB';
export * from './datastructures/FacilityVOR';
export * from './datastructures/FacilityWaypoint';
export * from './Types';

export * from './recv';
Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvAirportList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RawBuffer } from '../RawBuffer';
import { FacilityAirport } from '../facility/FacilityAirport';
import { FacilityAirport } from '../datastructures/FacilityAirport';
import { RecvFacilitiesList } from './RecvFacilitiesList';

export class RecvAirportList extends RecvFacilitiesList {
Expand Down
16 changes: 16 additions & 0 deletions src/recv/RecvControllersList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RawBuffer } from '../RawBuffer';
import { RecvListTemplate } from './RecvListTemplate';
import { ControllerItem } from '../datastructures/ControllerItem';

export class RecvControllersList extends RecvListTemplate {
controllers: ControllerItem[] = [];

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

this.controllers = [];
for (let i = 0; i < this.arraySize; i++) {
this.controllers.push(new ControllerItem(data));
}
}
}
2 changes: 1 addition & 1 deletion src/recv/RecvFacilityMinimalList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FacilityMinimal } from '../facility/FacilityMinimal';
import { FacilityMinimal } from '../datastructures/FacilityMinimal';
import { RawBuffer } from '../RawBuffer';
import { RecvFacilitiesList } from './RecvFacilitiesList';

Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvJetwayData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RecvListTemplate } from './RecvListTemplate';
import { JetwayData } from '../facility/JetwayData';
import { JetwayData } from '../datastructures/JetwayData';
import { RawBuffer } from '../RawBuffer';

export class RecvJetwayData extends RecvListTemplate {
Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvNDBList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RawBuffer } from '../RawBuffer';
import { FacilityNDB } from '../facility/FacilityNDB';
import { FacilityNDB } from '../datastructures/FacilityNDB';
import { RecvFacilitiesList } from './RecvFacilitiesList';

export class RecvNDBList extends RecvFacilitiesList {
Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvVORList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RawBuffer } from '../RawBuffer';
import { FacilityVOR } from '../facility/FacilityVOR';
import { FacilityVOR } from '../datastructures/FacilityVOR';
import { RecvFacilitiesList } from './RecvFacilitiesList';

export class RecvVORList extends RecvFacilitiesList {
Expand Down
2 changes: 1 addition & 1 deletion src/recv/RecvWaypointList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RawBuffer } from '../RawBuffer';
import { FacilityWaypoint } from '../facility/FacilityWaypoint';
import { FacilityWaypoint } from '../datastructures/FacilityWaypoint';
import { RecvFacilitiesList } from './RecvFacilitiesList';

export class RecvWaypointList extends RecvFacilitiesList {
Expand Down

0 comments on commit cd6934c

Please sign in to comment.