Doesn't look like those messages are supported.
The command sent to the device is a custom command, so it is supported, the command reaches the device and the device reply to the server, the problem is that the server is unable to decode the reply, the hex of the reply is correct. if i convert the hex to ascii is
Hex
24475052533d312c22696e7465726e65742e636f6d63656c2e636f6d2e636f222c22222c22222c223230392e3132362e38372e313133222c353034342c302c332c33302c31302c302c22302e302e302e30222c35343038382c300d0a
Ascii
$GPRS=1,"internet.comcel.com.co","","","209.126.87.113",5044,0,3,30,10,0,"0.0.0.0",54088,0
that should be in the message key of the attributes of the position.
I know that it worked before because i use it in production in version 4.5 and it worked, now i am trying to migrate to version 5.9 but it is no working
Have you tried any other versions?
Hi.
Yes, but i always need to modify the source code for atrack devices to work properly, i would appreciate if you can help me to check the source code i propose and if check if you can include it, or at least take a look and check it.
For example for class AtrackFrameDecoder.java i do this
Note that i need to check for the header $ that is the command response.
I did this modification in traccar 4.4 source code version.
This code only support binary message and not ascii, because some binary messages includes "," character and is imposible to check if the protocol is ascii or binary only with the presence of that character.
///*
// * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
// *
// * 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.protocol;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.BaseFrameDecoder;
import org.traccar.BaseProtocolDecoder;
import org.traccar.helper.BufferUtil;
import org.traccar.helper.DataConverter;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
public class AtrackFrameDecoder extends BaseFrameDecoder {
private static final int KEEPALIVE_LENGTH = 12;
private static final Logger LOGGER = LoggerFactory.getLogger(AtrackFrameDecoder.class);
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
if (buf.readableBytes() >= 2) {
if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
if (buf.readableBytes() >= KEEPALIVE_LENGTH) {
return buf.readRetainedSlice(KEEPALIVE_LENGTH);
}
}
// Prefix @P || @R
int pref = buf.getUnsignedShort(buf.readerIndex());
if (pref == 0x4050 || pref == 0x4052) {
// byte ascii = buf.getByte(buf.readerIndex() + 2);
// Binary data
// if (ascii != ',') {
if (buf.readableBytes() > 6) {
int length = buf.getUnsignedShort(buf.readerIndex() + 4) + 4 + 2;
if (buf.readableBytes() >= length) {
return buf.readRetainedSlice(length);
}
}
// }
// Ascii data
// else if (ascii == ',') {
// String orig = buf.toString(0, buf.readableBytes(),
// Charset.defaultCharset());
// LOGGER.warn(DataConverter.printHex(((String)
// orig).getBytes(StandardCharsets.US_ASCII)));
// LOGGER.warn(orig);
// int lengthStart = buf.indexOf(buf.readerIndex() + 3,
// buf.writerIndex(), (byte) ',') + 1;
// if (lengthStart > 0) {
// int lengthEnd = buf.indexOf(lengthStart, buf.writerIndex(),
// (byte) ',');
// if (lengthEnd > 0) {
// int length = lengthEnd + Integer.parseInt(
// buf.toString(lengthStart, lengthEnd - lengthStart,
// StandardCharsets.US_ASCII));
// if (buf.readableBytes() > length &&
// buf.getByte(buf.readerIndex() + length) == '\n') {
// length += 1;
// }
// if (buf.readableBytes() >= length) {
// return buf.readRetainedSlice(length);
// }
// }
// } else {
// int endIndex = BufferUtil.indexOf("\r\n", buf);
// if (endIndex > 0) {
// return buf.readRetainedSlice(endIndex - buf.readerIndex() +
// 2);
// }
// }
// }
} else if (buf.toString(0, 1, Charset.defaultCharset()).equals("$")) {
return buf.readBytes(buf.readableBytes());
}
}
return null;
// if (buf.readableBytes() >= 2) {
//
// if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
//
// if (buf.readableBytes() >= KEEPALIVE_LENGTH) {
// return buf.readBytes(KEEPALIVE_LENGTH);
// }
//
// } else if (buf.toString(0, 1, Charset.defaultCharset()).equals("$"))
// {
// return buf.readBytes(buf.readableBytes());
// }
// //
// else {
// return buf.readBytes(buf.readableBytes());
// }
//
// // else if (buf.getUnsignedShort(buf.readerIndex()) == 0x4050 &&
// // buf.getByte(buf.readerIndex() + 2) != ',') {
// //
// // if (buf.readableBytes() > 6) {
// // int length = buf.getUnsignedShort(buf.readerIndex() + 4) + 4 + 2;
// // if (buf.readableBytes() >= length) {
// // return buf.readRetainedSlice(length);
// // }
// // }
// //
// // } else {
// // int lengthStart = buf.indexOf(buf.readerIndex() + 3,
// // buf.writerIndex(), (byte) ',') + 1;
// // if (lengthStart > 0) {
// // int lengthEnd = buf.indexOf(lengthStart, buf.writerIndex(),
// // (byte) ',');
// // if (lengthEnd > 0) {
// // String s = buf.toString(lengthStart, lengthEnd - lengthStart,
// // StandardCharsets.US_ASCII);
// // System.out.println(s + " ******************");
// // int length = lengthEnd + Integer.parseInt(s);
// // if (buf.readableBytes() > length && buf.getByte(buf.readerIndex()
// // + length) == '\n') {
// // length += 1;
// // }
// // if (buf.readableBytes() >= length) {
// // return buf.readRetainedSlice(length);
// // }
// // }
// // } else {
// // int endIndex = BufferUtil.indexOf("\r\n", buf);
// // if (endIndex > 0) {
// // return buf.readRetainedSlice(endIndex - buf.readerIndex() + 2);
// // }
// // }
// //
// // }
// //
// }
//
// return null;
}
}
I would like to be able to upgrade traccar without source code modifications. I´ve using atrack devices for more than 8 years always using traccar, but i need to modify the source code if i want to upgrade.
I also modified the AtrackProtocolEncoder to support basic commands like TYPE_ENGINE_RESUME, TYPE_ENGINE_STOP, TYPE_REBOOT_DEVICE, TYPE_POSITION_SINGLE.
/*
* Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* 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.protocol;
import io.netty.buffer.Unpooled;
import org.traccar.BaseProtocolEncoder;
import org.traccar.model.Command;
import java.nio.charset.StandardCharsets;
public class AtrackProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
return Unpooled.copiedBuffer(command.getString(Command.KEY_DATA) + "\r\n", StandardCharsets.US_ASCII);
case Command.TYPE_ENGINE_STOP:
return Unpooled.copiedBuffer("AT$OUTC=2,0,1,0,30\r\n", StandardCharsets.US_ASCII);
case Command.TYPE_ENGINE_RESUME:
return Unpooled.copiedBuffer("AT$OUTC=2,1,1,0,30\r\n", StandardCharsets.US_ASCII);
case Command.TYPE_REBOOT_DEVICE:
return Unpooled.copiedBuffer("AT$REST=0\r\n", StandardCharsets.US_ASCII);
case Command.TYPE_POSITION_SINGLE:
return Unpooled.copiedBuffer("AT$GPOS=0\r\n", StandardCharsets.US_ASCII);
default:
return null;
}
}
}
I have made some simple modification to the file AtrackProtocolDecoder.java too trying to solve the problem with the ascii format, because some binary messages are decoded as ascii, this problem makes that the source code you have is not 100% reliable for binary format.
Yes, but i always need to modify the source code for atrack devices to work properly
Just wow. And you didn't mention this critical detail before?
Yes i think i mentioned something related here
Can you help me please, the command response always gives an error with Atrack protocol, no matter which command i send to the device, the device answer but it gives error, and the device gets disconnected.