configurable poll_rate
This commit is contained in:
@@ -3,6 +3,7 @@ server = "127.0.0.1:5002"
|
||||
|
||||
[grpc]
|
||||
url = "http://127.0.0.1:50051/"
|
||||
poll_rate = 10
|
||||
|
||||
[stt]
|
||||
url = "http://192.168.0.2:3000/"
|
||||
@@ -11,8 +12,3 @@ url = "http://192.168.0.2:3000/"
|
||||
frequency = 251250000
|
||||
modulation = "Am"
|
||||
voice = "David"
|
||||
|
||||
[channels.Magic1-1]
|
||||
frequency = 266000000
|
||||
modulation = "Am"
|
||||
voice = "Zira"
|
||||
|
||||
@@ -15,12 +15,16 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct GrpcBaseUrl {
|
||||
#[serde(skip)]
|
||||
hash: u64,
|
||||
/// The URL of the DCS-gRPC Server
|
||||
url: Cow<'static, str>,
|
||||
/// The poll rate for updating the mission situation in secononds.
|
||||
/// Lower values might cause noticeable ingame lag spikes
|
||||
poll_rate: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for GrpcBaseUrl {
|
||||
fn default() -> Self {
|
||||
GrpcBaseUrl::new("http://127.0.0.1:50051/")
|
||||
GrpcBaseUrl::new("http://127.0.0.1:50051/", Some(10))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +32,13 @@ impl GrpcBaseUrl {
|
||||
/// Creates a new [`GrpcBaseUrl`] from any string-like type.
|
||||
///
|
||||
/// The internal hash will be computed immediately.
|
||||
pub fn new(url: impl Into<Cow<'static, str>>) -> Self {
|
||||
pub fn new(url: impl Into<Cow<'static, str>>, poll_rate: Option<u32>) -> Self {
|
||||
let url = url.into();
|
||||
let mut url = GrpcBaseUrl { url, hash: 0 };
|
||||
let mut url = GrpcBaseUrl {
|
||||
url,
|
||||
hash: 0,
|
||||
poll_rate,
|
||||
};
|
||||
url.update_hash();
|
||||
url
|
||||
}
|
||||
@@ -40,7 +48,7 @@ impl GrpcBaseUrl {
|
||||
/// The internal hash will be re-computed.
|
||||
#[inline(always)]
|
||||
pub fn set(&mut self, url: impl Into<Cow<'static, str>>) {
|
||||
*self = GrpcBaseUrl::new(url);
|
||||
*self = GrpcBaseUrl::new(url, self.poll_rate);
|
||||
}
|
||||
|
||||
/// Updates the url of the entity in place.
|
||||
@@ -59,6 +67,11 @@ impl GrpcBaseUrl {
|
||||
&self.url
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn poll_rate(&self) -> Option<u32> {
|
||||
self.poll_rate
|
||||
}
|
||||
|
||||
fn update_hash(&mut self) {
|
||||
let mut hasher = AHasher::default();
|
||||
self.url.hash(&mut hasher);
|
||||
|
||||
@@ -4,7 +4,10 @@ use bevy::ecs::system::Resource;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Resource, Clone, Deserialize, Serialize)]
|
||||
pub struct SrsSocketAddr(SocketAddr);
|
||||
pub struct SrsSocketAddr(
|
||||
/// The server details for DCS-SRS
|
||||
SocketAddr,
|
||||
);
|
||||
|
||||
impl Default for SrsSocketAddr {
|
||||
fn default() -> Self {
|
||||
|
||||
@@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize};
|
||||
pub struct SttBaseUrl {
|
||||
#[serde(skip)]
|
||||
hash: u64,
|
||||
/// The url to the [whisper-web](https://git.avii.nl/Guardian/whisper-web) instance
|
||||
url: Cow<'static, str>,
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,9 @@ fn connect_to_grpc(mut commands: Commands, tokio: Res<TokioResource>, url: Res<G
|
||||
|
||||
let (tx, task) = unbounded();
|
||||
|
||||
let poll_rate = url.poll_rate();
|
||||
let url = url.to_string();
|
||||
|
||||
handle.spawn(async move {
|
||||
loop {
|
||||
let Ok(mut client) = MissionServiceClient::connect(url.clone()).await else {
|
||||
@@ -61,7 +63,7 @@ fn connect_to_grpc(mut commands: Commands, tokio: Res<TokioResource>, url: Res<G
|
||||
|
||||
let Ok(mut stream) = client
|
||||
.stream_units(StreamUnitsRequest {
|
||||
poll_rate: Some(10),
|
||||
poll_rate,
|
||||
max_backoff: Some(30),
|
||||
category: Airplane as i32,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user