From 3ebdc170d91df6d6e321ff8a91073ca674c0db60 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 15 May 2024 15:22:10 +0200 Subject: [PATCH 1/3] Add integer value to the ClockSyncMode enum which matches reactor-c enum --- .../target/property/type/ClockSyncModeType.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java b/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java index 72ec1f8d1a..1ea37c20d0 100644 --- a/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java +++ b/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java @@ -17,17 +17,25 @@ protected Class enumClass() { *
  • STARTUP: Clock synchronization occurs at startup only. *
  • ON: Clock synchronization occurs at startup and at runtime. * - * + * 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; + } } } From 91ef875dc132cd09511b9c069a73669b7fd6d747 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 15 May 2024 15:22:28 +0200 Subject: [PATCH 2/3] Always explicitly set the desired clock-sync mode --- .../federated/extensions/CExtensionUtils.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java index d65ff0658d..be0b8b7cb3 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -253,8 +253,9 @@ public static void initializeClockSynchronization( .nowhere() .info("Runtime clock synchronization is enabled for federate " + federate.id); } - addClockSyncCompileDefinitions(federate); + } else { + addDisableClockSyncCompileDefinitions(federate); } } @@ -272,20 +273,25 @@ public static void addClockSyncCompileDefinitions(FederateInstance federate) { ClockSyncOptions options = federate.targetConfig.get(ClockSyncOptionsProperty.INSTANCE); final var defs = new HashMap(); + 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(); + 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 { From 7cfa09e37c48ea6d910e45543743dda78dcc75b1 Mon Sep 17 00:00:00 2001 From: erlingrj Date: Wed, 15 May 2024 16:07:42 +0200 Subject: [PATCH 3/3] Spotless --- .../org/lflang/federated/extensions/CExtensionUtils.java | 7 +++---- .../org/lflang/target/property/type/ClockSyncModeType.java | 7 +++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java index be0b8b7cb3..1ef19bcd79 100644 --- a/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java +++ b/core/src/main/java/org/lflang/federated/extensions/CExtensionUtils.java @@ -279,9 +279,9 @@ public static void addClockSyncCompileDefinitions(FederateInstance federate) { defs.put("_LF_CLOCK_SYNC_EXCHANGES_PER_INTERVAL", String.valueOf(options.trials)); defs.put("_LF_CLOCK_SYNC_ATTENUATION", String.valueOf(options.attenuation)); - 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); } @@ -291,7 +291,6 @@ public static void addDisableClockSyncCompileDefinitions(FederateInstance federa CompileDefinitionsProperty.INSTANCE.update(federate.targetConfig, defs); } - /** Generate a file to be included by CMake. */ public static void generateCMakeInclude( FederateInstance federate, FederationFileConfig fileConfig) throws IOException { diff --git a/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java b/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java index 1ea37c20d0..a89866a650 100644 --- a/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java +++ b/core/src/main/java/org/lflang/target/property/type/ClockSyncModeType.java @@ -17,8 +17,9 @@ protected Class enumClass() { *
  • STARTUP: Clock synchronization occurs at startup only. *
  • ON: Clock synchronization occurs at startup and at runtime. * - * The values associated with the enum must match what is defined in - * clock_sync.h in reactor-c + * + * 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 { @@ -26,6 +27,7 @@ public enum ClockSyncMode { INIT(2), ON(3); private final int value; + private ClockSyncMode(int value) { this.value = value; } @@ -34,6 +36,7 @@ private ClockSyncMode(int value) { public String toString() { return this.name().toLowerCase(); } + public int toInt() { return this.value; }