Merge branch 'dev/its-time-tai' into 'main'
Count ITS time in TAI, with the leap seconds since 2004 See merge request urban-mobility-lab/microbu/microbuapp!2
This commit is contained in:
@@ -31,9 +31,12 @@ class CamEncodeGoldenTest {
|
||||
/**
|
||||
* asn1tools-verified encoding of [referenceCam]. The trap this pins down: `YawRateConfidence`
|
||||
* has nine enumerands (0..8), so it needs 4 bits and `unavailable` is 8 - not 3 bits and 7.
|
||||
* generationDeltaTime 19080 is TimestampIts mod 65536 with the 5 leap seconds since 2004 (TAI,
|
||||
* TS 102 894-2 V2.5.1); regenerated 2026-10 through asn1tools from the earlier UTC-based vector
|
||||
* (14080), every other bit unchanged.
|
||||
*/
|
||||
private val expectedHex =
|
||||
"0202000f423f3700402ab215af6e286477dffffffc23b7743e0027ffc0d0fe0118329337feebfff6000000"
|
||||
"0202000f423f4a88402ab215af6e286477dffffffc23b7743e0027ffc0d0fe0118329337feebfff6000000"
|
||||
|
||||
private val referenceCam = Cam(
|
||||
stationId = 999_999L,
|
||||
|
||||
@@ -104,7 +104,7 @@ class CamTxPvSerialTest {
|
||||
assertTrue(pv.pai)
|
||||
// The GN TST and the CAM's generationDeltaTime must follow one time rule.
|
||||
assertEquals(ItsTime.timestampIts(cam.timestamp), pv.tstMs)
|
||||
assertEquals(716_121_572_779L, pv.tstMs)
|
||||
assertEquals(716_121_577_779L, pv.tstMs) // TAI: Unix ms - ITS epoch + 5 leap seconds
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -145,7 +145,7 @@ class DenmAirReceiveTest {
|
||||
// detectionTime is a 42-bit TimestampIts counted from the 2004 ITS epoch. Getting either
|
||||
// the width or the epoch wrong lands the hazard decades away, so the absolute value is
|
||||
// asserted rather than a range.
|
||||
assertEquals(1_786_979_460_563L, denm.detectionTimeMs)
|
||||
assertEquals(1_786_979_455_563L, denm.detectionTimeMs) // TimestampIts is TAI: 5 leap seconds less in UTC
|
||||
|
||||
// Carried through from the GeoNetworking header and the serial prefix, not the payload.
|
||||
assertEquals(1000, denm.relevanceRadiusM)
|
||||
@@ -164,7 +164,7 @@ class DenmAirReceiveTest {
|
||||
assertNull("a terminating DENM carries no SituationContainer", termDenm.causeCode)
|
||||
assertEquals(4_194_380_752L, termDenm.stationId)
|
||||
assertEquals(6, termDenm.sequenceNumber)
|
||||
assertEquals(1_786_980_053_703L, termDenm.detectionTimeMs)
|
||||
assertEquals(1_786_980_048_703L, termDenm.detectionTimeMs)
|
||||
|
||||
// The whole point of keying dedup on actionID: the termination must land on the same key as
|
||||
// the event it ends, so filtering terminations actually removes that hazard from the map
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.hawhamburg.micr0bu
|
||||
|
||||
import com.hawhamburg.micr0bu.domain.asn1.CamUperCodec
|
||||
import com.hawhamburg.micr0bu.domain.asn1.ItsTime
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.time.Instant
|
||||
|
||||
/**
|
||||
* TimestampIts is TAI-based (ETSI TS 102 894-2 V2.5.1): it runs ahead of UTC by the leap seconds
|
||||
* inserted since the ITS epoch. Values from the standard's own example and the IANA leap-seconds.list.
|
||||
*/
|
||||
class ItsTimeLeapSecondTest {
|
||||
|
||||
private fun utc(text: String) = Instant.parse(text).toEpochMilli()
|
||||
|
||||
@Test
|
||||
fun `the ITS epoch is zero`() {
|
||||
assertEquals(0L, ItsTime.timestampIts(utc("2004-01-01T00:00:00Z")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the standard's example 2007-01-01 includes one leap second`() {
|
||||
assertEquals(94_694_401_000L, ItsTime.timestampIts(utc("2007-01-01T00:00:00Z")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `today TimestampIts is 5 s ahead of Unix time minus the epoch`() {
|
||||
val now = utc("2026-10-02T16:00:00Z")
|
||||
assertEquals(now - ItsTime.EPOCH_MS + 5_000L, ItsTime.timestampIts(now))
|
||||
// the value the micrOBU station-link reference (vbs.py its_timestamp_ms) produces for the same instant
|
||||
assertEquals(718_041_605_000L, ItsTime.timestampIts(now))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the leap second of 2017 counts from 2017-01-01 on`() {
|
||||
assertEquals(4, ItsTime.leapSecondsAt(utc("2016-12-31T23:59:59.999Z")))
|
||||
assertEquals(5, ItsTime.leapSecondsAt(utc("2017-01-01T00:00:00Z")))
|
||||
// the inserted second 23:59:60 lies between: two UTC instants 1 ms apart are 1001 ms apart in TAI
|
||||
assertEquals(1_001L, ItsTime.timestampIts(utc("2017-01-01T00:00:00Z")) -
|
||||
ItsTime.timestampIts(utc("2016-12-31T23:59:59.999Z")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `back to UTC is the inverse, also across every leap second`() {
|
||||
for (t in listOf("2004-01-01T00:00:00Z", "2005-12-31T23:59:59.999Z", "2006-01-01T00:00:00Z",
|
||||
"2012-06-30T23:59:59.500Z", "2012-07-01T00:00:00.001Z", "2017-01-01T00:00:00Z", "2026-10-02T16:00:00.123Z")) {
|
||||
assertEquals(t, utc(t), ItsTime.epochMs(ItsTime.timestampIts(utc(t))))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a TimestampIts inside an inserted leap second maps to the end of it`() {
|
||||
val its = ItsTime.timestampIts(utc("2017-01-01T00:00:00Z")) - 400L // 2016-12-31T23:59:60.600
|
||||
assertEquals(utc("2017-01-01T00:00:00Z"), ItsTime.epochMs(its))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `generationDeltaTime follows TimestampIts`() {
|
||||
val now = utc("2026-10-02T16:00:00Z")
|
||||
assertEquals(Math.floorMod(718_041_605_000L, 65_536L).toInt(), CamUperCodec.generationDeltaTime(now))
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,9 @@ import org.junit.Test
|
||||
* TS102894-2v241-CDD.asn, TS103300-3v231/VAM-PDU-Descriptions.asn and its motorcyclist container),
|
||||
* encoding the same values as a Python dict: the same toolchain the colleague's reference VBS
|
||||
* (microbu-esp32c5/station-link/python/microbu_link/vbs.py) builds its VAMs with. Station
|
||||
* 0x12345678, fix at Unix ms 1790170000123 (generationDeltaTime 45819), 53.5546667 N
|
||||
* 0x12345678, fix at Unix ms 1790170000123 (generationDeltaTime 50819: TimestampIts mod 65536 with the
|
||||
* 5 leap seconds since 2004, TAI per TS 102 894-2 V2.5.1; regenerated 2026-10 through asn1tools from the
|
||||
* earlier UTC-based vectors with 45819, every other bit unchanged), 53.5546667 N
|
||||
* 10.0223889 E, 5.43 m/s, heading 123.4 deg, -1.26 m/s^2; every confidence and the altitude
|
||||
* unavailable, as the encoder sends them.
|
||||
*/
|
||||
@@ -36,7 +38,7 @@ class VamUperCodecTest {
|
||||
@Test
|
||||
fun `VAM with the low-frequency container matches asn1tools`() {
|
||||
assertEquals(
|
||||
"031012345678b2fb400aac85a15b8a18ec88f30f3708eddd0f8002697e087ff24f322220",
|
||||
"031012345678c683400aac85a15b8a18ec88f30f3708eddd0f8002697e087ff24f322220",
|
||||
VamUperCodec.encode(content(includeLowFrequency = true)).hex(),
|
||||
)
|
||||
}
|
||||
@@ -44,7 +46,7 @@ class VamUperCodecTest {
|
||||
@Test
|
||||
fun `VAM without the low-frequency container matches asn1tools`() {
|
||||
assertEquals(
|
||||
"031012345678b2fb000aac85a15b8a18ec88f30f3708eddd0f8002697e087ff24f30",
|
||||
"031012345678c683000aac85a15b8a18ec88f30f3708eddd0f8002697e087ff24f30",
|
||||
VamUperCodec.encode(content(includeLowFrequency = false)).hex(),
|
||||
)
|
||||
}
|
||||
@@ -52,7 +54,7 @@ class VamUperCodecTest {
|
||||
@Test
|
||||
fun `unknown accuracy encodes the confidence ellipse as unavailable`() {
|
||||
assertEquals(
|
||||
"031012345678b2fb000aac85a15b8a18ec8fffffff08eddd0f8002697e087ff24f30",
|
||||
"031012345678c683000aac85a15b8a18ec8fffffff08eddd0f8002697e087ff24f30",
|
||||
VamUperCodec.encode(content(includeLowFrequency = false, accuracyM = null)).hex(),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user