aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BaseDataHandler.java2
-rw-r--r--src/org/traccar/BaseEventHandler.java2
-rw-r--r--src/org/traccar/BasePipelineFactory.java13
-rw-r--r--src/org/traccar/BaseProtocol.java2
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java36
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java2
-rw-r--r--src/org/traccar/CharacterDelimiterFrameDecoder.java2
-rw-r--r--src/org/traccar/Config.java55
-rw-r--r--src/org/traccar/Context.java27
-rw-r--r--src/org/traccar/CoordinatesHandler.java14
-rw-r--r--src/org/traccar/CopyAttributesHandler.java45
-rw-r--r--src/org/traccar/DefaultDataHandler.java2
-rw-r--r--src/org/traccar/DeviceSession.java2
-rw-r--r--src/org/traccar/DistanceHandler.java2
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java2
-rw-r--r--src/org/traccar/FilterHandler.java111
-rw-r--r--src/org/traccar/GlobalChannelFactory.java2
-rw-r--r--src/org/traccar/GlobalTimer.java2
-rw-r--r--src/org/traccar/HemisphereHandler.java2
-rw-r--r--src/org/traccar/LocationProviderHandler.java2
-rw-r--r--src/org/traccar/Main.java2
-rw-r--r--src/org/traccar/MainEventHandler.java3
-rw-r--r--src/org/traccar/RemoteAddressHandler.java2
-rw-r--r--src/org/traccar/ReverseGeocoderHandler.java2
-rw-r--r--src/org/traccar/ServerManager.java2
-rw-r--r--src/org/traccar/StringProtocolEncoder.java2
-rw-r--r--src/org/traccar/TrackerServer.java2
-rw-r--r--src/org/traccar/WebDataHandler.java21
-rw-r--r--src/org/traccar/api/AsyncSocket.java2
-rw-r--r--src/org/traccar/api/AsyncSocketServlet.java2
-rw-r--r--src/org/traccar/api/BaseResource.java2
-rw-r--r--src/org/traccar/api/CorsResponseFilter.java2
-rw-r--r--src/org/traccar/api/ObjectMapperProvider.java2
-rw-r--r--src/org/traccar/api/ResourceErrorHandler.java22
-rw-r--r--src/org/traccar/api/SecurityRequestFilter.java40
-rw-r--r--src/org/traccar/api/UserPrincipal.java2
-rw-r--r--src/org/traccar/api/UserSecurityContext.java2
-rw-r--r--src/org/traccar/api/resource/AttributeAliasResource.java90
-rw-r--r--src/org/traccar/api/resource/CommandResource.java2
-rw-r--r--src/org/traccar/api/resource/DeviceGeofenceResource.java2
-rw-r--r--src/org/traccar/api/resource/DevicePermissionResource.java2
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java23
-rw-r--r--src/org/traccar/api/resource/EventResource.java13
-rw-r--r--src/org/traccar/api/resource/GeofencePermissionResource.java2
-rw-r--r--src/org/traccar/api/resource/GeofenceResource.java14
-rw-r--r--src/org/traccar/api/resource/GroupGeofenceResource.java2
-rw-r--r--src/org/traccar/api/resource/GroupPermissionResource.java2
-rw-r--r--src/org/traccar/api/resource/GroupResource.java6
-rw-r--r--src/org/traccar/api/resource/NotificationResource.java3
-rw-r--r--src/org/traccar/api/resource/PositionResource.java45
-rw-r--r--src/org/traccar/api/resource/ReportResource.java101
-rw-r--r--src/org/traccar/api/resource/ServerResource.java2
-rw-r--r--src/org/traccar/api/resource/SessionResource.java14
-rw-r--r--src/org/traccar/api/resource/StatisticsResource.java44
-rw-r--r--src/org/traccar/api/resource/UserResource.java13
-rw-r--r--src/org/traccar/database/ActiveDevice.java2
-rw-r--r--src/org/traccar/database/AliasesManager.java113
-rw-r--r--src/org/traccar/database/ConnectionManager.java22
-rw-r--r--src/org/traccar/database/DataManager.java64
-rw-r--r--src/org/traccar/database/DeviceManager.java14
-rw-r--r--src/org/traccar/database/GeofenceManager.java2
-rw-r--r--src/org/traccar/database/GroupTree.java2
-rw-r--r--src/org/traccar/database/IdentityManager.java2
-rw-r--r--src/org/traccar/database/NotificationManager.java7
-rw-r--r--src/org/traccar/database/PermissionsManager.java66
-rw-r--r--src/org/traccar/database/QueryBuilder.java2
-rw-r--r--src/org/traccar/database/StatisticsManager.java88
-rw-r--r--src/org/traccar/events/AlertEventHandler.java2
-rw-r--r--src/org/traccar/events/CommandResultEventHandler.java2
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java2
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java4
-rw-r--r--src/org/traccar/events/MotionEventHandler.java2
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java2
-rw-r--r--src/org/traccar/geocode/Address.java2
-rw-r--r--src/org/traccar/geocode/AddressFormat.java2
-rw-r--r--src/org/traccar/geocode/GeocodeFarmReverseGeocoder.java2
-rw-r--r--src/org/traccar/geocode/GisgraphyReverseGeocoder.java2
-rw-r--r--src/org/traccar/geocode/GoogleReverseGeocoder.java2
-rw-r--r--src/org/traccar/geocode/JsonReverseGeocoder.java2
-rw-r--r--src/org/traccar/geocode/NominatimReverseGeocoder.java2
-rw-r--r--src/org/traccar/geocode/OpenCageReverseGeocoder.java2
-rw-r--r--src/org/traccar/geocode/ReverseGeocoder.java2
-rw-r--r--src/org/traccar/geofence/GeofenceCircle.java2
-rw-r--r--src/org/traccar/geofence/GeofenceGeometry.java2
-rw-r--r--src/org/traccar/geofence/GeofencePolygon.java2
-rw-r--r--src/org/traccar/helper/BcdUtil.java2
-rw-r--r--src/org/traccar/helper/BitUtil.java2
-rw-r--r--src/org/traccar/helper/Checksum.java15
-rw-r--r--src/org/traccar/helper/DateBuilder.java7
-rw-r--r--src/org/traccar/helper/DateUtil.java11
-rw-r--r--src/org/traccar/helper/DistanceCalculator.java2
-rw-r--r--src/org/traccar/helper/Hashing.java2
-rw-r--r--src/org/traccar/helper/LocationTree.java2
-rw-r--r--src/org/traccar/helper/Log.java8
-rw-r--r--src/org/traccar/helper/ObdDecoder.java6
-rw-r--r--src/org/traccar/helper/Parser.java4
-rw-r--r--src/org/traccar/helper/PatternBuilder.java2
-rw-r--r--src/org/traccar/helper/PatternUtil.java14
-rw-r--r--src/org/traccar/helper/StringFinder.java2
-rw-r--r--src/org/traccar/helper/UnitsConverter.java6
-rw-r--r--src/org/traccar/location/BaseLocationProvider.java2
-rw-r--r--src/org/traccar/location/CellInfo.java136
-rw-r--r--src/org/traccar/location/LocationProvider.java2
-rw-r--r--src/org/traccar/location/MozillaLocationProvider.java2
-rw-r--r--src/org/traccar/location/OpenCellIdLocationProvider.java2
-rw-r--r--src/org/traccar/model/AttributeAlias.java61
-rw-r--r--src/org/traccar/model/Command.java2
-rw-r--r--src/org/traccar/model/Device.java42
-rw-r--r--src/org/traccar/model/DeviceGeofence.java2
-rw-r--r--src/org/traccar/model/DevicePermission.java2
-rw-r--r--src/org/traccar/model/DeviceTotalDistance.java41
-rw-r--r--src/org/traccar/model/Event.java5
-rw-r--r--src/org/traccar/model/Extensible.java2
-rw-r--r--src/org/traccar/model/Geofence.java2
-rw-r--r--src/org/traccar/model/GeofencePermission.java2
-rw-r--r--src/org/traccar/model/Group.java2
-rw-r--r--src/org/traccar/model/GroupGeofence.java2
-rw-r--r--src/org/traccar/model/GroupPermission.java2
-rw-r--r--src/org/traccar/model/Message.java2
-rw-r--r--src/org/traccar/model/MiscFormatter.java2
-rw-r--r--src/org/traccar/model/Notification.java2
-rw-r--r--src/org/traccar/model/Position.java8
-rw-r--r--src/org/traccar/model/Server.java31
-rw-r--r--src/org/traccar/model/Statistics.java90
-rw-r--r--src/org/traccar/model/User.java72
-rw-r--r--src/org/traccar/notification/EventForwarder.java4
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java2
-rw-r--r--src/org/traccar/notification/NotificationMail.java143
-rw-r--r--src/org/traccar/notification/PropertiesProvider.java51
-rw-r--r--src/org/traccar/protocol/AdmProtocol.java2
-rw-r--r--src/org/traccar/protocol/AdmProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ApelProtocol.java2
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AplicomFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/AplicomProtocol.java2
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java155
-rwxr-xr-xsrc/org/traccar/protocol/AppelloProtocol.java2
-rwxr-xr-xsrc/org/traccar/protocol/AppelloProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AquilaProtocol.java2
-rw-r--r--src/org/traccar/protocol/AquilaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Ardi01Protocol.java4
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ArknavProtocol.java2
-rw-r--r--src/org/traccar/protocol/ArknavProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ArknavX8Protocol.java2
-rw-r--r--src/org/traccar/protocol/ArknavX8ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ArnaviProtocol.java2
-rw-r--r--src/org/traccar/protocol/ArnaviProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AstraProtocol.java2
-rw-r--r--src/org/traccar/protocol/AstraProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/AtrackFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/AtrackProtocol.java2
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AuroProtocol.java2
-rw-r--r--src/org/traccar/protocol/AuroProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AutoFonFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/AutoFonProtocol.java2
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/AutoGradeProtocol.java2
-rw-r--r--src/org/traccar/protocol/AutoGradeProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/Avl301Protocol.java2
-rw-r--r--src/org/traccar/protocol/Avl301ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/BceFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/BceProtocol.java2
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocol.java2
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/BoxProtocol.java2
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CalAmpProtocol.java2
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/CarTrackProtocol.java2
-rw-r--r--src/org/traccar/protocol/CarTrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CarcellProtocol.java2
-rw-r--r--src/org/traccar/protocol/CarcellProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CarcellProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/CarscopProtocol.java2
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CastelProtocol.java2
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java44
-rw-r--r--src/org/traccar/protocol/CellocatorFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/CellocatorProtocol.java12
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CguardProtocol.java2
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java95
-rw-r--r--src/org/traccar/protocol/CityeasyProtocol.java2
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/CradlepointProtocol.java2
-rw-r--r--src/org/traccar/protocol/CradlepointProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/DishaProtocol.java2
-rw-r--r--src/org/traccar/protocol/DishaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocol.java4
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/EelinkProtocol.java9
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java65
-rw-r--r--src/org/traccar/protocol/EnforaProtocol.java2
-rw-r--r--src/org/traccar/protocol/EnforaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ExtremTracProtocol.java47
-rw-r--r--src/org/traccar/protocol/ExtremTracProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/FifotrackProtocol.java45
-rw-r--r--src/org/traccar/protocol/FifotrackProtocolDecoder.java129
-rw-r--r--src/org/traccar/protocol/FlextrackProtocol.java2
-rw-r--r--src/org/traccar/protocol/FlextrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/FoxProtocol.java2
-rw-r--r--src/org/traccar/protocol/FoxProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/FreedomProtocol.java2
-rw-r--r--src/org/traccar/protocol/FreedomProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GalileoFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/GalileoProtocol.java2
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GatorProtocol.java2
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gl100Protocol.java2
-rw-r--r--src/org/traccar/protocol/Gl100ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gl200Protocol.java5
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java235
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolEncoder.java16
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocol.java2
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GnxProtocol.java2
-rw-r--r--src/org/traccar/protocol/GnxProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GoSafeProtocol.java2
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GotopProtocol.java2
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gps103Protocol.java2
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/GpsGateProtocol.java2
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GpsMarkerProtocol.java2
-rw-r--r--src/org/traccar/protocol/GpsMarkerProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GpsmtaProtocol.java2
-rw-r--r--src/org/traccar/protocol/GpsmtaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/GranitFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/GranitProtocol.java2
-rw-r--r--src/org/traccar/protocol/GranitProtocolDecoder.java22
-rw-r--r--src/org/traccar/protocol/GranitProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Gt02Protocol.java2
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gt06FrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gt06Protocol.java2
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolEncoder.java6
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java20
-rw-r--r--src/org/traccar/protocol/H02Protocol.java4
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java67
-rw-r--r--src/org/traccar/protocol/H02ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/HaicomProtocol.java2
-rw-r--r--src/org/traccar/protocol/HaicomProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/HomtecsProtocol.java2
-rw-r--r--src/org/traccar/protocol/HomtecsProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/HuaShengFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/HuaShengProtocol.java2
-rw-r--r--src/org/traccar/protocol/HuaShengProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/HuabaoFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/HuabaoProtocol.java2
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/HunterProProtocol.java2
-rw-r--r--src/org/traccar/protocol/HunterProProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/IdplProtocol.java2
-rw-r--r--src/org/traccar/protocol/IdplProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/IntellitracFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/IntellitracProtocol.java2
-rw-r--r--src/org/traccar/protocol/IntellitracProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/JpKorjarProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Jt600FrameDecoder.java5
-rw-r--r--src/org/traccar/protocol/Jt600Protocol.java11
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java136
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolEncoder.java43
-rwxr-xr-xsrc/org/traccar/protocol/KenjiProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/KhdProtocol.java2
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/KhdProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/L100Protocol.java2
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/LaipacProtocol.java2
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/M2mProtocol.java2
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ManPowerProtocol.java2
-rw-r--r--src/org/traccar/protocol/ManPowerProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MegastekFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/MegastekProtocol.java2
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocol.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/MeitrackFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java2
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocol.java2
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Mta6Protocol.java2
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MtxProtocol.java2
-rw-r--r--src/org/traccar/protocol/MtxProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/MxtFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/MxtProtocol.java2
-rw-r--r--src/org/traccar/protocol/MxtProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/NavigilFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/NavigilProtocol.java2
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/NavisProtocol.java2
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/NoranProtocol.java2
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/NoranProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/NvsFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/NvsProtocol.java2
-rw-r--r--src/org/traccar/protocol/NvsProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ObdDongleProtocol.java2
-rw-r--r--src/org/traccar/protocol/ObdDongleProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/OigoProtocol.java2
-rw-r--r--src/org/traccar/protocol/OigoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/OrionFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/OrionProtocol.java2
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/OsmAndProtocol.java2
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/PathAwayProtocol.java2
-rw-r--r--src/org/traccar/protocol/PathAwayProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/PiligrimProtocol.java2
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/ProgressProtocol.java2
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Pt3000Protocol.java2
-rw-r--r--src/org/traccar/protocol/Pt3000ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Pt502FrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/Pt502Protocol.java2
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/RaveonProtocol.java2
-rw-r--r--src/org/traccar/protocol/RaveonProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/RitiProtocol.java2
-rw-r--r--src/org/traccar/protocol/RitiProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/RuptelaProtocol.java2
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java32
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/SanavProtocol.java2
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocol.java2
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/SmokeyProtocol.java41
-rw-r--r--src/org/traccar/protocol/SmokeyProtocolDecoder.java85
-rw-r--r--src/org/traccar/protocol/Stl060FrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/Stl060Protocol.java2
-rw-r--r--src/org/traccar/protocol/Stl060ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/SuntechProtocol.java2
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/SuntechProtocolEncoder.java2
-rwxr-xr-xsrc/org/traccar/protocol/SupermateProtocol.java2
-rwxr-xr-xsrc/org/traccar/protocol/SupermateProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/T55Protocol.java2
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/T800xProtocol.java2
-rw-r--r--src/org/traccar/protocol/T800xProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/T800xProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/TaipProtocol.java2
-rw-r--r--src/org/traccar/protocol/TaipProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TelicFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/TelicProtocol.java2
-rw-r--r--src/org/traccar/protocol/TelicProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocol.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/ThinkRaceProtocol.java2
-rw-r--r--src/org/traccar/protocol/ThinkRaceProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Tk102Protocol.java10
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java68
-rw-r--r--src/org/traccar/protocol/Tk103Protocol.java2
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocol.java2
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TopflytechProtocol.java2
-rw-r--r--src/org/traccar/protocol/TopflytechProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TotemFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/TotemProtocol.java2
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java4
-rw-r--r--src/org/traccar/protocol/TotemProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Tr20Protocol.java2
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Tr900Protocol.java2
-rw-r--r--src/org/traccar/protocol/Tr900ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TrackboxProtocol.java2
-rw-r--r--src/org/traccar/protocol/TrackboxProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TrakMateProtocol.java47
-rw-r--r--src/org/traccar/protocol/TrakMateProtocolDecoder.java236
-rw-r--r--src/org/traccar/protocol/TramigoFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/TramigoProtocol.java2
-rw-r--r--src/org/traccar/protocol/TramigoProtocolDecoder.java11
-rw-r--r--src/org/traccar/protocol/TrvProtocol.java2
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Tt8850Protocol.java2
-rw-r--r--src/org/traccar/protocol/Tt8850ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TytanProtocol.java2
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/TzoneProtocol.java2
-rw-r--r--src/org/traccar/protocol/TzoneProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/UlbotechFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/UlbotechProtocol.java2
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/UproProtocol.java2
-rw-r--r--src/org/traccar/protocol/UproProtocolDecoder.java107
-rw-r--r--src/org/traccar/protocol/V680Protocol.java2
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java28
-rw-r--r--src/org/traccar/protocol/VisiontekProtocol.java2
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/WatchProtocol.java2
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/WialonProtocol.java2
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/WialonProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/WondexFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/WondexProtocol.java2
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/WondexProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/XexunFrameDecoder.java2
-rw-r--r--src/org/traccar/protocol/XexunProtocol.java2
-rw-r--r--src/org/traccar/protocol/XexunProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/XirgoProtocol.java2
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/Xt013Protocol.java2
-rw-r--r--src/org/traccar/protocol/Xt013ProtocolDecoder.java2
-rw-r--r--src/org/traccar/protocol/YwtProtocol.java2
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java2
-rw-r--r--src/org/traccar/reports/Events.java111
-rw-r--r--src/org/traccar/reports/ReportUtils.java28
-rw-r--r--src/org/traccar/reports/Route.java80
-rw-r--r--src/org/traccar/reports/Summary.java49
-rw-r--r--src/org/traccar/reports/Trips.java88
-rw-r--r--src/org/traccar/reports/model/BaseReport.java4
-rw-r--r--src/org/traccar/reports/model/DeviceReport.java49
-rw-r--r--src/org/traccar/reports/model/SummaryReport.java4
-rw-r--r--src/org/traccar/reports/model/TripReport.java48
-rw-r--r--src/org/traccar/web/ConsoleServlet.java10
-rw-r--r--src/org/traccar/web/CsvBuilder.java16
-rw-r--r--src/org/traccar/web/GpxBuilder.java73
-rw-r--r--src/org/traccar/web/JsonConverter.java2
-rw-r--r--src/org/traccar/web/WebServer.java37
448 files changed, 4135 insertions, 1048 deletions
diff --git a/src/org/traccar/BaseDataHandler.java b/src/org/traccar/BaseDataHandler.java
index 5ab124a79..0c71a6a4d 100644
--- a/src/org/traccar/BaseDataHandler.java
+++ b/src/org/traccar/BaseDataHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java
index 82e78c6b3..588406bf4 100644
--- a/src/org/traccar/BaseEventHandler.java
+++ b/src/org/traccar/BaseEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 615251d5f..22bb80ca1 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -50,6 +50,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private ReverseGeocoderHandler reverseGeocoderHandler;
private LocationProviderHandler locationProviderHandler;
private HemisphereHandler hemisphereHandler;
+ private CopyAttributesHandler copyAttributesHandler;
private CommandResultEventHandler commandResultEventHandler;
private OverspeedEventHandler overspeedEventHandler;
@@ -139,6 +140,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
hemisphereHandler = new HemisphereHandler();
}
+ if (Context.getConfig().getBoolean("processing.copyAttributes.enable")) {
+ copyAttributesHandler = new CopyAttributesHandler();
+ }
+
if (Context.getConfig().getBoolean("event.enable")) {
commandResultEventHandler = new CommandResultEventHandler();
@@ -201,6 +206,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("distance", distanceHandler);
}
+ if (copyAttributesHandler != null) {
+ pipeline.addLast("copyAttributes", copyAttributesHandler);
+ }
+
if (Context.getDataManager() != null) {
pipeline.addLast("dataHandler", new DefaultDataHandler());
}
@@ -229,7 +238,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("AlertEventHandler", alertEventHandler);
}
- if (alertEventHandler != null) {
+ if (ignitionEventHandler != null) {
pipeline.addLast("IgnitionEventHandler", ignitionEventHandler);
}
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index eb09022f5..4cbb5bd7c 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index 46832a4ca..d8130c79e 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -26,11 +26,27 @@ import java.net.SocketAddress;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.sql.SQLException;
public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
private final Protocol protocol;
+ public long addUnknownDevice(String uniqueId) {
+ Device device = new Device();
+ device.setName(uniqueId);
+ device.setUniqueId(uniqueId);
+
+ try {
+ Context.getDeviceManager().addDevice(device);
+ Log.info("Automatically registered device " + uniqueId);
+ return device.getId();
+ } catch (SQLException e) {
+ Log.warning(e);
+ return 0;
+ }
+ }
+
public String getProtocolName() {
return protocol.getName();
}
@@ -55,6 +71,10 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
Log.warning(e);
}
if (deviceId == 0) {
+ if (Context.getConfig().getBoolean("database.registerUnknown")) {
+ return addUnknownDevice(uniqueIds[0]);
+ }
+
StringBuilder message = new StringBuilder("Unknown device -");
for (String uniqueId : uniqueIds) {
message.append(" ").append(uniqueId);
@@ -69,6 +89,17 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) {
+ if (Context.getConfig().getBoolean("decoder.ignoreSessionCache")) {
+ long deviceId = findDeviceId(remoteAddress, uniqueIds);
+ if (deviceId != 0) {
+ if (Context.getConnectionManager() != null) {
+ Context.getConnectionManager().addActiveDevice(deviceId, protocol, channel, remoteAddress);
+ }
+ return new DeviceSession(deviceId);
+ } else {
+ return null;
+ }
+ }
if (channel instanceof DatagramChannel) {
long deviceId = findDeviceId(remoteAddress, uniqueIds);
DeviceSession deviceSession = addressDeviceSessions.get(remoteAddress);
@@ -129,6 +160,9 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
@Override
protected void onMessageEvent(Channel channel, SocketAddress remoteAddress, Object msg) {
+ if (Context.getStatisticsManager() != null) {
+ Context.getStatisticsManager().registerMessageReceived();
+ }
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession != null) {
Context.getConnectionManager().updateDevice(deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date());
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
index a9aa24cb0..5c2c503e4 100644
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ b/src/org/traccar/BaseProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/CharacterDelimiterFrameDecoder.java b/src/org/traccar/CharacterDelimiterFrameDecoder.java
index 96e86a947..d71974e78 100644
--- a/src/org/traccar/CharacterDelimiterFrameDecoder.java
+++ b/src/org/traccar/CharacterDelimiterFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java
index 7fd725734..1be86fce0 100644
--- a/src/org/traccar/Config.java
+++ b/src/org/traccar/Config.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -23,19 +23,44 @@ import java.util.Properties;
public class Config {
private final Properties properties = new Properties();
+ private Properties defaultProperties;
public void load(String file) throws IOException {
try (InputStream inputStream = new FileInputStream(file)) {
properties.loadFromXML(inputStream);
}
+
+ String defaultConfigFile = properties.getProperty("config.default");
+ if (defaultConfigFile != null) {
+ try (InputStream inputStream = new FileInputStream(defaultConfigFile)) {
+ defaultProperties = new Properties();
+ defaultProperties.loadFromXML(inputStream);
+ }
+ }
}
public boolean hasKey(String key) {
- return properties.containsKey(key);
+ return properties.containsKey(key) || defaultProperties != null && defaultProperties.containsKey(key);
+ }
+
+ public String getString(String key) {
+ if (properties.containsKey(key) || defaultProperties == null) {
+ return properties.getProperty(key);
+ } else {
+ return defaultProperties.getProperty(key);
+ }
+ }
+
+ public String getString(String key, String defaultValue) {
+ if (hasKey(key)) {
+ return getString(key);
+ } else {
+ return defaultValue;
+ }
}
public boolean getBoolean(String key) {
- return Boolean.parseBoolean(properties.getProperty(key));
+ return Boolean.parseBoolean(getString(key));
}
public int getInteger(String key) {
@@ -43,8 +68,8 @@ public class Config {
}
public int getInteger(String key, int defaultValue) {
- if (properties.containsKey(key)) {
- return Integer.parseInt(properties.getProperty(key));
+ if (hasKey(key)) {
+ return Integer.parseInt(getString(key));
} else {
return defaultValue;
}
@@ -55,20 +80,8 @@ public class Config {
}
public long getLong(String key, long defaultValue) {
- if (properties.containsKey(key)) {
- return Long.parseLong(properties.getProperty(key));
- } else {
- return defaultValue;
- }
- }
-
- public String getString(String key) {
- return properties.getProperty(key);
- }
-
- public String getString(String key, String defaultValue) {
- if (properties.containsKey(key)) {
- return properties.getProperty(key);
+ if (hasKey(key)) {
+ return Long.parseLong(getString(key));
} else {
return defaultValue;
}
@@ -79,8 +92,8 @@ public class Config {
}
public double getDouble(String key, double defaultValue) {
- if (properties.containsKey(key)) {
- return Double.parseDouble(properties.getProperty(key));
+ if (hasKey(key)) {
+ return Double.parseDouble(getString(key));
} else {
return defaultValue;
}
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index c7359e76c..581f00082 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -16,6 +16,8 @@
package org.traccar;
import com.ning.http.client.AsyncHttpClient;
+
+import org.traccar.database.AliasesManager;
import org.traccar.database.ConnectionManager;
import org.traccar.database.DataManager;
import org.traccar.database.DeviceManager;
@@ -23,6 +25,7 @@ import org.traccar.database.IdentityManager;
import org.traccar.database.NotificationManager;
import org.traccar.database.PermissionsManager;
import org.traccar.database.GeofenceManager;
+import org.traccar.database.StatisticsManager;
import org.traccar.geocode.BingMapsReverseGeocoder;
import org.traccar.geocode.FactualReverseGeocoder;
import org.traccar.geocode.GeocodeFarmReverseGeocoder;
@@ -134,13 +137,27 @@ public final class Context {
return eventForwarder;
}
+ private static AliasesManager aliasesManager;
+
+ public static AliasesManager getAliasesManager() {
+ return aliasesManager;
+ }
+
+ private static StatisticsManager statisticsManager;
+
+ public static StatisticsManager getStatisticsManager() {
+ return statisticsManager;
+ }
+
public static void init(String[] arguments) throws Exception {
config = new Config();
- if (arguments.length > 0) {
- config.load(arguments[0]);
+ if (arguments.length <= 0) {
+ throw new RuntimeException("Configuration file is not provided");
}
+ config.load(arguments[0]);
+
loggerEnabled = config.getBoolean("logger.enable");
if (loggerEnabled) {
Log.setupLogger(config);
@@ -233,6 +250,10 @@ public final class Context {
eventForwarder = new EventForwarder();
}
+ aliasesManager = new AliasesManager(dataManager);
+
+ statisticsManager = new StatisticsManager();
+
}
public static void init(IdentityManager testIdentityManager) {
diff --git a/src/org/traccar/CoordinatesHandler.java b/src/org/traccar/CoordinatesHandler.java
index 2dcb3c632..80a423da1 100644
--- a/src/org/traccar/CoordinatesHandler.java
+++ b/src/org/traccar/CoordinatesHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -20,11 +20,13 @@ import org.traccar.model.Position;
public class CoordinatesHandler extends BaseDataHandler {
- private final int coordinatesError;
+ private final int coordinatesMinError;
+ private final int coordinatesMaxError;
public CoordinatesHandler() {
Config config = Context.getConfig();
- coordinatesError = config.getInteger("coordinates.error", 50);
+ coordinatesMinError = config.getInteger("coordinates.minError");
+ coordinatesMaxError = config.getInteger("coordinates.maxError");
}
private Position getLastPosition(long deviceId) {
@@ -37,10 +39,12 @@ public class CoordinatesHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
Position last = getLastPosition(position.getDeviceId());
- if (last != null) {
+ if (last != null && last.getValid() && last.getLatitude() != 0 && last.getLongitude() != 0) {
double distance = DistanceCalculator.distance(
position.getLatitude(), position.getLongitude(), last.getLatitude(), last.getLongitude());
- if (distance < coordinatesError) {
+ boolean satisfiesMin = coordinatesMinError == 0 || distance > coordinatesMinError;
+ boolean satisfiesMax = coordinatesMaxError == 0 || distance < coordinatesMaxError || position.getValid();
+ if (!satisfiesMin || !satisfiesMax) {
position.setLatitude(last.getLatitude());
position.setLongitude(last.getLongitude());
}
diff --git a/src/org/traccar/CopyAttributesHandler.java b/src/org/traccar/CopyAttributesHandler.java
new file mode 100644
index 000000000..c4cac2e7f
--- /dev/null
+++ b/src/org/traccar/CopyAttributesHandler.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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;
+
+import org.traccar.model.Position;
+
+public class CopyAttributesHandler extends BaseDataHandler {
+
+ private Position getLastPosition(long deviceId) {
+ if (Context.getIdentityManager() != null) {
+ return Context.getIdentityManager().getLastPosition(deviceId);
+ }
+ return null;
+ }
+
+ @Override
+ protected Position handlePosition(Position position) {
+ String attributesString = Context.getDeviceManager().lookupConfigString(position.getDeviceId(),
+ "processing.copyAttributes", null);
+ Position last = getLastPosition(position.getDeviceId());
+ if (attributesString != null && last != null) {
+ for (String attribute : attributesString.split(" ")) {
+ if (last.getAttributes().containsKey(attribute) && !position.getAttributes().containsKey(attribute)) {
+ position.getAttributes().put(attribute, last.getAttributes().get(attribute));
+ }
+ }
+ }
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/DefaultDataHandler.java
index 7194c6a77..e32fe0e7d 100644
--- a/src/org/traccar/DefaultDataHandler.java
+++ b/src/org/traccar/DefaultDataHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/DeviceSession.java b/src/org/traccar/DeviceSession.java
index 5e2686f23..36958287d 100644
--- a/src/org/traccar/DeviceSession.java
+++ b/src/org/traccar/DeviceSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java
index 7537e2867..138fc85d6 100644
--- a/src/org/traccar/DistanceHandler.java
+++ b/src/org/traccar/DistanceHandler.java
@@ -1,6 +1,6 @@
/*
* Copyright 2015 Amila Silva
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index 1cfc93541..ec03afa60 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 5315bad9e..40676c72d 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 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.
@@ -23,37 +23,59 @@ public class FilterHandler extends BaseDataHandler {
private static final long FILTER_FUTURE_LIMIT = 5 * 60 * 1000;
- private final boolean filterInvalid;
- private final boolean filterZero;
- private final boolean filterDuplicate;
- private final boolean filterFuture;
- private final boolean filterApproximate;
- private final int filterDistance;
- private final long filterLimit;
-
- public FilterHandler(
- boolean filterInvalid, boolean filterZero, boolean filterDuplicate, boolean filterFuture,
- boolean filterApproximate, int filterDistance, long filterLimit) {
+ private boolean filterInvalid;
+ private boolean filterZero;
+ private boolean filterDuplicate;
+ private boolean filterFuture;
+ private boolean filterApproximate;
+ private boolean filterStatic;
+ private int filterDistance;
+ private long filterLimit;
+ public void setFilterInvalid(boolean filterInvalid) {
this.filterInvalid = filterInvalid;
+ }
+
+ public void setFilterZero(boolean filterZero) {
this.filterZero = filterZero;
+ }
+
+ public void setFilterDuplicate(boolean filterDuplicate) {
this.filterDuplicate = filterDuplicate;
- this.filterDistance = filterDistance;
+ }
+
+ public void setFilterFuture(boolean filterFuture) {
this.filterFuture = filterFuture;
+ }
+
+ public void setFilterApproximate(boolean filterApproximate) {
this.filterApproximate = filterApproximate;
+ }
+
+ public void setFilterStatic(boolean filterStatic) {
+ this.filterStatic = filterStatic;
+ }
+
+ public void setFilterDistance(int filterDistance) {
+ this.filterDistance = filterDistance;
+ }
+
+ public void setFilterLimit(long filterLimit) {
this.filterLimit = filterLimit;
}
public FilterHandler() {
Config config = Context.getConfig();
-
- filterInvalid = config.getBoolean("filter.invalid");
- filterZero = config.getBoolean("filter.zero");
- filterDuplicate = config.getBoolean("filter.duplicate");
- filterFuture = config.getBoolean("filter.future");
- filterApproximate = config.getBoolean("filter.approximate");
- filterDistance = config.getInteger("filter.distance");
- filterLimit = config.getLong("filter.limit") * 1000;
+ if (config != null) {
+ filterInvalid = config.getBoolean("filter.invalid");
+ filterZero = config.getBoolean("filter.zero");
+ filterDuplicate = config.getBoolean("filter.duplicate");
+ filterFuture = config.getBoolean("filter.future");
+ filterApproximate = config.getBoolean("filter.approximate");
+ filterStatic = config.getBoolean("filter.static");
+ filterDistance = config.getInteger("filter.distance");
+ filterLimit = config.getLong("filter.limit") * 1000;
+ }
}
private Position getLastPosition(long deviceId) {
@@ -93,6 +115,10 @@ public class FilterHandler extends BaseDataHandler {
return filterApproximate && approximate != null && approximate;
}
+ private boolean filterStatic(Position position) {
+ return filterStatic && position.getSpeed() == 0.0;
+ }
+
private boolean filterDistance(Position position) {
if (filterDistance != 0) {
Position last = getLastPosition(position.getDeviceId());
@@ -122,20 +148,47 @@ public class FilterHandler extends BaseDataHandler {
}
}
- private boolean filter(Position p) {
+ private boolean filter(Position position) {
- boolean result = filterInvalid(p) || filterZero(p) || filterDuplicate(p)
- || filterFuture(p) || filterApproximate(p) || filterDistance(p);
+ StringBuilder filterType = new StringBuilder();
- if (filterLimit(p)) {
- result = false;
+ if (filterInvalid(position)) {
+ filterType.append("Invalid ");
+ }
+ if (filterZero(position)) {
+ filterType.append("Zero ");
}
+ if (filterDuplicate(position)) {
+ filterType.append("Duplicate ");
+ }
+ if (filterFuture(position)) {
+ filterType.append("Future ");
+ }
+ if (filterApproximate(position)) {
+ filterType.append("Approximate ");
+ }
+ if (filterStatic(position)) {
+ filterType.append("Static ");
+ }
+ if (filterDistance(position)) {
+ filterType.append("Distance ");
+ }
+
+ if (filterType.length() > 0 && !filterLimit(position)) {
+
+ StringBuilder message = new StringBuilder();
+ message.append("Position filtered by ");
+ message.append(filterType.toString());
+ message.append("filters from device: ");
+ message.append(Context.getIdentityManager().getDeviceById(position.getDeviceId()).getUniqueId());
+ message.append(" with id: ");
+ message.append(position.getDeviceId());
- if (result) {
- Log.info("Position filtered from " + p.getDeviceId());
+ Log.info(message.toString());
+ return true;
}
- return result;
+ return false;
}
@Override
diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java
index aa4f855c5..c5cd1a697 100644
--- a/src/org/traccar/GlobalChannelFactory.java
+++ b/src/org/traccar/GlobalChannelFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 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.
diff --git a/src/org/traccar/GlobalTimer.java b/src/org/traccar/GlobalTimer.java
index f5dc9b87a..70e6e2e45 100644
--- a/src/org/traccar/GlobalTimer.java
+++ b/src/org/traccar/GlobalTimer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 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.
diff --git a/src/org/traccar/HemisphereHandler.java b/src/org/traccar/HemisphereHandler.java
index b46d0791c..b1e7d3fb2 100644
--- a/src/org/traccar/HemisphereHandler.java
+++ b/src/org/traccar/HemisphereHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/LocationProviderHandler.java b/src/org/traccar/LocationProviderHandler.java
index 8d5647d4b..d47f05bd1 100644
--- a/src/org/traccar/LocationProviderHandler.java
+++ b/src/org/traccar/LocationProviderHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index e992691ad..21625d3c1 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 3f7e68b2a..ec31c5efd 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
@@ -62,6 +62,7 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
}
Log.info(s.toString());
+ Context.getStatisticsManager().registerMessageStored(position.getDeviceId());
}
}
diff --git a/src/org/traccar/RemoteAddressHandler.java b/src/org/traccar/RemoteAddressHandler.java
index 3d9695dab..188bbcab9 100644
--- a/src/org/traccar/RemoteAddressHandler.java
+++ b/src/org/traccar/RemoteAddressHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/ReverseGeocoderHandler.java b/src/org/traccar/ReverseGeocoderHandler.java
index 0b4fd53ce..88875fb3a 100644
--- a/src/org/traccar/ReverseGeocoderHandler.java
+++ b/src/org/traccar/ReverseGeocoderHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 010438a44..953428b8f 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/StringProtocolEncoder.java b/src/org/traccar/StringProtocolEncoder.java
index 119b40cc4..1945ae174 100644
--- a/src/org/traccar/StringProtocolEncoder.java
+++ b/src/org/traccar/StringProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
index 7bbab071d..108688fb8 100644
--- a/src/org/traccar/TrackerServer.java
+++ b/src/org/traccar/TrackerServer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2014 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.
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
index b179fac8f..f99d7c97a 100644
--- a/src/org/traccar/WebDataHandler.java
+++ b/src/org/traccar/WebDataHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -51,23 +51,8 @@ public class WebDataHandler extends BaseDataHandler {
double lat = position.getLatitude();
double lon = position.getLongitude();
- char hemisphere;
-
- if (lat < 0) {
- hemisphere = 'S';
- } else {
- hemisphere = 'N';
- }
-
- f.format("%02d%07.4f,%c,", (int) Math.abs(lat), Math.abs(lat) % 1 * 60, hemisphere);
-
- if (lon < 0) {
- hemisphere = 'W';
- } else {
- hemisphere = 'E';
- }
-
- f.format("%03d%07.4f,%c,", (int) Math.abs(lon), Math.abs(lon) % 1 * 60, hemisphere);
+ f.format("%02d%07.4f,%c,", (int) Math.abs(lat), Math.abs(lat) % 1 * 60, lat < 0 ? 'S' : 'N');
+ f.format("%03d%07.4f,%c,", (int) Math.abs(lon), Math.abs(lon) % 1 * 60, lon < 0 ? 'W' : 'E');
f.format("%.2f,%.2f,", position.getSpeed(), position.getCourse());
f.format("%1$td%1$tm%1$ty,,", calendar);
diff --git a/src/org/traccar/api/AsyncSocket.java b/src/org/traccar/api/AsyncSocket.java
index 4422dbccd..7ac3810fa 100644
--- a/src/org/traccar/api/AsyncSocket.java
+++ b/src/org/traccar/api/AsyncSocket.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/api/AsyncSocketServlet.java b/src/org/traccar/api/AsyncSocketServlet.java
index ef6cef732..9318b6fc6 100644
--- a/src/org/traccar/api/AsyncSocketServlet.java
+++ b/src/org/traccar/api/AsyncSocketServlet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/api/BaseResource.java b/src/org/traccar/api/BaseResource.java
index 567b9735a..44ef33c53 100644
--- a/src/org/traccar/api/BaseResource.java
+++ b/src/org/traccar/api/BaseResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/api/CorsResponseFilter.java b/src/org/traccar/api/CorsResponseFilter.java
index 459fcee66..70ea7e3e1 100644
--- a/src/org/traccar/api/CorsResponseFilter.java
+++ b/src/org/traccar/api/CorsResponseFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/api/ObjectMapperProvider.java b/src/org/traccar/api/ObjectMapperProvider.java
index 6f654118a..c916c1f4c 100644
--- a/src/org/traccar/api/ObjectMapperProvider.java
+++ b/src/org/traccar/api/ObjectMapperProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/api/ResourceErrorHandler.java b/src/org/traccar/api/ResourceErrorHandler.java
index be63aad09..1d618b08d 100644
--- a/src/org/traccar/api/ResourceErrorHandler.java
+++ b/src/org/traccar/api/ResourceErrorHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -20,24 +20,22 @@ import org.traccar.helper.Log;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
-import java.util.HashMap;
-import java.util.Map;
public class ResourceErrorHandler implements ExceptionMapper<Exception> {
- private static final String KEY_MESSAGE = "message";
- private static final String KEY_DETAILS = "details";
-
@Override
public Response toResponse(Exception e) {
- Map<String, String> error = new HashMap<>();
if (e instanceof WebApplicationException) {
- WebApplicationException webApplicationException = (WebApplicationException) e;
- return Response.status(webApplicationException.getResponse().getStatus()).entity(error).build();
+ WebApplicationException exception = (WebApplicationException) e;
+ String message;
+ if (exception.getCause() != null) {
+ message = Log.exceptionStack(exception.getCause());
+ } else {
+ message = Log.exceptionStack(exception);
+ }
+ return Response.fromResponse(exception.getResponse()).entity(message).build();
} else {
- error.put(KEY_MESSAGE, e.getMessage());
- error.put(KEY_DETAILS, Log.exceptionStack(e));
- return Response.status(Response.Status.BAD_REQUEST).entity(error).build();
+ return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build();
}
}
diff --git a/src/org/traccar/api/SecurityRequestFilter.java b/src/org/traccar/api/SecurityRequestFilter.java
index f0dd363db..ca3ebf04d 100644
--- a/src/org/traccar/api/SecurityRequestFilter.java
+++ b/src/org/traccar/api/SecurityRequestFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -17,6 +17,7 @@ package org.traccar.api;
import org.traccar.Context;
import org.traccar.api.resource.SessionResource;
+import org.traccar.helper.Log;
import org.traccar.model.User;
import javax.annotation.security.PermitAll;
@@ -62,26 +63,35 @@ public class SecurityRequestFilter implements ContainerRequestFilter {
SecurityContext securityContext = null;
- String authHeader = requestContext.getHeaderString(AUTHORIZATION_HEADER);
- if (authHeader != null) {
+ try {
- try {
- String[] auth = decodeBasicAuth(authHeader);
- User user = Context.getDataManager().login(auth[0], auth[1]);
- if (user != null) {
- securityContext = new UserSecurityContext(new UserPrincipal(user.getId()));
+ String authHeader = requestContext.getHeaderString(AUTHORIZATION_HEADER);
+ if (authHeader != null) {
+
+ try {
+ String[] auth = decodeBasicAuth(authHeader);
+ User user = Context.getPermissionsManager().login(auth[0], auth[1]);
+ if (user != null) {
+ Context.getStatisticsManager().registerRequest(user.getId());
+ securityContext = new UserSecurityContext(new UserPrincipal(user.getId()));
+ }
+ } catch (SQLException e) {
+ throw new WebApplicationException(e);
}
- } catch (SQLException e) {
- throw new WebApplicationException(e);
- }
- } else if (request.getSession() != null) {
+ } else if (request.getSession() != null) {
+
+ Long userId = (Long) request.getSession().getAttribute(SessionResource.USER_ID_KEY);
+ if (userId != null) {
+ Context.getPermissionsManager().checkUserEnabled(userId);
+ Context.getStatisticsManager().registerRequest(userId);
+ securityContext = new UserSecurityContext(new UserPrincipal(userId));
+ }
- Long userId = (Long) request.getSession().getAttribute(SessionResource.USER_ID_KEY);
- if (userId != null) {
- securityContext = new UserSecurityContext(new UserPrincipal(userId));
}
+ } catch (SecurityException e) {
+ Log.warning(e);
}
if (securityContext != null) {
diff --git a/src/org/traccar/api/UserPrincipal.java b/src/org/traccar/api/UserPrincipal.java
index 25fcdb233..80e92c2dd 100644
--- a/src/org/traccar/api/UserPrincipal.java
+++ b/src/org/traccar/api/UserPrincipal.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/api/UserSecurityContext.java b/src/org/traccar/api/UserSecurityContext.java
index 0ff67a0f8..55c0621bc 100644
--- a/src/org/traccar/api/UserSecurityContext.java
+++ b/src/org/traccar/api/UserSecurityContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/api/resource/AttributeAliasResource.java b/src/org/traccar/api/resource/AttributeAliasResource.java
new file mode 100644
index 000000000..db767616f
--- /dev/null
+++ b/src/org/traccar/api/resource/AttributeAliasResource.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.api.resource;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.traccar.Context;
+import org.traccar.api.BaseResource;
+import org.traccar.model.AttributeAlias;
+
+@Path("attributes/aliases")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class AttributeAliasResource extends BaseResource {
+
+ @GET
+ public Collection<AttributeAlias> get(@QueryParam("deviceId") long deviceId) throws SQLException {
+ if (deviceId != 0) {
+ if (!Context.getPermissionsManager().isAdmin(getUserId())) {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ }
+ return Context.getAliasesManager().getAttributeAliases(deviceId);
+ } else {
+ return Context.getAliasesManager().getAllAttributeAliases(getUserId());
+ }
+ }
+
+ @POST
+ public Response add(AttributeAlias entity) throws SQLException {
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ if (!Context.getPermissionsManager().isAdmin(getUserId())) {
+ Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
+ }
+ Context.getAliasesManager().addAttributeAlias(entity);
+ return Response.ok(entity).build();
+ }
+
+ @Path("{id}")
+ @PUT
+ public Response update(AttributeAlias entity) throws SQLException {
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ if (!Context.getPermissionsManager().isAdmin(getUserId())) {
+ AttributeAlias oldEntity = Context.getAliasesManager().getAttributeAlias(entity.getId());
+ Context.getPermissionsManager().checkDevice(getUserId(), oldEntity.getDeviceId());
+ Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
+ }
+ Context.getAliasesManager().updateAttributeAlias(entity);
+ return Response.ok(entity).build();
+ }
+
+ @Path("{id}")
+ @DELETE
+ public Response remove(@PathParam("id") long id) throws SQLException {
+ Context.getPermissionsManager().checkReadonly(getUserId());
+ if (!Context.getPermissionsManager().isAdmin(getUserId())) {
+ AttributeAlias entity = Context.getAliasesManager().getAttributeAlias(id);
+ Context.getPermissionsManager().checkDevice(getUserId(), entity.getDeviceId());
+ }
+ Context.getAliasesManager().removeArrtibuteAlias(id);
+ return Response.noContent().build();
+ }
+
+}
diff --git a/src/org/traccar/api/resource/CommandResource.java b/src/org/traccar/api/resource/CommandResource.java
index f41faae2e..cce2dac2b 100644
--- a/src/org/traccar/api/resource/CommandResource.java
+++ b/src/org/traccar/api/resource/CommandResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/api/resource/DeviceGeofenceResource.java b/src/org/traccar/api/resource/DeviceGeofenceResource.java
index 27535617d..6254fe3cf 100644
--- a/src/org/traccar/api/resource/DeviceGeofenceResource.java
+++ b/src/org/traccar/api/resource/DeviceGeofenceResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/api/resource/DevicePermissionResource.java b/src/org/traccar/api/resource/DevicePermissionResource.java
index 7faa1ab09..3b89507fa 100644
--- a/src/org/traccar/api/resource/DevicePermissionResource.java
+++ b/src/org/traccar/api/resource/DevicePermissionResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index b12ab8c36..e4ecd3625 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -18,6 +18,7 @@ package org.traccar.api.resource;
import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.Device;
+import org.traccar.model.DeviceTotalDistance;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
@@ -57,6 +58,13 @@ public class DeviceResource extends BaseResource {
@POST
public Response add(Device entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
+ int deviceLimit = Context.getPermissionsManager().getUser(getUserId()).getDeviceLimit();
+ if (deviceLimit != 0) {
+ int deviceCount = Context.getPermissionsManager().getDevicePermissions(getUserId()).size();
+ if (deviceCount >= deviceLimit) {
+ throw new SecurityException("User device limit reached");
+ }
+ }
Context.getDeviceManager().addDevice(entity);
Context.getDataManager().linkDevice(getUserId(), entity.getId());
Context.getPermissionsManager().refreshPermissions();
@@ -68,9 +76,9 @@ public class DeviceResource extends BaseResource {
@Path("{id}")
@PUT
- public Response update(@PathParam("id") long id, Device entity) throws SQLException {
+ public Response update(Device entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDevice(getUserId(), id);
+ Context.getPermissionsManager().checkDevice(getUserId(), entity.getId());
Context.getDeviceManager().updateDevice(entity);
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
@@ -88,6 +96,15 @@ public class DeviceResource extends BaseResource {
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
+ Context.getAliasesManager().removeDevice(id);
+ return Response.noContent().build();
+ }
+
+ @Path("{id}/distance")
+ @PUT
+ public Response updateTotalDistance(DeviceTotalDistance entity) throws SQLException {
+ Context.getPermissionsManager().checkAdmin(getUserId());
+ Context.getDeviceManager().resetTotalDistance(entity);
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java
index 74a748ea5..c0a8f968d 100644
--- a/src/org/traccar/api/resource/EventResource.java
+++ b/src/org/traccar/api/resource/EventResource.java
@@ -1,14 +1,12 @@
package org.traccar.api.resource;
import java.sql.SQLException;
-import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.traccar.Context;
@@ -26,14 +24,9 @@ public class EventResource extends BaseResource {
public Event get(@PathParam("id") long id) throws SQLException {
Event event = Context.getDataManager().getEvent(id);
Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
+ if (event.getGeofenceId() != 0) {
+ Context.getPermissionsManager().checkGeofence(getUserId(), event.getGeofenceId());
+ }
return event;
}
-
- @GET
- public Collection<Event> get(
- @QueryParam("deviceId") long deviceId, @QueryParam("type") String type,
- @QueryParam("interval") int interval) throws SQLException {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- return Context.getDataManager().getLastEvents(deviceId, type, interval);
- }
}
diff --git a/src/org/traccar/api/resource/GeofencePermissionResource.java b/src/org/traccar/api/resource/GeofencePermissionResource.java
index 3a82845f5..8faa63d85 100644
--- a/src/org/traccar/api/resource/GeofencePermissionResource.java
+++ b/src/org/traccar/api/resource/GeofencePermissionResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java
index 960ab813f..591908813 100644
--- a/src/org/traccar/api/resource/GeofenceResource.java
+++ b/src/org/traccar/api/resource/GeofenceResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -45,9 +45,13 @@ public class GeofenceResource extends BaseResource {
@GET
public Collection<Geofence> get(
@QueryParam("all") boolean all, @QueryParam("userId") long userId, @QueryParam("groupId") long groupId,
- @QueryParam("deviceId") long deviceId) throws SQLException {
+ @QueryParam("deviceId") long deviceId, @QueryParam("refresh") boolean refresh) throws SQLException {
GeofenceManager geofenceManager = Context.getGeofenceManager();
+ if (refresh) {
+ geofenceManager.refreshGeofences();
+ }
+
Set<Long> result;
if (all) {
Context.getPermissionsManager().checkAdmin(getUserId());
@@ -57,7 +61,7 @@ public class GeofenceResource extends BaseResource {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- result = new HashSet<Long>(geofenceManager.getUserGeofencesIds(userId));
+ result = new HashSet<>(geofenceManager.getUserGeofencesIds(userId));
}
if (groupId != 0) {
@@ -84,9 +88,9 @@ public class GeofenceResource extends BaseResource {
@Path("{id}")
@PUT
- public Response update(@PathParam("id") long id, Geofence entity) throws SQLException {
+ public Response update(Geofence entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkGeofence(getUserId(), id);
+ Context.getPermissionsManager().checkGeofence(getUserId(), entity.getId());
Context.getGeofenceManager().updateGeofence(entity);
return Response.ok(entity).build();
}
diff --git a/src/org/traccar/api/resource/GroupGeofenceResource.java b/src/org/traccar/api/resource/GroupGeofenceResource.java
index 1ef495a86..81fd4e45f 100644
--- a/src/org/traccar/api/resource/GroupGeofenceResource.java
+++ b/src/org/traccar/api/resource/GroupGeofenceResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/api/resource/GroupPermissionResource.java b/src/org/traccar/api/resource/GroupPermissionResource.java
index 94100362b..07f101765 100644
--- a/src/org/traccar/api/resource/GroupPermissionResource.java
+++ b/src/org/traccar/api/resource/GroupPermissionResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java
index 6b722ef6d..c98a20b7e 100644
--- a/src/org/traccar/api/resource/GroupResource.java
+++ b/src/org/traccar/api/resource/GroupResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -67,9 +67,9 @@ public class GroupResource extends BaseResource {
@Path("{id}")
@PUT
- public Response update(@PathParam("id") long id, Group entity) throws SQLException {
+ public Response update(Group entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkGroup(getUserId(), id);
+ Context.getPermissionsManager().checkGroup(getUserId(), entity.getId());
Context.getDeviceManager().updateGroup(entity);
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
diff --git a/src/org/traccar/api/resource/NotificationResource.java b/src/org/traccar/api/resource/NotificationResource.java
index 5bec7fd85..c43cca122 100644
--- a/src/org/traccar/api/resource/NotificationResource.java
+++ b/src/org/traccar/api/resource/NotificationResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -56,4 +56,5 @@ public class NotificationResource extends BaseResource {
Context.getNotificationManager().updateNotification(entity);
return Response.ok(entity).build();
}
+
}
diff --git a/src/org/traccar/api/resource/PositionResource.java b/src/org/traccar/api/resource/PositionResource.java
index e00e06e7a..c1cfc0b5c 100644
--- a/src/org/traccar/api/resource/PositionResource.java
+++ b/src/org/traccar/api/resource/PositionResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -17,25 +17,35 @@ package org.traccar.api.resource;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.helper.DateUtil;
import org.traccar.model.Position;
-import org.traccar.web.JsonConverter;
+import org.traccar.web.CsvBuilder;
+import org.traccar.web.GpxBuilder;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
import java.sql.SQLException;
import java.util.Collection;
@Path("positions")
-@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class PositionResource extends BaseResource {
+ public static final String TEXT_CSV = "text/csv";
+ public static final String CONTENT_DISPOSITION_VALUE_CSV = "attachment; filename=positions.csv";
+ public static final String GPX = "application/gpx+xml";
+ public static final String CONTENT_DISPOSITION_VALUE_GPX = "attachment; filename=positions.gpx";
+
@GET
- public Collection<Position> get(
+ @Produces(MediaType.APPLICATION_JSON)
+ public Collection<Position> getJson(
@QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to)
throws SQLException {
if (deviceId == 0) {
@@ -43,8 +53,33 @@ public class PositionResource extends BaseResource {
} else {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
return Context.getDataManager().getPositions(
- deviceId, JsonConverter.parseDate(from), JsonConverter.parseDate(to));
+ deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to));
}
}
+ @GET
+ @Produces(TEXT_CSV)
+ public Response getCsv(
+ @QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to)
+ throws SQLException {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ CsvBuilder csv = new CsvBuilder();
+ csv.addHeaderLine(new Position());
+ csv.addArray(Context.getDataManager().getPositions(
+ deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to)));
+ return Response.ok(csv.build()).header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_CSV).build();
+ }
+
+ @GET
+ @Produces(GPX)
+ public Response getGpx(
+ @QueryParam("deviceId") long deviceId, @QueryParam("from") String from, @QueryParam("to") String to)
+ throws SQLException {
+ Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
+ GpxBuilder gpx = new GpxBuilder(Context.getIdentityManager().getDeviceById(deviceId).getName());
+ gpx.addPositions(Context.getDataManager().getPositions(
+ deviceId, DateUtil.parseDate(from), DateUtil.parseDate(to)));
+ return Response.ok(gpx.build()).header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_GPX).build();
+ }
+
}
diff --git a/src/org/traccar/api/resource/ReportResource.java b/src/org/traccar/api/resource/ReportResource.java
index 0dd0452ff..2717fe01e 100644
--- a/src/org/traccar/api/resource/ReportResource.java
+++ b/src/org/traccar/api/resource/ReportResource.java
@@ -1,6 +1,9 @@
package org.traccar.api.resource;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.sql.SQLException;
+import java.util.Collection;
import java.util.List;
import javax.ws.rs.Consumes;
@@ -13,107 +16,119 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.traccar.api.BaseResource;
+import org.traccar.helper.DateUtil;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
import org.traccar.reports.Events;
import org.traccar.reports.Summary;
import org.traccar.reports.Trips;
+import org.traccar.reports.model.SummaryReport;
+import org.traccar.reports.model.TripReport;
import org.traccar.reports.Route;
-import org.traccar.web.JsonConverter;
@Path("reports")
@Consumes(MediaType.APPLICATION_JSON)
public class ReportResource extends BaseResource {
- public static final String TEXT_CSV = "text/csv";
- public static final String CONTENT_DISPOSITION_VALUE = "attachment; filename=report.csv";
+ private static final String XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+ private static final String CONTENT_DISPOSITION_VALUE_XLSX = "attachment; filename=report.xlsx";
@Path("route")
@GET
@Produces(MediaType.APPLICATION_JSON)
- public Response getRouteJson(
+ public Collection<Position> getRoute(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
@QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Route.getJson(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build();
+ return Route.getObjects(getUserId(), deviceIds, groupIds,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
}
@Path("route")
@GET
- @Produces(TEXT_CSV)
- public Response getRouteCsv(
+ @Produces(XLSX)
+ public Response getRouteExcel(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
- @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Route.getCsv(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Route.getExcel(stream, getUserId(), deviceIds, groupIds,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
@Path("events")
@GET
@Produces(MediaType.APPLICATION_JSON)
- public Response getEventsJson(
+ public Collection<Event> getEvents(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
@QueryParam("type") final List<String> types,
@QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Events.getJson(getUserId(), deviceIds, groupIds, types,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build();
+ return Events.getObjects(getUserId(), deviceIds, groupIds, types,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
}
@Path("events")
@GET
- @Produces(TEXT_CSV)
- public Response getEventsCsv(
+ @Produces(XLSX)
+ public Response getEventsExcel(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
@QueryParam("type") final List<String> types,
- @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Events.getCsv(getUserId(), deviceIds, groupIds,
- types, JsonConverter.parseDate(from), JsonConverter.parseDate(to)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Events.getExcel(stream, getUserId(), deviceIds, groupIds, types,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
@Path("summary")
@GET
@Produces(MediaType.APPLICATION_JSON)
- public Response getSummaryJson(
+ public Collection<SummaryReport> getSummary(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
@QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Summary.getJson(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build();
+ return Summary.getObjects(getUserId(), deviceIds, groupIds,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
}
@Path("summary")
@GET
- @Produces(TEXT_CSV)
- public Response getSummaryCsv(
+ @Produces(XLSX)
+ public Response getSummaryExcel(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
- @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Summary.getCsv(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Summary.getExcel(stream, getUserId(), deviceIds, groupIds,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
@Path("trips")
@GET
@Produces(MediaType.APPLICATION_JSON)
- public Response getTripsJson(
+ public Collection<TripReport> getTrips(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
@QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Trips.getJson(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to))).build();
+ return Trips.getObjects(getUserId(), deviceIds, groupIds,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
}
@Path("trips")
@GET
- @Produces(TEXT_CSV)
- public Response getTripsCsv(
+ @Produces(XLSX)
+ public Response getTripsExcel(
@QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
- @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Response.ok(Trips.getCsv(getUserId(), deviceIds, groupIds,
- JsonConverter.parseDate(from), JsonConverter.parseDate(to)))
- .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE)
- .build();
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ Trips.getExcel(stream, getUserId(), deviceIds, groupIds,
+ DateUtil.parseDate(from), DateUtil.parseDate(to));
+
+ return Response.ok(stream.toByteArray())
+ .header(HttpHeaders.CONTENT_DISPOSITION, CONTENT_DISPOSITION_VALUE_XLSX).build();
}
}
diff --git a/src/org/traccar/api/resource/ServerResource.java b/src/org/traccar/api/resource/ServerResource.java
index 0ca0d62aa..034a5c492 100644
--- a/src/org/traccar/api/resource/ServerResource.java
+++ b/src/org/traccar/api/resource/ServerResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java
index deed70b37..5f1c597d1 100644
--- a/src/org/traccar/api/resource/SessionResource.java
+++ b/src/org/traccar/api/resource/SessionResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -29,6 +29,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -48,7 +49,7 @@ public class SessionResource extends BaseResource {
@PermitAll
@GET
- public User get() throws SQLException {
+ public User get(@QueryParam("token") String token) throws SQLException {
Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY);
if (userId == null) {
Cookie[] cookies = request.getCookies();
@@ -64,7 +65,13 @@ public class SessionResource extends BaseResource {
}
}
if (email != null && password != null) {
- User user = Context.getDataManager().login(email, password);
+ User user = Context.getPermissionsManager().login(email, password);
+ if (user != null) {
+ userId = user.getId();
+ request.getSession().setAttribute(USER_ID_KEY, userId);
+ }
+ } else if (token != null) {
+ User user = Context.getPermissionsManager().getUserByToken(token);
if (user != null) {
userId = user.getId();
request.getSession().setAttribute(USER_ID_KEY, userId);
@@ -73,6 +80,7 @@ public class SessionResource extends BaseResource {
}
if (userId != null) {
+ Context.getPermissionsManager().checkUserEnabled(userId);
return Context.getPermissionsManager().getUser(userId);
} else {
throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
diff --git a/src/org/traccar/api/resource/StatisticsResource.java b/src/org/traccar/api/resource/StatisticsResource.java
new file mode 100644
index 000000000..e801d4ff3
--- /dev/null
+++ b/src/org/traccar/api/resource/StatisticsResource.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016 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.api.resource;
+
+import org.traccar.Context;
+import org.traccar.api.BaseResource;
+import org.traccar.helper.DateUtil;
+import org.traccar.model.Statistics;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import java.sql.SQLException;
+import java.util.Collection;
+
+@Path("statistics")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class StatisticsResource extends BaseResource {
+
+ @GET
+ public Collection<Statistics> get(
+ @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
+ Context.getPermissionsManager().checkAdmin(getUserId());
+ return Context.getDataManager().getStatistics(DateUtil.parseDate(from), DateUtil.parseDate(to));
+ }
+
+}
diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java
index 2d187fe9d..ddbca6b0f 100644
--- a/src/org/traccar/api/resource/UserResource.java
+++ b/src/org/traccar/api/resource/UserResource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -49,6 +49,7 @@ public class UserResource extends BaseResource {
public Response add(User entity) throws SQLException {
if (!Context.getPermissionsManager().isAdmin(getUserId())) {
Context.getPermissionsManager().checkRegistration(getUserId());
+ Context.getPermissionsManager().checkUserUpdate(getUserId(), new User(), entity);
}
Context.getPermissionsManager().addUser(entity);
if (Context.getNotificationManager() != null) {
@@ -59,12 +60,10 @@ public class UserResource extends BaseResource {
@Path("{id}")
@PUT
- public Response update(@PathParam("id") long id, User entity) throws SQLException {
- if (entity.getAdmin()) {
- Context.getPermissionsManager().checkAdmin(getUserId());
- } else {
- Context.getPermissionsManager().checkUser(getUserId(), entity.getId());
- }
+ public Response update(User entity) throws SQLException {
+ User before = Context.getPermissionsManager().getUser(entity.getId());
+ Context.getPermissionsManager().checkUser(getUserId(), entity.getId());
+ Context.getPermissionsManager().checkUserUpdate(getUserId(), before, entity);
Context.getPermissionsManager().updateUser(entity);
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refresh();
diff --git a/src/org/traccar/database/ActiveDevice.java b/src/org/traccar/database/ActiveDevice.java
index 3f2510af1..6109bc517 100644
--- a/src/org/traccar/database/ActiveDevice.java
+++ b/src/org/traccar/database/ActiveDevice.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/database/AliasesManager.java b/src/org/traccar/database/AliasesManager.java
new file mode 100644
index 000000000..4f4f09731
--- /dev/null
+++ b/src/org/traccar/database/AliasesManager.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.database;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.traccar.Context;
+import org.traccar.helper.Log;
+import org.traccar.model.AttributeAlias;
+
+public class AliasesManager {
+
+ private final DataManager dataManager;
+
+ private final Map<Long, Set<AttributeAlias>> deviceAliases = new ConcurrentHashMap<>();
+ private final Map<Long, AttributeAlias> aliasesById = new ConcurrentHashMap<>();
+
+ public AliasesManager(DataManager dataManager) {
+ this.dataManager = dataManager;
+ if (dataManager != null) {
+ try {
+ for (AttributeAlias attributeAlias : dataManager.getAttributeAliases()) {
+ getAttributeAliases(attributeAlias.getDeviceId())
+ .add(attributeAlias);
+ aliasesById.put(attributeAlias.getId(), attributeAlias);
+ }
+ } catch (SQLException error) {
+ Log.warning(error);
+ }
+ }
+ }
+
+ public Set<AttributeAlias> getAttributeAliases(long deviceId) {
+ if (!deviceAliases.containsKey(deviceId)) {
+ deviceAliases.put(deviceId, new HashSet<AttributeAlias>());
+ }
+ return deviceAliases.get(deviceId);
+ }
+
+ public void removeDevice(long deviceId) {
+ for (AttributeAlias attributeAlias : getAttributeAliases(deviceId)) {
+ aliasesById.remove(attributeAlias.getId());
+ }
+ deviceAliases.remove(deviceId);
+ }
+
+ public void addAttributeAlias(AttributeAlias attributeAlias) throws SQLException {
+ dataManager.addAttributeAlias(attributeAlias);
+ aliasesById.put(attributeAlias.getId(), attributeAlias);
+ getAttributeAliases(attributeAlias.getDeviceId()).add(attributeAlias);
+ }
+
+ public void updateAttributeAlias(AttributeAlias attributeAlias) throws SQLException {
+ dataManager.updateAttributeAlias(attributeAlias);
+ AttributeAlias cachedAlias = aliasesById.get(attributeAlias.getId());
+ if (cachedAlias.getDeviceId() != attributeAlias.getDeviceId()) {
+ getAttributeAliases(cachedAlias.getDeviceId()).remove(cachedAlias);
+ cachedAlias.setDeviceId(attributeAlias.getDeviceId());
+ getAttributeAliases(cachedAlias.getDeviceId()).add(cachedAlias);
+ }
+ cachedAlias.setAttribute(attributeAlias.getAttribute());
+ cachedAlias.setAlias(attributeAlias.getAlias());
+ }
+
+ public void removeArrtibuteAlias(long attributeAliasId) throws SQLException {
+ dataManager.removeAttributeAlias(attributeAliasId);
+ AttributeAlias cachedAlias = aliasesById.get(attributeAliasId);
+ getAttributeAliases(cachedAlias.getDeviceId()).remove(cachedAlias);
+ aliasesById.remove(attributeAliasId);
+ }
+
+ public AttributeAlias getAttributeAlias(long deviceId, String attribute) {
+ for (AttributeAlias alias : getAttributeAliases(deviceId)) {
+ if (alias.getAttribute().equals(attribute)) {
+ return alias;
+ }
+ }
+ return null;
+ }
+
+ public Collection<AttributeAlias> getAllAttributeAliases(long userId) {
+ Collection<AttributeAlias> userDevicesAliases = new ArrayList<>();
+ for (long deviceId : Context.getPermissionsManager().getDevicePermissions(userId)) {
+ userDevicesAliases.addAll(getAttributeAliases(deviceId));
+ }
+ return userDevicesAliases;
+ }
+
+ public AttributeAlias getAttributeAlias(long id) {
+ return aliasesById.get(id);
+ }
+
+}
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index 46ccab81e..bc44c31ae 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -40,6 +40,7 @@ public class ConnectionManager {
private static final long DEFAULT_TIMEOUT = 600;
private final long deviceTimeout;
+ private final boolean enableStatusEvents;
private final Map<Long, ActiveDevice> activeDevices = new HashMap<>();
private final Map<Long, Set<UpdateListener>> listeners = new HashMap<>();
@@ -47,6 +48,7 @@ public class ConnectionManager {
public ConnectionManager() {
deviceTimeout = Context.getConfig().getLong("status.timeout", DEFAULT_TIMEOUT) * 1000;
+ enableStatusEvents = Context.getConfig().getBoolean("event.statusHandler");
}
public void addActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
@@ -73,11 +75,20 @@ public class ConnectionManager {
return;
}
- if (!status.equals(device.getStatus())) {
- Event event = new Event(Event.TYPE_DEVICE_OFFLINE, deviceId);
- if (status.equals(Device.STATUS_ONLINE)) {
- event.setType(Event.TYPE_DEVICE_ONLINE);
+ if (enableStatusEvents && !status.equals(device.getStatus())) {
+ String eventType;
+ switch (status) {
+ case Device.STATUS_ONLINE:
+ eventType = Event.TYPE_DEVICE_ONLINE;
+ break;
+ case Device.STATUS_UNKNOWN:
+ eventType = Event.TYPE_DEVICE_UNKNOWN;
+ break;
+ default:
+ eventType = Event.TYPE_DEVICE_OFFLINE;
+ break;
}
+ Event event = new Event(eventType, deviceId);
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().updateEvent(event, null);
}
@@ -89,7 +100,6 @@ public class ConnectionManager {
timeout.cancel();
}
-
if (time != null) {
device.setLastUpdate(time);
}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index abc48f063..afa8b1677 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -37,6 +36,7 @@ import liquibase.resource.ResourceAccessor;
import org.traccar.Config;
import org.traccar.helper.Log;
+import org.traccar.model.AttributeAlias;
import org.traccar.model.Device;
import org.traccar.model.DevicePermission;
import org.traccar.model.Event;
@@ -47,6 +47,7 @@ import org.traccar.model.GroupPermission;
import org.traccar.model.Notification;
import org.traccar.model.Position;
import org.traccar.model.Server;
+import org.traccar.model.Statistics;
import org.traccar.model.User;
import org.traccar.model.DeviceGeofence;
import org.traccar.model.GeofencePermission;
@@ -158,12 +159,6 @@ public class DataManager {
.executeQuery(User.class);
}
- public User getUser(long userId) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectUser"))
- .setLong("id", userId)
- .executeQuerySingle(User.class);
- }
-
public void addUser(User user) throws SQLException {
user.setId(QueryBuilder.create(dataSource, getQuery("database.insertUser"), true)
.setObject(user)
@@ -336,33 +331,19 @@ public class DataManager {
.executeUpdate());
}
- public Collection<Event> getEvents(long deviceId, String type, Date from, Date to) throws SQLException {
+ public Collection<Event> getEvents(long deviceId, Date from, Date to) throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectEvents"))
.setLong("deviceId", deviceId)
- .setString("type", type)
.setDate("from", from)
.setDate("to", to)
.executeQuery(Event.class);
}
- public Collection<Event> getLastEvents(long deviceId, String type, int interval) throws SQLException {
- Calendar calendar = Calendar.getInstance();
- calendar.add(Calendar.SECOND, -interval);
- Date from = calendar.getTime();
- return getEvents(deviceId, type, from, new Date());
- }
-
public Collection<Geofence> getGeofences() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectGeofencesAll"))
.executeQuery(Geofence.class);
}
- public Geofence getGeofence(long geofenceId) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectGeofences"))
- .setLong("id", geofenceId)
- .executeQuerySingle(Geofence.class);
- }
-
public void addGeofence(Geofence geofence) throws SQLException {
geofence.setId(QueryBuilder.create(dataSource, getQuery("database.insertGeofence"), true)
.setObject(geofence)
@@ -460,4 +441,41 @@ public class DataManager {
.setLong("id", notification.getId())
.executeUpdate();
}
+
+ public Collection<AttributeAlias> getAttributeAliases() throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectAttributeAliases"))
+ .executeQuery(AttributeAlias.class);
+ }
+
+ public void addAttributeAlias(AttributeAlias attributeAlias) throws SQLException {
+ attributeAlias.setId(QueryBuilder.create(dataSource, getQuery("database.insertAttributeAlias"), true)
+ .setObject(attributeAlias)
+ .executeUpdate());
+ }
+
+ public void updateAttributeAlias(AttributeAlias attributeAlias) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.updateAttributeAlias"))
+ .setObject(attributeAlias)
+ .executeUpdate();
+ }
+
+ public void removeAttributeAlias(long attributeAliasId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.deleteAttributeAlias"))
+ .setLong("id", attributeAliasId)
+ .executeUpdate();
+ }
+
+ public Collection<Statistics> getStatistics(Date from, Date to) throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectStatistics"))
+ .setDate("from", from)
+ .setDate("to", to)
+ .executeQuery(Statistics.class);
+ }
+
+ public void addStatistics(Statistics statistics) throws SQLException {
+ statistics.setId(QueryBuilder.create(dataSource, getQuery("database.insertStatistics"), true)
+ .setObject(statistics)
+ .executeUpdate());
+ }
+
}
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index f32c7edd2..5681602fe 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -30,6 +30,7 @@ import org.traccar.Config;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
+import org.traccar.model.DeviceTotalDistance;
import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.model.Server;
@@ -428,4 +429,15 @@ public class DeviceManager implements IdentityManager {
}
return result;
}
+
+ public void resetTotalDistance(DeviceTotalDistance deviceTotalDistance) throws SQLException {
+ Position last = positions.get(deviceTotalDistance.getDeviceId());
+ if (last != null) {
+ last.getAttributes().put(Position.KEY_TOTAL_DISTANCE, deviceTotalDistance.getTotalDistance());
+ dataManager.addPosition(last);
+ updateLatestPosition(last);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
}
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index 74dff70f4..e2e0c12d4 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/database/GroupTree.java b/src/org/traccar/database/GroupTree.java
index 9062e7aa8..8798f55bc 100644
--- a/src/org/traccar/database/GroupTree.java
+++ b/src/org/traccar/database/GroupTree.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
index 8507d1f2e..db8e9c1c7 100644
--- a/src/org/traccar/database/IdentityManager.java
+++ b/src/org/traccar/database/IdentityManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 779f42483..7e79e289f 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -74,7 +74,6 @@ public class NotificationManager {
}
public void updateEvents(Collection<Event> events, Position position) {
-
for (Event event : events) {
updateEvent(event, position);
}
@@ -176,9 +175,8 @@ public class NotificationManager {
}
public Set<Notification> getAllNotifications() {
-
Set<Notification> notifications = new HashSet<>();
- long id = 0;
+ long id = 1;
Field[] fields = Event.class.getDeclaredFields();
for (Field field : fields) {
if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("TYPE_")) {
@@ -194,4 +192,5 @@ public class NotificationManager {
}
return notifications;
}
+
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index f5fed978a..078a5f935 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -29,6 +29,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -39,6 +40,7 @@ public class PermissionsManager {
private volatile Server server;
private final Map<Long, User> users = new ConcurrentHashMap<>();
+ private final Map<String, Long> usersTokens = new HashMap<>();
private final Map<Long, Set<Long>> groupPermissions = new HashMap<>();
private final Map<Long, Set<Long>> devicePermissions = new HashMap<>();
@@ -81,10 +83,14 @@ public class PermissionsManager {
public final void refreshUsers() {
users.clear();
+ usersTokens.clear();
try {
server = dataManager.getServer();
for (User user : dataManager.getUsers()) {
users.put(user.getId(), user);
+ if (user.getToken() != null) {
+ usersTokens.put(user.getToken(), user.getId());
+ }
}
} catch (SQLException error) {
Log.warning(error);
@@ -140,6 +146,37 @@ public class PermissionsManager {
}
}
+ public boolean isReadonly(long userId) {
+ return users.containsKey(userId) && users.get(userId).getReadonly();
+ }
+
+ public void checkReadonly(long userId) throws SecurityException {
+ if (!isAdmin(userId) && (server.getReadonly() || isReadonly(userId))) {
+ throw new SecurityException("Account is readonly");
+ }
+ }
+
+ public void checkUserEnabled(long userId) throws SecurityException {
+ User user = getUser(userId);
+ if (user.getDisabled()) {
+ throw new SecurityException("Account is disabled");
+ }
+ if (user.getExpirationTime() != null && System.currentTimeMillis() > user.getExpirationTime().getTime()) {
+ throw new SecurityException("Account has expired");
+ }
+ }
+
+ public void checkUserUpdate(long userId, User before, User after) throws SecurityException {
+ if (before.getAdmin() != after.getAdmin()
+ || before.getReadonly() != after.getReadonly()
+ || before.getDisabled() != after.getDisabled()
+ || before.getDeviceLimit() != after.getDeviceLimit()
+ || !Objects.equals(before.getExpirationTime(), after.getExpirationTime())
+ || !Objects.equals(before.getToken(), after.getToken())) {
+ checkAdmin(userId);
+ }
+ }
+
public void checkUser(long userId, long otherUserId) throws SecurityException {
if (userId != otherUserId) {
checkAdmin(userId);
@@ -164,12 +201,6 @@ public class PermissionsManager {
}
}
- public void checkReadonly(long userId) {
- if (server.getReadonly() && !isAdmin(userId)) {
- throw new SecurityException("Readonly user");
- }
- }
-
public void checkGeofence(long userId, long geofenceId) throws SecurityException {
if (!Context.getGeofenceManager().checkGeofence(userId, geofenceId) && !isAdmin(userId)) {
throw new SecurityException("Geofence access denied");
@@ -196,28 +227,43 @@ public class PermissionsManager {
public void addUser(User user) throws SQLException {
dataManager.addUser(user);
users.put(user.getId(), user);
+ if (user.getToken() != null) {
+ usersTokens.put(user.getToken(), user.getId());
+ }
refreshPermissions();
}
public void updateUser(User user) throws SQLException {
dataManager.updateUser(user);
+ User old = users.get(user.getId());
users.put(user.getId(), user);
+ if (user.getToken() != null) {
+ usersTokens.put(user.getToken(), user.getId());
+ }
+ if (old.getToken() != null && !old.getToken().equals(user.getToken())) {
+ usersTokens.remove(old.getToken());
+ }
refreshPermissions();
}
public void removeUser(long userId) throws SQLException {
dataManager.removeUser(userId);
+ usersTokens.remove(users.get(userId).getToken());
users.remove(userId);
refreshPermissions();
}
public User login(String email, String password) throws SQLException {
User user = dataManager.login(email, password);
- if (user != null && users.get(user.getId()) != null) {
+ if (user != null) {
+ checkUserEnabled(user.getId());
return users.get(user.getId());
- } else {
- return null;
}
+ return null;
+ }
+
+ public User getUserByToken(String token) {
+ return users.get(usersTokens.get(token));
}
}
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index 1a83daab9..50d689a2a 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java
new file mode 100644
index 000000000..5b0aa5f41
--- /dev/null
+++ b/src/org/traccar/database/StatisticsManager.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2016 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.database;
+
+import org.traccar.Context;
+import org.traccar.helper.Log;
+import org.traccar.model.Statistics;
+
+import java.sql.SQLException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+public class StatisticsManager {
+
+ private static final int SPLIT_MODE = Calendar.DAY_OF_MONTH;
+
+ private int lastUpdate = Calendar.getInstance().get(SPLIT_MODE);
+
+ private Set<Long> users = new HashSet<>();
+ private Set<Long> devices = new HashSet<>();
+
+ private int requests;
+ private int messagesReceived;
+ private int messagesStored;
+
+ private void checkSplit() {
+ int currentUpdate = Calendar.getInstance().get(SPLIT_MODE);
+ if (lastUpdate != currentUpdate) {
+ Statistics statistics = new Statistics();
+ statistics.setCaptureTime(new Date());
+ statistics.setActiveUsers(users.size());
+ statistics.setActiveDevices(devices.size());
+ statistics.setRequests(requests);
+ statistics.setMessagesReceived(messagesReceived);
+ statistics.setMessagesStored(messagesStored);
+
+ try {
+ Context.getDataManager().addStatistics(statistics);
+ } catch (SQLException e) {
+ Log.warning(e);
+ }
+
+ users.clear();
+ devices.clear();
+ requests = 0;
+ messagesReceived = 0;
+ messagesStored = 0;
+ lastUpdate = currentUpdate;
+ }
+ }
+
+ public synchronized void registerRequest(long userId) {
+ checkSplit();
+ requests += 1;
+ if (userId != 0) {
+ users.add(userId);
+ }
+ }
+
+ public synchronized void registerMessageReceived() {
+ checkSplit();
+ messagesReceived += 1;
+ }
+
+ public synchronized void registerMessageStored(long deviceId) {
+ checkSplit();
+ messagesStored += 1;
+ if (deviceId != 0) {
+ devices.add(deviceId);
+ }
+ }
+
+}
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
index 61c2d7b16..296fe488c 100644
--- a/src/org/traccar/events/AlertEventHandler.java
+++ b/src/org/traccar/events/AlertEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java
index 3f4ff521b..aaa1d23f0 100644
--- a/src/org/traccar/events/CommandResultEventHandler.java
+++ b/src/org/traccar/events/CommandResultEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
index 6126331bd..d31e516ef 100644
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ b/src/org/traccar/events/GeofenceEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
index e241e450b..b52083f57 100644
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ b/src/org/traccar/events/IgnitionEventHandler.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index 33c7735cd..db19535a0 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 57f60d864..c3e3e19cb 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/geocode/Address.java b/src/org/traccar/geocode/Address.java
index 144a49474..d77602f2c 100644
--- a/src/org/traccar/geocode/Address.java
+++ b/src/org/traccar/geocode/Address.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/geocode/AddressFormat.java b/src/org/traccar/geocode/AddressFormat.java
index a2a0862bf..8046abfd7 100644
--- a/src/org/traccar/geocode/AddressFormat.java
+++ b/src/org/traccar/geocode/AddressFormat.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/geocode/GeocodeFarmReverseGeocoder.java b/src/org/traccar/geocode/GeocodeFarmReverseGeocoder.java
index 306fc25b8..477eec15b 100644
--- a/src/org/traccar/geocode/GeocodeFarmReverseGeocoder.java
+++ b/src/org/traccar/geocode/GeocodeFarmReverseGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/geocode/GisgraphyReverseGeocoder.java b/src/org/traccar/geocode/GisgraphyReverseGeocoder.java
index 18f59c7b0..dd5e1ff5b 100644
--- a/src/org/traccar/geocode/GisgraphyReverseGeocoder.java
+++ b/src/org/traccar/geocode/GisgraphyReverseGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java
index 1f607df78..b9835440e 100644
--- a/src/org/traccar/geocode/GoogleReverseGeocoder.java
+++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java
index dcc880ef9..c107d24e8 100644
--- a/src/org/traccar/geocode/JsonReverseGeocoder.java
+++ b/src/org/traccar/geocode/JsonReverseGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/geocode/NominatimReverseGeocoder.java b/src/org/traccar/geocode/NominatimReverseGeocoder.java
index c1481d1cb..0fbeaef83 100644
--- a/src/org/traccar/geocode/NominatimReverseGeocoder.java
+++ b/src/org/traccar/geocode/NominatimReverseGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 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.
diff --git a/src/org/traccar/geocode/OpenCageReverseGeocoder.java b/src/org/traccar/geocode/OpenCageReverseGeocoder.java
index b5b31179e..df447d59e 100644
--- a/src/org/traccar/geocode/OpenCageReverseGeocoder.java
+++ b/src/org/traccar/geocode/OpenCageReverseGeocoder.java
@@ -1,6 +1,6 @@
/*
* Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com)
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/geocode/ReverseGeocoder.java b/src/org/traccar/geocode/ReverseGeocoder.java
index 5d985fb31..e2641fa37 100644
--- a/src/org/traccar/geocode/ReverseGeocoder.java
+++ b/src/org/traccar/geocode/ReverseGeocoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2013 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.
diff --git a/src/org/traccar/geofence/GeofenceCircle.java b/src/org/traccar/geofence/GeofenceCircle.java
index a36620aec..d78734714 100644
--- a/src/org/traccar/geofence/GeofenceCircle.java
+++ b/src/org/traccar/geofence/GeofenceCircle.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/geofence/GeofenceGeometry.java b/src/org/traccar/geofence/GeofenceGeometry.java
index e717ede0b..6b5b0acb7 100644
--- a/src/org/traccar/geofence/GeofenceGeometry.java
+++ b/src/org/traccar/geofence/GeofenceGeometry.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/geofence/GeofencePolygon.java b/src/org/traccar/geofence/GeofencePolygon.java
index 33d91c0ff..03638d6c9 100644
--- a/src/org/traccar/geofence/GeofencePolygon.java
+++ b/src/org/traccar/geofence/GeofencePolygon.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/helper/BcdUtil.java b/src/org/traccar/helper/BcdUtil.java
index a248daf22..495f94104 100644
--- a/src/org/traccar/helper/BcdUtil.java
+++ b/src/org/traccar/helper/BcdUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/helper/BitUtil.java b/src/org/traccar/helper/BitUtil.java
index 31271a691..b6108edff 100644
--- a/src/org/traccar/helper/BitUtil.java
+++ b/src/org/traccar/helper/BitUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index 2a4b1191d..f08292392 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
@@ -194,10 +194,19 @@ public final class Checksum {
return checksum;
}
+ public static int xor(String string) {
+ byte checksum = 0;
+ for (byte b : string.getBytes(StandardCharsets.US_ASCII)) {
+ checksum ^= b;
+ }
+ return checksum;
+ }
+
public static String nmea(String msg) {
int checksum = 0;
- for (byte b : msg.getBytes(StandardCharsets.US_ASCII)) {
- checksum ^= b;
+ byte[] bytes = msg.getBytes(StandardCharsets.US_ASCII);
+ for (int i = 1; i < bytes.length; i++) {
+ checksum ^= bytes[i];
}
return String.format("*%02x", checksum).toUpperCase();
}
diff --git a/src/org/traccar/helper/DateBuilder.java b/src/org/traccar/helper/DateBuilder.java
index c52210326..6e1b779f0 100644
--- a/src/org/traccar/helper/DateBuilder.java
+++ b/src/org/traccar/helper/DateBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -92,6 +92,11 @@ public class DateBuilder {
return this;
}
+ public DateBuilder addSeconds(long seconds) {
+ calendar.setTimeInMillis(calendar.getTimeInMillis() + seconds * 1000);
+ return this;
+ }
+
public DateBuilder setMillis(int millis) {
calendar.set(Calendar.MILLISECOND, millis);
return this;
diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java
index 0dca88a2b..ad8534eb8 100644
--- a/src/org/traccar/helper/DateUtil.java
+++ b/src/org/traccar/helper/DateUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -18,8 +18,13 @@ package org.traccar.helper;
import java.util.Calendar;
import java.util.Date;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+
public final class DateUtil {
+ private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime();
+
private DateUtil() {
}
@@ -55,4 +60,8 @@ public final class DateUtil {
return calendar.getTime();
}
+ public static Date parseDate(String value) {
+ return DATE_FORMAT.parseDateTime(value).toDate();
+ }
+
}
diff --git a/src/org/traccar/helper/DistanceCalculator.java b/src/org/traccar/helper/DistanceCalculator.java
index d191a27af..3452597ab 100644
--- a/src/org/traccar/helper/DistanceCalculator.java
+++ b/src/org/traccar/helper/DistanceCalculator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java
index 38ae5813e..55086bac7 100644
--- a/src/org/traccar/helper/Hashing.java
+++ b/src/org/traccar/helper/Hashing.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/helper/LocationTree.java b/src/org/traccar/helper/LocationTree.java
index 5e16fc095..3aff3ce33 100644
--- a/src/org/traccar/helper/LocationTree.java
+++ b/src/org/traccar/helper/LocationTree.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
index d13210a17..d74246a64 100644
--- a/src/org/traccar/helper/Log.java
+++ b/src/org/traccar/helper/Log.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -49,6 +49,10 @@ public final class Log {
private static Logger logger = null;
+ public static String getAppVersion() {
+ return Log.class.getPackage().getImplementationVersion();
+ }
+
public static void setupLogger(Config config) throws IOException {
Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
@@ -72,7 +76,7 @@ public final class Log {
});
Log.logSystemInfo();
- Log.info("Version: " + Log.class.getPackage().getImplementationVersion());
+ Log.info("Version: " + getAppVersion());
}
public static Logger getLogger() {
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
index 3196c25e4..aea23ca60 100644
--- a/src/org/traccar/helper/ObdDecoder.java
+++ b/src/org/traccar/helper/ObdDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -60,7 +60,7 @@ public final class ObdDecoder {
StringBuilder codes = new StringBuilder();
for (int i = 0; i < value.length() / 4; i++) {
int numValue = Integer.parseInt(value.substring(i * 4, (i + 1) * 4), 16);
- codes.append(',');
+ codes.append(' ');
switch (numValue >> 14) {
case 1:
codes.append('C');
@@ -78,7 +78,7 @@ public final class ObdDecoder {
codes.append(String.format("%04X", numValue & 0x3FFF));
}
if (codes.length() > 0) {
- return createEntry("dtcs", codes.toString().replaceFirst(",", ""));
+ return createEntry(Position.KEY_DTCS, codes.toString().trim());
} else {
return null;
}
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java
index dcea1c8f7..d64993ccb 100644
--- a/src/org/traccar/helper/Parser.java
+++ b/src/org/traccar/helper/Parser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -155,7 +155,7 @@ public class Parser {
}
if (hemisphere != null && (hemisphere.equals("S") || hemisphere.equals("W") || hemisphere.equals("-"))) {
- coordinate = -coordinate;
+ coordinate = -Math.abs(coordinate);
}
return coordinate;
diff --git a/src/org/traccar/helper/PatternBuilder.java b/src/org/traccar/helper/PatternBuilder.java
index 1e7613043..f3de5c1e5 100644
--- a/src/org/traccar/helper/PatternBuilder.java
+++ b/src/org/traccar/helper/PatternBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java
index f665eb30d..12536eaef 100644
--- a/src/org/traccar/helper/PatternUtil.java
+++ b/src/org/traccar/helper/PatternUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -33,6 +33,18 @@ public final class PatternUtil {
public String getPatternMatch() {
return patternMatch;
}
+
+ public String getPatternTail() {
+ return patternTail;
+ }
+
+ public String getStringMatch() {
+ return stringMatch;
+ }
+
+ public String getStringTail() {
+ return stringTail;
+ }
}
public static MatchResult checkPattern(String pattern, String input) {
diff --git a/src/org/traccar/helper/StringFinder.java b/src/org/traccar/helper/StringFinder.java
index 6c1dafcfd..2fa0aa9a4 100644
--- a/src/org/traccar/helper/StringFinder.java
+++ b/src/org/traccar/helper/StringFinder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/helper/UnitsConverter.java b/src/org/traccar/helper/UnitsConverter.java
index 4bc7348db..00b00861e 100644
--- a/src/org/traccar/helper/UnitsConverter.java
+++ b/src/org/traccar/helper/UnitsConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -45,6 +45,10 @@ public final class UnitsConverter {
return value * KNOTS_TO_MPS_RATIO;
}
+ public static double mpsFromKnots(double value) {
+ return value / KNOTS_TO_MPS_RATIO;
+ }
+
public static double knotsFromCps(double value) { // cm/s
return value * KNOTS_TO_CPS_RATIO;
}
diff --git a/src/org/traccar/location/BaseLocationProvider.java b/src/org/traccar/location/BaseLocationProvider.java
index 7778cc0c5..d228685e2 100644
--- a/src/org/traccar/location/BaseLocationProvider.java
+++ b/src/org/traccar/location/BaseLocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/location/CellInfo.java b/src/org/traccar/location/CellInfo.java
new file mode 100644
index 000000000..2257cb1e8
--- /dev/null
+++ b/src/org/traccar/location/CellInfo.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2016 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.location;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.traccar.Config;
+import org.traccar.Context;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+public class CellInfo {
+
+ @JsonInclude(JsonInclude.Include.NON_DEFAULT)
+ public static class Cell {
+
+ private int mcc;
+ private int mnc;
+ private int lac;
+ private int cid;
+ private int signal;
+
+ public Cell() {
+ }
+
+ public Cell(int mcc, int mnc, int lac, int cid, int signal) {
+ this.mcc = mcc;
+ this.mnc = mnc;
+ this.lac = lac;
+ this.cid = cid;
+ this.signal = signal;
+ }
+
+ public int getMcc() {
+ return mcc;
+ }
+
+ public void setMcc(int mcc) {
+ this.mcc = mcc;
+ }
+
+ public int getMnc() {
+ return mnc;
+ }
+
+ public void setMnc(int mnc) {
+ this.mnc = mnc;
+ }
+
+ public int getLac() {
+ return lac;
+ }
+
+ public void setLac(int lac) {
+ this.lac = lac;
+ }
+
+ public int getCid() {
+ return cid;
+ }
+
+ public void setCid(int cid) {
+ this.cid = cid;
+ }
+
+ public int getSignal() {
+ return signal;
+ }
+
+ public void setSignal(int signal) {
+ this.signal = signal;
+ }
+ }
+
+ public CellInfo() {
+ }
+
+ public CellInfo(Collection<Cell> cells) {
+ this.cells.addAll(cells);
+ }
+
+ private List<Cell> cells = new ArrayList<>();
+
+ public List<Cell> getCells() {
+ return cells;
+ }
+
+ public void addCell(int lac, int cid) {
+ Config config = Context.getConfig();
+ if (config.hasKey("location.mcc") && config.hasKey("location.mnc")) {
+ int mcc = config.getInteger("location.mcc");
+ int mnc = config.getInteger("location.mnc");
+ cells.add(new Cell(mcc, mnc, lac, cid, 0));
+ }
+ }
+
+ public void addCell(int mcc, int mnc, int lac, int cid) {
+ cells.add(new Cell(mcc, mnc, lac, cid, 0));
+ }
+
+ @Override
+ public String toString() {
+ try {
+ return new ObjectMapper().writeValueAsString(cells);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static CellInfo fromString(String json) {
+ try {
+ return new CellInfo(Arrays.asList(new ObjectMapper().readValue(json, Cell[].class)));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/src/org/traccar/location/LocationProvider.java b/src/org/traccar/location/LocationProvider.java
index 2bff1a7ca..cc445c2b3 100644
--- a/src/org/traccar/location/LocationProvider.java
+++ b/src/org/traccar/location/LocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/location/MozillaLocationProvider.java b/src/org/traccar/location/MozillaLocationProvider.java
index d30fbf642..37040a95e 100644
--- a/src/org/traccar/location/MozillaLocationProvider.java
+++ b/src/org/traccar/location/MozillaLocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/location/OpenCellIdLocationProvider.java b/src/org/traccar/location/OpenCellIdLocationProvider.java
index 94cc1a4e4..d5d1b0ace 100644
--- a/src/org/traccar/location/OpenCellIdLocationProvider.java
+++ b/src/org/traccar/location/OpenCellIdLocationProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/model/AttributeAlias.java b/src/org/traccar/model/AttributeAlias.java
new file mode 100644
index 000000000..2835c0558
--- /dev/null
+++ b/src/org/traccar/model/AttributeAlias.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.model;
+
+public class AttributeAlias {
+
+ private long id;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ private long deviceId;
+
+ public long getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(long deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ private String attribute;
+
+ public String getAttribute() {
+ return attribute;
+ }
+
+ public void setAttribute(String attribute) {
+ this.attribute = attribute;
+ }
+
+ private String alias;
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+}
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
index 67c624fcd..51a61b966 100644
--- a/src/org/traccar/model/Command.java
+++ b/src/org/traccar/model/Command.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java
index e90742836..e492a6120 100644
--- a/src/org/traccar/model/Device.java
+++ b/src/org/traccar/model/Device.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -101,4 +101,44 @@ public class Device extends Extensible {
public void setGeofenceIds(List<Long> geofenceIds) {
this.geofenceIds = geofenceIds;
}
+
+ private String phone;
+
+ public String getPhone() {
+ return phone;
+ }
+
+ public void setPhone(String phone) {
+ this.phone = phone;
+ }
+
+ private String model;
+
+ public String getModel() {
+ return model;
+ }
+
+ public void setModel(String model) {
+ this.model = model;
+ }
+
+ private String contact;
+
+ public String getContact() {
+ return contact;
+ }
+
+ public void setContact(String contact) {
+ this.contact = contact;
+ }
+
+ private String category;
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
}
diff --git a/src/org/traccar/model/DeviceGeofence.java b/src/org/traccar/model/DeviceGeofence.java
index 05f06bb3d..00c99add6 100644
--- a/src/org/traccar/model/DeviceGeofence.java
+++ b/src/org/traccar/model/DeviceGeofence.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/DevicePermission.java b/src/org/traccar/model/DevicePermission.java
index b3bc0cae0..c62173132 100644
--- a/src/org/traccar/model/DevicePermission.java
+++ b/src/org/traccar/model/DevicePermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/model/DeviceTotalDistance.java b/src/org/traccar/model/DeviceTotalDistance.java
new file mode 100644
index 000000000..4c89b7689
--- /dev/null
+++ b/src/org/traccar/model/DeviceTotalDistance.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.model;
+
+public class DeviceTotalDistance {
+
+ private long deviceId;
+
+ public long getDeviceId() {
+ return deviceId;
+ }
+
+ public void setDeviceId(long deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ private double totalDistance;
+
+ public double getTotalDistance() {
+ return totalDistance;
+ }
+
+ public void setTotalDistance(double totalDistance) {
+ this.totalDistance = totalDistance;
+ }
+
+}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index c3c8b5320..3dc4778e1 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -35,9 +35,12 @@ public class Event extends Message {
public Event() {
}
+ public static final String ALL_EVENTS = "allEvents";
+
public static final String TYPE_COMMAND_RESULT = "commandResult";
public static final String TYPE_DEVICE_ONLINE = "deviceOnline";
+ public static final String TYPE_DEVICE_UNKNOWN = "deviceUnknown";
public static final String TYPE_DEVICE_OFFLINE = "deviceOffline";
public static final String TYPE_DEVICE_MOVING = "deviceMoving";
diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java
index eceeccadf..efe60fb75 100644
--- a/src/org/traccar/model/Extensible.java
+++ b/src/org/traccar/model/Extensible.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/Geofence.java b/src/org/traccar/model/Geofence.java
index 9a60f784f..ecfd3101c 100644
--- a/src/org/traccar/model/Geofence.java
+++ b/src/org/traccar/model/Geofence.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/GeofencePermission.java b/src/org/traccar/model/GeofencePermission.java
index 269918d66..464f4e9eb 100644
--- a/src/org/traccar/model/GeofencePermission.java
+++ b/src/org/traccar/model/GeofencePermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/Group.java b/src/org/traccar/model/Group.java
index e70b3f3d5..c21d43127 100644
--- a/src/org/traccar/model/Group.java
+++ b/src/org/traccar/model/Group.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/GroupGeofence.java b/src/org/traccar/model/GroupGeofence.java
index 0e261fd54..736e6c704 100644
--- a/src/org/traccar/model/GroupGeofence.java
+++ b/src/org/traccar/model/GroupGeofence.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/GroupPermission.java b/src/org/traccar/model/GroupPermission.java
index 9b0011575..59b41b049 100644
--- a/src/org/traccar/model/GroupPermission.java
+++ b/src/org/traccar/model/GroupPermission.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/Message.java b/src/org/traccar/model/Message.java
index 55d9fd0c7..ab472202b 100644
--- a/src/org/traccar/model/Message.java
+++ b/src/org/traccar/model/Message.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java
index 9bb856400..6194a998f 100644
--- a/src/org/traccar/model/MiscFormatter.java
+++ b/src/org/traccar/model/MiscFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/model/Notification.java b/src/org/traccar/model/Notification.java
index 0664d6a00..64e1ac60c 100644
--- a/src/org/traccar/model/Notification.java
+++ b/src/org/traccar/model/Notification.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index c1058aef9..b2965c89c 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -35,6 +35,7 @@ public class Position extends Message {
public static final String KEY_OUTPUT = "output";
public static final String KEY_POWER = "power";
public static final String KEY_BATTERY = "battery";
+ public static final String KEY_CELL_TOWERS = "cellTowers";
public static final String KEY_MCC = "mcc";
public static final String KEY_MNC = "mnc";
public static final String KEY_LAC = "lac";
@@ -59,6 +60,7 @@ public class Position extends Message {
public static final String KEY_ARMED = "armed";
public static final String KEY_ACCURACY = "accuracy";
+ public static final String KEY_DTCS = "dtcs";
public static final String KEY_OBD_SPEED = "obdSpeed";
public static final String KEY_OBD_ODOMETER = "obdOdometer";
@@ -81,6 +83,8 @@ public class Position extends Message {
public static final String ALARM_LOW_BATTERY = "lowBattery";
public static final String ALARM_FAULT = "fault";
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_GEOFENCE = "geofence";
public static final String ALARM_GEOFENCE_ENTER = "geofenceEnter";
public static final String ALARM_GEOFENCE_EXIT = "geofenceExit";
@@ -91,6 +95,8 @@ public class Position extends Message {
public static final String ALARM_BREAKING = "hardBreaking";
public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving";
public static final String ALARM_POWER_CUT = "powerCut";
+ public static final String ALARM_JAMMING = "jamming";
+ public static final String ALARM_TEMPERATURE = "temperature";
private String protocol;
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
index b1557bf8f..5cf26f7f2 100644
--- a/src/org/traccar/model/Server.java
+++ b/src/org/traccar/model/Server.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -15,8 +15,17 @@
*/
package org.traccar.model;
+import org.traccar.helper.Log;
+
public class Server extends Extensible {
+ public String getVersion() {
+ return Log.getAppVersion();
+ }
+
+ public void setVersion(String version) {
+ }
+
private boolean registration;
public boolean getRegistration() {
@@ -127,4 +136,24 @@ public class Server extends Extensible {
this.twelveHourFormat = twelveHourFormat;
}
+ private boolean forceSettings;
+
+ public boolean getForceSettings() {
+ return forceSettings;
+ }
+
+ public void setForceSettings(boolean forceSettings) {
+ this.forceSettings = forceSettings;
+ }
+
+ private String coordinateFormat;
+
+ public String getCoordinateFormat() {
+ return coordinateFormat;
+ }
+
+ public void setCoordinateFormat(String coordinateFormat) {
+ this.coordinateFormat = coordinateFormat;
+ }
+
}
diff --git a/src/org/traccar/model/Statistics.java b/src/org/traccar/model/Statistics.java
new file mode 100644
index 000000000..f458ddfad
--- /dev/null
+++ b/src/org/traccar/model/Statistics.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2016 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.model;
+
+import java.util.Date;
+
+public class Statistics extends Extensible {
+
+ private Date captureTime;
+
+ public Date getCaptureTime() {
+ if (captureTime != null) {
+ return new Date(captureTime.getTime());
+ } else {
+ return null;
+ }
+ }
+
+ public void setCaptureTime(Date captureTime) {
+ if (captureTime != null) {
+ this.captureTime = new Date(captureTime.getTime());
+ } else {
+ this.captureTime = null;
+ }
+ }
+
+ private int activeUsers;
+
+ public int getActiveUsers() {
+ return activeUsers;
+ }
+
+ public void setActiveUsers(int activeUsers) {
+ this.activeUsers = activeUsers;
+ }
+
+ private int activeDevices;
+
+ public int getActiveDevices() {
+ return activeDevices;
+ }
+
+ public void setActiveDevices(int activeDevices) {
+ this.activeDevices = activeDevices;
+ }
+
+ private int requests;
+
+ public int getRequests() {
+ return requests;
+ }
+
+ public void setRequests(int requests) {
+ this.requests = requests;
+ }
+
+ private int messagesReceived;
+
+ public int getMessagesReceived() {
+ return messagesReceived;
+ }
+
+ public void setMessagesReceived(int messagesReceived) {
+ this.messagesReceived = messagesReceived;
+ }
+
+ private int messagesStored;
+
+ public int getMessagesStored() {
+ return messagesStored;
+ }
+
+ public void setMessagesStored(int messagesStored) {
+ this.messagesStored = messagesStored;
+ }
+
+}
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index aa73cfcff..e6b9d663f 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -18,6 +18,8 @@ package org.traccar.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.traccar.helper.Hashing;
+import java.util.Date;
+
public class User extends Extensible {
private String name;
@@ -130,14 +132,76 @@ public class User extends Extensible {
this.twelveHourFormat = twelveHourFormat;
}
- private String password;
+ private String coordinateFormat;
+
+ public String getCoordinateFormat() {
+ return coordinateFormat;
+ }
+
+ public void setCoordinateFormat(String coordinateFormat) {
+ this.coordinateFormat = coordinateFormat;
+ }
+
+ private boolean disabled;
+
+ public boolean getDisabled() {
+ return disabled;
+ }
+
+ public void setDisabled(boolean disabled) {
+ this.disabled = disabled;
+ }
+
+ private Date expirationTime;
+
+ public Date getExpirationTime() {
+ if (expirationTime != null) {
+ return new Date(expirationTime.getTime());
+ } else {
+ return null;
+ }
+ }
+
+ public void setExpirationTime(Date expirationTime) {
+ if (expirationTime != null) {
+ this.expirationTime = new Date(expirationTime.getTime());
+ } else {
+ this.expirationTime = null;
+ }
+ }
+
+ private int deviceLimit;
+
+ public int getDeviceLimit() {
+ return deviceLimit;
+ }
+
+ public void setDeviceLimit(int deviceLimit) {
+ this.deviceLimit = deviceLimit;
+ }
+
+ private String token;
+
+ public String getToken() {
+ return token;
+ }
+
+ public void setToken(String token) {
+ if (token != null && !token.isEmpty()) {
+ if (!token.matches("^[a-zA-Z0-9]{16,}$")) {
+ throw new IllegalArgumentException("Illegal token");
+ }
+ this.token = token;
+ } else {
+ this.token = null;
+ }
+ }
public String getPassword() {
- return password;
+ return null;
}
public void setPassword(String password) {
- this.password = password;
if (password != null && !password.isEmpty()) {
Hashing.HashingResult hashingResult = Hashing.createHash(password);
hashedPassword = hashingResult.getHash();
diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java
index 3bd7e5cf5..9bd116339 100644
--- a/src/org/traccar/notification/EventForwarder.java
+++ b/src/org/traccar/notification/EventForwarder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -50,7 +50,7 @@ public final class EventForwarder {
BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url);
- requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8");
+ requestBuilder.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
requestBuilder.addHeader("User-Agent", USER_AGENT);
if (!header.equals("")) {
String[] headerLines = header.split("\\r?\\n");
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index 059f532cf..2355d1793 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java
index f8449e7d2..c7c1d689c 100644
--- a/src/org/traccar/notification/NotificationMail.java
+++ b/src/org/traccar/notification/NotificationMail.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -24,11 +24,9 @@ import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
-import org.traccar.Config;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Event;
-import org.traccar.model.Extensible;
import org.traccar.model.Position;
import org.traccar.model.User;
@@ -37,106 +35,86 @@ public final class NotificationMail {
private NotificationMail() {
}
- private static Properties getConfigProperies() {
- Config config = Context.getConfig();
- Properties result = new Properties();
- String host = config.getString("mail.smtp.host", null);
+ private static Properties getProperties(PropertiesProvider provider) {
+ Properties properties = new Properties();
+ String host = provider.getString("mail.smtp.host");
if (host != null) {
- result.put("mail.smtp.host", host);
- result.put("mail.smtp.port", config.getString("mail.smtp.port", "25"));
+ properties.put("mail.transport.protocol", provider.getString("mail.transport.protocol", "smtp"));
+ properties.put("mail.smtp.host", host);
+ properties.put("mail.smtp.port", provider.getString("mail.smtp.port", "25"));
- if (config.getBoolean("mail.smtp.starttls.enable")) {
- result.put("mail.smtp.starttls.enable", config.getBoolean("mail.smtp.starttls.enable"));
- } else if (config.getBoolean("mail.smtp.ssl.enable")) {
- result.put("mail.smtp.ssl.enable", config.getBoolean("mail.smtp.ssl.enable"));
+ String starttlsEnable = provider.getString("mail.smtp.starttls.enable");
+ if (starttlsEnable != null) {
+ properties.put("mail.smtp.starttls.enable", Boolean.parseBoolean(starttlsEnable));
}
- result.put("mail.smtp.ssl.trust", config.getBoolean("mail.smtp.ssl.trust"));
-
- result.put("mail.smtp.auth", config.getBoolean("mail.smtp.auth"));
-
- String username = config.getString("mail.smtp.username");
- if (username != null) {
- result.put("mail.smtp.user", username);
+ String starttlsRequired = provider.getString("mail.smtp.starttls.required");
+ if (starttlsRequired != null) {
+ properties.put("mail.smtp.starttls.required", Boolean.parseBoolean(starttlsRequired));
}
- String password = config.getString("mail.smtp.password");
- if (password != null) {
- result.put("mail.smtp.password", password);
- }
- String from = config.getString("mail.smtp.from");
- if (from != null) {
- result.put("mail.smtp.from", from);
- }
- }
- return result;
- }
- private static Properties getAttributesProperties(Extensible object) {
- Properties result = new Properties();
-
- if (object.getAttributes().containsKey("mail.smtp.host")) {
- result.put("mail.smtp.host", object.getAttributes().get("mail.smtp.host"));
- String port = (String) object.getAttributes().get("mail.smtp.port");
- result.put("mail.smtp.port", (port != null) ? port : "25");
- if (object.getAttributes().containsKey("mail.smtp.starttls.enable")) {
- boolean tls = Boolean.parseBoolean((String) object.getAttributes().get("mail.smtp.starttls.enable"));
- result.put("mail.smtp.starttls.enable", tls);
- } else if (object.getAttributes().containsKey("mail.smtp.ssl.enable")) {
- boolean ssl = Boolean.parseBoolean((String) object.getAttributes().get("mail.smtp.ssl.enable"));
- result.put("mail.smtp.ssl.enable", ssl);
+ String sslEnable = provider.getString("mail.smtp.ssl.enable");
+ if (sslEnable != null) {
+ properties.put("mail.smtp.ssl.enable", Boolean.parseBoolean(sslEnable));
}
- if (object.getAttributes().containsKey("mail.smtp.ssl.trust")) {
- result.put("mail.smtp.ssl.trust", object.getAttributes().get("mail.smtp.ssl.trust"));
+ String sslTrust = provider.getString("mail.smtp.ssl.trust");
+ if (sslTrust != null) {
+ properties.put("mail.smtp.ssl.trust", sslTrust);
}
- boolean auth = Boolean.parseBoolean((String) object.getAttributes().get("mail.smtp.auth"));
- result.put("mail.smtp.auth", auth);
- if (object.getAttributes().containsKey("mail.smtp.username")) {
- result.put("mail.smtp.username", object.getAttributes().get("mail.smtp.username"));
+ properties.put("mail.smtp.auth", provider.getString("mail.smtp.auth"));
+
+ String username = provider.getString("mail.smtp.username");
+ if (username != null) {
+ properties.put("mail.smtp.username", username);
}
- if (object.getAttributes().containsKey("mail.smtp.password")) {
- result.put("mail.smtp.password", object.getAttributes().get("mail.smtp.password"));
+ String password = provider.getString("mail.smtp.password");
+ if (password != null) {
+ properties.put("mail.smtp.password", password);
}
- if (object.getAttributes().containsKey("mail.smtp.from")) {
- result.put("mail.smtp.from", object.getAttributes().get("mail.smtp.from"));
+ String from = provider.getString("mail.smtp.from");
+ if (from != null) {
+ properties.put("mail.smtp.from", from);
}
}
- return result;
+ return properties;
}
- public static void sendMailSync(long userId, Event event, Position position) {
-
- Properties mailServerProperties;
- Session mailSession;
- MimeMessage mailMessage;
-
+ private static void sendMailSync(long userId, Event event, Position position) {
try {
User user = Context.getPermissionsManager().getUser(userId);
- mailServerProperties = getConfigProperies();
- if (!mailServerProperties.containsKey("mail.smtp.host")) {
- mailServerProperties = getAttributesProperties(user);
- if (!mailServerProperties.containsKey("mail.smtp.host")) {
+ Properties properties = getProperties(new PropertiesProvider(Context.getConfig()));
+ if (!properties.containsKey("mail.smtp.host")) {
+ properties = getProperties(new PropertiesProvider(user));
+ if (!properties.containsKey("mail.smtp.host")) {
+ Log.warning("No SMTP configuration found");
return;
}
}
- mailSession = Session.getInstance(mailServerProperties, null);
- mailMessage = new MimeMessage(mailSession);
+ Session session = Session.getInstance(properties);
- if (mailServerProperties.getProperty("mail.smtp.from") != null) {
- mailMessage.setFrom(new InternetAddress(mailServerProperties.getProperty("mail.smtp.from")));
- }
+ MimeMessage message = new MimeMessage(session);
- mailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
- mailMessage.setSubject(NotificationFormatter.formatTitle(userId, event, position));
- mailMessage.setText(NotificationFormatter.formatMessage(userId, event, position));
+ String from = properties.getProperty("mail.smtp.from");
+ if (from != null) {
+ message.setFrom(new InternetAddress(from));
+ }
- Transport transport = mailSession.getTransport("smtp");
- transport.connect(mailServerProperties.getProperty("mail.smtp.host"),
- mailServerProperties.getProperty("mail.smtp.username"),
- mailServerProperties.getProperty("mail.smtp.password"));
- transport.sendMessage(mailMessage, mailMessage.getAllRecipients());
- transport.close();
+ message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
+ message.setSubject(NotificationFormatter.formatTitle(userId, event, position));
+ message.setText(NotificationFormatter.formatMessage(userId, event, position));
+
+ Transport transport = session.getTransport();
+ try {
+ transport.connect(
+ properties.getProperty("mail.smtp.host"),
+ properties.getProperty("mail.smtp.username"),
+ properties.getProperty("mail.smtp.password"));
+ transport.sendMessage(message, message.getAllRecipients());
+ } finally {
+ transport.close();
+ }
} catch (MessagingException error) {
Log.warning(error);
@@ -144,12 +122,11 @@ public final class NotificationMail {
}
public static void sendMailAsync(final long userId, final Event event, final Position position) {
- Runnable runnableSend = new Runnable() {
+ new Thread(new Runnable() {
public void run() {
sendMailSync(userId, event, position);
}
- };
-
- new Thread(runnableSend).start();
+ }).start();
}
+
}
diff --git a/src/org/traccar/notification/PropertiesProvider.java b/src/org/traccar/notification/PropertiesProvider.java
new file mode 100644
index 000000000..9136288f8
--- /dev/null
+++ b/src/org/traccar/notification/PropertiesProvider.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 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.notification;
+
+import org.traccar.Config;
+import org.traccar.model.Extensible;
+
+public class PropertiesProvider {
+
+ private Config config;
+
+ private Extensible extensible;
+
+ public PropertiesProvider(Config config) {
+ this.config = config;
+ }
+
+ public PropertiesProvider(Extensible extensible) {
+ this.extensible = extensible;
+ }
+
+ public String getString(String key) {
+ if (config != null) {
+ return config.getString(key);
+ } else {
+ return (String) extensible.getAttributes().get(key);
+ }
+ }
+
+ public String getString(String key, String defaultValue) {
+ String value = getString(key);
+ if (value == null) {
+ value = defaultValue;
+ }
+ return value;
+ }
+
+}
diff --git a/src/org/traccar/protocol/AdmProtocol.java b/src/org/traccar/protocol/AdmProtocol.java
index 067ccf053..442121f0a 100644
--- a/src/org/traccar/protocol/AdmProtocol.java
+++ b/src/org/traccar/protocol/AdmProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AdmProtocolDecoder.java b/src/org/traccar/protocol/AdmProtocolDecoder.java
index e234e3f0b..72a6e5bce 100644
--- a/src/org/traccar/protocol/AdmProtocolDecoder.java
+++ b/src/org/traccar/protocol/AdmProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 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.
diff --git a/src/org/traccar/protocol/ApelProtocol.java b/src/org/traccar/protocol/ApelProtocol.java
index 47bce37a0..690b5ed99 100644
--- a/src/org/traccar/protocol/ApelProtocol.java
+++ b/src/org/traccar/protocol/ApelProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
index f10c4b5b1..aa58e478f 100644
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ b/src/org/traccar/protocol/ApelProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 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.
diff --git a/src/org/traccar/protocol/AplicomFrameDecoder.java b/src/org/traccar/protocol/AplicomFrameDecoder.java
index 8a896535c..785d90767 100644
--- a/src/org/traccar/protocol/AplicomFrameDecoder.java
+++ b/src/org/traccar/protocol/AplicomFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/AplicomProtocol.java b/src/org/traccar/protocol/AplicomProtocol.java
index 5155133c9..80f6f528f 100644
--- a/src/org/traccar/protocol/AplicomProtocol.java
+++ b/src/org/traccar/protocol/AplicomProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index abd30ee45..8c06aad6f 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -81,7 +81,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
private static final int EVENT_DATA = 119;
- private void decodeEventData(int event, ChannelBuffer buf) {
+ private void decodeEventData(Position position, ChannelBuffer buf, int event) {
switch (event) {
case 2:
case 40:
@@ -108,6 +108,9 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
case 130:
buf.readUnsignedInt(); // incorrect
break;
+ case 188:
+ decodeEB(position, buf);
+ break;
default:
break;
}
@@ -283,7 +286,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
if ((selector & 0x1000) != 0) {
- decodeEventData(event, buf);
+ decodeEventData(position, buf, event);
}
if (Context.getConfig().getBoolean(getProtocolName() + ".can")
@@ -348,6 +351,150 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private void decodeH(Position position, ChannelBuffer buf, int selector) {
+
+ if ((selector & 0x0004) != 0) {
+ getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
+ } else {
+ getLastLocation(position, null);
+ }
+
+ if ((selector & 0x0040) != 0) {
+ buf.readUnsignedInt(); // reset time
+ }
+
+ if ((selector & 0x2000) != 0) {
+ buf.readUnsignedShort(); // snapshot counter
+ }
+
+ int index = 1;
+ while (buf.readableBytes() > 0) {
+
+ position.set("h" + index + "Index", buf.readUnsignedByte());
+
+ buf.readUnsignedShort(); // length
+
+ int n = buf.readUnsignedByte();
+ int m = buf.readUnsignedByte();
+
+ position.set("h" + index + "XLength", n);
+ position.set("h" + index + "YLength", m);
+
+ if ((selector & 0x0008) != 0) {
+ position.set("h" + index + "XType", buf.readUnsignedByte());
+ position.set("h" + index + "YType", buf.readUnsignedByte());
+ position.set("h" + index + "Parameters", buf.readUnsignedByte());
+ }
+
+ boolean percentageFormat = (selector & 0x0020) != 0;
+
+ StringBuilder data = new StringBuilder();
+ for (int i = 0; i < n * m; i++) {
+ if (percentageFormat) {
+ data.append(buf.readUnsignedByte() * 0.5).append("%").append(" ");
+ } else {
+ data.append(buf.readUnsignedShort()).append(" ");
+ }
+ }
+
+ position.set("h" + index + "Data", data.toString().trim());
+
+ position.set("h" + index + "Total", buf.readUnsignedInt());
+
+ if ((selector & 0x0010) != 0) {
+ int k = buf.readUnsignedByte();
+
+ data = new StringBuilder();
+ for (int i = 1; i < n; i++) {
+ if (k == 1) {
+ data.append(buf.readByte()).append(" ");
+ } else if (k == 2) {
+ data.append(buf.readShort()).append(" ");
+ }
+ }
+ position.set("h" + index + "XLimits", data.toString().trim());
+
+ data = new StringBuilder();
+ for (int i = 1; i < m; i++) {
+ if (k == 1) {
+ data.append(buf.readByte()).append(" ");
+ } else if (k == 2) {
+ data.append(buf.readShort()).append(" ");
+ }
+ }
+ position.set("h" + index + "YLimits", data.toString().trim());
+ }
+
+ index += 1;
+ }
+ }
+
+ private void decodeEB(Position position, ChannelBuffer buf) {
+
+ if (buf.readByte() != (byte) 'E' || buf.readByte() != (byte) 'B') {
+ return;
+ }
+
+ buf.readUnsignedByte(); // version
+ buf.readUnsignedShort(); // event
+ buf.readUnsignedByte(); // data validity
+ buf.readUnsignedByte(); // towed
+ buf.readUnsignedShort(); // length
+
+ while (buf.readableBytes() > 0) {
+ buf.readUnsignedByte(); // towed position
+ int type = buf.readUnsignedByte();
+ int length = buf.readUnsignedByte();
+
+ if (type == 0x01) {
+ position.set("brakeFlags", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x02) {
+ position.set("wheelSpeed", buf.readUnsignedShort() / 256.0);
+ position.set("wheelSpeedDifference", buf.readUnsignedShort() / 256.0 - 125.0);
+ position.set("lateralAcceleration", buf.readUnsignedByte() / 10.0 - 12.5);
+ position.set("vehicleSpeed", buf.readUnsignedShort() / 256.0);
+ } else if (type == 0x03) {
+ position.set("axleLoadSum", buf.readUnsignedShort() * 2);
+ } else if (type == 0x04) {
+ position.set("tyrePressure", buf.readUnsignedByte() * 10);
+ position.set("pneumaticPressure", buf.readUnsignedByte() * 5);
+ } else if (type == 0x05) {
+ position.set("brakeLining", buf.readUnsignedByte() * 0.4);
+ position.set("brakeTemperature", buf.readUnsignedByte() * 10);
+ } else if (type == 0x06) {
+ position.set("totalDistance", buf.readUnsignedInt() * 5);
+ position.set("tripDistance", buf.readUnsignedInt() * 5);
+ position.set("serviceDistance", (buf.readUnsignedInt() - 2105540607) * 5);
+ } else if (type == 0x0A) {
+ position.set("brakeData", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x0B) {
+ position.set("brakeMinMaxData", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x0C) {
+ position.set("missingPgn", ChannelBuffers.hexDump(buf.readBytes(length)));
+ } else if (type == 0x0D) {
+ switch (buf.readUnsignedByte()) {
+ case 1:
+ position.set("brakeManufacturer", "Wabco");
+ break;
+ case 2:
+ position.set("brakeManufacturer", "Knorr");
+ break;
+ case 3:
+ position.set("brakeManufacturer", "Haldex");
+ break;
+ default:
+ position.set("brakeManufacturer", "Unknown");
+ break;
+ }
+ buf.readUnsignedByte();
+ buf.readBytes(17); // vin
+ position.set("towedDetectionStatus", buf.readUnsignedByte());
+ } else if (type == 0x0E) {
+ buf.skipBytes(length);
+ }
+ }
+ }
+
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -389,6 +536,8 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
decodeD(position, buf, selector, event);
} else if (protocol == 'E') {
decodeE(position, buf, selector);
+ } else if (protocol == 'H') {
+ decodeH(position, buf, selector);
} else {
return null;
}
diff --git a/src/org/traccar/protocol/AppelloProtocol.java b/src/org/traccar/protocol/AppelloProtocol.java
index b129a7520..8581850a1 100755
--- a/src/org/traccar/protocol/AppelloProtocol.java
+++ b/src/org/traccar/protocol/AppelloProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/AppelloProtocolDecoder.java b/src/org/traccar/protocol/AppelloProtocolDecoder.java
index 4535464ed..02c966834 100755
--- a/src/org/traccar/protocol/AppelloProtocolDecoder.java
+++ b/src/org/traccar/protocol/AppelloProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/AquilaProtocol.java b/src/org/traccar/protocol/AquilaProtocol.java
index 9607edd55..c1de71cd3 100644
--- a/src/org/traccar/protocol/AquilaProtocol.java
+++ b/src/org/traccar/protocol/AquilaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java
index 514448d9b..1ce763463 100644
--- a/src/org/traccar/protocol/AquilaProtocolDecoder.java
+++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Ardi01Protocol.java b/src/org/traccar/protocol/Ardi01Protocol.java
index 5b7770647..446592bd0 100644
--- a/src/org/traccar/protocol/Ardi01Protocol.java
+++ b/src/org/traccar/protocol/Ardi01Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -37,8 +37,8 @@ public class Ardi01Protocol extends BaseProtocol {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("objectDecoder", new Ardi01ProtocolDecoder(Ardi01Protocol.this));
}
});
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
index 1eaa65d84..71beb7d1d 100644
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/ArknavProtocol.java b/src/org/traccar/protocol/ArknavProtocol.java
index 6b9398f68..c22e5f443 100644
--- a/src/org/traccar/protocol/ArknavProtocol.java
+++ b/src/org/traccar/protocol/ArknavProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java
index 6c6edc905..d6abd4134 100644
--- a/src/org/traccar/protocol/ArknavProtocolDecoder.java
+++ b/src/org/traccar/protocol/ArknavProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ArknavX8Protocol.java b/src/org/traccar/protocol/ArknavX8Protocol.java
index 3b78a27ff..e759b5294 100644
--- a/src/org/traccar/protocol/ArknavX8Protocol.java
+++ b/src/org/traccar/protocol/ArknavX8Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
index c0a18311e..214ccfae2 100644
--- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
+++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ArnaviProtocol.java b/src/org/traccar/protocol/ArnaviProtocol.java
index 29661b8d4..956f2329a 100644
--- a/src/org/traccar/protocol/ArnaviProtocol.java
+++ b/src/org/traccar/protocol/ArnaviProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
index f7e146172..1215f7bad 100644
--- a/src/org/traccar/protocol/ArnaviProtocolDecoder.java
+++ b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AstraProtocol.java b/src/org/traccar/protocol/AstraProtocol.java
index 461888c4f..87c562a9d 100644
--- a/src/org/traccar/protocol/AstraProtocol.java
+++ b/src/org/traccar/protocol/AstraProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java
index d89a21082..390434d54 100644
--- a/src/org/traccar/protocol/AstraProtocolDecoder.java
+++ b/src/org/traccar/protocol/AstraProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -22,6 +22,7 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -82,7 +83,9 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder {
int reason = buf.readUnsignedMedium();
position.set(Position.KEY_EVENT, reason);
- position.set(Position.KEY_STATUS, buf.readUnsignedShort());
+ int status = buf.readUnsignedShort();
+ position.set(Position.KEY_STATUS, status);
+
position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedByte());
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
@@ -101,7 +104,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // geofence events
- if (BitUtil.check(reason, 6) || BitUtil.check(reason, 7)) {
+ if (BitUtil.check(status, 8)) {
position.set(Position.KEY_RFID, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000);
@@ -110,7 +113,10 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder {
}
- // extra data
+ if (BitUtil.check(status, 6)) {
+ Log.warning("Extension data is not supported");
+ return position;
+ }
positions.add(position);
diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java
index d1010daeb..a075254ea 100644
--- a/src/org/traccar/protocol/AtrackFrameDecoder.java
+++ b/src/org/traccar/protocol/AtrackFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 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.
diff --git a/src/org/traccar/protocol/AtrackProtocol.java b/src/org/traccar/protocol/AtrackProtocol.java
index d61d31522..2ab33ea6d 100644
--- a/src/org/traccar/protocol/AtrackProtocol.java
+++ b/src/org/traccar/protocol/AtrackProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index cb89f9438..9c34a2e78 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/AuroProtocol.java b/src/org/traccar/protocol/AuroProtocol.java
index e5635f12a..e1b23478f 100644
--- a/src/org/traccar/protocol/AuroProtocol.java
+++ b/src/org/traccar/protocol/AuroProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AuroProtocolDecoder.java b/src/org/traccar/protocol/AuroProtocolDecoder.java
index 428e83f99..26bf7dfc8 100644
--- a/src/org/traccar/protocol/AuroProtocolDecoder.java
+++ b/src/org/traccar/protocol/AuroProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java
index 2c547d822..2fa1b4072 100644
--- a/src/org/traccar/protocol/AutoFonFrameDecoder.java
+++ b/src/org/traccar/protocol/AutoFonFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
* Copyright 2015 Vitaly Litvak (vitavaque@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/src/org/traccar/protocol/AutoFonProtocol.java b/src/org/traccar/protocol/AutoFonProtocol.java
index 3e61b81a3..927bda120 100644
--- a/src/org/traccar/protocol/AutoFonProtocol.java
+++ b/src/org/traccar/protocol/AutoFonProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index 90e8ca103..1c618fdee 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
* Copyright 2015 Vitaly Litvak (vitavaque@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/src/org/traccar/protocol/AutoGradeProtocol.java b/src/org/traccar/protocol/AutoGradeProtocol.java
index 1fb6b1ce2..41bb8d9ad 100644
--- a/src/org/traccar/protocol/AutoGradeProtocol.java
+++ b/src/org/traccar/protocol/AutoGradeProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
index 5c9dd7ece..d8fe8b1a2 100644
--- a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -43,7 +44,7 @@ public class AutoGradeProtocolDecoder extends BaseProtocolDecoder {
.number("([d.]{5})") // speed
.number("(dd)(dd)(dd)") // time
.number("([d.]{6})") // course
- .expression(".") // status
+ .expression("(.)") // status
.number("A(xxxx)")
.number("B(xxxx)")
.number("C(xxxx)")
@@ -88,6 +89,10 @@ public class AutoGradeProtocolDecoder extends BaseProtocolDecoder {
position.setCourse(parser.nextDouble());
+ int status = (byte) parser.next().charAt(0);
+ position.set(Position.KEY_STATUS, status);
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 0));
+
for (int i = 1; i <= 5; i++) {
position.set(Position.PREFIX_ADC + i, parser.next());
}
diff --git a/src/org/traccar/protocol/Avl301Protocol.java b/src/org/traccar/protocol/Avl301Protocol.java
index b8453cfb3..4a217bad6 100644
--- a/src/org/traccar/protocol/Avl301Protocol.java
+++ b/src/org/traccar/protocol/Avl301Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
index 818dd94df..cac6f717f 100644
--- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/BceFrameDecoder.java b/src/org/traccar/protocol/BceFrameDecoder.java
index 1f8b8efcd..4fac79f85 100644
--- a/src/org/traccar/protocol/BceFrameDecoder.java
+++ b/src/org/traccar/protocol/BceFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/BceProtocol.java b/src/org/traccar/protocol/BceProtocol.java
index 576eb6862..5374fd0e1 100644
--- a/src/org/traccar/protocol/BceProtocol.java
+++ b/src/org/traccar/protocol/BceProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
index 06290b6b0..dace89659 100644
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/org/traccar/protocol/BceProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/BlackKiteProtocol.java b/src/org/traccar/protocol/BlackKiteProtocol.java
index ea5120b2b..db32f5328 100644
--- a/src/org/traccar/protocol/BlackKiteProtocol.java
+++ b/src/org/traccar/protocol/BlackKiteProtocol.java
@@ -1,6 +1,6 @@
/*
* Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com)
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
index c2c051884..86736c4c9 100644
--- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
+++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
* Copyright 2015 Vijay Kumar (vijaykumar@zilogic.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/src/org/traccar/protocol/BoxProtocol.java b/src/org/traccar/protocol/BoxProtocol.java
index 6e60a0dd8..36e7790f0 100644
--- a/src/org/traccar/protocol/BoxProtocol.java
+++ b/src/org/traccar/protocol/BoxProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
index 55d3142b2..b1fe55e5e 100644
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/BoxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 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.
diff --git a/src/org/traccar/protocol/CalAmpProtocol.java b/src/org/traccar/protocol/CalAmpProtocol.java
index a8eb59d0e..a3577f10c 100644
--- a/src/org/traccar/protocol/CalAmpProtocol.java
+++ b/src/org/traccar/protocol/CalAmpProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index 47d7bf483..510684411 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -121,7 +121,7 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
if (type != MSG_MINI_EVENT_REPORT) {
- buf.readUnsignedByte(); // reserved
+ position.set("append", buf.readUnsignedByte());
}
if (accType == 1) {
diff --git a/src/org/traccar/protocol/CarTrackProtocol.java b/src/org/traccar/protocol/CarTrackProtocol.java
index 0244c0ce1..d235c92be 100644
--- a/src/org/traccar/protocol/CarTrackProtocol.java
+++ b/src/org/traccar/protocol/CarTrackProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
index 0d21e77e6..94f5d208b 100644
--- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 Anton Tananaev (anton@traccar.org)
* Copyright 2014 Rohit
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/src/org/traccar/protocol/CarcellProtocol.java b/src/org/traccar/protocol/CarcellProtocol.java
index 1303b56b3..e53a10eb5 100644
--- a/src/org/traccar/protocol/CarcellProtocol.java
+++ b/src/org/traccar/protocol/CarcellProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java
index e9b6cdf28..5f5877852 100644
--- a/src/org/traccar/protocol/CarcellProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarcellProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/CarcellProtocolEncoder.java b/src/org/traccar/protocol/CarcellProtocolEncoder.java
index d01a11e52..0846949c4 100644
--- a/src/org/traccar/protocol/CarcellProtocolEncoder.java
+++ b/src/org/traccar/protocol/CarcellProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/CarscopProtocol.java b/src/org/traccar/protocol/CarscopProtocol.java
index 23c597a5b..01a754027 100644
--- a/src/org/traccar/protocol/CarscopProtocol.java
+++ b/src/org/traccar/protocol/CarscopProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java
index 5e1973ae8..9abfe2f86 100644
--- a/src/org/traccar/protocol/CarscopProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java
index 42f7cbb88..db9df0674 100644
--- a/src/org/traccar/protocol/CastelProtocol.java
+++ b/src/org/traccar/protocol/CastelProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 47df3735c..790dcd932 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -73,27 +73,27 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final short MSG_SC_LOGIN = 0x1001;
- private static final short MSG_SC_LOGIN_RESPONSE = (short) 0x9001;
- private static final short MSG_SC_LOGOUT = 0x1002;
- private static final short MSG_SC_HEARTBEAT = 0x1003;
- private static final short MSG_SC_HEARTBEAT_RESPONSE = (short) 0x9003;
- private static final short MSG_SC_GPS = 0x4001;
- private static final short MSG_SC_PID_DATA = 0x4002;
- private static final short MSG_SC_SUPPORTED_PID = 0x4004;
- private static final short MSG_SC_OBD_DATA = 0x4005;
- private static final short MSG_SC_DTCS_PASSENGER = 0x4006;
- private static final short MSG_SC_DTCS_COMMERCIAL = 0x400B;
- private static final short MSG_SC_ALARM = 0x4007;
- private static final short MSG_SC_CELL = 0x4008;
- private static final short MSG_SC_GPS_SLEEP = 0x4009;
- private static final short MSG_SC_AGPS_REQUEST = 0x5101;
- private static final short MSG_SC_CURRENT_LOCATION = (short) 0xB001;
-
- private static final short MSG_CC_LOGIN = 0x4001;
- private static final short MSG_CC_LOGIN_RESPONSE = (short) 0x8001;
- private static final short MSG_CC_HEARTBEAT = 0x4206;
- private static final short MSG_CC_HEARTBEAT_RESPONSE = (short) 0x8206;
+ public static final short MSG_SC_LOGIN = 0x1001;
+ public static final short MSG_SC_LOGIN_RESPONSE = (short) 0x9001;
+ public static final short MSG_SC_LOGOUT = 0x1002;
+ public static final short MSG_SC_HEARTBEAT = 0x1003;
+ public static final short MSG_SC_HEARTBEAT_RESPONSE = (short) 0x9003;
+ public static final short MSG_SC_GPS = 0x4001;
+ public static final short MSG_SC_PID_DATA = 0x4002;
+ public static final short MSG_SC_SUPPORTED_PID = 0x4004;
+ public static final short MSG_SC_OBD_DATA = 0x4005;
+ public static final short MSG_SC_DTCS_PASSENGER = 0x4006;
+ public static final short MSG_SC_DTCS_COMMERCIAL = 0x400B;
+ public static final short MSG_SC_ALARM = 0x4007;
+ public static final short MSG_SC_CELL = 0x4008;
+ public static final short MSG_SC_GPS_SLEEP = 0x4009;
+ public static final short MSG_SC_AGPS_REQUEST = 0x5101;
+ public static final short MSG_SC_CURRENT_LOCATION = (short) 0xB001;
+
+ public static final short MSG_CC_LOGIN = 0x4001;
+ public static final short MSG_CC_LOGIN_RESPONSE = (short) 0x8001;
+ public static final short MSG_CC_HEARTBEAT = 0x4206;
+ public static final short MSG_CC_HEARTBEAT_RESPONSE = (short) 0x8206;
private Position readPosition(DeviceSession deviceSession, ChannelBuffer buf) {
diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java
index c9cfab99e..b4708f5db 100644
--- a/src/org/traccar/protocol/CellocatorFrameDecoder.java
+++ b/src/org/traccar/protocol/CellocatorFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java
index 6d8eea8f5..bfaf03692 100644
--- a/src/org/traccar/protocol/CellocatorProtocol.java
+++ b/src/org/traccar/protocol/CellocatorProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -15,6 +15,7 @@
*/
package org.traccar.protocol;
+import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.traccar.BaseProtocol;
@@ -40,6 +41,15 @@ public class CellocatorProtocol extends BaseProtocol {
};
server.setEndianness(ByteOrder.LITTLE_ENDIAN);
serverList.add(server);
+
+ server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
+ }
+ };
+ server.setEndianness(ByteOrder.LITTLE_ENDIAN);
+ serverList.add(server);
}
}
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index f074cb5d3..14325e619 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java
index 1e6d212c8..460bd331f 100644
--- a/src/org/traccar/protocol/CguardProtocol.java
+++ b/src/org/traccar/protocol/CguardProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
index 1646363e5..c5dc51d81 100644
--- a/src/org/traccar/protocol/CguardProtocolDecoder.java
+++ b/src/org/traccar/protocol/CguardProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -33,7 +33,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_NV = new PatternBuilder()
.text("NV:")
.number("(dd)(dd)(dd) ") // date
.number("(dd)(dd)(dd):") // time
@@ -45,23 +45,16 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
.number("(?:NAN|(d+.?d*))") // altitude
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) {
- getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1));
- return null;
- }
+ private static final Pattern PATTERN_BC = new PatternBuilder()
+ .text("BC:")
+ .number("(dd)(dd)(dd) ") // date
+ .number("(dd)(dd)(dd):") // time
+ .expression("(.+)") // data
+ .compile();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
+ private Position decodePosition(DeviceSession deviceSession, String sentence) {
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN_NV, sentence);
if (!parser.matches()) {
return null;
}
@@ -88,4 +81,72 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeStatus(DeviceSession deviceSession, String sentence) {
+
+ Parser parser = new Parser(PATTERN_BC, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ String[] data = parser.next().split(":");
+ for (int i = 0; i < data.length / 2; i++) {
+ String key = data[i * 2];
+ String value = data[i * 2 + 1];
+ switch (key) {
+ case "CSQ1":
+ position.set(Position.KEY_GSM, Integer.parseInt(value));
+ break;
+ case "NSQ1":
+ position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
+ break;
+ case "BAT1":
+ position.set(Position.KEY_BATTERY, Integer.parseInt(value) + "%");
+ break;
+ case "PWR1":
+ position.set(Position.KEY_POWER, Double.parseDouble(value));
+ break;
+ default:
+ position.set(key.toLowerCase(), value);
+ break;
+ }
+ }
+
+ return position;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ if (sentence.startsWith("ID:") || sentence.startsWith("IDRO:")) {
+ getDeviceSession(channel, remoteAddress, sentence.substring(sentence.indexOf(':') + 1));
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ if (sentence.startsWith("NV:")) {
+ return decodePosition(deviceSession, sentence);
+ } else if (sentence.startsWith("BC:")) {
+ return decodeStatus(deviceSession, sentence);
+ }
+
+ return null;
+ }
+
}
diff --git a/src/org/traccar/protocol/CityeasyProtocol.java b/src/org/traccar/protocol/CityeasyProtocol.java
index e22c964ce..c5ad05fcd 100644
--- a/src/org/traccar/protocol/CityeasyProtocol.java
+++ b/src/org/traccar/protocol/CityeasyProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
index 5cdbe525d..9f2a0250d 100644
--- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
index 9c5695001..0c149c1c9 100644
--- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/CradlepointProtocol.java b/src/org/traccar/protocol/CradlepointProtocol.java
index 9b8de7fb8..6ed54aa17 100644
--- a/src/org/traccar/protocol/CradlepointProtocol.java
+++ b/src/org/traccar/protocol/CradlepointProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
index 4532172c0..f46459482 100644
--- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java
+++ b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/DishaProtocol.java b/src/org/traccar/protocol/DishaProtocol.java
index 612316112..53ba36004 100644
--- a/src/org/traccar/protocol/DishaProtocol.java
+++ b/src/org/traccar/protocol/DishaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/DishaProtocolDecoder.java b/src/org/traccar/protocol/DishaProtocolDecoder.java
index eb00700d8..dc8bddd38 100644
--- a/src/org/traccar/protocol/DishaProtocolDecoder.java
+++ b/src/org/traccar/protocol/DishaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/EasyTrackProtocol.java b/src/org/traccar/protocol/EasyTrackProtocol.java
index 86ec530d4..eeed07129 100644
--- a/src/org/traccar/protocol/EasyTrackProtocol.java
+++ b/src/org/traccar/protocol/EasyTrackProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -36,7 +36,7 @@ public class EasyTrackProtocol extends BaseProtocol {
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#'));
+ pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "#", "\r\n"));
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectDecoder", new EasyTrackProtocolDecoder(EasyTrackProtocol.this));
diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
index cec68b967..688629063 100644
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/EelinkProtocol.java b/src/org/traccar/protocol/EelinkProtocol.java
index 4da051159..5900f0059 100644
--- a/src/org/traccar/protocol/EelinkProtocol.java
+++ b/src/org/traccar/protocol/EelinkProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
+import org.traccar.model.Command;
import java.util.List;
@@ -27,6 +28,11 @@ public class EelinkProtocol extends BaseProtocol {
public EelinkProtocol() {
super("eelink");
+ setSupportedCommands(
+ Command.TYPE_CUSTOM,
+ Command.TYPE_ENGINE_STOP,
+ Command.TYPE_ENGINE_RESUME,
+ Command.TYPE_REBOOT_DEVICE);
}
@Override
@@ -35,6 +41,7 @@ public class EelinkProtocol extends BaseProtocol {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2));
+ pipeline.addLast("objectEncoder", new EelinkProtocolEncoder());
pipeline.addLast("objectDecoder", new EelinkProtocolDecoder(EelinkProtocol.this));
}
});
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index 87d706aff..0bf7d229b 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 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.
@@ -40,7 +40,7 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_STATE = 0x05;
public static final int MSG_SMS = 0x06;
public static final int MSG_OBD = 0x07;
- public static final int MSG_INTERACTIVE = 0x80;
+ public static final int MSG_DOWNLINK = 0x80;
public static final int MSG_DATA = 0x81;
public static final int MSG_NORMAL = 0x12;
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
new file mode 100644
index 000000000..b9d6b6f97
--- /dev/null
+++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.traccar.BaseProtocolEncoder;
+import org.traccar.helper.Log;
+import org.traccar.model.Command;
+
+import java.nio.charset.StandardCharsets;
+
+public class EelinkProtocolEncoder extends BaseProtocolEncoder {
+
+ private ChannelBuffer encodeContent(String content) {
+
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
+
+ buf.writeByte(0x67);
+ buf.writeByte(0x67);
+ buf.writeByte(EelinkProtocolDecoder.MSG_DOWNLINK);
+ buf.writeShort(2 + 1 + 4 + content.length()); // length
+ buf.writeShort(0); // index
+
+ buf.writeByte(0x01); // command
+ buf.writeInt(0); // server id
+ buf.writeBytes(content.getBytes(StandardCharsets.UTF_8));
+
+ return buf;
+ }
+
+ @Override
+ protected Object encodeCommand(Command command) {
+
+ switch (command.getType()) {
+ case Command.TYPE_CUSTOM:
+ return encodeContent((String) command.getAttributes().get(Command.KEY_DATA));
+ case Command.TYPE_ENGINE_STOP:
+ return encodeContent("RELAY,1#");
+ case Command.TYPE_ENGINE_RESUME:
+ return encodeContent("RELAY,0#");
+ case Command.TYPE_REBOOT_DEVICE:
+ return encodeContent("RESET#");
+ default:
+ Log.warning(new UnsupportedOperationException(command.getType()));
+ break;
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/EnforaProtocol.java b/src/org/traccar/protocol/EnforaProtocol.java
index f4ca505ca..156e09d67 100644
--- a/src/org/traccar/protocol/EnforaProtocol.java
+++ b/src/org/traccar/protocol/EnforaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java
index e9a32da2d..3c4473200 100644
--- a/src/org/traccar/protocol/EnforaProtocolDecoder.java
+++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
diff --git a/src/org/traccar/protocol/ExtremTracProtocol.java b/src/org/traccar/protocol/ExtremTracProtocol.java
new file mode 100644
index 000000000..d9b178e23
--- /dev/null
+++ b/src/org/traccar/protocol/ExtremTracProtocol.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 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 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 java.util.List;
+
+public class ExtremTracProtocol extends BaseProtocol {
+
+ public ExtremTracProtocol() {
+ super("extremtrac");
+ }
+
+ @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("stringDecoder", new StringDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectDecoder", new ExtremTracProtocolDecoder(ExtremTracProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/ExtremTracProtocolDecoder.java b/src/org/traccar/protocol/ExtremTracProtocolDecoder.java
new file mode 100644
index 000000000..c2f420d1c
--- /dev/null
+++ b/src/org/traccar/protocol/ExtremTracProtocolDecoder.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.regex.Pattern;
+
+public class ExtremTracProtocolDecoder extends BaseProtocolDecoder {
+
+ public ExtremTracProtocolDecoder(ExtremTracProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("$GPRMC,")
+ .number("(d+),") // device id
+ .number("(dd)(dd)(dd).d+,") // time
+ .expression("([AV]),") // validity
+ .number("(d+)(dd.d+),") // latitude
+ .expression("([NS]),")
+ .number("(d+)(dd.d+),") // longitude
+ .expression("([EW]),")
+ .number("(d+.d+),") // speed
+ .number("(d+.d+),") // course
+ .number("(dd)(dd)(dd),") // date
+ .any()
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextCoordinate());
+ position.setLongitude(parser.nextCoordinate());
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/FifotrackProtocol.java b/src/org/traccar/protocol/FifotrackProtocol.java
new file mode 100644
index 000000000..f4ca450c0
--- /dev/null
+++ b/src/org/traccar/protocol/FifotrackProtocol.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016 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 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.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class FifotrackProtocol extends BaseProtocol {
+
+ public FifotrackProtocol() {
+ super("fifotrack");
+ }
+
+ @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("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new FifotrackProtocolDecoder(FifotrackProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
new file mode 100644
index 000000000..9243d1894
--- /dev/null
+++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+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 FifotrackProtocolDecoder extends BaseProtocolDecoder {
+
+ public FifotrackProtocolDecoder(FifotrackProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("$$")
+ .number("d+,") // length
+ .number("(d+),") // imei
+ .number("x+,") // index
+ .expression("[^,]+,") // type
+ .number("(d+)?,") // alarm
+ .number("(dd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd),") // time
+ .number("([AV]),") // validity
+ .number("(-?d+.d+),") // latitude
+ .number("(-?d+.d+),") // longitude
+ .number("(d+),") // speed
+ .number("(d+),") // course
+ .number("(-?d+),") // altitude
+ .number("(d+),") // odometer
+ .number("d+,") // runtime
+ .number("(xxxx),") // status
+ .number("(x+)?,") // input
+ .number("(x+)?,") // output
+ .number("(d+)|") // mcc
+ .number("(d+)|") // mnc
+ .number("(x+)|") // lac
+ .number("(x+),") // cid
+ .number("([x|]+)") // adc
+ .expression(",([^,]+)") // rfid
+ .expression(",([^*]+)").optional(2) // sensors
+ .any()
+ .compile();
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ parser.next(); // alarm
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setValid(parser.next().equals("A"));
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
+ position.setCourse(parser.nextInt());
+ position.setAltitude(parser.nextInt());
+
+ position.set(Position.KEY_ODOMETER, parser.nextLong());
+ position.set(Position.KEY_STATUS, parser.nextInt(16));
+ if (parser.hasNext()) {
+ position.set(Position.KEY_INPUT, parser.nextInt(16));
+ }
+ if (parser.hasNext()) {
+ position.set(Position.KEY_OUTPUT, parser.nextInt(16));
+ }
+
+ position.set(Position.KEY_MCC, parser.nextInt());
+ position.set(Position.KEY_MNC, parser.nextInt());
+ position.set(Position.KEY_LAC, parser.nextInt(16));
+ position.set(Position.KEY_CID, parser.nextInt(16));
+
+ String[] adc = parser.next().split("\\|");
+ for (int i = 0; i < adc.length; i++) {
+ position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16));
+ }
+
+ position.set(Position.KEY_RFID, parser.next());
+
+ if (parser.hasNext()) {
+ String[] sensors = parser.next().split("\\|");
+ for (int i = 0; i < sensors.length; i++) {
+ position.set(Position.PREFIX_IO + (i + 1), sensors[i]);
+ }
+ }
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/FlextrackProtocol.java b/src/org/traccar/protocol/FlextrackProtocol.java
index d62c064d0..77e316d82 100644
--- a/src/org/traccar/protocol/FlextrackProtocol.java
+++ b/src/org/traccar/protocol/FlextrackProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
index 0ce2ab780..db85acd5d 100644
--- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/FoxProtocol.java b/src/org/traccar/protocol/FoxProtocol.java
index 30b76ef25..501bff4c4 100644
--- a/src/org/traccar/protocol/FoxProtocol.java
+++ b/src/org/traccar/protocol/FoxProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/FoxProtocolDecoder.java b/src/org/traccar/protocol/FoxProtocolDecoder.java
index 0a47f7ed1..cf1e4f1f2 100644
--- a/src/org/traccar/protocol/FoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/FoxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/FreedomProtocol.java b/src/org/traccar/protocol/FreedomProtocol.java
index 0176d9781..5b4bf22ff 100644
--- a/src/org/traccar/protocol/FreedomProtocol.java
+++ b/src/org/traccar/protocol/FreedomProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java
index 3a05486eb..a8995b8aa 100644
--- a/src/org/traccar/protocol/FreedomProtocolDecoder.java
+++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/GalileoFrameDecoder.java b/src/org/traccar/protocol/GalileoFrameDecoder.java
index 3c4284fe0..6d02ce744 100644
--- a/src/org/traccar/protocol/GalileoFrameDecoder.java
+++ b/src/org/traccar/protocol/GalileoFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/GalileoProtocol.java b/src/org/traccar/protocol/GalileoProtocol.java
index 7d5b47bbb..11151e9ca 100644
--- a/src/org/traccar/protocol/GalileoProtocol.java
+++ b/src/org/traccar/protocol/GalileoProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 12b35333d..68063c5c3 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
diff --git a/src/org/traccar/protocol/GatorProtocol.java b/src/org/traccar/protocol/GatorProtocol.java
index e6b7161db..7fa4854d3 100644
--- a/src/org/traccar/protocol/GatorProtocol.java
+++ b/src/org/traccar/protocol/GatorProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index 88da9a37f..d9c8a086c 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
diff --git a/src/org/traccar/protocol/Gl100Protocol.java b/src/org/traccar/protocol/Gl100Protocol.java
index a78aff35f..0fd18d44f 100644
--- a/src/org/traccar/protocol/Gl100Protocol.java
+++ b/src/org/traccar/protocol/Gl100Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
index d9e5bc6e6..daef6ea52 100644
--- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
diff --git a/src/org/traccar/protocol/Gl200Protocol.java b/src/org/traccar/protocol/Gl200Protocol.java
index d38bdf8a9..b6f01c773 100644
--- a/src/org/traccar/protocol/Gl200Protocol.java
+++ b/src/org/traccar/protocol/Gl200Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -35,6 +35,7 @@ public class Gl200Protocol extends BaseProtocol {
Command.TYPE_POSITION_SINGLE,
Command.TYPE_ENGINE_STOP,
Command.TYPE_ENGINE_RESUME,
+ Command.TYPE_IDENTIFICATION,
Command.TYPE_REBOOT_DEVICE);
}
@@ -43,7 +44,7 @@ public class Gl200Protocol extends BaseProtocol {
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, "$", "\0"));
+ pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(4096, "$", "\0"));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("stringDecoder", new StringDecoder());
pipeline.addLast("objectEncoder", new Gl200ProtocolEncoder());
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 385039399..66a4e2f7e 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -37,35 +37,65 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN_HBD = new PatternBuilder()
- .text("+ACK:GTHBD,")
- .number("([0-9A-Z]{2}xxxx),")
+ private static final Pattern PATTERN_ACK = new PatternBuilder()
+ .text("+ACK:GT")
+ .expression("...,") // type
+ .number("([0-9A-Z]{2}xxxx),") // protocol version
+ .number("(d{15}|x{14}),") // imei
.any().text(",")
- .number("(xxxx)")
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd),") // time
+ .number("(xxxx)") // counter
.text("$").optional()
.compile();
private static final Pattern PATTERN_INF = new PatternBuilder()
- .text("+RESP:GTINF,")
+ .text("+").expression("(?:RESP|BUFF):GTINF,")
.number("[0-9A-Z]{2}xxxx,") // protocol version
- .number("(d{15}),") // imei
- .expression("[0-9A-Z]{17},") // vin
- .expression("[^,]{0,20},") // device name
+ .number("(d{15}|x{14}),") // imei
+ .expression("(?:[0-9A-Z]{17},)?") // vin
+ .expression("(?:[^,]+)?,") // device name
.number("(xx),") // state
- .expression("[0-9F]{20},") // iccid
+ .expression("(?:[0-9F]{20})?,") // iccid
.number("d{1,2},")
.number("d{1,2},")
- .expression("[01],")
- .number("(d{1,5}),") // power
- .text(",")
+ .expression("[01],") // external power
+ .number("([d.]+)?,") // odometer or external power
+ .number("d*,") // backup battery or lightness
.number("(d+.d+),") // battery
.expression("([01]),") // charging
- .expression("[01],")
- .text(",,")
+ .number("(?:d),") // led
+ .number("(?:d)?,") // gps on need
+ .number("(?:d)?,") // gps antenna type
+ .number("(?:d),").optional() // gps antenna state
.number("d{14},") // last fix time
- .text(",,,,,")
+ .groupBegin()
+ .number("(d+),") // battery percentage
+ .expression("[01]?,") // flash type
+ .number("(-?[d.]+)?,,,") // temperature
+ .or()
+ .expression("(?:[01])?,").optional() // pin15 mode
+ .number("(d+)?,") // adc1
+ .number("(d+)?,").optional() // adc2
+ .number("(xx)?,") // digital input
+ .number("(xx)?,") // digital output
.number("[-+]dddd,") // timezone
.expression("[01],") // daylight saving
+ .groupEnd()
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd),") // time
+ .number("(xxxx)") // counter
+ .text("$").optional()
+ .compile();
+
+ private static final Pattern PATTERN_VER = new PatternBuilder()
+ .text("+").expression("(?:RESP|BUFF):GTVER,")
+ .number("[0-9A-Z]{2}xxxx,") // protocol version
+ .number("(d{15}|x{14}),") // imei
+ .expression("[^,]*,") // device name
+ .expression("([^,]*),") // device type
+ .number("(xxxx),") // firmware version
+ .number("(xxxx),") // hardware version
.number("(dddd)(dd)(dd)") // date
.number("(dd)(dd)(dd),") // time
.number("(xxxx)") // counter
@@ -99,7 +129,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN_OBD = new PatternBuilder()
.text("+RESP:GTOBD,")
.number("[0-9A-Z]{2}xxxx,") // protocol version
- .number("(d{15}),") // imei
+ .number("(d{15}|x{14}),") // imei
.expression("(?:[0-9A-Z]{17})?,") // vin
.expression("[^,]{0,20},") // device name
.expression("[01],") // report type
@@ -167,7 +197,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN_IGN = new PatternBuilder()
.text("+").expression("(?:RESP|BUFF):GTIG[NF],")
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}),") // imei
+ .number("(d{15}|x{14}),") // imei
.expression("[^,]*,") // device name
.number("d+,") // ignition off duration
.expression(PATTERN_LOCATION.pattern())
@@ -183,7 +213,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN_IDA = new PatternBuilder()
.text("+RESP:GTIDA,")
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}),") // imei
+ .number("(d{15}|x{14}),") // imei
.expression("[^,]*,,") // device name
.number("([^,]+),") // rfid
.expression("[01],") // report type
@@ -242,15 +272,37 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
- private Object decodeHbd(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_HBD, sentence);
- if (parser.matches() && channel != null) {
- channel.write("+SACK:GTHBD," + parser.next() + "," + parser.next() + "$", remoteAddress);
+ private Object decodeAck(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
+ Parser parser = new Parser(PATTERN_ACK, sentence);
+ if (parser.matches()) {
+ String protocolVersion = parser.next();
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+ if (type.equals("HBD")) {
+ if (channel != null) {
+ parser.skip(6);
+ channel.write("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress);
+ }
+ } else {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ getLastLocation(position, dateBuilder.getDate());
+ position.setValid(false);
+ position.set(Position.KEY_RESULT, "Command " + type + " accepted");
+ return position;
+ }
}
return null;
}
private Object decodeInf(Channel channel, SocketAddress remoteAddress, String sentence) {
+
Parser parser = new Parser(PATTERN_INF, sentence);
if (!parser.matches()) {
return null;
@@ -266,9 +318,21 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_STATUS, parser.next());
- position.set(Position.KEY_POWER, parser.next());
- position.set(Position.KEY_BATTERY, parser.next());
- position.set(Position.KEY_CHARGE, parser.next());
+
+ parser.next(); // odometer or external power
+
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+ position.set(Position.KEY_CHARGE, parser.nextInt() == 1);
+
+ parser.next(); // battery percentage
+
+ position.set(Position.PREFIX_TEMP + 1, parser.next());
+
+ position.set(Position.PREFIX_ADC + 1, parser.next());
+ position.set(Position.PREFIX_ADC + 2, parser.next());
+
+ position.set(Position.KEY_INPUT, parser.next());
+ position.set(Position.KEY_OUTPUT, parser.next());
DateBuilder dateBuilder = new DateBuilder()
.setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
@@ -276,7 +340,35 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, dateBuilder.getDate());
- position.set(Position.KEY_INDEX, parser.next());
+ position.set(Position.KEY_INDEX, parser.nextInt(16));
+
+ return position;
+ }
+
+ private Object decodeVer(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_VER, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.set("deviceType", parser.next());
+ position.set("firmwareVersion", parser.nextInt(16));
+ position.set("hardwareVersion", parser.nextInt(16));
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ getLastLocation(position, dateBuilder.getDate());
return position;
}
@@ -511,6 +603,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
int reportType = parser.nextInt();
if (type.equals("NMR")) {
position.set(Position.KEY_MOTION, reportType);
+ } else if (type.equals("SOS")) {
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
}
decodeLocation(position, parser);
@@ -537,7 +631,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence) {
+ private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
Parser parser = new Parser(PATTERN_BASIC, sentence);
if (!parser.matches()) {
return null;
@@ -574,6 +668,21 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
}
}
+ switch (type) {
+ case "BPL":
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ break;
+ case "TEM":
+ position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE);
+ break;
+ case "JDR":
+ case "JDS":
+ position.set(Position.KEY_ALARM, Position.ALARM_JAMMING);
+ break;
+ default:
+ break;
+ }
+
return position;
}
@@ -590,41 +699,45 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
Object result;
String type = sentence.substring(typeIndex + 3, typeIndex + 6);
- switch (type) {
- case "HBD":
- result = decodeHbd(channel, remoteAddress, sentence);
- break;
- case "INF":
- result = decodeInf(channel, remoteAddress, sentence);
- break;
- case "OBD":
- result = decodeObd(channel, remoteAddress, sentence);
- break;
- case "FRI":
- result = decodeFri(channel, remoteAddress, sentence);
- break;
- case "IGN":
- case "IGF":
- result = decodeIgn(channel, remoteAddress, sentence);
- break;
- case "IDA":
- result = decodeIda(channel, remoteAddress, sentence);
- break;
- default:
- result = decodeOther(channel, remoteAddress, sentence, type);
- break;
- }
+ if (sentence.startsWith("+ACK")) {
+ result = decodeAck(channel, remoteAddress, sentence, type);
+ } else {
+ switch (type) {
+ case "INF":
+ result = decodeInf(channel, remoteAddress, sentence);
+ break;
+ case "OBD":
+ result = decodeObd(channel, remoteAddress, sentence);
+ break;
+ case "FRI":
+ result = decodeFri(channel, remoteAddress, sentence);
+ break;
+ case "IGN":
+ case "IGF":
+ result = decodeIgn(channel, remoteAddress, sentence);
+ break;
+ case "IDA":
+ result = decodeIda(channel, remoteAddress, sentence);
+ break;
+ case "VER":
+ result = decodeVer(channel, remoteAddress, sentence);
+ break;
+ default:
+ result = decodeOther(channel, remoteAddress, sentence, type);
+ break;
+ }
- if (result == null) {
- result = decodeBasic(channel, remoteAddress, sentence);
- }
+ if (result == null) {
+ result = decodeBasic(channel, remoteAddress, sentence, type);
+ }
- if (result != null) {
- if (result instanceof Position) {
- ((Position) result).set(Position.KEY_TYPE, type);
- } else {
- for (Position p : (List<Position>) result) {
- p.set(Position.KEY_TYPE, type);
+ if (result != null) {
+ if (result instanceof Position) {
+ ((Position) result).set(Position.KEY_TYPE, type);
+ } else {
+ for (Position p : (List<Position>) result) {
+ p.set(Position.KEY_TYPE, type);
+ }
}
}
}
diff --git a/src/org/traccar/protocol/Gl200ProtocolEncoder.java b/src/org/traccar/protocol/Gl200ProtocolEncoder.java
index 0537420a0..2c8efa318 100644
--- a/src/org/traccar/protocol/Gl200ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -24,15 +24,21 @@ public class Gl200ProtocolEncoder extends StringProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
+ initDevicePassword(command, "");
+
switch (command.getType()) {
case Command.TYPE_POSITION_SINGLE:
- return "AT+GTRTO=gv300,1,,,,,,FFFF$";
+ return formatCommand(command, "AT+GTRTO={%s},1,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD);
case Command.TYPE_ENGINE_STOP:
- return "AT+GTOUT=gv300,1,,,0,0,0,0,0,0,0,,,,,,,FFFF$";
+ return formatCommand(command, "AT+GTOUT={%s},1,,,0,0,0,0,0,0,0,,,,,,,FFFF$",
+ Command.KEY_DEVICE_PASSWORD);
case Command.TYPE_ENGINE_RESUME:
- return "AT+GTOUT=gv300,0,,,0,0,0,0,0,0,0,,,,,,,FFFF$";
+ return formatCommand(command, "AT+GTOUT={%s},0,,,0,0,0,0,0,0,0,,,,,,,FFFF$",
+ Command.KEY_DEVICE_PASSWORD);
+ case Command.TYPE_IDENTIFICATION:
+ return formatCommand(command, "AT+GTRTO={%s},8,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD);
case Command.TYPE_REBOOT_DEVICE:
- return "AT+GTRTO=gv300,3,,,,,,FFFF$";
+ return formatCommand(command, "AT+GTRTO={%s},3,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/GlobalSatProtocol.java b/src/org/traccar/protocol/GlobalSatProtocol.java
index 25d7656f1..f3d07fc96 100644
--- a/src/org/traccar/protocol/GlobalSatProtocol.java
+++ b/src/org/traccar/protocol/GlobalSatProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
index 084279732..4c127a90b 100644
--- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 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.
diff --git a/src/org/traccar/protocol/GnxProtocol.java b/src/org/traccar/protocol/GnxProtocol.java
index aeef247c2..84af24000 100644
--- a/src/org/traccar/protocol/GnxProtocol.java
+++ b/src/org/traccar/protocol/GnxProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java
index b88d306a8..aff86ea7b 100644
--- a/src/org/traccar/protocol/GnxProtocolDecoder.java
+++ b/src/org/traccar/protocol/GnxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/GoSafeProtocol.java b/src/org/traccar/protocol/GoSafeProtocol.java
index 54abacd42..bfd473df9 100644
--- a/src/org/traccar/protocol/GoSafeProtocol.java
+++ b/src/org/traccar/protocol/GoSafeProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index a511f9926..a258e922c 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/GotopProtocol.java b/src/org/traccar/protocol/GotopProtocol.java
index 6b31e1acf..5d522adf5 100644
--- a/src/org/traccar/protocol/GotopProtocol.java
+++ b/src/org/traccar/protocol/GotopProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
index 0dcae3c8d..0c613eb2d 100644
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ b/src/org/traccar/protocol/GotopProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java
index 559de3187..82d42f1c9 100644
--- a/src/org/traccar/protocol/Gps103Protocol.java
+++ b/src/org/traccar/protocol/Gps103Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 363834f89..57dc784d3 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -95,10 +95,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.?d*%),") // throttle
.number("(d+),") // rpm
.number("(d+.d+),") // battery
- .number("[^,]*,") // dtc 1
- .number("[^,]*,") // dtc 2
- .number("[^,]*,") // dtc 3
- .number("[^,]*") // dtc 4
+ .number("([^;]*)") // dtcs
.any()
.compile();
@@ -116,6 +113,12 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
return Position.ALARM_MOVEMENT;
case "speed":
return Position.ALARM_OVERSPEED;
+ case "acc on":
+ return Position.ALARM_POWER_ON;
+ case "acc off":
+ return Position.ALARM_POWER_OFF;
+ case "door alarm":
+ return Position.ALARM_DOOR;
default:
return null;
}
@@ -197,6 +200,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_THROTTLE, parser.next());
position.set(Position.KEY_RPM, parser.next());
position.set(Position.KEY_BATTERY, parser.next());
+ position.set(Position.KEY_DTCS, parser.next().replace(',', ' ').trim());
return position;
diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java
index 23942e554..afe87cf8c 100644
--- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GpsGateProtocol.java b/src/org/traccar/protocol/GpsGateProtocol.java
index 78a7588ad..c7dc2c4f3 100644
--- a/src/org/traccar/protocol/GpsGateProtocol.java
+++ b/src/org/traccar/protocol/GpsGateProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index ac859b592..47b02de94 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
diff --git a/src/org/traccar/protocol/GpsMarkerProtocol.java b/src/org/traccar/protocol/GpsMarkerProtocol.java
index bb4b5b561..5c64d16b2 100644
--- a/src/org/traccar/protocol/GpsMarkerProtocol.java
+++ b/src/org/traccar/protocol/GpsMarkerProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
index 89537fa3d..3f9b52cd1 100644
--- a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/GpsmtaProtocol.java b/src/org/traccar/protocol/GpsmtaProtocol.java
index 51cce2650..2d1181bec 100644
--- a/src/org/traccar/protocol/GpsmtaProtocol.java
+++ b/src/org/traccar/protocol/GpsmtaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
index f10b3771c..7360dbc1d 100644
--- a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/GranitFrameDecoder.java b/src/org/traccar/protocol/GranitFrameDecoder.java
index 5f1297c6d..7e8f4a3f5 100644
--- a/src/org/traccar/protocol/GranitFrameDecoder.java
+++ b/src/org/traccar/protocol/GranitFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/GranitProtocol.java b/src/org/traccar/protocol/GranitProtocol.java
index 1e097c17b..a5d5458f0 100644
--- a/src/org/traccar/protocol/GranitProtocol.java
+++ b/src/org/traccar/protocol/GranitProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java
index 3a2d24fa2..5fa786e4d 100644
--- a/src/org/traccar/protocol/GranitProtocolDecoder.java
+++ b/src/org/traccar/protocol/GranitProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -19,6 +19,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
import org.traccar.helper.Checksum;
@@ -36,8 +37,17 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
private static final int HEADER_LENGTH = 6;
+ private double adc1Ratio;
+ private double adc2Ratio;
+ private double adc3Ratio;
+ private double adc4Ratio;
+
public GranitProtocolDecoder(GranitProtocol protocol) {
super(protocol);
+ adc1Ratio = Context.getConfig().getDouble("granit.adc1Ratio", 1);
+ adc2Ratio = Context.getConfig().getDouble("granit.adc2Ratio", 1);
+ adc3Ratio = Context.getConfig().getDouble("granit.adc3Ratio", 1);
+ adc4Ratio = Context.getConfig().getDouble("granit.adc4Ratio", 1);
}
public static void appendChecksum(ChannelBuffer buffer, int length) {
@@ -68,7 +78,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
channel.write(response);
}
- private static void decodeStructure(ChannelBuffer buf, Position position) {
+ private void decodeStructure(ChannelBuffer buf, Position position) {
short flags = buf.readUnsignedByte();
position.setValid(BitUtil.check(flags, 7));
if (BitUtil.check(flags, 1)) {
@@ -118,10 +128,10 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
analogIn3 = analogInHi << 4 & 0x300 | analogIn3;
analogIn4 = analogInHi << 2 & 0x300 | analogIn4;
- position.set(Position.PREFIX_ADC + 1, analogIn1);
- position.set(Position.PREFIX_ADC + 2, analogIn2);
- position.set(Position.PREFIX_ADC + 3, analogIn3);
- position.set(Position.PREFIX_ADC + 4, analogIn4);
+ position.set(Position.PREFIX_ADC + 1, analogIn1 * adc1Ratio);
+ position.set(Position.PREFIX_ADC + 2, analogIn2 * adc2Ratio);
+ position.set(Position.PREFIX_ADC + 3, analogIn3 * adc3Ratio);
+ position.set(Position.PREFIX_ADC + 4, analogIn4 * adc4Ratio);
position.setAltitude(buf.readUnsignedByte() * 10);
diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java
index 805bfbe24..dbfd30ff1 100644
--- a/src/org/traccar/protocol/GranitProtocolEncoder.java
+++ b/src/org/traccar/protocol/GranitProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/Gt02Protocol.java b/src/org/traccar/protocol/Gt02Protocol.java
index 595e6649e..e484b66cd 100644
--- a/src/org/traccar/protocol/Gt02Protocol.java
+++ b/src/org/traccar/protocol/Gt02Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index dea1416ac..8a42293b9 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/Gt06FrameDecoder.java b/src/org/traccar/protocol/Gt06FrameDecoder.java
index 67f42efb4..f35af6572 100644
--- a/src/org/traccar/protocol/Gt06FrameDecoder.java
+++ b/src/org/traccar/protocol/Gt06FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 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.
diff --git a/src/org/traccar/protocol/Gt06Protocol.java b/src/org/traccar/protocol/Gt06Protocol.java
index e4c9ef2e0..e96679799 100644
--- a/src/org/traccar/protocol/Gt06Protocol.java
+++ b/src/org/traccar/protocol/Gt06Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 4af814e24..35cb83dac 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
index e478424f9..b6ec5a0d1 100644
--- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -66,9 +66,9 @@ public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
switch (command.getType()) {
case Command.TYPE_ENGINE_STOP:
- return encodeContent(alternative ? "DYD,123456#\r\n" : "Relay,1#");
+ return encodeContent(alternative ? "DYD,123456#" : "Relay,1#");
case Command.TYPE_ENGINE_RESUME:
- return encodeContent(alternative ? "HFYD,123456#\r\n" : "Relay,0#");
+ return encodeContent(alternative ? "HFYD,123456#" : "Relay,0#");
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java
index feba8033d..a22252a57 100644
--- a/src/org/traccar/protocol/H02FrameDecoder.java
+++ b/src/org/traccar/protocol/H02FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -22,6 +22,9 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
public class H02FrameDecoder extends FrameDecoder {
+ private static final int MESSAGE_SHORT = 32;
+ private static final int MESSAGE_LONG = 45;
+
private int messageLength;
public H02FrameDecoder(int messageLength) {
@@ -49,10 +52,19 @@ public class H02FrameDecoder extends FrameDecoder {
return buf.readBytes(index + 1 - buf.readerIndex());
}
- } else if (marker == '$' && buf.readableBytes() >= messageLength) {
+ } else if (marker == '$') {
+
+ if (messageLength == 0) {
+ if (buf.readableBytes() == MESSAGE_LONG) {
+ messageLength = MESSAGE_LONG;
+ } else {
+ messageLength = MESSAGE_SHORT;
+ }
+ }
- // Return binary message
- return buf.readBytes(messageLength);
+ if (buf.readableBytes() >= messageLength) {
+ return buf.readBytes(messageLength);
+ }
}
diff --git a/src/org/traccar/protocol/H02Protocol.java b/src/org/traccar/protocol/H02Protocol.java
index 06ac2a6fa..498f63c0e 100644
--- a/src/org/traccar/protocol/H02Protocol.java
+++ b/src/org/traccar/protocol/H02Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -43,7 +43,7 @@ public class H02Protocol extends BaseProtocol {
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- int messageLength = Context.getConfig().getInteger(getName() + ".messageLength", 32);
+ int messageLength = Context.getConfig().getInteger(getName() + ".messageLength");
pipeline.addLast("frameDecoder", new H02FrameDecoder(messageLength));
pipeline.addLast("stringEncoder", new StringEncoder());
pipeline.addLast("objectEncoder", new H02ProtocolEncoder());
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index f876f40bc..45a978571 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -170,6 +170,22 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private static final Pattern PATTERN_NBR = new PatternBuilder()
+ .text("*")
+ .expression("..,") // manufacturer
+ .number("(d+),") // imei
+ .text("NBR,")
+ .number("(dd)(dd)(dd),") // time
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("d+,") // gsm delay time
+ .number("d+,") // count
+ .number("((?:d+,d+,d+,)+)") // cells
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(x{8})") // status
+ .any()
+ .compile();
+
private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN, sentence);
@@ -177,13 +193,13 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder();
@@ -224,6 +240,42 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Position decodeLbs(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_NBR, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.set(Position.KEY_MCC, parser.nextInt());
+ position.set(Position.KEY_MNC, parser.nextInt());
+
+ String[] cells = parser.next().split(","); // decode all in future
+ position.set(Position.KEY_LAC, Integer.parseInt(cells[0]));
+ position.set(Position.KEY_CID, Integer.parseInt(cells[1]));
+ position.set(Position.KEY_GSM, Integer.parseInt(cells[2]));
+
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ processStatus(position, parser.nextLong(16));
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -234,7 +286,12 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
// handle X mode?
if (marker.equals("*")) {
- return decodeText(buf.toString(StandardCharsets.US_ASCII), channel, remoteAddress);
+ String sentence = buf.toString(StandardCharsets.US_ASCII);
+ if (sentence.contains(",NBR,")) {
+ return decodeLbs(sentence, channel, remoteAddress);
+ } else {
+ return decodeText(sentence, channel, remoteAddress);
+ }
} else if (marker.equals("$")) {
return decodeBinary(buf, channel, remoteAddress);
}
diff --git a/src/org/traccar/protocol/H02ProtocolEncoder.java b/src/org/traccar/protocol/H02ProtocolEncoder.java
index 4045b46d4..7b5ff13bb 100644
--- a/src/org/traccar/protocol/H02ProtocolEncoder.java
+++ b/src/org/traccar/protocol/H02ProtocolEncoder.java
@@ -1,6 +1,6 @@
/*
* Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com)
- * 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * 2016 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.
diff --git a/src/org/traccar/protocol/HaicomProtocol.java b/src/org/traccar/protocol/HaicomProtocol.java
index 71970d476..4380dd2cc 100644
--- a/src/org/traccar/protocol/HaicomProtocol.java
+++ b/src/org/traccar/protocol/HaicomProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java
index 647477d50..8fbf98d3c 100644
--- a/src/org/traccar/protocol/HaicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 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.
diff --git a/src/org/traccar/protocol/HomtecsProtocol.java b/src/org/traccar/protocol/HomtecsProtocol.java
index e8a86fa37..a9ea19c51 100644
--- a/src/org/traccar/protocol/HomtecsProtocol.java
+++ b/src/org/traccar/protocol/HomtecsProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/HomtecsProtocolDecoder.java b/src/org/traccar/protocol/HomtecsProtocolDecoder.java
index 21eb2c0b5..78bf0a813 100644
--- a/src/org/traccar/protocol/HomtecsProtocolDecoder.java
+++ b/src/org/traccar/protocol/HomtecsProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/HuaShengFrameDecoder.java b/src/org/traccar/protocol/HuaShengFrameDecoder.java
index 0e1becc30..4c29b7915 100644
--- a/src/org/traccar/protocol/HuaShengFrameDecoder.java
+++ b/src/org/traccar/protocol/HuaShengFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/HuaShengProtocol.java b/src/org/traccar/protocol/HuaShengProtocol.java
index dcef2bd69..e0fddae20 100644
--- a/src/org/traccar/protocol/HuaShengProtocol.java
+++ b/src/org/traccar/protocol/HuaShengProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/org/traccar/protocol/HuaShengProtocolDecoder.java
index cbe931bd0..a0a1eb0ab 100644
--- a/src/org/traccar/protocol/HuaShengProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuaShengProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
@@ -98,7 +99,12 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder {
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_STATUS, buf.readUnsignedShort());
+ int status = buf.readUnsignedShort();
+
+ position.setValid(BitUtil.check(status, 15));
+
+ position.set(Position.KEY_STATUS, status);
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 14));
position.set(Position.KEY_EVENT, buf.readUnsignedShort());
String time = buf.readBytes(12).toString(StandardCharsets.US_ASCII);
diff --git a/src/org/traccar/protocol/HuabaoFrameDecoder.java b/src/org/traccar/protocol/HuabaoFrameDecoder.java
index 003876fe5..8e9c9fe72 100644
--- a/src/org/traccar/protocol/HuabaoFrameDecoder.java
+++ b/src/org/traccar/protocol/HuabaoFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/HuabaoProtocol.java b/src/org/traccar/protocol/HuabaoProtocol.java
index 4a83689e3..053ce59bb 100644
--- a/src/org/traccar/protocol/HuabaoProtocol.java
+++ b/src/org/traccar/protocol/HuabaoProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
index 9223ea9a5..196d7927d 100644
--- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/HunterProProtocol.java b/src/org/traccar/protocol/HunterProProtocol.java
index 502a95e11..17352a0f3 100644
--- a/src/org/traccar/protocol/HunterProProtocol.java
+++ b/src/org/traccar/protocol/HunterProProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/HunterProProtocolDecoder.java b/src/org/traccar/protocol/HunterProProtocolDecoder.java
index 2274ab1b8..fc19257f6 100644
--- a/src/org/traccar/protocol/HunterProProtocolDecoder.java
+++ b/src/org/traccar/protocol/HunterProProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/IdplProtocol.java b/src/org/traccar/protocol/IdplProtocol.java
index 88e106def..a954397cd 100644
--- a/src/org/traccar/protocol/IdplProtocol.java
+++ b/src/org/traccar/protocol/IdplProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/IdplProtocolDecoder.java b/src/org/traccar/protocol/IdplProtocolDecoder.java
index 4fdf9d677..cfef75952 100644
--- a/src/org/traccar/protocol/IdplProtocolDecoder.java
+++ b/src/org/traccar/protocol/IdplProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java
index 4e6241a40..49f8b4a5d 100644
--- a/src/org/traccar/protocol/IntellitracFrameDecoder.java
+++ b/src/org/traccar/protocol/IntellitracFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/IntellitracProtocol.java b/src/org/traccar/protocol/IntellitracProtocol.java
index 6db2b0011..2d9421636 100644
--- a/src/org/traccar/protocol/IntellitracProtocol.java
+++ b/src/org/traccar/protocol/IntellitracProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
index af9f9bbab..a2720028f 100644
--- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java
+++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
index e0fe0678d..debc66673 100644
--- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
+++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
@@ -1,6 +1,6 @@
/*
* Copyright 2016 Nyash (nyashh@gmail.com)
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java
index cb7fce0c0..5606ae1fc 100644
--- a/src/org/traccar/protocol/Jt600FrameDecoder.java
+++ b/src/org/traccar/protocol/Jt600FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -35,7 +35,8 @@ public class Jt600FrameDecoder extends FrameDecoder {
char type = (char) buf.getByte(buf.readerIndex());
if (type == '$') {
- int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10;
+ boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75;
+ int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10;
if (length >= buf.readableBytes()) {
return buf.readBytes(length);
}
diff --git a/src/org/traccar/protocol/Jt600Protocol.java b/src/org/traccar/protocol/Jt600Protocol.java
index 2df792b47..132770511 100644
--- a/src/org/traccar/protocol/Jt600Protocol.java
+++ b/src/org/traccar/protocol/Jt600Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
@@ -17,8 +17,10 @@ package org.traccar.protocol;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
+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;
@@ -26,6 +28,11 @@ public class Jt600Protocol extends BaseProtocol {
public Jt600Protocol() {
super("jt600");
+ setSupportedCommands(
+ Command.TYPE_ENGINE_RESUME,
+ Command.TYPE_ENGINE_STOP,
+ Command.TYPE_SET_TIMEZONE,
+ Command.TYPE_REBOOT_DEVICE);
}
@Override
@@ -34,6 +41,8 @@ public class Jt600Protocol extends BaseProtocol {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new Jt600FrameDecoder());
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("objectEncoder", new Jt600ProtocolEncoder());
pipeline.addLast("objectDecoder", new Jt600ProtocolDecoder(Jt600Protocol.this));
}
});
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index b7193d24b..ad7a00dc2 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -43,13 +43,15 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return degrees + minutes / 60;
}
- private Position decodeNormalMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
Position position = new Position();
position.setProtocol(getProtocolName());
buf.readByte(); // header
+ boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) == 0x75;
+
String id = String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(5))));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
@@ -57,9 +59,12 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(deviceSession.getDeviceId());
- int version = BcdUtil.readInteger(buf, 1);
- buf.readUnsignedByte(); // type
- buf.readBytes(2); // length
+ if (longFormat) {
+ buf.readUnsignedByte(); // protocol
+ }
+
+ int version = buf.readUnsignedByte() >> 4;
+ buf.readUnsignedShort(); // length
DateBuilder dateBuilder = new DateBuilder()
.setDay(BcdUtil.readInteger(buf, 2))
@@ -87,7 +92,28 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(BcdUtil.readInteger(buf, 2));
position.setCourse(buf.readUnsignedByte() * 2.0);
- if (version == 1) {
+ if (longFormat) {
+
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+
+ buf.readUnsignedInt(); // vehicle id combined
+
+ position.set(Position.KEY_STATUS, buf.readUnsignedShort());
+
+ int battery = buf.readUnsignedByte();
+ if (battery == 0xff) {
+ position.set(Position.KEY_CHARGE, true);
+ } else {
+ position.set(Position.KEY_BATTERY, battery + "%");
+ }
+
+ position.set(Position.KEY_CID, buf.readUnsignedShort());
+ position.set(Position.KEY_LAC, buf.readUnsignedShort());
+ position.set(Position.KEY_GSM, buf.readUnsignedByte());
+ position.set(Position.KEY_INDEX, buf.readUnsignedByte());
+
+ } else if (version == 1) {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedByte());
@@ -120,7 +146,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_W01 = new PatternBuilder()
.text("(")
.number("(d+),") // id
.text("W01,") // type
@@ -138,25 +164,22 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // gsm signal
.number("(d+),") // alert type
.any()
- .text(")")
.compile();
- private Position decodeAlertMessage(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
+ private Position decodeW01(String sentence, Channel channel, SocketAddress remoteAddress) {
- Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII));
+ Parser parser = new Parser(PATTERN_W01, sentence);
if (!parser.matches()) {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setLongitude(parser.nextCoordinate());
@@ -176,6 +199,80 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private static final Pattern PATTERN_U01 = new PatternBuilder()
+ .text("(")
+ .number("(d+),") // id
+ .number("(Udd),") // type
+ .number("d+,").optional() // alarm
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .number("(dd)(dd)(dd),") // time
+ .expression("([TF]),") // validity
+ .number("(d+.d+),([NS]),") // latitude
+ .number("(d+.d+),([EW]),") // longitude
+ .number("(d+.?d*),") // speed
+ .number("(d+),") // course
+ .number("(d+),") // satellites
+ .number("(d+%),") // battery
+ .expression("([01]+),") // status
+ .number("(d+),") // cid
+ .number("(d+),") // lac
+ .number("(d+),") // gsm signal
+ .number("(d+),") // odometer
+ .number("(d+)") // serial number
+ .number(",(xx)").optional() // checksum
+ .any()
+ .compile();
+
+ private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) {
+
+ Parser parser = new Parser(PATTERN_U01, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ String type = parser.next();
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setValid(parser.next().equals("T"));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+
+ position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble()));
+ position.setCourse(parser.nextDouble());
+
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_BATTERY, parser.next());
+ position.set(Position.KEY_STATUS, parser.nextInt(2));
+ position.set(Position.KEY_CID, parser.nextInt());
+ position.set(Position.KEY_LAC, parser.nextInt());
+ position.set(Position.KEY_GSM, parser.nextInt());
+ position.set(Position.KEY_ODOMETER, parser.nextLong() * 1000);
+ position.set(Position.KEY_INDEX, parser.nextInt());
+
+ if (channel != null) {
+ if (type.equals("U01") || type.equals("U02") || type.equals("U03")) {
+ channel.write("(S39)");
+ } else if (type.equals("U06")) {
+ channel.write("(S20)");
+ }
+ }
+
+ return position;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -184,9 +281,14 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
char first = (char) buf.getByte(0);
if (first == '$') {
- return decodeNormalMessage(buf, channel, remoteAddress);
+ return decodeBinary(buf, channel, remoteAddress);
} else if (first == '(') {
- return decodeAlertMessage(buf, channel, remoteAddress);
+ String sentence = buf.toString(StandardCharsets.US_ASCII);
+ if (sentence.contains("W01")) {
+ return decodeW01(sentence, channel, remoteAddress);
+ } else {
+ return decodeU01(sentence, channel, remoteAddress);
+ }
}
return null;
diff --git a/src/org/traccar/protocol/Jt600ProtocolEncoder.java b/src/org/traccar/protocol/Jt600ProtocolEncoder.java
new file mode 100644
index 000000000..3eb0566a4
--- /dev/null
+++ b/src/org/traccar/protocol/Jt600ProtocolEncoder.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 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 org.traccar.StringProtocolEncoder;
+import org.traccar.helper.Log;
+import org.traccar.model.Command;
+
+public class Jt600ProtocolEncoder extends StringProtocolEncoder {
+ @Override
+ protected Object encodeCommand(Command command) {
+
+ switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP:
+ return "(S07,0)";
+ case Command.TYPE_ENGINE_RESUME:
+ return "(S07,1)";
+ case Command.TYPE_SET_TIMEZONE:
+ int offset = ((Number) command.getAttributes().get(Command.KEY_TIMEZONE)).intValue() / 60;
+ return "(S09,1," + offset + ")";
+ case Command.TYPE_REBOOT_DEVICE:
+ return "(S17)";
+ default:
+ Log.warning(new UnsupportedOperationException(command.getType()));
+ break;
+ }
+
+ return null;
+ }
+}
diff --git a/src/org/traccar/protocol/KenjiProtocolDecoder.java b/src/org/traccar/protocol/KenjiProtocolDecoder.java
index e13c91e3a..8e59341bd 100755
--- a/src/org/traccar/protocol/KenjiProtocolDecoder.java
+++ b/src/org/traccar/protocol/KenjiProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/KhdProtocol.java b/src/org/traccar/protocol/KhdProtocol.java
index e5bcc1be3..bf0d2855d 100644
--- a/src/org/traccar/protocol/KhdProtocol.java
+++ b/src/org/traccar/protocol/KhdProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index e34a24b40..0c3d8ee51 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/KhdProtocolEncoder.java b/src/org/traccar/protocol/KhdProtocolEncoder.java
index a056fdf05..618e43dad 100644
--- a/src/org/traccar/protocol/KhdProtocolEncoder.java
+++ b/src/org/traccar/protocol/KhdProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
index 92af255dd..a597cbd7d 100644
--- a/src/org/traccar/protocol/L100FrameDecoder.java
+++ b/src/org/traccar/protocol/L100FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java
index 418b9beb7..2bcef4caa 100644
--- a/src/org/traccar/protocol/L100Protocol.java
+++ b/src/org/traccar/protocol/L100Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
index ff0687751..7eed7df9a 100644
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/LaipacProtocol.java b/src/org/traccar/protocol/LaipacProtocol.java
index f64204749..45b803a0f 100644
--- a/src/org/traccar/protocol/LaipacProtocol.java
+++ b/src/org/traccar/protocol/LaipacProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
index ebca443a1..a0e394d2c 100644
--- a/src/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -37,7 +37,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
.text("$AVRMC,")
.expression("([^,]+),") // identifier
.number("(dd)(dd)(dd),") // time
- .expression("([AVRavr]),") // validity
+ .expression("([AVRPavrp]),") // validity
.number("(dd)(dd.d+),") // latitude
.expression("([NS]),")
.number("(ddd)(dd.d+),") // longitude
@@ -66,13 +66,13 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/M2mProtocol.java b/src/org/traccar/protocol/M2mProtocol.java
index 662aa3f0f..09393fed0 100644
--- a/src/org/traccar/protocol/M2mProtocol.java
+++ b/src/org/traccar/protocol/M2mProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java
index 601b6d191..a3c2ada2f 100644
--- a/src/org/traccar/protocol/M2mProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2mProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/ManPowerProtocol.java b/src/org/traccar/protocol/ManPowerProtocol.java
index ce7045899..60ce8b282 100644
--- a/src/org/traccar/protocol/ManPowerProtocol.java
+++ b/src/org/traccar/protocol/ManPowerProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
index a2ede32b8..39b651d7e 100644
--- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java
+++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java
index da77d95fd..d9cb07108 100644
--- a/src/org/traccar/protocol/MegastekFrameDecoder.java
+++ b/src/org/traccar/protocol/MegastekFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/MegastekProtocol.java b/src/org/traccar/protocol/MegastekProtocol.java
index 77c2510bd..b28a05b92 100644
--- a/src/org/traccar/protocol/MegastekProtocol.java
+++ b/src/org/traccar/protocol/MegastekProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index 3ea76536c..005d38c41 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java
index 9fb530f8a..9340b6198 100644
--- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/MeiligaoProtocol.java b/src/org/traccar/protocol/MeiligaoProtocol.java
index 2c61af5cb..23af19ef1 100644
--- a/src/org/traccar/protocol/MeiligaoProtocol.java
+++ b/src/org/traccar/protocol/MeiligaoProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index f0e5032b4..9915eab8c 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
index 93399df60..a91b33a60 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java
index 3c2d34394..1eb0dae0f 100644
--- a/src/org/traccar/protocol/MeitrackFrameDecoder.java
+++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
index 0c85c6203..918729f97 100644
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ b/src/org/traccar/protocol/MeitrackProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index f2208984c..72ccaa037 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
index 784b3b917..b10a751c1 100644
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java
index 605633267..71a956d0f 100644
--- a/src/org/traccar/protocol/MiniFinderProtocol.java
+++ b/src/org/traccar/protocol/MiniFinderProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
index 348476c6b..33396cebb 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 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.
diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
index c5210aa0b..96079745c 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/Mta6Protocol.java b/src/org/traccar/protocol/Mta6Protocol.java
index cafda2bc6..65a48808d 100644
--- a/src/org/traccar/protocol/Mta6Protocol.java
+++ b/src/org/traccar/protocol/Mta6Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index 1da55f715..2109a63c3 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/MtxProtocol.java b/src/org/traccar/protocol/MtxProtocol.java
index c549653d0..58b2361cd 100644
--- a/src/org/traccar/protocol/MtxProtocol.java
+++ b/src/org/traccar/protocol/MtxProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java
index 6a6677830..0b84603bd 100644
--- a/src/org/traccar/protocol/MtxProtocolDecoder.java
+++ b/src/org/traccar/protocol/MtxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MxtFrameDecoder.java b/src/org/traccar/protocol/MxtFrameDecoder.java
index cb1d8ed8e..b2cd6de93 100644
--- a/src/org/traccar/protocol/MxtFrameDecoder.java
+++ b/src/org/traccar/protocol/MxtFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MxtProtocol.java b/src/org/traccar/protocol/MxtProtocol.java
index a5d21e445..03c1da71e 100644
--- a/src/org/traccar/protocol/MxtProtocol.java
+++ b/src/org/traccar/protocol/MxtProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java
index 1dbfc3696..0e01f807f 100644
--- a/src/org/traccar/protocol/MxtProtocolDecoder.java
+++ b/src/org/traccar/protocol/MxtProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/NavigilFrameDecoder.java b/src/org/traccar/protocol/NavigilFrameDecoder.java
index 7a8989115..34eb28941 100644
--- a/src/org/traccar/protocol/NavigilFrameDecoder.java
+++ b/src/org/traccar/protocol/NavigilFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/NavigilProtocol.java b/src/org/traccar/protocol/NavigilProtocol.java
index 7cf6f35ff..6646c6cc6 100644
--- a/src/org/traccar/protocol/NavigilProtocol.java
+++ b/src/org/traccar/protocol/NavigilProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
index e2afdf8d3..d18217861 100644
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/NavisProtocol.java b/src/org/traccar/protocol/NavisProtocol.java
index d4cf40f1f..771c9d61d 100644
--- a/src/org/traccar/protocol/NavisProtocol.java
+++ b/src/org/traccar/protocol/NavisProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index 03e578fe9..e06ef1b57 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 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.
@@ -22,6 +22,7 @@ import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -139,12 +140,12 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
DateBuilder dateBuilder = new DateBuilder()
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
+ .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte() + 1, buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
position.setLatitude(buf.readFloat() / Math.PI * 180);
position.setLongitude(buf.readFloat() / Math.PI * 180);
- position.setSpeed(buf.readFloat());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
position.setCourse(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readFloat() * 1000);
diff --git a/src/org/traccar/protocol/NoranProtocol.java b/src/org/traccar/protocol/NoranProtocol.java
index eeddbdead..bf10eb127 100644
--- a/src/org/traccar/protocol/NoranProtocol.java
+++ b/src/org/traccar/protocol/NoranProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index e062a9907..ebeacc659 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/NoranProtocolEncoder.java b/src/org/traccar/protocol/NoranProtocolEncoder.java
index 1f1988802..5bd069218 100644
--- a/src/org/traccar/protocol/NoranProtocolEncoder.java
+++ b/src/org/traccar/protocol/NoranProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/NvsFrameDecoder.java b/src/org/traccar/protocol/NvsFrameDecoder.java
index 3991a1865..598bb1e4c 100644
--- a/src/org/traccar/protocol/NvsFrameDecoder.java
+++ b/src/org/traccar/protocol/NvsFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/NvsProtocol.java b/src/org/traccar/protocol/NvsProtocol.java
index 4610e4abc..fdcb2bbcf 100644
--- a/src/org/traccar/protocol/NvsProtocol.java
+++ b/src/org/traccar/protocol/NvsProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/NvsProtocolDecoder.java b/src/org/traccar/protocol/NvsProtocolDecoder.java
index c32501d56..0e82fae69 100644
--- a/src/org/traccar/protocol/NvsProtocolDecoder.java
+++ b/src/org/traccar/protocol/NvsProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ObdDongleProtocol.java b/src/org/traccar/protocol/ObdDongleProtocol.java
index d91eb765a..6547a31ab 100644
--- a/src/org/traccar/protocol/ObdDongleProtocol.java
+++ b/src/org/traccar/protocol/ObdDongleProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
index 84ff1450a..e5ae5e93f 100644
--- a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
+++ b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/OigoProtocol.java b/src/org/traccar/protocol/OigoProtocol.java
index c60ee1be6..4b6ad0dd0 100644
--- a/src/org/traccar/protocol/OigoProtocol.java
+++ b/src/org/traccar/protocol/OigoProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java
index bbea38183..15a215c4f 100644
--- a/src/org/traccar/protocol/OigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/OigoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java
index 3babda175..f7371747a 100644
--- a/src/org/traccar/protocol/OrionFrameDecoder.java
+++ b/src/org/traccar/protocol/OrionFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/OrionProtocol.java b/src/org/traccar/protocol/OrionProtocol.java
index c0166b05d..f4bfef985 100644
--- a/src/org/traccar/protocol/OrionProtocol.java
+++ b/src/org/traccar/protocol/OrionProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
index c65e534f4..c65924337 100644
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ b/src/org/traccar/protocol/OrionProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/OsmAndProtocol.java b/src/org/traccar/protocol/OsmAndProtocol.java
index 7f5318576..785f4bd75 100644
--- a/src/org/traccar/protocol/OsmAndProtocol.java
+++ b/src/org/traccar/protocol/OsmAndProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index eddfb592c..5508cad92 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -135,8 +135,7 @@ public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date());
}
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession != null) {
+ if (position.getDeviceId() != 0) {
sendResponse(channel, HttpResponseStatus.OK);
return position;
} else {
diff --git a/src/org/traccar/protocol/PathAwayProtocol.java b/src/org/traccar/protocol/PathAwayProtocol.java
index 2583670a2..a41692750 100644
--- a/src/org/traccar/protocol/PathAwayProtocol.java
+++ b/src/org/traccar/protocol/PathAwayProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/PathAwayProtocolDecoder.java b/src/org/traccar/protocol/PathAwayProtocolDecoder.java
index aa2de5704..036cfa445 100644
--- a/src/org/traccar/protocol/PathAwayProtocolDecoder.java
+++ b/src/org/traccar/protocol/PathAwayProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/PiligrimProtocol.java b/src/org/traccar/protocol/PiligrimProtocol.java
index 0ab529d5c..a2960f762 100644
--- a/src/org/traccar/protocol/PiligrimProtocol.java
+++ b/src/org/traccar/protocol/PiligrimProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
index 47f73fe8f..9d5bb9e24 100644
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/ProgressProtocol.java b/src/org/traccar/protocol/ProgressProtocol.java
index 3fb702b7b..6e2093346 100644
--- a/src/org/traccar/protocol/ProgressProtocol.java
+++ b/src/org/traccar/protocol/ProgressProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 0032a9a1b..9e24efc38 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2014 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.
diff --git a/src/org/traccar/protocol/Pt3000Protocol.java b/src/org/traccar/protocol/Pt3000Protocol.java
index c4cb4129d..9c9da3301 100644
--- a/src/org/traccar/protocol/Pt3000Protocol.java
+++ b/src/org/traccar/protocol/Pt3000Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
index 88ffb0616..d25d96150 100644
--- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java
index 95289929e..200012965 100644
--- a/src/org/traccar/protocol/Pt502FrameDecoder.java
+++ b/src/org/traccar/protocol/Pt502FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/Pt502Protocol.java b/src/org/traccar/protocol/Pt502Protocol.java
index b609927ac..a15938dc3 100644
--- a/src/org/traccar/protocol/Pt502Protocol.java
+++ b/src/org/traccar/protocol/Pt502Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
index 24dc2094f..2d3cb9101 100644
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
* Copyright 2012 Luis Parada (luis.parada@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/src/org/traccar/protocol/Pt502ProtocolEncoder.java b/src/org/traccar/protocol/Pt502ProtocolEncoder.java
index d8aeb6e5d..5f7665e50 100644
--- a/src/org/traccar/protocol/Pt502ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/RaveonProtocol.java b/src/org/traccar/protocol/RaveonProtocol.java
index a81d52f0e..e4e100e0b 100644
--- a/src/org/traccar/protocol/RaveonProtocol.java
+++ b/src/org/traccar/protocol/RaveonProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/RaveonProtocolDecoder.java b/src/org/traccar/protocol/RaveonProtocolDecoder.java
index d6942da6f..19a9d6314 100644
--- a/src/org/traccar/protocol/RaveonProtocolDecoder.java
+++ b/src/org/traccar/protocol/RaveonProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/RitiProtocol.java b/src/org/traccar/protocol/RitiProtocol.java
index 8a39c29e1..0ff3ce87b 100644
--- a/src/org/traccar/protocol/RitiProtocol.java
+++ b/src/org/traccar/protocol/RitiProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java
index 455c1387a..1ca517057 100644
--- a/src/org/traccar/protocol/RitiProtocolDecoder.java
+++ b/src/org/traccar/protocol/RitiProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/RuptelaProtocol.java b/src/org/traccar/protocol/RuptelaProtocol.java
index 1fe7b02ad..54cdcc267 100644
--- a/src/org/traccar/protocol/RuptelaProtocol.java
+++ b/src/org/traccar/protocol/RuptelaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
index 224c027f3..461f9abc0 100644
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -35,6 +35,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
}
public static final int MSG_RECORDS = 1;
+ public static final int MSG_EXTENDED_RECORDS = 68;
public static final int MSG_SMS_VIA_GPRS = 108;
@Override
@@ -53,7 +54,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
int type = buf.readUnsignedByte();
- if (type == MSG_RECORDS) {
+ if (type == MSG_RECORDS || type == MSG_EXTENDED_RECORDS) {
List<Position> positions = new LinkedList<>();
buf.readUnsignedByte(); // records left
@@ -67,45 +68,56 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date(buf.readUnsignedInt() * 1000));
buf.readUnsignedByte(); // timestamp extension
+ if (type == MSG_EXTENDED_RECORDS) {
+ buf.readUnsignedByte(); // record extension
+ }
+
buf.readUnsignedByte(); // priority (reserved)
+ position.setValid(true);
position.setLongitude(buf.readInt() / 10000000.0);
position.setLatitude(buf.readInt() / 10000000.0);
position.setAltitude(buf.readUnsignedShort() / 10.0);
position.setCourse(buf.readUnsignedShort() / 100.0);
- int satellites = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, satellites);
- position.setValid(satellites >= 3);
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.set(Position.KEY_HDOP, buf.readUnsignedByte() / 10.0);
- buf.readUnsignedByte();
+ if (type == MSG_EXTENDED_RECORDS) {
+ buf.readUnsignedShort(); // event
+ } else {
+ buf.readUnsignedByte(); // event
+ }
// Read 1 byte data
int cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedByte());
+ int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
+ position.set(Position.PREFIX_IO + id, buf.readUnsignedByte());
}
// Read 2 byte data
cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedShort());
+ int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
+ position.set(Position.PREFIX_IO + id, buf.readUnsignedShort());
}
// Read 4 byte data
cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readUnsignedInt());
+ int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
+ position.set(Position.PREFIX_IO + id, buf.readUnsignedInt());
}
// Read 8 byte data
cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), buf.readLong());
+ int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
+ position.set(Position.PREFIX_IO + id, buf.readLong());
}
positions.add(position);
diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
index c036870d9..c3b3a3619 100644
--- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/SanavProtocol.java b/src/org/traccar/protocol/SanavProtocol.java
index 0e7958b8e..4f463725e 100644
--- a/src/org/traccar/protocol/SanavProtocol.java
+++ b/src/org/traccar/protocol/SanavProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java
index 103b2d395..606668713 100644
--- a/src/org/traccar/protocol/SanavProtocolDecoder.java
+++ b/src/org/traccar/protocol/SanavProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/SkypatrolProtocol.java b/src/org/traccar/protocol/SkypatrolProtocol.java
index 7d8240294..fba432522 100644
--- a/src/org/traccar/protocol/SkypatrolProtocol.java
+++ b/src/org/traccar/protocol/SkypatrolProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
index d07bb152b..dfe87caf5 100644
--- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2013 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.
diff --git a/src/org/traccar/protocol/SmokeyProtocol.java b/src/org/traccar/protocol/SmokeyProtocol.java
new file mode 100644
index 000000000..4f9a8dd74
--- /dev/null
+++ b/src/org/traccar/protocol/SmokeyProtocol.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.bootstrap.ConnectionlessBootstrap;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.traccar.BaseProtocol;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class SmokeyProtocol extends BaseProtocol {
+
+ public SmokeyProtocol() {
+ super("smokey");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("objectDecoder", new SmokeyProtocolDecoder(SmokeyProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/SmokeyProtocolDecoder.java b/src/org/traccar/protocol/SmokeyProtocolDecoder.java
new file mode 100644
index 000000000..86496fba6
--- /dev/null
+++ b/src/org/traccar/protocol/SmokeyProtocolDecoder.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+
+public class SmokeyProtocolDecoder extends BaseProtocolDecoder {
+
+ public SmokeyProtocolDecoder(SmokeyProtocol protocol) {
+ super(protocol);
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.skipBytes(2); // header
+ buf.readUnsignedByte(); // protocol version
+
+ int type = buf.readUnsignedByte();
+
+ String id = ChannelBuffers.hexDump(buf.readBytes(8));
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ if (type == 0) {
+
+ /*if (channel != null) {
+ // TODO send ack
+ }*/
+
+ buf.readUnsignedShort(); // firmware version
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.set(Position.KEY_STATUS, buf.readUnsignedByte());
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(2000, 1, 1).addSeconds(buf.readUnsignedInt());
+
+ getLastLocation(position, dateBuilder.getDate());
+
+ position.set(Position.KEY_INDEX, buf.readUnsignedByte());
+
+ buf.readUnsignedShort(); // task / parameter number
+
+ buf.readUnsignedShort(); // length
+
+ // data
+
+ return position;
+
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/Stl060FrameDecoder.java b/src/org/traccar/protocol/Stl060FrameDecoder.java
index f11d86564..455a869ee 100644
--- a/src/org/traccar/protocol/Stl060FrameDecoder.java
+++ b/src/org/traccar/protocol/Stl060FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/Stl060Protocol.java b/src/org/traccar/protocol/Stl060Protocol.java
index ccdd256d7..6fe2c5181 100644
--- a/src/org/traccar/protocol/Stl060Protocol.java
+++ b/src/org/traccar/protocol/Stl060Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
index 86b097f77..fa789510e 100644
--- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 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.
diff --git a/src/org/traccar/protocol/SuntechProtocol.java b/src/org/traccar/protocol/SuntechProtocol.java
index df6109722..410dc8af7 100644
--- a/src/org/traccar/protocol/SuntechProtocol.java
+++ b/src/org/traccar/protocol/SuntechProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index 503f4d6f8..c9235f47f 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/SuntechProtocolEncoder.java b/src/org/traccar/protocol/SuntechProtocolEncoder.java
index 000583759..4a2b230f2 100644
--- a/src/org/traccar/protocol/SuntechProtocolEncoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/SupermateProtocol.java b/src/org/traccar/protocol/SupermateProtocol.java
index 70c3c00e6..c9ae86fc1 100755
--- a/src/org/traccar/protocol/SupermateProtocol.java
+++ b/src/org/traccar/protocol/SupermateProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/SupermateProtocolDecoder.java b/src/org/traccar/protocol/SupermateProtocolDecoder.java
index f673bff40..7f12121bb 100755
--- a/src/org/traccar/protocol/SupermateProtocolDecoder.java
+++ b/src/org/traccar/protocol/SupermateProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/T55Protocol.java b/src/org/traccar/protocol/T55Protocol.java
index 657155042..402fd46b8 100644
--- a/src/org/traccar/protocol/T55Protocol.java
+++ b/src/org/traccar/protocol/T55Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
index 1909d9bea..faf9c4b7d 100644
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T55ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/T800xProtocol.java b/src/org/traccar/protocol/T800xProtocol.java
index 05650124c..70341d0dc 100644
--- a/src/org/traccar/protocol/T800xProtocol.java
+++ b/src/org/traccar/protocol/T800xProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java
index d92145e05..52d711a8d 100644
--- a/src/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/org/traccar/protocol/T800xProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/T800xProtocolEncoder.java b/src/org/traccar/protocol/T800xProtocolEncoder.java
index d603328e2..7b02ed10b 100644
--- a/src/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/org/traccar/protocol/T800xProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/TaipProtocol.java b/src/org/traccar/protocol/TaipProtocol.java
index 8b93eb42d..c3d934c04 100644
--- a/src/org/traccar/protocol/TaipProtocol.java
+++ b/src/org/traccar/protocol/TaipProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java
index 11acbd343..7927c28e6 100644
--- a/src/org/traccar/protocol/TaipProtocolDecoder.java
+++ b/src/org/traccar/protocol/TaipProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/TelicFrameDecoder.java b/src/org/traccar/protocol/TelicFrameDecoder.java
index 2a6e121cf..245be28fb 100644
--- a/src/org/traccar/protocol/TelicFrameDecoder.java
+++ b/src/org/traccar/protocol/TelicFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/TelicProtocol.java b/src/org/traccar/protocol/TelicProtocol.java
index b55e16caf..fdd0b94c6 100644
--- a/src/org/traccar/protocol/TelicProtocol.java
+++ b/src/org/traccar/protocol/TelicProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java
index 376ff4c84..4d496426d 100644
--- a/src/org/traccar/protocol/TelicProtocolDecoder.java
+++ b/src/org/traccar/protocol/TelicProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 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.
diff --git a/src/org/traccar/protocol/TeltonikaFrameDecoder.java b/src/org/traccar/protocol/TeltonikaFrameDecoder.java
index f8add090b..e7313b722 100644
--- a/src/org/traccar/protocol/TeltonikaFrameDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/TeltonikaProtocol.java b/src/org/traccar/protocol/TeltonikaProtocol.java
index c9c0f0f4d..f0ed61886 100644
--- a/src/org/traccar/protocol/TeltonikaProtocol.java
+++ b/src/org/traccar/protocol/TeltonikaProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 00ab90ce0..474718ee8 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
diff --git a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
index d91f7f7bf..eb83477b8 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/ThinkRaceProtocol.java b/src/org/traccar/protocol/ThinkRaceProtocol.java
index add7d33d3..98f43e2e3 100644
--- a/src/org/traccar/protocol/ThinkRaceProtocol.java
+++ b/src/org/traccar/protocol/ThinkRaceProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
index 2c49cccaf..f78f01329 100644
--- a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
+++ b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Tk102Protocol.java b/src/org/traccar/protocol/Tk102Protocol.java
index 7310d23bd..962f2401b 100644
--- a/src/org/traccar/protocol/Tk102Protocol.java
+++ b/src/org/traccar/protocol/Tk102Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -17,10 +17,8 @@ package org.traccar.protocol;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
+import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
-import org.traccar.CharacterDelimiterFrameDecoder;
import org.traccar.TrackerServer;
import java.util.List;
@@ -36,9 +34,7 @@ public class Tk102Protocol extends BaseProtocol {
serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, ']'));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 1 + 1 + 10, 1, 1, 0));
pipeline.addLast("objectDecoder", new Tk102ProtocolDecoder(Tk102Protocol.this));
}
});
diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
index bb7510eb1..c2a94257d 100644
--- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -15,6 +15,8 @@
*/
package org.traccar.protocol;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
@@ -24,6 +26,7 @@ import org.traccar.helper.PatternBuilder;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
@@ -32,11 +35,18 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
+ public static final int MSG_LOGIN_REQUEST = 0x80;
+ public static final int MSG_LOGIN_REQUEST_2 = 0x21;
+ public static final int MSG_LOGIN_RESPONSE = 0x00;
+ public static final int MSG_HEARTBEAT_REQUEST = 0xF0;
+ public static final int MSG_HEARTBEAT_RESPONSE = 0xFF;
+ public static final int MSG_REPORT_ONCE = 0x90;
+ public static final int MSG_REPORT_INTERVAL = 0x93;
+
+ public static final int MODE_GPRS = 0x30;
+ public static final int MODE_GPRS_SMS = 0x33;
+
private static final Pattern PATTERN = new PatternBuilder()
- .text("[")
- .expression(".")
- .number("d{10}")
- .expression(".")
.text("(")
.expression("[A-Z]+")
.number("(dd)(dd)(dd)") // time
@@ -45,25 +55,56 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
.number("(ddd)(dd.dddd)([EW])") // longitude
.number("(ddd.ddd)") // speed
.number("(dd)(dd)(dd)") // date (ddmmyy)
- .number("d+")
.any()
.text(")")
- .text("]").optional()
.compile();
+ private void sendResponse(Channel channel, int type, ChannelBuffer dataSequence, ChannelBuffer content) {
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeByte('[');
+ response.writeByte(type);
+ response.writeBytes(dataSequence);
+ response.writeByte(content.readableBytes());
+ response.writeBytes(content);
+ response.writeByte(']');
+ channel.write(response);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- String sentence = (String) msg;
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.skipBytes(1); // header
+ int type = buf.readUnsignedByte();
+ ChannelBuffer dataSequence = buf.readBytes(10);
+ int length = buf.readUnsignedByte();
- if (sentence.startsWith("[!")) {
+ if (type == MSG_LOGIN_REQUEST || type == MSG_LOGIN_REQUEST_2) {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(14, 14 + 15));
- if (deviceSession != null && channel != null) {
- channel.write("[”0000000001" + sentence.substring(13) + "]");
+ ChannelBuffer data = buf.readBytes(length);
+
+ String id;
+ if (type == MSG_LOGIN_REQUEST) {
+ id = data.toString(StandardCharsets.US_ASCII);
+ } else {
+ id = data.copy(1, 15).toString(StandardCharsets.US_ASCII);
+ }
+
+ if (getDeviceSession(channel, remoteAddress, id) != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+ response.writeByte(MODE_GPRS);
+ response.writeBytes(data);
+ sendResponse(channel, MSG_LOGIN_RESPONSE, dataSequence, response);
}
+ } else if (type == MSG_HEARTBEAT_REQUEST) {
+
+ sendResponse(channel, MSG_HEARTBEAT_RESPONSE, dataSequence, buf.readBytes(length));
+
} else {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
@@ -71,7 +112,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Parser parser = new Parser(PATTERN, sentence);
+ Parser parser = new Parser(PATTERN, buf.readBytes(length).toString(StandardCharsets.US_ASCII));
if (!parser.matches()) {
return null;
}
@@ -92,6 +133,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
position.setTime(dateBuilder.getDate());
return position;
+
}
return null;
diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java
index 3fe82ad8b..1520e88f6 100644
--- a/src/org/traccar/protocol/Tk103Protocol.java
+++ b/src/org/traccar/protocol/Tk103Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index c638e7f27..9d04483c1 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/Tlt2hProtocol.java b/src/org/traccar/protocol/Tlt2hProtocol.java
index e33b1b561..752b0d8ef 100644
--- a/src/org/traccar/protocol/Tlt2hProtocol.java
+++ b/src/org/traccar/protocol/Tlt2hProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index 6a58d6dcb..7df671109 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/TopflytechProtocol.java b/src/org/traccar/protocol/TopflytechProtocol.java
index 225cb66d7..7d4b13ee6 100644
--- a/src/org/traccar/protocol/TopflytechProtocol.java
+++ b/src/org/traccar/protocol/TopflytechProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
index 04f379557..0be411246 100644
--- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java
+++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java
index 374161758..6940d7b46 100644
--- a/src/org/traccar/protocol/TotemFrameDecoder.java
+++ b/src/org/traccar/protocol/TotemFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/TotemProtocol.java b/src/org/traccar/protocol/TotemProtocol.java
index 638755b7f..860fff894 100644
--- a/src/org/traccar/protocol/TotemProtocol.java
+++ b/src/org/traccar/protocol/TotemProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index fbda41921..1fe91b942 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2016 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.
@@ -138,9 +138,11 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
.number("(dd)") // external power
.number("(dddd)") // adc 1
.groupBegin()
+ .groupBegin()
.number("(dddd)") // adc 2
.number("(dddd)") // adc 3
.number("(dddd)") // adc 4
+ .groupEnd("?")
.number("(dddd)") // temperature 1
.number("(dddd)") // temperature 2
.groupEnd("?")
diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java
index 5e0ca407a..ff41a7df3 100644
--- a/src/org/traccar/protocol/TotemProtocolEncoder.java
+++ b/src/org/traccar/protocol/TotemProtocolEncoder.java
@@ -1,6 +1,6 @@
/*
* Copyright 2015 Irving Gonzalez
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/Tr20Protocol.java b/src/org/traccar/protocol/Tr20Protocol.java
index 1c47db86a..8de004be9 100644
--- a/src/org/traccar/protocol/Tr20Protocol.java
+++ b/src/org/traccar/protocol/Tr20Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
index 54b303b5d..20f7d2968 100644
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
diff --git a/src/org/traccar/protocol/Tr900Protocol.java b/src/org/traccar/protocol/Tr900Protocol.java
index d54e4cb3c..40f287efa 100644
--- a/src/org/traccar/protocol/Tr900Protocol.java
+++ b/src/org/traccar/protocol/Tr900Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
index 8dfff9e41..32362acd2 100644
--- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TrackboxProtocol.java b/src/org/traccar/protocol/TrackboxProtocol.java
index b71eb3810..c1aa5ac6a 100644
--- a/src/org/traccar/protocol/TrackboxProtocol.java
+++ b/src/org/traccar/protocol/TrackboxProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
index 89253b891..f909e8488 100644
--- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 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.
diff --git a/src/org/traccar/protocol/TrakMateProtocol.java b/src/org/traccar/protocol/TrakMateProtocol.java
new file mode 100644
index 000000000..f6d9bf457
--- /dev/null
+++ b/src/org/traccar/protocol/TrakMateProtocol.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.handler.codec.string.StringDecoder;
+import org.jboss.netty.handler.codec.string.StringEncoder;
+import org.traccar.BaseProtocol;
+import org.traccar.CharacterDelimiterFrameDecoder;
+import org.traccar.TrackerServer;
+
+import java.util.List;
+
+public class TrakMateProtocol extends BaseProtocol {
+
+ public TrakMateProtocol() {
+ super("trakmate");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '#'));
+ pipeline.addLast("stringEncoder", new StringEncoder());
+ pipeline.addLast("stringDecoder", new StringDecoder());
+ pipeline.addLast("objectDecoder", new TrakMateProtocolDecoder(TrakMateProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java
new file mode 100644
index 000000000..57003e832
--- /dev/null
+++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright 2016 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 org.jboss.netty.channel.Channel;
+import org.traccar.BaseProtocolDecoder;
+import org.traccar.Context;
+import org.traccar.DeviceSession;
+import org.traccar.helper.DateBuilder;
+import org.traccar.helper.Parser;
+import org.traccar.helper.PatternBuilder;
+import org.traccar.model.Position;
+
+import java.net.SocketAddress;
+import java.util.TimeZone;
+import java.util.regex.Pattern;
+
+public class TrakMateProtocolDecoder extends BaseProtocolDecoder {
+
+ private final TimeZone timeZone = TimeZone.getTimeZone("UTC");
+
+ public TrakMateProtocolDecoder(TrakMateProtocol protocol) {
+ super(protocol);
+ timeZone.setRawOffset(Context.getConfig().getInteger(getProtocolName() + ".timezone") * 1000);
+ }
+
+ private static final Pattern PATTERN_SRT = new PatternBuilder()
+ .text("^TMSRT|")
+ .expression("([^ ]+)|") // uid
+ .number("(d+.d+)|") // latitude
+ .number("(d+.d+)|") // longitude
+ .number("(dd)(dd)(dd)|") // time
+ .number("(dd)(dd)(dd)|") // date
+ .number("(d+.d+)|") // software ver
+ .number("(d+.d+)|") // Hardware ver
+ .any()
+ .compile();
+
+ private static final Pattern PATTERN_PER = new PatternBuilder()
+ .text("^TMPER|")
+ .expression("([^ ]+)|") // uid
+ .number("(d+)|") // seq
+ .number("(d+.d+)|") // latitude
+ .number("(d+.d+)|") // longitude
+ .number("(dd)(dd)(dd)|") // time
+ .number("(dd)(dd)(dd)|") // date
+ .number("(d+.d+)|") // speed
+ .number("(d+.d+)|") // heading
+ .number("(d+)|") // ignition
+ .number("(d+)|") // dop1
+ .number("(d+)|") // dop2
+ .number("(d+.d+)|") // analog
+ .number("(d+.d+)|") // internal battery
+ .number("(d+.d+)|") // vehicle battery
+ .number("(d+.d+)|") // gps odometer
+ .number("(d+.d+)|") // pulse odometer
+ .number("(d+)|") // main power status
+ .number("(d+)|") // gps data validity
+ .number("(d+)|") // live or cache
+ .any()
+ .compile();
+
+ private static final Pattern PATTERN_ALT = new PatternBuilder()
+ .text("^TMALT|")
+ .expression("([^ ]+)|") // uid
+ .number("(d+)|") // seq
+ .number("(d+)|") // Alert type
+ .number("(d+)|") // Alert status
+ .number("(d+.d+)|") // latitude
+ .number("(d+.d+)|") // longitude
+ .number("(dd)(dd)(dd)|") // time
+ .number("(dd)(dd)(dd)|") // date
+ .number("(d+.d+)|") // speed
+ .number("(d+.d+)|") // heading
+ .any()
+ .compile();
+
+ private String decodeAlarm(int value) {
+ switch (value) {
+ case 1:
+ return Position.ALARM_SOS;
+ case 3:
+ return Position.ALARM_GEOFENCE;
+ case 4:
+ return Position.ALARM_POWER_CUT;
+ default:
+ return null;
+ }
+ }
+
+ private Object decodeSrt(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_SRT, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+
+ DateBuilder dateBuilder = new DateBuilder(timeZone)
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.set(Position.KEY_VERSION, parser.next());
+ parser.next(); // hardware version
+
+ return position;
+ }
+
+ private Object decodeAlt(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_ALT, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ parser.next(); // seq
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt()));
+ parser.next(); // alert status or data
+
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+
+ DateBuilder dateBuilder = new DateBuilder(timeZone)
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ return position;
+ }
+
+ private Object decodePer(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ Parser parser = new Parser(PATTERN_PER, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ parser.next(); // seq
+
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+
+ DateBuilder dateBuilder = new DateBuilder(timeZone)
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ position.setSpeed(parser.nextDouble());
+ position.setCourse(parser.nextDouble());
+
+ position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
+ parser.next(); // dop1
+ parser.next(); // dop2
+ parser.next(); // analog input
+ position.set(Position.KEY_BATTERY, parser.nextDouble()); // device battery voltage
+ parser.next(); // vehicle internal voltage
+ position.set(Position.KEY_ODOMETER, parser.nextDouble()); // gps odometer
+ parser.next(); // pulse odometer
+ position.set(Position.KEY_STATUS, parser.nextInt());
+
+ position.setValid(parser.nextInt() != 0);
+
+ position.set(Position.KEY_ARCHIVE, parser.nextInt() == 1);
+
+ return position;
+ }
+
+ @Override
+ protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+ int typeIndex = sentence.indexOf("^TM");
+ if (typeIndex < 0) {
+ return null;
+ }
+
+ String type = sentence.substring(typeIndex + 3, typeIndex + 6);
+ switch (type) {
+ case "ALT":
+ return decodeAlt(channel, remoteAddress, sentence);
+ case "SRT":
+ return decodeSrt(channel, remoteAddress, sentence);
+ case "PER":
+ return decodePer(channel, remoteAddress, sentence);
+ default:
+ return null;
+ }
+ }
+
+}
diff --git a/src/org/traccar/protocol/TramigoFrameDecoder.java b/src/org/traccar/protocol/TramigoFrameDecoder.java
index 4178fba8d..20992c04b 100644
--- a/src/org/traccar/protocol/TramigoFrameDecoder.java
+++ b/src/org/traccar/protocol/TramigoFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TramigoProtocol.java b/src/org/traccar/protocol/TramigoProtocol.java
index ea4ea7140..28673c97b 100644
--- a/src/org/traccar/protocol/TramigoProtocol.java
+++ b/src/org/traccar/protocol/TramigoProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java
index af81616d8..9affa08b9 100644
--- a/src/org/traccar/protocol/TramigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 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.
@@ -43,6 +43,8 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_COMPACT = 0x0100;
public static final int MSG_FULL = 0x00FE;
+ private static final String[] DIRECTIONS = new String[] {"N", "NE", "E", "SE", "S", "SW", "W", "NW"};
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -119,8 +121,13 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
pattern = Pattern.compile("([NSWE]{1,2}) with speed (\\d+) km/h");
matcher = pattern.matcher(sentence);
if (matcher.find()) {
+ for (int i = 0; i < DIRECTIONS.length; i++) {
+ if (matcher.group(1).equals(DIRECTIONS[i])) {
+ position.setCourse(i * 45.0);
+ break;
+ }
+ }
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(matcher.group(2))));
- position.setCourse(0); // matcher.group(1) for course
}
pattern = Pattern.compile("(\\d{1,2}:\\d{2} \\w{3} \\d{1,2})");
diff --git a/src/org/traccar/protocol/TrvProtocol.java b/src/org/traccar/protocol/TrvProtocol.java
index 585cb7cf6..348ccd92a 100644
--- a/src/org/traccar/protocol/TrvProtocol.java
+++ b/src/org/traccar/protocol/TrvProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java
index 42f8d313c..0afe065c2 100644
--- a/src/org/traccar/protocol/TrvProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrvProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Tt8850Protocol.java b/src/org/traccar/protocol/Tt8850Protocol.java
index 5d188de60..79dc031bc 100644
--- a/src/org/traccar/protocol/Tt8850Protocol.java
+++ b/src/org/traccar/protocol/Tt8850Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
index 39fedc138..b128068be 100644
--- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/TytanProtocol.java b/src/org/traccar/protocol/TytanProtocol.java
index b6608f925..0c27fb12b 100644
--- a/src/org/traccar/protocol/TytanProtocol.java
+++ b/src/org/traccar/protocol/TytanProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index 7b5dc5ffe..b67902e56 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TzoneProtocol.java b/src/org/traccar/protocol/TzoneProtocol.java
index ca3e490d2..38d5b139a 100644
--- a/src/org/traccar/protocol/TzoneProtocol.java
+++ b/src/org/traccar/protocol/TzoneProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java
index 477dc6399..8fd695b80 100644
--- a/src/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/UlbotechFrameDecoder.java b/src/org/traccar/protocol/UlbotechFrameDecoder.java
index 09c1db717..8e7b497c5 100644
--- a/src/org/traccar/protocol/UlbotechFrameDecoder.java
+++ b/src/org/traccar/protocol/UlbotechFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2015 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.
diff --git a/src/org/traccar/protocol/UlbotechProtocol.java b/src/org/traccar/protocol/UlbotechProtocol.java
index ca31dffc9..40f4594a5 100644
--- a/src/org/traccar/protocol/UlbotechProtocol.java
+++ b/src/org/traccar/protocol/UlbotechProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index 9a951f770..d2a58f1b8 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -55,7 +55,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
private static final short DATA_RFID = 0x0E;
private static final short DATA_EVENT = 0x10;
- private void decodeObd(Position position, ChannelBuffer buf, short length) {
+ private void decodeObd(Position position, ChannelBuffer buf, int length) {
int end = buf.readerIndex() + length;
@@ -66,7 +66,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
}
}
- private void decodeJ1708(Position position, ChannelBuffer buf, short length) {
+ private void decodeJ1708(Position position, ChannelBuffer buf, int length) {
int end = buf.readerIndex() + length;
@@ -166,8 +166,8 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 3) {
- short type = buf.readUnsignedByte();
- short length = buf.readUnsignedByte();
+ int type = buf.readUnsignedByte();
+ int length = type == DATA_CANBUS ? buf.readUnsignedShort() : buf.readUnsignedByte();
switch (type) {
diff --git a/src/org/traccar/protocol/UproProtocol.java b/src/org/traccar/protocol/UproProtocol.java
index 8f940fa15..ae6cac603 100644
--- a/src/org/traccar/protocol/UproProtocol.java
+++ b/src/org/traccar/protocol/UproProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java
index b4000c37a..24a0f5dcd 100644
--- a/src/org/traccar/protocol/UproProtocolDecoder.java
+++ b/src/org/traccar/protocol/UproProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -33,18 +34,56 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
}
private static final Pattern PATTERN = new PatternBuilder()
- .text("*AI20")
+ .text("*")
+ .expression("..20")
+ .expression("([01])") // ack
.number("(d+),") // device id
- .expression("A.+&A")
+ .expression("(.)") // type
+ .expression("(.)") // subtype
+ .expression("(.*)") // content
+ .expression("#?") // delimiter
+ .compile();
+
+ private static final Pattern PATTERN_LOCATION = new PatternBuilder()
+ .text("A")
.number("(dd)(dd)(dd)") // time
.number("(dd)(dd)(dddd)") // latitude
.number("(ddd)(dd)(dddd)") // longitude
- .number("d{5}")
+ .number("(d)") // flags
+ .number("(dd)") // speed
+ .number("(dd)") // course
.number("(dd)(dd)(dd)") // date
- .expression("&B")
- .any()
.compile();
+ private void decodeLocation(Position position, String data) {
+ Parser parser = new Parser(PATTERN_LOCATION, data);
+ if (parser.matches()) {
+
+ DateBuilder dateBuilder = new DateBuilder()
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.setValid(true);
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
+
+ int flags = parser.nextInt();
+ position.setValid(BitUtil.check(flags, 0));
+ if (!BitUtil.check(flags, 1)) {
+ position.setLatitude(-position.getLatitude());
+ }
+ if (!BitUtil.check(flags, 2)) {
+ position.setLongitude(-position.getLongitude());
+ }
+
+ position.setSpeed(parser.nextInt() * 2);
+ position.setCourse(parser.nextInt() * 10);
+
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -54,26 +93,62 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ boolean reply = parser.next().equals("1");
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ String type = parser.next();
+ String subtype = parser.next();
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
+ if (reply && channel != null) {
+ channel.write("*MG20Y" + type + subtype + "#");
+ }
- dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
- position.setTime(dateBuilder.getDate());
+ String[] data = parser.next().split("&");
+ for (int i = 0; i < data.length; i++) {
+ if (i != 0) {
+ switch (data[i].charAt(0)) {
+ case 'A':
+ decodeLocation(position, data[i]);
+ break;
+ case 'B':
+ position.set(Position.KEY_STATUS, data[i].substring(1));
+ break;
+ case 'C':
+ long odometer = 0;
+ for (int j = 1; j < data[i].length(); j++) {
+ odometer <<= 4;
+ odometer += data[i].charAt(j) - '0';
+ }
+ position.set(Position.KEY_ODOMETER, odometer * 2 * 1852 / 3600);
+ break;
+ case 'P':
+ position.set(Position.KEY_MCC, Integer.parseInt(data[i].substring(1, 5)));
+ position.set(Position.KEY_MNC, Integer.parseInt(data[i].substring(5, 9)));
+ position.set(Position.KEY_LAC, Integer.parseInt(data[i].substring(9, 13), 16));
+ position.set(Position.KEY_CID, Integer.parseInt(data[i].substring(13, 17), 16));
+ break;
+ case 'S':
+ position.set("obd", data[i]);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (position.getLatitude() != 0 && position.getLongitude() != 0) {
+ return position;
+ }
- return position;
+ return null;
}
}
diff --git a/src/org/traccar/protocol/V680Protocol.java b/src/org/traccar/protocol/V680Protocol.java
index 83157790d..98c64830b 100644
--- a/src/org/traccar/protocol/V680Protocol.java
+++ b/src/org/traccar/protocol/V680Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java
index 29ac4fd90..ca9c451c2 100644
--- a/src/org/traccar/protocol/V680ProtocolDecoder.java
+++ b/src/org/traccar/protocol/V680ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -43,10 +43,8 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+)#") // packet number
.expression("([^#]+)?#?") // gsm base station
.expression("(?:[^#]+#)?")
- .number("(d+)?(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+)?(dd.d+),") // latitude
- .expression("([NS]),")
+ .number("(d+.d+),([EW]),") // longitude
+ .number("(d+.d+),([NS]),") // latitude
.number("(d+.d+),") // speed
.number("(d+.?d*)?#") // course
.number("(dd)(dd)(dd)#") // date
@@ -93,8 +91,24 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
position.set("packet", parser.next());
position.set(Position.KEY_GSM, parser.next());
- position.setLongitude(parser.nextCoordinate());
- position.setLatitude(parser.nextCoordinate());
+ double lon = parser.nextDouble();
+ boolean west = parser.next().equals("W");
+ double lat = parser.nextDouble();
+ boolean south = parser.next().equals("S");
+
+ if (lat > 90 || lon > 180) {
+ int lonDegrees = (int) (lon * 0.01);
+ lon = (lon - lonDegrees * 100) / 60.0;
+ lon += lonDegrees;
+
+ int latDegrees = (int) (lat * 0.01);
+ lat = (lat - latDegrees * 100) / 60.0;
+ lat += latDegrees;
+ }
+
+ position.setLongitude(west ? -lon : lon);
+ position.setLatitude(south ? -lat : lat);
+
position.setSpeed(parser.nextDouble());
position.setCourse(parser.nextDouble());
diff --git a/src/org/traccar/protocol/VisiontekProtocol.java b/src/org/traccar/protocol/VisiontekProtocol.java
index dde906370..c6dd09562 100644
--- a/src/org/traccar/protocol/VisiontekProtocol.java
+++ b/src/org/traccar/protocol/VisiontekProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
index 49c5dcc44..5ce12bd19 100644
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 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.
diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java
index 8f28916f0..b13fcfb11 100644
--- a/src/org/traccar/protocol/WatchProtocol.java
+++ b/src/org/traccar/protocol/WatchProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index d74fdbe81..13eb73254 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
index dc07a1046..f15c0f0c0 100644
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/org/traccar/protocol/WatchProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/WialonProtocol.java b/src/org/traccar/protocol/WialonProtocol.java
index 98af6973b..04e18cd85 100644
--- a/src/org/traccar/protocol/WialonProtocol.java
+++ b/src/org/traccar/protocol/WialonProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 538ee51ca..e3db1f8f0 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 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.
diff --git a/src/org/traccar/protocol/WialonProtocolEncoder.java b/src/org/traccar/protocol/WialonProtocolEncoder.java
index d3a0fc3b9..9c60a1356 100644
--- a/src/org/traccar/protocol/WialonProtocolEncoder.java
+++ b/src/org/traccar/protocol/WialonProtocolEncoder.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/protocol/WondexFrameDecoder.java b/src/org/traccar/protocol/WondexFrameDecoder.java
index ac1622350..db65ff80f 100644
--- a/src/org/traccar/protocol/WondexFrameDecoder.java
+++ b/src/org/traccar/protocol/WondexFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 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.
diff --git a/src/org/traccar/protocol/WondexProtocol.java b/src/org/traccar/protocol/WondexProtocol.java
index 54b39a5c4..0cc21d2b4 100644
--- a/src/org/traccar/protocol/WondexProtocol.java
+++ b/src/org/traccar/protocol/WondexProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index 0fcb99578..491252bf6 100644
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2015 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.
diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java
index c350838d0..8f9887b10 100644
--- a/src/org/traccar/protocol/WondexProtocolEncoder.java
+++ b/src/org/traccar/protocol/WondexProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2016 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.
diff --git a/src/org/traccar/protocol/XexunFrameDecoder.java b/src/org/traccar/protocol/XexunFrameDecoder.java
index 184e2f57b..801fb4d59 100644
--- a/src/org/traccar/protocol/XexunFrameDecoder.java
+++ b/src/org/traccar/protocol/XexunFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/XexunProtocol.java b/src/org/traccar/protocol/XexunProtocol.java
index ecaf18db4..2aea2f246 100644
--- a/src/org/traccar/protocol/XexunProtocol.java
+++ b/src/org/traccar/protocol/XexunProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java
index 06f255b91..5e390a4b7 100644
--- a/src/org/traccar/protocol/XexunProtocolDecoder.java
+++ b/src/org/traccar/protocol/XexunProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
diff --git a/src/org/traccar/protocol/XirgoProtocol.java b/src/org/traccar/protocol/XirgoProtocol.java
index 9298f71ad..9d7475308 100644
--- a/src/org/traccar/protocol/XirgoProtocol.java
+++ b/src/org/traccar/protocol/XirgoProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
index edab1af11..f20f4ef35 100644
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/protocol/Xt013Protocol.java b/src/org/traccar/protocol/Xt013Protocol.java
index db9d21333..ad3e24df0 100644
--- a/src/org/traccar/protocol/Xt013Protocol.java
+++ b/src/org/traccar/protocol/Xt013Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
index b5c222ba6..68497980b 100644
--- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/YwtProtocol.java b/src/org/traccar/protocol/YwtProtocol.java
index e24c8b02e..412365ecb 100644
--- a/src/org/traccar/protocol/YwtProtocol.java
+++ b/src/org/traccar/protocol/YwtProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 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.
diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java
index da5a86175..85f1264a8 100644
--- a/src/org/traccar/protocol/YwtProtocolDecoder.java
+++ b/src/org/traccar/protocol/YwtProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2013 - 2014 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.
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
index ed7e9e411..9d82b97a5 100644
--- a/src/org/traccar/reports/Events.java
+++ b/src/org/traccar/reports/Events.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,47 +16,118 @@
*/
package org.traccar.reports;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
+import org.jxls.area.Area;
+import org.jxls.builder.xls.XlsCommentAreaBuilder;
+import org.jxls.common.CellRef;
+import org.jxls.formula.StandardFormulaProcessor;
+import org.jxls.transform.Transformer;
+import org.jxls.transform.poi.PoiTransformer;
+import org.jxls.util.TransformerFactory;
import org.traccar.Context;
+import org.traccar.model.Device;
import org.traccar.model.Event;
-import org.traccar.web.CsvBuilder;
-import org.traccar.web.JsonConverter;
+import org.traccar.model.Geofence;
+import org.traccar.model.Group;
+import org.traccar.reports.model.DeviceReport;
public final class Events {
private Events() {
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<Event> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ ArrayList<Event> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- for (String type : types) {
- for (Event event : Context.getDataManager().getEvents(deviceId, type, from, to)) {
- json.add(JsonConverter.objectToJson(event));
+ Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
+ boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
+ for (Event event : events) {
+ if (all || types.contains(event.getType())) {
+ long geofenceId = event.getGeofenceId();
+ if (geofenceId == 0 || Context.getGeofenceManager().checkGeofence(userId, geofenceId)) {
+ result.add(event);
+ }
}
}
}
- return json.build().toString();
+ return result;
}
- public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Collection<String> types, Date from, Date to) throws SQLException {
- CsvBuilder csv = new CsvBuilder();
- csv.addHeaderLine(new Event());
+ public static void getExcel(OutputStream outputStream,
+ long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ Collection<String> types, Date from, Date to) throws SQLException, IOException {
+ ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
+ ArrayList<String> sheetNames = new ArrayList<>();
+ HashMap<Long, String> geofenceNames = new HashMap<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- for (String type : types) {
- csv.addArray(Context.getDataManager().getEvents(deviceId, type, from, to));
+ Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
+ boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
+ for (Iterator<Event> iterator = events.iterator(); iterator.hasNext();) {
+ Event event = iterator.next();
+ if (all || types.contains(event.getType())) {
+ long geofenceId = event.getGeofenceId();
+ if (geofenceId != 0) {
+ if (Context.getGeofenceManager().checkGeofence(userId, geofenceId)) {
+ Geofence geofence = Context.getGeofenceManager().getGeofence(geofenceId);
+ if (geofence != null) {
+ geofenceNames.put(geofenceId, geofence.getName());
+ }
+ } else {
+ iterator.remove();
+ }
+ }
+ } else {
+ iterator.remove();
+ }
+ }
+ DeviceReport deviceEvents = new DeviceReport();
+ Device device = Context.getIdentityManager().getDeviceById(deviceId);
+ deviceEvents.setDeviceName(device.getName());
+ sheetNames.add(deviceEvents.getDeviceName());
+ if (device.getGroupId() != 0) {
+ Group group = Context.getDeviceManager().getGroupById(device.getGroupId());
+ if (group != null) {
+ deviceEvents.setGroupName(group.getName());
+ }
+ }
+ deviceEvents.setObjects(events);
+ devicesEvents.add(deviceEvents);
+ }
+ String templatePath = Context.getConfig().getString("report.templatesPath",
+ "templates/export/");
+ try (InputStream inputStream = new FileInputStream(templatePath + "/events.xlsx")) {
+ org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
+ jxlsContext.putVar("devices", devicesEvents);
+ jxlsContext.putVar("sheetNames", sheetNames);
+ jxlsContext.putVar("geofenceNames", geofenceNames);
+ jxlsContext.putVar("from", from);
+ jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
+ jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]");
+ Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
+ List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
+ for (Area xlsArea : xlsAreas) {
+ xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext);
+ xlsArea.setFormulaProcessor(new StandardFormulaProcessor());
+ xlsArea.processFormulas();
}
+ transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName());
+ transformer.write();
}
- return csv.build();
}
}
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 818920ad5..7fcc767e9 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,20 +16,36 @@
*/
package org.traccar.reports;
+import org.traccar.Context;
+import org.traccar.helper.Log;
+import org.traccar.model.Position;
+
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collection;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-
public final class ReportUtils {
private ReportUtils() {
}
+ public static String getDistanceUnit(long userId) {
+ String unit = Context.getPermissionsManager().getUser(userId).getDistanceUnit();
+ if (unit == null) {
+ unit = Context.getPermissionsManager().getServer().getDistanceUnit();
+ }
+ return unit != null ? unit : "km";
+ }
+
+ public static String getSpeedUnit(long userId) {
+ String unit = Context.getPermissionsManager().getUser(userId).getSpeedUnit();
+ if (unit == null) {
+ unit = Context.getPermissionsManager().getServer().getSpeedUnit();
+ }
+ return unit != null ? unit : "kn";
+ }
+
public static Collection<Long> getDeviceList(Collection<Long> deviceIds, Collection<Long> groupIds) {
Collection<Long> result = new ArrayList<>();
result.addAll(deviceIds);
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java
index 45b81cd8c..b29e04b2e 100644
--- a/src/org/traccar/reports/Route.java
+++ b/src/org/traccar/reports/Route.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,43 +16,85 @@
*/
package org.traccar.reports;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
+import org.jxls.area.Area;
+import org.jxls.builder.xls.XlsCommentAreaBuilder;
+import org.jxls.common.CellRef;
+import org.jxls.formula.StandardFormulaProcessor;
+import org.jxls.transform.Transformer;
+import org.jxls.transform.poi.PoiTransformer;
+import org.jxls.util.TransformerFactory;
import org.traccar.Context;
+import org.traccar.model.Device;
+import org.traccar.model.Group;
import org.traccar.model.Position;
-import org.traccar.web.CsvBuilder;
-import org.traccar.web.JsonConverter;
+import org.traccar.reports.model.DeviceReport;
public final class Route {
private Route() {
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ ArrayList<Position> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- for (Position position : Context.getDataManager().getPositions(deviceId, from, to)) {
- json.add(JsonConverter.objectToJson(position));
- }
+ result.addAll(Context.getDataManager().getPositions(deviceId, from, to));
}
- return json.build().toString();
+ return result;
}
- public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- CsvBuilder csv = new CsvBuilder();
- csv.addHeaderLine(new Position());
+ public static void getExcel(OutputStream outputStream,
+ long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ Date from, Date to) throws SQLException, IOException {
+ ArrayList<DeviceReport> devicesRoutes = new ArrayList<>();
+ ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- csv.addArray(Context.getDataManager().getPositions(deviceId, from, to));
+ Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to);
+ DeviceReport deviceRoutes = new DeviceReport();
+ Device device = Context.getIdentityManager().getDeviceById(deviceId);
+ deviceRoutes.setDeviceName(device.getName());
+ sheetNames.add(deviceRoutes.getDeviceName());
+ if (device.getGroupId() != 0) {
+ Group group = Context.getDeviceManager().getGroupById(device.getGroupId());
+ if (group != null) {
+ deviceRoutes.setGroupName(group.getName());
+ }
+ }
+ deviceRoutes.setObjects(positions);
+ devicesRoutes.add(deviceRoutes);
+ }
+ String templatePath = Context.getConfig().getString("report.templatesPath",
+ "templates/export/");
+ try (InputStream inputStream = new FileInputStream(templatePath + "/route.xlsx")) {
+ org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
+ jxlsContext.putVar("devices", devicesRoutes);
+ jxlsContext.putVar("sheetNames", sheetNames);
+ jxlsContext.putVar("from", from);
+ jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
+ jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]");
+ Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
+ List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
+ for (Area xlsArea : xlsAreas) {
+ xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext);
+ xlsArea.setFormulaProcessor(new StandardFormulaProcessor());
+ xlsArea.processFormulas();
+ }
+ transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName());
+ transformer.write();
}
- return csv.build();
}
}
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
index d4171f644..95a3737a1 100644
--- a/src/org/traccar/reports/Summary.java
+++ b/src/org/traccar/reports/Summary.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,18 +16,20 @@
*/
package org.traccar.reports;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
+import org.jxls.transform.poi.PoiTransformer;
+import org.jxls.util.JxlsHelper;
import org.traccar.Context;
import org.traccar.model.Position;
import org.traccar.reports.model.SummaryReport;
-import org.traccar.web.CsvBuilder;
-import org.traccar.web.JsonConverter;
public final class Summary {
@@ -68,24 +70,31 @@ public final class Summary {
return result;
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ public static Collection<SummaryReport> getObjects(long userId, Collection<Long> deviceIds,
+ Collection<Long> groupIds, Date from, Date to) throws SQLException {
+ ArrayList<SummaryReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- json.add(JsonConverter.objectToJson(calculateSummaryResult(deviceId, from, to)));
+ result.add(calculateSummaryResult(deviceId, from, to));
}
- return json.build().toString();
+ return result;
}
- public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- CsvBuilder csv = new CsvBuilder();
- csv.addHeaderLine(new SummaryReport());
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- csv.addLine(calculateSummaryResult(deviceId, from, to));
+ public static void getExcel(OutputStream outputStream,
+ long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ Date from, Date to) throws SQLException, IOException {
+ Collection<SummaryReport> summaries = getObjects(userId, deviceIds, groupIds, from, to);
+ String templatePath = Context.getConfig().getString("report.templatesPath",
+ "templates/export/");
+ try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) {
+ org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
+ jxlsContext.putVar("summaries", summaries);
+ jxlsContext.putVar("from", from);
+ jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
+ JxlsHelper.getInstance().setUseFastFormulaProcessor(false)
+ .processTemplate(inputStream, outputStream, jxlsContext);
}
- return csv.build();
}
}
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index f0a10edbd..91a080d45 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,19 +16,29 @@
*/
package org.traccar.reports;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-
+import java.util.List;
+
+import org.jxls.area.Area;
+import org.jxls.builder.xls.XlsCommentAreaBuilder;
+import org.jxls.common.CellRef;
+import org.jxls.formula.StandardFormulaProcessor;
+import org.jxls.transform.Transformer;
+import org.jxls.transform.poi.PoiTransformer;
+import org.jxls.util.TransformerFactory;
import org.traccar.Context;
+import org.traccar.model.Device;
+import org.traccar.model.Group;
import org.traccar.model.Position;
+import org.traccar.reports.model.DeviceReport;
import org.traccar.reports.model.TripReport;
-import org.traccar.web.CsvBuilder;
-import org.traccar.web.JsonConverter;
public final class Trips {
@@ -50,16 +60,24 @@ public final class Trips {
}
TripReport trip = new TripReport();
+
long tripDuration = endTrip.getFixTime().getTime() - positions.get(startIndex).getFixTime().getTime();
long deviceId = startTrip.getDeviceId();
trip.setDeviceId(deviceId);
trip.setDeviceName(Context.getIdentityManager().getDeviceById(deviceId).getName());
+
trip.setStartPositionId(startTrip.getId());
+ trip.setStartLat(startTrip.getLatitude());
+ trip.setStartLon(startTrip.getLongitude());
trip.setStartTime(startTrip.getFixTime());
trip.setStartAddress(startTrip.getAddress());
+
trip.setEndPositionId(endTrip.getId());
+ trip.setEndLat(endTrip.getLatitude());
+ trip.setEndLon(endTrip.getLongitude());
trip.setEndTime(endTrip.getFixTime());
trip.setEndAddress(endTrip.getAddress());
+
boolean ignoreOdometer = Context.getDeviceManager()
.lookupConfigBoolean(deviceId, "report.ignoreOdometer", false);
trip.setDistance(ReportUtils.calculateDistance(startTrip, endTrip, !ignoreOdometer));
@@ -145,26 +163,56 @@ public final class Trips {
return result;
}
- public static String getJson(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ public static Collection<TripReport> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws SQLException {
- JsonArrayBuilder json = Json.createArrayBuilder();
+ ArrayList<TripReport> result = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- for (TripReport tripReport : detectTrips(deviceId, from, to)) {
- json.add(JsonConverter.objectToJson(tripReport));
- }
+ result.addAll(detectTrips(deviceId, from, to));
}
- return json.build().toString();
+ return result;
}
- public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- CsvBuilder csv = new CsvBuilder();
- csv.addHeaderLine(new TripReport());
+ public static void getExcel(OutputStream outputStream,
+ long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
+ Date from, Date to) throws SQLException, IOException {
+ ArrayList<DeviceReport> devicesTrips = new ArrayList<>();
+ ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
- csv.addArray(detectTrips(deviceId, from, to));
+ Collection<TripReport> trips = detectTrips(deviceId, from, to);
+ DeviceReport deviceTrips = new DeviceReport();
+ Device device = Context.getIdentityManager().getDeviceById(deviceId);
+ deviceTrips.setDeviceName(device.getName());
+ sheetNames.add(deviceTrips.getDeviceName());
+ if (device.getGroupId() != 0) {
+ Group group = Context.getDeviceManager().getGroupById(device.getGroupId());
+ if (group != null) {
+ deviceTrips.setGroupName(group.getName());
+ }
+ }
+ deviceTrips.setObjects(trips);
+ devicesTrips.add(deviceTrips);
+ }
+ String templatePath = Context.getConfig().getString("report.templatesPath",
+ "templates/export/");
+ try (InputStream inputStream = new FileInputStream(templatePath + "/trips.xlsx")) {
+ org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
+ jxlsContext.putVar("devices", devicesTrips);
+ jxlsContext.putVar("sheetNames", sheetNames);
+ jxlsContext.putVar("from", from);
+ jxlsContext.putVar("to", to);
+ jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId));
+ Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream);
+ List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build();
+ for (Area xlsArea : xlsAreas) {
+ xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext);
+ xlsArea.setFormulaProcessor(new StandardFormulaProcessor());
+ xlsArea.processFormulas();
+ }
+ transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName());
+ transformer.write();
}
- return csv.build();
}
}
diff --git a/src/org/traccar/reports/model/BaseReport.java b/src/org/traccar/reports/model/BaseReport.java
index 246cdede0..c33b9a8dd 100644
--- a/src/org/traccar/reports/model/BaseReport.java
+++ b/src/org/traccar/reports/model/BaseReport.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/reports/model/DeviceReport.java b/src/org/traccar/reports/model/DeviceReport.java
new file mode 100644
index 000000000..58caa809b
--- /dev/null
+++ b/src/org/traccar/reports/model/DeviceReport.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.reports.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class DeviceReport {
+
+ private String deviceName;
+ public String getDeviceName() {
+ return deviceName;
+ }
+ public void setDeviceName(String deviceName) {
+ this.deviceName = deviceName;
+ }
+
+ private String groupName = "";
+ public String getGroupName() {
+ return groupName;
+ }
+ public void setGroupName(String groupName) {
+ this.groupName = groupName;
+ }
+
+ private List<?> objects;
+ public Collection<?> getObjects() {
+ return objects;
+ }
+ public void setObjects(Collection<?> objects) {
+ this.objects = new ArrayList<>(objects);
+ }
+
+}
diff --git a/src/org/traccar/reports/model/SummaryReport.java b/src/org/traccar/reports/model/SummaryReport.java
index 1e6655904..2d650381d 100644
--- a/src/org/traccar/reports/model/SummaryReport.java
+++ b/src/org/traccar/reports/model/SummaryReport.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
- * Copyright 2016 Andrey Kunitsyn (abyss@fox5.ru)
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java
index 3a77b02ca..b28793e44 100644
--- a/src/org/traccar/reports/model/TripReport.java
+++ b/src/org/traccar/reports/model/TripReport.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.reports.model;
import java.util.Date;
@@ -20,6 +36,38 @@ public class TripReport extends BaseReport {
this.endPositionId = endPositionId;
}
+ private double startLat;
+ public double getStartLat() {
+ return startLat;
+ }
+ public void setStartLat(double startLat) {
+ this.startLat = startLat;
+ }
+
+ private double startLon;
+ public double getStartLon() {
+ return startLon;
+ }
+ public void setStartLon(double startLon) {
+ this.startLon = startLon;
+ }
+
+ private double endLat;
+ public double getEndLat() {
+ return endLat;
+ }
+ public void setEndLat(double endLat) {
+ this.endLat = endLat;
+ }
+
+ private double endLon;
+ public double getEndLon() {
+ return endLon;
+ }
+ public void setEndLon(double endLon) {
+ this.endLon = endLon;
+ }
+
private Date startTime;
public Date getStartTime() {
if (startTime != null) {
diff --git a/src/org/traccar/web/ConsoleServlet.java b/src/org/traccar/web/ConsoleServlet.java
index b219eaba4..9b3d8d54b 100644
--- a/src/org/traccar/web/ConsoleServlet.java
+++ b/src/org/traccar/web/ConsoleServlet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
@@ -40,10 +40,16 @@ public class ConsoleServlet extends WebServlet {
+ Context.getConfig().getString("database.url") + "|"
+ Context.getConfig().getString("database.user"));
- Method method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class);
+ Method method;
+
+ method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class);
method.setAccessible(true);
method.invoke(server, connectionInfo);
+ method = org.h2.server.web.WebServer.class.getDeclaredMethod("setAllowOthers", boolean.class);
+ method.setAccessible(true);
+ method.invoke(server, true);
+
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
Log.warning(e);
}
diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java
index f59aabc7f..532f06e3d 100644
--- a/src/org/traccar/web/CsvBuilder.java
+++ b/src/org/traccar/web/CsvBuilder.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.web;
import java.beans.Introspector;
diff --git a/src/org/traccar/web/GpxBuilder.java b/src/org/traccar/web/GpxBuilder.java
new file mode 100644
index 000000000..bac7182dc
--- /dev/null
+++ b/src/org/traccar/web/GpxBuilder.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 Andrey Kunitsyn (andrey@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.web;
+
+import java.util.Collection;
+
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+import org.traccar.helper.UnitsConverter;
+import org.traccar.model.Position;
+
+public class GpxBuilder {
+
+ private StringBuilder builder = new StringBuilder();
+ private static final String HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"
+ + "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"Traccar\" version=\"1.1\" "
+ + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ + "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 "
+ + "http://www.topografix.com/GPX/1/1/gpx.xsd\"><trk>\n";
+ private static final String NAME = "<name>%1$s</name><trkseg>%n";
+ private static final String POINT = "<trkpt lat=\"%1$f\" lon=\"%2$f\">"
+ + "<time>%3$s</time>"
+ + "<geoidheight>%4$f</geoidheight>"
+ + "<course>%5$f</course>"
+ + "<speed>%6$f</speed>"
+ + "</trkpt>%n";
+ private static final String FOOTER = "</trkseg></trk></gpx>";
+
+ private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime();
+
+ public GpxBuilder() {
+ builder.append(HEADER);
+ builder.append("<trkseg>\n");
+ }
+
+ public GpxBuilder(String name) {
+ builder.append(HEADER);
+ builder.append(String.format(NAME, name));
+ }
+
+ public void addPosition(Position position) {
+ builder.append(String.format(POINT, position.getLatitude(), position.getLongitude(),
+ DATE_FORMAT.print(new DateTime(position.getFixTime())), position.getAltitude(),
+ position.getCourse(), UnitsConverter.mpsFromKnots(position.getSpeed())));
+ }
+
+ public void addPositions(Collection<Position> positions) {
+ for (Position position : positions) {
+ addPosition(position);
+ }
+ }
+
+ public String build() {
+ builder.append(FOOTER);
+ return builder.toString();
+ }
+
+}
diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java
index 19ac6f777..bec0afe8e 100644
--- a/src/org/traccar/web/JsonConverter.java
+++ b/src/org/traccar/web/JsonConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 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.
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index e022a9285..8201f8d16 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 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.
@@ -34,23 +34,7 @@ import org.traccar.api.CorsResponseFilter;
import org.traccar.api.ObjectMapperProvider;
import org.traccar.api.ResourceErrorHandler;
import org.traccar.api.SecurityRequestFilter;
-import org.traccar.api.resource.CommandResource;
-import org.traccar.api.resource.GroupPermissionResource;
import org.traccar.api.resource.ServerResource;
-import org.traccar.api.resource.SessionResource;
-import org.traccar.api.resource.DevicePermissionResource;
-import org.traccar.api.resource.UserResource;
-import org.traccar.api.resource.GroupResource;
-import org.traccar.api.resource.NotificationResource;
-import org.traccar.api.resource.DeviceResource;
-import org.traccar.api.resource.PositionResource;
-import org.traccar.api.resource.ReportResource;
-import org.traccar.api.resource.CommandTypeResource;
-import org.traccar.api.resource.DeviceGeofenceResource;
-import org.traccar.api.resource.EventResource;
-import org.traccar.api.resource.GeofencePermissionResource;
-import org.traccar.api.resource.GeofenceResource;
-import org.traccar.api.resource.GroupGeofenceResource;
import org.traccar.helper.Log;
import javax.naming.InitialContext;
@@ -119,9 +103,7 @@ public class WebServer {
resourceHandler.setResourceBase(config.getString("web.path"));
if (config.getBoolean("web.debug")) {
resourceHandler.setWelcomeFiles(new String[] {"debug.html"});
- //Troubleshooting Locked UI Files on Windows while app is running (like html, js, css, etc...),
- //you can make changes to the UI Files and refresh the page in the browser without stopping the app first
- resourceHandler.setMinMemoryMappedContentLength(-1);
+ resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows
} else {
resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
}
@@ -151,17 +133,10 @@ public class WebServer {
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
ResourceConfig resourceConfig = new ResourceConfig();
- resourceConfig.register(ObjectMapperProvider.class);
- resourceConfig.register(JacksonFeature.class);
- resourceConfig.register(ResourceErrorHandler.class);
- resourceConfig.register(SecurityRequestFilter.class);
- resourceConfig.register(CorsResponseFilter.class);
- resourceConfig.registerClasses(ServerResource.class, SessionResource.class, CommandResource.class,
- GroupPermissionResource.class, DevicePermissionResource.class, UserResource.class,
- GroupResource.class, DeviceResource.class, PositionResource.class,
- CommandTypeResource.class, EventResource.class, GeofenceResource.class,
- DeviceGeofenceResource.class, GeofencePermissionResource.class, GroupGeofenceResource.class,
- NotificationResource.class, ReportResource.class);
+ resourceConfig.registerClasses(JacksonFeature.class, ObjectMapperProvider.class, ResourceErrorHandler.class);
+ resourceConfig.registerClasses(SecurityRequestFilter.class, CorsResponseFilter.class);
+ resourceConfig.packages(ServerResource.class.getPackage().getName());
+
servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/*");
handlers.addHandler(servletHandler);