Exemplo n.º 1
0
Arquivo: app.py Projeto: lz677/ipheno
def fan():
    try:
        hardware_info.all_states[HardwareStates.fan] = int(
            request.args.get('duty'))
        logger.debug('---- 风扇开度设置为:%d' %
                     hardware_info.all_states[HardwareStates.fan])
    except TypeError:
        hardware_info.all_states[HardwareStates.fan] = 10
        logger.warning('未设置风扇开度(duty) 将其默认开启最低值10')
    TaskManager.tasks['fan'].start()
    time.sleep(0.1)
    return jsonify({'state': "ok"}) if TaskManager.tasks['fan'].get_states().states == 'complete' \
        else jsonify({'state': "failed"})
Exemplo n.º 2
0
Arquivo: app.py Projeto: lz677/ipheno
def system(cmd: str):
    if utility.save_info_to_json(hardware_info,
                                 './doc/conf/main_control.json'):
        logger.info("--- 主控配置储存成功 ---")
    else:
        logger.error('--- 主控配置未能成功储存 ---')
    if cmd == 'info':
        logger.debug('--- 查询总控信息')
        return jsonify(hardware_info.get_system_info())
    elif cmd == 'restart':
        time.sleep(1)
        # 重启服务器代码
        logger.warning("--- 重启服务器 ---")
        os.execv(sys.executable, ['python -m flask run'] + sys.argv)
    elif cmd == 'reboot':
        time.sleep(1)
        logger.warning("--- 重启总控 ---")
        os.system('sudo reboot')
Exemplo n.º 3
0
Arquivo: app.py Projeto: lz677/ipheno
def task(task_name: str):
    logger.info('收到任务<%s>执行请求' % task_name)
    if 'fan' in task_name:
        try:
            hardware_info.all_states[HardwareStates.fan] = int(
                request.args.get('duty'))
            logger.debug('---- 风扇开度设置为:%d' %
                         hardware_info.all_states[HardwareStates.fan])
        except TypeError:
            hardware_info.all_states[HardwareStates.fan] = 10
            logger.warning('未设置风扇开度(duty) 将其默认开启最低值10')
    if 'set-ip' in task_name:
        try:
            hardware_info.system_info['temIP']['ip'] = request.args.get("ip")
            hardware_info.system_info['temIP']['port'] = request.args.get(
                "port")
        except KeyError:
            logger.warning('未设置ip和端口,将其默认为初始值')
            hardware_info.system_info['temIP']['ip'] = '192.168.1.7'
            hardware_info.system_info['temIP']['port'] = '5000'
    # time.sleep(1)
    return TaskManager.tasks[task_name].start().get_json()
Exemplo n.º 4
0
Arquivo: app.py Projeto: lz677/ipheno
def task_result(task_name: str):
    only_data = True
    if task_name == 'weight':
        return jsonify(
            {'称重结果': hardware_info.all_states[HardwareStates.balance]})
    if task_name == 'weight-zero':
        return jsonify({'清零成功': ' '})
    if task_name == 'image':
        img_result = {}
        for res in results_info.img_info:
            if results_info.img_info[res] != 'NONE':
                img_result.update({res: results_info.img_info[res]})
        return jsonify(img_result)

    if only_data:
        results = {}
        if task_name in ('weight', 'easy-mode-grain'):
            results.update(
                {'重量': hardware_info.all_states[HardwareStates.balance]})
        for res in results_info.img_parameters:
            if results_info.img_parameters[res] != 'NONE':
                results.update({res: results_info.img_parameters[res]})
        img_result = []
        for res in results_info.img_info:
            if results_info.img_info[res] != 'NONE':
                img_result.append(res)
                img_result.append(results_info.img_info[res])
        results.update({'image': img_result})
        # results.update(results_info.get_image_info())
        logger.debug(results)
        return jsonify(results)
    # 返回结果
    cal_results = results_info.get_image_parameters()
    # 算法返回的图片 以 base64 的方式 存储在 imageBase64的属性里。
    cal_results.update(results_info.get_image_info())
    return jsonify(results_info.get_image_parameters())
Exemplo n.º 5
0
Arquivo: app.py Projeto: lz677/ipheno
def img_realtime(image_name):
    if not hardware_info.capture.is_opened():
        hardware_info.capture.open()
    hardware_info.capture.start_stream()
    # app web端
    if image_name.endswith(".jpg"):
        logger.debug('--- 前端请求jpg')
        return Response(hardware_info.capture.gen_stream(),
                        mimetype="image/jpg")
    elif image_name.endswith(".png"):
        logger.debug('--- 前端请求png')
        return Response(hardware_info.capture.gen_stream(False),
                        mimetype="image/png")
    # web 端
    elif image_name == 'realtime':
        logger.debug('--- 前端请求实时流')
        return Response(hardware_info.capture.gen_stream_web(),
                        mimetype='multipart/x-mixed-replace; boundary=frame')