kopia lustrzana https://github.com/Hamlib/Hamlib
allow discovery(probe) of more than one rig attached to a port, fixes
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1405 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.4
rodzic
825871c328
commit
fdabf14513
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Hamlib Drake backend - main file
|
||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||
* Copyright (c) 2001-2003 by Stephane Fillod
|
||||
*
|
||||
* $Id: drake.c,v 1.2 2002-10-20 20:46:32 fillods Exp $
|
||||
* $Id: drake.c,v 1.3 2003-03-10 08:26:08 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -221,7 +221,7 @@ int initrigs_drake(void *be_handle)
|
|||
/*
|
||||
* probe_drake
|
||||
*/
|
||||
rig_model_t probe_drake(port_t *port)
|
||||
rig_model_t probeallrigs_drake(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)
|
||||
{
|
||||
static unsigned char idbuf[BUFSZ];
|
||||
int retval, id_len;
|
||||
|
@ -229,6 +229,10 @@ rig_model_t probe_drake(port_t *port)
|
|||
if (!port)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
if (port->type.rig != RIG_PORT_SERIAL)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
port->parm.serial.rate = r8b_caps.serial_rate_max;
|
||||
port->write_delay = port->post_write_delay = 0;
|
||||
port->timeout = 50;
|
||||
port->retry = 1;
|
||||
|
@ -242,19 +246,22 @@ rig_model_t probe_drake(port_t *port)
|
|||
|
||||
close(port->fd);
|
||||
|
||||
if (retval != RIG_OK)
|
||||
if (retval != RIG_OK || id_len <= 0 || id_len >= BUFSZ)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
idbuf[id_len] = '\0';
|
||||
|
||||
|
||||
if (!strcmp(idbuf, "R8B"))
|
||||
if (!strcmp(idbuf, "R8B")) {
|
||||
if (cfunc)
|
||||
(*cfunc)(port, RIG_MODEL_DKR8B, data);
|
||||
return RIG_MODEL_DKR8B;
|
||||
}
|
||||
|
||||
/*
|
||||
* not found...
|
||||
*/
|
||||
rig_debug(RIG_DEBUG_VERBOSE,"probe_drake: found unknown device "
|
||||
if (memcmp(idbuf, "ID" EOM, 3)) /* catch loopback serial */
|
||||
rig_debug(RIG_DEBUG_VERBOSE,"probe_drake: found unknown device "
|
||||
"with ID '%s', please report to Hamlib "
|
||||
"developers.\n", idbuf);
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Hamlib Drake backend - main header
|
||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||
* Copyright (c) 2001-2003 by Stephane Fillod
|
||||
*
|
||||
* $Id: drake.h,v 1.2 2002-10-20 20:46:32 fillods Exp $
|
||||
* $Id: drake.h,v 1.3 2003-03-10 08:26:08 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -34,7 +34,7 @@ const char *drake_get_info(RIG *rig);
|
|||
extern const struct rig_caps r8b_caps;
|
||||
|
||||
extern BACKEND_EXPORT(int) initrigs_drake(void *be_handle);
|
||||
extern BACKEND_EXPORT(rig_model_t) probe_drake(port_t *port);
|
||||
extern BACKEND_EXPORT(rig_model_t) probeallrigs_drake(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data);
|
||||
|
||||
|
||||
#endif /* _DRAKE_H */
|
||||
|
|
71
icom/icom.c
71
icom/icom.c
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Hamlib CI-V backend - main file
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||
* Copyright (c) 2000-2003 by Stephane Fillod
|
||||
*
|
||||
* $Id: icom.c,v 1.71 2003-02-19 23:56:56 fillods Exp $
|
||||
* $Id: icom.c,v 1.72 2003-03-10 08:26:08 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -2387,32 +2387,51 @@ int icom_decode_event(RIG *rig)
|
|||
/*
|
||||
* init_icom is called by rig_probe_all (register.c)
|
||||
*
|
||||
* TODO: probe_icom will only report the _first_ device on the CI-V bus.
|
||||
* more devices could be found on the bus.
|
||||
* probe_icom reports all the devices on the CI-V bus.
|
||||
* TODO: try different speeds
|
||||
*/
|
||||
rig_model_t probe_icom(port_t *p)
|
||||
rig_model_t probeallrigs_icom(port_t *p, rig_probe_func_t cfunc, rig_ptr_t data)
|
||||
{
|
||||
unsigned char buf[MAXFRAMELEN], civ_addr, civ_id;
|
||||
int frm_len, i;
|
||||
int retval;
|
||||
unsigned char buf[MAXFRAMELEN], civ_addr, civ_id;
|
||||
int frm_len, i;
|
||||
int retval;
|
||||
rig_model_t model = RIG_MODEL_NONE;
|
||||
int rates[] = { 19200, 9600, 300, 0 };
|
||||
int rates_idx;
|
||||
|
||||
if (!p)
|
||||
return RIG_MODEL_NONE;
|
||||
if (!p)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
p->write_delay = p->post_write_delay = 0;
|
||||
p->timeout = 50;
|
||||
p->retry = 1;
|
||||
if (p->type.rig != RIG_PORT_SERIAL)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
p->write_delay = p->post_write_delay = 0;
|
||||
p->retry = 1;
|
||||
|
||||
/*
|
||||
* try for all different baud rates
|
||||
*/
|
||||
for (rates_idx = 0; rates[rates_idx]; rates_idx++) {
|
||||
p->parm.serial.rate = rates[rates_idx];
|
||||
p->timeout = 2*1000/rates[rates_idx] + 40;
|
||||
|
||||
retval = serial_open(p);
|
||||
if (retval != RIG_OK)
|
||||
return RIG_MODEL_NONE;
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
/* try all possible addresses on the CI-V bus */
|
||||
/*
|
||||
* try all possible addresses on the CI-V bus
|
||||
* FIXME: actualy, old rigs do not support C_RD_TRXID cmd!
|
||||
* Try to be smart, and deduce model depending
|
||||
* on freq range, return address, and
|
||||
* available commands.
|
||||
*/
|
||||
for (civ_addr=0x01; civ_addr<=0x7f; civ_addr++) {
|
||||
|
||||
frm_len = make_cmd_frame(buf, civ_addr, C_RD_TRXID, S_RD_TRXID,
|
||||
NULL, 0);
|
||||
|
||||
serial_flush(p);
|
||||
write_block(p, buf, frm_len);
|
||||
|
||||
/* read out the bytes we just sent
|
||||
|
@ -2445,24 +2464,34 @@ rig_model_t probe_icom(port_t *p)
|
|||
|
||||
for (i=0; icom_addr_list[i].model != RIG_MODEL_NONE; i++) {
|
||||
if (icom_addr_list[i].re_civ_addr == civ_id) {
|
||||
close(p->fd);
|
||||
rig_debug(RIG_DEBUG_VERBOSE,"probe_icom: found %#x"
|
||||
" at %#x\n", civ_id, buf[3]);
|
||||
return icom_addr_list[i].model;
|
||||
model = icom_addr_list[i].model;
|
||||
if (cfunc)
|
||||
(*cfunc)(p, model, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* not found in known table....
|
||||
* update icom_addr_list[]!
|
||||
*/
|
||||
rig_debug(RIG_DEBUG_WARN,"probe_icom: found unknown device "
|
||||
if (icom_addr_list[i].model == RIG_MODEL_NONE)
|
||||
rig_debug(RIG_DEBUG_WARN,"probe_icom: found unknown device "
|
||||
"with CI-V ID %#x, please report to Hamlib "
|
||||
"developers.\n", civ_id);
|
||||
}
|
||||
|
||||
|
||||
close(p->fd);
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
/*
|
||||
* Assumes all the rigs on the bus are running at same speed.
|
||||
* So if one at least has been found, none will be at lower speed.
|
||||
*/
|
||||
if (model != RIG_MODEL_NONE)
|
||||
return model;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Hamlib CI-V backend - main header
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||
*
|
||||
* $Id: icom.h,v 1.52 2003-02-19 23:56:56 fillods Exp $
|
||||
* $Id: icom.h,v 1.53 2003-03-10 08:26:08 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -168,7 +168,7 @@ extern const struct rig_caps os535_caps;
|
|||
|
||||
extern const struct rig_caps omnivip_caps;
|
||||
|
||||
extern BACKEND_EXPORT(rig_model_t) proberigs_icom(port_t *p);
|
||||
extern BACKEND_EXPORT(rig_model_t) probeallrigs_icom(port_t *p, rig_probe_func_t cfunc, rig_ptr_t data);
|
||||
extern BACKEND_EXPORT(int) initrigs_icom(void *be_handle);
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Hamlib Kenwood backend - main file
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||
* Copyright (c) 2000-2003 by Stephane Fillod and others
|
||||
*
|
||||
* $Id: kenwood.c,v 1.57 2003-01-29 22:25:16 fillods Exp $
|
||||
* $Id: kenwood.c,v 1.58 2003-03-10 08:26:09 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -1312,32 +1312,50 @@ const char* kenwood_get_info(RIG *rig)
|
|||
#define IDBUFSZ 16
|
||||
|
||||
/*
|
||||
* probe_kenwood
|
||||
* proberigs_kenwood
|
||||
*
|
||||
* Notes:
|
||||
* There's only one rig possible per port.
|
||||
*/
|
||||
rig_model_t probe_kenwood(port_t *port)
|
||||
rig_model_t probeallrigs_kenwood(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)
|
||||
{
|
||||
unsigned char idbuf[IDBUFSZ];
|
||||
int id_len, i, k_id;
|
||||
int retval;
|
||||
int rates[] = { 57600, 9600, 4800, 0 }; /* possible baud rates */
|
||||
int rates_idx;
|
||||
|
||||
if (!port)
|
||||
return RIG_MODEL_NONE;
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
if (port->type.rig != RIG_PORT_SERIAL)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
port->write_delay = port->post_write_delay = 0;
|
||||
port->timeout = 50;
|
||||
port->parm.serial.stop_bits = 2;
|
||||
port->retry = 1;
|
||||
|
||||
retval = serial_open(port);
|
||||
if (retval != RIG_OK)
|
||||
/*
|
||||
* try for all different baud rates
|
||||
*/
|
||||
for (rates_idx = 0; rates[rates_idx]; rates_idx++) {
|
||||
port->parm.serial.rate = rates[rates_idx];
|
||||
port->timeout = 2*1000/rates[rates_idx] + 50;
|
||||
|
||||
retval = serial_open(port);
|
||||
if (retval != RIG_OK)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
retval = write_block(port, "ID;", 3);
|
||||
id_len = read_string(port, idbuf, IDBUFSZ, EOM_KEN EOM_TH, strlen(EOM_KEN EOM_TH));
|
||||
close(port->fd);
|
||||
|
||||
retval = write_block(port, "ID;", 3);
|
||||
id_len = read_string(port, idbuf, IDBUFSZ, EOM_KEN EOM_TH, 2);
|
||||
if (retval != RIG_OK || id_len < 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
close(port->fd);
|
||||
|
||||
if (retval != RIG_OK)
|
||||
return RIG_MODEL_NONE;
|
||||
if (retval != RIG_OK || id_len < 0 || !strcmp(idbuf, "ID;"))
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
/*
|
||||
* reply should be something like 'IDxxx;'
|
||||
|
@ -1356,6 +1374,8 @@ rig_model_t probe_kenwood(port_t *port)
|
|||
if (!strncmp(kenwood_id_string_list[i].id, idbuf+2, 16)) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: "
|
||||
"found %s\n", idbuf+2);
|
||||
if (cfunc)
|
||||
(*cfunc)(port, kenwood_id_string_list[i].model, data);
|
||||
return kenwood_id_string_list[i].model;
|
||||
}
|
||||
}
|
||||
|
@ -1381,6 +1401,8 @@ rig_model_t probe_kenwood(port_t *port)
|
|||
*/
|
||||
if (id_len == 4 || !strcmp(idbuf, "K2")) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: found K2\n");
|
||||
if (cfunc)
|
||||
(*cfunc)(port, RIG_MODEL_K2, data);
|
||||
return RIG_MODEL_K2;
|
||||
}
|
||||
}
|
||||
|
@ -1389,6 +1411,8 @@ rig_model_t probe_kenwood(port_t *port)
|
|||
if (kenwood_id_list[i].id == k_id) {
|
||||
rig_debug(RIG_DEBUG_VERBOSE,"probe_kenwood: "
|
||||
"found %03d\n", k_id);
|
||||
if (cfunc)
|
||||
(*cfunc)(port, kenwood_id_list[i].model, data);
|
||||
return kenwood_id_list[i].model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Kenwood backend - main header
|
||||
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||
*
|
||||
* $Id: kenwood.h,v 1.26 2002-11-13 20:35:18 fillods Exp $
|
||||
* $Id: kenwood.h,v 1.27 2003-03-10 08:26:09 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -96,7 +96,7 @@ extern const struct rig_caps thf7e_caps;
|
|||
extern const struct rig_caps k2_caps;
|
||||
|
||||
extern BACKEND_EXPORT(int) initrigs_kenwood(void *be_handle);
|
||||
extern BACKEND_EXPORT(rig_model_t) proberigs_kenwood(port_t *port);
|
||||
extern BACKEND_EXPORT(rig_model_t) probeallrigs_kenwood(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data);
|
||||
|
||||
|
||||
#endif /* _KENWOOD_H */
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* Hamlib Interface - provides registering for dynamically loadable backends.
|
||||
* Copyright (c) 2000,2001,2002 by Stephane Fillod
|
||||
* Copyright (c) 2000-2003 by Stephane Fillod
|
||||
*
|
||||
* $Id: register.c,v 1.17 2002-11-04 22:27:49 fillods Exp $
|
||||
* $Id: register.c,v 1.18 2003-03-10 08:26:09 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -53,7 +53,7 @@
|
|||
static struct {
|
||||
int be_num;
|
||||
const char *be_name;
|
||||
rig_model_t (*be_probe)(port_t *);
|
||||
rig_model_t (* be_probe_all)(port_t*, rig_probe_func_t, rig_ptr_t);
|
||||
} rig_backend_list[RIG_BACKEND_MAX] = RIG_BACKEND_LIST;
|
||||
|
||||
|
||||
|
@ -221,25 +221,48 @@ int rig_list_foreach(int (*cfunc)(const struct rig_caps*, rig_ptr_t),rig_ptr_t d
|
|||
return RIG_OK;
|
||||
}
|
||||
|
||||
static int dummy_rig_probe(port_t *p, rig_model_t model, rig_ptr_t data)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_TRACE, "Found rig, model %d\n", model);
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* rig_probe_all
|
||||
* rig_probe_first
|
||||
* called straight by rig_probe
|
||||
*/
|
||||
rig_model_t rig_probe_all(port_t *p)
|
||||
rig_model_t rig_probe_first(port_t *p)
|
||||
{
|
||||
int i;
|
||||
rig_model_t rig_model;
|
||||
rig_model_t model;
|
||||
|
||||
for (i=0; i<RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
|
||||
if (rig_backend_list[i].be_probe) {
|
||||
rig_model = (*rig_backend_list[i].be_probe)(p);
|
||||
if (rig_model != RIG_MODEL_NONE)
|
||||
return rig_model;
|
||||
}
|
||||
if (rig_backend_list[i].be_probe_all) {
|
||||
model = (*rig_backend_list[i].be_probe_all)(p, dummy_rig_probe, NULL);
|
||||
/* stop at first one found */
|
||||
if (model != RIG_MODEL_NONE)
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return RIG_MODEL_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* rig_probe_all_backends
|
||||
* called straight by rig_probe_all
|
||||
*/
|
||||
int rig_probe_all_backends(port_t *p, rig_probe_func_t cfunc, rig_ptr_t data)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
|
||||
if (rig_backend_list[i].be_probe_all) {
|
||||
(*rig_backend_list[i].be_probe_all)(p, cfunc, data);
|
||||
}
|
||||
}
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
|
||||
int rig_load_all_backends()
|
||||
{
|
||||
|
@ -275,7 +298,7 @@ int rig_load_backend(const char *be_name)
|
|||
int status;
|
||||
char libname[PATH_MAX];
|
||||
char initfname[MAXFUNCNAMELEN] = "initrigs_";
|
||||
char probefname[MAXFUNCNAMELEN] = "proberigs_";
|
||||
char probefname[MAXFUNCNAMELEN] = "probeallrigs_";
|
||||
int i;
|
||||
|
||||
/*
|
||||
|
@ -340,7 +363,7 @@ int rig_load_backend(const char *be_name)
|
|||
for (i=0; i<RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
|
||||
if (!strncmp(be_name, rig_backend_list[i].be_name, 64)) {
|
||||
strncat(probefname, be_name, MAXFUNCNAMELEN);
|
||||
rig_backend_list[i].be_probe = (rig_model_t (*)(port_t *))
|
||||
rig_backend_list[i].be_probe_all = (rig_probe_func_t)
|
||||
lt_dlsym (be_handle, probefname);
|
||||
break;
|
||||
}
|
||||
|
|
35
src/rig.c
35
src/rig.c
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Interface - main file
|
||||
* Copyright (c) 2000-2003 by Stephane Fillod and Frank Singleton
|
||||
*
|
||||
* $Id: rig.c,v 1.67 2003-02-23 22:38:54 fillods Exp $
|
||||
* $Id: rig.c,v 1.68 2003-03-10 08:26:09 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
|
@ -2227,7 +2227,7 @@ int rig_reset(RIG *rig, reset_t reset)
|
|||
* \brief try to guess a rig
|
||||
* \param port A pointer describing a port linking the host to the rig
|
||||
*
|
||||
* Try to guess what is the model of rig pointed to by port.
|
||||
* Try to guess what is the model of the first rig attached to the port.
|
||||
* It can be very buggy, and mess up the radio at the other end.
|
||||
* (but fun if it works!)
|
||||
*
|
||||
|
@ -2239,10 +2239,35 @@ int rig_reset(RIG *rig, reset_t reset)
|
|||
*/
|
||||
rig_model_t rig_probe(port_t *port)
|
||||
{
|
||||
if (!port)
|
||||
return RIG_MODEL_NONE;
|
||||
if (!port)
|
||||
return RIG_MODEL_NONE;
|
||||
|
||||
return rig_probe_all(port);
|
||||
return rig_probe_first(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief try to guess rigs
|
||||
* \param port A pointer describing a port linking the host to the rigs
|
||||
* \param cfunc Function to be called each time a rig is found
|
||||
* \param data Arbitrary data passed to cfunc
|
||||
*
|
||||
* Try to guess what are the model of all rigs attached to the port.
|
||||
* It can be very buggy, and mess up the radio at the other end.
|
||||
* (but fun if it works!)
|
||||
*
|
||||
* \warning this is really Experimental, It has been tested only
|
||||
* with IC-706MkIIG. any feedback welcome! --SF
|
||||
*
|
||||
* \return RIG_OK if the operation has been sucessful, otherwise
|
||||
* a negative value if an error occured (in which case, cause is
|
||||
* set appropriately).
|
||||
*/
|
||||
int rig_probe_all(port_t *port, rig_probe_func_t cfunc, rig_ptr_t data)
|
||||
{
|
||||
if (!port)
|
||||
return -RIG_EINVAL;
|
||||
|
||||
return rig_probe_all_backends(port, cfunc, data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Ładowanie…
Reference in New Issue