From 7d379fd5ddcced9e7b53213982fb3f43cbcb3996 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowalski Date: Mon, 6 Feb 2023 22:16:13 +0100 Subject: [PATCH] unify Tango types conversion --- .../AttributeProxy/lut_AttributeProxy.cpp | 5 +- .../tango/AttributeProxy/lut_AttributeProxy.h | 2 +- .../tango/DeviceProxy/lut_DeviceProxy.cpp | 9 +- src/core/tango/DeviceProxy/lut_DeviceProxy.h | 3 +- src/core/tango/attrdata.cpp | 357 ------------------ src/core/tango/attrdata.h | 50 --- src/core/tango/cmddata.h | 41 -- src/core/tango/{cmddata.cpp => types.cpp} | 161 +++++--- src/core/tango/types.h | 52 +++ 9 files changed, 179 insertions(+), 501 deletions(-) delete mode 100644 src/core/tango/attrdata.cpp delete mode 100644 src/core/tango/attrdata.h delete mode 100644 src/core/tango/cmddata.h rename src/core/tango/{cmddata.cpp => types.cpp} (68%) create mode 100644 src/core/tango/types.h diff --git a/src/core/tango/AttributeProxy/lut_AttributeProxy.cpp b/src/core/tango/AttributeProxy/lut_AttributeProxy.cpp index 9429996..55a46ba 100644 --- a/src/core/tango/AttributeProxy/lut_AttributeProxy.cpp +++ b/src/core/tango/AttributeProxy/lut_AttributeProxy.cpp @@ -129,7 +129,7 @@ int lut_AttributeProxy_call(lua_State* L) { // called without arguments - read attribute LUT_LOG(TRACE, "Reading attribute %s", attr_name.c_str()); - unpack_attr_data(L, read_attr(udata)); + lut_fromTangoType(L, read_attr(udata), udata->type_desc.type, udata->type_desc.format); return 1; } else @@ -141,7 +141,8 @@ int lut_AttributeProxy_call(lua_State* L) read_attr(udata); } - Tango::DeviceAttribute v = pack_attr_data(L, 2, udata->type_desc, attr_name.c_str()); + Tango::DeviceAttribute v = lut_toTangoType(L, 2, udata->type_desc.type, udata->type_desc.format); + v.set_name(attr_name); udata->attr->write(v); return 0; } diff --git a/src/core/tango/AttributeProxy/lut_AttributeProxy.h b/src/core/tango/AttributeProxy/lut_AttributeProxy.h index 51cde89..a19812b 100644 --- a/src/core/tango/AttributeProxy/lut_AttributeProxy.h +++ b/src/core/tango/AttributeProxy/lut_AttributeProxy.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include diff --git a/src/core/tango/DeviceProxy/lut_DeviceProxy.cpp b/src/core/tango/DeviceProxy/lut_DeviceProxy.cpp index 44f26d8..07a42b6 100644 --- a/src/core/tango/DeviceProxy/lut_DeviceProxy.cpp +++ b/src/core/tango/DeviceProxy/lut_DeviceProxy.cpp @@ -46,9 +46,9 @@ int cmd_wrapper(lua_State* L) LUT_LOG(TRACE, "Command: %s in:%d out:%d", full_name.c_str(), in_type, out_type); - Tango::DeviceData in = pack_cmd_data(L, 1, in_type); + Tango::DeviceData in = lut_toTangoType(L, 1, in_type); Tango::DeviceData out = udata->dev->command_inout(cmd_name, in); - unpack_cmd_data(L, out, out_type); + lut_fromTangoType(L, out, out_type); } catch(Tango::DevFailed e) { @@ -199,7 +199,7 @@ int lut_DeviceProxy_index(lua_State* L) Tango::DeviceAttribute attr = udata->dev->read_attribute(name); udata->type_map[name].type = attr.get_type(); udata->type_map[name].format = attr.get_data_format(); - unpack_attr_data(L, attr); + lut_fromTangoType(L, attr, attr.get_type(), attr.get_data_format()); } delete cmdlist; } @@ -241,7 +241,8 @@ int lut_DeviceProxy_newindex(lua_State* L) udata->type_map[attr_name].format = attr.get_data_format(); } - Tango::DeviceAttribute v = pack_attr_data(L, 3, udata->type_map[attr_name], attr_name); + Tango::DeviceAttribute v = lut_toTangoType(L, 3, udata->type_map[attr_name].type, udata->type_map[attr_name].format); + v.set_name(attr_name); udata->dev->write_attribute(v); } catch(Tango::DevFailed e) diff --git a/src/core/tango/DeviceProxy/lut_DeviceProxy.h b/src/core/tango/DeviceProxy/lut_DeviceProxy.h index 6e408fe..c86f7e5 100644 --- a/src/core/tango/DeviceProxy/lut_DeviceProxy.h +++ b/src/core/tango/DeviceProxy/lut_DeviceProxy.h @@ -25,8 +25,7 @@ #include #include -#include -#include +#include #include #define LUT_DEVICEPROXY "lut_DeviceProxy" diff --git a/src/core/tango/attrdata.cpp b/src/core/tango/attrdata.cpp deleted file mode 100644 index 5bb0042..0000000 --- a/src/core/tango/attrdata.cpp +++ /dev/null @@ -1,357 +0,0 @@ -//----------------------------------------------------------------------------- -// -// luTango - Lua binding for Tango -// -// Copyright (C) 2023 Grzegorz Kowalski -// See LICENSE for legal information -// -// file: attrdata.cpp -// -// Attribute data handling, type conversions -// -//----------------------------------------------------------------------------- - -#include "attrdata.h" - -void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr) -{ - switch(attr.get_type()) - { - case Tango::DEV_VOID: // 0 - void - lua_pushnil(L); - break; - - case Tango::DEV_BOOLEAN: // 1 - bool - push_attr_bool(L, attr); - break; - - case Tango::DEV_SHORT: // 2 - short - push_attr_number(L, attr); - break; - - case Tango::DEV_LONG: // 3 - long - push_attr_number(L, attr); - break; - - case Tango::DEV_FLOAT: // 4 - float - push_attr_number(L, attr); - break; - - case Tango::DEV_DOUBLE: // 5 - double - push_attr_number(L, attr); - break; - - case Tango::DEV_USHORT: // 6 - ushort - push_attr_number(L, attr); - break; - - case Tango::DEV_ULONG: // 7 - ulong - push_attr_number(L, attr); - break; - - case Tango::DEV_STRING: // 8 - string - case Tango::DEVVAR_CHARARRAY: // 9 - char[] - case Tango::CONST_DEV_STRING: // 20 - const string - push_attr_string(L, attr); - break; - - case Tango::DEVVAR_SHORTARRAY: // 10 - short[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_LONGARRAY: // 11 - long[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_FLOATARRAY: // 12 - float[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_DOUBLEARRAY: // 13 - double[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_USHORTARRAY: // 14 - ushort[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_ULONGARRAY: // 15 - ulong[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_STRINGARRAY: // 16 - string[] - { - std::vector v; - attr >> v; - push_string_table(L, v); - break; - } - - case Tango::DEV_STATE: // 19 - DevState - { - Tango::DevState v; - attr >> v; - lut_DevState(L, v); - break; - } - - case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[] - { - std::vector v; - attr >> v; - push_bool_table(L, v); - break; - } - - case Tango::DEV_UCHAR: // 22 - uchar - { - unsigned char v; - attr >> v; - lua_pushstring(L, (const char *)&v); - break; - } - - case Tango::DEV_LONG64: // 23 - long64 - push_attr_number(L, attr); - break; - - case Tango::DEV_ULONG64: // 24 - ulong64 - push_attr_number(L, attr); - break; - - case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEVVAR_ULONG64ARRAY: // 26 - ulong64[] - { - std::vector v; - attr >> v; - push_number_table(L, v); - break; - } - - case Tango::DEV_INT: // 27 - int - push_attr_number(L, attr); - 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::DEVVAR_STATEARRAY: // 31 - DevState[] - LUT_LOG(WARNING, "%s: Attribute type not implemented for reading yet: %d", attr.name.c_str(), attr.get_type()); - lua_pushnil(L); - break; - - case Tango::DATA_TYPE_UNKNOWN: // 32 - unknown - default: - LUT_LOG(ERROR, "%s: Device returned unknown type: %d", attr.name.c_str(), attr.get_type()); - lua_pushnil(L); - //return luaL_error(L, "Device returned type %d, that is unknown or unsupported.", attr.get_type()); - } -} - -template -void push_attr_number(lua_State* L, Tango::DeviceAttribute attr) -{ - Tango::AttrDataFormat fmt = attr.get_data_format(); - if(fmt == Tango::SCALAR) - { - T v; - attr >> v; - lua_pushnumber(L, v); - } - else if(fmt == Tango::SPECTRUM) - { - std::vector v; - attr >> v; - push_number_table(L, v); - } - else if(fmt == Tango::IMAGE) - { - // std::vector> v; - // //attr >> v; - // // push_number_2d(L, v); - LUT_LOG(WARNING, "%s: IMAGE data format is not supported yet", attr.name.c_str()); - lua_pushnil(L); - } - else - { - LUT_LOG(ERROR, "%s: Invalid data format", attr.name.c_str()); - lua_pushnil(L); - } -} - -void push_attr_bool(lua_State* L, Tango::DeviceAttribute attr) -{ - Tango::AttrDataFormat fmt = attr.get_data_format(); - if(fmt == Tango::SCALAR) - { - bool v; - attr >> v; - lua_pushboolean(L, v); - } - else if(fmt == Tango::SPECTRUM) - { - std::vector v; - attr >> v; - push_bool_table(L, v); - } - else if(fmt == Tango::IMAGE) - { - LUT_LOG(WARNING, "%s: IMAGE data format is not supported yet", attr.name.c_str()); - lua_pushnil(L); - } - else - { - LUT_LOG(ERROR, "%s: Invalid data format", attr.name.c_str()); - lua_pushnil(L); - } - -} - -void push_attr_string(lua_State* L, Tango::DeviceAttribute attr) -{ - Tango::AttrDataFormat fmt = attr.get_data_format(); - if(fmt == Tango::SCALAR) - { - std::string v; - attr >> v; - lua_pushstring(L, v.c_str()); - } - else if(fmt == Tango::SPECTRUM) - { - std::vector v; - attr >> v; - push_string_table(L, v); - } - else if(fmt == Tango::IMAGE) - { - LUT_LOG(WARNING, "%s: IMAGE data format is not supported yet", attr.name.c_str()); - lua_pushnil(L); - } - else - { - LUT_LOG(ERROR, "%s: Invalid data format", attr.name.c_str()); - lua_pushnil(L); - } -} - -Tango::DeviceAttribute pack_attr_data(lua_State* L, int idx, AttrTypeDescription d, const char* attr_name) -{ - switch(d.type) - { - case Tango::DEV_VOID: // 0 - void - LUT_LOG(ERROR, "%s: Void is not writeable type!", attr_name); - break; - - case Tango::DEV_BOOLEAN: // 1 - bool - // Lua 5.1 is missing the luaL_checkboolean function - return pack_attr_value(attr_name, (bool)lua_toboolean(L, idx)); - break; - - case Tango::DEV_SHORT: // 2 - short - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_LONG: // 3 - long - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_FLOAT: // 4 - float - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_DOUBLE: // 5 - double - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_USHORT: // 6 - ushort - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_ULONG: // 7 - ulong - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_STRING: // 8 - string - case Tango::DEVVAR_CHARARRAY: // 9 - char[] - case Tango::CONST_DEV_STRING: // 20 - const string - return pack_attr_value(attr_name, luaL_checkstring(L, idx)); - break; - - case Tango::DEV_LONG64: // 23 - long64 - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_ULONG64: // 24 - ulong64 - return pack_attr_value(attr_name, pop_number(L, idx)); - break; - - case Tango::DEV_INT: // 27 - int - return pack_attr_value(attr_name, pop_number(L, idx)); - 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_STRINGARRAY: // 16 - string[] - case Tango::DEVVAR_LONGSTRINGARRAY: // 17 - longstring[] ??? - case Tango::DEVVAR_DOUBLESTRINGARRAY: // 18 - doublestring[] ??? - case Tango::DEV_STATE: // 19 - DevState - case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[] - case Tango::DEV_UCHAR: // 22 - uchar - case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[] - case Tango::DEVVAR_ULONG64ARRAY: // 26 - ulong64[] - case Tango::DEV_ENCODED: // 28 - DevEncoded - case Tango::DEV_ENUM: // 29 - DevEnum - case Tango::DEV_PIPE_BLOB: // 30 - DevPipeBlob - case Tango::DEVVAR_STATEARRAY: // 31 - DevState[] - LUT_LOG(WARNING, "%s: Attribute type not implemented for writing yet: %d", attr_name, d.type); - break; - - case Tango::DATA_TYPE_UNKNOWN: // 32 - unknown - default: - LUT_LOG(ERROR, "%s: Attribute reports unknown type: %d", attr_name, d.type); - } -} - -template -Tango::DeviceAttribute pack_attr_value(const char* name, T value) -{ - Tango::DeviceAttribute v(name, value); - return v; -} diff --git a/src/core/tango/attrdata.h b/src/core/tango/attrdata.h deleted file mode 100644 index c08e775..0000000 --- a/src/core/tango/attrdata.h +++ /dev/null @@ -1,50 +0,0 @@ -//----------------------------------------------------------------------------- -// -// luTango - Lua binding for Tango -// -// Copyright (C) 2023 Grzegorz Kowalski -// See LICENSE for legal information -// -// file: attrdata.h -// -// Attribute data handling, type conversions -// -//----------------------------------------------------------------------------- - -#ifndef __ATTRDATA_H__ -# define __ATTRDATA_H__ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -typedef struct -{ - int type; - Tango::AttrDataFormat format; -} AttrTypeDescription; - -typedef std::map AttrTypeMap; - -// READ ATTRIBUTE ------------------------------------------------------------- -void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr); - -template -void push_attr_number(lua_State* L, Tango::DeviceAttribute attr); -void push_attr_bool(lua_State* L, Tango::DeviceAttribute attr); -void push_attr_string(lua_State* L, Tango::DeviceAttribute attr); - -// WRITE ATTRIBUTE ------------------------------------------------------------ -Tango::DeviceAttribute pack_attr_data(lua_State* L, int idx, AttrTypeDescription d, const char* attr_name); - -template -Tango::DeviceAttribute pack_attr_value(const char* name, T value); - -#endif /* __ATTRDATA_H__ */ diff --git a/src/core/tango/cmddata.h b/src/core/tango/cmddata.h deleted file mode 100644 index a48c762..0000000 --- a/src/core/tango/cmddata.h +++ /dev/null @@ -1,41 +0,0 @@ -//----------------------------------------------------------------------------- -// -// luTango - Lua binding for Tango -// -// Copyright (C) 2023 Grzegorz Kowalski -// See LICENSE for legal information -// -// file: cmddata.h -// -// Command data handling, type conversions -// -//----------------------------------------------------------------------------- - -#ifndef __CMDDATA_H__ -# define __CMDDATA_H__ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -typedef std::map CmdInfoMap; - -// DATA OUT ------------------------------------------------------------------- -void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type); - -// DATA IN -------------------------------------------------------------------- -template -void push_cmd_number(lua_State* L, Tango::DeviceData data); -void push_cmd_bool(lua_State* L, Tango::DeviceData data); -void push_cmd_string(lua_State* L, Tango::DeviceData data); - -Tango::DeviceData pack_cmd_data(lua_State* L, int idx, long type); - -#endif /* __CMDDATA_H__ */ diff --git a/src/core/tango/cmddata.cpp b/src/core/tango/types.cpp similarity index 68% rename from src/core/tango/cmddata.cpp rename to src/core/tango/types.cpp index 8007c9d..d11d1dc 100644 --- a/src/core/tango/cmddata.cpp +++ b/src/core/tango/types.cpp @@ -5,15 +5,19 @@ // Copyright (C) 2023 Grzegorz Kowalski // See LICENSE for legal information // -// file: cmddata.cpp +// file: types.cpp // -// Command data handling, type conversions +// Tango type conversions // //----------------------------------------------------------------------------- -#include "cmddata.h" +#include "types.h" -void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type) +template void lut_fromTangoType(lua_State* L, Tango::DeviceAttribute data, long type, Tango::AttrDataFormat format); +template void lut_fromTangoType(lua_State* L, Tango::DeviceData data, long type, Tango::AttrDataFormat format); + +template +void lut_fromTangoType(lua_State* L, T data, long type, Tango::AttrDataFormat format) { switch(type) { @@ -22,37 +26,37 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type) break; case Tango::DEV_BOOLEAN: // 1 - bool - push_cmd_bool(L, data); + extract_bool(L, data, format); break; case Tango::DEV_SHORT: // 2 - short - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_LONG: // 3 - long - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_FLOAT: // 4 - float - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_DOUBLE: // 5 - double - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_USHORT: // 6 - ushort - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_ULONG: // 7 - ulong - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_STRING: // 8 - string case Tango::DEVVAR_CHARARRAY: // 9 - char[] case Tango::CONST_DEV_STRING: // 20 - const string - push_cmd_string(L, data); + extract_string(L, data, format); break; case Tango::DEVVAR_SHORTARRAY: // 10 - short[] @@ -128,11 +132,11 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type) } case Tango::DEV_LONG64: // 23 - long64 - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEV_ULONG64: // 24 - ulong64 - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[] @@ -152,12 +156,12 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type) } case Tango::DEV_INT: // 27 - int - push_cmd_number(L, data); + extract_number(L, data, format); break; case Tango::DEVVAR_LONGSTRINGARRAY: // 17 - longstring[] ??? case Tango::DEVVAR_DOUBLESTRINGARRAY: // 18 - doublestring[] ??? - case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[] - cannot insert std::vector to DeviceData + case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[] case Tango::DEV_ENCODED: // 28 - DevEncoded case Tango::DEV_ENUM: // 29 - DevEnum case Tango::DEV_PIPE_BLOB: // 30 - DevPipeBlob @@ -170,36 +174,17 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type) default: LUT_LOG(ERROR, "Unknown type: %d", type); lua_pushnil(L); - //return luaL_error(L, "Device returned type %d, that is unknown or unsupported.", attr.get_type()); + break; } } +template Tango::DeviceAttribute lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format); +template Tango::DeviceData lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format); + template -void push_cmd_number(lua_State* L, Tango::DeviceData data) +T lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format) { - T v; - data >> v; - lua_pushnumber(L, v); -} - -void push_cmd_bool(lua_State* L, Tango::DeviceData data) -{ - bool v; - data >> v; - lua_pushboolean(L, v); - -} - -void push_cmd_string(lua_State* L, Tango::DeviceData data) -{ - std::string v; - data >> v; - lua_pushstring(L, v.c_str()); -} - -Tango::DeviceData pack_cmd_data(lua_State* L, int idx, long type) -{ - Tango::DeviceData data; + T data = T(); switch(type) { case Tango::DEV_VOID: // 0 - void @@ -350,18 +335,106 @@ Tango::DeviceData pack_cmd_data(lua_State* L, int idx, long type) case Tango::DEVVAR_LONGSTRINGARRAY: // 17 - longstring[] ??? case Tango::DEVVAR_DOUBLESTRINGARRAY: // 18 - doublestring[] ??? case Tango::DEV_STATE: // 19 - DevState - case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[] - cannot insert std::vector to DeviceData + case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[] case Tango::DEV_UCHAR: // 22 - uchar case Tango::DEV_ENCODED: // 28 - DevEncoded case Tango::DEV_ENUM: // 29 - DevEnum case Tango::DEV_PIPE_BLOB: // 30 - DevPipeBlob case Tango::DEVVAR_STATEARRAY: // 31 - DevState[] - LUT_LOG(WARNING, "Command input argument type not implemented yet: %d", type); + LUT_LOG(WARNING, "Conversion to Tango type not implemented yet: %d", type); break; case Tango::DATA_TYPE_UNKNOWN: // 32 - unknown default: - LUT_LOG(ERROR, "Command input argument type is unknown: %d", type); + LUT_LOG(ERROR, "Tango type is unknown: %d", type); + break; } return data; } + +template +void extract_number(lua_State* L, T data, Tango::AttrDataFormat format) +{ + if(format == Tango::SCALAR) + { + dT v; + data >> v; + lua_pushnumber(L, v); + } + else if(format == Tango::SPECTRUM) + { + std::vector
v; + data >> v; + push_number_table(L, v); + } + else if(format == Tango::IMAGE) + { + // std::vector> v; + // //attr >> v; + // // push_number_2d(L, v); + LUT_LOG(WARNING, "IMAGE data format is not supported yet"); + lua_pushnil(L); + } + else + { + LUT_LOG(ERROR, "Invalid data format"); + lua_pushnil(L); + } +} + +template +void extract_bool(lua_State* L, T data, Tango::AttrDataFormat format) +{ + if(format == Tango::SCALAR) + { + bool v; + data >> v; + lua_pushboolean(L, v); + } + else if(format == Tango::SPECTRUM) + { + // TODO: cannot insert std::vector to DeviceData + // std::vector v; + // data >> v; + // push_bool_table(L, v); + lua_pushnil(L); + } + else if(format == Tango::IMAGE) + { + LUT_LOG(WARNING, "IMAGE data format is not supported yet"); + lua_pushnil(L); + } + else + { + LUT_LOG(ERROR, "Invalid data format"); + lua_pushnil(L); + } + +} + +template +void extract_string(lua_State* L, T data, Tango::AttrDataFormat format) +{ + if(format == Tango::SCALAR) + { + std::string v; + data >> v; + lua_pushstring(L, v.c_str()); + } + else if(format == Tango::SPECTRUM) + { + std::vector v; + data >> v; + push_string_table(L, v); + } + else if(format == Tango::IMAGE) + { + LUT_LOG(WARNING, "IMAGE data format is not supported yet"); + lua_pushnil(L); + } + else + { + LUT_LOG(ERROR, "Invalid data format"); + lua_pushnil(L); + } +} diff --git a/src/core/tango/types.h b/src/core/tango/types.h new file mode 100644 index 0000000..a0bac25 --- /dev/null +++ b/src/core/tango/types.h @@ -0,0 +1,52 @@ +//----------------------------------------------------------------------------- +// +// luTango - Lua binding for Tango +// +// Copyright (C) 2023 Grzegorz Kowalski +// See LICENSE for legal information +// +// file: types.h +// +// Tango type conversions +// +//----------------------------------------------------------------------------- + +#ifndef __TYPES_H__ +# define __TYPES_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +typedef struct +{ + long type; + Tango::AttrDataFormat format; +} AttrTypeDescription; + +typedef std::map AttrTypeMap; +typedef std::map CmdInfoMap; + +template +void lut_fromTangoType(lua_State* L, T data, long type, Tango::AttrDataFormat format=Tango::SCALAR); + +template +T lut_toTangoType(lua_State* L, int idx, long type, Tango::AttrDataFormat format=Tango::SCALAR); + +template +void extract_number(lua_State* L, T data, Tango::AttrDataFormat format); + +template +void extract_bool(lua_State* L, T data, Tango::AttrDataFormat format); + +template +void extract_string(lua_State* L, T data, Tango::AttrDataFormat format); + +#endif /* __TYPES_H__ */