SB persist

Options page for GSX Sync
This commit is contained in:
2025-06-18 23:57:46 +02:00
parent 4b60f8eec2
commit 390edd29b8
16 changed files with 316 additions and 135 deletions
+39 -1
View File
@@ -502,12 +502,14 @@ int receiveData(const char* buf) {
switch(mode) {
// SB Entry
case 0: {
if (!document.HasMember("cargo") || !document.HasMember("CGTarget")) return -1;
if (!document.HasMember("cargo") || !document.HasMember("CGTarget") || !document.HasMember("plannedZFW") || !document.HasMember("plannedGW")) return -1;
unsigned int cargo = document["cargo"].GetInt();
double CGTarget = document["CGTarget"].GetDouble();
if (UserData->isCargo) {
targetFPayloadData->CGTarget = CGTarget;
targetFPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble();
targetFPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble();
distribute(targetFPayloadData, liveFuelData, cargo, UserData->isImperial, UserData->isER);
}
@@ -516,6 +518,9 @@ int receiveData(const char* buf) {
unsigned short numPax = document["numPax"].GetInt();
targetPaxPayloadData->CGTarget = CGTarget;
targetPaxPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble();
targetPaxPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble();
distribute(targetPaxPayloadData, liveFuelData, numPax, cargo, UserData->isImperial, UserData->isER);
}
break;
@@ -588,6 +593,32 @@ int receiveData(const char* buf) {
break;
}
// Option set
case 5: {
if (document.HasMember("GSXSync")) {
UserOptions->GSXSync = document["GSXSync"].GetBool();
}
rapidjson::Document optionsDoc;
rapidjson::Document::AllocatorType& allocator = optionsDoc.GetAllocator();
optionsDoc.SetObject();
optionsDoc.AddMember("GSXSync", UserOptions->GSXSync, allocator);
optionsDoc.AddMember("paxWeightKG", UserOptions->paxWeightKG, allocator);
optionsDoc.AddMember("bagWeightKG", UserOptions->bagWeightKG, allocator);
optionsDoc.AddMember("paxWeightLBS", UserOptions->paxWeightLBS, allocator);
optionsDoc.AddMember("bagWeightLBS", UserOptions->bagWeightLBS, allocator);
FILE* optionsFile = fopen("\\work\\options.json", "wb");
if (optionsFile != NULL) {
char writeBuffer[256];
rapidjson::FileWriteStream os(optionsFile, writeBuffer, sizeof(writeBuffer));
rapidjson::Writer<rapidjson::FileWriteStream> writer(os);
optionsDoc.Accept(writer);
fclose(optionsFile);
log(stdout, MODULE_NAME"Options written.\n");
}
break;
}
default:
break;
}
@@ -619,6 +650,8 @@ void sendData () {
limits.SetObject();
rapidjson::Value options;
options.SetObject();
rapidjson::Value sbPlanned;
sbPlanned.SetObject();
rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
@@ -773,6 +806,10 @@ void sendData () {
options.AddMember("paxWeight", UserData->isImperial ? UserOptions->paxWeightLBS : UserOptions->paxWeightKG, allocator);
options.AddMember("bagWeight", UserData->isImperial ? UserOptions->bagWeightLBS : UserOptions->bagWeightKG, allocator);
// SB Planned
sbPlanned.AddMember("ZFW", UserData->isCargo ? targetFPayloadData->sbPlanned.ZFW: targetPaxPayloadData->sbPlanned.ZFW, allocator);
sbPlanned.AddMember("GW", UserData->isCargo ? targetFPayloadData->sbPlanned.GW : targetPaxPayloadData->sbPlanned.GW, allocator);
// Construct document
document.AddMember("livePayload", livePayload.Move(), allocator);
document.AddMember("targetPayload", targetPayload.Move(), allocator);
@@ -780,6 +817,7 @@ void sendData () {
document.AddMember("userData", userData.Move(), allocator);
document.AddMember("limits", limits.Move(), allocator);
document.AddMember("options", options.Move(), allocator);
document.AddMember("sbPlanned", sbPlanned.Move(), allocator);
// Write to CommBus
document.Accept(writer);
+9 -1
View File
@@ -18,7 +18,7 @@
//PMC pallet due to 104in door
#define MAX_FRONT_CARGO(IS_IMPERIAL) ((IS_IMPERIAL) ? (6.0 * 15000.0) : (6.0 * 6804.0))
#define MAX_UPPER_CARGO(IS_IMPERIAL) ((IS_IMPERIAL) ? (6.5 * 15000.0) : (6.5 * 6804.0))
//LD3s due to 70in door
//LD3s due to 70in door, ER option takes up two slots
#define MAX_REAR_CARGO(IS_IMPERIAL, IS_ER) ((IS_IMPERIAL) ? ((IS_ER ? 12.0 : 14.0) * 3500.0) : ((IS_ER ? 12.0 : 14.0) * 1588.0))
// All actual Business seats
@@ -187,6 +187,10 @@ typedef struct {
unsigned char economy2;
unsigned short total;
} paxCount;
struct sbPlanned {
double ZFW;
double GW;
} sbPlanned;
} paxPayloadData_t;
typedef struct {
double pilot;
@@ -243,6 +247,10 @@ typedef struct {
unsigned int upper4;
unsigned int total;
} stations;
struct sbPlanned {
double ZFW;
double GW;
} sbPlanned;
} fPayloadData_t;
typedef struct {
// SimConnect mapped