Add grpc initalisation, start adding streaming grpc control

This commit is contained in:
piv
2022-08-07 16:04:07 +09:30
parent d876fcbb2e
commit f48518e88f
5 changed files with 71 additions and 33 deletions

63
car-rs/Cargo.lock generated
View File

@@ -34,9 +34,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.58" version = "1.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" checksum = "c794e162a5eff65c72ef524dfe393eb923c354e350bb78b9c7383df13f3bc142"
[[package]] [[package]]
name = "async-stream" name = "async-stream"
@@ -61,9 +61,9 @@ dependencies = [
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.56" version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -133,14 +133,16 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.2.0" version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
[[package]] [[package]]
name = "car-rs" name = "car-rs"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"futures-core",
"futures-util",
"prost", "prost",
"rppal", "rppal",
"serialport", "serialport",
@@ -197,6 +199,17 @@ version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]]
name = "futures-macro"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "futures-sink" name = "futures-sink"
version = "0.3.21" version = "0.3.21"
@@ -216,9 +229,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-macro",
"futures-task", "futures-task",
"pin-project-lite", "pin-project-lite",
"pin-utils", "pin-utils",
"slab",
] ]
[[package]] [[package]]
@@ -378,9 +393,9 @@ dependencies = [
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.2" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
@@ -390,9 +405,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.126" version = "0.2.127"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b"
[[package]] [[package]]
name = "libudev" name = "libudev"
@@ -609,9 +624,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.40" version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -671,9 +686,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.20" version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@@ -710,9 +725,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.15" version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@@ -761,9 +776,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.140" version = "1.0.142"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" checksum = "e590c437916fb6b221e1d00df6e3294f3fccd70ca7e92541c475d6ed6ef5fee2"
[[package]] [[package]]
name = "serialport" name = "serialport"
@@ -818,9 +833,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.98" version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -849,9 +864,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.20.0" version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57aec3cfa4c296db7255446efb4928a6be304b431a806216105542a67b6ca82e" checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"bytes", "bytes",
@@ -1061,9 +1076,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.2" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
[[package]] [[package]]
name = "want" name = "want"

View File

@@ -8,6 +8,8 @@ edition = "2021"
[dependencies] [dependencies]
# https://github.com/golemparts/rppal # https://github.com/golemparts/rppal
rppal = { version = "0.13.1", optional = true } rppal = { version = "0.13.1", optional = true }
futures-core = "0.3"
futures-util = "0.3"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
prost = "0.11" prost = "0.11"
@@ -17,12 +19,8 @@ tonic = "0.8.0"
# https://docs.rs/serialport/4.0.1/serialport/index.html # https://docs.rs/serialport/4.0.1/serialport/index.html
serialport = "4.0.1" serialport = "4.0.1"
[build]
target = "armv7-unknown-linux-gnueabihf"
[build-dependencies] [build-dependencies]
tonic-build = "0.8.0" tonic-build = "0.8.0"
[features] [features]
rppal = ["dep:rppal"] rppal = ["dep:rppal"]

View File

@@ -2,16 +2,21 @@ pub mod motor_control_service {
tonic::include_proto!("motor_control"); tonic::include_proto!("motor_control");
} }
use std::sync::{Arc, Mutex};
use car_rs::{Servo, Vehicle};
use motor_control_service::car_control_server::CarControl; use motor_control_service::car_control_server::CarControl;
use tonic::{Request, Response, Status, Streaming}; use tonic::{Request, Response, Status, Streaming};
use futures_util::StreamExt;
use self::motor_control_service::{ use self::motor_control_service::{
RecordingReqeust, RecordingResponse, SaveRequest, SaveResponse, SteeringRequest, RecordingReqeust, RecordingResponse, SaveRequest, SaveResponse, SteeringRequest,
SteeringResponse, ThrottleRequest, ThrottleResponse, Vehicle2DRequest, Vehicle2DResponse, SteeringResponse, ThrottleRequest, ThrottleResponse, Vehicle2DRequest, Vehicle2DResponse,
}; };
#[derive(Debug)] #[derive(Debug)]
struct MotorControlService {} pub struct MotorControlService {}
#[tonic::async_trait] #[tonic::async_trait]
impl CarControl for MotorControlService { impl CarControl for MotorControlService {
@@ -31,8 +36,16 @@ impl CarControl for MotorControlService {
async fn stream_vehicle_2d( async fn stream_vehicle_2d(
&self, &self,
_request: Request<Streaming<Vehicle2DRequest>>, request: Request<Streaming<Vehicle2DRequest>>,
) -> Result<Response<Vehicle2DResponse>, Status> { ) -> Result<Response<Vehicle2DResponse>, Status> {
let mut stream = request.into_inner();
let mut timed_out = false;
while let Some(req) = stream.next().await {
if !timed_out {}
timed_out = true;
}
unimplemented!() unimplemented!()
} }

View File

@@ -10,7 +10,7 @@ pub trait Servo {
fn set_frequency(&self, frequency: f64); fn set_frequency(&self, frequency: f64);
} }
pub trait Vechicle<T: Servo> { pub trait Vehicle<T: Servo> {
fn get_throttle_servo() -> T; fn get_throttle_servo() -> T;
fn get_steering_servo() -> T; fn get_steering_servo() -> T;
} }

View File

@@ -1,6 +1,18 @@
use crate::grpcserver::motor_control_service; use grpcserver::{
motor_control_service::car_control_server::CarControlServer, MotorControlService,
};
use tonic::transport::Server;
mod grpcserver; mod grpcserver;
#[tokio::main] #[tokio::main]
async fn main() {} async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr = "[::1]:10000".parse().unwrap();
let motor_control = MotorControlService {};
let svc = CarControlServer::new(motor_control);
Server::builder().add_service(svc).serve(addr).await?;
Ok(())
}