diff --git a/config b/config index 3951c06c..014ae111 100755 --- a/config +++ b/config @@ -210,7 +210,8 @@ function transmit_command_beacon { exit } -echo "CubeSatSim v2.1 configuration tool" +echo +echo "CubeSatSim v2.2 configuration tool" echo # echo $1 # echo $2 @@ -222,8 +223,13 @@ sudo modprobe snd-aloop if [ -z "$2" ] ; then noreboot=0 else - noreboot=1 - echo "Reboot disabled" + if [ "$2" = "n" ] ; then + echo "Reboot disabled" + noreboot=1 + else + fail=$2 + fi + fi # echo "No reboot" @@ -278,7 +284,7 @@ if [ "$1" = "" ]; then FILE=/home/pi/CubeSatSim/failure_mode.txt if [ -f "$FILE" ]; then - if [[ $(grep '0' $FILE) ]]; then + if [[ $(grep "\-1" $FILE) ]]; then echo "No simulated failure" else fail=$(<$FILE) @@ -314,6 +320,9 @@ if [ "$1" = "" ]; then 9) echo "Failed MPU Sensor" ;; +# "10") +# echo "Failed FM Audio" +# ;; *) echo "Unknown Failure" ;; @@ -1481,62 +1490,120 @@ elif [ "$1" = "-j" ]; then elif [ "$1" = "-M" ]; then -# echo - echo "Set simulated failure mode" - echo - - echo "0 No Failure (turn OFF)" - echo "1 +X Solar Panel Failure" - echo "2 -X Solar Panel Degredation" - echo "3 -Y Solar Panel Short Circuit" - echo "4 Failed I2C Bus 1" - echo "5 Failed I2C Bus 3" - echo "6 Failed Camera" - echo "7 Failed Payload" - echo "8 Failed BME Sensor" - echo "9 Failed MPU Sensor" - echo + if [ $fail ]; then + MODE=$fail + else - echo "Enter the failure number to set: 0 - 9" - read MODE + FILE=/home/pi/CubeSatSim/failure_mode.txt + if [ -f "$FILE" ]; then + if [[ $(grep "\-1" $FILE) ]]; then + echo "Currently, no simulated failure" + else + fail=$(<$FILE) + echo -n "Currently, simulated " + case $fail in + + 1) + echo "+X Solar Panel Failure" + ;; + 2) + echo "-X Solar Panel Degredation" + ;; + 3) + echo "-Y Solar Panel Short Circuit" + ;; + 4) + echo "Failed I2C Bus 1" + ;; + 5) + echo "Failed I2C Bus 3" + ;; + 6) + echo "Failed Camera" + ;; + 7) + echo "Failed Payload" + ;; + 8) + echo "Failed BME Sensor" + ;; + 9) + echo "Failed MPU Sensor" + ;; + # "10") + # echo "Failed FM Audio" + # ;; + *) + echo "Unknown Failure" + ;; + esac + fi + else + echo "Currently, no simulated failure" + fi + + echo + echo "Set simulated failure mode (or Return to turn OFF)" + echo + + echo " 0 No Failure (turn OFF)" + echo " 1 +X Solar Panel Failure" + echo " 2 -X Solar Panel Degredation" + echo " 3 -Y Solar Panel Short Circuit" + echo " 4 Failed I2C Bus 1" + echo " 5 Failed I2C Bus 3" + echo " 6 Failed Camera" + echo " 7 Failed Payload" + echo " 8 Failed BME Sensor" + echo " 9 Failed MPU Sensor" + # echo "10 Failed FM Audio" + echo + + # echo "Enter the failure number to set: 0 - 10" # 10 sometimes gets stuck on carrier + echo "Enter the failure number to set: 0 - 9" + read MODE + echo + fi - echo if [ "$MODE" = "0" ]; then echo "Setting No Simulated Failure" - else - echo -n "Setting Simulated " - + MODE=-1 + else case $MODE in 1) - echo "+X Solar Panel Failure" + echo "Setting Simulated +X Solar Panel Failure" ;; 2) - echo "-X Solar Panel Degredation" + echo "Setting Simulated -X Solar Panel Degredation" ;; 3) - echo "-Y Solar Panel Short Circuit" + echo "Setting Simulated -Y Solar Panel Short Circuit" ;; 4) - echo "Failed I2C Bus 1" + echo "Setting Simulated Failed I2C Bus 1" ;; 5) - echo "Failed I2C Bus 3" + echo "Setting Simulated Failed I2C Bus 3" ;; 6) - echo "Failed Camera" + echo "Setting Simulated Failed Camera" ;; 7) - echo "Failed Payload" + echo "Setting Simulated Failed Payload" ;; 8) - echo "Failed BME Sensor" + echo "Setting Simulated Failed BME Sensor" ;; 9) - echo "Failed MPU Sensor" + echo "Setting Simulated Failed MPU Sensor" ;; +# "10") +# echo "Setting Failed FM Audio" +# ;; *) - echo "Unknown Failure" + echo "Setting No Simulated Failure" + MODE=-1 ;; esac fi diff --git a/install b/install index fc333a64..3de142d4 100755 --- a/install +++ b/install @@ -1,6 +1,6 @@ #!/bin/bash -echo -e "\ninstallation script for CubeSatSim v2.1\n" +echo -e "\ninstallation script for CubeSatSim v2.2\n" FILE=/home/pi/CubeSatSim/sim.cfg if [ -f "$FILE" ]; then diff --git a/main.c b/main.c index fccfccb2..cbb42105 100644 --- a/main.c +++ b/main.c @@ -25,7 +25,7 @@ int main(int argc, char * argv[]) { - printf("\n\nCubeSatSim v2.1 starting...\n\n"); + printf("\n\nCubeSatSim v2.2 starting...\n\n"); wiringPiSetup(); @@ -276,7 +276,6 @@ int main(int argc, char * argv[]) { txLed = 2; txLedOn = HIGH; txLedOff = LOW; - vB5 = TRUE; onLed = 27; onLedOn = HIGH; onLedOff = LOW; @@ -295,12 +294,17 @@ int main(int argc, char * argv[]) { fclose(config_file); config_file = fopen("sim.cfg", "r"); - map[BAT2] = MINUS_Z; - map[BAT] = BAT2; - map[PLUS_Z] = BAT; - map[MINUS_Z] = PLUS_Z; - snprintf(busStr, 10, "%d %d", i2c_bus1, test_i2c_bus(0)); - voltageThreshold = 8.0; + map[MINUS_X] = MINUS_Y; + map[PLUS_Z] = MINUS_X; + map[MINUS_Y] = PLUS_Z; + + if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present + printf("/dev/i2c-11 is present\n\n"); + snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(11)); + } else { + snprintf(busStr, 10, "%d %d", i2c_bus1, i2c_bus3); + } + // check for camera // char cmdbuffer1[1000]; @@ -551,16 +555,17 @@ int main(int argc, char * argv[]) { if (sim_mode) { if (loop % 10 == 0) { - failureMode = (int) rnd_float(1, FAIL_COUNT); +// failureMode = (int) rnd_float(1, FAIL_COUNT); + failureMode = (int) rnd_float(1, 9); printf("Sim Mode Random Failure Change\n"); FILE * failure_mode_file = fopen("/home/pi/CubeSatSim/failure_mode.txt", "w"); fprintf(failure_mode_file, "%d", failureMode); fclose(failure_mode_file); } } - else - { - failureMode = OFF; +// else +// { +// failureMode = OFF; FILE * failure_mode_file = fopen("/home/pi/CubeSatSim/failure_mode.txt", "r"); if (failure_mode_file != NULL) { char failure_string[10]; @@ -571,9 +576,9 @@ int main(int argc, char * argv[]) { } } else { failureMode = FAIL_NONE; - printf("No simulated failure."); + printf("No simulated failure.\n"); } - } +// } { int count1; @@ -605,22 +610,22 @@ int main(int argc, char * argv[]) { } } if (voltage[map[BAT]] == 0.0) // No BAT Board - if (voltage[map[BAT2]] == 0.0) // No BAT2 Board - batteryVoltage = 4.5; - else { - batteryVoltage = voltage[map[BAT2]]; // only BAT2 Board present + if (voltage[map[BAT2]] == 0.0) // No BAT2 Board + batteryVoltage = 4.5; + else { + batteryVoltage = voltage[map[BAT2]]; // only BAT2 Board present + if (sim_mode && !sim_config) { // if Voltage sensor on Battery board is present, exit simulated telemetry mode + sim_mode = FALSE; + fprintf(stderr, "Turning off sim_mode since battery sensor 2 is present\n"); + } + } + else { + batteryVoltage = voltage[map[BAT]]; // BAT Board present if (sim_mode && !sim_config) { // if Voltage sensor on Battery board is present, exit simulated telemetry mode sim_mode = FALSE; - fprintf(stderr, "Turning off sim_mode since battery sensor 2 is present\n"); + fprintf(stderr, "Turning off sim_mode since battery sensor is present\n"); } } - else { - batteryVoltage = voltage[map[BAT]]; // BAT Board present - if (sim_mode && !sim_config) { // if Voltage sensor on Battery board is present, exit simulated telemetry mode - sim_mode = FALSE; - fprintf(stderr, "Turning off sim_mode since battery sensor is present\n"); - } - } batteryCurrent = current[map[BAT]] + current[map[BAT2]]; // Sum BAT and BAT2 currents } @@ -659,7 +664,7 @@ int main(int argc, char * argv[]) { if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) // only process if valid payload response { - printf("Valid Payload!\n"); +// printf("Valid Payload!\n"); int count1; char * token; @@ -748,7 +753,7 @@ int main(int argc, char * argv[]) { strcpy(sensor_payload, buffer2); // restore sensor_payload after strtok operation if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) { - printf("Valid Payload!!\n"); +// printf("Valid Payload!!\n"); for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) { if (sensor[count1] < sensor_min[count1]) sensor_min[count1] = sensor[count1]; @@ -825,8 +830,7 @@ int main(int argc, char * argv[]) { // end of simulated telemetry } - else { - } + FILE * cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); if (cpuTempSensor) { // double cpuTemp; @@ -1210,6 +1214,7 @@ void get_tlm_fox() { int i; long int sync = syncWord; + int cam = ON; smaller = (int) (S_RATE / (2 * freq_Hz)); @@ -1255,8 +1260,8 @@ void get_tlm_fox() { printf("+X Solar Simulated Failure\n"); } if (failureMode == FAIL_DEGRADE) { - voltage[map[MINUS_X]] = voltage[MINUS_X] * 0.5; - current[map[MINUS_X]] = current[MINUS_X] * 0.5; + voltage[map[MINUS_X]] = voltage[map[MINUS_X]] * 0.5; + current[map[MINUS_X]] = current[map[MINUS_X]] * 0.5; printf("-X Solar Deg Simulated Failure\n"); } if (failureMode == FAIL_SHORT) { @@ -1285,14 +1290,14 @@ void get_tlm_fox() { current[map[PLUS_Z]] = 0.0; printf("I2C Bus 3 Simulated Failure!\n"); } - if (failureMode == FAIL_CAMERA) { - camera = OFF; - printf("Camera Simulated Failure!\n"); - } if (failureMode == FAIL_PAYLOAD) { payload = OFF; printf("Payload Simulated Failure!\n"); } + if (failureMode == FAIL_CAMERA) { + cam = OFF; + printf("Camera Simulated Failure!\n"); + } if (mode == FSK) id = 7; @@ -1434,24 +1439,13 @@ void get_tlm_fox() { // encodeB(b, 1 + head_offset, batt_b_v); encodeA(b, 3 + head_offset, batt_c_v); - - if ((failureMode == FAIL_MPU) || (failureMode == FAIL_PAYLOAD)) - { - encodeB(b, 4 + head_offset, 2048); // 0 - encodeA(b, 6 + head_offset, 2048); // 0 - encodeB(b, 7 + head_offset, 2048); // 0 - } - else - { - encodeB(b, 4 + head_offset, (int)(sensor[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel - encodeA(b, 6 + head_offset, (int)(sensor[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel - encodeB(b, 7 + head_offset, (int)(sensor[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel - } + encodeB(b, 4 + head_offset, (int)(sensor[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel + encodeA(b, 6 + head_offset, (int)(sensor[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel + encodeB(b, 7 + head_offset, (int)(sensor[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel encodeA(b, 9 + head_offset, battCurr); - if ((failureMode != FAIL_PAYLOAD) && (failureMode != FAIL_BME)) - encodeB(b, 10 + head_offset, (int)(sensor[TEMP] * 10 + 0.5)); // Temp + encodeB(b, 10 + head_offset, (int)(sensor[TEMP] * 10 + 0.5)); // Temp if (mode == FSK) { encodeA(b, 12 + head_offset, posXv); @@ -1506,39 +1500,27 @@ void get_tlm_fox() { encodeA(b_max, 39 + head_offset, (int)(other_max[IHU_TEMP] * 10 + 0.5)); encodeB(b_max, 31 + head_offset, ((int)(other_max[SPIN] * 10)) + 2048); - if (failureMode != FAIL_PAYLOAD) { if (sensor_min[TEMP] != 1000.0) // make sure values are valid { - if (failureMode != FAIL_MPU) { - encodeB(b_max, 4 + head_offset, (int)(sensor_max[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel + + encodeB(b_max, 4 + head_offset, (int)(sensor_max[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel encodeA(b_max, 6 + head_offset, (int)(sensor_max[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel encodeB(b_max, 7 + head_offset, (int)(sensor_max[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel encodeB(b_max, 40 + head_offset, (int)(sensor_max[GYRO_X] + 0.5) + 2048); encodeA(b_max, 42 + head_offset, (int)(sensor_max[GYRO_Y] + 0.5) + 2048); encodeB(b_max, 43 + head_offset, (int)(sensor_max[GYRO_Z] + 0.5) + 2048); - } - else - { - encodeB(b_max, 4 + head_offset, 2048); // 0 - encodeA(b_max, 6 + head_offset, 2048); // 0 - encodeB(b_max, 7 + head_offset, 2048); // 0 - encodeB(b_max, 40 + head_offset, 2048); - encodeA(b_max, 42 + head_offset, 2048); - encodeB(b_max, 43 + head_offset, 2048); - } - if (failureMode != FAIL_BME) { - encodeA(b_max, 33 + head_offset, (int)(sensor_max[PRES] + 0.5)); // Pressure + + encodeA(b_max, 33 + head_offset, (int)(sensor_max[PRES] + 0.5)); // Pressure encodeB(b_max, 34 + head_offset, (int)(sensor_max[ALT] * 10.0 + 0.5)); // Altitude // encodeB(b_max, 49 + head_offset, (int)(sensor_max[XS1] * 10 + 0.5) + 2048); encodeB(b_max, 10 + head_offset, (int)(sensor_max[TEMP] * 10 + 0.5)); encodeA(b_max, 45 + head_offset, (int)(sensor_max[HUMI] * 10 + 0.5)); - } encodeA(b_max, 48 + head_offset, (int)(sensor_max[DTEMP] * 10 + 0.5) + 2048); encodeB(b_max, 49 + head_offset, (int)(sensor_max[XS1])); encodeA(b_max, 0 + head_offset, (int)(sensor_max[XS2])); encodeB(b_max, 1 + head_offset, (int)(sensor_max[XS3])); - } + } else { encodeB(b_max, 4 + head_offset, 2048); // 0 @@ -1550,18 +1532,8 @@ void get_tlm_fox() { encodeA(b_max, 48 + head_offset, 2048); // encodeB(b_max, 49 + head_offset, 2048); - } - } - else - { - encodeB(b_max, 4 + head_offset, 2048); // 0 - encodeA(b_max, 6 + head_offset, 2048); // 0 - encodeB(b_max, 7 + head_offset, 2048); // 0 - encodeB(b_max, 40 + head_offset, 2048); - encodeA(b_max, 42 + head_offset, 2048); - encodeB(b_max, 43 + head_offset, 2048); - encodeA(b_max, 48 + head_offset, 2048); - } + } + encodeA(b_min, 12 + head_offset, (int)(voltage_min[map[PLUS_X]] * 100)); encodeB(b_min, 13 + head_offset, (int)(voltage_min[map[PLUS_Y]] * 100)); encodeA(b_min, 15 + head_offset, (int)(voltage_min[map[PLUS_Z]] * 100)); @@ -1585,33 +1557,19 @@ void get_tlm_fox() { encodeB(b_min, 37 + head_offset, (int)(other_min[RSSI] + 0.5) + 2048); encodeA(b_min, 39 + head_offset, (int)(other_min[IHU_TEMP] * 10 + 0.5)); - if (failureMode != FAIL_PAYLOAD) { if (sensor_min[TEMP] != 1000.0) // make sure values are valid { - if (failureMode != FAIL_MPU) - { - encodeB(b_min, 4 + head_offset, (int)(sensor_min[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel - encodeA(b_min, 6 + head_offset, (int)(sensor_min[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel - encodeB(b_min, 7 + head_offset, (int)(sensor_min[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel - encodeB(b_min, 40 + head_offset, (int)(sensor_min[GYRO_X] + 0.5) + 2048); - encodeA(b_min, 42 + head_offset, (int)(sensor_min[GYRO_Y] + 0.5) + 2048); - encodeB(b_min, 43 + head_offset, (int)(sensor_min[GYRO_Z] + 0.5) + 2048); - } - else - { - encodeB(b_min, 4 + head_offset, 2048); // 0 - encodeA(b_min, 6 + head_offset, 2048); // 0 - encodeB(b_min, 7 + head_offset, 2048); // 0 - encodeB(b_min, 40 + head_offset, 2048); - encodeA(b_min, 42 + head_offset, 2048); - encodeB(b_min, 43 + head_offset, 2048); - } - if (failureMode != FAIL_BME) { - encodeA(b_min, 33 + head_offset, (int)(sensor_min[PRES] + 0.5)); // Pressure - encodeB(b_min, 34 + head_offset, (int)(sensor_min[ALT] * 10.0 + 0.5)); // Altitude - encodeB(b_min, 10 + head_offset, (int)(sensor_min[TEMP] * 10 + 0.5)); - encodeA(b_min, 45 + head_offset, (int)(sensor_min[HUMI] * 10 + 0.5)); - } + encodeB(b_min, 4 + head_offset, (int)(sensor_min[ACCEL_X] * 100 + 0.5) + 2048); // Xaccel + encodeA(b_min, 6 + head_offset, (int)(sensor_min[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel + encodeB(b_min, 7 + head_offset, (int)(sensor_min[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel + encodeB(b_min, 40 + head_offset, (int)(sensor_min[GYRO_X] + 0.5) + 2048); + encodeA(b_min, 42 + head_offset, (int)(sensor_min[GYRO_Y] + 0.5) + 2048); + encodeB(b_min, 43 + head_offset, (int)(sensor_min[GYRO_Z] + 0.5) + 2048); + + encodeA(b_min, 33 + head_offset, (int)(sensor_min[PRES] + 0.5)); // Pressure + encodeB(b_min, 34 + head_offset, (int)(sensor_min[ALT] * 10.0 + 0.5)); // Altitude + encodeB(b_min, 10 + head_offset, (int)(sensor_min[TEMP] * 10 + 0.5)); + encodeA(b_min, 45 + head_offset, (int)(sensor_min[HUMI] * 10 + 0.5)); encodeA(b_min, 48 + head_offset, (int)(sensor_min[DTEMP] * 10 + 0.5) + 2048); // encodeB(b_min, 49 + head_offset, (int)(sensor_min[XS1] * 10 + 0.5) + 2048); @@ -1633,64 +1591,29 @@ void get_tlm_fox() { encodeA(b_min, 48 + head_offset, 2048); // encodeB(b_min, 49 + head_offset, 2048); } - } - else - { - encodeB(b_min, 4 + head_offset, 2048); // 0 - encodeA(b_min, 6 + head_offset, 2048); // 0 - encodeB(b_min, 7 + head_offset, 2048); // 0 - - encodeB(b_min, 40 + head_offset, 2048); - encodeA(b_min, 42 + head_offset, 2048); - encodeB(b_min, 43 + head_offset, 2048); - - encodeA(b_min, 48 + head_offset, 2048); - } + } encodeA(b, 30 + head_offset, BAT2Voltage); encodeB(b, 31 + head_offset, ((int)(other[SPIN] * 10)) + 2048); - if (failureMode != FAIL_PAYLOAD) { - if (failureMode != FAIL_BME) { - encodeA(b, 33 + head_offset, (int)(sensor[PRES] + 0.5)); // Pressure + encodeA(b, 33 + head_offset, (int)(sensor[PRES] + 0.5)); // Pressure encodeB(b, 34 + head_offset, (int)(sensor[ALT] * 10.0 + 0.5)); // Altitude encodeA(b, 45 + head_offset, (int)(sensor[HUMI] * 10 + 0.5)); // in place of sensor1 encodeA(b, 39 + head_offset, (int)(other[TEMP] * 10 + 0.5)); - } + encodeA(b, 36 + head_offset, Resets); encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5) + 2048); - if (failureMode != FAIL_MPU) { encodeB(b, 40 + head_offset, (int)(sensor[GYRO_X] + 0.5) + 2048); encodeA(b, 42 + head_offset, (int)(sensor[GYRO_Y] + 0.5) + 2048); encodeB(b, 43 + head_offset, (int)(sensor[GYRO_Z] + 0.5) + 2048); - } - else - { - encodeB(b, 40 + head_offset, 2048); - encodeA(b, 42 + head_offset, 2048); - encodeB(b, 43 + head_offset, 2048); - } encodeA(b, 48 + head_offset, (int)(sensor[DTEMP] * 10 + 0.5) + 2048); encodeB(b, 49 + head_offset, (int)(sensor[XS1])); encodeA(b, 0 + head_offset, (int)(sensor[XS2])); encodeB(b, 1 + head_offset, (int)(sensor[XS3])); - } - else - { - encodeB(b, 4 + head_offset, 2048); // 0 - encodeA(b, 6 + head_offset, 2048); // 0 - encodeB(b, 7 + head_offset, 2048); // 0 - - encodeB(b, 40 + head_offset, 2048); - encodeA(b, 42 + head_offset, 2048); - encodeB(b, 43 + head_offset, 2048); - - encodeA(b, 48 + head_offset, 2048); -// encodeB(b_min, 49 + head_offset, 2048); - } + encodeB(b, 46 + head_offset, BAT2Current); encodeA(b, 39 + head_offset, (int)(other[IHU_TEMP] * 10 + 0.5)); @@ -1727,7 +1650,7 @@ void get_tlm_fox() { // int status = STEMBoardFailure + SafeMode * 2 + sim_mode * 4 + PayloadFailure1 * 8 + // (i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256; int status = STEMBoardFailure + SafeMode * 2 + simulated * 4 + PayloadFailure1 * 8 + - (i2c_bus0 == OFF) * 16 + (i2c_1 == OFF) * 32 + (i2c_3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256; + (i2c_bus0 == OFF) * 16 + (i2c_1 == OFF) * 32 + (i2c_3 == OFF) * 64 + (cam == OFF) * 128 + groundCommandCount * 256; encodeA(b, 51 + head_offset, status); encodeB(b, 52 + head_offset, rxAntennaDeployed + txAntennaDeployed * 2 + c2cStatus * 4); diff --git a/main.h b/main.h index 10c263d0..6ce6b86a 100644 --- a/main.h +++ b/main.h @@ -122,7 +122,7 @@ FILE *image_file; #define TXCOMMAND 12 #define FAIL_COUNT 10 -#define FAIL_NONE 0 +#define FAIL_NONE -1 #define FAIL_SOLAR 1 #define FAIL_DEGRADE 2 #define FAIL_SHORT 3 @@ -169,7 +169,7 @@ float sleepTime; unsigned int sampleTime = 0; int frames_sent = 0; int cw_id = ON; -int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; +int transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF; // float voltageThreshold = 3.6, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100; float voltageThreshold = 3.5, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100; float latitude = 39.027702f, longitude = -77.078064f; diff --git a/telem.c b/telem.c index 1fc534a5..ce4f14c3 100644 --- a/telem.c +++ b/telem.c @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) { } } - printf("CubeSatSim v2.1 INA219 Voltage and Current Telemetry\n"); + printf("CubeSatSim v2.2 INA219 Voltage and Current Telemetry\n"); map[MINUS_X] = MINUS_Y; map[PLUS_Z] = MINUS_X; map[MINUS_Y] = PLUS_Z; diff --git a/transmit.py b/transmit.py index 7fc649f9..fc745f45 100644 --- a/transmit.py +++ b/transmit.py @@ -12,6 +12,30 @@ from PIL import Image, ImageDraw, ImageFont, ImageColor import serial import random +def sim_failure_check(): + try: + global card + global cam_fail + cam_fail = False + file = open("/home/pi/CubeSatSim/failure_mode.txt") + fail_mode = int(file.read(2)) +# print("Fail_mode: ") +# print(fail_mode) + if (fail_mode == 10): + card = "Device" # Change audio so no FM audio plays + print("Failure mode no FM audio") + elif (fail_mode == 6): + cam_fail = True + print("Failure mode camera fail") + elif (fail_mode == 0): + print("No failure mode") + else: + print("Other failure mode") + card = "Headphones" + except: + print("No failure mode") + card = "Headphones" + def battery_saver_check(): try: global txc @@ -95,6 +119,8 @@ def increment_mode(): print("can't write to .mode file") def camera_photo(): + global cam_fail + sim_failure_check() system("sudo rm /home/pi/CubeSatSim/camera_out.jpg") stored_image = False try: @@ -102,6 +128,10 @@ def camera_photo(): f = open("/home/pi/CubeSatSim/camera_out.jpg") f.close() print("Photo taken") + if (cam_fail == True): + system("cp /home/pi/CubeSatSim/sstv//sstv_image_2_320_x_256.jpeg /home/pi/CubeSatSim/camera_out.jpg") + print("Using stored image") + stored_image = True except: system("cp /home/pi/CubeSatSim/sstv//sstv_image_2_320_x_256.jpeg /home/pi/CubeSatSim/camera_out.jpg") print("Using stored image") @@ -130,7 +160,7 @@ def camera_photo(): draw.text((120, 10), telem_string, font=font2, fill='white') img.save(file) -print("CubeSatSim v2.1 transmit.py starting...") +print("CubeSatSim v2.2 transmit.py starting...") pd = 21 ptt = 20 @@ -446,6 +476,7 @@ if __name__ == "__main__": # # battery_saver_check() if (txc): + sim_failure_check() # output(pd, 1) sleep(0.1) # add delay before transmit output (ptt, 0) @@ -472,16 +503,7 @@ if __name__ == "__main__": print("Ready for next packet!") sleep(0.5) - try: - file = open("/home/pi/CubeSatSim/failure_mode.txt") - fail_mode = file.read(2) - if (fail_mode == "10"): - card = "Device" # Change audio so no FM audio plays - print("Failure mode no FM audio") - else: - print("Other failure mode") - except: - print("No failure mode") + except: # command_control_check() sleep(1) @@ -508,6 +530,7 @@ if __name__ == "__main__": output(txLed, txLedOn) if (txc): + sim_failure_check() # output (pd, 1) sleep(0.3) output (ptt, 0) @@ -569,6 +592,7 @@ if __name__ == "__main__": # battery_saver_check() if (txc): + sim_failure_check() # output(pd, 1) output (ptt, 0) system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav") @@ -587,35 +611,7 @@ if __name__ == "__main__": print("image 2 did not load - copy from CubeSatSim/sstv directory") while 1: # command_control_check() - camera_photo() -## system("raspistill -o /home/pi/CubeSatSim/camera_out.jpg -w 320 -h 256") # > /dev/null 2>&1") -## print("Photo taken") -## -## file='/home/pi/CubeSatSim/camera_out.jpg' -## font1 = ImageFont.truetype('DejaVuSerif.ttf', 20) -## font2 = ImageFont.truetype('DejaVuSerif-Bold.ttf', 16) -## -## try: -## filep = open("/home/pi/CubeSatSim/telem_string.txt") -## telem_string = filep.readline() -## except: -## telem_string = "" -## if (debug_mode == 1): -## print("Can't read telem_string.txt") -## print(telem_string) -## -## img = Image.open(file) -## draw = ImageDraw.Draw(img) -# draw.text((10, 10), callsign, font=font2, fill='white') -# draw.text((120, 10), telem_string, font=font2, fill='white') -## draw.text((12, 12), callsign, font=font1, fill='black') -## draw.text((10, 10), callsign, font=font1, fill='white') -## draw.text((122, 12), telem_string, font=font2, fill='black') -## draw.text((120, 10), telem_string, font=font2, fill='white') -## img.save(file) - -# command_control_check() - + camera_photo() system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/camera_out.jpg") system("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1") @@ -629,6 +625,7 @@ if __name__ == "__main__": # battery_saver_check() if (txc): + sim_failure_check() # output(pd, 1) output (ptt, 0) system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav") @@ -666,6 +663,7 @@ if __name__ == "__main__": # battery_saver_check() if (txc): + sim_failure_check() # output(pd, 1) output (ptt, 0) system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") @@ -702,6 +700,7 @@ if __name__ == "__main__": # battery_saver_check() if (txc): + sim_failure_check() # output(pd, 1) output (ptt, 0) system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") @@ -733,6 +732,7 @@ if __name__ == "__main__": # battery_saver_check() if (txc): + sim_failure_check() # output(pd, 1) output (ptt, 0) system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv.wav")