polidea ble encode 发送包到base64

polidea ble encode send package to base64

我想通过 polidea ble 向我的滑板车发送命令,但我不知道如何打包并将其编码为 base64,我尝试了不同的方法,但似乎不起作用。这是我需要如何制作包的文档:

APP  Bluetooth
START_PACK, OPCODESEND, LENGTH, D0, CHECKSUM                  (START_PACK = 0x55)
OPCODESEND
0x02 – Speed Limit
    D0 – 1 is 6Km/k, 2 is 12Km/h, 3 is 20Km/h, 4 is 25Km/h, 5 No speed Limit
0x03 - Change Zero Start 
    D0  0 Zero Start OFF, 1 Zero Start ON
0x05 –Lock Unlock Scooter
    D0  0 Unlock, 1 Lock
0x06 – On/Off light from display
    D0  0 light OFF, 1 light ON

比如包裹应该怎么开灯?

我对您提供的文档的理解是,打开灯以 base64 格式创建数据包的代码是:

import { Buffer } from "buffer";

var start_pack = 0x55;
var opcode = 0x06 // light
var action = 0x01 // On
var length = 0x01 // Length of what? action?
var checksum = start_pack + opcode + action + length

var valueBytes = Buffer.alloc(5);
valueBytes[0] = start_pack;
valueBytes[1] = opcode;
valueBytes[2] = length;
valueBytes[3] = action;
valueBytes[4] = checksum;
var valueBase64 = valueBytes.toString('base64')
console.log("Data to write: " + valueBase64)

这给了我一个输出:

Data to write: VQYBAV0=