суббота, 13 августа 2022 г.

ip multicast changeover. Second edition TsDuck

This script work in semi automatic mode. 
It will switch to second source if first dissapears. Also you can control this switch sending an udp message to port 4444 as you can read in documentation of tsduck. (echo -n "0" >/dev/udp/127.0.0.1/4444) or (echo -n "1" >/dev/udp/127.0.0.1/4444)

event-command - run some program and pass args to the. 
-------------------------------------
#/bin/sh

dir="$(basename $0 .sh)"

cdir=$PWD

ip=$(ip a | grep 10.7.130 | awk -F '\.|\/' '{print $4}') # this string define multicast network address 

mkdir pids

#Loop cycle
while true; do
sleep 0.5
echo $dir
exec tsswitch --infinite \
--debug=1 -v \
--receive-timeout 100 \
--fast-switch \
--remote 4444 \
--first-input 0 \
--max-input-packets 7 \
--max-output-packets 7 \
--buffer-packets 1316 \
--event-command "$cdir/./sendsnmp.sh" \
-I ip 239.0.11.$ip:51059 \
-I ip 239.0.0.22:51059 \
-O ip  239.4.4.$ip:1234 --local-address 10.7.130.$ip --ttl 1 & echo $! > "$cdir"/pids/"$dir"_pid;

m1=$!
while [ $m1 -gt 0 ]; do
sleep 1;
ps -p $! >/dev/null || m1=[0] ;
done
sed -i /^$!/d "$cdir"/pids/"$dir"_pid
sleep 1
done

convert colors to midi note for midi controllers

I recently (2 years ago) designed and built a simple MIDI controller for my intercom system using an Arduino Leonardo, USB hub, sound card, ...