Added functionality to set target room temp
parent
ef18328529
commit
2c342bc658
22
idm/idm.cpp
22
idm/idm.cpp
|
|
@ -55,10 +55,32 @@ Idm::~Idm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Idm::setTargetRoomTemperature (double temperature) {
|
||||||
|
QVector<quint16> registers{};
|
||||||
|
|
||||||
|
printf("Setting target room temperature to %g\n", temperature);
|
||||||
|
|
||||||
|
ModbusHelpers::convertFloatToRegister(registers, temperature);
|
||||||
|
|
||||||
|
printf("registers to be sent: %x %x\n", registers[0], registers[1]);
|
||||||
|
|
||||||
|
m_modbusMaster->writeHoldingRegisters(Idm::ModbusUnitID, Idm::RoomTemperatureHKA, registers);
|
||||||
|
|
||||||
|
emit targetRoomTemperatureChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Idm::onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
void Idm::onReceivedHoldingRegister(int slaveAddress, int modbusRegister, const QVector<quint16> &value)
|
||||||
{
|
{
|
||||||
Q_UNUSED(slaveAddress);
|
Q_UNUSED(slaveAddress);
|
||||||
|
|
||||||
|
/* Introducing a delay here for testing.
|
||||||
|
* Purposely set here, so one delay works for all branches
|
||||||
|
* of the following switch statement. In fact, the delay
|
||||||
|
* is used before evaluating what was just read, which
|
||||||
|
* does not seem to make sense, but it also acts before
|
||||||
|
* the next read command is sent. */
|
||||||
|
QThread::msleep(200);
|
||||||
|
|
||||||
switch (modbusRegister) {
|
switch (modbusRegister) {
|
||||||
case Idm::OutsideTemperature:
|
case Idm::OutsideTemperature:
|
||||||
if (value.length() == 2) {
|
if (value.length() == 2) {
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ public:
|
||||||
/** Destructor */
|
/** Destructor */
|
||||||
~Idm();
|
~Idm();
|
||||||
|
|
||||||
|
void setTargetRoomTemperature (double temperature);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Note: It would be desirable to read the modbus registers
|
/* Note: It would be desirable to read the modbus registers
|
||||||
* of the Idm heat pump in groups to minimize the number
|
* of the Idm heat pump in groups to minimize the number
|
||||||
|
|
@ -153,6 +155,7 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void statusUpdated(IdmInfo *info);
|
void statusUpdated(IdmInfo *info);
|
||||||
|
void targetRoomTemperatureChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onModbusError();
|
void onModbusError();
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ void IntegrationPluginIdm::postSetupThing(Thing *thing)
|
||||||
Idm *idm = m_idmConnections.value(thing);
|
Idm *idm = m_idmConnections.value(thing);
|
||||||
|
|
||||||
connect(idm, &Idm::statusUpdated, this, &IntegrationPluginIdm::onStatusUpdated);
|
connect(idm, &Idm::statusUpdated, this, &IntegrationPluginIdm::onStatusUpdated);
|
||||||
|
connect(idm, &Idm::targetRoomTemperatureChanged, this, &IntegrationPluginIdm::onTargetRoomTemperatureChanged);
|
||||||
|
|
||||||
qCDebug(dcIdm()) << "Thing set up, calling update";
|
qCDebug(dcIdm()) << "Thing set up, calling update";
|
||||||
update(thing);
|
update(thing);
|
||||||
|
|
@ -105,7 +106,13 @@ void IntegrationPluginIdm::executeAction(ThingActionInfo *info)
|
||||||
|
|
||||||
if (thing->thingClassId() == navigator2ThingClassId) {
|
if (thing->thingClassId() == navigator2ThingClassId) {
|
||||||
if (action.actionTypeId() == navigator2PowerActionTypeId) {
|
if (action.actionTypeId() == navigator2PowerActionTypeId) {
|
||||||
} else {
|
|
||||||
|
} else if (action.actionTypeId() == navigator2TargetTemperatureStateTypeId) {
|
||||||
|
Idm *idm = m_idmConnections.value(thing);
|
||||||
|
|
||||||
|
idm->setTargetRoomTemperature(action.param(navigator2TargetTemperatureEventTargetTemperatureParamTypeId).value().value<double>());
|
||||||
|
|
||||||
|
} else {
|
||||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled action: %1").arg(action.actionTypeId().toString()).toUtf8());
|
Q_ASSERT_X(false, "executeAction", QString("Unhandled action: %1").arg(action.actionTypeId().toString()).toUtf8());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -160,6 +167,11 @@ void IntegrationPluginIdm::onStatusUpdated(IdmInfo *info)
|
||||||
thing->setStateValue(navigator2ErrorStateTypeId, info->m_error);
|
thing->setStateValue(navigator2ErrorStateTypeId, info->m_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginIdm::onTargetRoomTemperatureChanged()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void IntegrationPluginIdm::onRefreshTimer()
|
void IntegrationPluginIdm::onRefreshTimer()
|
||||||
{
|
{
|
||||||
foreach (Thing *thing, myThings().filterByThingClassId(navigator2ThingClassId)) {
|
foreach (Thing *thing, myThings().filterByThingClassId(navigator2ThingClassId)) {
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ private:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onStatusUpdated(IdmInfo *info);
|
void onStatusUpdated(IdmInfo *info);
|
||||||
|
void onTargetRoomTemperatureChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INTEGRATIONPLUGINIDM_H
|
#endif // INTEGRATIONPLUGINIDM_H
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
|
|
||||||
"id": "b98fb325-100d-4eae-bf8d-97e8f7e1eb00",
|
"id": "b98fb325-100d-4eae-bf8d-97e8f7e1eb00",
|
||||||
"name": "currentPowerConsumptionHeatPump",
|
"name": "currentPowerConsumptionHeatPump",
|
||||||
"displayName": "Current power consumption heat pump",
|
"displayName": "Curr. power consumption",
|
||||||
"displayNameEvent": "Current power consumption heat pump changed",
|
"displayNameEvent": "Current power consumption heat pump changed",
|
||||||
"displayNameAction": "Change current power consumption het pump",
|
"displayNameAction": "Change current power consumption het pump",
|
||||||
"type": "double",
|
"type": "double",
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ float ModbusHelpers::convertRegisterToFloat(const quint16 *reg) {
|
||||||
|
|
||||||
if (reg != nullptr) {
|
if (reg != nullptr) {
|
||||||
/* low-order byte is sent first, so swap order */
|
/* low-order byte is sent first, so swap order */
|
||||||
quint32 tmp = 0.0;
|
quint32 tmp = 0;
|
||||||
|
|
||||||
tmp |= ((quint32)(reg[1]) << 16) & 0xFFFF0000;
|
tmp |= ((quint32)(reg[1]) << 16) & 0xFFFF0000;
|
||||||
tmp |= reg[0];
|
tmp |= reg[0];
|
||||||
|
|
@ -50,3 +50,12 @@ float ModbusHelpers::convertRegisterToFloat(const quint16 *reg) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModbusHelpers::convertFloatToRegister(QVector<quint16> ®, float value) {
|
||||||
|
quint32 tmp = 0;
|
||||||
|
|
||||||
|
memcpy((char *)&tmp, (char *)&value, sizeof(value));
|
||||||
|
|
||||||
|
reg.append((quint16)(tmp));
|
||||||
|
reg.append((quint16)((tmp & 0xFFFF0000) >> 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,12 @@
|
||||||
#define MODBUSHELPERS_H
|
#define MODBUSHELPERS_H
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
class ModbusHelpers {
|
class ModbusHelpers {
|
||||||
public:
|
public:
|
||||||
static float convertRegisterToFloat(const quint16 *reg);
|
static float convertRegisterToFloat(const quint16 *reg);
|
||||||
|
static void convertFloatToRegister(QVector<quint16> ®, float value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue