[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. f37c24d0525dd81449c85
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: n0nb <n0...@us...> - 2023-05-28 20:32:19
|
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 f37c24d0525dd81449c854183c256b335f123991 (commit) via e5bb7355b8ab9e3adabe5f59625c0125c70d63c0 (commit) via 4ae3519c4ef97d6966122237a5ebc7b7c55583ad (commit) via 08abfbe19a66994108eb95c7363a6b4f6903049b (commit) via 1f95e06cc1cb1e438ff8055bf6d81eb80cabdb76 (commit) via 9b748bdb2e34d1e3e11aaf8398af71e4a96d92b9 (commit) via 4e8acc728c44f4a67646035351bcb5a344a93a88 (commit) via 34f20cc970af8ea5cc113a9df58f4ed7f1de08bc (commit) via c4a56a4cf087aa52f84c7f5434bb844cdb5641a9 (commit) via 33a1b2dfb0416b1619bc9f296ddd1411b1bf0462 (commit) via 3b45dfa4b845d581dd187c819876db6ccde447d7 (commit) via ab6058da0368aa3d4b5ce62ed8b8ee7c35d3ead0 (commit) via 00b6e0ecd72104d1c074e78ba3ddb87569ac1e19 (commit) from 77d9d11f9249edeaedef943766c243c595952ad8 (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 f37c24d0525dd81449c854183c256b335f123991 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 16:30:04 2023 -0500 Anytone process 0xaa 0x53 message diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index c7cfd3a36..b91dcd651 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -190,6 +190,7 @@ int anytone_receive(RIG *rig, char *buf, int buf_len, int expected) int anytone_transaction(RIG *rig, char *cmd, int cmd_len, int expected_len) { int retval = RIG_OK; + anytone_priv_data_t *p = rig->state.priv; ENTERFUNC; @@ -199,16 +200,20 @@ int anytone_transaction(RIG *rig, char *cmd, int cmd_len, int expected_len) } else { - MUTEX_LOCK(p->priv.mutex); + MUTEX_LOCK(p->mutex); retval = anytone_send(rig, cmd, cmd_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) + { + p->vfo_curr = buf[8] == 0x00 ? RIG_VFO_A : RIG_VFO_B; + } } - MUTEX_LOCK(p->priv.mutex); + MUTEX_LOCK(p->mutex); } RETURNFUNC(retval); commit e5bb7355b8ab9e3adabe5f59625c0125c70d63c0 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 16:21:14 2023 -0500 More anytone fixes https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index 44486b617..c7cfd3a36 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -187,7 +187,7 @@ int anytone_receive(RIG *rig, char *buf, int buf_len, int expected) // --------------------------------------------------------------------------- // anytone_transaction // --------------------------------------------------------------------------- -int anytone_transaction(RIG *rig, char *cmd, int cmd_len) +int anytone_transaction(RIG *rig, char *cmd, int cmd_len, int expected_len) { int retval = RIG_OK; @@ -202,7 +202,7 @@ int anytone_transaction(RIG *rig, char *cmd, int cmd_len) MUTEX_LOCK(p->priv.mutex); retval = anytone_send(rig, cmd, cmd_len); - if (retval == RIG_OK) + if (retval == RIG_OK && expected_len != 0) { char buf[16]; anytone_receive(rig, buf, sizeof(buf), 1); @@ -380,17 +380,17 @@ int anytone_set_vfo(RIG *rig, vfo_t vfo) { char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x06 }; char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x06 }; - anytone_transaction(rig, buf1, 8); + anytone_transaction(rig, buf1, 8, 0); hl_usleep(100 * 1000); - anytone_transaction(rig, buf2, 8); + anytone_transaction(rig, buf2, 8, 15); } else { char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x06 }; char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x06 }; - anytone_transaction(rig, buf1, 8); + anytone_transaction(rig, buf1, 8, 0); hl_usleep(100 * 1000); - anytone_transaction(rig, buf2, 8); + anytone_transaction(rig, buf2, 8, 15); } } @@ -437,7 +437,7 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) if (ptt) { buf[1] = 0x01; } - anytone_transaction(rig, buf, 8); + anytone_transaction(rig, buf, 8, 1); } RETURNFUNC(retval); commit 4ae3519c4ef97d6966122237a5ebc7b7c55583ad Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 15:13:22 2023 -0500 Revert "Allow generic_read_string to terminate on expected_len" This reverts commit 00b6e0ecd72104d1c074e78ba3ddb87569ac1e19. diff --git a/src/iofunc.c b/src/iofunc.c index e0d746cc6..2e37fb227 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -1336,11 +1336,12 @@ static int read_string_generic(hamlib_port_t *p, memset(rxbuffer, 0, rxmax); short timeout_retries = p->timeout_retry; - while ( total_count < expected_len && total_count < rxmax - 1) // allow 1 byte for end-of-string + while (total_count < rxmax - 1) // allow 1 byte for end-of-string { ssize_t rd_count = 0; int result; result = port_wait_for_data(p, direct); + if (result == -RIG_ETIMEOUT) { if (timeout_retries > 0) commit 08abfbe19a66994108eb95c7363a6b4f6903049b Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 15:11:40 2023 -0500 Revert "Fix read_string_generic to only use expected_len when expected_len == 0" This reverts commit 9b748bdb2e34d1e3e11aaf8398af71e4a96d92b9. diff --git a/src/iofunc.c b/src/iofunc.c index 25d5b9c33..e0d746cc6 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -1336,7 +1336,6 @@ static int read_string_generic(hamlib_port_t *p, memset(rxbuffer, 0, rxmax); short timeout_retries = p->timeout_retry; - if (expected_len == 0) expected_len = rxmax; while ( total_count < expected_len && total_count < rxmax - 1) // allow 1 byte for end-of-string { ssize_t rd_count = 0; commit 1f95e06cc1cb1e438ff8055bf6d81eb80cabdb76 Merge: 9b748bdb2 4e8acc728 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 14:59:22 2023 -0500 Merge branch 'master' of https://github.com/Hamlib/Hamlib commit 9b748bdb2e34d1e3e11aaf8398af71e4a96d92b9 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 14:58:07 2023 -0500 Fix read_string_generic to only use expected_len when expected_len == 0 https://github.com/Hamlib/Hamlib/commit/00b6e0ecd72104d1c074e78ba3ddb87569ac1e19#commitcomment-115297173 diff --git a/src/iofunc.c b/src/iofunc.c index e0d746cc6..25d5b9c33 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -1336,6 +1336,7 @@ static int read_string_generic(hamlib_port_t *p, memset(rxbuffer, 0, rxmax); short timeout_retries = p->timeout_retry; + if (expected_len == 0) expected_len = rxmax; while ( total_count < expected_len && total_count < rxmax - 1) // allow 1 byte for end-of-string { ssize_t rd_count = 0; commit 4e8acc728c44f4a67646035351bcb5a344a93a88 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 12:58:18 2023 -0500 Fix anytone/Makefile.am to include anytone.h https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/rigs/anytone/Makefile.am b/rigs/anytone/Makefile.am index 5e32ba81a..083bdb4e8 100644 --- a/rigs/anytone/Makefile.am +++ b/rigs/anytone/Makefile.am @@ -1,6 +1,6 @@ -ANYTONESRC = anytone.c d578.c +ANYTONESRC = anytone.c d578.c anytone.h noinst_LTLIBRARIES = libhamlib-anytone.la libhamlib_anytone_la_SOURCES = $(ANYTONESRC) -EXTRA_DIST = Android.mk +EXTRA_DIST = Android.mk commit 34f20cc970af8ea5cc113a9df58f4ed7f1de08bc Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 12:51:24 2023 -0500 Add thread to anytone.c to do the keep alive it needs https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index 7b95f0a28..44486b617 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -29,6 +29,7 @@ #include <string.h> #include <unistd.h> #include <ctype.h> +#include <errno.h> // --------------------------------------------------------------------------- // HAMLIB INCLUDES @@ -117,6 +118,30 @@ DECLARE_PROBERIG_BACKEND(anytone) return retval; } +// AnyTone needs a keep-alive to emulate the MIC +// Apparently to keep the rig from getting stuck in PTT if mic disconnects +void *anytone_thread(void *vrig) +{ + RIG *rig = (RIG *)vrig; + anytone_priv_data_t *p = rig->state.priv; + rig_debug(RIG_DEBUG_TRACE, "%s: anytone_thread started\n", __func__); + p->runflag = 1; + + while (p->runflag) + { + char c = 0x06; + MUTEX_LOCK(p->priv.mutex); + write_block(&rig->state.rigport, (unsigned char *)&c, 1); + hl_usleep(100 * 1000); + rig_flush(&rig->state.rigport); + MUTEX_UNLOCK(p->priv.mutex); + hl_usleep(1000 * 1000); // 1-second loop + + } + + return NULL; +} + // --------------------------------------------------------------------------- // anytone_send // --------------------------------------------------------------------------- @@ -174,6 +199,7 @@ int anytone_transaction(RIG *rig, char *cmd, int cmd_len) } else { + MUTEX_LOCK(p->priv.mutex); retval = anytone_send(rig, cmd, cmd_len); if (retval == RIG_OK) @@ -181,6 +207,8 @@ int anytone_transaction(RIG *rig, char *cmd, int cmd_len) char buf[16]; anytone_receive(rig, buf, sizeof(buf), 1); } + + MUTEX_LOCK(p->priv.mutex); } RETURNFUNC(retval); @@ -212,6 +240,9 @@ int anytone_init(RIG *rig) rig->state.priv = pPriv; anytone_priv_data_t *p = rig->state.priv; p->vfo_curr = RIG_VFO_NONE; +#ifdef HAVE_PTHREAD + pthread_mutex_init(&p->mutex, NULL); +#endif } RETURNFUNC(retval); @@ -265,6 +296,17 @@ int anytone_open(RIG *rig) // can we ask for any information? Maybe just toggle A/B? } + pthread_t id; + int err = pthread_create(&id, NULL, anytone_thread, (void *)rig); + + if (err) + { + rig_debug(RIG_DEBUG_ERR, "%s: pthread_create error: %s\n", __func__, + strerror(errno)); + RETURNFUNC(-RIG_EINTERNAL); + } + + RETURNFUNC(retval); } @@ -333,18 +375,19 @@ int anytone_set_vfo(RIG *rig, vfo_t vfo) } else { + // can we use status reponse to deteremin which VFO is active? if (vfo == RIG_VFO_A) { - char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x1a, 0x00, 0x00, 0x06 }; - char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x06 }; + char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x06 }; + char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x06 }; anytone_transaction(rig, buf1, 8); hl_usleep(100 * 1000); anytone_transaction(rig, buf2, 8); } else { - char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x1b, 0x00, 0x00, 0x06 }; - char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x06 }; + char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x0d, 0x00, 0x00, 0x06 }; + char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x06 }; anytone_transaction(rig, buf1, 8); hl_usleep(100 * 1000); anytone_transaction(rig, buf2, 8); diff --git a/rigs/anytone/anytone.h b/rigs/anytone/anytone.h index bafa6f60c..2388f3c54 100644 --- a/rigs/anytone/anytone.h +++ b/rigs/anytone/anytone.h @@ -9,10 +9,23 @@ extern const struct rig_caps anytone_d578_caps; +#ifdef PTHREAD +#include <pthread.h> +#define MUTEX(var) static pthread_mutex_t var = PTHREAD_MUTEX_INITIALIZER +#define MUTEX_LOCK(var) pthread_mutex_lock(var) +#define MUTEX_UNLOCK(var) pthread_mutex_unlock(var) +#else +#define MUTEX(var) +#define MUTEX_LOCK(var) +#define MUTEX_UNLOCK(var) +#endif + typedef struct _anytone_priv_data { int ptt; vfo_t vfo_curr; + int runflag; // thread control + pthread_mutex_t mutex; } anytone_priv_data_t, * anytone_priv_data_ptr; diff --git a/simulators/simatd578.c b/simulators/simatd578.c index ca95b2dc6..53560b23a 100644 --- a/simulators/simatd578.c +++ b/simulators/simatd578.c @@ -38,13 +38,14 @@ getmyline(int fd, unsigned char *buf) // seemd the anytone only gives 8-byte commands and 1-byte responses while (i < 8 && read(fd, &c, 1) > 0) { - if (i==0 && buf[i]==0x06) + if (i == 0 && c == 0x06) { - write(fd, buf, 1); + write(fd, &c, 1); } - else { - buf[i++] = c; - n++; + else + { + buf[i++] = c; + n++; } } @@ -96,10 +97,8 @@ int openPort(char *comport) // doesn't matter for using pts devices int main(int argc, char *argv[]) { unsigned char buf[256]; - unsigned char *pbuf; int n; - again: int fd = openPort(argv[1]); @@ -136,8 +135,15 @@ again: n = write(fd, buf, 1); break; - default: printf("Unknown cmd=%02x\n", buf[0]); + case 0x06: + buf[0] = 0x06; + n = write(fd, buf, 1); + break; + + default: printf("Unknown cmd=%02x\n", buf[0]); continue; } + + printf("%d bytes returned\n", n); } return 0; commit c4a56a4cf087aa52f84c7f5434bb844cdb5641a9 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 12:00:44 2023 -0500 Fix simatd578 one more time https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/simulators/Makefile.am b/simulators/Makefile.am index 8e421a5d2..299e04fb7 100644 --- a/simulators/Makefile.am +++ b/simulators/Makefile.am @@ -8,7 +8,7 @@ DISTCLEANFILES = bin_PROGRAMS = -check_PROGRAMS = simelecraft simicom simkenwood simyaesu simicom9100 simicom9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simicom7300 simicom7100 simatdt578 +check_PROGRAMS = simelecraft simicom simkenwood simyaesu simicom9100 simicom9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simicom7300 simicom7100 simatd578 simelecraft_SOURCES = simelecraft.c simicom_SOURCES = simicom.c commit 33a1b2dfb0416b1619bc9f296ddd1411b1bf0462 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 11:12:27 2023 -0500 Fix simatdt578 entry diff --git a/simulators/Makefile.am b/simulators/Makefile.am index 514721364..8e421a5d2 100644 --- a/simulators/Makefile.am +++ b/simulators/Makefile.am @@ -8,7 +8,7 @@ DISTCLEANFILES = bin_PROGRAMS = -check_PROGRAMS = simelecraft simicom simkenwood simyaesu simicom9100 simicom9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simicom7300 simicom7100 simdt578 +check_PROGRAMS = simelecraft simicom simkenwood simyaesu simicom9100 simicom9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simicom7300 simicom7100 simatdt578 simelecraft_SOURCES = simelecraft.c simicom_SOURCES = simicom.c commit 3b45dfa4b845d581dd187c819876db6ccde447d7 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 11:04:56 2023 -0500 Add AnyTone D578UVIII https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/configure.ac b/configure.ac index cee1aff02..08ba1fa48 100644 --- a/configure.ac +++ b/configure.ac @@ -49,7 +49,7 @@ dnl added to AC_CONFIG_FILES near the end of this file. See README.developer dnl Beware of duplication should a backend directory include both rig and dnl rotor definitions, e.g. "dummy". Optional backends will not be listed dnl here but will be added later, e.g. "winradio". -RIG_BACKEND_LIST="rigs/adat rigs/alinco rigs/aor rigs/barrett rigs/codan rigs/dorji rigs/drake rigs/dummy rigs/elad rigs/flexradio rigs/icom rigs/icmarine rigs/jrc rigs/kachina rigs/kenwood rigs/kit rigs/lowe rigs/pcr rigs/prm80 rigs/racal rigs/rft rigs/rs rigs/skanti rigs/tapr rigs/tentec rigs/tuner rigs/uniden rigs/winradio rigs/wj rigs/yaesu rigs/gomspace rigs/mds" +RIG_BACKEND_LIST="rigs/adat rigs/alinco rigs/aor rigs/barrett rigs/codan rigs/dorji rigs/drake rigs/dummy rigs/elad rigs/flexradio rigs/icom rigs/icmarine rigs/jrc rigs/kachina rigs/kenwood rigs/kit rigs/lowe rigs/pcr rigs/prm80 rigs/racal rigs/rft rigs/rs rigs/skanti rigs/tapr rigs/tentec rigs/tuner rigs/uniden rigs/winradio rigs/wj rigs/yaesu rigs/gomspace rigs/mds rigs/anytone" ROT_BACKEND_LIST="rotators/amsat rotators/apex rotators/ars rotators/celestron rotators/cnctrk rotators/grbltrk rotators/easycomm rotators/ether6 rotators/flir rotators/fodtrack rotators/gs232a rotators/heathkit rotators/m2 rotators/meade rotators/rotorez rotators/sartek rotators/saebrtrack rotators/spid rotators/ts7400 rotators/prosistel rotators/ioptron rotators/satel rotators/radant" # Amplifiers are all in the amplifiers directory AMP_BACKEND_LIST="amplifiers/elecraft amplifiers/gemini amplifiers/expert" @@ -912,6 +912,7 @@ rigs/wj/Makefile rigs/yaesu/Makefile rigs/gomspace/Makefile rigs/mds/Makefile +rigs/anytone/Makefile tests/Makefile scripts/Makefile android/Makefile diff --git a/include/hamlib/riglist.h b/include/hamlib/riglist.h index f73e639fc..94c29c9d8 100644 --- a/include/hamlib/riglist.h +++ b/include/hamlib/riglist.h @@ -656,6 +656,14 @@ etc. */ +/* + * AnyTone rigs + */ +#define RIG_ANYTONE 37 +#define RIG_BACKEND_ANYTONE "AnyTone" +#define RIG_MODEL_ATD578UVIII RIG_MAKE_MODEL(RIG_ANYTONE, 1) + + //! @endcond /*! \typedef typedef int rig_model_t diff --git a/rigs/anytone/Android.mk b/rigs/anytone/Android.mk new file mode 100644 index 000000000..8fbe3b54f --- /dev/null +++ b/rigs/anytone/Android.mk @@ -0,0 +1,12 @@ +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := anytone.c d578.c +LOCAL_MODULE := anytone + +LOCAL_CFLAGS := +LOCAL_C_INCLUDES := android include src +LOCAL_LDLIBS := $(LOCAL_SHARED_LIBRARIES) -Lobj/local/$(TARGET_ARCH_ABI) + +include $(BUILD_STATIC_LIBRARY) diff --git a/rigs/anytone/Makefile.am b/rigs/anytone/Makefile.am new file mode 100644 index 000000000..5e32ba81a --- /dev/null +++ b/rigs/anytone/Makefile.am @@ -0,0 +1,6 @@ +ANYTONESRC = anytone.c d578.c + +noinst_LTLIBRARIES = libhamlib-anytone.la +libhamlib_anytone_la_SOURCES = $(ANYTONESRC) + +EXTRA_DIST = Android.mk diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c new file mode 100644 index 000000000..7b95f0a28 --- /dev/null +++ b/rigs/anytone/anytone.c @@ -0,0 +1,405 @@ +// --------------------------------------------------------------------------- +// AnyTone D578 Hamlib Backend +// --------------------------------------------------------------------------- +// +// d578.c +// +// Created by Michael Black W9MDB +// Copyright © 2023 Michael Black W9MDB. +// +// 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 + +// --------------------------------------------------------------------------- +// SYSTEM INCLUDES +// --------------------------------------------------------------------------- + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <ctype.h> + +// --------------------------------------------------------------------------- +// HAMLIB INCLUDES +// --------------------------------------------------------------------------- + +#include <hamlib/rig.h> +#include "serial.h" +#include "misc.h" +#include "register.h" +#include "riglist.h" + +// --------------------------------------------------------------------------- +// ANYTONE INCLUDES +// --------------------------------------------------------------------------- + +#include "anytone.h" + +DECLARE_INITRIG_BACKEND(anytone) +{ + int retval = RIG_OK; + + rig_register(&anytone_d578_caps); + + return retval; +} + + + +// --------------------------------------------------------------------------- +// proberig_anytone +// --------------------------------------------------------------------------- +DECLARE_PROBERIG_BACKEND(anytone) +{ + int retval = RIG_OK; + + if (!port) + { + return RIG_MODEL_NONE; + } + + if (port->type.rig != RIG_PORT_SERIAL) + { + return RIG_MODEL_NONE; + } + + port->write_delay = port->post_write_delay = 0; + port->parm.serial.stop_bits = 1; + port->retry = 1; + + + retval = serial_open(port); + + if (retval != RIG_OK) + { + retval = RIG_MODEL_NONE; + } + else + { + char acBuf[ ANYTONE_RESPSZ + 1 ]; + int nRead = 0; + + 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)) + { + retval = RIG_MODEL_NONE; + } + else + { + rig_debug(RIG_DEBUG_VERBOSE, "Received ID = %s.", + acBuf); + + retval = RIG_MODEL_ADT_200A; + } + } + + return retval; +} + +// --------------------------------------------------------------------------- +// anytone_send +// --------------------------------------------------------------------------- +int anytone_send(RIG *rig, + char *cmd, int cmd_len) +{ + int retval = RIG_OK; + struct rig_state *rs = &rig->state; + + ENTERFUNC; + + rig_flush(&rs->rigport); + + retval = write_block(&rs->rigport, (unsigned char *) cmd, + cmd_len); + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// anytone_receive +// --------------------------------------------------------------------------- +int anytone_receive(RIG *rig, char *buf, int buf_len, int expected) +{ + int retval = RIG_OK; + struct rig_state *rs = &rig->state; + + ENTERFUNC; + + retval = read_string(&rs->rigport, (unsigned char *) buf, buf_len, + NULL, 0, 0, expected); + + if (retval > 0) + { + retval = RIG_OK; + rig_debug(RIG_DEBUG_VERBOSE, "%s: read %d byte=0x%02x\n", __func__, retval, + buf[0]); + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// anytone_transaction +// --------------------------------------------------------------------------- +int anytone_transaction(RIG *rig, char *cmd, int cmd_len) +{ + int retval = RIG_OK; + + ENTERFUNC; + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + retval = anytone_send(rig, cmd, cmd_len); + + if (retval == RIG_OK) + { + char buf[16]; + anytone_receive(rig, buf, sizeof(buf), 1); + } + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// Function anytone_init +// --------------------------------------------------------------------------- +int anytone_init(RIG *rig) +{ + int retval = RIG_OK; + + ENTERFUNC; + // Check Params + + if (rig != NULL) + { + anytone_priv_data_ptr pPriv = NULL; + + // Get new Priv Data + + pPriv = calloc(1, sizeof(anytone_priv_data_t)); + + if (pPriv == NULL) + { + retval = -RIG_ENOMEM; + } + + rig->state.priv = pPriv; + anytone_priv_data_t *p = rig->state.priv; + p->vfo_curr = RIG_VFO_NONE; + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// Function anytone_cleanup +// --------------------------------------------------------------------------- +int anytone_cleanup(RIG *rig) +{ + int retval = RIG_OK; + + ENTERFUNC; + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + if (rig->state.priv != NULL) + { + free(rig->state.priv); + rig->state.priv = NULL; + } + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// Function anytone_open +// --------------------------------------------------------------------------- +int anytone_open(RIG *rig) +{ + int retval = RIG_OK; + + ENTERFUNC; + // Check Params + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + // grace period for the radio to be there + + // hl_usleep(500); // do we need this for AnyTone? + + // can we ask for any information? Maybe just toggle A/B? + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// Function anytone_close +// --------------------------------------------------------------------------- +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); +} + +// --------------------------------------------------------------------------- +// Function anytone_get_vfo +// --------------------------------------------------------------------------- +int anytone_get_vfo(RIG *rig, vfo_t *vfo) +{ + int retval = RIG_OK; + + ENTERFUNC; + // Check Params + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + anytone_priv_data_ptr pPriv = (anytone_priv_data_ptr) rig->state.priv; + + *vfo = pPriv->vfo_curr; + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// Function anytone_set_vfo +// --------------------------------------------------------------------------- +int anytone_set_vfo(RIG *rig, vfo_t vfo) +{ + int retval = RIG_OK; + + ENTERFUNC; + // Check Params + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + if (vfo == RIG_VFO_A) + { + char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x1a, 0x00, 0x00, 0x06 }; + char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x06 }; + anytone_transaction(rig, buf1, 8); + hl_usleep(100 * 1000); + anytone_transaction(rig, buf2, 8); + } + else + { + char buf1[8] = { 0x41, 0x00, 0x01, 0x00, 0x1b, 0x00, 0x00, 0x06 }; + char buf2[8] = { 0x41, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x00, 0x06 }; + anytone_transaction(rig, buf1, 8); + hl_usleep(100 * 1000); + anytone_transaction(rig, buf2, 8); + } + + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// Function anytone_get_ptt +// --------------------------------------------------------------------------- +int anytone_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) +{ + int retval = RIG_OK; + + ENTERFUNC; + // Check Params + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + } + + return retval; +} +// --------------------------------------------------------------------------- +// anytone_set_ptt +// --------------------------------------------------------------------------- +int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) +{ + int retval = RIG_OK; + + ENTERFUNC; + + if (rig == NULL) + { + retval = -RIG_EARG; + } + else + { + char buf[8] = { 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06 }; + + if (ptt) { buf[1] = 0x01; } + + anytone_transaction(rig, buf, 8); + } + + RETURNFUNC(retval); +} + +// --------------------------------------------------------------------------- +// END OF FILE +// --------------------------------------------------------------------------- diff --git a/rigs/anytone/anytone.h b/rigs/anytone/anytone.h new file mode 100644 index 000000000..bafa6f60c --- /dev/null +++ b/rigs/anytone/anytone.h @@ -0,0 +1,31 @@ +#ifndef _ANYTONE_H +#define _ANYTONE_H 1 + +#include "hamlib/rig.h" + +#define BACKEND_VER "20230527" + +#define ANYTONE_RESPSZ 64 + +extern const struct rig_caps anytone_d578_caps; + +typedef struct _anytone_priv_data +{ + int ptt; + vfo_t vfo_curr; +} anytone_priv_data_t, +* anytone_priv_data_ptr; + + +extern int anytone_init(RIG *rig); +extern int anytone_cleanup(RIG *rig); +extern int anytone_open(RIG *rig); +extern int anytone_close(RIG *rig); + +extern int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt); +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); + +#endif /* _ANYTONE_H */ diff --git a/rigs/anytone/d578.c b/rigs/anytone/d578.c new file mode 100644 index 000000000..f6d56dd37 --- /dev/null +++ b/rigs/anytone/d578.c @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------------- +// Anytone D578UVIII +// --------------------------------------------------------------------------- +// +// d578.c +// +// Created by Michael Black W9MDB +// Copyright © 2023, Michael Black W9MDB. +// +// 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 + +#include "anytone.h" + +#define D578_VFO (RIG_VFO_A|RIG_VFO_B) +#define D578_MODES (RIG_MODE_USB|RIG_MODE_AM) + +const struct rig_caps anytone_d578_caps = +{ + RIG_MODEL(RIG_MODEL_ATD578UVIII), + .model_name = "D578A", + .mfg_name = "AnyTone", + .version = BACKEND_VER ".0", + .copyright = "Michael Black W9MDB: GNU LGPL", + .status = RIG_STATUS_ALPHA, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_RIG, + .dcd_type = RIG_DCD_NONE, + .port_type = RIG_PORT_SERIAL, + .serial_rate_min = 115200, + .serial_rate_max = 115200, + .serial_data_bits = 8, + .serial_stop_bits = 1, + .serial_parity = RIG_PARITY_NONE, + .serial_handshake = RIG_HANDSHAKE_NONE, + .write_delay = 0, + .post_write_delay = 0, + .timeout = 1000, + .retry = 3, + + .level_gran = {}, + .parm_gran = {}, + .ctcss_list = NULL, + .dcs_list = NULL, + .targetable_vfo = RIG_TARGETABLE_NONE, + .transceive = 0, + + .rx_range_list1 = + { + { MHz(108), MHz(174), D578_MODES, -1, -1, D578_VFO }, + { MHz(144), MHz(148), D578_MODES, -1, -1, D578_VFO }, + { MHz(222), MHz(225), D578_MODES, -1, -1, D578_VFO }, + { MHz(420), MHz(450), D578_MODES, -1, -1, D578_VFO }, + RIG_FRNG_END, + }, + + .tx_range_list1 = + { + { MHz(144), MHz(148), D578_MODES, W(1), W(55), D578_VFO }, + { MHz(222), MHz(225), D578_MODES, W(1), W(40), D578_VFO }, + { MHz(420), MHz(450), D578_MODES, W(1), W(25), D578_VFO }, + RIG_FRNG_END, + }, + + .rig_init = anytone_init, + .rig_cleanup = anytone_cleanup, + .rig_open = anytone_open, + .rig_close = anytone_close, + + .get_vfo = anytone_get_vfo, + .set_vfo = anytone_set_vfo, + + .get_ptt = anytone_get_ptt, + .set_ptt = anytone_set_ptt, + + .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS +}; + +// --------------------------------------------------------------------------- +// END OF FILE +// --------------------------------------------------------------------------- diff --git a/src/register.c b/src/register.c index 7b02f3528..70bbaed7c 100644 --- a/src/register.c +++ b/src/register.c @@ -89,6 +89,7 @@ DEFINE_INITRIG_BACKEND(elad); DEFINE_INITRIG_BACKEND(codan); DEFINE_INITRIG_BACKEND(gomspace); DEFINE_INITRIG_BACKEND(mds); +DEFINE_INITRIG_BACKEND(anytone); //! @endcond #ifdef HAVE_WINRADIO @@ -148,6 +149,7 @@ static struct { RIG_CODAN, RIG_BACKEND_CODAN, RIG_FUNCNAMA(codan) }, { RIG_GOMSPACE, RIG_BACKEND_GOMSPACE, RIG_FUNCNAM(gomspace) }, { RIG_MDS, RIG_BACKEND_MDS, RIG_FUNCNAMA(mds) }, + { RIG_ANYTONE, RIG_BACKEND_ANYTONE, RIG_FUNCNAMA(anytone) }, { 0, NULL }, /* end */ }; @@ -199,8 +201,8 @@ int HAMLIB_API rig_register(const struct rig_caps *caps) return -RIG_EINVAL; } -#if 0 - rig_debug(RIG_DEBUG_VERBOSE, +#if 1 + rig_debug(RIG_DEBUG_ERR, "%s: rig_register (%u)\n", __func__, caps->rig_model); commit ab6058da0368aa3d4b5ce62ed8b8ee7c35d3ead0 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 10:45:45 2023 -0500 Add simatd578.c diff --git a/simulators/Makefile.am b/simulators/Makefile.am index 78006dcf4..514721364 100644 --- a/simulators/Makefile.am +++ b/simulators/Makefile.am @@ -8,7 +8,7 @@ DISTCLEANFILES = bin_PROGRAMS = -check_PROGRAMS = simelecraft simicom simkenwood simyaesu simicom9100 simicom9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simicom7300 simicom7100 +check_PROGRAMS = simelecraft simicom simkenwood simyaesu simicom9100 simicom9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simicom7300 simicom7100 simdt578 simelecraft_SOURCES = simelecraft.c simicom_SOURCES = simicom.c diff --git a/simulators/simatd578.c b/simulators/simatd578.c new file mode 100644 index 000000000..ca95b2dc6 --- /dev/null +++ b/simulators/simatd578.c @@ -0,0 +1,144 @@ +// can run this using rigctl/rigctld and socat pty devices +// gcc -o simatd578 simatd578.c +#define _XOPEN_SOURCE 700 +// since we are POSIX here we need this +struct ip_mreq +{ + int dummy; +}; + +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <string.h> +#include <unistd.h> +#include "../include/hamlib/rig.h" + +#define BUFSIZE 256 + +float freqA = 14074000; +float freqB = 14074500; +char tx_vfo = '0'; +char rx_vfo = '0'; +char modeA = '1'; +char modeB = '1'; +int width_main = 500; +int width_sub = 700; +int ptt = 0; + + +int +getmyline(int fd, unsigned char *buf) +{ + unsigned char c; + int i = 0; + 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) + { + if (i==0 && buf[i]==0x06) + { + write(fd, buf, 1); + } + else { + buf[i++] = c; + n++; + } + } + + 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]); + return n; +} + +#if defined(WIN32) || defined(_WIN32) +int openPort(char *comport) // doesn't matter for using pts devices +{ + int fd; + fd = open(comport, O_RDWR); + + if (fd < 0) + { + perror(comport); + } + + return fd; +} + +#else +int openPort(char *comport) // doesn't matter for using pts devices +{ + int fd = posix_openpt(O_RDWR); + char *name = ptsname(fd); + + if (name == NULL) + { + perror("pstname"); + return -1; + } + + printf("name=%s\n", name); + + if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1) + { + perror("posix_openpt"); + return -1; + } + + return fd; +} +#endif + + + +int main(int argc, char *argv[]) +{ + unsigned char buf[256]; + unsigned char *pbuf; + int n; + + +again: + int fd = openPort(argv[1]); + + while (1) + { + int bytes = getmyline(fd, buf); + + if (bytes == 0) + { + close(fd); + goto again; + } + + if (bytes != 8) + { + printf("Not 8 bytes? bytes=%d\n", bytes); + } + + switch (buf[0]) + { + case 0x41: + if (buf[1] == 1) + { + ptt = 1; + printf("PTT ON\n"); + } + else + { + ptt = 0; + printf("PTT OFF\n"); + } + + buf[0] = 0x00; + n = write(fd, buf, 1); + break; + + default: printf("Unknown cmd=%02x\n", buf[0]); + } + } + + return 0; +} commit 00b6e0ecd72104d1c074e78ba3ddb87569ac1e19 Author: Mike Black W9MDB <mdb...@ya...> Date: Sat May 27 10:07:32 2023 -0500 Allow generic_read_string to terminate on expected_len https://github.com/Hamlib/Hamlib/issues/1303 diff --git a/src/iofunc.c b/src/iofunc.c index 2e37fb227..e0d746cc6 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -1336,12 +1336,11 @@ static int read_string_generic(hamlib_port_t *p, memset(rxbuffer, 0, rxmax); short timeout_retries = p->timeout_retry; - while (total_count < rxmax - 1) // allow 1 byte for end-of-string + while ( total_count < expected_len && total_count < rxmax - 1) // allow 1 byte for end-of-string { ssize_t rd_count = 0; int result; result = port_wait_for_data(p, direct); - if (result == -RIG_ETIMEOUT) { if (timeout_retries > 0) ----------------------------------------------------------------------- Summary of changes: configure.ac | 3 +- include/hamlib/riglist.h | 8 + rigs/{adat => anytone}/Android.mk | 4 +- rigs/anytone/Makefile.am | 6 + rigs/anytone/anytone.c | 453 +++++++++++++++++++++++++++++++ rigs/anytone/anytone.h | 44 +++ rigs/anytone/d578.c | 92 +++++++ simulators/Makefile.am | 2 +- simulators/{simjupiter.c => simatd578.c} | 60 ++-- src/register.c | 6 +- 10 files changed, 655 insertions(+), 23 deletions(-) copy rigs/{adat => anytone}/Android.mk (78%) create mode 100644 rigs/anytone/Makefile.am create mode 100644 rigs/anytone/anytone.c create mode 100644 rigs/anytone/anytone.h create mode 100644 rigs/anytone/d578.c copy simulators/{simjupiter.c => simatd578.c} (60%) hooks/post-receive -- Hamlib -- Ham radio control libraries |