More fragment refactoring: encode by type, not enum index (#4075)

* fragment refactoring

* jar

* jar?

* look up fragment by type, not index

* don't even include that

* jar again

* jar again

* unit tests are happy

* guards

* jar

* hpfp guarding

* handle knock controller

* jar

* s

* stub multiple for each

* jar

* Update live_data.cpp

* s

* s
This commit is contained in:
Matthew Kennedy 2022-06-18 14:23:44 +01:00 committed by GitHub
parent 6931862fba
commit 7cc09ade6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 172 additions and 49 deletions

View File

@ -1,27 +0,0 @@
// generated by gen_live_documentation.sh / UsagesReader.java
#include "pch.h"
#include "tunerstudio.h"
static const FragmentEntry fragments[] = {
reinterpret_cast<const output_channels_s*>(getStructAddr(LDS_output_channels)),
reinterpret_cast<const knock_controller_s*>(getStructAddr(LDS_knock_controller)),
reinterpret_cast<const high_pressure_fuel_pump_s*>(getStructAddr(LDS_high_pressure_fuel_pump)),
reinterpret_cast<const injector_model_s*>(getStructAddr(LDS_injector_model)),
reinterpret_cast<const launch_control_state_s*>(getStructAddr(LDS_launch_control_state)),
reinterpret_cast<const boost_control_s*>(getStructAddr(LDS_boost_control)),
reinterpret_cast<const ac_control_s*>(getStructAddr(LDS_ac_control)),
reinterpret_cast<const fan_control_s*>(getStructAddr(LDS_fan_control)),
reinterpret_cast<const fuel_pump_control_s*>(getStructAddr(LDS_fuel_pump_control)),
reinterpret_cast<const main_relay_s*>(getStructAddr(LDS_main_relay)),
reinterpret_cast<const engine_state_s*>(getStructAddr(LDS_engine_state)),
reinterpret_cast<const tps_accel_state_s*>(getStructAddr(LDS_tps_accel_state)),
reinterpret_cast<const trigger_central_s*>(getStructAddr(LDS_trigger_central)),
reinterpret_cast<const trigger_state_s*>(getStructAddr(LDS_trigger_state)),
reinterpret_cast<const wall_fuel_state_s*>(getStructAddr(LDS_wall_fuel_state)),
reinterpret_cast<const idle_state_s*>(getStructAddr(LDS_idle_state)),
reinterpret_cast<const ignition_state_s*>(getStructAddr(LDS_ignition_state)),
reinterpret_cast<const electronic_throttle_s*>(getStructAddr(LDS_electronic_throttle)),
};
FragmentList getFragments() {
return { fragments, efi::size(fragments) };
}

View File

@ -0,0 +1,141 @@
#include "pch.h"
#include "tunerstudio.h"
template <typename TStruct>
const TStruct* getLiveDataAddr();
template <typename TStruct>
const TStruct* getLiveDataAddr(size_t index);
template<>
const output_channels_s* getLiveDataAddr() {
return &engine->outputChannels;
}
template<>
const knock_controller_s* getLiveDataAddr() {
return &engine->module<KnockController>().unmock();
}
template<>
const high_pressure_fuel_pump_s* getLiveDataAddr() {
#if EFI_HPFP
return &engine->module<HpfpController>().unmock();
#else
return nullptr; // explicit null to confirm that this struct is handled
#endif // EFI_HPFP
}
template<>
const launch_control_state_s* getLiveDataAddr() {
#if EFI_LAUNCH_CONTROL
return &engine->launchController;
#else
return nullptr;
#endif
}
template<>
const injector_model_s* getLiveDataAddr() {
return &engine->module<InjectorModel>().unmock();
}
template<>
const boost_control_s* getLiveDataAddr() {
#if EFI_BOOST_CONTROL
return &engine->boostController;
#else
return nullptr;
#endif
}
template<>
const ac_control_s* getLiveDataAddr() {
return &engine->module<AcController>().unmock();
}
template<>
const fan_control_s* getLiveDataAddr() {
return &engine->fan1;
}
template<>
const fuel_pump_control_s* getLiveDataAddr() {
return &engine->module<FuelPumpController>().unmock();
}
template<>
const main_relay_s* getLiveDataAddr() {
return &engine->module<MainRelayController>().unmock();
}
template<>
const engine_state_s* getLiveDataAddr() {
return &engine->engineState;
}
template<>
const tps_accel_state_s* getLiveDataAddr() {
return &engine->tpsAccelEnrichment;
}
template<>
const trigger_central_s* getLiveDataAddr() {
return &engine->triggerCentral;
}
template<>
const trigger_state_s* getLiveDataAddr(size_t idx) {
#if EFI_SHAFT_POSITION_INPUT
switch (idx) {
case 0: return &engine->triggerCentral.triggerState;
case 1: return &engine->triggerCentral.vvtState[0][0];
case 2: return &engine->triggerCentral.vvtState[0][1];
case 3: return &engine->triggerCentral.vvtState[1][0];
case 4: return &engine->triggerCentral.vvtState[1][1];
default: return nullptr;
}
#else
return nullptr;
#endif
}
template<>
const wall_fuel_state_s* getLiveDataAddr() {
return &engine->injectionEvents.elements[0].wallFuel;
}
template<>
const idle_state_s* getLiveDataAddr() {
return &engine->module<IdleController>().unmock();
}
template<>
const ignition_state_s* getLiveDataAddr() {
return &engine->ignitionState;
}
template<>
const electronic_throttle_s* getLiveDataAddr() {
// todo: figure out how to handle two units?
// return engine->etbControllers[0];
return nullptr;
}
#if EFI_UNIT_TEST
FragmentList getLiveDataFragments() {
return { nullptr, 0 };
}
#else
static const FragmentEntry fragments[] = {
// This header is generated - do not edit by hand!
#include "live_data_fragments.h"
};
FragmentList getLiveDataFragments() {
return { fragments, efi::size(fragments) };
}
#endif

View File

@ -0,0 +1,3 @@
#pragma once
FragmentList getLiveDataFragments();

View File

@ -39,8 +39,6 @@ const void * getStructAddr(live_data_e structId);
#include "thread_controller.h"
#include "thread_priority.h"
FragmentList getFragments();
void updateTunerStudioState();
void requestBurn(void);

View File

@ -2,7 +2,7 @@
TUNERSTUDIO_SRC_CPP = $(PROJECT_DIR)/console/binary/tunerstudio_io.cpp \
$(PROJECT_DIR)/console/binary/tunerstudio_io_serial.cpp \
$(PROJECT_DIR)/console/binary/tunerstudio_io_serial_ports.cpp \
$(PROJECT_DIR)/console/binary/generated/live_data_fragments.cpp \
$(PROJECT_DIR)/console/binary/generated/live_data.cpp \
$(PROJECT_DIR)/console/binary/ts_can_channel.cpp \
$(PROJECT_DIR)/console/binary/serial_can.cpp \
$(PROJECT_DIR)/console/binary/tunerstudio.cpp \

View File

@ -4,6 +4,8 @@
#include "tunerstudio.h"
#include "tunerstudio_io.h"
#include "live_data.h"
#include "status_loop.h"
#if EFI_TUNER_STUDIO
@ -53,7 +55,7 @@ void TunerStudio::cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, u
/**
* collect data from all models
*/
copyRange(scratchBuffer + 3, getFragments(), offset, count);
copyRange(scratchBuffer + 3, getLiveDataFragments(), offset, count);
tsChannel->crcAndWriteBuffer(TS_RESPONSE_OK, count);
}

Binary file not shown.

View File

@ -31,10 +31,7 @@ public class UsagesReader {
private final StringBuilder fancyNewMenu = new StringBuilder();
private final StringBuilder fragmentsContent = new StringBuilder(
header +
"#include \"pch.h\"\n" +
"#include \"tunerstudio.h\"\n");
private final StringBuilder fragmentsContent = new StringBuilder(header);
public static void main(String[] args) throws IOException {
if (args.length != 1) {
@ -115,8 +112,6 @@ public class UsagesReader {
ArrayList<LinkedHashMap> liveDocs = (ArrayList<LinkedHashMap>)data.get("Usages");
fragmentsContent.append("static const FragmentEntry fragments[] = {\n");
for (LinkedHashMap entry : liveDocs) {
String name = (String)entry.get("name");
String java = (String)entry.get("java");
@ -146,23 +141,34 @@ public class UsagesReader {
String type = name + "_s"; // convention
enumContent.append(enumName + ",\n");
fragmentsContent
.append("\treinterpret_cast<const ")
.append(type)
.append("*>(getStructAddr(")
.append(enumName)
.append(")),\n");
if (outputNamesArr.length < 2) {
fragmentsContent
.append("getLiveDataAddr<")
.append(type)
.append(">(),\n");
} else {
for (int i = 0; i < outputNamesArr.length; i++) {
if (i != 0) {
// TODO: remove once the rest of the handling for multiple copies of one struct is in place.
fragmentsContent.append("// ");
}
fragmentsContent
.append("getLiveDataAddr<")
.append(type)
.append(">(")
.append(i)
.append("),\t// ")
.append(outputNamesArr[i])
.append("\n");
}
}
}
enumContent.append("} live_data_e;\n");
totalSensors.append(javaSensorsConsumer.getContent());
fragmentsContent
.append("};\n\n")
.append("FragmentList getFragments() {\n\treturn { fragments, efi::size(fragments) };\n}\n");
return javaSensorsConsumer.sensorTsPosition;
}
private void writeFiles() throws IOException {
@ -170,7 +176,7 @@ public class UsagesReader {
fw.write(enumContent.toString());
}
try (FileWriter fw = new FileWriter("console/binary/generated/live_data_fragments.cpp")) {
try (FileWriter fw = new FileWriter("console/binary/generated/live_data_fragments.h")) {
fw.write(fragmentsContent.toString());
}
}