diff options
author | Lars Holger Engelhard <mail@lars-engelhard.de> | 2016-12-24 20:43:56 (GMT) |
---|---|---|
committer | Lars <mail@dl5rcw.de> | 2016-12-29 06:30:12 (GMT) |
commit | a74835f216966692b2c16f892d9b65bda25ab5dc (patch) | |
tree | df3459e14ff7567a563d14e381a0a565922b88f6 /src | |
parent | 9fb153c4f164b63de77c3140edb8bbefd5d6b340 (diff) | |
download | mxe-a74835f216966692b2c16f892d9b65bda25ab5dc.zip mxe-a74835f216966692b2c16f892d9b65bda25ab5dc.tar.gz mxe-a74835f216966692b2c16f892d9b65bda25ab5dc.tar.bz2 |
Introducing hamlib
Diffstat (limited to 'src')
-rw-r--r-- | src/hamlib-test.c | 106 | ||||
-rw-r--r-- | src/hamlib.mk | 51 |
2 files changed, 157 insertions, 0 deletions
diff --git a/src/hamlib-test.c b/src/hamlib-test.c new file mode 100644 index 0000000..28c485c --- /dev/null +++ b/src/hamlib-test.c @@ -0,0 +1,106 @@ +/* This file is part of MXE. See LICENSE.md for licensing information. + * This is a elementary program calling and testing Hamlib. + */ + +#include <stdio.h> +#include <string.h> +#include <hamlib/rig.h> +#include <hamlib/riglist.h> + +int main(int argc, char *argv[]) { + RIG *my_rig; + char *rig_file, *info_buf, *mm; + freq_t freq; + value_t rawstrength, power, strength; + float s_meter, rig_raw2val(); + int status, retcode, isz; + unsigned int mwpower; + rmode_t mode; + pbwidth_t width; + rig_model_t myrig_model; + char portname[64]; + port_t myport; + + strncpy(portname, argv[2], 63); + portname[63] = '\0'; + + if ((strcmp(argv[2], "--help") == 0) || (argc < 2)) { + printf("use like: ./%s <portname>\n", argv[0]); + printf("example: ./%s /dev/ttyS0\n", argv[0]); + return 0; + } + + /* Try to detect rig */ + /* may be overriden by backend probe */ + myport.type.rig = RIG_PORT_SERIAL; + myport.parm.serial.rate = 9600; + myport.parm.serial.data_bits = 8; + myport.parm.serial.stop_bits = 1; + myport.parm.serial.parity = RIG_PARITY_NONE; + myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; + strncpy(myport.pathname, portname, FILPATHLEN); + + rig_load_all_backends(); + myrig_model = rig_probe(&myport); + /* Set verbosity level - errors only */ + rig_set_debug(RIG_DEBUG_ERR); + /* Instantiate a rig - your rig */ + /* my_rig = rig_init(RIG_MODEL_TT565); */ + my_rig = rig_init(myrig_model); + /* Set up serial port, baud rate - serial device + baudrate */ + rig_file = "/dev/ttyUSB0"; + strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN - 1); + my_rig->state.rigport.parm.serial.rate = 57600; + my_rig->state.rigport.parm.serial.rate = 9600; + /* Open my rig */ + retcode = rig_open(my_rig); + printf("retcode of rig_open = %d \n", retcode); + /* Give me ID info, e.g., firmware version. */ + info_buf = (char *)rig_get_info(my_rig); + printf("Rig_info: '%s'\n", info_buf); + + /* Note: As a general practice, we should check to see if a given + * function is within the rig's capabilities before calling it, but + * we are simplifying here. Also, we should check each call's returned + * status in case of error. (That's an inelegant way to catch an unsupported + * operation.) + */ + + /* Main VFO frequency */ + status = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); + printf("status of rig_get_freq = %d \n", status); + printf("VFO freq. = %.1f Hz\n", freq); + /* Current mode */ + status = rig_get_mode(my_rig, RIG_VFO_CURR, &mode, &width); + printf("status of rig_get_mode = %d \n", status); + switch(mode) { + case RIG_MODE_USB: mm = "USB"; break; + case RIG_MODE_LSB: mm = "LSB"; break; + case RIG_MODE_CW: mm = "CW"; break; + case RIG_MODE_CWR: mm = "CWR"; break; + case RIG_MODE_AM: mm = "AM"; break; + case RIG_MODE_FM: mm = "FM"; break; + case RIG_MODE_WFM: mm = "WFM"; break; + case RIG_MODE_RTTY:mm = "RTTY"; break; + default: mm = "unrecognized"; break; /* there are more possibilities! */ + } + printf("Current mode = 0x%X = %s, width = %d\n", mode, mm, (int) width); + /* rig power output */ + status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &power); + printf("RF Power relative setting = %.3f (0.0 - 1.0)\n", power.f); + /* Convert power reading to watts */ + status = rig_power2mW(my_rig, &mwpower, power.f, freq, mode); + printf("RF Power calibrated = %.1f Watts\n", mwpower/1000.); + /* Raw and calibrated S-meter values */ + status = rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RAWSTR, &rawstrength); + printf("Raw receive strength = %d\n", rawstrength.i); + isz = my_rig->caps->str_cal.size; + printf("isz = %d \n", isz); + s_meter = rig_raw2val(rawstrength.i, &my_rig->caps->str_cal); + printf("S-meter value = %.2f dB relative to S9\n", s_meter); + /* now try using RIG_LEVEL_STRENGTH itself */ + status = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); + printf("status of rig_get_strength = %d \n", status); + printf("LEVEL_STRENGTH returns %d\n", strength.i); +return 0; +} diff --git a/src/hamlib.mk b/src/hamlib.mk new file mode 100644 index 0000000..821831b --- /dev/null +++ b/src/hamlib.mk @@ -0,0 +1,51 @@ +# This file is part of MXE. See LICENSE.md for licensing information. +# visit http://hamlib.org or https://github.com/N0NB/hamlib +# 2016-12-24 Lars Holger Engelhard DL5RCW + +PKG := hamlib +$(PKG)_WEBSITE := http://www.hamlib.org +$(PKG)_DESCR := HamLib +$(PKG)_IGNORE := +$(PKG)_VERSION := 3.0.1 +$(PKG)_CHECKSUM := 3fec97ea326d02aa8f35834c4af34194a3f544e6212f391397d788c566b44e32 +$(PKG)_SUBDIR := hamlib-$($(PKG)_VERSION) +$(PKG)_FILE := Hamlib-$($(PKG)_VERSION).tar.gz +$(PKG)_URL := http://$(SOURCEFORGE_MIRROR)/project/hamlib/hamlib/$($(PKG)_VERSION)/hamlib-$($(PKG)_VERSION).tar.gz +$(PKG)_URL_2 := https://github.com/N0NB/$(PKG)/archive/$($(PKG)_VERSION).tar.gz +$(PKG)_DEPS := gcc libltdl libusb1 libxml2 pthreads + +# grabbing version from sourceforge +# prefered by Nate N0NB +define $(PKG)_UPDATE + $(WGET) -q -O- 'http://sourceforge.net/projects/hamlib/files/hamlib/' | \ + $(SED) -n 's,.*/\([0-9][^"]*\)/".*,\1,p' | \ + head -1 +endef + +## grabbing version from github via MXE +#define $(PKG)_UPDATE +# $(call MXE_GET_GITHUB_TAGS, N0NB/hamlib) +#endef + +define $(PKG)_BUILD + cd '$(BUILD_DIR)' && '$(SOURCE_DIR)/configure' \ + $(MXE_CONFIGURE_OPTS) \ + --with-included-ltdl \ + --disable-winradio + $(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' || $(MAKE) -C '$(BUILD_DIR)' -j 1 + $(MAKE) -C '$(BUILD_DIR)' -j 1 install $(MXE_DISABLE_CRUFT) + + # create pkg-config files + $(INSTALL) -d '$(PREFIX)/$(TARGET)/lib/pkgconfig' + (echo 'Name: $(PKG)'; \ + echo 'Version: $(hamlib_VERSION)'; \ + echo 'Description: $(PKG)'; \ + echo 'Cflags: -DHAMLIB_LIB'; \ + echo 'Libs: -lhamlib -lpthread -lws2_32';) \ + > '$(PREFIX)/$(TARGET)/lib/pkgconfig/$(PKG).pc' + + '$(TARGET)-gcc' \ + -W -Wall -Werror -ansi -pedantic \ + '$(PWD)/src/$(PKG)-test.c' -o '$(PREFIX)/$(TARGET)/bin/test-$(PKG).exe' \ + `'$(TARGET)-pkg-config' --cflags --libs hamlib pthreads` +endef |