mirror of
https://github.com/wader/fq.git
synced 2024-10-26 20:06:29 +03:00
fit: Show crc as hex, lower case "invalid" and some style harmonization
This commit is contained in:
parent
f7ae961e1e
commit
788088f84d
@ -28,8 +28,8 @@ func init() {
|
||||
}
|
||||
|
||||
var fitCRCTable = [16]uint16{
|
||||
0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401,
|
||||
0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400,
|
||||
0x0000, 0xcc01, 0xd801, 0x1400, 0xf001, 0x3c00, 0x2800, 0xe401,
|
||||
0xa001, 0x6c00, 0x7800, 0xb401, 0x5000, 0x9c01, 0x8801, 0x4400,
|
||||
}
|
||||
|
||||
func calcCRC(bytes []byte) uint16 {
|
||||
@ -38,12 +38,12 @@ func calcCRC(bytes []byte) uint16 {
|
||||
for i := 0; i < len(bytes); i++ {
|
||||
// compute checksum of lower four bits of byte
|
||||
var checkByte = bytes[i]
|
||||
var tmp = fitCRCTable[crc&0xF]
|
||||
crc = (crc >> 4) & 0x0FFF
|
||||
crc = crc ^ tmp ^ fitCRCTable[checkByte&0xF]
|
||||
tmp = fitCRCTable[crc&0xF]
|
||||
crc = (crc >> 4) & 0x0FFF
|
||||
crc = crc ^ tmp ^ fitCRCTable[(checkByte>>4)&0xF]
|
||||
var tmp = fitCRCTable[crc&0xf]
|
||||
crc = (crc >> 4) & 0x0fff
|
||||
crc = crc ^ tmp ^ fitCRCTable[checkByte&0xf]
|
||||
tmp = fitCRCTable[crc&0xf]
|
||||
crc = (crc >> 4) & 0x0fff
|
||||
crc = crc ^ tmp ^ fitCRCTable[(checkByte>>4)&0xf]
|
||||
}
|
||||
|
||||
return crc
|
||||
@ -97,7 +97,7 @@ func fitDecodeFileHeader(d *decode.D, fc *fitContext) {
|
||||
d.FieldRawLen("data_type", 4*8, d.AssertBitBuf([]byte(".FIT")))
|
||||
if headerSize == 14 {
|
||||
headerCRC := calcCRC(d.BytesRange(frameStart, int(headerSize)-2))
|
||||
d.FieldU16("crc", d.UintValidate(uint64(headerCRC)))
|
||||
d.FieldU16("crc", d.UintValidate(uint64(headerCRC)), scalar.UintHex)
|
||||
}
|
||||
fc.headerSize = headerSize
|
||||
fc.dataSize = dataSize
|
||||
@ -393,7 +393,7 @@ func decodeFIT(d *decode.D) any {
|
||||
} else {
|
||||
fileCRC = calcCRC(d.BytesRange(14*8, int(fc.dataSize))) // 14 byte header - CRC everything below header except the CRC itself
|
||||
}
|
||||
d.FieldU16("crc", d.UintValidate(uint64(fileCRC)))
|
||||
d.FieldU16("crc", d.UintValidate(uint64(fileCRC)), scalar.UintHex)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -10,34 +10,34 @@ import (
|
||||
var scConst = 180 / math.Pow(2, 31)
|
||||
|
||||
var invalidUint = map[string]uint64{
|
||||
"byte": 0xFF,
|
||||
"enum": 0xFF,
|
||||
"uint8": 0xFF,
|
||||
"byte": 0xff,
|
||||
"enum": 0xff,
|
||||
"uint8": 0xff,
|
||||
"uint8z": 0x00,
|
||||
"uint16": 0xFFFF,
|
||||
"uint16": 0xffff,
|
||||
"uint16z": 0x0000,
|
||||
"uint32": 0xFFFFFFFF,
|
||||
"uint32z": 0x00000000,
|
||||
"uint64": 0xFFFFFFFFFFFFFFFF,
|
||||
"uint64z": 0x0000000000000000,
|
||||
"uint32": 0xffff_ffff,
|
||||
"uint32z": 0x0000_0000,
|
||||
"uint64": 0xffff_ffff_ffff_ffff,
|
||||
"uint64z": 0x0000_0000_0000_0000,
|
||||
}
|
||||
|
||||
var invalidSint = map[string]int64{
|
||||
"sint8": 0x7F,
|
||||
"sint16": 0x7FFF,
|
||||
"sint32": 0x7FFFFFFF,
|
||||
"sint64": 0x7FFFFFFFFFFFFFFF,
|
||||
"sint8": 0x7f,
|
||||
"sint16": 0x7fff,
|
||||
"sint32": 0x7fff_ffff,
|
||||
"sint64": 0x7fff_ffff_ffff_ffff,
|
||||
}
|
||||
|
||||
var invalidFloat = map[string]float64{
|
||||
"float32": 0xFFFFFFFF,
|
||||
"float64": 0xFFFFFFFFFFFFFFFF,
|
||||
"float32": 0xffff_ffff,
|
||||
"float64": 0xffff_ffff_ffff_ffff,
|
||||
}
|
||||
|
||||
func GetUintFormatter(fDef LocalFieldDef) scalar.UintFn {
|
||||
return scalar.UintFn(func(s scalar.Uint) (scalar.Uint, error) {
|
||||
if s.Actual == invalidUint[fDef.Type] {
|
||||
s.Description = "Invalid"
|
||||
s.Description = "invalid"
|
||||
return s, nil
|
||||
}
|
||||
if fDef.Scale != 0.0 && fDef.Offset != 0 {
|
||||
@ -53,7 +53,7 @@ func GetUintFormatter(fDef LocalFieldDef) scalar.UintFn {
|
||||
|
||||
s.Description = fDef.Unit
|
||||
if t, ok := TypeDefMap[fDef.Format]; ok {
|
||||
if u, innerok := t[s.Actual]; innerok {
|
||||
if u, innerOk := t[s.Actual]; innerOk {
|
||||
s.Sym = u.Name
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,7 @@ func GetUintFormatter(fDef LocalFieldDef) scalar.UintFn {
|
||||
func GetSintFormatter(fDef LocalFieldDef) scalar.SintFn {
|
||||
return scalar.SintFn(func(s scalar.Sint) (scalar.Sint, error) {
|
||||
if s.Actual == invalidSint[fDef.Type] {
|
||||
s.Description = "Invalid"
|
||||
s.Description = "invalid"
|
||||
return s, nil
|
||||
}
|
||||
if fDef.Unit == "semicircles" {
|
||||
@ -90,7 +90,7 @@ func GetSintFormatter(fDef LocalFieldDef) scalar.SintFn {
|
||||
func GetFloatFormatter(fDef LocalFieldDef) scalar.FltFn {
|
||||
return scalar.FltFn(func(s scalar.Flt) (scalar.Flt, error) {
|
||||
if s.Actual == invalidFloat[fDef.Type] {
|
||||
s.Description = "Invalid"
|
||||
s.Description = "invalid"
|
||||
return s, nil
|
||||
}
|
||||
if fDef.Scale != 0.0 && fDef.Offset != 0 {
|
||||
|
8690
format/fit/testdata/activity.fqtest
vendored
8690
format/fit/testdata/activity.fqtest
vendored
File diff suppressed because it is too large
Load Diff
4
format/fit/testdata/activity_dev.fqtest
vendored
4
format/fit/testdata/activity_dev.fqtest
vendored
@ -6,7 +6,7 @@ $ fq -d fit dv activity_dev.fit
|
||||
0x0000| 57 08 | W. | profile_version: 2135 0x2-0x4 (2)
|
||||
0x0000| e1 fe 00 00 | .... | data_size: 65249 0x4-0x8 (4)
|
||||
0x0000| 2e 46 49 54 | .FIT | data_type: raw bits (valid) 0x8-0xc (4)
|
||||
0x0000| 99 95 | .. | crc: 38297 (valid) 0xc-0xe (2)
|
||||
0x0000| 99 95 | .. | crc: 0x9599 (valid) 0xc-0xe (2)
|
||||
| | | data_records[0:3622]: 0xe-0xfeef (65249)
|
||||
| | | [0]{}: data_record 0xe-0x23 (21)
|
||||
| | | record_header{}: 0xe-0xf (1)
|
||||
@ -59056,5 +59056,5 @@ $ fq -d fit dv activity_dev.fit
|
||||
0xfee0| f5 7a b5 39 | .z.9 | timestamp: 968194805 0xfee5-0xfee9 (4)
|
||||
0xfee0| 01 00 | .. | num_sessions: 1 0xfee9-0xfeeb (2)
|
||||
0xfee0| 85 18 b5 39 | ...9 | local_timestamp: 968169605 0xfeeb-0xfeef (4)
|
||||
0xfee0| ec| .| crc: 51948 (valid) 0xfeef-0xfef1 (2)
|
||||
0xfee0| ec| .| crc: 0xcaec (valid) 0xfeef-0xfef1 (2)
|
||||
0xfef0|ca| |.| |
|
||||
|
1970
format/fit/testdata/activity_invalid_strings.fqtest
vendored
1970
format/fit/testdata/activity_invalid_strings.fqtest
vendored
File diff suppressed because it is too large
Load Diff
2
format/fit/testdata/settings.fqtest
vendored
2
format/fit/testdata/settings.fqtest
vendored
@ -122,4 +122,4 @@ $ fq -d fit dv settings.fit
|
||||
0x40| 00 | . | local_message_type: 0 0x4d.4-0x4e (0.4)
|
||||
| | | data_message{}: 0x4e-0x50 (2)
|
||||
0x40| 00 64| .d| hrm_ant_id: 25600 0x4e-0x50 (2)
|
||||
0x50|39 50| |9P| | crc: 20537 (valid) 0x50-0x52 (2)
|
||||
0x50|39 50| |9P| | crc: 0x5039 (valid) 0x50-0x52 (2)
|
||||
|
Loading…
Reference in New Issue
Block a user