Ejemplo n.º 1
0
void ofxArtnet::sendDmx( string targetIp, const unsigned char* data512, int size )
{
    
    if ( status == NODES_FOUND)
    {
        if ( artnet_send_dmx(node, 0, targetIp.c_str(), size , data512) != ARTNET_EOK) {
            printf("Failed to Send: %s\n", artnet_strerror() );
        }
    }
    else
    {
        printf("Failed to Send: %s\n", artnet_strerror() );
    }
}
Ejemplo n.º 2
0
bool Node::setup(std::string _ip_addr, bool _sendRaw, uint8_t _subnet_addr)
{
    ip_addr = _ip_addr;
    subnet_addr = _subnet_addr;
    sendRaw = _sendRaw;
    
    artnetNode  = artnet_new(ip_addr.c_str(), 0);//int = verbose
    //@todo: allow for multiple nodes then artnet_join(artnetNode1, artnetNodeN)
    
    if (!artnetNode) {
        printf("Error: %s\n", artnet_strerror());
        return false;
    }
    
    artnet_set_long_name(artnetNode, "Cinder-LibArtnet");
    artnet_set_short_name(artnetNode, "CI");
    if (sendRaw) artnet_set_node_type(artnetNode, ARTNET_RAW);
    
    // set the upper 4 bits of the universe address 
    artnet_set_subnet_addr(artnetNode, subnet_addr) ;
    
    if (!unis.size()) {
        setNumUniverses(1);
        std::cout<<"Creating single universe with address 1 and ID 0."<<std::endl;
    }
    
    for (int i=0; i<unis.size(); i++) {
        // enable port        
        artnet_set_port_type(artnetNode, unis[i].port_id, ARTNET_ENABLE_OUTPUT, ARTNET_PORT_DMX);
        // bind port to universe
        artnet_set_port_addr(artnetNode, unis[i].port_id, ARTNET_OUTPUT_PORT, unis[i].port_addr); 
    }
    
    artnet_dump_config(artnetNode);
    
    //set receiver callback
    artnet_set_handler(artnetNode, ARTNET_RECV_HANDLER, artnetReceiverWrapper, this); 
    
    if (artnet_start(artnetNode) != 0) {
        printf("Error: %s\n", artnet_strerror());
        return false;
    }

    didSetup = true;
    return true;
    
};
Ejemplo n.º 3
0
void ofxArtnet::setup(const char* interfaceIP, int port_addr, int verbose)
{
    printf("ofxArtnet::setup\n");
    verbose = 1;
    nodes_found = 0;
    
    // create new artnet node, and set config values
    
    if ( (node = artnet_new(interfaceIP, verbose)) == NULL)
    {
        if ( verbose ) printf("cannot create node: %s\n", artnet_strerror() );
        goto error_destroy;
    }
    artnet_set_short_name(node, SHORT_NAME.c_str());
    artnet_set_long_name(node, LONG_NAME.c_str());
    artnet_set_node_type(node, ARTNET_RAW);
    
    artnet_set_port_type(node, 0, ARTNET_ENABLE_INPUT, ARTNET_PORT_DMX);
    artnet_set_port_addr(node, 0, ARTNET_INPUT_PORT, port_addr);
    artnet_set_handler(node, ARTNET_REPLY_HANDLER, ofxArtnet::reply_handler, NULL);
    
    if (artnet_start(node) != ARTNET_EOK) {
        if ( verbose ) printf("Failed to start: %s\n", artnet_strerror() );
        goto error_destroy;
    }
    
    sd = artnet_get_sd(node);
    
    find_timeout = ofGetElapsedTimeMillis();
    status = NODES_FINDING;
    if (artnet_send_poll(node, NULL, ARTNET_TTM_DEFAULT) != ARTNET_EOK) {
        printf("send poll failed: %s\n", artnet_strerror() );
        goto error_destroy;
    }
    printf("starting thread\n");
    startThread(true);
    return;
    
    error_destroy :
    artnet_destroy(node);
    
    //    free(ops.ip_addr);
    //    exit(1);
}
Ejemplo n.º 4
0
void ofxArtnet::sendDmx( string targetIp, int targetSubnet, int targetUniverse, const unsigned char* data512, int size )
{
    
    if ( status == NODES_FOUND)
    {
        if ( artnet_send_dmx_by_custom_SU(node, 0, targetSubnet, targetUniverse, targetIp.c_str(), size , data512) != ARTNET_EOK) {
            printf("Failed to Send: %s\n", artnet_strerror() );
        }
    }
    else if ( status != NODES_FINDING)
    {
        ofLogError() << "node is not found";
    }
}
Ejemplo n.º 5
0
int ofxArtnet::sendDmx( string targetIp, int targetSubnet, int targetUniverse, const unsigned char* data512, int size )
{
    int result = ARTNET_EOK;
    if ( status == NODES_FOUND)
    {
        result = artnet_send_dmx_by_custom_SU(node, 0, targetSubnet, targetUniverse, targetIp.c_str(), size , data512);
        if ( result!= ARTNET_EOK && verbose) {
            printf("Failed to Send: %s\n", artnet_strerror() );
        }
    }
    else if ( status != NODES_FINDING && verbose)
    {
        result = artnet_send_dmx(node, 0, targetIp.c_str(), size , data512);
        if ( result != ARTNET_EOK) {
            if ( verbose ) printf("[ofxArtnet]Failed to Send: %s\n", artnet_strerror() );
        }
    }
    else
    {
        if ( verbose ) printf("NODES_IS_NOT_FOUND\n");
        result = ARTNET_EFOUND;
    }
    return result;
}
int main(int argc, char *argv[]){
    int r=atoi(argv[1]);
    int g=atoi(argv[2]);
    int b=atoi(argv[3]);

    artnet_node node;
    node = artnet_new(NULL, 0);
    artnet_set_node_type(node, ARTNET_RAW);
    if (artnet_start(node) != ARTNET_EOK) {
        printf("Oh, kaputt: %s\n", artnet_strerror());
        return 1;
    }
    uint8_t dmx[3];
    dmx[0]=r;
    dmx[1]=g;
    dmx[2]=b;
    artnet_raw_send_dmx(node, 0, 1, dmx);
    artnet_raw_send_dmx(node, 0, 2, dmx);
    artnet_raw_send_dmx(node, 0, 3, dmx);
}