Blumen lumen now reads packet headers before attempting to interpret them

This commit is contained in:
PS 2021-02-28 16:58:22 -08:00
parent 64879c0e2d
commit f8d0f904ce
2 changed files with 58 additions and 21 deletions

View File

@ -5,6 +5,7 @@
//
#ifndef BLUMEN_LUMEN_CPP
internal void
BlumenLumen_MicListenJob(gs_thread_context* Ctx, u8* UserData)
{
@ -192,7 +193,12 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
while (BLState->MicPacketBuffer.ReadHead != BLState->MicPacketBuffer.WriteHead)
{
gs_data PacketData = BLState->MicPacketBuffer.Values[BLState->MicPacketBuffer.ReadHead++];
microphone_packet Packet = *(microphone_packet*)PacketData.Memory;
u8 PacketType = PacketData.Memory[0];
switch (PacketType) {
case PacketType_PatternCommand:
{
microphone_packet Packet = *(microphone_packet*)(PacketData.Memory + 1);
u32 NameLen = CStringLength(Packet.AnimationFileName);
if (StringEqualsCharArray(BlueString.ConstString, Packet.AnimationFileName, NameLen))
@ -212,6 +218,24 @@ BlumenLumen_CustomUpdate(gs_data UserData, app_state* State, context* Context)
{
BLState->MicPacketBuffer.ReadHead = 0;
}
OutputDebugStringA("Received Pattern Packet");
}break;
case PacketType_MotorState:
{
motor_packet Packet = *(motor_packet*)(PacketData.Memory + 1);
OutputDebugStringA("Received Motor Packet");
}break;
case PacketType_Temperature:
{
temp_packet Packet = *(temp_packet*)(PacketData.Memory + 1);
OutputDebugStringA("Received Temperature Packet");
}break;
InvalidDefaultCase;
}
}
if (MotorTimeElapsed > 60)

View File

@ -5,13 +5,21 @@
//
#ifndef BLUMEN_LUMEN_H
enum bl_python_packet_type
{
PacketType_Invalid = 0,
PacketType_PatternCommand = 1,
PacketType_MotorState = 2,
PacketType_Temperature = 3,
};
#pragma pack(push, 1)
typedef struct motor_packet
{
u8 FlowerPositions[3];
} motor_packet;
#pragma pack(push, 1)
struct microphone_packet
typedef struct microphone_packet
{
b8 ChangeAnimation;
char AnimationFileName[32];
@ -21,7 +29,12 @@ struct microphone_packet
b8 SetLayerParamColor;
char LayerParamColor[7];
r32 OverrideDuration;
};
} microphone_packet;
typedef struct temp_packet
{
s8 Temperature;
} temp_packet;
#pragma pack(pop)
#define BLUMEN_MESSAGE_QUEUE_COUNT 32