简体   繁体   English

将 Wiimote MAC 地址从 C++ 转换为 PIN 到 Python 或 Javascript

[英]Convert Wiimote MAC Address to PIN from C++ to Python or Javascript

In have found the following snippet posted here: http://wiibrew.org/wiki/Wiimote#Bluetooth_Pairing在这里找到了以下片段: http : //wiibrew.org/wiki/Wiimote#Bluetooth_Pairing

There is also another code snippet to convert an Address to pin number here: https://www.richlynch.com/2009/11/18/permanently-pair-wiimotewii-balance-board/还有另一个代码片段可以将地址转换为密码: https : //www.richlynch.com/2009/11/18/permanently-pair-wiimotewii-balance-board/

What this is attempting to do is to convert the mac address of a nintendo wiimote into a pin number that is requested during bluetooth pairing.它试图做的是将 nintendo wiimote 的 mac 地址转换为蓝牙配对期间请求的 pin 号。

I am guessing that this is C or C++ but know nothing at all about C / C++, but I do know javascript and python.我猜这是 C 或 C++,但对 C/C++ 一无所知,但我知道 javascript 和 python。

I would like to convert this code into javascript or python so I can generate a valid STRING pin number that can be entered when prompted during bluetooth pairing, or even do it manually once I understand what exactly this code does.我想将此代码转换为 javascript 或 python,这样我就可以生成一个有效的STRING引脚编号,在蓝牙配对期间出现提示时可以输入该编号,或者甚至在我了解此代码的确切作用后手动输入。

This is the original snippit:这是原始片段:

Lets assume the Wiimote has the bluetooth address "00:1E:35:3B:7E:6D". If you want the PIN for bluetooth pairing in a simple string, do the following:

char pin[6];
pin[0] = 0x6D;
pin[1] = 0x7E;
pin[2] = 0x3B;
pin[3] = 0x35;
pin[4] = 0x1E;
pin[5] = 0x00;

Now "pin" contains your bluetooth pin that should be used for pairing your devices.

Another snippit using a function:另一个使用函数的片段:

_TCHAR * FormatBTAddress(BLUETOOTH_ADDRESS address)
{
   static _TCHAR ret[20];
   _stprintf(ret, _T("%02x:%02x:%02x:%02x:%02x:%02x"),
      address.rgBytes[5],
      address.rgBytes[4],
      address.rgBytes[3],
      address.rgBytes[2],
      address.rgBytes[1],
      address.rgBytes[0]
      );
   return ret;
}

Now although I know nothing about C++, I know that this is using some kind of (reversed) 6 byte array, and when I run this code using the MAC address in the sample on repl.it it does produce what appears to be a human readable 4 character string which could be entered as a bluetooth Pin:现在虽然我对 C++ 一无所知,但我知道这是使用某种(反向)6 字节数组,当我使用 repl.it 上示例中的 MAC 地址运行此代码时,它确实产生了看起来像人类的东西可以作为蓝牙 Pin 输入的可读 4 个字符串:

m~;5

However, when I replace the original mac address with my actual mac address, it generates unreadable characters and it seems to me that this code cannot actually work and there must be something omitted by the original poster on wiibrew.org.但是,当我用我的实际 mac 地址替换原始 mac 地址时,它会生成不可读的字符,在我看来,这段代码实际上无法工作,并且 wiibrew.org 上的原始海报必须省略某些内容。

This is using my actual MAC Address:这是使用我的实际 MAC 地址:

  char xpin[6];
  xpin[0] = 0x03;
  xpin[1] = 0xF4;
  xpin[2] = 0xB9;
  xpin[3] = 0x6E;
  xpin[4] = 0xAE;
  xpin[5] = 0xB8;
  printf(xpin);

And this is the result, which includes unprintable characters that definitely not could not be entered when prompted as a valid Bluetooth PIN number:这就是结果,其中包括在提示为有效蓝牙 PIN 码时绝对无法输入的不可打印字符:

��n�� @ 

Can anyone throw any light on this, as I cannot possibly see how the code provided could create a human readable string that can be used as a bluetooth pin number ??任何人都可以对此有所了解,因为我不可能看到所提供的代码如何创建可用作蓝牙引脚号的人类可读字符串?

Ultimately I would like to code this in Javascript or Python, but even being able to do this manually and generate valid strings from mac addresses would be helpful.最终,我想用 Javascript 或 Python 对此进行编码,但即使能够手动执行此操作并从 mac 地址生成有效字符串也会有所帮助。

Referring to https://wiibrew.org/wiki/Wiimote :参考https://wiibrew.org/wiki/Wiimote

The PIN-Code is the binary bluetooth address of the wiimote backwards. PIN 码是反向的 wiimote 的二进制蓝牙地址。

Below seems to be an updated version of what was said above (same source):以下似乎是上述内容的更新版本(同一来源):

If connecting by holding down the 1+2 buttons, the PIN is the bluetooth address of the wiimote backwards, if connecting by pressing the "sync" button on the back of the wiimote, then the PIN is the bluetooth address of the host backwards.如果长按1+2键连接,PIN反接为wiimote的蓝牙地址,如果按下wiimote背面的“同步”键连接,PIN反接为主机的蓝牙地址。

So both original C and your Python code is correct.所以原始 C 和你的 Python 代码都是正确的。 In fact, resulting string is not supposed to be readable at all (and always have 6 characters, printable or not).事实上,结果字符串根本不应该是可读的(并且总是有 6 个字符,可打印或不可打印)。 It's up to WiiMote driver to invert MAC string and send it back, as is everything described on that page.由 WiiMote 驱动程序来反转 MAC 字符串并将其发送回,就像该页面上描述的所有内容一样。 So if you are not writing WiiMote driver, find one for your system (on Linux it is already included as BlueZ plugin and should work out-of-box).因此,如果您不是在编写 WiiMote 驱动程序,请为您的系统找到一个(在 Linux 上,它已经作为 BlueZ 插件包含在内,应该可以开箱即用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM