-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
181 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "ModbusThing.h" | ||
|
||
#include <QModbusTcpClient> | ||
|
||
#include <common/Logger.h> | ||
|
||
using namespace std::placeholders; | ||
|
||
ModbusThing::ModbusThing(const ThingInfo& info) : | ||
Thing{info}, | ||
_modbusClient(new QModbusTcpClient) { | ||
|
||
_modbusClient->connect(_modbusClient, &QModbusTcpClient::stateChanged, std::bind(&ModbusThing::onStateChanged, this, _1)); | ||
_modbusClient->connect(_modbusClient, &QModbusTcpClient::errorOccurred, std::bind(&ModbusThing::onErrorOccurred, this, _1)); | ||
|
||
_modbusClient->setConnectionParameter(QModbusDevice::NetworkPortParameter, 502); | ||
_modbusClient->setConnectionParameter(QModbusDevice::NetworkAddressParameter, QString::fromStdString(info.host())); | ||
|
||
_modbusClient->setTimeout(5000); | ||
_modbusClient->setNumberOfRetries(2); | ||
} | ||
|
||
ModbusThing::~ModbusThing() { | ||
_modbusClient->disconnect(); | ||
_modbusClient->deleteLater(); | ||
} | ||
|
||
bool ModbusThing::connect() { | ||
return _modbusClient->connectDevice(); | ||
} | ||
|
||
void ModbusThing::disconnect() { | ||
return _modbusClient->disconnectDevice(); | ||
} | ||
|
||
void ModbusThing::doRead() { | ||
}; | ||
|
||
void ModbusThing::onStateChanged(QModbusDevice::State state_) { | ||
if (state_ == QModbusDevice::State::ConnectedState && state() == Thing::State::Uninitialized) { | ||
LOG_S(INFO) << "host found: " << _modbusClient->connectionParameter(QModbusDevice::NetworkAddressParameter).toString(); | ||
stateSubscriber().on_next(State::Ready); | ||
//pollNextUnitId(); | ||
} else if (state_ == QModbusDevice::State::UnconnectedState && state() != Thing::State::Uninitialized) { | ||
// Elgris smart meters disconnects after 10s. So, we automatically reconnect. | ||
LOG_S(WARNING) << id() << "> disconnected. Reconnecting..."; | ||
connect(); | ||
} | ||
} | ||
|
||
void ModbusThing::onErrorOccurred(QModbusDevice::Error error) { | ||
if (error == QModbusDevice::Error::NoError) { | ||
return; | ||
} | ||
|
||
if (state() == Thing::State::Uninitialized) { | ||
stateSubscriber().on_next(State::Failed); | ||
return; | ||
} | ||
|
||
// We filter for connection error, because remotes might hang up. | ||
LOG_IF_S(WARNING, error != QModbusDevice::Error::ConnectionError) << host() << "> error occured: " << _modbusClient->errorString().toStdString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <QModbusDevice> | ||
|
||
#include <things/Thing.h> | ||
|
||
class QModbusTcpClient; | ||
|
||
class ModbusThing : public Thing { | ||
public: | ||
ModbusThing(const ThingInfo& info); | ||
virtual ~ModbusThing(); | ||
|
||
bool connect(); | ||
void disconnect(); | ||
|
||
private: | ||
virtual void doRead() override; | ||
|
||
void onStateChanged(QModbusDevice::State state); | ||
void onErrorOccurred(QModbusDevice::Error error); | ||
|
||
QModbusTcpClient* _modbusClient; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,5 +46,7 @@ PRIVATE | |
target_link_libraries(httpthing | ||
PUBLIC | ||
common | ||
goe | ||
qmdnsengine | ||
shelly | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "SunSpecDiscovery.h" | ||
|
||
SunSpecDiscovery::SunSpecDiscovery() { | ||
} | ||
|
||
void SunSpecDiscovery::start(int msec) { | ||
} | ||
|
||
void SunSpecDiscovery::stop() { | ||
} |
Oops, something went wrong.