Add very simple plot tool and fix the recipe

parent f4d53e8e
'''ObsBox python plotter.
This script will acquire a page from Federico's obsbox-dump tool,
parse its output looking for turns and plot the data of each turn.
'''
__author__ = 'Miguel Ojeda'
__copyright__ = 'Copyright 2015, CERN BE'
__credits__ = ['Miguel Ojeda']
__license__ = 'Unknown'
__maintainer__ = 'Miguel Ojeda'
__email__ = 'mos@cern.ch'
import binascii
import logging
import optparse
import subprocess
import sys
import zlib
import matplotlib
import matplotlib.pyplot
turnDataWords = 3564
turnDataSize = turnDataWords * 2
turnHeaderWords = 8
turnHeaderSize = turnHeaderWords * 4
turnFooterWords = 1
turnFooterSize = turnFooterWords * 4
turnSize = turnDataSize + turnHeaderSize + turnFooterSize
def acquire(device, numberPages, pagesize, filename):
logging.info('Acquiring %s pages from device %s into %s with size %s...', numberPages, device, filename, pagesize)
command = 'sudo /user/fvaga/workspace/projects/obs-box/sources/obs-box-sw/tools/obsbox-dump -r -1 -p %s -n %s -s -d %s > %s' % (pagesize, numberPages, device, filename)
logging.info('Command = %s', command)
subprocess.check_call(command, shell = True)
def parseDump(filename, skipFirstPage):
data = ''
page = 0
with open(filename, 'rb') as fd:
for line in fd.readlines():
line = line.strip()
if line.startswith('Page number'):
page = page + 1
if skipFirstPage and page < 2:
continue
if not line.startswith('Data'):
continue
data += ''.join(line.split()[2:])
return binascii.unhexlify(data)
def linkToHost32(data):
return (ord(data[1]) << 24) | (ord(data[0]) << 16) | (ord(data[3]) << 8) | ord(data[2])
def linkToHost16(data):
return (ord(data[1]) << 8) | ord(data[0])
def parseTurn(turn, dump, wrongOnly):
header = turn[:turnHeaderSize]
data = turn[turnHeaderSize:-turnFooterSize]
footer = turn[-turnFooterSize:]
signature = header[0:4]
sourceID = linkToHost32(header[4:8])
dataSize = linkToHost32(header[8:12])
turnCounter = linkToHost32(header[12:16])
tagBits = linkToHost32(header[16:20])
reserved = header[20:24]
reserved = header[24:28]
reserved = header[28:32]
crc = linkToHost32(footer)
computedCRC = zlib.crc32(turn[:-turnFooterSize]) & 0xFFFFFFFF
print 'Turn %s' % hex(turnCounter)
print
print ' Source ID = %s' % hex(sourceID)
print ' Data Size = %s' % hex(dataSize)
print ' Tag Bits = %s' % hex(tagBits)
print ' Hardware CRC = %s' % hex(crc)
print ' Software CRC = %s' % hex(computedCRC)
print
print
if wrongOnly and crc == computedCRC:
return
numericData = []
word = ''
for byte in data:
word += byte
if len(word) == 2:
numericData.append(linkToHost16(word))
word = ''
if dump:
with open('dump.%s.txt' % hex(turnCounter), 'w') as fd:
word = ''
for byte in turn:
word += byte
if len(word) == 2:
fd.write('%s\n' % binascii.hexlify(word[1] + word[0]))
word = ''
matplotlib.pyplot.plot(numericData, 'r.', markersize=2)
matplotlib.pyplot.title('Turn %s' % hex(turnCounter))
matplotlib.pyplot.show()
def parseStream(data, dump, wrongOnly):
signature = '\x62\x4f\x31\x73'
position = 0
while True:
position = data.find(signature, position)
if position == -1:
break
turn = data[position:position + turnSize]
if len(turn) == turnSize:
parseTurn(turn, dump, wrongOnly)
position += len(signature)
def main():
'''Entry point.
'''
logging.basicConfig(
format = '[%(asctime)s] %(levelname)s: %(message)s',
level = logging.INFO,
)
parser = optparse.OptionParser()
parser.add_option('-a', '--acquire', action = 'store_true', help = 'Acquire a new page')
parser.add_option('-w', '--wrongOnly', action = 'store_true', help = 'Only dump/plot the turns whose CRC does not match (i.e. wrong ones)')
parser.add_option('-s', '--skipFirstPage', action = 'store_true', help = 'Skip the first page to avoid problems with old values in FIFO when using gateware without DDR')
parser.add_option('-d', '--device', default = '0x8100', help = 'Device ID (see dmesg for the list)')
parser.add_option('-n', '--numberPages', type = int, default = 1, help = 'Number of pages to check')
parser.add_option('-p', '--pagesize', type = int, default = 2 * 1024 * 1024, help = 'Size of the page (i.e. kmalloc size in the driver).')
parser.add_option('-D', '--dump', action = 'store_true', help = 'Dump each turn data into a file, one word per line in hexadecimal (requested by Javier)')
parser.add_option('-f', '--filename', default = 'page.txt', help = 'Name of the file where the page will be saved')
(options, args) = parser.parse_args()
if options.acquire:
acquire(options.device, options.numberPages, options.pagesize, options.filename)
parseStream(parseDump(options.filename, options.skipFirstPage), options.dump, options.wrongOnly)
if __name__ == '__main__':
main()
......@@ -10,7 +10,8 @@ PV = "0.1"
SRC_URI = "gitsm://github.com/FedericoVaga/obs-box-sw.git \
file://001-obsbox_tools.patch"
file://001-obsbox_tools.patch \
file://obsplot.py"
SRCREV = "2d49db5ca1397bc020de071116a0d5080f6f580c"
S = "${WORKDIR}/git"
......@@ -21,6 +22,9 @@ do_compile(){
make
}
FILES_${PN} += "${bindir}/* ${libdir}/*.so"
FILES_SOLIBSDEV = ""
do_install_extra() {
install -d ${D}${libdir}
install -m 0755 ${S}/spec-sw/tools/libspec.so ${D}${libdir}
......@@ -45,6 +49,7 @@ do_install_extra() {
install -m 0755 ${S}/zio/tools/zio-cat-file ${D}${bindir}
install -m 0755 ${S}/zio/tools/zio-dump ${D}${bindir}
install -m 0755 ${S}/tools/obsbox-dump ${D}${bindir}
install -m 0755 ${WORKDIR}/obsplot.py ${D}${bindir}
}
addtask install_extra after do_install before do_populate_sysroot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment