Added Parse_KEvent_ID() (#14)
This is a convenience function for console commands. Co-authored-by: Joe Kearney <joe@clubk.club> Reviewed-on: #14
This commit is contained in:
parent
daa1a2a1ec
commit
5aeffbcbc9
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue