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
|
#ifndef _DATA_H_
#define _DATA_H_
//#include <RWOAttr.h>
#include <Tango.h>
#include <math.h>
#include <PLCServerProxy.h>
namespace PLCDataViewer_ns
{
template<typename T> class Attr: public Tango::Attr
{
public:
Attr(string name, long type, Tango::AttrWriteType rw_mode):Tango::Attr(name.c_str(), type, rw_mode){};
virtual ~Attr(){};
};
//- Abstract class : Data
template<typename T> class Data : public Tango::LogAdapter, public Attr<T>
{
public:
//Data(Tango::DeviceImpl* dev):Tango::LogAdapter(dev) {};
virtual ~Data() {};
virtual std::string get_type() = 0;
void setPLCProxy(PLCServerProxy* proxy) { plc = proxy;}
protected:
//- Abstract class : a Data is either readonly, writeonly or readwrite
Data(string name, long dataType, Tango::AttrWriteType rwType, PLCServerProxy* proxy, Tango::DeviceImpl* dev):Attr<T>(name, dataType, rwType), Tango::LogAdapter(dev), attrType(type), plc(proxy){};
long attrType;
PLCServerProxy* plc;
};
//- Read only Data class
template<typename T> class ROData : virtual public Data<T>
{
public:
ROData(string name, double offset, long dataType, PLCServerProxy* proxy, Tango::DeviceImpl* dev);
//ROData(Tango::DeviceImpl* dev, float offset):Data<T>(dev) { readAddress = offset;}
virtual ~ROData();
virtual void updateValueFromPLC(Tango::DevVarShortArray* plcData, long startOffset);
void setValue(T val) { *readValue = val;}
T* getValue() { return readValue;}
virtual void read(Tango::DeviceImpl *dev,Tango::Attribute &att);
virtual std::string get_type() { return "ROData"; }
double getReadAddress() { return readAddress; }
protected:
T* readValue;
double readAddress;
private:
unsigned short getBooleanMask(double address);
long getLongValue(short var1, short var2);
};
template<typename T>
ROData<T>::ROData(string name, double offset, long dataType, PLCServerProxy* proxy, Tango::DeviceImpl* dev):Data<T>(name, dataType, Tango::READ, proxy, dev), readAddress(offset)
{
readValue = 0;
readValue = new T;
}
template<typename T>
ROData<T>::~ROData()
{
DEBUG_STREAM << "Entering ROData<T>::~ROData()" << endl;
if(readValue)
{
delete readValue;
readValue = 0;
}
DEBUG_STREAM << "Exiting ROData<T>::~ROData()" << endl;
};
template<typename T>
void ROData<T>::read(Tango::DeviceImpl *dev,Tango::Attribute &att)
{
att.set_value(readValue);
}
template<typename T>
void ROData<T>::updateValueFromPLC(Tango::DevVarShortArray* plcData, long startOffset)
{
//- Inutile
}
//- Compute the mask used to get the boolean value from a word
template<typename T>
unsigned short ROData<T>::getBooleanMask(double addr)
{
//- Inutile
}
//- Get one long value from two words
template<typename T>
long ROData<T>::getLongValue(short var1, short var2)
{
//- Inutile
}
//- Write only Data class
template<typename T> class WOData : virtual public Data<T>
{
public:
WOData(string name, double offset, long dataType, PLCServerProxy* proxy, Tango::DeviceImpl* dev):Data<T>(name, dataType, Tango::WRITE, proxy, dev), writeAddress(offset) {};
//WOData(Tango::DeviceImpl* dev, double offset):Data<T>(dev) { writeAddress = offset;}
virtual ~WOData()
{
DEBUG_STREAM << "WOData<T>::~WOData()" << endl;
}
virtual void writeValueToPLC(T val);
void setValue(T val) { writeValue = val;}
T getValue() { return writeValue;}
virtual void write(Tango::DeviceImpl *dev,Tango::WAttribute &att);
virtual std::string get_type() { return "WOData"; }
double getWriteAddress() { return writeAddress; }
void setWriteAddress(double address) { writeAddress = address;}
protected:
T writeValue;
double writeAddress;
};
template<typename T>
void WOData<T>::writeValueToPLC(T val)
{
//-Inutile
}
template<typename T>
void WOData<T>::write(Tango::DeviceImpl *dev,Tango::WAttribute &att)
{
DEBUG_STREAM << "Entering WOData<T>::write" << endl;
att.get_write_value(writeValue);
DEBUG_STREAM << "writeValue = " << writeValue << endl;
this->writeValueToPLC(writeValue);
}
//- Read/Write Data class
template<typename T> class RWData : public ROData<T>, public WOData<T>
{
public:
RWData(string name, double readOffset, double writeOffset, long dataType, PLCServerProxy* proxy, Tango::DeviceImpl* dev):Data<T>(name, dataType, Tango::READ_WRITE, proxy, dev), ROData<T>(name, readOffset, dataType, proxy, dev), WOData<T>(name, writeOffset, dataType, proxy, dev) {};
virtual ~RWData()
{
DEBUG_STREAM << "RWData<T>::~RWData()" << endl;
}
virtual std::string get_type() { return "RWData"; }
};
}
#endif |
Partager