Browse Source

rfb: commands to send the code

mcspr-patch-1
Maxim Prokhorov 3 years ago
parent
commit
52a244db6e
3 changed files with 31 additions and 0 deletions
  1. +17
    -0
      code/espurna/rfbridge.cpp
  2. +3
    -0
      code/espurna/rfbridge.h
  3. +11
    -0
      code/espurna/rpnrules.cpp

+ 17
- 0
code/espurna/rfbridge.cpp View File

@ -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 #if MQTT_SUPPORT
void _rfbMqttCallback(unsigned int type, const char * topic, char * payload) { void _rfbMqttCallback(unsigned int type, const char * topic, char * payload) {
@ -1067,6 +1075,15 @@ void _rfbApiSetup() {
void _rfbInitCommands() { void _rfbInitCommands() {
terminalRegisterCommand(F("RFB.SEND"), [](const terminal::CommandContext& ctx) {
if (ctx.argc == 2) {
rfbSend(ctx.argv[1]);
return;
}
terminalError(ctx, F("RFB.SEND <CODE>"));
});
#if RELAY_SUPPORT #if RELAY_SUPPORT
terminalRegisterCommand(F("RFB.LEARN"), [](const terminal::CommandContext& ctx) { terminalRegisterCommand(F("RFB.LEARN"), [](const terminal::CommandContext& ctx) {


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

@ -16,6 +16,9 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
BrokerDeclare(RfbridgeBroker, void(unsigned char protocol, const char* code)); 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 rfbStatus(unsigned char id, bool status);
void rfbLearn(unsigned char id, bool status); void rfbLearn(unsigned char id, bool status);


+ 11
- 0
code/espurna/rpnrules.cpp View File

@ -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) { rpn_error _rpnRfbPop(rpn_context& ctxt) {
auto code = rpn_stack_pop(ctxt); auto code = rpn_stack_pop(ctxt);
auto proto = rpn_stack_pop(ctxt); auto proto = rpn_stack_pop(ctxt);
@ -682,6 +692,7 @@ void _rpnInit() {
#endif #endif
#if RFB_SUPPORT #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_pop", 2, _rpnRfbPop);
rpn_operator_set(_rpn_ctxt, "rfb_info", 2, _rpnRfbInfo); rpn_operator_set(_rpn_ctxt, "rfb_info", 2, _rpnRfbInfo);
rpn_operator_set(_rpn_ctxt, "rfb_sequence", 4, _rpnRfbSequence); rpn_operator_set(_rpn_ctxt, "rfb_sequence", 4, _rpnRfbSequence);


Loading…
Cancel
Save