Example #1
0
        private void _dataPointDefMonitor_Notification(object sender, PostgreSQLListener <FDADataPointDefinitionStructure> .PostgreSQLNotification notifyEvent)
        {
            string changeType = notifyEvent.Notification.operation;
            FDADataPointDefinitionStructure datapoint = notifyEvent.Notification.row;

            DataPointMonitorNotification(changeType, datapoint);
        }
Example #2
0
 public ScriptableTag(FDADataPointDefinitionStructure FDATag) : base(FDATag.ID)
 {
     _fdaTag = FDATag;
     FDATag.PropertyChanged += FDATag_PropertyChanged;
 }
Example #3
0
        static internal void MQTT_MqttMsgPublishReceived(object sender, uPLibrary.Networking.M2Mqtt.Messages.MqttMsgPublishEventArgs e)
        {
            string[] topic = e.Topic.Split('/');
            if (topic.Length < 2)
            {
                return;
            }

            /* these commands don't come through MQTT anymore
             * if (topic[0].ToUpper() == "FDAMANAGER")
             * {
             *
             * if (topic[1].ToUpper() == "COMMAND")
             * {
             *     string command = Encoding.UTF8.GetString(e.Message).ToUpper();
             *     switch (command)
             *     {
             *         // these commands will come over TCP from the FDAController service now
             *         //case "SHUTDOWN":
             *         //    DoShutdown();
             *         //    break;
             *         //case "PAUSE":
             *         //    Globals.SystemManager.LogApplicationEvent(Globals.FDANow(), "FDA Application", "", "Pause command received from FDA Manager", false, true);
             *         //    Console2.Flush();
             *         //    Globals.FDAStatus = Globals.AppState.Pausing;
             *         //    break;
             *         //case "RESUME":
             *         //    Globals.FDAStatus = Globals.AppState.Normal;
             *         //    Globals.SystemManager.LogApplicationEvent(Globals.FDANow(), "FDA Application", "", "Resume command received from FDA Manager", false, true);
             *         //    break;
             *     }
             * }
             * }
             */

            if (topic.Length < 3)
            {
                return;
            }

            if (topic[2].ToUpper() == "SETMQTTENABLED")
            {
                bool validGuid = Guid.TryParse(topic[1], out Guid objectID);
                if (!validGuid)
                {
                    return;
                }
                bool enabled = (e.Message[0] == 1);
                switch (topic[0].ToUpper())
                {
                case "CONNECTION":
                    RRConnectionManager conn = _dataAquisitionManager.GetDataConnection(objectID);
                    if (conn != null)
                    {
                        conn.MQTTEnabled = enabled;
                    }
                    break;

                case "TAG":
                    FDADataPointDefinitionStructure tag = ((DBManager)(Globals.DBManager)).GetTagDef(objectID);
                    if (tag != null)
                    {
                        tag.MQTTEnabled = enabled;
                    }
                    break;
                }
            }
        }
Example #4
0
        public void BitmaskFunctionalTest()
        {
            // set up a source tag, put it in a dictionary (like in the FDA), and make the dictionary available to the derived tags class
            Dictionary <Guid, FDADataPointDefinitionStructure> srcTags = new Dictionary <Guid, FDADataPointDefinitionStructure>();
            FDADataPointDefinitionStructure srcTag = new FDADataPointDefinitionStructure()
            {
                DPDUID      = Guid.NewGuid(),
                DPDSEnabled = true
            };

            srcTags.Add(srcTag.DPDUID, srcTag);
            DerivedTag.Tags = srcTags;



            UInt32 expectedDerivedVal;



            // bitmask 0000 0000 0000 0000 0000 0000 0000 0001
            DerivedTag softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":1");

            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    DT,
                    DataRequest.WriteMode.Insert);


                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(srcTag.LastRead.Timestamp, softTag.LastRead.Timestamp);
                Assert.AreEqual(srcTag.LastRead.Quality, softTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = testVal & 1;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }

            // bitmask 0000 0000 0000 0000 1100 0000 0000 0001
            softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":49153");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    DT,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp);
                Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = testVal & 49153;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }

            // bitmask 1111 1111 1111 1111 1111 1111 1111 1111
            softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":4294967295");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    DT,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(srcTag.LastRead.Timestamp, softTag.LastRead.Timestamp);
                Assert.AreEqual(srcTag.LastRead.Quality, softTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = testVal;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }


            // bitmask 0000 0000 0000 0000 1100 0000 0000 0001, source tag has bad quality
            softTag = DerivedTag.Create(Guid.NewGuid().ToString(), "bitmask", srcTag.DPDUID.ToString() + ":49153");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            FDADataPointDefinitionStructure.Datapoint lastRead_before_trigger;
            foreach (UInt32 testVal in TestValues)
            {
                lastRead_before_trigger = softTag.LastRead;
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    0,   // bad quality
                    DateTime.Now,
                    "",
                    DT,
                    DataRequest.WriteMode.Insert);

                // derived tag should not have updated (LastRead datapoint should not have changed)
                Assert.AreSame(lastRead_before_trigger, softTag.LastRead);
            }
        }
Example #5
0
        public void BitSeriesArgumentValidityChecks()
        {
            // set up a source tag, put it in a dictionary (like in the FDA), and make the dictionary available to the derived tags class
            Dictionary <Guid, FDADataPointDefinitionStructure> srcTags = new Dictionary <Guid, FDADataPointDefinitionStructure>();
            FDADataPointDefinitionStructure srcTag = new FDADataPointDefinitionStructure
            {
                DPDUID = Guid.NewGuid()
            };

            srcTags.Add(srcTag.DPDUID, srcTag);
            DerivedTag.Tags = srcTags;

            // good arguments, should all produce a valid and enabled derived tag
            List <string> goodArgs = new List <string>
            {
                srcTag.DPDUID.ToString() + ":0:2",
                          srcTag.DPDUID.ToString() + ":10:4",
                          srcTag.DPDUID.ToString() + ":0:32",
                          srcTag.DPDUID.ToString() + ":31:1"
            };

            // bad arguments, should all produce an invalid and disabled derived tag
            List <string> badArgs = new List <string>
            {
                null,                                 // null argument
                "",                                   // empty argument string
                Guid.NewGuid().ToString(),            // not enough args (1)
                Guid.NewGuid().ToString() + ":0",     // not enough args (2)

                "123456-789:0:2",                     // invalid SrcID
                Guid.NewGuid().ToString() + ":0:2",   // SrcID not found

                srcTag.DPDUID.ToString() + ":a:2",    // start bit not a number
                srcTag.DPDUID.ToString() + ":1.2:2",  // start bit not an integer
                srcTag.DPDUID.ToString() + ":50:2",   // start bit too high
                srcTag.DPDUID.ToString() + ":-2:2",   // start bit too low

                srcTag.DPDUID.ToString() + ":0:a",    // bit count not a number
                srcTag.DPDUID.ToString() + ":32:-5",  // negative bit count
                srcTag.DPDUID.ToString() + ":32:5.5", // bit count not an integer
                srcTag.DPDUID.ToString() + ":0:33",   // bit count too high
                srcTag.DPDUID.ToString() + ":1:32",   // start bit + bit count too high;
                srcTag.DPDUID.ToString() + ":10:25",  // start bit + bit count too high;
                srcTag.DPDUID.ToString() + ":31:2"    // start bit + bit count too high;
            };


            // check that bad softtag id is detected
            BitSeriesDerivedTag softTag = (BitSeriesDerivedTag)DerivedTag.Create("12345-678", "bitser", goodArgs[0]);

            softTag.Initialize();

            Assert.AreEqual(softTag.IsValid, false);


            // check that bad arguments are detected
            foreach (string badArgString in badArgs)
            {
                softTag = (BitSeriesDerivedTag)DerivedTag.Create(srcTag.DPDUID.ToString(), "bitser", badArgString);
                softTag.Initialize();
                Assert.AreEqual(softTag.IsValid, false);
            }

            // check that good arguments are determined to be valid
            foreach (string goodArgString in goodArgs)
            {
                softTag = (BitSeriesDerivedTag)DerivedTag.Create(srcTag.DPDUID.ToString(), "bitser", goodArgString);
                softTag.Initialize();
                Assert.AreEqual(softTag.IsValid, true);
            }
        }
Example #6
0
        public void BitmaskArgumentValidityChecks()
        {
            // set up a source tag, put it in a dictionary (like in the FDA), and make the dictionary available to the derived tags class
            Dictionary <Guid, FDADataPointDefinitionStructure> srcTags = new Dictionary <Guid, FDADataPointDefinitionStructure>();
            FDADataPointDefinitionStructure srcTag = new FDADataPointDefinitionStructure()
            {
                DPDSEnabled = true,
                DPDUID      = Guid.NewGuid()
            };

            srcTags.Add(srcTag.DPDUID, srcTag);
            DerivedTag.Tags = srcTags;

            // good arguments, should all produce a valid and enabled derived tag
            List <string> goodArgs = new List <string>
            {
                srcTag.DPDUID.ToString() + ":1",                    // 0000
                          srcTag.DPDUID.ToString() + ":2",          // 0010
                          srcTag.DPDUID.ToString() + ":4",          // 0100
                          srcTag.DPDUID.ToString() + ":8",          // 1000
                          srcTag.DPDUID.ToString() + ":12",         // 1100
                          srcTag.DPDUID.ToString() + ":2147483648", // 1000 0000 0000 0000 0000 0000 0000 0000
                          srcTag.DPDUID.ToString() + ":2147483649"  // 1000 0000 0000 0000 0000 0000 0000 0001
            };


            // bad arguments, should all produce an invalid and disabled derived tag
            List <string> badArgs = new List <string>
            {
                null,                                     // null argument
                "",                                       // empty argument string
                Guid.NewGuid().ToString(),                // not enough args (1)

                "123456-789:0:2",                         // invalid SrcID
                Guid.NewGuid().ToString() + ":0:2",       // SrcID not found

                srcTag.DPDUID.ToString() + ":a",          // bit mask not a number
                srcTag.DPDUID.ToString() + ":1.2",        // bit mask not an integer
                srcTag.DPDUID.ToString() + ":4294967296", // bit mask too high
                srcTag.DPDUID.ToString() + ":-2"          // bit mask too low
            };


            // check that bad softtag id is detected
            DerivedTag softTag = DerivedTag.Create("12345-678", "bitmask", goodArgs[0]);

            Assert.AreEqual(softTag.IsValid, false);
            Assert.AreEqual(softTag.DPDSEnabled, false);

            // check that bad arguments are detected
            foreach (string badArgString in badArgs)
            {
                softTag = DerivedTag.Create(srcTag.DPDUID.ToString(), "bitmask", badArgString);
                softTag.Initialize();
                Assert.AreEqual(softTag.IsValid, false);
                Assert.AreEqual(softTag.DPDSEnabled, false);
            }

            // check that good arguments are determined to be valid
            foreach (string goodArgString in goodArgs)
            {
                softTag = DerivedTag.Create(srcTag.DPDUID.ToString(), "bitmask", goodArgString);
                softTag.Initialize();
                Assert.AreEqual(true, softTag.IsValid);
            }
        }
Example #7
0
        public void BitSeriesFunctionalTest()
        {
            // set up a source tag, put it in a dictionary (like in the FDA), and make the dictionary available to the derived tags class
            Dictionary <Guid, FDADataPointDefinitionStructure> srcTags = new Dictionary <Guid, FDADataPointDefinitionStructure>();
            FDADataPointDefinitionStructure srcTag = new FDADataPointDefinitionStructure
            {
                DPDUID      = Guid.NewGuid(),
                DPDSEnabled = true
            };

            srcTags.Add(srcTag.DPDUID, srcTag);
            DerivedTag.Tags = srcTags;


            DataTypeBase datatype = Modbus.ModbusProtocol.DataType.UINT32;

            // extract bit 0 only
            BitSeriesDerivedTag softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":0:1");

            softTag.Initialize();
            softTag.DPDSEnabled = true;
            UInt32 expectedDerivedVal;

            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(srcTag.LastRead.Timestamp, softTag.LastRead.Timestamp);
                Assert.AreEqual(srcTag.LastRead.Quality, softTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = testVal & 1;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }


            // extract bit 31 only
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":31:1");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp);
                Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = (testVal & (UInt32)Math.Pow(2, 31)) >> 31;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }


            // extract bit 20 only
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":20:1");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp);
                Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = (testVal & (UInt32)Math.Pow(2, 20)) >> 20;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }

            // extract bits 0-1
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":0:2");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp);
                Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = testVal & ((UInt32)Math.Pow(2, 1) + (UInt32)Math.Pow(2, 0)) >> 0;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }

            // extract bits 10-13
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":10:4");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp);
                Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = (testVal & ((UInt32)Math.Pow(2, 10) + (UInt32)Math.Pow(2, 11) + (UInt32)Math.Pow(2, 12) + (UInt32)Math.Pow(2, 13))) >> 10;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }

            // "extract" all the bits
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":0:32");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(softTag.LastRead.Timestamp, srcTag.LastRead.Timestamp);
                Assert.AreEqual(softTag.LastRead.Quality, srcTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = testVal;
                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }

            // extract the highest 6 bits
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":26:6");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            foreach (UInt32 testVal in TestValues)
            {
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    192,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // check that the derived tag has the same timestamp and quality as the source tag
                Assert.AreEqual(srcTag.LastRead.Timestamp, softTag.LastRead.Timestamp);
                Assert.AreEqual(srcTag.LastRead.Quality, softTag.LastRead.Quality);

                // check that the value of the derived tag is correct
                expectedDerivedVal = expectedDerivedVal = (testVal & ((UInt32)Math.Pow(2, 26) + (UInt32)Math.Pow(2, 27) + (UInt32)Math.Pow(2, 28) + (UInt32)Math.Pow(2, 29) + (UInt32)Math.Pow(2, 30) + (UInt32)Math.Pow(2, 31))) >> 26;

                Assert.AreEqual(expectedDerivedVal, softTag.LastRead.Value);
            }


            // extract the highest 6 bits, source tag has bad quality
            softTag = (BitSeriesDerivedTag)DerivedTag.Create(Guid.NewGuid().ToString(), "bitser", srcTag.DPDUID.ToString() + ":26:6");
            softTag.Initialize();
            softTag.DPDSEnabled = true;
            FDADataPointDefinitionStructure.Datapoint lastread_before;
            foreach (UInt32 testVal in TestValues)
            {
                lastread_before = softTag.LastRead;
                // update the value in the source tag
                srcTag.LastRead = new FDADataPointDefinitionStructure.Datapoint(
                    testVal,
                    0,
                    DateTime.Now,
                    "",
                    datatype,
                    DataRequest.WriteMode.Insert);

                // soft tag should not have updated
                Assert.AreSame(lastread_before, softTag.LastRead);
            }
        }