void artnet_main(void) { if (get_dmx_slot_state(artnet_inputUniverse, artnet_conn_id) == DMX_NEWVALUES && artnet_connected == TRUE) { ARTNET_DEBUG("Universe has changed, sending artnet data!\r\n"); artnet_sendDmxPacket(); } }
/* ---------------------------------------------------------------------------- * initialization of Art-Net */ void artnet_init(void) { ARTNET_DEBUG("Init\n"); /* read Art-Net port */ artnet_port = CONF_ARTNET_PORT; /* read netconfig */ artnet_netConfig = NETCONFIG_DEFAULT; /* read subnet */ artnet_subNet = SUBNET_DEFAULT; artnet_inputUniverse = CONF_ARTNET_INUNIVERSE; artnet_outputUniverse = CONF_ARTNET_OUTUNIVERSE; strcpy_P(artnet_shortName, PSTR("e6ArtNode")); strcpy_P(artnet_longName, PSTR("e6ArtNode hostname: " CONF_HOSTNAME)); /* dmx storage connection */ artnet_conn_id = dmx_storage_connect(artnet_inputUniverse); if (artnet_conn_id != -1) { artnet_connected = TRUE; ARTNET_DEBUG("Connection to dmx-storage established! id:%d\r\n", artnet_conn_id); } else { artnet_connected = FALSE; ARTNET_DEBUG("Connection to dmx-storage couldn't be established!\r\n"); } /* net_init */ artnet_netInit(); /* annouce that we are here */ ARTNET_DEBUG("send PollReply\n"); artnet_sendPollReply(); /* enable PollReply on changes */ artnet_sendPollReplyOnChange = TRUE; ARTNET_DEBUG("init complete\n"); return; }
/* ---------------------------------------------------------------------------- * send an ArtPollReply packet */ void artnet_sendPollReply(void) { /* prepare artnet PollReply packet */ struct artnet_pollreply *msg = (struct artnet_pollreply *) &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; memset(msg, 0, sizeof(struct artnet_pollreply)); ARTNET_DEBUG("PollReply allocated\n"); msg->id[0] = 'A'; msg->id[1] = 'r'; msg->id[2] = 't'; msg->id[3] = '-'; msg->id[4] = 'N'; msg->id[5] = 'e'; msg->id[6] = 't'; msg->opcode = OP_POLLREPLY; memcpy (msg->addr.ip, uip_hostaddr, 4); msg->addr.port = artnet_port; msg->versionInfoH = (FIRMWARE_VERSION >> 8) & 0xFF; msg->versionInfo = FIRMWARE_VERSION & 0xFF; msg->subSwitchH = 0; msg->subSwitch = artnet_subNet & 15; msg->oem = (unsigned short)OEM_ID; msg->ubeaVersion = 0; msg->status = 0; msg->estaMan = 'D' * 256 + 'P'; strcpy(msg->shortName, artnet_shortName); strcpy(msg->longName, artnet_longName); sprintf(msg->nodeReport, "#%04X [%04u] AvrArtNode is ready", artnet_status, artnet_pollReplyCounter); msg->numPortsH = 0; msg->numPorts = 1; if (artnet_dmxDirection == 1) { msg->portTypes[0] = PORT_TYPE_DMX_INPUT; } else { msg->portTypes[0] = PORT_TYPE_DMX_OUTPUT; } if (artnet_dmxDirection != 1) { msg->goodInput[0] = (1 << 3); } else { if (artnet_dmxChannels > 0) { msg->goodInput[0] |= (1 << 7); } } msg->goodOutput[0] = (1 << 1); if (artnet_dmxTransmitting == TRUE) { msg->goodOutput[0] |= (1 << 7); } msg->swin[0] = (artnet_subNet & 15) * 16 | (artnet_inputUniverse1 & 15); msg->swout[0] = (artnet_subNet & 15) * 16 | (artnet_outputUniverse1 & 15); msg->style = STYLE_NODE; memcpy (msg->mac, uip_ethaddr.addr, 6); /* broadcast the packet */ artnet_send(sizeof(struct artnet_pollreply)); }
/* ---------------------------------------------------------------------------- * receive Art-Net packet */ void artnet_get(void) { struct artnet_header *header; header = (struct artnet_header *)uip_appdata; /* check the id */ if ( (header->id[0] != 'A') || (header->id[1] != 'r') || (header->id[2] != 't') || (header->id[3] != '-') || (header->id[4] != 'N') || (header->id[5] != 'e') || (header->id[6] != 't') || (header->id[7] != 0 ) ) { ARTNET_DEBUG("Wrong ArtNet header, discarded\r\n"); artnet_status = RC_PARSE_FAIL; return; } if (header->opcode == OP_POLL) { struct artnet_poll *poll; ARTNET_DEBUG("Received artnet poll packet!\r\n"); poll = (struct artnet_poll *)uip_appdata; // processPollPacket(poll); } else if (header->opcode == OP_POLLREPLY) { ARTNET_DEBUG("Received artnet poll reply packet!\r\n"); } else if (header->opcode == OP_OUTPUT) { struct artnet_dmx *dmx; ARTNET_DEBUG("Received artnet output packet!\r\n"); dmx = (struct artnet_dmx *)uip_appdata; if (dmx->universe == ((artnet_subNet << 4) | artnet_outputUniverse1)) { if (artnet_dmxDirection == 0) { uint16_t len = (dmx->lengthHi << 8) + dmx->length; ARTNET_DEBUG ("Updating %d channels ...\n", len); #ifdef DMX_SUPPORT if (len > CONF_DMX_MAX_CHAN) len = CONF_DMX_MAX_CHAN; memcpy (dmx_data, &dmx->dataStart, len); dmx_prg = 0; #endif /* DMX_SUPPORT */ #ifdef STELLA_SUPPORT stella_dmx(&dmx->dataStart, len); #endif if (artnet_sendPollReplyOnChange == TRUE) { artnet_pollReplyCounter++; artnet_sendPollReply(); } } } } else if (header->opcode == OP_ADDRESS) { struct artnet_address *address; ARTNET_DEBUG("Received artnet address packet!\r\n"); address = (struct artnet_address *)uip_appdata; // processAddressPacket(address); } else if (header->opcode == OP_IPPROG) { struct artnet_ipprog *ipprog; ARTNET_DEBUG("Received artnet ip prog packet!\r\n"); ipprog = (struct artnet_ipprog *)uip_appdata; // processIpProgPacket(ipprog); } }
/* ---------------------------------------------------------------------------- * initialization of Art-Net */ void artnet_init(void) { ARTNET_DEBUG("Init\n"); /* read Art-Net port */ // eeprom_read_block(&artnet_port, (unsigned char *)ARTNET_PORT_EEPROM_STORE, 2); // if (artnet_port == 0xFFFF) { artnet_port = PORT_DEFAULT; // } /* read netconfig */ // artnet_netConfig = eeprom_read_byte((unsigned char *)ARTNET_NETCONFIG_EEPROM_STORE); // if (artnet_netConfig == 0xFF) { artnet_netConfig = NETCONFIG_DEFAULT; // } /* read subnet */ // artnet_subNet = eeprom_read_byte((unsigned char *)ARTNET_SUBNET_EEPROM_STORE); // if (artnet_subNet == 0xFF) { artnet_subNet = SUBNET_DEFAULT; // } /* read nr. of input universe */ // artnet_inputUniverse1 = eeprom_read_byte((unsigned char *)ARTNET_INUNIVERSE_EEPROM_STORE); // if (artnet_inputUniverse1 == 0xFF) { artnet_inputUniverse1 = INUNIVERSE_DEFAULT; // } /* read nr. of output universe */ // artnet_outputUniverse1 = eeprom_read_byte((unsigned char *)ARTNET_OUTUNIVERSE_EEPROM_STORE); // if (artnet_outputUniverse1 == 0xFF) { artnet_outputUniverse1 = OUTUNIVERSE_DEFAULT; // } /* read short name */ // eeprom_read_block(&artnet_shortName, (unsigned char *)ARTNET_SHORTNAME_EEPROM_STORE, SHORT_NAME_LENGTH); // if ((*((unsigned long*)&artnet_shortName[0])) == 0xFFFFFFFF) { /* fill with zeroes */ for (unsigned char i = 0; i < SHORT_NAME_LENGTH; i++) { artnet_shortName[i] = 0; } strcpy_P(artnet_shortName, PSTR("AvrArtNode")); // } artnet_shortName[SHORT_NAME_LENGTH - 1] = 0; /* read long name */ // eeprom_read_block(&artnet_longName, (unsigned char *)ARTNET_LONGNAME_EEPROM_STORE, LONG_NAME_LENGTH); // if ((*((unsigned long*)&artnet_longName[0])) == 0xFFFFFFFF) { /* fill with zeroes */ for (unsigned char i = 0; i < LONG_NAME_LENGTH; i++) { artnet_longName[i] = 0; } strcpy_P(artnet_longName, PSTR("AVR based Art-Net node")); // } artnet_longName[LONG_NAME_LENGTH - 1] = 0; // ARTNET_DEBUG("net init\n"); artnet_netInit(); /* annouce that we are here */ ARTNET_DEBUG("send PollReply\n"); artnet_sendPollReply(); /* enable PollReply on changes */ artnet_sendPollReplyOnChange = TRUE; ARTNET_DEBUG("init complete\n"); return; }