Use librtlsdr to detect rtl-sdr dongle.

pull/156/head
Fredrik Öhrström 2020-09-27 19:40:05 +02:00
rodzic 3552282e8f
commit f5ff15af2c
13 zmienionych plików z 7064 dodań i 74 usunięć

Wyświetl plik

@ -146,6 +146,7 @@ METER_OBJS:=\
$(BUILD)/meter_vario451.o \
$(BUILD)/meter_waterstarm.o \
$(BUILD)/printer.o \
$(BUILD)/rtlsdr.o \
$(BUILD)/serial.o \
$(BUILD)/shell.o \
$(BUILD)/threads.o \
@ -197,10 +198,10 @@ snapcraft:
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/version.h
$(BUILD)/wmbusmeters: $(METER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters $(METER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lpthread
$(CXX) -o $(BUILD)/wmbusmeters $(METER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lrtlsdr -lpthread
$(BUILD)/wmbusmeters-admin: $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters-admin $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(LDFLAGS) -lmenu -lform -lncurses -lpthread
$(CXX) -o $(BUILD)/wmbusmeters-admin $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(LDFLAGS) -lmenu -lform -lncurses -lrtlsdr -lpthread
$(BUILD)/short_manual.h: README.md
echo 'R"MANUAL(' > $(BUILD)/short_manual.h
@ -210,10 +211,10 @@ $(BUILD)/short_manual.h: README.md
echo ')MANUAL";' >> $(BUILD)/short_manual.h
$(BUILD)/testinternals: $(METER_OBJS) $(BUILD)/testinternals.o
$(CXX) -o $(BUILD)/testinternals $(METER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lpthread
$(CXX) -o $(BUILD)/testinternals $(METER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lrtlsdr -lpthread
$(BUILD)/fuzz: $(METER_OBJS) $(BUILD)/fuzz.o
$(CXX) -o $(BUILD)/fuzz $(METER_OBJS) $(BUILD)/fuzz.o $(LDFLAGS) -lpthread
$(CXX) -o $(BUILD)/fuzz $(METER_OBJS) $(BUILD)/fuzz.o $(LDFLAGS) -lrtlsdr -lpthread
clean:
rm -rf build/* build_arm/* build_debug/* build_arm_debug/* *~

Wyświetl plik

@ -0,0 +1,2 @@
# Empty so far

1480
autoconf/config.guess vendored 100644

Plik diff jest za duży Load Diff

Wyświetl plik

@ -0,0 +1,64 @@
/* autoconf/config.h.in. Generated from configure.ac by autoheader. */
/* Stat structure has st_mtim */
#undef HAS_ST_MTIM
/* Stat structure has st_mtime */
#undef HAS_ST_MTIME
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* The size of `time_t', as computed by sizeof. */
#undef SIZEOF_TIME_T
/* Define to 1 if the `S_IS*' macros in <sys/stat.h> do not work properly. */
#undef STAT_MACROS_BROKEN
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
#undef TIME_WITH_SYS_TIME

1801
autoconf/config.sub vendored 100644

Plik diff jest za duży Load Diff

Wyświetl plik

Wyświetl plik

@ -0,0 +1,14 @@
X:=
SPACE:=$(X) $(X)
COMMA:=,
HASH:=\#
SQUOTE:='
#'
DQUOTE:="
#"
define NEWLINE
endef
CONF_NAME:=@CONF_NAME@

3647
configure vendored

Plik diff jest za duży Load Diff

47
configure.ac 100644
Wyświetl plik

@ -0,0 +1,47 @@
# Copyright (C) 2020 Fredrik Öhrström
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
AC_PREREQ([2.69])
AC_INIT(wmbusmeters, wmbusmeters, oehrstroem@gmail.com,,https://github.com/weetmuts/wmbusmeters)
AC_CONFIG_AUX_DIR([autoconf])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
SRC_ROOT="$(pwd -L)"
CONF_NAME="${host_cpu}-${host_vendor}-${host_os}"
BUILD_ROOT="$SRC_ROOT/build"
OUTPUT_ROOT="$SRC_ROOT/build/${CONF_NAME}"
mkdir -p "$OUTPUT_ROOT"
AC_LANG_PUSH([C++])
AC_MSG_CHECKING([for rtlsdr])
AC_CHECK_LIB(rtlsdr, rtlsdr_get_device_count, [],
[
AC_MSG_ERROR([Could not find rtlsdr library. Try: sudo apt install librtlsdr-dev])
])
AC_CONFIG_FILES([$OUTPUT_ROOT/spec.gmk:$SRC_ROOT/autoconf/spec.gmk.in])
AC_CONFIG_FILES([$OUTPUT_ROOT/Makefile:$SRC_ROOT/autoconf/Makefile.in])
# Make sure config.status ends up in the build directory instead of the src root.
CONFIG_STATUS="$OUTPUT_ROOT/config.status"
# Write out spec.gmk and build/Makefile
AC_OUTPUT

Wyświetl plik

@ -19,6 +19,7 @@
#include"config.h"
#include"meters.h"
#include"printer.h"
#include"rtlsdr.h"
#include"serial.h"
#include"shell.h"
#include"threads.h"
@ -638,31 +639,31 @@ void perform_auto_scan_of_serial_devices(Configuration *config)
void perform_auto_scan_of_swradio_devices(Configuration *config)
{
// Enumerate all swradio devices, that can be used.
vector<string> devices = serial_manager_->listSWRadioDevices();
vector<string> devices = listRtlSdrDevices();
// Did an unavailable swradio-device get unplugged? Then remove it from the known-not-swradio-device set.
remove_lost_swradio_devices_from_ignore_list(devices);
for (string& device : devices)
{
trace("[MAIN] swradio device %s\n", device.c_str());
trace("[MAIN] rtlsdr device %s\n", device.c_str());
if (not_swradio_wmbus_devices_.count(device) > 0)
{
trace("[MAIN] skipping already probed swradio device %s\n", device.c_str());
trace("[MAIN] skipping already probed rtlsdr device %s\n", device.c_str());
continue;
}
shared_ptr<SerialDevice> sd = serial_manager_->lookup(device);
if (!sd)
{
debug("(main) swradio device %s not currently used, detect contents...\n", device.c_str());
debug("(main) rtlsdr device %s not currently used.\n", device.c_str());
// This serial device is not in use.
Detected detected;
AccessCheck ac = detectRTLSDR(device, &detected, serial_manager_);
AccessCheck ac = detectRTLSDR(device, &detected);
if (ac != AccessCheck::AccessOK)
{
// We cannot access this swradio device.
not_swradio_wmbus_devices_.insert(device);
verbose("(main) ignoring swradio %s since it is unavailable.\n", device.c_str());
verbose("(main) ignoring rtlsdr %s since it is unavailable.\n", device.c_str());
}
else
{

Wyświetl plik

@ -16,6 +16,7 @@
*/
#include"util.h"
#include"rtlsdr.h"
#include"serial.h"
#include"shell.h"
#include"threads.h"
@ -94,7 +95,6 @@ struct SerialCommunicationManagerImp : public SerialCommunicationManager
void stopRegularCallback(int id);
vector<string> listSerialDevices();
vector<string> listSWRadioDevices();
shared_ptr<SerialDevice> lookup(std::string device);
private:
@ -1172,12 +1172,6 @@ vector<string> SerialCommunicationManagerImp::listSerialDevices()
list.push_back("Please add code here!");
return list;
}
vector<string> SerialCommunicationManagerImp::listSWRadioDevices()
{
vector<string> list;
list.push_back("Please add code here!");
return list;
}
#endif
#if defined(__linux__)
@ -1292,44 +1286,6 @@ vector<string> SerialCommunicationManagerImp::listSerialDevices()
return found_serials;
}
vector<string> SerialCommunicationManagerImp::listSWRadioDevices()
{
struct dirent **entries;
vector<string> found_swradios;
string devdir = "/dev/";
int n = scandir(devdir.c_str(), &entries, NULL, sorty);
if (n < 0)
{
perror("scandir");
return found_swradios;
}
for (int i=0; i<n; ++i)
{
string name = entries[i]->d_name;
if (name == ".." || name == ".")
{
free(entries[i]);
continue;
}
// swradio0 swradio1 swradio2 ...
if (name.length() > 7 &&
!strncmp(name.c_str(), "swradio", 7) &&
name[7] >= '0' &&
name[7] <= '9')
{
string rtlsdr = devdir+name;
found_swradios.push_back(rtlsdr);
}
free(entries[i]);
}
free(entries);
return found_swradios;
}
#endif
#define CHECK_SPEED(x) { if (speed == x) return #x; }

Wyświetl plik

@ -101,8 +101,6 @@ struct SerialCommunicationManager
// List all real serial devices (avoid pseudo ttys)
virtual std::vector<std::string> listSerialDevices() = 0;
// List all all rtlsdr swradio devices
virtual std::vector<std::string> listSWRadioDevices() = 0;
// Return a serial device for the given device, if it exists! Otherwise NULL.
virtual std::shared_ptr<SerialDevice> lookup(std::string device) = 0;
virtual ~SerialCommunicationManager();

Wyświetl plik

@ -287,16 +287,3 @@ FrameStatus WMBusRTLWMBUS::checkRTLWMBUSFrame(vector<uchar> &data,
debug("(rtlwmbus) received full frame\n");
return FullFrame;
}
AccessCheck detectRTLSDR(string device, Detected *detected, shared_ptr<SerialCommunicationManager> manager)
{
// No more advanced test than that the /dev/rtlsdr link exists.
AccessCheck rc = checkIfExistsAndSameGroup(device);
if (rc == AccessCheck::AccessOK)
{
detected->set(WMBusDeviceType::DEVICE_RTLWMBUS,0, false);
}
return rc;
}