Merge pull request #1568 from GeoBaltz/fix14

Fix rotators that want to do I/O before port is open
pull/1570/head
Michael Black 2024-06-15 12:20:10 -05:00 zatwierdzone przez GitHub
commit a462bc19ae
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
11 zmienionych plików z 114 dodań i 83 usunięć

Wyświetl plik

@ -1853,6 +1853,22 @@ struct rig_spectrum_line
unsigned char *spectrum_data; /*!< 8-bit spectrum data covering bandwidth of either the span_freq in center mode or from low edge to high edge in fixed mode. A higher value represents higher signal strength. */
};
/**
* Config item for deferred processing
**/
struct deferred_config_item {
struct deferred_config_item *next;
hamlib_token_t token;
char *value; // strdup'ed, must be freed
};
typedef struct deferred_config_item deferred_config_item_t;
struct deferred_config_header {
struct deferred_config_item *first; // NULL if none
struct deferred_config_item *last;
};
typedef struct deferred_config_header deferred_config_header_t;
/**
* \brief Rig data structure.
*

Wyświetl plik

@ -629,6 +629,7 @@ struct rot_state {
hamlib_port_t rotport; /*!< Rotator port (internal use). */
hamlib_port_t rotport2; /*!< 2nd Rotator port (internal use). */
rig_ptr_t *pstrotator_handler_priv_data;
deferred_config_header_t config_queue;
};

Wyświetl plik

@ -29,6 +29,7 @@
#include "serial.h"
#include "register.h"
#include "idx_builtin.h"
#include "misc.h"
#include "easycomm.h"
@ -508,6 +509,11 @@ static int easycomm_rot_set_conf(ROT *rot, hamlib_token_t token, const char *val
rig_debug(RIG_DEBUG_TRACE, "%s: cmdstr = %s, *val = %c\n", __func__, cmdstr,
*val);
if (!ROTSTATE(rot)->comm_state)
{
return queue_deferred_config(&ROTSTATE(rot)->config_queue, token, val);
}
retval = easycomm_transaction(rot, cmdstr, NULL, 0);
if (retval != RIG_OK)

Wyświetl plik

@ -35,6 +35,7 @@
#include "hamlib/rotator.h"
#include "hamlib/rig.h"
#include "misc.h"
#include "serial.h"
#include "token.h"
@ -419,6 +420,11 @@ grbltrk_rot_set_conf(ROT *rot, hamlib_token_t token, const char *val)
char req[RSIZE] = {0};
char rsp[RSIZE];
if (!ROTSTATE(rot)->comm_state)
{
return queue_deferred_config(&ROTSTATE(rot)->config_queue, token, val);
}
for (i = 0; i < len; i++)
{

Wyświetl plik

@ -493,9 +493,6 @@ const struct rot_caps meade_caps =
.move = meade_move,
.get_info = meade_get_info,
.get_conf = rot_get_conf,
.set_conf = rot_set_conf,
};
DECLARE_INITROT_BACKEND(meade)

Wyświetl plik

@ -29,6 +29,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <stdio.h>
#include <stdlib.h> /* Standard library definitions */
@ -39,6 +40,7 @@
#include "serial.h"
#include "register.h"
#include "iofunc.h"
#include "misc.h"
#include "rotorez.h"
@ -1087,12 +1089,21 @@ static int rotorez_rot_set_conf(ROT *rot, hamlib_token_t token, const char *val)
return -RIG_EINVAL;
}
rig_debug(RIG_DEBUG_TRACE, "%s: c = %c, *val = %c\n", __func__, c, *val);
SNPRINTF(cmdstr, sizeof(cmdstr), "%c", c);
rig_debug(RIG_DEBUG_TRACE, "%s: cmdstr = %s, *val = %c\n",
__func__, cmdstr, *val);
/*
* We cannot send anything to the rotator if it isn't open yet.
* Queue any set_conf commands and let rot_open reprocess them
* after it has done it's job.
*/
if (!ROTSTATE(rot)->comm_state)
{
err = queue_deferred_config(&ROTSTATE(rot)->config_queue, token, val);
return err;
}
err = rotorez_send_priv_cmd(rot, cmdstr);
if (err != RIG_OK)

Wyświetl plik

@ -3125,4 +3125,38 @@ int rig_test_2038(RIG *rig)
//! @endcond
/**
* Add item to be sent to device after it is opened
* (currently only used by rotators)
**/
int queue_deferred_config(deferred_config_header_t *head, hamlib_token_t token, const char *val)
{
deferred_config_item_t *item;
if (!(item = malloc(sizeof(deferred_config_item_t))))
{
return -RIG_ENOMEM;
}
if (!(item->value = strdup(val)))
{
free(item);
return -RIG_ENOMEM;
}
item->token = token;
item->next = NULL;
if (!head->first)
{
head->first = item;
}
else
{
head->last->next = item;
}
head->last = item;
return RIG_OK;
}
/** @} */

Wyświetl plik

@ -211,6 +211,8 @@ extern HAMLIB_EXPORT(int) rig_settings_load_all(char *settings_file);
extern int check_level_param(RIG *rig, setting_t level, value_t val, gran_t **gran);
extern int queue_deferred_config(deferred_config_header_t *head, hamlib_token_t token, const char *val);
// Takes rig-specific band result and maps it the bandlist int the rig's backend
extern HAMLIB_EXPORT(hamlib_band_t) rig_get_band(RIG *rig, freq_t freq, int band);
extern HAMLIB_EXPORT(const char*) rig_get_band_str(RIG *rig, hamlib_band_t band, int which);

Wyświetl plik

@ -377,6 +377,7 @@ int HAMLIB_API rot_open(ROT *rot)
hamlib_port_t *rotp2 = ROTPORT2(rot);
int status;
int net1, net2, net3, net4, port;
deferred_config_item_t *item;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
@ -520,24 +521,6 @@ int HAMLIB_API rot_open(ROT *rot)
add_opened_rot(rot);
rs->comm_state = 1;
/*
* Maybe the backend has something to initialize
* In case of failure, just close down and report error code.
*/
if (caps->rot_open != NULL)
{
status = caps->rot_open(rot);
if (status != RIG_OK)
{
memcpy(&rs->rotport_deprecated, rotp,
sizeof(rs->rotport_deprecated));
return status;
}
}
if (rotp->type.rig != RIG_PORT_NETWORK && rotp->type.rig != RIG_PORT_UDP_NETWORK)
{
if (rotp->parm.serial.dtr_state == RIG_SIGNAL_ON)
@ -559,6 +542,40 @@ int HAMLIB_API rot_open(ROT *rot)
}
}
rs->comm_state = 1;
/*
* Now that the rotator port is officially opened, we can
* send the deferred configuration info.
*/
while ((item = rs->config_queue.first))
{
rs->config_queue.first = item->next;
status = rot_set_conf(rot, item->token, item->value);
free(item->value);
free(item);
if (status != RIG_OK)
{
return status;
}
}
/*
* Maybe the backend has something to initialize
* In case of failure, just close down and report error code.
*/
if (caps->rot_open != NULL)
{
status = caps->rot_open(rot);
if (status != RIG_OK)
{
memcpy(&rs->rotport_deprecated, rotp,
sizeof(rs->rotport_deprecated));
return status;
}
}
memcpy(&rs->rotport_deprecated, rotp,
sizeof(rs->rotport_deprecated));

Wyświetl plik

@ -341,8 +341,7 @@ int main(int argc, char *argv[])
char *token = strtok(conf_parms, ",");
// ROTOREZ set_conf needs to be done after rot_open
while (token && my_rot->caps->rot_model != ROT_MODEL_ROTOREZ)
while (token)
{
char mytoken[100], myvalue[100];
hamlib_token_t lookup;
@ -407,34 +406,6 @@ int main(int argc, char *argv[])
exit(2);
}
// ROTOREZ set_conf needs to be done after rot_open
while (token && my_rot->caps->rot_model == ROT_MODEL_ROTOREZ)
{
char mytoken[100], myvalue[100];
hamlib_token_t lookup;
sscanf(token, "%99[^=]=%99s", mytoken, myvalue);
//printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue);
lookup = rot_token_lookup(my_rot, mytoken);
if (lookup == 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n",
__func__, mytoken);
token = strtok(NULL, ",");
continue;
}
retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot, mytoken), myvalue);
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
token = strtok(NULL, ",");
}
/*
* Print out capabilities, and exits immediately as we may be interested
* only in caps, and rig_open may fail.

Wyświetl plik

@ -347,8 +347,7 @@ int main(int argc, char *argv[])
char *token = strtok(conf_parms, ",");
// ROTOREZ set_conf needs to be done after rot_open
while (token && my_rot->caps->rot_model != ROT_MODEL_ROTOREZ)
while (token)
{
char mytoken[100], myvalue[100];
hamlib_token_t lookup;
@ -418,35 +417,6 @@ int main(int argc, char *argv[])
exit(2);
}
// ROTOREZ set_conf needs to be done after rot_open
while (token && my_rot->caps->rot_model == ROT_MODEL_ROTOREZ)
{
char mytoken[100], myvalue[100];
hamlib_token_t lookup;
sscanf(token, "%99[^=]=%99s", mytoken, myvalue);
//printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue);
lookup = rot_token_lookup(my_rot, mytoken);
if (lookup == 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n",
__func__, mytoken);
token = strtok(NULL, ",");
continue;
}
retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot, mytoken), myvalue);
if (retcode != RIG_OK)
{
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
exit(2);
}
token = strtok(NULL, ",");
}
my_rot->state.az_offset = az_offset;
my_rot->state.el_offset = el_offset;