From d8552cb2975ec8a78ed07e0ec0f1ba1c7d34086a Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 15 Mar 2016 22:16:47 +1300 Subject: Implement send SMS Meitrack command --- src/org/traccar/model/Command.java | 7 +++++-- src/org/traccar/protocol/MeitrackProtocol.java | 3 ++- src/org/traccar/protocol/MeitrackProtocolEncoder.java | 7 +++++++ 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index dd541e643..eda5f61d1 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class Command extends Extensible { + public static final String TYPE_CUSTOM = "custom"; public static final String TYPE_POSITION_SINGLE = "positionSingle"; public static final String TYPE_POSITION_PERIODIC = "positionPeriodic"; public static final String TYPE_POSITION_STOP = "positionStop"; @@ -31,12 +32,14 @@ public class Command extends Extensible { public static final String TYPE_REQUEST_PHOTO = "requestPhoto"; public static final String TYPE_REBOOT_DEVICE = "rebootDevice"; public static final String TYPE_MOVEMENT_ALARM = "movementAlarm"; + public static final String TYPE_SEND_SMS = "sendSms"; public static final String KEY_UNIQUE_ID = "uniqueId"; public static final String KEY_FREQUENCY = "frequency"; public static final String KEY_TIMEZONE = "timezone"; public static final String KEY_DEVICE_PASSWORD = "devicePassword"; public static final String KEY_RADIUS = "radius"; + public static final String KEY_PHONE_NUMBER = "phoneNumber"; + public static final String KEY_MESSAGE = "message"; - public static final String TYPE_CUSTOM = "CUSTOM"; } diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java index e5b5ddf2b..a004d5cb6 100644 --- a/src/org/traccar/protocol/MeitrackProtocol.java +++ b/src/org/traccar/protocol/MeitrackProtocol.java @@ -36,7 +36,8 @@ public class MeitrackProtocol extends BaseProtocol { Command.TYPE_ENGINE_RESUME, Command.TYPE_ALARM_ARM, Command.TYPE_ALARM_DISARM, - Command.TYPE_REQUEST_PHOTO); + Command.TYPE_REQUEST_PHOTO, + Command.TYPE_SEND_SMS); } @Override diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java index 381935c58..04cb39637 100644 --- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java @@ -20,6 +20,8 @@ import org.traccar.helper.Checksum; import org.traccar.helper.Log; import org.traccar.model.Command; +import java.util.Map; + public class MeitrackProtocolEncoder extends StringProtocolEncoder { private Object formatCommand(Command command, char dataId, String content) { @@ -33,6 +35,8 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { @Override protected Object encodeCommand(Command command) { + Map attributes = command.getAttributes(); + switch (command.getType()) { case Command.TYPE_POSITION_SINGLE: return formatCommand(command, 'Q', "A10"); @@ -46,6 +50,9 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder { return formatCommand(command, 'M', "C01,0,22022"); case Command.TYPE_REQUEST_PHOTO: return formatCommand(command, 'D', "D03,1,camera_picture.jpg"); + case Command.TYPE_SEND_SMS: + return formatCommand(command, 'f', "C02,0," + + attributes.get(Command.KEY_PHONE_NUMBER) + "," + attributes.get(Command.KEY_MESSAGE)); default: Log.warning(new UnsupportedOperationException(command.getType())); break; -- cgit v1.2.3