added my Recipes

This commit is contained in:
2024-07-11 14:16:35 +02:00
parent 38bc4f53ac
commit 09b621d929
7118 changed files with 525762 additions and 3 deletions

View File

@@ -0,0 +1,76 @@
{
"files.associations": {
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "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",
"ranges": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp"
}
}

View File

@@ -0,0 +1,77 @@
{
"files.associations": {
"iostream": "cpp",
"string": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bit": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "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",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"ranges": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"variant": "cpp",
"fstream": "cpp"
}
}

View File

@@ -0,0 +1,46 @@
cmake_minimum_required(VERSION 3.5)
project(rt_service)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Find python and Boost - both are required dependencies
#find_package(Boost COMPONENTS filesystem chrono REQUIRED)
find_package(PythonLibs 3.10 REQUIRED)
find_package(Boost COMPONENTS python filesystem chrono 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)
file( GLOB LIB_SOURCES .src/*.cpp )
file( GLOB LIB_HEADERS lib/*.h )
set (RTSERVICEINCLUDE ./include)
# 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 ./src/rt_service.cpp ./src/monitoringTask/RTSMonitoringTask.cpp ./src/utilities/RelGILLock.cpp ./src/utilities/GILLock.cpp ./src/utilities/RTSCoproHelper.cpp ./src/utilities/RTSPyLogging.cpp ./src/monitoringTask/RTSResult.cpp ./src/monitoringTask/RTSErrResult.cpp)
add_library(rt_service MODULE ./src/rt_service.cpp ./src/monitoringTask/RTSMonFrame.cpp ./src/monitoringTask/RTSMonitoringTask.cpp ./src/utilities/RelGILLock.cpp ./src/utilities/GILLock.cpp ./src/utilities/RTSCoproHelper.cpp ./src/monitoringTask/RTSErrResult.cpp ./src/monitoringTask/VibChannelDesc.cpp ./src/monitoringTask/VibSensorDesc.cpp)
# Set up the libraries and header search pathsfor this target
target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS} ${RTSERVICEINCLUDE})
set(MY_RESOURCE_FILE rt_service.so)
# install(TARGETS rt_service LIBRARY DESTINATION lib)
# install(TARGETS t tlib
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# )

View File

@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.5)
project(rt_service)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
# 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)
set (RTSERVICEINCLUDE ./include)
file( GLOB LIB_SOURCES .src/*.cpp )
file( GLOB LIB_HEADERS lib/*.h )
# 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 ./src/rt_service.cpp ./src/monitoringTask/RTSMonitoringTask.cpp ./src/utilities/RelGILLock.cpp ./src/utilities/GILLock.cpp ./src/utilities/RTSCoproHelper.cpp)
# Set up the libraries and header search pathsfor this target
target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS} ${RTSERVICEINCLUDE})
set(MY_RESOURCE_FILE rt_service.so)
install(TARGETS rt_service LIBRARY DESTINATION lib)
# install(TARGETS t tlib
# RUNTIME DESTINATION bin
# LIBRARY DESTINATION lib
# )

View File

@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.5)
project( rt_service CXX )
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
# set(TOOLCHAIN_PREFIX $ENV{SYSROOTS}/x86_64-ostl_sdk-linux/usr/bin/arm-ostl-linux-gnueabi/arm-ostl-linux-gnueabi-)
set(CMAKE_C_COMPILER "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/x86_64/gcc-cross-arm/usr/bin/arm-ostl-linux-gnueabi/arm-ostl-linux-gnueabi-gcc")
set(CMAKE_CXX_COMPILER "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/x86_64/gcc-cross-arm/usr/bin/arm-ostl-linux-gnueabi/arm-ostl-linux-gnueabi-g++")
# set(CMAKE_CXX_COMPILER "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/x86_64/gcc-cross-arm/usr/bin/arm-ostl-linux-gnueabi/arm-ostl-linux-gnueabi-g++")
# -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
set(COMPILER_FLAGS " -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 -m32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
set(PYTHON_INCLUDE_DIRS "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/cortexa7t2hf-neon-vfpv4/python3/usr/include")
set(Boost_INCLUDE "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/cortexa7t2hf-neon-vfpv4/boost/include")
set(Boost_LIBRARIES "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/cortexa7t2hf-neon-vfpv4/boost/lib")
set(PYTHON_LIBRARIES "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/cortexa7t2hf-neon-vfpv4/python3/usr/lib")
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(rt_service SHARED rt_service.cpp)
# add_library(rt_service MODULE rt_service.cpp)
set_target_properties(rt_service PROPERTIES LINKER_LANGUAGE CXX)
# 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} ${Boost_INCLUDE})

View File

@@ -0,0 +1,103 @@
cmake_minimum_required(VERSION 3.5)
project( rt_service NONE )
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
set(SYSROOTS home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/SDK/sysroots)
set(TOOLCHAIN_PREFIX $ENV{SYSROOTS}/x86_64-ostl_sdk-linux/usr/bin/arm-ostl-linux-gnueabi/arm-ostl-linux-gnueabi-)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_SYSROOT $ENV{SYSROOTS}/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi)
set(CMAKE_PREFIX_PATH ${CMAKE_SYSROOT}/usr/lib/cmake)
# set(OE_QMAKE_PATH_EXTERNAL_HOST_BINS $ENV{QT_BIN_PATH}) => only for QT not needed at the moment
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
set(COMPILER_FLAGS " -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}" CACHE STRING "" FORCE)
list(APPEND CMAKE_MODULE_PATH "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/ cortexa7t2hf-neon-vfpv4/python3/usr")
list(APPEND CMAKE_MODULE_PATH "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/ cortexa7t2hf-neon-vfpv4/boost/usr")
# set(PYTHON_LIBRARIES "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/ cortexa7t2hf-neon-vfpv4/python3/usr/lib")
# set(PYTHON_INCLUDE_DIRS "home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/build-vrpmdv-stm32mp1/tmp-glibc/sysroots-components/cortexa7t2hf-neon-vfpv4/python3/usr/include")
# set(CMAKE_C_COMPILER_WORKS 1)
# set(CMAKE_CXX_COMPILER_WORKS 1)
# set(TOOLCHAIN_PREFIX home/markus/STM32MPU_workspace/STM32MP1-Ecosystem-V6.1.0/Distribution-Package-VRDevice/SDK/sysroots/x86_64-ostl_sdk-linux/usr/bin/arm-ostl-linux/)
# set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
# set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
# set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
# Find python and Boost - both are required dependencies
# find_package(PythonLibs REQUIRED)
# find_package(PythonLibs 3.10 REQUIRED)
# find_package(Boost 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_FIND_ROOT_PATH ${CMAKE_SYSROOT})
# set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
# set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#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_target_properties(rt_service PROPERTIES LINKER_LANGUAGE CXX)
# this is probably unlikely to be needed, but just in case
set(CMAKE_CXX_FLAGS "-m32")
set(CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE)
# set_target_properties(rt_service PROPERTIES COMPILE_OPTIONS "-m32")
# 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,12 @@
CMake system name must be something like "Linux".
# This is important for cross-compiling.
set(CMAKE_SYSTEM_PROCESSOR )
set(CMAKE_C_COMPILER arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER arm-poky-linux-gnueabi-g++)
set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/moviloc/fsl-release-bsp/build_qt5/tmp/sysroots/imx6ulevk" CACHE STRING "CFLAGS")
set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/moviloc/fsl-release-bsp/build_qt5/tmp/sysroots/imx6ulevk -fpermissive" CACHE STRING "CXXFLAGS")
set(CMAKE_C_FLAGS_RELEASE "-march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/moviloc/fsl-release-bsp/build_qt5/tmp/sysroots/imx6ulevk -DNDEBUG" CACHE STRING "CFLAGS for release")
set(CMAKE_CXX_FLAGS_RELEASE "-march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/home/moviloc/fsl-release-bsp/build_qt5/tmp/sysroots/imx6ulevk -DNDEBUG" CACHE STRING "CXXFLAGS for release")
set(CMAKE_C_LINK_FLAGS "" CACHE STRING "LDFLAGS")
set(CMAKE_CXX_LINK_FLAGS "" CACHE STRING "LDFLAGS")

View File

@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.5)
project( rt_service CXX )
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
# -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=<SDK installation directory>/SDK/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
set(COMPILER_FLAGS " -march=armv7ve -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 -m32")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILER_FLAGS}")
# Without this, any build libraries automatically have names "lib{x}.so"
set(CMAKE_SHARED_MODULE_PREFIX "")
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
# Add a shared module - modules are intended to be imported at runtime.
# - This is where you add the source files
add_library(rt_service SHARED rt_service.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

@@ -0,0 +1,21 @@
#include <boost/python.hpp>
#include <boost/thread.hpp>
//Use this class in a c++ funktion that called into python : c++ => python
class PyLockGIL
{
public:
PyLockGIL();
~PyLockGIL();
PyLockGIL(const PyLockGIL&) = delete;
PyLockGIL& operator=(const PyLockGIL&) = delete;
private:
PyGILState_STATE m_gstate;
};

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_ICHANNELDESC_H_
#define RTS_INCLUDE_ICHANNELDESC_H_
#include <string>
#include <list>
enum VALUEFORMAT {
UINT32 = 0,
INT32,
FLOAT,
DOUBLE,
};
union rtsSensorValue
{
uint32_t vUINT32;
int32_t vINT32;
float vFLOAT;
double vDOUBLE;
};
static const std::string RTSMONCHANNELNAME("name");
static const std::string RTSMONCHANNELVALUE("value");
static const std::string RTSMONCHANNELVALUETYPE("valuetype");
class IChannelDesc
{
public:
virtual u_int32_t GetId() = 0;
virtual const std::string& GetName() = 0;
virtual VALUEFORMAT GetValueFormat() = 0;
/**
* return the length of the data that is neeeded for one value of the channel in UINT32
*
*/
virtual u_int32_t GetValueByteSpace() = 0;
};
#endif /* RTS_INCLUDE_ICHANNELDESC_H_ */

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_ISENSORDESC_H_
#define RTS_INCLUDE_ISENSORDESC_H_
#include <string>
#include <list>
#include <json.hpp>
using json = nlohmann::json;
static const std::string RTSMONSENSOR("sensors");
static const std::string RTSMONCHANNELS("channels");
static const std::string RTSMONVALUES("values");
class ISensorDesc
{
public:
virtual int GetDescription() = 0;
virtual bool AddHW2Json(json& j) = 0;
virtual u_int32_t AddValues2Json(json& j, u_int32_t* values, u_int32_t actno, u_int32_t length) = 0;
};
#endif /* RTS_INCLUDE_ISENSORDESC_H_ */

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_RTSCOPROHELPER_H_
#define RTS_INCLUDE_RTSCOPROHELPER_H_
#include <string>
class RTSCoproHelper
{
private:
/* data */
//lock Element
int mFdRpmsg[2] = {-1, -1};
public:
RTSCoproHelper(/* args */);
~RTSCoproHelper();
int Init(std::string fwPath, std::string fwName);
int Copro_isFwRunning(void);
int Copro_openTtyRpmsg(int ttyNb, int modeRaw);
int Copro_closeTtyRpmsg(int ttyNb);
int Copro_writeTtyRpmsg(int ttyNb, int len, char* pData);
int Copro_readTtyRpmsg(int ttyNb, int len, char* pData);
int Copro_stopFw(void);
int Copro_startFw(void);
private:
int Copro_getFwPath(char* pathStr);
int Copro_setFwPath(const char* pathStr);
int Copro_getFwName(char* pathStr);
int Copro_setFwName(const char* nameStr);
};
#endif /* RTS_INCLUDE_RTSCOPROHELPER_H_ */

View File

@@ -0,0 +1,105 @@
/**
* @author
*/
#ifndef CM_INCLUDE_RTSERRRESULT_H_
#define CM_INCLUDE_RTSERRRESULT_H_
//#include <RTSResult.h>
#include <string>
#include <list>
#include <boost/python/dict.hpp>
//#include <boost/python/module.hpp>
// #include <boost/python/def.hpp>
//#include <boost/python/class.hpp>
// #include <boost/ref.hpp>
// #include <boost/python/ptr.hpp>
// #include <boost/python/return_value_policy.hpp>
// #include <boost/python/reference_existing_object.hpp>
// #include <boost/python/call.hpp>
// #include <boost/python/object.hpp>
//#define BOOST_ENABLE_ASSERT_HANDLER
//#include <boost/assert.hpp>
//using namespace boost::python;
struct RTSResult {
public:
RTSResult() : mResCode("")
{}
void setResCode(const std::string& resCode)
{
mResCode = resCode;
}
std::string getResCode()
{
return mResCode;
}
// boost::python::dict const& getProps()
// {
// return mProps;
// }
void setMsg(const std::string& newmsg)
{
msg = newmsg;
}
std::string getMsg()
{
return msg;
}
private:
std::string mResCode;
//boost::python::dict mProps;
std::string msg;
};
class RTSErrResult
{
private:
std::string mResCode;
std::list<std::string> msgs;
public:
RTSErrResult();
RTSErrResult(std::string rescode);
~RTSErrResult();
void setResCode(std::string resCode);
void format(const std::string fmt_str, ...);
RTSResult* getResult();
};
// class RTSErrResult : public RTSResult
// {
// private:
// /* data */
// std::string resCode;
// public:
// RTSErrResult(std::string rescode);
// ~RTSErrResult();
// void format(const std::string fmt_str, ...);
// };
#endif /* CM_INCLUDE_RTSERRRESULT_H_ */

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_RTSMONFRAME_H_
#define RTS_INCLUDE_RTSMONFRAME_H_
#include <string>
#include <list>
#include <ISensorDesc.h>
using json = nlohmann::json;
struct vRCMDeviceData {
uint32_t packageNo; //current package Number
uint32_t packageCount; //complete package Number
uint32_t dataQuantity; //number of uint32_t in data
uint32_t data[]; //the data
};
class RTSMonFrame
{
private:
/* data */
std::string id;
std::string name;
int samplerate;
int sampleperiod;
int downtime;
std::list<std::shared_ptr<ISensorDesc>> mSenorDesriptions;
std::string path;
public:
RTSMonFrame(std::string id, std::string name, int samplerate, int sampleperiod, int downtime, const std::list<std::shared_ptr<ISensorDesc>>& sensDesc, std::string path);
~RTSMonFrame();
std::string GetId();
void SetName(const std::string& name);
const std::string& GetName();
void SetSampleRate(int samplerate);
int GetSampleRate();
void SetSamplePeriod(int sampleperiod);
int GetSamplePeriod();
void SetDownTime(int downtime);
int GetDownTime();
bool generate(u_int32_t* values, u_int32_t length);
};
#endif /* RTS_INCLUDE_RTSMONFRAME_H_ */

View File

@@ -0,0 +1,146 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_RTSMONITORINGTASK_H_
#define RTS_INCLUDE_RTSMONITORINGTASK_H_
#include "RTSCoproHelper.h"
#include "RTSMonFrame.h"
#include <pthread.h>
#include <map>
#include <string>
#include <atomic>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/eventfd.h>
#include <sys/poll.h>
#include <fcntl.h>
#include <regex.h>
#include <sched.h>
#include <signal.h>
#include <inttypes.h>
#include <termios.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <error.h>
#include <signal.h>
#include <stdio.h>
#define NB_BUF 1
typedef struct
{
int bufferId, eventfd;
} rpmsg_sdb_ioctl_set_efd;
typedef struct
{
int bufferId;
uint32_t size;
} rpmsg_sdb_ioctl_get_data_size;
class RTSMonitoringTask
{
private:
/* data */
//lock Element
//std::map<int, RTSMonFrame*> rtsMonFrames;
pthread_t monThread;
/* The file descriptor used to manage our TTY over RPMSG */
int mFdRpmsg[2] = {-1, -1};
RTSCoproHelper coproHelper;
/* The file descriptor used to manage our SDB over RPMSG */
int mFdSdbRpmsg = -1;
rpmsg_sdb_ioctl_get_data_size q_get_data_size;
rpmsg_sdb_ioctl_set_efd q_set_efd;
int mefd[NB_BUF];
void* mmappedData[NB_BUF];
bool mfMappedData = false;
struct pollfd mfds[NB_BUF];
//uint8_t mDdrBuffAwaited = 1;
uint32_t mNbUncompData=0;
uint32_t mNbWrittenInFileData;
uint32_t mNbUncompMB=0;
uint32_t mNbPrevUncompMB=0;
uint32_t mNbTty0Frame=0;
char mByteBuffCpy[512];
struct timeval tval_before, tval_after, tval_result;
std::atomic_bool mRunThread= true;
public:
std::string id;
std::string monName;
int samplerate;
int sampleperiod;
int downtime;
std::string path;
public:
RTSMonitoringTask(std::string id, std::string name, int samplerate, int sampleperiod, int downtime, std::string path);
~RTSMonitoringTask();
//static RTSMonitoringTask& Instance();
bool Init();
//bool CreateMonitoring(int id, std::string name, int samplerate, int sampleperiod, int downtime, std::string status);
bool LoadFW();
bool Start();
bool Stop();
int Open(std::string monfilename);
bool Close();
std::string Read();
bool GetRunState();
void SetRunState(bool runThread);
std::string GetId();
void SetId(std::string id);
int GetRate();
void SetRate(int rate);
int GetPeriod();
void SetPeriod(int period);
int GetDowntime();
void SetDowntime(int downtime);
std::string GetPath();
void SetPath(std::string path);
private:
static void* Run(void *obj);
bool Load();
};
#endif /* RTS_INCLUDE_RTSMONITORINGTASK_H_ */

View File

@@ -0,0 +1,51 @@
/**
* @author
*/
//#include <boost/python/detail/python_type.hpp>
#include <string>
//#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
//#include <boost/python/class.hpp>
#include <boost/ref.hpp>
#include <boost/python/ptr.hpp>
#include <boost/python/return_value_policy.hpp>
#include <boost/python/reference_existing_object.hpp>
#include <boost/python/call.hpp>
#include <boost/python/object.hpp>
//#define BOOST_ENABLE_ASSERT_HANDLER
//#include <boost/assert.hpp>
using namespace boost::python;
BOOST_STATIC_ASSERT(converter::is_object_manager<handle<> >::value);
// class RTSPyLoggingBase
// {
// public:
// virtual ~RTSPyLoggingBase();
// virtual void log(std::string msg) = 0;
// };
class RTSPyLogging // : RTSPyLoggingBase
{
private:
/* data */
//PyObject* const mplogging;
public:
// RTSPyLogging(PyObject* pPyLogging);
RTSPyLogging();
~RTSPyLogging();
void log(std::string msg, PyObject* f);
std::string format(const std::string fmt_str, ...);
};

View File

@@ -0,0 +1,70 @@
/**
* @author Markus Lehr<markus@malehr.de>
*/
#ifndef CM_INCLUDE_RTSRESULT_H_
#define CM_INCLUDE_RTSRESULT_H_
#include <string>
// #include <boost/python/module.hpp>
// #include <boost/python/def.hpp>
//#include <boost/python/class.hpp>
// #include <boost/ref.hpp>
// #include <boost/python/ptr.hpp>
// #include <boost/python/return_value_policy.hpp>
// #include <boost/python/reference_existing_object.hpp>
// #include <boost/python/call.hpp>
// #include <boost/python/object.hpp>
#include <boost/python/dict.hpp>
using namespace boost::python;
std::string format(const std::string fmt_str, ...)
{
va_list ap;
char *fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
std::unique_ptr<char[]> formatted(fp);
return std::string(formatted.get());
}
struct RTSResult
{
RTSResult(std::string resCode) : mResCode(resCode){}
std::string getResCode() {return mResCode;}
boost::python::dict const& getProperties() {return mProp;}
private:
/* data */
std::string mResCode;
boost::python::dict mProp;
};
// class RTSResult
// {
// private:
// /* data */
// std::string mResCode;
// protected:
// boost::python::dict mProp;
// public:
// RTSResult(std::string resCode);
// ~RTSResult();
// std::string getResCode();
// boost::python::dict const& getProperties();
// };
#endif /* CM_INCLUDE_RTSRESULT_H_ */

View File

@@ -0,0 +1,19 @@
#include <boost/python.hpp>
#include <boost/thread.hpp>
//Use this class in a c++ funktion that is called from python : python => c++
class PyRelinquishGIL
{
public:
PyRelinquishGIL();
~PyRelinquishGIL();
PyRelinquishGIL(const PyRelinquishGIL&) = delete;
PyRelinquishGIL& operator=(const PyRelinquishGIL&) = delete;
private:
PyThreadState* m_thread_state;
};

View File

@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_VIBCHANNELDESC_H_
#define RTS_INCLUDE_VIBCHANNELDESC_H_
#include <string>
#include <list>
#include <IChannelDesc.h>
class VibChannelDesc : public IChannelDesc
{
private:
u_int32_t id;
std::string name;
VALUEFORMAT valueFormat;
u_int32_t vByteSpace;
public:
VibChannelDesc(u_int32_t id, const std::string& name, VALUEFORMAT valueFormat, u_int32_t vByteSpace = 1);
u_int32_t GetId() override;
const std::string& GetName() override;
VALUEFORMAT GetValueFormat() override;
/**
* return the length of the data that is neeeded for one value of the channel in UINT32
*
*/
u_int32_t GetValueByteSpace() override;
};
#endif /* RTS_INCLUDE_VIBCHANNELDESC_H_ */

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024 Markus Lehr.
*
*
* SPDX-License-Identifier: Owend property of Markus Lehr
*
*/
#ifndef RTS_INCLUDE_VIBSENSORDESC_H_
#define RTS_INCLUDE_VIBSENSORDESC_H_
#include <ISensorDesc.h>
#include <IChannelDesc.h>
#include <string>
#include <list>
#include <json.hpp>
using json = nlohmann::json;
class VibSensorDesc: public ISensorDesc
{
private:
std::string name;
std::list<std::shared_ptr<IChannelDesc>> mDescriptions;
public:
VibSensorDesc(const std::string& name);
int GetDescription() override;
bool AddHW2Json(json& j) override;
u_int32_t AddValues2Json(json& j, u_int32_t* values, u_int32_t actno, u_int32_t length) override;
};
#endif /* RTS_INCLUDE_VIBSENSORDESC_H_ */

View File

@@ -0,0 +1,176 @@
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
#include <cstdint> // int64_t, uint64_t
#include <map> // map
#include <memory> // allocator
#include <string> // string
#include <vector> // vector
// #include <nlohmann/detail/abi_macros.hpp>
// __ _____ _____ _____
// __| | __| | | | JSON for Modern C++
// | | |__ | | | | | | version 3.11.3
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
//
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
// SPDX-License-Identifier: MIT
// This file contains all macro definitions affecting or depending on the ABI
#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
#if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
#if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3
#warning "Already included a different version of the library!"
#endif
#endif
#endif
#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum)
#define NLOHMANN_JSON_VERSION_PATCH 3 // NOLINT(modernize-macro-to-enum)
#ifndef JSON_DIAGNOSTICS
#define JSON_DIAGNOSTICS 0
#endif
#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
#endif
#if JSON_DIAGNOSTICS
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
#else
#define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
#endif
#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
#else
#define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
#endif
// Construct the namespace ABI tags component
#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
#define NLOHMANN_JSON_ABI_TAGS \
NLOHMANN_JSON_ABI_TAGS_CONCAT( \
NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
// Construct the namespace version component
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
_v ## major ## _ ## minor ## _ ## patch
#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
#define NLOHMANN_JSON_NAMESPACE_VERSION
#else
#define NLOHMANN_JSON_NAMESPACE_VERSION \
NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
NLOHMANN_JSON_VERSION_MINOR, \
NLOHMANN_JSON_VERSION_PATCH)
#endif
// Combine namespace components
#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
#ifndef NLOHMANN_JSON_NAMESPACE
#define NLOHMANN_JSON_NAMESPACE \
nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION)
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
#define NLOHMANN_JSON_NAMESPACE_BEGIN \
namespace nlohmann \
{ \
inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
NLOHMANN_JSON_ABI_TAGS, \
NLOHMANN_JSON_NAMESPACE_VERSION) \
{
#endif
#ifndef NLOHMANN_JSON_NAMESPACE_END
#define NLOHMANN_JSON_NAMESPACE_END \
} /* namespace (inline namespace) NOLINT(readability/namespace) */ \
} // namespace nlohmann
#endif
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@since version 1.0.0
*/
NLOHMANN_JSON_NAMESPACE_BEGIN
/*!
@brief default JSONSerializer template argument
This serializer ignores the template arguments and uses ADL
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
for serialization.
*/
template<typename T = void, typename SFINAE = void>
struct adl_serializer;
/// a class to store JSON values
/// @sa https://json.nlohmann.me/api/basic_json/
template<template<typename U, typename V, typename... Args> class ObjectType =
std::map,
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string, class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
class CustomBaseClass = void>
class basic_json;
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
/// @sa https://json.nlohmann.me/api/json_pointer/
template<typename RefStringType>
class json_pointer;
/*!
@brief default specialization
@sa https://json.nlohmann.me/api/json/
*/
using json = basic_json<>;
/// @brief a minimal map-like container that preserves insertion order
/// @sa https://json.nlohmann.me/api/ordered_map/
template<class Key, class T, class IgnoredLess, class Allocator>
struct ordered_map;
/// @brief specialization that maintains the insertion order of object keys
/// @sa https://json.nlohmann.me/api/ordered_json/
using ordered_json = basic_json<nlohmann::ordered_map>;
NLOHMANN_JSON_NAMESPACE_END
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_

View File

@@ -0,0 +1,23 @@
#include "../include/RTSMonitoringTask.h"
#include <chrono>
#include <thread>
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) {
RTSMonitoringTask rtMon;
if (rtMon.Init()) {
// idle
while(1)
{
rtMon.CreateMonitoring(1, "Test1", 3750, 2, 10, "stopped");
// sleep 100 ms
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
return 0;
}

View File

@@ -0,0 +1,130 @@
/**
*
*/
#include <RTSErrResult.h>
#include <GILLock.h>
#include <boost/python.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/return_value_policy.hpp>
RTSErrResult::RTSErrResult()
{
}
RTSErrResult::RTSErrResult(std::string resCode) : mResCode(resCode)
{
}
RTSErrResult::~RTSErrResult()
{
}
void RTSErrResult::setResCode(std::string resCode) {
this->mResCode = resCode;
}
void RTSErrResult::format(const std::string fmt_str, ...)
{
va_list ap;
char *fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
std::unique_ptr<char[]> formatted(fp);
this->msgs.push_back(formatted.get());
//this->mProp[std::wstring(L"msg")] = formatted.get();
//this->mProp[key] = formatted.get();
}
RTSResult* RTSErrResult::getResult() {
RTSResult* res = new RTSResult();
res->setResCode(this->mResCode);
std::string msgstr = std::string("msg"); //std::wstring msgstr = std::wstring(L"msg");
std::string msg = this->msgs.back();
res->setMsg(msg);
int i = 0;
// boost::python::dict d = res->getProps();
// for (std::string msgtext : this->msgs)
// {
// std::string newmsg = msgstr + std::to_string(i);
// d[newmsg]= msgtext;
// i = i + 1;
// }
return res;
}
// PyObject* RTSErrResult::getResult() {
// boost::python::dict d;
// d[std::string("rescode")] = this->mResCode;
// std::string msgstr = std::string("msg"); //std::wstring msgstr = std::wstring(L"msg");
// int i = 0;
// for (std::string msgtext : this->msgs)
// {
// std::string newmsg = msgstr + std::to_string(i);
// d[newmsg]= msgtext;
// i = i + 1;
// }
// return boost::python::incref(boost::python::object(d).ptr());
// }
using namespace boost::python;
// BOOST_PYTHON_MODULE(RTSResult)
// {
// class_<RTSResult>("RTSResult")
// .def("getResCode", &RTSResult::getResCode)
// .def("getProps", &RTSResult::getProps , return_value_policy<copy_const_reference>())
// ;
// }
// void RTSPyLogging::log(std::string msg, PyObject* f){
// // GIL state handler
// PyLockGIL gstate;
// // Python callback
// call_method<void>(f, "log", msg);
// // GIL handler release
// }
// std::string RTSErrResult::format(const std::string fmt_str, ...)
// {
// va_list ap;
// char *fp = NULL;
// va_start(ap, fmt_str);
// vasprintf(&fp, fmt_str.c_str(), ap);
// va_end(ap);
// std::unique_ptr<char[]> formatted(fp);
// return std::string(formatted.get());
// }
// BOOST_PYTHON_MODULE(RTSResult)
// {
// class_<RTSResult>("RTSResult", init<std::string>())
// .def("get_bar", &Foo::get_bar
// , return_value_policy<copy_const_reference>())
// ;
// }

View File

@@ -0,0 +1,283 @@
/*
*/
#include <RTSMonFrame.h>
#include <json.hpp>
#include <fstream>
#include <string>
#include <iostream>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
static const std::string RTSMONFID("id");
static const std::string RTSMONID("monid");
static const std::string RTSMONNAME("name");
static const std::string RTSMONSRATE("samplerate");
static const std::string RTSMONSPERIOD("sampleperiod");
static const std::string RTSMONDTIME("downtime");
static const std::string RTSMONTIMESTAMP("timestamp");
static const std::string RTSMONSAMPLES("samples");
static const std::string RTSMONHW("hwdescription");
using namespace std::chrono;
RTSMonFrame::RTSMonFrame(std::string id, std::string name, int samplerate, int sampleperiod, int downtime, const std::list<std::shared_ptr<ISensorDesc>>& sensDesc, std::string path) {
this->id = id;
this->name = name;
this->samplerate = samplerate;
this->sampleperiod = sampleperiod;
this->downtime = downtime;
this->mSenorDesriptions.insert(this->mSenorDesriptions.end(), sensDesc.begin(), sensDesc.end());
this->path = path;
}
RTSMonFrame::~RTSMonFrame(){}
std::string RTSMonFrame::GetId() {
return this->id;
}
void RTSMonFrame::SetName(const std::string& name){
this->name = name;
}
const std::string& RTSMonFrame::GetName() {
return this->name;
}
void RTSMonFrame::SetSampleRate(int samplerate){
this->samplerate = samplerate;
}
int RTSMonFrame::GetSampleRate() {
return this->samplerate;
}
void RTSMonFrame::SetSamplePeriod(int sampleperiod){
this->sampleperiod= sampleperiod;
}
int RTSMonFrame::GetSamplePeriod(){
return this->sampleperiod;
}
void RTSMonFrame::SetDownTime(int downtime){
this->downtime= downtime;
}
int RTSMonFrame::GetDownTime(){
return this->downtime;
}
bool RTSMonFrame::generate([[maybe_unused]] u_int32_t* values, [[maybe_unused]] u_int32_t length){
// Example of the very popular RFC 3339 format UTC time
std::stringstream ss;
//build path
ss << this->path << this->id;
std::string monpath = ss.str();
boost::filesystem::path directory(monpath.c_str());
//check for directory
if (!boost::filesystem::exists(directory)){
boost::filesystem::create_directories(directory);
printf("CA7 : created dir %s.\n", monpath.c_str());
}
std::time_t time = std::time({});
char timeString[std::size("yyyy-mm-ddThh:mm:ss")];
std::strftime(std::data(timeString), std::size(timeString),"%FT%TZ", std::gmtime(&time));
ss << "/" << timeString << ".json";
std::string filename = ss.str();
printf("CA7 : filename %s.\n", filename.c_str());
auto unix_timestamp = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
//generate header id, name, timestamp,samplerate, sampleperiod, downtime
json j;
json jsamples = json::array();
boost::uuids::random_generator gen;
boost::uuids::uuid u = gen();
std::string sampleid = to_string(u);
printf("CA7 : uuid %s.\n", sampleid.c_str());
j[RTSMONFID] = sampleid;
j[RTSMONID] = this->id;
j[RTSMONNAME] = this->name;
j[RTSMONSRATE] = this->samplerate;
j[RTSMONSPERIOD] = this->sampleperiod;
j[RTSMONDTIME] = this->downtime;
j[RTSMONTIMESTAMP] = unix_timestamp;
vRCMDeviceData* pDeviceData = (vRCMDeviceData*) values;
uint32_t pacCount = pDeviceData->packageCount;
uint32_t* packData = pDeviceData->data;
uint32_t actNo = 0;
json jsensors = json::array();
for (auto &&sensDesc : this->mSenorDesriptions)
{
actNo = sensDesc->AddHW2Json(jsensors);
}
j[RTSMONHW] = jsensors;
json jvalues = json::array();
printf("CA7 : start writing data %s.\n", monpath.c_str());
for (size_t actPacNo = 0; actPacNo <= pacCount; actPacNo++)
{
printf("CA7 : writing packing %d.\n", actPacNo);
//TODO ML: check that the maxNo is smaller than i
while (actNo < pDeviceData->dataQuantity)
{
//json jsample = json::object();
if (this->mSenorDesriptions.empty()) {
printf("CA7 : no sensor description.\n");
actPacNo = pacCount;
break;
}
for (auto &&sensDesc : this->mSenorDesriptions)
{
//actNo = sensDesc->Add2Json(jsample, values, actNo, pDeviceData->dataQuantity);
actNo = sensDesc->AddValues2Json(jvalues, packData, actNo, pDeviceData->dataQuantity);
}
// jsample[RTSMONVALUES] = jvalues;
// jsamples.push_back(jsample);
printf("CA7 : jsamples.push_back - actno[%d].\n", actNo);
}
//printf("CA7 : datpac written %d.\n", actPacNo);
//set the point to the new package
int dlength = actPacNo * (3 + pDeviceData->dataQuantity);
printf("CA7 : dlength = %d - actPacNo = %d - dataQuantity = %d.\n", dlength, actPacNo, pDeviceData->dataQuantity);
pDeviceData = (vRCMDeviceData*) (values + dlength);
packData = pDeviceData->data;
actNo = 0;
}
//j[RTSMONSAMPLES] = jsamples;
j[RTSMONVALUES] = jvalues;
printf("CA7 : end writing data %s.\n", monpath.c_str());
// write prettified JSON to another file
std::ofstream o(filename);
o << std::setw(4) << j << std::endl;
return true;
}
/*
uint64_t timeSinceEpochMillisec() {
using namespace std::chrono;
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
}
*/
/*
// Example of the very popular RFC 3339 format UTC time
std::stringstream ss;
std::time_t time = std::time({});
char timeString[std::size("yyyy-mm-ddThh:mm:ssZ")];
std::strftime(std::data(timeString), std::size(timeString),"%FT%TZ", std::gmtime(&time));
ss << "/home/root/monfiles/" << timeString << ".txt";
std::string filename = ss.str();
printf("CA7 : filename %s.\n", filename.c_str());
//save to file
std::ofstream outfile (filename,std::ofstream::binary);
// if (outfile.write (mByteBuffCpy,this->q_get_data_size.size))
// {
// printf("CA7 : write file %s succesfully.\n", filename.c_str());
// result = std::string("CA7 : write file %s succesfully.\n") + filename;
// }
// else {
// result = std::string("CA7 : file could not be written.\n") + filename;
// printf("CA7 : file %s could not be written.\n", filename.c_str());
// }
outfile.close();
printf("CA7 : file %s closed.\n", filename.c_str());
*/
/** old impl */
//unsigned char* pData = (unsigned char*) this->mmappedData[i];
// save a copy of 1st data
//mByteBuffCpy[0] = *pData;
// printf("CA7 : filename pointer:%p , pno:%d, pcount:%d, dataCount:%d .\n"
// , pData
// , pData[0].packageNo
// , pData[0].packageCount
// , pData[0].dataQuantity);
// printf("CA7 : data[0]:%d , data[1]:%d data[2]:%d \n data[115]:%d , data[116]:%d data[117]:%d.\n"
// , pData[0].data[0]
// , pData[0].data[1]
// , pData[0].data[2]
// , pData[0].data[115]
// , pData[0].data[116]
// , pData[0].data[117]);
// int dlength = 1* (3 + pData->dataQuantity);
// pData = (vRCMDeviceData*) (u32Buff + dlength);
// printf("CA7 : u32Buff[%p] - pData[%p] - dlength=%d \n", u32Buff , pData, dlength);
// printf("CA7 : filename pointer:%p , pno:%d, pcount:%d, dataCount:%d, data[0]:%d , data[1]:%d data[2]:%d , data[3]:%d , data[4]:%d data[5]:%d.\n"
// , pData
// , pData->packageNo
// , pData->packageCount
// , pData->dataQuantity
// , pData->data[0]
// , pData->data[1]
// , pData->data[2]
// , pData->data[3]
// , pData->data[4]
// , pData->data[5]);
// Example of the very popular RFC 3339 format UTC time
// std::stringstream ss;
// std::time_t time = std::time({});
// char timeString[std::size("yyyy-mm-ddThh:mm:ssZ")];
// std::strftime(std::data(timeString), std::size(timeString),"%FT%TZ", std::gmtime(&time));
// ss << "/home/root/monfiles/" << timeString << ".txt";
// std::string filename = ss.str();
// printf("CA7 : filename %s.\n", filename.c_str());
// //save to file
// std::ofstream outfile (filename,std::ofstream::binary);
// // if (outfile.write (mByteBuffCpy,this->q_get_data_size.size))
// // {
// // printf("CA7 : write file %s succesfully.\n", filename.c_str());
// // result = std::string("CA7 : write file %s succesfully.\n") + filename;
// // }
// // else {
// // result = std::string("CA7 : file could not be written.\n") + filename;
// // printf("CA7 : file %s could not be written.\n", filename.c_str());
// // }
// outfile.close();
//printf("CA7 : file %s closed.\n", filename.c_str());

View File

@@ -0,0 +1,332 @@
/*
*/
#include <RTSMonitoringTask.h>
#include <RTSErrResult.h>
#include <RelGILLock.h>
//#include "../../include/json.hpp"//((
//#include "../../include/json_fwd.hpp"
#include <string>
#include<iostream>
#include <memory>
#include<cstring>
#include <RTSMonFrame.h>
#include<ISensorDesc.h>
#include <chrono>
#include <sstream>
#include <fstream>
#include <VibSensorDesc.h>
// #define RPMSG_SDB_IOCTL_SET_EFD _IOW('R', 0x00, struct rpmsg_sdb_ioctl_set_efd *)
// #define RPMSG_SDB_IOCTL_GET_DATA_SIZE _IOWR('R', 0x01, struct rpmsg_sdb_ioctl_get_data_size *)
#define RPMSG_SDB_IOCTL_SET_EFD _IOW('R', 0x00, rpmsg_sdb_ioctl_set_efd *)
#define RPMSG_SDB_IOCTL_GET_DATA_SIZE _IOWR('R', 0x01, rpmsg_sdb_ioctl_get_data_size *)
#define DATA_BUF_POOL_SIZE 1024*1024 /* 1MB */
#define TIMEOUT 1 * 1000
RTSMonitoringTask::RTSMonitoringTask(std::string id, std::string name, int samplerate, int sampleperiod, int downtime, std::string path)
{
this->id = id;
this->monName = name;
this->samplerate = samplerate;
this->sampleperiod = sampleperiod;
this->downtime = downtime;
this->path = path;
}
RTSMonitoringTask::~RTSMonitoringTask()
{
}
bool RTSMonitoringTask::Load() {
//later load the file
//int id = 1;
return true;
}
bool RTSMonitoringTask::Init() {
const std::string fwPath = "home/root/elffile";
const std::string fwName = "zephyr_openamp_rsc_table.elf";
//check if the FWIsRunning
// if (coproHelper.Init(fwPath, fwName) >= 0) {
// printf("CA7 : Init success \n");
if (pthread_create( &monThread, NULL, &RTSMonitoringTask::Run, this) == 0) {
printf("CA7 : mon thread creation fails\n");
return true;
}
return false;
}
void* RTSMonitoringTask::Run(void *obj) {
RTSMonitoringTask* rtsMonTask = static_cast<RTSMonitoringTask*>(obj);
int fdSdbRpmsg = rtsMonTask->Open("/dev/mon-datafile");
if (fdSdbRpmsg > 0) {
while (rtsMonTask->GetRunState()) {
rtsMonTask->Read();
}
rtsMonTask->Close();
}
return 0;
}
bool RTSMonitoringTask::GetRunState() {
return mRunThread;
}
void RTSMonitoringTask::SetRunState(bool runThread) {
this->mRunThread.store(runThread) ;
}
int RTSMonitoringTask::Open(std::string monfilename){
//PyRelinquishGIL scoped;
this->mFdSdbRpmsg = open(monfilename.c_str(), O_RDWR);
if (this->mFdSdbRpmsg < 0) {
printf("CA7 : Err openening %s, ret=%d\n",monfilename.c_str(), this->mFdSdbRpmsg);
}
else {
printf("CA7 : Succes openening %s, ret=%d\n",monfilename.c_str(), this->mFdSdbRpmsg);
//this->log(this->format("CA7 : Success on openening %s, ret=%d\n",monfilename, this->mFdSdbRpmsg), f);
for (int i=0;i<NB_BUF;i++){
// Create the evenfd, and sent it to kernel driver, for notification of buffer full
this->mefd[i] = eventfd(0, 0);
if (this->mefd[i] == -1) {
printf("CA7 : failed to get eventfd:%d\n",i);
//this->mLogs.push_back("CA7 : failed to get eventfd:%d");
}
else {
printf("CA7 : Forward efd info for buf%d with mFdSdbRpmsg:%d and efd:%d\n",i,this->mFdSdbRpmsg,this->mefd[i]);
}
this->q_set_efd.bufferId = i;
this->q_set_efd.eventfd = this->mefd[i];
if(ioctl(mFdSdbRpmsg, RPMSG_SDB_IOCTL_SET_EFD, &(this->q_set_efd)) < 0) {
printf("CA7 :failed to set efd efd%d-mFdSdbRpmsg%d for :%d\n",i,this->mFdSdbRpmsg,this->mefd[i]);
}
else {
printf("CA7 : succes to set efd efd%d-mFdSdbRpmsg%d:%d\n",i,this->mFdSdbRpmsg,this->mefd[i]);
}
// watch eventfd for input
this->mfds[i].fd = this->mefd[i];
this->mfds[i].events = POLLIN;
printf("CA7 : start mapping buffer for efd:%d\n",i);
// opensuccess.format("CA7 : start mapping buffer for efd:%d",i);
// this->mLogs.push_back(this->format(u8"CA7 : start mapping buffer for efd:%d",i));
//this->mLogs.push_back("CA7 : start mapping buffer for efd");
mmappedData[i] = mmap(NULL,
DATA_BUF_POOL_SIZE,
PROT_READ | PROT_WRITE,
MAP_PRIVATE,
this->mFdSdbRpmsg,
0);
printf("CA7 : DBG mmappedData[%d]:%p\n", i, mmappedData[i]);
this->mfMappedData = true;
usleep(50000);
}
}
//assert(this->mFdSdbRpmsg != -1);
return this->mFdSdbRpmsg;
}
std::string RTSMonitoringTask::Read(){
//PyRelinquishGIL scoped;
std::string result;
std::list<std::shared_ptr<ISensorDesc>> sensDescs;
std::shared_ptr<ISensorDesc> sensorDesc = std::make_shared<VibSensorDesc>("RT850");
sensDescs.push_back(sensorDesc);
//std::string TEST = "Test";
RTSMonFrame frame(this->id,this->monName, this->samplerate, this->sampleperiod, this->downtime, sensDescs, this->path);
int ret, rc;
char buf[16];
char dbgmsg[80];
// wait till at least one buffer becomes available
//this->mLogs.push_back("CA7 : Start Polling.\n");
//printf("CA7 : Start Polling.\n");
ret = poll(this->mfds, NB_BUF, TIMEOUT); //ret = poll(fds, NB_BUF, TIMEOUT * 1000);
if (ret == -1) {
perror("poll()");
//this->mLogs.push_back("CA7 : Error Polling.\n");
printf("CA7 : Poll Error.\n");
return std::string("poll error");
}
else if (ret == 0){
printf("CA7 : No buffer data within %d msec.\n", TIMEOUT);
//this->mLogs.push_back("CA7 : No buffer data within 300 msec.\n");
return std::string("CA7 : No buffer data within %d msec.\n");
}
for (size_t i = 0; i < NB_BUF; i++)
{
int revent = this->mfds[i].revents;
printf("CA7 : try Reading Buffer %d, reevent=%d, POLLIN=%d.\n", i, revent, POLLIN);
if (this->mfds[i].revents & POLLIN) {
printf("CA7 : Start Reading Buffer %d.\n", i );
rc = read(this->mefd[i], buf, 16);
if (!rc) {
return std::string("CA7: stdin closed - Buffer:%d\n", i);
}
/* Get buffer data size*/
this->q_get_data_size.bufferId = i;
if(ioctl(this->mFdSdbRpmsg, RPMSG_SDB_IOCTL_GET_DATA_SIZE, &(this->q_get_data_size)) < 0) {
printf("CA7 : Failed to get data size.\n");
return std::string("Failed to get data size\n");
}
if (this->q_get_data_size.size) {
printf("CA7 : call generate frame - datasize:%d.\n", this->q_get_data_size.size);
mNbUncompMB++;
mNbUncompData += this->q_get_data_size.size;
u_int32_t* u32Buff = (u_int32_t*) this->mmappedData[i];
frame.generate(u32Buff, this->q_get_data_size.size);
this->mfds[i].revents = 0;
}
// else {
// result = std::string("CA7 : file could not be written.\n") + filename;
// //printf("CA7 : file %s could not be written.\n", filename);
// }
//outfile.close();
// gettimeofday(&tval_after, NULL);
// timersub(&tval_after, &tval_before, &tval_result);
//this->mLogs.push_back("CA7: mon_thread data EVENT mDdrBuffAwaited\n");
}
// else {
// //printf("CA7 : sdb_thread => buf[%d] is empty\n", mDdrBuffAwaited);
// //this->mLogs.push_back("CA7: buffer is empty\n");
// return std::string("CA7: buffer is empty\n");
// }
// mDdrBuffAwaited++;
// if (mDdrBuffAwaited >= NB_BUF) {
// mDdrBuffAwaited = 0;
// }
}
return result;
}
bool RTSMonitoringTask::Close(){
//PyRelinquishGIL scoped;
printf("CA7 : close of device \n");
if (this->mfMappedData) {
for (int i=0;i<NB_BUF;i++){
int rc = munmap(mmappedData[i], DATA_BUF_POOL_SIZE);
if (rc != 0) {
printf("CA7 : Buffer could not be unmapped\n");
}
}
this->mfMappedData = 0;
}
int res = close(this->mFdSdbRpmsg);
if (res != 0) {
printf("CA7 : close of device failed: %s\n", strerror(errno));
return false;
}
printf("CA7 : close of device done\n");
return true;
}
bool RTSMonitoringTask::Start(){
const std::string fwPath = "home/root/elffile";
const std::string fwName = "zephyr_openamp_rsc_table.elf";
if (pthread_create( &monThread, NULL, &RTSMonitoringTask::Run, this) == 0) {
printf("CA7 : mon thread creation success\n");
return true;
}
printf("CA7 : mon thread creation fails\n");
return false;
}
bool RTSMonitoringTask::Stop(){
this->SetRunState(false);
printf("CA7 : mon thread terminating\n");
pthread_join(monThread, NULL);
printf("CA7 : mon thread terminated\n");
return true;
}
std::string RTSMonitoringTask::GetId(){
return this->id;
}
void RTSMonitoringTask::SetId(std::string id){
this->id = id;
}
int RTSMonitoringTask::GetRate(){
return this->samplerate;
}
void RTSMonitoringTask::SetRate(int rate){
this->samplerate = rate;
}
int RTSMonitoringTask::GetPeriod(){
return this->sampleperiod;
}
void RTSMonitoringTask::SetPeriod(int period){
this->sampleperiod = period;
}
int RTSMonitoringTask::GetDowntime(){
return this->downtime;
}
void RTSMonitoringTask::SetDowntime(int downtime){
this->downtime = downtime;
}
std::string RTSMonitoringTask::GetPath(){
return this->path;
}
void RTSMonitoringTask::SetPath(std::string path){
this->path = path;
}

View File

@@ -0,0 +1,47 @@
/**
*
*/
#include <RTSResult.h>
#include <GILLock.h>
RTSResult::RTSResult(std::string resCode) : mResCode(resCode)
{
}
RTSResult::~RTSResult()
{}
std::string RTSResult::getResCode(){
return mResCode;
}
boost::python::dict const& RTSResult::getProperties() {
return mProp;
}
// void RTSPyLogging::log(std::string msg, PyObject* f){
// // GIL state handler
// PyLockGIL gstate;
// // Python callback
// call_method<void>(f, "log", msg);
// // GIL handler release
// }
// BOOST_PYTHON_MODULE(RTSResult)
// {
// class_<RTSResult>("RTSResult", init<std::string>())
// .def("getResCode", &RTSResult::getResCode)
// .def("getProperties", &RTSResult::getProperties, return_value_policy<copy_const_reference>())
// ;
// }

View File

@@ -0,0 +1,41 @@
/*
*/
#include <string>
#include <list>
#include <VibChannelDesc.h>
VibChannelDesc::VibChannelDesc(u_int32_t id, const std::string& name, VALUEFORMAT valueFormat, u_int32_t vByteSpace){
this->id = id;
this->name = name;
this->valueFormat = valueFormat;
this->vByteSpace = vByteSpace;
}
u_int32_t VibChannelDesc::GetId(){
return this->id;
}
const std::string& VibChannelDesc::GetName(){
return this->name;
}
VALUEFORMAT VibChannelDesc::GetValueFormat(){
return this->valueFormat;
}
/**
* return the length of the data that is neeeded for one value of the channel in UINT32
*
*/
u_int32_t VibChannelDesc::GetValueByteSpace(){
return this->vByteSpace;
}

View File

@@ -0,0 +1,199 @@
/*
*/
#include <VibSensorDesc.h>
#include <string>
#include <list>
#include <VibChannelDesc.h>
static const std::string RTSMONERROR("error");
static const std::string RTSMONNAME("name");
static const std::string RTSMONUINT("UINT32");
static const std::string RTSMONINT("INT32");
static const std::string RTSMONFLOAT("FLOAT");
static const std::string RTSMONDOUBLE("DOUBLE");
VibSensorDesc::VibSensorDesc(const std::string& name){
//Init Vibrationsensor
this->name = name;
//u_int32_t id, const std::string& name, VALUEFORMAT valueFormat, u_int32_t vByteSpace = 1)
std::shared_ptr<IChannelDesc> channelDesc = std::make_shared<VibChannelDesc>(1, "vibration1", VALUEFORMAT::UINT32, 1);
this->mDescriptions.push_back(channelDesc);
channelDesc = std::make_shared<VibChannelDesc>(2, "vibration2", VALUEFORMAT::UINT32, 1);
this->mDescriptions.push_back(channelDesc);
channelDesc = std::make_shared<VibChannelDesc>(3, "vibration3", VALUEFORMAT::UINT32, 1);
this->mDescriptions.push_back(channelDesc);
}
int VibSensorDesc::GetDescription(){
return 0;
}
bool VibSensorDesc::AddHW2Json(json& j){
json jsensor = json::object();
jsensor[RTSMONNAME] = this->name;
if (this->mDescriptions.empty()) {
printf("CA7 : Error empty channel description name:%s.\n", this->name.c_str());
j[RTSMONERROR] = "Error empty channel description";
return false;
}
json jchannels = json::array();
for (auto &&chanDesc : this->mDescriptions)
{
json jchannel = json::object();
jchannel[RTSMONCHANNELNAME] = chanDesc->GetName();
switch (chanDesc->GetValueFormat())
{
case VALUEFORMAT::UINT32:
jchannel[RTSMONCHANNELVALUETYPE] = RTSMONUINT;
break;
case VALUEFORMAT::INT32:
jchannel[RTSMONCHANNELVALUETYPE] = RTSMONINT;
break;
case VALUEFORMAT::FLOAT:
jchannel[RTSMONCHANNELVALUETYPE] = RTSMONFLOAT;
break;
case VALUEFORMAT::DOUBLE:
jchannel[RTSMONCHANNELVALUETYPE] = RTSMONDOUBLE;
break;
default:
break;
}
jchannels.push_back(jchannel);
}
jsensor[RTSMONCHANNELS] = jchannels;
j.push_back(jsensor);
return true;
}
u_int32_t VibSensorDesc::AddValues2Json(json& j, u_int32_t* values, u_int32_t actno, u_int32_t length){
//sensor Object
json jsensor = json::object();
u_int32_t result = actno;
if (actno <= length) {
//iterate over the channels
rtsSensorValue value;
if (this->mDescriptions.empty()) {
printf("CA7 : Error empty channel description - actno[%d].\n", actno);
j[RTSMONERROR] = "Error empty channel description";
return length;
}
//json jchannels = json::array();
for (auto &&chanDesc : this->mDescriptions)
{
value.vUINT32 = values[result];
result = result +1;
//json jchannel = json::object();
switch (chanDesc->GetValueFormat())
{
case VALUEFORMAT::UINT32:
//j[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vUINT32);
j.push_back(json::number_unsigned_t(value.vUINT32));
break;
case VALUEFORMAT::INT32:
//j[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vINT32);
j.push_back(json::number_unsigned_t(value.vINT32));
break;
case VALUEFORMAT::FLOAT:
//j[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vFLOAT);
j.push_back(json::number_unsigned_t(value.vFLOAT));
break;
case VALUEFORMAT::DOUBLE:
//j[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vDOUBLE);
j.push_back(json::number_unsigned_t(value.vDOUBLE));
break;
default:
break;
}
//jchannels.push_back(jchannel);
}
//jsensor[RTSMONCHANNELS] = jchannels;
//j.push_back(jsensor);
}
//printf("CA7 : add2json-1 return actno %d.\n", actno);
return result;
}
/*
json jsensor = json::object();
jsensor[RTSMONNAME] = this->name;
u_int32_t result = actno;
if (actno <= length) {
//iterate over the channels
rtsSensorValue value;
if (this->mDescriptions.empty()) {
printf("CA7 : Error empty channel description - actno[%d].\n", actno);
j[RTSMONERROR] = "Error empty channel description";
return length;
}
json jchannels = json::array();
for (auto &&chanDesc : this->mDescriptions)
{
value.vUINT32 = values[result];
result = result +1;
//printf("CA7 : add2json-1 actno %d.\n", actno);
json jchannel = json::object();
switch (chanDesc->GetValueFormat())
{
case VALUEFORMAT::UINT32:
// j[chanDesc->GetName()] = json::number_unsigned_t(value.vUINT32);
jchannel[RTSMONCHANNELNAME] = chanDesc->GetName();
jchannel[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vUINT32);
break;
case VALUEFORMAT::INT32:
//j[chanDesc->GetName()] = json::number_integer_t(value.vINT32);
jchannel[RTSMONCHANNELNAME] = chanDesc->GetName();
jchannel[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vINT32);
break;
case VALUEFORMAT::FLOAT:
//j[chanDesc->GetName()] = json::number_float_t(value.vFLOAT);
jchannel[RTSMONCHANNELNAME] = chanDesc->GetName();
jchannel[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vFLOAT);
break;
case VALUEFORMAT::DOUBLE:
//j[chanDesc->GetName()] = json::number_float_t(value.vDOUBLE);
jchannel[RTSMONCHANNELNAME] = chanDesc->GetName();
jchannel[RTSMONCHANNELVALUE] = json::number_unsigned_t(value.vDOUBLE);
break;
default:
break;
}
jchannels.push_back(jchannel);
}
jsensor[RTSMONCHANNELS] = jchannels;
j.push_back(jsensor);
}
//printf("CA7 : add2json-1 return actno %d.\n", actno);
return result;
*/

View File

@@ -0,0 +1,193 @@
#include <boost/python.hpp>
#include <boost/python/manage_new_object.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/return_value_policy.hpp>
#include <boost/python/extract.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <string>
#include <RTSMonitoringTask.h>
//#include <RTSResult.h>
#include <RTSErrResult.h>
#include <RelGILLock.h>
#include <GILLock.h>
struct RTService
{
private:
/* data */
//RTSMonitoringTask rtsMonTask;
RTSCoproHelper rtsCopro;
public:
// RT_Service(/* args */) {
// }
// ~RT_Service() {}
bool isCoproRunning(){
PyRelinquishGIL scoped;
return rtsCopro.Copro_isFwRunning();
}
bool initCoproFW(std::string fwPath, std::string fwName){
PyRelinquishGIL scoped;
return rtsCopro.Init(fwPath, fwName);
}
// bool initLogChannel(){
// PyRelinquishGIL scoped;
// return rtsCopro.Copro_initLogChannel();
// }
// bool openLogChannel(){
// PyRelinquishGIL scoped;
// return rtsCopro.Copro_initLogChannel();
// }
// bool writeLogChannel(){
// PyRelinquishGIL scoped;
// return rtsCopro.Copro_writeLogChannel();
// }
// std::string readLogChannel(){
// PyRelinquishGIL scoped;
// return rtsCopro.Copro_readLogChannel();
// }
// bool closeLogChannel(){
// PyRelinquishGIL scoped;
// return rtsCopro.Copro_closeLogChannel();
// }
// int openDataChannel(std::string monfilename){
// PyRelinquishGIL scoped;
// return rtsMonTask.Open(monfilename);
// }
// std::string readDataChannel(int fileDesc){
// PyRelinquishGIL scoped;
// return rtsMonTask.Read(fileDesc);
// }
// bool closeDataChannel(int fileDesc){
// PyRelinquishGIL scoped;
// return rtsMonTask.Close(fileDesc);
// }
boost::python::list getMonitoringStates() {
//TODO ask the M4Core for the Monitpring Status
PyRelinquishGIL scoped;
boost::python::list list;
return list;
}
// we need all parameters like id, samplerate, sampletime, downtime, later: HW-channels with the configurations
// bool startMonitoring(int samplerate, int sampleperiod, int downtime, std::string status) {
// PyRelinquishGIL scoped;
// //TODO ML: add this to the M4Core
// // if (rtsMonTask.Init()) {
// return rtsMonTask.Start(samplerate, sampleperiod, downtime);
// // }
// // return false;
// }
// we need all parameters like id, samplerate, sampletime, downtime, later: HW-channels with the configurations
// bool stopMonitoring(std::string id) {
// PyRelinquishGIL scoped;
// //TODO ML: add this to the M4Core
// // if (rtsMonTask.Init()) {
// return rtsMonTask.Stop(id);
// // }
// // return false;
// }
};
using namespace boost::python;
BOOST_PYTHON_MODULE(rt_service)
{
namespace python = boost::python;
// python::class_<RTSMonScript, boost::noncopyable>("RTSMonitoring", python::no_init)
// .add_property("id", &RTSMonitoring::GetId, &RTSMonitoring::SetId)
// .add_property("samplerate", &RTSMonitoring::GetSampleRate, &RTSMonitoring::SetId)
// .add_property("samplePeriod", &RTSMonitoring::GetSamplePeriod, &RTSMonitoring::SetId)
// .add_property("downtime", &RTSMonitoring::GetDownTime, &RTSMonitoring::SetId)
// .def("add2Script", pure_virtual(&RTSMonitoring::add2Script))
// ;
// class_<std::vector<RTSMonitoring*>>("RTSMonitoringList")
// .def(vector_indexing_suite<std::vector<RTSMonitoring*>>())
// ;
// def("add2Script", +[](RTSMonitoring* object) {
// return object->add2Script();
// });
//, python::init<PyObject*>()
class_<RTSMonitoringTask, boost::noncopyable>("RTSMonitoringTask", init<std::string, std::string, int, int, int, std::string>())
// .add_property("id", &RTSMonitoringTask::GetId, &RTSMonitoringTask::SetId)
// .add_property("samplerate", &RTSMonitoringTask::GetRate, &RTSMonitoringTask::SetRate)
// .add_property("samplePeriod", &RTSMonitoringTask::GetPeriod, &RTSMonitoringTask::SetPeriod)
// .add_property("downtime", &RTSMonitoringTask::GetDowntime, &RTSMonitoringTask::SetDowntime)
// .add_property("path", &RTSMonitoringTask::GetPath, &RTSMonitoringTask::SetPath)
.def("start", &RTSMonitoringTask::Start)
.def("stop", &RTSMonitoringTask::Stop)
.def_readonly("id", &RTSMonitoringTask::id)
.def_readonly("name", &RTSMonitoringTask::monName)
.def_readonly("samplerate", &RTSMonitoringTask::samplerate)
.def_readonly("sampleperiod", &RTSMonitoringTask::sampleperiod)
.def_readonly("downtime", &RTSMonitoringTask::downtime)
.def_readonly("path", &RTSMonitoringTask::path)
// .def("openChannel", &RTSMonitoringTask::Open) //, return_value_policy<manage_new_object>())
// .def("readChannel", &RTSMonitoringTask::Read)
// .def("closeChannel", &RTSMonitoringTask::Close)
// .def("getLogMsg", &RTSMonitoringTask::GetLogMsg) //, return_value_policy<manage_new_object>())
// .def("getExtError", &RTSMonitoringTask::GetExtError, return_value_policy<manage_new_object>())
;
class_<RTService>("RT_Service")
.def("isCoproRunning", &RTService::isCoproRunning)
.def("initCoproFW", &RTService::initCoproFW)
// .def("initLogChannel", &RTService::initLogChannel)
// .def("readLogChannel", &RTService::readLogChannel)
.def("getAllMonitoringStat", &RTService::getMonitoringStates)
// .def("startMonitoring", &RTService::startMonitoring)
// .def("stopMonitoring", &RTService::stopMonitoring)
// .def("openDataChannel", &RTService::openDataChannel)
// .def("readDataChannel", &RTService::readDataChannel)
// .def("closeDataChannel", &RTService::closeDataChannel)
;
class_<RTSResult>("RTSResult")
.def("getResCode", &RTSResult::getResCode)
.def("getMsg", &RTSResult::getMsg)
// .def("getProps", &RTSResult::getProps , return_value_policy<copy_const_reference>())
;
// class_<RTSResult, boost::noncopyable>("RTSResult", init<std::string>())
// .def("getResCode", &RTSResult::getResCode)
// .def("getProperties", &RTSResult::getProperties, return_value_policy<copy_const_reference>())
// ;
};
/**
* startmonitoring()
* stopmonitoring(id)
.def("createMonitoring", &RTService::createMonitoring)
.def("setMonitoringStatus", &RTService::setMonitoringStatus)
.def("getMonitoringStatus", &RTService::getMonitoringState)
*/

View File

@@ -0,0 +1,14 @@
#include <GILLock.h>
//Use this class in a c++ funktion that called into python : c++ => python
PyLockGIL::PyLockGIL()
: m_gstate(PyGILState_Ensure()) {
}
PyLockGIL::~PyLockGIL() {
PyGILState_Release(m_gstate);
}

View File

@@ -0,0 +1,430 @@
/*
*/
#include "../../include/RTSCoproHelper.h"
#include <signal.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <termios.h>
#include <fcntl.h>
#include <inttypes.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h> // for usleep
#include <math.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/eventfd.h>
#include <sys/poll.h>
#include <regex.h>
#include <sched.h>
#include <assert.h>
#include <errno.h>
#include <error.h>
#define MAX_BUF 80
#define TTY_CTRL_OPTS (CS8 | CLOCAL | CREAD)
#define TTY_INPUT_OPTS IGNPAR
#define TTY_OUTPUT_OPTS 0
#define TTY_LOCAL_OPTS 0
#define CMDCHANNEL 0
#define DATACHANNEL 1
RTSCoproHelper::RTSCoproHelper(/* args */)
{
}
RTSCoproHelper::~RTSCoproHelper()
{
}
int RTSCoproHelper::Init(std::string fwPath, std::string fwName) {
int res = -1;
if (this->Copro_isFwRunning() != 0){
//copro is already Runnibng nothing TODO
//res = this->Copro_openTtyRpmsg(CMDCHANNEL, 0);
//this->Copro_stopFw();
//return res;
return 0;
}
//load Firmware
//set firmware path
res = this->Copro_setFwPath(fwPath.c_str());
if (res >= 0) {
printf("CA7 : Success setting the fwpath, res=%d\n", res);
res = this->Copro_setFwName(fwName.c_str());
if (res >= 0) {
printf("CA7 : Success setting the fwname, res=%d\n", res);
res = this->Copro_startFw();
if (res >= 0) {
printf("CA7 : Success starting Copro, err=%d\n", res);
}
else {
printf("CA7 : Error could not start the firmware, res=-%d\n", res);
}
}
else {
printf("CA7 : Error setting the fwName, err=-%d\n", res);
}
}
else {
printf("CA7 : Error setting the fwpath, err=-%d\n", res);
}
return res;
}
// bool RTSCoproHelper::Copro_initLogChannel(){
// int res = this->Copro_openTtyRpmsg(LOGCHANNEL, 1);
// if (res >= 0 ){
// printf("CA7 : Success opening Logchannel, err=%d\n", res);
// const char* firstCMD = "Test";
// res = this->Copro_writeTtyRpmsg(LOGCHANNEL, strlen(firstCMD), firstCMD);
// if (res >= 0 ){
// printf("CA7 : Success sending data to Logchannel, err=%d\n", res);
// res = 0;
// }
// else {
// printf("CA7 : Error sending to logchannel, err=%d\n", res);
// }
// }
// else {
// printf("CA7 : Error opening logchannel, err=%d\n", res);
// }
// return (res >=0);
// }
// bool RTSCoproHelper::Copro_closeLogChannel(){
// int res = this->Copro_closeTtyRpmsg(LOGCHANNEL);
// if (res >= 0 ){
// printf("CA7 : Success opening Logchannel, err=%d\n", res);
// const char* firstCMD = "Test";
// res = this->Copro_writeTtyRpmsg(LOGCHANNEL, strlen(firstCMD), firstCMD);
// if (res >= 0 ){
// printf("CA7 : Success sending data to Logchannel, err=%d\n", res);
// res = 0;
// }
// else {
// printf("CA7 : Error sending to logchannel, err=%d\n", res);
// }
// }
// else {
// printf("CA7 : Error opening logchannel, err=%d\n", res);
// }
// return (res >=0);
// }
/**
* read1 = copro_readTtyRpmsg(1, 512, mRxTraceBuffer);
mRxTraceBuffer[read1] = 0; // to be sure to get a end of string
if (read1 > 0) {
if (strcmp(mRxTraceBuffer, "CM4 : DMA TransferError") == 0) {
// sampling is aborted, refresh the UI
mErrorDetected = 1;
//mMachineState = STATE_READY;
//gdk_threads_add_idle (refreshUI_CB, window);
}
gettimeofday(&tval_after, NULL);
timersub(&tval_after, &tval_before, &tval_result);
if (mRxTraceBuffer[0] == 'C') {
printf("[%ld.%06ld] : %s\n",
(long int)tval_result.tv_sec, (long int)tval_result.tv_usec,
mRxTraceBuffer);
} else {
printf("[%ld.%06ld] : CA7 : tty1 got %d [%x] bytes\n",
(long int)tval_result.tv_sec, (long int)tval_result.tv_usec,
read1, mRxTraceBuffer[0]);
}
}
*/
// std::string RTSCoproHelper::Copro_readLogChannel(){
// char mRxTraceBuffer[513];
// int res = this->Copro_readTtyRpmsg(LOGCHANNEL, 512, mRxTraceBuffer);
// struct timeval tval_before, tval_after, tval_result;
// gettimeofday(&tval_after, NULL);
// timersub(&tval_after, &tval_before, &tval_result);
// if (res > 0 ){
// mRxTraceBuffer[res] = 0;
// printf("CA7 : Success receiving data to Logchannel, err=%d\n", res);
// printf("[%ld.%06ld] : %s\n",(long int)tval_result.tv_sec, (long int)tval_result.tv_usec, mRxTraceBuffer);
// return std::string(mRxTraceBuffer);
// }
// const char* errMsg = "noResult";
// printf("CA7 : Error sending to logchannel, err=%d\n", res);
// return std::string("Error no Result");
// }
/********************************************************************************
Copro functions allowing to manage a virtual TTY over RPMSG
*********************************************************************************/
int RTSCoproHelper::Copro_isFwRunning(void)
{
int fd;
size_t byte_read;
bool result = 0;
unsigned char bufRead[MAX_BUF];
// char *user = getenv("USER");
// if (user && strncmp(user, "root", 4)) {
// system("XTERM=xterm su root -c 'cat /sys/class/remoteproc/remoteproc0/state' > /tmp/remoteproc0_state");
// fd = open("/tmp/remoteproc0_state", O_RDONLY);
// } else {
fd = open("/sys/class/remoteproc/remoteproc0/state", O_RDONLY);
// }
if (fd < 0) {
printf("CA7 : Error opening remoteproc0/state, err=-%d\n", errno);
return (errno * -1);
}
byte_read = (size_t) read (fd, bufRead, MAX_BUF);
if (byte_read >= strlen("running")) {
char* pos = strstr((char*)bufRead, "running");
if(pos) {
result = 1;
}
}
close(fd);
return result;
}
int RTSCoproHelper::Copro_stopFw(void)
{
int fd;
// char *user = getenv("USER");
// if (user && strncmp(user, "root",4)) {
// system("su root -c 'echo stop > /sys/class/remoteproc/remoteproc0/state'");
// return 0;
// }
fd = open("/sys/class/remoteproc/remoteproc0/state", O_RDWR);
if (fd < 0) {
printf("CA7 : Error opening remoteproc0/state, err=-%d\n", errno);
return (errno * -1);
}
write(fd, "stop", strlen("stop"));
close(fd);
return 0;
}
int RTSCoproHelper::Copro_startFw(void)
{
int fd;
// char *user = getenv("USER");
// if (user && strncmp(user, "root",4)) {
// system("su root -c 'echo start > /sys/class/remoteproc/remoteproc0/state'");
// return 0;
// }
fd = open("/sys/class/remoteproc/remoteproc0/state", O_RDWR);
if (fd < 0) {
printf("CA7 : Error opening remoteproc0/state, err=-%d\n", errno);
return (errno * -1);
}
write(fd, "start", strlen("start"));
close(fd);
return 0;
}
int RTSCoproHelper::Copro_getFwPath(char* pathStr)
{
int fd;
int byte_read;
// char *user = getenv("USER");
// if (user && strncmp(user, "root",4)) {
// system("XTERM=xterm su root -c 'cat /sys/module/firmware_class/parameters/path' > /tmp/parameters_path");
// fd = open("/tmp/parameters_path", O_RDONLY);
// } else {
fd = open("/sys/module/firmware_class/parameters/path", O_RDONLY);
// }
if (fd < 0) {
printf("CA7 : Error opening firmware_class/parameters/path, err=-%d\n", errno);
return (errno * -1);
}
byte_read = read (fd, pathStr, MAX_BUF);
close(fd);
return byte_read;
}
int RTSCoproHelper::Copro_setFwPath(const char* pathStr)
{
int fd;
int result = 0;
// char *user = getenv("USER");
// if (user && strncmp(user, "root",4)) {
// char cmd[1024];
// snprintf(cmd, 1024, "echo %s > /sys/module/firmware_class/parameters/path", pathStr);
// //snprintf(cmd, 1024, "su root -c 'echo %s > /sys/module/firmware_class/parameters/path'", pathStr);
// system(cmd);
// return strlen(pathStr);
// }
fd = open("/sys/module/firmware_class/parameters/path", O_RDWR);
if (fd < 0) {
printf("CA7 : Error opening firmware_class/parameters/path, err=-%d\n", errno);
return (errno * -1);
}
result = write(fd, pathStr, strlen(pathStr));
close(fd);
return result;
}
int RTSCoproHelper::Copro_getFwName(char* pathStr)
{
int fd;
int byte_read;
// char *user = getenv("USER");
// if (user && strncmp(user, "root",4)) {
// system("XTERM=xterm su root -c 'cat /sys/class/remoteproc/remoteproc0/firmware' > /tmp/remoteproc0_firmware");
// fd = open("/tmp/remoteproc0_firmware", O_RDONLY);
// } else {
fd = open("/sys/class/remoteproc/remoteproc0/firmware", O_RDWR);
// }
if (fd < 0) {
printf("CA7 : Error opening remoteproc0/firmware, err=-%d\n", errno);
return (errno * -1);
}
byte_read = read (fd, pathStr, MAX_BUF);
close(fd);
return byte_read;
}
int RTSCoproHelper::Copro_setFwName(const char* nameStr)
{
int fd;
int result = 0;
// char *user = getenv("USER");
// if (user && strncmp(user, "root",4)) {
// char cmd[1024];
// snprintf(cmd, 1024, "su root -c 'echo %s > /sys/class/remoteproc/remoteproc0/firmware'", nameStr);
// system(cmd);
// return strlen(nameStr);
// }
fd = open("/sys/class/remoteproc/remoteproc0/firmware", O_RDWR);
if (fd < 0) {
printf("CA7 : Error opening remoteproc0/firmware, err=-%d\n", errno);
return (errno * -1);
}
result = write(fd, nameStr, strlen(nameStr));
close(fd);
return result;
}
int RTSCoproHelper::Copro_openTtyRpmsg(int ttyNb, [[maybe_unused]]int modeRaw)
{
//struct termios tiorpmsg;
char devName[50];
sprintf(devName, "/dev/ttyRPMSG%d", ttyNb%2);
mFdRpmsg[ttyNb%2] = open(devName, O_RDWR | O_NOCTTY | O_NONBLOCK);
// mFdRpmsg[ttyNb%2] = open("rpmsg-client-sample", O_RDWR | O_NOCTTY | O_NONBLOCK);
if (mFdRpmsg[ttyNb%2] < 0) {
printf("CA7 : Error opening ttyRPMSG%d, err=-%d\n", ttyNb%2, errno);
return (errno * -1);
}
printf("CA7 : Success opening ttyRPMSG%d \n", ttyNb%2);
// #if 1
// /* get current port settings */
// tcgetattr(mFdRpmsg[ttyNb%2],&tiorpmsg);
// if (modeRaw) {
// #if 0
// tiorpmsg.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
// | INLCR | IGNCR | ICRNL | IXON);
// tiorpmsg.c_oflag &= ~OPOST;
// tiorpmsg.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
// tiorpmsg.c_cflag &= ~(CSIZE | PARENB);
// tiorpmsg.c_cflag |= CS8;
// #else
// memset(&tiorpmsg, 0, sizeof(tiorpmsg));
// tiorpmsg.c_cflag = TTY_CTRL_OPTS;
// tiorpmsg.c_iflag = TTY_INPUT_OPTS;
// tiorpmsg.c_oflag = TTY_OUTPUT_OPTS;
// tiorpmsg.c_lflag = TTY_LOCAL_OPTS;
// tiorpmsg.c_cc[VTIME] = 0;
// tiorpmsg.c_cc[VMIN] = 1;
// cfmakeraw(&tiorpmsg);
// #endif
// } else {
// /* ECHO off, other bits unchanged */
// tiorpmsg.c_lflag &= ~ECHO;
// /*do not convert LF to CR LF */
// tiorpmsg.c_oflag &= ~ONLCR;
// }
// if (tcsetattr(mFdRpmsg[ttyNb%2], TCSANOW, &tiorpmsg) < 0) {
// printf("Error %d in copro_openTtyRpmsg(%d) tcsetattr\n", errno, ttyNb);
// return (errno * -1);
// }
// #endif
return 0;
}
int RTSCoproHelper::Copro_closeTtyRpmsg(int ttyNb)
{
close(mFdRpmsg[ttyNb%2]);
mFdRpmsg[ttyNb%2] = -1;
return 0;
}
int RTSCoproHelper::Copro_writeTtyRpmsg(int ttyNb, int len, char* pData)
{
int result = 0;
if (mFdRpmsg[ttyNb%2] < 0) {
printf("CA7 : Error writing ttyRPMSG%d, fileDescriptor is not set\n", ttyNb%2);
return mFdRpmsg[ttyNb%2];
}
result = write(mFdRpmsg[ttyNb%2], pData, len);
if (result >= 0) {
printf("CA7 : Succes writing ttyRPMSG%d, result=%d\n", ttyNb%2, result);
}
else {
printf("CA7 : Error writing ttyRPMSG%d, err=-%d\n", ttyNb%2, result);
}
return result;
}
int RTSCoproHelper::Copro_readTtyRpmsg(int ttyNb, int len, char* pData)
{
int byte_rd, byte_avail;
int result = 0;
if (mFdRpmsg[ttyNb%2] < 0) {
printf("CA7 : Error reading ttyRPMSG%d, fileDescriptor is not set\n", ttyNb%2);
return mFdRpmsg[ttyNb%2];
}
ioctl(mFdRpmsg[ttyNb%2], FIONREAD, &byte_avail);
if (byte_avail > 0) {
if (byte_avail >= len) {
byte_rd = read (mFdRpmsg[ttyNb%2], pData, len);
} else {
byte_rd = read (mFdRpmsg[ttyNb%2], pData, byte_avail);
}
//printf("CA7 : read successfully %d bytes to %p, [0]=0x%x\n", byte_rd, pData, pData[0]);
result = byte_rd;
} else {
result = 0;
}
return result;
}
/********************************************************************************
End of Copro functions
*********************************************************************************/

View File

@@ -0,0 +1,36 @@
/**
*
*/
#include <RTSPyLogging.h>
#include <GILLock.h>
//RTSPyLogging::RTSPyLogging(PyObject* pPyLogging): mplogging(pPyLogging)
RTSPyLogging::RTSPyLogging()
{}
RTSPyLogging::~RTSPyLogging()
{}
void RTSPyLogging::log(std::string msg, PyObject* f){
// GIL state handler
PyLockGIL gstate;
// Python callback
call_method<void>(f, "log", msg);
// GIL handler release
}
std::string RTSPyLogging::format(const std::string fmt_str, ...)
{
va_list ap;
char *fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
std::unique_ptr<char[]> formatted(fp);
return std::string(formatted.get());
}

View File

@@ -0,0 +1,16 @@
#include <RelGILLock.h>
//Use this class in a c++ funktion that is called from python : python => c++
PyRelinquishGIL::PyRelinquishGIL()
: m_thread_state(PyEval_SaveThread()) {
}
PyRelinquishGIL::~PyRelinquishGIL() {
PyEval_RestoreThread(m_thread_state);
m_thread_state= NULL;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

View File

@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Markus Lehr | VR Predictive Maintenance Device."
/>
<meta
data-rh="true"
property="og:image"
content="https://refine.dev/img/refine_social.png"
/>
<meta
data-rh="true"
name="twitter:image"
content="https://refine.dev/img/refine_social.png"
/>
<title>
Markus Lehr | VR Predictive Maintenance Device.
</title>
<script type="module" crossorigin src="/assets/index-952960a4.js"></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm dev` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

View File

@@ -0,0 +1,11 @@
class VRPMDV_CreateMonCmd:
def __init__(self, samplerate, sampleperiod, downtime) :
self.cmdid = 1
self.samplerate = samplerate
self.sampleperiod = sampleperiod
self.downtime = downtime

View File

@@ -0,0 +1,50 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, post_dump
from vrpmdvcreatemoncmd import VRPMDV_CreateMonCmd
# class VRPMDV_CreateMonSchema(Schema):
# cmdid = fields.Integer()
# id = fields.UUID()
# samplerate = fields.Integer()
# sampleperiod = fields.Integer()
# downtime = fields.Integer()
# status = fields.String()
# #monstate = fields.Enum(VRPMDVMonitoringState)
# # def get_envelope_key(self, many):
# # """Helper to get the envelope key."""
# # key = self.__envelope__["many"] if many else self.__envelope__["single"]
# # assert key is not None, "Envelope key undefined"
# # return key
# # @post_dump(pass_many=True)
# # def wrap_with_envelope(self, data, many, **kwargs):
# # key = self.get_envelope_key(many)
# # return {key: data}
# @post_load
# def make_vrpmdv_Monitoring(self, data, **kwargs):
# mon = VRPMDV_Monitoring(**data)
# return mon
class VRPMDV_CreateMonSchema(Schema):
cmdid = fields.Integer()
samplerate = fields.Integer()
sampleperiod = fields.Integer()
downtime = fields.Integer()
@post_load
def make_vrpmdv_CreateMonitoring(self, data, **kwargs):
mon = VRPMDV_CreateMonCmd(**data)
return mon

View File

@@ -0,0 +1,485 @@
import os
import time
from uuid import uuid4
import uuid
from flask import jsonify
import json
from marshmallow import EXCLUDE, ValidationError
#from vrpmdvcreatemoncmd import VRPMDV_CreateMonCmd
#from vrpmdvcreatemonschema import VRPMDV_CreateMonSchema
#from vrpmdvdeletemoncmd import VRPMDV_DeleteMonCmd
#from vrpmdvdeletemonschema import VRPMDV_DeleteMonSchema
from vrpmdvmonfilescompleteschema import VRPMDV_MonfilesCompleteSchema
from vrpmdvmonfilter import VRPMDV_MonFilter
from vrpmdvmonfilterschema import VRPMDV_MonFilterSchema
from vrpmdvmonsensorschema import VRPMDV_MonSensorSchema
from vrpmdvmonchannelschema import VRPMDV_MonChannelSchema
from vrpmdvmonfilesschema import VRPMDV_MonfilesSchema
from vrpmdvmonitoring import VRPMDV_Monitoring
from vrpmdvmonitoringschema import VRPMDV_MonitoringSchema
from vrpmdvmonreqschema import VRPMDV_MonReqSchema
# from vrpmdvntlink import trySend
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState
#from vrpmdvlogging import createCoproLoggingTask
import logging
class VRPMDV_Data:
def __init__(self):
#self.loaded = False
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
self.mons:list = []
#TODO ML: uncomment this lines
self.rtservice = rts.RT_Service()
if (self.rtservice != None):
logging.info("init: initCoproFW")
self.rtservice.initCoproFW("home/root/elffile","zephyr_openamp_rsc_table.elf")
self.logTask = None #createCoproLoggingTask()
self.loaded = self.loadFile()
self.monfilespath = '/home/root/monfiles/'
#start the monitorings
time.sleep(1)
self.startMons();
def loadFile(self):
try:
with open('./mons.json', 'r') as f:
fmons = f.read()
if not fmons:
# return no Item
return True
else:
# data = json.loads(fmons)
schema = VRPMDV_MonitoringSchema(many=True)
#res = schema.loads(fmons) # data
self.mons = schema.loads(fmons) # .append(res)
return True
except:
#nothing todo ML we should create a file later the database
print("file not found")
def saveFile(self):
try:
with open('./mons.json', 'w') as f:
schema = VRPMDV_MonitoringSchema()
result = schema.dumps(self.mons, many=True)
f.write(result)
return True
except:
#nothing todo
print("could not write file")
def startMons(self):
try:
logging.info("MainThread: startMons")
# for i, val in enumerate(self.mons):
# if (val.status == 'started') :
# val.startMonitoring()
except:
print("could not start monitorings")
def findMon(mon):
return mon
def getMonitorings(self):
# 1st time read file
# if not self.loaded :
# self.loaded = self.loadFile()
schema = VRPMDV_MonitoringSchema()
result = schema.dumps(self.mons, many=True)
return result
def getMonitoring(self, vrpmid):
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
except:
return "no Item found"
# we find it and we return it
schema = VRPMDV_MonitoringSchema()
return schema.dumps(matched_obj)
def setMonitoring(self, id, request):
try:
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 :
if (request['status'] == 'started'):
if (matched_obj.status == VRPMDVMonitoringState.STOPPED):
logging.info("MainThread: started %s", matched_obj.id)
matched_obj.startMonitoring()
# matched_obj.setStatus(self.createMonOnDevice(matched_obj))
elif (matched_obj.status == 'started') :
logging.info("MainThread: stopped %s", matched_obj.id)
# matched_obj.setStatus(self._stopMonitoring(matched_obj))
matched_obj.stopMonitoring()
self.saveFile()
# we find it and we return it
schema = VRPMDV_MonitoringSchema()
return schema.dumps(matched_obj)
def createMonitoring(self, request):
id = uuid.uuid4()
createjson = request.get_json()
vrpmreq = VRPMDV_MonReqSchema().load(createjson)
mon = VRPMDV_Monitoring(0, id, vrpmreq.name, vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status, vrpmreq.owner)
logging.info("Monitoring %s: creating", str(id))
# create Monitoring on the realtime side
if (vrpmreq.status == 'started'):
logging.info("Monitoring %s: createMonOnDevice", str(id))
mon.startMonitoring()
# status = self.createMonOnDevice(mon)
# logging.info("Monitoring %s: _start executed. status:%s", str(id), str(status))
# mon.status = status
self.mons.append(mon)
#save to file
self.saveFile()
#create result Object in json
schema = VRPMDV_MonitoringSchema()
return schema.dumps(mon)
def deleteMonitoring(self, vrpmid):
# if not self.loaded :
# self.loaded = self.loadFile()
# find monitoring with uuid
#result = filter(lambda mon: str(mon.uuid) == vrpmid["uuid"], self.mons)
try:
matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
except:
return "no Item found"
# we find it, delete on realtime side and now remove from list
matched_obj.stopMonitoring()
self.mons.remove(matched_obj)
#save the list
self.saveFile()
#make result
schema = VRPMDV_MonitoringSchema()
return schema.dump(matched_obj)
# internal helper function
# ML: transfer to Monitoring class
# def createMonOnDevice(self, monitoring):
# #call the start API of the c++ driver
# try:
# logging.info("MainThread: createMonOnDevice => before vrpmdCreateCmd samplerate:%d, samplerate:%d, samplerate:%d", monitoring.samplerate, monitoring.sampleperiod, monitoring.downtime)
# vrpmdCreateCmd = VRPMDV_CreateMonCmd(monitoring.samplerate, monitoring.sampleperiod, monitoring.downtime)
# logging.info("MainThread: createMonOnDevice => before schemaCreateCmd")
# schemaCreateCmd = VRPMDV_CreateMonSchema()
# logging.info("MainThread: try send start monitoring starting %s", schemaCreateCmd.dumps(vrpmdCreateCmd))
# #res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
# #logging.info("MainThread: try send start monitoring done %s", res)
# self.status = "started"
# # set status if we have a success TODO
# except:
# self.status = "stopped"
# return "stopped"
# return "started"
# def _stopMonitoring(self, monitoring):
# #call the stop API of the c++ driver
# try:
# logging.info("MainThread: stop monitoring")
# vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(2, monitoring.id)
# schemaDeleteCmd = VRPMDV_DeleteMonSchema()
# #trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
# self.status = "stopped"
# logging.info("MainThread: stop monitoring done")
# except:
# self.status = "started"
# return "started"
# return monitoring.status
# old impl ML
#
# def createMonitoring(self, request):
# id = uuid.uuid4()
# createjson = request.get_json()
# vrpmreq = VRPMDV_MonReqSchema().load(createjson)
# vrpmdCreateCmd = VRPMDV_CreateMonCmd(1, id , vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status)
# schemaCreateCmd = VRPMDV_CreateMonSchema()
# valstr = schemaCreateCmd.dumps(vrpmdCreateCmd)
# trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
# mon = VRPMDV_Monitoring(id, vrpmreq.name, vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status, vrpmreq.owner)
# logging.info("Monitoring %s: starting", str(id))
# mon.startMonitoring()
# self.mons.append(mon)
# #save to file
# self.saveFile()
# #create result Object in json
# schema = VRPMDV_MonitoringSchema()
# return schema.dumps(mon)
# def createMonitoring(self, request):
# id = uuid.uuid4()
# createjson = request.get_json()
# vrpmreq = VRPMDV_MonReqSchema().load(createjson)
# vrpmdCreateCmd = VRPMDV_CreateMonCmd(1, id , vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status)
# schemaCreateCmd = VRPMDV_CreateMonSchema()
# valstr = schemaCreateCmd.dumps(vrpmdCreateCmd)
# trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
# mon = VRPMDV_Monitoring(id, vrpmreq.name, vrpmreq.samplerate, vrpmreq.sampleperiod, vrpmreq.downtime, vrpmreq.status, vrpmreq.owner)
# logging.info("Monitoring %s: starting", str(id))
# mon.startMonitoring()
# self.mons.append(mon)
# #save to file
# self.saveFile()
# #create result Object in json
# schema = VRPMDV_MonitoringSchema()
# return schema.dumps(mon)
# def deleteMonitoring(self, vrpmid):
# # if not self.loaded :
# # self.loaded = self.loadFile()
# # find monitoring with uuid
# #result = filter(lambda mon: str(mon.uuid) == vrpmid["uuid"], self.mons)
# try:
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
# except:
# return "no Item found"
# # 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()
# #make result
# schema = VRPMDV_MonitoringSchema()
# return schema.dump(matched_obj)
# def startMonitoring(self, vrpmid):
# # if not self.loaded :
# # self.loaded = self.loadFile()
# #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"
# if matched_obj.startMonitoring() :
# #TODO ML return the state
# return "started"
# return "created"
# def stopMonitoring(self, vrpmid):
# # if not self.loaded :
# # self.loaded = self.loadFile()
# #call the stop API of the c++ driver
# try:
# matched_obj = next(x for x in self.mons if str(x.id) == vrpmid)
# logging.info("MainThread: stop monitoring starting")
# vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(2, matched_obj.id)
# schemaDeleteCmd = VRPMDV_DeleteMonSchema()
# valstr = schemaDeleteCmd.dumps(vrpmdDeleteCmd)
# trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
# logging.info("MainThread: stop monitoring done")
# except:
# return "no Item found"
# matched_obj.stopMonitoring()
# 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
if (vrpmStatus['status'] == 'started'):
return self.startMonitoring(id)
else :
return self.stopMonitoring(id)
# 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 None #"no Item found"
def getMonitoring2files(self):
#search in the given directory
dirs = [d for d in os.listdir(self.monfilespath) if os.path.isdir(d)]
#return for the filter
def getMonitoringfiles(self, id, params):
#search in the given directory
monId = params.get('monId')
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
logging.info("getMonitoringfiles: monId:%s", monId)
if (monId == None):
return None
complete = False
mons = self.getMonofMonfiles(monId)
logging.info("getMonitoringfiles: mons.length:%d", len(mons))
if (len(mons) == 0) :
return None
else :
#TODO ML: only one monitoring
monId = mons[0].id
#TODO ML change to array
#for file in files:
filename = self.monfilespath + str(monId) + '/'
monfiles = self.loadMonfiles(filename, complete)
schema = VRPMDV_MonfilesSchema()
result = schema.dumps(monfiles, many=True)
return result
def loadMonfiles(self, id, complete):
#files = [f for f in os.listdir() if os.path.isfile(f)]
logging.info("loadMonfiles: monId:%s", id)
completeMonPath = os.path.dirname(id)
monfiles = []
for f in os.listdir(completeMonPath) :
# if (os.path.isfile(f)) :
try:
completeFilepath = id + str(f)
with open(completeFilepath, 'r') as f:
logging.info("loadMonfiles: before fmonfile:%s", completeFilepath)
fmonfile = f.read()
logging.info("loadMonfiles: after fmonfile:%s", completeFilepath)
if fmonfile:
# if (complete):
# schema = VRPMDV_MonfilesCompleteSchema()
# else :
logging.info("loadMonfiles: before schemaload")
if (complete):
schema = VRPMDV_MonfilesCompleteSchema()
else:
schema = VRPMDV_MonfilesSchema()
try:
monfile = schema.loads(fmonfile, unknown=EXCLUDE)
except ValidationError as err:
logging.info("SchemaError: %s",err.messages) # => {"email": ['"foo" is not a valid email address.']}
logging.info("Data: %s",err.valid_data) # => {"name": "John"}
monfiles.append(monfile)
except:
#nothing todo ML we should create a file later the database
print("file not found")
logging.info("loadMonfiles: file not found:%s", completeFilepath)
return monfiles
def getMonsDFAvalable(self):
monfilters = []
mons = self.getMonofMonfiles(0)
if (len(mons) == 0):
return None
else:
schema = VRPMDV_MonFilterSchema()
for mon in mons:
monfilter = VRPMDV_MonFilter(str(mon.id), mon.name)
monfilters.append(monfilter)
return schema.dumps(monfilters, many=True)
def getMonofMonfiles(self, monId) :
dirname = os.path.dirname(self.monfilespath)
dirs = []
for d in os.listdir(dirname) :
path_file = self.monfilespath + d #os.sep.join([self.monfilespath, d])
if os.path.isdir(path_file) :
dirs.append(d)
mons = []
for dir in dirs:
mon = self.findMonitoring(dir)
if ((mon != None) and ((monId == 0 ) or (monId == str(mon.id)))):
mons.append(mon)
# monId = mon.id
# else:
# return None
return mons
def getMFDownload(self, params):
#search in the given directory
monId = params.get('monId')
if (monId == None):
return None
fileId = params.get('fileid')
mons = self.getMonofMonfiles(monId)
#TODO ML change to array
#for file in files:
filename = self.monfilespath + str(monId) + '/'
monfiles = self.loadMonfiles(filename, True)
schema = VRPMDV_MonfilesCompleteSchema()
result = schema.dumps(monfiles, many=True)
return result
# This is to get the directory that the program
# is currently running in.
# dir_path = os.path.dirname(os.path.realpath(__file__))
# for root, dirs, files in os.walk(dir_path):
# for file in files:
# # change the extension from '.mp3' to
# # the one of your choice.
# if file.endswith('.mp3'):
# print (root+'/'+str(file))

View File

@@ -0,0 +1,10 @@
import datetime as dt
class VRPMDV_DeleteMonCmd:
def __init__(self, id ) :
self.cmdid = 2
self.id = id

View File

@@ -0,0 +1,23 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, post_dump
from vrpmdvdeletemoncmd import VRPMDV_DeleteMonCmd
class VRPMDV_DeleteMonSchema(Schema):
cmdid = fields.Integer()
id = fields.UUID()
@post_load
def make_vrpmdv_DeleteMonitoring(self, data, **kwargs):
mon = VRPMDV_DeleteMonCmd(**data)
return mon

View File

@@ -0,0 +1,10 @@
import datetime as dt
# generic command for delete, start, stop of the monitoring
class VRPMDV_GenericMonCmd:
def __init__(self, id , cmdId) :
self.id = id
self.cmdId = cmdId

View File

@@ -0,0 +1,34 @@
from extensions.rt_service import rt_service as rts
import logging
import threading
import time
def thread_function(name):
logging.info("Thread %s: starting", name)
rtserv = rts.RT_Service()
isok = rtserv.initLogChannel()
if (not isok):
logging.info("Thread %s: could not open the logport", name)
while (isok):
msg = rtserv.readLogChannel()
logging.info(msg)
if (msg == 'noResult'):
break
logging.info("Thread %s: finishing", name)
def createCoproLoggingTask():
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
x = threading.Thread(target=thread_function, args=(1,))
x.start()
return x

View File

@@ -0,0 +1,9 @@
import datetime as dt
class VRPMDV_MonChannels:
def __init__(self, name , valuetype):
self.name = name
self.valuetype = valuetype

View File

@@ -0,0 +1,18 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, EXCLUDE
from vrpmdvmonchannels import VRPMDV_MonChannels
class VRPMDV_MonChannelSchema(Schema):
name = fields.String()
valuetype = fields.String()
#value = fields.Number()
@post_load
def make_vrpmdv_MonfilesChannelSchema(self, data, **kwargs):
return VRPMDV_MonChannels(**data)

View File

@@ -0,0 +1,35 @@
from extensions.rt_service import rt_service as rts
import logging
import threading
import time
def thread_function(name):
logging.info("MonThread %s: starting", name)
rtserv = rts.RT_Service()
isok = rtserv.openDataChannel('/dev/mon-datafile')
if (not isok):
logging.info("MonThread %s: could not open the logport", name)
while (isok):
msg = rtserv.readDataChannel()
logging.info(msg)
if (msg == 'noResult'):
break
logging.info("MonThread %s: finishing", name)
rtserv.closeDataChannel()
def createCoproLoggingTask():
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
x = threading.Thread(target=thread_function, args=(1,))
x.start()
return x

View File

@@ -0,0 +1,15 @@
import datetime as dt
class VRPMDV_Monfiles:
def __init__(self, id, monid, name , samplerate, sampleperiod, downtime, timestamp, hwdescription) :
self.id = id
self.monid = monid
self.name = name
self.samplerate = samplerate
self.sampleperiod = sampleperiod
self.downtime = downtime
self.timestamp = timestamp
self.hwdescription = hwdescription

View File

@@ -0,0 +1,19 @@
import datetime as dt
from vrpmdvmonfiles import VRPMDV_Monfiles
class VRPMDV_MonfilesComplete(VRPMDV_Monfiles):
def __init__(self, id, monid, name , samplerate, sampleperiod, downtime, timestamp, hwdescription, values) :
self.id = id
self.monid = monid
self.name = name
self.samplerate = samplerate
self.sampleperiod = sampleperiod
self.downtime = downtime
self.timestamp = timestamp
self.hwdescription = hwdescription
self.values = values

View File

@@ -0,0 +1,39 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, EXCLUDE
from utilities.union import UnionField
from vrpmdvmonfilescomplete import VRPMDV_MonfilesComplete
from vrpmdvmonfilesschema import VRPMDV_MonfilesSchema
# books = fields.List(fields.Nested("BookSchema", exclude=("author",)))
class VRPMDV_MonfilesCompleteSchema(Schema):
id = fields.String(required=True)
monid = fields.String(required=True)
name = fields.String(required=True)
samplerate = fields.Integer(required=True)
sampleperiod = fields.Integer(required=True)
downtime = fields.Integer(required=True)
timestamp = fields.Integer(required=True)
hwdescription = fields.List(fields.Nested("VRPMDV_MonSensorSchema"))
values = fields.List(UnionField(
types=[int, float],
metadata={
"description": "Multiple types.",
},
))
@post_load
def make_vrpmdv_MonfilesCompleteSchema(self, data, **kwargs):
return VRPMDV_MonfilesComplete(**data)
# some_field = UnionField(
# types=[str, int, float, dict, list, bool, set, tuple],
# metadata={
# "description": "Multiple types.",
# },
# )

View File

@@ -0,0 +1,24 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, EXCLUDE
from vrpmdvmonfiles import VRPMDV_Monfiles
class VRPMDV_MonfilesSchema(Schema):
id = fields.String(required=True)
monid = fields.String(required=True)
name = fields.String(required=True)
samplerate = fields.Integer(required=True)
sampleperiod = fields.Integer(required=True)
downtime = fields.Integer(required=True)
timestamp = fields.Integer(required=True)
hwdescription = fields.List(fields.Nested("VRPMDV_MonSensorSchema"))
@post_load
def make_vrpmdv_Monfiles(self, data, **kwargs):
return VRPMDV_Monfiles(**data)

View File

@@ -0,0 +1,10 @@
import datetime as dt
class VRPMDV_MonFilter:
def __init__(self, id, name ) :
self.id = id
self.name = name

View File

@@ -0,0 +1,16 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load
from vrpmdvmonfilter import VRPMDV_MonFilter
class VRPMDV_MonFilterSchema(Schema):
id = fields.String()
name = fields.String()
@post_load
def make_vrpmdv_MonFilter(self, data, **kwargs):
return VRPMDV_MonFilter(**data)

View File

@@ -0,0 +1,223 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load
from vrpmdvcreatemoncmd import VRPMDV_CreateMonCmd
from vrpmdvcreatemonschema import VRPMDV_CreateMonSchema
from vrpmdvdeletemoncmd import VRPMDV_DeleteMonCmd
from vrpmdvdeletemonschema import VRPMDV_DeleteMonSchema
from vrpmdvmonreq import VRPMDV_MonReq
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState
from vrpmdvmondata import createCoproLoggingTask
# from vrpmdvntlink import trySend
import logging
import threading
import time
import io
import fcntl
import mmap
from vrpmdvntlink import trySend
from vrpmdvstatusmoncmd import VRPMDV_StatusMonCmd
from vrpmdvstatusmonschema import VRPMDV_StatusMonSchema
# def thread_function(name):
# logging.info("MonThread %s: starting", name)
# fdesc = -1
# rtMon = rts.RTSMonitoringTask()
# fdesc = rtMon.openChannel('/dev/mon-datafile')
# # write loginfos to Buffer
# msg = rtMon.getLogMsg()
# for msgstr in msg:
# logging.info(str(msgstr))
# while ((fdesc >= 0) && ()):
# msg = rtMon.readChannel(fdesc)
# # write loginfos to Buffer
# logmsg = rtMon.getLogMsg()
# for msgstr in logmsg:
# logging.info(str(msgstr))
# logging.info(msg)
# if (msg == 'noResult'):
# break
# logging.info("MonThread %s: finishing", name)
# rtMon.closeChannel(fdesc)
# if (res):
# props = res.getMsg()
# #props = res.getProps()
# if (res.getResCode() == 'error'):
# try:
# logging.info(props)
# # for key, value in props.items():
# # logging.info(key+" "+ str(value))
# except:
# logging.info("MonThread %s: could not open the channel", name)
# else:
# try:
# logging.info(props)
# # for key, value in props.items():
# # logging.info(key+" "+ str(value))
# except:
# logging.info("MonThread %s: could read fdesc of the channel", name)
# else :
# logging.info("MonThread %s: result = None", name)
class VRPMDV_Monitoring(VRPMDV_MonReq):
def __init__(self, no, id, name , samplerate, sampleperiod, downtime, status, owner="None", created_at=dt.datetime.now()) :
self.no = no
self.id = id
self.created_at = created_at
#TODO ML: uncomment
self.rtservice = None #rts.RT_Service()
self.rtMon = None
self.monTask = None
self.run_thread = False
self.fdesc = -1
super().__init__(name, samplerate, sampleperiod, downtime, owner, status)
def startMonitoring(self) :
#send create command to M4
try :
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
logging.info("MainThread: createMonOnDevice => before vrpmdCreateCmd samplerate:%d, samplerate:%d, samplerate:%d", self.samplerate, self.sampleperiod, self.downtime)
vrpmdCreateCmd = VRPMDV_CreateMonCmd(self.samplerate, self.sampleperiod, self.downtime)
logging.info("MainThread: createMonOnDevice => before schemaCreateCmd")
schemaCreateCmd = VRPMDV_CreateMonSchema()
logging.info("MainThread: try send start monitoring starting %s", schemaCreateCmd.dumps(vrpmdCreateCmd))
# TODO ML: uncomment this
res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
#res = 'Test'
logging.info("MainThread: try send start monitoring done %s", res)
# start the receiving thread
logging.info("MainThread %s: open", str(self.id))
# self.fdesc = self.rtMon.openChannel('/dev/mon-datafile')
# self.run_thread = True
# self.monTask = threading.Thread(target=self.run, args=())
# self.monTask.start()
# logging.info("MainThread: strated Mon Thread %s started", self.id)
logging.info("startmonitoring: create RTSMonitoringTask")
strid = str(self.id)
logging.info("rts.RTSMonitoringTask: self.id:%s", strid)
self.rtMon = rts.RTSMonitoringTask(str(self.id), str(self.name), self.samplerate, self.sampleperiod, self.downtime, '/home/root/monfiles/')
# self.rtMon.id = self.id
# self.rtMon.name = self.name
# self.rtMon.samplerate = self.samplerate
# self.rtMon.samplePeriod = self.sampleperiod
# self.rtMon.downtime = self.downtime
# self.rtMon.path = '/home/root/monfiles'
#logging.info("startmonitoring: created RTSMonitoringTask: id:%s name:%s samplerate:%d sampleperiod:%d downtime:%d path:%s", self.rtMon.id, self.rtMon.name, self.rtMon.samplerate, self.rtMon.samplePeriod, self.rtMon.downtime, self.rtMon.path)
##new ML 09.07.2024
if (self.rtMon.start()) :
logging.info("startmonitoring - self.rtMon.start(): Monitoring started")
self.status = 'started'
else :
self.status = 'stopped'
return self.status
except :
self.status = "stopped"
self.rtMon = None
return self.status
def stopMonitoring(self) :
# isstopped = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.stopped)
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")#
logging.info("MainThread: stopping Mon Thread %s ", self.id)
#send delete cmd to M4
#logging.info("MainThread: stop monitoring")
# if (self.monTask != None) :
# set the value Runthread to fals that the thread terminate
# self.run_thread = False
# self.monTask.join(None)
##new ML 09.07.2024
if (self.rtMon != None) :
self.rtMon.stop()
# self.monTask = None
# logging.info("MonThread %s: closing fdesc=%s", str(self.id), str(self.fdesc))
# # self.rtMon.closeChannel(self.fdesc)
# logging.info("MonThread %s: closed fdesc=%s", str(self.id), str(self.fdesc))
logging.info("MainThread: stopped Mon Thread %s ", self.id)
vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(self.no)
schemaDeleteCmd = VRPMDV_DeleteMonSchema()
# TODO ML: uncomment this
res = trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
#res = 'Stopped'
logging.info("MainThread: try send stop monitoring done %s", res)
self.rtMon = None
# if (isstopped) :
self.status = 'stopped'
return self.status
# def setStatus(self, status) :
# # isStatusSet = self.rtservice.setMonitoringStatus(str(self.id), status)
# logging.info("MainThread: set status ")
# return True
def run(self):
# logging.info("MonThread %s: starting", str(self.id))
# fdesc = -1
# rtMon = rts.RTSMonitoringTask()
# fdesc = rtMon.openChannel('/dev/mon-datafile')
# write loginfos to Buffer
# msg = rtMon.getLogMsg()
# for msgstr in msg:
# logging.info(str(msgstr))
count = 0;
if (self.fdesc >= 0) :
while (self.run_thread):
# check if the thread is running
# if (count == 50):
# vrpmdStatusCmd = VRPMDV_StatusMonCmd(self.no)
# schemaStatusCmd = VRPMDV_StatusMonSchema()
# res = trySend(schemaStatusCmd.dumps(vrpmdStatusCmd))
# logging.info("MainThread: try send stop monitoring done %s", res)
# count = 0
#count = count +1
msg = self.rtMon.readChannel(self.fdesc)
logging.info("MonThread %s: running", str(self.id))
logging.info("Result: %s", msg)
#time.sleep(1)
# write loginfos to Buffer
# logmsg = rtMon.getLogMsg()
# for msgstr in logmsg:
# logging.info(str(msgstr))
# logging.info(msg)
# if (msg == 'noResult'):
# break
# logging.info("MonThread %s: finishing", str(self.id))
# rtMon.closeChannel(fdesc)
logging.info("MonThread %s: finished", str(self.id))
# msg = rtMon.getLogMsg()
# for msgstr in msg:
# logging.info(str(msgstr))
else:
logging.info("MonThread %s: opening failed fdesc <= 0", str(self.id))

View File

@@ -0,0 +1,30 @@
#from enum import Enum
from marshmallow import Schema, fields, post_load
class VRPMDVMonitoringState():
STARTED = 'started'
STOPPED = 'stopped'
NCREATE = 0
NDELETE = 1
def __init__(self, state = STOPPED):
self.state = state
def get(self) :
if (self.state == self.STARTED) :
return self.NCREATE
else :
return self.NDELETE
# class VRPMDVMonitoringState(Enum):
# off = 1
# created = 2
# started = 3
# stopped = 4

View File

@@ -0,0 +1,29 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, post_dump
from vrpmdvmonitoring import VRPMDV_Monitoring
class VRPMDV_MonitoringSchema(Schema):
no = fields.Integer()
id = fields.UUID()
created_at = fields.DateTime("%m/%d/%Y, %H:%M")
name = fields.String()
samplerate = fields.Integer()
sampleperiod = fields.Integer()
downtime = fields.Integer()
owner = fields.String()
status = fields.String()
@post_load
def make_vrpmdv_Monitoring(self, data, **kwargs):
mon = VRPMDV_Monitoring(**data)
#create the monitoring on the realtime side
# mon.createMonitoring()
return mon

View File

@@ -0,0 +1,14 @@
import datetime as dt
class VRPMDV_MonReq:
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

@@ -0,0 +1,20 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load
from vrpmdvmonreq import VRPMDV_MonReq
class VRPMDV_MonReqSchema(Schema):
name = fields.String()
samplerate = fields.Integer()
sampleperiod = fields.Integer()
downtime = fields.Integer()
owner = fields.String()
status = fields.String()
@post_load
def make_vrpmdv_MonitoringReq(self, data, **kwargs):
return VRPMDV_MonReq(**data)

View File

@@ -0,0 +1,11 @@
import datetime as dt
class VRPMDV_MonSensor:
def __init__(self, name , channels):
self.name = name
self.channels = channels

View File

@@ -0,0 +1,16 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, EXCLUDE
from vrpmdvmonsensor import VRPMDV_MonSensor
class VRPMDV_MonSensorSchema(Schema):
name = fields.String()
channels = fields.List(fields.Nested("VRPMDV_MonChannelSchema"))
@post_load
def make_vrpmdv_MonfilesSensorSchema(self, data, **kwargs):
return VRPMDV_MonSensor(**data)

View File

@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import traceback
from pyroute2.netlink import NLM_F_REQUEST
from pyroute2.netlink import genlmsg
from pyroute2.netlink.generic import GenericNetlinkSocket
import sys
RLINK_CMD_UNSPEC = 0
RLINK_CMD_REQ = 1
class rcmd(genlmsg):
'''
Message class that will be used to communicate
with the kernel module
'''
nla_map = (
('RLINK_ATTR_UNSPEC', 'none'),
('RLINK_ATTR_DATA', 'asciiz'),
)
class Rlink(GenericNetlinkSocket):
def send_data(self, data):
msg = rcmd()
msg['cmd'] = RLINK_CMD_REQ
msg['version'] = 1
msg['attrs'] = [('RLINK_ATTR_DATA', data)]
ret = self.nlm_request(msg, self.prid, msg_flags=NLM_F_REQUEST)[0]
return ret.get_attr('RLINK_ATTR_DATA')
def trySend(data):
# if __name__ == '__main__':
try:
# create protocol instance
rlink = Rlink()
rlink.bind('gnl-vrpmdv-mcmd', rcmd)
#rlink.send_data(data)
# request a method
res = rlink.send_data(data)
if res :
print(res, file=sys.stdout)
sys.stdout.flush()
except:
# if there was an error, log it to the console
traceback.print_exc()
finally:
# finally -- release the instance
rlink.close()
return res

View File

@@ -0,0 +1,176 @@
# from vrpmdv-server/vrpmdv-main import application
import logging
import os
import sys
import json
from flask import Flask, request , send_from_directory , Response
from flask_cors import CORS
from vrpmdvdata import VRPMDV_Data
from vrpmdvmonreqschema import VRPMDV_MonReqSchema
# import ecal.core.core as ecal_core
# from proto_messages.RTService_pb2 import _RTSERVICE as rtservice
app = Flask(__name__, static_url_path='', static_folder='./build')
#app = Flask(__name__, static_url_path='/public', static_folder='../build')
#app = Flask(__name__)
CORS(app) #comment this on deployment
vrpmdvdata = VRPMDV_Data()
@app.route("/", defaults={'path':''})
#@app.route("/")
@app.route('/<path:path>')
def serve(path):
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
logging.info("vrpmdvserver: path:%s", path)
# path_dir = os.path.abspath("../build") #path react build
# if path != "" and os.path.exists(os.path.join(path_dir, path)):
# return send_from_directory(os.path.join(path_dir), path)
# else:
# return send_from_directory(os.path.join(path_dir),'index.html')
return send_from_directory(app.static_folder,'index.html')
@app.errorhandler(404)
def not_found(e):
return app.send_static_file('index.html')
@app.route('/vrpmdvapi/1_0/monitorings', methods=['GET'])
def get_monitorings():
data = vrpmdvdata.getMonitorings()
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitorings/<id>', methods=['GET'])
def get_monitoring(id):
data = vrpmdvdata.getMonitoring(id)
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitorings/<id>', methods=['PATCH'])
def set_monitoring(id):
# 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
@app.route('/vrpmdvapi/1_0/monitorings', methods=['POST'])
def create_monitoring():
#vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
#data = vrpmdvdata.createMonitoring(vrpmreq)
data = vrpmdvdata.createMonitoring(request)
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitorings/<id>', methods=['DELETE'])
def delete_monitoring(id):
data = vrpmdvdata.deleteMonitoring(id)
resp = Response(data, status=200, mimetype='application/json')
return resp
@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=['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
@app.route('/vrpmdvapi/1_0/monitoring/mondfaivalable', methods=['GET'])
def get_mondfaivalable():
data = vrpmdvdata.getMonsDFAvalable()
if (data == None):
resp = Response("no Item found", status=404, mimetype='application/json')
else:
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitoringfiles', methods=['GET'])
def get_monitoringfiles():
vrpmreqjson = request.args
#vrpmreq = VRPMDV_MonReqSchema().load(request.get_json())
#data = vrpmdvdata.createMonitoring(vrpmreq)
data = vrpmdvdata.getMonitoringfiles(0, request.args)
if (data == None):
resp = Response("no Item found", status=404, mimetype='application/json')
else:
resp = Response(data, status=200, mimetype='application/json')
return resp
@app.route('/vrpmdvapi/1_0/monitoringfiles/download', methods=['GET'])
def get_mfDownload():
vrpmreqjson = request.args
data = vrpmdvdata.getMFDownload(request.args)
if (data == None):
resp = Response("no Item found", status=404, mimetype='application/json')
else:
resp = Response(data, status=200, mimetype='application/json')
return resp
if __name__ == "__main__":
# initialize eCAL API. The name of our Process will be
# "Python Protobuf Subscriber"
#ecal_core.initialize(sys.argv, "Python Protobuf Subscriber")
app.run()
# if __name__ == "__main__":
# # Create a Protobuf Publisher that publishes on the topic
# # "hello_world_python_protobuf_topic". The second parameter tells eCAL which
# # datatype we are expecting to receive on that topic.
# sub = ProtoSubscriber("hello_world_python_protobuf_topic"
# , hello_world_pb2.HelloWorld)
# # Set the Callback
# sub.set_callback(callback)
# # Just don't exit
# while ecal_core.ok():
# time.sleep(0.5)
# # finalize eCAL API
# ecal_core.finalize()

View File

@@ -0,0 +1,10 @@
import datetime as dt
class VRPMDV_StatusMonCmd:
def __init__(self, id ) :
self.cmdid = 3
self.id = id

View File

@@ -0,0 +1,23 @@
import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load, post_dump
from vrpmdvstatusmoncmd import VRPMDV_StatusMonCmd
class VRPMDV_StatusMonSchema(Schema):
cmdid = fields.Integer()
id = fields.UUID()
@post_load
def make_vrpmdv_StatusMonitoring(self, data, **kwargs):
mon = VRPMDV_StatusMonCmd(**data)
return mon