Skip to content
Snippets Groups Projects
USB2.h 6.75 KiB
Newer Older
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
/*----- PROTECTED REGION ID(USB2.h) ENABLED START -----*/
//=============================================================================
//
// file :        USB2.h
//
// description : Include file for the USB2 class
//
// project :     
//
// 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/>.
// 
// $Author: alessio $
//
// $Revision: 1.2 $
// $Date: 2018-10-24 08:12:41 $
//
// $HeadURL:  $
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#ifndef USB2_H
#define USB2_H

#include <tango.h>
#include <libusb-1.0/libusb.h>

/*----- PROTECTED REGION END -----*/	//	USB2.h

#ifdef TANGO_LOG
	// cppTango after c934adea (Merge branch 'remove-cout-definition' into 'main', 2022-05-23)
	// nothing to do
#else
	// cppTango 9.3-backports and older
	#define TANGO_LOG       cout
	#define TANGO_LOG_INFO  cout2
	#define TANGO_LOG_DEBUG cout3
#endif // TANGO_LOG

Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
/**
 *  USB2 class description:
 *    
 */

Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
namespace USB2_ns
{
/*----- PROTECTED REGION ID(USB2::Additional Class Declarations) ENABLED START -----*/

//	Additional Class Declarations

/*----- PROTECTED REGION END -----*/	//	USB2::Additional Class Declarations

class USB2 : public TANGO_BASE_CLASS
{

/*----- PROTECTED REGION ID(USB2::Data Members) ENABLED START -----*/

//	Add your own data members
	string init_error;

	libusb_context *ctx;
	int vid, pid, ep_up, ep_down; // FIXME
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	libusb_device_handle *dev_handle;
	int conn_state;

	enum event_type {READ, WRITE};
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed

	vector<unsigned char> data;

	int reconnections;

	enum {SLEEP, SELECT} multiplexing;
	timeval timeout_timeval, tout;
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
/*----- PROTECTED REGION END -----*/	//	USB2::Data Members

//	Device property data members
public:
	//	Timeout:	
	Tango::DevLong	timeout;
	//	VendorID:	
	std::string	vendorID;
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	//	ProductID:	
	std::string	productID;
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	//	Interface:	
	Tango::DevLong	interface;
	//	EndpointUP:	
	std::string	endpointUP;
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	//	EndpointDOWN:	
	std::string	endpointDOWN;
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	//	MaxPacketSize:	
	Tango::DevLong	maxPacketSize;

	bool	mandatoryNotDefined;

//	Attribute data members
public:
	Tango::DevLong	*attr_InputLength_read;
	Tango::DevLong	*attr_OutputLength_read;
	Tango::DevLong	*attr_Reconnections_read;

//	Constructors and destructors
public:
	/**
	 * Constructs a newly device object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	USB2(Tango::DeviceClass *cl,std::string &s);
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	/**
	 * Constructs a newly device object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	USB2(Tango::DeviceClass *cl,const char *s);
	/**
	 * Constructs a newly device object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device name
	 *	@param d	Device description.
	 */
	USB2(Tango::DeviceClass *cl,const char *s,const char *d);
	/**
	 * The device object destructor.
	 */
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed


//	Miscellaneous methods
public:
	/*
	 *	will be called at device destruction or at init command.
	 */
	void delete_device();
	/*
	 *	Initialize the device
	 */
	virtual void init_device();
	/*
	 *	Read the device properties from database
	 */
	void get_device_property();
	/*
	 *	Always executed method before execution command method.
	 */
	virtual void always_executed_hook();

	/*
	 *	Check if mandatory property has been set
	 */
	 void check_mandatory_property(Tango::DbDatum &class_prop, Tango::DbDatum &dev_prop);

//	Attribute methods
public:
	//--------------------------------------------------------
	/*
	 *	Method     : USB2::read_attr_hardware()
	 *	Description: Hardware acquisition for attributes.
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	 */
	//--------------------------------------------------------
	virtual void read_attr_hardware(std::vector<long> &attr_list);
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed

/**
 *	Attribute InputLength related methods
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
 *
 *	Data type:	Tango::DevLong
 *	Attr type:	Scalar
 */
	virtual void read_InputLength(Tango::Attribute &attr);
	virtual bool is_InputLength_allowed(Tango::AttReqType type);
/**
 *	Attribute OutputLength related methods
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
 *
 *	Data type:	Tango::DevLong
 *	Attr type:	Scalar
 */
	virtual void read_OutputLength(Tango::Attribute &attr);
	virtual bool is_OutputLength_allowed(Tango::AttReqType type);
/**
 *	Attribute Reconnections related methods
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
 *
 *	Data type:	Tango::DevLong
 *	Attr type:	Scalar
 */
	virtual void read_Reconnections(Tango::Attribute &attr);
	virtual bool is_Reconnections_allowed(Tango::AttReqType type);


	//--------------------------------------------------------
	/**
	 *	Method     : USB2::add_dynamic_attributes()
	 *	Description: Add dynamic attributes if any.
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	 */
	//--------------------------------------------------------
	void add_dynamic_attributes();




//	Command related methods
public:
	/**
	 *	Command Write related method
	 *
	 *
	 *	@param argin
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	 */
	virtual void write(const Tango::DevVarCharArray *argin);
	virtual bool is_Write_allowed(const CORBA::Any &any);
	/**
	 *	Command Read related method
	 *
	 *
	 *	@param argin
	 *	@returns
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	 */
	virtual Tango::DevVarCharArray *read(Tango::DevLong argin);
	virtual bool is_Read_allowed(const CORBA::Any &any);
	/**
	 *	Command ReadUntil related method
	 *
	 *
	 *	@param argin
	 *	@returns
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	 */
	virtual Tango::DevVarCharArray *read_until(const Tango::DevVarCharArray *argin);
	virtual bool is_ReadUntil_allowed(const CORBA::Any &any);


	//--------------------------------------------------------
	/**
	 *	Method     : USB2::add_dynamic_commands()
	 *	Description: Add dynamic commands if any.
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	 */
	//--------------------------------------------------------
	void add_dynamic_commands();

/*----- PROTECTED REGION ID(USB2::Additional Method prototypes) ENABLED START -----*/

//	Additional Method prototypes
	bool sleep(timeval);
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
	void open();
	int input_queue_length();
	int output_queue_length();
	void close();
	ssize_t _write(unsigned char*, size_t);
	void _read(size_t);
	void check_state(bool);
	int select(event_type);
	void resolve();
Alessio Igor Bogani's avatar
Alessio Igor Bogani committed
/*----- PROTECTED REGION END -----*/	//	USB2::Additional Method prototypes
};

/*----- PROTECTED REGION ID(USB2::Additional Classes Definitions) ENABLED START -----*/

//	Additional Classes Definitions

/*----- PROTECTED REGION END -----*/	//	USB2::Additional Classes Definitions

}	//	End of namespace

#endif   //	USB2_H