Jump to content


Photo

current service change notification

python plugins

  • Please log in to reply
8 replies to this topic

#1 steavebba

  • Member
  • 16 posts

0
Neutral

Posted 24 July 2017 - 09:32

Hi all,

What is the proper way to get notified of the current service change without using a timer and pooling the information from the session.nav.getcurrentService() ?

 

 



Re: current service change notification #2 mrvica

  • Senior Member
  • 673 posts

+39
Good

Posted 24 July 2017 - 14:33

I don´t know how to do that in python, a simple shell script does the job too

#!/bin/sh
# service_changed
servicerefold=""
while sleep 1; do
      	servicerefnew=`/usr/bin/wget -O - -q http://127.0.0.1/web/getcurrent | /bin/grep -B 1 "\(<\|</\)e2servicename" | /bin/sed 's/<[^>]*>//g' | /bin/sed 's/^[ \t]*//' | /bin/sed '2d'`
        if [ "$servicerefnew" != "$servicerefold" ]; then
		# echo "service changed"
		/usr/bin/wget -q -O /dev/null "http://127.0.0.1/web/message?text=service%20changed%20!!&type=1&timeout=1"
        fi
        servicerefold="$servicerefnew"
done &



Re: current service change notification #3 littlesat

  • PLi® Core member
  • 48,315 posts

+508
Excellent

Posted 24 July 2017 - 14:56

This is so not done...

use the serviceEventTracker and e.g. use the iPlayableService.evStart from there and then get the current service from Navigation.

 

In InfoBarGenerics there are enough examples...


Edited by littlesat, 24 July 2017 - 14:56.

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: current service change notification #4 steavebba

  • Member
  • 16 posts

0
Neutral

Posted 24 July 2017 - 18:49

@mervica thank you for the answer, but pooling the state with python timer would be faster i think especially from a pluging context.

 

Thank you @littlsat, the serviceEventTracker used in the infobar dose not effectively help me it needs a screen and i want to watch for service change in the background.

 

i am using a timer to look for channel change every 1 second.

 

But i have not figured out how to get the service ID (sSID)..

    def update_service_info(self):
        service = session.nav.getCurrentService()
        info = service and service.info()
        data = info and info.getInfoObject(iServiceInformation.sTransponderData)
        sref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
        name = sref.getServiceName()
        print sref.toString()

        cur_orbpos = data.get("orbital_position", INVALID_POSITION)
        cur_freq = data.get("frequency", 0)
        service_id = self.getinfo(iServiceInformation.sSID)
        print  cur_orbpos,cur_freq,name, service_id


Re: current service change notification #5 steavebba

  • Member
  • 16 posts

0
Neutral

Posted 24 July 2017 - 19:43

        service = session.nav.getCurrentService()
        info = service and service.info()
        data = info and info.getInfoObject(iServiceInformation.sTransponderData)
        name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
        service_id = self.session.nav.getCurrentlyPlayingServiceReference().toString().split(':')[3] # geting service id from service reference string
        sat_pos = str(data.get("orbital_position", INVALID_POSITION))
        frequency = str(data.get("frequency", 0) / 1000)
        print  name,sat_pos,frequency, service_id

This is how i get the information now how i can avoid pooling this information continuously and  update it only on service change ?



Re: current service change notification #6 littlesat

  • PLi® Core member
  • 48,315 posts

+508
Excellent

Posted 25 July 2017 - 06:56

Then look further what that tracker is doing

WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: current service change notification #7 steavebba

  • Member
  • 16 posts

0
Neutral

Posted 25 July 2017 - 07:56

class   Someclass :
  event_callbacks =[]       


 self.session.nav.event.append(Someclass.service_event) # callback shoud be static method 
 Someclass.event_callbacks.append(self.update_service_info)

    @staticmethod
    def service_event(evt):
        if (evt == iPlayableService.evStart):
            print "channel changed....!", evt
            for func in Someclass.event_callbacks:
                print func
                func()

This is how to get notified when some navigation events occur.

Thank you @littlsat for the eventtracker hint.

 

 

 



Re: current service change notification #8 littlesat

  • PLi® Core member
  • 48,315 posts

+508
Excellent

Posted 25 July 2017 - 09:44

Sorry for not giving a direct answer... and just point to 'something'....


WaveFrontier 28.2E | 23.5E | 19.2E | 16E | 13E | 10/9E | 7E | 5E | 1W | 4/5W | 15W


Re: current service change notification #9 Cassie912

  • Member
  • 1 posts

0
Neutral

Posted 2 September 2017 - 09:31

This nice and useful info for me. Thanks guys







Also tagged with one or more of these keywords: python, plugins

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users