0

我希望在自定义 Movesense 固件中使用 LogBook 获取记录的数据。接收 HTTP_CONTINUE 时,如何为下一次 GET 调用获取正确的字节流偏移量?

我正在尝试按照 DataStorage.md 中的描述实现这些步骤:

### /Logbook usage ###

To get recording from the Movesense sensors EEPROM storage, you need to:

1. Do **GET** on  */Logbook/Entries*. This returns a list of LogEntry objects. If the status was HTTP_OK, the list is complete. If the result code is HTTP_CONTINUE, you must GET again with the parameter StartAfterId set to the Id of the last entry you received and you'll get the next entries.

2. Choose the Log that you are interested in and notice the Id of it.

3. Fetch the descriptors with **GET** to */Logbook/byId/<Id>/Descriptors*. This returns a bytestream with the similar HTTP_CONTINUE handling as above. However you **must** keep re-requesting the **GET** until you get error or HTTP_OK, or the Logbook service will stay "in the middle of the stream" (we hope to remove this limitation in the future).

4. Fetch the data with **GET** to */Logbook/byId/<Id>/Data*. This returns also a bytestream (just like the */Logbook/Descriptors* above). 

5. Convert the data using the converter tools or classes. (To Be Continued...)

第 3 步和第 4 步的问题基本相同。我在 onGetResult 回调函数中收到一个 whiteboard::ByteStream 对象,但我不知道如何从中获取正确的偏移信息。

我发现了许多不同的方法,这些方法似乎涉及 ByteStream.h 中字节数的不同方面(长度、fullSize、已传输、payloadSize 和 serializationLength),但我就是无法让它正常工作。

基本上我想在 onGetResult 中做这样的事情:

if (resultCode == whiteboard::HTTP_CODE_CONTINUE) {
    const whiteboard::ByteStream &byteStream = rResultData.convertTo<const whiteboard::ByteStream &>();

    currentEntryOffset += byteStream.length();

    asyncGet(WB_RES::LOCAL::MEM_LOGBOOK_BYID_LOGID_DESCRIPTORS(), AsyncRequestOptions::Empty, currentEntryIdToFetch, currentEntryOffset);
    return;
}
4

1 回答 1

0

基本思想是再次进行相同的调用。所以如果你这样做:

asyncGet(WB_RES::LOCAL::MEM_LOGBOOK_BYID_LOGID_DESCRIPTORS(),AsyncRequestOptions::Empty, currentEntryIdToFetch);

并获得响应 HTTP_CONTINUE,执行:

asyncGet(WB_RES::LOCAL::MEM_LOGBOOK_BYID_LOGID_DESCRIPTORS(),AsyncRequestOptions::Empty, currentEntryIdToFetch);

直到您收到 HTTP_CONTINUE 或错误。

如果结果代码是 HTTP_CONTINUE,您必须再次 GET 并将参数 StartAfterId 设置为您收到的最后一个条目的 Id,然后您将获得下一个条目。

可能有点神秘,但对完全相同的资源执行另一个 asyncGet 直到您获得 HTTP_OK 或 http 错误代码。

另外,请注意您需要解码数据,可以在此答案中找到 python 脚本

于 2019-04-29T14:47:35.133 回答