Skip to content

Commit

Permalink
play tone in background + monitoring network state
Browse files Browse the repository at this point in the history
  • Loading branch information
isra67 committed Jun 6, 2017
1 parent c227ee5 commit 5588616
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 37 deletions.
2 changes: 1 addition & 1 deletion audioini.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
#
# #################################################################################

python ./share/audioini.py
python ./share/audioini.py &
4 changes: 3 additions & 1 deletion diag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions indoor.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions killme.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions my_lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Binary file modified my_lib/constants.pyc
Binary file not shown.
9 changes: 5 additions & 4 deletions my_lib/tones.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ def ringingTones():
def playTone(tone):
"start play"

stopWAV()
# stopWAV()

Logger.debug('%s: %s' %(whoami(), tone))
## send_command(PHONERING_PLAYER)
send_command(tone)
# subprocess.Popen(tone.split())
### send_command(PHONERING_PLAYER)
## send_command(tone)
subprocess.Popen(tone.split())
#Clock.schedule_once(lambda dt: subprocess.Popen(tone.split()), .5)
# Clock.schedule_once(lambda dt: send_command(tone))


# ##############################################################################
Expand Down
Binary file modified my_lib/tones.pyc
Binary file not shown.
77 changes: 77 additions & 0 deletions netlink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import os
import socket
import struct

from my_lib import *

# These constants map to constants in the Linux kernel. This is a crappy
# way to get at them, but it'll do for now.
RTMGRP_LINK = 1
RTMGRP_IPV4_IFADDR = 0x10

NLMSG_NOOP = 1
NLMSG_ERROR = 2

RTM_NEWLINK = 16
RTM_DELLINK = 17
RTM_NEWADDR = 20
RTM_DELADDR = 21

IFLA_ADDRESS = 1
IFLA_IFNAME = 3

# Create the netlink socket and bind to RTMGRP_LINK
s = socket.socket(socket.AF_NETLINK, socket.SOCK_RAW, socket.NETLINK_ROUTE)
#s.bind((os.getpid(), RTMGRP_LINK))
#s.bind((0, RTMGRP_LINK | RTMGRP_IPV4_IFADDR))
s.bind((0, -1))

while True:
data = s.recv(65535)
msg_len, msg_type, flags, seq, pid = struct.unpack("=LHHLL", data[:16])

if msg_type == NLMSG_NOOP:
# print "no-op"
continue
elif msg_type == NLMSG_ERROR:
# print "error"
break

# We fundamentally only care about NEWLINK messages in this version.
# if msg_type != RTM_NEWLINK:
if not (msg_type == RTM_NEWLINK or msg_type == RTM_DELLINK or msg_type == RTM_NEWADDR or msg_type == RTM_DELADDR):
continue

data = data[16:]

family, _, if_type, index, flags, change = struct.unpack("=BBHiII", data[:16])
# print family, if_type, index, flags, change

remaining = msg_len - 32
data = data[16:]

while remaining and len(data) >= 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')
21 changes: 15 additions & 6 deletions pjindoor.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def kill_subprocesses():
except:
pass

send_command('pkill omxplayer')
send_command('pkill -9 omxplayer')


# ###############################################################
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',\
Expand All @@ -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)])

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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


# ###############################################################
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 7 additions & 1 deletion setmicvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion setvolume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 18 additions & 14 deletions share/indoor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -10,22 +12,21 @@ 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
## working dir
cd /root/indoorpy

## Diag request 1x 20min
# ./diag.sh
./tunnelservice.sh diag
sleep 1200
/bin/sleep 1200
done
}

Expand All @@ -37,35 +38,38 @@ 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?;
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
pustaj >& /dev/null &

## start diag
pustajDiag >& /dev/null &

## start WD
cd /root/indoorpy/share
./wdg.sh &
4 changes: 2 additions & 2 deletions share/wdg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion sysinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions tunnelgetport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5588616

Please sign in to comment.