27 #define SPECTRUM_SIZE (256)
29 ({ __typeof__ (a) _a = (a); \
30 __typeof__ (b) _b = (b); \
33 static pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
34 static pthread_mutex_t condMutex = PTHREAD_MUTEX_INITIALIZER;
40 terminateThread =
false;
53 LOG_INFO(
"Simulator Receiver connected successfully!");
59 terminateThread =
false;
74 pthread_mutex_lock(&condMutex);
76 terminateThread =
true;
77 pthread_cond_signal(&cv);
78 pthread_mutex_unlock(&condMutex);
79 LOG_INFO(
"Simulator Receiver disconnected successfully!");
88 return "Receiver Simulator";
103 setMinMaxStep(
"SENSOR_INTEGRATION",
"SENSOR_INTEGRATION_VALUE", 0.001, 86164.092, 0.001,
false);
104 setMinMaxStep(
"RECEIVER_SETTINGS",
"RECEIVER_FREQUENCY", 2.4e+7, 2.0e+9, 1,
false);
105 setMinMaxStep(
"RECEIVER_SETTINGS",
"RECEIVER_SAMPLERATE", 1.0e+6, 2.0e+6, 1,
false);
106 setMinMaxStep(
"RECEIVER_SETTINGS",
"RECEIVER_GAIN", 0.0, 25.0, 0.1,
false);
107 setMinMaxStep(
"RECEIVER_SETTINGS",
"RECEIVER_BANDWIDTH", 0, 0, 0,
false);
108 setMinMaxStep(
"RECEIVER_SETTINGS",
"RECEIVER_BITSPERSAMPLE", 16, 16, 0,
false);
127 setupParams(1000000, 1420000000, 10000, 10);
139 void RadioSim::setupParams(
float sr,
float freq,
float bw,
float gain)
154 for(
int i = 0; i < n; i++)
156 if (!strcmp(names[i],
"RECEIVER_GAIN"))
160 else if (!strcmp(names[i],
"RECEIVER_BANDWIDTH"))
164 else if (!strcmp(names[i],
"RECEIVER_FREQUENCY"))
168 else if (!strcmp(names[i],
"RECEIVER_SAMPLERATE"))
183 IntegrationRequest = duration;
193 gettimeofday(&CapStart,
nullptr);
219 float RadioSim::CalcTimeLeft()
224 gettimeofday(&now,
nullptr);
226 timesince = (double)(now.tv_sec * 1000.0 + now.tv_usec / 1000) -
227 (double)(CapStart.tv_sec * 1000.0 + CapStart.tv_usec / 1000);
228 timesince = timesince / 1000;
230 timeleft = IntegrationRequest - timesince;
246 timeleft = CalcTimeLeft();
250 LOG_INFO(
"Integration done, expecting data...");
279 for(
int i = 0; i < size; i++)
280 continuum[i] = rand() % 255;
291 pthread_mutex_lock(&condMutex);
293 pthread_mutex_unlock(&condMutex);
294 pthread_cond_signal(&cv);
301 pthread_mutex_lock(&condMutex);
303 pthread_mutex_unlock(&condMutex);
304 pthread_cond_signal(&cv);
311 struct itimerval tframe1, tframe2;
313 getitimer(ITIMER_REAL, &tframe1);
314 auto s1 = ((double)tframe2.it_value.tv_sec) + ((double)tframe2.it_value.tv_usec / 1e6);
315 auto s2 = ((double)tframe2.it_value.tv_sec) + ((double)tframe2.it_value.tv_usec / 1e6);
319 pthread_mutex_lock(&condMutex);
321 while (streamPredicate == 0)
323 pthread_cond_wait(&cv, &condMutex);
331 pthread_mutex_unlock(&condMutex);
336 getitimer(ITIMER_REAL, &tframe1);
338 s2 = ((double)tframe2.it_value.tv_sec) + ((double)tframe2.it_value.tv_usec / 1e6);
339 deltas = fabs(s2 - s1);
347 s1 = ((double)tframe1.it_value.tv_sec) + ((double)tframe1.it_value.tv_usec / 1e6);
349 getitimer(ITIMER_REAL, &tframe2);
352 pthread_mutex_unlock(&condMutex);
const char * getDeviceName() const
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void setGain(double gain)
setGain Set gain of Receiver device.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void setBandwidth(double bandwidth)
setBandwidth Set bandwidth of Receiver device.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
virtual void setMinMaxStep(const char *property, const char *element, double min, double max, double step, bool sendToClient=true) override
setMinMaxStep for a number property element
void setFrequency(double freq)
setFrequency Set the frequency observed.
INumberVectorProperty ReceiverSettingsNP
double getSampleRate()
getSampleRate Get requested sample rate for the sensor in Hz.
double getFrequency()
getFrequency Get requested integration frequency for the sensor in Hz.
double getBandwidth()
getBandwidth Get requested integration bandwidth for the sensor in Hz.
void setSampleRate(double sr)
setSampleRate Set depth of Receiver device.
double getGain()
getGain Get requested integration gain for the sensor.
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
void SetCapability(uint32_t cap)
SetCapability Set the Sensor capabilities. Al fields must be initialized.
void setBPS(int bps)
setBPP Set depth of Sensor device.
void setBufferSize(int nbuf, bool allocMem=true)
setBufferSize Set desired buffer size. The function will allocate memory accordingly....
void setIntegrationLeft(double duration)
setIntegrationLeft Update Integration time left. Inform the client of the new Integration time left v...
uint8_t * getBuffer()
getBuffer Get raw buffer of the stream of the Sensor device.
std::unique_ptr< StreamManager > Streamer
void setIntegrationTime(double duration)
setIntegrationTime Set desired Sensor frame Integration duration for next Integration....
int getBufferSize() const
getContinuumBufferSize Get allocated continuum buffer size to hold the Sensor integrationd stream.
virtual bool IntegrationComplete()
Uploads target Device exposed buffer as FITS to the client. Dervied classes should class this functio...
int getBPS() const
getBPS Get Sensor depth (bits per sample).
void setIntegrationFileExtension(const char *ext)
setIntegrationExtension Set integration exntension
double getIntegrationTime() const
getIntegrationTime Get requested Integration duration for the Sensor device in seconds.
void streamCaptureHelper()
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
const char * getDefaultName() override
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
bool Disconnect() override
Disconnect from device.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
bool StopStreaming() override
StopStreaming Stop live video streaming.
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
bool StartIntegration(double duration) override
Start integration from the Sensor device.
bool StartStreaming() override
StartStreaming Start live video streaming.
bool AbortIntegration() override
Abort ongoing Integration.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
std::unique_ptr< RadioSim > receiver(new RadioSim())