Commit 256a0a03 authored by Pavel Vainerman's avatar Pavel Vainerman

(IO): добавил поддержку precision < 0

parent 15492364
......@@ -16,7 +16,7 @@
Name: libuniset2
Version: 2.6
Release: alt12.1
Release: alt14
Summary: UniSet - library for building distributed industrial control systems
License: LGPL
......
......@@ -246,8 +246,8 @@ namespace uniset
val = uniset::lcalibrate(val, cal->minRaw, cal->maxRaw, cal->minCal, cal->maxCal, it->calcrop);
}
if( !it->noprecision && it->cal.precision > 0 )
val *= lround(pow10(it->cal.precision));
if( !it->noprecision && it->cal.precision != 0 )
val = lround( val*pow10(it->cal.precision) );
}
} // end of 'check_depend'
......@@ -282,7 +282,7 @@ namespace uniset
val = 0;
memcpy(&val, &fval, std::min(sizeof(val), sizeof(fval)));
}
else if( it->cal.precision > 0 && !it->noprecision )
else if( it->cal.precision != 0 && !it->noprecision )
val = lroundf( fval * pow10(it->cal.precision) );
// проверка на обрыв
......@@ -394,7 +394,7 @@ namespace uniset
else
{
// сперва "убираем степень", потом калибруем.. (это обратная последовательность для AsAI)
if( !it->noprecision && it->cal.precision > 0 )
if( !it->noprecision && it->cal.precision != 0 )
val = lroundf( (float)it->value / pow10(it->cal.precision) );
IOController_i::CalibrateInfo* cal( &(it->cal) );
......@@ -460,7 +460,7 @@ namespace uniset
fval = uniset::fcalibrate(fval, cal->minCal, cal->maxCal, cal->minRaw, cal->maxRaw, it->calcrop );
}
if( !it->noprecision && it->cal.precision > 0 )
if( !it->noprecision && it->cal.precision != 0 )
return ( fval / pow10(it->cal.precision) );
}
else // if( it->stype == UniversalIO::DI || it->stype == UniversalIO::DO )
......
......@@ -330,10 +330,10 @@ TEST_CASE("[IOBase::calibration]: AI calibration (precision)", "[iobase][calibra
init_test();
ObjectId ai = conf->getSensorID("CalibrationTest_AI2_AS");
CHECK( ai != DefaultObjectId );
REQUIRE( ai != DefaultObjectId );
IOBase ib;
CHECK( init_iobase(&ib, "CalibrationTest_AI2_AS") );
REQUIRE( init_iobase(&ib, "CalibrationTest_AI2_AS") );
SECTION("AI calibration with precision (asAI)")
{
......@@ -435,6 +435,22 @@ TEST_CASE("[IOBase::calibration]: AI calibration (precision)", "[iobase][calibra
ib.noprecision = false;
}
ai = conf->getSensorID("CalibrationTest_AI3_AS");
REQUIRE( ai != DefaultObjectId );
REQUIRE( init_iobase(&ib, "CalibrationTest_AI3_AS") );
SECTION("AI calibration with precision < 0 (asAI)")
{
IOBase::processingAsAI(&ib, 0, shm, true);
REQUIRE( shm->getValue(ai) == 0 );
IOBase::processingAsAI(&ib, 1000, shm, true);
REQUIRE( shm->getValue(ai) == 1 );
IOBase::processingAsAI(&ib, -10, shm, true);
REQUIRE( shm->getValue(ai) == 0 );
}
}
// -----------------------------------------------------------------------------
TEST_CASE("[IOBase::calibration]: asDI, asDO", "[iobase][di][do][extensions]")
......
......@@ -261,6 +261,7 @@
<!-- calibration test -->
<item id="114" iotype="AI" name="CalibrationTest_AI1_AS" textname="Calibration test: AI1" rmin="-100" rmax="100" cmin="-1000" cmax="1000"/>
<item id="115" iotype="AI" name="CalibrationTest_AI2_AS" textname="Calibration test: AI2" rmin="-100" rmax="100" cmin="-1000" cmax="1000" precision="2"/>
<item id="123" iotype="AI" name="CalibrationTest_AI3_AS" textname="Calibration test: AI3" precision="-3"/>
<!-- asDI, asDO -->
<item id="116" iotype="AI" name="AsDI1_AS" textname="AsDI1"/>
......
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