Parameter.cc 1.62 KB
Newer Older
1 2 3
#include "Parameter.h"
using namespace OpalRT;

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Parameter::Parameter(char *simulinkPath, char *simulinkName, uint8_t componentID,
                     QGCParamID paramID, unsigned short opalID)
                         : simulinkPath(new QString(simulinkPath)),
                         simulinkName(new QString(simulinkName)),
                         componentID(componentID),
                         paramID(new QGCParamID(paramID)),
                         opalID(opalID)

{
}
Parameter::Parameter(const Parameter &other)
    : componentID(other.componentID),
    opalID(other.opalID)
{
    simulinkPath = new QString(*other.simulinkPath);
    simulinkName = new QString(*other.simulinkName);
    paramID = new QGCParamID(*other.paramID);
}

Parameter::~Parameter()
24
{
25 26 27
    delete simulinkPath;
    delete simulinkName;
    delete paramID;
28
}
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

bool Parameter::operator ==(const Parameter& other) const
{
    return
            (*simulinkPath) == *(other.simulinkPath)
            && *simulinkName == *(other.simulinkName)
            && componentID == other.componentID
            && *paramID == *(other.paramID)
            && opalID == other.opalID;

}

float Parameter::getValue() //const
{
    unsigned short allocatedParams = 1;
    unsigned short numParams;
//    unsigned short allocatedValues;
    unsigned short numValues = 1;
    unsigned short returnedNumValues;
    double value;

    int returnVal = OpalGetParameters(allocatedParams, &numParams, &opalID,
                                      numValues, &returnedNumValues, &value);

    if (returnVal != EOK)
    {
        return FLT_MAX;
    }

    return static_cast<float>(value);
}