Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebServer as a device #458

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@file:Suppress("NON_EXPORTABLE_TYPE")

package dk.cachet.carp.common.application.devices

import dk.cachet.carp.common.application.Trilean
import dk.cachet.carp.common.application.data.DataType
import dk.cachet.carp.common.application.sampling.DataTypeSamplingSchemeMap
import dk.cachet.carp.common.application.sampling.SamplingConfiguration
import dk.cachet.carp.common.application.tasks.TaskConfigurationList
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
import kotlin.reflect.KClass

typealias WebServerDeviceRegistration = DefaultDeviceRegistration
typealias WebServerDeviceRegistrationBuilder = DefaultDeviceRegistrationBuilder

@Serializable
@JsExport
data class WebServer(
val url: String,
override val roleName: String,
override val isOptional: Boolean = false
) : PrimaryDeviceConfiguration<WebServerDeviceRegistration, WebServerDeviceRegistrationBuilder>()
{
companion object
{
fun create( url: String, roleName: String ): WebServer = WebServer( url, roleName )
}

object Sensors : DataTypeSamplingSchemeMap()
object Tasks : TaskConfigurationList()

override fun getSupportedDataTypes(): Set<DataType> = Sensors.keys

override val defaultSamplingConfiguration: Map<DataType, SamplingConfiguration> = emptyMap()

override fun getDataTypeSamplingSchemes(): DataTypeSamplingSchemeMap = Sensors

override fun createDeviceRegistrationBuilder(): WebServerDeviceRegistrationBuilder =
WebServerDeviceRegistrationBuilder()

override fun getRegistrationClass(): KClass<WebServerDeviceRegistration> = WebServerDeviceRegistration::class

override fun isValidRegistration( registration: WebServerDeviceRegistration ): Trilean = Trilean.TRUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ val COMMON_SERIAL_MODULE = SerializersModule {
{
subclass( CustomProtocolDevice::class )
subclass( Smartphone::class )
subclass( WebServer::class )

subclass( CustomPrimaryDeviceConfiguration::class )
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ val commonInstances = listOf(
BLESerialNumberDeviceRegistration( "123456789" ),
CustomProtocolDevice( "User's phone" ),
Smartphone( "User's phone" ),
WebServer( "https://example.com", "Example server" ),

// Shared device registrations in `devices` namespace.
DefaultDeviceRegistration(),
Expand Down
14 changes: 7 additions & 7 deletions docs/carp-common.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ _Primary_ devices ([`PrimaryDeviceConfiguration`](../carp.common/src/commonMain/
in addition to supporting data collection from internal sensors,
act as a hub to aggregate, synchronize, and upload incoming data received from one or more connected devices.

| Class | Primary | Description |
|--------------------------------------------------------------------------------------------------------------------------------|:-------:|----------------------------------------------------------------------------------------------------------|
| [Smartphone](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/Smartphone.kt) | Yes | An internet-connected phone with built-in sensors. |
| [AltBeacon](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/AltBeacon.kt) | | A beacon meeting the open AltBeacon standard. |
| [BLEHeartRateDevice](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/BLEHeartRateDevice.kt) | | A Bluetooth device which implements a Heart Rate service. |
| [CustomProtocolDevice](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/CustomProtocolDevice.kt) | Yes | A primary device which uses a single `CustomProtocolTask` to determine how to run a study on the device. |

| Class | Primary | Description |
|--------------------------------------------------------------------------------------------------------------------------------|:-------:|-----------------------------------------------------------------------------------------------------------|
| [Smartphone](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/Smartphone.kt) | Yes | An internet-connected phone with built-in sensors. |
| [AltBeacon](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/AltBeacon.kt) | | A beacon meeting the open AltBeacon standard. |
| [BLEHeartRateDevice](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/BLEHeartRateDevice.kt) | | A Bluetooth device which implements a Heart Rate service. |
| [CustomProtocolDevice](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/CustomProtocolDevice.kt) | Yes | A primary device which uses a single `CustomProtocolTask` to determine how to run a study on the device. |
| [WebServer](../carp.common/src/commonMain/kotlin/dk/cachet/carp/common/application/devices/WebServer.kt) | Yes | A primary device that has an associated URL where the study is hosted. |
## Sampling schemes and configurations

Supports specifying the sampling scheme for a [`DataType`](#data-types), including possible options, defaults, and constraints.
Expand Down
Loading