1
1
mirror of https://github.com/wader/fq.git synced 2024-09-11 20:07:11 +03:00

Fixed subfield referencing fields below self in message

This commit is contained in:
Mikael Lofjärd 2024-02-12 13:41:40 +01:00
parent 8ebe5da6a7
commit f7b067b6ba
2 changed files with 49 additions and 25 deletions

View File

@ -251,7 +251,6 @@ func fieldUint(fieldFn func(string, ...scalar.UintMapper) uint64, expectedSize u
} else {
val = fieldFn(fDef.Name, uintFormatter)
}
valMap[fDef.Name] = valueType{value: val, typ: fDef.Format}
// Save developer field definitions
switch fDef.Name {
@ -316,6 +315,31 @@ func fitDecodeDataMessage(d *decode.D, drc *dataRecordContext, lmfd localFieldDe
isDevDep := isDevMap[drc.localMessageType]
// pre read all integer fields and store them in the value map
// so that they can be referenced by eventual subfields
var val uint64
curPos := d.Pos()
for _, k := range keys {
fDef := lmfd[drc.localMessageType][uint64(k)]
switch fDef.Type {
case "enum", "uint8", "uint8z", "byte":
val = d.U8()
valMap[fDef.Name] = valueType{value: val, typ: fDef.Format}
case "uint16", "uint16z":
val = d.U16()
valMap[fDef.Name] = valueType{value: val, typ: fDef.Format}
case "uint32", "uint32z":
val = d.U32()
valMap[fDef.Name] = valueType{value: val, typ: fDef.Format}
case "uint64", "uint64z":
val = d.U64()
valMap[fDef.Name] = valueType{value: val, typ: fDef.Format}
default:
d.SeekRel(int64(fDef.Size) * 8)
}
}
d.SeekRel(curPos - d.Pos())
for _, k := range keys {
fDef := lmfd[drc.localMessageType][uint64(k)]

View File

@ -474,7 +474,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x01b0| ff ff | .. | UNKNOWN_13: 65535 (invalid) 0x1b6-0x1b8 (2)
0x01b0| 00 00 | .. | ant_device_number: 0 (invalid) 0x1b8-0x1ba (2)
0x01b0| 00 | . | device_index: "creator" (0) 0x1ba-0x1bb (1)
0x01b0| ff | . | device_type: 255 (invalid) 0x1bb-0x1bc (1)
0x01b0| ff | . | local_device_type: 255 (invalid) 0x1bb-0x1bc (1)
0x01b0| ff | . | hardware_version: 255 (invalid) 0x1bc-0x1bd (1)
0x01b0| ff | . | UNKNOWN_9: 255 (invalid) 0x1bd-0x1be (1)
0x01b0| ff | . | battery_status: 255 (invalid) 0x1be-0x1bf (1)
@ -520,7 +520,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x0210| ff ff | .. | UNKNOWN_13: 65535 (invalid) 0x215-0x217 (2)
0x0210| 00 00 | .. | ant_device_number: 0 (invalid) 0x217-0x219 (2)
0x0210| 01 | . | device_index: 1 0x219-0x21a (1)
0x0210| 03 | . | device_type: 3 0x21a-0x21b (1)
0x0210| 03 | . | local_device_type: "accelerometer" (3) 0x21a-0x21b (1)
0x0210| ff | . | hardware_version: 255 (invalid) 0x21b-0x21c (1)
0x0210| ff | . | UNKNOWN_9: 255 (invalid) 0x21c-0x21d (1)
0x0210| ff | . | battery_status: 255 (invalid) 0x21d-0x21e (1)
@ -563,7 +563,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x0270| ff ff | .. | UNKNOWN_13: 65535 (invalid) 0x274-0x276 (2)
0x0270| 00 00 | .. | ant_device_number: 0 (invalid) 0x276-0x278 (2)
0x0270| 02 | . | device_index: 2 0x278-0x279 (1)
0x0270| 08 | . | device_type: 8 0x279-0x27a (1)
0x0270| 08 | . | local_device_type: 8 0x279-0x27a (1)
0x0270| ff | . | hardware_version: 255 (invalid) 0x27a-0x27b (1)
0x0270| ff | . | UNKNOWN_9: 255 (invalid) 0x27b-0x27c (1)
0x0270| ff | . | battery_status: 255 (invalid) 0x27c-0x27d (1)
@ -609,7 +609,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x02d0| ff ff | .. | UNKNOWN_13: 65535 (invalid) 0x2d3-0x2d5 (2)
0x02d0| 00 00 | .. | ant_device_number: 0 (invalid) 0x2d5-0x2d7 (2)
0x02d0| 03 | . | device_index: 3 0x2d7-0x2d8 (1)
0x02d0| 0a | . | device_type: 10 0x2d8-0x2d9 (1)
0x02d0| 0a | . | local_device_type: "whr" (10) 0x2d8-0x2d9 (1)
0x02d0| ff | . | hardware_version: 255 (invalid) 0x2d9-0x2da (1)
0x02d0| ff | . | UNKNOWN_9: 255 (invalid) 0x2da-0x2db (1)
0x02d0| ff | . | battery_status: 255 (invalid) 0x2db-0x2dc (1)
@ -654,7 +654,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x0330| ff ff | .. | UNKNOWN_13: 65535 (invalid) 0x332-0x334 (2)
0x0330| 00 00 | .. | ant_device_number: 0 (invalid) 0x334-0x336 (2)
0x0330| 04 | . | device_index: 4 0x336-0x337 (1)
0x0330| 0c | . | device_type: 12 0x337-0x338 (1)
0x0330| 0c | . | local_device_type: "sensor_hub" (12) 0x337-0x338 (1)
0x0330| ff | . | hardware_version: 255 (invalid) 0x338-0x339 (1)
0x0330| ff | . | UNKNOWN_9: 255 (invalid) 0x339-0x33a (1)
0x0330| ff | . | battery_status: 255 (invalid) 0x33a-0x33b (1)
@ -8718,8 +8718,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x1580| 01 | . | event_type: "stop" (1) 0x1581-0x1582 (1)
0x1580| 80 | . | avg_heart_rate: 128 (bpm) 0x1582-0x1583 (1)
0x1580| 89 | . | max_heart_rate: 137 (bpm) 0x1583-0x1584 (1)
0x1580| 49 | I | avg_cadence: 73 (rpm) 0x1584-0x1585 (1)
0x1580| 4e | N | max_cadence: 78 (rpm) 0x1585-0x1586 (1)
0x1580| 49 | I | avg_running_cadence: 73 (strides/min) 0x1584-0x1585 (1)
0x1580| 4e | N | max_running_cadence: 78 (strides/min) 0x1585-0x1586 (1)
0x1580| 00 | . | intensity: "active" (0) 0x1586-0x1587 (1)
0x1580| 02 | . | lap_trigger: "distance" (2) 0x1587-0x1588 (1)
0x1580| 01 | . | sport: "running" (1) 0x1588-0x1589 (1)
@ -14969,8 +14969,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x2230| 01 | . | event_type: "stop" (1) 0x2234-0x2235 (1)
0x2230| 8b | . | avg_heart_rate: 139 (bpm) 0x2235-0x2236 (1)
0x2230| 8f | . | max_heart_rate: 143 (bpm) 0x2236-0x2237 (1)
0x2230| 49 | I | avg_cadence: 73 (rpm) 0x2237-0x2238 (1)
0x2230| 4c | L | max_cadence: 76 (rpm) 0x2238-0x2239 (1)
0x2230| 49 | I | avg_running_cadence: 73 (strides/min) 0x2237-0x2238 (1)
0x2230| 4c | L | max_running_cadence: 76 (strides/min) 0x2238-0x2239 (1)
0x2230| 00 | . | intensity: "active" (0) 0x2239-0x223a (1)
0x2230| 02 | . | lap_trigger: "distance" (2) 0x223a-0x223b (1)
0x2230| 01 | . | sport: "running" (1) 0x223b-0x223c (1)
@ -21172,8 +21172,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x2ea0| 01| .| event_type: "stop" (1) 0x2eaf-0x2eb0 (1)
0x2eb0|8c |. | avg_heart_rate: 140 (bpm) 0x2eb0-0x2eb1 (1)
0x2eb0| 8f | . | max_heart_rate: 143 (bpm) 0x2eb1-0x2eb2 (1)
0x2eb0| 49 | I | avg_cadence: 73 (rpm) 0x2eb2-0x2eb3 (1)
0x2eb0| 4a | J | max_cadence: 74 (rpm) 0x2eb3-0x2eb4 (1)
0x2eb0| 49 | I | avg_running_cadence: 73 (strides/min) 0x2eb2-0x2eb3 (1)
0x2eb0| 4a | J | max_running_cadence: 74 (strides/min) 0x2eb3-0x2eb4 (1)
0x2eb0| 00 | . | intensity: "active" (0) 0x2eb4-0x2eb5 (1)
0x2eb0| 02 | . | lap_trigger: "distance" (2) 0x2eb5-0x2eb6 (1)
0x2eb0| 01 | . | sport: "running" (1) 0x2eb6-0x2eb7 (1)
@ -27499,8 +27499,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x3b70| 01 | . | event_type: "stop" (1) 0x3b7e-0x3b7f (1)
0x3b70| 8a| .| avg_heart_rate: 138 (bpm) 0x3b7f-0x3b80 (1)
0x3b80|8f |. | max_heart_rate: 143 (bpm) 0x3b80-0x3b81 (1)
0x3b80| 49 | I | avg_cadence: 73 (rpm) 0x3b81-0x3b82 (1)
0x3b80| 4b | K | max_cadence: 75 (rpm) 0x3b82-0x3b83 (1)
0x3b80| 49 | I | avg_running_cadence: 73 (strides/min) 0x3b81-0x3b82 (1)
0x3b80| 4b | K | max_running_cadence: 75 (strides/min) 0x3b82-0x3b83 (1)
0x3b80| 00 | . | intensity: "active" (0) 0x3b83-0x3b84 (1)
0x3b80| 02 | . | lap_trigger: "distance" (2) 0x3b84-0x3b85 (1)
0x3b80| 01 | . | sport: "running" (1) 0x3b85-0x3b86 (1)
@ -34035,8 +34035,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x4890| 01 | . | event_type: "stop" (1) 0x4894-0x4895 (1)
0x4890| 89 | . | avg_heart_rate: 137 (bpm) 0x4895-0x4896 (1)
0x4890| 8f | . | max_heart_rate: 143 (bpm) 0x4896-0x4897 (1)
0x4890| 47 | G | avg_cadence: 71 (rpm) 0x4897-0x4898 (1)
0x4890| 4d | M | max_cadence: 77 (rpm) 0x4898-0x4899 (1)
0x4890| 47 | G | avg_running_cadence: 71 (strides/min) 0x4897-0x4898 (1)
0x4890| 4d | M | max_running_cadence: 77 (strides/min) 0x4898-0x4899 (1)
0x4890| 00 | . | intensity: "active" (0) 0x4899-0x489a (1)
0x4890| 02 | . | lap_trigger: "distance" (2) 0x489a-0x489b (1)
0x4890| 01 | . | sport: "running" (1) 0x489b-0x489c (1)
@ -40375,8 +40375,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x5560| 01 | . | event_type: "stop" (1) 0x556d-0x556e (1)
0x5560| 88 | . | avg_heart_rate: 136 (bpm) 0x556e-0x556f (1)
0x5560| 8b| .| max_heart_rate: 139 (bpm) 0x556f-0x5570 (1)
0x5570|4a |J | avg_cadence: 74 (rpm) 0x5570-0x5571 (1)
0x5570| 4c | L | max_cadence: 76 (rpm) 0x5571-0x5572 (1)
0x5570|4a |J | avg_running_cadence: 74 (strides/min) 0x5570-0x5571 (1)
0x5570| 4c | L | max_running_cadence: 76 (strides/min) 0x5571-0x5572 (1)
0x5570| 00 | . | intensity: "active" (0) 0x5572-0x5573 (1)
0x5570| 02 | . | lap_trigger: "distance" (2) 0x5573-0x5574 (1)
0x5570| 01 | . | sport: "running" (1) 0x5574-0x5575 (1)
@ -40579,7 +40579,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x5640| ff ff | .. | UNKNOWN_13: 65535 (invalid) 0x5641-0x5643 (2)
0x5640| 00 00 | .. | ant_device_number: 0 (invalid) 0x5643-0x5645 (2)
0x5640| 00 | . | device_index: "creator" (0) 0x5645-0x5646 (1)
0x5640| ff | . | device_type: 255 (invalid) 0x5646-0x5647 (1)
0x5640| ff | . | local_device_type: 255 (invalid) 0x5646-0x5647 (1)
0x5640| ff | . | hardware_version: 255 (invalid) 0x5647-0x5648 (1)
0x5640| ff | . | UNKNOWN_9: 255 (invalid) 0x5648-0x5649 (1)
0x5640| ff | . | battery_status: 255 (invalid) 0x5649-0x564a (1)
@ -40621,7 +40621,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x56a0|ff ff |.. | UNKNOWN_13: 65535 (invalid) 0x56a0-0x56a2 (2)
0x56a0| 00 00 | .. | ant_device_number: 0 (invalid) 0x56a2-0x56a4 (2)
0x56a0| 01 | . | device_index: 1 0x56a4-0x56a5 (1)
0x56a0| 03 | . | device_type: 3 0x56a5-0x56a6 (1)
0x56a0| 03 | . | local_device_type: "accelerometer" (3) 0x56a5-0x56a6 (1)
0x56a0| ff | . | hardware_version: 255 (invalid) 0x56a6-0x56a7 (1)
0x56a0| ff | . | UNKNOWN_9: 255 (invalid) 0x56a7-0x56a8 (1)
0x56a0| ff | . | battery_status: 255 (invalid) 0x56a8-0x56a9 (1)
@ -40667,7 +40667,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x5700|ff |. |
0x5700| 00 00 | .. | ant_device_number: 0 (invalid) 0x5701-0x5703 (2)
0x5700| 02 | . | device_index: 2 0x5703-0x5704 (1)
0x5700| 08 | . | device_type: 8 0x5704-0x5705 (1)
0x5700| 08 | . | local_device_type: 8 0x5704-0x5705 (1)
0x5700| ff | . | hardware_version: 255 (invalid) 0x5705-0x5706 (1)
0x5700| ff | . | UNKNOWN_9: 255 (invalid) 0x5706-0x5707 (1)
0x5700| ff | . | battery_status: 255 (invalid) 0x5707-0x5708 (1)
@ -40712,7 +40712,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x5750| ff ff| ..| UNKNOWN_13: 65535 (invalid) 0x575e-0x5760 (2)
0x5760|00 00 |.. | ant_device_number: 0 (invalid) 0x5760-0x5762 (2)
0x5760| 03 | . | device_index: 3 0x5762-0x5763 (1)
0x5760| 0a | . | device_type: 10 0x5763-0x5764 (1)
0x5760| 0a | . | local_device_type: "whr" (10) 0x5763-0x5764 (1)
0x5760| ff | . | hardware_version: 255 (invalid) 0x5764-0x5765 (1)
0x5760| ff | . | UNKNOWN_9: 255 (invalid) 0x5765-0x5766 (1)
0x5760| ff | . | battery_status: 255 (invalid) 0x5766-0x5767 (1)
@ -40758,7 +40758,7 @@ $ fq -d fit dv activity_invalid_strings.fit
0x57b0| 00| .| ant_device_number: 0 (invalid) 0x57bf-0x57c1 (2)
0x57c0|00 |. |
0x57c0| 04 | . | device_index: 4 0x57c1-0x57c2 (1)
0x57c0| 0c | . | device_type: 12 0x57c2-0x57c3 (1)
0x57c0| 0c | . | local_device_type: "sensor_hub" (12) 0x57c2-0x57c3 (1)
0x57c0| ff | . | hardware_version: 255 (invalid) 0x57c3-0x57c4 (1)
0x57c0| ff | . | UNKNOWN_9: 255 (invalid) 0x57c4-0x57c5 (1)
0x57c0| ff | . | battery_status: 255 (invalid) 0x57c5-0x57c6 (1)
@ -41298,8 +41298,8 @@ $ fq -d fit dv activity_invalid_strings.fit
0x5900| 01 | . | event_type: "stop" (1) 0x5902-0x5903 (1)
0x5900| 86 | . | avg_heart_rate: 134 (bpm) 0x5903-0x5904 (1)
0x5900| 86 | . | max_heart_rate: 134 (bpm) 0x5904-0x5905 (1)
0x5900| 2e | . | avg_cadence: 46 (rpm) 0x5905-0x5906 (1)
0x5900| 4a | J | max_cadence: 74 (rpm) 0x5906-0x5907 (1)
0x5900| 2e | . | avg_running_cadence: 46 (strides/min) 0x5905-0x5906 (1)
0x5900| 4a | J | max_running_cadence: 74 (strides/min) 0x5906-0x5907 (1)
0x5900| 00 | . | intensity: "active" (0) 0x5907-0x5908 (1)
0x5900| 07 | . | lap_trigger: "session_end" (7) 0x5908-0x5909 (1)
0x5900| 01 | . | sport: "running" (1) 0x5909-0x590a (1)