Skip to content

Commit

Permalink
stats: accumulated: Add last mavlink message
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric authored and joaoantoniocardoso committed Sep 19, 2024
1 parent ae6e8b3 commit 2a0e166
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/stats/accumulated/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::protocol::Protocol;

#[derive(Clone, Debug)]
pub struct AccumulatedStatsInner {
pub last_message: Option<Arc<Protocol>>,
pub last_update_us: u64,
pub messages: u64,
pub bytes: u64,
Expand All @@ -16,6 +17,7 @@ pub struct AccumulatedStatsInner {
impl Default for AccumulatedStatsInner {
fn default() -> Self {
Self {
last_message: None,
last_update_us: chrono::Utc::now().timestamp_micros() as u64,
messages: 0,
bytes: 0,
Expand All @@ -26,6 +28,7 @@ impl Default for AccumulatedStatsInner {

impl AccumulatedStatsInner {
pub fn update(&mut self, message: &Arc<Protocol>) {
self.last_message = Some(message.clone());
self.last_update_us = chrono::Utc::now().timestamp_micros() as u64;
self.bytes = self.bytes.wrapping_add(message.raw_bytes().len() as u64);
self.messages = self.messages.wrapping_add(1);
Expand Down

0 comments on commit 2a0e166

Please sign in to comment.