Update cw_main.c

pull/1/head
alanbjohnston 7 years ago committed by GitHub
parent 8435b6a383
commit 37db2a567d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -42,6 +42,10 @@
#define TIME 8 #define TIME 8
#define UCTEMP 30 #define UCTEMP 30
#define UPTIME_SEC 8 #define UPTIME_SEC 8
#define A 1
#define B 2
#define C 3
#define D 4
long int timestamp = 0; long int timestamp = 0;
extern uint8_t axradio_rxbuffer[]; extern uint8_t axradio_rxbuffer[];
@ -464,33 +468,37 @@ int get_tlm(int tlm[][5]) {
if (timestamp == 0) if (timestamp == 0)
timestamp = time; timestamp = time;
int tlm_2c = (int)((time - timestamp) / 15) % 100; // int tlm_2c = (int)((time - timestamp) / 15) % 100;
printf("Relative time: %ld seconds 2C: %d 2C: %d%d\n", time - timestamp,tlm_2c, upper_digit(tlm_2c), lower_digit(tlm_2c)); tlm[2][C] = (int)((time - timestamp) / 15) % 100;
// printf("Relative time: %ld seconds 2C: %d 2C: %d%d\n", time - timestamp,tlm_2c, upper_digit(tlm_2c), lower_digit(tlm_2c));
float vbat; float vbat;
vbat = strtof(mopower[VBATT], NULL); vbat = strtof(mopower[VBATT], NULL);
printf(" vbat: %f \n", vbat); printf(" vbat: %f \n", vbat);
int tlm_3a = (int)((vbat * 10) - 65.5); // int tlm_3a = (int)((vbat * 10) - 65.5);
int tlm_6b = 0, tlm_2b = 99; tlm[3][A] = (int)((vbat * 10) - 65.5);
printf("TLM 3A = %d \n", tlm_3a); // int tlm_6b = 0, tlm_2b = 99;
tlm[6][B] = 0, tlm_2b = 99;
// printf("TLM 3A = %d \n", tlm_3a);
// Read current from I2C bus // Read current from I2C bus
// printf("\n\nI2C result: %d\n", i2cDevice); // printf("\n\nI2C result: %d\n", i2cDevice);
// printf("Read: %d\n", wiringPiI2CRead(i2cDevice)) ; // printf("Read: %d\n", wiringPiI2CRead(i2cDevice)) ;
int result = wiringPiI2CWriteReg16(xPlusSensor, 0x05, 4096); // int result = wiringPiI2CWriteReg16(xPlusSensor, 0x05, 4096);
printf("Write result: %d\n", result); // printf("Write result: %d\n", result);
int currentValue = wiringPiI2CReadReg16(xPlusSensor, 0x04); int currentValue = wiringPiI2CReadReg16(xPlusSensor, 0x04);
printf("Current: %d\n\n\n", currentValue); // printf("Current: %d\n\n\n", currentValue);
int tlm_1b = (int) (98.5 - currentValue/400); // int tlm_1b = (int) (98.5 - currentValue/400);
printf("TLM 1B = %d \n\n", tlm_1b); tlm[1][B] = (int) (98.5 - currentValue/400);
int tlm_1a = 0, tlm_1c = 98, tlm_1d = 98, tlm_2a = 98; // printf("TLM 1B = %d \n\n", tlm_1b);
// int tlm_1a = 0, tlm_1c = 98, tlm_1d = 98, tlm_2a = 98;
// Reading 5V voltage and current // Reading 5V voltage and current
file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r"); file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r");
fgets(cmdbuffer, 1000, file); fgets(cmdbuffer, 1000, file);
pclose(file); pclose(file);
@ -507,12 +515,14 @@ int get_tlm(int tlm[][5]) {
i++; i++;
} }
int tlm_3b = (int)(strtof(battery[0], NULL) * 10.0); // int tlm_3b = (int)(strtof(battery[0], NULL) * 10.0);
int tlm_2d = (int)(50.0 + strtof(battery[1], NULL)/40.0); // int tlm_2d = (int)(50.0 + strtof(battery[1], NULL)/40.0);
printf(" 2D: %d 3B: %d\n", tlm_2d, tlm_3b); tlm[3][B] = (int)(strtof(battery[0], NULL) * 10.0);
tlm[2][D] = (int)(50.0 + strtof(battery[1], NULL)/40.0);
// printf(" 2D: %d 3B: %d\n", tlm_2d, tlm_3b);
int tempValue = wiringPiI2CReadReg16(tempSensor, 0); int tempValue = wiringPiI2CReadReg16(tempSensor, 0);
printf("Read: %x\n", tempValue); // printf("Read: %x\n", tempValue);
uint8_t upper = (uint8_t) (tempValue >> 8); uint8_t upper = (uint8_t) (tempValue >> 8);
uint8_t lower = (uint8_t) (tempValue & 0xff); uint8_t lower = (uint8_t) (tempValue & 0xff);
@ -520,11 +530,13 @@ int get_tlm(int tlm[][5]) {
float temp = (float)lower + ((float)upper / 0x100); float temp = (float)lower + ((float)upper / 0x100);
printf("upper: %x lower: %x temp: %f\n", upper, lower, temp); printf("upper: %x lower: %x temp: %f\n", upper, lower, temp);
int tlm_4a = (int)((95.8 - temp)/1.48 + 0.5); // int tlm_4a = (int)((95.8 - temp)/1.48 + 0.5);
printf(" 4A: %d \n", tlm_4a); tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5);
// printf(" 4A: %d \n", tlm_4a);
int tlm_6d = 49 + rand() % 3;
// int tlm_6d = 49 + rand() % 3;
tlm[6][D] = 49 + rand() % 3;
/*
char tlm_str[1000]; char tlm_str[1000];
printf("%d %d %d %d %d %d %d %d %d %d %d %d %d \n", tlm_1a, tlm_1b, tlm_1c, tlm_1d, tlm_2a, tlm_2b, tlm_2c, tlm_2d, tlm_3a, tlm_3b, tlm_4a, tlm_6b, tlm_6d); printf("%d %d %d %d %d %d %d %d %d %d %d %d %d \n", tlm_1a, tlm_1b, tlm_1c, tlm_1d, tlm_2a, tlm_2b, tlm_2c, tlm_2d, tlm_3a, tlm_3b, tlm_4a, tlm_6b, tlm_6d);
@ -554,6 +566,6 @@ int get_tlm(int tlm[][5]) {
upper_digit(tlm_6d), lower_digit(tlm_6d)); upper_digit(tlm_6d), lower_digit(tlm_6d));
printf("%s\n",tlm_str); printf("%s\n",tlm_str);
*/
return 0; return 0;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.