we could read the kernel data and make a json file

This commit is contained in:
2024-06-25 20:46:54 +02:00
parent 8d2fee2406
commit bd3078bdef
30 changed files with 536 additions and 4603 deletions

78
.vscode/settings.json vendored Normal file
View File

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

View File

@@ -13,8 +13,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Find python and Boost - both are required dependencies # Find python and Boost - both are required dependencies
#find_package(PythonLibs 3.10 REQUIRED) #find_package(PythonLibs 3.10 REQUIRED)
find_package(Boost COMPONENTS python REQUIRED) find_package(Boost COMPONENTS python REQUIRED)
find_package(eCAL REQUIRED) #find_package(eCAL REQUIRED)
find_package(Protobuf REQUIRED) #find_package(Protobuf REQUIRED)
set(source_files set(source_files
@@ -26,21 +26,21 @@ set(source_files
) )
set(rtservice_proto # set(rtservice_proto
${CMAKE_CURRENT_SOURCE_DIR}/src/proto_messages/RTService.proto # ${CMAKE_CURRENT_SOURCE_DIR}/src/proto_messages/RTService.proto
) # )
add_executable(${PROJECT_NAME} ${source_files}) add_executable(${PROJECT_NAME} ${source_files})
#ecal_add_sample(${PROJECT_NAME} ${math_client_src}) #ecal_add_sample(${PROJECT_NAME} ${math_client_src})
#PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src ${rtservice_proto}) #PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src ${rtservice_proto})
PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/proto_messages/ ${rtservice_proto}) #PROTOBUF_TARGET_CPP(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/proto_messages/ ${rtservice_proto})
#set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) #set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service) #set (CMAKE_RUNTIME_OUTPUT_DIRECTORY /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)
set (RTSERVICEINCLUDE ./include) #set (RTSERVICEINCLUDE ./include)
file( GLOB LIB_SOURCES .src/*.cpp ) file( GLOB LIB_SOURCES .src/*.cpp )
@@ -54,11 +54,16 @@ file( GLOB LIB_HEADERS lib/*.h )
# Set up the libraries and header search paths for this target # Set up the libraries and header search paths for this target
#target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) #target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
#target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS} ${RTSERVICEINCLUDE}) #target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS} ${RTSERVICEINCLUDE})
# target_link_libraries(RTService ${Boost_LIBRARIES} ) target_link_libraries(RTService ${Boost_LIBRARIES} )
target_link_libraries(${PROJECT_NAME} # target_link_libraries(${PROJECT_NAME}
eCAL::core # eCAL::core
protobuf::libprotobuf # protobuf::libprotobuf
) # )
# target_link_libraries(${PROJECT_NAME}
# eCAL::core
# )
target_include_directories(${PROJECT_NAME} PRIVATE ${RTSERVICEINCLUDE}) target_include_directories(${PROJECT_NAME} PRIVATE ${RTSERVICEINCLUDE})

View File

@@ -1 +0,0 @@
,markus,U2204VM,15.04.2024 12:29,file:///home/markus/.config/libreoffice/4;

287
__logicsample/RPMSGDriver.c Normal file
View File

@@ -0,0 +1,287 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 STMicroelectronics - All Rights Reserved
*
* The rpmsg tty driver implements serial communication on the RPMsg bus to makes
* possible for user-space programs to send and receive rpmsg messages as a standard
* tty protocol.
*
* The remote processor can instantiate a new tty by requesting a "rpmsg-tty" RPMsg service.
* The "rpmsg-tty" service is directly used for data exchange. No flow control is implemented yet.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/rpmsg.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_flip.h>
#define RPMSG_TTY_NAME "ttyRPMSG"
#define MAX_TTY_RPMSG 32
static DEFINE_IDR(tty_idr); /* tty instance id */
static DEFINE_MUTEX(idr_lock); /* protects tty_idr */
static struct tty_driver *rpmsg_tty_driver;
struct rpmsg_tty_port {
struct tty_port port; /* TTY port data */
int id; /* TTY rpmsg index */
struct rpmsg_device *rpdev; /* rpmsg device */
};
static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src)
{
struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev);
int copied;
if (!len)
return -EINVAL;
copied = tty_insert_flip_string(&cport->port, data, len);
if (copied != len)
dev_err_ratelimited(&rpdev->dev, "Trunc buffer: available space is %d\n", copied);
tty_flip_buffer_push(&cport->port);
return 0;
}
static int rpmsg_tty_install(struct tty_driver *driver, struct tty_struct *tty)
{
struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index);
struct tty_port *port;
tty->driver_data = cport;
port = tty_port_get(&cport->port);
return tty_port_install(port, driver, tty);
}
static void rpmsg_tty_cleanup(struct tty_struct *tty)
{
tty_port_put(tty->port);
}
static int rpmsg_tty_open(struct tty_struct *tty, struct file *filp)
{
return tty_port_open(tty->port, tty, filp);
}
static void rpmsg_tty_close(struct tty_struct *tty, struct file *filp)
{
return tty_port_close(tty->port, tty, filp);
}
static int rpmsg_tty_write(struct tty_struct *tty, const u8 *buf, int len)
{
struct rpmsg_tty_port *cport = tty->driver_data;
struct rpmsg_device *rpdev;
int msg_max_size, msg_size;
int ret;
rpdev = cport->rpdev;
msg_max_size = rpmsg_get_mtu(rpdev->ept);
if (msg_max_size < 0)
return msg_max_size;
msg_size = min(len, msg_max_size);
/*
* Use rpmsg_trysend instead of rpmsg_send to send the message so the caller is not
* hung until a rpmsg buffer is available. In such case rpmsg_trysend returns -ENOMEM.
*/
ret = rpmsg_trysend(rpdev->ept, (void *)buf, msg_size);
if (ret) {
dev_dbg_ratelimited(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
return ret;
}
return msg_size;
}
static unsigned int rpmsg_tty_write_room(struct tty_struct *tty)
{
struct rpmsg_tty_port *cport = tty->driver_data;
int size;
size = rpmsg_get_mtu(cport->rpdev->ept);
if (size < 0)
return 0;
return size;
}
static void rpmsg_tty_hangup(struct tty_struct *tty)
{
tty_port_hangup(tty->port);
}
static const struct tty_operations rpmsg_tty_ops = {
.install = rpmsg_tty_install,
.open = rpmsg_tty_open,
.close = rpmsg_tty_close,
.write = rpmsg_tty_write,
.write_room = rpmsg_tty_write_room,
.hangup = rpmsg_tty_hangup,
.cleanup = rpmsg_tty_cleanup,
};
static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void)
{
struct rpmsg_tty_port *cport;
int ret;
cport = kzalloc(sizeof(*cport), GFP_KERNEL);
if (!cport)
return ERR_PTR(-ENOMEM);
mutex_lock(&idr_lock);
ret = idr_alloc(&tty_idr, cport, 0, MAX_TTY_RPMSG, GFP_KERNEL);
mutex_unlock(&idr_lock);
if (ret < 0) {
kfree(cport);
return ERR_PTR(ret);
}
cport->id = ret;
return cport;
}
static void rpmsg_tty_destruct_port(struct tty_port *port)
{
struct rpmsg_tty_port *cport = container_of(port, struct rpmsg_tty_port, port);
mutex_lock(&idr_lock);
idr_remove(&tty_idr, cport->id);
mutex_unlock(&idr_lock);
kfree(cport);
}
static const struct tty_port_operations rpmsg_tty_port_ops = {
.destruct = rpmsg_tty_destruct_port,
};
static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
{
struct rpmsg_tty_port *cport;
struct device *dev = &rpdev->dev;
struct device *tty_dev;
int ret;
cport = rpmsg_tty_alloc_cport();
if (IS_ERR(cport))
return dev_err_probe(dev, PTR_ERR(cport), "Failed to alloc tty port\n");
tty_port_init(&cport->port);
cport->port.ops = &rpmsg_tty_port_ops;
tty_dev = tty_port_register_device(&cport->port, rpmsg_tty_driver,
cport->id, dev);
if (IS_ERR(tty_dev)) {
ret = dev_err_probe(dev, PTR_ERR(tty_dev), "Failed to register tty port\n");
tty_port_put(&cport->port);
return ret;
}
cport->rpdev = rpdev;
dev_set_drvdata(dev, cport);
dev_dbg(dev, "New channel: 0x%x -> 0x%x: " RPMSG_TTY_NAME "%d\n",
rpdev->src, rpdev->dst, cport->id);
return 0;
}
static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
{
struct rpmsg_tty_port *cport = dev_get_drvdata(&rpdev->dev);
dev_dbg(&rpdev->dev, "Removing rpmsg tty device %d\n", cport->id);
/* User hang up to release the tty */
tty_port_tty_hangup(&cport->port, false);
tty_unregister_device(rpmsg_tty_driver, cport->id);
tty_port_put(&cport->port);
}
static struct rpmsg_device_id rpmsg_driver_tty_id_table[] = {
{ .name = "rpmsg-tty" },
{ },
};
MODULE_DEVICE_TABLE(rpmsg, rpmsg_driver_tty_id_table);
static struct rpmsg_driver rpmsg_tty_rpmsg_drv = {
.drv.name = KBUILD_MODNAME,
.id_table = rpmsg_driver_tty_id_table,
.probe = rpmsg_tty_probe,
.callback = rpmsg_tty_cb,
.remove = rpmsg_tty_remove,
};
static int __init rpmsg_tty_init(void)
{
int ret;
rpmsg_tty_driver = tty_alloc_driver(MAX_TTY_RPMSG, TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV);
if (IS_ERR(rpmsg_tty_driver))
return PTR_ERR(rpmsg_tty_driver);
rpmsg_tty_driver->driver_name = "rpmsg_tty";
rpmsg_tty_driver->name = RPMSG_TTY_NAME;
rpmsg_tty_driver->major = 0;
rpmsg_tty_driver->type = TTY_DRIVER_TYPE_CONSOLE;
/* Disable unused mode by default */
rpmsg_tty_driver->init_termios = tty_std_termios;
rpmsg_tty_driver->init_termios.c_lflag &= ~(ECHO | ICANON);
rpmsg_tty_driver->init_termios.c_oflag &= ~(OPOST | ONLCR);
tty_set_operations(rpmsg_tty_driver, &rpmsg_tty_ops);
ret = tty_register_driver(rpmsg_tty_driver);
if (ret < 0) {
pr_err("Couldn't install driver: %d\n", ret);
goto error_put;
}
ret = register_rpmsg_driver(&rpmsg_tty_rpmsg_drv);
if (ret < 0) {
pr_err("Couldn't register driver: %d\n", ret);
goto error_unregister;
}
return 0;
error_unregister:
tty_unregister_driver(rpmsg_tty_driver);
error_put:
tty_driver_kref_put(rpmsg_tty_driver);
return ret;
}
static void __exit rpmsg_tty_exit(void)
{
unregister_rpmsg_driver(&rpmsg_tty_rpmsg_drv);
tty_unregister_driver(rpmsg_tty_driver);
tty_driver_kref_put(rpmsg_tty_driver);
idr_destroy(&tty_idr);
}
module_init(rpmsg_tty_init);
module_exit(rpmsg_tty_exit);
MODULE_AUTHOR("Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>");
MODULE_DESCRIPTION("remote processor messaging tty driver");
MODULE_LICENSE("GPL v2");

View File

@@ -0,0 +1 @@
/query.json

7
build/.cmake/api/v1/reply/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
/cache-v2-b083f9b25e5fcd6a2264.json
/cmakeFiles-v1-74273e290dadc9250fe0.json
/codemodel-v2-1dafefaac836f38d91b3.json
/directory-.-Debug-f5ebdc15457944623624.json
/index-2024-05-28T12-15-27-0540.json
/target-RTService-Debug-5a1ae4d2709fa8a6e973.json
/toolchains-v1-8f001b8fbe957a6b9d5a.json

6
build/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/CMakeCache.txt
/Makefile
/RTService
/build.ninja
/cmake_install.cmake
/compile_commands.json

6
build/CMakeFiles/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/CMakeConfigureLog.yaml
/Makefile2
/TargetDirectories.txt
/cmake.check_cache
/progress.marks
/rules.ninja

5
build/CMakeFiles/3.29.2/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/CMakeCCompiler.cmake
/CMakeCXXCompiler.cmake
/CMakeDetermineCompilerABI_C.bin
/CMakeDetermineCompilerABI_CXX.bin
/CMakeSystem.cmake

View File

@@ -0,0 +1,2 @@
/CMakeCCompilerId.c
/a.out

View File

@@ -0,0 +1,2 @@
/CMakeCXXCompilerId.cpp
/a.out

5
build/CMakeFiles/3.29.3/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
/CMakeCCompiler.cmake
/CMakeCXXCompiler.cmake
/CMakeDetermineCompilerABI_C.bin
/CMakeDetermineCompilerABI_CXX.bin
/CMakeSystem.cmake

View File

@@ -0,0 +1,2 @@
/CMakeCCompilerId.c
/a.out

View File

@@ -0,0 +1,2 @@
/CMakeCXXCompilerId.cpp
/a.out

View File

@@ -0,0 +1,9 @@
/DependInfo.cmake
/build.make
/cmake_clean.cmake
/compiler_depend.make
/compiler_depend.ts
/depend.make
/flags.make
/link.txt
/progress.make

View File

@@ -0,0 +1,2 @@
/RTService.cpp.o
/RTService.cpp.o.d

View File

@@ -0,0 +1,2 @@
/RTSMonitoringTask.cpp.o
/RTSMonitoringTask.cpp.o.d

View File

@@ -0,0 +1,2 @@
/RTSCoproHelper.cpp.o
/RTSCoproHelper.cpp.o.d

View File

@@ -0,0 +1,32 @@
#include <string>
#include <list>
#include <iostream>
#include <thread>
#include <ecal/ecal.h>
#include "RTSMonitoringTask.h"
class RTCreateMonitoring
{
private:
/* data */
std::shared_ptr<RTSMonitoringTask> rtsMonTask;
public:
RTCreateMonitoring(std::shared_ptr<RTSMonitoringTask> rtsMonTask) {
this->rtsMonTask = rtsMonTask;
}
int operator()(const std::string& method_, const std::string& req_type_, const std::string& resp_type_ , const std::string& request_, std::string& response_) {
//make data from json
bool res = true; //this->rtsMonTask.CreateMonitoring(id, name, samplerate, sampleperiod, downtime, status);
return res ? 0 : -1;
}
};

View File

@@ -30,8 +30,8 @@ public:
private: private:
int Copro_getFwPath(char* pathStr); int Copro_getFwPath(char* pathStr);
int Copro_setFwPath(char* pathStr); int Copro_setFwPath(const char* pathStr);
int Copro_getFwName(char* pathStr); int Copro_getFwName(char* pathStr);
int Copro_setFwName(char* nameStr); int Copro_setFwName(const char* nameStr);
}; };

View File

@@ -9,7 +9,8 @@ class RTSMonFrame
{ {
private: private:
/* data */ /* data */
std::string id; int id;
std::string name;
int samplerate; int samplerate;
int sampleperiod; int sampleperiod;
int downtime; int downtime;
@@ -17,14 +18,14 @@ private:
public: public:
RTSMonFrame(std::string id, int samplerate, int sampleperiod, int downtime) { RTSMonFrame(int id, std::string name, int samplerate, int sampleperiod, int downtime) {
this->id = id; this->id = id;
this->samplerate = samplerate; this->samplerate = samplerate;
this->sampleperiod = sampleperiod; this->sampleperiod = sampleperiod;
this->downtime = downtime; this->downtime = downtime;
} }
RTSMonFrame(std::string id) { RTSMonFrame(int id) {
this->id = id; this->id = id;
} }
@@ -37,10 +38,13 @@ public:
void Add(std::string item){ void Add(std::string item){
this->items.push_back(item); this->items.push_back(item);
} }
std::string GetId() { int GetId() {
return this->id; return this->id;
} }
std::string GetName() {
return name;
}
int GetSampleRate() { int GetSampleRate() {
return this->samplerate; return this->samplerate;
} }

View File

@@ -19,7 +19,7 @@ private:
int mFdRpmsg[2] = {-1, -1}; int mFdRpmsg[2] = {-1, -1};
RTSCoproHelper coproHelper; RTSCoproHelper coproHelper;
std::map<std::string, RTSMonFrame*> rtsMonFrames; std::map<int, RTSMonFrame*> rtsMonFrames;
pthread_t monThread; pthread_t monThread;
@@ -30,12 +30,13 @@ public:
//static RTSMonitoringTask& Instance(); //static RTSMonitoringTask& Instance();
bool Init(); bool Init();
bool CreateMonitoring(std::string id, int samplerate, int sampleperiod, int downtime, std::string status); bool CreateMonitoring(int id, std::string name, int samplerate, int sampleperiod, int downtime, std::string status);
bool LoadFW(); bool LoadFW();
bool Start(); bool Start();
bool Stop(); bool Stop();
private: private:
static void* Run(void *obj); static void* Run(void *obj);
bool Load();
}; };

View File

@@ -1,39 +0,0 @@
/*
*/
#include "../../include/RTSCoproHelper.h"
class RTSMonitoringTask
{
public:
typedef enum RTSMonitoringTaskState {
OFF= 0,
LOADED = 1,
READY = 2,
};
private:
/* data */
//lock Element
/* The file descriptor used to manage our TTY over RPMSG */
int mFdRpmsg[2] = {-1, -1};
RTSCoproHelper coproHelper;
RTSMonitoringTaskState rtsState=RTSMonitoringTaskState::OFF;
public:
RTSMonitoringTask(/* args */);
~RTSMonitoringTask();
bool Init();
bool LoadFW();
bool Start();
bool Stop();
private:
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,147 +1,22 @@
#include <string>
#include <list>
#include <iostream>
#include <thread>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <ecal/ecal.h>
#include <ecal/msg/protobuf/server.h>
#include "RTService.pb.h"
#include "../include/RTSMonitoringTask.h" #include "../include/RTSMonitoringTask.h"
#include <chrono>
using namespace boost::interprocess; #include <thread>
using namespace proto_messages;
class RTServiceImpl : public RTService
{
private:
/* data */
RTSMonitoringTask rtsMonTask;
const std::string RTSCOMMANDQUEUE = "RTSSERVICECOMMANDQUEUE";
const int MAXMSGSIZE = 250;
const int MAXMSGCOUNT = 25;
// message_queue shared_ptr<message_queue> rtsMQ;
private:
public:
virtual void createMonitoring(::google::protobuf::RpcController* /* controller_ */, const SCreateIn* request_, ::SResult* response_, ::google::protobuf::Closure* /* done_ */)
{
// print request and
std::cout << "Received request RTService / CreateMonitoring : " << request_->id() << " and " << request_->name() << std::endl << std::endl;
bool res = rtsMonTask.CreateMonitoring(request_->id(), request_->samplerate(), request_->sampleperiod(), request_->downtime(), request_->status());
// create response
response_->set_result(res);
}
// we need all parameters like id, samplerate, sampletime, downtime, later: HW-channels with the configurations
bool createMonitoring(std::string id, int samplerate, int sampleperiod, int downtime, std::string status) {
//TODO ML: add this to the M4Core
if (rtsMonTask.Init()) {
return rtsMonTask.CreateMonitoring(id, samplerate, sampleperiod, downtime, status);
}
return false;
}
bool deleteMonitoring(std::string id) {
//TODO ML: add this to the M4Core
return true;
}
std::string getMonitoringState(std::string id) {
//TODO ask the M4Core for the Monitpring Status
return "Start";
}
std::list<std::string> getMonitoringStates() {
//TODO ask the M4Core for the Monitpring Status
std::list<std::string> list;
return list;
}
bool setMonitoringStatus(std::string id, std::string status) {
//set the Status
return true;
}
void Run() {
BOOST_TRY{
//Erase previous message queue
message_queue::remove(RTSCOMMANDQUEUE.c_str());
//Create a message_queue.
message_queue rtsMQ
(create_only //only create
,RTSCOMMANDQUEUE.c_str() //name
,MAXMSGCOUNT //max message number
,MAXMSGSIZE //max message size
);
bool bCmdQueueRun = true;
unsigned int priority;
message_queue::size_type recvd_size;
boost::property_tree::ptree pt;
while (bCmdQueueRun) {
char rtsCmdbuffer [MAXMSGSIZE];
//mq.receive(buffer, sizeof(buffer), recvd_size, pri);
rtsMQ.receive(rtsCmdbuffer, sizeof(rtsCmdbuffer), recvd_size, priority);
//read json and go to cmd execution
boost::property_tree::read_json(rtsCmdbuffer,pt);
}
// //Send 100 numbers
// for(int i = 0; i < 100; ++i){
// mq.send(&i, sizeof(i), 0);
// }
}
BOOST_CATCH(interprocess_exception &ex){
std::cout << ex.what() << std::endl;
message_queue::remove(RTSCOMMANDQUEUE.c_str());
} BOOST_CATCH_END
}
};
int main(int argc, char **argv) { int main(int argc, char **argv) {
// initialize eCAL API
eCAL::Initialize(argc, argv, "RTService"); RTSMonitoringTask rtMon;
// create minimal service server
eCAL::CServiceServer rtService("RTSMonService");
// create Math service server
std::shared_ptr<RTService> rt_service = std::make_shared<RTServiceImpl>();
eCAL::protobuf::CServiceServer<RTService> math_server(rt_service);
rtMon.Init();
// idle // idle
while(eCAL::Ok()) while(1)
{ {
// sleep 100 ms // sleep 100 ms
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
// finalize eCAL API
eCAL::Finalize();
return 0; return 0;
} }

View File

@@ -20,21 +20,39 @@ RTSMonitoringTask::~RTSMonitoringTask()
{ {
} }
bool RTSMonitoringTask::Load() {
//later load the file
int id = 1;
RTSMonFrame* rtsMonFrame = new RTSMonFrame(id, "Monitoring1", 3750, 1, 4);
rtsMonFrames[id]= rtsMonFrame;
return true;
}
bool RTSMonitoringTask::Init() { bool RTSMonitoringTask::Init() {
bool ret = false;
//load the Monitorings
if (this->Load()) {
printf("CA7 : Monitorings loaded\n");
}
const std::string fwPath = "home/root/elffile/";
const std::string fwName = "zephyr_openamp_rsc_table.elf";
//check if the FWIsRunning //check if the FWIsRunning
//if (coproHelper.) if (coproHelper.Init(fwPath, fwName)) {
if (1) {
if (pthread_create( &monThread, NULL, &RTSMonitoringTask::Run, this) == 0) { if (pthread_create( &monThread, NULL, &RTSMonitoringTask::Run, this) == 0) {
printf("CA7 : virtual_tty_thread creation fails\n"); printf("CA7 : virtual_tty_thread creation fails\n");
return true; return true;
} }
} }
printf("CA7 : starting of Zephy.elf fails\n");
return false; return false;
} }
bool RTSMonitoringTask::CreateMonitoring(std::string id, int samplerate, int sampleperiod, int downtime, std::string status){ bool RTSMonitoringTask::CreateMonitoring(int id, std::string name, int samplerate, int sampleperiod, int downtime, std::string status){
this->rtsMonFrames[id] = new RTSMonFrame(id, samplerate, sampleperiod, downtime); this->rtsMonFrames[id] = new RTSMonFrame(id, name, samplerate, sampleperiod, downtime);
return true; return true;
} }
@@ -48,7 +66,7 @@ void* RTSMonitoringTask::Run(void *obj) {
int i = 1; int i = 1;
newItem = "New Item"; //new std::string("New Item: ").concat(new std::string(i)); newItem = "New Item"; //new std::string("New Item: ").concat(new std::string(i));
i++; i++;
std::map<std::string, RTSMonFrame*> rtsMonFrame = rtsMonTask->rtsMonFrames; std::map<int, RTSMonFrame*> rtsMonFrame = rtsMonTask->rtsMonFrames;
if (rtsMonFrame.size() > 0) { if (rtsMonFrame.size() > 0) {
RTSMonFrame* prtsMonFrame = rtsMonFrame.begin()->second; RTSMonFrame* prtsMonFrame = rtsMonFrame.begin()->second;

View File

@@ -1,231 +0,0 @@
/*
*/
#include "../../include/RTSMonitoring.h"
//static RTSMonitoringTask* RTMonitoringTask::rTSMonitoringTask = NULL;
RTMonitoringTask::RTMonitoringTask(/* args */)
{
}
RTSMonitoringTask::~RTSMonitoringTask()
{
}
// static RTSMonitoringTask& RTSMonitoringTask::Instance() {
// if (rTSMonitoringTask == NULL) {
// rTSMonitoringTask = new RTSMonitoringTask();
// }
// return *rTSMonitoringTask;
// }
bool RTSMonitoringTask::Init() {
//check if the FWIsRunning
//if (coproHelper.)
if (1) {
return true;
}
return false;
}
/********************************************************************************
* Threading: Run Method
*******************************************************************************/
void *virtual_tty_thread(void *arg)
{
int read0, read1;
int32_t wsize;
int nb2copy = 0;
char cmdmsg[20];
// open tty0
if (copro_openTtyRpmsg(0, 1)) {
printf("CA7 : fails to open the ttyRPMSG0\n");
return (errno * -1);
}
//system("stty -F /dev/ttyRPMGS0 -isig");
// needed to allow M4 to send any data over virtualTTY
copro_writeTtyRpmsg(0, 1, "r");
// open tty1
if (copro_openTtyRpmsg(1, 1)) {
printf("CA7 : fails to open the ttyRPMSG0\n");
return (errno * -1);
}
// needed to allow M4 to send any data over virtualTTY
copro_writeTtyRpmsg(1, 1, "r");
usleep(500000);
sprintf(cmdmsg, "B%02d", NB_BUF);
copro_writeTtyRpmsg(0, strlen(cmdmsg), cmdmsg);
while (1) {
if (mThreadCancel) break; // kill thread requested
// tty0 is used for low rate compressed data transfer (less or equal to 5MHz sampling)
read0 = copro_readTtyRpmsg(0, SAMP_SRAM_PACKET_SIZE, mByteBuffer);
if (read0 > 0) {
mNbTty0Frame++;
mNbUncompData += read0;
mNbUncompMB = mNbUncompData / 1024 / 1024;
if (mNbUncompMB != mNbPrevUncompMB) {
// a new MB has been received, update display
mNbPrevUncompMB = mNbUncompMB;
mByteBuffCpy[0] = mByteBuffer[0];
gdk_threads_add_idle (refreshUI_CB, window);
}
}
// tty1 is dedicated to trace of M4
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]);
}
}
//usleep(500);
//sleep_ms(1); // give time to UI
}
return 0;
}
/********************************************************************************
* Threading: Run Method
*******************************************************************************/
int main(int argc, char **argv)
{
int ret = 0, i, cmd;
char FwName[30];
strcpy(FIRM_NAME, "how2eldb04140.elf"); //!!! check the name ML
/* check if copro is already running */
ret = copro_isFwRunning();
if (ret) {
// check FW name
int nameLn = copro_getFwName(FwName);
if (FwName[nameLn-1] == 0x0a) {
FwName[nameLn-1] = 0x00; // replace \n by \0
}
if (strcmp(FwName, FIRM_NAME) == 0) {
printf("CA7 : %s is already running.\n", FIRM_NAME);
goto fwrunning;
}else {
printf("CA7 : wrong FW running. Try to stop it... \n");
if (copro_stopFw()) {
printf("CA7 : fails to stop firmware\n");
goto end;
}
}
}
setname:
/* set the firmware name to load */
ret = copro_setFwName(FIRM_NAME);
if (ret <= 0) {
printf("CA7 : fails to change the firmware name\n");
goto end;
}
/* start the firmware */
if (copro_startFw()) {
printf("CA7 : fails to start firmware\n");
goto end;
}
/* wait for 1 seconds the creation of the virtual ttyRPMSGx */
sleep_ms(1000);
fwrunning:
// signal(SIGINT, exit_fct); /* Ctrl-C signal */
// signal(SIGTERM, exit_fct); /* kill command */
// gettimeofday(&tval_before, NULL); // get current time
if (pthread_create( &threadTTY, NULL, virtual_tty_thread, NULL) != 0) {
printf("CA7 : virtual_tty_thread creation fails\n");
goto end;
}
// sleep_ms(500); // let tty send the DDR buffer command
// if (pthread_create( &threadSDB, NULL, sdb_thread, NULL) != 0) {
// printf("CA7 : sdb_thread creation fails\n");
// goto end;
// }
/****** new production way => use rpmsg-sdb driver to perform CMA buff allocation ******/
mMachineState = STATE_READY;
mSampFreq_Hz = 4;
mSampParmCount = 0;
// gtk_init (&argc, &argv);
// if (pthread_create( &threadUI, NULL, ui_thread, NULL) != 0) {
// printf("CA7 : ui_thread creation fails\n");
// goto end;
// }
// printf("CA7 : Entering in Main loop\n");
// while (1) {
// if (mExitRequested) break;
// if (mErrorDetected) {
// if (mMachineState >= STATE_SAMPLING_LOW) {
// virtual_tty_send_command(strlen("Exit"), "Exit");
// if (mErrorDetected == 2) printf("CA7 : ERROR in DDR Buffer order => Stop sampling!!!\n");
// //else if (mErrorDetected == 2) printf("CA7 : File System full => Stop sampling!!!\n");
// else if (mErrorDetected == 1) printf("CA7 : M4 reported DMA error !!!\n");
// mErrorDetected = 0;
// mMachineState = STATE_READY;
// gdk_threads_add_idle (refreshUI_CB, window);
// #if 0
// close_raw_file();
// #endif
// }
// }
// sleep_ms(1); // give time to UI
// }
for (i=0;i<NB_BUF;i++){
int rc = munmap(mmappedData[i], DATA_BUF_POOL_SIZE);
assert(rc == 0);
}
fMappedData = 0;
printf("CA7 : Buffers successfully unmapped\n");
end:
mThreadCancel = 1;
sleep_ms(100);
/* check if copro is already running */
if (copro_isFwRunning()) {
printf("CA7 : stop the firmware before exit\n");
copro_closeTtyRpmsg(0);
copro_closeTtyRpmsg(1);
copro_stopFw();
}
return ret;
}

View File

@@ -50,11 +50,32 @@ RTSCoproHelper::~RTSCoproHelper()
} }
int RTSCoproHelper::Init(std::string fwPath, std::string fwName) { int RTSCoproHelper::Init(std::string fwPath, std::string fwName) {
int res = 0;
if (this->Copro_isFwRunning() != 0){ if (this->Copro_isFwRunning() != 0){
return 1; //copro is already Runnibng nothing TODO
return 0;
} }
return 0; //load Firmware
//set firmware path
res = this->Copro_setFwPath(fwPath.c_str());
if (res == 0) {
res = this->Copro_setFwName(fwName.c_str());
if (res == 0) {
res = this->Copro_startFw();
if (res != 0) {
printf("CA7 : Error starting Copro, err=-%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;
} }
@@ -145,7 +166,7 @@ int RTSCoproHelper::Copro_getFwPath(char* pathStr)
return byte_read; return byte_read;
} }
int RTSCoproHelper::Copro_setFwPath(char* pathStr) int RTSCoproHelper::Copro_setFwPath(const char* pathStr)
{ {
int fd; int fd;
int result = 0; int result = 0;
@@ -186,7 +207,7 @@ int RTSCoproHelper::Copro_getFwName(char* pathStr)
return byte_read; return byte_read;
} }
int RTSCoproHelper::Copro_setFwName(char* nameStr) int RTSCoproHelper::Copro_setFwName(const char* nameStr)
{ {
int fd; int fd;
int result = 0; int result = 0;