package sopc2dts.lib.boardinfo;

import org.xml.sax.Attributes;

public class BICEthernet {
	String name;
	Integer miiID = null;
	Integer phyID = null;
	int[] mac = { 0, 0, 0, 0, 0, 0 };

	public BICEthernet(String compName) {
		name = compName;
	}
	public BICEthernet(Attributes atts) {
		this(atts.getValue("name"));
		String sVal = atts.getValue("mii_id"); 
		if(sVal != null)
		{
			miiID = Integer.decode(sVal);
		}
		sVal = atts.getValue("phy_id"); 
		if(sVal != null)
		{
			miiID = Integer.decode(sVal);
		}
		setMac(atts.getValue("mac")); 
	}

	public String getName() {
		return name;
	}

	public String toXml() {
		String res = "<Ethernet name=\"" + name + "\" mac=\"" + getMacString() + "\"";
		if(miiID!=null)
		{
			res += " mii_id=\"" + miiID + "\"";
		}
		if(phyID!=null)
		{
			res += " phy_id=\"" + phyID + "\"";
		}
		res +="></Ethernet>\n";
		return res;
	}
	public String getMacString()
	{
		return String.format("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1],
				mac[2], mac[3], mac[4], mac[5]);
	}

	public Integer getMiiID() {
		return miiID;
	}

	public void setMiiID(Integer miiID) {
		this.miiID = miiID;
	}

	public Integer getPhyID() {
		return phyID;
	}

	public void setPhyID(Integer phyID) {
		this.phyID = phyID;
	}

	public int[] getMac() {
		return mac;
	}

	public void setMac(int[] mac) {
		if(mac.length == 6)
		{
			this.mac = mac;
		}
	}
	public void setMac(String sVal)
	{
		if(sVal != null)
		{
			String[] sMac = sVal.split(":");
			if(sMac.length==6)
			{
				for(int i=0; i<6; i++)
				{
					mac[i] = Integer.parseInt(sMac[i], 16);
				}
			}
		}
	}
}

@@ -1,8 +1,832 @@
+/*%0Asopc2dts - Devicetree generation for Altera systems%0A%0ACopyright (C) 2011 Walter Goossens %3Cwaltergoossens@home.nl%3E%0A%0AThis library is free software; you can redistribute it and/or%0Amodify it under the terms of the GNU Lesser General Public%0ALicense as published by the Free Software Foundation; either%0Aversion 2.1 of the License, or (at your option) any later version.%0A%0AThis library is distributed in the hope that it will be useful,%0Abut WITHOUT ANY WARRANTY; without even the implied warranty of%0AMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0ALesser General Public License for more details.%0A%0AYou should have received a copy of the GNU Lesser General Public%0ALicense along with this library; if not, write to the Free Software%0AFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA%0A*/%0A
 package 
@@ -1291,35 +1291,35 @@
 != null)%0A%09%09%7B%0A%09%09%09
-mii
+phy
 ID = Integer.dec

fix phy-/mii-id loading bug