Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code-generator changes required for reactor-c clock-sync fix #2285

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ public static void initializeClockSynchronization(
.nowhere()
.info("Runtime clock synchronization is enabled for federate " + federate.id);
}

addClockSyncCompileDefinitions(federate);
} else {
addDisableClockSyncCompileDefinitions(federate);
}
}

Expand All @@ -272,20 +273,24 @@ public static void addClockSyncCompileDefinitions(FederateInstance federate) {
ClockSyncOptions options = federate.targetConfig.get(ClockSyncOptionsProperty.INSTANCE);
final var defs = new HashMap<String, String>();

defs.put("LF_CLOCK_SYNC", String.valueOf(mode.toInt()));
defs.put("_LF_CLOCK_SYNC_INITIAL", "");
defs.put("_LF_CLOCK_SYNC_PERIOD_NS", String.valueOf(options.period.toNanoSeconds()));
defs.put("_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL", String.valueOf(options.trials));
defs.put("_LF_CLOCK_SYNC_ATTENUATION", String.valueOf(options.attenuation));

if (mode == ClockSyncMode.ON) {
defs.put("_LF_CLOCK_SYNC_ON", "");
if (options.collectStats) {
defs.put("_LF_CLOCK_SYNC_COLLECT_STATS", "");
}
if (options.collectStats) {
defs.put("_LF_CLOCK_SYNC_COLLECT_STATS", "");
}
CompileDefinitionsProperty.INSTANCE.update(federate.targetConfig, defs);
}

public static void addDisableClockSyncCompileDefinitions(FederateInstance federate) {
final var defs = new HashMap<String, String>();
defs.put("LF_CLOCK_SYNC", String.valueOf(ClockSyncMode.OFF.toInt()));
CompileDefinitionsProperty.INSTANCE.update(federate.targetConfig, defs);
}

/** Generate a file to be included by CMake. */
public static void generateCMakeInclude(
FederateInstance federate, FederationFileConfig fileConfig) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@ protected Class<ClockSyncMode> enumClass() {
* <li>ON: Clock synchronization occurs at startup and at runtime.
* </ul>
*
* The values associated with the enum must match what is defined in clock_sync.h in reactor-c
*
* @author Edward A. Lee
*/
public enum ClockSyncMode {
OFF,
INIT,
ON;
OFF(1),
INIT(2),
ON(3);
private final int value;

private ClockSyncMode(int value) {
this.value = value;
}
/** Return the name in lower case. */
@Override
public String toString() {
return this.name().toLowerCase();
}

public int toInt() {
return this.value;
}
}
}
Loading