代码拉取完成,页面将自动刷新
同步操作将从 真高兴/iec104text 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* This software implements an IEC 60870-5-104 protocol tester.
* Copyright ?2010,2011,2012 Ricardo L. Olsen
*
* Disclaimer
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <QApplication>
#include "qiec104.h"
QIec104::QIec104( QObject *parent ) :
QObject( parent )
{
mEnding = false;
mAllowConnect = true;
SendCommands = 0;
mLog.activateLog();
mLog.doLogTime();
tcps = new QTcpSocket();
tmKeepAlive = new QTimer();
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( tmKeepAlive, SIGNAL(timeout()), this, SLOT(slot_keep_alive()) );
tcps->moveToThread( &tcpThread );
tcpThread.start( QThread::TimeCriticalPriority );
}
QIec104::~QIec104()
{
delete tmKeepAlive;
delete tcps;
}
void QIec104::dataIndication( iec_obj *obj, int numpoints )
{
emit signal_dataIndication( obj, numpoints );
}
void QIec104::connectTCP()
{
tcps->close();
if ( !mEnding && mAllowConnect )
tcps->connectToHost( getSecondaryIP(), getPortTCP(), QIODevice::ReadWrite );
}
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 char *)buf );
}
}
int QIec104::readTCP( char * buf, int szmax )
{
if (!mEnding)
return tcps->read( buf, szmax );
else
return 0;
}
// send tcp data, user provided
void QIec104::sendTCP( char * data, int sz )
{
if ( tcps->state() == QAbstractSocket::ConnectedState )
if ( !mEnding )
tcps->write( data, sz );
}
void QIec104::slot_tcpconnect()
{
tcps->setSocketOption( QAbstractSocket::LowDelayOption, 1 );
onConnectTCP();
emit signal_tcp_connect();
}
void QIec104::slot_tcpdisconnect()
{
onDisconnectTCP();
emit signal_tcp_disconnect();
}
void QIec104::slot_keep_alive()
{
if ( !mEnding )
onTimerSecond();
}
void QIec104::interrogationActConfIndication()
{
emit signal_interrogationActConfIndication();
}
void QIec104::interrogationActTermIndication()
{
emit signal_interrogationActTermIndication();
}
void QIec104::commandActConfIndication( iec_obj *obj )
{
emit signal_commandActConfIndication( obj );
}
void QIec104::commandActTermIndication( iec_obj *obj )
{
emit signal_commandActTermIndication( obj );
}
void QIec104::terminate()
{
mEnding = true;
tcps->close();
tcpThread.quit();
tcpThread.wait( 1000 );
if ( tcpThread.isRunning() )
tcpThread.terminate();
if ( tcpThread.isRunning() )
tcpThread.wait( 2000 );
}
void QIec104::slot_tcpreadytoread()
{
if ( tcps->bytesAvailable() < 6 )
return;
packetReadyTCP();
int cnt = 0;
// espera para ver se chega mais alguma coisa pela rede
while ( (tcps->bytesAvailable() > 5) && (cnt++ < 10) )
{
tcps->waitForReadyRead( 10 );
packetReadyTCP();
}
}
void QIec104::disable_connect()
{
mAllowConnect = false;
if ( tcps->state() == QAbstractSocket::ConnectedState )
disconnectTCP();
}
void QIec104::enable_connect()
{
mAllowConnect = true;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。