Skip to content

Commit

Permalink
Adapt Proto Files
Browse files Browse the repository at this point in the history
  • Loading branch information
wba2hi committed Nov 14, 2024
1 parent b9421a7 commit 94c7f37
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

package com.example.service

import DoorServiceGrpc
import DoorServiceOuterClass
import android.util.Log
import door.DoorGrpc
import door.DoorGrpc.DoorFutureStub
import door.DoorService
import io.grpc.Grpc
import io.grpc.InsecureChannelCredentials

Expand All @@ -30,29 +29,29 @@ class GrpcCarService(
port: Int,
) : CarService {

private val doorService: DoorFutureStub
private val doorService: DoorServiceGrpc.DoorServiceFutureStub

init {
Log.i(TAG, "Connecting to gRPC service at $host:$port")

val channelCredentials = InsecureChannelCredentials.create()
val channel = Grpc.newChannelBuilderForAddress(host, port, channelCredentials).build()

doorService = DoorGrpc.newFutureStub(channel)
doorService = DoorServiceGrpc.newFutureStub(channel)
}

// Door service
override fun lockDoor(): Boolean {
val request = DoorService.LockRequest.newBuilder().build()
val response = doorService.lock(request).get() // blocking call
Log.i(TAG, "lockDoor: Got response: " + response.getCode())
return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS
val request = DoorServiceOuterClass.LockDoorRequest.newBuilder().build()
val response = doorService.lockDoor(request).get() // blocking call
Log.i(TAG, "lockDoor: Got response: " + response.success)
return response.success
}

override fun unlockDoor(): Boolean {
val request = DoorService.UnlockRequest.newBuilder().build()
val response = doorService.unlock(request).get() // blocking call
Log.i(TAG, "unlockDoor: Got response: " + response.getCode())
return response.getCode() == DoorService.BCMReturnCode.BCM_RETURN_CODE_SUCCESS
val request = DoorServiceOuterClass.UnlockDoorRequest.newBuilder().build()
val response = doorService.unlockDoor(request).get() // blocking call
Log.i(TAG, "unlockDoor: Got response: " + response.success)
return response.success
}
}
20 changes: 20 additions & 0 deletions SampleApp/src/main/proto/DoorService.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

message UnlockDoorRequest {
}

message UnlockDoorResponse {
optional bool success = 1;
}

message LockDoorRequest {
}

message LockDoorResponse {
optional bool success = 1;
}

service DoorService {
rpc UnlockDoor(UnlockDoorRequest) returns (UnlockDoorResponse);
rpc LockDoor(LockDoorRequest) returns (LockDoorResponse);
}
37 changes: 37 additions & 0 deletions SampleApp/src/main/proto/FoldingService.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
syntax = "proto3";

message FoldMirrorsRequest {
}

message FoldMirrorsResponse {
optional bool success = 1;
}

message UnfoldMirrorsRequest {
}

message UnfoldMirrorsResponse {
optional bool success = 1;
}

message GetMirrorFoldStatusRequest {
}

message GetMirrorFoldStatusResponse {
optional uint32 status = 1;
}

message SetMirrorFoldStatusRequest {
optional uint32 mirrorFoldStatus = 1;
}

message SetMirrorFoldStatusResponse {
optional bool success = 1;
}

service FoldingService {
rpc FoldMirrors(FoldMirrorsRequest) returns (FoldMirrorsResponse);
rpc UnfoldMirrors(UnfoldMirrorsRequest) returns (UnfoldMirrorsResponse);
rpc GetMirrorFoldStatus(GetMirrorFoldStatusRequest) returns (GetMirrorFoldStatusResponse);
rpc SetMirrorFoldStatus(SetMirrorFoldStatusRequest) returns (SetMirrorFoldStatusResponse);
}
37 changes: 37 additions & 0 deletions SampleApp/src/main/proto/FronthousingService.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
syntax = "proto3";

message EnableAirConditioningRequest {
}

message EnableAirConditioningResponse {
optional bool success = 1;
}

message DisableAirConditioningRequest {
}

message DisableAirConditioningResponse {
optional bool success = 1;
}

message GetAirConditioningStatusRequest {
}

message GetAirConditioningStatusResponse {
optional uint32 status = 1;
}

message SetAirConditioningStatusRequest {
optional uint32 airConditioningStatus = 1;
}

message SetAirConditioningStatusResponse {
optional bool success = 1;
}

service FronthousingService {
rpc EnableAirConditioning(EnableAirConditioningRequest) returns (EnableAirConditioningResponse);
rpc DisableAirConditioning(DisableAirConditioningRequest) returns (DisableAirConditioningResponse);
rpc GetAirConditioningStatus(GetAirConditioningStatusRequest) returns (GetAirConditioningStatusResponse);
rpc SetAirConditioningStatus(SetAirConditioningStatusRequest) returns (SetAirConditioningStatusResponse);
}
44 changes: 0 additions & 44 deletions app/src/main/proto/door.proto

This file was deleted.

2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ dependencyResolutionManagement {

rootProject.name = "vehicle-app-kotlin-template"
include(":sdk")
include(":app")
include(":SampleApp")

0 comments on commit 94c7f37

Please sign in to comment.