Monday, August 20, 2012

POE (Power Over Ethernet)

VoIP (Voice over IP) has always fascinated me. I worked on EPABX software in 1993-94 time frame. It was all embedded world then. Smart members of our team developed the EPABX software in C programming language. It was all fun.
After so long, we have free commercial grade VoIP server softwares available, which can be installed on Linux server and used. Cheapest way to use them is by installing soft phones on PC. Other alternative is to use expensive VoIP phone instruments. These instrument come in two forms. One which takes power from Adapter and other ones expect power to be fed to them over regular Ethernet wire, which is generally used for Data communication.

I was very curious to know how power is given to these VoIP phone devices. The Ethernet cable has 4 pair of wire inside it. They are color coded too. The colors used are Green, Orange, Blue and Brown. The diagram below gives you the pin numbering of the RJ45 connector which is used to connect Ethernet cable to your PC, Laptop etc.


We can see from the diagram above, that out of 8 pins of RJ45 connector only 4 are used for Transmitting and receiving data where as remaining 4 pins ( 2 pairs) are reserved, i.e not used.

Basically these 4 pins or two pairs are used to transmit power. There are many schemes used by various vendors but most common of all, is to use pin 4 and 5 for +ve end of power source and pin 7 and 8 for the -ve end of power source.

Again, there is no specific standard on how much power is to be transferred. These pins are used to transmit from 12v to 48v depending on the need.

So these were some basics of POE ( Power over Ethernet)

Till next, take care.
 

Tuesday, August 14, 2012

Custom classloaders in Java

Friends,
I was obsessed with custom class loaders in Java because I faced a real issue while working on the project. The JAX-WS implementation would work on one App Server where the same code would fail on the other. I knew it could be because of Classloaders and how different vendors of App server implement features documented in Specs.
Well, after little reading I realized how a premitive Class loader can be written. Idea was to load a class using custom class loader and test if the same is really loaded using my class loader or by system class loader. If the the class we are trying to load is in classpath, then it gets loaded by system class loader by default and I did not really understand how not to keep my class on the class path and then load it using custom class loader.
I decided to load a class from a random directory which is NOT in the class path. Now I would load the class bytes from the class file for my class but would fail for java.lang.Object. As we all know, every class in Java is child of java.lang.Object :-) Now my class loader would fail because it could not find the class file for java.lang.Object at the specified location. After careful analysis I realized where the mistake was. I was trying to load all the classes (including system classes) using my custom class loader. Then I changed the approach to:
  • Check if the class is already loaded by custom class loader in the cache.
  • If not already loaded, use System class loader to load it for you.
  • If System class loader can not load it, then use our custom logic to load the byte codes from the generated .class file
  • Define and return the loaded class
This is "System class loader first" approach, where is I check if system class loader can load the class for me and use my custom class loader only if it fails to load.
Java also has Class loader hierarchy, which needs to be looked at. The behavious depends upon which method/s we override while extending java.lang.ClassLoader. I still have to look into it.
I managed to get my custom class loader working and also tested with a sample program. I will post it here once the cleanup is done.
Till then, take care.
- Manoj

Nice MBR and FAT recovery tool

Hi,

I have been experimenting a bit about Boot loaders in general for a while now. Found a piece of code, which when loaded onto first sector of first track etc, recognizes the hard drive as a bootable drive and prints message etc.

In the frenzy of testing this code, I used my 8GB pen drive, which had lot of valuable data on it and updated so called MBR ( Master Boot Record ). Needless to say that the experiment failed.

I had a pen drive with data on it, but just MBR overwritten with junk bytes on it. The Windows would recognize the drive, but said, it needs to be formatted. Linux sensed the pen drive connected, but would not mount the media as it did not find correct information in the MBR.

I was determined to NOT to format the pen drive and loose all the data on it. Tried lot many tricks, but they didn't work.

Finally, came across this wonderful free tool at http://www.cgsecurity.org/wiki/Advanced_FAT_Repair, which did the trick.

The tool is simple and easy to use and did precisely what needed it to do. It restored my MBR with default and I managed to see ALL my data intact on the pen drive.

Now, it has made me think more about bit and byte of format process. Will pen down my Boot Loader experiment once I see some ray of hope.

Till then, take care.