diff --git a/groundstation/fc_block_decode.py b/groundstation/fc_block_decode.py index 3d862902..7a411acc 100644 --- a/groundstation/fc_block_decode.py +++ b/groundstation/fc_block_decode.py @@ -12,7 +12,11 @@ logging.basicConfig(format='%(message)s') def fstr(template): - return eval(f"f'{template}'") + return eval(f"f'{template}'") + +def system_and_print(string): + print(string) + system(string) FC_EPS = 1 FC_BOB = 25 @@ -32,11 +36,11 @@ image_dir = "/home/pi/fctelem/" image = "image_file" ssdv = "/home/pi/ssdv/ssdv -d -J " -system("sudo rm " + image_dir + image) -#system("sudo rm " + html_dir + "*") -system("sudo rm " + html_dir + "/images/*") +system_and_print("sudo rm " + image_dir + image) +#system_and_print("sudo rm " + html_dir + "*") +system_and_print("sudo rm " + html_dir + "/images/*") -#system("cp /home/pi/CubeSatSim/sstv/sstv_image_1_320_x_256.jpg " + html_dir + "image_file.jpeg") +#system_and_print("cp /home/pi/CubeSatSim/sstv/sstv_image_1_320_x_256.jpg " + html_dir + "image_file.jpeg") head_string = '
All images
' @@ -117,7 +121,7 @@ if __name__ == "__main__": print('Payload {:x} {:x} \n'.format(data_block[FC_PAYLOAD + extended], data_block[FC_PAYLOAD + extended + 1])) if (data_block[FC_PAYLOAD + extended] == 0x55) and (data_block[FC_PAYLOAD + extended + 1] == 0x68): try: - print("Writing payload to file") + print("Writing this image payload block to file " + image + "_payload") immutable_payload = bytes(bytearray(data_block[(FC_PAYLOAD + extended):])) # payload) # print(immutable_payload) with open(image_dir + image + "_payload", "wb") as binary_file: @@ -125,8 +129,10 @@ if __name__ == "__main__": except: print("File error") # try: - system(ssdv + image_dir + image + "_payload " + + print("Processing payload with ssdv, saving image to " + image + "_paylad.jpeg and log to ssdv_output") + system_and_print(ssdv + image_dir + image + "_payload " + image_dir + image + "_payload.jpeg 2>&1 | sudo tee /home/pi/fctelem/ssdv_output") + print("Parsing ssdv_output") with open("/home/pi/fctelem/ssdv_output", "r") as file: for line in file: # print("line:") @@ -141,29 +147,25 @@ if __name__ == "__main__": print("End of image") if (image_id != 256): print("Saving complete image") - system("cp " + filename + " " + html_dir + "images/") - newfilename = image_dir + image + str(new_image_id) + ".jpeg" - # system(ssdv + image_dir + image + " " + filename) - system("mv " + filename + " " + newfilename) - system("mv " + image_dir + image + " " + image_dir + image + str(image_id)) - # system("cp " + filename + " " + html_dir + "images/" + image + str(image_id) + ".jpeg") + system_and_print("cp " + html_dir + "image_file.jpeg " + html_dir + "images/" + image + str(image_id) + "." + str(image_count) + ".jpeg") + system_and_print("sudo rm " + image_dir + image) else: - system("sudo rm " + image_dir + image) + system_and_print("sudo rm " + image_dir + image) print("New Image ID: ") print(new_image_id) image_id = new_image_id - # image_count = (image_count + 1) % 256 image_count = 1 else: image_count += 1 print("new image_count:") print(image_count) + print("Appending block to file " + image) with open(image_dir + image, "ab") as binary_file: binary_file.write(immutable_payload) - filename = image_dir + image + str(image_id) + "." + str(image_count) + ".jpeg" - system(ssdv + image_dir + image + " " + filename) - system("cp " + filename + " " + html_dir + "image_file.jpeg") + print("Running ssdv with all blocks in file " + image + " saving as " + html_dir + "image_file.jpeg") + system_and_print(ssdv + image_dir + image + " " + html_dir + "image_file.jpeg") telem_string = fstr(telem_string_format) + print("Writing index.html file") with open(html_dir + "index.html", "w") as html_file: html_file.write(head_string) html_file.write(telem_string) diff --git a/transmit.py b/transmit.py index 4507ccc9..e1c9336c 100644 --- a/transmit.py +++ b/transmit.py @@ -23,6 +23,14 @@ def battery_saver_check(): except: print("battery saver not activated") # txc = True + +def blink(times): + powerPin = 16 + for i in range(times): + GPIO.output(powerPin, 0) # blink two times + sleep(0.1) + GPIO.output(powerPin, 1) + sleep(0.1) def increment_mode(): print("increment mode") @@ -39,76 +47,26 @@ def increment_mode(): print(mode) if (mode == 'a'): mode = 'f' - GPIO.output(powerPin, 0) # blink two times - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) + blink(2) sleep(2.5) elif (mode == 'f'): mode = 'b' - GPIO.output(powerPin, 0) # blink three times - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) + blink(3) sleep(2.5) elif (mode == 'b'): mode = 's' - GPIO.output(powerPin, 0) # blink four times - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) + blink(4) sleep(2.5) elif (mode == 's'): mode = 'm' - GPIO.output(powerPin, 0) # blink five times - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1); - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) - sleep(0.1) - GPIO.output(powerPin, 0) - sleep(0.1) - GPIO.output(powerPin, 1) + blink(5) sleep(2.5) else: mode = 'a' - GPIO.output(powerPin, 0) # blink one time - sleep(0.1) - GPIO.output(powerPin, 1) + blink(1) sleep(2.5) try: @@ -815,7 +773,7 @@ if __name__ == "__main__": sleep(4.2) else: # FunCube mode image for i in range(4): - print("Checking image_file.bin") +# print("Checking image_file.bin") try: file = open("/home/pi/CubeSatSim/image_file.bin") file.close() @@ -839,7 +797,7 @@ if __name__ == "__main__": # else: sleep(0.6) elif (mode == 'e'): # code based on https://zr6aic.blogspot.com/2016/11/creating-2m-fm-repeater-with-raspberry.html - print("Repeater") + print("Cross Band Repeater") print("Stopping command and control") system("sudo systemctl stop command") print("turn on FM rx") @@ -847,11 +805,13 @@ if __name__ == "__main__": output(ptt, 1) GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi 4 GPIO.setup(txLed, GPIO.OUT) - GPIO.setup(powerPin, GPIO.OUT) +# GPIO.setup(powerPin, GPIO.OUT) GPIO.setup(squelch, GPIO.IN, pull_up_down=GPIO.PUD_UP) ## pull up in case pin is not connected - GPIO.output(powerPin, 0) +# GPIO.output(powerPin, 1) # was 0 + txf = float(tx) - 288.9 + print("Transmit frequency: ",txf) while True: - sleep(0.5) + sleep(1) if (GPIO.input(squelch) == False): print("Carrier detected, starting repeater") GPIO.setmode(GPIO.BCM) # added to make Tx LED work on Pi Zero 2 and Pi 4 @@ -859,12 +819,13 @@ if __name__ == "__main__": output(txLed, txLedOn) # system("arecord -D plughw:CARD=Device,DEV=0 | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") ## system("arecord -D plughw:CARD=Device,DEV=0 -f S16_LE -r 48000 -c 1 | csdr convert_s16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") - system("sudo nc -l 8011 | csdr convert_i16_f | csdr gain_ff 16000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") - sleep(1) - system("sudo arecord -D plughw:1 -r48000 -fS16_LE -c1 | nc localhost 8011 &") - GPIO.output(powerPin, 1) + system("sudo nc -l 8011 | csdr convert_i16_f | csdr gain_ff 16000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + str(txf) + "e3 &") sleep(0.5) - GPIO.output(powerPin, 0) +# system("sudo arecord -D plughw:1 -r48000 -fS16_LE -c1 | nc localhost 8011 &") + system("sudo arecord -D plughw:CARD=Device,DEV=0 -r48000 -fS16_LE -c1 | nc localhost 8011 &") +# GPIO.output(powerPin, 1) +# sleep(0.5) +# GPIO.output(powerPin, 0) while (GPIO.input(squelch) == False): sleep(1) print("No carrier detected, stopping repeater")