diff options
author | Chris Schlaeger <chris@linux.com> | 2015-05-10 22:51:25 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2015-05-10 22:51:25 +0200 |
commit | 4e9a7e11c192f32bc55c9007ebda6d672bec6f7a (patch) | |
tree | cb7781cbad02881b8976b44a380ab5372a881dad /lib | |
parent | 7494e2ec33a484c0bb8c9d8ca7b17cea8ed9c90c (diff) | |
download | postrunner-4e9a7e11c192f32bc55c9007ebda6d672bec6f7a.zip |
Fixing the baseline date for EPO files.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/postrunner/EPO_Downloader.rb | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/postrunner/EPO_Downloader.rb b/lib/postrunner/EPO_Downloader.rb index 0aa3fd9..26e6e0d 100644 --- a/lib/postrunner/EPO_Downloader.rb +++ b/lib/postrunner/EPO_Downloader.rb @@ -99,9 +99,9 @@ module PostRunner Log.error "EPO file has wrong length (#{epo.length})" return false end - date_1980_01_01 = Time.parse("1980-01-01T00:00:00+00:00") + date_1980_01_06 = Time.parse("1980-01-06T00:00:00+00:00") now = Time.now - largest_date = nil + end_date = start_date = nil # Split the EPO data into Arrays of 32 * 72 bytes. epo.each_slice(32 * 72).to_a.each do |epo_set| # For each of the 32 satellites we have 72 bytes of data. @@ -114,22 +114,21 @@ module PostRunner return false end # The first 3 bytes of every satellite record look like a timestamp. - # I assume they are hours after January 1st, 1980 UTC. They probably + # I assume they are hours after January 6th, 1980 UTC. They probably # indicate the start of the 6 hour window that the data is for. - hours_after_1980_01_01 = sat[0] | (sat[1] << 8) | (sat[2] << 16) - date = date_1980_01_01 + hours_after_1980_01_01 * 60 * 60 - # Either the start point (1980-01-01) is not correct or Garmin is - # publishing data that can be up to 5 days old. We check the date - # with some more relaxed ranges. + hours_after_1980_01_06 = sat[0] | (sat[1] << 8) | (sat[2] << 16) + date = date_1980_01_06 + hours_after_1980_01_06 * 60 * 60 if date > now + 8 * 24 * 60 * 60 - Log.warn "EPO timestamp (#{date}) is in the future" - elsif date < now - 8 * 24 * 60 * 60 + Log.warn "EPO timestamp (#{date}) is too far in the future" + elsif date < now - 24 * 60 * 60 Log.warn "EPO timestamp (#{date}) is too old" end - largest_date = date if largest_date.nil? || date > largest_date + start_date = date if start_date.nil? || date < start_date + end_date = date if end_date.nil? || date > end_date end end - Log.info "EPO data is valid until #{largest_date + 6 * 60 * 60}." + Log.info "EPO data is valid from #{start_date} to " + + "#{end_date + 6 * 60 * 60}." true end |