Skip to content

Commit

Permalink
Board (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored Jun 27, 2024
1 parent ef77c7a commit b251763
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.viam.sdk.core.robot.RobotClient
import java.util.*
import java.util.stream.Stream
import kotlin.time.Duration
import kotlin.time.toJavaDuration
import java.time.Duration as JDuration

typealias Tick = StreamTicksResponse

Expand Down Expand Up @@ -226,14 +228,23 @@ abstract class Board(name: String) : Component(SUBTYPE, named(name)) {
* @param powerMode the power mode to set
* @param duration if provided, the board will exit the given power mode after this duration
*/
abstract fun setPowerMode(powerMode: PowerMode, duration: Duration, extra: Struct)
abstract fun setPowerMode(powerMode: PowerMode, duration: JDuration, extra: Struct)

/**
* Set the board to the indicated power mode.
* @param powerMode the power mode to set
* @param duration if provided, the board will exit the given power mode after this duration
*/
fun setPowerMode(powerMode: PowerMode, duration: Duration) {
fun setPowerMode(powerMode: PowerMode, duration: JDuration) {
return setPowerMode(powerMode, duration, Struct.getDefaultInstance())
}

/**
* Set the board to the indicated power mode.
* @param powerMode the power mode to set
* @param duration if provided, the board will exit the given power mode after this duration
*/
fun setPowerMode(powerMode: PowerMode, duration: Duration, extra: Struct = Struct.getDefaultInstance()) {
return setPowerMode(powerMode, duration.toJavaDuration(), extra)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import com.viam.component.board.v1.BoardServiceGrpc.BoardServiceBlockingStub
import com.viam.sdk.core.exception.MethodNotImplementedException
import com.viam.sdk.core.rpc.Channel
import com.viam.sdk.core.util.Durations
import java.time.Duration
import java.util.*
import kotlin.jvm.optionals.getOrDefault
import kotlin.time.Duration
import kotlin.time.toKotlinDuration

/**
* gRPC Client for a Board component
Expand Down Expand Up @@ -99,7 +100,7 @@ class BoardRPCClient(name: String, channel: Channel) : Board(name) {
powerMode: PowerMode, duration: Duration, extra: Struct
) {
val request = SetPowerModeRequest.newBuilder().setName(this.name.name).setPowerMode(powerMode)
.setDuration(Durations.fromNanos(duration.inWholeNanoseconds)).setExtra(extra).build()
.setDuration(Durations.fromNanos(duration.toKotlinDuration().inWholeNanoseconds)).setExtra(extra).build()
this.client.setPowerMode(request)
}

Expand All @@ -116,4 +117,5 @@ class BoardRPCClient(name: String, channel: Channel) : Board(name) {
val response = this.client.getGeometries(request)
return response.geometriesList
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import java.util.*
import kotlin.random.Random
import kotlin.time.DurationUnit
import kotlin.time.toDuration
import kotlin.time.toJavaDuration

class BoardTest {
private lateinit var board: Board
Expand Down Expand Up @@ -163,6 +164,6 @@ class BoardTest {
val powerMode = PowerMode.POWER_MODE_OFFLINE_DEEP
val powerModeDuration = Random.nextInt().toDuration(DurationUnit.NANOSECONDS)
board.setPowerMode(powerMode, powerModeDuration)
verify(board).setPowerMode(powerMode, powerModeDuration)
verify(board).setPowerMode(powerMode, powerModeDuration.toJavaDuration(), Struct.getDefaultInstance())
}
}

0 comments on commit b251763

Please sign in to comment.