Skip to content

Commit

Permalink
Master no longer wall timestamps measurements. Time == 0 implies ther…
Browse files Browse the repository at this point in the history
…e was no device time
  • Loading branch information
jadamcrain committed Aug 12, 2010
1 parent f8f769f commit 558b0d2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 70 deletions.
7 changes: 3 additions & 4 deletions DNP3/AsyncMaster.cpp
Expand Up @@ -311,11 +311,10 @@ void AsyncMaster::OnUnsolResponse(const APDU& arAPDU)
void AsyncMaster::ProcessDataResponse(const APDU& arResponse)
{
try {
ResponseLoader loader(mpLogger, mpTimeSrc->GetTimeStampUTC(), mpPublisher);
ResponseLoader loader(mpLogger, mpPublisher);

for(HeaderReadIterator hdr = arResponse.BeginRead(); !hdr.IsEnd(); ++hdr) {
loader.Process(hdr);
}
for(HeaderReadIterator hdr = arResponse.BeginRead(); !hdr.IsEnd(); ++hdr)
loader.Process(hdr);
}
catch(Exception ex)
{
Expand Down
3 changes: 1 addition & 2 deletions DNP3/ObjectInterfaces.h
Expand Up @@ -97,8 +97,7 @@ namespace apl { namespace dnp {
public:
virtual void Write(apl::byte_t*, const T&) const = 0;
virtual T Read(const apl::byte_t*) const = 0;

virtual bool HasTime() const { return false; }

virtual bool HasQuality() const { return false; }

typedef T DataType;
Expand Down
5 changes: 2 additions & 3 deletions DNP3/ResponseLoader.cpp
Expand Up @@ -25,11 +25,10 @@

namespace apl { namespace dnp {

ResponseLoader::ResponseLoader(Logger* apLogger, TimeStamp_t aTime, IDataObserver* apPublisher) :
ResponseLoader::ResponseLoader(Logger* apLogger, IDataObserver* apPublisher) :
Loggable(apLogger),
mpPublisher(apPublisher),
mTransaction(apPublisher),
mTime(aTime)
mTransaction(apPublisher)
{

}
Expand Down
21 changes: 8 additions & 13 deletions DNP3/ResponseLoader.h
Expand Up @@ -38,7 +38,7 @@ class IVTODataSink;
class ResponseLoader : Loggable
{
public:
ResponseLoader(Logger*, TimeStamp_t, IDataObserver*);
ResponseLoader(Logger*, IDataObserver*);

void Process(HeaderReadIterator&);

Expand All @@ -56,8 +56,7 @@ class ResponseLoader : Loggable
void ReadBitfield(HeaderReadIterator& arHeader);

IDataObserver* mpPublisher;
Transaction mTransaction;
TimeStamp_t mTime;
Transaction mTransaction;
CTOHistory mCTO;
};

Expand Down Expand Up @@ -87,19 +86,15 @@ void ResponseLoader::Read(HeaderReadIterator& arIter, StreamObject<T>* apObj)

ObjectReadIterator obj = arIter.BeginRead();
LOG_BLOCK(LEV_INTERPRET, "Converting " << obj.Count() << " " << apObj->Name() << " To " << typeid(T).name());
for(; !obj.IsEnd(); ++obj)
{

for( ; !obj.IsEnd(); ++obj) {
size_t index = obj->Index();
T value = apObj->Read(*obj);

//Make sure the value has time information
// Make sure the value has time information
if(apObj->UseCTO()) value.SetTime(t+value.GetTime());
else if(!apObj->HasTime())
{
value.SetTime(mTime);
}

//Make sure the value has quality information

// Make sure the value has quality information
if(!apObj->HasQuality()) value.SetQuality(T::ONLINE);

mpPublisher->Update(value, index);
Expand All @@ -109,7 +104,7 @@ void ResponseLoader::Read(HeaderReadIterator& arIter, StreamObject<T>* apObj)
template <class T>
void ResponseLoader::ReadBitfield(HeaderReadIterator& arIter)
{
Binary b; b.SetQuality(Binary::ONLINE); b.SetTime(mTime);
Binary b; b.SetQuality(Binary::ONLINE);

ObjectReadIterator obj = arIter.BeginRead();
LOG_BLOCK(LEV_INTERPRET, "Converting " << obj.Count() << " " << T::Inst()->Name() << " To " << typeid(b).name());
Expand Down
38 changes: 19 additions & 19 deletions DNP3Test/ResponseLoaderTestObject.cpp
Expand Up @@ -35,64 +35,64 @@ mpLogger(log.GetLogger(LEV_INFO, "rsp"))

}

void ResponseLoaderTestObject::Load(const std::string& arAPDU, TimeStamp_t aTime)
void ResponseLoaderTestObject::Load(const std::string& arAPDU)
{
fdo.Clear();
HexSequence hs(arAPDU);
APDU f;
f.Write(hs, hs.Size());
f.Interpret();

ResponseLoader rl(mpLogger, aTime, &fdo);
ResponseLoader rl(mpLogger, &fdo);
for(HeaderReadIterator hdr = f.BeginRead(); !hdr.IsEnd(); ++hdr)
{
rl.Process(hdr);
}
}

void ResponseLoaderTestObject::CheckBinaries(const std::string& arAPDU, TimeStamp_t aTime)
void ResponseLoaderTestObject::CheckBinaries(const std::string& arAPDU)
{
this->Load(arAPDU, aTime);
this->Load(arAPDU);

BOOST_REQUIRE_EQUAL(fdo.mBinaryMap.size(), 3);
BOOST_REQUIRE_EQUAL(fdo.GetTotalCount(), 3);

BOOST_REQUIRE(fdo.Check(false, BQ_ONLINE, 1, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(true, BQ_ONLINE, 2, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(false, BQ_ONLINE, 3, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(false, BQ_ONLINE, 1, TimeStamp_t(0)));
BOOST_REQUIRE(fdo.Check(true, BQ_ONLINE, 2, TimeStamp_t(0)));
BOOST_REQUIRE(fdo.Check(false, BQ_ONLINE, 3, TimeStamp_t(0)));
}

void ResponseLoaderTestObject::CheckCounters(const std::string& arAPDU, TimeStamp_t aTime)
void ResponseLoaderTestObject::CheckCounters(const std::string& arAPDU)
{
this->Load(arAPDU, aTime);
this->Load(arAPDU);

BOOST_REQUIRE_EQUAL(fdo.mCounterMap.size(), 2);
BOOST_REQUIRE_EQUAL(fdo.GetTotalCount(), 2);

BOOST_REQUIRE(fdo.Check(4, CQ_ONLINE, 0, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(9, CQ_ONLINE, 1, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(4, CQ_ONLINE, 0, TimeStamp_t(0)));
BOOST_REQUIRE(fdo.Check(9, CQ_ONLINE, 1, TimeStamp_t(0)));
}

void ResponseLoaderTestObject::CheckAnalogs(const std::string& arAPDU, TimeStamp_t aTime)
void ResponseLoaderTestObject::CheckAnalogs(const std::string& arAPDU)
{
this->Load(arAPDU, aTime);
this->Load(arAPDU);

BOOST_REQUIRE_EQUAL(fdo.mAnalogMap.size(), 2);
BOOST_REQUIRE_EQUAL(fdo.GetTotalCount(), 2);

BOOST_REQUIRE(fdo.Check(4, AQ_ONLINE, 0, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(9, AQ_ONLINE, 1, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(4, AQ_ONLINE, 0, TimeStamp_t(0)));
BOOST_REQUIRE(fdo.Check(9, AQ_ONLINE, 1, TimeStamp_t(0)));
}

void ResponseLoaderTestObject::CheckSetpointStatii(const std::string& arAPDU, TimeStamp_t aTime)
void ResponseLoaderTestObject::CheckSetpointStatii(const std::string& arAPDU)
{
this->Load(arAPDU, aTime);
this->Load(arAPDU);

BOOST_REQUIRE_EQUAL(fdo.mSetpointStatusMap.size(), 2);
BOOST_REQUIRE_EQUAL(fdo.GetTotalCount(), 2);

BOOST_REQUIRE(fdo.Check(4, PQ_ONLINE, 0, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(9, PQ_ONLINE, 1, TimeStamp_t(20)));
BOOST_REQUIRE(fdo.Check(4, PQ_ONLINE, 0));
BOOST_REQUIRE(fdo.Check(9, PQ_ONLINE, 1));
}

}}
10 changes: 5 additions & 5 deletions DNP3Test/ResponseLoaderTestObject.h
Expand Up @@ -34,12 +34,12 @@ class ResponseLoaderTestObject
public:
ResponseLoaderTestObject();

void CheckBinaries(const std::string& arAPDU, TimeStamp_t aTime = TimeStamp_t(0));
void CheckCounters(const std::string& arAPDU, TimeStamp_t aTime = TimeStamp_t(0));
void CheckAnalogs(const std::string& arAPDU, TimeStamp_t aTime = TimeStamp_t(0));
void CheckSetpointStatii(const std::string& arAPDU, TimeStamp_t aTime = TimeStamp_t(0));
void CheckBinaries(const std::string& arAPDU);
void CheckCounters(const std::string& arAPDU);
void CheckAnalogs(const std::string& arAPDU);
void CheckSetpointStatii(const std::string& arAPDU);

void Load(const std::string& arAPDU, TimeStamp_t aTime);
void Load(const std::string& arAPDU);

private: EventLog log;
public: FlexibleDataObserver fdo;
Expand Down
9 changes: 3 additions & 6 deletions DNP3Test/TestAsyncMaster.cpp
Expand Up @@ -482,8 +482,7 @@ using namespace boost;
BOOST_AUTO_TEST_CASE(SolicitedResponseWithData)
{
MasterConfig master_cfg;
AsyncMasterTestObject t(master_cfg);
t.fake_time.SetTime(TimeStamp_t(0));
AsyncMasterTestObject t(master_cfg);
t.master.OnLowerLayerUp();

BOOST_REQUIRE_EQUAL(t.Read(), "C0 01 3C 01 06"); ;
Expand Down Expand Up @@ -522,8 +521,7 @@ using namespace boost;
BOOST_AUTO_TEST_CASE(SolicitedMultiFragResponse)
{
MasterConfig master_cfg;
AsyncMasterTestObject t(master_cfg);
t.fake_time.SetTime(TimeStamp_t(0));
AsyncMasterTestObject t(master_cfg);
t.master.OnLowerLayerUp();

BOOST_REQUIRE_EQUAL(t.Read(), "C0 01 3C 01 06");
Expand All @@ -544,8 +542,7 @@ using namespace boost;
master_cfg.mScans.push_back(scan);
scan.ClassMask = PC_CLASS_3;
master_cfg.mScans.push_back(scan);
AsyncMasterTestObject t(master_cfg);
t.fake_time.SetTime(TimeStamp_t(0));
AsyncMasterTestObject t(master_cfg);
t.master.OnLowerLayerUp();

BOOST_REQUIRE_EQUAL(t.Read(), "C0 01 3C 01 06");
Expand Down
2 changes: 1 addition & 1 deletion DNP3Test/TestAsyncSlave.cpp
Expand Up @@ -1076,7 +1076,7 @@ BOOST_AUTO_TEST_SUITE(AsyncSlaveSuite)

{
Transaction tr(&t.db);
t.db.Update(Binary(false, BQ_ONLINE), 0);
t.db.Update(Binary(false, BQ_ONLINE), 0);
t.db.Update(Counter(0, CQ_ONLINE), 0);
t.db.Update(Analog(0.0, AQ_ONLINE), 0);
t.db.Update(ControlStatus(false, TQ_ONLINE), 0);
Expand Down
34 changes: 17 additions & 17 deletions DNP3Test/TestResponseLoader.cpp
Expand Up @@ -31,91 +31,91 @@ using namespace boost;
BOOST_AUTO_TEST_CASE(Group1Var1)
{
ResponseLoaderTestObject t;
t.CheckBinaries("C0 81 00 00 01 01 00 01 03 02", TimeStamp_t(20));
t.CheckBinaries("C0 81 00 00 01 01 00 01 03 02");
}

BOOST_AUTO_TEST_CASE(Group1Var2)
{
ResponseLoaderTestObject t;
t.CheckBinaries("C0 81 00 00 01 02 00 01 03 01 81 01", TimeStamp_t(20));
t.CheckBinaries("C0 81 00 00 01 02 00 01 03 01 81 01");
}

BOOST_AUTO_TEST_CASE(Group20Var1)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 01 00 00 01 01 04 00 00 00 01 09 00 00 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 01 00 00 01 01 04 00 00 00 01 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group20Var2)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 02 00 00 01 01 04 00 01 09 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 02 00 00 01 01 04 00 01 09 00");
}

BOOST_AUTO_TEST_CASE(Group20Var3)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 03 00 00 01 01 04 00 00 00 01 09 00 00 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 03 00 00 01 01 04 00 00 00 01 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group20Var4)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 04 00 00 01 01 04 00 01 09 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 04 00 00 01 01 04 00 01 09 00");
}

BOOST_AUTO_TEST_CASE(Group20Var5)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 05 00 00 01 04 00 00 00 09 00 00 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 05 00 00 01 04 00 00 00 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group20Var6)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 06 00 00 01 04 00 09 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 06 00 00 01 04 00 09 00");
}

BOOST_AUTO_TEST_CASE(Group20Var7)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 07 00 00 01 04 00 00 00 09 00 00 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 07 00 00 01 04 00 00 00 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group20Var8)
{
ResponseLoaderTestObject t;
t.CheckCounters("C0 81 00 00 14 08 00 00 01 04 00 09 00", TimeStamp_t(20));
t.CheckCounters("C0 81 00 00 14 08 00 00 01 04 00 09 00");
}

BOOST_AUTO_TEST_CASE(Group30Var1)
{
ResponseLoaderTestObject t;
t.CheckAnalogs("C0 81 00 00 1E 01 00 00 01 01 04 00 00 00 01 09 00 00 00", TimeStamp_t(20));
t.CheckAnalogs("C0 81 00 00 1E 01 00 00 01 01 04 00 00 00 01 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group30Var2)
{
ResponseLoaderTestObject t;
t.CheckAnalogs("C0 81 00 00 1E 02 00 00 01 01 04 00 01 09 00", TimeStamp_t(20));
t.CheckAnalogs("C0 81 00 00 1E 02 00 00 01 01 04 00 01 09 00");
}

BOOST_AUTO_TEST_CASE(Group30Var3)
{
ResponseLoaderTestObject t;
t.CheckAnalogs("C0 81 00 00 1E 03 00 00 01 04 00 00 00 09 00 00 00", TimeStamp_t(20));
t.CheckAnalogs("C0 81 00 00 1E 03 00 00 01 04 00 00 00 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group30Var4)
{
ResponseLoaderTestObject t;
t.CheckAnalogs("C0 81 00 00 1E 04 00 00 01 04 00 09 00", TimeStamp_t(20));
t.CheckAnalogs("C0 81 00 00 1E 04 00 00 01 04 00 09 00");
}

BOOST_AUTO_TEST_CASE(Group30Var6)
{
ResponseLoaderTestObject t;
t.Load("C0 81 00 00 1E 06 00 00 00 01 20 74 85 2F C7 2B A2 C0", TimeStamp_t(20));
t.Load("C0 81 00 00 1E 06 00 00 00 01 20 74 85 2F C7 2B A2 C0");

BOOST_REQUIRE_EQUAL(t.fdo.mAnalogMap.size(), 1);
BOOST_REQUIRE_EQUAL(t.fdo.GetTotalCount(), 1);
Expand All @@ -124,13 +124,13 @@ using namespace boost;
BOOST_AUTO_TEST_CASE(Group40Var1)
{
ResponseLoaderTestObject t;
t.CheckSetpointStatii("C0 81 00 00 28 01 00 00 01 01 04 00 00 00 01 09 00 00 00", TimeStamp_t(20));
t.CheckSetpointStatii("C0 81 00 00 28 01 00 00 01 01 04 00 00 00 01 09 00 00 00");
}

BOOST_AUTO_TEST_CASE(Group40Var2)
{
ResponseLoaderTestObject t;
t.CheckSetpointStatii("C0 81 00 00 28 02 00 00 01 01 04 00 01 09 00", TimeStamp_t(20));
t.CheckSetpointStatii("C0 81 00 00 28 02 00 00 01 01 04 00 01 09 00");
}

BOOST_AUTO_TEST_SUITE_END() //end suite
Expand Down

0 comments on commit 558b0d2

Please sign in to comment.