2020-01-17 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* Hamlib CI-V backend - low level communication routines
|
|
|
|
* Copyright (c) 2000-2010 by Stephane Fillod
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-02-04 13:41:36 +00:00
|
|
|
#include <hamlib/config.h>
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
|
2023-02-14 19:00:43 +00:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
#include "hamlib/rig.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "icom.h"
|
|
|
|
#include "icom_defs.h"
|
|
|
|
#include "frame.h"
|
2024-03-01 22:41:44 +00:00
|
|
|
#include "cache.h"
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Build a CI-V frame.
|
|
|
|
* The whole frame is placed in frame[],
|
|
|
|
* "re_id" is the transceiver's CI-V address,
|
|
|
|
* "cmd" is the Command number,
|
|
|
|
* "subcmd" is the Sub command number, set to -1 if not present in frame,
|
|
|
|
* if the frame has no data, then the "data" pointer must be NULL,
|
|
|
|
* and data_len==0.
|
|
|
|
* "data_len" holds the Data area length pointed by the "data" pointer.
|
|
|
|
* REM: if "data" is NULL, then "data_len" MUST be 0.
|
|
|
|
*
|
|
|
|
* NB: the frame array must be big enough to hold the frame.
|
|
|
|
* The smallest frame is 6 bytes, the biggest is at least 13 bytes.
|
|
|
|
*/
|
2022-02-05 21:27:43 +00:00
|
|
|
int make_cmd_frame(unsigned char frame[], unsigned char re_id,
|
|
|
|
unsigned char ctrl_id,
|
2021-11-20 19:33:29 +00:00
|
|
|
unsigned char cmd, int subcmd,
|
2020-01-17 15:22:01 +00:00
|
|
|
const unsigned char *data, int data_len)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
frame[i++] = PAD; /* give old rigs a chance to flush their rx buffers */
|
|
|
|
#endif
|
|
|
|
frame[i++] = PR; /* Preamble code */
|
|
|
|
frame[i++] = PR;
|
|
|
|
frame[i++] = re_id;
|
|
|
|
frame[i++] = ctrl_id;
|
|
|
|
frame[i++] = cmd;
|
|
|
|
|
|
|
|
if (subcmd != -1)
|
|
|
|
{
|
|
|
|
#ifdef MULTIB_SUBCMD
|
|
|
|
register int j;
|
|
|
|
|
|
|
|
if ((j = subcmd & 0xff0000)) /* allows multi-byte subcmd for dsp rigs */
|
|
|
|
{
|
|
|
|
frame[i++] = j >> 16;
|
|
|
|
frame[i++] = (subcmd & 0xff00) >> 8;
|
|
|
|
}
|
|
|
|
else if ((j = subcmd & 0xff00)) { frame[i++] = j >> 8; }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
frame[i++] = subcmd & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data_len != 0)
|
|
|
|
{
|
|
|
|
memcpy(frame + i, data, data_len);
|
|
|
|
i += data_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame[i++] = FI; /* EOM code */
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
return (i);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
int icom_frame_fix_preamble(int frame_len, unsigned char *frame)
|
|
|
|
{
|
|
|
|
if (frame[0] == PR)
|
|
|
|
{
|
|
|
|
// Sometimes the second preamble byte is missing -> TODO: Find out why!
|
|
|
|
if (frame[1] != PR)
|
|
|
|
{
|
|
|
|
memmove(frame + 1, frame, frame_len);
|
|
|
|
frame_len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-26 11:49:24 +00:00
|
|
|
rig_debug(RIG_DEBUG_WARN, "%s: invalid Icom CI-V frame, no preamble found\n",
|
|
|
|
__func__);
|
2022-02-05 21:27:43 +00:00
|
|
|
return (-RIG_EPROTO);
|
2021-05-29 22:36:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return frame_len;
|
|
|
|
}
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* icom_one_transaction
|
|
|
|
*
|
|
|
|
* We assume that rig!=NULL, rig->state!= NULL, payload!=NULL, data!=NULL, data_len!=NULL
|
|
|
|
* Otherwise, you'll get a nice seg fault. You've been warned!
|
|
|
|
* payload can be NULL if payload_len == 0
|
|
|
|
* subcmd can be equal to -1 (no subcmd wanted)
|
|
|
|
* if no answer is to be expected, data_len must be set to NULL to tell so
|
|
|
|
*
|
|
|
|
* return RIG_OK if transaction completed,
|
|
|
|
* or a negative value otherwise indicating the error.
|
|
|
|
*/
|
2021-11-20 19:33:29 +00:00
|
|
|
int icom_one_transaction(RIG *rig, unsigned char cmd, int subcmd,
|
2020-01-17 15:22:01 +00:00
|
|
|
const unsigned char *payload, int payload_len, unsigned char *data,
|
|
|
|
int *data_len)
|
|
|
|
{
|
|
|
|
struct icom_priv_data *priv;
|
|
|
|
const struct icom_priv_caps *priv_caps;
|
|
|
|
struct rig_state *rs;
|
2024-02-03 19:11:46 +00:00
|
|
|
hamlib_port_t *rp = RIGPORT(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
struct timeval start_time, current_time, elapsed_time;
|
2020-01-17 15:22:01 +00:00
|
|
|
// this buf needs to be large enough for 0xfe strings for power up
|
|
|
|
// at 115,200 this is now at least 150
|
|
|
|
unsigned char buf[200];
|
|
|
|
unsigned char sendbuf[MAXFRAMELEN];
|
2021-05-29 22:36:49 +00:00
|
|
|
int frm_len, frm_data_len, retval;
|
2021-11-20 19:33:29 +00:00
|
|
|
unsigned char ctrl_id;
|
2023-04-25 16:07:25 +00:00
|
|
|
int collision_retry = 0;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2021-03-04 18:39:02 +00:00
|
|
|
ENTERFUNC;
|
2021-03-04 18:18:00 +00:00
|
|
|
memset(buf, 0, 200);
|
|
|
|
memset(sendbuf, 0, MAXFRAMELEN);
|
2020-01-17 15:22:01 +00:00
|
|
|
rs = &rig->state;
|
|
|
|
priv = (struct icom_priv_data *)rs->priv;
|
|
|
|
priv_caps = (struct icom_priv_caps *)rig->caps->priv;
|
|
|
|
|
|
|
|
ctrl_id = priv_caps->serial_full_duplex == 0 ? CTRLID : 0x80;
|
|
|
|
|
2021-11-20 19:33:29 +00:00
|
|
|
frm_len = make_cmd_frame(sendbuf, priv->re_civ_addr, ctrl_id, cmd,
|
2020-01-17 15:22:01 +00:00
|
|
|
subcmd, payload, payload_len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* should check return code and that write wrote cmd_len chars!
|
|
|
|
*/
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_active(rig);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2023-04-25 16:07:25 +00:00
|
|
|
collision_retry:
|
2024-03-01 22:41:44 +00:00
|
|
|
//rig_flush(rp);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2021-03-04 18:18:00 +00:00
|
|
|
if (data_len) { *data_len = 0; }
|
|
|
|
|
2024-02-03 19:11:46 +00:00
|
|
|
retval = write_block(rp, sendbuf, frm_len);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(retval);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv_caps->serial_full_duplex && !priv->serial_USB_echo_off)
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read what we just sent, because TX and RX are looped,
|
|
|
|
* and discard it...
|
|
|
|
* - if what we read is not what we sent, then it means
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
* a collision on the CI-V bus occurred!
|
2020-01-17 15:22:01 +00:00
|
|
|
* - if we get a timeout, then retry to send the frame,
|
|
|
|
* up to rs->retry times.
|
|
|
|
*/
|
|
|
|
|
2024-03-01 18:56:20 +00:00
|
|
|
again1:
|
2024-02-03 19:11:46 +00:00
|
|
|
retval = read_icom_frame(rp, buf, sizeof(buf));
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
if (retval == -RIG_ETIMEOUT || retval == 0)
|
|
|
|
{
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
/* Nothing received, CI-V interface is not echoing */
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_BUSERROR);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval < 0)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2020-01-17 15:22:01 +00:00
|
|
|
/* Other error, return it */
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(retval);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval < 1)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2024-03-01 22:41:44 +00:00
|
|
|
if (icom_is_async_frame(rig, frm_len, buf))
|
2024-03-01 18:56:20 +00:00
|
|
|
{
|
2024-03-01 22:41:44 +00:00
|
|
|
icom_process_async_frame(rig, frm_len, buf);
|
2024-03-01 18:56:20 +00:00
|
|
|
goto again1;
|
|
|
|
}
|
|
|
|
|
2024-03-01 22:41:44 +00:00
|
|
|
// we might have 0xfe string during rig wakeup
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: DEBUG retval=%d, frm_len=%d, cmd=0x%02x\n",
|
|
|
|
__func__, retval, frm_len, cmd);
|
|
|
|
|
2021-12-22 15:16:17 +00:00
|
|
|
if (retval != frm_len && cmd == C_SET_PWR)
|
|
|
|
{
|
2022-02-05 21:27:43 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: removing 0xfe power up echo, len=%d", __func__,
|
|
|
|
frm_len);
|
|
|
|
|
|
|
|
while (buf[2] == 0xfe)
|
2021-12-22 15:16:17 +00:00
|
|
|
{
|
2022-02-05 21:27:43 +00:00
|
|
|
memmove(buf, &buf[1], frm_len--);
|
2021-12-22 15:16:17 +00:00
|
|
|
}
|
2022-02-05 21:27:43 +00:00
|
|
|
|
|
|
|
dump_hex(buf, frm_len);
|
2021-12-22 15:16:17 +00:00
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
switch (buf[retval - 1])
|
|
|
|
{
|
|
|
|
case COL:
|
2023-05-08 12:37:13 +00:00
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
/* Collision */
|
2023-04-25 16:07:25 +00:00
|
|
|
// IC746 for example responds 0xfc when tuning is active so we will retry
|
|
|
|
if (collision_retry++ < 20)
|
|
|
|
{
|
2023-05-08 12:37:13 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: collision retry#%d\n", __func__,
|
|
|
|
collision_retry);
|
|
|
|
hl_usleep(500 *
|
|
|
|
1000); // 500ms 20 times for ~15 second max before we back out for a retry if needed
|
2023-04-25 16:07:25 +00:00
|
|
|
goto collision_retry;
|
|
|
|
}
|
2023-05-08 12:37:13 +00:00
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_BUSBUSY);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
case FI:
|
|
|
|
/* Ok, normal frame */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Timeout after reading at least one character */
|
|
|
|
/* Problem on ci-v bus? */
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_BUSERROR);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != frm_len)
|
|
|
|
{
|
|
|
|
/* Not the same length??? */
|
|
|
|
/* Problem on ci-v bus? */
|
|
|
|
/* Someone else got a packet in? */
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2023-07-24 22:35:14 +00:00
|
|
|
// first 2 bytes of everyting are 0xfe so we won't test those
|
|
|
|
// this allows some corruptin of the 0xfe bytes which has been seen in the wild
|
2023-12-16 17:37:58 +00:00
|
|
|
if (memcmp(&buf[2], &sendbuf[2], frm_len - 2) != 0)
|
2020-01-17 15:22:01 +00:00
|
|
|
{
|
|
|
|
/* Frames are different? */
|
|
|
|
/* Problem on ci-v bus? */
|
|
|
|
/* Someone else got a packet in? */
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* expect an answer?
|
|
|
|
*/
|
|
|
|
if (data_len == NULL)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(RIG_OK);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
gettimeofday(&start_time, NULL);
|
|
|
|
|
|
|
|
read_another_frame:
|
2020-01-17 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* wait for ACK ...
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
* FIXME: handle padding/collisions
|
2020-01-17 15:22:01 +00:00
|
|
|
* ACKFRMLEN is the smallest frame we can expect from the rig
|
|
|
|
*/
|
2024-03-01 18:56:20 +00:00
|
|
|
again2:
|
2020-07-03 13:05:13 +00:00
|
|
|
buf[0] = 0;
|
2024-02-03 19:11:46 +00:00
|
|
|
frm_len = read_icom_frame(rp, buf, sizeof(buf));
|
2023-12-16 17:37:58 +00:00
|
|
|
|
2024-03-15 12:27:19 +00:00
|
|
|
if (frm_len <= 0)
|
|
|
|
{
|
|
|
|
set_transaction_inactive(rig);
|
|
|
|
return frm_len;
|
|
|
|
}
|
|
|
|
|
2023-08-11 15:40:42 +00:00
|
|
|
if (frm_len > 4 && memcmp(buf, sendbuf, frm_len) == 0)
|
2023-12-16 17:37:58 +00:00
|
|
|
{
|
2023-08-11 15:40:42 +00:00
|
|
|
priv->serial_USB_echo_off = 0;
|
2023-12-16 17:37:58 +00:00
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2024-03-01 22:41:44 +00:00
|
|
|
if (icom_is_async_frame(rig, frm_len, buf))
|
2024-03-01 18:56:20 +00:00
|
|
|
{
|
2024-03-01 22:41:44 +00:00
|
|
|
icom_process_async_frame(rig, frm_len, buf);
|
2024-03-01 18:56:20 +00:00
|
|
|
goto again2;
|
|
|
|
}
|
|
|
|
|
2021-01-08 18:04:25 +00:00
|
|
|
#if 0
|
2021-01-09 16:13:17 +00:00
|
|
|
|
2021-01-08 18:04:25 +00:00
|
|
|
// this was causing rigctld to fail on IC706 and WSJT-X
|
|
|
|
// This dynamic detection is therefore disabled for now
|
2020-01-17 15:22:01 +00:00
|
|
|
if (memcmp(buf, sendbuf, frm_len) == 0 && priv->serial_USB_echo_off)
|
|
|
|
{
|
|
|
|
// Hmmm -- got an echo back when not expected so let's change
|
|
|
|
priv->serial_USB_echo_off = 0;
|
|
|
|
// And try again
|
2024-02-03 19:11:46 +00:00
|
|
|
frm_len = read_icom_frame(rp, buf, sizeof(buf));
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
2021-01-09 16:13:17 +00:00
|
|
|
|
2021-01-08 18:04:25 +00:00
|
|
|
#endif
|
2020-03-26 16:11:46 +00:00
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
if (frm_len < 0)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2023-02-04 20:22:57 +00:00
|
|
|
|
|
|
|
if (priv_caps->re_civ_addr != priv->re_civ_addr)
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Icom timeout civ expected=%02x, used=%02x\n",
|
|
|
|
__func__, priv_caps->re_civ_addr, priv->re_civ_addr);
|
|
|
|
}
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
/* RIG_TIMEOUT: timeout getting response, return timeout */
|
|
|
|
/* other error: return it */
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(frm_len);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (frm_len < 1)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
retval = icom_frame_fix_preamble(frm_len, buf);
|
2021-08-26 11:49:24 +00:00
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
if (retval < 0)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
RETURNFUNC(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
frm_len = retval;
|
|
|
|
|
2021-09-11 10:38:25 +00:00
|
|
|
if (frm_len < 1)
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "Unexpected frame len=%d\n", frm_len);
|
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
|
|
|
}
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
switch (buf[frm_len - 1])
|
|
|
|
{
|
|
|
|
case COL:
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2020-01-17 15:22:01 +00:00
|
|
|
/* Collision */
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_BUSBUSY);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
case FI:
|
|
|
|
/* Ok, normal frame */
|
|
|
|
break;
|
|
|
|
|
2021-03-11 16:24:22 +00:00
|
|
|
case NAK:
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-11 16:24:22 +00:00
|
|
|
RETURNFUNC(-RIG_ERJCTED);
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
default:
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2020-01-17 15:22:01 +00:00
|
|
|
/* Timeout after reading at least one character */
|
|
|
|
/* Problem on ci-v bus? */
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
if (frm_len < ACKFRMLEN)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
|
|
|
}
|
2021-03-15 22:51:22 +00:00
|
|
|
|
2021-03-13 14:03:53 +00:00
|
|
|
// if we send a bad command we will get back a NAK packet
|
|
|
|
// e.g. fe fe e0 50 fa fd
|
2021-05-29 22:36:49 +00:00
|
|
|
if (frm_len == 6 && NAK == buf[frm_len - 2])
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
RETURNFUNC(-RIG_ERJCTED);
|
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2021-03-15 22:51:22 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: frm_len=%d, frm_len-1=%02x, frm_len-2=%02x\n",
|
|
|
|
__func__, frm_len, buf[frm_len - 1], buf[frm_len - 2]);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2021-03-11 16:24:22 +00:00
|
|
|
// has to be one of these two now or frame is corrupt
|
2021-05-29 22:36:49 +00:00
|
|
|
if (FI != buf[frm_len - 1] && ACK != buf[frm_len - 1])
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
RETURNFUNC(-RIG_BUSBUSY);
|
|
|
|
}
|
2021-03-10 17:49:47 +00:00
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
frm_data_len = frm_len - (ACKFRMLEN - 1);
|
2021-03-15 22:51:22 +00:00
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
if (frm_data_len <= 0)
|
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
RETURNFUNC(-RIG_EPROTO);
|
|
|
|
}
|
|
|
|
|
2021-05-31 13:22:22 +00:00
|
|
|
// TODO: Does ctrlid (detected by icom_is_async_frame) vary (seeing some code above using 0x80 for non-full-duplex)?
|
2021-05-29 22:36:49 +00:00
|
|
|
if (icom_is_async_frame(rig, frm_len, buf))
|
|
|
|
{
|
2023-08-03 04:32:02 +00:00
|
|
|
int elapsedms;
|
2021-05-29 22:36:49 +00:00
|
|
|
icom_process_async_frame(rig, frm_len, buf);
|
|
|
|
|
|
|
|
gettimeofday(¤t_time, NULL);
|
|
|
|
timersub(¤t_time, &start_time, &elapsed_time);
|
|
|
|
|
2023-08-03 04:32:02 +00:00
|
|
|
elapsedms = (int)(elapsed_time.tv_sec * 1000 + elapsed_time.tv_usec / 1000);
|
2021-05-29 22:36:49 +00:00
|
|
|
|
2024-02-03 19:11:46 +00:00
|
|
|
if (elapsedms > rp->timeout)
|
2021-05-29 22:36:49 +00:00
|
|
|
{
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-05-29 22:36:49 +00:00
|
|
|
RETURNFUNC(-RIG_ETIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto read_another_frame;
|
|
|
|
}
|
|
|
|
|
2021-11-28 18:52:29 +00:00
|
|
|
set_transaction_inactive(rig);
|
2021-03-15 22:51:22 +00:00
|
|
|
|
2021-05-29 22:36:49 +00:00
|
|
|
*data_len = frm_data_len;
|
2021-12-02 04:52:55 +00:00
|
|
|
|
2023-08-02 22:32:51 +00:00
|
|
|
if (data != NULL) { memcpy(data, buf + 4, *data_len); }
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: check addresses in reply frame
|
|
|
|
*/
|
|
|
|
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(RIG_OK);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* icom_transaction
|
|
|
|
*
|
2022-01-25 23:41:26 +00:00
|
|
|
* This function honors rigport.retry count.
|
2020-01-17 15:22:01 +00:00
|
|
|
*
|
|
|
|
* We assume that rig!=NULL, rig->state!= NULL, payload!=NULL, data!=NULL, data_len!=NULL
|
|
|
|
* Otherwise, you'll get a nice seg fault. You've been warned!
|
|
|
|
* payload can be NULL if payload_len == 0
|
|
|
|
* subcmd can be equal to -1 (no subcmd wanted)
|
|
|
|
*
|
|
|
|
* return RIG_OK if transaction completed,
|
|
|
|
* or a negative value otherwise indicating the error.
|
|
|
|
*/
|
|
|
|
int icom_transaction(RIG *rig, int cmd, int subcmd,
|
|
|
|
const unsigned char *payload, int payload_len, unsigned char *data,
|
|
|
|
int *data_len)
|
|
|
|
{
|
|
|
|
int retval, retry;
|
|
|
|
|
2021-03-04 18:39:02 +00:00
|
|
|
ENTERFUNC;
|
2020-12-19 20:30:31 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,
|
2021-01-09 21:19:19 +00:00
|
|
|
"%s: cmd=0x%02x, subcmd=0x%02x, payload_len=%d\n", __func__,
|
|
|
|
cmd, subcmd, payload_len);
|
2020-12-19 20:30:31 +00:00
|
|
|
|
2024-02-03 19:11:46 +00:00
|
|
|
retry = RIGPORT(rig)->retry;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
retval = icom_one_transaction(rig, cmd, subcmd, payload, payload_len, data,
|
|
|
|
data_len);
|
|
|
|
|
2023-10-14 17:01:15 +00:00
|
|
|
// codes that make us return immediately
|
|
|
|
if (retval == RIG_OK || retval == -RIG_ERJCTED || retval == -RIG_BUSERROR)
|
2020-01-17 15:22:01 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2021-02-28 15:46:01 +00:00
|
|
|
|
2021-03-04 17:01:23 +00:00
|
|
|
rig_debug(RIG_DEBUG_WARN, "%s: retry=%d: %s\n", __func__, retry,
|
|
|
|
rigerror(retval));
|
2020-02-23 17:26:09 +00:00
|
|
|
|
2021-03-04 17:01:23 +00:00
|
|
|
// On some serial errors we may need a bit of time
|
|
|
|
hl_usleep(100 * 1000); // pause just a bit
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
while (retry-- > 0);
|
|
|
|
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
{
|
2020-05-09 16:52:27 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: failed: %s\n", __func__, rigerror(retval));
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 17:45:57 +00:00
|
|
|
RETURNFUNC(retval);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* used in read_icom_frame as end of block */
|
2021-10-10 22:17:30 +00:00
|
|
|
static const char icom_block_end[2] = { FI, COL};
|
|
|
|
#define icom_block_end_length 2
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
/*
|
2021-11-20 19:33:29 +00:00
|
|
|
* Read a whole CI-V frame (until 0xfd is encountered).
|
|
|
|
*
|
2020-01-17 15:22:01 +00:00
|
|
|
* TODO: strips padding/collisions
|
|
|
|
* FIXME: check return codes/bytes read
|
|
|
|
*/
|
2022-02-05 21:27:43 +00:00
|
|
|
static int read_icom_frame_generic(hamlib_port_t *p,
|
|
|
|
const unsigned char rxbuffer[],
|
2021-11-20 19:33:29 +00:00
|
|
|
size_t rxbuffer_len, int direct)
|
2020-01-17 15:22:01 +00:00
|
|
|
{
|
|
|
|
int read = 0;
|
|
|
|
int retries = 10;
|
2021-11-20 19:33:29 +00:00
|
|
|
unsigned char *rx_ptr = (unsigned char *) rxbuffer;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2021-03-04 17:01:23 +00:00
|
|
|
// zeroize the buffer so we can still check contents after timeouts
|
|
|
|
memset(rx_ptr, 0, rxbuffer_len);
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
/*
|
|
|
|
* OK, now sometimes we may time out, e.g. the IC7000 can time out
|
2021-11-20 19:33:29 +00:00
|
|
|
* during a PTT operation. So, we will ensure that the last thing we
|
2020-01-17 15:22:01 +00:00
|
|
|
* read was a proper end marker - if not, we will try again.
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
2021-11-20 19:33:29 +00:00
|
|
|
int i;
|
2022-02-05 21:27:43 +00:00
|
|
|
|
2021-11-20 19:33:29 +00:00
|
|
|
if (direct)
|
|
|
|
{
|
2021-12-12 21:05:26 +00:00
|
|
|
i = read_string_direct(p, rx_ptr, MAXFRAMELEN - read,
|
2022-02-05 21:27:43 +00:00
|
|
|
icom_block_end, icom_block_end_length, 0, 1);
|
2021-11-20 19:33:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-12 21:05:26 +00:00
|
|
|
i = read_string(p, rx_ptr, MAXFRAMELEN - read,
|
2022-02-05 21:27:43 +00:00
|
|
|
icom_block_end, icom_block_end_length, 0, 1);
|
2021-11-20 19:33:29 +00:00
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2023-04-11 21:20:32 +00:00
|
|
|
if (i < 0 && i != -RIG_BUSBUSY) /* die on errors */
|
2020-01-17 15:22:01 +00:00
|
|
|
{
|
2022-02-05 21:27:43 +00:00
|
|
|
return (i);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0) /* nothing read?*/
|
|
|
|
{
|
|
|
|
if (--retries <= 0) /* Tried enough times? */
|
|
|
|
{
|
2022-02-05 21:27:43 +00:00
|
|
|
return (read);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* OK, we got something. add it in and continue */
|
2021-10-10 21:27:58 +00:00
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
read += i;
|
|
|
|
rx_ptr += i;
|
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
while ((read < rxbuffer_len) && (rxbuffer[read - 1] != FI)
|
|
|
|
&& (rxbuffer[read - 1] != COL));
|
|
|
|
|
2023-03-08 21:35:08 +00:00
|
|
|
// Check that we have a valid frame preamble (which might be just a single preable character)
|
2023-04-26 20:38:08 +00:00
|
|
|
// Or an error code
|
|
|
|
if (rxbuffer[0] != PR && rxbuffer[0] != COL)
|
2023-03-08 21:35:08 +00:00
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:27:43 +00:00
|
|
|
return (read);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 19:33:29 +00:00
|
|
|
int read_icom_frame(hamlib_port_t *p, const unsigned char rxbuffer[],
|
|
|
|
size_t rxbuffer_len)
|
|
|
|
{
|
|
|
|
return read_icom_frame_generic(p, rxbuffer, rxbuffer_len, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int read_icom_frame_direct(hamlib_port_t *p, const unsigned char rxbuffer[],
|
|
|
|
size_t rxbuffer_len)
|
|
|
|
{
|
|
|
|
return read_icom_frame_generic(p, rxbuffer, rxbuffer_len, 1);
|
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* convert mode and width as expressed by Hamlib frontend
|
|
|
|
* to mode and passband data understandable by a CI-V rig
|
|
|
|
*
|
|
|
|
* if pd == -1, no passband data is to be sent
|
|
|
|
*
|
|
|
|
* return RIG_OK if everything's fine, negative value otherwise
|
|
|
|
*
|
|
|
|
* TODO: be more exhaustive
|
|
|
|
* assumes rig!=NULL
|
|
|
|
*/
|
2020-11-30 05:32:14 +00:00
|
|
|
int rig2icom_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width,
|
2020-01-17 15:22:01 +00:00
|
|
|
unsigned char *md, signed char *pd)
|
|
|
|
{
|
|
|
|
unsigned char icmode;
|
|
|
|
signed char icmode_ext;
|
2020-12-12 19:00:26 +00:00
|
|
|
pbwidth_t width_tmp = width;
|
2023-12-16 17:37:58 +00:00
|
|
|
const struct icom_priv_data *priv_data = (struct icom_priv_data *)
|
|
|
|
rig->state.priv;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2021-03-04 18:39:02 +00:00
|
|
|
ENTERFUNC;
|
2021-01-09 16:13:17 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: mode=%d, width=%d\n", __func__, (int)mode,
|
|
|
|
(int)width);
|
2020-01-17 15:22:01 +00:00
|
|
|
icmode_ext = -1;
|
|
|
|
|
2020-11-30 05:32:14 +00:00
|
|
|
if (width == RIG_PASSBAND_NOCHANGE) // then we read width so we can reuse it
|
|
|
|
{
|
2021-01-07 21:50:50 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: width==RIG_PASSBAND_NOCHANGE\n", __func__);
|
2020-11-30 05:32:14 +00:00
|
|
|
rmode_t tmode;
|
|
|
|
int ret = rig_get_mode(rig, vfo, &tmode, &width);
|
2020-11-30 20:53:55 +00:00
|
|
|
|
2020-11-30 05:32:14 +00:00
|
|
|
if (ret != RIG_OK)
|
|
|
|
{
|
2020-11-30 20:53:55 +00:00
|
|
|
rig_debug(RIG_DEBUG_WARN,
|
|
|
|
"%s: Failed to get width for passband nochange err=%s\n", __func__,
|
|
|
|
rigerror(ret));
|
2020-11-30 05:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case RIG_MODE_AM: icmode = S_AM; break;
|
|
|
|
|
2020-12-21 16:15:15 +00:00
|
|
|
case RIG_MODE_PKTAM: icmode = S_AM; break;
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
case RIG_MODE_AMN: icmode = S_AMN; break;
|
|
|
|
|
|
|
|
case RIG_MODE_AMS: icmode = S_AMS; break;
|
|
|
|
|
|
|
|
case RIG_MODE_CW: icmode = S_CW; break;
|
|
|
|
|
|
|
|
case RIG_MODE_CWR: icmode = S_CWR; break;
|
|
|
|
|
|
|
|
case RIG_MODE_USB: icmode = S_USB; break;
|
|
|
|
|
2022-07-27 22:16:17 +00:00
|
|
|
case RIG_MODE_PKTUSB:
|
|
|
|
icmode = S_USB;
|
|
|
|
|
2022-06-07 22:40:38 +00:00
|
|
|
if (rig->caps->rig_model == RIG_MODEL_IC7800)
|
|
|
|
{
|
|
|
|
icmode = S_PSK;
|
|
|
|
}
|
2022-07-27 22:16:17 +00:00
|
|
|
|
2022-06-07 22:40:38 +00:00
|
|
|
break;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
case RIG_MODE_LSB: icmode = S_LSB; break;
|
|
|
|
|
2022-07-27 22:16:17 +00:00
|
|
|
case RIG_MODE_PKTLSB:
|
2022-06-07 22:40:38 +00:00
|
|
|
icmode = S_LSB;
|
2022-07-27 22:16:17 +00:00
|
|
|
|
2022-06-07 22:40:38 +00:00
|
|
|
if (rig->caps->rig_model == RIG_MODEL_IC7800)
|
|
|
|
{
|
|
|
|
icmode = S_PSKR;
|
|
|
|
}
|
2022-07-27 22:16:17 +00:00
|
|
|
|
2022-06-07 22:40:38 +00:00
|
|
|
break;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
case RIG_MODE_RTTY: icmode = S_RTTY; break;
|
|
|
|
|
|
|
|
case RIG_MODE_RTTYR: icmode = S_RTTYR; break;
|
|
|
|
|
|
|
|
case RIG_MODE_PSK: icmode = S_PSK; break;
|
|
|
|
|
|
|
|
case RIG_MODE_PSKR: icmode = S_PSKR; break;
|
|
|
|
|
|
|
|
case RIG_MODE_FM: icmode = S_FM; break;
|
|
|
|
|
2020-12-21 16:15:15 +00:00
|
|
|
case RIG_MODE_PKTFM: icmode = S_FM; break;
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
case RIG_MODE_FMN: icmode = S_FMN; break;
|
|
|
|
|
2020-12-21 16:15:15 +00:00
|
|
|
case RIG_MODE_PKTFMN: icmode = S_FMN; break;
|
|
|
|
|
2020-01-17 15:22:01 +00:00
|
|
|
case RIG_MODE_WFM: icmode = S_WFM; break;
|
|
|
|
|
|
|
|
case RIG_MODE_P25: icmode = S_P25; break;
|
|
|
|
|
|
|
|
case RIG_MODE_DSTAR: icmode = S_DSTAR; break;
|
|
|
|
|
|
|
|
case RIG_MODE_DPMR: icmode = S_DPMR; break;
|
|
|
|
|
|
|
|
case RIG_MODE_NXDNVN: icmode = S_NXDNVN; break;
|
|
|
|
|
|
|
|
case RIG_MODE_NXDN_N: icmode = S_NXDN_N; break;
|
|
|
|
|
|
|
|
case RIG_MODE_DCR: icmode = S_DCR; break;
|
|
|
|
|
|
|
|
case RIG_MODE_DD: icmode = S_DD; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Unsupported Hamlib mode %s\n", __func__,
|
|
|
|
rig_strrmode(mode));
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(-RIG_EINVAL);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 19:00:26 +00:00
|
|
|
if (width_tmp != RIG_PASSBAND_NOCHANGE)
|
2020-01-17 15:22:01 +00:00
|
|
|
{
|
2021-01-07 21:50:50 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: width_tmp=%ld\n", __func__, width_tmp);
|
2020-03-20 12:51:32 +00:00
|
|
|
pbwidth_t medium_width = rig_passband_normal(rig, mode);
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2020-12-21 16:15:15 +00:00
|
|
|
if (width == RIG_PASSBAND_NORMAL)
|
2020-01-17 15:22:01 +00:00
|
|
|
{
|
2020-12-21 16:15:15 +00:00
|
|
|
// Use rig default for "normal" passband
|
|
|
|
icmode_ext = -1;
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
else if (width < medium_width)
|
|
|
|
{
|
|
|
|
icmode_ext = PD_NARROW_3;
|
|
|
|
}
|
2020-12-21 16:15:15 +00:00
|
|
|
else if (width == medium_width)
|
|
|
|
{
|
|
|
|
icmode_ext = PD_MEDIUM_3;
|
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
icmode_ext = PD_WIDE_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rig->caps->rig_model == RIG_MODEL_ICR7000)
|
|
|
|
{
|
|
|
|
if (mode == RIG_MODE_USB || mode == RIG_MODE_LSB)
|
|
|
|
{
|
|
|
|
icmode = S_R7000_SSB;
|
|
|
|
icmode_ext = 0x00;
|
|
|
|
}
|
|
|
|
else if (mode == RIG_MODE_AM && icmode_ext == -1)
|
|
|
|
{
|
|
|
|
icmode_ext = PD_WIDE_3; /* default to Wide */
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 21:07:04 +00:00
|
|
|
|
2020-12-13 05:05:59 +00:00
|
|
|
*pd = icmode_ext;
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
2020-12-12 19:22:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// filter should already be set elsewhere
|
2020-12-13 05:05:59 +00:00
|
|
|
*pd = priv_data->filter;
|
2020-12-12 19:22:49 +00:00
|
|
|
}
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
*md = icmode;
|
2021-03-04 18:39:02 +00:00
|
|
|
RETURNFUNC(RIG_OK);
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* assumes rig!=NULL, mode!=NULL, width!=NULL
|
|
|
|
*/
|
|
|
|
void icom2rig_mode(RIG *rig, unsigned char md, int pd, rmode_t *mode,
|
|
|
|
pbwidth_t *width)
|
|
|
|
{
|
2020-02-21 15:45:31 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: mode=0x%02x, pd=%d\n", __func__, md, pd);
|
2020-01-17 15:22:01 +00:00
|
|
|
*width = RIG_PASSBAND_NORMAL;
|
|
|
|
|
|
|
|
switch (md)
|
|
|
|
{
|
|
|
|
case S_AM: if (rig->caps->rig_model == RIG_MODEL_ICR30 && pd == 0x02)
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_AMN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_AM;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case S_AMS: *mode = RIG_MODE_AMS; break;
|
|
|
|
|
|
|
|
case S_CW: *mode = RIG_MODE_CW; break;
|
|
|
|
|
|
|
|
case S_CWR: *mode = RIG_MODE_CWR; break;
|
|
|
|
|
|
|
|
case S_FM: if (rig->caps->rig_model == RIG_MODEL_ICR7000
|
|
|
|
&& pd == 0x00)
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_USB;
|
|
|
|
*width = rig_passband_normal(rig, RIG_MODE_USB);
|
2021-03-05 17:51:56 +00:00
|
|
|
return;
|
2020-01-17 15:22:01 +00:00
|
|
|
}
|
|
|
|
else if (rig->caps->rig_model == RIG_MODEL_ICR30 && pd == 0x02)
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_FMN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_FM;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case S_WFM: *mode = RIG_MODE_WFM; break;
|
|
|
|
|
|
|
|
case S_USB: *mode = RIG_MODE_USB; break;
|
|
|
|
|
|
|
|
case S_LSB: *mode = RIG_MODE_LSB; break;
|
|
|
|
|
|
|
|
case S_RTTY: *mode = RIG_MODE_RTTY; break;
|
|
|
|
|
|
|
|
case S_RTTYR: *mode = RIG_MODE_RTTYR; break;
|
|
|
|
|
2022-06-07 22:40:38 +00:00
|
|
|
case S_PSK:
|
2022-07-27 22:16:17 +00:00
|
|
|
*mode = RIG_MODE_PSK;
|
|
|
|
|
|
|
|
if (rig->caps->rig_model == RIG_MODEL_IC7800)
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_PKTUSB;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
2022-06-07 22:40:38 +00:00
|
|
|
case S_PSKR:
|
2022-07-27 22:16:17 +00:00
|
|
|
*mode = RIG_MODE_PSKR;
|
|
|
|
|
|
|
|
if (rig->caps->rig_model == RIG_MODEL_IC7800)
|
|
|
|
{
|
|
|
|
*mode = RIG_MODE_PKTLSB;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
case S_DSTAR: *mode = RIG_MODE_DSTAR; break;
|
|
|
|
|
|
|
|
case S_P25: *mode = RIG_MODE_P25; break;
|
|
|
|
|
|
|
|
case S_DPMR: *mode = RIG_MODE_DPMR; break;
|
|
|
|
|
|
|
|
case S_NXDNVN: *mode = RIG_MODE_NXDNVN; break;
|
|
|
|
|
|
|
|
case S_NXDN_N: *mode = RIG_MODE_NXDN_N; break;
|
|
|
|
|
|
|
|
case S_DCR: *mode = RIG_MODE_DCR; break;
|
|
|
|
|
|
|
|
case 0xff: *mode = RIG_MODE_NONE; break; /* blank mem channel */
|
|
|
|
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "icom: Unsupported Icom mode %#.2x\n",
|
|
|
|
md);
|
|
|
|
*mode = RIG_MODE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Most rigs return 1-wide, 2-narrow; or if it has 3 filters: 1-wide, 2-middle,
|
|
|
|
3-narrow. (Except for the 706 mkIIg 0-wide, 1-middle, 2-narrow.) For DSP
|
|
|
|
rigs these are presets, which can be programmed for 30 - 41 bandwidths,
|
|
|
|
depending on mode */
|
|
|
|
|
2020-02-21 15:45:31 +00:00
|
|
|
if (pd >= 0 && (rig->caps->rig_model == RIG_MODEL_IC706MKIIG ||
|
2020-02-23 17:26:09 +00:00
|
|
|
rig->caps->rig_model == RIG_MODEL_IC706 ||
|
|
|
|
rig->caps->rig_model == RIG_MODEL_IC706MKII)) { pd++; }
|
2020-01-17 15:22:01 +00:00
|
|
|
|
|
|
|
switch (pd)
|
|
|
|
{
|
|
|
|
case 0x01:
|
|
|
|
|
|
|
|
/* if no wide filter defined it's the default */
|
|
|
|
if (!(*width = rig_passband_wide(rig, *mode)))
|
|
|
|
{
|
|
|
|
*width = rig_passband_normal(rig, *mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02:
|
|
|
|
if ((*width = rig_passband_wide(rig, *mode)))
|
|
|
|
{
|
|
|
|
*width = rig_passband_normal(rig, *mode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* This really just depends on how you program the table. */
|
|
|
|
{
|
|
|
|
*width = rig_passband_narrow(rig, *mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03:
|
|
|
|
*width = rig_passband_narrow(rig, *mode);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
break; /* no passband data */
|
|
|
|
|
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "icom: Unsupported Icom mode width %#.2x\n", pd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|