internal Message(DefinitionRecord definitionRecord) { this.globalMsgNum = definitionRecord.GlobalMsgNum; if (Messages.Names.ContainsKey(this.globalMsgNum)) { this.name = Messages.Names[this.globalMsgNum]; if (Fields._Fields.ContainsKey(this.globalMsgNum)) { var fields = Fields._Fields[this.globalMsgNum]; foreach (var dataRecord in definitionRecord.valid()) { foreach (var dataField in dataRecord.valid()) { if (fields.ContainsKey(dataField.Key)) { var field = fields[dataField.Key]; var data = processValue(field, dataField.Value.data); this.data[field.name] = data; } else { var a = 1; } } } } } }
public DataRecord(EndianBinaryReader binaryReader, DefinitionRecord definitionRecord) { this.globalMsgNum = definitionRecord.GlobalMsgNum; this.fields = new List <Dictionary <byte, DataField> >(); foreach (FieldDefinition fieldDefinition in definitionRecord.FieldDefinitions) { var opts = new Dictionary <string, byte>() { { "baseNum", fieldDefinition.baseNum }, { "size", fieldDefinition.size }, { "arch", fieldDefinition.endianness } }; this.fields.Add(new Dictionary <byte, DataField>() { { fieldDefinition.fieldDefNum, new DataField(binaryReader, opts) } }); } }
public Fit(EndianBinaryReader binaryReader) { this.fileHeader = new FileHeader(binaryReader); if (!validate(binaryReader)) { throw new Exception(); } while (binaryReader.Position < (this.fileHeader.dataSize + this.fileHeader.size)) { RecordHeader recordHeader = new RecordHeader(binaryReader); if (recordHeader.isDefinition()) { DefinitionRecord definitionRecord = new DefinitionRecord(binaryReader, recordHeader.localMessageType); if (definitions.ContainsKey(recordHeader.localMessageType)) { finished.Add(definitionRecord); } definitions[recordHeader.localMessageType] = definitionRecord; } else if (recordHeader.isData()) { DefinitionRecord definitionRecord = definitions[recordHeader.localMessageType]; DataRecord dataRecord = new DataRecord(binaryReader, definitionRecord); definitionRecord.dataRecords.Add(dataRecord); } } foreach (var definition in definitions) { finished.Add(definition.Value); } var grouped = new SortedDictionary <ushort, List <DefinitionRecord> >(); foreach (DefinitionRecord definition in finished) { if (!grouped.ContainsKey(definition.GlobalMsgNum)) { var list = new List <DefinitionRecord>(); list.Add(definition); grouped.Add(definition.GlobalMsgNum, list); } else { grouped[definition.GlobalMsgNum].Add(definition); } } foreach (KeyValuePair <ushort, List <DefinitionRecord> > entry in grouped) { var messages = new List <Message>(); string name = null; foreach (var definition in entry.Value) { var message = new Message(definition); if (message.Name != null) { if (name == null) { name = message.Name; } messages.Add(message); } } if (name != null) { this.messages[name] = messages; } } }