2003-10-07 22:15:49 +00:00
|
|
|
/*
|
|
|
|
* Hamlib RFT backend - main file
|
|
|
|
* Copyright (c) 2003 by Thomas B. Ruecker
|
|
|
|
*
|
|
|
|
*
|
2011-08-21 23:18:30 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-10-07 22:15:49 +00:00
|
|
|
*
|
2011-08-21 23:18:30 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2003-10-07 22:15:49 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-21 23:18:30 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-10-07 22:15:49 +00:00
|
|
|
*
|
2011-08-21 23:18:30 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2003-10-07 22:15:49 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2011-08-21 23:18:30 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-10-07 22:15:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "hamlib/rig.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "register.h"
|
|
|
|
|
|
|
|
#include "rft.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define BUFSZ 64
|
|
|
|
|
|
|
|
#define CR "\x0d"
|
|
|
|
#define EOM CR
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rft_transaction
|
|
|
|
* We assume that rig!=NULL, rig->state!= NULL, data!=NULL, data_len!=NULL
|
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
int rft_transaction(RIG *rig, const char *cmd, int cmd_len, char *data,
|
|
|
|
int *data_len)
|
2003-10-07 22:15:49 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int retval;
|
|
|
|
struct rig_state *rs;
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rs = &rig->state;
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2022-01-25 13:59:47 +00:00
|
|
|
rig_flush(rs->rigport);
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2022-01-25 13:59:47 +00:00
|
|
|
retval = write_block(rs->rigport, (unsigned char *) cmd, cmd_len);
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (retval != RIG_OK)
|
|
|
|
{
|
|
|
|
return retval;
|
|
|
|
}
|
2003-10-07 22:15:49 +00:00
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/* no data expected, TODO: flush input? */
|
|
|
|
if (!data || !data_len)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2022-01-25 13:59:47 +00:00
|
|
|
retval = read_string(rs->rigport, (unsigned char *) data, BUFSZ, CR, 1, 0, 1);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (retval == -RIG_ETIMEOUT)
|
|
|
|
{
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval < 0)
|
|
|
|
{
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
*data_len = retval;
|
|
|
|
|
|
|
|
return RIG_OK;
|
2003-10-07 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rft_set_freq
|
|
|
|
* Assumes rig!=NULL
|
|
|
|
*/
|
|
|
|
int rft_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
char freqbuf[16], ackbuf[16];
|
2022-01-11 22:35:35 +00:00
|
|
|
int ack_len, retval;
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/*
|
|
|
|
*/
|
2022-01-11 22:35:35 +00:00
|
|
|
SNPRINTF(freqbuf, sizeof(freqbuf), "FRQ%f" EOM, (float)freq / 1000);
|
|
|
|
retval = rft_transaction(rig, freqbuf, strlen(freqbuf), ackbuf, &ack_len);
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return retval;
|
2003-10-07 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initrigs_rft is called by rig_backend_load
|
|
|
|
*/
|
|
|
|
DECLARE_INITRIG_BACKEND(rft)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: _init called\n", __func__);
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_register(&ekd500_caps);
|
2003-10-07 22:15:49 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2003-10-07 22:15:49 +00:00
|
|
|
}
|
|
|
|
|