package com.hawhamburg.micr0bu import com.hawhamburg.micr0bu.domain.asn1.VamContent import com.hawhamburg.micr0bu.domain.asn1.VamUperCodec import org.junit.Assert.assertEquals import org.junit.Test /** * Pins the VAM encoder against bytes this code did not produce. * * ## Where the expected bytes come from * asn1tools 0.167, compiling the ETSI modules vanetza-idf ships (asn1/release2: * 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 * 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. */ class VamUperCodecTest { private fun ByteArray.hex(): String = joinToString("") { "%02x".format(it) } private fun content(includeLowFrequency: Boolean, accuracyM: Float? = 3.0f) = VamContent( stationId = 0x12345678, timestamp = 1_790_170_000_123L, latitude = 53.5546667, longitude = 10.0223889, accuracyM = accuracyM, speedMps = 5.43, headingDeg = 123.4, accelerationMps2 = -1.26, includeLowFrequency = includeLowFrequency, ) @Test fun `VAM with the low-frequency container matches asn1tools`() { assertEquals( "031012345678b2fb400aac85a15b8a18ec88f30f3708eddd0f8002697e087ff24f322220", VamUperCodec.encode(content(includeLowFrequency = true)).hex(), ) } @Test fun `VAM without the low-frequency container matches asn1tools`() { assertEquals( "031012345678b2fb000aac85a15b8a18ec88f30f3708eddd0f8002697e087ff24f30", VamUperCodec.encode(content(includeLowFrequency = false)).hex(), ) } @Test fun `unknown accuracy encodes the confidence ellipse as unavailable`() { assertEquals( "031012345678b2fb000aac85a15b8a18ec8fffffff08eddd0f8002697e087ff24f30", VamUperCodec.encode(content(includeLowFrequency = false, accuracyM = null)).hex(), ) } }