Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Fix EventOnly behaviour #385

Merged
merged 3 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/examples/outstation/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace opendnp3;
DatabaseConfig ConfigureDatabase()
{
DatabaseConfig config(10); // 10 of each type with default settings

config.analog_input[0].clazz = PointClass::Class2;
config.analog_input[0].svariation = StaticAnalogVariation::Group30Var5;
config.analog_input[0].evariation = EventAnalogVariation::Group32Var7;
Expand Down Expand Up @@ -73,7 +73,7 @@ int main(int argc, char* argv[])
auto channel = std::shared_ptr<IChannel>(nullptr);
try
{
channel = manager.AddTCPServer("server", logLevels, ServerAcceptMode::CloseExisting, IPEndpoint("asdf", 20000),
channel = manager.AddTCPServer("server", logLevels, ServerAcceptMode::CloseExisting, IPEndpoint("0.0.0.0", 20000),
PrintingChannelListener::Create());
}
catch(const std::exception& e)
Expand Down
10 changes: 6 additions & 4 deletions cpp/examples/tls/master/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ using namespace opendnp3;

int main(int argc, char* argv[])
{
if (argc != 3)
if (argc != 4)
{
std::cout << "usage: master-tls-demo <peer certificate> <private key/certificate>" << std::endl;
std::cout << "usage: master-tls-demo <peer certificate> <local certificate> <private key>" << std::endl;
return -1;
}

std::string peerCertificate(argv[1]);
std::string privateKey(argv[2]);
std::string localCertificate(argv[2]);
std::string privateKey(argv[3]);

std::cout << "Using peer cert: " << peerCertificate << std::endl;
std::cout << "Using local cert: " << localCertificate << std::endl;
std::cout << "Using private key file: " << privateKey << std::endl;

// Specify what log levels to use. NORMAL is warning and above
Expand All @@ -54,7 +56,7 @@ int main(int argc, char* argv[])
// Connect via a TCPClient socket to a outstation
auto channel = manager.AddTLSClient(
"tls-client", logLevels, ChannelRetry::Default(), {IPEndpoint("127.0.0.1", 20001)}, "0.0.0.0",
TLSConfig(peerCertificate, privateKey, privateKey), PrintingChannelListener::Create());
TLSConfig(peerCertificate, localCertificate, privateKey), PrintingChannelListener::Create());

// The master config object for a master. The default are
// useable, but understanding the options are important.
Expand Down
12 changes: 6 additions & 6 deletions cpp/examples/tls/outstation/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ int main(int argc, char* argv[])
{
if (argc != 4)
{
std::cout << "usage: master-gprs-tls-demo <ca certificate> <certificate chain> <private key>" << std::endl;
std::cout << "usage: master-gprs-tls-demo <peer certificate> <local certificate chain> <private key>" << std::endl;
return -1;
}

std::string caCertificate(argv[1]);
std::string certificateChain(argv[2]);
std::string peerCertificate(argv[1]);
std::string localCertificate(argv[2]);
std::string privateKey(argv[3]);

std::cout << "Using CA certificate: " << caCertificate << std::endl;
std::cout << "Using certificate chain: " << certificateChain << std::endl;
std::cout << "Using peer certificate: " << peerCertificate << std::endl;
std::cout << "Using local certificate: " << localCertificate << std::endl;
std::cout << "Using private key file: " << privateKey << std::endl;

// Specify what log levels to use. NORMAL is warning and above
Expand All @@ -79,7 +79,7 @@ int main(int argc, char* argv[])

// Create a TCP server (listener)
auto channel = manager.AddTLSServer("server", logLevels, ServerAcceptMode::CloseExisting, IPEndpoint("0.0.0.0", 20001),
TLSConfig(caCertificate, certificateChain, privateKey),
TLSConfig(peerCertificate, localCertificate, privateKey),
PrintingChannelListener::Create());

// The main object for a outstation. The defaults are useable,
Expand Down
3 changes: 2 additions & 1 deletion cpp/lib/include/opendnp3/gen/EventMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ enum class EventMode : uint8_t
Force = 0x1,
/// Never produce an event regardless of changes
Suppress = 0x2,
/// Send an event directly to the event buffer, bypassing the static value completely
/// Force the creation of an event bypassing detection mechanism, but does not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update this comment via the code generator. It will also update java/.net

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ My bad

/// update the static value
EventOnly = 0x3
};

Expand Down
4 changes: 1 addition & 3 deletions cpp/lib/src/outstation/StaticDataMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ template<class Spec> class StaticDataMap : private Uncopyable

iterator end();

iterator find(uint16_t index);

private:
map_t map;
Range selected;
Expand Down Expand Up @@ -252,7 +250,7 @@ bool StaticDataMap<Spec>::update(const map_iter_t& iter,
iter->second.value = new_value;
}

if (mode == EventMode::Force || Spec::IsEvent(iter->second.event.lastEvent, new_value, iter->second.config))
if (mode == EventMode::Force || mode == EventMode::EventOnly || Spec::IsEvent(iter->second.event.lastEvent, new_value, iter->second.config))
{
iter->second.event.lastEvent = new_value;
if (mode != EventMode::Suppress)
Expand Down
37 changes: 37 additions & 0 deletions cpp/tests/unit/TestStaticDataMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ TEST_CASE(SUITE("can only add points that aren't already defined"))
TEST_CASE(SUITE("can detect events on existing point"))
{
StaticDataMap<BinarySpec> map{{{0, {}}}};
map.select_all();

EventReceiver receiver;
REQUIRE(map.update(Binary(true), 0, EventMode::Detect, receiver));
Expand All @@ -96,6 +97,42 @@ TEST_CASE(SUITE("can detect events on existing point"))
REQUIRE(receiver.count == 1);
}

TEST_CASE(SUITE("can force events on existing point"))
{
StaticDataMap<BinarySpec> map{{{0, {}}}};
map.select_all();

EventReceiver receiver;
REQUIRE(map.update(Binary(true), 0, EventMode::Force, receiver));
REQUIRE(receiver.count == 1);
REQUIRE(map.update(Binary(true), 0, EventMode::Force, receiver));
REQUIRE(receiver.count == 2);
}

TEST_CASE(SUITE("can ignore events on existing point"))
{
StaticDataMap<BinarySpec> map{{{0, {}}}};
map.select_all();

EventReceiver receiver;
REQUIRE(map.update(Binary(true), 0, EventMode::Suppress, receiver));
REQUIRE(receiver.count == 0);
REQUIRE(map.update(Binary(true), 0, EventMode::Suppress, receiver));
REQUIRE(receiver.count == 0);
}

TEST_CASE(SUITE("can generate events on existing point"))
{
StaticDataMap<BinarySpec> map{{{0, {}}}};
map.select_all();

EventReceiver receiver;
REQUIRE(map.update(Binary(true), 0, EventMode::EventOnly, receiver));
REQUIRE(receiver.count == 1);
REQUIRE(map.update(Binary(true), 0, EventMode::EventOnly, receiver));
REQUIRE(receiver.count == 2);
}

TEST_CASE(SUITE("can select all points using default variation and iterate"))
{
StaticDataMap<BinarySpec> map{{
Expand Down