Пример #1
0
        public Message(Message mesg)
        {
            if (mesg == null)
            {
                this.Name          = "unknown";
                this.MessageNumber = (ushort)MessageNum.Invalid;
                return;
            }
            this.Name             = mesg.Name;
            this.MessageNumber    = mesg.MessageNumber;
            this.LocalNum         = mesg.LocalNum;
            this.systemTimeOffset = mesg.systemTimeOffset;
            foreach (Field field in mesg.FieldsList)
            {
                if (field.GetNumValues() > 0)
                {
                    this.FieldsList.Add(new Field(field));
                }
            }

            foreach (var fld in mesg.DeveloperFields)
            {
                if (fld.GetNumValues() > 0)
                {
                    var key = new DeveloperDataKey(fld.DeveloperDataIndex, fld.Num);
                    developerFields[key] = new DeveloperField(fld);
                }
            }
        }
Пример #2
0
        public void Read(Stream inStream, MesgDefinition defnMesg)
        {
            inStream.Position = 1;
            EndianBinaryReader mesgReader = new EndianBinaryReader(inStream, defnMesg.IsBigEndian);

            LocalNum = defnMesg.LocalMesgNum;

            foreach (FieldDefinition fieldDef in defnMesg.GetFields())
            {
                // It's possible the field type found in the field definition may
                // not agree with the type defined in the profile.  The profile
                // type will be preferred for decode.
                Field field = GetField(fieldDef.Num);
                if (field == null)
                {
                    // We normally won't have fields attached to our skeleton message,
                    // as we add values we need to add the fields too based on the mesg,field
                    // combo in the profile.  Must derive from the profile so the scale etc
                    // is correct
                    field = new Field(Profile.GetMesg(this.Num).GetField(fieldDef.Num));
                    if (field.Num == Fit.FieldNumInvalid)
                    {
                        // If there was no info in the profile the FieldNum will get set to invalid
                        // so preserve the unknown fields info while we know it
                        field.Num = fieldDef.Num;
                        field.SetType(fieldDef.Type);
                    }
                    SetField(field);
                }

                ReadFieldValue(field, fieldDef.Size, mesgReader);
            }

            foreach (DeveloperFieldDefinition fldDef in defnMesg.DeveloperFieldDefinitions)
            {
                DeveloperField fld = GetDeveloperField(fldDef.FieldNum, fldDef.DeveloperDataIndex);
                if (ReferenceEquals(fld, null))
                {
                    fld = new DeveloperField(fldDef);
                    SetDeveloperField(fld);
                }

                ReadFieldValue(fld, fldDef.Size, mesgReader);
            }
        }
Пример #3
0
        public void Write(Stream outStream, MesgDefinition mesgDef)
        {
            if (mesgDef == null)
            {
                mesgDef = new MesgDefinition(this);
            }

            EndianBinaryWriter bw = new EndianBinaryWriter(outStream, mesgDef.IsBigEndian);

            bw.Write(LocalNum);

            foreach (FieldDefinition fieldDef in mesgDef.GetFields())
            {
                Field field = GetField(fieldDef.Num);
                if (null == field)
                {
                    field = Profile.GetField(this.Num, fieldDef.Num);
                    if (null != field)
                    {
                        FieldsList.Add(field);
                    }
                    else
                    {
                        //Field does not exist in profile, continue to next field
                        continue;
                    }
                }

                WriteField(field, fieldDef.Size, bw);
            }

            foreach (DeveloperFieldDefinition fieldDef in mesgDef.DeveloperFieldDefinitions)
            {
                DeveloperField field = GetDeveloperField(fieldDef.FieldNum, fieldDef.DeveloperDataIndex);

                if (field == null)
                {
                    field = new DeveloperField(fieldDef);
                    SetDeveloperField(field);
                }

                WriteField(field, fieldDef.Size, bw);
            }
        }
Пример #4
0
        public void SetDeveloperField(DeveloperField field)
        {
            var devKey = new DeveloperDataKey(field.DeveloperDataIndex, field.Num);

            developerFields[devKey] = field;
        }
Пример #5
0
        public void Read(Stream inStream, MessageDefinition defnMessage)
        {
            inStream.Position = 1;
            EndianBinaryReader mesgReader = new EndianBinaryReader(inStream, defnMessage.IsBigEndian);

            LocalNum = defnMessage.LocalMessageNum;

            foreach (FieldDefinition fieldDef in defnMessage.GetFields())
            {
                bool read = true;

                // It's possible the field type found in the field definition may
                // not agree with the type defined in the profile.  The profile
                // type will be preferred for decode.
                Field field = GetField(fieldDef.Num);
                if (field == null)
                {
                    // We normally won't have fields attached to our skeleton message,
                    // as we add values we need to add the fields too based on the mesg,field
                    // combo in the profile.  Must derive from the profile so the scale etc
                    // is correct
                    field = new Field(Profile.GetMessage(this.MessageNumber).GetField(fieldDef.Num));
                    if (field.Num == Fit.FieldNumInvalid)
                    {
                        // If there was no info in the profile the FieldNum will get set to invalid
                        // so preserve the unknown fields info while we know it
                        field.Num = fieldDef.Num;
                        field.SetType(fieldDef.Type);
                    }
                    SetField(field);
                }

                if (field.Type != fieldDef.Type)
                {
                    int fieldSize = Fit.BaseType[field.Type & Fit.BaseTypeNumMask].size;
                    int defSize   = Fit.BaseType[fieldDef.Type & Fit.BaseTypeNumMask].size;

                    if (defSize < fieldSize)
                    {
                        field.SetType(fieldDef.Type);
                    }
                    else if (defSize != fieldSize)
                    {
                        // Demotion is hard. Don't read the field if the
                        // sizes are different. Use the profile type if the
                        // signedness of the field has changed.
                        read = false;
                    }
                }

                if (read)
                {
                    ReadFieldValue(field, fieldDef.Size, mesgReader);
                }
                else
                {
                    // Skip the bytes for the field if we aren't going to bother reading them
                    mesgReader.ReadBytes(fieldDef.Size);
                }
            }

            foreach (DeveloperFieldDefinition fldDef in defnMessage.DeveloperFieldDefinitions)
            {
                DeveloperField fld = GetDeveloperField(fldDef.FieldNum, fldDef.DeveloperDataIndex);
                if (ReferenceEquals(fld, null))
                {
                    fld = new DeveloperField(fldDef);
                    SetDeveloperField(fld);
                }

                ReadFieldValue(fld, fldDef.Size, mesgReader);
            }
        }
Пример #6
0
 public DeveloperField(DeveloperField other)
     : base(other)
 {
     m_definition = other.m_definition;
 }