Esempio n. 1
0
def add_register(selected_teds):
    tedsdict = pl.load_teds(sc.MAIN_PATH + pl.TEDS_FOLDER + '/' +
                            selected_teds)
    newtedsdict = sf.add_register_function(tedsdict)
    sf.save_data(
        newtedsdict, sc.MAIN_PATH + pl.TEDS_FOLDER + '/' +
        newtedsdict[pl.TEDS_NAME_ID] + '.ted')
    ##    return json.dumps(newtedsdict, indent=1)
    return redirect(url_for('editor_page', selected_teds=selected_teds))
Esempio n. 2
0
def editor_page(selected_teds):

    # Check if the user is logged
    if session.get('logged_in'):

        msg = 'Welcome'
        print(request.form)

        if selected_teds == 'new_teds':
            baseteds = sf.set_new_teds(pl.TEDS_BUILD_DICT)

        else:
            tedsdict = pl.load_teds(sc.MAIN_PATH + pl.TEDS_FOLDER + '/' +
                                    selected_teds)
            baseteds = sf.create_web_dict_from_teds_dict(
                tedsdict, pl.TEDS_BUILD_DICT, pl.REGISTER_BUILD_DICT)

        page_dict = {
            'method': request.method,
            'message': msg,
            'webteds': baseteds
        }

        if request.method == 'GET':
            return render_template('editor_page.html', **page_dict)

        elif request.method == 'POST':

            teds = sf.recover_teds_dict_from_form(request.form,
                                                  pl.TEDS_BUILD_DICT,
                                                  pl.REGISTER_BUILD_DICT)
            page_dict['message'] = teds
            ### lock here
            with ct.changed_teds_lock:
                sf.save_data(teds,
                             sc.MAIN_PATH + pl.TEDS_FOLDER + '/' + \
                             teds[pl.TEDS_NAME_ID] + '.ted')
                ct.changed_teds.append(teds[pl.TEDS_NAME_ID])

            tedsdictlist = sf.load_dict_teds_files(sc.MAIN_PATH +
                                                   pl.FILE_FOLDER + '/' +
                                                   pl.TEDSLISTFILE)
            tedsdictlist[teds[pl.TEDS_NAME_ID]] = teds[pl.TEDS_NAME_NAME]
            sf.save_data(tedsdictlist,
                         sc.MAIN_PATH + pl.FILE_FOLDER + '/' + pl.TEDSLISTFILE)

            ##            return render_template('editor_page.html', **page_dict)
            return redirect(url_for('main_page'))

        else:
            return METHOD_ERROR

    else:
        return redirect(url_for('login'))
Esempio n. 3
0
def console_controllers():

    if request.method == 'GET':
        with ct.actuator_data_lock:
            controllers_data = sf.load_controllers_data(sc.MAIN_PATH +
                                                        pl.FILE_FOLDER + '/' +
                                                        pl.CONTROLLERDATAFILE)

        return json.dumps(controllers_data)

    elif request.method == 'POST':
        with ct.actuator_data_lock:
            sf.save_data(
                request.json,
                sc.MAIN_PATH + pl.FILE_FOLDER + '/' + pl.CONTROLLERDATAFILE)
            ct.actuator_update = True
        #return redirect(url_for('controller_page'))
        #return json.dumps(controllers_data)

    else:
        return "Method not Allowed"
Esempio n. 4
0
def uploader_file():
    if request.method == 'POST':
        UPLOAD_DIR = '/home/pi/front-end/server/scripts/'
        server_app.config['UPLOAD_FOLDER'] = UPLOAD_DIR
        if not os.path.isdir(UPLOAD_DIR):
            os.mkdir(UPLOAD_DIR)
        f = request.files['file']
        filename = secure_filename(f.filename)
        f.save(os.path.join(server_app.config['UPLOAD_FOLDER'], filename))
        scriptlist = sf.load_dict_script_files(sc.MAIN_PATH + pl.FILE_FOLDER +
                                               '/' + pl.SCRIPTLISTFILE)
        for item in request.form:
            scriptlist['scripts'].append({
                'script_name':
                request.form[item],
                'script_file':
                f.filename.split('.')[0]
            })
        sf.save_data(scriptlist,
                     sc.MAIN_PATH + pl.FILE_FOLDER + '/' + pl.SCRIPTLISTFILE)
        return redirect(url_for('script_page'))
Esempio n. 5
0
    def run(self):

        import time  #test only
        chengedtedslist = ciermagthread.changed_teds

        system_transducers = {}
        time1 = 0
        maxlen = 30 * 60 * 8

        global looptime

        while exit_var:

            for modteds in list(chengedtedslist):

                with ciermagthread.changed_teds_lock:
                    tedsdict = pl.load_teds(sc.MAIN_PATH + pl.TEDS_FOLDER +
                                            '/' + modteds)
                    system_transducers[tedsdict[
                        'ID']] = ciermagtransducer.Transducer(tedsdict)
                    chengedtedslist.remove(modteds)
                    print(modteds, ' created')

                with ciermagthread.actuator_data_lock:
                    actuatordata = ciermagtransducer.create_actuator_data(
                        system_transducers)
                    sf.save_data(
                        actuatordata, sc.MAIN_PATH + pl.FILE_FOLDER + '/' +
                        pl.CONTROLLERDATAFILE)

            if ciermagthread.actuator_update:

                with ciermagthread.actuator_data_lock:
                    actuatordata = sf.load_controllers_data(
                        sc.MAIN_PATH + pl.FILE_FOLDER + '/' +
                        pl.CONTROLLERDATAFILE)
                    ciermagtransducer.process_actuator_data(
                        actuatordata, system_transducers)
                    ciermagthread.actuator_update = False
                    actuatordata = ciermagtransducer.create_actuator_data(
                        system_transducers)
                    sf.save_data(
                        actuatordata, sc.MAIN_PATH + pl.FILE_FOLDER + '/' +
                        pl.CONTROLLERDATAFILE)

            if time.time() > time1 + 5:

                with ciermagthread.sensor_data_lock:
                    sensordata = sf.load_sensor_data(sc.MAIN_PATH +
                                                     pl.FILE_FOLDER + '/' +
                                                     pl.SENSORDATAFILE)
                    ciermagtransducer.update_sensor_data(
                        sensordata, system_transducers, maxlen)
                    sf.save_data(
                        sensordata, sc.MAIN_PATH + pl.FILE_FOLDER + '/' +
                        pl.SENSORDATAFILE)
                time1 = time.time()

            time.sleep(0.05)