Skip to content

Commit

Permalink
WIP: Expose seek and history adjustment endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BatchDrake committed Apr 5, 2024
1 parent d81a586 commit 2a732db
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 17 deletions.
63 changes: 63 additions & 0 deletions analyzer/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ struct suscan_analyzer_interface {
SUFLOAT (*get_measured_samp_rate) (const void *);
void (*get_source_time) (const void *, struct timeval *tv);
SUBOOL (*seek) (void *, const struct timeval *tv);
SUBOOL (*set_history_size) (void *, SUSCOUNT);
SUBOOL (*replay) (void *, SUBOOL);
SUBOOL (*register_baseband_filter) (
void *,
suscan_analyzer_baseband_filter_func_t func,
Expand Down Expand Up @@ -327,6 +329,35 @@ suscan_analyzer_seek(
return (self->iface->seek) (self->impl, tv);
}

/*!
* Requests changing the history allocation for real-time sources. If size
* is greater than 0, history gets automatically enabled. Otherwise, it is
* disabled.
* \param analyzer a pointer to the analyzer object
* \param size allocation size of the history, in bytes
* \return SU_TRUE if the request was delivered, SU_FALSE otherwise
* \author Gonzalo José Carracedo Carballal
*/
SUINLINE SUBOOL
suscan_analyzer_set_history_size(suscan_analyzer_t *self, SUSCOUNT size)
{
return (self->iface->set_history_size) (self->impl, size);
}

/*!
* Requests switching source history to replay mode. History size must be
* greater than zero in order for this request to work.
* \param analyzer a pointer to the analyzer object
* \param replay SU_TRUE to enable replay mode, SU_FALSE to return to
* real time capture mode.
* \return SU_TRUE if the request was delivered, SU_FALSE otherwise
* \author Gonzalo José Carracedo Carballal
*/
SUINLINE SUBOOL
suscan_analyzer_replay(suscan_analyzer_t *self, SUBOOL replay)
{
return (self->iface->replay) (self->impl, replay);
}

/*!
* Return a pointer to the current source information structure. This pointer
Expand Down Expand Up @@ -745,6 +776,37 @@ SUBOOL suscan_analyzer_set_throttle_async(
SUSCOUNT samp_rate,
uint32_t req_id);

/*!
* Requests changing the history allocation for real-time sources. If size
* is greater than 0, history gets automatically enabled. Otherwise, it is
* disabled.
* \param analyzer a pointer to the analyzer object
* \param size allocation size of the history, in bytes
* \param req_id arbitrary request identifier used to match responses
* \return SU_TRUE if the request was delivered, SU_FALSE otherwise
* \author Gonzalo José Carracedo Carballal
*/
SUBOOL suscan_analyzer_set_history_size_async(
suscan_analyzer_t *analyzer,
SUSCOUNT size,
uint32_t req_id);

/*!
* Requests switching source history to replay mode. History size must be
* greater than zero in order for this request to work.
* \param analyzer a pointer to the analyzer object
* \param replay SU_TRUE to enable replay mode, SU_FALSE to return to
* real time capture mode.
* \param req_id arbitrary request identifier used to match responses
* \return SU_TRUE if the request was delivered, SU_FALSE otherwise
* \author Gonzalo José Carracedo Carballal
*/
SUBOOL suscan_analyzer_replay_async(
suscan_analyzer_t *analyzer,
SUBOOL replay,
uint32_t req_id);


/*!
* For seekable sources (e.g. file replay), sets the current read position
* \param analyzer pointer to the analyzer object
Expand All @@ -758,6 +820,7 @@ SUBOOL suscan_analyzer_seek_async(
const struct timeval *pos,
uint32_t req_id);


/*!
* For channel analyzers, open a new inspector of a given class at a given
* frequency (asynchronous).
Expand Down
68 changes: 68 additions & 0 deletions analyzer/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,74 @@ suscan_analyzer_seek_async(
return ok;
}

SUBOOL
suscan_analyzer_set_history_size_async(
suscan_analyzer_t *analyzer,
SUSCOUNT size,
uint32_t req_id)
{
struct suscan_analyzer_history_size_msg *msg = NULL;
SUBOOL ok = SU_FALSE;

SU_TRYCATCH(
msg = malloc(sizeof(struct suscan_analyzer_throttle_msg)),
goto done);

msg->buffer_length = size;

if (!suscan_analyzer_write(
analyzer,
SUSCAN_ANALYZER_MESSAGE_TYPE_HISTORY_SIZE,
msg)) {
SU_ERROR("Failed to send throttle command\n");
goto done;
}

msg = NULL;

ok = SU_TRUE;

done:
if (msg != NULL)
free(msg);

return ok;
}

SUBOOL
suscan_analyzer_replay_async(
suscan_analyzer_t *analyzer,
SUBOOL replay,
uint32_t req_id)
{
struct suscan_analyzer_replay_msg *msg = NULL;
SUBOOL ok = SU_FALSE;

SU_TRYCATCH(
msg = malloc(sizeof(struct suscan_analyzer_throttle_msg)),
goto done);

msg->replay = replay;

if (!suscan_analyzer_write(
analyzer,
SUSCAN_ANALYZER_MESSAGE_TYPE_REPLAY,
msg)) {
SU_ERROR("Failed to send throttle command\n");
goto done;
}

msg = NULL;

ok = SU_TRUE;

done:
if (msg != NULL)
free(msg);

return ok;
}

/****************************** Inspector methods ****************************/
SUBOOL
suscan_analyzer_open_ex_async(
Expand Down
35 changes: 35 additions & 0 deletions analyzer/impl/local.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ suscan_analyzer_thread(void *data)
const struct suscan_analyzer_params *new_params;
const struct suscan_analyzer_throttle_msg *throttle;
const struct suscan_analyzer_seek_msg *seek;
const struct suscan_analyzer_history_size_msg *history_size;
const struct suscan_analyzer_replay_msg *replay;

void *private = NULL;
uint32_t type;
SUBOOL mutex_acquired = SU_FALSE;
Expand Down Expand Up @@ -272,6 +275,20 @@ suscan_analyzer_thread(void *data)
goto done);
break;

case SUSCAN_ANALYZER_MESSAGE_TYPE_HISTORY_SIZE:
history_size = (const struct suscan_analyzer_history_size_msg *) private;
SU_TRYCATCH(
suscan_local_analyzer_slow_set_history_size(self, history_size->buffer_length),
goto done);
break;

case SUSCAN_ANALYZER_MESSAGE_TYPE_REPLAY:
replay = (const struct suscan_analyzer_replay_msg *) private;
SU_TRYCATCH(
suscan_local_analyzer_slow_set_replay(self, replay->replay),
goto done);
break;

/* Forward these messages to output */
case SUSCAN_ANALYZER_MESSAGE_TYPE_EOS:
case SUSCAN_ANALYZER_MESSAGE_TYPE_CHANNEL:
Expand Down Expand Up @@ -748,6 +765,22 @@ suscan_local_analyzer_seek(void *ptr, const struct timeval *pos)
return suscan_local_analyzer_slow_seek(self, pos);
}

SUPRIVATE SUBOOL
suscan_local_analyzer_set_history_size(void *ptr, SUSCOUNT size)
{
suscan_local_analyzer_t *self = (suscan_local_analyzer_t *) ptr;

return suscan_local_analyzer_slow_set_history_size(self, size);
}

SUPRIVATE SUBOOL
suscan_local_analyzer_replay(void *ptr, SUBOOL replay)
{
suscan_local_analyzer_t *self = (suscan_local_analyzer_t *) ptr;

return suscan_local_analyzer_slow_set_replay(self, replay);
}


SUPRIVATE SUBOOL
suscan_local_analyzer_set_gain(void *ptr, const char *name, SUFLOAT value)
Expand Down Expand Up @@ -1125,6 +1158,8 @@ suscan_local_analyzer_get_interface(void)
SET_CALLBACK(get_samp_rate);
SET_CALLBACK(get_source_time);
SET_CALLBACK(seek);
SET_CALLBACK(set_history_size);
SET_CALLBACK(replay);
SET_CALLBACK(register_baseband_filter);
SET_CALLBACK(get_measured_samp_rate);
SET_CALLBACK(get_source_info_pointer);
Expand Down
14 changes: 10 additions & 4 deletions analyzer/impl/local.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ struct suscan_local_analyzer {
SUBOOL seek_req;
SUSCOUNT seek_req_value; /* The seek request is a sample number */

/* Replay request */
SUBOOL replay_req;
SUBOOL replay_req_state; /* Whether or not enable replay */

/* XXX: Define list for inspector frequency set */
SUBOOL inspector_freq_req;
SUHANDLE inspector_freq_req_handle;
Expand Down Expand Up @@ -271,6 +267,16 @@ SUBOOL suscan_local_analyzer_slow_seek(
suscan_local_analyzer_t *self,
const struct timeval *tv);

/* Internal */
SUBOOL suscan_local_analyzer_slow_set_history_size(
suscan_local_analyzer_t *self,
SUSCOUNT size);

/* Internal */
SUBOOL suscan_local_analyzer_slow_set_replay(
suscan_local_analyzer_t *self,
SUBOOL replay);

/* Internal */
SUBOOL suscan_local_analyzer_slow_set_dc_remove(
suscan_local_analyzer_t *analyzer,
Expand Down
19 changes: 19 additions & 0 deletions analyzer/impl/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,23 @@ suscan_remote_analyzer_seek(void *ptr, const struct timeval *tv)
return suscan_analyzer_seek_async(self->parent, tv, 0);
}

SUPRIVATE SUBOOL
suscan_remote_analyzer_set_history_size(void *ptr, SUSCOUNT size)
{
suscan_remote_analyzer_t *self = (suscan_remote_analyzer_t *) ptr;

return suscan_analyzer_set_history_size_async(self->parent, size, 0);
}


SUPRIVATE SUBOOL
suscan_remote_analyzer_replay(void *ptr, SUBOOL replay)
{
suscan_remote_analyzer_t *self = (suscan_remote_analyzer_t *) ptr;

return suscan_analyzer_replay_async(self->parent, replay, 0);
}

SUPRIVATE struct suscan_source_info *
suscan_remote_analyzer_get_source_info_pointer(const void *ptr)
{
Expand Down Expand Up @@ -2705,6 +2722,8 @@ suscan_remote_analyzer_get_interface(void)
SET_CALLBACK(get_samp_rate);
SET_CALLBACK(get_source_time);
SET_CALLBACK(seek);
SET_CALLBACK(set_history_size);
SET_CALLBACK(replay);
SET_CALLBACK(get_measured_samp_rate);
SET_CALLBACK(get_source_info_pointer);
SET_CALLBACK(commit_source_info);
Expand Down
2 changes: 1 addition & 1 deletion analyzer/impl/remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern "C" {

#define SUSCAN_REMOTE_PROTOCOL_TOKEN_SIZE SHA256_BLOCK_SIZE
#define SUSCAN_REMOTE_PROTOCOL_MAJOR_VERSION 0
#define SUSCAN_REMOTE_PROTOCOL_MINOR_VERSION 10
#define SUSCAN_REMOTE_PROTOCOL_MINOR_VERSION 11

#define SUSCAN_REMOTE_AUTH_MODE_NONE 0
#define SUSCAN_REMOTE_AUTH_MODE_USER_PASSWORD 1
Expand Down
47 changes: 40 additions & 7 deletions analyzer/slow.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <analyzer/impl/local.h>
#include <analyzer/msg.h>
#include <string.h>
#include <inttypes.h>

/*
* Some tasks take some time to complete, time that is several orders of
Expand Down Expand Up @@ -179,6 +180,16 @@ suscan_local_analyzer_set_dc_remove_cb(
return SU_FALSE;
}

SUPRIVATE void
suscan_local_analyzer_copy_source_history_info(suscan_local_analyzer_t *self)
{
const struct suscan_source_info *info = suscan_source_get_info(self->source);
struct suscan_source_info *localinfo = &self->source_info;

localinfo->history_length = info->history_length;
localinfo->replay = info->replay;
}

SUPRIVATE SUBOOL
suscan_local_analyzer_set_history_size_cb(
struct suscan_mq *mq_out,
Expand All @@ -188,11 +199,35 @@ suscan_local_analyzer_set_history_size_cb(
suscan_local_analyzer_t *analyzer = (suscan_local_analyzer_t *) wk_private;
SUSCOUNT size = (SUSCOUNT) (uintptr_t) cb_private;

/* TODO: Implement me! */
(void) suscan_source_set_history_alloc(analyzer->source, size);

if (size > 0)
suscan_source_set_history_enabled(analyzer->source, SU_TRUE);

suscan_local_analyzer_copy_source_history_info(analyzer);

suscan_analyzer_send_source_info(analyzer->parent, &analyzer->source_info);

return SU_FALSE;
}

SUPRIVATE SUBOOL
suscan_local_analyzer_set_replay_cb(
struct suscan_mq *mq_out,
void *wk_private,
void *cb_private)
{
suscan_local_analyzer_t *analyzer = (suscan_local_analyzer_t *) wk_private;
SUBOOL replay = (SUBOOL) (uintptr_t) cb_private;

(void) suscan_source_set_replay_enabled(analyzer->source, replay);

suscan_local_analyzer_copy_source_history_info(analyzer);

suscan_analyzer_send_source_info(analyzer->parent, &analyzer->source_info);

return SU_FALSE;
}

SUPRIVATE SUBOOL
suscan_local_analyzer_set_agc_cb(
Expand Down Expand Up @@ -662,11 +697,10 @@ suscan_local_analyzer_slow_set_replay(
self->parent->params.mode == SUSCAN_ANALYZER_MODE_CHANNEL,
return SU_FALSE);

self->replay_req_state = replay;
self->replay_req = SU_TRUE;

/* This request is to be processed by the source thread */
return SU_TRUE;
return suscan_worker_push(
self->slow_wk,
suscan_local_analyzer_set_replay_cb,
(void *) (uintptr_t) replay);
}

SUBOOL
Expand All @@ -684,7 +718,6 @@ suscan_local_analyzer_slow_set_history_size(
(void *) (uintptr_t) size);
}


SUBOOL
suscan_local_analyzer_slow_set_dc_remove(
suscan_local_analyzer_t *analyzer,
Expand Down
Loading

0 comments on commit 2a732db

Please sign in to comment.