Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 13, 2024
2 parents f228706 + 9d0462d commit 5cb68c8
Show file tree
Hide file tree
Showing 195 changed files with 2,386 additions and 2,072 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 150
max_line_length = 1000
tab_width = 4
trim_trailing_whitespace = true
ij_continuation_indent_size = 4
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: api desktop build install
.PHONY: api desktop build install all

ifeq ($(OS),Windows_NT)
api:
Expand All @@ -15,6 +15,8 @@ desktop:

install:
sudo dpkg -i desktop/release/nebulosa_0.1.0_amd64.deb

all: build install
endif

build: api desktop
16 changes: 5 additions & 11 deletions api/BootJar.run.xml → api/ShadowJar.run.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false"
name="API BootJar"
type="GradleRunConfiguration"
factoryName="Gradle">
<configuration default="false" name="API ShadowJar" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName"/>
<option name="externalProjectPath"
value="$PROJECT_DIR$/api"/>
<option name="externalSystemIdString"
value="GRADLE"/>
<option name="scriptParameters"
value=""/>
<option name="externalProjectPath" value="$PROJECT_DIR$/api"/>
<option name="externalSystemIdString" value="GRADLE"/>
<option name="scriptParameters" value=""/>
<option name="taskDescriptions">
<list/>
</option>
<option name="taskNames">
<list>
<option value="bootJar"/>
<option value="shadowJar"/>
</list>
</option>
<option name="vmOptions"/>
Expand Down
25 changes: 20 additions & 5 deletions api/src/main/kotlin/nebulosa/api/Nebulosa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ import com.fasterxml.jackson.module.kotlin.jsonMapper
import com.github.rvesse.airline.annotations.Command
import com.github.rvesse.airline.annotations.Option
import io.javalin.Javalin
import io.javalin.http.Context
import io.javalin.http.HttpStatus.BAD_REQUEST
import io.javalin.json.JavalinJackson
import nebulosa.api.atlas.Location
import nebulosa.api.beans.modules.DeviceModule
import nebulosa.api.converters.modules.DeviceModule
import nebulosa.api.core.ErrorResponse
import nebulosa.api.inject.*
import nebulosa.json.PathModule
import nebulosa.log.i
import nebulosa.log.loggerFor
import org.koin.core.context.startKoin
import org.slf4j.LoggerFactory
import java.util.concurrent.ConcurrentHashMap
import java.net.ConnectException

@Command(name = "nebulosa")
class Nebulosa : Runnable, AutoCloseable {
Expand Down Expand Up @@ -53,13 +56,25 @@ class Nebulosa : Runnable, AutoCloseable {
}
}.start(host, port)

app.exception(Exception::class.java, ::handleException)

koinApp.modules(appModule(app))
koinApp.modules(objectMapperModule(OBJECT_MAPPER))
koinApp.modules(servicesModule())
koinApp.modules(controllersModule())
startKoin(koinApp)

LOG.info("server is started at port: {}", app.port())
LOG.i("server is started at port: {}", app.port())
}

private fun handleException(ex: Exception, ctx: Context) {
val message = when (ex) {
is ConnectException -> "connection refused"
is NumberFormatException -> "invalid number: ${ex.message}"
else -> ex.message!!
}

ctx.status(BAD_REQUEST).json(ErrorResponse.error(message.lowercase()))
}

override fun close() {
Expand All @@ -68,7 +83,7 @@ class Nebulosa : Runnable, AutoCloseable {

companion object {

@JvmStatic private val LOG = loggerFor<Nebulosa>()
@JvmStatic internal val LOG = loggerFor<Nebulosa>()

@JvmStatic private val OBJECT_MAPPER = jsonMapper {
addModule(JavaTimeModule())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import io.javalin.http.bodyAsClass
import nebulosa.api.alignment.polar.darv.DARVStartRequest
import nebulosa.api.alignment.polar.tppa.TPPAStartRequest
import nebulosa.api.connection.ConnectionService
import nebulosa.api.javalin.notNull
import nebulosa.api.javalin.valid
import nebulosa.api.core.Controller
import nebulosa.api.validators.notNull
import nebulosa.api.validators.valid

class PolarAlignmentController(
app: Javalin,
override val app: Javalin,
private val polarAlignmentService: PolarAlignmentService,
private val connectionService: ConnectionService,
) {
) : Controller {

init {
app.put("polar-alignment/darv/{camera}/{guideOutput}/start", ::darvStart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import nebulosa.job.manager.SplitTask
import nebulosa.job.manager.Task
import nebulosa.job.manager.delay.DelayEvent
import nebulosa.job.manager.delay.DelayTask
import nebulosa.log.d
import nebulosa.log.loggerFor
import java.nio.file.Files
import java.time.Duration
Expand Down Expand Up @@ -78,7 +79,7 @@ data class DARVJob(
}

override fun beforeStart() {
LOG.debug("DARV started. camera={}, guideOutput={}, request={}", camera, guideOutput, request)
LOG.d("DARV started. camera={}, guideOutput={}, request={}", camera, guideOutput, request)

status.capture.handleCameraCaptureStarted(cameraExposureTask.exposureTimeInMicroseconds)
}
Expand All @@ -88,7 +89,7 @@ data class DARVJob(
status.state = DARVState.IDLE
status.send()

LOG.debug("DARV finished. camera={}, guideOutput={}, request={}", camera, guideOutput, request)
LOG.d("DARV finished. camera={}, guideOutput={}, request={}", camera, guideOutput, request)
}

@Suppress("NOTHING_TO_INLINE")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nebulosa.api.alignment.polar.darv

import nebulosa.api.cameras.CameraStartCaptureRequest
import nebulosa.api.javalin.Validatable
import nebulosa.api.validators.Validatable
import nebulosa.guiding.GuideDirection

data class DARVStartRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package nebulosa.api.alignment.polar.tppa

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import nebulosa.api.beans.converters.angle.DeclinationSerializer
import nebulosa.api.beans.converters.angle.RightAscensionSerializer
import nebulosa.api.cameras.CameraCaptureEvent
import nebulosa.api.converters.angle.DeclinationSerializer
import nebulosa.api.converters.angle.RightAscensionSerializer
import nebulosa.api.message.MessageEvent
import nebulosa.indi.device.camera.Camera
import nebulosa.math.Angle
Expand Down
13 changes: 6 additions & 7 deletions api/src/main/kotlin/nebulosa/api/alignment/polar/tppa/TPPAJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import nebulosa.job.manager.Task
import nebulosa.job.manager.delay.DelayEvent
import nebulosa.job.manager.delay.DelayStarted
import nebulosa.job.manager.delay.DelayTask
import nebulosa.log.d
import nebulosa.log.loggerFor
import nebulosa.log.w
import nebulosa.math.Angle
import nebulosa.math.formatSignedDMS
import nebulosa.platesolver.PlateSolver
Expand Down Expand Up @@ -179,7 +181,7 @@ data class TPPAJob(
status.send()

if (noSolutionAttempts >= MAX_ATTEMPTS) {
LOG.error("exhausted all attempts to plate solve")
LOG.w("exhausted all attempts to plate solve")
stop()
}
}
Expand All @@ -204,10 +206,7 @@ data class TPPAJob(
else -> ""
}

LOG.debug(
"TPPA aligned. azimuthError={}, altitudeError={}",
status.azimuthError.formatSignedDMS(), status.altitudeError.formatSignedDMS()
)
LOG.d("TPPA aligned. azimuthError={}, altitudeError={}", status.azimuthError.formatSignedDMS(), status.altitudeError.formatSignedDMS())

status.state = TPPAState.COMPUTED
status.send()
Expand All @@ -216,7 +215,7 @@ data class TPPAJob(
}

override fun beforeStart() {
LOG.debug("TPPA started. longitude={}, latitude={}, camera={}, mount={}, request={}", longitude, latitude, camera, mount, request)
LOG.d("TPPA started. longitude={}, latitude={}, camera={}, mount={}, request={}", longitude, latitude, camera, mount, request)

status.rightAscension = mount.rightAscension
status.declination = mount.declination
Expand All @@ -225,7 +224,7 @@ data class TPPAJob(
}

override fun afterFinish() {
LOG.debug("TPPA finished. camera={}, mount={}, request={}", camera, mount, request)
LOG.d("TPPA finished. camera={}, mount={}, request={}", camera, mount, request)

stopwatch.stop()

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

import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import nebulosa.api.beans.converters.time.DurationUnit
import nebulosa.api.cameras.CameraStartCaptureRequest
import nebulosa.api.javalin.Validatable
import nebulosa.api.javalin.min
import nebulosa.api.converters.time.DurationUnit
import nebulosa.api.platesolver.PlateSolverRequest
import nebulosa.api.validators.Validatable
import nebulosa.api.validators.min
import nebulosa.guiding.GuideDirection
import java.time.Duration
import java.time.temporal.ChronoUnit
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/kotlin/nebulosa/api/atlas/BodyPosition.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package nebulosa.api.atlas

import com.fasterxml.jackson.databind.annotation.JsonSerialize
import nebulosa.api.beans.converters.angle.AzimuthSerializer
import nebulosa.api.beans.converters.angle.DeclinationSerializer
import nebulosa.api.beans.converters.angle.DegreesSerializer
import nebulosa.api.beans.converters.angle.RightAscensionSerializer
import nebulosa.api.converters.angle.AzimuthSerializer
import nebulosa.api.converters.angle.DeclinationSerializer
import nebulosa.api.converters.angle.DegreesSerializer
import nebulosa.api.converters.angle.RightAscensionSerializer
import nebulosa.constants.AU_KM
import nebulosa.constants.SPEED_OF_LIGHT
import nebulosa.horizons.HorizonsElement
Expand Down
11 changes: 7 additions & 4 deletions api/src/main/kotlin/nebulosa/api/atlas/IERSUpdateTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package nebulosa.api.atlas
import io.javalin.http.Header
import nebulosa.api.preference.PreferenceService
import nebulosa.io.transferAndClose
import nebulosa.log.d
import nebulosa.log.e
import nebulosa.log.i
import nebulosa.log.loggerFor
import nebulosa.time.IERS
import nebulosa.time.IERSA
Expand Down Expand Up @@ -52,22 +55,22 @@ class IERSUpdateTask(
.use { it.headers.getDate(Header.LAST_MODIFIED) }

if (modifiedAt != null && "$modifiedAt" == preferenceService.getText(key)) {
LOG.info("{} is up to date. modifiedAt={}", url, modifiedAt)
LOG.i("{} is up to date. modifiedAt={}", url, modifiedAt)
return
}

request = request.newBuilder().get().build()

LOG.debug("downloading {}", url)
LOG.d("downloading {}", url)

httpClient.newCall(request).execute().use {
it.body!!.byteStream().transferAndClose(outputStream())
modifiedAt = it.headers.getDate(Header.LAST_MODIFIED)
preferenceService.putText(key, "$modifiedAt")
LOG.debug("{} downloaded. modifiedAt={}", url, modifiedAt)
LOG.d("{} downloaded. modifiedAt={}", url, modifiedAt)
}
} catch (e: Throwable) {
LOG.error("failed to download finals2000A.all", e)
LOG.e("failed to download finals2000A.all", e)
}
}

Expand Down
5 changes: 3 additions & 2 deletions api/src/main/kotlin/nebulosa/api/atlas/LibWCSDownloadTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nebulosa.api.atlas
import com.sun.jna.Platform
import nebulosa.api.preference.PreferenceService
import nebulosa.io.transferAndCloseOutput
import nebulosa.log.i
import nebulosa.log.loggerFor
import nebulosa.wcs.LibWCS
import okhttp3.OkHttpClient
Expand Down Expand Up @@ -35,7 +36,7 @@ class LibWCSDownloadTask(
val newestVersion = response.body!!.string()

if (newestVersion != preferenceService.getText(VERSION_KEY) || !libraryPath.exists()) {
LOG.info("LibWCS is out of date. Downloading...")
LOG.i("LibWCS is out of date. Downloading...")

request = Request.Builder().get().url(libraryUrl).build()

Expand All @@ -46,7 +47,7 @@ class LibWCSDownloadTask(
}
}
} else {
LOG.info("LibWCS is up to date. version=$newestVersion")
LOG.i("LibWCS is up to date. version={}", newestVersion)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions api/src/main/kotlin/nebulosa/api/atlas/Location.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package nebulosa.api.atlas
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.annotation.JsonSerialize
import nebulosa.api.beans.converters.angle.DegreesDeserializer
import nebulosa.api.beans.converters.angle.DegreesSerializer
import nebulosa.api.beans.converters.distance.MetersDeserializer
import nebulosa.api.beans.converters.distance.MetersSerializer
import nebulosa.api.converters.angle.DegreesDeserializer
import nebulosa.api.converters.angle.DegreesSerializer
import nebulosa.api.converters.distance.MetersDeserializer
import nebulosa.api.converters.distance.MetersSerializer
import nebulosa.math.Angle
import nebulosa.math.Distance
import nebulosa.nova.position.GeographicCoordinate
Expand Down
10 changes: 6 additions & 4 deletions api/src/main/kotlin/nebulosa/api/atlas/SatelliteUpdateTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package nebulosa.api.atlas

import nebulosa.api.message.MessageService
import nebulosa.api.preference.PreferenceService
import nebulosa.log.i
import nebulosa.log.loggerFor
import nebulosa.log.w
import okhttp3.OkHttpClient
import okhttp3.Request
import java.util.concurrent.CompletableFuture
Expand Down Expand Up @@ -32,15 +34,15 @@ class SatelliteUpdateTask(

private fun checkIsOutOfDateAndUpdate() {
if (isOutOfDate()) {
LOG.info("satellites is out of date")
LOG.i("satellites is out of date")

if (updateTLEs()) {
preferenceService.putLong(UPDATED_AT_KEY, System.currentTimeMillis())
} else {
LOG.warn("no satellites was updated")
LOG.w("no satellites was updated")
}
} else {
LOG.info("satellites is up to date")
LOG.i("satellites is up to date")
}
}

Expand All @@ -62,7 +64,7 @@ class SatelliteUpdateTask(

return satelliteRepository
.save(data.values)
.also { LOG.info("{} satellites updated", it.size) }
.also { LOG.i("{} satellites updated", it.size) }
.also { messageService.sendMessage(SatelliteUpdateNotificationEvent.Finished(it.size)) }
.isNotEmpty()
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/kotlin/nebulosa/api/atlas/SimbadEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonIgnore
import io.objectbox.annotation.Convert
import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import nebulosa.api.beans.converters.database.ConstellationPropertyConverter
import nebulosa.api.beans.converters.database.SkyObjectTypePropertyConverter
import nebulosa.api.converters.database.ConstellationPropertyConverter
import nebulosa.api.converters.database.SkyObjectTypePropertyConverter
import nebulosa.api.database.BoxEntity
import nebulosa.math.Angle
import nebulosa.math.Velocity
Expand Down
Loading

0 comments on commit 5cb68c8

Please sign in to comment.