diff --git a/src/cache.c b/src/cache.c index 4811fc3b2..cac9c6ae8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -24,7 +24,7 @@ #include "cache.h" #include "misc.h" -#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) +#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state) /** * \file cache.c @@ -35,6 +35,7 @@ int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); ENTERFUNC; @@ -43,16 +44,16 @@ int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (vfo == RIG_VFO_CURR) { // if CURR then update this before we figure out the real VFO - vfo = rig->state.current_vfo; + vfo = rs->current_vfo; } else if (vfo == RIG_VFO_TX) { - vfo = rig->state.tx_vfo; + vfo = rs->tx_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: TX VFO = %s\n", __func__, rig_strvfo(vfo)); } else if (vfo == RIG_VFO_RX) { - vfo = rig->state.rx_vfo; + vfo = rs->rx_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: RX VFO = %s\n", __func__, rig_strvfo(vfo)); } @@ -63,7 +64,7 @@ int rig_set_cache_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (vfo == RIG_VFO_OTHER) { vfo = vfo_fixup(rig, vfo, cachep->split); } - if (vfo == rig->state.current_vfo) + if (vfo == rs->current_vfo) { cachep->modeCurr = mode; if (width > 0) @@ -157,6 +158,7 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq) { int flag = HAMLIB_ELAPSED_SET; struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); if (rig_need_debug(RIG_DEBUG_CACHE)) { @@ -165,12 +167,12 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_debug(RIG_DEBUG_CACHE, "%s(%d): vfo=%s, current_vfo=%s\n", __func__, __LINE__, - rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo)); + rig_strvfo(vfo), rig_strvfo(rs->current_vfo)); if (vfo == RIG_VFO_CURR) { // if CURR then update this before we figure out the real VFO - vfo = rig->state.current_vfo; + vfo = rs->current_vfo; } // if freq == 0 then we are asking to invalidate the cache @@ -188,7 +190,7 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_strvfo(vfo), freq); } - if (vfo == rig->state.current_vfo) + if (vfo == rs->current_vfo) { cachep->freqCurr = freq; elapsed_ms(&cachep->time_freqCurr, flag); @@ -307,6 +309,7 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, rmode_t *mode, int *cache_ms_mode, pbwidth_t *width, int *cache_ms_width) { struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); if (CHECK_RIG_ARG(rig) || !freq || !cache_ms_freq || !mode || !cache_ms_mode || !width || !cache_ms_width) @@ -321,25 +324,25 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, rig_debug(RIG_DEBUG_CACHE, "%s(%d): vfo=%s, current_vfo=%s\n", __func__, __LINE__, - rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo)); + rig_strvfo(vfo), rig_strvfo(rs->current_vfo)); if (vfo == RIG_VFO_CURR) { - vfo = rig->state.current_vfo; + vfo = rs->current_vfo; } else if (vfo == RIG_VFO_TX) { - vfo = rig->state.tx_vfo; + vfo = rs->tx_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: TX VFO = %s\n", __func__, rig_strvfo(vfo)); } else if (vfo == RIG_VFO_RX) { - vfo = rig->state.rx_vfo; + vfo = rs->rx_vfo; rig_debug(RIG_DEBUG_VERBOSE, "%s: RX VFO = %s\n", __func__, rig_strvfo(vfo)); } else if (vfo == RIG_VFO_OTHER) { - switch (rig->state.current_vfo) + switch (rs->current_vfo) { case RIG_VFO_CURR: break; // no change @@ -384,7 +387,7 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, default: rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown vfo=%s, curr_vfo=%s\n", __func__, __LINE__, - rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo)); + rig_strvfo(vfo), rig_strvfo(rs->current_vfo)); } } @@ -574,7 +577,7 @@ void rig_cache_show(RIG *rig, const char *func, int line) cachep->freqMainB, rig_strrmode(cachep->modeMainB), (int)cachep->widthMainB); - if (rig->state.vfo_list & RIG_VFO_SUB_A) + if (STATE(rig)->vfo_list & RIG_VFO_SUB_A) { rig_debug(RIG_DEBUG_CACHE, "%s(%d): freqSubA=%.0f, modeSubA=%s, widthSubA=%d\n", func, line, diff --git a/src/misc.h b/src/misc.h index 18a2050cc..31ff966ec 100644 --- a/src/misc.h +++ b/src/misc.h @@ -30,11 +30,11 @@ */ #ifdef HAVE_PTHREAD #include -#define set_transaction_active(rig) {pthread_mutex_lock(&rig->state.mutex_set_transaction);(rig)->state.transaction_active = 1;} -#define set_transaction_inactive(rig) {(rig)->state.transaction_active = 0;pthread_mutex_unlock(&rig->state.mutex_set_transaction);} +#define set_transaction_active(rig) {pthread_mutex_lock(&STATE(rig)->mutex_set_transaction);STATE(rig)->transaction_active = 1;} +#define set_transaction_inactive(rig) {STATE(rig)->transaction_active = 0;pthread_mutex_unlock(&STATE(rig)->mutex_set_transaction);} #else -#define set_transaction_active(rig) {(rig)->state.transaction_active = 1;} -#define set_transaction_inactive(rig) {(rig)->state.transaction_active = 0;} +#define set_transaction_active(rig) {STATE(rig)->transaction_active = 1;} +#define set_transaction_inactive(rig) {STATE(rig)->transaction_active = 0;} #endif __BEGIN_DECLS @@ -157,24 +157,24 @@ extern HAMLIB_EXPORT(char *)date_strget(char *buf, int buflen, int localtime); #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) void errmsg(int err, char *s, const char *func, const char *file, int line); #define ERRMSG(err, s) errmsg(err, s, __func__, __FILENAME__, __LINE__) -#define ENTERFUNC { ++rig->state.depth; \ - rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s entered\n", spaces(rig->state.depth), rig->state.depth, __FILENAME__, __LINE__, __func__); \ +#define ENTERFUNC { ++STATE(rig)->depth; \ + rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s entered\n", spaces(STATE(rig)->depth), STATE(rig)->depth, __FILENAME__, __LINE__, __func__); \ } #define ENTERFUNC2 { rig_debug(RIG_DEBUG_VERBOSE, "%s(%d):%s entered\n", __FILENAME__, __LINE__, __func__); \ } // we need to refer to rc just once as it // could be a function call #define RETURNFUNC(rc) {do { \ - int rctmp = rc; \ - rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s returning(%ld) %s\n", spaces(rig->state.depth), rig->state.depth, __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \ - --rig->state.depth; \ - return (rctmp); \ - } while(0);} + int rctmp = rc; \ + rig_debug(RIG_DEBUG_VERBOSE, "%s%d:%s(%d):%s returning(%ld) %s\n", spaces(STATE(rig)->depth), STATE(rig)->depth, __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \ + --STATE(rig)->depth; \ + return (rctmp); \ + } while(0);} #define RETURNFUNC2(rc) {do { \ - int rctmp = rc; \ - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d):%s returning2(%ld) %s\n", __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \ - return (rctmp); \ - } while(0);} + int rctmp = rc; \ + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d):%s returning2(%ld) %s\n", __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \ + return (rctmp); \ + } while(0);} #define CACHE_RESET {\ elapsed_ms(&CACHE(rig)->time_freqMainA, HAMLIB_ELAPSED_INVALIDATE);\ diff --git a/src/multicast.c b/src/multicast.c index 8570f279c..68cdd4803 100644 --- a/src/multicast.c +++ b/src/multicast.c @@ -33,9 +33,10 @@ static struct sockaddr_in dest_addr = {0}; int multicast_stop(RIG *rig) { - if (rig->state.multicast) { rig->state.multicast->runflag = 0; } + struct rig_state *rs = STATE(rig); + if (rs->multicast) { rs->multicast->runflag = 0; } - pthread_join(rig->state.multicast->threadid, NULL); + pthread_join(rs->multicast->threadid, NULL); return RIG_OK; } @@ -44,6 +45,7 @@ static int multicast_status_changed(RIG *rig) { int retval; struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); #if 0 freq_t freq, freqsave = cachep->freqMainA; @@ -63,7 +65,7 @@ static int multicast_status_changed(RIG *rig) #if 0 - if (rig->state.multicast->seqnumber % 2 == 0 + if (rs->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)); @@ -77,7 +79,7 @@ static int multicast_status_changed(RIG *rig) #if 0 - if (rig->state.multicast->seqnumber % 2 == 0 + if (rs->multicast->seqnumber % 2 == 0 && (rig->caps->targetable_vfo & RIG_TARGETABLE_MODE) && (retval = rig_get_mode(rig, RIG_VFO_B, &modeB, &widthB)) != RIG_OK) { @@ -94,14 +96,14 @@ static int multicast_status_changed(RIG *rig) #if 0 - if (rig->state.multicast->seqnumber % 2 == 0 + if (rs->multicast->seqnumber % 2 == 0 && (retval = rig_get_ptt(rig, RIG_VFO_CURR, &ptt)) != RIG_OK) if (ptt != pttsave) { return 1; } split_t split, splitsave = cachep->split; vfo_t txvfo; - if (rig->state.multicast->seqnumber % 2 == 0 + if (rs->multicast->seqnumber % 2 == 0 && (retval = rig_get_split_vfo(rig, RIG_VFO_CURR, &split, &txvfo)) != RIG_OK) if (split != splitsave) { return 1; } @@ -192,6 +194,7 @@ void json_add_time(char *msg, int addComma) void json_add_vfoA(RIG *rig, char *msg) { struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); strcat(msg, "{\n"); json_add_string(msg, "Name", "VFOA", 1); @@ -211,15 +214,15 @@ void json_add_vfoA(RIG *rig, char *msg) #if 0 // not working quite yet // what about full duplex? rx_vfo would be in rx all the time? rig_debug(RIG_DEBUG_ERR, "%s: rx_vfo=%s, tx_vfo=%s, split=%d\n", __func__, - rig_strvfo(rig->state.rx_vfo), rig_strvfo(rig->state.tx_vfo), + rig_strvfo(rs->rx_vfo), rig_strvfo(rs->tx_vfo), cachep->split); printf("%s: rx_vfo=%s, tx_vfo=%s, split=%d\n", __func__, - rig_strvfo(rig->state.rx_vfo), rig_strvfo(rig->state.tx_vfo), + rig_strvfo(rs->rx_vfo), rig_strvfo(rs->tx_vfo), cachep->split); if (cachep->split) { - if (rig->state.tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B)) + if (rs->tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B)) { json_add_boolean(msg, "RX", !cachep->ptt, 1); json_add_boolean(msg, "TX", 0, 0); @@ -230,7 +233,7 @@ void json_add_vfoA(RIG *rig, char *msg) json_add_boolean(msg, "TX", cachep->ptt, 0); } } - else if (rig->state.current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A)) + else if (rs->current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A)) { json_add_boolean(msg, "RX", !cachep->ptt, 1); json_add_boolean(msg, "TX", cachep->ptt, 0); @@ -248,6 +251,7 @@ void json_add_vfoA(RIG *rig, char *msg) void json_add_vfoB(RIG *rig, char *msg) { struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); strcat(msg, ",\n{\n"); json_add_string(msg, "Name", "VFOB", 1); @@ -266,9 +270,9 @@ void json_add_vfoB(RIG *rig, char *msg) #if 0 // not working yet - if (rig->state.rx_vfo != rig->state.tx_vfo && cachep->split) + if (rs->rx_vfo != rs->tx_vfo && cachep->split) { - if (rig->state.tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B)) + if (rs->tx_vfo && (RIG_VFO_B | RIG_VFO_MAIN_B)) { json_add_boolean(msg, "RX", 0, 1); json_add_boolean(msg, "TX", cachep->ptt, 0); @@ -279,7 +283,7 @@ void json_add_vfoB(RIG *rig, char *msg) json_add_boolean(msg, "TX", 0, 0); } } - else if (rig->state.current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A)) + else if (rs->current_vfo && (RIG_VFO_A | RIG_VFO_MAIN_A)) { json_add_boolean(msg, "RX", !cachep->ptt, 1); json_add_boolean(msg, "TX", cachep->ptt, 0); @@ -300,7 +304,8 @@ static int multicast_send_json(RIG *rig) char msg[8192]; // could be pretty big char buf[4096]; struct rig_cache *cachep = CACHE(rig); - + struct rig_state *rs = STATE(rig); + // sprintf(msg,"%s:f=%.1f", date_strget(msg, (int)sizeof(msg), 0), f); msg[0] = 0; snprintf(buf, sizeof(buf), "%s:%s", rig->caps->model_name, @@ -308,11 +313,11 @@ static int multicast_send_json(RIG *rig) strcat(msg, "{\n"); json_add_string(msg, "ID", buf, 1); json_add_time(msg, 1); - json_add_int(msg, "Sequence", rig->state.multicast->seqnumber++, 1); - json_add_string(msg, "VFOCurr", rig_strvfo(rig->state.current_vfo), 1); + json_add_int(msg, "Sequence", rs->multicast->seqnumber++, 1); + json_add_string(msg, "VFOCurr", rig_strvfo(rs->current_vfo), 1); json_add_int(msg, "PTT", cachep->ptt, 1); json_add_int(msg, "Split", cachep->split, 1); - rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list); + rig_sprintf_mode(buf, sizeof(buf), rs->mode_list); json_add_string(msg, "ModeList", buf, 1); strcat(msg, "\"VFOs\": [\n"); json_add_vfoA(rig, msg); @@ -333,17 +338,18 @@ void *multicast_thread_rx(void *vrig) // int ret = 0; RIG *rig = (RIG *)vrig; hamlib_port_t port; - rig->state.rig_type = RIG_TYPE_TRANSCEIVER; - rig->state.ptt_type = RIG_PTT_RIG; - rig->state.port_type = RIG_PORT_UDP_NETWORK; + struct rig_state *rs = STATE(rig); + rs->rig_type = RIG_TYPE_TRANSCEIVER; + rs->ptt_type = RIG_PTT_RIG; + rs->port_type = RIG_PORT_UDP_NETWORK; strcpy(port.pathname, "127.0.0.1:4532"); //rig_debug(RIG_DEBUG_TRACE, "%s: started\n", __func__); #if 0 network_open(&port, 4532); #endif - //while (rig->state.multicast->runflag && ret >= 0) - while (rig->state.multicast->runflag) + //while (rs->multicast->runflag && ret >= 0) + while (rs->multicast->runflag) { #if 0 ret = read_string(RIGPORT(rig), (unsigned char *) buf, sizeof(buf), "\n", @@ -377,10 +383,11 @@ void *multicast_thread(void *vrig) mode_t modeB, modeBsave = 0; ptt_t ptt, pttsave = 0; struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); - rig->state.multicast->runflag = 1; + rs->multicast->runflag = 1; - while (rig->state.multicast->runflag) + while (rs->multicast->runflag) { #if 0 @@ -470,7 +477,9 @@ static char *GetWinsockLastError(char *errorBuffer, DWORD errorBufferSize) int multicast_init(RIG *rig, char *addr, int port) { - if (rig->state.multicast && rig->state.multicast->multicast_running) { return RIG_OK; } + struct rig_state *rs = STATE(rig); + + if (rs->multicast && rs->multicast->multicast_running) { return RIG_OK; } #ifdef _WIN32 WSADATA wsaData; @@ -485,22 +494,22 @@ int multicast_init(RIG *rig, char *addr, int port) #endif - if (rig->state.multicast == NULL) + if (rs->multicast == NULL) { - rig->state.multicast = calloc(1, sizeof(struct multicast_s)); + rs->multicast = calloc(1, sizeof(struct multicast_s)); } - else if (rig->state.multicast->multicast_running) { return RIG_OK; } // we only need one port + else if (rs->multicast->multicast_running) { return RIG_OK; } // we only need one port - //rig->state.multicast->mreq = {0}; + //rs->multicast->mreq = {0}; if (addr == NULL) { addr = RIG_MULTICAST_ADDR; } if (port == 0) { port = RIG_MULTICAST_PORT; } // Create a UDP socket - rig->state.multicast->sock = socket(AF_INET, SOCK_DGRAM, 0); + rs->multicast->sock = socket(AF_INET, SOCK_DGRAM, 0); - if (rig->state.multicast->sock < 0) + if (rs->multicast->sock < 0) { #ifdef _WIN32 int err = WSAGetLastError(); @@ -515,7 +524,7 @@ int multicast_init(RIG *rig, char *addr, int port) // Set the SO_REUSEADDR option to allow multiple processes to use the same address int optval = 1; - if (setsockopt(rig->state.multicast->sock, SOL_SOCKET, SO_REUSEADDR, + if (setsockopt(rs->multicast->sock, SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof(optval)) < 0) { @@ -533,7 +542,7 @@ int multicast_init(RIG *rig, char *addr, int port) #if 0 - if (bind(rig->state.multicast->sock, (struct sockaddr *)&saddr, + if (bind(rs->multicast->sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: bind: %s\n", __func__, strerror(errno)); @@ -544,13 +553,13 @@ int multicast_init(RIG *rig, char *addr, int port) // Construct the multicast group address // struct ip_mreq mreq = {0}; - rig->state.multicast->mreq.imr_multiaddr.s_addr = inet_addr(addr); - rig->state.multicast->mreq.imr_interface.s_addr = htonl(INADDR_ANY); + rs->multicast->mreq.imr_multiaddr.s_addr = inet_addr(addr); + rs->multicast->mreq.imr_interface.s_addr = htonl(INADDR_ANY); // Set the multicast TTL (time-to-live) to limit the scope of the packets char ttl = 1; - if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, + if (setsockopt(rs->multicast->sock, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno)); @@ -561,8 +570,8 @@ int multicast_init(RIG *rig, char *addr, int port) // look like we need to implement the client in a separate thread? // Join the multicast group - if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, - (char *)&rig->state.multicast->mreq, sizeof(rig->state.multicast->mreq)) < 0) + if (setsockopt(rs->multicast->sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, + (char *)&rs->multicast->mreq, sizeof(rs->multicast->mreq)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno)); //return -RIG_EIO; @@ -571,19 +580,19 @@ int multicast_init(RIG *rig, char *addr, int port) #endif // prime the dest_addr for the send routine - memset(&rig->state.multicast->dest_addr, 0, - sizeof(rig->state.multicast->dest_addr)); - rig->state.multicast->dest_addr.sin_family = AF_INET; - rig->state.multicast->dest_addr.sin_addr.s_addr = inet_addr(addr); - rig->state.multicast->dest_addr.sin_port = htons(port); + memset(&rs->multicast->dest_addr, 0, + sizeof(rs->multicast->dest_addr)); + rs->multicast->dest_addr.sin_family = AF_INET; + rs->multicast->dest_addr.sin_addr.s_addr = inet_addr(addr); + rs->multicast->dest_addr.sin_port = htons(port); #if 0 - rig->state.multicast->runflag = 1; - pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread, + rs->multicast->runflag = 1; + pthread_create(&rs->multicast->threadid, NULL, multicast_thread, (void *)rig); - //printf("threadid=%ld\n", rig->state.multicast->threadid); - rig->state.multicast->multicast_running = 1; - pthread_create(&rig->state.multicast->threadid, NULL, multicast_thread_rx, + //printf("threadid=%ld\n", rs->multicast->threadid); + rs->multicast->multicast_running = 1; + pthread_create(&rs->multicast->threadid, NULL, multicast_thread_rx, (void *)rig); #endif return RIG_OK; @@ -592,17 +601,19 @@ int multicast_init(RIG *rig, char *addr, int port) // cppcheck-suppress unusedFunction void multicast_close(RIG *rig) { + struct rig_state *rs = STATE(rig); + // Leave the multicast group - if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, - IP_DROP_MEMBERSHIP, (char *)&rig->state.multicast->mreq, - sizeof(rig->state.multicast->mreq)) < 0) + if (setsockopt(rs->multicast->sock, IPPROTO_IP, + IP_DROP_MEMBERSHIP, (char *)&rs->multicast->mreq, + sizeof(rs->multicast->mreq)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno)); return; } // Close the socket - if (close(rig->state.multicast->sock)) + if (close(rs->multicast->sock)) { rig_debug(RIG_DEBUG_ERR, "%s: close: %s\n", __func__, strerror(errno)); } @@ -626,7 +637,7 @@ int multicast_send(RIG *rig, const char *msg, int msglen) // Send the message to the multicast group - ssize_t num_bytes = sendto(rig->state.multicast->sock, msg, msglen, 0, + ssize_t num_bytes = sendto(STATE(rig)->multicast->sock, msg, msglen, 0, (struct sockaddr *)&addr, sizeof(addr)); @@ -665,7 +676,7 @@ int main(int argc, const char *argv[]) RIGPORT(rig)->parm.serial.rate = 38400; rig_open(rig); multicast_init(rig, "224.0.0.1", 4532); - pthread_join(rig->state.multicast->threadid, NULL); + pthread_join(STATE(rig)->multicast->threadid, NULL); pthread_exit(NULL); return 0; } diff --git a/src/snapshot_data.c b/src/snapshot_data.c index ca5eca2eb..c68f13a90 100644 --- a/src/snapshot_data.c +++ b/src/snapshot_data.c @@ -20,16 +20,17 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig) cJSON *node; char buf[1024]; struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); cJSON *id_node = cJSON_CreateObject(); cJSON_AddStringToObject(id_node, "model", rig->caps->model_name); cJSON_AddStringToObject(id_node, "endpoint", RIGPORT(rig)->pathname); cJSON_AddStringToObject(id_node, "process", snapshot_data_pid); - cJSON_AddStringToObject(id_node, "deviceId", rig->state.device_id); + cJSON_AddStringToObject(id_node, "deviceId", rs->device_id); cJSON_AddItemToObject(rig_node, "id", id_node); node = cJSON_AddStringToObject(rig_node, "status", - rig_strcommstatus(rig->state.comm_status)); + rig_strcommstatus(rs->comm_status)); if (node == NULL) { @@ -75,7 +76,7 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig) goto error; } - rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list); + rig_sprintf_mode(buf, sizeof(buf), rs->mode_list); char *p; cJSON *modes_array = cJSON_CreateArray(); @@ -113,6 +114,7 @@ static int snapshot_serialize_vfo(cJSON *vfo_node, RIG *rig, vfo_t vfo) int is_rx, is_tx; cJSON *node; struct rig_cache *cachep = CACHE(rig); + struct rig_state *rs = STATE(rig); // TODO: This data should match rig_get_info command response @@ -153,9 +155,9 @@ static int snapshot_serialize_vfo(cJSON *vfo_node, RIG *rig, vfo_t vfo) split = cachep->split; split_vfo = cachep->split_vfo; - is_rx = (split == RIG_SPLIT_OFF && vfo == rig->state.current_vfo) + is_rx = (split == RIG_SPLIT_OFF && vfo == rs->current_vfo) || (split == RIG_SPLIT_ON && vfo != split_vfo); - is_tx = (split == RIG_SPLIT_OFF && vfo == rig->state.current_vfo) + is_tx = (split == RIG_SPLIT_OFF && vfo == rs->current_vfo) || (split == RIG_SPLIT_ON && vfo == split_vfo); ptt = cachep->ptt && is_tx; @@ -336,6 +338,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig, char buf[256]; int result; int i; + struct rig_state *rs = STATE(rig); root_node = cJSON_CreateObject(); @@ -360,7 +363,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig, } node = cJSON_AddNumberToObject(root_node, "seq", - rig->state.snapshot_packet_sequence_number); + rs->snapshot_packet_sequence_number); if (node == NULL) { @@ -410,7 +413,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig, for (i = 0; i < HAMLIB_MAX_VFOS; i++) { - vfo_t vfo = rig->state.vfo_list & RIG_VFO_N(i); + vfo_t vfo = rs->vfo_list & RIG_VFO_N(i); if (!vfo) { @@ -464,7 +467,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig, RETURNFUNC2(-RIG_EINVAL); } - rig->state.snapshot_packet_sequence_number++; + rs->snapshot_packet_sequence_number++; return RIG_OK; diff --git a/src/tones.c b/src/tones.c index 768e377f3..86d0b1fcf 100644 --- a/src/tones.c +++ b/src/tones.c @@ -68,7 +68,7 @@ tone_t full_dcs_list[] = { FULL_DCS_LIST }; #ifndef DOC_HIDDEN -#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state) +#define CHECK_RIG_ARG(r) (!(r) || !(r)->caps || !STATE(r)->comm_state) #endif /* !DOC_HIDDEN */ @@ -98,6 +98,7 @@ tone_t full_dcs_list[] = { FULL_DCS_LIST }; int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -117,7 +118,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->set_ctcss_tone(rig, vfo, tone); @@ -128,7 +129,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -165,6 +166,7 @@ int HAMLIB_API rig_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -184,7 +186,7 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->get_ctcss_tone(rig, vfo, tone); @@ -195,7 +197,7 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -228,6 +230,7 @@ int HAMLIB_API rig_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -247,7 +250,7 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->set_dcs_code(rig, vfo, code); @@ -258,7 +261,7 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -290,6 +293,7 @@ int HAMLIB_API rig_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code) int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -309,7 +313,7 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->get_dcs_code(rig, vfo, code); @@ -320,7 +324,7 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -360,6 +364,7 @@ int HAMLIB_API rig_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code) int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -379,7 +384,7 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->set_ctcss_sql(rig, vfo, tone); @@ -390,7 +395,7 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -427,6 +432,7 @@ int HAMLIB_API rig_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -446,7 +452,7 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->get_ctcss_sql(rig, vfo, tone); @@ -457,7 +463,7 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -489,6 +495,7 @@ int HAMLIB_API rig_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -508,7 +515,7 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->set_dcs_sql(rig, vfo, code); @@ -519,7 +526,7 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -551,6 +558,7 @@ int HAMLIB_API rig_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) { const struct rig_caps *caps; + struct rig_state *rs = STATE(rig); int retcode; vfo_t curr_vfo; @@ -570,7 +578,7 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) if ((caps->targetable_vfo & RIG_TARGETABLE_TONE) || vfo == RIG_VFO_CURR - || vfo == rig->state.current_vfo) + || vfo == rs->current_vfo) { return caps->get_dcs_sql(rig, vfo, code); @@ -581,7 +589,7 @@ int HAMLIB_API rig_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *code) return -RIG_ENTARGET; } - curr_vfo = rig->state.current_vfo; + curr_vfo = rs->current_vfo; retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK)