Commit a7a1b440 authored by Pavel Vainerman's avatar Pavel Vainerman

(Modbus): добавил ещё тестов

parent 5190121a
......@@ -2,6 +2,7 @@
#include <sstream>
#include <UniSetTypes.h>
#include "MBTCPTestServer.h"
#include "VTypes.h"
#include "uniset-config.h"
// -------------------------------------------------------------------------
#ifndef PACKAGE_URL
......@@ -352,6 +353,13 @@ ModbusRTU::mbErrCode MBTCPTestServer::writeOutputRegisters( ModbusRTU::WriteOutp
ModbusRTU::mbErrCode ret = ModbusRTU::erNoError;
reply.set(query.start, query.quant);
lastWriteOutputQ = query;
if( query.start == 41 )
{
VTypes::F2 f2(query.data,VTypes::F2::wsize());
f2_test_value = (float)f2;
}
return ret;
}
......
......@@ -64,6 +64,8 @@ class MBTCPTestServer
friend std::ostream& operator<<(std::ostream& os, const MBTCPTestServer* m );
inline float getF2TestValue(){ return f2_test_value; }
protected:
// действия при завершении работы
void sigterm( int signo );
......@@ -133,6 +135,8 @@ class MBTCPTestServer
int lastWriteOutputSingleRegister;
ModbusRTU::ForceCoilsMessage lastForceCoilsQ;
ModbusRTU::WriteOutputMessage lastWriteOutputQ;
float f2_test_value = {0.0};
#if 0
typedef std::map<ModbusRTU::mbErrCode, unsigned int> ExchangeErrorMap;
ExchangeErrorMap errmap; /*!< статистика обмена */
......
......@@ -112,6 +112,9 @@
<item id="1027" mb="1" mbtype="rtu" mbaddr="0x01" mbreg="41" mbfunc="0x10" vtype="F2" iotype="AO" name="TestWrite1027_F2" precision="1" textname="F2: Тестовый регистр для 0x10"/>
<item id="10000" iotype="DI" name="TestMode_S" textname="Тестовый датчик"/>
</sensors>
......
......@@ -8,11 +8,14 @@
#include "SharedMemory.h"
#include "Extensions.h"
#include "MBTCPMaster.h"
#include "SMInterface.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace UniSetTypes;
using namespace UniSetExtensions;
// --------------------------------------------------------------------------
std::shared_ptr<SharedMemory> shm;
// --------------------------------------------------------------------------
int main(int argc, char* argv[] )
{
Catch::Session session;
......@@ -38,7 +41,7 @@ int main(int argc, char* argv[] )
bool apart = findArgParam("--apart", argc, argv) != -1;
auto shm = SharedMemory::init_smemory(argc, argv);
shm = SharedMemory::init_smemory(argc, argv);
if( !shm )
return 1;
......
......@@ -16,11 +16,14 @@ static string addr("127.0.0.1"); // conf->getArgParam("--mbs-inet-addr");
static ModbusRTU::ModbusAddr slaveADDR = 0x01;
static shared_ptr<MBTCPTestServer> mbs;
static shared_ptr<UInterface> ui;
static std::shared_ptr<SMInterface> smi;
static ObjectId mbID = 6004; // MBTCPMaster1
static int polltime = 100; // conf->getArgInt("--mbtcp-polltime");
static ObjectId slaveNotRespond = 10; // Slave_Not_Respond_S
static const ObjectId exchangeMode = 11; // MBTCPMaster_Mode_AS
// -----------------------------------------------------------------------------
extern std::shared_ptr<SharedMemory> shm;
// -----------------------------------------------------------------------------
static void InitTest()
{
auto conf = uniset_conf();
......@@ -35,6 +38,17 @@ static void InitTest()
CHECK( ui->waitReady(slaveNotRespond, 8000) );
}
if( !smi )
{
if( shm == nullptr )
throw SystemError("SharedMemory don`t initialize..");
if( ui == nullptr )
throw SystemError("UInterface don`t initialize..");
smi = make_shared<SMInterface>(shm->getId(), ui, mbID, shm );
}
if( !mbs )
{
try
......@@ -67,6 +81,20 @@ static void InitTest()
}
}
// -----------------------------------------------------------------------------
static bool init_iobase( IOBase* ib, const std::string& sensor )
{
InitTest();
auto conf = uniset_conf();
xmlNode* snode = conf->getXMLObjectNode( conf->getSensorID(sensor) );
CHECK( snode != 0 );
UniXML::iterator it(snode);
smi->initIterator(ib->d_it);
smi->initIterator(ib->ioit);
smi->initIterator(ib->t_ait);
return IOBase::initItem(ib, it, smi, "", false);
}
// -----------------------------------------------------------------------------
TEST_CASE("MBTCPMaster: 0x01 (read coil status)", "[modbus][0x01][mbmaster][mbtcpmaster]")
{
InitTest();
......@@ -571,13 +599,13 @@ TEST_CASE("MBTCPMaster: 0x66 (file transfer)", "[modbus][0x66][mbmaster][mbtcpma
WARN("Test of '0x66'..not yet.. ");
}
// -----------------------------------------------------------------------------
#if 0
//#if 1
TEST_CASE("MBTCPMaster: 0x10 (F2)", "[modbus][0x10][F2][mbmaster][mbtcpmaster]")
{
InitTest();
ui->setValue(1027, 100);
REQUIRE( ui->getValue(1027) == 100 );
ui->setValue(1027, 112);
REQUIRE( ui->getValue(1027) == 112 );
msleep(polltime + 200);
ModbusRTU::WriteOutputMessage q = mbs->getLastWriteOutput();
REQUIRE( q.addr == slaveADDR );
......@@ -586,9 +614,10 @@ TEST_CASE("MBTCPMaster: 0x10 (F2)", "[modbus][0x10][F2][mbmaster][mbtcpmaster]")
VTypes::F2 f2(q.data, VTypes::F2::wsize());
float f = f2;
REQUIRE( f == 100 );
REQUIRE( f == 11.2f );
}
// -----------------------------------------------------------------------------
#if 0
TEST_CASE("MBTCPMaster: 0x10 (F4)", "[modbus][0x10][F4][mbmaster][mbtcpmaster]")
{
InitTest();
......@@ -609,3 +638,28 @@ TEST_CASE("MBTCPMaster: 0x10 (F4)", "[modbus][0x10][F4][mbmaster][mbtcpmaster]")
}
#endif
// -----------------------------------------------------------------------------
TEST_CASE("MBTCPMaster: FasAO -> FasAI", "[modbus][float]")
{
InitTest();
IOBase ib;
CHECK( init_iobase(&ib, "TestWrite1027_F2") );
ui->setValue(1027, 116);
REQUIRE( ui->getValue(1027) == 116 );
msleep(polltime + 200);
ModbusRTU::WriteOutputMessage q = mbs->getLastWriteOutput();
REQUIRE( q.addr == slaveADDR );
REQUIRE( q.start == 41 );
REQUIRE( q.quant == 2 );
float f2 = mbs->getF2TestValue();
ui->setValue(1027, 0);
IOBase::processingFasAI( &ib, f2, smi, true );
REQUIRE( ui->getValue(1027) == 116 );
float f3 = IOBase::processingFasAO( &ib, smi, true );
REQUIRE( f3 == 11.6f );
}
// -----------------------------------------------------------------------------
......@@ -197,6 +197,7 @@
<item id="2048" mbs="1" mbreg="258" iotype="AO" name="Test_CountWrite10_11" textname="Тестовый регистр для 0x10"/>
<item id="2049" mbs="1" mbreg="257" iotype="AO" name="Test_CountWrite10_12" textname="Тестовый регистр для 0x10"/>
<item id="2050" mbs="1" mbreg="259" iotype="AO" vtype="F2" name="Test_CountWrite10_F2" textname="Тестовый регистр для 0x10(F2)"/>
<item id="2051" mbs="1" mbreg="261" iotype="AO" vtype="F2" precision="1" name="Test_CountWrite10_F2prec" textname="Тестовый регистр для 0x10(F2)(prec)"/>
<item id="10000" iotype="DI" name="TestMode_S" textname="Тестовый датчик"/>
......
......@@ -1135,7 +1135,7 @@ TEST_CASE("(0x10): write register outputs or memories [F2]", "[modbus][mbslave][
using namespace VTypes;
float f = 200.0;
float f = 200.4;
F2 f2(f);
ModbusRTU::WriteOutputMessage msg(slaveaddr, tREG);
......@@ -1148,4 +1148,25 @@ TEST_CASE("(0x10): write register outputs or memories [F2]", "[modbus][mbslave][
REQUIRE( ui->getValue(tID) == 200 );
}
// -------------------------------------------------------------
TEST_CASE("(0x10): write register outputs or memories [F2](precision)", "[modbus][mbslave][F2prec][mbtcpslave]")
{
InitTest();
ObjectId tID = 2051;
ModbusRTU::ModbusData tREG = 261;
using namespace VTypes;
float f = 200.4;
F2 f2(f);
ModbusRTU::WriteOutputMessage msg(slaveaddr, tREG);
msg.addData(f2.raw.v[0]);
msg.addData(f2.raw.v[1]);
ModbusRTU::WriteOutputRetMessage ret = mb->write10(msg);
REQUIRE( ret.start == tREG );
REQUIRE( ret.quant == 2 );
REQUIRE( ui->getValue(tID) == 2004 );
}
// -------------------------------------------------------------
/*! \todo Доделать тесты на считывание с разными prop_prefix.. */
......@@ -494,3 +494,20 @@ TEST_CASE("IOBase with SM", "[iobase][extensions]")
// processingThreshold
}
// -----------------------------------------------------------------------------
TEST_CASE("[IOBase]: FasAO --> FasAI", "[iobase][float]")
{
CHECK( uniset_conf() != nullptr );
IOBase ib;
CHECK( init_iobase(&ib, "FasAI_S") );
shm->setValue(119, 232);
float f = IOBase::processingFasAO(&ib, shm, true);
CHECK( f == 23.2f );
IOBase::processingFasAI(&ib, f, shm, true);
CHECK(shm->getValue(119) == 232 );
}
// -----------------------------------------------------------------------------
......@@ -267,6 +267,11 @@
<item id="117" iotype="DI" name="AsDI2_S" textname="AsDI2"/>
<item id="118" iotype="DO" name="AsDO_S" textname="AsDO"/>
<!-- FasAO -> FasAI -->
<item id="119" iotype="AI" name="FasAI_S" textname="FasAI" precision="1"/>
<item id="120" iotype="AI" name="FasAO_S" textname="FasAO" precsision="1"/>
</sensors>
<thresholds name="thresholds">
<sensor iotype="AI" name="AI_AS">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment