Skip to content

Commit

Permalink
Merge pull request #33 from fledge-power/mz_refactoring
Browse files Browse the repository at this point in the history
Mz refactoring
  • Loading branch information
aklira authored Feb 22, 2023
2 parents c7308f3 + 77fcfa4 commit b418d0d
Show file tree
Hide file tree
Showing 12 changed files with 827 additions and 39 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ jobs:
- name: Download and install lib60870
env:
LIB60870_REPO_URL: "https://github.com/mz-automation/lib60870.git"
MBEDTLS_REPO_URL: "https://github.com/ARMmbed/mbedtls/archive/refs/tags/v2.28.1.tar.gz"
MBEDTLS_REPO_URL: "https://github.com/ARMmbed/mbedtls/archive/refs/tags/v2.28.2.tar.gz"
run: |
cd $HOME
git clone ${{ env.LIB60870_REPO_URL }}
cd $HOME/lib60870/lib60870-C
cd dependencies
wget ${{ env.MBEDTLS_REPO_URL }}
tar xf v2.28.1.tar.gz
tar xf v2.28.2.tar.gz
mv mbedtls-2.28.2 mbedtls-2.28
cd ..
mkdir build
cd build
Expand Down
7 changes: 6 additions & 1 deletion include/iec104.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class IEC104Server
void m_enqueueSpontDatapoint(IEC104DataPoint* dp, CS101_CauseOfTransmission cot, IEC60870_5_TypeID typeId);
void m_updateDataPoint(IEC104DataPoint* dp, IEC60870_5_TypeID typeId, DatapointValue* value, CP56Time2a ts, uint8_t quality);

bool checkIfSouthConnected();

bool checkTimestamp(CP56Time2a timestamp);
bool checkIfCmdTimeIsValid(int typeId, InformationObject io);
void addToOutstandingCommands(CS101_ASDU asdu, IMasterConnection connection, bool isSelect);
Expand All @@ -110,6 +112,8 @@ class IEC104Server
void removeAllOutstandingCommands();
void handleActCon(int type, int ca, int ioa, bool isNegative);
void handleActTerm(int type, int ca, int ioa, bool isNegative);
bool requestSouthConnectionStatus();
void updateSouthMonitoringInstance(Datapoint* dp, IEC104Config::SouthPluginMonitor* southPluginMonitor);

static void printCP56Time2a(CP56Time2a time);
static void rawMessageHandler(void* parameter, IMasterConnection connection,
Expand All @@ -128,6 +132,7 @@ class IEC104Server
const char* ipAddress);
static void connectionEventHandler(void* parameter, IMasterConnection con,
CS104_PeerConnectionEvent event);

CS104_Slave m_slave{};
TLSConfiguration m_tlsConfig = nullptr;
CS101_AppLayerParameters alParams;
Expand All @@ -138,7 +143,7 @@ class IEC104Server
int m_actConTimeout = 1000;
int m_actTermTimeout = 1000;

int (*m_oper)(char *operation, int paramCount, char* names[], char *parameters[], ControlDestination destination, ...);
int (*m_oper)(char *operation, int paramCount, char* names[], char* parameters[], ControlDestination destination, ...) = NULL;

bool m_started = false;
std::thread* m_monitoringThread = nullptr;
Expand Down
49 changes: 49 additions & 0 deletions include/iec104_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,58 @@ class IEC104Config
std::vector<std::string>& GetRemoteCertificates() {return m_remoteCertificates;};
std::vector<std::string>& GetCaCertificates() {return m_caCertificates;};

enum class Mode
{
CONNECT_ALWAYS,
CONNECT_IF_SOUTH_CONNX_STARTED
};

Mode GetMode() {return m_mode;};

enum class ConnectionStatus
{
STARTED,
NOT_CONNECTED
};

enum class GiStatus
{
IDLE,
STARTED,
IN_PROGRESS,
FAILED,
FINISHED
};

class SouthPluginMonitor {

public:
SouthPluginMonitor(std::string& assetName);

std::string& GetAssetName() {return m_assetName;};

ConnectionStatus GetConnxStatus() {return m_connxStatus;};
GiStatus GetGiStatus() {return m_giStatus;};

void SetConnxStatus(ConnectionStatus status) {m_connxStatus = status;};
void SetGiStatus(GiStatus status) {m_giStatus = status;};

private:

std::string m_assetName;
ConnectionStatus m_connxStatus;
GiStatus m_giStatus;
};

std::vector<SouthPluginMonitor*> GetMonitoredSouthPlugins() {return m_monitoredSouthPlugins;};

private:

static bool isValidIPAddress(const string& addrStr);

void deleteExchangeDefinitions();

Mode m_mode = Mode::CONNECT_ALWAYS;

bool m_protocolConfigComplete;
bool m_exchangeConfigComplete;
Expand Down Expand Up @@ -100,6 +147,8 @@ class IEC104Config

std::vector<CS104_RedundancyGroup> m_configuredRedundancyGroups;

std::vector<SouthPluginMonitor*> m_monitoredSouthPlugins;

std::map<int, std::map<int, IEC104DataPoint*>>* m_exchangeDefinitions = nullptr;
std::map<int, int> m_allowedOriginators;

Expand Down
Loading

0 comments on commit b418d0d

Please sign in to comment.