From 52a244db6e9fe4ad373b580ed4e504c0d84d6afd Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Thu, 28 Jan 2021 01:32:20 +0300 Subject: [PATCH] rfb: commands to send the code --- code/espurna/rfbridge.cpp | 17 +++++++++++++++++ code/espurna/rfbridge.h | 3 +++ code/espurna/rpnrules.cpp | 11 +++++++++++ 3 files changed, 31 insertions(+) diff --git a/code/espurna/rfbridge.cpp b/code/espurna/rfbridge.cpp index 52c23f84..48d08625 100644 --- a/code/espurna/rfbridge.cpp +++ b/code/espurna/rfbridge.cpp @@ -954,6 +954,14 @@ void _rfbSendFromPayload(const char * payload) { } +void rfbSend(const char* code) { + _rfbSendFromPayload(code); +} + +void rfbSend(const String& code) { + _rfbSendFromPayload(code.c_str()); +} + #if MQTT_SUPPORT void _rfbMqttCallback(unsigned int type, const char * topic, char * payload) { @@ -1067,6 +1075,15 @@ void _rfbApiSetup() { void _rfbInitCommands() { + terminalRegisterCommand(F("RFB.SEND"), [](const terminal::CommandContext& ctx) { + if (ctx.argc == 2) { + rfbSend(ctx.argv[1]); + return; + } + + terminalError(ctx, F("RFB.SEND ")); + }); + #if RELAY_SUPPORT terminalRegisterCommand(F("RFB.LEARN"), [](const terminal::CommandContext& ctx) { diff --git a/code/espurna/rfbridge.h b/code/espurna/rfbridge.h index e0304f6f..eac7a667 100644 --- a/code/espurna/rfbridge.h +++ b/code/espurna/rfbridge.h @@ -16,6 +16,9 @@ Copyright (C) 2016-2019 by Xose PĂ©rez BrokerDeclare(RfbridgeBroker, void(unsigned char protocol, const char* code)); +void rfbSend(const char* code); +void rfbSend(const String& code); + void rfbStatus(unsigned char id, bool status); void rfbLearn(unsigned char id, bool status); diff --git a/code/espurna/rpnrules.cpp b/code/espurna/rpnrules.cpp index 624c777d..29daf75c 100644 --- a/code/espurna/rpnrules.cpp +++ b/code/espurna/rpnrules.cpp @@ -404,6 +404,16 @@ decltype(_rfb_codes)::iterator _rpnRfbFindCode(unsigned char protocol, const Str }); } +rpn_error _rpnRfbSend(rpn_context& ctxt) { + auto code = rpn_stack_pop(ctxt); + if (!code.isString()) { + return rpn_operator_error::InvalidArgument; + } + + rfbSend(code.toString()); + return rpn_operator_error::Ok; +} + rpn_error _rpnRfbPop(rpn_context& ctxt) { auto code = rpn_stack_pop(ctxt); auto proto = rpn_stack_pop(ctxt); @@ -682,6 +692,7 @@ void _rpnInit() { #endif #if RFB_SUPPORT + rpn_operator_set(_rpn_ctxt, "rfb_send", 1, _rpnRfbSend); rpn_operator_set(_rpn_ctxt, "rfb_pop", 2, _rpnRfbPop); rpn_operator_set(_rpn_ctxt, "rfb_info", 2, _rpnRfbInfo); rpn_operator_set(_rpn_ctxt, "rfb_sequence", 4, _rpnRfbSequence);