kopia lustrzana https://github.com/weetmuts/wmbusmeters
A device (mbus/wmbus/tty) can now have an alias. A meter spec can now refer to this alias.
rodzic
5eea15b18c
commit
21d3595a53
17
src/bus.cc
17
src/bus.cc
|
@ -202,11 +202,11 @@ shared_ptr<WMBus> BusManager::createWmbusObject(Detected *detected, Configuratio
|
|||
break;
|
||||
case DEVICE_SIMULATION:
|
||||
verbose("(simulation) in %s\n", detected->found_file.c_str());
|
||||
wmbus = openSimulator(detected->found_file, serial_manager_, serial_override);
|
||||
wmbus = openSimulator(*detected, serial_manager_, serial_override);
|
||||
break;
|
||||
case DEVICE_RAWTTY:
|
||||
verbose("(rawtty) on %s\n", detected->found_file.c_str());
|
||||
wmbus = openRawTTY(detected->found_file, detected->found_bps, serial_manager_, serial_override);
|
||||
wmbus = openRawTTY(*detected, serial_manager_, serial_override);
|
||||
break;
|
||||
case DEVICE_RTLWMBUS:
|
||||
wmbus = openRTLWMBUS(*detected, config->bin_dir, config->daemon, serial_manager_, serial_override);
|
||||
|
@ -217,13 +217,13 @@ shared_ptr<WMBus> BusManager::createWmbusObject(Detected *detected, Configuratio
|
|||
case DEVICE_CUL:
|
||||
{
|
||||
verbose("(cul) on %s\n", detected->found_file.c_str());
|
||||
wmbus = openCUL(detected->found_file, serial_manager_, serial_override);
|
||||
wmbus = openCUL(*detected, serial_manager_, serial_override);
|
||||
break;
|
||||
}
|
||||
case DEVICE_RC1180:
|
||||
{
|
||||
verbose("(rc1180) on %s\n", detected->found_file.c_str());
|
||||
wmbus = openRC1180(detected->found_file, serial_manager_, serial_override);
|
||||
wmbus = openRC1180(*detected, serial_manager_, serial_override);
|
||||
break;
|
||||
}
|
||||
case DEVICE_UNKNOWN:
|
||||
|
@ -734,3 +734,12 @@ SpecifiedDevice *BusManager::find_specified_device_from_detected(Configuration *
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WMBus* BusManager::findBus(string name)
|
||||
{
|
||||
for (auto &w : bus_devices_)
|
||||
{
|
||||
if (w->alias() == name) return w.get();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
16
src/bus.h
16
src/bus.h
|
@ -24,8 +24,15 @@
|
|||
#include"units.h"
|
||||
#include"wmbus.h"
|
||||
|
||||
#include<memory>
|
||||
#include<set>
|
||||
#include<string>
|
||||
|
||||
enum class DetectionType { STDIN_FILE_SIMULATION, ALL };
|
||||
|
||||
struct MeterManager;
|
||||
struct Configuration;
|
||||
|
||||
struct BusManager
|
||||
{
|
||||
BusManager(shared_ptr<SerialCommunicationManager> serial_manager,
|
||||
|
@ -41,6 +48,7 @@ struct BusManager
|
|||
void regularCheckup();
|
||||
|
||||
int numBusDevices() { return bus_devices_.size(); }
|
||||
WMBus *findBus(string name);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -69,18 +77,18 @@ private:
|
|||
|
||||
// Remember devices that were not detected as wmbus devices.
|
||||
// To avoid probing them again and again.
|
||||
set<string> not_serial_wmbus_devices_;
|
||||
std::set<std::string> not_serial_wmbus_devices_;
|
||||
|
||||
// The software radio devices are always swradio devices
|
||||
// but they might not be available for wmbusmeters.
|
||||
set<string> not_swradio_wmbus_devices_;
|
||||
std::set<std::string> not_swradio_wmbus_devices_;
|
||||
|
||||
// When manually supplying stdin or a file, then, after
|
||||
// it has been read, do not open it again!
|
||||
set<string> do_not_open_file_again_;
|
||||
std::set<std::string> do_not_open_file_again_;
|
||||
|
||||
// Store simulation files here.
|
||||
set<string> simulation_files_;
|
||||
std::set<std::string> simulation_files_;
|
||||
|
||||
// Set as true when the warning for no detected wmbus devices has been printed.
|
||||
bool printed_warning_ = false;
|
||||
|
|
|
@ -293,7 +293,7 @@ void regular_checkup(Configuration *config)
|
|||
}
|
||||
}
|
||||
|
||||
meter_manager_->pollMeters();
|
||||
meter_manager_->pollMeters(bus_manager_);
|
||||
|
||||
if (serial_manager_ && config)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ struct MBusRawTTY : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate() { }
|
||||
|
||||
MBusRawTTY(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
MBusRawTTY(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~MBusRawTTY() { }
|
||||
|
||||
private:
|
||||
|
@ -55,6 +55,7 @@ private:
|
|||
|
||||
shared_ptr<WMBus> openMBUS(Detected detected, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string device = detected.found_file;
|
||||
int bps = detected.found_bps;
|
||||
|
||||
|
@ -62,17 +63,17 @@ shared_ptr<WMBus> openMBUS(Detected detected, shared_ptr<SerialCommunicationMana
|
|||
|
||||
if (serial_override)
|
||||
{
|
||||
MBusRawTTY *imp = new MBusRawTTY(serial_override, manager);
|
||||
MBusRawTTY *imp = new MBusRawTTY(alias, serial_override, manager);
|
||||
imp->markAsNoLongerSerial();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
auto serial = manager->createSerialDeviceTTY(device.c_str(), bps, PARITY::EVEN, "mbus");
|
||||
MBusRawTTY *imp = new MBusRawTTY(serial, manager);
|
||||
MBusRawTTY *imp = new MBusRawTTY(alias, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
MBusRawTTY::MBusRawTTY(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_MBUS, manager, serial, true)
|
||||
MBusRawTTY::MBusRawTTY(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_MBUS, manager, serial, true)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include"bus.h"
|
||||
#include"dvparser.h"
|
||||
#include"meters.h"
|
||||
#include"meters_common_implementation.h"
|
||||
|
@ -28,7 +29,7 @@ struct MeterPIIGTH : public virtual TempHygroMeter, public virtual MeterCommonIm
|
|||
double currentRelativeHumidity();
|
||||
|
||||
private:
|
||||
void poll();
|
||||
void poll(shared_ptr<BusManager> bus_manager);
|
||||
void processContent(Telegram *t);
|
||||
|
||||
double current_temperature_c_ {};
|
||||
|
@ -93,9 +94,17 @@ double MeterPIIGTH::currentRelativeHumidity()
|
|||
return current_relative_humidity_rh_;
|
||||
}
|
||||
|
||||
void MeterPIIGTH::poll()
|
||||
void MeterPIIGTH::poll(shared_ptr<BusManager> bus_manager)
|
||||
{
|
||||
fprintf(stderr, "SENDING Query...\n");
|
||||
|
||||
WMBus *dev = bus_manager->findBus(bus());
|
||||
|
||||
if (!dev)
|
||||
{
|
||||
fprintf(stderr, "Could not find bus from name %s\n", bus().c_str());
|
||||
return;
|
||||
}
|
||||
vector<uchar> buf(5);
|
||||
buf[0] = 0x10; // Start
|
||||
buf[1] = 0x40; // SND_NKE
|
||||
|
@ -105,7 +114,7 @@ void MeterPIIGTH::poll()
|
|||
buf[3] = cs; // checksum
|
||||
buf[4] = 0x16; // Stop
|
||||
|
||||
bus()->serial()->send(buf);
|
||||
dev->serial()->send(buf);
|
||||
|
||||
sleep(2);
|
||||
|
||||
|
@ -117,7 +126,7 @@ void MeterPIIGTH::poll()
|
|||
buf[3] = cs; // checksum
|
||||
buf[4] = 0x16; // Stop
|
||||
|
||||
bus()->serial()->send(buf);
|
||||
dev->serial()->send(buf);
|
||||
}
|
||||
|
||||
void MeterPIIGTH::processContent(Telegram *t)
|
||||
|
|
|
@ -245,11 +245,11 @@ public:
|
|||
on_meter_updated_ = cb;
|
||||
}
|
||||
|
||||
void pollMeters()
|
||||
void pollMeters(shared_ptr<BusManager> bus)
|
||||
{
|
||||
for (auto &m : meters_)
|
||||
{
|
||||
m->poll();
|
||||
m->poll(bus);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ shared_ptr<MeterManager> createMeterManager(bool daemon)
|
|||
|
||||
MeterCommonImplementation::MeterCommonImplementation(MeterInfo &mi,
|
||||
MeterDriver driver) :
|
||||
driver_(driver), bus_(NULL), name_(mi.name)
|
||||
driver_(driver), bus_(mi.bus), name_(mi.name)
|
||||
{
|
||||
ids_ = mi.ids;
|
||||
idsc_ = toIdsCommaSeparated(ids_);
|
||||
|
@ -344,7 +344,7 @@ void MeterCommonImplementation::addPrint(string vname, Quantity vquantity,
|
|||
prints_.push_back( { vname, vquantity, defaultUnitForQuantity(vquantity), NULL, getValueFunc, help, field, json, vname } );
|
||||
}
|
||||
|
||||
void MeterCommonImplementation::poll()
|
||||
void MeterCommonImplementation::poll(shared_ptr<BusManager> bus)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -563,7 +563,7 @@ void MeterCommonImplementation::setIndex(int i)
|
|||
index_ = i;
|
||||
}
|
||||
|
||||
WMBus *MeterCommonImplementation::bus()
|
||||
string MeterCommonImplementation::bus()
|
||||
{
|
||||
return bus_;
|
||||
}
|
||||
|
@ -1119,3 +1119,28 @@ bool MeterInfo::parse(string n, string d, string i, string k)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isValidKey(string& key, MeterDriver mt)
|
||||
{
|
||||
if (key.length() == 0) return true;
|
||||
if (key == "NOKEY") {
|
||||
key = "";
|
||||
return true;
|
||||
}
|
||||
if (mt == MeterDriver::IZAR ||
|
||||
mt == MeterDriver::HYDRUS)
|
||||
{
|
||||
// These meters can either be OMS compatible 128 bit key (32 hex).
|
||||
// Or using an older proprietary encryption with 64 bit keys (16 hex)
|
||||
if (key.length() != 16 && key.length() != 32) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// OMS compliant meters have 128 bit AES keys (32 hex).
|
||||
// There is a deprecated DES mode, but I have not yet
|
||||
// seen any telegram using that mode.
|
||||
if (key.length() != 32) return false;
|
||||
}
|
||||
vector<uchar> tmp;
|
||||
return hex2bin(key, &tmp);
|
||||
}
|
||||
|
|
10
src/meters.h
10
src/meters.h
|
@ -113,6 +113,8 @@ bool isMeterDriverValid(MeterDriver type, int manufacturer, int media, int versi
|
|||
// Return the best driver match for a telegram.
|
||||
MeterDriver pickMeterDriver(Telegram *t);
|
||||
|
||||
bool isValidKey(string& key, MeterDriver mt);
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
@ -190,6 +192,8 @@ struct Print
|
|||
string field_name; // Field name for default unit.
|
||||
};
|
||||
|
||||
struct BusManager;
|
||||
|
||||
struct Meter
|
||||
{
|
||||
// Meters are instantiated on the fly from a template, when a telegram arrives
|
||||
|
@ -197,7 +201,7 @@ struct Meter
|
|||
virtual int index() = 0;
|
||||
virtual void setIndex(int i) = 0;
|
||||
// Use this bus to send messages to the meter.
|
||||
virtual WMBus *bus() = 0;
|
||||
virtual string bus() = 0;
|
||||
// This meter listens to these ids.
|
||||
virtual vector<string> &ids() = 0;
|
||||
// Comma separated ids.
|
||||
|
@ -237,7 +241,7 @@ struct Meter
|
|||
virtual void addConversions(std::vector<Unit> cs) = 0;
|
||||
virtual void addShell(std::string cmdline) = 0;
|
||||
virtual vector<string> &shellCmdlines() = 0;
|
||||
virtual void poll() = 0;
|
||||
virtual void poll(shared_ptr<BusManager> bus) = 0;
|
||||
|
||||
virtual ~Meter() = default;
|
||||
};
|
||||
|
@ -254,7 +258,7 @@ struct MeterManager
|
|||
virtual bool hasMeters() = 0;
|
||||
virtual void onTelegram(function<void(AboutTelegram&,vector<uchar>)> cb) = 0;
|
||||
virtual void whenMeterUpdated(std::function<void(Telegram*t,Meter*)> cb) = 0;
|
||||
virtual void pollMeters() = 0;
|
||||
virtual void pollMeters(shared_ptr<BusManager> bus) = 0;
|
||||
|
||||
virtual ~MeterManager() = default;
|
||||
};
|
||||
|
|
|
@ -28,7 +28,7 @@ struct MeterCommonImplementation : public virtual Meter
|
|||
{
|
||||
int index();
|
||||
void setIndex(int i);
|
||||
WMBus *bus();
|
||||
string bus();
|
||||
vector<string>& ids();
|
||||
string idsc();
|
||||
vector<string> fields();
|
||||
|
@ -80,7 +80,7 @@ protected:
|
|||
function<std::string()> getValueFunc, string help, bool field, bool json);
|
||||
// The default implementation of poll does nothing.
|
||||
// Override for mbus meters that need to be queried and likewise for C2/T2 wmbus-meters.
|
||||
void poll();
|
||||
void poll(shared_ptr<BusManager> bus);
|
||||
bool handleTelegram(AboutTelegram &about, vector<uchar> frame, bool simulated, string *id, bool *id_match);
|
||||
void printMeter(Telegram *t,
|
||||
string *human_readable,
|
||||
|
@ -96,7 +96,7 @@ private:
|
|||
|
||||
int index_ {};
|
||||
MeterDriver driver_ {};
|
||||
WMBus *bus_ {};
|
||||
string bus_ {};
|
||||
MeterKeys meter_keys_ {};
|
||||
ELLSecurityMode expected_ell_sec_mode_ {};
|
||||
TPLSecurityMode expected_tpl_sec_mode_ {};
|
||||
|
|
|
@ -245,7 +245,7 @@ int test_linkmodes()
|
|||
shared_ptr<WMBus> wmbus_im871a = openIM871A(de, manager, serial1);
|
||||
shared_ptr<WMBus> wmbus_amb8465 = openAMB8465(de, manager, serial2);
|
||||
shared_ptr<WMBus> wmbus_rtlwmbus = openRTLWMBUS(de, "", false, manager, serial3);
|
||||
shared_ptr<WMBus> wmbus_rawtty = openRawTTY("", 0, manager, serial4);
|
||||
shared_ptr<WMBus> wmbus_rawtty = openRawTTY(de, manager, serial4);
|
||||
|
||||
Configuration nometers_config;
|
||||
// Check that if no meters are supplied then you must set a link mode.
|
||||
|
|
26
src/util.cc
26
src/util.cc
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
|
||||
#include"util.h"
|
||||
#include"meters.h"
|
||||
#include"shell.h"
|
||||
#include"version.h"
|
||||
|
||||
|
@ -782,31 +781,6 @@ string toIdsCommaSeparated(std::vector<std::string> &ids)
|
|||
return cs;
|
||||
}
|
||||
|
||||
bool isValidKey(string& key, MeterDriver mt)
|
||||
{
|
||||
if (key.length() == 0) return true;
|
||||
if (key == "NOKEY") {
|
||||
key = "";
|
||||
return true;
|
||||
}
|
||||
if (mt == MeterDriver::IZAR ||
|
||||
mt == MeterDriver::HYDRUS)
|
||||
{
|
||||
// These meters can either be OMS compatible 128 bit key (32 hex).
|
||||
// Or using an older proprietary encryption with 64 bit keys (16 hex)
|
||||
if (key.length() != 16 && key.length() != 32) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// OMS compliant meters have 128 bit AES keys (32 hex).
|
||||
// There is a deprecated DES mode, but I have not yet
|
||||
// seen any telegram using that mode.
|
||||
if (key.length() != 32) return false;
|
||||
}
|
||||
vector<uchar> tmp;
|
||||
return hex2bin(key, &tmp);
|
||||
}
|
||||
|
||||
bool isFrequency(std::string& fq)
|
||||
{
|
||||
int len = fq.length();
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include<map>
|
||||
#include<vector>
|
||||
|
||||
enum class MeterDriver;
|
||||
|
||||
void onExit(std::function<void()> cb);
|
||||
void restoreSignalHandlers();
|
||||
bool gotHupped();
|
||||
|
@ -122,7 +120,6 @@ std::string toIdsCommaSeparated(std::vector<std::string> &ids);
|
|||
|
||||
bool isValidId(std::string id, bool accept_non_compliant);
|
||||
|
||||
bool isValidKey(std::string& key, MeterDriver mt);
|
||||
bool isFrequency(std::string& fq);
|
||||
bool isNumber(std::string& fq);
|
||||
|
||||
|
|
12
src/wmbus.cc
12
src/wmbus.cc
|
@ -18,7 +18,6 @@
|
|||
#include"aescmac.h"
|
||||
#include"sha256.h"
|
||||
#include"timings.h"
|
||||
#include"meters.h"
|
||||
#include"wmbus.h"
|
||||
#include"wmbus_common_implementation.h"
|
||||
#include"wmbus_utils.h"
|
||||
|
@ -1819,6 +1818,8 @@ void Telegram::explainParse(string intro, int from)
|
|||
}
|
||||
}
|
||||
|
||||
void detectMeterDrivers(int manufacturer, int media, int version, std::vector<std::string> *drivers);
|
||||
|
||||
string Telegram::autoDetectPossibleDrivers()
|
||||
{
|
||||
vector<string> drivers;
|
||||
|
@ -3461,11 +3462,13 @@ WMBusCommonImplementation::~WMBusCommonImplementation()
|
|||
debug("(wmbus) deleted %s\n", toString(type()));
|
||||
}
|
||||
|
||||
WMBusCommonImplementation::WMBusCommonImplementation(WMBusDeviceType t,
|
||||
WMBusCommonImplementation::WMBusCommonImplementation(string alias,
|
||||
WMBusDeviceType t,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial,
|
||||
bool is_serial)
|
||||
: manager_(manager),
|
||||
alias_(alias),
|
||||
is_serial_(is_serial),
|
||||
is_working_(true),
|
||||
type_(t),
|
||||
|
@ -3509,6 +3512,11 @@ WMBusDeviceType WMBusCommonImplementation::type()
|
|||
return type_;
|
||||
}
|
||||
|
||||
string WMBusCommonImplementation::alias()
|
||||
{
|
||||
return alias_;
|
||||
}
|
||||
|
||||
void WMBusCommonImplementation::onTelegram(function<bool(AboutTelegram&,vector<uchar>)> cb)
|
||||
{
|
||||
telegram_listeners_.push_back(cb);
|
||||
|
|
31
src/wmbus.h
31
src/wmbus.h
|
@ -528,6 +528,10 @@ struct Meter;
|
|||
|
||||
struct WMBus
|
||||
{
|
||||
// Each bus can be given an alias name to be
|
||||
// referred to from meters.
|
||||
virtual std::string alias() = 0;
|
||||
|
||||
// I wmbus device identifier consists of:
|
||||
// device:type[id] for example:
|
||||
// /dev/ttyUSB1:im871a[12345678]
|
||||
|
@ -588,15 +592,20 @@ Detected detectWMBusDeviceWithCommand(SpecifiedDevice &specified_device,
|
|||
shared_ptr<SerialCommunicationManager> handler);
|
||||
|
||||
|
||||
shared_ptr<WMBus> openIM871A(Detected detected, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<WMBus> openIM871A(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openAMB8465(Detected detected, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<WMBus> openAMB8465(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openRawTTY(string device, int baudrate, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<WMBus> openRawTTY(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openMBUS(Detected detected, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<WMBus> openMBUS(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openRC1180(string device, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<WMBus> openRC1180(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openRTLWMBUS(Detected detected,
|
||||
string bin_dir,
|
||||
|
@ -608,13 +617,11 @@ shared_ptr<WMBus> openRTL433(Detected detected,
|
|||
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);
|
||||
shared_ptr<WMBus> openD1TC(string device, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openWMB13U(string device, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openSimulator(string file, shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<WMBus> openCUL(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
shared_ptr<WMBus> openSimulator(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override);
|
||||
|
||||
string manufacturer(int m_field);
|
||||
|
|
|
@ -114,7 +114,7 @@ struct WMBusAmber : public virtual WMBusCommonImplementation
|
|||
bool getConfiguration();
|
||||
void simulate() { }
|
||||
|
||||
WMBusAmber(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusAmber(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~WMBusAmber() {
|
||||
manager_->onDisappear(this->serial(), NULL);
|
||||
}
|
||||
|
@ -141,23 +141,24 @@ private:
|
|||
|
||||
shared_ptr<WMBus> openAMB8465(Detected detected, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string device = detected.found_file;
|
||||
assert(device != "");
|
||||
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusAmber *imp = new WMBusAmber(serial_override, manager);
|
||||
WMBusAmber *imp = new WMBusAmber(alias, serial_override, manager);
|
||||
imp->markAsNoLongerSerial();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
auto serial = manager->createSerialDeviceTTY(device.c_str(), 9600, PARITY::NONE, "amb8465");
|
||||
WMBusAmber *imp = new WMBusAmber(serial, manager);
|
||||
WMBusAmber *imp = new WMBusAmber(alias, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusAmber::WMBusAmber(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_AMB8465, manager, serial, true)
|
||||
WMBusAmber::WMBusAmber(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_AMB8465, manager, serial, true)
|
||||
{
|
||||
rssi_expected_ = true;
|
||||
reset();
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
|
||||
struct WMBusCommonImplementation : public virtual WMBus
|
||||
{
|
||||
WMBusCommonImplementation(WMBusDeviceType t,
|
||||
WMBusCommonImplementation(string alias,
|
||||
WMBusDeviceType t,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override,
|
||||
bool is_serial);
|
||||
~WMBusCommonImplementation();
|
||||
|
||||
string alias();
|
||||
string hr();
|
||||
bool isSerial();
|
||||
WMBusDeviceType type();
|
||||
|
@ -74,6 +76,8 @@ struct WMBusCommonImplementation : public virtual WMBus
|
|||
|
||||
private:
|
||||
|
||||
// Bus alias.
|
||||
string alias_;
|
||||
// Uses a serial tty?
|
||||
bool is_serial_ {};
|
||||
bool is_working_ {};
|
||||
|
|
|
@ -63,7 +63,7 @@ struct WMBusCUL : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate();
|
||||
|
||||
WMBusCUL(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusCUL(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~WMBusCUL() { }
|
||||
|
||||
private:
|
||||
|
@ -82,22 +82,24 @@ private:
|
|||
string setup_;
|
||||
};
|
||||
|
||||
shared_ptr<WMBus> openCUL(string device, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
shared_ptr<WMBus> openCUL(Detected detected, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string device = detected.found_file;
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusCUL *imp = new WMBusCUL(serial_override, manager);
|
||||
WMBusCUL *imp = new WMBusCUL(alias, serial_override, manager);
|
||||
imp->markAsNoLongerSerial();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
auto serial = manager->createSerialDeviceTTY(device.c_str(), 38400, PARITY::NONE, "cul");
|
||||
WMBusCUL *imp = new WMBusCUL(serial, manager);
|
||||
WMBusCUL *imp = new WMBusCUL(alias, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusCUL::WMBusCUL(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_CUL, manager, serial, true)
|
||||
WMBusCUL::WMBusCUL(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_CUL, manager, serial, true)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ struct WMBusIM871A : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate() { }
|
||||
|
||||
WMBusIM871A(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusIM871A(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~WMBusIM871A() {
|
||||
}
|
||||
|
||||
|
@ -230,22 +230,23 @@ int toDBM(int rssi)
|
|||
|
||||
shared_ptr<WMBus> openIM871A(Detected detected, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string device_file = detected.found_file;
|
||||
assert(device_file != "");
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusIM871A *imp = new WMBusIM871A(serial_override, manager);
|
||||
WMBusIM871A *imp = new WMBusIM871A(alias, serial_override, manager);
|
||||
imp->markAsNoLongerSerial();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
auto serial = manager->createSerialDeviceTTY(device_file.c_str(), 57600, PARITY::NONE, "im871a");
|
||||
WMBusIM871A *imp = new WMBusIM871A(serial, manager);
|
||||
WMBusIM871A *imp = new WMBusIM871A(alias, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusIM871A::WMBusIM871A(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_IM871A, manager, serial, true)
|
||||
WMBusIM871A::WMBusIM871A(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_IM871A, manager, serial, true)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ struct WMBusRawTTY : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate() { }
|
||||
|
||||
WMBusRawTTY(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusRawTTY(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~WMBusRawTTY() { }
|
||||
|
||||
private:
|
||||
|
@ -53,23 +53,29 @@ private:
|
|||
vector<uchar> received_payload_;
|
||||
};
|
||||
|
||||
shared_ptr<WMBus> openRawTTY(string device, int baudrate, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
shared_ptr<WMBus> openRawTTY(Detected detected,
|
||||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string device = detected.found_file;
|
||||
int bps = detected.found_bps;
|
||||
|
||||
assert(device != "");
|
||||
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusRawTTY *imp = new WMBusRawTTY(serial_override, manager);
|
||||
WMBusRawTTY *imp = new WMBusRawTTY(alias, serial_override, manager);
|
||||
imp->markAsNoLongerSerial();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
auto serial = manager->createSerialDeviceTTY(device.c_str(), baudrate, PARITY::NONE, "rawtty");
|
||||
WMBusRawTTY *imp = new WMBusRawTTY(serial, manager);
|
||||
auto serial = manager->createSerialDeviceTTY(device.c_str(), bps, PARITY::NONE, "rawtty");
|
||||
WMBusRawTTY *imp = new WMBusRawTTY(alias, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusRawTTY::WMBusRawTTY(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_RAWTTY, manager, serial, true)
|
||||
WMBusRawTTY::WMBusRawTTY(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_RAWTTY, manager, serial, true)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ struct WMBusRC1180 : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate();
|
||||
|
||||
WMBusRC1180(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusRC1180(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~WMBusRC1180() { }
|
||||
|
||||
private:
|
||||
|
@ -161,24 +161,26 @@ private:
|
|||
string setup_;
|
||||
};
|
||||
|
||||
shared_ptr<WMBus> openRC1180(string device, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
shared_ptr<WMBus> openRC1180(Detected detected, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string device = detected.found_file;
|
||||
assert(device != "");
|
||||
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusRC1180 *imp = new WMBusRC1180(serial_override, manager);
|
||||
WMBusRC1180 *imp = new WMBusRC1180(alias, serial_override, manager);
|
||||
imp->markAsNoLongerSerial();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
auto serial = manager->createSerialDeviceTTY(device.c_str(), 19200, PARITY::NONE, "rc1180");
|
||||
WMBusRC1180 *imp = new WMBusRC1180(serial, manager);
|
||||
WMBusRC1180 *imp = new WMBusRC1180(alias, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusRC1180::WMBusRC1180(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_RC1180, manager, serial, true)
|
||||
WMBusRC1180::WMBusRC1180(string alias, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_RC1180, manager, serial, true)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ struct WMBusRTL433 : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate();
|
||||
|
||||
WMBusRTL433(string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusRTL433(string alias, string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -81,6 +81,7 @@ shared_ptr<WMBus> openRTL433(Detected detected, string bin_dir, bool daemon,
|
|||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string identifier = detected.found_device_id;
|
||||
SpecifiedDevice &device = detected.specified_device;
|
||||
string command;
|
||||
|
@ -143,16 +144,16 @@ shared_ptr<WMBus> openRTL433(Detected detected, string bin_dir, bool daemon,
|
|||
args.push_back(command);
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusRTL433 *imp = new WMBusRTL433(identifier, serial_override, manager);
|
||||
WMBusRTL433 *imp = new WMBusRTL433(alias, identifier, serial_override, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
auto serial = manager->createSerialDeviceCommand(identifier, "/bin/sh", args, envs, "rtl433");
|
||||
WMBusRTL433 *imp = new WMBusRTL433(identifier, serial, manager);
|
||||
WMBusRTL433 *imp = new WMBusRTL433(alias, identifier, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusRTL433::WMBusRTL433(string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_RTL433, manager, serial, false), serialnr_(serialnr)
|
||||
WMBusRTL433::WMBusRTL433(string alias, string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_RTL433, manager, serial, false), serialnr_(serialnr)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ struct WMBusRTLWMBUS : public virtual WMBusCommonImplementation
|
|||
void processSerialData();
|
||||
void simulate();
|
||||
|
||||
WMBusRTLWMBUS(string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusRTLWMBUS(string alias, string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager);
|
||||
~WMBusRTLWMBUS() { }
|
||||
|
||||
private:
|
||||
|
@ -87,6 +87,7 @@ shared_ptr<WMBus> openRTLWMBUS(Detected detected,
|
|||
shared_ptr<SerialCommunicationManager> manager,
|
||||
shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
string alias = detected.specified_device.alias;
|
||||
string identifier = detected.found_device_id;
|
||||
SpecifiedDevice &device = detected.specified_device;
|
||||
string command;
|
||||
|
@ -176,17 +177,17 @@ shared_ptr<WMBus> openRTLWMBUS(Detected detected,
|
|||
args.push_back(command);
|
||||
if (serial_override)
|
||||
{
|
||||
WMBusRTLWMBUS *imp = new WMBusRTLWMBUS(identifier, serial_override, manager);
|
||||
WMBusRTLWMBUS *imp = new WMBusRTLWMBUS(alias, identifier, serial_override, manager);
|
||||
imp->markSerialAsOverriden();
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
auto serial = manager->createSerialDeviceCommand(identifier, "/bin/sh", args, envs, "rtlwmbus");
|
||||
WMBusRTLWMBUS *imp = new WMBusRTLWMBUS(identifier, serial, manager);
|
||||
WMBusRTLWMBUS *imp = new WMBusRTLWMBUS(alias, identifier, serial, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusRTLWMBUS::WMBusRTLWMBUS(string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(DEVICE_RTLWMBUS, manager, serial, false), serialnr_(serialnr)
|
||||
WMBusRTLWMBUS::WMBusRTLWMBUS(string alias, string serialnr, shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
|
||||
WMBusCommonImplementation(alias, DEVICE_RTLWMBUS, manager, serial, false), serialnr_(serialnr)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ struct WMBusSimulator : public WMBusCommonImplementation
|
|||
void simulate();
|
||||
string device() { return file_; }
|
||||
|
||||
WMBusSimulator(string file, shared_ptr<SerialCommunicationManager> manager);
|
||||
WMBusSimulator(string alias, string file, shared_ptr<SerialCommunicationManager> manager);
|
||||
|
||||
private:
|
||||
vector<uchar> received_payload_;
|
||||
|
@ -58,14 +58,16 @@ private:
|
|||
vector<string> lines_;
|
||||
};
|
||||
|
||||
shared_ptr<WMBus> openSimulator(string device, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
shared_ptr<WMBus> openSimulator(Detected detected, shared_ptr<SerialCommunicationManager> manager, shared_ptr<SerialDevice> serial_override)
|
||||
{
|
||||
WMBusSimulator *imp = new WMBusSimulator(device, manager);
|
||||
string alias = detected.specified_device.alias;
|
||||
string device = detected.found_file;
|
||||
WMBusSimulator *imp = new WMBusSimulator(alias, device, manager);
|
||||
return shared_ptr<WMBus>(imp);
|
||||
}
|
||||
|
||||
WMBusSimulator::WMBusSimulator(string file, shared_ptr<SerialCommunicationManager> manager)
|
||||
: WMBusCommonImplementation(DEVICE_SIMULATION, manager, NULL, false), file_(file)
|
||||
WMBusSimulator::WMBusSimulator(string alias, string file, shared_ptr<SerialCommunicationManager> manager)
|
||||
: WMBusCommonImplementation(alias, DEVICE_SIMULATION, manager, NULL, false), file_(file)
|
||||
{
|
||||
assert(file != "");
|
||||
loadFile(file, &lines_);
|
||||
|
|
Ładowanie…
Reference in New Issue