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
pull/1406/head
Mike Black W9MDB 2023-10-22 13:18:51 -05:00
rodzic 9b6d1565f1
commit 84875071a9
3 zmienionych plików z 36 dodań i 9 usunięć

Wyświetl plik

@ -90,14 +90,23 @@ JSON data snapshot format for UDP packets:
"crc": 0, "crc": 0,
"rig": { "rig": {
"__comment1__": "customizable rig identification -- will allow multiple rigs to be on the multicast", "__comment1__": "customizable rig identification -- will allow multiple rigs to be on the multicast",
"id": "Rig#1", "id": {
"name": "Dummy", "model":"IC-7300",
"endpoint":"com1",
"process":"53535",
}
"name": "IC-7300",
"ptt" : false, "ptt" : false,
"split": true, "split": true,
"splitVfo": "VFOB", "splitVfo": "VFOB",
"satMode": false, "satMode": false,
"status": "OK"; "status": "OK";
"errorMsg": "OK", "errorMsg": "OK",
"modes":[
"AM",
"CW",
"USB"
]
}, },
"vfos": [ "vfos": [
{ {

Wyświetl plik

@ -967,7 +967,7 @@ void *multicast_publisher(void *arg)
rig_debug(RIG_DEBUG_ERR, "%s: error sending UDP packet: %s\n", __func__, rig_debug(RIG_DEBUG_ERR, "%s: error sending UDP packet: %s\n", __func__,
strerror(errno)); strerror(errno));
} }
hl_usleep(1000); hl_usleep(1000*1000);
} }
rs->multicast_publisher_run = 2; // stop value rs->multicast_publisher_run = 2; // stop value

Wyświetl plik

@ -20,17 +20,27 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig)
cJSON *node; cJSON *node;
char buf[1024]; char buf[1024];
#if 0
// TODO: need to assign rig an ID, e.g. from command line // TODO: need to assign rig an ID, e.g. from command line
snprintf(buf, sizeof(buf), "%s:%s:%d", rig->caps->model_name, snprintf(buf, sizeof(buf), "%s:%s:%d", rig->caps->model_name,
rig->state.rigport.pathname, getpid()); rig->state.rigport.pathname, getpid());
node = cJSON_AddStringToObject(rig_node, "id", buf); node = cJSON_AddStringToObject(rig_node, "id", buf);
if (node == NULL) if (node == NULL)
{ {
goto error; 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? // TODO: what kind of status should this reflect?
node = cJSON_AddStringToObject(rig_node, "status", node = cJSON_AddStringToObject(rig_node, "status",
rig->state.comm_state ? "OK" : "CLOSED"); 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); rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list);
node = cJSON_AddStringToObject(rig_node, "modelist", buf); char *p;
cJSON *modes_array = cJSON_CreateArray();
if (node == NULL) 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); //RETURNFUNC2(RIG_OK);
return RIG_OK; return RIG_OK;
@ -94,11 +108,15 @@ error:
RETURNFUNC2(-RIG_EINTERNAL); 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) static int snapshot_serialize_vfo(cJSON *vfo_node, RIG *rig, vfo_t vfo)
{ {
freq_t freq; freq_t freq;
int freq_ms, mode_ms, width_ms; int freq_ms, mode_ms, width_ms;
rmode_t mode; rmode_t mode;
//rmode_t modes[MAX_MODES];
pbwidth_t width; pbwidth_t width;
ptt_t ptt; ptt_t ptt;
split_t split; split_t split;