FitnessKit / FitDataProtocol

Swift Implementation the Garmin Flexible and Interoperable Data Transfer Protocol.
https://fitnesskit.github.io/FitDataProtocol/
MIT License
51 stars 15 forks source link

How to access developer fields in RecordMessage #12

Closed stefanhp closed 5 years ago

stefanhp commented 5 years ago

Hi,

I have FIT files that include some developer fields in RecordMessage messages. For example developer_Power, developer_Vertical Oscillation or developer_Form Power.

Since the RecordMessage is only holding values for keys in FitCodingKeys how could I access those entries?

If not, what would be the best way to implement this?

Thanks, Stefan

khoogheem commented 5 years ago

I have not yet had the need for Developer Fields.. so I have not spent a lot of time trying to get at them. The problem is that Given they are Developer Specific It is hard to add it to the base lib

Option would be to use a Subclass of the RecordMessage and provide your own decodes for the dev data. and then decode the fieldData.developerFieldData based on the definitions.

The other option is I need to look at a few fit files with Dev Data and try and provide back some dictionary of the decoded results.. I have one fit file right now with dev data but if you have some you are willing to share with me so I can work on a solution that would be great

khoogheem commented 5 years ago

I will be pushing up some updates into master.. I wait to tag and get a Pod update out.. but should have Dev data support...

Right now it is pretty manual but you can extract the dev data from the Messages. I will look into doing it more automagically later. Probably with the Swift5.1 Release as I have a bunch of changes that I want to do to reduce the amount of code overall.

try decoder.decode(data: fileData,
                   messages: FitFileDecoder.defaultMessages,
                   decoded: { (message: FitMessage) in

                    if let message = message as? RecordMessage {

                        if let dev = self.fieldDescription {
                            if let devData = message.developerData {
                                for devtype in devData {
                                    switch dev.decodeDouble(developerData: devtype) {
                                    case .success(let value):
                                        print("Value: \(value) \(dev.units)")
                                    case .failure(let error):
                                        print(error.localizedDescription)
                                    }
                                }
                            }
                        }
                        self.records.append(message)
                    }

                    if let message = message as? FieldDescriptionMessage {
                        self.fieldDescription = message
                        print("mssage", message)
                    }

}
stefanhp commented 5 years ago

Hi @khoogheem,

Thank you for looking into this, and sorry I did not get back sooner: I had a few days off.

I now get FieldDescriptionMessage properly, but I'm not able to decode the values properly. I can send you an example file privately, I'd rather not share it publicly because there are user and position data in it. Can I use the your email address found in public commits?

Thanks, Stefan

khoogheem commented 5 years ago

yah.. you can send it over.. I will test it then destroy it.

stefanhp commented 5 years ago

Hi,

Changes in commit 37e38bdb2cdb02b7dbca066374a0d78114e4b37d work perfectly!

Thanks, Stefan

khoogheem commented 5 years ago

Good to hear.. I will tag it then