diff --git a/drake/drake.c b/drake/drake.c index 4b88d29c4..16b0780d9 100644 --- a/drake/drake.c +++ b/drake/drake.c @@ -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); diff --git a/drake/drake.h b/drake/drake.h index 9219268f9..7cd143fbf 100644 --- a/drake/drake.h +++ b/drake/drake.h @@ -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 */ diff --git a/icom/icom.c b/icom/icom.c index 0d30d0e3a..09bb84451 100644 --- a/icom/icom.c +++ b/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; } /* diff --git a/icom/icom.h b/icom/icom.h index b746d3ea6..5aa8931af 100644 --- a/icom/icom.h +++ b/icom/icom.h @@ -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); diff --git a/kenwood/kenwood.c b/kenwood/kenwood.c index bc049a490..18d750b5c 100644 --- a/kenwood/kenwood.c +++ b/kenwood/kenwood.c @@ -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; } } diff --git a/kenwood/kenwood.h b/kenwood/kenwood.h index b4f924405..420ee16bc 100644 --- a/kenwood/kenwood.h +++ b/kenwood/kenwood.h @@ -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 */ diff --git a/src/register.c b/src/register.c index 8707496d1..02c92a204 100644 --- a/src/register.c +++ b/src/register.c @@ -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