2nd Version with the complete UI and the first Version of cc+ .so

This commit is contained in:
2024-03-31 21:12:43 +02:00
parent 3fe818e144
commit a221b8f046
43 changed files with 2056 additions and 554 deletions

1
vrpmdvserver/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/vrpmwvpy-save-2023-03-27.zip

71
vrpmdvserver/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,71 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
},
"cmake.sourceDirectory": "/home/markus/git/vrpmdvweb/vrpmdvserver/rt_service"
}

View File

@@ -3,3 +3,4 @@
/vrpmdvmonitoringschema.cpython-310.pyc
/vrpmdvmonreq.cpython-310.pyc
/vrpmdvmonreqschema.cpython-310.pyc
/vrpmdvmonitoringState.cpython-310.pyc

8
vrpmdvserver/build/.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
/.cmake/
/CMakeFiles/
/.ninja_deps
/.ninja_log
/build.ninja
/cmake_install.cmake
/CMakeCache.txt
/compile_commands.json

BIN
vrpmdvserver/build/rt_service.so Executable file

Binary file not shown.

1
vrpmdvserver/extensions/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/__pycache__/

View File

View File

@@ -0,0 +1 @@
/__pycache__/

Binary file not shown.

View File

@@ -1 +1 @@
[{"id": "a214da99-2a77-4229-905b-5137a0d8071c", "created_at": "03/20/2024, 08:12", "name": "Monitorings1", "samplerate": 3750, "sampleperiod": 10, "downtime": 40, "owner": "Markus Lehr"}]
[{"id": "7c7a3fd8-0951-491c-bcf2-dc917058f60e", "created_at": "03/31/2024, 13:39", "name": "MM56", "samplerate": 3000, "sampleperiod": 2, "downtime": 7, "owner": "ML1", "status": "off"}, {"id": "4c17fd91-e273-4c1b-8561-5d2506c0f8b0", "created_at": "03/31/2024, 13:39", "name": "MM2", "samplerate": 7000, "sampleperiod": 1, "downtime": 5, "owner": "ML1", "status": "off"}, {"id": "13277d6a-4654-4448-8162-c057e8e03eac", "created_at": "03/31/2024, 13:48", "name": "MM1", "samplerate": 10000, "sampleperiod": 1, "downtime": 0, "owner": "ML1", "status": "stopped"}, {"id": "a412c952-cff7-4a4d-a064-214f4edbaac8", "created_at": "03/31/2024, 13:48", "name": "MM30", "samplerate": 3000, "sampleperiod": 2, "downtime": 30, "owner": "ML3", "status": "started"}, {"id": "a0d2fe83-f507-41c6-a833-283cf3ad69cf", "created_at": "03/31/2024, 13:48", "name": "MM37", "samplerate": 3000, "sampleperiod": 2, "downtime": 4, "owner": "ML35", "status": "started"}]

View File

@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 3.5)
# Find python and Boost - both are required dependencies
find_package(PythonLibs 3.10 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED)
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
#set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)
# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(rt_service MODULE rt_service.cpp)
# Set up the libraries and header search paths for this target
target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS})
set(MY_RESOURCE_FILE rt_service.so)
#set_directory_properties(MY_EXTENSION_LIB /home/markus/git/vrpmwvweb/vrpmdvserver/extensions/)
#file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${MY_RESOURCE_FILE}
# DESTINATION /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)
# location of the Python header files
#PYTHON_VERSION = 3.10
#PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
# location of the Boost Python include files and library
#BOOST_INC = /usr/include
#BOOST_LIB = /usr/lib
# compile mesh classes
#TARGET = rt_service
#$(TARGET).so: $(TARGET).o g++ -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -lboost_python-$(PYTHON_VERSION) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so
#$(TARGET).o: $(TARGET).cpp g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

View File

@@ -0,0 +1,69 @@
#include <boost/python.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include <string>
//#include <sstream>
//#include <vector>
struct RTService
{
// private:
// /* data */
// public:
// RT_Service(/* args */) {}
// ~RT_Service() {}
bool createMonitoring(std::string id) {
//TODO ML: add this to the M4Core
return true;
}
bool deleteMonitoring(std::string id) {
//TODO ML: add this to the M4Core
return true;
}
std::string getMonitoringState(std::string id) {
//TODO ask the M4Core for the Monitpring Status
return "Start";
}
boost::python::list getMonitoringStates() {
//TODO ask the M4Core for the Monitpring Status
boost::python::list list;
return list;
}
bool setMonitoringStatus(std::string id, std::string status) {
//set the Status
return true;
}
};
using namespace boost::python;
BOOST_PYTHON_MODULE(rt_service)
{
class_<RTService>("RT_Service")
.def("createMonitoring", &RTService::createMonitoring)
.def("getMonitoringStatus", &RTService::getMonitoringState)
.def("getAllMonitoringStat", &RTService::getMonitoringStates)
.def("setMonitoringStatus", &RTService::setMonitoringStatus)
;
};
//examples
// long l = len(msgs);
// std::stringstream ss;
// for (long i = 0; i<l; ++i) {
// if (i>0) ss << ", ";
// std::string s = boost::python::extract<std::string>(msgs[i]);
// ss << s;
// }
// mMsg = ss.str();

View File

@@ -2,6 +2,7 @@ from uuid import uuid4
import uuid
from flask import jsonify
import json
from extensions.rt_service import rt_service as rts
# from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
# from vrpmdvmonitoring import VRPMDV_Monitoring
@@ -13,8 +14,9 @@ class VRPMDV_Data:
def __init__(self):
#self.loaded = False
self.mons = []
self.mons:list = []
self.loaded = self.loadFile()
self.rtservice = rts.RT_Service()
def loadFile(self):
try:
@@ -27,11 +29,11 @@ class VRPMDV_Data:
else:
# data = json.loads(fmons)
schema = VRPMDV_MonitoringSchema(many=True)
res = schema.loads(fmons) # data
#res = schema.loads(fmons) # data
self.mons = schema.loads(fmons) # .append(res)
return True
except:
#nothing todo
#nothing todo ML we should create a file later the database
print("file not found")
def saveFile(self):
@@ -50,8 +52,8 @@ class VRPMDV_Data:
def getMonitorings(self):
# 1st time read file
if not self.loaded :
self.loaded = self.loadFile()
# if not self.loaded :
# self.loaded = self.loadFile()
schema = VRPMDV_MonitoringSchema()
result = schema.dumps(self.mons, many=True)
@@ -67,32 +69,51 @@ class VRPMDV_Data:
schema = VRPMDV_MonitoringSchema()
return schema.dumps(matched_obj)
def setMonitoring(self, vrpmid, request):
def setMonitoring(self, id, request):
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
matched_obj.name = request.name
matched_obj.samplerate = request.samplerate
matched_obj.sampleperiod = request.sampleperiod
matched_obj.downtime = request.downtime
self.saveFile()
matched_obj = next(x for x in self.mons if str(x.id) == id)
except:
return "no Item found"
if 'name' in request : matched_obj.name = request['name']
if 'samplerate' in request : matched_obj.samplerate = request['samplerate']
if 'sampleperiod' in request : matched_obj.sampleperiod = request['sampleperiod']
if 'downtime' in request : matched_obj.downtime = request['downtime']
if 'status' in request : matched_obj.setStatus(request['status'])
self.saveFile()
# we find it and we return it
schema = VRPMDV_MonitoringSchema()
return schema.dumps(matched_obj)
# try:
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
# matched_obj.name = request.name
# matched_obj.samplerate = request.samplerate
# matched_obj.sampleperiod = request.sampleperiod
# matched_obj.downtime = request.downtime
# self.saveFile()
# except:
# return "no Item found"
# # we find it and we return it
# schema = VRPMDV_MonitoringSchema()
# return schema.dumps(matched_obj)
def createMonitoring(self, request):
#mon = VRPMDV_Monitoring(request["name"], request["samplerate"], request["sampleperiod"], request["downtime"], request["owner"])
id = uuid.uuid4()
mon = VRPMDV_Monitoring(id, request.name, request.samplerate, request.sampleperiod, request.downtime, request.owner)
mon = VRPMDV_Monitoring(id, request.name, request.samplerate, request.sampleperiod, request.downtime, request.status, request.owner)
iscreated = mon.createMonitoring()
#iscreated = self.rtservice.createMonitoring(str(id))
if not self.loaded :
self.loaded = self.loadFile()
# if not self.loaded :
# self.loaded = self.loadFile()
# create monitoring
self.mons.append(mon)
#save to file
@@ -102,8 +123,8 @@ class VRPMDV_Data:
return schema.dumps(mon)
def deleteMonitoring(self, vrpmid):
if not self.loaded :
self.loaded = self.loadFile()
# if not self.loaded :
# self.loaded = self.loadFile()
# find monitoring with uuid
#result = filter(lambda mon: str(mon.uuid) == vrpmid["uuid"], self.mons)
@@ -112,7 +133,9 @@ class VRPMDV_Data:
except:
return "no Item found"
# we find it and now remove from list
# we find it, delete on realtime side and now remove from list
matched_obj.deleteMonitoring()
self.mons.remove(matched_obj)
#save the list
self.saveFile()
@@ -122,18 +145,47 @@ class VRPMDV_Data:
def startMonitoring(self, vrpmid):
#if not self.loaded :
# if not self.loaded :
# self.loaded = self.loadFile()
#call the start API of the kernel treiber
#call the start API of the c++ driver
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
except:
return "no Item found"
return "started"
if matched_obj.startMonitoring() :
#TODO ML return the state
return "started"
return "created"
def stopMonitoring(self, vrpmid):
#if not self.loaded :
# if not self.loaded :
# self.loaded = self.loadFile()
#call the start API of the kernel treiber
return "stopped"
#call the start API of the c++ driver
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
except:
return "no Item found"
matched_obj.startMonitoring()
return matched_obj.monstate.name
def setStatus(self, id, vrpmStatus):
if 'status' in vrpmStatus :
matched_obj = self.findMonitoring(id)
#call the start API of the c++ driver
matched_obj.setStatus(vrpmStatus['status'])
return matched_obj.status
return ""
def findMonitoring(self, id):
try:
return next(x for x in self.mons if str(x.id) == id)
except:
return "no Item found"

View File

@@ -3,7 +3,8 @@ import datetime as dt
from marshmallow import Schema, fields, post_load
from vrpmdvmonreq import VRPMDV_MonReq
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState
# class VRPMDV_MonReq:
# def __init__(self, name , samplerate, sampleperiod, downtime, owner) :
@@ -14,7 +15,45 @@ from vrpmdvmonreq import VRPMDV_MonReq
# self.owner = owner
class VRPMDV_Monitoring(VRPMDV_MonReq):
def __init__(self, id, name , samplerate, sampleperiod, downtime, owner="None", created_at=dt.datetime.now()) :
def __init__(self, id, name , samplerate, sampleperiod, downtime, status, owner="None", created_at=dt.datetime.now()) :
self.id = id
self.created_at = created_at
super().__init__(name, samplerate, sampleperiod, downtime, owner)
self.rtservice = rts.RT_Service()
super().__init__(name, samplerate, sampleperiod, downtime, owner, status)
def createMonitoring(self) :
if self.status != VRPMDVMonitoringState.OFF:
iscreated = self.rtservice.createMonitoring(str(self.id))
if not iscreated :
self.status = VRPMDVMonitoringState.OFF
return True
return False
def deleteMonitoring(self) :
isdeleted = self.rtservice.deleteMonitoring(str(self.id))
if (isdeleted) :
self.monstate = VRPMDVMonitoringState.OFF
return True
return False
def startMonitoring(self) :
isstarted = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.started)
if (isstarted) :
self.monstate = VRPMDVMonitoringState.STARTED
return True
return False
def stopMonitoring(self) :
isstopped = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.stopped)
if (isstopped) :
self.monstate = VRPMDVMonitoringState.STOPPED
return True
return False
def setStatus(self, status) :
isStatusSet = self.rtservice.setMonitoringStatus(str(self.id), status)
if (isStatusSet) :
self.status = status
return True
return False

View File

@@ -0,0 +1,31 @@
#from enum import Enum
from marshmallow import Schema, fields, post_load
class VRPMDVMonitoringState():
OFF = "off"
CREATED = "created"
STARTED = "started"
STOPPED = "stopped"
def __init__(self, state = OFF):
self.state = state
class VRPMDVMonitoringStateSchema(Schema):
monstate = fields.String()
@post_load
def make_vrpmdv_MonitoringState(self, data, **kwargs):
return VRPMDVMonitoringState(**data)
# class VRPMDVMonitoringState(Enum):
# off = 1
# created = 2
# started = 3
# stopped = 4

View File

@@ -2,11 +2,11 @@ import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, post_dump
from vrpmdvmonitoring import VRPMDV_Monitoring
from vrpmdvmonitoringState import VRPMDVMonitoringStateSchema
class VRPMDV_MonitoringSchema(Schema):
#__envelope__ = {"single": None, "many": "monitorings"}
id = fields.UUID()
created_at = fields.DateTime("%m/%d/%Y, %H:%M")
name = fields.String()
@@ -14,6 +14,9 @@ class VRPMDV_MonitoringSchema(Schema):
sampleperiod = fields.Integer()
downtime = fields.Integer()
owner = fields.String()
status = fields.String()
#monstate = fields.Enum(VRPMDVMonitoringState)
# def get_envelope_key(self, many):
# """Helper to get the envelope key."""
@@ -28,7 +31,12 @@ class VRPMDV_MonitoringSchema(Schema):
@post_load
def make_vrpmdv_Monitoring(self, data, **kwargs):
return VRPMDV_Monitoring(**data)
mon = VRPMDV_Monitoring(**data)
#create the monitoring on the realtime side
mon.createMonitoring()
return mon

View File

@@ -3,11 +3,12 @@ import datetime as dt
class VRPMDV_MonReq:
def __init__(self, name , samplerate, sampleperiod, downtime, owner) :
def __init__(self, name , samplerate, sampleperiod, downtime, owner, status) :
self.name = name
self.samplerate = samplerate
self.sampleperiod = sampleperiod
self.downtime = downtime
self.owner = owner
self.status = status

View File

@@ -10,6 +10,7 @@ class VRPMDV_MonReqSchema(Schema):
sampleperiod = fields.Integer()
downtime = fields.Integer()
owner = fields.String()
status = fields.String()
@post_load
def make_vrpmdv_MonitoringReq(self, data, **kwargs):

View File

@@ -30,7 +30,8 @@ def get_monitoring(id):
@app.route('/vrpmdvapi/1_0/monitorings/<id>', methods=['PATCH'])
def set_monitoring(id):
vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
# vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
vrpmreq = request.get_json()
data = vrpmdvdata.setMonitoring(id, vrpmreq)
resp = Response(data, status=200, mimetype='application/json')
return resp
@@ -52,20 +53,27 @@ def delete_monitoring(id):
@app.route('/vrpmdvapi/1_0/monitorings/start', methods=['PUT'])
@app.route('/vrpmdvapi/1_0/monitorings/start', methods=['PATCH'])
def start_monitoring():
vrpmid = request.get_json()
data = vrpmdvdata.startMonitoring(vrpmid)
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitorings/stop', methods=['PUT'])
@app.route('/vrpmdvapi/1_0/monitorings/stop/', methods=['PATCH'])
def stop_monitoring():
vrpmid = request.get_json()
data = vrpmdvdata.stopMonitoring(vrpmid)
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitoringstatus/<id>', methods=['PATCH'])
def setStatus(id):
vrpmStatus = request.get_json()
data = vrpmdvdata.setStatus(id, vrpmStatus)
resp = Response(data, status=200, mimetype='application/json')
return resp

View File

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB