Project 2
Aim: To write a program that performs a binary search for any given signal. The instrument cluster is used as a source of CAN traffic.
- It should record a log, assisted by a user prompt, and replay all other subsequent logs according to a prompt that the user checks (Did the signal occur again? Y/N)
- After every iteration, the number of messages remaining in the kept log should be displayed.
- The desired outcome is not one particular signal, but rather an interactive program that the user can use to automate the binary search process
- This project will demand extensive use of Bash to manage files in the working directory, split files in half, use the CAN tools, etc.
First, we will add virtual can networks vcan0
Terminal 1:
$sudo ip link add dev vcan0 type vcan
$sudo ip link set vcan0 up
$sudo ip link

Bash program
$mousepad Project2.sh
#!/bin/bash
c="00"
a='2'
b='1'
# Logging data
candump vcan0 -L >"P2_BinarySearch".log
#copying original log file in another folder
cp P2_BinarySearch.log Split_Logs
#changing directory to store all log files which are split
cd Split_Logs
#renaming original log file as file_00
mv P2_BinarySearch.log file_$c.log
wc -l file_$c.log
read -p "Original Log File Word Count:" len
while [ $len -gt 0 ]
do
read -p "Enter word count number of file with signal present:" wc
#checking if wc is even number or odd
if [ `expr $wc % 2` == 0 ]
then
let w2=$wc/$a
else
let w1=$wc/$a
let w2=$w1+$b
fi
# Spliting into 2 txt files xaa xab
split -l $w2 file_$c.log
# renaming files and converting them to .log file
mv xaa xaa.log
mv xab xab.log
# Incrementing split counter
((c++))
echo "Split: "$c
# replaying xaa.log for checking whether the signal is present or not.
canplayer -I xaa.log
#User Prompt: Signal occurence input from User
echo "Did the signal occur? Y/N"
read s
# If s=='Y' then enter word count of xaa.log for further splitting.
if [ $s == 'Y' ]
then
# xaa.log File Word Count
wc -l xaa.log
#renaming file
mv xaa.log file_$c.log
#removing other file...no signal
rm xab.log
# If s=='N' then enter word count of xaa.log for further splitting.
else
wc -l xab.log
mv xab.log file_$c.log
rm xaa.log
fi
#Decreasing len= len/2
((len/=2))
done


Adding Instrument Cluster Simulator & its controls.
Terminal 1:
$cd ICSim
$./icsim vcan0
Terminal 2:
$cd ICSim
$./controls vcan0

In the new terminal, we are running our bash program named Project2.sh after moving to the respective directory
$./Project2.sh
We are recording all doors open signal in our log file P2_BinarySearch.log.
We are making a copy of this file and moving it to the new directory.
Also, the file name is changed from P2_BinarySearch.log to file_00.log [file_$c.log...here c is initially set to "00"].

Next, the word count of the file_00 [6982 here] is read and we need to provide the same for further operation.

Following that the split command will split the file_00.log into 2 files (namely xaa and xab) with an equal number of data (i.e.3491 which can be seen later when we word count xaa.log and xab.log). First, these text files are converted into log files. The first file i.e. xaa.log will be replayed via. canplayer to check for signal presence. If the signal is reflected in IC Simulator, we have to Type 'Y' otherwise 'N'.

Since all doors get opened when xaa.log is replayed via canplayer. Our signal is present in xaa.log.

This file will be renamed from xaa.log to file_1.log (here file_$c.log c represents split count, which gets incremented each time the log file is split). The new word count of data messages present in our file_1.log file can be seen as 3491.
Also at the same time, xab.log is removed to avoid any kind of confusion. [Also, reset the ICSimulator manually to the original i.e. all doors locked position]
Next, we need to enter a new word count for further splits i.e. 3491 here.

The second split occurs and splits the file_1.log into 2 files (namely xaa and xab) with approximately equal numbers of data (i.e.1746 & 1745 respectively which can be seen later when we word count xaa.log and xab.log). First, these text files are converted into log files. The first file i.e. xaa.log will be replayed via. canplayer to check for signal presence. If the signal is reflected in IC Simulator, we have to Type 'Y' otherwise 'N'.
We can also see all files getting created, renamed, and removed in terminal 2 in the respective Split_Logs directory.

Since all doors are still locked when xaa.log is replayed via canplayer. Our signal is not present in xaa.log. This concludes that our signal of all doors getting opened is present in the xab.log file. The file will be renamed from xab.log to file_2.log (here file_$c.log c represents split count, which gets incremented each time the log file is split). The new word count of the data message present in our file_2.log file can be seen as 1745.
Also at the same time, xaa.log is removed to avoid any kind of confusion.
Next, we need to enter a new word count for further splits i.e. 1745 here.

Similarly, we will go splitting the respective log file. From the 3rd split to the 5th split also, we didn't find our signal in the xaa.log file. That means during each split the signal was present in the xab.log file. The xab.log file will be renamed from xab.log to file_3.log, file_4.log, and file_5.log respectively and the xaa.log file is removed during each split iteration. (here file_$c.log c represents split count, which gets incremented each time the log file is split).
The new word count of data present in our log file also gets updated (i.e. 218, which means only 218 data messages remained in the file_5.log)
We can also see each file getting created, renamed, and removed in terminal 2 in the respective Split_Logs directory.
During the 6th split, the signal was present in the xaa.log file created after splitting file_5.log into 2 files(xaa and xab- each with 109 data messages in it) as all doors get opened when xaa.log is replayed via canplayer.

The xaa.file is renamed as file_6.log while the xab.log file is removed.
[Also, reset the ICSimulator manually to the original i.e. all doors locked position for next check.]

Similarly, we will go splitting the respective log file. During the 7th split and the 8th split, we didn't find our signal in the xaa.log file. That means during each split the signal was present in the xab.log file. The xab.log file will be renamed from xab.log to file_7.log, and file_8.log respectively and the xaa.log file is removed during each split iteration. (here file_$c.log c represents split count, which gets incremented each time the log file is split).
The new word count of data present in our log file also gets updated (i.e. 27, which means only 27 data messages remained in the file_8.log)
We can also see each file getting created, renamed, and removed in terminal 2 in the respective Split_Logs directory.
During the 9th split, the signal was present in the xaa.log file created after splitting file_8.log into 2 files(xaa and xab- with 14 and 15 data messages respectively in it) as all doors get opened when xaa.log is replayed via canplayer.

The xaa.file is renamed as file_9.log while the xab.log file is removed. [Also, reset the ICSimulator manually to the original i.e. all doors locked position for next check.]
Proceeding similarly for the 10th split, the signal was not present in xaa.log created after splitting file_10.log into 2 files (xaa and xab each with 7 data messages respectively). Thus xaa.log file is removed and xab.log file is renamed as file_10.log (containing only 7 data messages in it).
For the 11th split, the file_10.log is split into 2 files(xaa and xab - having 4 and 3 data messages respectively). When replayed xaa.log via canplayer, the signal was present in the xaa.log file. Thus, the xab.log file is removed and the xaa.log file is renamed as file_11.log (containing only 4 data messages in it). [Also, reset the ICSimulator manually to the original i.e. all doors locked position for next check.]

Moving ahead with the 12th split, the file_11.log is split into 2 files(xaa and xab - each with 2 data messages respectively). When replayed xaa.log via canplayer, the signal was present in the xaa.log file. Thus, the xab.log file is removed and the xaa.log file is renamed as file_12.log (containing only 2 data messages in it). [Also, reset the ICSimulator manually to the original i.e. all doors locked position for next check.]

For the 13th split, the file_12.log is split into 2 files(xaa and xab - each with 1 data message respectively). When replayed xaa.log via canplayer, the signal was present in the xaa.log file. Thus, the xab.log file is removed and the xaa.log file is renamed as file_13.log (containing only 1 data message which is our signal for all doors getting opened).
[Also, reset the ICSimulator manually to the original i.e. all doors locked position for next check.]

Thus the program automatically ends as there is no data message left for the further split.

We can check whether file_13.log has our respective signal, and we can replay the signal.
$canplayer -I file_13.log
All doors get opened, this verifies that file_13.log has our respective signal of opening all doors in one go.

The files created, renamed, and removed during each split are stored in the respective Split_logs directory. Here file_00.log is a copy of our original log file(P2_BinarySearch.log) from where the split started.

Also, the original file is also stored in the Projects directory separately with its original name defined at the time of can dump.
Result:
- The binary search is performed effectively on logged data via the bash program.
- The word count of each log file created after the split is also displayed.
- The split count is also displayed for ease.
- All the necessary files are attached.