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

Refatorar Auto Focus #625

Merged
merged 2 commits into from
Oct 10, 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
16 changes: 4 additions & 12 deletions api/Main.run.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false"
name="Main"
type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME"
value="nebulosa.api.MainKt"/>
<configuration default="false" name="Main" type="JetRunConfigurationType">
<option name="MAIN_CLASS_NAME" value="nebulosa.api.MainKt"/>
<module name="nebulosa.api.main"/>
<option name="PROGRAM_PARAMETERS"
value="--port=7000"/>
<option name="PROGRAM_PARAMETERS" value="--port=7000 --debug"/>
<shortenClasspath name="NONE"/>
<method v="2">
<option name="Gradle.BeforeRunTask"
enabled="true"
tasks="build"
externalProjectPath="$PROJECT_DIR$/api"
vmOptions=""
<option name="Gradle.BeforeRunTask" enabled="true" tasks="build" externalProjectPath="$PROJECT_DIR$/api" vmOptions=""
scriptParameters="-x test"/>
</method>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(project(":nebulosa-astap"))
implementation(project(":nebulosa-astrometrynet"))
implementation(project(":nebulosa-alpaca-indi"))
implementation(project(":nebulosa-autofocus"))
implementation(project(":nebulosa-curve-fitting"))
implementation(project(":nebulosa-guiding-phd2"))
implementation(project(":nebulosa-hips2fits"))
Expand Down
21 changes: 11 additions & 10 deletions api/src/main/kotlin/nebulosa/api/Nebulosa.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nebulosa.api

import ch.qos.logback.classic.Level
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
Expand All @@ -14,6 +15,7 @@ import nebulosa.api.inject.*
import nebulosa.json.PathModule
import nebulosa.log.loggerFor
import org.koin.core.context.startKoin
import org.slf4j.LoggerFactory
import java.util.concurrent.ConcurrentHashMap

@Command(name = "nebulosa")
Expand All @@ -25,9 +27,18 @@ class Nebulosa : Runnable, AutoCloseable {
@Option(name = ["-p", "--port"])
private var port = 0

@Option(name = ["-d", "--debug"])
private var debug = false

private lateinit var app: Javalin

override fun run() {
if (debug) {
with(LoggerFactory.getLogger("nebulosa") as ch.qos.logback.classic.Logger) {
level = Level.DEBUG
}
}

// Run the server.
app = Javalin.create { config ->
config.showJavalinBanner = false
Expand Down Expand Up @@ -55,16 +66,6 @@ class Nebulosa : Runnable, AutoCloseable {
app.stop()
}

private data object LocationConverter : (String) -> Location? {

private val CACHED_LOCATION = ConcurrentHashMap<String, Location>(4)

override fun invoke(value: String): Location? {
return if (value.isBlank()) null
else CACHED_LOCATION.computeIfAbsent(value) { OBJECT_MAPPER.readValue(value, Location::class.java) }
}
}

companion object {

@JvmStatic private val LOG = loggerFor<Nebulosa>()
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/kotlin/nebulosa/api/atlas/IERSUpdateTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ class IERSUpdateTask(
.use { it.headers.getDate(Header.LAST_MODIFIED) }

if (modifiedAt != null && "$modifiedAt" == preferenceService.getText(key)) {
LOG.info("$url is up to date. modifiedAt={}", modifiedAt)
LOG.info("{} is up to date. modifiedAt={}", url, modifiedAt)
return
}

request = request.newBuilder().get().build()

LOG.info("downloading $url")
LOG.debug("downloading {}", url)

httpClient.newCall(request).execute().use {
it.body!!.byteStream().transferAndClose(outputStream())
modifiedAt = it.headers.getDate(Header.LAST_MODIFIED)
preferenceService.putText(key, "$modifiedAt")
LOG.info("$url downloaded. modifiedAt={}", modifiedAt)
LOG.debug("{} downloaded. modifiedAt={}", url, modifiedAt)
}
} catch (e: Throwable) {
LOG.error("failed to download finals2000A.all", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.javalin.http.Context
import io.javalin.http.bodyAsClass
import nebulosa.api.connection.ConnectionService
import nebulosa.api.javalin.notNull
import nebulosa.api.javalin.valid

class AutoFocusController(
app: Javalin,
Expand All @@ -21,7 +22,7 @@ class AutoFocusController(
private fun start(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
val focuser = connectionService.focuser(ctx.pathParam("focuser")).notNull()
val body = ctx.bodyAsClass<AutoFocusRequest>()
val body = ctx.bodyAsClass<AutoFocusRequest>().valid()
autoFocusService.start(camera, focuser, body)
}

Expand Down
Loading