aboutsummaryrefslogtreecommitdiff
path: root/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2010-04-11 14:32:30 +0000
committerAnton Tananaev <anton.tananaev@gmail.com>2010-04-11 14:32:30 +0000
commit794c0ef3f92e5031dd7722325933d4cefdfce047 (patch)
treec0b573e68a4aebea3a0ac9817082740d86fdd1d3 /src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
parentc9e11760f2131a9d0123c8575eaafc22dca407e3 (diff)
downloadtrackermap-server-794c0ef3f92e5031dd7722325933d4cefdfce047.tar.gz
trackermap-server-794c0ef3f92e5031dd7722325933d4cefdfce047.tar.bz2
trackermap-server-794c0ef3f92e5031dd7722325933d4cefdfce047.zip
Import project
Diffstat (limited to 'src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java')
-rw-r--r--src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java b/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
new file mode 100644
index 000000000..338c7bec9
--- /dev/null
+++ b/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java
@@ -0,0 +1,105 @@
+/*
+ * Минимум - 100
+ * Начало - (10 цифр) + ','
+ * Длина 16 x ','
+ */
+
+package net.sourceforge.opentracking.protocol.xexun;
+
+import org.jboss.netty.handler.codec.frame.FrameDecoder;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.buffer.ChannelBuffer;
+
+/**
+ *
+ */
+public class XexunFrameDecoder extends FrameDecoder {
+
+ protected Object decode(
+ ChannelHandlerContext ctx,
+ Channel channel,
+ ChannelBuffer buf) throws Exception {
+
+ System.out.println("read: " + buf.readableBytes());
+
+ // Check minimum length
+ int length = buf.readableBytes();
+ if (length < 100) {
+ return null;
+ }
+
+ // Find identifier
+ int index = 0;
+ int countDigit = 0;
+ for (; index < length; index++) {
+
+ // Check byte
+ char c = (char) buf.getByte(index);
+ if (Character.isDigit(c)) {
+ countDigit++;
+ }
+
+ // Check count
+ if (countDigit == 10) {
+ break;
+ }
+ }
+
+ if (countDigit < 10) {
+ return null;
+ }
+
+ // Find begin
+ int beginIndex = 0;
+ for (; index < length; index++) {
+
+ char c = (char) buf.getByte(index);
+ if (c == ',') {
+ beginIndex = index;
+ break;
+ }
+ }
+
+ if (beginIndex == 0) {
+ return null;
+ }
+
+ // Find imei
+ int imeiIndex = 0;
+ for (; index < length; index++) {
+
+ char c = (char) buf.getByte(index);
+ if (c == ':') {
+ imeiIndex = index;
+ break;
+ }
+ }
+
+ if (imeiIndex == 0) {
+ return null;
+ }
+
+ // Find end
+ int endIndex = 0;
+ for (; index < length; index++) {
+
+ char c = (char) buf.getByte(index);
+ if (c == ',') {
+ endIndex = index;
+ break;
+ }
+ }
+
+ if (endIndex == 0) {
+ return null;
+ }
+
+ // Read buffer
+ buf.skipBytes(beginIndex);
+ ChannelBuffer frame = buf.readBytes(endIndex - beginIndex + 1);
+
+ return frame;
+ }
+
+}