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 Dec 6, 2023
2 parents 8fdeddb + 4d776f7 commit 31e59b5
Show file tree
Hide file tree
Showing 559 changed files with 22,551 additions and 93,230 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.bsp binary
*.bpc binary
*.jar binary
*.fit binary
*.fits binary
*.ttf binary
*.xcf binary
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,6 @@ libobjectbox*.so
libobjectbox*.dylib

# End of https://www.toptal.com/developers/gitignore/api/intellij,kotlin,java,gradle

**/saved/*.png
**/saved/*.jpg
32 changes: 17 additions & 15 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,52 @@ import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
kotlin("jvm")
id("org.springframework.boot") version "3.1.5"
id("io.spring.dependency-management") version "1.1.3"
id("org.springframework.boot") version "3.2.0"
id("io.spring.dependency-management") version "1.1.4"
kotlin("plugin.spring")
kotlin("kapt")
}

dependencies {
implementation(project(":nebulosa-astap"))
implementation(project(":nebulosa-astrometrynet"))
implementation(project(":nebulosa-common"))
implementation(project(":nebulosa-guiding-phd2"))
implementation(project(":nebulosa-hips2fits"))
implementation(project(":nebulosa-horizons"))
implementation(project(":nebulosa-imaging"))
implementation(project(":nebulosa-indi-client"))
implementation(project(":nebulosa-json"))
implementation(project(":nebulosa-log"))
implementation(project(":nebulosa-lx200-protocol"))
implementation(project(":nebulosa-nova"))
implementation(project(":nebulosa-platesolving-astap"))
implementation(project(":nebulosa-platesolving-astrometrynet"))
implementation(project(":nebulosa-platesolving-watney"))
implementation(project(":nebulosa-sbd"))
implementation(project(":nebulosa-simbad"))
implementation(project(":nebulosa-stellarium-protocol"))
implementation(project(":nebulosa-watney"))
implementation(project(":nebulosa-wcs"))
implementation(project(":nebulosa-log"))
implementation(libs.apache.codec)
implementation(libs.csv)
implementation(libs.eventbus)
implementation(libs.flyway)
implementation(libs.okhttp)
implementation(libs.oshi)
implementation(libs.eventbus)
implementation(libs.apache.codec)
implementation(libs.rx)
implementation(libs.sqlite)
implementation(libs.flyway)
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude(module = "spring-boot-starter-tomcat")
}
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-websocket")
implementation("org.springframework.boot:spring-boot-starter-websocket") {
exclude(module = "spring-boot-starter-tomcat")
}
implementation("org.springframework.boot:spring-boot-starter-batch")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-undertow")
implementation("org.hibernate.orm:hibernate-community-dialects")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
kapt("org.springframework:spring-context-indexer:6.0.13")
testImplementation(project(":nebulosa-skycatalog-hyg"))
testImplementation(project(":nebulosa-skycatalog-stellarium"))
kapt("org.springframework:spring-context-indexer:6.1.1")
testImplementation(project(":nebulosa-test"))
}

Expand Down
21 changes: 6 additions & 15 deletions api/src/main/kotlin/nebulosa/api/Main.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package nebulosa.api

import com.sun.jna.Platform
import org.springframework.boot.runApplication
import oshi.PlatformEnum
import oshi.SystemInfo
import java.nio.file.Path
import java.time.LocalDate
import java.time.format.DateTimeFormatter
Expand All @@ -13,23 +12,15 @@ import kotlin.io.path.deleteIfExists
import kotlin.io.path.exists
import kotlin.io.path.listDirectoryEntries

fun initAppDirectory(): Path? {
val appPath = when (SystemInfo.getCurrentPlatform()) {
PlatformEnum.LINUX -> {
val userHomeDir = Path.of(System.getProperty("user.home"))
Path.of("$userHomeDir", ".nebulosa")
}
PlatformEnum.WINDOWS -> {
val documentsDir = FileSystemView.getFileSystemView().defaultDirectory.path
Path.of(documentsDir, "Nebulosa")
}
else -> return null
fun initAppDirectory(): Path {
val appPath = when {
Platform.isLinux() -> Path.of(System.getProperty("user.home"), ".nebulosa")
Platform.isWindows() -> Path.of(FileSystemView.getFileSystemView().defaultDirectory.path, "Nebulosa")
else -> throw IllegalStateException("unsupported operating system")
}

appPath.createDirectories()

System.setProperty("app.dir", "$appPath")

return appPath
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package nebulosa.api.alignment.polar.darv

import nebulosa.api.sequencer.SequenceJobEvent
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.guide.GuideOutput

sealed interface DARVPolarAlignmentEvent {
sealed interface DARVPolarAlignmentEvent : SequenceJobEvent {

val camera: Camera

val guideOutput: GuideOutput

val state: DARVPolarAlignmentState
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package nebulosa.api.alignment.polar.darv

import io.reactivex.rxjava3.functions.Consumer
import nebulosa.api.alignment.polar.darv.DARVPolarAlignmentState.BACKWARD
import nebulosa.api.alignment.polar.darv.DARVPolarAlignmentState.FORWARD
import nebulosa.api.cameras.CameraCaptureEvent
import nebulosa.api.cameras.CameraStartCaptureRequest
import nebulosa.api.guiding.*
import nebulosa.api.guiding.GuidePulseEvent
import nebulosa.api.guiding.GuidePulseRequest
import nebulosa.api.sequencer.*
import nebulosa.api.sequencer.tasklets.delay.DelayElapsed
import nebulosa.api.services.MessageService
Expand All @@ -24,7 +27,6 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor
import org.springframework.stereotype.Component
import java.nio.file.Path
import java.util.*
import kotlin.time.Duration.Companion.seconds

/**
* @see <a href="https://www.cloudynights.com/articles/cat/articles/darv-drift-alignment-by-robert-vice-r2760">Reference</a>
Expand Down Expand Up @@ -58,16 +60,16 @@ class DARVPolarAlignmentExecutor(

val cameraRequest = CameraStartCaptureRequest(
camera = camera,
exposureInMicroseconds = (request.exposureInSeconds + request.initialPauseInSeconds).seconds.inWholeMicroseconds,
exposureTime = request.exposureTime + request.initialPause,
savePath = Path.of("$capturesPath", "${camera.name}-DARV.fits")
)

val cameraExposureTasklet = sequenceTaskletFactory.cameraExposure(cameraRequest)
cameraExposureTasklet.subscribe(this)
val cameraExposureFlow = sequenceFlowFactory.cameraExposure(cameraExposureTasklet)

val guidePulseDuration = (request.exposureInSeconds / 2.0).seconds.inWholeMilliseconds
val initialPauseDelayTasklet = sequenceTaskletFactory.delay(request.initialPauseInSeconds.seconds)
val guidePulseDuration = request.exposureTime.dividedBy(2L)
val initialPauseDelayTasklet = sequenceTaskletFactory.delay(request.initialPause)
initialPauseDelayTasklet.subscribe(this)

val direction = if (request.reversed) request.direction.reversed else request.direction
Expand Down Expand Up @@ -123,26 +125,13 @@ class DARVPolarAlignmentExecutor(

val messageEvent = when (event) {
// Initial pulse event.
is DelayElapsed -> {
DARVPolarAlignmentInitialPauseElapsed(camera, guideOutput, event)
}
is DelayElapsed -> DARVPolarAlignmentInitialPauseElapsed(camera, guideOutput, event)
// Forward & backward guide pulse event.
is GuidePulseEvent -> {
val direction = event.tasklet.request.direction
val duration = event.tasklet.request.durationInMilliseconds
val forward = (direction == data.direction) != data.reversed

when (event) {
is GuidePulseStarted -> {
DARVPolarAlignmentGuidePulseElapsed(camera, guideOutput, forward, direction, duration, 0.0)
}
is GuidePulseElapsed -> {
DARVPolarAlignmentGuidePulseElapsed(camera, guideOutput, forward, direction, event.remainingTime, event.progress)
}
is GuidePulseFinished -> {
DARVPolarAlignmentGuidePulseElapsed(camera, guideOutput, forward, direction, 0L, 1.0)
}
}
val duration = event.tasklet.request.duration
val state = if ((direction == data.direction) != data.reversed) FORWARD else BACKWARD
DARVPolarAlignmentGuidePulseElapsed(camera, guideOutput, state, direction, duration, event.progress, event.jobExecution)
}
is CameraCaptureEvent -> event
else -> return
Expand All @@ -153,12 +142,12 @@ class DARVPolarAlignmentExecutor(

override fun beforeJob(jobExecution: JobExecution) {
val (camera, guideOutput) = sequenceJobWithId(jobExecution.jobId) ?: return
messageService.sendMessage(DARVPolarAlignmentStarted(camera, guideOutput))
messageService.sendMessage(DARVPolarAlignmentStarted(camera, guideOutput, jobExecution))
}

override fun afterJob(jobExecution: JobExecution) {
val (camera, guideOutput) = sequenceJobWithId(jobExecution.jobId) ?: return
messageService.sendMessage(DARVPolarAlignmentFinished(camera, guideOutput))
messageService.sendMessage(DARVPolarAlignmentFinished(camera, guideOutput, jobExecution))
}

override fun iterator(): Iterator<DARVSequenceJob> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import nebulosa.api.services.MessageEvent
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.guide.GuideOutput
import org.springframework.batch.core.JobExecution

data class DARVPolarAlignmentFinished(
override val camera: Camera,
override val guideOutput: GuideOutput,
@JsonIgnore override val jobExecution: JobExecution,
) : MessageEvent, DARVPolarAlignmentEvent {

@JsonIgnore override val eventName = "DARV_POLAR_ALIGNMENT_FINISHED"
override val progress = 1.0

override val state = DARVPolarAlignmentState.IDLE

override val eventName = "DARV_POLAR_ALIGNMENT_FINISHED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import nebulosa.api.services.MessageEvent
import nebulosa.guiding.GuideDirection
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.guide.GuideOutput
import org.springframework.batch.core.JobExecution
import java.time.Duration

data class DARVPolarAlignmentGuidePulseElapsed(
override val camera: Camera,
override val guideOutput: GuideOutput,
val forward: Boolean,
override val state: DARVPolarAlignmentState,
val direction: GuideDirection,
val remainingTime: Long,
val progress: Double,
val remainingTime: Duration,
override val progress: Double,
@JsonIgnore override val jobExecution: JobExecution,
) : MessageEvent, DARVPolarAlignmentEvent {

@JsonIgnore override val eventName = "DARV_POLAR_ALIGNMENT_GUIDE_PULSE_ELAPSED"
override val eventName = "DARV_POLAR_ALIGNMENT_UPDATED"
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
package nebulosa.api.alignment.polar.darv

import com.fasterxml.jackson.annotation.JsonIgnore
import nebulosa.api.sequencer.DelayEvent
import nebulosa.api.sequencer.tasklets.delay.DelayEvent
import nebulosa.api.services.MessageEvent
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.guide.GuideOutput
import org.springframework.batch.core.JobExecution
import java.time.Duration

data class DARVPolarAlignmentInitialPauseElapsed(
override val camera: Camera,
override val guideOutput: GuideOutput,
val pauseTime: Long,
val remainingTime: Long,
val progress: Double,
val pauseTime: Duration,
val remainingTime: Duration,
override val progress: Double,
@JsonIgnore override val jobExecution: JobExecution,
) : MessageEvent, DARVPolarAlignmentEvent {

constructor(camera: Camera, guideOutput: GuideOutput, delay: DelayEvent) : this(
camera, guideOutput, delay.waitTime.inWholeMicroseconds,
delay.remainingTime.inWholeMicroseconds, delay.progress
camera, guideOutput, delay.tasklet.duration,
delay.remainingTime, delay.progress, delay.jobExecution
)

@JsonIgnore override val eventName = "DARV_POLAR_ALIGNMENT_INITIAL_PAUSE_ELAPSED"
override val state = DARVPolarAlignmentState.INITIAL_PAUSE

override val eventName = "DARV_POLAR_ALIGNMENT_UPDATED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import nebulosa.api.services.MessageEvent
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.guide.GuideOutput
import org.springframework.batch.core.JobExecution

data class DARVPolarAlignmentStarted(
override val camera: Camera,
override val guideOutput: GuideOutput,
@JsonIgnore override val jobExecution: JobExecution,
) : MessageEvent, DARVPolarAlignmentEvent {

@JsonIgnore override val eventName = "DARV_POLAR_ALIGNMENT_STARTED"
override val progress = 0.0

override val state = DARVPolarAlignmentState.INITIAL_PAUSE

override val eventName = "DARV_POLAR_ALIGNMENT_STARTED"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package nebulosa.api.alignment.polar.darv

enum class DARVPolarAlignmentState {
IDLE,
INITIAL_PAUSE,
FORWARD,
BACKWARD,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import nebulosa.guiding.GuideDirection
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.guide.GuideOutput
import org.hibernate.validator.constraints.Range
import org.hibernate.validator.constraints.time.DurationMax
import org.hibernate.validator.constraints.time.DurationMin
import java.time.Duration

data class DARVStart(
@JsonIgnore val camera: Camera? = null,
@JsonIgnore val guideOutput: GuideOutput? = null,
@Range(min = 1, max = 600) val exposureInSeconds: Long = 0L,
@Range(min = 1, max = 60) val initialPauseInSeconds: Long = 0L,
@field:DurationMin(seconds = 1) @field:DurationMax(seconds = 600) val exposureTime: Duration = Duration.ZERO,
@field:DurationMin(seconds = 1) @field:DurationMax(seconds = 60) val initialPause: Duration = Duration.ZERO,
val direction: GuideDirection = GuideDirection.NORTH,
val reversed: Boolean = false,
)
Loading

0 comments on commit 31e59b5

Please sign in to comment.