React native polidea-able编码发送包到base64

React native polidea-able编码发送包到base64,react-native,bluetooth,base64,bluetooth-lowenergy,React Native,Bluetooth,Base64,Bluetooth Lowenergy,我想通过发送命令到我的scooter,但我不知道如何编写包并将其编码到base64,我尝试了不同的方法,但似乎不起作用。以下是我需要如何制作软件包的文档: APP My understanding of the documentation you have included, is that to turn on the light the code to create the packet in base64 would be: import { Buffer } from "buf

我想通过发送命令到我的scooter,但我不知道如何编写包并将其编码到base64,我尝试了不同的方法,但似乎不起作用。以下是我需要如何制作软件包的文档:

APP My understanding of the documentation you have included, is that to turn on the light the code to create the packet in base64 would be:

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)


APP我对您包含的文档的理解是,要打开指示灯,在base64中创建数据包的代码将是:

从“Buffer”导入{Buffer};
var start_pack=0x55;
var操作码=0x06//灯
var action=0x01//On
var length=0x01//什么的长度?行动?
var校验和=开始包+操作码+操作+长度
var valueBytes=Buffer.alloc(5);
valueBytes[0]=启动\u块;
valueBytes[1]=操作码;
valueBytes[2]=长度;
valueBytes[3]=操作;
valueBytes[4]=校验和;
var valueBase64=valueBytes.toString('base64'))
log(“要写入的数据:+valueBase64”)
这给了我一个输出:

Data to write: VQYBAV0= 

我对您包含的文档的理解是,要打开指示灯,在base64中创建数据包的代码将是:

从“Buffer”导入{Buffer};
var start_pack=0x55;
var操作码=0x06//灯
var action=0x01//On
var length=0x01//什么的长度?行动?
var校验和=开始包+操作码+操作+长度
var valueBytes=Buffer.alloc(5);
valueBytes[0]=启动\u块;
valueBytes[1]=操作码;
valueBytes[2]=长度;
valueBytes[3]=操作;
valueBytes[4]=校验和;
var valueBase64=valueBytes.toString('base64'))
log(“要写入的数据:+valueBase64”)
这给了我一个输出:

Data to write: VQYBAV0= 

很好,它在工作,长度是包裹长度的5倍。非常感谢。很好,它在工作,长度是包裹长度的5倍。非常感谢。