2000-09-16 01:49:40 +00:00
/*
2001-07-13 19:08:15 +00:00
* Hamlib CI - V backend - main file
2006-01-09 21:45:06 +00:00
* Copyright ( c ) 2000 - 2005 by Stephane Fillod
2000-09-16 01:49:40 +00:00
*
2007-02-28 08:52:49 +00:00
* $ Id : icom . c , v 1.101 2007 - 02 - 28 08 : 50 : 20 mardigras Exp $
2000-09-16 01:49:40 +00:00
*
2001-07-13 19:08:15 +00:00
* This library is free software ; you can redistribute it and / or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation ; either version 2 of
* the License , or ( at your option ) any later version .
2000-09-16 01:49:40 +00:00
*
2001-07-13 19:08:15 +00:00
* This program 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 Library General Public License for more details .
2000-09-16 01:49:40 +00:00
*
2001-07-13 19:08:15 +00:00
* You should have received a copy of the GNU Library General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
2000-09-16 01:49:40 +00:00
*
*/
2001-07-13 19:08:15 +00:00
# ifdef HAVE_CONFIG_H
# include "config.h"
# endif
2003-10-01 19:40:15 +00:00
# include <stdio.h>
2000-09-16 01:49:40 +00:00
# include <stdlib.h>
# include <string.h> /* String function definitions */
# include <unistd.h> /* UNIX standard function definitions */
2000-10-08 21:38:45 +00:00
# include <math.h>
2000-09-16 01:49:40 +00:00
2001-12-16 11:14:47 +00:00
# include <hamlib/rig.h>
# include <serial.h>
# include <misc.h>
# include <cal.h>
2002-01-27 14:50:22 +00:00
# include <token.h>
2003-04-16 22:30:43 +00:00
# include <register.h>
2001-06-15 07:08:37 +00:00
2000-09-16 01:49:40 +00:00
# include "icom.h"
# include "icom_defs.h"
2000-10-01 12:37:10 +00:00
# include "frame.h"
2000-09-16 01:49:40 +00:00
2000-10-10 21:58:31 +00:00
const struct ts_sc_list r8500_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ 50 , 0x01 } ,
{ 100 , 0x02 } ,
{ kHz ( 1 ) , 0x03 } ,
{ 12500 , 0x04 } ,
{ kHz ( 5 ) , 0x05 } ,
{ kHz ( 9 ) , 0x06 } ,
{ kHz ( 10 ) , 0x07 } ,
{ 12500 , 0x08 } ,
{ kHz ( 20 ) , 0x09 } ,
{ kHz ( 25 ) , 0x10 } ,
{ kHz ( 100 ) , 0x11 } ,
{ MHz ( 1 ) , 0x12 } ,
{ 0 , 0x13 } , /* programmable tuning step not supported */
{ 0 , 0 } ,
2000-10-10 21:58:31 +00:00
} ;
const struct ts_sc_list ic737_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ kHz ( 1 ) , 0x01 } ,
{ kHz ( 2 ) , 0x02 } ,
{ kHz ( 3 ) , 0x03 } ,
{ kHz ( 4 ) , 0x04 } ,
{ kHz ( 5 ) , 0x05 } ,
{ kHz ( 6 ) , 0x06 } ,
{ kHz ( 7 ) , 0x07 } ,
{ kHz ( 8 ) , 0x08 } ,
{ kHz ( 9 ) , 0x09 } ,
{ kHz ( 10 ) , 0x10 } ,
{ 0 , 0 } ,
2000-10-10 21:58:31 +00:00
} ;
const struct ts_sc_list r75_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ 100 , 0x01 } ,
{ kHz ( 1 ) , 0x02 } ,
{ kHz ( 5 ) , 0x03 } ,
{ 6250 , 0x04 } ,
{ kHz ( 9 ) , 0x05 } ,
{ kHz ( 10 ) , 0x06 } ,
{ 12500 , 0x07 } ,
{ kHz ( 20 ) , 0x08 } ,
{ kHz ( 25 ) , 0x09 } ,
{ kHz ( 100 ) , 0x10 } ,
{ MHz ( 1 ) , 0x11 } ,
{ 0 , 0 } ,
2000-10-10 21:58:31 +00:00
} ;
const struct ts_sc_list r7100_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 100 , 0x00 } ,
{ kHz ( 1 ) , 0x01 } ,
{ kHz ( 5 ) , 0x02 } ,
{ kHz ( 10 ) , 0x03 } ,
{ 12500 , 0x04 } ,
{ kHz ( 20 ) , 0x05 } ,
{ kHz ( 25 ) , 0x06 } ,
{ kHz ( 100 ) , 0x07 } ,
{ 0 , 0 } ,
2000-10-10 21:58:31 +00:00
} ;
2002-01-27 14:50:22 +00:00
const struct ts_sc_list r9000_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ 100 , 0x01 } ,
{ kHz ( 1 ) , 0x02 } ,
{ kHz ( 5 ) , 0x03 } ,
{ kHz ( 9 ) , 0x04 } ,
{ kHz ( 10 ) , 0x05 } ,
{ 12500 , 0x06 } ,
{ kHz ( 20 ) , 0x07 } ,
{ kHz ( 25 ) , 0x08 } ,
{ kHz ( 100 ) , 0x09 } ,
{ 0 , 0 } ,
2002-01-27 14:50:22 +00:00
} ;
2002-03-05 23:31:31 +00:00
const struct ts_sc_list ic718_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ kHz ( 1 ) , 0x01 } ,
{ kHz ( 5 ) , 0x01 } ,
{ kHz ( 9 ) , 0x01 } ,
{ kHz ( 10 ) , 0x04 } ,
{ kHz ( 100 ) , 0x05 } ,
{ 0 , 0 } ,
2002-03-05 23:31:31 +00:00
} ;
2002-01-27 14:50:22 +00:00
2000-10-10 21:58:31 +00:00
const struct ts_sc_list ic756_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ kHz ( 1 ) , 0x01 } ,
{ kHz ( 5 ) , 0x02 } ,
{ kHz ( 9 ) , 0x03 } ,
{ kHz ( 10 ) , 0x04 } ,
{ 0 , 0 } ,
2000-10-10 21:58:31 +00:00
} ;
2002-01-27 14:50:22 +00:00
const struct ts_sc_list ic756pro_ts_sc_list [ ] = {
2006-07-18 22:51:43 +00:00
{ 10 , 0x00 } , /* 1 if step turned off */
2005-04-16 11:55:49 +00:00
{ 100 , 0x01 } ,
{ kHz ( 1 ) , 0x02 } ,
{ kHz ( 5 ) , 0x03 } ,
{ kHz ( 9 ) , 0x04 } ,
{ kHz ( 10 ) , 0x05 } ,
{ kHz ( 12.5 ) , 0x06 } ,
{ kHz ( 20 ) , 0x07 } ,
{ kHz ( 25 ) , 0x08 } ,
{ 0 , 0 } ,
2002-01-27 14:50:22 +00:00
} ;
2000-10-10 21:58:31 +00:00
const struct ts_sc_list ic706_ts_sc_list [ ] = {
2005-04-16 11:55:49 +00:00
{ 10 , 0x00 } ,
{ 100 , 0x01 } ,
{ kHz ( 1 ) , 0x02 } ,
{ kHz ( 5 ) , 0x03 } ,
{ kHz ( 9 ) , 0x04 } ,
{ kHz ( 10 ) , 0x05 } ,
{ 12500 , 0x06 } ,
{ kHz ( 20 ) , 0x07 } ,
{ kHz ( 25 ) , 0x08 } ,
{ kHz ( 100 ) , 0x09 } ,
{ 0 , 0 } ,
2000-10-10 21:58:31 +00:00
} ;
2006-11-07 12:21:39 +00:00
const struct ts_sc_list ic7000_ts_sc_list [ ] = {
{ 10 , 0x00 } ,
{ 100 , 0x01 } ,
{ kHz ( 1 ) , 0x02 } ,
{ kHz ( 5 ) , 0x03 } ,
{ kHz ( 9 ) , 0x04 } ,
{ kHz ( 10 ) , 0x05 } ,
{ 12500 , 0x06 } ,
{ kHz ( 20 ) , 0x07 } ,
{ kHz ( 25 ) , 0x08 } ,
{ kHz ( 100 ) , 0x09 } ,
{ MHz ( 1 ) , 0x10 } ,
{ 0 , 0 } ,
} ;
2002-02-28 10:59:46 +00:00
const struct ts_sc_list ic910_ts_sc_list [ ] = {
{ Hz ( 1 ) , 0x00 } ,
{ Hz ( 10 ) , 0x01 } ,
{ Hz ( 50 ) , 0x02 } ,
{ Hz ( 100 ) , 0x03 } ,
{ kHz ( 1 ) , 0x04 } ,
{ kHz ( 5 ) , 0x05 } ,
{ kHz ( 6.25 ) , 0x06 } ,
{ kHz ( 10 ) , 0x07 } ,
{ kHz ( 12.5 ) , 0x08 } ,
{ kHz ( 20 ) , 0x09 } ,
{ kHz ( 25 ) , 0x10 } ,
{ kHz ( 100 ) , 0x11 } ,
{ 0 , 0 } ,
} ;
2000-09-16 01:49:40 +00:00
2006-09-22 19:55:59 +00:00
/* rtty filter list for some DSP rigs ie PRO */
const pbwidth_t rtty_fil [ ] = {
Hz ( 250 ) ,
Hz ( 300 ) ,
Hz ( 350 ) ,
Hz ( 500 ) ,
kHz ( 1 ) ,
0 ,
2006-07-18 22:51:43 +00:00
} ;
2000-09-19 07:04:05 +00:00
struct icom_addr {
2005-04-16 11:55:49 +00:00
rig_model_t model ;
unsigned char re_civ_addr ;
2000-09-19 07:04:05 +00:00
} ;
2001-07-21 13:00:03 +00:00
2002-01-27 14:50:22 +00:00
# define TOK_CIVADDR TOKEN_BACKEND(1)
# define TOK_MODE731 TOKEN_BACKEND(2)
2001-07-21 13:00:03 +00:00
const struct confparams icom_cfg_params [ ] = {
2002-02-28 10:59:46 +00:00
{ TOK_CIVADDR , " civaddr " , " CI-V address " , " Transceiver's CI-V address " ,
2002-08-16 17:43:02 +00:00
" 0 " , RIG_CONF_NUMERIC , { . n = { 0 , 0xff , 1 } }
2001-07-21 13:00:03 +00:00
} ,
{ TOK_MODE731 , " mode731 " , " CI-V 731 mode " , " CI-V operating frequency "
2002-02-28 10:59:46 +00:00
" data length, needed for IC731 and IC735 " ,
2001-07-21 13:00:03 +00:00
" 0 " , RIG_CONF_CHECKBUTTON
} ,
{ RIG_CONF_END , NULL , }
} ;
2000-10-08 21:38:45 +00:00
/*
* Please , if the default CI - V address of your rig is listed as UNKNOWN_ADDR ,
* send the value to < f4cfe @ users . sourceforge . net > for inclusion . Thanks - - SF
*
* TODO : sort this list with most frequent rigs first .
*/
2000-09-19 07:04:05 +00:00
static const struct icom_addr icom_addr_list [ ] = {
2005-04-16 11:55:49 +00:00
{ RIG_MODEL_IC703 , 0x68 } ,
{ RIG_MODEL_IC706 , 0x48 } ,
{ RIG_MODEL_IC706MKII , 0x4e } ,
{ RIG_MODEL_IC706MKIIG , 0x58 } ,
{ RIG_MODEL_IC271 , 0x20 } ,
{ RIG_MODEL_IC275 , 0x10 } ,
{ RIG_MODEL_IC375 , 0x12 } ,
{ RIG_MODEL_IC471 , 0x22 } ,
{ RIG_MODEL_IC475 , 0x14 } ,
{ RIG_MODEL_IC575 , 0x16 } ,
{ RIG_MODEL_IC707 , 0x3e } ,
{ RIG_MODEL_IC725 , 0x28 } ,
{ RIG_MODEL_IC726 , 0x30 } ,
{ RIG_MODEL_IC728 , 0x38 } ,
{ RIG_MODEL_IC729 , 0x3a } ,
{ RIG_MODEL_IC731 , 0x02 } , /* need confirmation */
{ RIG_MODEL_IC735 , 0x04 } ,
{ RIG_MODEL_IC736 , 0x40 } ,
{ RIG_MODEL_IC746 , 0x56 } ,
{ RIG_MODEL_IC746PRO , 0x66 } ,
{ RIG_MODEL_IC737 , 0x3c } ,
{ RIG_MODEL_IC738 , 0x44 } ,
{ RIG_MODEL_IC751 , 0x1c } ,
{ RIG_MODEL_IC751A , 0x1c } ,
{ RIG_MODEL_IC756 , 0x50 } ,
{ RIG_MODEL_IC756PRO , 0x5c } ,
{ RIG_MODEL_IC756PROII , 0x64 } ,
{ RIG_MODEL_IC756PROIII , 0x6e } ,
{ RIG_MODEL_IC761 , 0x1e } ,
{ RIG_MODEL_IC765 , 0x2c } ,
{ RIG_MODEL_IC775 , 0x46 } ,
{ RIG_MODEL_IC7800 , 0x6a } ,
{ RIG_MODEL_IC781 , 0x26 } ,
{ RIG_MODEL_IC820 , 0x42 } ,
{ RIG_MODEL_IC821 , 0x4c } ,
{ RIG_MODEL_IC821H , 0x4c } ,
{ RIG_MODEL_IC910 , 0x60 } ,
{ RIG_MODEL_IC970 , 0x2e } ,
{ RIG_MODEL_IC1271 , 0x24 } ,
{ RIG_MODEL_IC1275 , 0x18 } ,
{ RIG_MODEL_ICR10 , 0x52 } ,
{ RIG_MODEL_ICR20 , 0x6c } ,
{ RIG_MODEL_ICR71 , 0x1a } ,
{ RIG_MODEL_ICR72 , 0x32 } ,
{ RIG_MODEL_ICR75 , 0x5a } ,
{ RIG_MODEL_IC78 , 0x62 } ,
{ RIG_MODEL_ICR7000 , 0x08 } ,
{ RIG_MODEL_ICR7100 , 0x34 } ,
{ RIG_MODEL_ICR8500 , 0x4a } ,
{ RIG_MODEL_ICR9000 , 0x2a } ,
{ RIG_MODEL_MINISCOUT , 0x94 } ,
{ RIG_MODEL_IC718 , 0x5e } ,
{ RIG_MODEL_OS535 , 0x80 } ,
{ RIG_MODEL_ICID1 , 0x01 } ,
2006-01-09 21:45:06 +00:00
{ RIG_MODEL_IC7000 , 0x70 } ,
2005-04-16 11:55:49 +00:00
{ RIG_MODEL_NONE , 0 } ,
2000-09-19 07:04:05 +00:00
} ;
2000-09-16 01:49:40 +00:00
/*
* This is a generic icom_init function .
* You might want to define yours , so you can customize it for your rig
*
2002-02-28 10:59:46 +00:00
* Basically , it sets up * priv
2001-06-04 17:01:21 +00:00
* REM : serial port is already open ( rig - > state . rigport . fd )
2000-09-16 01:49:40 +00:00
*/
int icom_init ( RIG * rig )
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
const struct icom_priv_caps * priv_caps ;
const struct rig_caps * caps ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
if ( ! rig | | ! rig - > caps )
return - RIG_EINVAL ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
caps = rig - > caps ;
2001-02-27 23:06:53 +00:00
2005-04-16 11:55:49 +00:00
if ( ! caps - > priv )
return - RIG_ECONF ;
2001-03-04 13:03:41 +00:00
2005-04-16 11:55:49 +00:00
priv_caps = ( const struct icom_priv_caps * ) caps - > priv ;
2001-03-04 13:03:41 +00:00
2005-04-16 11:55:49 +00:00
priv = ( struct icom_priv_data * ) malloc ( sizeof ( struct icom_priv_data ) ) ;
if ( ! priv ) {
/* whoops! memory shortage! */
return - RIG_ENOMEM ;
}
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
rig - > state . priv = ( void * ) priv ;
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
/* TODO: CI-V address should be customizable */
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
/*
* init the priv_data from static struct
* + override with preferences
*/
2000-09-19 07:04:05 +00:00
2005-04-16 11:55:49 +00:00
priv - > re_civ_addr = priv_caps - > re_civ_addr ;
priv - > civ_731_mode = priv_caps - > civ_731_mode ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-09-16 01:49:40 +00:00
}
/*
* ICOM Generic icom_cleanup routine
* the serial port is closed by the frontend
*/
int icom_cleanup ( RIG * rig )
{
2005-04-16 11:55:49 +00:00
if ( ! rig )
return - RIG_EINVAL ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
if ( rig - > state . priv )
free ( rig - > state . priv ) ;
rig - > state . priv = NULL ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-09-16 01:49:40 +00:00
}
/*
2000-10-01 12:37:10 +00:00
* icom_set_freq
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
2000-09-16 01:49:40 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_set_freq ( RIG * rig , vfo_t vfo , freq_t freq )
2000-09-16 01:49:40 +00:00
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char freqbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int freq_len , ack_len = sizeof ( ackbuf ) , retval ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
freq_len = priv - > civ_731_mode ? 4 : 5 ;
/*
* to_bcd requires nibble len
*/
to_bcd ( freqbuf , freq , freq_len * 2 ) ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_FREQ , - 1 , freqbuf , freq_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-09-19 07:04:05 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_freq: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-09-16 01:49:40 +00:00
}
2000-09-19 07:04:05 +00:00
/*
2000-10-01 12:37:10 +00:00
* icom_get_freq
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , freq ! = NULL
2001-03-04 23:05:18 +00:00
* Note : old rig may return less than 4 / 5 bytes for get_freq
2000-09-19 07:04:05 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_get_freq ( RIG * rig , vfo_t vfo , freq_t * freq )
2000-09-19 07:04:05 +00:00
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char freqbuf [ MAXFRAMELEN ] ;
int freq_len , retval ;
2000-09-19 07:04:05 +00:00
2005-04-16 11:55:49 +00:00
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_RD_FREQ , - 1 , NULL , 0 ,
freqbuf , & freq_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
/*
* freqbuf should contain Cn , Data area
*/
freq_len - - ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
/*
* is it a blank mem channel ?
*/
if ( freq_len = = 1 & & freqbuf [ 1 ] = = 0xff ) {
* freq = RIG_FREQ_NONE ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
if ( freq_len ! = 4 & & freq_len ! = 5 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_freq: wrong frame len=%d \n " ,
freq_len ) ;
return - RIG_ERJCTED ;
}
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
if ( freq_len ! = ( priv - > civ_731_mode ? 4 : 5 ) ) {
rig_debug ( RIG_DEBUG_WARN , " icom_get_freq: "
" freq len (%d) differs from "
" expected \n " , freq_len ) ;
}
2003-01-06 22:06:57 +00:00
2005-04-16 11:55:49 +00:00
/*
* from_bcd requires nibble len
*/
* freq = from_bcd ( freqbuf + 1 , freq_len * 2 ) ;
2000-09-16 01:49:40 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-09-16 01:49:40 +00:00
}
2002-08-19 22:17:11 +00:00
int icom_set_rit ( RIG * rig , vfo_t vfo , shortfreq_t rit )
{
2005-04-16 11:55:49 +00:00
unsigned char freqbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int freq_len , ack_len = sizeof ( ackbuf ) , retval ;
2002-08-19 22:17:11 +00:00
2005-04-16 11:55:49 +00:00
freq_len = 2 ;
/*
* to_bcd requires nibble len
*/
to_bcd ( freqbuf , rit , freq_len * 2 ) ;
2002-08-19 22:17:11 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_OFFS , - 1 , freqbuf , freq_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2002-08-19 22:17:11 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_rit: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2002-08-19 22:17:11 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2002-08-19 22:17:11 +00:00
}
2006-09-22 19:55:59 +00:00
/* icom_get_dsp_flt
returns the dsp filter width in hz or 0 if the command is not implemented or error . This allows the default parameters to be assigned from the get_mode routine if the command is not implemented .
Assumes rig ! = null and the current mode is in mode .
Has been tested for IC - 746 pro , Should work on the all dsp rigs ie pro models .
The 746 documentation says it has the get_if_filter , but doesn ' t give any decoding information ? Please test .
*/
pbwidth_t icom_get_dsp_flt ( RIG * rig , rmode_t mode ) {
int retval , res_len , rfstatus ;
unsigned char resbuf [ MAXFRAMELEN ] ;
value_t rfwidth ;
if ( rig_has_get_func ( rig , RIG_FUNC_RF ) & & ( mode & ( RIG_MODE_RTTY | RIG_MODE_RTTYR ) ) ) {
if ( ! rig_get_func ( rig , RIG_VFO_CURR , RIG_FUNC_RF , & rfstatus ) & & ( rfstatus ) ) {
retval = rig_get_ext_parm ( rig , TOK_RTTY_FLTR , & rfwidth ) ;
if ( retval ! = RIG_OK ) return 0 ; /* use default */
else return rtty_fil [ rfwidth . i ] ;
}
}
retval = icom_transaction ( rig , C_CTL_MEM , S_MEM_FILT_WDTH , 0 , 0 ,
resbuf , & res_len ) ;
if ( retval ! = RIG_OK ) {
rig_debug ( RIG_DEBUG_ERR , " %s: protocol error (%#.2x), "
" len=%d \n " , __FUNCTION__ , resbuf [ 0 ] , res_len ) ;
return 0 ; /* use default */
}
if ( res_len = = 3 & & resbuf [ 0 ] = = C_CTL_MEM ) {
int i ;
i = ( int ) from_bcd ( resbuf + 2 , 2 ) ;
if ( mode & RIG_MODE_AM ) return ( i + 1 ) * 200 ; /* Ic_7800 */
else if ( mode & ( RIG_MODE_CW | RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_RTTY | RIG_MODE_RTTYR ) ) return i < 10 ? + + i * 50 : ( i - 4 ) * 100 ;
}
return 0 ;
}
2000-10-08 21:38:45 +00:00
/*
* icom_set_mode
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_mode ( RIG * rig , vfo_t vfo , rmode_t mode , pbwidth_t width )
2000-10-08 21:38:45 +00:00
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
unsigned char icmode ;
signed char icmode_ext ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval , err ;
2005-04-16 11:55:49 +00:00
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
err = rig2icom_mode ( rig , mode , width , & icmode , & icmode_ext ) ;
if ( err < 0 )
return err ;
/* IC-731 and IC-735 don't support passband data */
if ( priv - > civ_731_mode | | rig - > caps - > rig_model = = RIG_MODEL_OS456 )
icmode_ext = - 1 ;
2006-10-07 20:45:40 +00:00
retval = icom_transaction ( rig , C_SET_MODE , icmode , ( unsigned char * ) & icmode_ext ,
( icmode_ext = = - 1 ? 0 : 1 ) , ackbuf , & ack_len ) ;
2005-04-16 11:55:49 +00:00
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_mode: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-08 21:38:45 +00:00
}
/*
* icom_get_mode
2000-12-04 23:39:18 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , mode ! = NULL , width ! = NULL
2001-03-02 18:33:27 +00:00
*
* TODO : some IC781 ' s , when sending mode info , in wide filter mode , no
* width data is send along , making the frame 1 byte short .
* ( Thank to Mel , VE2DC for this info )
2000-10-08 21:38:45 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_get_mode ( RIG * rig , vfo_t vfo , rmode_t * mode , pbwidth_t * width )
2000-10-08 21:38:45 +00:00
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char modebuf [ MAXFRAMELEN ] ;
int mode_len , retval ;
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_RD_MODE , - 1 , NULL , 0 ,
modebuf , & mode_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
/*
* modebuf should contain Cn , Data area
*/
mode_len - - ;
if ( mode_len ! = 2 & & mode_len ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_mode: wrong frame len=%d \n " ,
mode_len ) ;
return - RIG_ERJCTED ;
}
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
icom2rig_mode ( rig , modebuf [ 1 ] , mode_len = = 2 ? modebuf [ 2 ] : - 1 , mode , width ) ;
2000-10-08 21:38:45 +00:00
2006-09-22 19:55:59 +00:00
/* Most rigs return 1-wide, 2-normal,3-narrow For DSP rigs these are presets, can be programmed for 30 - 41 bandwidths, depending on mode Lets check for dsp filters */
2007-02-28 08:52:49 +00:00
if ( ( retval = icom_get_dsp_flt ( rig , * mode ) ) ! = 0 )
2006-10-07 20:45:40 +00:00
* width = retval ;
2006-09-22 19:55:59 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-08 21:38:45 +00:00
}
/*
* icom_set_vfo
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
int icom_set_vfo ( RIG * rig , vfo_t vfo )
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , icvfo , retval ;
2005-04-16 11:55:49 +00:00
if ( vfo = = RIG_VFO_CURR )
return RIG_OK ;
switch ( vfo ) {
case RIG_VFO_A : icvfo = S_VFOA ; break ;
case RIG_VFO_B : icvfo = S_VFOB ; break ;
case RIG_VFO_MAIN : icvfo = S_MAIN ; break ;
case RIG_VFO_SUB : icvfo = S_SUB ; break ;
case RIG_VFO_VFO :
retval = icom_transaction ( rig , C_SET_VFO , - 1 , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_vfo: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
2000-10-08 21:38:45 +00:00
}
2005-04-16 11:55:49 +00:00
return RIG_OK ;
case RIG_VFO_MEM :
retval = icom_transaction ( rig , C_SET_MEM , - 1 , NULL , 0 ,
2001-06-10 22:29:00 +00:00
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return retval ;
2000-10-08 21:38:45 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_ERR , " icom_set_vfo: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
2000-10-08 21:38:45 +00:00
}
return RIG_OK ;
2005-04-16 11:55:49 +00:00
default :
rig_debug ( RIG_DEBUG_ERR , " icom: Unsupported VFO %d \n " , vfo ) ;
return - RIG_EINVAL ;
}
retval = icom_transaction ( rig , C_SET_VFO , icvfo , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_vfo: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
return RIG_OK ;
2000-10-08 21:38:45 +00:00
}
/*
2001-02-26 23:16:11 +00:00
* icom_set_level
2000-10-16 22:34:22 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_level ( RIG * rig , vfo_t vfo , setting_t level , value_t val )
2000-10-16 22:34:22 +00:00
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char lvlbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , lvl_len ;
2005-04-16 11:55:49 +00:00
int lvl_cn , lvl_sc ; /* Command Number, Subcommand */
int icom_val ;
int i , retval ;
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
/*
* So far , levels of float type are in [ 0.0 . .1 .0 ] range
*/
if ( RIG_LEVEL_IS_FLOAT ( level ) )
icom_val = val . f * 255 ;
else
icom_val = val . i ;
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
/* convert values to 0 .. 255 range */
if ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) {
switch ( level ) {
case RIG_LEVEL_NR :
icom_val = val . f * 240 ;
break ;
case RIG_LEVEL_PBT_IN :
case RIG_LEVEL_PBT_OUT :
icom_val = ( val . f / 10.0 ) + 128 ;
if ( icom_val > 255 )
icom_val = 255 ;
break ;
default :
break ;
2004-08-21 23:53:39 +00:00
}
2005-04-16 11:55:49 +00:00
}
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
/*
* Most of the time , the data field is a 3 digit BCD ,
* but in * big endian * order : 0000. .0255
* ( from_bcd is little endian )
*/
lvl_len = 2 ;
to_bcd_be ( lvlbuf , ( long long ) icom_val , lvl_len * 2 ) ;
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
/* Optimize:
* sort the switch cases with the most frequent first
*/
switch ( level ) {
case RIG_LEVEL_PREAMP :
lvl_cn = C_CTL_FUNC ;
lvl_sc = S_FUNC_PAMP ;
lvl_len = 1 ;
if ( val . i = = 0 ) {
lvlbuf [ 0 ] = 0 ; /* 0=OFF */
2001-02-26 23:16:11 +00:00
break ;
2005-04-16 11:55:49 +00:00
}
for ( i = 0 ; i < MAXDBLSTSIZ ; i + + ) {
if ( rs - > preamp [ i ] = = val . i )
break ;
}
if ( i = = MAXDBLSTSIZ | | rs - > preamp [ i ] = = 0 ) {
rig_debug ( RIG_DEBUG_ERR , " Unsupported preamp set_level %ddB " ,
val . i ) ;
return - RIG_EINVAL ;
}
lvlbuf [ 0 ] = i + 1 ; /* 1=P.AMP1, 2=P.AMP2 */
break ;
case RIG_LEVEL_ATT :
lvl_cn = C_CTL_ATT ;
/* attenuator level is dB, in BCD mode */
lvl_sc = ( val . i / 10 ) < < 4 | ( val . i % 10 ) ;
lvl_len = 0 ;
break ;
case RIG_LEVEL_AF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_AF ;
break ;
case RIG_LEVEL_RF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_RF ;
break ;
case RIG_LEVEL_SQL :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_SQL ;
break ;
case RIG_LEVEL_IF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_IF ;
break ;
case RIG_LEVEL_APF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_APF ;
break ;
case RIG_LEVEL_NR :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_NR ;
break ;
case RIG_LEVEL_PBT_IN :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_PBTIN ;
break ;
case RIG_LEVEL_PBT_OUT :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_PBTOUT ;
break ;
case RIG_LEVEL_CWPITCH :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_CWPITCH ;
/* use 'set mode' call for CWPITCH on IC-R75*/
if ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) {
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_MODE_SLCT ;
lvl_len = 3 ;
lvlbuf [ 0 ] = S_PRM_CWPITCH ;
to_bcd_be ( lvlbuf + 1 , ( long long ) icom_val , 4 ) ;
}
break ;
case RIG_LEVEL_RFPOWER :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_RFPOWER ;
break ;
case RIG_LEVEL_MICGAIN :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_MICGAIN ;
break ;
case RIG_LEVEL_KEYSPD :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_KEYSPD ;
break ;
case RIG_LEVEL_NOTCHF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_NOTCHF ;
break ;
case RIG_LEVEL_COMP :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_COMP ;
break ;
case RIG_LEVEL_AGC :
lvl_cn = C_CTL_FUNC ;
lvl_sc = S_FUNC_AGC ;
if ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) {
lvl_len = 1 ;
lvlbuf [ 0 ] = val . i ;
}
break ;
case RIG_LEVEL_BKINDL :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_BKINDL ;
break ;
case RIG_LEVEL_BALANCE :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_BALANCE ;
break ;
2002-02-28 10:59:46 +00:00
case RIG_LEVEL_VOXGAIN : /* IC-910H */
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_VOXGAIN ;
break ;
case RIG_LEVEL_VOXDELAY : /* IC-910H */
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_VOXDELAY ;
break ;
case RIG_LEVEL_ANTIVOX : /* IC-910H */
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_ANTIVOX ;
break ;
2005-04-16 11:55:49 +00:00
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported set_level %d " , level ) ;
return - RIG_EINVAL ;
}
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , lvl_cn , lvl_sc , lvlbuf , lvl_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_level: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2001-02-26 23:16:11 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-16 22:34:22 +00:00
}
2001-01-28 22:08:41 +00:00
/*
* icom_get_level
2000-10-16 22:34:22 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , val ! = NULL
2000-10-08 21:38:45 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_get_level ( RIG * rig , vfo_t vfo , setting_t level , value_t * val )
2000-10-08 21:38:45 +00:00
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char lvlbuf [ MAXFRAMELEN ] , lvl2buf [ MAXFRAMELEN ] ;
int lvl_len , lvl2_len ;
int lvl_cn , lvl_sc ; /* Command Number, Subcommand */
int icom_val ;
int cmdhead ;
int retval ;
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
lvl2_len = 0 ;
/* Optimize:
* sort the switch cases with the most frequent first
*/
switch ( level ) {
case RIG_LEVEL_STRENGTH :
case RIG_LEVEL_RAWSTR :
lvl_cn = C_RD_SQSM ;
lvl_sc = S_SML ;
break ;
case RIG_LEVEL_PREAMP :
lvl_cn = C_CTL_FUNC ;
lvl_sc = S_FUNC_PAMP ;
break ;
case RIG_LEVEL_ATT :
lvl_cn = C_CTL_ATT ;
lvl_sc = - 1 ;
break ;
case RIG_LEVEL_AF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_AF ;
break ;
case RIG_LEVEL_RF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_RF ;
break ;
case RIG_LEVEL_SQL :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_SQL ;
break ;
case RIG_LEVEL_IF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_IF ;
break ;
case RIG_LEVEL_APF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_APF ;
break ;
case RIG_LEVEL_NR :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_NR ;
break ;
case RIG_LEVEL_PBT_IN :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_PBTIN ;
break ;
case RIG_LEVEL_PBT_OUT :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_PBTOUT ;
break ;
case RIG_LEVEL_CWPITCH :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_CWPITCH ;
/* use 'set mode' call for CWPITCH on IC-R75*/
if ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) {
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_MODE_SLCT ;
lvl2_len = 1 ;
lvl2buf [ 0 ] = S_PRM_CWPITCH ;
}
break ;
case RIG_LEVEL_RFPOWER :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_RFPOWER ;
break ;
case RIG_LEVEL_MICGAIN :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_MICGAIN ;
break ;
case RIG_LEVEL_KEYSPD :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_KEYSPD ;
break ;
case RIG_LEVEL_NOTCHF :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_NOTCHF ;
break ;
case RIG_LEVEL_COMP :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_COMP ;
break ;
case RIG_LEVEL_AGC :
lvl_cn = C_CTL_FUNC ;
lvl_sc = S_FUNC_AGC ;
break ;
case RIG_LEVEL_BKINDL :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_BKINDL ;
break ;
case RIG_LEVEL_BALANCE :
lvl_cn = C_CTL_LVL ;
lvl_sc = S_LVL_BALANCE ;
break ;
2002-02-28 10:59:46 +00:00
case RIG_LEVEL_VOXGAIN : /* IC-910H */
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_VOXGAIN ;
break ;
case RIG_LEVEL_VOXDELAY : /* IC-910H */
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_VOXDELAY ;
break ;
case RIG_LEVEL_ANTIVOX : /* IC-910H */
lvl_cn = C_CTL_MEM ;
lvl_sc = S_MEM_ANTIVOX ;
break ;
2005-04-16 11:55:49 +00:00
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported get_level %d " , level ) ;
return - RIG_EINVAL ;
}
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
/* use lvl2buf and lvl2_len for 'set mode' subcommand */
retval = icom_transaction ( rig , lvl_cn , lvl_sc , lvl2buf , lvl2_len ,
lvlbuf , & lvl_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-03-01 21:21:23 +00:00
2005-04-16 11:55:49 +00:00
/*
* strbuf should contain Cn , Sc , Data area
*/
cmdhead = ( lvl_sc = = - 1 ) ? 1 : 2 ;
lvl_len - = cmdhead ;
/* back off one char since first char in buffer is now 'set mode' subcommand */
if ( ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) & & ( level = = RIG_LEVEL_CWPITCH ) ) {
cmdhead = 3 ;
lvl_len - - ;
}
2001-03-01 21:21:23 +00:00
2005-04-16 11:55:49 +00:00
if ( lvlbuf [ 0 ] ! = ACK & & lvlbuf [ 0 ] ! = lvl_cn ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_level: ack NG (%#.2x), "
" len=%d \n " , lvlbuf [ 0 ] , lvl_len ) ;
return - RIG_ERJCTED ;
}
2000-10-16 22:34:22 +00:00
2005-04-16 11:55:49 +00:00
/*
* The result is a 3 digit BCD , but in * big endian * order : 0000. .0255
* ( from_bcd is little endian )
*/
icom_val = from_bcd_be ( lvlbuf + cmdhead , lvl_len * 2 ) ;
switch ( level ) {
case RIG_LEVEL_RAWSTR :
val - > i = icom_val ;
break ;
case RIG_LEVEL_STRENGTH :
val - > i = ( int ) rig_raw2val ( icom_val , & rig - > caps - > str_cal ) ;
break ;
case RIG_LEVEL_PREAMP :
if ( icom_val = = 0 ) {
val - > i = 0 ;
break ;
}
if ( icom_val > MAXDBLSTSIZ | | rs - > preamp [ icom_val - 1 ] = = 0 ) {
rig_debug ( RIG_DEBUG_ERR , " Unsupported preamp get_level %ddB " ,
icom_val ) ;
return - RIG_EPROTO ;
2001-01-28 22:08:41 +00:00
}
2005-04-16 11:55:49 +00:00
val - > i = rs - > preamp [ icom_val - 1 ] ;
break ;
/* RIG_LEVEL_ATT: returned value is already an integer in dB (coded in BCD) */
default :
if ( RIG_LEVEL_IS_FLOAT ( level ) )
val - > f = ( float ) icom_val / 255 ;
else
val - > i = icom_val ;
}
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
/* convert values from 0 .. 255 range */
if ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) {
switch ( level ) {
case RIG_LEVEL_NR :
val - > f = ( float ) icom_val / 240 ;
break ;
case RIG_LEVEL_PBT_IN :
case RIG_LEVEL_PBT_OUT :
if ( icom_val = = 255 )
val - > f = 1280.0 ;
else
val - > f = ( float ) ( icom_val - 128 ) * 10.0 ;
break ;
default :
break ;
2004-08-27 01:49:38 +00:00
}
2005-04-16 11:55:49 +00:00
}
2004-08-27 01:49:38 +00:00
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_TRACE , " icom_get_level: %d %d %d %f \n " , lvl_len ,
icom_val , val - > i , val - > f ) ;
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-08 21:38:45 +00:00
}
2001-07-21 13:00:03 +00:00
/*
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
int icom_set_conf ( RIG * rig , token_t token , const char * val )
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
switch ( token ) {
case TOK_CIVADDR :
if ( val [ 0 ] = = ' 0 ' & & val [ 1 ] = = ' x ' )
priv - > re_civ_addr = strtol ( val , ( char * * ) NULL , 16 ) ;
else
priv - > re_civ_addr = atoi ( val ) ;
break ;
case TOK_MODE731 :
priv - > civ_731_mode = atoi ( val ) ? 1 : 0 ;
break ;
default :
return - RIG_EINVAL ;
}
return RIG_OK ;
2001-07-21 13:00:03 +00:00
}
/*
* assumes rig ! = NULL ,
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
* and val points to a buffer big enough to hold the conf value .
*/
int icom_get_conf ( RIG * rig , token_t token , char * val )
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
switch ( token ) {
case TOK_CIVADDR :
sprintf ( val , " %d " , priv - > re_civ_addr ) ;
break ;
case TOK_MODE731 :
sprintf ( val , " %d " , priv - > civ_731_mode ) ;
break ;
default :
return - RIG_EINVAL ;
}
return RIG_OK ;
2001-07-21 13:00:03 +00:00
}
2000-10-10 21:58:31 +00:00
/*
* icom_set_ptt
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_ptt ( RIG * rig , vfo_t vfo , ptt_t ptt )
2000-10-10 21:58:31 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] , pttbuf [ 1 ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
pttbuf [ 0 ] = ptt = = RIG_PTT_ON ? 1 : 0 ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_PTT , S_PTT , pttbuf , 1 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_ptt: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-10 21:58:31 +00:00
}
/*
* icom_get_ptt
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , ptt ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_get_ptt ( RIG * rig , vfo_t vfo , ptt_t * ptt )
2000-10-10 21:58:31 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char pttbuf [ MAXFRAMELEN ] ;
int ptt_len , retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_PTT , S_PTT , NULL , 0 ,
pttbuf , & ptt_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
/*
2006-07-18 22:51:43 +00:00
* freqbuf should contain Cn , Sc , Data area
2005-04-16 11:55:49 +00:00
*/
2006-07-18 22:51:43 +00:00
ptt_len - = 2 ;
2005-04-16 11:55:49 +00:00
if ( ptt_len ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_ptt: wrong frame len=%d \n " ,
ptt_len ) ;
return - RIG_ERJCTED ;
}
2000-10-10 21:58:31 +00:00
2006-07-18 22:51:43 +00:00
* ptt = pttbuf [ 2 ] = = 1 ? RIG_PTT_ON : RIG_PTT_OFF ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-10 21:58:31 +00:00
}
2001-02-14 23:55:54 +00:00
/*
* icom_get_dcd
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , ptt ! = NULL
*/
int icom_get_dcd ( RIG * rig , vfo_t vfo , dcd_t * dcd )
{
2005-04-16 11:55:49 +00:00
unsigned char dcdbuf [ MAXFRAMELEN ] ;
int dcd_len , retval ;
int icom_val ;
2001-02-14 23:55:54 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_RD_SQSM , S_SQL , NULL , 0 ,
dcdbuf , & dcd_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-02-14 23:55:54 +00:00
2005-04-16 11:55:49 +00:00
/*
* freqbuf should contain Cn , Data area
*/
dcd_len - = 2 ;
if ( dcd_len ! = 2 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_dcd: wrong frame len=%d \n " ,
dcd_len ) ;
return - RIG_ERJCTED ;
}
/*
* The result is a 3 digit BCD , but in * big endian * order : 0000. .0255
* ( from_bcd is little endian )
*/
icom_val = from_bcd_be ( dcdbuf + 2 , dcd_len * 2 ) ;
2002-02-28 10:59:46 +00:00
/*
2005-04-16 11:55:49 +00:00
* 0x00 = sql closed , 0x01 = sql open
*
* TODO : replace icom_val by dcdbuf [ 2 ] ?
2001-02-14 23:55:54 +00:00
*/
2005-04-16 11:55:49 +00:00
* dcd = ( icom_val = = 0x01 ) ? RIG_DCD_ON : RIG_DCD_OFF ;
2001-02-14 23:55:54 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2001-02-14 23:55:54 +00:00
}
2000-10-23 19:48:12 +00:00
/*
* icom_set_rptr_shift
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_rptr_shift ( RIG * rig , vfo_t vfo , rptr_shift_t rptr_shift )
2000-10-23 19:48:12 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int rptr_sc ;
switch ( rptr_shift ) {
case RIG_RPT_SHIFT_NONE :
rptr_sc = S_DUP_OFF ; /* Simplex mode */
break ;
case RIG_RPT_SHIFT_MINUS :
rptr_sc = S_DUP_M ; /* Duplex - mode */
break ;
case RIG_RPT_SHIFT_PLUS :
rptr_sc = S_DUP_P ; /* Duplex + mode */
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported shift %d " , rptr_shift ) ;
return - RIG_EINVAL ;
}
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_SPLT , rptr_sc , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_rptr_shift: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-23 19:48:12 +00:00
}
2000-10-10 21:58:31 +00:00
/*
2000-10-23 19:48:12 +00:00
* icom_get_rptr_shift
2000-10-10 21:58:31 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , rptr_shift ! = NULL
2006-07-18 22:51:43 +00:00
* will not work for IC - 746 Pro
* NOTE : seems not to work ( tested on IC - 706 MkIIG ) , please report - - SF
2000-10-10 21:58:31 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_get_rptr_shift ( RIG * rig , vfo_t vfo , rptr_shift_t * rptr_shift )
2000-10-10 21:58:31 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char rptrbuf [ MAXFRAMELEN ] ;
int rptr_len , retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_SPLT , - 1 , NULL , 0 ,
rptrbuf , & rptr_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
/*
* rptrbuf should contain Cn , Sc
*/
rptr_len - - ;
if ( rptr_len ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_rptr_shift: wrong frame len=%d \n " ,
rptr_len ) ;
return - RIG_ERJCTED ;
}
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
switch ( rptrbuf [ 1 ] ) {
case S_DUP_OFF :
* rptr_shift = RIG_RPT_SHIFT_NONE ; /* Simplex mode */
break ;
case S_DUP_M :
* rptr_shift = RIG_RPT_SHIFT_MINUS ; /* Duples - mode */
break ;
case S_DUP_P :
* rptr_shift = RIG_RPT_SHIFT_PLUS ; /* Duplex + mode */
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported shift %d " , rptrbuf [ 1 ] ) ;
return - RIG_EPROTO ;
}
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-10 21:58:31 +00:00
}
2000-10-29 16:25:56 +00:00
/*
* icom_set_rptr_offs
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_rptr_offs ( RIG * rig , vfo_t vfo , shortfreq_t rptr_offs )
2000-10-29 16:25:56 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char offsbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
/*
* Icoms are using a 100 Hz unit ( at least on 706 MKIIg ) - - SF
*/
to_bcd ( offsbuf , rptr_offs / 100 , OFFS_LEN * 2 ) ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_OFFS , - 1 , offsbuf , OFFS_LEN ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_rptr_offs: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-29 16:25:56 +00:00
}
/*
* icom_get_rptr_offs
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , rptr_offs ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_get_rptr_offs ( RIG * rig , vfo_t vfo , shortfreq_t * rptr_offs )
2000-10-29 16:25:56 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char offsbuf [ MAXFRAMELEN ] ;
int offs_len , retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_RD_OFFS , - 1 , NULL , 0 ,
offsbuf , & offs_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
/*
* offsbuf should contain Cn
*/
offs_len - - ;
if ( offs_len ! = OFFS_LEN ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_rptr_offs: "
" wrong frame len=%d \n " , offs_len ) ;
return - RIG_ERJCTED ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
/*
* Icoms are using a 100 Hz unit ( at least on 706 MKIIg ) - - SF
*/
* rptr_offs = from_bcd ( offsbuf + 1 , offs_len * 2 ) * 100 ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-29 16:25:56 +00:00
}
/*
* icom_set_split_freq
2002-02-28 10:59:46 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL ,
2000-10-29 16:25:56 +00:00
* icom_set_vfo , icom_set_freq works for this rig
* FIXME : status
2003-12-04 23:27:28 +00:00
*
* Assumes also that the current VFO is the rx VFO .
2000-10-29 16:25:56 +00:00
*/
2001-06-27 17:32:47 +00:00
int icom_set_split_freq ( RIG * rig , vfo_t vfo , freq_t tx_freq )
2000-10-29 16:25:56 +00:00
{
2005-04-16 11:55:49 +00:00
int status ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
/* This method works also in memory mode(RIG_VFO_MEM) */
if ( rig_has_vfo_op ( rig , RIG_OP_XCHG ) ) {
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
status = icom_set_freq ( rig , RIG_VFO_CURR , tx_freq ) ;
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
2005-04-16 11:55:49 +00:00
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
return 0 ;
}
status = icom_set_vfo ( rig , RIG_VFO_B ) ;
if ( status ! = RIG_OK )
return status ;
status = icom_set_freq ( rig , RIG_VFO_CURR , tx_freq ) ;
if ( status ! = RIG_OK )
return status ;
2001-06-27 17:32:47 +00:00
2005-04-16 11:55:49 +00:00
status = icom_set_vfo ( rig , RIG_VFO_A ) ;
if ( status ! = RIG_OK )
2000-10-29 16:25:56 +00:00
return status ;
2005-04-16 11:55:49 +00:00
return status ;
2000-10-29 16:25:56 +00:00
}
/*
* icom_get_split_freq
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , rx_freq ! = NULL , tx_freq ! = NULL
* icom_set_vfo , icom_get_freq works for this rig
* FIXME : status
*/
2001-06-27 17:32:47 +00:00
int icom_get_split_freq ( RIG * rig , vfo_t vfo , freq_t * tx_freq )
2000-10-29 16:25:56 +00:00
{
2005-04-16 11:55:49 +00:00
int status ;
2003-12-04 23:27:28 +00:00
2005-04-16 11:55:49 +00:00
/* This method works also in memory mode(RIG_VFO_MEM) */
if ( rig_has_vfo_op ( rig , RIG_OP_XCHG ) ) {
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
status = icom_get_freq ( rig , RIG_VFO_CURR , tx_freq ) ;
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
2005-04-16 11:55:49 +00:00
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
return 0 ;
}
status = icom_set_vfo ( rig , RIG_VFO_B ) ;
if ( status ! = RIG_OK )
return status ;
status = icom_get_freq ( rig , RIG_VFO_CURR , tx_freq ) ;
if ( status ! = RIG_OK )
return status ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
status = icom_set_vfo ( rig , RIG_VFO_A ) ;
if ( status ! = RIG_OK )
2000-10-29 16:25:56 +00:00
return status ;
2005-04-16 11:55:49 +00:00
return status ;
2000-10-29 16:25:56 +00:00
}
2001-04-28 12:38:02 +00:00
/*
* icom_set_split_mode
2002-02-28 10:59:46 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL ,
2001-04-28 12:38:02 +00:00
* icom_set_vfo , icom_set_mode works for this rig
* FIXME : status
*/
2001-06-27 17:32:47 +00:00
int icom_set_split_mode ( RIG * rig , vfo_t vfo , rmode_t tx_mode , pbwidth_t tx_width )
2001-04-28 12:38:02 +00:00
{
2005-04-16 11:55:49 +00:00
int status ;
2001-04-28 12:38:02 +00:00
2005-04-16 11:55:49 +00:00
/* This method works also in memory mode(RIG_VFO_MEM) */
if ( rig_has_vfo_op ( rig , RIG_OP_XCHG ) ) {
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
status = icom_set_mode ( rig , RIG_VFO_CURR , tx_mode , tx_width ) ;
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
2005-04-16 11:55:49 +00:00
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
return 0 ;
}
status = icom_set_vfo ( rig , RIG_VFO_B ) ;
if ( status ! = RIG_OK )
return status ;
status = icom_set_mode ( rig , RIG_VFO_CURR , tx_mode , tx_width ) ;
if ( status ! = RIG_OK )
return status ;
2001-04-28 12:38:02 +00:00
2005-04-16 11:55:49 +00:00
status = icom_set_vfo ( rig , RIG_VFO_A ) ;
if ( status ! = RIG_OK )
2001-04-28 12:38:02 +00:00
return status ;
2005-04-16 11:55:49 +00:00
return status ;
2001-04-28 12:38:02 +00:00
}
/*
* icom_get_split_mode
2002-02-28 10:59:46 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL ,
2001-04-28 12:38:02 +00:00
* rx_mode ! = NULL , rx_width ! = NULL , tx_mode ! = NULL , tx_width ! = NULL
* icom_set_vfo , icom_get_mode works for this rig
* FIXME : status
*/
2001-06-27 17:32:47 +00:00
int icom_get_split_mode ( RIG * rig , vfo_t vfo , rmode_t * tx_mode , pbwidth_t * tx_width )
2001-04-28 12:38:02 +00:00
{
2005-04-16 11:55:49 +00:00
int status ;
2003-12-04 23:27:28 +00:00
2005-04-16 11:55:49 +00:00
/* This method works also in memory mode(RIG_VFO_MEM) */
if ( rig_has_vfo_op ( rig , RIG_OP_XCHG ) ) {
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
2003-12-04 23:27:28 +00:00
status = icom_get_mode ( rig , RIG_VFO_CURR , tx_mode , tx_width ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
2001-06-27 17:32:47 +00:00
2005-04-16 11:55:49 +00:00
status = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2001-06-27 17:32:47 +00:00
if ( status ! = RIG_OK )
2005-04-16 11:55:49 +00:00
return status ;
return 0 ;
}
status = icom_set_vfo ( rig , RIG_VFO_B ) ;
if ( status ! = RIG_OK )
return status ;
status = icom_get_mode ( rig , RIG_VFO_CURR , tx_mode , tx_width ) ;
if ( status ! = RIG_OK )
return status ;
2001-04-28 12:38:02 +00:00
2005-04-16 11:55:49 +00:00
status = icom_set_vfo ( rig , RIG_VFO_A ) ;
if ( status ! = RIG_OK )
2001-04-28 12:38:02 +00:00
return status ;
2005-04-16 11:55:49 +00:00
return status ;
2001-04-28 12:38:02 +00:00
}
2000-10-29 16:25:56 +00:00
/*
* icom_set_split
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2003-04-06 18:40:36 +00:00
int icom_set_split_vfo ( RIG * rig , vfo_t vfo , split_t split , vfo_t tx_vfo )
2000-10-29 16:25:56 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int split_sc ;
switch ( split ) {
case RIG_SPLIT_OFF :
split_sc = S_SPLT_OFF ;
break ;
case RIG_SPLIT_ON :
split_sc = S_SPLT_ON ;
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " %s: Unsupported split %d " , __FUNCTION__ , split ) ;
return - RIG_EINVAL ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_SPLT , split_sc , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_split: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-29 16:25:56 +00:00
}
/*
2003-12-04 23:27:28 +00:00
* icom_get_split_vfo
2000-10-29 16:25:56 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , split ! = NULL
*/
2003-04-06 18:40:36 +00:00
int icom_get_split_vfo ( RIG * rig , vfo_t vfo , split_t * split , vfo_t * tx_vfo )
2000-10-29 16:25:56 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char splitbuf [ MAXFRAMELEN ] ;
int split_len , retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_SPLT , - 1 , NULL , 0 ,
splitbuf , & split_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
/*
* splitbuf should contain Cn , Sc
*/
split_len - - ;
if ( split_len ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " %s: wrong frame len=%d \n " ,
__FUNCTION__ , split_len ) ;
return - RIG_ERJCTED ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
switch ( splitbuf [ 1 ] ) {
case S_SPLT_OFF :
* split = RIG_SPLIT_OFF ;
break ;
case S_SPLT_ON :
* split = RIG_SPLIT_ON ;
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported split %d " , splitbuf [ 1 ] ) ;
return - RIG_EPROTO ;
}
2000-10-29 16:25:56 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-29 16:25:56 +00:00
}
2003-12-04 23:27:28 +00:00
/*
* icom_mem_get_split_vfo
* Assumes rig ! = NULL , rig - > state . priv ! = NULL , split ! = NULL
*/
int icom_mem_get_split_vfo ( RIG * rig , vfo_t vfo , split_t * split , vfo_t * tx_vfo )
{
2005-04-16 11:55:49 +00:00
int retval ;
2003-12-04 23:27:28 +00:00
2005-04-16 11:55:49 +00:00
/* this hacks works only when in memory mode
* I have no clue how to detect split in regular VFO mode
*/
if ( rig - > state . current_vfo ! = RIG_VFO_MEM )
return - RIG_ENAVAIL ;
2003-12-04 23:27:28 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
if ( retval = = RIG_OK ) {
* split = RIG_SPLIT_ON ;
/* get it back to normal */
2003-12-04 23:27:28 +00:00
retval = icom_vfo_op ( rig , vfo , RIG_OP_XCHG ) ;
2005-04-16 11:55:49 +00:00
} else if ( retval = = - RIG_ERJCTED ) {
* split = RIG_SPLIT_OFF ;
} else {
/* this is really an error! */
return retval ;
}
2003-12-04 23:27:28 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2003-12-04 23:27:28 +00:00
}
2000-10-10 21:58:31 +00:00
/*
* icom_set_ts
2001-03-04 13:03:41 +00:00
* Assumes rig ! = NULL , rig - > caps - > priv ! = NULL
2000-10-10 21:58:31 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_set_ts ( RIG * rig , vfo_t vfo , shortfreq_t ts )
2000-10-10 21:58:31 +00:00
{
2005-04-16 11:55:49 +00:00
const struct icom_priv_caps * priv_caps ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int i , ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int ts_sc = 0 ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
priv_caps = ( const struct icom_priv_caps * ) rig - > caps - > priv ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
for ( i = 0 ; i < TSLSTSIZ ; i + + ) {
if ( priv_caps - > ts_sc_list [ i ] . ts = = ts ) {
ts_sc = priv_caps - > ts_sc_list [ i ] . sc ;
break ;
2000-10-10 21:58:31 +00:00
}
2005-04-16 11:55:49 +00:00
}
if ( i > = TSLSTSIZ )
return - RIG_EINVAL ; /* not found, unsupported */
retval = icom_transaction ( rig , C_SET_TS , ts_sc , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_ts: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-10 21:58:31 +00:00
}
/*
* icom_get_ts
2001-03-04 13:03:41 +00:00
* Assumes rig ! = NULL , rig - > caps - > priv ! = NULL , ts ! = NULL
2006-07-18 22:51:43 +00:00
* NOTE : seems not to work ( tested on IC - 706 MkIIG ) , please report - - SF Not available on 746 pro
2000-10-10 21:58:31 +00:00
*/
2000-12-05 22:01:03 +00:00
int icom_get_ts ( RIG * rig , vfo_t vfo , shortfreq_t * ts )
2000-10-10 21:58:31 +00:00
{
2005-04-16 11:55:49 +00:00
const struct icom_priv_caps * priv_caps ;
unsigned char tsbuf [ MAXFRAMELEN ] ;
int ts_len , i , retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
priv_caps = ( const struct icom_priv_caps * ) rig - > caps - > priv ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_TS , - 1 , NULL , 0 , tsbuf , & ts_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
/*
* tsbuf should contain Cn , Sc
*/
ts_len - - ;
if ( ts_len ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_ts: wrong frame len=%d \n " ,
ts_len ) ;
return - RIG_ERJCTED ;
}
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
for ( i = 0 ; i < TSLSTSIZ ; i + + ) {
if ( priv_caps - > ts_sc_list [ i ] . sc = = tsbuf [ 1 ] ) {
* ts = priv_caps - > ts_sc_list [ i ] . ts ;
break ;
2000-10-10 21:58:31 +00:00
}
2005-04-16 11:55:49 +00:00
}
if ( i > = TSLSTSIZ )
return - RIG_EPROTO ; /* not found, unsupported */
2000-10-10 21:58:31 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-10 21:58:31 +00:00
}
2001-01-28 22:08:41 +00:00
/*
* icom_set_func
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
int icom_set_func ( RIG * rig , vfo_t vfo , setting_t func , int status )
{
2005-04-16 11:55:49 +00:00
unsigned char fctbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
int fct_len , acklen , retval ;
int fct_cn , fct_sc ; /* Command Number, Subcommand */
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
/*
* except for IC - R8500
*/
fctbuf [ 0 ] = status ? 0x01 : 0x00 ;
fct_len = rig - > caps - > rig_model = = RIG_MODEL_ICR8500 ? 0 : 1 ;
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
/* Optimize:
* sort the switch cases with the most frequent first
*/
switch ( func ) {
case RIG_FUNC_FAGC :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_AGC ;
/* note: should it be a LEVEL only, and no func? --SF */
if ( status ! = 0 )
2006-07-18 22:51:43 +00:00
fctbuf [ 0 ] = 0x03 ; /* default to 0x03 in IC746 pro super-fast */
2005-04-16 11:55:49 +00:00
else
fctbuf [ 0 ] = 0x02 ;
break ;
case RIG_FUNC_NB :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_NB ;
break ;
case RIG_FUNC_COMP :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_COMP ;
break ;
case RIG_FUNC_VOX :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_VOX ;
break ;
case RIG_FUNC_TONE : /* repeater tone */
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_TONE ;
break ;
case RIG_FUNC_TSQL :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_TSQL ;
break ;
2006-07-18 22:51:43 +00:00
case RIG_FUNC_SBKIN :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_BKIN ;
if ( status ! = 0 )
fctbuf [ 0 ] = 0x01 ;
else
fctbuf [ 0 ] = 0x00 ;
break ;
2005-04-16 11:55:49 +00:00
case RIG_FUNC_FBKIN :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_BKIN ;
2006-07-18 22:51:43 +00:00
if ( status ! = 0 )
fctbuf [ 0 ] = 0x02 ;
else
fctbuf [ 0 ] = 0x00 ;
2005-04-16 11:55:49 +00:00
break ;
case RIG_FUNC_ANF :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_ANF ;
break ;
case RIG_FUNC_NR :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_NR ;
break ;
case RIG_FUNC_APF :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_APF ;
break ;
case RIG_FUNC_MON :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_MON ;
break ;
case RIG_FUNC_MN :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_MN ;
break ;
2006-07-18 22:51:43 +00:00
case RIG_FUNC_RF :
2005-04-16 11:55:49 +00:00
fct_cn = C_CTL_FUNC ;
2006-07-18 22:51:43 +00:00
fct_sc = S_FUNC_RF ;
break ;
case RIG_FUNC_VSC :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_VSC ;
2005-04-16 11:55:49 +00:00
break ;
2002-02-28 10:59:46 +00:00
case RIG_FUNC_AFC : /* IC-910H */
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_AFC ;
break ;
case RIG_FUNC_SATMODE : /* IC-910H */
fct_cn = C_CTL_MEM ;
fct_sc = S_MEM_SATMODE ;
break ;
case RIG_FUNC_SCOPE : /* IC-910H */
fct_cn = C_CTL_MEM ;
fct_sc = S_MEM_BANDSCOPE ;
break ;
2006-07-18 22:51:43 +00:00
case RIG_FUNC_RESUME : /* IC-910H & IC-746-Pro*/
2005-04-16 11:55:49 +00:00
fct_cn = C_CTL_SCAN ;
fct_sc = status ? S_SCAN_RSMON : S_SCAN_RSMOFF ;
fct_len = 0 ;
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported set_func %d " , func ) ;
return - RIG_EINVAL ;
}
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , fct_cn , fct_sc , fctbuf , fct_len ,
ackbuf , & acklen ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
if ( acklen ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_func: wrong frame len=%d \n " ,
acklen ) ;
return - RIG_EPROTO ;
}
2001-01-28 22:08:41 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2001-01-28 22:08:41 +00:00
}
2001-03-01 21:21:23 +00:00
/*
* icom_get_func
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
* FIXME : IC8500 and no - sc , any support ?
*/
int icom_get_func ( RIG * rig , vfo_t vfo , setting_t func , int * status )
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int fct_cn , fct_sc ; /* Command Number, Subcommand */
2001-03-01 21:21:23 +00:00
2005-04-16 11:55:49 +00:00
/* Optimize:
* sort the switch cases with the most frequent first
*/
switch ( func ) {
case RIG_FUNC_FAGC :
fct_cn = C_CTL_FUNC ;
2006-07-18 22:51:43 +00:00
fct_sc = S_FUNC_AGC ; /* default to 0x01=slow 0x03=super-fast */
2005-04-16 11:55:49 +00:00
break ;
case RIG_FUNC_NB :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_NB ;
break ;
case RIG_FUNC_COMP :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_COMP ;
break ;
case RIG_FUNC_VOX :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_VOX ;
break ;
case RIG_FUNC_TONE : /* repeater tone */
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_TONE ;
break ;
case RIG_FUNC_TSQL :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_TSQL ;
break ;
2006-07-18 22:51:43 +00:00
case RIG_FUNC_SBKIN : /* returns 1 for semi and 2 for full adjusted below */
2005-04-16 11:55:49 +00:00
case RIG_FUNC_FBKIN :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_BKIN ;
break ;
case RIG_FUNC_ANF :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_ANF ;
break ;
case RIG_FUNC_NR :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_NR ;
break ;
case RIG_FUNC_APF :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_APF ;
break ;
case RIG_FUNC_MON :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_MON ;
break ;
case RIG_FUNC_MN :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_MN ;
break ;
2006-07-18 22:51:43 +00:00
case RIG_FUNC_RF :
2002-02-28 10:59:46 +00:00
fct_cn = C_CTL_FUNC ;
2006-07-18 22:51:43 +00:00
fct_sc = S_FUNC_RF ;
2002-02-28 10:59:46 +00:00
break ;
2006-07-18 22:51:43 +00:00
case RIG_FUNC_VSC :
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_VSC ;
break ;
case RIG_FUNC_AFC : /* IC-910H */
2002-02-28 10:59:46 +00:00
fct_cn = C_CTL_FUNC ;
fct_sc = S_FUNC_AFC ;
break ;
case RIG_FUNC_SATMODE : /* IC-910H */
fct_cn = C_CTL_MEM ;
fct_sc = S_MEM_SATMODE ;
break ;
case RIG_FUNC_SCOPE : /* IC-910H */
fct_cn = C_CTL_MEM ;
fct_sc = S_MEM_BANDSCOPE ;
break ;
2005-04-16 11:55:49 +00:00
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported get_func %d " , func ) ;
return - RIG_EINVAL ;
}
2001-03-01 21:21:23 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , fct_cn , fct_sc , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-03-01 21:21:23 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 3 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_func: wrong frame len=%d \n " ,
ack_len ) ;
return - RIG_EPROTO ;
2006-07-18 22:51:43 +00:00
}
if ( func ! = RIG_FUNC_FBKIN )
* status = ackbuf [ 2 ] ;
else
* status = ackbuf [ 2 ] = = 2 ? 1 : 0 ;
2001-03-01 21:21:23 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2001-03-01 21:21:23 +00:00
}
2004-08-21 23:53:39 +00:00
/*
* icom_set_parm
* Assumes rig ! = NULL
2006-07-18 22:51:43 +00:00
These are very much rig specific and should probably be in rig files . These are for ICR75C only .
2004-08-21 23:53:39 +00:00
*/
int icom_set_parm ( RIG * rig , setting_t parm , value_t val )
{
2005-04-16 11:55:49 +00:00
unsigned char prmbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , prm_len ;
2005-04-16 11:55:49 +00:00
int prm_cn , prm_sc ;
int icom_val ;
int retval ;
int min , hr , sec ;
switch ( parm ) {
case RIG_PARM_ANN :
if ( ( val . i = = RIG_ANN_FREQ ) | | ( val . i = = RIG_ANN_RXMODE ) ) {
prm_cn = C_CTL_ANN ;
prm_sc = val . i ;
prm_len = 0 ;
}
else {
if ( ( val . i = = RIG_ANN_ENG ) | | ( val . i = = RIG_ANN_JAP ) ) {
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
prm_len = 2 ;
prmbuf [ 0 ] = S_PRM_LANG ;
prmbuf [ 1 ] = ( val . i = = RIG_ANN_ENG ? 0 : 1 ) ;
2004-08-21 23:53:39 +00:00
}
else {
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_ERR , " Unsupported set_parm_ann %d \n " , val . i ) ;
return - RIG_EINVAL ;
2004-08-21 23:53:39 +00:00
}
}
2005-04-16 11:55:49 +00:00
break ;
case RIG_PARM_APO :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
hr = ( float ) val . i / 60.0 ;
min = val . i - ( hr * 60 ) ;
prm_len = 3 ;
prmbuf [ 0 ] = S_PRM_SLPTM ;
to_bcd_be ( prmbuf + 1 , ( long long ) hr , 2 ) ;
to_bcd_be ( prmbuf + 2 , ( long long ) min , 2 ) ;
break ;
case RIG_PARM_BACKLIGHT :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
icom_val = val . f * 255 ;
prm_len = 3 ;
prmbuf [ 0 ] = S_PRM_BACKLT ;
to_bcd_be ( prmbuf + 1 , ( long long ) icom_val , ( prm_len - 1 ) * 2 ) ;
break ;
case RIG_PARM_BEEP :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
prm_len = 2 ;
prmbuf [ 0 ] = S_PRM_BEEP ;
prmbuf [ 1 ] = val . i ;
break ;
case RIG_PARM_TIME :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
hr = ( float ) val . i / 3600.0 ;
min = ( float ) ( val . i - ( hr * 3600 ) ) / 60.0 ;
sec = ( val . i - ( hr * 3600 ) - ( min * 60 ) ) ;
prm_len = 4 ;
prmbuf [ 0 ] = S_PRM_TIME ;
to_bcd_be ( prmbuf + 1 , ( long long ) hr , 2 ) ;
to_bcd_be ( prmbuf + 2 , ( long long ) min , 2 ) ;
to_bcd_be ( prmbuf + 3 , ( long long ) sec , 2 ) ;
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported set_parm %d \n " , parm ) ;
return - RIG_EINVAL ;
}
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , prm_cn , prm_sc , prmbuf , prm_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_parm: wrong frame len=%d \n " ,
ack_len ) ;
return - RIG_EPROTO ;
}
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2004-08-21 23:53:39 +00:00
}
2005-04-16 11:55:49 +00:00
/*
* icom_get_parm
* Assumes rig ! = NULL
*/
int icom_get_parm ( RIG * rig , setting_t parm , value_t * val )
{
unsigned char prmbuf [ MAXFRAMELEN ] , resbuf [ MAXFRAMELEN ] ;
int prm_len , res_len ;
int prm_cn , prm_sc ;
int icom_val ;
int cmdhead ;
int retval ;
int min , hr , sec ;
switch ( parm ) {
case RIG_PARM_APO :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
prm_len = 1 ;
prmbuf [ 0 ] = S_PRM_SLPTM ;
break ;
case RIG_PARM_BACKLIGHT :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
prm_len = 1 ;
prmbuf [ 0 ] = S_PRM_BACKLT ;
break ;
case RIG_PARM_BEEP :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
prm_len = 1 ;
prmbuf [ 0 ] = S_PRM_BEEP ;
break ;
case RIG_PARM_TIME :
prm_cn = C_CTL_MEM ;
prm_sc = S_MEM_MODE_SLCT ;
prm_len = 1 ;
prmbuf [ 0 ] = S_PRM_TIME ;
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported get_parm %d " , parm ) ;
return - RIG_EINVAL ;
}
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , prm_cn , prm_sc , prmbuf , prm_len ,
resbuf , & res_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
/*
* strbuf should contain Cn , Sc , [ pn ] , Data area
*/
cmdhead = ( prm_sc = = - 1 ) ? 1 : 3 ;
res_len - = cmdhead ;
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
if ( resbuf [ 0 ] ! = ACK & & resbuf [ 0 ] ! = prm_cn ) {
rig_debug ( RIG_DEBUG_ERR , " %s: ack NG (%#.2x), "
" len=%d \n " , __FUNCTION__ , resbuf [ 0 ] , res_len ) ;
return - RIG_ERJCTED ;
}
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
switch ( parm ) {
case RIG_PARM_APO :
hr = from_bcd_be ( resbuf + cmdhead , 2 ) ;
min = from_bcd_be ( resbuf + cmdhead + 1 , 2 ) ;
icom_val = ( hr * 60 ) + min ;
val - > i = icom_val ;
break ;
case RIG_PARM_TIME :
hr = from_bcd_be ( resbuf + cmdhead , 2 ) ;
min = from_bcd_be ( resbuf + cmdhead + 1 , 2 ) ;
sec = from_bcd_be ( resbuf + cmdhead + 2 , 2 ) ;
icom_val = ( hr * 3600 ) + ( min * 60 ) + sec ;
val - > i = icom_val ;
break ;
default :
icom_val = from_bcd_be ( resbuf + cmdhead , res_len * 2 ) ;
if ( RIG_PARM_IS_FLOAT ( parm ) )
val - > f = ( float ) icom_val / 255 ;
else
2004-08-21 23:53:39 +00:00
val - > i = icom_val ;
2005-04-16 11:55:49 +00:00
}
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_TRACE , " %s: %d %d %d %f \n " ,
__FUNCTION__ , res_len , icom_val , val - > i , val - > f ) ;
2004-08-21 23:53:39 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2004-08-21 23:53:39 +00:00
}
2001-03-02 18:33:27 +00:00
/*
2001-07-01 11:46:17 +00:00
* icom_set_ctcss_tone
2006-07-18 22:51:43 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
2001-03-02 18:33:27 +00:00
*
* Warning ! This is untested stuff ! May work at least on 756 PRO and IC746 .
* Please owners report to me < f4cfe @ users . sourceforge . net > , thanks . - - SF
2006-07-18 22:51:43 +00:00
Works for 746 pro and should work for 756 xx and 7800
2001-03-02 18:33:27 +00:00
*/
2001-07-01 11:46:17 +00:00
int icom_set_ctcss_tone ( RIG * rig , vfo_t vfo , tone_t tone )
2001-03-02 18:33:27 +00:00
{
2005-04-16 11:55:49 +00:00
const struct rig_caps * caps ;
unsigned char tonebuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int tone_len , ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int i ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
caps = rig - > caps ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
/*
* I don ' t have documentation for this function ,
* and I can ' t experiment ( no hardware ) , so let ' s guess .
* Most probably , it might be the index of the CTCSS subaudible
* tone , and not the tone itself , starting from zero .
*
2006-07-18 22:51:43 +00:00
* Something in the range of 00. .51 , BCD big endian 4 nibbles
2005-04-16 11:55:49 +00:00
* Please someone let me know if it works this way . - - SF
2006-07-18 22:51:43 +00:00
* No . sent directly as be nibbles with frequency same format as internal kh
2005-04-16 11:55:49 +00:00
*/
2006-07-18 22:51:43 +00:00
for ( i = 0 ; caps - > ctcss_list [ i ] ! = 0 & & i < 52 ; i + + ) {
2005-04-16 11:55:49 +00:00
if ( caps - > ctcss_list [ i ] = = tone )
break ;
}
if ( caps - > ctcss_list [ i ] ! = tone )
return - RIG_EINVAL ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
tone_len = 1 ;
2006-07-18 22:51:43 +00:00
to_bcd_be ( tonebuf , tone , tone_len * 2 ) ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_TONE , S_TONE_RPTR ,
tonebuf , tone_len , ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_ctcss_tone: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2001-03-02 18:33:27 +00:00
}
/*
2001-07-01 11:46:17 +00:00
* icom_get_ctcss_tone
2001-03-02 18:33:27 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2001-07-01 11:46:17 +00:00
int icom_get_ctcss_tone ( RIG * rig , vfo_t vfo , tone_t * tone )
2001-03-02 18:33:27 +00:00
{
2005-04-16 11:55:49 +00:00
const struct rig_caps * caps ;
unsigned char tonebuf [ MAXFRAMELEN ] ;
2006-07-18 22:51:43 +00:00
int tone_len , retval ;
2005-04-16 11:55:49 +00:00
int i ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
caps = rig - > caps ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
/*
2006-07-18 22:51:43 +00:00
* see icom_set_ctcss for discussion on the status !
2005-04-16 11:55:49 +00:00
*/
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_TONE , S_TONE_RPTR , NULL , 0 ,
tonebuf , & tone_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-03-02 18:33:27 +00:00
2006-07-18 22:51:43 +00:00
/* cn,sc,data*3 */
if ( tone_len ! = 5 ) {
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_ERR , " icom_get_ctcss_tone: ack NG (%#.2x), "
" len=%d \n " , tonebuf [ 0 ] , tone_len ) ;
return - RIG_ERJCTED ;
}
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
tone_len - = 2 ;
2006-07-18 22:51:43 +00:00
* tone = from_bcd_be ( tonebuf + 2 , tone_len * 2 ) ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
/* check this tone exists. That's better than nothing. */
2006-07-18 22:51:43 +00:00
for ( i = 0 ; caps - > ctcss_list [ i ] ! = 0 & & i < 52 ; i + + ) {
if ( caps - > ctcss_list [ i ] = = * tone )
return RIG_OK ;
2005-04-16 11:55:49 +00:00
}
2001-03-02 18:33:27 +00:00
2006-07-18 22:51:43 +00:00
rig_debug ( RIG_DEBUG_ERR , " icom_get_ctcss_tone: CTCSS NG "
" (%#.2x) \n " , tonebuf [ 2 ] ) ;
return - RIG_EPROTO ;
2001-03-02 18:33:27 +00:00
}
/*
* icom_set_ctcss_sql
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*
* Warning ! This is untested stuff ! May work at least on 756 PRO and IC746 .
* Please owners report to me < f4cfe @ users . sourceforge . net > , thanks . - - SF
*/
2006-07-18 22:51:43 +00:00
int icom_set_ctcss_sql ( RIG * rig , vfo_t vfo , tone_t tone )
2001-03-02 18:33:27 +00:00
{
2005-04-16 11:55:49 +00:00
const struct rig_caps * caps ;
unsigned char tonebuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int tone_len , ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int i ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
caps = rig - > caps ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
/*
* see icom_set_ctcss for discussion on the untested status !
*/
2001-03-02 18:33:27 +00:00
2006-07-18 22:51:43 +00:00
for ( i = 0 ; caps - > ctcss_list [ i ] ! = 0 & & i < 52 ; i + + ) {
2005-04-16 11:55:49 +00:00
if ( caps - > ctcss_list [ i ] = = tone )
break ;
}
if ( caps - > ctcss_list [ i ] ! = tone )
return - RIG_EINVAL ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
tone_len = 1 ;
2006-07-18 22:51:43 +00:00
to_bcd_be ( tonebuf , tone , tone_len * 2 ) ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_TONE , S_TONE_SQL ,
tonebuf , tone_len , ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_ctcss_sql: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2001-03-02 18:33:27 +00:00
}
/*
* icom_get_ctcss_sql
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2006-07-18 22:51:43 +00:00
int icom_get_ctcss_sql ( RIG * rig , vfo_t vfo , tone_t * tone )
2001-03-02 18:33:27 +00:00
{
2005-04-16 11:55:49 +00:00
const struct rig_caps * caps ;
unsigned char tonebuf [ MAXFRAMELEN ] ;
2006-07-18 22:51:43 +00:00
int tone_len , retval ;
2005-04-16 11:55:49 +00:00
int i ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
caps = rig - > caps ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
/*
* see icom_set_ctcss for discussion on the untested status !
*/
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_TONE , S_TONE_SQL , NULL , 0 ,
tonebuf , & tone_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-03-02 18:33:27 +00:00
2006-07-18 22:51:43 +00:00
if ( tone_len ! = 5 ) {
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_ERR , " icom_get_ctcss_sql: ack NG (%#.2x), "
" len=%d \n " , tonebuf [ 0 ] , tone_len ) ;
return - RIG_ERJCTED ;
}
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
tone_len - = 2 ;
2006-07-18 22:51:43 +00:00
* tone = from_bcd_be ( tonebuf + 2 , tone_len * 2 ) ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
/* check this tone exists. That's better than nothing. */
2006-07-18 22:51:43 +00:00
for ( i = 0 ; caps - > ctcss_list [ i ] ! = 0 & & i < 52 ; i + + ) {
if ( caps - > ctcss_list [ i ] = = * tone )
return RIG_OK ;
2005-04-16 11:55:49 +00:00
}
2001-03-02 18:33:27 +00:00
2006-07-18 22:51:43 +00:00
rig_debug ( RIG_DEBUG_ERR , " icom_get_ctcss_sql: CTCSS NG "
" (%#.2x) \n " , tonebuf [ 2 ] ) ;
return - RIG_EPROTO ;
2001-03-02 18:33:27 +00:00
}
2000-10-10 21:58:31 +00:00
2000-10-23 19:48:12 +00:00
/*
2001-03-02 18:33:27 +00:00
* icom_set_powerstat
2000-10-23 19:48:12 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2001-03-02 18:33:27 +00:00
int icom_set_powerstat ( RIG * rig , powerstat_t status )
2000-10-23 19:48:12 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int pwr_sc ;
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
pwr_sc = status = = RIG_POWER_ON ? S_PWR_ON : S_PWR_OFF ;
2001-03-02 18:33:27 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_SET_PWR , pwr_sc , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_powerstat: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-23 19:48:12 +00:00
}
/*
2001-03-02 18:33:27 +00:00
* icom_get_powerstat
2000-10-23 19:48:12 +00:00
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2001-03-02 18:33:27 +00:00
int icom_get_powerstat ( RIG * rig , powerstat_t * status )
2000-10-23 19:48:12 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char cmdbuf [ MAXFRAMELEN ] , ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int cmd_len , ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
/* r75 has no way to get power status, so fake it */
if ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) {
/* getting the mode doesn't work if a memory is blank */
/* so use one of the more innculous 'set mode' commands instead */
cmd_len = 1 ;
cmdbuf [ 0 ] = S_PRM_TIME ;
retval = icom_transaction ( rig , C_CTL_MEM , S_MEM_MODE_SLCT ,
cmdbuf , cmd_len , ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2004-08-27 01:49:38 +00:00
2005-04-16 11:55:49 +00:00
* status = ( ( ack_len = = 6 ) & & ( ackbuf [ 0 ] = = C_CTL_MEM ) ) ?
RIG_POWER_ON : RIG_POWER_OFF ;
}
else {
retval = icom_transaction ( rig , C_SET_PWR , - 1 , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2004-08-27 01:49:38 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_get_powerstat: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
2000-10-23 19:48:12 +00:00
}
2005-04-16 11:55:49 +00:00
* status = ackbuf [ 1 ] = = S_PWR_ON ? RIG_POWER_ON : RIG_POWER_OFF ;
}
return RIG_OK ;
2000-10-23 19:48:12 +00:00
}
2001-03-02 18:33:27 +00:00
2000-10-23 19:48:12 +00:00
/*
* icom_set_mem
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_mem ( RIG * rig , vfo_t vfo , int ch )
2000-10-23 19:48:12 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char membuf [ 2 ] ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int chan_len ;
chan_len = ch < 100 ? 1 : 2 ;
to_bcd_be ( membuf , ch , chan_len * 2 ) ;
retval = icom_transaction ( rig , C_SET_MEM , - 1 , membuf , chan_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_mem: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-23 19:48:12 +00:00
}
/*
* icom_set_bank
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
2000-12-05 22:01:03 +00:00
int icom_set_bank ( RIG * rig , vfo_t vfo , int bank )
2000-10-23 19:48:12 +00:00
{
2005-04-16 11:55:49 +00:00
unsigned char bankbuf [ 2 ] ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
to_bcd_be ( bankbuf , bank , BANK_NB_LEN * 2 ) ;
retval = icom_transaction ( rig , C_SET_MEM , S_BANK ,
bankbuf , CHAN_NB_LEN , ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_bank: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2000-10-23 19:48:12 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-23 19:48:12 +00:00
}
2003-11-16 17:28:29 +00:00
/*
* icom_set_ant
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
int icom_set_ant ( RIG * rig , vfo_t vfo , ant_t ant )
{
2005-04-16 11:55:49 +00:00
unsigned char antarg ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval , i_ant ;
2005-04-16 11:55:49 +00:00
int ant_len ;
2003-11-16 17:28:29 +00:00
2005-04-16 11:55:49 +00:00
/*
2006-07-18 22:51:43 +00:00
* FIXME : IC - 756 *
2005-04-16 11:55:49 +00:00
*/
i_ant = ant = = RIG_ANT_1 ? 0 : 1 ;
antarg = 0 ;
ant_len = ( rig - > caps - > rig_model = = RIG_MODEL_ICR75 ) ? 0 : 1 ;
retval = icom_transaction ( rig , C_CTL_ANT , i_ant ,
& antarg , ant_len , ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_set_ant: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2003-11-16 17:28:29 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2003-11-16 17:28:29 +00:00
}
/*
* icom_get_ant
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
2006-07-18 22:51:43 +00:00
* only meaningfull for HF
2003-11-16 17:28:29 +00:00
*/
int icom_get_ant ( RIG * rig , vfo_t vfo , ant_t * ant )
{
2005-04-16 11:55:49 +00:00
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int ack_len = sizeof ( ackbuf ) , retval ;
2003-11-16 17:28:29 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , C_CTL_ANT , - 1 , NULL , 0 ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2003-11-16 17:28:29 +00:00
2006-07-18 22:51:43 +00:00
if ( ack_len ! = 2 | | ackbuf [ 0 ] ! = C_CTL_ANT ) {
2005-04-16 11:55:49 +00:00
rig_debug ( RIG_DEBUG_ERR , " icom_get_ant: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2006-07-18 22:51:43 +00:00
2005-04-16 11:55:49 +00:00
* ant = ackbuf [ 1 ] = = 0 ? RIG_ANT_1 : RIG_ANT_2 ;
2003-11-16 17:28:29 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2003-11-16 17:28:29 +00:00
}
2001-06-03 19:54:05 +00:00
/*
* icom_vfo_op , Mem / VFO operation
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
int icom_vfo_op ( RIG * rig , vfo_t vfo , vfo_op_t op )
{
2005-04-16 11:55:49 +00:00
unsigned char mvbuf [ MAXFRAMELEN ] ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int mv_len , ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int mv_cn , mv_sc ;
mv_len = 0 ;
switch ( op ) {
case RIG_OP_CPY :
mv_cn = C_SET_VFO ;
mv_sc = S_BTOA ;
break ;
case RIG_OP_XCHG :
mv_cn = C_SET_VFO ;
mv_sc = S_XCHNG ;
break ;
2001-06-03 19:54:05 +00:00
#if 0
2005-04-16 11:55:49 +00:00
case RIG_OP_DUAL_OFF :
mv_cn = C_SET_VFO ;
mv_sc = S_DUAL_OFF ;
break ;
case RIG_OP_DUAL_ON :
mv_cn = C_SET_VFO ;
mv_sc = S_DUAL_ON ;
break ;
2001-06-03 19:54:05 +00:00
# endif
2005-04-16 11:55:49 +00:00
case RIG_OP_FROM_VFO :
mv_cn = C_WR_MEM ;
mv_sc = - 1 ;
break ;
case RIG_OP_TO_VFO :
mv_cn = C_MEM2VFO ;
mv_sc = - 1 ;
break ;
case RIG_OP_MCL :
mv_cn = C_CLR_MEM ;
mv_sc = - 1 ;
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported mem/vfo op %#x " , op ) ;
return - RIG_EINVAL ;
}
2001-06-03 19:54:05 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , mv_cn , mv_sc , mvbuf , mv_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-06-03 19:54:05 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
2005-04-20 13:26:55 +00:00
if ( op ! = RIG_OP_XCHG )
rig_debug ( RIG_DEBUG_ERR , " icom_vfo_op: ack NG (%#.2x), "
2005-04-16 11:55:49 +00:00
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
2001-06-03 19:54:05 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2001-06-03 19:54:05 +00:00
}
2000-10-23 19:48:12 +00:00
2001-06-26 20:55:29 +00:00
/*
* icom_scan , scan operation
* Assumes rig ! = NULL , rig - > state . priv ! = NULL
*/
int icom_scan ( RIG * rig , vfo_t vfo , scan_t scan , int ch )
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char scanbuf [ MAXFRAMELEN ] ;
unsigned char ackbuf [ MAXFRAMELEN ] ;
2007-01-27 23:50:13 +00:00
int scan_len , ack_len = sizeof ( ackbuf ) , retval ;
2005-04-16 11:55:49 +00:00
int scan_cn , scan_sc ;
2001-06-26 20:55:29 +00:00
2005-04-16 11:55:49 +00:00
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
scan_len = 0 ;
scan_cn = C_CTL_SCAN ;
switch ( scan ) {
case RIG_SCAN_STOP :
scan_sc = S_SCAN_STOP ;
break ;
case RIG_SCAN_MEM :
retval = icom_set_vfo ( rig , RIG_VFO_MEM ) ;
if ( retval ! = RIG_OK )
return retval ;
scan_sc = S_SCAN_START ;
break ;
case RIG_SCAN_SLCT :
retval = icom_set_vfo ( rig , RIG_VFO_MEM ) ;
if ( retval ! = RIG_OK )
return retval ;
scan_sc = S_SCAN_START ;
break ;
case RIG_SCAN_PRIO :
case RIG_SCAN_PROG :
/* TODO: for SCAN_PROG, check this is an edge chan */
/* BTW, I'm wondering if this is possible with CI-V */
retval = icom_set_mem ( rig , RIG_VFO_CURR , ch ) ;
if ( retval ! = RIG_OK )
return retval ;
retval = icom_set_vfo ( rig , RIG_VFO_VFO ) ;
if ( retval ! = RIG_OK )
2001-06-26 20:55:29 +00:00
return retval ;
2005-04-16 11:55:49 +00:00
scan_sc = S_SCAN_START ;
break ;
case RIG_SCAN_DELTA :
scan_sc = S_SCAN_DELTA ; /* TODO: delta-f support */
break ;
default :
rig_debug ( RIG_DEBUG_ERR , " Unsupported scan %#x " , scan ) ;
return - RIG_EINVAL ;
}
2001-06-26 20:55:29 +00:00
2005-04-16 11:55:49 +00:00
retval = icom_transaction ( rig , scan_cn , scan_sc , scanbuf , scan_len ,
ackbuf , & ack_len ) ;
if ( retval ! = RIG_OK )
return retval ;
2001-06-26 20:55:29 +00:00
2005-04-16 11:55:49 +00:00
if ( ack_len ! = 1 | | ackbuf [ 0 ] ! = ACK ) {
rig_debug ( RIG_DEBUG_ERR , " icom_scan: ack NG (%#.2x), "
" len=%d \n " , ackbuf [ 0 ] , ack_len ) ;
return - RIG_ERJCTED ;
}
return RIG_OK ;
2001-06-26 20:55:29 +00:00
}
2000-10-08 21:38:45 +00:00
/*
* icom_decode is called by sa_sigio , when some asynchronous
* data has been received from the rig
*/
int icom_decode_event ( RIG * rig )
{
2005-04-16 11:55:49 +00:00
struct icom_priv_data * priv ;
struct rig_state * rs ;
unsigned char buf [ MAXFRAMELEN ] ;
int frm_len ;
freq_t freq ;
rmode_t mode ;
pbwidth_t width ;
rig_debug ( RIG_DEBUG_VERBOSE , " icom: icom_decode called \n " ) ;
rs = & rig - > state ;
priv = ( struct icom_priv_data * ) rs - > priv ;
frm_len = read_icom_frame ( & rs - > rigport , buf ) ;
if ( frm_len = = - RIG_ETIMEOUT )
rig_debug ( RIG_DEBUG_VERBOSE , " icom: icom_decode got a timeout before the first character \n " ) ;
if ( frm_len < 0 )
return frm_len ;
switch ( buf [ frm_len - 1 ] )
{
case COL :
rig_debug ( RIG_DEBUG_VERBOSE , " icom: icom_decode saw a collision \n " ) ;
/* Collision */
return - RIG_BUSBUSY ;
case FI :
/* Ok, normal frame */
break ;
default :
/* Timeout after reading at least one character */
/* Problem on ci-v bus? */
return - RIG_EPROTO ;
}
if ( buf [ 3 ] ! = BCASTID & & buf [ 3 ] ! = priv - > re_civ_addr ) {
rig_debug ( RIG_DEBUG_WARN , " icom_decode: CI-V %#x called for %#x! \n " ,
priv - > re_civ_addr , buf [ 3 ] ) ;
}
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
/*
* the first 2 bytes must be 0xfe
* the 3 rd one the emitter
* the 4 rd one 0x00 since this is transceive mode
* then the command number
* the rest is data
* and don ' t forget one byte at the end for the EOM
*/
switch ( buf [ 4 ] ) {
case C_SND_FREQ :
2000-10-08 21:38:45 +00:00
/*
2005-04-16 11:55:49 +00:00
* TODO : the freq length might be less than 4 or 5 bytes
* on older rigs !
2000-10-08 21:38:45 +00:00
*/
2005-04-16 11:55:49 +00:00
if ( rig - > callbacks . freq_event ) {
freq = from_bcd ( buf + 5 , ( priv - > civ_731_mode ? 4 : 5 ) * 2 ) ;
return rig - > callbacks . freq_event ( rig , RIG_VFO_CURR , freq ,
rig - > callbacks . freq_arg ) ;
} else
return - RIG_ENAVAIL ;
break ;
case C_SND_MODE :
if ( rig - > callbacks . mode_event ) {
icom2rig_mode ( rig , buf [ 5 ] , buf [ 6 ] , & mode , & width ) ;
return rig - > callbacks . mode_event ( rig , RIG_VFO_CURR ,
mode , width ,
rig - > callbacks . mode_arg ) ;
} else
return - RIG_ENAVAIL ;
break ;
default :
rig_debug ( RIG_DEBUG_VERBOSE , " icom_decode: tranceive cmd "
" unsupported %#2.2x \n " , buf [ 4 ] ) ;
return - RIG_ENIMPL ;
}
2000-10-08 21:38:45 +00:00
2005-04-16 11:55:49 +00:00
return RIG_OK ;
2000-10-08 21:38:45 +00:00
}
2001-06-10 22:29:00 +00:00
/*
* init_icom is called by rig_probe_all ( register . c )
*
2003-03-10 08:26:09 +00:00
* probe_icom reports all the devices on the CI - V bus .
2003-04-16 22:30:43 +00:00
*
* rig_model_t probeallrigs_icom ( port_t * port , rig_probe_func_t cfunc , rig_ptr_t data )
2001-06-10 22:29:00 +00:00
*/
2003-04-16 22:30:43 +00:00
DECLARE_PROBERIG_BACKEND ( icom )
2001-06-10 22:29:00 +00:00
{
2003-03-10 08:26:09 +00:00
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 ;
2003-04-16 22:30:43 +00:00
if ( ! port )
2005-04-16 11:55:49 +00:00
return RIG_MODEL_NONE ;
2003-03-10 08:26:09 +00:00
2003-04-16 22:30:43 +00:00
if ( port - > type . rig ! = RIG_PORT_SERIAL )
2005-04-16 11:55:49 +00:00
return RIG_MODEL_NONE ;
2001-06-10 22:29:00 +00:00
2003-04-16 22:30:43 +00:00
port - > write_delay = port - > post_write_delay = 0 ;
port - > retry = 1 ;
2001-06-10 22:29:00 +00:00
2003-03-10 08:26:09 +00:00
/*
* try for all different baud rates
*/
for ( rates_idx = 0 ; rates [ rates_idx ] ; rates_idx + + ) {
2005-04-16 11:55:49 +00:00
port - > parm . serial . rate = rates [ rates_idx ] ;
port - > timeout = 2 * 1000 / rates [ rates_idx ] + 40 ;
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
retval = serial_open ( port ) ;
if ( retval ! = RIG_OK )
return RIG_MODEL_NONE ;
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
/*
* 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 + + ) {
2001-06-10 22:29:00 +00:00
2006-10-07 20:45:40 +00:00
frm_len = make_cmd_frame ( ( char * ) buf , civ_addr , C_RD_TRXID , S_RD_TRXID ,
NULL , 0 ) ;
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
serial_flush ( port ) ;
2006-10-07 20:45:40 +00:00
write_block ( port , ( char * ) buf , frm_len ) ;
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
/* read out the bytes we just sent
* TODO : check this is what we expect
*/
frm_len = read_icom_frame ( port , buf ) ;
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
/* this is the reply */
frm_len = read_icom_frame ( port , buf ) ;
/* timeout.. nobody's there */
if ( frm_len < = 0 )
continue ;
if ( buf [ 7 ] ! = FI & & buf [ 5 ] ! = FI ) {
/* protocol error, unexpected reply.
* is this a CI - V device ?
2001-06-10 22:29:00 +00:00
*/
2005-04-16 11:55:49 +00:00
close ( port - > fd ) ;
return RIG_MODEL_NONE ;
} else if ( buf [ 4 ] = = NAK ) {
/*
* this is an Icom , but it does not support transceiver ID
* try to guess from the return address
*/
civ_id = buf [ 3 ] ;
} else {
civ_id = buf [ 6 ] ;
2001-06-10 22:29:00 +00:00
}
2003-06-22 19:40:54 +00:00
2005-04-16 11:55:49 +00:00
for ( i = 0 ; icom_addr_list [ i ] . model ! = RIG_MODEL_NONE ; i + + ) {
if ( icom_addr_list [ i ] . re_civ_addr = = civ_id ) {
rig_debug ( RIG_DEBUG_VERBOSE , " probe_icom: found %#x "
" at %#x \n " , civ_id , buf [ 3 ] ) ;
model = icom_addr_list [ i ] . model ;
if ( cfunc )
( * cfunc ) ( port , model , data ) ;
break ;
}
}
2003-06-22 19:40:54 +00:00
/*
2005-04-16 11:55:49 +00:00
* not found in known table . . . .
* update icom_addr_list [ ] !
2003-06-22 19:40:54 +00:00
*/
2005-04-16 11:55:49 +00:00
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 ) ;
}
2003-06-22 19:40:54 +00:00
2005-04-16 11:55:49 +00:00
/*
* Try to identify OptoScan
*/
for ( civ_addr = 0x80 ; civ_addr < = 0x8f ; civ_addr + + ) {
2006-10-07 20:45:40 +00:00
frm_len = make_cmd_frame ( ( char * ) buf , civ_addr , C_CTL_MISC , S_OPTO_RDID ,
NULL , 0 ) ;
2005-04-16 11:55:49 +00:00
serial_flush ( port ) ;
2006-10-07 20:45:40 +00:00
write_block ( port , ( char * ) buf , frm_len ) ;
2005-04-16 11:55:49 +00:00
/* read out the bytes we just sent
* TODO : check this is what we expect
*/
frm_len = read_icom_frame ( port , buf ) ;
/* this is the reply */
frm_len = read_icom_frame ( port , buf ) ;
/* timeout.. nobody's there */
if ( frm_len < = 0 )
continue ;
/* wrong protocol? */
if ( frm_len ! = 7 | | buf [ 4 ] ! = C_CTL_MISC | | buf [ 5 ] ! = S_OPTO_RDID )
continue ;
rig_debug ( RIG_DEBUG_VERBOSE , " %s, found OptoScan%c%c%c, software version %d.%d, "
" interface version %d.%d, at %#x \n " ,
__FUNCTION__ ,
buf [ 2 ] , buf [ 3 ] , buf [ 4 ] ,
buf [ 5 ] > > 4 , buf [ 5 ] & 0xf ,
buf [ 6 ] > > 4 , buf [ 6 ] & 0xf ,
civ_addr ) ;
if ( buf [ 6 ] = = ' 5 ' & & buf [ 7 ] = = ' 3 ' & & buf [ 8 ] = = ' 5 ' )
model = RIG_MODEL_OS535 ;
else if ( buf [ 6 ] = = ' 4 ' & & buf [ 7 ] = = ' 5 ' & & buf [ 8 ] = = ' 6 ' )
model = RIG_MODEL_OS456 ;
else
continue ;
2003-06-22 19:40:54 +00:00
2005-04-16 11:55:49 +00:00
if ( cfunc )
( * cfunc ) ( port , model , data ) ;
break ;
}
2003-06-22 19:40:54 +00:00
2005-04-16 11:55:49 +00:00
close ( port - > fd ) ;
2001-06-10 22:29:00 +00:00
2005-04-16 11:55:49 +00:00
/*
* 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 ;
2003-03-10 08:26:09 +00:00
}
2001-06-10 22:29:00 +00:00
2003-03-10 08:26:09 +00:00
return model ;
2001-06-10 22:29:00 +00:00
}
2000-10-08 21:38:45 +00:00
/*
2001-12-28 20:28:04 +00:00
* initrigs_icom is called by rig_backend_load
2000-10-08 21:38:45 +00:00
*/
2003-04-16 22:30:43 +00:00
DECLARE_INITRIG_BACKEND ( icom )
2000-10-08 21:38:45 +00:00
{
2002-07-09 20:43:37 +00:00
rig_debug ( RIG_DEBUG_VERBOSE , " icom: _init called \n " ) ;
2003-11-05 20:40:27 +00:00
rig_register ( & ic703_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & ic706_caps ) ;
rig_register ( & ic706mkii_caps ) ;
rig_register ( & ic706mkiig_caps ) ;
rig_register ( & ic718_caps ) ;
2002-12-23 14:20:42 +00:00
rig_register ( & ic725_caps ) ;
2003-11-10 16:01:21 +00:00
rig_register ( & ic726_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & ic735_caps ) ;
2003-02-19 23:56:56 +00:00
rig_register ( & ic736_caps ) ;
2002-11-16 14:05:53 +00:00
rig_register ( & ic737_caps ) ;
2003-10-24 22:59:18 +00:00
rig_register ( & ic746_caps ) ;
rig_register ( & ic746pro_caps ) ;
2004-05-18 06:55:06 +00:00
rig_register ( & ic751_caps ) ;
2004-03-07 15:49:45 +00:00
rig_register ( & ic761_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & ic775_caps ) ;
rig_register ( & ic756_caps ) ;
rig_register ( & ic756pro_caps ) ;
rig_register ( & ic756pro2_caps ) ;
2004-09-25 14:33:17 +00:00
rig_register ( & ic756pro3_caps ) ;
2003-11-10 16:01:21 +00:00
rig_register ( & ic765_caps ) ;
2004-09-25 14:33:17 +00:00
rig_register ( & ic78_caps ) ;
rig_register ( & ic7800_caps ) ;
2006-11-07 12:21:39 +00:00
rig_register ( & ic7000_caps ) ;
2003-11-10 16:01:21 +00:00
rig_register ( & ic781_caps ) ;
2004-02-02 22:15:17 +00:00
rig_register ( & ic707_caps ) ;
rig_register ( & ic728_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & ic821h_caps ) ;
rig_register ( & ic910_caps ) ;
rig_register ( & ic970_caps ) ;
2002-02-28 10:59:46 +00:00
2003-11-16 17:28:29 +00:00
rig_register ( & icr10_caps ) ;
2004-09-25 14:33:17 +00:00
rig_register ( & icr20_caps ) ;
2003-11-16 17:28:29 +00:00
rig_register ( & icr71_caps ) ;
rig_register ( & icr72_caps ) ;
rig_register ( & icr75_caps ) ;
2002-02-28 10:59:46 +00:00
rig_register ( & icr7000_caps ) ;
2003-11-16 17:28:29 +00:00
rig_register ( & icr7100_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & icr8500_caps ) ;
2003-11-16 17:28:29 +00:00
rig_register ( & icr9000_caps ) ;
2001-01-28 22:08:41 +00:00
2003-11-16 17:28:29 +00:00
rig_register ( & ic271_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & ic275_caps ) ;
2003-11-10 16:01:21 +00:00
rig_register ( & ic471_caps ) ;
2002-07-09 20:43:37 +00:00
rig_register ( & ic475_caps ) ;
2001-11-28 22:04:56 +00:00
2002-07-09 20:43:37 +00:00
rig_register ( & os535_caps ) ;
rig_register ( & os456_caps ) ;
2002-03-06 21:10:56 +00:00
2002-07-09 20:43:37 +00:00
rig_register ( & omnivip_caps ) ;
2002-05-30 17:38:07 +00:00
2003-11-16 17:28:29 +00:00
rig_register ( & id1_caps ) ;
2002-07-09 20:43:37 +00:00
return RIG_OK ;
2000-10-08 21:38:45 +00:00
}