diff --git a/kill.sh b/kill.sh index d4c29e7..e327b36 100755 --- a/kill.sh +++ b/kill.sh @@ -1,2 +1,2 @@ #!/bin/bash -killall ssh.sh \ No newline at end of file +sudo killall rpitx pifmrds diff --git a/main.py b/main.py index 5b6cfe0..d5718fc 100644 --- a/main.py +++ b/main.py @@ -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()) \ No newline at end of file + try: + asyncio.run(main("fmrds", 430)) + except KeyboardInterrupt: + print("\n") diff --git a/modulations/fmrds.sh b/modulations/fmrds.sh new file mode 100755 index 0000000..cb508f9 --- /dev/null +++ b/modulations/fmrds.sh @@ -0,0 +1,2 @@ +#!/bin/sh +arecord -q -c2 -t wav -f cd | sudo ./modulations/pifmrds -freq "$1" -audio - diff --git a/modulations/pifmrds b/modulations/pifmrds new file mode 100755 index 0000000..f89a01f Binary files /dev/null and b/modulations/pifmrds differ diff --git a/modulations/ssb.sh b/modulations/ssb.sh index 49f9c7c..6171890 100755 --- a/modulations/ssb.sh +++ b/modulations/ssb.sh @@ -1,37 +1,11 @@ -#!/bin/sh - -# 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 +#!/bin/bash +echo $1 +echo $2 +#arecord -q -c2 -t wav -f dat | sudo rpitx -f $1 -i- - -m $2 -s 48000 + +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 == "$(