-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
682 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
api/src/main/kotlin/nebulosa/api/dustcap/DustCapController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import nebulosa.api.connection.ConnectionService | ||
import nebulosa.indi.device.dustcap.DustCap | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("dust-caps") | ||
class DustCapController( | ||
private val connectionService: ConnectionService, | ||
private val dustCapService: DustCapService, | ||
) { | ||
|
||
@GetMapping | ||
fun dustCaps(): List<DustCap> { | ||
return connectionService.dustCaps().sorted() | ||
} | ||
|
||
@GetMapping("{dustCap}") | ||
fun dustCap(dustCap: DustCap): DustCap { | ||
return dustCap | ||
} | ||
|
||
@PutMapping("{dustCap}/connect") | ||
fun connect(dustCap: DustCap) { | ||
dustCapService.connect(dustCap) | ||
} | ||
|
||
@PutMapping("{dustCap}/disconnect") | ||
fun disconnect(dustCap: DustCap) { | ||
dustCapService.disconnect(dustCap) | ||
} | ||
|
||
@PutMapping("{dustCap}/park") | ||
fun park(dustCap: DustCap) { | ||
dustCapService.park(dustCap) | ||
} | ||
|
||
@PutMapping("{dustCap}/unpark") | ||
fun unpark(dustCap: DustCap) { | ||
dustCapService.unpark(dustCap) | ||
} | ||
|
||
@PutMapping("{dustCap}/listen") | ||
fun listen(dustCap: DustCap) { | ||
dustCapService.listen(dustCap) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/kotlin/nebulosa/api/dustcap/DustCapDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import nebulosa.api.connection.ConnectionService | ||
import nebulosa.api.devices.DeviceDeserializer | ||
import nebulosa.indi.device.dustcap.DustCap | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.context.annotation.Lazy | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DustCapDeserializer : DeviceDeserializer<DustCap>(DustCap::class.java) { | ||
|
||
@Autowired @Lazy private lateinit var connectionService: ConnectionService | ||
|
||
override fun deviceFor(name: String) = connectionService.dustCap(name) | ||
} |
8 changes: 8 additions & 0 deletions
8
api/src/main/kotlin/nebulosa/api/dustcap/DustCapEventAware.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import nebulosa.indi.device.dustcap.DustCapEvent | ||
|
||
fun interface DustCapEventAware { | ||
|
||
fun handleDustCapEvent(event: DustCapEvent) | ||
} |
36 changes: 36 additions & 0 deletions
36
api/src/main/kotlin/nebulosa/api/dustcap/DustCapEventHub.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import nebulosa.api.beans.annotations.Subscriber | ||
import nebulosa.api.devices.DeviceEventHub | ||
import nebulosa.api.message.MessageService | ||
import nebulosa.indi.device.DeviceType | ||
import nebulosa.indi.device.PropertyChangedEvent | ||
import nebulosa.indi.device.dustcap.DustCap | ||
import nebulosa.indi.device.dustcap.DustCapAttached | ||
import nebulosa.indi.device.dustcap.DustCapDetached | ||
import nebulosa.indi.device.dustcap.DustCapEvent | ||
import org.greenrobot.eventbus.Subscribe | ||
import org.greenrobot.eventbus.ThreadMode | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
@Subscriber | ||
class DustCapEventHub( | ||
private val messageService: MessageService, | ||
) : DeviceEventHub<DustCap, DustCapEvent>(DeviceType.DUST_CAP), DustCapEventAware { | ||
|
||
@Subscribe(threadMode = ThreadMode.ASYNC) | ||
override fun handleDustCapEvent(event: DustCapEvent) { | ||
if (event.device.type == DeviceType.DUST_CAP) { | ||
when (event) { | ||
is PropertyChangedEvent -> onNext(event) | ||
is DustCapAttached -> onAttached(event.device) | ||
is DustCapDetached -> onDetached(event.device) | ||
} | ||
} | ||
} | ||
|
||
override fun sendMessage(eventName: String, device: DustCap) { | ||
messageService.sendMessage(DustCapMessageEvent(eventName, device)) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
api/src/main/kotlin/nebulosa/api/dustcap/DustCapMessageEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import nebulosa.api.devices.DeviceMessageEvent | ||
import nebulosa.indi.device.dustcap.DustCap | ||
|
||
data class DustCapMessageEvent(override val eventName: String, override val device: DustCap) : DeviceMessageEvent<DustCap> |
16 changes: 16 additions & 0 deletions
16
api/src/main/kotlin/nebulosa/api/dustcap/DustCapSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator | ||
import nebulosa.api.devices.DeviceSerializer | ||
import nebulosa.indi.device.dustcap.DustCap | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DustCapSerializer : DeviceSerializer<DustCap>(DustCap::class.java) { | ||
|
||
override fun JsonGenerator.serialize(value: DustCap) { | ||
writeBooleanField("canPark", value.canPark) | ||
writeBooleanField("parking", value.parking) | ||
writeBooleanField("parked", value.parked) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/kotlin/nebulosa/api/dustcap/DustCapService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import nebulosa.indi.device.dustcap.DustCap | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DustCapService(private val dustCapEventHub: DustCapEventHub) { | ||
|
||
fun connect(dustCap: DustCap) { | ||
dustCap.connect() | ||
} | ||
|
||
fun disconnect(dustCap: DustCap) { | ||
dustCap.disconnect() | ||
} | ||
|
||
fun park(dustCap: DustCap) { | ||
dustCap.park() | ||
} | ||
|
||
fun unpark(dustCap: DustCap) { | ||
dustCap.unpark() | ||
} | ||
|
||
fun listen(dustCap: DustCap) { | ||
dustCapEventHub.listen(dustCap) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.