aboutsummaryrefslogtreecommitdiffstats
path: root/Software/.metadata/.plugins/org.eclipse.core.resources/.history/e8/80095e9cd415001a1004f953c999aac4
stat options
Period:
Authors:

Commits per author per week (path 'Software/.metadata/.plugins/org.eclipse.core.resources/.history/e8/80095e9cd415001a1004f953c999aac4')

AuthorW27 2026W28 2026W29 2026W30 2026Total
Total00000
/************************************************************************************************************************
 * Printing.c
 * High managment logical unit of slow motors in the system ( 6 dispensers and the screw motor)
 * profile run up begins from screw homing to begin position and only then from fast motors activation.
 * when every slow motor tuches the limit switch (no matter whether its screw or dispenser)
 * an interrupt occures in the system and as long as its pushing the limit switch all the system is prevented from operation.
 * because of that the work flow with interrupts must be :
	 * design a function handle (what to do in the moment the interrupt arrives)
	 * configure the wanted interrupt in the cfg file (according to the defined port and pin and its interrupt number and the handler)
	 * enable interupt for predefined gpio in the application
	 * when the interrupt arrives the handle will be automatically called
	 * in case of the limit switches since the operation is continuess the interrupt must be disabled in order to continue the application running.
	 * then the operation is not continues (like butten pushing) there is no need in disabling the interrupts

 * Printing module is responsible for :
 	 * operating diffrent winding algorithms with predefined parameters from the UI
 	 * operating the dispensers according to predefined dispensing rate from the UI
 **************************************************************************************************************************/

////////////////////////////////State machine operation////////////////////////////////////
//the state machine operation is used to operate in runtime correct profile flow execution
//by recieved esign flow of the user from the UI
///////////////////////////////////////////////////////////////////////////////////////////
#include <Container.h>
#include <DataDef.h>
#include "include.h"
#include <ti/sysbios/knl/mailbox.h>
#include <ti/sysbios/knl/Clock.h>
#include <ti/sysbios/knl/task.h>

#include "Common/report/report.h"

#include "PMR/Printing/JobSegment.pb-c.h"
#include "PMR/Printing/JobRequest.pb-c.h"
#include "PMR/Printing/JobResponse.pb-c.h"
#include "PMR/Printing/CurrentJobRequest.pb-c.h"
#include "PMR/Printing/CurrentJobResponse.pb-c.h"
#include "PMR/Printing/ResumeCurrentJobRequest.pb-c.h"
#include "PMR/Printing/ResumeCurrentJobResponse.pb-c.h"
#include "PMR/Printing/JobStatus.pb-c.h"
#include "PMR/Printing/AbortJobRequest.pb-c.h"
#include "PMR/Printing/AbortJobResponse.pb-c.h"
#include "PMR/Hardware/Hardwaremotor.pb-c.h"
#include "PMR/Hardware/HardwareWinder.pb-c.h"
#include "PMR/common/MessageContainer.pb-c.h"
#include "Modules/General/process.h"
#include "modules/Diagnostics/Diagnostics.h"

#include "PMR/Stubs/StubJobRequest.pb-c.h"
#include "PMR/Stubs/StubJobResponse.pb-c.h"
#include "PMR/Stubs/StubAbortJobRequest.pb-c.h"
#include "PMR/Stubs/StubAbortJobResponse.pb-c.h"

#include "./printingSTM.h"
#include "modules/thread/thread_ex.h"
#include "modules/ids/ids_ex.h"
#include "Modules/heaters/heaters_ex.h"
#include "Modules/control/control.h"


#define INVALID_MSG_ID    0xFFFF

Mailbox_Handle JobmsgQ = NULL;

//static Clock_Handle JobClock;
//static Clock_Params jobclkParams;

JobEndReasonEnum JobEndReason = JOB_OK;
ErrorCode JobError_to_ErrorCode[JOB_ERRORS_MAX+1] = {ERROR_CODE__NONE,ERROR_CODE__JOB_UNSPECIFIED_ERROR,ERROR_CODE__JOB_THREAD_BREAK,ERROR_CODE__JOB_WINDER_DANCER_FAIL,
                                                      ERROR_CODE__JOB_POOLER_DANCER_FAIL,ERROR_CODE__JOB_FEEDER_DANCER_FAIL,ERROR_CODE__JOB_OUT_OF_DYE,ERROR_CODE__JOB_OTHER_ALARM,
                                                      ERROR_CODE__JOB_TEMPERATURE_ALARM,ERROR_CODE__JOB_LS_ALARM,ERROR_CODE__JOB_PRESSURE_ALARM,ERROR_CODE__JOB_CURRENT_ALARM,ERROR_CODE__JOB_MOTOR_ALARM};

#define MAX_TICKET_SIZE  10000
//char CurrentJobBuffer[MAX_TICKET_SIZE];
JobTicket *CurrentJob = NULL;//(JobTicket *)CurrentJobBuffer;
JobRequest *CurrentRequest  = NULL;
//char PreviousJobBuffer[MAX_TICKET_SIZE];
//JobTicket *PreviousJob = (JobTicket *)PreviousJobBuffer;




ModuleStateEnum PrepareWaiting[MAX_SYSTEM_MODULES] = {ModuleIdle};

/********************************************************************************************
* functions describes motor operation flow and movement state during profile execution
* used to operate in runtime correct profileflow execution
*********************************************************************************************/
static ReturnCode IdleState(void *JobDetails);
static ReturnCode ValidateState(void *JobDetails);
static ReturnCode PrepareState(void *JobDetails);
static ReturnCode PrintState(void *JobDetails);
static ReturnCode CleanState(void *JobDetails);
static ReturnCode ExitState(void *JobDetails);
/**********************************************************************
* the array and enum of JobState_t below must be in sync order
***********************************************************************/
//static ReturnCode (* state[])(void *JobDetails) = { IdleState, ValidateState, PrepareState,  PrintState, CleanState};
void AbortJob(char *Msg);


typedef enum
{
    Idle= 0,
	Validate,
	PrepareJob,
	Print,
	Clean,
	ExitJob
} JobState_t;

typedef struct
{
    JobState_t	m_sourceState;
    ReturnCode   		m_returnCode;
    JobState_t 	m_destinationState;
} Transition_t;


////////////////////////Slow Motor State////////////////////////////////////
char JobToken[36+1]={0};
bool JobAbortedByUser = false;

bool JobActive = false;
bool JobResumed = false;
////////////////////////////////////////////////////////////////////////////
void StartJob(void *JobDetails);


//********************************************************************************************************************
bool JobIsActive(void)
{
    return JobActive;
}
/********************************************************************************************************************
*function describes entry point of motor in profile execution - accelerate from stop position
*function described above used to operate motor operation flow and movement state during profile execution
*********************************************************************************************************************/
static ReturnCode IdleState(void *JobDetails)
{
    ReturnCode retcode;
    retcode = JobSuccess;

    return retcode;
}
//********************************************************************************************************************
static ReturnCode ValidateState(void *JobDetails)
{
    ReturnCode retcode;
    retcode = JobSuccess;

    return retcode;
}
//********************************************************************************************************************
bool GetHeatersPrepareWaiting(void)
{
    if (PrepareWaiting[Module_Heaters] == ModuleWaiting)
        return true;
    else
        return false;

}
//********************************************************************************************************************
static ReturnCode PrepareState(void *JobDetails)
{
    ReturnCode retcode;
    retcode = JobSuccess;
    //start (fast??) heating
    DiagnosticsStart();

    if (Configured[Module_IDS])
    {
        PrepareWaiting[Module_IDS] = ModuleWaiting;
    }
    if (Configured[Module_Thread])
    {
        PrepareWaiting[Module_Thread] = ModuleWaiting;
    }
    if (Configured[Module_Winder])
    {
        PrepareWaiting[Module_Winder] = ModuleWaiting;
    }
    if (Configured[Module_Heaters])
    {
        if (HeaterCheckReady() == false) // if heaters are in heating / cooling state we must wait for them
            PrepareWaiting[Module_Heaters] = ModuleWaiting;
    }
    //wait for fast heating to end
    //start other peripheral systems: chiller, waist handling
    //check thread type
    if (Configured[Module_IDS])
    {
        IDSPrepareState(JobDetails);
    }
/*    if (Configured[Module_Heaters])
    {
        //heaters preparation starts on process parameters handling
    }*/
    if (Configured[Module_Thread])
    {
        ThreadPrepareState(CurrentJob);
    }
    if (Configured[Module_Winder])
    {
       if( Winder_Prepare()!= OK)
       {
           SendJobProgress(0.0, 0, false, "Winder prepare failed !!!!");
       }
    }

	return retcode;
}
//********************************************************************************************************************
uint32_t PrepareReady(int ModuleId, ModuleStateEnum result)
{
    int i;
    bool ready = true;
    uint32_t retcode = 0,status = OK;

    JobMessageStruc Message;

    assert (ModuleId<MAX_SYSTEM_MODULES);
    assert (result<=ModuleFail);

    if (JobActive == false)
        return ERROR;
    if (PrepareWaiting[ModuleId] != ModuleWaiting)
    {
        LOG_ERROR (ModuleId, "Message from unrelated module!!");
        return ERROR;
    }

    PrepareWaiting[ModuleId] = result;
    if (result == ModuleFail) status = ERROR;
    for (i=0;i<MAX_SYSTEM_MODULES ;i++)
    {
        if (PrepareWaiting[i] == ModuleWaiting)
            ready = false;
    }
    if (ready == false) return OK;
    else
    {
        SendJobProgress(0.0, 0, false, "Prepare Ready");
        if (status == OK)    Message.messageId = PreparationResultsOk;
        else Message.messageId = PreparationResultsFail;
        //memcpy(Message.messageData,JobDetails,MAX_MSG_LEN);
        Message.msglen = 10;
        if (JobmsgQ != NULL)
            retcode = Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT);
    }
    return retcode;
}

//********************************************************************************************************************
static ReturnCode PrintState(void *JobDetails)
{
    ReturnCode retcode;
    retcode = JobSuccess;
    JobMessageStruc Message;
    PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData;

        Message.messageId = PrintMessage;
        PrtMessage->messageId = PrintRequest;
        Message.msglen = 10;
        if (JobmsgQ != NULL)
            Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT);

    return retcode;
}

//********************************************************************************************************************
static ReturnCode CleanState(void *JobDetails)
{
    ReturnCode retcode;
    retcode = JobSuccess;

    return retcode;
}
//********************************************************************************************************************
static ReturnCode ExitState(void *JobDetails)
{
    ReturnCode retcode;
    retcode = JobStop;

    return retcode;
}

/*static void JobClockHandle(UArg arg0)
{
    //Clock_setTimeout(JobClock, 1000);
    //Clock_start(JobClock);

}*/

//********************************************************************************************************************

/*void JobInit(void)
{
    Clock_Params_init(&jobclkParams);
    jobclkParams.period = 0;
    jobclkParams.startFlag = FALSE;
    JobClock = Clock_create(JobClockHandle, 0, &jobclkParams, NULL);
    return ;
}*/
//********************************************************************************************************************
void JobAbortFunc(MessageContainer* requestContainer)
{
    MessageContainer responseContainer;
    uint8_t* container_buffer;


    AbortJobRequest* request = abort_job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

    //AbortJob();
    AbortJobResponse response = ABORT_JOB_RESPONSE__INIT;
    responseContainer = createContainer(MESSAGE_TYPE__AbortJobResponse, requestContainer->token, false, &response, &abort_job_response__pack, &abort_job_response__get_packed_size);
    container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));

    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
    abort_job_request__free_unpacked(request,NULL);
    JobAbortedByUser = true;
    AbortJob("Job Aborted by user");
    //We keep the job request until it is done


}
double previousJobLength;
char ErrorMsg[100];
uint32_t    StubControlId = 0xFF;
double StubLengthCounter = 0,StubLength = 0,StubSpeed=0;
//********************************************************************************************************************
uint32_t SendStubJobProgress(uint32_t IfIndex, uint32_t readValue)
{
    MessageContainer responseContainer;
    uint8_t* container_buffer;
    bool done = false;
//


    //REPORT_MSG(msdid++,logmsg);
    Report("Stub Job",__FILE__,__LINE__,StubLengthCounter,RpWarning,StubLength,  StubSpeed);

    if (JobToken[0] == 0)
        return OK;


    StubJobResponse response = STUB_JOB_RESPONSE__INIT;
    JobStatus jobStatus = JOB_STATUS__INIT;

    jobStatus.has_progress = true;
    jobStatus.progress = StubLengthCounter/100;
    StubLengthCounter += StubSpeed;
    if (StubLengthCounter>=StubLength)
    {
        done = true;
        RemoveControlCallback(StubControlId, SendStubJobProgress);
    }

    jobStatus.has_currentsegmentindex = true;
    jobStatus.currentsegmentindex = 0;

    response.status = &jobStatus;
    responseContainer = createContainer(MESSAGE_TYPE__StubJobResponse, JobToken, done, &response, &stub_job_response__pack, &stub_job_response__get_packed_size);

    container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    SendChars((char*)container_buffer, container_size);
    my_free(responseContainer.data.data);

    return OK;
}

void Stub_JobRequest(MessageContainer* requestContainer)
{
    uint32_t status = OK;

    MessageContainer responseContainer;

    StubJobRequest* request = stub_job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    JobTicket *Ticket = request->jobticket;

    StubJobResponse response = STUB_JOB_RESPONSE__INIT;
    JobStatus jobStatus = JOB_STATUS__INIT;
    StubSpeed = Ticket->processparameters->dyeingspeed;
    StubLength  = Ticket->length*100;
    StubLengthCounter = 0;
    ustrncpy (JobToken, requestContainer->token,36);
    StubControlId =  AddControlCallback( SendStubJobProgress, eOneSecond,TemplateDataReadCBFunction,0,0,0);

    jobStatus.has_progress = true;
    jobStatus.progress = 0.0;
    jobStatus.has_currentsegmentindex = false;
    response.status = &jobStatus;
    responseContainer = createContainer(MESSAGE_TYPE__StubJobResponse, JobToken, false, &response, &stub_job_response__pack, &stub_job_response__get_packed_size);
    if (status!= OK)
    {
        responseContainer.error = ERROR_CODE__INVALID_PROCESS_ID;
        responseContainer.errormessage = "JOb Active or incorrect parameters";
    }
//    responseContainer.continuous = false;
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    SendChars(container_buffer, container_size);
    my_free(responseContainer.data.data);

    return ;

}
void Stub_AbortJobRequest(MessageContainer* requestContainer)
{
    uint32_t status = OK;

    MessageContainer responseContainer;

    StubAbortJobRequest* request = stub_abort_job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

    StubAbortJobResponse response = STUB_ABORT_JOB_RESPONSE__INIT;


    //RemoveControlCallback(StubControlId, SendStubJobProgress);
    StubLength  = 0;
    StubLengthCounter = 10;  //trigger job end message;

    responseContainer = createContainer(MESSAGE_TYPE__StubAbortJobResponse,  requestContainer->token, false, &response, &stub_abort_job_response__pack, &stub_abort_job_response__get_packed_size);

    responseContainer.continuous = false;
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars(container_buffer, container_size);

    return ;

}

//********************************************************************************************************************
void JobRequestFunc(MessageContainer* requestContainer)
{
    uint32_t status = NOT_SUPPORTED;
    MessageContainer responseContainer;
    uint8_t* container_buffer;
    ErrorCode error = ERROR_CODE__NONE;

    int len;
    len = usnprintf(ErrorMsg, 100, "GJM");

    JobRequest* request = job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
    if (request != NULL)
    {
        ustrncpy (JobToken, requestContainer->token,36);
        previousJobLength = 0.0;
        JobTicket *Ticket = request->jobticket;
        int TicketSize = job_ticket__get_packed_size(Ticket);
        if (TicketSize >= MAX_TICKET_SIZE)
        {
            LOG_ERROR (TicketSize, "job ticket message too long");
            status = FAILED;
            error = ERROR_CODE__BAD_CRC;
            len = usnprintf(ErrorMsg, 100, "job ticket message too long");
        }
        else
        {
            //memcpy(CurrentJob, Ticket,TicketSize);
            CurrentJob = Ticket;
            if (CurrentRequest!= NULL)
                job_request__free_unpacked(CurrentRequest,NULL);
            CurrentRequest = request;

            status  = PASSED;
            if (Ticket->processparameters)
            {
                if (HandleProcessParameters(Ticket->processparameters)!= OK)
                {
                    status = FAILED;
                    error = ERROR_CODE__INVALID_PARAMETER;
                    len = usnprintf(ErrorMsg, 100, "Hardware Parameters Not Set");
                }
            }
            if (Ticket->spool)
            {
                if (InternalWindingConfigMessage(Ticket->spool)!= OK)
                {
                    status = FAILED;
                    error = ERROR_CODE__INVALID_PARAMETER;
                    len = usnprintf(ErrorMsg, 100, "spool parameters error");
                }
            }
    //        PrepareWaiting[Module_Heaters] = ModuleWaiting;
        }
        if (status == PASSED)
        {
            Report("Job Request ",__FILE__,__LINE__,Ticket->processparameters->dyeingspeed,RpWarning,Ticket->n_segments, Ticket->intersegmentlength);
            StartJob(CurrentJob);
        }
    }
    else
        status = FAILED;

    JobResponse response = JOB_RESPONSE__INIT;
    JobStatus jobStatus = JOB_STATUS__INIT;
    if (status == PASSED)
    {
        JobResumed = false;
        len = usnprintf(ErrorMsg, 100, "Job Accepted");

        jobStatus.message =ErrorMsg;
        jobStatus.has_progress = true;
        jobStatus.progress = 0.0;
        jobStatus.has_currentsegmentindex = false;
        response.status = &jobStatus;
        response.has_canceled = false;
        responseContainer = createContainer(MESSAGE_TYPE__JobResponse, JobToken, false, &response, &job_response__pack, &job_response__get_packed_size);
        container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    }
    else
    {
        jobStatus.message = ErrorMsg;
        jobStatus.has_progress = true;
        jobStatus.progress = 0.0;
        jobStatus.has_currentsegmentindex = false;
        response.status = &jobStatus;
        response.has_canceled = true;
        response.canceled = true;
        responseContainer = createContainer(MESSAGE_TYPE__JobResponse, JobToken, true, &response, &job_response__pack, &job_response__get_packed_size);
        responseContainer.has_error = true;
        responseContainer.error = error;
        container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    }
    if (container_buffer)
    {
        size_t container_size = message_container__pack(&responseContainer, container_buffer);
        my_free(responseContainer.data.data);
        SendChars((char*)container_buffer, container_size);
        //We keep the job request until it is done
        //    job_request__free_unpacked(request,NULL);
    }
}
//********************************************************************************************************************
char logmsg[254];
char infomsg[254];
void SendJobProgress(double ProcessedLength, int SegmentId, bool done, char *Message)
{
    MessageContainer responseContainer;
    uint8_t* container_buffer;

//

    int len;
    //static msdid = 0;
    int length = (int)(ProcessedLength*100);
    //len = usnprintf(logmsg, 254, "MSG: Job Progress Length %d, Seg %d Done %d ",length,  SegmentId,  done);

    //REPORT_MSG(msdid++,logmsg);
    //Report(logmsg,__FILE__,__LINE__,SegmentId,RpWarning,SegmentId,  done);
    /*if (Message)
    {
        strcpy (infomsg,Message);
        Report(infomsg,__FILE__,__LINE__,55,RpWarning,33,  44);
    }*/

    if (JobToken[0] == 0)
        return;


    ResumeCurrentJobResponse resumeresponse = RESUME_CURRENT_JOB_RESPONSE__INIT;
    JobResponse response = JOB_RESPONSE__INIT;
    JobStatus jobStatus = JOB_STATUS__INIT;

    if (Message)
    {
        jobStatus.message = Message;
    }
    //previousJobLength =  ProcessedLength;
    jobStatus.has_progress = true;
    jobStatus.progress = TotalProcessedLength;
    jobStatus.has_currentsegmentindex = true;
    jobStatus.currentsegmentindex = SegmentId;

    if (JobResumed == true)
    {
        resumeresponse.status = &jobStatus;
        responseContainer = createContainer(MESSAGE_TYPE__ResumeCurrentJobResponse,  JobToken, done, &resumeresponse, &resume_current_job_response__pack, &resume_current_job_response__get_packed_size);
    }
    else
    {
        response.status = &jobStatus;
        responseContainer = createContainer(MESSAGE_TYPE__JobResponse, JobToken, done, &response, &job_response__pack, &job_response__get_packed_size);
    }

    container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    if (done == true)
    {
        if(JobEndReason != JOB_OK)
        {
            responseContainer.has_error = true;
            responseContainer.error = JobError_to_ErrorCode[JobEndReason];
        }
        if (JobAbortedByUser == true)
        {
            JobAbortedByUser = false;
            responseContainer.has_error = true;
            responseContainer.error = ERROR_CODE__CONTINUOUS_RESPONSE_ABORTED;
        }
    }
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars((char*)container_buffer, container_size);
}
void JobStopReporting(void)
{
    JobToken[0] = 0;
}

void AbortJob(char *Msg)
{
    //ReturnCode retcode;
    //retcode = JobSuccess;
    JobMessageStruc Message;
    PrintMessageStruc *PrtMessage = (PrintMessageStruc *)Message.messageData;

        Message.messageId = Abort;
        PrtMessage->messageId = PrintSystemFailure;
        strcpy(PrtMessage->messageData,Msg);
        Message.msglen = 10;
        if (JobmsgQ != NULL)
            Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT);
}
uint32_t    CurrentJobRequestFunc(MessageContainer* requestContainer)
{
    uint32_t status = OK;

    MessageContainer responseContainer;

    CurrentJobRequest* request = current_job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

    CurrentJobResponse response = CURRENT_JOB_RESPONSE__INIT;


    if (JobActive == true)
    {
        response.has_isjobinprogress = true;
        response.isjobinprogress = true;
        response.jobticket = CurrentJob;
    }
    else
    {
        response.has_isjobinprogress = true;
        response.isjobinprogress = false;
        response.jobticket = NULL;
    }
    responseContainer = createContainer(MESSAGE_TYPE__CurrentJobResponse,  requestContainer->token, false, &response, &current_job_response__pack, &current_job_response__get_packed_size);
    if (status!= OK)
    {
        responseContainer.error = ERROR_CODE__INVALID_PROCESS_ID;
        responseContainer.errormessage = "JOb Active or incorrect parameters";
    }
    responseContainer.continuous = false;
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars(container_buffer, container_size);

    return OK;
}
uint32_t    ResumeCurrentJobRequestFunc(MessageContainer* requestContainer)
{
    uint32_t status = OK;

    MessageContainer responseContainer;

    ResumeCurrentJobRequest* request = resume_current_job_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);

    ResumeCurrentJobResponse response = RESUME_CURRENT_JOB_RESPONSE__INIT;
    JobStatus jobStatus = JOB_STATUS__INIT;

    ustrncpy (JobToken, requestContainer->token,36);
    JobResumed = true;
    usnprintf(ErrorMsg, 100, "Job Resumeded");

    jobStatus.message =ErrorMsg;
    jobStatus.has_progress = true;
    jobStatus.progress = 0.0;
    jobStatus.has_currentsegmentindex = false;
    response.status = &jobStatus;
    response.has_canceled = false;

    responseContainer = createContainer(MESSAGE_TYPE__ResumeCurrentJobResponse,  JobToken, false, &response, &resume_current_job_response__pack, &resume_current_job_response__get_packed_size);
    if (status!= OK)
    {
        responseContainer.error = ERROR_CODE__INVALID_PROCESS_ID;
        responseContainer.errormessage = "JOb Active or incorrect parameters";
    }
    responseContainer.continuous = false;
    uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer));
    size_t container_size = message_container__pack(&responseContainer, container_buffer);
    my_free(responseContainer.data.data);
    SendChars(container_buffer, container_size);

    return OK;
}


void StartJob(void *JobDetails)
{
    JobMessageStruc Message;

    Message.messageId = JobRequestMsg;
    Message.msglen = MAX_MSG_LEN;
    if (JobmsgQ != NULL)
       Mailbox_post(JobmsgQ , &Message, BIOS_NO_WAIT);
}

/******************************************************************************
 *  ======== messageTsk ========
 *  Task for this function is created statically. See the project's .cfg file.
 *  this message task is created statically in system initialization,
 ******************************************************************************/
Void jobTask(UArg arg0, UArg arg1)
{
    JobMessageStruc Message;
    //char str[60];
    //uint16_t length;
    //Clock_setTimeout(HostKAClock, 1000);
    //Clock_start(HostKAClock);
    JobmsgQ = Mailbox_create(MAX_MSG_LEN, 20, NULL,NULL);


    while(1)
    {
        Mailbox_pend(JobmsgQ , &Message, BIOS_WAIT_FOREVER);
        switch (Message.messageId)
        {
            case JobRequestMsg:
                JobEndReason = JOB_OK;
                JobActive = true;
                /*ValidateState (CurrentJob);
                break;
            case ValidationResultsOk:*/
                PrepareState (CurrentJob);
                break;
            case ValidationResultsFail:
                //send message data as a validation error message to host
                ExitState(Message.messageData);
                break;
            case PreparationResultsOk:
                PrintState(CurrentJob);
                break;
            case PreparationResultsFail:
                //send message data as a validation error message to host
                ExitState(Message.messageData);
                break;
            case PrintMessage:
                //send message data as a validation error message to host
                PrintSTMMsgHandler(&Message);
                break;
            case PrintingResultsOk:
                JobActive = false;
                CurrentJob = NULL;
                  if (CurrentRequest!= NULL)
                      job_request__free_unpacked(CurrentRequest,NULL);
                  CurrentRequest = NULL;
                  SuspendLargeMessages = false;
                //CleanState(CurrentJob);
                break;
            case PrintingResultsFail:
                JobActive = false;
                CurrentJob = NULL;
                  if (CurrentRequest!= NULL)
                      job_request__free_unpacked(CurrentRequest,NULL);
                  CurrentRequest = NULL;
                  SuspendLargeMessages = false;
                //send message data as a validation error message to host
                ExitState(Message.messageData);
                break;
            case CleaningResultsOk:
                //send message data as a validation error message to host
                ExitState(Message.messageData);
                break;
            case CleaningResultsFail:
                //send message data as a validation error message to host
                ExitState(Message.messageData);
                break;
            case SystemFailure:
                //send message data as a validation error message to host
                ExitState(Message.messageData);
                break;
            case Abort:
                PrintSTMMsgHandler(&Message);
                break;
            default:
                break;
        }
    }
}