From 9280355123ee13f7f7d8bf7076a39dcab57ab1cd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 2 Nov 2022 17:57:22 -0700 Subject: Improve attribute type handling --- .../java/org/traccar/protocol/KhdProtocolEncoder.java | 2 +- .../org/traccar/protocol/MeiligaoProtocolEncoder.java | 6 +++--- .../org/traccar/protocol/RuptelaProtocolEncoder.java | 4 ++-- .../org/traccar/protocol/SuntechProtocolEncoder.java | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/main/java/org/traccar/protocol') diff --git a/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java b/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java index 8aeb9660d..12353b415 100644 --- a/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/KhdProtocolEncoder.java @@ -84,7 +84,7 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder { return encodeCommand(MSG_FACTORY_RESET, uniqueId, null); case Command.TYPE_SET_SPEED_LIMIT: ByteBuf content = Unpooled.buffer(); - content.writeByte(Integer.parseInt(command.getString(Command.KEY_DATA))); + content.writeByte(command.getInteger(Command.KEY_DATA)); return encodeCommand(MSG_RESUME_OIL, uniqueId, content); case Command.TYPE_SET_ODOMETER: return encodeCommand(MSG_DELETE_MILEAGE, uniqueId, null); diff --git a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java index 03f0e7ecf..5859d91ce 100644 --- a/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/MeiligaoProtocolEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2022 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. @@ -99,8 +99,8 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder { content.writeShort(command.getInteger(Command.KEY_FREQUENCY) / 10); return encodeContent(command.getDeviceId(), MeiligaoProtocolDecoder.MSG_TRACK_BY_INTERVAL, content); case Command.TYPE_OUTPUT_CONTROL: - int index = Integer.parseInt(command.getString(Command.KEY_INDEX)) - 1; - int value = Integer.parseInt(command.getString(Command.KEY_DATA)); + int index = command.getInteger(Command.KEY_INDEX) - 1; + int value = command.getInteger(Command.KEY_DATA); return encodeOutputCommand(command.getDeviceId(), index, value); case Command.TYPE_ENGINE_STOP: return encodeOutputCommand(command.getDeviceId(), 1, 1); diff --git a/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java index 442961b19..5ec971a98 100644 --- a/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/RuptelaProtocolEncoder.java @@ -80,14 +80,14 @@ public class RuptelaProtocolEncoder extends BaseProtocolEncoder { return encodeContent(RuptelaProtocolDecoder.MSG_FIRMWARE_UPDATE, content); case Command.TYPE_OUTPUT_CONTROL: content.writeInt(command.getInteger(Command.KEY_INDEX)); - content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA))); + content.writeInt(command.getInteger(Command.KEY_DATA)); return encodeContent(RuptelaProtocolDecoder.MSG_SET_IO, content); case Command.TYPE_SET_CONNECTION: String c = command.getString(Command.KEY_SERVER) + "," + command.getInteger(Command.KEY_PORT) + ",TCP"; content.writeBytes(c.getBytes(StandardCharsets.US_ASCII)); return encodeContent(RuptelaProtocolDecoder.MSG_SET_CONNECTION, content); case Command.TYPE_SET_ODOMETER: - content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA))); + content.writeInt(command.getInteger(Command.KEY_DATA)); return encodeContent(RuptelaProtocolDecoder.MSG_SET_ODOMETER, content); default: return null; diff --git a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java index 53308f968..b298adc5a 100644 --- a/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java +++ b/src/main/java/org/traccar/protocol/SuntechProtocolEncoder.java @@ -59,23 +59,23 @@ public class SuntechProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, "CMD;%s;03;01\r", Command.KEY_UNIQUE_ID); case Command.TYPE_OUTPUT_CONTROL: if (command.getAttributes().get(Command.KEY_DATA).equals("1")) { - switch (command.getString(Command.KEY_INDEX)) { - case "1": + switch (command.getInteger(Command.KEY_INDEX)) { + case 1: return formatCommand(command, "CMD;%s;04;01\r", Command.KEY_UNIQUE_ID); - case "2": + case 2: return formatCommand(command, "CMD;%s;04;03\r", Command.KEY_UNIQUE_ID); - case "3": + case 3: return formatCommand(command, "CMD;%s;04;09\r", Command.KEY_UNIQUE_ID); default: return null; } } else { - switch (command.getString(Command.KEY_INDEX)) { - case "1": + switch (command.getInteger(Command.KEY_INDEX)) { + case 1: return formatCommand(command, "CMD;%s;04;02\r", Command.KEY_UNIQUE_ID); - case "2": + case 2: return formatCommand(command, "CMD;%s;04;04\r", Command.KEY_UNIQUE_ID); - case "3": + case 3: return formatCommand(command, "CMD;%s;04;10\r", Command.KEY_UNIQUE_ID); default: return null; -- cgit v1.2.3