2000-11-01 23:25:54 +00:00
|
|
|
/*
|
|
|
|
* hamlib - (C) Frank Singleton 2000 (vk3fcs@ix.netcom.com)
|
|
|
|
*
|
2001-04-26 21:32:54 +00:00
|
|
|
* aor.c - Copyright (C) 2000,2001 Stephane Fillod
|
2000-11-01 23:25:54 +00:00
|
|
|
* This shared library provides an API for communicating
|
|
|
|
* via serial interface to an AOR scanner.
|
|
|
|
*
|
|
|
|
*
|
2001-06-15 07:08:37 +00:00
|
|
|
* $Id: aor.c,v 1.10 2001-06-15 07:08:37 f4cfe Exp $
|
2000-11-01 23:25:54 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h> /* Standard input/output definitions */
|
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
|
|
#include <fcntl.h> /* File control definitions */
|
|
|
|
#include <errno.h> /* Error number definitions */
|
|
|
|
#include <termios.h> /* POSIX terminal control definitions */
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2001-06-15 07:08:37 +00:00
|
|
|
#if defined(__CYGWIN__) && defined(HAMLIB_DLL)
|
|
|
|
# undef HAMLIB_DLL
|
|
|
|
# include <hamlib/rig.h>
|
|
|
|
# include <serial.h>
|
|
|
|
# include <misc.h>
|
|
|
|
# define HAMLIB_DLL
|
|
|
|
# include <hamlib/rig_dll.h>
|
|
|
|
#else
|
|
|
|
# include <hamlib/rig.h>
|
|
|
|
# include <serial.h>
|
|
|
|
# include <misc.h>
|
|
|
|
#endif
|
|
|
|
|
2000-11-01 23:25:54 +00:00
|
|
|
#include "aor.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* acknowledge is CR
|
|
|
|
* Is \r portable enough?
|
|
|
|
*/
|
|
|
|
#define CR '\r'
|
|
|
|
|
|
|
|
/*
|
|
|
|
* modes in use by the "MD" command
|
|
|
|
*/
|
|
|
|
#define MD_WFM '0'
|
|
|
|
#define MD_NFM '1'
|
|
|
|
#define MD_AM '2'
|
|
|
|
#define MD_USB '3'
|
|
|
|
#define MD_LSB '4'
|
|
|
|
#define MD_CW '5'
|
|
|
|
#define MD_SFM '6'
|
|
|
|
#define MD_WAM '7'
|
|
|
|
#define MD_NAM '8'
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_transaction
|
|
|
|
* We assume that rig!=NULL, rig->state!= NULL, data!=NULL, data_len!=NULL
|
|
|
|
* Otherwise, you'll get a nice seg fault. You've been warned!
|
2001-06-12 07:07:11 +00:00
|
|
|
* return value: RIG_OK if everything's fine, negative value otherwise
|
2000-11-01 23:25:54 +00:00
|
|
|
* TODO: error case handling
|
|
|
|
*/
|
|
|
|
int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
|
|
|
{
|
2001-06-12 07:07:11 +00:00
|
|
|
int i, retval;
|
2001-02-27 23:06:53 +00:00
|
|
|
struct rig_state *rs;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
2001-02-27 23:06:53 +00:00
|
|
|
rs = &rig->state;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = write_block(&rs->rigport, cmd, cmd_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
retval = write_block(&rs->rigport, "\n", 1);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* buffered read are quite helpful here!
|
|
|
|
* However, an automate with a state model would be more efficient..
|
|
|
|
*/
|
|
|
|
i = 0;
|
|
|
|
do {
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = fread_block(&rs->rigport, data+i, 1);
|
|
|
|
if (retval == 0)
|
|
|
|
continue; /* huh!? */
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
} while (data[i++] != CR);
|
|
|
|
|
|
|
|
*data_len = i;
|
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
return RIG_OK;
|
2000-11-01 23:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_close
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int aor_close(RIG *rig)
|
|
|
|
{
|
|
|
|
unsigned char ackbuf[16];
|
|
|
|
int ack_len;
|
|
|
|
|
|
|
|
/* terminate remote operation via the RS-232 */
|
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
return aor_transaction (rig, "EX", 2, ackbuf, &ack_len);
|
2000-11-01 23:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_set_freq
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
2000-12-05 22:01:03 +00:00
|
|
|
int aor_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
2000-11-01 23:25:54 +00:00
|
|
|
{
|
|
|
|
unsigned char freqbuf[16], ackbuf[16];
|
2001-06-12 07:07:11 +00:00
|
|
|
int freq_len, ack_len, retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* actually, frequency must be like nnnnnnnnm0,
|
|
|
|
* where m must be 0 or 5 (for 50Hz).
|
|
|
|
*/
|
|
|
|
freq_len = sprintf(freqbuf,"RF%010Ld", freq);
|
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = aor_transaction (rig, freqbuf, freq_len, ackbuf, &ack_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_get_freq
|
|
|
|
* Assumes rig!=NULL, freq!=NULL
|
|
|
|
*/
|
2000-12-05 22:01:03 +00:00
|
|
|
int aor_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
2000-11-01 23:25:54 +00:00
|
|
|
{
|
|
|
|
unsigned char freqbuf[16];
|
|
|
|
char *rfp;
|
2001-06-12 07:07:11 +00:00
|
|
|
int freq_len, retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = aor_transaction (rig, "RX", 2, freqbuf, &freq_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
rfp = strstr(freqbuf, "RF");
|
|
|
|
sscanf(rfp+2,"%Ld", freq);
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_set_mode
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
2000-12-05 22:01:03 +00:00
|
|
|
int aor_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
2000-11-01 23:25:54 +00:00
|
|
|
{
|
|
|
|
unsigned char mdbuf[16],ackbuf[16];
|
2001-06-12 07:07:11 +00:00
|
|
|
int mdbuf_len, ack_len, aormode, retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
2000-12-04 23:39:18 +00:00
|
|
|
case RIG_MODE_AM:
|
|
|
|
switch(width) {
|
2001-04-26 21:32:54 +00:00
|
|
|
case RIG_PASSBAND_NORMAL:
|
|
|
|
case kHz(9): aormode = MD_AM; break;
|
|
|
|
|
|
|
|
case kHz(12): aormode = MD_WAM; break;
|
|
|
|
case kHz(3): aormode = MD_NAM; break;
|
2000-12-04 23:39:18 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,
|
|
|
|
"aor_set_mode: unsupported passband %d %d\n",
|
|
|
|
mode, width);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-01 23:25:54 +00:00
|
|
|
case RIG_MODE_CW: aormode = MD_CW; break;
|
|
|
|
case RIG_MODE_USB: aormode = MD_USB; break;
|
|
|
|
case RIG_MODE_LSB: aormode = MD_LSB; break;
|
2001-04-26 21:32:54 +00:00
|
|
|
case RIG_MODE_WFM: aormode = MD_WFM; break;
|
2000-12-04 23:39:18 +00:00
|
|
|
case RIG_MODE_FM:
|
|
|
|
switch(width) {
|
2001-04-26 21:32:54 +00:00
|
|
|
case RIG_PASSBAND_NORMAL:
|
|
|
|
case kHz(12): aormode = MD_NFM; break;
|
|
|
|
|
|
|
|
case kHz(9): aormode = MD_SFM; break;
|
2000-12-04 23:39:18 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,
|
|
|
|
"aor_set_mode: unsupported passband %d %d\n",
|
|
|
|
mode, width);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
2000-11-01 23:25:54 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"aor_set_mode: unsupported mode %d\n",
|
|
|
|
mode);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mdbuf_len = sprintf(mdbuf, "MD%c", aormode);
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = aor_transaction (rig, mdbuf, mdbuf_len, ackbuf, &ack_len);
|
2000-11-01 23:25:54 +00:00
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
return retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_get_mode
|
|
|
|
* Assumes rig!=NULL, mode!=NULL
|
|
|
|
*/
|
2000-12-05 22:01:03 +00:00
|
|
|
int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
2000-11-01 23:25:54 +00:00
|
|
|
{
|
|
|
|
unsigned char ackbuf[16];
|
2001-06-12 07:07:11 +00:00
|
|
|
int ack_len, retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
retval = aor_transaction (rig, "MD", 2, ackbuf, &ack_len);
|
|
|
|
if (retval != RIG_OK)
|
|
|
|
return retval;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
if (ack_len != 2 || ackbuf[1] != CR) {
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"aor_get_mode: ack NG, len=%d\n",
|
|
|
|
ack_len);
|
|
|
|
return -RIG_ERJCTED;
|
|
|
|
}
|
|
|
|
|
2000-12-04 23:39:18 +00:00
|
|
|
*width = RIG_PASSBAND_NORMAL;
|
2000-11-01 23:25:54 +00:00
|
|
|
switch (ackbuf[0]) {
|
|
|
|
case MD_AM: *mode = RIG_MODE_AM; break;
|
2000-12-04 23:39:18 +00:00
|
|
|
case MD_NAM:
|
|
|
|
*mode = RIG_MODE_AM;
|
2001-04-26 21:32:54 +00:00
|
|
|
*width = rig_passband_narrow(rig, *mode);
|
2000-12-04 23:39:18 +00:00
|
|
|
break;
|
|
|
|
case MD_WAM:
|
|
|
|
*mode = RIG_MODE_AM;
|
2001-04-26 21:32:54 +00:00
|
|
|
*width = rig_passband_wide(rig, *mode);
|
2000-12-04 23:39:18 +00:00
|
|
|
break;
|
2000-11-01 23:25:54 +00:00
|
|
|
case MD_CW: *mode = RIG_MODE_CW; break;
|
|
|
|
case MD_USB: *mode = RIG_MODE_USB; break;
|
|
|
|
case MD_LSB: *mode = RIG_MODE_LSB; break;
|
2001-04-26 21:32:54 +00:00
|
|
|
case MD_WFM: *mode = RIG_MODE_WFM; break;
|
2000-11-01 23:25:54 +00:00
|
|
|
case MD_NFM: *mode = RIG_MODE_FM; break;
|
2000-12-04 23:39:18 +00:00
|
|
|
case MD_SFM:
|
|
|
|
*mode = RIG_MODE_FM;
|
2001-04-26 21:32:54 +00:00
|
|
|
*width = rig_passband_narrow(rig, *mode);
|
2000-12-04 23:39:18 +00:00
|
|
|
break;
|
2000-11-01 23:25:54 +00:00
|
|
|
default:
|
|
|
|
rig_debug(RIG_DEBUG_ERR,"aor_get_mode: unsupported mode %d\n",
|
|
|
|
ackbuf[0]);
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2001-04-26 21:32:54 +00:00
|
|
|
if (*width != RIG_PASSBAND_NORMAL)
|
|
|
|
*width = rig_passband_normal(rig, *mode);
|
2000-11-01 23:25:54 +00:00
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* aor_set_ts
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
2000-12-05 22:01:03 +00:00
|
|
|
int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts)
|
2000-11-01 23:25:54 +00:00
|
|
|
{
|
|
|
|
unsigned char tsbuf[16],ackbuf[16];
|
|
|
|
int ts_len, ack_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* actually, tuning step must be like nnnnm0,
|
|
|
|
* where m must be 0 or 5 (for 50Hz).
|
|
|
|
*/
|
|
|
|
ts_len = sprintf(tsbuf,"ST%06ld", ts);
|
|
|
|
|
2001-06-12 07:07:11 +00:00
|
|
|
return aor_transaction (rig, tsbuf, ts_len, ackbuf, &ack_len);
|
2000-11-01 23:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-02 18:30:11 +00:00
|
|
|
* aor_set_powerstat
|
2000-11-01 23:25:54 +00:00
|
|
|
* Assumes rig!=NULL, rig->state.priv!=NULL
|
|
|
|
*/
|
2001-03-02 18:30:11 +00:00
|
|
|
int aor_set_powerstat(RIG *rig, powerstat_t status)
|
2000-11-01 23:25:54 +00:00
|
|
|
{
|
|
|
|
unsigned char ackbuf[16];
|
|
|
|
int ack_len;
|
|
|
|
|
2001-03-02 18:30:11 +00:00
|
|
|
if (status != RIG_POWER_OFF)
|
|
|
|
return -RIG_EINVAL;
|
2000-11-01 23:25:54 +00:00
|
|
|
|
2001-03-02 18:30:11 +00:00
|
|
|
/* turn off power */
|
2001-06-12 07:07:11 +00:00
|
|
|
return aor_transaction (rig, "QP", 2, ackbuf, &ack_len);
|
2000-11-01 23:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init_aor is called by rig_backend_load
|
|
|
|
*/
|
|
|
|
int init_aor(void *be_handle)
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "aor: _init called\n");
|
|
|
|
|
|
|
|
rig_register(&ar8200_caps);
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|