T2/T3 USB tuner non-Terrestrial mode

Moderators: Gully, peteru

Post Reply
Grumpy_Geoff
Uber Wizard
Posts: 6490
Joined: Thu Mar 05, 2009 22:54
Location: Perth

T2/T3 USB tuner non-Terrestrial mode

Post by Grumpy_Geoff » Mon Jul 30, 2018 17:53

To permit broadcast TV reception, the USB tuner must be assigned either of two terrestrial modes; DVB-T or DVB-T2. The 'DVB' mode for the USB tuner is assigned within a few seconds of the GUI start time.
At times, the assigned mode may be neither of those two terrestrial modes, and instead one of the non-terrestrial modes of DVB-C, DVB-S, or DVB-S2 is chosen. These non-terrestrial modes mean the tuner is not suitable for broadcast TV reception.

You can see the assigned mode a number of ways -
  • GUI - Information>>Devices, or Setup>>Tuners>>Tuner configuration
  • OpenWebif - In the 'Tuners' section of the Box Info option which is located under Extras
  • File system
The system 'file' /proc/bus/nim_sockets has the tuner/NIM socket entries.
For a T2 the USB tuner is detailed in the "NIM Socket 2" entry, and for a T3 it is the "NIM Socket 3" entry. The other sockets are for the internal tuners.
My examples shown here are from a T2, as I don't have a T3.

Code: Select all

root@beyonwizt2:~# cat /proc/bus/nim_sockets
NIM Socket 0:
        Type: DVB-T2
        Name: DVB-T/T2 NIM
        Mode 0: DVB-T2
        Mode 2: DVB-C
        Frontend_Device: 0
        I2C_Device: 0
NIM Socket 1:
        Type: DVB-T
        Name: DVB-T NIM
        Frontend_Device: 1
        I2C_Device: 1
NIM Socket 2:
        Type: DVB-T
        Name: RTL2832U
        Frontend_Device: 2
        I2C_Device: 843863122
root@beyonwizt2:~#

The correct entry for the USB tuner should be DVB-T (single-type with no "Mode: " entries), represented in /proc/bus/nim_sockets as -

Code: Select all

NIM Socket 2:
	Type: DVB-T
	Name: RTL2832U
	Frontend_Device: 2
	I2C_Device: 843863122
The USB tuner may at times be reported as multi-type, with a number of switchable modes. This is not an issue _if_ at least one or both of the terrestrial modes (DVB-T or DVB-T2) is/are present, as the firmware prefers those two over the others.
Example 1 (multi-type, single-mode, effectively the same as above):

Code: Select all

NIM Socket 2:
	Type: DVB-T
	Name: RTL2832U
	Mode 3: DVB-T
	Frontend_Device: 2
	I2C_Device: 843863122
Example 2 (multi-type, multi-mode, in the below DVB-T will be preferred):

Code: Select all

NIM Socket 2:
	Type: DVB-T
	Name: RTL2832U
	Mode 3: DVB-T
	Mode 2: DVB-C
	Mode 4: DVB-S2
	Frontend_Device: 2
	I2C_Device: 843863122
Example 3 (multi-type, multi-mode, in the below DVB-T2 will be preferred):

Code: Select all

NIM Socket 2:
	Type: DVB-T
	Name: RTL2832U
	Mode 6: DVB-T2
	Mode 3: DVB-T
	Mode 5: DVB-C2
	Mode 2: DVB-C
	Mode 4: DVB-S2
	Frontend_Device: 2
	I2C_Device: 843863122
Non-terrestrial problem mode
Here's an example of when the USB tuner was assigned the non-terrestrial mode DVB-C, which meant it couldn't receive a broadcast signal.

Code: Select all

NIM Socket 2:
	Type: DVB-T
	Name: RTL2832U
	Mode 5: DVB-C2
	Mode 2: DVB-C
	Mode 4: DVB-S2
	Frontend_Device: 2
	I2C_Device: 843863122
I'm not sure if the non-terrestrial mode chosen is that of the lowest mode number, or the lowest name, or just a random selection.
Here's how the above was reported in OWIF for the USB tuner -

Code: Select all

			<e2name>Tuner C</e2name>
			<e2model>RTL2832U (DVB-C)</e2model>

... and the [NimManager] entries from the debug log -

Code: Select all

{627}<    46.130> [NimManager] slotname = Tuner A, slotdescription = DVB-T/T2 NIM, multitype = True
{627}<    46.131> [NimManager] slotname = Tuner B, slotdescription = DVB-T NIM, multitype = 0
{627}<    48.189> [NimManager][enumerateNIMs] slot: 0 - entry: {'multi_type': {'0': 'DVB-T2', '2': 'DVB-C'}, 'name': 'DVB-T/T2 NIM', 'frontend_device': 0, 'isempty': False, 'i2c': 0, 'type': 'DVB-T2'}
{627}<    48.191> [NimManager][enumerateNIMs] slot: 1 - entry: {'isempty': False, 'frontend_device': 1, 'i2c': 1, 'type': 'DVB-T', 'name': 'DVB-T NIM'}
{627}<    48.192> [NimManager][enumerateNIMs] slot: 2 - entry: {'multi_type': {'2': 'DVB-C', '5': 'DVB-C2', '4': 'DVB-S2'}, 'name': 'RTL2832U', 'frontend_device': 2, 'isempty': False, 'i2c': 843863122, 'type': 'DVB-T'}
{627}<    48.194> [NimManager] slotname = Tuner C, slotdescription = RTL2832U, multitype = True



If you observe a non-terrestrial mode for the USB tuner, then restart the UI. Likely the restart will get a terrestrial mode assigned, if not then rinse, repeat.

If a terrestrial mode has been selected for the USB tuner, and if you keep your T2/T3 in standby rather than shutting it down to deep standby when not in use, then you'll not have this non-terrestrial mode issue appear, until such time as you reboot or restart the UI and then the possibility exists and you must check the mode again.

If you want to keep your T2/T3 in deep standby when not in use, and assuming you're not wanting to risk USB tuner 'mode-itis' (i.e. a non-Terrestrial mode being assigned), then you'll need extra steps in the GUI startup process to monitor the USB tuner mode and take action. That's what I've done with our T2.
I'll post detail of that in the next post.


The U4 is _not_ affected by mode-itis.

Grumpy_Geoff
Uber Wizard
Posts: 6490
Joined: Thu Mar 05, 2009 22:54
Location: Perth

Re: T2/T3 USB tuner non-Terrestrial mode

Post by Grumpy_Geoff » Mon Jul 30, 2018 17:57

Before the "enigma2" binary is started for the GUI environment, the invoking shell script /usr/bin/enigma2.sh checks to see if there is a pre-start script named enigma2_pre_start.sh in the same directory and if it has the exectuable permission. If so, the pre-start script is called and enigma2.sh waits for enigma2_pre_start.sh to return, and then proceeds to fires up the GUI.

My workaround for the USB tuner 'mode-itis' issue is to have the pre-start script wait until OpenWebif has started, and then make a call to OWIF to work out what mode the USB tuner has been assigned. If a non-terrestrial mode has been assigned, then make another call to OWIF to restart the UI and the cycle is then repeated.

Below I'll list the pre-start script lines and attempt to describe what is going on.
The script has been built up over time and thus has some old code commented out, which obviously you won't need if you install this.
It's not pretty, but it works.

To install -
  1. You'll find the script without the line numbering in the attached file; open it using something that understands files with Unix-style line endings (on Windows: Wordpad, Notepad++, TextPad, UltraEdit, et. al.).
  2. Remove the ".txt" extension if you copy it to your T2/T3. Copy it to/as /usr/bin/enigma2_pre_start.sh or use the command line to edit the same file using nano or vi and paste in the contents.
  3. Make the file executable - chmod a+x /usr/bin/enigma2_pre_start.sh
  4. Create the /media/hdd/logs directory.
  5. Create the 'flag' file(s) in /home/root (refer points below)
If your T2/T3 is not networked, you should be able to achieve the above by using File Commander (the pre-start script execute permission required is "755"). The only issue I can anticipate is that you'll need to get in quick to rename/remove the 'test the restart' flag file if you've tested a restart.

The pre-start script will be removed if you perform a USB firmware update, so take a copy of it (e.g. into /media/hdd/Runnables).

If you don't understand any of this, then I suggest you think about giving this a miss.

  • Line 3 - send the output (concatenated) to a file named vtuner8.log in the /media/hdd/logs directory. You need to create the directory. Send the error output to file vtuner_errs.log
    The names for the log files were based on my logging of vtuner entries in the messages file. Obviously call them what you would like.
  • Line 5 - start a new sub-process thingamie that runs in the background. Thus, this pre-start script returns immediately and doesn't hold up the startup of the UI.
  • Lines 6-7 - these were just proving that the USB tuner entry is not present before the UI starts; it is populated very early on in the UI start process. You won't need them.
  • Line 9 - Give the UI some time to start up, before we go looking for info.
  • Line 17 - List the USB tuner entry from the system file. For a T3 you want to match on the fourth socket - "/NIM Socket 3:/"
  • Lines 19-34 - Wait for OpenWebif to start. The startup will be longer if you have shares offline.
  • Lines 35-42 - Get the device information from OWIF (it is some of the same stuff you see in OWIF's Box Info).
    Extract just the USB tuner entry and output it to a file. For a T3 you want to match on tuner D - "/<e2name>Tuner D<\/e2name>/" on line 39.
  • Line 43 - List the extracted USB tuner entry for the record.
  • Lines 48-71 - List the [NimManager] entries from the debug log if logging is enabled.
  • Lines 61-70 - This was the old way I awaited OWIF startup. It required the debug log, hence why I moved to the method in lines 19-34. You won't need them.
  • Lines 73-81 - This was the old way of looking through /proc/bus/nim_sockets to determine if a non-Terrestrial mode was selected. You won't need them, as I swapped to using what the UI states the tuner mode is.
  • Lines 82-90 - Detect if the USB tuner is in a non-Terrestrial mode. If so, set variable RC to value 99 (RC=99).
  • Lines 92-100 This is where the rubber hits the road, if we're permitted to restart (the presence of the 'flag' file "Allow_UI_Restart" in the home directory) -
    • Use OWIF to put a message up on the TV - "Bad USB tuner mode. Restarting GUI".
    • Wait 5 seconds.
    • Then use OWIF to issue a UI restart. We're then out of here - rinse, repeat as the UI is starting again.
  • Lines 105-113 If we've made it this far, then the tuner is in the correct terrestrial TV mode. Allow for a hook to test out the restart process - the presence of flag file "Force_UI_Restart" in the home directory. If found, restart and rinse repeat as above.
  • Line 116 - Put the PVR into standby. I think this has merit for a T2, as it doesn't have a smart front panel and so it can't tell the firmware that it started for a scheduled timer. This way the T2 won't stay timeshifting. Combined with a repeated 'Go to deep standby' Power Timer conditioned on already being in standby, the T2 will then return to deep standby after the specified time.
  • Line 118 - This is the end of the sub-process thingamie that started on line 5. The "&" makes the process run in the background, meaning the immediate return of the pre-start script and allowing the startup of the UI.
/usr/bin/enigma2_pre_start.sh contents -

Code: Select all

  1:  #!/bin/sh
  2:  
  3:  exec >> /media/hdd/logs/vtuner8.log 2>> /media/hdd/logs/vtuner_errs.log

  5:  (
  6:      (echo -e "\n\n=> $(date -Iseconds)"; cat /proc/bus/nim_sockets) >> /media/hdd/logs/nim_sockets_bootup_0secs.txt
  7:      (sleep 5; echo -e "\n\n=> $(date -Iseconds)"; cat /proc/bus/nim_sockets) >> /media/hdd/logs/nim_sockets_bootup_5secs.txt

  9:      sleep 55

 11:      echo -e "\n==> $(date -Iseconds)"

 13:      ##grep -i vtuner /var/log/messages

 15:      (echo -e "\n==> $(date -Iseconds)"; cat /proc/bus/nim_sockets) >> /media/hdd/logs/nim_sockets.txt

 17:      awk '/NIM Socket 2:/ {printIt=1}; printIt' /proc/bus/nim_sockets

 19:      # Wait for OWIF to start, then get USB tuner type from UI
 20:      (( i=0 ))
 21:      while true; do
 22:          if wget -q -O - http://localhost/web/currenttime | grep -q '<e2currenttime>'; then
 23:              if (( i > 0 )); then
 24:                 echo "$(date +'%T') - slept for ${i} seconds"
 25:              fi
 26:              break
 27:          else
 28:              if (( i == 0 )); then 
 29:                  echo $(date +'%T') - OWIF has yet to start, sleeping until then...
 30:              fi
 31:              sleep 5
 32:              (( i=i+5 ))
 33:          fi
 34:      done
 35:      wget -q -O - http://localhost/web/deviceinfo |
 36:          awk '{
 37:              if(printNext) { print $0; printNext = 0 }
 38:          }
 39:          /<e2name>Tuner C<\/e2name>/ {
 40:              print $0
 41:              printNext = 1
 42:          }' > /home/root/TunerInfo.txt
 43:      cat /home/root/TunerInfo.txt

 45:      # Check if USB tuner is attached
 46:      if [ -s /home/root/TunerInfo.txt ] ; then
    
 48:          # If debug logging currently enabled, list NIM entries
 49:          DbgPath=""
 50:          if grep -qi 'config.crash.enabledebug=true' /etc/enigma2/settings; then
 51:              DbgPath=$(grep debug_path /etc/enigma2/settings)
 52:              if [ -n "$DbgPath" ] ; then
 53:                  DbgPath=$(echo $DbgPath | sed -e 's/config.crash.debug_path=//')
 54:              else
 55:                  DbgPath=/home/root/logs/
 56:              fi
 57:              latestFile=$(ls -t ${DbgPath}Enigma2-*.log | head -n 1)
 58:              echo "==> Debug file: $latestFile"
 59:              grep '\[NimManager\]' $latestFile;
    
 61:              # Look for OWIF startup in log
 62:              #while true; do
 63:              #  OWIFstarted=$(grep '\[OpenWebif\] started on 80' $latestFile)
 64:              #  if [ -z "$OWIFstarted" ] ; then
 65:              #      echo Awaiting OWIF startup, sleeping
 66:              #      sleep 5
 67:              #  else
 68:              #      break
 69:              #  fi
 70:              #done
 71:          fi
    
 73:         ## Check if restart of UI is needed if non-Terrestrial USB tuner found
 74:         #awk '/NIM Socket 2:/ {USBtuner = 1}
 75:         #     USBtuner && /Mode [0-9]: DVB-/ {
 76:         #         if($0 !~ /DVB-T/) {
 77:         #             print "*** non-Terrestrial USB tuner type, restarting UI"; exit 99
 78:         #         }
 79:         #         exit
 80:         #     }' /proc/bus/nim_sockets
 81:         #RC=$?; echo -e "awk RC: $RC"
 82:         TunerType=$(cat /home/root/TunerInfo.txt) 
 83:         TunerType=${TunerType#* (}  # nuke tuner id & model/name prefix
 84:         TunerType=${TunerType%%)*}  # leave type; nuke the rest
 85:         echo ">>>(${TunerType})<<<"
 86:         RC=0
 87:         if [[ ! $TunerType =~ ^DVB-T.*$ ]]; then
 88:             echo "*** Non-Terrestrial USB tuner type (${TunerType}), restarting UI"
 89:             RC=99
 90:         fi
    
 92:         if [ $RC -eq 99 -a -f /home/root/Allow_UI_Restart ]; then
 93:             echo "*** about to restart"
 94:             wget -q -O - 'http://localhost/web/message?text=Bad%20USB%20tuner%20mode.%20%20Restarting%20GUI&type=3'
 95:             sleep 5
 96:             echo "issuing command:"
 97:             echo wget -q -O - http://localhost/web/powerstate?newstate=3
 98:             wget -q -O - 'http://localhost/web/powerstate?newstate=3'
 99:             echo "*** command issued"
100:         fi
101:      else
102:          echo "--- No USB tuner detected"
103:      fi  # end: check if USB tuner is attached

105:      if [ $RC -eq 0 -a -f /home/root/Force_UI_Restart ]; then
106:          echo "*** forcing a restart"
107:          wget -q -O - 'http://localhost/web/message?text=Pretending%20a%20bad%20USB%20tuner%20mode.%20%20Restarting%20GUI&type=3'
108:          sleep 5
109:          echo "issuing command:"
110:          echo wget -q -O - http://localhost/web/powerstate?newstate=3
111:          wget -q -O - 'http://localhost/web/powerstate?newstate=3'
112:          echo "*** command issued"
113:      fi

115:      # Go to standby state
116:      wget -q -O - 'http://localhost/web/powerstate?newstate=0'

118:   ) &
Attachments
enigma2_pre_start.sh.txt
(4.28 KiB) Downloaded 74 times

Grumpy_Geoff
Uber Wizard
Posts: 6490
Joined: Thu Mar 05, 2009 22:54
Location: Perth

Re: T2/T3 USB tuner non-Terrestrial mode

Post by Grumpy_Geoff » Sun Aug 12, 2018 20:33

If anybody is playing along at home, I've made a change to the script to cater for the MessageBox popup -
'Recording(s) are in progress or coming up soon, or you are saving timeshift!
Really restart now?
no
yes'

The code now does DOWN and OK actions to select the 'yes' option to allow the restart to occur.

The added code -

Code: Select all

# Allow for possibility of 'MessageBox' popup -
# "Recording(s) are in progress or coming up soon, or you are saving timeshift! Really restart now? no, yes" 
# DOWN to yes option
sleep 2
wget -q -O - 'http://localhost/web/remotecontrol?command=108'
# press OK
wget -q -O - 'http://localhost/web/remotecontrol?command=352'
Attachments
enigma2_pre_start.sh[#2].txt
(5.05 KiB) Downloaded 68 times
Pre-start_RC_presses.png
Pre-start_RC_presses.png (57.89 KiB) Viewed 1619 times

IanL-S
Master
Posts: 324
Joined: Mon Jun 27, 2016 15:11

Re: T2/T3 USB tuner non-Terrestrial mode

Post by IanL-S » Wed Jan 26, 2022 09:58

@Grumpy_Geoff, thanks for the detailed description of this problem. I have this happen from time to time with my T2s. When I get a chance I will try you solution. It seems to be far superior than attempting to do so from within the T2 settings which I find a bit hit and miss.

Ian
Enjoying an active retirement "playing" with my Toppys and now Beyonwiz.
T2, U4 and V2 controlled by IceTV
Various Toppys including TRF-2400, TRF-5300 and TF7100HDPVRt Plus
For help with your Toppy checkout the oztoppy forum and the oztoppy wiki.

Grumpy_Geoff
Uber Wizard
Posts: 6490
Joined: Thu Mar 05, 2009 22:54
Location: Perth

Re: T2/T3 USB tuner non-Terrestrial mode

Post by Grumpy_Geoff » Wed Jan 26, 2022 11:40

Hi Ian,

I've attached the latest version - it's essentially the same. It also includes the "framebuffer" check.
Attachments
enigma2_pre_start.sh[#3].txt
(4.92 KiB) Downloaded 42 times

IanL-S
Master
Posts: 324
Joined: Mon Jun 27, 2016 15:11

Re: T2/T3 USB tuner non-Terrestrial mode

Post by IanL-S » Wed Jan 26, 2022 14:45

Hi Geoff

Many thanks for the latest version.

Ian
Enjoying an active retirement "playing" with my Toppys and now Beyonwiz.
T2, U4 and V2 controlled by IceTV
Various Toppys including TRF-2400, TRF-5300 and TF7100HDPVRt Plus
For help with your Toppy checkout the oztoppy forum and the oztoppy wiki.

Post Reply

Return to “Hacks & Tricks”