예제 #1
0
def get_server_info():
    server_conf, _ = confmgr.get_conf_section('SERVER')
    server_info = {
        'address': server_conf['address'],
        'port': server_conf['port']
    }
    return True, server_info
예제 #2
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'
예제 #3
0
def get_configured_bracelet_list():
    bracelet_conf, _ = confmgr.get_conf_section('BRACELET')
    bracelet1 = bracelet_conf['bracelet1']
    bracelet2 = bracelet_conf['bracelet2']
    bracelet_list = []
    if bracelet1 != '':
        bracelet_list.append({'id': 1, 'mac': bracelet1})
    if bracelet2 != '':
        bracelet_list.append({'id': 2, 'mac': bracelet2})
    return True, bracelet_list
예제 #4
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'
예제 #5
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'
예제 #6
0
def get_bracelet_info(bracelet_id):
    if bracelet_id > 2:
        return False, 'not found'
    bracelet_conf, _ = confmgr.get_conf_section('BRACELET')
    if bracelet_id == 1:
        bracelet = bracelet_conf['bracelet1']
    else:
        bracelet = bracelet_conf['bracelet2']
    if bracelet != '':
        return True, {'id': bracelet_id, 'mac': bracelet}
    return False, 'not found'
예제 #7
0
def get_settings():
    setting_conf, _ = confmgr.get_conf_section('SETTINGS')
    if setting_conf['audio_frequency'] == '':
        audio_frequency = ''
    else:
        audio_frequency = int(setting_conf['audio_frequency'])
    return True, {
        'cameraResolution': setting_conf['camera_resolution'],
        'audioFrequency': audio_frequency,
        'gpsCoord': setting_conf['gps']
    }
예제 #8
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'
예제 #9
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'
예제 #10
0
def get_wifi_info():
    # conn = dbmgr.get_connection()
    # try:
    #     wifi_info = {}
    #     cursor = conn.cursor()
    #     cursor.execute('select name, password from robot_conf.wifi limit 1')
    #     result = cursor.fetchall()
    #     if len(result) > 0:
    #         wifi_info = {
    #             'name': result[0][0],
    #             'password': result[0][1]
    #         }
    #     return True, wifi_info
    # except IOError:
    #     return False, 'database operation error'
    # finally:
    #     conn.close()
    wifi_conf, _ = confmgr.get_conf_section('WIFI')
    wifi_info = {'name': wifi_conf['name'], 'password': wifi_conf['password']}
    return True, wifi_info
예제 #11
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'
예제 #12
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'
예제 #13
0
def get_wifi_info():
    wifi_conf, _ = confmgr.get_conf_section('WIFI')
    wifi_info = {'name': wifi_conf['name'], 'password': wifi_conf['password']}
    return True, wifi_info
예제 #14
0
def get_volume():
    volume_info, _ = confmgr.get_conf_section('VOLUME')
    return True, int(volume_info['volume'])
예제 #15
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'