Skip to content

Commit

Permalink
[api]: Fixes & improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 9, 2024
1 parent aafe107 commit aec0e2e
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.javalin.Javalin
import io.javalin.http.Context
import io.javalin.http.bodyAsClass
import nebulosa.api.connection.ConnectionService
import nebulosa.api.javalin.notNull

class AutoFocusController(
app: Javalin,
Expand All @@ -18,19 +19,19 @@ class AutoFocusController(
}

private fun start(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val focuser = connectionService.focuser(ctx.pathParam("focuser"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
val focuser = connectionService.focuser(ctx.pathParam("focuser")).notNull()
val body = ctx.bodyAsClass<AutoFocusRequest>()
autoFocusService.start(camera, focuser, body)
}

private fun stop(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
autoFocusService.stop(camera)
}

private fun status(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
autoFocusService.status(camera)?.also(ctx::json)
}
}
6 changes: 3 additions & 3 deletions api/src/main/kotlin/nebulosa/api/autofocus/AutoFocusJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ data class AutoFocusJob(
}

val predictedFocusPoint = status.determinedFocusPoint ?: determineFinalFocusPoint()
val (minX, minY) = if (focusPoints.isEmpty()) CurvePoint.ZERO else focusPoints[0]
val (maxX, maxY) = if (focusPoints.isEmpty()) CurvePoint.ZERO else focusPoints[focusPoints.lastIndex]
val (minX, minY) = if (isEmpty()) CurvePoint.ZERO else first()
val (maxX, maxY) = if (isEmpty()) CurvePoint.ZERO else last()
status.chart = AutoFocusEvent.Chart(predictedFocusPoint, minX, minY, maxX, maxY, trendLineCurve, parabolicCurve, hyperbolicCurve)

status.state = AutoFocusState.CURVE_FITTED
Expand All @@ -191,7 +191,7 @@ data class AutoFocusJob(

private fun determineFinalFocusPoint(): CurvePoint? {
return when (request.fittingMode) {
AutoFocusFittingMode.TRENDLINES -> trendLineCurve!!.intersection
AutoFocusFittingMode.TRENDLINES -> trendLineCurve?.intersection
AutoFocusFittingMode.PARABOLIC -> parabolicCurve?.minimum
AutoFocusFittingMode.TREND_PARABOLIC -> parabolicCurve?.minimum?.midPoint(trendLineCurve!!.intersection)
AutoFocusFittingMode.HYPERBOLIC -> hyperbolicCurve?.minimum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CameraController(

private fun camera(ctx: Context) {
val id = ctx.pathParam("id")
val camera = connectionService.camera(id)!!
val camera = connectionService.camera(id).notNull()
ctx.json(camera)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.javalin.Javalin
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 SequencerController(
Expand All @@ -21,7 +22,7 @@ class SequencerController(
}

private fun start(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
val mount = ctx.queryParam("mount")?.let(connectionService::mount)
val wheel = ctx.queryParam("wheel")?.let(connectionService::wheel)
val focuser = ctx.queryParam("focuser")?.let(connectionService::focuser)
Expand All @@ -46,7 +47,7 @@ class SequencerController(
}

fun status(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
sequencerService.status(camera)?.also(ctx::json)
}
}
2 changes: 1 addition & 1 deletion api/src/main/kotlin/nebulosa/api/stacker/StackerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class StackerService(private val messageService: MessageService?) {
else if (path.isXisf()) path.xisf()
else return null

return image.use { it.firstOrNull { it is ImageHdu }?.header }?.let(::AnalyzedTarget)
return image.use { it.firstOrNull { hdu -> hdu is ImageHdu }?.header }?.let(::AnalyzedTarget)
}

private inner class AutoStackerMessageHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.javalin.Javalin
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 FlatWizardController(
Expand All @@ -19,18 +20,18 @@ class FlatWizardController(
}

private fun start(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
val body = ctx.bodyAsClass<FlatWizardRequest>().valid()
flatWizardService.start(camera, body)
}

private fun stop(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
flatWizardService.stop(camera)
}

private fun status(ctx: Context) {
val camera = connectionService.camera(ctx.pathParam("camera"))!!
val camera = connectionService.camera(ctx.pathParam("camera")).notNull()
flatWizardService.status(camera)?.also(ctx::json)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ data class ASCOMMount(
longitude = 0.0
latitude = 0.0
elevation = 0.0
dateTime = OffsetDateTime.now(SystemClock)!!
dateTime = OffsetDateTime.now(SystemClock)

axisRates.clear()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ internal abstract class INDIDevice : Device {
is DefNumberVector -> {
val properties = LinkedHashMap<String, NumberProperty>()

for (e in message) {
val property = NumberProperty(e.name, e.label, e.value)
for ((name, label, value) in message) {
val property = NumberProperty(name, label, value)
properties[property.name] = property
}

Expand All @@ -105,8 +105,8 @@ internal abstract class INDIDevice : Device {
is DefSwitchVector -> {
val properties = LinkedHashMap<String, SwitchProperty>()

for (e in message) {
val property = SwitchProperty(e.name, e.label, e.value)
for ((name, label, value) in message) {
val property = SwitchProperty(name, label, value)
properties[property.name] = property
}

Expand All @@ -120,8 +120,8 @@ internal abstract class INDIDevice : Device {
is DefTextVector -> {
val properties = LinkedHashMap<String, TextProperty>()

for (e in message) {
val property = TextProperty(e.name, e.label, e.value)
for ((name, label, value) in message) {
val property = TextProperty(name, label, value)
properties[property.name] = property
}

Expand All @@ -147,9 +147,9 @@ internal abstract class INDIDevice : Device {

vector.state = message.state

for (e in message) {
val property = vector[e.name] ?: continue
property.value = e.value
for ((name, value) in message) {
val property = vector[name] ?: continue
property.value = value
}

vector
Expand All @@ -159,9 +159,9 @@ internal abstract class INDIDevice : Device {

vector.state = message.state

for (e in message) {
val property = vector[e.name] ?: continue
property.value = e.value
for ((name, value) in message) {
val property = vector[name] ?: continue
property.value = value
}

vector
Expand All @@ -171,9 +171,9 @@ internal abstract class INDIDevice : Device {

vector.state = message.state

for (e in message) {
val property = vector[e.name] ?: continue
property.value = e.value
for ((name, value) in message) {
val property = vector[name] ?: continue
property.value = value
}

vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class PHD2Client : NettyClient() {

@JvmStatic private val LOG = loggerFor<PHD2Client>()

@JvmStatic private val MODULE = kotlinModule().also {
it.addDeserializer(GuideState::class.java, GuideStateDeserializer)
it.addSerializer(GuideStateSerializer)
@JvmStatic private val MODULE = with(kotlinModule()) {
addDeserializer(GuideState::class.java, GuideStateDeserializer)
addSerializer(GuideStateSerializer)
}

@JvmStatic private val JSON_MAPPER = jsonMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import nebulosa.guiding.GuideState

data object GuideStateDeserializer : StdDeserializer<GuideState>(GuideState::class.java) {

private fun readResolve(): Any = GuideStateDeserializer

override fun deserialize(p: JsonParser, ctxt: DeserializationContext): GuideState? {
return p.valueAsString?.let(GUIDE_STATE_NAMES::get)
}
Expand Down
1 change: 0 additions & 1 deletion nebulosa-test/src/main/kotlin/nebulosa/test/Http.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@file:JvmName("Http")
@file:Suppress("NOTHING_TO_INLINE")

package nebulosa.test

Expand Down
4 changes: 0 additions & 4 deletions nebulosa-test/src/main/kotlin/nebulosa/test/Matchers.kt

This file was deleted.

7 changes: 4 additions & 3 deletions nebulosa-time/src/main/kotlin/nebulosa/time/SystemClock.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package nebulosa.time

import java.time.Clock
import java.time.Instant
import java.time.ZoneId

object SystemClock : Clock() {

private val clock = systemDefaultZone()

override fun getZone() = ZoneId.systemDefault()
override fun getZone(): ZoneId = ZoneId.systemDefault()

override fun withZone(zone: ZoneId) = clock.withZone(zone)
override fun withZone(zone: ZoneId): Clock = clock.withZone(zone)

override fun instant() = clock.instant()
override fun instant(): Instant = clock.instant()
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class XisfHeaderInputStream(source: InputStream) : AutoCloseable {
}

private fun parseProperty(): HeaderCard? {
val id = reader.attribute("id")!!
val id = reader.attribute("id") ?: return null
val key = AstronomicalImageProperties[id] ?: return null
val propertyType = XisfPropertyType.fromTypeName(reader.attribute("type")!!) ?: return null
val propertyType = XisfPropertyType.fromTypeName(reader.attribute("type") ?: return null) ?: return null
val value = reader.attribute("value") ?: reader.elementText.trim()
return XisfHeaderCard(key.key, value, key.comment, propertyType)
}
Expand Down

0 comments on commit aec0e2e

Please sign in to comment.