Added Test Data Message for Game Development Testing
This commit is contained in:
+59
@@ -42,6 +42,64 @@ static ESP_MessageBrokerTaskParams_t esp_broker_task_params;
|
||||
|
||||
ClientList clientList = {.Clients = {{0}}, .ClientCount = 0};
|
||||
|
||||
size_t build_ClientInfoPart(uint8_t clientid, float_t lagex, float_t lagey,
|
||||
int32_t bitmask, uint8_t *outputArray,
|
||||
size_t outputArrayOffset, size_t outputArraySize) {
|
||||
|
||||
size_t offset = outputArrayOffset;
|
||||
memcpy(&outputArray[offset], &clientid, sizeof(clientid));
|
||||
offset += sizeof(clientid);
|
||||
|
||||
// lagex (typischerweise 4 Bytes)
|
||||
memcpy(&outputArray[offset], &lagex, sizeof(lagex));
|
||||
offset += sizeof(lagex);
|
||||
|
||||
// lagey (typischerweise 4 Bytes)
|
||||
memcpy(&outputArray[offset], &lagey, sizeof(lagey));
|
||||
offset += sizeof(lagey);
|
||||
|
||||
// bitmask (4 Bytes)
|
||||
memcpy(&outputArray[offset], &bitmask, sizeof(bitmask));
|
||||
offset += sizeof(bitmask);
|
||||
|
||||
return offset - outputArrayOffset;
|
||||
}
|
||||
|
||||
void fakeDataCallback(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
||||
uint8_t *send_payload_buffer,
|
||||
size_t send_payload_buffer_size, uint8_t *send_buffer,
|
||||
size_t send_buffer_size) {
|
||||
|
||||
uint8_t seed = payload[1];
|
||||
ESP_LOGI(TAG, "Sending Fake Client Infos with seed %d", seed);
|
||||
srand(seed);
|
||||
|
||||
size_t offset = 1;
|
||||
send_payload_buffer[0] = 3; // Client Count
|
||||
offset +=
|
||||
build_ClientInfoPart(1, rand() * 1.0, rand() * 1.0, rand() * 1,
|
||||
send_payload_buffer, 1, send_payload_buffer_size);
|
||||
offset += build_ClientInfoPart(2, rand() * 2.0, rand() * 2.0, rand() * 2,
|
||||
send_payload_buffer, offset,
|
||||
send_payload_buffer_size);
|
||||
offset += build_ClientInfoPart(3, rand() * 3.0, rand() * 3.0, rand() * 3,
|
||||
send_payload_buffer, offset,
|
||||
send_payload_buffer_size);
|
||||
|
||||
int len = build_message(UART_CLIENT_INPUT, send_payload_buffer, offset,
|
||||
send_buffer, send_buffer_size);
|
||||
|
||||
if (len < 0) {
|
||||
ESP_LOGE(TAG,
|
||||
"Error Building UART Message: payload_len, %d, sendbuffer_size: "
|
||||
"%d, mes_len(error): %d",
|
||||
payload_len, send_buffer_size, len);
|
||||
return;
|
||||
}
|
||||
|
||||
uart_write_bytes(MASTER_UART, send_buffer, len);
|
||||
}
|
||||
|
||||
void echoCallback(uint8_t msgid, const uint8_t *payload, size_t payload_len,
|
||||
uint8_t *send_payload_buffer, size_t send_payload_buffer_size,
|
||||
uint8_t *send_buffer, size_t send_buffer_size) {
|
||||
@@ -310,6 +368,7 @@ void app_main(void) {
|
||||
RegisterCallback(0x01, echoCallback);
|
||||
RegisterCallback(0x02, versionCallback);
|
||||
RegisterCallback(0x03, clientInfoCallback);
|
||||
RegisterCallback(0x04, fakeDataCallback);
|
||||
RegisterCallback(UART_OTA_START_ESPNOW, start_ota_update_espnow);
|
||||
|
||||
init_ota();
|
||||
|
||||
@@ -6,6 +6,7 @@ enum UART_MSG_IDS {
|
||||
UART_ECHO = 0x01,
|
||||
UART_VERSION = 0x02,
|
||||
UART_CLIENT_INFO = 0x03,
|
||||
UART_CLIENT_INPUT = 0x04,
|
||||
|
||||
// OTA
|
||||
UART_OTA_START = 0x10,
|
||||
|
||||
Reference in New Issue
Block a user