1st Version with ECAL

This commit is contained in:
2024-04-17 09:34:52 +02:00
commit 8d2fee2406
24 changed files with 31664 additions and 0 deletions

View 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();
}
}
}
}

View 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;
}