Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable dynamically configurable logging by default #1213

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions user/tests/accept/features/logging/log_config_app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

SYSTEM_MODE(MANUAL)

// Enable dynamically configurable logging
STARTUP(System.enableFeature(FEATURE_CONFIGURABLE_LOGGING))

bool usb_request_custom_handler(char* buf, size_t bufSize, size_t reqSize, size_t* repSize) {
const char* msg = "Test message";
const char* cat = "app"; // Category name
Expand Down
10 changes: 10 additions & 0 deletions wiring/inc/spark_wiring_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define SPARK_WIRING_SYSTEM_H
#include "spark_wiring_ticks.h"
#include "spark_wiring_string.h"
#include "spark_wiring_platform.h"
#include "spark_wiring_version.h"
#include "system_mode.h"
#include "system_update.h"
Expand Down Expand Up @@ -68,6 +69,11 @@ class SleepNetworkFlag
const SleepNetworkFlag SLEEP_NETWORK_OFF(SystemSleepNetwork::Off);
const SleepNetworkFlag SLEEP_NETWORK_STANDBY(SystemSleepNetwork::Standby);

#if Wiring_LogConfig
enum LoggingFeature {
FEATURE_CONFIGURABLE_LOGGING = 1
};
#endif

class SystemClass {
public:
Expand Down Expand Up @@ -199,6 +205,10 @@ class SystemClass {
return HAL_Feature_Set(feature, false);
}

#if Wiring_LogConfig
bool enableFeature(LoggingFeature feature);
#endif

String version()
{
SystemVersionInfo info;
Expand Down
12 changes: 12 additions & 0 deletions wiring/src/spark_wiring_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
#include "rgbled.h"
#include "spark_wiring_wifi.h"
#include "spark_wiring_cloud.h"
#include "spark_wiring_logging.h"
#include "system_task.h"
#include "system_control.h"
#include "system_network.h"

#if Wiring_LogConfig
extern bool(*log_process_config_request_callback)(char*, size_t, size_t, size_t*, DataFormat);
#endif

SystemClass System;

Expand Down Expand Up @@ -53,3 +58,10 @@ uint32_t SystemClass::freeMemory()
HAL_Core_Runtime_Info(&info, NULL);
return info.freeheap;
}

#if Wiring_LogConfig
bool SystemClass::enableFeature(LoggingFeature) {
log_process_config_request_callback = spark::logProcessConfigRequest;
return true;
}
#endif
11 changes: 9 additions & 2 deletions wiring/src/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include "system_user.h"
#include "system_control.h"
#include <stddef.h>
#include <string.h>
#include "spark_wiring_platform.h"
Expand Down Expand Up @@ -163,7 +164,10 @@ bool __backup_ram_was_valid() { return false; }

#endif

#include "system_control.h"
#if Wiring_LogConfig
// Callback invoked to process USB request for logging configuration
bool(*log_process_config_request_callback)(char*, size_t, size_t, size_t*, DataFormat) = nullptr;
#endif

#ifdef USB_VENDOR_REQUEST_ENABLE

Expand All @@ -174,13 +178,16 @@ bool __attribute((weak)) usb_request_custom_handler(char* buf, size_t buf_size,

bool usb_request_app_handler(USBRequest* req, void* reserved) {
switch (req->type) {
#if Wiring_LogConfig
case USB_REQUEST_LOG_CONFIG: {
if (!spark::logProcessConfigRequest(req->data, USB_REQUEST_BUFFER_SIZE, req->request_size, &req->reply_size, (DataFormat)req->format)) {
if (!log_process_config_request_callback || !log_process_config_request_callback(req->data, USB_REQUEST_BUFFER_SIZE,
req->request_size, &req->reply_size, (DataFormat)req->format)) {
return false;
}
system_set_usb_request_result(req, USB_REQUEST_RESULT_OK, nullptr);
return true;
}
#endif
case USB_REQUEST_CUSTOM: {
if (!usb_request_custom_handler(req->data, USB_REQUEST_BUFFER_SIZE, req->request_size, &req->reply_size)) {
return false;
Expand Down