// ----------------------------------------------------------------------------
void artnet_main(void) {
	if (artnet_dmxInComplete == TRUE) {
		if (artnet_dmxInChanged == TRUE) {
			artnet_sendDmxPacket();
			artnet_dmxInChanged = FALSE;
		}
		artnet_dmxInComplete = FALSE;
		artnet_dmxChannels = 0;
	}
	if(artnet_poll == 1)
	{
		artnet_poll = 0;
		artnet_sendPollReply();
	}	
	
	if (DMXIOPinPort & (1 << DMXIOPin))
	{
		artnet_rs485_safty_counter++;
		if(artnet_rs485_safty_counter > 250)
		{
			artnet_dmxChannels = 511;
			// setup USART
			PORTD |= (1 << 2);
			PORTD |= (1 << 1);
			UBRR0   = (F_CPU / (250000* 16L) - 1);
			UCSR0C|= (1<<USBS0); //USBS0 2 Stop bits
			UCSR0B|= (1<<TXEN0)|(1<<TXCIE0); // TXEN0 Transmitter enable / TXCIE0 TX complete interrupt enable
			UDR0    = 0;//start transmitting
			artnet_rs485_safty_counter = 0;
		}
	}
}
Exemple #2
0
/* ----------------------------------------------------------------------------
 * receive Art-Net packet
 */
void
artnet_get(void)
{
  struct artnet_header *header;

  header = (struct artnet_header *) uip_appdata;

  /* check the id */
  if (strncmp_P((char *) header->id, artnet_ID, 8))
  {
    ARTNET_DEBUG("Wrong ArtNet header, discarded\r\n");
    artnet_status = RC_PARSE_FAIL;
    return;
  }
  switch (header->opcode)
  {
    case OP_POLL:;
      struct artnet_poll *poll;

      ARTNET_DEBUG("Received artnet poll packet!\r\n");
      poll = (struct artnet_poll *) uip_appdata;
      processPollPacket(poll);
      break;
    case OP_POLLREPLY:;
      ARTNET_DEBUG("Received artnet poll reply packet!\r\n");
      break;
    case OP_OUTPUT:;
      uip_ipaddr_t artnet_pollReplyTarget;
      struct artnet_dmx *dmx;

      ARTNET_DEBUG("Received artnet output packet!\r\n");
      dmx = (struct artnet_dmx *) uip_appdata;
      uip_ipaddr_copy(&artnet_pollReplyTarget, BUF->srcipaddr);

      if (dmx->universe == ((artnet_subNet << 4) | artnet_outputUniverse))
      {
        if (artnet_dmxDirection == 0)
        {
          uint16_t len = ((dmx->lengthHi << 8) + dmx->length);
          set_dmx_channels((const uint8_t *) &dmx->dataStart,
                           artnet_outputUniverse, 0, len);
          if (artnet_sendPollReplyOnChange == TRUE)
          {
            artnet_pollReplyCounter++;
            artnet_sendPollReply(&artnet_pollReplyTarget);
          }
        }
      }
      break;
    case OP_ADDRESS:;
    case OP_IPPROG:;
      break;
    default:
      ARTNET_DEBUG("Received an invalid artnet packet!\r\n");
      break;
  }
}
Exemple #3
0
void
processPollPacket(struct artnet_poll *poll)
{
  if ((poll->talkToMe & 2) == 2)
    artnet_sendPollReplyOnChange = TRUE;
  else
    artnet_sendPollReplyOnChange = FALSE;
  if ((poll->talkToMe & 1) == 1)
    artnet_pollReplyTarget = *uip_hostaddr;
  else
    artnet_pollReplyTarget = (uint64_t) 0xffffffff;
  artnet_sendPollReply();
}
Exemple #4
0
/* ----------------------------------------------------------------------------
 * 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;
#ifdef CONF_ARTNET_SEND_POLL_REPLY
  artnet_sendPollReplyOnChange = 1;
#else
  artnet_sendPollReplyOnChange = 0;
#endif
  strcpy_P(artnet_shortName, PSTR("e6ArtNode"));
  strcpy_P(artnet_longName, PSTR("e6ArtNode hostname: " CONF_HOSTNAME));

  set_CONF_ARTNET_OUTPUT_IP(&artnet_outputTarget);

  /* 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(&all_ones_addr);

  /* enable PollReply on changes */
  artnet_sendPollReplyOnChange = TRUE;
  ARTNET_DEBUG("init complete\n");
  return;
}
// ----------------------------------------------------------------------------
// process an ArtPoll packet
void processPollPacket(struct artnet_poll *poll) {
	if ((poll->talkToMe & 2) == 2) {
		artnet_sendPollReplyOnChange = TRUE;
	} else {
		artnet_sendPollReplyOnChange = FALSE;
	}

	if ((poll->talkToMe & 1) == 1) {
		struct IP_Header *ip;
		ip = (struct IP_Header *)&eth_buffer[IP_OFFSET];
		artnet_pollReplyTarget = ip->IP_Srcaddr;
	} else {
		artnet_pollReplyTarget = (unsigned long)0xffffffff;
	}

	artnet_sendPollReply();
}
Exemple #6
0
void
processPollPacket(struct artnet_poll *poll)
{
  uip_ipaddr_t poll_reply_target;
  if ((poll->talkToMe & 2) == 2)
    artnet_sendPollReplyOnChange = TRUE;
  else
    artnet_sendPollReplyOnChange = FALSE;
  if ((poll->talkToMe & 1) == 1)
    uip_ipaddr_copy(poll_reply_target, uip_hostaddr);
  else
    uip_ipaddr_copy(poll_reply_target, all_ones_addr);
  artnet_sendPollReply(&poll_reply_target);

  /* we send a dmx packet on a poll packet, if artnet_sendPollReplyOnChange is active */
  if (artnet_sendPollReplyOnChange)
    artnet_sendDmxPacket();
}
// ----------------------------------------------------------------------------
// initialization of Art-Net
void artnet_init(void) {
	 // set ports for USART, port direction and dip-switches
	 DMXDirectionPort  |= (1<<DMXTXD)|(1<<DMXDIR_IO); // DIR_IO and TXD Output
	
	 //PULLUP DMX IN/OUT
	 DMXIOPullupPort |= (1<<DMXIOPullupPin);

	 // read Art-Net port
	artnet_port = PORT_DEFAULT;

	// read netconfig
	artnet_netConfig = NETCONFIG_DEFAULT;

	// read subnet
	artnet_subNet = SUBNET_DEFAULT;

	artnet_inputUniverse1 = INUNIVERSE_DEFAULT;

	// read nr. of output universe
	artnet_outputUniverse1 = OUTUNIVERSE_DEFAULT;

	// read short name
	strcpy_P(artnet_shortName, PSTR("AvrArtNode\0"));
	artnet_shortName[SHORT_NAME_LENGTH - 1] = 0;

	// read long name
	strcpy_P(artnet_longName, PSTR("AVR based Art-Net node\0"));
	artnet_longName[LONG_NAME_LENGTH - 1] = 0;

	artnet_netInit();

	// annouce that we are here 
	artnet_sendPollReply();

	// enable PollReply on changes
	artnet_sendPollReplyOnChange = TRUE;

	return;
}
// ----------------------------------------------------------------------------
// receive Art-Net packet
void artnet_get(unsigned char index) {
	struct artnet_header *header;

	header = (struct artnet_header *)&eth_buffer[UDP_DATA_START];
	//check the id
	if(strcasestr_P((char*)&header->id,PSTR("Art-Net")) == 0){
		//ARTNET_DEBUG("Wrong ArtNet header, discarded\r\n");
		artnet_status = RC_PARSE_FAIL;
		return;
	}

	switch(header->opcode)
	{
		//OP_POLL
		case (OP_POLL):{
			struct artnet_poll *poll;
			//ARTNET_DEBUG("Received artnet poll packet!\r\n");
			poll = (struct artnet_poll *)&eth_buffer[UDP_DATA_START];
			processPollPacket(poll);
			return;
		}
		//OP_POLLREPLY
		case (OP_POLLREPLY):{
			//ARTNET_DEBUG("Received artnet poll reply packet!\r\n");
			return;
		}
		//OP_OUTPUT
		case (OP_OUTPUT):{
			struct artnet_dmx *dmx;

			//ARTNET_DEBUG("Received artnet output packet!\r\n");
			dmx = (struct artnet_dmx *)&eth_buffer[UDP_DATA_START];

			if (dmx->universe == ((artnet_subNet << 4) | artnet_outputUniverse1)) 
			{
				if (artnet_dmxDirection == 0)
				{
					artnet_dmxChannels = (dmx->lengthHi << 8) | dmx->length;
					memcpy((unsigned char*)&artnet_dmxUniverse[0], &(dmx->dataStart), artnet_dmxChannels);
					
					if (artnet_dmxTransmitting == FALSE)
						{
						// setup USART
						DMXPort |= (1 << DMXDIR_IO);
						DMXPort |= (1 << DMXTXD);
						UBRR0   = (F_CPU / (250000* 16L) - 1);
						UCSR0C|= (1<<USBS0); //USBS0 2 Stop bits
						UCSR0B|= (1<<TXEN0)|(1<<TXCIE0); // TXEN0 Transmitter enable / TXCIE0 TX complete interrupt enable
						UDR0    = 0;//start transmitting

						artnet_dmxTransmitting = TRUE;
						if (artnet_sendPollReplyOnChange == TRUE) {
							artnet_pollReplyCounter++;
							artnet_sendPollReply();
						}
					}
					isActive = 1;

				}
			}
			return;
		}
		//OP_ADDRESS
		case (OP_ADDRESS):{
			struct artnet_address *address;
			//ARTNET_DEBUG("Received artnet address packet!\r\n");
			address = (struct artnet_address *)&eth_buffer[UDP_DATA_START];
			//processAddressPacket(address);
			return;
		}
		//OP_IPPROG
		case (OP_IPPROG):{
			struct artnet_ipprog *ipprog;
			//ARTNET_DEBUG("Received artnet ip prog packet!\r\n");
			ipprog = (struct artnet_ipprog *)&eth_buffer[UDP_DATA_START];
			//processIpProgPacket(ipprog);
			return;		
		}	
	}
}
Exemple #9
0
int16_t
parse_cmd_artnet_pollreply(int8_t * cmd, int8_t * output, uint16_t len)
{
  artnet_sendPollReply(&all_ones_addr);
  return ECMD_FINAL_OK;
}
Exemple #10
0
/* ----------------------------------------------------------------------------
 * 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);
 }
}
Exemple #11
0
int16_t 
parse_cmd_artnet_pollreply (char *cmd, char *output, uint16_t len)
{
  artnet_sendPollReply();
  return ECMD_FINAL_OK;
}
Exemple #12
0
/* ----------------------------------------------------------------------------
 * 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;
}