Exemplo n.º 1
0
def cadastro_camera():
    identificador = request.form["identificador"]
    rua = request.form["rua"]
    numero = request.form["numero"]
    bairro = request.form["bairro"]
    complemento = request.form["complemento"]
    cidade = request.form["cidade"]
    UF = request.form["UF"]

    nova_camera = Camera(identificador=identificador,
                         rua=rua,
                         numero=numero,
                         bairro=bairro,
                         complemento=complemento,
                         cidade=cidade,
                         UF=UF)
    nova_camera.save()
    return redirect("/perfil")
Exemplo n.º 2
0
def node_discover(request):

    g_logger.debug('Node Discover %s' % request.data['machine_name'])

    # Look for existing machine in the database, with the same name
    nodes = CaptureNode.objects.filter(
        machine_name=request.data['machine_name'])

    if nodes:
        # Node exists in database, update it
        node = nodes[0]
        node.ip_address = request.data['ip_address']
        node.last_seen = timezone.now()
    else:
        # Node does not exist, create it
        node = CaptureNode(ip_address=request.data['ip_address'],
                           machine_name=request.data['machine_name'])

    if 'sync_found' in request.data:
        node.sync_found = request.data['sync_found']
    if 'os' in request.data:
        node.os = request.data['os']
    node.online = True
    node.code_version = request.data[
        'code_version'] if 'code_version' in request.data else 0

    if node.code_version < 1024:
        return JSONResponse({'Result': 'avacapture.exe Version Too Old'},
                            status=426)

    # Update drive info
    if 'drives' in request.data:
        node.drive_info = json.dumps(request.data['drives'])

    node.save()

    # Update list of cameras
    if 'cameras' in request.data:

        # TODO We should be getting each cameras Model and Version here, to update the DB

        if type(request.data) is dict:
            cam_list = request.data['cameras']
        else:
            cam_list = request.data.getlist('cameras')
        for unique_id in cam_list:
            # if camera does no exist, create it
            obj = Camera.objects.filter(unique_id=unique_id, node=node)
            if not obj:
                obj = Camera(node=node, unique_id=unique_id)
                obj.save()
        # delete any cameras that are not in the list
        for item in Camera.objects.filter(node=node).exclude(
                unique_id__in=cam_list):
            item.delete()

    if node.location:
        result = {
            'Result': 'OK',
            'sync_freq': node.location.hardware_sync_frequency,
            'pulse_duration': node.location.pulse_duration,
            'external_sync': node.location.external_sync,
            'display_focus_peak': node.location.display_focus_peak,
            'display_overexposed': node.location.display_overexposed,
            'display_histogram': node.location.display_histogram,
            'bitdepth_avi': node.location.bitdepth_avi,
            'bitdepth_single': node.location.bitdepth_single
        }
    else:
        return HttpResponse("Node not registered", status=403)

    if 'request_camera_params' in request.data:
        # client is requesting the current parameters of the cameras
        cameras = Camera.objects.filter(node=node)

        # TODO Generalize DB for parameters
        result['camera_params'] = [
            dict(unique_id=cam.unique_id,
                 lens_aperture_value=cam.lens_aperture,
                 exposure=cam.exposure,
                 gain=cam.gain,
                 using_sync=cam.using_sync) for cam in cameras
        ]

        # TODO Camera roi

    # return JSON data for the current machine
    return JSONResponse(result)