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 #298 from dnp3/feature/soehandler
Browse files Browse the repository at this point in the history
extend ISOEHandler
  • Loading branch information
jadamcrain committed Jun 7, 2019
2 parents a57b523 + ea401bb commit cf4b1c6
Show file tree
Hide file tree
Showing 25 changed files with 274 additions and 245 deletions.
22 changes: 11 additions & 11 deletions cpp/examples/master-gprs/ExampleListenCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class ExampleSOEHandler : public ISOEHandler
public:
explicit ExampleSOEHandler(const uint16_t address) : address(address) {}

void begin_fragment(const ResponseInfo& info) override
{
std::cout << "Begin receiving measurement data for outstation: " << address << std::endl;
}

void end_fragment(const ResponseInfo& info) override
{
std::cout << "End receiving measurement data for outstation: " << address << std::endl;
}

void Process(const HeaderInfo& info,
const ICollection<Indexed<Binary>>& values) override
{
Expand Down Expand Up @@ -103,17 +113,7 @@ class ExampleSOEHandler : public ISOEHandler
void Process(const HeaderInfo& info, const ICollection<DNPTime>& values) override {}

protected:
const uint16_t address;

void Start() override
{
std::cout << "Begin receiving measurement data for outstation: " << address << std::endl;
}

void End() override
{
std::cout << "End receiving measurement data for outstation: " << address << std::endl;
}
const uint16_t address;
};

std::shared_ptr<IMasterSession> ExampleListenCallbacks::get_outstation_session(uint16_t address)
Expand Down
4 changes: 2 additions & 2 deletions cpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ set(opendnp3_public_headers
./include/opendnp3/app/Flags.h
./include/opendnp3/app/GroupVariationID.h
./include/opendnp3/app/IINField.h
./include/opendnp3/app/Indexed.h
./include/opendnp3/app/ITransactable.h
./include/opendnp3/app/Indexed.h
./include/opendnp3/app/MeasurementInfo.h
./include/opendnp3/app/MeasurementTypes.h
./include/opendnp3/app/OctetData.h
Expand Down Expand Up @@ -141,6 +140,7 @@ set(opendnp3_public_headers
./include/opendnp3/master/IUTCTimeSource.h
./include/opendnp3/master/MasterParams.h
./include/opendnp3/master/PrintingSOEHandler.h
./include/opendnp3/master/ResponseInfo.h
./include/opendnp3/master/RestartOperationResult.h
./include/opendnp3/master/TaskConfig.h
./include/opendnp3/master/TaskId.h
Expand Down
97 changes: 0 additions & 97 deletions cpp/lib/include/opendnp3/app/ITransactable.h

This file was deleted.

17 changes: 11 additions & 6 deletions cpp/lib/include/opendnp3/master/ISOEHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@

#include "opendnp3/app/AnalogCommandEvent.h"
#include "opendnp3/app/BinaryCommandEvent.h"
#include "opendnp3/app/ITransactable.h"
#include "opendnp3/app/Indexed.h"
#include "opendnp3/app/MeasurementTypes.h"
#include "opendnp3/app/OctetString.h"
#include "opendnp3/app/SecurityStat.h"
#include "opendnp3/app/parsing/ICollection.h"
#include "opendnp3/master/HeaderInfo.h"
#include "opendnp3/master/ResponseInfo.h"

namespace opendnp3
{


/**
* An interface for Sequence-Of-Events (SOE) callbacks from a master stack to
* the application layer.
Expand All @@ -41,9 +42,15 @@ namespace opendnp3
* The HeaderInfo class provides information about the object header associated with the value.
*
*/
class ISOEHandler : public ITransactable
{
class ISOEHandler
{

public:
virtual ~ISOEHandler() = default;

virtual void begin_fragment(const ResponseInfo& info) = 0;
virtual void end_fragment(const ResponseInfo& info) = 0;

virtual void Process(const HeaderInfo& info, const ICollection<Indexed<Binary>>& values) = 0;
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<DoubleBitBinary>>& values) = 0;
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<Analog>>& values) = 0;
Expand All @@ -56,9 +63,7 @@ class ISOEHandler : public ITransactable
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<BinaryCommandEvent>>& values) = 0;
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<AnalogCommandEvent>>& values) = 0;
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<SecurityStat>>& values) = 0;
virtual void Process(const HeaderInfo& info, const ICollection<DNPTime>& values) = 0;

virtual ~ISOEHandler() {}
virtual void Process(const HeaderInfo& info, const ICollection<DNPTime>& values) = 0;
};

} // namespace opendnp3
Expand Down
7 changes: 3 additions & 4 deletions cpp/lib/include/opendnp3/master/PrintingSOEHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class PrintingSOEHandler final : public ISOEHandler
return std::make_shared<PrintingSOEHandler>();
}

void begin_fragment(const ResponseInfo& info) override;
void end_fragment(const ResponseInfo& info) override;

virtual void Process(const HeaderInfo& info, const ICollection<Indexed<Binary>>& values) override;
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<DoubleBitBinary>>& values) override;
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<Analog>>& values) override;
Expand All @@ -57,10 +60,6 @@ class PrintingSOEHandler final : public ISOEHandler
virtual void Process(const HeaderInfo& info, const ICollection<Indexed<SecurityStat>>& values) override;
virtual void Process(const HeaderInfo& info, const ICollection<DNPTime>& values) override;

protected:
void Start() final {}
void End() final {}

private:
template<class T> static void PrintAll(const HeaderInfo& info, const ICollection<Indexed<T>>& values)
{
Expand Down
43 changes: 43 additions & 0 deletions cpp/lib/include/opendnp3/master/ResponseInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2013-2019 Automatak, LLC
*
* Licensed to Green Energy Corp (www.greenenergycorp.com) and Automatak
* LLC (www.automatak.com) under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Green Energy Corp and Automatak LLC license
* this file to you under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may obtain
* a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OPENDNP3_RESPONSEINFO_H
#define OPENDNP3_RESPONSEINFO_H

namespace opendnp3
{

/**
* provides basic information about an APDU response
*/
struct ResponseInfo
{
ResponseInfo(bool unsolicited, bool fir, bool fin) : unsolicited(unsolicited), fir(fir), fin(fin) {}

// true if the response is unsolicited
bool unsolicited;
// true if this is the first fragment in a multi-fragment response
bool fir;
// true if this is the final fragment in a multi-fragment response
bool fin;
};

} // namespace opendnp3

#endif
15 changes: 12 additions & 3 deletions cpp/lib/include/opendnp3/outstation/ICommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "opendnp3/app/AnalogOutput.h"
#include "opendnp3/app/ControlRelayOutputBlock.h"
#include "opendnp3/app/ITransactable.h"
#include "opendnp3/gen/OperateType.h"

namespace opendnp3
Expand All @@ -34,10 +33,20 @@ namespace opendnp3
*
* The ITransactable sub-interface is used to determine the start and end of an ASDU containing commands.
*/
class ICommandHandler : public ITransactable
class ICommandHandler
{
public:
virtual ~ICommandHandler() {}
virtual ~ICommandHandler() = default;

/**
* called when a command APDU begins processing
*/
virtual void begin() = 0;

/**
* called when a command APDU ends processing
*/
virtual void end() = 0;

/**
* Ask if the application supports a ControlRelayOutputBlock - group 12 variation 1
Expand Down
26 changes: 13 additions & 13 deletions cpp/lib/include/opendnp3/outstation/SimpleCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ class SimpleCommandHandler : public ICommandHandler
*/
SimpleCommandHandler(CommandStatus status);

CommandStatus Select(const ControlRelayOutputBlock& command, uint16_t index) override final;
CommandStatus Operate(const ControlRelayOutputBlock& command, uint16_t index, OperateType opType) override final;
virtual void begin() override;
virtual void end() override;

CommandStatus Select(const AnalogOutputInt16& command, uint16_t index) override final;
CommandStatus Operate(const AnalogOutputInt16& command, uint16_t index, OperateType opType) override final;
CommandStatus Select(const ControlRelayOutputBlock& command, uint16_t index) override;
CommandStatus Operate(const ControlRelayOutputBlock& command, uint16_t index, OperateType opType) override;

CommandStatus Select(const AnalogOutputInt32& command, uint16_t index) override final;
CommandStatus Operate(const AnalogOutputInt32& command, uint16_t index, OperateType opType) override final;
CommandStatus Select(const AnalogOutputInt16& command, uint16_t index) override;
CommandStatus Operate(const AnalogOutputInt16& command, uint16_t index, OperateType opType) override;

CommandStatus Select(const AnalogOutputFloat32& command, uint16_t index) override final;
CommandStatus Operate(const AnalogOutputFloat32& command, uint16_t index, OperateType opType) override final;
CommandStatus Select(const AnalogOutputInt32& command, uint16_t index) override;
CommandStatus Operate(const AnalogOutputInt32& command, uint16_t index, OperateType opType) override;

CommandStatus Select(const AnalogOutputDouble64& command, uint16_t index) override final;
CommandStatus Operate(const AnalogOutputDouble64& command, uint16_t index, OperateType opType) override final;
CommandStatus Select(const AnalogOutputFloat32& command, uint16_t index) override;
CommandStatus Operate(const AnalogOutputFloat32& command, uint16_t index, OperateType opType) override;

CommandStatus Select(const AnalogOutputDouble64& command, uint16_t index) override;
CommandStatus Operate(const AnalogOutputDouble64& command, uint16_t index, OperateType opType) override;

protected:
virtual void DoSelect(const ControlRelayOutputBlock& command, uint16_t index) {}
Expand All @@ -69,9 +72,6 @@ class SimpleCommandHandler : public ICommandHandler
virtual void DoSelect(const AnalogOutputDouble64& command, uint16_t index) {}
virtual void DoOperate(const AnalogOutputDouble64& command, uint16_t index, OperateType opType) {}

virtual void Start() override;
virtual void End() override;

CommandStatus status;

public:
Expand Down
6 changes: 6 additions & 0 deletions cpp/lib/src/app/APDUHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "opendnp3/app/IINField.h"
#include "opendnp3/gen/FunctionCode.h"
#include "opendnp3/master/ResponseInfo.h"

namespace opendnp3
{
Expand Down Expand Up @@ -59,6 +60,11 @@ struct APDUResponseHeader : public APDUHeader
{
}

ResponseInfo as_response_info() const
{
return ResponseInfo(this->function == FunctionCode::UNSOLICITED_RESPONSE, control.FIR, control.FIN);
}

IINField IIN;
};

Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/src/master/MasterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void MContext::ProcessUnsolicitedResponse(const APDUResponseHeader& header, cons
return;
}

auto result = MeasurementHandler::ProcessMeasurements(objects, logger, SOEHandler.get());
auto result = MeasurementHandler::ProcessMeasurements(header.as_response_info(), objects, logger, SOEHandler.get());

if ((result == ParseResult::OK) && header.control.CON)
{
Expand Down

0 comments on commit cf4b1c6

Please sign in to comment.