/****************************************************************************
Module
PrintService.c
Revision
1.0.1
Description
This is a template file for implementing a simple service under the
Gen2 Events and Services Framework.
Notes
History
When Who What/Why
-------------- --- --------
01/16/12 09:58 jec began conversion from TemplateFSM.c
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "PrintService.h"
#include "LEDService.h"
#include "dbprintf.h"
#include <stdio.h>
#include <string.h>
/*----------------------------- Module Defines ----------------------------*/
#define HALF_SEC 500
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this service.They should be functions
relevant to the behavior of this service
*/
/*---------------------------- Module Variables ---------------------------*/
// with the introduction of Gen2, we need a module level Priority variable
static uint8_t MyPriority;
/*------------------------------ Module Code ------------------------------*/
/****************************************************************************
Function
InitPrintService
Parameters
uint8_t : the priorty of this service
Returns
bool, false if error in initialization, true otherwise
Description
Saves away the priority, and does any
other required initialization for this service
Notes
Author
J. Edward Carryer, 01/16/12, 10:00
****************************************************************************/
bool InitPrintService(uint8_t Priority)
{
ES_Event_t ThisEvent;
MyPriority = Priority;
DB_printf("Print Service Initialized\r\n");
// post the initial transition event
ThisEvent.EventType = ES_INIT;
if (ES_PostToService(MyPriority, ThisEvent) == true)
{
return true;
}
else
{
return false;
}
}
/****************************************************************************
Function
PostPrintService
Parameters
EF_Event_t ThisEvent ,the event to post to the queue
Returns
bool false if the Enqueue operation failed, true otherwise
Description
Posts an event to this state machine's queue
Notes
Author
J. Edward Carryer, 10/23/11, 19:25
****************************************************************************/
bool PostPrintService(ES_Event_t ThisEvent)
{
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
Function
RunPrintService
Parameters
ES_Event_t : the event to process
Returns
ES_Event, ES_NO_EVENT if no error ES_ERROR otherwise
Description
add your description here
Notes
Author
J. Edward Carryer, 01/15/12, 15:23
****************************************************************************/
ES_Event_t RunPrintService(ES_Event_t ThisEvent)
{
ES_Event_t ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no
static int i = 0;
static char toPrint[20] = "";
switch (ThisEvent.EventType)
{
case ES_INIT:
{
DB_printf("\rES_INIT received in Service %d\r\n", MyPriority);
ES_Timer_StopTimer(PRINT_TIMER);
}
break;
case ES_PRINT: // re-start timer & announce
{
ES_Timer_InitTimer(PRINT_TIMER, HALF_SEC);
//DB_printf("ES_PRINT\r\n");
strncpy(toPrint, ThisEvent.EventPrint, sizeof(toPrint) - 1);
toPrint[sizeof(toPrint) - 1] = '\0';
}
break;
case ES_TIMEOUT:
{
ES_Timer_InitTimer(PRINT_TIMER, HALF_SEC);
//DB_printf("Timeout\r\n");
ThisEvent.EventType = ES_MESSAGE;
ThisEvent.EventParam = toPrint[i];
PostLEDService(ThisEvent);
if (i < strlen(toPrint) - 1){
i++;
} else {
i = 0;
}
}
break;
default:
{}
break;
}
return ReturnEvent;
}
/***************************************************************************
private functions
***************************************************************************/
/*------------------------------- Footnotes -------------------------------*/
/*------------------------------ End of file ------------------------------*/