/* Copyright 2018 Michal Fratczak This file is part of habdec. habdec is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. habdec is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with habdec. If not, see . */ #include #include #include #include #include #include "GLOBALS.h" #include "common/console_colors.h" #include "habitat/habitat_interface.h" namespace { int LoadPayloadParameters(std::string i_payload_id) { using namespace std; using namespace habdec::habitat; std::map flights = ListFlights(0); for(auto& flight : flights) { for(auto& payload : flight.second.payloads_) { if( !i_payload_id.compare(payload.second.id_) ) { GLOBALS::get().par_.baud_ = payload.second.baud_; GLOBALS::get().par_.rtty_ascii_bits_ = payload.second.ascii_bits_; GLOBALS::get().par_.rtty_ascii_stops_ = payload.second.ascii_stops_; GLOBALS::get().par_.frequency_ = payload.second.frequency_; GLOBALS::get().par_.coord_format_lat_ = payload.second.coord_format_lat_; GLOBALS::get().par_.coord_format_lon_ = payload.second.coord_format_lon_; cout<(), "SDR Device Number. -1 to list") ("sampling_rate", po::value()->default_value(GLOBALS::get().par_.sampling_rate_), "Sampling Rate, as supported by device") ("no_exit", po::value(), "Constantly retry on missing device instead of exit.") ("port", po::value(), "Command Port, example: --port 127.0.0.1:5555") ("station", po::value(), "HABHUB station callsign") ("latlon", po::value< std::vector >()->multitoken(), "station GPS location (decimal)") ("alt", po::value(), "station altitude in meters") ("freq", po::value(), "frequency in MHz") ("ppm", po::value(), "frequency correction in PPM") ("gain", po::value(), "gain") ("print", po::value(), "live print received chars, values: 0, 1") ("rtty", po::value< std::vector >()->multitoken(), "rtty: baud bits stops, example: --rtty 300 8 2") ("biast", po::value(), "biasT, values: 0, 1") ("bias_t", po::value(), "biasT, values: 0, 1") ("afc", po::value(), "Auto Frequency Correction, values: 0, 1") ("usb_pack", po::value(), "AirSpy USB bit packing") ("dc_remove", po::value(), "DC remove") ("dec", po::value(), "decimation: 2^dec, range: 0-8") ("lowpass", po::value(), "lowpass bandwidth in Hertz") ("lp_trans", po::value(), "lowpass transition width. (0-1)") ("sentence_cmd", po::value(), "Call external command with sentence as parameter") ("flights", po::value()->implicit_value(0), "List Habitat flights") ("payload", po::value(), "Configure for Payload ID") ("nmea", po::value(), "assume NMEA lat/lon format: ddmm.mmmm") ; po::options_description cli_options("Command Line Interface options"); cli_options.add(generic); string config_file; cli_options.add_options() ("config", po::value(&config_file), "Last run config file. Autosaved on every successful decode."); // ("config", po::value(&config_file)->default_value("./habdecWebsocketServer.opts"), "Last run config file. Autosaved on every successfull decode."); po::options_description file_options; file_options.add(generic); po::variables_map vm; store( po::command_line_parser(ac, av).options(cli_options).allow_unregistered().run(), vm ); notify(vm); if(vm.count("help")) { cout<(); } if (vm.count("sampling_rate")) { GLOBALS::get().par_.sampling_rate_ = vm["sampling_rate"].as(); } if (vm.count("port")) // [host:][port] { smatch match; regex_match( vm["port"].as(), match, std::regex(R"_(([\w\.]*)(\:?)(\d*))_") ); if(match.size() == 4) { if(match[2] == "" && match[3] == "") // special case when only port is given: --port 5555 { GLOBALS::get().par_.command_port_ = stoi(match[1]); } else { if(match[1] != "") GLOBALS::get().par_.command_host_ = match[1]; if(match[3] != "") GLOBALS::get().par_.command_port_ = stoi(match[3]); } } } if (vm.count("station")) { GLOBALS::get().par_.station_callsign_ = vm["station"].as(); } if (vm.count("payload")) { GLOBALS::get().par_.habitat_payload_ = vm["payload"].as(); if( !LoadPayloadParameters( GLOBALS::get().par_.habitat_payload_ ) ) cout<(); } if (vm.count("freq")) { GLOBALS::get().par_.frequency_ = vm["freq"].as() * 1e6; } if (vm.count("ppm")) { GLOBALS::get().par_.ppm_ = vm["ppm"].as(); } if (vm.count("gain")) { GLOBALS::get().par_.gain_ = vm["gain"].as(); } if (vm.count("print")) { GLOBALS::get().par_.live_print_ = vm["print"].as(); } if (vm.count("no_exit")) { GLOBALS::get().par_.no_exit_ = vm["no_exit"].as(); } if (vm.count("biast")) { GLOBALS::get().par_.biast_ = vm["biast"].as(); } if (vm.count("bias_t")) { GLOBALS::get().par_.biast_ = vm["bias_t"].as(); } if (vm.count("afc")) { GLOBALS::get().par_.afc_ = vm["afc"].as(); } if (vm.count("usb_pack")) { GLOBALS::get().par_.usb_pack_ = vm["usb_pack"].as(); } if (vm.count("dc_remove")) { GLOBALS::get().par_.dc_remove_ = vm["dc_remove"].as(); } if (vm.count("lowpass")) { GLOBALS::get().par_.lowpass_bw_Hz_ = vm["lowpass"].as(); } if (vm.count("lp_trans")) { GLOBALS::get().par_.lowpass_tr_ = vm["lp_trans"].as(); } if (vm.count("dec")) { GLOBALS::get().par_.decimation_ = std::max(0, vm["dec"].as()); } if (vm.count("rtty")) { vector rtty_tokens = vm["rtty"].as< vector >(); if( rtty_tokens.size() != 3 ) { cout<(); cout<<"Habitat Flights: "< payloads = ListFlights(hours_offset); for(auto& flight : payloads) cout<()) { GLOBALS::get().par_.coord_format_lat_ = "ddmm.mmmm"; GLOBALS::get().par_.coord_format_lon_ = "ddmm.mmmm"; } if (vm.count("latlon")) { vector latlon_vec = vm["latlon"].as< vector >(); if( latlon_vec.size() != 2 ) { cout<(); } } catch(exception& e) { cout << e.what() << "\n"; } GLOBALS::DumpToFile("./habdecWebsocketServer.opts"); }