kopia lustrzana https://github.com/ogre/habdec
Merge branch 'ssdv'
commit
112dc02962
|
@ -0,0 +1,3 @@
|
|||
[submodule "code/ssdv"]
|
||||
path = code/ssdv
|
||||
url = https://github.com/fsphil/ssdv.git
|
|
@ -11,6 +11,7 @@ Some facts:
|
|||
- provides websocket server so can be controlled from any web browser [even on your phone](https://www.youtube.com/watch?v=dli8FEFy5tM)
|
||||
- can be easily integrated into your own code
|
||||
- has example python client
|
||||
- decodes [SSDV](https://ukhas.org.uk/guides:ssdv) images
|
||||
|
||||
Original motivation for habdec was to have a portable tracking device you could take to a chasecar or into a field.
|
||||
|
||||
|
@ -186,7 +187,6 @@ Do not try connecting directly to `http://ip:port ` - habdec is not an HTTP serv
|
|||
## Known Limitations
|
||||
|
||||
- RTTY Modes **NOT** supported: 5bit baudot, 1.5 bit stop
|
||||
- SSDV is not supported
|
||||
- Decoding will stop if decimation setting is too low or too high. It was tested to work with stream around 40kHz bandwidth.
|
||||
- Automatic Frequency Correction needs more work. Use consciously. dc_remove=on can help if AFC is confused by center spike.
|
||||
- Connecting from browser is not very reliable yet, sometimes you need to refresh and wait.
|
||||
|
|
|
@ -17,6 +17,7 @@ message ( "CMAKE_INSTALL_PREFIX: " ${CMAKE_INSTALL_PREFIX} )
|
|||
|
||||
add_subdirectory("Decoder")
|
||||
add_subdirectory("IQSource")
|
||||
add_subdirectory("ssdv_build")
|
||||
add_subdirectory("websocketServer")
|
||||
|
||||
option( fltkGUI "fltkGUI" OFF )
|
||||
|
|
|
@ -31,6 +31,7 @@ set ( Decoder_src
|
|||
sentence_extract.h sentence_extract.cpp
|
||||
SpectrumInfo.h
|
||||
SymbolExtractor.h
|
||||
ssdv_wrapper.cpp
|
||||
)
|
||||
|
||||
SET( CMAKE_CXX_FLAGS " -O3 " )
|
||||
|
@ -50,6 +51,7 @@ endif()
|
|||
|
||||
add_library( Decoder ${Decoder_src})
|
||||
target_link_libraries( Decoder
|
||||
ssdv_lib
|
||||
#${SoapySDR_LIBRARIES}
|
||||
${FFTW3f_LIBRARIES}
|
||||
${PlatformSpecificLinking} )
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "SpectrumInfo.h"
|
||||
#include "print_habhub_sentence.h"
|
||||
#include "CRC.h"
|
||||
#include "ssdv_wrapper.h"
|
||||
|
||||
namespace habdec
|
||||
{
|
||||
|
@ -62,12 +63,12 @@ class Decoder
|
|||
// RTTY
|
||||
|
||||
public:
|
||||
typedef TReal TValue;
|
||||
typedef std::complex<TReal> TComplex;
|
||||
typedef std::vector<TReal> TRVector;
|
||||
typedef habdec::IQVector<TReal> TIQVector;
|
||||
typedef habdec::Decimator< std::complex<TReal>, TReal > TDecimator;
|
||||
typedef habdec::FirFilter< std::complex<TReal>, TReal> TFIR;
|
||||
using TValue = TReal;
|
||||
using TComplex = std::complex<TReal>;
|
||||
using TRVector = std::vector<TReal>;
|
||||
using TIQVector = habdec::IQVector<TReal>;
|
||||
using TDecimator = habdec::Decimator< std::complex<TReal>, TReal >;
|
||||
using TFIR = habdec::FirFilter< std::complex<TReal>, TReal>;
|
||||
|
||||
// feed decoder
|
||||
bool pushSamples(const TIQVector& i_stream);
|
||||
|
@ -126,8 +127,18 @@ public:
|
|||
|
||||
bool livePrint() const { return live_print_; }
|
||||
void livePrint(bool i_live) { live_print_ = i_live; }
|
||||
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
|
||||
|
||||
std::string ssdvBaseFile() const { return ssdv_.base_file(); }
|
||||
void ssdvBaseFile(const std::string& _f) { ssdv_.base_file(_f); }
|
||||
|
||||
// callback on each successfull sentence decode. callsign, sentence_data, CRC
|
||||
std::function<void(std::string, std::string, std::string)> sentence_callback_;
|
||||
|
||||
// callback on each decoded characters
|
||||
std::function<void(std::string)> character_callback_;
|
||||
|
||||
// callback on each decoded ssdv packet. callsign, image_id, jpeg_bytes
|
||||
std::function<void(std::string, int, std::vector<uint8_t>)> ssdv_callback_;
|
||||
|
||||
private:
|
||||
// IQ buffers
|
||||
|
@ -178,6 +189,9 @@ 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
|
||||
|
||||
|
@ -555,14 +569,19 @@ void habdec::Decoder<TReal>::process()
|
|||
return;
|
||||
|
||||
|
||||
auto decoded_chars = rtty_.get();
|
||||
rtty_char_stream_.insert( rtty_char_stream_.end(), decoded_chars.begin(), decoded_chars.end() );
|
||||
chr_callback_stream_.insert( chr_callback_stream_.end(), decoded_chars.begin(), decoded_chars.end() );
|
||||
vector<char> raw_chars = rtty_.get();
|
||||
const bool b_new_ssdv = ssdv_.push(raw_chars);
|
||||
|
||||
vector<char> printable_chars;
|
||||
copy_if( raw_chars.begin(), raw_chars.end(), back_inserter(printable_chars),
|
||||
[](char c){return isprint(c) || c == '\n';}
|
||||
);
|
||||
rtty_char_stream_.insert( rtty_char_stream_.end(), printable_chars.begin(), printable_chars.end() );
|
||||
chr_callback_stream_.insert( chr_callback_stream_.end(), printable_chars.begin(), printable_chars.end() );
|
||||
|
||||
if(live_print_)
|
||||
{
|
||||
for( auto c : decoded_chars )
|
||||
for( auto c : printable_chars )
|
||||
cout<<c;
|
||||
cout.flush();
|
||||
}
|
||||
|
@ -609,6 +628,8 @@ void habdec::Decoder<TReal>::process()
|
|||
character_callback_time = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
if(b_new_ssdv && ssdv_callback_)
|
||||
ssdv_callback_( ssdv_.last_img_k_.first, ssdv_.last_img_k_.second, ssdv_.get_jpeg(ssdv_.last_img_k_) );
|
||||
|
||||
// overflow protection
|
||||
if(rtty_char_stream_.size() > 1000)
|
||||
|
@ -824,5 +845,4 @@ std::ostream& operator<<( std::ostream& output, const std::vector<T>& v )
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
// namespace habdec
|
||||
} // namespace habdec
|
||||
|
|
|
@ -84,7 +84,7 @@ size_t RTTY<TBit>::operator()()
|
|||
|
||||
using namespace std;
|
||||
|
||||
size_t decoded_chars = 0;
|
||||
size_t n_decoded_chars = 0;
|
||||
size_t last_decoded_bit_index = 0;
|
||||
|
||||
for(size_t i=0; i<bits_.size()/*-char_bitlen*/; /**/)
|
||||
|
@ -118,10 +118,10 @@ size_t RTTY<TBit>::operator()()
|
|||
++i;
|
||||
}
|
||||
|
||||
if( isprint(c) || c == '\n' )
|
||||
// if( isprint(c) || c == '\n' )
|
||||
{
|
||||
chars_.push_back(c);
|
||||
++decoded_chars;
|
||||
++n_decoded_chars;
|
||||
}
|
||||
|
||||
i += nstops_;
|
||||
|
@ -133,7 +133,7 @@ size_t RTTY<TBit>::operator()()
|
|||
if(last_decoded_bit_index)
|
||||
bits_.erase( bits_.begin(), bits_.begin() + last_decoded_bit_index + 1 );
|
||||
|
||||
return decoded_chars;
|
||||
return n_decoded_chars;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ssdv_wrapper.h"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <future>
|
||||
#include <ctime>
|
||||
#include <stdio.h>
|
||||
#include "../ssdv/ssdv.h"
|
||||
|
||||
|
||||
namespace habdec
|
||||
{
|
||||
|
||||
|
||||
bool SSDV_wraper_t::push(const std::vector<char>& i_chars)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
// copy to buff_
|
||||
const size_t last_buff_end = buff_.size();
|
||||
buff_.resize( buff_.size() + i_chars.size() );
|
||||
memcpy( buff_.data() + last_buff_end, i_chars.data(), i_chars.size() );
|
||||
|
||||
if( buff_.size() < SSDV_PKT_SIZE )
|
||||
return false;
|
||||
|
||||
// scan buff_ for packet sync byte: 0x55
|
||||
if(packet_begin_ == -1)
|
||||
{
|
||||
while( ++packet_begin_ < buff_.size() && buff_[packet_begin_] != 0x55 ) /**/;
|
||||
|
||||
if(packet_begin_ == buff_.size())
|
||||
{
|
||||
buff_.clear();
|
||||
packet_begin_ = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( (buff_.size()-packet_begin_) < SSDV_PKT_SIZE )
|
||||
return false;
|
||||
|
||||
int errors = 0;
|
||||
const int is_packet = ssdv_dec_is_packet( buff_.data()+packet_begin_, &errors );
|
||||
if( is_packet != 0 ) // no packet starting at packet_begin_
|
||||
{
|
||||
//scan for another 0x55
|
||||
while( ++packet_begin_ < buff_.size() && buff_[packet_begin_] != 0x55 ) /**/;
|
||||
|
||||
if(packet_begin_ == buff_.size())
|
||||
{
|
||||
buff_.clear();
|
||||
packet_begin_ = -1;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
buff_.erase( buff_.begin(), buff_.begin() + packet_begin_ );
|
||||
packet_begin_ = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// make packet and decode header
|
||||
shared_ptr<packet_t> p_packet(new packet_t);
|
||||
memcpy( p_packet->data_.data(), buff_.data()+packet_begin_, sizeof(p_packet->data_) );
|
||||
buff_.erase( buff_.begin() + packet_begin_, buff_.begin() + packet_begin_ + SSDV_PKT_SIZE );
|
||||
packet_begin_ = -1;
|
||||
ssdv_dec_header( &(p_packet->header_), p_packet->data_.data() );
|
||||
|
||||
// insert to packets_ map
|
||||
// what happens when we already inserted packet with that ID ?
|
||||
// either the packet is retransmitted for the same image
|
||||
// or this indicates that a new image is being send with conflicting image num (over 255 cycle?)
|
||||
// -> delete image and insert as new packet
|
||||
// what happens when new packet has different resolution as previously inserted ?
|
||||
// this indicates that a new image is being send with conflicting image num
|
||||
// -> delete image and insert as new packet
|
||||
|
||||
pair<string,uint16_t> image_key(p_packet->header_.callsign_s, p_packet->header_.image_id);
|
||||
auto p_packet_list = packets_.find(image_key);
|
||||
if( p_packet_list == packets_.end() ) // new image (callsign/id)
|
||||
{
|
||||
cout<<endl<<" -- new image/packet set: "<<image_key.first<<" "<<image_key.second<<endl;
|
||||
packets_[image_key] = packet_set_t();
|
||||
packets_[image_key].insert(p_packet);
|
||||
}
|
||||
else // append to existing image (callsign/id)
|
||||
{
|
||||
// check if this packet ID was already inserted
|
||||
bool packet_already_exists = false;
|
||||
for(auto _p_pkt : p_packet_list->second) {
|
||||
if(_p_pkt->header_.packet_id == p_packet->header_.packet_id) {
|
||||
packet_already_exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// and check for resolution mismatch against previously inserted packet
|
||||
const auto last_height = p_packet_list->second.rbegin()->get()->header_.height;
|
||||
const auto last_width = p_packet_list->second.rbegin()->get()->header_.width;
|
||||
|
||||
if(packet_already_exists) {
|
||||
cout<<endl<<"Packet ID "<<p_packet->header_.packet_id<<" for image "<<image_key.first<<"/"<<image_key.second
|
||||
<<" has already been received. Deleting and restarting image with new packet."<<endl;
|
||||
packets_[image_key] = packet_set_t();
|
||||
packets_[image_key].insert(p_packet);
|
||||
}
|
||||
else if(last_height != p_packet->header_.height || last_width != p_packet->header_.width ) {
|
||||
cout<<endl<<"Packet ID "<<p_packet->header_.packet_id<<" for image "<<image_key.first<<"/"<<image_key.second
|
||||
<<" has different resolution. Deleting and restarting image with new packet."<<endl;
|
||||
packets_[image_key] = packet_set_t();
|
||||
packets_[image_key].insert(p_packet);
|
||||
}
|
||||
else { // new packet has OK resolution and unique ID. Inserting.
|
||||
packets_[image_key].insert(p_packet);
|
||||
}
|
||||
}
|
||||
|
||||
// decode and save image
|
||||
make_jpeg( packets_[image_key], image_key );
|
||||
save_jpeg(image_key);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SSDV_wraper_t::make_jpeg( const packet_set_t& packet_list, const image_key_t& image_key )
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
auto& last_pkt = *packet_list.rbegin();
|
||||
size_t jpeg_sz = 3 * last_pkt->header_.width * last_pkt->header_.height;
|
||||
|
||||
if( jpegs_.find(image_key) == jpegs_.end() )
|
||||
jpegs_[image_key] = vector<uint8_t>( jpeg_sz );
|
||||
|
||||
auto& jpeg = jpegs_[image_key];
|
||||
uint8_t* p_data = &jpeg[0];
|
||||
|
||||
ssdv_t ssdv;
|
||||
ssdv_dec_init(&ssdv);
|
||||
|
||||
ssdv_dec_set_buffer( &ssdv, p_data, jpeg_sz );
|
||||
for(auto p_pkt : packet_list)
|
||||
ssdv_dec_feed( &ssdv, p_pkt->data_.data() );
|
||||
|
||||
ssdv_dec_get_jpeg(&ssdv, &p_data, &jpeg_sz);
|
||||
|
||||
last_img_k_ = image_key;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> SSDV_wraper_t::get_jpeg(const image_key_t& image_key)
|
||||
|
||||
{
|
||||
if( jpegs_.find(image_key) == jpegs_.end() ) {
|
||||
return std::vector<uint8_t>(0);
|
||||
}
|
||||
|
||||
return jpegs_[image_key];
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SSDV_wraper_t::save_jpeg( const image_key_t& image_key )
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if( jpegs_.find(image_key) == jpegs_.end() )
|
||||
return;
|
||||
|
||||
const auto jpeg = jpegs_[image_key];
|
||||
const auto base_file = base_file_;
|
||||
|
||||
async(launch::async, [&jpeg, &base_file, image_key](){
|
||||
// timestamp
|
||||
auto t = std::time(nullptr);
|
||||
char timestamp[200];
|
||||
strftime(timestamp, 200, "%Y-%m-%d", std::localtime(&t) );
|
||||
// filename 0 padding
|
||||
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.data(), 1, jpeg.size(), fh);
|
||||
fclose(fh);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace habdec
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <memory>
|
||||
#include "../ssdv/ssdv.h"
|
||||
|
||||
namespace habdec
|
||||
{
|
||||
|
||||
class SSDV_wraper_t
|
||||
{
|
||||
private:
|
||||
// incomming data buffer
|
||||
std::vector<uint8_t> buff_;
|
||||
int packet_begin_ = -1;
|
||||
|
||||
// ssdv packet with header
|
||||
struct packet_t {
|
||||
ssdv_packet_info_t header_;
|
||||
std::array<uint8_t, 256> data_;
|
||||
};
|
||||
|
||||
using packet_t_ptr = std::shared_ptr<packet_t>;
|
||||
|
||||
struct packet_t_ptr_less { // comparator
|
||||
bool operator()(const packet_t_ptr& lhs, const packet_t_ptr& rhs) {
|
||||
return lhs->header_.packet_id < rhs->header_.packet_id;
|
||||
}
|
||||
};
|
||||
|
||||
using packet_set_t = std::set<packet_t_ptr, packet_t_ptr_less>;
|
||||
|
||||
using image_key_t = std::pair<std::string,uint16_t>;
|
||||
|
||||
using image_map_t = std::map< // indexed by (callsign,imageID)
|
||||
image_key_t,
|
||||
packet_set_t >;
|
||||
|
||||
// list of packets for each (callsign, imageId)
|
||||
std::map< image_key_t, packet_set_t > packets_;
|
||||
|
||||
// complete JPEG for each (callsign, imageId)
|
||||
std::map< image_key_t, std::vector<uint8_t> > jpegs_;
|
||||
|
||||
// output_image base filename
|
||||
std::string base_file_;
|
||||
|
||||
void make_jpeg(const packet_set_t&, const image_key_t&);
|
||||
void save_jpeg(const image_key_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; }
|
||||
image_key_t last_img_k_ = {"",0};
|
||||
std::vector<uint8_t> get_jpeg(const image_key_t&);
|
||||
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
set ( ssdv_lib_src
|
||||
${PROJECT_SOURCE_DIR}/ssdv/rs8.c
|
||||
${PROJECT_SOURCE_DIR}/ssdv/ssdv.c
|
||||
)
|
||||
set_source_files_properties ( ${ssdv_lib_src} LANGUAGE "C" )
|
||||
add_library( ssdv_lib ${ssdv_lib_src} )
|
||||
|
||||
|
||||
if(NOT WIN32)
|
||||
set ( ssdv_exe_src
|
||||
${PROJECT_SOURCE_DIR}/ssdv/rs8.c
|
||||
${PROJECT_SOURCE_DIR}/ssdv/ssdv.c
|
||||
${PROJECT_SOURCE_DIR}/ssdv/main.c
|
||||
)
|
||||
set_source_files_properties ( ${ssdv_exe_src} LANGUAGE "C" )
|
||||
add_executable( ssdv ${ssdv_exe_src} )
|
||||
ENDIF(WIN32)
|
|
@ -143,4 +143,25 @@ input[type=checkbox]
|
|||
}
|
||||
|
||||
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
|
||||
.show {display:block;}
|
||||
.show {display:block;}
|
||||
|
||||
.HD_ssdv_modal {
|
||||
display: none; /* Hidden by default */
|
||||
position: fixed; /* Stay in place */
|
||||
z-index: 1; /* Sit on top */
|
||||
padding-top: 100px; /* Location of the box */
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%; /* Full width */
|
||||
height: 100%; /* Full height */
|
||||
overflow: auto; /* Enable scroll if needed */
|
||||
}
|
||||
|
||||
.HD_ssdv_modal img {
|
||||
width: 50%;
|
||||
height: 50%;
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
|
||||
}
|
|
@ -78,3 +78,22 @@ function DecodeDemod(i_buffer, i_offset)
|
|||
|
||||
return header;
|
||||
}
|
||||
|
||||
|
||||
function DecodeJpegBase64(i_buffer, i_offset)
|
||||
{
|
||||
var dv = new DataView(i_buffer, i_offset);
|
||||
var offset = 0;
|
||||
var callsign_size = dv.getInt32(offset, true); offset += 4;
|
||||
var image_id = dv.getInt32(offset, true); offset += 4;
|
||||
|
||||
offset += 4; // why ?
|
||||
var callsing_data = new Uint8Array( i_buffer, offset, callsign_size); offset += callsign_size;
|
||||
var callsing_str = new TextDecoder("utf-8").decode(callsing_data);
|
||||
|
||||
// rest is JPEG data
|
||||
var jpeg_data = new Uint8Array( i_buffer, offset );
|
||||
var jpeg_str = new TextDecoder("utf-8").decode(jpeg_data);
|
||||
|
||||
return [callsing_str, image_id, jpeg_str];
|
||||
}
|
||||
|
|
|
@ -474,6 +474,32 @@ function HABDEC_BUILD_UI_DemodAndInfo()
|
|||
divcnt_habsentence_list.id = "cnt_habsentence_list";
|
||||
divcnt_habsentence_list.classList.add("habsentence_text");
|
||||
|
||||
// SSDV
|
||||
var ssdv_div = document.createElement("div");
|
||||
var ssdv_info = document.createElement("text");
|
||||
ssdv_info.id = "HabDec_SSDV_Info";
|
||||
ssdv_info.style.color = "var(--HD_label)"
|
||||
var ssdv_img = document.createElement("img");
|
||||
ssdv_img.id = "HabDec_SSDV_Image";
|
||||
ssdv_img.style.height = "100%";
|
||||
var ssdv_img_div = document.createElement("div");
|
||||
ssdv_div.appendChild(ssdv_info);
|
||||
ssdv_img_div.appendChild(ssdv_img);
|
||||
ssdv_div.appendChild(ssdv_img_div);
|
||||
|
||||
// SSDV fullscreen - when clicked
|
||||
var ssdv_FS_div = document.createElement("div");
|
||||
ssdv_FS_div.classList.add("HD_ssdv_modal");
|
||||
ssdv_img.onclick = function(){
|
||||
ssdv_FS_div.appendChild(ssdv_img_div);
|
||||
ssdv_FS_div.style.display = "block";
|
||||
}
|
||||
ssdv_FS_div.onclick = function(){
|
||||
ssdv_div.appendChild(ssdv_img_div);
|
||||
ssdv_FS_div.style.display = "None";
|
||||
}
|
||||
ssdv_div.appendChild(ssdv_FS_div);
|
||||
|
||||
|
||||
div_info.appendChild(div_debug);
|
||||
div_info.appendChild( document.createElement("br") );
|
||||
|
@ -483,6 +509,7 @@ function HABDEC_BUILD_UI_DemodAndInfo()
|
|||
|
||||
div_top.appendChild(div_cnt_demodCanvas);
|
||||
div_top.appendChild(div_info);
|
||||
div_top.appendChild(ssdv_div);
|
||||
|
||||
return div_top;
|
||||
|
||||
|
@ -563,15 +590,7 @@ function HABDEC_BUILD_UI_ExtraRadioButtons()
|
|||
div_three_buttons.appendChild(b_afc);
|
||||
div_three_buttons.appendChild(b_dc_remove);
|
||||
|
||||
// <p> <button id="btnFullscreen" type="button" onclick="toggleFullscreen()">Fullscreen</button> </p>
|
||||
var btnFullscreen = document.createElement("button");
|
||||
btnFullscreen.innerHTML = "Fullscreen";
|
||||
btnFullscreen.onclick = () => { toggleFullscreen() };
|
||||
var paragraph = document.createElement("p");
|
||||
paragraph.appendChild(btnFullscreen);
|
||||
|
||||
div_top.appendChild(div_three_buttons);
|
||||
div_top.appendChild(paragraph);
|
||||
|
||||
return div_top;
|
||||
}
|
||||
|
@ -666,7 +685,6 @@ function HABDEC_BUILD_UI(parent_div)
|
|||
var div_server = HABDEC_BUILD_UI_Server();
|
||||
//<!-- <div id="PayloadsWrapperDiv"></div> -->
|
||||
|
||||
|
||||
// flights list
|
||||
var div_payloads_wrapper = document.createElement("div");
|
||||
div_payloads_wrapper.id = "PayloadsWrapperDiv";
|
||||
|
@ -675,11 +693,19 @@ function HABDEC_BUILD_UI(parent_div)
|
|||
var div_colors_wrapper = document.createElement("div");
|
||||
div_colors_wrapper.id = "ColorSchemesWrapperDiv";
|
||||
|
||||
// div for flights and colors - in row
|
||||
// fullscreen button
|
||||
var div_but_fs = document.createElement("div");
|
||||
var btnFullscreen = document.createElement("button");
|
||||
btnFullscreen.innerHTML = "Fullscreen";
|
||||
btnFullscreen.onclick = () => { toggleFullscreen() };
|
||||
div_but_fs.appendChild(btnFullscreen);
|
||||
|
||||
// div for [flights, colors, fillscreen] - in row
|
||||
var extra_options = document.createElement("div");
|
||||
extra_options.style.display = 'flex';
|
||||
extra_options.appendChild(div_payloads_wrapper);
|
||||
extra_options.appendChild(div_colors_wrapper);
|
||||
extra_options.appendChild(div_but_fs);
|
||||
|
||||
// parent_div.display.height = "1000px";
|
||||
parent_div.appendChild(div_power);
|
||||
|
@ -696,7 +722,6 @@ function HABDEC_BUILD_UI(parent_div)
|
|||
|
||||
window.addEventListener('message', HB_WinMsgHandler);
|
||||
|
||||
|
||||
// HD_ApplyeColorScheme( HD_COLOR_SCHEMES["DEFAULT"] );
|
||||
}
|
||||
|
||||
|
|
|
@ -118,6 +118,15 @@ function ws_onMessage(evt)
|
|||
G_DEMOD_DATA = DecodeDemod(evt.data, 4);
|
||||
RefreshDemod_lastReq = 0;
|
||||
}
|
||||
else if(what == "SDV_") // SSDV jpeg
|
||||
{
|
||||
[callsing_str, image_id, jpeg_en64] = DecodeJpegBase64(evt.data, 4);
|
||||
console.debug("SSDV", callsing_str, image_id);
|
||||
var img = document.getElementById("HabDec_SSDV_Image");
|
||||
img.setAttribute('src', 'data:image/jpeg;base64,' + jpeg_en64);
|
||||
var tex= document.getElementById("HabDec_SSDV_Info");
|
||||
tex.innerHTML = callsing_str + " / " + image_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -0,0 +1,124 @@
|
|||
#ifndef _MACARON_BASE64_H_
|
||||
#define _MACARON_BASE64_H_
|
||||
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2016 tomykaira
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace macaron {
|
||||
|
||||
class Base64 {
|
||||
public:
|
||||
|
||||
static std::string Encode(const std::string data) {
|
||||
static constexpr char sEncodingTable[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
size_t in_len = data.size();
|
||||
size_t out_len = 4 * ((in_len + 2) / 3);
|
||||
std::string ret(out_len, '\0');
|
||||
size_t i;
|
||||
char *p = const_cast<char*>(ret.c_str());
|
||||
|
||||
for (i = 0; i < in_len - 2; i += 3) {
|
||||
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
|
||||
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int) (data[i + 2] & 0xC0) >> 6)];
|
||||
*p++ = sEncodingTable[data[i + 2] & 0x3F];
|
||||
}
|
||||
if (i < in_len) {
|
||||
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
|
||||
if (i == (in_len - 1)) {
|
||||
*p++ = sEncodingTable[((data[i] & 0x3) << 4)];
|
||||
*p++ = '=';
|
||||
}
|
||||
else {
|
||||
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
|
||||
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)];
|
||||
}
|
||||
*p++ = '=';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::string Decode(const std::string& input, std::string& out) {
|
||||
static constexpr unsigned char kDecodingTable[] = {
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
|
||||
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
|
||||
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
|
||||
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
|
||||
};
|
||||
|
||||
size_t in_len = input.size();
|
||||
if (in_len % 4 != 0) return "Input data size is not a multiple of 4";
|
||||
|
||||
size_t out_len = in_len / 4 * 3;
|
||||
if (input[in_len - 1] == '=') out_len--;
|
||||
if (input[in_len - 2] == '=') out_len--;
|
||||
|
||||
out.resize(out_len);
|
||||
|
||||
for (size_t i = 0, j = 0; i < in_len;) {
|
||||
uint32_t a = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
|
||||
uint32_t b = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
|
||||
uint32_t c = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
|
||||
uint32_t d = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
|
||||
|
||||
uint32_t triple = (a << 3 * 6) + (b << 2 * 6) + (c << 1 * 6) + (d << 0 * 6);
|
||||
|
||||
if (j < out_len) out[j++] = (triple >> 2 * 8) & 0xFF;
|
||||
if (j < out_len) out[j++] = (triple >> 1 * 8) & 0xFF;
|
||||
if (j < out_len) out[j++] = (triple >> 0 * 8) & 0xFF;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* _MACARON_BASE64_H_ */
|
|
@ -103,6 +103,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;
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "GLOBALS.h"
|
||||
#include "ws_server.h"
|
||||
#include "common/git_repo_sha1.h"
|
||||
#include "Base64.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
@ -238,8 +239,6 @@ void DECODER_THREAD()
|
|||
//////
|
||||
//
|
||||
|
||||
typedef std::chrono::nanoseconds TDur;
|
||||
|
||||
auto& DECODER = GLOBALS::get().decoder_;
|
||||
|
||||
habdec::IQVector<TReal> samples;
|
||||
|
@ -248,8 +247,6 @@ void DECODER_THREAD()
|
|||
|
||||
while(1)
|
||||
{
|
||||
auto _start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
size_t count = p_iq_src->get( samples.data(), samples.size() );
|
||||
if(count)
|
||||
samples.resize(count);
|
||||
|
@ -277,9 +274,6 @@ void DECODER_THREAD()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
TDur _duration = std::chrono::duration_cast<TDur>(std::chrono::high_resolution_clock::now() - _start);
|
||||
|
||||
// accumulate demod samples to display more
|
||||
{
|
||||
std::lock_guard<std::mutex> _lock(GLOBALS::get().demod_accumulated_mtx_);
|
||||
|
@ -416,6 +410,7 @@ int main(int argc, char** argv)
|
|||
// setup GLOBALS
|
||||
prog_opts(argc, argv);
|
||||
|
||||
auto& G = GLOBALS::get();
|
||||
|
||||
// setup SoapySDR device
|
||||
SoapySDR::Kwargs device;
|
||||
|
@ -427,7 +422,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) ));
|
||||
|
@ -443,37 +438,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.ssdvBaseFile( 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;
|
||||
|
@ -482,7 +478,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)
|
||||
|
@ -498,6 +494,26 @@ int main(int argc, char** argv)
|
|||
p_ws_server->sessions_send(p_msg);
|
||||
};
|
||||
|
||||
DECODER.ssdv_callback_ =
|
||||
[p_ws_server](string callsign, int image_id, std::vector<uint8_t> jpeg)
|
||||
{
|
||||
shared_ptr<HabdecMessage> p_msg = make_shared<HabdecMessage>();
|
||||
p_msg->is_binary_ = true;
|
||||
// p_msg->to_all_clients_ = true;
|
||||
|
||||
// header
|
||||
pair<int,int> ssdv_header{ (int)callsign.size(), (int)image_id };
|
||||
p_msg->data_stream_<<"SDV_";
|
||||
p_msg->data_stream_.write( reinterpret_cast<char*>(&ssdv_header), sizeof(ssdv_header) );
|
||||
p_msg->data_stream_<<callsign;
|
||||
// base64 encoded JPEG bytes
|
||||
string b64_jpeg_out = macaron::Base64().Encode( string((char*)jpeg.data(), jpeg.size()) );
|
||||
for(size_t i = 0; i<b64_jpeg_out.size(); ++i)
|
||||
p_msg->data_stream_<<(char)b64_jpeg_out[i];
|
||||
p_ws_server->sessions_send(p_msg);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// START THREADS
|
||||
//
|
||||
|
|
|
@ -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