0

这两个工具都在这里可用:https ://github.com/ninjablocks/433Utils/tree/master/RPi_utils

我真的想要一个简单的界面来管理我的 433mhz 设备。但我找不到一个好的。

所以我现在整天工作,试图为 RCSwitch 类制作 nodejs 的包装器。使用 2 个简单的方法 - 发送 [代码] - 接收 [回调 [代码]]

当我尝试创建 RCSwitch 类的新实例时出现此错误。

node: symbol lookup error:
/root/nodemodule/example/build/Release/kaku.node: 
undefined symbol: _ZN8RCSwitchC1Ev

它与 node-gyp 完美编译,但是当我执行 node 时它失败了。

现在我使用 exec 来执行带有代码的 sendCommand 。(丑陋我知道)

我试图让 RFSniffer 像这样工作:

  1. ./RFSniffer > rfsniffer.log
  2. .然后tail -f rfsniffer.log

但 RFSniffer 不会给我任何数据。

所以我的问题是任何人都可以帮助我让 RFsniffer 使用 tail -f 甚至更好的人可以帮助我修复 nodejs 的 c++ 插件:)

这是包装器代码:

#include "RCSwitch.h"
#include <node.h>
#include <v8.h>

using namespace v8;

Handle<Value> CodeSend(const Arguments& args) {
  HandleScope scope;

  int PIN = 0;
    RCSwitch mySwitch = RCSwitch();
    mySwitch.enableTransmit(PIN);

    mySwitch.send(args[0]->IntegerValue(), 24);

  return scope.Close(True());
}

Handle<Value> CodeRecieve(const Arguments& args) {
    HandleScope scope;
    // Entry check
    if (args.Length() != 2) {
        ThrowException(Exception::TypeError(String::New("Wrong number of arguments")));
        return scope.Close(Undefined());
    }

    Local<String> name= args[0]->ToString();
    Local<String> msg = name;
    Local<Function> cb = Local<Function>::Cast(args[1]);

    const unsigned argc = 1;
    Local<Value> argv[argc] = { Local<Value>::New(msg) };
    cb->Call(Context::GetCurrent()->Global(), argc, argv);

    return scope.Close(Undefined());
}

extern "C" {
  static void init(Handle<Object> target) {
    if( wiringPiSetup() == -1 ) {
        ThrowException( Exception::TypeError( String::New( "rcswitch: GPIO initialization failed" ) ) );
        return;
    }

    NODE_SET_METHOD(target, "Send", CodeSend);
    NODE_SET_METHOD(target, "Recieve", CodeRecieve);


  }
  NODE_MODULE(kaku, init);
}

节点代码:

var addon = require('./build/Release/kaku');

console.log(addon.Send(1234));

addon.Recieve(1234, function (val) {
    console.log(val);
});
4

1 回答 1

0

我和你有同样的问题,为什么./RFSniffer > rfsniffer.log不起作用的原因是 RFSniffer 代码中的 printf() 函数没有被刷新。

试试这个源代码:

/*
  RF_Sniffer

  Hacked from http://code.google.com/p/rc-switch/

  by @justy to provide a handy RF code sniffer
*/

#include "RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>

RCSwitch mySwitch;

int main(int argc, char *argv[]) {

     // This pin is not the first pin on the RPi GPIO header!
     // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/
     // for more information.
     int PIN = 2;

     if(wiringPiSetup() == -1)
       return 0;

     mySwitch = RCSwitch();
     mySwitch.enableReceive(PIN);  // Receiver on inerrupt 0 => that is pin #2

     while(1) {

      if (mySwitch.available()) {

        int value = mySwitch.getReceivedValue();

        if (value == 0) {
          printf("Unknown encoding");
        } else {
          printf("Received %i\n", mySwitch.getReceivedValue() );
        }

        fflush(stdout); // Add this line to flush the previous printf()
        mySwitch.resetAvailable();

      }

  }

  exit(0);

}

如果您使用 sudo 权限运行 RFSniffer 工具,您可以使用以下命令执行:

sudo ./RFSniffer | sudo tee rfsniffer.log

或者

sudo sh -c './RFSniffer >> rfsniffer.log'

于 2015-06-14T20:59:53.893 回答