GSX Reset and Disable button

This commit is contained in:
Kilian Hofmann 2025-09-09 23:40:24 +02:00
parent 04e5ec4251
commit acf4b9ee47
11 changed files with 117 additions and 77 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
Packages
_PackageInt
PackagesMetadata
PackageSources/js-bundle/__generated__
PackageSources/js-bundle/.rollup.cache
PackageSources/js-bundle/node_modules

View File

@ -1,6 +1,6 @@
{
"name": "tfdidesign-md11-load-manager",
"version": "0.1.138",
"version": "0.1.141",
"description": "",
"main": "index.js",
"type": "module",

View File

@ -1,13 +1,9 @@
import { FC, useCallback, useEffect, useState } from 'react';
import Freighter from './components/freighter/Freighter';
import Pax from './components/pax/Pax';
import {
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_LIVE_DATA_EVENT,
TFDI_SIMBRIEF_USERNAME_CALL,
TFDI_SIMBRIEF_USERNAME_EVENT,
} from './constants';
import { COHERENT_COMM_BUS_WASM_CALL } from './constants';
import { WASMDataF, WASMDataPax } from './types/WASMData';
import { CommBusCall, CommBusEvent } from './types/general';
const App: FC = () => {
const [SBUsername, setSBUsername] = useState<string>();
@ -23,22 +19,24 @@ const App: FC = () => {
setWASMData(JSON.parse(data));
}, []);
useEffect(() => {
console.log('[KHOFMANN TFDi MD-11 Load Manager] JS Version [VI]{version}[/VI]: process.env.NODE_ENV [VI]{date}[/VI]');
console.log(
'[KHOFMANN TFDi MD-11 Load Manager] JS Version [VI]{version}[/VI]: process.env.NODE_ENV [VI]{date}[/VI]'
);
console.log('[KHOFMANN TFDi MD-11 Load Manager] Initializing CommBus');
const commBus = RegisterViewListener('JS_LISTENER_COMM_BUS');
commBus.on(TFDI_SIMBRIEF_USERNAME_EVENT, usernameCallback);
commBus.on(COMM_BUS_LIVE_DATA_EVENT, wasmCallback);
commBus.on(CommBusEvent.TFDI_SIMBRIEF_USERNAME, usernameCallback);
commBus.on(CommBusEvent.LIVE_DATA, wasmCallback);
Coherent.call(COHERENT_COMM_BUS_WASM_CALL, TFDI_SIMBRIEF_USERNAME_CALL, 'null');
Coherent.call(COHERENT_COMM_BUS_WASM_CALL, CommBusCall.TFDI_SIMBRIEF_USERNAME, 'null');
return () => {
console.log('[KHOFMANN TFDi MD-11 Load Manager] De-Initializing CommBus');
commBus.off(TFDI_SIMBRIEF_USERNAME_EVENT, usernameCallback);
commBus.off(COMM_BUS_LIVE_DATA_EVENT, wasmCallback);
commBus.off(CommBusEvent.TFDI_SIMBRIEF_USERNAME, usernameCallback);
commBus.off(CommBusEvent.LIVE_DATA, wasmCallback);
commBus.unregister();
};

View File

@ -1,7 +1,7 @@
import { FC } from 'react';
import { LoadingState } from '../../types/general';
import { WASMDataF } from '../../types/WASMData';
import { CoherentCallOptionsSet } from '../../utils/utils';
import { CoherentCallGSXReset, CoherentCallOptionsSet } from '../../utils/utils';
import ToggleComponentKH from '../toggleComponent/ToggleComponent';
interface OptionsFProps {
@ -102,6 +102,16 @@ const OptionsF: FC<OptionsFProps> = ({ WASMData, loadingState, gsxActive }) => {
</>
)}
</div>
<div className="block flex w-full flex-col opacity-100 transition-opacity duration-150 ease-linear mb-4">
<button
className="middle none center rounded-lg bg-red-600 px-6 py-3 font-sans text-xs font-bold uppercase text-white shadow-md shadow-red-500/20 transition-all hover:shadow-lg hover:shadow-red-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
data-ripple-light="true"
onClick={CoherentCallGSXReset}
>
Reset internal GSX state
</button>
</div>
</>
);
};

View File

@ -1,7 +1,7 @@
import { FC, useEffect, useState } from 'react';
import { LoadingState } from '../../types/general';
import { WASMDataPax } from '../../types/WASMData';
import { CoherentCallOptionsSet } from '../../utils/utils';
import { CoherentCallGSXReset, CoherentCallOptionsSet } from '../../utils/utils';
import ToggleComponentKH from '../toggleComponent/ToggleComponent';
interface OptionsPaxProps {
@ -162,6 +162,16 @@ const OptionsPax: FC<OptionsPaxProps> = ({ WASMData, loadingState, gsxActive })
</>
)}
</div>
<div className="block flex w-full flex-col opacity-100 transition-opacity duration-150 ease-linear mb-4">
<button
className="middle none center rounded-lg bg-red-600 px-6 py-3 font-sans text-xs font-bold uppercase text-white shadow-md shadow-red-500/20 transition-all hover:shadow-lg hover:shadow-red-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
data-ripple-light="true"
onClick={CoherentCallGSXReset}
>
Reset internal GSX state & disable SYNC
</button>
</div>
</>
);
};

View File

@ -1,16 +1,3 @@
export const COHERENT_COMM_BUS_WASM_CALL = 'COMM_BUS_WASM_CALLBACK';
export const TFDI_SIMBRIEF_USERNAME_CALL = 'requestSimBriefUsername';
export const TFDI_SIMBRIEF_USERNAME_EVENT = 'receiveSimBriefUsername';
export const COMM_BUS_LIVE_DATA_EVENT = 'khofmann_tfdi_md-11_load_manager_live_data';
export const COMM_BUS_UPDATE_TARGET_EVENT = 'khofmann_tfdi_md-11_load_manager_update_target';
export const CG_ADJUST = 0.05;
export const MODE_SB_SET = 0;
export const MODE_ZFW_SET = 1;
export const MODE_STATION_SET = 2;
export const MODE_LOAD_SET = 3;
export const MODE_UNLOAD_SET = 4;
export const MODE_OPTIONS_SET = 5;

View File

@ -7,3 +7,23 @@ export interface SimBrief {
cargo: number;
fuel: number;
}
export enum CallMode {
SB_SET = 0,
ZFW_SET = 1,
STATION_SET = 2,
LOAD_SET = 3,
UNLOAD_SET = 4,
OPTIONS_SET = 5,
GSX_RESET = 6,
}
export enum CommBusCall {
TFDI_SIMBRIEF_USERNAME = 'requestSimBriefUsername',
}
export enum CommBusEvent {
TFDI_SIMBRIEF_USERNAME = 'receiveSimBriefUsername',
LIVE_DATA = 'khofmann_tfdi_md-11_load_manager_live_data',
UPDATE_TARGET = 'khofmann_tfdi_md-11_load_manager_update_target',
}

View File

@ -1,21 +1,12 @@
import {
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
MODE_LOAD_SET,
MODE_OPTIONS_SET,
MODE_SB_SET,
MODE_STATION_SET,
MODE_UNLOAD_SET,
MODE_ZFW_SET,
} from '../constants';
import { SimBrief } from '../types/general';
import { COHERENT_COMM_BUS_WASM_CALL } from '../constants';
import { CallMode, CommBusEvent, SimBrief } from '../types/general';
export const loadAircraft = () => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_LOAD_SET,
mode: CallMode.LOAD_SET,
})
);
};
@ -23,9 +14,9 @@ export const loadAircraft = () => {
export const unloadAircraft = () => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_UNLOAD_SET,
mode: CallMode.UNLOAD_SET,
})
);
};
@ -37,9 +28,9 @@ export const inRangeOf = (value: number, target: number, tolerance: number = 10)
export const CoherentCallZFWEntry = (ZFWTarget: number, CGTarget: number) => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_ZFW_SET,
mode: CallMode.ZFW_SET,
ZFWTarget: ZFWTarget,
CGTarget: CGTarget,
})
@ -56,9 +47,9 @@ export const CoherentCallStationEntryPax = (
) => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_STATION_SET,
mode: CallMode.STATION_SET,
business1,
business2,
economy1,
@ -79,9 +70,9 @@ export const CoherentCallStationEntryF = (
) => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_STATION_SET,
mode: CallMode.STATION_SET,
upper1,
upper2,
upper3,
@ -93,25 +84,26 @@ export const CoherentCallStationEntryF = (
};
export const CoherentCallSBEntryPax = (CGTarget: number, SBPlan?: SimBrief) => {
const payload = {
mode: MODE_SB_SET,
cargo: SBPlan?.cargo,
numPax: SBPlan ? parseInt(SBPlan.pax as unknown as string) : undefined,
CGTarget: CGTarget,
plannedZFW: SBPlan?.plannedZFW,
plannedGW: SBPlan?.plannedGW,
};
const string = JSON.stringify(payload);
Coherent.call(COHERENT_COMM_BUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT, string);
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: CallMode.SB_SET,
cargo: SBPlan?.cargo,
numPax: SBPlan ? parseInt(SBPlan.pax as unknown as string) : undefined,
CGTarget: CGTarget,
plannedZFW: SBPlan?.plannedZFW,
plannedGW: SBPlan?.plannedGW,
})
);
};
export const CoherentCallSBEntryF = (CGTarget: number, SBPlan?: SimBrief) => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_SB_SET,
mode: CallMode.SB_SET,
cargo: SBPlan?.cargo,
CGTarget: CGTarget,
plannedZFW: SBPlan?.plannedZFW,
@ -123,12 +115,22 @@ export const CoherentCallSBEntryF = (CGTarget: number, SBPlan?: SimBrief) => {
export const CoherentCallOptionsSet = (GSXSync?: boolean, paxWeight?: number, bagWeight?: number) => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: MODE_OPTIONS_SET,
mode: CallMode.OPTIONS_SET,
GSXSync,
paxWeight,
bagWeight,
})
);
};
export const CoherentCallGSXReset = () => {
Coherent.call(
COHERENT_COMM_BUS_WASM_CALL,
CommBusEvent.UPDATE_TARGET,
JSON.stringify({
mode: CallMode.GSX_RESET,
})
);
};

View File

@ -518,8 +518,7 @@ int receiveData(const char* buf) {
if (document.HasMember("mode")) {
int mode = document["mode"].GetUint();
switch(mode) {
// SB Entry
case 0: {
case CALL_MODE_SB_SET: {
if (UserData->isCargo) {
if(document.HasMember("CGTarget"))
targetFPayloadData->CGTarget = document["CGTarget"].GetDouble();
@ -552,8 +551,7 @@ int receiveData(const char* buf) {
}
break;
}
// ZFW Entry
case 1: {
case CALL_MODE_ZFW_SET: {
if (!document.HasMember("ZFWTarget") || !document.HasMember("CGTarget")) return -1;
double ZFWTarget = document["ZFWTarget"].GetDouble();
double CGTarget = document["CGTarget"].GetDouble();
@ -568,8 +566,7 @@ int receiveData(const char* buf) {
}
break;
}
// Station Entry
case 2: {
case CALL_MODE_STATION_SET: {
if (UserData->isCargo) {
if (!document.HasMember("upper1") || !document.HasMember("upper2") ||
!document.HasMember("upper3") || !document.HasMember("upper4") ||
@ -598,8 +595,7 @@ int receiveData(const char* buf) {
}
break;
}
// Trigger load
case 3: {
case CALL_MODE_LOAD_SET: {
if (UserData->isCargo) {
load(targetFPayloadData, simConnect, UserData->isImperial);
}
@ -611,8 +607,7 @@ int receiveData(const char* buf) {
break;
}
// Trigger unload
case 4: {
case CALL_MODE_UNLOAD_SET: {
if (UserData->isCargo) {
unloadF(simConnect, UserData->isER);
}
@ -624,8 +619,7 @@ int receiveData(const char* buf) {
break;
}
// Option set
case 5: {
case CALL_MODE_OPTIONS_SET: {
if (document.HasMember("GSXSync")) {
UserOptions->GSXSync = document["GSXSync"].GetBool();
}
@ -658,6 +652,10 @@ int receiveData(const char* buf) {
}
break;
}
case CALL_MODE_GSX_RESET: {
GSXData->loadingState = LOADING_STATE_IDLE;
UserOptions->GSXSync = false;
}
default:
break;
}
@ -1033,6 +1031,8 @@ void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContex
break;
}
default:
break;
}
switch ((char)GSXData->deboardingState) {
case GSX_SERVICE_ACTIVE: {
@ -1115,6 +1115,8 @@ void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void* pContex
break;
}
default:
break;
}
}

View File

@ -32,7 +32,7 @@
/******************************** Constants ********************************/
// Module identification
#define MODULE_NAME "[KHOFMANN TFDi MD-11 Load Manager] "
#define VERSION_STRING "1.3"
#define VERSION_STRING "1.5"
// COMM BUS
#define COMM_BUS_LIVE_DATA_EVENT "khofmann_tfdi_md-11_load_manager_live_data"
#define COMM_BUS_UPDATE_TARGET_EVENT "khofmann_tfdi_md-11_load_manager_update_target"

View File

@ -96,6 +96,16 @@ enum LOADING_STATES {
LOADING_STATE_DEBOARDED,
};
enum CALL_MODES {
CALL_MODE_SB_SET,
CALL_MODE_ZFW_SET,
CALL_MODE_STATION_SET,
CALL_MODE_LOAD_SET,
CALL_MODE_UNLOAD_SET,
CALL_MODE_OPTIONS_SET,
CALL_MODE_GSX_RESET,
};
/***************************** Data structures *****************************/
typedef struct {
double isCargo;