|
|
|
|
@ -88,18 +88,7 @@ int main(void) {
|
|
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
uint8_t data[1024];
|
|
|
|
|
// 0x03 is a UI frame
|
|
|
|
|
// 0x0F is no Level 3 protocol
|
|
|
|
|
// rest is dummy CubeSatSim telemetry in AO-7 format
|
|
|
|
|
// const char *str = "\x03\x0fhi hi 101 102 103 104 202 203 204 205 303 304 305 306 404 405 406 407 408 505 506 507 508 606 607 608 609\n";
|
|
|
|
|
|
|
|
|
|
//int devId = 0x40; // +X Panel current
|
|
|
|
|
//int i2cDevice = wiringPiI2CSetup (devId) ;
|
|
|
|
|
|
|
|
|
|
//int tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48);
|
|
|
|
|
|
|
|
|
|
//srand((unsigned int)(wiringPiI2CReadReg16(tempSensor, 0)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Infinite loop */
|
|
|
|
|
for (;;) {
|
|
|
|
|
sleep(2);
|
|
|
|
|
@ -193,73 +182,7 @@ int upper_digit(int number) {
|
|
|
|
|
}
|
|
|
|
|
int get_tlm(int tlm[][5]) {
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Read MoPower UPS data
|
|
|
|
|
FILE* file = popen("mpcmd show data 2>&1", "r");
|
|
|
|
|
char cmdbuffer[1000];
|
|
|
|
|
fgets(cmdbuffer, 1000, file);
|
|
|
|
|
pclose(file);
|
|
|
|
|
// printf("buffer is :%s\n", cmdbuffer);
|
|
|
|
|
|
|
|
|
|
char mopower[64][14];
|
|
|
|
|
char * data2;
|
|
|
|
|
int i = 0;
|
|
|
|
|
data2 = strtok (cmdbuffer," ");
|
|
|
|
|
while (data2 != NULL) {
|
|
|
|
|
strcpy(mopower[i], data2);
|
|
|
|
|
// printf ("mopwer[%d]=%s\n",i,mopower[i]);
|
|
|
|
|
data2 = strtok (NULL, " ");
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
printf("Battery voltage = %s UPTIME_SEC %s UCTEMP %s \n",
|
|
|
|
|
mopower[VBATT], mopower[UPTIME_SEC], mopower[UCTEMP]);
|
|
|
|
|
|
|
|
|
|
long int time = atoi(mopower[UPTIME_SEC]);
|
|
|
|
|
|
|
|
|
|
if (timestamp == 0)
|
|
|
|
|
timestamp = time;
|
|
|
|
|
|
|
|
|
|
// int tlm_2c = (int)((time - timestamp) / 15) % 100;
|
|
|
|
|
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;
|
|
|
|
|
vbat = strtof(mopower[VBATT], NULL);
|
|
|
|
|
// printf(" vbat: %f \n", vbat);
|
|
|
|
|
// int tlm_3a = (int)((vbat * 10) - 65.5);
|
|
|
|
|
tlm[3][A] = (int)((vbat * 10) - 65.5);
|
|
|
|
|
// int tlm_6b = 0, tlm_2b = 99;
|
|
|
|
|
tlm[6][B] = 0 ;
|
|
|
|
|
tlm[2][B] = 99;
|
|
|
|
|
// printf("TLM 3A = %d \n", tlm_3a);
|
|
|
|
|
|
|
|
|
|
// Read current from I2C bus
|
|
|
|
|
|
|
|
|
|
// printf("\n\nI2C result: %d\n", i2cDevice);
|
|
|
|
|
// printf("Read: %d\n", wiringPiI2CRead(i2cDevice)) ;
|
|
|
|
|
|
|
|
|
|
// int result = wiringPiI2CWriteReg16(xPlusSensor, 0x05, 4096);
|
|
|
|
|
// printf("Write result: %d\n", result);
|
|
|
|
|
*
|
|
|
|
|
int xCurrentValue = wiringPiI2CReadReg16(xPlusSensor, 0x04);
|
|
|
|
|
int yCurrentValue = wiringPiI2CReadReg16(yPlusSensor, 0x04);
|
|
|
|
|
int zCurrentValue = wiringPiI2CReadReg16(zPlusSensor, 0x04);
|
|
|
|
|
int battCurrentValue = wiringPiI2CReadReg16(battCurrentSensor, 0x04);
|
|
|
|
|
printf("Currents: %d %d %d %d \n\n", xCurrentValue, yCurrentValue, zCurrentValue, battCurrentValue);
|
|
|
|
|
*
|
|
|
|
|
|
|
|
|
|
// int tlm_1b = (int) (98.5 - currentValue/400);
|
|
|
|
|
// tlm[1][A] = (int) (98.5 - battCurrentValue/400);
|
|
|
|
|
// tlm[1][B] = (int) (98.5 - xCurrentValue/400);
|
|
|
|
|
// tlm[1][C] = (int) (98.5 - yCurrentValue/400);
|
|
|
|
|
// tlm[1][D] = (int) (98.5 - zCurrentValue/400);
|
|
|
|
|
// 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 I2C voltage and current sensors
|
|
|
|
|
char cmdbuffer[1000];
|
|
|
|
|
FILE* file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r");
|
|
|
|
|
fgets(cmdbuffer, 1000, file);
|
|
|
|
|
@ -271,53 +194,52 @@ int get_tlm(int tlm[][5]) {
|
|
|
|
|
char * data2 = strtok (cmdbuffer," ");
|
|
|
|
|
|
|
|
|
|
while (data2 != NULL) {
|
|
|
|
|
strcpy(ina219[i], data2);
|
|
|
|
|
printf ("ina219[%d]=%s\n",i,ina219[i]);
|
|
|
|
|
data2 = strtok (NULL, " ");
|
|
|
|
|
i++;
|
|
|
|
|
strcpy(ina219[i], data2);
|
|
|
|
|
printf ("ina219[%d]=%s\n",i,ina219[i]);
|
|
|
|
|
data2 = strtok (NULL, " ");
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL));
|
|
|
|
|
// printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL));
|
|
|
|
|
|
|
|
|
|
tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5); // Current of 5V supply to Pi
|
|
|
|
|
tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENT], NULL)/10); // +X current [4]
|
|
|
|
|
tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENT], NULL)/10); // +Y current [7]
|
|
|
|
|
tlm[1][C] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENT], NULL)/10); // +Z current [10] (actually -X current, AO-7 didn't have a Z solar panel?)
|
|
|
|
|
|
|
|
|
|
// int tlm_3b = (int)(strtof(ina219[0], NULL) * 10.0);
|
|
|
|
|
// int tlm_2d = (int)(50.0 + strtof(ina219[SENSOR_4A + VOLTAGE], NULL)/40.0);
|
|
|
|
|
tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0); // 5V supply to Pi
|
|
|
|
|
|
|
|
|
|
tlm[2][B] = 99;
|
|
|
|
|
tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100;
|
|
|
|
|
tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENT], NULL)/10.0); // NiMH Battery current
|
|
|
|
|
|
|
|
|
|
tlm[3][A] = (int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5);
|
|
|
|
|
tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0); // 5V supply to Pi
|
|
|
|
|
|
|
|
|
|
// printf(" 2D: %d 3B: %d\n", tlm_2d, tlm_3b);
|
|
|
|
|
|
|
|
|
|
printf("1A: ina219[%d]: %s val: %f \n", SENSOR_4A + CURRENT, ina219[SENSOR_4A + CURRENT], strtof(ina219[SENSOR_4A + CURRENT], NULL));
|
|
|
|
|
|
|
|
|
|
tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5); // Current of 5V supply to Pi
|
|
|
|
|
|
|
|
|
|
// printf("1A: ina219[%d]: %s val: %f \n", SENSOR_4A + CURRENT, ina219[SENSOR_4A + CURRENT], strtof(ina219[SENSOR_4A + CURRENT], NULL));
|
|
|
|
|
|
|
|
|
|
int tempValue = wiringPiI2CReadReg16(tempSensor, 0);
|
|
|
|
|
// printf("Read: %x\n", tempValue);
|
|
|
|
|
|
|
|
|
|
uint8_t upper = (uint8_t) (tempValue >> 8);
|
|
|
|
|
uint8_t lower = (uint8_t) (tempValue & 0xff);
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5);
|
|
|
|
|
|
|
|
|
|
// printf(" 4A: %d \n", tlm_4a);
|
|
|
|
|
|
|
|
|
|
tlm[6][B] = 0 ;
|
|
|
|
|
tlm[2][B] = 99;
|
|
|
|
|
tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100;
|
|
|
|
|
tlm[6][D] = 49 + rand() % 3;
|
|
|
|
|
|
|
|
|
|
// tlm[5][A] = (int)((95.8 - (atoi(mopower[UCTEMP]) - 30))/1.48 + 0.5);
|
|
|
|
|
printf(" 5A: %d \n", tlm[5][A]);
|
|
|
|
|
// printf(" 5A: %d \n", tlm[5][A]);
|
|
|
|
|
|
|
|
|
|
// int tlm_6d = 49 + rand() % 3;
|
|
|
|
|
tlm[6][D] = 49 + rand() % 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Display tlm
|
|
|
|
|
int k, j;
|
|
|
|
|
for (k = 1; k < 7; k++) {
|
|
|
|
|
for (j = 1; j < 5; j++) {
|
|
|
|
|
|