From 558861655fffd49667341824ca5fb473b78ae358 Mon Sep 17 00:00:00 2001 From: isra67 Date: Tue, 6 Jun 2017 15:16:42 +0200 Subject: [PATCH] play tone in background + monitoring network state --- audioini.sh | 2 +- diag.sh | 4 ++- indoor.ini | 4 +-- killme.sh | 12 +++++++ my_lib/constants.py | 1 + my_lib/constants.pyc | Bin 2746 -> 2791 bytes my_lib/tones.py | 9 ++--- my_lib/tones.pyc | Bin 1489 -> 1504 bytes netlink.py | 77 +++++++++++++++++++++++++++++++++++++++++++ pjindoor.py | 21 ++++++++---- setmicvolume.sh | 8 ++++- setvolume.sh | 8 ++++- share/indoor.sh | 32 ++++++++++-------- share/wdg.sh | 4 +-- sysinfo.sh | 2 +- tunnelgetport.sh | 4 +-- tunnelservice.sh | 4 +-- 17 files changed, 155 insertions(+), 37 deletions(-) create mode 100755 killme.sh create mode 100644 netlink.py diff --git a/audioini.sh b/audioini.sh index b526ba2..e848b12 100755 --- a/audioini.sh +++ b/audioini.sh @@ -7,4 +7,4 @@ # # ################################################################################# -python ./share/audioini.py +python ./share/audioini.py & diff --git a/diag.sh b/diag.sh index 46a6080..8d8b762 100755 --- a/diag.sh +++ b/diag.sh @@ -10,7 +10,9 @@ SERIAL=`/bin/cat /proc/cpuinfo | grep -i '^serial' | grep -Eo '[a-fA-F0-9]{16}$'` DAT=$(/bin/date "+%Y-%m-%d %H:%M:%S") CMMD=diag -if [ $# -eq 1 ] + +#if [ $# -eq 1 ] +if [ -n $1 ] then # zapis informacie do DB CMMD=$1 diff --git a/indoor.ini b/indoor.ini index 995c3e6..0a017d2 100644 --- a/indoor.ini +++ b/indoor.ini @@ -15,8 +15,8 @@ sip_authentication_name = [devices] ringtone = tone1.wav -volume = 50 -micvolume = 50 +volume = 80.0 +micvolume = 80.0 [gui] screen_mode = 4 diff --git a/killme.sh b/killme.sh new file mode 100755 index 0000000..f93ae33 --- /dev/null +++ b/killme.sh @@ -0,0 +1,12 @@ + +#! /bin/bash + +# ################################################################################# +# +# Indoor system script +# kill pjindoor.py app +# +# ################################################################################# + +pkill -9 omxplayer +ps aux | grep pjindoor | awk 'NR==1 {print $2}' | xargs kill -9 \ No newline at end of file diff --git a/my_lib/constants.py b/my_lib/constants.py index 3610646..9a27af5 100644 --- a/my_lib/constants.py +++ b/my_lib/constants.py @@ -36,6 +36,7 @@ SETVOLUME_SCRIPT = './setvolume.sh' SETMICVOLUME_SCRIPT = './setmicvolume.sh' SETIPADDRESS_SCRIPT = './setipaddress.sh' +HIDINIT_SCRIPT = './hid_init.sh' # ### images: ### MAKE_CALL_IMG = 'imgs/phone-call.png' diff --git a/my_lib/constants.pyc b/my_lib/constants.pyc index cb217d17e5258344098b1b3192d65f8ce61f5aeb..d62f7b8a447b5e23197a27dec51a4c97c865a9a8 100644 GIT binary patch delta 350 zcmY+9xlTe+5Qe`4N`ZmK5DGfkF5A6;hzl-gEF>m2niwZR3y0usjEUA#n%Eg0<#xV+ ziI3n5SXtSc=r`@wl{$kF~zOCDrr`+3Q3CW{Pq=2@N zBHBhu=rU4fR6sn`iZ=6%<4EOyExNUemXI1+M(U`CG|&p-qg5neWUU(6QQcO9tTbm7 zpGj6)Gg4rW+Gv1u&^of>xa;~Vnn2bZuRGpA8;lLoLw#h^SzE4eyMrCaea0ZWzkKX< z?C;^X4bMRIVHQm~WhFnj3iTqq4)3C`*kjD>MGy0bW+82@gTembXmAp}CT`;9e%ebG Iro-g$2Lt6uU;qFB delta 323 zcmY+9J5B>p3`NglNQ#kCMnOtPev`~EAqoFas41y1B@TfaN~Cm%f(B&)EMhu3w!sEi z02KuS^8`Xz_Vw|#8^2bcs`cQl65i$GlQVu|+4{ul>iMDmGS86)+DDq`0BNCXNSkQ` z>7Zs>t}+Xd=yz=Tv5U5l9@<7?w1XsQgrsN}$(Y)zM{OEgCDbJU=cMNJ&6)olWo8Y~ z3>l&^GV(n3x{j8S4bPjNx6p){L$=Wr+3~AguY3Mr-}3=8kjXb6M??Gi^3x)6M%N{i g;@wqTu@c-axx?bIbmWSU@|vf};H7)Z*e2kVHU!L24eDRa}sh zSu*(}lP?DgP@I8Pig~gJvk#-t^Gq+BDz$7@imc@>@gdJp1Nq#}NV_3lC sgDhICL3}`w$-h_}7{w=Bv&xAI1Gz!GAVLU4h=K@-$$6{^%>10306U;A761SM delta 191 zcmaFBeUY1;`7}gDz`V0&VB@7JB3=E7Vj0{;!3@MBZCCngx4Ff|O6N6YY zBT$Bgp=R<7CT#&$kZN`yQCyN=5bhW@IiE#g@=qpTE;gVT12a356w_osW*= 4: + rta_len, rta_type = struct.unpack("=HH", data[:4]) + + # This check comes from RTA_OK, and terminates a string of routing attributes + if rta_len < 4: break + + rta_data = data[4:rta_len] + + increment = (rta_len + 4 - 1) & ~(4 - 1) + data = data[increment:] + remaining -= increment + + if not (msg_type == RTM_NEWLINK or msg_type == RTM_NEWADDR): continue + + # Hoorah, a link is up! + if rta_type == IFLA_IFNAME: + t = "New link %s" % rta_data +# print "New link %s" % rta_data + send_command('echo %s' % t) + send_command('./killme.sh') + + # Hoorah, a link have an address! + if rta_type == IFLA_ADDRESS: +# print "New address %s" % rta_data + send_command('./killme.sh') diff --git a/pjindoor.py b/pjindoor.py index 2b5dfb7..0b2e293 100644 --- a/pjindoor.py +++ b/pjindoor.py @@ -85,7 +85,7 @@ def kill_subprocesses(): except: pass - send_command('pkill omxplayer') + send_command('pkill -9 omxplayer') # ############################################################### @@ -329,6 +329,7 @@ def __init__(self,winpos,servaddr,sipcall,streamaddr,relaycmd,rotation=0,aspectr self.playerPosition = [i for i in self.winPosition] self.rotation = (360 - rotation) % 360 self.aspectratio = aspectratio # 'letterbox | stretch | fill' + self.isPlaying = True delta = 2 self.playerPosition[0] += delta @@ -424,6 +425,7 @@ def initPlayer(self): interval = 19. + .2 * self.screenIndex if self.checkEvent > 0: Clock.unschedule(self.checkEvent) self.checkEvent = Clock.schedule_interval(self.checkLoop, interval) + self.isPlaying = True return subprocess.Popen(['omxplayer', '--live', '--no-osd', '--no-keys', '--display','0',\ '--alpha','0', '--layer', '1',\ @@ -441,11 +443,12 @@ def checkLoop(self, dt): sendNodeInfo('[***]VIDEO: %d OK' % self.screenIndex) - if (mainLayout.scrmngr.current in CAMERA_SCR and not mainLayout.popupSettings and not current_call) or\ - (current_call and active_display_index == self.screenIndex): - val = 255 - else: - val = 0 +# if (mainLayout.scrmngr.current in CAMERA_SCR and not mainLayout.popupSettings and not current_call) or\ +# (current_call and active_display_index == self.screenIndex): +# val = 255 +# else: +# val = 0 + val = 255 if self.isPlaying else 0 self.dbus_command(TRANSPARENCY_VIDEO_CMD + [str(val)]) @@ -1365,6 +1368,7 @@ def callback_btn_docall(self, btn=None): current_call = None self.outgoingCall = False self.setButtons(False) + docall_button_global.imgpath = DND_CALL_IMG if mainLayout.dnd_mode else MAKE_CALL_IMG else: target = self.displays[active_display_index].sipcall @@ -1682,6 +1686,7 @@ def showPlayers(self): for d in self.displays: d.dbus_command(TRANSPARENCY_VIDEO_CMD + [str(255)]) + d.isPlaying = True self.displays[active_display_index].resizePlayer() self.addInfoText() @@ -1695,6 +1700,7 @@ def hidePlayers(self, serial=False): for d in self.displays: d.dbus_command(TRANSPARENCY_VIDEO_CMD + [str(0)]) + d.isPlaying = False # ############################################################### @@ -1838,9 +1844,11 @@ def findTargetWindow(self, addr): active_display_index = idx self.addInfoText(d.sipcall) d.resizePlayer('90,10,710,390') + d.isPlaying = True ret = True else: d.dbus_command(TRANSPARENCY_VIDEO_CMD + [str(0)]) + d.isPlaying = False self.refreshLockIcons() self.add_sliders() @@ -1913,6 +1921,7 @@ def build(self): reset_usb_audio() time.sleep(2) + send_command(HIDINIT_SCRIPT) try: self.rotation = config.getint('gui', 'screen_orientation') diff --git a/setmicvolume.sh b/setmicvolume.sh index 0be306b..ff89c04 100755 --- a/setmicvolume.sh +++ b/setmicvolume.sh @@ -10,6 +10,12 @@ VOLUMEID=`amixer controls | grep "Mic Capture Volume" | sed -e 's/,/\n/g' | awk 'NR==1 {print $1}' | sed 's/numid=//'` AGCID=`amixer controls | grep "Auto Gain Control" | sed -e 's/,/\n/g' | awk 'NR==1 {print $1}' | sed 's/numid=//'` -amixer cset numid=$VOLUMEID $1% +VOL=50 +if [ -n $1 ]; then + VOL=$1 +fi + +#amixer cset numid=$VOLUMEID $1% +amixer cset numid=$VOLUMEID $VOL% amixer cset numid=$AGCID 0 alsactl store diff --git a/setvolume.sh b/setvolume.sh index 717b2b8..5b49f19 100755 --- a/setvolume.sh +++ b/setvolume.sh @@ -9,5 +9,11 @@ VOLUMEID=`amixer controls | grep "PCM Playback Volume" | sed -e 's/,/\n/g' | awk 'NR==1 {print $1}' | sed 's/numid=//'` -amixer cset numid=$VOLUMEID $1% +VOL=50 +if [ -n $1 ]; then + VOL=$1 +fi + +#amixer cset numid=$VOLUMEID $1% +amixer cset numid=$VOLUMEID $VOL% alsactl store diff --git a/share/indoor.sh b/share/indoor.sh index 36b365c..2e87c72 100755 --- a/share/indoor.sh +++ b/share/indoor.sh @@ -2,6 +2,8 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +WDG_FILE=/tmp/indoor_wd.dat + pustajNode() { while true do @@ -10,12 +12,12 @@ pustajNode() { ## Inoteska Evidence nodejs App /usr/local/bin/node server.js - sleep 3 + /bin/sleep 3 done } pustajDiag() { - sleep 60 + /bin/sleep 60 while true do @@ -23,9 +25,8 @@ pustajDiag() { cd /root/indoorpy ## Diag request 1x 20min -# ./diag.sh ./tunnelservice.sh diag - sleep 1200 + /bin/sleep 1200 done } @@ -37,12 +38,11 @@ pustaj() { ## Inoteska Evidence python App /usr/bin/python pjindoor.py -# /usr/bin/python test.py - sleep 3 + /bin/sleep 3 done } -sleep 1 +/bin/sleep 1 ## RPi 2 - set CPU performance: for cpucore in /sys/devices/system/cpu/cpu?; @@ -50,14 +50,22 @@ do [[ -f "$cpucore" ]] || echo "performance" | tee /sys/devices/system/cpu/cpu${cpucore:(-1)}/cpufreq/scaling_governor >/dev/null; done -sleep 1 +/bin/sleep 1 + +## start WD +#echo 01 > $WDG_FILE +cd /root/indoorpy/share +./wdg.sh & ## Audio setting: +#cd /root/indoorpy +#./hid_init.sh + +## IP monitor: cd /root/indoorpy -./hid_init.sh +/usr/bin/python netlink.py & ## start node server -#/usr/local/bin/node /root/app/server >& /dev/null & pustajNode >& /dev/null & ## start python app @@ -65,7 +73,3 @@ pustaj >& /dev/null & ## start diag pustajDiag >& /dev/null & - -## start WD -cd /root/indoorpy/share -./wdg.sh & diff --git a/share/wdg.sh b/share/wdg.sh index 246e04f..4878106 100755 --- a/share/wdg.sh +++ b/share/wdg.sh @@ -12,7 +12,7 @@ wdg_task() { if [ -f $TEST_FILE ] then new_val=`cat $TEST_FILE` - if [ "$new_val" == "" ] + if [ -z "$new_val" ] then #echo empty file old_val=1 @@ -22,7 +22,7 @@ wdg_task() { old_val=$new_val else #echo test ERR - > $TEST_FILE +# > $TEST_FILE old_val=1 # /usr/bin/pkill $PROCESS_NAME -9 echo "AUDIO ERROR $SUCCESS" > /tmp/test.xxx diff --git a/sysinfo.sh b/sysinfo.sh index aa53f15..693b707 100755 --- a/sysinfo.sh +++ b/sysinfo.sh @@ -18,7 +18,7 @@ NETWORK=`netstat -rn | grep eth0 | awk '{if($1!="0.0.0.0") print $1}'` DNS=`cat /etc/resolv.conf | grep nameserver | awk 'NR==1 {print $2}'` INET_TMP=`cat /etc/dhcpcd.conf | grep "interface eth0"` -if [ "$INET_TMP" = "" ]; then +if [ -z $INET_TMP ]; then INET='dhcp' else INET='static' diff --git a/tunnelgetport.sh b/tunnelgetport.sh index dfba78f..e4182b7 100755 --- a/tunnelgetport.sh +++ b/tunnelgetport.sh @@ -8,9 +8,9 @@ words=`echo $service | awk '{print NF}'` #echo $words -if [ "$words" == "7" ] +if [ "$words" = "7" ] then - if [ "$service" != "" ] + if [ -n $service ] then PORT=`echo $service | awk '{print $2}'` # echo $PORT diff --git a/tunnelservice.sh b/tunnelservice.sh index 268fce9..1e23267 100755 --- a/tunnelservice.sh +++ b/tunnelservice.sh @@ -10,7 +10,7 @@ SERIAL=`cat /proc/cpuinfo | grep Serial | awk -F \: '{print $2}'` CMMD=diag -if [ $# -eq 1 ] +if [ -n $1 ] then # zapis informacie do DB CMMD=$1 @@ -19,7 +19,7 @@ fi wget -T 30 -O $TMP_FILE -o /tmp/wgets "$URL?t=$DATEY%20$DATEH&i=$SERIAL&d=$CMMD" service=`cat $TMP_FILE` -if [ "$service" != "" ] +if [ -n $service ] then echo $service $DATEY $DATEH $SERIAL $CMMD >$TMP_FILE $FINAL_SCRIPT $TMP_FILE