forked from daneos/lutango
add DevState support
This commit is contained in:
parent
b07072a5a8
commit
a93c8292f1
6
src/core/global.h
Normal file
6
src/core/global.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef __GLOBAL_H__
|
||||
# define __GLOBAL_H__
|
||||
|
||||
#define LUTANGO "lutango"
|
||||
|
||||
#endif /* __GLOBAL_H__ */
|
||||
8
src/core/lua/load.cpp
Normal file
8
src/core/lua/load.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "load.h"
|
||||
|
||||
void load_lua_lib(lua_State* L, const char* name)
|
||||
{
|
||||
lua_getglobal(L, "require");
|
||||
lua_pushstring(L, name);
|
||||
lua_call(L, 1, 1);
|
||||
}
|
||||
8
src/core/lua/load.h
Normal file
8
src/core/lua/load.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef __LOAD_H__
|
||||
# define __LOAD_H__
|
||||
|
||||
#include <core/lua.h>
|
||||
|
||||
void load_lua_lib(lua_State* L, const char* name);
|
||||
|
||||
#endif /* __LOAD_H__ */
|
||||
@ -2,8 +2,6 @@
|
||||
# define __LUTANGO_H__
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// #define LUTANGO_CORE "lutango_core"
|
||||
|
||||
#include <core/lua.h>
|
||||
#include <core/logging/log.h>
|
||||
#include <core/sys/sys.h>
|
||||
|
||||
14
src/core/tango/DevState/lut_DevState.cpp
Normal file
14
src/core/tango/DevState/lut_DevState.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "lut_DevState.h"
|
||||
|
||||
void lut_DevState(lua_State* L, Tango::DevState state)
|
||||
{
|
||||
LUT_LOG(TRACE, "Converting DevState(%d) into lut_DevState", state);
|
||||
|
||||
load_lua_lib(L, LUTANGO);
|
||||
lua_getglobal(L, LUTANGO);
|
||||
|
||||
lua_getfield(L, 1, "DevState");
|
||||
lua_pushnumber(L, (int)state);
|
||||
|
||||
lua_call(L, 1, 1);
|
||||
}
|
||||
12
src/core/tango/DevState/lut_DevState.h
Normal file
12
src/core/tango/DevState/lut_DevState.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef __LUT_DEVSTATE_H__
|
||||
# define __LUT_DEVSTATE_H__
|
||||
|
||||
#include <core/tango.h>
|
||||
#include <core/lua.h>
|
||||
#include <core/global.h>
|
||||
#include <core/logging/log.h>
|
||||
#include <core/lua/load.h>
|
||||
|
||||
void lut_DevState(lua_State* L, Tango::DevState state);
|
||||
|
||||
#endif /* __LUT_DEVSTATE_H__ */
|
||||
@ -98,6 +98,14 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
|
||||
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<bool> v;
|
||||
@ -144,7 +152,6 @@ void unpack_attr_data(lua_State* L, Tango::DeviceAttribute attr)
|
||||
|
||||
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
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <core/tango.h>
|
||||
#include <core/logging/log.h>
|
||||
#include <core/lua/stack.h>
|
||||
#include <core/tango/DevState/lut_DevState.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
||||
@ -98,6 +98,14 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, long type)
|
||||
break;
|
||||
}
|
||||
|
||||
case Tango::DEV_STATE: // 19 - DevState
|
||||
{
|
||||
Tango::DevState v;
|
||||
data >> v;
|
||||
lut_DevState(L, v);
|
||||
break;
|
||||
}
|
||||
|
||||
case Tango::DEV_UCHAR: // 22 - uchar
|
||||
{
|
||||
unsigned char v;
|
||||
@ -136,7 +144,6 @@ void unpack_cmd_data(lua_State* L, Tango::DeviceData data, 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<bool(or DevBoolean)> to DeviceData
|
||||
case Tango::DEV_ENCODED: // 28 - DevEncoded
|
||||
case Tango::DEV_ENUM: // 29 - DevEnum
|
||||
|
||||
@ -3,12 +3,14 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <core/lua.h>
|
||||
#include <core/tango.h>
|
||||
#include <core/logging/log.h>
|
||||
#include <core/lua/stack.h>
|
||||
#include <core/tango/DevState/lut_DevState.h>
|
||||
|
||||
typedef std::map<const char*, Tango::CommandInfo> CmdInfoMap;
|
||||
|
||||
|
||||
@ -8,7 +8,8 @@ local lutango = {
|
||||
log = log,
|
||||
sys = core.sys,
|
||||
lutObject = lutObject,
|
||||
DeviceProxy = lutObject("DeviceProxy")
|
||||
DeviceProxy = lutObject("DeviceProxy"),
|
||||
DevState = require "lutango.lutDevState"
|
||||
}
|
||||
|
||||
lutango.sys.lua_version = utils.lua_version
|
||||
|
||||
37
src/lutDevState.lua
Normal file
37
src/lutDevState.lua
Normal file
@ -0,0 +1,37 @@
|
||||
local utils = require "lutango.utils"
|
||||
local log = require "lutango.lutLog"
|
||||
|
||||
local lutDevState = {
|
||||
labels = {[0] = "ON", "OFF", "CLOSE", "OPEN", "INSERT", "EXTRACT", "MOVING", "STANDBY", "FAULT", "INIT", "RUNNING", "ALARM", "DISABLE", "UNKNOWN"}
|
||||
}
|
||||
|
||||
lutDevState.__index = lutDevState
|
||||
|
||||
function lutDevState:__call(state)
|
||||
log(log.level.TRACE, "New DevState("..tostring(state)..")")
|
||||
|
||||
o = { value = state}
|
||||
|
||||
setmetatable(o, lutDevState)
|
||||
return o
|
||||
end
|
||||
|
||||
function lutDevState:number()
|
||||
return self.value
|
||||
end
|
||||
|
||||
function lutDevState:__tostring()
|
||||
return self.labels[self.value]
|
||||
end
|
||||
|
||||
function lutDevState:__eq(other)
|
||||
return self.state == other.state
|
||||
end
|
||||
|
||||
local r = {}
|
||||
-- pregenerate available state objects
|
||||
for i = 0,#lutDevState.labels do
|
||||
r[lutDevState.labels[i]] = lutDevState:__call(i)
|
||||
end
|
||||
setmetatable(r, lutDevState)
|
||||
return r
|
||||
22
tests/test_state.lua
Normal file
22
tests/test_state.lua
Normal file
@ -0,0 +1,22 @@
|
||||
local lut = require "lutango"
|
||||
|
||||
local states = {}
|
||||
for i = 0,13 do
|
||||
states[i] = lut.DevState(i)
|
||||
print(tostring(states[i]).." = "..states[i]:number())
|
||||
end
|
||||
|
||||
print(states[0] == lut.DevState.ON)
|
||||
print(states[1] == lut.DevState.OFF)
|
||||
print(states[2] == lut.DevState.CLOSE)
|
||||
print(states[3] == lut.DevState.OPEN)
|
||||
print(states[4] == lut.DevState.INSERT)
|
||||
print(states[5] == lut.DevState.EXTRACT)
|
||||
print(states[6] == lut.DevState.MOVING)
|
||||
print(states[7] == lut.DevState.STANDBY)
|
||||
print(states[8] == lut.DevState.FAULT)
|
||||
print(states[9] == lut.DevState.INIT)
|
||||
print(states[10] == lut.DevState.RUNNING)
|
||||
print(states[11] == lut.DevState.ALARM)
|
||||
print(states[12] == lut.DevState.DISABLE)
|
||||
print(states[13] == lut.DevState.UNKNOWN)
|
||||
Loading…
x
Reference in New Issue
Block a user