-
-
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
12 changed files
with
187 additions
and
6 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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
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-cap") | ||
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) | ||
} | ||
} |
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.beans.converters.device.DeviceDeserializer | ||
import nebulosa.api.connection.ConnectionService | ||
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> |
24 changes: 24 additions & 0 deletions
24
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,24 @@ | ||
package nebulosa.api.dustcap | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator | ||
import com.fasterxml.jackson.databind.SerializerProvider | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer | ||
import nebulosa.indi.device.dustcap.DustCap | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DustCapSerializer : StdSerializer<DustCap>(DustCap::class.java) { | ||
|
||
override fun serialize(value: DustCap, gen: JsonGenerator, provider: SerializerProvider) { | ||
gen.writeStartObject() | ||
gen.writeStringField("type", value.type.name) | ||
gen.writeStringField("sender", value.sender.id) | ||
gen.writeStringField("id", value.id) | ||
gen.writeStringField("name", value.name) | ||
gen.writeBooleanField("connected", value.connected) | ||
gen.writeBooleanField("canPark", value.canPark) | ||
gen.writeBooleanField("parking", value.parking) | ||
gen.writeBooleanField("parked", value.parked) | ||
gen.writeEndObject() | ||
} | ||
} |
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