fix(go): flatten jt808 additional fields
This commit is contained in:
@@ -57,19 +57,14 @@ func TestExtractFramesUnescapesAndParsesLocationWithTotalMileage(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("parsed location missing: %#v", env.Parsed)
|
||||
}
|
||||
additional, ok := location["additional"].([]map[string]any)
|
||||
if !ok || len(additional) == 0 {
|
||||
t.Fatalf("additional fields missing: %#v", location["additional"])
|
||||
if _, ok := location["additional"]; ok {
|
||||
t.Fatalf("additional wrapper should not be exposed: %#v", location["additional"])
|
||||
}
|
||||
if additional[0]["id"] != "0x01" || additional[0]["value_hex"] != "0001900C" {
|
||||
t.Fatalf("unexpected first additional item: %#v", additional[0])
|
||||
if location[envelope.FieldTotalMileageKM] != 10241.2 {
|
||||
t.Fatalf("mileage should be flattened on location: %#v", location)
|
||||
}
|
||||
parsed, ok := additional[0]["parsed"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("mileage parsed field missing: %#v", additional[0])
|
||||
}
|
||||
if parsed["raw_value_tenth_km"] != uint32(102412) || parsed["value"] != 10241.2 {
|
||||
t.Fatalf("unexpected mileage parsed value: %#v", parsed)
|
||||
if _, ok := location["raw_value_tenth_km"]; ok {
|
||||
t.Fatalf("raw mileage helper should not be exposed: %#v", location)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,32 +143,38 @@ func TestParseFrameParsesCommonLocationAdditionalItems(t *testing.T) {
|
||||
}
|
||||
assertFloatField(t, env, envelope.FieldTotalMileageKM, 1.1)
|
||||
|
||||
location := env.Parsed["location"].(map[string]any)
|
||||
additional := location["additional"].([]map[string]any)
|
||||
byID := map[string]map[string]any{}
|
||||
for _, item := range additional {
|
||||
byID[item["id"].(string)] = item["parsed"].(map[string]any)
|
||||
location, ok := env.Parsed["location"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("location missing: %#v", env.Parsed)
|
||||
}
|
||||
if byID["0x01"]["raw_value_tenth_km"] != uint32(11) || byID["0x01"]["value"] != 1.1 {
|
||||
t.Fatalf("mileage parsed = %#v", byID["0x01"])
|
||||
if _, ok := location["additional"]; ok {
|
||||
t.Fatalf("additional wrapper should not be exposed: %#v", location["additional"])
|
||||
}
|
||||
if byID["0x05"]["name"] != "tire_pressure" {
|
||||
t.Fatalf("tire pressure missing: %#v", byID["0x05"])
|
||||
if location[envelope.FieldTotalMileageKM] != 1.1 {
|
||||
t.Fatalf("mileage parsed = %#v", location[envelope.FieldTotalMileageKM])
|
||||
}
|
||||
tireValues := byID["0x05"]["values"].([]map[string]any)
|
||||
tirePressure, ok := location["tire_pressure"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("tire pressure missing: %#v", location["tire_pressure"])
|
||||
}
|
||||
tireValues := tirePressure["values"].([]map[string]any)
|
||||
if tireValues[0]["value"] != byte(0x37) || tireValues[0]["valid"] != true {
|
||||
t.Fatalf("tire pressure first value = %#v", tireValues[0])
|
||||
}
|
||||
if byID["0x11"]["location_type"] != byte(0x42) || byID["0x11"]["area_id"] != uint32(0x42) {
|
||||
t.Fatalf("overspeed parsed = %#v", byID["0x11"])
|
||||
overspeed := location["overspeed_alarm"].(map[string]any)
|
||||
if overspeed["location_type"] != byte(0x42) || overspeed["area_id"] != uint32(0x42) {
|
||||
t.Fatalf("overspeed parsed = %#v", overspeed)
|
||||
}
|
||||
if byID["0x12"]["location_type"] != byte(0x4d) || byID["0x12"]["area_id"] != uint32(0x4d) || byID["0x12"]["direction"] != byte(0x4d) {
|
||||
t.Fatalf("area route parsed = %#v", byID["0x12"])
|
||||
areaRoute := location["area_route_alarm"].(map[string]any)
|
||||
if areaRoute["location_type"] != byte(0x4d) || areaRoute["area_id"] != uint32(0x4d) || areaRoute["direction"] != byte(0x4d) {
|
||||
t.Fatalf("area route parsed = %#v", areaRoute)
|
||||
}
|
||||
if byID["0x13"]["road_section_id"] != uint32(0x58) || byID["0x13"]["driving_time_seconds"] != uint16(0x58) {
|
||||
t.Fatalf("road section parsed = %#v", byID["0x13"])
|
||||
roadSection := location["road_section_driving_time_alarm"].(map[string]any)
|
||||
if roadSection["road_section_id"] != uint32(0x58) || roadSection["driving_time_seconds"] != uint16(0x58) {
|
||||
t.Fatalf("road section parsed = %#v", roadSection)
|
||||
}
|
||||
ioBits := byID["0x2A"]["bits"].(map[string]bool)
|
||||
ioStatus := location["io_status"].(map[string]any)
|
||||
ioBits := ioStatus["bits"].(map[string]bool)
|
||||
if ioBits["deep_sleep"] || !ioBits["sleep"] {
|
||||
t.Fatalf("io bits = %#v", ioBits)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user