Example #1
0
def get_gps_fix():
    log_txt("Waiting for GPS link")

    # Run gpsFix.py, which returns JSON output to stdout
    cmd_ = os.path.join(mod_settings.settings['pythonPath'], "gpsFix.py")
    gps_process = subprocess.Popen(cmd_, shell=True, stdout=subprocess.PIPE)
    gps_fix_json = gps_process.stdout.read()
    try:
        gps_result = json.loads(gps_fix_json)
    except ValueError:
        log_txt("Could not read valid JSON response from gpsFix.py")
        gps_result = False

    # If true, we get a structure with fields "offset", "latitude" and "longitude"
    if isinstance(gps_result, dict):
        t_offset = gps_result['offset']
        gps_latitude = gps_result['latitude']
        gps_longitude = gps_result['longitude']
        gps_altitude = gps_result['altitude']
        log_txt("GPS link achieved")
        log_txt(
            "Longitude = %.6f ; Latitude = %.6f ; Altitude = %.6f ; Clock offset: %.2f sec behind."
            % (gps_longitude, gps_latitude, gps_altitude, t_offset))
        set_utc_offset(t_offset)

        # Use the time shell command to update the system clock (required root access)
        log_txt("Trying to update system clock")
        utc_now = get_utc()
        os.system("date -s @%d" % utc_now)

        # Because the above may fail if we don't have root access, as a fallback we recalculate the clock offset
        t_offset = utc_now - time.time()
        set_utc_offset(t_offset)
        log_txt(
            "Revised clock offset after trying to set the system clock: %.2f sec behind."
            % t_offset)

        return {
            'latitude': gps_latitude,
            'longitude': gps_longitude,
            'altitude': gps_altitude
        }

    # If false, we didn't manage to establish a GPS link
    else:
        log_txt("Gave up waiting for a GPS link")
        return None
Example #2
0
                                       mark_type=hwm_output,
                                       time=0)
            high_water = db.get_high_water_mark(obstory_name=obstory_name,
                                                mark_type=hwm_output)
            for task in task_list:
                out_dirs = task[1]

                # Remove any output which is newer than HWM
                for out_dir in out_dirs:
                    for dir_name, subdir_list, file_list in os.walk(out_dir):
                        for f in file_list:
                            utc = mod_log.filename_to_utc(f)
                            if utc < 0:
                                continue
                            if utc > high_water:
                                os.system("rm -f %s" %
                                          os.path.join(dir_name, f))

    os.chdir(cwd)
    log_txt("Finished daytimeJobsClean")


# If we're called as a script, run the method exportData()
if __name__ == "__main__":
    utc_now = time.time()
    if len(sys.argv) > 1:
        utc_now = float(sys.argv[1])
    mod_log.set_utc_offset(utc_now - time.time())
    dbh = meteorpi_db.MeteorDatabase(mod_settings.settings['dbFilestore'])
    day_time_jobs_clean(dbh)
Example #3
0
import mod_log
import mod_settings
import orientationCalc
from mod_log import log_txt, get_utc

pid = os.getpid()
db = meteorpi_db.MeteorDatabase(mod_settings.settings['dbFilestore'])

# User should supply unix time on commandline at which we are to stop work
if len(sys.argv) != 3:
    print "Need to call daytimeJobs.py with clock offset, and an end time to tell it when it needs to quit by."
    sys.exit(1)

utc_offset = float(sys.argv[1])
quit_time = float(sys.argv[2])
mod_log.set_utc_offset(utc_offset)

log_txt("Running daytimeJobs. Need to quit at %s." %
        mod_astro.time_print(quit_time))

# Clean up any output files which are ahead of high water marks
log_txt("Cleaning up any output files which are ahead of high water marks")
daytimeJobsClean.day_time_jobs_clean(db)

# Change into the directory where data files are kept
cwd = os.getcwd()
os.chdir(mod_settings.settings['dataPath'])


# Run a list of shell commands in parallel
# Pass a list of job descriptor dictionaries, each having a cmd template, and a dictionary of params to substitute