On the A1 channel of the converter comes the voltage of the S-meter (after level adjustment by divider bridge). The following python script must be started continuously and informs the measurement file when the signal level changes. This file is a TCL file that will be used by the logic of the relay.

smeter.py

#!/usr/bin/python
#
# MCP3204/MCP3208 sample program for Raspberry Pi
#
# how to setup /dev/spidev?.?
# $ sudo modprobe spi_bcm2708
#
# how to setup spidev
# $ sudo apt-get install python-dev python-pip
# $ sudo pip install spidev
#
import spidev
import time
from collections import deque
 
class MCP3208:
        def __init__(self, spi_channel=0):
                self.spi_channel = spi_channel
                self.conn = spidev.SpiDev(0, spi_channel)
                self.conn.max_speed_hz = 1000000 # 1MHz
 
        def __del__( self ):
                self.close
 
        def close(self):
                if self.conn != None:
                        self.conn.close
                        self.conn = None
 
        def bitstring(self, n):
                s = bin(n)[2:]
                return '0'*(8-len(s)) + s
 
        def read(self, adc_channel=0):
                # build command
                cmd = 128 # start bit
                cmd += 64 # single end / diff
                if adc_channel % 2 == 1:
                        cmd += 8
                if (adc_channel/2) % 2 == 1:
                        cmd += 16
                if (adc_channel/4) % 2 == 1:
                        cmd += 32
 
                # send & receive data
                reply_bytes = self.conn.xfer2([cmd, 0, 0, 0])
 
                #
                reply_bitstring = ''.join(self.bitstring(n) for n in reply_bytes)
                # print reply_bitstring
 
                # see also... http://akizukidenshi.com/download/MCP3204.pdf (page.20)
                reply = reply_bitstring[5:19]
                return int(reply, 2)
 
if __name__ == '__main__':
                spi = MCP3208(0)
 
                count = 0
                nb=4  #number of aquiring signal
                t = 0.5 #time between two acquiring in seconds. Can be a float value. If nb=3 and t= 2, the qualified value will be given after 6 seconds of continuous signal over 'level'
                level=1730 #under this value, signal is not considered
                stack = deque([],maxlen=nb)
 
                sig=-1
                sig_old= -1
                #while count <= 11:
                while True:
 
                        val = spi.read(0)
                        time.sleep(t)
                        #print "val brute = "
                        #print val
                        #print " stack = "
                        #print stack
                        if val> level :    # software Squelch
                                stack.append(val)
 
                        else :  # Reset counting
                                stack = deque([],maxlen=nb)
                                sig = -1
 
 
 
                        if len(stack)==nb :
                                v=0
                                for i in range(0,nb) :
                                        v+= stack [i]
                                        i = i+1
                                meanv= (v/nb)
                                #print len(stack)
                                #print stack
 
                                #print "meanv = "
                                #print meanv
                                if ((meanv <= stack[0]*1.05) and (meanv >= stack[0]*0.95)) :
                                #prend en compte uniquement si signal stable pour les n echantillons
                                        meanv = stack[0]
                                else :meanv= 0
 
                                if 0 <= meanv < 800 : sig=-1
                                #elif 650 <= meanv < 1950 : sig=0
                                elif 800 <= meanv < 920 : sig=1
                                elif 920 <= meanv < 1117 : sig=2
                                elif 1117 <= meanv < 1336 : sig=3
                                elif 1336 <= meanv < 1616 : sig=4
                                elif 1616 <= meanv < 1987 : sig=5
                                elif 1987 <= meanv < 2365 : sig=6
                                elif 2365 <= meanv < 2702 : sig=7
                                elif 2702 <= meanv < 3035 : sig=8
                                elif 3035 <= meanv < 3370 : sig=9
                                elif meanv>=3370 : sig=24
                                else : sig=-1
 
 
                        #print "Signal = %d" % sig
                        if sig != sig_old :
                                print "Changement de niveau de signal =  %d" % sig
                                file = open("/tmp/smeter.tcl", "w")
                                file.write( "set signal " + str(sig) + ";")
                                file.close()
                                sig_old=sig

Now modify the function called send_rgr_sound in the /usr/share/svxlink/events.d/local/Logic.tcl file. We created 10 different sound files (S1 to S9, and S9 +).

proc send_rgr_sound {} {
  variable sql_rx_id;
  variable signal;
  #variable filename;
 
 
 
#lecture du signal
#   set output [exec python /etc/svxlink/smeter/smeter_1mes.py]
 
   if { [file exists /tmp/smeter.tcl]  } {
           source "/tmp/smeter.tcl"
           set son ""
                  if {$signal >=0} {
                        if {$signal>=10} {
                        set son "S9+" ; } else {
                        append son "S" $signal ;
                        }
                  playMsg "SVXCard/SMeter" $son;
                  }
           puts "Signal level on RX ID $sql_rx_id : $son";
        }
 
  playTone 440 200 100;
#CW::setPitch 600; # Sets the CW Tone to ~750 Hz
#CW::setAmplitude 100;
#CW::setCpm 125
#CW::play "k";
 
  playSilence 200;
 
  for {set i 0} {$i < $sql_rx_id} {incr i 1} {
    playTone 880 500 50;
    playSilence 50;
  }
  playSilence 100;
}