[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. 07a9f321b4a3a337df306
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: n0nb <n0...@us...> - 2023-05-29 11:42:13
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via 07a9f321b4a3a337df306b4b6184435040174eae (commit) from f37c24d0525dd81449c854183c256b335f123991 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 07a9f321b4a3a337df306b4b6184435040174eae Author: Mike Black W9MDB <mdb...@ya...> Date: Sun May 28 16:38:27 2023 -0500 Fix anytone set/get VFO https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index b91dcd651..1aed8db46 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -93,13 +93,6 @@ DECLARE_PROBERIG_BACKEND(anytone) memset(acBuf, 0, ANYTONE_RESPSZ + 1); -#if 0 - retval = write_block(port, - (unsigned char *)ADAT_CMD_DEF_STRING_GET_ID_CODE, - strlen(ADAT_CMD_DEF_STRING_GET_ID_CODE)); - nRead = read_string(port, (unsigned char *) acBuf, ANYTONE_RESPSZ, - ADAT_EOM, 1, 0, 1); -#endif close(port->fd); if ((retval != RIG_OK || nRead < 0)) @@ -205,12 +198,14 @@ int anytone_transaction(RIG *rig, char *cmd, int cmd_len, int expected_len) if (retval == RIG_OK && expected_len != 0) { - char buf[16]; - anytone_receive(rig, buf, sizeof(buf), 1); - if (buf[0] == 0xaa && buf[1] == 0x53) + char *buf = calloc(64,1); + int len = anytone_receive(rig, buf, 64, expected_len); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): rx len=%d\n", __func__, __LINE__, len); + if ( len == 16 && buf[0] == 0xaa && buf[1] == 0x53) { p->vfo_curr = buf[8] == 0x00 ? RIG_VFO_A : RIG_VFO_B; } + free(buf); } MUTEX_LOCK(p->mutex); @@ -231,19 +226,18 @@ int anytone_init(RIG *rig) if (rig != NULL) { - anytone_priv_data_ptr pPriv = NULL; + anytone_priv_data_ptr p = NULL; // Get new Priv Data - pPriv = calloc(1, sizeof(anytone_priv_data_t)); + p = calloc(1, sizeof(anytone_priv_data_t)); - if (pPriv == NULL) + if (p == NULL) { retval = -RIG_ENOMEM; } - rig->state.priv = pPriv; - anytone_priv_data_t *p = rig->state.priv; + rig->state.priv = p; p->vfo_curr = RIG_VFO_NONE; #ifdef HAVE_PTHREAD pthread_mutex_init(&p->mutex, NULL); @@ -301,6 +295,7 @@ int anytone_open(RIG *rig) // can we ask for any information? Maybe just toggle A/B? } +#if 0 pthread_t id; int err = pthread_create(&id, NULL, anytone_thread, (void *)rig); @@ -310,6 +305,7 @@ int anytone_open(RIG *rig) strerror(errno)); RETURNFUNC(-RIG_EINTERNAL); } +#endif RETURNFUNC(retval); @@ -321,21 +317,8 @@ int anytone_open(RIG *rig) int anytone_close(RIG *rig) { int retval = RIG_OK; -#if 0 - anytone_priv_data_ptr pPriv = (anytone_priv_data_ptr) rig->state.priv; - - if (pPriv->pcCmd != NULL) { free(pPriv->pcCmd); } - - if (pPriv->pcResult != NULL) { free(pPriv->pcResult); } - -#endif ENTERFUNC; -#if 0 - // Now switch to interactive mode - - retval = anytone_transaction(rig, &anytone_cmd_list_close_adat); -#endif RETURNFUNC(retval); } @@ -356,9 +339,15 @@ int anytone_get_vfo(RIG *rig, vfo_t *vfo) } else { - anytone_priv_data_ptr pPriv = (anytone_priv_data_ptr) rig->state.priv; + anytone_priv_data_ptr p = (anytone_priv_data_ptr) rig->state.priv; + if (p->vfo_curr == RIG_VFO_NONE) // then we need to find out what our current VFO is + { + // only way we know to do this is switch VFOS twice so we can get the reply + anytone_set_vfo(rig, RIG_VFO_B); // it's just toggle right now so VFO doesn't really matter + anytone_set_vfo(rig, RIG_VFO_A); + } - *vfo = pPriv->vfo_curr; + *vfo = p->vfo_curr; } RETURNFUNC(retval); @@ -370,6 +359,7 @@ int anytone_get_vfo(RIG *rig, vfo_t *vfo) int anytone_set_vfo(RIG *rig, vfo_t vfo) { int retval = RIG_OK; + anytone_priv_data_t *p = rig->state.priv; ENTERFUNC; // Check Params @@ -387,7 +377,13 @@ int anytone_set_vfo(RIG *rig, vfo_t vfo) char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x06 }; anytone_transaction(rig, buf1, 8, 0); hl_usleep(100 * 1000); - anytone_transaction(rig, buf2, 8, 15); + anytone_transaction(rig, buf2, 8, 0); + // we expect 16 bytes coming back + unsigned char reply[16]; + int nbytes = read_block(&rig->state.rigport, reply, 16); + rig_debug(RIG_DEBUG_ERR, "%s(%d): nbytes=%d\n", __func__, __LINE__, nbytes); + if (reply[8] == 0x00) p->vfo_curr = RIG_VFO_A; + else p->vfo_curr = RIG_VFO_B; } else { @@ -395,7 +391,12 @@ int anytone_set_vfo(RIG *rig, vfo_t vfo) char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x06 }; anytone_transaction(rig, buf1, 8, 0); hl_usleep(100 * 1000); - anytone_transaction(rig, buf2, 8, 15); + anytone_transaction(rig, buf2, 8, 0); + unsigned char reply[16]; + int nbytes = read_block(&rig->state.rigport, reply, 16); + rig_debug(RIG_DEBUG_ERR, "%s(%d): nbytes=%d\n", __func__, __LINE__, nbytes); + if (reply[8] == 0x00) p->vfo_curr = RIG_VFO_A; + else p->vfo_curr = RIG_VFO_B; } } @@ -419,6 +420,8 @@ int anytone_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) } else { + anytone_priv_data_t *p = rig->state.priv; + *ptt = p->ptt; } return retval; @@ -443,6 +446,8 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) if (ptt) { buf[1] = 0x01; } anytone_transaction(rig, buf, 8, 1); + anytone_priv_data_t *p = rig->state.priv; + p->ptt = ptt; } RETURNFUNC(retval); diff --git a/rigs/anytone/anytone.h b/rigs/anytone/anytone.h index 2388f3c54..70cee0aca 100644 --- a/rigs/anytone/anytone.h +++ b/rigs/anytone/anytone.h @@ -3,7 +3,7 @@ #include "hamlib/rig.h" -#define BACKEND_VER "20230527" +#define BACKEND_VER "20230528" #define ANYTONE_RESPSZ 64 @@ -22,9 +22,10 @@ extern const struct rig_caps anytone_d578_caps; typedef struct _anytone_priv_data { - int ptt; + ptt_t ptt; vfo_t vfo_curr; int runflag; // thread control + char buf[64]; pthread_mutex_t mutex; } anytone_priv_data_t, * anytone_priv_data_ptr; diff --git a/simulators/simatd578.c b/simulators/simatd578.c index 53560b23a..f9b977332 100644 --- a/simulators/simatd578.c +++ b/simulators/simatd578.c @@ -25,6 +25,7 @@ char modeB = '1'; int width_main = 500; int width_sub = 700; int ptt = 0; +int curr_vfo = 0; int @@ -96,7 +97,7 @@ int openPort(char *comport) // doesn't matter for using pts devices int main(int argc, char *argv[]) { - unsigned char buf[256]; + unsigned char buf[256], buf2[256]; int n; again: @@ -120,19 +121,61 @@ again: switch (buf[0]) { case 0x41: - if (buf[1] == 1) + if (buf[4] == 0x00) // set ptt { - ptt = 1; - printf("PTT ON\n"); + if (buf[1] == 1) + { + ptt = 1; + printf("PTT ON\n"); + } + else + { + ptt = 0; + printf("PTT OFF\n"); + } + + buf[0] = 0x06; + n = write(fd, buf, 1); } - else + + if (buf[4] == 0x0d) // set vfo { - ptt = 0; - printf("PTT OFF\n"); + printf("Set VFO key1=%d, curr_vfo=%d\n", buf[2], curr_vfo); + + if (buf[2] == 0x00) + { + if (curr_vfo == 1) + { + curr_vfo = 0; + } + else + { + curr_vfo = 1; + } + } + + printf("Set VFO key2=%d, curr_vfo=%d\n", buf[2], curr_vfo); + buf2[0] = 0xaa; + buf2[1] = 0x53; + buf2[2] = 0x00; + buf2[3] = 0x00; + buf2[4] = 0x00; + buf2[5] = 0x00; + buf2[6] = 0x00; + buf2[7] = 0x00; + buf2[8] = curr_vfo; + buf2[9] = 0x00; + buf2[10] = 0x10; + buf2[11] = 0x00; + buf2[12] = 0x00; + buf2[13] = 0x00; + buf2[14] = 0x00; + buf2[15] = 0x06; + + if (buf[2] == 0x00) { n = write(fd, buf2, 16); } + else { n = 0; } } - buf[0] = 0x00; - n = write(fd, buf, 1); break; case 0x06: ----------------------------------------------------------------------- Summary of changes: rigs/anytone/anytone.c | 69 +++++++++++++++++++++++++++----------------------- rigs/anytone/anytone.h | 5 ++-- simulators/simatd578.c | 61 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 92 insertions(+), 43 deletions(-) hooks/post-receive -- Hamlib -- Ham radio control libraries |