From 80d5530cfc351a4c04086feb55c5ccd974a72931 Mon Sep 17 00:00:00 2001 From: Pecusx Date: Tue, 9 May 2017 20:26:26 +0200 Subject: [PATCH] Prevent to start streaming if the processor has only 1 core. --- radio4.py | 2 +- radio_class.py | 31 ++++++++++++++++++++++--------- version | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/radio4.py b/radio4.py index 5c69c35..56c9b0f 100755 --- a/radio4.py +++ b/radio4.py @@ -159,7 +159,7 @@ class MyDaemon(Daemon): mpd_version = radio.execMpcCommand("version") log.message(mpd_version, log.INFO) lcd.line3(mpd_version) - lcd.line4("GPIO version " + str(GPIO.VERSION)) + lcd.line4("GPIO: " + str(GPIO.VERSION) + " cores:"+str(radio.cores)) time.sleep(2.0) reload(lcd,radio) diff --git a/radio_class.py b/radio_class.py index 7cc2a9a..4dbc6df 100755 --- a/radio_class.py +++ b/radio_class.py @@ -116,6 +116,7 @@ class Radio: version = "0.0" boardrevision = 2 # Raspberry board version type + cores = 0 # number of processor cores udphost = 'localhost' # Remote IR listener UDP Host udpport = 5100 # Remote IR listener UDP port number mpdport = 6600 # MPD port number @@ -405,6 +406,7 @@ class Radio: config.display() # Get Configuration parameters /etc/radiod.conf self.boardrevision = self.getBoardRevision() + self.cores = self.getCores() self.mpdport = config.getMpdPort() self.udpport = config.getRemoteUdpPort() self.udphost = config.getRemoteListenHost() @@ -436,6 +438,7 @@ class Radio: log.message("radio.start current ID " + str(self.current_id), log.DEBUG) self.volume = self.getStoredVolume() self.setVolume(self.volume) + self.execCommand ("killall pianobar") # Necessary after restart problems # Alarm and timer settings self.timeTimer = int(time.time()) @@ -842,6 +845,12 @@ class Radio: log.message("Board revision " + str(self.boardrevision), log.INFO) return self.boardrevision + # Get number of processor cores from /proc/cpuinfo + def getCores(self): + cores_text = self.execCommand("cat /proc/cpuinfo | grep -c processor") + self.cores = int(cores_text) + return self.cores + # Get the MPD port number def getMpdPort(self): port = 6600 @@ -1400,13 +1409,17 @@ class Radio: # Switch on Icecast2 streaming def streamingOn(self): - output_id = 2 - self.streaming = True - self.execCommand("service icecast2 start") - self.execCommand("service darkice start") - self.execMpcCommand("enable " + str(output_id)) - self.storeStreaming("on") - self.streamingStatus() + if self.streamingAvailable(): + output_id = 2 + self.streaming = True + self.execCommand("service icecast2 start") + self.execCommand("service darkice start") + self.execMpcCommand("enable " + str(output_id)) + self.storeStreaming("on") + self.streamingStatus() + else: + self.streaming = False + self.storeStreaming("off") self.streammetadata = '' return self.streaming @@ -1430,10 +1443,10 @@ class Radio: log.message(status, log.INFO) return - # Check if icecast streaming installed + # Check if icecast streaming installed and pocessor has more than 1 core def streamingAvailable(self): fpath = "/usr/bin/icecast2" - return os.path.isfile(fpath) and os.access(fpath, os.X_OK) + return os.path.isfile(fpath) and os.access(fpath, os.X_OK) and (self.cores>1) # Store stram on or off in streaming file def storeStreaming(self,onoff): diff --git a/version b/version index 7c7630e..8ffef5b 100644 --- a/version +++ b/version @@ -1 +1 @@ -5.5e +5.5f