Ejemplo n.º 1
0
def update_specific_param(parameters, parameters_file_name):

    # Get the cam_pwd & ip
    config = read_config_raw()

    #Add Specific parameters for calib/day/night
    if (parameters_file_name == 'Night'):

        #Add to parameters string
        parameters += "&InfraredLamp=high"
        parameters += "&TRCutLevel=high"

        ## WR - ON
        set_special(config, "1037", "0")

    elif (parameters_file_name == 'Day'):

        ## WR - OFF
        set_special(config, "1037", "1")

        #Add to parameters string
        parameters += "&InfraredLamp=low"
        parameters += "&TRCutLevel=low"

    return parameters
Ejemplo n.º 2
0
def set_parameters(_file, argv):

    #Ex:
    #python ./cam/set_parameters.py '{"Brightness": 29}'

    config = read_config_raw()
    possible_values = ['Brightness', 'Contrast', 'Gamma']

    logging.debug('Set parameters for ' + _file)
    logging.debug('Parameters ' + str(argv))

    # Get Parameters passed in arg
    if (len(argv) != 0):

        new_values = json.loads(argv[0])

        parameters = ''

        for key in new_values:
            if key in possible_values:
                parameters += '&' + key + '=' + str(new_values[key])

        if (parameters != ''):
            # Get Specific Parameters
            parameters = update_specific_param(parameters, _file)

            # Update Cam Parameters
            update_cam(parameters)

        else:
            print('No Parameters to Update')

    else:
        print('No Parameters to Update (argv)')
Ejemplo n.º 3
0
def update_cam(parameters):
    # Get the cam_pwd
    config = read_config_raw()

    # Update the cam live parameters
    fname = 'http://' + config[
        'cam_ip'] + '/cgi-bin/videoparameter_cgi?action=set&channel=0&user=admin&pwd=' + config[
            'cam_pwd'] + parameters

    # Call to CGI
    urllib.urlopen(fname)

    logging.debug('Set Cam Parameter ' + fname)
Ejemplo n.º 4
0
def update_parameters(_file, new_values):

    possible_values = ['Brightness', 'Contrast', 'Gamma', 'Chroma', 'File']
    special_values = ['Exposure']
    parameters = ''
    special_parameters = {}

    # Build the parameters URL string
    for key in new_values:

        if key in possible_values and key != 'file' and key != 'File':
            parameters += '&' + key + '=' + str(new_values[key])

        if key in special_values:
            if (key == 'Exposure'):
                special_parameters['1058'] = str(new_values[key])

    if (parameters != '' or len(special_parameters) > 0):

        if (parameters != ''):
            # Get Specific Parameters
            parameters = update_specific_param(parameters, _file)

            # Update Cam Parameters
            update_cam(parameters)

        if (len(special_parameters) > 0):

            config = read_config_raw()

            for k in special_parameters:
                set_special(config, str(k), str(special_parameters[k]))

        # Replace only the new values passed in the calib file
        log_file = "/home/pi/fireball_camera/cam_calib/" + _file

        for key in new_values:
            if key != 'file':
                v = str(key)
                r = re.compile(r"(" + v + ")=(\d*)")

                for line in fileinput.input([log_file], inplace=True):
                    # Search the current value for new_values[key]
                    newV = new_values[key]
                    print r.sub(r"\1=%s" % newV, line.strip())

    else:
        print('No Parameters to Update')
Ejemplo n.º 5
0
        urllib.urlopen(fname)
         
        # Encrypt the Cam Password to store it in the config file 
        try:
            c     = Crypt()
            value = c.encrypt(value)
            logging.debug('cam_pwd successfully encrypted') 
            
            # Write new pwd in config.txt
            line = "cam_pwd=" + str(value) + "\n"
            file.write(line)   
        except:
            logging.error('IMPOSSIBLE to encrypted the following cam_pwd ' + str(value))
            logging.debug('Config (ERROR) ' + str(config))
        
        del tmp_config['new_cam_pwd']


logging.debug('Updating config.txt') 
for key in tmp_config:
    value = tmp_config[key]
    line = str(key) + "=" + str(value) + "\n"
    logging.debug(str(key) + "=" + str(value)) 
    file.write(line)
        
file.close()
logging.debug('config.txt updated') 

#Read again before sending  
configN = read_config_raw();
print json.dumps(configN, ensure_ascii=False)
Ejemplo n.º 6
0
def get_sun_info():

    config = read_config_raw()

    obs = ephem.Observer()
    obs.pressure = 0
    obs.horizon = '-0:34'
    obs.lat = config['device_lat']
    obs.lon = config['device_lng']
    cur_date = time.strftime("%Y/%m/%d %H:%M")  # Get Current Date
    obs.date = cur_date

    sun = ephem.Sun()
    sun.compute(obs)

    (sun_alt, x, y) = str(sun.alt).split(":")

    #Sun Altitude
    #print ("Sun Alt: %s" % (sun_alt))

    saz = str(sun.az)
    (sun_az, x, y) = saz.split(":")

    #print ("SUN AZ IS : %s" % sun_az)
    #print ("CAM FOV IS : %s to %s " % (config['az_left'], config['az_right']))

    if (int(sun_az) >= config['az_left']
            and int(sun_az) <= config['az_right']):
        #print ("Uh Oh... Sun is in the cam's field of view.")
        fov = 1
    else:
        #print ("Sun is not in the cam's field of view")
        fov = 0

    #print (obs.previous_rising(ephem.Sun()))
    #print (obs.next_setting(ephem.Sun()))

    if int(sun_alt) < -3:
        dark = 1
    else:
        dark = 0

    if int(sun_alt) < -3:
        status = "dark"
    if int(sun_alt) > -3 and int(sun_alt) < 5:
        if int(sun_az) > 0 and int(sun_az) < 180:
            status = "dawn"
        else:
            status = "dusk"
    if int(sun_alt) >= 5:
        status = "day"

    # UPDATE sun.txt
    sun_file = open("/home/pi/fireball_camera/sun.txt", "w")
    sun_file.write("az=" + str(sun_az) + "\n" + "el=" + str(sun_alt) + "\n" +
                   "fov=" + str(fov) + "\n" + "dark=" + str(dark) + "\n" +
                   "status=" + str(status) + "\n")
    sun_file.close()

    # RETURN ARRAY OF DATA
    return json.dumps(
        {
            'az': sun_az,
            'el': sun_alt,
            'fov': fov,
            'dark': dark,
            'status': status
        },
        ensure_ascii=False,
        encoding="utf-8")