Fix so that rtl433 works again.

pull/267/head
Fredrik Öhrström 2021-03-06 15:44:38 +01:00
rodzic 30c2926489
commit 0c9fdcd81d
5 zmienionych plików z 74 dodań i 56 usunięć

Wyświetl plik

@ -224,7 +224,7 @@ wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
@echo But the deb package is not yet working correctly! Work in progress.
snapcraft:
snapcraft --config snap/snapcraft.yaml
snapcraft
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/version.h

Wyświetl plik

@ -109,9 +109,10 @@ shared_ptr<Printer> printer_;
// Set as true when the warning for no detected wmbus devices has been printed.
bool printed_warning_ = false;
// Then check if the rtl_sdr and/or rtl_wmbus is in the path.
// Then check if the rtl_sdr and/or rtl_wmbus and/or rtl_433 is available.
bool rtlsdr_found_ = false;
bool rtlwmbus_found_ = false;
bool rtl433_found_ = false;
int main(int argc, char **argv)
{
@ -347,44 +348,8 @@ shared_ptr<WMBus> create_wmbus_object(Detected *detected, Configuration *config,
wmbus = openRTLWMBUS(*detected, config->bin_dir, config->daemon, manager, serial_override);
break;
case DEVICE_RTL433:
{
string command;
string identifier = detected->found_file;
int id = 0;
if (!detected->found_tty_override)
{
id = indexFromRtlSdrName(identifier);
command = "";
if (detected->specified_device.command != "")
{
command = detected->specified_device.command;
identifier = "cmd_"+to_string(detected->specified_device.index);
}
string freq = "868.95M";
if (detected->specified_device.fq != "")
{
freq = detected->specified_device.fq;
}
string prefix = "";
if (config->daemon) {
prefix = "/usr/bin/";
if (command == "")
{
// Default command is used, check that the binaries are in place.
if (!checkFileExists("/usr/bin/rtl_433"))
{
error("(rtl433) error: when starting as daemon, wmbusmeters expects /usr/bin/rtl_433 to exist!\n");
}
}
}
if (command == "") {
command = prefix+"rtl_433 -d "+to_string(id)+" -F csv -f "+freq;
}
verbose("(rtl433) using command: %s\n", command.c_str());
}
wmbus = openRTL433(identifier, command, manager, serial_override);
wmbus = openRTL433(*detected, config->bin_dir, config->daemon, manager, serial_override);
break;
}
case DEVICE_CUL:
{
verbose("(cul) on %s\n", detected->found_file.c_str());
@ -587,7 +552,9 @@ SpecifiedDevice *find_specified_device_from_detected(Configuration *c, Detected
// This will find specified devices like: im871a[12345678]
for (SpecifiedDevice & sd : c->supplied_bus_devices)
{
if (sd.file == "" && sd.id != "" && sd.id == d->found_device_id && sd.type == d->found_type)
if (sd.file == "" && sd.id != "" && sd.id == d->found_device_id &&
(sd.type == d->found_type ||
(sd.type == DEVICE_RTL433 && d->found_type == DEVICE_RTLWMBUS)))
{
return &sd;
}
@ -597,7 +564,9 @@ SpecifiedDevice *find_specified_device_from_detected(Configuration *c, Detected
// This will find specified devices like: im871a, rtlwmbus
for (SpecifiedDevice & sd : c->supplied_bus_devices)
{
if (sd.file == "" && sd.id == "" && sd.type == d->found_type)
if (sd.file == "" && sd.id == "" &&
(sd.type == d->found_type ||
(sd.type == DEVICE_RTL433 && d->found_type == DEVICE_RTLWMBUS)))
{
return &sd;
}
@ -612,6 +581,11 @@ bool find_specified_device_and_update_detected(Configuration *c, Detected *d)
if (sd)
{
if (sd->type == DEVICE_RTL433 && d->found_type == DEVICE_RTLWMBUS)
{
d->found_type = DEVICE_RTL433;
}
d->specified_device = *sd;
debug("(main) found specified device (%s) that matches detected device (%s)\n",
sd->str().c_str(),
@ -900,6 +874,7 @@ void perform_auto_scan_of_swradio_devices(Configuration *config)
{
rtlsdr_found_ = check_if_rtlsdr_exists_in_path();
rtlwmbus_found_ = check_if_rtlwmbus_exists_in_path();
// rtl433_found_ = check_if_rtl433_exists_in_path();
}
if (!rtlsdr_found_)
{

Wyświetl plik

@ -1816,8 +1816,6 @@ std::string currentProcessExe()
return "";
}
return buf;
}
#else
# if (defined(__FreeBSD__))
const char *self = "/proc/curproc/file";

Wyświetl plik

@ -602,7 +602,10 @@ shared_ptr<WMBus> openRTLWMBUS(Detected detected,
bool daemon,
shared_ptr<SerialCommunicationManager> manager,
shared_ptr<SerialDevice> serial_override);
shared_ptr<WMBus> openRTL433(string identifier, string command, shared_ptr<SerialCommunicationManager> manager,
shared_ptr<WMBus> openRTL433(Detected detected,
string bin_dir,
bool daemon,
shared_ptr<SerialCommunicationManager> manager,
shared_ptr<SerialDevice> serial_override);
shared_ptr<WMBus> openCUL(string device, shared_ptr<SerialCommunicationManager> manager,
shared_ptr<SerialDevice> serial_override);

Wyświetl plik

@ -18,6 +18,7 @@
#include"wmbus.h"
#include"wmbus_common_implementation.h"
#include"wmbus_utils.h"
#include"rtlsdr.h"
#include"serial.h"
#include<assert.h>
@ -57,9 +58,11 @@ struct WMBusRTL433 : public virtual WMBusCommonImplementation
void processSerialData();
void simulate();
WMBusRTL433(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
WMBusRTL433(string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
private:
string serialnr_;
shared_ptr<SerialDevice> serial_;
vector<uchar> read_buffer_;
vector<uchar> received_payload_;
@ -74,26 +77,67 @@ private:
string setup_;
};
shared_ptr<WMBus> openRTL433(string identifier, string command, shared_ptr<SerialCommunicationManager> manager,
shared_ptr<WMBus> openRTL433(Detected detected, string bin_dir, bool daemon,
shared_ptr<SerialCommunicationManager> manager,
shared_ptr<SerialDevice> serial_override)
{
assert(identifier != "");
string identifier = detected.found_device_id;
SpecifiedDevice &device = detected.specified_device;
string command;
int id = 0;
if (!serial_override)
{
id = indexFromRtlSdrSerial(identifier);
command = "";
if (device.command != "")
{
command = device.command;
identifier = "cmd_"+to_string(device.index);
}
string freq = "868.95M";
if (device.fq != "")
{
freq = device.fq;
}
string rtl_433 = lookForExecutable("rtl_433", bin_dir, "/usr/bin");
if (rtl_433 == "")
{
if (daemon)
{
error("(rtl433) error: when starting as daemon, wmbusmeters looked for %s/rtl_433 and %s/rtl_sdr, but found neither!\n",
bin_dir.c_str(), "/usr/bin");
}
else
{
// Look for it in the PATH
rtl_433 = "rtl_433";
}
}
if (command == "")
{
command = rtl_433+" -d "+to_string(id)+" -F csv -f "+freq;
}
verbose("(rtl433) using command: %s\n", command.c_str());
}
vector<string> args;
vector<string> envs;
args.push_back("-c");
args.push_back(command);
if (serial_override)
{
WMBusRTL433 *imp = new WMBusRTL433(serial_override, manager);
WMBusRTL433 *imp = new WMBusRTL433(identifier, serial_override, manager);
return shared_ptr<WMBus>(imp);
}
auto serial = manager->createSerialDeviceCommand(identifier, "/bin/sh", args, envs, "rtl433");
WMBusRTL433 *imp = new WMBusRTL433(serial, manager);
WMBusRTL433 *imp = new WMBusRTL433(identifier, serial, manager);
return shared_ptr<WMBus>(imp);
}
WMBusRTL433::WMBusRTL433(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_RTL433, manager, serial, false)
WMBusRTL433::WMBusRTL433(string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_RTL433, manager, serial, false), serialnr_(serialnr)
{
reset();
}
@ -105,7 +149,7 @@ bool WMBusRTL433::ping()
string WMBusRTL433::getDeviceId()
{
return "?";
return serialnr_;
}
string WMBusRTL433::getDeviceUniqueId()
@ -305,8 +349,6 @@ FrameStatus WMBusRTL433::checkRTL433Frame(vector<uchar> &data,
AccessCheck detectRTL433(Detected *detected, shared_ptr<SerialCommunicationManager> handler)
{
detected->setAsFound("", WMBusDeviceType::DEVICE_RTL433, 0, false,
detected->specified_device.linkmodes);
return AccessCheck::AccessOK;
assert(0);
return AccessCheck::NotThere;
}