/*
*/

#include "../../include/RTSMonitoringTask.h"
//#include "../../include/json.hpp"//((
//#include "../../include/json_fwd.hpp"
#include <string>
#include<iostream>
#include<cstring>




RTSMonitoringTask::RTSMonitoringTask(/* args */)
{
}




RTSMonitoringTask::~RTSMonitoringTask()
{
}

// bool RTSMonitoringTask::Load() {
//     //later load the file
//     int id = 1;
//     RTSMonFrame* rtsMonFrame = new RTSMonFrame(id, "Monitoring1", 3750, 1, 4, "started");
//     rtsMonFrames[id]= rtsMonFrame;
//     return true;
// }

bool RTSMonitoringTask::Init() {
    
    //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
    if (coproHelper.Init(fwPath, fwName) >= 0) {
        printf("CA7 : Init success \n");

        // if (pthread_create( &monThread, NULL, &RTSMonitoringTask::Run, this) == 0) {
        //     printf("CA7 : virtual_tty_thread creation fails\n");
        //     return true;
        // }
        return true;
    }
    printf("CA7 : starting of Zephyr.elf fails\n");
    return false;
}


// bool RTSMonitoringTask::CreateMonitoring(int id, std::string name, int samplerate, int sampleperiod, int downtime, std::string status){    
//     // this->rtsMonFrames[id] = new RTSMonFrame(id, name, samplerate, sampleperiod, downtime, status);
//     char * ch = new char[name.length() + 1];

//     // Copying the value of the string into the character array.
//     strcpy(ch, name.c_str());

//     this->coproHelper.Copro_writeTtyRpmsg(0,name.length()+1, ch);

//     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<int, 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();

//             }
//         }
//     }
// }

bool RTSMonitoringTask::Start(int samplerate, int sampleperiod, int downtime){
    // char * ch = new char[name.length() + 1];

    // // Copying the value of the string into the character array.
    // strcpy(ch, name.c_str());

    // this->coproHelper.Copro_writeTtyRpmsg(0,name.length()+1, ch);

    return true;
}

bool RTSMonitoringTask::Stop(std::string id){
    return true;
}
