Skip to content

Commit

Permalink
Refactor formatOutgoingString and allow string output
Browse files Browse the repository at this point in the history
Renamed formatOutgoingString to formatOutgoingFloat and created a new method for formatting strings, called formatOutgoingString. Also added string output handling in the dashboard and other necessary changes across files. Adjusted automated tests and made related minor changes and tweaks in other parts of the code to align with this change.
  • Loading branch information
BitsAndDroids committed Dec 7, 2023
1 parent 03bb162 commit 1dbd233
Show file tree
Hide file tree
Showing 8 changed files with 499 additions and 380 deletions.
33 changes: 31 additions & 2 deletions dashboard/workers/MFSWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ struct StructOneDatum {
float value;
};

struct StructString {
int id;
char value[256];
};

float dualDataRecv = 1.2f;

enum EVENT_ID {
Expand All @@ -38,6 +43,7 @@ struct dataStr {

enum DATA_DEFINE_ID {
DEFINITION_PDR_RADIO,
DEFINITION_STRING,
DEFINITION_1 = 12,

};
Expand All @@ -46,6 +52,10 @@ struct StructDatum {
StructOneDatum datum[MAX_RETURNED_ITEMS];
};

struct StructDatumString {
StructString datum_string[MAX_RETURNED_ITEMS];
};

enum DATA_REQUEST_ID {
REQUEST_PDR_RADIO,
REQUEST_STRING,
Expand Down Expand Up @@ -144,7 +154,7 @@ void MFSWorker::MyDispatchProcInput(SIMCONNECT_RECV *pData, DWORD cbData,

auto *data = (dataStr *) &pObjData->dwData;
if (pObjData->dwRequestID > 999 && pObjData->dwRequestID < 9999) {
dualCast->sendToArduino(dualCast->converter.formatOutgoingString(data->val, *output), i);
dualCast->sendToArduino(dualCast->converter.formatOutgoingFloat(data->val, *output), i);
}
}
}
Expand All @@ -165,7 +175,7 @@ void MFSWorker::MyDispatchProcInput(SIMCONNECT_RECV *pData, DWORD cbData,
if (dualCast->comBundles->at(i)->isOutputInBundle(
output->getId())) {
dualCast->sendToArduino(
dualCast->converter.formatOutgoingString(pS->datum[count].value, *output), i);
dualCast->converter.formatOutgoingFloat(pS->datum[count].value, *output), i);
}
}

Expand All @@ -174,6 +184,18 @@ void MFSWorker::MyDispatchProcInput(SIMCONNECT_RECV *pData, DWORD cbData,
}
break;
}
case REQUEST_STRING: {
auto pS = reinterpret_cast<StructDatumString *>(&pObjData->dwData);
int id = pS->datum_string[0].id;
Output *output = dualCast->outputHandler.findOutputById(id);
for (int i = 0; i < dualCast->comBundles->size(); i++) {
if (dualCast->comBundles->at(i)->isOutputInBundle(output->getId())) {
dualCast->sendToArduino(
dualCast->converter.formatOutgoingString(pS->datum_string[0].value, *output), i);
}
}
break;
}
case SIMCONNECT_RECV_ID_QUIT: {
// quit = 1;
dualCast->setConnected(false);
Expand Down Expand Up @@ -306,6 +328,7 @@ void MFSWorker::eventLoop() {
SIMCONNECT_CLIENT_DATA_PERIOD_SECOND,
SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_DEFAULT);


dualOutputMapper->mapOutputs(outputsToMap, dualSimConnect);
SimConnect_SubscribeToSystemEvent(dualSimConnect, EVENT_SIM_START,
"6Hz");
Expand All @@ -315,6 +338,12 @@ void MFSWorker::eventLoop() {
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME,
SIMCONNECT_DATA_REQUEST_FLAG_CHANGED |
SIMCONNECT_DATA_REQUEST_FLAG_TAGGED);
SimConnect_RequestDataOnSimObject(
dualSimConnect, REQUEST_STRING, DEFINITION_STRING,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_VISUAL_FRAME,
SIMCONNECT_DATA_REQUEST_FLAG_CHANGED |
SIMCONNECT_DATA_REQUEST_FLAG_TAGGED);


while (!abortDual && connected) {
SimConnect_CallDispatch(dualSimConnect, MyDispatchProcInput, this);
Expand Down
Loading

0 comments on commit 1dbd233

Please sign in to comment.