Skip to content
Snippets Groups Projects
N_PhotoVoltaique.cpp 7.24 KiB
Newer Older
LE's avatar
LE committed
// ============================================================================
//
// = CONTEXT
//    TANGO Project - NovelecElectrometer Support Library
//			PhotoVoltaique Types are Type 1, 2 & 3
//
// = FILENAME
//    N_PhotoVoltaique.cpp
//
// = AUTHOR
//    X. Elattaoui
//
// ============================================================================

// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
ELATTAOUI's avatar
ELATTAOUI committed
#include <Xstring.h>
LE's avatar
LE committed
#include "N_PhotoVoltaique.h"
#include "NovelecProtocol.h"
/*
* Valid Range values for a N_PhotoVoltaique
*/
ELATTAOUI's avatar
ELATTAOUI committed
static const std::string NType1_rangeValue[] = {"1E-11AcC","3E-11AcC","1E-10AcC","3E-10AcC"};
static const std::string NType2_rangeValue[] = {"1E-10AcC","3E-10AcC","1E-09AcC","3E-09AcC","1E-08AcC","3E-08AcC","1E-07AcC","3E-07AcC"};
static const std::string NType3_rangeValue[] = {"1E-08AcC","3E-08AcC","1E-07AcC","3E-07AcC","1E-06AcC","3E-06AcC","1E-05AcC","3E-05AcC"};
LE's avatar
LE committed


// ============================================================================
// N_PhotoVoltaique::N_PhotoVoltaique
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
N_PhotoVoltaique::N_PhotoVoltaique (std::string comLink_device_name, short address)
:	Novelec_MCCE2(comLink_device_name, address)
LE's avatar
LE committed
{
ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoVoltaique::N_PhotoVoltaique <-" << std::endl;
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoVoltaique::N_PhotoVoltaique ->" << std::endl;
LE's avatar
LE committed
}

// ============================================================================
// N_PhotoVoltaique::~N_PhotoVoltaique
// ============================================================================
N_PhotoVoltaique::~N_PhotoVoltaique (void)
{
ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoVoltaique::~N_PhotoVoltaique <-" << std::endl;
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoVoltaique::~N_PhotoVoltaique ->" << std::endl;
LE's avatar
LE committed
}

// ============================================================================
// N_PhotoVoltaique::range_up
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void N_PhotoVoltaique::range_up (void)
LE's avatar
LE committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoVoltaique::range_up( ).");
LE's avatar
LE committed

std::stringstream cmd_to_send;

  //- update range idx
  this->get_ElectroMeterRange();

LE's avatar
LE committed
	_range += 1;
ELATTAOUI's avatar
ELATTAOUI committed
/*
	//- get range limit
	switch(_MCCE2electroTypeNumber)
	{
	case 1 :	_rangeLimit = 3;
		break;
	case 2 :
	case 3 :	_rangeLimit = 7;
		break;
	}
*/
LE's avatar
LE committed
	if(_range > _rangeLimit)
	{
		_range = _rangeLimit;
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("OUT_OF_RANGE",
LE's avatar
LE committed
												"Range up limit reached.",
												"N_PhotoVoltaique::range_up( ).");
	}

	//- build and send the command
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << _range;
LE's avatar
LE committed
	_electrometerProtocol->set_range(cmd_to_send.str());
}

// ============================================================================
// N_PhotoVoltaique::range_down
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void N_PhotoVoltaique::range_down (void)
LE's avatar
LE committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoVoltaique::range_down( ).");
LE's avatar
LE committed

std::stringstream cmd_to_send;

  //- update range idx
  this->get_ElectroMeterRange();

LE's avatar
LE committed
	_range -= 1;
ELATTAOUI's avatar
ELATTAOUI committed
/*
	//- get range limit
	switch(_MCCE2electroTypeNumber)
	{
	case 1 :	_rangeLimit = 3;
		break;
	case 2 :
	case 3 :	_rangeLimit = 7;
		break;
	}
*/
LE's avatar
LE committed
	if(_range < 0)
	{
		_range = 0;
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("OUT_OF_RANGE",
LE's avatar
LE committed
												"Range down limit reached.",
												"N_PhotoVoltaique::range_down( ).");
	}

	//- build and send the command
//	_rangeStr = NType1_rangeValue[_range];
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << _range;
ELATTAOUI's avatar
ELATTAOUI committed

LE's avatar
LE committed
	_electrometerProtocol->set_range(cmd_to_send.str());
}

// ============================================================================
// N_PhotoVoltaique::get_ElectroMeterFrequency Filter
// ============================================================================
std::string N_PhotoVoltaique::get_ElectroMeterFrequency (void)
ELATTAOUI's avatar
ELATTAOUI committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
LE's avatar
LE committed
												"N_PhotoVoltaique::get_ElectroMeterFrequency( ).");
ELATTAOUI's avatar
ELATTAOUI committed

ELATTAOUI's avatar
ELATTAOUI committed
	return _electrometerProtocol->get_frequency();
LE's avatar
LE committed
}

// ============================================================================
// N_PhotoVoltaique::set_ElectroMeterFrequency Filter
// ============================================================================
void N_PhotoVoltaique::set_ElectroMeterFrequency (std::string freqFilter)
ELATTAOUI's avatar
ELATTAOUI committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
LE's avatar
LE committed
												"N_PhotoVoltaique::set_ElectroMeterFrequency( ).");
ELATTAOUI's avatar
ELATTAOUI committed

ELATTAOUI's avatar
ELATTAOUI committed
  _electrometerProtocol->set_frequency(freqFilter);
LE's avatar
LE committed
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
// N_PhotoVoltaique::set_ElectroMeterRange
ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void N_PhotoVoltaique::set_ElectroMeterRange (std::string rgStr)
ELATTAOUI's avatar
ELATTAOUI committed
{
std::stringstream range_cmd_to_send;

ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoVoltaique::set_ElectroMeterRange( ).");

ELATTAOUI's avatar
ELATTAOUI committed
	//- switch the novelec type :
	switch(_MCCE2electroTypeNumber)
	{
ELATTAOUI's avatar
ELATTAOUI committed
	case 1 : _range = Novelec_MCCE2::check_range_value(rgStr, NType1_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
ELATTAOUI's avatar
ELATTAOUI committed
	case 2 : _range = Novelec_MCCE2::check_range_value(rgStr, NType2_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
ELATTAOUI's avatar
ELATTAOUI committed
	case 3 : _range = Novelec_MCCE2::check_range_value(rgStr, NType3_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
	}

ELATTAOUI's avatar
ELATTAOUI committed
	if (_range < 0)
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INVALID_PARAMETER",
ELATTAOUI's avatar
ELATTAOUI committed
												  "This electrometer does not support this range value.",
ELATTAOUI's avatar
ELATTAOUI committed
												  "N_PhotoVoltaique::set_ElectroMeterRange( ).");
ELATTAOUI's avatar
ELATTAOUI committed
	//- it is OK
ELATTAOUI's avatar
ELATTAOUI committed
	range_cmd_to_send << _range;
ELATTAOUI's avatar
ELATTAOUI committed

ELATTAOUI's avatar
ELATTAOUI committed
	_electrometerProtocol->set_range(range_cmd_to_send.str());
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// N_PhotoVoltaique::get_ElectroMeterRange
// ============================================================================
std::string N_PhotoVoltaique::get_ElectroMeterRange()
{
std::string rangeStr("");

  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoVoltaique::get_ElectroMeterRange( ).");

	rangeStr = this->_electrometerProtocol->get_range();

	//- switch the novelec type :
	switch(_MCCE2electroTypeNumber)
	{
ELATTAOUI's avatar
ELATTAOUI committed
	case 1 : 
        _range = Novelec_MCCE2::check_range_value(rangeStr, NType1_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
ELATTAOUI's avatar
ELATTAOUI committed
	case 2 : 
        _range = Novelec_MCCE2::check_range_value(rangeStr, NType2_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
ELATTAOUI's avatar
ELATTAOUI committed
	case 3 :
        _range = Novelec_MCCE2::check_range_value(rangeStr, NType3_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
	}

	if (_range < 0)
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INVALID_PARAMETER",
ELATTAOUI's avatar
ELATTAOUI committed
												  "Cannot find the applied range value.",
												  "N_PhotoVoltaique::get_ElectroMeterRange( ).");

	return rangeStr;
ELATTAOUI's avatar
ELATTAOUI committed
}