forked from traccar/traccar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add BufferUtil helper class
- Loading branch information
Showing
19 changed files
with
129 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2018 Anton Tananaev ([email protected]) | ||
* Copyright 2018 Andrey Kunitsyn ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.traccar.helper; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.ByteBufUtil; | ||
import io.netty.buffer.Unpooled; | ||
|
||
public class BufferUtil { | ||
|
||
public static int indexOf(String needle, ByteBuf haystack) { | ||
return ByteBufUtil.indexOf( | ||
Unpooled.wrappedBuffer(needle.getBytes(StandardCharsets.US_ASCII)), haystack); | ||
} | ||
|
||
public static int indexOf(String needle, ByteBuf haystack, int startIndex, int endIndex) { | ||
int index = ByteBufUtil.indexOf( | ||
Unpooled.wrappedBuffer(needle.getBytes(StandardCharsets.US_ASCII)), | ||
Unpooled.wrappedBuffer(haystack.array(), startIndex, endIndex - startIndex)); | ||
return (index != -1) ? (startIndex + index) : -1; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2015 - 2017 Anton Tananaev ([email protected]) | ||
* Copyright 2015 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -15,13 +15,13 @@ | |
*/ | ||
package org.traccar.protocol; | ||
|
||
import org.jboss.netty.bootstrap.ServerBootstrap; | ||
import org.jboss.netty.channel.ChannelPipeline; | ||
import org.jboss.netty.handler.codec.string.StringEncoder; | ||
import org.traccar.BaseProtocol; | ||
import org.traccar.PipelineBuilder; | ||
import org.traccar.TrackerServer; | ||
import org.traccar.model.Command; | ||
|
||
import io.netty.handler.codec.string.StringEncoder; | ||
|
||
import java.util.List; | ||
|
||
public class WatchProtocol extends BaseProtocol { | ||
|
@@ -47,9 +47,9 @@ public WatchProtocol() { | |
|
||
@Override | ||
public void initTrackerServers(List<TrackerServer> serverList) { | ||
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { | ||
serverList.add(new TrackerServer(false, getName()) { | ||
@Override | ||
protected void addSpecificHandlers(ChannelPipeline pipeline) { | ||
protected void addProtocolHandlers(PipelineBuilder pipeline) { | ||
pipeline.addLast("frameDecoder", new WatchFrameDecoder()); | ||
pipeline.addLast("stringEncoder", new StringEncoder()); | ||
pipeline.addLast("objectEncoder", new WatchProtocolEncoder()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2016 - 2017 Anton Tananaev ([email protected]) | ||
* Copyright 2016 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -15,7 +15,7 @@ | |
*/ | ||
package org.traccar.protocol; | ||
|
||
import org.jboss.netty.channel.Channel; | ||
import io.netty.channel.Channel; | ||
import org.traccar.StringProtocolEncoder; | ||
import org.traccar.helper.DataConverter; | ||
import org.traccar.helper.Log; | ||
|
@@ -47,7 +47,7 @@ protected String formatCommand(Channel channel, Command command, String format, | |
boolean hasIndex = false; | ||
String manufacturer = "CS"; | ||
if (channel != null) { | ||
WatchProtocolDecoder decoder = channel.getPipeline().get(WatchProtocolDecoder.class); | ||
WatchProtocolDecoder decoder = channel.pipeline().get(WatchProtocolDecoder.class); | ||
if (decoder != null) { | ||
hasIndex = decoder.getHasIndex(); | ||
manufacturer = decoder.getManufacturer(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2012 - 2016 Anton Tananaev ([email protected]) | ||
* Copyright 2012 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -15,31 +15,32 @@ | |
*/ | ||
package org.traccar.protocol; | ||
|
||
import org.jboss.netty.buffer.ChannelBuffer; | ||
import org.jboss.netty.channel.Channel; | ||
import org.jboss.netty.channel.ChannelHandlerContext; | ||
import org.jboss.netty.handler.codec.frame.FrameDecoder; | ||
import org.traccar.helper.StringFinder; | ||
import org.traccar.BaseFrameDecoder; | ||
import org.traccar.helper.BufferUtil; | ||
|
||
public class XexunFrameDecoder extends FrameDecoder { | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelHandlerContext; | ||
|
||
public class XexunFrameDecoder extends BaseFrameDecoder { | ||
|
||
@Override | ||
protected Object decode( | ||
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { | ||
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { | ||
|
||
if (buf.readableBytes() < 80) { | ||
return null; | ||
} | ||
|
||
int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC")); | ||
int beginIndex = BufferUtil.indexOf("GPRMC", buf); | ||
if (beginIndex == -1) { | ||
beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GNRMC")); | ||
beginIndex = BufferUtil.indexOf("GNRMC", buf); | ||
if (beginIndex == -1) { | ||
return null; | ||
} | ||
} | ||
|
||
int identifierIndex = buf.indexOf(beginIndex, buf.writerIndex(), new StringFinder("imei:")); | ||
int identifierIndex = BufferUtil.indexOf("imei:", buf, beginIndex, buf.writerIndex()); | ||
if (identifierIndex == -1) { | ||
return null; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2015 - 2016 Anton Tananaev ([email protected]) | ||
* Copyright 2015 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -15,16 +15,16 @@ | |
*/ | ||
package org.traccar.protocol; | ||
|
||
import org.jboss.netty.bootstrap.ServerBootstrap; | ||
import org.jboss.netty.channel.ChannelPipeline; | ||
import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder; | ||
import org.jboss.netty.handler.codec.string.StringDecoder; | ||
import org.jboss.netty.handler.codec.string.StringEncoder; | ||
import org.traccar.BaseProtocol; | ||
import org.traccar.Context; | ||
import org.traccar.PipelineBuilder; | ||
import org.traccar.TrackerServer; | ||
import org.traccar.model.Command; | ||
|
||
import io.netty.handler.codec.LineBasedFrameDecoder; | ||
import io.netty.handler.codec.string.StringDecoder; | ||
import io.netty.handler.codec.string.StringEncoder; | ||
|
||
import java.util.List; | ||
|
||
public class XexunProtocol extends BaseProtocol { | ||
|
@@ -38,9 +38,9 @@ public XexunProtocol() { | |
|
||
@Override | ||
public void initTrackerServers(List<TrackerServer> serverList) { | ||
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) { | ||
serverList.add(new TrackerServer(false, getName()) { | ||
@Override | ||
protected void addSpecificHandlers(ChannelPipeline pipeline) { | ||
protected void addProtocolHandlers(PipelineBuilder pipeline) { | ||
boolean full = Context.getConfig().getBoolean(getName() + ".extended"); | ||
if (full) { | ||
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); // tracker bug \n\r | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2012 - 2017 Anton Tananaev ([email protected]) | ||
* Copyright 2012 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -15,7 +15,7 @@ | |
*/ | ||
package org.traccar.protocol; | ||
|
||
import org.jboss.netty.channel.Channel; | ||
import io.netty.channel.Channel; | ||
import org.traccar.BaseProtocolDecoder; | ||
import org.traccar.DeviceSession; | ||
import org.traccar.helper.DateBuilder; | ||
|
Oops, something went wrong.