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 (v1.1), supporting 2Mbps BLE
7#
8# Run for example as:
9#./convert_results_to_ellisysv2.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 '
21function rfchannel(freq) { return (freq-2)/2; }
22function rtrim(s)        { sub(/[ \t\r\n]+$/, "", s); return s; }
23
24BEGIN{
25FS=",";
26print("FileFormat:Bluetooth\n\
27                version=1.0\n\
28\n\
29ItemFormat:LE version=1.1")
30
31}
32{
33TI = $1 * 1000;
34RF_CHANNEL=rfchannel($3);
35AA=$4;
36Mod=$5;
37Packet=$10;
38RSSI=-40;
39if (Mod == 16){
40printf("Item time=%i aa=%s rssi=%i rfchannel=%i phy=1Mbps rawdata=\"%s\"\n",TI,AA,RSSI, RF_CHANNEL, rtrim(Packet));
41}
42if (Mod == 32 || Mod == 33){
43printf("Item time=%i aa=%s rssi=%i rfchannel=%i phy=2Mbps rawdata=\"%s\"\n",TI,AA,RSSI, RF_CHANNEL, rtrim(Packet));
44}
45}'
46
47#Examples of the importable format:
48#v1.0:
49#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"
50#v1.1:
51#Item time=15102072375 aa=0x1848870A rssi=-23 rfchannel=35 phy=1Mbps rawdata="09 00 38 A4 5B"
52#Item time=15351840875 aa=0x1848870A rssi=-37.5 rfchannel=3 phy=2Mbps rawdata="01 00 9E A9 5B"
53
54rm $TMP_FILE