Skip to content

Commit

Permalink
Implement executeAction
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenAR committed Dec 9, 2023
1 parent 7e9768f commit a23f5dd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/SimConnectConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import { ClientDataRequestFlag } from './flags/ClientDataRequestFlag';
import { SimConnectConstants } from './SimConnectConstants';
import { SimConnectPacketBuilder } from './SimConnectPacketBuilder';
import {
RecvActionCallback,
RecvAirportList,
RecvAssignedObjectID,
RecvCloudState,
RecvControllersList,
RecvCustomAction,
RecvEnumerateInputEventParams,
RecvEnumerateInputEvents,
RecvEvent,
RecvEventAddRemove,
RecvEventEx1,
Expand All @@ -34,11 +38,13 @@ import {
RecvFacilityData,
RecvFacilityDataEnd,
RecvFacilityMinimalList,
RecvGetInputEvent,
RecvJetwayData,
RecvNDBList,
RecvOpen,
RecvReservedKey,
RecvSimObjectData,
RecvSubscribeInputEvent,
RecvSystemState,
RecvVORList,
RecvWaypointList,
Expand All @@ -55,11 +61,6 @@ import {
ObjectId,
} from './Types';
import Timeout = NodeJS.Timeout;
import { RecvControllersList } from './recv/RecvControllersList';
import { RecvEnumerateInputEvents } from './recv/RecvEnumerateInputEvents';
import { RecvGetInputEvent } from './recv/RecvGetInputEvent';
import { RecvSubscribeInputEvent } from './recv/RecvSubscribeInputEvent';
import { RecvEnumerateInputEventParams } from './recv/RecvEnumerateInputEventParams';

type OpenPacketData = {
major: number;
Expand Down Expand Up @@ -134,6 +135,7 @@ interface SimConnectRecvEvents {
facilityDataEnd: (recvFacilityDataEnd: RecvFacilityDataEnd) => void;
facilityMinimalList: (recvFacilityMinimalList: RecvFacilityMinimalList) => void;
jetwayData: (recvJetwayData: RecvJetwayData) => void;
actionCallback: (recvActionCallback: RecvActionCallback) => void;
controllersList: (recvControllersList: RecvControllersList) => void;
inputEventsList: (recvEnumerateInputEvents: RecvEnumerateInputEvents) => void;
getInputEvent: (recvGetInputEvent: RecvGetInputEvent) => void;
Expand Down Expand Up @@ -1536,7 +1538,23 @@ class SimConnectConnection extends EventEmitter {
);
}

// TODO: implement 0x4e: executeAction(dataRequestID: number, actionID: string, values: RawBuffer)
/**
* See https://www.fsdeveloper.com/wiki/index.php/MSFS_Mission_Script_-_Actions
*
* @returns sendId of packet (can be used to identify packet when exception event occurs)
*/
executeAction(dataRequestID: number, actionID: string, values: RawBuffer) {
if (this._ourProtocol < Protocol.KittyHawk) throw Error(SimConnectError.BadVersion);

const paramValues = values.getBuffer();

const packet = this._beginPacket(0x4e)
.putInt32(dataRequestID)
.putString256(actionID)
.putInt32(paramValues.length)
.putBytes(paramValues);
return this._buildAndSend(packet);
}

/**
*
Expand Down Expand Up @@ -1740,6 +1758,7 @@ class SimConnectConnection extends EventEmitter {
this.emit('controllersList', new RecvControllersList(data));
break;
case RecvID.ID_ACTION_CALLBACK:
this.emit('actionCallback', new RecvActionCallback(data));
break;
case RecvID.ID_ENUMERATE_INPUT_EVENTS:
this.emit('inputEventsList', new RecvEnumerateInputEvents(data));
Expand Down
15 changes: 15 additions & 0 deletions src/recv/RecvActionCallback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { RawBuffer } from '../RawBuffer';
import { RecvEvent } from './RecvEvent';
import { DataRequestId } from '../Types';

export class RecvActionCallback extends RecvEvent {
requestID: DataRequestId;

actionID: string;

constructor(data: RawBuffer) {
super(data);
this.actionID = data.readString260();
this.requestID = data.readInt32();
}
}
5 changes: 5 additions & 0 deletions src/recv/RecvException.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RawBuffer } from '../RawBuffer';
import { SimConnectException } from '../enums/SimConnectException';

export class RecvException {
exception: number;
Expand All @@ -7,10 +8,14 @@ export class RecvException {

index: number;

exceptionName: string;

constructor(data: RawBuffer) {
this.exception = data.readInt32();
this.sendId = data.readInt32();
this.index = data.readInt32();

this.exceptionName = SimConnectException[this.exception];
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/recv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ export * from './RecvVORList';
export * from './RecvWaypointList';
export * from './RecvWeatherObservation';
export * from './RecvJetwayData';
export * from './RecvControllersList';
export * from './RecvEnumerateInputEvents';
export * from './RecvGetInputEvent';
export * from './RecvSubscribeInputEvent';
export * from './RecvEnumerateInputEventParams';
export * from './RecvActionCallback';

0 comments on commit a23f5dd

Please sign in to comment.