Browse Source

mqtt: fixing types

pull/2552/head
Maxim Prokhorov 1 year ago
parent
commit
25be31251b
7 changed files with 26 additions and 22 deletions
  1. +1
    -1
      code/espurna/esp8266_pwm.c
  2. +1
    -1
      code/espurna/garland.cpp
  3. +4
    -1
      code/espurna/light.h
  4. +4
    -4
      code/espurna/rfbridge.cpp
  5. +4
    -3
      code/espurna/rfbridge.h
  6. +10
    -9
      code/espurna/rpnrules.cpp
  7. +2
    -3
      code/espurna/terminal.cpp

+ 1
- 1
code/espurna/esp8266_pwm.c View File

@ -70,7 +70,7 @@ struct pwm_phase {
* pwm phase
*/
typedef struct pwm_phase (pwm_phase_array)[PWM_MAX_CHANNELS + 2];
static pwm_phase_array pwm_phases[3] = {0};
static pwm_phase_array pwm_phases[3];
static struct {
struct pwm_phase* next_set;
struct pwm_phase* current_set;


+ 1
- 1
code/espurna/garland.cpp View File

@ -418,7 +418,7 @@ void garlandMqttCallback(unsigned int type, espurna::StringView topic, espurna::
auto t = mqttMagnitude(topic);
if (t.equals(MQTT_TOPIC_GARLAND)) {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(payload);
JsonObject& root = jsonBuffer.parseObject(payload.begin());
if (!root.success()) {
DEBUG_MSG_P(PSTR("[GARLAND] Error parsing mqtt data\n"));
return;


+ 4
- 1
code/espurna/light.h View File

@ -66,7 +66,10 @@ struct Hsv {
Hsv& operator=(const Hsv&) = default;
Hsv& operator=(Hsv&&) = default;
constexpr explicit Hsv(Array array) noexcept :
#if __cplusplus > 201103L
constexpr
#endif
explicit Hsv(Array array) noexcept :
_hue(array[0]),
_saturation(array[1]),
_value(array[2])


+ 4
- 4
code/espurna/rfbridge.cpp View File

@ -527,7 +527,7 @@ RfbRelayMatch _rfbMatch(espurna::StringView code) {
}
size_t id;
if (!tryParseId(id_view, relayCount, id)) {
if (!tryParseId(id_view, relayCount(), id)) {
return;
}
@ -612,7 +612,7 @@ void _rfbLearnStartFromPayload(espurna::StringView payload) {
std::copy(payload.begin(), it, relay);
size_t id;
if (!tryParseId(relay, relayCount, id)) {
if (!tryParseId(relay, relayCount(), id)) {
DEBUG_MSG_P(PSTR("[RF] Invalid relay ID (%u)\n"), id);
return;
}
@ -1195,7 +1195,7 @@ static void _rfbCommandLearn(::terminal::CommandContext&& ctx) {
}
size_t id;
if (!tryParseId(ctx.argv[1], relayCount, id)) {
if (!tryParseId(ctx.argv[1], relayCount(), id)) {
terminalError(ctx, F("Invalid relay ID"));
return;
}
@ -1212,7 +1212,7 @@ static void _rfbCommandForget(::terminal::CommandContext&& ctx) {
}
size_t id;
if (!tryParseId(ctx.argv[1], relayCount, id)) {
if (!tryParseId(ctx.argv[1], relayCount(), id)) {
terminalError(ctx, F("Invalid relay ID"));
return;
}


+ 4
- 3
code/espurna/rfbridge.h View File

@ -11,11 +11,12 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include <Arduino.h>
#include <cstdint>
using RfbCodeHandler = void(*)(unsigned char protocol, const char* code);
#include "types.h"
using RfbCodeHandler = void(*)(unsigned char protocol, espurna::StringView code);
void rfbOnCode(RfbCodeHandler);
void rfbSend(const char* code);
void rfbSend(const String& code);
void rfbSend(espurna::StringView code);
void rfbStatus(size_t id, bool status);
void rfbLearn(size_t id, bool status);


+ 10
- 9
code/espurna/rpnrules.cpp View File

@ -542,7 +542,7 @@ namespace operators {
namespace runners {
rpn_operator_error handle(rpn_context& ctxt, Runner::Policy policy, unsigned long time) {
for (auto& runner : ::rpnrules::internal::runners) {
for (auto& runner : internal::runners) {
if (runner.match(policy, time)) {
return static_cast<bool>(runner)
? rpn_operator_error::Ok
@ -550,7 +550,7 @@ rpn_operator_error handle(rpn_context& ctxt, Runner::Policy policy, unsigned lon
}
}
::rpnrules::internal::runners.emplace_front(policy, time);
internal::runners.emplace_front(policy, time);
return rpn_operator_error::CannotContinue;
}
@ -880,10 +880,11 @@ namespace internal {
using Codes = std::list<Code>;
Codes codes;
Codes::iterator find(Codes& container, unsigned char protocol, const String& match) {
return std::find_if(container.begin(), container.end(), [protocol, &match](const Code& code) {
return (code.protocol == protocol) && (code.raw == match);
});
Codes::iterator find(Codes& container, unsigned char protocol, StringView match) {
return std::find_if(container.begin(), container.end(),
[protocol, &match](const Code& code) {
return (code.protocol == protocol) && (code.raw == match);
});
}
uint32_t repeat_window { build::RepeatWindow };
@ -990,7 +991,7 @@ rpn_error matchAndWait(rpn_context& ctxt) {
}
// purge code to avoid matching again on the next rules run
if (rpn_operator_error::Ok == ::rpnrules::operators::runners::handle(ctxt, Runner::Policy::OneShot, time.toUint())) {
if (rpn_operator_error::Ok == operators::runners::handle(ctxt, Runner::Policy::OneShot, time.toUint())) {
internal::codes.erase(result);
return rpn_operator_error::Ok;
}
@ -1022,7 +1023,7 @@ rpn_error match(rpn_context& ctxt) {
return rpn_operator_error::CannotContinue;
}
void codeHandler(unsigned char protocol, const char* raw_code) {
void codeHandler(unsigned char protocol, StringView raw_code) {
// remove really old codes that we have not seen in a while to avoid memory exhaustion
auto ts = millis();
auto old = std::remove_if(internal::codes.begin(), internal::codes.end(), [ts](Code& code) {
@ -1042,7 +1043,7 @@ void codeHandler(unsigned char protocol, const char* raw_code) {
(*result).last = millis();
(*result).count += 1u;
} else {
internal::codes.push_back({protocol, raw_code, 1u, millis()});
internal::codes.push_back({protocol, raw_code.toString(), 1u, millis()});
}
schedule();


+ 2
- 3
code/espurna/terminal.cpp View File

@ -671,12 +671,11 @@ void setup() {
return false;
}
auto cmd = std::make_shared<String>(line.toString());
if (!line.endsWith("\r\n") && !line.endsWith("\n")) {
line += '\n';
(*cmd) += '\n';
}
auto cmd = std::make_shared<String>(std::move(line));
api.handle([&](AsyncWebServerRequest* request) {
AsyncWebPrint::scheduleFromRequest(request,
[cmd](Print& out) {


Loading…
Cancel
Save