/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package udpUnitAdapt;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import message.UdpMessage;
/**
*
* @author axelsben
*/
public class adaptor {
private static unitClient uc = new unitClient("10.0.1.3",4774); //acer laptop DL
private static unitServer us = new unitServer("10.0.1.3",4776); //acer laptop UL
private static appClient ac = new appClient("10.0.1.90",12345); //android uplnk
private static appServer as = new appServer("10.0.1.90",12345); // android nerlnk
private static String strRetVal = "";
private static UdpMessage nda = null;
public static void app2unit(byte[] byteArray, int length)
{
nda = new UdpMessage("","",0);
nda.ASCIIDeSerialize(byteArray, length);
// Send to Unit
System.out.println(nda);
if(nda.getCommand().equalsIgnoreCase("set")){
uc.send(new String("#" + nda.getCommand().toLowerCase() + "*" + nda.getType().toLowerCase() + "*" + nda.getValue()).getBytes());
}else if(nda.getCommand().equalsIgnoreCase("get")){
uc.send(new String("#" + nda.getCommand().toLowerCase() + "*" + nda.getType().toLowerCase() + "*").getBytes());
}
}
public static void unit2app(byte[] byteArray)
{
String str = new String(byteArray, 0, byteArray.length);
strRetVal += str;
if(strRetVal.contains("\n")){
strRetVal = strRetVal.substring(0, strRetVal.indexOf("\r"));
if(strRetVal.equalsIgnoreCase("not implemented!"))
{
strRetVal = "-1";
}
// Do command handling, fill in serialization class
UdpMessage um = new UdpMessage(nda.getCommand(), nda.getType(), Integer.parseInt(strRetVal));
ac.send(um.ASCIISerialize());
strRetVal = "";
}
}
}
|