aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-03-23 21:42:43 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-03-23 21:42:43 +1300
commitac2f547aa7799e471a8f4a71812fe8efdf5505c5 (patch)
tree163b16ca93714fb18be5c432324433177bff8f41
parent23086613c6e88aa768afa795340fe9ac0ac3a7db (diff)
downloadtraccar-server-ac2f547aa7799e471a8f4a71812fe8efdf5505c5.tar.gz
traccar-server-ac2f547aa7799e471a8f4a71812fe8efdf5505c5.tar.bz2
traccar-server-ac2f547aa7799e471a8f4a71812fe8efdf5505c5.zip
Fix Norad decoder (fix #610)
-rw-r--r--src/org/traccar/BasePipelineFactory.java7
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java39
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java8
-rwxr-xr-xtools/hex.sh2
4 files changed, 52 insertions, 4 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 9d2ab5071..e0c88ff90 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -15,6 +15,7 @@
*/
package org.traccar;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -66,6 +67,12 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
msg.append("[").append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort());
msg.append((e instanceof DownstreamMessageEvent) ? " -> " : " <- ");
+
+ event.getRemoteAddress().hashCode();
+ //InetSocketAddress a = (InetSocketAddress) event.getRemoteAddress();
+ //InetAddress b = a.getAddress();
+ //String s = b.getHostAddress();
+
msg.append(((InetSocketAddress) event.getRemoteAddress()).getAddress().getHostAddress()).append("]");
// Append hex message
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 657e56258..447bf364b 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -15,6 +15,12 @@
*/
package org.traccar;
+import java.net.SocketAddress;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelEvent;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import static org.jboss.netty.channel.Channels.fireMessageReceived;
+import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import org.traccar.model.DataManager;
@@ -51,5 +57,38 @@ public abstract class BaseProtocolDecoder extends OneToOneDecoder {
dataManager = serverManager.getDataManager();
}
}
+
+ @Override
+ public void handleUpstream(
+ ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
+ if (!(evt instanceof MessageEvent)) {
+ ctx.sendUpstream(evt);
+ return;
+ }
+
+ MessageEvent e = (MessageEvent) evt;
+ Object originalMessage = e.getMessage();
+ Object decodedMessage = decode(ctx, e.getChannel(), e.getRemoteAddress(), originalMessage);
+ if (originalMessage == decodedMessage) {
+ ctx.sendUpstream(evt);
+ } else if (decodedMessage != null) {
+ fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
+ }
+ }
+
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ return decode(ctx, channel, msg);
+
+ }
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
+
+ return null; // default implementation
+
+ }
}
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index 7fecf18e1..fc4654016 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -15,6 +15,7 @@
*/
package org.traccar.protocol;
+import java.net.SocketAddress;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.util.Calendar;
@@ -45,11 +46,11 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx, Channel channel, Object msg)
+ ChannelHandlerContext ctx, Channel channel, SocketAddress remoteAddress, Object msg)
throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
-
+
buf.readUnsignedShort(); // length
int type = buf.readUnsignedShort();
@@ -63,7 +64,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
response.writeByte(1); // status
response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset()));
- channel.write(response);
+ channel.write(response, remoteAddress);
}
else if (type == MSG_UPLOAD_POSITION ||
@@ -111,6 +112,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(getDataManager().getDeviceByImei(id).getId());
} catch(Exception error) {
Log.warning("Unknown device - " + id);
+ return null;
}
// IO status
diff --git a/tools/hex.sh b/tools/hex.sh
index 762af00d1..ddff34834 100755
--- a/tools/hex.sh
+++ b/tools/hex.sh
@@ -1,2 +1,2 @@
echo 242442323335363839353033373537383531387c4141244750524d432c3230333832332e3030302c412c333734302e333238352c4e2c30323132392e393239352c452c302e30302c2c3131313131332c2c2c412a37397c30312e357c30312e307c30312e317c3030303030303030303030307c32303133313131313230333832337c31343034313235317c30303030303030307c30303245304444377c303030307c302e303030307c363337317c333832340d0a | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie' | nc -v -w 10 localhost 5007
-
+#echo -n -e "\x0f\x00\x00\x00\x4e\x52\x30\x39\x46\x30\x34\x31\x35\x35\x00" >/dev/udp/localhost/5053