From ee807a7541fbd85a8125aafcc12fddfa954e44cb Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Thu, 14 Sep 2023 08:55:21 -0500 Subject: [PATCH] Prevent multicast from doing rig queries at all for now -- threading contention needs to be addressed https://github.com/Hamlib/Hamlib/issues/695 --- include/hamlib/rig.h | 2 ++ src/multicast.c | 21 ++++++++++++++++++--- src/rig.c | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 5692cb62f..9813e0be5 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2571,6 +2571,7 @@ struct multicast_s //#ifdef HAVE_ARPA_INET_H struct ip_mreq mreq; // = {0}; struct sockaddr_in dest_addr; // = {0}; + int port; //#endif }; @@ -2756,6 +2757,7 @@ struct rig_state { volatile int morse_data_handler_thread_run; void *morse_data_handler_priv_data; FIFO_RIG *fifo_morse; + int port_multicast; /*!< May be different so this is initially a copy of rigctl'd port selection */ }; /** diff --git a/src/multicast.c b/src/multicast.c index 2a3da70fd..1442b592d 100644 --- a/src/multicast.c +++ b/src/multicast.c @@ -29,6 +29,14 @@ static struct sockaddr_in dest_addr = {0}; #endif +int multicast_stop(RIG *rig) +{ + if (rig->state.multicast) rig->state.multicast->runflag = 0; + pthread_join(rig->state.multicast->threadid, NULL); + return RIG_OK; +} + +#if 0 static int multicast_status_changed(RIG *rig) { int retval; @@ -49,22 +57,26 @@ static int multicast_status_changed(RIG *rig) pbwidth_t widthA, widthAsave = rig->state.cache.widthMainA; pbwidth_t widthB, widthBsave = rig->state.cache.widthMainB; +#if 0 if (rig->state.multicast->seqnumber % 2 == 0 && (retval = rig_get_mode(rig, RIG_VFO_A, &modeA, &widthA)) != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: rig_get_modeA:%s\n", __func__, rigerror(retval)); } +#endif if (modeA != modeAsave) { return 1; } if (widthA != widthAsave) { return 1; } +#if 0 if (rig->state.multicast->seqnumber % 2 == 0 && (rig->caps->targetable_vfo & RIG_TARGETABLE_MODE) && (retval = rig_get_mode(rig, RIG_VFO_B, &modeB, &widthB)) != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: rig_get_modeB:%s\n", __func__, rigerror(retval)); } +#endif if (modeB != modeBsave) { return 1; } @@ -72,6 +84,7 @@ static int multicast_status_changed(RIG *rig) ptt_t ptt, pttsave = rig->state.cache.ptt; +#if 0 if (rig->state.multicast->seqnumber % 2 == 0 && (retval = rig_get_ptt(rig, RIG_VFO_CURR, &ptt)) != RIG_OK) if (ptt != pttsave) { return 1; } @@ -82,9 +95,11 @@ static int multicast_status_changed(RIG *rig) if (rig->state.multicast->seqnumber % 2 == 0 && (retval = rig_get_split_vfo(rig, RIG_VFO_CURR, &split, &txvfo)) != RIG_OK) if (split != splitsave) { return 1; } +#endif return 0; } +#endif void json_add_string(char *msg, const char *key, const char *value, int addComma) @@ -287,8 +302,8 @@ void *multicast_thread(void *vrig) rig_debug(RIG_DEBUG_TRACE, "%s: multicast_thread started\n", __func__); // do the 1st packet all the time - multicast_status_changed(rig); - multicast_send_json(rig); + //multicast_status_changed(rig); + //multicast_send_json(rig); int loopcount = 8; freq_t freqA, freqAsave = 0; @@ -346,7 +361,7 @@ void *multicast_thread(void *vrig) else { //rig_debug(RIG_DEBUG_VERBOSE, "%s: loop\n", __func__); - hl_usleep(100 * 1000); + hl_usleep(10 * 1000); } diff --git a/src/rig.c b/src/rig.c index 77c3121e3..83bd1c524 100644 --- a/src/rig.c +++ b/src/rig.c @@ -1526,6 +1526,7 @@ int HAMLIB_API rig_close(RIG *rig) morse_data_handler_stop(rig); async_data_handler_stop(rig); + multicast_stop(rig); /* * Let the backend say 73s to the rig.