Skip to content
Snippets Groups Projects
SimulatedE2PS.cpp 15.7 KiB
Newer Older
Claudio Scafuri's avatar
Claudio Scafuri committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
/*----- PROTECTED REGION ID(SimulatedE2PS.cpp) ENABLED START -----*/
/* clang-format on */
//=============================================================================
//
// file :        SimulatedE2PS.cpp
//
// description : C++ source for the SimulatedE2PS class and its commands.
//               The class is derived from Device. It represents the
//               CORBA servant object which will be accessed from the
//               network. All commands which can be executed on the
//               SimulatedE2PS are implemented in this file.
//
// project :     SimulatedE2PS
//
// This file is part of Tango device class.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango.  If not, see <http://www.gnu.org/licenses/>.
//
//
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#include "SimulatedE2PS.h"
#include "SimulatedE2PSClass.h"
/* clang-format off */
/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS.cpp

/**
 *  SimulatedE2PS class description:
 *    Simulated power supply for Elettra 2.0 tests (digiltal twin).
 *    Tango interface Loosely based on NGPS tango device
 */

//================================================================
//  The following table gives the correspondence
//  between command and method names.
//
//  Command name  |  Method name
//================================================================
//  State         |  Inherited (no method)
//  Status        |  Inherited (no method)
//  On            |  on
//  Off           |  off
//  Reset         |  reset
//  StartCycling  |  start_cycling
//  Abort         |  abort
//  fault         |  fault
//================================================================

//================================================================
//  Attributes managed are:
//================================================================
//  current     |  Tango::DevDouble	Scalar
//  voltage     |  Tango::DevDouble	Scalar
//  currentSet  |  Tango::DevDouble	Scalar
//================================================================

namespace SimulatedE2PS_ns
{
/*----- PROTECTED REGION ID(SimulatedE2PS::namespace_starting) ENABLED START -----*/
/* clang-format on */
//	static initializations
/* clang-format off */
/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::namespace_starting

//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::SimulatedE2PS()
 * Description:  Constructors for a Tango device
 *                implementing the classSimulatedE2PS
 */
//--------------------------------------------------------
SimulatedE2PS::SimulatedE2PS(Tango::DeviceClass *cl, std::string &s)
 : TANGO_BASE_CLASS(cl, s.c_str())
{
	/*----- PROTECTED REGION ID(SimulatedE2PS::constructor_1) ENABLED START -----*/
	/* clang-format on */
	init_device();
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::constructor_1
}
//--------------------------------------------------------
SimulatedE2PS::SimulatedE2PS(Tango::DeviceClass *cl, const char *s)
 : TANGO_BASE_CLASS(cl, s)
{
	/*----- PROTECTED REGION ID(SimulatedE2PS::constructor_2) ENABLED START -----*/
	/* clang-format on */
	init_device();
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::constructor_2
}
//--------------------------------------------------------
SimulatedE2PS::SimulatedE2PS(Tango::DeviceClass *cl, const char *s, const char *d)
 : TANGO_BASE_CLASS(cl, s, d)
{
	/*----- PROTECTED REGION ID(SimulatedE2PS::constructor_3) ENABLED START -----*/
	/* clang-format on */
	init_device();
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::constructor_3
}
//--------------------------------------------------------
SimulatedE2PS::~SimulatedE2PS()
{
	delete_device();
}

//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::delete_device()
 * Description:  will be called at device destruction or at init command
 */
//--------------------------------------------------------
void SimulatedE2PS::delete_device()
{
	DEBUG_STREAM << "SimulatedE2PS::delete_device() " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::delete_device) ENABLED START -----*/
	/* clang-format on */
	//	Delete device allocated objects
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::delete_device
}

//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::init_device()
 * Description:  will be called at device initialization.
 */
//--------------------------------------------------------
void SimulatedE2PS::init_device()
{
	DEBUG_STREAM << "SimulatedE2PS::init_device() create device " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::init_device_before) ENABLED START -----*/
	/* clang-format on */
	//	Initialization before get_device_property() call
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::init_device_before

	//	No device property to be read from database

	/*----- PROTECTED REGION ID(SimulatedE2PS::init_device) ENABLED START -----*/
	/* clang-format on */
	//	Initialize device
	// Initialise variables to default values
	_current= 0.0;
	_current_read= 0.0;
	_voltage= 0.1;
	_ohm = 0.2; // load resistance in ohm
	_busy = false;
	thread_running=false;
	Tango::MultiAttribute *attr_list = get_device_attr();
	attr_current = &(attr_list->get_w_attr_by_name("current"));
	try{
		attr_current->set_write_value(_current);
	}
	catch(...){} // ignore error!
	set_state(Tango::ON);
	INFO_STREAM << "SimulatedE2PS::init_device() create device  end " << device_name << endl;
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::init_device
}


//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::always_executed_hook()
 * Description:  method always executed before any command is executed
 */
//--------------------------------------------------------
void SimulatedE2PS::always_executed_hook()
{
	DEBUG_STREAM << "SimulatedE2PS::always_executed_hook()  " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::always_executed_hook) ENABLED START -----*/
	/* clang-format on */
	//	code always executed before all requests
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::always_executed_hook
}

//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::read_attr_hardware()
 * Description:  Hardware acquisition for attributes
 */
//--------------------------------------------------------
void SimulatedE2PS::read_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list))
{
	DEBUG_STREAM << "SimulatedE2PS::read_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::read_attr_hardware) ENABLED START -----*/
	/* clang-format on */
	//	Add your own code
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::read_attr_hardware
}
//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::write_attr_hardware()
 * Description:  Hardware writing for attributes
 */
//--------------------------------------------------------
void SimulatedE2PS::write_attr_hardware(TANGO_UNUSED(std::vector<long> &attr_list))
{
	DEBUG_STREAM << "SimulatedE2PS::write_attr_hardware(std::vector<long> &attr_list) entering... " << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::write_attr_hardware) ENABLED START -----*/
	/* clang-format on */
	//	Add your own code
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::write_attr_hardware
}

//--------------------------------------------------------
/**
 *	Read attribute current related method
 * Description:  The powersupply current setting in amps
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
//--------------------------------------------------------
void SimulatedE2PS::read_current(Tango::Attribute &attr)
{
	DEBUG_STREAM << "SimulatedE2PS::read_current(Tango::Attribute &attr) entering... " << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::read_current) ENABLED START -----*/
	/* clang-format on */
	//	Set the attribute value
	double delta=rand_r(&rand_r_seed)/RAND_MAX;
	if(get_state() == Tango::OFF){
		delta +=0.5;
		_current_read =  delta *0.0001;
	}
	else{
		delta -=0.5;
		_current_read = _current +( delta *0.0001 );
	}
	attr.set_value(&_current_read);
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::read_current
}
//--------------------------------------------------------
/**
 *	Write attribute current related method
 * Description:  The powersupply current setting in amps
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
//--------------------------------------------------------
void SimulatedE2PS::write_current(Tango::WAttribute &attr)
{
	DEBUG_STREAM << "SimulatedE2PS::write_current(Tango::WAttribute &attr) entering... " << std::endl;
	//	Retrieve write value
	attr.get_write_value(_current_read);
	attr.get_write_value(_current);
	_voltage = _current * _ohm;
	/*----- PROTECTED REGION ID(SimulatedE2PS::write_current) ENABLED START -----*/
	/* clang-format on */
	//	Add your own code
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::write_current
}
//--------------------------------------------------------
/**
 *	Read attribute voltage related method
 * Description:  The powersupply voltage in volts.
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
//--------------------------------------------------------
void SimulatedE2PS::read_voltage(Tango::Attribute &attr)
{
	DEBUG_STREAM << "SimulatedE2PS::read_voltage(Tango::Attribute &attr) entering... " << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::read_voltage) ENABLED START -----*/
	/* clang-format on */
	//	Set the attribute value
	attr.set_value(&_voltage);
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::read_voltage
}
//--------------------------------------------------------
/**
 *	Read attribute currentSet related method
 * Description:  The current set value as stored in the powersupply.
 *
 *	Data type:	Tango::DevDouble
 *	Attr type:	Scalar
 */
//--------------------------------------------------------
void SimulatedE2PS::read_currentSet(Tango::Attribute &attr)
{
	DEBUG_STREAM << "SimulatedE2PS::read_currentSet(Tango::Attribute &attr) entering... " << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::read_currentSet) ENABLED START -----*/
	/* clang-format on */
	//	Set the attribute value
	attr.set_value(&_current);
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::read_currentSet
}

//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::add_dynamic_attributes()
 * Description:  Create the dynamic attributes if any
 *                for specified device.
 */
//--------------------------------------------------------
void SimulatedE2PS::add_dynamic_attributes()
{
	/*----- PROTECTED REGION ID(SimulatedE2PS::add_dynamic_attributes) ENABLED START -----*/
	/* clang-format on */
	//	Add your own code to create and add dynamic attributes if any
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::add_dynamic_attributes
}

//--------------------------------------------------------
/**
 *	Command On related method
 * Description:  Switch powersupply ON.
 *
 */
//--------------------------------------------------------
void SimulatedE2PS::on()
{
	DEBUG_STREAM << "SimulatedE2PS::On()  - " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::on) ENABLED START -----*/
	/* clang-format on */

	//	Add your own code

	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::on
}
//--------------------------------------------------------
/**
 *	Command Off related method
 * Description:  Switch power supply OFF.
 *
 */
//--------------------------------------------------------
void SimulatedE2PS::off()
{
	DEBUG_STREAM << "SimulatedE2PS::Off()  - " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::off) ENABLED START -----*/
	/* clang-format on */

	//	Add your own code

	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::off
}
//--------------------------------------------------------
/**
 *	Command Reset related method
 * Description:  Reset the powersupply to a well known state.
 *
 */
//--------------------------------------------------------
void SimulatedE2PS::reset()
{
	DEBUG_STREAM << "SimulatedE2PS::Reset()  - " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::reset) ENABLED START -----*/
	/* clang-format on */

	//	Add your own code

	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::reset
}
//--------------------------------------------------------
/**
 *	Command StartCycling related method
 *
 *
 */
//--------------------------------------------------------
void SimulatedE2PS::start_cycling()
{
	DEBUG_STREAM << "SimulatedE2PS::StartCycling()  - " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::start_cycling) ENABLED START -----*/
	/* clang-format on */

	//	Add your own code

	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::start_cycling
}
//--------------------------------------------------------
/**
 *	Command Abort related method
 * Description:  stop ramp or cycling
 *
 */
//--------------------------------------------------------
void SimulatedE2PS::abort()
{
	DEBUG_STREAM << "SimulatedE2PS::Abort()  - " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::abort) ENABLED START -----*/
	/* clang-format on */

	//	Add your own code

	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::abort
}
//--------------------------------------------------------
/**
 *	Command fault related method
 * Description:  Force a simulated faulty condtion
 *
 */
//--------------------------------------------------------
void SimulatedE2PS::fault()
{
	DEBUG_STREAM << "SimulatedE2PS::fault()  - " << device_name << std::endl;
	/*----- PROTECTED REGION ID(SimulatedE2PS::fault) ENABLED START -----*/
	/* clang-format on */

	//	Add your own code

	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::fault
}
//--------------------------------------------------------
/**
 *	Method      : SimulatedE2PS::add_dynamic_commands()
 * Description:  Create the dynamic commands if any
 *                for specified device.
 */
//--------------------------------------------------------
void SimulatedE2PS::add_dynamic_commands()
{
	/*----- PROTECTED REGION ID(SimulatedE2PS::add_dynamic_commands) ENABLED START -----*/
	/* clang-format on */
	//	Add your own code to create and add dynamic commands if any
	/* clang-format off */
	/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::add_dynamic_commands
}

/*----- PROTECTED REGION ID(SimulatedE2PS::namespace_ending) ENABLED START -----*/
/* clang-format on */
//	Additional Methods
/* clang-format off */
/*----- PROTECTED REGION END -----*/	//	SimulatedE2PS::namespace_ending
} //	namespace