Commit e4547d0a authored by Reto Da Forno's avatar Reto Da Forno
Browse files

helper scripts added

parent 1ef0731b
#!/bin/bash
#
# embeds an exe/elf file into a the FlockLab XML config file
#
# 2020, rdaforno
#
#
# in order to use "drag&drop" to pass the image file and XML config to this script,
# you will need to create a *.desktop file with the following content:
# [Desktop Entry]
# Name=Embed FlockLab Image Wrapper
# Comment=Drop FlockLab XML config and target image file here
# Exec=[absolute_path_to_embed_image_script] %U
# Type=Application
#
SEDCMD=sed
B64CMD=base64
XMLFILE=flocklab.xml # default file name, if not provided via argument
# check if sed tool is installed
which $SEDCMD > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "command '$SEDCMD' not found"
exit 1
fi
# check if base64 tool is installed
which $B64CMD > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "command '$B64CMD' not found"
exit 1
fi
# at least one arguments are required (the target image)
if [ $# -lt 1 ]
then
echo "usage: $0 [image file (exe/elf)] ([input / output XML file])"
exit 1
fi
# if an additional argument is provided, check if it is an xml file
IMGFILE=$1
if [ $# -gt 1 ]
then
XMLFILE=$2
if [[ $1 == *.xml ]]
then
# swap the two files
XMLFILE=$1
IMGFILE=$2
fi
fi
# check file extension of image
if [[ ! $IMGFILE == *.exe ]] && [[ ! $IMGFILE == *.elf ]] && [[ ! $IMGFILE == *.hex ]] && [[ ! $IMGFILE == *.sky ]] && [[ ! $IMGFILE == *.out ]]
then
echo "invalid image file format"
exit 2
fi
# check if files exist
if [ ! -f $IMGFILE ]
then
echo "file $IMGFILE not found"
exit 3
fi
if [ ! -f $XMLFILE ]
then
echo "file $XMLFILE not found"
exit 4
fi
if [ ! -f $XMLFILE ]
then
echo "file $XMLFILE not found"
exit 5
fi
B64FILE="$IMGFILE.b64"
# convert to base 64
$B64CMD $IMGFILE > $B64FILE
# insert binary into xml (in-place)
$SEDCMD -i -n '1h;1!H;${ g;s/<data>.*<\/data>/<data>\n<\/data>/;p}' $XMLFILE
$SEDCMD -i "/<data>/r ${B64FILE}" $XMLFILE
# remove temporary file
rm $B64FILE
echo "image $IMGFILE embedded into $XMLFILE"
#!/usr/bin/env python3
# extracts a specified part of a GPIO tracing file for easier plotting with the FlockLab tools
import sys
import os
if len(sys.argv) < 4:
print("no enough arguments provided")
print("usage: %s [results_dir] [start_time] [end_time]" % (__file__))
sys.exit(1)
results_dir = sys.argv[1]
start_time = float(sys.argv[2])
end_time = float(sys.argv[3])
if not os.path.isdir(results_dir):
print("directory %s not found" % results_dir)
sys.exit(1)
if (start_time < 0) or (end_time <= start_time) or (end_time > 86400):
print("invalid start and/or end time")
sys.exit(1)
# check if output directory exists
outdir = results_dir.rstrip("/") + "_part"
if not os.path.isdir(outdir):
os.mkdir(outdir)
processed_lines = 0
output_lines = 0
output = []
with open("%s/gpiotracing.csv" % results_dir, 'r') as f_in:
lines = f_in.readlines()
teststart_time = 0
for line in lines:
(timestamp, obsid, node_id, pin, state) = line.split(",", 5)
if "timestamp" in timestamp: # first line?
output.append(line)
continue
if teststart_time == 0:
teststart_time = float(timestamp)
relative_time = float(timestamp) - teststart_time
if (relative_time >= start_time) and (relative_time <= end_time) or ("nRST" in pin):
output.append(line)
output_lines += 1
processed_lines += 1
if len(output) > 0:
with open("%s/gpiotracing.csv" % outdir, 'w') as f_out:
f_out.write("".join(output))
print("%d lines processed, %d lines written to %s" % (processed_lines, output_lines, outdir))
Supports Markdown
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