Reworked BLE according to v0.11 of the KTag Beacon Specification (#2)

This was done to support the new KTag Konfigurator app, which Jack created for his Senior Design project.

Co-authored-by: Joe Kearney <joe@clubk.club>
Reviewed-on: #2
This commit is contained in:
Joe Kearney 2025-06-08 21:52:29 +00:00
parent 4fe072f2d3
commit bfcdf4c354
26 changed files with 917 additions and 128 deletions

View file

@ -22,13 +22,6 @@
/* Include Files */
#include "SystemK.h"
const StateActivity_T STATE_DEFAULT_Activities =
{
.Entry = NULL,
.Do = NULL,
.Exit = NULL
};
//! Activities for the top-level state machine.
/*!
* This array is indexed by #StateID_T (except there is no entry for
@ -37,7 +30,6 @@ const StateActivity_T STATE_DEFAULT_Activities =
*/
static const StateActivity_T * Activities[] =
{
&STATE_DEFAULT_Activities,
&STATE_INITIALIZING_Activities,
&STATE_REPROGRAMMING_Activities,
&STATE_CONFIGURING_Activities,
@ -62,6 +54,11 @@ static StateMachineContext_T Context =
.Time_At_State_Entry_In_Ticks = 0,
};
StateMachineContext_T* GetContext()
{
return &Context;
}
TaskHandle_t State_Machine_Task_Handle;
void State_Machine_Task(void * pvParameters)
@ -131,3 +128,70 @@ void ProcessUnhandledEvent(KEvent_T * Event)
break;
}
}
void HandleBLEEventPacket(const BLE_EventPacket_T *const packet, StateMachineContext_T *context)
{
if (BLE_IsBLEPacketForMe(packet->target_BD_ADDR))
{
if (BLE_IsPacketNew(packet->BD_ADDR, BLE_PACKET_TYPE_EVENT, packet->event_number))
{
if (packet->event_ID == BLE_EVENT_CONFIGURED)
{
if (context->States.Current_State == STATE_CONFIGURING)
{
static KEvent_T Event =
{
.ID = KEVENT_BLE_EVENT_RECEIVED,
.Data = (void *)BLE_EVENT_CONFIGURED
};
Transition_For_Event(context, STATE_READY, &Event);
}
}
else if (packet->event_ID == BLE_EVENT_CONFIGURE)
{
if (context->States.Current_State == STATE_READY)
{
static KEvent_T Event =
{
.ID = KEVENT_BLE_EVENT_RECEIVED,
.Data = (void *)BLE_EVENT_CONFIGURE
};
Transition_For_Event(context, STATE_CONFIGURING, &Event);
}
}
else if (packet->event_ID == BLE_EVENT_WRAPUP_COMPLETE)
{
if (context->States.Current_State == STATE_WRAPPING_UP)
{
StateID_T next_state = (StateID_T)packet->event_data;
if (next_state < STATE_IS_OUT_OF_RANGE)
{
static KEvent_T Event =
{
.ID = KEVENT_BLE_EVENT_RECEIVED,
.Data = (void *)BLE_EVENT_WRAPUP_COMPLETE
};
Transition_For_Event(context, next_state, &Event);
}
else
{
KLOG_WARN("STATE", "Received a BLE Wrapup Complete event with an invalid Next State!");
}
}
}
else if (packet->event_ID == BLE_EVENT_GAME_OVER)
{
if ((context->States.Current_State == STATE_PLAYING__INTERACTING) ||
(context->States.Current_State == STATE_PLAYING__TAGGED_OUT))
{
KEvent_T game_over_event = { .ID = KEVENT_GAME_OVER, .Data = (void *)0x00 };
Post_KEvent(&game_over_event);
}
}
}
}
BLE_FreePacketBuffer((BLE_GenericPacketType_T *)packet);
}