Projet: Utiliser un orange pi avec interface TRX pour faire une balise avec les fonctions balise CW et répéteur.
Vous pouvez télécharger le script et les autres fichiers ICI.
1.Installation des paquets
1 2 3 4 5 |
apt-get install python-dev libttspico-utils sox qt4-qmake libx11-dev qt4-qmake cmake build-essential qt4-qmake cw python-configparser git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3 nano orangepi_PC_gpio_pyH3//pyA20/gpio/mapping.h |
ligne 88 ajouter:
{ « PA14 », SUNXI_GPA(14), 10 },
{ « PA15 », SUNXI_GPA(15), 19 },
1 2 |
cd orangepi_PC_gpio_pyH3 python setup.py install |
2.Mise en place du script principale:
mkdir /etc/balise
nano /etc/balise/ultimatebeacon.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
#!/usr/bin/python #-*- coding: utf-8 -*- import os, sys, time, subprocess, threading, commands from ConfigParser import SafeConfigParser scriptspath = os.path.dirname(sys.argv[0]) + "/" config = SafeConfigParser() config.read(scriptspath + 'config.ini') if not os.getegid() == 0: sys.exit('Script must be run as root') from pyA20.gpio import gpio from pyA20.gpio import connector from pyA20.gpio import port PTTSTAT = False #********Variables à adapter************** PTTPIN = port.PA14 COSPIN = port.PA15 alsadeviceinput = config.get('main', 'alsadeviceinput') alsadeviceoutput = config.get('main', 'alsadeviceoutput') TimeToPTT = config.getint('main', 'TimeToPTT') TimeToReleasePTT = config.getint('main', 'TimeToReleasePTT') BeaconInterval = config.getint('main', 'BeaconInterval') BeaconIntervalMin = config.getint('main', 'BeaconIntervalMin') parrotisAlive = config.getint('main', 'parrotisAlive') beaconisAlive = config.getint('main', 'beaconisAlive') #**************************************** #GPIO gpio.init() gpio.setcfg(PTTPIN, gpio.OUTPUT) gpio.setcfg(COSPIN, gpio.INPUT) gpio.pullup(COSPIN, gpio.PULLUP) def savparam(param,value): global config config.set('main', param, str(value)) def stop_if_already_running(): script_name = os.path.basename(__file__) pid = str(os.getpid()) l = commands.getstatusoutput("ps aux | grep -e "+script_name+" | grep -v grep | grep -v "+ pid +" | grep -v awk | awk '{print $2}'") if l[1]: sys.exit(0); def playwav(chemin): os.system("aplay "+chemin+" -q -N -D "+alsadeviceoutput) def PTT(status): CTTPTT = int(round(time.time() * 1000)) global PTTSTAT if status == True: while(PTTSTAT == True): time.sleep(1) PTTSTAT = True gpio.output(PTTPIN, 1) while ((CTTPTT + TimeToPTT) > int(round(time.time() * 1000))): time.sleep(0.1) return True else: CTTPTT = int(round(time.time() * 1000)) while ((CTTPTT + TimeToReleasePTT) > int(round(time.time() * 1000))): time.sleep(0.1) gpio.output(PTTPIN, 0) PTTSTAT = False return False def COS(): if gpio.input(COSPIN) == 1: return False else: return True def mes(N): print N PTT(True) try: playwav(scriptspath + N +".wav") except: pass PTT(False) def play_line_pico(text): os.system("pico2wave -l fr-FR -w /dev/shm/temp.wav '" + text + "';") os.system("sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /dev/shm/mess.wav") PTT(True) os.system("aplay -q -N -r 48000 -c 2 -D "+alsadeviceoutput+" /dev/shm/mess.wav") PTT(False) def action(mess): global parrot, beacon, BeaconInterval, BeaconIntervalMin, commande if mess.find("0") != -1: mes("som") if mess.find("1") != -1: if beacon.isAlive() == False: mes("baon") if len(commande) > 1 : if int(commande[1:]) >= BeaconIntervalMin: BeaconInterval = int(commande[1:]) else: BeaconInterval = BeaconIntervalMin play_line_pico("attention interval minimal fixé à : " + str(BeaconIntervalMin) + " secondes") play_line_pico("intervale: " + str(BeaconInterval) + " secondes") beacon = beaconClass() beacon.start() else: try: beacon.stop() mes("baoff") beacon = beaconClass() except: pass if mess.find("2") != -1: if parrot.isAlive() == False: mes("paon") parrot.start() else: try: parrot.stop() mes("paoff") parrot = parrotClass() except: pass if mess.find("3") != -1: mes("hello") if mess.find("9") != -1: mes("reboot") time.sleep(5) os.system("shutdown -r -f now") if mess.find("*") != -1: savparam("BeaconInterval",BeaconInterval) if parrot.isAlive() == True: savparam("parrotisAlive",1) else: savparam("parrotisAlive",0) if beacon.isAlive() == True: savparam("beaconisAlive",1) else: savparam("beaconisAlive",0) mes("savparam") with open(scriptspath + 'config.ini', 'w') as f: config.write(f) class parrotClass(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): global processparrot, commande while not self.event.is_set(): try: processparrot = subprocess.Popen("arecord -q -N -f S32_LE -r 48000 -c 2 -D " + alsadeviceinput + " -t raw | sox -t raw -r 48000 -b 16 -L -e signed -c 1 - -t raw - silence 1 0.1 3% 5 1.0 5% trim 0 60 highpass 300 lowpass 5000 | sox -t raw -r 48000 -b 32 -L -e signed -c 2 - /dev/shm/parrot.wav speed 0.48 gain -n -2 compand 0.1,0.1 -60,-60,-40,-10,-20,-8,-10,-6,-6,-5,-3,-3 -6", shell=True, stdout=subprocess.PIPE) processparrot.wait() if commande == "": PTT(True) processparrot = subprocess.Popen("aplay /dev/shm/parrot.wav -q -N -D "+alsadeviceoutput, shell=True, stdout=subprocess.PIPE) processparrot.wait() PTT(False) except: pass def stop(self): global processparrot processparrot.kill() os.system("ps -ef | grep /dev/shm/parrot.wav | grep -v grep | awk '{print $2}' | xargs kill -9") self.event.set() parrot = parrotClass() class beaconClass(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): while not self.event.is_set(): global BeaconInterval print BeaconInterval mes("cw") self.event.wait( BeaconInterval ) def stop(self): self.event.set() beacon = beaconClass() class getcommand(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.event = threading.Event() def run(self): global multimon_ng, commande multimon_ng = subprocess.Popen("(arecord -t raw -D "+alsadeviceinput+" -r 48000 -c 2 -f S32_LE | sox -t raw -e signed-integer -b32 -r 48000 -c 2 - -t raw -e signed-integer -b 16 -r 22050 - | multimon-ng -a DTMF -q -t raw -)", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) ready = False while(COS()==True): nextline = multimon_ng.stdout.readline() multimon_ng.poll() if nextline.__contains__("DTMF:"): nextline = nextline.split('DTMF: ')[1] if nextline.find("#") != -1: ready = True if nextline.find("#") == -1 and ready == True: commande += str(nextline.rstrip()) def stop(self): global multimon_ng multimon_ng.kill() os.system("ps -ef | grep multimon-ng | grep -v grep | awk '{print $2}' | xargs kill -9") self.event.set() if __name__ == '__main__': stop_if_already_running() try: global commande mes("start") if parrotisAlive == 1: commande = "2" action(commande[0]) time.sleep(1) if beaconisAlive == 1: commande = "1" + str(BeaconInterval) action(commande[0]) time.sleep(1) while(True): if COS()==True: commande = "" print "rx start" getC = getcommand() getC.start() while(COS()==True): time.sleep(0.5) getC.stop() print "rx stop" if len(commande) > 0 : print commande action(commande[0]) time.sleep(0.1) except KeyboardInterrupt: PTT(False) try: getC.stop() except: pass try: beacon.stop() except: pass try: parrot.stop() except: pass print ("Goodbye.") except: PTT(False) try: getC.stop() except: pass try: beacon.stop() except: pass try: parrot.stop() except: pass pass |
chmod 755 /etc/balise/ultimatebeacon.py
3.Mise en place des éléments secondaires
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
cd /tmp && wget https://github.com/Kerrick/cwwav/archive/master.tar.gz --output-document cwwav.tar.gz tar -zxvf cwwav.tar.gz && cd cwwav-master make apt-get install libsndfile-dev make make install mkdir /etc/balise cd /etc/balise pico2wave -l fr-FR -w /dev/shm/temp.wav "démarage de la balise" sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/start.wav pico2wave -l fr-FR -w /dev/shm/temp.wav "Sommaire 1 activer ou désactiver la balise 2 activer ou désactiver le peroquet" sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/som.wav pico2wave -l fr-FR -w /dev/shm/temp.wav "Mode balise activé" sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/baon.wav pico2wave -l fr-FR -w /dev/shm/temp.wav "Mode balise désactivé" sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/baoff.wav pico2wave -l fr-FR -w /dev/shm/temp.wav "Mode répéteur activé" sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/paon.wav pico2wave -l fr-FR -w /dev/shm/temp.wav "Mode répéteur désactivé" sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/paoff.wav pico2wave -l fr-FR -w /dev/shm/temp.wav "Redémarage en cours" root@orangepizero:~# sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/reboot.wav echo "QRA DE ET / ET DE QRA" | cwwav -f 700 -w 20 -o /dev/shm/temp.wav sox -t wav /dev/shm/temp.wav -esigned-integer -b32 -r 48000 -c 2 -t wav /etc/balise/cw.wav |
4.Lancement au démarage
nano /etc/balise/startU.sh
1 2 3 |
#!/bin/bash sleep 20 nice -n -15 /usr/bin/python /etc/balise/ultimatebeacon.py & |
nano /etc/rc.local
ajouter:
/etc/balise/startU.sh &
avant exit 0