use offsetof instead of generated offset defines (#4696)

* constify efi_gpio, use size_t

* use offsetof instead of macros

* don't generate offsets in rusefi_generated.h

* comment explaining the madness

* java fixes

* casing
This commit is contained in:
Matthew Kennedy 2022-10-23 13:39:18 -07:00 committed by GitHub
parent 4bcc61a588
commit 2924d98609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 14 deletions

View File

@ -107,11 +107,15 @@ void RegisteredOutputPin::unregister() {
}
}
#define CONFIG_OFFSET(x) x##_offset
#define CONFIG_OFFSET(x) (offsetof(engine_configuration_s, x))
// todo: pin and pinMode should be combined into a composite entity
// todo: one of the impediments is code generator hints handling (we need custom hints and those are not handled nice for fields of structs?)
#define CONFIG_PIN_OFFSETS(x) CONFIG_OFFSET(x##Pin), CONFIG_OFFSET(x##PinMode)
// offset of X within engineConfiguration, plus offset of Y within X
// decltype(engine_configuration_s::x) resolves the typename of the struct X inside engineConfiguration
#define CONFIG_OFFSET2(x, y) (offsetof(engine_configuration_s, x) + offsetof(decltype(engine_configuration_s::x), y))
#define CONFIG_PIN_OFFSETS2(x, y) CONFIG_OFFSET2(x, y##Pin), CONFIG_OFFSET2(x, y##PinMode)
EnginePins::EnginePins() :
mainRelay("Main Relay", CONFIG_PIN_OFFSETS(mainRelay)),
@ -123,8 +127,8 @@ EnginePins::EnginePins() :
acRelay("A/C Relay", CONFIG_PIN_OFFSETS(acRelay)),
fuelPumpRelay("Fuel pump Relay", CONFIG_PIN_OFFSETS(fuelPump)),
boostPin("Boost", CONFIG_PIN_OFFSETS(boostControl)),
idleSolenoidPin("Idle Valve", idle_solenoidPin_offset, idle_solenoidPinMode_offset),
secondIdleSolenoidPin("Idle Valve#2", CONFIG_OFFSET(secondSolenoidPin), idle_solenoidPinMode_offset),
idleSolenoidPin("Idle Valve", CONFIG_OFFSET2(idle, solenoidPin), CONFIG_OFFSET2(idle, solenoidPinMode)),
secondIdleSolenoidPin("Idle Valve#2", CONFIG_OFFSET(secondSolenoidPin), CONFIG_OFFSET2(idle, solenoidPinMode)),
alternatorPin("Alternator control", CONFIG_PIN_OFFSETS(alternatorControl)),
checkEnginePin("checkEnginePin", CONFIG_PIN_OFFSETS(malfunctionIndicator)),
tachOut("tachOut", CONFIG_PIN_OFFSETS(tachOutput)),

View File

@ -163,7 +163,7 @@ public class ConsoleTools {
private static void printCrc(ConfigurationImage image) {
for (int i = 0; i < Fields.ERROR_BUFFER_SIZE; i++)
image.getContent()[Fields.warning_message_offset + i] = 0;
image.getContent()[Fields.WARNING_MESSAGE.getOffset() + i] = 0;
int crc32 = getCrc32(image.getContent());
int crc16 = crc32 & 0xFFFF;
System.out.printf("tune_CRC32_hex=0x%x\n", crc32);

View File

@ -131,7 +131,7 @@ public class LuaScriptPanel {
scriptText.setText("No configuration image");
return;
}
ByteBuffer luaScriptBuffer = image.getByteBuffer(Fields.luaScript_offset, Fields.LUA_SCRIPT_SIZE);
ByteBuffer luaScriptBuffer = image.getByteBuffer(Fields.LUASCRIPT.getOffset(), Fields.LUA_SCRIPT_SIZE);
byte[] scriptArr = new byte[Fields.LUA_SCRIPT_SIZE];
luaScriptBuffer.get(scriptArr);
@ -166,7 +166,7 @@ public class LuaScriptPanel {
remaining = paddedScript.length - idx;
int thisWrite = Math.min(remaining, Fields.BLOCKING_FACTOR);
bp.writeData(paddedScript, idx, Fields.luaScript_offset + idx, thisWrite);
bp.writeData(paddedScript, idx, Fields.LUASCRIPT.getOffset() + idx, thisWrite);
idx += thisWrite;

Binary file not shown.

View File

@ -15,7 +15,7 @@ public class OutputsSectionConsumer implements ConfigurationConsumer {
public OutputsSectionConsumer(String tsOutputsSectionFileName) {
this.tsOutputsSectionFileName = tsOutputsSectionFileName;
tsOutput = new TsOutput(false, false);
tsOutput = new TsOutput(false);
}
public String getContent() {

View File

@ -27,7 +27,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
public TSProjectConsumer(String tsPath, ReaderState state) {
this.tsPath = tsPath;
tsOutput = new TsOutput(true, true);
tsOutput = new TsOutput(true);
this.state = state;
}

View File

@ -18,12 +18,10 @@ public class TsOutput {
private static final int MSQ_LENGTH_LIMIT = 34;
private final StringBuilder settingContextHelp = new StringBuilder();
private final boolean isConstantsSection;
private final boolean registerOffsets;
private final StringBuilder tsHeader = new StringBuilder();
public TsOutput(boolean longForm, boolean registerOffsets) {
public TsOutput(boolean longForm) {
this.isConstantsSection = longForm;
this.registerOffsets = registerOffsets;
}
public String getContent() {
@ -68,9 +66,6 @@ public class TsOutput {
// throw new IllegalStateException("[" + commentContent + "] is too long for rusEFI online");
settingContextHelp.append("\t" + nameWithPrefix + " = " + quote(commentContent) + EOL);
}
if (registerOffsets) {
state.variableRegistry.register(nameWithPrefix + "_offset", tsPosition);
}
if (cs != null) {
String extraPrefix = cs.withPrefix ? configField.getName() + "_" : "";