PTT is working now, added fmrds modulation

This commit is contained in:
PiFestim 2022-07-21 01:47:08 +01:00
parent dbf1900f56
commit d29f17b57b
6 changed files with 33 additions and 78 deletions

View File

@ -1,2 +1,2 @@
#!/bin/bash
killall ssh.sh
sudo killall rpitx pifmrds

67
main.py
View File

@ -5,7 +5,12 @@ import datetime
import asyncio
import os
PTT_IS_ON = 0
PTT_IS_ON = False
modulations = {
"ssb":"./modulations/ssb.sh",
"fmrds":"./modulations/fmrds.sh"
}
# init GPIO
pi = pigpio.pi()
@ -13,62 +18,36 @@ pi = pigpio.pi()
pi.set_mode(10, pigpio.INPUT)
async def run_command(*args):
"""Run command in subprocess.
Example from:
http://asyncio.readthedocs.io/en/latest/subprocess.html
"""
# Create subprocess
process = await asyncio.create_subprocess_exec(
*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
# Status
process = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
print("Started: %s, pid=%s" % (args, process.pid), flush=True)
# Wait for the subprocess to finish
stdout, stderr = asyncio.get_event_loop().create_task(process.communicate())
# Progress
if process.returncode == 0:
print(
"Done: %s, pid=%s, result: %s"
% (args, process.pid, stdout.decode().strip()),
flush=True,
)
else:
print(
"Failed: %s, pid=%s, result: %s"
% (args, process.pid, stderr.decode().strip()),
flush=True,
)
# Result
result = stdout.decode().strip()
asyncio.sleep(5)
# Return stdout
return result
async def button_press(gpio:int, level) -> bool:
global PTT_IS_ON
while True:
if(pi.read(gpio)!=0):
PTT_IS_ON = 1
PTT_IS_ON = True
if(pi.read(gpio)==0):
PTT_IS_ON = 0
PTT_IS_ON = False
await asyncio.sleep(.5)
async def main():
async def main(mod, freq:float):
asyncio.create_task(button_press(10, pigpio.EITHER_EDGE))
global PTT_IS_ON
task_created = False
print("Ready")
while True:
if PTT_IS_ON == 1:
while PTT_IS_ON == 1:
await run_command("./ssb.sh")
else:
await run_command("./kill.sh")
if (PTT_IS_ON and not task_created):
asyncio.create_task(run_command(modulations[mod], str(freq)))
task_created = True
elif (task_created and not PTT_IS_ON):
await asyncio.sleep(1)
asyncio.create_task(run_command("./kill.sh"))
task_created = False
await asyncio.sleep(.5)
if __name__ == "__main__":
asyncio.run(main())
try:
asyncio.run(main("fmrds", 430))
except KeyboardInterrupt:
print("\n")

2
modulations/fmrds.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
arecord -q -c2 -t wav -f cd | sudo ./modulations/pifmrds -freq "$1" -audio -

BIN
modulations/pifmrds Executable file

Binary file not shown.

View File

@ -1,37 +1,11 @@
#!/bin/sh
#!/bin/bash
echo $1
echo $2
#arecord -q -c2 -t wav -f dat | sudo rpitx -f $1 -i- - -m $2 -s 48000
# Pin logic
#selecting pin
GPIO=19
# "Prepare" it, whatever that means, I just copied it from SO
if [ ! -d /sys/class/gpio/gpio${GPIO} ]; then
echo "${GPIO}" > /sys/class/gpio/export
fi
echo "in" > /sys/class/gpio/gpio"${GPIO}"/direction
arecord -q -c2 -t wav -f dat | sudo rpitx -i - -m RF -f "$1" -s 48000
# old line
#(while true; do cat sampleaudio.wav; done)
# | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo sendiq -i /dev/stdin -s 96000 -f 430000000 -t float e6 -l
while true; do
if 1 == "$(</sys/class/gpio/gpio"${GPIO}"/value)" ]; then
arecord -q -f cd -r 44100 -c2 -D hw:0,7 -t raw | csdr convert_i16_f \ | csdr fir_interpolate_cc 2 | csdr dsb_fc \ | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff \ | sudo sendiq -i /dev/stdin -s 96000 -f "$1" -t float
# REMOVE THIS
else
echo "Not pressed"
# do arecord -l or arecord -L to find your audio card and change hw:0,7 to the corresponding value
# maybe i just need to extract this command and put it in a subprocess... 🤔
fi
sleep .5
done
# this should work
# screen will probably be operated using python, so all we need to do there is to killall ssb.sh, then run a new one with new freq async subproc
# usage: bash ssb.sh "freq"

BIN
test.wav Normal file

Binary file not shown.