Skip to content

Commit

Permalink
Fix date extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Nov 1, 2023
1 parent 38303bf commit 000d2fa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default {
console.log('unable to load trajectory')
}
}
this.state.metadata = { startTime: this.dataExtractor.extractStartTime(this.state.messages.GPS) }
Vue.delete(this.state.messages, 'AHR2')
Vue.delete(this.state.messages, 'POS')
Vue.delete(this.state.messages, 'GPS')
Expand Down
5 changes: 5 additions & 0 deletions src/tools/dataflashDataExtractor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ParamSeeker } from '../tools/paramseeker'
import extractStartTime from './datetools'

window.radians = function (a) {
return 0.0174533 * a
Expand Down Expand Up @@ -452,4 +453,8 @@ export class DataflashDataExtractor {
}
return ret
}

static extractStartTime (messages) {
return extractStartTime(messages)
}
}
31 changes: 31 additions & 0 deletions src/tools/datetools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

function leapSecondsGPS (year, month) {
return leapSecondsTAI(year, month) - 19
}

function leapSecondsTAI (year, month) {
const yyyymm = year * 100 + month
if (yyyymm >= 201701) return 37
if (yyyymm >= 201507) return 36
if (yyyymm >= 201207) return 35
if (yyyymm >= 200901) return 34
if (yyyymm >= 200601) return 33
if (yyyymm >= 199901) return 32
if (yyyymm >= 199707) return 31
if (yyyymm >= 199601) return 30

return 0
}

export default function extractStartTime (msgs) {
for (const i in msgs.time_boot_ms) {
if (msgs.GWk[i] > 1000) { // lousy validation
const weeks = msgs.GWk[i]
const ms = msgs.GMS[i]
let d = new Date((315964800.0 + ((60 * 60 * 24 * 7) * weeks) + ms / 1000.0) * 1000.0)
// adjusting for leap seconds
d = new Date(d.getTime() - leapSecondsGPS(d.getUTCFullYear(), d.getUTCMonth() + 1) * 1000)
return d
}
}
}
4 changes: 4 additions & 0 deletions src/tools/mavlinkDataExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,8 @@ export class MavlinkDataExtractor {
}
return texts
}

static extractStartTime (messages) {
return undefined
}
}

0 comments on commit 000d2fa

Please sign in to comment.