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); } }
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); } }