Exemplo n.º 1
0
def update_server_info(s_info):
    if not ('address' in s_info and 'port' in s_info):
        return False, 'address or port is missing'
    server_info, conf = confmgr.get_conf_section('SERVER')
    server_info['address'] = s_info['address']
    server_info['port'] = str(s_info['port'])
    confmgr.update_conf(conf)
    return True, 'updated'
Exemplo n.º 2
0
def update_bracelet_info(bracelet_id, mac):
    if bracelet_id > 2:
        return False, 'not found'
    bracelet_conf, conf = confmgr.get_conf_section('BRACELET')
    if bracelet_id == 1:
        bracelet_conf['bracelet1'] = mac
    else:
        bracelet_conf['bracelet2'] = mac
    confmgr.update_conf(conf)
    return True, 'updated'
Exemplo n.º 3
0
def add_bracelet(mac):
    # 保证先加bracelet1,  然后加bracelet2
    bracelet_conf, conf = confmgr.get_conf_section('BRACELET')
    if bracelet_conf['bracelet1'] != '' and bracelet_conf['bracelet2'] != '':
        return False, 'Only two bracelets supported'
    if bracelet_conf['bracelet1'] == '':
        bracelet_conf['bracelet1'] = mac
    else:
        bracelet_conf['bracelet2'] = mac
    confmgr.update_conf(conf)
    return True, 'added'
Exemplo n.º 4
0
def update_wifi_info(w_info):
    if not ('name' in w_info):
        return False, 'wifi name is missing'
    wifi_info, conf = confmgr.get_conf_section('WIFI')
    wifi_info['name'] = w_info['name']
    if 'password' in w_info:
        wifi_info['password'] = w_info['password']
    else:
        wifi_info['password'] = ''
    confmgr.update_conf(conf)
    updateWifi.updateWifi(w_info['name'], w_info['password'], '5')
    return True, 'updated'
Exemplo n.º 5
0
def update_settings(s):
    if not ('cameraResolution' in s and 'audioFrequency' in s):
        return False, 'cameraResolution or audioFrequency is missing'
    setting_conf, conf = confmgr.get_conf_section('SETTINGS')
    setting_conf['camera_resolution'] = s['cameraResolution']
    setting_conf['audio_frequency'] = str(s['audioFrequency'])
    if 'gpsCoord' in s:
        setting_conf['gps'] = s['gpsCoord']
    else:
        setting_conf['gps'] = ''
    confmgr.update_conf(conf)
    return True, 'updated'
Exemplo n.º 6
0
def delete_bracelet(bracelet_id):
    # conn = dbmgr.get_connection()
    # try:
    #     cursor = conn.cursor()
    #     cursor.execute('delete from robot_conf.bracelet where id = ' + bracelet_id)
    #     conn.commit()
    #     return True, 'deleted'
    # except IOError:
    #     conn.rollback()
    #     return False, 'deleted failed'
    # finally:
    #     conn.close()
    if bracelet_id > 2:
        return False, 'not found'
    bracelet_conf, conf = confmgr.get_conf_section('BRACELET')
    if bracelet_id == 1:
        bracelet_conf['bracelet1'] = ''
    else:
        bracelet_conf['bracelet2'] = ''
    confmgr.update_conf(conf)
    return True, 'deleted'
Exemplo n.º 7
0
def update_wifi_info(w_info):
    if not ('name' in w_info):
        return False, 'wifi name is missing'
    # conn = dbmgr.get_connection()
    # try:
    #     cursor = conn.cursor()
    #     cursor.execute('delete from robot_conf.wifi')
    #     add_sql = 'insert into robot_conf.wifi(name, password) values (%s, %s)'
    #     cursor.execute(add_sql, (w_info['name'], w_info['password']))
    #     conn.commit()
    #     return True, 'updated'
    # except IOError:
    #     conn.rollback()
    #     return False, 'update failed'
    # finally:
    #     conn.close()
    wifi_info, conf = confmgr.get_conf_section('WIFI')
    wifi_info['name'] = w_info['name']
    if 'password' in w_info:
        wifi_info['password'] = w_info['password']
    else:
        wifi_info['password'] = ''
    confmgr.update_conf(conf)
    return True, 'updated'
Exemplo n.º 8
0
def set_volume(volume):
    volume_info, conf = confmgr.get_conf_section('VOLUME')
    volume_info['volume'] = str(volume)
    confmgr.update_conf(conf)
    return True, 'updated'