diff --git a/main.c b/main.c index 2846dc73..9958c06f 100644 --- a/main.c +++ b/main.c @@ -1122,7 +1122,7 @@ void get_tlm(void) { char footer_str1[] = "\' > t.txt"; // char footer_str[] = "-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py char footer_str[] = " && echo 'AMSAT-11>APCSS:010101/hi hi ' >> t.txt && touch /home/pi/CubeSatSim/ready"; // transmit is done by rpitx.py - char footer_str2[] = " && touch /home/pi/CubeSatSim/ready"; + char footer_str2[] = " && touch /home/pi/CubeSatSim/ready"; if (ax5043) { strcpy(str, header_str); @@ -1161,7 +1161,12 @@ void get_tlm(void) { strcat(str, header_str2b); } else { // CW mode strcat(str, header_str4); - strcat(str, call); + strcat(str, call); + + sprintf(tlm_str, "%s' > cw0.txt", &str); + printf("CW string to execute: %s\n", &tlm_str); + FILE * cw_file = popen(tlm_str, "r"); + pclose(cw_file); } // } @@ -1169,18 +1174,23 @@ void get_tlm(void) { if (mode == CW) { int channel; for (channel = 1; channel < 7; channel++) { - sprintf(tlm_str, "%d%d%d %d%d%d %d%d%d %d%d%d ", + sprintf(tlm_str, "echo ' %d%d%d %d%d%d %d%d%d %d%d%d ' > cw%1d.txt", channel, upper_digit(tlm[channel][1]), lower_digit(tlm[channel][1]), channel, upper_digit(tlm[channel][2]), lower_digit(tlm[channel][2]), channel, upper_digit(tlm[channel][3]), lower_digit(tlm[channel][3]), - channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4])); + channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]), channel); // printf("%s",tlm_str); //#ifdef HAB // if (mode != AFSK) //#endif // if ((!hab_mode) || ((hab_mode) && (mode != AFSK))) - strcat(str, tlm_str); + strcat(str, tlm_str); + + printf("CW string to execute: %s\n", &tlm_str); + + FILE * cw_file = popen(tlm_str, "r"); + pclose(cw_file); } } else { // APRS @@ -1253,6 +1263,7 @@ void get_tlm(void) { // char cw_header2[] = "echo '"; // char cw_footer2[] = "' > id.txt && gen_packets -M 20 id.txt -o morse.wav -r 48000 > /dev/null 2>&1 && cat morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.897e3"; char cw_footer3[] = "' > cw.txt && touch /home/pi/CubeSatSim/cwready"; // transmit is done by rpitx.py + char cwready[] = "touch /home/pi/CubeSatSim/cwready"; // cw frame is complete. transmit is done by rpitx.py // printf("Str str: %s \n", str); // fflush(stdout); @@ -1263,7 +1274,10 @@ void get_tlm(void) { fflush(stdout); FILE * cw_file = popen(str, "r"); - pclose(cw_file); + pclose(cw_file); + +// FILE * cw_file = popen(cwready, "r"); +// pclose(cw_file); while ((cw_file = fopen("/home/pi/CubeSatSim/cwready", "r")) != NULL) { // wait for rpitx to be done fclose(cw_file); diff --git a/rpitx.py b/rpitx.py index 7bd6ba95..b46c4e46 100644 --- a/rpitx.py +++ b/rpitx.py @@ -372,7 +372,6 @@ if __name__ == "__main__": print("Programming FM module!\n"); output(pd, 1) output (ptt, 1) - try: ser = serial.Serial("/dev/ttyAMA0", 9600) print(ser.portstr) @@ -384,15 +383,17 @@ if __name__ == "__main__": except: print("Error in serial write") ser.close() - output(pd, 0) sleep(10) # delay so cubesatsim code catches up - system("echo 'hi hi de " + callsign + "' > id.txt && gen_packets -M 20 /home/pi/CubeSatSim/id.txt -o /home/pi/CubeSatSim/morse.wav -r 48000 > /dev/null 2>&1") + system("echo 'hi hi de " + callsign + "' > id.txt && gen_packets -M 20 /home/pi/CubeSatSim/id.txt -o /home/pi/CubeSatSim/morse.wav -r 48000 > /dev/null 2>&1") + + command_control_check() # if (mode != 'a') and (command_tx == True): - if (command_tx == True): +# if (command_tx == True): + if (mode != 'm'): # battery_saver_mode output(txLed, txLedOn) # if (txc): @@ -425,14 +426,9 @@ if __name__ == "__main__": # if (len(sys.argv)) > 1: # print("There are arguments!") if (mode == 'a'): + command_control_check() # output(pd, 1) print("AFSK") -# sleep(5) -## try: -## file = open("/home/pi/CubeSatSim/t.txt") -## file.close() -## except: -## system("echo '" + callsign + "-11>APCSS:hi hi 100 199 199 199 298 299 299 278 380 350 300 300 439 400 400 400 500 500 500 500 600 600 600 650' > /home/pi/CubeSatSim/t.txt && echo 'AMSAT>APCSS:010101/hi hi ' >> /home/pi/CubeSatSim/t.txt") while True: try: f = open("/home/pi/CubeSatSim/ready") @@ -479,70 +475,45 @@ if __name__ == "__main__": sleep(1) elif (mode == 'm'): print("CW") -# sleep(4) - try: - file = open("/home/pi/CubeSatSim/cw.txt") - file.close() - except: - system("echo 'hi hi 100 199 199 199 298 299 299 278 380 350 300 300 439 400 400 400 500 500 500 500 600 600 600 650' > /home/pi/CubeSatSim/cw.txt") - output(pd, 1) - - if (command_tx == True): - output(txLed, txLedOn) -# battery_saver_check() - - if (txc): - output (pd, 1) - output (ptt, 0) - sleep(0.1) - - system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") - sleep(0.1) - output (ptt, 1) - output (pd, 0) - else: - if (debug_mode == 1): - system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3") - else: - system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1") - - output(txLed, txLedOff) -# output (ptt, 1) - sleep(5) while True: command_control_check() try: f = open("/home/pi/CubeSatSim/cwready") f.close() - system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1") system("sudo rm /home/pi/CubeSatSim/cwready") - - if (command_tx == True): - output(txLed, txLedOn) - output (ptt, 0) - sleep(0.1) -# battery_saver_check() - - if (txc): - system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") - else: - if (debug_mode == 1): - system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3") + ch = 1 + for chan in range(7): + command = "gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw" + str(chan) + ".txt -r 48000 > /dev/null 2>&1" + print(command) + system(command) + chan = chan + 1 + if (command_tx == True): + output(txLed, txLedOn) + output (pd, 1) + sleep(0.3) + output (ptt, 0) + + if (txc): + system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav") else: - system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1") - - sleep(0.1) - output(txLed, txLedOff) - output (ptt, 1) + if (debug_mode == 1): + system("cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3") + else: + system("cat /home/pi/CubeSatSim/morse.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f " + tx + "e3 > /dev/null 2>&1") + sleep(0.1) + output(txLed, txLedOff) + output (ptt, 1) + command_control_check() f.close() -# system("sudo rm /home/pi/CubeSatSim/cwready") sleep(5) - except: + except: + command_control_check() sleep(1) elif (mode == 's'): print("SSTV") + command_control_check() try: # from picamera import PiCamera # from pysstv.sstv import SSTV @@ -568,6 +539,7 @@ if __name__ == "__main__": file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") print("First SSTV stored image detected") system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") + command_control_check() if (command_tx == True): print ("Sending SSTV image") @@ -724,7 +696,7 @@ if __name__ == "__main__": system("(while true; do (sleep 5 && cat /home/pi/CubeSatSim/wav/sstv.wav); done) | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f " + tx + "e3 &") while 1: if (command_tx == True): - + command_control_check() output(txLed, txLedOn) # battery_saver_check() @@ -741,7 +713,9 @@ if __name__ == "__main__": # output (ptt, 1) # output(pd, 0) sleep(1) + elif (mode == 'b'): + command_control_check() print("BPSK") print("turn on FM rx") output(pd, 1)