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 Jul 27, 2023
2 parents c214c5a + 58469dc commit 5f712db
Show file tree
Hide file tree
Showing 87 changed files with 2,449 additions and 16,679 deletions.
10 changes: 0 additions & 10 deletions api/src/main/kotlin/nebulosa/api/controllers/AtlasController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,6 @@ class AtlasController(
atlasService.imageOfSun(response)
}

@GetMapping("imageOfMoon")
fun imageOfMoon(
@RequestParam location: Long,
@DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam(required = false) date: LocalDate?,
@DateTimeFormat(pattern = "HH:mm") @RequestParam(required = false) time: LocalTime?,
response: HttpServletResponse,
) {
atlasService.imageOfMoon(locationRepository.withId(location)!!, (date + time).noSeconds(), response)
}

@GetMapping("positionOfSun")
fun positionOfSun(
@RequestParam location: Long,
Expand Down
19 changes: 10 additions & 9 deletions api/src/main/kotlin/nebulosa/api/controllers/CameraController.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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 org.hibernate.validator.constraints.Range
import org.springframework.web.bind.annotation.*
import java.util.*

@RestController
class CameraController(
Expand All @@ -18,42 +19,42 @@ class CameraController(
}

@GetMapping("camera")
fun camera(@RequestParam name: String): CameraResponse {
fun camera(@RequestParam @Valid @NotBlank name: String): CameraResponse {
return cameraService[name]
}

@PostMapping("cameraConnect")
fun connect(@RequestParam name: String) {
fun connect(@RequestParam @Valid @NotBlank name: String) {
cameraService.connect(name)
}

@PostMapping("cameraDisconnect")
fun disconnect(@RequestParam name: String) {
fun disconnect(@RequestParam @Valid @NotBlank name: String) {
cameraService.disconnect(name)
}

@GetMapping("cameraIsCapturing")
fun isCapturing(@RequestParam name: String): Boolean {
fun isCapturing(@RequestParam @Valid @NotBlank name: String): Boolean {
return cameraService.isCapturing(name)
}

@PostMapping("cameraSetpointTemperature")
fun setpointTemperature(@RequestParam name: String, @RequestParam temperature: Double) {
fun setpointTemperature(@RequestParam @Valid @NotBlank name: String, @RequestParam @Valid @Range(min = -50, max = 50) temperature: Double) {
cameraService.setpointTemperature(name, temperature)
}

@PostMapping("cameraCooler")
fun cooler(@RequestParam name: String, @RequestParam value: Boolean) {
fun cooler(@RequestParam @Valid @NotBlank name: String, @RequestParam value: Boolean) {
cameraService.cooler(name, value)
}

@PostMapping("cameraStartCapture")
fun startCapture(@RequestParam name: String, @RequestBody @Valid body: CameraStartCaptureRequest) {
fun startCapture(@RequestParam @Valid @NotBlank name: String, @RequestBody @Valid body: CameraStartCaptureRequest) {
cameraService.startCapture(name, body)
}

@PostMapping("cameraAbortCapture")
fun abortCapture(@RequestParam name: String) {
fun abortCapture(@RequestParam @Valid @NotBlank name: String) {
cameraService.abortCapture(name)
}
}
74 changes: 74 additions & 0 deletions api/src/main/kotlin/nebulosa/api/controllers/FocuserController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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.FocuserService
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
class FocuserController(
private val focuserService: FocuserService,
) {

@GetMapping("attachedFocusers")
fun attachedFocusers(): List<FocuserResponse> {
return focuserService.attachedFocusers()
}

@GetMapping("focuser")
fun focuser(@RequestParam @Valid @NotBlank name: String): FocuserResponse {
return focuserService[name]
}

@PostMapping("focuserConnect")
fun connect(@RequestParam @Valid @NotBlank name: String) {
focuserService.connect(name)
}

@PostMapping("focuserDisconnect")
fun disconnect(@RequestParam @Valid @NotBlank name: String) {
focuserService.disconnect(name)
}

@PostMapping("focuserMoveIn")
fun moveIn(
@RequestParam @Valid @NotBlank name: String,
@RequestParam @Valid @PositiveOrZero steps: Int,
) {
focuserService.moveIn(name, steps)
}

@PostMapping("focuserMoveOut")
fun moveOut(
@RequestParam @Valid @NotBlank name: String,
@RequestParam @Valid @PositiveOrZero steps: Int,
) {
focuserService.moveOut(name, steps)
}

@PostMapping("focuserMoveTo")
fun moveTo(
@RequestParam @Valid @NotBlank name: String,
@RequestParam @Valid @PositiveOrZero steps: Int,
) {
focuserService.moveTo(name, steps)
}

@PostMapping("focuserAbort")
fun abort(@RequestParam @Valid @NotBlank name: String) {
focuserService.abort(name)
}

@PostMapping("focuserSyncTo")
fun syncTo(
@RequestParam @Valid @NotBlank name: String,
@RequestParam @Valid @PositiveOrZero steps: Int,
) {
focuserService.syncTo(name, steps)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data class BodyPositionResponse(
val distanceUnit: String,
val illuminated: Double,
val elongation: Double,
val leading: Boolean, // true = rises and sets BEFORE Sun.
) {

companion object {
Expand Down Expand Up @@ -51,6 +52,7 @@ data class BodyPositionResponse(
distance, distanceUnit,
element.asDouble(HorizonsQuantity.ILLUMINATED_FRACTION),
element.asDouble(HorizonsQuantity.SUN_OBSERVER_TARGET_ELONGATION_ANGLE),
element.asString(HorizonsQuantity.SUN_OBSERVER_TARGET_ELONGATION_ANGLE, index = 1) == "/L",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package nebulosa.api.data.responses

data class FITSHeaderItemResponse(val name: String, val value: String)
38 changes: 38 additions & 0 deletions api/src/main/kotlin/nebulosa/api/data/responses/FocuserResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package nebulosa.api.data.responses

import nebulosa.indi.device.focuser.Focuser

data class FocuserResponse(
val name: String,
val connected: Boolean,
val moving: Boolean,
val position: Int,
val canAbsoluteMove: Boolean,
val canRelativeMove: Boolean,
val canAbort: Boolean,
val canReverse: Boolean,
val reverse: Boolean,
val canSync: Boolean,
val hasBackslash: Boolean,
val maxPosition: Int,
val hasThermometer: Boolean,
val temperature: Double,
) {

constructor(focuser: Focuser) : this(
focuser.name,
focuser.connected,
focuser.moving,
focuser.position,
focuser.canAbsoluteMove,
focuser.canRelativeMove,
focuser.canAbort,
focuser.canReverse,
focuser.reverse,
focuser.canSync,
focuser.hasBackslash,
focuser.maxPosition,
focuser.hasThermometer,
focuser.temperature,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package nebulosa.api.data.responses

data class ImageInfoResponse(
val camera: String,
val path: String,
val savedAt: Long,
val width: Int,
val height: Int,
val mono: Boolean,
val stretchShadow: Float,
val stretchHighlight: Float,
val stretchMidtone: Float,
val rightAscension: String?,
val declination: String?,
val calibrated: Boolean,
val headers: List<FITSHeaderItemResponse>,
)
24 changes: 0 additions & 24 deletions api/src/main/kotlin/nebulosa/api/services/AtlasService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import nebulosa.api.services.ephemeris.BodyEphemerisProvider
import nebulosa.api.services.ephemeris.HorizonsEphemerisProvider
import nebulosa.horizons.HorizonsElement
import nebulosa.horizons.HorizonsQuantity
import nebulosa.io.resource
import nebulosa.io.transferAndCloseInput
import nebulosa.log.loggerFor
import nebulosa.math.Angle
import nebulosa.math.Angle.Companion.mas
Expand Down Expand Up @@ -91,28 +89,6 @@ class AtlasService(
output.outputStream.write(sunImage)
}

fun imageOfMoon(
location: LocationEntity, dateTime: LocalDateTime,
output: HttpServletResponse,
) {
val sot = bodyEphemeris(MOON, location, dateTime)
.withLocationAndDateTime(location, dateTime)!![HorizonsQuantity.SUN_OBSERVER_TARGET_ELONGATION_ANGLE]
?.split(",") ?: return

val angle = sot[0].toDouble()
val leading = sot[1] == "/L"
val phase = if (leading) 360.0 - angle else angle
val age = 29.53058868 * (phase / 360.0)

LOG.info("moon phase. phase={}, age={}, location={}, dateTime={}", phase, age, location, dateTime)

val phaseNum = ((age * 1.01589576574604) % 30.0).toInt() + 1

output.contentType = "image/png"
resource("images/moonPhases/%02d.png".format(phaseNum))!!
.transferAndCloseInput(output.outputStream)
}

fun positionOfSun(location: LocationEntity, dateTime: LocalDateTime): BodyPositionResponse {
return positionOfBody(SUN, location, dateTime)!!
}
Expand Down
12 changes: 6 additions & 6 deletions api/src/main/kotlin/nebulosa/api/services/CameraService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ class CameraService(
}

operator fun get(name: String): CameraResponse {
val camera = equipmentService.camera(name)!!
val camera = requireNotNull(equipmentService.camera(name))
return CameraResponse(camera)
}

fun connect(name: String) {
val camera = equipmentService.camera(name)!!
val camera = requireNotNull(equipmentService.camera(name))
camera.connect()
}

fun disconnect(name: String) {
val camera = equipmentService.camera(name)!!
val camera = requireNotNull(equipmentService.camera(name))
camera.disconnect()
}

Expand All @@ -81,20 +81,20 @@ class CameraService(
}

fun setpointTemperature(name: String, temperature: Double) {
val camera = equipmentService.camera(name)!!
val camera = requireNotNull(equipmentService.camera(name))
camera.temperature(temperature)
}

fun cooler(name: String, enable: Boolean) {
val camera = equipmentService.camera(name)!!
val camera = requireNotNull(equipmentService.camera(name))
camera.cooler(enable)
}

@Synchronized
fun startCapture(name: String, data: CameraStartCaptureRequest) {
if (isCapturing(name)) return

val camera = equipmentService.camera(name)!!
val camera = requireNotNull(equipmentService.camera(name))
val savePath = data.savePath?.ifBlank { null }?.let(Path::of)
?.takeIf { it.exists() && it.isDirectory() }
?: Path.of("$capturesDirectory", name).createDirectories()
Expand Down
16 changes: 15 additions & 1 deletion api/src/main/kotlin/nebulosa/api/services/EquipmentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import nebulosa.indi.device.DeviceEventHandler
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.camera.CameraAttached
import nebulosa.indi.device.camera.CameraDetached
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.focuser.FocuserAttached
import nebulosa.indi.device.focuser.FocuserDetached
import org.greenrobot.eventbus.EventBus
import org.springframework.stereotype.Service
import java.util.*
Expand All @@ -14,12 +17,15 @@ import java.util.*
class EquipmentService(private val eventBus: EventBus) : DeviceEventHandler {

private val cameras = ArrayList<Camera>(2)
private val focusers = ArrayList<Focuser>(2)

@Synchronized
override fun onEventReceived(event: DeviceEvent<*>) {
when (event) {
is CameraAttached -> cameras.add(event.device)
is CameraDetached -> cameras.remove(event.device)
is FocuserAttached -> focusers.add(event.device)
is FocuserDetached -> focusers.remove(event.device)
}

eventBus.post(event)
Expand All @@ -33,7 +39,15 @@ class EquipmentService(private val eventBus: EventBus) : DeviceEventHandler {
return cameras.firstOrNull { it.name == name }
}

fun focusers(): List<Focuser> {
return Collections.unmodifiableList(focusers)
}

fun focuser(name: String): Focuser? {
return focusers.firstOrNull { it.name == name }
}

operator fun get(name: String): Device? {
return camera(name)
return camera(name) ?: focuser(name)
}
}
Loading

0 comments on commit 5f712db

Please sign in to comment.