More work on the Thermostat cluster

This commit is contained in:
Michael Zanetti 2022-02-14 01:02:52 +01:00
parent a38e8be190
commit 88920274da
2 changed files with 83 additions and 59 deletions

View File

@ -34,62 +34,62 @@
ZigbeeClusterThermostat::ZigbeeClusterThermostat(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, ZigbeeCluster::Direction direction, QObject *parent): ZigbeeClusterThermostat::ZigbeeClusterThermostat(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, ZigbeeCluster::Direction direction, QObject *parent):
ZigbeeCluster(network, node, endpoint, ZigbeeClusterLibrary::ClusterIdThermostat, direction, parent) ZigbeeCluster(network, node, endpoint, ZigbeeClusterLibrary::ClusterIdThermostat, direction, parent)
{ {
} }
void ZigbeeClusterThermostat::processDataIndication(ZigbeeClusterLibrary::Frame frame) qint16 ZigbeeClusterThermostat::localTemperature() const
{ {
qCDebug(dcZigbeeCluster()) << "Processing cluster frame" << m_node << m_endpoint << this << frame; return m_attributes.value(AttributeLocalTemperature).dataType().toInt16();
}
// switch (m_direction) {
// case Client: qint16 ZigbeeClusterThermostat::occupiedCoolingSetpoint() const
// if (frame.header.frameControl.direction == ZigbeeClusterLibrary::DirectionClientToServer) { {
// Command command = static_cast<Command>(frame.header.command); return m_attributes.value(AttributeOccupiedCoolingSetpoint).dataType().toInt16();
// qCDebug(dcZigbeeCluster()) << "Received" << command << "from" << m_node << m_endpoint << this; }
// switch (command) {
// case CommandQueryNextImageRequest: { qint16 ZigbeeClusterThermostat::occupiedHeatingSetpoint() const
// // Print the image information {
// quint8 fieldControl; return m_attributes.value(AttributeOccupiedHeatingSetpoint).dataType().toInt16();
// quint16 manufacturerCode; }
// quint16 imageType;
// quint32 currentVersion; ZigbeeClusterReply *ZigbeeClusterThermostat::setOccupiedHeatingSetpoint(qint16 occupiedHeatingSetpoint)
// quint16 hardwareVersion; {
ZigbeeDataType dataType(occupiedHeatingSetpoint);
// QDataStream requestStream(&frame.payload, QIODevice::ReadOnly); QList<ZigbeeClusterLibrary::WriteAttributeRecord> attributes;
// requestStream.setByteOrder(QDataStream::LittleEndian); ZigbeeClusterLibrary::WriteAttributeRecord attribute;
// requestStream >> fieldControl >> manufacturerCode >> imageType >> currentVersion >> hardwareVersion; attribute.attributeId = ZigbeeClusterThermostat::AttributeOccupiedHeatingSetpoint;
// qCDebug(dcZigbeeCluster()) << "OTA image request:" << (fieldControl == 0x0000 ? "Hardware version not present" : "Hardware version present"); attribute.dataType = dataType.dataType();
// qCDebug(dcZigbeeCluster()) << "OTA image request: Manufacturer code" << ZigbeeUtils::convertUint16ToHexString(manufacturerCode); attribute.data = dataType.data();
// qCDebug(dcZigbeeCluster()) << "OTA image request: Image type" << ZigbeeUtils::convertUint16ToHexString(imageType); attributes.append(attribute);
// qCDebug(dcZigbeeCluster()) << "OTA image request: Current file version" << ZigbeeUtils::convertUint32ToHexString(currentVersion) << parseFileVersion(currentVersion);
// qCDebug(dcZigbeeCluster()) << "OTA image request: Hardware version" << hardwareVersion; return this->writeAttributes(attributes);
}
// // Respond with no image available until we implement the entire cluster for OTA updates
// qCDebug(dcZigbeeCluster()) << "OTA mechanism not implemented yet. Tell the node there is no image available."; ZigbeeClusterReply *ZigbeeClusterThermostat::setOccupiedCoolingSetpoint(qint16 occupiedCoolingSetpoint)
{
// QByteArray payload; ZigbeeDataType dataType(occupiedCoolingSetpoint);
// QDataStream stream(&payload, QIODevice::WriteOnly); QList<ZigbeeClusterLibrary::WriteAttributeRecord> attributes;
// stream.setByteOrder(QDataStream::LittleEndian); ZigbeeClusterLibrary::WriteAttributeRecord attribute;
// stream << static_cast<quint8>(StatuCodeNoImageAvailable); attribute.attributeId = ZigbeeClusterThermostat::AttributeOccupiedCoolingSetpoint;
attribute.dataType = dataType.dataType();
// // Note: if there would be an image available, the response would be success, followed by manufacturer code, image type, file version of image and file size attribute.data = dataType.data();
attributes.append(attribute);
// ZigbeeClusterReply *reply = sendClusterServerResponse(CommandQueryNextImageResponse, frame.header.transactionSequenceNumber, payload);
// connect(reply, &ZigbeeClusterReply::finished, this, [](){ return this->writeAttributes(attributes);
// qCDebug(dcZigbeeCluster()) << "OTA image request response for image query sent successfully to requested node."; }
// });
void ZigbeeClusterThermostat::setAttribute(const ZigbeeClusterAttribute &attribute)
// break; {
// } ZigbeeCluster::setAttribute(attribute);
// default:
// qCWarning(dcZigbeeCluster()) << "Received command" << command << "which is not implemented yet from" << m_node << m_endpoint << this; switch (attribute.id()) {
// break; case AttributeLocalTemperature:
// } emit localTemperatureChanged(localTemperature());
// } break;
// break; case AttributeOccupiedCoolingSetpoint:
// case Server: emit occupiedCoolingSetpointChanged(occupiedCoolingSetpoint());
// qCWarning(dcZigbeeCluster()) << "Unhandled ZCL indication in" << m_node << m_endpoint << this << frame; break;
// break; case AttributeOccupiedHeatingSetpoint:
// } emit occupiedHeatingSetpointChanged(occupiedHeatingSetpoint());
break;
}
} }

View File

@ -51,7 +51,7 @@ public:
AttributePIHeatingDemand = 0x0008, AttributePIHeatingDemand = 0x0008,
AttributeHVACSystemTypeConfiguration = 0x0009, AttributeHVACSystemTypeConfiguration = 0x0009,
AttributeLocalTemperatureCalibratioon = 0x0010, AttributeLocalTemperatureCalibration = 0x0010,
AttributeOccupiedCoolingSetpoint = 0x0011, AttributeOccupiedCoolingSetpoint = 0x0011,
AttributeOccupiedHeatingSetpoint = 0x0012, AttributeOccupiedHeatingSetpoint = 0x0012,
AttributeUnoccupiedCoolingSetpoint = 0x0013, AttributeUnoccupiedCoolingSetpoint = 0x0013,
@ -66,15 +66,39 @@ public:
AttributeSystemMode = 0x001c, AttributeSystemMode = 0x001c,
AttributeAlarmMask = 0x001d, AttributeAlarmMask = 0x001d,
AttributeThermostatRunningMode = 0x001e AttributeThermostatRunningMode = 0x001e
}; };
Q_ENUM(Attribute) Q_ENUM(Attribute)
enum SystemMode {
SystemModeOff = 0x00,
SystemModeAuto = 0x01,
SystemModeCool = 0x03,
SystemModeHeat = 0x04,
SystemModeEmergencyHeating = 0x05,
SystemModePrecooling = 0x06,
SystemModeFanOnly = 0x07,
SystemModeDry = 0x08,
SystemModeSleep = 0x09
};
Q_ENUM(SystemMode)
explicit ZigbeeClusterThermostat(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr); explicit ZigbeeClusterThermostat(ZigbeeNetwork *network, ZigbeeNode *node, ZigbeeNodeEndpoint *endpoint, Direction direction, QObject *parent = nullptr);
protected: qint16 localTemperature() const;
void processDataIndication(ZigbeeClusterLibrary::Frame frame) override; qint16 occupiedCoolingSetpoint() const;
qint16 occupiedHeatingSetpoint() const;
// targetTemp is °C*100. e.g. 20.5°C -> 2050
ZigbeeClusterReply *setOccupiedHeatingSetpoint(qint16 occupiedHeatingSetpoint);
ZigbeeClusterReply *setOccupiedCoolingSetpoint(qint16 occupiedCoolingSetpoint);
signals:
void localTemperatureChanged(qint16 localTemp);
void occupiedCoolingSetpointChanged(qint16 occupiedCoolingSetpoint);
void occupiedHeatingSetpointChanged(qint16 occupiedHeatingSetpoint);
private:
void setAttribute(const ZigbeeClusterAttribute &attribute) override;
}; };
#endif // ZIGBEECLUSTERTHERMOSTAT_H #endif // ZIGBEECLUSTERTHERMOSTAT_H