added the rtservice, Webserver, webfrontend with:

1. Monitoring
2. Monitoringfiles
3. Download
This commit is contained in:
2024-07-10 11:36:16 +02:00
parent 3f966ecc89
commit 96308eb092
29 changed files with 27475 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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