Skip to content

Commit

Permalink
Added convienience functions for sending events
Browse files Browse the repository at this point in the history
  • Loading branch information
drempelg committed Nov 9, 2023
1 parent f7b5327 commit 6d8daca
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "electrical-energy-measurement-server.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Events.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app-common/zap-generated/ids/Commands.h>
#include <app/EventLogging.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>

Expand All @@ -21,4 +24,130 @@ using chip::Protocols::InteractionModel::Status;
void MatterElectricalEnergyMeasurementPluginServerInitCallback()
{

}
}

namespace chip {
namespace app {
namespace Clusters {
namespace ElectricalEnergyMeasurement {
namespace Server {

bool NotifyCumulativeEnergyImported(chip::EndpointId endpointId, uint32_t aImportedTimeStampS, uint64_t aEnergyImported)
{
Events::CumulativeEnergyImported::Type event;
event.importedTimestamp = aImportedTimeStampS;
event.energyImported = aEnergyImported;

EventNumber eventNumber;
CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber);

if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[NotifyCumulativeEnergyImported] Unable to send event: %s [endpointId=%d]", error.AsString(), endpointId);
return false;
}
ChipLogProgress(Zcl, "[NotifyCumulativeEnergyImported] Sent event [endpointId=%d,eventNumber=%" PRIu64 ",importedTimestamp=%u,energyImported=%" PRIu64 "]",
endpointId, eventNumber, aImportedTimeStampS, aEnergyImported);
return true;
}

bool NotifyCumulativeEnergyExported(chip::EndpointId endpointId, uint32_t aImportedTimeStampS, uint64_t aEnergyExported)
{
Events::CumulativeEnergyExported::Type event;
event.importedTimestamp = aImportedTimeStampS;
event.energyExported = aEnergyExported;

EventNumber eventNumber;
CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber);

if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[NotifyCumulativeEnergyExported] Unable to send event: %s [endpointId=%d]", error.AsString(), endpointId);
return false;
}
ChipLogProgress(Zcl, "[NotifyCumulativeEnergyExported] Sent event [endpointId=%d,eventNumber=%" PRIu64 ",importedTimestamp=%u,energyExported=%" PRIu64 "]",
endpointId, eventNumber, aImportedTimeStampS, aEnergyExported);
return true;
}

bool NotifyPeriodicEnergyImported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyImported)
{
Events::PeriodicEnergyImported::Type event;
event.periodStart = aPeriodStartS;
event.periodEnd = aPeriodEndS;
event.energyImported = aEnergyImported;

EventNumber eventNumber;
CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber);

if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[NotifyPeriodicEnergyImported] Unable to send event: %s [endpointId=%d]", error.AsString(), endpointId);
return false;
}
ChipLogProgress(Zcl, "[NotifyPeriodicEnergyImported] Sent event [endpointId=%d,eventNumber=%" PRIu64 ",periodStart=%u,periodEnd=%u,energyImported=%" PRIu64 "]",
endpointId, eventNumber, aPeriodStartS, aPeriodEndS, aEnergyImported);
return true;
}

bool NotifyPeriodicEnergyExported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyExported)
{
Events::PeriodicEnergyExported::Type event;
event.periodStart = aPeriodStartS;
event.periodEnd = aPeriodEndS;
event.energyExported = aEnergyExported;

EventNumber eventNumber;
CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber);

if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[NotifyPeriodicEnergyExported] Unable to send event: %s [endpointId=%d]", error.AsString(), endpointId);
return false;
}
ChipLogProgress(Zcl, "[NotifyPeriodicEnergyExported] Sent event [endpointId=%d,eventNumber=%" PRIu64 ",periodStart=%u,periodEnd=%u,energyExported=%" PRIu64 "]",
endpointId, eventNumber, aPeriodStartS, aPeriodEndS, aEnergyExported);
return true;
}

bool NotifyEphemeralEnergyImported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyImported)
{
Events::EphemeralEnergyImported::Type event;
event.periodStart = aPeriodStartS;
event.periodEnd = aPeriodEndS;
event.energyImported = aEnergyImported;

EventNumber eventNumber;
CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber);

if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[NotifyEphemeralEnergyImported] Unable to send event: %s [endpointId=%d]", error.AsString(), endpointId);
return false;
}
ChipLogProgress(Zcl, "[NotifyEphemeralEnergyImported] Sent event [endpointId=%d,eventNumber=%" PRIu64 ",periodStart=%u,periodEnd=%u,energyImported=%" PRIu64 "]",
endpointId, eventNumber, aPeriodStartS, aPeriodEndS, aEnergyImported);
return true;
}

bool NotifyEphemeralEnergyExported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyExported)
{
Events::EphemeralEnergyExported::Type event;
event.periodStart = aPeriodStartS;
event.periodEnd = aPeriodEndS;
event.energyExported = aEnergyExported;

EventNumber eventNumber;
CHIP_ERROR error = app::LogEvent(event, endpointId, eventNumber);

if (CHIP_NO_ERROR != error)
{
ChipLogError(Zcl, "[NotifyEphemeralEnergyExported] Unable to send event: %s [endpointId=%d]", error.AsString(), endpointId);
return false;
}
ChipLogProgress(Zcl, "[NotifyEphemeralEnergyExported] Sent event [endpointId=%d,eventNumber=%" PRIu64 ",periodStart=%u,periodEnd=%u,energyExported=%" PRIu64 "]",
endpointId, eventNumber, aPeriodStartS, aPeriodEndS, aEnergyExported);
return true;
}

}}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <app-common/zap-generated/cluster-objects.h>
#include <app/CommandHandler.h>
#include <app/ConcreteCommandPath.h>
#include <app/util/af.h>
#include <app/util/config.h>
#include <platform/CHIPDeviceConfig.h>
#include <protocols/interaction_model/StatusCode.h>

namespace chip {
namespace app {
namespace Clusters {
namespace ElectricalEnergyMeasurement {
namespace Server {

bool NotifyCumulativeEnergyImported(chip::EndpointId endpointId, uint32_t aImportedTimeStampS, uint64_t aEnergyImported);
bool NotifyCumulativeEnergyExported(chip::EndpointId endpointId, uint32_t aImportedTimeStampS, uint64_t aEnergyExported);

bool NotifyPeriodicEnergyImported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyImported);
bool NotifyPeriodicEnergyExported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyExported);

bool NotifyEphemeralEnergyImported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyImported);
bool NotifyEphemeralEnergyExported(chip::EndpointId endpointId, uint32_t aPeriodStartS, uint32_t aPeriodEndS, uint64_t aEnergyExported);

}}}}}

0 comments on commit 6d8daca

Please sign in to comment.