2023-10-20 20:18:23 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#define _XOPEN_SOURCE 700
|
|
|
|
#include <unistd.h>
|
2022-02-04 13:41:36 +00:00
|
|
|
#include <hamlib/config.h>
|
2021-11-28 18:52:29 +00:00
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "snapshot_data.h"
|
|
|
|
#include "hamlibdatetime.h"
|
2023-09-18 17:48:39 +00:00
|
|
|
#include "sprintflst.h"
|
2021-11-28 18:52:29 +00:00
|
|
|
|
|
|
|
#include "cJSON.h"
|
|
|
|
|
|
|
|
#define SPECTRUM_MODE_FIXED "FIXED"
|
|
|
|
#define SPECTRUM_MODE_CENTER "CENTER"
|
|
|
|
|
2023-11-05 22:42:02 +00:00
|
|
|
char snapshot_data_pid[20];
|
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig)
|
|
|
|
{
|
|
|
|
cJSON *node;
|
2023-09-18 17:48:39 +00:00
|
|
|
char buf[1024];
|
2021-11-30 07:25:51 +00:00
|
|
|
|
2023-10-22 18:18:51 +00:00
|
|
|
cJSON *id_node = cJSON_CreateObject();
|
|
|
|
cJSON_AddStringToObject(id_node, "model", rig->caps->model_name);
|
|
|
|
cJSON_AddStringToObject(id_node, "endpoint", rig->state.rigport.pathname);
|
2023-11-05 22:42:02 +00:00
|
|
|
cJSON_AddStringToObject(id_node, "process", snapshot_data_pid);
|
|
|
|
cJSON_AddStringToObject(id_node, "deviceId", rig->state.device_id);
|
2023-10-22 18:18:51 +00:00
|
|
|
cJSON_AddItemToObject(rig_node, "id", id_node);
|
|
|
|
|
2023-12-16 17:37:58 +00:00
|
|
|
node = cJSON_AddStringToObject(rig_node, "status",
|
|
|
|
rig_strcommstatus(rig->state.comm_status));
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
// TODO: need to store last error code
|
|
|
|
node = cJSON_AddStringToObject(rig_node, "errorMsg", "");
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddStringToObject(rig_node, "name", rig->caps->model_name);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddBoolToObject(rig_node, "split",
|
|
|
|
rig->state.cache.split == RIG_SPLIT_ON ? 1 : 0);
|
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddStringToObject(rig_node, "splitVfo",
|
|
|
|
rig_strvfo(rig->state.cache.split_vfo));
|
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddBoolToObject(rig_node, "satMode",
|
|
|
|
rig->state.cache.satmode ? 1 : 0);
|
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-09-18 17:48:39 +00:00
|
|
|
rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list);
|
2023-10-22 18:18:51 +00:00
|
|
|
char *p;
|
|
|
|
cJSON *modes_array = cJSON_CreateArray();
|
2023-12-16 17:37:58 +00:00
|
|
|
|
|
|
|
for (p = strtok(buf, " "); p; p = strtok(NULL, " "))
|
2023-09-18 17:48:39 +00:00
|
|
|
{
|
2023-12-16 17:37:58 +00:00
|
|
|
if (strlen(buf) > 0)
|
|
|
|
{
|
2023-10-22 18:18:51 +00:00
|
|
|
cJSON *tmp = cJSON_CreateString(p);
|
|
|
|
cJSON_AddItemToArray(modes_array, tmp);
|
|
|
|
}
|
2023-09-18 17:48:39 +00:00
|
|
|
}
|
2023-12-16 17:37:58 +00:00
|
|
|
|
2023-10-22 18:18:51 +00:00
|
|
|
cJSON_AddItemToObject(rig_node, "modes", modes_array);
|
2023-12-16 17:37:58 +00:00
|
|
|
|
2023-10-20 21:25:21 +00:00
|
|
|
return RIG_OK;
|
2021-11-30 07:25:51 +00:00
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
error:
|
2022-02-13 22:17:41 +00:00
|
|
|
RETURNFUNC2(-RIG_EINTERNAL);
|
2021-11-30 07:25:51 +00:00
|
|
|
}
|
|
|
|
|
2023-10-22 18:18:51 +00:00
|
|
|
// 128 max modes should last a while
|
|
|
|
#define MAX_MODES 128
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
static int snapshot_serialize_vfo(cJSON *vfo_node, RIG *rig, vfo_t vfo)
|
|
|
|
{
|
|
|
|
freq_t freq;
|
|
|
|
int freq_ms, mode_ms, width_ms;
|
|
|
|
rmode_t mode;
|
2023-10-22 18:18:51 +00:00
|
|
|
//rmode_t modes[MAX_MODES];
|
2021-11-28 18:52:29 +00:00
|
|
|
pbwidth_t width;
|
|
|
|
ptt_t ptt;
|
|
|
|
split_t split;
|
|
|
|
vfo_t split_vfo;
|
|
|
|
int result;
|
|
|
|
int is_rx, is_tx;
|
|
|
|
cJSON *node;
|
|
|
|
|
|
|
|
// TODO: This data should match rig_get_info command response
|
|
|
|
|
|
|
|
node = cJSON_AddStringToObject(vfo_node, "name", rig_strvfo(vfo));
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
result = rig_get_cache(rig, vfo, &freq, &freq_ms, &mode, &mode_ms, &width,
|
|
|
|
&width_ms);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (result == RIG_OK)
|
|
|
|
{
|
|
|
|
node = cJSON_AddNumberToObject(vfo_node, "freq", freq);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
node = cJSON_AddStringToObject(vfo_node, "mode", rig_strrmode(mode));
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
node = cJSON_AddNumberToObject(vfo_node, "width", (double) width);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 20:11:19 +00:00
|
|
|
split = rig->state.cache.split;
|
|
|
|
split_vfo = rig->state.cache.split_vfo;
|
|
|
|
|
|
|
|
is_rx = (split == RIG_SPLIT_OFF && vfo == rig->state.current_vfo)
|
|
|
|
|| (split == RIG_SPLIT_ON && vfo != split_vfo);
|
|
|
|
is_tx = (split == RIG_SPLIT_OFF && vfo == rig->state.current_vfo)
|
|
|
|
|| (split == RIG_SPLIT_ON && vfo == split_vfo);
|
2023-11-09 17:26:56 +00:00
|
|
|
ptt = rig->state.cache.ptt && is_tx;
|
2023-10-27 20:11:19 +00:00
|
|
|
|
|
|
|
if (is_tx)
|
2023-11-07 07:55:30 +00:00
|
|
|
{
|
|
|
|
node = cJSON_AddBoolToObject(vfo_node, "ptt", ptt == RIG_PTT_OFF ? 0 : 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = cJSON_AddBoolToObject(vfo_node, "ptt", 0);
|
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node = cJSON_AddBoolToObject(vfo_node, "rx", is_rx);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddBoolToObject(vfo_node, "tx", is_tx);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-10-20 21:25:21 +00:00
|
|
|
return RIG_OK;
|
2021-11-28 18:52:29 +00:00
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
error:
|
2022-02-13 22:17:41 +00:00
|
|
|
RETURNFUNC2(-RIG_EINTERNAL);
|
2021-11-28 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
static int snapshot_serialize_spectrum(cJSON *spectrum_node, RIG *rig,
|
|
|
|
struct rig_spectrum_line *spectrum_line)
|
2021-11-28 18:52:29 +00:00
|
|
|
{
|
|
|
|
// Spectrum data is represented as a hexadecimal ASCII string where each data byte is represented as 2 ASCII letters
|
2021-11-30 07:25:51 +00:00
|
|
|
char spectrum_data_string[HAMLIB_MAX_SPECTRUM_DATA * 2];
|
2021-11-28 18:52:29 +00:00
|
|
|
cJSON *node;
|
|
|
|
int i;
|
|
|
|
struct rig_spectrum_scope *scopes = rig->caps->spectrum_scopes;
|
|
|
|
char *name = "?";
|
|
|
|
|
|
|
|
for (i = 0; scopes[i].name != NULL; i++)
|
|
|
|
{
|
|
|
|
if (scopes[i].id == spectrum_line->id)
|
|
|
|
{
|
|
|
|
name = scopes[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "id", spectrum_line->id);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddStringToObject(spectrum_node, "name", name);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddStringToObject(spectrum_node, "type",
|
2022-02-05 21:27:43 +00:00
|
|
|
spectrum_line->spectrum_mode == RIG_SPECTRUM_MODE_CENTER ?
|
|
|
|
SPECTRUM_MODE_CENTER : SPECTRUM_MODE_FIXED);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "minLevel",
|
|
|
|
spectrum_line->data_level_min);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "maxLevel",
|
|
|
|
spectrum_line->data_level_max);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "minStrength",
|
|
|
|
spectrum_line->signal_strength_min);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "maxStrength",
|
|
|
|
spectrum_line->signal_strength_max);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "centerFreq",
|
|
|
|
spectrum_line->center_freq);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "span", spectrum_line->span_freq);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "lowFreq",
|
|
|
|
spectrum_line->low_edge_freq);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "highFreq",
|
|
|
|
spectrum_line->high_edge_freq);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
node = cJSON_AddNumberToObject(spectrum_node, "length",
|
|
|
|
(double) spectrum_line->spectrum_data_length);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
to_hex(spectrum_line->spectrum_data_length, spectrum_line->spectrum_data,
|
2022-02-05 21:27:43 +00:00
|
|
|
sizeof(spectrum_data_string), spectrum_data_string);
|
2021-11-28 18:52:29 +00:00
|
|
|
node = cJSON_AddStringToObject(spectrum_node, "data", spectrum_data_string);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-10-20 21:25:21 +00:00
|
|
|
return RIG_OK;
|
2021-11-28 18:52:29 +00:00
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
error:
|
2022-02-13 22:17:41 +00:00
|
|
|
RETURNFUNC2(-RIG_EINTERNAL);
|
2021-11-28 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
2023-11-05 22:42:02 +00:00
|
|
|
void snapshot_init()
|
|
|
|
{
|
|
|
|
snprintf(snapshot_data_pid, sizeof(snapshot_data_pid), "%d", getpid());
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
|
|
|
|
struct rig_spectrum_line *spectrum_line)
|
2021-11-28 18:52:29 +00:00
|
|
|
{
|
|
|
|
cJSON *root_node;
|
|
|
|
cJSON *rig_node, *vfos_array, *vfo_node, *spectra_array, *spectrum_node;
|
|
|
|
cJSON *node;
|
|
|
|
cJSON_bool bool_result;
|
2023-09-18 17:48:39 +00:00
|
|
|
char buf[256];
|
2021-11-28 18:52:29 +00:00
|
|
|
int result;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
root_node = cJSON_CreateObject();
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (root_node == NULL)
|
|
|
|
{
|
2022-02-13 22:17:41 +00:00
|
|
|
RETURNFUNC2(-RIG_EINTERNAL);
|
2021-11-28 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node = cJSON_AddStringToObject(root_node, "app", PACKAGE_NAME);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
|
|
|
node = cJSON_AddStringToObject(root_node, "version",
|
|
|
|
PACKAGE_VERSION " " HAMLIBDATETIME);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
|
|
|
node = cJSON_AddNumberToObject(root_node, "seq",
|
|
|
|
rig->state.snapshot_packet_sequence_number);
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2023-12-16 17:37:58 +00:00
|
|
|
|
2023-09-18 17:48:39 +00:00
|
|
|
date_strget(buf, sizeof(buf), 0);
|
|
|
|
node = cJSON_AddStringToObject(root_node, "time", buf);
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
|
2021-12-20 07:53:21 +00:00
|
|
|
// TODO: Calculate 32-bit CRC of the entire JSON record replacing the CRC value with 0
|
2021-11-28 18:52:29 +00:00
|
|
|
node = cJSON_AddNumberToObject(root_node, "crc", 0);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
rig_node = cJSON_CreateObject();
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (rig_node == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
result = snapshot_serialize_rig(rig_node, rig);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
if (result != RIG_OK)
|
2021-11-28 18:52:29 +00:00
|
|
|
{
|
2021-11-30 07:25:51 +00:00
|
|
|
cJSON_Delete(rig_node);
|
2021-11-28 18:52:29 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2021-11-30 07:25:51 +00:00
|
|
|
cJSON_AddItemToObject(root_node, "rig", rig_node);
|
2021-11-28 18:52:29 +00:00
|
|
|
|
|
|
|
vfos_array = cJSON_CreateArray();
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (vfos_array == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2023-11-07 07:55:30 +00:00
|
|
|
for (i = 0; i < HAMLIB_MAX_VFOS; i++)
|
2021-11-28 18:52:29 +00:00
|
|
|
{
|
2023-11-07 07:55:30 +00:00
|
|
|
vfo_t vfo = rig->state.vfo_list & RIG_VFO_N(i);
|
2023-12-16 17:37:58 +00:00
|
|
|
|
2023-11-07 07:55:30 +00:00
|
|
|
if (!vfo)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
vfo_node = cJSON_CreateObject();
|
2023-11-07 07:55:30 +00:00
|
|
|
result = snapshot_serialize_vfo(vfo_node, rig, vfo);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (result != RIG_OK)
|
|
|
|
{
|
|
|
|
cJSON_Delete(vfo_node);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
cJSON_AddItemToArray(vfos_array, vfo_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
cJSON_AddItemToObject(root_node, "vfos", vfos_array);
|
|
|
|
|
|
|
|
if (spectrum_line != NULL)
|
|
|
|
{
|
|
|
|
spectra_array = cJSON_CreateArray();
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (spectra_array == NULL)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
spectrum_node = cJSON_CreateObject();
|
|
|
|
result = snapshot_serialize_spectrum(spectrum_node, rig, spectrum_line);
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
if (result != RIG_OK)
|
|
|
|
{
|
|
|
|
cJSON_Delete(spectrum_node);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
cJSON_AddItemToArray(spectra_array, spectrum_node);
|
|
|
|
|
|
|
|
cJSON_AddItemToObject(root_node, "spectra", spectra_array);
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
bool_result = cJSON_PrintPreallocated(root_node, buffer, (int) buffer_length,
|
|
|
|
0);
|
2021-11-28 18:52:29 +00:00
|
|
|
|
|
|
|
cJSON_Delete(root_node);
|
|
|
|
|
|
|
|
if (!bool_result)
|
|
|
|
{
|
2022-02-13 22:17:41 +00:00
|
|
|
RETURNFUNC2(-RIG_EINVAL);
|
2021-11-28 18:52:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rig->state.snapshot_packet_sequence_number++;
|
|
|
|
|
2023-10-20 21:25:21 +00:00
|
|
|
return RIG_OK;
|
2021-11-28 18:52:29 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
cJSON_Delete(root_node);
|
2022-02-13 22:17:41 +00:00
|
|
|
RETURNFUNC2(-RIG_EINTERNAL);
|
2021-11-28 18:52:29 +00:00
|
|
|
}
|