Skip to content

Commit

Permalink
nano negative
Browse files Browse the repository at this point in the history
  • Loading branch information
gauteh committed Oct 22, 2024
1 parent 5c4be73 commit fccd12e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sfy-buoy/sfy-ext-gps/ext-gps-mod/gps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct)
uint8_t hour = ubxDataStruct->hour;
uint8_t minute = ubxDataStruct->min;
uint8_t sec = ubxDataStruct->sec;
uint32_t nano = ubxDataStruct->nano;
int32_t nano = ubxDataStruct->nano;

String datetime = String(year) + "-" + String(month) + "-" + String(day) + ":" + String(hour) + ":" + String(minute) + ":" + String(sec) + "." + String(nano);
Serial.print(F("Time: "));
Expand Down
16 changes: 13 additions & 3 deletions sfy-buoy/src/gps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Sample {
hour: u8,
minute: u8,
sec: u8,
nano: u32,
nano: i32,

time_acc: u32, // ns

Expand All @@ -49,13 +49,23 @@ pub struct Sample {

impl Sample {
pub fn timestamp(&self) -> NaiveDateTime {
let mut sec = self.sec;
let mut nano = self.nano;

if nano < 0 {
sec -= 1;
nano = 1_000_000_000 + nano;
}

let nano = nano as u32;

NaiveDate::from_ymd_opt(self.year.into(), self.month.into(), self.day.into())
.unwrap()
.and_hms_nano(
self.hour.into(),
self.minute.into(),
self.sec.into(),
self.nano.into(),
sec.into(),
nano.into(),
)
}
}
Expand Down

0 comments on commit fccd12e

Please sign in to comment.