Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
77b6dc12
Commit
77b6dc12
authored
Oct 27, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(python): Доработка интерфейса UProxyObject
(netdata-plugin): Реализовал инициализацию из файла,обновление данных
parent
575ce067
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
509 additions
and
99 deletions
+509
-99
testUC.py
python/examples/testUC.py
+4
-1
UConnector_wrap.cxx
python/lib/pyUniSet/UConnector_wrap.cxx
+65
-31
UInterface_wrap.cxx
python/lib/pyUniSet/UInterface_wrap.cxx
+126
-0
UModbus.i
python/lib/pyUniSet/UModbus.i
+0
-1
UModbus_wrap.cxx
python/lib/pyUniSet/UModbus_wrap.cxx
+0
-0
UProxyObject.cc
python/lib/pyUniSet/UProxyObject.cc
+82
-4
UProxyObject.h
python/lib/pyUniSet/UProxyObject.h
+14
-0
UTypes.h
python/lib/pyUniSet/UTypes.h
+13
-1
pyUConnector.py
python/lib/pyUniSet/pyUConnector.py
+3
-0
pyUModbus.py
python/lib/pyUniSet/pyUModbus.py
+0
-34
pyUniSet.py
python/lib/pyUniSet/pyUniSet.py
+15
-0
uniset.chart.py
python/netdata-plugin/uniset.chart.py
+95
-23
uniset.conf
python/netdata-plugin/uniset.conf
+86
-3
testUI.py
python/tests/UInterface/testUI.py
+6
-1
No files found.
python/examples/testUC.py
View file @
77b6dc12
...
...
@@ -3,10 +3,11 @@
import
sys
from
uniset
import
*
from
uniset
2
import
*
if
__name__
==
"__main__"
:
prop
=
"test"
lst
=
Params_inst
()
for
i
in
range
(
0
,
len
(
sys
.
argv
)):
...
...
@@ -15,6 +16,8 @@ if __name__ == "__main__":
lst
.
add
(
sys
.
argv
[
i
]
)
lst
.
add_str
(
prop
)
p
=
[]
print
"lst: class: "
+
str
(
p
.
__class__
.
__name__
)
...
...
python/lib/pyUniSet/UConnector_wrap.cxx
View file @
77b6dc12
...
...
@@ -3256,6 +3256,37 @@ SWIGINTERNINLINE PyObject*
}
SWIGINTERN
int
SWIG_AsPtr_std_string
(
PyObject
*
obj
,
std
::
string
**
val
)
{
char
*
buf
=
0
;
size_t
size
=
0
;
int
alloc
=
SWIG_OLDOBJ
;
if
(
SWIG_IsOK
((
SWIG_AsCharPtrAndSize
(
obj
,
&
buf
,
&
size
,
&
alloc
))))
{
if
(
buf
)
{
if
(
val
)
*
val
=
new
std
::
string
(
buf
,
size
-
1
);
if
(
alloc
==
SWIG_NEWOBJ
)
delete
[]
buf
;
return
SWIG_NEWOBJ
;
}
else
{
if
(
val
)
*
val
=
0
;
return
SWIG_OLDOBJ
;
}
}
else
{
static
int
init
=
0
;
static
swig_type_info
*
descriptor
=
0
;
if
(
!
init
)
{
descriptor
=
SWIG_TypeQuery
(
"std::string"
" *"
);
init
=
1
;
}
if
(
descriptor
)
{
std
::
string
*
vptr
;
int
res
=
SWIG_ConvertPtr
(
obj
,
(
void
**
)
&
vptr
,
descriptor
,
0
);
if
(
SWIG_IsOK
(
res
)
&&
val
)
*
val
=
vptr
;
return
res
;
}
}
return
SWIG_ERROR
;
}
#include <limits.h>
#if !defined(SWIG_NO_LLONG_MAX)
# if !defined(LLONG_MAX) && defined(__GNUC__) && defined (__LONG_LONG_MAX__)
...
...
@@ -3407,37 +3438,6 @@ SWIG_AsVal_int (PyObject * obj, int *val)
}
SWIGINTERN
int
SWIG_AsPtr_std_string
(
PyObject
*
obj
,
std
::
string
**
val
)
{
char
*
buf
=
0
;
size_t
size
=
0
;
int
alloc
=
SWIG_OLDOBJ
;
if
(
SWIG_IsOK
((
SWIG_AsCharPtrAndSize
(
obj
,
&
buf
,
&
size
,
&
alloc
))))
{
if
(
buf
)
{
if
(
val
)
*
val
=
new
std
::
string
(
buf
,
size
-
1
);
if
(
alloc
==
SWIG_NEWOBJ
)
delete
[]
buf
;
return
SWIG_NEWOBJ
;
}
else
{
if
(
val
)
*
val
=
0
;
return
SWIG_OLDOBJ
;
}
}
else
{
static
int
init
=
0
;
static
swig_type_info
*
descriptor
=
0
;
if
(
!
init
)
{
descriptor
=
SWIG_TypeQuery
(
"std::string"
" *"
);
init
=
1
;
}
if
(
descriptor
)
{
std
::
string
*
vptr
;
int
res
=
SWIG_ConvertPtr
(
obj
,
(
void
**
)
&
vptr
,
descriptor
,
0
);
if
(
SWIG_IsOK
(
res
)
&&
val
)
*
val
=
vptr
;
return
res
;
}
}
return
SWIG_ERROR
;
}
SWIGINTERNINLINE
PyObject
*
SWIG_FromCharPtrAndSize
(
const
char
*
carray
,
size_t
size
)
{
...
...
@@ -3547,6 +3547,39 @@ fail:
}
SWIGINTERN
PyObject
*
_wrap_Params_add_str
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UTypes
::
Params
*
arg1
=
(
UTypes
::
Params
*
)
0
;
std
::
string
arg2
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
PyObject
*
obj1
=
0
;
bool
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"OO:Params_add_str"
,
&
obj0
,
&
obj1
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UTypes__Params
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"Params_add_str"
"', argument "
"1"" of type '"
"UTypes::Params *""'"
);
}
arg1
=
reinterpret_cast
<
UTypes
::
Params
*
>
(
argp1
);
{
std
::
string
*
ptr
=
(
std
::
string
*
)
0
;
int
res
=
SWIG_AsPtr_std_string
(
obj1
,
&
ptr
);
if
(
!
SWIG_IsOK
(
res
)
||
!
ptr
)
{
SWIG_exception_fail
(
SWIG_ArgError
((
ptr
?
res
:
SWIG_TypeError
)),
"in method '"
"Params_add_str"
"', argument "
"2"" of type '"
"std::string""'"
);
}
arg2
=
*
ptr
;
if
(
SWIG_IsNewObj
(
res
))
delete
ptr
;
}
result
=
(
bool
)(
arg1
)
->
add_str
(
arg2
);
resultobj
=
SWIG_From_bool
(
static_cast
<
bool
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_Params_argc_set
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UTypes
::
Params
*
arg1
=
(
UTypes
::
Params
*
)
0
;
...
...
@@ -4378,6 +4411,7 @@ static PyMethodDef SwigMethods[] = {
{
(
char
*
)
"SWIG_PyInstanceMethod_New"
,
(
PyCFunction
)
SWIG_PyInstanceMethod_New
,
METH_O
,
NULL
},
{
(
char
*
)
"new_Params"
,
_wrap_new_Params
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_add"
,
_wrap_Params_add
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_add_str"
,
_wrap_Params_add_str
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_argc_set"
,
_wrap_Params_argc_set
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_argc_get"
,
_wrap_Params_argc_get
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_argv_set"
,
_wrap_Params_argv_set
,
METH_VARARGS
,
NULL
},
...
...
python/lib/pyUniSet/UInterface_wrap.cxx
View file @
77b6dc12
...
...
@@ -3979,6 +3979,39 @@ fail:
}
SWIGINTERN
PyObject
*
_wrap_Params_add_str
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UTypes
::
Params
*
arg1
=
(
UTypes
::
Params
*
)
0
;
std
::
string
arg2
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
PyObject
*
obj1
=
0
;
bool
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"OO:Params_add_str"
,
&
obj0
,
&
obj1
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UTypes__Params
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"Params_add_str"
"', argument "
"1"" of type '"
"UTypes::Params *""'"
);
}
arg1
=
reinterpret_cast
<
UTypes
::
Params
*
>
(
argp1
);
{
std
::
string
*
ptr
=
(
std
::
string
*
)
0
;
int
res
=
SWIG_AsPtr_std_string
(
obj1
,
&
ptr
);
if
(
!
SWIG_IsOK
(
res
)
||
!
ptr
)
{
SWIG_exception_fail
(
SWIG_ArgError
((
ptr
?
res
:
SWIG_TypeError
)),
"in method '"
"Params_add_str"
"', argument "
"2"" of type '"
"std::string const""'"
);
}
arg2
=
*
ptr
;
if
(
SWIG_IsNewObj
(
res
))
delete
ptr
;
}
result
=
(
bool
)(
arg1
)
->
add_str
(
arg2
);
resultobj
=
SWIG_From_bool
(
static_cast
<
bool
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_Params_argc_set
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UTypes
::
Params
*
arg1
=
(
UTypes
::
Params
*
)
0
;
...
...
@@ -4834,6 +4867,94 @@ fail:
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_askIsOK
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
bool
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:UProxyObject_askIsOK"
,
&
obj0
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_askIsOK"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
result
=
(
bool
)(
arg1
)
->
askIsOK
();
resultobj
=
SWIG_From_bool
(
static_cast
<
bool
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_reaskSensors
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
bool
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:UProxyObject_reaskSensors"
,
&
obj0
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_reaskSensors"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
result
=
(
bool
)(
arg1
)
->
reaskSensors
();
resultobj
=
SWIG_From_bool
(
static_cast
<
bool
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_updateValues
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
bool
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:UProxyObject_updateValues"
,
&
obj0
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_updateValues"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
result
=
(
bool
)(
arg1
)
->
updateValues
();
resultobj
=
SWIG_From_bool
(
static_cast
<
bool
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
_wrap_UProxyObject_smIsOK
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
resultobj
=
0
;
UProxyObject
*
arg1
=
(
UProxyObject
*
)
0
;
void
*
argp1
=
0
;
int
res1
=
0
;
PyObject
*
obj0
=
0
;
bool
result
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:UProxyObject_smIsOK"
,
&
obj0
))
SWIG_fail
;
res1
=
SWIG_ConvertPtr
(
obj0
,
&
argp1
,
SWIGTYPE_p_UProxyObject
,
0
|
0
);
if
(
!
SWIG_IsOK
(
res1
))
{
SWIG_exception_fail
(
SWIG_ArgError
(
res1
),
"in method '"
"UProxyObject_smIsOK"
"', argument "
"1"" of type '"
"UProxyObject *""'"
);
}
arg1
=
reinterpret_cast
<
UProxyObject
*
>
(
argp1
);
result
=
(
bool
)(
arg1
)
->
smIsOK
();
resultobj
=
SWIG_From_bool
(
static_cast
<
bool
>
(
result
));
return
resultobj
;
fail
:
return
NULL
;
}
SWIGINTERN
PyObject
*
UProxyObject_swigregister
(
PyObject
*
SWIGUNUSEDPARM
(
self
),
PyObject
*
args
)
{
PyObject
*
obj
;
if
(
!
PyArg_ParseTuple
(
args
,(
char
*
)
"O:swigregister"
,
&
obj
))
return
NULL
;
...
...
@@ -4856,6 +4977,7 @@ static PyMethodDef SwigMethods[] = {
{
(
char
*
)
"getConfFileName"
,
_wrap_getConfFileName
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"new_Params"
,
_wrap_new_Params
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_add"
,
_wrap_Params_add
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_add_str"
,
_wrap_Params_add_str
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_argc_set"
,
_wrap_Params_argc_set
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_argc_get"
,
_wrap_Params_argc_get
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"Params_argv_set"
,
_wrap_Params_argv_set
,
METH_VARARGS
,
NULL
},
...
...
@@ -4881,6 +5003,10 @@ static PyMethodDef SwigMethods[] = {
{
(
char
*
)
"UProxyObject_getValue"
,
_wrap_UProxyObject_getValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_getFloatValue"
,
_wrap_UProxyObject_getFloatValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_setValue"
,
_wrap_UProxyObject_setValue
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_askIsOK"
,
_wrap_UProxyObject_askIsOK
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_reaskSensors"
,
_wrap_UProxyObject_reaskSensors
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_updateValues"
,
_wrap_UProxyObject_updateValues
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_smIsOK"
,
_wrap_UProxyObject_smIsOK
,
METH_VARARGS
,
NULL
},
{
(
char
*
)
"UProxyObject_swigregister"
,
UProxyObject_swigregister
,
METH_VARARGS
,
NULL
},
{
NULL
,
NULL
,
0
,
NULL
}
};
...
...
python/lib/pyUniSet/UModbus.i
View file @
77b6dc12
...
...
@@ -12,5 +12,4 @@
/* Для генерации классов и констант в Питоне */
%include "UModbus.h"
%include "UTypes.h"
%include "UExceptions.h"
python/lib/pyUniSet/UModbus_wrap.cxx
View file @
77b6dc12
This diff is collapsed.
Click to expand it.
python/lib/pyUniSet/UProxyObject.cc
View file @
77b6dc12
...
...
@@ -40,6 +40,11 @@ class UProxyObject_impl:
void
impl_setValue
(
long
id
,
long
val
)
throw
(
UException
);
float
impl_getFloatValue
(
long
id
)
throw
(
UException
);
bool
impl_askIsOK
();
bool
impl_reaskSensors
();
bool
impl_updateValues
();
bool
impl_smIsOK
();
protected
:
virtual
void
askSensors
(
UniversalIO
::
UIOCommand
cmd
)
override
;
virtual
void
sensorInfo
(
const
UniSetTypes
::
SensorMessage
*
sm
)
override
;
...
...
@@ -51,10 +56,12 @@ class UProxyObject_impl:
IOController_i
::
SensorInfo
si
;
long
value
=
{
0
};
float
fvalue
=
{
0.0
};
long
precision
=
{
0
};
};
std
::
mutex
mutexSMap
;
std
::
unordered_map
<
UniSetTypes
::
ObjectId
,
SInfo
>
smap
;
bool
askOK
=
{
false
};
};
// --------------------------------------------------------------------------
UProxyObject
::
UProxyObject
()
throw
(
UException
)
...
...
@@ -97,6 +104,26 @@ void UProxyObject::setValue( long id, long val ) throw(UException)
uobj
->
impl_setValue
(
id
,
val
);
}
// --------------------------------------------------------------------------
bool
UProxyObject
::
askIsOK
()
{
return
uobj
->
impl_askIsOK
();
}
// --------------------------------------------------------------------------
bool
UProxyObject
::
reaskSensors
()
{
return
uobj
->
impl_reaskSensors
();
}
// --------------------------------------------------------------------------
bool
UProxyObject
::
updateValues
()
{
return
uobj
->
impl_updateValues
();
}
// --------------------------------------------------------------------------
bool
UProxyObject
::
smIsOK
()
{
return
uobj
->
impl_smIsOK
();
}
// --------------------------------------------------------------------------
float
UProxyObject
::
getFloatValue
(
long
id
)
throw
(
UException
)
{
return
uobj
->
impl_getFloatValue
(
id
);
...
...
@@ -129,9 +156,18 @@ UProxyObject_impl::~UProxyObject_impl()
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
impl_addToAsk
(
ObjectId
id
)
throw
(
UException
)
{
auto
conf
=
uniset_conf
();
UProxyObject_impl
::
SInfo
i
;
i
.
si
.
id
=
id
;
i
.
si
.
node
=
uniset_conf
()
->
getLocalNode
();
i
.
si
.
node
=
conf
->
getLocalNode
();
auto
inf
=
conf
->
oind
->
getObjectInfo
(
id
);
if
(
inf
&&
inf
->
data
)
{
UniXML
::
iterator
it
(
(
xmlNode
*
)(
inf
->
data
)
);
i
.
precision
=
it
.
getIntProp
(
"precision"
);
}
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
smap
[
id
]
=
i
;
...
...
@@ -165,6 +201,12 @@ float UProxyObject_impl::impl_getFloatValue( long id ) throw(UException)
return
i
->
second
.
fvalue
;
}
// --------------------------------------------------------------------------
bool
UProxyObject_impl
::
impl_askIsOK
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
return
askOK
;
}
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
impl_setValue
(
long
id
,
long
val
)
throw
(
UException
)
{
try
...
...
@@ -179,9 +221,46 @@ void UProxyObject_impl::impl_setValue( long id, long val ) throw(UException)
}
}
// --------------------------------------------------------------------------
bool
UProxyObject_impl
::
impl_reaskSensors
()
{
askSensors
(
UniversalIO
::
UIONotify
);
return
impl_askIsOK
();
}
// --------------------------------------------------------------------------
bool
UProxyObject_impl
::
impl_updateValues
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
bool
ret
=
true
;
for
(
auto
&&
i
:
smap
)
{
try
{
i
.
second
.
value
=
ui
->
getValue
(
i
.
second
.
si
.
id
,
i
.
second
.
si
.
node
);
i
.
second
.
fvalue
=
(
float
)
i
.
second
.
value
/
pow
(
10.0
,
i
.
second
.
precision
);
}
catch
(
std
::
exception
&
ex
)
{
mycrit
<<
myname
<<
"(updateValues): "
<<
i
.
second
.
si
.
id
<<
" error: "
<<
ex
.
what
()
<<
std
::
endl
;
ret
=
false
;
}
}
return
ret
;
}
// --------------------------------------------------------------------------
bool
UProxyObject_impl
::
impl_smIsOK
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
// проверяем по первому датчику
auto
s
=
smap
.
begin
();
return
ui
->
isExist
(
s
->
second
.
si
.
id
,
s
->
second
.
si
.
node
);
}
// --------------------------------------------------------------------------
void
UProxyObject_impl
::
askSensors
(
UniversalIO
::
UIOCommand
cmd
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
mutexSMap
);
askOK
=
true
;
for
(
const
auto
&
i
:
smap
)
{
try
...
...
@@ -190,9 +269,8 @@ void UProxyObject_impl::askSensors( UniversalIO::UIOCommand cmd )
}
catch
(
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
myname
<<
"(askSensors): "
<<
i
.
second
.
si
.
id
<<
" error: "
<<
std
::
string
(
ex
.
what
());
throw
UException
(
err
.
str
());
mywarn
<<
myname
<<
"(askSensors): "
<<
i
.
second
.
si
.
id
<<
" error: "
<<
ex
.
what
()
<<
std
::
endl
;
askOK
=
false
;
}
}
}
...
...
python/lib/pyUniSet/UProxyObject.h
View file @
77b6dc12
...
...
@@ -52,6 +52,20 @@ class UProxyObject
/*! Сохраняемые датчики не требуют добавления при помощи addToAsk ! */
void
setValue
(
long
id
,
long
val
)
throw
(
UException
);
/*! \return true если заказ датчиков прошёл успешно */
bool
askIsOK
();
/*! перезаказ датчиков */
bool
reaskSensors
();
/*! принудительное обновление значений.
* В случае если не используется заказ датчиков
*/
bool
updateValues
();
/*! Проверка работы SM */
bool
smIsOK
();
protected
:
private
:
...
...
python/lib/pyUniSet/UTypes.h
View file @
77b6dc12
...
...
@@ -17,7 +17,8 @@
#ifndef UTypes_H_
#define UTypes_H_
// --------------------------------------------------------------------------
#include <UniSetTypes.h>
#include <string>
#include "UniSetTypes.h"
// --------------------------------------------------------------------------
namespace
UTypes
{
...
...
@@ -44,6 +45,17 @@ namespace UTypes
return
false
;
}
bool
add_str
(
const
std
::
string
s
)
{
if
(
argc
<
Params
::
max
)
{
argv
[
argc
++
]
=
UniSetTypes
::
uni_strdup
(
s
);
return
true
;
}
return
false
;
}
int
argc
;
char
*
argv
[
max
];
...
...
python/lib/pyUniSet/pyUConnector.py
View file @
77b6dc12
...
...
@@ -90,6 +90,9 @@ class Params:
def
add
(
self
,
s
):
return
_pyUConnector
.
Params_add
(
self
,
s
)
def
add_str
(
self
,
s
):
return
_pyUConnector
.
Params_add_str
(
self
,
s
)
__swig_setmethods__
[
"argc"
]
=
_pyUConnector
.
Params_argc_set
__swig_getmethods__
[
"argc"
]
=
_pyUConnector
.
Params_argc_get
__swig_setmethods__
[
"argv"
]
=
_pyUConnector
.
Params_argv_set
...
...
python/lib/pyUniSet/pyUModbus.py
View file @
77b6dc12
...
...
@@ -130,40 +130,6 @@ class UModbus:
UModbus_swigregister
=
_pyUModbus
.
UModbus_swigregister
UModbus_swigregister
(
UModbus
)
class
Params
:
__swig_setmethods__
=
{}
__setattr__
=
lambda
self
,
name
,
value
:
_swig_setattr
(
self
,
Params
,
name
,
value
)
__swig_getmethods__
=
{}
__getattr__
=
lambda
self
,
name
:
_swig_getattr
(
self
,
Params
,
name
)
__repr__
=
_swig_repr
max
=
_pyUModbus
.
Params_max
def
__init__
(
self
):
this
=
_pyUModbus
.
new_Params
()
try
:
self
.
this
.
append
(
this
)
except
Exception
:
self
.
this
=
this
def
add
(
self
,
s
):
return
_pyUModbus
.
Params_add
(
self
,
s
)
__swig_setmethods__
[
"argc"
]
=
_pyUModbus
.
Params_argc_set
__swig_getmethods__
[
"argc"
]
=
_pyUModbus
.
Params_argc_get
__swig_setmethods__
[
"argv"
]
=
_pyUModbus
.
Params_argv_set
__swig_getmethods__
[
"argv"
]
=
_pyUModbus
.
Params_argv_get
__swig_getmethods__
[
"inst"
]
=
lambda
x
:
_pyUModbus
.
Params_inst
__swig_destroy__
=
_pyUModbus
.
delete_Params
__del__
=
lambda
self
:
None
Params_swigregister
=
_pyUModbus
.
Params_swigregister
Params_swigregister
(
Params
)
cvar
=
_pyUModbus
.
cvar
DefaultID
=
cvar
.
DefaultID
DefaultSupplerID
=
cvar
.
DefaultSupplerID
def
Params_inst
():
return
_pyUModbus
.
Params_inst
()
Params_inst
=
_pyUModbus
.
Params_inst
class
UException
(
Exception
):
__swig_setmethods__
=
{}
__setattr__
=
lambda
self
,
name
,
value
:
_swig_setattr
(
self
,
UException
,
name
,
value
)
...
...
python/lib/pyUniSet/pyUniSet.py
View file @
77b6dc12
...
...
@@ -134,6 +134,9 @@ class Params:
def
add
(
self
,
s
):
return
_pyUniSet
.
Params_add
(
self
,
s
)
def
add_str
(
self
,
s
):
return
_pyUniSet
.
Params_add_str
(
self
,
s
)
__swig_setmethods__
[
"argc"
]
=
_pyUniSet
.
Params_argc_set
__swig_getmethods__
[
"argc"
]
=
_pyUniSet
.
Params_argc_get
__swig_setmethods__
[
"argv"
]
=
_pyUniSet
.
Params_argv_set
...
...
@@ -245,6 +248,18 @@ class UProxyObject:
def
setValue
(
self
,
id
,
val
):
return
_pyUniSet
.
UProxyObject_setValue
(
self
,
id
,
val
)
def
askIsOK
(
self
):
return
_pyUniSet
.
UProxyObject_askIsOK
(
self
)
def
reaskSensors
(
self
):
return
_pyUniSet
.
UProxyObject_reaskSensors
(
self
)
def
updateValues
(
self
):
return
_pyUniSet
.
UProxyObject_updateValues
(
self
)
def
smIsOK
(
self
):
return
_pyUniSet
.
UProxyObject_smIsOK
(
self
)
UProxyObject_swigregister
=
_pyUniSet
.
UProxyObject_swigregister
UProxyObject_swigregister
(
UProxyObject
)
...
...
python/netdata-plugin/uniset.chart.py
View file @
77b6dc12
...
...
@@ -5,12 +5,12 @@
import
os
import
sys
sys
.
path
.
append
(
"./python_modules"
)
import
random
import
uniset2
from
uniset2
import
UniXML
from
uniset2
import
UProxyObject
sys
.
path
.
append
(
"./python_modules"
)
from
base
import
SimpleService
NAME
=
os
.
path
.
basename
(
__file__
)
.
replace
(
".chart.py"
,
""
)
...
...
@@ -23,26 +23,65 @@ retries = 60
class
Service
(
SimpleService
):
sensors
=
[]
uproxy
=
None
smOK
=
False
def
__init__
(
self
,
configuration
=
None
,
name
=
None
):
super
(
self
.
__class__
,
self
)
.
__init__
(
configuration
=
configuration
,
name
=
name
)
# if 'confile' not in self.configuration:
# self.error("uniset plugin: Unknown confile..")
# raise RuntimeError
conf
=
self
.
configuration
.
pop
confile
=
None
try
:
confile
=
conf
(
'confile'
)
except
KeyError
:
self
.
error
(
"uniset plugin: Unknown uniset config file. Set 'confile: /xxx/zzz/xxxx.xml' in config"
)
raise
RuntimeError
if
not
os
.
path
.
isfile
(
confile
):
self
.
error
(
"uniset plugin: Not found confile '
%
s'"
%
confile
)
raise
RuntimeError
self
.
info
(
"uniset plugin: read from /home/pv/Projects.com/uniset-2.0/conf/test.xml"
)
self
.
create_charts
(
"/home/pv/Projects.com/uniset-2.0/conf/test.xml"
)
self
.
name
=
self
.
get_conf_param
(
'name'
,
name
)
self
.
info
(
"
%
s: uniset plugin: read from
%
s"
%
(
name
,
confile
))
self
.
create_charts
(
confile
)
self
.
init_uniset
(
confile
)
# добавляем датчики в опрос..
for
s
in
self
.
sensors
:
self
.
uproxy
.
addToAsk
(
s
[
1
])
# class Service():
#
# sensors = []
#
# def error(self,txt):
# print txt
#
# def __init__(self, configuration=None, name=None):
# self.create_charts("./test.xml")
def
init_uniset
(
self
,
confile
):
lst
=
uniset2
.
Params_inst
()
for
i
in
range
(
0
,
len
(
sys
.
argv
)):
if
i
>=
uniset2
.
Params
.
max
:
break
;
lst
.
add
(
sys
.
argv
[
i
])
port
=
self
.
get_conf_param
(
'port'
,
''
)
if
port
!=
''
:
self
.
info
(
"
%
s: uniset plugin: --uniset-port
%
s"
%
(
self
.
name
,
port
))
p
=
'--uniset-port'
lst
.
add_str
(
p
)
lst
.
add_str
(
str
(
port
)
)
uname
=
self
.
get_conf_param
(
'uname'
,
'TestProc'
)
self
.
info
(
"
%
s: uniset plugin: init ObjectID '
%
s'"
%
(
self
.
name
,
uname
))
try
:
uniset2
.
uniset_init_params
(
lst
,
confile
);
self
.
uproxy
=
UProxyObject
(
uname
)
except
uniset2
.
UException
,
e
:
self
.
error
(
"uniset plugin: error:
%
s"
%
e
.
getError
())
raise
RuntimeError
def
get_conf_param
(
self
,
propname
,
defval
):
try
:
pop
=
self
.
configuration
.
pop
return
pop
(
propname
)
except
KeyError
:
pass
return
defval
def
find_section
(
self
,
xml
,
secname
):
node
=
xml
.
findNode
(
xml
.
getDoc
(),
secname
)[
0
]
...
...
@@ -145,7 +184,7 @@ class Service(SimpleService):
# params.append(self.get_param(node, 'netdata_divisor', None))
# params.append(self.get_param(node, 'netdata_hidden', None))
self
.
sensors
.
append
([
id
,
node
.
prop
(
'id'
)])
self
.
sensors
.
append
([
id
,
uniset2
.
to_int
(
node
.
prop
(
'id'
)
)])
chart
[
'lines'
]
.
append
(
params
)
...
...
@@ -175,17 +214,51 @@ class Service(SimpleService):
return
True
def
check
(
self
):
# ret = super(self.__class__, self).check()
try
:
uniset2
.
uniset_activate_objects
()
except
uniset2
.
UException
,
e
:
self
.
error
(
"
%
s"
%
e
.
getError
())
raise
False
return
True
def
_get_data
(
self
):
data
=
{}
for
netid
,
id
in
self
.
sensors
:
data
[
netid
]
=
random
.
randint
(
0
,
100
)
data
[
netid
]
=
self
.
uproxy
.
getValue
(
id
)
if
len
(
data
)
==
0
:
return
None
return
data
# if __name__ == "__main__":
#
# serv = Service(None,"test")
\ No newline at end of file
def
update
(
self
,
interval
):
if
not
self
.
uproxy
.
askIsOK
()
and
not
self
.
uproxy
.
reaskSensors
():
return
False
prev_smOK
=
self
.
smOK
self
.
smOK
=
self
.
uproxy
.
smIsOK
()
if
prev_smOK
!=
self
.
smOK
and
self
.
smOK
:
self
.
info
(
"SM exist OK. Reask sensors.."
)
self
.
uproxy
.
reaskSensors
()
return
super
(
self
.
__class__
,
self
)
.
update
(
interval
)
if
__name__
==
"__main__"
:
config
=
{}
config
[
'confile'
]
=
'./test.xml'
config
[
'port'
]
=
2809
config
[
'uname'
]
=
'TestProc'
config
[
'update_every'
]
=
update_every
config
[
'priority'
]
=
priority
config
[
'retries'
]
=
retries
serv
=
Service
(
config
,
"test"
)
python/netdata-plugin/uniset.conf
View file @
77b6dc12
update_every
=
5
confile
: /
home
/
pv
/
Projects
.
com
/
uniset
-
2
.
0
/
conf
/
test
.
xml
\ No newline at end of file
# netdata python.d.plugin configuration for example
#
# This file is in YaML format. Generally the format is:
#
# name: value
#
# There are 2 sections:
# - global variables
# - one or more JOBS
#
# JOBS allow you to collect values from multiple sources.
# Each source will have its own set of charts.
#
# JOB parameters have to be indented (using spaces only, example below).
# ----------------------------------------------------------------------
# Global Variables
# These variables set the defaults for all JOBs, however each JOB
# may define its own, overriding the defaults.
# update_every sets the default data collection frequency.
# If unset, the python.d.plugin default is used.
# update_every: 1
# priority controls the order of charts at the netdata dashboard.
# Lower numbers move the charts towards the top of the page.
# If unset, the default for python.d.plugin is used.
# priority: 60000
# retries sets the number of retries to be made in case of failures.
# If unset, the default for python.d.plugin is used.
# Attempts to restore the service are made once every update_every
# and only if the module has collected values in the past.
# retries: 5
# ----------------------------------------------------------------------
# JOBS (data collection sources)
#
# The default JOBS share the same *name*. JOBS with the same name
# are mutually exclusive. Only one of them will be allowed running at
# any time. This allows autodetection to try several alternatives and
# pick the one that works.
#
# Any number of jobs is supported.
#
# All python.d.plugin JOBS (for all its modules) support a set of
# predefined parameters. These are:
#
# job_name:
# name: myname # the JOB's name as it will appear at the
# # dashboard (by default is the job_name)
# # JOBs sharing a name are mutually exclusive
# update_every: 1 # the JOB's data collection frequency
# priority: 60000 # the JOB's order on the dashboard
# retries: 5 # the JOB's number of restoration attempts
#
# uniset-plugin parameters:
# confile: xxx # configure.xml for project
# uname: ObjectName # ObjectID for monitoring process (Default: 'TestProc')
# port: num # port for connect to SharedMemory. Default: get from confile.
#
# Additionally to the above, example also supports the following:
#
# - none
#
# ----------------------------------------------------------------------
# AUTO-DETECTION JOBS
# only one of them will run (they have the same name)
unet
:
confile
: /
home
/
pv
/
Projects
.
com
/
uniset
-
2
.
0
/
conf
/
test
.
xml
name
:
utest
uname
:
TestProc
port
:
53817
project2
:
confile
: /
home
/
pv
/
Projects
.
com
/
uniset
-
2
.
0
/
conf
/
test
.
xml
name
:
project2
uname
:
TestProc1
port
:
53817
project3
:
confile
: /
home
/
pv
/
Projects
.
com
/
uniset
-
2
.
0
/
conf
/
test
.
xml
name
:
project3
uname
:
TestProc2
port
:
53817
python/tests/UInterface/testUI.py
View file @
77b6dc12
...
...
@@ -19,11 +19,16 @@ if __name__ == "__main__":
lst
.
add
(
sys
.
argv
[
i
]
)
prop
=
'Test'
lst
.
add_str
(
prop
)
try
:
uniset_init_params
(
lst
,
"test.xml"
);
obj1
=
UProxyObject
(
"TestProc"
)
uniset_activate_objects
()
;
uniset_activate_objects
()
print
"getShortName: id=
%
d name=
%
s"
%
(
1
,
getShortName
(
1
))
print
" getName: id=
%
d name=
%
s"
%
(
1
,
getName
(
1
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment