added the rtservice, Webserver, webfrontend with:
1. Monitoring 2. Monitoringfiles 3. Download
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project( rt_service CXX )
|
project(rt_service)
|
||||||
|
|
||||||
set(CMAKE_SYSTEM_NAME Linux)
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
|
||||||
set(CMAKE_SYSTEM_PROCESSOR armv7-a)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
# -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}")
|
|
||||||
|
|
||||||
|
# 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"
|
# Without this, any build libraries automatically have names "lib{x}.so"
|
||||||
set(CMAKE_SHARED_MODULE_PREFIX "")
|
set(CMAKE_SHARED_MODULE_PREFIX "")
|
||||||
@@ -18,9 +18,29 @@ set(CMAKE_SHARED_MODULE_PREFIX "")
|
|||||||
add_definitions(-DBOOST_BIND_GLOBAL_PLACEHOLDERS)
|
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.
|
# Add a shared module - modules are intended to be imported at runtime.
|
||||||
# - This is where you add the source files
|
# - This is where you add the source files
|
||||||
add_library(rt_service SHARED rt_service.cpp)
|
#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
|
||||||
|
# )
|
||||||
|
|||||||
@@ -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;
|
||||||
|
};
|
||||||
@@ -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_ */
|
||||||
@@ -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_ */
|
||||||
@@ -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_ */
|
||||||
@@ -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_ */
|
||||||
@@ -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_ */
|
||||||
@@ -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_ */
|
||||||
|
|
||||||
@@ -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, ...);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
@@ -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_ */
|
||||||
@@ -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;
|
||||||
|
};
|
||||||
@@ -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_ */
|
||||||
@@ -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_ */
|
||||||
24766
recipes-vrpmdv/recipes-base/vrpmdv-web/files/rt_service/include/json.hpp
Normal file
24766
recipes-vrpmdv/recipes-base/vrpmdv-web/files/rt_service/include/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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_
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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>())
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
@@ -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());
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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>())
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
*********************************************************************************/
|
||||||
@@ -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());
|
||||||
|
}
|
||||||
@@ -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.
@@ -1,9 +1,11 @@
|
|||||||
SUMMARY = "vrpmdv-web recipe"
|
SUMMARY = "vrpmdv-web recipe"
|
||||||
DESCRIPTION = "Recipe to add vrpmdv-setup-page to it's location."
|
DESCRIPTION = "Recipe to add vrpmdv-web to it's location."
|
||||||
LICENSE = "CLOSED"
|
LICENSE = "CLOSED"
|
||||||
|
# LICENSE_FLAGS = "commercial"
|
||||||
|
|
||||||
# inherit allarch perlnative cmake pkgconfig
|
# inherit allarch perlnative cmake pkgconfig
|
||||||
inherit perlnative
|
inherit perlnative
|
||||||
|
inherit cmake
|
||||||
|
|
||||||
DEPENDS += "perl"
|
DEPENDS += "perl"
|
||||||
DEPENDS += "boost"
|
DEPENDS += "boost"
|
||||||
@@ -14,22 +16,55 @@ DEPENDS += "boost"
|
|||||||
# file://rt_service/rt_service.cpp \
|
# file://rt_service/rt_service.cpp \
|
||||||
# "
|
# "
|
||||||
|
|
||||||
|
#TODO ML make a git repo
|
||||||
|
SRC_URI += " \
|
||||||
|
file://rt_service/CMakeLists.txt \
|
||||||
|
file://rt_service/zephyr_openamp_rsc_table.elf \
|
||||||
|
file://rt_service/include/GILLock.h \
|
||||||
|
file://rt_service/include/IChannelDesc.h \
|
||||||
|
file://rt_service/include/ISensorDesc.h \
|
||||||
|
file://rt_service/include/json.hpp \
|
||||||
|
file://rt_service/include/json_fwd.hpp \
|
||||||
|
file://rt_service/include/RelGILLock.h \
|
||||||
|
file://rt_service/include/RTSCoproHelper.h \
|
||||||
|
file://rt_service/include/RTSErrResult.h \
|
||||||
|
file://rt_service/include/RTSMonFrame.h \
|
||||||
|
file://rt_service/include/RTSMonitoringTask.h \
|
||||||
|
file://rt_service/include/RTSPyLogging.h \
|
||||||
|
file://rt_service/include/RTSResult.h \
|
||||||
|
file://rt_service/include/VibChannelDesc.h \
|
||||||
|
file://rt_service/include/VibSensorDesc.h \
|
||||||
|
file://rt_service/src/rt_service.cpp \
|
||||||
|
file://rt_service/src/monitoringTask/RTSErrResult.cpp \
|
||||||
|
file://rt_service/src/monitoringTask/RTSMonFrame.cpp \
|
||||||
|
file://rt_service/src/monitoringTask/RTSMonitoringTask.cpp \
|
||||||
|
file://rt_service/src/monitoringTask/RTSResult.cpp \
|
||||||
|
file://rt_service/src/monitoringTask/VibChannelDesc.cpp \
|
||||||
|
file://rt_service/src/monitoringTask/VibSensorDesc.cpp \
|
||||||
|
file://rt_service/src/utilities/GILLock.cpp \
|
||||||
|
file://rt_service/src/utilities/RelGILLock.cpp \
|
||||||
|
file://rt_service/src/utilities/RTSCoproHelper.cpp \
|
||||||
|
file://rt_service/src/utilities/RTSPyLogging.cpp \
|
||||||
|
"
|
||||||
|
|
||||||
SRC_URI+="git://gitea.malehr.de/markus.lehr/vrpmdv-py-rtservice.git;protocol=https;branch=master;user=makus.lehr:gQsZ2Qht346yQG;destsuffix=vrpmdv-py-rtservice;name=vrpmdv-py-rtservice"
|
|
||||||
SRCREV_vrpmdv-py-rtservice="45380e38b1c0abd7244bd36dd504fb736669a384"
|
# SRC_URI+="git://gitea.malehr.de/markus.lehr/vrpmdv-py-rtservice.git;protocol=https;branch=master;user=makus.lehr:gQsZ2Qht346yQG;destsuffix=vrpmdv-py-rtservice;name=vrpmdv-py-rtservice"
|
||||||
|
# SRCREV_vrpmdv-py-rtservice="45380e38b1c0abd7244bd36dd504fb736669a384"
|
||||||
|
|
||||||
|
|
||||||
SRC_URI+="git://gitea.malehr.de/markus.lehr/vrpmdv-web.git;protocol=https;branch=master;user=makus.lehr:gQsZ2Qht346yQG;name=vrpmdv-web"
|
SRC_URI+="git://gitea.malehr.de/markus.lehr/vrpmdv-web.git;protocol=https;branch=master;user=makus.lehr:gQsZ2Qht346yQG;name=vrpmdv-web"
|
||||||
SRCREV_vrpmdv-web="9ebdd8fd55286e42a6b5c1e592ff07a282799aa9"
|
SRCREV_vrpmdv-web="bd3078bdefa3892b3c8714a4d4035391f4984529"
|
||||||
|
|
||||||
# S = "${WORKDIR}/rt_service"
|
S = "${WORKDIR}/rt_service"
|
||||||
# B = "${WORKDIR}/rt_service/build"
|
B = "${WORKDIR}/rt_service/build"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DESTINATION = "/var/www/vrpmdv-web.local"
|
DESTINATION = "/var/www/vrpmdv-web.local"
|
||||||
|
ELFDESTINATION = "home/root/elffile"
|
||||||
|
|
||||||
FILES:${PN} += "${DESTINATION}"
|
FILES:${PN} += "${DESTINATION}"
|
||||||
|
FILES:${PN} += "${ELFDESTINATION}"
|
||||||
|
|
||||||
# do_configure(){
|
# do_configure(){
|
||||||
# set(CMAKE_C_COMPILER_WORKS 1)
|
# set(CMAKE_C_COMPILER_WORKS 1)
|
||||||
@@ -43,20 +78,29 @@ do_install () {
|
|||||||
install -d ${D}${DESTINATION}
|
install -d ${D}${DESTINATION}
|
||||||
install -d ${D}${DESTINATION}/extensions
|
install -d ${D}${DESTINATION}/extensions
|
||||||
install -d ${D}${DESTINATION}/extensions/rt_service
|
install -d ${D}${DESTINATION}/extensions/rt_service
|
||||||
|
install -d ${D}${DESTINATION}/home
|
||||||
|
install -d ${D}/home/root
|
||||||
|
install -d ${D}/home/root/elffile
|
||||||
|
|
||||||
|
|
||||||
install -d ${D}${DESTINATION}/build
|
install -d ${D}${DESTINATION}/build
|
||||||
install -d ${D}${DESTINATION}/build/assets
|
install -d ${D}${DESTINATION}/build/assets
|
||||||
install -m 0644 ${WORKDIR}/git/vrpmdvserver/*.py ${D}/${DESTINATION}
|
install -m 0644 ${WORKDIR}/git/vrpmdvserver/*.py ${D}/${DESTINATION}
|
||||||
install -m 0644 ${WORKDIR}/vrpmdv-py-rtservice/*.so ${D}/${DESTINATION}/extensions/rt_service
|
install -m 0644 ${B}/*.so ${D}/${DESTINATION}/extensions/rt_service
|
||||||
|
install -m 0644 ${WORKDIR}/rt_service/*.elf ${D}/${ELFDESTINATION}
|
||||||
|
|
||||||
|
# install -m 0644 ${WORKDIR}/vrpmdv-py-rtservice/*.so ${D}/${DESTINATION}/extensions/rt_service
|
||||||
|
|
||||||
install -m 0644 ${WORKDIR}/git/vrpmdvserver/webbuild/index.html ${D}/${DESTINATION}/build
|
install -m 0644 ${WORKDIR}/git/vrpmdvserver/webbuild/index.html ${D}/${DESTINATION}/build
|
||||||
install -m 0644 ${WORKDIR}/git/vrpmdvserver/webbuild/favicon.ico ${D}/${DESTINATION}/build
|
install -m 0644 ${WORKDIR}/git/vrpmdvserver/webbuild/favicon.ico ${D}/${DESTINATION}/build
|
||||||
install -m 0644 ${WORKDIR}/git/vrpmdvserver/webbuild/assets/*.js ${D}/${DESTINATION}/build/assets
|
install -m 0644 ${WORKDIR}/git/vrpmdvserver/webbuild/assets/*.js ${D}/${DESTINATION}/build/assets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BBCLASSEXTEND = "native "
|
||||||
# BBCLASSEXTEND =+ "native nativesdk"
|
# BBCLASSEXTEND =+ "native nativesdk"
|
||||||
# BBCLASSEXTEND =+ "multilib:multilib_name"
|
# BBCLASSEXTEND =+ "multilib:multilib_name"
|
||||||
RDEPENDS:${PN} += " perl"
|
RDEPENDS:${PN} += " perl"
|
||||||
RDEPENDS:${PN} += " boost-python"
|
RDEPENDS:${PN} += " boost-python"
|
||||||
|
RDEPENDS:${PN} += " boost"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user