Files
MicrOBU/app/src/test/java/com/hawhamburg/micr0bu/YawRateJsonSignTest.kt
T
Ashin Walpola 6fa91d1702 Send and read the CAM yaw rate with the ETSI sign
YawRateValue is positive to the left (degSec-000-01ToLeft(1), TS 102 894-2),
while Cam.yawRateDps is positive clockwise, to the right, which is what the
use-case engine and its heading-trend fallback assume. CamUperCodec used the
value as it is in both directions, so every CAM this phone sent showed a
standard receiver the opposite turn, and received CAMs were read the wrong
way round in turn detection. It now negates on encode and decode. The
expected bytes for a right turn in CamEncodeGoldenTest come from asn1tools,
not from this encoder.

The CiT One's CAM topic (v2x-uca/output/json/cam) is left-positive too, as
its API document says and as 316 of 316 turning samples in the logged runs
confirm, so CamParser negates as well. Its obu_gnss topic is documented as
left-positive but sends yawRate_degps right-positive in practice (27 of 27
turning windows in the 2026-03-18 bacospat log), so ObuGnssParser keeps the
value and now reads that documented key, which it used to miss.
2026-11-18 14:56:17 +01:00

38 lines
1.6 KiB
Kotlin

package com.hawhamburg.micr0bu
import com.hawhamburg.micr0bu.domain.cam.CamParser
import com.hawhamburg.micr0bu.domain.cam.ObuGnssParser
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
/**
* [com.hawhamburg.micr0bu.domain.cam.Cam.yawRateDps] is positive clockwise. The CiT One's CAM topic
* is positive to the left (documented, and 316 of 316 turning samples in the logged runs), so
* [CamParser] flips it. Its `obu_gnss` topic is documented as left-positive too, but the logs show
* it positive to the right (27 of 27), so [ObuGnssParser] keeps it.
*/
class YawRateJsonSignTest {
@Test
fun `CAM topic - positive is a left turn, so it becomes negative`() {
val json = """{"stationID": 42, "stationType": 5, "latitude": 53.55, "longitude": 10.02,
"yawRate_dps": 15.0}"""
assertEquals(-15.0, CamParser.parse(json, ownStationId = null)!!.yawRateDps!!, 1e-9)
}
@Test
fun `CAM topic - a missing yaw rate stays unavailable`() {
val json = """{"stationID": 42, "stationType": 5, "latitude": 53.55, "longitude": 10.02}"""
assertNull(CamParser.parse(json, ownStationId = null)!!.yawRateDps)
}
@Test
fun `obu_gnss - yawRate_degps is read as it is, since the CiT One sends it right-positive`() {
// own_info as in Listing 2.1, with the position placed where this parser reads it.
val json = """{"own_info": {"stationID": 1345678, "stationType": 2,
"latitude": 53.55, "longitude": 10.02, "yawRate_degps": -7.5}}"""
assertEquals(-7.5, ObuGnssParser.parseEgo(json)!!.yawRateDps!!, 1e-9)
}
}