Add modelist to multicast

Add time to multicast
Fix id to show rig+path
Remove sleep to speed up multicast packets to once per seconds
https://github.com/Hamlib/Hamlib/issues/695
pull/1389/head
Mike Black W9MDB 2023-09-18 12:48:39 -05:00
rodzic da9199577e
commit 5f825aa0d4
4 zmienionych plików z 30 dodań i 8 usunięć

Wyświetl plik

@ -560,7 +560,7 @@ int multicast_init(RIG *rig, char *addr, int port)
rig->state.multicast->dest_addr.sin_addr.s_addr = inet_addr(addr);
rig->state.multicast->dest_addr.sin_port = htons(port);
#if 1
#if 0
rig->state.multicast->runflag = 1;
pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread,
(void *)rig);

Wyświetl plik

@ -887,7 +887,7 @@ void *multicast_publisher(void *arg)
RIG *rig = args->rig;
struct rig_state *rs = &rig->state;
struct rig_spectrum_line spectrum_line;
uint8_t packet_type;
uint8_t packet_type = MULTICAST_PUBLISHER_DATA_PACKET_TYPE_SPECTRUM;
struct sockaddr_in dest_addr;
int socket_fd = args->socket_fd;
@ -913,13 +913,13 @@ void *multicast_publisher(void *arg)
{
if (result == -RIG_ETIMEOUT)
{
continue;
// continue;
}
// TODO: how to detect closing of pipe, indicate with error code
// TODO: error handling, flush pipe in case of error?
hl_usleep(500 * 1000);
continue;
//hl_usleep(500 * 1000);
// continue;
}
result = snapshot_serialize(sizeof(snapshot_buffer), snapshot_buffer, rig,

Wyświetl plik

@ -1486,7 +1486,7 @@ int HAMLIB_API rig_open(RIG *rig)
memcpy(&rs->pttport_deprecated, &rs->pttport, sizeof(hamlib_port_t_deprecated));
memcpy(&rs->dcdport_deprecated, &rs->dcdport, sizeof(hamlib_port_t_deprecated));
rig_flush_force(&rs->rigport, 1);
if (rig->caps->rig_model != RIG_MODEL_NETRIGCTL) multicast_init(rig, "224.0.0.1", 4532);
// if (rig->caps->rig_model != RIG_MODEL_NETRIGCTL) multicast_init(rig, "224.0.0.1", 4532);
RETURNFUNC2(RIG_OK);
}
@ -1526,7 +1526,7 @@ int HAMLIB_API rig_close(RIG *rig)
morse_data_handler_stop(rig);
async_data_handler_stop(rig);
multicast_stop(rig);
//multicast_stop(rig);
/*
* Let the backend say 73s to the rig.

Wyświetl plik

@ -4,6 +4,7 @@
#include "misc.h"
#include "snapshot_data.h"
#include "hamlibdatetime.h"
#include "sprintflst.h"
#include "cJSON.h"
@ -15,9 +16,13 @@
static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig)
{
cJSON *node;
char buf[1024];
// TODO: need to assign rig an ID, e.g. from command line
node = cJSON_AddStringToObject(rig_node, "id", "rig_id");
snprintf(buf, sizeof(buf), "%s:%s", rig->caps->model_name,
rig->state.rigport.pathname);
node = cJSON_AddStringToObject(rig_node, "id", buf);
if (node == NULL)
{
@ -72,6 +77,14 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig)
goto error;
}
rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list);
node = cJSON_AddStringToObject(rig_node, "modelist", buf);
if (node == NULL)
{
goto error;
}
RETURNFUNC2(RIG_OK);
error:
@ -296,6 +309,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
cJSON *rig_node, *vfos_array, *vfo_node, *spectra_array, *spectrum_node;
cJSON *node;
cJSON_bool bool_result;
char buf[256];
int vfo_count = 2;
vfo_t vfos[MAX_VFO_COUNT];
@ -334,6 +348,14 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig,
{
goto error;
}
date_strget(buf, sizeof(buf), 0);
node = cJSON_AddStringToObject(root_node, "time", buf);
if (node == NULL)
{
goto error;
}
// TODO: Calculate 32-bit CRC of the entire JSON record replacing the CRC value with 0
node = cJSON_AddNumberToObject(root_node, "crc", 0);