WIP: New BLE
This commit is contained in:
parent
4fe072f2d3
commit
a9212c5a3a
12 changed files with 191 additions and 56 deletions
|
@ -147,7 +147,7 @@ void BLE_UpdateInstigationPacket(uint32_t Game_Length_in_ms, uint32_t Time_Remai
|
|||
}
|
||||
}
|
||||
|
||||
void BLE_UpdateStatusPacket()
|
||||
void BLE_UpdateStatusPacket(uint8_t current_state)
|
||||
{
|
||||
static uint8_t EventNumber = 0;
|
||||
|
||||
|
@ -190,7 +190,7 @@ void BLE_UpdateStatusPacket()
|
|||
Advertising_Data.data[23] = (Team_Color >> 8) & 0xFF; // Secondary Color
|
||||
Advertising_Data.data[24] = (Team_Color >> 16) & 0xFF; // Secondary Color
|
||||
Advertising_Data.data[25] = (Team_Color >> 24) & 0xFF; // Secondary Color
|
||||
Advertising_Data.data[26] = 0xFF;
|
||||
Advertising_Data.data[26] = current_state;
|
||||
Advertising_Data.data[27] = 0xFF;
|
||||
Advertising_Data.data[28] = 0xFF;
|
||||
Advertising_Data.data[29] = 0xFF;
|
||||
|
@ -237,12 +237,12 @@ void BLE_UpdateTagPacket(int16_t damage, color_t color, uint8_t target_BD_ADDR[B
|
|||
Advertising_Data.data[17] = (color >> 8) & 0xFF;
|
||||
Advertising_Data.data[18] = (color >> 16) & 0xFF;
|
||||
Advertising_Data.data[19] = (color >> 24) & 0xFF;
|
||||
Advertising_Data.data[20] = target_BD_ADDR[0],
|
||||
Advertising_Data.data[21] = target_BD_ADDR[1],
|
||||
Advertising_Data.data[22] = target_BD_ADDR[2],
|
||||
Advertising_Data.data[23] = target_BD_ADDR[3],
|
||||
Advertising_Data.data[24] = target_BD_ADDR[4],
|
||||
Advertising_Data.data[25] = target_BD_ADDR[5],
|
||||
Advertising_Data.data[20] = target_BD_ADDR[0];
|
||||
Advertising_Data.data[21] = target_BD_ADDR[1];
|
||||
Advertising_Data.data[22] = target_BD_ADDR[2];
|
||||
Advertising_Data.data[23] = target_BD_ADDR[3];
|
||||
Advertising_Data.data[24] = target_BD_ADDR[4];
|
||||
Advertising_Data.data[25] = target_BD_ADDR[5];
|
||||
Advertising_Data.data[26] = 0xFF;
|
||||
Advertising_Data.data[27] = 0xFF;
|
||||
Advertising_Data.data[28] = 0xFF;
|
||||
|
@ -257,6 +257,74 @@ void BLE_UpdateTagPacket(int16_t damage, color_t color, uint8_t target_BD_ADDR[B
|
|||
}
|
||||
}
|
||||
|
||||
void BLE_UpdateHelloPacket()
|
||||
{
|
||||
static uint8_t EventNumber = 0;
|
||||
|
||||
uint32_t device_type32;
|
||||
uint16_t device_type = BLE_DEVICE_TYPE_UNKNOWN;
|
||||
if (SETTINGS_get_uint32_t(SYSTEMK_SETTING_DEVICE_TYPE, &device_type32) == SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
device_type = (uint16_t)device_type32;
|
||||
}
|
||||
|
||||
uint8_t team_ID;
|
||||
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &team_ID);
|
||||
|
||||
char device_name[SYSTEMK_MAX_CHARS_IN_DEVICE_NAME + 1];
|
||||
SystemKResult_T result = SETTINGS_get_device_name(&device_name[0]);
|
||||
if (result != SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
strcpy(device_name, "Anonymous");
|
||||
}
|
||||
size_t len = strlen(device_name);
|
||||
if (len < sizeof(device_name)) {
|
||||
memset(device_name + len, 0x00, sizeof(device_name) - len);
|
||||
}
|
||||
|
||||
Advertising_Data.length = BLE_KTAG_PACKET_TOTAL_SIZE;
|
||||
|
||||
// Manufacturer Specific Data
|
||||
Advertising_Data.data[0] = 0x1E;
|
||||
Advertising_Data.data[1] = 0xFF;
|
||||
Advertising_Data.data[2] = 0xFF;
|
||||
Advertising_Data.data[3] = 0xFF;
|
||||
Advertising_Data.data[4] = 'K';
|
||||
Advertising_Data.data[5] = 'T';
|
||||
Advertising_Data.data[6] = 'a';
|
||||
Advertising_Data.data[7] = 'g';
|
||||
Advertising_Data.data[8] = BLE_PACKET_TYPE_HELLO;
|
||||
Advertising_Data.data[9] = EventNumber++;
|
||||
Advertising_Data.data[10] = SYSTEMK_MAJOR_VERSION;
|
||||
Advertising_Data.data[11] = SYSTEMK_MINOR_VERSION;
|
||||
Advertising_Data.data[12] = (device_type >> 0) & 0xFF;
|
||||
Advertising_Data.data[13] = (device_type >> 8) & 0xFF;
|
||||
Advertising_Data.data[14] = team_ID;
|
||||
Advertising_Data.data[15] = device_name[0];
|
||||
Advertising_Data.data[16] = device_name[1];
|
||||
Advertising_Data.data[17] = device_name[2];
|
||||
Advertising_Data.data[18] = device_name[3];
|
||||
Advertising_Data.data[19] = device_name[4];
|
||||
Advertising_Data.data[20] = device_name[5];
|
||||
Advertising_Data.data[21] = device_name[6];
|
||||
Advertising_Data.data[22] = device_name[7];
|
||||
Advertising_Data.data[23] = device_name[8];
|
||||
Advertising_Data.data[24] = device_name[9];
|
||||
Advertising_Data.data[25] = device_name[10];
|
||||
Advertising_Data.data[26] = device_name[11];
|
||||
Advertising_Data.data[27] = device_name[12];
|
||||
Advertising_Data.data[28] = device_name[13];
|
||||
Advertising_Data.data[29] = device_name[14];
|
||||
Advertising_Data.data[30] = device_name[15];
|
||||
|
||||
result = BLE_SetAdvertisingData(&Advertising_Data);
|
||||
|
||||
if (result != SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
KLOG_ERROR(KLOG_TAG, "Error updating hello packet!");
|
||||
}
|
||||
}
|
||||
|
||||
bool BLE_IsBLEPacketForMe(const uint8_t BD_ADDR[6])
|
||||
{
|
||||
bool for_me = false;
|
||||
|
|
|
@ -59,11 +59,13 @@ typedef enum
|
|||
BLE_PACKET_TYPE_BUFFER_FREE = 0,
|
||||
BLE_PACKET_TYPE_INSTIGATE_GAME = 1,
|
||||
BLE_FIRST_VALID_PACKET_TYPE = BLE_PACKET_TYPE_INSTIGATE_GAME,
|
||||
BLE_PACKET_TYPE_JOIN_NOW = 2,
|
||||
BLE_PACKET_TYPE_EVENT = 2,
|
||||
BLE_PACKET_TYPE_TAG = 3,
|
||||
BLE_PACKET_TYPE_CONSOLE = 4,
|
||||
BLE_PACKET_TYPE_STATUS = 5,
|
||||
BLE_LAST_VALID_PACKET_TYPE = BLE_PACKET_TYPE_STATUS,
|
||||
BLE_PACKET_TYPE_CONFIGURATION = 6,
|
||||
BLE_PACKET_TYPE_HELLO = 7,
|
||||
BLE_LAST_VALID_PACKET_TYPE = BLE_PACKET_TYPE_HELLO,
|
||||
BLE_PACKET_TYPE_UNKNOWN
|
||||
} BLE_PacketType_T;
|
||||
|
||||
|
@ -87,11 +89,10 @@ typedef struct
|
|||
|
||||
uint32_t game_length_in_ms;
|
||||
uint32_t time_remaining_until_countdown_in_ms;
|
||||
uint8_t random_time_after_countdown_in_ms_x100;
|
||||
uint8_t unused[12];
|
||||
uint8_t unused[13];
|
||||
} __attribute__((packed, aligned(1))) BLE_InstigationPacket_T;
|
||||
|
||||
//! Contents of the BLE packet #BLE_PACKET_TYPE_JOIN_NOW.
|
||||
//! Contents of the BLE packet #BLE_PACKET_TYPE_EVENT.
|
||||
typedef struct
|
||||
{
|
||||
BLE_PacketType_T type;
|
||||
|
@ -99,10 +100,11 @@ typedef struct
|
|||
int8_t RSSI;
|
||||
uint8_t event_number;
|
||||
|
||||
uint32_t game_length_in_ms;
|
||||
uint32_t time_remaining_in_game_in_ms;
|
||||
uint8_t unused[13];
|
||||
} __attribute__((packed, aligned(1))) BLE_JoinNowPacket_T;
|
||||
uint8_t target_BD_ADDR[BD_ADDR_SIZE];
|
||||
uint32_t event_ID;
|
||||
uint32_t event_data;
|
||||
uint8_t unused[7];
|
||||
} __attribute__((packed, aligned(1))) BLE_EventPacket_T;
|
||||
|
||||
//! Contents of the BLE packet #BLE_PACKET_TYPE_TAG.
|
||||
typedef struct
|
||||
|
@ -149,17 +151,61 @@ typedef struct
|
|||
uint16_t maximum_health;
|
||||
color_t primary_color;
|
||||
color_t secondary_color;
|
||||
uint8_t unused[5];
|
||||
uint8_t SystemK_top_level_state; // StateID_T
|
||||
uint8_t unused[4];
|
||||
} __attribute__((packed, aligned(1)))BLE_StatusPacket_T;
|
||||
|
||||
//! Contents of the BLE packet #BLE_PACKET_TYPE_CONFIGURATION.
|
||||
typedef struct
|
||||
{
|
||||
BLE_PacketType_T type;
|
||||
uint8_t BD_ADDR[BD_ADDR_SIZE];
|
||||
int8_t RSSI;
|
||||
uint8_t event_number;
|
||||
|
||||
uint8_t target_BD_ADDR[BD_ADDR_SIZE];
|
||||
uint8_t subtype;
|
||||
uint16_t key_one;
|
||||
uint32_t value_one;
|
||||
uint16_t key_two;
|
||||
uint32_t value_two;
|
||||
uint8_t unused[2];
|
||||
} __attribute__((packed, aligned(1)))BLE_ConfigurationPacket_T;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BLE_DEVICE_TYPE_LITTLE_BOY_BLUE = 0x0000,
|
||||
BLE_DEVICE_TYPE_2020TPC = 0x0001,
|
||||
BLE_DEVICE_TYPE_MOBILE_APP = 0x0002,
|
||||
BLE_DEVICE_TYPE_32ESPECIAL = 0x0003,
|
||||
BLE_DEVICE_TYPE_UNKNOWN = 0xFFFF
|
||||
} BLE_DeviceType_T;
|
||||
|
||||
//! Contents of the BLE packet #BLE_PACKET_TYPE_HELLO.
|
||||
typedef struct
|
||||
{
|
||||
BLE_PacketType_T type;
|
||||
uint8_t BD_ADDR[BD_ADDR_SIZE];
|
||||
int8_t RSSI;
|
||||
uint8_t event_number;
|
||||
|
||||
uint8_t SystemK_major_version;
|
||||
uint8_t SystemK_minor_version;
|
||||
uint16_t device_type;
|
||||
uint8_t team_ID;
|
||||
uint8_t device_name[SYSTEMK_MAX_CHARS_IN_DEVICE_NAME];
|
||||
} __attribute__((packed, aligned(1)))BLE_HelloPacket_T;
|
||||
|
||||
typedef union
|
||||
{
|
||||
BLE_GenericPacketType_T Generic;
|
||||
BLE_InstigationPacket_T Instigation;
|
||||
BLE_JoinNowPacket_T JoinNow;
|
||||
BLE_EventPacket_T Event;
|
||||
BLE_TagPacket_T Tag;
|
||||
BLE_ConsolePacket_T Console;
|
||||
BLE_StatusPacket_T Status;
|
||||
BLE_ConfigurationPacket_T Configuration;
|
||||
BLE_HelloPacket_T Hello;
|
||||
} BLE_Packet_T;
|
||||
|
||||
/* Include Files */
|
||||
|
@ -180,8 +226,9 @@ void BLE_InitPacketBuffers(void);
|
|||
|
||||
BLE_Packet_T * BLE_DecodeKTagPacket(const uint8_t * received_data, uint8_t received_data_length, uint8_t peer_BD_ADDR[BD_ADDR_SIZE], int8_t rssi_in_dBm);
|
||||
void BLE_UpdateInstigationPacket(uint32_t Game_Length_in_ms, uint32_t Time_Remaining_Until_Countdown_in_ms);
|
||||
void BLE_UpdateStatusPacket();
|
||||
void BLE_UpdateStatusPacket(uint8_t current_state);
|
||||
void BLE_UpdateTagPacket(int16_t damage, color_t color, uint8_t target_BD_ADDR[BD_ADDR_SIZE]);
|
||||
void BLE_UpdateHelloPacket();
|
||||
bool BLE_IsBLEPacketForMe(const uint8_t BD_ADDR[BD_ADDR_SIZE]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue