From dd39fe55f77cd0c94bd9119f43303873fdb1800d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Sat, 6 Mar 2021 16:28:42 +0100 Subject: [PATCH] Add ppm support for rtlsdr. --- README.md | 12 +++++++++--- src/main.cc | 5 ++++- src/util.cc | 13 +++++++++++++ src/util.h | 4 ++++ src/wmbus_rtl433.cc | 17 ++++++++++++++++- src/wmbus_rtlwmbus.cc | 31 ++++++++++++++++++++++++++++--- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2599157..3dcaf5a 100644 --- a/README.md +++ b/README.md @@ -214,13 +214,19 @@ rtlsdr dongle like this `rtlwmbus[1234]`. /dev/ttyUSB0:38400, to have wmbusmeters set the baud rate to 38400 and listen for raw wmbus telegrams. These telegrams are expected to have the data link layer crc bytes removed already! -rtlwmbus, to spawn the background process: "rtl_sdr -f 868.95M -s 1600000 - 2>/dev/null | rtl_wmbus" -for each attached rtlsdr dongle. +rtlwmbus, to spawn the background process: "rtl_sdr -f 868.625M -s 1600000 - 2>/dev/null | rtl_wmbus -s" +for each attached rtlsdr dongle. This will listen to S1,T1 and C1 meters in parallel. -rtlwmbus:868.9M, to tune to this fq instead. +rtlwmbus(ppm=17), to tune your rtlsdr dongle accordingly. Use this to tune your dongle and at +the same time listen to S1,T1 and C1. + +rtlwmbus:868.9M, to tune to this fq instead. This will listen to exactly to what is on this frequency, +ie no more S1,T1 and C1 at the same time since they are on different frequencies. rtl433, to spawn the background process: "rtl_433 -F csv -f 868.95M" +rtl433(ppm=17), to tune your rtlsdr dongle accordingly. + rtl433:868.9M, to tune to this fq instead. rtlwmbus:CMD(), to specify the entire background process command line that is expected to produce rtlwbus compatible output. diff --git a/src/main.cc b/src/main.cc index 58755db..9ada488 100644 --- a/src/main.cc +++ b/src/main.cc @@ -735,6 +735,8 @@ void open_bus_device_and_potentially_set_linkmodes(Configuration *config, string string id = detected->found_device_id.c_str(); if (id != "") id = "["+id+"]"; + string extras = detected->specified_device.extras.c_str(); + if (extras != "") extras = "("+extras+")"; string fq = detected->specified_device.fq; if (fq != "") fq = " using fq "+fq; string file = detected->found_file.c_str(); @@ -753,10 +755,11 @@ void open_bus_device_and_potentially_set_linkmodes(Configuration *config, string fq.c_str(), cmd.c_str()); } - string started = tostrprintf("Started %s %s%s%s%s\n", + string started = tostrprintf("Started %s %s%s%s%s%s\n", how.c_str(), toLowerCaseString(detected->found_type), id.c_str(), + extras.c_str(), file.c_str(), listening.c_str()); diff --git a/src/util.cc b/src/util.cc index bad3360..5d2b1c3 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1852,3 +1852,16 @@ string lookForExecutable(string prog, string bin_dir, string default_dir) } return ""; } + +bool parseExtras(string s, map *extras) +{ + vector parts = splitString(s, ' '); + + for (auto &p : parts) + { + vector kv = splitString(p, '='); + if (kv.size() != 2) return false; + (*extras)[kv[0]] = kv[1]; + } + return true; +} diff --git a/src/util.h b/src/util.h index 5e27668..e3ab5d2 100644 --- a/src/util.h +++ b/src/util.h @@ -22,6 +22,7 @@ #include #include #include +#include #include enum class MeterType; @@ -202,4 +203,7 @@ std::string dirname(std::string p); std::string lookForExecutable(std::string prog, std::string bin_dir, std::string default_dir); +// Extract from "ppm=5 radix=7" and put key values into map. +bool parseExtras(std::string s, std::map *extras); + #endif diff --git a/src/wmbus_rtl433.cc b/src/wmbus_rtl433.cc index 2a27b10..f353d96 100644 --- a/src/wmbus_rtl433.cc +++ b/src/wmbus_rtl433.cc @@ -85,6 +85,21 @@ shared_ptr openRTL433(Detected detected, string bin_dir, bool daemon, SpecifiedDevice &device = detected.specified_device; string command; int id = 0; + map extras; + + bool ok = parseExtras(detected.specified_device.extras, &extras); + if (!ok) + { + error("(rtlwmbus) invalid extra parameters to rtlwmbus (%s)\n", detected.specified_device.extras.c_str()); + } + string ppm = ""; + if (extras.size() > 0) + { + if (extras.count("ppm") > 0) + { + ppm = string("-p ")+extras["ppm"]; + } + } if (!serial_override) { @@ -117,7 +132,7 @@ shared_ptr openRTL433(Detected detected, string bin_dir, bool daemon, } if (command == "") { - command = rtl_433+" -d "+to_string(id)+" -F csv -f "+freq; + command = rtl_433+" "+ppm+" -d "+to_string(id)+" -F csv -f "+freq; } verbose("(rtl433) using command: %s\n", command.c_str()); } diff --git a/src/wmbus_rtlwmbus.cc b/src/wmbus_rtlwmbus.cc index 1109a90..e40f5da 100644 --- a/src/wmbus_rtlwmbus.cc +++ b/src/wmbus_rtlwmbus.cc @@ -45,9 +45,10 @@ struct WMBusRTLWMBUS : public virtual WMBusCommonImplementation LinkModeSet supportedLinkModes() { return C1_bit | + S1_bit | T1_bit; } - int numConcurrentLinkModes() { return 2; } + int numConcurrentLinkModes() { return 3; } bool canSetLinkModes(LinkModeSet lms) { //if (!supportedLinkModes().supports(lms)) return false; @@ -90,7 +91,21 @@ shared_ptr openRTLWMBUS(Detected detected, SpecifiedDevice &device = detected.specified_device; string command; int id = 0; + map extras; + bool ok = parseExtras(detected.specified_device.extras, &extras); + if (!ok) + { + error("(rtlwmbus) invalid extra parameters to rtlwmbus (%s)\n", detected.specified_device.extras.c_str()); + } + string ppm = ""; + if (extras.size() > 0) + { + if (extras.count("ppm") > 0) + { + ppm = string("-p ")+extras["ppm"]; + } + } if (!serial_override) { id = indexFromRtlSdrSerial(identifier); @@ -101,10 +116,13 @@ shared_ptr openRTLWMBUS(Detected detected, command = device.command; identifier = "cmd_"+to_string(device.index); } - string freq = "868.95M"; + string freq = "868.625M"; + bool force_freq = false; if (device.fq != "") { freq = device.fq; + // This will disable the listen to s1,t1 and c1 at the same time setting. + force_freq = true; } string rtl_sdr; string rtl_wmbus; @@ -138,7 +156,14 @@ shared_ptr openRTLWMBUS(Detected detected, } if (command == "") { - command = rtl_sdr+" -d "+to_string(id)+" -f "+freq+" -s 1.6e6 - 2>/dev/null | "+rtl_wmbus; + if (!force_freq) + { + command = rtl_sdr+" "+ppm+" -d "+to_string(id)+" -f "+freq+" -s 1.6e6 - 2>/dev/null | "+rtl_wmbus+" -s"; + } + else + { + command = rtl_sdr+" "+ppm+" -d "+to_string(id)+" -f "+freq+" -s 1.6e6 - 2>/dev/null | "+rtl_wmbus; + } } verbose("(rtlwmbus) using command: %s\n", command.c_str()); }