Dynamic heating control The following sample shows how to combine an analog input channel and an analog output channels to realize a heating control loop.
#include <labbcan/common/labbcan_test_helpers.h>
#include <thread>
#include <usl/core/PollingTimer.h>
#include <diag/diag.h>
#include <iostream>
using namespace Usl;
#define BOOST_TEST_MODULE capi_dynamic_controller_test
#include <boost/test/unit_test.hpp>
using namespace boost::unit_test;
struct ArgsFixture {
ArgsFixture(): argc(framework::master_test_suite().argc),
argv(framework::master_test_suite().argv){}
int argc;
char **argv;
};
BOOST_GLOBAL_FIXTURE( ArgsFixture );
static long Result;
BOOST_FIXTURE_TEST_CASE(testCapiOpen, ArgsFixture)
{
using namespace boost::unit_test;
const char* ConfigPath = "config/testconfig_qmixsdk";
if (argc > 1)
{
ConfigPath = argv[1];
}
REQUIRE_ERR_NOERR(Result);
}
BOOST_AUTO_TEST_CASE(testCapiBuildController)
{
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
}
BOOST_AUTO_TEST_CASE(testSetControlParam)
{
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
}
BOOST_AUTO_TEST_CASE(testBusStart)
{
Result =
LCB_Log(
"C-API Log Test Message");
}
BOOST_AUTO_TEST_CASE(testControlLoop)
{
double Setpoint = 50;
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
REQUIRE_ERR_NOERR(Result);
BOOST_TEST_MESSAGE("Control loop enabled. This test runs until the actual value raises above " << Setpoint - 1);
double ActualValue;
do
{
BREAK_ON_ERROR(Result);
BOOST_TEST_MESSAGE("Actual value: " << ActualValue);
std::this_thread::sleep_for(1s);
}
while (ActualValue < (Setpoint - 1));
REQUIRE_ERR_NOERR(Result);
BOOST_TEST_MESSAGE("Control loop disabled. This test runs until the actual value drops below " << Setpoint - 10);
REQUIRE_ERR_NOERR(Result);
do
{
BREAK_ON_ERROR(Result);
BOOST_TEST_MESSAGE("Actual value: " << ActualValue);
std::this_thread::sleep_for(1s);
}
while (ActualValue > (Setpoint - 10));
REQUIRE_ERR_NOERR(Result);
}
BOOST_AUTO_TEST_CASE(testCapiClose)
{
std::this_thread::sleep_for(2s);
}