Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Aug 11, 2023
2 parents a8f8826 + e3fb7aa commit 4c821f3
Show file tree
Hide file tree
Showing 53 changed files with 1,960 additions and 1,575 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.springframework.boot.gradle.tasks.bundling.BootJar
plugins {
kotlin("jvm")
id("org.springframework.boot") version "3.1.2"
id("io.spring.dependency-management") version "1.1.2"
id("io.spring.dependency-management") version "1.1.3"
kotlin("plugin.spring")
kotlin("kapt")
id("io.objectbox")
Expand Down
8 changes: 6 additions & 2 deletions api/src/main/kotlin/nebulosa/api/configs/BeanConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package nebulosa.api.configs

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.api.data.entities.MyObjectBox
import nebulosa.common.concurrency.DaemonThreadFactory
import nebulosa.hips2fits.Hips2FitsService
Expand All @@ -13,6 +15,7 @@ import okhttp3.ConnectionPool
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.greenrobot.eventbus.EventBus
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
Expand Down Expand Up @@ -46,9 +49,10 @@ class BeanConfig {

@Bean
@Primary
fun objectMapper() = ObjectMapper()
fun objectMapper(@Qualifier("serializer") serializers: List<StdSerializer<*>>) = ObjectMapper()
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)!!
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
.registerModule(SimpleModule().apply { serializers.forEach(::addSerializer) })!!

@Bean
fun connectionPool() = ConnectionPool(32, 5L, TimeUnit.MINUTES)
Expand Down
11 changes: 5 additions & 6 deletions api/src/main/kotlin/nebulosa/api/controllers/CameraController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package nebulosa.api.controllers
import jakarta.validation.Valid
import jakarta.validation.constraints.NotBlank
import nebulosa.api.data.requests.CameraStartCaptureRequest
import nebulosa.api.data.responses.CameraResponse
import nebulosa.api.services.CameraService
import nebulosa.api.services.EquipmentService
import nebulosa.indi.device.camera.Camera
import org.hibernate.validator.constraints.Range
import org.springframework.web.bind.annotation.*

Expand All @@ -16,14 +16,13 @@ class CameraController(
) {

@GetMapping("attachedCameras")
fun attachedCameras(): List<CameraResponse> {
return equipmentService.cameras().map(::CameraResponse)
fun attachedCameras(): List<Camera> {
return equipmentService.cameras()
}

@GetMapping("camera")
fun camera(@RequestParam @Valid @NotBlank name: String): CameraResponse {
val camera = requireNotNull(equipmentService.camera(name))
return CameraResponse(camera)
fun camera(@RequestParam @Valid @NotBlank name: String): Camera {
return requireNotNull(equipmentService.camera(name))
}

@PostMapping("cameraConnect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package nebulosa.api.controllers
import jakarta.validation.Valid
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.PositiveOrZero
import nebulosa.api.data.responses.FilterWheelResponse
import nebulosa.api.services.EquipmentService
import nebulosa.api.services.FilterWheelService
import nebulosa.indi.device.filterwheel.FilterWheel
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
Expand All @@ -18,13 +18,13 @@ class FilterWheelController(
) {

@GetMapping("attachedFilterWheels")
fun attachedFilterWheels(): List<FilterWheelResponse> {
return equipmentService.filterWheels().map(::FilterWheelResponse)
fun attachedFilterWheels(): List<FilterWheel> {
return equipmentService.filterWheels()
}

@GetMapping("filterWheel")
fun filterWheel(@RequestParam @Valid @NotBlank name: String): FilterWheelResponse {
return FilterWheelResponse(requireNotNull(equipmentService.filterWheel(name)))
fun filterWheel(@RequestParam @Valid @NotBlank name: String): FilterWheel {
return requireNotNull(equipmentService.filterWheel(name))
}

@PostMapping("filterWheelConnect")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package nebulosa.api.controllers
import jakarta.validation.Valid
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.PositiveOrZero
import nebulosa.api.data.responses.FocuserResponse
import nebulosa.api.services.EquipmentService
import nebulosa.api.services.FocuserService
import nebulosa.indi.device.focuser.Focuser
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
Expand All @@ -18,13 +18,13 @@ class FocuserController(
) {

@GetMapping("attachedFocusers")
fun attachedFocusers(): List<FocuserResponse> {
return equipmentService.focusers().map(::FocuserResponse)
fun attachedFocusers(): List<Focuser> {
return equipmentService.focusers()
}

@GetMapping("focuser")
fun focuser(@RequestParam @Valid @NotBlank name: String): FocuserResponse {
return FocuserResponse(requireNotNull(equipmentService.focuser(name)))
fun focuser(@RequestParam @Valid @NotBlank name: String): Focuser {
return requireNotNull(equipmentService.focuser(name))
}

@PostMapping("focuserConnect")
Expand Down
35 changes: 2 additions & 33 deletions api/src/main/kotlin/nebulosa/api/controllers/INDIController.kt
Original file line number Diff line number Diff line change
@@ -1,55 +1,24 @@
package nebulosa.api.controllers

import jakarta.annotation.PostConstruct
import jakarta.validation.Valid
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotEmpty
import nebulosa.api.data.requests.INDISendPropertyRequest
import nebulosa.api.data.responses.INDIPropertyResponse
import nebulosa.api.services.EquipmentService
import nebulosa.api.services.INDIService
import nebulosa.api.services.WebSocketService
import nebulosa.indi.device.DeviceMessageReceived
import nebulosa.indi.device.DevicePropertyChanged
import nebulosa.indi.device.DevicePropertyDeleted
import nebulosa.indi.device.DevicePropertyEvent
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import nebulosa.indi.device.PropertyVector
import org.springframework.web.bind.annotation.*

@RestController
class INDIController(
private val equipmentService: EquipmentService,
private val indiService: INDIService,
private val webSocketService: WebSocketService,
private val eventBus: EventBus,
) {

@PostConstruct
private fun initialize() {
eventBus.register(this)
}

@Subscribe(threadMode = ThreadMode.ASYNC)
fun onDevicePropertyEvent(event: DevicePropertyEvent) {
when (event) {
is DevicePropertyChanged -> webSocketService.sendINDIPropertyChanged(event)
is DevicePropertyDeleted -> webSocketService.sendINDIPropertyDeleted(event)
}
}

@Subscribe(threadMode = ThreadMode.ASYNC)
fun onDeviceMessageReceived(event: DeviceMessageReceived) {
if (event.device == null) {
indiService.addFirst(event.message)
}

webSocketService.sendINDIMessageReceived(event)
}

@GetMapping("indiProperties")
fun properties(@RequestParam @Valid @NotBlank name: String): List<INDIPropertyResponse> {
fun properties(@RequestParam @Valid @NotBlank name: String): Collection<PropertyVector<*, *>> {
val device = requireNotNull(equipmentService[name])
return indiService.properties(device)
}
Expand Down
11 changes: 5 additions & 6 deletions api/src/main/kotlin/nebulosa/api/controllers/MountController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package nebulosa.api.controllers
import jakarta.validation.Valid
import jakarta.validation.constraints.NotBlank
import nebulosa.api.data.responses.ComputedCoordinateResponse
import nebulosa.api.data.responses.MountResponse
import nebulosa.api.services.EquipmentService
import nebulosa.api.services.MountService
import nebulosa.indi.device.mount.Mount
import nebulosa.indi.device.mount.TrackMode
import nebulosa.math.Angle
import nebulosa.math.Distance.Companion.m
Expand All @@ -26,14 +26,13 @@ class MountController(
) {

@GetMapping("attachedMounts")
fun attachedMounts(): List<MountResponse> {
return equipmentService.mounts().map(::MountResponse)
fun attachedMounts(): List<Mount> {
return equipmentService.mounts()
}

@GetMapping("mount")
fun mount(@RequestParam @Valid @NotBlank name: String): MountResponse {
val mount = requireNotNull(equipmentService.mount(name))
return MountResponse(mount)
fun mount(@RequestParam @Valid @NotBlank name: String): Mount {
return requireNotNull(equipmentService.mount(name))
}

@PostMapping("mountConnect")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package nebulosa.api.data.events

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.api.services.CameraExposureTask
import nebulosa.indi.device.camera.CameraEvent
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Component

data class CameraCaptureFinished(val task: CameraExposureTask) : CameraEvent {
data class CameraCaptureFinished(override val task: CameraExposureTask) : TaskEvent, CameraEvent {

override val device
get() = task.camera

@Component
@Qualifier("serializer")
class Serializer : StdSerializer<CameraCaptureFinished>(CameraCaptureFinished::class.java) {

override fun serialize(
event: CameraCaptureFinished,
gen: JsonGenerator,
provider: SerializerProvider,
) {
gen.writeStartObject()
gen.writeStringField("camera", event.device.name)
gen.writeEndObject()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package nebulosa.api.data.events

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import nebulosa.api.services.CameraExposureTask
import nebulosa.indi.device.camera.CameraEvent
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Component

data class CameraCaptureProgressChanged(
override val task: CameraExposureTask,
) : TaskEvent, CameraEvent {

override val device
get() = task.camera

@Component
@Qualifier("serializer")
class Serializer : StdSerializer<CameraCaptureProgressChanged>(CameraCaptureProgressChanged::class.java) {

override fun serialize(
event: CameraCaptureProgressChanged,
gen: JsonGenerator,
provider: SerializerProvider,
) {
gen.writeStartObject()
gen.writeStringField("camera", event.device.name)
gen.writeNumberField("remainingAmount", event.task.remainingAmount)
gen.writeNumberField("frameRemainingTime", event.task.frameRemainingTime)
gen.writeNumberField("frameProgress", event.task.frameProgress)
gen.writeNumberField("totalAmount", event.task.amount)
gen.writeNumberField("totalRemainingTime", event.task.totalRemainingTime)
gen.writeNumberField("totalProgress", event.task.totalProgress)
gen.writeNumberField("totalExposureTime", event.task.totalExposureTime)
gen.writeBooleanField("indeterminate", event.task.indeterminate)
gen.writeEndObject()
}
}
}
8 changes: 8 additions & 0 deletions api/src/main/kotlin/nebulosa/api/data/events/TaskEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package nebulosa.api.data.events

import nebulosa.common.concurrency.ThreadedJob

sealed interface TaskEvent {

val task: ThreadedJob<*>
}
Loading

0 comments on commit 4c821f3

Please sign in to comment.