Good afternoon everyone! I'm trying to create a new protocol in my traccar 3.6, I've already registered port 6822 in my traccar.xml. I'm building the protocol with the help of research but it's still giving me an unknown device. Could someone validate where I'm going wrong? I'll send my daycomProtocol and my DaycomProtocolDevice.
//DaycomProtocol.java
package org.traccar.protocol;
import org.traccar.BaseProtocol;
import org.traccar.PipelineBuilder;
import org.traccar.TrackerServer;
import org.traccar.config.Config;
import jakarta.inject.Inject;
public class DaycomProtocol extends BaseProtocol {
@Inject
public DaycomProtocol(Config config) {
addServer(new TrackerServer(config, getName(), false) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline, Config config) {
pipeline.addLast(new DaycomFrameDecoder());
pipeline.addLast(new DaycomProtocolDecoder(DaycomProtocol.this));
}
});
}
}
//DaycomProtocol.java
//DaycomProtocolDecoder.java
package org.traccar.protocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.model.Position;
import org.traccar.session.DeviceSession;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Date;
public class DaycomProtocolDecoder extends BaseProtocolDecoder {
public DaycomProtocolDecoder(DaycomProtocol protocol) {
super(protocol);
}
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) {
ByteBuf buf = (ByteBuf) msg;
System.out.println("[Daycom] Pacote recebido. Tamanho: " + buf.readableBytes());
if (buf.readableBytes() < 24) {
System.out.println("[Daycom] Pacote muito pequeno. Ignorado.");
return null;
}
// Tentando extrair IMEI
String imei;
try {
byte[] imeiBytes = new byte[15];
buf.readBytes(imeiBytes);
imei = new String(imeiBytes, StandardCharsets.US_ASCII).trim();
System.out.println("[Daycom] IMEI Extraído: " + imei);
} catch (Exception e) {
System.out.println("[Daycom] Erro ao extrair IMEI: " + e.getMessage());
return null;
}
// Verificando se o dispositivo está cadastrado
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
System.out.println("[Daycom] Dispositivo desconhecido: " + imei);
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
try {
// Extraindo latitude e longitude
float latitude = buf.readFloat();
float longitude = buf.readFloat();
position.setLatitude(latitude);
position.setLongitude(longitude);
System.out.println("[Daycom] Latitude = " + latitude + ", Longitude = " + longitude);
// Extraindo velocidade
float speed = buf.readFloat();
position.setSpeed(speed);
System.out.println("[Daycom] Velocidade = " + speed + " km/h");
// Configurar data/hora do servidor
position.setFixTime(new Date());
position.setValid(true);
System.out.println("[Daycom] Posição processada com sucesso.");
return position;
} catch (Exception e) {
System.out.println("[Daycom] Erro ao processar pacote: " + e.getMessage());
return null;
}
}
}
//DaycomProtocolDecoder.java
Please don't duplicate your questions.
Good afternoon everyone! I'm trying to create a new protocol in my traccar 3.6, I've already registered port 6822 in my traccar.xml. I'm building the protocol with the help of research but it's still giving me an unknown device. Could someone validate where I'm going wrong? I'll send my daycomProtocol and my DaycomProtocolDevice.