Skip to content

Commit

Permalink
Merge branch 'master' into netty4
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/org/traccar/protocol/AquilaProtocolDecoder.java
#	src/org/traccar/protocol/L100FrameDecoder.java
  • Loading branch information
tananaev committed Jun 12, 2018
2 parents 1dc1e06 + 86ad45c commit 69a4af1
Show file tree
Hide file tree
Showing 32 changed files with 1,159 additions and 39 deletions.
56 changes: 56 additions & 0 deletions schema/changelog-4.0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"
logicalFilePath="changelog-4.0">

<changeSet author="author" id="changelog-4.0-renaming">

<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="tc_servers" />
</not>
</preConditions>

<renameTable oldTableName="attributes" newTableName="tc_attributes" />
<renameTable oldTableName="calendars" newTableName="tc_calendars" />
<renameTable oldTableName="commands" newTableName="tc_commands" />
<renameTable oldTableName="device_attribute" newTableName="tc_device_attribute" />
<renameTable oldTableName="device_command" newTableName="tc_device_command" />
<renameTable oldTableName="device_driver" newTableName="tc_device_driver" />
<renameTable oldTableName="device_geofence" newTableName="tc_device_geofence" />
<renameTable oldTableName="device_maintenance" newTableName="tc_device_maintenance" />
<renameTable oldTableName="device_notification" newTableName="tc_device_notification" />
<renameTable oldTableName="devices" newTableName="tc_devices" />
<renameTable oldTableName="drivers" newTableName="tc_drivers" />
<renameTable oldTableName="events" newTableName="tc_events" />
<renameTable oldTableName="geofences" newTableName="tc_geofences" />
<renameTable oldTableName="group_attribute" newTableName="tc_group_attribute" />
<renameTable oldTableName="group_command" newTableName="tc_group_command" />
<renameTable oldTableName="group_driver" newTableName="tc_group_driver" />
<renameTable oldTableName="group_geofence" newTableName="tc_group_geofence" />
<renameTable oldTableName="group_maintenance" newTableName="tc_group_maintenance" />
<renameTable oldTableName="group_notification" newTableName="tc_group_notification" />
<renameTable oldTableName="groups" newTableName="tc_groups" />
<renameTable oldTableName="maintenances" newTableName="tc_maintenances" />
<renameTable oldTableName="notifications" newTableName="tc_notifications" />
<renameTable oldTableName="positions" newTableName="tc_positions" />
<renameTable oldTableName="servers" newTableName="tc_servers" />
<renameTable oldTableName="statistics" newTableName="tc_statistics" />
<renameTable oldTableName="user_attribute" newTableName="tc_user_attribute" />
<renameTable oldTableName="user_calendar" newTableName="tc_user_calendar" />
<renameTable oldTableName="user_command" newTableName="tc_user_command" />
<renameTable oldTableName="user_device" newTableName="tc_user_device" />
<renameTable oldTableName="user_driver" newTableName="tc_user_driver" />
<renameTable oldTableName="user_geofence" newTableName="tc_user_geofence" />
<renameTable oldTableName="user_group" newTableName="tc_user_group" />
<renameTable oldTableName="user_maintenance" newTableName="tc_user_maintenance" />
<renameTable oldTableName="user_notification" newTableName="tc_user_notification" />
<renameTable oldTableName="user_user" newTableName="tc_user_user" />
<renameTable oldTableName="users" newTableName="tc_users" />

</changeSet>

</databaseChangeLog>
1 change: 1 addition & 0 deletions schema/changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
<include file="changelog-3.15.xml" relativeToChangelogFile="true" />
<include file="changelog-3.16.xml" relativeToChangelogFile="true" />
<include file="changelog-3.17.xml" relativeToChangelogFile="true" />
<include file="changelog-4.0.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
22 changes: 13 additions & 9 deletions setup/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<entry key='logger.file'>./logs/tracker-server.log</entry>

<entry key='filter.enable'>true</entry>
<entry key='filter.future'>3600</entry>
<entry key='filter.future'>86400</entry>

<entry key='event.enable'>true</entry>
<entry key='event.ignoreDuplicateAlerts'>true</entry>
Expand All @@ -41,36 +41,36 @@
<entry key='database.changelog'>./schema/changelog-master.xml</entry>

<entry key='database.loginUser'>
SELECT * FROM users
SELECT * FROM tc_users
WHERE email = :email OR login = :email
</entry>

<entry key='database.selectPositions'>
SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime
SELECT * FROM tc_positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime
</entry>

<entry key='database.selectLatestPositions'>
SELECT positions.* FROM positions INNER JOIN devices ON positions.id = devices.positionid;
SELECT tc_positions.* FROM tc_positions INNER JOIN tc_devices ON tc_positions.id = tc_devices.positionid;
</entry>

<entry key='database.updateLatestPosition'>
UPDATE devices SET positionId = :id WHERE id = :deviceId
UPDATE tc_devices SET positionId = :id WHERE id = :deviceId
</entry>

<entry key='database.selectEvents'>
SELECT * FROM events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime
SELECT * FROM tc_events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime
</entry>

<entry key='database.deletePositions'>
DELETE FROM positions WHERE serverTime &lt; :serverTime AND id NOT IN (SELECT positionId FROM devices WHERE positionId IS NOT NULL)
DELETE FROM tc_positions WHERE serverTime &lt; :serverTime AND id NOT IN (SELECT positionId FROM tc_devices WHERE positionId IS NOT NULL)
</entry>

<entry key='database.deleteEvents'>
DELETE FROM events WHERE serverTime &lt; :serverTime
DELETE FROM tc_events WHERE serverTime &lt; :serverTime
</entry>

<entry key='database.selectStatistics'>
SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime
SELECT * FROM tc_statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime
</entry>

<!-- PROTOCOL CONFIG -->
Expand Down Expand Up @@ -242,5 +242,9 @@
<entry key='pt60.port'>5164</entry>
<entry key='telemax.port'>5165</entry>
<entry key='sabertek.port'>5166</entry>
<entry key='retranslator.port'>5167</entry>
<entry key='svias.port'>5168</entry>
<entry key='eseal.port'>5169</entry>
<entry key='freematics.port'>5170</entry>

</properties>
1 change: 1 addition & 0 deletions src/org/traccar/WebDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public String formatRequest(Position position) {
.replace("{altitude}", String.valueOf(position.getAltitude()))
.replace("{speed}", String.valueOf(position.getSpeed()))
.replace("{course}", String.valueOf(position.getCourse()))
.replace("{accuracy}", String.valueOf(position.getAccuracy()))
.replace("{statusCode}", calculateStatus(position));

if (position.getAddress() != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/org/traccar/database/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,12 @@ private static String getPermissionsTableName(Class<?> owner, Class<?> property)
if (propertyName.equals("ManagedUser")) {
propertyName = "User";
}
return Introspector.decapitalize(owner.getSimpleName()) + "_" + Introspector.decapitalize(propertyName);
return "tc_" + Introspector.decapitalize(owner.getSimpleName())
+ "_" + Introspector.decapitalize(propertyName);
}

private static String getObjectsTableName(Class<?> clazz) {
String result = Introspector.decapitalize(clazz.getSimpleName());
String result = "tc_" + Introspector.decapitalize(clazz.getSimpleName());
// Add "s" ending if object name is not plural already
if (!result.endsWith("s")) {
result += "s";
Expand Down
2 changes: 2 additions & 0 deletions src/org/traccar/model/Position.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public class Position extends Message {
public static final String ALARM_POWER_OFF = "powerOff";
public static final String ALARM_POWER_ON = "powerOn";
public static final String ALARM_DOOR = "door";
public static final String ALARM_LOCK = "lock";
public static final String ALARM_UNLOCK = "unlock";
public static final String ALARM_GEOFENCE = "geofence";
public static final String ALARM_GEOFENCE_ENTER = "geofenceEnter";
public static final String ALARM_GEOFENCE_EXIT = "geofenceExit";
Expand Down
2 changes: 1 addition & 1 deletion src/org/traccar/protocol/AquilaProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private Position decodeB(Channel channel, SocketAddress remoteAddress, String se
position.set(Position.KEY_ALARM, Position.ALARM_SOS);
if (channel != null) {
String password = Context.getIdentityManager().lookupAttributeString(
position.getDeviceId(), getProtocolName() + ".language", "aquila123", true);
position.getDeviceId(), getProtocolName() + ".password", "aquila123", true);
channel.writeAndFlush(new NetworkMessage(
"#set$" + id + "@" + password + "#EMR_MODE:0*", remoteAddress));
}
Expand Down
53 changes: 53 additions & 0 deletions src/org/traccar/protocol/EsealProtocol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 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.
* 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 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.TrackerServer;
import org.traccar.model.Command;

import java.util.List;

public class EsealProtocol extends BaseProtocol {

public EsealProtocol() {
super("eseal");
setSupportedDataCommands(
Command.TYPE_CUSTOM,
Command.TYPE_ALARM_ARM,
Command.TYPE_ALARM_DISARM);
}

@Override
public void initTrackerServers(List<TrackerServer> serverList) {
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("objectEncoder", new EsealProtocolEncoder());
pipeline.addLast("objectDecoder", new EsealProtocolDecoder(EsealProtocol.this));
}
});
}

}
155 changes: 155 additions & 0 deletions src/org/traccar/protocol/EsealProtocolDecoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright 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.
* 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 org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;

import java.net.SocketAddress;
import java.util.regex.Pattern;

public class EsealProtocolDecoder extends BaseProtocolDecoder {

private String config;

public EsealProtocolDecoder(EsealProtocol protocol) {
super(protocol);
config = Context.getConfig().getString(getProtocolName() + ".config");
}

private static final Pattern PATTERN = new PatternBuilder()
.text("##S,")
.expression("[^,]+,") // device type
.number("(d+),") // device id
.number("d+,") // customer id
.expression("[^,]+,") // firmware version
.expression("([^,]+),") // type
.number("(d+),") // index
.number("(dddd)-(dd)-(dd),") // date
.number("(dd):(dd):(dd),") // time
.number("d+,") // interval
.expression("([AV]),") // validity
.number("(d+.d+)([NS]) ") // latitude
.number("(d+.d+)([EW]),") // longitude
.number("(d+),") // course
.number("(d+),") // speed
.expression("([^,]+),") // door
.number("(d+.d+),") // acceleration
.expression("([^,]+),") // nfc
.number("(d+.d+),") // battery
.number("(-?d+),") // rssi
.text("E##")
.compile();

private void sendResponse(Channel channel, String prefix, String type, String payload) {
if (channel != null) {
channel.write(prefix + type + "," + payload + ",E##\r\n");
}
}

private String decodeAlarm(String type) {
switch (type) {
case "Event-Door":
return Position.ALARM_DOOR;
case "Event-Shock":
return Position.ALARM_SHOCK;
case "Event-Drop":
return Position.ALARM_FALL_DOWN;
case "Event-Lock":
return Position.ALARM_LOCK;
case "Event-RC-Unlock":
return Position.ALARM_UNLOCK;
default:
return null;
}
}

@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

String sentence = (String) msg;
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}

DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}

Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());

String type = parser.next();
String prefix = sentence.substring(0, sentence.indexOf(type));
int index = parser.nextInt();

position.set(Position.KEY_INDEX, index);
position.set(Position.KEY_ALARM, decodeAlarm(type));

switch (type) {
case "Startup":
sendResponse(channel, prefix, type + " ACK", index + "," + config);
break;
case "Normal":
case "Button-Normal":
case "Termination":
case "Event-Door":
case "Event-Shock":
case "Event-Drop":
case "Event-Lock":
case "Event-RC-Unlock":
sendResponse(channel, prefix, type + " ACK", String.valueOf(index));
break;
default:
break;
}

position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setCourse(parser.nextInt());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));

switch (parser.next()) {
case "Open":
position.set(Position.KEY_DOOR, true);
break;
case "Close":
position.set(Position.KEY_DOOR, false);
break;
default:
break;
}

position.set(Position.KEY_ACCELERATION, parser.nextDouble());
position.set("nfc", parser.next());
position.set(Position.KEY_BATTERY, parser.nextDouble());
position.set(Position.KEY_RSSI, parser.nextInt());

return position;
}

}
Loading

0 comments on commit 69a4af1

Please sign in to comment.