kopia lustrzana https://github.com/Hamlib/Hamlib
Add get_freq to FRG-100
This patch adds get_freq to frg100 allowing it to work with WSJT-X. Added rest of Yaesu command set for future expansion too. RRR Mike W9MDBlibusb-1-0
rodzic
1f8f4510dd
commit
03c04209d2
114
yaesu/frg100.c
114
yaesu/frg100.c
|
@ -34,6 +34,7 @@
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "yaesu.h"
|
#include "yaesu.h"
|
||||||
|
#include "frg100.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,11 +55,43 @@
|
||||||
.mode = 1, \
|
.mode = 1, \
|
||||||
.width = 1 \
|
.width = 1 \
|
||||||
}
|
}
|
||||||
|
static const yaesu_cmd_set_t ncmd[] = {
|
||||||
|
{ 0, { 0x00, 0x00, 0x00, 0x00, 0x02 } }, /* Recall Memory */
|
||||||
|
{ 0, { 0x00, 0x00, 0x00, 0x00, 0x03 } }, /* VFO to MEM */
|
||||||
|
{ 0, { 0x00, 0x00, 0x01, 0x00, 0x03 } }, /* Hide Memory Channel */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x05 } }, /* Select VFO (A) */
|
||||||
|
{ 0, { 0x00, 0x00, 0x00, 0x00, 0x0a } }, /* Set Op Freq */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x0c } }, /* OP Mode Set LSB */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x01, 0x0c } }, /* OP Mode Set USB */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x02, 0x0c } }, /* OP Mode Set CW-W */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x03, 0x0c } }, /* OP Mode Set CW-N */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x04, 0x0c } }, /* OP Mode Set AM */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x08, 0x0c } }, /* OP Mode Set RTTY LSB-W */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x09, 0x0c } }, /* OP Mode Set RTTY USB-W */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x0d, 0x0c } }, /* OP Mode Set H3E */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x0e, 0x0c } }, /* OP Mode Set RTTY LSB-N */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x0f, 0x0c } }, /* OP Mode Set RTTY USB-N */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x0f } }, /* PTT (OFF) */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x01, 0x0f } }, /* PTT (ON) */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x01, 0x10 } }, /* Update Memory Ch Number */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x02, 0x10 } }, /* Update Op Data */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x03, 0x10 } }, /* Update VFO Data */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x18 } }, /* Set TX power low */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x28 } }, /* Set TX power mid */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x48 } }, /* Set TX power hi */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x85 } }, /* Copy RX to TX */
|
||||||
|
{ 0, { 0x00, 0x00, 0x00, 0x00, 0x8a } }, /* Set TX Freq only */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0x8e } }, /* Step Operating Frequency Up */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x01, 0x8e } }, /* Step Operating Frequency Down */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0xf7 } }, /* Read Meter */
|
||||||
|
{ 1, { 0x00, 0x00, 0x00, 0x00, 0xfa } }, /* Read Status Flags */
|
||||||
|
};
|
||||||
|
|
||||||
/* Private helper function prototypes */
|
/* Private helper function prototypes */
|
||||||
|
|
||||||
static int frg100_open(RIG *rig);
|
static int frg100_open(RIG *rig);
|
||||||
|
|
||||||
|
static int frg100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
|
||||||
static int frg100_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
|
static int frg100_set_freq(RIG *rig, vfo_t vfo, freq_t freq);
|
||||||
static int frg100_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
|
static int frg100_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width);
|
||||||
static int frg100_set_vfo(RIG *rig, vfo_t vfo);
|
static int frg100_set_vfo(RIG *rig, vfo_t vfo);
|
||||||
|
@ -89,7 +122,7 @@ const struct rig_caps frg100_caps = {
|
||||||
.rig_model = RIG_MODEL_FRG100,
|
.rig_model = RIG_MODEL_FRG100,
|
||||||
.model_name = "FRG-100",
|
.model_name = "FRG-100",
|
||||||
.mfg_name = "Yaesu",
|
.mfg_name = "Yaesu",
|
||||||
.version = "0.4",
|
.version = "0.5",
|
||||||
.copyright = "LGPL",
|
.copyright = "LGPL",
|
||||||
.status = RIG_STATUS_BETA,
|
.status = RIG_STATUS_BETA,
|
||||||
.rig_type = RIG_TYPE_RECEIVER,
|
.rig_type = RIG_TYPE_RECEIVER,
|
||||||
|
@ -132,6 +165,7 @@ const struct rig_caps frg100_caps = {
|
||||||
}, /* Region 1 rx ranges */
|
}, /* Region 1 rx ranges */
|
||||||
|
|
||||||
.tx_range_list1 = {
|
.tx_range_list1 = {
|
||||||
|
{kHz(50), MHz(30), FRG100_MODES, -1, -1, FRG100_VFOS, FRG100_ANTS },
|
||||||
RIG_FRNG_END,
|
RIG_FRNG_END,
|
||||||
}, /* region 1 TX ranges */
|
}, /* region 1 TX ranges */
|
||||||
|
|
||||||
|
@ -141,6 +175,7 @@ const struct rig_caps frg100_caps = {
|
||||||
}, /* Region 2 rx ranges */
|
}, /* Region 2 rx ranges */
|
||||||
|
|
||||||
.tx_range_list2 = {
|
.tx_range_list2 = {
|
||||||
|
{kHz(50), MHz(30), FRG100_MODES, -1, -1, FRG100_VFOS, FRG100_ANTS },
|
||||||
RIG_FRNG_END,
|
RIG_FRNG_END,
|
||||||
}, /* region 2 TX ranges */
|
}, /* region 2 TX ranges */
|
||||||
|
|
||||||
|
@ -164,6 +199,7 @@ const struct rig_caps frg100_caps = {
|
||||||
|
|
||||||
.rig_open = frg100_open,
|
.rig_open = frg100_open,
|
||||||
|
|
||||||
|
.get_freq = frg100_get_freq,
|
||||||
.set_freq = frg100_set_freq,
|
.set_freq = frg100_set_freq,
|
||||||
.set_mode = frg100_set_mode,
|
.set_mode = frg100_set_mode,
|
||||||
.set_vfo = frg100_set_vfo,
|
.set_vfo = frg100_set_vfo,
|
||||||
|
@ -172,6 +208,77 @@ const struct rig_caps frg100_caps = {
|
||||||
.set_powerstat = frg100_set_powerstat,
|
.set_powerstat = frg100_set_powerstat,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline int frg100_channel_is_ok(unsigned char channel){
|
||||||
|
return ((channel >= FRG100_MIN_CHANNEL) &&
|
||||||
|
(channel <= FRG100_MAX_CHANNEL)) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int frg100_do_transaction(RIG *rig, const unsigned char cmd[YAESU_CMD_LENGTH],
|
||||||
|
unsigned char *retbuf, size_t retbuf_len){
|
||||||
|
struct rig_state *rs;
|
||||||
|
unsigned char default_retbuf[1];
|
||||||
|
int retval;
|
||||||
|
|
||||||
|
if (retbuf == NULL){
|
||||||
|
retbuf = default_retbuf;
|
||||||
|
retbuf_len = sizeof(default_retbuf);
|
||||||
|
}
|
||||||
|
rs = &rig->state;
|
||||||
|
memset(retbuf, 0, retbuf_len);
|
||||||
|
|
||||||
|
serial_flush(&rs->rigport);
|
||||||
|
retval = write_block(&rs->rigport, (const char*)cmd, YAESU_CMD_LENGTH);
|
||||||
|
if (retval != RIG_OK) return retval;
|
||||||
|
|
||||||
|
retval = read_block(&rs->rigport, (char*)retbuf, retbuf_len);
|
||||||
|
if (retval != retbuf_len){
|
||||||
|
if ((retval == 1) && (retbuf[0] == FRG100_CMD_RETCODE_ERROR)) return -RIG_ERJCTED;
|
||||||
|
return -RIG_EIO;
|
||||||
|
}
|
||||||
|
if (retval == 1){
|
||||||
|
if ((cmd[4] == FRG100_CMD_UPDATE) && (cmd[3] == 0x01)){
|
||||||
|
/* read memory channel number */
|
||||||
|
if (frg100_channel_is_ok(retbuf[0] + 1)){
|
||||||
|
/* WARNING: Documentation bug, actually
|
||||||
|
we got 0--199 for channels 1--200 */
|
||||||
|
return RIG_OK;
|
||||||
|
}
|
||||||
|
if (retbuf[0] == FRG100_CMD_RETCODE_ERROR) return -RIG_ERJCTED;
|
||||||
|
return -RIG_EIO;
|
||||||
|
}
|
||||||
|
if (retbuf[0] == FRG100_CMD_RETCODE_OK) return RIG_OK;
|
||||||
|
if (retbuf[0] == FRG100_CMD_RETCODE_ERROR) return -RIG_ERJCTED;
|
||||||
|
return -RIG_EIO;
|
||||||
|
}
|
||||||
|
return RIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline freq_t frg100_read_freq_from_buf(const unsigned char p[]){
|
||||||
|
/* WARNING: documentation bug, actually frequency stored in bytes 0..2 only,
|
||||||
|
byte 3 is not used and contain zero */
|
||||||
|
return ((((((unsigned)p[2]) << 8) + p[1]) << 8) + p[0]) * 10.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int frg100_read_op_data_raw(RIG *rig, unsigned char reply[]){
|
||||||
|
if (rig == NULL) return -RIG_EINVAL;
|
||||||
|
return frg100_do_transaction(rig, ncmd[FRG100_NATIVE_UPDATE_OP_DATA].nseq,
|
||||||
|
reply, FRG100_OP_DATA_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int frg100_read_op_data(RIG *rig, unsigned char *hwmode,
|
||||||
|
freq_t *rx_freq, freq_t *tx_freq){
|
||||||
|
int ret;
|
||||||
|
unsigned char reply[FRG100_OP_DATA_LENGTH];
|
||||||
|
|
||||||
|
if ((ret = frg100_read_op_data_raw(rig, reply)) != RIG_OK) return ret;
|
||||||
|
if (hwmode != NULL) *hwmode = reply[7];
|
||||||
|
if (rx_freq != NULL) *rx_freq = frg100_read_freq_from_buf(reply + 2);
|
||||||
|
if (tx_freq != NULL) *tx_freq = frg100_read_freq_from_buf(reply + 11);
|
||||||
|
return RIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* frg100_open routine
|
* frg100_open routine
|
||||||
|
@ -189,6 +296,11 @@ int frg100_open(RIG *rig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int frg100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq){
|
||||||
|
(void) vfo;
|
||||||
|
return frg100_read_op_data(rig, NULL, freq, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int frg100_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
int frg100_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
{
|
{
|
||||||
unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, 0x00, 0x0a};
|
unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, 0x00, 0x0a};
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* frg100.h - (C) Michael Black <mdblack98@gmail.com> 2016
|
||||||
|
*
|
||||||
|
* This shared library provides an API for communicating
|
||||||
|
* via serial interface to an FRG-100 using the "CAT" interface
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define FRG100_OP_DATA_LENGTH 19 /* 0x10 p1=02 return size */
|
||||||
|
#define FRG100_CMD_UPDATE 0x10
|
||||||
|
|
||||||
|
#define FRG100_MIN_CHANNEL 1
|
||||||
|
#define FRG100_MAX_CHANNEL 200
|
||||||
|
|
||||||
|
|
||||||
|
// Return codes
|
||||||
|
#define FRG100_CMD_RETCODE_OK 0x00
|
||||||
|
#define FRG100_CMD_RETCODE_ERROR 0xF0
|
||||||
|
|
||||||
|
typedef enum frg100_native_cmd_e {
|
||||||
|
FRG100_NATIVE_RECALL_MEM = 0, /* 0x02, p1=ch */
|
||||||
|
FRG100_NATIVE_VFO_TO_MEM, /* 0x03, p1=ch, p2=0 */
|
||||||
|
FRG100_NATIVE_MEM_HIDE, /* 0x03, p1=ch, p2=1 */
|
||||||
|
FRG100_NATIVE_VFO_A, /* 0x05 */
|
||||||
|
FRG100_NATIVE_FREQ_SET, /* 0x0a, p1:4=freq */
|
||||||
|
FRG100_NATIVE_MODE_SET_LSB, /* 0x0c, p1=0x00 */
|
||||||
|
FRG100_NATIVE_MODE_SET_USB, /* 0x0c, p1=0x01 */
|
||||||
|
FRG100_NATIVE_MODE_SET_CW_W, /* 0x0c, p1=0x02 */
|
||||||
|
FRG100_NATIVE_MODE_SET_CW_N, /* 0x0c, p1=0x03 */
|
||||||
|
FRG100_NATIVE_MODE_SET_AM, /* 0x0c, p1=0x04 */
|
||||||
|
FRG100_NATIVE_MODE_SET_RTTY_LSB_W, /* 0x0c, p1=0x08 */
|
||||||
|
FRG100_NATIVE_MODE_SET_RTTY_USB_W, /* 0x0c, p1=0x09 */
|
||||||
|
FRG100_NATIVE_MODE_SET_H3E, /* 0x0c, p1=0x0d */
|
||||||
|
FRG100_NATIVE_MODE_SET_RTTY_LSB_N, /* 0x0c, p1=0x0e */
|
||||||
|
FRG100_NATIVE_MODE_SET_RTTY_USB_N, /* 0x0c, p1=0x0f */
|
||||||
|
FRG100_NATIVE_PTT_OFF, /* 0x0f, p1=0 */
|
||||||
|
FRG100_NATIVE_PTT_ON, /* 0x0f, p1=1 */
|
||||||
|
FRG100_NATIVE_UPDATE_MEM_CHNL, /* 0x10, p1=1 */
|
||||||
|
FRG100_NATIVE_UPDATE_OP_DATA, /* 0x10, p1=2 */
|
||||||
|
FRG100_NATIVE_UPDATE_VFO_DATA, /* 0x10, p1=3 */
|
||||||
|
FRG100_NATIVE_TX_POWER_LOW, /* 0x18 */
|
||||||
|
FRG100_NATIVE_TX_POWER_MID, /* 0x28 */
|
||||||
|
FRG100_NATIVE_TX_POWER_HI, /* 0x48 */
|
||||||
|
FRG100_NATIVE_CPY_RX_TO_TX, /* 0x85 */
|
||||||
|
FRG100_NATIVE_TX_FREQ_SET, /* 0x8a, p1:4=freq */
|
||||||
|
FRG100_NATIVE_OP_FREQ_STEP_UP, /* 0x8e, p1=0 */
|
||||||
|
FRG100_NATIVE_OP_FREQ_STEP_DOWN, /* 0x8e, p1=1 */
|
||||||
|
FRG100_NATIVE_READ_METER, /* 0xf7 */
|
||||||
|
FRG100_NATIVE_READ_FLAGS, /* 0xfa */
|
||||||
|
FRG100_NATIVE_SIZE
|
||||||
|
} frg100_native_cmd_t;
|
||||||
|
|
Ładowanie…
Reference in New Issue