Instrument Neutral Distributed Interface INDI 2.2.5
transforms.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*******************************************************************************/
18
19#include "transforms.h"
21#include "indicom.h"
22#include "indilogger.h"
23#include "dsp.h"
24
25#include <dirent.h>
26#include <cerrno>
27#include <cstring>
28#include <algorithm>
29#include <thread>
30#include <chrono>
31
32namespace DSP
33{
34
36{
37}
38
42
43bool FourierTransform::processBLOB(uint8_t *buf, uint32_t dims, int *sizes, int bits_per_sample)
44{
45 if(!PluginActive) return false;
46 setStream(buf, dims, sizes, bits_per_sample);
47
50}
51
53{
54 IUFillBLOB(&DownloadB, "PHASE_DOWNLOAD", "Phase", "");
55 IUFillBLOBVector(&DownloadBP, &FitsB, 1, m_Device->getDeviceName(), "PHASE", "Phase Data", DSP_TAB, IP_RW, 60, IPS_IDLE);
56}
57
61
67
73
74bool InverseFourierTransform::processBLOB(uint8_t *buf, uint32_t dims, int *sizes, int bits_per_sample)
75{
76 if(!PluginActive) return false;
77 if(!phase_loaded) return false;
78 setStream(buf, dims, sizes, bits_per_sample);
79 if (phase->dims != stream->dims) return false;
80 for (int d = 0; d < stream->dims; d++)
81 if (phase->sizes[d] != stream->sizes[d])
82 return false;
83 setMagnitude(buf, dims, sizes, bits_per_sample);
84 stream->phase = phase;
87 return Interface::processBLOB(getStream(), stream->dims, stream->sizes, bits_per_sample);
88}
89
90bool InverseFourierTransform::ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
91 char *formats[], char *names[], int n)
92{
93 if(!strcmp(dev, getDeviceName()))
94 {
95 if(!strcmp(name, DownloadBP.name))
96 {
97 IUUpdateBLOB(&DownloadBP, sizes, blobsizes, blobs, formats, names, n);
98 LOGF_INFO("Received phase BLOB for %s", getDeviceName());
99 if(phase != nullptr)
100 {
102 dsp_stream_free(phase);
103 }
104 phase = loadFITS(blobs[0], sizes[0]);
105 if (phase != nullptr)
106 {
107 LOGF_INFO("Phase for %s loaded", getDeviceName());
108 phase_loaded = true;
109 return true;
110 }
111 }
112 }
113 return false;
114}
115
116Spectrum::Spectrum(INDI::DefaultDevice *dev) : Interface(dev, DSP_SPECTRUM, "SPECTRUM", "Spectrum")
117{
118}
119
123
124bool Spectrum::processBLOB(uint8_t *buf, uint32_t dims, int *sizes, int bits_per_sample)
125{
126 if(!PluginActive) return false;
127 setStream(buf, dims, sizes, bits_per_sample);
128
130 double *histo = dsp_stats_histogram(stream->magnitude, 4096);
131 return Interface::processBLOB(static_cast<uint8_t*>(static_cast<void*>(histo)), 1, new int{4096}, -64);
132}
133
134
135Histogram::Histogram(INDI::DefaultDevice *dev) : Interface(dev, DSP_HISTOGRAM, "HISTOGRAM", "Histogram")
136{
137}
138
142
143bool Histogram::processBLOB(uint8_t *buf, uint32_t dims, int *sizes, int bits_per_sample)
144{
145 if(!PluginActive) return false;
146 setStream(buf, dims, sizes, bits_per_sample);
147
148 double *histo = dsp_stats_histogram(stream, 4096);
149 return Interface::processBLOB(static_cast<uint8_t*>(static_cast<void*>(histo)), 1, new int{4096}, -64);
150}
151}
FourierTransform(INDI::DefaultDevice *dev)
virtual bool processBLOB(uint8_t *out, uint32_t dims, int *sizes, int bits_per_sample) override
processBLOB Propagate to Callback and generate BLOBs for parent device.
virtual bool processBLOB(uint8_t *out, uint32_t dims, int *sizes, int bits_per_sample) override
processBLOB Propagate to Callback and generate BLOBs for parent device.
Histogram(INDI::DefaultDevice *dev)
const char * getDeviceName()
uint8_t * getStream()
virtual void Activated()
Activated Called after activation from client application.
uint8_t * getMagnitude()
virtual bool processBLOB(uint8_t *buf, uint32_t ndims, int *dims, int bits_per_sample)
processBLOB Propagate to Callback and generate BLOBs for parent device.
dsp_stream_p stream
bool setStream(void *buf, uint32_t dims, int *sizes, int bits_per_sample)
INDI::DefaultDevice * m_Device
dsp_stream_p loadFITS(char *buf, int len)
loadFITS Converts FITS data into a dsp_stream structure pointer.
bool setMagnitude(void *buf, uint32_t dims, int *sizes, int bits_per_sample)
virtual void Deactivated()
Deactivated Called after deactivation from client application.
bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) override
void Deactivated() override
Deactivated Called after deactivation from client application.
virtual bool processBLOB(uint8_t *out, uint32_t dims, int *sizes, int bits_per_sample) override
processBLOB Propagate to Callback and generate BLOBs for parent device.
InverseFourierTransform(INDI::DefaultDevice *dev)
void Activated() override
Activated Called after activation from client application.
virtual bool processBLOB(uint8_t *out, uint32_t dims, int *sizes, int bits_per_sample) override
processBLOB Propagate to Callback and generate BLOBs for parent device.
Spectrum(INDI::DefaultDevice *dev)
const char * getDeviceName() const
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
struct dsp_stream_t * phase
Fourier transform phase.
Definition dsp.h:429
int * sizes
Sizes of each dimension.
Definition dsp.h:389
struct dsp_stream_t * magnitude
Fourier transform magnitude.
Definition dsp.h:427
int dims
Number of dimensions of the buffers.
Definition dsp.h:387
dsp_t * buf
buffer
Definition dsp.h:391
int len
The buffers length.
Definition dsp.h:385
#define dsp_buffer_set(buf, len, _val)
Fill the buffer with the passed value.
Definition dsp.h:831
DLL_EXPORT void dsp_stream_free(dsp_stream_p stream)
Free the DSP stream passed as argument.
Definition stream.c:167
DLL_EXPORT void dsp_stream_free_buffer(dsp_stream_p stream)
Free the buffer of the DSP Stream passed as argument.
Definition stream.c:112
DLL_EXPORT void dsp_fourier_idft(dsp_stream_p stream)
Perform an inverse discrete Fourier Transform of a dsp_stream.
Definition fft.c:173
DLL_EXPORT void dsp_fourier_dft(dsp_stream_p stream, int exp)
Perform a discrete Fourier Transform of a dsp_stream.
Definition fft.c:135
DLL_EXPORT double * dsp_stats_histogram(dsp_stream_p stream, int size)
Histogram of the inut stream.
Definition stats.c:22
@ IP_RW
Definition indiapi.h:184
@ IPS_IDLE
Definition indiapi.h:159
Implementations for common driver routines.
void IUFillBLOBVector(IBLOBVectorProperty *bvp, IBLOB *bp, int nbp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a BLOB vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:528
void IUFillBLOB(IBLOB *bp, const char *name, const char *label, const char *format)
Assign attributes for a BLOB property. The BLOB's data and auxiliary elements will be set to NULL.
Definition indidevapi.c:434
int IUUpdateBLOB(IBLOBVectorProperty *bvp, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Update all BLOB members in a BLOB vector property.
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
The DSP Namespace adds signal processing to INDI drivers. Primarily written for sensors and detectors...
const char * DSP_TAB
char name[MAXINDINAME]
Definition indiapi.h:473