From 878117ab1f342d0e04b7bbd9998accb30665bbee Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Thu, 15 Feb 2024 21:50:21 -0500 Subject: [PATCH 1/3] Convert all port references in amplifiers/ to pointers. --- amplifiers/elecraft/kpa.c | 27 ++++++++++----------------- amplifiers/elecraft/kpa1500.c | 4 +--- amplifiers/expert/expert.c | 29 ++++++++++------------------- amplifiers/gemini/dx1200.c | 4 +--- amplifiers/gemini/gemini.c | 19 ++++++------------- 5 files changed, 28 insertions(+), 55 deletions(-) diff --git a/amplifiers/elecraft/kpa.c b/amplifiers/elecraft/kpa.c index c2c7ea44e..842f77c57 100644 --- a/amplifiers/elecraft/kpa.c +++ b/amplifiers/elecraft/kpa.c @@ -74,7 +74,7 @@ int kpa_init(AMP *amp) return -RIG_ENOMEM; } - amp->state.ampport.type.rig = RIG_PORT_SERIAL; + AMPPORT(amp)->type.rig = RIG_PORT_SERIAL; return RIG_OK; } @@ -92,18 +92,14 @@ int kpa_close(AMP *amp) int kpa_flushbuffer(AMP *amp) { - struct amp_state *rs; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rs = &->state; - - return rig_flush(&rs->ampport); + return rig_flush(AMPPORT(amp)); } int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) { - struct amp_state *rs; + hamlib_port_t *ampp = AMPPORT(amp); int err; int len = 0; int loop; @@ -114,19 +110,17 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) kpa_flushbuffer(amp); - rs = &->state; - loop = 3; do // wake up the amp by sending ; until we receive ; { char c = ';'; rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); - err = write_block(&rs->ampport, (unsigned char *) &c, 1); + err = write_block(ampp, (unsigned char *) &c, 1); if (err != RIG_OK) { return err; } - len = read_string(&rs->ampport, (unsigned char *) response, response_len, ";", + len = read_string(ampp, (unsigned char *) response, response_len, ";", 1, 0, 1); if (len < 0) { return len; } @@ -134,14 +128,14 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) while (--loop > 0 && (len != 1 || response[0] != ';')); // Now send our command - err = write_block(&rs->ampport, (unsigned char *) cmd, strlen(cmd)); + err = write_block(ampp, (unsigned char *) cmd, strlen(cmd)); if (err != RIG_OK) { return err; } if (response) // if response expected get it { response[0] = 0; - len = read_string(&rs->ampport, (unsigned char *) response, response_len, ";", + len = read_string(ampp, (unsigned char *) response, response_len, ";", 1, 0, 1); if (len < 0) @@ -164,11 +158,11 @@ int kpa_transaction(AMP *amp, const char *cmd, char *response, int response_len) { char c = ';'; rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); - err = write_block(&rs->ampport, (unsigned char *) &c, 1); + err = write_block(ampp, (unsigned char *) &c, 1); if (err != RIG_OK) { return err; } - len = read_string(&rs->ampport, (unsigned char *) responsebuf, KPABUFSZ, ";", 1, + len = read_string(ampp, (unsigned char *) responsebuf, KPABUFSZ, ";", 1, 0, 1); if (len < 0) { return len; } @@ -277,7 +271,6 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) int pwrinput; float float_value = 0; int int_value = 0, int_value2 = 0; - struct amp_state *rs = &->state; struct kpa_priv_data *priv = amp->state.priv; @@ -373,7 +366,7 @@ int kpa_get_level(AMP *amp, setting_t level, value_t *val) // do { - retval = read_string(&rs->ampport, (unsigned char *) responsebuf, + retval = read_string(AMPPORT(amp), (unsigned char *) responsebuf, sizeof(responsebuf), ";", 1, 0, 1); diff --git a/amplifiers/elecraft/kpa1500.c b/amplifiers/elecraft/kpa1500.c index f53d4c85a..bcdbed910 100644 --- a/amplifiers/elecraft/kpa1500.c +++ b/amplifiers/elecraft/kpa1500.c @@ -109,7 +109,6 @@ const struct amp_caps kpa1500_amp_caps = static int kpa1500_send_priv_cmd(AMP *amp, const char *cmdstr) { - struct amp_state *rs; int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -119,8 +118,7 @@ static int kpa1500_send_priv_cmd(AMP *amp, const char *cmdstr) return -RIG_EINVAL; } - rs = &->state; - err = write_block(&rs->ampport, cmdstr, strlen(cmdstr)); + err = write_block(AMPPORT(amp), cmdstr, strlen(cmdstr)); if (err != RIG_OK) { diff --git a/amplifiers/expert/expert.c b/amplifiers/expert/expert.c index 756cb7b49..059e5f887 100644 --- a/amplifiers/expert/expert.c +++ b/amplifiers/expert/expert.c @@ -76,7 +76,7 @@ int expert_init(AMP *amp) return -RIG_ENOMEM; } - amp->state.ampport.type.rig = RIG_PORT_SERIAL; + AMPPORT(amp)->type.rig = RIG_PORT_SERIAL; return RIG_OK; } @@ -111,19 +111,15 @@ int expert_close(AMP *amp) int expert_flushbuffer(AMP *amp) { - struct amp_state *rs; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rs = &->state; - - return rig_flush(&rs->ampport); + return rig_flush(AMPPORT(amp)); } int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, unsigned char *response, int response_len) { - struct amp_state *rs; + hamlib_port_t *ampp = AMPPORT(amp); int err; int len = 0; char cmdbuf[64]; @@ -140,8 +136,6 @@ int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, expert_flushbuffer(amp); - rs = &->state; - cmdbuf[0] = cmdbuf[1] = cmdbuf[2] = 0x55; for (int i = 0; i < cmd_len; ++i) { checksum += cmd[i]; } @@ -152,7 +146,7 @@ int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, cmdbuf[3 + cmd_len + 1] = checksum; // Now send our command - err = write_block(&rs->ampport, (unsigned char *) cmdbuf, 3 + cmd_len + 2); + err = write_block(ampp, (unsigned char *) cmdbuf, 3 + cmd_len + 2); if (err != RIG_OK) { return err; } @@ -161,7 +155,7 @@ int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, int bytes = 0; response[0] = 0; // read the 4-byte header x55x55x55xXX where XX is the hex # of bytes - len = read_block_direct(&rs->ampport, (unsigned char *) response, 4); + len = read_block_direct(ampp, (unsigned char *) response, 4); rig_debug(RIG_DEBUG_ERR, "%s: len=%d, bytes=%02x\n", __func__, len, response[3]); @@ -175,7 +169,7 @@ int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, if (len == 4) { bytes = response[3]; } rig_debug(RIG_DEBUG_ERR, "%s: bytes=%d\n", __func__, bytes); - len = read_block_direct(&rs->ampport, (unsigned char *) response, bytes - 3); + len = read_block_direct(ampp, (unsigned char *) response, bytes - 3); dump_hex(response, len); } else // if no response expected try to get one @@ -188,11 +182,11 @@ int expert_transaction(AMP *amp, const unsigned char *cmd, int cmd_len, { char c = ';'; rig_debug(RIG_DEBUG_VERBOSE, "%s waiting for ;\n", __func__); - err = write_block(&rs->ampport, (unsigned char *) &c, 1); + err = write_block(ampp, (unsigned char *) &c, 1); if (err != RIG_OK) { return err; } - len = read_string(&rs->ampport, (unsigned char *) responsebuf, KPABUFSZ, ";", 1, + len = read_string(ampp, (unsigned char *) responsebuf, KPABUFSZ, ";", 1, 0, 1); if (len < 0) { return len; } @@ -302,7 +296,6 @@ int expert_get_level(AMP *amp, setting_t level, value_t *val) int pwrinput; float float_value = 0; int int_value = 0, int_value2 = 0; - struct amp_state *rs = &->state; struct expert_priv_data *priv = amp->state.priv; @@ -400,7 +393,7 @@ int expert_get_level(AMP *amp, setting_t level, value_t *val) // do { - retval = read_string(&rs->ampport, (unsigned char *) responsebuf, + retval = read_string(AMPPORT(amp), (unsigned char *) responsebuf, sizeof(responsebuf), ";", 1, 0, 1); @@ -723,7 +716,6 @@ const struct amp_caps expert_amp_caps = static int expert_send_priv_cmd(AMP *amp, const char *cmdstr) { - struct amp_state *rs; int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -733,8 +725,7 @@ static int expert_send_priv_cmd(AMP *amp, const char *cmdstr) return -RIG_EINVAL; } - rs = &->state; - err = write_block(&rs->ampport, cmdstr, strlen(cmdstr)); + err = write_block(AMPPORT(amp), cmdstr, strlen(cmdstr)); if (err != RIG_OK) { diff --git a/amplifiers/gemini/dx1200.c b/amplifiers/gemini/dx1200.c index a685453ba..ba41d370e 100644 --- a/amplifiers/gemini/dx1200.c +++ b/amplifiers/gemini/dx1200.c @@ -104,7 +104,6 @@ const struct amp_caps gemini_amp_caps = static int gemini_send_priv_cmd(AMP *amp, const char *cmdstr) { - struct amp_state *rs; int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -114,8 +113,7 @@ static int gemini_send_priv_cmd(AMP *amp, const char *cmdstr) return -RIG_EINVAL; } - rs = &->state; - err = write_block(&rs->ampport, cmdstr, strlen(cmdstr)); + err = write_block(AMPPORT(amp), cmdstr, strlen(cmdstr)); if (err != RIG_OK) { diff --git a/amplifiers/gemini/gemini.c b/amplifiers/gemini/gemini.c index df7ad27f7..ad8c3e856 100644 --- a/amplifiers/gemini/gemini.c +++ b/amplifiers/gemini/gemini.c @@ -53,7 +53,7 @@ int gemini_init(AMP *amp) return -RIG_ENOMEM; } - amp->state.ampport.type.rig = RIG_PORT_NETWORK; + AMPPORT(amp)->type.rig = RIG_PORT_NETWORK; return RIG_OK; } @@ -71,20 +71,16 @@ int gemini_close(AMP *amp) int gemini_flushbuffer(AMP *amp) { - struct amp_state *rs; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rs = &->state; - - return rig_flush(&rs->ampport); + return rig_flush(AMPPORT(amp)); } int gemini_transaction(AMP *amp, const char *cmd, char *response, int response_len) { - struct amp_state *rs; + hamlib_port_t *ampp = AMPPORT(amp); int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called, cmd=%s\n", __func__, cmd); @@ -93,19 +89,16 @@ int gemini_transaction(AMP *amp, const char *cmd, char *response, gemini_flushbuffer(amp); - rs = &->state; - // Now send our command - err = write_block(&rs->ampport, (unsigned char *) cmd, strlen(cmd)); + err = write_block(ampp, (unsigned char *) cmd, strlen(cmd)); if (err != RIG_OK) { return err; } if (response) // if response expected get it { response[0] = 0; - int len = read_string(&rs->ampport, (unsigned char *) response, response_len, - "\n", - 1, 0, 1); + int len = read_string(ampp, (unsigned char *) response, response_len, + "\n", 1, 0, 1); if (len < 0) { From f247ee20888acb9dfb66f9e4455fbc14a2d41d36 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Fri, 16 Feb 2024 05:23:20 -0500 Subject: [PATCH 2/3] Convert first part of rotators/ --- rotators/amsat/if100.c | 2 +- rotators/ars/ars.c | 16 ++++++++-------- rotators/celestron/celestron.c | 12 +++++------- rotators/easycomm/easycomm.c | 10 ++++------ rotators/ether6/ether6.c | 7 ++++--- rotators/fodtrack/fodtrack.c | 2 +- rotators/grbltrk/grbltrk.c | 15 ++++++++------- rotators/gs232a/gs232.c | 16 +++++++--------- rotators/gs232a/gs232a.c | 14 ++++++-------- rotators/gs232a/gs232b.c | 16 +++++++--------- rotators/heathkit/hd1780.c | 15 ++++----------- rotators/ioptron/rot_ioptron.c | 12 +++++------- rotators/m2/rc2800.c | 16 +++++++--------- rotators/meade/meade.c | 14 ++++++-------- 14 files changed, 73 insertions(+), 94 deletions(-) diff --git a/rotators/amsat/if100.c b/rotators/amsat/if100.c index 83b244009..50ed2d04f 100644 --- a/rotators/amsat/if100.c +++ b/rotators/amsat/if100.c @@ -33,7 +33,7 @@ static int if100_set_position(ROT *rot, azimuth_t az, elevation_t el) { - hamlib_port_t *port = &rot->state.rotport; + hamlib_port_t *port = ROTPORT(rot); int retval; int az_i; int el_i; diff --git a/rotators/ars/ars.c b/rotators/ars/ars.c index 386d3778a..c8e2f8a3c 100644 --- a/rotators/ars/ars.c +++ b/rotators/ars/ars.c @@ -71,7 +71,7 @@ */ #define CHKPPRET(a) \ do { int _retval = a; if (_retval != RIG_OK) \ - {par_unlock (&rot->state.rotport);return _retval; }} while(0) + {par_unlock (ROTPORT(rot));return _retval; }} while(0) static int ars_init(ROT *rot); static int ars_cleanup(ROT *rot); @@ -91,7 +91,7 @@ static void *handle_set_position(void *); static int ars_clear_ctrl_pin(ROT *rot, unsigned char pin) { - hamlib_port_t *pport = &rot->state.rotport; + hamlib_port_t *pport = ROTPORT(rot); struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; priv->pp_control &= ~pin; @@ -101,7 +101,7 @@ static int ars_clear_ctrl_pin(ROT *rot, unsigned char pin) static int ars_set_ctrl_pin(ROT *rot, unsigned char pin) { - hamlib_port_t *pport = &rot->state.rotport; + hamlib_port_t *pport = ROTPORT(rot); struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; priv->pp_control |= pin; @@ -111,7 +111,7 @@ static int ars_set_ctrl_pin(ROT *rot, unsigned char pin) static int ars_clear_data_pin(ROT *rot, unsigned char pin) { - hamlib_port_t *pport = &rot->state.rotport; + hamlib_port_t *pport = ROTPORT(rot); struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; priv->pp_data &= ~pin; @@ -121,7 +121,7 @@ static int ars_clear_data_pin(ROT *rot, unsigned char pin) static int ars_set_data_pin(ROT *rot, unsigned char pin) { - hamlib_port_t *pport = &rot->state.rotport; + hamlib_port_t *pport = ROTPORT(rot); struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; priv->pp_data |= pin; @@ -235,7 +235,7 @@ int ars_stop(ROT *rot) { struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; - hamlib_port_t *pport = &rot->state.rotport; + hamlib_port_t *pport = ROTPORT(rot); rig_debug(RIG_DEBUG_TRACE, "%s called, brake was %s\n", __func__, priv->brake_off ? "OFF" : "ON"); @@ -265,7 +265,7 @@ int ars_move(ROT *rot, int direction, int speed) { struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; - hamlib_port_t *pport = &rot->state.rotport; + hamlib_port_t *pport = ROTPORT(rot); int need_settle_delay = 0; rig_debug(RIG_DEBUG_TRACE, "%s called%s%s%s%s%s\n", __func__, @@ -608,7 +608,7 @@ ars_get_position(ROT *rot, azimuth_t *az, elevation_t *el) { const struct ars_priv_data *priv = (struct ars_priv_data *)rot->state.priv; struct rot_state *rs = &rot->state; - hamlib_port_t *pport = &rs->rotport; + hamlib_port_t *pport = ROTPORT(rot); int i, num_sample; unsigned az_samples[NUM_SAMPLES], az_value; unsigned el_samples[NUM_SAMPLES], el_value; diff --git a/rotators/celestron/celestron.c b/rotators/celestron/celestron.c index e7608a74d..40d0eb923 100644 --- a/rotators/celestron/celestron.c +++ b/rotators/celestron/celestron.c @@ -50,20 +50,18 @@ static int celestron_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; char replybuf[BUFSZ]; - rs = &rot->state; - transaction_write: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -84,12 +82,12 @@ transaction_write: /* the answer */ memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + retval = read_string(rotp, (unsigned char *) data, data_len, ACK, strlen(ACK), 0, 1); if (retval < 0) { - if (retry_read++ < rot->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } diff --git a/rotators/easycomm/easycomm.c b/rotators/easycomm/easycomm.c index 1fc846c34..defe6a4f7 100644 --- a/rotators/easycomm/easycomm.c +++ b/rotators/easycomm/easycomm.c @@ -48,7 +48,7 @@ static int easycomm_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry = rot->caps->retry; @@ -59,12 +59,10 @@ easycomm_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) return -RIG_EINVAL; } - rs = &rot->state; - do { - rig_flush(&rs->rotport); - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + rig_flush(rotp); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -76,7 +74,7 @@ easycomm_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) return RIG_OK; /* don't want a reply */ } - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + retval = read_string(rotp, (unsigned char *) data, data_len, "\n", 1, 0, 1); if (retval < 0) diff --git a/rotators/ether6/ether6.c b/rotators/ether6/ether6.c index 94b6a14d5..8c71914da 100644 --- a/rotators/ether6/ether6.c +++ b/rotators/ether6/ether6.c @@ -42,8 +42,9 @@ static int ether_transaction(ROT *rot, char *cmd, int len, char *buf) { int ret; + hamlib_port_t *rotp = ROTPORT(rot); - ret = write_block(&rot->state.rotport, (unsigned char *) cmd, len); + ret = write_block(rotp, (unsigned char *) cmd, len); rig_debug(RIG_DEBUG_VERBOSE, "function %s(1): ret=%d || send=%s\n", __func__, ret, cmd); @@ -52,7 +53,7 @@ static int ether_transaction(ROT *rot, char *cmd, int len, char *buf) return ret; } - ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, + ret = read_string(rotp, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1); rig_debug(RIG_DEBUG_VERBOSE, "function %s(2): ret=%d || receive=%s\n", __func__, ret, buf); @@ -118,7 +119,7 @@ static int ether_rot_close(ROT *rot) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); /* clean signoff, no read back */ - write_block(&rot->state.rotport, (unsigned char *) "\n", 1); + write_block(ROTPORT(rot), (unsigned char *) "\n", 1); return RIG_OK; } diff --git a/rotators/fodtrack/fodtrack.c b/rotators/fodtrack/fodtrack.c index 1d570235f..ce5317ab9 100644 --- a/rotators/fodtrack/fodtrack.c +++ b/rotators/fodtrack/fodtrack.c @@ -144,7 +144,7 @@ fodtrack_set_position(ROT *rot, azimuth_t az, elevation_t el) rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __func__, az, el); - pport = &rot->state.rotport; + pport = ROTPORT(rot); retval = setDirection(pport, el / (float)rot->state.max_el * 255.0, 0); diff --git a/rotators/grbltrk/grbltrk.c b/rotators/grbltrk/grbltrk.c index 2ab2c1777..795cc7ef3 100644 --- a/rotators/grbltrk/grbltrk.c +++ b/rotators/grbltrk/grbltrk.c @@ -116,6 +116,7 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, uint32_t *resp_size) { static int fail_count = 0; + hamlib_port_t *rotp = ROTPORT(rot); rot_debug(RIG_DEBUG_ERR, "req: [%s][%d]\n", request, fail_count); @@ -125,7 +126,7 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, int retval; //fprintf(stderr, "ctrl by serial/network\n"); - if ((retval = write_block(&rot->state.rotport, (unsigned char *)request, + if ((retval = write_block(rotp, (unsigned char *)request, req_size)) != RIG_OK) { rot_debug(RIG_DEBUG_ERR, "%s write_block fail!\n", __func__); @@ -138,11 +139,11 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, fail_count = 0; } - rig_flush(&rot->state.rotport); + rig_flush(rotp); usleep(300000); - if ((retval = read_string(&rot->state.rotport, (unsigned char *)response, 1024, + if ((retval = read_string(rotp, (unsigned char *)response, 1024, "\n", 1, 0, 1)) < 0) { rot_debug(RIG_DEBUG_ERR, "%s read_string fail! (%d) \n", __func__, retval); @@ -161,7 +162,7 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, return -RIG_EPROTO; } - rig_flush(&rot->state.rotport); + rig_flush(rotp); rot_debug(RIG_DEBUG_ERR, "rsp: [%s]\n", response); //fprintf(stderr, "rsp: [%s]\n", response); @@ -461,9 +462,9 @@ grbltrk_rot_init(ROT *rot) static int grbl_net_open(ROT *rot, int port) { - //network_open(&rot->state.rotport, port); + //network_open(ROTPORT(rot), port); - //rot_debug(RIG_DEBUG_ERR, "%s:%d network_fd: %d\n", __func__, __LINE__, (&rot->state.rotport)->fd); + //rot_debug(RIG_DEBUG_ERR, "%s:%d network_fd: %d\n", __func__, __LINE__, ROTPORT(rot)->fd); rot_debug(RIG_DEBUG_ERR, "%s:%d \n", __func__, __LINE__); return 0; @@ -514,7 +515,7 @@ grbltrk_rot_open(ROT *rot) static void grbl_net_close(ROT *rot) { - port_close(&rot->state.rotport, RIG_PORT_NETWORK); + port_close(ROTPORT(rot), RIG_PORT_NETWORK); } static int diff --git a/rotators/gs232a/gs232.c b/rotators/gs232a/gs232.c index 977c12b70..e58a916c6 100644 --- a/rotators/gs232a/gs232.c +++ b/rotators/gs232a/gs232.c @@ -52,19 +52,17 @@ static int gs232_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; - rs = &rot->state; - transaction_write: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -84,12 +82,12 @@ transaction_write: } memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + retval = read_string(rotp, (unsigned char *) data, data_len, REPLY_EOM, strlen(REPLY_EOM), 0, 1); if (retval < 0) { - if (retry_read++ < rot->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } @@ -105,7 +103,7 @@ transaction_write: rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n", __func__, data); - if (retry_read++ < rig->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } @@ -139,7 +137,7 @@ static int gs232_wo_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - return write_block(&rot->state.rotport, (unsigned char *) cmdstr, + return write_block(ROTPORT(rot), (unsigned char *) cmdstr, strlen(cmdstr)); } diff --git a/rotators/gs232a/gs232a.c b/rotators/gs232a/gs232a.c index 254892210..f7044f55e 100644 --- a/rotators/gs232a/gs232a.c +++ b/rotators/gs232a/gs232a.c @@ -64,19 +64,17 @@ static int gs232a_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len, int no_reply) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; - rs = &rot->state; - transaction_write: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -98,7 +96,7 @@ transaction_write: if (!no_reply) { memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + retval = read_string(rotp, (unsigned char *) data, data_len, REPLY_EOM, strlen(REPLY_EOM), 0, 1); if (strncmp(data, "\r\n", 2) == 0 @@ -112,7 +110,7 @@ transaction_write: if (retval < 0) { - if (retry_read++ < rot->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } @@ -129,7 +127,7 @@ transaction_write: rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n", __func__, data); - if (retry_read++ < rig->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } diff --git a/rotators/gs232a/gs232b.c b/rotators/gs232a/gs232b.c index a0872d44c..a732ab2f7 100644 --- a/rotators/gs232a/gs232b.c +++ b/rotators/gs232a/gs232b.c @@ -60,19 +60,17 @@ static int gs232b_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len, int no_reply) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; - rs = &rot->state; - transaction_write: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -81,7 +79,7 @@ transaction_write: if (!data) { - write_block(&rs->rotport, (unsigned char *) EOM, strlen(EOM)); + write_block(rotp, (unsigned char *) EOM, strlen(EOM)); } } @@ -100,7 +98,7 @@ transaction_write: memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + retval = read_string(rotp, (unsigned char *) data, data_len, REPLY_EOM, strlen(REPLY_EOM), 0, 1); if (strncmp(data, "\r\n", 2) == 0 || strchr(data, '>')) @@ -114,7 +112,7 @@ transaction_write: if (retval < 0) { - if (retry_read++ < rot->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } @@ -131,7 +129,7 @@ transaction_write: "%s: Command is not correctly terminated '%s'\n", __func__, data); - if (retry_read++ < rig->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } diff --git a/rotators/heathkit/hd1780.c b/rotators/heathkit/hd1780.c index 174dff9e5..843bbbf2b 100644 --- a/rotators/heathkit/hd1780.c +++ b/rotators/heathkit/hd1780.c @@ -125,7 +125,7 @@ static int hd1780_rot_init(ROT *rot) priv = rot->state.priv; - rot->state.rotport.type.rig = RIG_PORT_SERIAL; + ROTPORT(rot)->type.rig = RIG_PORT_SERIAL; priv->az = 0; @@ -166,7 +166,6 @@ static int hd1780_rot_cleanup(ROT *rot) static int hd1780_rot_set_position(ROT *rot, azimuth_t azimuth, elevation_t elevation) { - struct rot_state *rs; char cmdstr[8]; const char execstr[5] = "\r", ok[3]; int err; @@ -203,8 +202,7 @@ static int hd1780_rot_set_position(ROT *rot, azimuth_t azimuth, /* We need to look for the + to signify that everything finished. The HD 1780 * sends a when it is finished rotating. */ - rs = &rot->state; - err = read_block(&rs->rotport, (unsigned char *) ok, 2); + err = read_block(ROTPORT(rot), (unsigned char *) ok, 2); if (err != 2) { @@ -231,7 +229,6 @@ static int hd1780_rot_set_position(ROT *rot, azimuth_t azimuth, static int hd1780_rot_get_position(ROT *rot, azimuth_t *azimuth, elevation_t *elevation) { - struct rot_state *rs; const char cmdstr[3] = "b\r"; char az[7]; /* read azimuth string */ char *p; @@ -252,8 +249,7 @@ static int hd1780_rot_get_position(ROT *rot, azimuth_t *azimuth, return err; } - rs = &rot->state; - err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN); + err = read_block(ROTPORT(rot), (unsigned char *) az, AZ_READ_LEN); if (err != AZ_READ_LEN) { @@ -300,7 +296,6 @@ static int hd1780_rot_get_position(ROT *rot, azimuth_t *azimuth, static int hd1780_send_priv_cmd(ROT *rot, const char *cmdstr) { - struct rot_state *rs; int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -310,9 +305,7 @@ static int hd1780_send_priv_cmd(ROT *rot, const char *cmdstr) return -RIG_EINVAL; } - rs = &rot->state; - - err = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + err = write_block(ROTPORT(rot), (unsigned char *) cmdstr, strlen(cmdstr)); if (err != RIG_OK) { diff --git a/rotators/ioptron/rot_ioptron.c b/rotators/ioptron/rot_ioptron.c index f46d58612..c921dbca0 100644 --- a/rotators/ioptron/rot_ioptron.c +++ b/rotators/ioptron/rot_ioptron.c @@ -63,19 +63,17 @@ static int ioptron_transaction(ROT *rot, const char *cmdstr, char *data, size_t resp_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval = 0; int retry_read; - rs = &rot->state; - - for (retry_read = 0; retry_read <= rot->state.rotport.retry; retry_read++) + for (retry_read = 0; retry_read <= rotp->retry; retry_read++) { - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -85,7 +83,7 @@ ioptron_transaction(ROT *rot, const char *cmdstr, char *data, size_t resp_len) /** the answer */ memset(data, 0, resp_len + 1); - retval = read_block(&rs->rotport, (unsigned char *) data, resp_len); + retval = read_block(rotp, (unsigned char *) data, resp_len); /** if expected number of bytes received, return OK status */ if (retval == resp_len) diff --git a/rotators/m2/rc2800.c b/rotators/m2/rc2800.c index 21816bfed..edfb6980b 100644 --- a/rotators/m2/rc2800.c +++ b/rotators/m2/rc2800.c @@ -163,20 +163,18 @@ static int rc2800_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; char replybuf[BUFSZ]; - rs = &rot->state; - transaction_write: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -197,7 +195,7 @@ transaction_write: /* then comes the answer */ memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, CR LF, + retval = read_string(rotp, (unsigned char *) data, data_len, CR LF, strlen(CR LF), 0, 1); // some models seem to echo -- so we'll check and read again if echoed @@ -205,7 +203,7 @@ transaction_write: if (cmdstr && strncmp(data, cmdstr, strlen(data) - 1) == 0) { memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, CR LF, + retval = read_string(rotp, (unsigned char *) data, data_len, CR LF, strlen(CR LF), 0, 1); } @@ -213,13 +211,13 @@ transaction_write: if (strlen(data) == 1) { memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, CR LF, + retval = read_string(rotp, (unsigned char *) data, data_len, CR LF, strlen(CR LF), 0, 1); } if (retval < 0) { - if (retry_read++ < rot->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } diff --git a/rotators/meade/meade.c b/rotators/meade/meade.c index dff52ac3e..5c43fddab 100644 --- a/rotators/meade/meade.c +++ b/rotators/meade/meade.c @@ -96,20 +96,18 @@ struct meade_priv_data static int meade_transaction(ROT *rot, const char *cmdstr, char *data, size_t *data_len, size_t expected_return_length) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int return_value; int retry_read = 0; - rs = &rot->state; - while (1) { transaction: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - return_value = write_block(&rs->rotport, (unsigned char *) cmdstr, + return_value = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (return_value != RIG_OK) @@ -123,7 +121,7 @@ transaction: return value is expected, Strings end with '#' */ if (data != NULL) { - return_value = read_string(&rs->rotport, (unsigned char *) data, + return_value = read_string(rotp, (unsigned char *) data, expected_return_length + 1, "\r\n", strlen("\r\n"), 0, 1); @@ -134,7 +132,7 @@ transaction: } else { - if (retry_read++ >= rot->state.rotport.retry) + if (retry_read++ >= rotp->retry) { rig_debug(RIG_DEBUG_ERR, "%s: read_string error %s\n", __func__, rigerror(return_value)); @@ -173,7 +171,7 @@ static int meade_init(ROT *rot) rig_debug(RIG_DEBUG_VERBOSE, "%s called version %s\n", __func__, rot->caps->version); - rot->state.rotport.type.rig = RIG_PORT_SERIAL; + ROTPORT(rot)->type.rig = RIG_PORT_SERIAL; priv->az = priv->el = 0; From 8ff07c47f9d0c3cf13aaed05dfcc9607933ba014 Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Sun, 18 Feb 2024 05:47:04 -0500 Subject: [PATCH 3/3] Finish rotators/ --- rotators/apex/apex.c | 9 +++--- rotators/apex/sharedloop.c | 6 ++-- rotators/flir/flir.c | 9 +++--- rotators/prosistel/prosistel.c | 12 +++---- rotators/radant/radant.c | 10 +++--- rotators/rotorez/rotorez.c | 54 +++++++++++++------------------- rotators/saebrtrack/saebrtrack.c | 9 +++--- rotators/sartek/sartek.c | 4 +-- rotators/satel/satel.c | 41 +++++++----------------- rotators/spid/spid.c | 39 +++++++++++------------ rotators/ts7400/ts7400.c | 2 +- 11 files changed, 81 insertions(+), 114 deletions(-) diff --git a/rotators/apex/apex.c b/rotators/apex/apex.c index 37b2bec23..04f803f05 100644 --- a/rotators/apex/apex.c +++ b/rotators/apex/apex.c @@ -19,12 +19,11 @@ static pthread_t apex_read_thread; static int apex_get_string(ROT *rot, char *s, int maxlen) { int retval = 0; - struct rot_state *rs = &rot->state; char buf[64]; memset(s, 0, maxlen); - retval = read_string(&rs->rotport, (unsigned char *)buf, + retval = read_string(ROTPORT(rot), (unsigned char *)buf, sizeof(buf), "\n", strlen("\n"), sizeof(buf), 1); strncpy(s, buf, 64); @@ -98,13 +97,13 @@ int apex_open(ROT *rot) { int retval; char *cmdstr = "[GETVER]\r"; // does this work on all Apex controllers? - struct rot_state *rs = &rot->state; + hamlib_port_t *rotp = ROTPORT(rot); rig_debug(RIG_DEBUG_VERBOSE, "%s: entered\n", __func__); apex_azimuth = -1; // we check to see if we've seen azimuth at least one time - rig_flush(&rs->rotport); - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + rig_flush(rotp); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { diff --git a/rotators/apex/sharedloop.c b/rotators/apex/sharedloop.c index d8b9d3bad..5fa8eb865 100644 --- a/rotators/apex/sharedloop.c +++ b/rotators/apex/sharedloop.c @@ -25,7 +25,7 @@ int apex_shared_loop_set_position(ROT *rot, float az, float dummy) { char cmdstr[16]; int retval; - struct rot_state *rs = &rot->state; + hamlib_port_t *rotp = ROTPORT(rot); int remainder = lround(az + 22.5) % 45; int apex_az = lround(az + 22.5) - remainder; @@ -53,9 +53,9 @@ int apex_shared_loop_set_position(ROT *rot, float az, float dummy) return -RIG_EINTERNAL; } - rig_flush(&rs->rotport); + rig_flush(rotp); apex_azimuth = -1; - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { diff --git a/rotators/flir/flir.c b/rotators/flir/flir.c index c2de2baae..9d3c3a2da 100644 --- a/rotators/flir/flir.c +++ b/rotators/flir/flir.c @@ -71,14 +71,15 @@ static int flir_request(ROT *rot, char *request, char *response, int resp_size) { int return_value = -RIG_EINVAL; + hamlib_port_t *rotp = ROTPORT(rot); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - rig_flush(&rot->state.rotport); + rig_flush(rotp); if (request) { - return_value = write_block(&rot->state.rotport, (unsigned char *)request, + return_value = write_block(rotp, (unsigned char *)request, strlen(request)); if (return_value != RIG_OK) @@ -94,10 +95,10 @@ static int flir_request(ROT *rot, char *request, char *response, int retry_read = 0; int read_char; - while (retry_read < rot->state.rotport.retry) + while (retry_read < rotp->retry) { memset(response, 0, (size_t)resp_size); - read_char = read_string(&rot->state.rotport, (unsigned char *)response, + read_char = read_string(rotp, (unsigned char *)response, resp_size, "\r\n", sizeof("\r\n"), 0, 1); diff --git a/rotators/prosistel/prosistel.c b/rotators/prosistel/prosistel.c index de0c85077..7bf7871a2 100644 --- a/rotators/prosistel/prosistel.c +++ b/rotators/prosistel/prosistel.c @@ -62,20 +62,18 @@ struct prosistel_rot_priv_caps static int prosistel_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; char replybuf[BUFSZ]; - rs = &rot->state; - transaction_write: - rig_flush(&rs->rotport); + rig_flush(rotp); if (cmdstr) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -95,12 +93,12 @@ transaction_write: } // Remember to check for STXA,G,R or STXA,?,XXX,R 10 bytes - retval = read_string(&rs->rotport, (unsigned char *) data, 20, CR, strlen(CR), + retval = read_string(rotp, (unsigned char *) data, 20, CR, strlen(CR), 0, 1); if (retval < 0) { - if (retry_read++ < rot->state.rotport.retry) + if (retry_read++ < rotp->retry) { goto transaction_write; } diff --git a/rotators/radant/radant.c b/rotators/radant/radant.c index 52985ab21..b8203ef1f 100644 --- a/rotators/radant/radant.c +++ b/rotators/radant/radant.c @@ -49,7 +49,7 @@ static int radant_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; rig_debug(RIG_DEBUG_TRACE, "%s called: %s\n", __func__, cmdstr); @@ -59,9 +59,8 @@ radant_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) return -RIG_EINVAL; } - rs = &rot->state; - rig_flush(&rs->rotport); - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + rig_flush(rotp); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -73,8 +72,7 @@ radant_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) return RIG_OK; /* don't want a reply */ } - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, "\n", 1, 0, - 1); + retval = read_string(rotp, (unsigned char *) data, data_len, "\n", 1, 0, 1); if (retval < 0) { diff --git a/rotators/rotorez/rotorez.c b/rotators/rotorez/rotorez.c index 371e10f45..ec4e559ca 100644 --- a/rotators/rotorez/rotorez.c +++ b/rotators/rotorez/rotorez.c @@ -421,7 +421,7 @@ static int rotorez_rot_init(ROT *rot) return -RIG_ENOMEM; } - rot->state.rotport.type.rig = RIG_PORT_SERIAL; + ROTPORT(rot)->type.rig = RIG_PORT_SERIAL; ((struct rotorez_rot_priv_data *)rot->state.priv)->az = 0; @@ -538,7 +538,7 @@ static int rt21_rot_set_position(ROT *rot, azimuth_t azimuth, return err; } - if (rot->state.rotport2.pathname[0] != 0) + if (ROTPORT2(rot)->pathname[0] != 0) { SNPRINTF(cmdstr, sizeof(cmdstr), "AP1%05.1f\r;", elevation); /* Total field width of 5 chars */ @@ -565,7 +565,8 @@ static int rt21_rot_set_position(ROT *rot, azimuth_t azimuth, static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, elevation_t *elevation) { - struct rot_state *rs; + hamlib_port_t *rotp; + hamlib_port_t *rotp2; const char cmdstr[5] = "AI1;"; char az[5]; /* read azimuth string */ char *p; @@ -578,6 +579,8 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, { return -RIG_EINVAL; } + rotp = ROTPORT(rot); + rotp2 = ROTPORT2(rot); do { @@ -588,9 +591,7 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, return err; } - rs = &rot->state; - - err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN); + err = read_block(rotp, (unsigned char *) az, AZ_READ_LEN); if (err != AZ_READ_LEN) { @@ -653,7 +654,7 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, *azimuth = tmp; - if (strlen(rot->state.rotport2.pathname) > 0) + if (strlen(rotp2->pathname) > 0) { do { @@ -664,9 +665,9 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, return err; } - rs = &rot->state; - - err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN); + //TODO: Should this be rotp or rotp2???? + //err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN); + err = read_block(rotp, (unsigned char *) az, AZ_READ_LEN); if (err != AZ_READ_LEN) { @@ -732,7 +733,6 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth, static int erc_rot_get_position(ROT *rot, azimuth_t *azimuth, elevation_t *elevation) { - struct rot_state *rs; const char cmdstr[5] = "AI1;"; char az[5]; /* read azimuth string */ char *p; @@ -755,9 +755,7 @@ static int erc_rot_get_position(ROT *rot, azimuth_t *azimuth, return err; } - rs = &rot->state; - - err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN); + err = read_block(ROTPORT(rot), (unsigned char *) az, AZ_READ_LEN); if (err != AZ_READ_LEN) { @@ -850,7 +848,8 @@ static int erc_rot_get_position(ROT *rot, azimuth_t *azimuth, static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth, elevation_t *elevation) { - struct rot_state *rs; + hamlib_port_t *rotp; + hamlib_port_t *rotp2; char az[8]; /* read azimuth string */ int err; @@ -860,6 +859,8 @@ static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth, { return -RIG_EINVAL; } + rotp = ROTPORT(rot); + rotp2 = ROTPORT2(rot); /* 'BI1' is an RT-21 specific command that queries for a floating * point position (to the tenth of a degree). @@ -871,9 +872,7 @@ static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth, return err; } - rs = &rot->state; - - err = read_string(&rs->rotport, (unsigned char *) az, RT21_AZ_LEN + 1, ";", + err = read_string(rotp, (unsigned char *) az, RT21_AZ_LEN + 1, ";", strlen(";"), 0, 1); if (err < 0) /* read_string returns negative on error. */ @@ -906,7 +905,7 @@ static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth, *azimuth = tmp; - if (strlen(rot->state.rotport2.pathname) > 0) + if (rotp2 && strlen(rotp2->pathname) > 0) { err = rotorez_send_priv_cmd2(rot, "BI1;"); @@ -915,9 +914,7 @@ static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth, return err; } - rs = &rot->state; - - err = read_string(&rs->rotport2, (unsigned char *) az, RT21_AZ_LEN + 1, ";", + err = read_string(rotp2, (unsigned char *) az, RT21_AZ_LEN + 1, ";", strlen(";"), 0, 1); if (err < 0) /* read_string returns negative on error. */ @@ -1134,7 +1131,6 @@ static const char *rotorez_rot_get_info(ROT *rot) static int rotorez_send_priv_cmd(ROT *rot, const char *cmdstr) { - struct rot_state *rs; int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1144,8 +1140,7 @@ static int rotorez_send_priv_cmd(ROT *rot, const char *cmdstr) return -RIG_EINVAL; } - rs = &rot->state; - err = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + err = write_block(ROTPORT(rot), (unsigned char *) cmdstr, strlen(cmdstr)); if (err != RIG_OK) { @@ -1158,7 +1153,6 @@ static int rotorez_send_priv_cmd(ROT *rot, const char *cmdstr) // send command to 2nd rotator port static int rotorez_send_priv_cmd2(ROT *rot, const char *cmdstr) { - struct rot_state *rs; int err; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -1168,8 +1162,7 @@ static int rotorez_send_priv_cmd2(ROT *rot, const char *cmdstr) return -RIG_EINVAL; } - rs = &rot->state; - err = write_block(&rs->rotport2, (unsigned char *) cmdstr, strlen(cmdstr)); + err = write_block(ROTPORT2(rot), (unsigned char *) cmdstr, strlen(cmdstr)); if (err != RIG_OK) { @@ -1193,7 +1186,6 @@ static int rotorez_send_priv_cmd2(ROT *rot, const char *cmdstr) static int rotorez_flush_buffer(ROT *rot) { - struct rot_state *rs; char garbage[32]; /* read buffer */ int err = 0; size_t MAX = 31; @@ -1205,11 +1197,9 @@ static int rotorez_flush_buffer(ROT *rot) return -RIG_EINVAL; } - rs = &rot->state; - do { - err = read_block(&rs->rotport, (unsigned char *) garbage, MAX); + err = read_block(ROTPORT(rot), (unsigned char *) garbage, MAX); /* Oops! An IO error was encountered. Bail out! */ if (err == -RIG_EIO) diff --git a/rotators/saebrtrack/saebrtrack.c b/rotators/saebrtrack/saebrtrack.c index 5ecdb35cc..4baa4a8f9 100644 --- a/rotators/saebrtrack/saebrtrack.c +++ b/rotators/saebrtrack/saebrtrack.c @@ -49,7 +49,7 @@ static int saebrtrack_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { - struct rot_state *rs; + hamlib_port_t *rotp = ROTPORT(rot); int retval; rig_debug(RIG_DEBUG_TRACE, "%s called: %s\n", __func__, cmdstr); @@ -59,9 +59,8 @@ saebrtrack_transaction(ROT *rot, const char *cmdstr, char *data, return -RIG_EINVAL; } - rs = &rot->state; - rig_flush(&rs->rotport); - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + rig_flush(rotp); + retval = write_block(rotp, (unsigned char *) cmdstr, strlen(cmdstr)); if (retval != RIG_OK) { @@ -73,7 +72,7 @@ saebrtrack_transaction(ROT *rot, const char *cmdstr, char *data, return RIG_OK; /* don't want a reply */ } - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + retval = read_string(rotp, (unsigned char *) data, data_len, "\n", 1, 0, 1); if (retval < 0) diff --git a/rotators/sartek/sartek.c b/rotators/sartek/sartek.c index 363064260..baeb5716c 100644 --- a/rotators/sartek/sartek.c +++ b/rotators/sartek/sartek.c @@ -124,7 +124,7 @@ static int sartek_rot_set_position(ROT *rot, azimuth_t azimuth, SNPRINTF(cmdstr, sizeof(cmdstr), "P%c", (int)((azimuth * 255) / 360)); - err = write_block(&rot->state.rotport, (unsigned char *) cmdstr, + err = write_block(ROTPORT(rot), (unsigned char *) cmdstr, strlen(cmdstr)); if (err != RIG_OK) @@ -147,7 +147,7 @@ static int sartek_rot_stop(ROT *rot) rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); - err = write_block(&rot->state.rotport, (unsigned char *) "P\0", 2); + err = write_block(ROTPORT(rot), (unsigned char *) "P\0", 2); if (err != RIG_OK) { diff --git a/rotators/satel/satel.c b/rotators/satel/satel.c index 7d13c2b82..aa90d8db7 100644 --- a/rotators/satel/satel.c +++ b/rotators/satel/satel.c @@ -109,17 +109,13 @@ struct satel_stat static int satel_cmd(ROT *rot, char *cmd, int cmdlen, char *res, int reslen) { int ret; - struct rot_state *rs; - + hamlib_port_t *rotp = ROTPORT(rot); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + rig_flush(rotp); - rs = &rot->state; - - rig_flush(&rs->rotport); - - ret = write_block(&rs->rotport, (unsigned char *) cmd, cmdlen); + ret = write_block(rotp, (unsigned char *) cmd, cmdlen); if (ret != RIG_OK) { @@ -128,7 +124,7 @@ static int satel_cmd(ROT *rot, char *cmd, int cmdlen, char *res, int reslen) if (reslen > 0 && res != NULL) { - ret = read_string(&rs->rotport, (unsigned char *) res, reslen, "\n", 1, 0, 1); + ret = read_string(rotp, (unsigned char *) res, reslen, "\n", 1, 0, 1); if (ret < 0) { @@ -146,16 +142,10 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) char resbuf[BUF_SIZE]; char *p; int ret; - struct rot_state *rs; - - - rs = &rot->state; - - + hamlib_port_t *rotp = ROTPORT(rot); // read motion state - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -165,8 +155,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) stat->motion_enabled = strcmp(resbuf, "Motion ENABLED") == 0 ? true : false; // XXX skip mode - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -174,8 +163,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) } // XXX skip time - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -183,8 +171,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) } // read azimuth line - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -196,8 +183,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) stat->az = (int)strtof(p, NULL); // read elevation line - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -209,8 +195,7 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) stat->el = (int)strtof(p, NULL); // skip blank line - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { @@ -218,15 +203,13 @@ static int satel_read_status(ROT *rot, satel_stat_t *stat) } // XXX skip stored position count - ret = read_string(&rs->rotport, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, - 1); + ret = read_string(rotp, (unsigned char *) resbuf, BUF_SIZE, "\n", 1, 0, 1); if (ret < 0) { return ret; } - return RIG_OK; } diff --git a/rotators/spid/spid.c b/rotators/spid/spid.c index a8689bbc4..e0dd0d712 100644 --- a/rotators/spid/spid.c +++ b/rotators/spid/spid.c @@ -306,7 +306,6 @@ static int spid_set_conf(ROT *rot, hamlib_token_t token, const char *val) static int spid_rot1prog_rot_set_position(ROT *rot, azimuth_t az, elevation_t el) { - struct rot_state *rs = &rot->state; int retval; char cmdstr[13]; unsigned int u_az; @@ -329,7 +328,7 @@ static int spid_rot1prog_rot_set_position(ROT *rot, azimuth_t az, cmdstr[11] = 0x2F; /* K */ cmdstr[12] = 0x20; /* END */ - retval = spid_write(&rs->rotport, (unsigned char *) cmdstr, 13); + retval = spid_write(ROTPORT(rot), (unsigned char *) cmdstr, 13); if (retval != RIG_OK) { @@ -343,6 +342,7 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, elevation_t el) { struct rot_state *rs = &rot->state; + hamlib_port_t *rotp = ROTPORT(rot); const struct spid_rot2prog_priv_data *priv = (struct spid_rot2prog_priv_data *) rs->priv; int retval; @@ -356,7 +356,7 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, { do { - retval = spid_write(&rs->rotport, + retval = spid_write(rotp, (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x20", 13); if (retval != RIG_OK) @@ -365,9 +365,9 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, } memset(cmdstr, 0, 12); - retval = read_r2p_frame(&rs->rotport, (unsigned char *) cmdstr, 12); + retval = read_r2p_frame(rotp, (unsigned char *) cmdstr, 12); } - while (retval < 0 && retry_read++ < rot->state.rotport.retry); + while (retval < 0 && retry_read++ < rotp->retry); if (retval < 0) { @@ -397,7 +397,7 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, cmdstr[11] = 0x2F; /* K */ cmdstr[12] = 0x20; /* END */ - retval = spid_write(&rs->rotport, (unsigned char *) cmdstr, 13); + retval = spid_write(rotp, (unsigned char *) cmdstr, 13); if (retval != RIG_OK) { @@ -412,9 +412,9 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, do { - retval = read_r2p_frame(&rs->rotport, (unsigned char *) cmdstr, 12); + retval = read_r2p_frame(rotp, (unsigned char *) cmdstr, 12); } - while ((retval < 0) && (retry_read++ < rot->state.rotport.retry)); + while ((retval < 0) && (retry_read++ < rotp->retry)); } return RIG_OK; @@ -422,7 +422,7 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, static int spid_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) { - struct rot_state *rs = &rot->state; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; char posbuf[12]; @@ -431,7 +431,7 @@ static int spid_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) do { - retval = spid_write(&rs->rotport, + retval = spid_write(rotp, (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x20", 13); if (retval != RIG_OK) @@ -443,19 +443,19 @@ static int spid_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) if (rot->caps->rot_model == ROT_MODEL_SPID_ROT1PROG) { - retval = read_r2p_frame(&rs->rotport, (unsigned char *) posbuf, 5); + retval = read_r2p_frame(rotp, (unsigned char *) posbuf, 5); } else if (rot->caps->rot_model == ROT_MODEL_SPID_ROT2PROG || rot->caps->rot_model == ROT_MODEL_SPID_MD01_ROT2PROG) { - retval = read_r2p_frame(&rs->rotport, (unsigned char *) posbuf, 12); + retval = read_r2p_frame(rotp, (unsigned char *) posbuf, 12); } else { retval = -RIG_EINVAL; } } - while (retval < 0 && retry_read++ < rot->state.rotport.retry); + while (retval < 0 && retry_read++ < rotp->retry); if (retval < 0) { @@ -494,7 +494,7 @@ static int spid_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) static int spid_rot_stop(ROT *rot) { - struct rot_state *rs = &rot->state; + hamlib_port_t *rotp = ROTPORT(rot); int retval; int retry_read = 0; char posbuf[12]; @@ -503,7 +503,7 @@ static int spid_rot_stop(ROT *rot) do { - retval = spid_write(&rs->rotport, + retval = spid_write(rotp, (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0F\x20", 13); if (retval != RIG_OK) @@ -515,15 +515,15 @@ static int spid_rot_stop(ROT *rot) if (rot->caps->rot_model == ROT_MODEL_SPID_ROT1PROG) { - retval = read_r2p_frame(&rs->rotport, (unsigned char *) posbuf, 5); + retval = read_r2p_frame(rotp, (unsigned char *) posbuf, 5); } else if (rot->caps->rot_model == ROT_MODEL_SPID_ROT2PROG || rot->caps->rot_model == ROT_MODEL_SPID_MD01_ROT2PROG) { - retval = read_r2p_frame(&rs->rotport, (unsigned char *) posbuf, 12); + retval = read_r2p_frame(rotp, (unsigned char *) posbuf, 12); } } - while (retval < 0 && retry_read++ < rot->state.rotport.retry); + while (retval < 0 && retry_read++ < rotp->retry); if (retval < 0) { @@ -535,7 +535,6 @@ static int spid_rot_stop(ROT *rot) static int spid_md01_rot2prog_rot_move(ROT *rot, int direction, int speed) { - struct rot_state *rs = &rot->state; char dir = 0x00; int retval; char cmdstr[13]; @@ -578,7 +577,7 @@ static int spid_md01_rot2prog_rot_move(ROT *rot, int direction, int speed) moving at all), always send the stop command first. */ spid_rot_stop(rot); - retval = spid_write(&rs->rotport, (unsigned char *) cmdstr, 13); + retval = spid_write(ROTPORT(rot), (unsigned char *) cmdstr, 13); return retval; } diff --git a/rotators/ts7400/ts7400.c b/rotators/ts7400/ts7400.c index f8abef74d..953504c91 100644 --- a/rotators/ts7400/ts7400.c +++ b/rotators/ts7400/ts7400.c @@ -59,7 +59,7 @@ static int ts7400_rot_init(ROT *rot) priv = rot->state.priv; - rot->state.rotport.type.rig = RIG_PORT_NONE; + ROTPORT(rot)->type.rig = RIG_PORT_NONE; priv->az = priv->el = 0;