Skip to content

Commit

Permalink
Test: check core feature build (#2080)
Browse files Browse the repository at this point in the history
* Test: check core feature build

* order

* add missing
  • Loading branch information
mcspr committed Dec 21, 2019
1 parent 9edccd1 commit 37763f1
Show file tree
Hide file tree
Showing 21 changed files with 325 additions and 251 deletions.
64 changes: 0 additions & 64 deletions code/espurna/config/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ extern "C" {
}

#define UNUSED(x) (void)(x)
#define INLINE inline __attribute__((always_inline))

// -----------------------------------------------------------------------------
// System
Expand Down Expand Up @@ -313,69 +312,6 @@ using web_request_callback_f = std::function<bool(AsyncWebServerRequest*)>;
void webBodyRegister(web_body_callback_f);
void webRequestRegister(web_request_callback_f);

// -----------------------------------------------------------------------------
// WebSockets
// -----------------------------------------------------------------------------
#include <queue>

// TODO: pending configuration headers refactoring... here for now
struct ws_counter_t;
struct ws_data_t;
struct ws_debug_t;
struct ws_callbacks_t;

using ws_on_send_callback_f = std::function<void(JsonObject& root)>;
using ws_on_action_callback_f = std::function<void(uint32_t client_id, const char * action, JsonObject& data)>;
using ws_on_keycheck_callback_f = std::function<bool(const char * key, JsonVariant& value)>;

using ws_on_send_callback_list_t = std::vector<ws_on_send_callback_f>;
using ws_on_action_callback_list_t = std::vector<ws_on_action_callback_f>;
using ws_on_keycheck_callback_list_t = std::vector<ws_on_keycheck_callback_f>;

#if WEB_SUPPORT
struct ws_callbacks_t {
ws_on_send_callback_list_t on_visible;
ws_on_send_callback_list_t on_connected;
ws_on_send_callback_list_t on_data;

ws_on_action_callback_list_t on_action;
ws_on_keycheck_callback_list_t on_keycheck;

ws_callbacks_t& onVisible(ws_on_send_callback_f);
ws_callbacks_t& onConnected(ws_on_send_callback_f);
ws_callbacks_t& onData(ws_on_send_callback_f);
ws_callbacks_t& onAction(ws_on_action_callback_f);
ws_callbacks_t& onKeyCheck(ws_on_keycheck_callback_f);
};

ws_callbacks_t& wsRegister();

void wsSetup();
void wsSend(uint32_t client_id, const char* data);
void wsSend(uint32_t client_id, JsonObject& root);
void wsSend(JsonObject& root);
void wsSend(ws_on_send_callback_f callback);

void wsSend_P(PGM_P data);
void wsSend_P(uint32_t client_id, PGM_P data);

void INLINE wsPost(const ws_on_send_callback_f& callback);
void INLINE wsPost(uint32_t client_id, const ws_on_send_callback_f& callback);
void INLINE wsPost(const ws_on_send_callback_list_t& callbacks);
void INLINE wsPost(uint32_t client_id, const ws_on_send_callback_list_t& callbacks);

void INLINE wsPostAll(uint32_t client_id, const ws_on_send_callback_list_t& callbacks);
void INLINE wsPostAll(const ws_on_send_callback_list_t& callbacks);

void INLINE wsPostSequence(uint32_t client_id, const ws_on_send_callback_list_t& callbacks);
void INLINE wsPostSequence(uint32_t client_id, ws_on_send_callback_list_t&& callbacks);
void INLINE wsPostSequence(const ws_on_send_callback_list_t& callbacks);

bool INLINE wsConnected();
bool INLINE wsConnected(uint32_t client_id);
bool wsDebugSend(const char* prefix, const char* message);
#endif

// -----------------------------------------------------------------------------
// WIFI
// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions code/espurna/espurna.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "relay.h"
#include "broker.h"
#include "tuya.h"
#include "ws.h"
#include "libs/HeapStats.h"

using void_callback_f = void (*)();
Expand Down
2 changes: 2 additions & 0 deletions code/espurna/homeassistant.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <Schedule.h>
#include <ArduinoJson.h>

#include "ws.h"

bool _ha_enabled = false;
bool _ha_send_flag = false;

Expand Down
1 change: 1 addition & 0 deletions code/espurna/light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "tuya.h"
#include "light.h"
#include "broker.h"
#include "ws.h"

#include <Ticker.h>
#include <Schedule.h>
Expand Down
1 change: 1 addition & 0 deletions code/espurna/mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Updated secure client support by Niek van der Maas < mail at niekvandermaas dot

#include "system.h"
#include "libs/SecureClientHelpers.h"
#include "ws.h"

#if MQTT_LIBRARY == MQTT_LIBRARY_ASYNCMQTTCLIENT

Expand Down
1 change: 1 addition & 0 deletions code/espurna/nofuss.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if NOFUSS_SUPPORT

#include "NoFUSSClient.h"
#include "ws.h"

unsigned long _nofussLastCheck = 0;
unsigned long _nofussInterval = 0;
Expand Down
1 change: 1 addition & 0 deletions code/espurna/ntp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>

#include "libs/NtpClientWrap.h"
#include "broker.h"
#include "ws.h"

Ticker _ntp_defer;

Expand Down
5 changes: 4 additions & 1 deletion code/espurna/ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ OTA COMMON FUNCTIONS

#pragma once

#include "ws.h"
#include <Updater.h>

void otaPrintError() {
Expand Down Expand Up @@ -61,7 +62,9 @@ bool otaVerifyHeader(uint8_t* data, size_t len) {
void otaProgress(size_t bytes, size_t each = 8192u) {
// Removed to avoid websocket ping back during upgrade (see #1574)
// TODO: implement as separate from debugging message
if (wsConnected()) return;
#if WEB_SUPPORT
if (wsConnected()) return;
#endif

// Telnet and serial will still output things, but slightly throttled
static size_t last = 0;
Expand Down
1 change: 1 addition & 0 deletions code/espurna/ota_arduinoota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if OTA_ARDUINOOTA_SUPPORT

#include "system.h"
#include "ws.h"

// TODO: allocate ArduinoOTAClass on-demand, stop using global instance

Expand Down
1 change: 1 addition & 0 deletions code/espurna/relay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "relay.h"
#include "broker.h"
#include "tuya.h"
#include "ws.h"

#include "relay_config.h"

Expand Down
5 changes: 3 additions & 2 deletions code/espurna/rfbridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>

#if RF_SUPPORT

#include "relay.h"

#include <queue>

#if RFB_DIRECT
#include <RCSwitch.h>
#endif

#include "relay.h"
#include "ws.h"

// -----------------------------------------------------------------------------
// DEFINITIONS
// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions code/espurna/rfm69.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#if RFM69_SUPPORT

#include "libs/RFM69Wrap.h"
#include "ws.h"

#define RFM69_PACKET_SEPARATOR ':'

Expand Down
46 changes: 24 additions & 22 deletions code/espurna/rtcmem.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,41 @@ void _rtcmemInitCommands() {
_rtcmemInit();
});

terminalRegisterCommand(F("RTCMEM.DUMP"), [](Embedis* e) {
#if DEBUG_SUPPORT
terminalRegisterCommand(F("RTCMEM.DUMP"), [](Embedis* e) {

DEBUG_MSG_P(PSTR("[RTCMEM] boot_status=%u status=%u blocks_used=%u\n"),
_rtcmem_status, _rtcmemStatus(), RtcmemSize);
DEBUG_MSG_P(PSTR("[RTCMEM] boot_status=%u status=%u blocks_used=%u\n"),
_rtcmem_status, _rtcmemStatus(), RtcmemSize);

String line;
line.reserve(96);
char buffer[16] = {0};
String line;
line.reserve(96);
char buffer[16] = {0};

auto addr = reinterpret_cast<volatile uint32_t*>(RTCMEM_ADDR);
auto addr = reinterpret_cast<volatile uint32_t*>(RTCMEM_ADDR);

uint8_t block = 1;
uint8_t offset = 0;
uint8_t start = 0;
uint8_t block = 1;
uint8_t offset = 0;
uint8_t start = 0;

do {
do {

offset = block - 1;
offset = block - 1;

snprintf(buffer, sizeof(buffer), "%08x ", *(addr + offset));
line += buffer;
snprintf(buffer, sizeof(buffer), "%08x ", *(addr + offset));
line += buffer;

if ((block % 8) == 0) {
DEBUG_MSG_P(PSTR("%02u %p: %s\n"), start, addr+start, line.c_str());
start = block;
line = "";
}
if ((block % 8) == 0) {
DEBUG_MSG_P(PSTR("%02u %p: %s\n"), start, addr+start, line.c_str());
start = block;
line = "";
}

++block;
++block;

} while (block<(RTCMEM_BLOCKS+1));
} while (block<(RTCMEM_BLOCKS+1));

});
});
#endif
}

#endif
Expand Down
8 changes: 5 additions & 3 deletions code/espurna/sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>

#if SENSOR_SUPPORT

#include "relay.h"
#include "broker.h"

#include <vector>
#include "filters/LastFilter.h"
#include "filters/MaxFilter.h"
Expand All @@ -20,6 +17,11 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>

#include <float.h>

#include "relay.h"
#include "broker.h"
#include "ws.h"


struct sensor_magnitude_t {
BaseSensor * sensor; // Sensor object
BaseFilter * filter; // Filter object
Expand Down
6 changes: 4 additions & 2 deletions code/espurna/thermostat.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Copyright (C) 2017 by Dmitry Blinov <dblinov76 at gmail dot com>

#if THERMOSTAT_SUPPORT

#include "relay.h"

#include <ArduinoJson.h>
#include <float.h>

#include "relay.h"
#include "ws.h"


bool _thermostat_enabled = true;
bool _thermostat_mode_cooler = false;

Expand Down
2 changes: 2 additions & 0 deletions code/espurna/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>

#pragma once

#define INLINE inline __attribute__((always_inline))

extern "C" uint32_t _SPIFFS_start;
extern "C" uint32_t _SPIFFS_end;

Expand Down
2 changes: 2 additions & 0 deletions code/espurna/wifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <JustWifi.h>
#include <Ticker.h>

#include "ws.h"

bool _wifi_wps_running = false;
bool _wifi_smartconfig_running = false;
bool _wifi_smartconfig_initial = false;
Expand Down
67 changes: 67 additions & 0 deletions code/espurna/ws.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
WEBSOCKET MODULE
Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
*/

#pragma once

#include <ArduinoJson.h>

#include <queue>
#include <functional>
#include <vector>

#include "utils.h"

using ws_on_send_callback_f = std::function<void(JsonObject& root)>;
using ws_on_action_callback_f = std::function<void(uint32_t client_id, const char * action, JsonObject& data)>;
using ws_on_keycheck_callback_f = std::function<bool(const char * key, JsonVariant& value)>;

using ws_on_send_callback_list_t = std::vector<ws_on_send_callback_f>;
using ws_on_action_callback_list_t = std::vector<ws_on_action_callback_f>;
using ws_on_keycheck_callback_list_t = std::vector<ws_on_keycheck_callback_f>;

struct ws_callbacks_t {
ws_on_send_callback_list_t on_visible;
ws_on_send_callback_list_t on_connected;
ws_on_send_callback_list_t on_data;

ws_on_action_callback_list_t on_action;
ws_on_keycheck_callback_list_t on_keycheck;

ws_callbacks_t& onVisible(ws_on_send_callback_f);
ws_callbacks_t& onConnected(ws_on_send_callback_f);
ws_callbacks_t& onData(ws_on_send_callback_f);
ws_callbacks_t& onAction(ws_on_action_callback_f);
ws_callbacks_t& onKeyCheck(ws_on_keycheck_callback_f);
};

ws_callbacks_t& wsRegister();

void wsSetup();
void wsSend(uint32_t client_id, const char* data);
void wsSend(uint32_t client_id, JsonObject& root);
void wsSend(JsonObject& root);
void wsSend(ws_on_send_callback_f callback);

void wsSend_P(PGM_P data);
void wsSend_P(uint32_t client_id, PGM_P data);

void INLINE wsPost(const ws_on_send_callback_f& callback);
void INLINE wsPost(uint32_t client_id, const ws_on_send_callback_f& callback);
void INLINE wsPost(const ws_on_send_callback_list_t& callbacks);
void INLINE wsPost(uint32_t client_id, const ws_on_send_callback_list_t& callbacks);

void INLINE wsPostAll(uint32_t client_id, const ws_on_send_callback_list_t& callbacks);
void INLINE wsPostAll(const ws_on_send_callback_list_t& callbacks);

void INLINE wsPostSequence(uint32_t client_id, const ws_on_send_callback_list_t& callbacks);
void INLINE wsPostSequence(uint32_t client_id, ws_on_send_callback_list_t&& callbacks);
void INLINE wsPostSequence(const ws_on_send_callback_list_t& callbacks);

bool INLINE wsConnected();
bool INLINE wsConnected(uint32_t client_id);
bool wsDebugSend(const char* prefix, const char* message);
Loading

0 comments on commit 37763f1

Please sign in to comment.