#include "cpowermeterdriver_analog.h"
#include "logic_compdef.h"
#include "callsystem.h"
#include "cpowermeter.h"
#include "cmotordriver.h"
CPowerMeterDriver_Analog::CPowerMeterDriver_Analog(const QString& name,int32_t id)
    :CPowerMeterDriver(name,id)
{

}

int32_t CPowerMeterDriver_Analog::freshresult(int32_t chid)
{
	double dValueMax = 40.4;
	double dValueMin = -0.395;
	double dPowMax = 4.695;
	double dPowMin = 0.094;
	double dOffset = 0.195;
    CPowerMeter* pHead=(CPowerMeter*)FindChannel(chid);
    CMotorDriver* pDriver=GET_CARD(MOTOR_DRIVER,CMotorDriver);
    int iSerial=pHead->m_Variants.get_VData(Var_Base_SerialID_ID)->toInt();
    double danalog= pDriver->get_iodata_analog(IO_INPUT_ANALOG,
                                               iSerial,true) + dOffset;

	double dScale = (dPowMax-dPowMin)/(dValueMax-dValueMin);
	pHead->m_Variants.get_VData(Var_PowerMeter_MeasResult_ID)->setValue(danalog*dScale);
    return RTN_SUCCESS1;
}

CPowerMeterDriver_Analog::~CPowerMeterDriver_Analog()
{

}

