我目前正在通过蓝牙(作为特征)向C程序发送一组无符号的8位整数.当收到这个数据包时,我想拿一对索引并"连接"它们的数字,如下所示:
Input: [0xDE, 0xAD,
0xDE, 0xAD,
0xBE, 0xEF]
Output: [0xDEAD, 0xDEAD, 0xBEEF]
Run Code Online (Sandbox Code Playgroud)
但是,我遇到了一个奇怪的问题.当我输出到一个偶数索引(取数组的前两个元素并将它们连接起来)时,我的代码工作正常,但是当我输出到奇数元素时失败(例如,尝试连接元素3和4(0xDE和0xAD) .
所以,我从程序中得到的输出是这样的:
Input: [0xDE, 0xAD,
0xDE, 0xAD,
0xBE, 0xEF]
Output: [0xDEAD, 0xADDE, 0xBEEF]
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
for(int i = 0; i < numUUID; i++)
{
// The i+1 and i+2 are because the first value of the array contains
// a byte on how many UUIDs are incoming
uuidFilter[i] = (incoming[i + 1] << 8) | incoming[i + 2];
}
Run Code Online (Sandbox Code Playgroud) 我已经尝试了另一个 StackOverflow 线程中的所有解决方案,但没有一个对我有用。此时我完全被难住了,不知道下一步该尝试什么。
我试图访问的数据是这样的:
我尝试使用的密钥是一个 URL,它位于帐户映射内。这是我正在运行的尝试删除密钥的代码:
var userRef = db.collection('userAccounts').doc(userEmail)
let dynamicKey = `accounts.${accountURL}`
console.log(dynamicKey)
userRef.set({
[dynamicKey]: firebase.firestore.FieldValue.delete()
}, { merge: true})
.then((result) => {
console.log(result)
})
.catch((error) => {
console.log(error)
})
Run Code Online (Sandbox Code Playgroud)
查看控制台,打印了accounts.www.stackoverflow.com:
所以,看起来路径应该匹配。需要注意的是,没有句点的 URL 工作得很好,所以看起来路径是正确的,而句点实际上是问题所在。
J Livengood 接受的答案根本不适用于名称中带有句点的键:
[`hello.${world}`]: firebase.firestore.FieldValue.delete()
Run Code Online (Sandbox Code Playgroud)
Sam Stern 发布的代码根本无法运行,并且我收到一条错误,指出更新仅采用一个参数。与上一张海报(ishandutta2007)相反,在 FieldPath 之前添加“new”并不能修复错误:
doc.update(
firebase.firestore.FieldPath("hello.world"),
firebase.firestore.FieldValue.delete());
Run Code Online (Sandbox Code Playgroud)
OP Sandeep Dinesh 发布的这段代码(在评论中)根本不起作用,即使在尝试使用不带句点的密钥进行删除时也是如此。我的代码如下,返回的 Promise 在代码的“then”部分未定义:
var userRef = db.collection('accounts').doc(userEmail)
let dynamicKey = `accounts.${accountURL}`
userRef.set({
[dynamicKey]: firebase.firestore.FieldValue.delete()
}, { merge: true})
.then((result) => {
console.log(result)
})
.catch((error) => { …Run Code Online (Sandbox Code Playgroud) 我目前正在从蓝牙设备读取变量。这显然需要不确定的时间,所以我使用期货(这个方法在下面的代码中是 readCharacteristic )。
一次不能进行多个读取操作——如果在第一个操作仍在进行时启动了第二个读取操作,Flutter 将抛出错误。
我的理解是,使用 .then() 将期货链接在一起只会允许在前一个调用完成时执行下一个语句。这个想法似乎是正确的,直到我尝试读取第三个值——也就是当错误被抛出时,因为重叠的读取事件。
这是我的代码:
readCharacteristic(scanDurationCharacteristic)
.then((list) => sensorScanDuration = list[0].toDouble())
.then((_) {
readCharacteristic(scanPeriodCharacteristic)
.then((list) => sensorScanPeriod = list[0].toDouble());
}).then((_) {
readCharacteristic(aggregateCharacteristic)
.then((list) => sensorAggregateCount = list[0].toDouble());
}).then((_) {
readCharacteristic(appEUICharacteristic)
.then((list) => appEUI = decimalToHexString(list));
}).then((_) {
readCharacteristic(devEUICharacteristic)
.then((list) => devEUI = decimalToHexString(list));
}).then((_) {
readCharacteristic(appKeyCharacteristic)
.then((list) => appKey = decimalToHexString(list));
});
Run Code Online (Sandbox Code Playgroud)
确保这些读取事件不会重叠的更好方法是什么?