Skip to content

Commit

Permalink
Update EMBER_AF_PLUGIN_REPORTING to EMBER_AF_PLUGIN_REPORTING_SERVER …
Browse files Browse the repository at this point in the history
…in InitDataModelHandler

 #### Problem

The stack status callbacks should be called for the server side, not for the client.

This PR also contains some small changes to the `HandleDataModelMessage` signature as one of the argument is unused, and the other is only used to get the `NodeId`.
  • Loading branch information
vivien-apple committed Feb 1, 2021
1 parent d3bd21d commit 2215c63
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 44 deletions.
67 changes: 28 additions & 39 deletions src/app/server/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@

#include <app/server/DataModelHandler.h>

#include <app/chip-zcl-zpro-codec.h>
#include <app/util/af-types.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>
#include <lib/support/logging/CHIPLogging.h>
#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>

#ifdef EMBER_AF_PLUGIN_REPORTING
#ifdef EMBER_AF_PLUGIN_REPORTING_SERVER
void emberAfPluginReportingStackStatusCallback(EmberStatus status);
#endif
#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER
Expand All @@ -42,24 +38,38 @@ void emberAfPluginIasZoneServerStackStatusCallback(EmberStatus status);

using namespace ::chip;

/**
* Handle a message that should be processed via our data model processing
* codepath. This function will free the packet buffer.
*
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*/
void HandleDataModelMessage(const PacketHeader & header, System::PacketBufferHandle buffer, SecureSessionMgr * mgr)
void InitDataModelHandler()
{
emberAfEndpointConfigure();
emberAfInit();

#if defined(EMBER_AF_PLUGIN_REPORTING_SERVER) || defined(EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER) || \
defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER)
EmberStatus status = EMBER_NETWORK_UP;
#endif

#ifdef EMBER_AF_PLUGIN_REPORTING_SERVER
emberAfPluginReportingStackStatusCallback(status);
#endif
#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER
emberAfPluginTemperatureMeasurementServerStackStatusCallback(status);
#endif
#ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER
emberAfPluginIasZoneServerStackStatusCallback(status);
#endif
}

void HandleDataModelMessage(NodeId nodeId, System::PacketBufferHandle buffer)
{
EmberApsFrame frame;
bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0;
if (ok)
{
ChipLogProgress(Zcl, "APS frame processing success!");
ChipLogDetail(Zcl, "APS frame processing success!");
}
else
{
ChipLogProgress(Zcl, "APS frame processing failure!");
ChipLogDetail(Zcl, "APS frame processing failure!");
return;
}

Expand All @@ -68,36 +78,15 @@ void HandleDataModelMessage(const PacketHeader & header, System::PacketBufferHan
ok = emberAfProcessMessage(&frame,
0, // type
message, messageLen,
header.GetSourceNodeId().Value(), // source identifier
nodeId, // source identifier
NULL);

if (ok)
{
ChipLogProgress(Zcl, "Data model processing success!");
ChipLogDetail(Zcl, "Data model processing success!");
}
else
{
ChipLogProgress(Zcl, "Data model processing failure!");
ChipLogDetail(Zcl, "Data model processing failure!");
}
}

void InitDataModelHandler()
{
emberAfEndpointConfigure();
emberAfInit();

#if defined(EMBER_AF_PLUGIN_REPORTING) || defined(EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER) || \
defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER)
EmberStatus status = EMBER_NETWORK_UP;
#endif

#ifdef EMBER_AF_PLUGIN_REPORTING
emberAfPluginReportingStackStatusCallback(status);
#endif
#ifdef EMBER_AF_PLUGIN_TEMPERATURE_MEASUREMENT_SERVER
emberAfPluginTemperatureMeasurementServerStackStatusCallback(status);
#endif
#ifdef EMBER_AF_PLUGIN_IAS_ZONE_SERVER
emberAfPluginIasZoneServerStackStatusCallback(status);
#endif
}
14 changes: 10 additions & 4 deletions src/app/server/DataModelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@
#pragma once

#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/raw/MessageHeader.h>

/**
* Initialize the data model internal code to be ready to send and receive
* data model messages.
*
*/
void InitDataModelHandler();

/**
* Handle a message that should be processed via our data model processing
* codepath.
*
* @param [in] nodeId The source node id of the message
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*
*/
void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBufferHandle buffer,
chip::SecureSessionMgr * mgr);
void InitDataModelHandler();
void HandleDataModelMessage(chip::NodeId nodeId, chip::System::PacketBufferHandle buffer);
2 changes: 1 addition & 1 deletion src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ServerCallback : public SecureSessionMgrDelegate

ChipLogProgress(AppServer, "Packet received from %s: %zu bytes", src_addr, static_cast<size_t>(data_len));

HandleDataModelMessage(header, std::move(buffer), mgr);
HandleDataModelMessage(header.GetSourceNodeId().Value(), std::move(buffer));

exit:;
}
Expand Down

0 comments on commit 2215c63

Please sign in to comment.