Merge pull request #384 from alanbjohnston/sim-fail-3

Sim mode failure improvements
pull/395/head
Alan Johnston 4 months ago committed by GitHub
commit facd8bfc99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

121
config

@ -210,7 +210,8 @@ function transmit_command_beacon {
exit exit
} }
echo "CubeSatSim v2.1 configuration tool" echo
echo "CubeSatSim v2.2 configuration tool"
echo echo
# echo $1 # echo $1
# echo $2 # echo $2
@ -222,8 +223,13 @@ sudo modprobe snd-aloop
if [ -z "$2" ] ; then if [ -z "$2" ] ; then
noreboot=0 noreboot=0
else else
noreboot=1 if [ "$2" = "n" ] ; then
echo "Reboot disabled" echo "Reboot disabled"
noreboot=1
else
fail=$2
fi
fi fi
# echo "No reboot" # echo "No reboot"
@ -278,7 +284,7 @@ if [ "$1" = "" ]; then
FILE=/home/pi/CubeSatSim/failure_mode.txt FILE=/home/pi/CubeSatSim/failure_mode.txt
if [ -f "$FILE" ]; then if [ -f "$FILE" ]; then
if [[ $(grep '0' $FILE) ]]; then if [[ $(grep "\-1" $FILE) ]]; then
echo "No simulated failure" echo "No simulated failure"
else else
fail=$(<$FILE) fail=$(<$FILE)
@ -314,6 +320,9 @@ if [ "$1" = "" ]; then
9) 9)
echo "Failed MPU Sensor" echo "Failed MPU Sensor"
;; ;;
# "10")
# echo "Failed FM Audio"
# ;;
*) *)
echo "Unknown Failure" echo "Unknown Failure"
;; ;;
@ -1481,32 +1490,18 @@ elif [ "$1" = "-j" ]; then
elif [ "$1" = "-M" ]; then elif [ "$1" = "-M" ]; then
# echo if [ $fail ]; then
echo "Set simulated failure mode" MODE=$fail
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
echo "Enter the failure number to set: 0 - 9"
read MODE
echo
if [ "$MODE" = "0" ]; then
echo "Setting No Simulated Failure"
else else
echo -n "Setting Simulated "
case $MODE in 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) 1)
echo "+X Solar Panel Failure" echo "+X Solar Panel Failure"
@ -1535,11 +1530,83 @@ elif [ "$1" = "-M" ]; then
9) 9)
echo "Failed MPU Sensor" echo "Failed MPU Sensor"
;; ;;
# "10")
# echo "Failed FM Audio"
# ;;
*) *)
echo "Unknown Failure" echo "Unknown Failure"
;; ;;
esac esac
fi 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
if [ "$MODE" = "0" ]; then
echo "Setting No Simulated Failure"
MODE=-1
else
case $MODE in
1)
echo "Setting Simulated +X Solar Panel Failure"
;;
2)
echo "Setting Simulated -X Solar Panel Degredation"
;;
3)
echo "Setting Simulated -Y Solar Panel Short Circuit"
;;
4)
echo "Setting Simulated Failed I2C Bus 1"
;;
5)
echo "Setting Simulated Failed I2C Bus 3"
;;
6)
echo "Setting Simulated Failed Camera"
;;
7)
echo "Setting Simulated Failed Payload"
;;
8)
echo "Setting Simulated Failed BME Sensor"
;;
9)
echo "Setting Simulated Failed MPU Sensor"
;;
# "10")
# echo "Setting Failed FM Audio"
# ;;
*)
echo "Setting No Simulated Failure"
MODE=-1
;;
esac
fi
# echo $MODE # echo $MODE
echo echo

@ -1,6 +1,6 @@
#!/bin/bash #!/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 FILE=/home/pi/CubeSatSim/sim.cfg
if [ -f "$FILE" ]; then if [ -f "$FILE" ]; then

147
main.c

@ -25,7 +25,7 @@
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
printf("\n\nCubeSatSim v2.1 starting...\n\n"); printf("\n\nCubeSatSim v2.2 starting...\n\n");
wiringPiSetup(); wiringPiSetup();
@ -276,7 +276,6 @@ int main(int argc, char * argv[]) {
txLed = 2; txLed = 2;
txLedOn = HIGH; txLedOn = HIGH;
txLedOff = LOW; txLedOff = LOW;
vB5 = TRUE;
onLed = 27; onLed = 27;
onLedOn = HIGH; onLedOn = HIGH;
onLedOff = LOW; onLedOff = LOW;
@ -295,12 +294,17 @@ int main(int argc, char * argv[]) {
fclose(config_file); fclose(config_file);
config_file = fopen("sim.cfg", "r"); config_file = fopen("sim.cfg", "r");
map[BAT2] = MINUS_Z; map[MINUS_X] = MINUS_Y;
map[BAT] = BAT2; map[PLUS_Z] = MINUS_X;
map[PLUS_Z] = BAT; map[MINUS_Y] = PLUS_Z;
map[MINUS_Z] = PLUS_Z;
snprintf(busStr, 10, "%d %d", i2c_bus1, test_i2c_bus(0)); if (access("/dev/i2c-11", W_OK | R_OK) >= 0) { // Test if I2C Bus 11 is present
voltageThreshold = 8.0; 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 // check for camera
// char cmdbuffer1[1000]; // char cmdbuffer1[1000];
@ -551,16 +555,17 @@ int main(int argc, char * argv[]) {
if (sim_mode) { if (sim_mode) {
if (loop % 10 == 0) { 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"); printf("Sim Mode Random Failure Change\n");
FILE * failure_mode_file = fopen("/home/pi/CubeSatSim/failure_mode.txt", "w"); FILE * failure_mode_file = fopen("/home/pi/CubeSatSim/failure_mode.txt", "w");
fprintf(failure_mode_file, "%d", failureMode); fprintf(failure_mode_file, "%d", failureMode);
fclose(failure_mode_file); fclose(failure_mode_file);
} }
} }
else // else
{ // {
failureMode = OFF; // failureMode = OFF;
FILE * failure_mode_file = fopen("/home/pi/CubeSatSim/failure_mode.txt", "r"); FILE * failure_mode_file = fopen("/home/pi/CubeSatSim/failure_mode.txt", "r");
if (failure_mode_file != NULL) { if (failure_mode_file != NULL) {
char failure_string[10]; char failure_string[10];
@ -571,9 +576,9 @@ int main(int argc, char * argv[]) {
} }
} else { } else {
failureMode = FAIL_NONE; failureMode = FAIL_NONE;
printf("No simulated failure."); printf("No simulated failure.\n");
}
} }
// }
{ {
int count1; int count1;
@ -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 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; int count1;
char * token; char * token;
@ -748,7 +753,7 @@ int main(int argc, char * argv[]) {
strcpy(sensor_payload, buffer2); // restore sensor_payload after strtok operation strcpy(sensor_payload, buffer2); // restore sensor_payload after strtok operation
if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) { 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++) { for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) {
if (sensor[count1] < sensor_min[count1]) if (sensor[count1] < sensor_min[count1])
sensor_min[count1] = sensor[count1]; sensor_min[count1] = sensor[count1];
@ -825,8 +830,7 @@ int main(int argc, char * argv[]) {
// end of simulated telemetry // end of simulated telemetry
} }
else {
}
FILE * cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); FILE * cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (cpuTempSensor) { if (cpuTempSensor) {
// double cpuTemp; // double cpuTemp;
@ -1210,6 +1214,7 @@ void get_tlm_fox() {
int i; int i;
long int sync = syncWord; long int sync = syncWord;
int cam = ON;
smaller = (int) (S_RATE / (2 * freq_Hz)); smaller = (int) (S_RATE / (2 * freq_Hz));
@ -1255,8 +1260,8 @@ void get_tlm_fox() {
printf("+X Solar Simulated Failure\n"); printf("+X Solar Simulated Failure\n");
} }
if (failureMode == FAIL_DEGRADE) { if (failureMode == FAIL_DEGRADE) {
voltage[map[MINUS_X]] = voltage[MINUS_X] * 0.5; voltage[map[MINUS_X]] = voltage[map[MINUS_X]] * 0.5;
current[map[MINUS_X]] = current[MINUS_X] * 0.5; current[map[MINUS_X]] = current[map[MINUS_X]] * 0.5;
printf("-X Solar Deg Simulated Failure\n"); printf("-X Solar Deg Simulated Failure\n");
} }
if (failureMode == FAIL_SHORT) { if (failureMode == FAIL_SHORT) {
@ -1285,14 +1290,14 @@ void get_tlm_fox() {
current[map[PLUS_Z]] = 0.0; current[map[PLUS_Z]] = 0.0;
printf("I2C Bus 3 Simulated Failure!\n"); printf("I2C Bus 3 Simulated Failure!\n");
} }
if (failureMode == FAIL_CAMERA) {
camera = OFF;
printf("Camera Simulated Failure!\n");
}
if (failureMode == FAIL_PAYLOAD) { if (failureMode == FAIL_PAYLOAD) {
payload = OFF; payload = OFF;
printf("Payload Simulated Failure!\n"); printf("Payload Simulated Failure!\n");
} }
if (failureMode == FAIL_CAMERA) {
cam = OFF;
printf("Camera Simulated Failure!\n");
}
if (mode == FSK) if (mode == FSK)
id = 7; id = 7;
@ -1434,23 +1439,12 @@ void get_tlm_fox() {
// encodeB(b, 1 + head_offset, batt_b_v); // encodeB(b, 1 + head_offset, batt_b_v);
encodeA(b, 3 + head_offset, batt_c_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 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 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, 7 + head_offset, (int)(sensor[ACCEL_Z] * 100 + 0.5) + 2048); // Zaccel
}
encodeA(b, 9 + head_offset, battCurr); 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) { if (mode == FSK) {
@ -1506,33 +1500,21 @@ void get_tlm_fox() {
encodeA(b_max, 39 + head_offset, (int)(other_max[IHU_TEMP] * 10 + 0.5)); 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); 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 (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 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, 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); 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); 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); 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, 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, 49 + head_offset, (int)(sensor_max[XS1] * 10 + 0.5) + 2048);
encodeB(b_max, 10 + head_offset, (int)(sensor_max[TEMP] * 10 + 0.5)); 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, 45 + head_offset, (int)(sensor_max[HUMI] * 10 + 0.5));
}
encodeA(b_max, 48 + head_offset, (int)(sensor_max[DTEMP] * 10 + 0.5) + 2048); encodeA(b_max, 48 + head_offset, (int)(sensor_max[DTEMP] * 10 + 0.5) + 2048);
encodeB(b_max, 49 + head_offset, (int)(sensor_max[XS1])); encodeB(b_max, 49 + head_offset, (int)(sensor_max[XS1]));
@ -1551,17 +1533,7 @@ void get_tlm_fox() {
encodeA(b_max, 48 + head_offset, 2048); encodeA(b_max, 48 + head_offset, 2048);
// encodeB(b_max, 49 + 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)); 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)); 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)); encodeA(b_min, 15 + head_offset, (int)(voltage_min[map[PLUS_Z]] * 100));
@ -1585,10 +1557,7 @@ void get_tlm_fox() {
encodeB(b_min, 37 + head_offset, (int)(other_min[RSSI] + 0.5) + 2048); 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)); 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 (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 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 encodeA(b_min, 6 + head_offset, (int)(sensor_min[ACCEL_Y] * 100 + 0.5) + 2048); // Yaccel
@ -1596,22 +1565,11 @@ void get_tlm_fox() {
encodeB(b_min, 40 + head_offset, (int)(sensor_min[GYRO_X] + 0.5) + 2048); 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); 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); 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 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, 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)); 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, 45 + head_offset, (int)(sensor_min[HUMI] * 10 + 0.5));
}
encodeA(b_min, 48 + head_offset, (int)(sensor_min[DTEMP] * 10 + 0.5) + 2048); 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); // 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); encodeA(b_min, 48 + head_offset, 2048);
// encodeB(b_min, 49 + 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); encodeA(b, 30 + head_offset, BAT2Voltage);
encodeB(b, 31 + head_offset, ((int)(other[SPIN] * 10)) + 2048); 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 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, 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, 39 + head_offset, (int)(other[TEMP] * 10 + 0.5));
}
encodeA(b, 36 + head_offset, Resets); encodeA(b, 36 + head_offset, Resets);
encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5) + 2048); 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); encodeB(b, 40 + head_offset, (int)(sensor[GYRO_X] + 0.5) + 2048);
encodeA(b, 42 + head_offset, (int)(sensor[GYRO_Y] + 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); 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); encodeA(b, 48 + head_offset, (int)(sensor[DTEMP] * 10 + 0.5) + 2048);
encodeB(b, 49 + head_offset, (int)(sensor[XS1])); encodeB(b, 49 + head_offset, (int)(sensor[XS1]));
encodeA(b, 0 + head_offset, (int)(sensor[XS2])); encodeA(b, 0 + head_offset, (int)(sensor[XS2]));
encodeB(b, 1 + head_offset, (int)(sensor[XS3])); 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); encodeB(b, 46 + head_offset, BAT2Current);
encodeA(b, 39 + head_offset, (int)(other[IHU_TEMP] * 10 + 0.5)); 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 + // 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; // (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 + 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); encodeA(b, 51 + head_offset, status);
encodeB(b, 52 + head_offset, rxAntennaDeployed + txAntennaDeployed * 2 + c2cStatus * 4); encodeB(b, 52 + head_offset, rxAntennaDeployed + txAntennaDeployed * 2 + c2cStatus * 4);

@ -122,7 +122,7 @@ FILE *image_file;
#define TXCOMMAND 12 #define TXCOMMAND 12
#define FAIL_COUNT 10 #define FAIL_COUNT 10
#define FAIL_NONE 0 #define FAIL_NONE -1
#define FAIL_SOLAR 1 #define FAIL_SOLAR 1
#define FAIL_DEGRADE 2 #define FAIL_DEGRADE 2
#define FAIL_SHORT 3 #define FAIL_SHORT 3
@ -169,7 +169,7 @@ float sleepTime;
unsigned int sampleTime = 0; unsigned int sampleTime = 0;
int frames_sent = 0; int frames_sent = 0;
int cw_id = ON; 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.6, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100;
float voltageThreshold = 3.5, 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; float latitude = 39.027702f, longitude = -77.078064f;

@ -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[MINUS_X] = MINUS_Y;
map[PLUS_Z] = MINUS_X; map[PLUS_Z] = MINUS_X;
map[MINUS_Y] = PLUS_Z; map[MINUS_Y] = PLUS_Z;

@ -12,6 +12,30 @@ from PIL import Image, ImageDraw, ImageFont, ImageColor
import serial import serial
import random 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(): def battery_saver_check():
try: try:
global txc global txc
@ -95,6 +119,8 @@ def increment_mode():
print("can't write to .mode file") print("can't write to .mode file")
def camera_photo(): def camera_photo():
global cam_fail
sim_failure_check()
system("sudo rm /home/pi/CubeSatSim/camera_out.jpg") system("sudo rm /home/pi/CubeSatSim/camera_out.jpg")
stored_image = False stored_image = False
try: try:
@ -102,6 +128,10 @@ def camera_photo():
f = open("/home/pi/CubeSatSim/camera_out.jpg") f = open("/home/pi/CubeSatSim/camera_out.jpg")
f.close() f.close()
print("Photo taken") 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: except:
system("cp /home/pi/CubeSatSim/sstv//sstv_image_2_320_x_256.jpeg /home/pi/CubeSatSim/camera_out.jpg") system("cp /home/pi/CubeSatSim/sstv//sstv_image_2_320_x_256.jpeg /home/pi/CubeSatSim/camera_out.jpg")
print("Using stored image") print("Using stored image")
@ -130,7 +160,7 @@ def camera_photo():
draw.text((120, 10), telem_string, font=font2, fill='white') draw.text((120, 10), telem_string, font=font2, fill='white')
img.save(file) img.save(file)
print("CubeSatSim v2.1 transmit.py starting...") print("CubeSatSim v2.2 transmit.py starting...")
pd = 21 pd = 21
ptt = 20 ptt = 20
@ -446,6 +476,7 @@ if __name__ == "__main__":
# #
# battery_saver_check() # battery_saver_check()
if (txc): if (txc):
sim_failure_check()
# output(pd, 1) # output(pd, 1)
sleep(0.1) # add delay before transmit sleep(0.1) # add delay before transmit
output (ptt, 0) output (ptt, 0)
@ -472,16 +503,7 @@ if __name__ == "__main__":
print("Ready for next packet!") print("Ready for next packet!")
sleep(0.5) 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: except:
# command_control_check() # command_control_check()
sleep(1) sleep(1)
@ -508,6 +530,7 @@ if __name__ == "__main__":
output(txLed, txLedOn) output(txLed, txLedOn)
if (txc): if (txc):
sim_failure_check()
# output (pd, 1) # output (pd, 1)
sleep(0.3) sleep(0.3)
output (ptt, 0) output (ptt, 0)
@ -569,6 +592,7 @@ if __name__ == "__main__":
# battery_saver_check() # battery_saver_check()
if (txc): if (txc):
sim_failure_check()
# output(pd, 1) # output(pd, 1)
output (ptt, 0) output (ptt, 0)
system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav") system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav")
@ -588,34 +612,6 @@ if __name__ == "__main__":
while 1: while 1:
# command_control_check() # command_control_check()
camera_photo() 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()
system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/camera_out.jpg") 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") system("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1")
@ -629,6 +625,7 @@ if __name__ == "__main__":
# battery_saver_check() # battery_saver_check()
if (txc): if (txc):
sim_failure_check()
# output(pd, 1) # output(pd, 1)
output (ptt, 0) output (ptt, 0)
system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav") 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() # battery_saver_check()
if (txc): if (txc):
sim_failure_check()
# output(pd, 1) # output(pd, 1)
output (ptt, 0) output (ptt, 0)
system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") 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() # battery_saver_check()
if (txc): if (txc):
sim_failure_check()
# output(pd, 1) # output(pd, 1)
output (ptt, 0) output (ptt, 0)
system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav") 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() # battery_saver_check()
if (txc): if (txc):
sim_failure_check()
# output(pd, 1) # output(pd, 1)
output (ptt, 0) output (ptt, 0)
system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv.wav") system("aplay -D plughw:CARD=" + card + ",DEV=0 /home/pi/CubeSatSim/sstv.wav")

Loading…
Cancel
Save

Powered by TurnKey Linux.