Skip to content

Commit

Permalink
[api]: Implement LightBox endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Aug 27, 2024
1 parent eee333a commit be5481d
Show file tree
Hide file tree
Showing 22 changed files with 340 additions and 202 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import nebulosa.indi.device.filterwheel.FilterWheel
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.gps.GPS
import nebulosa.indi.device.guider.GuideOutput
import nebulosa.indi.device.lightbox.LightBox
import nebulosa.indi.device.mount.Mount
import nebulosa.indi.device.rotator.Rotator
import nebulosa.indi.device.thermometer.Thermometer
Expand Down Expand Up @@ -41,6 +42,7 @@ class DeviceOrEntityParamMethodArgumentResolver(
Rotator::class.java to { connectionService.rotator(it) },
GPS::class.java to { connectionService.gps(it) },
GuideOutput::class.java to { connectionService.guideOutput(it) },
LightBox::class.java to { connectionService.lightBox(it) },
Thermometer::class.java to { connectionService.thermometer(it) },
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nebulosa.api.cameras

import nebulosa.api.beans.converters.device.DeviceDeserializer
import nebulosa.api.devices.DeviceDeserializer
import nebulosa.api.connection.ConnectionService
import nebulosa.indi.device.camera.Camera
import org.springframework.beans.factory.annotation.Autowired
Expand Down
139 changes: 66 additions & 73 deletions api/src/main/kotlin/nebulosa/api/cameras/CameraSerializer.kt
Original file line number Diff line number Diff line change
@@ -1,91 +1,84 @@
package nebulosa.api.cameras

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.api.devices.DeviceSerializer
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.camera.GuideHead
import org.springframework.stereotype.Component
import java.nio.file.Path

@Component
class CameraSerializer(private val capturesPath: Path) : StdSerializer<Camera>(Camera::class.java) {
class CameraSerializer(private val capturesPath: Path) : DeviceSerializer<Camera>(Camera::class.java) {

override fun serialize(value: Camera, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeStartObject()
gen.writeStringField("type", value.type.name)
gen.writeStringField("sender", value.sender.id)
gen.writeStringField("driverName", value.driverName)
gen.writeStringField("driverVersion", value.driverVersion)
gen.writeStringField("id", value.id)
gen.writeStringField("name", value.name)
gen.writeBooleanField("connected", value.connected)
gen.writeBooleanField("exposuring", value.exposuring)
gen.writeBooleanField("hasCoolerControl", value.hasCoolerControl)
gen.writeNumberField("coolerPower", value.coolerPower)
gen.writeBooleanField("cooler", value.cooler)
gen.writeBooleanField("hasDewHeater", value.hasDewHeater)
gen.writeBooleanField("dewHeater", value.dewHeater)
gen.writeObjectField("frameFormats", value.frameFormats)
gen.writeBooleanField("canAbort", value.canAbort)
gen.writeNumberField("cfaOffsetX", value.cfaOffsetX)
gen.writeNumberField("cfaOffsetY", value.cfaOffsetY)
gen.writeStringField("cfaType", value.cfaType.name)
gen.writeNumberField("exposureMin", value.exposureMin.toNanos() / 1000L)
gen.writeNumberField("exposureMax", value.exposureMax.toNanos() / 1000L)
gen.writeStringField("exposureState", value.exposureState.name)
gen.writeNumberField("exposureTime", value.exposureTime.toNanos() / 1000L)
gen.writeBooleanField("hasCooler", value.hasCooler)
gen.writeBooleanField("canSetTemperature", value.canSetTemperature)
gen.writeBooleanField("canSubFrame", value.canSubFrame)
gen.writeNumberField("x", value.x)
gen.writeNumberField("minX", value.minX)
gen.writeNumberField("maxX", value.maxX)
gen.writeNumberField("y", value.y)
gen.writeNumberField("minY", value.minY)
gen.writeNumberField("maxY", value.maxY)
gen.writeNumberField("width", value.width)
gen.writeNumberField("minWidth", value.minWidth)
gen.writeNumberField("maxWidth", value.maxWidth)
gen.writeNumberField("height", value.height)
gen.writeNumberField("minHeight", value.minHeight)
gen.writeNumberField("maxHeight", value.maxHeight)
gen.writeBooleanField("canBin", value.canBin)
gen.writeNumberField("maxBinX", value.maxBinX)
gen.writeNumberField("maxBinY", value.maxBinY)
gen.writeNumberField("binX", value.binX)
gen.writeNumberField("binY", value.binY)
gen.writeNumberField("gain", value.gain)
gen.writeNumberField("gainMin", value.gainMin)
gen.writeNumberField("gainMax", value.gainMax)
gen.writeNumberField("offset", value.offset)
gen.writeNumberField("offsetMin", value.offsetMin)
gen.writeNumberField("offsetMax", value.offsetMax)
gen.writeBooleanField("hasGuideHead", value.guideHead != null)
gen.writeNumberField("pixelSizeX", value.pixelSizeX)
gen.writeNumberField("pixelSizeY", value.pixelSizeY)
gen.writeBooleanField("canPulseGuide", value.canPulseGuide)
gen.writeBooleanField("pulseGuiding", value.pulseGuiding)
gen.writeBooleanField("hasThermometer", value.hasThermometer)
gen.writeNumberField("temperature", value.temperature)
gen.writeObjectField("capturesPath", Path.of("$capturesPath", value.name))
override fun JsonGenerator.serialize(value: Camera) {
writeBooleanField("exposuring", value.exposuring)
writeBooleanField("hasCoolerControl", value.hasCoolerControl)
writeNumberField("coolerPower", value.coolerPower)
writeBooleanField("cooler", value.cooler)
writeBooleanField("hasDewHeater", value.hasDewHeater)
writeBooleanField("dewHeater", value.dewHeater)
writeObjectField("frameFormats", value.frameFormats)
writeBooleanField("canAbort", value.canAbort)
writeNumberField("cfaOffsetX", value.cfaOffsetX)
writeNumberField("cfaOffsetY", value.cfaOffsetY)
writeStringField("cfaType", value.cfaType.name)
writeNumberField("exposureMin", value.exposureMin.toNanos() / 1000L)
writeNumberField("exposureMax", value.exposureMax.toNanos() / 1000L)
writeStringField("exposureState", value.exposureState.name)
writeNumberField("exposureTime", value.exposureTime.toNanos() / 1000L)
writeBooleanField("hasCooler", value.hasCooler)
writeBooleanField("canSetTemperature", value.canSetTemperature)
writeBooleanField("canSubFrame", value.canSubFrame)
writeNumberField("x", value.x)
writeNumberField("minX", value.minX)
writeNumberField("maxX", value.maxX)
writeNumberField("y", value.y)
writeNumberField("minY", value.minY)
writeNumberField("maxY", value.maxY)
writeNumberField("width", value.width)
writeNumberField("minWidth", value.minWidth)
writeNumberField("maxWidth", value.maxWidth)
writeNumberField("height", value.height)
writeNumberField("minHeight", value.minHeight)
writeNumberField("maxHeight", value.maxHeight)
writeBooleanField("canBin", value.canBin)
writeNumberField("maxBinX", value.maxBinX)
writeNumberField("maxBinY", value.maxBinY)
writeNumberField("binX", value.binX)
writeNumberField("binY", value.binY)
writeNumberField("gain", value.gain)
writeNumberField("gainMin", value.gainMin)
writeNumberField("gainMax", value.gainMax)
writeNumberField("offset", value.offset)
writeNumberField("offsetMin", value.offsetMin)
writeNumberField("offsetMax", value.offsetMax)
writeBooleanField("hasGuideHead", value.guideHead != null)
writeNumberField("pixelSizeX", value.pixelSizeX)
writeNumberField("pixelSizeY", value.pixelSizeY)
writeBooleanField("canPulseGuide", value.canPulseGuide)
writeBooleanField("pulseGuiding", value.pulseGuiding)
writeBooleanField("hasThermometer", value.hasThermometer)
writeNumberField("temperature", value.temperature)
writeObjectField("capturesPath", Path.of("$capturesPath", value.name))

if (value is GuideHead) {
gen.writeMainOrGuideHead(value.main, "main")
writeMainOrGuideHead(value.main, "main")
} else if (value.guideHead != null) {
gen.writeMainOrGuideHead(value.guideHead!!, "guideHead")
writeMainOrGuideHead(value.guideHead!!, "guideHead")
}

gen.writeEndObject()
}

private fun JsonGenerator.writeMainOrGuideHead(camera: Camera, fieldName: String) {
writeObjectFieldStart(fieldName)
writeStringField("type", camera.type.name)
writeStringField("id", camera.id)
writeStringField("name", camera.name)
writeStringField("sender", camera.sender.id)
writeBooleanField("connected", camera.connected)
writeEndObject()
companion object {

@JvmStatic
private fun JsonGenerator.writeMainOrGuideHead(camera: Camera, fieldName: String) {
writeObjectFieldStart(fieldName)
writeStringField("type", camera.type.name)
writeStringField("id", camera.id)
writeStringField("name", camera.name)
writeStringField("sender", camera.sender.id)
writeBooleanField("connected", camera.connected)
writeEndObject()
}
}
}
18 changes: 18 additions & 0 deletions api/src/main/kotlin/nebulosa/api/connection/ConnectionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import nebulosa.indi.device.filterwheel.FilterWheel
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.gps.GPS
import nebulosa.indi.device.guider.GuideOutput
import nebulosa.indi.device.lightbox.LightBox
import nebulosa.indi.device.mount.Mount
import nebulosa.indi.device.rotator.Rotator
import nebulosa.indi.device.thermometer.Thermometer
Expand Down Expand Up @@ -134,6 +135,10 @@ class ConnectionService(
return providers[id]?.guideOutputs() ?: emptyList()
}

fun lightBoxes(id: String): Collection<LightBox> {
return providers[id]?.lightBoxes() ?: emptyList()
}

fun thermometers(id: String): Collection<Thermometer> {
return providers[id]?.thermometers() ?: emptyList()
}
Expand Down Expand Up @@ -166,6 +171,10 @@ class ConnectionService(
return providers.values.flatMap { it.guideOutputs() }
}

fun lightBoxes(): List<LightBox> {
return providers.values.flatMap { it.lightBoxes() }
}

fun thermometers(): List<Thermometer> {
return providers.values.flatMap { it.thermometers() }
}
Expand Down Expand Up @@ -198,6 +207,10 @@ class ConnectionService(
return providers[id]?.guideOutput(name)
}

fun lightBox(id: String, name: String): LightBox? {
return providers[id]?.lightBox(name)
}

fun thermometer(id: String, name: String): Thermometer? {
return providers[id]?.thermometer(name)
}
Expand Down Expand Up @@ -230,6 +243,10 @@ class ConnectionService(
return providers.firstNotNullOfOrNull { it.value.guideOutput(name) }
}

fun lightBox(name: String): LightBox? {
return providers.firstNotNullOfOrNull { it.value.lightBox(name) }
}

fun thermometer(name: String): Thermometer? {
return providers.firstNotNullOfOrNull { it.value.thermometer(name) }
}
Expand All @@ -241,6 +258,7 @@ class ConnectionService(
?: wheel(name)
?: rotator(name)
?: guideOutput(name)
?: lightBox(name)
?: gps(name)
?: thermometer(name)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.beans.converters.device
package nebulosa.api.devices

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
Expand Down
24 changes: 24 additions & 0 deletions api/src/main/kotlin/nebulosa/api/devices/DeviceSerializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nebulosa.api.devices

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.indi.device.Device

abstract class DeviceSerializer<T : Device>(type: Class<T>) : StdSerializer<T>(type) {

protected abstract fun JsonGenerator.serialize(value: T)

final override fun serialize(value: T, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeStartObject()
gen.writeStringField("type", value.type.name)
gen.writeStringField("sender", value.sender.id)
gen.writeStringField("driverName", value.driverName)
gen.writeStringField("driverVersion", value.driverVersion)
gen.writeStringField("id", value.id)
gen.writeStringField("name", value.name)
gen.writeBooleanField("connected", value.connected)
gen.serialize(value)
gen.writeEndObject()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nebulosa.api.focusers

import nebulosa.api.beans.converters.device.DeviceDeserializer
import nebulosa.api.devices.DeviceDeserializer
import nebulosa.api.connection.ConnectionService
import nebulosa.indi.device.focuser.Focuser
import org.springframework.beans.factory.annotation.Autowired
Expand Down
40 changes: 15 additions & 25 deletions api/src/main/kotlin/nebulosa/api/focusers/FocuserSerializer.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
package nebulosa.api.focusers

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.api.devices.DeviceSerializer
import nebulosa.indi.device.focuser.Focuser
import org.springframework.stereotype.Component

@Component
class FocuserSerializer : StdSerializer<Focuser>(Focuser::class.java) {
class FocuserSerializer : DeviceSerializer<Focuser>(Focuser::class.java) {

override fun serialize(value: Focuser, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeStartObject()
gen.writeStringField("type", value.type.name)
gen.writeStringField("sender", value.sender.id)
gen.writeStringField("driverName", value.driverName)
gen.writeStringField("driverVersion", value.driverVersion)
gen.writeStringField("id", value.id)
gen.writeStringField("name", value.name)
gen.writeBooleanField("connected", value.connected)
gen.writeBooleanField("moving", value.moving)
gen.writeNumberField("position", value.position)
gen.writeBooleanField("canAbsoluteMove", value.canAbsoluteMove)
gen.writeBooleanField("canRelativeMove", value.canRelativeMove)
gen.writeBooleanField("canAbort", value.canAbort)
gen.writeBooleanField("canReverse", value.canReverse)
gen.writeBooleanField("reversed", value.reversed)
gen.writeBooleanField("canSync", value.canSync)
gen.writeBooleanField("hasBacklash", value.hasBacklash)
gen.writeNumberField("maxPosition", value.maxPosition)
gen.writeBooleanField("hasThermometer", value.hasThermometer)
gen.writeNumberField("temperature", value.temperature)
gen.writeEndObject()
override fun JsonGenerator.serialize(value: Focuser) {
writeBooleanField("moving", value.moving)
writeNumberField("position", value.position)
writeBooleanField("canAbsoluteMove", value.canAbsoluteMove)
writeBooleanField("canRelativeMove", value.canRelativeMove)
writeBooleanField("canAbort", value.canAbort)
writeBooleanField("canReverse", value.canReverse)
writeBooleanField("reversed", value.reversed)
writeBooleanField("canSync", value.canSync)
writeBooleanField("hasBacklash", value.hasBacklash)
writeNumberField("maxPosition", value.maxPosition)
writeBooleanField("hasThermometer", value.hasThermometer)
writeNumberField("temperature", value.temperature)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nebulosa.api.guiding

import nebulosa.api.beans.converters.device.DeviceDeserializer
import nebulosa.api.devices.DeviceDeserializer
import nebulosa.api.connection.ConnectionService
import nebulosa.indi.device.guider.GuideOutput
import org.springframework.beans.factory.annotation.Autowired
Expand Down
20 changes: 5 additions & 15 deletions api/src/main/kotlin/nebulosa/api/guiding/GuideOutputSerializer.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package nebulosa.api.guiding

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.api.devices.DeviceSerializer
import nebulosa.indi.device.guider.GuideOutput
import org.springframework.stereotype.Component

@Component
class GuideOutputSerializer : StdSerializer<GuideOutput>(GuideOutput::class.java) {
class GuideOutputSerializer : DeviceSerializer<GuideOutput>(GuideOutput::class.java) {

override fun serialize(value: GuideOutput, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeStartObject()
gen.writeStringField("type", value.type.name)
gen.writeStringField("sender", value.sender.id)
gen.writeStringField("driverName", value.driverName)
gen.writeStringField("driverVersion", value.driverVersion)
gen.writeStringField("id", value.id)
gen.writeStringField("name", value.name)
gen.writeBooleanField("connected", value.connected)
gen.writeBooleanField("canPulseGuide", value.canPulseGuide)
gen.writeBooleanField("pulseGuiding", value.pulseGuiding)
gen.writeEndObject()
override fun JsonGenerator.serialize(value: GuideOutput) {
writeBooleanField("canPulseGuide", value.canPulseGuide)
writeBooleanField("pulseGuiding", value.pulseGuiding)
}
}
Loading

0 comments on commit be5481d

Please sign in to comment.