-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88ebc79
commit 247dd58
Showing
6 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright (c) 2019-2020, Jacques Gagnon | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <xtensa/hal.h> | ||
#include <driver/gpio.h> | ||
#include "sdkconfig.h" | ||
#include "../stats.h" | ||
|
||
static uint8_t type; | ||
static uint32_t counter; | ||
static uint32_t start, end; | ||
|
||
//#define REPORT_INTEVAL_STATS | ||
//#define MIN_LATENCY_TEST | ||
void bt_dbg_init(uint8_t dev_type) { | ||
end = 0; | ||
start = xthal_get_ccount(); | ||
counter = 0; | ||
type = dev_type; | ||
} | ||
|
||
void bt_dbg(uint8_t *data, uint16_t len) { | ||
#ifdef REPORT_INTEVAL_STATS | ||
float average, max, min, std_dev; | ||
uint32_t interval; | ||
|
||
end = xthal_get_ccount(); | ||
counter++; | ||
|
||
if (end > start) { | ||
interval = (end - start)/CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; | ||
} | ||
else { | ||
interval = ((0xFFFFFFFF - start) + end)/CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; | ||
} | ||
start = end; | ||
|
||
average = getAverage(interval)/1000; | ||
max = getMax(interval)/1000; | ||
min = getMin(interval)/1000; | ||
std_dev = getStdDev(interval)/1000; | ||
printf("\e[1;1H\e[2J"); | ||
|
||
printf("Samples: %d\n", counter); | ||
printf("Average: %.6f ms\n", average); | ||
printf("Max: %.6f ms\n", max); | ||
printf("Min: %.6f ms\n", min); | ||
printf("Std Dev: %.6f ms\n", std_dev); | ||
#endif | ||
#ifdef MIN_LATENCY_TEST | ||
//#define PS3 | ||
//#define PS4 | ||
//#define PS5 | ||
//#define WIIU | ||
//#define XB1 | ||
//#define SW | ||
#ifdef PS3 | ||
if ((*(uint32_t *)&data[11]) & 0x01FFFF00) { | ||
GPIO.out = 0xFBFFFFFF; | ||
} | ||
else { | ||
GPIO.out = 0xFFFFFFFF; | ||
} | ||
#else | ||
#ifdef PS4 | ||
if ((*(uint32_t *)&data[6+11]) & 0x0003FFF0) { | ||
GPIO.out = 0xFBFFFFFF; | ||
} | ||
else { | ||
GPIO.out = 0xFFFFFFFF; | ||
} | ||
#else | ||
#ifdef PS5 | ||
if ((*(uint32_t *)&data[8+11]) & 0x0003FFF0) { | ||
GPIO.out = 0xFBFFFFFF; | ||
} | ||
else { | ||
GPIO.out = 0xFFFFFFFF; | ||
} | ||
#else | ||
#ifdef WIIU | ||
if (~(*(uint32_t *)&data[13+11]) & 0x0003FFFE) { | ||
GPIO.out = 0xFBFFFFFF; | ||
} | ||
else { | ||
GPIO.out = 0xFFFFFFFF; | ||
} | ||
#else | ||
#ifdef XB1 | ||
if ((*(uint32_t *)&data[13+11]) & 0x000003FF) { | ||
GPIO.out = 0xFBFFFFFF; | ||
} | ||
else { | ||
GPIO.out = 0xFFFFFFFF; | ||
} | ||
#else | ||
#ifdef SW | ||
if ((*(uint16_t *)&data[+11])) { | ||
GPIO.out = 0xFBFFFFFF; | ||
} | ||
else { | ||
GPIO.out = 0xFFFFFFFF; | ||
} | ||
#endif | ||
#endif | ||
#endif | ||
#endif | ||
#endif | ||
#endif | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2019-2020, Jacques Gagnon | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef _BT_DBG_H_ | ||
#define _BT_DBG_H_ | ||
|
||
void bt_dbg_init(uint8_t dev_type); | ||
void bt_dbg(uint8_t *data, uint16_t len); | ||
|
||
#endif /* _BT_DBG_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* Functions to calculate Average, Min, Max, and Std Dev */ | ||
/* Taken from Arduino lag test code by @jorge_: https://pastebin.com/ktqn7izx */ | ||
|
||
#include <stdint.h> | ||
#include <math.h> | ||
|
||
float getAverage(uint32_t newNum){ | ||
static uint32_t numSamples = 1; | ||
static float curAvg; | ||
|
||
curAvg = curAvg + (newNum - curAvg) / numSamples; | ||
numSamples++; | ||
|
||
return curAvg; | ||
} | ||
|
||
float getMax(uint32_t newNum){ | ||
static uint32_t maxVal = 0; | ||
|
||
if(newNum > maxVal){ | ||
maxVal = newNum; | ||
} | ||
|
||
return maxVal; | ||
} | ||
|
||
float getMin(uint32_t newNum){ | ||
static uint32_t minVal = 0xFFFFFFFF; | ||
|
||
if(newNum < minVal){ | ||
minVal = newNum; | ||
} | ||
|
||
return minVal; | ||
} | ||
|
||
float getStdDev(uint32_t newNum){ | ||
static float M = 0.0; | ||
static float S = 0.0; | ||
static uint32_t i = 1; | ||
|
||
float tmpM = M; | ||
M += (newNum - tmpM) / i; | ||
S += (newNum - tmpM) * (newNum - M); | ||
i++; | ||
|
||
return sqrt(S/(i-2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* Functions to calculate Average, Min, Max, and Std Dev */ | ||
/* Taken from Arduino lag test code by @jorge_: https://pastebin.com/ktqn7izx */ | ||
|
||
#ifndef _STATS_H_ | ||
#define _STATS_H_ | ||
|
||
float getAverage(uint32_t newNum); | ||
float getMax(uint32_t newNum); | ||
float getMin(uint32_t newNum); | ||
float getStdDev(uint32_t newNum); | ||
|
||
#endif /* _STATS_H_ */ |