Parse the CiT One's real obu_gnss and processed CAM payloads

Both JSON parsers returned null for every real CiT One message, checked
against the logged runs:

- ObuGnssParser read everything from own_info, but obu_gnss keeps the
  position, speed, heading and acceleration under gnss (as its API document
  shows). So on the CiT One the ego state never came from obu_gnss, the own
  station ID was never learned from it, and the V2X logger wrote no OBU
  fixes. Kinematics now come from gnss and identity, yaw rate and vehicle
  size from own_info. The documented no-fix (91/181) and invalid-speed
  (163.82) markers are rejected.
- CamParser only took stationType as a number, but the CAM topic sends the
  name ("passengerCar"), so the processed CAM fallback was dead. Names are
  now mapped too, and the vehicle size is read from vehicleLength_m and
  vehicleWidth_m, the keys actually sent.

The name table moves from DenmEvent into StationType.fromApiName so the
DENM and CAM parsers share one copy. The tests use payloads with the keys,
nesting and types of the logged ones.
This commit is contained in:
Ashin Walpola
2026-11-18 14:56:26 +01:00
parent 6fa91d1702
commit 275d382a1d
6 changed files with 162 additions and 19 deletions
@@ -0,0 +1,110 @@
package com.hawhamburg.micr0bu
import com.hawhamburg.micr0bu.domain.cam.CamParser
import com.hawhamburg.micr0bu.domain.cam.ObuGnssParser
import com.hawhamburg.micr0bu.domain.cam.StationType
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* The two CiT One JSON parsers against payloads shaped exactly like the ones the CiT One really
* sends (keys, nesting and types copied from the logged runs, values changed). Both parsers used to
* return null for every one of them: `obu_gnss` keeps its position under `gnss`, not `own_info`,
* and the CAM topic sends `stationType` as a name.
*/
class CitOneJsonParsersTest {
private val obuGnss = """
{ "type": "v2xgw-owninfo", "obu_timestamp_sec": 1773834329.0660601,
"gnss": { "latitude": 53.5551, "longitude": 10.0222, "altitude_m": 60.5, "speed_mps": 5.25,
"time_utc": "2026-03-18T11:45:29Z", "heading_deg": 87.5, "acceleration_mpss": -0.25,
"curvature": { "radiusOfCurve_m": 3276.0, "confidence": 100.0 },
"positionError_stdDev": { "posErrSemiMajorAxisLen_m": 0.446, "posErrSemiMinorAxisLen_m": 0.446,
"posErrSemiMajorAxisOrientation_deg": 0.0, "altitudeErr_m": 0.609, "headingErr_deg": 361.0,
"groundSpeedErr_mps": 0.077, "verticalSpeedErr_mps": -1.0, "DOP": -4.45e-25 },
"satInfo": { "fix": "3d", "numSatUsed": 14,
"numSatVisible": { "gps": 0, "gbas": 0, "sbas": 0, "gnss": 0 } } },
"own_info": { "stationID": 319450879, "stationType": 5, "vehicleRole": 0, "vehicleWidth_m": 1.8,
"vehicleLength_m": 4.26, "yawRate_degps": 6.5, "isBreaking": false },
"pathHistory": { "refLatitude": 53.5551, "refLongitude": 10.0222, "refAltitude": 60.5,
"pathPoints": [ { "deltaLatitude": -3.5e-06, "deltaLongitude": 1.31e-05,
"deltaAltitude_m": -5.0, "pathDeltaTime_ms": 834 } ] } }
""".trimIndent()
private val processedCam = """
{"heading_deg":1.2,"pathHistory":{"path":{"coordinates":[[10.0258218,53.5526996,52.6],
[10.0258295,53.5524988,51.6]],"type":"LineString"}},"position":{"coordinates":[10.0258076,53.5528397,52.6],
"type":"Point"},"positionError_stdDev":{"altitudeErr_m":10.0,"groundSpeedErr_mps":0.105,"headingErr_deg":0.5,
"posErrSemiMajorAxisLen_m":1.57,"posErrSemiMajorAxisOrientation_deg":5.4,"posErrSemiMinorAxisLen_m":1.56},
"speed_mps":7.25,"stationId":3124041003,"stationType":"passengerCar","type":"v2x-cam",
"vehicleLength_m":4.9,"vehicleRole":"default","vehicleWidth_m":1.8,"yawRate_dps":-1.43}
""".trimIndent()
@Test
fun `obu_gnss - kinematics from gnss, identity and yaw rate from own_info`() {
val ego = ObuGnssParser.parseEgo(obuGnss, timestamp = 1_000L)!!
assertEquals(319450879L, ego.stationId)
assertEquals(StationType.PASSENGER_CAR, ego.stationType)
assertEquals(53.5551, ego.latitude, 1e-9)
assertEquals(10.0222, ego.longitude, 1e-9)
assertEquals(5.25, ego.speedMps, 1e-9)
assertEquals(87.5, ego.headingDeg, 1e-9)
assertEquals(-0.25, ego.accelerationMps2!!, 1e-9)
// Right-positive on this topic in practice, as Cam.yawRateDps is: taken as it is.
assertEquals(6.5, ego.yawRateDps!!, 1e-9)
assertEquals(4.26, ego.vehicleLengthM!!, 1e-9)
assertEquals(1.8, ego.vehicleWidthM!!, 1e-9)
assertTrue(ego.isOwn)
}
@Test
fun `obu_gnss - the no-fix marker is not a position`() {
val noFix = obuGnss.replace("\"latitude\": 53.5551", "\"latitude\": 91.0")
.replace("\"longitude\": 10.0222", "\"longitude\": 181.0")
assertNull(ObuGnssParser.parseEgo(noFix))
}
@Test
fun `obu_gnss - the invalid speed marker reads as no speed`() {
val badSpeed = obuGnss.replace("\"speed_mps\": 5.25", "\"speed_mps\": 163.82")
assertEquals(0.0, ObuGnssParser.parseEgo(badSpeed)!!.speedMps, 0.0)
}
@Test
fun `CAM topic - station type name, vehicle size and a left-positive yaw rate`() {
val cam = CamParser.parse(processedCam, ownStationId = null)!!
assertEquals(3124041003L, cam.stationId)
assertEquals(StationType.PASSENGER_CAR, cam.stationType)
assertEquals(53.5528397, cam.latitude, 1e-9)
assertEquals(10.0258076, cam.longitude, 1e-9)
assertEquals(7.25, cam.speedMps, 1e-9)
assertEquals(1.2, cam.headingDeg, 1e-9)
// -1.43 on this left-positive topic is 1.43 deg/s to the right: +1.43 in Cam.yawRateDps.
assertEquals(1.43, cam.yawRateDps!!, 1e-9)
assertEquals(4.9, cam.vehicleLengthM!!, 1e-9)
assertEquals(1.8, cam.vehicleWidthM!!, 1e-9)
assertFalse(cam.isOwn)
}
@Test
fun `CAM topic - own CAM recognised by the station id learned from obu_gnss`() {
assertTrue(CamParser.parse(processedCam, ownStationId = 3124041003L)!!.isOwn)
}
@Test
fun `CAM topic - an unknown station type name is still rejected`() {
assertNull(CamParser.parse(processedCam.replace("passengerCar", "spaceship"), ownStationId = null))
}
@Test
fun `station type names map by name, with the gap before roadSideUnit`() {
assertEquals(2, StationType.fromApiName("cyclist"))
assertEquals(11, StationType.fromApiName("tram"))
assertEquals(15, StationType.fromApiName("roadSideUnit"))
assertNull(StationType.fromApiName(""))
assertNull(StationType.fromApiName(null))
}
}