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

Commit

Permalink
Merge pull request #316 from dnp3/feature/g51var2
Browse files Browse the repository at this point in the history
Support g51v2 (CTO Unsynchronized)
  • Loading branch information
emgre committed Jun 21, 2019
2 parents 7ec628f + 786fb80 commit d64940b
Show file tree
Hide file tree
Showing 55 changed files with 352 additions and 261 deletions.
9 changes: 4 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ jobs:
#- run: *init_submodules
- run:
name: Configure
command: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Werror -Wno-format-truncation" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON -DDNP3_COVERAGE=ON ..
command: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON -DDNP3_COVERAGE=ON ..
working_directory: build
- run: *build
- run: *test
- run: *coverage
#- run: *build_java
#- run: *test_java
#- run: *package
Expand All @@ -75,7 +74,7 @@ jobs:
#- run: *init_submodules
- run:
name: Configure
command: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Werror -Wno-format-truncation" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON ..
command: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror -Wno-unused-parameter -Wno-format-truncation" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON ..
working_directory: build
- run: *build
- run: *test
Expand All @@ -93,7 +92,7 @@ jobs:
#- run: *init_submodules
- run:
name: Configure
command: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Werror" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON ..
command: cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wno-unused-parameter -Werror" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON ..
working_directory: build
- run: *build
- run: *test
Expand All @@ -111,7 +110,7 @@ jobs:
#- run: *init_submodules
- run:
name: Configure
command: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Werror" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON ..
command: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wno-unused-parameter -Werror" -DDNP3_TLS=ON -DDNP3_TESTS=ON -DDNP3_EXAMPLES=ON ..
working_directory: build
- run: *build
- run: *test
Expand Down
60 changes: 35 additions & 25 deletions cpp/examples/outstation/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <opendnp3/DNP3Manager.h>
#include <opendnp3/LogLevels.h>
#include <opendnp3/channel/PrintingChannelListener.h>
#include <opendnp3/outstation/IUpdateHandler.h>
#include <opendnp3/outstation/SimpleCommandHandler.h>
#include <opendnp3/outstation/UpdateBuilder.h>

Expand All @@ -35,11 +34,11 @@ using namespace opendnp3;
DatabaseConfig ConfigureDatabase()
{
DatabaseConfig config(10); // 10 of each type

config.analog_input[0].clazz = PointClass::Class2;
config.analog_input[0].svariation = StaticAnalogVariation::Group30Var5;
config.analog_input[0].evariation = EventAnalogVariation::Group32Var7;

return config;
}

Expand All @@ -49,50 +48,69 @@ struct State
double value = 0;
bool binary = false;
DoubleBit dbit = DoubleBit::DETERMINED_OFF;
uint8_t octetStringValue = 1;
};

void AddUpdates(UpdateBuilder& builder, State& state, const std::string& arguments);

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

std::string caCertificate(argv[1]);
std::string certificateChain(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 private key file: " << privateKey << std::endl;

// Specify what log levels to use. NORMAL is warning and above
// You can add all the comms logging by uncommenting below.
const auto logLevels = levels::NORMAL | levels::ALL_COMMS;

// This is the main point of interaction with the stack
// Allocate a single thread to the pool since this is a single outstation
// Log messages to the console
DNP3Manager manager(1, ConsoleLogger::Create());

std::error_code ec;

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

if (ec)
{
std::cout << "Unable to create tls server: " << ec.message() << std::endl;
return ec.value();
}

// The main object for a outstation. The defaults are useable,
// but understanding the options are important.
OutstationStackConfig config(ConfigureDatabase());
OutstationStackConfig stackConfig(ConfigureDatabase());

// Specify the maximum size of the event buffers
config.outstation.eventBufferConfig = EventBufferConfig::AllTypes(10);
// specify the maximum size of the event buffers
stackConfig.outstation.eventBufferConfig = EventBufferConfig::AllTypes(10);

// you can override an default outstation parameters here
// in this example, we've enabled the oustation to use unsolicted reporting
// if the master enables it
config.outstation.params.allowUnsolicited = true;
stackConfig.outstation.params.allowUnsolicited = true;

// You can override the default link layer settings here
// in this example we've changed the default link layer addressing
config.link.LocalAddr = 10;
config.link.RemoteAddr = 1;
config.link.KeepAliveTimeout = TimeDuration::Max();
stackConfig.link.LocalAddr = 10;
stackConfig.link.RemoteAddr = 1;

// Create a new outstation with a log level, command handler, and
// config info this returns a thread-safe interface used for
// updating the outstation's database.
auto outstation = channel->AddOutstation("outstation", SuccessCommandHandler::Create(),
DefaultOutstationApplication::Create(), config);
DefaultOutstationApplication::Create(), stackConfig);

// Enable the outstation and start communications
outstation->Enable();
Expand All @@ -104,14 +122,13 @@ int main(int argc, char* argv[])
while (true)
{
std::cout << "Enter one or more measurement changes then press <enter>" << std::endl;
std::cout << "c = counter, b = binary, d = doublebit, a = analog, o = octet string, 'quit' = exit" << std::endl;
std::cout << "c = counter, b = binary, d = doublebit, a = analog, 'quit' = exit" << std::endl;
std::cin >> input;

if (input == "quit")
return 0; // DNP3Manager destructor cleanups up everything automatically
return 0;
else
{
// update measurement values based on input string
UpdateBuilder builder;
AddUpdates(builder, state, input);
outstation->Apply(builder.Build());
Expand Down Expand Up @@ -152,13 +169,6 @@ void AddUpdates(UpdateBuilder& builder, State& state, const std::string& argumen
= (state.dbit == DoubleBit::DETERMINED_OFF) ? DoubleBit::DETERMINED_ON : DoubleBit::DETERMINED_OFF;
break;
}
case ('o'):
{
OctetString value(Buffer(&state.octetStringValue, 1));
builder.Update(value, 0);
state.octetStringValue += 1;
break;
}
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ set(opendnp3_public_headers
./include/opendnp3/gen/StaticTypeBitmask.h
./include/opendnp3/gen/StopBits.h
./include/opendnp3/gen/TaskCompletion.h
./include/opendnp3/gen/TimestampMode.h
./include/opendnp3/gen/TimestampQuality.h
./include/opendnp3/gen/TimeSyncMode.h
./include/opendnp3/gen/UserOperation.h
./include/opendnp3/gen/UserRole.h
Expand Down Expand Up @@ -546,7 +546,7 @@ set(opendnp3_src
./src/gen/StaticTypeBitmask.cpp
./src/gen/StopBits.cpp
./src/gen/TaskCompletion.cpp
./src/gen/TimestampMode.cpp
./src/gen/TimestampQuality.cpp
./src/gen/TimeSyncMode.cpp
./src/gen/UserOperation.cpp
./src/gen/UserRole.cpp
Expand Down
11 changes: 8 additions & 3 deletions cpp/lib/include/opendnp3/app/DNPTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@
#ifndef OPENDNP3_DNPTIME_H
#define OPENDNP3_DNPTIME_H

#include "opendnp3/gen/TimestampQuality.h"

#include <cstdint>

namespace opendnp3
{

struct DNPTime
{
DNPTime() : value(0) {}
explicit DNPTime(uint64_t value) : value(value) {}
DNPTime() : value(0), quality(TimestampQuality::INVALID) {}
explicit DNPTime(uint64_t value) : value(value), quality(TimestampQuality::INVALID) {}
DNPTime(uint64_t value, TimestampQuality quality)
: value(value), quality(quality) {}

bool operator==(const DNPTime& rhs) const
{
return this->value == rhs.value;
return this->value == rhs.value && this->quality == rhs.quality;
}

uint64_t value;
TimestampQuality quality;
};

}
Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/include/opendnp3/app/Flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Flags
public:
Flags() : value(0) {}

Flags(uint8_t value) : value(value) {}
explicit Flags(uint8_t value) : value(value) {}

inline bool IsSet(BinaryQuality flag) const
{
Expand Down
4 changes: 2 additions & 2 deletions cpp/lib/include/opendnp3/app/IINField.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace opendnp3

enum class IINBit
{
ALL_STATIONS = 0,
BROADCAST = 0,
CLASS1_EVENTS,
CLASS2_EVENTS,
CLASS3_EVENTS,
Expand All @@ -53,7 +53,7 @@ class IINField
private:
enum class LSBMask : uint8_t
{
ALL_STATIONS = 0x01,
BROADCAST = 0x01,
CLASS1_EVENTS = 0x02,
CLASS2_EVENTS = 0x04,
CLASS3_EVENTS = 0x08,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
// limitations under the License.
//

#ifndef OPENDNP3_TIMESTAMPMODE_H
#define OPENDNP3_TIMESTAMPMODE_H
#ifndef OPENDNP3_TIMESTAMPQUALITY_H
#define OPENDNP3_TIMESTAMPQUALITY_H

#include <cstdint>
#include <string>

namespace opendnp3 {

/**
Indicates the validity of timestamp values for an entire object header
Indicates the quality of timestamp values
*/
enum class TimestampMode : uint8_t
enum class TimestampQuality : uint8_t
{
/// The timestamp is UTC synchronized at the remote device
SYNCHRONIZED = 1,
Expand All @@ -50,15 +50,15 @@ enum class TimestampMode : uint8_t
INVALID = 0
};

struct TimestampModeSpec
struct TimestampQualitySpec
{
using enum_type_t = TimestampMode;
using enum_type_t = TimestampQuality;

static uint8_t to_type(TimestampMode arg);
static TimestampMode from_type(uint8_t arg);
static char const* to_string(TimestampMode arg);
static char const* to_human_string(TimestampMode arg);
static TimestampMode from_string(const std::string& arg);
static uint8_t to_type(TimestampQuality arg);
static TimestampQuality from_type(uint8_t arg);
static char const* to_string(TimestampQuality arg);
static char const* to_human_string(TimestampQuality arg);
static TimestampQuality from_string(const std::string& arg);
};

}
Expand Down
10 changes: 5 additions & 5 deletions cpp/lib/include/opendnp3/master/HeaderInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "opendnp3/gen/Attributes.h"
#include "opendnp3/gen/GroupVariation.h"
#include "opendnp3/gen/QualifierCode.h"
#include "opendnp3/gen/TimestampMode.h"
#include "opendnp3/gen/TimestampQuality.h"

namespace opendnp3
{
Expand All @@ -38,17 +38,17 @@ class HeaderInfo
HeaderInfo()
: gv(GroupVariation::UNKNOWN),
qualifier(QualifierCode::UNDEFINED),
tsmode(TimestampMode::INVALID),
tsquality(TimestampQuality::INVALID),
isEventVariation(false),
flagsValid(false),
headerIndex(0)
{
}

HeaderInfo(GroupVariation gv_, QualifierCode qualifier_, TimestampMode tsmode_, uint32_t headerIndex_)
HeaderInfo(GroupVariation gv_, QualifierCode qualifier_, TimestampQuality tsquality_, uint32_t headerIndex_)
: gv(gv_),
qualifier(qualifier_),
tsmode(tsmode_),
tsquality(tsquality_),
isEventVariation(IsEvent(gv_)),
flagsValid(HasFlags(gv_)),
headerIndex(headerIndex_)
Expand All @@ -60,7 +60,7 @@ class HeaderInfo
/// The qualifier code enumeration for the header
QualifierCode qualifier;
/// Enumeration that provides information about the validity of timestamps on the associated objects
TimestampMode tsmode;
TimestampQuality tsquality;
/// True if the specfied variation is an event variation
bool isEventVariation;
/// True if the flags on the value were present on underlying type, false if online is just assumed
Expand Down
8 changes: 4 additions & 4 deletions cpp/lib/include/opendnp3/master/PrintingSOEHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ class PrintingSOEHandler final : public ISOEHandler
return oss.str();
}

static std::string GetTimeString(TimestampMode tsmode)
static std::string GetTimeString(TimestampQuality tsquality)
{
std::ostringstream oss;
switch (tsmode)
switch (tsquality)
{
case (TimestampMode::SYNCHRONIZED):
case (TimestampQuality::SYNCHRONIZED):
return "synchronized";
break;
case (TimestampMode::UNSYNCHRONIZED):
case (TimestampQuality::UNSYNCHRONIZED):
oss << "unsynchronized";
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/src/app/BinaryCommandEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ BinaryCommandEvent::BinaryCommandEvent(bool value, CommandStatus status, DNPTime

Flags BinaryCommandEvent::GetFlags() const
{
return (static_cast<uint8_t>(value) << 7) | (CommandStatusSpec::to_type(status));
return Flags((static_cast<uint8_t>(value) << 7) | (CommandStatusSpec::to_type(status)));
}

bool BinaryCommandEvent::operator==(const BinaryCommandEvent& rhs) const
Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/src/app/GroupVariationRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "opendnp3/util/Uncopyable.h"
#include "opendnp3/gen/GroupVariation.h"
#include "opendnp3/gen/QualifierCode.h"
#include "opendnp3/gen/TimestampMode.h"
#include "opendnp3/gen/TimestampQuality.h"

#include <cstdint>

Expand Down

0 comments on commit d64940b

Please sign in to comment.