Skip to content

Commit

Permalink
broker: get fop state
Browse files Browse the repository at this point in the history
  • Loading branch information
kobkaz committed Nov 20, 2024
1 parent 87e7d97 commit b1aa156
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
14 changes: 14 additions & 0 deletions gaia-stub/proto/broker.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ service Broker {
rpc PostUnlock(PostUnlockRequest) returns (PostUnlockResponse);
rpc PostADCommand(PostADCommandRequest) returns (PostADCommandResponse);
rpc SubscribeFopFrameEvents(SubscribeFopFrameEventsRequest) returns (stream FopFrameEvent);
rpc GetFopState(GetFopStateRequest) returns (GetFopStateResponse);
}

message PostCommandRequest {
Expand Down Expand Up @@ -91,3 +92,16 @@ message FopFrameEvent {
};
EventType event_type = 2;
}

message GetFopStateRequest {}

message GetFopStateResponse {
bool received_clcw = 1;
bool lockout_flag = 2;
bool wait_flag = 3;
bool retransmit_flag = 4;
uint32 next_expected_sequence_number = 5;

bool has_next_sequence_number = 11;
uint32 next_sequence_number = 12;
}
44 changes: 44 additions & 0 deletions gaia-tmtc/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ pub enum FopFrameEvent {
Cancel(u64),
}

#[derive(Default)]
pub struct ClcwInfo {
pub lockout: bool,
pub wait: bool,
pub retransmit: bool,
pub next_expected_fsn: u8,
}

pub struct FopState {
pub last_clcw: Option<ClcwInfo>,
pub next_fsn: Option<u8>,
}

#[async_trait]
pub trait FopCommandService {
async fn send_set_vr(&mut self, value: u8);
Expand All @@ -54,6 +67,8 @@ pub trait FopCommandService {
async fn subscribe_frame_events(
&mut self,
) -> Result<Pin<Box<dyn Stream<Item = FopFrameEvent> + Send>>>;

async fn get_fop_state(&mut self) -> Result<FopState>;
}

#[tonic::async_trait]
Expand Down Expand Up @@ -225,4 +240,33 @@ where
});
Ok(Response::new(stream.boxed()))
}

#[tracing::instrument(skip(self))]
async fn get_fop_state(
&self,
_request: tonic::Request<GetFopStateRequest>,
) -> Result<tonic::Response<GetFopStateResponse>, tonic::Status> {
let state = self
.fop_command_service
.lock()
.await
.get_fop_state()
.await
.map_err(|_| Status::internal("failed to get fop state"))?;
let received_clcw = state.last_clcw.is_some();
let clcw = state.last_clcw.unwrap_or_default();

let resp = GetFopStateResponse {
received_clcw,
lockout_flag: clcw.lockout,
wait_flag: clcw.wait,
retransmit_flag: clcw.retransmit,
next_expected_sequence_number: clcw.next_expected_fsn as _,

has_next_sequence_number: state.next_fsn.is_some(),
next_sequence_number: state.next_fsn.unwrap_or_default() as _,
};

Ok(Response::new(resp))
}
}
24 changes: 18 additions & 6 deletions tmtc-c2a/src/fop1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ fn remove_acknowledged_frames(
}

#[derive(Clone, Copy)]
struct FarmState {
next_expected_fsn: u8,
lockout: bool,
_wait: bool,
retransmit: bool,
pub(crate) struct FarmState {
pub(crate) next_expected_fsn: u8,
pub(crate) lockout: bool,
pub(crate) wait: bool,
pub(crate) retransmit: bool,
}

enum FopState {
Expand Down Expand Up @@ -182,6 +182,18 @@ impl Fop {
}
}

pub(crate) fn last_received_farm_state(&self) -> Option<&FarmState> {
self.last_received_farm_state.as_ref()
}

pub(crate) fn next_fsn(&self) -> Option<u8> {
match &self.state {
FopState::Initial { expected_nr } => *expected_nr,
FopState::Active(state) => Some(state.next_fsn),
FopState::Retransmit(state) => Some(state.next_fsn),
}
}

pub(crate) fn subscribe_frame_events(&self) -> broadcast::Receiver<FrameEvent> {
self.event_sender.subscribe()
}
Expand All @@ -191,7 +203,7 @@ impl Fop {
let farm_state = FarmState {
next_expected_fsn: clcw.report_value(),
lockout: clcw.lockout() != 0,
_wait: clcw.wait() != 0,
wait: clcw.wait() != 0,
retransmit: clcw.retransmit() != 0,
};
self.last_received_farm_state = Some(farm_state);
Expand Down
17 changes: 17 additions & 0 deletions tmtc-c2a/src/satellite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,21 @@ impl<T: tc::SyncAndChannelCoding + Send> gaia_tmtc::broker::FopCommandService
});
Ok(stream.boxed())
}

async fn get_fop_state(&mut self) -> Result<gaia_tmtc::broker::FopState> {
let fop = self.fop.lock().await;
let last_clcw = fop
.last_received_farm_state()
.map(|s| gaia_tmtc::broker::ClcwInfo {
lockout: s.lockout,
wait: s.wait,
retransmit: s.retransmit,
next_expected_fsn: s.next_expected_fsn as _,
});
let next_fsn = fop.next_fsn();
Ok(gaia_tmtc::broker::FopState {
last_clcw,
next_fsn,
})
}
}

0 comments on commit b1aa156

Please sign in to comment.