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 Sep 1, 2023
2 parents 87d5881 + b58a28a commit f58e5ae
Show file tree
Hide file tree
Showing 129 changed files with 2,112 additions and 1,773 deletions.
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation(libs.oshi)
implementation(libs.eventbus)
implementation(libs.apache.codec)
implementation(libs.rx)
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
Expand Down
71 changes: 2 additions & 69 deletions api/objectbox-models/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -557,77 +557,10 @@
}
],
"relations": []
},
{
"id": "7:8968304416388002032",
"lastPropertyId": "5:7830389679541367505",
"name": "TLEEntity",
"properties": [
{
"id": "1:1418769500440679099",
"name": "id",
"type": 6,
"flags": 129
},
{
"id": "2:7290811067773705137",
"name": "source",
"indexId": "14:9187059019963520245",
"type": 6,
"flags": 8
},
{
"id": "3:2719054692725905613",
"name": "name",
"type": 9
},
{
"id": "4:7447454692522974010",
"name": "tle",
"type": 9
}
],
"relations": []
},
{
"id": "8:3715657608088091992",
"lastPropertyId": "5:6338712844528940250",
"name": "TLESourceEntity",
"properties": [
{
"id": "1:1484675797823198018",
"name": "id",
"type": 6,
"flags": 1
},
{
"id": "2:3112508440451107751",
"name": "url",
"indexId": "15:6936188058417201855",
"type": 9,
"flags": 2048
},
{
"id": "3:6679808789215869090",
"name": "updatedAt",
"type": 6
},
{
"id": "4:3330731028661288545",
"name": "enabled",
"type": 1
},
{
"id": "5:6338712844528940250",
"name": "deletable",
"type": 1
}
],
"relations": []
}
],
"lastEntityId": "8:3715657608088091992",
"lastIndexId": "15:6936188058417201855",
"lastEntityId": "6:2301362482019052453",
"lastIndexId": "13:1450764334546729064",
"lastRelationId": "0:0",
"lastSequenceId": "0:0",
"modelVersion": 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package nebulosa.api.controllers
package nebulosa.api.atlas

import jakarta.annotation.PostConstruct
import jakarta.servlet.http.HttpServletResponse
import jakarta.validation.Valid
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Positive
import nebulosa.api.data.entities.*
import nebulosa.api.data.entities.DeepSkyObjectEntity
import nebulosa.api.data.entities.LocationEntity
import nebulosa.api.data.entities.StarEntity
import nebulosa.api.data.enums.SatelliteGroupType
import nebulosa.api.data.responses.BodyPositionResponse
import nebulosa.api.data.responses.MinorPlanetResponse
import nebulosa.api.data.responses.SatelliteResponse
import nebulosa.api.data.responses.TwilightResponse
import nebulosa.api.repositories.DeepSkyObjectRepository
import nebulosa.api.repositories.LocationRepository
import nebulosa.api.repositories.StarRepository
import nebulosa.api.services.AtlasService
import nebulosa.api.utils.noSeconds
import nebulosa.api.utils.orNow
import nebulosa.api.utils.plus
Expand All @@ -34,13 +36,6 @@ class AtlasController(
private val deepSkyObjectRepository: DeepSkyObjectRepository,
) {

@PostConstruct
private fun initialize() {
if (locationRepository.isEmpty()) {
locationRepository.save(LocationEntity(0, "Saint Helena", -15.9655282, -5.7114846, 77.0))
}
}

@GetMapping("locations")
fun location(): List<LocationEntity> {
return locationRepository.all()
Expand Down Expand Up @@ -131,13 +126,9 @@ class AtlasController(
@GetMapping("searchSatellites")
fun searchSatellites(
@RequestParam(required = false, defaultValue = "") text: String,
): List<TLEEntity> {
return atlasService.searchSatellites(text)
}

@GetMapping("satelliteSources")
fun satelliteSources(): List<TLESourceEntity> {
return atlasService.satelliteSources()
@RequestParam(name = "group", required = false) groups: List<SatelliteGroupType>,
): List<SatelliteResponse> {
return atlasService.searchSatellites(text, groups)
}

@GetMapping("twilight")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package nebulosa.api.services
package nebulosa.api.atlas

import jakarta.annotation.PostConstruct
import jakarta.servlet.http.HttpServletResponse
import nebulosa.api.data.entities.*
import nebulosa.api.atlas.ephemeris.BodyEphemerisProvider
import nebulosa.api.atlas.ephemeris.HorizonsEphemerisProvider
import nebulosa.api.data.entities.AppPreferenceEntity
import nebulosa.api.data.entities.DeepSkyObjectEntity
import nebulosa.api.data.entities.LocationEntity
import nebulosa.api.data.entities.StarEntity
import nebulosa.api.data.enums.SatelliteGroupType
import nebulosa.api.data.responses.BodyPositionResponse
import nebulosa.api.data.responses.MinorPlanetResponse
import nebulosa.api.data.responses.SatelliteResponse
import nebulosa.api.data.responses.TwilightResponse
import nebulosa.api.repositories.*
import nebulosa.api.services.algorithms.TwilightDiscreteFunction
import nebulosa.api.services.ephemeris.BodyEphemerisProvider
import nebulosa.api.services.ephemeris.HorizonsEphemerisProvider
import nebulosa.api.repositories.AppPreferenceRepository
import nebulosa.api.repositories.DeepSkyObjectRepository
import nebulosa.api.repositories.SatelliteRepository
import nebulosa.api.repositories.StarRepository
import nebulosa.horizons.HorizonsElement
import nebulosa.horizons.HorizonsQuantity
import nebulosa.log.loggerFor
Expand Down Expand Up @@ -52,8 +59,7 @@ class AtlasService(
private val starRepository: StarRepository,
private val deepSkyObjectRepository: DeepSkyObjectRepository,
private val appPreferenceRepository: AppPreferenceRepository,
private val tleRepository: TLERepository,
private val tleSourceRepository: TLESourceRepository,
private val satelliteRepository: SatelliteRepository,
private val okHttpClient: OkHttpClient,
) {

Expand Down Expand Up @@ -126,13 +132,8 @@ class AtlasService(
else horizonsEphemerisProvider.compute(target, position, dateTime, zoneId)
}

fun searchSatellites(text: String): List<TLEEntity> {
return if (text.isBlank()) tleRepository.all()
else tleRepository.withName(text)
}

fun satelliteSources(): List<TLESourceEntity> {
return tleRepository.sources()
fun searchSatellites(text: String, groups: List<SatelliteGroupType>): List<SatelliteResponse> {
return satelliteRepository.search(text, groups)
}

fun twilight(location: LocationEntity, date: LocalDate): TwilightResponse {
Expand Down Expand Up @@ -198,21 +199,6 @@ class AtlasService(
return altitudePointsOfBody(ephemeris, stepSize)
}

fun enableSatelliteSource(source: TLESourceEntity, enabled: Boolean) {
source.enabled = enabled

tleSourceRepository.save(source)

if (!enabled) {
tleSourceRepository
.asSequence()
.onEach { it.updatedAt = 0 }
.onEach { tleSourceRepository.save(it) }
}

tleRepository.updateIfOld()
}

private fun fixedStarOf(star: StarEntity): FixedStar {
return stars.getOrPut(star.id) {
FixedStar(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.services.algorithms
package nebulosa.api.atlas

import nebulosa.horizons.HorizonsElement
import nebulosa.horizons.HorizonsQuantity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.services.ephemeris
package nebulosa.api.atlas.ephemeris

import nebulosa.horizons.HorizonsElement
import nebulosa.horizons.HorizonsQuantity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.services.ephemeris
package nebulosa.api.atlas.ephemeris

import nebulosa.horizons.HorizonsElement
import nebulosa.log.loggerFor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.services.ephemeris
package nebulosa.api.atlas.ephemeris

import nebulosa.horizons.HorizonsElement
import nebulosa.nova.position.GeographicPosition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nebulosa.api.services.ephemeris
package nebulosa.api.atlas.ephemeris

import nebulosa.horizons.HorizonsElement
import nebulosa.horizons.HorizonsQuantity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
package nebulosa.api.controllers
package nebulosa.api.cameras

import jakarta.validation.Valid
import jakarta.validation.constraints.NotBlank
import nebulosa.api.connection.ConnectionService
import nebulosa.api.data.requests.CameraStartCaptureRequest
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.*

@RestController
class CameraController(
private val equipmentService: EquipmentService,
private val connectionService: ConnectionService,
private val cameraService: CameraService,
) {

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

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

@PostMapping("cameraConnect")
fun connect(@RequestParam @Valid @NotBlank name: String) {
val camera = requireNotNull(equipmentService.camera(name))
val camera = requireNotNull(connectionService.camera(name))
cameraService.connect(camera)
}

@PostMapping("cameraDisconnect")
fun disconnect(@RequestParam @Valid @NotBlank name: String) {
val camera = requireNotNull(equipmentService.camera(name))
val camera = requireNotNull(connectionService.camera(name))
cameraService.disconnect(camera)
}

@GetMapping("cameraIsCapturing")
fun isCapturing(@RequestParam @Valid @NotBlank name: String): Boolean {
val camera = requireNotNull(equipmentService.camera(name))
val camera = requireNotNull(connectionService.camera(name))
return cameraService.isCapturing(camera)
}

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

@PostMapping("cameraCooler")
fun cooler(@RequestParam @Valid @NotBlank name: String, @RequestParam value: Boolean) {
val camera = requireNotNull(equipmentService.camera(name))
val camera = requireNotNull(connectionService.camera(name))
cameraService.cooler(camera, value)
}

@PostMapping("cameraStartCapture")
fun startCapture(@RequestParam @Valid @NotBlank name: String, @RequestBody @Valid body: CameraStartCaptureRequest) {
val camera = requireNotNull(equipmentService.camera(name))
val camera = requireNotNull(connectionService.camera(name))
cameraService.startCapture(camera, body)
}

@PostMapping("cameraAbortCapture")
fun abortCapture(@RequestParam @Valid @NotBlank name: String) {
val camera = requireNotNull(equipmentService.camera(name))
val camera = requireNotNull(connectionService.camera(name))
cameraService.abortCapture(camera)
}
}
59 changes: 59 additions & 0 deletions api/src/main/kotlin/nebulosa/api/cameras/CameraEventHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package nebulosa.api.cameras

import io.reactivex.rxjava3.subjects.PublishSubject
import jakarta.annotation.PostConstruct
import nebulosa.api.services.MessageService
import nebulosa.indi.device.PropertyChangedEvent
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.camera.CameraAttached
import nebulosa.indi.device.camera.CameraDetached
import nebulosa.indi.device.camera.CameraEvent
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.springframework.stereotype.Component
import java.util.concurrent.TimeUnit

@Component
class CameraEventHandler(
private val eventBus: EventBus,
private val messageService: MessageService,
) {

private val throttler = PublishSubject.create<CameraEvent>()

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

throttler
.throttleLast(1000, TimeUnit.MILLISECONDS)
.subscribe { sendUpdate(it.device!!) }
}

@Subscribe(threadMode = ThreadMode.ASYNC)
fun onCameraEvent(event: CameraEvent) {
when (event) {
is PropertyChangedEvent -> {
throttler.onNext(event)
}
is CameraAttached -> {
messageService.sendMessage(CAMERA_ATTACHED, event.device)
}
is CameraDetached -> {
messageService.sendMessage(CAMERA_DETACHED, event.device)
}
}
}

fun sendUpdate(device: Camera) {
messageService.sendMessage(CAMERA_UPDATED, device)
}

companion object {

const val CAMERA_UPDATED = "CAMERA_UPDATED"
const val CAMERA_ATTACHED = "CAMERA_ATTACHED"
const val CAMERA_DETACHED = "CAMERA_DETACHED"
}
}
Loading

0 comments on commit f58e5ae

Please sign in to comment.