Skip to content

Commit

Permalink
Merge pull request #12 from fledge-power/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aklira authored Sep 12, 2023
2 parents ad075b9 + 92556e9 commit 455c501
Show file tree
Hide file tree
Showing 11 changed files with 4,326 additions and 256 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@
*.exe
*.out
*.app

*.idea

/.vscode

build/*
tests/build/
cmake-build-debug/*

# Github
.github*
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# fledgepower-filter-iec104topivot
A filter plugin which can be used to convert IEC 104 ASDU objects to FledgePower pivot model objects

This filter plugin can run in the IEC 104 north plugin, the IEC 104 south plugin, and the control dispatcher (to filter operations from north to south).

12 changes: 7 additions & 5 deletions include/iec104_pivot_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Released under the Apache 2.0 Licence
*
* Author: Michael Zillgith (michael.zillgith at mz-automation.de)
*
*
*/

#ifndef _IEC104_PIVOT_FILTER_H
Expand Down Expand Up @@ -43,12 +43,14 @@ class IEC104PivotFilter {

Datapoint* createDp(string name);

template <class T>
Datapoint* createDpWithValue(string name, const T value);
Datapoint* convertDataObjectToPivot(Datapoint* sourceDp, IEC104PivotDataPoint* exchangeConfig);

Datapoint* convertOperationObjectToPivot(std::vector<Datapoint*> sourceDp);

Datapoint* convertDatapointToIEC104DataObject(Datapoint* sourceDp, IEC104PivotDataPoint* exchangeConfig);

Datapoint* convertDatapointToPivot(Datapoint* sourceDp, IEC104PivotDataPoint* exchangeConfig);
std::vector<Datapoint*> convertReadingToIEC104OperationObject(Datapoint* datapoints);

Datapoint* convertDatapointToIEC104(Datapoint* sourceDp, IEC104PivotDataPoint* exchangeConfig);

OUTPUT_HANDLE* m_outHandle;
OUTPUT_STREAM m_output;
Expand Down
15 changes: 10 additions & 5 deletions include/iec104_pivot_filter_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* Released under the Apache 2.0 Licence
*
* Author: Michael Zillgith (michael.zillgith at mz-automation.de)
*
*
*/

#ifndef PIVOT_IEC104_CONFIG_H
#define PIVOT_IEC104_CONFIG_H

#include <map>
#include <vector>
#include <memory>

using namespace std;

Expand Down Expand Up @@ -50,16 +51,20 @@ class IEC104PivotConfig

void importExchangeConfig(const string& exchangeConfig);

std::map<std::string, IEC104PivotDataPoint*>& getExchangeDefinitions() {return m_exchangeDefinitions;};
IEC104PivotDataPoint* getExchangeDefinitionsByLabel(std::string label);
IEC104PivotDataPoint* getExchangeDefinitionsByAddress(std::string address);
IEC104PivotDataPoint* getExchangeDefinitionsByPivotId(std::string pivotid);

private:

void deleteExchangeDefinitions();

bool m_exchangeConfigComplete;

/* list of exchange data points -> the label is the key */
std::map<std::string, IEC104PivotDataPoint*> m_exchangeDefinitions;
std::map<std::string, std::shared_ptr<IEC104PivotDataPoint>> m_exchangeDefinitionsLabel;
std::map<std::string, std::shared_ptr<IEC104PivotDataPoint>> m_exchangeDefinitionsAddress;
std::map<std::string, std::shared_ptr<IEC104PivotDataPoint>> m_exchangeDefinitionsPivotId;

};

#endif /* PIVOT_IEC104_CONFIG_H */
144 changes: 96 additions & 48 deletions include/iec104_pivot_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Released under the Apache 2.0 Licence
*
* Author: Michael Zillgith (michael.zillgith at mz-automation.de)
*
*
*/

#ifndef _IEC104_PIVOT_OBJECT_H
Expand All @@ -20,7 +20,7 @@
using namespace std;

class PivotObjectException : public std::exception //NOSONAR
{
{
public:
explicit PivotObjectException(const std::string& context):
m_context(context) {}
Expand All @@ -35,10 +35,15 @@ class PivotTimestamp
{
public:
PivotTimestamp(Datapoint* timestampData);

int SecondSinceEpoch() {return m_secondSinceEpoch;};
int FractionOfSecond() {return m_fractionOfSecond;};

PivotTimestamp(long ms);
~PivotTimestamp();

void setTimeInMs(long ms);

int SecondSinceEpoch();
int FractionOfSecond();
uint64_t getTimeInMs();

bool ClockFailure() {return m_clockFailure;};
bool LeapSecondKnown() {return m_leapSecondKnown;};
bool ClockNotSynchronized() {return m_clockNotSynchronized;};
Expand All @@ -50,15 +55,19 @@ class PivotTimestamp

void handleTimeQuality(Datapoint* timeQuality);

uint8_t* m_valueArray;

int m_secondSinceEpoch;
int m_fractionOfSecond;

int m_timeAccuracy;
bool m_clockFailure;
bool m_leapSecondKnown;
bool m_clockNotSynchronized;
bool m_clockFailure = false;
bool m_leapSecondKnown = false;
bool m_clockNotSynchronized = false;
};



class PivotObject
{
public:
Expand All @@ -74,9 +83,59 @@ class PivotObject
{
SPS,
DPS,
MV
MV,
SPC,
DPC,
INC,
APC,
BSC
} PivotCdc;

void setIdentifier(const string& identifier);
void setCause(int cause);
void setConfirmation(bool value);
void setTest(bool value);
void setCtlValBool(bool value);
void setCtlValStr(const std::string& value);
void setCtlValI(int value);
void setCtlValF(float value);

Datapoint* toDatapoint() {return m_dp;};

std::string& getIdentifier() {return m_identifier;};
std::string& getComingFrom() {return m_comingFrom;};
int getCause() {return m_cause;};
bool isConfirmation() {return m_confirmation;};
bool Test() {return m_test;};

protected:

Datapoint* getCdc(Datapoint* dp);

Datapoint* m_dp;
Datapoint* m_ln;
Datapoint* m_cdc;
PivotClass m_pivotClass;
PivotCdc m_pivotCdc;

std::string m_comingFrom = "iec104";
std::string m_identifier;
int m_cause = 0;
bool m_confirmation = false;
bool m_test = false;

PivotTimestamp* m_timestamp = nullptr;

bool hasIntVal = true;
long intVal = 0;
float floatVal = 0.0;
};


class PivotDataObject : public PivotObject
{
public:

typedef enum
{
GOOD,
Expand All @@ -91,36 +150,24 @@ class PivotObject
SUBSTITUTED
} Source;

PivotObject(Datapoint* pivotData);
PivotObject(const string& pivotLN, const string& valueType);
~PivotObject();

void setIdentifier(const string& identifier);
void setCause(int cause);
PivotDataObject(Datapoint* pivotData);
PivotDataObject(const string& pivotLN, const string& valueType);
~PivotDataObject();

void setStVal(bool value);
void setStValStr(const std::string& value);

void setMagF(float value);
void setMagI(int value);

void setConfirmation(bool value);
void setMagF(float value);
void setPosVal(int value, bool trans);

void addQuality(bool bl, bool iv, bool nt, bool ov, bool sb, bool test);
void addTimestamp(long ts, bool iv, bool su, bool sub);

void addTmOrg(bool substituted);
void addTmValidity(bool invalid);

Datapoint* toDatapoint() {return m_dp;};

Datapoint* toIec104DataObject(IEC104PivotDataPoint* exchangeConfig);

std::string& getIdentifier() {return m_identifier;};
std::string& getComingFrom() {return m_comingFrom;};
int getCause() {return m_cause;};
bool isConfirmation() {return m_isConfirmation;};

Validity getValidity() {return m_validity;};
Source getSource() {return m_source;};

Expand All @@ -131,30 +178,17 @@ class PivotObject
bool Oscillatory() {return m_oscillatory;};
bool OutOfRange() {return m_outOfRange;};
bool Overflow() {return m_overflow;};

bool OperatorBlocked() {return m_operatorBlocked;};
bool Test() {return m_test;};
bool isTransient() {return m_transient;}

bool IsTimestampSubstituted() {return m_timestampSubstituted;};
bool IsTimestampInvalid() {return m_timestampInvalid;};

private:

Datapoint* getCdc(Datapoint* dp);
void handleDetailQuality(Datapoint* detailQuality);
void handleQuality(Datapoint* q);

Datapoint* m_dp;
Datapoint* m_ln;
Datapoint* m_cdc;
PivotClass m_pivotClass;
PivotCdc m_pivotCdc;

std::string m_comingFrom;
std::string m_identifier;
int m_cause = 0;
bool m_isConfirmation = false;

Validity m_validity = Validity::GOOD;
bool m_badReference = false;
bool m_failure = false;
Expand All @@ -166,16 +200,30 @@ class PivotObject
bool m_overflow = false;
Source m_source = Source::PROCESS;
bool m_operatorBlocked = false;
bool m_test = false;

PivotTimestamp* m_timestamp = nullptr;

bool m_timestampSubstituted = false;
bool m_timestampInvalid = false;
bool m_transient = false;
};

class PivotOperationObject : public PivotObject
{
public:

PivotOperationObject(Datapoint* pivotData);
PivotOperationObject(const string& pivotLN, const string& valueType);
~PivotOperationObject();

void setSelect(int select);
void addTimestamp(long ts);

std::vector<Datapoint*> toIec104OperationObject(IEC104PivotDataPoint* exchangeConfig);

int getSelect() {return m_select;}

private:
int m_select = 0;

bool hasIntVal = true;
long intVal;
float floatVal;
};

#endif /* _IEC104_PIVOT_OBJECT_H */
Loading

0 comments on commit 455c501

Please sign in to comment.