[rcpilot-cvs] src/rcpilot/rcgs AGWAX25.java,NONE,1.1
Status: Beta
Brought to you by:
mjpawlowsky
|
From: <mjp...@us...> - 2004-03-12 17:38:56
|
Update of /cvsroot/rcpilot/src/rcpilot/rcgs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32733 Added Files: AGWAX25.java Log Message: Parses AGW Rax AX25 frames --- NEW FILE: AGWAX25.java --- package rcpilot.rcgs; import java.nio.ByteBuffer; import java.nio.Buffer; import java.nio.ByteOrder; public class AGWAX25{ public int port; public String destination; public String source; public String repeater_1; public String repeater_2; public byte control; public byte PID; public byte[] info; public AGWAX25(){ } public int decodeAX25(byte[] dat){ // Let's make sure we have the minimum size required if (dat.length < 17) return(-1); ByteBuffer bdat = ByteBuffer.wrap(dat); StringBuffer sb; // bdat.order(ByteOrder.LITTLE_ENDIAN); byte b; int t; // Get the port b = bdat.get(); port = (b&0xff); //Get the destination field sb = new StringBuffer(); for (int i = 0; i<6; i++){ b = bdat.get(); t = (b & 0xff); t = t >> 1; sb.append((char)t); } b = bdat.get(); int s = makeSSID(b); if (s != 0) { sb.append('-'); sb.append(Integer.toString(s)); } this.destination = sb.toString(); // Get the source field sb = new StringBuffer(); int more = 0; for (int i = 0; i<6; i++){ b = bdat.get(); more = (b & 0x01); t = (b & 0xff); t = t >> 1; sb.append((char)t); } b = bdat.get(); s = makeSSID(b); if (s != 0) { sb.append('-'); sb.append(Integer.toString(s)); } this.source = sb.toString(); // If we have a repeater_1 if (more == 1){ sb = new StringBuffer(); for (int i = 0; i<6; i++){ b = bdat.get(); more = (b & 0x01); t = (b & 0xff); t = t >> 1; sb.append((char)t); } b = bdat.get(); s = makeSSID(b); if (s != 0) { sb.append('-'); sb.append(Integer.toString(s)); } this.repeater_1 = sb.toString(); } // If we have a repeater_1 if (more == 1){ sb = new StringBuffer(); for (int i = 0; i<6; i++){ b = bdat.get(); more = b & 0x01; t = (b & 0xff); t = t >> 1; sb.append((char)t); } b = bdat.get(); s = makeSSID(b); if (s != 0) { sb.append('-'); sb.append(Integer.toString(s)); } this.repeater_2 = sb.toString(); } // Get the control byte control = bdat.get(); // Getthe PID byte PID = bdat.get(); // Get the info bytes info = new byte[bdat.remaining()]; bdat.get(info, 0, bdat.remaining()); return(0); } private int makeSSID(byte ssid){ int i = (int)(ssid & 0x0E); return(i); } } |