public void Heading()
        {
            PGNSettings configuration = new PGNSettings();

            configuration.AddPGN(127250, "Vessel Heading")
            .FirstField("SID", 8)
            .NextField("Heading", 16, f => f.SetAngle(AngleUnit.Radians, 0.0001d))
            .NextField("Deviation", 16, f => f.SetAngle(AngleUnit.Radians, 0.0001d))
            .NextField("Variation", 16, f => f.SetAngle(AngleUnit.Radians, 0.0001d))
            .NextField("Reference", 2, f => f.SetLookups
                           (d =>
            {
                d.Add(0, "True");
                d.Add(1, "Magnetic");
            }
                           ));

            PGNConfiguration vesselHeading = configuration.GetById(127250);

            Assert.IsNotNull(vesselHeading);
            Assert.AreEqual(127250, vesselHeading.PGN);
            Assert.AreEqual("Vessel Heading", vesselHeading.Name);

            var fields = vesselHeading.Fields;

            Assert.IsNotNull(fields);
            Assert.AreEqual(5, fields.Count);

            var deviation = fields.FirstOrDefault(f => f.Name == "Deviation");

            Assert.IsNotNull(deviation);
            Assert.AreEqual(24, deviation.BitOffset);
            Assert.AreEqual(AngleUnit.Radians, deviation.Units);
            Assert.AreEqual(0.0001d, deviation.Resolution);
        }
        public void BasicConfiguration()
        {
            PGNSettings configuration = new PGNSettings();

            configuration.AddPGN(59392, "ISO Acknowledgement")
            .FirstField("Control", 8, f =>
                        f.SetLookups(d =>
            {
                d.Add(0, "ACK");
                d.Add(1, "NAK");
                d.Add(2, "Access Denied");
                d.Add(3, "Adress Busy");
            }))
            .NextField("Group Function", 8)
            .NextField("Reserved", 24, f => f.IsSigned = true)
            .NextField("PGN", 24, f =>
            {
                f.Description = "Parameter Group Number of requested information";
                f.FieldType   = PGNFieldType.Integer;
            });

            configuration.AddPGN(59904, "ISO Request")
            .FirstField("PGN", 24).IsInteger();

            PGNConfiguration result59392 = configuration.GetById(59392);

            Assert.IsNotNull(result59392);
            Assert.AreEqual(59392, result59392.PGN);
            Assert.AreEqual("ISO Acknowledgement", result59392.Name);

            var fields = result59392.Fields;

            Assert.IsNotNull(fields);
            Assert.AreEqual(4, fields.Count);

            var pgn = fields.FirstOrDefault(f => f.Name == "PGN");

            Assert.IsNotNull(pgn);
            Assert.AreEqual("Parameter Group Number of requested information", pgn.Description);
            Assert.AreEqual(4, pgn.Order);

            var signed = fields.FirstOrDefault(f => f.IsSigned);

            Assert.IsNotNull(signed);
            Assert.AreEqual("Reserved", signed.Name);

            var result59904 = configuration.GetById(59904);

            Assert.IsNotNull(result59904);
            Assert.AreEqual(59904, result59904.PGN);
            Assert.AreEqual("ISO Request", result59904.Name);
        }
Exemplo n.º 3
0
        private void DecodeMessage(byte[] payload)
        {
            #region this has to be totally refactored somehow and made more efficient for loading via singleton or whatever:
            PGNSettings configuration = new PGNSettings();
            configuration.AddPGN(127250, "Vessel Heading")
            .FirstField("SID", 8)
            .NextField("Heading", 16, f => f.SetAngle(AngleUnit.Radians, 0.0001d))
            .NextField("Deviation", 16, f => f.SetAngle(AngleUnit.Radians, 0.0001d))
            .NextField("Variation", 16, f => f.SetAngle(AngleUnit.Radians, 0.0001d))
            .NextField("Reference", 2, f => f.SetLookups
                           (d =>
            {
                d.Add(0, "True");
                d.Add(1, "Magnetic");
            }
                           ));
            #endregion

            PGNConfiguration vesselHeadingConfiguration = configuration.GetById(PGN);

            var      fieldInformation = new Dictionary <string, PGNFieldInformation>();
            BitArray payloadBitArray  = new BitArray(payload);
            foreach (PGNField field in vesselHeadingConfiguration.Fields)
            {
                BitArray bitArray = new BitArray(field.BitLength);
                for (int i = 0; i < field.BitLength; i++)
                {
                    bitArray[i] = payloadBitArray[i + field.BitOffset];
                }

                PGNFieldInformation pgnFieldInformation = new PGNFieldInformation
                {
                    Configuration = field,
                    Data          = bitArray
                };
                fieldInformation.Add(field.Name, pgnFieldInformation);
            }

            ProcessPayload(fieldInformation);
        }