Porównaj commity

...

5 Commity

Autor SHA1 Wiadomość Data
Michal Fratczak 4996583a5c update readme 2022-10-09 13:50:53 +02:00
Michal Fratczak cfceb8e07e playback IQ files 2022-10-09 13:47:02 +02:00
Michal Fratczak c7cfb2af91 using json lib 2022-10-09 12:56:15 +02:00
Michal Fratczak cf762bc598 transport datasize = float by default 2022-10-09 11:40:58 +02:00
Michal Fratczak 67f9ce193b websocket: sending "cmd::info:tracking_telemetry" 2022-10-08 21:34:34 +02:00
8 zmienionych plików z 24726 dodań i 212 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
![alt text](./webClientScreenshot.png)
Habdec is a C++11 software to decode RTTY telemetry from High Altitude Balloon and upload it to [UKHAS Habitat](http://habitat.habhub.org/)
Habdec is a C++17 software to decode RTTY telemetry from High Altitude Balloons and upload it to [UKHAS Habitat](http://habitat.habhub.org/) and [sondehub.org](https://amateur.sondehub.org)
Some facts:
- builds and runs on Windows/Linux and x64/RaspberryPI/OdroixXU4 platforms
@ -35,7 +35,7 @@ To get habdec you can download precompiled exec or build it from source.
There's also raspberryPi 3 image with ready to use binary and build env. Go to [Wiki](https://github.com/ogre/habdec/wiki)
#### Building from source:
To build habdec you need a C++11 compiler and CMake version 3.8.2
To build habdec you need a C++17 compiler and CMake version 3.8.2
You also need to build or install some dependencies:
- basic decoder: [FFTW](http://www.fftw.org/)
- websocket server: [SoapySDR](https://github.com/pothosware/SoapySDR), [boost 1.68](https://www.boost.org/) (any version with boost-beast)
@ -75,6 +75,7 @@ CLI opts:
--sentence_cmd arg Call external command with sentence as parameter
--flights [=arg(=0)] List Habitat flights
--payload arg Configure for Payload ID
--sondehub arg (=https://api.v2.sondehub.org) sondehub API url
```
### Examples:

24596
code/common/json.hpp 100644

Plik diff jest za duży Load Diff

Wyświetl plik

@ -129,6 +129,7 @@ std::string HabitatUploadSentence(
string sentence_json = SentenceToHabJson(sentence_b64, i_listener_callsign);
string result;
// return result;
int retries_left = 5;
while( retries_left-- )

Wyświetl plik

@ -4,6 +4,7 @@
#include <boost/algorithm/string.hpp>
#include "common/utc_now_iso.h"
#include "common/git_repo_sha1.h"
#include "common/json.hpp"
#include <cpr/cpr.h>
namespace sondehub
@ -44,25 +45,29 @@ void SondeHubUploader::upload()
using namespace std;
const string utc_now_str = utc_now_iso();
string payload{"["};
stringstream s;
s<<"[";
for(auto& t : processing_queue_) {
string tele_json = JSON_TEMPLATE;
using json = nlohmann::json;
json tele_json;
boost::replace_all(tele_json, "$uploader_callsign", uploader_callsign_);
boost::replace_all(tele_json, "$software_version", string(g_GIT_SHA1).substr(0,7));
boost::replace_all(tele_json, "$time_received", t.time_received);
boost::replace_all(tele_json, "$upload_time", utc_now_str);
boost::replace_all(tele_json, "$payload_callsign", t.payload_callsign);
boost::replace_all(tele_json, "$datetime", t.datetime);
boost::replace_all(tele_json, "$frame", to_string(t.frame));
boost::replace_all(tele_json, "$lat", to_string(t.lat));
boost::replace_all(tele_json, "$lon", to_string(t.lon));
boost::replace_all(tele_json, "$alt", to_string(static_cast<int>(t.alt)));
tele_json["uploader_callsign"] = uploader_callsign_;
tele_json["software_version"] = string(g_GIT_SHA1).substr(0,7);
tele_json["time_received"] = t.time_received;
tele_json["upload_time"] = utc_now_str;
tele_json["payload_callsign"] = t.payload_callsign;
tele_json["datetime"] = t.datetime;
tele_json["frame"] = t.frame;
tele_json["lat"] = t.lat;
tele_json["lon"] = t.lon;
tele_json["alt"] = static_cast<int>(t.alt);
s<<tele_json<<",";
payload += tele_json + string{','};
}
string payload{s.str()};
payload.at(payload.size()-1) = ']';
// cout<<payload<<endl;

Wyświetl plik

@ -30,23 +30,6 @@ private:
std::string api_endpoint_;
std::string uploader_callsign_;
inline static const std::string JSON_TEMPLATE =
R"({
"dev": "true",
"software_name": "habdec",
"software_version": "$software_version",
"uploader_callsign": "$uploader_callsign",
"time_received": "$time_received",
"upload_time": "$upload_time",
"payload_callsign": "$payload_callsign",
"datetime": "$datetime",
"frame": $frame,
"lat": $lat,
"lon": $lon,
"alt": $alt
})";
public:
SondeHubUploader(const std::string& api_endpoint, const std::string& uploader_callsign) : api_endpoint_(api_endpoint), uploader_callsign_(uploader_callsign) {};
void push(const MinTelemetry&);

Wyświetl plik

@ -106,8 +106,9 @@ public:
std::string ssdv_dir_ = ".";
std::string test_parse_sentence_ = "";
std::string sondehub_ = "https://api.v2.sondehub.org/";
// int datasize_ = 1;
TransportDataType transport_data_type_ = TransportDataType::kChar;
std::string iqfile_ = "";
float iqfile_sampling_rate_ = 0;
TransportDataType transport_data_type_ = TransportDataType::kFloat;
bool operator==(const PARAMS& rhs) const

Wyświetl plik

@ -35,6 +35,7 @@
#include <SoapySDR/Version.hpp>
#include "IQSource/IQSource_File.h"
#include "IQSource/IQSource_SoapySDR.h"
#include "Decoder/Decoder.h"
#include "common/console_colors.h"
@ -47,6 +48,7 @@
#include "common/http_request.h"
#include "common/date.h"
#include "common/utc_now_iso.h"
#include "common/json.hpp"
#include "Decoder/CRC.h"
#include "sondehub/sondehub_uploader.h"
#include <cpr/cpr.h>
@ -68,33 +70,6 @@ std::vector<std::string> split_str(const std::string& text, char sep)
}
void SentenceToPosition(const std::string i_snt,
float &lat, float &lon, float &alt,
const std::string coord_format_lat, const std::string coord_format_lon
)
{
// "CALLSIGN,123,15:41:24,44.32800,-74.14427,00491,0,0,12,30.7,0.0,0.001,20.2,958*6BC9"
std::vector<std::string> tokens = split_str(i_snt, ',');
lat = std::stof(tokens[3]);
lon = std::stof(tokens[4]);
alt = std::stof(tokens[5]);
if(coord_format_lat == "ddmm.mmmm")
{
const float degs = trunc(lat / 100);
const float mins = lat - 100.0f * degs;
lat = degs + mins / 60.0f;
}
if(coord_format_lon == "ddmm.mmmm")
{
const float degs = trunc(lon / 100);
const float mins = lon - 100.0f * degs;
lon = degs + mins / 60.0f;
}
}
void PrintDevicesList(const SoapySDR::KwargsList& device_list)
{
int DEV_NUM = 0;
@ -317,7 +292,6 @@ void SentenceCallback( std::string callsign, std::string data, std::string crc,
using namespace std;
const string sentence_no_crc = callsign + "," + data;
cout<<"SentenceCallback "<<sentence_no_crc<<endl;
auto maybe_telemetry = habdec::parse_sentence(sentence_no_crc);
sondehub::MinTelemetry t;
@ -325,13 +299,12 @@ void SentenceCallback( std::string callsign, std::string data, std::string crc,
t = maybe_telemetry.value();
}
else {
cout<<"Failed parsing "<<sentence_no_crc<<endl;
cout<<"Failed parsing sentence "<<sentence_no_crc<<endl;
return;
}
t.time_received = utc_now_iso();
// sondehub upload
// cout<<"push"<<endl;
p_sondehub_uploader->push(t);
using Ms = std::chrono::milliseconds;
@ -344,10 +317,23 @@ void SentenceCallback( std::string callsign, std::string data, std::string crc,
// notify all websocket clients
if(p_ws)
{
// sentence
auto p_sentence_msg = std::make_shared<HabdecMessage>();
p_sentence_msg->to_all_clients_ = true;
p_sentence_msg->data_stream_<<"cmd::info:sentence="<<sentence;
p_ws->sessions_send(p_sentence_msg);
// tracking telemetry
stringstream s;
auto p_tele_msg = std::make_shared<HabdecMessage>();
p_tele_msg->to_all_clients_ = true;
p_tele_msg->data_stream_ << "cmd::info:tracking_telemetry=";
p_tele_msg->data_stream_ << t.payload_callsign << ","
<< t.datetime << ","
<< t.lat << ","
<< t.lon << ","
<< t.alt;
p_ws->sessions_send(p_tele_msg);
}
@ -411,71 +397,6 @@ void SentenceCallback( std::string callsign, std::string data, std::string crc,
}
}
void test_sentence_parsing_and_upload(std::string test_sentence, std::string api_endpoint)
{
using namespace std;
using namespace boost;
sondehub::MinTelemetry t;
try {
auto maybe_telemetry = habdec::parse_sentence(test_sentence);
if(!maybe_telemetry) {
cout<<"Failed parsing sentence to minimal telemetry"<<endl;
return;
}
else {
t = maybe_telemetry.value();
}
} catch(std::exception const& e) {
cout<<"Failed parsing sentence to minimal telemetry: "<<e.what()<<endl;
return;
}
//upload to sondehub
//
string tele_json =
R"([{
"software_name": "habdec",
"software_version": "4ec86fbad93fb30e073f29be0eef53b437c2c64b",
"uploader_callsign": "$uploader_callsign",
"time_received": "$time_received",
"upload_time": "$upload_time",
"payload_callsign": "$payload_callsign",
"datetime": "$datetime",
"lat": $lat,
"lon": $lon,
"alt": $alt
}])";
string utc_now_str = utc_now_iso();
boost::replace_all(tele_json, "$uploader_callsign", "SP7HAB");
boost::replace_all(tele_json, "$time_received", utc_now_str);
boost::replace_all(tele_json, "$upload_time", utc_now_str);
boost::replace_all(tele_json, "$payload_callsign", t.payload_callsign);
boost::replace_all(tele_json, "$datetime", t.datetime);
boost::replace_all(tele_json, "$lat", to_string(t.lat));
boost::replace_all(tele_json, "$lon", to_string(t.lon));
boost::replace_all(tele_json, "$alt", to_string(static_cast<int>(t.alt)));
cout<<tele_json<<endl;
return;
cout<<endl<<api_endpoint<<endl;
cpr::Response r = cpr::Put(
cpr::Url{api_endpoint},
cpr::Body{tele_json},
cpr::Header{
{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0"},
{"Content-Type", "application/json"}
}
);
cout<<r.status_code<<endl; // 200
cout<<r.header["content-type"]<<endl; // application/json; charset=utf-8
cout<<r.text<<endl;
}
void Test_SentenceGenerator(
std::shared_ptr<WebsocketServer> p_ws_server,
@ -497,7 +418,6 @@ void Test_SentenceGenerator(
auto sys_HMS = make_time(sys_now - floor<days>(sys_now) );
stringstream ss;
// ss << "SP7HAB-test,";
ss << sentence_id;
ss << "," << sys_HMS;
if(sentence_id%2)
@ -508,9 +428,12 @@ void Test_SentenceGenerator(
ss << ",-25.3";
string data{ ss.str() };
// cout<<data<<endl;
SentenceCallback( "SP7HAB-test", data, habdec::CRC(string("SP7HAB-test") + string(",") + data),
string callsign = GLOBALS::get().par_.station_callsign_ + "-test";
cout<<callsign<<","<<data<<endl;
SentenceCallback( callsign, data, habdec::CRC(callsign + string(",") + data),
p_ws_server,
p_sondehub_uploader );
}
@ -549,47 +472,48 @@ int main(int argc, char** argv)
auto& G = GLOBALS::get();
if( G.par_.test_parse_sentence_ != "" ) {
test_sentence_parsing_and_upload(
G.par_.test_parse_sentence_,
G.par_.sondehub_ + string("/amateur/telemetry") );
return 0;
}
// setup SoapySDR device
// setup SoapySDR device or iqfile
SoapySDR::Kwargs device;
while(true)
if(G.par_.iqfile_ != "")
{
bool ok = false;
try {
ok = SetupDevice(device);
} catch(std::runtime_error& er) {
cout<<C_RED<<"Failed opening device: "
<<C_MAGENTA<<er.what()<<C_OFF<<endl;
}
if( ok )
{
break;
}
else
{
if( G.par_.no_exit_ )
{
cout<<C_RED<<"Failed Device Setup. Retry."<<C_OFF<<endl;
std::this_thread::sleep_for( ( std::chrono::duration<double, std::milli>(3000) ));
continue;
G.p_iq_source_.reset( new habdec::IQSource_File<float> );
G.p_iq_source_->setOption("file_string", &G.par_.iqfile_);
double sr = G.par_.iqfile_sampling_rate_;
G.p_iq_source_->setOption("sampling_rate_double", &sr);
bool iq_loop = true;
G.p_iq_source_->setOption("loop_bool", &iq_loop);
G.p_iq_source_->init();
cout<<"Reading IQ samples from "<<G.par_.iqfile_<<" at "<<sr<<endl;
G.p_iq_source_->start();
}
else
{
while(true) {
bool ok = false;
try {
ok = SetupDevice(device);
} catch(std::runtime_error& er) {
cout<<C_RED<<"Failed opening device: "
<<C_MAGENTA<<er.what()<<C_OFF<<endl;
}
else
{
cout<<C_RED<<"Failed Device Setup. EXIT."<<C_OFF<<endl;
return 1;
if( ok ) {
break;
}
else {
if( G.par_.no_exit_ ) {
cout<<C_RED<<"Failed Device Setup. Retry."<<C_OFF<<endl;
std::this_thread::sleep_for( ( std::chrono::duration<double, std::milli>(3000) ));
continue;
}
else {
cout<<C_RED<<"Failed Device Setup. EXIT."<<C_OFF<<endl;
return 1;
}
}
}
}
// station info
if( G.par_.station_callsign_ != "" )
{
@ -599,50 +523,45 @@ int main(int argc, char** argv)
if( G.par_.station_lat_
&& G.par_.station_lon_ ) {
// habitat
cout<<"Uploading station info to HabHub."<<endl;
habdec::habitat::UploadStationTelemetry(
G.par_.station_callsign_,
G.par_.station_lat_, G.par_.station_lon_,
G.par_.station_alt_, 0, false
);
// habitat
cout<<"Uploading station info to HabHub."<<endl;
habdec::habitat::UploadStationTelemetry(
G.par_.station_callsign_,
G.par_.station_lat_, G.par_.station_lon_,
G.par_.station_alt_, 0, false
);
// sondehub
string sondehub_station_json = R"(
{
"uploader_callsign": "$uploader_callsign",
"uploader_position": [$lat,$lon,$alt],
"software_name": "habdec",
"software_version": "$software_version",
"uploader_radio": "$uploader_radio",
"mobile": false
}
)";
boost::replace_all(sondehub_station_json, "$uploader_callsign", G.par_.station_callsign_);
boost::replace_all(sondehub_station_json, "$lat", to_string(G.par_.station_lat_));
boost::replace_all(sondehub_station_json, "$lon", to_string(G.par_.station_lon_));
boost::replace_all(sondehub_station_json, "$alt", to_string(G.par_.station_alt_));
boost::replace_all(sondehub_station_json, "$software_version", string(g_GIT_SHA1).substr(0,7));
boost::replace_all(sondehub_station_json, "$uploader_radio", device["driver"]);
// sondehub
using json = nlohmann::json;
json sh_json;
sh_json["software_name"] = "habdec";
sh_json["software_version"] = string(g_GIT_SHA1).substr(0,7);
sh_json["uploader_callsign"] = G.par_.station_callsign_;
sh_json["uploader_position"] = vector<float>{
G.par_.station_lat_, G.par_.station_lon_, G.par_.station_alt_};
sh_json["uploader_radio"] = device["driver"];
sh_json["mobile"] = false;
cout<<"Uploading station info to SondeHub."<<endl;
cout<<sondehub_station_json<<endl;
cout<<"Uploading station info to SondeHub."<<endl;
// cout<<sh_json<<endl;
stringstream s;
s<<sh_json;
cpr::Response r = cpr::Put(
cpr::Url{G.par_.sondehub_ + "/amateur/listeners"},
cpr::Body{sondehub_station_json},
cpr::Header{
{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0"},
{"Content-Type", "application/json"}
}
);
cpr::Response r = cpr::Put(
cpr::Url{G.par_.sondehub_ + "/amateur/listeners"},
cpr::Body{s.str()},
cpr::Header{
{"User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0"},
{"Content-Type", "application/json"}
}
);
if(r.status_code != 200) {
cout<<"sondehub station info upload error:\n";
cout<<r.status_code<<endl; // 200
cout<<r.header["content-type"]<<endl; // application/json; charset=utf-8
cout<<r.text<<endl;
}
if(r.status_code != 200) {
cout<<"sondehub station info upload error:\n";
cout<<r.status_code<<endl; // 200
cout<<r.header["content-type"]<<endl; // application/json; charset=utf-8
cout<<r.text<<endl;
}
}
}
@ -731,7 +650,7 @@ int main(int argc, char** argv)
// sondehub uploader
if(G.par_.station_callsign_ != "" && G.par_.sondehub_ != "") {
cout<<"Uploading to sondehub "<<G.par_.sondehub_<<endl;
cout<<"Uploading telemetry to sondehub "<<G.par_.sondehub_<<endl;
threads.emplace( new thread(
[p_sondehub_uploader]() {
while(1) {

Wyświetl plik

@ -111,8 +111,8 @@ void prog_opts(int ac, char* av[])
("ssdv_dir", po::value<string>()->default_value(GLOBALS::get().par_.ssdv_dir_), "SSDV directory.")
("test_parse", po::value<string>(), "arg: full habhub sentence without CRC. test parsing")
("sondehub", po::value<string>()->default_value("https://api.v2.sondehub.org"), "sondehub API url")
("iqfile", po::value< std::vector<string> >()->multitoken(), "iqfile and it's sampling_rate")
;
@ -297,14 +297,22 @@ void prog_opts(int ac, char* av[])
{
GLOBALS::get().par_.ssdv_dir_ = vm["ssdv_dir"].as<string>();
}
if (vm.count("test_parse"))
{
GLOBALS::get().par_.test_parse_sentence_ = vm["test_parse"].as<string>();
}
if (vm.count("sondehub"))
{
GLOBALS::get().par_.sondehub_ = vm["sondehub"].as<string>();
}
if (vm.count("iqfile"))
{
vector<string> file_and_sr = vm["iqfile"].as< vector<string> >();
if( file_and_sr.size() != 2 )
{
cout<<C_RED<<"--iqfile option needs 2 args"<<C_OFF<<endl;
exit(1);
}
GLOBALS::get().par_.iqfile_ = file_and_sr[0];
GLOBALS::get().par_.iqfile_sampling_rate_ = stof(file_and_sr[1]);
}
}
catch(exception& e)
{