kopia lustrzana https://github.com/ogre/habdec
websocketSrv: --ssdv_dir opt
rodzic
cfaa6797a0
commit
332809c847
|
@ -130,6 +130,9 @@ public:
|
|||
std::function<void(std::string, std::string, std::string)> sentence_callback_; // callback on each successfull sentence decode
|
||||
std::function<void(std::string)> character_callback_; // callback on each decoded character
|
||||
|
||||
// SSDV
|
||||
SSDV_wraper_t ssdv_;
|
||||
|
||||
private:
|
||||
// IQ buffers
|
||||
TIQVector iq_in_buffer_; // input IQ buffer
|
||||
|
@ -179,9 +182,6 @@ private:
|
|||
std::string last_sentence_; // result of rtty
|
||||
// size_t last_sentence_len_ = 0; // optimization for regexp run
|
||||
|
||||
// SSDV
|
||||
SSDV_wraper_t ssdv_;
|
||||
|
||||
// threading
|
||||
mutable std::mutex process_mutex_; // mutex for main processing
|
||||
|
||||
|
@ -833,5 +833,4 @@ std::ostream& operator<<( std::ostream& output, const std::vector<T>& v )
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
// namespace habdec
|
||||
} // namespace habdec
|
||||
|
|
|
@ -19,11 +19,11 @@
|
|||
*/
|
||||
|
||||
#include "ssdv_wrapper.h"
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <ctime>
|
||||
#include <stdio.h>
|
||||
#include "../ssdv/ssdv.h"
|
||||
|
||||
|
@ -56,10 +56,13 @@ bool SSDV_wraper_t::push(const std::vector<char>& i_chars)
|
|||
size_t i = last_buff_end;
|
||||
while( i < buff_.size() && buff_[i] != 0x55 )
|
||||
++i;
|
||||
if(i < buff_.size() )
|
||||
if(i < buff_.size() ) {
|
||||
packet_begin_ = i;
|
||||
else
|
||||
}
|
||||
else {
|
||||
buff_.clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(packet_begin_>0)
|
||||
|
@ -68,7 +71,6 @@ bool SSDV_wraper_t::push(const std::vector<char>& i_chars)
|
|||
packet_begin_ = 0;
|
||||
}
|
||||
|
||||
// packet incomplete
|
||||
if( buff_.size() < SSDV_PKT_SIZE )
|
||||
return false;
|
||||
|
||||
|
@ -90,39 +92,56 @@ bool SSDV_wraper_t::push(const std::vector<char>& i_chars)
|
|||
packet_begin_ = -1;
|
||||
ssdv_dec_header( &(p_packet->header_), p_packet->data_.data() );
|
||||
|
||||
//insert to image_ map
|
||||
// insert to image_ map
|
||||
pair<string,uint16_t> image_key(p_packet->header_.callsign_s, p_packet->header_.image_id);
|
||||
if( images_.find(image_key) == images_.end() )
|
||||
images_[image_key] = packet_set_t();
|
||||
auto& packet_list = images_[image_key];
|
||||
cout<<image_key.first<<" "<<image_key.second<<" "<<packet_list.size()<<endl;
|
||||
packet_list.insert(p_packet);
|
||||
|
||||
// decode and save image
|
||||
{
|
||||
ssdv_t ssdv;
|
||||
ssdv_dec_init(&ssdv);
|
||||
uint8_t* jpeg = new uint8_t[1024*1024*3];
|
||||
ssdv_dec_set_buffer( &ssdv, jpeg, 1024*1024*3 );
|
||||
|
||||
for(auto p_pkt : packet_list)
|
||||
ssdv_dec_feed( &ssdv, p_pkt->data_.data() );
|
||||
|
||||
size_t jpeg_sz = 0;
|
||||
ssdv_dec_get_jpeg(&ssdv, &jpeg, &jpeg_sz);
|
||||
|
||||
string fname = "./ssdv_" + string(p_packet->header_.callsign_s)
|
||||
+ "_" + std::to_string(int(p_packet->header_.image_id)) + ".jpeg";
|
||||
FILE* fh = fopen( fname.c_str(), "wb" );
|
||||
fwrite(jpeg, 1, jpeg_sz, fh);
|
||||
fclose(fh);
|
||||
delete [] jpeg;
|
||||
|
||||
if( (*packet_list.rbegin())->header_.eoi )
|
||||
images_.erase(image_key);
|
||||
}
|
||||
decode_and_save(image_key);
|
||||
if( (*packet_list.rbegin())->header_.eoi )
|
||||
images_.erase(image_key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SSDV_wraper_t::decode_and_save( std::pair<std::string,uint16_t> image_key )
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if( images_.find(image_key) == images_.end() )
|
||||
return;
|
||||
|
||||
ssdv_t ssdv;
|
||||
ssdv_dec_init(&ssdv);
|
||||
uint8_t* jpeg = new uint8_t[1024*1024*3];
|
||||
ssdv_dec_set_buffer( &ssdv, jpeg, 1024*1024*3 );
|
||||
|
||||
auto& packet_list = images_[image_key];
|
||||
|
||||
for(auto p_pkt : packet_list)
|
||||
ssdv_dec_feed( &ssdv, p_pkt->data_.data() );
|
||||
|
||||
size_t jpeg_sz = 0;
|
||||
ssdv_dec_get_jpeg(&ssdv, &jpeg, &jpeg_sz);
|
||||
|
||||
auto t = std::time(nullptr);
|
||||
char timestamp[200];
|
||||
strftime(timestamp, 200, "%Y-%m-%d", std::localtime(&t) );
|
||||
|
||||
string img_id_pad = std::to_string(image_key.second);
|
||||
img_id_pad = string(4 - img_id_pad.length(), '0') + img_id_pad;
|
||||
|
||||
string fname = base_file_ + string(timestamp)
|
||||
+ "_" + image_key.first
|
||||
+ "_" + img_id_pad + ".jpeg";
|
||||
FILE* fh = fopen( fname.c_str(), "wb" );
|
||||
fwrite(jpeg, 1, jpeg_sz, fh);
|
||||
fclose(fh);
|
||||
delete [] jpeg;
|
||||
}
|
||||
|
||||
} // namespace habdec
|
||||
|
|
|
@ -23,11 +23,8 @@
|
|||
#include <array>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include "../ssdv/ssdv.h"
|
||||
|
||||
namespace habdec
|
||||
|
@ -38,8 +35,12 @@ class SSDV_wraper_t
|
|||
|
||||
public:
|
||||
bool push(const std::vector<char>& i_chars);
|
||||
std::string base_file() const { return base_file_; }
|
||||
void base_file(const std::string& i_fn) { base_file_ = i_fn; }
|
||||
|
||||
private:
|
||||
void decode_and_save( std::pair<std::string,uint16_t> );
|
||||
|
||||
// incomming data buffer
|
||||
std::vector<uint8_t> buff_;
|
||||
int packet_begin_ = -1;
|
||||
|
@ -66,6 +67,9 @@ private:
|
|||
|
||||
image_map_t images_;
|
||||
|
||||
// output_image base filename
|
||||
std::string base_file_;
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -102,6 +102,7 @@ public:
|
|||
std::string habitat_payload_ = "";
|
||||
std::string coord_format_lat_ = "dd.dddd"; // encoding of lat/lon coords: dd.dddd or ddmm.mmmm
|
||||
std::string coord_format_lon_ = "dd.dddd"; // encoding of lat/lon coords: dd.dddd or ddmm.mmmm
|
||||
std::string ssdv_dir_ = ".";
|
||||
// int datasize_ = 1;
|
||||
TransportDataType transport_data_type_ = TransportDataType::kChar;
|
||||
|
||||
|
|
|
@ -415,6 +415,7 @@ int main(int argc, char** argv)
|
|||
// setup GLOBALS
|
||||
prog_opts(argc, argv);
|
||||
|
||||
auto& G = GLOBALS::get();
|
||||
|
||||
// setup SoapySDR device
|
||||
SoapySDR::Kwargs device;
|
||||
|
@ -426,7 +427,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
if( GLOBALS::get().par_.no_exit_ )
|
||||
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) ));
|
||||
|
@ -442,37 +443,38 @@ int main(int argc, char** argv)
|
|||
|
||||
|
||||
// station info
|
||||
if( GLOBALS::get().par_.station_callsign_ != "" )
|
||||
if( G.par_.station_callsign_ != "" )
|
||||
{
|
||||
habdec::habitat::UploadStationInfo( GLOBALS::get().par_.station_callsign_,
|
||||
habdec::habitat::UploadStationInfo( G.par_.station_callsign_,
|
||||
device["driver"] + " - habdec" );
|
||||
|
||||
if( GLOBALS::get().par_.station_lat_
|
||||
&& GLOBALS::get().par_.station_lon_ )
|
||||
if( G.par_.station_lat_
|
||||
&& G.par_.station_lon_ )
|
||||
habdec::habitat::UploadStationTelemetry(
|
||||
GLOBALS::get().par_.station_callsign_,
|
||||
GLOBALS::get().par_.station_lat_, GLOBALS::get().par_.station_lon_,
|
||||
GLOBALS::get().par_.station_alt_, 0, false
|
||||
G.par_.station_callsign_,
|
||||
G.par_.station_lat_, G.par_.station_lon_,
|
||||
G.par_.station_alt_, 0, false
|
||||
);
|
||||
}
|
||||
|
||||
// initial options from globals
|
||||
//
|
||||
auto& DECODER = GLOBALS::get().decoder_;
|
||||
DECODER.baud(GLOBALS::get().par_.baud_);
|
||||
DECODER.rtty_bits(GLOBALS::get().par_.rtty_ascii_bits_);
|
||||
DECODER.rtty_stops(GLOBALS::get().par_.rtty_ascii_stops_);
|
||||
DECODER.livePrint( GLOBALS::get().par_.live_print_ );
|
||||
DECODER.dc_remove( GLOBALS::get().par_.dc_remove_ );
|
||||
DECODER.lowpass_bw( GLOBALS::get().par_.lowpass_bw_Hz_ );
|
||||
DECODER.lowpass_trans( GLOBALS::get().par_.lowpass_tr_ );
|
||||
int _decim = GLOBALS::get().par_.decimation_;
|
||||
auto& DECODER = G.decoder_;
|
||||
DECODER.baud(G.par_.baud_);
|
||||
DECODER.rtty_bits(G.par_.rtty_ascii_bits_);
|
||||
DECODER.rtty_stops(G.par_.rtty_ascii_stops_);
|
||||
DECODER.livePrint( G.par_.live_print_ );
|
||||
DECODER.dc_remove( G.par_.dc_remove_ );
|
||||
DECODER.lowpass_bw( G.par_.lowpass_bw_Hz_ );
|
||||
DECODER.lowpass_trans( G.par_.lowpass_tr_ );
|
||||
int _decim = G.par_.decimation_;
|
||||
DECODER.setupDecimationStagesFactor( pow(2,_decim) );
|
||||
DECODER.ssdv_.base_file( G.par_.ssdv_dir_ + "/ssdv_" );
|
||||
|
||||
double freq = GLOBALS::get().par_.frequency_;
|
||||
GLOBALS::get().p_iq_source_->setOption("frequency_double", &freq);
|
||||
double freq = G.par_.frequency_;
|
||||
G.p_iq_source_->setOption("frequency_double", &freq);
|
||||
|
||||
if(GLOBALS::get().par_.station_callsign_ == "")
|
||||
if(G.par_.station_callsign_ == "")
|
||||
cout<<C_RED<<"No --station parameter set. HAB Upload disabled."<<C_OFF<<endl;
|
||||
|
||||
cout<<"Current Options: "<<endl;
|
||||
|
@ -481,7 +483,7 @@ int main(int argc, char** argv)
|
|||
|
||||
// websocket server
|
||||
shared_ptr<WebsocketServer> p_ws_server = make_shared<WebsocketServer>(
|
||||
GLOBALS::get().par_.command_host_ , GLOBALS::get().par_.command_port_);
|
||||
G.par_.command_host_ , G.par_.command_port_);
|
||||
|
||||
DECODER.sentence_callback_ =
|
||||
[p_ws_server](string callsign, string data, string crc)
|
||||
|
|
|
@ -109,6 +109,9 @@ void prog_opts(int ac, char* av[])
|
|||
("flights", po::value<int>()->implicit_value(0), "List Habitat flights")
|
||||
("payload", po::value<string>(), "Configure for Payload ID")
|
||||
("nmea", po::value<bool>(), "assume NMEA lat/lon format: ddmm.mmmm")
|
||||
|
||||
("ssdv_dir", po::value<string>()->default_value(GLOBALS::get().par_.ssdv_dir_), "SSDV directory.")
|
||||
|
||||
;
|
||||
|
||||
po::options_description cli_options("Command Line Interface options");
|
||||
|
@ -293,6 +296,10 @@ void prog_opts(int ac, char* av[])
|
|||
{
|
||||
GLOBALS::get().par_.station_alt_ = vm["alt"].as<float>();
|
||||
}
|
||||
if (vm.count("ssdv_dir"))
|
||||
{
|
||||
GLOBALS::get().par_.ssdv_dir_ = vm["ssdv_dir"].as<string>();
|
||||
}
|
||||
}
|
||||
catch(exception& e)
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue