我正在尝试通过BLE将LogBook数据获取到我的应用程序。 这对于JSON正常工作,数据似乎准确。 但是由于JSON编码,这需要一些时间。 获取SBEM数据的速度更快。但是我找不到有关编码的任何文档。我发现“内容”字符串是Base64编码的。 它以SBEM开头,这表示未压缩,如下所示:
但是我什么也找不到。
有人对此有进一步的信息还是发现编码是什么样的?
最好的问候 亚历克斯
答案 0 :(得分:0)
首先要澄清一点:当从 MDS / Logbook / 服务请求JSON日志时,数据本身将从SBEM格式的Movesense传感器传输,并在电话上进行转换。如果您有特定的示例,其中所说的转换很慢(可能很好),那么最好在movesense-mobile-lib中添加一个bitbucket问题。
关于SBEM格式。这是“ Suunto Oy内部”二进制格式,用于显示xml(和当今的json)文件。这意味着当格式演变时,它的解释可能会改变。除了警告,这是以下格式:
如果您想了解DataLogger / Logbook服务使用的SBEM格式,请参阅在构建过程中创建的“ generate / sbem-code”文件夹。
最后,这是解析SBEM格式的简单python代码:
from __future__ import print_function
import sys
import re
import glob, os
data_path = sys.argv[0]
descriptor_path = sys.argv[1]
ReservedSbemId_e_Escape = b"\255"
ReservedSbemId_e_Descriptor = 0
#print("data_path:",data_path)
print("descriptor_path:",descriptor_path)
# reads sbem ID upto uint16 from file
def readId(f):
byte1 = f.read(1)
id = None
if not byte1:
print("EOF found")
elif byte1 < ReservedSbemId_e_Escape:
id = int.from_bytes(byte1, byteorder='little')
#print("one byte id:", id)
else:
# read 2 following bytes
id_bytes = f.read(2)
id = int.from_bytes(id_bytes, byteorder='little')
#print("two byte id:",id)
return id
# reads sbem length upto uint32 from file
def readLen(f):
byte1 = f.read(1)
if byte1 < ReservedSbemId_e_Escape:
datasize = int.from_bytes(byte1, byteorder='little')
#print("one byte len:", len)
else:
# read 4 following bytes
id_bytes = f.read(4)
datasize = int.from_bytes(id_bytes, byteorder='little')
#print("4 byte len:",len)
return datasize
# read sbem chunkheader from file
def readChunkHeader(f):
id = readId(f)
if id is None:
return (None,None)
datasize = readLen(f)
ret = (id, datasize)
print("SBEM chunk header:", ret)
print(" offset:", f.tell())
return ret
def readHeader(f):
# read header
header_bytes = f.read(8)
print("SBEM Header: ", header_bytes)
def parseDescriptorChunk(data_bytes):
print("parseDescriptorChunk data:", chunk_bytes)
return
def parseDataChunk(data_bytes):
print("parseDataChunk data:", chunk_bytes)
return
# read descriptors
with open(descriptor_path, 'rb') as f_desc:
readHeader(f_desc)
while True:
(id, datasize) = readChunkHeader(f_desc)
if id is None:
# print("None id:",id)
break;
chunk_bytes = f_desc.read(datasize)
if (len(chunk_bytes) != datasize):
print("ERROR: too few bytes returned.")
break
if id == ReservedSbemId_e_Descriptor:
parseDescriptorChunk(chunk_bytes)
else:
print("WARNING: data chunk in descriptor file!")
parseDataChunk(chunk_bytes)
# read data
with open(data_path, 'rb') as f_data:
readHeader(f_data)
while True:
(id, datasize) = readChunkHeader(f_data)
if id is None:
# print("None id:",id)
break;
chunk_bytes = f_data.read(datasize)
if (len(chunk_bytes) != datasize):
print("ERROR: too few bytes returned.")
break
if id == ReservedSbemId_e_Descriptor:
parseDescriptorChunk(chunk_bytes)
else:
parseDataChunk(chunk_bytes)
完全免责声明:我为Movesense团队工作