A single rtlwmbus now works.

pull/156/head
Fredrik Öhrström 2020-10-05 19:47:58 +02:00
rodzic 8cc2123df0
commit d8e7be70c4
9 zmienionych plików z 59 dodań i 48 usunięć

Wyświetl plik

@ -231,10 +231,13 @@ void check_for_dead_wmbus_devices(Configuration *config)
if (!w->isWorking())
{
not_working.push_back(w.get());
notice("Lost %s closing %s(%s)\n",
string id = w->getDeviceId();
if (id != "") id = "["+id+"]";
notice("Lost %s closing %s%s\n",
w->device().c_str(),
toLowerCaseString(w->type()),
w->getDeviceId().c_str());
id.c_str());
}
}
@ -327,8 +330,13 @@ shared_ptr<WMBus> create_wmbus_object(Detected *detected, Configuration *config,
case DEVICE_RTLWMBUS:
{
string command;
string name = "";
int id = 0;
if (!detected->found_tty_override)
{
name = detected->found_file;
id = indexFromRtlSdrName(name);
command = "";
if (detected->specified_device.command != "")
{
@ -357,11 +365,11 @@ shared_ptr<WMBus> create_wmbus_object(Detected *detected, Configuration *config,
}
}
if (command == "") {
command = prefix+"rtl_sdr -f "+freq+" -s 1.6e6 - 2>/dev/null | "+prefix+"rtl_wmbus";
command = prefix+"rtl_sdr -d "+to_string(id)+" -f "+freq+" -s 1.6e6 - 2>/dev/null | "+prefix+"rtl_wmbus";
}
verbose("(rtlwmbus) using command: %s\n", command.c_str());
}
wmbus = openRTLWMBUS("rtlwmbus"/*detected->found_file*/, command, manager,
wmbus = openRTLWMBUS(name, command, manager,
[command](){
warning("(rtlwmbus) child process exited! "
"Command was: \"%s\"\n", command.c_str());
@ -684,10 +692,13 @@ void open_wmbus_device_and_set_linkmodes(Configuration *config, string how, stri
string using_link_modes = lms.hr();
string started = tostrprintf("Started %s %s[%s] on %s listening on %s\n",
string id = detected->found_device_id.c_str();
if (id != "") id = "["+id+"]";
string started = tostrprintf("Started %s %s%s on %s listening on %s\n",
how.c_str(),
toLowerCaseString(detected->found_type),
detected->found_device_id.c_str(),
id.c_str(),
device.c_str(),
using_link_modes.c_str());
@ -783,37 +794,38 @@ 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 = listRtlSdrDevices();
vector<string> names = 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);
remove_lost_swradio_devices_from_ignore_list(names);
for (string& device : devices)
for (string& name : names)
{
trace("[MAIN] rtlsdr device %s\n", device.c_str());
if (not_swradio_wmbus_devices_.count(device) > 0)
trace("[MAIN] rtlsdr device %s\n", name.c_str());
if (not_swradio_wmbus_devices_.count(name) > 0)
{
trace("[MAIN] skipping already probed rtlsdr device %s\n", device.c_str());
trace("[MAIN] skipping already probed rtlsdr %s\n", name.c_str());
continue;
}
shared_ptr<SerialDevice> sd = serial_manager_->lookup(device);
shared_ptr<SerialDevice> sd = serial_manager_->lookup(name);
if (!sd)
{
debug("(main) rtlsdr device %s not currently used.\n", device.c_str());
// This serial device is not in use.
debug("(main) rtlsdr device %s not currently used.\n", name.c_str());
Detected detected;
detected.setSpecifiedDeviceAsAuto();
AccessCheck ac = detectRTLSDR(device, &detected);
AccessCheck ac = detectRTLSDR(name, &detected);
if (ac != AccessCheck::AccessOK)
{
// We cannot access this swradio device.
not_swradio_wmbus_devices_.insert(device);
verbose("(main) ignoring rtlsdr %s since it is unavailable.\n", device.c_str());
not_swradio_wmbus_devices_.insert(name);
verbose("(main) ignoring rtlsdr %s since it is unavailable.\n", name.c_str());
}
else
{
// Use the name as the file.
detected.found_file = name;
find_specified_device_and_update_detected(config, &detected);
open_wmbus_device_and_set_linkmodes(config, "auto", device, &detected);
open_wmbus_device_and_set_linkmodes(config, "auto", name, &detected);
}
}
}

Wyświetl plik

@ -44,17 +44,9 @@ vector<string> listRtlSdrDevices()
return devices;
}
uint32_t index(string &s)
AccessCheck detectRTLSDR(string device, Detected *detected)
{
size_t p = s.find('_');
if (p == string::npos) return -1;
string n = s.substr(0, p);
return (uint32_t)atoi(n.c_str());
}
AccessCheck detectRTLSDR(string id, Detected *detected)
{
uint32_t i = index(id);
uint32_t i = indexFromRtlSdrName(device);
uint32_t n = rtlsdr_get_device_count();
@ -62,7 +54,7 @@ AccessCheck detectRTLSDR(string id, Detected *detected)
// Would be nice to properly test if the device can be opened.
if (i < n)
{
detected->setAsFound(id, WMBusDeviceType::DEVICE_RTLWMBUS, 0, false);
detected->setAsFound("", WMBusDeviceType::DEVICE_RTLWMBUS, 0, false);
return AccessCheck::AccessOK;
}

Wyświetl plik

@ -388,7 +388,7 @@ bool SerialDeviceTTY::working()
struct SerialDeviceCommand : public SerialDeviceImp
{
SerialDeviceCommand(string device, string command, vector<string> args, vector<string> envs,
SerialDeviceCommand(string identifier, string command, vector<string> args, vector<string> envs,
SerialCommunicationManagerImp *manager,
function<void()> on_exit,
string purpose);
@ -399,12 +399,12 @@ struct SerialDeviceCommand : public SerialDeviceImp
bool send(vector<uchar> &data);
int available();
bool working();
string device() { return device_; }
string device() { return identifier_; }
string command() { return command_; }
private:
string device_;
string identifier_;
string command_;
int pid_ {};
vector<string> args_;
@ -415,7 +415,7 @@ struct SerialDeviceCommand : public SerialDeviceImp
function<void()> on_exit_;
};
SerialDeviceCommand::SerialDeviceCommand(string device,
SerialDeviceCommand::SerialDeviceCommand(string identifier,
string command,
vector<string> args,
vector<string> envs,
@ -424,8 +424,8 @@ SerialDeviceCommand::SerialDeviceCommand(string device,
string purpose)
: SerialDeviceImp(manager, purpose)
{
assert(device != "");
device_ = device;
assert(identifier != "");
identifier_ = identifier;
command_ = command;
args_ = args;
envs_ = envs;
@ -671,14 +671,14 @@ shared_ptr<SerialDevice> SerialCommunicationManagerImp::createSerialDeviceTTY(st
return addSerialDeviceForManagement(new SerialDeviceTTY(device, baud_rate, this, purpose));
}
shared_ptr<SerialDevice> SerialCommunicationManagerImp::createSerialDeviceCommand(string device,
shared_ptr<SerialDevice> SerialCommunicationManagerImp::createSerialDeviceCommand(string identifier,
string command,
vector<string> args,
vector<string> envs,
function<void()> on_exit,
string purpose)
{
return addSerialDeviceForManagement(new SerialDeviceCommand(device, command, args, envs, this, on_exit, purpose));
return addSerialDeviceForManagement(new SerialDeviceCommand(identifier, command, args, envs, this, on_exit, purpose));
}
shared_ptr<SerialDevice> SerialCommunicationManagerImp::createSerialDeviceFile(string file, string purpose)

Wyświetl plik

@ -71,7 +71,7 @@ struct SerialCommunicationManager
// Read from a /dev/ttyUSB0 or /dev/ttyACM0 device with baud settings.
virtual shared_ptr<SerialDevice> createSerialDeviceTTY(string dev, int baud_rate, string purpose) = 0;
// Read from a sub shell.
virtual shared_ptr<SerialDevice> createSerialDeviceCommand(string device,
virtual shared_ptr<SerialDevice> createSerialDeviceCommand(string identifier,
string command,
vector<string> args,
vector<string> envs,

Wyświetl plik

@ -1506,3 +1506,11 @@ vector<string> splitString(string &s, char c)
}
return v;
}
uint32_t indexFromRtlSdrName(string &s)
{
size_t p = s.find('_');
if (p == string::npos) return -1;
string n = s.substr(0, p);
return (uint32_t)atoi(n.c_str());
}

Wyświetl plik

@ -173,5 +173,6 @@ bool startsWith(std::string s, std::vector<uchar> &data);
// Sum the memory used by the heap and stack.
size_t memoryUsage();
uint32_t indexFromRtlSdrName(std::string &s);
#endif

Wyświetl plik

@ -593,8 +593,6 @@ AccessCheck detectRTL433(Detected *detected, shared_ptr<SerialCommunicationManag
AccessCheck detectRTLWMBUS(Detected *detected, shared_ptr<SerialCommunicationManager> handler);
AccessCheck detectWMB13U(Detected *detected, shared_ptr<SerialCommunicationManager> handler);
AccessCheck detectRTLSDR(Detected *detected, shared_ptr<SerialCommunicationManager> handler);
// Try to factory reset an AMB8465 by trying all possible serial speeds and
// restore to factory settings.
AccessCheck factoryResetAMB8465(string tty, shared_ptr<SerialCommunicationManager> handler, int *was_baud);

Wyświetl plik

@ -73,9 +73,10 @@ private:
string setup_;
};
shared_ptr<WMBus> openRTLWMBUS(string device, string command, shared_ptr<SerialCommunicationManager> manager,
shared_ptr<WMBus> openRTLWMBUS(string identifier, string command, shared_ptr<SerialCommunicationManager> manager,
function<void()> on_exit, shared_ptr<SerialDevice> serial_override)
{
debug("(rtlwmbus) opening %s\n", identifier.c_str());
vector<string> args;
vector<string> envs;
args.push_back("-c");
@ -85,7 +86,7 @@ shared_ptr<WMBus> openRTLWMBUS(string device, string command, shared_ptr<SerialC
WMBusRTLWMBUS *imp = new WMBusRTLWMBUS(serial_override, manager);
return shared_ptr<WMBus>(imp);
}
auto serial = manager->createSerialDeviceCommand(device, "/bin/sh", args, envs, on_exit, "rtlwmbus");
auto serial = manager->createSerialDeviceCommand(identifier, "/bin/sh", args, envs, on_exit, "rtlwmbus");
WMBusRTLWMBUS *imp = new WMBusRTLWMBUS(serial, manager);
return shared_ptr<WMBus>(imp);
}
@ -103,7 +104,7 @@ bool WMBusRTLWMBUS::ping()
string WMBusRTLWMBUS::getDeviceId()
{
return "?";
return "";
}
LinkModeSet WMBusRTLWMBUS::getLinkModes()
@ -290,7 +291,6 @@ FrameStatus WMBusRTLWMBUS::checkRTLWMBUSFrame(vector<uchar> &data,
AccessCheck detectRTLWMBUS(Detected *detected, shared_ptr<SerialCommunicationManager> handler)
{
detected->setAsFound("", WMBusDeviceType::DEVICE_RTLWMBUS, 0, false);
return AccessCheck::AccessOK;
assert(0);
return AccessCheck::NotThere;
}

Wyświetl plik

@ -27,7 +27,7 @@ then
fi
cat <<EOF > $TEST/test_expected.txt
Started config rtlwmbus[] on stdin listening on any
Started config rtlwmbus on stdin listening on any
(wmbus) decrypted content failed check, did you use the correct decryption key? Ignoring telegram.
(wmbus) decrypted payload crc failed check, did you use the correct decryption key? Ignoring telegram.
(wmbus) decrypted content failed check, did you use the correct decryption key? Ignoring telegram.