kopia lustrzana https://github.com/Hamlib/Hamlib
replaced fread_block in favor of the more intelligent read_string, added some serial_flush
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1025 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.3
rodzic
ab2811115b
commit
ad7310335b
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Alinco backend - main file
|
* Hamlib Alinco backend - main file
|
||||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: alinco.c,v 1.12 2001-12-28 20:28:02 fillods Exp $
|
* $Id: alinco.c,v 1.13 2002-03-13 23:37:12 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -42,7 +42,10 @@
|
||||||
#include "alinco.h"
|
#include "alinco.h"
|
||||||
|
|
||||||
|
|
||||||
#define EOM "\r"
|
/* Line Feed */
|
||||||
|
#define EOM "\x0a"
|
||||||
|
|
||||||
|
#define BUFSZ 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* modes in use by the "2G" command
|
* modes in use by the "2G" command
|
||||||
|
@ -98,11 +101,13 @@
|
||||||
*/
|
*/
|
||||||
int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
||||||
{
|
{
|
||||||
int i, count, retval;
|
int retval;
|
||||||
struct rig_state *rs;
|
struct rig_state *rs;
|
||||||
|
|
||||||
rs = &rig->state;
|
rs = &rig->state;
|
||||||
|
|
||||||
|
serial_flush(&rs->rigport);
|
||||||
|
|
||||||
retval = write_block(&rs->rigport, cmd, cmd_len);
|
retval = write_block(&rs->rigport, cmd, cmd_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -110,20 +115,8 @@ int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
|
||||||
/* no data expected, TODO: flush input? */
|
/* no data expected, TODO: flush input? */
|
||||||
if (!data || !data_len)
|
if (!data || !data_len)
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
* buffered read are quite helpful here!
|
|
||||||
* However, an automate with a state model would be more efficient..
|
|
||||||
*/
|
|
||||||
i = 0;
|
|
||||||
do {
|
|
||||||
count = fread_block(&rs->rigport, data+i, 1);
|
|
||||||
if (count > 0)
|
|
||||||
i += count;
|
|
||||||
else if (count < 0)
|
|
||||||
return count;
|
|
||||||
} while (count > 0);
|
|
||||||
|
|
||||||
*data_len = i;
|
*data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -134,7 +127,7 @@ int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
|
||||||
*/
|
*/
|
||||||
int alinco_set_vfo(RIG *rig, vfo_t vfo)
|
int alinco_set_vfo(RIG *rig, vfo_t vfo)
|
||||||
{
|
{
|
||||||
char cmdbuf[16];
|
char cmdbuf[BUFSZ];
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
char vfo_num;
|
char vfo_num;
|
||||||
|
|
||||||
|
@ -160,7 +153,7 @@ int alinco_set_vfo(RIG *rig, vfo_t vfo)
|
||||||
*/
|
*/
|
||||||
int alinco_get_vfo(RIG *rig, vfo_t *vfo)
|
int alinco_get_vfo(RIG *rig, vfo_t *vfo)
|
||||||
{
|
{
|
||||||
char vfobuf[16];
|
char vfobuf[BUFSZ];
|
||||||
int vfo_len, retval;
|
int vfo_len, retval;
|
||||||
|
|
||||||
retval = alinco_transaction(rig, AL CMD_RMV EOM,
|
retval = alinco_transaction(rig, AL CMD_RMV EOM,
|
||||||
|
@ -195,7 +188,7 @@ int alinco_get_vfo(RIG *rig, vfo_t *vfo)
|
||||||
*/
|
*/
|
||||||
int alinco_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
int alinco_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
{
|
{
|
||||||
char freqbuf[16];
|
char freqbuf[BUFSZ];
|
||||||
int freq_len;
|
int freq_len;
|
||||||
|
|
||||||
/* max 10 digits */
|
/* max 10 digits */
|
||||||
|
@ -235,7 +228,7 @@ static int current_data_read(RIG *rig, char *databuf)
|
||||||
int alinco_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
int alinco_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
char freqbuf[32];
|
char freqbuf[BUFSZ];
|
||||||
|
|
||||||
retval = current_data_read(rig, freqbuf);
|
retval = current_data_read(rig, freqbuf);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -254,7 +247,7 @@ int alinco_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
*/
|
*/
|
||||||
int alinco_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
int alinco_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||||
{
|
{
|
||||||
char mdbuf[16];
|
char mdbuf[BUFSZ];
|
||||||
int mdbuf_len, narrow_filter, retval;
|
int mdbuf_len, narrow_filter, retval;
|
||||||
char amode;
|
char amode;
|
||||||
|
|
||||||
|
@ -301,7 +294,7 @@ int alinco_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
int settings;
|
int settings;
|
||||||
char modebuf[32];
|
char modebuf[BUFSZ];
|
||||||
|
|
||||||
retval = current_data_read(rig, modebuf);
|
retval = current_data_read(rig, modebuf);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -342,7 +335,7 @@ int alinco_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
int alinco_set_split(RIG *rig, vfo_t vfo, split_t split)
|
int alinco_set_split(RIG *rig, vfo_t vfo, split_t split)
|
||||||
{
|
{
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
char cmdbuf[32];
|
char cmdbuf[BUFSZ];
|
||||||
|
|
||||||
cmd_len = sprintf(cmdbuf, AL CMD_SPLT "%d" EOM,
|
cmd_len = sprintf(cmdbuf, AL CMD_SPLT "%d" EOM,
|
||||||
split==RIG_SPLIT_ON ? 1 : 0);
|
split==RIG_SPLIT_ON ? 1 : 0);
|
||||||
|
@ -357,7 +350,7 @@ int alinco_set_split(RIG *rig, vfo_t vfo, split_t split)
|
||||||
int alinco_get_split(RIG *rig, vfo_t vfo, split_t *split)
|
int alinco_get_split(RIG *rig, vfo_t vfo, split_t *split)
|
||||||
{
|
{
|
||||||
int splt_len, retval;
|
int splt_len, retval;
|
||||||
char spltbuf[32];
|
char spltbuf[BUFSZ];
|
||||||
|
|
||||||
retval = alinco_transaction (rig, AL CMD_RSPLT EOM,
|
retval = alinco_transaction (rig, AL CMD_RSPLT EOM,
|
||||||
strlen(AL CMD_RSPLT EOM), spltbuf, &splt_len);
|
strlen(AL CMD_RSPLT EOM), spltbuf, &splt_len);
|
||||||
|
@ -389,7 +382,7 @@ int alinco_get_split(RIG *rig, vfo_t vfo, split_t *split)
|
||||||
*/
|
*/
|
||||||
int alinco_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq)
|
int alinco_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq)
|
||||||
{
|
{
|
||||||
char freqbuf[16];
|
char freqbuf[BUFSZ];
|
||||||
int freq_len;
|
int freq_len;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -412,7 +405,7 @@ int alinco_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq)
|
||||||
int alinco_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq)
|
int alinco_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
char freqbuf[32];
|
char freqbuf[BUFSZ];
|
||||||
|
|
||||||
retval = current_data_read(rig, freqbuf);
|
retval = current_data_read(rig, freqbuf);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -433,7 +426,7 @@ int alinco_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq)
|
||||||
int alinco_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit)
|
int alinco_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit)
|
||||||
{
|
{
|
||||||
int rit_len, retval;
|
int rit_len, retval;
|
||||||
char ritbuf[32];
|
char ritbuf[BUFSZ];
|
||||||
|
|
||||||
/* read in Hertz unit */
|
/* read in Hertz unit */
|
||||||
retval = alinco_transaction (rig, AL CMD_RIT "0" EOM,
|
retval = alinco_transaction (rig, AL CMD_RIT "0" EOM,
|
||||||
|
@ -461,7 +454,7 @@ int alinco_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit)
|
||||||
int alinco_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
int alinco_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
||||||
{
|
{
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
char cmdbuf[32];
|
char cmdbuf[BUFSZ];
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
* sort the switch cases with the most frequent first
|
* sort the switch cases with the most frequent first
|
||||||
|
@ -504,7 +497,7 @@ int alinco_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
int settings;
|
int settings;
|
||||||
char funcbuf[32];
|
char funcbuf[BUFSZ];
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
* sort the switch cases with the most frequent first
|
* sort the switch cases with the most frequent first
|
||||||
|
@ -553,7 +546,7 @@ int alinco_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
||||||
int alinco_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
int alinco_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
||||||
{
|
{
|
||||||
int cmd_len, lvl;
|
int cmd_len, lvl;
|
||||||
char cmdbuf[32];
|
char cmdbuf[BUFSZ];
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
* sort the switch cases with the most frequent first
|
* sort the switch cases with the most frequent first
|
||||||
|
@ -606,7 +599,7 @@ int alinco_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
||||||
{
|
{
|
||||||
struct alinco_priv_caps *priv;
|
struct alinco_priv_caps *priv;
|
||||||
int retval, lvl_len;
|
int retval, lvl_len;
|
||||||
char lvlbuf[32];
|
char lvlbuf[BUFSZ];
|
||||||
|
|
||||||
priv = (struct alinco_priv_caps*)rig->caps->priv;
|
priv = (struct alinco_priv_caps*)rig->caps->priv;
|
||||||
|
|
||||||
|
@ -693,7 +686,7 @@ int alinco_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
||||||
int alinco_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
|
int alinco_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
|
||||||
{
|
{
|
||||||
const struct rig_caps *caps;
|
const struct rig_caps *caps;
|
||||||
unsigned char tonebuf[16];
|
unsigned char tonebuf[BUFSZ];
|
||||||
int tone_len;
|
int tone_len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -718,7 +711,7 @@ int alinco_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone)
|
||||||
*/
|
*/
|
||||||
int alinco_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
int alinco_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
||||||
{
|
{
|
||||||
char pttbuf[16];
|
char pttbuf[BUFSZ];
|
||||||
int ptt_len, retval;
|
int ptt_len, retval;
|
||||||
|
|
||||||
retval = alinco_transaction (rig, AL CMD_PTT EOM,
|
retval = alinco_transaction (rig, AL CMD_PTT EOM,
|
||||||
|
@ -752,7 +745,7 @@ int alinco_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt)
|
||||||
*/
|
*/
|
||||||
int alinco_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
int alinco_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
||||||
{
|
{
|
||||||
char dcdbuf[16];
|
char dcdbuf[BUFSZ];
|
||||||
int dcd_len, retval;
|
int dcd_len, retval;
|
||||||
|
|
||||||
retval = alinco_transaction (rig, AL CMD_SQL EOM,
|
retval = alinco_transaction (rig, AL CMD_SQL EOM,
|
||||||
|
@ -786,7 +779,7 @@ int alinco_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
||||||
*/
|
*/
|
||||||
int alinco_set_mem(RIG *rig, vfo_t vfo, int ch)
|
int alinco_set_mem(RIG *rig, vfo_t vfo, int ch)
|
||||||
{
|
{
|
||||||
char cmdbuf[16];
|
char cmdbuf[BUFSZ];
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
|
|
||||||
if (ch < 0 || ch > 99)
|
if (ch < 0 || ch > 99)
|
||||||
|
@ -803,7 +796,7 @@ int alinco_set_mem(RIG *rig, vfo_t vfo, int ch)
|
||||||
*/
|
*/
|
||||||
int alinco_get_mem(RIG *rig, vfo_t vfo, int *ch)
|
int alinco_get_mem(RIG *rig, vfo_t vfo, int *ch)
|
||||||
{
|
{
|
||||||
char membuf[16];
|
char membuf[BUFSZ];
|
||||||
int mem_len, retval;
|
int mem_len, retval;
|
||||||
|
|
||||||
retval = alinco_transaction (rig, AL CMD_RMEM EOM,
|
retval = alinco_transaction (rig, AL CMD_RMEM EOM,
|
||||||
|
|
51
aor/aor.c
51
aor/aor.c
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Hamlib AOR backend - main file
|
* Hamlib AOR backend - main file
|
||||||
* Copyright (c) 2000,2001,2002 by Stephane Fillod
|
* Copyright (c) 2000-2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: aor.c,v 1.19 2002-02-27 23:17:22 fillods Exp $
|
* $Id: aor.c,v 1.20 2002-03-13 23:37:12 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -47,7 +47,9 @@
|
||||||
* Is \r portable enough?
|
* Is \r portable enough?
|
||||||
*/
|
*/
|
||||||
#define CR '\r'
|
#define CR '\r'
|
||||||
#define EOM "\r"
|
#define EOM "\x0a"
|
||||||
|
|
||||||
|
#define BUFSZ 64
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* modes in use by the "MD" command
|
* modes in use by the "MD" command
|
||||||
|
@ -72,9 +74,8 @@
|
||||||
*/
|
*/
|
||||||
int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
||||||
{
|
{
|
||||||
int i, retval;
|
int retval;
|
||||||
struct rig_state *rs;
|
struct rig_state *rs;
|
||||||
char c;
|
|
||||||
|
|
||||||
rs = &rig->state;
|
rs = &rig->state;
|
||||||
|
|
||||||
|
@ -84,23 +85,11 @@ int aor_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/*
|
/* will flush data on next transaction */
|
||||||
* buffered read are quite helpful here!
|
if (!data || !data_len)
|
||||||
* However, an automate with a state model would be more efficient..
|
return RIG_OK;
|
||||||
*/
|
|
||||||
i = 0;
|
|
||||||
do {
|
|
||||||
retval = fread_block(&rs->rigport, &c, 1);
|
|
||||||
if (retval == 0)
|
|
||||||
continue; /* huh!? */
|
|
||||||
if (retval != RIG_OK)
|
|
||||||
return retval;
|
|
||||||
if (data)
|
|
||||||
data[i++] = c;
|
|
||||||
} while (c != CR);
|
|
||||||
|
|
||||||
if (data_len)
|
*data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
|
||||||
*data_len = i;
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -123,7 +112,7 @@ int aor_close(RIG *rig)
|
||||||
*/
|
*/
|
||||||
int aor_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
int aor_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
{
|
{
|
||||||
unsigned char freqbuf[16], ackbuf[16];
|
unsigned char freqbuf[BUFSZ], ackbuf[BUFSZ];
|
||||||
int freq_len, ack_len, retval;
|
int freq_len, ack_len, retval;
|
||||||
int lowhz;
|
int lowhz;
|
||||||
|
|
||||||
|
@ -158,7 +147,7 @@ int aor_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
{
|
{
|
||||||
char *rfp;
|
char *rfp;
|
||||||
int freq_len, retval;
|
int freq_len, retval;
|
||||||
unsigned char freqbuf[64];
|
unsigned char freqbuf[BUFSZ];
|
||||||
|
|
||||||
retval = aor_transaction (rig, "RX" EOM, 3, freqbuf, &freq_len);
|
retval = aor_transaction (rig, "RX" EOM, 3, freqbuf, &freq_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -198,7 +187,7 @@ int aor_set_vfo(RIG *rig, vfo_t vfo)
|
||||||
int aor_get_vfo(RIG *rig, vfo_t *vfo)
|
int aor_get_vfo(RIG *rig, vfo_t *vfo)
|
||||||
{
|
{
|
||||||
int vfo_len, retval;
|
int vfo_len, retval;
|
||||||
unsigned char vfobuf[64];
|
unsigned char vfobuf[BUFSZ];
|
||||||
|
|
||||||
retval = aor_transaction (rig, "RX" EOM, 3, vfobuf, &vfo_len);
|
retval = aor_transaction (rig, "RX" EOM, 3, vfobuf, &vfo_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -227,7 +216,7 @@ int aor_get_vfo(RIG *rig, vfo_t *vfo)
|
||||||
*/
|
*/
|
||||||
int aor_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
int aor_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||||
{
|
{
|
||||||
unsigned char mdbuf[16],ackbuf[16];
|
unsigned char mdbuf[BUFSZ],ackbuf[BUFSZ];
|
||||||
int mdbuf_len, ack_len, aormode, retval;
|
int mdbuf_len, ack_len, aormode, retval;
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
@ -280,7 +269,7 @@ int aor_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||||
*/
|
*/
|
||||||
int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
{
|
{
|
||||||
unsigned char ackbuf[16];
|
unsigned char ackbuf[BUFSZ];
|
||||||
int ack_len, retval;
|
int ack_len, retval;
|
||||||
|
|
||||||
|
|
||||||
|
@ -331,7 +320,7 @@ int aor_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
|
||||||
*/
|
*/
|
||||||
int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts)
|
int aor_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts)
|
||||||
{
|
{
|
||||||
unsigned char tsbuf[16],ackbuf[16];
|
unsigned char tsbuf[BUFSZ],ackbuf[BUFSZ];
|
||||||
int ts_len, ack_len;
|
int ts_len, ack_len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -364,7 +353,7 @@ int aor_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op)
|
||||||
{
|
{
|
||||||
char *aorcmd;
|
char *aorcmd;
|
||||||
int ack_len;
|
int ack_len;
|
||||||
char ackbuf[16];
|
char ackbuf[BUFSZ];
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case RIG_OP_UP: aorcmd = "\x1e" EOM; break;
|
case RIG_OP_UP: aorcmd = "\x1e" EOM; break;
|
||||||
|
@ -388,10 +377,10 @@ int aor_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op)
|
||||||
*/
|
*/
|
||||||
const char *aor_get_info(RIG *rig)
|
const char *aor_get_info(RIG *rig)
|
||||||
{
|
{
|
||||||
static char infobuf[16];
|
static char infobuf[BUFSZ];
|
||||||
int id_len, frm_len, retval;
|
int id_len, frm_len, retval;
|
||||||
char idbuf[4];
|
char idbuf[BUFSZ];
|
||||||
char frmbuf[16];
|
char frmbuf[BUFSZ];
|
||||||
|
|
||||||
retval = aor_transaction (rig, "\001" EOM, 2, idbuf, &id_len);
|
retval = aor_transaction (rig, "\001" EOM, 2, idbuf, &id_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
|
56
jrc/jrc.c
56
jrc/jrc.c
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib JRC backend - main file
|
* Hamlib JRC backend - main file
|
||||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: jrc.c,v 1.5 2002-02-27 23:25:41 fillods Exp $
|
* $Id: jrc.c,v 1.6 2002-03-13 23:37:12 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -46,6 +46,8 @@
|
||||||
*/
|
*/
|
||||||
#define EOM "\r"
|
#define EOM "\r"
|
||||||
|
|
||||||
|
#define BUFSZ 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* modes in use by the "2G" command
|
* modes in use by the "2G" command
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +71,7 @@
|
||||||
*/
|
*/
|
||||||
int jrc_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
int jrc_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
||||||
{
|
{
|
||||||
int i, count, retval;
|
int retval;
|
||||||
struct rig_state *rs;
|
struct rig_state *rs;
|
||||||
|
|
||||||
rs = &rig->state;
|
rs = &rig->state;
|
||||||
|
@ -83,20 +85,8 @@ int jrc_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
|
||||||
/* no data expected, TODO: flush input? */
|
/* no data expected, TODO: flush input? */
|
||||||
if (!data || !data_len)
|
if (!data || !data_len)
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
* buffered read are quite helpful here!
|
|
||||||
* However, an automate with a state model would be more efficient..
|
|
||||||
*/
|
|
||||||
i = 0;
|
|
||||||
do {
|
|
||||||
count = fread_block(&rs->rigport, data+i, 1);
|
|
||||||
if (count > 0)
|
|
||||||
i += count;
|
|
||||||
else if (count < 0)
|
|
||||||
return count;
|
|
||||||
} while (count > 0 && data[i-1] != EOM[0]);
|
|
||||||
|
|
||||||
*data_len = i;
|
*data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -129,7 +119,7 @@ int jrc_close(RIG *rig)
|
||||||
*/
|
*/
|
||||||
int jrc_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
int jrc_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
{
|
{
|
||||||
char freqbuf[16];
|
char freqbuf[BUFSZ];
|
||||||
int freq_len;
|
int freq_len;
|
||||||
|
|
||||||
/* max 10 digits */
|
/* max 10 digits */
|
||||||
|
@ -148,7 +138,7 @@ int jrc_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
int jrc_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
int jrc_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
{
|
{
|
||||||
int freq_len, retval;
|
int freq_len, retval;
|
||||||
char freqbuf[32];
|
char freqbuf[BUFSZ];
|
||||||
|
|
||||||
retval = jrc_transaction (rig, "F" EOM, 2, freqbuf, &freq_len);
|
retval = jrc_transaction (rig, "F" EOM, 2, freqbuf, &freq_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
|
@ -173,7 +163,7 @@ int jrc_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||||
*/
|
*/
|
||||||
int jrc_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
int jrc_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||||
{
|
{
|
||||||
char mdbuf[16];
|
char mdbuf[BUFSZ];
|
||||||
int retval, mdbuf_len;
|
int retval, mdbuf_len;
|
||||||
char amode;
|
char amode;
|
||||||
const char *bandwidth;
|
const char *bandwidth;
|
||||||
|
@ -223,7 +213,7 @@ int jrc_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
|
||||||
int jrc_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
int jrc_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
||||||
{
|
{
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
char cmdbuf[32];
|
char cmdbuf[BUFSZ];
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
* sort the switch cases with the most frequent first
|
* sort the switch cases with the most frequent first
|
||||||
|
@ -275,7 +265,7 @@ int jrc_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
|
||||||
int jrc_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
int jrc_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
||||||
{
|
{
|
||||||
int retval, func_len;
|
int retval, func_len;
|
||||||
char funcbuf[32];
|
char funcbuf[BUFSZ];
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
* sort the switch cases with the most frequent first
|
* sort the switch cases with the most frequent first
|
||||||
|
@ -372,7 +362,7 @@ int jrc_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
|
||||||
int jrc_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
int jrc_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
|
||||||
{
|
{
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
char cmdbuf[32];
|
char cmdbuf[BUFSZ];
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
* sort the switch cases with the most frequent first
|
* sort the switch cases with the most frequent first
|
||||||
|
@ -426,7 +416,7 @@ int jrc_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
||||||
{
|
{
|
||||||
struct jrc_priv_caps *priv;
|
struct jrc_priv_caps *priv;
|
||||||
int retval, lvl_len, lvl;
|
int retval, lvl_len, lvl;
|
||||||
char lvlbuf[32];
|
char lvlbuf[BUFSZ];
|
||||||
|
|
||||||
priv = (struct jrc_priv_caps*)rig->caps->priv;
|
priv = (struct jrc_priv_caps*)rig->caps->priv;
|
||||||
|
|
||||||
|
@ -551,7 +541,7 @@ int jrc_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
|
||||||
int jrc_set_parm(RIG *rig, setting_t parm, value_t val)
|
int jrc_set_parm(RIG *rig, setting_t parm, value_t val)
|
||||||
{
|
{
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
char cmdbuf[32];
|
char cmdbuf[BUFSZ];
|
||||||
int minutes;
|
int minutes;
|
||||||
|
|
||||||
/* Optimize:
|
/* Optimize:
|
||||||
|
@ -592,7 +582,7 @@ int jrc_get_parm(RIG *rig, setting_t parm, value_t *val)
|
||||||
{
|
{
|
||||||
struct jrc_priv_caps *priv;
|
struct jrc_priv_caps *priv;
|
||||||
int retval, lvl_len, i;
|
int retval, lvl_len, i;
|
||||||
char lvlbuf[32];
|
char lvlbuf[BUFSZ];
|
||||||
|
|
||||||
priv = (struct jrc_priv_caps*)rig->caps->priv;
|
priv = (struct jrc_priv_caps*)rig->caps->priv;
|
||||||
|
|
||||||
|
@ -635,7 +625,7 @@ int jrc_get_parm(RIG *rig, setting_t parm, value_t *val)
|
||||||
*/
|
*/
|
||||||
int jrc_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
int jrc_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
||||||
{
|
{
|
||||||
char dcdbuf[16];
|
char dcdbuf[BUFSZ];
|
||||||
int dcd_len, retval;
|
int dcd_len, retval;
|
||||||
|
|
||||||
retval = jrc_transaction (rig, "Q" EOM, 2, dcdbuf, &dcd_len);
|
retval = jrc_transaction (rig, "Q" EOM, 2, dcdbuf, &dcd_len);
|
||||||
|
@ -658,7 +648,7 @@ int jrc_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd)
|
||||||
*/
|
*/
|
||||||
int jrc_set_trn(RIG *rig, int trn)
|
int jrc_set_trn(RIG *rig, int trn)
|
||||||
{
|
{
|
||||||
unsigned char trnbuf[16];
|
unsigned char trnbuf[BUFSZ];
|
||||||
int trn_len;
|
int trn_len;
|
||||||
|
|
||||||
trn_len = sprintf(trnbuf, "I%d" EOM, trn==RIG_TRN_RIG?1:0);
|
trn_len = sprintf(trnbuf, "I%d" EOM, trn==RIG_TRN_RIG?1:0);
|
||||||
|
@ -672,7 +662,7 @@ int jrc_set_trn(RIG *rig, int trn)
|
||||||
*/
|
*/
|
||||||
int jrc_set_powerstat(RIG *rig, powerstat_t status)
|
int jrc_set_powerstat(RIG *rig, powerstat_t status)
|
||||||
{
|
{
|
||||||
unsigned char pwrbuf[16];
|
unsigned char pwrbuf[BUFSZ];
|
||||||
int pwr_len;
|
int pwr_len;
|
||||||
|
|
||||||
pwr_len = sprintf(pwrbuf, "T%d" EOM, status==RIG_POWER_ON?1:0);
|
pwr_len = sprintf(pwrbuf, "T%d" EOM, status==RIG_POWER_ON?1:0);
|
||||||
|
@ -686,7 +676,7 @@ int jrc_set_powerstat(RIG *rig, powerstat_t status)
|
||||||
*/
|
*/
|
||||||
int jrc_reset(RIG *rig, reset_t reset)
|
int jrc_reset(RIG *rig, reset_t reset)
|
||||||
{
|
{
|
||||||
unsigned char rstbuf[16];
|
unsigned char rstbuf[BUFSZ];
|
||||||
int rst_len;
|
int rst_len;
|
||||||
char rst;
|
char rst;
|
||||||
|
|
||||||
|
@ -710,8 +700,8 @@ int jrc_reset(RIG *rig, reset_t reset)
|
||||||
*/
|
*/
|
||||||
int jrc_set_mem(RIG *rig, vfo_t vfo, int ch)
|
int jrc_set_mem(RIG *rig, vfo_t vfo, int ch)
|
||||||
{
|
{
|
||||||
char cmdbuf[16];
|
char cmdbuf[BUFSZ];
|
||||||
char membuf[16];
|
char membuf[BUFSZ];
|
||||||
int cmd_len, mem_len;
|
int cmd_len, mem_len;
|
||||||
|
|
||||||
if (ch < 0 || ch > 999)
|
if (ch < 0 || ch > 999)
|
||||||
|
@ -826,7 +816,7 @@ int jrc_decode_event(RIG *rig)
|
||||||
rmode_t mode;
|
rmode_t mode;
|
||||||
pbwidth_t width;
|
pbwidth_t width;
|
||||||
int count;
|
int count;
|
||||||
char buf[32];
|
char buf[BUFSZ];
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "jrc: jrc_decode called\n");
|
rig_debug(RIG_DEBUG_VERBOSE, "jrc: jrc_decode called\n");
|
||||||
|
|
||||||
|
@ -835,9 +825,9 @@ int jrc_decode_event(RIG *rig)
|
||||||
/* "Iabdfg"CR */
|
/* "Iabdfg"CR */
|
||||||
#define SETUP_STATUS_LEN 17
|
#define SETUP_STATUS_LEN 17
|
||||||
|
|
||||||
count = fread_block(&rs->rigport, buf, SETUP_STATUS_LEN);
|
count = read_string(&rs->rigport, buf, SETUP_STATUS_LEN, "", 0);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
rig_debug(RIG_DEBUG_ERR, "jrc: fread_block failed: %s\n",
|
rig_debug(RIG_DEBUG_ERR, "jrc: read_string failed: %s\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -RIG_EIO;
|
return -RIG_EIO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Kachina backend - main file
|
* Hamlib Kachina backend - main file
|
||||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: kachina.c,v 1.3 2001-12-28 20:28:03 fillods Exp $
|
* $Id: kachina.c,v 1.4 2002-03-13 23:37:12 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -89,11 +89,13 @@ int kachina_transaction(RIG *rig, unsigned char cmd1, unsigned char cmd2)
|
||||||
buf4[2] = cmd2;
|
buf4[2] = cmd2;
|
||||||
buf4[3] = ETX;
|
buf4[3] = ETX;
|
||||||
|
|
||||||
|
serial_flush(&rs->rigport);
|
||||||
|
|
||||||
retval = write_block(&rs->rigport, buf4, 4);
|
retval = write_block(&rs->rigport, buf4, 4);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
count = fread_block(&rs->rigport, buf4, 1);
|
count = read_string(&rs->rigport, buf4, 1, "", 0);
|
||||||
if (count != 1)
|
if (count != 1)
|
||||||
return count;
|
return count;
|
||||||
|
|
||||||
|
@ -115,11 +117,13 @@ int kachina_trans_n(RIG *rig, unsigned char cmd1, const char *data, int data_len
|
||||||
|
|
||||||
cmd_len = data_len+3;
|
cmd_len = data_len+3;
|
||||||
|
|
||||||
|
serial_flush(&rs->rigport);
|
||||||
|
|
||||||
retval = write_block(&rs->rigport, buf, cmd_len);
|
retval = write_block(&rs->rigport, buf, cmd_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
count = fread_block(&rs->rigport, buf, 1);
|
count = read_string(&rs->rigport, buf, 1, "", 0);
|
||||||
if (count != 1)
|
if (count != 1)
|
||||||
return count;
|
return count;
|
||||||
|
|
||||||
|
|
19
pcr/pcr.c
19
pcr/pcr.c
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib PCR backend - main file
|
* Hamlib PCR backend - main file
|
||||||
* Copyright (c) 2001-2002 by Stephane Fillod
|
* Copyright (c) 2001-2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: pcr.c,v 1.12 2002-03-07 22:48:50 fillods Exp $
|
* $Id: pcr.c,v 1.13 2002-03-13 23:37:12 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -93,7 +93,7 @@ const int pcr1_ctcss_list[] = {
|
||||||
*/
|
*/
|
||||||
int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
||||||
{
|
{
|
||||||
int i, retval;
|
int retval;
|
||||||
struct rig_state *rs;
|
struct rig_state *rs;
|
||||||
|
|
||||||
rs = &rig->state;
|
rs = &rig->state;
|
||||||
|
@ -104,20 +104,7 @@ int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
/*
|
*data_len = read_string(&rs->rigport, data, *data_len, "\x0a", 1);
|
||||||
* buffered read are quite helpful here!
|
|
||||||
* However, an automate with a state model would be more efficient..
|
|
||||||
*/
|
|
||||||
i = 0;
|
|
||||||
do {
|
|
||||||
retval = fread_block(&rs->rigport, data+i, 1);
|
|
||||||
if (retval == 0)
|
|
||||||
continue; /* huh!? */
|
|
||||||
if (retval < 0)
|
|
||||||
return retval;
|
|
||||||
} while (i++ < *data_len || data[i-1] != '\x0a');
|
|
||||||
|
|
||||||
*data_len = i; /* useless ? */
|
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Tentec backend - main file
|
* Hamlib Tentec backend - main file
|
||||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: tentec.c,v 1.4 2002-01-06 17:49:55 fillods Exp $
|
* $Id: tentec.c,v 1.5 2002-03-13 23:37:13 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -67,7 +67,7 @@ static int tentec_filters[] = {
|
||||||
*/
|
*/
|
||||||
int tentec_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
int tentec_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
||||||
{
|
{
|
||||||
int i, count, retval;
|
int retval;
|
||||||
struct rig_state *rs;
|
struct rig_state *rs;
|
||||||
|
|
||||||
rs = &rig->state;
|
rs = &rig->state;
|
||||||
|
@ -81,23 +81,8 @@ int tentec_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
|
||||||
/* no data expected, TODO: flush input? */
|
/* no data expected, TODO: flush input? */
|
||||||
if (!data || !data_len)
|
if (!data || !data_len)
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
* buffered read are quite helpful here!
|
|
||||||
* However, an automate with a state model would be more efficient..
|
|
||||||
*
|
|
||||||
* FIXME:
|
|
||||||
* and BTW, this is currently helpless since length of response may vary
|
|
||||||
*/
|
|
||||||
i = 0;
|
|
||||||
do {
|
|
||||||
count = fread_block(&rs->rigport, data+i, 1);
|
|
||||||
if (count > 0)
|
|
||||||
i += count;
|
|
||||||
else if (count < 0)
|
|
||||||
return count;
|
|
||||||
} while (i < *data_len);
|
|
||||||
|
|
||||||
*data_len = i;
|
*data_len = read_string(&rs->rigport, data, *data_len, "", 0);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -159,9 +144,7 @@ int tentec_cleanup(RIG *rig)
|
||||||
*/
|
*/
|
||||||
int tentec_trx_open(RIG *rig)
|
int tentec_trx_open(RIG *rig)
|
||||||
{
|
{
|
||||||
struct rig_state *rs = &rig->state;
|
int retval;
|
||||||
int ack_len, retval;
|
|
||||||
char ack[16];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* be kind: use XX first, and do 'Dsp Program Execute' only
|
* be kind: use XX first, and do 'Dsp Program Execute' only
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* Hamlib Uniden backend - main file
|
* Hamlib Uniden backend - main file
|
||||||
* Copyright (c) 2001,2002 by Stephane Fillod
|
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: uniden.c,v 1.3 2001-12-28 20:28:04 fillods Exp $
|
* $Id: uniden.c,v 1.4 2002-03-13 23:37:13 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -52,6 +52,7 @@
|
||||||
|
|
||||||
#define EOM "\r"
|
#define EOM "\r"
|
||||||
|
|
||||||
|
#define BUFSZ 32
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* uniden_transaction
|
* uniden_transaction
|
||||||
|
@ -60,11 +61,13 @@
|
||||||
*/
|
*/
|
||||||
int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
|
||||||
{
|
{
|
||||||
int i, count, retval;
|
int retval;
|
||||||
struct rig_state *rs;
|
struct rig_state *rs;
|
||||||
|
|
||||||
rs = &rig->state;
|
rs = &rig->state;
|
||||||
|
|
||||||
|
serial_flush(&rs->rigport);
|
||||||
|
|
||||||
retval = write_block(&rs->rigport, cmd, cmd_len);
|
retval = write_block(&rs->rigport, cmd, cmd_len);
|
||||||
if (retval != RIG_OK)
|
if (retval != RIG_OK)
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -73,22 +76,8 @@ int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
|
||||||
/* no data expected, TODO: flush input? */
|
/* no data expected, TODO: flush input? */
|
||||||
if (!data || !data_len)
|
if (!data || !data_len)
|
||||||
return 0;
|
return 0;
|
||||||
/*
|
|
||||||
* buffered read are quite helpful here!
|
|
||||||
* However, an automate with a state model would be more efficient..
|
|
||||||
*
|
|
||||||
* FIXME: should read until CR or LF?
|
|
||||||
*/
|
|
||||||
i = 0;
|
|
||||||
do {
|
|
||||||
count = fread_block(&rs->rigport, data+i, 1);
|
|
||||||
if (count > 0)
|
|
||||||
i += count;
|
|
||||||
else if (count < 0)
|
|
||||||
return count;
|
|
||||||
} while (count > 0);
|
|
||||||
|
|
||||||
*data_len = i;
|
*data_len = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +88,7 @@ int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
|
||||||
*/
|
*/
|
||||||
int uniden_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
int uniden_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
{
|
{
|
||||||
char freqbuf[16];
|
char freqbuf[BUFSZ];
|
||||||
int freq_len;
|
int freq_len;
|
||||||
|
|
||||||
/* max 8 digits */
|
/* max 8 digits */
|
||||||
|
@ -118,7 +107,7 @@ int uniden_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
|
||||||
*/
|
*/
|
||||||
int uniden_set_mem(RIG *rig, vfo_t vfo, int ch)
|
int uniden_set_mem(RIG *rig, vfo_t vfo, int ch)
|
||||||
{
|
{
|
||||||
char cmdbuf[16];
|
char cmdbuf[BUFSZ];
|
||||||
int cmd_len;
|
int cmd_len;
|
||||||
|
|
||||||
cmd_len = sprintf(cmdbuf, "MA%03d" EOM, ch);
|
cmd_len = sprintf(cmdbuf, "MA%03d" EOM, ch);
|
||||||
|
|
Ładowanie…
Reference in New Issue