WIP: Device layer port to nRF52840
-- Added event logging infrastructure support for the Weave Device Layer.
diff --git a/build/esp32/components/openweave/Kconfig b/build/esp32/components/openweave/Kconfig
index 2e5aa05..0c8e426 100644
--- a/build/esp32/components/openweave/Kconfig
+++ b/build/esp32/components/openweave/Kconfig
@@ -751,4 +751,44 @@
endmenu
+ menu "Event Logging Options"
+
+ config EVENT_LOGGING_DEBUG_BUFFER_SIZE
+ int "Event Logging Debug Buffer Size"
+ range 0 65535
+ default 1024
+ help
+ A size, in bytes, of the individual debug event logging buffer.
+
+ When this option is set to 0, the debug event buffer is disabled.
+
+ config EVENT_LOGGING_INFO_BUFFER_SIZE
+ int "Event Logging Info Buffer Size"
+ range 0 65535
+ default 1024
+ help
+ A size, in bytes, of the individual info event logging buffer.
+
+ When this option is set to 0, the info event buffer is disabled.
+
+ config EVENT_LOGGING_PROD_BUFFER_SIZE
+ int "Event Logging Production Buffer Size"
+ range 0 65535
+ default 2048
+ help
+ A size, in bytes, of the individual production event logging buffer.
+
+ This critical production event buffer must exist.
+
+ config EVENT_LOGGING_CRIT_BUFFER_SIZE
+ int "Event Logging Critical Production Buffer Size"
+ range 0 65535
+ default 4096
+ help
+ A size, in bytes, of the individual critical production event logging buffer.
+
+ This critical production event buffer must exist.
+
+ endmenu
+
endmenu
diff --git a/src/adaptations/device-layer/ESP32/ESP32Config.cpp b/src/adaptations/device-layer/ESP32/ESP32Config.cpp
index b1920be..28ee2de 100644
--- a/src/adaptations/device-layer/ESP32/ESP32Config.cpp
+++ b/src/adaptations/device-layer/ESP32/ESP32Config.cpp
@@ -56,6 +56,12 @@
const ESP32Config::Key ESP32Config::kConfigKey_FailSafeArmed = { kConfigNamespace_WeaveConfig, "fail-safe-armed" };
const ESP32Config::Key ESP32Config::kConfigKey_WiFiStationSecType = { kConfigNamespace_WeaveConfig, "sta-sec-type" };
+// Keys stored in the weave-counters namespace
+const ESP32Config::Key ESP32Config::kConfigKey_DebugEventIdCounter = { kConfigNamespace_WeaveCounters, "debug-eidc" };
+const ESP32Config::Key ESP32Config::kConfigKey_InfoEventIdCounter = { kConfigNamespace_WeaveCounters, "info-eidc" };
+const ESP32Config::Key ESP32Config::kConfigKey_ProdEventIdCounter = { kConfigNamespace_WeaveCounters, "production-eidc" };
+const ESP32Config::Key ESP32Config::kConfigKey_CritEventIdCounter = { kConfigNamespace_WeaveCounters, "critical-eidc" };
+
// Prefix used for NVS keys that contain Weave group encryption keys.
const char ESP32Config::kGroupKeyNamePrefix[] = "gk-";
diff --git a/src/adaptations/device-layer/EventLoggingManager.cpp b/src/adaptations/device-layer/EventLoggingManager.cpp
new file mode 100644
index 0000000..9d98c95
--- /dev/null
+++ b/src/adaptations/device-layer/EventLoggingManager.cpp
@@ -0,0 +1,149 @@
+/*
+ *
+ * Copyright (c) 2019 Google LLC.
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Implementation for the Weave Device Layer EventLoggingManager object.
+ *
+ */
+
+#include <Weave/DeviceLayer/internal/WeaveDeviceLayerInternal.h>
+#include <Weave/DeviceLayer/EventLoggingManager.h>
+
+using namespace nl::Weave::DeviceLayer;
+
+namespace nl {
+namespace Weave {
+namespace DeviceLayer {
+namespace Internal {
+
+// For each priority level initialize event buffers and event Id counters.
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+uint64_t gDebugEventBuffer[(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE + 7) / 8];
+PersistedCounter sDebugEventIdCounter;
+#endif
+
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+uint64_t gInfoEventBuffer[(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE + 7) / 8];
+PersistedCounter sInfoEventIdCounter;
+#endif
+
+uint64_t gProdEventBuffer[(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE + 7) / 8];
+PersistedCounter sProdEventIdCounter;
+
+uint64_t gCritEventBuffer[(WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE + 7) / 8];
+PersistedCounter sCritEventIdCounter;
+
+EventLoggingManager EventLoggingManager::sInstance;
+
+WEAVE_ERROR EventLoggingManager::Init(void)
+{
+ nl::Weave::Platform::PersistedStorage::Key eidcStorageKeys[WEAVE_DEVICE_CONFIG_EVENT_LOGGING_NUM_BUFFERS];
+
+ size_t eventBufferSizes[] = {
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+ sizeof(gDebugEventBuffer),
+#endif
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+ sizeof(gInfoEventBuffer),
+#endif
+ sizeof(gProdEventBuffer),
+ sizeof(gCritEventBuffer),
+ };
+
+ void * eventBuffers[] = {
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+ static_cast<void *>(&gDebugEventBuffer[0]),
+#endif
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+ static_cast<void *>(&gInfoEventBuffer[0]),
+#endif
+ static_cast<void *>(&gProdEventBuffer[0]),
+ static_cast<void *>(&gCritEventBuffer[0]),
+ };
+
+ // For each priority level initialize event id counter storage keys.
+ ConfigurationMgr().GetEventIdCounterStorageKeys(eidcStorageKeys);
+
+ const uint32_t eidcEpochs[] = {
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+ WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH,
+#endif
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+ WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH,
+#endif
+ WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH,
+ WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH,
+ };
+
+ PersistedCounter * eidcStorage[] = {
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+ &sDebugEventIdCounter,
+#endif
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+ &sInfoEventIdCounter,
+#endif
+ &sProdEventIdCounter,
+ &sCritEventIdCounter,
+ };
+
+ LoggingManagement::CreateLoggingManagement(
+ &::nl::Weave::DeviceLayer::ExchangeMgr,
+ WEAVE_DEVICE_CONFIG_EVENT_LOGGING_NUM_BUFFERS,
+ &eventBufferSizes[0],
+ &eventBuffers[0],
+ eidcStorageKeys,
+ eidcEpochs,
+ eidcStorage);
+
+ return WEAVE_NO_ERROR;
+}
+
+WEAVE_ERROR EventLoggingManager::Shutdown(void)
+{
+ LoggingManagement::DestroyLoggingManagement();
+ return WEAVE_NO_ERROR;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace Weave
+} // namespace nl
+
+
+namespace nl {
+namespace Weave {
+namespace Profiles {
+namespace DataManagement_Current {
+namespace Platform {
+
+void CriticalSectionEnter(void)
+{
+ return PlatformMgr().LockWeaveStack();
+}
+
+void CriticalSectionExit(void)
+{
+ return PlatformMgr().UnlockWeaveStack();
+}
+
+} // namespace Platform
+} // namespace DataManagement_Current
+} // namespace Profiles
+} // namespace Weave
+} // namespace nl
diff --git a/src/adaptations/device-layer/Makefile.am b/src/adaptations/device-layer/Makefile.am
index 995eb6b..8445981 100644
--- a/src/adaptations/device-layer/Makefile.am
+++ b/src/adaptations/device-layer/Makefile.am
@@ -51,6 +51,7 @@
include/Weave/DeviceLayer/nRF5/nRF5Config.h \
include/Weave/DeviceLayer/nRF5/WeaveDevicePlatformConfig.h \
include/Weave/DeviceLayer/nRF5/WeaveDevicePlatformEvent.h \
+ include/Weave/DeviceLayer/EventLoggingManager.h \
include/Weave/DeviceLayer/FreeRTOS/GenericPlatformManagerImpl_FreeRTOS.h \
include/Weave/DeviceLayer/FreeRTOS/GenericPlatformManagerImpl_FreeRTOS.ipp \
include/Weave/DeviceLayer/GeneralUtils.h \
@@ -104,6 +105,7 @@
DeviceIdentityTraitDataSource.cpp \
DeviceNetworkInfo.cpp \
EchoServer.cpp \
+ EventLoggingManager.cpp \
FabricProvisioningServer.cpp \
GeneralUtils.cpp \
Globals.cpp \
diff --git a/src/adaptations/device-layer/Makefile.in b/src/adaptations/device-layer/Makefile.in
index 26b4925..f2b902b 100644
--- a/src/adaptations/device-layer/Makefile.in
+++ b/src/adaptations/device-layer/Makefile.in
@@ -216,8 +216,8 @@
am__libDeviceLayer_a_SOURCES_DIST = CASEAuth.cpp \
DeviceControlServer.cpp DeviceDescriptionServer.cpp \
DeviceIdentityTraitDataSource.cpp DeviceNetworkInfo.cpp \
- EchoServer.cpp FabricProvisioningServer.cpp GeneralUtils.cpp \
- Globals.cpp NetworkTelemetryManager.cpp \
+ EchoServer.cpp EventLoggingManager.cpp FabricProvisioningServer.cpp \
+ GeneralUtils.cpp Globals.cpp NetworkTelemetryManager.cpp \
PersistedStorage.cpp ServiceDirectoryManager.cpp \
ServiceProvisioningServer.cpp ServiceTunnelAgent.cpp \
SystemEventSupport.cpp SystemTimerSupport.cpp \
@@ -278,6 +278,7 @@
@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-DeviceIdentityTraitDataSource.$(OBJEXT) \
@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-DeviceNetworkInfo.$(OBJEXT) \
@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-EchoServer.$(OBJEXT) \
+@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-EventLoggingManager.$(OBJEXT) \
@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-FabricProvisioningServer.$(OBJEXT) \
@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-GeneralUtils.$(OBJEXT) \
@CONFIG_DEVICE_LAYER_TRUE@ libDeviceLayer_a-Globals.$(OBJEXT) \
@@ -642,6 +643,7 @@
include/Weave/DeviceLayer/nRF5/nRF5Config.h \
include/Weave/DeviceLayer/nRF5/WeaveDevicePlatformConfig.h \
include/Weave/DeviceLayer/nRF5/WeaveDevicePlatformEvent.h \
+ include/Weave/DeviceLayer/EventLoggingManager.h \
include/Weave/DeviceLayer/FreeRTOS/GenericPlatformManagerImpl_FreeRTOS.h \
include/Weave/DeviceLayer/FreeRTOS/GenericPlatformManagerImpl_FreeRTOS.ipp \
include/Weave/DeviceLayer/GeneralUtils.h \
@@ -690,6 +692,7 @@
@CONFIG_DEVICE_LAYER_TRUE@ DeviceDescriptionServer.cpp \
@CONFIG_DEVICE_LAYER_TRUE@ DeviceIdentityTraitDataSource.cpp \
@CONFIG_DEVICE_LAYER_TRUE@ DeviceNetworkInfo.cpp EchoServer.cpp \
+@CONFIG_DEVICE_LAYER_TRUE@ EventLoggingManager.cpp \
@CONFIG_DEVICE_LAYER_TRUE@ FabricProvisioningServer.cpp \
@CONFIG_DEVICE_LAYER_TRUE@ GeneralUtils.cpp Globals.cpp \
@CONFIG_DEVICE_LAYER_TRUE@ NetworkTelemetryManager.cpp \
@@ -917,6 +920,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-DeviceIdentityTraitDataSource.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-DeviceNetworkInfo.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-EchoServer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-FabricProvisioningServer.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-GeneralUtils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libDeviceLayer_a-Globals.Po@am__quote@
@@ -1071,6 +1075,20 @@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libDeviceLayer_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libDeviceLayer_a-EchoServer.obj `if test -f 'EchoServer.cpp'; then $(CYGPATH_W) 'EchoServer.cpp'; else $(CYGPATH_W) '$(srcdir)/EchoServer.cpp'; fi`
+libDeviceLayer_a-EventLoggingManager.o: EventLoggingManager.cpp
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libDeviceLayer_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libDeviceLayer_a-EventLoggingManager.o -MD -MP -MF $(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Tpo -c -o libDeviceLayer_a-EventLoggingManager.o `test -f 'EventLoggingManager.cpp' || echo '$(srcdir)/'`EventLoggingManager.cpp
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Tpo $(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='EventLoggingManager.cpp' object='libDeviceLayer_a-EventLoggingManager.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libDeviceLayer_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libDeviceLayer_a-EventLoggingManager.o `test -f 'EventLoggingManager.cpp' || echo '$(srcdir)/'`EventLoggingManager.cpp
+
+libDeviceLayer_a-EventLoggingManager.obj: EventLoggingManager.cpp
+@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libDeviceLayer_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libDeviceLayer_a-EventLoggingManager.obj -MD -MP -MF $(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Tpo -c -o libDeviceLayer_a-EventLoggingManager.obj `if test -f 'EventLoggingManager.cpp'; then $(CYGPATH_W) 'EventLoggingManager.cpp'; else $(CYGPATH_W) '$(srcdir)/EventLoggingManager.cpp'; fi`
+@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Tpo $(DEPDIR)/libDeviceLayer_a-EventLoggingManager.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='EventLoggingManager.cpp' object='libDeviceLayer_a-EventLoggingManager.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libDeviceLayer_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o libDeviceLayer_a-EventLoggingManager.obj `if test -f 'EventLoggingManager.cpp'; then $(CYGPATH_W) 'EventLoggingManager.cpp'; else $(CYGPATH_W) '$(srcdir)/EventLoggingManager.cpp'; fi`
+
libDeviceLayer_a-FabricProvisioningServer.o: FabricProvisioningServer.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libDeviceLayer_a_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT libDeviceLayer_a-FabricProvisioningServer.o -MD -MP -MF $(DEPDIR)/libDeviceLayer_a-FabricProvisioningServer.Tpo -c -o libDeviceLayer_a-FabricProvisioningServer.o `test -f 'FabricProvisioningServer.cpp' || echo '$(srcdir)/'`FabricProvisioningServer.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libDeviceLayer_a-FabricProvisioningServer.Tpo $(DEPDIR)/libDeviceLayer_a-FabricProvisioningServer.Po
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h
index 7a9acfd..db9a1ac 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h
@@ -34,6 +34,7 @@
class PlatformManagerImpl;
class ConfigurationManagerImpl;
+class EventLoggingManager;
class TraitManager;
namespace Internal {
template<class> class GenericPlatformManagerImpl;
@@ -98,6 +99,8 @@
WEAVE_ERROR GetWiFiAPSSID(char * buf, size_t bufSize);
+ void GetEventIdCounterStorageKeys(::nl::Weave::Platform::PersistedStorage::Key * eidcStorageKeys);
+
bool IsServiceProvisioned();
bool IsPairedToAccount();
bool IsMemberOfFabric();
@@ -362,6 +365,11 @@
return static_cast<ImplClass*>(this)->_GetWiFiAPSSID(buf, bufSize);
}
+inline void ConfigurationManager::GetEventIdCounterStorageKeys(::nl::Weave::Platform::PersistedStorage::Key * eidcStorageKeys)
+{
+ static_cast<ImplClass*>(this)->_GetEventIdCounterStorageKeys(eidcStorageKeys);
+}
+
inline bool ConfigurationManager::IsServiceProvisioned()
{
return static_cast<ImplClass*>(this)->_IsServiceProvisioned();
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/ESP32Config.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/ESP32Config.h
index 7acef67..1b1f076 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/ESP32Config.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/ESP32Config.h
@@ -67,6 +67,10 @@
static const Key kConfigKey_LastUsedEpochKeyId;
static const Key kConfigKey_FailSafeArmed;
static const Key kConfigKey_WiFiStationSecType;
+ static const Key kConfigKey_DebugEventIdCounter;
+ static const Key kConfigKey_InfoEventIdCounter;
+ static const Key kConfigKey_ProdEventIdCounter;
+ static const Key kConfigKey_CritEventIdCounter;
static const char kGroupKeyNamePrefix[];
@@ -88,6 +92,11 @@
// NVS Namespace helper functions.
static WEAVE_ERROR EnsureNamespace(const char * ns);
static WEAVE_ERROR ClearNamespace(const char * ns);
+
+protected:
+
+ static const char * GetFileId(Key key);
+ static const char * GetRecordKey(Key key);
};
struct ESP32Config::Key
@@ -98,6 +107,16 @@
bool operator==(const Key & other) const;
};
+inline const char * ESP32Config::GetFileId(Key configKey)
+{
+ return configKey.Namespace;
+}
+
+inline const char * ESP32Config::GetRecordKey(Key configKey)
+{
+ return configKey.Name;
+}
+
inline bool ESP32Config::Key::operator==(const Key & other) const
{
return strcmp(Namespace, other.Namespace) == 0 && strcmp(Name, other.Name) == 0;
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeaveDevicePlatformConfig.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeaveDevicePlatformConfig.h
index fb834e3..c8561ae 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeaveDevicePlatformConfig.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeaveDevicePlatformConfig.h
@@ -73,5 +73,9 @@
#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY CONFIG_ENABLE_THREAD_TELEMETRY
#define WEAVE_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL CONFIG_ENABLE_THREAD_TELEMETRY_FULL
#define WEAVE_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY CONFIG_ENABLE_TUNNEL_TELEMETRY
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE
#endif // WEAVE_DEVICE_PLATFORM_CONFIG_H
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/EventLoggingManager.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/EventLoggingManager.h
new file mode 100644
index 0000000..b825daf
--- /dev/null
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/EventLoggingManager.h
@@ -0,0 +1,72 @@
+/*
+ *
+ * Copyright (c) 2019 Google LLC.
+ * All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * Defines the Weave Device Layer EventLoggingManager object.
+ *
+ */
+
+#ifndef EVENT_LOGGING_MANAGER_H
+#define EVENT_LOGGING_MANAGER_H
+
+#include <Weave/Profiles/data-management/Current/DataManagement.h>
+
+namespace nl {
+namespace Weave {
+namespace DeviceLayer {
+namespace Internal {
+
+/**
+ * When an event is logged by Weave, the event is first serialized (on
+ * the thread that's denoting the event) and stored in an event buffer
+ * owned by a LoggingManagement. Sometime later (on the Weave
+ * thread), the event buffers are flushed and the events are offloaded
+ * (via WDM) to all events subscribers.
+ */
+class EventLoggingManager final
+{
+ typedef ::nl::Weave::Profiles::DataManagement_Current::LoggingManagement LoggingManagement;
+
+public:
+ WEAVE_ERROR Init(void);
+ WEAVE_ERROR Shutdown(void);
+
+private:
+ // ===== Members for internal use by the following friends.
+
+ friend class ::nl::Weave::DeviceLayer::PlatformManagerImpl;
+ friend EventLoggingManager & EventLoggingMgr(void);
+
+ static EventLoggingManager sInstance;
+};
+
+/**
+ * Returns a reference to the EventLoggingManager singleton object.
+ */
+inline EventLoggingManager & EventLoggingMgr(void)
+{
+ return EventLoggingManager::sInstance;
+}
+
+} // namespace Internal
+} // namespace DeviceLayer
+} // namespace Weave
+} // namespace nl
+
+#endif // EVENT_LOGGING_MANAGER_H
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/PlatformManager.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/PlatformManager.h
index 37d5fd4..9a1d83d 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/PlatformManager.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/PlatformManager.h
@@ -33,6 +33,7 @@
class PlatformManagerImpl;
class ConnectivityManagerImpl;
class ConfigurationManagerImpl;
+class EventLoggingManager;
class TraitManager;
class TimeSyncManager;
namespace Internal {
@@ -79,6 +80,7 @@
friend class PlatformManagerImpl;
friend class ConnectivityManagerImpl;
friend class ConfigurationManagerImpl;
+ friend class EventLoggingManager;
friend class TraitManager;
friend class TimeSyncManager;
friend class Internal::FabricProvisioningServer;
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h
index b88a74f..66e0d2c 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h
@@ -657,4 +657,96 @@
#define WEAVE_DEVICE_CONFIG_DEFAULT_TUNNEL_TELEMETRY_INTERVAL_MS 300000
#endif
+// -------------------- Event Logging Configuration --------------------
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
+ *
+ * @brief
+ * A size, in bytes, of the individual debug event logging buffer.
+ * Note: set to 0 to disable debug event buffer.
+ */
+#ifndef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (256)
+#endif
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+ *
+ * @brief
+ * Bool if the debug buffer for events exists
+ */
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS (1)
+#else
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS (0)
+#endif
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE
+ *
+ * @brief
+ * A size, in bytes, of the individual info event logging buffer.
+ * Note: set to 0 to disable info event buffer.
+ */
+#ifndef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE (512)
+#endif
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+ *
+ * @brief
+ * Bool if the info buffer for events exists
+ */
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS (1)
+#else
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS (0)
+#endif
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE
+ *
+ * @brief
+ * A size, in bytes, of the individual production event logging buffer.
+ * Note: the production event buffer must exist.
+ */
+#ifndef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE (512)
+#endif
+
+#if (WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE <= 0)
+#error "The Prod event buffer must exist (WEAVE_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE > 0)"
+#endif
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE
+ *
+ * @brief
+ * A size, in bytes, of the individual critical event logging buffer.
+ * Note: the critical event buffer must exist.
+ */
+#ifndef WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE (1024)
+#endif
+
+#if (WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE <= 0)
+#error "The Prod critical event buffer must exist (WEAVE_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE > 0)"
+#endif
+
+#define WEAVE_DEVICE_CONFIG_EVENT_LOGGING_NUM_BUFFERS (2 + \
+ WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS + \
+ WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS)
+
+/**
+ * @def WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH
+ *
+ * @brief
+ * The event id counter persisted storage epoch.
+ */
+#ifndef WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH
+#define WEAVE_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH (0x10000)
+#endif
+
#endif // WEAVE_DEVICE_CONFIG_H
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceLayer.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceLayer.h
index 1d7343e..362e76c 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceLayer.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceLayer.h
@@ -31,6 +31,7 @@
#if WEAVE_DEVICE_CONFIG_ENABLE_TRAIT_MANAGER
#include <Weave/DeviceLayer/TraitManager.h>
#endif // WEAVE_DEVICE_CONFIG_ENABLE_TRAIT_MANAGER
+#include <Weave/DeviceLayer/EventLoggingManager.h>
#include <Weave/DeviceLayer/TimeSyncManager.h>
#if WEAVE_DEVICE_CONFIG_ENABLE_THREAD
#include <Weave/DeviceLayer/ThreadStackManager.h>
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h
index 8d18db7..27e9614 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h
@@ -85,6 +85,7 @@
WEAVE_ERROR _GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen);
WEAVE_ERROR _GetQRCodeString(char * buf, size_t bufSize);
WEAVE_ERROR _GetWiFiAPSSID(char * buf, size_t bufSize);
+ void _GetEventIdCounterStorageKeys(::nl::Weave::Platform::PersistedStorage::Key * eidcStorageKeys);
bool _IsServiceProvisioned();
bool _IsMemberOfFabric();
bool _IsPairedToAccount();
@@ -140,4 +141,3 @@
} // namespace nl
#endif // GENERIC_CONFIGURATION_MANAGER_IMPL_H
-
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp
index 81c9612..30f569f 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp
@@ -616,6 +616,21 @@
}
template<class ImplClass>
+void GenericConfigurationManagerImpl<ImplClass>::_GetEventIdCounterStorageKeys(::nl::Weave::Platform::PersistedStorage::Key * eidcStorageKeys)
+{
+ int i = 0;
+
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_EVENTS
+ eidcStorageKeys[i++] = ImplClass::GetRecordKey(ImplClass::kConfigKey_DebugEventIdCounter);
+#endif
+#if WEAVE_DEVICE_CONFIG_EVENT_LOGGING_INFO_EVENTS
+ eidcStorageKeys[i++] = ImplClass::GetRecordKey(ImplClass::kConfigKey_InfoEventIdCounter);
+#endif
+ eidcStorageKeys[i++] = ImplClass::GetRecordKey(ImplClass::kConfigKey_ProdEventIdCounter);
+ eidcStorageKeys[i] = ImplClass::GetRecordKey(ImplClass::kConfigKey_CritEventIdCounter);
+}
+
+template<class ImplClass>
bool GenericConfigurationManagerImpl<ImplClass>::_IsServiceProvisioned()
{
return ::nl::GetFlag(mFlags, kFlag_IsServiceProvisioned);
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericPlatformManagerImpl.ipp b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericPlatformManagerImpl.ipp
index c554aed..ca327a7 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericPlatformManagerImpl.ipp
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericPlatformManagerImpl.ipp
@@ -236,6 +236,14 @@
}
SuccessOrExit(err);
+ // Initialize the Event Logging Manager object.
+ err = EventLoggingMgr().Init();
+ if (err != WEAVE_NO_ERROR)
+ {
+ WeaveLogError(DeviceLayer, "Event Logging Manager initialization failed: %s", ErrorStr(err));
+ }
+ SuccessOrExit(err);
+
// Initialize the Trait Manager object.
#if WEAVE_DEVICE_CONFIG_ENABLE_TRAIT_MANAGER
err = TraitMgr().Init();
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/testing/ConfigUnitTest.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/testing/ConfigUnitTest.h
index 50676a3..dda9273 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/testing/ConfigUnitTest.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/internal/testing/ConfigUnitTest.h
@@ -44,6 +44,18 @@
VerifyOrDie(err == WEAVE_NO_ERROR);
VerifyOrDie(v == 42);
+
+ v = 0xAA99FF03;
+
+ err = ConfigClass::WriteConfigValue(ConfigClass::kConfigKey_CritEventIdCounter, v);
+ VerifyOrDie(err == WEAVE_NO_ERROR);
+
+ v = 0;
+
+ err = ConfigClass::ReadConfigValue(ConfigClass::kConfigKey_CritEventIdCounter, v);
+ VerifyOrDie(err == WEAVE_NO_ERROR);
+
+ VerifyOrDie(v == 0xAA99FF03);
}
// ===== Test 2: Store and read uint64_t
@@ -181,6 +193,12 @@
v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_FailSafeArmed);
VerifyOrDie(v == true);
+ v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_CritEventIdCounter);
+ VerifyOrDie(v == true);
+
+ v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_DebugEventIdCounter);
+ VerifyOrDie(v == false);
+
v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_DeviceCert);
VerifyOrDie(v == false);
}
@@ -197,6 +215,12 @@
v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_FailSafeArmed);
VerifyOrDie(v == false);
+
+ v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_CritEventIdCounter);
+ VerifyOrDie(v == true);
+
+ v = ConfigClass::ConfigValueExists(ConfigClass::kConfigKey_DebugEventIdCounter);
+ VerifyOrDie(v == false);
}
}
diff --git a/src/adaptations/device-layer/include/Weave/DeviceLayer/nRF5/nRF5Config.h b/src/adaptations/device-layer/include/Weave/DeviceLayer/nRF5/nRF5Config.h
index 4765d48..24a3a07 100644
--- a/src/adaptations/device-layer/include/Weave/DeviceLayer/nRF5/nRF5Config.h
+++ b/src/adaptations/device-layer/include/Weave/DeviceLayer/nRF5/nRF5Config.h
@@ -41,7 +41,6 @@
return static_cast<uint32_t>(fileId) << 16 | recordId;
}
-
/**
* Provides functions and definitions for accessing persisted device configuration
* on platforms based on the Nordic nRF5 SDK.
@@ -90,6 +89,10 @@
static constexpr Key kConfigKey_LastUsedEpochKeyId = NRF5ConfigKey(kFileId_WeaveConfig, 0x000C);
static constexpr Key kConfigKey_FailSafeArmed = NRF5ConfigKey(kFileId_WeaveConfig, 0x000D);
static constexpr Key kConfigKey_GroupKey = NRF5ConfigKey(kFileId_WeaveConfig, 0x000E);
+ static constexpr Key kConfigKey_DebugEventIdCounter = NRF5ConfigKey(kFileId_WeaveCounter, 0x000F);
+ static constexpr Key kConfigKey_InfoEventIdCounter = NRF5ConfigKey(kFileId_WeaveCounter, 0x0010);
+ static constexpr Key kConfigKey_ProdEventIdCounter = NRF5ConfigKey(kFileId_WeaveCounter, 0x0011);
+ static constexpr Key kConfigKey_CritEventIdCounter = NRF5ConfigKey(kFileId_WeaveCounter, 0x0012);
// Range of FDS record keys used to store Weave persisted counter values.
static constexpr uint16_t kPersistedCounterRecordKeyBase = kFDSRecordKeyMin;
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index b6c5bf3..7b7d4d3 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -968,6 +968,7 @@
nl_public_WeaveDeviceLayer_base_header_sources = \
$(nl_public_WeaveDeviceLayer_source_dirstem)/ConfigurationManager.h \
$(nl_public_WeaveDeviceLayer_source_dirstem)/ConnectivityManager.h \
+$(nl_public_WeaveDeviceLayer_source_dirstem)/EventLoggingManager.h \
$(nl_public_WeaveDeviceLayer_source_dirstem)/GeneralUtils.h \
$(nl_public_WeaveDeviceLayer_source_dirstem)/NetworkTelemetryManager.h \
$(nl_public_WeaveDeviceLayer_source_dirstem)/PlatformManager.h \
diff --git a/src/include/Makefile.in b/src/include/Makefile.in
index 7a6b959..e4e92ec 100644
--- a/src/include/Makefile.in
+++ b/src/include/Makefile.in
@@ -1345,6 +1345,7 @@
@CONFIG_DEVICE_LAYER_TRUE@nl_public_WeaveDeviceLayer_base_header_sources = \
@CONFIG_DEVICE_LAYER_TRUE@$(nl_public_WeaveDeviceLayer_source_dirstem)/ConfigurationManager.h \
@CONFIG_DEVICE_LAYER_TRUE@$(nl_public_WeaveDeviceLayer_source_dirstem)/ConnectivityManager.h \
+@CONFIG_DEVICE_LAYER_TRUE@$(nl_public_WeaveDeviceLayer_source_dirstem)/EventLoggingManager.h \
@CONFIG_DEVICE_LAYER_TRUE@$(nl_public_WeaveDeviceLayer_source_dirstem)/GeneralUtils.h \
@CONFIG_DEVICE_LAYER_TRUE@$(nl_public_WeaveDeviceLayer_source_dirstem)/NetworkTelemetryManager.h \
@CONFIG_DEVICE_LAYER_TRUE@$(nl_public_WeaveDeviceLayer_source_dirstem)/PlatformManager.h \