Skip to content

Commit ce2bb05

Browse files
committed
fix controller_pc with new libs tree
1 parent 734d451 commit ce2bb05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+693
-1384
lines changed

controller_pc/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ include( add_submodule )
55
enable_language( C CXX ASM )
66
project( controller_pc )
77

8-
SET( board "pc" CACHE BOOL "board" )
8+
SET( board "generic" CACHE BOOL "board" )
99

10-
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g3 -std=c11 -D_GNU_SOURCE -D_BSD_SOURCE -Wfatal-errors" )
11-
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -g3 -std=c++11 -DGE_LINUX -DGE_EGL -fpermissive -Wno-pmf-conversions -Wfatal-errors" )
10+
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -g3 -std=c11 -D_GNU_SOURCE -D_BSD_SOURCE -Wfatal-errors" )
11+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -g3 -std=c++17 -DGE_LINUX -DGE_EGL -fpermissive -Wno-pmf-conversions -Wfatal-errors" )
1212
set( CMAKE_AUTOMOC ON )
1313
set( CMAKE_AUTORCC ON )
1414
set( OpenGL_GL_PREFERENCE LEGACY )
@@ -23,6 +23,11 @@ find_package( MP4V2 )
2323
find_package( Shine )
2424

2525
add_definitions( -DSTD=std )
26+
add_definitions( -DLUA_CLASS= -DLUA_EXPORT= )
27+
add_definitions( -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DSYSTEM_NAME_${CMAKE_SYSTEM_NAME} )
28+
add_definitions( -DBOARD="${board}" -DBOARD_${board} -DVARIANT="${variant}" -DVARIANT_${variant} )
29+
add_definitions( -DVERSION_STRING="bcflight_${board}_${VERSION_MAJOR}.${VERSION_MINOR}_${GIT_HASH}" )
30+
add_definitions( -DTARGET_CPU_BITS=${TARGET_CPU_BITS} )
2631

2732
if ( WIN32 OR MINGW )
2833
if ( NOT DEFINED ${QSCINTILLA_LIBRARY} OR ${QSCINTILLA_LIBRARY} MATCHES OFF )
@@ -38,10 +43,13 @@ else()
3843
endif()
3944

4045

46+
include_directories( ${CMAKE_SOURCE_DIR}/../lib/boards/common )
47+
include_directories( ${CMAKE_SOURCE_DIR}/../lib/boards/${board} )
4148
include_directories( ${CMAKE_SOURCE_DIR}/../lib/controller )
4249
include_directories( ${CMAKE_SOURCE_DIR}/../lib/links )
4350
include_directories( ${CMAKE_SOURCE_DIR}/../lib/rawwifi )
4451
include_directories( ${CMAKE_SOURCE_DIR}/../lib/debug )
52+
include_directories( ${CMAKE_SOURCE_DIR}/../lib/luacore/src )
4553
include_directories( ${CMAKE_SOURCE_DIR}/../external/LuaJIT-2.0.4/src )
4654
include_directories( ${CMAKE_SOURCE_DIR}/../external/openh264-master/codec/api/svc )
4755
include_directories( ${Qt5PrintSupport_INCLUDE_DIRS} ${QSCINTILLA_INCLUDE_DIR} ${QSCINTILLA_INCLUDE_DIR}/Qsci )
@@ -92,6 +100,6 @@ add_dependencies( controller_pc libopenh264_static )
92100
add_dependencies( controller_pc controller )
93101
add_dependencies( controller_pc debuglib )
94102

95-
target_link_libraries( controller_pc -L./ controller debuglib -ldecoder_static -lopenh264_static ${SHINE_LIBRARIES} ${MP4V2_LIBRARIES} ${QSCINTILLA_LIBRARY} Qt5::Widgets Qt5::OpenGL Qt5::PrintSupport Qt5::Multimedia ${OPENGL_LIBRARIES} -lpthread ${OTHER_LIBS} )
103+
target_link_libraries( controller_pc -L./ controller debuglib boards -ldecoder_static -lopenh264_static ${SHINE_LIBRARIES} ${MP4V2_LIBRARIES} ${QSCINTILLA_LIBRARY} Qt5::Widgets Qt5::OpenGL Qt5::PrintSupport Qt5::Multimedia ${OPENGL_LIBRARIES} -lpthread ${OTHER_LIBS} )
96104

97105
install( TARGETS controller_pc RUNTIME DESTINATION bin )

controller_pc/MainWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ MainWindow::MainWindow()
100100
std::function<Socket::PortType(const QString&)> socket_type = [](const QString& type){ if ( type == "UDPLite" ) return Socket::UDPLite; else if ( type == "UDP" ) return Socket::UDP; else return Socket::TCP; };
101101
mControllerLink = new Socket( mConfig->value( "tcpip/address", "192.168.32.1" ).toString().toStdString(), mConfig->value( "tcpip/controller/port", 2020 ).toInt(), socket_type( mConfig->value( "tcpip/controller/type", "TCP" ).toString() ) );
102102
mStreamLink = new Socket( mConfig->value( "tcpip/address", "192.168.32.1" ).toString().toStdString(), mConfig->value( "tcpip/video/port", 2021 ).toInt(), socket_type( mConfig->value( "tcpip/video/type", "UDPLite" ).toString() ) );
103-
mAudioLink = new Socket( mConfig->value( "tcpip/address", "192.168.32.1" ).toString().toStdString(), mConfig->value( "tcpip/audio/port", 2022 ).toInt(), socket_type( mConfig->value( "tcpip/audio/type", "TCP" ).toString() ) );
103+
// mAudioLink = new Socket( mConfig->value( "tcpip/address", "192.168.32.1" ).toString().toStdString(), mConfig->value( "tcpip/audio/port", 2022 ).toInt(), socket_type( mConfig->value( "tcpip/audio/type", "TCP" ).toString() ) );
104104
}
105105
uint8_t test[2048];
106106
// mControllerLink->Read( test, 2048, 0 );
@@ -190,7 +190,7 @@ MainWindow::MainWindow()
190190

191191
ui->video->setMainWindow( this );
192192
ui->video->setLink( mStreamLink );
193-
ui->video->setAudioLink( mAudioLink );
193+
// ui->video->setAudioLink( mAudioLink );
194194
}
195195

196196

@@ -305,7 +305,7 @@ void MainWindow::updateData()
305305
}
306306

307307
if ( mController->ping() < 10000 ) {
308-
ui->latency->setText( QString::number( mController->ping() ) + " ms" );
308+
ui->latency->setText( QString::number( mController->ping() / 1000 ) + " ms" );
309309
}
310310
ui->voltage->setText( QString::number( mController->batteryVoltage(), 'f', 2 ) + " V" );
311311
ui->current->setText( QString::number( mController->currentDraw(), 'f', 2 ) + " A" );

controller_pc/Stream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "ControllerPC.h"
2626
#include "ui_mainWindow.h"
2727
#include "Socket.h"
28+
#include "Debug.h"
2829

2930

3031
#if ( defined(WIN32) && !defined(glActiveTexture) )
@@ -352,7 +353,7 @@ bool Stream::run()
352353
}
353354

354355
if ( ( mSocketTellIPCounter = ( ( mSocketTellIPCounter + 1 ) % 16 ) ) == 1 ) {
355-
// Dummy write to tell own IP address in case of Socket
356+
// Dummy write to tell own IP address in case of UDP Socket
356357
if ( dynamic_cast<Socket*>( mLink ) ) {
357358
uint32_t uid = htonl( 0x12345678 );
358359
mLink->Write( &uid, sizeof(uid), 0, -1 );

controller_rc/ADCs/MCP320x.cpp

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "MCP320x.h"
2525

2626
MCP320x::MCP320x( const std::string& devfile )
27-
: mSPI( new SPI( devfile, 500000 ) )
27+
: mSPI( new SPI( devfile, 2000000 ) )
2828
{
2929
mSPI->Connect();
3030
}
@@ -43,51 +43,68 @@ void MCP320x::setSmoothFactor( uint8_t channel, float f )
4343

4444
uint16_t MCP320x::Read( uint8_t channel, float dt )
4545
{
46-
static const int nbx = 1;
47-
// static const int nbx = 4;
48-
uint32_t b[3] = { 0, 0, 0 };
49-
uint8_t bx[nbx][3] = { { 0 } };
50-
uint8_t buf[12];
46+
static constexpr int nbx = 1;
47+
uint8_t bx[3 * nbx] = { 0 };
48+
uint8_t buf[3 * nbx];
5149

52-
buf[0] = 0b00000110 | ( ( channel & 0b100 ) >> 2 );
53-
buf[1] = ( ( channel & 0b11 ) << 6 );
50+
buf[0] = 0b00000110 | ((channel & 0b100) >> 2);
51+
buf[1] = (channel & 0b011) << 6;
5452
buf[2] = 0x00;
55-
// buf[3] = 0b00000110 | ( ( channel & 0b100 ) >> 2 );
56-
// buf[4] = ( ( channel & 0b11 ) << 6 );
57-
// buf[5] = 0x00;
58-
// buf[6] = 0b00000110 | ( ( channel & 0b100 ) >> 2 );
59-
// buf[7] = ( ( channel & 0b11 ) << 6 );
60-
// buf[8] = 0x00;
61-
// buf[9] = 0b00000110 | ( ( channel & 0b100 ) >> 2 );
62-
// buf[10] = ( ( channel & 0b11 ) << 6 );
63-
// buf[11] = 0x00;
6453

65-
for ( int i = 0; i < nbx; i++ ) {
66-
if ( mSPI->Transfer( buf, bx[i], 3 ) < 0 ) {
67-
return 0;
54+
bool ok = false;
55+
static constexpr int retries = 3;
56+
// for ( int i = 0; i < nbx; i++ ) {
57+
for ( int i = 0; i < retries; i++ ) {
58+
if ( mSPI->Transfer( buf, &bx[i * 3], 3 ) == 3 ) {
59+
ok = true;
60+
break;
6861
}
6962
}
63+
if ( not ok ) {
64+
return 0;
65+
}
7066

7167
uint32_t ret[nbx] = { 0 };
7268
uint32_t final_ret = 0;
7369
for ( int i = 0; i < nbx; i++ ) {
74-
ret[i] = ( ( bx[i][1] & 0b1111 ) << 8 ) | bx[i][2];
70+
ret[i] = ( ( bx[i*3 + 1] & 0b1111 ) << 8 ) | bx[i*3 + 2];
7571
}
7672
final_ret = ret[0];
73+
74+
// int final_nbx = 0;
75+
// for ( int j = 0; j < nbx; j++ ) {
76+
// bool ignore = false;
77+
// for ( int i = 0; i < nbx; i++ ) {
78+
// if ( i != j and std::abs( (int32_t)(ret[i] - ret[j]) ) > 250 ) {
79+
// ignore = true;
80+
// }
81+
// }
82+
// if ( not ignore ) {
83+
// final_ret += ret[j];
84+
// final_nbx++;
85+
// }
86+
// }
87+
// final_ret /= final_nbx;
88+
// final_ret &= 0xFFFFFFF7;
89+
// if ( channel >= 4 ) {
90+
// printf( "smooth[%d] : %04d (%d / %d values)\n", channel, final_ret, final_nbx, nbx );
91+
// }
7792
/*
78-
for ( int j = 0; j < nbx; j++ ) {
79-
for ( int i = 0; i < nbx; i++ ) {
80-
if ( i != j and std::abs( (int32_t)(ret[i] - ret[j]) ) > 250 ) {
81-
if ( channel == 3 ) {
82-
// printf( "ADC too large (%d, %d - %d)\n", ret[i] - ret[j], ret[i], ret[j] );
83-
}
84-
return 0;
85-
}
86-
}
87-
final_ret += ret[j];
93+
if ( channel == 0 ) {
94+
printf( "\r% 6d", final_ret ); fflush(stdout);
95+
}
96+
if ( channel == 1 ) {
97+
printf( "\r\033[6C% 6d", final_ret ); fflush(stdout);
98+
}
99+
if ( channel == 2 ) {
100+
printf( "\r\033[12C% 6d", final_ret ); fflush(stdout);
101+
}
102+
if ( channel == 3 ) {
103+
printf( "\r\033[18C% 6d", final_ret ); fflush(stdout);
104+
}
105+
if ( channel >= 4 ) {
106+
printf( "\r\033[24C% 6d", final_ret ); fflush(stdout);
88107
}
89-
final_ret /= nbx;
90-
final_ret &= 0xFFFFFFF7;
91108
*/
92109
// Raw value
93110
if ( dt == 0.0f ) {
@@ -96,12 +113,10 @@ uint16_t MCP320x::Read( uint8_t channel, float dt )
96113

97114
if ( mSmoothFactor.find(channel) != mSmoothFactor.end() ) {
98115
float smooth = mSmoothFactor[channel];
99-
if ( smooth > 0.0f and smooth < 1.0f ) {
116+
if ( smooth > 0.0f ) {
100117
float s = smooth * std::max( 0.0f, std::min( 1.0f, dt * 1000.0f ) );
118+
// float s = smooth * std::max( 0.0f, dt * 1000.0f );
101119
mLastValue[channel] = std::max( 0.0f, mLastValue[channel] * s + (float)final_ret * ( 1.0f - s ) );
102-
if ( channel == 3 ) {
103-
// printf( "ok : %d\n", (uint16_t)mLastValue[channel] );
104-
}
105120
return (uint16_t)mLastValue[channel];
106121
}
107122
}

controller_rc/CMakeLists.txt

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../CMakeModules" )
33
include( add_submodule )
44

55
set( CMAKE_CXX_STANDARD 17 )
6+
set( UIC uic )
7+
set( RCC rcc )
8+
set( MOC moc )
69

710
# Command line options
8-
SET( board "rpi" CACHE BOOL "board" )
911
SET( rawwifi "0" CACHE BOOL "rawwifi" )
10-
option( board "board" )
1112
option( rawwifi "rawwifi" )
1213

1314
if ( NOT ${board} MATCHES OFF AND NOT ${board} MATCHES "generic" )
@@ -17,39 +18,15 @@ endif()
1718
enable_language( C CXX ASM )
1819
project( controller_rc )
1920

21+
add_definitions( -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DSYSTEM_NAME_${CMAKE_SYSTEM_NAME} )
22+
add_definitions( -DBOARD="${board}" -DBOARD_${board} -DVARIANT="${variant}" -DVARIANT_${variant} )
23+
add_definitions( -DVERSION_STRING="bcflight_${board}_${VERSION_MAJOR}.${VERSION_MINOR}_${GIT_HASH}" )
24+
add_definitions( -DTARGET_CPU_BITS=${TARGET_CPU_BITS} )
25+
add_submodule( boards )
26+
2027
# Set compiler options
2128
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -ggdb3 -O0 -D_DEFAULT_SOURCE" )
22-
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ggdb3 -O0 -std=c++11 -DGE_LINUX -DGE_EGL -fpermissive -Wno-pmf-conversions" )
23-
24-
# Check chosen board
25-
macro( DIRLIST result curdir removes )
26-
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
27-
set(dirlist "")
28-
foreach(child ${children})
29-
if ( NOT "${child}" MATCHES ".md" )
30-
string(REPLACE ".cpp" "" child ${child})
31-
string(REPLACE ".h" "" child ${child})
32-
list(APPEND dirlist ${child})
33-
endif()
34-
endforeach()
35-
if ( NOT ${removes} MATCHES OFF )
36-
list(REMOVE_ITEM dirlist ${removes})
37-
endif()
38-
list(REMOVE_DUPLICATES dirlist)
39-
set(${result} ${dirlist})
40-
endmacro()
41-
DIRLIST( BOARDS ${CMAKE_SOURCE_DIR}/boards "" )
42-
43-
list( FIND BOARDS ${board} board_found )
44-
if ( ${board_found} LESS 0 )
45-
message( FATAL_ERROR "Board ${board} not supported.\nAvailable boards are :\n${BOARDS}" )
46-
endif()
47-
48-
include( boards/${board}/board.cmake )
49-
include_directories( boards/${board} )
50-
include_directories( ${CMAKE_SOURCE_DIR} )
51-
include_directories( ${CMAKE_BINARY_DIR} )
52-
add_definitions( -DBOARD="${board}" -DBOARD_${board} )
29+
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ggdb3 -O0 -std=c++17 -DGE_LINUX -DGE_EGL -fpermissive -Wno-pmf-conversions -Wno-psabi" )
5330

5431
include_directories( ${CMAKE_SOURCE_DIR}/../lib/debug )
5532
include_directories( ${CMAKE_SOURCE_DIR}/../lib/controller )
@@ -60,13 +37,18 @@ if ( ${rawwifi} MATCHES "1" OR ${rawwifi} MATCHES "yes" OR ${rawwifi} MATCHES "t
6037
add_definitions( -DBUILD_rawwifi )
6138
endif()
6239

40+
include_directories( ${CMAKE_BINARY_DIR} )
41+
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
42+
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/boards/${board} )
6343
include_directories( ${CMAKE_SOURCE_DIR}/../lib/luacore/src )
6444
include_directories( ${CMAKE_SOURCE_DIR}/../external/LuaJIT-2.0.4/src )
45+
include_directories( ${CMAKE_SOURCE_DIR}/../lib/boards/${board} )
46+
include_directories( ${CMAKE_SOURCE_DIR}/../lib/boards/common )
47+
include_directories( ${CMAKE_SOURCE_DIR}/../lib/maths )
6548
add_submodule( controller )
6649
add_submodule( debug )
6750

6851

69-
file( GLOB_RECURSE BOARD_SOURCES boards/${board}/*.cpp boards/${board}/*.c )
7052
file( GLOB_RECURSE ADCS_SOURCES ADCs/*.cpp ADCs/*.c )
7153

7254
file( GLOB HEADERS
@@ -75,6 +57,9 @@ file( GLOB HEADERS
7557
${CMAKE_SOURCE_DIR}/../lib/controller/*.h
7658
${CMAKE_SOURCE_DIR}/../lib/links/*.h
7759
)
60+
file( GLOB BOARD_HEADERS ${CMAKE_SOURCE_DIR}/../lib/boards/common/*.h ${CMAKE_SOURCE_DIR}/../lib/boards/${board}/*.h )
61+
list( APPEND HEADERS ${BOARD_HEADERS} )
62+
message( WARNING ${HEADERS} )
7863

7964
set_source_files_properties( ${CMAKE_BINARY_DIR}/lua_init.cpp PROPERTIES GENERATED TRUE )
8065
set_source_files_properties( ${CMAKE_BINARY_DIR}/rc_data.cpp PROPERTIES GENERATED TRUE )
@@ -126,17 +111,39 @@ add_executable( controller_rc
126111
Config.cpp
127112
ui/GlobalUI.cpp
128113
ui/MainWindow.cpp
114+
boards/${board}/ControllerClient.cpp
129115
${CMAKE_BINARY_DIR}/rc_data.cpp
130116
${CMAKE_BINARY_DIR}/MainWindow.moc.cpp
131117
${CMAKE_BINARY_DIR}/lua_init.cpp
132118
${ADCS_SOURCES}
133-
${BOARD_SOURCES}
134119
)
135120

136121
add_dependencies( controller_rc controller )
137122
add_dependencies( controller_rc ui_headers )
123+
if ( BOARD_DEPENDENCIES )
124+
add_dependencies( controller_rc ${BOARD_DEPENDENCIES} )
125+
endif()
138126

139127

140-
target_link_libraries( controller_rc -L./ controller debuglib -lrt -ldl ${RAWWIFI_LIBS} -lz pthread ${BOARD_LIBS} )
128+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,--unresolved-symbols=ignore-in-shared-libs -L${CMAKE_BINARY_DIR} ${BOARD_LIBS_PATHS}" )
129+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--unresolved-symbols=ignore-in-shared-libs -L${CMAKE_BINARY_DIR} ${BOARD_LIBS_PATHS}" )
130+
set(CMAKE_LD_FLAGS "${CMAKE_LD_FLAGS} -Wl,--unresolved-symbols=ignore-in-shared-libs -L${CMAKE_BINARY_DIR} ${BOARD_LIBS_PATHS}" )
131+
set(CMAKE_LINKER_FLAGS "${CMAKE_LD_FLAGS} -Wl,--unresolved-symbols=ignore-in-shared-libs -L${CMAKE_BINARY_DIR} ${BOARD_LIBS_PATHS}" )
132+
target_link_libraries(
133+
controller_rc
134+
-L./
135+
controller
136+
debuglib
137+
links
138+
boards
139+
${RAWWIFI_LIBS}
140+
Qt5Widgets Qt5Gui Qt5PrintSupport Qt5Core
141+
-lrt
142+
-ldl
143+
-lz
144+
${BOARD_LIBS}
145+
pthread
146+
)
147+
# set( CONTROLLER_BOARD_LIBS ${CONTROLLER_BOARD_LIBS} -lGLESv2 -lEGL )
141148

142149
install( TARGETS controller_rc RUNTIME DESTINATION bin )

0 commit comments

Comments
 (0)