summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/postrunner/EPO_Downloader.rb23
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