Skip to content

Commit

Permalink
Version 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
riclolsen authored Nov 10, 2022
1 parent 009621e commit 7617b5c
Show file tree
Hide file tree
Showing 10 changed files with 2,333 additions and 1,249 deletions.
834 changes: 737 additions & 97 deletions iec104_class.cpp

Large diffs are not rendered by default.

302 changes: 172 additions & 130 deletions iec104_class.h

Large diffs are not rendered by default.

846 changes: 519 additions & 327 deletions iec104_types.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion logmsg.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This software implements an IEC 60870-5-104 protocol tester.
* Copyright © 2010-2017 Ricardo L. Olsen
* Copyright © 2010-2022 Ricardo L. Olsen
*
* Disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Expand Down
2 changes: 1 addition & 1 deletion logmsg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This software implements an IEC 60870-5-104 protocol tester.
* Copyright © 2010-2017 Ricardo L. Olsen
* Copyright © 2010-2022 Ricardo L. Olsen
*
* Disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Expand Down
1,483 changes: 845 additions & 638 deletions mainwindow.cpp

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This software implements an IEC 60870-5-104 protocol tester.
* Copyright © 2010-2017 Ricardo L. Olsen
* Copyright © 2010-2022 Ricardo L. Olsen
*
* Disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Expand Down Expand Up @@ -42,6 +42,11 @@
#include "iec104_class.h"
#include "qiec104.h"

#define QTESTER_VERSION "v2.5"
#define QTESTER_COPYRIGHT "Copyright © 2010-2022 Ricardo Lastra Olsen"
#define CURDIRINIFILENAME "/qtester104.ini"
#define CONFDIRINIFILENAME "../conf/qtester104.ini"

namespace Ui {
class MainWindow;
}
Expand Down Expand Up @@ -102,11 +107,11 @@ class MainWindow : public QMainWindow {
static const int I104M_porta_escuta = 8098; // udp port to receive commands from OSHMI
static const int I104M_CntToBePrimary = 3; // counts necessary to be primary when not receiving keepalive messages
static const int I104M_seconds_kamsg = 7; // period of keepalive messages
int I104M_CntDnToBePrimary; // countdown to be primary when not receiving keepalive messages
int I104M_Logar; // controls log of I104M messages
int I104M_CntDnToBePrimary = 0; // countdown to be primary when not receiving keepalive messages
int I104M_Logar = 0; // controls log of I104M messages
bool isPrimary; // primary or secondary redundant mode
QUdpSocket* udps; // I104M: udp socket
QTimer* tmI104M_kamsg; // timer to send keep alive messages to the dual host
QUdpSocket* udps = nullptr; // I104M: udp socket
QTimer* tmI104M_kamsg = nullptr; // timer to send keep alive messages to the dual host
void SendOSHMI(char* msg, unsigned int packet_size);
void fmtCP56Time(char*, cp56time2a*);
};
Expand Down
47 changes: 22 additions & 25 deletions qiec104.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This software implements an IEC 60870-5-104 protocol tester.
* Copyright © 2010-2017 Ricardo L. Olsen
* Copyright © 2010-2022 Ricardo L. Olsen
*
* Disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Expand All @@ -27,11 +27,10 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <QtWidgets/QApplication>
#include "qiec104.h"
#include <QtWidgets/QApplication>

QIec104::QIec104(QObject* parent) :
QObject(parent) {
QIec104::QIec104(QObject *parent) : QObject(parent) {
mEnding = false;
mAllowConnect = true;
SendCommands = 0;
Expand All @@ -45,7 +44,9 @@ QIec104::QIec104(QObject* parent) :
connect(tcps, SIGNAL(readyRead()), this, SLOT(slot_tcpreadytoread()));
connect(tcps, SIGNAL(connected()), this, SLOT(slot_tcpconnect()));
connect(tcps, SIGNAL(disconnected()), this, SLOT(slot_tcpdisconnect()));
connect(tcps, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slot_tcperror(QAbstractSocket::SocketError)), Qt::DirectConnection);
connect(tcps, SIGNAL(error(QAbstractSocket::SocketError)), this,
SLOT(slot_tcperror(QAbstractSocket::SocketError)),
Qt::DirectConnection);
connect(tmKeepAlive, SIGNAL(timeout()), this, SLOT(slot_keep_alive()));

tcps->moveToThread(&tcpThread);
Expand All @@ -64,7 +65,7 @@ void QIec104::waitBytes(int bytes, int msTout) {
}
}

void QIec104::dataIndication(iec_obj* obj, unsigned numpoints) {
void QIec104::dataIndication(iec_obj *obj, unsigned numpoints) {
emit signal_dataIndication(obj, numpoints);
}

Expand All @@ -76,30 +77,30 @@ void QIec104::connectTCP() {
if (!mEnding && mAllowConnect) {
// alternate main and backup UTR IP address, if configured
if ((++cnt) % 2 || strcmp(getSecondaryIP_backup(), "") == 0) {
tcps->connectToHost(getSecondaryIP(), quint16(getPortTCP()), QIODevice::ReadWrite);
tcps->connectToHost(getSecondaryIP(), quint16(getPortTCP()),
QIODevice::ReadWrite);
sprintf(buf, "Try to connect IP: %s", getSecondaryIP());
mLog.pushMsg(const_cast<char*>(buf));
mLog.pushMsg(const_cast<char *>(buf));
} else {
tcps->connectToHost(getSecondaryIP_backup(), quint16(getPortTCP()), QIODevice::ReadWrite);
tcps->connectToHost(getSecondaryIP_backup(), quint16(getPortTCP()),
QIODevice::ReadWrite);
sprintf(buf, "Try to connect IP: %s", getSecondaryIP_backup());
mLog.pushMsg(const_cast<char*>(buf));
mLog.pushMsg(const_cast<char *>(buf));
}
}
}

void QIec104::disconnectTCP() {
tcps->close();
}
void QIec104::disconnectTCP() { tcps->close(); }

void QIec104::slot_tcperror(QAbstractSocket::SocketError socketError) {
if (socketError != QAbstractSocket::SocketTimeoutError) {
char buf[100];
sprintf(buf, "SocketError: %d", socketError);
mLog.pushMsg(const_cast<char*>(buf));
mLog.pushMsg(const_cast<char *>(buf));
}
}

int QIec104::readTCP(char* buf, int szmax) {
int QIec104::readTCP(char *buf, int szmax) {
int ret = int(tcps->read(buf, szmax));

if (!mEnding && ret > 0)
Expand All @@ -109,7 +110,7 @@ int QIec104::readTCP(char* buf, int szmax) {
}

// send tcp data, user provided
void QIec104::sendTCP(char* data, int sz) {
void QIec104::sendTCP(char *data, int sz) {
if (tcps->state() == QAbstractSocket::ConnectedState)
if (!mEnding) {
tcps->write(data, sz);
Expand Down Expand Up @@ -145,15 +146,15 @@ void QIec104::slot_keep_alive() {
}
}

void QIec104::interrogationActConfIndication() {
void QIec104::interrogationActConfIndication() {
emit signal_interrogationActConfIndication();
}

void QIec104::interrogationActTermIndication() {
void QIec104::interrogationActTermIndication() {
emit signal_interrogationActTermIndication();
}

void QIec104::commandActRespIndication(iec_obj* obj) {
void QIec104::commandActRespIndication(iec_obj *obj) {
emit signal_commandActRespIndication(obj);
}

Expand Down Expand Up @@ -181,10 +182,6 @@ void QIec104::disable_connect() {
disconnectTCP();
}

void QIec104::enable_connect() {
mAllowConnect = true;
}
void QIec104::enable_connect() { mAllowConnect = true; }

int QIec104::bytesAvailableTCP() {
return int(tcps->bytesAvailable());
}
int QIec104::bytesAvailableTCP() { return int(tcps->bytesAvailable()); }
45 changes: 23 additions & 22 deletions qiec104.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This software implements an IEC 60870-5-104 protocol tester.
* Copyright © 2010-2017 Ricardo L. Olsen
* Copyright © 2010-2022 Ricardo L. Olsen
*
* Disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Expand Down Expand Up @@ -31,59 +31,60 @@
#define QIEC104_H

#include <QObject>
#include <QTimer>
#include <QThread>
#include <QTimer>
#include <QtNetwork/QTcpSocket>
#include <iec104_class.h>

class QIec104 : public QObject, public iec104_class {
Q_OBJECT

public:
explicit QIec104(QObject* parent = 0);
public:
explicit QIec104(QObject *parent = 0);
~QIec104();
int SendCommands; // 1 = allow sending commands, 0 = don't send commands
int ForcePrimary; // 1 = force primary (cant't stay secondary) , 0 = can be secondary
QTimer* tmKeepAlive; // 1 second timer
QTcpSocket* tcps; // socket for iec104 (tcp)
int SendCommands; // 1 = allow sending commands, 0 = don't send commands
int ForcePrimary; // 1 = force primary (cant't stay secondary) , 0 = can be
// secondary
QTimer *tmKeepAlive; // 1 second timer
QTcpSocket *tcps; // socket for iec104 (tcp)
void terminate();
void disable_connect();
void enable_connect();

signals:
void signal_dataIndication(iec_obj* obj, unsigned numpoints);
signals:
void signal_dataIndication(iec_obj *obj, unsigned numpoints);
void signal_interrogationActConfIndication();
void signal_interrogationActTermIndication();
void signal_tcp_connect();
void signal_tcp_disconnect();
void signal_commandActRespIndication(iec_obj* obj);
void signal_commandActRespIndication(iec_obj *obj);

public slots:
public slots:
void slot_tcpdisconnect(); // tcp disconnect for iec104

private slots:
void slot_tcpconnect(); // tcp connect for iec104
private slots:
void slot_tcpconnect(); // tcp connect for iec104
void slot_tcpreadytoread(); // ready to read data on iec104 tcp socket
void slot_tcperror(QAbstractSocket::SocketError socketError); // show errors of tcp
void slot_keep_alive(); // timer de 1s
void
slot_tcperror(QAbstractSocket::SocketError socketError); // show errors of tcp
void slot_keep_alive(); // timer de 1s

private:
private:
QThread tcpThread;

// redefine for iec104_class
void waitBytes(int bytes, int msTout);
int bytesAvailableTCP();
void connectTCP();
void disconnectTCP();
int readTCP(char* buf, int szmax);
void sendTCP(char* data, int sz);
int readTCP(char *buf, int szmax);
void sendTCP(char *data, int sz);
void interrogationActConfIndication();
void interrogationActTermIndication();
void commandActRespIndication(iec_obj* obj);
void dataIndication(iec_obj* obj, unsigned numpoints);
void commandActRespIndication(iec_obj *obj);
void dataIndication(iec_obj *obj, unsigned numpoints);
bool mEnding;
bool mAllowConnect;
};


#endif // QIEC104_H
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QTester104 Copyright � 2010-2021 Ricardo L. Olsen.
QTester104 Copyright � 2010-2022 Ricardo L. Olsen.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -17,8 +17,8 @@ This software implements an IEC 60870-5-104 protocol tester.
IEC 60870-5-104 is a commonly used protocol for data acquisition and control of power substations.

Directories:
src - multiplatform qt sources, compile with QT 5.13.1 or later on any supported platform.
bin - win32 binaries built with QT 5.13.1.
src - multiplatform qt sources, compile with QT 6.4.0 or later on any supported platform.
bin - win32 X64 binaries built with QT 6.4.0.
conf - configuration file

Can be used to poll substation data and issuing commands.
Expand Down

0 comments on commit 7617b5c

Please sign in to comment.