 *************************************************************************/
 
 void loop() {
+
   read_result_artnet1 = RESULT_NONE;
   read_result_artnet2 = RESULT_NONE;
   read_result_sacn1 = RESULT_NONE;
   read_result_sacn2 = RESULT_NONE;
-  
+
   packetSize = aUDP.parsePacket();
   if ( packetSize ) {
-  	packetSize = aUDP.read(artnetBuffer, ARTNET_BUFFER_MAX);
+	packetSize = aUDP.read(artnetBuffer, ARTNET_BUFFER_MAX);
 	  read_result_artnet1 = artNetInterface->readDMXPacketContents(&aUDP, packetSize);
 	  if ( read_result_artnet1 == RESULT_NONE ) {				// if not good_dmx or otherwise handled, try 2nd universe
-      read_result_artnet2 = artNetInterfaceUniverse2->readDMXPacketContents(&aUDP, packetSize);
+	  read_result_artnet2 = artNetInterfaceUniverse2->readDMXPacketContents(&aUDP, packetSize);
 	  }
   }
-  
+
 #if defined ( use_multicast )
   packetSize = sUDP.parsePacket();
   if ( packetSize ) {
-    packetSize = sUDP.read(sACNBuffer, SACN_BUFFER_MAX);
-  	read_result_sacn1 = sACNInterface->readDMXPacketContents(&sUDP, packetSize);
+	  packetSize = sUDP.read(sACNBuffer, SACN_BUFFER_MAX);
+	  read_result_sacn1 = sACNInterface->readDMXPacketContents(&sUDP, packetSize);
   }
   // read packet from 2nd multicast address
   packetSize = tUDP.parsePacket();
   if ( packetSize ) {
-    packetSize = tUDP.read(sACNBuffer, SACN_BUFFER_MAX);
-    read_result_sacn2 = sACNInterfaceUniverse2->readDMXPacketContents(&tUDP, packetSize);
+	  packetSize = tUDP.read(sACNBuffer, SACN_BUFFER_MAX);
+	  read_result_sacn2 = sACNInterfaceUniverse2->readDMXPacketContents(&tUDP, packetSize);
   }
 #else
   //assume sender unicasts both universes to same IP address
   packetSize = sUDP.parsePacket();
   if ( packetSize ) {
-    packetSize = sUDP.read(sACNBuffer, SACN_BUFFER_MAX);
-    read_result_sacn1 = sACNInterface->readDMXPacketContents(&sUDP, packetSize);
-    if ( read_result_sacn1 == RESULT_NONE ) {       // if not good_dmx or otherwise handled, try 2nd universe
-      read_result_sacn2 = sACNInterfaceUniverse2->readDMXPacketContents(&sUDP, packetSize);
-    }   // was not dmx first universe
+	  packetSize = sUDP.read(sACNBuffer, SACN_BUFFER_MAX);
+	  read_result_sacn1 = sACNInterface->readDMXPacketContents(&sUDP, packetSize);
+	if ( read_result_sacn1 == RESULT_NONE ) {       // if not good_dmx or otherwise handled, try 2nd universe
+	  read_result_sacn2 = sACNInterfaceUniverse2->readDMXPacketContents(&sUDP, packetSize);
+	}   // was not dmx first universe
   }     // no packetSize
 #endif
 
   if ((read_result_artnet1 == RESULT_DMX_RECEIVED) || (read_result_sacn1 == RESULT_DMX_RECEIVED)) {
-    copyDMX1ToOutput();
-    blinkLED();
+	  copyDMX1ToOutput();
+	  blinkLED();
   } else if ( rdm_enabled ) {
-  	updateRDMDiscovery();
+	  updateRDMDiscovery();
   }
   if ((read_result_artnet2 == RESULT_DMX_RECEIVED) || (read_result_sacn2 == RESULT_DMX_RECEIVED)) {
-    copyDMX2ToOutput();
-    blinkLED2();
+	  copyDMX2ToOutput();
+	  blinkLED2();
   }
 
   uint8_t dhcpr = Ethernet.maintain();
   if (( dhcpr == 4 ) || (dhcpr == 2)) {	//renew/rebind success, update ArtPollReply
-  	artNetInterface->setLocalIP(Ethernet.localIP(), Ethernet.subnetMask());
-  	artNetInterfaceUniverse2->setLocalIP(Ethernet.localIP(), Ethernet.subnetMask());
-  }
+	  artNetInterface->setLocalIP(Ethernet.localIP(), Ethernet.subnetMask());
+	  artNetInterfaceUniverse2->setLocalIP(Ethernet.localIP(), Ethernet.subnetMask());
+  }
+
 } //loop()

  Ethernet.begin(mac);

  // Initialize Interfaces
  uint8_t interface1univ = 1;
  uint8_t interface2univ = 0;
  sACNInterface = new LXSACN(sACNBuffer);
  sACNInterface->enableHTP();
  sACNInterface->setUniverse(interface1univ+1);

  return 0;     // none left to pop
}

void sendTODifChanged() {
  if ( tableChangedFlag ) {   //if the table has changed...
    tableChangedFlag--;
    
    artNetInterface->send_art_tod(&aUDP, tableOfDevices.rawBytes(), tableOfDevices.count());
#if defined PRINT_DEBUG_MESSAGES
    Serial.println("_______________ Table Of Devices _______________");
    tableOfDevices.printTOD();
#endif
  }
}

void updateRDMDiscovery() {
  	if ( rdm_discovery_enable ) {  // run RDM updates for a limited number of times
	  if ( discovery_state ) {
		// check the table of devices#if defined PRINT_DEBUG_MESSAGES

		discovery_tbl_ck_index = checkTable(discovery_tbl_ck_index);
	
		if ( discovery_tbl_ck_index == 0 ) {
		  // done with table check
		  discovery_state = DISC_STATE_SEARCH;
		  pushInitialBranch();
   
		  sendTODifChanged();
		} //end table check ended
	  } else {    // search for devices in range popped from discoveryTree
	
		if ( checkNextRange() == 0 ) {
		  // done with search
		  discovery_tbl_ck_index = 0;
		  discovery_state = DISC_STATE_TBL_CK;
		  
		  sendTODifChanged();
		  if ( RDM_DISCOVER_ALWAYS == 0 ) {
		     rdm_discovery_enable--;
		  }
		}
	  }           //end search
  }               //end rdm_discovery_enable
}


