kopia lustrzana https://github.com/ogre/habdec
websocketServer: added --latlon opt, uploading station telemetry to HAB.
rodzic
4af393fc27
commit
1da92d0d91
|
@ -5,6 +5,8 @@
|
|||
|
||||
namespace habdec
|
||||
{
|
||||
namespace habitat
|
||||
{
|
||||
|
||||
std::string HabitatUploadSentence(
|
||||
const std::string& i_sentence,
|
||||
|
@ -40,7 +42,22 @@ struct HabitatFlight
|
|||
std::ostream&
|
||||
operator<<(std::ostream& os, const HabitatFlight& f);
|
||||
|
||||
std::map<std::string, habdec::HabitatFlight>
|
||||
|
||||
std::map<std::string, HabitatFlight>
|
||||
ListFlights(int hour_offset);
|
||||
|
||||
|
||||
int UploadStationInfo(
|
||||
const std::string& i_callsign,
|
||||
const std::string& i_radio
|
||||
);
|
||||
|
||||
int UploadStationTelemetry(
|
||||
const std::string& i_callsign,
|
||||
const float i_lat, const float i_lon,
|
||||
const float i_alt, const float i_speed,
|
||||
bool i_chase
|
||||
);
|
||||
|
||||
} // namespace habitat
|
||||
} // namespace habdec
|
||||
|
|
|
@ -30,16 +30,17 @@ std::string FlightsListUrl(int hour_offset = 0)
|
|||
|
||||
|
||||
|
||||
std::map<std::string, habdec::HabitatFlight> ParseFlightsJson(const std::string& i_json_str)
|
||||
std::map<std::string, habdec::habitat::HabitatFlight> ParseFlightsJson(const std::string& i_json_str)
|
||||
{
|
||||
using namespace std;
|
||||
namespace pt = boost::property_tree;
|
||||
using namespace habdec::habitat;
|
||||
|
||||
pt::ptree root;
|
||||
stringstream ss; ss << i_json_str;
|
||||
pt::read_json(ss, root);
|
||||
|
||||
std::map<string, habdec::HabitatFlight> flights_map;
|
||||
std::map<string, HabitatFlight> flights_map;
|
||||
|
||||
// flights
|
||||
//
|
||||
|
@ -52,7 +53,7 @@ std::map<std::string, habdec::HabitatFlight> ParseFlightsJson(const std::string&
|
|||
/*if( !doc.get<bool>("approved") )
|
||||
continue;*/
|
||||
|
||||
habdec::HabitatFlight _f;
|
||||
HabitatFlight _f;
|
||||
|
||||
_f.name_ = doc.get<string>("name");
|
||||
_f.id_ = doc.get<string>("_id");
|
||||
|
@ -71,7 +72,7 @@ std::map<std::string, habdec::HabitatFlight> ParseFlightsJson(const std::string&
|
|||
if( doc.get<string>("type") != "payload_configuration" )
|
||||
continue;
|
||||
|
||||
habdec::HabitatPayload _p;
|
||||
HabitatPayload _p;
|
||||
|
||||
_p.flight_id_ = row.second.get<string>("id");
|
||||
_p.name_ = doc.get<string>("name");
|
||||
|
@ -110,8 +111,10 @@ std::map<std::string, habdec::HabitatFlight> ParseFlightsJson(const std::string&
|
|||
|
||||
namespace habdec
|
||||
{
|
||||
namespace habitat
|
||||
{
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const habdec::HabitatPayload& p)
|
||||
std::ostream& operator<<(std::ostream& os, const habdec::habitat::HabitatPayload& p)
|
||||
{
|
||||
os << "Payload: " << p.name_ << " "
|
||||
<< C_RED << p.id_ << C_OFF << "\n"
|
||||
|
@ -126,7 +129,7 @@ std::ostream& operator<<(std::ostream& os, const habdec::HabitatPayload& p)
|
|||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const habdec::HabitatFlight& f)
|
||||
std::ostream& operator<<(std::ostream& os, const habdec::habitat::HabitatFlight& f)
|
||||
{
|
||||
os << "Flight: " << f.name_ << " " << f.id_ << "\n"
|
||||
<< "\tlat/lon: " << f.lat_ << " " << f.lon_ << "\n";
|
||||
|
@ -136,16 +139,17 @@ std::ostream& operator<<(std::ostream& os, const habdec::HabitatFlight& f)
|
|||
}
|
||||
|
||||
|
||||
std::map<std::string, habdec::HabitatFlight> ListFlights(int hour_offset)
|
||||
std::map<std::string, habdec::habitat::HabitatFlight> ListFlights(int hour_offset)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace habdec::habitat;
|
||||
|
||||
string docs_json;
|
||||
int result = HttpRequest(
|
||||
"habitat.habhub.org", FlightsListUrl(hour_offset), 80,
|
||||
habdec::HTTP_VERB::kGet, "application/json", "", docs_json );
|
||||
|
||||
std::map<std::string, habdec::HabitatFlight> flights;
|
||||
std::map<std::string, HabitatFlight> flights;
|
||||
|
||||
if( result )
|
||||
flights = ParseFlightsJson( docs_json );
|
||||
|
@ -154,4 +158,5 @@ std::map<std::string, habdec::HabitatFlight> ListFlights(int hour_offset)
|
|||
return flights;
|
||||
}
|
||||
|
||||
} // namespace habitat
|
||||
} // namespace habdec
|
|
@ -106,6 +106,8 @@ std::string SentenceToHabJson(
|
|||
|
||||
namespace habdec
|
||||
{
|
||||
namespace habitat
|
||||
{
|
||||
|
||||
std::string HabitatUploadSentence(
|
||||
const std::string& i_sentence,
|
||||
|
@ -157,4 +159,101 @@ std::string HabitatUploadSentence(
|
|||
return result;
|
||||
}
|
||||
|
||||
} // namespace habdec
|
||||
|
||||
int UploadStationInfo(
|
||||
const std::string& i_callsign,
|
||||
const std::string& i_radio
|
||||
)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace boost::posix_time;
|
||||
using namespace habdec;
|
||||
|
||||
ptime now = second_clock::universal_time();
|
||||
string utc_now_str = to_iso_extended_string(now) + "Z"; // habitat needs Z at the end
|
||||
|
||||
const string info_template = R"_(
|
||||
{
|
||||
"type": "listener_information",
|
||||
"data": {"callsign": "$callsign", "radio": "$radio" },
|
||||
"time_created": "$time",
|
||||
"time_uploaded": "$time"
|
||||
}
|
||||
)_";
|
||||
|
||||
string info_data_str = info_template;
|
||||
info_data_str.replace( info_data_str.find("$callsign"), 9, i_callsign );
|
||||
info_data_str.replace( info_data_str.find("$time"), 5, utc_now_str );
|
||||
info_data_str.replace( info_data_str.find("$time"), 5, utc_now_str );
|
||||
info_data_str.replace( info_data_str.find("$radio"), 6, "habdec" );
|
||||
|
||||
string http_req_result;
|
||||
int res = HttpRequest(
|
||||
"habitat.habhub.org",
|
||||
"/habitat",
|
||||
80,
|
||||
habdec::HTTP_VERB::kPost,
|
||||
"application/json",
|
||||
info_data_str,
|
||||
http_req_result
|
||||
);
|
||||
return res;
|
||||
}
|
||||
|
||||
int UploadStationTelemetry(
|
||||
const std::string& i_callsign,
|
||||
const float i_lat, const float i_lon,
|
||||
const float i_alt, const float i_speed,
|
||||
bool i_chase
|
||||
)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace boost::posix_time;
|
||||
using namespace habdec;
|
||||
|
||||
ptime now = second_clock::universal_time();
|
||||
string utc_now_str = to_iso_extended_string(now) + "Z"; // habitat needs Z at the end
|
||||
|
||||
const string telemetry_template = R"_(
|
||||
{
|
||||
"type": "listener_telemetry",
|
||||
"time_created": "$time",
|
||||
"time_uploaded": "$time",
|
||||
"data": {
|
||||
"callsign": "$callsign",
|
||||
"latitude": $lat,
|
||||
"longitude": $lon,
|
||||
"altitude": $alt,
|
||||
"speed": $speed,
|
||||
"chase": $chase
|
||||
}
|
||||
}
|
||||
)_";
|
||||
|
||||
string telemetry_data_str = telemetry_template;
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$callsign"), 9, i_callsign );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$time"), 5, utc_now_str );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$time"), 5, utc_now_str );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$lat"), 4, to_string(i_lat) );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$lon"), 4, to_string(i_lon) );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$alt"), 4, to_string(i_alt) );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$speed"), 6, to_string(i_speed) );
|
||||
telemetry_data_str.replace( telemetry_data_str.find("$chase"), 6, i_chase ? "true" : "false" );
|
||||
|
||||
string http_req_result;
|
||||
int res = HttpRequest(
|
||||
"habitat.habhub.org",
|
||||
"/habitat",
|
||||
80,
|
||||
habdec::HTTP_VERB::kPost,
|
||||
"application/json",
|
||||
telemetry_data_str,
|
||||
http_req_result
|
||||
);
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
} // namespace habitat
|
||||
} // namespace habdec
|
|
@ -73,6 +73,8 @@ public:
|
|||
std::string command_host_ = "0.0.0.0";
|
||||
int command_port_ = 5555;
|
||||
std::string station_callsign_ = ""; // habitat upload
|
||||
float station_lat_ = 0;
|
||||
float station_lon_ = 0;
|
||||
double sampling_rate_ = 0;
|
||||
double frequency_ = 434349500.0f;
|
||||
double gain_ = 15;
|
||||
|
@ -95,6 +97,8 @@ public:
|
|||
oFile<<"sampling_rate = "<<GLOBALS::get().sampling_rate_<<endl;
|
||||
oFile<<"port = "<<GLOBALS::get().command_host_<<":"<<GLOBALS::get().command_port_<<endl;
|
||||
oFile<<"station = "<<GLOBALS::get().station_callsign_<<endl;
|
||||
oFile<<"latlon = "<<GLOBALS::get().station_lat_<<endl;
|
||||
oFile<<"latlon = "<<GLOBALS::get().station_lon_<<endl;
|
||||
|
||||
oFile<<"freq = "<<setprecision(9)<<GLOBALS::get().frequency_/1e6<<endl;
|
||||
oFile<<"gain = "<<GLOBALS::get().gain_<<endl;
|
||||
|
@ -125,6 +129,7 @@ public:
|
|||
cout<<"\tsentence_cmd: "<<GLOBALS::get().sentence_cmd_<<endl;
|
||||
cout<<"\tpayload: "<<GLOBALS::get().habitat_payload_<<endl;
|
||||
cout<<"\tstation: "<<GLOBALS::get().station_callsign_<<endl;
|
||||
cout<<"\tlatlon: "<<GLOBALS::get().station_lat_<<" "<<GLOBALS::get().station_lon_<<endl;
|
||||
cout<<"\tfreq: "<<GLOBALS::get().frequency_<<endl;
|
||||
cout<<"\tgain: "<<GLOBALS::get().gain_<<endl;
|
||||
cout<<"\tlive_print: "<<GLOBALS::get().live_print_<<endl;
|
||||
|
|
|
@ -66,7 +66,7 @@ void PrintDevicesList(const SoapySDR::KwargsList& device_list)
|
|||
}
|
||||
|
||||
|
||||
bool SetupDevice()
|
||||
bool SetupDevice(SoapySDR::Kwargs& o_device)
|
||||
{
|
||||
SoapySDR::KwargsList device_list = SoapySDR::Device::enumerate();
|
||||
|
||||
|
@ -138,6 +138,7 @@ bool SetupDevice()
|
|||
GLOBALS::get().p_iq_source_->setOption("biastee_double", &biastee);
|
||||
GLOBALS::get().p_iq_source_->setOption("sampling_rate_double", &GLOBALS::get().sampling_rate_);
|
||||
|
||||
o_device = device;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -234,7 +235,6 @@ void DECODER_FEED_THREAD()
|
|||
void LOG_THREAD()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace habdec;
|
||||
|
||||
while(!G_DO_EXIT)
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ void LOG_THREAD()
|
|||
{
|
||||
if(GLOBALS::get().station_callsign_ != "")
|
||||
{
|
||||
string res = HabitatUploadSentence( sentence, GLOBALS::get().station_callsign_ );
|
||||
string res = habdec::habitat::HabitatUploadSentence( sentence, GLOBALS::get().station_callsign_ );
|
||||
if( res != "OK" )
|
||||
cout<<C_CLEAR<<C_RED<<"HAB Upload result: "<<res<<endl;
|
||||
}
|
||||
|
@ -292,21 +292,27 @@ int main(int argc, char** argv)
|
|||
prog_opts(argc, argv);
|
||||
|
||||
// setup SoapySDR device
|
||||
if(!SetupDevice())
|
||||
SoapySDR::Kwargs device;
|
||||
if(!SetupDevice(device))
|
||||
{
|
||||
cout<<C_RED<<"Failed Device Setup. EXIT."<<C_OFF<<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// initial options from payload id
|
||||
//
|
||||
/*
|
||||
if( GLOBALS::get().habitat_payload_ != "" )
|
||||
// station info
|
||||
if( GLOBALS::get().station_callsign_ != "" )
|
||||
{
|
||||
if( !SetPayloadParameters(GLOBALS::get().habitat_payload_) )
|
||||
cout<<C_RED<<"\nFailed setting options for payload "<<GLOBALS::get().habitat_payload_<<C_OFF<<endl;
|
||||
habdec::habitat::UploadStationInfo( GLOBALS::get().station_callsign_,
|
||||
device["driver"] + " - habdec" );
|
||||
|
||||
if( GLOBALS::get().station_lat_
|
||||
&& GLOBALS::get().station_lon_ )
|
||||
habdec::habitat::UploadStationTelemetry(
|
||||
GLOBALS::get().station_callsign_,
|
||||
GLOBALS::get().station_lat_, GLOBALS::get().station_lon_,
|
||||
0, 0, false
|
||||
);
|
||||
}
|
||||
*/
|
||||
|
||||
// initial options from globals
|
||||
//
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace
|
|||
int LoadPayloadParameters(std::string i_payload_id)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace habdec;
|
||||
using namespace habdec::habitat;
|
||||
|
||||
std::map<std::string, HabitatFlight> flights = ListFlights(0);
|
||||
|
||||
|
@ -81,7 +81,9 @@ void prog_opts(int ac, char* av[])
|
|||
("sampling_rate", po::value<double>()->default_value(0), "Sampling Rate, as supported by device")
|
||||
|
||||
("port", po::value<string>()->default_value("5555"), "Command Port, example: --port 127.0.0.1:5555")
|
||||
|
||||
("station", po::value<string>()->default_value(""), "HABHUB station callsign")
|
||||
("latlon", po::value< std::vector<float> >()->multitoken(), "station GPS location (decimal)")
|
||||
|
||||
("freq", po::value<float>(), "frequency in MHz")
|
||||
("gain", po::value<int>(), "gain")
|
||||
|
@ -223,7 +225,7 @@ void prog_opts(int ac, char* av[])
|
|||
}
|
||||
if (vm.count("flights"))
|
||||
{
|
||||
using namespace habdec;
|
||||
using namespace habdec::habitat;
|
||||
int hours_offset = vm["flights"].as<int>();
|
||||
cout<<"Habitat Flights: "<<endl;
|
||||
std::map<std::string, HabitatFlight> payloads = ListFlights(hours_offset);
|
||||
|
@ -231,6 +233,17 @@ void prog_opts(int ac, char* av[])
|
|||
cout<<flight.second<<endl;
|
||||
exit(0);
|
||||
}
|
||||
if (vm.count("latlon"))
|
||||
{
|
||||
vector<float> latlon_vec = vm["latlon"].as< vector<float> >();
|
||||
if( latlon_vec.size() != 2 )
|
||||
{
|
||||
cout<<C_RED<<"--latlon option needs 2 args"<<C_OFF<<endl;
|
||||
exit(1);
|
||||
}
|
||||
GLOBALS::get().station_lat_ = latlon_vec[0];
|
||||
GLOBALS::get().station_lon_ = latlon_vec[1];
|
||||
}
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue