diff --git a/main.c b/main.c index 2ca7190f..e3a71d2b 100644 --- a/main.c +++ b/main.c @@ -45,7 +45,50 @@ int main(int argc, char * argv[]) { printf("\n\nCubeSatSim v1.3b starting...\n\n"); - wiringPiSetup(); + // Open configuration file with callsign and reset count + FILE * config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r"); + if (config_file == NULL) { + printf("Creating config file."); + config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "w"); + fprintf(config_file, "%s %d", " ", 100); + fclose(config_file); + config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r"); + } + +// char * cfg_buf[100]; + + fscanf(config_file, "%s %d %f %f %s %d %s %s", call, & reset_count, & lat_file, & long_file, sim_yes, & squelch, tx, rx); + fclose(config_file); + printf("Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f %s %d %s %s\n", + call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx); + + printf("==%s==%s==\n", tx, rx); + + program_radio(); + + 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)) { + printf("Valid latitude and longitude in config file\n"); +// convert to APRS DDMM.MM format +// latitude = toAprsFormat(lat_file); +// longitude = toAprsFormat(long_file); + latitude = lat_file; + longitude = long_file; + printf("Lat/Long %f %f\n", latitude, longitude); + printf("Lat/Long in APRS DDMM.MM format: %07.2f/%08.2f\n", toAprsFormat(latitude), toAprsFormat(longitude)); + newGpsTime = millis(); + + } else { // set default +// latitude = toAprsFormat(latitude); +// longitude = toAprsFormat(longitude); + newGpsTime = millis(); + } + + if (strcmp(sim_yes, "yes") == 0) + sim_mode = TRUE; + + wiringPiSetup(); // FILE * rpitx_stop = popen("sudo systemctl stop rpitx", "r"); FILE * rpitx_stop = popen("sudo systemctl restart rpitx", "r"); @@ -137,49 +180,6 @@ int main(int argc, char * argv[]) { fclose(telem_file); printf("Opened telem file\n"); - - // Open configuration file with callsign and reset count - FILE * config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r"); - if (config_file == NULL) { - printf("Creating config file."); - config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "w"); - fprintf(config_file, "%s %d", " ", 100); - fclose(config_file); - config_file = fopen("/home/pi/CubeSatSim/sim.cfg", "r"); - } - -// char * cfg_buf[100]; - - fscanf(config_file, "%s %d %f %f %s %d %s %s", call, & reset_count, & lat_file, & long_file, sim_yes, & squelch, tx, rx); - fclose(config_file); - printf("Config file /home/pi/CubeSatSim/sim.cfg contains %s %d %f %f %s %d %s %s\n", - call, reset_count, lat_file, long_file, sim_yes, squelch, tx, rx); - - printf("==%s==%s==\n", tx, rx); - - program_radio(); - - 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)) { - printf("Valid latitude and longitude in config file\n"); -// convert to APRS DDMM.MM format -// latitude = toAprsFormat(lat_file); -// longitude = toAprsFormat(long_file); - latitude = lat_file; - longitude = long_file; - printf("Lat/Long %f %f\n", latitude, longitude); - printf("Lat/Long in APRS DDMM.MM format: %07.2f/%08.2f\n", toAprsFormat(latitude), toAprsFormat(longitude)); - newGpsTime = millis(); - - } else { // set default -// latitude = toAprsFormat(latitude); -// longitude = toAprsFormat(longitude); - newGpsTime = millis(); - } - - if (strcmp(sim_yes, "yes") == 0) - sim_mode = TRUE; if (mode == AFSK) {