Skip to content

Commit d66e2b5

Browse files
committed
Added code to measure latency with an oscilloscope.
Both the GTG latency and the ground station in isolation can be measured. Oscilloscope required.
1 parent af24fc0 commit d66e2b5

File tree

11 files changed

+241
-103
lines changed

11 files changed

+241
-103
lines changed

air_firmware/main/main.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,21 @@ IRAM_ATTR static void wifi_tx_proc(void *)
992992
//xSemaphoreTake(s_wifi_tx_done_semaphore, portMAX_DELAY); //wait for the tx_done notification
993993
#endif
994994
}
995-
else
995+
else if (res == ESP_ERR_NO_MEM) //No TX buffers available, need to poll.
996996
{
997997
spins++;
998-
if (spins > 10000)
998+
if (spins > 1000)
999999
vTaskDelay(1);
1000+
else
1001+
taskYIELD();
1002+
}
1003+
else //other errors
1004+
{
1005+
//LOG("Wlan err: %d\n", res);
1006+
s_stats.wlan_error_count++;
1007+
xSemaphoreTake(s_wlan_outgoing_mux, portMAX_DELAY);
1008+
end_reading_wlan_outgoing_packet(packet);
1009+
xSemaphoreGive(s_wlan_outgoing_mux);
10001010
}
10011011
}
10021012
}
@@ -1084,9 +1094,9 @@ void setup_wifi()
10841094
xSemaphoreGive(s_fec_encoder_mux);
10851095

10861096
Fec_Codec::Descriptor descriptor;
1087-
descriptor.coding_k = 4;
1088-
descriptor.coding_n = 7;
1089-
descriptor.mtu = AIR2GROUND_MTU;
1097+
descriptor.coding_k = s_ground2air_config_packet.fec_codec_k;
1098+
descriptor.coding_n = s_ground2air_config_packet.fec_codec_n;
1099+
descriptor.mtu = s_ground2air_config_packet.fec_codec_mtu;
10901100
descriptor.core = Fec_Codec::Core::Any;
10911101
descriptor.priority = 1;
10921102
xSemaphoreTake(s_fec_encoder_mux, portMAX_DELAY);

air_firmware/main/main.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/////////////////////////////////////////////////////////////////////////
77

88
constexpr size_t WLAN_INCOMING_BUFFER_SIZE = 1024;
9-
constexpr size_t WLAN_OUTGOING_BUFFER_SIZE = 32768;
9+
constexpr size_t WLAN_OUTGOING_BUFFER_SIZE = 70000;
1010

1111
////////////////////////////////////////////////////////////////////////////////////
1212

components/common/packets.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include "structures.h"
4+
35
#pragma pack(push, 1) // exact fit - no padding
46

57
enum class WIFI_Rate : uint8_t
@@ -38,7 +40,7 @@ enum class WIFI_Rate : uint8_t
3840
/* 29 */ RATE_N_72M_MCS7_S,
3941
};
4042

41-
static constexpr size_t AIR2GROUND_MTU = 1400;
43+
static constexpr size_t AIR2GROUND_MTU = WLAN_MAX_PAYLOAD_SIZE - 6; //6 is the fec header size
4244

4345
///////////////////////////////////////////////////////////////////////////////////////
4446

@@ -79,8 +81,8 @@ struct Ground2Air_Config_Packet : Ground2Air_Header
7981
uint8_t ping = 0; //used for latency measurement
8082
int8_t wifi_power = 20;//dBm
8183
WIFI_Rate wifi_rate = WIFI_Rate::RATE_G_18M_ODFM;
82-
uint8_t fec_codec_k = 4;
83-
uint8_t fec_codec_n = 7;
84+
uint8_t fec_codec_k = 2;
85+
uint8_t fec_codec_n = 3;
8486
uint16_t fec_codec_mtu = AIR2GROUND_MTU;
8587
bool dvr_record = false;
8688

gs/.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"utility": "cpp",
7171
"__tree": "cpp",
7272
"map": "cpp",
73-
"set": "cpp"
73+
"set": "cpp",
74+
"condition_variable": "cpp"
7475
}
7576
}

gs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ CPPFLAGS := -O3 -DNDEBUG -ffast-math -funroll-loops -mcpu=cortex-a8 -mfpu=neon -
6767
# linker flags
6868
#LDFLAGS := -L/usr/lib -L=/opt/vc/lib -lstdc++ -lm -lpthread -lz -lrt -lfreetype -lmmal_core -lmmal_util -lmmal_vc_client -lvcos -lbcm_host -lbrcmGLESv2 -lbrcmEGL -lts
6969
#LDFLAGS := -L/usr/lib -L=/opt/vc/lib -lstdc++ -lm -lpthread -lz -lrt -lfreetype -lSDL2 -lGLESv2 -lturbojpeg -lmmal_core -lmmal_util -lmmal_vc_client -lvcos -lepoxy
70-
LDFLAGS := -L/usr/lib -L=/opt/vc/lib -lstdc++ -lm -lpthread -lz -lrt -lfreetype -lSDL2 -lturbojpeg -lpcap -lGLESv2
70+
LDFLAGS := -L/usr/lib -L=/opt/vc/lib -lstdc++ -lm -lpthread -lz -lrt -lfreetype -lSDL2 -lturbojpeg -lpcap -lGLESv2 -lpigpio
7171
# flags required for dependency generation; passed to compilers
7272
DEPFLAGS = -MT $@ -MD -MP -MF $(DEPDIR)/$*.Td
7373

gs/src/PI_HAL.cpp

+46-38
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#define USE_SDL
55
//#define USE_MANGA_SCREEN2
66

7-
#define USE_BOUBLE_BUFFER
7+
//#define USE_BOUBLE_BUFFER
88

99
#include <fstream>
1010
#include <future>
@@ -39,7 +39,7 @@ extern "C"
3939

4040
extern "C"
4141
{
42-
//#include "pigpio.h"
42+
#include "pigpio.h"
4343
}
4444

4545
extern uint8_t s_font_droid_sans[];
@@ -102,7 +102,7 @@ struct PI_HAL::Impl
102102
};
103103
std::array<Touch, MAX_TOUCHES> touches;
104104

105-
//bool pigpio_is_isitialized = false;
105+
bool pigpio_is_isitialized = false;
106106
float target_backlight = 1.0f;
107107
float backlight = 0.0f;
108108

@@ -117,38 +117,38 @@ struct PI_HAL::Impl
117117
///////////////////////////////////////////////////////////////////////////////////////////////////
118118

119119

120-
// bool PI_HAL::init_pigpio()
121-
// {
122-
// if (m_impl->pigpio_is_isitialized)
123-
// return true;
120+
bool PI_HAL::init_pigpio()
121+
{
122+
if (m_impl->pigpio_is_isitialized)
123+
return true;
124124

125-
// LOGI("Initializing pigpio");
126-
// if (gpioCfgClock(2, PI_CLOCK_PCM, 0) < 0 ||
127-
// gpioCfgPermissions(static_cast<uint64_t>(-1)))
128-
// {
129-
// LOGE("Cannot configure pigpio");
130-
// return false;
131-
// }
132-
// if (gpioInitialise() < 0)
133-
// {
134-
// LOGE("Cannot init pigpio");
135-
// return false;
136-
// }
125+
LOGI("Initializing pigpio");
126+
if (gpioCfgClock(2, PI_CLOCK_PCM, 0) < 0 ||
127+
gpioCfgPermissions(static_cast<uint64_t>(-1)))
128+
{
129+
LOGE("Cannot configure pigpio");
130+
return false;
131+
}
132+
if (gpioInitialise() < 0)
133+
{
134+
LOGE("Cannot init pigpio");
135+
return false;
136+
}
137137

138-
// m_impl->pigpio_is_isitialized = true;
138+
m_impl->pigpio_is_isitialized = true;
139139

140-
// return true;
141-
// }
140+
return true;
141+
}
142142

143143
// ///////////////////////////////////////////////////////////////////////////////////////////////////
144144

145-
// void PI_HAL::shutdown_pigpio()
146-
// {
147-
// if (m_impl->pigpio_is_isitialized)
148-
// gpioTerminate();
145+
void PI_HAL::shutdown_pigpio()
146+
{
147+
if (m_impl->pigpio_is_isitialized)
148+
gpioTerminate();
149149

150-
// m_impl->pigpio_is_isitialized = false;
151-
// }
150+
m_impl->pigpio_is_isitialized = false;
151+
}
152152

153153
///////////////////////////////////////////////////////////////////////////////////////////////////
154154

@@ -253,6 +253,8 @@ bool PI_HAL::init_display_dispmanx()
253253

254254
bool PI_HAL::init_display_sdl()
255255
{
256+
//SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
257+
256258
#ifdef USE_SDL
257259
SDL_Init(SDL_INIT_VIDEO);
258260
#ifdef USE_BOUBLE_BUFFER
@@ -265,14 +267,18 @@ bool PI_HAL::init_display_sdl()
265267
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
266268
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
267269
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
268-
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
270+
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
269271
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
270272

271273
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
272274
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
273275
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
274276
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
275277

278+
SDL_SetHintWithPriority(SDL_HINT_VIDEO_DOUBLE_BUFFER, "1", SDL_HINT_OVERRIDE);
279+
//SDL_SetHintWithPriority(SDL_HINT_RENDER_VSYNC, "0", SDL_HINT_OVERRIDE);
280+
281+
276282
int driver_count = SDL_GetNumVideoDrivers();
277283
LOGI("Drivers: {}", driver_count);
278284
for (int i = 0; i < driver_count; i++)
@@ -290,9 +296,9 @@ bool PI_HAL::init_display_sdl()
290296

291297
// Create an application window with the following settings:
292298
m_impl->window = SDL_CreateWindow(
293-
"An SDL2 window", // window title
294-
SDL_WINDOWPOS_UNDEFINED, // initial x position
295-
SDL_WINDOWPOS_UNDEFINED, // initial y position
299+
"ESP32 FPV", // window title
300+
0, // initial x position
301+
0, // initial y position
296302
m_impl->width, // width, in pixels
297303
m_impl->height, // height, in pixels
298304
SDL_WINDOW_FULLSCREEN |
@@ -430,6 +436,8 @@ bool PI_HAL::update_display()
430436
}
431437

432438
SDL_GL_SwapWindow(m_impl->window);
439+
//SDL_GL_SwapWindow(m_impl->window);
440+
//SDL_GL_SwapWindow(m_impl->window);
433441
//glFlush();
434442

435443
ImGui_ImplSDL2_NewFrame(m_impl->window);
@@ -580,11 +588,11 @@ bool PI_HAL::init()
580588
bcm_host_init();
581589
#endif
582590

583-
// if (!init_pigpio())
584-
// {
585-
// LOGE("Cannot initialize pigpio");
586-
// return false;
587-
// }
591+
if (!init_pigpio())
592+
{
593+
LOGE("Cannot initialize pigpio");
594+
return false;
595+
}
588596
if (!init_display())
589597
{
590598
LOGE("Cannot initialize display");
@@ -614,7 +622,7 @@ void PI_HAL::shutdown()
614622
{
615623
ImGui_ImplOpenGL3_Shutdown();
616624

617-
//shutdown_pigpio();
625+
shutdown_pigpio();
618626
shutdown_ts();
619627
shutdown_display();
620628
}

0 commit comments

Comments
 (0)