It uses the descriptor in [] array format.
EDIT: my attempt at the firmware is here: https://github.com/jsphuebner/stm32-sin ... arylogging
Code: Select all
[
{"name":"counter","size":8,"scale":1,"signed":false},
{"name":"angle","size":14,"scale":1,"signed":true},
{"name":"idc","size":14,"scale":1,"signed":true},
{"name":"il1","size":14,"scale":1,"signed":true},
{"name":"il2","size":14,"scale":1,"signed":true},
{"name":"pwm1","size":14,"scale":1,"signed":false},
{"name":"opmode","size":2,"scale":1,"signed":false},
{"name":"pwm2","size":14,"scale":1,"signed":false},
{"name":"desat","size":1,"scale":1,"signed":false},
{"name":"pwm3","size":14,"scale":1,"signed":false},
{"name":"iqref","size":14,"scale":1,"signed":true},
{"name":"idref","size":14,"scale":1,"signed":true},
{"name":"ifw","size":14,"scale":1,"signed":true},
{"name":"uq","size":16,"scale":1,"signed":true},
{"name":"ud","size":16,"scale":1,"signed":true},
{"name":"csum","size":8,"scale":1,"signed":false}
]
Code: Select all
import json, math
dataFile = open('dump.bin', "rb")
paramFile = open('params.json', 'wb')
outFile = open('data.csv', 'wb')
c = dataFile.read(1)
openBraces = (c == b'{') + 0
while openBraces > 0:
paramFile.write(c)
c = dataFile.read(1)
if c == b'{':
openBraces = openBraces + 1
elif c == b'}':
openBraces = openBraces - 1
paramFile.write(b'}')
paramFile.close()
while c != b'[':
c = dataFile.read(1)
openBrackets = 1
descriptorJson = c
while openBrackets > 0:
c = dataFile.read(1)
descriptorJson = descriptorJson + c
if c == b'[':
openBrackets = openBrackets + 1
elif c == b']':
openBrackets = openBrackets - 1
items = json.loads(descriptorJson)
dataFile.read(2) #skip \r\n
bitPos = 0
comma = ''
for item in items:
item['start'] = bitPos
item['mask'] = (1 << item['size']) - 1
bitPos = bitPos + item['size']
outFile.write((comma + item['name']).encode())
comma = ','
outFile.write(b'\n')
totalBits = sum([i['size'] for i in items])
recordSize = math.ceil(totalBits / 8)
record = dataFile.read(recordSize)
recordsRead = 1
def getBits(record, start, mask):
byteidx = start // 8
word = int(record[byteidx])
byteidx = byteidx + 1
if byteidx < len(record):
word = word + (int(record[byteidx]) << 8)
byteidx = byteidx + 1
if byteidx < len(record):
word = word + (int(record[byteidx]) << 16)
byteidx = byteidx + 1
if byteidx < len(record):
word = word + (int(record[byteidx]) << 24)
word = word >> (start % 8)
return word & mask
while len(record) == recordSize:
comma = ''
for item in items:
value = getBits(record, item['start'], item['mask'])
outFile.write((comma + str(value)).encode())
comma = ','
outFile.write(b'\n')
record = dataFile.read(recordSize)
recordsRead = recordsRead + 1
print(recordsRead)
print(len(record))