Merge pull request #277 from alanbjohnston/beta-v1.3.1

Beta v1.3.1
sr-frs-aprs-payload-minute-1.3
Alan Johnston 2 years ago committed by GitHub
commit 4171a4a107
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,7 +36,7 @@ To get the software follow these steps:
`cd CubeSatSim`
`git checkout master`
`git checkout sr-frs-rx`
You are now ready to install the software using this script in the CubeSatSim directory:

140
config

@ -1,6 +1,7 @@
#!/bin/bash
echo "CubeSatSim v1.2 configuration tool"
echo "CubeSatSim v1.3b configuration tool"
echo
if [ "$2" = "-n" ]; then
norestart=1
@ -26,7 +27,7 @@ if [ "$1" = "" ]; then
else
echo
fi
echo
value=`cat /home/pi/CubeSatSim/sim.cfg`
echo "$value" > /dev/null
set -- $value
@ -38,48 +39,71 @@ if [ "$1" = "" ]; then
# sim="no"
echo "Simulated Telemetry is OFF"
fi
echo
echo "Current command count is:"
cat /home/pi/CubeSatSim/command_count.txt
echo
echo
echo "Current beacon transmit mode is:"
cat /home/pi/CubeSatSim/command_tx
echo
echo -e "Current sim.cfg configuration file:"
# echo
echo
echo $1 $2 $3 $4 $5
echo
echo "To change, include an OPTION"
echo "To see options, type config -h"
# echo
# echo "To change, include an OPTION"
# echo
set -- "-h"
# set -- "-h"
fi
if [ "$1" = "-i" ]; then
echo "Restarting CubeSatSim"
sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-a" ]; then
echo "changing CubeSatSim to AFSK mode"
sudo echo "a" > /home/pi/CubeSatSim/.mode
sudo systemctl restart cubesatsim
sudo echo "a" > /home/pi/CubeSatSim/.mode
sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
echo "rebooting"
sudo reboot now
# sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-m" ]; then
echo "changing CubeSatSim to CW mode"
sudo echo "m" > /home/pi/CubeSatSim/.mode
sudo systemctl restart cubesatsim
sudo echo "m" > /home/pi/CubeSatSim/.mode
sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
echo "rebooting"
sudo reboot now
# sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-f" ]; then
echo "changing CubeSatSim to FSK mode"
sudo echo "f" > /home/pi/CubeSatSim/.mode
sudo systemctl restart cubesatsim
sudo echo "f" > /home/pi/CubeSatSim/.mode
if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
echo "rebooting"
sudo reboot now
# sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-b" ]; then
echo "changing CubeSatSim to BPSK mode"
sudo echo "b" > /home/pi/CubeSatSim/.mode
sudo systemctl restart cubesatsim
sudo echo "b" > /home/pi/CubeSatSim/.mode
if ! grep -q force_turbo=1 /boot/config.txt ; then sudo sh -c 'echo "force_turbo=1" >> /boot/config.txt'; fi
echo "rebooting"
sudo reboot now
# sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-s" ]; then
echo "changing CubeSatSim to SSTV mode"
sudo echo "s" > /home/pi/CubeSatSim/.mode
sudo systemctl restart cubesatsim
sudo echo "s" > /home/pi/CubeSatSim/.mode
sudo sed -i ':a;N;$!ba;s/\nforce_turbo=1//g' /boot/config.txt
echo "rebooting"
sudo reboot now
# sudo systemctl restart cubesatsim
exit
elif [ "$1" = "-h" ]; then
echo "config OPTION"
@ -97,6 +121,10 @@ elif [ "$1" = "-h" ]; then
echo " -t Change the Simulated Telemetry setting in sim.cfg"
echo " -r Change the Resets Count in the configuration file sim.cfg"
echo " -l Change the Latitude and Longitude in the configuration file sim.cfg"
echo " -S Scan both I2C buses on the Raspberry Pi"
echo " -C Clear logs"
echo " -T Change command state"
echo " -R Change the Commands Count in the file command_count.txt"
echo
exit
@ -314,6 +342,84 @@ elif [ "$1" = "-l" ]; then
echo
sudo systemctl restart cubesatsim
fi
elif [ "$1" = "-S" ]; then
echo
echo "Scan both I2C buses on the Raspberry Pi"
echo
echo "I2C Bus 1"
echo
i2cdetect -y 1
echo
echo "I2C Bus 1"
echo
i2cdetect -y 3
echo
elif [ "$1" = "-C" ]; then
echo
echo "Clear logs"
echo
sudo systemctl stop cubesatsim
sudo systemctl stop rpitx
sudo journalctl --vacuum-time=1s
sudo systemctl reboot now
echo "rebooting"
elif [ "$1" = "-T" ]; then
echo
echo "Change command state"
echo
echo "Current command state is:"
cat /home/pi/CubeSatSim/command_tx
echo
echo "Do you want to set beacon transmit to ON (y/n) "
read reset
echo
if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then
sudo sed -i 's/False/True/g' /home/pi/CubeSatSim/command_tx
echo "Command state set to True to enable beacon"
echo "rebooting"
sudo reboot now
else
sudo sed -i 's/True/False/g' /home/pi/CubeSatSim/command_tx
echo "Command state set to False to disable beacon"
echo "rebooting"
sudo reboot now
fi
elif [ "$1" = "-R" ]; then
echo
echo "Reset the Commands Count in the file command_count.txt"
echo
echo "Current commands count is:"
cat /home/pi/CubeSatSim/commands_count.txt
echo
echo "Do you want to reset the commands count to zero (y/n) "
read reset
echo
if [ "$reset" = "y" ] || [ "$reset" = "yes" ] ; then
sudo rm /home/pi/CubeSatSim/command_count.txt
echo "Commands count reset to 0"
echo "0\n" > /home/pi/CubeSatSim/command_count.txt
else
echo "Commands count not reset"
fi
fi
# sudo systemctl restart cubesatsim

@ -1,6 +1,6 @@
#!/bin/bash
echo -e "\ninstallation script for CubeSatSim v1.2\n"
echo -e "\ninstallation script for CubeSatSim v1.3b\n"
FILE=/home/pi/CubeSatSim/sim.cfg
if [ -f "$FILE" ]; then
@ -10,6 +10,22 @@ else
echo "AMSAT 1 0.0 0.0" > /home/pi/CubeSatSim/sim.cfg
fi
FILE=/home/pi/CubeSatSim/command_tx
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "creating $FILE"
echo "True\n" > /home/pi/CubeSatSim/command_tx
fi
FILE=/home/pi/CubeSatSim/command_count.txt
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "creating $FILE"
echo "0\n" > /home/pi/CubeSatSim/command_count.txt
fi
cd
CubeSatSim/config -c -n
@ -72,7 +88,7 @@ git clone https://github.com/alanbjohnston/pi-power-button.git
cd pi-power-button
git checkout master
git checkout reboot-mode-change
./script/install
@ -91,6 +107,16 @@ cp /home/pi/CubeSatSim/sstv/sstv_image_1_320_x_256.jpg /home/pi/CubeSatSim/sstv_
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
git clone https://github.com/alanbjohnston/rpitx.git
cd rpitx
./install.sh
cd
cd
@ -119,7 +145,82 @@ sudo raspi-config nonint do_legacy 0
## sudo sed -i 's/console=serial0,115200 //g' /boot/cmdline.txt
sudo sed -i 's/console=serial0,115200 //g' /boot/cmdline.txt
sudo sed -i 's/#dtparam=i2c_arm=on/dtparam=i2c_arm=on/g' /boot/config.txt
if [[ $(grep 'dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24' /boot/config.txt) ]]; then
echo "dtoverlay=i2c-gpio already in /boot/config.txt"
else
echo "adding dtoverlay=i2c-gpio to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24" >> /boot/config.txt'
fi
if [[ $(grep 'enable_uart=1' /boot/config.txt) ]]; then
echo "enable_uart=1 already in /boot/config.txt"
else
echo "adding enable_uart=1 to /boot/config.txt"
sudo sh -c 'echo "\nenable_uart=1" >> /boot/config.txt'
fi
if [[ $(grep 'dtoverlay=disable-bt' /boot/config.txt) ]]; then
echo "dtoverlay=disable-bt already in /boot/config.txt"
else
echo "adding dtoverlay=disable-bt to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=disable-bt" >> /boot/config.txt'
fi
if [[ $(grep 'dtoverlay=dwc2' /boot/config.txt) ]]; then
echo "dtoverlay=dwc2 aalready in /boot/config.txt"
else
echo "adding dtoverlay=dwc2 to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=dwc2" >> /boot/config.txt'
fi
if [[ $(grep 'modules-load=dwc2,g_ether' /boot/cmdline.txt) ]]; then
echo "modules-load=dwc2,g_ether already in /boot/cmdline.txt"
else
echo "adding modules-load=dwc2,g_ether to /boot/cmdline.txt"
sudo sed -i 's/ rootwait/ rootwait modules-load=dwc2,g_ether/g' /boot/cmdline.txt
fi
if [[ $(grep 'dtparam=audio=on' /boot/config.txt) ]]; then
echo "dtparam=audio=on already in /boot/config.txt"
else
echo "adding dtparam=audio=on to /boot/config.txt"
sudo sh -c 'echo "\ndtparam=audio=on" >> /boot/config.txt'
fi
if [[ $(grep 'dtoverlay=audremap,enable_jack=on' /boot/config.txt) ]]; then
echo "dtoverlay=audremap,enable_jack=on already in /boot/config.txt"
else
echo "adding dtoverlay=audremap,enable_jack=on to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'
fi
if [[ $(grep 'dtoverlay=pwm,pin=18,func=2' /boot/config.txt) ]]; then
echo "dtoverlay=pwm,pin=18,func=2 already in /boot/config.txt"
else
echo "adding to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'
fi
if [[ $(grep 'disable_splash=1 ' /boot/config.txt) ]]; then
echo "disable_splash=1 already in /boot/config.txt"
else
echo "adding to /boot/config.txt"
sudo sh -c 'echo "\ndisable_splash=1" >> /boot/config.txt'
fi
if [[ $(grep 'boot_delay=0' /boot/config.txt) ]]; then
echo "boot_delay=0 already in /boot/config.txt"
else
echo "adding to /boot/config.txt"
sudo sh -c 'echo "\nboot_delay=0" >> /boot/config.txt'
fi
sudo sh -c 'echo "\n" >> /boot/config.txt'
echo "Would you like to reboot to complete the installation (y/n)?"
read -r ANS

244
main.c

@ -6,7 +6,7 @@
*
* Portions Copyright (C) 2018 Jonathan Brandenburg
*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistributVe it and/or modify
* it under the terms of the GNU General Public License as published by
* (at your option) any later version.
*
@ -20,9 +20,10 @@
*/
#include "main.h"
// #define HAB // uncomment to change APRS icon from Satellite to Balloon
int main(int argc, char * argv[]) {
@ -42,7 +43,7 @@ int main(int argc, char * argv[]) {
printf("Pi Zero 2 detected");
}
printf("\n\nCubeSatSim v1.2 starting...\n\n");
printf("\n\nCubeSatSim v1.3b starting...\n\n");
FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r");
pclose(rpitx_stop);
@ -155,7 +156,7 @@ int main(int argc, char * argv[]) {
latitude = lat_file;
longitude = long_file;
printf("Lat/Long %f %f\n", latitude, longitude);
printf("Lat/Long in APRS DDMM.MM format: %f/%f\n", toAprsFormat(latitude), toAprsFormat(longitude));
printf("Lat/Long in APRS DDMM.MM format: %07.2f/%08.2f\n", toAprsFormat(latitude), toAprsFormat(longitude));
newGpsTime = millis();
} else { // set default
@ -391,6 +392,7 @@ int main(int argc, char * argv[]) {
}
if ((i2c_bus3 == OFF) || (sim_mode == TRUE)) {
// if (sim_mode == TRUE) {
sim_mode = TRUE;
@ -693,8 +695,13 @@ int main(int argc, char * argv[]) {
if (payload == ON) { // -55
STEMBoardFailure = 0;
printf("get_payload_status: %d \n", get_payload_serial(FALSE)); // not debug
fflush(stdout);
printf("String: %s\n", buffer2);
fflush(stdout);
strcpy(sensor_payload, buffer2);
/*
char c;
unsigned int waitTime;
int i, end, trys = 0;
@ -728,8 +735,13 @@ int main(int argc, char * argv[]) {
// sensor_payload[i++] = '\n';
sensor_payload[i] = '\0';
printf(" Response from STEM Payload board: %s\n", sensor_payload);
sleep(0.1); // added sleep between loops
}
*/
printf(" Response from STEM Payload board: %s\n", sensor_payload);
if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) // only process if valid payload response
{
int count1;
@ -737,6 +749,7 @@ int main(int argc, char * argv[]) {
const char space[2] = " ";
token = strtok(sensor_payload, space);
// printf("token: %s\n", token);
for (count1 = 0; count1 < 17; count1++) {
if (token != NULL) {
sensor[count1] = (float) atof(token);
@ -771,7 +784,7 @@ int main(int argc, char * argv[]) {
longitude += rnd_float(-0.05, 0.05) / 100.0; // was .05
latitude += rnd_float(-0.05, 0.05) / 100.0;
printf("GPS Location with Rnd: %f, %f \n", latitude, longitude);
printf("GPS Location with Rnd: APRS %7.2f, %08.2f \n", toAprsFormat(latitude), toAprsFormat(longitude));
printf("GPS Location with Rnd: APRS %07.2f, %08.2f \n", toAprsFormat(latitude), toAprsFormat(longitude));
newGpsTime = millis();
}
@ -809,11 +822,17 @@ int main(int argc, char * argv[]) {
FILE * file6 = popen("/home/pi/CubeSatSim/log > shutdown_log.txt", "r");
pclose(file6);
sleep(40);
sleep(80);
file6 = popen("sudo shutdown -h now > /dev/null 2>&1", "r");
pclose(file6);
sleep(10);
}
FILE * fp = fopen("/home/pi/CubeSatSim/telem_string.txt", "w");
printf("Writing telem_string.txt\n");
fprintf(fp, "Vbatt = %4.2f\n", batteryVoltage);
fclose(fp);
/**/
// sleep(1); // Delay 1 second
ctr = 0;
@ -977,9 +996,9 @@ void get_tlm(void) {
if (mode != CW) {
// 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", toAprsFormat(latitude), 'N'); // lat
sprintf(header_lat, "%07.2f%c", toAprsFormat(latitude), 'N'); // lat
else
sprintf(header_lat, "%7.2f%c", toAprsFormat(latitude) * (-1.0), 'S'); // lat
sprintf(header_lat, "%07.2f%c", toAprsFormat(latitude) * (-1.0), 'S'); // lat
if (longitude > 0)
sprintf(header_long, "%08.2f%c", toAprsFormat(longitude) , 'E'); // long
else
@ -988,8 +1007,12 @@ void get_tlm(void) {
if (ax5043)
sprintf(header_str2b, "=%s%c%sShi hi ", header_lat, 0x5c, header_long); // add APRS lat and long
else
// sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long
sprintf(header_str2b, "=%s%c%sOhi hi ", header_lat, 0x2f, header_long); // add APRS lat and long with Balloon
#ifdef HAB
sprintf(header_str2b, "=%s%c%sOhi hi ", header_lat, 0x2f, header_long); // add APRS lat and long with Balloon HAB icon
#else
sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long with Satellite icon
#endif
printf("\n\nString is %s \n\n", header_str2b);
strcat(str, header_str2b);
} else {
@ -1007,12 +1030,12 @@ void get_tlm(void) {
channel, upper_digit(tlm[channel][4]), lower_digit(tlm[channel][4]));
// printf("%s",tlm_str);
if (mode != AFSK)
// if (mode != AFSK)
strcat(str, tlm_str);
}
// read payload sensor if available
/*
char sensor_payload[500];
if (payload == ON) {
@ -1048,6 +1071,7 @@ void get_tlm(void) {
sensor_payload[i++] = ' ';
// sensor_payload[i++] = '\n';
sensor_payload[i] = '\0';
printf(" Response from STEM Payload board: %s\n", sensor_payload);
sleep(0.1); // added sleep between loops
}
@ -1055,7 +1079,15 @@ void get_tlm(void) {
if (mode != CW)
strcat(str, sensor_payload); // append to telemetry string for transmission
}
*/
strcpy(sensor_payload, buffer2);
printf(" Response from STEM Payload board:: %s\n", sensor_payload);
// printf(" Str so far: %s\n", str);
if (mode != CW) {
strcat(str, sensor_payload); // append to telemetry string for transmission
// printf(" Str so far: %s\n", str);
}
if (mode == CW) {
char cw_str2[1000];
@ -1485,6 +1517,16 @@ void get_tlm_fox() {
encodeA(b, 48 + head_offset, (int)(sensor[XS1] * 10 + 0.5) + 2048);
encodeB(b, 49 + head_offset, (int)(sensor[XS2] * 10 + 0.5) + 2048);
FILE * command_count_file = fopen("/home/pi/CubeSatSim/command_count.txt", "r");
if (command_count_file != NULL) {
char count_string[10];
if ( (fgets(count_string, 10, command_count_file)) != NULL)
groundCommandCount = atoi(count_string);
} else
printf("Error opening command_count.txt!\n");
fclose(command_count_file);
printf("Command count: %d\n", groundCommandCount);
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;
@ -1495,6 +1537,10 @@ void get_tlm_fox() {
txAntennaDeployed = 1;
printf("TX Antenna Deployed!\n");
}
if (rxAntennaDeployed == 0) {
rxAntennaDeployed = 1;
printf("RX Antenna Deployed!\n");
}
if (mode == BPSK) { // wod field experiments
unsigned long val = 0xffff;
@ -1950,3 +1996,171 @@ float toAprsFormat(float input) {
float output = dd * 100 + mm1 + (float)mm2 * 0.01;
return(output);
}
//#define GET_IMAGE_DEBUG
//#define DEBUG
//#define PICOW true
//int led_pin = LED_BUILTIN;
/*
void loop() {
char input_file[] = "/cam.jpg";
char output_file[] = "/cam.bin";
get_image_file();
Serial.println("Got image from ESP-32-CAM!");
delay(1000);
}
*/
int get_payload_serial(int debug_camera) {
index1 = 0;
flag_count = 0;
start_flag_detected = FALSE;
start_flag_complete = FALSE;
end_flag_detected = FALSE;
jpeg_start = 0;
// #ifdef GET_IMAGE_DEBUG
if (debug_camera)
printf("Received from Payload:\n");
// #endif
finished = FALSE;
unsigned long time_start = millis();
while ((!finished) && ((millis() - time_start) < CAMERA_TIMEOUT)) {
if (serialDataAvail(uart_fd)) {
char octet = (char) serialGetchar(uart_fd);
printf("%c", octet);
fflush(stdout);
// if (Serial2.available()) { // If anything comes in Serial2
// byte octet = Serial2.read();
/// if ((!start_flag_detected) && (debug_camera))
/// Serial.write(octet);
if (start_flag_complete) {
// printf("Start flag complete detected\n");
buffer2[index1++] = octet;
if (octet == end_flag[flag_count]) { // looking for end flag
// if (end_flag_detected) {
flag_count++;
#ifdef GET_IMAGE_DEBUG
// if (debug_camera)
printf("Found part of end flag!\n");
#endif
if (flag_count >= strlen(end_flag)) { // complete image
/// buffer2[index1++] = octet;
// Serial.println("\nFound end flag");
// Serial.println(octet, HEX);
/// while(!Serial2.available()) { } // Wait for another byte
// octet = Serial2.read();
// buffer2[index1++] = octet;
// Serial.println(octet, HEX);
// while(!Serial2.available()) { } // Wait for another byte
/// int received_crc = Serial2.read();
// buffer2[index1++] = octet;
/*
Serial.print("\nFile length: ");
Serial.println(index1 - (int)strlen(end_flag));
// index1 -= 1; // 40;
// Serial.println(buffer2[index1 - 1], HEX);
// int received_crc = buffer2[index1];
// index1 -= 1;
uint8_t * data = (uint8_t *) &buffer2[0];
#ifdef GET_IMAGE_DEBUG
Serial.println(buffer2[0], HEX);
Serial.println(buffer2[index1 - 1], HEX);
Serial.println(index1);
#endif
if (debug_camera) {
Serial.print("\nCRC received:");
Serial.println(received_crc, HEX);
}
int calculated_crc = CRC8.smbus(data, index1);
// Serial.println(calculated_crc, HEX);
if (received_crc == calculated_crc)
Serial.println("CRC check succeeded!");
else
Serial.println("CRC check failed!");
*/
// index1 -= 40;
index1 -= strlen(end_flag);
buffer2[index1++] = 0;
printf(" Payload length: %d \n",index1);
// write_jpg();
finished = TRUE;
index1 = 0;
start_flag_complete = FALSE;
start_flag_detected = FALSE; // get ready for next image
end_flag_detected = FALSE;
flag_count = 0;
// delay(6000);
}
} else {
if (flag_count > 1)
printf("Resetting. Not end flag.\n");
flag_count = 0;
}
/// buffer2[index1++] = octet;
//#ifdef GET_IMAGE_DEBUG
if (debug_camera) {
char hexValue[5];
if (octet != 0x66) {
sprintf(hexValue, "%02X", octet);
// printf(hexValue);
} else {
// Serial.println("\n********************************************* Got a 66!");
printf("66");
}
// Serial.write(octet);
}
//#endif
if (index1 > 1000) {
index1 = 0;
printf("Resetting index!\n");
}
// }
} else if (octet == start_flag[flag_count]) { // looking for start flag
start_flag_detected = TRUE;
flag_count++;
#ifdef GET_IMAGE_DEBUG
printf("Found part of start flag! \n");
#endif
if (flag_count >= strlen(start_flag)) {
flag_count = 0;
start_flag_complete = TRUE;
#ifdef GET_IMAGE_DEBUG
printf("Found all of start flag!\n");
#endif
}
} else { // not the flag, keep looking
start_flag_detected = FALSE;
flag_count = 0;
#ifdef GET_IMAGE_DEBUG
printf("Resetting. Not start flag.\n");
#endif
}
}
// Serial.println("writing to Serial2");
}
if (debug_camera)
printf("\nComplete\n");
fflush(stdout);
return(finished);
}

@ -129,7 +129,7 @@ unsigned int sampleTime = 0;
int frames_sent = 0;
int cw_id = ON;
int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF;
float voltageThreshold = 3.5, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100;
float voltageThreshold = 3.25, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100;
float latitude = 39.027702f, longitude = -77.078064f;
float lat_file, long_file;
double cpuTemp;
@ -153,3 +153,22 @@ char src_addr[5] = "";
char dest_addr[5] = "APCSS";
float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[17], sensor_min[17], other_max[3], other_min[3];
int get_payload_serial(int debug_camera);
int finished = FALSE;
//char buffer2[100001];
char buffer2[2000];
int index1 = 0;
//char start_flag[] = "3d99de816e5ad7742b61a37c39141783";
char start_flag[] = "_START_FLAG_";
//char end_flag[] = "f681a5c52351befe0e3524eb1a40f14b7803317a";
char end_flag[] = "_END_FLAG_";
int flag_count = 0;
int start_flag_detected = FALSE;
int start_flag_complete = FALSE;
int end_flag_detected = FALSE;
int jpeg_start = 0;
#define CAMERA_TIMEOUT 10000 // 20000 // Camera timeout in milli seconds

@ -8,17 +8,134 @@ from time import sleep
#import os
import sys
from os import system
from PIL import Image, ImageDraw, ImageFont, ImageColor
print("CubeSatSim v1.1 rpitx.py starting...")
def increment_mode():
print("increment mode")
powerPin = 16
try:
file = open("/home/pi/CubeSatSim/.mode")
mode = file.read(1)
except:
# mode = "f"
if (debug_mode == 1):
print("Can't open .mode file") # , defaulting to FSK")
print("Mode is: ")
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)
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)
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)
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)
sleep(2.5)
else:
mode = 'a'
GPIO.output(powerPin, 0) # blink one time
sleep(0.1)
GPIO.output(powerPin, 1)
sleep(2.5)
try:
file = open("/home/pi/CubeSatSim/.mode", "w")
# count_string = str(command_count)
file.write(mode)
file.close()
print(".mode file written")
GPIO.setwarnings(False)
GPIO.output(txLed, 0)
GPIO.output(powerPin, 0)
print("sudo reboot -h now")
GPIO.setwarnings(False)
GPIO.setup(powerPin, GPIO.OUT)
GPIO.output(powerPin, 0);
system("reboot -h now")
# release = True;
sleep(10);
except:
print("can't write to .mode file")
print("CubeSatSim v1.3b rpitx.py starting...")
pd = 21
ptt = 20
txc = 7
squelch = 6
green = 16
command_tx = True
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(green, GPIO.OUT)
GPIO.setup(squelch, GPIO.IN)
transmit = False
if GPIO.input(12) == False:
@ -54,10 +171,17 @@ GPIO.setwarnings(False)
GPIO.setup(txLed, GPIO.OUT)
GPIO.setup(pd, GPIO.OUT)
output(pd, 1)
#output(pd, 1)
output(pd, 0)
GPIO.setup(ptt, GPIO.OUT)
output (ptt, 1)
txc = False
if GPIO.input(7) == False:
print("TXC is present")
txc = True;
else:
print("TXC not present")
output(txLed, txLedOn)
sleep(1)
output(txLed, txLedOff)
@ -88,6 +212,35 @@ if __name__ == "__main__":
print("Mode is: ")
print(mode)
try:
file = open("/home/pi/CubeSatSim/command_tx")
char = file.read(1)
if (char == 'T'):
command_tx = True
else:
command_tx = False
except:
command_tx = True
if (debug_mode == 1):
print("Can't open command_tx file, defaulting to True")
print("Command_tx: ")
print(command_tx)
try:
file = open("/home/pi/CubeSatSim/command_count.txt", "r")
string = file.read()
command_count = int(string)
except:
command_count = 0
if (debug_mode == 1):
print("Can't open command_count file, setting to 0")
file = open("/home/pi/CubeSatSim/command_count.txt", "w")
count_string = str(command_count)
file.write(count_string)
file.close()
print("Command_count: ")
print(command_count)
try:
file = open("/home/pi/CubeSatSim/sim.cfg")
callsign = file.readline().split(" ")[0]
@ -103,21 +256,28 @@ if __name__ == "__main__":
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")
if (mode != 'a'):
# if (mode != 'a'):
if (command_tx == True):
output(pd, 1)
output (ptt, 0)
output(txLed, txLedOn)
sleep(0.1)
# if (debug_mode == 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 && 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")
# else:
# 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 && 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 > /dev/null 2>&1")
system("aplay /home/pi/CubeSatSim/morse.wav")
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/morse.wav")
else:
if (debug_mode == 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 && 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")
else:
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 && 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 > /dev/null 2>&1")
sleep(0.1)
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
sleep(1)
else:
print("Don't transmit CW ID for APRS")
print("Don't transmit CW ID since command_tx is False")
if (transmit):
@ -126,36 +286,80 @@ if __name__ == "__main__":
# if (len(sys.argv)) > 1:
# print("There are arguments!")
if (mode == 'a'):
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")
## 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")
if (debug_mode == 1):
print("Packet ready!")
system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1")
output(txLed, txLedOn)
output (ptt, 0)
sleep(.1)
# if (debug_mode == 1):
# system("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")
# else:
# system("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")
system("aplay /home/pi/CubeSatSim/telem.wav")
sleep(0.1)
output (ptt, 1)
output(txLed, txLedOff)
system("gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1")
system("cat /home/pi/CubeSatSim/t.txt")
if (command_tx == True):
output(txLed, txLedOn)
# output(pd, 1)
output (ptt, 0)
sleep(.1)
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/telem.wav")
else:
if (debug_mode == 1):
system("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")
else:
system("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")
sleep(0.1)
output (ptt, 1)
# output(pd, 0)
output(txLed, txLedOff)
system("sudo rm /home/pi/CubeSatSim/ready")
f.close()
system("sudo rm /home/pi/CubeSatSim/ready")
sleep(1)
if GPIO.input(squelch) == False:
print("carrier received!")
# command_tx = not command_tx
print(command_tx)
try:
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
if (debug_mode == 1):
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
increment_mode()
if (command_tx == True):
print("Turning on transmit")
system("echo > command_tx True")
# output(txLed, txLedOn)
# sleep(0.5)
# output(txLed, txLedff)
else:
print("Turning off transmit")
system("echo > command_tx False")
else:
print("No carrier received!")
if (debug_mode == 1):
print("Ready for next packet!")
sleep(0.5)
except:
except:
sleep(0.5)
elif (mode == 'm'):
print("CW")
@ -165,35 +369,80 @@ if __name__ == "__main__":
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(txLed, txLedOn)
output (ptt, 0)
sleep(0.1)
# 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 434.9e3")
# 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 434.9e3 > /dev/null 2>&1")
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1 && aplay /home/pi/CubeSatSim/morse.wav")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 1)
if (command_tx == True):
output(txLed, txLedOn)
output (ptt, 0)
sleep(0.1)
if (txc):
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")
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 434.9e3")
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 434.9e3 > /dev/null 2>&1")
output(txLed, txLedOff)
output (ptt, 1)
sleep(5)
while True:
if GPIO.input(squelch) == False:
print("carrier received!")
# command_tx = not command_tx
print(command_tx)
try:
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
if (debug_mode == 1):
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
increment_mode()
if (command_tx == True):
print("Turning on transmit")
system("echo > command_tx True")
# output(txLed, txLedOn)
# sleep(0.5)
# output(txLed, txLedff)
else:
print("Turning off transmit")
system("echo > command_tx False")
sleep(5)
try:
f = open("/home/pi/CubeSatSim/cwready")
system("gen_packets -M 20 -o /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/cw.txt -r 48000 > /dev/null 2>&1")
output(txLed, txLedOn)
output (ptt, 0)
sleep(0.1)
# 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 434.9e3")
# 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 434.9e3 > /dev/null 2>&1")
system("aplay /home/pi/CubeSatSim/morse.wav")
sleep(0.1)
output(txLed, txLedOff)
output (ptt, 1)
f.close()
system("sudo rm /home/pi/CubeSatSim/cwready")
sleep(1)
if (command_tx == True):
output(txLed, txLedOn)
output (ptt, 0)
sleep(0.1)
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 434.9e3")
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 434.9e3 > /dev/null 2>&1")
sleep(0.1)
output(txLed, txLedOff)
output (ptt, 1)
f.close()
# system("sudo rm /home/pi/CubeSatSim/cwready")
sleep(5)
except:
sleep(1)
elif (mode == 's'):
@ -216,39 +465,112 @@ if __name__ == "__main__":
# while 1:
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
if (camera_present == 1):
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")
output(txLed, txLedOn)
output (ptt, 0)
system("aplay /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav")
# if (debug_mode == 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")
# else:
# 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")
output(txLed, txLedOff)
output (ptt, 1)
if (command_tx == True):
print ("Sending SSTV image")
output(txLed, txLedOn)
output(pd, 1)
output (ptt, 0)
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_2_320_x_256.jpg.wav")
else:
if (debug_mode == 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")
else:
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")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
# sleep(1)
except:
print("image 2 did not load - copy from CubeSatSim/sstv directory")
while 1:
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', 20)
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((10, 10), callsign, font=font2, fill='black')
draw.text((120, 10), telem_string, font=font2, fill='black')
img.save(file)
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")
print ("Sending SSTV image")
output(txLed, txLedOn)
output (ptt, 0)
system("aplay /home/pi/CubeSatSim/camera_out.jpg.wav")
# if (debug_mode == 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")
# else:
# 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")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 1)
sleep(1)
if GPIO.input(squelch) == False:
print("carrier received!")
# command_tx = not command_tx
print(command_tx)
try:
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
if (debug_mode == 1):
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
increment_mode()
if (command_tx == True):
print("Turning on transmit")
system("echo > command_tx True")
# output(txLed, txLedOn)
# sleep(0.5)
# output(txLed, txLedff)
else:
print("Turning off transmit")
system("echo > command_tx False")
output(pd, 0)
if (command_tx == True):
print ("Sending SSTV image")
output(txLed, txLedOn)
output(pd, 1)
output (ptt, 0)
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/camera_out.jpg.wav")
else:
if (debug_mode == 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")
else:
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")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
system("sudo rm /home/pi/CubeSatSim/camera_out.jpg.wav > /dev/null 2>&1")
sleep(1)
else:
@ -256,16 +578,24 @@ if __name__ == "__main__":
file = open("/home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg")
print("First SSTV stored image detected")
system("/home/pi/PiSSTVpp/pisstvpp -r 48000 -p s2 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg")
print ("Sending SSTV image")
output(txLed, txLedOn)
output (ptt, 0)
system("aplay /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav")
# if (debug_mode == 1):
# system("cat /home/pi/CubeSatSim/sstv_image_1_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")
# else:
# system("cat /home/pi/CubeSatSim/sstv_image_1_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")
output(txLed, txLedOff)
output (ptt, 1)
if (command_tx == True):
print ("Sending SSTV image")
output(txLed, txLedOn)
output(pd, 1)
output (ptt, 0)
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav")
else:
if (debug_mode == 1):
system("cat /home/pi/CubeSatSim/sstv_image_1_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")
else:
system("cat /home/pi/CubeSatSim/sstv_image_1_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")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
sleep(1)
except:
print("image 1 did not load - copy from CubeSatSim/sstv directory")
@ -274,37 +604,175 @@ if __name__ == "__main__":
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")
output(txLed, txLedOn)
output (ptt, 0)
system("aplay /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav")
# if (debug_mode == 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")
# else:
# 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")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 1)
sleep(1)
if GPIO.input(squelch) == False:
print("carrier received!")
# command_tx = not command_tx
print(command_tx)
try:
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
if (debug_mode == 1):
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
increment_mode()
if (command_tx == True):
print("Turning on transmit")
system("echo > command_tx True")
# output(txLed, txLedOn)
# sleep(0.5)
# output(txLed, txLedff)
else:
print("Turning off transmit")
system("echo > command_tx False")
output(pd, 0)
if (command_tx == True):
print ("Sending SSTV image")
output(txLed, txLedOn)
output(pd, 1)
output (ptt, 0)
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv_image_1_320_x_256.jpg.wav")
else:
if (debug_mode == 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")
else:
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")
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
sleep(5)
except:
print("image 2 did not load - copy from CubeSatSim/sstv directory")
system("aplay /home/pi/CubeSatSim/sstv.wav")
# 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 &")
if (txc == False):
if (command_tx == True):
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:
output(txLed, txLedOn)
output (ptt, 0)
# sleep(60)
system("aplay /home/pi/CubeSatSim/sstv.wav")
output(txLed, txLedOff)
output (ptt, 1)
sleep(1)
if (command_tx == True):
output(txLed, txLedOn)
output(pd, 1)
output (ptt, 0)
if (txc):
system("aplay -D hw:CARD=Headphones,DEV=0 /home/pi/CubeSatSim/sstv.wav")
else:
sleep(60)
output(txLed, txLedOff)
output (ptt, 1)
output(pd, 0)
sleep(1)
elif (mode == 'b'):
print("BPSK not supported in SR_FRS mode")
mode = a
print("BPSK")
print("turn on FM rx")
output(pd, 1)
output(ptt, 1)
if (command_tx == True):
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 &")
print("Turning LED on/off and listening for carrier")
while 1:
output(txLed, txLedOff)
sleep(0.5)
# if (command_tx == False):
# output(txLed, txLedOn)
# sleep(0.03)
# output(txLed, txLedOff)
if GPIO.input(squelch) == False:
print("carrier received!")
# command_tx = not command_tx
print(command_tx)
try:
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
if (debug_mode == 1):
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
increment_mode()
if (command_tx == True):
print("Turning on transmit")
system("echo > command_tx True")
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("Turning off transmit") # and rebooting")
system("echo > command_tx False")
system("sudo systemctl restart rpitx")
# system("sudo reboot now")
sleep(60)
if (command_tx == True):
output(txLed, txLedOn)
sleep(4.0)
else:
print("FSK not supported in SR_FRS mode")
mode = a
print("FSK")
print("turn on FM rx")
output(pd, 1)
output(ptt, 1)
if (command_tx == True):
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 &")
print("Turning LED on/off and listening for carrier")
while 1:
output(txLed, txLedOff)
sleep(0.5)
# if (command_tx == False):
# output(txLed, txLedOn)
# sleep(0.03)
# output(txLed, txLedOff)
if GPIO.input(squelch) == False:
print("carrier received!")
# command_tx = not command_tx
print(command_tx)
try:
command_count += 1
filec = open("/home/pi/CubeSatSim/command_count.txt", "w")
command_count_string = str(command_count)
print(command_count_string)
string = filec.write(command_count_string)
filec.close()
except:
if (debug_mode == 1):
print("Can't write command_count file!")
print("Command_count: ")
print(command_count)
increment_mode()
if (command_tx == True):
print("Turning on transmit")
system("echo > command_tx True")
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("Turning of transmit and rebooting")
system("echo > command_tx False")
system("sudo systemctl restart rpitx")
# system("sudo reboot now")
sleep(60)
if (command_tx == True):
output(txLed, txLedOn)
sleep(4.0)
else:
print("No Band Pass Filter so no telemetry transmit. See http://cubesatsim.org/wiki for instructions on how to build the BPF.")
print("No Low Pass Filter so no telemetry transmit. See http://cubesatsim.org/wiki for instructions on how to build the BPF.")
while 1:
sleep(5)

@ -0,0 +1,481 @@
//#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
//#include <unistd.h>
#include <string.h>
//#include "afsk/status.h"
//#include "afsk/ax5043.h"
//#include "afsk/ax25.h"
//#include "ax5043/spi/ax5043spi.h"
//#include <wiringPiI2C.h>
//#include <wiringPi.h>
//#include <wiringSerial.h>
#include <time.h>
#include <math.h>
//#include "TelemEncoding.h"
//#include <sys/socket.h>
//#include <stdlib.h>
//#include <netinet/in.h>
#include <string.h>
//#include <arpa/inet.h>
//#include <errno.h>
#include "DumbTXSWS.h"
#include <Wire.h>
//#include <Adafruit_INA219.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <MPU6050_tockn.h>
#include <EEPROM.h>
//#include <Arduino-APRS-Library.h>
#include <stdio.h>
#include "pico/stdlib.h" // stdlib
#include "hardware/irq.h" // interrupts
#include "hardware/pwm.h" // pwm
#include "hardware/sync.h" // wait for interrupt
//#include "RPi_Pico_TimerInterrupt.h"
//#include <WiFi.h>
#include "hardware/gpio.h"
#include "hardware/adc.h"
#include <ctype.h>
// Pico GPIO pin assignments
#define PI_TX 0 // Serial to Pi transmit data
#define PI_RX 1 // Serial to Pi receive data
#define SDA 2 // I2C 1 Data
#define SCL 3 // I2C 1 Clock
#define SDA2 4 // I2C 2 Data
#define SCL2 5 // I2C 2 Clock
#define BPSK_CONTROL_A 6 // was 16 // control for Phase A to switch
#define BPSK_CONTROL_B 7 // was 15 // control for Phase A to switch
#ifdef PICO_0V1
#define BPF_PIN 8 // BPF is installed for v0.1 Pico
#define PI_3V3_PIN 9 // 3.3V supply used to detect Pi Zero for v0.1 Pico
#define TX2 12 // Serial2 to ESP32-CAM transmit data
#define RX2 13 // Serial2 to ESP32-CAM receive data
#else
#define TX2 8 // Serial2 to ESP32-CAM transmit data
#define RX2 9 // Serial2 to ESP32-CAM receive data
#define BPF_PIN 12 // BPF is installed
#define PI_3V3_PIN 13 // 3.3V supply used to detect Pi Zero
#endif
#define MAIN_PB_PIN 10 // Main board PB pushbutton pin
#define TXC_PIN 11 // Transceiver Board is present
#define BPSK_PWM_A_PIN 14 // was 6 // PWM Output Phase A to switch
#define BPSK_PWM_B_PIN 15 // was 7 // PWM Output Phase B to switch
#define SWTX_PIN 16 // was 14 SR_FRS_05W Transmit Pico software serial port
#define PTT_PIN 17 // SR_FRS_05W PTT Push to Talk - transmit
#define STEM_LED_GREEN 18 // STEM board LED1 Green
#define STEM_LED_BLUE 19 // STEM board LED2 Blue
#define MAIN_LED_GREEN 20 // Main board LED1
#define MAIN_LED_BLUE 21 // Main board LED1
#define PD_PIN 22 // SR_FRS_05W PD pin - enable
#define AUDIO_OUT_PIN 26 // 26 // SR_FRS_05W audio out pin
#define AUDIO_IN_PIN 27 // SR_FRS_05W audio in pin
#define TEMPERATURE_PIN 28 // Diode temperature analog pin
#define PORT 8080
#define FREQUENCY_OFFSET 0
#define TRUE 1
#define FALSE 0
#define A_ 1
#define B_ 2
#define C_ 3
#define D_ 4
#define PLUS_X 0
#define PLUS_Y 1
#define BAT 2
#define BUS 3
#define MINUS_X 5 // 4
#define MINUS_Y 6 // 5
#define PLUS_Z 4 // 6
#define MINUS_Z 7
#define TEMP 2
#define PRES 3
#define ALT 4
#define HUMI 5
#define GYRO_X 7
#define GYRO_Y 8
#define GYRO_Z 9
#define ACCEL_X 10
#define ACCEL_Y 11
#define ACCEL_Z 12
#define XS1 14
#define XS2 15
#define XS3 16
#define RSSI_ 0
#define IHU_TEMP 2
#define SPIN 1
#define OFF - 1
#define ON 1
#define PROMPT_CALLSIGN 1
#define PROMPT_SIM 2
#define PROMPT_LAT 3
#define PROMPT_RESET 4
#define PROMPT_QUERY 5
#define PROMPT_HELP 6
#define PROMPT_RESTART 7
#define PROMPT_DEBUG 8
#define PROMPT_VOLTAGE 9
#define PROMPT_PAYLOAD 10
#define PROMPT_TEMP 11
#define PROMPT_FORMAT 12
#define PROMPT_REBOOT 13
#define PROMPT_I2CSCAN 14
#define PROMPT_WIFI 15
#define PROMPT_CAMERA 16
#define PAYLOAD_QUERY 1
#define PAYLOAD_RESET 2
#define PAYLOAD_CLEAR 3
volatile int prompt = false;
volatile int prompting = false;
char serial_string[128];
float get_cpu_temp();
//#define WAV_DATA_LENGTH (50000 * 8)
uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET;
//uint8_t data[1024];
uint32_t tx_channel = 0;
//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();
int encodeA(short int * b, int index, int val);
int encodeB(short int * b, int index, int val);
void config_x25();
void trans_x25();
int upper_digit(int number);
int lower_digit(int number);
void update_rs(unsigned char parity[32], unsigned char c);
void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file);
static int init_rf();
void test_radio();
void config_radio();
void send_aprs_packet();
void read_ina219();
void read_sensors();
void get_tlm_ao7();
void print_string(char *string);
void start_payload();
void led_set(int ledPin, bool state);
void blink(int length);
void blink_setup();
short eeprom_word_read(int addr);
void eeprom_word_write(int addr, int val);
void read_payload();
void start_ina219();
void pwm_interrupt_handler();
void start_pwm();
void transmit_on();
void transmit_off();
void config_telem();
void config_simulated_telem();
void generate_simulated_telem();
void process_pushbutton();
void blinkTimes(int blinks);
void blink_pin(int pin, int duration);
void config_gpio();
void start_isr();
void read_reset_count();
void start_button_isr();
void payload_OK_only();
void client_print_string(char *string);
bool check_for_wifi();
void check_for_browser();
void configure_wifi();
void transmit_cw(int freq, float duration);
void transmit_char(char character);
void transmit_string(char *string);
void transmit_callsign(char *callsign);
void parse_payload();
void load_files();
void show_dir();
void serial_input();
void get_serial_string();
void get_serial_char();
void get_serial_clear_buffer();
void set_lat_lon();
void program_radio();
void read_config_file();
void write_config_file();
void read_mode();
void write_mode();
void start_clockgen();
bool TimerHandler1(struct repeating_timer *t);
void load_sstv_image_1_as_cam_dot_jpg();
void load_sstv_image_2_as_cam_dot_jpg();
void get_input();
void transmit_led(bool status);
void reset_min_max();
#ifndef STASSID
#define STASSID "Pico"
#define STAPSK "picoPassword"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
int port = 7373;
volatile bool wifi = false;
extern int Encode_8b10b[][256];
//int socket_open = 0;
//int sock = 0;
int loop_count = 0;
int firstTime = ON; // 0;
long start;
int testCount = 0;
long time_start;
//char cmdbuffer[1000];
//FILE * file1;//
#define BUFFER_SIZE 5841 //970 // (970 * 2) // * 2)
//short int buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK
byte buffer[BUFFER_SIZE]; // 50000]; //BUFFER_SIZE]; // ctr is an int // 100000]; // 50000]; // 25000]; // 10240]; // was 2336400]; // max size for 10 frames count of BPSK
//short int buffer[(WAV_DATA_LENGTH/8)];
//FILE *sopen(const char *program);
char tlm_str[1000];
char payload_str[100];
#define S_RATE (200) // (8000) //(48000) // (44100)
#define AFSK 1
#define FSK 2
#define BPSK 3
#define SSTV 4
#define CW 5
int rpitxStatus = -1;
float amplitude; // = ; // 20000; // 32767/(10%amp+5%amp+100%amp)
float freq_Hz = 3000; // 1200
short int sin_samples;
short int sin_map[16];
int STEMBoardFailure = 1;
int smaller;
int flip_ctr = 0;
int phase = 1;
int ctr = 0;
int rd = 0;
int nrd;
void write_to_buffer(int i, int symbol, int val);
void write_wave(int i, byte * buffer);
void sleep(float time);
int uart_fd;
int reset_count = 0;
float uptime_sec = 1000;
long int uptime = 1000;
//char call[5];
char sim_yes[10];
int mode = BPSK; // SSTV;
volatile int new_mode;
int bitRate, bufLen, rsFrames, payloads, rsFrameLen, dataLen, headerLen, syncBits, syncWord, parityLen, samples, frameCnt, samplePeriod;
float sleepTime;
unsigned int sampleTime = 0;
int frames_sent = 0;
int cw_id = ON;
int vB4 = FALSE, vB5 = FALSE, vB3 = FALSE, ax5043 = FALSE, transmit = FALSE, onLed, onLedOn, onLedOff, txLed, txLedOn, txLedOff, payload = OFF;
float voltageThreshold = 3.5, batteryVoltage = 4.5, batteryCurrent = 0, currentThreshold = 100;
float latitude = 39.027702f, longitude = -77.078064f;
float lat_file, long_file;
double cpuTemp;
int frameTime;
bool debug_camera = false;
float axis[3], angle[3], volts_max[3], amps_max[3], batt, rotation_speed, period, tempS, temp_max, temp_min, eclipse;
int i2c_bus0 = OFF, i2c_bus1 = OFF, i2c_bus3 = OFF, camera = OFF, sim_mode = FALSE, SafeMode = FALSE, rxAntennaDeployed = 0, txAntennaDeployed = 0;
double eclipse_time;
bool i2c_1, i2c2, i2c3,i2c4, i2c5, i2c6, i2c7, i2c8;
float voltage[9], current[9], sensor[17], other[3];
char sensor_payload[500];
int test_i2c_bus(int bus);
//const char pythonCmd[] = "python3 -u /home/pi/CubeSatSim/python/voltcurrent.py ";
//const char pythonCmd[] = "python3 -u /home/pi/CubeSatSim/ina219.py ";
//char pythonStr[100], pythonConfigStr[100], busStr[10];
int mapping[8] = {0, 1, 2, 3, 4, 5, 6, 7};
char src_addr[5] = "";
char dest_addr[6] = "APCSS";
float voltage_min[9], current_min[9], voltage_max[9], current_max[9], sensor_max[17], sensor_min[17], other_max[3], other_min[3];
// Payload OK
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
MPU6050 mpu6050(Wire);
long timer = 0;
int bmePresent, mpuPresent;
int RXLED = 17; // The RX LED has a defined Arduino pin
int greenLED = 19;
int blueLED = 18;
float Sensor1 = 0.0;
float Sensor2 = 0.0;
float Sensor3 = 0.0;
bool newData = false;
void eeprom_word_write(int addr, int val);
short eeprom_word_read(int addr);
int first_time = true;
int first_time_sstv = true;
int first_read = true;
float T2 = 27; // Temperature data point 1
float R2 = 170; // Reading data point 1
float T1 = 7; // Temperature data point 2
float R1 = 184; // Reading data point 2
int sensorValue;
float Temp;
float rest;
unsigned int wav_position = 0;
/*
int pwm_counter = 0;
int pwm_counter_max = 420;
int pwm_amplitude = 50; //50 //100;
int pwm_value;
int tx_bit = 1;
*/
volatile unsigned long delay_time;
bool polarity = true;
pwm_config config;
int bpsk_pin_slice_A;
int bpsk_pin_slice_B;
int bpsk_pin_slice;
int sample_rate;
int buffer_size;
long micro_timer;
long micro_timer2;
int ready = FALSE;
bool cw_stop = false;
int payload_command = false;
bool debug_mode = false;
bool voltage_read = false;
bool ina219_started = false;
bool camera_detected = false;
bool rotate_flag = true;
int led_builtin_pin;
#define PRESSED 0
#define HELD 0
#define RELEASED 1
int pb_state = RELEASED;
int mode_count = 0;
unsigned long pb_press_start;
const char sstv1_filename[] = "/sstv_image_1_320_x_240.jpg";
const char sstv2_filename[] = "/sstv_image_2_320_x_240.jpg";
//bool TimerHandler0(struct repeating_timer *t);
//RPI_PICO_Timer ITimer0(0);
//RPI_PICO_Timer ITimer1(1);
bool timer0_on = false;
volatile int timer_counter;
bool filter_present = false; // BPF installation state for transmitter
bool sr_frs_present = false; // SR_FRS FM transmitter module state
char callsign[20];
int morse_timing = 60; // ms for a dit
int morse_freq = 1800; // Hz
//int morse_table[44][6] = { // 0-9, A-Z only by (ASCII - 48)
byte morse_table[44][6] = { // 0-9, A-Z only by (ASCII - 48)
{ 3, 3, 3, 3, 3, 0 }, // 0
{ 1, 3, 3, 3, 3, 0 }, // 1
{ 1, 1, 3, 3, 3, 0 }, // 2
{ 1, 1, 1, 3, 3, 0 }, // 3
{ 1, 1, 1, 1, 3, 0 }, // 4
{ 1, 1, 1, 1, 1, 0 }, // 5
{ 3, 1, 1, 1, 1, 0 }, // 6
{ 3, 3, 1, 1, 1, 0 }, // 7
{ 3, 3, 3, 1, 1, 0 }, // 8
{ 3, 3, 3, 3, 1, 0 }, // 9
{ 0, 0, 0, 0, 0, 0 }, // -
{ 0, 0, 0, 0, 0, 0 }, // -
{ 0, 0, 0, 0, 0, 0 }, // -
{ 0, 0, 0, 0, 0, 0 }, // -
{ 0, 0, 0, 0, 0, 0 }, // -
{ 0, 0, 0, 0, 0, 0 }, // -
{ 0, 0, 0, 0, 0, 0 }, // -
{ 1, 3, 0, 0, 0, 0 }, // A
{ 3, 1, 1, 1, 0, 0 }, // B
{ 3, 1, 3, 1, 0, 0 }, // C
{ 3, 1, 1, 0, 0, 0 }, // D
{ 1, 0, 0, 0, 0, 0 }, // E
{ 1, 1, 3, 1, 0, 0 }, // F
{ 3, 3, 1, 0, 0, 0 }, // G
{ 1, 1, 1, 1, 0, 0 }, // H
{ 1, 1, 0, 0, 0, 0 }, // I
{ 1, 3, 3, 3, 0, 0 }, // J
{ 3, 1, 3, 0, 0, 0 }, // K
{ 1, 3, 1, 1, 0, 0 }, // L
{ 3, 3, 0, 0, 0, 0 }, // M
{ 3, 1, 0, 0, 0, 0 }, // N
{ 3, 3, 3, 0, 0, 0 }, // O
{ 1, 3, 3, 1, 0, 0 }, // P
{ 3, 3, 1, 3, 0, 0 }, // Q
{ 1, 3, 1, 0, 0, 0 }, // R
{ 1, 1, 1, 0, 0, 0 }, // S
{ 3, 0, 0, 0, 0, 0 }, // T
{ 1, 1, 3, 0, 0, 0 }, // U
{ 1, 1, 1, 3, 0, 0 }, // V
{ 1, 3, 3, 0, 0, 0 }, // W
{ 3, 1, 1, 3, 0, 0 }, // X
{ 3, 1, 3, 3, 0, 0 }, // Y
{ 3, 3, 1, 1, 0, 0 } // Z
};
/*
* TelemEncoding.h
*
* Created on: Feb 3, 2014
* Author: fox
*/
#ifndef TELEMENCODING_H_
#define TELEMENCODING_H_
/*
void update_rs(
unsigned char parity[32], // 32-byte encoder state; zero before each frame
unsigned char c // Current data byte to update
);
*/
#define CHARACTER_BITS 10
#define CHARACTERS_PER_LONGWORD 3
#define CHARACTER_MASK ((1<<CHARACTER_BITS)-1)
#define SYNC_CHARACTER -1
#define PARITY_BYTES_PER_CODEWORD 32U // Number of parity symbols in frame
#define NP 32U //For Phil's code
#define DATA_BYTES_PER_CODE_WORD 223
#endif /* TELEMENCODING_H_ */
char sensor_end_flag[] = "_END_FLAG_";
char sensor_start_flag[] = "_START_FLAG_";

File diff suppressed because it is too large Load Diff

@ -15,7 +15,7 @@ int main(int argc, char *argv[]) {
}
}
printf("CubeSatSim v1.2 INA219 Voltage and Current Telemetry\n");
printf("CubeSatSim v1.3 INA219 Voltage and Current Telemetry\n");
map[MINUS_X] = MINUS_Y;
map[PLUS_Z] = MINUS_X;
map[MINUS_Y] = PLUS_Z;

111
update

@ -1,6 +1,6 @@
#!/bin/bash
echo -e "\nupdate script for CubeSatSim v1.2\n"
echo -e "\nupdate script for CubeSatSim v1.3b\n"
sudo rm /home/pi/CubeSatSim/morse.wav /home/pi/CubeSatSim/id.txt /home/pi/CubeSatSim/cw.txt > /dev/null 2>&1
@ -28,6 +28,22 @@ git pull > .updated
make debug
FILE=/home/pi/CubeSatSim/command_tx
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "creating $FILE"
echo "True\n" > /home/pi/CubeSatSim/command_tx
fi
FILE=/home/pi/CubeSatSim/command_count.txt
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "creating $FILE"
echo "0\n" > /home/pi/CubeSatSim/command_count.txt
fi
FLAG=0
if [[ $(diff systemd/cubesatsim.service /etc/systemd/system/cubesatsim.service) ]]; then
@ -64,20 +80,6 @@ if [[ $(grep 'update' /home/pi/CubeSatSim/.updated) ]]; then
/home/pi/CubeSatSim/update
fi
if [ $FLAG -eq 1 ]; then
echo "systemctl daemon-reload and restart"
sudo systemctl daemon-reload
sudo systemctl restart cubesatsim
else
grep 'changed' /home/pi/CubeSatSim/.updated
if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then
echo "systemctl restart cubesatsim"
sudo systemctl restart cubesatsim
else
echo "nothing to do."
fi
fi
if [ ! -d "/home/pi/PiSSTVpp" ]; then
sudo apt-get update && sudo apt-get dist-upgrade -y
@ -129,6 +131,8 @@ fi
cd /home/pi/pi-power-button
# git checkout reboot-mode-change
git pull > .updated_p
grep 'changed' /home/pi/pi-power-button/.updated_p
@ -155,5 +159,82 @@ git pull > .updated_p
else
echo "nothing to do for pi-power-button."
fi
if [[ $(grep 'dtparam=audio=on' /boot/config.txt) ]]; then
echo "dtparam=audio=on already in /boot/config.txt"
else
echo "adding dtparam=audio=on to /boot/config.txt"
sudo sh -c 'echo "\ndtparam=audio=on" >> /boot/config.txt'
FLAG=1
fi
if [[ $(grep 'dtoverlay=audremap,enable_jack=on' /boot/config.txt) ]]; then
echo "dtoverlay=audremap,enable_jack=on already in /boot/config.txt"
else
echo "adding dtoverlay=audremap,enable_jack=on to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=audremap,enable_jack=on" >> /boot/config.txt'
FLAG=1
fi
if [[ $(grep 'dtoverlay=pwm,pin=18,func=2' /boot/config.txt) ]]; then
echo "dtoverlay=pwm,pin=18,func=2 already in /boot/config.txt"
else
echo "adding dtoverlay=pwm,pin=18,func=2 to /boot/config.txt"
sudo sh -c 'echo "\ndtoverlay=pwm,pin=18,func=2" >> /boot/config.txt'
FLAG=1
cd /home/pi/pi-power-button
git pull
git checkout reboot-mode-change
script/install
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo apt-get install -y libjpeg-dev zlib1g-dev libfreetype6-dev liblcms1-dev libopenjp2-7 libtiff5 -y
sudo pip3 install pillow
fi
if [[ $(grep 'disable_splash=1' /boot/config.txt) ]]; then
echo "disable_splash=1 already in /boot/config.txt"
else
echo "adding to /boot/config.txt"
sudo sh -c 'echo "\ndisable_splash=1" >> /boot/config.txt'
FLAG=1
fi
if [[ $(grep 'boot_delay=0' /boot/config.txt) ]]; then
echo "boot_delay=0 already in /boot/config.txt"
else
echo "adding to /boot/config.txt"
sudo sh -c 'echo "\nboot_delay=0" >> /boot/config.txt'
FLAG=1
fi
#if [ ! -f "/home/pi/CubeSatSim/telem_string.txt" ]; then
# sudo apt-get update && sudo apt-get dist-upgrade -y
# sudo apt-get install -y libjpeg-dev zlib1g-dev libfreetype6-dev liblcms1-dev libopenjp2-7 libtiff5 -y
# sudo pip3 install pillow
#fi
if [ $FLAG -eq 1 ]; then
echo "systemctl daemon-reload and reboot"
sudo systemctl daemon-reload
sudo reboot -h now
# sudo systemctl restart cubesatsim
else
grep 'changed' /home/pi/CubeSatSim/.updated
if [[ $(grep 'changed' /home/pi/CubeSatSim/.updated) ]]; then
echo "reboot"
sudo reboot -h now
# sudo systemctl restart cubesatsim
else
echo "nothing to do."
fi
fi
echo "CubeSatSim update complete."

Loading…
Cancel
Save

Powered by TurnKey Linux.