1#! /usr/bin/env bash
2# Copyright 2018 Oticon A/S
3# SPDX-License-Identifier: Apache-2.0
4
5# Script to convert the babblesim 2G4 phy dumps into the format the ellisys can
6# import
7#
8# Run for example as:
9#./convert_results_to_ellisys.sh ../../results/Hola/d_*.Tx.csv > ~/c_drive/Users/alpi/LocalDocs/trial.bttrp
10
11Input_files="$@"
12TMP_FILE="tmp_file_to_merge_for_ellisys"
13
14echo -n "" > $TMP_FILE
15for file in $Input_files
16do
17  tail -n+2 $file >> $TMP_FILE
18done
19
20sort -g $TMP_FILE | awk '
21func rfchannel(freq) { return (freq-2)/2 }
22function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
23BEGIN{
24FS=",";
25print("FileFormat:Bluetooth\n\
26                version=1.0\n\
27\n\
28ItemFormat:LE version=1.0")
29
30}
31{
32TI = $1 * 1000;
33RF_CHANNEL=rfchannel($3);
34AA=$4;
35Mod=$5;
36Packet=$10;
37RSSI=-15;
38if (Mod == 16){
39printf("Item time=%.0f aa=%s rssi=%i rfchannel=%i rawdata=\"%s\"\n",TI,AA,RSSI, RF_CHANNEL, rtrim(Packet));
40}
41}'
42#Item time=522186250 aa=0x8E89BED6 rssi=-58 rfchannel=12 rawdata="40 1E 60 B6 6E 2D A3 4A 02 01 06 02 0A 00 11 06 92 15 37 84 E8 CC 2C 86 31 44 4A C7 BD F4 74 7D 9E CD 7E"
43
44rm $TMP_FILE
45