Merge pull request #99 from alanbjohnston/master-faster

Master faster with dummy frames during startup
pull/102/head
alanbjohnston 5 years ago committed by GitHub
commit 497b681a6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

3
.gitignore vendored

@ -19,3 +19,6 @@ sstv_image_2_320_x_256.jpg.wav
t.txt t.txt
telem telem
telem.wav telem.wav
cw.txt
cwready
logr.txt

@ -132,8 +132,8 @@ void write_to_buffer(int i, int symbol, int val);
void write_wave(int i, short int * buffer); void write_wave(int i, short int * buffer);
int uart_fd; int uart_fd;
int reset_count; int reset_count = 0;
float uptime_sec; float uptime_sec = 0;
long int uptime; long int uptime;
char call[5]; char call[5];
char sim_yes[10]; char sim_yes[10];
@ -396,15 +396,6 @@ int main(int argc, char * argv[]) {
voltageThreshold = 8.0; voltageThreshold = 8.0;
} }
strcpy(pythonStr, pythonCmd);
strcat(pythonStr, busStr);
strcat(pythonConfigStr, pythonStr);
strcat(pythonConfigStr, " c");
fprintf(stderr, "pythonConfigStr: %s\n", pythonConfigStr);
file1 = sopen(pythonConfigStr); // try new function
// test i2c buses // test i2c buses
fflush(stdout); fflush(stdout);
//printf("Test bus 0\n"); //printf("Test bus 0\n");
@ -433,10 +424,7 @@ int main(int argc, char * argv[]) {
printf("INFO: I2C bus status 0: %d 1: %d 3: %d camera: %d\n", i2c_bus0, i2c_bus1, i2c_bus3, camera); printf("INFO: I2C bus status 0: %d 1: %d 3: %d camera: %d\n", i2c_bus0, i2c_bus1, i2c_bus3, camera);
#endif #endif
fgets(cmdbuffer, 1000, file1); FILE * file5 = popen("sudo rm /home/pi/CubeSatSim/camera_out.jpg > /dev/null 2>&1", "r");
fprintf(stderr, "pythonStr result: %s\n", cmdbuffer);
FILE * file5 = popen("sudo rm /home/pi/CubeSatSim/t.txt > /dev/null 2>&1", "r");
pclose(file5); pclose(file5);
// try connecting to STEM Payload board using UART // try connecting to STEM Payload board using UART
@ -550,22 +538,6 @@ int main(int argc, char * argv[]) {
fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n"); fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n");
} }
for (int i = 0; i < 9; i++) {
voltage_min[i] = 1000.0;
current_min[i] = 1000.0;
voltage_max[i] = -1000.0;
current_max[i] = -1000.0;
}
for (int i = 0; i < 17; i++) {
sensor_min[i] = 1000.0;
sensor_max[i] = -1000.0;
// printf("Sensor min and max initialized!");
}
for (int i = 0; i < 3; i++) {
other_min[i] = 1000.0;
other_max[i] = -1000.0;
}
if (mode == FSK) { if (mode == FSK) {
bitRate = 200; bitRate = 200;
rsFrames = 1; rsFrames = 1;
@ -621,6 +593,46 @@ int main(int argc, char * argv[]) {
printf("\n"); printf("\n");
} }
memset(voltage, 0, sizeof(voltage));
memset(current, 0, sizeof(current));
memset(sensor, 0, sizeof(sensor));
memset(other, 0, sizeof(other));
if ((mode == FSK) || (mode == BPSK))
get_tlm_fox(); // fill transmit buffer with reset count 0 packets that will be ignored
firstTime = 1;
if (!sim_mode)
{
strcpy(pythonStr, pythonCmd);
strcat(pythonStr, busStr);
strcat(pythonConfigStr, pythonStr);
strcat(pythonConfigStr, " c");
fprintf(stderr, "pythonConfigStr: %s\n", pythonConfigStr);
file1 = sopen(pythonConfigStr); // python sensor polling function
fgets(cmdbuffer, 1000, file1);
fprintf(stderr, "pythonStr result: %s\n", cmdbuffer);
}
for (int i = 0; i < 9; i++) {
voltage_min[i] = 1000.0;
current_min[i] = 1000.0;
voltage_max[i] = -1000.0;
current_max[i] = -1000.0;
}
for (int i = 0; i < 17; i++) {
sensor_min[i] = 1000.0;
sensor_max[i] = -1000.0;
// printf("Sensor min and max initialized!");
}
for (int i = 0; i < 3; i++) {
other_min[i] = 1000.0;
other_max[i] = -1000.0;
}
long int loopTime; long int loopTime;
loopTime = millis(); loopTime = millis();
@ -1739,15 +1751,13 @@ void get_tlm_fox() {
//printf("Sleep over\n"); //printf("Sleep over\n");
h[0] = (short int) ((h[0] & 0xf8) | (id & 0x07)); // 3 bits h[0] = (short int) ((h[0] & 0xf8) | (id & 0x07)); // 3 bits
// printf("h[0] %x\n", h[0]); if (uptime != 0) // if uptime is 0, leave reset count at 0
{
h[0] = (short int) ((h[0] & 0x07) | ((reset_count & 0x1f) << 3)); h[0] = (short int) ((h[0] & 0x07) | ((reset_count & 0x1f) << 3));
// printf("h[0] %x\n", h[0]);
h[1] = (short int) ((reset_count >> 5) & 0xff); h[1] = (short int) ((reset_count >> 5) & 0xff);
// printf("h[1] %x\n", h[1]);
h[2] = (short int) ((h[2] & 0xf8) | ((reset_count >> 13) & 0x07)); h[2] = (short int) ((h[2] & 0xf8) | ((reset_count >> 13) & 0x07));
// printf("h[2] %x\n", h[2]); }
h[2] = (short int) ((h[2] & 0x0e) | ((uptime & 0x1f) << 3)); h[2] = (short int) ((h[2] & 0x0e) | ((uptime & 0x1f) << 3));
// printf("h[2] %x\n", h[2]);
h[3] = (short int) ((uptime >> 5) & 0xff); h[3] = (short int) ((uptime >> 5) & 0xff);
h[4] = (short int) ((uptime >> 13) & 0xff); h[4] = (short int) ((uptime >> 13) & 0xff);
h[5] = (short int) ((h[5] & 0xf0) | ((uptime >> 21) & 0x0f)); h[5] = (short int) ((h[5] & 0xf0) | ((uptime >> 21) & 0x0f));
@ -2077,8 +2087,10 @@ void get_tlm_fox() {
rd = nrd; // ^ nrd; rd = nrd; // ^ nrd;
ctr2++; ctr2++;
} }
// {
for (i = 0; i < parityLen; i++) { for (i = 0; i < parityLen; i++) {
for (int j = 0; j < rsFrames; j++) { for (int j = 0; j < rsFrames; j++) {
if ((uptime != 0) || (i != 0)) // don't correctly update parties if uptime is 0 so the frame will fail the FEC check and be discarded
data10[ctr2++] = (Encode_8b10b[rd][((int) parities[j][i])] & 0x3ff); data10[ctr2++] = (Encode_8b10b[rd][((int) parities[j][i])] & 0x3ff);
nrd = (Encode_8b10b[rd][((int) parities[j][i])] >> 10) & 1; nrd = (Encode_8b10b[rd][((int) parities[j][i])] >> 10) & 1;
// printf ("data10[%d] = encoded parities[%d][%d] = %x \n", // printf ("data10[%d] = encoded parities[%d][%d] = %x \n",
@ -2087,6 +2099,7 @@ void get_tlm_fox() {
rd = nrd; rd = nrd;
} }
} }
// }
#ifdef DEBUG_LOGGING #ifdef DEBUG_LOGGING
// printf("\nAt end of data10 write, %d ctr2 values written\n\n", ctr2); // printf("\nAt end of data10 write, %d ctr2 values written\n\n", ctr2);
#endif #endif
@ -2571,7 +2584,7 @@ int test_i2c_bus(int bus)
if (access(busDev, W_OK | R_OK) >= 0) { // Test if I2C Bus is present if (access(busDev, W_OK | R_OK) >= 0) { // Test if I2C Bus is present
// printf("bus is present\n\n"); // printf("bus is present\n\n");
char result[128]; char result[128];
const char command_start[] = "timeout 10 i2cdetect -y "; const char command_start[] = "timeout 5 i2cdetect -y "; // was 10
char command[50]; char command[50];
strcpy (command, command_start); strcpy (command, command_start);
strcat (command, busS); strcat (command, busS);

@ -98,12 +98,17 @@ if __name__ == "__main__":
if (mode == 'a'): if (mode == 'a'):
print("AFSK") print("AFSK")
# time.sleep(4) # time.sleep(4)
try:
file = open("/home/pi/CubeSatSim/t.txt")
file.close()
except:
system("echo '" + callsign + ">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")
for x in range(5): for x in range(5):
GPIO.output(txLed, txLedOn) GPIO.output(txLed, txLedOn)
if (debug_mode == 1): if (debug_mode == 1):
system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") 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: else:
system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") 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")
time.sleep(0.2) time.sleep(0.2)
GPIO.output(txLed, txLedOff) GPIO.output(txLed, txLedOff)
time.sleep(3.8) time.sleep(3.8)
@ -112,9 +117,9 @@ if __name__ == "__main__":
f = open("/home/pi/CubeSatSim/ready") f = open("/home/pi/CubeSatSim/ready")
GPIO.output(txLed, txLedOn) GPIO.output(txLed, txLedOn)
if (debug_mode == 1): if (debug_mode == 1):
system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3") 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: else:
system("sudo gen_packets -o /home/pi/CubeSatSim/telem.wav /home/pi/CubeSatSim/t.txt -r 48000 > /dev/null 2>&1 && cat /home/pi/CubeSatSim/telem.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/rpitx/rpitx -i- -m RF -f 434.9e3 > /dev/null 2>&1") 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")
GPIO.output(txLed, txLedOff) GPIO.output(txLed, txLedOff)
f.close() f.close()
system("sudo rm ready") system("sudo rm ready")
@ -124,11 +129,16 @@ if __name__ == "__main__":
elif (mode == 'm'): elif (mode == 'm'):
print("CW") print("CW")
# time.sleep(4) # time.sleep(4)
try:
file = open("/home/pi/CubeSatSim/cw.txt")
file.close()
except:
system("echo 'hi hi 100 199 199 199 298 299 299 278 380 350 300 300 439 400 400 400 500 500 500 500 600 600 600 650' > /home/pi/CubeSatSim/cw.txt")
GPIO.output(txLed, txLedOn) GPIO.output(txLed, txLedOn)
if (debug_mode == 1): if (debug_mode == 1):
system("sudo 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") 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: else:
system("sudo 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 && 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")
GPIO.output(txLed, txLedOff) GPIO.output(txLed, txLedOff)
while True: while True:
@ -136,9 +146,9 @@ if __name__ == "__main__":
f = open("/home/pi/CubeSatSim/cwready") f = open("/home/pi/CubeSatSim/cwready")
GPIO.output(txLed, txLedOn) GPIO.output(txLed, txLedOn)
if (debug_mode == 1): if (debug_mode == 1):
system("sudo 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") 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: else:
system("sudo 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 && 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")
GPIO.output(txLed, txLedOff) GPIO.output(txLed, txLedOff)
f.close() f.close()
system("sudo rm cwready") system("sudo rm cwready")

@ -8,7 +8,7 @@ WorkingDirectory=/home/pi/CubeSatSim
StandardOutput=inherit StandardOutput=inherit
StandardError=inherit StandardError=inherit
Restart=always Restart=always
User=root User=pi
[Install] [Install]
WantedBy=default.target WantedBy=default.target

Loading…
Cancel
Save

Powered by TurnKey Linux.