Support both legacy and new PMT messages at the file sink

To allow easier integration to the new architecture the
multi format file sink supports bot legacy and the new
format of the PMT messages. In poth cases, only the PDU
is extracted. Legacy used the PDU as a BLOB, whereas
now the PDU is stored in base64 format inside a
dictionary, which structure is defined through
the gr::satnogs::metadata() class
This commit is contained in:
Manolis Surligas 2019-09-26 17:35:33 +03:00
parent 7a95b44475
commit 2cc9184fbc
2 changed files with 49 additions and 19 deletions

View File

@ -46,9 +46,9 @@ endif(NOT CMAKE_BUILD_TYPE)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)
# Set the version information here
set(VERSION_INFO_MAJOR_VERSION 1)
set(VERSION_INFO_API_COMPAT 5)
set(VERSION_INFO_MINOR_VERSION 1)
set(VERSION_INFO_MAJOR_VERSION 2)
set(VERSION_INFO_API_COMPAT 0)
set(VERSION_INFO_MINOR_VERSION 0)
set(VERSION_INFO_MAINT_VERSION git)
# Set cmake policies.

View File

@ -2,7 +2,7 @@
/*
* gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
*
* Copyright (C) 2016,2017 Libre Space Foundation <http://librespacefoundation.org/>
* Copyright (C) 2016,2017,2019 Libre Space Foundation <http://libre.space>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -24,6 +24,8 @@
#include <gnuradio/io_signature.h>
#include "multi_format_msg_sink_impl.h"
#include <satnogs/base64.h>
#include <satnogs/metadata.h>
#include <ctime>
#include <iostream>
#include <iomanip>
@ -45,10 +47,26 @@ multi_format_msg_sink::make(size_t format,
void
multi_format_msg_sink_impl::msg_handler_file(pmt::pmt_t msg)
{
uint8_t *su;
const uint8_t *su;
size_t len;
std::string s;
char buf[256];
std::string s((const char *) pmt::blob_data(msg),
pmt::blob_length(msg));
/* Check if the message contains the legacy or the new format */
if (pmt::is_dict(msg)) {
pmt::pmt_t pdu = pmt::dict_ref(msg, pmt::mp(metadata::value(metadata::PDU)),
pmt::PMT_NIL);
std::string d = base64_decode(std::string((const char *) pmt::blob_data(pdu),
pmt::blob_length(pdu)));
su = (const uint8_t *) pmt::blob_data(pdu), pmt::blob_length(pdu);
s = std::string((const char *) pmt::blob_data(pdu), pmt::blob_length(pdu));
len = pmt::blob_length(pdu);
}
else {
su = (const uint8_t *) pmt::blob_data(msg), pmt::blob_length(msg);
s = std::string((const char *) pmt::blob_data(msg), pmt::blob_length(msg));
len = pmt::blob_length(msg);
}
if (d_timestamp) {
std::time_t t = std::time(nullptr);
@ -62,16 +80,14 @@ multi_format_msg_sink_impl::msg_handler_file(pmt::pmt_t msg)
d_fos << s << std::endl;
break;
case 1:
su = (uint8_t *) pmt::blob_data(msg);
for (size_t i = 0; i < pmt::blob_length(msg); i++) {
for (size_t i = 0; i < len; i++) {
d_fos << "0x" << std::hex << std::setw(2) << std::setfill('0')
<< (uint32_t) su[i] << " ";
}
d_fos << std::endl;
break;
case 2:
su = (uint8_t *) pmt::blob_data(msg);
for (size_t i = 0; i < pmt::blob_length(msg); i++) {
for (size_t i = 0; i < len; i++) {
d_fos << "0b" << std::bitset<8> (su[i]) << " ";
}
d_fos << std::endl;
@ -84,10 +100,26 @@ multi_format_msg_sink_impl::msg_handler_file(pmt::pmt_t msg)
void
multi_format_msg_sink_impl::msg_handler_stdout(pmt::pmt_t msg)
{
uint8_t *su;
const uint8_t *su;
size_t len;
std::string s;
char buf[256];
std::string s((const char *) pmt::blob_data(msg),
pmt::blob_length(msg));
/* Check if the message contains the legacy or the new format */
if (pmt::is_dict(msg)) {
pmt::pmt_t pdu = pmt::dict_ref(msg, pmt::mp(metadata::value(metadata::PDU)),
pmt::PMT_NIL);
std::string d = base64_decode(std::string((const char *) pmt::blob_data(pdu),
pmt::blob_length(pdu)));
su = (const uint8_t *) pmt::blob_data(pdu), pmt::blob_length(pdu);
s = std::string((const char *) pmt::blob_data(pdu), pmt::blob_length(pdu));
len = pmt::blob_length(pdu);
}
else {
su = (const uint8_t *) pmt::blob_data(msg), pmt::blob_length(msg);
s = std::string((const char *) pmt::blob_data(msg), pmt::blob_length(msg));
len = pmt::blob_length(msg);
}
if (d_timestamp) {
std::time_t t = std::time(nullptr);
@ -98,22 +130,20 @@ multi_format_msg_sink_impl::msg_handler_stdout(pmt::pmt_t msg)
switch (d_format) {
case 0: // binary
for (size_t i = 0; i < pmt::blob_length(msg); i++) {
for (size_t i = 0; i < len; i++) {
std::cout << s[i];
}
std::cout << std::endl;
break;
case 1: // hex annotated
su = (uint8_t *) pmt::blob_data(msg);
for (size_t i = 0; i < pmt::blob_length(msg); i++) {
for (size_t i = 0; i < len; i++) {
std::cout << "0x" << std::hex << std::setw(2) << std::setfill('0')
<< (uint32_t) su[i] << " ";
}
std::cout << std::endl;
break;
case 2: // binary annotated
su = (uint8_t *) pmt::blob_data(msg);
for (size_t i = 0; i < pmt::blob_length(msg); i++) {
for (size_t i = 0; i < len; i++) {
std::cout << "0b" << std::bitset<8> (su[i]) << " ";
}
std::cout << std::endl;