diff --git a/afsk/main.c b/afsk/main.c index 1dde5c8b..3f1612f3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -83,6 +83,7 @@ ax5043_conf_t hax5043; ax25_conf_t hax25; int twosToInt(int val, int len); +float toAprsFormat(float input); float rnd_float(double min, double max); void get_tlm(); void get_tlm_fox(); @@ -110,7 +111,8 @@ FILE *sopen(const char *program); #define AFSK 1 #define FSK 2 #define BPSK 3 -#define CW 4 +#define SSTV 4 +#define CW 5 int rpitxStatus = -1; @@ -191,7 +193,36 @@ int main(int argc, char * argv[]) { printf("No CW id\n"); } } + } else { + + FILE * mode_file = fopen("/home/pi/CubeSatSim/.mode", "r"); + if (mode_file != NULL) { + char mode_string; + mode_string = fgetc(mode_file); + fclose(mode_file); + printf("Mode file /home/pi/CubeSatSim/.mode contains %c\n", mode_string); + + if ( mode_string == 'b') { + mode = BPSK; + printf("Mode is BPSK\n"); + } else if ( mode_string == 'a') { + mode = AFSK; + printf("Mode is AFSK\n"); + } else if ( mode_string == 's') { + mode = SSTV; + printf("Mode is SSTV\n"); + } else if ( mode_string == 'c') { + mode = CW; + printf("Mode is CW\n"); + } else { + printf("Mode is FSK\n"); + } + + } } + + FILE * rpitx_restart = popen("sudo systemctl restart rpitx", "r"); + fclose(rpitx_restart); // Open configuration file with callsign and reset count FILE * config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r"); @@ -212,11 +243,25 @@ int main(int argc, char * argv[]) { if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) { printf("Valid latitude and longitude in config file\n"); - latitude = lat_file; - longitude = long_file; +// convert to APRS DDMM.MM format + latitude = toAprsFormat(lat_file); + longitude = toAprsFormat(long_file); + printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", latitude, longitude); + } else { // set default + latitude = toAprsFormat(latitude); + longitude = toAprsFormat(longitude); } + if (strcmp(sim_yes, "yes") == 0) sim_mode = TRUE; + + if (mode == SSTV) { + + fprintf(stderr, "Sleeping"); + while (1) + sleep(10); + } + wiringPiSetup(); // Check for SPI and AX-5043 Digital Transceiver Board @@ -852,7 +897,12 @@ void get_tlm(void) { tlm[2][C] = (int)(99.5 - current[map[MINUS_Z]] / 10.0) % 100; // -Z current (was timestamp) tlm[2][D] = (int)(50.5 + current[map[BAT]] / 10.0) % 100; // NiMH Battery current - tlm[3][A] = abs((int)((voltage[map[BAT]] * 10.0) - 65.5) % 100); +// tlm[3][A] = abs((int)((voltage[map[BAT]] * 10.0) - 65.5) % 100); + if (voltage[map[BAT]] > 4.6) + tlm[3][A] = (int)((voltage[map[BAT]] * 10.0) - 65.5) % 100; // 7.0 - 10.0 V for old 9V battery + else + tlm[3][A] = (int)((voltage[map[BAT]] * 10.0) + 44.5) % 100; // 0 - 4.5 V for new 3 cell battery + tlm[3][B] = (int)(voltage[map[BUS]] * 10.0) % 100; // 5V supply to Pi tlm[4][B] = (int)((95.8 - cpuTemp) / 1.48 + 0.5) % 100; @@ -895,13 +945,13 @@ void get_tlm(void) { strcat(str, header_str2); // sprintf(header_str2b, "=%7.2f%c%c%c%08.2f%cShi hi ",4003.79,'N',0x5c,0x5c,07534.33,'W'); // add APRS lat and long if (latitude > 0) - sprintf(header_lat, "%7.2f%c", latitude * 100.0, 'N'); // lat + sprintf(header_lat, "%7.2f%c", latitude, 'N'); // lat else - sprintf(header_lat, "%7.2f%c", latitude * (-100.0), 'S'); // lat + sprintf(header_lat, "%7.2f%c", latitude * (-1.0), 'S'); // lat if (longitude > 0) - sprintf(header_long, "%08.2f%c", longitude * 100.0, 'E'); // long + sprintf(header_long, "%08.2f%c", longitude , 'E'); // long else - sprintf(header_long, "%08.2f%c", longitude * (-100.0), 'W'); // long + sprintf(header_long, "%08.2f%c", longitude * (-1.0), 'W'); // long sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long printf("\n\nString is %s \n\n", header_str2b); @@ -2252,3 +2302,12 @@ int test_i2c_bus(int bus) } return(output); // return bus number or -1 if there is a problem with the bus } + +float toAprsFormat(float input) { +// converts decimal coordinate (latitude or longitude) to APRS DDMM.MM format + int dd = (int) input; + int mm1 = (int)((input - dd) * 60.0); + int mm2 = (int)((input - dd - (float)mm1/60.0) * 60.0 * 60.0); + float output = dd * 100 + mm1 + (float)mm2 * 0.01; + return(output); +} diff --git a/config b/config index f2ed02ab..02ddf9f4 100755 --- a/config +++ b/config @@ -13,13 +13,13 @@ if [ "$1" = "" ]; then echo "$value" > /dev/null set -- $value - if [ "$1" = "ARG1=a" ]; then + if [ "$1" = "a" ]; then echo "APRS mode is set" - elif [ "$1" = "ARG1=f" ]; then + elif [ "$1" = "f" ]; then echo "FSK mode is set" - elif [ "$1" = "ARG1=b" ]; then + elif [ "$1" = "b" ]; then echo "BPSK mode is set" - elif [ "$1" = "ARG1=s" ]; then + elif [ "$1" = "s" ]; then echo "SSTV mode is set" else echo @@ -55,22 +55,22 @@ if [ "$1" = "-i" ]; then exit elif [ "$1" = "-a" ]; then echo "changing CubeSatSim to AFSK mode" - sudo echo "ARG1=a" > /home/pi/CubeSatSim/.mode + sudo echo "a" > /home/pi/CubeSatSim/.mode sudo systemctl restart cubesatsim exit elif [ "$1" = "-f" ]; then echo "changing CubeSatSim to FSK mode" - sudo echo "ARG1=f" > /home/pi/CubeSatSim/.mode + sudo echo "f" > /home/pi/CubeSatSim/.mode sudo systemctl restart cubesatsim exit elif [ "$1" = "-b" ]; then echo "changing CubeSatSim to BPSK mode" - sudo echo "ARG1=b" > /home/pi/CubeSatSim/.mode + sudo echo "b" > /home/pi/CubeSatSim/.mode sudo systemctl restart cubesatsim exit elif [ "$1" = "-s" ]; then echo "changing CubeSatSim to SSTV mode" - sudo echo "ARG1=s" > /home/pi/CubeSatSim/.mode + sudo echo "s" > /home/pi/CubeSatSim/.mode sudo systemctl restart cubesatsim exit elif [ "$1" = "-h" ]; then diff --git a/demo.sh b/demo.sh deleted file mode 100755 index e25a8214..00000000 --- a/demo.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -echo -e "\nDemo of CubeSatSim at 434.9 MHz\n" - -sudo systemctl restart rpitx - -if [ "$1" = "c" ]; then - echo "Mode cycling" - y=$(last reboot | grep ^reboot | wc -l) - echo $y - echo $(($y % 4)) -fi - -if [[ ("$1" = "a" ) || (("$1" = "c") && ("$(($y %4))" = 3)) ]]; then - echo "Mode is continuous AFSK" - /home/pi/CubeSatSim/cubesatsim afsk -elif [[ ("$1" = "b" ) || (("$1" = "c") && ("$(($y %4))" = 1)) ]]; then - echo "Mode is continuous BPSK" - sudo cpulimit -l 2.5 -b -P cubesatsim - /home/pi/CubeSatSim/cubesatsim bpsk -elif [[ ("$1" = "s" ) || (("$1" = "c") && ("$(($y %4))" = 2)) ]]; then - echo "Mode is continuous SSTV" - while true; do sleep 5; done -else - echo "Mode is continuous FSK" - /home/pi/CubeSatSim/cubesatsim fsk -fi - diff --git a/install b/install index 554de89e..4f0c6b8b 100755 --- a/install +++ b/install @@ -77,6 +77,12 @@ cd PiSSTVpp make pisstvpp +echo "Copying SSTV image 1" +cp /home/pi/CubeSatSim/sstv/sstv_image_1_320_x_256.jpg /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg + +echo "Copying SSTV image 2" +cp /home/pi/CubeSatSim/sstv/sstv_image_2_320_x_256.jpg /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg + cd diff --git a/rpitx.py b/rpitx.py index b45e829b..6c975ded 100644 --- a/rpitx.py +++ b/rpitx.py @@ -32,6 +32,14 @@ GPIO.output(27, 0) print(transmit) +try: + file = open("/home/pi/CubeSatSim/.mode") + mode = file.read(1) +except: + mode = "f" +print("Mode is: ") +print(mode) + try: file = open("/home/pi/CubeSatSim/sim.cfg") callsign = file.readline().split(" ")[0] @@ -41,7 +49,7 @@ print(callsign) #GPIO.output(27, 1); GPIO.output(txLed, txLedOn); -system("echo 'de " + callsign + "' > id.txt && sudo gen_packets -M 20 /home/pi/CubeSatSim/id.txt -o /home/pi/CubeSatSim/morse.wav -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 434.9e3") +system("echo '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 && 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 434.9e3") #GPIO.output(27, 0); GPIO.output(txLed, txLedOff); @@ -53,88 +61,88 @@ if __name__ == "__main__": # print 'Length: ', len(sys.argv) - if (len(sys.argv)) > 1: +# if (len(sys.argv)) > 1: # print("There are arguments!") - if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])): - print("AFSK") + if (mode == 'a'): + print("AFSK") + time.sleep(4) + for x in range(5): + GPIO.output(txLed, txLedOn); + system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") + GPIO.output(txLed, txLedOff); time.sleep(4) - for x in range(5): - GPIO.output(txLed, txLedOn); + while True: + try: + f = open("/home/pi/CubeSatSim/ready") system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") - GPIO.output(txLed, txLedOff); - time.sleep(4) - while True: - try: - f = open("/home/pi/CubeSatSim/ready") - system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") - f.close() - system("sudo rm ready") - time.sleep(0.5) - except: - time.sleep(0.5) - elif (('s' == sys.argv[1]) or ('sstv' in sys.argv[1])): - print("SSTV") - try: - from picamera import PiCamera + f.close() + system("sudo rm ready") + time.sleep(0.5) + except: + time.sleep(0.5) + elif (mode == 's'): + print("SSTV") + try: + from picamera import PiCamera # from pysstv.sstv import SSTV - camera = PiCamera() - print("Camera present") - camera_present = 1 - camera.close() - except: - print("No camera") - camera_present = 0 - try: - 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") + camera = PiCamera() + print("Camera present") + camera_present = 1 + camera.close() + except: + print("No camera") + camera_present = 0 + try: + 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") + print ("Sending SSTV image") + GPIO.output(txLed, txLedOn); + system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # > /dev/null 2>&1") + GPIO.output(txLed, txLedOff) +# time.sleep(1) + except: + print("No first image") +# while 1: + GPIO.output(txLed, txLedOff) + if (camera_present == 1): + while 1: + system("raspistill -o /home/pi/CubeSatSim/camera_out.jpg -w 320 -h 256") # > /dev/null 2>&1") + print("Photo taken") + system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/camera_out.jpg") print ("Sending SSTV image") GPIO.output(txLed, txLedOn); - system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # > /dev/null 2>&1") + system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # > /dev/null 2>&1") GPIO.output(txLed, txLedOff) -# time.sleep(1) - except: - print("No first image") -# while 1: - GPIO.output(txLed, txLedOff) - if (camera_present == 1): + time.sleep(1) + else: + try: + file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") + print("Second SSTV stored image detected") + system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") while 1: - system("raspistill -o /home/pi/CubeSatSim/camera_out.jpg -w 320 -h 256") # > /dev/null 2>&1") - print("Photo taken") - system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/camera_out.jpg") print ("Sending SSTV image") GPIO.output(txLed, txLedOn); - system("cat /home/pi/CubeSatSim/camera_out.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # > /dev/null 2>&1") + system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # > /dev/null 2>&1") + GPIO.output(txLed, txLedOff) + time.sleep(5) + except: + 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 434.9e3 &") + while 1: + GPIO.output(txLed, txLedOn) + time.sleep(60) GPIO.output(txLed, txLedOff) time.sleep(1) - else: - try: - file = open("/home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") - print("Second SSTV stored image detected") - system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg") - while 1: - print ("Sending SSTV image") - GPIO.output(txLed, txLedOn); - system("cat /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav | csdr convert_i16_f | csdr gain_ff 14000 | csdr convert_f_samplerf 20833 | sudo rpitx -i- -m RF -f 434.9e3") # > /dev/null 2>&1") - GPIO.output(txLed, txLedOff) - time.sleep(5) - except: - 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 434.9e3 &") - while 1: - GPIO.output(txLed, txLedOn) - time.sleep(60) - GPIO.output(txLed, txLedOff) - time.sleep(1) - elif (('b' == sys.argv[1]) or ('bpsk' in sys.argv[1])): - print("BPSK") - system("sudo nc -l 8080 | 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 /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float") - else: - print("FSK") - system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") + elif (mode == 'b'): + print("BPSK") + system("sudo nc -l 8080 | 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 /home/pi/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float") else: print("FSK") system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") +# else: +# print("FSK") +# system("sudo nc -l 8080 | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") else: print("No Band Pass Filter so no telemetry transmit. See http://cubesatsim.org/wiki for instructions on how to build the BPF.") diff --git a/rpitx.sh b/rpitx.sh deleted file mode 100755 index afc736a2..00000000 --- a/rpitx.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -echo -e "\nrpitx for CubeSatSim at 434.9 MHz using python\n" - -if [ "$1" = "c" ]; then - echo "Mode cycling" - y=$(last reboot | grep ^reboot | wc -l) - echo $y - if [ $(($y % 4)) = 3 ]; then - echo "Mode is continuous AFSK" - python3 -u /home/pi/CubeSatSim/rpitx.py a - elif [ $(($y % 4)) = 1 ]; then - echo "Mode is continuous BPSK" - python3 -u /home/pi/CubeSatSim/rpitx.py b - elif [ $(($y % 4)) = 2 ]; then - echo "Mode is continuous SSTV" - python3 -u /home/pi/CubeSatSim/rpitx.py s - else - echo "Mode is continuous FSK" - python3 -u /home/pi/CubeSatSim/rpitx.py f - fi -else - python3 -u /home/pi/CubeSatSim/rpitx.py $1 -fi - diff --git a/systemd/cubesatsim.service b/systemd/cubesatsim.service index e704d5b8..213fdfea 100644 --- a/systemd/cubesatsim.service +++ b/systemd/cubesatsim.service @@ -1,15 +1,14 @@ [Unit] -Description=CubeSatSim demo service +Description=CubeSatSim service [Service] TimeoutStopSec=5 -EnvironmentFile=/home/pi/CubeSatSim/.mode -ExecStart=/home/pi/CubeSatSim/demo.sh $ARG1 +ExecStart=/home/pi/CubeSatSim/cubesatsim WorkingDirectory=/home/pi/CubeSatSim StandardOutput=inherit StandardError=inherit Restart=always -User=root +User=pi CPUAccounting=true CPUQuota=5% diff --git a/systemd/rpitx.service b/systemd/rpitx.service index c58b7bd1..2f2feac2 100644 --- a/systemd/rpitx.service +++ b/systemd/rpitx.service @@ -3,8 +3,7 @@ Description=CubeSatSim rpitx service [Service] TimeoutStopSec=5 -EnvironmentFile=/home/pi/CubeSatSim/.mode -ExecStart=/home/pi/CubeSatSim/rpitx.sh $ARG1 +ExecStart=python3 -u /home/pi/CubeSatSim/rpitx.py WorkingDirectory=/home/pi/CubeSatSim StandardOutput=inherit StandardError=inherit diff --git a/update b/update index 4e9e29b9..c96f5bd6 100755 --- a/update +++ b/update @@ -18,6 +18,14 @@ sudo sed -i 's/more information/more\ninformation/g' /etc/motd sudo sed -i 's/update to/update\nto/g' /etc/motd + +cd /home/pi/pi-power-button && git pull + +script/install + +cd + + cd /home/pi/CubeSatSim git pull > .updated