add attribute info to AttributeProxy

This commit is contained in:
Grzegorz Kowalski 2023-02-07 18:48:06 +01:00
parent b0be10e25d
commit 5c829d936f
4 changed files with 321 additions and 22 deletions

View File

@ -16,4 +16,10 @@
#include <tango/tango.h>
namespace lut_Tango
{
static const char* DispLevelNames[] = {"OPERATOR", "EXPERT", "DL_UNKNOWN"};
static const char* AttrDataFormatNames[] = {"SCALAR", "SPECTRUM", "IMAGE", "FMT_UNKNOWN"};
}
#endif /* __TANGO_INCLUDES_H__ */

View File

@ -15,9 +15,9 @@
// WRAPPER CLASS --------------------------------------------------------------
AttributeProxyWrapper::AttributeProxyWrapper(const char* name)
: type_cached(false)
{
attr = new Tango::AttributeProxy(name);
cache = attr->get_config();
}
AttributeProxyWrapper::~AttributeProxyWrapper()
@ -25,13 +25,64 @@ AttributeProxyWrapper::~AttributeProxyWrapper()
delete attr;
}
Tango::DeviceAttribute read_attr(AttributeProxyWrapper* udata)
int AttributeProxyWrapper::type()
{
Tango::DeviceAttribute attr_data = udata->attr->read();
udata->type_desc.type = attr_data.get_type();
udata->type_desc.format = attr_data.get_data_format();
udata->type_cached = true;
return attr_data;
return cache.data_type;
}
const char* AttributeProxyWrapper::type_name()
{
return Tango::CmdArgTypeName[cache.data_type];
}
Tango::AttrDataFormat AttributeProxyWrapper::format()
{
return cache.data_format;
}
Tango::DispLevel AttributeProxyWrapper::disp_level()
{
return cache.disp_level;
}
std::string AttributeProxyWrapper::label()
{
return cache.label;
}
std::string AttributeProxyWrapper::description()
{
return cache.description;
}
std::string AttributeProxyWrapper::disp_format()
{
return cache.format;
}
std::string AttributeProxyWrapper::unit()
{
return cache.unit;
}
std::vector<std::string> AttributeProxyWrapper::enum_labels()
{
return cache.enum_labels;
}
int AttributeProxyWrapper::max_dim_x()
{
return cache.max_dim_x;
}
int AttributeProxyWrapper::max_dim_y()
{
return cache.max_dim_y;
}
bool AttributeProxyWrapper::is_read_only()
{
return (cache.writable == Tango::READ);
}
// TANGO API ------------------------------------------------------------------
@ -71,6 +122,196 @@ int lut_AttributeProxy_status(lua_State* L)
return 1;
}
int lut_AttributeProxy_type(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:type()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
std::string type;
switch(udata->type())
{
case Tango::DEV_VOID: // 0 - void
type = "nil";
break;
case Tango::DEV_BOOLEAN: // 1 - bool
type = "boolean";
break;
case Tango::DEV_SHORT: // 2 - short
case Tango::DEV_LONG: // 3 - long
case Tango::DEV_FLOAT: // 4 - float
case Tango::DEV_DOUBLE: // 5 - double
case Tango::DEV_USHORT: // 6 - ushort
case Tango::DEV_ULONG: // 7 - ulong
case Tango::DEV_LONG64: // 23 - long64
case Tango::DEV_ULONG64: // 24 - ulong64
case Tango::DEV_INT: // 27 - int
type = "number";
break;
case Tango::DEV_STRING: // 8 - string
case Tango::DEVVAR_CHARARRAY: // 9 - char[]
case Tango::CONST_DEV_STRING: // 20 - const string
case Tango::DEV_UCHAR: // 22 - uchar
type = "string";
break;
case Tango::DEVVAR_SHORTARRAY: // 10 - short[]
case Tango::DEVVAR_LONGARRAY: // 11 - long[]
case Tango::DEVVAR_FLOATARRAY: // 12 - float[]
case Tango::DEVVAR_DOUBLEARRAY: // 13 - double[]
case Tango::DEVVAR_USHORTARRAY: // 14 - ushort[]
case Tango::DEVVAR_ULONGARRAY: // 15 - ulong[]
case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[]
case Tango::DEVVAR_ULONG64ARRAY: // 26 - ulong64[]
type = "table(number)";
break;
case Tango::DEVVAR_STRINGARRAY: // 16 - string[]
type = "table(string)";
break;
case Tango::DEV_STATE: // 19 - DevState
type = "DevState";
break;
case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[]
type = "table(boolean)";
break;
case Tango::DEVVAR_STATEARRAY: // 31 - DevState[]
type = "table(DevState)";
break;
case Tango::DEVVAR_LONGSTRINGARRAY: // 17 - longstring[] ???
case Tango::DEVVAR_DOUBLESTRINGARRAY: // 18 - doublestring[] ???
case Tango::DEV_ENCODED: // 28 - DevEncoded
case Tango::DEV_ENUM: // 29 - DevEnum
case Tango::DEV_PIPE_BLOB: // 30 - DevPipeBlob
case Tango::DATA_TYPE_UNKNOWN: // 32 - unknown
default:
type = "-not-supported-";
break;
}
Tango::AttrDataFormat format = udata->format();
if(format == Tango::SCALAR)
;
else if(format == Tango::SPECTRUM)
type = "table(" + type + ")";
else
type = "-not-supported-";
lua_pushstring(L, type.c_str());
return 1;
}
int lut_AttributeProxy_tango_type(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:tango_type()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, udata->type_name());
return 1;
}
int lut_AttributeProxy_format(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:format()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, lut_Tango::AttrDataFormatNames[udata->format()]);
return 1;
}
int lut_AttributeProxy_disp_level(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:disp_level()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, lut_Tango::DispLevelNames[udata->disp_level()]);
return 1;
}
int lut_AttributeProxy_label(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:label()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, udata->label().c_str());
return 1;
}
int lut_AttributeProxy_description(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:description()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, udata->description().c_str());
return 1;
}
int lut_AttributeProxy_disp_format(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:disp_format()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, udata->disp_format().c_str());
return 1;
}
int lut_AttributeProxy_unit(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:unit()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushstring(L, udata->unit().c_str());
return 1;
}
int lut_AttributeProxy_enum_labels(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:enum_labels()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
push_string_table(L, udata->enum_labels());
return 1;
}
int lut_AttributeProxy_max_dim_x(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:max_dim_x()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushnumber(L, udata->max_dim_x());
return 1;
}
int lut_AttributeProxy_max_dim_y(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:max_dim_y()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushnumber(L, udata->max_dim_y());
return 1;
}
int lut_AttributeProxy_is_read_only(lua_State* L)
{
LUT_LOG(TRACE, "TANGO API AttributeProxy:is_read_only()");
AttributeProxyWrapper* udata = (AttributeProxyWrapper*)lut_getobj(L, 1);
lua_pushboolean(L, udata->is_read_only());
return 1;
}
// LUA API --------------------------------------------------------------------
void lut_lua_register_AttributeProxy(lua_State* L)
{
@ -129,19 +370,12 @@ int lut_AttributeProxy_call(lua_State* L)
{
// called without arguments - read attribute
LUT_LOG(TRACE, "Reading attribute %s", attr_name.c_str());
lut_fromTangoType(L, read_attr(udata), udata->type_desc.type, udata->type_desc.format);
lut_fromTangoType(L, udata->attr->read(), udata->type(), udata->format());
return 1;
}
else
{
if(!udata->type_cached)
{
// no cached type mapping
LUT_LOG(TRACE, "Type mapping for attribute %s doesn't exist, reading first", attr_name.c_str());
read_attr(udata);
}
Tango::DeviceAttribute v = lut_toTangoType<Tango::DeviceAttribute>(L, 2, udata->type_desc.type, udata->type_desc.format);
Tango::DeviceAttribute v = lut_toTangoType<Tango::DeviceAttribute>(L, 2, udata->type(), udata->format());
v.set_name(attr_name);
udata->attr->write(v);
return 0;

View File

@ -22,6 +22,7 @@
#include <core/utils.h>
#include <core/lua/object.h>
#include <core/lua/stack.h>
#include <core/lua/version_agnostic.h>
#include <core/logging/log.h>
@ -35,18 +36,43 @@
class AttributeProxyWrapper
{
public:
Tango::AttributeProxy* attr;
AttributeProxyWrapper(const char* name);
~AttributeProxyWrapper();
Tango::AttributeProxy* attr;
AttrTypeDescription type_desc;
bool type_cached;
};
Tango::DeviceAttribute read_attr(AttributeProxyWrapper* udata);
int type();
const char* type_name();
Tango::AttrDataFormat format();
Tango::DispLevel disp_level();
std::string label();
std::string description();
std::string disp_format();
std::string unit();
std::vector<std::string> enum_labels();
int max_dim_x();
int max_dim_y();
bool is_read_only();
private:
Tango::AttributeInfoEx cache;
};
// Tango API
int lut_AttributeProxy_state(lua_State* L);
int lut_AttributeProxy_status(lua_State* L);
int lut_AttributeProxy_type(lua_State* L);
int lut_AttributeProxy_tango_type(lua_State* L);
int lut_AttributeProxy_format(lua_State* L);
int lut_AttributeProxy_disp_level(lua_State* L);
int lut_AttributeProxy_label(lua_State* L);
int lut_AttributeProxy_description(lua_State* L);
int lut_AttributeProxy_disp_format(lua_State* L);
int lut_AttributeProxy_unit(lua_State* L);
int lut_AttributeProxy_enum_labels(lua_State* L);
int lut_AttributeProxy_max_dim_x(lua_State* L);
int lut_AttributeProxy_max_dim_y(lua_State* L);
int lut_AttributeProxy_is_read_only(lua_State* L);
// Lua API
void lut_lua_register_AttributeProxy(lua_State* L);
@ -61,8 +87,20 @@ static const luaL_Reg lut_AttributeProxy[] =
{ "call", lut_AttributeProxy_call },
// Tango API
{ "status", lut_AttributeProxy_status },
{ "state", lut_AttributeProxy_state },
{ "status", lut_AttributeProxy_status },
{ "type", lut_AttributeProxy_type },
{ "tango_type", lut_AttributeProxy_tango_type },
{ "format", lut_AttributeProxy_format },
{ "disp_level", lut_AttributeProxy_disp_level },
{ "label", lut_AttributeProxy_label },
{ "description", lut_AttributeProxy_description },
{ "disp_format", lut_AttributeProxy_disp_format },
{ "unit", lut_AttributeProxy_unit },
{ "enum_labels", lut_AttributeProxy_enum_labels },
{ "max_dim_x", lut_AttributeProxy_max_dim_x },
{ "max_dim_y", lut_AttributeProxy_max_dim_y },
{ "is_read_only", lut_AttributeProxy_is_read_only },
{ NULL, NULL }
};

View File

@ -29,3 +29,24 @@ ap(v+1)
print("Reading again")
print("ampli = "..ap())
print("Attribute info:")
print("type: "..tostring(ap:type()))
print("tango_type: "..tostring(ap:tango_type()))
print("format: "..tostring(ap:format()))
print("displ_level: "..tostring(ap:disp_level()))
print("label: "..tostring(ap:label()))
print("description: "..tostring(ap:description()))
print("disp_format: "..tostring(ap:disp_format()))
print("unit: "..tostring(ap:unit()))
local enum_labels = ap:enum_labels()
io.write("enum_labels: "..tostring(enum_labels))
io.write(": {")
for _,l in ipairs(enum_labels) do
io.write(tostring(l)..", ")
end
print("}")
print("max_dim_x: "..tostring(ap:max_dim_x()))
print("max_dim_y: "..tostring(ap:max_dim_y()))
print("read_only?: "..tostring(ap:is_read_only()))