-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
340 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 66 additions & 73 deletions
139
api/src/main/kotlin/nebulosa/api/cameras/CameraSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/converters/device/DeviceDeserializer.kt → ...ebulosa/api/devices/DeviceDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
api/src/main/kotlin/nebulosa/api/devices/DeviceSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
api/src/main/kotlin/nebulosa/api/focusers/FocuserDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 15 additions & 25 deletions
40
api/src/main/kotlin/nebulosa/api/focusers/FocuserSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
api/src/main/kotlin/nebulosa/api/guiding/GuideOutputDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 5 additions & 15 deletions
20
api/src/main/kotlin/nebulosa/api/guiding/GuideOutputSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.