Skip to content

Commit

Permalink
RSDK-7309: Update Status for Board in Flutter SDK (#193)
Browse files Browse the repository at this point in the history
* remove status from board

* fix formatting

* Update widget

* generate protos

* fix test

* return 0 for value of analogs and digitals

---------

Co-authored-by: Naveed Jooma <naveed@viam.com>
  • Loading branch information
martha-johnston and njooma authored Apr 26, 2024
1 parent 661bffb commit 1106568
Show file tree
Hide file tree
Showing 18 changed files with 563 additions and 399 deletions.
34 changes: 1 addition & 33 deletions lib/src/components/board/board.dart
Original file line number Diff line number Diff line change
@@ -1,50 +1,18 @@
import 'dart:collection';

import 'package:fixnum/fixnum.dart';

import '../../gen/common/v1/common.pb.dart' as common;
import '../../gen/component/board/v1/board.pbgrpc.dart';
import '../../resource/base.dart';
import '../../robot/client.dart';

/// The values of the [Board]'s analog readers and digital interrupts
class BoardStatus {
final Map<String, int> analogs;
final Map<String, int> digitalInterrupts;

const BoardStatus(this.analogs, this.digitalInterrupts);

factory BoardStatus.fromProto(common.BoardStatus pbBoardStatus) {
final Map<String, int> analogs = pbBoardStatus.analogs.map((key, value) => MapEntry(key, value.value));
final Map<String, int> digitalInterrupts = pbBoardStatus.digitalInterrupts.map((key, value) => MapEntry(key, value.value.toInt()));
return BoardStatus(analogs, digitalInterrupts);
}

common.BoardStatus get proto {
final pbBoardStatus = common.BoardStatus();
analogs.forEach((key, value) => pbBoardStatus.analogs[key] = common.AnalogStatus()..value = value);
digitalInterrupts.forEach((key, value) => pbBoardStatus.digitalInterrupts[key] = common.DigitalInterruptStatus()..value = Int64(value));
return pbBoardStatus;
}
}

/// Tick of a digital interrupt
class Tick {
String pinName;
bool high;
Int64 time;

Tick({required this.pinName, required this.high, required this.time});
}
typedef Tick = StreamTicksResponse;

/// Board represents a physical general purpose compute board that contains various
/// components such as analog readers, and digital interrupts.
abstract class Board extends Resource {
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeComponent, 'board');

/// Get the status of the Board.
Future<BoardStatus> status({Map<String, dynamic>? extra});

/// Set the high/low state of the given pin of a board.
Future<void> setGpioState(String pin, bool high, {Map<String, dynamic>? extra});

Expand Down
9 changes: 0 additions & 9 deletions lib/src/components/board/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ class BoardClient extends Board implements ResourceRPCClient {
return response.result.toMap();
}

@override
Future<BoardStatus> status({Map<String, dynamic>? extra}) async {
final request = StatusRequest()
..name = name
..extra = extra?.toStruct() ?? Struct();
final response = await client.status(request);
return BoardStatus.fromProto(response.status);
}

@override
Future<void> setGpioState(String pin, bool high, {Map<String, dynamic>? extra}) async {
final request = SetGPIORequest()
Expand Down
7 changes: 0 additions & 7 deletions lib/src/components/board/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ class BoardService extends BoardServiceBase {
return SetPowerModeResponse();
}

@override
Future<StatusResponse> status(ServiceCall call, StatusRequest request) async {
final board = _fromManager(request.name);
final boardStatus = await board.status(extra: request.extra.toMap());
return StatusResponse()..status = boardStatus.proto;
}

@override
Future<common.GetGeometriesResponse> getGeometries(ServiceCall call, common.GetGeometriesRequest request) {
// TODO: implement getGeometries
Expand Down
198 changes: 198 additions & 0 deletions lib/src/gen/app/mltraining/v1/ml_training.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,162 @@ class SubmitTrainingJobResponse extends $pb.GeneratedMessage {
void clearId() => clearField(1);
}

class SubmitCustomTrainingJobRequest extends $pb.GeneratedMessage {
factory SubmitCustomTrainingJobRequest({
$core.String? datasetId,
$core.String? registryItemId,
$core.String? organizationId,
$core.String? modelName,
$core.String? modelVersion,
}) {
final $result = create();
if (datasetId != null) {
$result.datasetId = datasetId;
}
if (registryItemId != null) {
$result.registryItemId = registryItemId;
}
if (organizationId != null) {
$result.organizationId = organizationId;
}
if (modelName != null) {
$result.modelName = modelName;
}
if (modelVersion != null) {
$result.modelVersion = modelVersion;
}
return $result;
}
SubmitCustomTrainingJobRequest._() : super();
factory SubmitCustomTrainingJobRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory SubmitCustomTrainingJobRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'SubmitCustomTrainingJobRequest', package: const $pb.PackageName(_omitMessageNames ? '' : 'viam.app.mltraining.v1'), createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'datasetId')
..aOS(2, _omitFieldNames ? '' : 'registryItemId')
..aOS(3, _omitFieldNames ? '' : 'organizationId')
..aOS(4, _omitFieldNames ? '' : 'modelName')
..aOS(5, _omitFieldNames ? '' : 'modelVersion')
..hasRequiredFields = false
;

@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
SubmitCustomTrainingJobRequest clone() => SubmitCustomTrainingJobRequest()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
SubmitCustomTrainingJobRequest copyWith(void Function(SubmitCustomTrainingJobRequest) updates) => super.copyWith((message) => updates(message as SubmitCustomTrainingJobRequest)) as SubmitCustomTrainingJobRequest;

$pb.BuilderInfo get info_ => _i;

@$core.pragma('dart2js:noInline')
static SubmitCustomTrainingJobRequest create() => SubmitCustomTrainingJobRequest._();
SubmitCustomTrainingJobRequest createEmptyInstance() => create();
static $pb.PbList<SubmitCustomTrainingJobRequest> createRepeated() => $pb.PbList<SubmitCustomTrainingJobRequest>();
@$core.pragma('dart2js:noInline')
static SubmitCustomTrainingJobRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<SubmitCustomTrainingJobRequest>(create);
static SubmitCustomTrainingJobRequest? _defaultInstance;

@$pb.TagNumber(1)
$core.String get datasetId => $_getSZ(0);
@$pb.TagNumber(1)
set datasetId($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasDatasetId() => $_has(0);
@$pb.TagNumber(1)
void clearDatasetId() => clearField(1);

@$pb.TagNumber(2)
$core.String get registryItemId => $_getSZ(1);
@$pb.TagNumber(2)
set registryItemId($core.String v) { $_setString(1, v); }
@$pb.TagNumber(2)
$core.bool hasRegistryItemId() => $_has(1);
@$pb.TagNumber(2)
void clearRegistryItemId() => clearField(2);

@$pb.TagNumber(3)
$core.String get organizationId => $_getSZ(2);
@$pb.TagNumber(3)
set organizationId($core.String v) { $_setString(2, v); }
@$pb.TagNumber(3)
$core.bool hasOrganizationId() => $_has(2);
@$pb.TagNumber(3)
void clearOrganizationId() => clearField(3);

@$pb.TagNumber(4)
$core.String get modelName => $_getSZ(3);
@$pb.TagNumber(4)
set modelName($core.String v) { $_setString(3, v); }
@$pb.TagNumber(4)
$core.bool hasModelName() => $_has(3);
@$pb.TagNumber(4)
void clearModelName() => clearField(4);

@$pb.TagNumber(5)
$core.String get modelVersion => $_getSZ(4);
@$pb.TagNumber(5)
set modelVersion($core.String v) { $_setString(4, v); }
@$pb.TagNumber(5)
$core.bool hasModelVersion() => $_has(4);
@$pb.TagNumber(5)
void clearModelVersion() => clearField(5);
}

class SubmitCustomTrainingJobResponse extends $pb.GeneratedMessage {
factory SubmitCustomTrainingJobResponse({
$core.String? id,
}) {
final $result = create();
if (id != null) {
$result.id = id;
}
return $result;
}
SubmitCustomTrainingJobResponse._() : super();
factory SubmitCustomTrainingJobResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory SubmitCustomTrainingJobResponse.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);

static final $pb.BuilderInfo _i = $pb.BuilderInfo(_omitMessageNames ? '' : 'SubmitCustomTrainingJobResponse', package: const $pb.PackageName(_omitMessageNames ? '' : 'viam.app.mltraining.v1'), createEmptyInstance: create)
..aOS(1, _omitFieldNames ? '' : 'id')
..hasRequiredFields = false
;

@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
SubmitCustomTrainingJobResponse clone() => SubmitCustomTrainingJobResponse()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
SubmitCustomTrainingJobResponse copyWith(void Function(SubmitCustomTrainingJobResponse) updates) => super.copyWith((message) => updates(message as SubmitCustomTrainingJobResponse)) as SubmitCustomTrainingJobResponse;

$pb.BuilderInfo get info_ => _i;

@$core.pragma('dart2js:noInline')
static SubmitCustomTrainingJobResponse create() => SubmitCustomTrainingJobResponse._();
SubmitCustomTrainingJobResponse createEmptyInstance() => create();
static $pb.PbList<SubmitCustomTrainingJobResponse> createRepeated() => $pb.PbList<SubmitCustomTrainingJobResponse>();
@$core.pragma('dart2js:noInline')
static SubmitCustomTrainingJobResponse getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<SubmitCustomTrainingJobResponse>(create);
static SubmitCustomTrainingJobResponse? _defaultInstance;

@$pb.TagNumber(1)
$core.String get id => $_getSZ(0);
@$pb.TagNumber(1)
set id($core.String v) { $_setString(0, v); }
@$pb.TagNumber(1)
$core.bool hasId() => $_has(0);
@$pb.TagNumber(1)
void clearId() => clearField(1);
}

class GetTrainingJobRequest extends $pb.GeneratedMessage {
factory GetTrainingJobRequest({
$core.String? id,
Expand Down Expand Up @@ -410,6 +566,9 @@ class TrainingJobMetadata extends $pb.GeneratedMessage {
$core.String? modelVersion,
ModelType? modelType,
$core.Iterable<$core.String>? tags,
ModelFramework? modelFramework,
$core.bool? isCustomJob,
$core.String? registryItemId,
}) {
final $result = create();
if (request != null) {
Expand Down Expand Up @@ -457,6 +616,15 @@ class TrainingJobMetadata extends $pb.GeneratedMessage {
if (tags != null) {
$result.tags.addAll(tags);
}
if (modelFramework != null) {
$result.modelFramework = modelFramework;
}
if (isCustomJob != null) {
$result.isCustomJob = isCustomJob;
}
if (registryItemId != null) {
$result.registryItemId = registryItemId;
}
return $result;
}
TrainingJobMetadata._() : super();
Expand All @@ -479,6 +647,9 @@ class TrainingJobMetadata extends $pb.GeneratedMessage {
..aOS(14, _omitFieldNames ? '' : 'modelVersion')
..e<ModelType>(15, _omitFieldNames ? '' : 'modelType', $pb.PbFieldType.OE, defaultOrMaker: ModelType.MODEL_TYPE_UNSPECIFIED, valueOf: ModelType.valueOf, enumValues: ModelType.values)
..pPS(16, _omitFieldNames ? '' : 'tags')
..e<ModelFramework>(17, _omitFieldNames ? '' : 'modelFramework', $pb.PbFieldType.OE, defaultOrMaker: ModelFramework.MODEL_FRAMEWORK_UNSPECIFIED, valueOf: ModelFramework.valueOf, enumValues: ModelFramework.values)
..aOB(18, _omitFieldNames ? '' : 'isCustomJob')
..aOS(19, _omitFieldNames ? '' : 'registryItemId')
..hasRequiredFields = false
;

Expand Down Expand Up @@ -643,6 +814,33 @@ class TrainingJobMetadata extends $pb.GeneratedMessage {

@$pb.TagNumber(16)
$core.List<$core.String> get tags => $_getList(14);

@$pb.TagNumber(17)
ModelFramework get modelFramework => $_getN(15);
@$pb.TagNumber(17)
set modelFramework(ModelFramework v) { setField(17, v); }
@$pb.TagNumber(17)
$core.bool hasModelFramework() => $_has(15);
@$pb.TagNumber(17)
void clearModelFramework() => clearField(17);

@$pb.TagNumber(18)
$core.bool get isCustomJob => $_getBF(16);
@$pb.TagNumber(18)
set isCustomJob($core.bool v) { $_setBool(16, v); }
@$pb.TagNumber(18)
$core.bool hasIsCustomJob() => $_has(16);
@$pb.TagNumber(18)
void clearIsCustomJob() => clearField(18);

@$pb.TagNumber(19)
$core.String get registryItemId => $_getSZ(17);
@$pb.TagNumber(19)
set registryItemId($core.String v) { $_setString(17, v); }
@$pb.TagNumber(19)
$core.bool hasRegistryItemId() => $_has(17);
@$pb.TagNumber(19)
void clearRegistryItemId() => clearField(19);
}

class CancelTrainingJobRequest extends $pb.GeneratedMessage {
Expand Down
20 changes: 20 additions & 0 deletions lib/src/gen/app/mltraining/v1/ml_training.pbgrpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class MLTrainingServiceClient extends $grpc.Client {
'/viam.app.mltraining.v1.MLTrainingService/SubmitTrainingJob',
($0.SubmitTrainingJobRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.SubmitTrainingJobResponse.fromBuffer(value));
static final _$submitCustomTrainingJob = $grpc.ClientMethod<$0.SubmitCustomTrainingJobRequest, $0.SubmitCustomTrainingJobResponse>(
'/viam.app.mltraining.v1.MLTrainingService/SubmitCustomTrainingJob',
($0.SubmitCustomTrainingJobRequest value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.SubmitCustomTrainingJobResponse.fromBuffer(value));
static final _$getTrainingJob = $grpc.ClientMethod<$0.GetTrainingJobRequest, $0.GetTrainingJobResponse>(
'/viam.app.mltraining.v1.MLTrainingService/GetTrainingJob',
($0.GetTrainingJobRequest value) => value.writeToBuffer(),
Expand Down Expand Up @@ -52,6 +56,10 @@ class MLTrainingServiceClient extends $grpc.Client {
return $createUnaryCall(_$submitTrainingJob, request, options: options);
}

$grpc.ResponseFuture<$0.SubmitCustomTrainingJobResponse> submitCustomTrainingJob($0.SubmitCustomTrainingJobRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$submitCustomTrainingJob, request, options: options);
}

$grpc.ResponseFuture<$0.GetTrainingJobResponse> getTrainingJob($0.GetTrainingJobRequest request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$getTrainingJob, request, options: options);
}
Expand Down Expand Up @@ -81,6 +89,13 @@ abstract class MLTrainingServiceBase extends $grpc.Service {
false,
($core.List<$core.int> value) => $0.SubmitTrainingJobRequest.fromBuffer(value),
($0.SubmitTrainingJobResponse value) => value.writeToBuffer()));
$addMethod($grpc.ServiceMethod<$0.SubmitCustomTrainingJobRequest, $0.SubmitCustomTrainingJobResponse>(
'SubmitCustomTrainingJob',
submitCustomTrainingJob_Pre,
false,
false,
($core.List<$core.int> value) => $0.SubmitCustomTrainingJobRequest.fromBuffer(value),
($0.SubmitCustomTrainingJobResponse value) => value.writeToBuffer()));
$addMethod($grpc.ServiceMethod<$0.GetTrainingJobRequest, $0.GetTrainingJobResponse>(
'GetTrainingJob',
getTrainingJob_Pre,
Expand Down Expand Up @@ -115,6 +130,10 @@ abstract class MLTrainingServiceBase extends $grpc.Service {
return submitTrainingJob(call, await request);
}

$async.Future<$0.SubmitCustomTrainingJobResponse> submitCustomTrainingJob_Pre($grpc.ServiceCall call, $async.Future<$0.SubmitCustomTrainingJobRequest> request) async {
return submitCustomTrainingJob(call, await request);
}

$async.Future<$0.GetTrainingJobResponse> getTrainingJob_Pre($grpc.ServiceCall call, $async.Future<$0.GetTrainingJobRequest> request) async {
return getTrainingJob(call, await request);
}
Expand All @@ -132,6 +151,7 @@ abstract class MLTrainingServiceBase extends $grpc.Service {
}

$async.Future<$0.SubmitTrainingJobResponse> submitTrainingJob($grpc.ServiceCall call, $0.SubmitTrainingJobRequest request);
$async.Future<$0.SubmitCustomTrainingJobResponse> submitCustomTrainingJob($grpc.ServiceCall call, $0.SubmitCustomTrainingJobRequest request);
$async.Future<$0.GetTrainingJobResponse> getTrainingJob($grpc.ServiceCall call, $0.GetTrainingJobRequest request);
$async.Future<$0.ListTrainingJobsResponse> listTrainingJobs($grpc.ServiceCall call, $0.ListTrainingJobsRequest request);
$async.Future<$0.CancelTrainingJobResponse> cancelTrainingJob($grpc.ServiceCall call, $0.CancelTrainingJobRequest request);
Expand Down
Loading

0 comments on commit 1106568

Please sign in to comment.