1st Version with ECAL
This commit is contained in:
65
CMakeLists.txt
Normal file
65
CMakeLists.txt
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
|
||||||
|
|
||||||
|
project(RTService)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Find python and Boost - both are required dependencies
|
||||||
|
#find_package(PythonLibs 3.10 REQUIRED)
|
||||||
|
find_package(Boost COMPONENTS python REQUIRED)
|
||||||
|
find_package(eCAL REQUIRED)
|
||||||
|
find_package(Protobuf REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
|
set(source_files
|
||||||
|
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/RTService.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/monitoringTask/RTSMonitoringTask.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/utilities/RTSCoproHelper.cpp
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
set(rtservice_proto
|
||||||
|
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/proto_messages/RTService.proto
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${source_files})
|
||||||
|
|
||||||
|
#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/proto_messages/ ${rtservice_proto})
|
||||||
|
|
||||||
|
#set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
|
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY /home/markus/git/vrpmdvweb/vrpmdvserver/extensions/rt_service)
|
||||||
|
set (RTSERVICEINCLUDE ./include)
|
||||||
|
|
||||||
|
|
||||||
|
file( GLOB LIB_SOURCES .src/*.cpp )
|
||||||
|
file( GLOB LIB_HEADERS lib/*.h )
|
||||||
|
# Add a shared module - modules are intended to be imported at runtime.
|
||||||
|
# - This is where you add the source files
|
||||||
|
#add_library(rt_service MODULE ./src/rt_service.cpp ./src/monitoringTask/RTSMonitoringTask.cpp ./src/utilities/RelGILLock.cpp ./src/utilities/GILLock.cpp ./src/utilities/RTSCoproHelper.cpp)
|
||||||
|
#add_executable(RTService ./src/RTService.cpp ./src/monitoringTask/RTSMonitoringTask.cpp ./src/utilities/RTSCoproHelper.cpp)
|
||||||
|
|
||||||
|
|
||||||
|
# Set up the libraries and header search paths for this target
|
||||||
|
#target_link_libraries(rt_service ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||||
|
#target_include_directories(rt_service PRIVATE ${PYTHON_INCLUDE_DIRS} ${RTSERVICEINCLUDE})
|
||||||
|
# target_link_libraries(RTService ${Boost_LIBRARIES} )
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
eCAL::core
|
||||||
|
protobuf::libprotobuf
|
||||||
|
)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE ${RTSERVICEINCLUDE})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1
__doc/.~lock.ECAL_Infos.odt#
Normal file
1
__doc/.~lock.ECAL_Infos.odt#
Normal file
@@ -0,0 +1 @@
|
|||||||
|
,markus,U2204VM,15.04.2024 12:29,file:///home/markus/.config/libreoffice/4;
|
||||||
BIN
__doc/ECAL_Infos.odt
Normal file
BIN
__doc/ECAL_Infos.odt
Normal file
Binary file not shown.
1057
__logicsample/backend.c
Normal file
1057
__logicsample/backend.c
Normal file
File diff suppressed because it is too large
Load Diff
204
__logicsample/keyboard.c
Normal file
204
__logicsample/keyboard.c
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
/*
|
||||||
|
* <Description>
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018, STMicroelectronics - All Rights Reserved
|
||||||
|
* Author: YOUR NAME <> for STMicroelectronics.
|
||||||
|
*
|
||||||
|
* License type: GPLv2
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 as published by
|
||||||
|
* the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/gpio.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
#define USER_GPIO_OFFSET 13
|
||||||
|
|
||||||
|
int running = 0;
|
||||||
|
int gpio13_pressed = 0;
|
||||||
|
int gpio14_pressed = 0;
|
||||||
|
static pthread_t thread_ioctl1;
|
||||||
|
static pthread_t thread_ioctl2;
|
||||||
|
pthread_mutex_t keybMutex;
|
||||||
|
struct gpioevent_request ereq1, ereq2;
|
||||||
|
struct gpioevent_data event1, event2;
|
||||||
|
|
||||||
|
static void sleep_ms(int milliseconds)
|
||||||
|
{
|
||||||
|
usleep(milliseconds * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***************** configure_userbutton ***************************/
|
||||||
|
int configure_userbutton(struct gpioevent_request *ereq, int offset)
|
||||||
|
{
|
||||||
|
char chrdev_name[20];
|
||||||
|
int fd,ret;
|
||||||
|
|
||||||
|
strcpy(chrdev_name, "/dev/gpiochip0");
|
||||||
|
|
||||||
|
/* Open device: gpiochip0 for GPIO bank A */
|
||||||
|
fd = open(chrdev_name, 0);
|
||||||
|
|
||||||
|
if (fd == -1) {
|
||||||
|
ret = -errno;
|
||||||
|
fprintf(stderr, "Failed to open %s\n", chrdev_name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* request GPIO line for Button activation*/
|
||||||
|
memset(ereq,0,sizeof(struct gpioevent_request));
|
||||||
|
ereq->lineoffset = offset;
|
||||||
|
ereq->handleflags = GPIOHANDLE_REQUEST_INPUT;
|
||||||
|
ereq->eventflags = GPIOEVENT_EVENT_FALLING_EDGE;
|
||||||
|
sprintf(ereq->consumer_label, "User PA%02d", offset);
|
||||||
|
|
||||||
|
ret = ioctl(fd, GPIO_GET_LINEEVENT_IOCTL, ereq);
|
||||||
|
if (ret == -1) {
|
||||||
|
ret = -errno;
|
||||||
|
fprintf(stderr, "Failed to issue GET event1 IOCTL (%d)\n",ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ioctl1_thread(void *arg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
while (1) {
|
||||||
|
/* read User button input event1 */
|
||||||
|
ret = read(ereq1.fd, &event1, sizeof(event1));
|
||||||
|
if (ret == -1) {
|
||||||
|
if (errno == -EAGAIN) {
|
||||||
|
fprintf(stderr, "nothing available\n");
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
ret = -errno;
|
||||||
|
fprintf(stderr, "Failed to read event1 (%d)\n",ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret != sizeof(event1)) {
|
||||||
|
fprintf(stderr, "Reading event1 failed\n");
|
||||||
|
ret = -EIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* process the event1 received */
|
||||||
|
switch (event1.id) {
|
||||||
|
case GPIOEVENT_EVENT_FALLING_EDGE:
|
||||||
|
printf("GPIO13 GPIOEVENT_EVENT_FALLING_EDGE\n");
|
||||||
|
pthread_mutex_lock(&keybMutex);
|
||||||
|
gpio13_pressed = 1;
|
||||||
|
pthread_mutex_unlock(&keybMutex);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stdout, "unknown event1\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *ioctl2_thread(void *arg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
while (1) {
|
||||||
|
/* read User button input event2 */
|
||||||
|
ret = read(ereq2.fd, &event2, sizeof(event2));
|
||||||
|
if (ret == -1) {
|
||||||
|
if (errno == -EAGAIN) {
|
||||||
|
fprintf(stderr, "nothing available\n");
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
ret = -errno;
|
||||||
|
fprintf(stderr, "Failed to read event2 (%d)\n",ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ret != sizeof(event2)) {
|
||||||
|
fprintf(stderr, "Reading event2 failed\n");
|
||||||
|
ret = -EIO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* process the event2 received */
|
||||||
|
switch (event2.id) {
|
||||||
|
case GPIOEVENT_EVENT_FALLING_EDGE:
|
||||||
|
printf("GPIO14 GPIOEVENT_EVENT_FALLING_EDGE\n");
|
||||||
|
pthread_mutex_lock(&keybMutex);
|
||||||
|
gpio14_pressed = 1;
|
||||||
|
pthread_mutex_unlock(&keybMutex);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stdout, "unknown event2\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int ret=0;
|
||||||
|
|
||||||
|
printf("read keyb event thread\n");
|
||||||
|
|
||||||
|
if ((getuid ()) != 0) {
|
||||||
|
fprintf(stderr, "You are not root! This may not work...\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* configure USER button */
|
||||||
|
if (configure_userbutton(&ereq1, 14) < 0){
|
||||||
|
perror("GPIO_A14 export issue");
|
||||||
|
goto quit;
|
||||||
|
}
|
||||||
|
if (configure_userbutton(&ereq2, 13) < 0){
|
||||||
|
perror("GPIO_A13 export issue");
|
||||||
|
goto quit;
|
||||||
|
}
|
||||||
|
if (pthread_create( &thread_ioctl1, NULL, ioctl1_thread, NULL) != 0) {
|
||||||
|
printf("greio_receiver_thread creation fails\n");
|
||||||
|
goto quit;
|
||||||
|
}
|
||||||
|
if (pthread_create( &thread_ioctl2, NULL, ioctl2_thread, NULL) != 0) {
|
||||||
|
printf("greio_receiver_thread creation fails\n");
|
||||||
|
goto quit;
|
||||||
|
}
|
||||||
|
pthread_mutex_init(&keybMutex, NULL);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
sleep_ms(1);
|
||||||
|
pthread_mutex_lock(&keybMutex);
|
||||||
|
if (gpio13_pressed) {
|
||||||
|
gpio13_pressed = 0;
|
||||||
|
system("/usr/local/demo/la/run_la.sh");
|
||||||
|
} else if (gpio14_pressed) {
|
||||||
|
gpio14_pressed = 0;
|
||||||
|
system("/usr/local/demo/la/run_la.sh");
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&keybMutex);
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
|
||||||
|
quit:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
64
__logicsample/testMQ.c
Normal file
64
__logicsample/testMQ.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#include <boost/interprocess/ipc/message_queue.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
namespace bip = boost::interprocess;
|
||||||
|
using MQ = bip::message_queue;
|
||||||
|
|
||||||
|
template<size_t N>
|
||||||
|
static inline void safe_copy(std::array<char, N>& dst, std::string_view src) {
|
||||||
|
std::copy_n(src.data(), std::min(src.size(), N), dst.data());
|
||||||
|
dst.back() = 0; // make sure of NUL termination
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AccessQueue {
|
||||||
|
std::array<char, 64> name{0};
|
||||||
|
std::array<char, 64> action{0};
|
||||||
|
|
||||||
|
AccessQueue(std::string_view n = "", std::string_view a = "") {
|
||||||
|
safe_copy(name, n);
|
||||||
|
safe_copy(action, a);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert(std::is_standard_layout_v<AccessQueue>);
|
||||||
|
|
||||||
|
struct X {
|
||||||
|
void send() {
|
||||||
|
AccessQueue packet("asd", "vsq");
|
||||||
|
try {
|
||||||
|
mq.send(&packet, sizeof(packet), 0);
|
||||||
|
} catch(std::exception const & ex) {
|
||||||
|
std::cout << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AccessQueue receive() {
|
||||||
|
AccessQueue retval;
|
||||||
|
|
||||||
|
report();
|
||||||
|
try {
|
||||||
|
unsigned int priority;
|
||||||
|
MQ::size_type recvd_size;
|
||||||
|
mq.try_receive(&retval, sizeof(AccessQueue), recvd_size, priority);
|
||||||
|
} catch(std::exception const & ex) {
|
||||||
|
std::cout << ex.what() << std::endl;
|
||||||
|
}
|
||||||
|
report();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
void report() {
|
||||||
|
std::cout << mq.get_num_msg() << "\t" << mq.get_max_msg_size() << "\t" << mq.get_max_msg() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
MQ mq { bip::open_or_create, "somequeue", 10, sizeof(AccessQueue) };
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
X tryit;
|
||||||
|
tryit.send();
|
||||||
|
auto const& [name, action] = tryit.receive();
|
||||||
|
|
||||||
|
std::cout << std::quoted(name.data()) << " " << std::quoted(action.data()) << std::endl;
|
||||||
|
}
|
||||||
21
include/GILLock.h
Normal file
21
include/GILLock.h
Normal 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;
|
||||||
|
};
|
||||||
37
include/RTSCoproHelper.h
Normal file
37
include/RTSCoproHelper.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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(char* pathStr);
|
||||||
|
int Copro_getFwName(char* pathStr);
|
||||||
|
int Copro_setFwName(char* nameStr);
|
||||||
|
|
||||||
|
};
|
||||||
60
include/RTSMonFrame.h
Normal file
60
include/RTSMonFrame.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
|
||||||
|
class RTSMonFrame
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/* data */
|
||||||
|
std::string id;
|
||||||
|
int samplerate;
|
||||||
|
int sampleperiod;
|
||||||
|
int downtime;
|
||||||
|
std::list<std::string> items;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RTSMonFrame(std::string id, int samplerate, int sampleperiod, int downtime) {
|
||||||
|
this->id = id;
|
||||||
|
this->samplerate = samplerate;
|
||||||
|
this->sampleperiod = sampleperiod;
|
||||||
|
this->downtime = downtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
RTSMonFrame(std::string id) {
|
||||||
|
this->id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
RTSMonFrame(RTSMonFrame& rtsMonFrameCopy) {
|
||||||
|
this->id = rtsMonFrameCopy.GetId();
|
||||||
|
}
|
||||||
|
|
||||||
|
~RTSMonFrame();
|
||||||
|
|
||||||
|
void Add(std::string item){
|
||||||
|
this->items.push_back(item);
|
||||||
|
}
|
||||||
|
std::string GetId() {
|
||||||
|
return this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetSampleRate() {
|
||||||
|
return this->samplerate;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetSamplePeriod(){
|
||||||
|
return this->sampleperiod;
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetDownTime(){
|
||||||
|
return this->downtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<std::string>& GetItems() {
|
||||||
|
return this->items;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
41
include/RTSMonitoringTask.h
Normal file
41
include/RTSMonitoringTask.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
#include "RTSCoproHelper.h"
|
||||||
|
#include "RTSMonFrame.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class RTSMonitoringTask
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/* data */
|
||||||
|
//lock Element
|
||||||
|
|
||||||
|
/* The file descriptor used to manage our TTY over RPMSG */
|
||||||
|
int mFdRpmsg[2] = {-1, -1};
|
||||||
|
RTSCoproHelper coproHelper;
|
||||||
|
|
||||||
|
std::map<std::string, RTSMonFrame*> rtsMonFrames;
|
||||||
|
|
||||||
|
pthread_t monThread;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RTSMonitoringTask(/* args */);
|
||||||
|
~RTSMonitoringTask();
|
||||||
|
|
||||||
|
//static RTSMonitoringTask& Instance();
|
||||||
|
bool Init();
|
||||||
|
bool CreateMonitoring(std::string id, int samplerate, int sampleperiod, int downtime, std::string status);
|
||||||
|
bool LoadFW();
|
||||||
|
bool Start();
|
||||||
|
bool Stop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void* Run(void *obj);
|
||||||
|
|
||||||
|
};
|
||||||
39
include/RTSMonitoringTask.h.old
Normal file
39
include/RTSMonitoringTask.h.old
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
#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:
|
||||||
|
|
||||||
|
};
|
||||||
19
include/RelGILLock.h
Normal file
19
include/RelGILLock.h
Normal 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;
|
||||||
|
};
|
||||||
24766
include/json.hpp
Normal file
24766
include/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
176
include/json_fwd.hpp
Normal file
176
include/json_fwd.hpp
Normal 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_
|
||||||
2040
protobuf/RTService.pb.cc
Normal file
2040
protobuf/RTService.pb.cc
Normal file
File diff suppressed because it is too large
Load Diff
2130
protobuf/RTService.pb.h
Normal file
2130
protobuf/RTService.pb.h
Normal file
File diff suppressed because it is too large
Load Diff
149
src/RTService.cpp
Normal file
149
src/RTService.cpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#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"
|
||||||
|
|
||||||
|
using namespace boost::interprocess;
|
||||||
|
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) {
|
||||||
|
// initialize eCAL API
|
||||||
|
eCAL::Initialize(argc, argv, "RTService");
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// idle
|
||||||
|
while(eCAL::Ok())
|
||||||
|
{
|
||||||
|
// sleep 100 ms
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
// finalize eCAL API
|
||||||
|
eCAL::Finalize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
76
src/monitoringTask/RTSMonitoringTask.cpp
Normal file
76
src/monitoringTask/RTSMonitoringTask.cpp
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../../include/RTSMonitoringTask.h"
|
||||||
|
#include "../../include/json.hpp"
|
||||||
|
#include "../../include/json_fwd.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RTSMonitoringTask::RTSMonitoringTask(/* args */)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RTSMonitoringTask::~RTSMonitoringTask()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RTSMonitoringTask::Init() {
|
||||||
|
//check if the FWIsRunning
|
||||||
|
//if (coproHelper.)
|
||||||
|
if (1) {
|
||||||
|
if (pthread_create( &monThread, NULL, &RTSMonitoringTask::Run, this) == 0) {
|
||||||
|
printf("CA7 : virtual_tty_thread creation fails\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool RTSMonitoringTask::CreateMonitoring(std::string id, int samplerate, int sampleperiod, int downtime, std::string status){
|
||||||
|
this->rtsMonFrames[id] = new RTSMonFrame(id, samplerate, sampleperiod, downtime);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void* RTSMonitoringTask::Run(void *obj) {
|
||||||
|
|
||||||
|
RTSMonitoringTask* rtsMonTask = static_cast<RTSMonitoringTask*>(obj);
|
||||||
|
std::string newItem;
|
||||||
|
while (1) {
|
||||||
|
// genrate data
|
||||||
|
int i = 1;
|
||||||
|
newItem = "New Item"; //new std::string("New Item: ").concat(new std::string(i));
|
||||||
|
i++;
|
||||||
|
std::map<std::string, RTSMonFrame*> rtsMonFrame = rtsMonTask->rtsMonFrames;
|
||||||
|
if (rtsMonFrame.size() > 0) {
|
||||||
|
RTSMonFrame* prtsMonFrame = rtsMonFrame.begin()->second;
|
||||||
|
|
||||||
|
prtsMonFrame->Add(newItem);
|
||||||
|
if (i == 200) {
|
||||||
|
//make a dictonary for the rtsMonFrame id, samplerate, sampleperiod, downtime
|
||||||
|
// boost::python::dict rtsMonFrameDict;
|
||||||
|
// rtsMonFrameDict["id"] = prtsMonFrame->GetId();
|
||||||
|
// rtsMonFrameDict["samplerate"] = prtsMonFrame->GetSampleRate();
|
||||||
|
// rtsMonFrameDict["sampleperiod"] = prtsMonFrame->GetSamplePeriod();
|
||||||
|
// rtsMonFrameDict["downtime"] = prtsMonFrame->GetDownTime();
|
||||||
|
// //make a dictonary for the sampleItems
|
||||||
|
// boost::python::list rtsMonItemsList;
|
||||||
|
// auto items = prtsMonFrame->GetItems();
|
||||||
|
// for (auto iter = items.begin(); iter!= items.end(); ++iter)
|
||||||
|
// {
|
||||||
|
// rtsMonItemsList.append(*iter);
|
||||||
|
// }
|
||||||
|
// rtsMonFrameDict["items"]= rtsMonItemsList;
|
||||||
|
// rtsMonTask->callback();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
231
src/monitoringTask/RTSMonitoringTask.cpp.old
Normal file
231
src/monitoringTask/RTSMonitoringTask.cpp.old
Normal file
@@ -0,0 +1,231 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
74
src/proto_messages/RTService.proto
Normal file
74
src/proto_messages/RTService.proto
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/* ========================= LICENSE =================================
|
||||||
|
*
|
||||||
|
* Copyright (C) 2024 Markus Lehr
|
||||||
|
*
|
||||||
|
+ closed License property of Markus Lehr
|
||||||
|
*
|
||||||
|
* ========================= LICENSE =================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
option cc_generic_services = true;
|
||||||
|
|
||||||
|
package proto_messages;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////
|
||||||
|
// RT Service
|
||||||
|
///////////////////////////////////////////////////////
|
||||||
|
message SCreateIn
|
||||||
|
{
|
||||||
|
string name = 1;
|
||||||
|
string id = 2;
|
||||||
|
int64 samplerate = 3;
|
||||||
|
int64 sampleperiod = 4;
|
||||||
|
int64 downtime = 5;
|
||||||
|
string status = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SDeleteIn
|
||||||
|
{
|
||||||
|
string id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SMonStateIn
|
||||||
|
{
|
||||||
|
string id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SMonStatesIn
|
||||||
|
{
|
||||||
|
string query = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message SSetMonStateIn
|
||||||
|
{
|
||||||
|
string id = 1;
|
||||||
|
string status = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
message SResult
|
||||||
|
{
|
||||||
|
bool result = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
message SStateResult
|
||||||
|
{
|
||||||
|
repeated string result = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
service RTService
|
||||||
|
{
|
||||||
|
rpc CreateMonitoring(SCreateIn) returns (SResult);
|
||||||
|
rpc DeleteMonitoring (SDeleteIn) returns (SResult);
|
||||||
|
rpc GetMonitoringState (SMonStateIn) returns (SResult);
|
||||||
|
rpc GetMonitoringStates (SMonStatesIn) returns (SStateResult);
|
||||||
|
rpc SetMonitoringState (SSetMonStateIn) returns (SResult);
|
||||||
|
|
||||||
|
}
|
||||||
86
src/rt_service.cpp
Normal file
86
src/rt_service.cpp
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#include <boost/python.hpp>
|
||||||
|
#include <boost/python/extract.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include "../include/RTSMonitoringTask.h"
|
||||||
|
#include "../include/RelGILLock.h"
|
||||||
|
//#include "../include/GILLock.h"
|
||||||
|
//#include <sstream>
|
||||||
|
//#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct RTService
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/* data */
|
||||||
|
|
||||||
|
RTSMonitoringTask rtsMonTask;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// RT_Service(/* args */) {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ~RT_Service() {}
|
||||||
|
|
||||||
|
// 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, boost::python::object callback) {
|
||||||
|
PyRelinquishGIL scoped;
|
||||||
|
//TODO ML: add this to the M4Core
|
||||||
|
if (rtsMonTask.Init()) {
|
||||||
|
return rtsMonTask.CreateMonitoring(id, samplerate, sampleperiod, downtime, status, callback);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deleteMonitoring(std::string id) {
|
||||||
|
//TODO ML: add this to the M4Core
|
||||||
|
PyRelinquishGIL scoped;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getMonitoringState(std::string id) {
|
||||||
|
//TODO ask the M4Core for the Monitpring Status
|
||||||
|
PyRelinquishGIL scoped;
|
||||||
|
return "Start";
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::python::list getMonitoringStates() {
|
||||||
|
//TODO ask the M4Core for the Monitpring Status
|
||||||
|
PyRelinquishGIL scoped;
|
||||||
|
boost::python::list list;
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool setMonitoringStatus(std::string id, std::string status) {
|
||||||
|
//set the Status
|
||||||
|
PyRelinquishGIL scoped;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using namespace boost::python;
|
||||||
|
|
||||||
|
BOOST_PYTHON_MODULE(rt_service)
|
||||||
|
{
|
||||||
|
class_<RTService>("RT_Service")
|
||||||
|
.def("createMonitoring", &RTService::createMonitoring)
|
||||||
|
.def("getMonitoringStatus", &RTService::getMonitoringState)
|
||||||
|
.def("getAllMonitoringStat", &RTService::getMonitoringStates)
|
||||||
|
.def("setMonitoringStatus", &RTService::setMonitoringStatus)
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//examples
|
||||||
|
// long l = len(msgs);
|
||||||
|
// std::stringstream ss;
|
||||||
|
// for (long i = 0; i<l; ++i) {
|
||||||
|
// if (i>0) ss << ", ";
|
||||||
|
// std::string s = boost::python::extract<std::string>(msgs[i]);
|
||||||
|
// ss << s;
|
||||||
|
// }
|
||||||
|
// mMsg = ss.str();
|
||||||
14
src/utilities/GILLock.cpp
Normal file
14
src/utilities/GILLock.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
#include "../../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);
|
||||||
|
}
|
||||||
298
src/utilities/RTSCoproHelper.cpp
Normal file
298
src/utilities/RTSCoproHelper.cpp
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
/*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RTSCoproHelper::RTSCoproHelper(/* args */)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RTSCoproHelper::~RTSCoproHelper()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int RTSCoproHelper::Init(std::string fwPath, std::string fwName) {
|
||||||
|
if (this->Copro_isFwRunning() != 0){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************************
|
||||||
|
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(char* pathStr)
|
||||||
|
{
|
||||||
|
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/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(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, 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);
|
||||||
|
if (mFdRpmsg[ttyNb%2] < 0) {
|
||||||
|
printf("CA7 : Error opening ttyRPMSG%d, err=-%d\n", ttyNb%2, errno);
|
||||||
|
return (errno * -1);
|
||||||
|
}
|
||||||
|
#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", 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);
|
||||||
|
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
|
||||||
|
*********************************************************************************/
|
||||||
16
src/utilities/RelGILLock.cpp
Normal file
16
src/utilities/RelGILLock.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
#include "../../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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user