Stop using a grpc stream.

This commit is contained in:
Piv
2019-11-28 08:01:26 +10:30
parent eae291da07
commit 10e45f5b45
4 changed files with 14 additions and 18 deletions

View File

@@ -20,16 +20,12 @@ class MotorServicer(motorService_pb2_grpc.CarControlServicer):
self._timer = None self._timer = None
def SetThrottle(self, request_iterator, context): def SetThrottle(self, request_iterator, context):
# gRPC streams currently don't work between python and android.
# If we don't get a response every 3 seconds, stop the car. # If we don't get a response every 3 seconds, stop the car.
# This isn't a stream right now, however may change it to be so since we'll constantly
# be sending values...
throttleFailed = False throttleFailed = False
for throttleRequest in request_iterator:
print('Setting throttle to: ' + str(throttleRequest.throttle)) print('Setting throttle to: ' + str(throttleRequest.throttle))
self.set_timeout(3) self.set_timeout(3)
throttleFailed = self.motor.set_throttle(throttleRequest.throttle) throttleFailed = self.motor.set_throttle(throttleRequest.throttle)
if not throttleFailed:
break
return motorService_pb2.ThrottleResponse(throttleSet = throttleFailed) return motorService_pb2.ThrottleResponse(throttleSet = throttleFailed)
def SetSteering(self, request, context): def SetSteering(self, request, context):

View File

@@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor(
package='MotorControl', package='MotorControl',
syntax='proto3', syntax='proto3',
serialized_options=None, serialized_options=None,
serialized_pb=_b('\n\x12motorService.proto\x12\x0cMotorControl\"#\n\x0fThrottleRequest\x12\x10\n\x08throttle\x18\x01 \x01(\x02\"\'\n\x10ThrottleResponse\x12\x13\n\x0bthrottleSet\x18\x01 \x01(\x08\"#\n\x0fSteeringRequest\x12\x10\n\x08steering\x18\x01 \x01(\x02\"\'\n\x10SteeringResponse\x12\x13\n\x0bsteeringSet\x18\x01 \x01(\x08\x32\xb0\x01\n\nCarControl\x12P\n\x0bSetThrottle\x12\x1d.MotorControl.ThrottleRequest\x1a\x1e.MotorControl.ThrottleResponse\"\x00(\x01\x12P\n\x0bSetSteering\x12\x1d.MotorControl.SteeringRequest\x1a\x1e.MotorControl.SteeringResponse\"\x00(\x01\x62\x06proto3') serialized_pb=_b('\n\x12motorService.proto\x12\x0cMotorControl\"#\n\x0fThrottleRequest\x12\x10\n\x08throttle\x18\x01 \x01(\x02\"\'\n\x10ThrottleResponse\x12\x13\n\x0bthrottleSet\x18\x01 \x01(\x08\"#\n\x0fSteeringRequest\x12\x10\n\x08steering\x18\x01 \x01(\x02\"\'\n\x10SteeringResponse\x12\x13\n\x0bsteeringSet\x18\x01 \x01(\x08\x32\xac\x01\n\nCarControl\x12N\n\x0bSetThrottle\x12\x1d.MotorControl.ThrottleRequest\x1a\x1e.MotorControl.ThrottleResponse\"\x00\x12N\n\x0bSetSteering\x12\x1d.MotorControl.SteeringRequest\x1a\x1e.MotorControl.SteeringResponse\"\x00\x62\x06proto3')
) )
@@ -192,7 +192,7 @@ _CARCONTROL = _descriptor.ServiceDescriptor(
index=0, index=0,
serialized_options=None, serialized_options=None,
serialized_start=193, serialized_start=193,
serialized_end=369, serialized_end=365,
methods=[ methods=[
_descriptor.MethodDescriptor( _descriptor.MethodDescriptor(
name='SetThrottle', name='SetThrottle',

View File

@@ -14,12 +14,12 @@ class CarControlStub(object):
Args: Args:
channel: A grpc.Channel. channel: A grpc.Channel.
""" """
self.SetThrottle = channel.stream_unary( self.SetThrottle = channel.unary_unary(
'/MotorControl.CarControl/SetThrottle', '/MotorControl.CarControl/SetThrottle',
request_serializer=motorService__pb2.ThrottleRequest.SerializeToString, request_serializer=motorService__pb2.ThrottleRequest.SerializeToString,
response_deserializer=motorService__pb2.ThrottleResponse.FromString, response_deserializer=motorService__pb2.ThrottleResponse.FromString,
) )
self.SetSteering = channel.stream_unary( self.SetSteering = channel.unary_unary(
'/MotorControl.CarControl/SetSteering', '/MotorControl.CarControl/SetSteering',
request_serializer=motorService__pb2.SteeringRequest.SerializeToString, request_serializer=motorService__pb2.SteeringRequest.SerializeToString,
response_deserializer=motorService__pb2.SteeringResponse.FromString, response_deserializer=motorService__pb2.SteeringResponse.FromString,
@@ -30,14 +30,14 @@ class CarControlServicer(object):
# missing associated documentation comment in .proto file # missing associated documentation comment in .proto file
pass pass
def SetThrottle(self, request_iterator, context): def SetThrottle(self, request, context):
# missing associated documentation comment in .proto file # missing associated documentation comment in .proto file
pass pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!') context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!') raise NotImplementedError('Method not implemented!')
def SetSteering(self, request_iterator, context): def SetSteering(self, request, context):
# missing associated documentation comment in .proto file # missing associated documentation comment in .proto file
pass pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED) context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@@ -47,12 +47,12 @@ class CarControlServicer(object):
def add_CarControlServicer_to_server(servicer, server): def add_CarControlServicer_to_server(servicer, server):
rpc_method_handlers = { rpc_method_handlers = {
'SetThrottle': grpc.stream_unary_rpc_method_handler( 'SetThrottle': grpc.unary_unary_rpc_method_handler(
servicer.SetThrottle, servicer.SetThrottle,
request_deserializer=motorService__pb2.ThrottleRequest.FromString, request_deserializer=motorService__pb2.ThrottleRequest.FromString,
response_serializer=motorService__pb2.ThrottleResponse.SerializeToString, response_serializer=motorService__pb2.ThrottleResponse.SerializeToString,
), ),
'SetSteering': grpc.stream_unary_rpc_method_handler( 'SetSteering': grpc.unary_unary_rpc_method_handler(
servicer.SetSteering, servicer.SetSteering,
request_deserializer=motorService__pb2.SteeringRequest.FromString, request_deserializer=motorService__pb2.SteeringRequest.FromString,
response_serializer=motorService__pb2.SteeringResponse.SerializeToString, response_serializer=motorService__pb2.SteeringResponse.SerializeToString,

View File

@@ -19,6 +19,6 @@ message SteeringResponse{
} }
service CarControl{ service CarControl{
rpc SetThrottle(stream ThrottleRequest) returns (ThrottleResponse){} rpc SetThrottle(ThrottleRequest) returns (ThrottleResponse){}
rpc SetSteering(stream SteeringRequest) returns (SteeringResponse){} rpc SetSteering(SteeringRequest) returns (SteeringResponse){}
} }