Ejemplo n.º 1
0
void connect_signals()
{
    char source_name[1024], destination_name[1024];

    printf("%s\n", mdev_name(source));
    printf("%s\n", mdev_name(destination));

    lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570");
    lo_address_set_ttl(a, 1);

    lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination));

    // wait for link to be processed
    int j = 50;
    while (j >= 0) {
        mdev_poll(source, 10);
        mdev_poll(destination, 10);
        j--;
    }

    msig_full_name(sendsig, source_name, 1024);
    msig_full_name(recvsig, destination_name, 1024);

    lo_send(a, "/connect", "ssssss", source_name, destination_name, "@mode", "expression", "@expression", "y=y{-1}+1");

    lo_address_free(a);

    // wait for connection to be processed
    j = 50;
    while (j >= 0) {
        mdev_poll(source, 10);
        mdev_poll(destination, 10);
        j--;
    }
}
Ejemplo n.º 2
0
void dev_db_callback(mapper_db_device record,
                     mapper_db_action_t action,
                     void *user)
{
    // if we see /influence.1 or /XAgora.1, send /link message
    struct _agentInfo *info = (struct _agentInfo*)user;

    if (action == MDB_NEW) {
        if (strcmp(record->name, info->influence_device_name)==0) {
            mapper_monitor_link(info->mon, mdev_name(info->dev),
                                record->name);
            mapper_monitor_link(info->mon, record->name,
                                mdev_name(info->dev));
        }
        else if (strcmp(record->name, info->xagora_device_name)==0)
            mapper_monitor_link(info->mon, mdev_name(info->dev),
                                record->name);
    }
    else if (action == MDB_REMOVE) {
        if (strcmp(record->name, info->influence_device_name)==0) {
            mapper_monitor_unlink(info->mon, mdev_name(info->dev),
                                  record->name);
            info->linked_influence = 0;
        }
    }
}
Ejemplo n.º 3
0
void agentLogout()
{
    struct _agentInfo *info = &agentInfo;

    if (info->influence_device_name) {
        mapper_monitor_unlink(info->mon,
                              info->influence_device_name,
                              mdev_name(info->dev));
        free(info->influence_device_name);
    }
    if (info->xagora_device_name) {
        mapper_monitor_unlink(info->mon,
                              mdev_name(info->dev),
                              info->xagora_device_name);
        free(info->xagora_device_name);
    }
    if (info->dev)
        mdev_free(info->dev);
    if (info->db) {
        mapper_db_remove_device_callback(info->db, dev_db_callback, info);
        mapper_db_remove_link_callback(info->db, link_db_callback, info);
    }
    if (info->mon)
        mapper_monitor_free(info->mon);
    if (info->admin) {
        mapper_admin_free(info->admin);
    }
    memset(info, 0, sizeof(struct _agentInfo));
}
Ejemplo n.º 4
0
void connect_signals()
{
    char source_name[1024], destination_name[1024];

    printf("%s\n", mdev_name(source));
    printf("%s\n", mdev_name(destination));

    lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570");
    lo_address_set_ttl(a, 1);

    lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination));

    int j = 50;
    while (j >= 0) {
        mdev_poll(source, 10);
        mdev_poll(destination, 10);
        j--;
    }

    msig_full_name(sendsig, source_name, 1024);
    msig_full_name(recvsig, destination_name, 1024);

    lo_send(a, "/connect", "ss", source_name, destination_name);

    lo_address_free(a);
}
Ejemplo n.º 5
0
void link_db_callback(mapper_db_link record,
                      mapper_db_action_t action,
                      void *user)
{
    // if we see our links, send /connect messages
    struct _agentInfo *info = (struct _agentInfo*)user;

    if (action == MDB_NEW) {
        if (((strcmp(record->src_name, info->influence_device_name)==0) &&
             (strcmp(record->dest_name, mdev_name(info->dev))==0)) ||
            ((strcmp(record->dest_name, info->influence_device_name)==0) &&
             (strcmp(record->src_name, mdev_name(info->dev))==0))) {
            info->linked_influence++;
            if (info->linked_influence >= 2)
                make_influence_connections();
        }
        else if ((strcmp(record->src_name, mdev_name(info->dev))==0) &&
              (strcmp(record->dest_name, info->xagora_device_name)==0)) {
            make_xagora_connections();
        }
    }
    else if (action == MDB_REMOVE) {
        if ((strcmp(record->src_name, info->influence_device_name)==0) ||
            (strcmp(record->dest_name, info->influence_device_name)==0))
            info->linked_influence--;
    }
}
Ejemplo n.º 6
0
void loop()
{
    printf("-------------------- GO ! --------------------\n");
    int i = 0;

    if (automate) {
        char source_name[1024], destination_name[1024];

        printf("%s\n", mdev_name(source));
        printf("%s\n", mdev_name(destination));

        lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570");
        lo_address_set_ttl(a, 1);

        lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination));

        msig_full_name(sendsig, source_name, 1024);
        msig_full_name(recvsig, destination_name, 1024);

        lo_send(a, "/connect", "ssss", source_name, destination_name,
                "@mode", "reverse");

        lo_address_free(a);
    }

    while (i >= 0 && !done) {
        msig_update_float(recvsig, ((i % 10) * 1.0f));
        printf("\ndestination value updated to %f -->\n", (i % 10) * 1.0f);
        mdev_poll(destination, 1);
        mdev_poll(source, 100);
        i++;
    }
}
Ejemplo n.º 7
0
int setup_router()
{
    const char *host = "localhost";
    router = mapper_router_new(source, host, destination->props.port,
                               mdev_name(destination), 0);
    mdev_add_router(source, router);
    printf("Router to %s:%d added.\n", host, destination->props.port);

    char signame_in[1024];
    if (!msig_full_name(recvsig, signame_in, 1024)) {
        printf("Could not get destination signal name.\n");
        return 1;
    }

    char signame_out[1024];
    if (!msig_full_name(sendsig, signame_out, 1024)) {
        printf("Could not get source signal name.\n");
        return 1;
    }

    printf("Connecting signal %s -> %s\n", signame_out, signame_in);
    mapper_connection c = mapper_router_add_connection(router, sendsig,
                                                       recvsig->props.name,
                                                       'f', 1);
    mapper_connection_range_t range;
    range.src_min = 0;
    range.src_max = 1;
    range.dest_min = -10;
    range.dest_max = 10;
    range.known = CONNECTION_RANGE_KNOWN;
    
    mapper_connection_set_linear_range(c, &range);

    return 0;
}
Ejemplo n.º 8
0
int setup_router()
{
    const char *host = "localhost";
    router = mapper_router_new(source, host, destination->admin->port.value, 
                               mdev_name(destination));
    mdev_add_router(source, router);
    printf("Router to %s:%d added.\n", host, port);

    char signame_in[1024];
    if (!msig_full_name(recvsig, signame_in, 1024)) {
        printf("Could not get destination signal name.\n");
        return 1;
    }

    char signame_out[1024];
    if (!msig_full_name(sendsig, signame_out, 1024)) {
        printf("Could not get source signal name.\n");
        return 1;
    }

    printf("Mapping signal %s -> %s\n", signame_out, signame_in);
    mapper_connection c = mapper_router_add_connection(router, sendsig,
                                                       recvsig->props.name,
                                                       'f', 3);
    const char *expr = "y=x*10";
    mapper_connection_set_expression(c, sendsig, expr);

    return 0;
}
Ejemplo n.º 9
0
int setup_connection()
{
    mval src_min, src_max, dest_min, dest_max;
    src_min.f = 0.;
    src_max.f = 1.;
    dest_min.f = -10.;
    dest_max.f = 10.;

    mapper_monitor mon = mapper_monitor_new(source->admin, 0);

    char src_name[1024], dest_name[1024];
    mapper_monitor_link(mon, mdev_name(source),
                        mdev_name(destination), 0, 0);

    msig_full_name(sendsig, src_name, 1024);
    msig_full_name(recvsig, dest_name, 1024);

    mapper_connection_range_t range;
    range.src_min = &src_min;
    range.src_max = &src_max;
    range.dest_min = &dest_min;
    range.dest_max = &dest_max;
    range.known = CONNECTION_RANGE_KNOWN;

    mapper_db_connection_t props;
    props.range = range;
    props.src_length = 1;
    props.dest_length = 1;
    props.src_type = 'f';
    props.dest_type = 'f';
    props.mode = MO_LINEAR;

    mapper_monitor_connect(mon, src_name, dest_name, &props,
                           CONNECTION_RANGE_KNOWN | CONNECTION_MODE);

    // poll devices for a bit to allow time for connection
    int i = 0;
    while (i++ < 10) {
        mdev_poll(destination, 10);
        mdev_poll(source, 10);
    }

    mapper_monitor_free(mon);

    return 0;
}
Ejemplo n.º 10
0
static void signal_callback(mapper_db_signal sig,
                            mapper_db_action_t action,
                            void *user)
{
    if (!sig->is_output)
        return;
    if (action == MDB_NEW) {
        put_signal_name(sig->device_name, sig->name, 1);
        struct stringlist **devnode = &device_strings;
        while (*devnode) {
            if (strstr(sig->device_name, (*devnode)->string)!=0
                    && strcmp(sig->device_name,
                              mdev_name(recdev)?mdev_name(recdev):"")!=0)
            {
                struct stringlist **signode = &signal_strings;
                if (!*signode) {
                    push_signal_stack(sig->device_name, sig->name,
                                      sig->type, sig->length);
                    break;
                }
                while (*signode) {
                    if ((strncmp(sig->name, (*signode)->string,
                                 strlen((*signode)->string))==0)
                            || ((*signode)->string[0]=='/'
                                && strncmp(sig->name, (*signode)->string+1,
                                           strlen((*signode)->string))==0))
                    {
                        push_signal_stack(sig->device_name, sig->name,
                                          sig->type, sig->length);
                        signode = 0;
                        break;
                    }
                    else
                        signode = &(*signode)->next;
                }
                if (!signode)
                    break;
            }
            devnode = &(*devnode)->next;
        }
    }
    else if (action == MDB_REMOVE) {
        put_signal_name(sig->device_name, sig->name, -1);
    }
}
Ejemplo n.º 11
0
void make_influence_connections()
{
    char signame1[1024], signame2[1024];
    struct _agentInfo *info = &agentInfo;

    sprintf(signame1, "%s/node/%d/observation",
            info->influence_device_name, mdev_ordinal(info->dev));

    sprintf(signame2, "%s/observation", mdev_name(info->dev));

    mapper_monitor_connect(info->mon, signame1, signame2, 0, 0);

    sprintf(signame1, "%s/position", mdev_name(info->dev));

    sprintf(signame2, "%s/node/%d/position",
            info->influence_device_name, mdev_ordinal(info->dev));

    mapper_monitor_connect(info->mon, signame1, signame2, 0, 0);
}
Ejemplo n.º 12
0
void loop()
{
    printf("-------------------- GO ! --------------------\n");
    int i = 0, j = 0, count;

    if (automate) {
        char source_name[1024], destination_name[1024];

        printf("%s\n", mdev_name(source));
        printf("%s\n", mdev_name(destination));

        lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570");
        lo_address_set_ttl(a, 1);

        lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination));

        for (int i = 0; i < 4; i++) {
            msig_full_name(sendsig[i], source_name, 1024);
            msig_full_name(recvsig[i], destination_name, 1024);

            lo_send(a, "/connect", "ss", source_name, destination_name);
        }

        lo_address_free(a);
    }

    while (i >= 0 && !done) {
        for (j = 0; j < 4; j++) {
            msig_update_float(recvsig[j], ((i % 10) * 1.0f));
        }
        printf("\ndestination values updated to %d -->\n", i % 10);
        for (j = 0; j < 4; j++) {
            count = msig_query_remote(sendsig[j], dummysig[j]);
            printf("Sent %i queries for sendsig[%i]\n", count, j);
        }
        mdev_poll(destination, 100);
        mdev_poll(source, 0);
        i++;
        usleep(500 * 1000);
    }
}
Ejemplo n.º 13
0
void loop()
{
    printf("-------------------- GO ! --------------------\n");
    int i = 0;

    if (automate) {
        char source_name_1[1024], destination_name_1[1024];
        char source_name_2[1024], destination_name_2[1024];

        printf("%s\n", mdev_name(source));
        printf("%s\n", mdev_name(destination));

        lo_address a = lo_address_new_from_url("osc.udp://224.0.1.3:7570");
        lo_address_set_ttl(a, 1);

        lo_send(a, "/link", "ss", mdev_name(source), mdev_name(destination));

        msig_full_name(sendsig_1, source_name_1, 1024);
        msig_full_name(recvsig_1, destination_name_1, 1024);

        lo_send(a, "/connect", "ss", source_name_1, destination_name_1);

        msig_full_name(sendsig_2, source_name_2, 1024);
        msig_full_name(recvsig_2, destination_name_2, 1024);

        lo_send(a, "/connect", "ss", source_name_2, destination_name_2);

        lo_address_free(a);
    }

    while (i >= 0 && !done) {
        mdev_poll(source, 0);
        msig_update_float(source->outputs[0], ((i % 10) * 1.0f));
        msig_update_float(source->outputs[1], ((i % 10) * 1.0f));
        printf("source value updated to %d -->\n", i % 10);

        printf("Received %i messages.\n\n", mdev_poll(destination, 100));
        i++;
    }
}
Ejemplo n.º 14
0
int setup_connection()
{
    int count = 0;

    mapper_monitor mon = mapper_monitor_new(source->admin, 0);
    if (!mon)
        goto error;

    char src_name[1024], dest_name[1024];
    mapper_monitor_link(mon, mdev_name(source),
                        mdev_name(destination), 0, 0);

    while (!done && !source->routers) {
        if (count++ > 50)
            goto error;
        mdev_poll(source, 10);
        mdev_poll(destination, 10);
    }

    msig_full_name(sendsig, src_name, 1024);
    msig_full_name(recvsig, dest_name, 1024);
    mapper_monitor_connect(mon, src_name, dest_name, 0, 0);

    // wait until connection has been established
    while (!done && !source->routers->num_connections) {
        if (count++ > 50)
            goto error;
        mdev_poll(source, 10);
        mdev_poll(destination, 10);
    }
    eprintf("Connection established.\n");

    mapper_monitor_free(mon);

    return 0;

  error:
    return 1;
}
Ejemplo n.º 15
0
static void device_callback(mapper_db_device dev,
                            mapper_db_action_t action,
                            void *user)
{
    if (action == MDB_NEW) {
        put_device_name(dev->name, 1);
        struct stringlist **node = &device_strings;
        while (*node) {
            if (strstr(dev->name, (*node)->string)!=0
                    && strcmp(dev->name,
                              mdev_name(recdev)?mdev_name(recdev):"")!=0)
            {
                mapper_monitor_request_signals_by_device_name(mon, dev->name);
                break;
            }
            node = &(*node)->next;
        }
    }
    else if (action == MDB_REMOVE) {
        put_device_name(dev->name, -1);
    }
}
Ejemplo n.º 16
0
void recmonitor_stop()
{
    if (!mon)
        return;
    if (mdev_ready(recdev)) {
        const char *devname = mdev_name(recdev);
        if (devname) {
            struct stringlist **node = &device_strings;
            while (*node) {
                mapper_db_device *dev =
                    mapper_db_match_devices_by_name(db, (*node)->string);
                while (dev) {
                    printf("Unlinking %s %s\n", (*dev)->name, devname);
                    mapper_monitor_unlink(mon, (*dev)->name, devname);
                    dev = mapper_db_device_next(dev);
                }
                node = &(*node)->next;
            }
        }
    }
    mapper_monitor_free(mon);
}
Ejemplo n.º 17
0
void record_signals_on_stack()
{
    if (!mdev_ready(recdev))
        return;

    const char *devname = mdev_name(recdev);
    char destname[256] = "";
    if (!devname) return;

    signal_list_t *n = pop_signal_stack();
    if (!n)
        return;

    while (n) {
        printf("Recording %s%s\n", n->device_name, n->signal_name);

        if (strncmp(n->device_name, destname, 256)) {
            mapper_monitor_link(mon, n->device_name, devname, 0, 0);
            snprintf(destname, 256, "%s", n->device_name);
        }

        recdevice_add_input(n->device_name, n->signal_name,
                            n->type, n->length);

        char signame[1024], recsigname[1024];
        snprintf(signame, 1024, "%s%s", n->device_name, n->signal_name);
        snprintf(recsigname, 1024, "%s%s%s", devname, n->device_name,
                 n->signal_name);

        mapper_monitor_connect(mon, signame, recsigname, 0, 0);

        free_signal(n);
        n = pop_signal_stack();
    }

    recdevice_reset_generic_handler();
}