├── .bettercodehub.yml ├── .clang-format ├── .dockerignore ├── .gitattributes ├── .github ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── question.md └── pull_request_template.md ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── Dockerfile ├── LICENSE ├── README.md ├── bootstrap.sh ├── build └── .gitkeep ├── docs ├── AUTHORS.md ├── CHANGELOG.md ├── _config.yml ├── _includes │ ├── README.md │ ├── base │ └── pages_list ├── _layouts │ └── default.html ├── assets │ └── header.png ├── configuration.md ├── css │ ├── colors.css │ ├── default.css │ └── syntax.css ├── get-started.html ├── index.html ├── index.md ├── installation.md ├── operation.md └── reports.html ├── healthcheck.sh ├── include ├── VFRB.h ├── client │ ├── AprscClient.h │ ├── Client.h │ ├── ClientFactory.h │ ├── ClientManager.h │ ├── GpsdClient.h │ ├── SbsClient.h │ ├── SensorClient.h │ └── net │ │ ├── Connector.hpp │ │ ├── Endpoint.hpp │ │ └── impl │ │ └── ConnectorImplBoost.h ├── config │ ├── ConfigReader.h │ ├── Configuration.h │ └── Properties.h ├── data │ ├── AircraftData.h │ ├── AtmosphereData.h │ ├── Data.hpp │ ├── GpsData.h │ ├── WindData.h │ └── processor │ │ ├── AircraftProcessor.h │ │ ├── GpsProcessor.h │ │ └── Processor.hpp ├── feed │ ├── AprscFeed.h │ ├── AtmosphereFeed.h │ ├── Feed.h │ ├── FeedFactory.h │ ├── GpsFeed.h │ ├── SbsFeed.h │ ├── WindFeed.h │ └── parser │ │ ├── AprsParser.h │ │ ├── AtmosphereParser.h │ │ ├── GpsParser.h │ │ ├── Parser.hpp │ │ ├── SbsParser.h │ │ └── WindParser.h ├── object │ ├── Aircraft.h │ ├── Atmosphere.h │ ├── GpsPosition.h │ ├── Object.h │ ├── TimeStamp.hpp │ ├── Wind.h │ └── impl │ │ └── DateTimeImplBoost.h ├── parameters.h ├── server │ ├── Connection.hpp │ ├── Server.hpp │ └── net │ │ ├── NetworkInterface.hpp │ │ ├── SocketException.h │ │ └── impl │ │ ├── NetworkInterfaceImplBoost.h │ │ └── SocketImplBoost.h └── util │ ├── Logger.hpp │ ├── SignalListener.h │ ├── defines.h │ ├── math.hpp │ └── utility.hpp ├── run.sh ├── src ├── VFRB.cpp ├── client │ ├── AprscClient.cpp │ ├── Client.cpp │ ├── ClientFactory.cpp │ ├── ClientManager.cpp │ ├── GpsdClient.cpp │ ├── SbsClient.cpp │ ├── SensorClient.cpp │ └── net │ │ └── impl │ │ └── ConnectorImplBoost.cpp ├── config │ ├── ConfigReader.cpp │ ├── Configuration.cpp │ └── Properties.cpp ├── data │ ├── AircraftData.cpp │ ├── AtmosphereData.cpp │ ├── GpsData.cpp │ ├── WindData.cpp │ └── processor │ │ ├── AircraftProcessor.cpp │ │ └── GpsProcessor.cpp ├── feed │ ├── AprscFeed.cpp │ ├── AtmosphereFeed.cpp │ ├── Feed.cpp │ ├── FeedFactory.cpp │ ├── GpsFeed.cpp │ ├── SbsFeed.cpp │ ├── WindFeed.cpp │ └── parser │ │ ├── AprsParser.cpp │ │ ├── AtmosphereParser.cpp │ │ ├── GpsParser.cpp │ │ ├── SbsParser.cpp │ │ └── WindParser.cpp ├── main.cpp ├── object │ ├── Aircraft.cpp │ ├── Atmosphere.cpp │ ├── GpsPosition.cpp │ ├── Object.cpp │ ├── Wind.cpp │ └── impl │ │ └── DateTimeImplBoost.cpp ├── server │ └── net │ │ ├── SocketException.cpp │ │ └── impl │ │ ├── NetworkInterfaceImplBoost.cpp │ │ └── SocketImplBoost.cpp └── util │ ├── Logger.cpp │ └── SignalListener.cpp ├── test ├── DateTimeImplTest.cpp ├── NetworkInterfaceImplTest.cpp ├── README.md ├── SocketImplTest.cpp ├── TestClient.cpp ├── TestConfig.cpp ├── TestData.cpp ├── TestDataProcessor.cpp ├── TestFeed.cpp ├── TestFeedParser.cpp ├── TestMath.cpp ├── TestObject.cpp ├── TestServer.cpp ├── UnitTests.cpp ├── include │ ├── DateTimeImplTest.h │ ├── NetworkInterfaceImplTest.h │ ├── SocketImplTest.h │ └── helper.hpp └── resources │ ├── invalid.ini │ ├── regression.sh │ ├── server.lua │ └── test.ini ├── version.txt ├── vfrb.ini.in └── vfrb.service.in /.bettercodehub.yml: -------------------------------------------------------------------------------- 1 | component_depth: 3 2 | languages: 3 | - cpp 4 | exclude: 5 | - /include/.* -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | Language: Cpp 2 | Standard: Cpp11 3 | AccessModifierOffset: -4 4 | AlignAfterOpenBracket: Align 5 | AlignConsecutiveAssignments: true 6 | AlignConsecutiveDeclarations: true 7 | AlignEscapedNewlines: Left 8 | AlignOperands: true 9 | AlignTrailingComments: true 10 | AllowAllParametersOfDeclarationOnNextLine: true 11 | AllowShortBlocksOnASingleLine: false 12 | AllowShortCaseLabelsOnASingleLine: true 13 | AllowShortFunctionsOnASingleLine: Empty 14 | AllowShortIfStatementsOnASingleLine: true 15 | AllowShortLoopsOnASingleLine: true 16 | AlwaysBreakAfterReturnType: None 17 | AlwaysBreakBeforeMultilineStrings: false 18 | AlwaysBreakTemplateDeclarations: true 19 | BinPackArguments: true 20 | BinPackParameters: true 21 | BreakBeforeBraces: Custom 22 | BraceWrapping: 23 | AfterClass: true 24 | AfterControlStatement: true 25 | AfterEnum: true 26 | AfterFunction: true 27 | AfterNamespace: true 28 | AfterStruct: true 29 | AfterUnion: true 30 | AfterExternBlock: true 31 | BeforeCatch: true 32 | BeforeElse: true 33 | IndentBraces: false 34 | SplitEmptyFunction: false 35 | SplitEmptyRecord: false 36 | SplitEmptyNamespace: false 37 | BreakBeforeBinaryOperators: None 38 | BreakBeforeInheritanceComma: false 39 | BreakBeforeTernaryOperators: false 40 | BreakConstructorInitializers: BeforeColon 41 | BreakStringLiterals: false 42 | ColumnLimit: 100 43 | CompactNamespaces: false 44 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 45 | ConstructorInitializerIndentWidth: 4 46 | ContinuationIndentWidth: 4 47 | Cpp11BracedListStyle: true 48 | DerivePointerAlignment: false 49 | DisableFormat: false 50 | FixNamespaceComments: true 51 | ForEachMacros: ['FOREACH', 'BOOST_FOREACH'] 52 | IncludeBlocks: Regroup 53 | IncludeCategories: 54 | - Regex: '^> /etc/apt/sources.list" 18 | 19 | script: 20 | # build production docker image 21 | - ./run.sh docker 22 | # prepare cicd docker image 23 | - docker exec -it vfrb sh -c "mkdir -p $TRAVIS_BUILD_DIR" 24 | - docker exec -it vfrb sh -c "cp -r /travis/. $TRAVIS_BUILD_DIR" 25 | # run build and tests 26 | - docker exec -it vfrb sh -c "$TRAVIS_BUILD_DIR/run.sh build test -y" 27 | # copy reports back 28 | - docker exec -it vfrb sh -c "cp -r $TRAVIS_BUILD_DIR/reports /travis/" 29 | - docker exec -it vfrb sh -c "chown $(id -u):$(id -g) -R /travis/reports" 30 | - docker stop vfrb 31 | 32 | after_success: 33 | - bash <(curl -s https://codecov.io/bash) 34 | 35 | notifications: 36 | email: 37 | recipients: 38 | - jarthianur.github@gmail.com 39 | on_success: change 40 | on_failure: change 41 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.7.2) 2 | project(VirtualFlightRadar-Backend LANGUAGES CXX) 3 | 4 | message(STATUS "We are on a ${CMAKE_SYSTEM_NAME} system") 5 | message(STATUS "The host processor is ${CMAKE_HOST_SYSTEM_PROCESSOR}") 6 | 7 | # 8 | # definitions 9 | # 10 | 11 | file(READ ${PROJECT_SOURCE_DIR}/version.txt TMP_VERSION) 12 | string(STRIP "${TMP_VERSION}" CMAKE_PROJECT_VERSION) 13 | 14 | if(NOT DEFINED VFRB_BIN_TAG) 15 | set(VFRB_BIN_TAG "${CMAKE_PROJECT_VERSION}-${CMAKE_HOST_SYSTEM_PROCESSOR}") 16 | endif() 17 | 18 | set(vfrb_prod_bin vfrb-${VFRB_BIN_TAG}) 19 | set(vfrb_regression_bin vfrb_regression-${VFRB_BIN_TAG}) 20 | set(vfrb_test_bin vfrb_test-${VFRB_BIN_TAG}) 21 | 22 | set(THREADS_PREFER_PTHREAD_FLAG ON) 23 | set(CMAKE_CXX_STANDARD 14) 24 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 25 | set(CMAKE_CXX_EXTENSIONS OFF) 26 | 27 | file(GLOB_RECURSE vfrb_sources src/*.cpp) 28 | file(GLOB_RECURSE vfrb_test_sources test/*.cpp) 29 | 30 | set(CMAKE_BUILD_TYPE staged) 31 | set(CMAKE_CXX_FLAGS_STAGED "-Wall -Wextra -Wpedantic") 32 | 33 | if(DEFINED BOOST_STATIC) 34 | message(STATUS "Linking boost statically") 35 | set(Boost_USE_STATIC_LIBS ON) 36 | endif() 37 | 38 | # 39 | # dependencies 40 | # 41 | 42 | find_package(Boost REQUIRED COMPONENTS regex system program_options) 43 | find_package(Threads REQUIRED) 44 | 45 | # 46 | # target: release 47 | # 48 | add_executable(release ${vfrb_sources}) 49 | set_target_properties(release PROPERTIES OUTPUT_NAME ${vfrb_prod_bin}) 50 | target_compile_options(release PUBLIC -O2 -DNDEBUG -DVERSION=\"${CMAKE_PROJECT_VERSION}\") 51 | target_include_directories(release PUBLIC ${PROJECT_SOURCE_DIR}/include) 52 | target_link_libraries(release PUBLIC Boost::regex Boost::system Boost::program_options Threads::Threads) 53 | 54 | # 55 | # target: regression 56 | # 57 | add_executable(regression ${vfrb_sources}) 58 | set_target_properties(regression PROPERTIES OUTPUT_NAME ${vfrb_regression_bin}) 59 | target_compile_options(regression PUBLIC -O0 -g --coverage -DLOG_ENABLE_DEBUG -DVERSION=\"${CMAKE_PROJECT_VERSION}\" -DAPRSCCLIENT_BEACON_INTERVAL=1 -DCLIENT_CONNECT_WAIT_TIMEVAL=2) 60 | target_include_directories(regression PUBLIC ${PROJECT_SOURCE_DIR}/include) 61 | target_link_libraries(regression PUBLIC Boost::regex Boost::system Boost::program_options Threads::Threads gcov) 62 | 63 | # 64 | # target: test 65 | # 66 | list(REMOVE_ITEM vfrb_sources ${PROJECT_SOURCE_DIR}/src/main.cpp) 67 | list(APPEND vfrb_test_sources ${vfrb_sources}) 68 | add_executable(unittest ${vfrb_test_sources}) 69 | set_target_properties(unittest PROPERTIES OUTPUT_NAME ${vfrb_test_bin}) 70 | target_compile_options(unittest PUBLIC -O0 -g --coverage -fopenmp -DLOG_ENABLE_DEBUG -DSCTF_CUSTOM_EPSILON=0.000001) 71 | target_include_directories(unittest PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/test/include ${PROJECT_SOURCE_DIR}/test/framework) 72 | target_link_libraries(unittest PUBLIC Boost::regex Boost::system Boost::program_options Threads::Threads gcov gomp) 73 | 74 | # 75 | # target: install 76 | # 77 | set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true) 78 | install(CODE "file(READ ${PROJECT_SOURCE_DIR}/vfrb.service.in service_file_data)\n 79 | string(REPLACE \"%VFRB_EXEC_PATH%\" \"${PROJECT_BINARY_DIR}/${vfrb_prod_bin}\" service_file_data \"\${service_file_data}\")\n 80 | string(REPLACE \"%VFRB_INI_PATH%\" \"${PROJECT_BINARY_DIR}/$ENV{VFRB_INI}\" service_file_data \"\${service_file_data}\")\n 81 | file(WRITE /etc/systemd/system/vfrb.service \"\${service_file_data}\")") 82 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.8 AS build 2 | 3 | ENV VFRB_LINK_STATIC="yes" \ 4 | VFRB_BIN_TAG="dock" 5 | 6 | RUN apk add --no-cache bash 7 | 8 | COPY . /tmp/vfrb/ 9 | RUN echo -en "$VFRB_BIN_TAG" > /tmp/vfrb/version.txt 10 | WORKDIR /tmp/vfrb 11 | RUN ./run.sh build -y 12 | RUN mkdir /opt && \ 13 | mv build/vfrb-dock healthcheck.sh /opt/ && \ 14 | mv vfrb.ini.in /opt/vfrb.ini 15 | 16 | FROM alpine:3.8 17 | 18 | LABEL maintainer="Jarthianur " \ 19 | app="VirtualFlightRadar-Backend" \ 20 | description="VirtualFlightRadar-Backend running in a docker container." \ 21 | url="https://github.com/Jarthianur/VirtualFlightRadar-Backend" 22 | 23 | EXPOSE 4353 24 | 25 | RUN apk add --no-cache libstdc++ curl 26 | 27 | COPY --from=build /opt/* /opt/ 28 | 29 | HEALTHCHECK --interval=5m \ 30 | --timeout=10s \ 31 | --start-period=10s \ 32 | --retries=1 \ 33 | CMD [ "/opt/healthcheck.sh" ] 34 | 35 | ENTRYPOINT [ "/opt/vfrb-dock", "-c", "/opt/vfrb.ini" ] 36 | -------------------------------------------------------------------------------- /build/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarthianur/VirtualFlightRadar-Backend/7c8db16b1e4d9117c3810448f77a41661885266c/build/.gitkeep -------------------------------------------------------------------------------- /docs/AUTHORS.md: -------------------------------------------------------------------------------- 1 | # VirtualFlightRadar-Backend 2 | 3 | ## Copyright (C) 2016 VirtualFlightRadar-Backend 4 | 5 | ### The following people and organizations have contributed code to "VirtualFlightRadar-Backend": 6 | 7 | + Julian Becht (Jarthianur) 8 | 9 | ### The following people and organizations have helped by testing or developing the basic concept: 10 | 11 | + Wolfram Zirngibl -------------------------------------------------------------------------------- /docs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # changelog 2 | 3 | ## 3.0.3 4 | 5 | + changed default compiler optimization level to 2 6 | 7 | ## 3.0.2 8 | 9 | + fixed client timeout handling 10 | + some internal interface changes for client 11 | 12 | ## 3.0.1 13 | 14 | + restructuring code 15 | + build with cmake 16 | + small changes in client 17 | 18 | ## 3.0.0 19 | 20 | + improved priority handling of feeds 21 | + take timestamps into account 22 | + a lot of internal code changes 23 | + several bugfixes 24 | + option to log into file 25 | + option for debug logging 26 | + split sensor feeds to wind and atmosphere 27 | + improved connection handling 28 | 29 | ## 2.2.0 30 | 31 | + new code documentation 32 | + new github pages 33 | + internal class representation changed (Feed, Parser) 34 | + integrated coveralls 35 | + more tests 36 | 37 | ### 2.1.0 38 | 39 | + support GPSD 40 | + common sensor interface (support [BME280 driver](https://github.com/Jarthianur/sensorics)) 41 | + generic input feeds 42 | + ! configuration refactoring 43 | 44 | ### 2.0.1 45 | 46 | + latitude/longitude parsing fixed 47 | 48 | ### 2.0.0 49 | 50 | + integrate boost 51 | + major refactoring, packaging 52 | + changed logging format 53 | + changed config format 54 | + signal handling 55 | + disable filters via properties 56 | + systemd service 57 | + installation script 58 | + unit tests 59 | 60 | ### 1.3.0 61 | 62 | + ADS-B (SBS) input 63 | + APRS (OGN flavor) input 64 | + Wind input and output (WIMWV, WIMDA NMEA sentences) 65 | + height, distance filters 66 | + static GPS output 67 | + PFLAU / PFLAA NMEA output 68 | + all I/O's and parameters are configurable via config file 69 | + multi client support -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | title: VirtualFlightRadar-Backend 2 | markdown: kramdown 3 | kramdown: 4 | input: GFM 5 | hard_wrap: false 6 | syntax_highlighter: rouge 7 | highlighter: rouge 8 | gems: 9 | - jekyll-sitemap 10 | -------------------------------------------------------------------------------- /docs/_includes/README.md: -------------------------------------------------------------------------------- 1 | Include files stay here -------------------------------------------------------------------------------- /docs/_includes/base: -------------------------------------------------------------------------------- 1 | {% assign base = '' %} 2 | {% assign depth = page.url | split: '/' | size | minus: 1 %} 3 | {% if depth <= 1 %}{% assign base = '.' %} 4 | {% elsif depth == 2 %}{% assign base = '..' %} 5 | {% elsif depth == 3 %}{% assign base = '../..' %} 6 | {% elsif depth == 4 %}{% assign base = '../../..' %}{% endif %} -------------------------------------------------------------------------------- /docs/_includes/pages_list: -------------------------------------------------------------------------------- 1 | {% assign pages_list = pages_list | sort:"grp_index" %} 2 | {% for node in pages_list %} 3 | {% if group == null or group == node.group %} 4 | {% if page.url == node.url or node.sub_urls contains page.url %} 5 | {{node.title}} 6 | {% else %} 7 | {{node.title}} 8 | {% endif %} 9 | {% endif %} 10 | {% endfor %} 11 | {% assign pages_list = nil %} 12 | {% assign group = nil %} -------------------------------------------------------------------------------- /docs/_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | {{ site.title }} 18 | 19 | 20 | 21 |
22 |
23 | 24 | 29 |
30 | 31 | Fork me on GitHub 34 | 35 |
36 | 41 |
42 | {{ content }} 43 |
44 |
45 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /docs/assets/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarthianur/VirtualFlightRadar-Backend/7c8db16b1e4d9117c3810448f77a41661885266c/docs/assets/header.png -------------------------------------------------------------------------------- /docs/configuration.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | ## Note 4 | 5 | The configuration file must be a valid `.ini` file. Thus there are sections, key-value parameters and comments. 6 | Comments start with `;`. Parameters are of kind `key = value`, 7 | where several spaces between the key, value and the equal-sign are allowed. 8 | The first non-whitespace character after the equal-sign determines the beginning of the value, 9 | all following characters, including spaces, are taken as part of the value. 10 | Sections start with `[section]`. Until the next section all following parameters are part of that section. 11 | 12 | ## What To Configure 13 | 14 | The *ini* file looks like this 15 | >[general] 16 | feeds = sbs1,gps 17 | serverPort = 4353 18 | gndMode = 19 | [fallback] 20 | latitude = 50.000000 21 | longitude = 10.000000 22 | altitude = 100 23 | geoid = 48.0 24 | pressure = 1013.25 25 | [filter] 26 | maxHeight = -1 27 | maxDist = 40000 28 | [sbs1] 29 | host = localhost 30 | port = 1234 31 | priority = 0 32 | ... 33 | 34 | All the parameters and sections should be self explanatory. 35 | 36 | ### [general] 37 | 38 | The `feeds` parameter is one of the most important, because here are the input feeds defined. 39 | It is a comma-separated list, spaces are allowed. The feed type is determined by keywords in its name. 40 | Therefore the entries must contain one of the following keywords 41 | 42 | + aprs 43 | + sbs 44 | + wind 45 | + atm 46 | + gps 47 | 48 | To enable the [Ground-Mode](#ground-mode), just assign any value to `gndMode`, to disable leave it empty. 49 | `serverPort` defines the port where to serve the NMEA reports. 50 | 51 | ### [fallback] 52 | 53 | Here the static fallback values for Your GPS position and the local air pressure are defined. 54 | The pressure is necessary in order to correctly evaluate the altitude given from ADSB (transponder) targets. 55 | 56 | ### [filter] 57 | 58 | Here the filters for height and distance of aircrafts are defined. 59 | To disable a filter leave its value empty, or explicitly set it to `-1`. 60 | Aircrafts beeing filtered out will not be reported. 61 | 62 | ### Per Feed Entry Section (e.g. [sbs1]) 63 | 64 | Every entry in the `feeds` list needs its own section, with exactly the same name as in the list. 65 | If a feed has not all required parameters defined, or the section can not be found or evaluated, that feed will not be run. 66 | The parameters for a feed section are 67 | 68 | + host 69 | + port 70 | + priority 71 | + login 72 | 73 | Where `login` is only required for APRS feeds. `host` and `port` define the hostname /-address and port to connect to. 74 | `priority` defines the priority relative to all other feeds of the same type, therefor is only required if multiple feeds of same type exist. 75 | If multiple feeds of the same type use the same host, port combination, only one connection is used and thus shared betweeen them. 76 | The priority is an integer, where a higher value means a higher priority. 77 | 78 | #### Ground-Mode 79 | 80 | This is a feature that aims to let You stay independent with Your position, but operating static though. 81 | If You have a GPS feed in use, there is no need to set Your position in the fallbacks. 82 | But also, if You operate at a static position, there is no need to receive (possibly jumping) GPS positions all the time. 83 | By activating the Ground-Mode, You tell VFR-B to stop the GPS feed as soon as it receives a "good" position. 84 | -------------------------------------------------------------------------------- /docs/css/colors.css: -------------------------------------------------------------------------------- 1 | .ral-yellow, 2 | .ral-hover-yellow:hover { 3 | color: #fff; 4 | background-color: #f7ba0b 5 | } 6 | 7 | .ral-orange, 8 | .ral-hover-orange:hover { 9 | color: #fff; 10 | background-color: #d4652f 11 | } 12 | 13 | .ral-red, 14 | .ral-hover-red:hover { 15 | color: #fff; 16 | background-color: #a02128 17 | } 18 | 19 | .ral-violet, 20 | .ral-hover-violet:hover { 21 | color: #fff; 22 | background-color: #904684 23 | } 24 | 25 | .ral-blue, 26 | .ral-hover-blue:hover { 27 | color: #fff; 28 | background-color: #154889 29 | } 30 | 31 | .ral-green, 32 | .ral-hover-green:hover { 33 | color: #fff; 34 | background-color: #317f43 35 | } 36 | 37 | .ral-grey, 38 | .ral-hover-grey:hover { 39 | color: #fff; 40 | background-color: #9b9b9b 41 | } 42 | 43 | .ral-brown, 44 | .ral-hover-brown:hover { 45 | color: #fff; 46 | background-color: #7b5141 47 | } 48 | 49 | .ral-white, 50 | .ral-hover-white:hover { 51 | color: #000; 52 | background-color: #ecece7 53 | } 54 | 55 | .ral-black, 56 | .ral-hover-black:hover { 57 | color: #fff; 58 | background-color: #282828 59 | } 60 | 61 | .ral-steel-blue, 62 | .ral-hover-steel-blue:hover { 63 | color: #fff; 64 | background-color: #1a2b3c 65 | } 66 | 67 | .ral-sky-blue, 68 | .ral-hover-sky-blue:hover { 69 | color: #fff; 70 | background-color: #007cb0 71 | } 72 | 73 | .ral-lumi-green, 74 | .ral-hover-lumi-green:hover { 75 | color: #282828; 76 | background-color: #00b51a 77 | } 78 | 79 | .ral-text-yellow, 80 | .ral-text-hover-yellow:hover { 81 | color: #f7ba0b 82 | } 83 | 84 | .ral-text-orange, 85 | .ral-text-hover-orange:hover { 86 | color: #d4652f 87 | } 88 | 89 | .ral-text-red, 90 | .ral-text-hover-red:hover { 91 | color: #a02128 92 | } 93 | 94 | .ral-text-violet, 95 | .ral-text-hover-violet:hover { 96 | color: #904684 97 | } 98 | 99 | .ral-text-blue, 100 | .ral-text-hover-blue:hover { 101 | color: #154889 102 | } 103 | 104 | .ral-text-green, 105 | .ral-text-hover-green:hover { 106 | color: #317f43 107 | } 108 | 109 | .ral-text-grey, 110 | .ral-text-hover-grey:hover { 111 | color: #9b9b9b 112 | } 113 | 114 | .ral-text-brown, 115 | .ral-text-hover-brown:hover { 116 | color: #7b5141 117 | } 118 | 119 | .ral-text-white, 120 | .ral-text-hover-white:hover { 121 | color: #f4f4f4 122 | } 123 | 124 | .ral-text-black, 125 | .ral-text-hover-black:hover { 126 | color: #282828 127 | } 128 | 129 | .ral-text-steel-blue, 130 | .ral-text-hover-steel-blue:hover { 131 | color: #1a2b3c 132 | } 133 | 134 | .ral-text-sky-blue, 135 | .ral-text-hover-sky-blue:hover { 136 | color: #007cb0 137 | } 138 | 139 | .ral-text-lumi-green, 140 | .ral-text-hover-lumi-green:hover { 141 | color: #00b51a 142 | } -------------------------------------------------------------------------------- /docs/css/default.css: -------------------------------------------------------------------------------- 1 | body { 2 | height: 100% 3 | } 4 | 5 | a { 6 | text-decoration: none; 7 | color: #008000 8 | } 9 | 10 | a:hover { 11 | text-decoration: underline; 12 | color: #00b51a; 13 | } 14 | 15 | .not-a, .not-a:hover { 16 | text-decoration: none; 17 | } 18 | 19 | * { 20 | font-family: 'Inconsolata', monospace !important; 21 | } -------------------------------------------------------------------------------- /docs/css/syntax.css: -------------------------------------------------------------------------------- 1 | .highlight table td { 2 | padding: 5px; 3 | } 4 | 5 | .highlight table pre { 6 | margin: 0; 7 | } 8 | 9 | .highlight, 10 | .highlight .w { 11 | color: #00b51a; 12 | background-color: #282828; 13 | } 14 | 15 | .highlight .err { 16 | color: #fb4934; 17 | background-color: #282828; 18 | font-weight: bold; 19 | } 20 | 21 | .highlight .c, 22 | .highlight .cd, 23 | .highlight .cm, 24 | .highlight .c1, 25 | .highlight .cs { 26 | color: #928374; 27 | font-style: italic; 28 | } 29 | 30 | .highlight .cp { 31 | color: #8ec07c; 32 | } 33 | 34 | .highlight .nt { 35 | color: #fb4934; 36 | } 37 | 38 | .highlight .o, 39 | .highlight .ow { 40 | color: #fbf1c7; 41 | } 42 | 43 | .highlight .p, 44 | .highlight .pi { 45 | color: #fbf1c7; 46 | } 47 | 48 | .highlight .gi { 49 | color: #b8bb26; 50 | background-color: #282828; 51 | } 52 | 53 | .highlight .gd { 54 | color: #fb4934; 55 | background-color: #282828; 56 | } 57 | 58 | .highlight .gh { 59 | color: #b8bb26; 60 | font-weight: bold; 61 | } 62 | 63 | .highlight .k, 64 | .highlight .kn, 65 | .highlight .kp, 66 | .highlight .kr, 67 | .highlight .kv { 68 | color: #fb4934; 69 | } 70 | 71 | .highlight .kc { 72 | color: #d3869b; 73 | } 74 | 75 | .highlight .kt { 76 | color: #fabd2f; 77 | } 78 | 79 | .highlight .kd { 80 | color: #fe8019; 81 | } 82 | 83 | .highlight .s, 84 | .highlight .sb, 85 | .highlight .sc, 86 | .highlight .sd, 87 | .highlight .s2, 88 | .highlight .sh, 89 | .highlight .sx, 90 | .highlight .s1 { 91 | color: #b8bb26; 92 | font-style: italic; 93 | } 94 | 95 | .highlight .si { 96 | color: #b8bb26; 97 | font-style: italic; 98 | } 99 | 100 | .highlight .sr { 101 | color: #b8bb26; 102 | font-style: italic; 103 | } 104 | 105 | .highlight .se { 106 | color: #fe8019; 107 | } 108 | 109 | .highlight .nn { 110 | color: #8ec07c; 111 | } 112 | 113 | .highlight .nc { 114 | color: #8ec07c; 115 | } 116 | 117 | .highlight .no { 118 | color: #d3869b; 119 | } 120 | 121 | .highlight .na { 122 | color: #b8bb26; 123 | } 124 | 125 | .highlight .m, 126 | .highlight .mf, 127 | .highlight .mh, 128 | .highlight .mi, 129 | .highlight .il, 130 | .highlight .mo, 131 | .highlight .mb, 132 | .highlight .mx { 133 | color: #d3869b; 134 | } 135 | 136 | .highlight .ss { 137 | color: #83a598; 138 | } 139 | 140 | .highlighter-rouge { 141 | color: #a02128; 142 | } -------------------------------------------------------------------------------- /docs/get-started.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: 'GET STARTED' 4 | group: 'navigation' 5 | grp_index: 2 6 | sub_urls: ['/installation.html', '/configuration.html', '/operation.html'] 7 | --- 8 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: 'HOME' 4 | group: 'navigation' 5 | grp_index: 1 6 | sub_urls: ['/CHANGELOG.html'] 7 | --- 8 |
9 |
-------------------------------------------------------------------------------- /docs/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | All necessary dependencies and build steps are automated in the `run.sh` file. 4 | To build the VFRB execute `./run.sh build` in bash. 5 | If you want to specify build paths etc, just follow the description from `run.sh --help`. 6 | 7 | ## Install 8 | 9 | ### Manually 10 | 11 | Clone or download this repository. 12 | Before installing the program, you may adjust the values in 13 | [parameters.h](https://github.com/Jarthianur/VirtualFlightRadar-Backend/blob/master/include/parameters.h). 14 | These parameters have to stay fixed, so they can not be changed after compilation. 15 | Please read the comments carefully, as these values change the programs behavior, or may even break it. 16 | 17 | #### From inside the projects root directory follow these steps 18 | 19 | Either adjust the [vfrb.ini.in](https://github.com/Jarthianur/VirtualFlightRadar-Backend/blob/master/vfrb.ini.in) 20 | file right now to deploy it ready-to-use, or edit the final *vfrb.ini* file later. 21 | Next run `./run.sh build install [options]` and look at its output if you want it as a systemd service. 22 | If all requirements are met, the VFR-B was successfully built and a systemd service was properly configured. 23 | All built files and the config can be found in `build`. 24 | 25 | If not already done, now the runtime configuration must be specified in the target `.ini` file. 26 | 27 | #### Example 28 | 29 | ```bash 30 | ./run.sh build install --ini=custom.ini -y 31 | ``` 32 | 33 | ### Prebuilt 34 | 35 | There are prebuilt binaries available per release, at least for the RaspberryPi. 36 | Download the right one and put it where ever you want it to stay. 37 | Of course you need to write an `.ini` file. 38 | 39 | ### Docker 40 | 41 | If you want to run this application containerized, using docker, there is a task which creates a minimal docker image. 42 | Simply run `./run.sh docker` to build the image. Whilst the image creation process, the *vfrb.ini* file is copied into the image. 43 | This allows to create an image with complete configuration done and without the need to touch the file later. 44 | Please pay attention to your network setup, as "localhost" refers to the docker container and not the actual host. 45 | Hence use the actual IP address of your host for all services that run there. Also the internal port must stay at 4353. 46 | -------------------------------------------------------------------------------- /docs/operation.md: -------------------------------------------------------------------------------- 1 | # Operation - How To Run 2 | 3 | ## Manually 4 | 5 | ```bash 6 | {path to binary} -c {path to config file} -o {path to log file} & 7 | ``` 8 | 9 | ### Example 10 | 11 | ```bash 12 | ./vfrb -c vfrb.ini -o vfrb.log & 13 | ``` 14 | 15 | The log will be in the specified file. 16 | 17 | ## As Service 18 | 19 | By invoking `./run.sh install`, the systemd service for VFR-B was automatically configured to start after boot. 20 | 21 | ### Watch the log with 22 | 23 | ```bash 24 | journalctl -u {servicename}.service 25 | ``` 26 | 27 | ## Commandline arguments 28 | 29 | VFRB supports a few commandline arguments to control its behavior. 30 | 31 | | Argument | Explanation | 32 | | -- | -- | 33 | |-h / --help| Show an overview of all arguments and their usage.| 34 | |-c / --config | Set the configuration file to use.| 35 | |-v / --verbose| Enable debug logging | 36 | |-g / --ground-mode| Forcibly enable ground mode. | 37 | |-o / --output| Set a file where to pu all the logs. | 38 | 39 | ## Run as docker container 40 | 41 | Assuming the docker image was built correctly as described [here](installation.md), 42 | you can run the VFRB inside a minimal container without messing up your host with dependencies or whatever. 43 | Also you can run the VFRB on any platform you like, wherever docker is available. 44 | To run a docker container execute like `docker run --name VFRB -p :4353 -dit user/vfrb:latest [OPTIONS]`. 45 | Where *PORT* can be any port you like and *OPTIONS* can be any VFRB commandline argument, except for *-c*. 46 | -------------------------------------------------------------------------------- /docs/reports.html: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: 'REPORTS' 4 | group: 'navigation' 5 | grp_index: 3 6 | sub_urls: [] 7 | --- 8 | -------------------------------------------------------------------------------- /healthcheck.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl -m 2 -f -s -o /dev/null localhost:4353 4 | err=$? 5 | if [ $err -eq 28 ] || [ $err -eq 52 ]; then 6 | exit 0 7 | fi 8 | exit 1 9 | -------------------------------------------------------------------------------- /include/VFRB.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "server/Server.hpp" 31 | #include "server/net/impl/NetworkInterfaceImplBoost.h" 32 | #include "server/net/impl/SocketImplBoost.h" 33 | #include "util/defines.h" 34 | 35 | namespace config 36 | { 37 | class Configuration; 38 | } // namespace config 39 | namespace data 40 | { 41 | class AircraftData; 42 | class AtmosphereData; 43 | class GpsData; 44 | class WindData; 45 | } // namespace data 46 | namespace feed 47 | { 48 | class Feed; 49 | } // namespace feed 50 | 51 | /** 52 | * @brief Combine all features and is the main entry point for the actual VFR-B. 53 | */ 54 | class VFRB 55 | { 56 | public: 57 | NOT_COPYABLE(VFRB) 58 | DEFAULT_DTOR(VFRB) 59 | 60 | /** 61 | * @brief Constructor 62 | * @param config The Configuration 63 | */ 64 | explicit VFRB(std::shared_ptr config); 65 | 66 | /** 67 | * @brief The VFRB's main method, runs the VFR-B. 68 | */ 69 | void run() noexcept; 70 | 71 | private: 72 | /** 73 | * @brief Create all input feeds. 74 | * @param config The Configuration 75 | */ 76 | void createFeeds(std::shared_ptr config); 77 | 78 | /** 79 | * @brief Serve the data frequently every second. 80 | */ 81 | void serve(); 82 | 83 | /** 84 | * @brief Get the duration from given start value as formatted string. 85 | * @param start The start value 86 | * @return the duration string 87 | */ 88 | std::string get_duration(std::chrono::steady_clock::time_point start) const; 89 | 90 | /// Aircraft container 91 | std::shared_ptr m_aircraftData; 92 | 93 | /// Atmospheric data container 94 | std::shared_ptr m_atmosphereData; 95 | 96 | /// GPS data container 97 | std::shared_ptr m_gpsData; 98 | 99 | /// Wind data container 100 | std::shared_ptr m_windData; 101 | 102 | /// Manage clients and sending of data 103 | server::Server m_server; 104 | 105 | /// List of all active feeds 106 | std::list> m_feeds; 107 | 108 | /// Atomic run-status. 109 | std::atomic m_running; 110 | }; 111 | -------------------------------------------------------------------------------- /include/client/AprscClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "Client.h" 27 | #include "parameters.h" 28 | 29 | #ifdef APRSCCLIENT_BEACON_INTERVAL 30 | # define AC_BEACON_INT APRSCCLIENT_BEACON_INTERVAL 31 | #else 32 | # define AC_BEACON_INT 600 33 | #endif 34 | 35 | namespace client 36 | { 37 | /** 38 | * @brief Client for APRSC servers 39 | */ 40 | class AprscClient : public Client 41 | { 42 | public: 43 | NOT_COPYABLE(AprscClient) 44 | DEFAULT_DTOR(AprscClient) 45 | 46 | /** 47 | * @brief Constructor 48 | * @param endpoint The remote endpoint 49 | * @param login The login string 50 | * @param connector The Connector interface 51 | */ 52 | AprscClient(const net::Endpoint& endpoint, const std::string& login, 53 | std::shared_ptr connector); 54 | 55 | bool equals(const Client& other) const override; 56 | 57 | std::size_t hash() const override; 58 | 59 | private: 60 | /** 61 | * @brief Schedule sending of a keep-alive beacon. 62 | */ 63 | void sendKeepAlive(); 64 | 65 | /** 66 | * @brief Implement Client::handleConnect 67 | * @threadsafe 68 | */ 69 | void handleConnect(net::ErrorCode error) override; 70 | 71 | /** 72 | * @brief Handler for sending of the login string. 73 | * @param error The error indicator 74 | * @threadsafe 75 | */ 76 | void handleLogin(net::ErrorCode error); 77 | 78 | /** 79 | * @brief Handler for sending a keep-alive beacon. 80 | * @param error The error indicator 81 | * @threadsafe 82 | */ 83 | void handleSendKeepAlive(net::ErrorCode error); 84 | 85 | /// Login string 86 | const std::string m_login; 87 | }; 88 | 89 | } // namespace client 90 | -------------------------------------------------------------------------------- /include/client/ClientFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/defines.h" 27 | 28 | #include "Client.h" 29 | 30 | namespace feed 31 | { 32 | class Feed; 33 | } // namespace feed 34 | 35 | namespace client 36 | { 37 | /** 38 | * @brief A factory for clients. 39 | */ 40 | class ClientFactory 41 | { 42 | public: 43 | DEFAULT_CTOR(ClientFactory) 44 | DEFAULT_DTOR(ClientFactory) 45 | 46 | /** 47 | * @brief Create a Client needed by a Feed. 48 | * @param feed The feed to create for 49 | * @return the client as pointer 50 | */ 51 | static std::shared_ptr createClientFor(std::shared_ptr feed); 52 | 53 | private: 54 | /** 55 | * @brief Factory method for Client creation. 56 | * @tparam T The type of client 57 | * @param feed The feed to create for 58 | * @return the client as pointer 59 | */ 60 | template::value>::type* = nullptr> 62 | static std::shared_ptr makeClient(std::shared_ptr feed); 63 | }; 64 | 65 | } // namespace client 66 | -------------------------------------------------------------------------------- /include/client/GpsdClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "Client.h" 25 | 26 | namespace client 27 | { 28 | /** 29 | * @brief Client for GPSD servers 30 | */ 31 | class GpsdClient : public Client 32 | { 33 | public: 34 | NOT_COPYABLE(GpsdClient) 35 | DEFAULT_DTOR(GpsdClient) 36 | 37 | /** 38 | * @brief Constructor 39 | * @param endpoint The remote endpoint 40 | * @param connector The Connector interface 41 | */ 42 | GpsdClient(const net::Endpoint& endpoint, std::shared_ptr connector); 43 | 44 | private: 45 | /** 46 | * @brief Send unwatch-request and stop this client. 47 | */ 48 | void stop() override; 49 | 50 | /** 51 | * @brief Implement Client::handleConnect 52 | * @threadsafe 53 | */ 54 | void handleConnect(net::ErrorCode error) override; 55 | 56 | /** 57 | * @brief Handler for watch-request sending 58 | * @param error The error indicator 59 | * @threadsafe 60 | */ 61 | void handleWatch(net::ErrorCode error); 62 | }; 63 | 64 | } // namespace client 65 | -------------------------------------------------------------------------------- /include/client/SbsClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "Client.h" 25 | 26 | namespace client 27 | { 28 | /** 29 | * @brief Client for SBS servers 30 | */ 31 | class SbsClient : public Client 32 | { 33 | public: 34 | NOT_COPYABLE(SbsClient) 35 | DEFAULT_DTOR(SbsClient) 36 | 37 | /** 38 | * @brief Constructor 39 | * @param endpoint The remote endpoint 40 | * @param connector The Connector interface 41 | */ 42 | SbsClient(const net::Endpoint& endpoint, std::shared_ptr connector); 43 | 44 | private: 45 | /** 46 | * @brief Implement Client::handleConnect 47 | * @threadsafe 48 | */ 49 | void handleConnect(net::ErrorCode error) override; 50 | }; 51 | 52 | } // namespace client 53 | -------------------------------------------------------------------------------- /include/client/SensorClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "Client.h" 25 | #include "parameters.h" 26 | 27 | #ifdef WINDCLIENT_RECEIVE_TIMEOUT 28 | # define WC_RCV_TIMEOUT WINDCLIENT_RECEIVE_TIMEOUT 29 | #else 30 | # define WC_RCV_TIMEOUT 5 31 | #endif 32 | 33 | namespace client 34 | { 35 | /** 36 | * @brief Client for sensor servers 37 | */ 38 | class SensorClient : public Client 39 | { 40 | public: 41 | NOT_COPYABLE(SensorClient) 42 | DEFAULT_DTOR(SensorClient) 43 | 44 | /** 45 | * @brief Constructor 46 | * @param endpoint The remote endpoint 47 | * @param connector The Connector interface 48 | */ 49 | SensorClient(const net::Endpoint& endpoint, std::shared_ptr connector); 50 | 51 | private: 52 | /** 53 | * @brief Override Client::read, use timeout 54 | */ 55 | void read() override; 56 | 57 | /** 58 | * @brief Check read timeout deadline reached. 59 | * @threadsafe 60 | */ 61 | void checkDeadline(net::ErrorCode error); 62 | 63 | /** 64 | * @brief Implement Client::handleConnect 65 | * @threadsafe 66 | */ 67 | void handleConnect(net::ErrorCode error) override; 68 | }; 69 | 70 | } // namespace client 71 | -------------------------------------------------------------------------------- /include/client/net/Endpoint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace client 27 | { 28 | namespace net 29 | { 30 | /** 31 | * @brief A remote endpoint 32 | */ 33 | struct Endpoint 34 | { 35 | /** 36 | * @brief Equality comparison by value 37 | * @param other The other endpoint 38 | * @return true if both are equal, else false 39 | */ 40 | bool operator==(const Endpoint& other) const 41 | { 42 | return host == other.host && port == other.port; 43 | } 44 | 45 | /// Hostname 46 | const std::string host; 47 | 48 | /// Port number 49 | const std::string port; 50 | }; 51 | } // namespace net 52 | } // namespace client 53 | -------------------------------------------------------------------------------- /include/config/ConfigReader.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/defines.h" 27 | 28 | #include "Properties.h" 29 | 30 | namespace config 31 | { 32 | /** 33 | * @brief Read a config in INI format. 34 | */ 35 | class ConfigReader 36 | { 37 | public: 38 | DEFAULT_DTOR(ConfigReader) 39 | 40 | /** 41 | * @brief Constructor 42 | * @param stream The input stream to read from 43 | */ 44 | explicit ConfigReader(std::istream& stream); 45 | 46 | /** 47 | * @brief Read the given stream and return read properties. 48 | * @return the Properties 49 | */ 50 | Properties read(); 51 | 52 | private: 53 | /// The input stream 54 | std::istream& m_stream; 55 | }; 56 | 57 | } // namespace config 58 | -------------------------------------------------------------------------------- /include/config/Properties.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "util/defines.h" 30 | 31 | namespace config 32 | { 33 | /** 34 | * @brief Store key-value pairs sectionwise. 35 | */ 36 | class Properties 37 | { 38 | public: 39 | DEFAULT_DTOR(Properties) 40 | 41 | /** 42 | * @brief Copy-constructor 43 | * @param ptree The property tree to copy 44 | */ 45 | explicit Properties(const boost::property_tree::ptree& ptree); 46 | 47 | /** 48 | * @brief Move-constructor 49 | * @param ptree The property tree to move 50 | */ 51 | explicit Properties(boost::property_tree::ptree&& ptree); 52 | 53 | /** 54 | * @brief Get the value at a property path (section.key), or a default value. 55 | * @param path The property path 56 | * @param alternative The default value (default: empty) 57 | * @return the value at path if found and not empty, else the default value 58 | */ 59 | std::string get_property(const std::string& path, const std::string& alternative = "") const; 60 | 61 | /** 62 | * @brief Get the Properties for a section. 63 | * @param section The section 64 | * @return the Properties for that section 65 | * @throw std::out_of_range if the section is not found 66 | */ 67 | Properties get_propertySection(const std::string& section) const; 68 | 69 | private: 70 | /// The underlying property tree 71 | boost::property_tree::ptree m_pTree; 72 | }; 73 | 74 | } // namespace config 75 | -------------------------------------------------------------------------------- /include/data/AircraftData.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "object/Aircraft.h" 31 | #include "processor/AircraftProcessor.h" 32 | #include "util/defines.h" 33 | 34 | #include "Data.hpp" 35 | 36 | /// Times until aircraft gets deleted 37 | #define AC_DELETE_THRESHOLD 120 38 | 39 | /// Times until FLARM status is removed 40 | #define AC_NO_FLARM_THRESHOLD OBJ_OUTDATED 41 | 42 | namespace data 43 | { 44 | /** 45 | * @brief Store aircrafts. 46 | */ 47 | class AircraftData : public Data 48 | { 49 | public: 50 | DEFAULT_DTOR(AircraftData) 51 | 52 | AircraftData(); 53 | 54 | /** 55 | * @brief Constructor 56 | * @param maxDist The max distance filter 57 | */ 58 | explicit AircraftData(std::int32_t maxDist); 59 | 60 | /** 61 | * @brief Get the reports for all processed aircrafts. 62 | * @param dest The destination string to append reports 63 | * @threadsafe 64 | */ 65 | void get_serialized(std::string& dest) override; 66 | 67 | /** 68 | * @brief Insert or update an Aircraft. 69 | * @param aircraft The update 70 | * @return true on success, else false 71 | * @threadsafe 72 | */ 73 | bool update(object::Object&& aircraft) override; 74 | 75 | /** 76 | * @brief Process all aircrafts. 77 | * @param position The refered position 78 | * @param atmPress The atmospheric pressure 79 | * @threadsafe 80 | */ 81 | void processAircrafts(const object::Position& position, double atmPress) noexcept; 82 | 83 | private: 84 | /** 85 | * @brief Insert an aircraft into the internal container. 86 | * @param aircraft The aircraft 87 | */ 88 | void insert(object::Aircraft&& aircraft); 89 | 90 | /// Processor for aircrafts 91 | processor::AircraftProcessor m_processor; 92 | 93 | /// Vector holding the aircrafts 94 | std::vector m_container; 95 | 96 | /// Map aircraft Id's to container index 97 | std::unordered_map m_index; 98 | }; 99 | 100 | } // namespace data 101 | -------------------------------------------------------------------------------- /include/data/AtmosphereData.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "object/Atmosphere.h" 27 | #include "util/defines.h" 28 | 29 | #include "Data.hpp" 30 | 31 | namespace data 32 | { 33 | /** 34 | * @brief Store atmospheric information. 35 | */ 36 | class AtmosphereData : public Data 37 | { 38 | public: 39 | DEFAULT_DTOR(AtmosphereData) 40 | 41 | AtmosphereData(); 42 | 43 | /** 44 | * @brief Constructor 45 | * @param atmosphere The initial atm info 46 | */ 47 | explicit AtmosphereData(const object::Atmosphere& atmosphere); 48 | 49 | /** 50 | * @brief Get the MDA sentence. 51 | * @param dest The destination string to append data 52 | * @threadsafe 53 | */ 54 | void get_serialized(std::string& dest) override; 55 | 56 | /** 57 | * @brief Update he athmosphere data. 58 | * @param atmosphere The new atm info 59 | * @return true on success, else false 60 | * @threadsafe 61 | */ 62 | bool update(object::Object&& atmosphere) override; 63 | 64 | /** 65 | * @brief Get the atmospheric pressure. 66 | * @return the pressure 67 | * @threadsafe 68 | */ 69 | double get_atmPressure(); 70 | 71 | private: 72 | /// Atmospheric information 73 | object::Atmosphere m_atmosphere; 74 | }; 75 | } // namespace data 76 | -------------------------------------------------------------------------------- /include/data/Data.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | Copyright (C) 2016 VirtualFlightRadar-Backend 4 | A detailed list of copyright holders can be found in the file "AUTHORS". 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License version 3 7 | as published by the Free Software Foundation. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | } 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "util/defines.h" 24 | 25 | namespace object 26 | { 27 | class Object; 28 | } // namespace object 29 | 30 | namespace data 31 | { 32 | /** 33 | * @brief The Data interface 34 | */ 35 | class Data 36 | { 37 | public: 38 | DEFAULT_CTOR(Data) 39 | DEFAULT_VIRTUAL_DTOR(Data) 40 | 41 | /** 42 | * @brief Get the serialized data. 43 | * @param dest The string to append the data to 44 | */ 45 | virtual void get_serialized(std::string& dest) = 0; 46 | 47 | /** 48 | * @brief Attempt to update this data. 49 | * @param _1 The new Object 50 | * @return true on success, else false 51 | */ 52 | virtual bool update(object::Object&& _1) = 0; 53 | 54 | protected: 55 | mutable std::mutex m_mutex; 56 | }; 57 | } // namespace data 58 | -------------------------------------------------------------------------------- /include/data/WindData.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "object/Wind.h" 27 | #include "util/defines.h" 28 | 29 | #include "Data.hpp" 30 | 31 | namespace data 32 | { 33 | /** 34 | * @brief Store wind information. 35 | */ 36 | class WindData : public Data 37 | { 38 | public: 39 | DEFAULT_DTOR(WindData) 40 | 41 | WindData(); 42 | 43 | /** 44 | * @brief Constructor 45 | * @param wind The initial wind information 46 | */ 47 | explicit WindData(const object::Wind& wind); 48 | 49 | /** 50 | * @brief Get the MWV sentence. 51 | * @note The wind info is invalid after this operation. 52 | * @param dest The destination string to append data 53 | * @threadsafe 54 | */ 55 | void get_serialized(std::string& dest) override; 56 | 57 | /** 58 | * @brief Update the wind information. 59 | * @param wind The new wind information. 60 | * @return true on success, else false 61 | * @threadsafe 62 | */ 63 | bool update(object::Object&& wind) override; 64 | 65 | private: 66 | /// The Wind information 67 | object::Wind m_wind; 68 | }; 69 | 70 | } // namespace data 71 | -------------------------------------------------------------------------------- /include/data/processor/GpsProcessor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "object/GpsPosition.h" 28 | #include "util/defines.h" 29 | 30 | #include "Processor.hpp" 31 | 32 | namespace data 33 | { 34 | namespace processor 35 | { 36 | /** 37 | * @brief Process GPS positions to NMEA GGA and RMC sentences. 38 | */ 39 | class GpsProcessor : public Processor 40 | { 41 | public: 42 | DEFAULT_DTOR(GpsProcessor) 43 | 44 | GpsProcessor(); 45 | 46 | /** 47 | * @brief Process a GPS position. 48 | * @param rPosition The position 49 | */ 50 | void process(object::GpsPosition& position) override; 51 | 52 | private: 53 | /** 54 | * @brief Append GPGGA sentence to processing string. 55 | * @param position The position 56 | * @param utc The current utc time 57 | */ 58 | void appendGPGGA(const object::GpsPosition& position, const std::tm* utc); 59 | 60 | /** 61 | * @brief Append GPRMC sentence to processing string. 62 | * @param utc The current utc time 63 | */ 64 | void appendGPRMC(const std::tm* utc); 65 | 66 | /** 67 | * @brief Evaluate position for given latitude and longitude. 68 | * @param latitude The latitude 69 | * @param longitude The longitude 70 | */ 71 | void evalPosition(double latitude, double longitude); 72 | 73 | /// Orientation of the latitude (S,N) 74 | mutable char m_directionSN = 'x'; 75 | 76 | /// Orientation of the longitude (E,W) 77 | mutable char m_directionEW = 'x'; 78 | 79 | /// Degrees of latitude 80 | mutable double m_degLatitude = 0.0; 81 | 82 | /// Degrees of longitude 83 | mutable double m_degLongitude = 0.0; 84 | 85 | /// Minutes of latitude 86 | mutable double m_minLatitude = 0.0; 87 | 88 | /// Minutes of longitude 89 | mutable double m_minLongitude = 0.0; 90 | }; 91 | 92 | } // namespace processor 93 | } // namespace data 94 | -------------------------------------------------------------------------------- /include/data/processor/Processor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "util/defines.h" 28 | #include "util/math.hpp" 29 | 30 | namespace data 31 | { 32 | namespace processor 33 | { 34 | /** 35 | * @brief Processor base class/interface. 36 | * @tparam T The type of object to process 37 | */ 38 | template 39 | class Processor 40 | { 41 | public: 42 | DEFAULT_CTOR(Processor) 43 | DEFAULT_VIRTUAL_DTOR(Processor) 44 | 45 | /** 46 | * @brief Process an object. 47 | * @param _1 The object of type T 48 | */ 49 | virtual void process(T& _1) = 0; 50 | 51 | protected: 52 | /** 53 | * @brief End the processing string with checksum and CRLF. 54 | */ 55 | inline void finishSentence() 56 | { 57 | std::snprintf(m_buffer, sizeof(m_buffer), "%02x\r\n", 58 | math::checksum(m_buffer, sizeof(m_buffer))); 59 | m_processed.append(m_buffer); 60 | } 61 | 62 | /// The internal buffer for format strings 63 | char m_buffer[4096] = ""; 64 | 65 | /// Processing string 66 | mutable std::string m_processed; 67 | }; 68 | } // namespace processor 69 | } // namespace data 70 | -------------------------------------------------------------------------------- /include/feed/AprscFeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "config/Properties.h" 30 | #include "util/defines.h" 31 | 32 | #include "Feed.h" 33 | 34 | namespace feed 35 | { 36 | namespace parser 37 | { 38 | class AprsParser; 39 | } // namespace parser 40 | } // namespace feed 41 | 42 | namespace data 43 | { 44 | class AircraftData; 45 | } // namespace data 46 | 47 | namespace feed 48 | { 49 | /** 50 | * @brief Extend Feed for APRSC protocol. 51 | */ 52 | class AprscFeed : public Feed 53 | { 54 | public: 55 | NOT_COPYABLE(AprscFeed) 56 | DEFAULT_DTOR(AprscFeed) 57 | 58 | /** 59 | * @brief Constructor 60 | * @param name The unique name 61 | * @param properties The Properties 62 | * @param data The AircraftData container 63 | * @param maxHeight The max height filter 64 | * @throw std::logic_error if login is not given, or from parent constructor 65 | */ 66 | AprscFeed(const std::string& name, const config::Properties& propertyMap, 67 | std::shared_ptr data, std::int32_t maxHeight); 68 | 69 | /** 70 | * @brief Get this feeds Protocol. 71 | * @return Protocol::APRS 72 | */ 73 | Protocol get_protocol() const override; 74 | 75 | /** 76 | * @brief Implement Feed::process. 77 | */ 78 | bool process(const std::string& response) override; 79 | 80 | /** 81 | * @brief Get the login string. 82 | * @return the login 83 | */ 84 | std::string get_login() const; 85 | 86 | private: 87 | /// Parser to unpack response from Client 88 | static parser::AprsParser s_parser; 89 | }; 90 | 91 | } // namespace feed 92 | -------------------------------------------------------------------------------- /include/feed/AtmosphereFeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "config/Properties.h" 28 | #include "util/defines.h" 29 | 30 | #include "Feed.h" 31 | 32 | namespace feed 33 | { 34 | namespace parser 35 | { 36 | class AtmosphereParser; 37 | } // namespace parser 38 | } // namespace feed 39 | 40 | namespace data 41 | { 42 | class AtmosphereData; 43 | } // namespace data 44 | 45 | namespace feed 46 | { 47 | /** 48 | * @brief Extend Feed for sensor input. 49 | */ 50 | class AtmosphereFeed : public Feed 51 | { 52 | public: 53 | NOT_COPYABLE(AtmosphereFeed) 54 | DEFAULT_DTOR(AtmosphereFeed) 55 | 56 | /** 57 | * @brief Constructor 58 | * @param name The unique name 59 | * @param properties The Properties 60 | * @param data The WindData container 61 | * @throw std::logic_error from parent constructor 62 | */ 63 | AtmosphereFeed(const std::string& name, const config::Properties& properties, 64 | std::shared_ptr data); 65 | 66 | /** 67 | * @brief Get this feeds Protocol. 68 | * @return Protocol::SENSOR 69 | */ 70 | Protocol get_protocol() const override; 71 | 72 | /** 73 | * @brief Implement Feed::process. 74 | */ 75 | bool process(const std::string& response) override; 76 | 77 | private: 78 | /// Parser to unpack response from Client 79 | static parser::AtmosphereParser s_parser; 80 | }; 81 | 82 | } // namespace feed 83 | -------------------------------------------------------------------------------- /include/feed/Feed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "client/net/Endpoint.hpp" 29 | #include "config/Properties.h" 30 | #include "util/defines.h" 31 | 32 | namespace data 33 | { 34 | class Data; 35 | } // namespace data 36 | 37 | namespace feed 38 | { 39 | /** 40 | * @brief Base class for input feeds. 41 | */ 42 | class Feed 43 | { 44 | public: 45 | NOT_COPYABLE(Feed) 46 | DEFAULT_VIRTUAL_DTOR(Feed) 47 | 48 | /** 49 | * @brief The protocol that the Feed supports. 50 | */ 51 | enum class Protocol : std::uint8_t 52 | { 53 | APRS, 54 | SBS, 55 | GPS, 56 | SENSOR 57 | }; 58 | 59 | /** 60 | * @brief Get the supported Protocol. 61 | * @return the protocol 62 | */ 63 | virtual Protocol get_protocol() const = 0; 64 | 65 | /** 66 | * @brief Get the feeds required Endpoint. 67 | * @return the endpoint 68 | */ 69 | client::net::Endpoint get_endpoint() const; 70 | 71 | /** 72 | * @brief Handle client's response. 73 | * @param response The response 74 | */ 75 | virtual bool process(const std::string& response) = 0; 76 | 77 | protected: 78 | /** 79 | * @brief Constructor 80 | * @param name The Feeds unique name 81 | * @param component The component string 82 | * @param properties The Properties 83 | * @throw std::logic_error if host or port are not given in properties 84 | */ 85 | Feed(const std::string& name, const char* component, const config::Properties& propertyMap, 86 | std::shared_ptr data); 87 | 88 | /// Unique name 89 | const std::string m_name; 90 | 91 | /// Component string 92 | const char* const m_component; 93 | 94 | /// Properties 95 | const config::Properties m_properties; 96 | 97 | /// Respective Data container 98 | std::shared_ptr m_data; 99 | 100 | private: 101 | /** 102 | * @brief Initialize the priority from the given properties. 103 | */ 104 | void initPriority() noexcept; 105 | 106 | /// Priority 107 | std::uint32_t m_priority; 108 | 109 | public: 110 | /** 111 | * Getters 112 | */ 113 | GETTER_CR(name) 114 | GETTER_V(priority) 115 | }; 116 | 117 | } // namespace feed 118 | -------------------------------------------------------------------------------- /include/feed/FeedFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include "config/Properties.h" 31 | #include "util/defines.h" 32 | 33 | namespace config 34 | { 35 | class Configuration; 36 | } // namespace config 37 | 38 | namespace data 39 | { 40 | class AircraftData; 41 | class AtmosphereData; 42 | class GpsData; 43 | class WindData; 44 | } // namespace data 45 | 46 | namespace feed 47 | { 48 | class Feed; 49 | 50 | /** 51 | * @brief Factory for Feed creation. 52 | */ 53 | class FeedFactory 54 | { 55 | public: 56 | DEFAULT_DTOR(FeedFactory) 57 | 58 | /** 59 | * @brief Constructor 60 | * @param config The Configuration 61 | * @param aircraftData The AircraftData pointer 62 | * @param atmosData The AtmosphereData pointer 63 | * @param gpsData The GpsData pointer 64 | * @param windData The WindData pointer 65 | */ 66 | FeedFactory(std::shared_ptr config, 67 | std::shared_ptr aircraftData, 68 | std::shared_ptr atmosData, 69 | std::shared_ptr gpsData, std::shared_ptr windData); 70 | 71 | /** 72 | * @brief Create a Feed. 73 | * @param name The feed name 74 | * @return an optional unique pointer to the feed 75 | * @throw std::logic_error from invoked methods 76 | */ 77 | boost::optional> createFeed(const std::string& name); 78 | 79 | private: 80 | /** 81 | * @brief Make a new Feed. 82 | * @tparam T The Feed type 83 | * @note Must be fully specialized for every concrete Feed type T. 84 | * @param name The feed name 85 | * @return a pointer to the concrete Feed 86 | * @throw std::logic_error from invoked constructors 87 | */ 88 | template::value>::type* = nullptr> 89 | std::shared_ptr makeFeed(const std::string& name); 90 | 91 | /// Pointer to the Configuration 92 | std::shared_ptr m_config; 93 | 94 | /// Pointer to the AircraftData 95 | std::shared_ptr m_aircraftData; 96 | 97 | /// Pointer to the AtmosphereData 98 | std::shared_ptr m_atmosData; 99 | 100 | /// Pointer to the GpsData 101 | std::shared_ptr m_gpsData; 102 | 103 | /// Pointer to the WindData 104 | std::shared_ptr m_windData; 105 | }; 106 | } // namespace feed 107 | -------------------------------------------------------------------------------- /include/feed/GpsFeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "config/Properties.h" 28 | #include "util/defines.h" 29 | 30 | #include "Feed.h" 31 | 32 | namespace feed 33 | { 34 | namespace parser 35 | { 36 | class GpsParser; 37 | } // namespace parser 38 | } // namespace feed 39 | 40 | namespace data 41 | { 42 | class GpsData; 43 | } // namespace data 44 | 45 | namespace feed 46 | { 47 | /** 48 | * @brief Extend Feed for GPS input. 49 | */ 50 | class GpsFeed : public Feed 51 | { 52 | public: 53 | NOT_COPYABLE(GpsFeed) 54 | DEFAULT_DTOR(GpsFeed) 55 | 56 | /** 57 | * @brief Constructor 58 | * @param name The unique name 59 | * @param properties The Properties 60 | * @param data The GpsData container 61 | * @throw std::logic_error from parent constructor 62 | */ 63 | GpsFeed(const std::string& name, const config::Properties& properties, 64 | std::shared_ptr data); 65 | 66 | /** 67 | * @brief Get this feeds Protocol. 68 | * @return Protocol::GPS 69 | */ 70 | Protocol get_protocol() const override; 71 | 72 | /** 73 | * @brief Implement Feed::process. 74 | */ 75 | bool process(const std::string& response) override; 76 | 77 | private: 78 | /// Parser to unpack response from Client 79 | static parser::GpsParser s_parser; 80 | }; 81 | 82 | } // namespace feed 83 | -------------------------------------------------------------------------------- /include/feed/SbsFeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "config/Properties.h" 29 | #include "util/defines.h" 30 | 31 | #include "Feed.h" 32 | 33 | namespace feed 34 | { 35 | namespace parser 36 | { 37 | class SbsParser; 38 | } // namespace parser 39 | } // namespace feed 40 | 41 | namespace data 42 | { 43 | class AircraftData; 44 | } // namespace data 45 | 46 | namespace feed 47 | { 48 | /** 49 | * @brief Extend Feed for SBS protocol. 50 | */ 51 | class SbsFeed : public Feed 52 | { 53 | public: 54 | NOT_COPYABLE(SbsFeed) 55 | DEFAULT_DTOR(SbsFeed) 56 | 57 | /** 58 | * @brief Constructor 59 | * @param name The unique name 60 | * @param properties The Properties 61 | * @param data The AircraftData container 62 | * @param maxHeight The max height filter 63 | * @throw std::logic_error from parent constructor 64 | */ 65 | SbsFeed(const std::string& name, const config::Properties& properties, 66 | std::shared_ptr data, std::int32_t maxHeight); 67 | 68 | /** 69 | * @brief Get this feeds Protocol. 70 | * @return Protocol::SBS 71 | */ 72 | Protocol get_protocol() const override; 73 | 74 | /** 75 | * @brief Feed::process. 76 | */ 77 | bool process(const std::string& response) override; 78 | 79 | private: 80 | /// Parser to unpack response from Client 81 | static parser::SbsParser s_parser; 82 | }; 83 | 84 | } // namespace feed 85 | -------------------------------------------------------------------------------- /include/feed/WindFeed.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "config/Properties.h" 28 | #include "util/defines.h" 29 | 30 | #include "Feed.h" 31 | 32 | namespace feed 33 | { 34 | namespace parser 35 | { 36 | class WindParser; 37 | } // namespace parser 38 | } // namespace feed 39 | 40 | namespace data 41 | { 42 | class WindData; 43 | } // namespace data 44 | 45 | namespace feed 46 | { 47 | /** 48 | * @brief Extend Feed for windsensor input. 49 | */ 50 | class WindFeed : public Feed 51 | { 52 | public: 53 | NOT_COPYABLE(WindFeed) 54 | DEFAULT_DTOR(WindFeed) 55 | 56 | /** 57 | * @brief Constructor 58 | * @param name The SensorFeeds unique name 59 | * @param properties The Properties 60 | * @param data The WindData contianer 61 | * @throw std::logic_error from parent constructor 62 | */ 63 | WindFeed(const std::string& name, const config::Properties& properties, 64 | std::shared_ptr data); 65 | 66 | /** 67 | * @brief Get this feeds Protocol. 68 | * @return Protocol::SENSOR 69 | */ 70 | Protocol get_protocol() const override; 71 | 72 | /** 73 | * @brief Feed::process. 74 | */ 75 | bool process(const std::string& response) override; 76 | 77 | private: 78 | /// Parser to unpack response from Client 79 | static parser::WindParser s_parser; 80 | }; 81 | 82 | } // namespace feed 83 | -------------------------------------------------------------------------------- /include/feed/parser/AprsParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include "object/Aircraft.h" 30 | #include "util/defines.h" 31 | 32 | #include "Parser.hpp" 33 | 34 | namespace feed 35 | { 36 | namespace parser 37 | { 38 | /** 39 | * @brief Implement Parser for APRS sentences. 40 | */ 41 | class AprsParser : public Parser 42 | { 43 | public: 44 | DEFAULT_DTOR(AprsParser) 45 | 46 | AprsParser(); 47 | 48 | /** 49 | * @brief Unpack into Aircraft. 50 | * @param sentence The string to unpack 51 | * @param aircraft The Aircraft to unpack into 52 | * @return true on success, else false 53 | */ 54 | bool unpack(const std::string& sentence, object::Aircraft& aircraft) noexcept override; 55 | 56 | /// The max height filter 57 | static std::int32_t s_maxHeight; 58 | 59 | private: 60 | /** 61 | * @brief Parse a Position. 62 | * @param match The regex match 63 | * @param aircraft The target Aircraft 64 | * @return true on success, else false 65 | */ 66 | bool parsePosition(const boost::smatch& match, object::Aircraft& aircraft) noexcept; 67 | 68 | /** 69 | * @brief Parse the APRS comment. 70 | * @param match The regex match 71 | * @param aircraft The target Aircraft 72 | * @return true on success, else false 73 | */ 74 | bool parseComment(const boost::smatch& match, object::Aircraft& aircraft) noexcept; 75 | 76 | /** 77 | * @brief Parse the Movement information. 78 | * @param match The regex match 79 | * @param comMatch The comment regex match 80 | * @param aircraft The target Aircraft 81 | * @return true on success, else false 82 | */ 83 | bool parseMovement(const boost::smatch& match, const boost::smatch& comMatch, 84 | object::Aircraft& aircraft) noexcept; 85 | 86 | /** 87 | * @brief Parse the TimeStamp information. 88 | * @param match The regex match 89 | * @param aircraft The target Aircraft 90 | * @return true on success, else false 91 | */ 92 | bool parseTimeStamp(const boost::smatch& match, object::Aircraft& aircraft) noexcept; 93 | 94 | /// Regular expression for APRS protocol 95 | static const boost::regex s_APRS_RE; 96 | 97 | /// Regular expression for OGN specific APRS extension 98 | static const boost::regex s_APRSExtRE; 99 | }; 100 | } // namespace parser 101 | } // namespace feed 102 | -------------------------------------------------------------------------------- /include/feed/parser/AtmosphereParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "object/Atmosphere.h" 27 | #include "util/defines.h" 28 | 29 | #include "Parser.hpp" 30 | 31 | namespace feed 32 | { 33 | namespace parser 34 | { 35 | /** 36 | * @brief Implement Parser for NMEA sentences from sensors. 37 | */ 38 | class AtmosphereParser : public Parser 39 | { 40 | public: 41 | DEFAULT_DTOR(AtmosphereParser) 42 | 43 | AtmosphereParser(); 44 | 45 | /** 46 | * @brief Unpack into Atmosphere. 47 | * @param sentence The string to unpack 48 | * @param atmosphere The Atmosphere to unpack into 49 | */ 50 | bool unpack(const std::string& sentence, object::Atmosphere& atmosphere) noexcept override; 51 | }; 52 | } // namespace parser 53 | } // namespace feed 54 | -------------------------------------------------------------------------------- /include/feed/parser/GpsParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2017 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include 27 | 28 | #include "object/GpsPosition.h" 29 | #include "util/defines.h" 30 | 31 | #include "Parser.hpp" 32 | 33 | namespace feed 34 | { 35 | namespace parser 36 | { 37 | /** 38 | * @brief Implement Parser for GPS NMEA sentences. 39 | */ 40 | class GpsParser : public Parser 41 | { 42 | public: 43 | DEFAULT_DTOR(GpsParser) 44 | 45 | GpsParser(); 46 | 47 | /** 48 | * @brief Unpack into GpsPosition. 49 | * @param sentence The string to unpack 50 | * @param position The position to unpack into 51 | * @return true on success, else false 52 | */ 53 | bool unpack(const std::string& sentence, object::GpsPosition& position) noexcept override; 54 | 55 | private: 56 | /** 57 | * @brief Parse a Position. 58 | * @param match The regex match 59 | * @param position The target position 60 | * @return true on success, else false 61 | */ 62 | bool parsePosition(const boost::smatch& match, object::GpsPosition& position); 63 | 64 | /// Regular expression to parse GGA 65 | static const boost::regex s_GPGGA_RE; 66 | }; 67 | } // namespace parser 68 | } // namespace feed 69 | -------------------------------------------------------------------------------- /include/feed/parser/Parser.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/defines.h" 27 | 28 | namespace feed 29 | { 30 | namespace parser 31 | { 32 | /** 33 | * @brief Interface for parsers. 34 | * @tparam T The corresponding object type 35 | */ 36 | template 37 | class Parser 38 | { 39 | public: 40 | DEFAULT_CTOR(Parser) 41 | DEFAULT_VIRTUAL_DTOR(Parser) 42 | 43 | /** 44 | * @brief Unpack a given string into the templated object. 45 | * @param sentence The string to unpack 46 | * @param _1 The target object 47 | * @return true on success, else false 48 | */ 49 | virtual bool unpack(const std::string& sentence, T& _1) noexcept = 0; 50 | }; 51 | 52 | } // namespace parser 53 | } // namespace feed 54 | -------------------------------------------------------------------------------- /include/feed/parser/SbsParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "object/Aircraft.h" 28 | #include "util/defines.h" 29 | 30 | #include "Parser.hpp" 31 | 32 | namespace feed 33 | { 34 | namespace parser 35 | { 36 | /** 37 | * @brief Implement Parser for SBS sentences. 38 | */ 39 | class SbsParser : public Parser 40 | { 41 | public: 42 | DEFAULT_DTOR(SbsParser) 43 | 44 | SbsParser(); 45 | 46 | /** 47 | * @brief Unpack into Aircraft. 48 | * @param sentence The string to unpack 49 | * @param aircraft The Aircraft to unpack into 50 | */ 51 | bool unpack(const std::string& sentence, object::Aircraft& aircraft) noexcept override; 52 | 53 | /// The max height filter 54 | static std::int32_t s_maxHeight; 55 | 56 | private: 57 | /** 58 | * @brief Parse a field in SBS and set respective values. 59 | * @param fieldNr The field number 60 | * @param field The string in that field 61 | * @param position The target position 62 | * @param aircraft The target Aircraft 63 | * @return true on success, else false 64 | */ 65 | bool parseField(std::uint32_t fieldNr, const std::string& field, object::Position& position, 66 | object::Aircraft& aircraft) noexcept; 67 | }; 68 | } // namespace parser 69 | } // namespace feed 70 | -------------------------------------------------------------------------------- /include/feed/parser/WindParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "object/Wind.h" 27 | #include "util/defines.h" 28 | 29 | #include "Parser.hpp" 30 | 31 | namespace feed 32 | { 33 | namespace parser 34 | { 35 | /** 36 | * @brief Implement Parser for NMEA wind sentences. 37 | */ 38 | class WindParser : public Parser 39 | { 40 | public: 41 | DEFAULT_DTOR(WindParser) 42 | 43 | WindParser(); 44 | 45 | /** 46 | * @brief Unpack into Wind. 47 | * @param sentence The string to unpack 48 | * @param wind The Wind to unpack into 49 | * @return true on success, else false 50 | */ 51 | bool unpack(const std::string& sentence, object::Wind& wind) noexcept override; 52 | }; 53 | } // namespace parser 54 | } // namespace feed 55 | -------------------------------------------------------------------------------- /include/object/Atmosphere.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/defines.h" 27 | 28 | #include "Object.h" 29 | 30 | /// ICAO standard atmospheric pressure at MSL 31 | #define ICAO_STD_A 1013.25 32 | 33 | namespace object 34 | { 35 | struct Climate; 36 | 37 | /** 38 | * @brief Extend Object to atmospheric information. 39 | */ 40 | class Atmosphere : public Object 41 | { 42 | public: 43 | DEFAULT_DTOR(Atmosphere) 44 | 45 | Atmosphere(); 46 | 47 | /** 48 | * @brief Constructor 49 | * @param priority The initial priority 50 | */ 51 | explicit Atmosphere(std::uint32_t priority); 52 | 53 | /** 54 | * @brief Constructor 55 | * @param pressure The initial pressure 56 | * @param priority The initial priority 57 | */ 58 | Atmosphere(double pressure, std::uint32_t priority); 59 | 60 | private: 61 | /** 62 | * @brief Extend Object::assign. 63 | */ 64 | void assign(Object&& other) override; 65 | 66 | /// The atmospheric pressure 67 | double m_pressure = ICAO_STD_A; 68 | 69 | public: 70 | /** 71 | * Getters and setters 72 | */ 73 | GETSET_V(pressure) 74 | }; 75 | 76 | } // namespace object 77 | -------------------------------------------------------------------------------- /include/object/GpsPosition.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "impl/DateTimeImplBoost.h" 27 | #include "util/defines.h" 28 | 29 | #include "Object.h" 30 | #include "TimeStamp.hpp" 31 | 32 | namespace object 33 | { 34 | /** 35 | * @brief A position on earth. 36 | */ 37 | struct Position 38 | { 39 | /// Latitude; deg 40 | double latitude; 41 | 42 | /// Longitude; deg 43 | double longitude; 44 | 45 | /// Altitude; m 46 | std::int32_t altitude; 47 | }; 48 | 49 | /** 50 | * @brief Extend Object to a GPS position. 51 | */ 52 | class GpsPosition : public Object 53 | { 54 | public: 55 | DEFAULT_DTOR(GpsPosition) 56 | 57 | GpsPosition(); 58 | 59 | /** 60 | * @brief Constructor 61 | * @param priority The initial priority 62 | */ 63 | explicit GpsPosition(std::uint32_t priority); 64 | 65 | /** 66 | * @brief Constructor 67 | * @param position The position 68 | * @param geoid The geoid 69 | */ 70 | GpsPosition(const Position& position, double geoid); 71 | 72 | private: 73 | /** 74 | * @brief Override Object::assign. 75 | */ 76 | void assign(Object&& other) override; 77 | 78 | /** 79 | * @brief Override Object::canUpdate. 80 | */ 81 | bool canUpdate(const Object& other) const override; 82 | 83 | /// The position 84 | Position m_position{0.0, 0.0, 0}; 85 | 86 | /// The geoid separation 87 | double m_geoid = 0.0; 88 | 89 | /// The timestamp of this position 90 | TimeStamp m_timeStamp; 91 | 92 | /// The position dilution 93 | double m_dilution = 0.0; 94 | 95 | /// The number of satellites 96 | std::uint8_t m_nrOfSatellites = 1; 97 | 98 | /// The GPS fix quality 99 | std::int8_t m_fixQuality = 5; 100 | 101 | public: 102 | /** 103 | *Getters and setters 104 | */ 105 | GETSET_CR(position) 106 | GETSET_V(geoid) 107 | GETSET_V(timeStamp) 108 | GETSET_V(nrOfSatellites) 109 | GETSET_V(fixQuality) 110 | GETSET_V(dilution) 111 | }; 112 | } // namespace object 113 | -------------------------------------------------------------------------------- /include/object/Object.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | Copyright (C) 2016 VirtualFlightRadar-Backend 4 | A detailed list of copyright holders can be found in the file "AUTHORS". 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License version 3 7 | as published by the Free Software Foundation. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | } 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | 23 | #include "util/defines.h" 24 | 25 | /// Times until aircraft is outdated 26 | #define OBJ_OUTDATED 4 27 | 28 | namespace object 29 | { 30 | /** 31 | * @brief Base object class 32 | */ 33 | class Object 34 | { 35 | public: 36 | DEFAULT_CTOR(Object) 37 | DEFAULT_VIRTUAL_DTOR(Object) 38 | 39 | /** 40 | * @brief Constructor 41 | * @param priority The initial priority 42 | */ 43 | explicit Object(std::uint32_t priority); 44 | 45 | /** 46 | * @brief Try to update this Object. 47 | * @note If the other Object cannot update this, nothing happens. 48 | * @param other The other Object 49 | * @return true on success, else false 50 | */ 51 | virtual bool tryUpdate(Object&& other); 52 | 53 | /** 54 | * @brief Set the string representation of this Objects data. 55 | * @param serialized The string representation 56 | */ 57 | virtual void set_serialized(std::string&& serialized); 58 | 59 | /** 60 | * @brief Get the string representation of this Objects data. 61 | * @return m_serialized 62 | */ 63 | virtual const std::string& get_serialized() const; 64 | 65 | /** 66 | * @brief Increment the update age. 67 | * @return this 68 | */ 69 | Object& operator++(); 70 | 71 | protected: 72 | /** 73 | * @brief Assign other objects values to this. 74 | * @param other The other Object 75 | */ 76 | virtual void assign(Object&& other); 77 | 78 | /** 79 | * @brief Check whether this Object can update the other one. 80 | * @param other The other Object 81 | * @return true if yes, else false 82 | */ 83 | virtual bool canUpdate(const Object& other) const; 84 | 85 | /// Got last update with this priority. 86 | std::uint32_t m_lastPriority = 0; 87 | 88 | /// Times processed without update. 89 | std::uint32_t m_updateAge = 0; 90 | 91 | /// The string representation of this Objects data. 92 | std::string m_serialized; 93 | 94 | public: 95 | /** 96 | * Getters 97 | */ 98 | GETTER_V(updateAge) 99 | }; 100 | } // namespace object 101 | -------------------------------------------------------------------------------- /include/object/Wind.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/defines.h" 27 | 28 | #include "Object.h" 29 | 30 | namespace object 31 | { 32 | struct Climate; 33 | 34 | /** 35 | * @brief Extend Object to wind information. 36 | */ 37 | class Wind : public Object 38 | { 39 | public: 40 | DEFAULT_DTOR(Wind) 41 | 42 | Wind(); 43 | 44 | /** 45 | * @brief Constructor 46 | * @param priority The initial priority 47 | */ 48 | explicit Wind(std::uint32_t priority); 49 | }; 50 | 51 | } // namespace object 52 | -------------------------------------------------------------------------------- /include/object/impl/DateTimeImplBoost.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include "util/defines.h" 27 | 28 | namespace object 29 | { 30 | namespace timestamp 31 | { 32 | /** 33 | * @brief Provide time functions using boost. 34 | */ 35 | class DateTimeImplBoost 36 | { 37 | public: 38 | DEFAULT_CTOR(DateTimeImplBoost) 39 | DEFAULT_DTOR(DateTimeImplBoost) 40 | 41 | /** 42 | * @brief Get the amount of milliseconds since 00:00 UTC. 43 | * @return the milliseconds 44 | */ 45 | static std::int64_t now(); 46 | 47 | /** 48 | * @brief Get the current day as incremental number. 49 | * @return the current day 50 | */ 51 | static std::uint32_t day(); 52 | }; 53 | } // namespace timestamp 54 | } // namespace object 55 | -------------------------------------------------------------------------------- /include/server/Connection.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "net/SocketException.h" 29 | #include "util/Logger.hpp" 30 | #include "util/defines.h" 31 | 32 | namespace server 33 | { 34 | /** 35 | * @brief TCP connection opened by the Server. 36 | * @tparam SocketT The type of socket implementation 37 | */ 38 | template 39 | class Connection final 40 | { 41 | public: 42 | NOT_COPYABLE(Connection) 43 | DEFAULT_DTOR(Connection) 44 | 45 | /** 46 | * @brief Start a Connection. 47 | * @param socket The socket 48 | * @return a shared ptr to the Connection object 49 | */ 50 | static std::unique_ptr> create(SocketT&& socket); 51 | 52 | /** 53 | * @brief Write a message to the endpoint. 54 | * @param msg The message 55 | * @return true on success, else false 56 | */ 57 | bool write(const std::string& msg); 58 | 59 | private: 60 | /** 61 | * @brief Constructor 62 | * @param socket The socket 63 | */ 64 | explicit Connection(SocketT&& socket); 65 | 66 | /// Socket 67 | SocketT m_socket; 68 | 69 | /// IP address 70 | const std::string m_address; 71 | 72 | public: 73 | /** 74 | * Getters 75 | */ 76 | GETTER_CR(address) 77 | }; 78 | 79 | template 80 | std::unique_ptr> Connection::create(SocketT&& socket) 81 | { 82 | return std::unique_ptr>(new Connection(std::move(socket))); 83 | } 84 | 85 | template 86 | bool Connection::write(const std::string& msg) 87 | { 88 | try 89 | { 90 | return m_socket.write(msg); 91 | } 92 | catch (const net::SocketException& e) 93 | { 94 | logger.debug("(Connection) write: ", e.what()); 95 | } 96 | return false; 97 | } 98 | 99 | template 100 | Connection::Connection(SocketT&& socket) 101 | : m_socket(std::move(socket)), m_address(m_socket.get_address()) 102 | {} 103 | 104 | } // namespace server 105 | -------------------------------------------------------------------------------- /include/server/net/NetworkInterface.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "util/defines.h" 30 | 31 | namespace server 32 | { 33 | template 34 | class Connection; 35 | namespace net 36 | { 37 | /** 38 | * @brief Network interface for TCP a server. 39 | * @tparam SocketT The socket implementation 40 | */ 41 | template 42 | class NetworkInterface 43 | { 44 | public: 45 | DEFAULT_CTOR(NetworkInterface) 46 | DEFAULT_VIRTUAL_DTOR(NetworkInterface) 47 | 48 | /** 49 | * @brief Run this interface. 50 | * @param lock The lock that may be hold and released inside 51 | */ 52 | virtual void run(std::unique_lock& lock) = 0; 53 | 54 | /** 55 | * @brief Stop this interface. 56 | */ 57 | virtual void stop() = 0; 58 | 59 | /** 60 | * @brief Schedule an accept call. 61 | * @param callback The callback to invoke when done 62 | */ 63 | virtual void onAccept(const std::function& callback) = 0; 64 | 65 | /** 66 | * @brief Close the connection. 67 | */ 68 | virtual void close() = 0; 69 | 70 | /** 71 | * @brief Start and get the current Connection. 72 | * @return the Connection 73 | */ 74 | virtual std::unique_ptr> startConnection() = 0; 75 | 76 | /** 77 | * @brief Get the current connection address. 78 | * @return the address 79 | */ 80 | virtual std::string get_currentAddress() const = 0; 81 | }; 82 | } // namespace net 83 | } // namespace server 84 | -------------------------------------------------------------------------------- /include/server/net/SocketException.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "util/defines.h" 28 | 29 | namespace server 30 | { 31 | namespace net 32 | { 33 | /** 34 | * @brief Exception to signal socket errors. 35 | */ 36 | class SocketException : public std::exception 37 | { 38 | public: 39 | DEFAULT_DTOR(SocketException) 40 | 41 | /** 42 | * @brief Constructor 43 | * @param msg The error message 44 | */ 45 | explicit SocketException(const std::string& msg); 46 | 47 | /** 48 | * @brief Get the error message. 49 | * @return the message 50 | */ 51 | const char* what() const noexcept; 52 | 53 | private: 54 | /// Error message 55 | const std::string m_message; 56 | }; 57 | } // namespace net 58 | } // namespace server 59 | -------------------------------------------------------------------------------- /include/server/net/impl/NetworkInterfaceImplBoost.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "server/net/NetworkInterface.hpp" 32 | #include "server/net/impl/SocketImplBoost.h" 33 | #include "util/defines.h" 34 | 35 | namespace server 36 | { 37 | namespace net 38 | { 39 | /** 40 | * @brief Implement NetworkInterface using boost. 41 | */ 42 | class NetworkInterfaceImplBoost : public NetworkInterface 43 | { 44 | public: 45 | NOT_COPYABLE(NetworkInterfaceImplBoost) 46 | 47 | /** 48 | * @brief Constructor 49 | * @param port The port number 50 | */ 51 | explicit NetworkInterfaceImplBoost(std::uint16_t port); 52 | 53 | ~NetworkInterfaceImplBoost() noexcept; 54 | 55 | /** 56 | * @brief Run the event handler queue. 57 | * @note Blocks until all handlers have returned. 58 | * @param lock The lock to release before entering blocking section 59 | */ 60 | void run(std::unique_lock& lock) override; 61 | 62 | /** 63 | * @brief Stop the event handler queue. 64 | */ 65 | void stop() override; 66 | 67 | /** 68 | * @brief Schedule an accept call. 69 | * @param callback The callback to invoke when done 70 | */ 71 | void onAccept(const std::function& callback) override; 72 | 73 | /** 74 | * @brief Close current connection. 75 | */ 76 | void close() override; 77 | 78 | /** 79 | * @brief Start and get the Connection on current socket. 80 | * @return the Connection 81 | * @throw SocketException if the current socket is not open 82 | */ 83 | std::unique_ptr> startConnection() override; 84 | 85 | /** 86 | * @brief Get the current connected address. 87 | * @return the address 88 | * @throw SocketException if the current socket is not open 89 | */ 90 | std::string get_currentAddress() const override; 91 | 92 | private: 93 | /** 94 | * @brief Handler for accept calls 95 | * @param error The error code 96 | * @param callback The callback to invoke 97 | */ 98 | void handleAccept(const boost::system::error_code& error, 99 | const std::function& callback); 100 | 101 | /// Internal IO-service 102 | boost::asio::io_service m_ioService; 103 | 104 | /// Acceptor 105 | boost::asio::ip::tcp::acceptor m_acceptor; 106 | 107 | /// Current socket 108 | SocketImplBoost m_socket; 109 | }; 110 | } // namespace net 111 | } // namespace server 112 | -------------------------------------------------------------------------------- /include/server/net/impl/SocketImplBoost.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include "util/defines.h" 30 | 31 | namespace server 32 | { 33 | namespace net 34 | { 35 | /** 36 | * @brief Socket implementation using boost 37 | */ 38 | class SocketImplBoost 39 | { 40 | public: 41 | MOVABLE_BUT_NOT_COPYABLE(SocketImplBoost) 42 | 43 | /** 44 | * @brief Constructor 45 | * @param socket The underlying socket 46 | */ 47 | explicit SocketImplBoost(BOOST_RV_REF(boost::asio::ip::tcp::socket) socket); 48 | 49 | ~SocketImplBoost() noexcept; 50 | 51 | /** 52 | * @brief Get the remote IP address. 53 | * @return the address 54 | * @throw SocketException if the socket is closed 55 | */ 56 | std::string get_address() const; 57 | 58 | /** 59 | * @brief Write a message on the socket to the endpoint. 60 | * @param msg The message 61 | * @return true on success, else false 62 | * @throw SocketException if the socket is closed 63 | */ 64 | bool write(const std::string& msg); 65 | 66 | /** 67 | * @brief Close the socket. 68 | */ 69 | void close(); 70 | 71 | /** 72 | * @brief Get the underlying socket. 73 | * @return the socket 74 | */ 75 | boost::asio::ip::tcp::socket& get(); 76 | 77 | private: 78 | /// Underlying socket 79 | boost::asio::ip::tcp::socket m_socket; 80 | }; 81 | } // namespace net 82 | } // namespace server 83 | -------------------------------------------------------------------------------- /include/util/SignalListener.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "util/defines.h" 32 | 33 | namespace util 34 | { 35 | /// @typedef SignalHandler 36 | /// Handler function 37 | using SignalHandler = std::function; 38 | 39 | /** 40 | * @brief Catch and handle system signals. 41 | */ 42 | class SignalListener 43 | { 44 | public: 45 | NOT_COPYABLE(SignalListener) 46 | 47 | SignalListener(); 48 | 49 | ~SignalListener() noexcept; 50 | 51 | /** 52 | * @brief Run this signal listener. 53 | * @threadsafe 54 | */ 55 | void run(); 56 | 57 | /** 58 | * @brief Stop this signal listener. 59 | * @threadsafe 60 | */ 61 | void stop(); 62 | 63 | /** 64 | * @brief Add a SignalHandler. 65 | * @param handler The handler to invoke when signal caught 66 | * @threadsafe 67 | */ 68 | void addHandler(const SignalHandler& handler); 69 | 70 | private: 71 | /// Internal IO-service 72 | boost::asio::io_service m_ioService; 73 | 74 | /// Internal signal set 75 | boost::asio::signal_set m_sigSet; 76 | 77 | /// Thread to run this 78 | std::thread m_thread; 79 | 80 | mutable std::mutex m_mutex; 81 | }; 82 | } // namespace util 83 | -------------------------------------------------------------------------------- /include/util/utility.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | namespace util 34 | { 35 | /// @typedef Number 36 | /// A variant number, which can have one of multiple representations 37 | using Number = boost::variant; 38 | 39 | /// @typedef OptNumber 40 | /// An optional number, which may be invalid 41 | using OptNumber = boost::optional; 42 | 43 | /** 44 | * @brief Convert a string to number. 45 | * @tparam T The number type 46 | * @param str The string to convert 47 | * @return an optional number, which may be invalid 48 | */ 49 | template 50 | inline OptNumber stringToNumber(const std::string& str) 51 | { 52 | std::stringstream ss(str); 53 | T result; 54 | if (ss >> result) 55 | { 56 | return Number(result); 57 | } 58 | return boost::none; 59 | } 60 | 61 | /** 62 | * @brief Trim a string on both sides. 63 | * @param str The string to trim 64 | * @return the trimmed string 65 | */ 66 | inline std::string& trimString(std::string& str) 67 | { 68 | std::size_t f = str.find_first_not_of(' '); 69 | if (f != std::string::npos) 70 | { 71 | str = str.substr(f); 72 | } 73 | std::size_t l = str.find_last_not_of(' '); 74 | if (l != std::string::npos) 75 | { 76 | str = str.substr(0, l + 1); 77 | } 78 | return str; 79 | } 80 | 81 | /** 82 | * @brief Split a string, separated at commata. 83 | * @param str The string to split 84 | * @return a list of strings 85 | */ 86 | inline std::list splitCommaSeparated(const std::string& str) 87 | { 88 | std::list list; 89 | std::stringstream ss; 90 | ss.str(str); 91 | std::string item; 92 | 93 | while (std::getline(ss, item, ',')) 94 | { 95 | list.push_back(trimString(item)); 96 | } 97 | return list; 98 | } 99 | 100 | /** 101 | * @brief Get enum value as the underlying type. 102 | * @param value The enum value 103 | * @return the value as its underlyig type 104 | */ 105 | template 106 | constexpr auto raw_type(T value) -> typename std::underlying_type::type 107 | { 108 | return static_cast::type>(value); 109 | } 110 | 111 | } // namespace util 112 | -------------------------------------------------------------------------------- /src/client/ClientFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "client/ClientFactory.h" 23 | 24 | #include "client/AprscClient.h" 25 | #include "client/GpsdClient.h" 26 | #include "client/SbsClient.h" 27 | #include "client/SensorClient.h" 28 | #include "client/net/impl/ConnectorImplBoost.h" 29 | #include "feed/AprscFeed.h" 30 | #include "feed/Feed.h" 31 | 32 | namespace client 33 | { 34 | using namespace net; 35 | 36 | template<> 37 | std::shared_ptr 38 | ClientFactory::makeClient(std::shared_ptr feed) 39 | { 40 | return std::make_shared( 41 | feed->get_endpoint(), std::static_pointer_cast(feed)->get_login(), 42 | std::make_shared()); 43 | } 44 | 45 | template<> 46 | std::shared_ptr ClientFactory::makeClient(std::shared_ptr feed) 47 | { 48 | return std::make_shared(feed->get_endpoint(), 49 | std::make_shared()); 50 | } 51 | 52 | template<> 53 | std::shared_ptr 54 | ClientFactory::makeClient(std::shared_ptr feed) 55 | { 56 | return std::make_shared(feed->get_endpoint(), 57 | std::make_shared()); 58 | } 59 | 60 | template<> 61 | std::shared_ptr ClientFactory::makeClient(std::shared_ptr feed) 62 | { 63 | return std::make_shared(feed->get_endpoint(), 64 | std::make_shared()); 65 | } 66 | 67 | std::shared_ptr ClientFactory::createClientFor(std::shared_ptr feed) 68 | { 69 | switch (feed->get_protocol()) 70 | { 71 | case feed::Feed::Protocol::APRS: return makeClient(feed); 72 | case feed::Feed::Protocol::SBS: return makeClient(feed); 73 | case feed::Feed::Protocol::GPS: return makeClient(feed); 74 | case feed::Feed::Protocol::SENSOR: return makeClient(feed); 75 | } 76 | throw std::logic_error("unknown protocol"); // can never happen 77 | } 78 | } // namespace client 79 | -------------------------------------------------------------------------------- /src/client/ClientManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "client/ClientManager.h" 23 | 24 | #include "client/ClientFactory.h" 25 | #include "feed/Feed.h" 26 | 27 | namespace client 28 | { 29 | ClientManager::~ClientManager() noexcept 30 | { 31 | stop(); 32 | } 33 | 34 | void ClientManager::subscribe(std::shared_ptr feed) 35 | { 36 | std::lock_guard lock(m_mutex); 37 | ClientIter it = m_clients.end(); 38 | it = m_clients.insert(ClientFactory::createClientFor(feed)).first; 39 | if (it != m_clients.end()) 40 | { 41 | (*it)->subscribe(feed); 42 | } 43 | else 44 | { 45 | throw std::logic_error("could not subscribe feed " + feed->get_name()); 46 | } 47 | } 48 | 49 | void ClientManager::run() 50 | { 51 | std::lock_guard lock(m_mutex); 52 | for (auto it : m_clients) 53 | { 54 | m_thdGroup.create_thread([this, it] { 55 | it->run(); 56 | std::lock_guard lock(m_mutex); 57 | m_clients.erase(it); 58 | }); 59 | } 60 | } 61 | 62 | void ClientManager::stop() 63 | { 64 | { 65 | std::lock_guard lock(m_mutex); 66 | for (auto it : m_clients) 67 | { 68 | it->scheduleStop(); 69 | } 70 | } 71 | m_thdGroup.join_all(); 72 | } 73 | } // namespace client 74 | -------------------------------------------------------------------------------- /src/client/GpsdClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "client/GpsdClient.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "util/Logger.hpp" 30 | 31 | #ifdef COMPONENT 32 | # undef COMPONENT 33 | #endif 34 | #define COMPONENT "(GpsdClient)" 35 | 36 | namespace client 37 | { 38 | using namespace net; 39 | 40 | GpsdClient::GpsdClient(const Endpoint& endpoint, std::shared_ptr connector) 41 | : Client(endpoint, COMPONENT, connector) 42 | {} 43 | 44 | void GpsdClient::handleConnect(ErrorCode error) 45 | { 46 | std::lock_guard lk(m_mutex); 47 | if (m_state == State::CONNECTING) 48 | { 49 | if (error == ErrorCode::SUCCESS) 50 | { 51 | m_connector->onWrite("?WATCH={\"enable\":true,\"nmea\":true}\r\n", 52 | std::bind(&GpsdClient::handleWatch, this, std::placeholders::_1)); 53 | } 54 | else 55 | { 56 | logger.warn(m_component, " failed to connect to ", m_endpoint.host, ":", 57 | m_endpoint.port); 58 | reconnect(); 59 | } 60 | } 61 | } 62 | 63 | void GpsdClient::stop() 64 | { 65 | if (m_state == State::RUNNING) 66 | { 67 | std::mutex sync; 68 | std::unique_lock lk(sync); 69 | std::condition_variable cv; 70 | bool sent = false; 71 | m_connector->onWrite("?WATCH={\"enable\":false}\r\n", [&](ErrorCode) { 72 | logger.info(m_component, " stopped watch"); 73 | sent = true; 74 | cv.notify_one(); 75 | }); 76 | cv.wait_for(lk, std::chrono::milliseconds(500), [&] { return sent; }); 77 | } 78 | Client::stop(); 79 | } 80 | 81 | void GpsdClient::handleWatch(ErrorCode error) 82 | { 83 | std::lock_guard lk(m_mutex); 84 | if (m_state == State::CONNECTING) 85 | { 86 | if (error == ErrorCode::SUCCESS) 87 | { 88 | m_state = State::RUNNING; 89 | logger.info(m_component, " connected to ", m_endpoint.host, ":", m_endpoint.port); 90 | read(); 91 | } 92 | else 93 | { 94 | logger.error(m_component, " send watch request failed"); 95 | reconnect(); 96 | } 97 | } 98 | } 99 | } // namespace client 100 | -------------------------------------------------------------------------------- /src/client/SbsClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "client/SbsClient.h" 23 | 24 | #include "util/Logger.hpp" 25 | 26 | #ifdef COMPONENT 27 | # undef COMPONENT 28 | #endif 29 | #define COMPONENT "(SbsClient)" 30 | 31 | namespace client 32 | { 33 | using namespace net; 34 | 35 | SbsClient::SbsClient(const Endpoint& endpoint, std::shared_ptr connector) 36 | : Client(endpoint, COMPONENT, connector) 37 | {} 38 | 39 | void SbsClient::handleConnect(ErrorCode error) 40 | { 41 | std::lock_guard lk(m_mutex); 42 | if (m_state == State::CONNECTING) 43 | { 44 | if (error == ErrorCode::SUCCESS) 45 | { 46 | m_state = State::RUNNING; 47 | logger.info(m_component, " connected to ", m_endpoint.host, ":", m_endpoint.port); 48 | read(); 49 | } 50 | else 51 | { 52 | logger.warn(m_component, " failed to connect to ", m_endpoint.host, ":", 53 | m_endpoint.port); 54 | reconnect(); 55 | } 56 | } 57 | } 58 | } // namespace client 59 | -------------------------------------------------------------------------------- /src/client/SensorClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "client/SensorClient.h" 23 | 24 | #include 25 | 26 | #include "util/Logger.hpp" 27 | 28 | #ifdef COMPONENT 29 | # undef COMPONENT 30 | #endif 31 | #define COMPONENT "(SensorClient)" 32 | 33 | namespace client 34 | { 35 | using namespace net; 36 | 37 | SensorClient::SensorClient(const Endpoint& endpoint, std::shared_ptr connector) 38 | : Client(endpoint, COMPONENT, connector) 39 | {} 40 | 41 | void SensorClient::read() 42 | { 43 | m_connector->resetTimer(WC_RCV_TIMEOUT); 44 | Client::read(); 45 | } 46 | 47 | void SensorClient::checkDeadline(ErrorCode error) 48 | { 49 | std::lock_guard lk(m_mutex); 50 | if (m_state == State::RUNNING) 51 | { 52 | if (error == ErrorCode::SUCCESS) 53 | { 54 | logger.debug(m_component, " timed out, reconnect ..."); 55 | reconnect(); 56 | } 57 | else 58 | { 59 | m_connector->onTimeout( 60 | std::bind(&SensorClient::checkDeadline, this, std::placeholders::_1)); 61 | } 62 | } 63 | } 64 | 65 | void SensorClient::handleConnect(ErrorCode error) 66 | { 67 | std::lock_guard lk(m_mutex); 68 | if (m_state == State::CONNECTING) 69 | { 70 | if (error == ErrorCode::SUCCESS) 71 | { 72 | m_state = State::RUNNING; 73 | logger.info(m_component, " connected to ", m_endpoint.host, ":", m_endpoint.port); 74 | m_connector->onTimeout( 75 | std::bind(&SensorClient::checkDeadline, this, std::placeholders::_1), 76 | WC_RCV_TIMEOUT); 77 | read(); 78 | } 79 | else 80 | { 81 | logger.warn(m_component, " failed to connect to ", m_endpoint.host, ":", 82 | m_endpoint.port); 83 | reconnect(); 84 | } 85 | } 86 | } 87 | } // namespace client 88 | -------------------------------------------------------------------------------- /src/config/ConfigReader.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "config/ConfigReader.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace config 33 | { 34 | ConfigReader::ConfigReader(std::istream& stream) : m_stream(stream) {} 35 | 36 | Properties ConfigReader::read() 37 | { 38 | boost::property_tree::ptree tree; 39 | try 40 | { 41 | boost::property_tree::read_ini(m_stream, tree); 42 | } 43 | catch (const boost::property_tree::ini_parser_error& e) 44 | { 45 | throw std::invalid_argument(e.filename() + " is not a valid INI file"); 46 | } 47 | return Properties(std::move(tree)); 48 | } 49 | } // namespace config 50 | -------------------------------------------------------------------------------- /src/config/Properties.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "config/Properties.h" 23 | 24 | #include 25 | 26 | namespace config 27 | { 28 | Properties::Properties(const boost::property_tree::ptree& ptree) : m_pTree(ptree) {} 29 | 30 | Properties::Properties(boost::property_tree::ptree&& ptree) : m_pTree(std::move(ptree)) {} 31 | 32 | std::string Properties::get_property(const std::string& path, const std::string& alternative) const 33 | { 34 | std::string property(m_pTree.get(path, alternative)); 35 | return property.empty() ? alternative : property; 36 | } 37 | 38 | Properties Properties::get_propertySection(const std::string& section) const 39 | { 40 | try 41 | { 42 | return Properties(m_pTree.get_child(section)); 43 | } 44 | catch (const boost::property_tree::ptree_bad_path&) 45 | { 46 | throw std::out_of_range(section + " not found"); 47 | } 48 | } 49 | } // namespace config 50 | -------------------------------------------------------------------------------- /src/data/AtmosphereData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "data/AtmosphereData.h" 23 | 24 | using namespace object; 25 | 26 | namespace data 27 | { 28 | AtmosphereData::AtmosphereData() : Data() {} 29 | 30 | AtmosphereData::AtmosphereData(const Atmosphere& atmosphere) : Data(), m_atmosphere(atmosphere) {} 31 | 32 | void AtmosphereData::get_serialized(std::string& dest) 33 | { 34 | std::lock_guard lock(m_mutex); 35 | dest += (++m_atmosphere).get_serialized(); 36 | } 37 | 38 | bool AtmosphereData::update(Object&& atmosphere) 39 | { 40 | std::lock_guard lock(m_mutex); 41 | return m_atmosphere.tryUpdate(std::move(atmosphere)); 42 | } 43 | 44 | double AtmosphereData::get_atmPressure() 45 | { 46 | std::lock_guard lock(m_mutex); 47 | return m_atmosphere.get_pressure(); 48 | } 49 | 50 | } // namespace data 51 | -------------------------------------------------------------------------------- /src/data/GpsData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "data/GpsData.h" 23 | 24 | #include 25 | 26 | /// @def GPS_NR_SATS_GOOD 27 | /// Good number of satellites 28 | #define GPS_NR_SATS_GOOD 7 29 | 30 | /// @def GPS_FIX_GOOD 31 | /// Good fix quality 32 | #define GPS_FIX_GOOD 1 33 | 34 | /// @def GPS_HOR_DILUTION_GOOD 35 | /// Good horizontal dilution 36 | #define GPS_HOR_DILUTION_GOOD 1.0 37 | 38 | using namespace object; 39 | 40 | namespace data 41 | { 42 | GpsData::GpsData() : Data() {} 43 | 44 | GpsData::GpsData(const GpsPosition& position, bool ground) 45 | : Data(), m_position(position), m_groundMode(ground) 46 | { 47 | m_processor.process(m_position); 48 | } 49 | 50 | void GpsData::get_serialized(std::string& dest) 51 | { 52 | std::lock_guard lock(m_mutex); 53 | m_processor.process(m_position); 54 | dest += (++m_position).get_serialized(); 55 | } 56 | 57 | bool GpsData::update(Object&& position) 58 | { 59 | std::lock_guard lock(m_mutex); 60 | if (m_positionLocked) 61 | { 62 | throw PositionAlreadyLocked(); 63 | } 64 | bool updated = m_position.tryUpdate(std::move(position)); 65 | if (updated) 66 | { 67 | m_processor.process(m_position); 68 | if (m_groundMode && isPositionGood()) 69 | { 70 | throw ReceivedGoodPosition(); 71 | } 72 | } 73 | return updated; 74 | } 75 | 76 | Position GpsData::get_position() 77 | { 78 | std::lock_guard lock(m_mutex); 79 | return m_position.get_position(); 80 | } 81 | 82 | bool GpsData::isPositionGood() 83 | { 84 | return m_position.get_nrOfSatellites() >= GPS_NR_SATS_GOOD && 85 | m_position.get_fixQuality() >= GPS_FIX_GOOD && 86 | m_position.get_dilution() <= GPS_HOR_DILUTION_GOOD; 87 | } 88 | 89 | PositionAlreadyLocked::PositionAlreadyLocked() : GpsDataException() {} 90 | 91 | const char* PositionAlreadyLocked::what() const noexcept 92 | { 93 | return "position was locked before"; 94 | } 95 | 96 | ReceivedGoodPosition::ReceivedGoodPosition() : GpsDataException() {} 97 | 98 | const char* ReceivedGoodPosition::what() const noexcept 99 | { 100 | return "received good position"; 101 | } 102 | 103 | } // namespace data 104 | -------------------------------------------------------------------------------- /src/data/WindData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "data/WindData.h" 23 | 24 | using namespace object; 25 | 26 | namespace data 27 | { 28 | WindData::WindData() : Data() {} 29 | 30 | WindData::WindData(const object::Wind& wind) : Data(), m_wind(wind) {} 31 | 32 | void WindData::get_serialized(std::string& dest) 33 | { 34 | std::lock_guard lock(m_mutex); 35 | dest += (++m_wind).get_serialized(); 36 | m_wind.set_serialized(""); 37 | } 38 | 39 | bool WindData::update(Object&& wind) 40 | { 41 | std::lock_guard lock(m_mutex); 42 | return m_wind.tryUpdate(std::move(wind)); 43 | } 44 | 45 | } // namespace data 46 | -------------------------------------------------------------------------------- /src/data/processor/GpsProcessor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "data/processor/GpsProcessor.h" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace object; 29 | 30 | namespace data 31 | { 32 | namespace processor 33 | { 34 | GpsProcessor::GpsProcessor() : Processor() {} 35 | 36 | void GpsProcessor::process(object::GpsPosition& position) 37 | { 38 | std::time_t now = std::time(nullptr); 39 | std::tm* utc = std::gmtime(&now); 40 | evalPosition(position.get_position().latitude, position.get_position().longitude); 41 | m_processed.clear(); 42 | appendGPGGA(position, utc); 43 | appendGPRMC(utc); 44 | position.set_serialized(std::move(m_processed)); 45 | } 46 | 47 | void GpsProcessor::appendGPGGA(const GpsPosition& position, const std::tm* utc) 48 | { 49 | // As we use XCSoar as frontend, we need to set the fix quality to 1. It doesn't 50 | // support others. 51 | std::snprintf( 52 | m_buffer, sizeof(m_buffer), 53 | /*"$GPGGA,%02d%02d%02d,%02.0lf%07.4lf,%c,%03.0lf%07.4lf,%c,%1d,%02d,1,%d,M,%.1lf,M,,*"*/ 54 | "$GPGGA,%02d%02d%02d,%02.0lf%07.4lf,%c,%03.0lf%07.4lf,%c,1,%02hhu,1,%d,M,%.1lf,M,,*", 55 | utc->tm_hour, utc->tm_min, utc->tm_sec, m_degLatitude, m_minLatitude, m_directionSN, 56 | m_degLongitude, m_minLongitude, m_directionEW, /*pos.fixQa,*/ position.get_nrOfSatellites(), 57 | position.get_position().altitude, position.get_geoid()); 58 | m_processed.append(m_buffer); 59 | finishSentence(); 60 | } 61 | 62 | void GpsProcessor::appendGPRMC(const std::tm* utc) 63 | { 64 | std::snprintf( 65 | m_buffer, sizeof(m_buffer), 66 | "$GPRMC,%02d%02d%02d,A,%02.0lf%05.2lf,%c,%03.0lf%05.2lf,%c,0,0,%02d%02d%02d,001.0,W*", 67 | utc->tm_hour, utc->tm_min, utc->tm_sec, m_degLatitude, m_minLatitude, m_directionSN, 68 | m_degLongitude, m_minLongitude, m_directionEW, utc->tm_mday, utc->tm_mon + 1, 69 | utc->tm_year - 100); 70 | m_processed.append(m_buffer); 71 | finishSentence(); 72 | } 73 | 74 | void GpsProcessor::evalPosition(double latitude, double longitude) 75 | { 76 | m_directionSN = (latitude < 0) ? 'S' : 'N'; 77 | m_directionEW = (longitude < 0) ? 'W' : 'E'; 78 | m_degLatitude = std::abs(std::floor(latitude)); 79 | m_minLatitude = std::abs(60.0 * (latitude - m_degLatitude)); 80 | m_degLongitude = std::abs(std::floor(longitude)); 81 | m_minLongitude = std::abs(60.0 * (longitude - m_degLongitude)); 82 | } 83 | 84 | } // namespace processor 85 | } // namespace data 86 | -------------------------------------------------------------------------------- /src/feed/AprscFeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/AprscFeed.h" 23 | 24 | #include 25 | 26 | #include "config/Configuration.h" 27 | #include "data/AircraftData.h" 28 | #include "feed/parser/AprsParser.h" 29 | #include "object/Aircraft.h" 30 | #include "util/Logger.hpp" 31 | 32 | #ifdef COMPONENT 33 | # undef COMPONENT 34 | #endif 35 | #define COMPONENT "(AprscFeed)" 36 | 37 | namespace feed 38 | { 39 | parser::AprsParser AprscFeed::s_parser; 40 | 41 | AprscFeed::AprscFeed(const std::string& name, const config::Properties& properties, 42 | std::shared_ptr data, std::int32_t maxHeight) 43 | : Feed(name, COMPONENT, properties, data) 44 | { 45 | parser::AprsParser::s_maxHeight = maxHeight; 46 | if (m_properties.get_property(KV_KEY_LOGIN, "-") == "-") 47 | { 48 | logger.warn(m_component, " could not find: ", m_name, "." KV_KEY_LOGIN); 49 | throw std::logic_error("No login given"); 50 | } 51 | } 52 | 53 | Feed::Protocol AprscFeed::get_protocol() const 54 | { 55 | return Protocol::APRS; 56 | } 57 | 58 | bool AprscFeed::process(const std::string& response) 59 | { 60 | object::Aircraft ac(get_priority()); 61 | if (s_parser.unpack(response, ac)) 62 | { 63 | m_data->update(std::move(ac)); 64 | } 65 | return true; 66 | } 67 | 68 | std::string AprscFeed::get_login() const 69 | { 70 | return m_properties.get_property(KV_KEY_LOGIN); 71 | } 72 | 73 | } // namespace feed 74 | -------------------------------------------------------------------------------- /src/feed/AtmosphereFeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/AtmosphereFeed.h" 23 | 24 | #include 25 | 26 | #include "config/Configuration.h" 27 | #include "data/AtmosphereData.h" 28 | #include "feed/parser/AtmosphereParser.h" 29 | #include "object/Atmosphere.h" 30 | 31 | #ifdef COMPONENT 32 | # undef COMPONENT 33 | #endif 34 | #define COMPONENT "(AtmosphereFeed)" 35 | 36 | namespace feed 37 | { 38 | parser::AtmosphereParser AtmosphereFeed::s_parser; 39 | 40 | AtmosphereFeed::AtmosphereFeed(const std::string& name, const config::Properties& properties, 41 | std::shared_ptr data) 42 | : Feed(name, COMPONENT, properties, data) 43 | {} 44 | 45 | Feed::Protocol AtmosphereFeed::get_protocol() const 46 | { 47 | return Protocol::SENSOR; 48 | } 49 | 50 | bool AtmosphereFeed::process(const std::string& response) 51 | { 52 | object::Atmosphere atmos(get_priority()); 53 | if (s_parser.unpack(response, atmos)) 54 | { 55 | m_data->update(std::move(atmos)); 56 | } 57 | return true; 58 | } 59 | 60 | } // namespace feed 61 | -------------------------------------------------------------------------------- /src/feed/Feed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/Feed.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "config/Configuration.h" 30 | #include "data/Data.hpp" 31 | #include "util/Logger.hpp" 32 | 33 | using namespace config; 34 | 35 | namespace feed 36 | { 37 | Feed::Feed(const std::string& name, const char* component, const Properties& properties, 38 | std::shared_ptr data) 39 | : m_name(name), m_component(component), m_properties(properties), m_data(data) 40 | { 41 | initPriority(); 42 | if (m_properties.get_property(KV_KEY_HOST).empty()) 43 | { 44 | logger.warn(m_component, " could not find: ", m_name, "." KV_KEY_HOST); 45 | throw std::logic_error("No host given"); 46 | } 47 | if (m_properties.get_property(KV_KEY_PORT).empty()) 48 | { 49 | logger.warn(m_component, " could not find: ", m_name, "." KV_KEY_PORT); 50 | throw std::logic_error("No port given"); 51 | } 52 | } 53 | 54 | void Feed::initPriority() noexcept 55 | { 56 | try 57 | { 58 | m_priority = static_cast(std::max( 59 | 0, std::min(std::stoul(m_properties.get_property(KV_KEY_PRIORITY)), 60 | std::numeric_limits::max()))); 61 | } 62 | catch (const std::logic_error&) 63 | { 64 | logger.warn(m_component, " create ", m_name, ": Invalid priority given."); 65 | } 66 | } 67 | 68 | client::net::Endpoint Feed::get_endpoint() const 69 | { 70 | return {m_properties.get_property(KV_KEY_HOST), m_properties.get_property(KV_KEY_PORT)}; 71 | } 72 | 73 | } // namespace feed 74 | -------------------------------------------------------------------------------- /src/feed/GpsFeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/GpsFeed.h" 23 | 24 | #include 25 | #include 26 | 27 | #include "config/Configuration.h" 28 | #include "data/GpsData.h" 29 | #include "feed/parser/GpsParser.h" 30 | #include "object/GpsPosition.h" 31 | #include "util/Logger.hpp" 32 | 33 | #ifdef COMPONENT 34 | # undef COMPONENT 35 | #endif 36 | #define COMPONENT "(GpsFeed)" 37 | 38 | namespace feed 39 | { 40 | parser::GpsParser GpsFeed::s_parser; 41 | 42 | GpsFeed::GpsFeed(const std::string& name, const config::Properties& properties, 43 | std::shared_ptr data) 44 | : Feed(name, COMPONENT, properties, data) 45 | {} 46 | 47 | Feed::Protocol GpsFeed::get_protocol() const 48 | { 49 | return Protocol::GPS; 50 | } 51 | 52 | bool GpsFeed::process(const std::string& response) 53 | { 54 | object::GpsPosition pos(get_priority()); 55 | if (s_parser.unpack(response, pos)) 56 | { 57 | try 58 | { 59 | m_data->update(std::move(pos)); 60 | } 61 | catch (const data::GpsDataException& e) 62 | { 63 | logger.info(m_component, " ", m_name, ": ", e.what()); 64 | return false; 65 | } 66 | } 67 | return true; 68 | } 69 | 70 | } // namespace feed 71 | -------------------------------------------------------------------------------- /src/feed/SbsFeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/SbsFeed.h" 23 | 24 | #include 25 | 26 | #include "config/Configuration.h" 27 | #include "data/AircraftData.h" 28 | #include "feed/parser/SbsParser.h" 29 | #include "object/Aircraft.h" 30 | 31 | #ifdef COMPONENT 32 | # undef COMPONENT 33 | #endif 34 | #define COMPONENT "(SbsFeed)" 35 | 36 | namespace feed 37 | { 38 | parser::SbsParser SbsFeed::s_parser; 39 | 40 | SbsFeed::SbsFeed(const std::string& name, const config::Properties& properties, 41 | std::shared_ptr data, std::int32_t maxHeight) 42 | : Feed(name, COMPONENT, properties, data) 43 | { 44 | parser::SbsParser::s_maxHeight = maxHeight; 45 | } 46 | 47 | Feed::Protocol SbsFeed::get_protocol() const 48 | { 49 | return Protocol::SBS; 50 | } 51 | 52 | bool SbsFeed::process(const std::string& response) 53 | { 54 | object::Aircraft ac(get_priority()); 55 | if (s_parser.unpack(response, ac)) 56 | { 57 | m_data->update(std::move(ac)); 58 | } 59 | return true; 60 | } 61 | 62 | } // namespace feed 63 | -------------------------------------------------------------------------------- /src/feed/WindFeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/WindFeed.h" 23 | 24 | #include 25 | 26 | #include "config/Configuration.h" 27 | #include "data/WindData.h" 28 | #include "feed/parser/WindParser.h" 29 | #include "object/Wind.h" 30 | 31 | #ifdef COMPONENT 32 | # undef COMPONENT 33 | #endif 34 | #define COMPONENT "(WindFeed)" 35 | 36 | namespace feed 37 | { 38 | parser::WindParser WindFeed::s_parser; 39 | 40 | WindFeed::WindFeed(const std::string& name, const config::Properties& properties, 41 | std::shared_ptr data) 42 | : Feed(name, COMPONENT, properties, data) 43 | {} 44 | 45 | Feed::Protocol WindFeed::get_protocol() const 46 | { 47 | return Protocol::SENSOR; 48 | } 49 | 50 | bool WindFeed::process(const std::string& response) 51 | { 52 | object::Wind wind(get_priority()); 53 | if (s_parser.unpack(response, wind)) 54 | { 55 | m_data->update(std::move(wind)); 56 | } 57 | return true; 58 | } 59 | 60 | } // namespace feed 61 | -------------------------------------------------------------------------------- /src/feed/parser/AtmosphereParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/parser/AtmosphereParser.h" 23 | 24 | #include 25 | #include 26 | 27 | #include "util/math.hpp" 28 | 29 | namespace feed 30 | { 31 | namespace parser 32 | { 33 | AtmosphereParser::AtmosphereParser() : Parser() {} 34 | 35 | bool AtmosphereParser::unpack(const std::string& sentence, object::Atmosphere& atmosphere) noexcept 36 | { 37 | try 38 | { 39 | if ((std::stoi(sentence.substr(sentence.rfind('*') + 1, 2), nullptr, 16) == 40 | math::checksum(sentence.c_str(), sentence.length())) && 41 | (sentence.find("MDA") != std::string::npos)) 42 | { 43 | bool valid = false; 44 | std::size_t tmpB = sentence.find('B') - 1; 45 | std::size_t tmpS = sentence.substr(0, tmpB).find_last_of(',') + 1; 46 | std::size_t subLen = tmpB - tmpS; 47 | std::size_t numIdx; 48 | double tmpPress = std::stod(sentence.substr(tmpS, subLen), &numIdx) * 1000.0; 49 | if ((valid = (numIdx == subLen))) 50 | { 51 | atmosphere.set_serialized(std::string(sentence)); 52 | atmosphere.set_pressure(tmpPress); 53 | } 54 | return valid; 55 | } 56 | } 57 | catch (const std::logic_error&) 58 | {} 59 | return false; 60 | } 61 | 62 | } // namespace parser 63 | } // namespace feed 64 | -------------------------------------------------------------------------------- /src/feed/parser/WindParser.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "feed/parser/WindParser.h" 23 | 24 | #include 25 | 26 | #include "util/math.hpp" 27 | 28 | namespace feed 29 | { 30 | namespace parser 31 | { 32 | WindParser::WindParser() : Parser() {} 33 | 34 | bool WindParser::unpack(const std::string& sentence, object::Wind& wind) noexcept 35 | { 36 | try 37 | { 38 | if ((std::stoi(sentence.substr(sentence.rfind('*') + 1, 2), nullptr, 16) == 39 | math::checksum(sentence.c_str(), sentence.length())) && 40 | (sentence.find("MWV") != std::string::npos)) 41 | { 42 | wind.set_serialized(std::string(sentence)); 43 | return true; 44 | } 45 | } 46 | catch (const std::logic_error&) 47 | {} 48 | return false; 49 | } 50 | 51 | } // namespace parser 52 | } // namespace feed 53 | -------------------------------------------------------------------------------- /src/object/Aircraft.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "object/Aircraft.h" 23 | 24 | #include 25 | 26 | namespace object 27 | { 28 | Aircraft::Aircraft() : Aircraft(0) {} 29 | 30 | Aircraft::Aircraft(std::uint32_t priority) 31 | : Object(priority), 32 | m_idType(IdType::ICAO), 33 | m_aircraftType(AircraftType::POWERED_AIRCRAFT), 34 | m_targetType(TargetType::TRANSPONDER) 35 | {} 36 | 37 | void Aircraft::assign(Object&& other) 38 | { 39 | try 40 | { 41 | Aircraft&& update = dynamic_cast(other); 42 | Object::assign(std::move(other)); 43 | this->m_idType = update.m_idType; 44 | this->m_aircraftType = update.m_aircraftType; 45 | this->m_targetType = update.m_targetType; 46 | this->m_position = update.m_position; 47 | this->m_movement = update.m_movement; 48 | this->m_timeStamp = update.m_timeStamp; 49 | this->m_fullInfo = update.m_fullInfo; 50 | } 51 | catch (const std::bad_cast&) 52 | {} 53 | } 54 | 55 | bool Aircraft::canUpdate(const Object& other) const 56 | { 57 | try 58 | { 59 | const Aircraft& toUpdate = dynamic_cast(other); 60 | return (this->m_timeStamp > toUpdate.m_timeStamp) && 61 | (toUpdate.m_targetType == TargetType::TRANSPONDER || 62 | this->m_targetType == TargetType::FLARM) && 63 | Object::canUpdate(other); 64 | } 65 | catch (const std::bad_cast&) 66 | { 67 | return false; 68 | } 69 | } 70 | 71 | void Aircraft::set_aircraftType(Aircraft::AircraftType type) 72 | { 73 | m_aircraftType = type > AircraftType::STATIC_OBJECT ? AircraftType::UNKNOWN : type; 74 | } 75 | 76 | void Aircraft::set_idType(Aircraft::IdType type) 77 | { 78 | m_idType = type > IdType::OGN ? IdType::RANDOM : type; 79 | } 80 | 81 | } // namespace object 82 | -------------------------------------------------------------------------------- /src/object/Atmosphere.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | Copyright (C) 2016 VirtualFlightRadar-Backend 4 | A detailed list of copyright holders can be found in the file "AUTHORS". 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License version 3 7 | as published by the Free Software Foundation. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | } 16 | */ 17 | 18 | #include "object/Atmosphere.h" 19 | 20 | #include 21 | 22 | namespace object 23 | { 24 | Atmosphere::Atmosphere() : Object() {} 25 | 26 | Atmosphere::Atmosphere(std::uint32_t priority) : Object(priority) {} 27 | 28 | Atmosphere::Atmosphere(double pressure, std::uint32_t priority) 29 | : Object(priority), m_pressure(pressure) 30 | {} 31 | 32 | void Atmosphere::assign(Object&& other) 33 | { 34 | try 35 | { 36 | Atmosphere&& update = dynamic_cast(other); 37 | Object::assign(std::move(other)); 38 | this->m_pressure = update.m_pressure; 39 | } 40 | catch (const std::bad_cast&) 41 | {} 42 | } 43 | 44 | } // namespace object 45 | -------------------------------------------------------------------------------- /src/object/GpsPosition.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | Copyright (C) 2016 VirtualFlightRadar-Backend 4 | A detailed list of copyright holders can be found in the file "AUTHORS". 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License version 3 7 | as published by the Free Software Foundation. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | } 16 | */ 17 | 18 | #include "object/GpsPosition.h" 19 | 20 | #include 21 | 22 | namespace object 23 | { 24 | GpsPosition::GpsPosition() : Object() {} 25 | 26 | GpsPosition::GpsPosition(std::uint32_t priority) : Object(priority) {} 27 | 28 | GpsPosition::GpsPosition(const Position& position, double geoid) 29 | : Object(), m_position(position), m_geoid(geoid) 30 | {} 31 | 32 | void GpsPosition::assign(Object&& other) 33 | { 34 | try 35 | { 36 | GpsPosition&& update = dynamic_cast(other); 37 | Object::assign(std::move(other)); 38 | this->m_position = update.m_position; 39 | this->m_timeStamp = update.m_timeStamp; 40 | this->m_nrOfSatellites = update.m_nrOfSatellites; 41 | this->m_fixQuality = update.m_fixQuality; 42 | this->m_geoid = update.m_geoid; 43 | this->m_dilution = update.m_dilution; 44 | } 45 | catch (const std::bad_cast&) 46 | {} 47 | } 48 | 49 | bool GpsPosition::canUpdate(const Object& other) const 50 | { 51 | try 52 | { 53 | const GpsPosition& toUpdate = dynamic_cast(other); 54 | return (this->m_timeStamp > toUpdate.m_timeStamp) && Object::canUpdate(other); 55 | } 56 | catch (const std::bad_cast&) 57 | { 58 | return false; 59 | } 60 | } 61 | 62 | } // namespace object 63 | -------------------------------------------------------------------------------- /src/object/Object.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | Copyright (C) 2016 VirtualFlightRadar-Backend 4 | A detailed list of copyright holders can be found in the file "AUTHORS". 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License version 3 7 | as published by the Free Software Foundation. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | } 16 | */ 17 | 18 | #include "object/Object.h" 19 | 20 | namespace object 21 | { 22 | Object::Object(std::uint32_t priority) : m_lastPriority(priority) {} 23 | 24 | void Object::assign(Object&& other) 25 | { 26 | this->m_serialized = std::move(other.m_serialized); 27 | this->m_lastPriority = other.m_lastPriority; 28 | this->m_updateAge = 0; 29 | } 30 | 31 | bool Object::tryUpdate(Object&& other) 32 | { 33 | if (other.canUpdate(*this)) 34 | { 35 | this->assign(std::move(other)); 36 | return true; 37 | } 38 | return false; 39 | } 40 | 41 | bool Object::canUpdate(const Object& other) const 42 | { 43 | return this->m_lastPriority >= other.m_lastPriority || other.m_updateAge >= OBJ_OUTDATED; 44 | } 45 | 46 | void Object::set_serialized(std::string&& serialized) 47 | { 48 | m_serialized = std::move(serialized); 49 | } 50 | 51 | const std::string& Object::get_serialized() const 52 | { 53 | return m_serialized; 54 | } 55 | 56 | Object& Object::operator++() 57 | { 58 | ++m_updateAge; 59 | return *this; 60 | } 61 | 62 | } // namespace object 63 | -------------------------------------------------------------------------------- /src/object/Wind.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | Copyright (C) 2016 VirtualFlightRadar-Backend 4 | A detailed list of copyright holders can be found in the file "AUTHORS". 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License version 3 7 | as published by the Free Software Foundation. 8 | This program is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | You should have received a copy of the GNU General Public License 13 | along with this program; if not, write to the Free Software 14 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 | } 16 | */ 17 | 18 | #include "object/Wind.h" 19 | 20 | namespace object 21 | { 22 | Wind::Wind() : Object() {} 23 | 24 | Wind::Wind(std::uint32_t priority) : Object(priority) {} 25 | 26 | } // namespace object 27 | -------------------------------------------------------------------------------- /src/object/impl/DateTimeImplBoost.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "object/impl/DateTimeImplBoost.h" 23 | 24 | #include 25 | 26 | namespace object 27 | { 28 | namespace timestamp 29 | { 30 | std::int64_t DateTimeImplBoost::now() 31 | { 32 | return static_cast( 33 | boost::posix_time::time_duration( 34 | boost::posix_time::microsec_clock::universal_time().time_of_day()) 35 | .total_milliseconds()); 36 | } 37 | 38 | std::uint32_t DateTimeImplBoost::day() 39 | { 40 | return static_cast( 41 | boost::posix_time::microsec_clock::universal_time().date().modjulian_day()); 42 | } 43 | 44 | } // namespace timestamp 45 | } // namespace object 46 | -------------------------------------------------------------------------------- /src/server/net/SocketException.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "server/net/SocketException.h" 23 | 24 | namespace server 25 | { 26 | namespace net 27 | { 28 | SocketException::SocketException(const std::string& msg) : std::exception(), m_message(msg) {} 29 | 30 | const char* SocketException::what() const noexcept 31 | { 32 | return m_message.c_str(); 33 | } 34 | } // namespace net 35 | } // namespace server 36 | -------------------------------------------------------------------------------- /src/server/net/impl/SocketImplBoost.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "server/net/impl/SocketImplBoost.h" 23 | 24 | #include 25 | 26 | #include "server/net/SocketException.h" 27 | 28 | namespace server 29 | { 30 | using namespace net; 31 | 32 | SocketImplBoost::SocketImplBoost(SocketImplBoost&& other) : m_socket(boost::move(other.m_socket)) {} 33 | 34 | SocketImplBoost& SocketImplBoost::operator=(SocketImplBoost&& other) 35 | { 36 | m_socket = boost::move(other.m_socket); 37 | return *this; 38 | } 39 | 40 | SocketImplBoost::SocketImplBoost(BOOST_RV_REF(boost::asio::ip::tcp::socket) socket) 41 | : m_socket(boost::move(socket)) 42 | { 43 | if (m_socket.is_open()) 44 | { 45 | m_socket.non_blocking(true); 46 | } 47 | } 48 | 49 | SocketImplBoost::~SocketImplBoost() noexcept 50 | { 51 | close(); 52 | } 53 | 54 | std::string SocketImplBoost::get_address() const 55 | { 56 | if (!m_socket.is_open()) 57 | { 58 | throw SocketException("cannot get address from closed socket"); 59 | } 60 | return m_socket.remote_endpoint().address().to_string(); 61 | } 62 | 63 | bool SocketImplBoost::write(const std::string& msg) 64 | { 65 | if (!m_socket.is_open()) 66 | { 67 | throw SocketException("cannot write on closed socket"); 68 | } 69 | boost::system::error_code ec; 70 | boost::asio::write(m_socket, boost::asio::buffer(msg), ec); 71 | return !ec; 72 | } 73 | 74 | void SocketImplBoost::close() 75 | { 76 | if (m_socket.is_open()) 77 | { 78 | boost::system::error_code ignored_ec; 79 | m_socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ignored_ec); 80 | m_socket.close(); 81 | } 82 | } 83 | 84 | boost::asio::ip::tcp::socket& SocketImplBoost::get() 85 | { 86 | return m_socket; 87 | } 88 | 89 | } // namespace server 90 | -------------------------------------------------------------------------------- /src/util/Logger.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "util/Logger.hpp" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | Logger logger; 29 | 30 | void Logger::set_debug(bool enable) 31 | { 32 | std::lock_guard lock(m_mutex); 33 | m_debugEnabled = enable; 34 | } 35 | 36 | void Logger::set_logFile(const std::string& file) 37 | { 38 | std::lock_guard lock(m_mutex); 39 | m_logFile = std::ofstream(file); 40 | if (!m_logFile) 41 | { 42 | throw std::runtime_error("Could not open log file"); 43 | } 44 | m_outStream = &m_logFile; 45 | m_errStream = &m_logFile; 46 | } 47 | 48 | std::string Logger::get_time() 49 | { 50 | std::time_t tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); 51 | char time[32] = ""; 52 | std::strftime(time, 32, "%c", gmtime(&tt)); 53 | return std::string(time); 54 | } 55 | -------------------------------------------------------------------------------- /src/util/SignalListener.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "util/SignalListener.h" 23 | 24 | namespace util 25 | { 26 | SignalListener::SignalListener() : m_ioService(), m_sigSet(m_ioService) 27 | { 28 | m_sigSet.add(SIGINT); 29 | m_sigSet.add(SIGTERM); 30 | #ifdef SIGQUIT 31 | m_sigSet.add(SIGQUIT); 32 | #endif 33 | } 34 | 35 | SignalListener::~SignalListener() noexcept 36 | { 37 | stop(); 38 | } 39 | 40 | void SignalListener::run() 41 | { 42 | std::lock_guard lock(m_mutex); 43 | m_thread = std::thread([this]() { m_ioService.run(); }); 44 | } 45 | 46 | void SignalListener::stop() 47 | { 48 | { 49 | std::lock_guard lock(m_mutex); 50 | if (!m_ioService.stopped()) 51 | { 52 | m_ioService.stop(); 53 | } 54 | } 55 | if (m_thread.joinable()) 56 | { 57 | m_thread.join(); 58 | } 59 | } 60 | 61 | void SignalListener::addHandler(const SignalHandler& handler) 62 | { 63 | std::lock_guard lock(m_mutex); 64 | m_sigSet.async_wait(handler); 65 | } 66 | } // namespace util 67 | -------------------------------------------------------------------------------- /test/DateTimeImplTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "DateTimeImplTest.h" 23 | 24 | std::int64_t DateTimeImplTest::_now = 0; 25 | std::uint32_t DateTimeImplTest::_day = 0; 26 | 27 | std::int64_t DateTimeImplTest::now() 28 | { 29 | return _now; 30 | } 31 | std::uint32_t DateTimeImplTest::day() 32 | { 33 | return _day; 34 | } 35 | void DateTimeImplTest::set_day(std::uint32_t d) 36 | { 37 | _day = d; 38 | } 39 | void DateTimeImplTest::set_now(std::uint32_t h, std::uint32_t m, std::uint32_t s) 40 | { 41 | _now = h * 3600000 + m * 60000 + s * 1000; 42 | } 43 | -------------------------------------------------------------------------------- /test/NetworkInterfaceImplTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "NetworkInterfaceImplTest.h" 23 | 24 | #include 25 | 26 | #include "server/Connection.hpp" 27 | 28 | #include "SocketImplTest.h" 29 | 30 | namespace server 31 | { 32 | namespace net 33 | { 34 | NetworkInterfaceImplTests::NetworkInterfaceImplTests() : NetworkInterface() {} 35 | 36 | NetworkInterfaceImplTests::~NetworkInterfaceImplTests() noexcept {} 37 | 38 | void NetworkInterfaceImplTests::run(std::unique_lock& lock) 39 | { 40 | lock.unlock(); 41 | while (!stopped) 42 | { 43 | std::this_thread::yield(); 44 | } 45 | } 46 | 47 | void NetworkInterfaceImplTests::stop() 48 | { 49 | if (on_accept) on_accept(true); 50 | } 51 | 52 | void NetworkInterfaceImplTests::onAccept(const std::function& callback) 53 | { 54 | on_accept = callback; 55 | } 56 | 57 | void NetworkInterfaceImplTests::close() 58 | { 59 | if (on_accept) on_accept(true); 60 | } 61 | 62 | std::unique_ptr> NetworkInterfaceImplTests::startConnection() 63 | { 64 | return Connection::create(SocketImplTest(0)); 65 | } 66 | 67 | std::string NetworkInterfaceImplTests::get_currentAddress() const 68 | { 69 | return currentAddress; 70 | } 71 | 72 | void NetworkInterfaceImplTests::connect(bool err, const std::string& adr) 73 | { 74 | currentAddress = adr; 75 | on_accept(err); 76 | } 77 | } // namespace net 78 | } // namespace server 79 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # VFR-B Test Reports 2 | 3 | This directory contains a C++ unit-test framework as git submodule. In the reports folder, a test report and a HTML coverage report can be found. To view the coverage report open up the index.html in any browser. To view the test report open up the unittest/index.html in any browser. 4 | 5 | These unit-tests are part of the travis build process. Thus a passing build includes running tests without any failures or errors. 6 | Some components can not be tested inside a testsuite, hence the coverage for those stays low. But every component is at least tested live in a real, and simulated, environment. 7 | 8 | ## include test framework 9 | 10 | Run `git submodule update --remote`. 11 | -------------------------------------------------------------------------------- /test/SocketImplTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "SocketImplTest.h" 23 | 24 | namespace server 25 | { 26 | namespace net 27 | { 28 | SocketImplTest::SocketImplTest(SocketImplTest&& other) : m_socket(other.m_socket) {} 29 | 30 | SocketImplTest& SocketImplTest::operator=(SocketImplTest&& other) 31 | { 32 | m_socket = other.m_socket; 33 | return *this; 34 | } 35 | 36 | SocketImplTest::SocketImplTest(int&& socket) : m_socket(socket) {} 37 | 38 | SocketImplTest::~SocketImplTest() noexcept {} 39 | 40 | std::string SocketImplTest::get_address() const 41 | { 42 | return m_address; 43 | } 44 | 45 | bool SocketImplTest::write(const std::string& msg) 46 | { 47 | m_buffer = msg; 48 | return true; 49 | } 50 | 51 | void SocketImplTest::close() 52 | { 53 | m_socket = 0; 54 | } 55 | 56 | int& SocketImplTest::get() 57 | { 58 | return m_socket; 59 | } 60 | } // namespace net 61 | } // namespace server 62 | -------------------------------------------------------------------------------- /test/TestClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "helper.hpp" 23 | 24 | using namespace sctf; 25 | 26 | void test_client(test::TestSuitesRunner& runner) 27 | {} 28 | -------------------------------------------------------------------------------- /test/TestFeed.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "helper.hpp" 23 | 24 | using namespace sctf; 25 | 26 | void test_feed(test::TestSuitesRunner& runner) 27 | {} 28 | -------------------------------------------------------------------------------- /test/TestMath.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include 23 | 24 | #include "util/math.hpp" 25 | #include "helper.hpp" 26 | 27 | using namespace sctf; 28 | 29 | void test_math(test::TestSuitesRunner& runner) 30 | { 31 | describe("math utils", runner, "math") 32 | ->test("radian", 33 | []() { 34 | assertEquals(math::radian(45.0), 0.785398); 35 | assertEquals(math::radian(0.0), 0.0); 36 | assertEquals(math::radian(360.0), 6.28319); 37 | }) 38 | ->test("degree", 39 | []() { 40 | assertEquals(math::degree(0.785398), 45.0); 41 | assertEquals(math::degree(0.0), 0.0); 42 | assertEquals(math::degree(6.28319), 360.0); 43 | }) 44 | ->test("doubleToInt", 45 | []() { 46 | assertEquals(math::doubleToInt(0.0), 0); 47 | assertEquals(math::doubleToInt(1.4), 1); 48 | assertEquals(math::doubleToInt(1.5), 2); 49 | assertEquals(math::doubleToInt(-1.4), -1); 50 | assertEquals(math::doubleToInt(-1.5), -2); 51 | }) 52 | ->test("dmToDeg", 53 | []() { 54 | assertEquals(math::dmToDeg(0.0), 0.0); 55 | assertEquals(math::dmToDeg(9030.50), 90.508333); 56 | assertEquals(math::dmToDeg(18000.0), 180.0); 57 | assertEquals(math::dmToDeg(-4512.3456), 45.205760); 58 | }) 59 | ->test("calcIcaoHeight", 60 | []() { 61 | assertEquals(math::icaoHeight(0.0), 44331); 62 | assertEquals(math::icaoHeight(1013.25), 0); 63 | assertEquals(math::icaoHeight(980.0), 281); 64 | }) 65 | ->test("checksum", []() { 66 | assertEquals(math::checksum("", sizeof("")), 0); 67 | assertEquals(math::checksum("\0", sizeof("\0")), 0); 68 | assertEquals(math::checksum("$abc*", sizeof("$abc*")), 96); 69 | }); 70 | } 71 | -------------------------------------------------------------------------------- /test/TestServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "server/Server.hpp" 23 | 24 | #include "NetworkInterfaceImplTest.h" 25 | #include "SocketImplTest.h" 26 | #include "helper.hpp" 27 | 28 | using namespace sctf; 29 | using namespace server; 30 | 31 | void test_server(test::TestSuitesRunner& runner) 32 | { 33 | /*describe("Basic Server tests", runner)->test("accept connection", [] { 34 | auto ifc = std::make_shared(); 35 | Server server(ifc); 36 | server.run(); 37 | });*/ 38 | } 39 | -------------------------------------------------------------------------------- /test/UnitTests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #include "util/Logger.hpp" 23 | 24 | #include "helper.hpp" 25 | 26 | using namespace sctf; 27 | 28 | TEST_FUNCTION(test_config) 29 | TEST_FUNCTION(test_data) 30 | TEST_FUNCTION(test_data_processor) 31 | TEST_FUNCTION(test_feed_parser) 32 | TEST_FUNCTION(test_object) 33 | TEST_FUNCTION(test_math) 34 | TEST_FUNCTION(test_client) 35 | TEST_FUNCTION(test_server) 36 | TEST_FUNCTION(test_feed) 37 | 38 | int main(int, char**) 39 | { 40 | logger.set_logFile("/dev/null"); 41 | // auto rep = createXmlReporter(); 42 | auto rep = createPlainTextReporter(true); 43 | test::TestSuitesRunner runner; 44 | 45 | test_config(runner); 46 | test_data(runner); 47 | test_data_processor(runner); 48 | test_feed_parser(runner); 49 | test_object(runner); 50 | test_math(runner); 51 | test_feed(runner); 52 | test_client(runner); 53 | test_server(runner); 54 | 55 | return rep->report(runner) > 0 ? 1 : 0; 56 | } 57 | -------------------------------------------------------------------------------- /test/include/DateTimeImplTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | struct DateTimeImplTest 27 | { 28 | static std::int64_t now(); 29 | static std::uint32_t day(); 30 | static void set_day(std::uint32_t d); 31 | static void set_now(std::uint32_t h, std::uint32_t m, std::uint32_t s); 32 | 33 | private: 34 | static std::int64_t _now; 35 | static std::uint32_t _day; 36 | }; 37 | -------------------------------------------------------------------------------- /test/include/NetworkInterfaceImplTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "server/net/NetworkInterface.hpp" 25 | 26 | namespace server 27 | { 28 | namespace net 29 | { 30 | class SocketImplTest; 31 | 32 | class NetworkInterfaceImplTests : public NetworkInterface 33 | { 34 | public: 35 | NetworkInterfaceImplTests(); 36 | ~NetworkInterfaceImplTests() noexcept; 37 | 38 | void run(std::unique_lock& lock) override; 39 | 40 | void stop() override; 41 | 42 | void onAccept(const std::function& callback) override; 43 | 44 | void close() override; 45 | 46 | std::unique_ptr> startConnection() override; 47 | 48 | std::string get_currentAddress() const override; 49 | 50 | void connect(bool err, const std::string& adr); 51 | 52 | private: 53 | std::function on_accept; 54 | std::string currentAddress; 55 | bool stopped = false; 56 | }; 57 | } // namespace net 58 | } // namespace server 59 | -------------------------------------------------------------------------------- /test/include/SocketImplTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | #include "util/defines.h" 28 | 29 | namespace server 30 | { 31 | namespace net 32 | { 33 | class SocketImplTest 34 | { 35 | public: 36 | MOVABLE_BUT_NOT_COPYABLE(SocketImplTest) 37 | 38 | explicit SocketImplTest(int&& socket); 39 | ~SocketImplTest() noexcept; 40 | 41 | std::string get_address() const; 42 | bool write(const std::string& msg); 43 | void close(); 44 | int& get(); 45 | 46 | private: 47 | std::string m_buffer; 48 | std::int32_t m_socket; 49 | std::string m_address; 50 | 51 | public: 52 | GETTER_CR(buffer) 53 | SETTER_CR(address) 54 | }; 55 | } // namespace net 56 | } // namespace server 57 | -------------------------------------------------------------------------------- /test/include/helper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright_License { 3 | 4 | Copyright (C) 2016 VirtualFlightRadar-Backend 5 | A detailed list of copyright holders can be found in the file "AUTHORS". 6 | 7 | This program is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU General Public License version 3 9 | as published by the Free Software Foundation. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | } 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include "object/Aircraft.h" 32 | #include "util/utility.hpp" 33 | 34 | #include "sctf.hpp" 35 | 36 | #define TEST_FUNCTION(NAME) extern void NAME(test::TestSuitesRunner&); 37 | 38 | #define syso(M) std::cout << M << std::endl 39 | 40 | #define assertEqStr(V, E) assertT(V, EQUALS, E, std::string) 41 | 42 | namespace sctf 43 | { 44 | namespace util 45 | { 46 | template<> 47 | inline std::string 48 | serialize(const object::Aircraft::TargetType& crTargetType) 49 | { 50 | return std::to_string(::util::raw_type(crTargetType)); 51 | } 52 | } // namespace util 53 | } // namespace sctf 54 | 55 | namespace helper 56 | { 57 | static boost::regex pflauRe("\\$PFLAU,,,,1,0,([-]?\\d+?),0,(\\d+?),(\\d+?),(\\S{6})\\*(?:\\S{2})"); 58 | static boost::regex pflaaRe( 59 | "\\$PFLAA,0,([-]?\\d+?),([-]?\\d+?),([-]?\\d+?),(\\d+?),(\\S{6}),(\\d{3})?,,(\\d+?)?,([-]?\\d+?\\.\\d+?)?,([0-9A-F]{1,2})\\*(?:\\S{2})"); 60 | static boost::regex gpsRe( 61 | "(\\$GPRMC,\\d{6},A,0000\\.00,N,00000\\.00,E,0,0,\\d{6},001\\.0,W\\*[0-9a-fA-F]{2}\\s*)?(\\$GPGGA,\\d{6},0000\\.0000,N,00000\\.0000,E,1,00,1,0,M,0\\.0,M,,\\*[0-9a-fA-F]{2}\\s*)?"); 62 | 63 | static std::string timePlus(std::int32_t val) 64 | { 65 | return boost::posix_time::to_iso_string( 66 | boost::posix_time::time_duration( 67 | boost::posix_time::second_clock::local_time().time_of_day()) + 68 | boost::posix_time::seconds(val)); 69 | } 70 | } // namespace helper 71 | -------------------------------------------------------------------------------- /test/resources/invalid.ini: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jarthianur/VirtualFlightRadar-Backend/7c8db16b1e4d9117c3810448f77a41661885266c/test/resources/invalid.ini -------------------------------------------------------------------------------- /test/resources/regression.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -eE 3 | 4 | REGR_PORT_SBS=44400 5 | REGR_PORT_APRS=44401 6 | REGR_PORT_GPS=44402 7 | REGR_PORT_SENS=44403 8 | REGR_PORT_VFRB=44404 9 | 10 | function cleanup() { 11 | kill -9 $(cat sbs_srv.pid) $(cat aprs_srv.pid) $(cat gps_srv.pid) $(cat sens_srv.pid) 12 | rm sens_srv.pid aprs_srv.pid sbs_srv.pid gps_srv.pid 13 | } 14 | 15 | case "$1" in 16 | "serve") 17 | lua server.lua $REGR_PORT_SBS sbs >/dev/null & 18 | echo -en $! >sbs_srv.pid 19 | lua server.lua -r $REGR_PORT_APRS aprs >aprs.log & 20 | echo -en $! >aprs_srv.pid 21 | lua server.lua -r $REGR_PORT_GPS gps >gps.log & 22 | echo -en $! >gps_srv.pid 23 | lua server.lua $REGR_PORT_SENS sens >/dev/null & 24 | echo -en $! >sens_srv.pid 25 | ;; 26 | "receive") 27 | nc localhost $REGR_PORT_VFRB >recv.log & 28 | ;; 29 | "check") 30 | trap cleanup ERR 31 | LOG=$(cat aprs.log | grep -o "regression") 32 | if [ "$LOG" == "" ]; then 33 | echo "APRS login regression failed" 34 | $(exit 1) 35 | fi 36 | LOG=$(cat aprs.log | grep -o "#keep-alive beacon" | wc -l) 37 | if [ $LOG -lt 5 ]; then 38 | echo "APRS keep-alive beacon regression failed" 39 | $(exit 1) 40 | fi 41 | LOG=$(cat gps.log | grep -o "?WATCH={\"enable\":true,\"nmea\":true}") 42 | if [ "$LOG" == "" ]; then 43 | echo "VFRB - gps_watch_enable regression failed" 44 | $(exit 1) 45 | fi 46 | LOG=$(cat gps.log | grep -o "?WATCH={\"enable\":false}") 47 | if [ "$LOG" == "" ]; then 48 | echo "VFRB - gps_watch_disable regression failed" 49 | $(exit 1) 50 | fi 51 | LOG=$(cat recv.log | grep -o -P 'GPRMC,\d{6},A,5000.05,N' | head -n1) 52 | if [ "$LOG" == "" ]; then 53 | echo "VFRB - gprmc regression failed" 54 | $(exit 1) 55 | fi 56 | LOG=$(cat recv.log | grep -o -P 'GPGGA,\d{6},5000.0466,N' | head -n1) 57 | if [ "$LOG" == "" ]; then 58 | echo "VFRB - gpgga regression failed" 59 | $(exit 1) 60 | fi 61 | LOG=$(cat recv.log | grep -o 'PFLAU,,,,1,0,-180,0,-105' | head -n1) 62 | if [ "$LOG" == "" ]; then 63 | echo "VFRB - pflau regression failed" 64 | $(exit 1) 65 | fi 66 | LOG=$(cat recv.log | grep -o 'PFLAA,0,-11008362,-33512,-105' | head -n1) 67 | if [ "$LOG" == "" ]; then 68 | echo "VFRB - pflaa regression failed" 69 | $(exit 1) 70 | fi 71 | LOG=$(cat recv.log | grep -o 'WIMDA,29.7987,I,1.0091,B,14.8' | head -n1) 72 | if [ "$LOG" == "" ]; then 73 | echo "VFRB - wimda regression failed" 74 | $(exit 1) 75 | fi 76 | LOG=$(cat recv.log | grep -o 'WIMWV,242.8,R,6.9,N,A' | head -n1) 77 | if [ "$LOG" == "" ]; then 78 | echo "VFRB - wimwv regression failed" 79 | $(exit 1) 80 | fi 81 | cleanup 82 | ;; 83 | *) 84 | echo "Run this script with 'serve' to start regression servers." 85 | echo "Run this script with 'receive' to connect to regression servers from 'serve' call." 86 | ;; 87 | esac 88 | exit 0 89 | -------------------------------------------------------------------------------- /test/resources/test.ini: -------------------------------------------------------------------------------- 1 | [general] 2 | feeds=sbs,aprs,gps,atm,wind 3 | serverPort=44404 4 | gndMode=y 5 | [fallback] 6 | latitude= 7 | longitude= 8 | altitude= 9 | geoid= 10 | pressure= 11 | [filter] 12 | maxHeight= 13 | maxDist= 14 | [sbs] 15 | host=localhost 16 | port=44400 17 | [aprs] 18 | host=localhost 19 | port=44401 20 | login=regression 21 | [gps] 22 | host=localhost 23 | port=44402 24 | [wind] 25 | host=localhost 26 | port=44403 27 | [atm] 28 | host=localhost 29 | port=44403 30 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 3.0.2 2 | -------------------------------------------------------------------------------- /vfrb.ini.in: -------------------------------------------------------------------------------- 1 | ; 2 | ; VirtualFlightRadar-Backend 3 | ; Version %VERSION% 4 | ; 5 | 6 | [general] 7 | ; Input feeds 8 | ; Comma-separated list 9 | ; Keywords: aprs, sbs, gps, atm, wind 10 | ; Example: aprsc1,aprsc2,sbs,gps,atm1,wind2 11 | feeds = 12 | ; Serve NMEA output on this port 13 | serverPort = 14 | ; Assign anything to enable 15 | gndMode = 16 | 17 | [fallback] 18 | ; format (degree): x.xxxxxx 19 | ; [-90,90] 20 | latitude = 21 | ; [-180,180] 22 | longitude = 23 | ; GPS height including antenna height 24 | ; meters 25 | ; format: x 26 | altitude = 27 | ; Geoid separation 28 | ; format: x.x 29 | geoid = 30 | ; hPa 31 | ; format: x.x 32 | pressure = 33 | 34 | [filter] 35 | ; meters 36 | ; -1, or empty to disable 37 | ; format: x 38 | maxHeight = 39 | maxDist = 40 | 41 | ; Each entry in 'general.feeds' needs its own section. 42 | ; Only 'aprs' needs the 'login'. 43 | ; Priorities are relative to each other and matter only for feeds of same type (keyword). 44 | ;[name] 45 | ;host = 46 | ;port = 47 | ;(login =)? 48 | ;priority = 49 | 50 | ;Example: 51 | ;[aprsc1] 52 | ;host = localhost 53 | ;port = 14580 54 | ;login = user x pass y filter r/1/2/3 55 | ;priority = 1 56 | -------------------------------------------------------------------------------- /vfrb.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=VirtualFlightRadar-Backend 3 | 4 | [Service] 5 | Type=simple 6 | ExecStart=%VFRB_EXEC_PATH% -c %VFRB_INI_PATH% 7 | 8 | [Install] 9 | WantedBy=multi-user.target 10 | --------------------------------------------------------------------------------