added debug or d parameter to print extra info

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

@ -25,20 +25,21 @@
#define PLUS_Z 6 #define PLUS_Z 6
#define MINUS_Z 7 #define MINUS_Z 7
#define OFF -1 define OFF -1
#define ON 1 define ON 1
int test_i2c_bus(int bus); int test_i2c_bus(int bus);
const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py "; const char pythonCmd[] = "python3 /home/pi/CubeSatSim/python/voltcurrent.py ";
char pythonStr[100], pythonConfigStr[100], busStr[10]; 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 };
FILE *sopen(const char *program); FILE *sopen(const char *program);
int debug = OFF;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (argc > 1) { if (argc > 1) {
; if ( * argv[1] == 'd') {
} debug = ON;
wiringPiSetup (); wiringPiSetup ();
@ -55,8 +56,6 @@ int main(int argc, char *argv[]) {
map[PLUS_Z] = BAT; map[PLUS_Z] = BAT;
map[MINUS_Z] = PLUS_Z; map[MINUS_Z] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
printf("New Bus String: %s \n", busStr);
/* /*
if (access("/dev/i2c-0", W_OK | R_OK) >= 0) { // Test if I2C Bus 0 is present if (access("/dev/i2c-0", W_OK | R_OK) >= 0) { // Test if I2C Bus 0 is present
printf("/dev/i2c-0 is present\n\n"); printf("/dev/i2c-0 is present\n\n");
@ -97,10 +96,6 @@ int main(int argc, char *argv[]) {
map[BAT] = BUS; map[BAT] = BUS;
map[BUS] = BAT; map[BUS] = BAT;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
printf("New Bus String: %s \n", busStr);
// strcpy(busStr,"1 0"); // strcpy(busStr,"1 0");
} }
else else
@ -114,9 +109,7 @@ int main(int argc, char *argv[]) {
map[MINUS_X] = MINUS_Y; map[MINUS_X] = MINUS_Y;
map[PLUS_Z] = MINUS_X; map[PLUS_Z] = MINUS_X;
map[MINUS_Y] = PLUS_Z; map[MINUS_Y] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(3)); if (debug == ON)
printf("New Bus String: %s \n", busStr);
/* /*
if (test_i2c_b0) != OFF) if (test_i2c_b0) != OFF)
strcpy(busStr,"1 "); strcpy(busStr,"1 ");
@ -189,10 +182,6 @@ int main(int argc, char *argv[]) {
map[BAT] = BUS; map[BAT] = BUS;
map[PLUS_Z] = BAT; map[PLUS_Z] = BAT;
map[MINUS_Z] = PLUS_Z; map[MINUS_Z] = PLUS_Z;
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
printf("New Bus String: %s \n", busStr);
/* /*
if (access("/dev/i2c-0", W_OK | R_OK) >= 0) { // Test if I2C Bus 0 is present if (access("/dev/i2c-0", W_OK | R_OK) >= 0) { // Test if I2C Bus 0 is present
printf("/dev/i2c-0 is present\n\n"); printf("/dev/i2c-0 is present\n\n");
@ -227,7 +216,7 @@ int main(int argc, char *argv[]) {
// Reading I2C voltage and current sensors // Reading I2C voltage and current sensors
// printf("Starting\n"); // printf("Starting\n");
strcpy(pythonStr, pythonCmd); strcpy(pythonStr, pythonCmd);
strcat(pythonStr, busStr); strcat(pythonStr, busStr);
strcat(pythonConfigStr, pythonStr); strcat(pythonConfigStr, pythonStr);
@ -236,7 +225,12 @@ int main(int argc, char *argv[]) {
char cmdbuffer[1000]; char cmdbuffer[1000];
FILE *file1 = sopen(pythonConfigStr); // try new function FILE *file1 = sopen(pythonConfigStr); // try new function
fgets(cmdbuffer, 1000, file1); fgets(cmdbuffer, 1000, file1);
fprintf(stderr, "pythonStr result: %s\n", cmdbuffer); if (debug == ON)
{
snprintf(busStr, 10, "%d %d", test_i2c_bus(1), test_i2c_bus(0));
printf("New Bus String: %s \n", busStr);
fprintf(stderr, "pythonStr result: %s\n", cmdbuffer);
}
// FILE* file1 = popen(pythonConfigStr, "r"); // FILE* file1 = popen(pythonConfigStr, "r");
// fgets(cmdbuffer, 1000, file1); // fgets(cmdbuffer, 1000, file1);
// printf("pythonStr result: %s\n", cmdbuffer); // printf("pythonStr result: %s\n", cmdbuffer);

Loading…
Cancel
Save

Powered by TurnKey Linux.