From 84875071a93fefc9f4f7c56e31a4fc90c42f203c Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sun, 22 Oct 2023 13:18:51 -0500 Subject: [PATCH] Change modelist to modes array Change id: to 3-elements 1 packet per second right now -- but will soon send out a packet upon any change of data https://github.com/Hamlib/Hamlib/issues/695 --- README.multicast | 13 +++++++++++-- src/network.c | 2 +- src/snapshot_data.c | 30 ++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/README.multicast b/README.multicast index ead2dd410..0734cde7a 100644 --- a/README.multicast +++ b/README.multicast @@ -90,14 +90,23 @@ JSON data snapshot format for UDP packets: "crc": 0, "rig": { "__comment1__": "customizable rig identification -- will allow multiple rigs to be on the multicast", - "id": "Rig#1", - "name": "Dummy", + "id": { + "model":"IC-7300", + "endpoint":"com1", + "process":"53535", + } + "name": "IC-7300", "ptt" : false, "split": true, "splitVfo": "VFOB", "satMode": false, "status": "OK"; "errorMsg": "OK", + "modes":[ + "AM", + "CW", + "USB" + ] }, "vfos": [ { diff --git a/src/network.c b/src/network.c index d2519eba4..0028dff5a 100644 --- a/src/network.c +++ b/src/network.c @@ -967,7 +967,7 @@ void *multicast_publisher(void *arg) rig_debug(RIG_DEBUG_ERR, "%s: error sending UDP packet: %s\n", __func__, strerror(errno)); } - hl_usleep(1000); + hl_usleep(1000*1000); } rs->multicast_publisher_run = 2; // stop value diff --git a/src/snapshot_data.c b/src/snapshot_data.c index 60bfa63bf..d8d6aa8bf 100644 --- a/src/snapshot_data.c +++ b/src/snapshot_data.c @@ -20,17 +20,27 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig) cJSON *node; char buf[1024]; +#if 0 // TODO: need to assign rig an ID, e.g. from command line snprintf(buf, sizeof(buf), "%s:%s:%d", rig->caps->model_name, rig->state.rigport.pathname, getpid()); node = cJSON_AddStringToObject(rig_node, "id", buf); - if (node == NULL) { goto error; } +#else + cJSON *id_node = cJSON_CreateObject(); + cJSON_AddStringToObject(id_node, "model", rig->caps->model_name); + cJSON_AddStringToObject(id_node, "endpoint", rig->state.rigport.pathname); + char pid[16]; + sprintf(pid,"%d",getpid()); + cJSON_AddStringToObject(id_node, "process", pid); + cJSON_AddItemToObject(rig_node, "id", id_node); +#endif + // TODO: what kind of status should this reflect? node = cJSON_AddStringToObject(rig_node, "status", rig->state.comm_state ? "OK" : "CLOSED"); @@ -80,13 +90,17 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig) } rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list); - node = cJSON_AddStringToObject(rig_node, "modelist", buf); - - if (node == NULL) + char *p; + cJSON *modes_array = cJSON_CreateArray(); + for(p=strtok(buf," ");p;p=strtok(NULL, " ")) { - goto error; + if (strlen(buf)>0) { + cJSON *tmp = cJSON_CreateString(p); + cJSON_AddItemToArray(modes_array, tmp); + } } - + cJSON_AddItemToObject(rig_node, "modes", modes_array); + //RETURNFUNC2(RIG_OK); return RIG_OK; @@ -94,11 +108,15 @@ error: RETURNFUNC2(-RIG_EINTERNAL); } +// 128 max modes should last a while +#define MAX_MODES 128 + 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; + //rmode_t modes[MAX_MODES]; pbwidth_t width; ptt_t ptt; split_t split;