kopia lustrzana https://github.com/weetmuts/wmbusmeters
Pass the meter as an argument to the update callback.
rodzic
666ef51819
commit
d075beac50
4
main.cc
4
main.cc
|
@ -48,9 +48,9 @@ int main(int argc, char **argv)
|
|||
wmbus->setLinkMode(C1a);
|
||||
if (wmbus->getLinkMode()!=C1a) error("Could not set link mode to C1a\n");
|
||||
|
||||
auto meter = createMultical21(wmbus, "MyHouseWater", "12345678", "00112233445566778899AABBCCDDEEFF");
|
||||
auto house = createMultical21(wmbus, "MyHouseWater", "12345678", "00112233445566778899AABBCCDDEEFF");
|
||||
|
||||
meter->onUpdate([meter](){
|
||||
house->onUpdate([](Meter*meter){
|
||||
printf("%s\t%s\t% 3.3f m3\t%s\n",
|
||||
meter->name().c_str(),
|
||||
meter->id().c_str(),
|
||||
|
|
|
@ -38,7 +38,7 @@ struct MeterMultical21 : public Meter {
|
|||
string name();
|
||||
float totalWaterConsumption();
|
||||
string datetimeOfUpdate();
|
||||
void onUpdate(function<void()> cb);
|
||||
void onUpdate(function<void(Meter*)> cb);
|
||||
|
||||
private:
|
||||
void handleTelegram(Telegram*t);
|
||||
|
@ -51,7 +51,7 @@ private:
|
|||
vector<uchar> id_;
|
||||
vector<uchar> key_;
|
||||
WMBus *bus_;
|
||||
function<void()> on_update_;
|
||||
function<void(Meter*)> on_update_;
|
||||
};
|
||||
|
||||
MeterMultical21::MeterMultical21(WMBus *bus, const char *name, const char *id, const char *key) :
|
||||
|
@ -72,7 +72,7 @@ string MeterMultical21::name()
|
|||
return name_;
|
||||
}
|
||||
|
||||
void MeterMultical21::onUpdate(function<void()> cb)
|
||||
void MeterMultical21::onUpdate(function<void(Meter*)> cb)
|
||||
{
|
||||
on_update_ = cb;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void MeterMultical21::handleTelegram(Telegram *t) {
|
|||
total_water_consumption_ = processContent(dec);
|
||||
datetime_of_update_ = time(NULL);
|
||||
|
||||
if (on_update_) on_update_();
|
||||
if (on_update_) on_update_(this);
|
||||
}
|
||||
|
||||
float MeterMultical21::processContent(vector<uchar> &c) {
|
||||
|
|
2
meters.h
2
meters.h
|
@ -37,7 +37,7 @@ struct Meter {
|
|||
virtual float totalWaterConsumption() = 0;
|
||||
virtual string datetimeOfUpdate() = 0;
|
||||
|
||||
virtual void onUpdate(function<void()> cb) = 0;
|
||||
virtual void onUpdate(function<void(Meter*)> cb) = 0;
|
||||
};
|
||||
|
||||
Meter *createMultical21(WMBus *bus, const char *name, const char *id, const char *key);
|
||||
|
|
Ładowanie…
Reference in New Issue