use type names instead of IDs

This commit is contained in:
Grzegorz Kowalski 2023-02-04 15:05:07 +01:00
parent ccf52c63ea
commit fe640b0ae0
3 changed files with 133 additions and 124 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.sublime-workspace
build/*
lib/*
tmp/*

View File

@ -4,45 +4,45 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
{
switch(attr.get_type())
{
case 0: // void
case Tango::DEV_VOID: // 0 - void
lua_pushnil(L);
break;
case 1: // bool
case Tango::DEV_BOOLEAN: // 1 - bool
push_attr_bool(L, attr);
break;
case 2: // short
case Tango::DEV_SHORT: // 2 - short
push_attr_number<short>(L, attr);
break;
case 3: // long
case Tango::DEV_LONG: // 3 - long
push_attr_number<long>(L, attr);
break;
case 4: // float
case Tango::DEV_FLOAT: // 4 - float
push_attr_number<float>(L, attr);
break;
case 5: // double
case Tango::DEV_DOUBLE: // 5 - double
push_attr_number<double>(L, attr);
break;
case 6: // ushort
case Tango::DEV_USHORT: // 6 - ushort
push_attr_number<unsigned short>(L, attr);
break;
case 7: // ulong
case Tango::DEV_ULONG: // 7 - ulong
push_attr_number<unsigned long>(L, attr);
break;
case 8: // string
case 9: // char[]
case 20: // const string
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 10: // short[]
case Tango::DEVVAR_SHORTARRAY: // 10 - short[]
{
std::vector<short> v;
attr >> v;
@ -50,7 +50,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 11: // long[]
case Tango::DEVVAR_LONGARRAY: // 11 - long[]
{
std::vector<long> v;
attr >> v;
@ -58,7 +58,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 12: // float[]
case Tango::DEVVAR_FLOATARRAY: // 12 - float[]
{
std::vector<float> v;
attr >> v;
@ -66,7 +66,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 13: // double[]
case Tango::DEVVAR_DOUBLEARRAY: // 13 - double[]
{
std::vector<double> v;
attr >> v;
@ -74,7 +74,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 14: // ushort[]
case Tango::DEVVAR_USHORTARRAY: // 14 - ushort[]
{
std::vector<unsigned short> v;
attr >> v;
@ -82,7 +82,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 15: // ulong[]
case Tango::DEVVAR_ULONGARRAY: // 15 - ulong[]
{
std::vector<unsigned long> v;
attr >> v;
@ -90,7 +90,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 16: // string[]
case Tango::DEVVAR_STRINGARRAY: // 16 - string[]
{
std::vector<std::string> v;
attr >> v;
@ -98,7 +98,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 21: // bool[]
case Tango::DEVVAR_BOOLEANARRAY: // 21 - bool[]
{
std::vector<bool> v;
attr >> v;
@ -106,7 +106,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 22: // uchar
case Tango::DEV_UCHAR: // 22 - uchar
{
unsigned char v;
attr >> v;
@ -114,15 +114,15 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 23: // long64
case Tango::DEV_LONG64: // 23 - long64
push_attr_number<int64_t>(L, attr);
break;
case 24: // ulong64
case Tango::DEV_ULONG64: // 24 - ulong64
push_attr_number<uint64_t>(L, attr);
break;
case 25: // long64[]
case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[]
{
std::vector<int64_t> v;
attr >> v;
@ -130,7 +130,7 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 26: // ulong64[]
case Tango::DEVVAR_ULONG64ARRAY: // 26 - ulong64[]
{
std::vector<uint64_t> v;
attr >> v;
@ -138,18 +138,22 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
break;
}
case 27: // int
case Tango::DEV_INT: // 27 - int
push_attr_number<int>(L, attr);
break;
case 17: // longstring[] ???
case 18: // doublestring[] ???
case 19: // DevState
case 28: // DevEncoded
case Tango::DEVVAR_LONGSTRINGARRAY: // 17 - longstring[] ???
case Tango::DEVVAR_DOUBLESTRINGARRAY: // 18 - doublestring[] ???
case Tango::DEV_STATE: // 19 - DevState
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);
@ -247,75 +251,79 @@ Tango::DeviceAttribute pack_attr_data(lua_State* L, int idx, AttrTypeDescription
{
switch(d.type)
{
case 0: // void
case Tango::DEV_VOID: // 0 - void
LUT_LOG(ERROR, "%s: Void is not writeable type!", attr_name);
break;
case 1: // bool
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 2: // short
case Tango::DEV_SHORT: // 2 - short
return pack_attr_value(attr_name, pop_number<short>(L, idx));
break;
case 3: // long
case Tango::DEV_LONG: // 3 - long
return pack_attr_value(attr_name, pop_number<long>(L, idx));
break;
case 4: // float
case Tango::DEV_FLOAT: // 4 - float
return pack_attr_value(attr_name, pop_number<float>(L, idx));
break;
case 5: // double
case Tango::DEV_DOUBLE: // 5 - double
return pack_attr_value(attr_name, pop_number<double>(L, idx));
break;
case 6: // ushort
case Tango::DEV_USHORT: // 6 - ushort
return pack_attr_value(attr_name, pop_number<unsigned short>(L, idx));
break;
case 7: // ulong
case Tango::DEV_ULONG: // 7 - ulong
return pack_attr_value(attr_name, pop_number<unsigned long>(L, idx));
break;
case 8: // string
case 9: // char[]
case 20: // const string
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 23: // long64
case Tango::DEV_LONG64: // 23 - long64
return pack_attr_value(attr_name, pop_number<int64_t>(L, idx));
break;
case 24: // ulong64
case Tango::DEV_ULONG64: // 24 - ulong64
return pack_attr_value(attr_name, pop_number<uint64_t>(L, idx));
break;
case 27: // int
case Tango::DEV_INT: // 27 - int
return pack_attr_value(attr_name, pop_number<int>(L, idx));
break;
case 10: // short[]
case 11: // long[]
case 12: // float[]
case 13: // double[]
case 14: // ushort[]
case 15: // ulong[]
case 16: // string[]
case 17: // longstring[] ???
case 18: // doublestring[] ???
case 19: // DevState
case 21: // bool[]
case 22: // uchar
case 25: // long64[]
case 26: // ulong64[]
case 28: // DevEncoded
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);
}

View File

@ -4,45 +4,45 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
{
switch(type)
{
case 0: // void
case Tango::DEV_VOID: // 0 - void
lua_pushnil(L);
break;
case 1: // bool
case Tango::DEV_BOOLEAN: // 1 - bool
push_cmd_bool(L, data);
break;
case 2: // short
case Tango::DEV_SHORT: // 2 - short
push_cmd_number<short>(L, data);
break;
case 3: // long
case Tango::DEV_LONG: // 3 - long
push_cmd_number<long>(L, data);
break;
case 4: // float
case Tango::DEV_FLOAT: // 4 - float
push_cmd_number<float>(L, data);
break;
case 5: // double
case Tango::DEV_DOUBLE: // 5 - double
push_cmd_number<double>(L, data);
break;
case 6: // ushort
case Tango::DEV_USHORT: // 6 - ushort
push_cmd_number<unsigned short>(L, data);
break;
case 7: // ulong
case Tango::DEV_ULONG: // 7 - ulong
push_cmd_number<unsigned long>(L, data);
break;
case 8: // string
case 9: // char[]
case 20: // const string
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);
break;
case 10: // short[]
case Tango::DEVVAR_SHORTARRAY: // 10 - short[]
{
std::vector<short> v;
data >> v;
@ -50,7 +50,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 11: // long[]
case Tango::DEVVAR_LONGARRAY: // 11 - long[]
{
std::vector<long> v;
data >> v;
@ -58,7 +58,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 12: // float[]
case Tango::DEVVAR_FLOATARRAY: // 12 - float[]
{
std::vector<float> v;
data >> v;
@ -66,7 +66,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 13: // double[]
case Tango::DEVVAR_DOUBLEARRAY: // 13 - double[]
{
std::vector<double> v;
data >> v;
@ -74,7 +74,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 14: // ushort[]
case Tango::DEVVAR_USHORTARRAY: // 14 - ushort[]
{
std::vector<unsigned short> v;
data >> v;
@ -82,7 +82,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 15: // ulong[]
case Tango::DEVVAR_ULONGARRAY: // 15 - ulong[]
{
std::vector<unsigned long> v;
data >> v;
@ -90,7 +90,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 16: // string[]
case Tango::DEVVAR_STRINGARRAY: // 16 - string[]
{
std::vector<std::string> v;
data >> v;
@ -98,15 +98,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 21: // bool[]
{
std::vector<bool> v;
//data >> v;
push_bool_table(L, v);
break;
}
case 22: // uchar
case Tango::DEV_UCHAR: // 22 - uchar
{
unsigned char v;
// data >> v;
@ -114,15 +106,15 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 23: // long64
case Tango::DEV_LONG64: // 23 - long64
push_cmd_number<int64_t>(L, data);
break;
case 24: // ulong64
case Tango::DEV_ULONG64: // 24 - ulong64
push_cmd_number<uint64_t>(L, data);
break;
case 25: // long64[]
case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[]
{
std::vector<int64_t> v;
data >> v;
@ -130,7 +122,7 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 26: // ulong64[]
case Tango::DEVVAR_ULONG64ARRAY: // 26 - ulong64[]
{
std::vector<uint64_t> v;
data >> v;
@ -138,18 +130,23 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
break;
}
case 27: // int
case Tango::DEV_INT: // 27 - int
push_cmd_number<int>(L, data);
break;
case 17: // longstring[] ???
case 18: // doublestring[] ???
case 19: // DevState
case 28: // DevEncoded
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<bool(or DevBoolean)> to DeviceData
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 type conversion not implemented yet: %d", type);
lua_pushnil(L);
break;
case Tango::DATA_TYPE_UNKNOWN: // 32 - unknown
default:
LUT_LOG(ERROR, "Unknown type: %d", type);
lua_pushnil(L);
@ -185,161 +182,164 @@ Tango::DeviceData pack_cmd_data(lua_State* L, int idx, long type)
Tango::DeviceData data;
switch(type)
{
case 0: // void
case Tango::DEV_VOID: // 0 - void
break;
case 1: // bool
case Tango::DEV_BOOLEAN: // 1 - bool
{
Tango::DevBoolean v = lua_toboolean(L, idx);
data << v;
break;
}
case 2: // short
case Tango::DEV_SHORT: // 2 - short
{
Tango::DevShort v = luaL_checknumber(L, idx);
data << v;
break;
}
case 3: // long
case Tango::DEV_LONG: // 3 - long
{
Tango::DevLong v = luaL_checknumber(L, idx);
data << v;
break;
}
case 4: // float
case Tango::DEV_FLOAT: // 4 - float
{
Tango::DevFloat v = luaL_checknumber(L, idx);
data << v;
break;
}
case 5: // double
case Tango::DEV_DOUBLE: // 5 - double
{
Tango::DevDouble v = luaL_checknumber(L, idx);
data << v;
break;
}
case 6: // ushort
case Tango::DEV_USHORT: // 6 - ushort
{
Tango::DevUShort v = luaL_checknumber(L, idx);
data << v;
break;
}
case 7: // ulong
case Tango::DEV_ULONG: // 7 - ulong
{
Tango::DevULong v = luaL_checknumber(L, idx);
data << v;
break;
}
case 8: // string
case 9: // char[]
case 20: // const string
case Tango::DEV_STRING: // 8 - string
case Tango::DEVVAR_CHARARRAY: // 9 - char[]
case Tango::CONST_DEV_STRING: // 20 - const string
{
const char* v = luaL_checkstring(L, idx);
data << v;
break;
}
case 10: // short[]
case Tango::DEVVAR_SHORTARRAY: // 10 - short[]
{
std::vector<Tango::DevShort> v = pop_number_table<Tango::DevShort>(L, idx);
data << v;
break;
}
case 11: // long[]
case Tango::DEVVAR_LONGARRAY: // 11 - long[]
{
std::vector<Tango::DevLong> v = pop_number_table<Tango::DevLong>(L, idx);
data << v;
break;
}
case 12: // float[]
case Tango::DEVVAR_FLOATARRAY: // 12 - float[]
{
std::vector<Tango::DevFloat> v = pop_number_table<Tango::DevFloat>(L, idx);
data << v;
break;
}
case 13: // double[]
case Tango::DEVVAR_DOUBLEARRAY: // 13 - double[]
{
std::vector<Tango::DevDouble> v = pop_number_table<Tango::DevDouble>(L, idx);
data << v;
break;
}
case 14: // ushort[]
case Tango::DEVVAR_USHORTARRAY: // 14 - ushort[]
{
std::vector<Tango::DevUShort> v = pop_number_table<Tango::DevUShort>(L, idx);
data << v;
break;
}
case 15: // ulong[]
case Tango::DEVVAR_ULONGARRAY: // 15 - ulong[]
{
std::vector<Tango::DevULong> v = pop_number_table<Tango::DevULong>(L, idx);
data << v;
break;
}
case 16: // string[]
case Tango::DEVVAR_STRINGARRAY: // 16 - string[]
{
std::vector<std::string> v = pop_string_table(L, idx);
data << v;
break;
}
case 23: // long64
case Tango::DEV_LONG64: // 23 - long64
{
Tango::DevLong64 v = luaL_checknumber(L, idx);
data << v;
break;
}
case 24: // ulong64
case Tango::DEV_ULONG64: // 24 - ulong64
{
Tango::DevULong64 v = luaL_checknumber(L, idx);
data << v;
break;
}
case 25: // long64[]
case Tango::DEVVAR_LONG64ARRAY: // 25 - long64[]
{
std::vector<Tango::DevLong64> v = pop_number_table<Tango::DevLong64>(L, idx);
data << v;
break;
}
case 26: // ulong64[]
case Tango::DEVVAR_ULONG64ARRAY: // 26 - ulong64[]
{
std::vector<Tango::DevULong64> v = pop_number_table<Tango::DevULong64>(L, idx);
data << v;
break;
}
case 27: // int
case Tango::DEV_INT: // 27 - int
{
int v = luaL_checknumber(L, idx);
data << v;
break;
}
case 17: // longstring[] ???
case 18: // doublestring[] ???
case 19: // DevState
case 21: // bool[] - cannot insert std::vector<bool(or DevBoolean)> to DeviceData
case 22: // uchar
case 28: // DevEncoded
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<bool(or DevBoolean)> to DeviceData
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);
break;
case Tango::DATA_TYPE_UNKNOWN: // 32 - unknown
default:
LUT_LOG(ERROR, "Command input argument type is unknown: %d", type);
}