diff --git a/.gitignore b/.gitignore index c8576bdd93df369a43f91928035fa826dd45209d..078fbbcbdc9609428de74f1d2808d5f58985f198 100755 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,6 @@ distTmp/ outTmp/ /test.output /kotlin-native/dist -kotlin-ide/ \ No newline at end of file +kotlin-ide/ +config.yaml +config.yml diff --git a/build.gradle.kts b/build.gradle.kts index 4ad9650fa5ffb380fc33ed881231d054d35a513f..103e12336132dfa2fc753ac217d2402d3cce567b 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -92,6 +92,10 @@ dependencies { runtimeOnly("io.grpc:grpc-netty-shaded:1.53.0") implementation(kotlin("stdlib-jdk8")) + + implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.2") + implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2") } tasks.test { diff --git a/config.example.yaml b/config.example.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f111cfea3fe60d99b59e653935a44a4732734ab6 --- /dev/null +++ b/config.example.yaml @@ -0,0 +1,2 @@ +PRODUCER_HOST: localhost +PRODUCER_PORT: 3333 diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 2fc5734c9d6aba3a1b60e4033c3e944833404632..e977547d73b83dadfeb89f010c860a6bc55c4130 100755 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,4 +1,5 @@ import Service.FlowDrawer +import config.Configuration import connection.Connection import drawing.Color import drawing.ColorInterpolation @@ -12,7 +13,7 @@ import sun.misc.Signal fun main(args: Array<String>) { println("Radar Viewer") - val conn = Connection("localhost", 3333) + val conn = Connection(Configuration.producerHost, Configuration.producerPort) val processRepo = ProcessedClient(conn) // Try adding program arguments via Run/Debug configuration. @@ -25,10 +26,10 @@ fun main(args: Array<String>) { throw Exception("Unable to create GLFW") } - val (ppiZdbFetcher, ppiZdbDrawer) = FlowDrawer("PPI ZDB", processRepo.getPpiZdb(), -10.0, 50.0).draw() - val (ppiZdrFetcher, ppiZdrDrawer) = FlowDrawer("PPI ZDR", processRepo.getPpiZdr(), -4.0, 6.0).draw() - val (cappiZdbFetcher, cappiZdbDrawer) = FlowDrawer("CAPPI ZDB", processRepo.getCappiZdb(), -10.0, 50.0).draw() - val (cappiZdrFetcher, cappiZdrDrawer) = FlowDrawer("CAPPI ZDR", processRepo.getCappiZdr(), -4.0, 6.0).draw() + val (ppiZdbFetcher, ppiZdbDrawer) = FlowDrawer("PPI ZDB", processRepo.getPpiZdb(), Configuration.zdbMinValue, Configuration.zdbMaxValue).draw() + val (ppiZdrFetcher, ppiZdrDrawer) = FlowDrawer("PPI ZDR", processRepo.getPpiZdr(), Configuration.zdrMinValue, Configuration.zdrMaxValue).draw() + val (cappiZdbFetcher, cappiZdbDrawer) = FlowDrawer("CAPPI ZDB", processRepo.getCappiZdb(), Configuration.zdbMinValue, Configuration.zdbMaxValue).draw() + val (cappiZdrFetcher, cappiZdrDrawer) = FlowDrawer("CAPPI ZDR", processRepo.getCappiZdr(), Configuration.zdrMinValue, Configuration.zdrMaxValue).draw() Signal.handle(Signal("INT")) { ppiZdrDrawer.cancel() @@ -43,7 +44,9 @@ fun main(args: Array<String>) { } runBlocking { -// joinAll(ppiZdbFetcher, ppiZdrFetcher, ppiZdrDrawer, ppiZdbDrawer) - joinAll(cappiZdbFetcher, cappiZdrFetcher, cappiZdrDrawer, cappiZdbDrawer) + joinAll(ppiZdrFetcher, ppiZdrDrawer) + joinAll(cappiZdrFetcher, cappiZdrDrawer) + joinAll(ppiZdbFetcher, ppiZdbDrawer) + joinAll(cappiZdbFetcher, cappiZdbDrawer) } } \ No newline at end of file diff --git a/src/main/kotlin/config/Configuration.kt b/src/main/kotlin/config/Configuration.kt new file mode 100644 index 0000000000000000000000000000000000000000..53c2f1c997ddcd4cc7cf2a97519f321fcc47390e --- /dev/null +++ b/src/main/kotlin/config/Configuration.kt @@ -0,0 +1,15 @@ +package config + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import com.fasterxml.jackson.module.kotlin.registerKotlinModule +import java.io.File + +fun getConfig(): ConfigurationSchema { + val configurationLocation = System.getenv("CONFIG_PATH") ?: "config.yaml" + + val mapper = ObjectMapper(YAMLFactory()).registerKotlinModule() + return mapper.readValue(File(configurationLocation), ConfigurationSchema::class.java) ?: ConfigurationSchema() +} + +val Configuration = getConfig() diff --git a/src/main/kotlin/config/ConfigurationSchema.kt b/src/main/kotlin/config/ConfigurationSchema.kt new file mode 100644 index 0000000000000000000000000000000000000000..95e746f1f25c79979ef3b16dcbdcdae7b1ee10e6 --- /dev/null +++ b/src/main/kotlin/config/ConfigurationSchema.kt @@ -0,0 +1,15 @@ +package config + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties +import com.fasterxml.jackson.annotation.JsonProperty + +@JsonIgnoreProperties(ignoreUnknown = true) +data class ConfigurationSchema ( + @get:JsonProperty("PRODUCER_HOST") val producerHost: String = "localhost", + @get:JsonProperty("PRODUCER_PORT") val producerPort: Int = 3333, + @get:JsonProperty("SECTOR_COUNT") val sectorCount: Int = 143, + @get:JsonProperty("ZDB_MIN_VALUE") val zdbMinValue: Double = -10.0, + @get:JsonProperty("ZDB_MAX_VALUE") val zdbMaxValue: Double = 50.0, + @get:JsonProperty("ZDR_MIX_VALUE") val zdrMinValue: Double = -4.0, + @get:JsonProperty("ZDR_MAX_VALUE") val zdrMaxValue: Double = 6.0, +)