Update main.c fix get_tlm_fox {}

pi-sensors-auto-gps
Alan Johnston 5 days ago committed by GitHub
parent ff90373130
commit 39ebc247c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

117
main.c

@ -1384,8 +1384,7 @@ void get_tlm_fox() {
int buffSize;
buffSize = (int)sizeof(buffer_test);
if (failureMode == FAIL_NONE)
printf("No Simulated Failure!\n");
if (failureMode == FAIL_NONE) printf("No Simulated Failure!\n");
// if (failureMode == -1) {
// failureMode = (int) rnd_float(1, FAIL_COUNT);
// printf("Random Failure\n");
@ -1447,7 +1446,6 @@ void get_tlm_fox() {
// for (int frames = 0; frames < FRAME_CNT; frames++)
for (int frames = 0; frames < frameCnt; frames++) {
// if (firstTime != ON) {
if (TRUE) {
// delay for sample period
@ -1476,34 +1474,26 @@ void get_tlm_fox() {
// if (mode == FSK)
{ // just moved
for (int count1 = 0; count1 < 8; count1++) {
if (voltage[count1] < voltage_min[count1])
voltage_min[count1] = voltage[count1];
if (current[count1] < current_min[count1])
current_min[count1] = current[count1];
if (voltage[count1] < voltage_min[count1]) voltage_min[count1] = voltage[count1];
if (current[count1] < current_min[count1]) current_min[count1] = current[count1];
if (voltage[count1] > voltage_max[count1])
voltage_max[count1] = voltage[count1];
if (current[count1] > current_max[count1])
current_max[count1] = current[count1];
if (voltage[count1] > voltage_max[count1]) voltage_max[count1] = voltage[count1];
if (current[count1] > current_max[count1]) current_max[count1] = current[count1];
// printf("Vmin %4.2f Vmax %4.2f Imin %4.2f Imax %4.2f \n", voltage_min[count1], voltage_max[count1], current_min[count1], current_max[count1]);
}
for (int count1 = 0; count1 < 3; count1++) {
if (other[count1] < other_min[count1])
other_min[count1] = other[count1];
if (other[count1] > other_max[count1])
other_max[count1] = other[count1];
if (other[count1] < other_min[count1]) other_min[count1] = other[count1];
if (other[count1] > other_max[count1]) other_max[count1] = other[count1];
// printf("Other min %f max %f \n", other_min[count1], other_max[count1]);
}
if (mode == FSK)
{
if (mode == FSK) {
if (loop % 32 == 0) { // was 8
// printf("Sending MIN frame \n");
frm_type = 0x03;
for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) {
if (count1 < 3)
other[count1] = other_min[count1];
if (count1 < 3) other[count1] = other_min[count1];
if (count1 < 8) {
voltage[count1] = voltage_min[count1];
current[count1] = current_min[count1];
@ -1516,8 +1506,7 @@ void get_tlm_fox() {
// printf("Sending MAX frame \n");
frm_type = 0x02;
for (int count1 = 0; count1 < SENSOR_FIELDS; count1++) {
if (count1 < 3)
other[count1] = other_max[count1];
if (count1 < 3) other[count1] = other_max[count1];
if (count1 < 8) {
voltage[count1] = voltage_max[count1];
current[count1] = current_max[count1];
@ -1526,8 +1515,7 @@ void get_tlm_fox() {
sensor[count1] = sensor_max[count1];
}
}
}
else
} else
frm_type = 0x02; // BPSK always send MAX MIN frame
}
sensor_payload[0] = 0; // clear for next payload
@ -1550,8 +1538,7 @@ void get_tlm_fox() {
h[5] = (short int)((h[5] & 0xf0) | ((uptime >> 21) & 0x0f));
h[5] = (short int)((h[5] & 0x0f) | (frm_type << 4));
if (mode == BPSK)
h[6] = 99;
if (mode == BPSK) h[6] = 99;
posXi = (int)(current[map[PLUS_X]] + 0.5) + 2048;
posYi = (int)(current[map[PLUS_Y]] + 0.5) + 2048;
@ -1572,8 +1559,7 @@ void get_tlm_fox() {
BAT2Voltage = (int)(voltage[map[BAT2]] * 100);
BAT2Current = (int)(current[map[BAT2]] + 0.5) + 2048;
if (payload == ON)
STEMBoardFailure = 0;
if (payload == ON) STEMBoardFailure = 0;
// read payload sensor if available
@ -1662,9 +1648,7 @@ void get_tlm_fox() {
encodeB(b_max, 49 + head_offset, (int)(sensor_max[XS1]));
encodeA(b_max, 0 + head_offset, (int)(sensor_max[XS2]));
encodeB(b_max, 1 + head_offset, (int)(sensor_max[XS3]));
}
else
{
} else {
encodeB(b_max, 4 + head_offset, 2048); // 0
encodeA(b_max, 6 + head_offset, 2048); // 0
encodeB(b_max, 7 + head_offset, 2048); // 0
@ -1719,9 +1703,7 @@ void get_tlm_fox() {
encodeB(b_min, 49 + head_offset, (int)(sensor_min[XS1]));
encodeA(b_min, 0 + head_offset, (int)(sensor_min[XS2]));
encodeB(b_min, 1 + head_offset, (int)(sensor_min[XS3]));
}
else
{
} else {
encodeB(b_min, 4 + head_offset, 2048); // 0
encodeA(b_min, 6 + head_offset, 2048); // 0
encodeB(b_min, 7 + head_offset, 2048); // 0
@ -1741,26 +1723,25 @@ void get_tlm_fox() {
encodeA(b, 33 + head_offset, (int)(sensor[PRES] + 0.5)); // Pressure
encodeB(b, 34 + head_offset, (int)(sensor[ALT] / 10.0 + 0.5)); // Altitude
encodeB(b_min, 49 + head_offset, (int)(sensor_min[XS1]));
encodeA(b_min, 0 + head_offset, (int)(sensor_min[XS2]));
encodeB(b_min, 1 + head_offset, (int)(sensor_min[XS3]));
}
else
{
encodeB(b_min, 4 + head_offset, 2048); // 0
encodeA(b_min, 6 + head_offset, 2048); // 0
encodeB(b_min, 7 + head_offset, 2048); // 0
encodeB(b_min, 40 + head_offset, 2048);
encodeA(b_min, 42 + head_offset, 2048);
encodeB(b_min, 43 + head_offset, 2048);
encodeA(b_min, 48 + head_offset, 2048);
// encodeB(b_min, 49 + head_offset, 2048);
}
}
// }
// else
// {
// encodeB(b_min, 4 + head_offset, 2048); // 0
// encodeA(b_min, 6 + head_offset, 2048); // 0
// encodeB(b_min, 7 + head_offset, 2048); // 0
//
// encodeB(b_min, 40 + head_offset, 2048);
// encodeA(b_min, 42 + head_offset, 2048);
// encodeB(b_min, 43 + head_offset, 2048);
//
// encodeA(b_min, 48 + head_offset, 2048);
// // encodeB(b_min, 49 + head_offset, 2048);
// }
//
// }
encodeA(b, 30 + head_offset, BAT2Voltage);
encodeB(b, 31 + head_offset, ((int)(other[SPIN] * 10)) + 2048);
@ -1773,7 +1754,6 @@ void get_tlm_fox() {
encodeA(b, 36 + head_offset, Resets);
encodeB(b, 37 + head_offset, (int)(other[RSSI] + 0.5) + 2048);
encodeB(b, 40 + head_offset, (int)(sensor[GYRO_X] + 0.5) + 2048);
encodeA(b, 42 + head_offset, (int)(sensor[GYRO_Y] + 0.5) + 2048);
encodeB(b, 43 + head_offset, (int)(sensor[GYRO_Z] + 0.5) + 2048);
@ -1790,8 +1770,7 @@ void get_tlm_fox() {
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);
if ((fgets(count_string, 10, command_count_file)) != NULL) groundCommandCount = atoi(count_string);
// fclose(command_count_file);
} else
printf("Error opening command_count.txt!\n");
@ -1817,8 +1796,7 @@ void get_tlm_fox() {
}
// int status = STEMBoardFailure + SafeMode * 2 + sim_mode * 4 + PayloadFailure1 * 8 +
// (i2c_bus0 == OFF) * 16 + (i2c_bus1 == OFF) * 32 + (i2c_bus3 == OFF) * 64 + (camera == OFF) * 128 + groundCommandCount * 256;
int status = STEMBoardFailure + SafeMode * 2 + simulated * 4 + PayloadFailure1 * 8 +
(i2c_bus0 == OFF) * 16 + (i2c_1 == OFF) * 32 + (i2c_3 == OFF) * 64 + (cam == OFF) * 128 + groundCommandCount * 256;
int status = STEMBoardFailure + SafeMode * 2 + simulated * 4 + PayloadFailure1 * 8 + (i2c_bus0 == OFF) * 16 + (i2c_1 == OFF) * 32 + (i2c_3 == OFF) * 64 + (cam == OFF) * 128 + groundCommandCount * 256;
encodeA(b, 51 + head_offset, status);
encodeB(b, 52 + head_offset, rxAntennaDeployed + txAntennaDeployed * 2 + c2cStatus * 4);
@ -1864,28 +1842,21 @@ void get_tlm_fox() {
data8[ctr1++] = rs_frame[j][i];
// printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]);
} else {
if (mode == FSK)
{
if (mode == FSK) {
rs_frame[j][i] = b[ctr3 % dataLen];
update_rs(parities[j], b[ctr3 % dataLen]);
} else // BPSK
if ((int)(ctr3/dataLen) == 3)
{
if ((int)(ctr3 / dataLen) == 3) {
rs_frame[j][i] = b_max[ctr3 % dataLen];
update_rs(parities[j], b_max[ctr3 % dataLen]);
}
else if ((int)(ctr3/dataLen) == 4)
{
} else if ((int)(ctr3 / dataLen) == 4) {
rs_frame[j][i] = b_min[ctr3 % dataLen];
update_rs(parities[j], b_min[ctr3 % dataLen]);
}
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",
// ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN);
@ -1962,8 +1933,7 @@ void get_tlm_fox() {
if (data == 0) {
phase *= -1;
if ((ctr - smaller) > 0) {
for (int j = 1; j <= smaller; j++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
for (int j = 1; j <= smaller; j++) buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
flip_ctr = ctr;
}
@ -1990,8 +1960,7 @@ void get_tlm_fox() {
if (data == 0) {
phase *= -1;
if ((ctr - smaller) > 0) {
for (int j = 1; j <= smaller; j++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
for (int j = 1; j <= smaller; j++) buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
flip_ctr = ctr;
}
@ -2116,14 +2085,12 @@ void get_tlm_fox() {
max = 4; // 5; // was 6
else
max = 3;
else
if (firstTime == 1)
else if (firstTime == 1)
max = 5; // 5; // was 6
else
max = 4;
for (int times = 0; times < max; times++)
{
for (int times = 0; times < max; times++) {
/// start = millis(); // send frame until buffer fills
socket_send(ctr);
/// sock_ret = send(sock, buffer, (unsigned int)(ctr * 2 + 2), 0);

Loading…
Cancel
Save

Powered by TurnKey Linux.