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 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
From 277c682b5cbf2e3766c3144b22ee6ad1e362bd73 Mon Sep 17 00:00:00 2001
From: schneider <[email protected]>
Date: Fri, 8 Oct 2021 02:59:10 0200
Subject: [PATCH 22/31] sigmf: Use QT to parse the json
---
src/CMakeLists.txt | 11 -----
src/inputsource.cpp | 110 -----------------
2 files changed, 69 insertions( ), 52 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3bdffde..05b20e7 100644
--- a/src/CMakeLists.txt
b/src/CMakeLists.txt
@@ -56,7 56,6 @@ find_package(Qt5Widgets REQUIRED)
find_package(Qt5Concurrent REQUIRED)
find_package(FFTW REQUIRED)
find_package(Liquid REQUIRED)
-find_package(libsigmf QUIET)
include_directories(
${FFTW_INCLUDES}
@@ -71,16 70,6 @@ target_link_libraries(inspectrum
${LIQUID_LIBRARIES}
)
-if (libsigmf_FOUND)
- message("-- libsigmf found. Enabling SigMF support")
- target_link_libraries(inspectrum
- libsigmf::libsigmf
- )
- add_definitions(-DENABLE_SIGMF)
-else()
- message("-- libsigmf not found. Disabling SigMF support")
-endif()
-
set(INSTALL_DEFAULT_BINDIR "bin" CACHE STRING "Appended to CMAKE_INSTALL_PREFIX")
install(TARGETS inspectrum RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
diff --git a/src/inputsource.cpp b/src/inputsource.cpp
index 201d7fe..86b2fd5 100644
--- a/src/inputsource.cpp
b/src/inputsource.cpp
@@ -29,10 29,6 @@
#include <QFileInfo>
-#if ENABLE_SIGMF
-#include <sigmf/sigmf.h>
-#endif
-
#include <QElapsedTimer>
#include <QPainter>
#include <QPaintEvent>
@@ -196,7 192,6 @@ void InputSource::cleanup()
}
}
-#if ENABLE_SIGMF
void InputSource::readMetaData(const QString &filename)
{
QFile datafile(filename);
@@ -204,64 199,103 @@ void InputSource::readMetaData(const QString &filename)
throw std::runtime_error("Error while opening meta data file: " datafile.errorString().toStdString());
}
- sigmf::SigMF<sigmf::Global<core::DescrT>,
- sigmf::Capture<core::DescrT>,
- sigmf::Annotation<core::DescrT> > metaData = json::parse(datafile.readAll());
QJsonDocument d = QJsonDocument::fromJson(datafile.readAll());
datafile.close();
auto root = d.object();
if(!root.contains("global") || !root["global"].isObject()) {
throw std::runtime_error("SigMF meta data is invalid (no global object found)");
}
auto global = root["global"].toObject();
if(!global.contains("core:datatype") || !global["core:datatype"].isString()) {
throw std::runtime_error("SigMF meta data does not specify a valid datatype");
}
- auto global_core = metaData.global.access<core::GlobalT>();
- if(global_core.datatype.compare("cf32_le") == 0) {
auto datatype = global["core:datatype"].toString();
if(datatype.compare("cf32_le") == 0) {
sampleAdapter = std::make_unique<ComplexF32SampleAdapter>();
- } else if(global_core.datatype.compare("ci16_le") == 0) {
} else if(datatype.compare("ci16_le") == 0) {
sampleAdapter = std::make_unique<ComplexS16SampleAdapter>();
- } else if(global_core.datatype.compare("ci8") == 0) {
} else if(datatype.compare("ci8") == 0) {
sampleAdapter = std::make_unique<ComplexS8SampleAdapter>();
- } else if(global_core.datatype.compare("cu8") == 0) {
} else if(datatype.compare("cu8") == 0) {
sampleAdapter = std::make_unique<ComplexU8SampleAdapter>();
- } else if(global_core.datatype.compare("rf32_le") == 0) {
} else if(datatype.compare("rf32_le") == 0) {
sampleAdapter = std::make_unique<RealF32SampleAdapter>();
_realSignal = true;
- } else if(global_core.datatype.compare("ri16_le") == 0) {
} else if(datatype.compare("ri16_le") == 0) {
sampleAdapter = std::make_unique<RealS16SampleAdapter>();
_realSignal = true;
- } else if(global_core.datatype.compare("ri8") == 0) {
} else if(datatype.compare("ri8") == 0) {
sampleAdapter = std::make_unique<RealS8SampleAdapter>();
_realSignal = true;
- } else if(global_core.datatype.compare("ru8") == 0) {
} else if(datatype.compare("ru8") == 0) {
sampleAdapter = std::make_unique<RealU8SampleAdapter>();
_realSignal = true;
} else {
throw std::runtime_error("SigMF meta data specifies unsupported datatype");
}
- setSampleRate(global_core.sample_rate);
if(global.contains("core:sample_rate") && global["core:sample_rate"].isDouble()) {
setSampleRate(global["core:sample_rate"].toDouble());
}
- for(auto capture : metaData.captures) {
- auto core = capture.access<core::CaptureT>();
- frequency = core.frequency;
if(root.contains("captures") && root["captures"].isArray()) {
auto captures = root["captures"].toArray();
for(auto capture_ref : captures) {
if(capture_ref.isObject()) {
auto capture = capture_ref.toObject();
if(capture.contains("core:frequency") && capture["core:frequency"].isDouble()) {
frequency = capture["core:frequency"].toDouble();
}
} else {
throw std::runtime_error("SigMF meta data is invalid (invalid capture object)");
}
}
}
- for(auto annotation : metaData.annotations) {
- Annotation a;
- auto core = annotation.access<core::AnnotationT>();
if(root.contains("annotations") && root["annotations"].isArray()) {
- const size_t offset = global_core.offset;
- const size_t sample_start = core.sample_start;
size_t offset = 0;
- if (sample_start < offset)
- continue;
if(global.contains("core:offset")) {
offset = global["offset"].toDouble();
}
- const size_t rel_sample_start = sample_start - offset;
auto annotations = root["annotations"].toArray();
- a.sampleRange = range_t<size_t>{rel_sample_start, rel_sample_start core.sample_count - 1};
- a.frequencyRange = range_t<double>{core.freq_lower_edge, core.freq_upper_edge};
- a.description = QString::fromStdString(core.description);
for(auto annotation_ref : annotations) {
if(annotation_ref.isObject()) {
auto sigmf_annotation = annotation_ref.toObject();
- annotationList.append(a);
Annotation a;
const size_t sample_start = sigmf_annotation["core:sample_start"].toDouble();
if (sample_start < offset)
continue;
const size_t rel_sample_start = sample_start - offset;
const size_t sample_count = sigmf_annotation["core:sample_count"].toDouble();
a.sampleRange = range_t<size_t>{rel_sample_start, rel_sample_start sample_count - 1};
const double freq_lower_edge = sigmf_annotation["core:freq_lower_edge"].toDouble();
const double freq_upper_edge = sigmf_annotation["core:freq_upper_edge"].toDouble();
a.frequencyRange = range_t<double>{freq_lower_edge, freq_upper_edge};
a.description = sigmf_annotation["core:description"].toString();
annotationList.append(a);
}
}
}
}
-#endif
-
void InputSource::openFile(const char *filename)
{
@@ -302,7 336,6 @@ void InputSource::openFile(const char *filename)
QString dataFilename;
-#if ENABLE_SIGMF
annotationList.clear();
QString metaFilename;
@@ -319,11 352,6 @@ void InputSource::openFile(const char *filename)
else if (suffix == "sigmf") {
throw std::runtime_error("SigMF archives are not supported. Consider extracting a recording.");
}
-#else
- if (suffix == "sigmf-meta" || suffix == "sigmf-data" || suffix == "sigmf") {
- throw std::runtime_error("Support for SigMF recordings is not enabled");
- }
-#endif
else {
dataFilename = filename;
}
--
2.35.1
|