reformatted

pull/75/head
alanbjohnston 5 years ago committed by GitHub
parent a534fabf69
commit d7c5d11a62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,7 +21,6 @@
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "status.h"
@ -150,7 +149,16 @@ int test_i2c_bus(int bus);
const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py ";
char pythonStr[100], pythonConfigStr[100], busStr[10];
int map[8] = { 0, 1, 2, 3, 4, 5, 6, 7};
int map[8] = {
0,
1,
2,
3,
4,
5,
6,
7
};
char src_addr[5] = "";
char dest_addr[5] = "CQ";
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];
@ -162,23 +170,16 @@ int main(int argc, char *argv[]) {
if (argc > 1) {
// strcpy(src_addr, argv[1]);
if (*argv[1] == 'b')
{
if ( * argv[1] == 'b') {
mode = BPSK;
printf("Mode BPSK\n");
}
else if (*argv[1] == 'a')
{
} else if ( * argv[1] == 'a') {
mode = AFSK;
printf("Mode AFSK\n");
}
else if (*argv[1] == 'c')
{
} else if ( * argv[1] == 'c') {
mode = CW;
printf("Mode CW\n");
}
else
{
} else {
printf("Mode FSK\n");
}
@ -190,8 +191,7 @@ int main(int argc, char *argv[]) {
printf("Looping %d times \n", loop);
if (argc > 3) {
if (*argv[3] == 'n')
{
if ( * argv[3] == 'n') {
cw_id = OFF;
printf("No CW id\n");
}
@ -200,8 +200,7 @@ int main(int argc, char *argv[]) {
// Open configuration file with callsign and reset count
FILE * config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r");
if (config_file == NULL)
{
if (config_file == NULL) {
printf("Creating config file.");
config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "w");
fprintf(config_file, "%s %d", " ", 100);
@ -215,8 +214,7 @@ int main(int argc, char *argv[]) {
printf("Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f\n", call, reset_count, lat_file, long_file);
reset_count = (reset_count + 1) % 0xffff;
if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0))
{
if ((fabs(lat_file) > 0) && (fabs(lat_file) < 90.0) && (fabs(long_file) > 0) && (fabs(long_file) < 180.0)) {
printf("Valid latitude and longitude in config file\n");
latitude = lat_file;
longitude = long_file;
@ -225,15 +223,13 @@ int main(int argc, char *argv[]) {
// Check for SPI and AX-5043 Digital Transceiver Board
FILE * file = popen("sudo raspi-config nonint get_spi", "r");
if (fgetc(file) == 48)
{
if (fgetc(file) == 48) {
printf("SPI is enabled!\n");
FILE * file2 = popen("ls /dev/spidev0.* 2>&1", "r");
// printf("Result getc: %c \n", getc(file2));
if (fgetc(file2) != 'l')
{
if (fgetc(file2) != 'l') {
printf("SPI devices present!\n");
// }
pclose(file2);
@ -243,8 +239,7 @@ int main(int argc, char *argv[]) {
// char src_addr[5] = "KU2Y";
// char dest_addr[5] = "CQ";
ax25_init( & hax25, (uint8_t * ) dest_addr, '1', (uint8_t * ) call, '1', AX25_PREAMBLE_LEN, AX25_POSTAMBLE_LEN);
if (init_rf())
{
if (init_rf()) {
printf("AX5043 successfully initialized!\n");
ax5043 = TRUE;
cw_id = OFF;
@ -252,8 +247,7 @@ int main(int argc, char *argv[]) {
// cycle = OFF;
printf("Mode AFSK with AX5043\n");
transmit = TRUE;
}
else
} else
printf("AX5043 not present!\n");
}
}
@ -265,13 +259,11 @@ int main(int argc, char *argv[]) {
txLed = 0; // defaults for vB3 board without TFB
txLedOn = LOW;
txLedOff = HIGH;
if (!ax5043)
{
if (!ax5043) {
pinMode(2, INPUT);
pullUpDnControl(2, PUD_UP);
if (digitalRead(2) != HIGH)
{
if (digitalRead(2) != HIGH) {
printf("vB3 with TFB Present\n");
vB3 = TRUE;
txLed = 3;
@ -281,13 +273,11 @@ int main(int argc, char *argv[]) {
onLedOn = LOW;
onLedOff = HIGH;
transmit = TRUE;
} else
{
} else {
pinMode(3, INPUT);
pullUpDnControl(3, PUD_UP);
if (digitalRead(3) != HIGH)
{
if (digitalRead(3) != HIGH) {
printf("vB4 Present\n");
txLed = 2;
txLedOn = HIGH;
@ -297,14 +287,11 @@ int main(int argc, char *argv[]) {
onLedOn = HIGH;
onLedOff = LOW;
transmit = TRUE;
}
else
{
} else {
pinMode(26, INPUT);
pullUpDnControl(26, PUD_UP);
if (digitalRead(26) != HIGH)
{
if (digitalRead(26) != HIGH) {
printf("vB5 Present\n");
txLed = 2;
txLedOn = HIGH;
@ -335,14 +322,11 @@ int main(int argc, char *argv[]) {
fclose(config_file);
config_file = fopen("sim.cfg", "r");
if (vB4)
{
if (vB4) {
map[BAT] = BUS;
map[BUS] = BAT;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
}
else if (vB5)
{
} else if (vB5) {
map[MINUS_X] = PLUS_Z;
map[PLUS_Z] = MINUS_X;
@ -352,9 +336,7 @@ else if (vB5)
} else {
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3));
}
}
else
{
} else {
map[BUS] = MINUS_Z;
map[BAT] = BUS;
map[PLUS_Z] = BAT;
@ -381,8 +363,7 @@ else
{
payload = OFF;
if ((uart_fd = serialOpen ("/dev/ttyAMA0", 9600)) >= 0)
{
if ((uart_fd = serialOpen("/dev/ttyAMA0", 9600)) >= 0) {
char c;
int charss = serialDataAvail(uart_fd);
if (charss != 0)
@ -392,19 +373,15 @@ else
unsigned int waitTime;
int i;
for(i = 0; i < 2; i++)
{
for (i = 0; i < 2; i++) {
serialPutchar(uart_fd, 'R');
printf("Querying payload with R to reset\n");
waitTime = millis() + 500;
while ((millis() < waitTime) && (payload != ON))
{
if (serialDataAvail (uart_fd))
{
while ((millis() < waitTime) && (payload != ON)) {
if (serialDataAvail(uart_fd)) {
printf("%c", c = serialGetchar(uart_fd));
fflush(stdout);
if (c == 'O')
{
if (c == 'O') {
printf("%c", c = serialGetchar(uart_fd));
fflush(stdout);
if (c == 'K')
@ -418,9 +395,7 @@ else
printf("\nPayload is present!\n");
else
printf("\nPayload not present!\n");
}
else
{
} else {
fprintf(stderr, "Unable to open UART: %s\n", strerror(errno));
}
}
@ -444,8 +419,7 @@ pclose(file4);
printf("INFO: I2C bus status 0: %d 1: %d 3: %d camera: %d\n", i2c_bus0, i2c_bus1, i2c_bus3, camera);
#endif
if ((i2c_bus1 == OFF) && (i2c_bus3 == OFF))
{
if ((i2c_bus1 == OFF) && (i2c_bus3 == OFF)) {
sim_mode = TRUE;
@ -502,34 +476,29 @@ printf("batt: %f speed: %f eclipse_time: %f eclipse: %d period: %f temp: %f max:
if (mode == AFSK)
sleep(10); // delay awaiting CW ID completion
if (transmit == FALSE)
{
if (transmit == FALSE) {
fprintf(stderr, "\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n");
fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n");
}
for(int i=0; i < 9; i++)
{
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++)
{
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++)
{
for (int i = 0; i < 3; i++) {
other_min[i] = 1000.0;
other_max[i] = -1000.0;
}
while (loop-- != 0)
{
while (loop-- != 0) {
frames_sent++;
#ifdef DEBUG_LOGGING
@ -572,8 +541,7 @@ while (loop-- != 0)
printf("\n FSK Mode, %d bits per frame, %d bits per second, %d ms sample period\n",
bufLen / (samples * frameCnt), bitRate, samplePeriod);
}
else if (mode == BPSK) {
} else if (mode == BPSK) {
bitRate = 1200;
rsFrames = 3;
payloads = 6;
@ -603,11 +571,9 @@ while (loop-- != 0)
fprintf(stderr, "INFO: Getting TLM Data\n");
#endif
if ((mode == AFSK) || (mode == CW))
{
if ((mode == AFSK) || (mode == CW)) {
get_tlm();
}
else // FSK or BPSK
} else // FSK or BPSK
{
get_tlm_fox();
}
@ -617,8 +583,7 @@ while (loop-- != 0)
#endif
}
if (mode == BPSK)
{
if (mode == BPSK) {
digitalWrite(txLed, txLedOn);
#ifdef DEBUG_LOGGING
printf("Tx LED On\n");
@ -630,9 +595,7 @@ while (loop-- != 0)
#ifdef DEBUG_LOGGING
printf("Tx LED Off\n");
#endif
}
else if (mode == FSK)
{
} else if (mode == FSK) {
printf("Sleeping to allow FSK transmission to finish.\n");
sleep(loop_count);
printf("Done sleeping\n");
@ -684,8 +647,7 @@ int get_tlm(void) {
FILE * txResult;
for (int j = 0; j < frameCnt; j++)
{
for (int j = 0; j < frameCnt; j++) {
digitalWrite(txLed, txLedOn);
#ifdef DEBUG_LOGGING
printf("Tx LED On\n");
@ -712,17 +674,14 @@ for (int j = 0; j < frameCnt; j++)
memset(voltage, 0, sizeof(voltage));
memset(current, 0, sizeof(current));
for (count1 = 0; count1 < 8; count1++)
{
if (token != NULL)
{
for (count1 = 0; count1 < 8; count1++) {
if (token != NULL) {
voltage[count1] = atof(token);
#ifdef DEBUG_LOGGING
// printf("voltage: %f ", voltage[count1]);
#endif
token = strtok(NULL, space);
if (token != NULL)
{
if (token != NULL) {
current[count1] = atof(token);
if ((current[count1] < 0) && (current[count1] > -0.5))
current[count1] *= (-1.0);
@ -750,15 +709,12 @@ for (int j = 0; j < frameCnt; j++)
}
fclose(cpuTempSensor);
if (sim_mode)
{
if (sim_mode) {
// simulated telemetry
double time = (millis() - time_start) / 1000.0;
if ((time - eclipse_time) > period)
{
if ((time - eclipse_time) > period) {
eclipse = (eclipse == 1) ? 0 : 1;
eclipse_time = time;
printf("\n\nSwitching eclipse mode! \n\n");
@ -809,8 +765,7 @@ if (sim_mode)
// printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[map[BAT]], current[map[BUS]], batt, voltage[map[BUS]]);
batt -= (batt > 3.5) ? current[map[BAT]] / 30000 : current[map[BAT]] / 3000;
if (batt < 3.0)
{
if (batt < 3.0) {
batt = 3.0;
printf("Safe Mode!\n");
}
@ -864,15 +819,11 @@ if (sim_mode)
char footer_str1[] = "\' > t.txt && echo \'";
char footer_str[] = ">CQ:010101/hi hi ' >> t.txt && gen_packets -o telem.wav t.txt -r 48000 > /dev/null 2>&1 && cat 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";
if (ax5043)
{
if (ax5043) {
strcpy(str, header_str);
}
else
{
} else {
strcpy(str, header_str3);
if (mode != CW)
{
if (mode != CW) {
strcat(str, call);
strcat(str, header_str2);
// sprintf(header_str2b, "=%7.2f%c%c%c%08.2f%cShi hi ",4003.79,'N',0x5c,0x5c,07534.33,'W'); // add APRS lat and long
@ -888,8 +839,7 @@ if (sim_mode)
sprintf(header_str2b, "=%s%c%c%sShi hi ", header_lat, 0x5c, 0x5c, header_long); // add APRS lat and long
printf("\n\nString is %s \n\n", header_str2b);
strcat(str, header_str2b);
} else
{
} else {
strcat(str, header_str4);
}
}
@ -921,8 +871,7 @@ if (sim_mode)
char sensor_payload[500];
if (payload == ON)
{
if (payload == ON) {
char c;
int charss = serialDataAvail(uart_fd);
if (charss != 0)
@ -937,20 +886,15 @@ if (payload == ON)
printf("Querying payload with ?\n");
waitTime = millis() + 500;
int end = FALSE;
while ((millis() < waitTime) && !end)
{
while ((millis() < waitTime) && !end) {
int chars = serialDataAvail(uart_fd);
while ((chars-- > 0) && !end)
{
while ((chars--> 0) && !end) {
c = serialGetchar(uart_fd);
// printf ("%c", c);
// fflush(stdout);
if (c != '\n')
{
if (c != '\n') {
sensor_payload[i++] = c;
}
else
{
} else {
end = TRUE;
}
}
@ -973,8 +917,7 @@ if (payload == ON)
printf("Tx LED On\n");
#endif
if (ax5043)
{
if (ax5043) {
digitalWrite(txLed, txLedOn);
#ifdef DEBUG_LOGGING
printf("Tx LED On\n");
@ -1001,20 +944,15 @@ if (payload == ON)
exit(EXIT_FAILURE);
}
sleep(2);
}
else
{
} else {
strcat(str, footer_str1);
strcat(str, call);
strcat(str, footer_str);
fprintf(stderr, "String to execute: %s\n", str);
if (transmit)
{
if (transmit) {
FILE * file2 = popen(str, "r");
pclose(file2);
}
else
{
} else {
fprintf(stderr, "\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n");
fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n");
}
@ -1100,11 +1038,9 @@ int get_tlm_fox() {
id = 0; // 99 in h[6]
// for (int frames = 0; frames < FRAME_CNT; frames++)
for (int frames = 0; frames < frameCnt; frames++)
{
for (int frames = 0; frames < frameCnt; frames++) {
if (firstTime != ON)
{
if (firstTime != ON) {
// delay for sample period
digitalWrite(txLed, txLedOn);
#ifdef DEBUG_LOGGING
@ -1142,17 +1078,14 @@ if (firstTime != ON)
memset(sensor, 0, sizeof(sensor));
memset(other, 0, sizeof(other));
for (count1 = 0; count1 < 8; count1++)
{
if (token != NULL)
{
for (count1 = 0; count1 < 8; count1++) {
if (token != NULL) {
voltage[count1] = atof(token);
#ifdef DEBUG_LOGGING
// printf("voltage: %f ", voltage[count1]);
#endif
token = strtok(NULL, space);
if (token != NULL)
{
if (token != NULL) {
current[count1] = atof(token);
if ((current[count1] < 0) && (current[count1] > -0.5))
current[count1] *= (-1.0);
@ -1166,14 +1099,11 @@ if (firstTime != ON)
// printf("\n");
batteryVoltage = voltage[map[BAT]];
if (batteryVoltage < 3.5)
{
if (batteryVoltage < 3.5) {
NormalModeFailure = 1;
printf("Safe Mode!\n");
}
else
} else
NormalModeFailure = 0;
FILE * cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
@ -1194,8 +1124,7 @@ if (firstTime != ON)
char sensor_payload[500];
if (payload == ON)
{
if (payload == ON) {
STEMBoardFailure = 0;
char c;
@ -1212,20 +1141,15 @@ if (payload == ON)
waitTime = millis() + 500;
int end = FALSE;
// int retry = FALSE;
while ((millis() < waitTime) && !end)
{
while ((millis() < waitTime) && !end) {
int chars = serialDataAvail(uart_fd);
while ((chars-- > 0) && !end)
{
while ((chars--> 0) && !end) {
c = serialGetchar(uart_fd);
// printf ("%c", c);
// fflush(stdout);
if (c != '\n')
{
if (c != '\n') {
sensor_payload[i++] = c;
}
else
{
} else {
end = TRUE;
}
}
@ -1248,10 +1172,8 @@ if (payload == ON)
const char space[2] = " ";
token = strtok(sensor_payload, space);
for (count1 = 0; count1 < 17; count1++)
{
if (token != NULL)
{
for (count1 = 0; count1 < 17; count1++) {
if (token != NULL) {
sensor[count1] = atof(token);
#ifdef DEBUG_LOGGING
printf("sensor: %f ", sensor[count1]);
@ -1265,14 +1187,12 @@ if (payload == ON)
}
if (sim_mode)
{
if (sim_mode) {
// simulated telemetry
double time = (millis() - time_start) / 1000.0;
if ((time - eclipse_time) > period)
{
if ((time - eclipse_time) > period) {
eclipse = (eclipse == 1) ? 0 : 1;
eclipse_time = time;
printf("\n\nSwitching eclipse mode! \n\n");
@ -1325,13 +1245,11 @@ if (sim_mode)
// printf("charging: %f bat curr: %f bus curr: %f bat volt: %f bus volt: %f \n",charging, current[map[BAT]], current[map[BUS]], batt, voltage[map[BUS]]);
batt -= (batt > 3.5) ? current[map[BAT]] / 30000 : current[map[BAT]] / 3000;
if (batt < 3.0)
{
if (batt < 3.0) {
batt = 3.0;
NormalModeFailure = 1;
printf("Safe Mode!\n");
}
else
} else
NormalModeFailure = 0;
if (batt > 4.5)
@ -1342,8 +1260,7 @@ if (sim_mode)
// end of simulated telemetry
}
for (count1 = 0; count1 < 8; count1++)
{
for (count1 = 0; count1 < 8; count1++) {
if (voltage[count1] < voltage_min[count1])
voltage_min[count1] = voltage[count1];
if (current[count1] < current_min[count1])
@ -1357,10 +1274,8 @@ if (sim_mode)
printf("Vmin %f Vmax %f Imin %f Imax %f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]);
}
if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K'))
{
for (count1 = 0; count1 < 17; count1++)
{
if ((sensor_payload[0] == 'O') && (sensor_payload[1] == 'K')) {
for (count1 = 0; count1 < 17; count1++) {
if (sensor[count1] < sensor_min[count1])
sensor_min[count1] = sensor[count1];
if (sensor[count1] > sensor_max[count1])
@ -1370,8 +1285,7 @@ if (sim_mode)
}
}
for (count1 = 0; count1 < 3; count1++)
{
for (count1 = 0; count1 < 3; count1++) {
if (other[count1] < other_min[count1])
other_min[count1] = other[count1];
if (other[count1] > other_max[count1])
@ -1380,16 +1294,13 @@ if (sim_mode)
printf("Other min %f max %f \n", other_min[count1], other_max[count1]);
}
if (loop % 8 == 0)
{
if (loop % 8 == 0) {
printf("Sending MIN frame \n");
frm_type = 0x03;
for (count1 = 0; count1 < 17; count1++)
{
for (count1 = 0; count1 < 17; count1++) {
if (count1 < 3)
other[count1] = other_min[count1];
if (count1 < 8)
{
if (count1 < 8) {
voltage[count1] = voltage_min[count1];
current[count1] = current_min[count1];
}
@ -1397,16 +1308,13 @@ if (sim_mode)
sensor[count1] = sensor_min[count1];
}
}
if ((loop + 4) % 8 == 0)
{
if ((loop + 4) % 8 == 0) {
printf("Sending MAX frame \n");
frm_type = 0x02;
for (count1 = 0; count1 < 17; count1++)
{
for (count1 = 0; count1 < 17; count1++) {
if (count1 < 3)
other[count1] = other_max[count1];
if (count1 < 8)
{
if (count1 < 8) {
voltage[count1] = voltage_max[count1];
current[count1] = current_max[count1];
}
@ -1449,7 +1357,6 @@ if (sim_mode)
negYi = (int)(current[map[MINUS_Y]] + 0.5) + 2048;
negZi = (int)(current[map[MINUS_Z]] + 0.5) + 2048;
posXv = (int)(voltage[map[PLUS_X]] * 100);
posYv = (int)(voltage[map[PLUS_Y]] * 100);
posZv = (int)(voltage[map[PLUS_Z]] * 100);
@ -1471,8 +1378,6 @@ if (sim_mode)
// read payload sensor if available
encodeA(b, 0 + head_offset, batt_a_v);
encodeB(b, 1 + head_offset, batt_b_v);
encodeA(b, 3 + head_offset, batt_c_v);
@ -1490,8 +1395,7 @@ if (sim_mode)
// encodeB(b, 10 + head_offset,(int)(BME280temperature * 10 + 0.5)); // Temp
encodeB(b, 10 + head_offset, (int)(sensor[TEMP] * 10 + 0.5)); // Temp
if (mode == FSK)
{
if (mode == FSK) {
encodeA(b, 12 + head_offset, posXv);
encodeB(b, 13 + head_offset, negXv);
encodeA(b, 15 + head_offset, posYv);
@ -1505,8 +1409,7 @@ if (sim_mode)
encodeB(b, 25 + head_offset, negYi);
encodeA(b, 27 + head_offset, posZi);
encodeB(b, 28 + head_offset, negZi);
}
else // BPSK
} else // BPSK
{
encodeA(b, 12 + head_offset, posXv);
encodeB(b, 13 + head_offset, posYv);
@ -1548,8 +1451,6 @@ if (sim_mode)
encodeA(b, 42 + head_offset, (int)(sensor[GYRO_Y] + 0.5) + 2048);
encodeB(b, 43 + head_offset, (int)(sensor[GYRO_Z] + 0.5) + 2048);
// encodeA(b, 45 + head_offset, (int)(BME280humidity + 0.5)); // in place of sensor1
encodeA(b, 45 + head_offset, (int)(sensor[HUMI] + 0.5)); // in place of sensor1
@ -1562,15 +1463,14 @@ if (sim_mode)
// camera = ON;
int status = STEMBoardFailure + NormalModeFailure * 2 + PayloadFailure1 * 4 + PayloadFailure2 * 8
+ (i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256;
int status = STEMBoardFailure + NormalModeFailure * 2 + PayloadFailure1 * 4 + PayloadFailure2 * 8 +
(i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256;
encodeA(b, 51 + head_offset, status);
// encodeA(b, 51 + head_offset, STEMBoardFailure + NormalModeFailure * 2 + (i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (0) * 128 + 1 * 256 + 1 * 512 + 1 * 1024 + 1*2048);
encodeB(b, 52 + head_offset, rxAntennaDeployed + txAntennaDeployed * 2);
if (txAntennaDeployed == 0)
{
if (txAntennaDeployed == 0) {
txAntennaDeployed = 1;
printf("TX Antenna Deployed!\n");
}
@ -1579,22 +1479,17 @@ if (sim_mode)
int ctr1 = 0;
int ctr3 = 0;
for (i = 0; i < rsFrameLen; i++)
{
for (int j = 0; j < rsFrames ; j++)
{
for (i = 0; i < rsFrameLen; i++) {
for (int j = 0; j < rsFrames; j++) {
if (!((i == (rsFrameLen - 1)) && (j == 2))) // skip last one for BPSK
{
if (ctr1 < headerLen)
{
if (ctr1 < headerLen) {
rs_frame[j][i] = h[ctr1];
update_rs(parities[j], h[ctr1]);
// printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]);
data8[ctr1++] = rs_frame[j][i];
// printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]);
}
else
{
} else {
rs_frame[j][i] = b[ctr3 % dataLen];
update_rs(parities[j], b[ctr3 % dataLen]);
// printf("%d rs_frame[%d][%d] = %x %d \n",
@ -1631,10 +1526,8 @@ if (sim_mode)
rd = nrd; // ^ nrd;
ctr2++;
}
for (i = 0; i < parityLen; i++)
{
for (int j = 0; j < rsFrames; j++)
{
for (i = 0; i < parityLen; i++) {
for (int j = 0; j < rsFrames; j++) {
data10[ctr2++] = (Encode_8b10b[rd][((int) parities[j][i])] & 0x3ff);
nrd = (Encode_8b10b[rd][((int) parities[j][i])] >> 10) & 1;
// printf ("data10[%d] = encoded parities[%d][%d] = %x \n",
@ -1655,8 +1548,7 @@ if (sim_mode)
// printf("\nAt start of buffer loop, syncBits %d samples %d ctr %d\n", syncBits, samples, ctr);
#endif
for (i = 1; i <= syncBits * samples; i++)
{
for (i = 1; i <= syncBits * samples; i++) {
write_wave(ctr, buffer);
// printf("%d ",ctr);
if ((i % samples) == 0) {
@ -1665,17 +1557,13 @@ if (sim_mode)
data = val & 1 << (bit - 1);
// printf ("%d i: %d new frame %d sync bit %d = %d \n",
// ctr/SAMPLES, i, frames, bit, (data > 0) );
if (mode == FSK)
{
if (mode == FSK) {
phase = ((data != 0) * 2) - 1;
// printf("Sending a %d\n", phase);
}
else
{
} else {
if (data == 0) {
phase *= -1;
if ( (ctr - smaller) > 0)
{
if ((ctr - smaller) > 0) {
for (int j = 1; j <= smaller; j++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
@ -1687,8 +1575,7 @@ if (sim_mode)
#ifdef DEBUG_LOGGING
// printf("\n\nValue of ctr after header: %d Buffer Len: %d\n\n", ctr, buffSize);
#endif
for (i = 1;
i <= (10 * (headerLen + dataLen * payloads + rsFrames * parityLen) * samples); i++) // 572
for (i = 1; i <= (10 * (headerLen + dataLen * payloads + rsFrames * parityLen) * samples); i++) // 572
{
write_wave(ctr, buffer);
if ((i % samples) == 0) {
@ -1698,17 +1585,13 @@ if (sim_mode)
data = val & 1 << (bit - 1);
// printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n",
// ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) );
if (mode == FSK)
{
if (mode == FSK) {
phase = ((data != 0) * 2) - 1;
// printf("Sending a %d\n", phase);
}
else
{
} else {
if (data == 0) {
phase *= -1;
if ( (ctr - smaller) > 0)
{
if ((ctr - smaller) > 0) {
for (int j = 1; j <= smaller; j++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
@ -1732,16 +1615,14 @@ if (sim_mode)
// socket write
if (!socket_open && transmit)
{
if (!socket_open && transmit) {
printf("Opening socket!\n");
struct sockaddr_in address;
int valread;
struct sockaddr_in serv_addr;
// char *hello = "Hello from client";
// char buffer[1024] = {0};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("\n Socket creation error \n");
error = 1;
}
@ -1752,14 +1633,12 @@ if (sim_mode)
serv_addr.sin_port = htons(PORT);
// Convert IPv4 and IPv6 addresses from text to binary form
if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
{
if (inet_pton(AF_INET, "127.0.0.1", & serv_addr.sin_addr) <= 0) {
printf("\nInvalid address/ Address not supported \n");
error = 1;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
if (connect(sock, (struct sockaddr * ) & serv_addr, sizeof(serv_addr)) < 0) {
printf("\nConnection Failed \n");
printf("Error: %s \n", strerror(errno));
error = 1;
@ -1770,16 +1649,14 @@ if (sim_mode)
socket_open = 1;
}
if (!error && transmit)
{
if (!error && transmit) {
// digitalWrite (0, LOW);
printf("Sending %d buffer bytes over socket after %d ms!\n", ctr, millis() - start);
start = millis();
int sock_ret = send(sock, buffer, ctr * 2 + 2, 0);
printf("Millis5: %d Result of socket send: %d \n", millis() - start, sock_ret);
if (sock_ret < (ctr * 2 + 2))
{
if (sock_ret < (ctr * 2 + 2)) {
printf("Not resending\n");
// sock_ret = send(sock, buffer[sock_ret], ctr * 2 + 2 - sock_ret, 0);
// printf("Millis10: %d Result of socket send: %d \n", millis() - start, sock_ret);
@ -1791,8 +1668,7 @@ if (sim_mode)
//rpitxStatus = -1;
}
}
if (!transmit)
{
if (!transmit) {
fprintf(stderr, "\nNo CubeSatSim Band Pass Filter detected. No transmissions after the CW ID.\n");
fprintf(stderr, " See http://cubesatsim.org/wiki for info about building a CubeSatSim\n\n");
}
@ -1805,7 +1681,6 @@ if (sim_mode)
return 0;
}
/*
* TelemEncoding.h
*

Loading…
Cancel
Save

Powered by TurnKey Linux.