Skip to content

Commit

Permalink
Add Cluster livedecoder including live audio!
Browse files Browse the repository at this point in the history
  • Loading branch information
OK9UWU committed Jan 16, 2024
1 parent 2d80719 commit 92c37aa
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pipelines/Cluster.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
[
2,
0
],
[
3,
0
]
],
"work": {
Expand Down
42 changes: 40 additions & 2 deletions plugins/cluster_support/cluster/instruments/wbd_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,46 @@ namespace cluster{
std::vector<MajorFrame> WBDdecoder::work(uint8_t *frm){
std::vector<MajorFrame> outputframes;



if(frm[3] % 4 == 0){

if(wbdwip.payload.size() == 1090*4-8){
outputframes.push_back(wbdwip);
}
wbdwip = MajorFrame();

}
else if(frm[3] % 4 == 1){
wbdwip.antennaselect = (frm[5] >> 4) & 0b11; // 0 Ez, 1 Bz, 2 By, 3 Ey
wbdwip.convfreq = (frm[5] >> 2) & 0b11; // conversion freq, 0, 125.454, 250.908, 501.816k
wbdwip.hgagc = frm[5] & 0b11; //Higher AGC select
wbdwip.commands = frm[5] >> 5 & 0b1; // Command Status (0=No cmds; 1=Cmds received)
wbdwip.OBDH = frm[5] >> 6 & 0b1; // OBDH Interface (0=Primary; 1=Redundant)
wbdwip.ADpower = frm[5] >> 4 & 0b1; //seems to be always on
wbdwip.VCXO = frm[5] >> 7; //locked unlocked, 0 is locked

}
else if(frm[3] % 4 == 2){

wbdwip.AGC = frm[4] >> 5 & 0b1; //AGC MAN/AUTO 0 for Auto, 1 for Manual
wbdwip.gainlevel = frm[4] >> 1 & 0b1111; // Gain, 16steps as per 3.2.2.4-1
wbdwip.antennaselect = (frm[5] >> 4) & 0b11; // 0 Ez, 1 Bz, 2 By, 3 Ey
wbdwip.convfreq = (frm[5] >> 2) & 0b11; // conversion freq, 0, 125.454, 250.908, 501.816k
wbdwip.hgagc = frm[5] & 0b11; //Higher AGC select

}
else if(frm[3] % 4 == 3){
wbdwip.commands = frm[5] >> 5 & 0b1; // Command Status (0=No cmds; 1=Cmds received)
wbdwip.OBDH = frm[5] >> 6 & 0b1; // OBDH Interface (0=Primary; 1=Redundant)
wbdwip.ADpower = frm[5] >> 4 & 0b1; //seems to be always on
wbdwip.VCXO = frm[5] >> 7; //locked unlocked, 0 is locked
wbdwip.outputmode = frm[4] >> 2 & 0b111; // sampling rate, bit depth, duty cycle as per 3.2.2.5-1
wbdwip.lwagc = frm[4] & 0b11; //Lower AGC select
}
for(int i = 6; i < 1096; i++){
if(i != 88 && i != 89){
wbdwip.payload.push_back(frm[i]);
}
}
return outputframes;
}
}
3 changes: 3 additions & 0 deletions plugins/cluster_support/cluster/instruments/wbd_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ namespace cluster{
int hgagc = 0;
};
class WBDdecoder{
private:
MajorFrame wbdwip;

public:
std::vector<MajorFrame> work(uint8_t *frm);
};
Expand Down
47 changes: 42 additions & 5 deletions plugins/cluster_support/cluster/module_cluster_instruments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "products/products.h"
#include "products/dataset.h"
#include "common/simple_deframer.h"
#include "instruments/wbd_decoder.h"
#include "common/audio/audio_sink.h"

namespace cluster
{
Expand All @@ -21,8 +23,11 @@ namespace cluster

void CLUSTERInstrumentsDecoderModule::process()
{
if (input_data_type == DATA_FILE)
filesize = getFilesize(d_input_file);
std::ifstream data_in(d_input_file, std::ios::binary);
std::ifstream data_in;
if (input_data_type == DATA_FILE)
data_in = std::ifstream(d_input_file, std::ios::binary);

logger->info("Using input frames " + d_input_file);

Expand All @@ -35,12 +40,28 @@ namespace cluster
def::SimpleDeframer wbddeframer(0xFAF334, 24, 8768, 0);


std::ofstream output("file.ccsds");
std::ofstream output("file.ccsds");
WBDdecoder wbddecode;

while (!data_in.eof())

bool enable_audio = false;
std::shared_ptr<audio::AudioSink> audio_sink;
if (input_data_type != DATA_FILE && audio::has_sink())
{
enable_audio = true;
audio_sink = audio::get_default_sink();
audio_sink->set_samplerate(27443);
audio_sink->start();
}

while (input_data_type == DATA_FILE ? !data_in.eof() : input_active.load())
{
if (input_data_type == DATA_FILE)
data_in.read((char *)&cadu, 1279);
else
input_fifo->read((uint8_t *)&cadu, 1279);

// Read buffer
data_in.read((char *)&cadu, 1279);

// Parse this transport frame
ccsds::ccsds_standard::VCDU vcdu = ccsds::ccsds_standard::parseVCDU(cadu);
Expand All @@ -55,7 +76,22 @@ namespace cluster
{
std::vector<std::vector<uint8_t>> minorframes = wbddeframer.work(pkt.payload.data(), pkt.payload.size());
for(auto &frm : minorframes){
output.write((char *)frm.data(),frm.size());
std::vector<MajorFrame> majorframes = wbddecode.work(frm.data());
for(auto &majorframe : majorframes){
int16_t audiobuf[4352];
for(int i = 0; i < 4352; i++){
audiobuf[i] = (int(majorframe.payload[i]) - 127) * 255;
}

if(enable_audio){
audio_sink->push_samples(audiobuf,4352);
}
if(majorframe.VCXO == 0 && majorframe.antennaselect == 0){
output.write((char *)majorframe.payload.data(),majorframe.payload.size());


}
}
}
}
}
Expand All @@ -67,6 +103,7 @@ namespace cluster
logger->info("Progress " + std::to_string(round(((double)progress / (double)filesize) * 1000.0) / 10.0) + "%%");
}
}
if (input_data_type == DATA_FILE)

data_in.close();

Expand Down
4 changes: 3 additions & 1 deletion plugins/cluster_support/cluster/module_cluster_instruments.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "core/module.h"

#include "instruments/wbd_decoder.h"

namespace cluster
{
namespace instruments
Expand All @@ -14,7 +16,7 @@ namespace cluster

// Readers
//cips::CIPSReader cips_readers[4];

//totally not stolen AIM decoder.....
// Statuses
//instrument_status_t cips_status[4] = {DECODING, DECODING, DECODING, DECODING};

Expand Down

0 comments on commit 92c37aa

Please sign in to comment.