kopia lustrzana https://github.com/Hamlib/Hamlib
Change anytone.c to use bluetooth protocol
Update some things to keep debug quiet during thread operations in anytone.cpull/1330/head
rodzic
e1e570d19a
commit
eb97c7c107
|
@ -2681,6 +2681,136 @@ struct rig_state {
|
|||
int spectrum_attenuator[HAMLIB_MAXDBLSTSIZ]; /*!< Spectrum attenuator list in dB, 0 terminated */
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Deprecated Rig state containing live data and customized fields.
|
||||
* Due to DLL problems this remains in-place in the rig_caps structure but is no longer referred to
|
||||
* A new rig_state has been added at the end of the structure instead of the middle
|
||||
*
|
||||
* This struct contains no data and is just a place holder for DLL alignment
|
||||
*
|
||||
* It is NOT fine to touch this struct AT ALL!!!
|
||||
*/
|
||||
struct rig_state_deprecated {
|
||||
/********* DO NOT MODIFY OR REMOVE THIS STRUCTURE -- IT IS FOREVER DEPRECATED *********/
|
||||
/*
|
||||
* overridable fields
|
||||
*/
|
||||
// moving the hamlib_port_t to the end of rig_state and making it a pointer
|
||||
// this should allow changes to hamlib_port_t without breaking shared libraries
|
||||
// these will maintain a copy of the new port_t for backwards compatibility
|
||||
// to these offsets -- note these must stay until a major version update is done like 5.0
|
||||
hamlib_port_t_deprecated rigport_deprecated; /*!< Rig port (internal use). */
|
||||
hamlib_port_t_deprecated pttport_deprecated; /*!< PTT port (internal use). */
|
||||
hamlib_port_t_deprecated dcdport_deprecated; /*!< DCD port (internal use). */
|
||||
|
||||
double vfo_comp; /*!< VFO compensation in PPM, 0.0 to disable */
|
||||
|
||||
int deprecated_itu_region; /*!< ITU region to select among freq_range_t */
|
||||
freq_range_t rx_range_list[HAMLIB_FRQRANGESIZ]; /*!< Receive frequency range list */
|
||||
freq_range_t tx_range_list[HAMLIB_FRQRANGESIZ]; /*!< Transmit frequency range list */
|
||||
|
||||
struct tuning_step_list tuning_steps[HAMLIB_TSLSTSIZ]; /*!< Tuning step list */
|
||||
|
||||
struct filter_list filters[HAMLIB_FLTLSTSIZ]; /*!< Mode/filter table, at -6dB */
|
||||
|
||||
cal_table_t str_cal; /*!< S-meter calibration table */
|
||||
|
||||
chan_t chan_list[HAMLIB_CHANLSTSIZ]; /*!< Channel list, zero ended */
|
||||
|
||||
shortfreq_t max_rit; /*!< max absolute RIT */
|
||||
shortfreq_t max_xit; /*!< max absolute XIT */
|
||||
shortfreq_t max_ifshift; /*!< max absolute IF-SHIFT */
|
||||
|
||||
ann_t announces; /*!< Announces bit field list */
|
||||
|
||||
int preamp[HAMLIB_MAXDBLSTSIZ]; /*!< Preamp list in dB, 0 terminated */
|
||||
int attenuator[HAMLIB_MAXDBLSTSIZ]; /*!< Preamp list in dB, 0 terminated */
|
||||
|
||||
setting_t has_get_func; /*!< List of get functions */
|
||||
setting_t has_set_func; /*!< List of set functions */
|
||||
setting_t has_get_level; /*!< List of get level */
|
||||
setting_t has_set_level; /*!< List of set level */
|
||||
setting_t has_get_parm; /*!< List of get parm */
|
||||
setting_t has_set_parm; /*!< List of set parm */
|
||||
|
||||
gran_t level_gran[RIG_SETTING_MAX]; /*!< level granularity */
|
||||
gran_t parm_gran[RIG_SETTING_MAX]; /*!< parm granularity */
|
||||
|
||||
|
||||
/*
|
||||
* non overridable fields, internal use
|
||||
*/
|
||||
|
||||
int transaction_active; /*!< set to 1 to inform the async reader thread that a synchronous command transaction is waiting for a response, otherwise 0 */
|
||||
vfo_t current_vfo; /*!< VFO currently set */
|
||||
int vfo_list; /*!< Complete list of VFO for this rig */
|
||||
int comm_state; /*!< Comm port state, opened/closed. */
|
||||
rig_ptr_t priv; /*!< Pointer to private rig state data. */
|
||||
rig_ptr_t obj; /*!< Internal use by hamlib++ for event handling. */
|
||||
|
||||
int async_data_enabled; /*!< Whether async data mode is enabled */
|
||||
int poll_interval; /*!< Rig state polling period in milliseconds */
|
||||
freq_t current_freq; /*!< Frequency currently set */
|
||||
rmode_t current_mode; /*!< Mode currently set */
|
||||
//rmode_t current_modeB; /*!< Mode currently set VFOB */
|
||||
pbwidth_t current_width; /*!< Passband width currently set */
|
||||
vfo_t tx_vfo; /*!< Tx VFO currently set */
|
||||
rmode_t mode_list; /*!< Complete list of modes for this rig */
|
||||
// mode_list is used by some
|
||||
// so anything added to this structure must be below here
|
||||
int transmit; /*!< rig should be transmitting i.e. hard
|
||||
wired PTT asserted - used by rigs that
|
||||
don't do CAT while in Tx */
|
||||
freq_t lo_freq; /*!< Local oscillator frequency of any transverter */
|
||||
time_t twiddle_time; /*!< time when vfo twiddling was detected */
|
||||
int twiddle_timeout; /*!< timeout to resume from twiddling */
|
||||
// uplink allows gpredict to behave better by no reading the uplink VFO
|
||||
int uplink; /*!< uplink=1 will not read Sub, uplink=2 will not read Main */
|
||||
struct rig_cache cache;
|
||||
int vfo_opt; /*!< Is -o switch turned on? */
|
||||
int auto_power_on; /*!< Allow Hamlib to power on rig
|
||||
automatically if supported */
|
||||
int auto_power_off; /*!< Allow Hamlib to power off rig
|
||||
automatically if supported */
|
||||
int auto_disable_screensaver; /*!< Allow Hamlib to disable the
|
||||
rig's screen saver automatically if
|
||||
supported */
|
||||
int ptt_share; /*!< Share ptt port by open/close during get_ptt, set_ptt hogs the port while active */
|
||||
int power_now; /*!< Current RF power level in rig units */
|
||||
int power_min; /*!< Minimum RF power level in rig units */
|
||||
int power_max; /*!< Maximum RF power level in rig units */
|
||||
unsigned char disable_yaesu_bandselect; /*!< Disables Yaesu band select logic */
|
||||
int twiddle_rit; /*!< Suppresses VFOB reading (cached value used) so RIT control can be used */
|
||||
int twiddle_state; /*!< keeps track of twiddle status */
|
||||
vfo_t rx_vfo; /*!< Rx VFO currently set */
|
||||
|
||||
volatile unsigned int snapshot_packet_sequence_number;
|
||||
|
||||
volatile int multicast_publisher_run;
|
||||
void *multicast_publisher_priv_data;
|
||||
volatile int async_data_handler_thread_run;
|
||||
void *async_data_handler_priv_data;
|
||||
volatile int poll_routine_thread_run;
|
||||
void *poll_routine_priv_data;
|
||||
pthread_mutex_t mutex_set_transaction;
|
||||
hamlib_port_t rigport; /*!< Rig port (internal use). */
|
||||
hamlib_port_t pttport; /*!< PTT port (internal use). */
|
||||
hamlib_port_t dcdport; /*!< DCD port (internal use). */
|
||||
/********* DO NOT ADD or CHANGE anything (or than to rename) ABOVE THIS LINE *********/
|
||||
/********* ENSURE ANY NEW ITEMS ARE ADDED AFTER HERE *********/
|
||||
/* flags instructing the rig_get routines to use cached values when asyncio is in use */
|
||||
int use_cached_freq; /*!< flag instructing rig_get_freq to use cached values when asyncio is in use */
|
||||
int use_cached_mode; /*!< flag instructing rig_get_mode to use cached values when asyncio is in use */
|
||||
int use_cached_ptt; /*!< flag instructing rig_get_ptt to use cached values when asyncio is in use */
|
||||
int depth; /*!< a depth counter to use for debug indentation and such */
|
||||
int lock_mode; /*!< flag that prevents mode changes if ~= 0 -- see set/get_lock_mode */
|
||||
powerstat_t powerstat; /*!< power status */
|
||||
char *tuner_control_pathname; /*!< Path to external tuner control program that get 0/1 (Off/On) argument */
|
||||
char client_version[32]; /*!<! Allow client to report version for compatibility checks/capability */
|
||||
freq_t offset_vfoa; /*!< Offset to apply to VFOA/Main set_freq */
|
||||
freq_t offset_vfob; /*!< Offset to apply to VFOB/Sub set_freq */
|
||||
};
|
||||
|
||||
//! @cond Doxygen_Suppress
|
||||
typedef int (*vprintf_cb_t)(enum rig_debug_level_e,
|
||||
rig_ptr_t,
|
||||
|
@ -2750,8 +2880,10 @@ struct rig_callbacks {
|
|||
*/
|
||||
struct s_rig {
|
||||
struct rig_caps *caps; /*!< Pointer to rig capabilities (read only) */
|
||||
struct rig_state state; /*!< Rig state */
|
||||
// Do not remove the deprecated structure -- it will mess up DLL backwards compatibility
|
||||
struct rig_state_deprecated state_deprecated; /*!< Deprecated Rig state */
|
||||
struct rig_callbacks callbacks; /*!< registered event callbacks */
|
||||
struct rig_state state; /*!< Rig state */
|
||||
};
|
||||
|
||||
|
||||
|
@ -3377,6 +3509,9 @@ rig_idx2setting(int i);
|
|||
extern HAMLIB_EXPORT(void)
|
||||
rig_set_debug HAMLIB_PARAMS((enum rig_debug_level_e debug_level));
|
||||
|
||||
extern HAMLIB_EXPORT(void)
|
||||
rig_get_debug HAMLIB_PARAMS((enum rig_debug_level_e *debug_level));
|
||||
|
||||
extern HAMLIB_EXPORT(void)
|
||||
rig_set_debug_time_stamp HAMLIB_PARAMS((int flag));
|
||||
|
||||
|
|
|
@ -120,18 +120,28 @@ void *anytone_thread(void *vrig)
|
|||
rig_debug(RIG_DEBUG_TRACE, "%s: anytone_thread started\n", __func__);
|
||||
p->runflag = 1;
|
||||
|
||||
// if we don't have CACHE debug enabled then we only show WARN and higher for this rig
|
||||
if (rig_need_debug(RIG_DEBUG_CACHE) == 0)
|
||||
{
|
||||
rig_set_debug(RIG_DEBUG_WARN); // only show WARN debug otherwise too verbose
|
||||
}
|
||||
|
||||
while (p->runflag)
|
||||
{
|
||||
char c = 0x06;
|
||||
// char c [] = { 0x2b, 0x41, 0x44, 0x41, 0x54, 0x41, 0x3a, 0x30, 0x30, 0x2c, 0x30, 0x30, 0x31, 0x0d, 0x0a, 0x61, 0x0d, 0x0a };
|
||||
char *c = "+ADATA:00,001\r\na\r\n";
|
||||
MUTEX_LOCK(p->priv.mutex);
|
||||
write_block(&rig->state.rigport, (unsigned char *)&c, 1);
|
||||
// if we don't have CACHE debug enabled then we only show WARN and higher for this rig
|
||||
enum rig_debug_level_e debug_level_save;
|
||||
rig_get_debug(&debug_level_save);
|
||||
|
||||
if (rig_need_debug(RIG_DEBUG_CACHE) == 0)
|
||||
{
|
||||
rig_set_debug(RIG_DEBUG_WARN); // only show WARN debug otherwise too verbose
|
||||
}
|
||||
|
||||
write_block(&rig->state.rigport, (unsigned char *)c, strlen(c));
|
||||
hl_usleep(100 * 1000);
|
||||
|
||||
if (rig_need_debug(RIG_DEBUG_CACHE) == 0)
|
||||
{
|
||||
rig_set_debug(debug_level_save);
|
||||
}
|
||||
|
||||
rig_flush(&rig->state.rigport);
|
||||
MUTEX_UNLOCK(p->priv.mutex);
|
||||
hl_usleep(1000 * 1000); // 1-second loop
|
||||
|
@ -246,7 +256,7 @@ int anytone_init(RIG *rig)
|
|||
rig->state.priv = p;
|
||||
p->vfo_curr = RIG_VFO_NONE;
|
||||
#ifdef HAVE_PTHREAD
|
||||
// pthread_mutex_init(&p->mutex, NULL);
|
||||
pthread_mutex_init(&p->mutex, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -301,8 +311,8 @@ int anytone_open(RIG *rig)
|
|||
// can we ask for any information? Maybe just toggle A/B?
|
||||
}
|
||||
|
||||
#if 0
|
||||
pthread_t id;
|
||||
// will start the keep alive
|
||||
int err = pthread_create(&id, NULL, anytone_thread, (void *)rig);
|
||||
|
||||
if (err)
|
||||
|
@ -311,7 +321,12 @@ int anytone_open(RIG *rig)
|
|||
strerror(errno));
|
||||
RETURNFUNC(-RIG_EINTERNAL);
|
||||
}
|
||||
#endif
|
||||
|
||||
hl_usleep(500 * 1000);
|
||||
char *cmd = "+ADATA:00,016\r\n";
|
||||
|
||||
anytone_transaction(rig, cmd, strlen(cmd), 21);
|
||||
|
||||
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
|
@ -324,6 +339,8 @@ int anytone_close(RIG *rig)
|
|||
int retval = RIG_OK;
|
||||
|
||||
ENTERFUNC;
|
||||
char *cmd = "+ADATA:00,000\r\n";
|
||||
anytone_transaction(rig, cmd, strlen(cmd), 0);
|
||||
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
|
@ -452,12 +469,13 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
|
|||
}
|
||||
else
|
||||
{
|
||||
char buf[8] = { 0x41, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x06 };
|
||||
//char buf[8] = { 0x41, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x06 };
|
||||
char *cmd = "+ADATA:00,001\r\na\r\n";
|
||||
|
||||
if (!ptt) { buf[1] = 0x01; }
|
||||
if (!ptt) { cmd = "+ADATA:00,023\r\nV\r\n"; }
|
||||
|
||||
MUTEX_LOCK(p->mutex);
|
||||
anytone_transaction(rig, buf, 8, 1);
|
||||
anytone_transaction(rig, cmd, strlen(cmd), 1);
|
||||
anytone_priv_data_t *p = rig->state.priv;
|
||||
p->ptt = ptt;
|
||||
MUTEX_UNLOCK(p->mutex);
|
||||
|
@ -466,6 +484,50 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
|
|||
RETURNFUNC(retval);
|
||||
}
|
||||
|
||||
int anytone_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
|
||||
{
|
||||
char cmd[32];
|
||||
|
||||
if (vfo == RIG_VFO_A)
|
||||
{
|
||||
SNPRINTF(cmd, sizeof(cmd), "+ADATA:00,119\r\n");
|
||||
cmd[15] = 0x04;
|
||||
cmd[16] = 0x2c;
|
||||
cmd[17] = 0x07;
|
||||
cmd[18] = 0x00;
|
||||
cmd[19] = 0x00;
|
||||
cmd[21] = 0x00;
|
||||
cmd[22] = 0x00;
|
||||
cmd[23] = 0x0d;
|
||||
cmd[24] = 0x0a;
|
||||
}
|
||||
else
|
||||
{
|
||||
SNPRINTF(cmd, sizeof(cmd), "+ADATA:00,006\r\n");
|
||||
cmd[15] = 0x04;
|
||||
cmd[16] = 0x2d;
|
||||
cmd[17] = 0x07;
|
||||
cmd[18] = 0x00;
|
||||
cmd[19] = 0x00;
|
||||
cmd[21] = 0x00;
|
||||
cmd[22] = 0x00;
|
||||
cmd[23] = 0x0d;
|
||||
cmd[24] = 0x0a;
|
||||
}
|
||||
|
||||
write_block(&rig->state.rigport, (unsigned char *)cmd, 25);
|
||||
unsigned char buf[64];
|
||||
int retval = read_block(&rig->state.rigport, buf, 135);
|
||||
|
||||
if (retval == 135)
|
||||
{
|
||||
*freq = buf[17] * 10e7 + buf[18] * 10e5 + buf[19] * 10e3 + buf[20] * 10e1;
|
||||
retval = RIG_OK;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// END OF FILE
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -42,4 +42,6 @@ extern int anytone_get_ptt(RIG *rig, vfo_t vfo,ptt_t *ptt);
|
|||
extern int anytone_set_vfo(RIG *rig, vfo_t vfo);
|
||||
extern int anytone_get_vfo(RIG *rig, vfo_t *vfo);
|
||||
|
||||
extern int anytone_get_freq(RIG *rig, vfo_t vfo, freq_t *freq);
|
||||
|
||||
#endif /* _ANYTONE_H */
|
||||
|
|
|
@ -84,6 +84,8 @@ const struct rig_caps anytone_d578_caps =
|
|||
.get_ptt = anytone_get_ptt,
|
||||
.set_ptt = anytone_set_ptt,
|
||||
|
||||
.get_freq = anytone_get_freq,
|
||||
|
||||
.hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
|
||||
};
|
||||
|
||||
|
|
|
@ -36,22 +36,23 @@ getmyline(int fd, unsigned char *buf)
|
|||
int n = 0;
|
||||
memset(buf, 0, BUFSIZE);
|
||||
|
||||
// seemd the anytone only gives 8-byte commands and 1-byte responses
|
||||
while (i < 8 && read(fd, &c, 1) > 0)
|
||||
// seems the anytone only gives 8-byte commands and 1-byte responses
|
||||
do
|
||||
{
|
||||
if (i == 0 && c == 0x06)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
else
|
||||
int bytes = read(fd, &c, 1);
|
||||
if (bytes > 0)
|
||||
{
|
||||
buf[i++] = c;
|
||||
n++;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
while (c != 0x0a);
|
||||
|
||||
printf("n=%d %02x %02x %02x %02x %02x %02x %02x %02x\n", n, buf[0], buf[1],
|
||||
buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
|
||||
printf("n=%d \n", n);
|
||||
|
||||
for (i = 0; i < n; ++i) { printf("%02x ", buf[i]); }
|
||||
|
||||
printf("\n");
|
||||
return n;
|
||||
}
|
||||
|
||||
|
|
13
src/debug.c
13
src/debug.c
|
@ -149,6 +149,19 @@ void HAMLIB_API rig_set_debug(enum rig_debug_level_e debug_level)
|
|||
rig_debug_level = debug_level;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get the current debug level.
|
||||
*
|
||||
* \param debug_level Equivalent to the `-v` option of the utilities.
|
||||
*
|
||||
* Allows for obtaining the current debug level
|
||||
*
|
||||
*/
|
||||
void HAMLIB_API rig_get_debug(enum rig_debug_level_e *debug_level)
|
||||
{
|
||||
*debug_level = rig_debug_level;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Test if a given debug level is active.
|
||||
|
|
|
@ -2188,8 +2188,8 @@ int HAMLIB_API rig_flush_force(hamlib_port_t *port, int flush_async_data)
|
|||
}
|
||||
|
||||
#ifndef RIG_FLUSH_REMOVE
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: called for %s device\n", __func__,
|
||||
port->type.rig == RIG_PORT_SERIAL ? "serial" : "network");
|
||||
// rig_debug(RIG_DEBUG_TRACE, "%s: called for %s device\n", __func__,
|
||||
// port->type.rig == RIG_PORT_SERIAL ? "serial" : "network");
|
||||
|
||||
if (port->type.rig == RIG_PORT_NETWORK
|
||||
|| port->type.rig == RIG_PORT_UDP_NETWORK)
|
||||
|
|
|
@ -799,7 +799,7 @@ int HAMLIB_API serial_flush(hamlib_port_t *p)
|
|||
p->timeout = timeout_save;
|
||||
p->timeout_retry = timeout_retry_save;
|
||||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", "");
|
||||
// rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", "");
|
||||
// we also do this flush https://github.com/Hamlib/Hamlib/issues/1241
|
||||
tcflush(p->fd,TCIFLUSH);
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue