Skip to content

Commit

Permalink
Fixed warnings and reformat (#17)
Browse files Browse the repository at this point in the history
* BUILD_WITH_ALL_WARNINGS option to build with more warnings
* fixed most warnings while building with BUILD_WITH_ALL_WARNINGS
* reformatted most of the code
* fixed issues compiling with GCC 4.8
* INCLUDE_GENERATOR_RTCM=OFF now works
  • Loading branch information
ewasjon authored Apr 4, 2024
1 parent 6c64f84 commit 91c310e
Show file tree
Hide file tree
Showing 164 changed files with 2,066 additions and 1,726 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: false
InsertNewlineAtEOF: true
QualifierAlignment: Right
RemoveSemicolon: true
...
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [3.4.*]
- You can optionally include/exclude which generators to build by using the CMake options `-DINCLUDE_GENERATOR_*`. By default, RTCM and SPARTN generators are included and the old SPARTN generator is excluded.

## [3.4.5] 2024-04-02
- SPARTN generator will not use provided URA epoch-time. This caused issues where only the URA timestamp would be used and because it isn't update vary frequently the corrections data would not be used.
- SPARTN is now "officially" supported. It has been tested with multiple data feed providers and is working as expected.
Expand Down
85 changes: 69 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ option(INTERFACE_FD_DEBUG "Print FD debug information" OFF)
option(RECEIVER_UBLOX_THREADED "Print Receiver u-blox (threaded) debug information" OFF)
option(SPARTN_DEBUG_PRINT "Print SPARTN debug information" OFF)
option(RECEIVER_NMEA_DEBUG "Print Receiver NMEA debug information" OFF)

option(INCLUDE_GENERATOR_RTCM "Include RTCM generator" ON)
option(INCLUDE_GENERATOR_SPARTN "Include SPARTN generator" ON)
option(INCLUDE_GENERATOR_SPARTN_OLD "Include old SPARTN generator" OFF)

option(BUILD_WITH_ALL_WARNINGS "BUILD_WITH_ALL_WARNINGS" OFF)
option(WARNINGS_AS_ERRORS "WARNINGS_AS_ERRORS" OFF)
option(EXPERIMENTAL "EXPERIMENTAL" OFF)

option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
Expand All @@ -32,28 +39,74 @@ add_definitions(-D_POSIX_C_SOURCE=200809L)
add_definitions(-DCLIENT_VERSION="3.4.5")
add_definitions(-DCLIENT_VERSION_INT=0x030405)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_definitions(-DCOMPILER_CANNOT_DEDUCE_UNREACHABLE=1)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_definitions(-DCOMPILER_CANNOT_DEDUCE_UNREACHABLE=0)
endif()

if(${ASN_DEBUG})
add_definitions(-DASN_EMIT_DEBUG=1)
endif(${ASN_DEBUG})

find_package(Threads REQUIRED)

add_compile_options("-Wall" "-Wno-unused-function" "-Wno-unused-variable" "-Wno-sign-compare")
function(setup_target target)
target_compile_options(${target} PRIVATE
"-Wall"
"-Wextra"
"-Wpedantic"
)

if(${WARNINGS_AS_ERRORS})
target_compile_options(${target} PRIVATE
"-Werror"
)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(${BUILD_WITH_ALL_WARNINGS})
target_compile_options(${target} PRIVATE
"-Weverything"
"-Wno-c++98-compat"
"-Wno-c++98-compat-pedantic"
"-Wno-c++98-c++11-compat-pedantic"
"-Wno-nested-anon-types"
"-Wno-gnu-anonymous-struct"
"-Wno-missing-prototypes"
"-Wno-documentation"
"-Wno-documentation-unknown-command"
"-Wno-weak-vtables"
"-Wno-unused-const-variable"
"-Wno-format-nonliteral"
"-Wno-global-constructors"
"-Wno-exit-time-destructors"
"-Wno-padded"
)
endif()

target_compile_options(${target} PRIVATE
"-Wno-c++17-extensions"
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(${target} PRIVATE
"-Wno-missing-field-initializers"
"-Wno-error=pragmas"
"-Wno-pragmas"
)
endif()

if (USE_ASAN)
target_compile_options(${target} PRIVATE -fsanitize=address,undefined,leak)
target_link_libraries(${target} PRIVATE -fsanitize=address,undefined,leak)
endif (USE_ASAN)
endfunction()


add_subdirectory("libs")
add_subdirectory("interface")
add_subdirectory("asn.1")
add_subdirectory("generator/rtcm")
add_subdirectory("generator/spartn")
add_subdirectory("generator/spartn2")
add_subdirectory("receiver/ublox")
add_subdirectory("receiver/nmea")
add_subdirectory("examples/ublox")
add_subdirectory("examples/nmea")
add_subdirectory("examples/lpp")
add_subdirectory("examples/lpp2spartn")
add_subdirectory("examples/ntrip")
add_subdirectory("examples/ctrl_switch")
if(${EXPERIMENTAL})
add_subdirectory("examples/client")
endif()
add_subdirectory("interface")
add_subdirectory("receiver")
add_subdirectory("generator")
add_subdirectory("examples")

9 changes: 3 additions & 6 deletions asn.1/helper/bit_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void BitString::initialize(size_t bits) {
auto total_bits = bytes * 8;
auto unused_bits = total_bits - bits;
size = bytes;
assert(unused_bits >= 0);
assert(unused_bits <= 7);
bits_unused = unused_bits;
buf = reinterpret_cast<uint8_t*>(calloc(size, sizeof(uint8_t)));
Expand All @@ -49,9 +48,7 @@ BitString::Index BitString::bit_index(ssize_t index) const {
auto byte_index = size - 1 - byte;
auto local_bit = (bit - byte * 8);

assert(byte_index >= 0);
assert(byte_index < size);
assert(local_bit >= 0);
assert(local_bit < 8);
return {byte_index, local_bit};
}
Expand Down Expand Up @@ -183,10 +180,10 @@ BIT_STRING_s* BitStringBuilder::into_bit_string(size_t bits, BIT_STRING_s* bit_s
BIT_STRING_initialize(bit_string, bits);

assert(bits <= 64);
for (int j = 0; j < 64; j++) {
for (size_t j = 0; j < 64; j++) {
if (mBits & (1llu << j)) {
auto x = j / 8;
auto y = 7 - (j % 8);
size_t x = j / 8;
size_t y = 7 - (j % 8);
assert(x < bit_string->size);
if (x < bit_string->size) {
bit_string->buf[x] |= 1 << y;
Expand Down
11 changes: 11 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

add_subdirectory("ublox")
add_subdirectory("nmea")
add_subdirectory("lpp")
add_subdirectory("lpp2spartn")
add_subdirectory("ntrip")
add_subdirectory("ctrl_switch")

if(${EXPERIMENTAL})
add_subdirectory("client")
endif()
14 changes: 7 additions & 7 deletions examples/client/assistance_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

#define LOGLET_CURRENT_MODULE "client"

static void process_rtcm(const Config& config, lpp::Message message) {
static void process_rtcm(Config const& config, lpp::Message message) {
INFOF("processing RTCM message");
}

static void process_spartn_old(const Config& config, lpp::Message message) {
static void process_spartn_old(Config const& config, lpp::Message message) {
INFOF("processing SPARTN_OLD message");
}

static void process_spartn(const Config& config, lpp::Message message) {
static void process_spartn(Config const& config, lpp::Message message) {
INFOF("processing SPARTN message");
}

static void process_xer(const Config& config, lpp::Message message) {
static void process_xer(Config const& config, lpp::Message message) {
INFOF("processing XER message");
}

static void process_uper(const Config& config, lpp::Message message) {
static void process_uper(Config const& config, lpp::Message message) {
INFOF("processing UPER message");
}

static void process_lpp_rtcm(const Config& config, lpp::Message message) {
static void process_lpp_rtcm(Config const& config, lpp::Message message) {
INFOF("processing LPP_RTCM message");
}

void process_assistance_data(const Config& config, lpp::Message message) {
void process_assistance_data(Config const& config, lpp::Message message) {
INFOF("received assistance data");

switch (config.output_format) {
Expand Down
2 changes: 1 addition & 1 deletion examples/client/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

#include <lpp/message.hpp>

void process_assistance_data(const Config& config, lpp::Message message);
void process_assistance_data(Config const& config, lpp::Message message);
9 changes: 1 addition & 8 deletions examples/ctrl_switch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,5 @@ target_link_libraries(example_ctrl_switch PRIVATE args)
set_target_properties(example_ctrl_switch PROPERTIES OUTPUT_NAME "example-ctrl-switch")
set_target_properties(example_ctrl_switch PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

if (USE_OPENSSL)
target_link_libraries(example_ctrl_switch PRIVATE OpenSSL::SSL)
target_compile_definitions(example_ctrl_switch PRIVATE "USE_OPENSSL=1")
endif (USE_OPENSSL)
setup_target(example_ctrl_switch)

if (USE_ASAN)
target_compile_options(example_ctrl_switch PRIVATE -fsanitize=address,undefined,leak)
target_link_libraries(example_ctrl_switch PRIVATE -fsanitize=address,undefined,leak)
endif (USE_ASAN)
11 changes: 8 additions & 3 deletions examples/ctrl_switch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <sys/socket.h>
#include <unistd.h>

static void loop(Config& config) {
[[noreturn]] static void loop(Config& config) {
printf("[ctrl-switch]\n");

// Open TCP server
Expand All @@ -19,7 +19,10 @@ static void loop(Config& config) {
addr.sin_family = AF_INET;
addr.sin_port = htons(13226);
addr.sin_addr.s_addr = INADDR_ANY;
if (::bind(socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {

auto socket_addr = reinterpret_cast<struct sockaddr*>(&addr);
auto socket_size = static_cast<socklen_t>(sizeof(addr));
if (::bind(socket, socket_addr, socket_size) < 0) {
perror("bind");
exit(1);
}
Expand Down Expand Up @@ -50,7 +53,7 @@ static void loop(Config& config) {

char buffer[1024];
auto length = snprintf(buffer, sizeof(buffer), "%s\r\n", command.c_str());
auto result = ::send(client, buffer, length, MSG_NOSIGNAL);
auto result = ::send(client, buffer, static_cast<size_t>(length), MSG_NOSIGNAL);
if (result < 0) {
printf("write failed\n");
connected = false;
Expand All @@ -70,5 +73,7 @@ static void loop(Config& config) {
int main(int argc, char** argv) {
auto config = parse_configuration(argc, argv);
loop(config);
#if COMPILER_CANNOT_DEDUCE_UNREACHABLE
return 0;
#endif
}
22 changes: 16 additions & 6 deletions examples/ctrl_switch/options.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include "options.hpp"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsuggest-destructor-override"
#pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-dtor"
#pragma GCC diagnostic ignored "-Wnewline-eof"
#pragma GCC diagnostic ignored "-Wmissing-variable-declarations"
#pragma GCC diagnostic ignored "-Winconsistent-missing-destructor-override"
#pragma GCC diagnostic ignored "-Wsuggest-override"
#pragma GCC diagnostic ignored "-Wshadow-field"
#include <args.hpp>
#pragma GCC diagnostic pop

args::Group arguments{"Arguments:"};
args::PositionalList<std::string> commands{arguments, "commands", "List of commands"};
static args::Group arguments{"Arguments:"};
static args::PositionalList<std::string> commands{arguments, "commands", "List of commands"};

Config parse_configuration(int argc, char** argv) {
args::ArgumentParser parser(
Expand All @@ -27,18 +37,18 @@ Config parse_configuration(int argc, char** argv) {
Config config{};
config.commands = commands.Get();
return config;
} catch (const args::ValidationError& e) {
} catch (args::ValidationError const& e) {
std::cerr << e.what() << std::endl;
parser.Help(std::cerr);
exit(1);
} catch (const args::Help&) {
} catch (args::Help const&) {
std::cout << parser;
exit(0);
} catch (const args::ParseError& e) {
} catch (args::ParseError const& e) {
std::cerr << e.what() << std::endl;
std::cerr << parser;
exit(1);
} catch (const std::exception& e) {
} catch (std::exception const& e) {
std::cerr << "Error: " << e.what() << std::endl;
exit(1);
}
Expand Down
23 changes: 16 additions & 7 deletions examples/lpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ add_executable(examples::lpp ALIAS example_lpp)
target_include_directories(example_lpp PRIVATE "./")
target_link_libraries(example_lpp PRIVATE utility modem lpplib Threads::Threads)
target_link_libraries(example_lpp PRIVATE args)
target_link_libraries(example_lpp PRIVATE generator::rtcm)
target_link_libraries(example_lpp PRIVATE generator::spartn)
target_link_libraries(example_lpp PRIVATE generator::spartn2)
target_link_libraries(example_lpp PRIVATE dependency::interface)
target_link_libraries(example_lpp PRIVATE receiver::ublox)
target_link_libraries(example_lpp PRIVATE receiver::nmea)
target_link_libraries(example_lpp PRIVATE asn1::generated asn1::helper)

if(${INCLUDE_GENERATOR_RTCM})
target_compile_definitions(example_lpp PRIVATE "INCLUDE_GENERATOR_RTCM=1")
target_link_libraries(example_lpp PRIVATE generator::rtcm)
endif()

if(${INCLUDE_GENERATOR_SPARTN})
target_compile_definitions(example_lpp PRIVATE "INCLUDE_GENERATOR_SPARTN=1")
target_link_libraries(example_lpp PRIVATE generator::spartn2)
endif()

if(${INCLUDE_GENERATOR_SPARTN_OLD})
target_compile_definitions(example_lpp PRIVATE "INCLUDE_GENERATOR_SPARTN_OLD=1")
target_link_libraries(example_lpp PRIVATE generator::spartn)
endif()

set_target_properties(example_lpp PROPERTIES OUTPUT_NAME "example-lpp")
set_target_properties(example_lpp PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

Expand All @@ -30,7 +42,4 @@ target_link_libraries(example_lpp PRIVATE OpenSSL::SSL)
target_compile_definitions(example_lpp PRIVATE "USE_OPENSSL=1")
endif (USE_OPENSSL)

if (USE_ASAN)
target_compile_options(example_lpp PRIVATE -fsanitize=address,undefined,leak)
target_link_libraries(example_lpp PRIVATE -fsanitize=address,undefined,leak)
endif (USE_ASAN)
setup_target(example_lpp)
Loading

0 comments on commit 91c310e

Please sign in to comment.