Added Parse_KEvent_ID() #14
3 changed files with 38 additions and 4 deletions
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "SystemK.h"
|
||||
#include "Command_Mapping.h"
|
||||
|
|
@ -77,3 +79,33 @@ portBASE_TYPE Receive_KEvent(KEvent_T *event)
|
|||
{
|
||||
return xQueueReceive(xQueueEvents, event, 0);
|
||||
}
|
||||
|
||||
SystemKResult_T Parse_KEvent_ID(const char *str, KEvent_T *event)
|
||||
{
|
||||
char *end;
|
||||
errno = 0;
|
||||
long val = strtol(str, &end, 10);
|
||||
|
||||
if (errno != 0 || end == str || *end != '\0')
|
||||
{
|
||||
event->ID = KEVENT_UNSUCCESSFUL_SYSTEMK_RESULT;
|
||||
event->Data = (void *)SYSTEMK_RESULT_COULD_NOT_PARSE_STRING;
|
||||
}
|
||||
else if (val >= KEVENT_IS_OUT_OF_RANGE)
|
||||
{
|
||||
event->ID = KEVENT_UNSUCCESSFUL_SYSTEMK_RESULT;
|
||||
event->Data = (void *)SYSTEMK_RESULT_OVERFLOW;
|
||||
}
|
||||
else if (val < KEVENT_NO_EVENT)
|
||||
{
|
||||
event->ID = KEVENT_UNSUCCESSFUL_SYSTEMK_RESULT;
|
||||
event->Data = (void *)SYSTEMK_RESULT_OVERFLOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
event->ID = (KEvent_ID_T) val;
|
||||
event->Data = (void *)SYSTEMK_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
return (SystemKResult_T)event->Data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef EVENTS_H
|
||||
#define EVENTS_H
|
||||
#ifndef KEVENTS_H
|
||||
|
|
||||
#define KEVENTS_H
|
||||
|
||||
//! Event identifiers used by the SystemK.
|
||||
typedef enum
|
||||
|
|
@ -103,5 +103,6 @@ void Init_KEvents(void);
|
|||
void Post_KEvent(KEvent_T *event);
|
||||
void Post_KEvent_From_ISR(KEvent_T *event, portBASE_TYPE *xHigherPriorityTaskWoken);
|
||||
portBASE_TYPE Receive_KEvent(KEvent_T *event);
|
||||
SystemKResult_T Parse_KEvent_ID(const char *str, KEvent_T *event);
|
||||
|
||||
#endif // EVENTS_H
|
||||
#endif // KEVENTS_H
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ typedef enum
|
|||
SYSTEMK_RESULT_WRITE_FAILED,
|
||||
SYSTEMK_RESULT_OVERFLOW,
|
||||
SYSTEMK_RESULT_UNDERFLOW,
|
||||
SYSTEMK_RESULT_EVENT_NOT_HANDLED
|
||||
SYSTEMK_RESULT_EVENT_NOT_HANDLED,
|
||||
SYSTEMK_RESULT_COULD_NOT_PARSE_STRING
|
||||
} SystemKResult_T;
|
||||
|
||||
#endif // RESULTS_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue
The #include guard should match the filename.