aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseDataHandler.java37
-rw-r--r--src/org/traccar/BaseEventHandler.java37
-rw-r--r--src/org/traccar/BasePipelineFactory.java296
-rw-r--r--src/org/traccar/BaseProtocol.java110
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java236
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java70
-rw-r--r--src/org/traccar/CharacterDelimiterFrameDecoder.java57
-rw-r--r--src/org/traccar/Config.java103
-rw-r--r--src/org/traccar/Context.java445
-rw-r--r--src/org/traccar/DefaultDataHandler.java35
-rw-r--r--src/org/traccar/DeviceSession.java30
-rw-r--r--src/org/traccar/DistanceHandler.java80
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java90
-rw-r--r--src/org/traccar/FilterHandler.java224
-rw-r--r--src/org/traccar/GeocoderHandler.java95
-rw-r--r--src/org/traccar/GeolocationHandler.java83
-rw-r--r--src/org/traccar/GlobalChannelFactory.java56
-rw-r--r--src/org/traccar/GlobalTimer.java42
-rw-r--r--src/org/traccar/HemisphereHandler.java64
-rw-r--r--src/org/traccar/Main.java67
-rw-r--r--src/org/traccar/MainEventHandler.java119
-rw-r--r--src/org/traccar/MotionHandler.java37
-rw-r--r--src/org/traccar/Protocol.java23
-rw-r--r--src/org/traccar/RemoteAddressHandler.java40
-rw-r--r--src/org/traccar/ServerManager.java101
-rw-r--r--src/org/traccar/StringProtocolEncoder.java51
-rw-r--r--src/org/traccar/TrackerServer.java132
-rw-r--r--src/org/traccar/WebDataHandler.java129
-rw-r--r--src/org/traccar/api/AsyncSocket.java93
-rw-r--r--src/org/traccar/api/AsyncSocketServlet.java46
-rw-r--r--src/org/traccar/api/BaseObjectResource.java149
-rw-r--r--src/org/traccar/api/BaseResource.java32
-rw-r--r--src/org/traccar/api/CorsResponseFilter.java58
-rw-r--r--src/org/traccar/api/ExtendedObjectResource.java62
-rw-r--r--src/org/traccar/api/ObjectMapperProvider.java32
-rw-r--r--src/org/traccar/api/ResourceErrorHandler.java42
-rw-r--r--src/org/traccar/api/SecurityRequestFilter.java114
-rw-r--r--src/org/traccar/api/SimpleObjectResource.java43
-rw-r--r--src/org/traccar/api/UserPrincipal.java37
-rw-r--r--src/org/traccar/api/UserSecurityContext.java49
-rw-r--r--src/org/traccar/api/resource/AttributeResource.java69
-rw-r--r--src/org/traccar/api/resource/CalendarResource.java36
-rw-r--r--src/org/traccar/api/resource/CommandResource.java89
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java91
-rw-r--r--src/org/traccar/api/resource/DriverResource.java36
-rw-r--r--src/org/traccar/api/resource/EventResource.java34
-rw-r--r--src/org/traccar/api/resource/GeofenceResource.java35
-rw-r--r--src/org/traccar/api/resource/GroupResource.java35
-rw-r--r--src/org/traccar/api/resource/NotificationResource.java66
-rw-r--r--src/org/traccar/api/resource/PermissionsResource.java79
-rw-r--r--src/org/traccar/api/resource/PositionResource.java96
-rw-r--r--src/org/traccar/api/resource/ReportResource.java159
-rw-r--r--src/org/traccar/api/resource/ServerResource.java50
-rw-r--r--src/org/traccar/api/resource/SessionResource.java118
-rw-r--r--src/org/traccar/api/resource/StatisticsResource.java44
-rw-r--r--src/org/traccar/api/resource/UserResource.java91
-rw-r--r--src/org/traccar/database/ActiveDevice.java54
-rw-r--r--src/org/traccar/database/AttributesManager.java36
-rw-r--r--src/org/traccar/database/BaseObjectManager.java124
-rw-r--r--src/org/traccar/database/CalendarManager.java27
-rw-r--r--src/org/traccar/database/CommandsManager.java149
-rw-r--r--src/org/traccar/database/ConnectionManager.java210
-rw-r--r--src/org/traccar/database/DataManager.java457
-rw-r--r--src/org/traccar/database/DeviceManager.java353
-rw-r--r--src/org/traccar/database/DriversManager.java73
-rw-r--r--src/org/traccar/database/ExtendedObjectManager.java112
-rw-r--r--src/org/traccar/database/GeofenceManager.java66
-rw-r--r--src/org/traccar/database/GroupTree.java151
-rw-r--r--src/org/traccar/database/GroupsManager.java103
-rw-r--r--src/org/traccar/database/IdentityManager.java39
-rw-r--r--src/org/traccar/database/ManagableObjects.java27
-rw-r--r--src/org/traccar/database/MediaManager.java68
-rw-r--r--src/org/traccar/database/NotificationManager.java115
-rw-r--r--src/org/traccar/database/PermissionsManager.java431
-rw-r--r--src/org/traccar/database/QueryBuilder.java516
-rw-r--r--src/org/traccar/database/QueryExtended.java27
-rw-r--r--src/org/traccar/database/QueryIgnore.java26
-rw-r--r--src/org/traccar/database/SimpleObjectManager.java91
-rw-r--r--src/org/traccar/database/StatisticsManager.java144
-rw-r--r--src/org/traccar/database/UsersManager.java86
-rw-r--r--src/org/traccar/events/AlertEventHandler.java38
-rw-r--r--src/org/traccar/events/CommandResultEventHandler.java38
-rw-r--r--src/org/traccar/events/DriverEventHandler.java50
-rw-r--r--src/org/traccar/events/FuelDropEventHandler.java63
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java81
-rw-r--r--src/org/traccar/events/IgnitionEventHandler.java58
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java69
-rw-r--r--src/org/traccar/events/MotionEventHandler.java129
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java121
-rw-r--r--src/org/traccar/events/TextMessageEventHandler.java37
-rw-r--r--src/org/traccar/geocoder/Address.java100
-rw-r--r--src/org/traccar/geocoder/AddressFormat.java80
-rw-r--r--src/org/traccar/geocoder/BingMapsGeocoder.java59
-rw-r--r--src/org/traccar/geocoder/FactualGeocoder.java57
-rw-r--r--src/org/traccar/geocoder/GeocodeFarmGeocoder.java66
-rw-r--r--src/org/traccar/geocoder/Geocoder.java30
-rw-r--r--src/org/traccar/geocoder/GeocoderException.java24
-rw-r--r--src/org/traccar/geocoder/GisgraphyGeocoder.java52
-rw-r--r--src/org/traccar/geocoder/GoogleGeocoder.java89
-rw-r--r--src/org/traccar/geocoder/JsonGeocoder.java89
-rw-r--r--src/org/traccar/geocoder/MapQuestGeocoder.java62
-rw-r--r--src/org/traccar/geocoder/NominatimGeocoder.java87
-rw-r--r--src/org/traccar/geocoder/OpenCageGeocoder.java73
-rw-r--r--src/org/traccar/geofence/GeofenceCircle.java94
-rw-r--r--src/org/traccar/geofence/GeofenceGeometry.java50
-rw-r--r--src/org/traccar/geofence/GeofencePolygon.java164
-rw-r--r--src/org/traccar/geofence/GeofencePolyline.java107
-rw-r--r--src/org/traccar/geolocation/GeolocationException.java24
-rw-r--r--src/org/traccar/geolocation/GeolocationProvider.java32
-rw-r--r--src/org/traccar/geolocation/GoogleGeolocationProvider.java26
-rw-r--r--src/org/traccar/geolocation/MozillaGeolocationProvider.java26
-rw-r--r--src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java75
-rw-r--r--src/org/traccar/geolocation/UniversalGeolocationProvider.java74
-rw-r--r--src/org/traccar/geolocation/UnwiredGeolocationProvider.java128
-rw-r--r--src/org/traccar/helper/BcdUtil.java63
-rw-r--r--src/org/traccar/helper/BitBuffer.java101
-rw-r--r--src/org/traccar/helper/BitUtil.java51
-rw-r--r--src/org/traccar/helper/Checksum.java254
-rw-r--r--src/org/traccar/helper/DateBuilder.java126
-rw-r--r--src/org/traccar/helper/DateUtil.java66
-rw-r--r--src/org/traccar/helper/DistanceCalculator.java53
-rw-r--r--src/org/traccar/helper/Hashing.java101
-rw-r--r--src/org/traccar/helper/LocationTree.java125
-rw-r--r--src/org/traccar/helper/Log.java268
-rw-r--r--src/org/traccar/helper/ObdDecoder.java110
-rw-r--r--src/org/traccar/helper/Parser.java348
-rw-r--r--src/org/traccar/helper/PatternBuilder.java98
-rw-r--r--src/org/traccar/helper/PatternUtil.java76
-rw-r--r--src/org/traccar/helper/StringFinder.java41
-rw-r--r--src/org/traccar/helper/UnitsConverter.java74
-rw-r--r--src/org/traccar/model/Attribute.java61
-rw-r--r--src/org/traccar/model/BaseModel.java31
-rw-r--r--src/org/traccar/model/Calendar.java82
-rw-r--r--src/org/traccar/model/CellTower.java115
-rw-r--r--src/org/traccar/model/Command.java111
-rw-r--r--src/org/traccar/model/Device.java152
-rw-r--r--src/org/traccar/model/DeviceState.java61
-rw-r--r--src/org/traccar/model/DeviceTotalDistance.java41
-rw-r--r--src/org/traccar/model/Driver.java40
-rw-r--r--src/org/traccar/model/Event.java102
-rw-r--r--src/org/traccar/model/ExtendedModel.java127
-rw-r--r--src/org/traccar/model/Geofence.java100
-rw-r--r--src/org/traccar/model/Group.java40
-rw-r--r--src/org/traccar/model/ManagedUser.java21
-rw-r--r--src/org/traccar/model/Message.java40
-rw-r--r--src/org/traccar/model/MiscFormatter.java56
-rw-r--r--src/org/traccar/model/Network.java117
-rw-r--r--src/org/traccar/model/Notification.java69
-rw-r--r--src/org/traccar/model/Permission.java57
-rw-r--r--src/org/traccar/model/Position.java309
-rw-r--r--src/org/traccar/model/Server.java160
-rw-r--r--src/org/traccar/model/Statistics.java130
-rw-r--r--src/org/traccar/model/Typed.java33
-rw-r--r--src/org/traccar/model/User.java264
-rw-r--r--src/org/traccar/model/WifiAccessPoint.java66
-rw-r--r--src/org/traccar/notification/EventForwarder.java91
-rw-r--r--src/org/traccar/notification/MailMessage.java36
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java98
-rw-r--r--src/org/traccar/notification/NotificationMail.java142
-rw-r--r--src/org/traccar/notification/NotificationSms.java52
-rw-r--r--src/org/traccar/notification/PropertiesProvider.java64
-rw-r--r--src/org/traccar/processing/ComputedAttributesHandler.java122
-rw-r--r--src/org/traccar/processing/CopyAttributesHandler.java52
-rw-r--r--src/org/traccar/protocol/AdmProtocol.java53
-rw-r--r--src/org/traccar/protocol/AdmProtocolDecoder.java163
-rw-r--r--src/org/traccar/protocol/AdmProtocolEncoder.java42
-rw-r--r--src/org/traccar/protocol/AisProtocol.java43
-rw-r--r--src/org/traccar/protocol/AisProtocolDecoder.java140
-rw-r--r--src/org/traccar/protocol/AlematicsFrameDecoder.java50
-rw-r--r--src/org/traccar/protocol/AlematicsProtocol.java46
-rw-r--r--src/org/traccar/protocol/AlematicsProtocolDecoder.java155
-rw-r--r--src/org/traccar/protocol/ApelProtocol.java46
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java210
-rw-r--r--src/org/traccar/protocol/AplicomFrameDecoder.java62
-rw-r--r--src/org/traccar/protocol/AplicomProtocol.java42
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java638
-rw-r--r--src/org/traccar/protocol/AppelloProtocol.java47
-rw-r--r--src/org/traccar/protocol/AppelloProtocolDecoder.java92
-rw-r--r--src/org/traccar/protocol/AquilaProtocol.java47
-rw-r--r--src/org/traccar/protocol/AquilaProtocolDecoder.java209
-rw-r--r--src/org/traccar/protocol/Ardi01Protocol.java47
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java87
-rw-r--r--src/org/traccar/protocol/ArknavProtocol.java47
-rw-r--r--src/org/traccar/protocol/ArknavProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/ArknavX8Protocol.java47
-rw-r--r--src/org/traccar/protocol/ArknavX8ProtocolDecoder.java88
-rw-r--r--src/org/traccar/protocol/Arnavi4FrameDecoder.java74
-rw-r--r--src/org/traccar/protocol/Arnavi4Protocol.java45
-rw-r--r--src/org/traccar/protocol/Arnavi4ProtocolDecoder.java182
-rw-r--r--src/org/traccar/protocol/ArnaviProtocol.java47
-rw-r--r--src/org/traccar/protocol/ArnaviProtocolDecoder.java99
-rw-r--r--src/org/traccar/protocol/AstraProtocol.java50
-rw-r--r--src/org/traccar/protocol/AstraProtocolDecoder.java125
-rw-r--r--src/org/traccar/protocol/At2000FrameDecoder.java82
-rw-r--r--src/org/traccar/protocol/At2000Protocol.java45
-rw-r--r--src/org/traccar/protocol/At2000ProtocolDecoder.java168
-rw-r--r--src/org/traccar/protocol/AtrackFrameDecoder.java63
-rw-r--r--src/org/traccar/protocol/AtrackProtocol.java54
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java352
-rw-r--r--src/org/traccar/protocol/AtrackProtocolEncoder.java42
-rw-r--r--src/org/traccar/protocol/AuroProtocol.java47
-rw-r--r--src/org/traccar/protocol/AuroProtocolDecoder.java91
-rw-r--r--src/org/traccar/protocol/AutoFonFrameDecoder.java67
-rw-r--r--src/org/traccar/protocol/AutoFonProtocol.java42
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java214
-rw-r--r--src/org/traccar/protocol/AutoGradeProtocol.java47
-rw-r--r--src/org/traccar/protocol/AutoGradeProtocolDecoder.java107
-rw-r--r--src/org/traccar/protocol/Avl301Protocol.java43
-rw-r--r--src/org/traccar/protocol/Avl301ProtocolDecoder.java144
-rw-r--r--src/org/traccar/protocol/BceFrameDecoder.java61
-rw-r--r--src/org/traccar/protocol/BceProtocol.java45
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java169
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocol.java46
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocolDecoder.java195
-rw-r--r--src/org/traccar/protocol/BoxProtocol.java47
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java104
-rw-r--r--src/org/traccar/protocol/CalAmpProtocol.java41
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java200
-rw-r--r--src/org/traccar/protocol/CarTrackProtocol.java47
-rw-r--r--src/org/traccar/protocol/CarTrackProtocolDecoder.java108
-rw-r--r--src/org/traccar/protocol/CarcellProtocol.java52
-rw-r--r--src/org/traccar/protocol/CarcellProtocolDecoder.java164
-rw-r--r--src/org/traccar/protocol/CarcellProtocolEncoder.java40
-rw-r--r--src/org/traccar/protocol/CarscopProtocol.java47
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java101
-rw-r--r--src/org/traccar/protocol/CastelProtocol.java56
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java456
-rw-r--r--src/org/traccar/protocol/CellocatorFrameDecoder.java74
-rw-r--r--src/org/traccar/protocol/CellocatorProtocol.java60
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java160
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolEncoder.java72
-rw-r--r--src/org/traccar/protocol/CguardProtocol.java47
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java144
-rw-r--r--src/org/traccar/protocol/CityeasyProtocol.java50
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolDecoder.java127
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolEncoder.java77
-rw-r--r--src/org/traccar/protocol/CradlepointProtocol.java47
-rw-r--r--src/org/traccar/protocol/CradlepointProtocolDecoder.java95
-rw-r--r--src/org/traccar/protocol/DishaProtocol.java47
-rw-r--r--src/org/traccar/protocol/DishaProtocolDecoder.java102
-rw-r--r--src/org/traccar/protocol/DmtHttpProtocol.java47
-rw-r--r--src/org/traccar/protocol/DmtHttpProtocolDecoder.java145
-rw-r--r--src/org/traccar/protocol/DmtProtocol.java46
-rw-r--r--src/org/traccar/protocol/DmtProtocolDecoder.java189
-rw-r--r--src/org/traccar/protocol/DwayProtocol.java47
-rw-r--r--src/org/traccar/protocol/DwayProtocolDecoder.java102
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocol.java47
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java110
-rw-r--r--src/org/traccar/protocol/EelinkProtocol.java50
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java311
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java65
-rw-r--r--src/org/traccar/protocol/EnforaProtocol.java49
-rw-r--r--src/org/traccar/protocol/EnforaProtocolDecoder.java117
-rw-r--r--src/org/traccar/protocol/EnforaProtocolEncoder.java59
-rw-r--r--src/org/traccar/protocol/EskyFrameDecoder.java39
-rw-r--r--src/org/traccar/protocol/EskyProtocol.java46
-rw-r--r--src/org/traccar/protocol/EskyProtocolDecoder.java89
-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.java125
-rw-r--r--src/org/traccar/protocol/FlespiProtocol.java46
-rw-r--r--src/org/traccar/protocol/FlespiProtocolDecoder.java116
-rw-r--r--src/org/traccar/protocol/FlexCommProtocol.java47
-rw-r--r--src/org/traccar/protocol/FlexCommProtocolDecoder.java127
-rw-r--r--src/org/traccar/protocol/FlextrackProtocol.java47
-rw-r--r--src/org/traccar/protocol/FlextrackProtocolDecoder.java143
-rw-r--r--src/org/traccar/protocol/FoxProtocol.java47
-rw-r--r--src/org/traccar/protocol/FoxProtocolDecoder.java124
-rw-r--r--src/org/traccar/protocol/FreedomProtocol.java47
-rw-r--r--src/org/traccar/protocol/FreedomProtocolDecoder.java77
-rw-r--r--src/org/traccar/protocol/GalileoFrameDecoder.java47
-rw-r--r--src/org/traccar/protocol/GalileoProtocol.java50
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java305
-rw-r--r--src/org/traccar/protocol/GalileoProtocolEncoder.java72
-rw-r--r--src/org/traccar/protocol/GatorProtocol.java50
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java132
-rw-r--r--src/org/traccar/protocol/GenxProtocol.java45
-rw-r--r--src/org/traccar/protocol/GenxProtocolDecoder.java98
-rw-r--r--src/org/traccar/protocol/Gl100Protocol.java56
-rw-r--r--src/org/traccar/protocol/Gl100ProtocolDecoder.java96
-rw-r--r--src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java406
-rw-r--r--src/org/traccar/protocol/Gl200FrameDecoder.java96
-rw-r--r--src/org/traccar/protocol/Gl200Protocol.java61
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java48
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolEncoder.java50
-rw-r--r--src/org/traccar/protocol/Gl200TextProtocolDecoder.java917
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocol.java47
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocolDecoder.java248
-rw-r--r--src/org/traccar/protocol/GnxProtocol.java47
-rw-r--r--src/org/traccar/protocol/GnxProtocolDecoder.java111
-rw-r--r--src/org/traccar/protocol/GoSafeProtocol.java47
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java259
-rw-r--r--src/org/traccar/protocol/GotopProtocol.java47
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java82
-rw-r--r--src/org/traccar/protocol/Gps056FrameDecoder.java47
-rw-r--r--src/org/traccar/protocol/Gps056Protocol.java42
-rw-r--r--src/org/traccar/protocol/Gps056ProtocolDecoder.java136
-rw-r--r--src/org/traccar/protocol/Gps103Protocol.java69
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java298
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolEncoder.java72
-rw-r--r--src/org/traccar/protocol/GpsGateProtocol.java47
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java172
-rw-r--r--src/org/traccar/protocol/GpsMarkerProtocol.java47
-rw-r--r--src/org/traccar/protocol/GpsMarkerProtocolDecoder.java90
-rw-r--r--src/org/traccar/protocol/GpsmtaProtocol.java45
-rw-r--r--src/org/traccar/protocol/GpsmtaProtocolDecoder.java91
-rw-r--r--src/org/traccar/protocol/GranitFrameDecoder.java47
-rw-r--r--src/org/traccar/protocol/GranitProtocol.java56
-rw-r--r--src/org/traccar/protocol/GranitProtocolDecoder.java242
-rw-r--r--src/org/traccar/protocol/GranitProtocolEncoder.java55
-rw-r--r--src/org/traccar/protocol/GranitProtocolSmsEncoder.java38
-rw-r--r--src/org/traccar/protocol/Gt02Protocol.java43
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java123
-rw-r--r--src/org/traccar/protocol/Gt06FrameDecoder.java56
-rw-r--r--src/org/traccar/protocol/Gt06Protocol.java48
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java666
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolEncoder.java76
-rw-r--r--src/org/traccar/protocol/Gt30Protocol.java47
-rw-r--r--src/org/traccar/protocol/Gt30ProtocolDecoder.java114
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java95
-rw-r--r--src/org/traccar/protocol/H02Protocol.java63
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java490
-rw-r--r--src/org/traccar/protocol/H02ProtocolEncoder.java72
-rw-r--r--src/org/traccar/protocol/HaicomProtocol.java47
-rw-r--r--src/org/traccar/protocol/HaicomProtocolDecoder.java109
-rw-r--r--src/org/traccar/protocol/HomtecsProtocol.java45
-rw-r--r--src/org/traccar/protocol/HomtecsProtocolDecoder.java91
-rw-r--r--src/org/traccar/protocol/HuaShengFrameDecoder.java60
-rw-r--r--src/org/traccar/protocol/HuaShengProtocol.java42
-rw-r--r--src/org/traccar/protocol/HuaShengProtocolDecoder.java145
-rw-r--r--src/org/traccar/protocol/HuabaoFrameDecoder.java58
-rw-r--r--src/org/traccar/protocol/HuabaoProtocol.java47
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolDecoder.java181
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolEncoder.java54
-rw-r--r--src/org/traccar/protocol/HunterProProtocol.java47
-rw-r--r--src/org/traccar/protocol/HunterProProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/IdplProtocol.java47
-rw-r--r--src/org/traccar/protocol/IdplProtocolDecoder.java113
-rw-r--r--src/org/traccar/protocol/IntellitracFrameDecoder.java52
-rw-r--r--src/org/traccar/protocol/IntellitracProtocol.java46
-rw-r--r--src/org/traccar/protocol/IntellitracProtocolDecoder.java118
-rw-r--r--src/org/traccar/protocol/JpKorjarFrameDecoder.java46
-rw-r--r--src/org/traccar/protocol/JpKorjarProtocol.java45
-rw-r--r--src/org/traccar/protocol/JpKorjarProtocolDecoder.java89
-rw-r--r--src/org/traccar/protocol/Jt600FrameDecoder.java55
-rw-r--r--src/org/traccar/protocol/Jt600Protocol.java51
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java313
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolEncoder.java45
-rw-r--r--src/org/traccar/protocol/KenjiProtocol.java48
-rw-r--r--src/org/traccar/protocol/KenjiProtocolDecoder.java110
-rw-r--r--src/org/traccar/protocol/KhdProtocol.java48
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java156
-rw-r--r--src/org/traccar/protocol/KhdProtocolEncoder.java64
-rw-r--r--src/org/traccar/protocol/L100FrameDecoder.java50
-rw-r--r--src/org/traccar/protocol/L100Protocol.java42
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java120
-rw-r--r--src/org/traccar/protocol/LaipacProtocol.java47
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java116
-rw-r--r--src/org/traccar/protocol/M2mProtocol.java43
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java127
-rw-r--r--src/org/traccar/protocol/MaestroProtocol.java47
-rw-r--r--src/org/traccar/protocol/MaestroProtocolDecoder.java103
-rw-r--r--src/org/traccar/protocol/ManPowerProtocol.java47
-rw-r--r--src/org/traccar/protocol/ManPowerProtocolDecoder.java81
-rw-r--r--src/org/traccar/protocol/MegastekFrameDecoder.java59
-rw-r--r--src/org/traccar/protocol/MegastekProtocol.java46
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java385
-rw-r--r--src/org/traccar/protocol/MeiligaoFrameDecoder.java47
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocol.java60
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java448
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolEncoder.java95
-rw-r--r--src/org/traccar/protocol/MeitrackFrameDecoder.java47
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java68
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java469
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java64
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocol.java61
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolDecoder.java200
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolEncoder.java84
-rw-r--r--src/org/traccar/protocol/Mta6Protocol.java47
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java318
-rw-r--r--src/org/traccar/protocol/MtxProtocol.java47
-rw-r--r--src/org/traccar/protocol/MtxProtocolDecoder.java97
-rw-r--r--src/org/traccar/protocol/MxtFrameDecoder.java57
-rw-r--r--src/org/traccar/protocol/MxtProtocol.java45
-rw-r--r--src/org/traccar/protocol/MxtProtocolDecoder.java174
-rw-r--r--src/org/traccar/protocol/NavigilFrameDecoder.java58
-rw-r--r--src/org/traccar/protocol/NavigilProtocol.java45
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java317
-rw-r--r--src/org/traccar/protocol/NavisProtocol.java46
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java287
-rw-r--r--src/org/traccar/protocol/NoranProtocol.java52
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java166
-rw-r--r--src/org/traccar/protocol/NoranProtocolEncoder.java71
-rw-r--r--src/org/traccar/protocol/NvsFrameDecoder.java49
-rw-r--r--src/org/traccar/protocol/NvsProtocol.java42
-rw-r--r--src/org/traccar/protocol/NvsProtocolDecoder.java135
-rw-r--r--src/org/traccar/protocol/ObdDongleProtocol.java43
-rw-r--r--src/org/traccar/protocol/ObdDongleProtocolDecoder.java128
-rw-r--r--src/org/traccar/protocol/OigoProtocol.java41
-rw-r--r--src/org/traccar/protocol/OigoProtocolDecoder.java239
-rw-r--r--src/org/traccar/protocol/OrionFrameDecoder.java70
-rw-r--r--src/org/traccar/protocol/OrionProtocol.java45
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java114
-rw-r--r--src/org/traccar/protocol/OsmAndProtocol.java45
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java167
-rw-r--r--src/org/traccar/protocol/OwnTracksProtocol.java46
-rw-r--r--src/org/traccar/protocol/OwnTracksProtocolDecoder.java115
-rw-r--r--src/org/traccar/protocol/PathAwayProtocol.java45
-rw-r--r--src/org/traccar/protocol/PathAwayProtocolDecoder.java96
-rw-r--r--src/org/traccar/protocol/PiligrimProtocol.java47
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java168
-rw-r--r--src/org/traccar/protocol/PretraceProtocol.java47
-rw-r--r--src/org/traccar/protocol/PretraceProtocolDecoder.java96
-rw-r--r--src/org/traccar/protocol/PricolProtocol.java50
-rw-r--r--src/org/traccar/protocol/PricolProtocolDecoder.java96
-rw-r--r--src/org/traccar/protocol/ProgressProtocol.java46
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java172
-rw-r--r--src/org/traccar/protocol/Pt3000Protocol.java47
-rw-r--r--src/org/traccar/protocol/Pt3000ProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/Pt502FrameDecoder.java56
-rw-r--r--src/org/traccar/protocol/Pt502Protocol.java57
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java148
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolEncoder.java62
-rw-r--r--src/org/traccar/protocol/RaveonProtocol.java47
-rw-r--r--src/org/traccar/protocol/RaveonProtocolDecoder.java99
-rw-r--r--src/org/traccar/protocol/RecodaProtocol.java46
-rw-r--r--src/org/traccar/protocol/RecodaProtocolDecoder.java110
-rw-r--r--src/org/traccar/protocol/RitiProtocol.java46
-rw-r--r--src/org/traccar/protocol/RitiProtocolDecoder.java102
-rw-r--r--src/org/traccar/protocol/RuptelaProtocol.java53
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java247
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolEncoder.java77
-rw-r--r--src/org/traccar/protocol/SanavProtocol.java47
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java86
-rw-r--r--src/org/traccar/protocol/SiwiProtocol.java45
-rw-r--r--src/org/traccar/protocol/SiwiProtocolDecoder.java96
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocol.java41
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java190
-rw-r--r--src/org/traccar/protocol/SmokeyProtocol.java41
-rw-r--r--src/org/traccar/protocol/SmokeyProtocolDecoder.java160
-rw-r--r--src/org/traccar/protocol/StarLinkProtocol.java47
-rw-r--r--src/org/traccar/protocol/StarLinkProtocolDecoder.java229
-rw-r--r--src/org/traccar/protocol/Stl060FrameDecoder.java50
-rw-r--r--src/org/traccar/protocol/Stl060Protocol.java46
-rw-r--r--src/org/traccar/protocol/Stl060ProtocolDecoder.java120
-rw-r--r--src/org/traccar/protocol/SuntechProtocol.java57
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java379
-rw-r--r--src/org/traccar/protocol/SuntechProtocolEncoder.java58
-rw-r--r--src/org/traccar/protocol/SupermateProtocol.java46
-rw-r--r--src/org/traccar/protocol/SupermateProtocolDecoder.java120
-rw-r--r--src/org/traccar/protocol/T55Protocol.java56
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java282
-rw-r--r--src/org/traccar/protocol/T800xProtocol.java47
-rw-r--r--src/org/traccar/protocol/T800xProtocolDecoder.java189
-rw-r--r--src/org/traccar/protocol/T800xProtocolEncoder.java63
-rw-r--r--src/org/traccar/protocol/TaipProtocol.java56
-rw-r--r--src/org/traccar/protocol/TaipProtocolDecoder.java248
-rw-r--r--src/org/traccar/protocol/TelicFrameDecoder.java54
-rw-r--r--src/org/traccar/protocol/TelicProtocol.java49
-rw-r--r--src/org/traccar/protocol/TelicProtocolDecoder.java135
-rw-r--r--src/org/traccar/protocol/TeltonikaFrameDecoder.java54
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocol.java54
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java453
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolEncoder.java62
-rw-r--r--src/org/traccar/protocol/ThinkRaceProtocol.java43
-rw-r--r--src/org/traccar/protocol/ThinkRaceProtocolDecoder.java115
-rw-r--r--src/org/traccar/protocol/Tk102Protocol.java43
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java142
-rw-r--r--src/org/traccar/protocol/Tk103Protocol.java69
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java305
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolEncoder.java54
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocol.java47
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java114
-rw-r--r--src/org/traccar/protocol/TlvProtocol.java43
-rw-r--r--src/org/traccar/protocol/TlvProtocolDecoder.java109
-rw-r--r--src/org/traccar/protocol/TmgProtocol.java47
-rw-r--r--src/org/traccar/protocol/TmgProtocolDecoder.java152
-rw-r--r--src/org/traccar/protocol/TopflytechProtocol.java47
-rw-r--r--src/org/traccar/protocol/TopflytechProtocolDecoder.java76
-rw-r--r--src/org/traccar/protocol/TotemFrameDecoder.java59
-rw-r--r--src/org/traccar/protocol/TotemProtocol.java52
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java361
-rw-r--r--src/org/traccar/protocol/TotemProtocolEncoder.java44
-rw-r--r--src/org/traccar/protocol/Tr20Protocol.java47
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java94
-rw-r--r--src/org/traccar/protocol/Tr900Protocol.java56
-rw-r--r--src/org/traccar/protocol/Tr900ProtocolDecoder.java94
-rw-r--r--src/org/traccar/protocol/TrackboxProtocol.java47
-rw-r--r--src/org/traccar/protocol/TrackboxProtocolDecoder.java109
-rw-r--r--src/org/traccar/protocol/TrakMateProtocol.java47
-rw-r--r--src/org/traccar/protocol/TrakMateProtocolDecoder.java226
-rw-r--r--src/org/traccar/protocol/TramigoFrameDecoder.java59
-rw-r--r--src/org/traccar/protocol/TramigoProtocol.java45
-rw-r--r--src/org/traccar/protocol/TramigoProtocolDecoder.java156
-rw-r--r--src/org/traccar/protocol/TrvProtocol.java47
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java199
-rw-r--r--src/org/traccar/protocol/Tt8850Protocol.java47
-rw-r--r--src/org/traccar/protocol/Tt8850ProtocolDecoder.java99
-rw-r--r--src/org/traccar/protocol/TytanProtocol.java41
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java191
-rw-r--r--src/org/traccar/protocol/TzoneProtocol.java43
-rw-r--r--src/org/traccar/protocol/TzoneProtocolDecoder.java244
-rw-r--r--src/org/traccar/protocol/UlbotechFrameDecoder.java71
-rw-r--r--src/org/traccar/protocol/UlbotechProtocol.java42
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java370
-rw-r--r--src/org/traccar/protocol/UproProtocol.java45
-rw-r--r--src/org/traccar/protocol/UproProtocolDecoder.java187
-rw-r--r--src/org/traccar/protocol/V680Protocol.java56
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java132
-rw-r--r--src/org/traccar/protocol/VisiontekProtocol.java47
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java138
-rw-r--r--src/org/traccar/protocol/Vt200FrameDecoder.java51
-rw-r--r--src/org/traccar/protocol/Vt200Protocol.java42
-rw-r--r--src/org/traccar/protocol/Vt200ProtocolDecoder.java151
-rw-r--r--src/org/traccar/protocol/VtfmsFrameDecoder.java40
-rw-r--r--src/org/traccar/protocol/VtfmsProtocol.java52
-rw-r--r--src/org/traccar/protocol/VtfmsProtocolDecoder.java156
-rw-r--r--src/org/traccar/protocol/WatchFrameDecoder.java74
-rw-r--r--src/org/traccar/protocol/WatchProtocol.java61
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java274
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java138
-rw-r--r--src/org/traccar/protocol/WialonProtocol.java61
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java196
-rw-r--r--src/org/traccar/protocol/WialonProtocolEncoder.java42
-rw-r--r--src/org/traccar/protocol/WondexFrameDecoder.java59
-rw-r--r--src/org/traccar/protocol/WondexProtocol.java63
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java127
-rw-r--r--src/org/traccar/protocol/WondexProtocolEncoder.java49
-rw-r--r--src/org/traccar/protocol/XexunFrameDecoder.java57
-rw-r--r--src/org/traccar/protocol/XexunProtocol.java58
-rw-r--r--src/org/traccar/protocol/XexunProtocolDecoder.java152
-rw-r--r--src/org/traccar/protocol/XexunProtocolEncoder.java42
-rw-r--r--src/org/traccar/protocol/XirgoProtocol.java56
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java183
-rw-r--r--src/org/traccar/protocol/Xt013Protocol.java47
-rw-r--r--src/org/traccar/protocol/Xt013ProtocolDecoder.java94
-rw-r--r--src/org/traccar/protocol/Xt2400Protocol.java41
-rw-r--r--src/org/traccar/protocol/Xt2400ProtocolDecoder.java198
-rw-r--r--src/org/traccar/protocol/YwtProtocol.java47
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java114
-rw-r--r--src/org/traccar/reports/Events.java117
-rw-r--r--src/org/traccar/reports/ReportUtils.java322
-rw-r--r--src/org/traccar/reports/Route.java85
-rw-r--r--src/org/traccar/reports/Stops.java98
-rw-r--r--src/org/traccar/reports/Summary.java96
-rw-r--r--src/org/traccar/reports/Trips.java96
-rw-r--r--src/org/traccar/reports/model/BaseReport.java87
-rw-r--r--src/org/traccar/reports/model/DeviceReport.java55
-rw-r--r--src/org/traccar/reports/model/StopReport.java122
-rw-r--r--src/org/traccar/reports/model/SummaryReport.java34
-rw-r--r--src/org/traccar/reports/model/TripReport.java168
-rw-r--r--src/org/traccar/reports/model/TripsConfig.java105
-rw-r--r--src/org/traccar/smpp/ClientSmppSessionHandler.java75
-rw-r--r--src/org/traccar/smpp/EnquireLinkTask.java56
-rw-r--r--src/org/traccar/smpp/ReconnectionTask.java31
-rw-r--r--src/org/traccar/smpp/SmppClient.java240
-rw-r--r--src/org/traccar/web/ConsoleServlet.java58
-rw-r--r--src/org/traccar/web/CsvBuilder.java163
-rw-r--r--src/org/traccar/web/GpxBuilder.java73
-rw-r--r--src/org/traccar/web/WebServer.java199
561 files changed, 0 insertions, 57212 deletions
diff --git a/src/org/traccar/BaseDataHandler.java b/src/org/traccar/BaseDataHandler.java
deleted file mode 100644
index 0c71a6a4d..000000000
--- a/src/org/traccar/BaseDataHandler.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
-import org.traccar.model.Position;
-
-public abstract class BaseDataHandler extends OneToOneDecoder {
-
- @Override
- protected final Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
-
- if (msg instanceof Position) {
- return handlePosition((Position) msg);
- }
-
- return msg;
- }
-
- protected abstract Position handlePosition(Position position);
-
-}
diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java
deleted file mode 100644
index b6f7e2085..000000000
--- a/src/org/traccar/BaseEventHandler.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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;
-
-import java.util.Map;
-
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public abstract class BaseEventHandler extends BaseDataHandler {
-
- @Override
- protected Position handlePosition(Position position) {
-
- Map<Event, Position> events = analyzePosition(position);
- if (events != null && Context.getNotificationManager() != null) {
- Context.getNotificationManager().updateEvents(events);
- }
- return position;
- }
-
- protected abstract Map<Event, Position> analyzePosition(Position position);
-
-}
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
deleted file mode 100644
index 771ab8acb..000000000
--- a/src/org/traccar/BasePipelineFactory.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandler;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.DownstreamMessageEvent;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.SimpleChannelHandler;
-import org.jboss.netty.handler.logging.LoggingHandler;
-import org.jboss.netty.handler.timeout.IdleStateHandler;
-import org.traccar.events.CommandResultEventHandler;
-import org.traccar.events.DriverEventHandler;
-import org.traccar.events.FuelDropEventHandler;
-import org.traccar.events.GeofenceEventHandler;
-import org.traccar.events.IgnitionEventHandler;
-import org.traccar.events.MaintenanceEventHandler;
-import org.traccar.events.MotionEventHandler;
-import org.traccar.events.OverspeedEventHandler;
-import org.traccar.events.AlertEventHandler;
-import org.traccar.helper.Log;
-import org.traccar.processing.ComputedAttributesHandler;
-import org.traccar.processing.CopyAttributesHandler;
-
-import java.net.InetSocketAddress;
-
-public abstract class BasePipelineFactory implements ChannelPipelineFactory {
-
- private final TrackerServer server;
- private int timeout;
-
- private FilterHandler filterHandler;
- private DistanceHandler distanceHandler;
- private RemoteAddressHandler remoteAddressHandler;
- private MotionHandler motionHandler;
- private GeocoderHandler geocoderHandler;
- private GeolocationHandler geolocationHandler;
- private HemisphereHandler hemisphereHandler;
- private CopyAttributesHandler copyAttributesHandler;
- private ComputedAttributesHandler computedAttributesHandler;
-
- private CommandResultEventHandler commandResultEventHandler;
- private OverspeedEventHandler overspeedEventHandler;
- private FuelDropEventHandler fuelDropEventHandler;
- private MotionEventHandler motionEventHandler;
- private GeofenceEventHandler geofenceEventHandler;
- private AlertEventHandler alertEventHandler;
- private IgnitionEventHandler ignitionEventHandler;
- private MaintenanceEventHandler maintenanceEventHandler;
- private DriverEventHandler driverEventHandler;
-
- private static final class OpenChannelHandler extends SimpleChannelHandler {
-
- private final TrackerServer server;
-
- private OpenChannelHandler(TrackerServer server) {
- this.server = server;
- }
-
- @Override
- public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
- server.getChannelGroup().add(e.getChannel());
- }
- }
-
- private static class StandardLoggingHandler extends LoggingHandler {
-
- @Override
- public void log(ChannelEvent e) {
- if (e instanceof MessageEvent) {
- MessageEvent event = (MessageEvent) e;
- StringBuilder msg = new StringBuilder();
-
- msg.append("[").append(String.format("%08X", e.getChannel().getId())).append(": ");
- msg.append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort());
- if (e instanceof DownstreamMessageEvent) {
- msg.append(" > ");
- } else {
- msg.append(" < ");
- }
-
- if (event.getRemoteAddress() != null) {
- msg.append(((InetSocketAddress) event.getRemoteAddress()).getHostString());
- } else {
- msg.append("null");
- }
- msg.append("]");
-
- if (event.getMessage() instanceof ChannelBuffer) {
- msg.append(" HEX: ");
- msg.append(ChannelBuffers.hexDump((ChannelBuffer) event.getMessage()));
- }
-
- Log.debug(msg.toString());
- }
- }
-
- }
-
- public BasePipelineFactory(TrackerServer server, String protocol) {
- this.server = server;
-
- timeout = Context.getConfig().getInteger(protocol + ".timeout");
- if (timeout == 0) {
- timeout = Context.getConfig().getInteger(protocol + ".resetDelay"); // temporary
- if (timeout == 0) {
- timeout = Context.getConfig().getInteger("server.timeout");
- }
- }
-
- distanceHandler = new DistanceHandler(
- Context.getConfig().getBoolean("coordinates.filter"),
- Context.getConfig().getInteger("coordinates.minError"),
- Context.getConfig().getInteger("coordinates.maxError"));
-
- if (Context.getConfig().getBoolean("processing.remoteAddress.enable")) {
- remoteAddressHandler = new RemoteAddressHandler();
- }
-
- if (Context.getConfig().getBoolean("filter.enable")) {
- filterHandler = new FilterHandler();
- }
-
- if (Context.getGeocoder() != null) {
- geocoderHandler = new GeocoderHandler(
- Context.getGeocoder(),
- Context.getConfig().getBoolean("geocoder.processInvalidPositions"));
- }
-
- if (Context.getGeolocationProvider() != null) {
- geolocationHandler = new GeolocationHandler(
- Context.getGeolocationProvider(),
- Context.getConfig().getBoolean("geolocation.processInvalidPositions"));
- }
-
- motionHandler = new MotionHandler(Context.getTripsConfig().getSpeedThreshold());
-
- if (Context.getConfig().hasKey("location.latitudeHemisphere")
- || Context.getConfig().hasKey("location.longitudeHemisphere")) {
- hemisphereHandler = new HemisphereHandler();
- }
-
- if (Context.getConfig().getBoolean("processing.copyAttributes.enable")) {
- copyAttributesHandler = new CopyAttributesHandler();
- }
-
- if (Context.getConfig().getBoolean("processing.computedAttributes.enable")) {
- computedAttributesHandler = new ComputedAttributesHandler();
- }
-
- if (Context.getConfig().getBoolean("event.enable")) {
- commandResultEventHandler = new CommandResultEventHandler();
- overspeedEventHandler = Context.getOverspeedEventHandler();
- fuelDropEventHandler = new FuelDropEventHandler();
- motionEventHandler = Context.getMotionEventHandler();
- geofenceEventHandler = new GeofenceEventHandler();
- alertEventHandler = new AlertEventHandler();
- ignitionEventHandler = new IgnitionEventHandler();
- maintenanceEventHandler = new MaintenanceEventHandler();
- driverEventHandler = new DriverEventHandler();
- }
- }
-
- protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
-
- @Override
- public ChannelPipeline getPipeline() {
- ChannelPipeline pipeline = Channels.pipeline();
- if (timeout > 0 && !server.isConnectionless()) {
- pipeline.addLast("idleHandler", new IdleStateHandler(GlobalTimer.getTimer(), timeout, 0, 0));
- }
- pipeline.addLast("openHandler", new OpenChannelHandler(server));
- if (Context.isLoggerEnabled()) {
- pipeline.addLast("logger", new StandardLoggingHandler());
- }
-
- addSpecificHandlers(pipeline);
-
- if (geolocationHandler != null) {
- pipeline.addLast("location", geolocationHandler);
- }
- if (hemisphereHandler != null) {
- pipeline.addLast("hemisphere", hemisphereHandler);
- }
-
- if (distanceHandler != null) {
- pipeline.addLast("distance", distanceHandler);
- }
-
- if (remoteAddressHandler != null) {
- pipeline.addLast("remoteAddress", remoteAddressHandler);
- }
-
- addDynamicHandlers(pipeline);
-
- if (filterHandler != null) {
- pipeline.addLast("filter", filterHandler);
- }
-
- if (geocoderHandler != null) {
- pipeline.addLast("geocoder", geocoderHandler);
- }
-
- if (motionHandler != null) {
- pipeline.addLast("motion", motionHandler);
- }
-
- if (copyAttributesHandler != null) {
- pipeline.addLast("copyAttributes", copyAttributesHandler);
- }
-
- if (computedAttributesHandler != null) {
- pipeline.addLast("computedAttributes", computedAttributesHandler);
- }
-
- if (Context.getDataManager() != null) {
- pipeline.addLast("dataHandler", new DefaultDataHandler());
- }
-
- if (Context.getConfig().getBoolean("forward.enable")) {
- pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url")));
- }
-
- if (commandResultEventHandler != null) {
- pipeline.addLast("CommandResultEventHandler", commandResultEventHandler);
- }
-
- if (overspeedEventHandler != null) {
- pipeline.addLast("OverspeedEventHandler", overspeedEventHandler);
- }
-
- if (fuelDropEventHandler != null) {
- pipeline.addLast("FuelDropEventHandler", fuelDropEventHandler);
- }
-
- if (motionEventHandler != null) {
- pipeline.addLast("MotionEventHandler", motionEventHandler);
- }
-
- if (geofenceEventHandler != null) {
- pipeline.addLast("GeofenceEventHandler", geofenceEventHandler);
- }
-
- if (alertEventHandler != null) {
- pipeline.addLast("AlertEventHandler", alertEventHandler);
- }
-
- if (ignitionEventHandler != null) {
- pipeline.addLast("IgnitionEventHandler", ignitionEventHandler);
- }
-
- if (maintenanceEventHandler != null) {
- pipeline.addLast("MaintenanceEventHandler", maintenanceEventHandler);
- }
-
- if (driverEventHandler != null) {
- pipeline.addLast("DriverEventHandler", driverEventHandler);
- }
-
- pipeline.addLast("mainHandler", new MainEventHandler());
- return pipeline;
- }
-
- private void addDynamicHandlers(ChannelPipeline pipeline) {
- if (Context.getConfig().hasKey("extra.handlers")) {
- String[] handlers = Context.getConfig().getString("extra.handlers").split(",");
- for (int i = 0; i < handlers.length; i++) {
- try {
- pipeline.addLast("extraHandler." + i, (ChannelHandler) Class.forName(handlers[i]).newInstance());
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException error) {
- Log.warning(error);
- }
- }
- }
- }
-}
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
deleted file mode 100644
index 90b9f21f2..000000000
--- a/src/org/traccar/BaseProtocol.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.handler.codec.string.StringEncoder;
-import org.traccar.database.ActiveDevice;
-import org.traccar.model.Command;
-
-import javax.xml.bind.DatatypeConverter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-public abstract class BaseProtocol implements Protocol {
-
- private final String name;
- private final Set<String> supportedDataCommands = new HashSet<>();
- private final Set<String> supportedTextCommands = new HashSet<>();
-
- private StringProtocolEncoder textCommandEncoder = null;
-
- public BaseProtocol(String name) {
- this.name = name;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public void setSupportedDataCommands(String... commands) {
- supportedDataCommands.addAll(Arrays.asList(commands));
- }
-
- public void setSupportedTextCommands(String... commands) {
- supportedTextCommands.addAll(Arrays.asList(commands));
- }
-
- public void setSupportedCommands(String... commands) {
- supportedDataCommands.addAll(Arrays.asList(commands));
- supportedTextCommands.addAll(Arrays.asList(commands));
- }
-
- @Override
- public Collection<String> getSupportedDataCommands() {
- Set<String> commands = new HashSet<>(supportedDataCommands);
- commands.add(Command.TYPE_CUSTOM);
- return commands;
- }
-
- @Override
- public Collection<String> getSupportedTextCommands() {
- Set<String> commands = new HashSet<>(supportedTextCommands);
- commands.add(Command.TYPE_CUSTOM);
- return commands;
- }
-
- @Override
- public void sendDataCommand(ActiveDevice activeDevice, Command command) {
- if (supportedDataCommands.contains(command.getType())) {
- activeDevice.write(command);
- } else if (command.getType().equals(Command.TYPE_CUSTOM)) {
- String data = command.getString(Command.KEY_DATA);
- if (activeDevice.getChannel().getPipeline().get(StringEncoder.class) != null) {
- activeDevice.write(data);
- } else {
- activeDevice.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary(data)));
- }
- } else {
- throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName());
- }
- }
-
- public void setTextCommandEncoder(StringProtocolEncoder textCommandEncoder) {
- this.textCommandEncoder = textCommandEncoder;
- }
-
- @Override
- public void sendTextCommand(String destAddress, Command command) throws Exception {
- if (Context.getSmppManager() != null) {
- if (command.getType().equals(Command.TYPE_CUSTOM)) {
- Context.getSmppManager().sendMessageSync(destAddress, command.getString(Command.KEY_DATA), true);
- } else if (supportedTextCommands.contains(command.getType()) && textCommandEncoder != null) {
- Context.getSmppManager().sendMessageSync(destAddress,
- (String) textCommandEncoder.encodeCommand(command), true);
- } else {
- throw new RuntimeException(
- "Command " + command.getType() + " is not supported in protocol " + getName());
- }
- } else {
- throw new RuntimeException("SMPP client is not enabled");
- }
- }
-
-}
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
deleted file mode 100644
index 2d6286bf8..000000000
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.socket.DatagramChannel;
-import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
-import org.traccar.helper.Log;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Device;
-import org.traccar.model.Position;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.util.Collection;
-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);
- device.setCategory(Context.getConfig().getString("database.registerUnknown.defaultCategory"));
-
- long defaultGroupId = Context.getConfig().getLong("database.registerUnknown.defaultGroupId");
- if (defaultGroupId != 0) {
- device.setGroupId(defaultGroupId);
- }
-
- try {
- Context.getDeviceManager().addItem(device);
-
- Log.info("Automatically registered device " + uniqueId);
-
- if (defaultGroupId != 0) {
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- }
-
- return device.getId();
- } catch (SQLException e) {
- Log.warning(e);
- return 0;
- }
- }
-
- public String getProtocolName() {
- return protocol.getName();
- }
-
- protected double convertSpeed(double value, String defaultUnits) {
- switch (Context.getConfig().getString(getProtocolName() + ".speed", defaultUnits)) {
- case "kmh":
- return UnitsConverter.knotsFromKph(value);
- case "mps":
- return UnitsConverter.knotsFromMps(value);
- case "mph":
- return UnitsConverter.knotsFromMph(value);
- case "kn":
- default:
- return value;
- }
- }
-
- private DeviceSession channelDeviceSession; // connection-based protocols
- private Map<SocketAddress, DeviceSession> addressDeviceSessions = new HashMap<>(); // connectionless protocols
-
- private long findDeviceId(SocketAddress remoteAddress, String... uniqueIds) {
- long deviceId = 0;
- if (uniqueIds.length > 0) {
- try {
- for (String uniqueId : uniqueIds) {
- if (uniqueId != null) {
- Device device = Context.getIdentityManager().getByUniqueId(uniqueId);
- if (device != null) {
- deviceId = device.getId();
- break;
- }
- }
- }
- } catch (Exception e) {
- 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);
- }
- if (remoteAddress != null) {
- message.append(" (").append(((InetSocketAddress) remoteAddress).getHostString()).append(")");
- }
- Log.warning(message.toString());
- }
- }
- return deviceId;
- }
-
- public DeviceSession getDeviceSession(Channel channel, SocketAddress remoteAddress, String... uniqueIds) {
- if (channel != null && channel.getPipeline().get(HttpRequestDecoder.class) != null
- || 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);
- if (deviceSession != null && (deviceSession.getDeviceId() == deviceId || uniqueIds.length == 0)) {
- return deviceSession;
- } else if (deviceId != 0) {
- deviceSession = new DeviceSession(deviceId);
- addressDeviceSessions.put(remoteAddress, deviceSession);
- if (Context.getConnectionManager() != null) {
- Context.getConnectionManager().addActiveDevice(deviceId, protocol, channel, remoteAddress);
- }
- return deviceSession;
- } else {
- return null;
- }
- } else {
- if (channelDeviceSession == null) {
- long deviceId = findDeviceId(remoteAddress, uniqueIds);
- if (deviceId != 0) {
- channelDeviceSession = new DeviceSession(deviceId);
- if (Context.getConnectionManager() != null) {
- Context.getConnectionManager().addActiveDevice(deviceId, protocol, channel, remoteAddress);
- }
- }
- }
- return channelDeviceSession;
- }
- }
-
- public BaseProtocolDecoder(Protocol protocol) {
- this.protocol = protocol;
- }
-
- public void getLastLocation(Position position, Date deviceTime) {
- if (position.getDeviceId() != 0) {
- position.setOutdated(true);
-
- Position last = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (last != null) {
- position.setFixTime(last.getFixTime());
- position.setValid(last.getValid());
- position.setLatitude(last.getLatitude());
- position.setLongitude(last.getLongitude());
- position.setAltitude(last.getAltitude());
- position.setSpeed(last.getSpeed());
- position.setCourse(last.getCourse());
- position.setAccuracy(last.getAccuracy());
- } else {
- position.setFixTime(new Date(0));
- }
-
- if (deviceTime != null) {
- position.setDeviceTime(deviceTime);
- } else {
- position.setDeviceTime(new Date());
- }
- }
- }
-
- @Override
- protected void onMessageEvent(
- Channel channel, SocketAddress remoteAddress, Object originalMessage, Object decodedMessage) {
- if (Context.getStatisticsManager() != null) {
- Context.getStatisticsManager().registerMessageReceived();
- }
- Position position = null;
- if (decodedMessage != null) {
- if (decodedMessage instanceof Position) {
- position = (Position) decodedMessage;
- } else if (decodedMessage instanceof Collection) {
- Collection positions = (Collection) decodedMessage;
- if (!positions.isEmpty()) {
- position = (Position) positions.iterator().next();
- }
- }
- }
- if (position != null) {
- Context.getConnectionManager().updateDevice(
- position.getDeviceId(), Device.STATUS_ONLINE, new Date());
- } else {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession != null) {
- Context.getConnectionManager().updateDevice(
- deviceSession.getDeviceId(), Device.STATUS_ONLINE, new Date());
- }
- }
- }
-
- @Override
- protected Object handleEmptyMessage(Channel channel, SocketAddress remoteAddress, Object msg) {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (Context.getConfig().getBoolean("database.saveEmpty") && deviceSession != null) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- getLastLocation(position, null);
- return position;
- } else {
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
deleted file mode 100644
index 2c8a81868..000000000
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-import org.traccar.model.Device;
-
-public abstract class BaseProtocolEncoder extends OneToOneEncoder {
-
- protected String getUniqueId(long deviceId) {
- return Context.getIdentityManager().getById(deviceId).getUniqueId();
- }
-
- protected void initDevicePassword(Command command, String defaultPassword) {
- if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
- Device device = Context.getIdentityManager().getById(command.getDeviceId());
- String password = device.getString(Command.KEY_DEVICE_PASSWORD);
- if (password != null) {
- command.set(Command.KEY_DEVICE_PASSWORD, password);
- } else {
- command.set(Command.KEY_DEVICE_PASSWORD, defaultPassword);
- }
- }
- }
-
- @Override
- protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
-
- if (msg instanceof Command) {
- Command command = (Command) msg;
- Object encodedCommand = encodeCommand(command);
-
- // Log command
- StringBuilder s = new StringBuilder();
- s.append(String.format("[%08X] ", channel.getId()));
- s.append("id: ").append(getUniqueId(command.getDeviceId())).append(", ");
- s.append("command type: ").append(command.getType()).append(" ");
- if (encodedCommand != null) {
- s.append("sent");
- } else {
- s.append("not sent");
- }
- Log.info(s.toString());
-
- return encodedCommand;
- }
-
- return msg;
- }
-
- protected abstract Object encodeCommand(Command command);
-
-}
diff --git a/src/org/traccar/CharacterDelimiterFrameDecoder.java b/src/org/traccar/CharacterDelimiterFrameDecoder.java
deleted file mode 100644
index d71974e78..000000000
--- a/src/org/traccar/CharacterDelimiterFrameDecoder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
-
-public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder {
-
- private static ChannelBuffer createDelimiter(char delimiter) {
- byte[] buf = {(byte) delimiter};
- return ChannelBuffers.wrappedBuffer(buf);
- }
-
- private static ChannelBuffer createDelimiter(String delimiter) {
- byte[] buf = new byte[delimiter.length()];
- for (int i = 0; i < delimiter.length(); i++) {
- buf[i] = (byte) delimiter.charAt(i);
- }
- return ChannelBuffers.wrappedBuffer(buf);
- }
-
- private static ChannelBuffer[] convertDelimiters(String[] delimiters) {
- ChannelBuffer[] result = new ChannelBuffer[delimiters.length];
- for (int i = 0; i < delimiters.length; i++) {
- result[i] = createDelimiter(delimiters[i]);
- }
- return result;
- }
-
- public CharacterDelimiterFrameDecoder(int maxFrameLength, char delimiter) {
- super(maxFrameLength, createDelimiter(delimiter));
- }
-
- public CharacterDelimiterFrameDecoder(int maxFrameLength, String delimiter) {
- super(maxFrameLength, createDelimiter(delimiter));
- }
-
- public CharacterDelimiterFrameDecoder(int maxFrameLength, String... delimiters) {
- super(maxFrameLength, convertDelimiters(delimiters));
- }
-
-}
diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java
deleted file mode 100644
index 43f4632da..000000000
--- a/src/org/traccar/Config.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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 java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public class Config {
-
- private final Properties properties = new Properties();
-
- private boolean useEnvironmentVariables;
-
- void load(String file) throws IOException {
- Properties mainProperties = new Properties();
- try (InputStream inputStream = new FileInputStream(file)) {
- mainProperties.loadFromXML(inputStream);
- }
-
- String defaultConfigFile = mainProperties.getProperty("config.default");
- if (defaultConfigFile != null) {
- try (InputStream inputStream = new FileInputStream(defaultConfigFile)) {
- properties.loadFromXML(inputStream);
- }
- }
-
- properties.putAll(mainProperties); // override defaults
-
- useEnvironmentVariables = Boolean.parseBoolean(System.getenv("CONFIG_USE_ENVIRONMENT_VARIABLES"))
- || Boolean.parseBoolean(properties.getProperty("config.useEnvironmentVariables"));
- }
-
- public boolean hasKey(String key) {
- return useEnvironmentVariables && System.getenv().containsKey(getEnvironmentVariableName(key))
- || properties.containsKey(key);
- }
-
- public String getString(String key) {
- if (useEnvironmentVariables) {
- String value = System.getenv(getEnvironmentVariableName(key));
- if (value != null && !value.isEmpty()) {
- return value;
- }
- }
- return properties.getProperty(key);
- }
-
- public String getString(String key, String defaultValue) {
- return hasKey(key) ? getString(key) : defaultValue;
- }
-
- public boolean getBoolean(String key) {
- return Boolean.parseBoolean(getString(key));
- }
-
- public int getInteger(String key) {
- return getInteger(key, 0);
- }
-
- public int getInteger(String key, int defaultValue) {
- return hasKey(key) ? Integer.parseInt(getString(key)) : defaultValue;
- }
-
- public long getLong(String key) {
- return getLong(key, 0);
- }
-
- public long getLong(String key, long defaultValue) {
- return hasKey(key) ? Long.parseLong(getString(key)) : defaultValue;
- }
-
- public double getDouble(String key) {
- return getDouble(key, 0.0);
- }
-
- public double getDouble(String key, double defaultValue) {
- return hasKey(key) ? Double.parseDouble(getString(key)) : defaultValue;
- }
-
- public static String getEnvironmentVariableName(String key) {
- return key.replaceAll("\\.", "_").replaceAll("(\\p{Lu})", "_$1").toUpperCase();
- }
-
- public void setString(String key, String value) {
- properties.put(key, value);
- }
-
-}
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
deleted file mode 100644
index 3b24c6460..000000000
--- a/src/org/traccar/Context.java
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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 com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.ning.http.client.AsyncHttpClient;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Properties;
-
-import org.apache.velocity.app.VelocityEngine;
-import org.eclipse.jetty.util.URIUtil;
-import org.traccar.database.CalendarManager;
-import org.traccar.database.CommandsManager;
-import org.traccar.database.AttributesManager;
-import org.traccar.database.BaseObjectManager;
-import org.traccar.database.ConnectionManager;
-import org.traccar.database.DataManager;
-import org.traccar.database.DeviceManager;
-import org.traccar.database.DriversManager;
-import org.traccar.database.IdentityManager;
-import org.traccar.database.MediaManager;
-import org.traccar.database.NotificationManager;
-import org.traccar.database.PermissionsManager;
-import org.traccar.database.GeofenceManager;
-import org.traccar.database.GroupsManager;
-import org.traccar.database.StatisticsManager;
-import org.traccar.database.UsersManager;
-import org.traccar.events.MotionEventHandler;
-import org.traccar.events.OverspeedEventHandler;
-import org.traccar.geocoder.BingMapsGeocoder;
-import org.traccar.geocoder.FactualGeocoder;
-import org.traccar.geocoder.GeocodeFarmGeocoder;
-import org.traccar.geocoder.GisgraphyGeocoder;
-import org.traccar.geocoder.GoogleGeocoder;
-import org.traccar.geocoder.MapQuestGeocoder;
-import org.traccar.geocoder.NominatimGeocoder;
-import org.traccar.geocoder.OpenCageGeocoder;
-import org.traccar.geocoder.Geocoder;
-import org.traccar.geolocation.UnwiredGeolocationProvider;
-import org.traccar.helper.Log;
-import org.traccar.model.Attribute;
-import org.traccar.model.BaseModel;
-import org.traccar.model.Calendar;
-import org.traccar.model.Command;
-import org.traccar.model.Device;
-import org.traccar.model.Driver;
-import org.traccar.model.Geofence;
-import org.traccar.model.Group;
-import org.traccar.model.Notification;
-import org.traccar.model.User;
-import org.traccar.geolocation.GoogleGeolocationProvider;
-import org.traccar.geolocation.GeolocationProvider;
-import org.traccar.geolocation.MozillaGeolocationProvider;
-import org.traccar.geolocation.OpenCellIdGeolocationProvider;
-import org.traccar.notification.EventForwarder;
-import org.traccar.reports.model.TripsConfig;
-import org.traccar.smpp.SmppClient;
-import org.traccar.web.WebServer;
-
-public final class Context {
-
- private Context() {
- }
-
- private static Config config;
-
- public static Config getConfig() {
- return config;
- }
-
- private static boolean loggerEnabled;
-
- public static boolean isLoggerEnabled() {
- return loggerEnabled;
- }
-
- private static ObjectMapper objectMapper;
-
- public static ObjectMapper getObjectMapper() {
- return objectMapper;
- }
-
- private static IdentityManager identityManager;
-
- public static IdentityManager getIdentityManager() {
- return identityManager;
- }
-
- private static DataManager dataManager;
-
- public static DataManager getDataManager() {
- return dataManager;
- }
-
- private static MediaManager mediaManager;
-
- public static MediaManager getMediaManager() {
- return mediaManager;
- }
-
- private static UsersManager usersManager;
-
- public static UsersManager getUsersManager() {
- return usersManager;
- }
-
- private static GroupsManager groupsManager;
-
- public static GroupsManager getGroupsManager() {
- return groupsManager;
- }
-
- private static DeviceManager deviceManager;
-
- public static DeviceManager getDeviceManager() {
- return deviceManager;
- }
-
- private static ConnectionManager connectionManager;
-
- public static ConnectionManager getConnectionManager() {
- return connectionManager;
- }
-
- private static PermissionsManager permissionsManager;
-
- public static PermissionsManager getPermissionsManager() {
- return permissionsManager;
- }
-
- private static Geocoder geocoder;
-
- public static Geocoder getGeocoder() {
- return geocoder;
- }
-
- private static GeolocationProvider geolocationProvider;
-
- public static GeolocationProvider getGeolocationProvider() {
- return geolocationProvider;
- }
-
- private static WebServer webServer;
-
- public static WebServer getWebServer() {
- return webServer;
- }
-
- private static ServerManager serverManager;
-
- public static ServerManager getServerManager() {
- return serverManager;
- }
-
- private static GeofenceManager geofenceManager;
-
- public static GeofenceManager getGeofenceManager() {
- return geofenceManager;
- }
-
- private static CalendarManager calendarManager;
-
- public static CalendarManager getCalendarManager() {
- return calendarManager;
- }
-
- private static NotificationManager notificationManager;
-
- public static NotificationManager getNotificationManager() {
- return notificationManager;
- }
-
- private static VelocityEngine velocityEngine;
-
- public static VelocityEngine getVelocityEngine() {
- return velocityEngine;
- }
-
- private static final AsyncHttpClient ASYNC_HTTP_CLIENT = new AsyncHttpClient();
-
- public static AsyncHttpClient getAsyncHttpClient() {
- return ASYNC_HTTP_CLIENT;
- }
-
- private static EventForwarder eventForwarder;
-
- public static EventForwarder getEventForwarder() {
- return eventForwarder;
- }
-
- private static AttributesManager attributesManager;
-
- public static AttributesManager getAttributesManager() {
- return attributesManager;
- }
-
- private static DriversManager driversManager;
-
- public static DriversManager getDriversManager() {
- return driversManager;
- }
-
- private static CommandsManager commandsManager;
-
- public static CommandsManager getCommandsManager() {
- return commandsManager;
- }
-
- private static StatisticsManager statisticsManager;
-
- public static StatisticsManager getStatisticsManager() {
- return statisticsManager;
- }
-
- private static SmppClient smppClient;
-
- public static SmppClient getSmppManager() {
- return smppClient;
- }
-
- private static MotionEventHandler motionEventHandler;
-
- public static MotionEventHandler getMotionEventHandler() {
- return motionEventHandler;
- }
-
- private static OverspeedEventHandler overspeedEventHandler;
-
- public static OverspeedEventHandler getOverspeedEventHandler() {
- return overspeedEventHandler;
- }
-
- private static TripsConfig tripsConfig;
-
- public static TripsConfig getTripsConfig() {
- return tripsConfig;
- }
-
- public static TripsConfig initTripsConfig() {
- return new TripsConfig(
- config.getLong("report.trip.minimalTripDistance", 500),
- config.getLong("report.trip.minimalTripDuration", 300) * 1000,
- config.getLong("report.trip.minimalParkingDuration", 300) * 1000,
- config.getLong("report.trip.minimalNoDataDuration", 3600) * 1000,
- config.getBoolean("report.trip.useIgnition"),
- config.getBoolean("event.motion.processInvalidPositions"),
- config.getDouble("event.motion.speedThreshold", 0.01));
- }
-
- public static void init(String[] arguments) throws Exception {
-
- config = new Config();
- 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);
- }
-
- objectMapper = new ObjectMapper();
- objectMapper.setConfig(
- objectMapper.getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS));
-
- if (config.hasKey("database.url")) {
- dataManager = new DataManager(config);
- }
-
- if (config.hasKey("media.path")) {
- mediaManager = new MediaManager(config);
- }
-
- if (dataManager != null) {
- usersManager = new UsersManager(dataManager);
- groupsManager = new GroupsManager(dataManager);
- deviceManager = new DeviceManager(dataManager);
- }
-
- identityManager = deviceManager;
-
- if (config.getBoolean("geocoder.enable")) {
- String type = config.getString("geocoder.type", "google");
- String url = config.getString("geocoder.url");
- String key = config.getString("geocoder.key");
- String language = config.getString("geocoder.language");
-
- int cacheSize = config.getInteger("geocoder.cacheSize");
- switch (type) {
- case "nominatim":
- geocoder = new NominatimGeocoder(url, key, language, cacheSize);
- break;
- case "gisgraphy":
- geocoder = new GisgraphyGeocoder(url, cacheSize);
- break;
- case "mapquest":
- geocoder = new MapQuestGeocoder(url, key, cacheSize);
- break;
- case "opencage":
- geocoder = new OpenCageGeocoder(url, key, cacheSize);
- break;
- case "bingmaps":
- geocoder = new BingMapsGeocoder(url, key, cacheSize);
- break;
- case "factual":
- geocoder = new FactualGeocoder(url, key, cacheSize);
- break;
- case "geocodefarm":
- geocoder = new GeocodeFarmGeocoder(key, language, cacheSize);
- break;
- default:
- geocoder = new GoogleGeocoder(key, language, cacheSize);
- break;
- }
- }
-
- if (config.getBoolean("geolocation.enable")) {
- String type = config.getString("geolocation.type", "mozilla");
- String url = config.getString("geolocation.url");
- String key = config.getString("geolocation.key");
-
- switch (type) {
- case "google":
- geolocationProvider = new GoogleGeolocationProvider(key);
- break;
- case "opencellid":
- geolocationProvider = new OpenCellIdGeolocationProvider(key);
- break;
- case "unwired":
- geolocationProvider = new UnwiredGeolocationProvider(url, key);
- break;
- default:
- geolocationProvider = new MozillaGeolocationProvider(key);
- break;
- }
- }
-
- if (config.getBoolean("web.enable")) {
- webServer = new WebServer(config, dataManager.getDataSource());
- }
-
- permissionsManager = new PermissionsManager(dataManager, usersManager);
-
- connectionManager = new ConnectionManager();
-
- tripsConfig = initTripsConfig();
-
- if (config.getBoolean("event.enable")) {
- geofenceManager = new GeofenceManager(dataManager);
- calendarManager = new CalendarManager(dataManager);
- notificationManager = new NotificationManager(dataManager);
- Properties velocityProperties = new Properties();
- velocityProperties.setProperty("file.resource.loader.path",
- Context.getConfig().getString("templates.rootPath", "templates") + "/");
- velocityProperties.setProperty("runtime.log.logsystem.class",
- "org.apache.velocity.runtime.log.NullLogChute");
-
- String address;
- try {
- address = config.getString("web.address", InetAddress.getLocalHost().getHostAddress());
- } catch (UnknownHostException e) {
- address = "localhost";
- }
-
- String webUrl = URIUtil.newURI("http", address, config.getInteger("web.port", 8082), "", "");
- webUrl = Context.getConfig().getString("web.url", webUrl);
- velocityProperties.setProperty("web.url", webUrl);
-
- velocityEngine = new VelocityEngine();
- velocityEngine.init(velocityProperties);
-
- motionEventHandler = new MotionEventHandler(tripsConfig);
- overspeedEventHandler = new OverspeedEventHandler(
- Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000,
- Context.getConfig().getBoolean("event.overspeed.notRepeat"));
- }
-
- serverManager = new ServerManager();
-
- if (config.getBoolean("event.forward.enable")) {
- eventForwarder = new EventForwarder();
- }
-
- attributesManager = new AttributesManager(dataManager);
-
- driversManager = new DriversManager(dataManager);
-
- commandsManager = new CommandsManager(dataManager);
-
- statisticsManager = new StatisticsManager();
-
- if (config.getBoolean("sms.smpp.enable")) {
- smppClient = new SmppClient();
- }
-
- }
-
- public static void init(IdentityManager testIdentityManager) {
- config = new Config();
- objectMapper = new ObjectMapper();
- identityManager = testIdentityManager;
- }
-
- public static <T extends BaseModel> BaseObjectManager<T> getManager(Class<T> clazz) {
- if (clazz.equals(Device.class)) {
- return (BaseObjectManager<T>) deviceManager;
- } else if (clazz.equals(Group.class)) {
- return (BaseObjectManager<T>) groupsManager;
- } else if (clazz.equals(User.class)) {
- return (BaseObjectManager<T>) usersManager;
- } else if (clazz.equals(Calendar.class)) {
- return (BaseObjectManager<T>) calendarManager;
- } else if (clazz.equals(Attribute.class)) {
- return (BaseObjectManager<T>) attributesManager;
- } else if (clazz.equals(Geofence.class)) {
- return (BaseObjectManager<T>) geofenceManager;
- } else if (clazz.equals(Driver.class)) {
- return (BaseObjectManager<T>) driversManager;
- } else if (clazz.equals(Command.class)) {
- return (BaseObjectManager<T>) commandsManager;
- } else if (clazz.equals(Notification.class)) {
- return (BaseObjectManager<T>) notificationManager;
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/DefaultDataHandler.java
deleted file mode 100644
index e32fe0e7d..000000000
--- a/src/org/traccar/DefaultDataHandler.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- * 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.helper.Log;
-import org.traccar.model.Position;
-
-public class DefaultDataHandler extends BaseDataHandler {
-
- @Override
- protected Position handlePosition(Position position) {
-
- try {
- Context.getDataManager().addPosition(position);
- } catch (Exception error) {
- Log.warning(error);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/DeviceSession.java b/src/org/traccar/DeviceSession.java
deleted file mode 100644
index 36958287d..000000000
--- a/src/org/traccar/DeviceSession.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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;
-
-public class DeviceSession {
-
- private final long deviceId;
-
- public DeviceSession(long deviceId) {
- this.deviceId = deviceId;
- }
-
- public long getDeviceId() {
- return deviceId;
- }
-
-}
diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java
deleted file mode 100644
index 295bc3b29..000000000
--- a/src/org/traccar/DistanceHandler.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2015 Amila Silva
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.helper.DistanceCalculator;
-import org.traccar.model.Position;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-
-public class DistanceHandler extends BaseDataHandler {
-
- private final boolean filter;
- private final int coordinatesMinError;
- private final int coordinatesMaxError;
-
- public DistanceHandler(boolean filter, int coordinatesMinError, int coordinatesMaxError) {
- this.filter = filter;
- this.coordinatesMinError = coordinatesMinError;
- this.coordinatesMaxError = coordinatesMaxError;
- }
-
- private Position getLastPosition(long deviceId) {
- if (Context.getIdentityManager() != null) {
- return Context.getIdentityManager().getLastPosition(deviceId);
- }
- return null;
- }
-
- @Override
- protected Position handlePosition(Position position) {
-
- double distance = 0.0;
- if (position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
- distance = position.getDouble(Position.KEY_DISTANCE);
- }
- double totalDistance = 0.0;
-
- Position last = getLastPosition(position.getDeviceId());
- if (last != null) {
- totalDistance = last.getDouble(Position.KEY_TOTAL_DISTANCE);
- if (!position.getAttributes().containsKey(Position.KEY_DISTANCE)) {
- distance = DistanceCalculator.distance(
- position.getLatitude(), position.getLongitude(),
- last.getLatitude(), last.getLongitude());
- distance = BigDecimal.valueOf(distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
- }
- if (filter && last.getValid() && last.getLatitude() != 0 && last.getLongitude() != 0) {
- 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());
- distance = 0;
- }
- }
- }
- position.set(Position.KEY_DISTANCE, distance);
- totalDistance = BigDecimal.valueOf(totalDistance + distance).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
- position.set(Position.KEY_TOTAL_DISTANCE, totalDistance);
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
deleted file mode 100644
index 268e6f688..000000000
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
-import org.traccar.model.Position;
-
-import javax.xml.bind.DatatypeConverter;
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-
-public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
-
- private void saveOriginal(Object decodedMessage, Object originalMessage) {
- if (Context.getConfig().getBoolean("database.saveOriginal") && decodedMessage instanceof Position) {
- Position position = (Position) decodedMessage;
- if (originalMessage instanceof ChannelBuffer) {
- ChannelBuffer buf = (ChannelBuffer) originalMessage;
- position.set(Position.KEY_ORIGINAL, ChannelBuffers.hexDump(buf, 0, buf.writerIndex()));
- } else if (originalMessage instanceof String) {
- position.set(Position.KEY_ORIGINAL, DatatypeConverter.printHexBinary(
- ((String) originalMessage).getBytes(StandardCharsets.US_ASCII)));
- }
- }
- }
-
- @Override
- public void handleUpstream(
- ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
- if (!(evt instanceof MessageEvent)) {
- ctx.sendUpstream(evt);
- return;
- }
-
- MessageEvent e = (MessageEvent) evt;
- Object originalMessage = e.getMessage();
- Object decodedMessage = decode(e.getChannel(), e.getRemoteAddress(), originalMessage);
- onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage, decodedMessage);
- if (originalMessage == decodedMessage) {
- ctx.sendUpstream(evt);
- } else {
- if (decodedMessage == null) {
- decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
- }
- if (decodedMessage != null) {
- if (decodedMessage instanceof Collection) {
- for (Object o : (Collection) decodedMessage) {
- saveOriginal(o, originalMessage);
- Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
- }
- } else {
- saveOriginal(decodedMessage, originalMessage);
- Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
- }
- }
- }
- }
-
- protected void onMessageEvent(
- Channel channel, SocketAddress remoteAddress, Object originalMessage, Object decodedMessage) {
- }
-
- protected Object handleEmptyMessage(Channel channel, SocketAddress remoteAddress, Object msg) {
- return null;
- }
-
- protected abstract Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception;
-
-}
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
deleted file mode 100644
index 4cd3eb0eb..000000000
--- a/src/org/traccar/FilterHandler.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.helper.Log;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-public class FilterHandler extends BaseDataHandler {
-
- private boolean filterInvalid;
- private boolean filterZero;
- private boolean filterDuplicate;
- private long filterFuture;
- private boolean filterApproximate;
- private boolean filterStatic;
- private int filterDistance;
- private int filterMaxSpeed;
- private long skipLimit;
- private boolean skipAttributes;
-
- public void setFilterInvalid(boolean filterInvalid) {
- this.filterInvalid = filterInvalid;
- }
-
- public void setFilterZero(boolean filterZero) {
- this.filterZero = filterZero;
- }
-
- public void setFilterDuplicate(boolean filterDuplicate) {
- this.filterDuplicate = filterDuplicate;
- }
-
- public void setFilterFuture(long 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 setFilterMaxSpeed(int filterMaxSpeed) {
- this.filterMaxSpeed = filterMaxSpeed;
- }
-
- public void setSkipLimit(long skipLimit) {
- this.skipLimit = skipLimit;
- }
-
- public void setSkipAttributes(boolean skipAttributes) {
- this.skipAttributes = skipAttributes;
- }
-
- public FilterHandler() {
- Config config = Context.getConfig();
- if (config != null) {
- filterInvalid = config.getBoolean("filter.invalid");
- filterZero = config.getBoolean("filter.zero");
- filterDuplicate = config.getBoolean("filter.duplicate");
- filterFuture = config.getLong("filter.future") * 1000;
- filterApproximate = config.getBoolean("filter.approximate");
- filterStatic = config.getBoolean("filter.static");
- filterDistance = config.getInteger("filter.distance");
- filterMaxSpeed = config.getInteger("filter.maxSpeed");
- skipLimit = config.getLong("filter.skipLimit") * 1000;
- skipAttributes = config.getBoolean("filter.skipAttributes.enable");
- }
- }
-
- private boolean filterInvalid(Position position) {
- return filterInvalid && (!position.getValid()
- || position.getLatitude() > 90 || position.getLongitude() > 180
- || position.getLatitude() < -90 || position.getLongitude() < -180);
- }
-
- private boolean filterZero(Position position) {
- return filterZero && position.getLatitude() == 0.0 && position.getLongitude() == 0.0;
- }
-
- private boolean filterDuplicate(Position position, Position last) {
- if (filterDuplicate && last != null && position.getFixTime().equals(last.getFixTime())) {
- for (String key : position.getAttributes().keySet()) {
- if (!last.getAttributes().containsKey(key)) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- private boolean filterFuture(Position position) {
- return filterFuture != 0 && position.getFixTime().getTime() > System.currentTimeMillis() + filterFuture;
- }
-
- private boolean filterApproximate(Position position) {
- return filterApproximate && position.getBoolean(Position.KEY_APPROXIMATE);
- }
-
- private boolean filterStatic(Position position) {
- return filterStatic && position.getSpeed() == 0.0;
- }
-
- private boolean filterDistance(Position position, Position last) {
- if (filterDistance != 0 && last != null) {
- return position.getDouble(Position.KEY_DISTANCE) < filterDistance;
- }
- return false;
- }
-
- private boolean filterMaxSpeed(Position position, Position last) {
- if (filterMaxSpeed != 0 && last != null) {
- double distance = position.getDouble(Position.KEY_DISTANCE);
- double time = position.getFixTime().getTime() - last.getFixTime().getTime();
- return UnitsConverter.knotsFromMps(distance / (time / 1000)) > filterMaxSpeed;
- }
- return false;
- }
-
- private boolean skipLimit(Position position, Position last) {
- if (skipLimit != 0 && last != null) {
- return (position.getFixTime().getTime() - last.getFixTime().getTime()) > skipLimit;
- }
- return false;
- }
-
- private boolean skipAttributes(Position position) {
- if (skipAttributes) {
- String attributesString = Context.getIdentityManager().lookupAttributeString(
- position.getDeviceId(), "filter.skipAttributes", "", true);
- for (String attribute : attributesString.split("[ ,]")) {
- if (position.getAttributes().containsKey(attribute)) {
- return true;
- }
- }
- }
- return false;
- }
-
- private boolean filter(Position position) {
-
- StringBuilder filterType = new StringBuilder();
-
- Position last = null;
- if (Context.getIdentityManager() != null) {
- last = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- }
-
- if (skipLimit(position, last) || skipAttributes(position)) {
- return false;
- }
-
- if (filterInvalid(position)) {
- filterType.append("Invalid ");
- }
- if (filterZero(position)) {
- filterType.append("Zero ");
- }
- if (filterDuplicate(position, last)) {
- filterType.append("Duplicate ");
- }
- if (filterFuture(position)) {
- filterType.append("Future ");
- }
- if (filterApproximate(position)) {
- filterType.append("Approximate ");
- }
- if (filterStatic(position)) {
- filterType.append("Static ");
- }
- if (filterDistance(position, last)) {
- filterType.append("Distance ");
- }
- if (filterMaxSpeed(position, last)) {
- filterType.append("MaxSpeed ");
- }
-
- if (filterType.length() > 0) {
-
- StringBuilder message = new StringBuilder();
- message.append("Position filtered by ");
- message.append(filterType.toString());
- message.append("filters from device: ");
- message.append(Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId());
- message.append(" with id: ");
- message.append(position.getDeviceId());
-
- Log.info(message.toString());
- return true;
- }
-
- return false;
- }
-
- @Override
- protected Position handlePosition(Position position) {
- if (filter(position)) {
- return null;
- }
- return position;
- }
-
-}
diff --git a/src/org/traccar/GeocoderHandler.java b/src/org/traccar/GeocoderHandler.java
deleted file mode 100644
index a211d1a23..000000000
--- a/src/org/traccar/GeocoderHandler.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
-import org.traccar.geocoder.AddressFormat;
-import org.traccar.geocoder.Geocoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-
-public class GeocoderHandler implements ChannelUpstreamHandler {
-
- private final Geocoder geocoder;
- private final boolean processInvalidPositions;
- private final AddressFormat addressFormat;
- private final int geocoderReuseDistance;
-
- public GeocoderHandler(Geocoder geocoder, boolean processInvalidPositions) {
- this.geocoder = geocoder;
- this.processInvalidPositions = processInvalidPositions;
-
- String formatString = Context.getConfig().getString("geocoder.format");
- if (formatString != null) {
- addressFormat = new AddressFormat(formatString);
- } else {
- addressFormat = new AddressFormat();
- }
-
- geocoderReuseDistance = Context.getConfig().getInteger("geocoder.reuseDistance", 0);
- }
-
- @Override
- public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
- if (!(evt instanceof MessageEvent)) {
- ctx.sendUpstream(evt);
- return;
- }
-
- final MessageEvent event = (MessageEvent) evt;
- Object message = event.getMessage();
- if (message instanceof Position) {
- final Position position = (Position) message;
- if (processInvalidPositions || position.getValid()) {
- if (geocoderReuseDistance != 0) {
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (lastPosition != null && lastPosition.getAddress() != null
- && position.getDouble(Position.KEY_DISTANCE) <= geocoderReuseDistance) {
- position.setAddress(lastPosition.getAddress());
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- return;
- }
- }
-
- Context.getStatisticsManager().registerGeocoderRequest();
-
- geocoder.getAddress(addressFormat, position.getLatitude(), position.getLongitude(),
- new Geocoder.ReverseGeocoderCallback() {
- @Override
- public void onSuccess(String address) {
- position.setAddress(address);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- }
-
- @Override
- public void onFailure(Throwable e) {
- Log.warning("Geocoding failed", e);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- }
- });
- } else {
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- }
- } else {
- Channels.fireMessageReceived(ctx, message, event.getRemoteAddress());
- }
- }
-
-}
diff --git a/src/org/traccar/GeolocationHandler.java b/src/org/traccar/GeolocationHandler.java
deleted file mode 100644
index 346ad5904..000000000
--- a/src/org/traccar/GeolocationHandler.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.jboss.netty.channel.ChannelEvent;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
-import org.traccar.helper.Log;
-import org.traccar.geolocation.GeolocationProvider;
-import org.traccar.model.Position;
-
-public class GeolocationHandler implements ChannelUpstreamHandler {
-
- private final GeolocationProvider geolocationProvider;
- private final boolean processInvalidPositions;
-
- public GeolocationHandler(GeolocationProvider geolocationProvider, boolean processInvalidPositions) {
- this.geolocationProvider = geolocationProvider;
- this.processInvalidPositions = processInvalidPositions;
- }
-
- @Override
- public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
- if (!(evt instanceof MessageEvent)) {
- ctx.sendUpstream(evt);
- return;
- }
-
- final MessageEvent event = (MessageEvent) evt;
- Object message = event.getMessage();
- if (message instanceof Position) {
- final Position position = (Position) message;
- if ((position.getOutdated() || processInvalidPositions && !position.getValid())
- && position.getNetwork() != null) {
- Context.getStatisticsManager().registerGeolocationRequest();
-
- geolocationProvider.getLocation(position.getNetwork(),
- new GeolocationProvider.LocationProviderCallback() {
- @Override
- public void onSuccess(double latitude, double longitude, double accuracy) {
- position.set(Position.KEY_APPROXIMATE, true);
- position.setValid(true);
- position.setFixTime(position.getDeviceTime());
- position.setLatitude(latitude);
- position.setLongitude(longitude);
- position.setAccuracy(accuracy);
- position.setAltitude(0);
- position.setSpeed(0);
- position.setCourse(0);
- position.set(Position.KEY_RSSI, 0);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- }
-
- @Override
- public void onFailure(Throwable e) {
- Log.warning(e);
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- }
- });
- } else {
- Channels.fireMessageReceived(ctx, position, event.getRemoteAddress());
- }
- } else {
- Channels.fireMessageReceived(ctx, message, event.getRemoteAddress());
- }
- }
-
-}
diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java
deleted file mode 100644
index c5cd1a697..000000000
--- a/src/org/traccar/GlobalChannelFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.ChannelFactory;
-import org.jboss.netty.channel.socket.DatagramChannelFactory;
-import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
-import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
-
-public final class GlobalChannelFactory {
-
- private static ChannelFactory channelFactory = null;
- private static DatagramChannelFactory datagramChannelFactory = null;
-
- private GlobalChannelFactory() {
- }
-
- public static void release() {
- if (channelFactory != null) {
- channelFactory.releaseExternalResources();
- }
- if (datagramChannelFactory != null) {
- datagramChannelFactory.releaseExternalResources();
- }
- channelFactory = null;
- datagramChannelFactory = null;
- }
-
- public static ChannelFactory getFactory() {
- if (channelFactory == null) {
- channelFactory = new NioServerSocketChannelFactory();
- }
- return channelFactory;
- }
-
- public static DatagramChannelFactory getDatagramFactory() {
- if (datagramChannelFactory == null) {
- datagramChannelFactory = new NioDatagramChannelFactory();
- }
- return datagramChannelFactory;
- }
-
-}
diff --git a/src/org/traccar/GlobalTimer.java b/src/org/traccar/GlobalTimer.java
deleted file mode 100644
index 70e6e2e45..000000000
--- a/src/org/traccar/GlobalTimer.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.util.HashedWheelTimer;
-import org.jboss.netty.util.Timer;
-
-public final class GlobalTimer {
-
- private static Timer instance = null;
-
- private GlobalTimer() {
- }
-
- public static void release() {
- if (instance != null) {
- instance.stop();
- }
- instance = null;
- }
-
- public static Timer getTimer() {
- if (instance == null) {
- instance = new HashedWheelTimer();
- }
- return instance;
- }
-
-}
diff --git a/src/org/traccar/HemisphereHandler.java b/src/org/traccar/HemisphereHandler.java
deleted file mode 100644
index b1e7d3fb2..000000000
--- a/src/org/traccar/HemisphereHandler.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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;
-
-import org.jboss.netty.channel.Channel;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-
-public class HemisphereHandler extends ExtendedObjectDecoder {
-
- private int latitudeFactor;
- private int longitudeFactor;
-
- public HemisphereHandler() {
- String latitudeHemisphere = Context.getConfig().getString("location.latitudeHemisphere");
- if (latitudeHemisphere != null) {
- if (latitudeHemisphere.equalsIgnoreCase("N")) {
- latitudeFactor = 1;
- } else if (latitudeHemisphere.equalsIgnoreCase("S")) {
- latitudeFactor = -1;
- }
- }
- String longitudeHemisphere = Context.getConfig().getString("location.longitudeHemisphere");
- if (longitudeHemisphere != null) {
- if (longitudeHemisphere.equalsIgnoreCase("E")) {
- longitudeFactor = 1;
- } else if (longitudeHemisphere.equalsIgnoreCase("W")) {
- longitudeFactor = -1;
- }
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- if (msg instanceof Position) {
- Position position = (Position) msg;
- if (latitudeFactor != 0) {
- position.setLatitude(Math.abs(position.getLatitude()) * latitudeFactor);
- }
- if (longitudeFactor != 0) {
- position.setLongitude(Math.abs(position.getLongitude()) * longitudeFactor);
- }
- }
-
- return msg;
- }
-
-}
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
deleted file mode 100644
index 1e2db2693..000000000
--- a/src/org/traccar/Main.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.
- * 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.helper.Log;
-
-import java.sql.SQLException;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.Locale;
-
-public final class Main {
-
- private static final long CLEAN_PERIOD = 24 * 60 * 60 * 1000;
-
- private Main() {
- }
-
- public static void main(String[] args) throws Exception {
- Locale.setDefault(Locale.ENGLISH);
-
- Context.init(args);
- Log.info("Starting server...");
-
- Context.getServerManager().start();
- if (Context.getWebServer() != null) {
- Context.getWebServer().start();
- }
-
- new Timer().scheduleAtFixedRate(new TimerTask() {
- @Override
- public void run() {
- try {
- Context.getDataManager().clearHistory();
- } catch (SQLException error) {
- Log.warning(error);
- }
- }
- }, 0, CLEAN_PERIOD);
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- Log.info("Shutting down server...");
-
- if (Context.getWebServer() != null) {
- Context.getWebServer().stop();
- }
- Context.getServerManager().stop();
- }
- });
- }
-
-}
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
deleted file mode 100644
index 8e88e15b9..000000000
--- a/src/org/traccar/MainEventHandler.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.ExceptionEvent;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.channel.socket.DatagramChannel;
-import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler;
-import org.jboss.netty.handler.timeout.IdleStateEvent;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-public class MainEventHandler extends IdleStateAwareChannelHandler {
-
- private final Set<String> connectionlessProtocols = new HashSet<>();
-
- public MainEventHandler() {
- String connectionlessProtocolList = Context.getConfig().getString("status.ignoreOffline");
- if (connectionlessProtocolList != null) {
- connectionlessProtocols.addAll(Arrays.asList(connectionlessProtocolList.split(",")));
- }
- }
-
- @Override
- public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
-
- if (e.getMessage() != null && e.getMessage() instanceof Position) {
-
- Position position = (Position) e.getMessage();
- try {
- Context.getDeviceManager().updateLatestPosition(position);
- } catch (SQLException error) {
- Log.warning(error);
- }
-
- String uniqueId = Context.getIdentityManager().getById(position.getDeviceId()).getUniqueId();
-
- // Log position
- StringBuilder s = new StringBuilder();
- s.append(formatChannel(e.getChannel())).append(" ");
- s.append("id: ").append(uniqueId).append(", ");
- s.append("time: ").append(
- new SimpleDateFormat(Log.DATE_FORMAT).format(position.getFixTime())).append(", ");
- s.append("lat: ").append(String.format("%.5f", position.getLatitude())).append(", ");
- s.append("lon: ").append(String.format("%.5f", position.getLongitude())).append(", ");
- s.append("speed: ").append(String.format("%.1f", position.getSpeed())).append(", ");
- s.append("course: ").append(String.format("%.1f", position.getCourse()));
- Object cmdResult = position.getAttributes().get(Position.KEY_RESULT);
- if (cmdResult != null) {
- s.append(", result: ").append(cmdResult);
- }
- Log.info(s.toString());
-
- Context.getStatisticsManager().registerMessageStored(position.getDeviceId());
- }
- }
-
- private static String formatChannel(Channel channel) {
- return String.format("[%08X]", channel.getId());
- }
-
- @Override
- public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
- Log.info(formatChannel(e.getChannel()) + " connected");
- }
-
- @Override
- public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
- Log.info(formatChannel(e.getChannel()) + " disconnected");
- closeChannel(e.getChannel());
-
- BaseProtocolDecoder protocolDecoder = (BaseProtocolDecoder) ctx.getPipeline().get("objectDecoder");
- if (ctx.getPipeline().get("httpDecoder") == null
- && !connectionlessProtocols.contains(protocolDecoder.getProtocolName())) {
- Context.getConnectionManager().removeActiveDevice(e.getChannel());
- }
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
- Log.warning(formatChannel(e.getChannel()) + " error", e.getCause());
- closeChannel(e.getChannel());
- }
-
- @Override
- public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) {
- Log.info(formatChannel(e.getChannel()) + " timed out");
- closeChannel(e.getChannel());
- }
-
- private void closeChannel(Channel channel) {
- if (!(channel instanceof DatagramChannel)) {
- channel.close();
- }
- }
-
-}
diff --git a/src/org/traccar/MotionHandler.java b/src/org/traccar/MotionHandler.java
deleted file mode 100644
index 901965dd5..000000000
--- a/src/org/traccar/MotionHandler.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 MotionHandler extends BaseDataHandler {
-
- private double speedThreshold;
-
- public MotionHandler(double speedThreshold) {
- this.speedThreshold = speedThreshold;
- }
-
- @Override
- protected Position handlePosition(Position position) {
- if (!position.getAttributes().containsKey(Position.KEY_MOTION)) {
- position.set(Position.KEY_MOTION, position.getSpeed() > speedThreshold);
- }
- return position;
- }
-
-}
diff --git a/src/org/traccar/Protocol.java b/src/org/traccar/Protocol.java
deleted file mode 100644
index 87ac05298..000000000
--- a/src/org/traccar/Protocol.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.traccar;
-
-import org.traccar.database.ActiveDevice;
-import org.traccar.model.Command;
-
-import java.util.Collection;
-import java.util.List;
-
-public interface Protocol {
-
- String getName();
-
- Collection<String> getSupportedDataCommands();
-
- void sendDataCommand(ActiveDevice activeDevice, Command command);
-
- void initTrackerServers(List<TrackerServer> serverList);
-
- Collection<String> getSupportedTextCommands();
-
- void sendTextCommand(String destAddress, Command command) throws Exception;
-
-}
diff --git a/src/org/traccar/RemoteAddressHandler.java b/src/org/traccar/RemoteAddressHandler.java
deleted file mode 100644
index 188bbcab9..000000000
--- a/src/org/traccar/RemoteAddressHandler.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.Channel;
-import org.traccar.model.Position;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-
-public class RemoteAddressHandler extends ExtendedObjectDecoder {
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String hostAddress = ((InetSocketAddress) remoteAddress).getAddress().getHostAddress();
-
- if (msg instanceof Position) {
- Position position = (Position) msg;
- position.set(Position.KEY_IP, hostAddress);
- }
-
- return msg;
- }
-
-}
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
deleted file mode 100644
index 9b1e2650d..000000000
--- a/src/org/traccar/ServerManager.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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 java.io.File;
-import java.net.URI;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-public class ServerManager {
-
- private final List<TrackerServer> serverList = new LinkedList<>();
- private final Map<String, BaseProtocol> protocolList = new ConcurrentHashMap<>();
-
- public ServerManager() throws Exception {
-
- List<String> names = new LinkedList<>();
- String packageName = "org.traccar.protocol";
- String packagePath = packageName.replace('.', '/');
- URL packageUrl = Thread.currentThread().getContextClassLoader().getResource(packagePath);
-
- if (packageUrl.getProtocol().equals("jar")) {
- String jarFileName = URLDecoder.decode(packageUrl.getFile(), StandardCharsets.UTF_8.name());
- try (JarFile jf = new JarFile(jarFileName.substring(5, jarFileName.indexOf("!")))) {
- Enumeration<JarEntry> jarEntries = jf.entries();
- while (jarEntries.hasMoreElements()) {
- String entryName = jarEntries.nextElement().getName();
- if (entryName.startsWith(packagePath) && entryName.length() > packagePath.length() + 5) {
- names.add(entryName.substring(packagePath.length() + 1, entryName.lastIndexOf('.')));
- }
- }
- }
- } else {
- File folder = new File(new URI(packageUrl.toString()));
- File[] files = folder.listFiles();
- if (files != null) {
- for (File actual: files) {
- String entryName = actual.getName();
- names.add(entryName.substring(0, entryName.lastIndexOf('.')));
- }
- }
- }
-
- for (String name : names) {
- Class protocolClass = Class.forName(packageName + '.' + name);
- if (BaseProtocol.class.isAssignableFrom(protocolClass)) {
- BaseProtocol baseProtocol = (BaseProtocol) protocolClass.newInstance();
- initProtocolServer(baseProtocol);
- protocolList.put(baseProtocol.getName(), baseProtocol);
- }
- }
- }
-
- public BaseProtocol getProtocol(String name) {
- return protocolList.get(name);
- }
-
- public void start() {
- for (TrackerServer server: serverList) {
- server.start();
- }
- }
-
- public void stop() {
- for (TrackerServer server: serverList) {
- server.stop();
- }
-
- // Release resources
- GlobalChannelFactory.release();
- GlobalTimer.release();
- }
-
- private void initProtocolServer(final Protocol protocol) {
- if (Context.getConfig().hasKey(protocol.getName() + ".port")) {
- protocol.initTrackerServers(serverList);
- }
- }
-
-}
diff --git a/src/org/traccar/StringProtocolEncoder.java b/src/org/traccar/StringProtocolEncoder.java
deleted file mode 100644
index 1945ae174..000000000
--- a/src/org/traccar/StringProtocolEncoder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.
- * 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.Command;
-
-import java.util.Map;
-
-public abstract class StringProtocolEncoder extends BaseProtocolEncoder {
-
- public interface ValueFormatter {
- String formatValue(String key, Object value);
- }
-
- protected String formatCommand(Command command, String format, ValueFormatter valueFormatter, String... keys) {
-
- String result = String.format(format, (Object[]) keys);
-
- result = result.replaceAll("\\{" + Command.KEY_UNIQUE_ID + "}", getUniqueId(command.getDeviceId()));
- for (Map.Entry<String, Object> entry : command.getAttributes().entrySet()) {
- String value = null;
- if (valueFormatter != null) {
- value = valueFormatter.formatValue(entry.getKey(), entry.getValue());
- }
- if (value == null) {
- value = entry.getValue().toString();
- }
- result = result.replaceAll("\\{" + entry.getKey() + "}", value);
- }
-
- return result;
- }
-
- protected String formatCommand(Command command, String format, String... keys) {
- return formatCommand(command, format, null, keys);
- }
-
-}
diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java
deleted file mode 100644
index 7e0a6f0c6..000000000
--- a/src/org/traccar/TrackerServer.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.jboss.netty.bootstrap.Bootstrap;
-import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.buffer.HeapChannelBufferFactory;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.group.ChannelGroup;
-import org.jboss.netty.channel.group.ChannelGroupFuture;
-import org.jboss.netty.channel.group.DefaultChannelGroup;
-
-import java.net.InetSocketAddress;
-import java.nio.ByteOrder;
-
-public abstract class TrackerServer {
-
- private final Bootstrap bootstrap;
- private final String protocol;
-
- public boolean isConnectionless() {
- return bootstrap instanceof ConnectionlessBootstrap;
- }
-
- public String getProtocol() {
- return protocol;
- }
-
- public TrackerServer(Bootstrap bootstrap, String protocol) {
- this.bootstrap = bootstrap;
- this.protocol = protocol;
-
- if (bootstrap instanceof ServerBootstrap) {
- bootstrap.setFactory(GlobalChannelFactory.getFactory());
- } else if (bootstrap instanceof ConnectionlessBootstrap) {
- bootstrap.setFactory(GlobalChannelFactory.getDatagramFactory());
- }
-
- address = Context.getConfig().getString(protocol + ".address");
- port = Context.getConfig().getInteger(protocol + ".port");
-
- bootstrap.setPipelineFactory(new BasePipelineFactory(this, protocol) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- TrackerServer.this.addSpecificHandlers(pipeline);
- }
- });
- }
-
- protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
-
- private int port;
-
- public int getPort() {
- return port;
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- private String address;
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- public void setEndianness(ByteOrder byteOrder) {
- bootstrap.setOption("bufferFactory", new HeapChannelBufferFactory(byteOrder));
- bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(byteOrder));
- }
-
- private final ChannelGroup allChannels = new DefaultChannelGroup();
-
- public ChannelGroup getChannelGroup() {
- return allChannels;
- }
-
- public void setPipelineFactory(ChannelPipelineFactory pipelineFactory) {
- bootstrap.setPipelineFactory(pipelineFactory);
- }
-
- public ChannelPipelineFactory getPipelineFactory() {
- return bootstrap.getPipelineFactory();
- }
-
- public void start() {
- InetSocketAddress endpoint;
- if (address == null) {
- endpoint = new InetSocketAddress(port);
- } else {
- endpoint = new InetSocketAddress(address, port);
- }
-
- Channel channel = null;
- if (bootstrap instanceof ServerBootstrap) {
- channel = ((ServerBootstrap) bootstrap).bind(endpoint);
- } else if (bootstrap instanceof ConnectionlessBootstrap) {
- channel = ((ConnectionlessBootstrap) bootstrap).bind(endpoint);
- }
-
- if (channel != null) {
- getChannelGroup().add(channel);
- }
- }
-
- public void stop() {
- ChannelGroupFuture future = getChannelGroup().close();
- future.awaitUninterruptibly();
- }
-
-}
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
deleted file mode 100644
index c64dcc81b..000000000
--- a/src/org/traccar/WebDataHandler.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.
- * 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 com.fasterxml.jackson.core.JsonProcessingException;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Device;
-import org.traccar.model.Position;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.util.Calendar;
-import java.util.Formatter;
-import java.util.Locale;
-import java.util.TimeZone;
-
-public class WebDataHandler extends BaseDataHandler {
-
- private final String url;
-
- public WebDataHandler(String url) {
- this.url = url;
- }
-
- private static String formatSentence(Position position) {
-
- StringBuilder s = new StringBuilder("$GPRMC,");
-
- try (Formatter f = new Formatter(s, Locale.ENGLISH)) {
-
- Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ENGLISH);
- calendar.setTimeInMillis(position.getFixTime().getTime());
-
- f.format("%1$tH%1$tM%1$tS.%1$tL,A,", calendar);
-
- double lat = position.getLatitude();
- double lon = position.getLongitude();
-
- 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);
- }
-
- s.append(Checksum.nmea(s.toString()));
-
- return s.toString();
- }
-
- private String calculateStatus(Position position) {
- if (position.getAttributes().containsKey(Position.KEY_ALARM)) {
- return "0xF841"; // STATUS_PANIC_ON
- } else if (position.getSpeed() < 1.0) {
- return "0xF020"; // STATUS_LOCATION
- } else {
- return "0xF11C"; // STATUS_MOTION_MOVING
- }
- }
-
- public String formatRequest(Position position) {
-
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
-
- String request = url
- .replace("{name}", device.getName())
- .replace("{uniqueId}", device.getUniqueId())
- .replace("{deviceId}", String.valueOf(position.getDeviceId()))
- .replace("{protocol}", String.valueOf(position.getProtocol()))
- .replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime()))
- .replace("{fixTime}", String.valueOf(position.getFixTime().getTime()))
- .replace("{valid}", String.valueOf(position.getValid()))
- .replace("{latitude}", String.valueOf(position.getLatitude()))
- .replace("{longitude}", String.valueOf(position.getLongitude()))
- .replace("{altitude}", String.valueOf(position.getAltitude()))
- .replace("{speed}", String.valueOf(position.getSpeed()))
- .replace("{course}", String.valueOf(position.getCourse()))
- .replace("{statusCode}", calculateStatus(position));
-
- if (position.getAddress() != null) {
- try {
- request = request.replace(
- "{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name()));
- } catch (UnsupportedEncodingException error) {
- Log.warning(error);
- }
- }
-
- if (request.contains("{attributes}")) {
- try {
- String attributes = Context.getObjectMapper().writeValueAsString(position.getAttributes());
- request = request.replace(
- "{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name()));
- } catch (UnsupportedEncodingException | JsonProcessingException error) {
- Log.warning(error);
- }
- }
-
- if (request.contains("{gprmc}")) {
- request = request.replace("{gprmc}", formatSentence(position));
- }
-
- return request;
- }
-
- @Override
- protected Position handlePosition(Position position) {
-
- Context.getAsyncHttpClient().prepareGet(formatRequest(position)).execute();
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/api/AsyncSocket.java b/src/org/traccar/api/AsyncSocket.java
deleted file mode 100644
index 70523d253..000000000
--- a/src/org/traccar/api/AsyncSocket.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.
- * 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;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.eclipse.jetty.websocket.api.Session;
-import org.eclipse.jetty.websocket.api.WebSocketAdapter;
-import org.traccar.Context;
-import org.traccar.database.ConnectionManager;
-import org.traccar.helper.Log;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-public class AsyncSocket extends WebSocketAdapter implements ConnectionManager.UpdateListener {
-
- private static final String KEY_DEVICES = "devices";
- private static final String KEY_POSITIONS = "positions";
- private static final String KEY_EVENTS = "events";
-
- private long userId;
-
- public AsyncSocket(long userId) {
- this.userId = userId;
- }
-
- @Override
- public void onWebSocketConnect(Session session) {
- super.onWebSocketConnect(session);
-
- Map<String, Collection<?>> data = new HashMap<>();
- data.put(KEY_POSITIONS, Context.getDeviceManager().getInitialState(userId));
- sendData(data);
-
- Context.getConnectionManager().addListener(userId, this);
- }
-
- @Override
- public void onWebSocketClose(int statusCode, String reason) {
- super.onWebSocketClose(statusCode, reason);
-
- Context.getConnectionManager().removeListener(userId, this);
- }
-
- @Override
- public void onUpdateDevice(Device device) {
- Map<String, Collection<?>> data = new HashMap<>();
- data.put(KEY_DEVICES, Collections.singletonList(device));
- sendData(data);
- }
-
- @Override
- public void onUpdatePosition(Position position) {
- Map<String, Collection<?>> data = new HashMap<>();
- data.put(KEY_POSITIONS, Collections.singletonList(position));
- sendData(data);
- }
-
- @Override
- public void onUpdateEvent(Event event) {
- Map<String, Collection<?>> data = new HashMap<>();
- data.put(KEY_EVENTS, Collections.singletonList(event));
- sendData(data);
- }
-
- private void sendData(Map<String, Collection<?>> data) {
- if (!data.isEmpty() && isConnected()) {
- try {
- getRemote().sendString(Context.getObjectMapper().writeValueAsString(data), null);
- } catch (JsonProcessingException e) {
- Log.warning(e);
- }
- }
- }
-}
diff --git a/src/org/traccar/api/AsyncSocketServlet.java b/src/org/traccar/api/AsyncSocketServlet.java
deleted file mode 100644
index 9318b6fc6..000000000
--- a/src/org/traccar/api/AsyncSocketServlet.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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;
-
-import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
-import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
-import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
-import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
-import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
-import org.traccar.Context;
-import org.traccar.api.resource.SessionResource;
-
-public class AsyncSocketServlet extends WebSocketServlet {
-
- private static final long ASYNC_TIMEOUT = 10 * 60 * 1000;
-
- @Override
- public void configure(WebSocketServletFactory factory) {
- factory.getPolicy().setIdleTimeout(Context.getConfig().getLong("web.timeout", ASYNC_TIMEOUT));
- factory.setCreator(new WebSocketCreator() {
- @Override
- public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
- if (req.getSession() != null) {
- long userId = (Long) req.getSession().getAttribute(SessionResource.USER_ID_KEY);
- return new AsyncSocket(userId);
- } else {
- return null;
- }
- }
- });
- }
-
-}
diff --git a/src/org/traccar/api/BaseObjectResource.java b/src/org/traccar/api/BaseObjectResource.java
deleted file mode 100644
index 634957a49..000000000
--- a/src/org/traccar/api/BaseObjectResource.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-import java.sql.SQLException;
-import java.util.Set;
-
-import javax.ws.rs.DELETE;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.Response;
-
-import org.traccar.Context;
-import org.traccar.database.BaseObjectManager;
-import org.traccar.database.ExtendedObjectManager;
-import org.traccar.database.ManagableObjects;
-import org.traccar.database.SimpleObjectManager;
-import org.traccar.model.BaseModel;
-import org.traccar.model.Command;
-import org.traccar.model.Device;
-import org.traccar.model.Group;
-import org.traccar.model.User;
-
-public abstract class BaseObjectResource<T extends BaseModel> extends BaseResource {
-
- private Class<T> baseClass;
-
- public BaseObjectResource(Class<T> baseClass) {
- this.baseClass = baseClass;
- }
-
- protected final Class<T> getBaseClass() {
- return baseClass;
- }
-
- protected final Set<Long> getSimpleManagerItems(BaseObjectManager<T> manager, boolean all, long userId) {
- Set<Long> result = null;
- if (all) {
- if (Context.getPermissionsManager().getUserAdmin(getUserId())) {
- result = manager.getAllItems();
- } else {
- Context.getPermissionsManager().checkManager(getUserId());
- result = ((ManagableObjects) manager).getManagedItems(getUserId());
- }
- } else {
- if (userId == 0) {
- userId = getUserId();
- }
- Context.getPermissionsManager().checkUser(getUserId(), userId);
- result = ((ManagableObjects) manager).getUserItems(userId);
- }
- return result;
- }
-
- @POST
- public Response add(T entity) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- if (baseClass.equals(Device.class)) {
- Context.getPermissionsManager().checkDeviceReadonly(getUserId());
- Context.getPermissionsManager().checkDeviceLimit(getUserId());
- } else if (baseClass.equals(Command.class)) {
- Context.getPermissionsManager().checkLimitCommands(getUserId());
- }
-
- BaseObjectManager<T> manager = Context.getManager(baseClass);
- manager.addItem(entity);
-
- Context.getDataManager().linkObject(User.class, getUserId(), baseClass, entity.getId(), true);
-
- if (manager instanceof SimpleObjectManager) {
- ((SimpleObjectManager<T>) manager).refreshUserItems();
- } else if (baseClass.equals(Group.class) || baseClass.equals(Device.class)) {
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- }
- return Response.ok(entity).build();
- }
-
- @Path("{id}")
- @PUT
- public Response update(T entity) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- if (baseClass.equals(Device.class)) {
- Context.getPermissionsManager().checkDeviceReadonly(getUserId());
- } else if (baseClass.equals(User.class)) {
- User before = Context.getPermissionsManager().getUser(entity.getId());
- Context.getPermissionsManager().checkUserUpdate(getUserId(), before, (User) entity);
- } else if (baseClass.equals(Command.class)) {
- Context.getPermissionsManager().checkLimitCommands(getUserId());
- }
- Context.getPermissionsManager().checkPermission(baseClass, getUserId(), entity.getId());
-
- Context.getManager(baseClass).updateItem(entity);
-
- if (baseClass.equals(Group.class) || baseClass.equals(Device.class)) {
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- }
- return Response.ok(entity).build();
- }
-
- @Path("{id}")
- @DELETE
- public Response remove(@PathParam("id") long id) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- if (baseClass.equals(Device.class)) {
- Context.getPermissionsManager().checkDeviceReadonly(getUserId());
- } else if (baseClass.equals(Command.class)) {
- Context.getPermissionsManager().checkLimitCommands(getUserId());
- }
- Context.getPermissionsManager().checkPermission(baseClass, getUserId(), id);
-
- BaseObjectManager<T> manager = Context.getManager(baseClass);
- manager.removeItem(id);
-
- if (manager instanceof SimpleObjectManager) {
- ((SimpleObjectManager<T>) manager).refreshUserItems();
- if (manager instanceof ExtendedObjectManager) {
- ((ExtendedObjectManager<T>) manager).refreshExtendedPermissions();
- }
- }
- if (baseClass.equals(Group.class) || baseClass.equals(Device.class) || baseClass.equals(User.class)) {
- Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
- if (baseClass.equals(User.class)) {
- Context.getPermissionsManager().refreshAllUsersPermissions();
- } else {
- Context.getPermissionsManager().refreshAllExtendedPermissions();
- }
- }
- return Response.noContent().build();
- }
-
-}
diff --git a/src/org/traccar/api/BaseResource.java b/src/org/traccar/api/BaseResource.java
deleted file mode 100644
index cc272df9c..000000000
--- a/src/org/traccar/api/BaseResource.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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;
-
-import javax.ws.rs.core.SecurityContext;
-
-public class BaseResource {
-
- @javax.ws.rs.core.Context
- private SecurityContext securityContext;
-
- protected long getUserId() {
- UserPrincipal principal = (UserPrincipal) securityContext.getUserPrincipal();
- if (principal != null) {
- return principal.getUserId();
- }
- return 0;
- }
-}
diff --git a/src/org/traccar/api/CorsResponseFilter.java b/src/org/traccar/api/CorsResponseFilter.java
deleted file mode 100644
index 70ea7e3e1..000000000
--- a/src/org/traccar/api/CorsResponseFilter.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * 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;
-
-import org.jboss.netty.handler.codec.http.HttpHeaders;
-import org.traccar.Context;
-
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-import java.io.IOException;
-
-public class CorsResponseFilter implements ContainerResponseFilter {
-
- private static final String ORIGIN_ALL = "*";
- private static final String HEADERS_ALL = "origin, content-type, accept, authorization";
- private static final String METHODS_ALL = "GET, POST, PUT, DELETE, OPTIONS";
-
- @Override
- public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException {
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS, HEADERS_ALL);
- }
-
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS, true);
- }
-
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_METHODS)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_METHODS, METHODS_ALL);
- }
-
- if (!response.getHeaders().containsKey(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)) {
- String origin = request.getHeaderString(HttpHeaders.Names.ORIGIN);
- String allowed = Context.getConfig().getString("web.origin");
-
- if (origin == null) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN, ORIGIN_ALL);
- } else if (allowed == null || allowed.equals(ORIGIN_ALL) || allowed.contains(origin)) {
- response.getHeaders().add(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
- }
- }
- }
-
-}
diff --git a/src/org/traccar/api/ExtendedObjectResource.java b/src/org/traccar/api/ExtendedObjectResource.java
deleted file mode 100644
index 007a7b1bd..000000000
--- a/src/org/traccar/api/ExtendedObjectResource.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.QueryParam;
-
-import org.traccar.Context;
-import org.traccar.database.ExtendedObjectManager;
-import org.traccar.model.BaseModel;
-
-public class ExtendedObjectResource<T extends BaseModel> extends BaseObjectResource<T> {
-
- public ExtendedObjectResource(Class<T> baseClass) {
- super(baseClass);
- }
-
- @GET
- public Collection<T> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId, @QueryParam("groupId") long groupId,
- @QueryParam("deviceId") long deviceId, @QueryParam("refresh") boolean refresh) throws SQLException {
-
- ExtendedObjectManager<T> manager = (ExtendedObjectManager<T>) Context.getManager(getBaseClass());
- if (refresh) {
- manager.refreshItems();
- }
-
- Set<Long> result = new HashSet<>(getSimpleManagerItems(manager, all, userId));
-
- if (groupId != 0) {
- Context.getPermissionsManager().checkGroup(getUserId(), groupId);
- result.retainAll(manager.getGroupItems(groupId));
- }
-
- if (deviceId != 0) {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- result.retainAll(manager.getDeviceItems(deviceId));
- }
- return manager.getItems(result);
-
- }
-
-}
diff --git a/src/org/traccar/api/ObjectMapperProvider.java b/src/org/traccar/api/ObjectMapperProvider.java
deleted file mode 100644
index f81b20917..000000000
--- a/src/org/traccar/api/ObjectMapperProvider.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- * 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;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.traccar.Context;
-
-import javax.ws.rs.ext.ContextResolver;
-import javax.ws.rs.ext.Provider;
-
-@Provider
-public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
-
- @Override
- public ObjectMapper getContext(Class<?> type) {
- return Context.getObjectMapper();
- }
-
-}
diff --git a/src/org/traccar/api/ResourceErrorHandler.java b/src/org/traccar/api/ResourceErrorHandler.java
deleted file mode 100644
index 1d618b08d..000000000
--- a/src/org/traccar/api/ResourceErrorHandler.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.
- * 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;
-
-import org.traccar.helper.Log;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.ext.ExceptionMapper;
-
-public class ResourceErrorHandler implements ExceptionMapper<Exception> {
-
- @Override
- public Response toResponse(Exception e) {
- if (e instanceof WebApplicationException) {
- 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 {
- 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
deleted file mode 100644
index 7024bdbc9..000000000
--- a/src/org/traccar/api/SecurityRequestFilter.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.
- * 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;
-
-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;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.ResourceInfo;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.SecurityContext;
-import javax.xml.bind.DatatypeConverter;
-import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
-import java.sql.SQLException;
-
-public class SecurityRequestFilter implements ContainerRequestFilter {
-
- public static final String AUTHORIZATION_HEADER = "Authorization";
- public static final String WWW_AUTHENTICATE = "WWW-Authenticate";
- public static final String BASIC_REALM = "Basic realm=\"api\"";
- public static final String X_REQUESTED_WITH = "X-Requested-With";
- public static final String XML_HTTP_REQUEST = "XMLHttpRequest";
-
- public static String[] decodeBasicAuth(String auth) {
- auth = auth.replaceFirst("[B|b]asic ", "");
- byte[] decodedBytes = DatatypeConverter.parseBase64Binary(auth);
- if (decodedBytes != null && decodedBytes.length > 0) {
- return new String(decodedBytes, StandardCharsets.US_ASCII).split(":", 2);
- }
- return null;
- }
-
- @javax.ws.rs.core.Context
- private HttpServletRequest request;
-
- @javax.ws.rs.core.Context
- private ResourceInfo resourceInfo;
-
- @Override
- public void filter(ContainerRequestContext requestContext) {
-
- if (requestContext.getMethod().equals("OPTIONS")) {
- return;
- }
-
- SecurityContext securityContext = null;
-
- try {
-
- 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);
- }
-
- } 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));
- }
-
- }
-
- } catch (SecurityException e) {
- Log.warning(e);
- }
-
- if (securityContext != null) {
- requestContext.setSecurityContext(securityContext);
- } else {
- Method method = resourceInfo.getResourceMethod();
- if (!method.isAnnotationPresent(PermitAll.class)) {
- Response.ResponseBuilder responseBuilder = Response.status(Response.Status.UNAUTHORIZED);
- if (!XML_HTTP_REQUEST.equals(request.getHeader(X_REQUESTED_WITH))) {
- responseBuilder.header(WWW_AUTHENTICATE, BASIC_REALM);
- }
- throw new WebApplicationException(responseBuilder.build());
- }
- }
-
- }
-
-}
diff --git a/src/org/traccar/api/SimpleObjectResource.java b/src/org/traccar/api/SimpleObjectResource.java
deleted file mode 100644
index a7fcae0e7..000000000
--- a/src/org/traccar/api/SimpleObjectResource.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-import java.sql.SQLException;
-import java.util.Collection;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.QueryParam;
-
-import org.traccar.Context;
-import org.traccar.database.BaseObjectManager;
-import org.traccar.model.BaseModel;
-
-public class SimpleObjectResource<T extends BaseModel> extends BaseObjectResource<T> {
-
- public SimpleObjectResource(Class<T> baseClass) {
- super(baseClass);
- }
-
- @GET
- public Collection<T> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException {
-
- BaseObjectManager<T> manager = Context.getManager(getBaseClass());
- return manager.getItems(getSimpleManagerItems(manager, all, userId));
- }
-
-}
diff --git a/src/org/traccar/api/UserPrincipal.java b/src/org/traccar/api/UserPrincipal.java
deleted file mode 100644
index 80e92c2dd..000000000
--- a/src/org/traccar/api/UserPrincipal.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.
- * 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;
-
-import java.security.Principal;
-
-public class UserPrincipal implements Principal {
-
- private long userId;
-
- public UserPrincipal(long userId) {
- this.userId = userId;
- }
-
- public Long getUserId() {
- return userId;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
-}
diff --git a/src/org/traccar/api/UserSecurityContext.java b/src/org/traccar/api/UserSecurityContext.java
deleted file mode 100644
index 55c0621bc..000000000
--- a/src/org/traccar/api/UserSecurityContext.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.
- * 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;
-
-import javax.ws.rs.core.SecurityContext;
-import java.security.Principal;
-
-public class UserSecurityContext implements SecurityContext {
-
- private UserPrincipal principal;
-
- public UserSecurityContext(UserPrincipal principal) {
- this.principal = principal;
- }
-
- @Override
- public Principal getUserPrincipal() {
- return principal;
- }
-
- @Override
- public boolean isUserInRole(String role) {
- return true;
- }
-
- @Override
- public boolean isSecure() {
- return false;
- }
-
- @Override
- public String getAuthenticationScheme() {
- return BASIC_AUTH;
- }
-
-}
diff --git a/src/org/traccar/api/resource/AttributeResource.java b/src/org/traccar/api/resource/AttributeResource.java
deleted file mode 100644
index 26a1f6931..000000000
--- a/src/org/traccar/api/resource/AttributeResource.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-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.ExtendedObjectResource;
-import org.traccar.model.Attribute;
-import org.traccar.model.Position;
-import org.traccar.processing.ComputedAttributesHandler;
-
-@Path("attributes/computed")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class AttributeResource extends ExtendedObjectResource<Attribute> {
-
- public AttributeResource() {
- super(Attribute.class);
- }
-
- @POST
- @Path("test")
- public Response test(@QueryParam("deviceId") long deviceId, Attribute entity) throws SQLException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- Position last = Context.getIdentityManager().getLastPosition(deviceId);
- if (last != null) {
- Object result = new ComputedAttributesHandler().computeAttribute(entity, last);
- if (result != null) {
- switch (entity.getType()) {
- case "number":
- return Response.ok((Number) result).build();
- case "boolean":
- return Response.ok((Boolean) result).build();
- default:
- return Response.ok(result.toString()).build();
- }
- } else {
- return Response.noContent().build();
- }
- } else {
- throw new IllegalArgumentException("Device has no last position");
- }
- }
-
-}
diff --git a/src/org/traccar/api/resource/CalendarResource.java b/src/org/traccar/api/resource/CalendarResource.java
deleted file mode 100644
index 9399c34a5..000000000
--- a/src/org/traccar/api/resource/CalendarResource.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 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 javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import org.traccar.api.SimpleObjectResource;
-import org.traccar.model.Calendar;
-
-@Path("calendars")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class CalendarResource extends SimpleObjectResource<Calendar> {
-
- public CalendarResource() {
- super(Calendar.class);
- }
-
-}
diff --git a/src/org/traccar/api/resource/CommandResource.java b/src/org/traccar/api/resource/CommandResource.java
deleted file mode 100644
index 703638701..000000000
--- a/src/org/traccar/api/resource/CommandResource.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com)
- * Copyright 2017 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 org.traccar.Context;
-import org.traccar.api.ExtendedObjectResource;
-import org.traccar.database.CommandsManager;
-import org.traccar.model.Command;
-import org.traccar.model.Typed;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.ws.rs.Consumes;
-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.core.MediaType;
-import javax.ws.rs.core.Response;
-
-@Path("commands")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class CommandResource extends ExtendedObjectResource<Command> {
-
- public CommandResource() {
- super(Command.class);
- }
-
- @GET
- @Path("send")
- public Collection<Command> get(@QueryParam("deviceId") long deviceId) throws SQLException {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- CommandsManager commandsManager = Context.getCommandsManager();
- Set<Long> result = new HashSet<>(commandsManager.getUserItems(getUserId()));
- result.retainAll(commandsManager.getSupportedCommands(deviceId));
- return commandsManager.getItems(result);
- }
-
- @POST
- @Path("send")
- public Response send(Command entity) throws Exception {
- Context.getPermissionsManager().checkReadonly(getUserId());
- long deviceId = entity.getDeviceId();
- long id = entity.getId();
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- if (id != 0) {
- Context.getPermissionsManager().checkPermission(Command.class, getUserId(), id);
- Context.getPermissionsManager().checkUserDeviceCommand(getUserId(), deviceId, id);
- } else {
- Context.getPermissionsManager().checkLimitCommands(getUserId());
- }
- if (!Context.getCommandsManager().sendCommand(entity)) {
- return Response.accepted(entity).build();
- }
- return Response.ok(entity).build();
- }
-
- @GET
- @Path("types")
- public Collection<Typed> get(@QueryParam("deviceId") long deviceId,
- @QueryParam("textChannel") boolean textChannel) {
- if (deviceId != 0) {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- return Context.getCommandsManager().getCommandTypes(deviceId, textChannel);
- } else {
- return Context.getCommandsManager().getAllCommandTypes();
- }
- }
-}
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
deleted file mode 100644
index 1fae92dc7..000000000
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.BaseObjectResource;
-import org.traccar.database.DeviceManager;
-import org.traccar.model.Device;
-import org.traccar.model.DeviceTotalDistance;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-@Path("devices")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class DeviceResource extends BaseObjectResource<Device> {
-
- public DeviceResource() {
- super(Device.class);
- }
-
- @GET
- public Collection<Device> get(
- @QueryParam("all") boolean all, @QueryParam("userId") long userId,
- @QueryParam("uniqueId") List<String> uniqueIds,
- @QueryParam("id") List<Long> deviceIds) throws SQLException {
- DeviceManager deviceManager = Context.getDeviceManager();
- Set<Long> result = null;
- if (all) {
- if (Context.getPermissionsManager().getUserAdmin(getUserId())) {
- result = deviceManager.getAllItems();
- } else {
- Context.getPermissionsManager().checkManager(getUserId());
- result = deviceManager.getManagedItems(getUserId());
- }
- } else if (uniqueIds.isEmpty() && deviceIds.isEmpty()) {
- if (userId == 0) {
- userId = getUserId();
- }
- Context.getPermissionsManager().checkUser(getUserId(), userId);
- result = deviceManager.getUserItems(userId);
- } else {
- result = new HashSet<Long>();
- for (String uniqueId : uniqueIds) {
- Device device = deviceManager.getByUniqueId(uniqueId);
- Context.getPermissionsManager().checkDevice(getUserId(), device.getId());
- result.add(device.getId());
- }
- for (Long deviceId : deviceIds) {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- result.add(deviceId);
- }
- }
- return deviceManager.getItems(result);
- }
-
- @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/DriverResource.java b/src/org/traccar/api/resource/DriverResource.java
deleted file mode 100644
index 91aa54c5e..000000000
--- a/src/org/traccar/api/resource/DriverResource.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import org.traccar.api.ExtendedObjectResource;
-import org.traccar.model.Driver;
-
-@Path("drivers")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class DriverResource extends ExtendedObjectResource<Driver> {
-
- public DriverResource() {
- super(Driver.class);
- }
-
-}
diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java
deleted file mode 100644
index a7cf9edbd..000000000
--- a/src/org/traccar/api/resource/EventResource.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.traccar.api.resource;
-
-import java.sql.SQLException;
-
-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.core.MediaType;
-
-import org.traccar.Context;
-import org.traccar.api.BaseResource;
-import org.traccar.model.Event;
-import org.traccar.model.Geofence;
-
-@Path("events")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-
-public class EventResource extends BaseResource {
-
- @Path("{id}")
- @GET
- public Event get(@PathParam("id") long id) throws SQLException {
- Event event = Context.getDataManager().getObject(Event.class, id);
- Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
- if (event.getGeofenceId() != 0) {
- Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId());
- }
- return event;
- }
-
-}
diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java
deleted file mode 100644
index 58f2c188c..000000000
--- a/src/org/traccar/api/resource/GeofenceResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.api.ExtendedObjectResource;
-import org.traccar.model.Geofence;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-@Path("geofences")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class GeofenceResource extends ExtendedObjectResource<Geofence> {
-
- public GeofenceResource() {
- super(Geofence.class);
- }
-
-}
diff --git a/src/org/traccar/api/resource/GroupResource.java b/src/org/traccar/api/resource/GroupResource.java
deleted file mode 100644
index fcea15d0a..000000000
--- a/src/org/traccar/api/resource/GroupResource.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.api.SimpleObjectResource;
-import org.traccar.model.Group;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-@Path("groups")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class GroupResource extends SimpleObjectResource<Group> {
-
- public GroupResource() {
- super(Group.class);
- }
-
-}
diff --git a/src/org/traccar/api/resource/NotificationResource.java b/src/org/traccar/api/resource/NotificationResource.java
deleted file mode 100644
index 540f02926..000000000
--- a/src/org/traccar/api/resource/NotificationResource.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.util.Collection;
-
-import javax.mail.MessagingException;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.traccar.Context;
-import org.traccar.api.ExtendedObjectResource;
-import org.traccar.model.Event;
-import org.traccar.model.Notification;
-import org.traccar.model.Typed;
-import org.traccar.notification.NotificationMail;
-import org.traccar.notification.NotificationSms;
-
-import com.cloudhopper.smpp.type.RecoverablePduException;
-import com.cloudhopper.smpp.type.SmppChannelException;
-import com.cloudhopper.smpp.type.SmppTimeoutException;
-import com.cloudhopper.smpp.type.UnrecoverablePduException;
-
-@Path("notifications")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class NotificationResource extends ExtendedObjectResource<Notification> {
-
- public NotificationResource() {
- super(Notification.class);
- }
-
- @GET
- @Path("types")
- public Collection<Typed> get() {
- return Context.getNotificationManager().getAllNotificationTypes();
- }
-
- @POST
- @Path("test")
- public Response testMessage() throws MessagingException, RecoverablePduException,
- UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
- NotificationMail.sendMailSync(getUserId(), new Event("test", 0), null);
- NotificationSms.sendSmsSync(getUserId(), new Event("test", 0), null);
- return Response.noContent().build();
- }
-
-}
diff --git a/src/org/traccar/api/resource/PermissionsResource.java b/src/org/traccar/api/resource/PermissionsResource.java
deleted file mode 100644
index 9b9f65ad1..000000000
--- a/src/org/traccar/api/resource/PermissionsResource.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.LinkedHashMap;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-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.Device;
-import org.traccar.model.Permission;
-import org.traccar.model.User;
-
-@Path("permissions")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class PermissionsResource extends BaseResource {
-
- private void checkPermission(Permission permission, boolean link) {
- if (!link && permission.getOwnerClass().equals(User.class)
- && permission.getPropertyClass().equals(Device.class)) {
- if (getUserId() != permission.getOwnerId()) {
- Context.getPermissionsManager().checkUser(getUserId(), permission.getOwnerId());
- } else {
- Context.getPermissionsManager().checkAdmin(getUserId());
- }
- } else {
- Context.getPermissionsManager().checkPermission(
- permission.getOwnerClass(), getUserId(), permission.getOwnerId());
- }
- Context.getPermissionsManager().checkPermission(
- permission.getPropertyClass(), getUserId(), permission.getPropertyId());
- }
-
- @POST
- public Response add(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- Permission permission = new Permission(entity);
- checkPermission(permission, true);
- Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
- permission.getPropertyClass(), permission.getPropertyId(), true);
- Context.getPermissionsManager().refreshPermissions(permission);
- return Response.noContent().build();
- }
-
- @DELETE
- public Response remove(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
- Context.getPermissionsManager().checkReadonly(getUserId());
- Permission permission = new Permission(entity);
- checkPermission(permission, false);
- Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(),
- permission.getPropertyClass(), permission.getPropertyId(), false);
- Context.getPermissionsManager().refreshPermissions(permission);
- return Response.noContent().build();
- }
-
-}
diff --git a/src/org/traccar/api/resource/PositionResource.java b/src/org/traccar/api/resource/PositionResource.java
deleted file mode 100644
index c031b842f..000000000
--- a/src/org/traccar/api/resource/PositionResource.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.
- * 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.Position;
-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.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-@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> getJson(
- @QueryParam("deviceId") long deviceId, @QueryParam("id") List<Long> positionIds,
- @QueryParam("from") String from, @QueryParam("to") String to)
- throws SQLException {
- if (!positionIds.isEmpty()) {
- ArrayList<Position> positions = new ArrayList<>();
- for (Long positionId : positionIds) {
- Position position = Context.getDataManager().getObject(Position.class, positionId);
- Context.getPermissionsManager().checkDevice(getUserId(), position.getDeviceId());
- positions.add(position);
- }
- return positions;
- } else if (deviceId == 0) {
- return Context.getDeviceManager().getInitialState(getUserId());
- } else {
- Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
- return Context.getDataManager().getPositions(
- 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().getById(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
deleted file mode 100644
index 7c472e84d..000000000
--- a/src/org/traccar/api/resource/ReportResource.java
+++ /dev/null
@@ -1,159 +0,0 @@
-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;
-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 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.StopReport;
-import org.traccar.reports.model.SummaryReport;
-import org.traccar.reports.model.TripReport;
-import org.traccar.reports.Route;
-import org.traccar.reports.Stops;
-
-@Path("reports")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class ReportResource extends BaseResource {
-
- 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
- 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 Route.getObjects(getUserId(), deviceIds, groupIds,
- DateUtil.parseDate(from), DateUtil.parseDate(to));
- }
-
- @Path("route")
- @GET
- @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, 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
- 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 Events.getObjects(getUserId(), deviceIds, groupIds, types,
- DateUtil.parseDate(from), DateUtil.parseDate(to));
- }
-
- @Path("events")
- @GET
- @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, 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
- 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 Summary.getObjects(getUserId(), deviceIds, groupIds,
- DateUtil.parseDate(from), DateUtil.parseDate(to));
- }
-
- @Path("summary")
- @GET
- @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, 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 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 Trips.getObjects(getUserId(), deviceIds, groupIds,
- DateUtil.parseDate(from), DateUtil.parseDate(to));
- }
-
- @Path("trips")
- @GET
- @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, 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();
- }
-
- @Path("stops")
- @GET
- @Produces(MediaType.APPLICATION_JSON)
- public Collection<StopReport> getStops(
- @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
- @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException {
- return Stops.getObjects(getUserId(), deviceIds, groupIds,
- DateUtil.parseDate(from), DateUtil.parseDate(to));
- }
-
- @Path("stops")
- @GET
- @Produces(XLSX)
- public Response getStopsExcel(
- @QueryParam("deviceId") final List<Long> deviceIds, @QueryParam("groupId") final List<Long> groupIds,
- @QueryParam("from") String from, @QueryParam("to") String to) throws SQLException, IOException {
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- Stops.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
deleted file mode 100644
index 034a5c492..000000000
--- a/src/org/traccar/api/resource/ServerResource.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.
- * 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.model.Server;
-
-import javax.annotation.security.PermitAll;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.sql.SQLException;
-
-@Path("server")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class ServerResource extends BaseResource {
-
- @PermitAll
- @GET
- public Server get() throws SQLException {
- return Context.getPermissionsManager().getServer();
- }
-
- @PUT
- public Response update(Server entity) throws SQLException {
- Context.getPermissionsManager().checkAdmin(getUserId());
- Context.getPermissionsManager().updateServer(entity);
- return Response.ok(entity).build();
- }
-
-}
diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java
deleted file mode 100644
index fa2a14c6f..000000000
--- a/src/org/traccar/api/resource/SessionResource.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.
- * 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.model.User;
-
-import javax.annotation.security.PermitAll;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.FormParam;
-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;
-import javax.xml.bind.DatatypeConverter;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.sql.SQLException;
-
-@Path("session")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
-public class SessionResource extends BaseResource {
-
- public static final String USER_ID_KEY = "userId";
- public static final String USER_COOKIE_KEY = "user";
- public static final String PASS_COOKIE_KEY = "password";
-
- @javax.ws.rs.core.Context
- private HttpServletRequest request;
-
- @PermitAll
- @GET
- public User get(@QueryParam("token") String token) throws SQLException, UnsupportedEncodingException {
- Long userId = (Long) request.getSession().getAttribute(USER_ID_KEY);
- if (userId == null) {
- Cookie[] cookies = request.getCookies();
- String email = null, password = null;
- if (cookies != null) {
- for (int i = 0; i < cookies.length; i++) {
- if (cookies[i].getName().equals(USER_COOKIE_KEY)) {
- byte[] emailBytes = DatatypeConverter.parseBase64Binary(
- URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name()));
- email = new String(emailBytes, StandardCharsets.UTF_8);
- }
- if (cookies[i].getName().equals(PASS_COOKIE_KEY)) {
- byte[] passwordBytes = DatatypeConverter.parseBase64Binary(
- URLDecoder.decode(cookies[i].getValue(), StandardCharsets.US_ASCII.name()));
- password = new String(passwordBytes, StandardCharsets.UTF_8);
- }
- }
- }
- if (email != null && password != null) {
- 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.getUsersManager().getUserByToken(token);
- if (user != null) {
- userId = user.getId();
- request.getSession().setAttribute(USER_ID_KEY, userId);
- }
- }
- }
-
- if (userId != null) {
- Context.getPermissionsManager().checkUserEnabled(userId);
- return Context.getPermissionsManager().getUser(userId);
- } else {
- throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
- }
- }
-
- @PermitAll
- @POST
- public User add(
- @FormParam("email") String email, @FormParam("password") String password) throws SQLException {
- User user = Context.getPermissionsManager().login(email, password);
- if (user != null) {
- request.getSession().setAttribute(USER_ID_KEY, user.getId());
- return user;
- } else {
- throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
- }
- }
-
- @DELETE
- public Response remove() {
- request.getSession().removeAttribute(USER_ID_KEY);
- return Response.noContent().build();
- }
-
-}
diff --git a/src/org/traccar/api/resource/StatisticsResource.java b/src/org/traccar/api/resource/StatisticsResource.java
deleted file mode 100644
index e801d4ff3..000000000
--- a/src/org/traccar/api/resource/StatisticsResource.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 0f6f6edba..000000000
--- a/src/org/traccar/api/resource/UserResource.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.BaseObjectResource;
-import org.traccar.database.UsersManager;
-import org.traccar.model.ManagedUser;
-import org.traccar.model.User;
-
-import javax.annotation.security.PermitAll;
-import javax.ws.rs.Consumes;
-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.core.MediaType;
-import javax.ws.rs.core.Response;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Set;
-
-@Path("users")
-@Produces(MediaType.APPLICATION_JSON)
-@Consumes(MediaType.APPLICATION_JSON)
-public class UserResource extends BaseObjectResource<User> {
-
- public UserResource() {
- super(User.class);
- }
-
- @GET
- public Collection<User> get(@QueryParam("userId") long userId) throws SQLException {
- UsersManager usersManager = Context.getUsersManager();
- Set<Long> result = null;
- if (Context.getPermissionsManager().getUserAdmin(getUserId())) {
- if (userId != 0) {
- result = usersManager.getUserItems(userId);
- } else {
- result = usersManager.getAllItems();
- }
- } else if (Context.getPermissionsManager().getUserManager(getUserId())) {
- result = usersManager.getManagedItems(getUserId());
- } else {
- throw new SecurityException("Admin or manager access required");
- }
- return usersManager.getItems(result);
- }
-
- @Override
- @PermitAll
- @POST
- public Response add(User entity) throws SQLException {
- if (!Context.getPermissionsManager().getUserAdmin(getUserId())) {
- Context.getPermissionsManager().checkUserUpdate(getUserId(), new User(), entity);
- if (Context.getPermissionsManager().getUserManager(getUserId())) {
- Context.getPermissionsManager().checkUserLimit(getUserId());
- } else {
- Context.getPermissionsManager().checkRegistration(getUserId());
- entity.setDeviceLimit(Context.getConfig().getInteger("users.defaultDeviceLimit", -1));
- int expirationDays = Context.getConfig().getInteger("users.defaultExpirationDays");
- if (expirationDays > 0) {
- entity.setExpirationTime(
- new Date(System.currentTimeMillis() + (long) expirationDays * 24 * 3600 * 1000));
- }
- }
- }
- Context.getUsersManager().addItem(entity);
- if (Context.getPermissionsManager().getUserManager(getUserId())) {
- Context.getDataManager().linkObject(User.class, getUserId(), ManagedUser.class, entity.getId(), true);
- }
- Context.getUsersManager().refreshUserItems();
- return Response.ok(entity).build();
- }
-
-}
diff --git a/src/org/traccar/database/ActiveDevice.java b/src/org/traccar/database/ActiveDevice.java
deleted file mode 100644
index f491111e1..000000000
--- a/src/org/traccar/database/ActiveDevice.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.jboss.netty.channel.Channel;
-import org.traccar.Protocol;
-import org.traccar.model.Command;
-
-import java.net.SocketAddress;
-
-public class ActiveDevice {
-
- private final long deviceId;
- private final Protocol protocol;
- private final Channel channel;
- private final SocketAddress remoteAddress;
-
- public ActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
- this.deviceId = deviceId;
- this.protocol = protocol;
- this.channel = channel;
- this.remoteAddress = remoteAddress;
- }
-
- public Channel getChannel() {
- return channel;
- }
-
- public long getDeviceId() {
- return deviceId;
- }
-
- public void sendCommand(Command command) {
- protocol.sendDataCommand(this, command);
- }
-
- public void write(Object message) {
- getChannel().write(message, remoteAddress);
- }
-
-}
diff --git a/src/org/traccar/database/AttributesManager.java b/src/org/traccar/database/AttributesManager.java
deleted file mode 100644
index 28816645a..000000000
--- a/src/org/traccar/database/AttributesManager.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 org.traccar.model.Attribute;
-
-public class AttributesManager extends ExtendedObjectManager<Attribute> {
-
- public AttributesManager(DataManager dataManager) {
- super(dataManager, Attribute.class);
- }
-
- @Override
- public void updateCachedItem(Attribute attribute) {
- Attribute cachedAttribute = getById(attribute.getId());
- cachedAttribute.setDescription(attribute.getDescription());
- cachedAttribute.setAttribute(attribute.getAttribute());
- cachedAttribute.setExpression(attribute.getExpression());
- cachedAttribute.setType(attribute.getType());
- }
-
-}
diff --git a/src/org/traccar/database/BaseObjectManager.java b/src/org/traccar/database/BaseObjectManager.java
deleted file mode 100644
index cc1dbde5f..000000000
--- a/src/org/traccar/database/BaseObjectManager.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.traccar.helper.Log;
-import org.traccar.model.BaseModel;
-
-public class BaseObjectManager<T extends BaseModel> {
-
- private final DataManager dataManager;
-
- private Map<Long, T> items;
- private Class<T> baseClass;
-
- protected BaseObjectManager(DataManager dataManager, Class<T> baseClass) {
- this.dataManager = dataManager;
- this.baseClass = baseClass;
- refreshItems();
- }
-
- protected final DataManager getDataManager() {
- return dataManager;
- }
-
- protected final Class<T> getBaseClass() {
- return baseClass;
- }
-
- public T getById(long itemId) {
- return items.get(itemId);
- }
-
- public void refreshItems() {
- if (dataManager != null) {
- try {
- Collection<T> databaseItems = dataManager.getObjects(baseClass);
- if (items == null) {
- items = new ConcurrentHashMap<>(databaseItems.size());
- }
- Set<Long> databaseItemIds = new HashSet<>();
- for (T item : databaseItems) {
- databaseItemIds.add(item.getId());
- if (items.containsKey(item.getId())) {
- updateCachedItem(item);
- } else {
- addNewItem(item);
- }
- }
- for (Long cachedItemId : items.keySet()) {
- if (!databaseItemIds.contains(cachedItemId)) {
- removeCachedItem(cachedItemId);
- }
- }
- } catch (SQLException error) {
- Log.warning(error);
- }
- }
- }
-
- protected void addNewItem(T item) {
- items.put(item.getId(), item);
- }
-
- public void addItem(T item) throws SQLException {
- dataManager.addObject(item);
- addNewItem(item);
- }
-
- protected void updateCachedItem(T item) {
- items.put(item.getId(), item);
- }
-
- public void updateItem(T item) throws SQLException {
- dataManager.updateObject(item);
- updateCachedItem(item);
- }
-
- protected void removeCachedItem(long itemId) {
- items.remove(itemId);
- }
-
- public void removeItem(long itemId) throws SQLException {
- BaseModel item = getById(itemId);
- if (item != null) {
- dataManager.removeObject(baseClass, itemId);
- removeCachedItem(itemId);
- }
- }
-
- public final Collection<T> getItems(Set<Long> itemIds) {
- Collection<T> result = new LinkedList<>();
- for (long itemId : itemIds) {
- result.add(getById(itemId));
- }
- return result;
- }
-
- public Set<Long> getAllItems() {
- return items.keySet();
- }
-
-}
diff --git a/src/org/traccar/database/CalendarManager.java b/src/org/traccar/database/CalendarManager.java
deleted file mode 100644
index 44ced1082..000000000
--- a/src/org/traccar/database/CalendarManager.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 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 org.traccar.model.Calendar;
-
-public class CalendarManager extends SimpleObjectManager<Calendar> {
-
- public CalendarManager(DataManager dataManager) {
- super(dataManager, Calendar.class);
- }
-
-}
diff --git a/src/org/traccar/database/CommandsManager.java b/src/org/traccar/database/CommandsManager.java
deleted file mode 100644
index 9ceb995ef..000000000
--- a/src/org/traccar/database/CommandsManager.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import org.traccar.BaseProtocol;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-import org.traccar.model.Typed;
-import org.traccar.model.Position;
-
-public class CommandsManager extends ExtendedObjectManager<Command> {
-
- private final Map<Long, Queue<Command>> deviceQueues = new ConcurrentHashMap<>();
-
- public CommandsManager(DataManager dataManager) {
- super(dataManager, Command.class);
- }
-
- public boolean checkDeviceCommand(long deviceId, long commandId) {
- return !getAllDeviceItems(deviceId).contains(commandId);
- }
-
- public boolean sendCommand(Command command) throws Exception {
- long deviceId = command.getDeviceId();
- if (command.getId() != 0) {
- command = getById(command.getId()).clone();
- command.setDeviceId(deviceId);
- }
- if (command.getTextChannel()) {
- Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
- String phone = Context.getIdentityManager().getById(deviceId).getPhone();
- if (lastPosition != null) {
- BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
- protocol.sendTextCommand(phone, command);
- } else if (command.getType().equals(Command.TYPE_CUSTOM)) {
- if (Context.getSmppManager() != null) {
- Context.getSmppManager().sendMessageSync(phone, command.getString(Command.KEY_DATA), true);
- } else {
- throw new RuntimeException("SMPP client is not enabled");
- }
- } else {
- throw new RuntimeException("Command " + command.getType() + " is not supported");
- }
- } else {
- ActiveDevice activeDevice = Context.getConnectionManager().getActiveDevice(deviceId);
- if (activeDevice != null) {
- activeDevice.sendCommand(command);
- } else {
- getDeviceQueue(deviceId).add(command);
- return false;
- }
- }
- return true;
- }
-
- public Collection<Long> getSupportedCommands(long deviceId) {
- List<Long> result = new ArrayList<>();
- Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
- for (long commandId : getAllDeviceItems(deviceId)) {
- Command command = getById(commandId);
- if (lastPosition != null) {
- BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
- if (command.getTextChannel() && protocol.getSupportedTextCommands().contains(command.getType())
- || !command.getTextChannel()
- && protocol.getSupportedDataCommands().contains(command.getType())) {
- result.add(commandId);
- }
- } else if (command.getType().equals(Command.TYPE_CUSTOM)) {
- result.add(commandId);
- }
- }
- return result;
- }
-
- public Collection<Typed> getCommandTypes(long deviceId, boolean textChannel) {
- List<Typed> result = new ArrayList<>();
- Position lastPosition = Context.getIdentityManager().getLastPosition(deviceId);
- if (lastPosition != null) {
- BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
- Collection<String> commands;
- commands = textChannel ? protocol.getSupportedTextCommands() : protocol.getSupportedDataCommands();
- for (String commandKey : commands) {
- result.add(new Typed(commandKey));
- }
- } else {
- result.add(new Typed(Command.TYPE_CUSTOM));
- }
- return result;
- }
-
- public Collection<Typed> getAllCommandTypes() {
- List<Typed> result = new ArrayList<>();
- Field[] fields = Command.class.getDeclaredFields();
- for (Field field : fields) {
- if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("TYPE_")) {
- try {
- result.add(new Typed(field.get(null).toString()));
- } catch (IllegalArgumentException | IllegalAccessException error) {
- Log.warning(error);
- }
- }
- }
- return result;
- }
-
- private Queue<Command> getDeviceQueue(long deviceId) {
- if (!deviceQueues.containsKey(deviceId)) {
- deviceQueues.put(deviceId, new ConcurrentLinkedQueue<Command>());
- }
- return deviceQueues.get(deviceId);
- }
-
- public void sendQueuedCommands(ActiveDevice activeDevice) {
- Queue<Command> deviceQueue = deviceQueues.get(activeDevice.getDeviceId());
- if (deviceQueue != null) {
- Command command = deviceQueue.poll();
- while (command != null) {
- activeDevice.sendCommand(command);
- command = deviceQueue.poll();
- }
- }
- }
-
-}
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
deleted file mode 100644
index e5a7a272f..000000000
--- a/src/org/traccar/database/ConnectionManager.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.jboss.netty.channel.Channel;
-import org.jboss.netty.util.Timeout;
-import org.jboss.netty.util.TimerTask;
-import org.traccar.Context;
-import org.traccar.GlobalTimer;
-import org.traccar.Protocol;
-import org.traccar.events.OverspeedEventHandler;
-import org.traccar.helper.Log;
-import org.traccar.model.Device;
-import org.traccar.model.DeviceState;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
-
-public class ConnectionManager {
-
- private static final long DEFAULT_TIMEOUT = 600;
-
- private final long deviceTimeout;
- private final boolean enableStatusEvents;
- private final boolean updateDeviceState;
-
- private final Map<Long, ActiveDevice> activeDevices = new ConcurrentHashMap<>();
- private final Map<Long, Set<UpdateListener>> listeners = new ConcurrentHashMap<>();
- private final Map<Long, Timeout> timeouts = new ConcurrentHashMap<>();
-
- public ConnectionManager() {
- deviceTimeout = Context.getConfig().getLong("status.timeout", DEFAULT_TIMEOUT) * 1000;
- enableStatusEvents = Context.getConfig().getBoolean("event.enable");
- updateDeviceState = Context.getConfig().getBoolean("status.updateDeviceState");
- }
-
- public void addActiveDevice(long deviceId, Protocol protocol, Channel channel, SocketAddress remoteAddress) {
- ActiveDevice activeDevice = new ActiveDevice(deviceId, protocol, channel, remoteAddress);
- activeDevices.put(deviceId, activeDevice);
- Context.getCommandsManager().sendQueuedCommands(activeDevice);
- }
-
- public void removeActiveDevice(Channel channel) {
- for (ActiveDevice activeDevice : activeDevices.values()) {
- if (activeDevice.getChannel() == channel) {
- updateDevice(activeDevice.getDeviceId(), Device.STATUS_OFFLINE, null);
- activeDevices.remove(activeDevice.getDeviceId());
- break;
- }
- }
- }
-
- public ActiveDevice getActiveDevice(long deviceId) {
- return activeDevices.get(deviceId);
- }
-
- public void updateDevice(final long deviceId, String status, Date time) {
- Device device = Context.getIdentityManager().getById(deviceId);
- if (device == null) {
- return;
- }
-
- String oldStatus = device.getStatus();
- device.setStatus(status);
-
- if (enableStatusEvents && !status.equals(oldStatus)) {
- String eventType;
- Map<Event, Position> events = new HashMap<>();
- switch (status) {
- case Device.STATUS_ONLINE:
- eventType = Event.TYPE_DEVICE_ONLINE;
- break;
- case Device.STATUS_UNKNOWN:
- eventType = Event.TYPE_DEVICE_UNKNOWN;
- if (updateDeviceState) {
- events.putAll(updateDeviceState(deviceId));
- }
- break;
- default:
- eventType = Event.TYPE_DEVICE_OFFLINE;
- if (updateDeviceState) {
- events.putAll(updateDeviceState(deviceId));
- }
- break;
- }
- events.put(new Event(eventType, deviceId), null);
- Context.getNotificationManager().updateEvents(events);
- }
-
- Timeout timeout = timeouts.remove(deviceId);
- if (timeout != null) {
- timeout.cancel();
- }
-
- if (time != null) {
- device.setLastUpdate(time);
- }
-
- if (status.equals(Device.STATUS_ONLINE)) {
- timeouts.put(deviceId, GlobalTimer.getTimer().newTimeout(new TimerTask() {
- @Override
- public void run(Timeout timeout) throws Exception {
- if (!timeout.isCancelled()) {
- updateDevice(deviceId, Device.STATUS_UNKNOWN, null);
- activeDevices.remove(deviceId);
- }
- }
- }, deviceTimeout, TimeUnit.MILLISECONDS));
- }
-
- try {
- Context.getDeviceManager().updateDeviceStatus(device);
- } catch (SQLException error) {
- Log.warning(error);
- }
-
- updateDevice(device);
- }
-
- public Map<Event, Position> updateDeviceState(long deviceId) {
- DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
- Map<Event, Position> result = new HashMap<>();
-
- Map<Event, Position> event = Context.getMotionEventHandler().updateMotionState(deviceState);
- if (event != null) {
- result.putAll(event);
- }
-
- event = Context.getOverspeedEventHandler().updateOverspeedState(deviceState, Context.getDeviceManager().
- lookupAttributeDouble(deviceId, OverspeedEventHandler.ATTRIBUTE_SPEED_LIMIT, 0, false));
- if (event != null) {
- result.putAll(event);
- }
-
- return result;
- }
-
- public synchronized void updateDevice(Device device) {
- for (long userId : Context.getPermissionsManager().getDeviceUsers(device.getId())) {
- if (listeners.containsKey(userId)) {
- for (UpdateListener listener : listeners.get(userId)) {
- listener.onUpdateDevice(device);
- }
- }
- }
- }
-
- public synchronized void updatePosition(Position position) {
- long deviceId = position.getDeviceId();
-
- for (long userId : Context.getPermissionsManager().getDeviceUsers(deviceId)) {
- if (listeners.containsKey(userId)) {
- for (UpdateListener listener : listeners.get(userId)) {
- listener.onUpdatePosition(position);
- }
- }
- }
- }
-
- public synchronized void updateEvent(long userId, Event event) {
- if (listeners.containsKey(userId)) {
- for (UpdateListener listener : listeners.get(userId)) {
- listener.onUpdateEvent(event);
- }
- }
- }
-
- public interface UpdateListener {
- void onUpdateDevice(Device device);
- void onUpdatePosition(Position position);
- void onUpdateEvent(Event event);
- }
-
- public synchronized void addListener(long userId, UpdateListener listener) {
- if (!listeners.containsKey(userId)) {
- listeners.put(userId, new HashSet<UpdateListener>());
- }
- listeners.get(userId).add(listener);
- }
-
- public synchronized void removeListener(long userId, UpdateListener listener) {
- if (!listeners.containsKey(userId)) {
- listeners.put(userId, new HashSet<UpdateListener>());
- }
- listeners.get(userId).remove(listener);
- }
-
-}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
deleted file mode 100644
index e88ff7f0d..000000000
--- a/src/org/traccar/database/DataManager.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.beans.Introspector;
-import java.io.File;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
-
-import liquibase.Contexts;
-import liquibase.Liquibase;
-import liquibase.database.Database;
-import liquibase.database.DatabaseFactory;
-import liquibase.exception.LiquibaseException;
-import liquibase.resource.FileSystemResourceAccessor;
-import liquibase.resource.ResourceAccessor;
-
-import org.traccar.Config;
-import org.traccar.helper.Log;
-import org.traccar.model.Attribute;
-import org.traccar.model.Device;
-import org.traccar.model.Driver;
-import org.traccar.model.Event;
-import org.traccar.model.Geofence;
-import org.traccar.model.Group;
-import org.traccar.model.ManagedUser;
-import org.traccar.model.Notification;
-import org.traccar.model.Permission;
-import org.traccar.model.BaseModel;
-import org.traccar.model.Calendar;
-import org.traccar.model.Command;
-import org.traccar.model.Position;
-import org.traccar.model.Server;
-import org.traccar.model.Statistics;
-import org.traccar.model.User;
-
-import com.zaxxer.hikari.HikariConfig;
-import com.zaxxer.hikari.HikariDataSource;
-
-public class DataManager {
-
- public static final String ACTION_SELECT_ALL = "selectAll";
- public static final String ACTION_SELECT = "select";
- public static final String ACTION_INSERT = "insert";
- public static final String ACTION_UPDATE = "update";
- public static final String ACTION_DELETE = "delete";
-
- private final Config config;
-
- private DataSource dataSource;
-
- private boolean generateQueries;
-
- public DataManager(Config config) throws Exception {
- this.config = config;
-
- initDatabase();
- initDatabaseSchema();
- }
-
- public DataSource getDataSource() {
- return dataSource;
- }
-
- private void initDatabase() throws Exception {
-
- String jndiName = config.getString("database.jndi");
-
- if (jndiName != null) {
-
- dataSource = (DataSource) new InitialContext().lookup(jndiName);
-
- } else {
-
- String driverFile = config.getString("database.driverFile");
- if (driverFile != null) {
- URLClassLoader classLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
- Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
- method.setAccessible(true);
- method.invoke(classLoader, new File(driverFile).toURI().toURL());
- }
-
- String driver = config.getString("database.driver");
- if (driver != null) {
- Class.forName(driver);
- }
-
- HikariConfig hikariConfig = new HikariConfig();
- hikariConfig.setDriverClassName(config.getString("database.driver"));
- hikariConfig.setJdbcUrl(config.getString("database.url"));
- hikariConfig.setUsername(config.getString("database.user"));
- hikariConfig.setPassword(config.getString("database.password"));
- hikariConfig.setConnectionInitSql(config.getString("database.checkConnection", "SELECT 1"));
- hikariConfig.setIdleTimeout(600000);
-
- int maxPoolSize = config.getInteger("database.maxPoolSize");
-
- if (maxPoolSize != 0) {
- hikariConfig.setMaximumPoolSize(maxPoolSize);
- }
-
- generateQueries = config.getBoolean("database.generateQueries");
-
- dataSource = new HikariDataSource(hikariConfig);
-
- }
- }
-
- public static String constructObjectQuery(String action, Class<?> clazz, boolean extended) {
- switch (action) {
- case ACTION_INSERT:
- case ACTION_UPDATE:
- StringBuilder result = new StringBuilder();
- StringBuilder fields = new StringBuilder();
- StringBuilder values = new StringBuilder();
-
- Set<Method> methods = new HashSet<>(Arrays.asList(clazz.getMethods()));
- methods.removeAll(Arrays.asList(Object.class.getMethods()));
- methods.removeAll(Arrays.asList(BaseModel.class.getMethods()));
- for (Method method : methods) {
- boolean skip;
- if (extended) {
- skip = !method.isAnnotationPresent(QueryExtended.class);
- } else {
- skip = method.isAnnotationPresent(QueryIgnore.class)
- || method.isAnnotationPresent(QueryExtended.class) && !action.equals(ACTION_INSERT);
- }
- if (!skip && method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
- String name = Introspector.decapitalize(method.getName().substring(3));
- if (action.equals(ACTION_INSERT)) {
- fields.append(name).append(", ");
- values.append(":").append(name).append(", ");
- } else {
- fields.append(name).append(" = :").append(name).append(", ");
- }
- }
- }
- fields.setLength(fields.length() - 2);
- if (action.equals(ACTION_INSERT)) {
- values.setLength(values.length() - 2);
- result.append("INSERT INTO ").append(getObjectsTableName(clazz)).append(" (");
- result.append(fields).append(") ");
- result.append("VALUES (").append(values).append(")");
- } else {
- result.append("UPDATE ").append(getObjectsTableName(clazz)).append(" SET ");
- result.append(fields);
- result.append(" WHERE id = :id");
- }
- return result.toString();
- case ACTION_SELECT_ALL:
- return "SELECT * FROM " + getObjectsTableName(clazz);
- case ACTION_SELECT:
- return "SELECT * FROM " + getObjectsTableName(clazz) + " WHERE id = :id";
- case ACTION_DELETE:
- return "DELETE FROM " + getObjectsTableName(clazz) + " WHERE id = :id";
- default:
- throw new IllegalArgumentException("Unknown action");
- }
- }
-
- public static String constructPermissionQuery(String action, Class<?> owner, Class<?> property) {
- switch (action) {
- case ACTION_SELECT_ALL:
- return "SELECT " + makeNameId(owner) + ", " + makeNameId(property) + " FROM "
- + getPermissionsTableName(owner, property);
- case ACTION_INSERT:
- return "INSERT INTO " + getPermissionsTableName(owner, property)
- + " (" + makeNameId(owner) + ", " + makeNameId(property) + ") VALUES (:"
- + makeNameId(owner) + ", :" + makeNameId(property) + ")";
- case ACTION_DELETE:
- return "DELETE FROM " + getPermissionsTableName(owner, property)
- + " WHERE " + makeNameId(owner) + " = :" + makeNameId(owner)
- + " AND " + makeNameId(property) + " = :" + makeNameId(property);
- default:
- throw new IllegalArgumentException("Unknown action");
- }
- }
-
- private String getQuery(String key) {
- String query = config.getString(key);
- if (query == null) {
- Log.info("Query not provided: " + key);
- }
- return query;
- }
-
- public String getQuery(String action, Class<?> clazz) {
- return getQuery(action, clazz, false);
- }
-
- public String getQuery(String action, Class<?> clazz, boolean extended) {
- String queryName;
- if (action.equals(ACTION_SELECT_ALL)) {
- queryName = "database.select" + clazz.getSimpleName() + "s";
- } else {
- queryName = "database." + action.toLowerCase() + clazz.getSimpleName();
- if (extended) {
- queryName += "Extended";
- }
- }
- String query = config.getString(queryName);
- if (query == null) {
- if (generateQueries) {
- query = constructObjectQuery(action, clazz, extended);
- config.setString(queryName, query);
- } else {
- Log.info("Query not provided: " + queryName);
- }
- }
-
- return query;
- }
-
- public String getQuery(String action, Class<?> owner, Class<?> property) {
- String queryName;
- if (action.equals(ACTION_SELECT_ALL)) {
- queryName = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s";
- } else if (action.equals(ACTION_INSERT)) {
- queryName = "database.link" + owner.getSimpleName() + property.getSimpleName();
- } else {
- queryName = "database.unlink" + owner.getSimpleName() + property.getSimpleName();
- }
- String query = config.getString(queryName);
- if (query == null) {
- if (generateQueries) {
- query = constructPermissionQuery(action, owner,
- property.equals(User.class) ? ManagedUser.class : property);
- config.setString(queryName, query);
- } else {
- Log.info("Query not provided: " + queryName);
- }
- }
-
- return query;
- }
-
- private static String getPermissionsTableName(Class<?> owner, Class<?> property) {
- String propertyName = property.getSimpleName();
- if (propertyName.equals("ManagedUser")) {
- propertyName = "User";
- }
- return Introspector.decapitalize(owner.getSimpleName()) + "_" + Introspector.decapitalize(propertyName);
- }
-
- private static String getObjectsTableName(Class<?> clazz) {
- String result = Introspector.decapitalize(clazz.getSimpleName());
- // Add "s" ending if object name is not plural already
- if (!result.endsWith("s")) {
- result += "s";
- }
- return result;
- }
-
- private void initDatabaseSchema() throws SQLException, LiquibaseException {
-
- if (config.hasKey("database.changelog")) {
-
- ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
-
- Database database = DatabaseFactory.getInstance().openDatabase(
- config.getString("database.url"),
- config.getString("database.user"),
- config.getString("database.password"),
- null, resourceAccessor);
-
- Liquibase liquibase = new Liquibase(
- config.getString("database.changelog"), resourceAccessor, database);
-
- liquibase.clearCheckSums();
-
- liquibase.update(new Contexts());
- }
- }
-
- public User login(String email, String password) throws SQLException {
- User user = QueryBuilder.create(dataSource, getQuery("database.loginUser"))
- .setString("email", email.trim())
- .executeQuerySingle(User.class);
- if (user != null && user.isPasswordValid(password)) {
- return user;
- } else {
- return null;
- }
- }
-
- public void updateDeviceStatus(Device device) throws SQLException {
- QueryBuilder.create(dataSource, getQuery(ACTION_UPDATE, Device.class, true))
- .setObject(device)
- .executeUpdate();
- }
-
- public Collection<Position> getPositions(long deviceId, Date from, Date to) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectPositions"))
- .setLong("deviceId", deviceId)
- .setDate("from", from)
- .setDate("to", to)
- .executeQuery(Position.class);
- }
-
- public void addPosition(Position position) throws SQLException {
- position.setId(QueryBuilder.create(dataSource, getQuery(ACTION_INSERT, Position.class), true)
- .setObject(position)
- .setDate("serverTime", new Date())
- .executeUpdate());
- }
-
- public void updateLatestPosition(Position position) throws SQLException {
- QueryBuilder.create(dataSource, getQuery("database.updateLatestPosition"))
- .setDate("now", new Date())
- .setObject(position)
- .executeUpdate();
- }
-
- public Collection<Position> getLatestPositions() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectLatestPositions"))
- .executeQuery(Position.class);
- }
-
- public void clearHistory() throws SQLException {
- long historyDays = config.getInteger("database.historyDays");
- if (historyDays != 0) {
- Date timeLimit = new Date(System.currentTimeMillis() - historyDays * 24 * 3600 * 1000);
- Log.debug("Clearing history earlier than " + new SimpleDateFormat(Log.DATE_FORMAT).format(timeLimit));
- QueryBuilder.create(dataSource, getQuery("database.deletePositions"))
- .setDate("serverTime", timeLimit)
- .executeUpdate();
- QueryBuilder.create(dataSource, getQuery("database.deleteEvents"))
- .setDate("serverTime", timeLimit)
- .executeUpdate();
- }
- }
-
- public Server getServer() throws SQLException {
- return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, Server.class))
- .executeQuerySingle(Server.class);
- }
-
- public Collection<Event> getEvents(long deviceId, Date from, Date to) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectEvents"))
- .setLong("deviceId", deviceId)
- .setDate("from", from)
- .setDate("to", to)
- .executeQuery(Event.class);
- }
-
- 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 static Class<?> getClassByName(String name) throws ClassNotFoundException {
- switch (name.toLowerCase().replace("id", "")) {
- case "device":
- return Device.class;
- case "group":
- return Group.class;
- case "user":
- return User.class;
- case "manageduser":
- return ManagedUser.class;
- case "geofence":
- return Geofence.class;
- case "driver":
- return Driver.class;
- case "attribute":
- return Attribute.class;
- case "calendar":
- return Calendar.class;
- case "command":
- return Command.class;
- case "notification":
- return Notification.class;
- default:
- throw new ClassNotFoundException();
- }
- }
-
- private static String makeNameId(Class<?> clazz) {
- String name = clazz.getSimpleName();
- return Introspector.decapitalize(name) + (!name.contains("Id") ? "Id" : "");
- }
-
- public Collection<Permission> getPermissions(Class<? extends BaseModel> owner, Class<? extends BaseModel> property)
- throws SQLException, ClassNotFoundException {
- return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, owner, property))
- .executePermissionsQuery();
- }
-
- public void linkObject(Class<?> owner, long ownerId, Class<?> property, long propertyId, boolean link)
- throws SQLException {
- QueryBuilder.create(dataSource, getQuery(link ? ACTION_INSERT : ACTION_DELETE, owner, property))
- .setLong(makeNameId(owner), ownerId)
- .setLong(makeNameId(property), propertyId)
- .executeUpdate();
- }
-
- public <T extends BaseModel> T getObject(Class<T> clazz, long entityId) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT, clazz))
- .setLong("id", entityId)
- .executeQuerySingle(clazz);
- }
-
- public <T extends BaseModel> Collection<T> getObjects(Class<T> clazz) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery(ACTION_SELECT_ALL, clazz))
- .executeQuery(clazz);
- }
-
- public void addObject(BaseModel entity) throws SQLException {
- entity.setId(QueryBuilder.create(dataSource, getQuery(ACTION_INSERT, entity.getClass()), true)
- .setObject(entity)
- .executeUpdate());
- }
-
- public void updateObject(BaseModel entity) throws SQLException {
- QueryBuilder.create(dataSource, getQuery(ACTION_UPDATE, entity.getClass()))
- .setObject(entity)
- .executeUpdate();
- if (entity instanceof User && ((User) entity).getHashedPassword() != null) {
- QueryBuilder.create(dataSource, getQuery(ACTION_UPDATE, User.class, true))
- .setObject(entity)
- .executeUpdate();
- }
- }
-
- public void removeObject(Class<? extends BaseModel> clazz, long entityId) throws SQLException {
- QueryBuilder.create(dataSource, getQuery(ACTION_DELETE, clazz))
- .setLong("id", entityId)
- .executeUpdate();
- }
-
-}
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
deleted file mode 100644
index 1eb90b7eb..000000000
--- a/src/org/traccar/database/DeviceManager.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.traccar.Config;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Device;
-import org.traccar.model.DeviceState;
-import org.traccar.model.DeviceTotalDistance;
-import org.traccar.model.Group;
-import org.traccar.model.Position;
-import org.traccar.model.Server;
-
-public class DeviceManager extends BaseObjectManager<Device> implements IdentityManager, ManagableObjects {
-
- public static final long DEFAULT_REFRESH_DELAY = 300;
-
- private final Config config;
- private final long dataRefreshDelay;
- private boolean lookupGroupsAttribute;
-
- private Map<String, Device> devicesByUniqueId;
- private Map<String, Device> devicesByPhone;
- private AtomicLong devicesLastUpdate = new AtomicLong();
-
- private final Map<Long, Position> positions = new ConcurrentHashMap<>();
-
- private final Map<Long, DeviceState> deviceStates = new ConcurrentHashMap<>();
-
- public DeviceManager(DataManager dataManager) {
- super(dataManager, Device.class);
- this.config = Context.getConfig();
- if (devicesByPhone == null) {
- devicesByPhone = new ConcurrentHashMap<>();
- }
- if (devicesByUniqueId == null) {
- devicesByUniqueId = new ConcurrentHashMap<>();
- }
- dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000;
- lookupGroupsAttribute = config.getBoolean("deviceManager.lookupGroupsAttribute");
- refreshLastPositions();
- }
-
- private void updateDeviceCache(boolean force) throws SQLException {
- long lastUpdate = devicesLastUpdate.get();
- if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
- && devicesLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
- refreshItems();
- }
- }
-
- @Override
- public Device getByUniqueId(String uniqueId) throws SQLException {
- boolean forceUpdate = !devicesByUniqueId.containsKey(uniqueId) && !config.getBoolean("database.ignoreUnknown");
-
- updateDeviceCache(forceUpdate);
-
- return devicesByUniqueId.get(uniqueId);
- }
-
- public Device getDeviceByPhone(String phone) {
- return devicesByPhone.get(phone);
- }
-
- @Override
- public Set<Long> getAllItems() {
- Set<Long> result = super.getAllItems();
- if (result.isEmpty()) {
- try {
- updateDeviceCache(true);
- } catch (SQLException e) {
- Log.warning(e);
- }
- result = super.getAllItems();
- }
- return result;
- }
-
- public Collection<Device> getAllDevices() {
- return getItems(getAllItems());
- }
-
- @Override
- public Set<Long> getUserItems(long userId) {
- if (Context.getPermissionsManager() != null) {
- return Context.getPermissionsManager().getDevicePermissions(userId);
- } else {
- return new HashSet<>();
- }
- }
-
- @Override
- public Set<Long> getManagedItems(long userId) {
- Set<Long> result = new HashSet<>();
- result.addAll(getUserItems(userId));
- for (long managedUserId : Context.getUsersManager().getUserItems(userId)) {
- result.addAll(getUserItems(managedUserId));
- }
- return result;
- }
-
- private void putUniqueDeviceId(Device device) {
- if (devicesByUniqueId == null) {
- devicesByUniqueId = new ConcurrentHashMap<>(getAllItems().size());
- }
- devicesByUniqueId.put(device.getUniqueId(), device);
- }
-
- private void putPhone(Device device) {
- if (devicesByPhone == null) {
- devicesByPhone = new ConcurrentHashMap<>(getAllItems().size());
- }
- devicesByPhone.put(device.getPhone(), device);
- }
-
- @Override
- protected void addNewItem(Device device) {
- super.addNewItem(device);
- putUniqueDeviceId(device);
- if (device.getPhone() != null && !device.getPhone().isEmpty()) {
- putPhone(device);
- }
- if (Context.getGeofenceManager() != null) {
- Position lastPosition = getLastPosition(device.getId());
- if (lastPosition != null) {
- device.setGeofenceIds(Context.getGeofenceManager().getCurrentDeviceGeofences(lastPosition));
- }
- }
- }
-
- @Override
- protected void updateCachedItem(Device device) {
- Device cachedDevice = getById(device.getId());
- cachedDevice.setName(device.getName());
- cachedDevice.setGroupId(device.getGroupId());
- cachedDevice.setCategory(device.getCategory());
- cachedDevice.setContact(device.getContact());
- cachedDevice.setModel(device.getModel());
- cachedDevice.setAttributes(device.getAttributes());
- if (!device.getUniqueId().equals(cachedDevice.getUniqueId())) {
- devicesByUniqueId.remove(cachedDevice.getUniqueId());
- cachedDevice.setUniqueId(device.getUniqueId());
- putUniqueDeviceId(cachedDevice);
- }
- if (device.getPhone() != null && !device.getPhone().isEmpty()
- && !device.getPhone().equals(cachedDevice.getPhone())) {
- devicesByPhone.remove(cachedDevice.getPhone());
- cachedDevice.setPhone(device.getPhone());
- putPhone(cachedDevice);
- }
- }
-
- @Override
- protected void removeCachedItem(long deviceId) {
- Device cachedDevice = getById(deviceId);
- if (cachedDevice != null) {
- String deviceUniqueId = cachedDevice.getUniqueId();
- String phone = cachedDevice.getPhone();
- super.removeCachedItem(deviceId);
- devicesByUniqueId.remove(deviceUniqueId);
- if (phone != null && !phone.isEmpty()) {
- devicesByPhone.remove(phone);
- }
- }
- positions.remove(deviceId);
- }
-
- public void updateDeviceStatus(Device device) throws SQLException {
- getDataManager().updateDeviceStatus(device);
- Device cachedDevice = getById(device.getId());
- if (cachedDevice != null) {
- cachedDevice.setStatus(device.getStatus());
- }
- }
-
- private void refreshLastPositions() {
- if (getDataManager() != null) {
- try {
- for (Position position : getDataManager().getLatestPositions()) {
- positions.put(position.getDeviceId(), position);
- }
- } catch (SQLException error) {
- Log.warning(error);
- }
- }
- }
-
- public boolean isLatestPosition(Position position) {
- Position lastPosition = getLastPosition(position.getDeviceId());
- return lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) >= 0;
- }
-
- public void updateLatestPosition(Position position) throws SQLException {
-
- if (isLatestPosition(position)) {
-
- getDataManager().updateLatestPosition(position);
-
- Device device = getById(position.getDeviceId());
- if (device != null) {
- device.setPositionId(position.getId());
- }
-
- positions.put(position.getDeviceId(), position);
-
- if (Context.getConnectionManager() != null) {
- Context.getConnectionManager().updatePosition(position);
- }
- }
- }
-
- @Override
- public Position getLastPosition(long deviceId) {
- return positions.get(deviceId);
- }
-
- public Collection<Position> getInitialState(long userId) {
-
- List<Position> result = new LinkedList<>();
-
- if (Context.getPermissionsManager() != null) {
- for (long deviceId : getUserItems(userId)) {
- if (positions.containsKey(deviceId)) {
- result.add(positions.get(deviceId));
- }
- }
- }
-
- return result;
- }
-
- public boolean lookupAttributeBoolean(
- long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) {
- Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return result instanceof String ? Boolean.parseBoolean((String) result) : (Boolean) result;
- }
- return defaultValue;
- }
-
- public String lookupAttributeString(
- long deviceId, String attributeName, String defaultValue, boolean lookupConfig) {
- Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- return result != null ? (String) result : defaultValue;
- }
-
- public int lookupAttributeInteger(long deviceId, String attributeName, int defaultValue, boolean lookupConfig) {
- Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return result instanceof String ? Integer.parseInt((String) result) : ((Number) result).intValue();
- }
- return defaultValue;
- }
-
- public long lookupAttributeLong(
- long deviceId, String attributeName, long defaultValue, boolean lookupConfig) {
- Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return result instanceof String ? Long.parseLong((String) result) : ((Number) result).longValue();
- }
- return defaultValue;
- }
-
- public double lookupAttributeDouble(
- long deviceId, String attributeName, double defaultValue, boolean lookupConfig) {
- Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return result instanceof String ? Double.parseDouble((String) result) : ((Number) result).doubleValue();
- }
- return defaultValue;
- }
-
- private Object lookupAttribute(long deviceId, String attributeName, boolean lookupConfig) {
- Object result = null;
- Device device = getById(deviceId);
- if (device != null) {
- result = device.getAttributes().get(attributeName);
- if (result == null && lookupGroupsAttribute) {
- long groupId = device.getGroupId();
- while (groupId != 0) {
- Group group = Context.getGroupsManager().getById(groupId);
- if (group != null) {
- result = group.getAttributes().get(attributeName);
- if (result != null) {
- break;
- }
- groupId = group.getGroupId();
- } else {
- groupId = 0;
- }
- }
- }
- if (result == null) {
- if (lookupConfig) {
- result = Context.getConfig().getString(attributeName);
- } else {
- Server server = Context.getPermissionsManager().getServer();
- result = server.getAttributes().get(attributeName);
- }
- }
- }
- 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());
- getDataManager().addPosition(last);
- updateLatestPosition(last);
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- public DeviceState getDeviceState(long deviceId) {
- DeviceState deviceState = deviceStates.get(deviceId);
- if (deviceState == null) {
- deviceState = new DeviceState();
- deviceStates.put(deviceId, deviceState);
- }
- return deviceState;
- }
-
- public void setDeviceState(long deviceId, DeviceState deviceState) {
- deviceStates.put(deviceId, deviceState);
- }
-
-}
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java
deleted file mode 100644
index 930951460..000000000
--- a/src/org/traccar/database/DriversManager.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.traccar.model.Driver;
-
-public class DriversManager extends ExtendedObjectManager<Driver> {
-
- private Map<String, Driver> driversByUniqueId;
-
- public DriversManager(DataManager dataManager) {
- super(dataManager, Driver.class);
- if (driversByUniqueId == null) {
- driversByUniqueId = new ConcurrentHashMap<>();
- }
- }
-
- private void putUniqueDriverId(Driver driver) {
- if (driversByUniqueId == null) {
- driversByUniqueId = new ConcurrentHashMap<>(getAllItems().size());
- }
- driversByUniqueId.put(driver.getUniqueId(), driver);
- }
-
- @Override
- protected void addNewItem(Driver driver) {
- super.addNewItem(driver);
- putUniqueDriverId(driver);
- }
-
- @Override
- protected void updateCachedItem(Driver driver) {
- Driver cachedDriver = getById(driver.getId());
- cachedDriver.setName(driver.getName());
- if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) {
- driversByUniqueId.remove(cachedDriver.getUniqueId());
- cachedDriver.setUniqueId(driver.getUniqueId());
- putUniqueDriverId(cachedDriver);
- }
- cachedDriver.setAttributes(driver.getAttributes());
- }
-
- @Override
- protected void removeCachedItem(long driverId) {
- Driver cachedDriver = getById(driverId);
- if (cachedDriver != null) {
- String driverUniqueId = cachedDriver.getUniqueId();
- super.removeCachedItem(driverId);
- driversByUniqueId.remove(driverUniqueId);
- }
- }
-
- public Driver getDriverByUniqueId(String uniqueId) {
- return driversByUniqueId.get(uniqueId);
- }
-}
diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java
deleted file mode 100644
index 16785cb37..000000000
--- a/src/org/traccar/database/ExtendedObjectManager.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.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.Device;
-import org.traccar.model.Group;
-import org.traccar.model.Permission;
-import org.traccar.model.BaseModel;
-
-public abstract class ExtendedObjectManager<T extends BaseModel> extends SimpleObjectManager<T> {
-
- private final Map<Long, Set<Long>> deviceItems = new ConcurrentHashMap<>();
- private final Map<Long, Set<Long>> deviceItemsWithGroups = new ConcurrentHashMap<>();
- private final Map<Long, Set<Long>> groupItems = new ConcurrentHashMap<>();
-
- protected ExtendedObjectManager(DataManager dataManager, Class<T> baseClass) {
- super(dataManager, baseClass);
- refreshExtendedPermissions();
- }
-
- public final Set<Long> getGroupItems(long groupId) {
- if (!groupItems.containsKey(groupId)) {
- groupItems.put(groupId, new HashSet<Long>());
- }
- return groupItems.get(groupId);
- }
-
- public final Set<Long> getDeviceItems(long deviceId) {
- if (!deviceItems.containsKey(deviceId)) {
- deviceItems.put(deviceId, new HashSet<Long>());
- }
- return deviceItems.get(deviceId);
- }
-
- public Set<Long> getAllDeviceItems(long deviceId) {
- if (!deviceItemsWithGroups.containsKey(deviceId)) {
- deviceItemsWithGroups.put(deviceId, new HashSet<Long>());
- }
- return deviceItemsWithGroups.get(deviceId);
- }
-
- @Override
- public void removeItem(long itemId) throws SQLException {
- super.removeItem(itemId);
- refreshExtendedPermissions();
- }
-
- public void refreshExtendedPermissions() {
- if (getDataManager() != null) {
- try {
-
- Collection<Permission> databaseGroupPermissions =
- getDataManager().getPermissions(Group.class, getBaseClass());
-
- groupItems.clear();
- for (Permission groupPermission : databaseGroupPermissions) {
- getGroupItems(groupPermission.getOwnerId()).add(groupPermission.getPropertyId());
- }
-
- Collection<Permission> databaseDevicePermissions =
- getDataManager().getPermissions(Device.class, getBaseClass());
-
- deviceItems.clear();
- deviceItemsWithGroups.clear();
-
- for (Permission devicePermission : databaseDevicePermissions) {
- getDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
- getAllDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
- }
-
- for (Device device : Context.getDeviceManager().getAllDevices()) {
- long groupId = device.getGroupId();
- while (groupId != 0) {
- getAllDeviceItems(device.getId()).addAll(getGroupItems(groupId));
- Group group = (Group) Context.getGroupsManager().getById(groupId);
- if (group != null) {
- groupId = group.getGroupId();
- } else {
- groupId = 0;
- }
- }
- }
-
- } catch (SQLException | ClassNotFoundException error) {
- Log.warning(error);
- }
- }
- }
-}
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
deleted file mode 100644
index a32847cf9..000000000
--- a/src/org/traccar/database/GeofenceManager.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.util.ArrayList;
-import java.util.List;
-
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Geofence;
-import org.traccar.model.Position;
-
-public class GeofenceManager extends ExtendedObjectManager<Geofence> {
-
- public GeofenceManager(DataManager dataManager) {
- super(dataManager, Geofence.class);
- }
-
- @Override
- public final void refreshExtendedPermissions() {
- super.refreshExtendedPermissions();
- recalculateDevicesGeofences();
- }
-
- public List<Long> getCurrentDeviceGeofences(Position position) {
- List<Long> result = new ArrayList<>();
- for (long geofenceId : getAllDeviceItems(position.getDeviceId())) {
- Geofence geofence = getById(geofenceId);
- if (geofence != null && geofence.getGeometry()
- .containsPoint(position.getLatitude(), position.getLongitude())) {
- result.add(geofenceId);
- }
- }
- return result;
- }
-
- public void recalculateDevicesGeofences() {
- for (Device device : Context.getDeviceManager().getAllDevices()) {
- List<Long> deviceGeofenceIds = device.getGeofenceIds();
- if (deviceGeofenceIds == null) {
- deviceGeofenceIds = new ArrayList<>();
- } else {
- deviceGeofenceIds.clear();
- }
- Position lastPosition = Context.getIdentityManager().getLastPosition(device.getId());
- if (lastPosition != null && getAllDeviceItems(device.getId()) != null) {
- deviceGeofenceIds.addAll(getCurrentDeviceGeofences(lastPosition));
- }
- device.setGeofenceIds(deviceGeofenceIds);
- }
- }
-
-}
diff --git a/src/org/traccar/database/GroupTree.java b/src/org/traccar/database/GroupTree.java
deleted file mode 100644
index 8798f55bc..000000000
--- a/src/org/traccar/database/GroupTree.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.model.Device;
-import org.traccar.model.Group;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-public class GroupTree {
-
- private static class TreeNode {
-
- private Group group;
- private Device device;
- private Collection<TreeNode> children = new HashSet<>();
-
- TreeNode(Group group) {
- this.group = group;
- }
-
- TreeNode(Device device) {
- this.device = device;
- }
-
- @Override
- public int hashCode() {
- if (group != null) {
- return (int) group.getId();
- } else {
- return (int) device.getId();
- }
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof TreeNode)) {
- return false;
- }
- TreeNode other = (TreeNode) obj;
- if (other == this) {
- return true;
- }
- if (group != null && other.group != null) {
- return group.getId() == other.group.getId();
- } else if (device != null && other.device != null) {
- return device.getId() == other.device.getId();
- }
- return false;
- }
-
- public Group getGroup() {
- return group;
- }
-
- public Device getDevice() {
- return device;
- }
-
- public void setParent(TreeNode parent) {
- if (parent != null) {
- parent.children.add(this);
- }
- }
-
- public Collection<TreeNode> getChildren() {
- return children;
- }
-
- }
-
- private final Map<Long, TreeNode> groupMap = new HashMap<>();
-
- public GroupTree(Collection<Group> groups, Collection<Device> devices) {
-
- for (Group group : groups) {
- groupMap.put(group.getId(), new TreeNode(group));
- }
-
- for (TreeNode node : groupMap.values()) {
- if (node.getGroup().getGroupId() != 0) {
- node.setParent(groupMap.get(node.getGroup().getGroupId()));
- }
- }
-
- Map<Long, TreeNode> deviceMap = new HashMap<>();
-
- for (Device device : devices) {
- deviceMap.put(device.getId(), new TreeNode(device));
- }
-
- for (TreeNode node : deviceMap.values()) {
- if (node.getDevice().getGroupId() != 0) {
- node.setParent(groupMap.get(node.getDevice().getGroupId()));
- }
- }
-
- }
-
- public Collection<Group> getGroups(long groupId) {
- Set<TreeNode> results = new HashSet<>();
- getNodes(results, groupMap.get(groupId));
- Collection<Group> groups = new ArrayList<>();
- for (TreeNode node : results) {
- if (node.getGroup() != null) {
- groups.add(node.getGroup());
- }
- }
- return groups;
- }
-
- public Collection<Device> getDevices(long groupId) {
- Set<TreeNode> results = new HashSet<>();
- getNodes(results, groupMap.get(groupId));
- Collection<Device> devices = new ArrayList<>();
- for (TreeNode node : results) {
- if (node.getDevice() != null) {
- devices.add(node.getDevice());
- }
- }
- return devices;
- }
-
- private void getNodes(Set<TreeNode> results, TreeNode node) {
- if (node != null) {
- for (TreeNode child : node.getChildren()) {
- results.add(child);
- getNodes(results, child);
- }
- }
- }
-
-}
diff --git a/src/org/traccar/database/GroupsManager.java b/src/org/traccar/database/GroupsManager.java
deleted file mode 100644
index c0456085b..000000000
--- a/src/org/traccar/database/GroupsManager.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.HashSet;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Group;
-
-public class GroupsManager extends BaseObjectManager<Group> implements ManagableObjects {
-
- private AtomicLong groupsLastUpdate = new AtomicLong();
- private final long dataRefreshDelay;
-
- public GroupsManager(DataManager dataManager) {
- super(dataManager, Group.class);
- dataRefreshDelay = Context.getConfig().getLong("database.refreshDelay",
- DeviceManager.DEFAULT_REFRESH_DELAY) * 1000;
- }
-
- private void checkGroupCycles(Group group) {
- Set<Long> groups = new HashSet<>();
- while (group != null) {
- if (groups.contains(group.getId())) {
- throw new IllegalArgumentException("Cycle in group hierarchy");
- }
- groups.add(group.getId());
- group = getById(group.getGroupId());
- }
- }
-
- private void updateGroupCache(boolean force) throws SQLException {
- long lastUpdate = groupsLastUpdate.get();
- if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
- && groupsLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
- refreshItems();
- }
- }
-
- @Override
- public Set<Long> getAllItems() {
- Set<Long> result = super.getAllItems();
- if (result.isEmpty()) {
- try {
- updateGroupCache(true);
- } catch (SQLException e) {
- Log.warning(e);
- }
- result = super.getAllItems();
- }
- return result;
- }
-
- @Override
- protected void addNewItem(Group group) {
- checkGroupCycles(group);
- super.addNewItem(group);
- }
-
- @Override
- protected void updateCachedItem(Group group) {
- checkGroupCycles(group);
- super.updateCachedItem(group);
- }
-
- @Override
- public Set<Long> getUserItems(long userId) {
- if (Context.getPermissionsManager() != null) {
- return Context.getPermissionsManager().getGroupPermissions(userId);
- } else {
- return new HashSet<>();
- }
- }
-
- @Override
- public Set<Long> getManagedItems(long userId) {
- Set<Long> result = new HashSet<>();
- result.addAll(getUserItems(userId));
- for (long managedUserId : Context.getUsersManager().getUserItems(userId)) {
- result.addAll(getUserItems(managedUserId));
- }
- return result;
- }
-
-}
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
deleted file mode 100644
index 82d905963..000000000
--- a/src/org/traccar/database/IdentityManager.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.
- * 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.model.Device;
-import org.traccar.model.Position;
-
-public interface IdentityManager {
-
- Device getById(long id);
-
- Device getByUniqueId(String uniqueId) throws Exception;
-
- Position getLastPosition(long deviceId);
-
- boolean isLatestPosition(Position position);
-
- boolean lookupAttributeBoolean(long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig);
-
- String lookupAttributeString(long deviceId, String attributeName, String defaultValue, boolean lookupConfig);
-
- int lookupAttributeInteger(long deviceId, String attributeName, int defaultValue, boolean lookupConfig);
-
- long lookupAttributeLong(long deviceId, String attributeName, long defaultValue, boolean lookupConfig);
-
-}
diff --git a/src/org/traccar/database/ManagableObjects.java b/src/org/traccar/database/ManagableObjects.java
deleted file mode 100644
index ec9549493..000000000
--- a/src/org/traccar/database/ManagableObjects.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.util.Set;
-
-public interface ManagableObjects {
-
- Set<Long> getUserItems(long userId);
-
- Set<Long> getManagedItems(long userId);
-
-}
diff --git a/src/org/traccar/database/MediaManager.java b/src/org/traccar/database/MediaManager.java
deleted file mode 100644
index 2c448a20c..000000000
--- a/src/org/traccar/database/MediaManager.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.jboss.netty.buffer.ChannelBuffer;
-import org.traccar.Config;
-import org.traccar.helper.Log;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class MediaManager {
-
- private String path;
-
- public MediaManager(Config config) {
- path = config.getString("media.path");
- }
-
- private File createFile(String uniqueId, String name) throws IOException {
- Path filePath = Paths.get(path, uniqueId, name);
- Path directoryPath = filePath.getParent();
- if (directoryPath != null) {
- Files.createDirectories(directoryPath);
- }
- return filePath.toFile();
- }
-
- public String writeFile(String uniqueId, ChannelBuffer buf, String extension) {
- int size = buf.readableBytes();
- String name = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()) + "." + extension;
- try (FileOutputStream output = new FileOutputStream(createFile(uniqueId, name));
- FileChannel fileChannel = output.getChannel()) {
- ByteBuffer byteBuffer = buf.toByteBuffer();
- int written = 0;
- while (written < size) {
- written += fileChannel.write(byteBuffer);
- }
- fileChannel.force(false);
- return name;
- } catch (IOException e) {
- Log.warning(e);
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
deleted file mode 100644
index 73041a23f..000000000
--- a/src/org/traccar/database/NotificationManager.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 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.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Event;
-import org.traccar.model.Notification;
-import org.traccar.model.Position;
-import org.traccar.model.Typed;
-import org.traccar.notification.NotificationMail;
-import org.traccar.notification.NotificationSms;
-
-public class NotificationManager extends ExtendedObjectManager<Notification> {
-
- public NotificationManager(DataManager dataManager) {
- super(dataManager, Notification.class);
- }
-
- private Set<Long> getEffectiveNotifications(long userId, long deviceId) {
- Set<Long> result = new HashSet<>();
- Set<Long> deviceNotifications = getAllDeviceItems(deviceId);
- for (long itemId : getUserItems(userId)) {
- if (getById(itemId).getAlways() || deviceNotifications.contains(itemId)) {
- result.add(itemId);
- }
- }
- return result;
- }
-
- public void updateEvent(Event event, Position position) {
- try {
- getDataManager().addObject(event);
- } catch (SQLException error) {
- Log.warning(error);
- }
-
- long deviceId = event.getDeviceId();
- Set<Long> users = Context.getPermissionsManager().getDeviceUsers(deviceId);
- for (long userId : users) {
- if (event.getGeofenceId() == 0 || Context.getGeofenceManager() != null
- && Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId())) {
- boolean sentWeb = false;
- boolean sentMail = false;
- boolean sentSms = Context.getSmppManager() == null;
- for (long notificationId : getEffectiveNotifications(userId, deviceId)) {
- Notification notification = getById(notificationId);
- if (getById(notificationId).getType().equals(event.getType())) {
- if (!sentWeb && notification.getWeb()) {
- Context.getConnectionManager().updateEvent(userId, event);
- sentWeb = true;
- }
- if (!sentMail && notification.getMail()) {
- NotificationMail.sendMailAsync(userId, event, position);
- sentMail = true;
- }
- if (!sentSms && notification.getSms()) {
- NotificationSms.sendSmsAsync(userId, event, position);
- sentSms = true;
- }
- }
- if (sentWeb && sentMail && sentSms) {
- break;
- }
- }
- }
- }
- if (Context.getEventForwarder() != null) {
- Context.getEventForwarder().forwardEvent(event, position);
- }
- }
-
- public void updateEvents(Map<Event, Position> events) {
- for (Entry<Event, Position> event : events.entrySet()) {
- updateEvent(event.getKey(), event.getValue());
- }
- }
-
- public Set<Typed> getAllNotificationTypes() {
- Set<Typed> types = new HashSet<>();
- Field[] fields = Event.class.getDeclaredFields();
- for (Field field : fields) {
- if (Modifier.isStatic(field.getModifiers()) && field.getName().startsWith("TYPE_")) {
- try {
- types.add(new Typed(field.get(null).toString()));
- } catch (IllegalArgumentException | IllegalAccessException error) {
- Log.warning(error);
- }
- }
- }
- return types;
- }
-}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
deleted file mode 100644
index 07b60ba58..000000000
--- a/src/org/traccar/database/PermissionsManager.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.Attribute;
-import org.traccar.model.BaseModel;
-import org.traccar.model.Calendar;
-import org.traccar.model.Command;
-import org.traccar.model.Device;
-import org.traccar.model.Driver;
-import org.traccar.model.Geofence;
-import org.traccar.model.Group;
-import org.traccar.model.ManagedUser;
-import org.traccar.model.Notification;
-import org.traccar.model.Permission;
-import org.traccar.model.Server;
-import org.traccar.model.User;
-
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-public class PermissionsManager {
-
- private final DataManager dataManager;
- private final UsersManager usersManager;
-
- private volatile Server server;
-
- private final Map<Long, Set<Long>> groupPermissions = new HashMap<>();
- private final Map<Long, Set<Long>> devicePermissions = new HashMap<>();
- private final Map<Long, Set<Long>> deviceUsers = new HashMap<>();
- private final Map<Long, Set<Long>> groupDevices = new HashMap<>();
-
- public PermissionsManager(DataManager dataManager, UsersManager usersManager) {
- this.dataManager = dataManager;
- this.usersManager = usersManager;
- refreshServer();
- refreshDeviceAndGroupPermissions();
- }
-
- public User getUser(long userId) {
- return (User) usersManager.getById(userId);
- }
-
- public Set<Long> getGroupPermissions(long userId) {
- if (!groupPermissions.containsKey(userId)) {
- groupPermissions.put(userId, new HashSet<Long>());
- }
- return groupPermissions.get(userId);
- }
-
- public Set<Long> getDevicePermissions(long userId) {
- if (!devicePermissions.containsKey(userId)) {
- devicePermissions.put(userId, new HashSet<Long>());
- }
- return devicePermissions.get(userId);
- }
-
- public Set<Long> getDeviceUsers(long deviceId) {
- if (!deviceUsers.containsKey(deviceId)) {
- deviceUsers.put(deviceId, new HashSet<Long>());
- }
- return deviceUsers.get(deviceId);
- }
-
- public Set<Long> getGroupDevices(long groupId) {
- if (!groupDevices.containsKey(groupId)) {
- groupDevices.put(groupId, new HashSet<Long>());
- }
- return groupDevices.get(groupId);
- }
-
- public void refreshServer() {
- try {
- server = dataManager.getServer();
- } catch (SQLException error) {
- Log.warning(error);
- }
- }
-
- public final void refreshDeviceAndGroupPermissions() {
- groupPermissions.clear();
- devicePermissions.clear();
- try {
- GroupTree groupTree = new GroupTree(Context.getGroupsManager().getItems(
- Context.getGroupsManager().getAllItems()),
- Context.getDeviceManager().getAllDevices());
- for (Permission groupPermission : dataManager.getPermissions(User.class, Group.class)) {
- Set<Long> userGroupPermissions = getGroupPermissions(groupPermission.getOwnerId());
- Set<Long> userDevicePermissions = getDevicePermissions(groupPermission.getOwnerId());
- userGroupPermissions.add(groupPermission.getPropertyId());
- for (Group group : groupTree.getGroups(groupPermission.getPropertyId())) {
- userGroupPermissions.add(group.getId());
- }
- for (Device device : groupTree.getDevices(groupPermission.getPropertyId())) {
- userDevicePermissions.add(device.getId());
- }
- }
-
- for (Permission devicePermission : dataManager.getPermissions(User.class, Device.class)) {
- getDevicePermissions(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
- }
-
- groupDevices.clear();
- for (long groupId : Context.getGroupsManager().getAllItems()) {
- for (Device device : groupTree.getDevices(groupId)) {
- getGroupDevices(groupId).add(device.getId());
- }
- }
-
- } catch (SQLException | ClassNotFoundException error) {
- Log.warning(error);
- }
-
- deviceUsers.clear();
- for (Map.Entry<Long, Set<Long>> entry : devicePermissions.entrySet()) {
- for (long deviceId : entry.getValue()) {
- getDeviceUsers(deviceId).add(entry.getKey());
- }
- }
- }
-
- public boolean getUserAdmin(long userId) {
- User user = getUser(userId);
- return user != null && user.getAdmin();
- }
-
- public void checkAdmin(long userId) throws SecurityException {
- if (!getUserAdmin(userId)) {
- throw new SecurityException("Admin access required");
- }
- }
-
- public boolean getUserManager(long userId) {
- User user = getUser(userId);
- return user != null && user.getUserLimit() != 0;
- }
-
- public void checkManager(long userId) throws SecurityException {
- if (!getUserManager(userId)) {
- throw new SecurityException("Manager access required");
- }
- }
-
- public void checkManager(long userId, long managedUserId) throws SecurityException {
- checkManager(userId);
- if (!usersManager.getUserItems(userId).contains(managedUserId)) {
- throw new SecurityException("User access denied");
- }
- }
-
- public void checkUserLimit(long userId) throws SecurityException {
- int userLimit = getUser(userId).getUserLimit();
- if (userLimit != -1 && usersManager.getUserItems(userId).size() >= userLimit) {
- throw new SecurityException("Manager user limit reached");
- }
- }
-
- public void checkDeviceLimit(long userId) throws SecurityException, SQLException {
- int deviceLimit = getUser(userId).getDeviceLimit();
- if (deviceLimit != -1) {
- int deviceCount = 0;
- if (getUserManager(userId)) {
- deviceCount = Context.getDeviceManager().getManagedItems(userId).size();
- } else {
- deviceCount = Context.getDeviceManager().getUserItems(userId).size();
- }
- if (deviceCount >= deviceLimit) {
- throw new SecurityException("User device limit reached");
- }
- }
- }
-
- public boolean getUserReadonly(long userId) {
- User user = getUser(userId);
- return user != null && user.getReadonly();
- }
-
- public boolean getUserDeviceReadonly(long userId) {
- User user = getUser(userId);
- return user != null && user.getDeviceReadonly();
- }
-
- public boolean getUserLimitCommands(long userId) {
- User user = getUser(userId);
- return user != null && user.getLimitCommands();
- }
-
- public void checkReadonly(long userId) throws SecurityException {
- if (!getUserAdmin(userId) && (server.getReadonly() || getUserReadonly(userId))) {
- throw new SecurityException("Account is readonly");
- }
- }
-
- public void checkDeviceReadonly(long userId) throws SecurityException {
- if (!getUserAdmin(userId) && (server.getDeviceReadonly() || getUserDeviceReadonly(userId))) {
- throw new SecurityException("Account is device readonly");
- }
- }
-
- public void checkLimitCommands(long userId) throws SecurityException {
- if (!getUserAdmin(userId) && (server.getLimitCommands() || getUserLimitCommands(userId))) {
- throw new SecurityException("Account has limit sending commands");
- }
- }
-
- public void checkUserDeviceCommand(long userId, long deviceId, long commandId) throws SecurityException {
- if (!getUserAdmin(userId) && Context.getCommandsManager().checkDeviceCommand(deviceId, commandId)) {
- throw new SecurityException("Command can not be sent to this device");
- }
- }
-
- public void checkUserEnabled(long userId) throws SecurityException {
- User user = getUser(userId);
- if (user == null) {
- throw new SecurityException("Unknown account");
- }
- 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.getDeviceLimit() != after.getDeviceLimit()
- || before.getUserLimit() != after.getUserLimit()) {
- checkAdmin(userId);
- }
- User user = getUser(userId);
- if (user != null && user.getExpirationTime() != null
- && (after.getExpirationTime() == null
- || user.getExpirationTime().compareTo(after.getExpirationTime()) < 0)) {
- checkAdmin(userId);
- }
- if (before.getReadonly() != after.getReadonly()
- || before.getDeviceReadonly() != after.getDeviceReadonly()
- || before.getDisabled() != after.getDisabled()) {
- if (userId == after.getId()) {
- checkAdmin(userId);
- }
- if (!getUserAdmin(userId)) {
- checkManager(userId);
- }
- }
- }
-
- public void checkUser(long userId, long managedUserId) throws SecurityException {
- if (userId != managedUserId && !getUserAdmin(userId)) {
- checkManager(userId, managedUserId);
- }
- }
-
- public void checkGroup(long userId, long groupId) throws SecurityException {
- if (!getGroupPermissions(userId).contains(groupId) && !getUserAdmin(userId)) {
- checkManager(userId);
- for (long managedUserId : usersManager.getUserItems(userId)) {
- if (getGroupPermissions(managedUserId).contains(groupId)) {
- return;
- }
- }
- throw new SecurityException("Group access denied");
- }
- }
-
- public void checkDevice(long userId, long deviceId) throws SecurityException {
- if (!Context.getDeviceManager().getUserItems(userId).contains(deviceId) && !getUserAdmin(userId)) {
- checkManager(userId);
- for (long managedUserId : usersManager.getUserItems(userId)) {
- if (Context.getDeviceManager().getUserItems(managedUserId).contains(deviceId)) {
- return;
- }
- }
- throw new SecurityException("Device access denied");
- }
- }
-
- public void checkRegistration(long userId) {
- if (!server.getRegistration() && !getUserAdmin(userId)) {
- throw new SecurityException("Registration disabled");
- }
- }
-
- public void checkPermission(Class<?> object, long userId, long objectId)
- throws SecurityException {
- SimpleObjectManager<? extends BaseModel> manager = null;
-
- if (object.equals(Device.class)) {
- checkDevice(userId, objectId);
- } else if (object.equals(Group.class)) {
- checkGroup(userId, objectId);
- } else if (object.equals(User.class) || object.equals(ManagedUser.class)) {
- checkUser(userId, objectId);
- } else if (object.equals(Geofence.class)) {
- manager = Context.getGeofenceManager();
- } else if (object.equals(Attribute.class)) {
- manager = Context.getAttributesManager();
- } else if (object.equals(Driver.class)) {
- manager = Context.getDriversManager();
- } else if (object.equals(Calendar.class)) {
- manager = Context.getCalendarManager();
- } else if (object.equals(Command.class)) {
- manager = Context.getCommandsManager();
- } else if (object.equals(Notification.class)) {
- manager = Context.getNotificationManager();
- } else {
- throw new IllegalArgumentException("Unknown object type");
- }
-
- if (manager != null && !manager.checkItemPermission(userId, objectId) && !getUserAdmin(userId)) {
- checkManager(userId);
- for (long managedUserId : usersManager.getManagedItems(userId)) {
- if (manager.checkItemPermission(managedUserId, objectId)) {
- return;
- }
- }
- throw new SecurityException("Type " + object + " access denied");
- }
- }
-
- public void refreshAllUsersPermissions() {
- if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refreshUserItems();
- }
- Context.getCalendarManager().refreshUserItems();
- Context.getDriversManager().refreshUserItems();
- Context.getAttributesManager().refreshUserItems();
- Context.getCommandsManager().refreshUserItems();
- if (Context.getNotificationManager() != null) {
- Context.getNotificationManager().refreshUserItems();
- }
- }
-
- public void refreshAllExtendedPermissions() {
- if (Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refreshExtendedPermissions();
- }
- Context.getDriversManager().refreshExtendedPermissions();
- Context.getAttributesManager().refreshExtendedPermissions();
- Context.getCommandsManager().refreshExtendedPermissions();
- }
-
- public void refreshPermissions(Permission permission) {
- if (permission.getOwnerClass().equals(User.class)) {
- if (permission.getPropertyClass().equals(Device.class)
- || permission.getPropertyClass().equals(Group.class)) {
- refreshDeviceAndGroupPermissions();
- refreshAllExtendedPermissions();
- } else if (permission.getPropertyClass().equals(ManagedUser.class)) {
- usersManager.refreshUserItems();
- } else if (permission.getPropertyClass().equals(Geofence.class) && Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Driver.class)) {
- Context.getDriversManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Attribute.class)) {
- Context.getAttributesManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Calendar.class)) {
- Context.getCalendarManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Command.class)) {
- Context.getCommandsManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Notification.class)
- && Context.getNotificationManager() != null) {
- Context.getNotificationManager().refreshUserItems();
- }
- } else if (permission.getOwnerClass().equals(Device.class) || permission.getOwnerClass().equals(Group.class)) {
- if (permission.getPropertyClass().equals(Geofence.class) && Context.getGeofenceManager() != null) {
- Context.getGeofenceManager().refreshExtendedPermissions();
- } else if (permission.getPropertyClass().equals(Driver.class)) {
- Context.getDriversManager().refreshExtendedPermissions();
- } else if (permission.getPropertyClass().equals(Attribute.class)) {
- Context.getAttributesManager().refreshExtendedPermissions();
- } else if (permission.getPropertyClass().equals(Command.class)) {
- Context.getCommandsManager().refreshExtendedPermissions();
- } else if (permission.getPropertyClass().equals(Notification.class)
- && Context.getNotificationManager() != null) {
- Context.getNotificationManager().refreshExtendedPermissions();
- }
- }
- }
-
- public Server getServer() {
- return server;
- }
-
- public void updateServer(Server server) throws SQLException {
- dataManager.updateObject(server);
- this.server = server;
- }
-
- public User login(String email, String password) throws SQLException {
- User user = dataManager.login(email, password);
- if (user != null) {
- checkUserEnabled(user.getId());
- return getUser(user.getId());
- }
- return null;
- }
-
- public Object lookupAttribute(long userId, String key, Object defaultValue) {
- Object preference;
- Object serverPreference = server.getAttributes().get(key);
- Object userPreference = getUser(userId).getAttributes().get(key);
- if (server.getForceSettings()) {
- preference = serverPreference != null ? serverPreference : userPreference;
- } else {
- preference = userPreference != null ? userPreference : serverPreference;
- }
- return preference != null ? preference : defaultValue;
- }
-
-}
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
deleted file mode 100644
index af33458a8..000000000
--- a/src/org/traccar/database/QueryBuilder.java
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- * 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.
- * 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 com.fasterxml.jackson.core.JsonProcessingException;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.MiscFormatter;
-import org.traccar.model.Permission;
-
-import javax.sql.DataSource;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Timestamp;
-import java.sql.Types;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public final class QueryBuilder {
-
- private final Map<String, List<Integer>> indexMap = new HashMap<>();
- private Connection connection;
- private PreparedStatement statement;
- private final String query;
- private final boolean returnGeneratedKeys;
-
- private QueryBuilder(DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException {
- this.query = query;
- this.returnGeneratedKeys = returnGeneratedKeys;
- if (query != null) {
- connection = dataSource.getConnection();
- String parsedQuery = parse(query.trim(), indexMap);
- try {
- if (returnGeneratedKeys) {
- statement = connection.prepareStatement(parsedQuery, Statement.RETURN_GENERATED_KEYS);
- } else {
- statement = connection.prepareStatement(parsedQuery);
- }
- } catch (SQLException error) {
- connection.close();
- throw error;
- }
- }
- }
-
- private static String parse(String query, Map<String, List<Integer>> paramMap) {
-
- int length = query.length();
- StringBuilder parsedQuery = new StringBuilder(length);
- boolean inSingleQuote = false;
- boolean inDoubleQuote = false;
- int index = 1;
-
- for (int i = 0; i < length; i++) {
-
- char c = query.charAt(i);
-
- // String end
- if (inSingleQuote) {
- if (c == '\'') {
- inSingleQuote = false;
- }
- } else if (inDoubleQuote) {
- if (c == '"') {
- inDoubleQuote = false;
- }
- } else {
-
- // String begin
- if (c == '\'') {
- inSingleQuote = true;
- } else if (c == '"') {
- inDoubleQuote = true;
- } else if (c == ':' && i + 1 < length
- && Character.isJavaIdentifierStart(query.charAt(i + 1))) {
-
- // Identifier name
- int j = i + 2;
- while (j < length && Character.isJavaIdentifierPart(query.charAt(j))) {
- j++;
- }
-
- String name = query.substring(i + 1, j);
- c = '?';
- i += name.length();
- name = name.toLowerCase();
-
- // Add to list
- List<Integer> indexList = paramMap.get(name);
- if (indexList == null) {
- indexList = new LinkedList<>();
- paramMap.put(name, indexList);
- }
- indexList.add(index);
-
- index++;
- }
- }
-
- parsedQuery.append(c);
- }
-
- return parsedQuery.toString();
- }
-
- public static QueryBuilder create(DataSource dataSource, String query) throws SQLException {
- return new QueryBuilder(dataSource, query, false);
- }
-
- public static QueryBuilder create(
- DataSource dataSource, String query, boolean returnGeneratedKeys) throws SQLException {
- return new QueryBuilder(dataSource, query, returnGeneratedKeys);
- }
-
- private List<Integer> indexes(String name) {
- name = name.toLowerCase();
- List<Integer> result = indexMap.get(name);
- if (result == null) {
- result = new LinkedList<>();
- }
- return result;
- }
-
- public QueryBuilder setBoolean(String name, boolean value) throws SQLException {
- for (int i : indexes(name)) {
- try {
- statement.setBoolean(i, value);
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setInteger(String name, int value) throws SQLException {
- for (int i : indexes(name)) {
- try {
- statement.setInt(i, value);
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setLong(String name, long value) throws SQLException {
- return setLong(name, value, false);
- }
-
- public QueryBuilder setLong(String name, long value, boolean nullIfZero) throws SQLException {
- for (int i : indexes(name)) {
- try {
- if (value == 0 && nullIfZero) {
- statement.setNull(i, Types.INTEGER);
- } else {
- statement.setLong(i, value);
- }
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setDouble(String name, double value) throws SQLException {
- for (int i : indexes(name)) {
- try {
- statement.setDouble(i, value);
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setString(String name, String value) throws SQLException {
- for (int i : indexes(name)) {
- try {
- if (value == null) {
- statement.setNull(i, Types.VARCHAR);
- } else {
- statement.setString(i, value);
- }
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setDate(String name, Date value) throws SQLException {
- for (int i : indexes(name)) {
- try {
- if (value == null) {
- statement.setNull(i, Types.TIMESTAMP);
- } else {
- statement.setTimestamp(i, new Timestamp(value.getTime()));
- }
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setBlob(String name, byte[] value) throws SQLException {
- for (int i : indexes(name)) {
- try {
- if (value == null) {
- statement.setNull(i, Types.BLOB);
- } else {
- statement.setBytes(i, value);
- }
- } catch (SQLException error) {
- statement.close();
- connection.close();
- throw error;
- }
- }
- return this;
- }
-
- public QueryBuilder setObject(Object object) throws SQLException {
-
- Method[] methods = object.getClass().getMethods();
-
- for (Method method : methods) {
- if (method.getName().startsWith("get") && method.getParameterTypes().length == 0
- && !method.isAnnotationPresent(QueryIgnore.class)) {
- String name = method.getName().substring(3);
- try {
- if (method.getReturnType().equals(boolean.class)) {
- setBoolean(name, (Boolean) method.invoke(object));
- } else if (method.getReturnType().equals(int.class)) {
- setInteger(name, (Integer) method.invoke(object));
- } else if (method.getReturnType().equals(long.class)) {
- setLong(name, (Long) method.invoke(object), name.endsWith("Id"));
- } else if (method.getReturnType().equals(double.class)) {
- setDouble(name, (Double) method.invoke(object));
- } else if (method.getReturnType().equals(String.class)) {
- setString(name, (String) method.invoke(object));
- } else if (method.getReturnType().equals(Date.class)) {
- setDate(name, (Date) method.invoke(object));
- } else if (method.getReturnType().equals(byte[].class)) {
- setBlob(name, (byte[]) method.invoke(object));
- } else {
- if (method.getReturnType().equals(Map.class)
- && Context.getConfig().getBoolean("database.xml")) {
- setString(name, MiscFormatter.toXmlString((Map) method.invoke(object)));
- } else {
- setString(name, Context.getObjectMapper().writeValueAsString(method.invoke(object)));
- }
- }
- } catch (IllegalAccessException | InvocationTargetException | JsonProcessingException error) {
- Log.warning(error);
- }
- }
- }
-
- return this;
- }
-
- private interface ResultSetProcessor<T> {
- void process(T object, ResultSet resultSet) throws SQLException;
- }
-
- public <T> T executeQuerySingle(Class<T> clazz) throws SQLException {
- Collection<T> result = executeQuery(clazz);
- if (!result.isEmpty()) {
- return result.iterator().next();
- } else {
- return null;
- }
- }
-
- private <T> void addProcessors(
- List<ResultSetProcessor<T>> processors,
- final Class<?> parameterType, final Method method, final String name) {
-
- if (parameterType.equals(boolean.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getBoolean(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else if (parameterType.equals(int.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getInt(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else if (parameterType.equals(long.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getLong(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else if (parameterType.equals(double.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getDouble(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else if (parameterType.equals(String.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getString(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else if (parameterType.equals(Date.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- Timestamp timestamp = resultSet.getTimestamp(name);
- if (timestamp != null) {
- method.invoke(object, new Date(timestamp.getTime()));
- }
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else if (parameterType.equals(byte[].class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getBytes(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- });
- } else {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- String value = resultSet.getString(name);
- if (value != null && !value.isEmpty()) {
- try {
- method.invoke(object, Context.getObjectMapper().readValue(value, parameterType));
- } catch (InvocationTargetException | IllegalAccessException | IOException error) {
- Log.warning(error);
- }
- }
- }
- });
- }
- }
-
- public <T> Collection<T> executeQuery(Class<T> clazz) throws SQLException {
- List<T> result = new LinkedList<>();
-
- if (query != null) {
-
- try {
-
- try (ResultSet resultSet = statement.executeQuery()) {
-
- ResultSetMetaData resultMetaData = resultSet.getMetaData();
-
- List<ResultSetProcessor<T>> processors = new LinkedList<>();
-
- Method[] methods = clazz.getMethods();
-
- for (final Method method : methods) {
- if (method.getName().startsWith("set") && method.getParameterTypes().length == 1
- && !method.isAnnotationPresent(QueryIgnore.class)) {
-
- final String name = method.getName().substring(3);
-
- // Check if column exists
- boolean column = false;
- for (int i = 1; i <= resultMetaData.getColumnCount(); i++) {
- if (name.equalsIgnoreCase(resultMetaData.getColumnLabel(i))) {
- column = true;
- break;
- }
- }
- if (!column) {
- continue;
- }
-
- addProcessors(processors, method.getParameterTypes()[0], method, name);
- }
- }
-
- while (resultSet.next()) {
- try {
- T object = clazz.newInstance();
- for (ResultSetProcessor<T> processor : processors) {
- processor.process(object, resultSet);
- }
- result.add(object);
- } catch (InstantiationException | IllegalAccessException e) {
- throw new IllegalArgumentException();
- }
- }
- }
-
- } finally {
- statement.close();
- connection.close();
- }
- }
-
- return result;
- }
-
- public long executeUpdate() throws SQLException {
-
- if (query != null) {
- try {
- statement.execute();
- if (returnGeneratedKeys) {
- ResultSet resultSet = statement.getGeneratedKeys();
- if (resultSet.next()) {
- return resultSet.getLong(1);
- }
- }
- } finally {
- statement.close();
- connection.close();
- }
- }
- return 0;
- }
-
- public Collection<Permission> executePermissionsQuery() throws SQLException, ClassNotFoundException {
- List<Permission> result = new LinkedList<>();
- if (query != null) {
- try {
- try (ResultSet resultSet = statement.executeQuery()) {
- ResultSetMetaData resultMetaData = resultSet.getMetaData();
- while (resultSet.next()) {
- LinkedHashMap<String, Long> map = new LinkedHashMap<>();
- for (int i = 1; i <= resultMetaData.getColumnCount(); i++) {
- String label = resultMetaData.getColumnLabel(i);
- map.put(label, resultSet.getLong(label));
- }
- result.add(new Permission(map));
- }
- }
- } finally {
- statement.close();
- connection.close();
- }
- }
-
- return result;
- }
-
-}
diff --git a/src/org/traccar/database/QueryExtended.java b/src/org/traccar/database/QueryExtended.java
deleted file mode 100644
index 07bc2c211..000000000
--- a/src/org/traccar/database/QueryExtended.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface QueryExtended {
-}
diff --git a/src/org/traccar/database/QueryIgnore.java b/src/org/traccar/database/QueryIgnore.java
deleted file mode 100644
index ac835cf2f..000000000
--- a/src/org/traccar/database/QueryIgnore.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface QueryIgnore {
-}
diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java
deleted file mode 100644
index 0b4d11378..000000000
--- a/src/org/traccar/database/SimpleObjectManager.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.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.BaseModel;
-import org.traccar.model.Permission;
-import org.traccar.model.User;
-
-public abstract class SimpleObjectManager<T extends BaseModel> extends BaseObjectManager<T>
- implements ManagableObjects {
-
- private Map<Long, Set<Long>> userItems;
-
- protected SimpleObjectManager(DataManager dataManager, Class<T> baseClass) {
- super(dataManager, baseClass);
- }
-
- @Override
- public final Set<Long> getUserItems(long userId) {
- if (!userItems.containsKey(userId)) {
- userItems.put(userId, new HashSet<Long>());
- }
- return userItems.get(userId);
- }
-
- @Override
- public Set<Long> getManagedItems(long userId) {
- Set<Long> result = new HashSet<>();
- result.addAll(getUserItems(userId));
- for (long managedUserId : Context.getUsersManager().getUserItems(userId)) {
- result.addAll(getUserItems(managedUserId));
- }
- return result;
- }
-
- public final boolean checkItemPermission(long userId, long itemId) {
- return getUserItems(userId).contains(itemId);
- }
-
- @Override
- public void refreshItems() {
- super.refreshItems();
- refreshUserItems();
- }
-
- public final void refreshUserItems() {
- if (getDataManager() != null) {
- try {
- if (userItems != null) {
- userItems.clear();
- } else {
- userItems = new ConcurrentHashMap<>();
- }
- for (Permission permission : getDataManager().getPermissions(User.class, getBaseClass())) {
- getUserItems(permission.getOwnerId()).add(permission.getPropertyId());
- }
- } catch (SQLException | ClassNotFoundException error) {
- Log.warning(error);
- }
- }
- }
-
- @Override
- public void removeItem(long itemId) throws SQLException {
- super.removeItem(itemId);
- refreshUserItems();
- }
-
-}
diff --git a/src/org/traccar/database/StatisticsManager.java b/src/org/traccar/database/StatisticsManager.java
deleted file mode 100644
index 9a3ff06bd..000000000
--- a/src/org/traccar/database/StatisticsManager.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 com.ning.http.client.Request;
-import com.ning.http.client.RequestBuilder;
-import org.joda.time.format.ISODateTimeFormat;
-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;
-import java.util.concurrent.atomic.AtomicInteger;
-
-public class StatisticsManager {
-
- private static final int SPLIT_MODE = Calendar.DAY_OF_MONTH;
-
- private AtomicInteger lastUpdate = new AtomicInteger(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 int mailSent;
- private int smsSent;
- private int geocoderRequests;
- private int geolocationRequests;
-
- private void checkSplit() {
- int currentUpdate = Calendar.getInstance().get(SPLIT_MODE);
- if (lastUpdate.getAndSet(currentUpdate) != 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);
- statistics.setMailSent(mailSent);
- statistics.setSmsSent(smsSent);
- statistics.setGeocoderRequests(geocoderRequests);
- statistics.setGeolocationRequests(geolocationRequests);
-
- try {
- Context.getDataManager().addObject(statistics);
- } catch (SQLException e) {
- Log.warning(e);
- }
-
- String url = Context.getConfig().getString("server.statistics");
- if (url != null) {
- String time = ISODateTimeFormat.dateTime().print(statistics.getCaptureTime().getTime());
- Request request = new RequestBuilder("POST")
- .setUrl(url)
- .addHeader("Content-Type", "application/x-www-form-urlencoded")
- .addFormParam("version", Log.getAppVersion())
- .addFormParam("captureTime", time)
- .addFormParam("activeUsers", String.valueOf(statistics.getActiveUsers()))
- .addFormParam("activeDevices", String.valueOf(statistics.getActiveDevices()))
- .addFormParam("requests", String.valueOf(statistics.getRequests()))
- .addFormParam("messagesReceived", String.valueOf(statistics.getMessagesReceived()))
- .addFormParam("messagesStored", String.valueOf(statistics.getMessagesStored()))
- .addFormParam("mailSent", String.valueOf(statistics.getMailSent()))
- .addFormParam("smsSent", String.valueOf(statistics.getSmsSent()))
- .addFormParam("geocoderRequests", String.valueOf(statistics.getGeocoderRequests()))
- .addFormParam("geolocationRequests", String.valueOf(statistics.getGeolocationRequests()))
- .build();
- Context.getAsyncHttpClient().prepareRequest(request).execute();
- }
-
- users.clear();
- devices.clear();
- requests = 0;
- messagesReceived = 0;
- messagesStored = 0;
- mailSent = 0;
- smsSent = 0;
- geocoderRequests = 0;
- geolocationRequests = 0;
- }
- }
-
- 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);
- }
- }
-
- public synchronized void registerMail() {
- checkSplit();
- mailSent += 1;
- }
-
- public synchronized void registerSms() {
- checkSplit();
- smsSent += 1;
- }
-
- public synchronized void registerGeocoderRequest() {
- checkSplit();
- geocoderRequests += 1;
- }
-
- public synchronized void registerGeolocationRequest() {
- checkSplit();
- geolocationRequests += 1;
- }
-
-}
diff --git a/src/org/traccar/database/UsersManager.java b/src/org/traccar/database/UsersManager.java
deleted file mode 100644
index 576a9e6c7..000000000
--- a/src/org/traccar/database/UsersManager.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.traccar.model.User;
-
-public class UsersManager extends SimpleObjectManager<User> {
-
- private Map<String, User> usersTokens;
-
- public UsersManager(DataManager dataManager) {
- super(dataManager, User.class);
- if (usersTokens == null) {
- usersTokens = new ConcurrentHashMap<>();
- }
- }
-
- private void putToken(User user) {
- if (usersTokens == null) {
- usersTokens = new ConcurrentHashMap<>();
- }
- if (user.getToken() != null) {
- usersTokens.put(user.getToken(), user);
- }
- }
-
- @Override
- protected void addNewItem(User user) {
- super.addNewItem(user);
- putToken(user);
- }
-
- @Override
- protected void updateCachedItem(User user) {
- User cachedUser = getById(user.getId());
- super.updateCachedItem(user);
- putToken(user);
- if (cachedUser.getToken() != null && !cachedUser.getToken().equals(user.getToken())) {
- usersTokens.remove(cachedUser.getToken());
- }
- }
-
- @Override
- protected void removeCachedItem(long userId) {
- User cachedUser = getById(userId);
- if (cachedUser != null) {
- String userToken = cachedUser.getToken();
- super.removeCachedItem(userId);
- if (userToken != null) {
- usersTokens.remove(userToken);
- }
- }
- }
-
- @Override
- public Set<Long> getManagedItems(long userId) {
- Set<Long> result = new HashSet<>();
- result.addAll(getUserItems(userId));
- result.add(userId);
- return result;
- }
-
- public User getUserByToken(String token) {
- return usersTokens.get(token);
- }
-
-}
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
deleted file mode 100644
index 003ccb662..000000000
--- a/src/org/traccar/events/AlertEventHandler.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class AlertEventHandler extends BaseEventHandler {
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
- Object alarm = position.getAttributes().get(Position.KEY_ALARM);
- if (alarm != null) {
- Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId());
- event.set(Position.KEY_ALARM, (String) alarm);
- return Collections.singletonMap(event, position);
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java
deleted file mode 100644
index 775aa903f..000000000
--- a/src/org/traccar/events/CommandResultEventHandler.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class CommandResultEventHandler extends BaseEventHandler {
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
- Object commandResult = position.getAttributes().get(Position.KEY_RESULT);
- if (commandResult != null) {
- Event event = new Event(Event.TYPE_COMMAND_RESULT, position.getDeviceId(), position.getId());
- event.set(Position.KEY_RESULT, (String) commandResult);
- return Collections.singletonMap(event, position);
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/events/DriverEventHandler.java b/src/org/traccar/events/DriverEventHandler.java
deleted file mode 100644
index 39b8eb9c0..000000000
--- a/src/org/traccar/events/DriverEventHandler.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class DriverEventHandler extends BaseEventHandler {
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
- if (!Context.getIdentityManager().isLatestPosition(position)) {
- return null;
- }
- String driverUniqueId = position.getString(Position.KEY_DRIVER_UNIQUE_ID);
- if (driverUniqueId != null) {
- String oldDriverUniqueId = null;
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (lastPosition != null) {
- oldDriverUniqueId = lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
- }
- if (!driverUniqueId.equals(oldDriverUniqueId)) {
- Event event = new Event(Event.TYPE_DRIVER_CHANGED, position.getDeviceId(), position.getId());
- event.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId);
- return Collections.singletonMap(event, position);
- }
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/events/FuelDropEventHandler.java b/src/org/traccar/events/FuelDropEventHandler.java
deleted file mode 100644
index 2ee3e1a58..000000000
--- a/src/org/traccar/events/FuelDropEventHandler.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.events;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-import java.util.Collections;
-import java.util.Map;
-
-public class FuelDropEventHandler extends BaseEventHandler {
-
- public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold";
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
-
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
- if (device == null) {
- return null;
- }
- if (!Context.getIdentityManager().isLatestPosition(position)) {
- return null;
- }
-
- double fuelDropThreshold = Context.getDeviceManager()
- .lookupAttributeDouble(device.getId(), ATTRIBUTE_FUEL_DROP_THRESHOLD, 0, false);
-
- if (fuelDropThreshold > 0) {
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)
- && lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {
-
- double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL)
- - position.getDouble(Position.KEY_FUEL_LEVEL);
- if (drop >= fuelDropThreshold) {
- Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position.getDeviceId(), position.getId());
- event.set(ATTRIBUTE_FUEL_DROP_THRESHOLD, fuelDropThreshold);
- return Collections.singletonMap(event, position);
- }
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
deleted file mode 100644
index 31d82a81e..000000000
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.events;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.database.GeofenceManager;
-import org.traccar.model.Calendar;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class GeofenceEventHandler extends BaseEventHandler {
-
- private GeofenceManager geofenceManager;
-
- public GeofenceEventHandler() {
- geofenceManager = Context.getGeofenceManager();
- }
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
- if (device == null) {
- return null;
- }
- if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
- return null;
- }
-
- List<Long> currentGeofences = geofenceManager.getCurrentDeviceGeofences(position);
- List<Long> oldGeofences = new ArrayList<>();
- if (device.getGeofenceIds() != null) {
- oldGeofences.addAll(device.getGeofenceIds());
- }
- List<Long> newGeofences = new ArrayList<>(currentGeofences);
- newGeofences.removeAll(oldGeofences);
- oldGeofences.removeAll(currentGeofences);
-
- device.setGeofenceIds(currentGeofences);
-
- Map<Event, Position> events = new HashMap<>();
- for (long geofenceId : newGeofences) {
- long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
- if (calendar == null || calendar.checkMoment(position.getFixTime())) {
- Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
- event.setGeofenceId(geofenceId);
- events.put(event, position);
- }
- }
- for (long geofenceId : oldGeofences) {
- long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
- if (calendar == null || calendar.checkMoment(position.getFixTime())) {
- Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
- event.setGeofenceId(geofenceId);
- events.put(event, position);
- }
- }
- return events;
- }
-}
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java
deleted file mode 100644
index cc53b216c..000000000
--- a/src/org/traccar/events/IgnitionEventHandler.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class IgnitionEventHandler extends BaseEventHandler {
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
- if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
- return null;
- }
-
- Map<Event, Position> result = null;
-
- if (position.getAttributes().containsKey(Position.KEY_IGNITION)) {
- boolean ignition = position.getBoolean(Position.KEY_IGNITION);
-
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_IGNITION)) {
- boolean oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION);
-
- if (ignition && !oldIgnition) {
- result = Collections.singletonMap(
- new Event(Event.TYPE_IGNITION_ON, position.getDeviceId(), position.getId()), position);
- } else if (!ignition && oldIgnition) {
- result = Collections.singletonMap(
- new Event(Event.TYPE_IGNITION_OFF, position.getDeviceId(), position.getId()), position);
- }
- }
- }
- return result;
- }
-
-}
diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
deleted file mode 100644
index 86abf7c17..000000000
--- a/src/org/traccar/events/MaintenanceEventHandler.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class MaintenanceEventHandler extends BaseEventHandler {
-
- public static final String ATTRIBUTE_MAINTENANCE_START = "maintenance.start";
- public static final String ATTRIBUTE_MAINTENANCE_INTERVAL = "maintenance.interval";
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
- if (device == null || !Context.getIdentityManager().isLatestPosition(position)) {
- return null;
- }
-
- double maintenanceInterval = Context.getDeviceManager()
- .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0, false);
- if (maintenanceInterval == 0) {
- return null;
- }
- double maintenanceStart = Context.getDeviceManager()
- .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false);
-
- double oldTotalDistance = 0.0;
- double newTotalDistance = 0.0;
-
- Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
- if (lastPosition != null) {
- oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
- }
- newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE);
-
- oldTotalDistance -= maintenanceStart;
- newTotalDistance -= maintenanceStart;
-
- if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) {
- Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
- event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance);
- return Collections.singletonMap(event, position);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
deleted file mode 100644
index 0c1c4848f..000000000
--- a/src/org/traccar/events/MotionEventHandler.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.DeviceState;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-import org.traccar.reports.ReportUtils;
-import org.traccar.reports.model.TripsConfig;
-
-public class MotionEventHandler extends BaseEventHandler {
-
- private TripsConfig tripsConfig;
-
- public MotionEventHandler(TripsConfig tripsConfig) {
- this.tripsConfig = tripsConfig;
- }
-
- private Map<Event, Position> newEvent(DeviceState deviceState, boolean newMotion) {
- String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
- Position position = deviceState.getMotionPosition();
- Event event = new Event(eventType, position.getDeviceId(), position.getId());
- deviceState.setMotionState(newMotion);
- deviceState.setMotionPosition(null);
- return Collections.singletonMap(event, position);
- }
-
- public Map<Event, Position> updateMotionState(DeviceState deviceState) {
- Map<Event, Position> result = null;
- if (deviceState.getMotionState() != null && deviceState.getMotionPosition() != null) {
- boolean newMotion = !deviceState.getMotionState();
- Position motionPosition = deviceState.getMotionPosition();
- long currentTime = System.currentTimeMillis();
- long motionTime = motionPosition.getFixTime().getTime()
- + (newMotion ? tripsConfig.getMinimalTripDuration() : tripsConfig.getMinimalParkingDuration());
- if (motionTime <= currentTime) {
- result = newEvent(deviceState, newMotion);
- }
- }
- return result;
- }
-
- public Map<Event, Position> updateMotionState(DeviceState deviceState, Position position) {
- return updateMotionState(deviceState, position, position.getBoolean(Position.KEY_MOTION));
- }
-
- public Map<Event, Position> updateMotionState(DeviceState deviceState, Position position, boolean newMotion) {
- Map<Event, Position> result = null;
- Boolean oldMotion = deviceState.getMotionState();
-
- long currentTime = position.getFixTime().getTime();
- if (newMotion != oldMotion) {
- if (deviceState.getMotionPosition() == null) {
- deviceState.setMotionPosition(position);
- }
- } else {
- deviceState.setMotionPosition(null);
- }
-
- Position motionPosition = deviceState.getMotionPosition();
- if (motionPosition != null) {
- long motionTime = motionPosition.getFixTime().getTime();
- double distance = ReportUtils.calculateDistance(motionPosition, position, false);
- Boolean ignition = null;
- if (tripsConfig.getUseIgnition()
- && position.getAttributes().containsKey(Position.KEY_IGNITION)) {
- ignition = position.getBoolean(Position.KEY_IGNITION);
- }
- if (newMotion) {
- if (motionTime + tripsConfig.getMinimalTripDuration() <= currentTime
- || distance >= tripsConfig.getMinimalTripDistance()) {
- result = newEvent(deviceState, newMotion);
- }
- } else {
- if (motionTime + tripsConfig.getMinimalParkingDuration() <= currentTime
- || ignition != null && !ignition) {
- result = newEvent(deviceState, newMotion);
- }
- }
- }
- return result;
- }
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
-
- long deviceId = position.getDeviceId();
- Device device = Context.getIdentityManager().getById(deviceId);
- if (device == null) {
- return null;
- }
- if (!Context.getIdentityManager().isLatestPosition(position)
- || !tripsConfig.getProcessInvalidPositions() && !position.getValid()) {
- return null;
- }
-
- Map<Event, Position> result = null;
- DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
-
- if (deviceState.getMotionState() == null) {
- deviceState.setMotionState(position.getBoolean(Position.KEY_MOTION));
- } else {
- result = updateMotionState(deviceState, position);
- }
- Context.getDeviceManager().setDeviceState(deviceId, deviceState);
- return result;
- }
-
-}
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
deleted file mode 100644
index cb658415c..000000000
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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.events;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.traccar.BaseEventHandler;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.DeviceState;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-public class OverspeedEventHandler extends BaseEventHandler {
-
- public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit";
-
- private boolean notRepeat;
- private long minimalDuration;
-
- public OverspeedEventHandler(long minimalDuration, boolean notRepeat) {
- this.notRepeat = notRepeat;
- this.minimalDuration = minimalDuration;
- }
-
- private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) {
- Position position = deviceState.getOverspeedPosition();
- Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
- event.set("speed", deviceState.getOverspeedPosition().getSpeed());
- event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit);
- deviceState.setOverspeedState(notRepeat);
- deviceState.setOverspeedPosition(null);
- return Collections.singletonMap(event, position);
- }
-
- public Map<Event, Position> updateOverspeedState(DeviceState deviceState, double speedLimit) {
- Map<Event, Position> result = null;
- if (deviceState.getOverspeedState() != null && !deviceState.getOverspeedState()
- && deviceState.getOverspeedPosition() != null && speedLimit != 0) {
- long currentTime = System.currentTimeMillis();
- Position overspeedPosition = deviceState.getOverspeedPosition();
- long overspeedTime = overspeedPosition.getFixTime().getTime();
- if (overspeedTime + minimalDuration <= currentTime) {
- result = newEvent(deviceState, speedLimit);
- }
- }
- return result;
- }
-
- public Map<Event, Position> updateOverspeedState(DeviceState deviceState, Position position, double speedLimit) {
- Map<Event, Position> result = null;
-
- Boolean oldOverspeed = deviceState.getOverspeedState();
-
- long currentTime = position.getFixTime().getTime();
- boolean newOverspeed = position.getSpeed() > speedLimit;
- if (newOverspeed && !oldOverspeed) {
- if (deviceState.getOverspeedPosition() == null) {
- deviceState.setOverspeedPosition(position);
- }
- } else if (oldOverspeed && !newOverspeed) {
- deviceState.setOverspeedState(false);
- deviceState.setOverspeedPosition(null);
- } else {
- deviceState.setOverspeedPosition(null);
- }
- Position overspeedPosition = deviceState.getOverspeedPosition();
- if (overspeedPosition != null) {
- long overspeedTime = overspeedPosition.getFixTime().getTime();
- if (newOverspeed && overspeedTime + minimalDuration <= currentTime) {
- result = newEvent(deviceState, speedLimit);
- }
- }
- return result;
- }
-
- @Override
- protected Map<Event, Position> analyzePosition(Position position) {
-
- long deviceId = position.getDeviceId();
- Device device = Context.getIdentityManager().getById(deviceId);
- if (device == null) {
- return null;
- }
- if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
- return null;
- }
-
- double speedLimit = Context.getDeviceManager().lookupAttributeDouble(deviceId, ATTRIBUTE_SPEED_LIMIT, 0, false);
- if (speedLimit == 0) {
- return null;
- }
-
- Map<Event, Position> result = null;
- DeviceState deviceState = Context.getDeviceManager().getDeviceState(deviceId);
-
- if (deviceState.getOverspeedState() == null) {
- deviceState.setOverspeedState(position.getSpeed() > speedLimit);
- } else {
- result = updateOverspeedState(deviceState, position, speedLimit);
- }
-
- Context.getDeviceManager().setDeviceState(deviceId, deviceState);
- return result;
- }
-
-}
diff --git a/src/org/traccar/events/TextMessageEventHandler.java b/src/org/traccar/events/TextMessageEventHandler.java
deleted file mode 100644
index be4a193a7..000000000
--- a/src/org/traccar/events/TextMessageEventHandler.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.events;
-
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-
-public final class TextMessageEventHandler {
-
- private TextMessageEventHandler() {
- }
-
- public static void handleTextMessage(String phone, String message) {
- Device device = Context.getDeviceManager().getDeviceByPhone(phone);
- if (device != null && Context.getNotificationManager() != null) {
- Event event = new Event(Event.TYPE_TEXT_MESSAGE, device.getId());
- event.set("message", message);
- Context.getNotificationManager().updateEvent(event, null);
- }
- }
-
-}
diff --git a/src/org/traccar/geocoder/Address.java b/src/org/traccar/geocoder/Address.java
deleted file mode 100644
index d542d1b19..000000000
--- a/src/org/traccar/geocoder/Address.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-public class Address {
-
- private String postcode;
-
- public String getPostcode() {
- return postcode;
- }
-
- public void setPostcode(String postcode) {
- this.postcode = postcode;
- }
-
- private String country;
-
- public String getCountry() {
- return country;
- }
-
- public void setCountry(String country) {
- this.country = country;
- }
-
- private String state;
-
- public String getState() {
- return state;
- }
-
- public void setState(String state) {
- this.state = state;
- }
-
- private String district;
-
- public String getDistrict() {
- return district;
- }
-
- public void setDistrict(String district) {
- this.district = district;
- }
-
- private String settlement;
-
- public String getSettlement() {
- return settlement;
- }
-
- public void setSettlement(String settlement) {
- this.settlement = settlement;
- }
-
- private String suburb;
-
- public String getSuburb() {
- return suburb;
- }
-
- public void setSuburb(String suburb) {
- this.suburb = suburb;
- }
-
- private String street;
-
- public String getStreet() {
- return street;
- }
-
- public void setStreet(String street) {
- this.street = street;
- }
-
- private String house;
-
- public String getHouse() {
- return house;
- }
-
- public void setHouse(String house) {
- this.house = house;
- }
-
-}
diff --git a/src/org/traccar/geocoder/AddressFormat.java b/src/org/traccar/geocoder/AddressFormat.java
deleted file mode 100644
index 0800d6dcc..000000000
--- a/src/org/traccar/geocoder/AddressFormat.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-import java.text.FieldPosition;
-import java.text.Format;
-import java.text.ParsePosition;
-
-/**
- * Available parameters:
- *
- * %p - postcode
- * %c - country
- * %s - state
- * %d - district
- * %t - settlement (town)
- * %u - suburb
- * %r - street (road)
- * %h - house
- *
- */
-public class AddressFormat extends Format {
-
- private final String format;
-
- public AddressFormat() {
- this("%h %r, %t, %s, %c");
- }
-
- public AddressFormat(String format) {
- this.format = format;
- }
-
- private static String replace(String s, String key, String value) {
- if (value != null) {
- s = s.replace(key, value);
- } else {
- s = s.replaceAll("[, ]*" + key, "");
- }
- return s;
- }
-
- @Override
- public StringBuffer format(Object o, StringBuffer stringBuffer, FieldPosition fieldPosition) {
- Address address = (Address) o;
- String result = format;
-
- result = replace(result, "%p", address.getPostcode());
- result = replace(result, "%c", address.getCountry());
- result = replace(result, "%s", address.getState());
- result = replace(result, "%d", address.getDistrict());
- result = replace(result, "%t", address.getSettlement());
- result = replace(result, "%u", address.getSuburb());
- result = replace(result, "%r", address.getStreet());
- result = replace(result, "%h", address.getHouse());
-
- result = result.replaceAll("^[, ]*", "");
-
- return stringBuffer.append(result);
- }
-
- @Override
- public Address parseObject(String s, ParsePosition parsePosition) {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/src/org/traccar/geocoder/BingMapsGeocoder.java b/src/org/traccar/geocoder/BingMapsGeocoder.java
deleted file mode 100644
index a9b36219a..000000000
--- a/src/org/traccar/geocoder/BingMapsGeocoder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com)
- *
- * 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.geocoder;
-
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-
-public class BingMapsGeocoder extends JsonGeocoder {
-
- public BingMapsGeocoder(String url, String key, int cacheSize) {
- super(url + "/Locations/%f,%f?key=" + key + "&include=ciso2", cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- JsonArray result = json.getJsonArray("resourceSets");
- if (result != null) {
- JsonObject location =
- result.getJsonObject(0).getJsonArray("resources").getJsonObject(0).getJsonObject("address");
- if (location != null) {
- Address address = new Address();
- if (location.containsKey("addressLine")) {
- address.setStreet(location.getString("addressLine"));
- }
- if (location.containsKey("locality")) {
- address.setSettlement(location.getString("locality"));
- }
- if (location.containsKey("adminDistrict2")) {
- address.setDistrict(location.getString("adminDistrict2"));
- }
- if (location.containsKey("adminDistrict")) {
- address.setState(location.getString("adminDistrict"));
- }
- if (location.containsKey("countryRegionIso2")) {
- address.setCountry(location.getString("countryRegionIso2").toUpperCase());
- }
- if (location.containsKey("postalCode")) {
- address.setPostcode(location.getString("postalCode"));
- }
- return address;
- }
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/geocoder/FactualGeocoder.java b/src/org/traccar/geocoder/FactualGeocoder.java
deleted file mode 100644
index 0c76e4625..000000000
--- a/src/org/traccar/geocoder/FactualGeocoder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com)
- *
- * 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.geocoder;
-
-import javax.json.JsonObject;
-
-public class FactualGeocoder extends JsonGeocoder {
-
- public FactualGeocoder(String url, String key, int cacheSize) {
- super(url + "?latitude=%f&longitude=%f&KEY=" + key, cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- JsonObject result = json.getJsonObject("response").getJsonObject("data");
- if (result != null) {
- Address address = new Address();
- if (result.getJsonObject("street_number") != null) {
- address.setHouse(result.getJsonObject("street_number").getString("name"));
- }
- if (result.getJsonObject("street_name") != null) {
- address.setStreet(result.getJsonObject("street_name").getString("name"));
- }
- if (result.getJsonObject("locality") != null) {
- address.setSettlement(result.getJsonObject("locality").getString("name"));
- }
- if (result.getJsonObject("county") != null) {
- address.setDistrict(result.getJsonObject("county").getString("name"));
- }
- if (result.getJsonObject("region") != null) {
- address.setState(result.getJsonObject("region").getString("name"));
- }
- if (result.getJsonObject("country") != null) {
- address.setCountry(result.getJsonObject("country").getString("name"));
- }
- if (result.getJsonObject("postcode") != null) {
- address.setPostcode(result.getJsonObject("postcode").getString("name"));
- }
- return address;
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
deleted file mode 100644
index 73ff85aa4..000000000
--- a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.geocoder;
-
-import javax.json.JsonObject;
-
-public class GeocodeFarmGeocoder extends JsonGeocoder {
-
- private static String formatUrl(String key, String language) {
- String url = "https://www.geocode.farm/v3/json/reverse/";
- url += "?lat=%f&lon=%f&country=us&count=1";
- if (key != null) {
- url += "&key=" + key;
- }
- if (language != null) {
- url += "&lang=" + language;
- }
- return url;
- }
- public GeocodeFarmGeocoder(String key, String language, int cacheSize) {
- super(formatUrl(key, language), cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- Address address = new Address();
-
- JsonObject result = json
- .getJsonObject("geocoding_results")
- .getJsonArray("RESULTS")
- .getJsonObject(0)
- .getJsonObject("ADDRESS");
-
- if (result.containsKey("street_number")) {
- address.setStreet(result.getString("street_number"));
- }
- if (result.containsKey("street_name")) {
- address.setStreet(result.getString("street_name"));
- }
- if (result.containsKey("locality")) {
- address.setSettlement(result.getString("locality"));
- }
- if (result.containsKey("admin_1")) {
- address.setState(result.getString("admin_1"));
- }
- if (result.containsKey("country")) {
- address.setCountry(result.getString("country"));
- }
-
- return address;
- }
-
-}
diff --git a/src/org/traccar/geocoder/Geocoder.java b/src/org/traccar/geocoder/Geocoder.java
deleted file mode 100644
index 3ce3fb67f..000000000
--- a/src/org/traccar/geocoder/Geocoder.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-public interface Geocoder {
-
- interface ReverseGeocoderCallback {
-
- void onSuccess(String address);
-
- void onFailure(Throwable e);
-
- }
-
- void getAddress(AddressFormat format, double latitude, double longitude, ReverseGeocoderCallback callback);
-
-}
diff --git a/src/org/traccar/geocoder/GeocoderException.java b/src/org/traccar/geocoder/GeocoderException.java
deleted file mode 100644
index 608916641..000000000
--- a/src/org/traccar/geocoder/GeocoderException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.geocoder;
-
-public class GeocoderException extends RuntimeException {
-
- public GeocoderException(String message) {
- super(message);
- }
-
-}
diff --git a/src/org/traccar/geocoder/GisgraphyGeocoder.java b/src/org/traccar/geocoder/GisgraphyGeocoder.java
deleted file mode 100644
index 1432166e9..000000000
--- a/src/org/traccar/geocoder/GisgraphyGeocoder.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-import javax.json.JsonObject;
-
-public class GisgraphyGeocoder extends JsonGeocoder {
-
- public GisgraphyGeocoder() {
- this("http://services.gisgraphy.com/reversegeocoding/search", 0);
- }
-
- public GisgraphyGeocoder(String url, int cacheSize) {
- super(url + "?format=json&lat=%f&lng=%f&from=1&to=1", cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- Address address = new Address();
-
- JsonObject result = json.getJsonArray("result").getJsonObject(0);
-
- if (result.containsKey("streetName")) {
- address.setStreet(result.getString("streetName"));
- }
- if (result.containsKey("city")) {
- address.setSettlement(result.getString("city"));
- }
- if (result.containsKey("state")) {
- address.setState(result.getString("state"));
- }
- if (result.containsKey("countryCode")) {
- address.setCountry(result.getString("countryCode"));
- }
-
- return address;
- }
-
-}
diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java
deleted file mode 100644
index b38870c8f..000000000
--- a/src/org/traccar/geocoder/GoogleGeocoder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import javax.json.JsonString;
-
-public class GoogleGeocoder extends JsonGeocoder {
-
- private static String formatUrl(String key, String language) {
- String url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f";
- if (key != null) {
- url += "&key=" + key;
- }
- if (language != null) {
- url += "&language=" + language;
- }
- return url;
- }
-
- public GoogleGeocoder(String key, String language, int cacheSize) {
- super(formatUrl(key, language), cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- JsonArray results = json.getJsonArray("results");
-
- if (!results.isEmpty()) {
- Address address = new Address();
-
- JsonObject result = (JsonObject) results.get(0);
- JsonArray components = result.getJsonArray("address_components");
-
- for (JsonObject component : components.getValuesAs(JsonObject.class)) {
-
- String value = component.getString("short_name");
-
- typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) {
-
- switch (type.getString()) {
- case "street_number":
- address.setHouse(value);
- break typesLoop;
- case "route":
- address.setStreet(value);
- break typesLoop;
- case "locality":
- address.setSettlement(value);
- break typesLoop;
- case "administrative_area_level_2":
- address.setDistrict(value);
- break typesLoop;
- case "administrative_area_level_1":
- address.setState(value);
- break typesLoop;
- case "country":
- address.setCountry(value);
- break typesLoop;
- case "postal_code":
- address.setPostcode(value);
- break typesLoop;
- default:
- break;
- }
- }
- }
-
- return address;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/geocoder/JsonGeocoder.java b/src/org/traccar/geocoder/JsonGeocoder.java
deleted file mode 100644
index 6d1380729..000000000
--- a/src/org/traccar/geocoder/JsonGeocoder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-import com.ning.http.client.AsyncCompletionHandler;
-import com.ning.http.client.Response;
-import org.traccar.Context;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import java.util.AbstractMap;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public abstract class JsonGeocoder implements Geocoder {
-
- private final String url;
-
- private Map<Map.Entry<Double, Double>, String> cache;
-
- public JsonGeocoder(String url, final int cacheSize) {
- this.url = url;
- if (cacheSize > 0) {
- this.cache = Collections.synchronizedMap(new LinkedHashMap<Map.Entry<Double, Double>, String>() {
- @Override
- protected boolean removeEldestEntry(Map.Entry eldest) {
- return size() > cacheSize;
- }
- });
- }
- }
-
- @Override
- public void getAddress(
- final AddressFormat format, final double latitude,
- final double longitude, final ReverseGeocoderCallback callback) {
-
- if (cache != null) {
- String cachedAddress = cache.get(new AbstractMap.SimpleImmutableEntry<>(latitude, longitude));
- if (cachedAddress != null) {
- callback.onSuccess(cachedAddress);
- return;
- }
- }
-
- Context.getAsyncHttpClient().prepareGet(String.format(url, latitude, longitude))
- .execute(new AsyncCompletionHandler() {
- @Override
- public Object onCompleted(Response response) throws Exception {
- try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
- Address address = parseAddress(reader.readObject());
- if (address != null) {
- String formattedAddress = format.format(address);
- if (cache != null) {
- cache.put(new AbstractMap.SimpleImmutableEntry<>(latitude, longitude), formattedAddress);
- }
- callback.onSuccess(formattedAddress);
- } else {
- callback.onFailure(new GeocoderException("Empty address"));
- }
- }
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- callback.onFailure(t);
- }
- });
- }
-
- public abstract Address parseAddress(JsonObject json);
-
-}
diff --git a/src/org/traccar/geocoder/MapQuestGeocoder.java b/src/org/traccar/geocoder/MapQuestGeocoder.java
deleted file mode 100644
index 7d7217e91..000000000
--- a/src/org/traccar/geocoder/MapQuestGeocoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@gmail.com)
- *
- * 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.geocoder;
-
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-
-public class MapQuestGeocoder extends JsonGeocoder {
-
- public MapQuestGeocoder(String url, String key, int cacheSize) {
- super(url + "?key=" + key + "&location=%f,%f", cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- JsonArray result = json.getJsonArray("results");
- if (result != null) {
- JsonArray locations = result.getJsonObject(0).getJsonArray("locations");
- if (locations != null) {
- JsonObject location = locations.getJsonObject(0);
-
- Address address = new Address();
-
- if (location.containsKey("street")) {
- address.setStreet(location.getString("street"));
- }
- if (location.containsKey("adminArea5")) {
- address.setSettlement(location.getString("adminArea5"));
- }
- if (location.containsKey("adminArea4")) {
- address.setDistrict(location.getString("adminArea4"));
- }
- if (location.containsKey("adminArea3")) {
- address.setState(location.getString("adminArea3"));
- }
- if (location.containsKey("adminArea1")) {
- address.setCountry(location.getString("adminArea1").toUpperCase());
- }
- if (location.containsKey("postalCode")) {
- address.setPostcode(location.getString("postalCode"));
- }
-
- return address;
- }
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/geocoder/NominatimGeocoder.java b/src/org/traccar/geocoder/NominatimGeocoder.java
deleted file mode 100644
index 051727e93..000000000
--- a/src/org/traccar/geocoder/NominatimGeocoder.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.
- * 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.geocoder;
-
-import javax.json.JsonObject;
-
-public class NominatimGeocoder extends JsonGeocoder {
-
- private static String formatUrl(String url, String key, String language) {
- if (url == null) {
- url = "http://nominatim.openstreetmap.org/reverse";
- }
- url += "?format=json&lat=%f&lon=%f&zoom=18&addressdetails=1";
- if (key != null) {
- url += "&key=" + key;
- }
- if (language != null) {
- url += "&accept-language=" + language;
- }
- return url;
- }
-
- public NominatimGeocoder(String url, String key, String language, int cacheSize) {
- super(formatUrl(url, key, language), cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- JsonObject result = json.getJsonObject("address");
-
- if (result != null) {
- Address address = new Address();
-
- if (result.containsKey("house_number")) {
- address.setHouse(result.getString("house_number"));
- }
- if (result.containsKey("road")) {
- address.setStreet(result.getString("road"));
- }
- if (result.containsKey("suburb")) {
- address.setSuburb(result.getString("suburb"));
- }
-
- if (result.containsKey("village")) {
- address.setSettlement(result.getString("village"));
- } else if (result.containsKey("town")) {
- address.setSettlement(result.getString("town"));
- } else if (result.containsKey("city")) {
- address.setSettlement(result.getString("city"));
- }
-
- if (result.containsKey("state_district")) {
- address.setDistrict(result.getString("state_district"));
- } else if (result.containsKey("region")) {
- address.setDistrict(result.getString("region"));
- }
-
- if (result.containsKey("state")) {
- address.setState(result.getString("state"));
- }
- if (result.containsKey("country_code")) {
- address.setCountry(result.getString("country_code").toUpperCase());
- }
- if (result.containsKey("postcode")) {
- address.setPostcode(result.getString("postcode"));
- }
-
- return address;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/geocoder/OpenCageGeocoder.java b/src/org/traccar/geocoder/OpenCageGeocoder.java
deleted file mode 100644
index 9fa56a4a3..000000000
--- a/src/org/traccar/geocoder/OpenCageGeocoder.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2014 - 2015 Stefaan Van Dooren (stefaan.vandooren@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.
- * 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.geocoder;
-
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-
-public class OpenCageGeocoder extends JsonGeocoder {
-
- public OpenCageGeocoder(String url, String key, int cacheSize) {
- super(url + "/json?q=%f,%f&key=" + key, cacheSize);
- }
-
- @Override
- public Address parseAddress(JsonObject json) {
- JsonArray result = json.getJsonArray("results");
- if (result != null) {
- JsonObject location = result.getJsonObject(0).getJsonObject("components");
- if (location != null) {
- Address address = new Address();
-
- if (location.containsKey("building")) {
- address.setHouse(location.getString("building"));
- }
- if (location.containsKey("house_number")) {
- address.setHouse(location.getString("house_number"));
- }
- if (location.containsKey("road")) {
- address.setStreet(location.getString("road"));
- }
- if (location.containsKey("suburb")) {
- address.setSuburb(location.getString("suburb"));
- }
- if (location.containsKey("city")) {
- address.setSettlement(location.getString("city"));
- }
- if (location.containsKey("city_district")) {
- address.setSettlement(location.getString("city_district"));
- }
- if (location.containsKey("county")) {
- address.setDistrict(location.getString("county"));
- }
- if (location.containsKey("state")) {
- address.setState(location.getString("state"));
- }
- if (location.containsKey("country_code")) {
- address.setCountry(location.getString("country_code").toUpperCase());
- }
- if (location.containsKey("postcode")) {
- address.setPostcode(location.getString("postcode"));
- }
-
- return address;
- }
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/geofence/GeofenceCircle.java b/src/org/traccar/geofence/GeofenceCircle.java
deleted file mode 100644
index d78734714..000000000
--- a/src/org/traccar/geofence/GeofenceCircle.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.geofence;
-
-import java.text.DecimalFormat;
-import java.text.ParseException;
-
-import org.traccar.helper.DistanceCalculator;
-
-public class GeofenceCircle extends GeofenceGeometry {
-
- private double centerLatitude;
- private double centerLongitude;
- private double radius;
-
- public GeofenceCircle() {
- }
-
- public GeofenceCircle(String wkt) throws ParseException {
- fromWkt(wkt);
- }
-
- public GeofenceCircle(double latitude, double longitude, double radius) {
- this.centerLatitude = latitude;
- this.centerLongitude = longitude;
- this.radius = radius;
- }
-
- @Override
- public boolean containsPoint(double latitude, double longitude) {
- return DistanceCalculator.distance(centerLatitude, centerLongitude, latitude, longitude) <= radius;
- }
-
- @Override
- public String toWkt() {
- String wkt = "";
- wkt = "CIRCLE (";
- wkt += String.valueOf(centerLatitude);
- wkt += " ";
- wkt += String.valueOf(centerLongitude);
- wkt += ", ";
- DecimalFormat format = new DecimalFormat("0.#");
- wkt += format.format(radius);
- wkt += ")";
- return wkt;
- }
-
- @Override
- public void fromWkt(String wkt) throws ParseException {
- if (!wkt.startsWith("CIRCLE")) {
- throw new ParseException("Mismatch geometry type", 0);
- }
- String content = wkt.substring(wkt.indexOf("(") + 1, wkt.indexOf(")"));
- if (content == null || content.equals("")) {
- throw new ParseException("No content", 0);
- }
- String[] commaTokens = content.split(",");
- if (commaTokens.length != 2) {
- throw new ParseException("Not valid content", 0);
- }
- String[] tokens = commaTokens[0].split("\\s");
- if (tokens.length != 2) {
- throw new ParseException("Too much or less coordinates", 0);
- }
- try {
- centerLatitude = Double.parseDouble(tokens[0]);
- } catch (NumberFormatException e) {
- throw new ParseException(tokens[0] + " is not a double", 0);
- }
- try {
- centerLongitude = Double.parseDouble(tokens[1]);
- } catch (NumberFormatException e) {
- throw new ParseException(tokens[1] + " is not a double", 0);
- }
- try {
- radius = Double.parseDouble(commaTokens[1]);
- } catch (NumberFormatException e) {
- throw new ParseException(commaTokens[1] + " is not a double", 0);
- }
- }
-}
diff --git a/src/org/traccar/geofence/GeofenceGeometry.java b/src/org/traccar/geofence/GeofenceGeometry.java
deleted file mode 100644
index 857ba3414..000000000
--- a/src/org/traccar/geofence/GeofenceGeometry.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.geofence;
-
-import java.text.ParseException;
-
-public abstract class GeofenceGeometry {
-
- public abstract boolean containsPoint(double latitude, double longitude);
-
- public abstract String toWkt();
-
- public abstract void fromWkt(String wkt) throws ParseException;
-
- public static class Coordinate {
-
- private double lat;
- private double lon;
-
- public double getLat() {
- return lat;
- }
-
- public void setLat(double lat) {
- this.lat = lat;
- }
-
- public double getLon() {
- return lon;
- }
-
- public void setLon(double lon) {
- this.lon = lon;
- }
- }
-
-}
diff --git a/src/org/traccar/geofence/GeofencePolygon.java b/src/org/traccar/geofence/GeofencePolygon.java
deleted file mode 100644
index 2048ba26d..000000000
--- a/src/org/traccar/geofence/GeofencePolygon.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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.geofence;
-
-import java.text.ParseException;
-import java.util.ArrayList;
-
-public class GeofencePolygon extends GeofenceGeometry {
-
- public GeofencePolygon() {
- }
-
- public GeofencePolygon(String wkt) throws ParseException {
- fromWkt(wkt);
- }
-
- private ArrayList<Coordinate> coordinates;
-
- private double[] constant;
- private double[] multiple;
-
- private boolean needNormalize = false;
-
- private void precalc() {
- if (coordinates == null) {
- return;
- }
-
- int polyCorners = coordinates.size();
- int i;
- int j = polyCorners - 1;
-
- if (constant != null) {
- constant = null;
- }
- if (multiple != null) {
- multiple = null;
- }
-
- constant = new double[polyCorners];
- multiple = new double[polyCorners];
-
- boolean hasNegative = false;
- boolean hasPositive = false;
- for (i = 0; i < polyCorners; i++) {
- if (coordinates.get(i).getLon() > 90) {
- hasPositive = true;
- } else if (coordinates.get(i).getLon() < -90) {
- hasNegative = true;
- }
- }
- needNormalize = hasPositive && hasNegative;
-
- for (i = 0; i < polyCorners; j = i++) {
- if (normalizeLon(coordinates.get(j).getLon()) == normalizeLon(coordinates.get(i).getLon())) {
- constant[i] = coordinates.get(i).getLat();
- multiple[i] = 0;
- } else {
- constant[i] = coordinates.get(i).getLat()
- - (normalizeLon(coordinates.get(i).getLon()) * coordinates.get(j).getLat())
- / (normalizeLon(coordinates.get(j).getLon()) - normalizeLon(coordinates.get(i).getLon()))
- + (normalizeLon(coordinates.get(i).getLon()) * coordinates.get(i).getLat())
- / (normalizeLon(coordinates.get(j).getLon()) - normalizeLon(coordinates.get(i).getLon()));
- multiple[i] = (coordinates.get(j).getLat() - coordinates.get(i).getLat())
- / (normalizeLon(coordinates.get(j).getLon()) - normalizeLon(coordinates.get(i).getLon()));
- }
- }
- }
-
- private double normalizeLon(double lon) {
- if (needNormalize && lon < -90) {
- return lon + 360;
- }
- return lon;
- }
-
- @Override
- public boolean containsPoint(double latitude, double longitude) {
-
- int polyCorners = coordinates.size();
- int i;
- int j = polyCorners - 1;
- double longitudeNorm = normalizeLon(longitude);
- boolean oddNodes = false;
-
- for (i = 0; i < polyCorners; j = i++) {
- if (normalizeLon(coordinates.get(i).getLon()) < longitudeNorm
- && normalizeLon(coordinates.get(j).getLon()) >= longitudeNorm
- || normalizeLon(coordinates.get(j).getLon()) < longitudeNorm
- && normalizeLon(coordinates.get(i).getLon()) >= longitudeNorm) {
- oddNodes ^= longitudeNorm * multiple[i] + constant[i] < latitude;
- }
- }
- return oddNodes;
- }
-
- @Override
- public String toWkt() {
- StringBuilder buf = new StringBuilder();
- buf.append("POLYGON ((");
- for (Coordinate coordinate : coordinates) {
- buf.append(String.valueOf(coordinate.getLat()));
- buf.append(" ");
- buf.append(String.valueOf(coordinate.getLon()));
- buf.append(", ");
- }
- return buf.substring(0, buf.length() - 2) + "))";
- }
-
- @Override
- public void fromWkt(String wkt) throws ParseException {
- if (coordinates == null) {
- coordinates = new ArrayList<>();
- } else {
- coordinates.clear();
- }
-
- if (!wkt.startsWith("POLYGON")) {
- throw new ParseException("Mismatch geometry type", 0);
- }
- String content = wkt.substring(wkt.indexOf("((") + 2, wkt.indexOf("))"));
- if (content.isEmpty()) {
- throw new ParseException("No content", 0);
- }
- String[] commaTokens = content.split(",");
- if (commaTokens.length < 3) {
- throw new ParseException("Not valid content", 0);
- }
-
- for (String commaToken : commaTokens) {
- String[] tokens = commaToken.trim().split("\\s");
- if (tokens.length != 2) {
- throw new ParseException("Here must be two coordinates: " + commaToken, 0);
- }
- Coordinate coordinate = new Coordinate();
- try {
- coordinate.setLat(Double.parseDouble(tokens[0]));
- } catch (NumberFormatException e) {
- throw new ParseException(tokens[0] + " is not a double", 0);
- }
- try {
- coordinate.setLon(Double.parseDouble(tokens[1]));
- } catch (NumberFormatException e) {
- throw new ParseException(tokens[1] + " is not a double", 0);
- }
- coordinates.add(coordinate);
- }
- precalc();
- }
-
-}
diff --git a/src/org/traccar/geofence/GeofencePolyline.java b/src/org/traccar/geofence/GeofencePolyline.java
deleted file mode 100644
index d84f512e3..000000000
--- a/src/org/traccar/geofence/GeofencePolyline.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.geofence;
-
-import java.text.ParseException;
-import java.util.ArrayList;
-
-import org.traccar.helper.DistanceCalculator;
-
-public class GeofencePolyline extends GeofenceGeometry {
-
- private ArrayList<Coordinate> coordinates;
- private double distance;
-
- public GeofencePolyline() {
- }
-
- public GeofencePolyline(String wkt, double distance) throws ParseException {
- fromWkt(wkt);
- this.distance = distance;
- }
-
- @Override
- public boolean containsPoint(double latitude, double longitude) {
- for (int i = 1; i < coordinates.size(); i++) {
- if (DistanceCalculator.distanceToLine(
- latitude, longitude, coordinates.get(i - 1).getLat(), coordinates.get(i - 1).getLon(),
- coordinates.get(i).getLat(), coordinates.get(i).getLon()) <= distance) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public String toWkt() {
- StringBuilder buf = new StringBuilder();
- buf.append("LINESTRING (");
- for (Coordinate coordinate : coordinates) {
- buf.append(String.valueOf(coordinate.getLat()));
- buf.append(" ");
- buf.append(String.valueOf(coordinate.getLon()));
- buf.append(", ");
- }
- return buf.substring(0, buf.length() - 2) + ")";
- }
-
- @Override
- public void fromWkt(String wkt) throws ParseException {
- if (coordinates == null) {
- coordinates = new ArrayList<>();
- } else {
- coordinates.clear();
- }
-
- if (!wkt.startsWith("LINESTRING")) {
- throw new ParseException("Mismatch geometry type", 0);
- }
- String content = wkt.substring(wkt.indexOf("(") + 1, wkt.indexOf(")"));
- if (content.isEmpty()) {
- throw new ParseException("No content", 0);
- }
- String[] commaTokens = content.split(",");
- if (commaTokens.length < 2) {
- throw new ParseException("Not valid content", 0);
- }
-
- for (String commaToken : commaTokens) {
- String[] tokens = commaToken.trim().split("\\s");
- if (tokens.length != 2) {
- throw new ParseException("Here must be two coordinates: " + commaToken, 0);
- }
- Coordinate coordinate = new Coordinate();
- try {
- coordinate.setLat(Double.parseDouble(tokens[0]));
- } catch (NumberFormatException e) {
- throw new ParseException(tokens[0] + " is not a double", 0);
- }
- try {
- coordinate.setLon(Double.parseDouble(tokens[1]));
- } catch (NumberFormatException e) {
- throw new ParseException(tokens[1] + " is not a double", 0);
- }
- coordinates.add(coordinate);
- }
-
- }
-
- public void setDistance(double distance) {
- this.distance = distance;
- }
-
-}
diff --git a/src/org/traccar/geolocation/GeolocationException.java b/src/org/traccar/geolocation/GeolocationException.java
deleted file mode 100644
index 5847cc807..000000000
--- a/src/org/traccar/geolocation/GeolocationException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.geolocation;
-
-public class GeolocationException extends RuntimeException {
-
- public GeolocationException(String message) {
- super(message);
- }
-
-}
diff --git a/src/org/traccar/geolocation/GeolocationProvider.java b/src/org/traccar/geolocation/GeolocationProvider.java
deleted file mode 100644
index d9dec6bbb..000000000
--- a/src/org/traccar/geolocation/GeolocationProvider.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.
- * 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.geolocation;
-
-import org.traccar.model.Network;
-
-public interface GeolocationProvider {
-
- interface LocationProviderCallback {
-
- void onSuccess(double latitude, double longitude, double accuracy);
-
- void onFailure(Throwable e);
-
- }
-
- void getLocation(Network network, LocationProviderCallback callback);
-
-}
diff --git a/src/org/traccar/geolocation/GoogleGeolocationProvider.java b/src/org/traccar/geolocation/GoogleGeolocationProvider.java
deleted file mode 100644
index 5901b47cd..000000000
--- a/src/org/traccar/geolocation/GoogleGeolocationProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.geolocation;
-
-public class GoogleGeolocationProvider extends UniversalGeolocationProvider {
-
- private static final String URL = "https://www.googleapis.com/geolocation/v1/geolocate";
-
- public GoogleGeolocationProvider(String key) {
- super(URL, key);
- }
-
-}
diff --git a/src/org/traccar/geolocation/MozillaGeolocationProvider.java b/src/org/traccar/geolocation/MozillaGeolocationProvider.java
deleted file mode 100644
index c6a73a52b..000000000
--- a/src/org/traccar/geolocation/MozillaGeolocationProvider.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.
- * 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.geolocation;
-
-public class MozillaGeolocationProvider extends UniversalGeolocationProvider {
-
- private static final String URL = "https://location.services.mozilla.com/v1/geolocate";
-
- public MozillaGeolocationProvider(String key) {
- super(URL, key != null ? key : "test");
- }
-
-}
diff --git a/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
deleted file mode 100644
index d6e45b550..000000000
--- a/src/org/traccar/geolocation/OpenCellIdGeolocationProvider.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.
- * 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.geolocation;
-
-import com.ning.http.client.AsyncCompletionHandler;
-import com.ning.http.client.Response;
-import org.traccar.Context;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-
-public class OpenCellIdGeolocationProvider implements GeolocationProvider {
-
- private String url;
-
- public OpenCellIdGeolocationProvider(String key) {
- this("http://opencellid.org/cell/get", key);
- }
-
- public OpenCellIdGeolocationProvider(String url, String key) {
- this.url = url + "?format=json&mcc=%d&mnc=%d&lac=%d&cellid=%d&key=" + key;
- }
-
- @Override
- public void getLocation(Network network, final LocationProviderCallback callback) {
- if (network.getCellTowers() != null && !network.getCellTowers().isEmpty()) {
-
- CellTower cellTower = network.getCellTowers().iterator().next();
- String request = String.format(url, cellTower.getMobileCountryCode(), cellTower.getMobileNetworkCode(),
- cellTower.getLocationAreaCode(), cellTower.getCellId());
-
- Context.getAsyncHttpClient().prepareGet(request).execute(new AsyncCompletionHandler() {
- @Override
- public Object onCompleted(Response response) throws Exception {
- try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
- JsonObject json = reader.readObject();
- if (json.containsKey("lat") && json.containsKey("lon")) {
- callback.onSuccess(
- json.getJsonNumber("lat").doubleValue(),
- json.getJsonNumber("lon").doubleValue(), 0);
- } else {
- callback.onFailure(new GeolocationException("Coordinates are missing"));
- }
- }
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- callback.onFailure(t);
- }
- });
-
- } else {
- callback.onFailure(new GeolocationException("No network information"));
- }
- }
-
-}
diff --git a/src/org/traccar/geolocation/UniversalGeolocationProvider.java b/src/org/traccar/geolocation/UniversalGeolocationProvider.java
deleted file mode 100644
index 6416b2633..000000000
--- a/src/org/traccar/geolocation/UniversalGeolocationProvider.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.geolocation;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.ning.http.client.AsyncCompletionHandler;
-import com.ning.http.client.Response;
-import org.traccar.Context;
-import org.traccar.model.Network;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-
-public class UniversalGeolocationProvider implements GeolocationProvider {
-
- private String url;
-
- public UniversalGeolocationProvider(String url, String key) {
- this.url = url + "?key=" + key;
- }
-
- @Override
- public void getLocation(Network network, final LocationProviderCallback callback) {
- try {
- String request = Context.getObjectMapper().writeValueAsString(network);
- Context.getAsyncHttpClient().preparePost(url)
- .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(request.length()))
- .setBody(request).execute(new AsyncCompletionHandler() {
- @Override
- public Object onCompleted(Response response) throws Exception {
- try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
- JsonObject json = reader.readObject();
- if (json.containsKey("error")) {
- callback.onFailure(
- new GeolocationException(json.getJsonObject("error").getString("message")));
- } else {
- JsonObject location = json.getJsonObject("location");
- callback.onSuccess(
- location.getJsonNumber("lat").doubleValue(),
- location.getJsonNumber("lng").doubleValue(),
- json.getJsonNumber("accuracy").doubleValue());
- }
- }
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- callback.onFailure(t);
- }
- });
- } catch (JsonProcessingException e) {
- callback.onFailure(e);
- }
- }
-
-}
diff --git a/src/org/traccar/geolocation/UnwiredGeolocationProvider.java b/src/org/traccar/geolocation/UnwiredGeolocationProvider.java
deleted file mode 100644
index dcc5a4e7a..000000000
--- a/src/org/traccar/geolocation/UnwiredGeolocationProvider.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.geolocation;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.ning.http.client.AsyncCompletionHandler;
-import com.ning.http.client.Response;
-import org.traccar.Context;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.WifiAccessPoint;
-
-import javax.json.Json;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import java.util.Collection;
-
-public class UnwiredGeolocationProvider implements GeolocationProvider {
-
- private String url;
- private String key;
-
- private ObjectMapper objectMapper;
-
- private abstract static class NetworkMixIn {
- @JsonProperty("mcc")
- abstract Integer getHomeMobileCountryCode();
- @JsonProperty("mnc")
- abstract Integer getHomeMobileNetworkCode();
- @JsonProperty("radio")
- abstract String getRadioType();
- @JsonIgnore
- abstract String getCarrier();
- @JsonIgnore
- abstract Boolean getConsiderIp();
- @JsonProperty("cells")
- abstract Collection<CellTower> getCellTowers();
- @JsonProperty("wifi")
- abstract Collection<WifiAccessPoint> getWifiAccessPoints();
- }
-
- private abstract static class CellTowerMixIn {
- @JsonProperty("radio")
- abstract String getRadioType();
- @JsonProperty("mcc")
- abstract Integer getMobileCountryCode();
- @JsonProperty("mnc")
- abstract Integer getMobileNetworkCode();
- @JsonProperty("lac")
- abstract Integer getLocationAreaCode();
- @JsonProperty("cid")
- abstract Long getCellId();
- }
-
- private abstract static class WifiAccessPointMixIn {
- @JsonProperty("bssid")
- abstract String getMacAddress();
- @JsonProperty("signal")
- abstract Integer getSignalStrength();
- }
-
- public UnwiredGeolocationProvider(String url, String key) {
- this.url = url;
- this.key = key;
-
- objectMapper = new ObjectMapper();
- objectMapper.addMixIn(Network.class, NetworkMixIn.class);
- objectMapper.addMixIn(CellTower.class, CellTowerMixIn.class);
- objectMapper.addMixIn(WifiAccessPoint.class, WifiAccessPointMixIn.class);
- }
-
- @Override
- public void getLocation(Network network, final LocationProviderCallback callback) {
- try {
- ObjectNode json = objectMapper.valueToTree(network);
- json.put("token", key);
- String request = objectMapper.writeValueAsString(json);
- Context.getAsyncHttpClient().preparePost(url)
- .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
- .setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(request.length()))
- .setBody(request).execute(new AsyncCompletionHandler() {
- @Override
- public Object onCompleted(Response response) throws Exception {
- try (JsonReader reader = Json.createReader(response.getResponseBodyAsStream())) {
- JsonObject json = reader.readObject();
- if (json.getString("status").equals("error")) {
- callback.onFailure(
- new GeolocationException(json.getString("message")));
- } else {
- callback.onSuccess(
- json.getJsonNumber("lat").doubleValue(),
- json.getJsonNumber("lon").doubleValue(),
- json.getJsonNumber("accuracy").doubleValue());
- }
- }
- return null;
- }
-
- @Override
- public void onThrowable(Throwable t) {
- callback.onFailure(t);
- }
- });
- } catch (JsonProcessingException e) {
- callback.onFailure(e);
- }
- }
-
-}
diff --git a/src/org/traccar/helper/BcdUtil.java b/src/org/traccar/helper/BcdUtil.java
deleted file mode 100644
index 495f94104..000000000
--- a/src/org/traccar/helper/BcdUtil.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-
-public final class BcdUtil {
-
- private BcdUtil() {
- }
-
- public static int readInteger(ChannelBuffer buf, int digits) {
- int result = 0;
-
- for (int i = 0; i < digits / 2; i++) {
- int b = buf.readUnsignedByte();
- result *= 10;
- result += b >>> 4;
- result *= 10;
- result += b & 0x0f;
- }
-
- if (digits % 2 != 0) {
- int b = buf.getUnsignedByte(buf.readerIndex());
- result *= 10;
- result += b >>> 4;
- }
-
- return result;
- }
-
- public static double readCoordinate(ChannelBuffer buf) {
- int b1 = buf.readUnsignedByte();
- int b2 = buf.readUnsignedByte();
- int b3 = buf.readUnsignedByte();
- int b4 = buf.readUnsignedByte();
-
- double value = (b2 & 0xf) * 10 + (b3 >> 4);
- value += (((b3 & 0xf) * 10 + (b4 >> 4)) * 10 + (b4 & 0xf)) / 1000.0;
- value /= 60;
- value += ((b1 >> 4 & 0x7) * 10 + (b1 & 0xf)) * 10 + (b2 >> 4);
-
- if ((b1 & 0x80) != 0) {
- value = -value;
- }
-
- return value;
- }
-
-}
diff --git a/src/org/traccar/helper/BitBuffer.java b/src/org/traccar/helper/BitBuffer.java
deleted file mode 100644
index ac307efdf..000000000
--- a/src/org/traccar/helper/BitBuffer.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.helper;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-
-public class BitBuffer {
-
- private final ChannelBuffer buffer;
-
- private int writeByte;
- private int writeCount;
-
- private int readByte;
- private int readCount;
-
- public BitBuffer() {
- buffer = ChannelBuffers.dynamicBuffer();
- }
-
- public BitBuffer(ChannelBuffer buffer) {
- this.buffer = buffer;
- }
-
- public void writeEncoded(byte[] bytes) {
- for (byte b : bytes) {
- b -= 48;
- if (b > 40) {
- b -= 8;
- }
- write(b);
- }
- }
-
- public void write(int b) {
- if (writeCount == 0) {
- writeByte |= b;
- writeCount = 6;
- } else {
- int remaining = 8 - writeCount;
- writeByte <<= remaining;
- writeByte |= b >> (6 - remaining);
- buffer.writeByte(writeByte);
- writeByte = b & ((1 << (6 - remaining)) - 1);
- writeCount = 6 - remaining;
- }
- }
-
- public int readUnsigned(int length) {
- int result = 0;
-
- while (length > 0) {
- if (readCount == 0) {
- readByte = buffer.readUnsignedByte();
- readCount = 8;
- }
- if (readCount >= length) {
- result <<= length;
- result |= readByte >> (readCount - length);
- readByte &= (1 << (readCount - length)) - 1;
- readCount -= length;
- length = 0;
- } else {
- result <<= readCount;
- result |= readByte;
- length -= readCount;
- readByte = 0;
- readCount = 0;
- }
- }
-
- return result;
- }
-
- public int readSigned(int length) {
- int result = readUnsigned(length);
- int signBit = 1 << (length - 1);
- if ((result & signBit) == 0) {
- return result;
- } else {
- result &= signBit - 1;
- result += ~(signBit - 1);
- return result;
- }
- }
-
-}
diff --git a/src/org/traccar/helper/BitUtil.java b/src/org/traccar/helper/BitUtil.java
deleted file mode 100644
index b6108edff..000000000
--- a/src/org/traccar/helper/BitUtil.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-public final class BitUtil {
-
- private BitUtil() {
- }
-
- public static boolean check(long number, int index) {
- return (number & (1 << index)) != 0;
- }
-
- public static int between(int number, int from, int to) {
- return (number >> from) & ((1 << to - from) - 1);
- }
-
- public static int from(int number, int from) {
- return number >> from;
- }
-
- public static int to(int number, int to) {
- return between(number, 0, to);
- }
-
- public static long between(long number, int from, int to) {
- return (number >> from) & ((1L << to - from) - 1L);
- }
-
- public static long from(long number, int from) {
- return number >> from;
- }
-
- public static long to(long number, int to) {
- return between(number, 0, to);
- }
-
-}
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
deleted file mode 100644
index 44cef9635..000000000
--- a/src/org/traccar/helper/Checksum.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
-import java.util.zip.CRC32;
-
-public final class Checksum {
-
- private Checksum() {
- }
-
- private static final int[] CRC16_CCITT_TABLE_REVERSE = {
- 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
- 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
- 0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E,
- 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
- 0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD,
- 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
- 0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C,
- 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
- 0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB,
- 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
- 0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A,
- 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
- 0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9,
- 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
- 0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738,
- 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
- 0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7,
- 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
- 0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036,
- 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
- 0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5,
- 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
- 0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134,
- 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
- 0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3,
- 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
- 0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232,
- 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
- 0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1,
- 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
- 0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
- 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
- };
-
- private static final int[] CRC16_CCITT_TABLE = {
- 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
- 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
- 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
- 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
- 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
- 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
- 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
- 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
- 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
- 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
- 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
- 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
- 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
- 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
- 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
- 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
- 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
- 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
- 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
- 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
- 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
- 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
- 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
- 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
- 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
- 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
- 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
- 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
- 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
- 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
- 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
- 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
- };
-
- private static final int[] CRC16_IBM_TABLE = {
- 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241,
- 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440,
- 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40,
- 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841,
- 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40,
- 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41,
- 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641,
- 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040,
- 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240,
- 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441,
- 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41,
- 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840,
- 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41,
- 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40,
- 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640,
- 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041,
- 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240,
- 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441,
- 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41,
- 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840,
- 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41,
- 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40,
- 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640,
- 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041,
- 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241,
- 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440,
- 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40,
- 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841,
- 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40,
- 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41,
- 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641,
- 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040,
- };
-
- // More info: http://reveng.sourceforge.net/crc-catalogue/16.htm
- public static final String CRC16_IBM = "IBM";
- public static final String CRC16_MODBUS = "MODBUS";
- public static final String CRC16_X25 = "X-25";
- public static final String CRC16_CCITT_FALSE = "CCITT-FALSE";
- public static final String CRC16_KERMIT = "KERMIT";
- public static final String CRC16_XMODEM = "XMODEM";
- public static final String CRC16_AUG_CCITT = "AUG-CCITT";
- public static final String CRC16_GENIBUS = "GENIBUS";
- public static final String CRC16_MCRF4XX = "MCRF4XX";
-
- private static int crc16Unreflected(ByteBuffer buf, int crcIn, int[] table) {
- int crc16 = crcIn;
- while (buf.hasRemaining()) {
- crc16 = table[((crc16 >> 8) ^ buf.get()) & 0xff] ^ (crc16 << 8);
- }
- return crc16 & 0xFFFF;
- }
-
- private static int crc16Reflected(ByteBuffer buf, int crcIn, int[] table) {
- int crc16 = crcIn;
- while (buf.hasRemaining()) {
- crc16 = table[(crc16 ^ buf.get()) & 0xff] ^ (crc16 >> 8);
- }
- return crc16 & 0xFFFF;
- }
-
- public static int crc16(String type, ByteBuffer buf) {
- switch (type) {
- case CRC16_IBM:
- return crc16Reflected(buf, 0, CRC16_IBM_TABLE);
- case CRC16_MODBUS:
- return crc16Reflected(buf, 0xFFFF, CRC16_IBM_TABLE);
- case CRC16_X25:
- return crc16Reflected(buf, 0xFFFF, CRC16_CCITT_TABLE_REVERSE) ^ 0xFFFF;
- case CRC16_CCITT_FALSE:
- return crc16Unreflected(buf, 0xFFFF, CRC16_CCITT_TABLE);
- case CRC16_KERMIT:
- return crc16Reflected(buf, 0, CRC16_CCITT_TABLE_REVERSE);
- case CRC16_XMODEM:
- return crc16Unreflected(buf, 0, CRC16_CCITT_TABLE);
- case CRC16_AUG_CCITT:
- return crc16Unreflected(buf, 0x1d0f, CRC16_CCITT_TABLE);
- case CRC16_GENIBUS:
- return crc16Unreflected(buf, 0xFFFF, CRC16_CCITT_TABLE) ^ 0xFFFF;
- case CRC16_MCRF4XX:
- return crc16Reflected(buf, 0xFFFF, CRC16_CCITT_TABLE_REVERSE);
- default:
- throw new UnsupportedOperationException(type);
- }
- }
-
- public static int crc32(ByteBuffer buf) {
- CRC32 checksum = new CRC32();
- while (buf.hasRemaining()) {
- checksum.update(buf.get());
- }
- return (int) checksum.getValue();
- }
-
- public static int xor(ByteBuffer buf) {
- int checksum = 0;
- while (buf.hasRemaining()) {
- checksum ^= buf.get();
- }
- 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;
- byte[] bytes = msg.getBytes(StandardCharsets.US_ASCII);
- for (int i = 1; i < bytes.length; i++) {
- checksum ^= bytes[i];
- }
- return String.format("*%02x", checksum).toUpperCase();
- }
-
- public static String sum(String msg) {
- byte checksum = 0;
- for (byte b : msg.getBytes(StandardCharsets.US_ASCII)) {
- checksum += b;
- }
- return String.format("%02X", checksum).toUpperCase();
- }
-
- public static long luhn(long imei) {
- long checksum = 0;
- long remain = imei;
-
- for (int i = 0; remain != 0; i++) {
- long digit = remain % 10;
-
- if (i % 2 == 0) {
- digit *= 2;
- if (digit >= 10) {
- digit = 1 + (digit % 10);
- }
- }
-
- checksum += digit;
- remain /= 10;
- }
-
- return (10 - (checksum % 10)) % 10;
- }
-
- public static int modulo256(byte[] bytes) {
- int sum = 0;
- for (byte b : bytes) {
- sum = (sum + b) & 0xFF;
- }
- return sum;
- }
-
-}
diff --git a/src/org/traccar/helper/DateBuilder.java b/src/org/traccar/helper/DateBuilder.java
deleted file mode 100644
index 6e1b779f0..000000000
--- a/src/org/traccar/helper/DateBuilder.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-
-public class DateBuilder {
-
- private Calendar calendar;
-
- public DateBuilder() {
- this(TimeZone.getTimeZone("UTC"));
- }
-
- public DateBuilder(Date time) {
- this(time, TimeZone.getTimeZone("UTC"));
- }
-
- public DateBuilder(TimeZone timeZone) {
- this(new Date(0), timeZone);
- }
-
- public DateBuilder(Date time, TimeZone timeZone) {
- calendar = Calendar.getInstance(timeZone);
- calendar.clear();
- calendar.setTimeInMillis(time.getTime());
- }
-
- public DateBuilder setYear(int year) {
- if (year < 100) {
- year += 2000;
- }
- calendar.set(Calendar.YEAR, year);
- return this;
- }
-
- public DateBuilder setMonth(int month) {
- calendar.set(Calendar.MONTH, month - 1);
- return this;
- }
-
- public DateBuilder setDay(int day) {
- calendar.set(Calendar.DAY_OF_MONTH, day);
- return this;
- }
-
- public DateBuilder setDate(int year, int month, int day) {
- return setYear(year).setMonth(month).setDay(day);
- }
-
- public DateBuilder setDateReverse(int day, int month, int year) {
- return setDate(year, month, day);
- }
-
- public DateBuilder setCurrentDate() {
- Calendar now = Calendar.getInstance(calendar.getTimeZone());
- return setYear(now.get(Calendar.YEAR)).setMonth(now.get(Calendar.MONTH)).setDay(now.get(Calendar.DAY_OF_MONTH));
- }
-
- public DateBuilder setHour(int hour) {
- calendar.set(Calendar.HOUR_OF_DAY, hour);
- return this;
- }
-
- public DateBuilder setMinute(int minute) {
- calendar.set(Calendar.MINUTE, minute);
- return this;
- }
-
- public DateBuilder addMinute(int minute) {
- calendar.add(Calendar.MINUTE, minute);
- return this;
- }
-
- public DateBuilder setSecond(int second) {
- calendar.set(Calendar.SECOND, second);
- 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;
- }
-
- public DateBuilder addMillis(long millis) {
- calendar.setTimeInMillis(calendar.getTimeInMillis() + millis);
- return this;
- }
-
- public DateBuilder setTime(int hour, int minute, int second) {
- return setHour(hour).setMinute(minute).setSecond(second);
- }
-
- public DateBuilder setTimeReverse(int second, int minute, int hour) {
- return setHour(hour).setMinute(minute).setSecond(second);
- }
-
- public DateBuilder setTime(int hour, int minute, int second, int millis) {
- return setHour(hour).setMinute(minute).setSecond(second).setMillis(millis);
- }
-
- public Date getDate() {
- return calendar.getTime();
- }
-
-}
diff --git a/src/org/traccar/helper/DateUtil.java b/src/org/traccar/helper/DateUtil.java
deleted file mode 100644
index 30bb1b2fa..000000000
--- a/src/org/traccar/helper/DateUtil.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.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.dateTimeParser();
-
- private DateUtil() {
- }
-
- public static Date correctDay(Date guess) {
- return correctDate(new Date(), guess, Calendar.DAY_OF_MONTH);
- }
-
- public static Date correctYear(Date guess) {
- return correctDate(new Date(), guess, Calendar.YEAR);
- }
-
- public static Date correctDate(Date now, Date guess, int field) {
-
- if (guess.getTime() > now.getTime()) {
- Date previous = dateAdd(guess, field, -1);
- if (now.getTime() - previous.getTime() < guess.getTime() - now.getTime()) {
- return previous;
- }
- } else if (guess.getTime() < now.getTime()) {
- Date next = dateAdd(guess, field, 1);
- if (next.getTime() - now.getTime() < now.getTime() - guess.getTime()) {
- return next;
- }
- }
-
- return guess;
- }
-
- private static Date dateAdd(Date guess, int field, int amount) {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(guess);
- calendar.add(field, amount);
- 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
deleted file mode 100644
index 88d4ef8a4..000000000
--- a/src/org/traccar/helper/DistanceCalculator.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2014 - 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.helper;
-
-public final class DistanceCalculator {
-
- private DistanceCalculator() {
- }
-
- private static final double EQUATORIAL_EARTH_RADIUS = 6378.1370;
- private static final double DEG_TO_RAD = Math.PI / 180;
-
- public static double distance(double lat1, double lon1, double lat2, double lon2) {
- double dlong = (lon2 - lon1) * DEG_TO_RAD;
- double dlat = (lat2 - lat1) * DEG_TO_RAD;
- double a = Math.pow(Math.sin(dlat / 2), 2)
- + Math.cos(lat1 * DEG_TO_RAD) * Math.cos(lat2 * DEG_TO_RAD) * Math.pow(Math.sin(dlong / 2), 2);
- double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- double d = EQUATORIAL_EARTH_RADIUS * c;
- return d * 1000;
- }
-
- public static double distanceToLine(
- double pointLat, double pointLon, double lat1, double lon1, double lat2, double lon2) {
- double d0 = distance(pointLat, pointLon, lat1, lon1);
- double d1 = distance(lat1, lon1, lat2, lon2);
- double d2 = distance(lat2, lon2, pointLat, pointLon);
- if (Math.pow(d0, 2) > Math.pow(d1, 2) + Math.pow(d2, 2)) {
- return d2;
- }
- if (Math.pow(d2, 2) > Math.pow(d1, 2) + Math.pow(d0, 2)) {
- return d0;
- }
- double halfP = (d0 + d1 + d2) * 0.5;
- double area = Math.sqrt(halfP * (halfP - d0) * (halfP - d1) * (halfP - d2));
- return 2 * area / d1;
- }
-
-}
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java
deleted file mode 100644
index 3fcc124fa..000000000
--- a/src/org/traccar/helper/Hashing.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.PBEKeySpec;
-import javax.xml.bind.DatatypeConverter;
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.spec.InvalidKeySpecException;
-
-public final class Hashing {
-
- public static final int ITERATIONS = 1000;
- public static final int SALT_SIZE = 24;
- public static final int HASH_SIZE = 24;
-
- private static SecretKeyFactory factory;
- static {
- try {
- factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- }
-
- public static class HashingResult {
-
- private final String hash;
- private final String salt;
-
- public HashingResult(String hash, String salt) {
- this.hash = hash;
- this.salt = salt;
- }
-
- public String getHash() {
- return hash;
- }
-
- public String getSalt() {
- return salt;
- }
- }
-
- private Hashing() {
- }
-
- private static byte[] function(char[] password, byte[] salt) {
- try {
- PBEKeySpec spec = new PBEKeySpec(password, salt, ITERATIONS, HASH_SIZE * Byte.SIZE);
- return factory.generateSecret(spec).getEncoded();
- } catch (InvalidKeySpecException e) {
- throw new SecurityException(e);
- }
- }
-
- private static final SecureRandom RANDOM = new SecureRandom();
-
- public static HashingResult createHash(String password) {
- byte[] salt = new byte[SALT_SIZE];
- RANDOM.nextBytes(salt);
- byte[] hash = function(password.toCharArray(), salt);
- return new HashingResult(
- DatatypeConverter.printHexBinary(hash),
- DatatypeConverter.printHexBinary(salt));
- }
-
- public static boolean validatePassword(String password, String hashHex, String saltHex) {
- byte[] hash = DatatypeConverter.parseHexBinary(hashHex);
- byte[] salt = DatatypeConverter.parseHexBinary(saltHex);
- return slowEquals(hash, function(password.toCharArray(), salt));
- }
-
- /**
- * Compares two byte arrays in length-constant time. This comparison method
- * is used so that password hashes cannot be extracted from an on-line
- * system using a timing attack and then attacked off-line.
- */
- private static boolean slowEquals(byte[] a, byte[] b) {
- int diff = a.length ^ b.length;
- for (int i = 0; i < a.length && i < b.length; i++) {
- diff |= a[i] ^ b[i];
- }
- return diff == 0;
- }
-
-}
diff --git a/src/org/traccar/helper/LocationTree.java b/src/org/traccar/helper/LocationTree.java
deleted file mode 100644
index 3aff3ce33..000000000
--- a/src/org/traccar/helper/LocationTree.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.helper;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-public class LocationTree {
-
- public static class Item {
-
- private Item left, right;
- private float x, y;
- private String data;
-
- public Item(float x, float y) {
- this(x, y, null);
- }
-
- public Item(float x, float y, String data) {
- this.x = x;
- this.y = y;
- this.data = data;
- }
-
- public String getData() {
- return data;
- }
-
- private float squaredDistance(Item item) {
- return (x - item.x) * (x - item.x) + (y - item.y) * (y - item.y);
- }
-
- private float axisSquaredDistance(Item item, int axis) {
- if (axis == 0) {
- return (x - item.x) * (x - item.x);
- } else {
- return (y - item.y) * (y - item.y);
- }
- }
-
- }
-
- private Item root;
-
- private ArrayList<Comparator<Item>> comparators = new ArrayList<>();
-
- public LocationTree(List<Item> items) {
- comparators.add(new Comparator<Item>() {
- @Override
- public int compare(Item o1, Item o2) {
- return Float.compare(o1.x, o2.x);
- }
- });
- comparators.add(new Comparator<Item>() {
- @Override
- public int compare(Item o1, Item o2) {
- return Float.compare(o1.y, o2.y);
- }
- });
- root = createTree(items, 0);
- }
-
- private Item createTree(List<Item> items, int depth) {
- if (items.isEmpty()) {
- return null;
- }
- Collections.sort(items, comparators.get(depth % 2));
- int currentIndex = items.size() / 2;
- Item median = items.get(currentIndex);
- median.left = createTree(new ArrayList<>(items.subList(0, currentIndex)), depth + 1);
- median.right = createTree(new ArrayList<>(items.subList(currentIndex + 1, items.size())), depth + 1);
- return median;
- }
-
- public Item findNearest(Item search) {
- return findNearest(root, search, 0);
- }
-
- private Item findNearest(Item current, Item search, int depth) {
- int direction = comparators.get(depth % 2).compare(search, current);
-
- Item next, other;
- if (direction < 0) {
- next = current.left;
- other = current.right;
- } else {
- next = current.right;
- other = current.left;
- }
-
- Item best = current;
- if (next != null) {
- best = findNearest(next, search, depth + 1);
- }
-
- if (current.squaredDistance(search) < best.squaredDistance(search)) {
- best = current;
- }
- if (other != null && current.axisSquaredDistance(search, depth % 2) < best.squaredDistance(search)) {
- Item possibleBest = findNearest(other, search, depth + 1);
- if (possibleBest.squaredDistance(search) < best.squaredDistance(search)) {
- best = possibleBest;
- }
- }
-
- return best;
- }
-
-}
diff --git a/src/org/traccar/helper/Log.java b/src/org/traccar/helper/Log.java
deleted file mode 100644
index d74246a64..000000000
--- a/src/org/traccar/helper/Log.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import org.apache.log4j.Appender;
-import org.apache.log4j.DailyRollingFileAppender;
-import org.apache.log4j.Layout;
-import org.apache.log4j.Level;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.varia.NullAppender;
-import org.jboss.netty.logging.AbstractInternalLogger;
-import org.jboss.netty.logging.InternalLogger;
-import org.jboss.netty.logging.InternalLoggerFactory;
-import org.traccar.Config;
-
-import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryMXBean;
-import java.lang.management.OperatingSystemMXBean;
-import java.lang.management.RuntimeMXBean;
-import java.nio.charset.Charset;
-
-public final class Log {
-
- private Log() {
- }
-
- public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
-
- private static final String LOGGER_NAME = "traccar";
-
- private static final String STACK_PACKAGE = "org.traccar";
- private static final int STACK_LIMIT = 3;
-
- 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");
-
- Appender appender = new DailyRollingFileAppender(
- layout, config.getString("logger.file"), "'.'yyyyMMdd");
-
- LogManager.resetConfiguration();
- LogManager.getRootLogger().addAppender(new NullAppender());
-
- logger = Logger.getLogger(LOGGER_NAME);
- logger.addAppender(appender);
- logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
-
- // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
- InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
- @Override
- public InternalLogger newInstance(String string) {
- return new NettyInternalLogger();
- }
- });
-
- Log.logSystemInfo();
- Log.info("Version: " + getAppVersion());
- }
-
- public static Logger getLogger() {
- if (logger == null) {
- logger = Logger.getLogger(LOGGER_NAME);
- logger.setLevel(Level.OFF);
- }
- return logger;
- }
-
- public static void logSystemInfo() {
- try {
- OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
- Log.info("Operating system"
- + " name: " + operatingSystemBean.getName()
- + " version: " + operatingSystemBean.getVersion()
- + " architecture: " + operatingSystemBean.getArch());
-
- RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
- Log.info("Java runtime"
- + " name: " + runtimeBean.getVmName()
- + " vendor: " + runtimeBean.getVmVendor()
- + " version: " + runtimeBean.getVmVersion());
-
- MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
- Log.info("Memory limit"
- + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"
- + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");
-
- Log.info("Character encoding: "
- + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());
-
- } catch (Exception error) {
- Log.warning("Failed to get system info");
- }
- }
-
- public static void error(String msg) {
- getLogger().error(msg);
- }
-
- public static void warning(String msg) {
- getLogger().warn(msg);
- }
-
- public static void warning(Throwable exception) {
- warning(null, exception);
- }
-
- public static void warning(String msg, Throwable exception) {
- StringBuilder s = new StringBuilder();
- if (msg != null) {
- s.append(msg);
- }
- if (exception != null) {
- if (msg != null) {
- s.append(" - ");
- }
- s.append(exceptionStack(exception));
- }
- getLogger().warn(s.toString());
- }
-
- public static void info(String msg) {
- getLogger().info(msg);
- }
-
- public static void debug(String msg) {
- getLogger().debug(msg);
- }
-
- public static String exceptionStack(Throwable exception) {
- StringBuilder s = new StringBuilder();
- String exceptionMsg = exception.getMessage();
- if (exceptionMsg != null) {
- s.append(exceptionMsg);
- s.append(" - ");
- }
- s.append(exception.getClass().getSimpleName());
- StackTraceElement[] stack = exception.getStackTrace();
-
- if (stack.length > 0) {
- int count = STACK_LIMIT;
- boolean first = true;
- boolean skip = false;
- String file = "";
- s.append(" (");
- for (StackTraceElement element : stack) {
- if (count > 0 && element.getClassName().startsWith(STACK_PACKAGE)) {
- if (!first) {
- s.append(" < ");
- } else {
- first = false;
- }
-
- if (skip) {
- s.append("... < ");
- skip = false;
- }
-
- if (file.equals(element.getFileName())) {
- s.append("*");
- } else {
- file = element.getFileName();
- s.append(file.substring(0, file.length() - 5)); // remove ".java"
- count -= 1;
- }
- s.append(":").append(element.getLineNumber());
- } else {
- skip = true;
- }
- }
- if (skip) {
- if (!first) {
- s.append(" < ");
- }
- s.append("...");
- }
- s.append(")");
- }
- return s.toString();
- }
-
- /**
- * Netty logger implementation
- */
- private static class NettyInternalLogger extends AbstractInternalLogger {
-
- @Override
- public boolean isDebugEnabled() {
- return false;
- }
-
- @Override
- public boolean isInfoEnabled() {
- return false;
- }
-
- @Override
- public boolean isWarnEnabled() {
- return true;
- }
-
- @Override
- public boolean isErrorEnabled() {
- return true;
- }
-
- @Override
- public void debug(String string) {
- debug(string, null);
- }
-
- @Override
- public void debug(String string, Throwable thrwbl) {
- }
-
- @Override
- public void info(String string) {
- info(string, null);
- }
-
- @Override
- public void info(String string, Throwable thrwbl) {
- }
-
- @Override
- public void warn(String string) {
- warn(string, null);
- }
-
- @Override
- public void warn(String string, Throwable thrwbl) {
- getLogger().warn("netty warning: " + string);
- }
-
- @Override
- public void error(String string) {
- error(string, null);
- }
-
- @Override
- public void error(String string, Throwable thrwbl) {
- getLogger().error("netty error: " + string);
- }
-
- }
-
-}
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
deleted file mode 100644
index 4bc3bcdfb..000000000
--- a/src/org/traccar/helper/ObdDecoder.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import org.traccar.model.Position;
-
-import java.util.AbstractMap;
-import java.util.Map;
-
-public final class ObdDecoder {
-
- private ObdDecoder() {
- }
-
- private static final int MODE_CURRENT = 0x01;
- private static final int MODE_FREEZE_FRAME = 0x02;
- private static final int MODE_CODES = 0x03;
-
- private static final int PID_ENGINE_LOAD = 0x04;
- private static final int PID_COOLANT_TEMPERATURE = 0x05;
- private static final int PID_ENGINE_RPM = 0x0C;
- private static final int PID_VEHICLE_SPEED = 0x0D;
- private static final int PID_THROTTLE_POSITION = 0x11;
- private static final int PID_MIL_DISTANCE = 0x21;
- private static final int PID_FUEL_LEVEL = 0x2F;
- private static final int PID_DISTANCE_CLEARED = 0x31;
-
- public static Map.Entry<String, Object> decode(int mode, String value) {
- switch (mode) {
- case MODE_CURRENT:
- case MODE_FREEZE_FRAME:
- return decodeData(
- Integer.parseInt(value.substring(0, 2), 16),
- Integer.parseInt(value.substring(2), 16), true);
- case MODE_CODES:
- return decodeCodes(value);
- default:
- return null;
- }
- }
-
- private static Map.Entry<String, Object> createEntry(String key, Object value) {
- return new AbstractMap.SimpleEntry<>(key, value);
- }
-
- public static Map.Entry<String, Object> decodeCodes(String value) {
- 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(' ');
- switch (numValue >> 14) {
- case 1:
- codes.append('C');
- break;
- case 2:
- codes.append('B');
- break;
- case 3:
- codes.append('U');
- break;
- default:
- codes.append('P');
- break;
- }
- codes.append(String.format("%04X", numValue & 0x3FFF));
- }
- if (codes.length() > 0) {
- return createEntry(Position.KEY_DTCS, codes.toString().trim());
- } else {
- return null;
- }
- }
-
- public static Map.Entry<String, Object> decodeData(int pid, int value, boolean convert) {
- switch (pid) {
- case PID_ENGINE_LOAD:
- return createEntry(Position.KEY_ENGINE_LOAD, convert ? value * 100 / 255 : value);
- case PID_COOLANT_TEMPERATURE:
- return createEntry(Position.KEY_COOLANT_TEMP, convert ? value - 40 : value);
- case PID_ENGINE_RPM:
- return createEntry(Position.KEY_RPM, convert ? value / 4 : value);
- case PID_VEHICLE_SPEED:
- return createEntry(Position.KEY_OBD_SPEED, value);
- case PID_THROTTLE_POSITION:
- return createEntry(Position.KEY_THROTTLE, convert ? value * 100 / 255 : value);
- case PID_MIL_DISTANCE:
- return createEntry("milDistance", value);
- case PID_FUEL_LEVEL:
- return createEntry(Position.KEY_FUEL_LEVEL, convert ? value * 100 / 255 : value);
- case PID_DISTANCE_CLEARED:
- return createEntry("clearedDistance", value);
- default:
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java
deleted file mode 100644
index 1471ec237..000000000
--- a/src/org/traccar/helper/Parser.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.helper;
-
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class Parser {
-
- private int position;
- private final Matcher matcher;
-
- public Parser(Pattern pattern, String input) {
- matcher = pattern.matcher(input);
- }
-
- public boolean matches() {
- position = 1;
- return matcher.matches();
- }
-
- public boolean find() {
- position = 1;
- return matcher.find();
- }
-
- public void skip(int number) {
- position += number;
- }
-
- public boolean hasNext() {
- return hasNext(1);
- }
-
- public boolean hasNext(int number) {
- String value = matcher.group(position);
- if (value != null && !value.isEmpty()) {
- return true;
- } else {
- position += number;
- return false;
- }
- }
-
- public String next() {
- return matcher.group(position++);
- }
-
- public Integer nextInt() {
- if (hasNext()) {
- return Integer.parseInt(next());
- } else {
- return null;
- }
- }
-
- public int nextInt(int defaultValue) {
- if (hasNext()) {
- return Integer.parseInt(next());
- } else {
- return defaultValue;
- }
- }
-
- public Integer nextHexInt() {
- if (hasNext()) {
- return Integer.parseInt(next(), 16);
- } else {
- return null;
- }
- }
-
- public int nextHexInt(int defaultValue) {
- if (hasNext()) {
- return Integer.parseInt(next(), 16);
- } else {
- return defaultValue;
- }
- }
-
- public Integer nextBinInt() {
- if (hasNext()) {
- return Integer.parseInt(next(), 2);
- } else {
- return null;
- }
- }
-
- public int nextBinInt(int defaultValue) {
- if (hasNext()) {
- return Integer.parseInt(next(), 2);
- } else {
- return defaultValue;
- }
- }
-
- public Long nextLong() {
- if (hasNext()) {
- return Long.parseLong(next());
- } else {
- return null;
- }
- }
-
- public Long nextHexLong() {
- if (hasNext()) {
- return Long.parseLong(next(), 16);
- } else {
- return null;
- }
- }
-
- public long nextLong(long defaultValue) {
- return nextLong(10, defaultValue);
- }
-
- public long nextLong(int radix, long defaultValue) {
- if (hasNext()) {
- return Long.parseLong(next(), radix);
- } else {
- return defaultValue;
- }
- }
-
- public Double nextDouble() {
- if (hasNext()) {
- return Double.parseDouble(next());
- } else {
- return null;
- }
- }
-
- public double nextDouble(double defaultValue) {
- if (hasNext()) {
- return Double.parseDouble(next());
- } else {
- return defaultValue;
- }
- }
-
- public enum CoordinateFormat {
- DEG_DEG,
- DEG_HEM,
- DEG_MIN_MIN,
- DEG_MIN_HEM,
- DEG_MIN_MIN_HEM,
- HEM_DEG_MIN_MIN,
- HEM_DEG,
- HEM_DEG_MIN,
- HEM_DEG_MIN_HEM
- }
-
- public double nextCoordinate(CoordinateFormat format) {
- double coordinate;
- String hemisphere = null;
-
- switch (format) {
- case DEG_DEG:
- coordinate = Double.parseDouble(next() + '.' + next());
- break;
- case DEG_HEM:
- coordinate = nextDouble(0);
- hemisphere = next();
- break;
- case DEG_MIN_MIN:
- coordinate = nextInt(0);
- coordinate += Double.parseDouble(next() + '.' + next()) / 60;
- break;
- case DEG_MIN_MIN_HEM:
- coordinate = nextInt(0);
- coordinate += Double.parseDouble(next() + '.' + next()) / 60;
- hemisphere = next();
- break;
- case HEM_DEG:
- hemisphere = next();
- coordinate = nextDouble(0);
- break;
- case HEM_DEG_MIN:
- hemisphere = next();
- coordinate = nextInt(0);
- coordinate += nextDouble(0) / 60;
- break;
- case HEM_DEG_MIN_HEM:
- hemisphere = next();
- coordinate = nextInt(0);
- coordinate += nextDouble(0) / 60;
- if (hasNext()) {
- hemisphere = next();
- }
- break;
- case HEM_DEG_MIN_MIN:
- hemisphere = next();
- coordinate = nextInt(0);
- coordinate += Double.parseDouble(next() + '.' + next()) / 60;
- break;
- case DEG_MIN_HEM:
- default:
- coordinate = nextInt(0);
- coordinate += nextDouble(0) / 60;
- hemisphere = next();
- break;
- }
-
- if (hemisphere != null && (hemisphere.equals("S") || hemisphere.equals("W") || hemisphere.equals("-"))) {
- coordinate = -Math.abs(coordinate);
- }
-
- return coordinate;
- }
-
- public double nextCoordinate() {
- return nextCoordinate(CoordinateFormat.DEG_MIN_HEM);
- }
-
- public enum DateTimeFormat {
- HMS,
- SMH,
- HMS_YMD,
- HMS_DMY,
- SMH_YMD,
- SMH_DMY,
- DMY_HMS,
- DMY_HMSS,
- YMD_HMS,
- YMD_HMSS,
- }
-
- public Date nextDateTime(DateTimeFormat format, String timeZone) {
- int year = 0, month = 0, day = 0;
- int hour = 0, minute = 0, second = 0, millisecond = 0;
-
- switch (format) {
- case HMS:
- hour = nextInt(0);
- minute = nextInt(0);
- second = nextInt(0);
- break;
- case SMH:
- second = nextInt(0);
- minute = nextInt(0);
- hour = nextInt(0);
- break;
- case HMS_YMD:
- hour = nextInt(0);
- minute = nextInt(0);
- second = nextInt(0);
- year = nextInt(0);
- month = nextInt(0);
- day = nextInt(0);
- break;
- case HMS_DMY:
- hour = nextInt(0);
- minute = nextInt(0);
- second = nextInt(0);
- day = nextInt(0);
- month = nextInt(0);
- year = nextInt(0);
- break;
- case SMH_YMD:
- second = nextInt(0);
- minute = nextInt(0);
- hour = nextInt(0);
- year = nextInt(0);
- month = nextInt(0);
- day = nextInt(0);
- break;
- case SMH_DMY:
- second = nextInt(0);
- minute = nextInt(0);
- hour = nextInt(0);
- day = nextInt(0);
- month = nextInt(0);
- year = nextInt(0);
- break;
- case DMY_HMS:
- case DMY_HMSS:
- day = nextInt(0);
- month = nextInt(0);
- year = nextInt(0);
- hour = nextInt(0);
- minute = nextInt(0);
- second = nextInt(0);
- break;
- case YMD_HMS:
- case YMD_HMSS:
- default:
- year = nextInt(0);
- month = nextInt(0);
- day = nextInt(0);
- hour = nextInt(0);
- minute = nextInt(0);
- second = nextInt(0);
- break;
- }
-
- if (format == DateTimeFormat.YMD_HMSS || format == DateTimeFormat.DMY_HMSS) {
- millisecond = nextInt(0); // (ddd)
- }
-
- if (year >= 0 && year < 100) {
- year += 2000;
- }
-
- DateBuilder dateBuilder;
- if (format != DateTimeFormat.HMS && format != DateTimeFormat.SMH) {
- if (timeZone != null) {
- dateBuilder = new DateBuilder(TimeZone.getTimeZone(timeZone));
- } else {
- dateBuilder = new DateBuilder();
- }
- dateBuilder.setDate(year, month, day);
- } else {
- if (timeZone != null) {
- dateBuilder = new DateBuilder(new Date(), TimeZone.getTimeZone(timeZone));
- } else {
- dateBuilder = new DateBuilder(new Date());
- }
- }
-
- dateBuilder.setTime(hour, minute, second, millisecond);
-
- return dateBuilder.getDate();
- }
-
- public Date nextDateTime(DateTimeFormat format) {
- return nextDateTime(format, null);
- }
-
- public Date nextDateTime() {
- return nextDateTime(DateTimeFormat.YMD_HMS, null);
- }
-
-}
diff --git a/src/org/traccar/helper/PatternBuilder.java b/src/org/traccar/helper/PatternBuilder.java
deleted file mode 100644
index f3de5c1e5..000000000
--- a/src/org/traccar/helper/PatternBuilder.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import java.util.ArrayList;
-import java.util.regex.Pattern;
-
-public class PatternBuilder {
-
- private final ArrayList<String> fragments = new ArrayList<>();
-
- public PatternBuilder optional() {
- return optional(1);
- }
-
- public PatternBuilder optional(int count) {
- fragments.add(fragments.size() - count, "(?:");
- fragments.add(")?");
- return this;
- }
-
- public PatternBuilder expression(String s) {
- s = s.replaceAll("\\|$", "\\\\|"); // special case for delimiter
-
- fragments.add(s);
- return this;
- }
-
- public PatternBuilder text(String s) {
- fragments.add(s.replaceAll("([\\\\\\.\\[\\{\\(\\)\\*\\+\\?\\^\\$\\|])", "\\\\$1"));
- return this;
- }
-
- public PatternBuilder number(String s) {
- s = s.replace("dddd", "d{4}").replace("ddd", "d{3}").replace("dd", "d{2}");
- s = s.replace("xxxx", "x{4}").replace("xxx", "x{3}").replace("xx", "x{2}");
-
- s = s.replace("d", "\\d").replace("x", "[0-9a-fA-F]").replaceAll("([\\.])", "\\\\$1");
- s = s.replaceAll("\\|$", "\\\\|").replaceAll("^\\|", "\\\\|"); // special case for delimiter
-
- fragments.add(s);
- return this;
- }
-
- public PatternBuilder any() {
- fragments.add(".*?");
- return this;
- }
-
- public PatternBuilder binary(String s) {
- fragments.add(s.replaceAll("(\\p{XDigit}{2})", "\\\\$1"));
- return this;
- }
-
- public PatternBuilder or() {
- fragments.add("|");
- return this;
- }
-
- public PatternBuilder groupBegin() {
- return expression("(?:");
- }
-
- public PatternBuilder groupEnd() {
- return expression(")");
- }
-
- public PatternBuilder groupEnd(String s) {
- return expression(")" + s);
- }
-
- public Pattern compile() {
- return Pattern.compile(toString(), Pattern.DOTALL);
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- for (String fragment : fragments) {
- builder.append(fragment);
- }
- return builder.toString();
- }
-
-}
diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java
deleted file mode 100644
index 1bbb166a6..000000000
--- a/src/org/traccar/helper/PatternUtil.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.helper;
-
-import java.lang.management.ManagementFactory;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-public final class PatternUtil {
-
- private PatternUtil() {
- }
-
- public static class MatchResult {
- private String patternMatch;
- private String patternTail;
- private String stringMatch;
- private String stringTail;
-
- 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) {
-
- if (!ManagementFactory.getRuntimeMXBean().getInputArguments().toString().contains("-agentlib:jdwp")) {
- throw new RuntimeException("PatternUtil usage detected");
- }
-
- MatchResult result = new MatchResult();
-
- for (int i = 0; i < pattern.length(); i++) {
- try {
- Matcher matcher = Pattern.compile("(" + pattern.substring(0, i) + ").*").matcher(input);
- if (matcher.matches()) {
- result.patternMatch = pattern.substring(0, i);
- result.patternTail = pattern.substring(i);
- result.stringMatch = matcher.group(1);
- result.stringTail = input.substring(matcher.group(1).length());
- }
- } catch (PatternSyntaxException error) {
- Log.warning(error);
- }
- }
-
- return result;
- }
-
-}
diff --git a/src/org/traccar/helper/StringFinder.java b/src/org/traccar/helper/StringFinder.java
deleted file mode 100644
index 2fa0aa9a4..000000000
--- a/src/org/traccar/helper/StringFinder.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferIndexFinder;
-
-import java.nio.charset.StandardCharsets;
-
-public class StringFinder implements ChannelBufferIndexFinder {
-
- private String string;
-
- public StringFinder(String string) {
- this.string = string;
- }
-
- @Override
- public boolean find(ChannelBuffer buffer, int guessedIndex) {
-
- if (buffer.writerIndex() - guessedIndex < string.length()) {
- return false;
- }
-
- return string.equals(buffer.toString(guessedIndex, string.length(), StandardCharsets.US_ASCII));
- }
-
-}
diff --git a/src/org/traccar/helper/UnitsConverter.java b/src/org/traccar/helper/UnitsConverter.java
deleted file mode 100644
index 56d15e4e7..000000000
--- a/src/org/traccar/helper/UnitsConverter.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.
- * 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.helper;
-
-public final class UnitsConverter {
-
- private static final double KNOTS_TO_KPH_RATIO = 0.539957;
- private static final double KNOTS_TO_MPH_RATIO = 0.868976;
- private static final double KNOTS_TO_MPS_RATIO = 1.94384;
- private static final double KNOTS_TO_CPS_RATIO = 0.0194384449;
- private static final double METERS_TO_FEET_RATIO = 0.3048;
- private static final double METERS_TO_MILE_RATIO = 1609.34;
-
- private UnitsConverter() {
- }
-
- public static double knotsFromKph(double value) { // km/h
- return value * KNOTS_TO_KPH_RATIO;
- }
-
- public static double kphFromKnots(double value) {
- return value / KNOTS_TO_KPH_RATIO;
- }
-
- public static double knotsFromMph(double value) {
- return value * KNOTS_TO_MPH_RATIO;
- }
-
- public static double mphFromKnots(double value) {
- return value / KNOTS_TO_MPH_RATIO;
- }
-
- public static double knotsFromMps(double value) { // m/s
- 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;
- }
-
- public static double feetFromMeters(double value) {
- return value / METERS_TO_FEET_RATIO;
- }
-
- public static double metersFromFeet(double value) {
- return value * METERS_TO_FEET_RATIO;
- }
-
- public static double milesFromMeters(double value) {
- return value / METERS_TO_MILE_RATIO;
- }
-
- public static double metersFromMiles(double value) {
- return value * METERS_TO_MILE_RATIO;
- }
-
-}
diff --git a/src/org/traccar/model/Attribute.java b/src/org/traccar/model/Attribute.java
deleted file mode 100644
index 45d40b3ec..000000000
--- a/src/org/traccar/model/Attribute.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 Attribute extends BaseModel {
-
- private String description;
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- private String attribute;
-
- public String getAttribute() {
- return attribute;
- }
-
- public void setAttribute(String attribute) {
- this.attribute = attribute;
- }
-
- private String expression;
-
- public String getExpression() {
- return expression;
- }
-
- public void setExpression(String expression) {
- this.expression = expression;
- }
-
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
-}
diff --git a/src/org/traccar/model/BaseModel.java b/src/org/traccar/model/BaseModel.java
deleted file mode 100644
index 8bdb916e8..000000000
--- a/src/org/traccar/model/BaseModel.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 BaseModel {
-
- private long id;
-
- public final long getId() {
- return id;
- }
-
- public final void setId(long id) {
- this.id = id;
- }
-
-}
diff --git a/src/org/traccar/model/Calendar.java b/src/org/traccar/model/Calendar.java
deleted file mode 100644
index 56d3eb74c..000000000
--- a/src/org/traccar/model/Calendar.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Date;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
-import net.fortuna.ical4j.data.CalendarBuilder;
-import net.fortuna.ical4j.data.ParserException;
-import net.fortuna.ical4j.filter.Filter;
-import net.fortuna.ical4j.filter.PeriodRule;
-import net.fortuna.ical4j.model.DateTime;
-import net.fortuna.ical4j.model.Dur;
-import net.fortuna.ical4j.model.Period;
-import net.fortuna.ical4j.model.component.CalendarComponent;
-import org.apache.commons.collections4.Predicate;
-import org.traccar.database.QueryIgnore;
-
-public class Calendar extends ExtendedModel {
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- private byte[] data;
-
- public byte[] getData() {
- return data.clone();
- }
-
- public void setData(byte[] data) throws IOException, ParserException {
- CalendarBuilder builder = new CalendarBuilder();
- calendar = builder.build(new ByteArrayInputStream(data));
- this.data = data.clone();
- }
-
- private net.fortuna.ical4j.model.Calendar calendar;
-
- @QueryIgnore
- @JsonIgnore
- public net.fortuna.ical4j.model.Calendar getCalendar() {
- return calendar;
- }
-
- public boolean checkMoment(Date date) {
- if (calendar != null) {
- Period period = new Period(new DateTime(date), new Dur(0, 0, 0, 0));
- Predicate<CalendarComponent> periodRule = new PeriodRule<>(period);
- Filter<CalendarComponent> filter = new Filter<>(new Predicate[] {periodRule}, Filter.MATCH_ANY);
- Collection<CalendarComponent> events = filter.filter(calendar.getComponents(CalendarComponent.VEVENT));
- if (events != null && !events.isEmpty()) {
- return true;
- }
- }
- return false;
- }
-
-}
diff --git a/src/org/traccar/model/CellTower.java b/src/org/traccar/model/CellTower.java
deleted file mode 100644
index 6d1dfbd7f..000000000
--- a/src/org/traccar/model/CellTower.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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 com.fasterxml.jackson.annotation.JsonInclude;
-import org.traccar.Context;
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-public class CellTower {
-
- public static CellTower from(int mcc, int mnc, int lac, long cid) {
- CellTower cellTower = new CellTower();
- cellTower.setMobileCountryCode(mcc);
- cellTower.setMobileNetworkCode(mnc);
- cellTower.setLocationAreaCode(lac);
- cellTower.setCellId(cid);
- return cellTower;
- }
-
- public static CellTower from(int mcc, int mnc, int lac, long cid, int rssi) {
- CellTower cellTower = CellTower.from(mcc, mnc, lac, cid);
- cellTower.setSignalStrength(rssi);
- return cellTower;
- }
-
- public static CellTower fromLacCid(int lac, long cid) {
- return from(
- Context.getConfig().getInteger("geolocation.mcc"),
- Context.getConfig().getInteger("geolocation.mnc"), lac, cid);
- }
-
- public static CellTower fromCidLac(long cid, int lac) {
- return fromLacCid(lac, cid);
- }
-
- private String radioType;
-
- public String getRadioType() {
- return radioType;
- }
-
- public void setRadioType(String radioType) {
- this.radioType = radioType;
- }
-
- private Long cellId;
-
- public Long getCellId() {
- return cellId;
- }
-
- public void setCellId(Long cellId) {
- this.cellId = cellId;
- }
-
- private Integer locationAreaCode;
-
- public Integer getLocationAreaCode() {
- return locationAreaCode;
- }
-
- public void setLocationAreaCode(Integer locationAreaCode) {
- this.locationAreaCode = locationAreaCode;
- }
-
- private Integer mobileCountryCode;
-
- public Integer getMobileCountryCode() {
- return mobileCountryCode;
- }
-
- public void setMobileCountryCode(Integer mobileCountryCode) {
- this.mobileCountryCode = mobileCountryCode;
- }
-
- private Integer mobileNetworkCode;
-
- public Integer getMobileNetworkCode() {
- return mobileNetworkCode;
- }
-
- public void setMobileNetworkCode(Integer mobileNetworkCode) {
- this.mobileNetworkCode = mobileNetworkCode;
- }
-
- private Integer signalStrength;
-
- public Integer getSignalStrength() {
- return signalStrength;
- }
-
- public void setSignalStrength(Integer signalStrength) {
- this.signalStrength = signalStrength;
- }
-
- public void setOperator(long operator) {
- String operatorString = String.valueOf(operator);
- mobileCountryCode = Integer.parseInt(operatorString.substring(0, 3));
- mobileNetworkCode = Integer.parseInt(operatorString.substring(3));
- }
-
-}
diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java
deleted file mode 100644
index 16205ede1..000000000
--- a/src/org/traccar/model/Command.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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 org.traccar.database.QueryIgnore;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class Command extends Message implements Cloneable {
-
- public static final String TYPE_CUSTOM = "custom";
- public static final String TYPE_IDENTIFICATION = "deviceIdentification";
- public static final String TYPE_POSITION_SINGLE = "positionSingle";
- public static final String TYPE_POSITION_PERIODIC = "positionPeriodic";
- public static final String TYPE_POSITION_STOP = "positionStop";
- public static final String TYPE_ENGINE_STOP = "engineStop";
- public static final String TYPE_ENGINE_RESUME = "engineResume";
- public static final String TYPE_ALARM_ARM = "alarmArm";
- public static final String TYPE_ALARM_DISARM = "alarmDisarm";
- public static final String TYPE_SET_TIMEZONE = "setTimezone";
- public static final String TYPE_REQUEST_PHOTO = "requestPhoto";
- public static final String TYPE_REBOOT_DEVICE = "rebootDevice";
- public static final String TYPE_SEND_SMS = "sendSms";
- public static final String TYPE_SEND_USSD = "sendUssd";
- public static final String TYPE_SOS_NUMBER = "sosNumber";
- public static final String TYPE_SILENCE_TIME = "silenceTime";
- public static final String TYPE_SET_PHONEBOOK = "setPhonebook";
- public static final String TYPE_VOICE_MESSAGE = "voiceMessage";
- public static final String TYPE_OUTPUT_CONTROL = "outputControl";
- public static final String TYPE_VOICE_MONITORING = "voiceMonitoring";
- public static final String TYPE_SET_AGPS = "setAgps";
- public static final String TYPE_SET_INDICATOR = "setIndicator";
- public static final String TYPE_CONFIGURATION = "configuration";
- public static final String TYPE_GET_VERSION = "getVersion";
- public static final String TYPE_FIRMWARE_UPDATE = "firmwareUpdate";
- public static final String TYPE_SET_CONNECTION = "setConnection";
- public static final String TYPE_SET_ODOMETER = "setOdometer";
- public static final String TYPE_GET_MODEM_STATUS = "getModemStatus";
- public static final String TYPE_GET_DEVICE_STATUS = "getDeviceStatus";
-
- public static final String TYPE_MODE_POWER_SAVING = "modePowerSaving";
- public static final String TYPE_MODE_DEEP_SLEEP = "modeDeepSleep";
-
- public static final String TYPE_ALARM_GEOFENCE = "movementAlarm";
- public static final String TYPE_ALARM_BATTERY = "alarmBattery";
- public static final String TYPE_ALARM_SOS = "alarmSos";
- public static final String TYPE_ALARM_REMOVE = "alarmRemove";
- public static final String TYPE_ALARM_CLOCK = "alarmClock";
- public static final String TYPE_ALARM_SPEED = "alarmSpeed";
- public static final String TYPE_ALARM_FALL = "alarmFall";
- public static final String TYPE_ALARM_VIBRATION = "alarmVibration";
-
- public static final String KEY_UNIQUE_ID = "uniqueId";
- public static final String KEY_FREQUENCY = "frequency";
- public static final String KEY_TIMEZONE = "timezone";
- public static final String KEY_DEVICE_PASSWORD = "devicePassword";
- public static final String KEY_RADIUS = "radius";
- public static final String KEY_MESSAGE = "message";
- public static final String KEY_ENABLE = "enable";
- public static final String KEY_DATA = "data";
- public static final String KEY_INDEX = "index";
- public static final String KEY_PHONE = "phone";
- public static final String KEY_SERVER = "server";
- public static final String KEY_PORT = "port";
-
- @Override
- public Command clone() throws CloneNotSupportedException {
- return (Command) super.clone();
- }
-
- private boolean textChannel;
-
- public boolean getTextChannel() {
- return textChannel;
- }
-
- public void setTextChannel(boolean textChannel) {
- this.textChannel = textChannel;
- }
-
- @QueryIgnore
- @Override
- public long getDeviceId() {
- return super.getDeviceId();
- }
-
- private String description;
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
-}
diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java
deleted file mode 100644
index c8a28404c..000000000
--- a/src/org/traccar/model/Device.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * 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.
- * 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;
-import java.util.List;
-
-import org.traccar.database.QueryExtended;
-import org.traccar.database.QueryIgnore;
-
-public class Device extends ExtendedModel {
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- private String uniqueId;
-
- public String getUniqueId() {
- return uniqueId;
- }
-
- public void setUniqueId(String uniqueId) {
- this.uniqueId = uniqueId;
- }
-
- public static final String STATUS_UNKNOWN = "unknown";
- public static final String STATUS_ONLINE = "online";
- public static final String STATUS_OFFLINE = "offline";
-
- private String status;
-
- @QueryIgnore
- public String getStatus() {
- return status != null ? status : STATUS_OFFLINE;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- private Date lastUpdate;
-
- @QueryExtended
- public Date getLastUpdate() {
- if (lastUpdate != null) {
- return new Date(lastUpdate.getTime());
- } else {
- return null;
- }
- }
-
- public void setLastUpdate(Date lastUpdate) {
- if (lastUpdate != null) {
- this.lastUpdate = new Date(lastUpdate.getTime());
- } else {
- this.lastUpdate = null;
- }
- }
-
- private long positionId;
-
- @QueryIgnore
- public long getPositionId() {
- return positionId;
- }
-
- public void setPositionId(long positionId) {
- this.positionId = positionId;
- }
-
- private long groupId;
-
- public long getGroupId() {
- return groupId;
- }
-
- public void setGroupId(long groupId) {
- this.groupId = groupId;
- }
-
- private List<Long> geofenceIds;
-
- @QueryIgnore
- public List<Long> getGeofenceIds() {
- return geofenceIds;
- }
-
- 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/DeviceState.java b/src/org/traccar/model/DeviceState.java
deleted file mode 100644
index f2d0ff614..000000000
--- a/src/org/traccar/model/DeviceState.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 DeviceState {
-
- private Boolean motionState;
-
- public void setMotionState(boolean motionState) {
- this.motionState = motionState;
- }
-
- public Boolean getMotionState() {
- return motionState;
- }
-
- private Position motionPosition;
-
- public void setMotionPosition(Position motionPosition) {
- this.motionPosition = motionPosition;
- }
-
- public Position getMotionPosition() {
- return motionPosition;
- }
-
- private Boolean overspeedState;
-
- public void setOverspeedState(boolean overspeedState) {
- this.overspeedState = overspeedState;
- }
-
- public Boolean getOverspeedState() {
- return overspeedState;
- }
-
- private Position overspeedPosition;
-
- public void setOverspeedPosition(Position overspeedPosition) {
- this.overspeedPosition = overspeedPosition;
- }
-
- public Position getOverspeedPosition() {
- return overspeedPosition;
- }
-
-}
diff --git a/src/org/traccar/model/DeviceTotalDistance.java b/src/org/traccar/model/DeviceTotalDistance.java
deleted file mode 100644
index 4c89b7689..000000000
--- a/src/org/traccar/model/DeviceTotalDistance.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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/Driver.java b/src/org/traccar/model/Driver.java
deleted file mode 100644
index 05f52fd4d..000000000
--- a/src/org/traccar/model/Driver.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 Driver extends ExtendedModel {
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- private String uniqueId;
-
- public String getUniqueId() {
- return uniqueId;
- }
-
- public void setUniqueId(String uniqueId) {
- this.uniqueId = uniqueId;
- }
-}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
deleted file mode 100644
index 47b60af01..000000000
--- a/src/org/traccar/model/Event.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 Event extends Message {
-
- public Event(String type, long deviceId, long positionId) {
- this(type, deviceId);
- setPositionId(positionId);
- }
-
- public Event(String type, long deviceId) {
- setType(type);
- setDeviceId(deviceId);
- this.serverTime = new Date();
- }
-
- 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";
- public static final String TYPE_DEVICE_STOPPED = "deviceStopped";
-
- public static final String TYPE_DEVICE_OVERSPEED = "deviceOverspeed";
- public static final String TYPE_DEVICE_FUEL_DROP = "deviceFuelDrop";
-
- public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter";
- public static final String TYPE_GEOFENCE_EXIT = "geofenceExit";
-
- public static final String TYPE_ALARM = "alarm";
-
- public static final String TYPE_IGNITION_ON = "ignitionOn";
- public static final String TYPE_IGNITION_OFF = "ignitionOff";
-
- public static final String TYPE_MAINTENANCE = "maintenance";
-
- public static final String TYPE_TEXT_MESSAGE = "textMessage";
-
- public static final String TYPE_DRIVER_CHANGED = "driverChanged";
-
- private Date serverTime;
-
- public Date getServerTime() {
- if (serverTime != null) {
- return new Date(serverTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setServerTime(Date serverTime) {
- if (serverTime != null) {
- this.serverTime = new Date(serverTime.getTime());
- } else {
- this.serverTime = null;
- }
- }
-
- private long positionId;
-
- public long getPositionId() {
- return positionId;
- }
-
- public void setPositionId(long positionId) {
- this.positionId = positionId;
- }
-
- private long geofenceId = 0;
-
- public long getGeofenceId() {
- return geofenceId;
- }
-
- public void setGeofenceId(long geofenceId) {
- this.geofenceId = geofenceId;
- }
-
-}
diff --git a/src/org/traccar/model/ExtendedModel.java b/src/org/traccar/model/ExtendedModel.java
deleted file mode 100644
index 8353d0e66..000000000
--- a/src/org/traccar/model/ExtendedModel.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.LinkedHashMap;
-import java.util.Map;
-
-public class ExtendedModel extends BaseModel {
-
- private Map<String, Object> attributes = new LinkedHashMap<>();
-
- public Map<String, Object> getAttributes() {
- return attributes;
- }
-
- public void setAttributes(Map<String, Object> attributes) {
- this.attributes = attributes;
- }
-
- public void set(String key, Boolean value) {
- if (value != null) {
- attributes.put(key, value);
- }
- }
-
- public void set(String key, Byte value) {
- if (value != null) {
- attributes.put(key, value.intValue());
- }
- }
-
- public void set(String key, Short value) {
- if (value != null) {
- attributes.put(key, value.intValue());
- }
- }
-
- public void set(String key, Integer value) {
- if (value != null) {
- attributes.put(key, value);
- }
- }
-
- public void set(String key, Long value) {
- if (value != null) {
- attributes.put(key, value);
- }
- }
-
- public void set(String key, Float value) {
- if (value != null) {
- attributes.put(key, value.doubleValue());
- }
- }
-
- public void set(String key, Double value) {
- if (value != null) {
- attributes.put(key, value);
- }
- }
-
- public void set(String key, String value) {
- if (value != null && !value.isEmpty()) {
- attributes.put(key, value);
- }
- }
-
- public void add(Map.Entry<String, Object> entry) {
- if (entry != null && entry.getValue() != null) {
- attributes.put(entry.getKey(), entry.getValue());
- }
- }
-
- public String getString(String key) {
- if (attributes.containsKey(key)) {
- return (String) attributes.get(key);
- } else {
- return null;
- }
- }
-
- public double getDouble(String key) {
- if (attributes.containsKey(key)) {
- return ((Number) attributes.get(key)).doubleValue();
- } else {
- return 0.0;
- }
- }
-
- public boolean getBoolean(String key) {
- if (attributes.containsKey(key)) {
- return (Boolean) attributes.get(key);
- } else {
- return false;
- }
- }
-
- public int getInteger(String key) {
- if (attributes.containsKey(key)) {
- return ((Number) attributes.get(key)).intValue();
- } else {
- return 0;
- }
- }
-
- public long getLong(String key) {
- if (attributes.containsKey(key)) {
- return ((Number) attributes.get(key)).longValue();
- } else {
- return 0;
- }
- }
-
-}
diff --git a/src/org/traccar/model/Geofence.java b/src/org/traccar/model/Geofence.java
deleted file mode 100644
index 21c196da9..000000000
--- a/src/org/traccar/model/Geofence.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.text.ParseException;
-
-import org.traccar.Context;
-import org.traccar.database.QueryIgnore;
-import org.traccar.geofence.GeofenceCircle;
-import org.traccar.geofence.GeofenceGeometry;
-import org.traccar.geofence.GeofencePolygon;
-import org.traccar.geofence.GeofencePolyline;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-
-public class Geofence extends ExtendedModel {
-
- public static final String TYPE_GEOFENCE_CILCLE = "geofenceCircle";
- public static final String TYPE_GEOFENCE_POLYGON = "geofencePolygon";
- public static final String TYPE_GEOFENCE_POLYLINE = "geofencePolyline";
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- private String description;
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- private String area;
-
- public String getArea() {
- return area;
- }
-
- public void setArea(String area) throws ParseException {
-
- if (area.startsWith("CIRCLE")) {
- geometry = new GeofenceCircle(area);
- } else if (area.startsWith("POLYGON")) {
- geometry = new GeofencePolygon(area);
- } else if (area.startsWith("LINESTRING")) {
- geometry = new GeofencePolyline(area, Context.getConfig().getDouble("geofence.polylineDistance", 25));
- } else {
- throw new ParseException("Unknown geometry type", 0);
- }
-
- this.area = area;
- }
-
- private GeofenceGeometry geometry;
-
- @QueryIgnore
- @JsonIgnore
- public GeofenceGeometry getGeometry() {
- return geometry;
- }
-
- @QueryIgnore
- @JsonIgnore
- public void setGeometry(GeofenceGeometry geometry) {
- area = geometry.toWkt();
- this.geometry = geometry;
- }
-
- private long calendarId;
-
- public long getCalendarId() {
- return calendarId;
- }
-
- public void setCalendarId(long calendarId) {
- this.calendarId = calendarId;
- }
-}
diff --git a/src/org/traccar/model/Group.java b/src/org/traccar/model/Group.java
deleted file mode 100644
index aad206aad..000000000
--- a/src/org/traccar/model/Group.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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;
-
-public class Group extends ExtendedModel {
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- private long groupId;
-
- public long getGroupId() {
- return groupId;
- }
-
- public void setGroupId(long groupId) {
- this.groupId = groupId;
- }
-
-}
diff --git a/src/org/traccar/model/ManagedUser.java b/src/org/traccar/model/ManagedUser.java
deleted file mode 100644
index 03c5ef48d..000000000
--- a/src/org/traccar/model/ManagedUser.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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 ManagedUser extends User {
-
-}
diff --git a/src/org/traccar/model/Message.java b/src/org/traccar/model/Message.java
deleted file mode 100644
index dad9c20f0..000000000
--- a/src/org/traccar/model/Message.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.
- * 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 Message extends ExtendedModel {
-
- private long deviceId;
-
- public long getDeviceId() {
- return deviceId;
- }
-
- public void setDeviceId(long deviceId) {
- this.deviceId = deviceId;
- }
-
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
-}
diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java
deleted file mode 100644
index c6511f063..000000000
--- a/src/org/traccar/model/MiscFormatter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.text.DecimalFormat;
-import java.util.Map;
-
-public final class MiscFormatter {
-
- private MiscFormatter() {
- }
-
- private static final String XML_ROOT_NODE = "info";
-
- private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#.##");
-
- private static String format(Object value) {
- if (value instanceof Double || value instanceof Float) {
- return DECIMAL_FORMAT.format(value);
- } else {
- return value.toString();
- }
- }
-
- public static String toXmlString(Map<String, Object> attributes) {
- StringBuilder result = new StringBuilder();
-
- result.append("<").append(XML_ROOT_NODE).append(">");
-
- for (Map.Entry<String, Object> entry : attributes.entrySet()) {
-
- result.append("<").append(entry.getKey()).append(">");
- result.append(format(entry.getValue()));
- result.append("</").append(entry.getKey()).append(">");
- }
-
- result.append("</").append(XML_ROOT_NODE).append(">");
-
- return result.toString();
- }
-
-}
diff --git a/src/org/traccar/model/Network.java b/src/org/traccar/model/Network.java
deleted file mode 100644
index 2d56950f1..000000000
--- a/src/org/traccar/model/Network.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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 com.fasterxml.jackson.annotation.JsonInclude;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-public class Network {
-
- public Network() {
- }
-
- public Network(CellTower cellTower) {
- addCellTower(cellTower);
- }
-
- private Integer homeMobileCountryCode;
-
- public Integer getHomeMobileCountryCode() {
- return homeMobileCountryCode;
- }
-
- public void setHomeMobileCountryCode(Integer homeMobileCountryCode) {
- this.homeMobileCountryCode = homeMobileCountryCode;
- }
-
- private Integer homeMobileNetworkCode;
-
- public Integer getHomeMobileNetworkCode() {
- return homeMobileNetworkCode;
- }
-
- public void setHomeMobileNetworkCode(Integer homeMobileNetworkCode) {
- this.homeMobileNetworkCode = homeMobileNetworkCode;
- }
-
- private String radioType = "gsm";
-
- public String getRadioType() {
- return radioType;
- }
-
- public void setRadioType(String radioType) {
- this.radioType = radioType;
- }
-
- private String carrier;
-
- public String getCarrier() {
- return carrier;
- }
-
- public void setCarrier(String carrier) {
- this.carrier = carrier;
- }
-
- private Boolean considerIp = false;
-
- public Boolean getConsiderIp() {
- return considerIp;
- }
-
- public void setConsiderIp(Boolean considerIp) {
- this.considerIp = considerIp;
- }
-
- private Collection<CellTower> cellTowers;
-
- public Collection<CellTower> getCellTowers() {
- return cellTowers;
- }
-
- public void setCellTowers(Collection<CellTower> cellTowers) {
- this.cellTowers = cellTowers;
- }
-
- public void addCellTower(CellTower cellTower) {
- if (cellTowers == null) {
- cellTowers = new ArrayList<>();
- }
- cellTowers.add(cellTower);
- }
-
- private Collection<WifiAccessPoint> wifiAccessPoints;
-
- public Collection<WifiAccessPoint> getWifiAccessPoints() {
- return wifiAccessPoints;
- }
-
- public void setWifiAccessPoints(Collection<WifiAccessPoint> wifiAccessPoints) {
- this.wifiAccessPoints = wifiAccessPoints;
- }
-
- public void addWifiAccessPoint(WifiAccessPoint wifiAccessPoint) {
- if (wifiAccessPoints == null) {
- wifiAccessPoints = new ArrayList<>();
- }
- wifiAccessPoints.add(wifiAccessPoint);
- }
-
-}
diff --git a/src/org/traccar/model/Notification.java b/src/org/traccar/model/Notification.java
deleted file mode 100644
index 9d6034fff..000000000
--- a/src/org/traccar/model/Notification.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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;
-
-public class Notification extends ExtendedModel {
-
- private boolean always;
-
- public boolean getAlways() {
- return always;
- }
-
- public void setAlways(boolean always) {
- this.always = always;
- }
-
- private String type;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- private boolean web;
-
- public boolean getWeb() {
- return web;
- }
-
- public void setWeb(boolean web) {
- this.web = web;
- }
-
- private boolean mail;
-
- public boolean getMail() {
- return mail;
- }
-
- public void setMail(boolean mail) {
- this.mail = mail;
- }
-
- private boolean sms;
-
- public boolean getSms() {
- return sms;
- }
-
- public void setSms(boolean sms) {
- this.sms = sms;
- }
-}
diff --git a/src/org/traccar/model/Permission.java b/src/org/traccar/model/Permission.java
deleted file mode 100644
index 1006b1c47..000000000
--- a/src/org/traccar/model/Permission.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.traccar.database.DataManager;
-
-public class Permission {
-
- private Class<?> ownerClass;
- private long ownerId;
- private Class<?> propertyClass;
- private long propertyId;
-
- public Permission(LinkedHashMap<String, Long> permissionMap) throws ClassNotFoundException {
- Iterator<Map.Entry<String, Long>> iterator = permissionMap.entrySet().iterator();
- String owner = iterator.next().getKey();
- ownerClass = DataManager.getClassByName(owner);
- String property = iterator.next().getKey();
- propertyClass = DataManager.getClassByName(property);
- ownerId = permissionMap.get(owner);
- propertyId = permissionMap.get(property);
- }
-
- public Class<?> getOwnerClass() {
- return ownerClass;
- }
-
- public long getOwnerId() {
- return ownerId;
- }
-
- public Class<?> getPropertyClass() {
- return propertyClass;
- }
-
- public long getPropertyId() {
- return propertyId;
- }
-}
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
deleted file mode 100644
index 099e6d686..000000000
--- a/src/org/traccar/model/Position.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*
- * 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.
- * 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;
-
-import org.traccar.database.QueryIgnore;
-
-public class Position extends Message {
-
- public static final String KEY_ORIGINAL = "raw";
- public static final String KEY_INDEX = "index";
- public static final String KEY_HDOP = "hdop";
- public static final String KEY_VDOP = "vdop";
- public static final String KEY_PDOP = "pdop";
- public static final String KEY_SATELLITES = "sat"; // in use
- public static final String KEY_SATELLITES_VISIBLE = "satVisible";
- public static final String KEY_RSSI = "rssi";
- public static final String KEY_GPS = "gps";
- public static final String KEY_ROAMING = "roaming";
- public static final String KEY_EVENT = "event";
- public static final String KEY_ALARM = "alarm";
- public static final String KEY_STATUS = "status";
- public static final String KEY_ODOMETER = "odometer"; // meters
- public static final String KEY_ODOMETER_SERVICE = "serviceOdometer"; // meters
- public static final String KEY_ODOMETER_TRIP = "tripOdometer"; // meters
- public static final String KEY_HOURS = "hours";
- public static final String KEY_STEPS = "steps";
- public static final String KEY_INPUT = "input";
- public static final String KEY_OUTPUT = "output";
- public static final String KEY_IMAGE = "image";
- public static final String KEY_VIDEO = "video";
- public static final String KEY_AUDIO = "audio";
-
- // The units for the below four KEYs currently vary.
- // The preferred units of measure are specified in the comment for each.
- public static final String KEY_POWER = "power"; // volts
- public static final String KEY_BATTERY = "battery"; // volts
- public static final String KEY_BATTERY_LEVEL = "batteryLevel"; // percentage
- public static final String KEY_FUEL_LEVEL = "fuel"; // liters
- public static final String KEY_FUEL_CONSUMPTION = "fuelConsumption"; // liters/hour
-
- public static final String KEY_VERSION_FW = "versionFw";
- public static final String KEY_VERSION_HW = "versionHw";
- public static final String KEY_TYPE = "type";
- public static final String KEY_IGNITION = "ignition";
- public static final String KEY_FLAGS = "flags";
- public static final String KEY_CHARGE = "charge";
- public static final String KEY_IP = "ip";
- public static final String KEY_ARCHIVE = "archive";
- public static final String KEY_DISTANCE = "distance"; // meters
- public static final String KEY_TOTAL_DISTANCE = "totalDistance"; // meters
- public static final String KEY_RPM = "rpm";
- public static final String KEY_VIN = "vin";
- public static final String KEY_APPROXIMATE = "approximate";
- public static final String KEY_THROTTLE = "throttle";
- public static final String KEY_MOTION = "motion";
- public static final String KEY_ARMED = "armed";
- public static final String KEY_GEOFENCE = "geofence";
- public static final String KEY_ACCELERATION = "acceleration";
- public static final String KEY_DEVICE_TEMP = "deviceTemp"; // celsius
- public static final String KEY_COOLANT_TEMP = "coolantTemp"; // celsius
- public static final String KEY_ENGINE_LOAD = "engineLoad";
- public static final String KEY_OPERATOR = "operator";
- public static final String KEY_COMMAND = "command";
- public static final String KEY_BLOCKED = "blocked";
- public static final String KEY_DOOR = "door";
-
- public static final String KEY_DTCS = "dtcs";
- public static final String KEY_OBD_SPEED = "obdSpeed"; // knots
- public static final String KEY_OBD_ODOMETER = "obdOdometer"; // meters
-
- public static final String KEY_RESULT = "result";
-
- public static final String KEY_DRIVER_UNIQUE_ID = "driverUniqueId";
-
- // Start with 1 not 0
- public static final String PREFIX_TEMP = "temp";
- public static final String PREFIX_ADC = "adc";
- public static final String PREFIX_IO = "io";
- public static final String PREFIX_COUNT = "count";
- public static final String PREFIX_IN = "in";
- public static final String PREFIX_OUT = "out";
-
- public static final String ALARM_GENERAL = "general";
- public static final String ALARM_SOS = "sos";
- public static final String ALARM_VIBRATION = "vibration";
- public static final String ALARM_MOVEMENT = "movement";
- public static final String ALARM_LOW_SPEED = "lowspeed";
- public static final String ALARM_OVERSPEED = "overspeed";
- public static final String ALARM_FALL_DOWN = "fallDown";
- public static final String ALARM_LOW_POWER = "lowPower";
- 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";
- public static final String ALARM_GPS_ANTENNA_CUT = "gpsAntennaCut";
- public static final String ALARM_ACCIDENT = "accident";
- public static final String ALARM_TOW = "tow";
- public static final String ALARM_ACCELERATION = "hardAcceleration";
- public static final String ALARM_BRAKING = "hardBraking";
- public static final String ALARM_CORNERING = "hardCornering";
- public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving";
- public static final String ALARM_POWER_CUT = "powerCut";
- public static final String ALARM_POWER_RESTORED = "powerRestored";
- public static final String ALARM_JAMMING = "jamming";
- public static final String ALARM_TEMPERATURE = "temperature";
- public static final String ALARM_PARKING = "parking";
- public static final String ALARM_SHOCK = "shock";
- public static final String ALARM_BONNET = "bonnet";
- public static final String ALARM_FOOT_BRAKE = "footBrake";
- public static final String ALARM_OIL_LEAK = "oilLeak";
- public static final String ALARM_TAMPERING = "tampering";
- public static final String ALARM_REMOVING = "removing";
-
- private String protocol;
-
- public String getProtocol() {
- return protocol;
- }
-
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
-
- private Date serverTime;
-
- public Date getServerTime() {
- if (serverTime != null) {
- return new Date(serverTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setServerTime(Date serverTime) {
- if (serverTime != null) {
- this.serverTime = new Date(serverTime.getTime());
- } else {
- this.serverTime = null;
- }
- }
-
- private Date deviceTime;
-
- public Date getDeviceTime() {
- if (deviceTime != null) {
- return new Date(deviceTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setDeviceTime(Date deviceTime) {
- if (deviceTime != null) {
- this.deviceTime = new Date(deviceTime.getTime());
- } else {
- this.deviceTime = null;
- }
- }
-
- private Date fixTime;
-
- public Date getFixTime() {
- if (fixTime != null) {
- return new Date(fixTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setFixTime(Date fixTime) {
- if (fixTime != null) {
- this.fixTime = new Date(fixTime.getTime());
- } else {
- this.fixTime = null;
- }
- }
-
- public void setTime(Date time) {
- setDeviceTime(time);
- setFixTime(time);
- }
-
- private boolean outdated;
-
- @QueryIgnore
- public boolean getOutdated() {
- return outdated;
- }
-
- public void setOutdated(boolean outdated) {
- this.outdated = outdated;
- }
-
- private boolean valid;
-
- public boolean getValid() {
- return valid;
- }
-
- public void setValid(boolean valid) {
- this.valid = valid;
- }
-
- private double latitude;
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- private double longitude;
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
-
- private double altitude; // value in meters
-
- public double getAltitude() {
- return altitude;
- }
-
- public void setAltitude(double altitude) {
- this.altitude = altitude;
- }
-
- private double speed; // value in knots
-
- public double getSpeed() {
- return speed;
- }
-
- public void setSpeed(double speed) {
- this.speed = speed;
- }
-
- private double course;
-
- public double getCourse() {
- return course;
- }
-
- public void setCourse(double course) {
- this.course = course;
- }
-
- private String address;
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- private double accuracy;
-
- public double getAccuracy() {
- return accuracy;
- }
-
- public void setAccuracy(double accuracy) {
- this.accuracy = accuracy;
- }
-
- private Network network;
-
- public Network getNetwork() {
- return network;
- }
-
- public void setNetwork(Network network) {
- this.network = network;
- }
-
- @Override
- @QueryIgnore
- public String getType() {
- return super.getType();
- }
-
-}
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
deleted file mode 100644
index 072e85d55..000000000
--- a/src/org/traccar/model/Server.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.
- * 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 org.traccar.database.QueryIgnore;
-import org.traccar.helper.Log;
-
-public class Server extends ExtendedModel {
-
- @QueryIgnore
- public String getVersion() {
- return Log.getAppVersion();
- }
-
- public void setVersion(String version) {
- }
-
- private boolean registration;
-
- public boolean getRegistration() {
- return registration;
- }
-
- public void setRegistration(boolean registration) {
- this.registration = registration;
- }
-
- private boolean readonly;
-
- public boolean getReadonly() {
- return readonly;
- }
-
- public void setReadonly(boolean readonly) {
- this.readonly = readonly;
- }
-
- private boolean deviceReadonly;
-
- public boolean getDeviceReadonly() {
- return deviceReadonly;
- }
-
- public void setDeviceReadonly(boolean deviceReadonly) {
- this.deviceReadonly = deviceReadonly;
- }
-
- private String map;
-
- public String getMap() {
- return map;
- }
-
- public void setMap(String map) {
- this.map = map;
- }
-
- private String bingKey;
-
- public String getBingKey() {
- return bingKey;
- }
-
- public void setBingKey(String bingKey) {
- this.bingKey = bingKey;
- }
-
- private String mapUrl;
-
- public String getMapUrl() {
- return mapUrl;
- }
-
- public void setMapUrl(String mapUrl) {
- this.mapUrl = mapUrl;
- }
-
- private double latitude;
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- private double longitude;
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
-
- private int zoom;
-
- public int getZoom() {
- return zoom;
- }
-
- public void setZoom(int zoom) {
- this.zoom = zoom;
- }
-
- private boolean twelveHourFormat;
-
- public boolean getTwelveHourFormat() {
- return twelveHourFormat;
- }
-
- public void setTwelveHourFormat(boolean twelveHourFormat) {
- 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;
- }
-
- private boolean limitCommands;
-
- public boolean getLimitCommands() {
- return limitCommands;
- }
-
- public void setLimitCommands(boolean limitCommands) {
- this.limitCommands = limitCommands;
- }
-}
diff --git a/src/org/traccar/model/Statistics.java b/src/org/traccar/model/Statistics.java
deleted file mode 100644
index 2acf8514f..000000000
--- a/src/org/traccar/model/Statistics.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 ExtendedModel {
-
- 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;
- }
-
- private int mailSent;
-
- public int getMailSent() {
- return mailSent;
- }
-
- public void setMailSent(int mailSent) {
- this.mailSent = mailSent;
- }
-
- private int smsSent;
-
- public int getSmsSent() {
- return smsSent;
- }
-
- public void setSmsSent(int smsSent) {
- this.smsSent = smsSent;
- }
-
- private int geocoderRequests;
-
- public int getGeocoderRequests() {
- return geocoderRequests;
- }
-
- public void setGeocoderRequests(int geocoderRequests) {
- this.geocoderRequests = geocoderRequests;
- }
-
- private int geolocationRequests;
-
- public int getGeolocationRequests() {
- return geolocationRequests;
- }
-
- public void setGeolocationRequests(int geolocationRequests) {
- this.geolocationRequests = geolocationRequests;
- }
-
-}
diff --git a/src/org/traccar/model/Typed.java b/src/org/traccar/model/Typed.java
deleted file mode 100644
index 313ec7bcd..000000000
--- a/src/org/traccar/model/Typed.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@gmail.com)
- *
- * 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 Typed {
-
- private String type;
-
- public Typed(String type) {
- this.type = type;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-}
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
deleted file mode 100644
index 5d89dcfae..000000000
--- a/src/org/traccar/model/User.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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 com.fasterxml.jackson.annotation.JsonIgnore;
-
-import org.traccar.database.QueryExtended;
-import org.traccar.database.QueryIgnore;
-import org.traccar.helper.Hashing;
-
-import java.util.Date;
-
-public class User extends ExtendedModel {
-
- private String name;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- private String email;
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email.trim();
- }
-
- private String phone;
-
- public String getPhone() {
- return phone;
- }
-
- public void setPhone(String phone) {
- this.phone = phone;
- }
-
- private boolean readonly;
-
- public boolean getReadonly() {
- return readonly;
- }
-
- public void setReadonly(boolean readonly) {
- this.readonly = readonly;
- }
-
- private boolean admin;
-
- public boolean getAdmin() {
- return admin;
- }
-
- public void setAdmin(boolean admin) {
- this.admin = admin;
- }
-
- private String map;
-
- public String getMap() {
- return map;
- }
-
- public void setMap(String map) {
- this.map = map;
- }
-
- private double latitude;
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- private double longitude;
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
-
- private int zoom;
-
- public int getZoom() {
- return zoom;
- }
-
- public void setZoom(int zoom) {
- this.zoom = zoom;
- }
-
- private boolean twelveHourFormat;
-
- public boolean getTwelveHourFormat() {
- return twelveHourFormat;
- }
-
- public void setTwelveHourFormat(boolean twelveHourFormat) {
- this.twelveHourFormat = twelveHourFormat;
- }
-
- 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 int userLimit;
-
- public int getUserLimit() {
- return userLimit;
- }
-
- public void setUserLimit(int userLimit) {
- this.userLimit = userLimit;
- }
-
- private boolean deviceReadonly;
-
- public boolean getDeviceReadonly() {
- return deviceReadonly;
- }
-
- public void setDeviceReadonly(boolean deviceReadonly) {
- this.deviceReadonly = deviceReadonly;
- }
-
- 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;
- }
- }
-
- private boolean limitCommands;
-
- public boolean getLimitCommands() {
- return limitCommands;
- }
-
- public void setLimitCommands(boolean limitCommands) {
- this.limitCommands = limitCommands;
- }
-
- @QueryIgnore
- public String getPassword() {
- return null;
- }
-
- public void setPassword(String password) {
- if (password != null && !password.isEmpty()) {
- Hashing.HashingResult hashingResult = Hashing.createHash(password);
- hashedPassword = hashingResult.getHash();
- salt = hashingResult.getSalt();
- }
- }
-
- private String hashedPassword;
-
- @JsonIgnore
- @QueryExtended
- public String getHashedPassword() {
- return hashedPassword;
- }
-
- public void setHashedPassword(String hashedPassword) {
- this.hashedPassword = hashedPassword;
- }
-
- private String salt;
-
- @JsonIgnore
- @QueryExtended
- public String getSalt() {
- return salt;
- }
-
- public void setSalt(String salt) {
- this.salt = salt;
- }
-
- public boolean isPasswordValid(String password) {
- return Hashing.validatePassword(password, hashedPassword, salt);
- }
-
-}
diff --git a/src/org/traccar/model/WifiAccessPoint.java b/src/org/traccar/model/WifiAccessPoint.java
deleted file mode 100644
index 87a77f3c0..000000000
--- a/src/org/traccar/model/WifiAccessPoint.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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 com.fasterxml.jackson.annotation.JsonInclude;
-
-@JsonInclude(JsonInclude.Include.NON_NULL)
-public class WifiAccessPoint {
-
- public static WifiAccessPoint from(String macAddress, int signalStrength) {
- WifiAccessPoint wifiAccessPoint = new WifiAccessPoint();
- wifiAccessPoint.setMacAddress(macAddress);
- wifiAccessPoint.setSignalStrength(signalStrength);
- return wifiAccessPoint;
- }
-
- public static WifiAccessPoint from(String macAddress, int signalStrength, int channel) {
- WifiAccessPoint wifiAccessPoint = from(macAddress, signalStrength);
- wifiAccessPoint.setChannel(channel);
- return wifiAccessPoint;
- }
-
- private String macAddress;
-
- public String getMacAddress() {
- return macAddress;
- }
-
- public void setMacAddress(String macAddress) {
- this.macAddress = macAddress;
- }
-
- private Integer signalStrength;
-
- public Integer getSignalStrength() {
- return signalStrength;
- }
-
- public void setSignalStrength(Integer signalStrength) {
- this.signalStrength = signalStrength;
- }
-
- private Integer channel;
-
- public Integer getChannel() {
- return channel;
- }
-
- public void setChannel(Integer channel) {
- this.channel = channel;
- }
-
-}
diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java
deleted file mode 100644
index ac37f980c..000000000
--- a/src/org/traccar/notification/EventForwarder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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 com.fasterxml.jackson.core.JsonProcessingException;
-import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Geofence;
-import org.traccar.model.Position;
-
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class EventForwarder {
-
- private String url;
- private String header;
-
- public EventForwarder() {
- url = Context.getConfig().getString("event.forward.url", "http://localhost/");
- header = Context.getConfig().getString("event.forward.header", "");
- }
-
- private static final String KEY_POSITION = "position";
- private static final String KEY_EVENT = "event";
- private static final String KEY_GEOFENCE = "geofence";
- private static final String KEY_DEVICE = "device";
-
- public void forwardEvent(Event event, Position position) {
-
- BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url);
-
- requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8");
- if (!header.equals("")) {
- String[] headerLines = header.split("\\r?\\n");
- for (String headerLine: headerLines) {
- String[] splitedLine = headerLine.split(":", 2);
- if (splitedLine.length == 2) {
- requestBuilder.setHeader(splitedLine[0].trim(), splitedLine[1].trim());
- }
- }
- }
-
- requestBuilder.setBody(preparePayload(event, position));
- requestBuilder.execute();
- }
-
- private byte[] preparePayload(Event event, Position position) {
- Map<String, Object> data = new HashMap<>();
- data.put(KEY_EVENT, event);
- if (position != null) {
- data.put(KEY_POSITION, position);
- }
- if (event.getDeviceId() != 0) {
- Device device = Context.getIdentityManager().getById(event.getDeviceId());
- if (device != null) {
- data.put(KEY_DEVICE, device);
- }
- }
- if (event.getGeofenceId() != 0) {
- Geofence geofence = (Geofence) Context.getGeofenceManager().getById(event.getGeofenceId());
- if (geofence != null) {
- data.put(KEY_GEOFENCE, geofence);
- }
- }
- try {
- return Context.getObjectMapper().writeValueAsString(data).getBytes(StandardCharsets.UTF_8);
- } catch (JsonProcessingException e) {
- Log.warning(e);
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/notification/MailMessage.java b/src/org/traccar/notification/MailMessage.java
deleted file mode 100644
index 0fce43740..000000000
--- a/src/org/traccar/notification/MailMessage.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.notification;
-
-public class MailMessage {
-
- private String subject;
- private String body;
-
- public MailMessage(String subject, String body) {
- this.subject = subject;
- this.body = body;
- }
-
- public String getSubject() {
- return subject;
- }
-
- public String getBody() {
- return body;
- }
-}
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
deleted file mode 100644
index 8da819430..000000000
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.notification;
-
-import java.io.StringWriter;
-import java.nio.charset.StandardCharsets;
-import java.util.Locale;
-
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.velocity.tools.generic.DateTool;
-import org.apache.velocity.tools.generic.NumberTool;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-import org.traccar.model.User;
-import org.traccar.reports.ReportUtils;
-
-public final class NotificationFormatter {
-
- private NotificationFormatter() {
- }
-
- public static VelocityContext prepareContext(long userId, Event event, Position position) {
- User user = Context.getPermissionsManager().getUser(userId);
- Device device = Context.getIdentityManager().getById(event.getDeviceId());
-
- VelocityContext velocityContext = new VelocityContext();
- velocityContext.put("user", user);
- velocityContext.put("device", device);
- velocityContext.put("event", event);
- if (position != null) {
- velocityContext.put("position", position);
- velocityContext.put("speedUnit", ReportUtils.getSpeedUnit(userId));
- velocityContext.put("distanceUnit", ReportUtils.getDistanceUnit(userId));
- velocityContext.put("volumeUnit", ReportUtils.getVolumeUnit(userId));
- }
- if (event.getGeofenceId() != 0) {
- velocityContext.put("geofence", Context.getGeofenceManager().getById(event.getGeofenceId()));
- }
- String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID);
- if (driverUniqueId != null) {
- velocityContext.put("driver", Context.getDriversManager().getDriverByUniqueId(driverUniqueId));
- }
- velocityContext.put("webUrl", Context.getVelocityEngine().getProperty("web.url"));
- velocityContext.put("dateTool", new DateTool());
- velocityContext.put("numberTool", new NumberTool());
- velocityContext.put("timezone", ReportUtils.getTimezone(userId));
- velocityContext.put("locale", Locale.getDefault());
- return velocityContext;
- }
-
- public static Template getTemplate(Event event, String path) {
- Template template;
- try {
- template = Context.getVelocityEngine().getTemplate(path + event.getType() + ".vm",
- StandardCharsets.UTF_8.name());
- } catch (ResourceNotFoundException error) {
- Log.warning(error);
- template = Context.getVelocityEngine().getTemplate(path + "unknown.vm",
- StandardCharsets.UTF_8.name());
- }
- return template;
- }
-
- public static MailMessage formatMailMessage(long userId, Event event, Position position) {
- VelocityContext velocityContext = prepareContext(userId, event, position);
- StringWriter writer = new StringWriter();
- getTemplate(event, Context.getConfig().getString("mail.templatesPath", "mail") + "/")
- .merge(velocityContext, writer);
- return new MailMessage((String) velocityContext.get("subject"), writer.toString());
- }
-
- public static String formatSmsMessage(long userId, Event event, Position position) {
- VelocityContext velocityContext = prepareContext(userId, event, position);
- StringWriter writer = new StringWriter();
- getTemplate(event, Context.getConfig().getString("sms.templatesPath", "sms") + "/")
- .merge(velocityContext, writer);
- return writer.toString();
- }
-}
diff --git a/src/org/traccar/notification/NotificationMail.java b/src/org/traccar/notification/NotificationMail.java
deleted file mode 100644
index 8707b10da..000000000
--- a/src/org/traccar/notification/NotificationMail.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.notification;
-
-import java.util.Properties;
-
-import javax.mail.Message;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import java.util.Date;
-
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-import org.traccar.model.User;
-
-public final class NotificationMail {
-
- private NotificationMail() {
- }
-
- private static Properties getProperties(PropertiesProvider provider) {
- Properties properties = new Properties();
- String host = provider.getString("mail.smtp.host");
- if (host != null) {
- properties.put("mail.transport.protocol", provider.getString("mail.transport.protocol", "smtp"));
- properties.put("mail.smtp.host", host);
- properties.put("mail.smtp.port", String.valueOf(provider.getInteger("mail.smtp.port", 25)));
-
- String starttlsEnable = provider.getString("mail.smtp.starttls.enable");
- if (starttlsEnable != null) {
- properties.put("mail.smtp.starttls.enable", Boolean.parseBoolean(starttlsEnable));
- }
- String starttlsRequired = provider.getString("mail.smtp.starttls.required");
- if (starttlsRequired != null) {
- properties.put("mail.smtp.starttls.required", Boolean.parseBoolean(starttlsRequired));
- }
-
- String sslEnable = provider.getString("mail.smtp.ssl.enable");
- if (sslEnable != null) {
- properties.put("mail.smtp.ssl.enable", Boolean.parseBoolean(sslEnable));
- }
- String sslTrust = provider.getString("mail.smtp.ssl.trust");
- if (sslTrust != null) {
- properties.put("mail.smtp.ssl.trust", sslTrust);
- }
-
- String sslProtocols = provider.getString("mail.smtp.ssl.protocols");
- if (sslProtocols != null) {
- properties.put("mail.smtp.ssl.protocols", sslProtocols);
- }
-
- String username = provider.getString("mail.smtp.username");
- if (username != null) {
- properties.put("mail.smtp.username", username);
- }
- String password = provider.getString("mail.smtp.password");
- if (password != null) {
- properties.put("mail.smtp.password", password);
- }
- String from = provider.getString("mail.smtp.from");
- if (from != null) {
- properties.put("mail.smtp.from", from);
- }
- }
- return properties;
- }
-
- public static void sendMailSync(long userId, Event event, Position position) throws MessagingException {
- User user = Context.getPermissionsManager().getUser(userId);
-
- Properties properties = null;
- if (!Context.getConfig().getBoolean("mail.smtp.ignoreUserConfig")) {
- properties = getProperties(new PropertiesProvider(user));
- }
- if (properties == null || !properties.containsKey("mail.smtp.host")) {
- properties = getProperties(new PropertiesProvider(Context.getConfig()));
- }
- if (!properties.containsKey("mail.smtp.host")) {
- Log.warning("No SMTP configuration found");
- return;
- }
-
- Session session = Session.getInstance(properties);
-
- MimeMessage message = new MimeMessage(session);
-
- String from = properties.getProperty("mail.smtp.from");
- if (from != null) {
- message.setFrom(new InternetAddress(from));
- }
-
- message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
- MailMessage mailMessage = NotificationFormatter.formatMailMessage(userId, event, position);
- message.setSubject(mailMessage.getSubject());
- message.setSentDate(new Date());
- message.setContent(mailMessage.getBody(), "text/html; charset=utf-8");
-
- Transport transport = session.getTransport();
- try {
- Context.getStatisticsManager().registerMail();
- 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();
- }
- }
-
- public static void sendMailAsync(final long userId, final Event event, final Position position) {
- new Thread(new Runnable() {
- public void run() {
- try {
- sendMailSync(userId, event, position);
- } catch (MessagingException error) {
- Log.warning(error);
- }
- }
- }).start();
- }
-
-}
diff --git a/src/org/traccar/notification/NotificationSms.java b/src/org/traccar/notification/NotificationSms.java
deleted file mode 100644
index 8c0265af4..000000000
--- a/src/org/traccar/notification/NotificationSms.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.notification;
-
-import org.traccar.Context;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-import org.traccar.model.User;
-
-import com.cloudhopper.smpp.type.RecoverablePduException;
-import com.cloudhopper.smpp.type.SmppChannelException;
-import com.cloudhopper.smpp.type.SmppTimeoutException;
-import com.cloudhopper.smpp.type.UnrecoverablePduException;
-
-public final class NotificationSms {
-
- private NotificationSms() {
- }
-
- public static void sendSmsAsync(long userId, Event event, Position position) {
- User user = Context.getPermissionsManager().getUser(userId);
- if (Context.getSmppManager() != null && user.getPhone() != null) {
- Context.getStatisticsManager().registerSms();
- Context.getSmppManager().sendMessageAsync(user.getPhone(),
- NotificationFormatter.formatSmsMessage(userId, event, position), false);
- }
- }
-
- public static void sendSmsSync(long userId, Event event, Position position) throws RecoverablePduException,
- UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException {
- User user = Context.getPermissionsManager().getUser(userId);
- if (Context.getSmppManager() != null && user.getPhone() != null) {
- Context.getStatisticsManager().registerSms();
- Context.getSmppManager().sendMessageSync(user.getPhone(),
- NotificationFormatter.formatSmsMessage(userId, event, position), false);
- }
- }
-}
diff --git a/src/org/traccar/notification/PropertiesProvider.java b/src/org/traccar/notification/PropertiesProvider.java
deleted file mode 100644
index c5ba688e8..000000000
--- a/src/org/traccar/notification/PropertiesProvider.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.ExtendedModel;
-
-public class PropertiesProvider {
-
- private Config config;
-
- private ExtendedModel extendedModel;
-
- public PropertiesProvider(Config config) {
- this.config = config;
- }
-
- public PropertiesProvider(ExtendedModel extendedModel) {
- this.extendedModel = extendedModel;
- }
-
- public String getString(String key) {
- if (config != null) {
- return config.getString(key);
- } else {
- return extendedModel.getString(key);
- }
- }
-
- public String getString(String key, String defaultValue) {
- String value = getString(key);
- if (value == null) {
- value = defaultValue;
- }
- return value;
- }
-
- public int getInteger(String key, int defaultValue) {
- if (config != null) {
- return config.getInteger(key, defaultValue);
- } else {
- Object result = extendedModel.getAttributes().get(key);
- if (result != null) {
- return result instanceof String ? Integer.parseInt((String) result) : (Integer) result;
- } else {
- return defaultValue;
- }
- }
- }
-
-}
diff --git a/src/org/traccar/processing/ComputedAttributesHandler.java b/src/org/traccar/processing/ComputedAttributesHandler.java
deleted file mode 100644
index 1e702d17f..000000000
--- a/src/org/traccar/processing/ComputedAttributesHandler.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.processing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.jexl2.JexlEngine;
-import org.apache.commons.jexl2.JexlException;
-import org.apache.commons.jexl2.MapContext;
-import org.traccar.BaseDataHandler;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-import org.traccar.model.Attribute;
-import org.traccar.model.Device;
-import org.traccar.model.Position;
-
-public class ComputedAttributesHandler extends BaseDataHandler {
-
- private JexlEngine engine;
-
- private boolean mapDeviceAttributes;
-
- public ComputedAttributesHandler() {
- engine = new JexlEngine();
- engine.setStrict(true);
- engine.setFunctions(Collections.singletonMap("math", (Object) Math.class));
- if (Context.getConfig() != null) {
- mapDeviceAttributes = Context.getConfig().getBoolean("processing.computedAttributes.deviceAttributes");
- }
- }
-
- private MapContext prepareContext(Position position) {
- MapContext result = new MapContext();
- if (mapDeviceAttributes) {
- Device device = Context.getIdentityManager().getById(position.getDeviceId());
- if (device != null) {
- for (Object key : device.getAttributes().keySet()) {
- result.set((String) key, device.getAttributes().get(key));
- }
- }
- }
- Set<Method> methods = new HashSet<>(Arrays.asList(position.getClass().getMethods()));
- methods.removeAll(Arrays.asList(Object.class.getMethods()));
- for (Method method : methods) {
- if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
- String name = Character.toLowerCase(method.getName().charAt(3)) + method.getName().substring(4);
-
- try {
- if (!method.getReturnType().equals(Map.class)) {
- result.set(name, method.invoke(position));
- } else {
- for (Object key : ((Map) method.invoke(position)).keySet()) {
- result.set((String) key, ((Map) method.invoke(position)).get(key));
- }
- }
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- }
- return result;
- }
-
- public Object computeAttribute(Attribute attribute, Position position) throws JexlException {
- return engine.createExpression(attribute.getExpression()).evaluate(prepareContext(position));
- }
-
- @Override
- protected Position handlePosition(Position position) {
- Collection<Attribute> attributes = Context.getAttributesManager().getItems(
- Context.getAttributesManager().getAllDeviceItems(position.getDeviceId()));
- for (Attribute attribute : attributes) {
- if (attribute.getAttribute() != null) {
- Object result = null;
- try {
- result = computeAttribute(attribute, position);
- } catch (JexlException error) {
- Log.warning(error);
- }
- if (result != null) {
- try {
- switch (attribute.getType()) {
- case "number":
- position.getAttributes().put(attribute.getAttribute(), (Number) result);
- break;
- case "boolean":
- position.getAttributes().put(attribute.getAttribute(), (Boolean) result);
- break;
- default:
- position.getAttributes().put(attribute.getAttribute(), result.toString());
- }
- } catch (ClassCastException error) {
- Log.warning(error);
- }
- }
- }
- }
- return position;
- }
-
-}
diff --git a/src/org/traccar/processing/CopyAttributesHandler.java b/src/org/traccar/processing/CopyAttributesHandler.java
deleted file mode 100644
index 9fbcfa73f..000000000
--- a/src/org/traccar/processing/CopyAttributesHandler.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 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.processing;
-
-import org.traccar.BaseDataHandler;
-import org.traccar.Context;
-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().lookupAttributeString(
- position.getDeviceId(), "processing.copyAttributes", "", true);
- Position last = getLastPosition(position.getDeviceId());
- if (attributesString.isEmpty()) {
- attributesString = Position.KEY_DRIVER_UNIQUE_ID;
- } else {
- attributesString += "," + Position.KEY_DRIVER_UNIQUE_ID;
- }
- if (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/protocol/AdmProtocol.java b/src/org/traccar/protocol/AdmProtocol.java
deleted file mode 100644
index 4d2cbe7b3..000000000
--- a/src/org/traccar/protocol/AdmProtocol.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.LengthFieldBasedFrameDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class AdmProtocol extends BaseProtocol {
-
- public AdmProtocol() {
- super("adm");
- setSupportedDataCommands(
- Command.TYPE_GET_DEVICE_STATUS,
- Command.TYPE_CUSTOM);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 1, -3, 0));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new AdmProtocolEncoder());
- pipeline.addLast("objectDecoder", new AdmProtocolDecoder(AdmProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/AdmProtocolDecoder.java b/src/org/traccar/protocol/AdmProtocolDecoder.java
deleted file mode 100644
index f93c55e18..000000000
--- a/src/org/traccar/protocol/AdmProtocolDecoder.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-public class AdmProtocolDecoder extends BaseProtocolDecoder {
-
- public AdmProtocolDecoder(AdmProtocol protocol) {
- super(protocol);
- }
-
- public static final int CMD_RESPONSE_SIZE = 0x84;
- public static final int MSG_IMEI = 0x03;
- public static final int MSG_PHOTO = 0x0A;
- public static final int MSG_ADM5 = 0x01;
-
- private Position decodeData(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int type) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- if (BitUtil.to(type, 2) == 0) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
-
- int status = buf.readUnsignedShort();
- position.set(Position.KEY_STATUS, status);
- position.setValid(!BitUtil.check(status, 5));
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- position.setCourse(buf.readUnsignedShort() * 0.1);
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
-
- position.set(Position.KEY_ACCELERATION, buf.readUnsignedByte() * 0.1);
- position.setAltitude(buf.readUnsignedShort());
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte() & 0x0f);
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
-
- if (BitUtil.check(type, 2)) {
- buf.readUnsignedByte(); // vib
- buf.readUnsignedByte(); // vib_count
-
- int out = buf.readUnsignedByte();
- for (int i = 0; i <= 3; i++) {
- position.set(Position.PREFIX_OUT + (i + 1), BitUtil.check(out, i) ? 1 : 0);
- }
-
- buf.readUnsignedByte(); // in_alarm
- }
-
- if (BitUtil.check(type, 3)) {
- for (int i = 1; i <= 6; i++) {
- position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort() * 0.001);
- }
- }
-
- if (BitUtil.check(type, 4)) {
- for (int i = 1; i <= 2; i++) {
- position.set(Position.PREFIX_COUNT + i, buf.readUnsignedInt());
- }
- }
-
- if (BitUtil.check(type, 5)) {
- for (int i = 1; i <= 3; i++) {
- buf.readUnsignedShort(); // fuel level
- }
- for (int i = 1; i <= 3; i++) {
- position.set(Position.PREFIX_TEMP + i, buf.readUnsignedByte());
- }
- }
-
- if (BitUtil.check(type, 6)) {
- buf.skipBytes(buf.getUnsignedByte(buf.readerIndex()));
- }
-
- if (BitUtil.check(type, 7)) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- return position;
- }
-
- return null;
- }
-
- private Position parseCommandResponse(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- int responseTextLength = buf.bytesBefore((byte) 0);
- if (responseTextLength < 0) {
- responseTextLength = CMD_RESPONSE_SIZE - 3;
- }
- position.set(Position.KEY_RESULT, buf.readBytes(responseTextLength).toString(StandardCharsets.UTF_8));
-
- return position;
- }
-
- @Override
- protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedShort(); // device id
-
- int size = buf.readUnsignedByte();
- if (size != CMD_RESPONSE_SIZE) {
- int type = buf.readUnsignedByte();
- if (type == MSG_IMEI) {
- getDeviceSession(channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.UTF_8));
- } else {
- return decodeData(channel, remoteAddress, buf, type);
- }
- } else {
- return parseCommandResponse(channel, remoteAddress, buf);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AdmProtocolEncoder.java b/src/org/traccar/protocol/AdmProtocolEncoder.java
deleted file mode 100644
index 8cbd8618d..000000000
--- a/src/org/traccar/protocol/AdmProtocolEncoder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Anatoliy Golubev (darth.naihil@gmail.com)
- *
- * 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 AdmProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_GET_DEVICE_STATUS:
- return formatCommand(command, "STATUS\r\n");
-
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "{%s}\r\n", Command.KEY_DATA);
-
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-}
diff --git a/src/org/traccar/protocol/AisProtocol.java b/src/org/traccar/protocol/AisProtocol.java
deleted file mode 100644
index 4b2e1719e..000000000
--- a/src/org/traccar/protocol/AisProtocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.jboss.netty.handler.codec.string.StringDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class AisProtocol extends BaseProtocol {
-
- public AisProtocol() {
- super("ais");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new AisProtocolDecoder(AisProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AisProtocolDecoder.java b/src/org/traccar/protocol/AisProtocolDecoder.java
deleted file mode 100644
index 1f7a12595..000000000
--- a/src/org/traccar/protocol/AisProtocolDecoder.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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.BitBuffer;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-public class AisProtocolDecoder extends BaseProtocolDecoder {
-
- public AisProtocolDecoder(AisProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("!AIVDM,")
- .number("(d+),") // count
- .number("(d+),") // index
- .number("(d+)?,") // id
- .expression(".,") // radio channel
- .expression("([^,]+),") // payload
- .any()
- .compile();
-
- private Position decodePayload(Channel channel, SocketAddress remoteAddress, BitBuffer buf) {
-
- int type = buf.readUnsigned(6);
- if (type == 1 || type == 2 || type == 3 || type == 18) {
-
- buf.readUnsigned(2);
- int mmsi = buf.readUnsigned(30);
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(mmsi));
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date());
-
- if (type == 18) {
- buf.readUnsigned(8); // reserved
- } else {
- position.set(Position.KEY_STATUS, buf.readUnsigned(4));
- position.set("turn", buf.readSigned(8));
- }
-
- position.setSpeed(buf.readUnsigned(10) * 0.1);
- position.setValid(buf.readUnsigned(1) != 0);
- position.setLongitude(buf.readSigned(28) * 0.0001 / 60.0);
- position.setLatitude(buf.readSigned(27) * 0.0001 / 60.0);
- position.setCourse(buf.readUnsigned(12) * 0.1);
-
- position.set("heading", buf.readUnsigned(9));
-
- return position;
-
- }
-
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String[] sentences = ((String) msg).split("\\r\\n");
-
- List<Position> positions = new ArrayList<>();
- Map<Integer, BitBuffer> buffers = new HashMap<>();
-
- for (String sentence : sentences) {
- if (!sentence.isEmpty()) {
- Parser parser = new Parser(PATTERN, sentence);
- if (parser.matches()) {
-
- int count = parser.nextInt(0);
- int index = parser.nextInt(0);
- int id = parser.nextInt(0);
-
- Position position = null;
-
- if (count == 1) {
- BitBuffer bits = new BitBuffer();
- bits.writeEncoded(parser.next().getBytes(StandardCharsets.US_ASCII));
- position = decodePayload(channel, remoteAddress, bits);
- } else {
- BitBuffer bits = buffers.get(id);
- if (bits == null) {
- bits = new BitBuffer();
- buffers.put(id, bits);
- }
- bits.writeEncoded(parser.next().getBytes(StandardCharsets.US_ASCII));
- if (count == index) {
- position = decodePayload(channel, remoteAddress, bits);
- buffers.remove(id);
- }
- }
-
- if (position != null) {
- positions.add(position);
- }
-
- }
- }
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/AlematicsFrameDecoder.java b/src/org/traccar/protocol/AlematicsFrameDecoder.java
deleted file mode 100644
index b8b3e3403..000000000
--- a/src/org/traccar/protocol/AlematicsFrameDecoder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
-
-public class AlematicsFrameDecoder extends LineBasedFrameDecoder {
-
- private static final int MESSAGE_MINIMUM_LENGTH = 2;
-
- public AlematicsFrameDecoder(int maxFrameLength) {
- super(maxFrameLength);
- }
-
- // example of heartbeat: FA F8 00 07 00 03 15 AD 4E 78 3A D2
-
- @Override
- protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
- return null;
- }
-
- if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
- ChannelBuffer heartbeat = buf.readBytes(12);
- if (channel != null) {
- channel.write(heartbeat);
- }
- }
-
- return super.decode(ctx, channel, buf);
- }
-
-}
diff --git a/src/org/traccar/protocol/AlematicsProtocol.java b/src/org/traccar/protocol/AlematicsProtocol.java
deleted file mode 100644
index 241ce8bf9..000000000
--- a/src/org/traccar/protocol/AlematicsProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.TrackerServer;
-
-import java.util.List;
-
-public class AlematicsProtocol extends BaseProtocol {
-
- public AlematicsProtocol() {
- super("alematics");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new AlematicsFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new AlematicsProtocolDecoder(AlematicsProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AlematicsProtocolDecoder.java b/src/org/traccar/protocol/AlematicsProtocolDecoder.java
deleted file mode 100644
index da0704242..000000000
--- a/src/org/traccar/protocol/AlematicsProtocolDecoder.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.BitUtil;
-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 AlematicsProtocolDecoder extends BaseProtocolDecoder {
-
- public AlematicsProtocolDecoder(AlematicsProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$T,")
- .number("(d+),") // type
- .number("(d+),") // index
- .number("(d+),") // id
- .number("(dddd)(dd)(dd)") // gps date
- .number("(dd)(dd)(dd),") // gps time
- .number("(dddd)(dd)(dd)") // device date
- .number("(dd)(dd)(dd),") // device time
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(-?d+),") // altitude
- .number("(d+.d),") // hdop
- .number("(d+),") // satellites
- .number("(d+),") // input
- .number("(d+),") // output
- .number("(d+.d+),") // adc
- .number("(d+.d+),") // power
- .number("(d+),") // odometer
- .groupBegin()
- .text("0,$S,")
- .expression("(.*)") // text message
- .or()
- .number("(d+),") // extra mask
- .expression("(.*)") // extra data
- .groupEnd()
- .compile();
-
- private void decodeExtras(Position position, Parser parser) {
-
- int mask = parser.nextInt();
- String[] data = parser.next().split(",");
-
- int index = 0;
-
- if (BitUtil.check(mask, 0)) {
- index++; // pulse counter 3
- }
-
- if (BitUtil.check(mask, 1)) {
- position.set(Position.KEY_POWER, Integer.parseInt(data[index++]));
- }
-
- if (BitUtil.check(mask, 2)) {
- position.set(Position.KEY_BATTERY, Integer.parseInt(data[index++]));
- }
-
- if (BitUtil.check(mask, 3)) {
- position.set(Position.KEY_OBD_SPEED, Integer.parseInt(data[index++]));
- }
-
- if (BitUtil.check(mask, 4)) {
- position.set(Position.KEY_RPM, Integer.parseInt(data[index++]));
- }
-
- if (BitUtil.check(mask, 5)) {
- position.set(Position.KEY_RSSI, Integer.parseInt(data[index++]));
- }
-
- if (BitUtil.check(mask, 6)) {
- index++; // pulse counter 2
- }
-
- if (BitUtil.check(mask, 7)) {
- index++; // magnetic rotation sensor rpm
- }
-
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Parser parser = new Parser(PATTERN, (String) msg);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_TYPE, parser.nextInt());
- position.set(Position.KEY_INDEX, parser.nextInt());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setFixTime(parser.nextDateTime());
- position.setDeviceTime(parser.nextDateTime());
-
- position.setValid(true);
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
- position.setAltitude(parser.nextInt(0));
-
- position.set(Position.KEY_HDOP, parser.nextDouble());
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_INPUT, parser.nextInt());
- position.set(Position.KEY_OUTPUT, parser.nextInt());
- position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
- position.set(Position.KEY_POWER, parser.nextDouble());
- position.set(Position.KEY_ODOMETER, parser.nextInt());
-
- if (parser.hasNext()) {
- position.set("text", parser.next());
- } else {
- decodeExtras(position, parser);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/ApelProtocol.java b/src/org/traccar/protocol/ApelProtocol.java
deleted file mode 100644
index 690b5ed99..000000000
--- a/src/org/traccar/protocol/ApelProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class ApelProtocol extends BaseProtocol {
-
- public ApelProtocol() {
- super("apel");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0));
- pipeline.addLast("objectDecoder", new ApelProtocolDecoder(ApelProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
deleted file mode 100644
index 6e16e02be..000000000
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class ApelProtocolDecoder extends BaseProtocolDecoder {
-
- private long lastIndex;
- private long newIndex;
-
- public ApelProtocolDecoder(ApelProtocol protocol) {
- super(protocol);
- }
-
- public static final short MSG_NULL = 0;
- public static final short MSG_REQUEST_TRACKER_ID = 10;
- public static final short MSG_TRACKER_ID = 11;
- public static final short MSG_TRACKER_ID_EXT = 12;
- public static final short MSG_DISCONNECT = 20;
- public static final short MSG_REQUEST_PASSWORD = 30;
- public static final short MSG_PASSWORD = 31;
- public static final short MSG_REQUEST_STATE_FULL_INFO = 90;
- public static final short MSG_STATE_FULL_INFO_T104 = 92;
- public static final short MSG_REQUEST_CURRENT_GPS_DATA = 100;
- public static final short MSG_CURRENT_GPS_DATA = 101;
- public static final short MSG_REQUEST_SENSORS_STATE = 110;
- public static final short MSG_SENSORS_STATE = 111;
- public static final short MSG_SENSORS_STATE_T100 = 112;
- public static final short MSG_SENSORS_STATE_T100_4 = 113;
- public static final short MSG_REQUEST_LAST_LOG_INDEX = 120;
- public static final short MSG_LAST_LOG_INDEX = 121;
- public static final short MSG_REQUEST_LOG_RECORDS = 130;
- public static final short MSG_LOG_RECORDS = 131;
- public static final short MSG_EVENT = 141;
- public static final short MSG_TEXT = 150;
- public static final short MSG_ACK_ALARM = 160;
- public static final short MSG_SET_TRACKER_MODE = 170;
- public static final short MSG_GPRS_COMMAND = 180;
-
- private void sendSimpleMessage(Channel channel, short type) {
- ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 8);
- request.writeShort(type);
- request.writeShort(0);
- request.writeInt(Checksum.crc32(request.toByteBuffer(0, 4)));
- channel.write(request);
- }
-
- private void requestArchive(Channel channel) {
- if (lastIndex == 0) {
- lastIndex = newIndex;
- } else if (newIndex > lastIndex) {
- ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 14);
- request.writeShort(MSG_REQUEST_LOG_RECORDS);
- request.writeShort(6);
- request.writeInt((int) lastIndex);
- request.writeShort(512);
- request.writeInt(Checksum.crc32(request.toByteBuffer(0, 10)));
- channel.write(request);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
- int type = buf.readUnsignedShort();
- boolean alarm = (type & 0x8000) != 0;
- type = type & 0x7FFF;
- buf.readUnsignedShort(); // length
-
- if (alarm) {
- sendSimpleMessage(channel, MSG_ACK_ALARM);
- }
-
- if (type == MSG_TRACKER_ID) {
- return null; // unsupported authentication type
- }
-
- if (type == MSG_TRACKER_ID_EXT) {
-
- buf.readUnsignedInt(); // id
- int length = buf.readUnsignedShort();
- buf.skipBytes(length);
- length = buf.readUnsignedShort();
- getDeviceSession(channel, remoteAddress, buf.readBytes(length).toString(StandardCharsets.US_ASCII));
-
- } else if (type == MSG_LAST_LOG_INDEX) {
-
- long index = buf.readUnsignedInt();
- if (index > 0) {
- newIndex = index;
- requestArchive(channel);
- }
-
- } else if (type == MSG_CURRENT_GPS_DATA || type == MSG_STATE_FULL_INFO_T104 || type == MSG_LOG_RECORDS) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- int recordCount = 1;
- if (type == MSG_LOG_RECORDS) {
- recordCount = buf.readUnsignedShort();
- }
-
- for (int j = 0; j < recordCount; j++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- int subtype = type;
- if (type == MSG_LOG_RECORDS) {
- position.set(Position.KEY_ARCHIVE, true);
- lastIndex = buf.readUnsignedInt() + 1;
- position.set(Position.KEY_INDEX, lastIndex);
-
- subtype = buf.readUnsignedShort();
- if (subtype != MSG_CURRENT_GPS_DATA && subtype != MSG_STATE_FULL_INFO_T104) {
- buf.skipBytes(buf.readUnsignedShort());
- continue;
- }
- buf.readUnsignedShort(); // length
- }
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- position.setLatitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
- position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
-
- if (subtype == MSG_STATE_FULL_INFO_T104) {
- int speed = buf.readUnsignedByte();
- position.setValid(speed != 255);
- position.setSpeed(UnitsConverter.knotsFromKph(speed));
- position.set(Position.KEY_HDOP, buf.readByte());
- } else {
- int speed = buf.readShort();
- position.setValid(speed != -1);
- position.setSpeed(UnitsConverter.knotsFromKph(speed * 0.01));
- }
-
- position.setCourse(buf.readShort() * 0.01);
- position.setAltitude(buf.readShort());
-
- if (subtype == MSG_STATE_FULL_INFO_T104) {
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- position.set(Position.KEY_EVENT, buf.readUnsignedShort());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
-
- for (int i = 1; i <= 8; i++) {
- position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
- }
-
- position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
- position.set(Position.PREFIX_COUNT + 2, buf.readUnsignedInt());
- position.set(Position.PREFIX_COUNT + 3, buf.readUnsignedInt());
- }
-
- positions.add(position);
- }
-
- buf.readUnsignedInt(); // crc
-
- if (type == MSG_LOG_RECORDS) {
- requestArchive(channel);
- } else {
- sendSimpleMessage(channel, MSG_REQUEST_LAST_LOG_INDEX);
- }
-
- return positions;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AplicomFrameDecoder.java b/src/org/traccar/protocol/AplicomFrameDecoder.java
deleted file mode 100644
index 24d55f1cf..000000000
--- a/src/org/traccar/protocol/AplicomFrameDecoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class AplicomFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- // Skip Alive message
- while (buf.readable() && Character.isDigit(buf.getByte(buf.readerIndex()))) {
- buf.readByte();
- }
-
- // Check minimum length
- if (buf.readableBytes() < 11) {
- return null;
- }
-
- // Read flags
- int version = buf.getUnsignedByte(buf.readerIndex() + 1);
- int offset = 1 + 1 + 3;
- if ((version & 0x80) != 0) {
- offset += 4;
- }
-
- // Get data length
- int length = buf.getUnsignedShort(buf.readerIndex() + offset);
- offset += 2;
- if ((version & 0x40) != 0) {
- offset += 3;
- }
- length += offset; // add header
-
- // Return buffer
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AplicomProtocol.java b/src/org/traccar/protocol/AplicomProtocol.java
deleted file mode 100644
index 80f6f528f..000000000
--- a/src/org/traccar/protocol/AplicomProtocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class AplicomProtocol extends BaseProtocol {
-
- public AplicomProtocol() {
- super("aplicom");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new AplicomFrameDecoder());
- pipeline.addLast("objectDecoder", new AplicomProtocolDecoder(AplicomProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
deleted file mode 100644
index 154451b5b..000000000
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ /dev/null
@@ -1,638 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Date;
-
-public class AplicomProtocolDecoder extends BaseProtocolDecoder {
-
- public AplicomProtocolDecoder(AplicomProtocol protocol) {
- super(protocol);
- }
-
- private static final long IMEI_BASE_TC65_V20 = 0x1437207000000L;
- private static final long IMEI_BASE_TC65_V28 = 358244010000000L;
- private static final long IMEI_BASE_TC65I_V11 = 0x14143B4000000L;
-
- private static boolean validateImei(long imei) {
- return Checksum.luhn(imei / 10) == imei % 10;
- }
-
- private static long imeiFromUnitId(long unitId) {
-
- if (unitId == 0) {
-
- return 0;
-
- } else {
-
- // Try TC65i
- long imei = IMEI_BASE_TC65I_V11 + unitId;
- if (validateImei(imei)) {
- return imei;
- }
-
- // Try TC65 v2.8
- imei = IMEI_BASE_TC65_V28 + ((unitId + 0xA8180) & 0xFFFFFF);
- if (validateImei(imei)) {
- return imei;
- }
-
- // Try TC65 v2.0
- imei = IMEI_BASE_TC65_V20 + unitId;
- if (validateImei(imei)) {
- return imei;
- }
-
- }
-
- return unitId;
- }
-
- private static final int DEFAULT_SELECTOR_D = 0x0002fC;
- private static final int DEFAULT_SELECTOR_E = 0x007ffc;
- private static final int DEFAULT_SELECTOR_F = 0x0007fd;
-
- private static final int EVENT_DATA = 119;
-
- private void decodeEventData(Position position, ChannelBuffer buf, int event) {
- switch (event) {
- case 2:
- case 40:
- buf.readUnsignedByte();
- break;
- case 9:
- buf.readUnsignedMedium();
- break;
- case 31:
- case 32:
- buf.readUnsignedShort();
- break;
- case 38:
- buf.skipBytes(4 * 9);
- break;
- case 113:
- buf.readUnsignedInt();
- buf.readUnsignedByte();
- break;
- case 121:
- case 142:
- buf.readLong();
- break;
- case 130:
- buf.readUnsignedInt(); // incorrect
- break;
- case 188:
- decodeEB(position, buf);
- break;
- default:
- break;
- }
- }
-
- private void decodeCanData(ChannelBuffer buf, Position position) {
-
- buf.readUnsignedMedium(); // packet identifier
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
- int count = buf.readUnsignedByte();
- buf.readUnsignedByte(); // batch count
- buf.readUnsignedShort(); // selector bit
- buf.readUnsignedInt(); // timestamp
-
- buf.skipBytes(8);
-
- ArrayList<ChannelBuffer> values = new ArrayList<>(count);
-
- for (int i = 0; i < count; i++) {
- values.add(buf.readBytes(8));
- }
-
- for (int i = 0; i < count; i++) {
- ChannelBuffer value = values.get(i);
- switch (buf.readInt()) {
- case 0x20D:
- position.set(Position.KEY_RPM, ChannelBuffers.swapShort(value.readShort()));
- position.set("dieselTemperature", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- position.set("batteryVoltage", ChannelBuffers.swapShort(value.readShort()) * 0.01);
- position.set("supplyAirTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- break;
- case 0x30D:
- position.set("activeAlarm", ChannelBuffers.hexDump(value));
- break;
- case 0x40C:
- position.set("airTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- position.set("airTempDep2", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- break;
- case 0x40D:
- position.set("coldUnitState", ChannelBuffers.hexDump(value));
- break;
- case 0x50C:
- position.set("defrostTempDep1", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- position.set("defrostTempDep2", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- break;
- case 0x50D:
- position.set("condenserPressure", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- position.set("suctionPressure", ChannelBuffers.swapShort(value.readShort()) * 0.1);
- break;
- case 0x58C:
- value.readByte();
- value.readShort(); // index
- switch (value.readByte()) {
- case 0x01:
- position.set("setpointZone1", ChannelBuffers.swapInt(value.readInt()) * 0.1);
- break;
- case 0x02:
- position.set("setpointZone2", ChannelBuffers.swapInt(value.readInt()) * 0.1);
- break;
- case 0x05:
- position.set("unitType", ChannelBuffers.swapInt(value.readInt()));
- break;
- case 0x13:
- position.set("dieselHours", ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
- break;
- case 0x14:
- position.set("electricHours", ChannelBuffers.swapInt(value.readInt()) / 60 / 60);
- break;
- case 0x17:
- position.set("serviceIndicator", ChannelBuffers.swapInt(value.readInt()));
- break;
- case 0x18:
- position.set("softwareVersion", ChannelBuffers.swapInt(value.readInt()) * 0.01);
- break;
- default:
- break;
- }
- break;
- default:
- Log.warning(new UnsupportedOperationException());
- break;
- }
- }
- }
-
- private void decodeD(Position position, ChannelBuffer buf, int selector, int event) {
-
- if ((selector & 0x0008) != 0) {
- position.setValid((buf.readUnsignedByte() & 0x40) != 0);
- } else {
- getLastLocation(position, null);
- }
-
- if ((selector & 0x0004) != 0) {
- buf.skipBytes(4); // snapshot time
- }
-
- if ((selector & 0x0008) != 0) {
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
- }
-
- if ((selector & 0x0010) != 0) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.set("maximumSpeed", buf.readUnsignedByte());
- position.setCourse(buf.readUnsignedByte() * 2.0);
- }
-
- if ((selector & 0x0040) != 0) {
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- }
-
- if ((selector & 0x0020) != 0) {
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort());
- }
-
- if ((selector & 0x8000) != 0) {
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- }
-
- // Pulse rate 1
- if ((selector & 0x10000) != 0) {
- buf.readUnsignedShort();
- buf.readUnsignedInt();
- }
-
- // Pulse rate 2
- if ((selector & 0x20000) != 0) {
- buf.readUnsignedShort();
- buf.readUnsignedInt();
- }
-
- if ((selector & 0x0080) != 0) {
- position.set("trip1", buf.readUnsignedInt());
- }
-
- if ((selector & 0x0100) != 0) {
- position.set("trip2", buf.readUnsignedInt());
- }
-
- if ((selector & 0x0040) != 0) {
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- }
-
- if ((selector & 0x0200) != 0) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID,
- String.valueOf(((long) buf.readUnsignedShort()) << 32) + buf.readUnsignedInt());
- }
-
- if ((selector & 0x0400) != 0) {
- buf.readUnsignedByte(); // Keypad
- }
-
- if ((selector & 0x0800) != 0) {
- position.setAltitude(buf.readShort());
- }
-
- if ((selector & 0x2000) != 0) {
- buf.readUnsignedShort(); // snapshot counter
- }
-
- if ((selector & 0x4000) != 0) {
- buf.skipBytes(8); // state flags
- }
-
- if ((selector & 0x80000) != 0) {
- buf.skipBytes(11); // cell info
- }
-
- if ((selector & 0x1000) != 0) {
- decodeEventData(position, buf, event);
- }
-
- if (Context.getConfig().getBoolean(getProtocolName() + ".can")
- && buf.readable() && (selector & 0x1000) != 0 && event == EVENT_DATA) {
- decodeCanData(buf, position);
- }
- }
-
- private void decodeE(Position position, ChannelBuffer buf, int selector) {
-
- if ((selector & 0x0008) != 0) {
- position.set("tachographEvent", buf.readUnsignedShort());
- }
-
- if ((selector & 0x0004) != 0) {
- getLastLocation(position, new Date(buf.readUnsignedInt() * 1000));
- } else {
- getLastLocation(position, null);
- }
-
- if ((selector & 0x0010) != 0) {
- String time = buf.readUnsignedByte() + "s " + buf.readUnsignedByte() + "m " + buf.readUnsignedByte() + "h "
- + buf.readUnsignedByte() + "M " + buf.readUnsignedByte() + "D " + buf.readUnsignedByte() + "Y "
- + buf.readByte() + "m " + buf.readByte() + "h";
- position.set("tachographTime", time);
- }
-
- position.set("workState", buf.readUnsignedByte());
- position.set("driver1State", buf.readUnsignedByte());
- position.set("driver2State", buf.readUnsignedByte());
-
- if ((selector & 0x0020) != 0) {
- position.set("tachographStatus", buf.readUnsignedByte());
- }
-
- if ((selector & 0x0040) != 0) {
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedShort() / 256.0);
- }
-
- if ((selector & 0x0080) != 0) {
- position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5);
- }
-
- if ((selector & 0x0100) != 0) {
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt() * 5);
- }
-
- if ((selector & 0x8000) != 0) {
- position.set("kFactor", buf.readUnsignedShort() * 0.001 + " pulses/m");
- }
-
- if ((selector & 0x0200) != 0) {
- position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125);
- }
-
- if ((selector & 0x0400) != 0) {
- position.set("extraInfo", buf.readUnsignedShort());
- }
-
- if ((selector & 0x0800) != 0) {
- position.set(Position.KEY_VIN, buf.readBytes(18).toString(StandardCharsets.US_ASCII).trim());
- }
-
- if ((selector & 0x2000) != 0) {
- buf.readUnsignedByte(); // card 1 type
- buf.readUnsignedByte(); // card 1 country code
- String card = buf.readBytes(20).toString(StandardCharsets.US_ASCII).trim();
- if (!card.isEmpty()) {
- position.set("card1", card);
- }
- }
-
- if ((selector & 0x4000) != 0) {
- buf.readUnsignedByte(); // card 2 type
- buf.readUnsignedByte(); // card 2 country code
- String card = buf.readBytes(20).toString(StandardCharsets.US_ASCII).trim();
- if (!card.isEmpty()) {
- position.set("card2", card);
- }
- }
-
- if ((selector & 0x10000) != 0) {
- int count = buf.readUnsignedByte();
- for (int i = 1; i <= count; i++) {
- position.set("driver" + i, buf.readBytes(22).toString(StandardCharsets.US_ASCII).trim());
- position.set("driverTime" + i, buf.readUnsignedInt());
- }
- }
- }
-
- 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;
- }
-
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
- position.set(Position.KEY_EVENT, buf.readUnsignedShort());
- position.set("dataValidity", buf.readUnsignedByte());
- position.set("towed", buf.readUnsignedByte());
- buf.readUnsignedShort(); // length
-
- while (buf.readableBytes() > 0) {
- buf.readUnsignedByte(); // towed position
- int type = buf.readUnsignedByte();
- int length = buf.readUnsignedByte();
- int end = buf.readerIndex() + length;
-
- switch (type) {
- case 0x01:
- position.set("brakeFlags", ChannelBuffers.hexDump(buf.readBytes(length)));
- break;
- case 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);
- break;
- case 0x03:
- position.set("axleLoadSum", buf.readUnsignedShort() * 2);
- break;
- case 0x04:
- position.set("tyrePressure", buf.readUnsignedByte() * 10);
- position.set("pneumaticPressure", buf.readUnsignedByte() * 5);
- break;
- case 0x05:
- position.set("brakeLining", buf.readUnsignedByte() * 0.4);
- position.set("brakeTemperature", buf.readUnsignedByte() * 10);
- break;
- case 0x06:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 5L);
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt() * 5L);
- position.set(Position.KEY_ODOMETER_SERVICE, (buf.readUnsignedInt() - 2105540607) * 5L);
- break;
- case 0x0A:
- position.set("absStatusCounter", buf.readUnsignedShort());
- position.set("atvbStatusCounter", buf.readUnsignedShort());
- position.set("vdcActiveCounter", buf.readUnsignedShort());
- break;
- case 0x0B:
- position.set("brakeMinMaxData", ChannelBuffers.hexDump(buf.readBytes(length)));
- break;
- case 0x0C:
- position.set("missingPgn", ChannelBuffers.hexDump(buf.readBytes(length)));
- break;
- case 0x0D:
- buf.readUnsignedByte();
- position.set("towedDetectionStatus", buf.readUnsignedInt());
- buf.skipBytes(17); // vin
- break;
- case 0x0E:
- default:
- break;
- }
-
- buf.readerIndex(end);
- }
- }
-
- private void decodeF(Position position, ChannelBuffer buf, int selector) {
-
- getLastLocation(position, null);
-
- if ((selector & 0x0004) != 0) {
- buf.skipBytes(4); // snapshot time
- }
-
- buf.readUnsignedByte(); // data validity
-
- if ((selector & 0x0008) != 0) {
- position.set(Position.KEY_RPM, buf.readUnsignedShort());
- position.set("rpmMax", buf.readUnsignedShort());
- position.set("rpmMin", buf.readUnsignedShort());
- }
-
- if ((selector & 0x0010) != 0) {
- position.set("engineTemp", buf.readShort());
- position.set("engineTempMax", buf.readShort());
- position.set("engineTempMin", buf.readShort());
- }
-
- if ((selector & 0x0020) != 0) {
- position.set(Position.KEY_HOURS, buf.readUnsignedInt());
- position.set("serviceDistance", buf.readInt());
- position.set("driverActivity", buf.readUnsignedByte());
- position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
- }
-
- if ((selector & 0x0040) != 0) {
- position.set("totalFuelUsed", buf.readUnsignedInt());
- }
-
- if ((selector & 0x0080) != 0) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- if ((selector & 0x0100) != 0) {
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
- position.set("speedMax", buf.readUnsignedByte());
- position.set("speedMin", buf.readUnsignedByte());
- position.set("hardBraking", buf.readUnsignedByte());
- }
-
- if ((selector & 0x0200) != 0) {
- position.set("tachographSpeed", buf.readUnsignedByte());
- position.set("driver1State", buf.readUnsignedByte());
- position.set("driver2State", buf.readUnsignedByte());
- position.set("tachographStatus", buf.readUnsignedByte());
- position.set("overspeedCount", buf.readUnsignedByte());
- }
-
- }
-
- @Override
- protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- char protocol = (char) buf.readByte();
- int version = buf.readUnsignedByte();
-
- String imei;
- if ((version & 0x80) != 0) {
- imei = String.valueOf((buf.readUnsignedInt() << (3 * 8)) | buf.readUnsignedMedium());
- } else {
- imei = String.valueOf(imeiFromUnitId(buf.readUnsignedMedium()));
- }
-
- buf.readUnsignedShort(); // length
-
- int selector = DEFAULT_SELECTOR_D;
- if (protocol == 'E') {
- selector = DEFAULT_SELECTOR_E;
- } else if (protocol == 'F') {
- selector = DEFAULT_SELECTOR_F;
- }
- if ((version & 0x40) != 0) {
- selector = buf.readUnsignedMedium();
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- int event = buf.readUnsignedByte();
- position.set(Position.KEY_EVENT, event);
- position.set("eventInfo", buf.readUnsignedByte());
-
- if (protocol == 'D') {
- decodeD(position, buf, selector, event);
- } else if (protocol == 'E') {
- decodeE(position, buf, selector);
- } else if (protocol == 'H') {
- decodeH(position, buf, selector);
- } else if (protocol == 'F') {
- decodeF(position, buf, selector);
- } else {
- return null;
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/AppelloProtocol.java b/src/org/traccar/protocol/AppelloProtocol.java
deleted file mode 100644
index 8581850a1..000000000
--- a/src/org/traccar/protocol/AppelloProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 AppelloProtocol extends BaseProtocol {
-
- public AppelloProtocol() {
- super("appello");
- }
-
- @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 AppelloProtocolDecoder(AppelloProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AppelloProtocolDecoder.java b/src/org/traccar/protocol/AppelloProtocolDecoder.java
deleted file mode 100644
index 30dec3941..000000000
--- a/src/org/traccar/protocol/AppelloProtocolDecoder.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class AppelloProtocolDecoder extends BaseProtocolDecoder {
-
- public AppelloProtocolDecoder(AppelloProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("FOLLOWIT,") // brand
- .number("(d+),") // imei
- .groupBegin()
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .or()
- .text("UTCTIME,")
- .groupEnd()
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(d+),") // satellites
- .number("(-?d+),") // altitude
- .expression("([FL]),") // gps state
- .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;
- }
-
- String imei = parser.next();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (parser.hasNext(6)) {
- position.setTime(parser.nextDateTime());
- } else {
- getLastLocation(position, null);
- }
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
-
- position.setAltitude(parser.nextDouble(0));
-
- position.setValid(parser.next().equals("F"));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/AquilaProtocol.java b/src/org/traccar/protocol/AquilaProtocol.java
deleted file mode 100644
index c1de71cd3..000000000
--- a/src/org/traccar/protocol/AquilaProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 AquilaProtocol extends BaseProtocol {
-
- public AquilaProtocol() {
- super("aquila");
- }
-
- @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 AquilaProtocolDecoder(AquilaProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java
deleted file mode 100644
index 773210b04..000000000
--- a/src/org/traccar/protocol/AquilaProtocolDecoder.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.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 AquilaProtocolDecoder extends BaseProtocolDecoder {
-
- public AquilaProtocolDecoder(AquilaProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$$")
- .expression("[^,]*,") // client
- .number("(d+),") // device serial number
- .number("(d+),") // event
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(d+),") // gsm
- .number("(d+),") // speed
- .number("(d+),") // distance
- .groupBegin()
- .number("d+,") // driver code
- .number("(d+),") // fuel
- .number("([01]),") // io 1
- .number("[01],") // case open switch
- .number("[01],") // over speed start
- .number("[01],") // over speed end
- .number("(?:d+,){3}") // reserved
- .number("([01]),") // power status
- .number("([01]),") // io 2
- .number("d+,") // reserved
- .number("([01]),") // ignition
- .number("[01],") // ignition off event
- .number("(?:d+,){7}") // reserved
- .number("[01],") // corner packet
- .number("(?:d+,){8}") // reserved
- .number("([01]),") // course bit 0
- .number("([01]),") // course bit 1
- .number("([01]),") // course bit 2
- .number("([01]),") // course bit 3
- .or()
- .number("(d+),") // course
- .number("(?:d+,){3}") // reserved
- .number("[01],") // over speed start
- .number("[01],") // over speed end
- .number("(?:d+,){3}") // reserved
- .number("([01]),") // power status
- .number("(?:d+,){2}") // reserved
- .number("[01],") // ignition on event
- .number("([01]),") // ignition
- .number("[01],") // ignition off event
- .number("(?:d+,){5}") // reserved
- .number("[01],") // low battery
- .number("[01],") // corner packet
- .number("(?:d+,){6}") // reserved
- .number("[01],") // hard acceleration
- .number("[01],") // hard braking
- .number("[01],[01],[01],[01],") // course bits
- .number("(d+),") // external voltage
- .number("(d+),") // internal voltage
- .number("(?:d+,){6}") // reserved
- .expression("P([^,]+),") // obd
- .expression("D([^,]+),") // dtcs
- .number("-?d+,") // accelerometer x
- .number("-?d+,") // accelerometer y
- .number("-?d+,") // accelerometer z
- .number("d+,") // delta distance
- .or()
- .number("(d+),") // course
- .number("(d+),") // satellites
- .number("(d+.d+),") // hdop
- .number("(?:d+,){2}") // reserved
- .number("(d+),") // adc 1
- .number("([01]),") // di 1
- .number("[01],") // case open
- .number("[01],") // over speed start
- .number("[01],") // over speed end
- .number("(?:[01],){2}") // reserved
- .number("[01],") // immobilizer
- .number("([01]),") // power status
- .number("([01]),") // di 2
- .number("(?:[01],){2}") // reserved
- .number("([01]),") // ignition
- .number("(?:[01],){6}") // reserved
- .number("[01],") // low battery
- .number("[01],") // corner packet
- .number("(?:[01],){4}") // reserved
- .number("[01],") // do 1
- .number("[01],") // reserved
- .number("[01],") // hard acceleration
- .number("[01],") // hard braking
- .number("(?:[01],){4}") // reserved
- .number("(d+),") // external voltage
- .number("(d+),") // internal voltage
- .groupEnd()
- .text("*")
- .number("xx") // checksum
- .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());
-
- position.set(Position.KEY_EVENT, parser.nextInt(0));
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
-
- position.set(Position.KEY_RSSI, parser.nextInt(0));
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
-
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
-
- if (parser.hasNext(9)) {
-
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
- position.set(Position.PREFIX_IN + 1, parser.next());
- position.set(Position.KEY_CHARGE, parser.next().equals("1"));
- position.set(Position.PREFIX_IN + 2, parser.next());
-
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
-
- int course = (parser.nextInt(0) << 3) + (parser.nextInt(0) << 2)
- + (parser.nextInt(0) << 1) + parser.nextInt(0);
- if (course > 0 && course <= 8) {
- position.setCourse((course - 1) * 45);
- }
-
- } else if (parser.hasNext(7)) {
-
- position.setCourse(parser.nextInt(0));
-
- position.set(Position.KEY_CHARGE, parser.next().equals("1"));
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_POWER, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
-
- String obd = parser.next();
- position.set("obd", obd.substring(1, obd.length() - 1));
-
- String dtcs = parser.next();
- position.set(Position.KEY_DTCS, dtcs.substring(1, dtcs.length() - 1).replace('|', ' '));
-
- } else {
-
- position.setCourse(parser.nextInt(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
- position.set(Position.PREFIX_IN + 1, parser.nextInt(0));
- position.set(Position.KEY_CHARGE, parser.next().equals("1"));
- position.set(Position.PREFIX_IN + 2, parser.nextInt(0));
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_POWER, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
-
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Ardi01Protocol.java b/src/org/traccar/protocol/Ardi01Protocol.java
deleted file mode 100644
index 446592bd0..000000000
--- a/src/org/traccar/protocol/Ardi01Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 Ardi01Protocol extends BaseProtocol {
-
- public Ardi01Protocol() {
- super("ardi01");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Ardi01ProtocolDecoder(Ardi01Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
deleted file mode 100644
index 7a5bd217c..000000000
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.
- * 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.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 Ardi01ProtocolDecoder extends BaseProtocolDecoder {
-
- public Ardi01ProtocolDecoder(Ardi01Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(d+),") // imei
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(-?d+.d+),") // longitude
- .number("(-?d+.d+),") // latitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(-?d+.?d*),") // altitude
- .number("(d+),") // satellites
- .number("(d+),") // event
- .number("(d+),") // battery
- .number("(-?d+)") // temperature
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- int satellites = parser.nextInt(0);
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
-
- position.set(Position.KEY_EVENT, parser.next());
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
- position.set(Position.PREFIX_TEMP + 1, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/ArknavProtocol.java b/src/org/traccar/protocol/ArknavProtocol.java
deleted file mode 100644
index c22e5f443..000000000
--- a/src/org/traccar/protocol/ArknavProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 ArknavProtocol extends BaseProtocol {
-
- public ArknavProtocol() {
- super("arknav");
- }
-
- @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, '\r'));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new ArknavProtocolDecoder(ArknavProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java
deleted file mode 100644
index 927c50c29..000000000
--- a/src/org/traccar/protocol/ArknavProtocolDecoder.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class ArknavProtocolDecoder extends BaseProtocolDecoder {
-
- public ArknavProtocolDecoder(ArknavProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(d+),") // imei
- .expression(".{6},") // id code
- .number("ddd,") // status
- .number("Lddd,") // version
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(d+.?d*),") // hdop
- .number("(dd):(dd):(dd) ") // time (hh:mm:ss)
- .number("(dd)-(dd)-(dd),") // date (dd-mm-yy)
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/ArknavX8Protocol.java b/src/org/traccar/protocol/ArknavX8Protocol.java
deleted file mode 100644
index e759b5294..000000000
--- a/src/org/traccar/protocol/ArknavX8Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 ArknavX8Protocol extends BaseProtocol {
-
- public ArknavX8Protocol() {
- super("arknavx8");
- }
-
- @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 ArknavX8ProtocolDecoder(ArknavX8Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
deleted file mode 100644
index 8a80901b5..000000000
--- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder {
-
- public ArknavX8ProtocolDecoder(ArknavX8Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("(..),") // type
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(d+)(dd.d+)([NS]),") // latitude
- .number("(d+)(dd.d+)([EW]),") // longitude
- .number("(d+.d+),") // speed
- .number("(d+),") // course
- .number("(d+.d+),") // hdop
- .number("(d+)") // status
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.charAt(2) != ',') {
- getDeviceSession(channel, remoteAddress, sentence.substring(0, 15));
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_TYPE, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.KEY_STATUS, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Arnavi4FrameDecoder.java b/src/org/traccar/protocol/Arnavi4FrameDecoder.java
deleted file mode 100644
index b13f3fd7d..000000000
--- a/src/org/traccar/protocol/Arnavi4FrameDecoder.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2017 Ivan Muratov (binakot@gmail.com)
- *
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class Arnavi4FrameDecoder extends FrameDecoder {
-
- private static final int MIN_LENGTH = 4;
- private static final int HEADER_LENGTH = 10;
- private static final int PACKET_WRAPPER_LENGTH = 8;
- private static final int COMMAND_ANSWER_PACKET_LENGTH = 4;
- private static final int COMMAND_ANSWER_PARCEL_NUMBER = 0xfd;
- private static final byte PACKAGE_END_SIGN = 0x5d;
-
- private boolean firstPacket = true;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < MIN_LENGTH) {
- return null;
- }
-
- int length;
- if (firstPacket) {
- firstPacket = false;
- length = HEADER_LENGTH;
- } else {
- int index = buf.getUnsignedByte(1); // parcel number
- if (index == COMMAND_ANSWER_PARCEL_NUMBER) {
- length = COMMAND_ANSWER_PACKET_LENGTH;
- } else {
- int pos = 2; // start sign + parcel number
- while (pos + PACKET_WRAPPER_LENGTH < buf.readableBytes()
- && buf.getByte(pos) != PACKAGE_END_SIGN) {
-
- int dataLength = buf.getUnsignedShort(pos + 1);
- pos += PACKET_WRAPPER_LENGTH + dataLength; // packet type + data length + unixtime + data + crc
- }
-
- if (buf.getByte(pos) != PACKAGE_END_SIGN) { // end sign
- return null;
- }
-
- length = pos + 1;
- }
- }
-
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Arnavi4Protocol.java b/src/org/traccar/protocol/Arnavi4Protocol.java
deleted file mode 100644
index 381a9b457..000000000
--- a/src/org/traccar/protocol/Arnavi4Protocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2017 Ivan Muratov (binakot@gmail.com)
- *
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class Arnavi4Protocol extends BaseProtocol {
-
- public Arnavi4Protocol() {
- super("arnavi4");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Arnavi4FrameDecoder());
- pipeline.addLast("objectDecoder", new Arnavi4ProtocolDecoder(Arnavi4Protocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java b/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java
deleted file mode 100644
index 06abb563f..000000000
--- a/src/org/traccar/protocol/Arnavi4ProtocolDecoder.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2017 Ivan Muratov (binakot@gmail.com)
- *
- * 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.Checksum;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class Arnavi4ProtocolDecoder extends BaseProtocolDecoder {
-
- private static final byte HEADER_START_SIGN = (byte) 0xff;
- private static final byte HEADER_VERSION_1 = 0x22;
- private static final byte HEADER_VERSION_2 = 0x23;
-
- private static final byte RECORD_PING = 0x00;
- private static final byte RECORD_DATA = 0x01;
- private static final byte RECORD_TEXT = 0x03;
- private static final byte RECORD_FILE = 0x04;
- private static final byte RECORD_BINARY = 0x06;
-
- private static final byte TAG_LATITUDE = 3;
- private static final byte TAG_LONGITUDE = 4;
- private static final byte TAG_COORD_PARAMS = 5;
-
- public Arnavi4ProtocolDecoder(Arnavi4Protocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, byte version, int index) {
- if (channel != null) {
- final ChannelBuffer response;
- if (version == HEADER_VERSION_1) {
- response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 4);
- response.writeByte(0x7b);
- response.writeByte(0x00);
- response.writeByte((byte) index);
- response.writeByte(0x7d);
- } else if (version == HEADER_VERSION_2) {
- response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 9);
- response.writeByte(0x7b);
- response.writeByte(0x04);
- response.writeByte(0x00);
- byte[] timeBytes = ByteBuffer.allocate(4).putInt((int) (System.currentTimeMillis() / 1000)).array();
- response.writeByte(Checksum.modulo256(timeBytes));
- response.writeBytes(timeBytes);
- response.writeByte(0x7d);
- } else {
- return; // Ignore unsupported header's versions
- }
- channel.write(response);
- }
- }
-
- private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, int length, Date time) {
-
- final Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(time);
-
- int readBytes = 0;
- while (readBytes < length) {
- short tag = buf.readUnsignedByte();
- switch (tag) {
- case TAG_LATITUDE:
- position.setLatitude(buf.readFloat());
- position.setValid(true);
- break;
-
- case TAG_LONGITUDE:
- position.setLongitude(buf.readFloat());
- position.setValid(true);
- break;
-
- case TAG_COORD_PARAMS:
- position.setCourse(buf.readUnsignedByte() * 2);
- position.setAltitude(buf.readUnsignedByte() * 10);
- byte satellites = buf.readByte();
- position.set(Position.KEY_SATELLITES, satellites & 0x0F + (satellites >> 4) & 0x0F); // gps+glonass
- position.setSpeed(buf.readUnsignedByte());
- break;
-
- default:
- buf.readBytes(4); // Skip unsupported tags
- break;
- }
-
- readBytes += 5; // 1 byte tag + 4 bytes value
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- byte startSign = buf.readByte();
-
- if (startSign == HEADER_START_SIGN) {
-
- byte version = buf.readByte();
-
- String imei = String.valueOf(buf.readLong());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
-
- if (deviceSession != null) {
- sendResponse(channel, version, 0);
- }
-
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- int index = buf.readUnsignedByte();
-
- byte recordType = buf.readByte();
- while (buf.readableBytes() > 0) {
- switch (recordType) {
- case RECORD_PING:
- case RECORD_DATA:
- case RECORD_TEXT:
- case RECORD_FILE:
- case RECORD_BINARY:
- int length = buf.readUnsignedShort();
- Date time = new Date(buf.readUnsignedInt() * 1000);
-
- if (recordType == RECORD_DATA) {
- positions.add(decodePosition(deviceSession, buf, length, time));
- } else {
- buf.readBytes(length); // Skip other types of record
- }
-
- buf.readUnsignedByte(); // crc
- break;
-
- default:
- return null; // Ignore unsupported types of record
- }
-
- recordType = buf.readByte();
- }
-
- sendResponse(channel, HEADER_VERSION_1, index);
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/ArnaviProtocol.java b/src/org/traccar/protocol/ArnaviProtocol.java
deleted file mode 100644
index 956f2329a..000000000
--- a/src/org/traccar/protocol/ArnaviProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 ArnaviProtocol extends BaseProtocol {
-
- public ArnaviProtocol() {
- super("arnavi");
- }
-
- @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 ArnaviProtocolDecoder(ArnaviProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
deleted file mode 100644
index 9c4ab5d05..000000000
--- a/src/org/traccar/protocol/ArnaviProtocolDecoder.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.
- * 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 ArnaviProtocolDecoder extends BaseProtocolDecoder {
-
- public ArnaviProtocolDecoder(ArnaviProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$AV,")
- .number("Vd,") // type
- .number("(d+),") // device id
- .number("(d+),") // index
- .number("(d+),") // power
- .number("(d+),") // battery
- .number("-?d+,")
- .expression("[01],") // movement
- .expression("([01]),") // ignition
- .number("(d+),") // input
- .number("d+,d+,") // input 1
- .number("d+,d+,").optional() // input 2
- .expression("[01],") // fix type
- .number("(d+),") // satellites
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(dd)(dd.d+)([NS]),") // latitude
- .number("(ddd)(dd.d+)([EW]),") // longitude
- .number("(d+.d+),") // speed
- .number("(d+.d+),") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .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;
- }
-
- 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(Position.KEY_INDEX, parser.nextInt(0));
- position.set(Position.KEY_POWER, parser.nextInt(0) * 0.01);
- position.set(Position.KEY_BATTERY, parser.nextInt(0) * 0.01);
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_INPUT, parser.nextInt(0));
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/AstraProtocol.java b/src/org/traccar/protocol/AstraProtocol.java
deleted file mode 100644
index 87c562a9d..000000000
--- a/src/org/traccar/protocol/AstraProtocol.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class AstraProtocol extends BaseProtocol {
-
- public AstraProtocol() {
- super("astra");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 1, 2, -3, 0));
- pipeline.addLast("objectDecoder", new AstraProtocolDecoder(AstraProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new AstraProtocolDecoder(AstraProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java
deleted file mode 100644
index 8d86cd2be..000000000
--- a/src/org/traccar/protocol/AstraProtocolDecoder.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Log;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-
-public class AstraProtocolDecoder extends BaseProtocolDecoder {
-
- public AstraProtocolDecoder(AstraProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_HEARTBEAT = 0x1A;
- public static final int MSG_DATA = 0x10;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (channel != null) {
- channel.write(ChannelBuffers.wrappedBuffer(new byte[] {0x06}), remoteAddress);
- }
-
- buf.readUnsignedByte(); // protocol
- buf.readUnsignedShort(); // length
-
- String imei = String.format("%08d", buf.readUnsignedInt()) + String.format("%07d", buf.readUnsignedMedium());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- while (buf.readableBytes() > 2) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedByte(); // index
-
- position.setValid(true);
- position.setLatitude(buf.readInt() * 0.000001);
- position.setLongitude(buf.readInt() * 0.000001);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(1980, 1, 6).addMillis(buf.readUnsignedInt() * 1000L);
- position.setTime(dateBuilder.getDate());
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte() * 2));
- position.setCourse(buf.readUnsignedByte() * 2);
-
- int reason = buf.readUnsignedMedium();
- position.set(Position.KEY_EVENT, reason);
-
- 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());
- position.set(Position.KEY_POWER, buf.readUnsignedByte());
-
- buf.readUnsignedByte(); // max journey speed
- buf.skipBytes(6); // accelerometer
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedShort());
- buf.readUnsignedShort(); // journey idle time
-
- position.setAltitude(buf.readUnsignedByte() * 20);
-
- int quality = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, quality & 0xf);
- position.set(Position.KEY_RSSI, quality >> 4);
-
- buf.readUnsignedByte(); // geofence events
-
- if (BitUtil.check(status, 8)) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 1000);
- position.set(Position.KEY_HOURS, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(status, 6)) {
- Log.warning("Extension data is not supported");
- return position;
- }
-
- positions.add(position);
-
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/At2000FrameDecoder.java b/src/org/traccar/protocol/At2000FrameDecoder.java
deleted file mode 100644
index af257d0fb..000000000
--- a/src/org/traccar/protocol/At2000FrameDecoder.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.nio.ByteOrder;
-
-public class At2000FrameDecoder extends FrameDecoder {
-
- private static final int BLOCK_LENGTH = 16;
- private static final int ACK_LENGTH = 496;
-
- private boolean firstPacket = true;
-
- private ChannelBuffer currentBuffer;
- private int acknowledgedBytes;
-
- private void sendResponse(Channel channel) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 2 * BLOCK_LENGTH);
- response.writeByte(At2000ProtocolDecoder.MSG_ACKNOWLEDGEMENT);
- response.writeMedium(ChannelBuffers.swapMedium(1));
- response.writeByte(0x00); // success
- response.writerIndex(2 * BLOCK_LENGTH);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 5) {
- return null;
- }
-
- int length;
- if (firstPacket) {
- firstPacket = false;
- length = buf.getUnsignedMedium(buf.readerIndex() + 2);
- } else {
- length = buf.getUnsignedMedium(buf.readerIndex() + 1);
- }
-
- length += BLOCK_LENGTH;
- if (length % BLOCK_LENGTH != 0) {
- length = (length / BLOCK_LENGTH + 1) * BLOCK_LENGTH;
- }
-
- if ((buf.readableBytes() >= length || buf.readableBytes() % ACK_LENGTH == 0)
- && (buf != currentBuffer || buf.readableBytes() > acknowledgedBytes)) {
- sendResponse(channel);
- currentBuffer = buf;
- acknowledgedBytes = buf.readableBytes();
- }
-
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/At2000Protocol.java b/src/org/traccar/protocol/At2000Protocol.java
deleted file mode 100644
index 35aa0b469..000000000
--- a/src/org/traccar/protocol/At2000Protocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class At2000Protocol extends BaseProtocol {
-
- public At2000Protocol() {
- super("at2000");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new At2000FrameDecoder());
- pipeline.addLast("objectDecoder", new At2000ProtocolDecoder(At2000Protocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java
deleted file mode 100644
index 70840c37d..000000000
--- a/src/org/traccar/protocol/At2000ProtocolDecoder.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.UnitsConverter;
-import org.traccar.model.Position;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-import javax.xml.bind.DatatypeConverter;
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class At2000ProtocolDecoder extends BaseProtocolDecoder {
-
- private static final int BLOCK_LENGTH = 16;
-
- public At2000ProtocolDecoder(At2000Protocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_ACKNOWLEDGEMENT = 0x00;
- public static final int MSG_DEVICE_ID = 0x01;
- public static final int MSG_TRACK_REQUEST = 0x88;
- public static final int MSG_TRACK_RESPONSE = 0x89;
- public static final int MSG_SESSION_END = 0x0c;
-
- private Cipher cipher;
-
- private static void sendRequest(Channel channel) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, BLOCK_LENGTH);
- response.writeByte(MSG_TRACK_REQUEST);
- response.writeMedium(ChannelBuffers.swapMedium(0));
- response.writerIndex(BLOCK_LENGTH);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0x01) {
- buf.readUnsignedByte(); // codec id
- }
-
- int type = buf.readUnsignedByte();
- buf.readUnsignedMedium(); // length
- buf.skipBytes(BLOCK_LENGTH - 1 - 3);
-
- if (type == MSG_DEVICE_ID) {
-
- String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
- if (getDeviceSession(channel, remoteAddress, imei) != null) {
-
- byte[] iv = new byte[BLOCK_LENGTH];
- buf.readBytes(iv);
- IvParameterSpec ivSpec = new IvParameterSpec(iv);
-
- SecretKeySpec keySpec = new SecretKeySpec(
- DatatypeConverter.parseHexBinary("000102030405060708090a0b0c0d0e0f"), "AES");
-
- cipher = Cipher.getInstance("AES/CBC/NoPadding");
- cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
-
- byte[] data = new byte[BLOCK_LENGTH];
- buf.readBytes(data);
- cipher.update(data);
-
- }
-
- } else if (type == MSG_TRACK_RESPONSE) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- if (buf.capacity() <= BLOCK_LENGTH) {
- return null; // empty message
- }
-
- byte[] data = new byte[buf.capacity() - BLOCK_LENGTH];
- buf.readBytes(data);
- buf = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, cipher.update(data));
-
- List<Position> positions = new LinkedList<>();
-
- while (buf.readableBytes() >= 63) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedShort(); // index
- buf.readUnsignedShort(); // reserved
-
- position.setValid(true);
-
- position.setTime(new Date(buf.readLong() * 1000));
-
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- position.setAltitude(buf.readFloat());
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readFloat()));
- position.setCourse(buf.readFloat());
-
- buf.readUnsignedInt(); // geozone event
- buf.readUnsignedInt(); // io events
- buf.readUnsignedInt(); // geozone value
- buf.readUnsignedInt(); // io values
- buf.readUnsignedShort(); // operator
-
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
-
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
-
- buf.readUnsignedShort(); // cid
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- buf.readUnsignedByte(); // current profile
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte());
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- positions.add(position);
-
- }
-
- return positions;
-
- }
-
- if (type == MSG_DEVICE_ID) {
- sendRequest(channel);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AtrackFrameDecoder.java b/src/org/traccar/protocol/AtrackFrameDecoder.java
deleted file mode 100644
index ce4a9a65f..000000000
--- a/src/org/traccar/protocol/AtrackFrameDecoder.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
-
-public class AtrackFrameDecoder extends FrameDecoder {
-
- private static final int KEEPALIVE_LENGTH = 12;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() >= 2) {
-
- if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
-
- if (buf.readableBytes() >= KEEPALIVE_LENGTH) {
- return buf.readBytes(KEEPALIVE_LENGTH);
- }
-
- } else if (buf.getUnsignedShort(buf.readerIndex()) == 0x4050) {
-
- if (buf.readableBytes() > 6) {
- int length = buf.getUnsignedShort(buf.readerIndex() + 4) + 4 + 2;
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
- }
-
- } else {
-
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
- if (endIndex > 0) {
- return buf.readBytes(endIndex - buf.readerIndex() + 2);
- }
-
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AtrackProtocol.java b/src/org/traccar/protocol/AtrackProtocol.java
deleted file mode 100644
index 5104e5587..000000000
--- a/src/org/traccar/protocol/AtrackProtocol.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class AtrackProtocol extends BaseProtocol {
-
- public AtrackProtocol() {
- super("atrack");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new AtrackFrameDecoder());
- pipeline.addLast("objectEncoder", new AtrackProtocolEncoder());
- pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectEncoder", new AtrackProtocolEncoder());
- pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
deleted file mode 100644
index 23cb67e15..000000000
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.Context;
-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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-public class AtrackProtocolDecoder extends BaseProtocolDecoder {
-
- private static final int MIN_DATA_LENGTH = 40;
-
- private boolean longDate;
- private boolean custom;
- private String form;
-
- private final Map<Integer, String> alarmMap = new HashMap<>();
-
- public AtrackProtocolDecoder(AtrackProtocol protocol) {
- super(protocol);
-
- longDate = Context.getConfig().getBoolean(getProtocolName() + ".longDate");
-
- custom = Context.getConfig().getBoolean(getProtocolName() + ".custom");
- form = Context.getConfig().getString(getProtocolName() + ".form");
- if (form != null) {
- custom = true;
- }
-
- for (String pair : Context.getConfig().getString(getProtocolName() + ".alarmMap", "").split(",")) {
- if (!pair.isEmpty()) {
- alarmMap.put(
- Integer.parseInt(pair.substring(0, pair.indexOf('='))), pair.substring(pair.indexOf('=') + 1));
- }
- }
- }
-
- public void setLongDate(boolean longDate) {
- this.longDate = longDate;
- }
-
- public void setCustom(boolean custom) {
- this.custom = custom;
- }
-
- private static void sendResponse(Channel channel, SocketAddress remoteAddress, long rawId, int index) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(12);
- response.writeShort(0xfe02);
- response.writeLong(rawId);
- response.writeShort(index);
- channel.write(response, remoteAddress);
- }
- }
-
- private static String readString(ChannelBuffer buf) {
- String result = null;
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
- if (index > buf.readerIndex()) {
- result = buf.readBytes(index - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
- }
- buf.readByte();
- return result;
- }
-
- private void readCustomData(Position position, ChannelBuffer buf, String form) {
- CellTower cellTower = new CellTower();
- String[] keys = form.substring(1).split("%");
- for (String key : keys) {
- switch (key) {
- case "SA":
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- case "MV":
- position.set(Position.KEY_POWER, buf.readUnsignedShort());
- break;
- case "BV":
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
- break;
- case "GQ":
- cellTower.setSignalStrength((int) buf.readUnsignedByte());
- break;
- case "CE":
- cellTower.setCellId(buf.readUnsignedInt());
- break;
- case "LC":
- cellTower.setLocationAreaCode(buf.readUnsignedShort());
- break;
- case "CN":
- int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000); // cccnn
- cellTower.setMobileCountryCode(combinedMobileCodes / 100);
- cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
- break;
- case "RL":
- buf.readUnsignedByte(); // rxlev
- break;
- case "PC":
- position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
- break;
- case "AT":
- position.setAltitude(buf.readUnsignedInt());
- break;
- case "RP":
- position.set(Position.KEY_RPM, buf.readUnsignedShort());
- break;
- case "GS":
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- break;
- case "DT":
- position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
- break;
- case "VN":
- position.set(Position.KEY_VIN, readString(buf));
- break;
- case "MF":
- buf.readUnsignedShort(); // mass air flow rate
- break;
- case "EL":
- buf.readUnsignedByte(); // engine load
- break;
- case "TR":
- position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
- break;
- case "ET":
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
- break;
- case "FL":
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
- break;
- case "ML":
- buf.readUnsignedByte(); // mil status
- break;
- case "FC":
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
- break;
- case "CI":
- readString(buf); // format string
- break;
- case "AV1":
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- break;
- case "NC":
- readString(buf); // gsm neighbor cell info
- break;
- case "SM":
- buf.readUnsignedShort(); // max speed between reports
- break;
- case "GL":
- readString(buf); // google link
- break;
- case "MA":
- readString(buf); // mac address
- break;
- default:
- break;
- }
- }
-
- if (cellTower.getMobileCountryCode() != null
- && cellTower.getMobileNetworkCode() != null
- && cellTower.getCellId() != null
- && cellTower.getLocationAreaCode() != null) {
- position.setNetwork(new Network(cellTower));
- } else if (cellTower.getSignalStrength() != null) {
- position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
- }
- }
-
- private static final Pattern PATTERN_INFO = new PatternBuilder()
- .text("$INFO=")
- .number("(d+),") // unit id
- .expression("([^,]+),") // model
- .expression("([^,]+),") // firmware version
- .number("d+,") // imei
- .number("d+,") // imsi
- .number("d+,") // sim card id
- .number("(d+),") // power
- .number("(d+),") // battery
- .number("(d+),") // satellites
- .number("d+,") // gsm status
- .number("(d+),") // rssi
- .number("d+,") // connection status
- .number("d+") // antenna status
- .any()
- .compile();
-
- private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- getLastLocation(position, null);
-
- DeviceSession deviceSession;
-
- if (sentence.startsWith("$INFO")) {
-
- Parser parser = new Parser(PATTERN_INFO, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
-
- position.set("model", parser.next());
- position.set(Position.KEY_VERSION_FW, parser.next());
- position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
- position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1);
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_RSSI, parser.nextInt());
-
- } else {
-
- deviceSession = getDeviceSession(channel, remoteAddress);
-
- position.set(Position.KEY_RESULT, sentence);
-
- }
-
- if (deviceSession == null) {
- return null;
- } else {
- position.setDeviceId(deviceSession.getDeviceId());
- return position;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {
- if (channel != null) {
- channel.write(buf, remoteAddress); // keep-alive message
- }
- return null;
- } else if (buf.getByte(buf.readerIndex()) == '$') {
- return decodeString(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII).trim());
- }
-
- buf.skipBytes(2); // prefix
- buf.readUnsignedShort(); // checksum
- buf.readUnsignedShort(); // length
- int index = buf.readUnsignedShort();
-
- long id = buf.readLong();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
- if (deviceSession == null) {
- return null;
- }
-
- sendResponse(channel, remoteAddress, id, index);
-
- List<Position> positions = new LinkedList<>();
-
- while (buf.readableBytes() >= MIN_DATA_LENGTH) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (longDate) {
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- buf.skipBytes(7 + 7);
-
-
- } else {
-
- position.setFixTime(new Date(buf.readUnsignedInt() * 1000));
- position.setDeviceTime(new Date(buf.readUnsignedInt() * 1000));
- buf.readUnsignedInt(); // send time
- }
-
- position.setValid(true);
- position.setLongitude(buf.readInt() * 0.000001);
- position.setLatitude(buf.readInt() * 0.000001);
- position.setCourse(buf.readUnsignedShort());
-
- int type = buf.readUnsignedByte();
- position.set(Position.KEY_TYPE, type);
- position.set(Position.KEY_ALARM, alarmMap.get(type));
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
- position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
-
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() * 0.001);
-
- position.set(Position.KEY_DRIVER_UNIQUE_ID, readString(buf));
-
- position.set(Position.PREFIX_TEMP + 1, buf.readShort() * 0.1);
- position.set(Position.PREFIX_TEMP + 2, buf.readShort() * 0.1);
-
- position.set("message", readString(buf));
-
- if (custom) {
- String form = this.form;
- if (form == null) {
- form = readString(buf).substring("%CI".length());
- }
- readCustomData(position, buf, form);
- }
-
- positions.add(position);
-
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/AtrackProtocolEncoder.java b/src/org/traccar/protocol/AtrackProtocolEncoder.java
deleted file mode 100644
index 77f16527f..000000000
--- a/src/org/traccar/protocol/AtrackProtocolEncoder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.ChannelBuffers;
-import org.traccar.BaseProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.nio.charset.StandardCharsets;
-
-public class AtrackProtocolEncoder extends BaseProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return ChannelBuffers.copiedBuffer(
- command.getString(Command.KEY_DATA) + "\r\n", StandardCharsets.US_ASCII);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AuroProtocol.java b/src/org/traccar/protocol/AuroProtocol.java
deleted file mode 100644
index e1b23478f..000000000
--- a/src/org/traccar/protocol/AuroProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 AuroProtocol extends BaseProtocol {
-
- public AuroProtocol() {
- super("auro");
- }
-
- @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 AuroProtocolDecoder(AuroProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AuroProtocolDecoder.java b/src/org/traccar/protocol/AuroProtocolDecoder.java
deleted file mode 100644
index a45d14709..000000000
--- a/src/org/traccar/protocol/AuroProtocolDecoder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.
- * 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.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 AuroProtocolDecoder extends BaseProtocolDecoder {
-
- public AuroProtocolDecoder(AuroProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("M(dddd)") // index
- .number("Td+") // phone
- .number("I(d+)") // imei
- .number("Ed+W")
- .text("*****")
- .number("d{8}d{4}") // local time
- .expression(".{8}#.{8}")
- .number("d{10}") // status
- .number("([-+])(ddd)(dd)(dddd)") // longitude
- .number("([-+])(ddd)(dd)(dddd)") // latitude
- .number("(dd)(dd)(dddd)") // date (ddmmyyyy)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(ddd)") // course
- .number("d{6}")
- .number("(ddd)") // speed
- .number("d")
- .number("(dd)") // battery
- .expression("([01])") // charging
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, parser.nextInt(0));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(true);
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setCourse(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
-
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFonFrameDecoder.java b/src/org/traccar/protocol/AutoFonFrameDecoder.java
deleted file mode 100644
index 2fa1b4072..000000000
--- a/src/org/traccar/protocol/AutoFonFrameDecoder.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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");
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class AutoFonFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- if (buf.readableBytes() < 12) {
- return null;
- }
-
- int length;
- switch (buf.getUnsignedByte(buf.readerIndex())) {
- case AutoFonProtocolDecoder.MSG_LOGIN:
- length = 12;
- break;
- case AutoFonProtocolDecoder.MSG_LOCATION:
- length = 78;
- break;
- case AutoFonProtocolDecoder.MSG_HISTORY:
- length = 257;
- break;
- case AutoFonProtocolDecoder.MSG_45_LOGIN:
- length = 19;
- break;
- case AutoFonProtocolDecoder.MSG_45_LOCATION:
- length = 34;
- break;
- default:
- length = 0;
- break;
- }
-
- // Check length and return buffer
- if (length != 0 && buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFonProtocol.java b/src/org/traccar/protocol/AutoFonProtocol.java
deleted file mode 100644
index 927bda120..000000000
--- a/src/org/traccar/protocol/AutoFonProtocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class AutoFonProtocol extends BaseProtocol {
-
- public AutoFonProtocol() {
- super("autofon");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new AutoFonFrameDecoder());
- pipeline.addLast("objectDecoder", new AutoFonProtocolDecoder(AutoFonProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
deleted file mode 100644
index 32b4bfa74..000000000
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * 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");
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-
-public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
-
- public AutoFonProtocolDecoder(AutoFonProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_LOGIN = 0x10;
- public static final int MSG_LOCATION = 0x11;
- public static final int MSG_HISTORY = 0x12;
-
- public static final int MSG_45_LOGIN = 0x41;
- public static final int MSG_45_LOCATION = 0x02;
-
- private static double convertCoordinate(int raw) {
- int degrees = raw / 1000000;
- double minutes = (raw % 1000000) / 10000.0;
- return degrees + minutes / 60;
- }
-
- private static double convertCoordinate(short degrees, int minutes) {
- double value = degrees + BitUtil.from(minutes, 4) / 600000.0;
- if (BitUtil.check(minutes, 0)) {
- return value;
- } else {
- return -value;
- }
- }
-
- private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (!history) {
- buf.readUnsignedByte(); // interval
- buf.skipBytes(8); // settings
- }
- position.set(Position.KEY_STATUS, buf.readUnsignedByte());
- if (!history) {
- buf.readUnsignedShort();
- }
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- buf.skipBytes(6); // time
-
- if (!history) {
- for (int i = 0; i < 2; i++) {
- buf.skipBytes(5); // time
- buf.readUnsignedShort(); // interval
- buf.skipBytes(5); // mode
- }
- }
-
- position.set(Position.PREFIX_TEMP + 1, buf.readByte());
-
- int rssi = buf.readUnsignedByte();
- CellTower cellTower = CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort(), rssi);
- position.setNetwork(new Network(cellTower));
-
- int valid = buf.readUnsignedByte();
- position.setValid((valid & 0xc0) != 0);
- position.set(Position.KEY_SATELLITES, valid & 0x3f);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- position.setLatitude(convertCoordinate(buf.readInt()));
- position.setLongitude(convertCoordinate(buf.readInt()));
- position.setAltitude(buf.readShort());
- position.setSpeed(buf.readUnsignedByte());
- position.setCourse(buf.readUnsignedByte() * 2.0);
-
- position.set(Position.KEY_HDOP, buf.readUnsignedShort());
-
- buf.readUnsignedShort(); // reserved
- buf.readUnsignedByte(); // checksum
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int type = buf.readUnsignedByte();
-
- if (type == MSG_LOGIN || type == MSG_45_LOGIN) {
-
- if (type == MSG_LOGIN) {
- buf.readUnsignedByte(); // hardware version
- buf.readUnsignedByte(); // software version
- }
-
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
-
- if (deviceSession != null && channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeBytes("resp_crc=".getBytes(StandardCharsets.US_ASCII));
- response.writeByte(buf.getByte(buf.writerIndex() - 1));
- channel.write(response);
- }
-
- return null;
-
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- if (type == MSG_LOCATION) {
-
- return decodePosition(deviceSession, buf, false);
-
- } else if (type == MSG_HISTORY) {
-
- int count = buf.readUnsignedByte() & 0x0f;
- buf.readUnsignedShort(); // total count
- List<Position> positions = new LinkedList<>();
-
- for (int i = 0; i < count; i++) {
- positions.add(decodePosition(deviceSession, buf, true));
- }
-
- return positions;
-
- } else if (type == MSG_45_LOCATION) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- short status = buf.readUnsignedByte();
- if (BitUtil.check(status, 7)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- position.set(Position.KEY_BATTERY, BitUtil.to(status, 7));
-
- buf.skipBytes(2); // remaining time
-
- position.set(Position.PREFIX_TEMP + 1, buf.readByte());
-
- buf.skipBytes(2); // timer (interval and units)
- buf.readByte(); // mode
- buf.readByte(); // gprs sending interval
-
- buf.skipBytes(6); // mcc, mnc, lac, cid
-
- int valid = buf.readUnsignedByte();
- position.setValid(BitUtil.from(valid, 6) != 0);
- position.set(Position.KEY_SATELLITES, BitUtil.from(valid, 6));
-
- int time = buf.readUnsignedMedium();
- int date = buf.readUnsignedMedium();
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(time / 10000, time / 100 % 100, time % 100)
- .setDateReverse(date / 10000, date / 100 % 100, date % 100);
- position.setTime(dateBuilder.getDate());
-
- position.setLatitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedMedium()));
- position.setLongitude(convertCoordinate(buf.readUnsignedByte(), buf.readUnsignedMedium()));
- position.setSpeed(buf.readUnsignedByte());
- position.setCourse(buf.readUnsignedShort());
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoGradeProtocol.java b/src/org/traccar/protocol/AutoGradeProtocol.java
deleted file mode 100644
index 41bb8d9ad..000000000
--- a/src/org/traccar/protocol/AutoGradeProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 AutoGradeProtocol extends BaseProtocol {
-
- public AutoGradeProtocol() {
- super("autograde");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new AutoGradeProtocolDecoder(AutoGradeProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
deleted file mode 100644
index 753509f31..000000000
--- a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.BitUtil;
-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 AutoGradeProtocolDecoder extends BaseProtocolDecoder {
-
- public AutoGradeProtocolDecoder(AutoGradeProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("(")
- .number("d{12}") // index
- .number("(d{15})") // imei
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .expression("([AV])") // validity
- .number("(d+)(dd.d+)([NS])") // latitude
- .number("(d+)(dd.d+)([EW])") // longitude
- .number("([d.]{5})") // speed
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("([d.]{6})") // course
- .expression("(.)") // status
- .number("A(xxxx)")
- .number("B(xxxx)")
- .number("C(xxxx)")
- .number("D(xxxx)")
- .number("E(xxxx)")
- .number("K(xxxx)")
- .number("L(xxxx)")
- .number("M(xxxx)")
- .number("N(xxxx)")
- .number("O(xxxx)")
- .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()
- .setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
-
- dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.setCourse(parser.nextDouble(0));
-
- int status = 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());
- }
-
- for (int i = 1; i <= 5; i++) {
- position.set("can" + i, parser.next());
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Avl301Protocol.java b/src/org/traccar/protocol/Avl301Protocol.java
deleted file mode 100644
index 4a217bad6..000000000
--- a/src/org/traccar/protocol/Avl301Protocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class Avl301Protocol extends BaseProtocol {
-
- public Avl301Protocol() {
- super("avl301");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, -3, 0));
- pipeline.addLast("objectDecoder", new Avl301ProtocolDecoder(Avl301Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
deleted file mode 100644
index cc61be91b..000000000
--- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.
- * 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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-
-public class Avl301ProtocolDecoder extends BaseProtocolDecoder {
-
- public Avl301ProtocolDecoder(Avl301Protocol protocol) {
- super(protocol);
- }
-
- private String readImei(ChannelBuffer buf) {
- int b = buf.readUnsignedByte();
- StringBuilder imei = new StringBuilder();
- imei.append(b & 0x0F);
- for (int i = 0; i < 7; i++) {
- b = buf.readUnsignedByte();
- imei.append((b & 0xF0) >> 4);
- imei.append(b & 0x0F);
- }
- return imei.toString();
- }
-
- public static final int MSG_LOGIN = 'L';
- public static final int MSG_STATUS = 'H';
- public static final int MSG_GPS_LBS_STATUS = '$';
-
- private void sendResponse(Channel channel, int type) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(5);
- response.writeByte('$');
- response.writeByte(type);
- response.writeByte('#');
- response.writeByte('\r'); response.writeByte('\n');
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(1); // header
- int type = buf.readUnsignedByte();
- buf.readUnsignedByte(); // length
-
- if (type == MSG_LOGIN) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readImei(buf));
- if (deviceSession == null) {
- sendResponse(channel, type);
- }
-
- } else if (type == MSG_STATUS) {
-
- sendResponse(channel, type);
-
- } else if (type == MSG_GPS_LBS_STATUS) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- int gpsLength = buf.readUnsignedByte(); // gps len and sat
- position.set(Position.KEY_SATELLITES, gpsLength & 0xf);
-
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte()); // satellites
-
- double latitude = buf.readUnsignedInt() / 600000.0;
- double longitude = buf.readUnsignedInt() / 600000.0;
- position.setSpeed(buf.readUnsignedByte());
-
- int union = buf.readUnsignedShort(); // course and flags
- position.setCourse(union & 0x03FF);
- position.setValid((union & 0x1000) != 0);
- if ((union & 0x0400) != 0) {
- latitude = -latitude;
- }
- if ((union & 0x0800) != 0) {
- longitude = -longitude;
- }
-
- position.setLatitude(latitude);
- position.setLongitude(longitude);
-
- if ((union & 0x4000) != 0) {
- position.set("acc", (union & 0x8000) != 0);
- }
-
- position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedMedium())));
-
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- int flags = buf.readUnsignedByte();
- position.set("acc", (flags & 0x2) != 0);
-
- // parse other flags
-
- position.set(Position.KEY_POWER, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/BceFrameDecoder.java b/src/org/traccar/protocol/BceFrameDecoder.java
deleted file mode 100644
index 4fac79f85..000000000
--- a/src/org/traccar/protocol/BceFrameDecoder.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class BceFrameDecoder extends FrameDecoder {
-
- private static final int HANDSHAKE_LENGTH = 7; // "#BCE#\r\n"
-
- private boolean header = true;
-
- private static byte checksum(ChannelBuffer buf, int end) {
- byte result = 0;
- for (int i = 0; i < end; i++) {
- result += buf.getByte(buf.readerIndex() + i);
- }
- return result;
- }
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- if (header && buf.readableBytes() >= HANDSHAKE_LENGTH) {
- buf.skipBytes(HANDSHAKE_LENGTH);
- header = false;
- }
-
- int end = 8; // IMEI
-
- while (buf.readableBytes() >= end + 2 + 1 + 1 + 1) {
- end += buf.getUnsignedShort(buf.readerIndex() + end) + 2;
-
- if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) {
- return buf.readBytes(end + 1);
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/BceProtocol.java b/src/org/traccar/protocol/BceProtocol.java
deleted file mode 100644
index 5374fd0e1..000000000
--- a/src/org/traccar/protocol/BceProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class BceProtocol extends BaseProtocol {
-
- public BceProtocol() {
- super("bce");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new BceFrameDecoder());
- pipeline.addLast("objectDecoder", new BceProtocolDecoder(BceProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
deleted file mode 100644
index b472ac6c9..000000000
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class BceProtocolDecoder extends BaseProtocolDecoder {
-
- public BceProtocolDecoder(BceProtocol protocol) {
- super(protocol);
- }
-
- private static final int DATA_TYPE = 7;
-
- public static final int MSG_ASYNC_STACK = 0xA5;
- public static final int MSG_STACK_COFIRM = 0x19;
- public static final int MSG_TIME_TRIGGERED = 0xA0;
- public static final int MSG_OUTPUT_CONTROL = 0x41;
- public static final int MSG_OUTPUT_CONTROL_ACK = 0xC1;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- String imei = String.format("%015d", buf.readLong());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- while (buf.readableBytes() > 1) {
-
- int dataEnd = buf.readUnsignedShort() + buf.readerIndex();
- int type = buf.readUnsignedByte();
- int confirmKey = buf.readUnsignedByte() & 0x7F;
-
- while (buf.readerIndex() < dataEnd) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- int structEnd = buf.readUnsignedByte() + buf.readerIndex();
-
- long time = buf.readUnsignedInt();
- if ((time & 0x0f) == DATA_TYPE) {
-
- time = time >> 4 << 1;
- time += 0x47798280; // 01/01/2008
- position.setTime(new Date(time * 1000));
-
- // Read masks
- int mask;
- List<Integer> masks = new LinkedList<>();
- do {
- mask = buf.readUnsignedShort();
- masks.add(mask);
- } while (BitUtil.check(mask, 15));
-
- mask = masks.get(0);
-
- if (BitUtil.check(mask, 0)) {
- position.setValid(true);
- position.setLongitude(buf.readFloat());
- position.setLatitude(buf.readFloat());
- position.setSpeed(buf.readUnsignedByte());
-
- int gps = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, gps & 0xf);
- position.set(Position.KEY_HDOP, gps >> 4);
-
- position.setCourse(buf.readUnsignedByte());
- position.setAltitude(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- if (BitUtil.check(mask, 1)) {
- position.set(Position.KEY_INPUT, buf.readUnsignedShort());
- }
-
- for (int i = 1; i <= 8; i++) {
- if (BitUtil.check(mask, i + 1)) {
- position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
- }
- }
-
- if (BitUtil.check(mask, 10)) {
- buf.skipBytes(4);
- }
- if (BitUtil.check(mask, 11)) {
- buf.skipBytes(4);
- }
- if (BitUtil.check(mask, 12)) {
- buf.skipBytes(2);
- }
- if (BitUtil.check(mask, 13)) {
- buf.skipBytes(2);
- }
-
- if (BitUtil.check(mask, 14)) {
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedByte(),
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedByte())));
- buf.readUnsignedByte();
- }
-
- if (BitUtil.check(mask, 0)) {
- positions.add(position);
- }
- }
-
- buf.readerIndex(structEnd);
- }
-
- // Send response
- if (type == MSG_ASYNC_STACK && channel != null) {
- ChannelBuffer response = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 8 + 2 + 2 + 1);
- response.writeLong(Long.parseLong(imei));
- response.writeShort(2);
- response.writeByte(MSG_STACK_COFIRM);
- response.writeByte(confirmKey);
-
- int checksum = 0;
- for (int i = 0; i < response.writerIndex(); i++) {
- checksum += response.getUnsignedByte(i);
- }
- response.writeByte(checksum);
-
- channel.write(response);
- }
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/BlackKiteProtocol.java b/src/org/traccar/protocol/BlackKiteProtocol.java
deleted file mode 100644
index db32f5328..000000000
--- a/src/org/traccar/protocol/BlackKiteProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2015 Vijay Kumar (vijaykumar@zilogic.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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class BlackKiteProtocol extends BaseProtocol {
-
- public BlackKiteProtocol() {
- super("blackkite");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new GalileoFrameDecoder());
- pipeline.addLast("objectDecoder", new BlackKiteProtocolDecoder(BlackKiteProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
deleted file mode 100644
index 561d7c18b..000000000
--- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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");
- * 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.BitUtil;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
-
- public BlackKiteProtocolDecoder(BlackKiteProtocol protocol) {
- super(protocol);
- }
-
- private static final int TAG_IMEI = 0x03;
- private static final int TAG_DATE = 0x20;
- private static final int TAG_COORDINATES = 0x30;
- private static final int TAG_SPEED_COURSE = 0x33;
- private static final int TAG_ALTITUDE = 0x34;
- private static final int TAG_STATUS = 0x40;
- private static final int TAG_DIGITAL_OUTPUTS = 0x45;
- private static final int TAG_DIGITAL_INPUTS = 0x46;
- private static final int TAG_INPUT_VOLTAGE1 = 0x50;
- private static final int TAG_INPUT_VOLTAGE2 = 0x51;
- private static final int TAG_INPUT_VOLTAGE3 = 0x52;
- private static final int TAG_INPUT_VOLTAGE4 = 0x53;
- private static final int TAG_XT1 = 0x60;
- private static final int TAG_XT2 = 0x61;
- private static final int TAG_XT3 = 0x62;
-
- private void sendReply(Channel channel, int checksum) {
- ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
- reply.writeByte(0x02);
- reply.writeShort((short) checksum);
- if (channel != null) {
- channel.write(reply);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // header
- int length = (buf.readUnsignedShort() & 0x7fff) + 3;
-
- List<Position> positions = new LinkedList<>();
- Set<Integer> tags = new HashSet<>();
- boolean hasLocation = false;
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- while (buf.readerIndex() < length) {
-
- // Check if new message started
- int tag = buf.readUnsignedByte();
- if (tags.contains(tag)) {
- if (hasLocation && position.getFixTime() != null) {
- positions.add(position);
- }
- tags.clear();
- hasLocation = false;
- position = new Position();
- }
- tags.add(tag);
-
- switch (tag) {
-
- case TAG_IMEI:
- getDeviceSession(channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII));
- break;
-
- case TAG_DATE:
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- break;
-
- case TAG_COORDINATES:
- hasLocation = true;
- position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00);
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
- break;
-
- case TAG_SPEED_COURSE:
- position.setSpeed(buf.readUnsignedShort() * 0.0539957);
- position.setCourse(buf.readUnsignedShort() * 0.1);
- break;
-
- case TAG_ALTITUDE:
- position.setAltitude(buf.readShort());
- break;
-
- case TAG_STATUS:
- int status = buf.readUnsignedShort();
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 9));
- if (BitUtil.check(status, 15)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- position.set(Position.KEY_CHARGE, BitUtil.check(status, 2));
- break;
-
- case TAG_DIGITAL_INPUTS:
- int input = buf.readUnsignedShort();
- for (int i = 0; i < 16; i++) {
- position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(input, i));
- }
- break;
-
- case TAG_DIGITAL_OUTPUTS:
- int output = buf.readUnsignedShort();
- for (int i = 0; i < 16; i++) {
- position.set(Position.PREFIX_IO + (i + 17), BitUtil.check(output, i));
- }
- break;
-
- case TAG_INPUT_VOLTAGE1:
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() / 1000.0);
- break;
-
- case TAG_INPUT_VOLTAGE2:
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort() / 1000.0);
- break;
-
- case TAG_INPUT_VOLTAGE3:
- position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort() / 1000.0);
- break;
-
- case TAG_INPUT_VOLTAGE4:
- position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort() / 1000.0);
- break;
-
- case TAG_XT1:
- case TAG_XT2:
- case TAG_XT3:
- buf.skipBytes(16);
- break;
-
- default:
- break;
-
- }
- }
-
- if (hasLocation && position.getFixTime() != null) {
- positions.add(position);
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- sendReply(channel, buf.readUnsignedShort());
-
- for (Position p : positions) {
- p.setDeviceId(deviceSession.getDeviceId());
- }
-
- if (positions.isEmpty()) {
- return null;
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/BoxProtocol.java b/src/org/traccar/protocol/BoxProtocol.java
deleted file mode 100644
index 36e7790f0..000000000
--- a/src/org/traccar/protocol/BoxProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 BoxProtocol extends BaseProtocol {
-
- public BoxProtocol() {
- super("box");
- }
-
- @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, '\r'));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new BoxProtocolDecoder(BoxProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
deleted file mode 100644
index 562731657..000000000
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.
- * 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.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 BoxProtocolDecoder extends BaseProtocolDecoder {
-
- public BoxProtocolDecoder(BoxProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("L,")
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .text("G,")
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(d+.?d*),") // distance
- .number("(d+),") // event
- .number("(d+)") // status
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("H,")) {
-
- int index = sentence.indexOf(',', 2) + 1;
- String id = sentence.substring(index, sentence.indexOf(',', index));
- getDeviceSession(channel, remoteAddress, id);
-
- } else if (sentence.startsWith("E,")) {
-
- if (channel != null) {
- channel.write("A," + sentence.substring(2) + "\r");
- }
-
- } else if (sentence.startsWith("L,")) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_ODOMETER_TRIP, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_EVENT, parser.next());
-
- int status = parser.nextInt(0);
- position.setValid((status & 0x04) == 0);
- position.set(Position.KEY_STATUS, status);
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CalAmpProtocol.java b/src/org/traccar/protocol/CalAmpProtocol.java
deleted file mode 100644
index a3577f10c..000000000
--- a/src/org/traccar/protocol/CalAmpProtocol.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- * 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 CalAmpProtocol extends BaseProtocol {
-
- public CalAmpProtocol() {
- super("calamp");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new CalAmpProtocolDecoder(CalAmpProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
deleted file mode 100644
index 557e2d6e6..000000000
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.Date;
-
-public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
-
- public CalAmpProtocolDecoder(CalAmpProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_NULL = 0;
- public static final int MSG_ACK = 1;
- public static final int MSG_EVENT_REPORT = 2;
- public static final int MSG_ID_REPORT = 3;
- public static final int MSG_USER_DATA = 4;
- public static final int MSG_APP_DATA = 5;
- public static final int MSG_CONFIG = 6;
- public static final int MSG_UNIT_REQUEST = 7;
- public static final int MSG_LOCATE_REPORT = 8;
- public static final int MSG_USER_DATA_ACC = 9;
- public static final int MSG_MINI_EVENT_REPORT = 10;
- public static final int MSG_MINI_USER_DATA = 11;
-
- public static final int SERVICE_UNACKNOWLEDGED = 0;
- public static final int SERVICE_ACKNOWLEDGED = 1;
- public static final int SERVICE_RESPONSE = 2;
-
- private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, int index, int result) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(10);
- response.writeByte(SERVICE_RESPONSE);
- response.writeByte(MSG_ACK);
- response.writeShort(index);
- response.writeByte(type);
- response.writeByte(result);
- response.writeByte(0);
- response.writeMedium(0);
- channel.write(response, remoteAddress);
- }
- }
-
- private Position decodePosition(DeviceSession deviceSession, int type, ChannelBuffer buf) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- if (type != MSG_MINI_EVENT_REPORT) {
- buf.readUnsignedInt(); // fix time
- }
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- if (type != MSG_MINI_EVENT_REPORT) {
- position.setAltitude(buf.readInt() * 0.01);
- position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedInt()));
- }
- position.setCourse(buf.readShort());
- if (type == MSG_MINI_EVENT_REPORT) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- }
-
- if (type == MSG_MINI_EVENT_REPORT) {
- position.set(Position.KEY_SATELLITES, buf.getUnsignedByte(buf.readerIndex()) & 0xf);
- position.setValid((buf.readUnsignedByte() & 0x20) == 0);
- } else {
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.setValid((buf.readUnsignedByte() & 0x08) == 0);
- }
-
- if (type != MSG_MINI_EVENT_REPORT) {
- position.set("carrier", buf.readUnsignedShort());
- position.set(Position.KEY_RSSI, buf.readShort());
- }
-
- position.set("modem", buf.readUnsignedByte());
-
- if (type != MSG_MINI_EVENT_REPORT) {
- position.set(Position.KEY_HDOP, buf.readUnsignedByte());
- }
-
- int input = buf.readUnsignedByte();
- position.set(Position.KEY_INPUT, input);
- position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
-
- if (type != MSG_MINI_EVENT_REPORT) {
- position.set(Position.KEY_STATUS, buf.readUnsignedByte());
- }
-
- if (type == MSG_EVENT_REPORT || type == MSG_MINI_EVENT_REPORT) {
- if (type != MSG_MINI_EVENT_REPORT) {
- buf.readUnsignedByte(); // event index
- }
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- }
-
- int accType = BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 6);
- int accCount = BitUtil.to(buf.readUnsignedByte(), 6);
-
- if (type != MSG_MINI_EVENT_REPORT) {
- position.set("append", buf.readUnsignedByte());
- }
-
- if (accType == 1) {
- buf.readUnsignedInt(); // threshold
- buf.readUnsignedInt(); // mask
- }
-
- for (int i = 0; i < accCount; i++) {
- if (buf.readableBytes() >= 4) {
- position.set("acc" + i, buf.readUnsignedInt());
- }
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (BitUtil.check(buf.getByte(buf.readerIndex()), 7)) {
-
- int content = buf.readUnsignedByte();
-
- if (BitUtil.check(content, 0)) {
- String id = ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()));
- getDeviceSession(channel, remoteAddress, id);
- }
-
- if (BitUtil.check(content, 1)) {
- buf.skipBytes(buf.readUnsignedByte()); // identifier type
- }
-
- if (BitUtil.check(content, 2)) {
- buf.skipBytes(buf.readUnsignedByte()); // authentication
- }
-
- if (BitUtil.check(content, 3)) {
- buf.skipBytes(buf.readUnsignedByte()); // routing
- }
-
- if (BitUtil.check(content, 4)) {
- buf.skipBytes(buf.readUnsignedByte()); // forwarding
- }
-
- if (BitUtil.check(content, 5)) {
- buf.skipBytes(buf.readUnsignedByte()); // response redirection
- }
-
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- int service = buf.readUnsignedByte();
- int type = buf.readUnsignedByte();
- int index = buf.readUnsignedShort();
-
- if (service == SERVICE_ACKNOWLEDGED) {
- sendResponse(channel, remoteAddress, type, index, 0);
- }
-
- if (type == MSG_EVENT_REPORT || type == MSG_LOCATE_REPORT || type == MSG_MINI_EVENT_REPORT) {
- return decodePosition(deviceSession, type, buf);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CarTrackProtocol.java b/src/org/traccar/protocol/CarTrackProtocol.java
deleted file mode 100644
index d235c92be..000000000
--- a/src/org/traccar/protocol/CarTrackProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 CarTrackProtocol extends BaseProtocol {
-
- public CarTrackProtocol() {
- super("cartrack");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new CarTrackProtocolDecoder(CarTrackProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
deleted file mode 100644
index 3064bbb35..000000000
--- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2014 - 2015 Anton Tananaev (anton@traccar.org)
- * Copyright 2014 Rohit
- *
- * 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 CarTrackProtocolDecoder extends BaseProtocolDecoder {
-
- public CarTrackProtocolDecoder(CarTrackProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$$") // header
- .number("(d+)") // device id
- .text("?").expression("*")
- .text("&A")
- .number("(dddd)") // command
- .text("&B")
- .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.dddd),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.dddd),") // longitude
- .expression("([EW]),")
- .number("(d+.d*)?,") // speed
- .number("(d+.d*)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any()
- .expression("&C([^&]*)") // io
- .expression("&D([^&]*)") // odometer
- .expression("&E([^&]*)") // alarm
- .expression("&Y([^&]*)").optional() // adc
- .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;
- }
-
- 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(Position.KEY_COMMAND, parser.next());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.PREFIX_IO + 1, parser.next());
-
- String odometer = parser.next();
- odometer = odometer.replace(":", "A");
- odometer = odometer.replace(";", "B");
- odometer = odometer.replace("<", "C");
- odometer = odometer.replace("=", "D");
- odometer = odometer.replace(">", "E");
- odometer = odometer.replace("?", "F");
- position.set(Position.KEY_ODOMETER, Integer.parseInt(odometer, 16));
-
- parser.next(); // there is no meaningful alarms
- position.set(Position.PREFIX_ADC + 1, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/CarcellProtocol.java b/src/org/traccar/protocol/CarcellProtocol.java
deleted file mode 100644
index c9fedad65..000000000
--- a/src/org/traccar/protocol/CarcellProtocol.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 java.util.List;
-
-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 org.traccar.model.Command;
-
-public class CarcellProtocol extends BaseProtocol {
-
- public CarcellProtocol() {
- super("carcell");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @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, '\r'));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new CarcellProtocolEncoder());
- pipeline.addLast("objectDecoder", new CarcellProtocolDecoder(CarcellProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java
deleted file mode 100644
index fc5710f09..000000000
--- a/src/org/traccar/protocol/CarcellProtocolDecoder.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * 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 java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-import org.jboss.netty.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.Parser;
-import org.traccar.helper.Parser.CoordinateFormat;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-public class CarcellProtocolDecoder extends BaseProtocolDecoder {
-
- public CarcellProtocolDecoder(CarcellProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("([$%])") // memory flag
- .number("(d+),") // imei
- .groupBegin()
- .number("([NS])(dd)(dd).(dddd),") // latitude
- .number("([EW])(ddd)(dd).(dddd),") // longitude
- .or()
- .text("CEL,")
- .number("([NS])(d+.d+),") // latitude
- .number("([EW])(d+.d+),") // longitude
- .groupEnd()
- .number("(d+),") // speed
- .number("(d+),") // course
- .groupBegin()
- .number("([-+]ddd)([-+]ddd)([-+]ddd),") // x,y,z
- .or()
- .number("(d+),") // accel
- .groupEnd()
- .number("(d+),") // battery
- .number("(d+),") // csq
- .number("(d),") // jamming
- .number("(d+),") // hdop
- .expression("([CG]),?") // clock type
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d),") // block
- .number("(d),") // ignition
- .groupBegin()
- .number("(d),") // cloned
- .expression("([AF])") // panic
- .number("(d),") // painel
- .number("(d+),") // battery voltage
- .or()
- .number("(dd),") // time until delivery
- .expression("([AF])") // panic
- .number("(d),") // aux
- .number("(d{2,4}),") // battery voltage
- .number("(d{20}),") // ccid
- .groupEnd()
- .number("(xx)") // crc
- .any() // full format
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.set(Position.KEY_ARCHIVE, parser.next().equals("%"));
- position.setValid(true);
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (parser.hasNext(8)) {
- position.setLatitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG_MIN_MIN));
- position.setLongitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG_MIN_MIN));
- }
-
- if (parser.hasNext(4)) {
- position.setLatitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG));
- position.setLongitude(parser.nextCoordinate(CoordinateFormat.HEM_DEG));
- }
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
-
- if (parser.hasNext(3)) {
- position.set("x", parser.nextInt(0));
- position.set("y", parser.nextInt(0));
- position.set("z", parser.nextInt(0));
- }
-
- if (parser.hasNext(1)) {
- position.set(Position.KEY_ACCELERATION, parser.nextInt(0));
- }
-
- Double internalBattery = (parser.nextDouble(0) + 100d) * 0.0294d;
- position.set(Position.KEY_BATTERY, internalBattery);
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set("jamming", parser.next().equals("1"));
- position.set(Position.KEY_GPS, parser.nextInt(0));
-
- position.set("clockType", parser.next());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.set("blocked", parser.next().equals("1"));
- position.set(Position.KEY_IGNITION, parser.next().equals("1"));
-
- if (parser.hasNext(4)) {
- position.set("cloned", parser.next().equals("1"));
-
- parser.next(); // panic button status
-
- String painelStatus = parser.next();
- if (painelStatus.equals("1")) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- position.set("painel", painelStatus.equals("2"));
-
- Double mainVoltage = parser.nextDouble(0) / 100d;
- position.set(Position.KEY_POWER, mainVoltage);
- }
-
- if (parser.hasNext(5)) {
- position.set("timeUntilDelivery", parser.nextInt(0));
- parser.next(); // panic button status
- position.set(Position.KEY_INPUT, parser.next());
-
- Double mainVoltage = parser.nextDouble(0) / 100d;
- position.set(Position.KEY_POWER, mainVoltage);
-
- position.set("iccid", parser.next());
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/CarcellProtocolEncoder.java b/src/org/traccar/protocol/CarcellProtocolEncoder.java
deleted file mode 100644
index 0846949c4..000000000
--- a/src/org/traccar/protocol/CarcellProtocolEncoder.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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 CarcellProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "$SRVCMD,{%s},BA#\r\n", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "$SRVCMD,{%s},BD#\r\n", Command.KEY_UNIQUE_ID);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CarscopProtocol.java b/src/org/traccar/protocol/CarscopProtocol.java
deleted file mode 100644
index 01a754027..000000000
--- a/src/org/traccar/protocol/CarscopProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 CarscopProtocol extends BaseProtocol {
-
- public CarscopProtocol() {
- super("carscop");
- }
-
- @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 CarscopProtocolDecoder(CarscopProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java
deleted file mode 100644
index 2a081bcdd..000000000
--- a/src/org/traccar/protocol/CarscopProtocolDecoder.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.
- * 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 CarscopProtocolDecoder extends BaseProtocolDecoder {
-
- public CarscopProtocolDecoder(CarscopProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("*")
- .any()
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .expression("([AV])") // validity
- .number("(dd)(dd.dddd)") // latitude
- .expression("([NS])")
- .number("(ddd)(dd.dddd)") // longitude
- .expression("([EW])")
- .number("(ddd.d)") // speed
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(ddd.dd)") // course
- .groupBegin()
- .number("(d{8})") // state
- .number("L(d{6})") // odometer
- .groupEnd("?")
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- DeviceSession deviceSession;
- int index = sentence.indexOf("UB05");
- if (index != -1) {
- String imei = sentence.substring(index + 4, index + 4 + 15);
- deviceSession = getDeviceSession(channel, remoteAddress, imei);
- } else {
- deviceSession = getDeviceSession(channel, remoteAddress);
- }
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
-
- dateBuilder.setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.setCourse(parser.nextDouble(0));
-
- if (parser.hasNext(2)) {
- position.set(Position.KEY_STATUS, parser.next());
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java
deleted file mode 100644
index db9df0674..000000000
--- a/src/org/traccar/protocol/CastelProtocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class CastelProtocol extends BaseProtocol {
-
- public CastelProtocol() {
- super("castel");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
- pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
-
- server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
deleted file mode 100644
index 3a0ccea78..000000000
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.ObdDecoder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public class CastelProtocolDecoder extends BaseProtocolDecoder {
-
- private static final Map<Integer, Integer> PID_LENGTH_MAP = new HashMap<>();
-
- static {
- int[] l1 = {
- 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b, 0x0d,
- 0x0e, 0x0f, 0x11, 0x12, 0x13, 0x1c, 0x1d, 0x1e, 0x2c,
- 0x2d, 0x2e, 0x2f, 0x30, 0x33, 0x43, 0x45, 0x46,
- 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x51, 0x52,
- 0x5a
- };
- int[] l2 = {
- 0x02, 0x03, 0x0a, 0x0c, 0x10, 0x14, 0x15, 0x16,
- 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1f, 0x21, 0x22,
- 0x23, 0x31, 0x32, 0x3c, 0x3d, 0x3e, 0x3f, 0x42,
- 0x44, 0x4d, 0x4e, 0x50, 0x53, 0x54, 0x55, 0x56,
- 0x57, 0x58, 0x59
- };
- int[] l4 = {
- 0x00, 0x01, 0x20, 0x24, 0x25, 0x26, 0x27, 0x28,
- 0x29, 0x2a, 0x2b, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x3a, 0x3b, 0x40, 0x41, 0x4f
- };
- for (int i : l1) {
- PID_LENGTH_MAP.put(i, 1);
- }
- for (int i : l2) {
- PID_LENGTH_MAP.put(i, 2);
- }
- for (int i : l4) {
- PID_LENGTH_MAP.put(i, 4);
- }
- }
-
- public CastelProtocolDecoder(CastelProtocol protocol) {
- super(protocol);
- }
-
- 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) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- double lat = buf.readUnsignedInt() / 3600000.0;
- double lon = buf.readUnsignedInt() / 3600000.0;
- position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort() * 0.1);
-
- int flags = buf.readUnsignedByte();
- if ((flags & 0x02) == 0) {
- lat = -lat;
- }
- if ((flags & 0x01) == 0) {
- lon = -lon;
- }
- position.setLatitude(lat);
- position.setLongitude(lon);
- position.setValid((flags & 0x0C) > 0);
- position.set(Position.KEY_SATELLITES, flags >> 4);
-
- return position;
- }
-
- private Position createPosition(DeviceSession deviceSession) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- return position;
- }
-
- private void decodeObd(Position position, ChannelBuffer buf, boolean groups) {
-
- int count = buf.readUnsignedByte();
-
- int[] pids = new int[count];
- for (int i = 0; i < count; i++) {
- pids[i] = buf.readUnsignedShort() & 0xff;
- }
-
- if (groups) {
- buf.readUnsignedByte(); // group count
- buf.readUnsignedByte(); // group size
- }
-
- for (int i = 0; i < count; i++) {
- int value;
- switch (PID_LENGTH_MAP.get(pids[i])) {
- case 1:
- value = buf.readUnsignedByte();
- break;
- case 2:
- value = buf.readUnsignedShort();
- break;
- case 4:
- value = buf.readInt();
- break;
- default:
- value = 0;
- break;
- }
- position.add(ObdDecoder.decodeData(pids[i], value, false));
- }
- }
-
- private void decodeStat(Position position, ChannelBuffer buf) {
-
- buf.readUnsignedInt(); // ACC ON time
- buf.readUnsignedInt(); // UTC time
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
- buf.readUnsignedShort(); // current fuel consumption
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
- buf.skipBytes(8);
- }
-
- private void sendResponse(
- Channel channel, SocketAddress remoteAddress,
- int version, ChannelBuffer id, short type, ChannelBuffer content) {
-
- if (channel != null) {
- int length = 2 + 2 + 1 + id.readableBytes() + 2 + 2 + 2;
- if (content != null) {
- length += content.readableBytes();
- }
-
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
- response.writeByte('@'); response.writeByte('@');
- response.writeShort(length);
- response.writeByte(version);
- response.writeBytes(id);
- response.writeShort(ChannelBuffers.swapShort(type));
- if (content != null) {
- response.writeBytes(content);
- }
- response.writeShort(
- Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
- response.writeByte(0x0D); response.writeByte(0x0A);
- channel.write(response, remoteAddress);
- }
- }
-
- private void sendResponse(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer id, short type) {
-
- if (channel != null) {
- int length = 2 + 2 + id.readableBytes() + 2 + 4 + 8 + 2 + 2;
-
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, length);
- response.writeByte('@'); response.writeByte('@');
- response.writeShort(length);
- response.writeBytes(id);
- response.writeShort(ChannelBuffers.swapShort(type));
- response.writeInt(0);
- for (int i = 0; i < 8; i++) {
- response.writeByte(0xff);
- }
- response.writeShort(
- Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex())));
- response.writeByte(0x0D); response.writeByte(0x0A);
- channel.write(response, remoteAddress);
- }
- }
-
- private Object decodeSc(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
- int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
-
- if (type == MSG_SC_HEARTBEAT) {
-
- sendResponse(channel, remoteAddress, version, id, MSG_SC_HEARTBEAT_RESPONSE, null);
-
- } else if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS
- || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) {
-
- if (type == MSG_SC_LOGIN) {
- ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 10);
- response.writeInt(0xFFFFFFFF);
- response.writeShort(0);
- response.writeInt((int) (System.currentTimeMillis() / 1000));
- sendResponse(channel, remoteAddress, version, id, MSG_SC_LOGIN_RESPONSE, response);
- }
-
- if (type == MSG_SC_GPS) {
- buf.readUnsignedByte(); // historical
- } else if (type == MSG_SC_ALARM) {
- buf.readUnsignedInt(); // alarm
- } else if (type == MSG_SC_CURRENT_LOCATION) {
- buf.readUnsignedShort();
- }
-
- buf.readUnsignedInt(); // ACC ON time
- buf.readUnsignedInt(); // UTC time
- long odometer = buf.readUnsignedInt();
- long tripOdometer = buf.readUnsignedInt();
- long fuelConsumption = buf.readUnsignedInt();
- buf.readUnsignedShort(); // current fuel consumption
- long status = buf.readUnsignedInt();
- buf.skipBytes(8);
-
- int count = buf.readUnsignedByte();
-
- List<Position> positions = new LinkedList<>();
-
- for (int i = 0; i < count; i++) {
- Position position = readPosition(deviceSession, buf);
- position.set(Position.KEY_ODOMETER, odometer);
- position.set(Position.KEY_ODOMETER_TRIP, tripOdometer);
- position.set(Position.KEY_FUEL_CONSUMPTION, fuelConsumption);
- position.set(Position.KEY_STATUS, status);
- positions.add(position);
- }
-
- if (!positions.isEmpty()) {
- return positions;
- }
-
- } else if (type == MSG_SC_GPS_SLEEP) {
-
- buf.readUnsignedInt(); // device time
-
- return readPosition(deviceSession, buf);
-
- } else if (type == MSG_SC_AGPS_REQUEST) {
-
- return readPosition(deviceSession, buf);
-
- } else if (type == MSG_SC_PID_DATA) {
-
- Position position = createPosition(deviceSession);
-
- decodeStat(position, buf);
-
- buf.readUnsignedShort(); // sample rate
- decodeObd(position, buf, true);
-
- return position;
-
- } else if (type == MSG_SC_DTCS_PASSENGER) {
-
- Position position = createPosition(deviceSession);
-
- decodeStat(position, buf);
-
- buf.readUnsignedByte(); // flag
- position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()))));
-
- return position;
-
- } else if (type == MSG_SC_OBD_DATA) {
-
- Position position = createPosition(deviceSession);
-
- decodeStat(position, buf);
-
- buf.readUnsignedByte(); // flag
- decodeObd(position, buf, false);
-
- return position;
-
- } else if (type == MSG_SC_CELL) {
-
- Position position = createPosition(deviceSession);
-
- decodeStat(position, buf);
-
- position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
-
- return position;
-
- }
-
- return null;
- }
-
-
- private Object decodeCc(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
- int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
-
- if (type == MSG_CC_HEARTBEAT) {
-
- sendResponse(channel, remoteAddress, version, id, MSG_CC_HEARTBEAT_RESPONSE, null);
-
- buf.readUnsignedByte(); // 0x01 for history
- int count = buf.readUnsignedByte();
-
- List<Position> positions = new LinkedList<>();
-
- for (int i = 0; i < count; i++) {
- Position position = readPosition(deviceSession, buf);
-
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- buf.readUnsignedByte(); // geo-fencing id
- buf.readUnsignedByte(); // geo-fencing flags
- buf.readUnsignedByte(); // additional flags
-
- position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
-
- positions.add(position);
- }
-
- return positions;
-
- } else if (type == MSG_CC_LOGIN) {
-
- sendResponse(channel, remoteAddress, version, id, MSG_CC_LOGIN_RESPONSE, null);
-
- Position position = readPosition(deviceSession, buf);
-
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- buf.readUnsignedByte(); // geo-fencing id
- buf.readUnsignedByte(); // geo-fencing flags
- buf.readUnsignedByte(); // additional flags
-
- // GSM_CELL_CODE
- // STR_Z - firmware version
- // STR_Z - hardware version
-
- return position;
-
- }
-
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int header = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
-
- int version = -1;
- if (header == 0x4040) {
- version = buf.readUnsignedByte();
- }
-
- ChannelBuffer id = buf.readBytes(20);
- int type = ChannelBuffers.swapShort(buf.readShort());
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim());
- if (deviceSession == null) {
- return null;
- }
-
- if (version == -1) {
-
- if (type == 0x2001) {
-
- sendResponse(channel, remoteAddress, id, (short) 0x1001);
-
- buf.readUnsignedInt(); // index
- buf.readUnsignedInt(); // unix time
- buf.readUnsignedByte();
-
- return readPosition(deviceSession, buf);
-
- }
-
- } else if (version == 3 || version == 4) {
-
- return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession);
-
- } else {
-
- return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession);
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CellocatorFrameDecoder.java b/src/org/traccar/protocol/CellocatorFrameDecoder.java
deleted file mode 100644
index b4708f5db..000000000
--- a/src/org/traccar/protocol/CellocatorFrameDecoder.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.Log;
-
-public class CellocatorFrameDecoder extends FrameDecoder {
-
- private static final int MESSAGE_MINIMUM_LENGTH = 15;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- int available = buf.readableBytes();
- if (available < MESSAGE_MINIMUM_LENGTH) {
- return null;
- }
-
- // Size depending on message type
- int length = 0;
- int type = buf.getUnsignedByte(4);
- switch (type) {
- case CellocatorProtocolDecoder.MSG_CLIENT_STATUS:
- length = 70;
- break;
- case CellocatorProtocolDecoder.MSG_CLIENT_PROGRAMMING:
- length = 31;
- break;
- case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL_LOG:
- length = 70;
- break;
- case CellocatorProtocolDecoder.MSG_CLIENT_SERIAL:
- if (available >= 19) {
- length = 19 + buf.getUnsignedShort(16);
- }
- break;
- case CellocatorProtocolDecoder.MSG_CLIENT_MODULAR:
- length = 15 + buf.getUnsignedByte(13);
- break;
- default:
- Log.warning(new UnsupportedOperationException(String.valueOf(type)));
- break;
- }
-
- // Read packet
- if (length > 0 && available >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CellocatorProtocol.java b/src/org/traccar/protocol/CellocatorProtocol.java
deleted file mode 100644
index 4a20bc977..000000000
--- a/src/org/traccar/protocol/CellocatorProtocol.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class CellocatorProtocol extends BaseProtocol {
-
- public CellocatorProtocol() {
- super("cellocator");
- setSupportedDataCommands(
- Command.TYPE_OUTPUT_CONTROL);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new CellocatorFrameDecoder());
- pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
- pipeline.addLast("objectDecoder", new CellocatorProtocolDecoder(CellocatorProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
-
- server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectEncoder", new CellocatorProtocolEncoder());
- 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
deleted file mode 100644
index 7ef013e28..000000000
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-
-public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
-
- public CellocatorProtocolDecoder(CellocatorProtocol protocol) {
- super(protocol);
- }
-
- static final int MSG_CLIENT_STATUS = 0;
- static final int MSG_CLIENT_PROGRAMMING = 3;
- static final int MSG_CLIENT_SERIAL_LOG = 7;
- static final int MSG_CLIENT_SERIAL = 8;
- static final int MSG_CLIENT_MODULAR = 9;
-
- public static final int MSG_SERVER_ACKNOWLEDGE = 4;
-
- private byte commandCount;
-
- private void sendReply(Channel channel, SocketAddress remoteAddress, long deviceId, byte packetNumber) {
- ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 28);
- reply.writeByte('M');
- reply.writeByte('C');
- reply.writeByte('G');
- reply.writeByte('P');
- reply.writeByte(MSG_SERVER_ACKNOWLEDGE);
- reply.writeInt((int) deviceId);
- reply.writeByte(commandCount++);
- reply.writeInt(0); // authentication code
- reply.writeByte(0);
- reply.writeByte(packetNumber);
- reply.writeZero(11);
-
- byte checksum = 0;
- for (int i = 4; i < 27; i++) {
- checksum += reply.getByte(i);
- }
- reply.writeByte(checksum);
-
- if (channel != null) {
- channel.write(reply, remoteAddress);
- }
- }
-
- private String decodeAlarm(short reason) {
- switch (reason) {
- case 70:
- return Position.ALARM_SOS;
- case 80:
- return Position.ALARM_POWER_CUT;
- case 81:
- return Position.ALARM_LOW_POWER;
- default:
- return null;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(4); // system code
- int type = buf.readUnsignedByte();
- long deviceUniqueId = buf.readUnsignedInt();
-
- if (type != MSG_CLIENT_SERIAL) {
- buf.readUnsignedShort(); // communication control
- }
- byte packetNumber = buf.readByte();
-
- sendReply(channel, remoteAddress, deviceUniqueId, packetNumber);
-
- if (type == MSG_CLIENT_STATUS) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceUniqueId));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte());
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
- position.set("protocolVersion", buf.readUnsignedByte());
-
- position.set(Position.KEY_STATUS, buf.getUnsignedByte(buf.readerIndex()) & 0x0f);
-
- int operator = (buf.readUnsignedByte() & 0xf0) << 4;
- operator += buf.readUnsignedByte();
-
- buf.readUnsignedByte(); // reason data
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
-
- position.set("mode", buf.readUnsignedByte());
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedInt());
-
- operator <<= 8;
- operator += buf.readUnsignedByte();
- position.set(Position.KEY_OPERATOR, operator);
-
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
- buf.skipBytes(6); // multi-purpose data
-
- position.set(Position.KEY_GPS, buf.readUnsignedShort());
- position.set("locationStatus", buf.readUnsignedByte());
- position.set("mode1", buf.readUnsignedByte());
- position.set("mode2", buf.readUnsignedByte());
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- position.setValid(true);
- position.setLongitude(buf.readInt() / Math.PI * 180 / 100000000);
- position.setLatitude(buf.readInt() / Math.PI * 180 / 100000000.0);
- position.setAltitude(buf.readInt() * 0.01);
- position.setSpeed(UnitsConverter.knotsFromMps(buf.readInt() * 0.01));
- position.setCourse(buf.readUnsignedShort() / Math.PI * 180.0 / 1000.0);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTimeReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedShort());
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CellocatorProtocolEncoder.java b/src/org/traccar/protocol/CellocatorProtocolEncoder.java
deleted file mode 100644
index bb143d349..000000000
--- a/src/org/traccar/protocol/CellocatorProtocolEncoder.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.ByteOrder;
-
-public class CellocatorProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeContent(long deviceId, int command, int data1, int data2) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
- buf.writeByte('M');
- buf.writeByte('C');
- buf.writeByte('G');
- buf.writeByte('P');
- buf.writeByte(0);
- buf.writeInt(Integer.parseInt(getUniqueId(deviceId)));
- buf.writeByte(0); // command numerator
- buf.writeInt(0); // authentication code
- buf.writeByte(command);
- buf.writeByte(command);
- buf.writeByte(data1);
- buf.writeByte(data1);
- buf.writeByte(data2);
- buf.writeByte(data2);
- buf.writeInt(0); // command specific data
-
- byte checksum = 0;
- for (int i = 4; i < buf.writerIndex(); i++) {
- checksum += buf.getByte(i);
- }
- buf.writeByte(checksum);
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_OUTPUT_CONTROL:
- int data = Integer.parseInt(command.getString(Command.KEY_DATA)) << 4
- + command.getInteger(Command.KEY_INDEX);
- return encodeContent(command.getDeviceId(), 0x03, data, 0);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CguardProtocol.java b/src/org/traccar/protocol/CguardProtocol.java
deleted file mode 100644
index 460bd331f..000000000
--- a/src/org/traccar/protocol/CguardProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 CguardProtocol extends BaseProtocol {
-
- public CguardProtocol() {
- super("cguard");
- }
-
- @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 CguardProtocolDecoder(CguardProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
deleted file mode 100644
index 54f83fb73..000000000
--- a/src/org/traccar/protocol/CguardProtocolDecoder.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.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 CguardProtocolDecoder extends BaseProtocolDecoder {
-
- public CguardProtocolDecoder(CguardProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_NV = new PatternBuilder()
- .text("NV:")
- .number("(dd)(dd)(dd) ") // date (yymmdd)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number(":(-?d+.d+)") // longitude
- .number(":(-?d+.d+)") // latitude
- .number(":(d+.?d*)") // speed
- .number(":(?:NAN|(d+.?d*))") // accuracy
- .number(":(?:NAN|(d+.?d*))") // course
- .number(":(?:NAN|(d+.?d*))").optional() // altitude
- .compile();
-
- private static final Pattern PATTERN_BC = new PatternBuilder()
- .text("BC:")
- .number("(dd)(dd)(dd) ") // date (yymmdd)
- .number("(dd)(dd)(dd):") // time (hhmmss)
- .expression("(.+)") // data
- .compile();
-
- private Position decodePosition(DeviceSession deviceSession, String sentence) {
-
- Parser parser = new Parser(PATTERN_NV, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(true);
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
-
- position.setAccuracy(parser.nextDouble(0));
-
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- 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());
-
- getLastLocation(position, parser.nextDateTime());
-
- 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_RSSI, Integer.parseInt(value));
- break;
- case "NSQ1":
- position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
- break;
- case "BAT1":
- position.set(Position.KEY_BATTERY_LEVEL, 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
deleted file mode 100644
index 7e5ca0ba0..000000000
--- a/src/org/traccar/protocol/CityeasyProtocol.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class CityeasyProtocol extends BaseProtocol {
-
- public CityeasyProtocol() {
- super("cityeasy");
- setSupportedDataCommands(
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_POSITION_PERIODIC,
- Command.TYPE_POSITION_STOP,
- Command.TYPE_SET_TIMEZONE);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
- pipeline.addLast("objectEncoder", new CityeasyProtocolEncoder());
- pipeline.addLast("objectDecoder", new CityeasyProtocolDecoder(CityeasyProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
deleted file mode 100644
index 9a614730f..000000000
--- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.regex.Pattern;
-
-public class CityeasyProtocolDecoder extends BaseProtocolDecoder {
-
- public CityeasyProtocolDecoder(CityeasyProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .groupBegin()
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("([AV]),") // validity
- .number("(d+),") // satellites
- .number("([NS]),(d+.d+),") // latitude
- .number("([EW]),(d+.d+),") // longitude
- .number("(d+.d),") // speed
- .number("(d+.d),") // hdop
- .number("(d+.d)") // altitude
- .groupEnd("?").text(";")
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(d+),") // lac
- .number("(d+)") // cell
- .any()
- .compile();
-
- public static final int MSG_ADDRESS_REQUEST = 0x0001;
- public static final int MSG_STATUS = 0x0002;
- public static final int MSG_LOCATION_REPORT = 0x0003;
- public static final int MSG_LOCATION_REQUEST = 0x0004;
- public static final int MSG_LOCATION_INTERVAL = 0x0005;
- public static final int MSG_PHONE_NUMBER = 0x0006;
- public static final int MSG_MONITORING = 0x0007;
- public static final int MSG_TIMEZONE = 0x0008;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- buf.readUnsignedShort(); // length
-
- String imei = ChannelBuffers.hexDump(buf.readBytes(7));
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei)));
- if (deviceSession == null) {
- return null;
- }
-
- int type = buf.readUnsignedShort();
-
- if (type == MSG_LOCATION_REPORT || type == MSG_LOCATION_REQUEST) {
-
- String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 8, StandardCharsets.US_ASCII);
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (parser.hasNext(15)) {
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
-
- position.setSpeed(parser.nextDouble(0));
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- } else {
-
- getLastLocation(position, null);
-
- }
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))));
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CityeasyProtocolEncoder.java b/src/org/traccar/protocol/CityeasyProtocolEncoder.java
deleted file mode 100644
index 387926e03..000000000
--- a/src/org/traccar/protocol/CityeasyProtocolEncoder.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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 java.util.TimeZone;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-import org.traccar.BaseProtocolEncoder;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class CityeasyProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeContent(int type, ChannelBuffer content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeByte('S');
- buf.writeByte('S');
- buf.writeShort(2 + 2 + 2 + content.readableBytes() + 4 + 2 + 2);
- buf.writeShort(type);
- buf.writeBytes(content);
- buf.writeInt(0x0B);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
- buf.writeByte('\r');
- buf.writeByte('\n');
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- ChannelBuffer content = ChannelBuffers.dynamicBuffer();
-
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_REQUEST, content);
- case Command.TYPE_POSITION_PERIODIC:
- content.writeShort(command.getInteger(Command.KEY_FREQUENCY));
- return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
- case Command.TYPE_POSITION_STOP:
- content.writeShort(0);
- return encodeContent(CityeasyProtocolDecoder.MSG_LOCATION_INTERVAL, content);
- case Command.TYPE_SET_TIMEZONE:
- int timezone = TimeZone.getTimeZone(command.getString(Command.KEY_TIMEZONE)).getRawOffset() / 60000;
- if (timezone < 0) {
- content.writeByte(1);
- } else {
- content.writeByte(0);
- }
- content.writeShort(Math.abs(timezone));
- return encodeContent(CityeasyProtocolDecoder.MSG_TIMEZONE, content);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/CradlepointProtocol.java b/src/org/traccar/protocol/CradlepointProtocol.java
deleted file mode 100644
index 6ed54aa17..000000000
--- a/src/org/traccar/protocol/CradlepointProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 CradlepointProtocol extends BaseProtocol {
-
- public CradlepointProtocol() {
- super("cradlepoint");
- }
-
- @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 CradlepointProtocolDecoder(CradlepointProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
deleted file mode 100644
index e8f95a60c..000000000
--- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.Date;
-import java.util.regex.Pattern;
-
-public class CradlepointProtocolDecoder extends BaseProtocolDecoder {
-
- public CradlepointProtocolDecoder(CradlepointProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("([^,]+),") // id
- .number("(d{1,6}),") // time (hhmmss)
- .number("(d+)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(d+)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.d+)?,") // speed
- .number("(d+.d+)?,") // course
- .expression("([^,]+)?,") // carrier
- .expression("([^,]+)?,") // serdis
- .number("(-?d+)?,") // rsrp
- .number("(-?d+)?,") // rssi
- .number("(-?d+)?,") // rsrq
- .expression("([^,]+)?,") // ecio
- .expression("([^,]+)?") // wan ip
- .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());
-
- int time = parser.nextInt();
- DateBuilder dateBuilder = new DateBuilder(new Date());
- dateBuilder.setHour(time / 100 / 100);
- dateBuilder.setMinute(time / 100 % 100);
- dateBuilder.setSecond(time % 100);
- position.setTime(dateBuilder.getDate());
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set("carrid", parser.next());
- position.set("serdis", parser.next());
- position.set("rsrp", parser.next());
- position.set("dbm", parser.next());
- position.set("rsrq", parser.next());
- position.set("ecio", parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/DishaProtocol.java b/src/org/traccar/protocol/DishaProtocol.java
deleted file mode 100644
index 53ba36004..000000000
--- a/src/org/traccar/protocol/DishaProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 DishaProtocol extends BaseProtocol {
-
- public DishaProtocol() {
- super("disha");
- }
-
- @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 DishaProtocolDecoder(DishaProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/DishaProtocolDecoder.java b/src/org/traccar/protocol/DishaProtocolDecoder.java
deleted file mode 100644
index ab0a63215..000000000
--- a/src/org/traccar/protocol/DishaProtocolDecoder.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class DishaProtocolDecoder extends BaseProtocolDecoder {
-
- public DishaProtocolDecoder(DishaProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$A#A#")
- .number("(d+)#") // imei
- .expression("([AVMX])#") // validity
- .number("(dd)(dd)(dd)#") // time (hhmmss)
- .number("(dd)(dd)(dd)#") // date (ddmmyy)
- .number("(dd)(dd.d+)#") // latitude
- .expression("([NS])#")
- .number("(ddd)(dd.d+)#") // longitude
- .expression("([EW])#")
- .number("(d+.d+)#") // speed
- .number("(d+.d+)#") // course
- .number("(d+)#") // satellites
- .number("(d+.d+)#") // hdop
- .number("(d+)#") // gsm
- .expression("([012])#") // power mode
- .number("(d+)#") // battery
- .number("(d+)#") // adc 1
- .number("(d+)#") // adc 2
- .number("d+.d+#") // day distance
- .number("(d+.d+)#") // odometer
- .expression("([01]+)") // digital inputs
- .text("*")
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(parser.next().equals("A"));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_HDOP, parser.nextDouble());
- position.set(Position.KEY_RSSI, parser.nextDouble());
- position.set(Position.KEY_CHARGE, parser.nextInt(0) == 2);
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
-
- position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
- position.set(Position.PREFIX_ADC + 2, parser.nextInt(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_INPUT, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/DmtHttpProtocol.java b/src/org/traccar/protocol/DmtHttpProtocol.java
deleted file mode 100644
index 2378441ba..000000000
--- a/src/org/traccar/protocol/DmtHttpProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.http.HttpChunkAggregator;
-import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class DmtHttpProtocol extends BaseProtocol {
-
- public DmtHttpProtocol() {
- super("dmthttp");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("httpAggregator", new HttpChunkAggregator(65535));
- pipeline.addLast("objectDecoder", new DmtHttpProtocolDecoder(DmtHttpProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/DmtHttpProtocolDecoder.java b/src/org/traccar/protocol/DmtHttpProtocolDecoder.java
deleted file mode 100644
index 1bd808a1f..000000000
--- a/src/org/traccar/protocol/DmtHttpProtocolDecoder.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpHeaders;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import java.io.StringReader;
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.TimeZone;
-
-public class DmtHttpProtocolDecoder extends BaseProtocolDecoder {
-
- public DmtHttpProtocolDecoder(DmtHttpProtocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, HttpResponseStatus status) {
- if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
- response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- JsonObject root = Json.createReader(
- new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject();
-
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, root.getString("IMEI"));
- if (deviceSession == null) {
- sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- JsonArray records = root.getJsonArray("Records");
-
- for (int i = 0; i < records.size(); i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- JsonObject record = records.getJsonObject(i);
-
- position.set(Position.KEY_INDEX, record.getInt("SeqNo"));
- position.set(Position.KEY_EVENT, record.getInt("Reason"));
-
- position.setDeviceTime(dateFormat.parse(record.getString("DateUTC")));
-
- JsonArray fields = record.getJsonArray("Fields");
-
- for (int j = 0; j < fields.size(); j++) {
- JsonObject field = fields.getJsonObject(j);
- switch (field.getInt("FType")) {
- case 0:
- position.setFixTime(dateFormat.parse(field.getString("GpsUTC")));
- position.setLatitude(field.getJsonNumber("Lat").doubleValue());
- position.setLongitude(field.getJsonNumber("Long").doubleValue());
- position.setAltitude(field.getInt("Alt"));
- position.setSpeed(UnitsConverter.knotsFromCps(field.getInt("Spd")));
- position.setCourse(field.getInt("Head"));
- position.setAccuracy(field.getInt("PosAcc"));
- position.setValid(field.getInt("GpsStat") > 0);
- break;
- case 2:
- int input = field.getInt("DIn");
- int output = field.getInt("DOut");
-
- position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
-
- position.set(Position.KEY_INPUT, input);
- position.set(Position.KEY_OUTPUT, output);
- position.set(Position.KEY_STATUS, field.getInt("DevStat"));
- break;
- case 6:
- JsonObject adc = field.getJsonObject("AnalogueData");
- if (adc.containsKey("1")) {
- position.set(Position.KEY_BATTERY, adc.getInt("1") * 0.001);
- }
- if (adc.containsKey("2")) {
- position.set(Position.KEY_POWER, adc.getInt("2") * 0.01);
- }
- if (adc.containsKey("3")) {
- position.set(Position.KEY_DEVICE_TEMP, adc.getInt("3") * 0.01);
- }
- if (adc.containsKey("4")) {
- position.set(Position.KEY_RSSI, adc.getInt("4"));
- }
- if (adc.containsKey("5")) {
- position.set("solarPower", adc.getInt("5") * 0.001);
- }
- break;
- default:
- break;
- }
- }
-
- positions.add(position);
- }
-
- sendResponse(channel, HttpResponseStatus.OK);
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/DmtProtocol.java b/src/org/traccar/protocol/DmtProtocol.java
deleted file mode 100644
index 18bb1524a..000000000
--- a/src/org/traccar/protocol/DmtProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class DmtProtocol extends BaseProtocol {
-
- public DmtProtocol() {
- super("dmt");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2));
- pipeline.addLast("objectDecoder", new DmtProtocolDecoder(DmtProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/DmtProtocolDecoder.java b/src/org/traccar/protocol/DmtProtocolDecoder.java
deleted file mode 100644
index 39462a469..000000000
--- a/src/org/traccar/protocol/DmtProtocolDecoder.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class DmtProtocolDecoder extends BaseProtocolDecoder {
-
- public DmtProtocolDecoder(DmtProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_HELLO = 0x00;
- public static final int MSG_HELLO_RESPONSE = 0x01;
- public static final int MSG_DATA_RECORD = 0x04;
- public static final int MSG_COMMIT = 0x05;
- public static final int MSG_COMMIT_RESPONSE = 0x06;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
-
- int type = buf.readUnsignedByte();
-
- buf.readUnsignedShort(); // length
-
- if (type == MSG_HELLO) {
-
- buf.readUnsignedInt(); // device serial number
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII));
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
- response.writeByte(0x02); response.writeByte(0x55); // header
- response.writeByte(MSG_HELLO_RESPONSE);
- response.writeShort(4 + 4);
- response.writeInt((int) (System.currentTimeMillis() / 1000));
- response.writeInt(deviceSession != null ? 0 : 1); // flags
- channel.write(response);
- }
-
- } else if (type == MSG_COMMIT) {
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
- response.writeByte(0x02); response.writeByte(0x55); // header
- response.writeByte(MSG_COMMIT_RESPONSE);
- response.writeShort(1);
- response.writeByte(1); // flags (success)
- channel.write(response);
- }
-
- } else if (type == MSG_DATA_RECORD) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- while (buf.readable()) {
-
- int recordEnd = buf.readerIndex() + buf.readUnsignedShort();
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_INDEX, buf.readUnsignedInt());
-
- position.setDeviceTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000)); // since 1 Jan 2013
-
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
-
- while (buf.readerIndex() < recordEnd) {
-
- int fieldId = buf.readUnsignedByte();
- int fieldLength = buf.readUnsignedByte();
- int fieldEnd = buf.readerIndex() + (fieldLength == 255 ? buf.readUnsignedShort() : fieldLength);
-
- if (fieldId == 0) {
-
- position.setFixTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000));
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readShort());
- position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
-
- buf.readUnsignedByte(); // speed accuracy
-
- position.setCourse(buf.readUnsignedByte() * 2);
-
- position.set(Position.KEY_PDOP, buf.readUnsignedByte() * 0.1);
-
- position.setAccuracy(buf.readUnsignedByte());
- position.setValid(buf.readUnsignedByte() != 0);
-
- } else if (fieldId == 2) {
-
- int input = buf.readInt();
- int output = buf.readUnsignedShort();
- int status = buf.readUnsignedShort();
-
- position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
-
- position.set(Position.KEY_INPUT, input);
- position.set(Position.KEY_OUTPUT, output);
- position.set(Position.KEY_STATUS, status);
-
- } else if (fieldId == 6) {
-
- while (buf.readerIndex() < fieldEnd) {
- switch (buf.readUnsignedByte()) {
- case 1:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- break;
- case 2:
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
- break;
- case 3:
- position.set(Position.KEY_DEVICE_TEMP, buf.readShort() * 0.01);
- break;
- case 4:
- position.set(Position.KEY_RSSI, buf.readUnsignedShort());
- break;
- case 5:
- position.set("solarPower", buf.readUnsignedShort() * 0.001);
- break;
- default:
- break;
- }
- }
-
- }
-
- buf.readerIndex(fieldEnd);
-
- }
-
- if (position.getFixTime() == null) {
- getLastLocation(position, position.getDeviceTime());
- }
-
- positions.add(position);
-
- }
-
- return positions;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/DwayProtocol.java b/src/org/traccar/protocol/DwayProtocol.java
deleted file mode 100644
index 151d3fe01..000000000
--- a/src/org/traccar/protocol/DwayProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 DwayProtocol extends BaseProtocol {
-
- public DwayProtocol() {
- super("dway");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new DwayProtocolDecoder(DwayProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/DwayProtocolDecoder.java b/src/org/traccar/protocol/DwayProtocolDecoder.java
deleted file mode 100644
index 767b35c72..000000000
--- a/src/org/traccar/protocol/DwayProtocolDecoder.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.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 DwayProtocolDecoder extends BaseProtocolDecoder {
-
- public DwayProtocolDecoder(DwayProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("AA55,")
- .number("d+,") // index
- .number("(d+),") // imei
- .number("d+,") // type
- .number("(dd)(dd)(dd),") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(-?d+),") // altitude
- .number(" ?(d+.d+),") // speed
- .number("(d+),") // course
- .number("([01]{4}),") // input
- .number("([01]{4}),") // output
- .number("([01]+),") // flags
- .number("(d+),") // battery
- .number("(d+),") // adc1
- .number("(d+),") // adc2
- .number("(d+)") // driver
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
- if (sentence.startsWith(">H")) {
- if (channel != null) {
- channel.write(">ALIVE\r\n");
- }
- return null;
- }
-
- 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());
-
- position.setValid(true);
- position.setTime(parser.nextDateTime());
- position.setLatitude(parser.nextDouble());
- position.setLongitude(parser.nextDouble());
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_INPUT, parser.nextBinInt());
- position.set(Position.KEY_OUTPUT, parser.nextBinInt());
-
- position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001);
- position.set(Position.PREFIX_ADC + 1, parser.nextInt() * 0.001);
- position.set(Position.PREFIX_ADC + 2, parser.nextInt() * 0.001);
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/EasyTrackProtocol.java b/src/org/traccar/protocol/EasyTrackProtocol.java
deleted file mode 100644
index eeed07129..000000000
--- a/src/org/traccar/protocol/EasyTrackProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 EasyTrackProtocol extends BaseProtocol {
-
- public EasyTrackProtocol() {
- super("easytrack");
- }
-
- @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, "#", "\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
deleted file mode 100644
index 799254b65..000000000
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.BitUtil;
-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 EasyTrackProtocolDecoder extends BaseProtocolDecoder {
-
- public EasyTrackProtocolDecoder(EasyTrackProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("*").expression("..,") // manufacturer
- .number("(d+),") // imei
- .expression("([^,]{2}),") // command
- .expression("([AV]),") // validity
- .number("(xx)(xx)(xx),") // date (yymmdd)
- .number("(xx)(xx)(xx),") // time (hhmmss)
- .number("(x)(x{7}),") // latitude
- .number("(x)(x{7}),") // longitude
- .number("(x{4}),") // speed
- .number("(x{4}),") // course
- .number("(x{8}),") // status
- .number("(x+),") // signal
- .number("(d+),") // power
- .number("(x{4}),") // oil
- .number("(x+),?") // odometer
- .number("(d+)?") // altitude
- .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;
- }
-
- 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(Position.KEY_COMMAND, parser.next());
-
- position.setValid(parser.next().equals("A"));
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0))
- .setTime(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0));
- position.setTime(dateBuilder.getDate());
-
- if (BitUtil.check(parser.nextHexInt(0), 3)) {
- position.setLatitude(-parser.nextHexInt(0) / 600000.0);
- } else {
- position.setLatitude(parser.nextHexInt(0) / 600000.0);
- }
-
- if (BitUtil.check(parser.nextHexInt(0), 3)) {
- position.setLongitude(-parser.nextHexInt(0) / 600000.0);
- } else {
- position.setLongitude(parser.nextHexInt(0) / 600000.0);
- }
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextHexInt(0) / 100.0));
- position.setCourse(parser.nextHexInt(0) / 100.0);
-
- position.set(Position.KEY_STATUS, parser.next());
- position.set("signal", parser.next());
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- position.set("oil", parser.nextHexInt(0));
- position.set(Position.KEY_ODOMETER, parser.nextHexInt(0) * 100);
-
- position.setAltitude(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/EelinkProtocol.java b/src/org/traccar/protocol/EelinkProtocol.java
deleted file mode 100644
index 5499094d9..000000000
--- a/src/org/traccar/protocol/EelinkProtocol.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class EelinkProtocol extends BaseProtocol {
-
- public EelinkProtocol() {
- super("eelink");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_REBOOT_DEVICE);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @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
deleted file mode 100644
index 8d0f8016a..000000000
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.Date;
-
-public class EelinkProtocolDecoder extends BaseProtocolDecoder {
-
- public EelinkProtocolDecoder(EelinkProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_LOGIN = 0x01;
- public static final int MSG_GPS = 0x02;
- public static final int MSG_HEARTBEAT = 0x03;
- public static final int MSG_ALARM = 0x04;
- 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_DOWNLINK = 0x80;
- public static final int MSG_DATA = 0x81;
-
- public static final int MSG_NORMAL = 0x12;
- public static final int MSG_WARNING = 0x14;
- public static final int MSG_REPORT = 0x15;
- public static final int MSG_COMMAND = 0x16;
- public static final int MSG_OBD_DATA = 0x17;
- public static final int MSG_OBD_BODY = 0x18;
- public static final int MSG_OBD_CODE = 0x19;
- public static final int MSG_CAMERA_INFO = 0x1E;
- public static final int MSG_CAMERA_DATA = 0x1F;
-
- private void sendResponse(Channel channel, int type, int index) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.buffer(7);
- response.writeByte(0x67); response.writeByte(0x67); // header
- response.writeByte(type);
- response.writeShort(2); // length
- response.writeShort(index);
- channel.write(response);
- }
- }
-
- private String decodeAlarm(Short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_POWER_OFF;
- case 0x02:
- return Position.ALARM_SOS;
- case 0x03:
- return Position.ALARM_LOW_BATTERY;
- case 0x04:
- return Position.ALARM_VIBRATION;
- case 0x08:
- case 0x09:
- return Position.ALARM_GPS_ANTENNA_CUT;
- case 0x81:
- return Position.ALARM_LOW_SPEED;
- case 0x82:
- return Position.ALARM_OVERSPEED;
- case 0x83:
- return Position.ALARM_GEOFENCE_ENTER;
- case 0x84:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x85:
- return Position.ALARM_ACCIDENT;
- case 0x86:
- return Position.ALARM_FALL_DOWN;
- default:
- return null;
- }
- }
-
- private void decodeStatus(Position position, int status) {
- if (BitUtil.check(status, 1)) {
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 2));
- }
- if (BitUtil.check(status, 3)) {
- position.set(Position.KEY_ARMED, BitUtil.check(status, 4));
- }
- if (BitUtil.check(status, 5)) {
- position.set(Position.KEY_BLOCKED, !BitUtil.check(status, 6));
- }
- if (BitUtil.check(status, 7)) {
- position.set(Position.KEY_CHARGE, BitUtil.check(status, 8));
- }
- position.set(Position.KEY_STATUS, status);
- }
-
- private Position decodeOld(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, index);
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- position.setLatitude(buf.readInt() / 1800000.0);
- position.setLongitude(buf.readInt() / 1800000.0);
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedShort());
-
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedMedium())));
-
- position.setValid((buf.readUnsignedByte() & 0x01) != 0);
-
- if (type == MSG_GPS) {
-
- if (buf.readableBytes() >= 2) {
- decodeStatus(position, buf.readUnsignedShort());
- }
-
- if (buf.readableBytes() >= 2 * 4) {
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
-
- position.set(Position.KEY_RSSI, buf.readUnsignedShort());
-
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
-
- }
-
- } else if (type == MSG_ALARM) {
-
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
-
- } else if (type == MSG_STATE) {
-
- int statusType = buf.readUnsignedByte();
-
- position.set(Position.KEY_EVENT, statusType);
-
- if (statusType == 0x01 || statusType == 0x02 || statusType == 0x03) {
- buf.readUnsignedInt(); // device time
- if (buf.readableBytes() >= 2) {
- decodeStatus(position, buf.readUnsignedShort());
- }
- }
-
- }
-
- return position;
- }
-
- private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int index) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, index);
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- int flags = buf.readUnsignedByte();
-
- if (BitUtil.check(flags, 0)) {
- position.setLatitude(buf.readInt() / 1800000.0);
- position.setLongitude(buf.readInt() / 1800000.0);
- position.setAltitude(buf.readShort());
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort());
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- }
-
- if (BitUtil.check(flags, 1)) {
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedInt(), buf.readUnsignedByte())));
- }
-
- if (BitUtil.check(flags, 2)) {
- buf.skipBytes(7); // bsid1
- }
-
- if (BitUtil.check(flags, 3)) {
- buf.skipBytes(7); // bsid2
- }
-
- if (BitUtil.check(flags, 4)) {
- buf.skipBytes(7); // bss0
- }
-
- if (BitUtil.check(flags, 5)) {
- buf.skipBytes(7); // bss1
- }
-
- if (BitUtil.check(flags, 6)) {
- buf.skipBytes(7); // bss2
- }
-
- if (buf.readableBytes() >= 2) {
- int status = buf.readUnsignedShort();
- position.setValid(BitUtil.check(status, 0));
- if (BitUtil.check(status, 1)) {
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 2));
- }
- position.set(Position.KEY_STATUS, status);
- }
-
- if (buf.readableBytes() >= 2) {
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- }
-
- if (buf.readableBytes() >= 4) {
- position.set(Position.PREFIX_ADC + 0, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- }
-
- if (buf.readableBytes() >= 4) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- if (buf.readableBytes() >= 4) {
- buf.readUnsignedShort(); // gsm counter
- buf.readUnsignedShort(); // gps counter
- }
-
- if (buf.readableBytes() >= 4) {
- position.set(Position.KEY_STEPS, buf.readUnsignedShort());
- buf.readUnsignedShort(); // walking time
- }
-
- if (buf.readableBytes() >= 12) {
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort() / 256.0);
- position.set("humidity", buf.readUnsignedShort() * 0.1);
- position.set("illuminance", buf.readUnsignedInt() / 256.0);
- position.set("co2", buf.readUnsignedInt());
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- int type = buf.readUnsignedByte();
- buf.readShort(); // length
- int index = buf.readUnsignedShort();
-
- if (type != MSG_GPS && type != MSG_DATA) {
- sendResponse(channel, type, index);
- }
-
- if (type == MSG_LOGIN) {
-
- getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(8)).substring(1));
-
- } else {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- if (type == MSG_GPS || type == MSG_ALARM || type == MSG_STATE || type == MSG_SMS) {
- return decodeOld(deviceSession, buf, type, index);
- } else if (type >= MSG_NORMAL && type <= MSG_OBD_CODE) {
- return decodeNew(deviceSession, buf, index);
- } else if (type == MSG_HEARTBEAT && buf.readableBytes() >= 2) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- getLastLocation(position, null);
-
- decodeStatus(position, buf.readUnsignedShort());
-
- return position;
-
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
deleted file mode 100644
index 5a28733f7..000000000
--- a/src/org/traccar/protocol/EelinkProtocolEncoder.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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(command.getString(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
deleted file mode 100644
index 79cc47c0b..000000000
--- a/src/org/traccar/protocol/EnforaProtocol.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class EnforaProtocol extends BaseProtocol {
-
- public EnforaProtocol() {
- super("enfora");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2));
- pipeline.addLast("objectEncoder", new EnforaProtocolEncoder());
- pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(EnforaProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java
deleted file mode 100644
index f0b79aa1f..000000000
--- a/src/org/traccar/protocol/EnforaProtocolDecoder.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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.
- * 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.ChannelBufferIndexFinder;
-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.StringFinder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.regex.Pattern;
-
-public class EnforaProtocolDecoder extends BaseProtocolDecoder {
-
- public EnforaProtocolDecoder(EnforaProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("GPRMC,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.d+)?,") // speed
- .number("(d+.d+)?,") // course
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .any()
- .compile();
-
- public static final int IMEI_LENGTH = 15;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- // Find IMEI number
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() {
- @Override
- public boolean find(ChannelBuffer buffer, int guessedIndex) {
- if (buffer.writerIndex() - guessedIndex >= IMEI_LENGTH) {
- for (int i = 0; i < IMEI_LENGTH; i++) {
- if (!Character.isDigit((char) buffer.getByte(guessedIndex + i))) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
- });
- if (index == -1) {
- return null;
- }
-
- String imei = buf.toString(index, IMEI_LENGTH, StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- // Find NMEA sentence
- int start = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
- if (start == -1) {
- return null;
- }
-
- String sentence = buf.toString(start, buf.readableBytes() - start, StandardCharsets.US_ASCII);
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/EnforaProtocolEncoder.java b/src/org/traccar/protocol/EnforaProtocolEncoder.java
deleted file mode 100644
index 3dca1b9b3..000000000
--- a/src/org/traccar/protocol/EnforaProtocolEncoder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Jose Castellanos
- *
- * 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.StringProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.nio.charset.StandardCharsets;
-
-public class EnforaProtocolEncoder extends StringProtocolEncoder {
-
- private ChannelBuffer encodeContent(String content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeShort(content.length() + 6);
- buf.writeShort(0); // index
- buf.writeByte(0x04); // command type
- buf.writeByte(0); // optional header
- buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeContent(command.getString(Command.KEY_DATA));
- case Command.TYPE_ENGINE_STOP:
- return encodeContent("AT$IOGP3=1");
- case Command.TYPE_ENGINE_RESUME:
- return encodeContent("AT$IOGP3=0");
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/EskyFrameDecoder.java b/src/org/traccar/protocol/EskyFrameDecoder.java
deleted file mode 100644
index 3175698fd..000000000
--- a/src/org/traccar/protocol/EskyFrameDecoder.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class EskyFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 'E'));
-
- int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E');
- if (endIndex > 0) {
- return buf.readBytes(endIndex - buf.readerIndex());
- } else {
- return buf.readBytes(buf.readableBytes()); // assume full frame
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/EskyProtocol.java b/src/org/traccar/protocol/EskyProtocol.java
deleted file mode 100644
index 4c1d11f7d..000000000
--- a/src/org/traccar/protocol/EskyProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.TrackerServer;
-
-import java.util.List;
-
-public class EskyProtocol extends BaseProtocol {
-
- public EskyProtocol() {
- super("esky");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new EskyFrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new EskyProtocolDecoder(EskyProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/EskyProtocolDecoder.java b/src/org/traccar/protocol/EskyProtocolDecoder.java
deleted file mode 100644
index d524224af..000000000
--- a/src/org/traccar/protocol/EskyProtocolDecoder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.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 EskyProtocolDecoder extends BaseProtocolDecoder {
-
- public EskyProtocolDecoder(EskyProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("EO;") // header
- .number("d+;") // index
- .number("(d+);") // imei
- .text("R;") // data type
- .number("(d+)").text("+") // satellites
- .number("(dd)(dd)(dd)") // date
- .number("(dd)(dd)(dd)").text("+") // time
- .number("(-?d+.d+)").text("+") // latitude
- .number("(-?d+.d+)").text("+") // longitude
- .number("(d+.d+)").text("+") // speed
- .number("(d+)").text("+") // course
- .text("0x").number("(d+)").text("+") // input
- .number("(d+)").text("+") // message type
- .number("(d+)").text("+") // odometer
- .number("(d+)") // voltage
- .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());
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- position.setValid(true);
- position.setTime(parser.nextDateTime());
- position.setLatitude(parser.nextDouble());
- position.setLongitude(parser.nextDouble());
- position.setSpeed(UnitsConverter.knotsFromMps(parser.nextDouble()));
- position.setCourse(parser.nextDouble());
-
- position.set(Position.KEY_INPUT, parser.nextHexInt());
- position.set(Position.KEY_EVENT, parser.nextInt());
- position.set(Position.KEY_ODOMETER, parser.nextInt());
- position.set(Position.KEY_POWER, parser.nextInt());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/ExtremTracProtocol.java b/src/org/traccar/protocol/ExtremTracProtocol.java
deleted file mode 100644
index d9b178e23..000000000
--- a/src/org/traccar/protocol/ExtremTracProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 79e3306df..000000000
--- a/src/org/traccar/protocol/ExtremTracProtocolDecoder.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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).(ddd),") // time (hhmmss.sss)
- .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 (ddmmyy)
- .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(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/FifotrackProtocol.java b/src/org/traccar/protocol/FifotrackProtocol.java
deleted file mode 100644
index f4ca450c0..000000000
--- a/src/org/traccar/protocol/FifotrackProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 304f6a2c3..000000000
--- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-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 (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .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());
-
- position.set(Position.KEY_ALARM, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
- position.setAltitude(parser.nextInt(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextLong(0));
- position.set(Position.KEY_STATUS, parser.nextHexInt(0));
- if (parser.hasNext()) {
- position.set(Position.KEY_INPUT, parser.nextHexInt(0));
- }
- if (parser.hasNext()) {
- position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
- }
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
-
- 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_DRIVER_UNIQUE_ID, 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/FlespiProtocol.java b/src/org/traccar/protocol/FlespiProtocol.java
deleted file mode 100644
index d22bd7ae0..000000000
--- a/src/org/traccar/protocol/FlespiProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.http.HttpChunkAggregator;
-import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class FlespiProtocol extends BaseProtocol {
-
- public FlespiProtocol() {
- super("flespi");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("httpAggregator", new HttpChunkAggregator(Integer.MAX_VALUE));
- pipeline.addLast("objectDecoder", new FlespiProtocolDecoder(FlespiProtocol.this));
- }
- });
- }
-}
diff --git a/src/org/traccar/protocol/FlespiProtocolDecoder.java b/src/org/traccar/protocol/FlespiProtocolDecoder.java
deleted file mode 100644
index 799d78ecb..000000000
--- a/src/org/traccar/protocol/FlespiProtocolDecoder.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.jboss.netty.handler.codec.http.HttpHeaders;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.model.Position;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonNumber;
-import javax.json.JsonObject;
-import javax.json.JsonString;
-import java.io.StringReader;
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Date;
-
-public class FlespiProtocolDecoder extends BaseProtocolDecoder {
-
- public FlespiProtocolDecoder(FlespiProtocol protocol) {
- super(protocol);
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- JsonArray result = Json.createReader(new StringReader(request.getContent().toString(StandardCharsets.UTF_8)))
- .readArray();
- List<Position> positions = new LinkedList<>();
- for (int i = 0; i < result.size(); i++) {
- JsonObject message = result.getJsonObject(i);
- JsonString ident = message.getJsonString("ident");
- if (ident == null) {
- continue;
- }
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ident.getString());
- if (deviceSession == null) {
- continue;
- }
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- decodePosition(message, position);
- positions.add(position);
- }
-
- sendResponse(channel, HttpResponseStatus.OK);
- return positions;
- }
-
- private void sendResponse(Channel channel, HttpResponseStatus status) {
- if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
- response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
- channel.write(response);
- }
- }
-
- private void decodePosition(JsonObject object, Position position) {
- position.setProtocol(getProtocolName());
-
- Date deviceTime = new Date((long) object.getJsonNumber("timestamp").doubleValue() * 1000);
- position.setTime(deviceTime);
- JsonNumber lat = object.getJsonNumber("position.latitude");
- JsonNumber lon = object.getJsonNumber("position.longitude");
- if (lat != null && lon != null) {
- position.setLatitude(lat.doubleValue());
- position.setLongitude(lon.doubleValue());
- } else {
- getLastLocation(position, deviceTime);
- }
- JsonNumber speed = object.getJsonNumber("position.speed");
- if (speed != null) {
- position.setSpeed(speed.doubleValue());
- }
- JsonNumber course = object.getJsonNumber("position.direction");
- if (course != null) {
- position.setCourse(course.doubleValue());
- }
- JsonNumber altitude = object.getJsonNumber("position.altitude");
- if (altitude != null) {
- position.setAltitude(altitude.doubleValue());
- }
-
- position.setValid(object.getBoolean("position.valid", true));
- position.set(Position.KEY_SATELLITES, object.getInt("position.satellites", 0));
-
- if (object.getBoolean("alarm.event.trigger", false)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- }
-}
diff --git a/src/org/traccar/protocol/FlexCommProtocol.java b/src/org/traccar/protocol/FlexCommProtocol.java
deleted file mode 100644
index 5dba4421a..000000000
--- a/src/org/traccar/protocol/FlexCommProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.FixedLengthFrameDecoder;
-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 FlexCommProtocol extends BaseProtocol {
-
- public FlexCommProtocol() {
- super("flexcomm");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(2 + 2 + 101 + 5));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new FlexCommProtocolDecoder(FlexCommProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/FlexCommProtocolDecoder.java b/src/org/traccar/protocol/FlexCommProtocolDecoder.java
deleted file mode 100644
index f401145b9..000000000
--- a/src/org/traccar/protocol/FlexCommProtocolDecoder.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class FlexCommProtocolDecoder extends BaseProtocolDecoder {
-
- public FlexCommProtocolDecoder(FlexCommProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("7E")
- .number("(dd)") // status
- .number("(d{15})") // imei
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .expression("([01])") // valid
- .number("(d{9})") // latitude
- .number("(d{10})") // longitude
- .number("(d{4})") // altitude
- .number("(ddd)") // speed
- .number("(ddd)") // course
- .number("(dd)") // satellites view
- .number("(dd)") // satellites used
- .number("(dd)") // rssi
- .number("(ddd)") // mcc
- .number("(ddd)") // mnc
- .number("(x{6})") // lac
- .number("(x{6})") // cid
- .expression("([01])([01])([01])") // input
- .expression("([01])([01])") // output
- .number("(ddd)") // fuel
- .number("(d{4})") // temperature
- .number("(ddd)") // battery
- .number("(ddd)") // power
- .any()
- .compile();
-
- private static double parseSignedValue(Parser parser, int decimalPoints) {
- String stringValue = parser.next();
- boolean negative = stringValue.charAt(0) == '1';
- double value = Integer.parseInt(stringValue.substring(1)) * Math.pow(10, -decimalPoints);
- return negative ? -value : value;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Parser parser = new Parser(PATTERN, (String) msg);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_STATUS, parser.nextInt());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
- position.setValid(parser.next().equals("1"));
- position.setLatitude(parseSignedValue(parser, 6));
- position.setLongitude(parseSignedValue(parser, 6));
- position.setAltitude(parseSignedValue(parser, 0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt());
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_RSSI, parser.nextInt());
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
-
- for (int i = 1; i <= 3; i++) {
- position.set(Position.PREFIX_IN + i, parser.nextInt());
- }
-
- for (int i = 1; i <= 2; i++) {
- position.set(Position.PREFIX_OUT + i, parser.nextInt());
- }
-
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
- position.set(Position.PREFIX_TEMP + 1, parseSignedValue(parser, 0));
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
- position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
-
- if (channel != null) {
- channel.write("{01}");
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/FlextrackProtocol.java b/src/org/traccar/protocol/FlextrackProtocol.java
deleted file mode 100644
index 77e316d82..000000000
--- a/src/org/traccar/protocol/FlextrackProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 FlextrackProtocol extends BaseProtocol {
-
- public FlextrackProtocol() {
- super("flextrack");
- }
-
- @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, "\r"));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new FlextrackProtocolDecoder(FlextrackProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
deleted file mode 100644
index ab2e4d24c..000000000
--- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class FlextrackProtocolDecoder extends BaseProtocolDecoder {
-
- public FlextrackProtocolDecoder(FlextrackProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_LOGON = new PatternBuilder()
- .number("(-?d+),") // index
- .text("LOGON,")
- .number("(d+),") // node id
- .number("(d+)") // iccid
- .compile();
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(-?d+),") // index
- .text("UNITSTAT,")
- .number("(dddd)(dd)(dd),") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("d+,") // node id
- .number("([NS])(d+).(d+.d+),") // latitude
- .number("([EW])(d+).(d+.d+),") // longitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(d+),") // satellites
- .number("(d+),") // battery
- .number("(-?d+),") // gsm
- .number("(x+),") // state
- .number("(ddd)") // mcc
- .number("(dd),") // mnc
- .number("(-?d+),") // altitude
- .number("(d+),") // hdop
- .number("(x+),") // cell
- .number("d+,") // gps fix time
- .number("(x+),") // lac
- .number("(d+)") // odometer
- .compile();
-
- private void sendAcknowledgement(Channel channel, String index) {
- if (channel != null) {
- channel.write(index + ",ACK\r");
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.contains("LOGON")) {
-
- Parser parser = new Parser(PATTERN_LOGON, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- sendAcknowledgement(channel, parser.next());
-
- String id = parser.next();
- String iccid = parser.next();
-
- getDeviceSession(channel, remoteAddress, iccid, id);
-
- } else if (sentence.contains("UNITSTAT")) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- sendAcknowledgement(channel, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- int rssi = parser.nextInt(0);
- position.set(Position.KEY_STATUS, parser.nextHexInt(0));
-
- int mcc = parser.nextInt(0);
- int mnc = parser.nextInt(0);
-
- position.setAltitude(parser.nextInt(0));
-
- position.set(Position.KEY_HDOP, parser.nextInt(0) * 0.1);
-
- position.setNetwork(new Network(CellTower.from(
- mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
-
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/FoxProtocol.java b/src/org/traccar/protocol/FoxProtocol.java
deleted file mode 100644
index 501bff4c4..000000000
--- a/src/org/traccar/protocol/FoxProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 FoxProtocol extends BaseProtocol {
-
- public FoxProtocol() {
- super("fox");
- }
-
- @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, "</fox>"));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new FoxProtocolDecoder(FoxProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/FoxProtocolDecoder.java b/src/org/traccar/protocol/FoxProtocolDecoder.java
deleted file mode 100644
index 9b2cf0e1d..000000000
--- a/src/org/traccar/protocol/FoxProtocolDecoder.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.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 FoxProtocolDecoder extends BaseProtocolDecoder {
-
- public FoxProtocolDecoder(FoxProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(d+),") // status id
- .expression("([AV]),") // validity
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .expression("[^,]*,") // cell info
- .number("([01]+) ") // input
- .number("(d+) ") // power
- .number("(d+) ") // temperature
- .number("(d+) ") // rpm
- .number("(d+) ") // fuel
- .number("(d+) ") // adc 1
- .number("(d+) ") // adc 2
- .number("([01]+) ") // output
- .number("(d+),") // odometer
- .expression("(.+)") // status info
- .compile();
-
- private String getAttribute(String xml, String key) {
- int start = xml.indexOf(key + "=\"");
- if (start != -1) {
- start += key.length() + 2;
- int end = xml.indexOf("\"", start);
- if (end != -1) {
- return xml.substring(start, end);
- }
- }
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String xml = (String) msg;
- String id = getAttribute(xml, "id");
- String data = getAttribute(xml, "data");
-
- if (id != null && data != null) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, data);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_STATUS, parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_INPUT, parser.nextBinInt(0));
- position.set(Position.KEY_POWER, parser.nextDouble(0) * 0.1);
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
- position.set(Position.KEY_RPM, parser.nextInt(0));
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
- position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
- position.set(Position.PREFIX_ADC + 2, parser.nextInt(0));
- position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
-
- position.set("statusData", parser.next());
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/FreedomProtocol.java b/src/org/traccar/protocol/FreedomProtocol.java
deleted file mode 100644
index 5b4bf22ff..000000000
--- a/src/org/traccar/protocol/FreedomProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 FreedomProtocol extends BaseProtocol {
-
- public FreedomProtocol() {
- super("freedom");
- }
-
- @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 FreedomProtocolDecoder(FreedomProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java
deleted file mode 100644
index 56b6b9e19..000000000
--- a/src/org/traccar/protocol/FreedomProtocolDecoder.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class FreedomProtocolDecoder extends BaseProtocolDecoder {
-
- public FreedomProtocolDecoder(FreedomProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("IMEI,")
- .number("(d+),") // imei
- .number("(dddd)/(dd)/(dd), ") // date (yyyy/dd/mm)
- .number("(dd):(dd):(dd), ") // time (hh:mm:ss)
- .expression("([NS]), ")
- .number("Lat:(dd)(d+.d+), ") // latitude
- .expression("([EW]), ")
- .number("Lon:(ddd)(d+.d+), ") // longitude
- .text("Spd:").number("(d+.d+)") // speed
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(true);
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
-
- position.setSpeed(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/GalileoFrameDecoder.java b/src/org/traccar/protocol/GalileoFrameDecoder.java
deleted file mode 100644
index 6d02ce744..000000000
--- a/src/org/traccar/protocol/GalileoFrameDecoder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class GalileoFrameDecoder extends FrameDecoder {
-
- private static final int MESSAGE_MINIMUM_LENGTH = 5;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
- return null;
- }
-
- // Read packet
- int length = buf.getUnsignedShort(buf.readerIndex() + 1) & 0x7fff;
- if (buf.readableBytes() >= (length + MESSAGE_MINIMUM_LENGTH)) {
- return buf.readBytes(length + MESSAGE_MINIMUM_LENGTH);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GalileoProtocol.java b/src/org/traccar/protocol/GalileoProtocol.java
deleted file mode 100644
index f76de04a0..000000000
--- a/src/org/traccar/protocol/GalileoProtocol.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class GalileoProtocol extends BaseProtocol {
-
- public GalileoProtocol() {
- super("galileo");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_OUTPUT_CONTROL);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new GalileoFrameDecoder());
- pipeline.addLast("objectEncoder", new GalileoProtocolEncoder());
- pipeline.addLast("objectDecoder", new GalileoProtocolDecoder(GalileoProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
deleted file mode 100644
index 3944b37de..000000000
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class GalileoProtocolDecoder extends BaseProtocolDecoder {
-
- public GalileoProtocolDecoder(GalileoProtocol protocol) {
- super(protocol);
- }
-
- private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>();
-
- static {
- int[] l1 = {
- 0x01, 0x02, 0x35, 0x43, 0xc4, 0xc5, 0xc6, 0xc7,
- 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- 0xd0, 0xd1, 0xd2, 0xd5, 0x88, 0x8a, 0x8b, 0x8c,
- 0xa0, 0xaf, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
- 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae
- };
- int[] l2 = {
- 0x04, 0x10, 0x34, 0x40, 0x41, 0x42, 0x45, 0x46,
- 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x60, 0x61,
- 0x62, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,
- 0x77, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
- 0xb7, 0xb8, 0xb9, 0xd6, 0xd7, 0xd8, 0xd9, 0xda
- };
- int[] l3 = {
- 0x63, 0x64, 0x6f, 0x5d, 0x65, 0x66, 0x67, 0x68,
- 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e
- };
- int[] l4 = {
- 0x20, 0x33, 0x44, 0x90, 0xc0, 0xc2, 0xc3, 0xd3,
- 0xd4, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xf0, 0xf9,
- 0x5a, 0x47, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6,
- 0xf7, 0xf8, 0xe2, 0xe9
- };
- for (int i : l1) {
- TAG_LENGTH_MAP.put(i, 1);
- }
- for (int i : l2) {
- TAG_LENGTH_MAP.put(i, 2);
- }
- for (int i : l3) {
- TAG_LENGTH_MAP.put(i, 3);
- }
- for (int i : l4) {
- TAG_LENGTH_MAP.put(i, 4);
- }
- TAG_LENGTH_MAP.put(0x5b, 7); // variable length
- TAG_LENGTH_MAP.put(0x5c, 68);
- }
-
- private static int getTagLength(int tag) {
- Integer length = TAG_LENGTH_MAP.get(tag);
- if (length == null) {
- throw new IllegalArgumentException("Unknown tag: " + tag);
- }
- return length;
- }
-
- private void sendReply(Channel channel, int checksum) {
- ChannelBuffer reply = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 3);
- reply.writeByte(0x02);
- reply.writeShort((short) checksum);
- if (channel != null) {
- channel.write(reply);
- }
- }
-
- private void decodeTag(Position position, ChannelBuffer buf, int tag) {
- switch (tag) {
- case 0x01:
- position.set(Position.KEY_VERSION_HW, buf.readUnsignedByte());
- break;
- case 0x02:
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
- break;
- case 0x04:
- position.set("deviceId", buf.readUnsignedShort());
- break;
- case 0x10:
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
- break;
- case 0x20:
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- break;
- case 0x33:
- position.setSpeed(buf.readUnsignedShort() * 0.0539957);
- position.setCourse(buf.readUnsignedShort() * 0.1);
- break;
- case 0x34:
- position.setAltitude(buf.readShort());
- break;
- case 0x40:
- position.set(Position.KEY_STATUS, buf.readUnsignedShort());
- break;
- case 0x41:
- position.set(Position.KEY_POWER, buf.readUnsignedShort());
- break;
- case 0x42:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
- break;
- case 0x43:
- position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
- break;
- case 0x44:
- position.set(Position.KEY_ACCELERATION, buf.readUnsignedInt());
- break;
- case 0x45:
- position.set(Position.KEY_OUTPUT, buf.readUnsignedShort());
- break;
- case 0x46:
- position.set(Position.KEY_INPUT, buf.readUnsignedShort());
- break;
- case 0x50:
- case 0x51:
- case 0x52:
- case 0x53:
- case 0x54:
- case 0x55:
- case 0x56:
- case 0x57:
- position.set(Position.PREFIX_ADC + (tag - 0x50), buf.readUnsignedShort());
- break;
- case 0x58:
- position.set("rs2320", buf.readUnsignedShort());
- break;
- case 0x59:
- position.set("rs2321", buf.readUnsignedShort());
- break;
- case 0xc0:
- position.set("fuelTotal", buf.readUnsignedInt() * 0.5);
- break;
- case 0xc1:
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 0.4);
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() - 40);
- position.set(Position.KEY_RPM, buf.readUnsignedShort() * 0.125);
- break;
- case 0xc2:
- position.set("canB0", buf.readUnsignedInt());
- break;
- case 0xc3:
- position.set("canB1", buf.readUnsignedInt());
- break;
- case 0xc4:
- case 0xc5:
- case 0xc6:
- case 0xc7:
- case 0xc8:
- case 0xc9:
- case 0xca:
- case 0xcb:
- case 0xcc:
- case 0xcd:
- case 0xce:
- case 0xcf:
- case 0xd0:
- case 0xd1:
- case 0xd2:
- position.set("can8Bit" + (tag - 0xc4), buf.readUnsignedByte());
- break;
- case 0xd6:
- case 0xd7:
- case 0xd8:
- case 0xd9:
- case 0xda:
- position.set("can16Bit" + (tag - 0xd6), buf.readUnsignedShort());
- break;
- case 0xdb:
- case 0xdc:
- case 0xdd:
- case 0xde:
- case 0xdf:
- position.set("can32Bit" + (tag - 0xdb), buf.readUnsignedInt());
- break;
- case 0xd4:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- break;
- case 0xe0:
- position.set(Position.KEY_INDEX, buf.readUnsignedInt());
- break;
- case 0xe1:
- position.set(Position.KEY_RESULT,
- buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII));
- break;
- case 0xe2:
- case 0xe3:
- case 0xe4:
- case 0xe5:
- case 0xe6:
- case 0xe7:
- case 0xe8:
- case 0xe9:
- position.set("userData" + (tag - 0xe2), buf.readUnsignedInt());
- break;
- case 0xea:
- position.set("userDataArray", ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte())));
- break;
- default:
- buf.skipBytes(getTagLength(tag));
- break;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // header
- int length = (buf.readUnsignedShort() & 0x7fff) + 3;
-
- List<Position> positions = new LinkedList<>();
- Set<Integer> tags = new HashSet<>();
- boolean hasLocation = false;
-
- DeviceSession deviceSession = null;
- Position position = new Position();
-
- while (buf.readerIndex() < length) {
-
- // Check if new message started
- int tag = buf.readUnsignedByte();
- if (tags.contains(tag)) {
- if (hasLocation && position.getFixTime() != null) {
- positions.add(position);
- }
- tags.clear();
- hasLocation = false;
- position = new Position();
- }
- tags.add(tag);
-
- if (tag == 0x03) {
- deviceSession = getDeviceSession(
- channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII));
- } else if (tag == 0x30) {
- hasLocation = true;
- position.setValid((buf.readUnsignedByte() & 0xf0) == 0x00);
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
- } else {
- decodeTag(position, buf, tag);
- }
-
- }
-
- if (hasLocation && position.getFixTime() != null) {
- positions.add(position);
- } else if (position.getAttributes().containsKey(Position.KEY_RESULT)) {
- getLastLocation(position, null);
- positions.add(position);
- }
-
- if (deviceSession == null) {
- deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
- }
-
- sendReply(channel, buf.readUnsignedShort());
-
- for (Position p : positions) {
- p.setProtocol(getProtocolName());
- p.setDeviceId(deviceSession.getDeviceId());
- }
-
- return positions.isEmpty() ? null : positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/GalileoProtocolEncoder.java b/src/org/traccar/protocol/GalileoProtocolEncoder.java
deleted file mode 100644
index cb6028abb..000000000
--- a/src/org/traccar/protocol/GalileoProtocolEncoder.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-
-public class GalileoProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeText(String uniqueId, String text) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 256);
-
- buf.writeByte(0x01);
- buf.writeShort(uniqueId.length() + text.length() + 11); // TODO
-
- buf.writeByte(0x03); // imei tag
- buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII));
-
- buf.writeByte(0x04); // device id tag
- buf.writeShort(0); // not needed if imei provided
-
- buf.writeByte(0xE0); // index tag
- buf.writeInt(0); // index
-
- buf.writeByte(0xE1); // command text tag
- buf.writeByte(text.length());
- buf.writeBytes(text.getBytes(StandardCharsets.US_ASCII));
-
- buf.writeShort(Checksum.crc16(Checksum.CRC16_MODBUS, buf.toByteBuffer(0, buf.writerIndex())));
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeText(getUniqueId(command.getDeviceId()), command.getString(Command.KEY_DATA));
- case Command.TYPE_OUTPUT_CONTROL:
- return encodeText(getUniqueId(command.getDeviceId()),
- "Out " + command.getInteger(Command.KEY_INDEX) + "," + command.getString(Command.KEY_DATA));
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GatorProtocol.java b/src/org/traccar/protocol/GatorProtocol.java
deleted file mode 100644
index 7fa4854d3..000000000
--- a/src/org/traccar/protocol/GatorProtocol.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class GatorProtocol extends BaseProtocol {
-
- public GatorProtocol() {
- super("gator");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2));
- pipeline.addLast("objectDecoder", new GatorProtocolDecoder(GatorProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new GatorProtocolDecoder(GatorProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
deleted file mode 100644
index 2ad4be3d3..000000000
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.BcdUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-
-public class GatorProtocolDecoder extends BaseProtocolDecoder {
-
- public GatorProtocolDecoder(GatorProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_HEARTBEAT = 0x21;
- public static final int MSG_POSITION_DATA = 0x80;
- public static final int MSG_ROLLCALL_RESPONSE = 0x81;
- public static final int MSG_ALARM_DATA = 0x82;
- public static final int MSG_TERMINAL_STATUS = 0x83;
- public static final int MSG_MESSAGE = 0x84;
- public static final int MSG_TERMINAL_ANSWER = 0x85;
- public static final int MSG_BLIND_AREA = 0x8E;
- public static final int MSG_PICTURE_FRAME = 0x54;
- public static final int MSG_CAMERA_RESPONSE = 0x56;
- public static final int MSG_PICTURE_DATA = 0x57;
-
- public static String decodeId(int b1, int b2, int b3, int b4) {
-
- int d1 = 30 + ((b1 >> 7) << 3) + ((b2 >> 7) << 2) + ((b3 >> 7) << 1) + (b4 >> 7);
- int d2 = b1 & 0x7f;
- int d3 = b2 & 0x7f;
- int d4 = b3 & 0x7f;
- int d5 = b4 & 0x7f;
-
- return String.format("%02d%02d%02d%02d%02d", d1, d2, d3, d4, d5);
- }
-
- private void sendResponse(Channel channel, byte calibration) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(0x24); response.writeByte(0x24); // header
- response.writeByte(MSG_HEARTBEAT); // size
- response.writeShort(5);
- response.writeByte(calibration);
- response.writeByte(0); // main order
- response.writeByte(0); // slave order
- response.writeByte(1); // calibration
- response.writeByte(0x0D);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- int type = buf.readUnsignedByte();
- buf.readUnsignedShort(); // length
-
- String id = decodeId(
- buf.readUnsignedByte(), buf.readUnsignedByte(),
- buf.readUnsignedByte(), buf.readUnsignedByte());
-
- sendResponse(channel, buf.getByte(buf.writerIndex() - 2));
-
- if (type == MSG_POSITION_DATA || type == MSG_ROLLCALL_RESPONSE
- || type == MSG_ALARM_DATA || type == MSG_BLIND_AREA) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, "1" + id, id);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
-
- position.setLatitude(BcdUtil.readCoordinate(buf));
- position.setLongitude(BcdUtil.readCoordinate(buf));
- position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
- position.setCourse(BcdUtil.readInteger(buf, 4));
-
- int flags = buf.readUnsignedByte();
- position.setValid((flags & 0x80) != 0);
- position.set(Position.KEY_SATELLITES, flags & 0x0f);
-
- position.set(Position.KEY_STATUS, buf.readUnsignedByte());
- position.set("key", buf.readUnsignedByte());
- position.set("oil", buf.readUnsignedShort() / 10.0);
- position.set(Position.KEY_POWER, buf.readUnsignedByte() + buf.readUnsignedByte() * 0.01);
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GenxProtocol.java b/src/org/traccar/protocol/GenxProtocol.java
deleted file mode 100644
index 2b5b1a43d..000000000
--- a/src/org/traccar/protocol/GenxProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 GenxProtocol extends BaseProtocol {
-
- public GenxProtocol() {
- super("genx");
- }
-
- @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 GenxProtocolDecoder(GenxProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GenxProtocolDecoder.java b/src/org/traccar/protocol/GenxProtocolDecoder.java
deleted file mode 100644
index ebf6f2b53..000000000
--- a/src/org/traccar/protocol/GenxProtocolDecoder.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.text.SimpleDateFormat;
-
-public class GenxProtocolDecoder extends BaseProtocolDecoder {
-
- private int[] reportColumns;
-
- public GenxProtocolDecoder(GenxProtocol protocol) {
- super(protocol);
- setReportColumns(Context.getConfig().getString(getProtocolName() + ".reportColumns", "1,2,3,4"));
- }
-
- public void setReportColumns(String format) {
- String[] columns = format.split(",");
- reportColumns = new int[columns.length];
- for (int i = 0; i < columns.length; i++) {
- reportColumns[i] = Integer.parseInt(columns[i]);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String[] values = ((String) msg).split(",");
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setValid(true);
-
- for (int i = 0; i < Math.min(values.length, reportColumns.length); i++) {
- switch (reportColumns[i]) {
- case 1:
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[i]);
- if (deviceSession != null) {
- position.setDeviceId(deviceSession.getDeviceId());
- }
- break;
- case 2:
- position.setTime(new SimpleDateFormat("MM/dd/yy HH:mm:ss").parse(values[i]));
- break;
- case 3:
- position.setLatitude(Double.parseDouble(values[i]));
- break;
- case 4:
- position.setLongitude(Double.parseDouble(values[i]));
- break;
- case 11:
- position.set(Position.KEY_IGNITION, values[i].equals("ON"));
- break;
- case 13:
- position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[i])));
- break;
- case 17:
- position.setCourse(Integer.parseInt(values[i]));
- break;
- case 23:
- position.set(Position.KEY_ODOMETER, Double.parseDouble(values[i]) * 1000);
- break;
- case 27:
- position.setAltitude(UnitsConverter.metersFromFeet(Integer.parseInt(values[i])));
- break;
- case 46:
- position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i]));
- break;
- default:
- break;
- }
- }
-
- return position.getDeviceId() != 0 ? position : null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl100Protocol.java b/src/org/traccar/protocol/Gl100Protocol.java
deleted file mode 100644
index 0fd18d44f..000000000
--- a/src/org/traccar/protocol/Gl100Protocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.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 Gl100Protocol extends BaseProtocol {
-
- public Gl100Protocol() {
- super("gl100");
- }
-
- @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, '\0'));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(Gl100Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(Gl100Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
deleted file mode 100644
index 945edfff0..000000000
--- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class Gl100ProtocolDecoder extends BaseProtocolDecoder {
-
- public Gl100ProtocolDecoder(Gl100Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("+RESP:")
- .expression("GT...,")
- .number("(d{15}),") // imei
- .groupBegin()
- .number("d+,") // number
- .number("d,") // reserved / geofence id
- .number("d+") // reserved / geofence alert // battery
- .or()
- .number("[^,]*") // calling number
- .groupEnd(",")
- .expression("([01]),") // gps fix
- .number("(d+.d),") // speed
- .number("(d+),") // course
- .number("(-?d+.d),") // altitude
- .number("d*,") // gps accuracy
- .number("(-?d+.d+),") // longitude
- .number("(-?d+.d+),") // latitude
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.contains("AT+GTHBD=") && channel != null) {
- String response = "+RESP:GTHBD,GPRS ACTIVE,";
- response += sentence.substring(9, sentence.lastIndexOf(','));
- response += '\0';
- channel.write(response); // heartbeat response
- }
-
- Parser parser = new Parser(PATTERN, 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.setValid(parser.nextInt(0) == 0);
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java b/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java
deleted file mode 100644
index 071960e49..000000000
--- a/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitBuffer;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder {
-
- public Gl200BinaryProtocolDecoder(Gl200Protocol protocol) {
- super(protocol);
- }
-
- private Date decodeTime(ChannelBuffer buf) {
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- return dateBuilder.getDate();
- }
-
- public static final int MSG_RSP_LCB = 3;
- public static final int MSG_RSP_GEO = 8;
- public static final int MSG_RSP_COMPRESSED = 100;
-
- private List<Position> decodeLocation(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- List<Position> positions = new LinkedList<>();
-
- int type = buf.readUnsignedByte();
-
- buf.readUnsignedInt(); // mask
- buf.readUnsignedShort(); // length
- buf.readUnsignedByte(); // device type
- buf.readUnsignedShort(); // protocol version
- buf.readUnsignedShort(); // firmware version
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
- if (deviceSession == null) {
- return null;
- }
-
- int battery = buf.readUnsignedByte();
- int power = buf.readUnsignedShort();
-
- if (type == MSG_RSP_GEO) {
- buf.readUnsignedByte(); // reserved
- buf.readUnsignedByte(); // reserved
- }
-
- buf.readUnsignedByte(); // motion status
- int satellites = buf.readUnsignedByte();
-
- if (type != MSG_RSP_COMPRESSED) {
- buf.readUnsignedByte(); // index
- }
-
- if (type == MSG_RSP_LCB) {
- buf.readUnsignedByte(); // phone length
- for (int b = buf.readUnsignedByte();; b = buf.readUnsignedByte()) {
- if ((b & 0xf) == 0xf || (b & 0xf0) == 0xf0) {
- break;
- }
- }
- }
-
- if (type == MSG_RSP_COMPRESSED) {
-
- int count = buf.readUnsignedShort();
-
- BitBuffer bits;
- int speed = 0;
- int heading = 0;
- int latitude = 0;
- int longitude = 0;
- long time = 0;
-
- for (int i = 0; i < count; i++) {
-
- if (time > 0) {
- time += 1;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- switch (BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 8 - 2)) {
- case 1:
- bits = new BitBuffer(buf.readBytes(3));
- bits.readUnsigned(2); // point attribute
- bits.readUnsigned(1); // fix type
- speed = bits.readUnsigned(12);
- heading = bits.readUnsigned(9);
- longitude = buf.readInt();
- latitude = buf.readInt();
- if (time == 0) {
- time = buf.readUnsignedInt();
- }
- break;
- case 2:
- bits = new BitBuffer(buf.readBytes(5));
- bits.readUnsigned(2); // point attribute
- bits.readUnsigned(1); // fix type
- speed += bits.readSigned(7);
- heading += bits.readSigned(7);
- longitude += bits.readSigned(12);
- latitude += bits.readSigned(11);
- break;
- default:
- buf.readUnsignedByte(); // invalid or same
- continue;
- }
-
- position.setValid(true);
- position.setTime(new Date(time * 1000));
- position.setSpeed(UnitsConverter.knotsFromKph(speed * 0.1));
- position.setCourse(heading);
- position.setLongitude(longitude * 0.000001);
- position.setLatitude(latitude * 0.000001);
-
- positions.add(position);
-
- }
-
- } else {
-
- int count = buf.readUnsignedByte();
-
- for (int i = 0; i < count; i++) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_BATTERY_LEVEL, battery);
- position.set(Position.KEY_POWER, power);
- position.set(Position.KEY_SATELLITES, satellites);
-
- int hdop = buf.readUnsignedByte();
- position.setValid(hdop > 0);
- position.set(Position.KEY_HDOP, hdop);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedMedium() * 0.1));
- position.setCourse(buf.readUnsignedShort());
- position.setAltitude(buf.readShort());
- position.setLongitude(buf.readInt() * 0.000001);
- position.setLatitude(buf.readInt() * 0.000001);
-
- position.setTime(decodeTime(buf));
-
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort())));
-
- buf.readUnsignedByte(); // reserved
-
- positions.add(position);
-
- }
-
- }
-
- return positions;
- }
-
- public static final int MSG_EVT_BPL = 6;
- public static final int MSG_EVT_VGN = 45;
- public static final int MSG_EVT_VGF = 46;
- public static final int MSG_EVT_UPD = 15;
- public static final int MSG_EVT_IDF = 17;
- public static final int MSG_EVT_GSS = 21;
- public static final int MSG_EVT_GES = 26;
- public static final int MSG_EVT_GPJ = 31;
- public static final int MSG_EVT_RMD = 35;
- public static final int MSG_EVT_JDS = 33;
- public static final int MSG_EVT_CRA = 23;
- public static final int MSG_EVT_UPC = 34;
-
- private Position decodeEvent(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- int type = buf.readUnsignedByte();
-
- buf.readUnsignedInt(); // mask
- buf.readUnsignedShort(); // length
- buf.readUnsignedByte(); // device type
- buf.readUnsignedShort(); // protocol version
-
- position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedShort()));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- position.set(Position.KEY_POWER, buf.readUnsignedShort());
-
- buf.readUnsignedByte(); // motion status
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- switch (type) {
- case MSG_EVT_BPL:
- buf.readUnsignedShort(); // backup battery voltage
- break;
- case MSG_EVT_VGN:
- case MSG_EVT_VGF:
- buf.readUnsignedShort(); // reserved
- buf.readUnsignedByte(); // report type
- buf.readUnsignedInt(); // ignition duration
- break;
- case MSG_EVT_UPD:
- buf.readUnsignedShort(); // code
- buf.readUnsignedByte(); // retry
- break;
- case MSG_EVT_IDF:
- buf.readUnsignedInt(); // idling duration
- break;
- case MSG_EVT_GSS:
- buf.readUnsignedByte(); // gps signal status
- buf.readUnsignedInt(); // reserved
- break;
- case MSG_EVT_GES:
- buf.readUnsignedShort(); // trigger geo id
- buf.readUnsignedByte(); // trigger geo enable
- buf.readUnsignedByte(); // trigger mode
- buf.readUnsignedInt(); // radius
- buf.readUnsignedInt(); // check interval
- break;
- case MSG_EVT_GPJ:
- buf.readUnsignedByte(); // cw jamming value
- buf.readUnsignedByte(); // gps jamming state
- break;
- case MSG_EVT_RMD:
- buf.readUnsignedByte(); // roaming state
- break;
- case MSG_EVT_JDS:
- buf.readUnsignedByte(); // jamming state
- break;
- case MSG_EVT_CRA:
- buf.readUnsignedByte(); // crash counter
- break;
- case MSG_EVT_UPC:
- buf.readUnsignedByte(); // command id
- buf.readUnsignedShort(); // result
- break;
- default:
- break;
- }
-
- buf.readUnsignedByte(); // count
-
- int hdop = buf.readUnsignedByte();
- position.setValid(hdop > 0);
- position.set(Position.KEY_HDOP, hdop);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedMedium() * 0.1));
- position.setCourse(buf.readUnsignedShort());
- position.setAltitude(buf.readShort());
- position.setLongitude(buf.readInt() * 0.000001);
- position.setLatitude(buf.readInt() * 0.000001);
-
- position.setTime(decodeTime(buf));
-
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort())));
-
- buf.readUnsignedByte(); // reserved
-
- return position;
- }
-
- public static final int MSG_INF_GPS = 2;
- public static final int MSG_INF_CID = 4;
- public static final int MSG_INF_CSQ = 5;
- public static final int MSG_INF_VER = 6;
- public static final int MSG_INF_BAT = 7;
- public static final int MSG_INF_TMZ = 9;
- public static final int MSG_INF_GIR = 10;
-
- private Position decodeInformation(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- int type = buf.readUnsignedByte();
-
- buf.readUnsignedInt(); // mask
- buf.readUnsignedShort(); // length
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedByte(); // device type
- buf.readUnsignedShort(); // protocol version
-
- position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedShort()));
-
- if (type == MSG_INF_VER) {
- buf.readUnsignedShort(); // hardware version
- buf.readUnsignedShort(); // mcu version
- buf.readUnsignedShort(); // reserved
- }
-
- buf.readUnsignedByte(); // motion status
- buf.readUnsignedByte(); // reserved
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- buf.readUnsignedByte(); // mode
- buf.skipBytes(7); // last fix time
- buf.readUnsignedByte(); // reserved
- buf.readUnsignedByte();
- buf.readUnsignedShort(); // response report mask
- buf.readUnsignedShort(); // ign interval
- buf.readUnsignedShort(); // igf interval
- buf.readUnsignedInt(); // reserved
- buf.readUnsignedByte(); // reserved
-
- if (type == MSG_INF_BAT) {
- position.set(Position.KEY_CHARGE, buf.readUnsignedByte() != 0);
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
- }
-
- buf.skipBytes(10); // iccid
-
- if (type == MSG_INF_CSQ) {
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- buf.readUnsignedByte();
- }
-
- buf.readUnsignedByte(); // time zone flags
- buf.readUnsignedShort(); // time zone offset
-
- if (type == MSG_INF_GIR) {
- buf.readUnsignedByte(); // gir trigger
- buf.readUnsignedByte(); // cell number
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort())));
- buf.readUnsignedByte(); // ta
- buf.readUnsignedByte(); // rx level
- }
-
- getLastLocation(position, decodeTime(buf));
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- switch (buf.readBytes(4).toString(StandardCharsets.US_ASCII)) {
- case "+RSP":
- return decodeLocation(channel, remoteAddress, buf);
- case "+INF":
- return decodeInformation(channel, remoteAddress, buf);
- case "+EVT":
- return decodeEvent(channel, remoteAddress, buf);
- default:
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl200FrameDecoder.java b/src/org/traccar/protocol/Gl200FrameDecoder.java
deleted file mode 100644
index 960c3779a..000000000
--- a/src/org/traccar/protocol/Gl200FrameDecoder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-public class Gl200FrameDecoder extends FrameDecoder {
-
- private static final int MINIMUM_LENGTH = 11;
-
- private static final Set<String> BINARY_HEADERS = new HashSet<>(
- Arrays.asList("+RSP", "+BSP", "+EVT", "+BVT", "+INF", "+BNF", "+HBD", "+CRD", "+BRD"));
-
- public static boolean isBinary(ChannelBuffer buf) {
- String header = buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII);
- if (header.equals("+ACK")) {
- return buf.getByte(buf.readerIndex() + header.length()) != (byte) ':';
- } else {
- return BINARY_HEADERS.contains(header);
- }
- }
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < MINIMUM_LENGTH) {
- return null;
- }
-
- if (isBinary(buf)) {
-
- int length;
- switch (buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII)) {
- case "+ACK":
- length = buf.getUnsignedByte(buf.readerIndex() + 6);
- break;
- case "+INF":
- case "+BNF":
- length = buf.getUnsignedShort(buf.readerIndex() + 7);
- break;
- case "+HBD":
- length = buf.getUnsignedByte(buf.readerIndex() + 5);
- break;
- case "+CRD":
- case "+BRD":
- length = buf.getUnsignedShort(buf.readerIndex() + 6);
- break;
- default:
- length = buf.getUnsignedShort(buf.readerIndex() + 9);
- break;
- }
-
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- } else {
-
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '$');
- if (endIndex < 0) {
- endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
- }
- if (endIndex > 0) {
- ChannelBuffer frame = buf.readBytes(endIndex - buf.readerIndex());
- buf.readByte(); // delimiter
- return frame;
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl200Protocol.java b/src/org/traccar/protocol/Gl200Protocol.java
deleted file mode 100644
index 799d7fe36..000000000
--- a/src/org/traccar/protocol/Gl200Protocol.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.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;
-
-public class Gl200Protocol extends BaseProtocol {
-
- public Gl200Protocol() {
- super("gl200");
- setSupportedDataCommands(
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_IDENTIFICATION,
- Command.TYPE_REBOOT_DEVICE);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Gl200FrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new Gl200ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(Gl200Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new Gl200ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(Gl200Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
deleted file mode 100644
index 0de7bb926..000000000
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-
-import java.net.SocketAddress;
-
-public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
-
- private final Gl200TextProtocolDecoder textProtocolDecoder;
- private final Gl200BinaryProtocolDecoder binaryProtocolDecoder;
-
- public Gl200ProtocolDecoder(Gl200Protocol protocol) {
- super(protocol);
- textProtocolDecoder = new Gl200TextProtocolDecoder(protocol);
- binaryProtocolDecoder = new Gl200BinaryProtocolDecoder(protocol);
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (Gl200FrameDecoder.isBinary(buf)) {
- return binaryProtocolDecoder.decode(channel, remoteAddress, msg);
- } else {
- return textProtocolDecoder.decode(channel, remoteAddress, msg);
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl200ProtocolEncoder.java b/src/org/traccar/protocol/Gl200ProtocolEncoder.java
deleted file mode 100644
index 2c8efa318..000000000
--- a/src/org/traccar/protocol/Gl200ProtocolEncoder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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 Gl200ProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- initDevicePassword(command, "");
-
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "AT+GTRTO={%s},1,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_ENGINE_STOP:
- 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 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 formatCommand(command, "AT+GTRTO={%s},3,,,,,,FFFF$", Command.KEY_DEVICE_PASSWORD);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
deleted file mode 100644
index 2f03cbb8f..000000000
--- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
+++ /dev/null
@@ -1,917 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-import org.traccar.model.WifiAccessPoint;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
-
- private boolean ignoreFixTime;
-
- public Gl200TextProtocolDecoder(Gl200Protocol protocol) {
- super(protocol);
-
- ignoreFixTime = Context.getConfig().getBoolean(getProtocolName() + ".ignoreFixTime");
- }
-
- 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("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(xxxx)") // counter
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_INF = new PatternBuilder()
- .text("+").expression("(?:RESP|BUFF):GTINF,")
- .number("[0-9A-Z]{2}xxxx,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("(?:[0-9A-Z]{17},)?") // vin
- .expression("(?:[^,]+)?,") // device name
- .number("(xx),") // state
- .expression("(?:[0-9Ff]{20})?,") // iccid
- .number("(d{1,2}),") // rssi
- .number("d{1,2},")
- .expression("[01],") // external power
- .number("([d.]+)?,") // odometer or external power
- .number("d*,") // backup battery or lightness
- .number("(d+.d+),") // battery
- .expression("([01]),") // charging
- .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
- .groupBegin()
- .number("(d+),") // battery percentage
- .number("[d.]*,") // flash type / power
- .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 (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .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 (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(xxxx)") // counter
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_LOCATION = new PatternBuilder()
- .number("(d{1,2})?,") // hdop
- .number("(d{1,3}.d)?,") // speed
- .number("(d{1,3})?,") // course
- .number("(-?d{1,5}.d)?,") // altitude
- .number("(-?d{1,3}.d{6})?,") // longitude
- .number("(-?d{1,2}.d{6})?,") // latitude
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(d+)?,") // mcc
- .number("(d+)?,") // mnc
- .groupBegin()
- .number("(d+),") // lac
- .number("(d+),") // cid
- .or()
- .number("(x+)?,") // lac
- .number("(x+)?,") // cid
- .groupEnd()
- .number("(?:d+|(d+.d))?,") // odometer
- .compile();
-
- private static final Pattern PATTERN_OBD = new PatternBuilder()
- .text("+RESP:GTOBD,")
- .number("[0-9A-Z]{2}xxxx,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("(?:[0-9A-Z]{17})?,") // vin
- .expression("[^,]{0,20},") // device name
- .expression("[01],") // report type
- .number("x{1,8},") // report mask
- .expression("(?:[0-9A-Z]{17})?,") // vin
- .number("[01],") // obd connect
- .number("(?:d{1,5})?,") // obd voltage
- .number("(?:x{8})?,") // support pids
- .number("(d{1,5})?,") // engine rpm
- .number("(d{1,3})?,") // speed
- .number("(-?d{1,3})?,") // coolant temp
- .number("(d+.?d*|Inf|NaN)?,") // fuel consumption
- .number("(d{1,5})?,") // dtcs cleared distance
- .number("(?:d{1,5})?,")
- .expression("([01])?,") // obd connect
- .number("(d{1,3})?,") // number of dtcs
- .number("(x*),") // dtcs
- .number("(d{1,3})?,") // throttle
- .number("(?:d{1,3})?,") // engine load
- .number("(d{1,3})?,") // fuel level
- .expression("(?:[0-9A],)?") // obd protocol
- .number("(d+),") // odometer
- .expression(PATTERN_LOCATION.pattern())
- .number("(d{1,7}.d)?,") // odometer
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_FRI = new PatternBuilder()
- .text("+").expression("(?:RESP|BUFF):GTFRI,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("(?:([0-9A-Z]{17}),)?") // vin
- .expression("[^,]*,") // device name
- .number("(d+)?,") // power
- .number("d{1,2},") // report type
- .number("d{1,2},") // count
- .expression("((?:")
- .expression(PATTERN_LOCATION.pattern())
- .expression(")+)")
- .groupBegin()
- .number("(d{1,7}.d)?,").optional() // odometer
- .number("(d{1,3})?,") // battery
- .or()
- .number("(d{1,7}.d)?,") // odometer
- .number("(d{5}:dd:dd)?,") // hour meter
- .number("(x+)?,") // adc 1
- .number("(x+)?,") // adc 2
- .number("(d{1,3})?,") // battery
- .number("(?:(xx)(xx)(xx))?,") // device status
- .number("(d+)?,") // rpm
- .number("(?:d+.?d*|Inf|NaN)?,") // fuel consumption
- .number("(d+)?,") // fuel level
- .groupEnd()
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_ERI = new PatternBuilder()
- .text("+").expression("(?:RESP|BUFF):GTERI,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("[^,]*,") // device name
- .number("x{8},") // mask
- .number("(d+)?,") // power
- .number("d{1,2},") // report type
- .number("d{1,2},") // count
- .expression("((?:")
- .expression(PATTERN_LOCATION.pattern())
- .expression(")+)")
- .number("(d{1,7}.d)?,") // odometer
- .number("(d{5}:dd:dd)?,") // hour meter
- .number("(x+)?,") // adc 1
- .number("(x+)?,") // adc 2
- .number("(d{1,3})?,") // battery
- .number("(?:(xx)(xx)(xx))?,") // device status
- .expression("(.*)") // additional data
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- 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}|x{14}),") // imei
- .expression("[^,]*,") // device name
- .number("d+,") // ignition off duration
- .expression(PATTERN_LOCATION.pattern())
- .number("(d{5}:dd:dd)?,") // hour meter
- .number("(d{1,7}.d)?,") // odometer
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_IDA = new PatternBuilder()
- .text("+RESP:GTIDA,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("[^,]*,,") // device name
- .number("([^,]+),") // rfid
- .expression("[01],") // report type
- .number("1,") // count
- .expression(PATTERN_LOCATION.pattern())
- .number("(d+.d),") // odometer
- .text(",,,,")
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_WIF = new PatternBuilder()
- .text("+RESP:GTWIF,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("[^,]*,") // device name
- .number("(d+),") // count
- .number("((?:x{12},-?d+,,,,)+),,,,") // wifi
- .number("(d{1,3}),") // battery
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_GSM = new PatternBuilder()
- .text("+RESP:GTGSM,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("(?:STR|CTN|NMR|RTL),") // fix type
- .expression("(.*)") // cells
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("+").expression("(?:RESP|BUFF):GT...,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .number("(d{15}|x{14}),") // imei
- .expression("[^,]*,") // device name
- .number("d*,")
- .number("(d{1,2}),") // report type
- .number("d{1,2},") // count
- .expression(PATTERN_LOCATION.pattern())
- .groupBegin()
- .number("(d{1,7}.d)?,").optional() // odometer
- .number("(d{1,3})?,") // battery
- .or()
- .number("(d{1,7}.d)?,") // odometer
- .groupEnd()
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- private static final Pattern PATTERN_BASIC = new PatternBuilder()
- .text("+").expression("(?:RESP|BUFF)").text(":")
- .expression("GT...,")
- .number("(?:[0-9A-Z]{2}xxxx)?,").optional() // protocol version
- .number("(d{15}|x{14}),") // imei
- .any()
- .number("(d{1,2})?,") // hdop
- .number("(d{1,3}.d)?,") // speed
- .number("(d{1,3})?,") // course
- .number("(-?d{1,5}.d)?,") // altitude
- .number("(-?d{1,3}.d{6})?,") // longitude
- .number("(-?d{1,2}.d{6})?,") // latitude
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(x+),") // lac
- .number("(x+),").optional(4) // cell
- .any()
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd)").optional(2) // time (hhmmss)
- .text(",")
- .number("(xxxx)") // count number
- .text("$").optional()
- .compile();
-
- 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());
- getLastLocation(position, parser.nextDateTime());
- position.setValid(false);
- position.set(Position.KEY_RESULT, "Command " + type + " accepted");
- return position;
- }
- }
- return null;
- }
-
- private Position initPosition(Parser parser, Channel channel, SocketAddress remoteAddress) {
- if (parser.matches()) {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession != null) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- return position;
- }
- }
- return null;
- }
-
- private void decodeDeviceTime(Position position, Parser parser) {
- if (parser.hasNext(6)) {
- if (ignoreFixTime) {
- position.setTime(parser.nextDateTime());
- } else {
- position.setDeviceTime(parser.nextDateTime());
- }
- }
- }
-
- private Object decodeInf(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_INF, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- switch (parser.nextHexInt()) {
- case 0x16:
- case 0x1A:
- case 0x12:
- position.set(Position.KEY_IGNITION, false);
- position.set(Position.KEY_MOTION, true);
- break;
- case 0x11:
- position.set(Position.KEY_IGNITION, false);
- position.set(Position.KEY_MOTION, false);
- break;
- case 0x21:
- position.set(Position.KEY_IGNITION, true);
- position.set(Position.KEY_MOTION, false);
- break;
- case 0x22:
- position.set(Position.KEY_IGNITION, true);
- position.set(Position.KEY_MOTION, true);
- break;
- case 0x41:
- position.set(Position.KEY_MOTION, false);
- break;
- case 0x42:
- position.set(Position.KEY_MOTION, true);
- break;
- default:
- break;
- }
-
- position.set(Position.KEY_RSSI, parser.nextInt());
-
- parser.next(); // odometer or external power
-
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
-
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
-
- 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());
-
- getLastLocation(position, parser.nextDateTime());
-
- position.set(Position.KEY_INDEX, parser.nextHexInt(0));
-
- return position;
- }
-
- private Object decodeVer(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_VER, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- position.set("deviceType", parser.next());
- position.set(Position.KEY_VERSION_FW, parser.nextHexInt(0));
- position.set(Position.KEY_VERSION_HW, parser.nextHexInt(0));
-
- getLastLocation(position, parser.nextDateTime());
-
- return position;
- }
-
- private void decodeLocation(Position position, Parser parser) {
- int hdop = parser.nextInt(0);
- position.setValid(hdop > 0);
- position.set(Position.KEY_HDOP, hdop);
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- if (parser.hasNext(8)) {
- position.setValid(true);
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
- position.setTime(parser.nextDateTime());
- } else {
- getLastLocation(position, null);
- }
-
- if (parser.hasNext(6)) {
- int mcc = parser.nextInt(0);
- int mnc = parser.nextInt(0);
- if (parser.hasNext(2)) {
- position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(0), parser.nextInt(0))));
- }
- if (parser.hasNext(2)) {
- position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0))));
- }
- }
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- }
-
- private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_OBD, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- position.set(Position.KEY_RPM, parser.nextInt());
- position.set(Position.KEY_OBD_SPEED, parser.nextInt());
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt());
- position.set(Position.KEY_FUEL_CONSUMPTION, parser.next());
- position.set("dtcsClearedDistance", parser.nextInt());
- position.set("odbConnect", parser.nextInt(0) == 1);
- position.set("dtcsNumber", parser.nextInt());
- position.set("dtcsCodes", parser.next());
- position.set(Position.KEY_THROTTLE, parser.nextInt());
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
- position.set(Position.KEY_OBD_ODOMETER, parser.nextInt(0) * 1000);
-
- decodeLocation(position, parser);
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
-
- decodeDeviceTime(position, parser);
-
- return position;
- }
-
- private void decodeStatus(Position position, Parser parser) {
- if (parser.hasNext(3)) {
- int ignition = parser.nextHexInt(0);
- if (BitUtil.check(ignition, 4)) {
- position.set(Position.KEY_IGNITION, false);
- } else if (BitUtil.check(ignition, 5)) {
- position.set(Position.KEY_IGNITION, true);
- }
- position.set(Position.KEY_INPUT, parser.nextHexInt(0));
- position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
- }
- }
-
- private Object decodeFri(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_FRI, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- LinkedList<Position> positions = new LinkedList<>();
-
- String vin = parser.next();
- int power = parser.nextInt(0);
-
- Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
- while (itemParser.find()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_VIN, vin);
-
- decodeLocation(position, itemParser);
-
- positions.add(position);
- }
-
- Position position = positions.getLast();
-
- decodeLocation(position, parser);
-
- // power value only on some devices
- if (power > 10) {
- position.set(Position.KEY_POWER, power);
- }
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_HOURS, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
-
- decodeStatus(position, parser);
-
- position.set(Position.KEY_RPM, parser.nextInt());
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
-
- decodeDeviceTime(position, parser);
- if (ignoreFixTime) {
- positions.clear();
- positions.add(position);
- }
-
- return positions;
- }
-
- private Object decodeEri(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_ERI, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- LinkedList<Position> positions = new LinkedList<>();
-
- int power = parser.nextInt(0);
-
- Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
- while (itemParser.find()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- decodeLocation(position, itemParser);
-
- positions.add(position);
- }
-
- Position position = positions.getLast();
-
- decodeLocation(position, parser);
-
- position.set(Position.KEY_POWER, power);
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_HOURS, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
-
- decodeStatus(position, parser);
-
- int index = 0;
- String[] data = parser.next().split(",");
- if (data.length > 1) {
- int deviceType = Integer.parseInt(data[index++]);
- if (deviceType == 2) {
- int deviceCount = Integer.parseInt(data[index++]);
- for (int i = 1; i <= deviceCount; i++) {
- index++; // id
- index++; // type
- position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index++], 16) * 0.0625);
- }
- }
- }
-
- decodeDeviceTime(position, parser);
- if (ignoreFixTime) {
- positions.clear();
- positions.add(position);
- }
-
- return positions;
- }
-
- private Object decodeIgn(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_IGN, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- decodeLocation(position, parser);
-
- position.set(Position.KEY_HOURS, parser.next());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
-
- decodeDeviceTime(position, parser);
-
- return position;
- }
-
- private Object decodeIda(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_IDA, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- decodeLocation(position, parser);
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
-
- decodeDeviceTime(position, parser);
-
- return position;
- }
-
- private Object decodeWif(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_WIF, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- getLastLocation(position, null);
-
- Network network = new Network();
-
- parser.nextInt(0); // count
- Matcher matcher = Pattern.compile("([0-9a-fA-F]{12}),(-?\\d+),,,,").matcher(parser.next());
- while (matcher.find()) {
- String mac = matcher.group(1).replaceAll("(..)", "$1:");
- network.addWifiAccessPoint(WifiAccessPoint.from(
- mac.substring(0, mac.length() - 1), Integer.parseInt(matcher.group(2))));
- }
-
- position.setNetwork(network);
-
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
-
- return position;
- }
-
- private Object decodeGsm(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_GSM, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- getLastLocation(position, null);
-
- Network network = new Network();
-
- String[] data = parser.next().split(",");
- for (int i = 0; i < 6; i++) {
- if (!data[i * 6].isEmpty()) {
- network.addCellTower(CellTower.from(
- Integer.parseInt(data[i * 6]), Integer.parseInt(data[i * 6 + 1]),
- Integer.parseInt(data[i * 6 + 2], 16), Integer.parseInt(data[i * 6 + 3], 16),
- Integer.parseInt(data[i * 6 + 4])));
- }
- }
-
- position.setNetwork(network);
-
- return position;
- }
-
- private Object decodeOther(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
- Parser parser = new Parser(PATTERN, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- int reportType = parser.nextInt(0);
- if (type.equals("NMR")) {
- position.set(Position.KEY_MOTION, reportType == 1);
- } else if (type.equals("SOS")) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
-
- decodeLocation(position, parser);
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
-
- decodeDeviceTime(position, parser);
-
- if (Context.getConfig().getBoolean(getProtocolName() + ".ack") && channel != null) {
- channel.write("+SACK:" + parser.next() + "$", remoteAddress);
- }
-
- return position;
- }
-
- private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
- Parser parser = new Parser(PATTERN_BASIC, sentence);
- Position position = initPosition(parser, channel, remoteAddress);
- if (position == null) {
- return null;
- }
-
- int hdop = parser.nextInt(0);
- position.setValid(hdop > 0);
- position.set(Position.KEY_HDOP, hdop);
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- if (parser.hasNext(2)) {
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
- } else {
- getLastLocation(position, null);
- }
-
- if (parser.hasNext(6)) {
- position.setTime(parser.nextDateTime());
- }
-
- if (parser.hasNext(4)) {
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
- }
-
- decodeDeviceTime(position, parser);
-
- switch (type) {
- case "PNA":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON);
- break;
- case "PFA":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
- break;
- case "EPN":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
- break;
- case "EPF":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "BPL":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "STT":
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- break;
- case "SWG":
- position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE);
- break;
- case "TMP":
- 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;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = ((ChannelBuffer) msg).toString(StandardCharsets.US_ASCII);
-
- int typeIndex = sentence.indexOf(":GT");
- if (typeIndex < 0) {
- return null;
- }
-
- Object result;
- String type = sentence.substring(typeIndex + 3, typeIndex + 6);
- 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 "ERI":
- result = decodeEri(channel, remoteAddress, sentence);
- break;
- case "IGN":
- case "IGF":
- result = decodeIgn(channel, remoteAddress, sentence);
- break;
- case "IDA":
- result = decodeIda(channel, remoteAddress, sentence);
- break;
- case "WIF":
- result = decodeWif(channel, remoteAddress, sentence);
- break;
- case "GSM":
- result = decodeGsm(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, 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);
- }
- }
- }
- }
-
- return result;
- }
-
-}
diff --git a/src/org/traccar/protocol/GlobalSatProtocol.java b/src/org/traccar/protocol/GlobalSatProtocol.java
deleted file mode 100644
index f3d07fc96..000000000
--- a/src/org/traccar/protocol/GlobalSatProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 GlobalSatProtocol extends BaseProtocol {
-
- public GlobalSatProtocol() {
- super("globalsat");
- }
-
- @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 GlobalSatProtocolDecoder(GlobalSatProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
deleted file mode 100644
index c45a937d4..000000000
--- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * 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.
- * 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.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
-
- private String format0;
- private String format1;
-
- public GlobalSatProtocolDecoder(GlobalSatProtocol protocol) {
- super(protocol);
-
- format0 = Context.getConfig().getString(getProtocolName() + ".format0", "TSPRXAB27GHKLMnaicz*U!");
- format1 = Context.getConfig().getString(getProtocolName() + ".format1", "SARY*U!");
- }
-
- public void setFormat0(String format) {
- format0 = format;
- }
-
- public void setFormat1(String format) {
- format1 = format;
- }
-
- private Position decodeOriginal(Channel channel, SocketAddress remoteAddress, String sentence) {
-
- if (channel != null) {
- channel.write("ACK\r");
- }
-
- String format;
- if (sentence.startsWith("GSr")) {
- format = format0;
- } else if (sentence.startsWith("GSh")) {
- format = format1;
- } else {
- return null;
- }
-
- // Check that message contains required parameters
- if (!format.contains("B") || !format.contains("S") || !(format.contains("1")
- || format.contains("2") || format.contains("3")) || !(format.contains("6")
- || format.contains("7") || format.contains("8"))) {
- return null;
- }
-
- if (format.contains("*")) {
- format = format.substring(0, format.indexOf('*'));
- sentence = sentence.substring(0, sentence.indexOf('*'));
- }
- String[] values = sentence.split(",");
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- for (int formatIndex = 0, valueIndex = 1; formatIndex < format.length()
- && valueIndex < values.length; formatIndex++) {
- String value = values[valueIndex];
-
- switch (format.charAt(formatIndex)) {
- case 'S':
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
- break;
- case 'A':
- if (value.isEmpty()) {
- position.setValid(false);
- } else {
- position.setValid(Integer.parseInt(value) != 1);
- }
- break;
- case 'B':
- DateBuilder dateBuilder = new DateBuilder()
- .setDay(Integer.parseInt(value.substring(0, 2)))
- .setMonth(Integer.parseInt(value.substring(2, 4)))
- .setYear(Integer.parseInt(value.substring(4)));
- value = values[++valueIndex];
- dateBuilder
- .setHour(Integer.parseInt(value.substring(0, 2)))
- .setMinute(Integer.parseInt(value.substring(2, 4)))
- .setSecond(Integer.parseInt(value.substring(4)));
- position.setTime(dateBuilder.getDate());
- break;
- case 'C':
- valueIndex += 1;
- break;
- case '1':
- double longitude = Double.parseDouble(value.substring(1));
- if (value.charAt(0) == 'W') {
- longitude = -longitude;
- }
- position.setLongitude(longitude);
- break;
- case '2':
- longitude = Double.parseDouble(value.substring(4)) / 60;
- longitude += Integer.parseInt(value.substring(1, 4));
- if (value.charAt(0) == 'W') {
- longitude = -longitude;
- }
- position.setLongitude(longitude);
- break;
- case '3':
- position.setLongitude(Double.parseDouble(value) * 0.000001);
- break;
- case '6':
- double latitude = Double.parseDouble(value.substring(1));
- if (value.charAt(0) == 'S') {
- latitude = -latitude;
- }
- position.setLatitude(latitude);
- break;
- case '7':
- latitude = Double.parseDouble(value.substring(3)) / 60;
- latitude += Integer.parseInt(value.substring(1, 3));
- if (value.charAt(0) == 'S') {
- latitude = -latitude;
- }
- position.setLatitude(latitude);
- break;
- case '8':
- position.setLatitude(Double.parseDouble(value) * 0.000001);
- break;
- case 'G':
- position.setAltitude(Double.parseDouble(value));
- break;
- case 'H':
- position.setSpeed(Double.parseDouble(value));
- break;
- case 'I':
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(value)));
- break;
- case 'J':
- position.setSpeed(UnitsConverter.knotsFromMph(Double.parseDouble(value)));
- break;
- case 'K':
- position.setCourse(Double.parseDouble(value));
- break;
- case 'N':
- if (value.endsWith("mV")) {
- position.set(Position.KEY_BATTERY,
- Integer.parseInt(value.substring(0, value.length() - 2)) / 1000.0);
- } else {
- position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(value));
- }
- break;
- default:
- // Unsupported
- break;
- }
-
- valueIndex += 1;
- }
- return position;
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$")
- .number("(d+),") // imei
- .number("d+,") // mode
- .number("(d+),") // fix
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([EW])")
- .number("(ddd)(dd.d+),") // longitude (dddmm.mmmm)
- .expression("([NS])")
- .number("(dd)(dd.d+),") // latitude (ddmm.mmmm)
- .number("(d+.?d*),") // altitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*)?,") // course
- .number("(d+)[,*]") // satellites
- .number("(d+.?d*)") // hdop
- .compile();
-
- private Position decodeAlternative(Channel channel, SocketAddress remoteAddress, String sentence) {
-
- Parser parser = new Parser(PATTERN, 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.setValid(!parser.next().equals("1"));
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_HDOP, parser.nextDouble());
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("GS")) {
- return decodeOriginal(channel, remoteAddress, sentence);
- } else if (sentence.startsWith("$")) {
- return decodeAlternative(channel, remoteAddress, sentence);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GnxProtocol.java b/src/org/traccar/protocol/GnxProtocol.java
deleted file mode 100644
index 84af24000..000000000
--- a/src/org/traccar/protocol/GnxProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 GnxProtocol extends BaseProtocol {
-
- public GnxProtocol() {
- super("gnx");
- }
-
- @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, "\n\r"));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new GnxProtocolDecoder(GnxProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java
deleted file mode 100644
index 2274ec164..000000000
--- a/src/org/traccar/protocol/GnxProtocolDecoder.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class GnxProtocolDecoder extends BaseProtocolDecoder {
-
- public GnxProtocolDecoder(GnxProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_LOCATION = new PatternBuilder()
- .number("(d+),") // imei
- .number("d+,") // length
- .expression("([01]),") // history
- .number("(dd)(dd)(dd),") // device time (hhmmss)
- .number("(dd)(dd)(dd),") // device date (ddmmyy)
- .number("(dd)(dd)(dd),") // fix time (hhmmss)
- .number("(dd)(dd)(dd),") // fix date (ddmmyy)
- .number("(d),") // valid
- .number("(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd.d+),") // longitude
- .expression("([EW]),")
- .compile();
-
- private static final Pattern PATTERN_MIF = new PatternBuilder()
- .text("$GNX_MIF,")
- .expression(PATTERN_LOCATION.pattern())
- .expression("[01],") // valid card
- .expression("([^,]+),") // rfid
- .any()
- .compile();
-
- private static final Pattern PATTERN_OTHER = new PatternBuilder()
- .text("$GNX_")
- .expression("...,")
- .expression(PATTERN_LOCATION.pattern())
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
- String type = sentence.substring(5, 8);
-
- Pattern pattern;
- if (type.equals("MIF")) {
- pattern = PATTERN_MIF;
- } else {
- pattern = PATTERN_OTHER;
- }
-
- Parser parser = new Parser(pattern, 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());
-
- if (parser.nextInt(0) == 1) {
- position.set(Position.KEY_ARCHIVE, true);
- }
-
- position.setDeviceTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "GMT+5:30"));
- position.setFixTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "GMT+5:30"));
-
- position.setValid(parser.nextInt(0) != 0);
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
-
- if (type.equals("MIF")) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/GoSafeProtocol.java b/src/org/traccar/protocol/GoSafeProtocol.java
deleted file mode 100644
index bfd473df9..000000000
--- a/src/org/traccar/protocol/GoSafeProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 GoSafeProtocol extends BaseProtocol {
-
- public GoSafeProtocol() {
- super("gosafe");
- }
-
- @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 GoSafeProtocolDecoder(GoSafeProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
deleted file mode 100644
index f9aaae0ce..000000000
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
-
- public GoSafeProtocolDecoder(GoSafeProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("*GS") // header
- .number("d+,") // protocol version
- .number("(d+),") // imei
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .expression("(.*)#?") // data
- .compile();
-
- private static final Pattern PATTERN_ITEM = new PatternBuilder()
- .number("(x+)?,").optional() // event
- .groupBegin()
- .text("SYS:")
- .expression("[^,]*,")
- .groupEnd("?")
- .groupBegin()
- .text("GPS:")
- .expression("([AV]);") // validity
- .number("(d+);") // satellites
- .number("([NS])(d+.d+);") // latitude
- .number("([EW])(d+.d+);") // longitude
- .number("(d+)?;") // speed
- .number("(d+);") // course
- .number("(d+);") // altitude
- .number("(d+.d+)") // hdop
- .number(";(d+.d+)").optional() // vdop
- .expression(",?")
- .groupEnd()
- .groupBegin()
- .text("GSM:")
- .number("d*;") // registration
- .number("d*;") // gsm signal
- .number("(d+);") // mcc
- .number("(d+);") // mnc
- .number("(x+);") // lac
- .number("(x+);") // cid
- .number("(-d+)") // rssi
- .expression("[^,]*,?")
- .groupEnd("?")
- .groupBegin()
- .text("COT:")
- .number("(d+)") // odometer
- .number("(?:;d+:d+:d+)?") // engine hours
- .expression(",?")
- .groupEnd("?")
- .groupBegin()
- .text("ADC:")
- .number("(d+.d+)") // power
- .number("(?:;(d+.d+))?,?") // battery
- .groupEnd("?")
- .groupBegin()
- .text("DTT:")
- .number("(x+);") // status
- .number("(x+)?;") // io
- .number("(x+);") // geo-fence 0-119
- .number("(x+);") // geo-fence 120-155
- .number("(x+)") // event status
- .number("(?:;(x+))?,?") // packet type
- .groupEnd("?")
- .groupBegin()
- .text("ETD:").expression("([^,]+),?")
- .groupEnd("?")
- .groupBegin()
- .text("OBD:")
- .number("(x+),?")
- .groupEnd("?")
- .groupBegin()
- .text("FUL:").expression("[^,]*,?")
- .groupEnd("?")
- .groupBegin()
- .text("TRU:").expression("[^,]*,?")
- .groupEnd("?")
- .groupBegin()
- .text("TAG:").expression("([^,]+),?")
- .groupEnd("?")
- .compile();
-
- private static final Pattern PATTERN_OLD = new PatternBuilder()
- .text("*GS") // header
- .number("d+,") // protocol version
- .number("(d+),") // imei
- .text("GPS:")
- .number("(dd)(dd)(dd);") // time (hhmmss)
- .number("d;").optional() // fix type
- .expression("([AV]);") // validity
- .number("([NS])(d+.d+);") // latitude
- .number("([EW])(d+.d+);") // longitude
- .number("(d+)?;") // speed
- .number("(d+);") // course
- .number("(d+.?d*)").optional() // hdop
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any()
- .compile();
-
- private Position decodePosition(DeviceSession deviceSession, Parser parser, Date time) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (time != null) {
- position.setTime(time);
- }
-
- position.set(Position.KEY_EVENT, parser.next());
-
- position.setValid(parser.next().equals("A"));
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.KEY_VDOP, parser.nextDouble(0));
-
- if (parser.hasNext(5)) {
- position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0),
- parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
- }
- if (parser.hasNext()) {
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- }
- position.set(Position.KEY_POWER, parser.nextDouble());
- position.set(Position.KEY_BATTERY, parser.nextDouble());
-
- if (parser.hasNext(6)) {
- long status = parser.nextLong(16, 0);
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 13));
- position.set(Position.KEY_STATUS, status);
- position.set("ioStatus", parser.next());
- position.set(Position.KEY_GEOFENCE, parser.next() + parser.next());
- position.set("eventStatus", parser.next());
- position.set("packetType", parser.next());
- }
-
- if (parser.hasNext()) {
- position.set("eventData", parser.next());
- }
-
- if (parser.hasNext()) {
- position.set("obd", parser.next());
- }
-
- if (parser.hasNext()) {
- position.set("tagData", parser.next());
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- if (channel != null) {
- channel.write("1234");
- }
-
- String sentence = (String) msg;
- Pattern pattern = PATTERN;
- if (sentence.startsWith("*GS02")) {
- pattern = PATTERN_OLD;
- }
-
- Parser parser = new Parser(pattern, (String) msg);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- if (pattern == PATTERN_OLD) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_HDOP, parser.next());
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
-
- } else {
-
- Date time = null;
- if (parser.hasNext(6)) {
- time = parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY);
- }
-
- List<Position> positions = new LinkedList<>();
- Parser itemParser = new Parser(PATTERN_ITEM, parser.next());
- while (itemParser.find()) {
- positions.add(decodePosition(deviceSession, itemParser, time));
- }
-
- return positions;
-
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/GotopProtocol.java b/src/org/traccar/protocol/GotopProtocol.java
deleted file mode 100644
index 5d522adf5..000000000
--- a/src/org/traccar/protocol/GotopProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 GotopProtocol extends BaseProtocol {
-
- public GotopProtocol() {
- super("gotop");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new GotopProtocolDecoder(GotopProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
deleted file mode 100644
index f938887e2..000000000
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.
- * 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.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 GotopProtocolDecoder extends BaseProtocolDecoder {
-
- public GotopProtocolDecoder(GotopProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(d+),") // imei
- .expression("[^,]+,") // type
- .expression("([AV]),") // validity
- .number("DATE:(dd)(dd)(dd),") // date (yyddmm)
- .number("TIME:(dd)(dd)(dd),") // time (hhmmss)
- .number("LAT:(d+.d+)([NS]),") // latitude
- .number("LOT:(d+.d+)([EW]),") // longitude
- .text("Speed:").number("(d+.d+),") // speed
- .expression("([^,]+),") // status
- .number("(d+)?") // course
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(parser.next().equals("A"));
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
-
- position.set(Position.KEY_STATUS, parser.next());
-
- position.setCourse(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gps056FrameDecoder.java b/src/org/traccar/protocol/Gps056FrameDecoder.java
deleted file mode 100644
index 4ce83dc0a..000000000
--- a/src/org/traccar/protocol/Gps056FrameDecoder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.nio.charset.StandardCharsets;
-
-public class Gps056FrameDecoder extends FrameDecoder {
-
- private static final int MESSAGE_HEADER = 4;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() >= MESSAGE_HEADER) {
- int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
- if (buf.readableBytes() >= length) {
- ChannelBuffer frame = buf.readBytes(length);
- while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
- buf.readByte();
- }
- return frame;
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gps056Protocol.java b/src/org/traccar/protocol/Gps056Protocol.java
deleted file mode 100644
index 33c190ad2..000000000
--- a/src/org/traccar/protocol/Gps056Protocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class Gps056Protocol extends BaseProtocol {
-
- public Gps056Protocol() {
- super("gps056");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Gps056FrameDecoder());
- pipeline.addLast("objectDecoder", new Gps056ProtocolDecoder(Gps056Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gps056ProtocolDecoder.java b/src/org/traccar/protocol/Gps056ProtocolDecoder.java
deleted file mode 100644
index 7248365b0..000000000
--- a/src/org/traccar/protocol/Gps056ProtocolDecoder.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class Gps056ProtocolDecoder extends BaseProtocolDecoder {
-
- public Gps056ProtocolDecoder(Gps056Protocol protocol) {
- super(protocol);
- }
-
- private static void sendResponse(Channel channel, String type, String imei, ChannelBuffer content) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- String header = "*" + type + imei;
- response.writeBytes(header.getBytes(StandardCharsets.US_ASCII));
- if (content != null) {
- response.writeBytes(content);
- }
- response.writeByte('#');
- channel.write(response);
- }
- }
-
- private static double decodeCoordinate(ChannelBuffer buf) {
- double degrees = buf.getUnsignedShort(buf.readerIndex()) / 100;
- double minutes = buf.readUnsignedShort() % 100 + buf.readUnsignedShort() * 0.0001;
- degrees += minutes / 60;
- byte hemisphere = buf.readByte();
- if (hemisphere == 'S' || hemisphere == 'W') {
- degrees = -degrees;
- }
- return degrees;
- }
-
- private static void decodeStatus(ChannelBuffer buf, Position position) {
-
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
-
- position.set(Position.PREFIX_ADC + 1, ChannelBuffers.swapShort(buf.readShort()) * 5.06); // mV
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
-
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- buf.skipBytes(2); // length
-
- String type = buf.readBytes(7).toString(StandardCharsets.US_ASCII);
- String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- if (type.startsWith("LOGN")) {
-
- sendResponse(channel, "LGSA" + type.substring(4), imei,
- ChannelBuffers.copiedBuffer("1", StandardCharsets.US_ASCII));
-
- } else if (type.startsWith("GPSL")) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
-
- position.setValid(true);
- position.setTime(dateBuilder.getDate());
- position.setLatitude(decodeCoordinate(buf));
- position.setLongitude(decodeCoordinate(buf));
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedShort());
-
- decodeStatus(buf, position);
-
- sendResponse(channel, "GPSA" + type.substring(4), imei, buf.readBytes(2));
-
- return position;
-
- } else if (type.startsWith("SYNC")) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- decodeStatus(buf, position);
-
- sendResponse(channel, "SYSA" + type.substring(4), imei, null);
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gps103Protocol.java b/src/org/traccar/protocol/Gps103Protocol.java
deleted file mode 100644
index a5bd32261..000000000
--- a/src/org/traccar/protocol/Gps103Protocol.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.
- * 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.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 org.traccar.model.Command;
-
-import java.util.List;
-
-public class Gps103Protocol extends BaseProtocol {
-
- public Gps103Protocol() {
- super("gps103");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_POSITION_PERIODIC,
- Command.TYPE_POSITION_STOP,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_ALARM_ARM,
- Command.TYPE_ALARM_DISARM,
- Command.TYPE_REQUEST_PHOTO);
- }
-
- @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(2048, "\r\n", "\n", ";"));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new Gps103ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(Gps103Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new Gps103ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(Gps103Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
deleted file mode 100644
index 099047aa0..000000000
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
-
- public Gps103ProtocolDecoder(Gps103Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("imei:")
- .number("(d+),") // imei
- .expression("([^,]+),") // alarm
- .number("(dd)/?(dd)/?(dd) ?") // local date (yymmdd)
- .number("(dd):?(dd)(?:dd)?,") // local time (hhmmss)
- .expression("([^,]+)?,") // rfid
- .expression("[FL],") // full / low
- .groupBegin()
- .number("(dd)(dd)(dd).d+") // time utc (hhmmss)
- .or()
- .number("(?:d{1,5}.d+)?")
- .groupEnd()
- .text(",")
- .expression("([AV]),") // validity
- .expression("([NS]),").optional()
- .number("(d+)(dd.d+),") // latitude (ddmm.mmmm)
- .expression("([NS]),").optional()
- .expression("([EW]),").optional()
- .number("(d+)(dd.d+),") // longitude (dddmm.mmmm)
- .expression("([EW])?,").optional()
- .number("(d+.?d*)?,?") // speed
- .number("(d+.?d*)?,?") // course
- .number("(d+.?d*)?,?") // altitude
- .expression("([^,;]+)?,?")
- .expression("([^,;]+)?,?")
- .expression("([^,;]+)?,?")
- .expression("([^,;]+)?,?")
- .expression("([^,;]+)?,?")
- .any()
- .compile();
-
- private static final Pattern PATTERN_NETWORK = new PatternBuilder()
- .text("imei:")
- .number("(d+),") // imei
- .expression("[^,]+,") // alarm
- .number("d*,,")
- .text("L,,,")
- .number("(x+),,") // lac
- .number("(x+),,,") // cid
- .any()
- .compile();
-
- private static final Pattern PATTERN_HANDSHAKE = new PatternBuilder()
- .number("##,imei:(d+),A")
- .compile();
-
- private static final Pattern PATTERN_OBD = new PatternBuilder()
- .text("imei:")
- .number("(d+),") // imei
- .expression("OBD,") // type
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d+),") // odometer
- .number("(d+.d+)?,") // fuel instant
- .number("(d+.d+)?,") // fuel average
- .number("(d+)?,") // hours
- .number("(d+),") // speed
- .number("(d+.?d*%),") // power load
- .number("(?:([-+]?d+)|[-+]?),") // temperature
- .number("(d+.?d*%),") // throttle
- .number("(d+),") // rpm
- .number("(d+.d+),") // battery
- .number("([^;]*)") // dtcs
- .any()
- .compile();
-
- private String decodeAlarm(String value) {
- if (value.startsWith("T:")) {
- return Position.ALARM_TEMPERATURE;
- } else if (value.startsWith("oil")) {
- return Position.ALARM_OIL_LEAK;
- }
- switch (value) {
- case "tracker":
- return null;
- case "help me":
- return Position.ALARM_SOS;
- case "low battery":
- return Position.ALARM_LOW_BATTERY;
- case "stockade":
- return Position.ALARM_GEOFENCE;
- case "move":
- 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;
- case "ac alarm":
- return Position.ALARM_POWER_CUT;
- case "accident alarm":
- return Position.ALARM_ACCIDENT;
- case "sensor alarm":
- return Position.ALARM_SHOCK;
- case "bonnet alarm":
- return Position.ALARM_BONNET;
- case "footbrake alarm":
- return Position.ALARM_FOOT_BRAKE;
- case "DTC":
- return Position.ALARM_FAULT;
- default:
- return null;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- // Send response #1
- if (sentence.contains("##")) {
- if (channel != null) {
- channel.write("LOAD", remoteAddress);
- Parser handshakeParser = new Parser(PATTERN_HANDSHAKE, sentence);
- if (handshakeParser.matches()) {
- getDeviceSession(channel, remoteAddress, handshakeParser.next());
- }
- }
- return null;
- }
-
- // Send response #2
- if (!sentence.isEmpty() && Character.isDigit(sentence.charAt(0))) {
- if (channel != null) {
- channel.write("ON", remoteAddress);
- }
- int start = sentence.indexOf("imei:");
- if (start >= 0) {
- sentence = sentence.substring(start);
- } else {
- return null;
- }
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- Parser parser = new Parser(PATTERN_NETWORK, sentence);
- if (parser.matches()) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- position.setNetwork(new Network(
- CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
-
- return position;
-
- }
-
- parser = new Parser(PATTERN_OBD, sentence);
- if (parser.matches()) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, parser.nextDateTime());
-
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- parser.nextDouble(0); // instant fuel consumption
- position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble(0));
- position.set(Position.KEY_HOURS, parser.nextInt());
- position.set(Position.KEY_OBD_SPEED, parser.nextInt(0));
- position.set(Position.KEY_ENGINE_LOAD, parser.next());
- position.set(Position.KEY_COOLANT_TEMP, parser.nextInt());
- position.set(Position.KEY_THROTTLE, parser.next());
- position.set(Position.KEY_RPM, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_DTCS, parser.next().replace(',', ' ').trim());
-
- return position;
-
- }
-
- parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- String imei = parser.next();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- String alarm = parser.next();
- position.set(Position.KEY_ALARM, decodeAlarm(alarm));
- if (alarm.equals("help me")) {
- if (channel != null) {
- channel.write("**,imei:" + imei + ",E;", remoteAddress);
- }
- } else if (alarm.equals("acc on")) {
- position.set(Position.KEY_IGNITION, true);
- } else if (alarm.equals("acc off")) {
- position.set(Position.KEY_IGNITION, false);
- } else if (alarm.startsWith("T:")) {
- position.set(Position.PREFIX_TEMP + 1, alarm.substring(2));
- } else if (alarm.startsWith("oil ")) {
- position.set("oil", alarm.substring(4));
- } else if (!position.getAttributes().containsKey(Position.KEY_ALARM) && !alarm.equals("tracker")) {
- position.set(Position.KEY_EVENT, alarm);
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- int localHours = parser.nextInt(0);
- int localMinutes = parser.nextInt(0);
-
- String rfid = parser.next();
- if (alarm.equals("rfid")) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid);
- }
-
- String utcHours = parser.next();
- String utcMinutes = parser.next();
-
- dateBuilder.setTime(localHours, localMinutes, parser.nextInt(0));
-
- // Timezone calculation
- if (utcHours != null && utcMinutes != null) {
- int deltaMinutes = (localHours - Integer.parseInt(utcHours)) * 60;
- deltaMinutes += localMinutes - Integer.parseInt(utcMinutes);
- if (deltaMinutes <= -12 * 60) {
- deltaMinutes += 24 * 60;
- } else if (deltaMinutes > 12 * 60) {
- deltaMinutes -= 24 * 60;
- }
- dateBuilder.addMinute(-deltaMinutes);
- }
- position.setTime(dateBuilder.getDate());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_HEM));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- for (int i = 1; i <= 5; i++) {
- position.set(Position.PREFIX_IO + i, parser.next());
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gps103ProtocolEncoder.java b/src/org/traccar/protocol/Gps103ProtocolEncoder.java
deleted file mode 100644
index 36801b401..000000000
--- a/src/org/traccar/protocol/Gps103ProtocolEncoder.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.
- * 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 Gps103ProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
-
- @Override
- public String formatValue(String key, Object value) {
-
- if (key.equals(Command.KEY_FREQUENCY)) {
- long frequency = ((Number) value).longValue();
- if (frequency / 60 / 60 > 0) {
- return String.format("%02dh", frequency / 60 / 60);
- } else if (frequency / 60 > 0) {
- return String.format("%02dm", frequency / 60);
- } else {
- return String.format("%02ds", frequency);
- }
- }
-
- return null;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "**,imei:{%s},{%s}", Command.KEY_UNIQUE_ID, Command.KEY_DATA);
- case Command.TYPE_POSITION_STOP:
- return formatCommand(command, "**,imei:{%s},A", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "**,imei:{%s},B", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(
- command, "**,imei:{%s},C,{%s}", this, Command.KEY_UNIQUE_ID, Command.KEY_FREQUENCY);
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "**,imei:{%s},J", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "**,imei:{%s},K", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ALARM_ARM:
- return formatCommand(command, "**,imei:{%s},L", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, "**,imei:{%s},M", Command.KEY_UNIQUE_ID);
- case Command.TYPE_REQUEST_PHOTO:
- return formatCommand(command, "**,imei:{%s},160", Command.KEY_UNIQUE_ID);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GpsGateProtocol.java b/src/org/traccar/protocol/GpsGateProtocol.java
deleted file mode 100644
index c7dc2c4f3..000000000
--- a/src/org/traccar/protocol/GpsGateProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 GpsGateProtocol extends BaseProtocol {
-
- public GpsGateProtocol() {
- super("gpsgate");
- }
-
- @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, "\0", "\n", "\r\n"));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new GpsGateProtocolDecoder(GpsGateProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
deleted file mode 100644
index ca1d6453e..000000000
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-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 GpsGateProtocolDecoder extends BaseProtocolDecoder {
-
- public GpsGateProtocolDecoder(GpsGateProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_GPRMC = new PatternBuilder()
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.d+)?,") // speed
- .number("(d+.d+)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any()
- .compile();
-
- private static final Pattern PATTERN_FRCMD = new PatternBuilder()
- .text("$FRCMD,")
- .number("(d+),") // imei
- .expression("[^,]*,") // command
- .expression("[^,]*,")
- .number("(d+)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(d+)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*),") // altitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([01])") // validity
- .any()
- .compile();
-
- private void send(Channel channel, String message) {
- if (channel != null) {
- channel.write(message + Checksum.nmea(message) + "\r\n");
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("$FRLIN,")) {
-
- // Login
- int beginIndex = sentence.indexOf(',', 7);
- if (beginIndex != -1) {
- beginIndex += 1;
- int endIndex = sentence.indexOf(',', beginIndex);
- if (endIndex != -1) {
- String imei = sentence.substring(beginIndex, endIndex);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession != null) {
- if (channel != null) {
- send(channel, "$FRSES," + channel.getId());
- }
- } else {
- send(channel, "$FRERR,AuthError,Unknown device");
- }
- } else {
- send(channel, "$FRERR,AuthError,Parse error");
- }
- } else {
- send(channel, "$FRERR,AuthError,Parse error");
- }
-
- } else if (sentence.startsWith("$FRVER,")) {
-
- // Version check
- send(channel, "$FRVER,1,0,GpsGate Server 1.0");
-
- } else if (sentence.startsWith("$GPRMC,")) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN_GPRMC, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
-
- } else if (sentence.startsWith("$FRCMD,")) {
-
- Parser parser = new Parser(PATTERN_FRCMD, 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.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(parser.next().equals("1"));
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GpsMarkerProtocol.java b/src/org/traccar/protocol/GpsMarkerProtocol.java
deleted file mode 100644
index 5c64d16b2..000000000
--- a/src/org/traccar/protocol/GpsMarkerProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 GpsMarkerProtocol extends BaseProtocol {
-
- public GpsMarkerProtocol() {
- super("gpsmarker");
- }
-
- @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, "\r"));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new GpsMarkerProtocolDecoder(GpsMarkerProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
deleted file mode 100644
index f65f5b2bb..000000000
--- a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class GpsMarkerProtocolDecoder extends BaseProtocolDecoder {
-
- public GpsMarkerProtocolDecoder(GpsMarkerProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$GM")
- .number("d") // type
- .number("(?:xx)?") // index
- .number("(d{15})") // imei
- .number("T(dd)(dd)(dd)") // date (ddmmyy)
- .number("(dd)(dd)(dd)?") // time (hhmmss)
- .expression("([NS])")
- .number("(dd)(dd)(dddd)") // latitude
- .expression("([EW])")
- .number("(ddd)(dd)(dddd)") // longitude
- .number("(ddd)") // speed
- .number("(ddd)") // course
- .number("(x)") // satellites
- .number("(dd)") // battery
- .number("(d)") // input
- .number("(d)") // output
- .number("(ddd)") // temperature
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextHexInt(0));
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
- position.set(Position.PREFIX_TEMP + 1, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/GpsmtaProtocol.java b/src/org/traccar/protocol/GpsmtaProtocol.java
deleted file mode 100644
index 2d1181bec..000000000
--- a/src/org/traccar/protocol/GpsmtaProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.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 GpsmtaProtocol extends BaseProtocol {
-
- public GpsmtaProtocol() {
- super("gpsmta");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new GpsmtaProtocolDecoder(GpsmtaProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
deleted file mode 100644
index 11777bece..000000000
--- a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class GpsmtaProtocolDecoder extends BaseProtocolDecoder {
-
- public GpsmtaProtocolDecoder(GpsmtaProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("([^ ]+) ") // uid
- .number("(d+) ") // time (unix time)
- .number("(d+.d+) ") // latitude
- .number("(d+.d+) ") // longitude
- .number("(d+) ") // speed
- .number("(d+) ") // course
- .number("(d+) ") // accuracy
- .number("(d+) ") // altitude
- .number("(d+) ") // flags
- .number("(d+) ") // battery
- .number("(d+) ") // temperature
- .number("(d)") // changing status
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- String time = parser.next();
- position.setTime(new Date(Long.parseLong(time) * 1000));
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(parser.nextInt(0));
- position.setCourse(parser.nextInt(0));
- position.setAccuracy(parser.nextInt(0));
- position.setAltitude(parser.nextInt(0));
-
- position.set(Position.KEY_STATUS, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
- position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
-
- if (channel != null) {
- channel.write(time, remoteAddress);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/GranitFrameDecoder.java b/src/org/traccar/protocol/GranitFrameDecoder.java
deleted file mode 100644
index 7e8f4a3f5..000000000
--- a/src/org/traccar/protocol/GranitFrameDecoder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
-
-public class GranitFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- int indexEnd = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
- if (indexEnd != -1) {
- int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("~"));
- if (indexTilde != -1 && indexTilde < indexEnd) {
- int length = buf.getUnsignedShort(indexTilde + 1);
- indexEnd = buf.indexOf(indexTilde + 2 + length, buf.writerIndex(), new StringFinder("\r\n"));
- if (indexEnd == -1) {
- return null;
- }
- }
- ChannelBuffer frame = buf.readBytes(indexEnd - buf.readerIndex());
- buf.skipBytes(2);
- return frame;
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GranitProtocol.java b/src/org/traccar/protocol/GranitProtocol.java
deleted file mode 100644
index 32e8e00b0..000000000
--- a/src/org/traccar/protocol/GranitProtocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.protocol;
-
-import org.jboss.netty.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class GranitProtocol extends BaseProtocol {
-
- public GranitProtocol() {
- super("granit");
- setSupportedDataCommands(
- Command.TYPE_IDENTIFICATION,
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_POSITION_SINGLE);
- setTextCommandEncoder(new GranitProtocolSmsEncoder());
- setSupportedTextCommands(
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_POSITION_PERIODIC);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new GranitFrameDecoder());
- pipeline.addLast("objectEncoder", new GranitProtocolEncoder());
- pipeline.addLast("objectDecoder", new GranitProtocolDecoder(GranitProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java
deleted file mode 100644
index 8e935ae9e..000000000
--- a/src/org/traccar/protocol/GranitProtocolDecoder.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.StringFinder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-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) {
- buffer.writeByte('*');
- int checksum = Checksum.xor(buffer.toByteBuffer(0, length)) & 0xFF;
- String checksumString = String.format("%02X", checksum);
- buffer.writeBytes(checksumString.getBytes(StandardCharsets.US_ASCII));
- buffer.writeByte('\r'); buffer.writeByte('\n');
- }
-
- private static void sendResponseCurrent(Channel channel, int deviceId, long time) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
- response.writeBytes("BB+UGRC~".getBytes(StandardCharsets.US_ASCII));
- response.writeShort(6); // length
- response.writeInt((int) time);
- response.writeShort(deviceId);
- appendChecksum(response, 16);
- channel.write(response);
- }
-
- private static void sendResponseArchive(Channel channel, int deviceId, int packNum) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
- response.writeBytes("BB+ARCF~".getBytes(StandardCharsets.US_ASCII));
- response.writeShort(4); // length
- response.writeShort(packNum);
- response.writeShort(deviceId);
- appendChecksum(response, 14);
- channel.write(response);
- }
-
- private void decodeStructure(ChannelBuffer buf, Position position) {
- short flags = buf.readUnsignedByte();
- position.setValid(BitUtil.check(flags, 7));
- if (BitUtil.check(flags, 1)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
-
- short satDel = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, BitUtil.from(satDel, 4));
-
- int pdop = BitUtil.to(satDel, 4);
- position.set(Position.KEY_PDOP, pdop);
-
- int lonDegrees = buf.readUnsignedByte();
- int latDegrees = buf.readUnsignedByte();
- int lonMinutes = buf.readUnsignedShort();
- int latMinutes = buf.readUnsignedShort();
-
- double latitude = latDegrees + latMinutes / 60000.0;
- double longitude = lonDegrees + lonMinutes / 60000.0;
-
- if (position.getValid()) {
- if (!BitUtil.check(flags, 4)) {
- latitude = -latitude;
- }
- if (!BitUtil.check(flags, 5)) {
- longitude = -longitude;
- }
- }
-
- position.setLongitude(longitude);
- position.setLatitude(latitude);
-
- position.setSpeed(buf.readUnsignedByte());
-
- int course = buf.readUnsignedByte();
- if (BitUtil.check(flags, 6)) {
- course = course | 0x100;
- }
- position.setCourse(course);
-
- position.set(Position.KEY_DISTANCE, buf.readShort());
-
- int analogIn1 = buf.readUnsignedByte();
- int analogIn2 = buf.readUnsignedByte();
- int analogIn3 = buf.readUnsignedByte();
- int analogIn4 = buf.readUnsignedByte();
-
- int analogInHi = buf.readUnsignedByte();
-
- analogIn1 = analogInHi << 8 & 0x300 | analogIn1;
- analogIn2 = analogInHi << 6 & 0x300 | analogIn2;
- analogIn3 = analogInHi << 4 & 0x300 | analogIn3;
- analogIn4 = analogInHi << 2 & 0x300 | 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);
-
- int output = buf.readUnsignedByte();
- for (int i = 0; i < 8; i++) {
- position.set(Position.PREFIX_IO + (i + 1), BitUtil.check(output, i));
- }
- buf.readUnsignedByte(); // status message buffer
- }
-
- @Override
- protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("~"));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
-
- if (deviceSession != null && indexTilde == -1) {
- String bufString = buf.toString(StandardCharsets.US_ASCII);
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date());
- getLastLocation(position, new Date());
- position.setValid(false);
- position.set(Position.KEY_RESULT, bufString);
- return position;
- }
-
- if (buf.readableBytes() < HEADER_LENGTH) {
- return null;
- }
- String header = buf.readBytes(HEADER_LENGTH).toString(StandardCharsets.US_ASCII);
-
- if (header.equals("+RRCB~")) {
-
- buf.skipBytes(2); //binary length 26
- int deviceId = buf.readUnsignedShort();
- deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId));
- if (deviceSession == null) {
- return null;
- }
- long unixTime = buf.readUnsignedInt();
- if (channel != null) {
- sendResponseCurrent(channel, deviceId, unixTime);
- }
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date(unixTime * 1000));
-
- decodeStructure(buf, position);
- return position;
-
- } else if (header.equals("+DDAT~")) {
-
- buf.skipBytes(2); //binary length
- int deviceId = buf.readUnsignedShort();
- deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceId));
- if (deviceSession == null) {
- return null;
- }
- byte format = buf.readByte();
- if (format != 4) {
- return null;
- }
- byte nblocks = buf.readByte();
- int packNum = buf.readUnsignedShort();
- if (channel != null) {
- sendResponseArchive(channel, deviceId, packNum);
- }
- List<Position> positions = new ArrayList<>();
- while (nblocks > 0) {
- nblocks--;
- long unixTime = buf.readUnsignedInt();
- int timeIncrement = buf.getUnsignedShort(buf.readerIndex() + 120);
- for (int i = 0; i < 6; i++) {
- if (buf.getUnsignedByte(buf.readerIndex()) != 0xFE) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(new Date((unixTime + i * timeIncrement) * 1000));
- decodeStructure(buf, position);
- position.set(Position.KEY_ARCHIVE, true);
- positions.add(position);
- } else {
- buf.skipBytes(20); // skip filled 0xFE structure
- }
- }
- buf.skipBytes(2); // increment
- }
- return positions;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GranitProtocolEncoder.java b/src/org/traccar/protocol/GranitProtocolEncoder.java
deleted file mode 100644
index dbfd30ff1..000000000
--- a/src/org/traccar/protocol/GranitProtocolEncoder.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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 java.nio.charset.StandardCharsets;
-
-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;
-
-public class GranitProtocolEncoder extends BaseProtocolEncoder {
- @Override
- protected Object encodeCommand(Command command) {
-
- String commandString = "";
-
- switch (command.getType()) {
- case Command.TYPE_IDENTIFICATION:
- commandString = "BB+IDNT";
- break;
- case Command.TYPE_REBOOT_DEVICE:
- commandString = "BB+RESET";
- break;
- case Command.TYPE_POSITION_SINGLE:
- commandString = "BB+RRCD";
- break;
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- return null;
- }
- if (!commandString.isEmpty()) {
- ChannelBuffer commandBuf = ChannelBuffers.dynamicBuffer();
- commandBuf.writeBytes(commandString.getBytes(StandardCharsets.US_ASCII));
- GranitProtocolDecoder.appendChecksum(commandBuf, commandString.length());
- return commandBuf;
- }
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/GranitProtocolSmsEncoder.java b/src/org/traccar/protocol/GranitProtocolSmsEncoder.java
deleted file mode 100644
index 668e5d4d3..000000000
--- a/src/org/traccar/protocol/GranitProtocolSmsEncoder.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.protocol;
-
-import org.traccar.StringProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class GranitProtocolSmsEncoder extends StringProtocolEncoder {
-
- @Override
- protected String encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_REBOOT_DEVICE:
- return "BB+RESET";
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(command, "BB+BBMD={%s}", Command.KEY_FREQUENCY);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt02Protocol.java b/src/org/traccar/protocol/Gt02Protocol.java
deleted file mode 100644
index e484b66cd..000000000
--- a/src/org/traccar/protocol/Gt02Protocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class Gt02Protocol extends BaseProtocol {
-
- public Gt02Protocol() {
- super("gt02");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 1, 2, 0));
- pipeline.addLast("objectDecoder", new Gt02ProtocolDecoder(Gt02Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
deleted file mode 100644
index a520bff13..000000000
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
-
- public Gt02ProtocolDecoder(Gt02Protocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_DATA = 0x10;
- public static final int MSG_HEARTBEAT = 0x1A;
- public static final int MSG_RESPONSE = 0x1C;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- buf.readByte(); // size
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- // Zero for location messages
- int power = buf.readUnsignedByte();
- int gsm = buf.readUnsignedByte();
-
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
-
- int type = buf.readUnsignedByte();
-
- if (type == MSG_HEARTBEAT) {
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_POWER, power);
- position.set(Position.KEY_RSSI, gsm);
-
- if (channel != null) {
- byte[] response = {0x54, 0x68, 0x1A, 0x0D, 0x0A};
- channel.write(ChannelBuffers.wrappedBuffer(response));
- }
-
- } else if (type == MSG_DATA) {
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- double latitude = buf.readUnsignedInt() / (60.0 * 30000.0);
- double longitude = buf.readUnsignedInt() / (60.0 * 30000.0);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedShort());
-
- buf.skipBytes(3); // reserved
-
- long flags = buf.readUnsignedInt();
- position.setValid(BitUtil.check(flags, 0));
- if (!BitUtil.check(flags, 1)) {
- latitude = -latitude;
- }
- if (!BitUtil.check(flags, 2)) {
- longitude = -longitude;
- }
-
- position.setLatitude(latitude);
- position.setLongitude(longitude);
-
- } else if (type == MSG_RESPONSE) {
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_RESULT,
- buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII));
-
- } else {
-
- return null;
-
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt06FrameDecoder.java b/src/org/traccar/protocol/Gt06FrameDecoder.java
deleted file mode 100644
index c8b5e56ae..000000000
--- a/src/org/traccar/protocol/Gt06FrameDecoder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class Gt06FrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 5) {
- return null;
- }
-
- int length = 2 + 2; // head and tail
-
- if (buf.getByte(buf.readerIndex()) == 0x78) {
- length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2);
- } else {
- length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2);
- }
-
- if (buf.readableBytes() >= length && buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) {
- return buf.readBytes(length);
- }
-
- int endIndex = buf.readerIndex() - 1;
- do {
- endIndex = buf.indexOf(endIndex + 1, buf.writerIndex(), (byte) 0x0d);
- if (endIndex > 0 && buf.writerIndex() > endIndex + 1 && buf.getByte(endIndex + 1) == 0x0a) {
- return buf.readBytes(endIndex + 2 - buf.readerIndex());
- }
- } while (endIndex > 0);
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt06Protocol.java b/src/org/traccar/protocol/Gt06Protocol.java
deleted file mode 100644
index f45ac95ee..000000000
--- a/src/org/traccar/protocol/Gt06Protocol.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class Gt06Protocol extends BaseProtocol {
-
- public Gt06Protocol() {
- super("gt06");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_CUSTOM);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Gt06FrameDecoder());
- pipeline.addLast("objectEncoder", new Gt06ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Gt06ProtocolDecoder(Gt06Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
deleted file mode 100644
index 177c0b653..000000000
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ /dev/null
@@ -1,666 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BcdUtil;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Device;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-import org.traccar.model.WifiAccessPoint;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TimeZone;
-import java.util.regex.Pattern;
-
-public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
-
- private boolean forceTimeZone = false;
- private final TimeZone timeZone = TimeZone.getTimeZone("UTC");
-
- private int serverIndex;
-
- private final Map<Integer, ChannelBuffer> photos = new HashMap<>();
-
- public Gt06ProtocolDecoder(Gt06Protocol protocol) {
- super(protocol);
-
- if (Context.getConfig().hasKey(getProtocolName() + ".timezone")) {
- forceTimeZone = true;
- timeZone.setRawOffset(Context.getConfig().getInteger(getProtocolName() + ".timezone") * 1000);
- }
- }
-
- public static final int MSG_LOGIN = 0x01;
- public static final int MSG_GPS = 0x10;
- public static final int MSG_LBS = 0x11;
- public static final int MSG_GPS_LBS_1 = 0x12;
- public static final int MSG_GPS_LBS_2 = 0x22;
- public static final int MSG_STATUS = 0x13;
- public static final int MSG_SATELLITE = 0x14;
- public static final int MSG_STRING = 0x15;
- public static final int MSG_GPS_LBS_STATUS_1 = 0x16;
- public static final int MSG_WIFI = 0x17;
- public static final int MSG_GPS_LBS_STATUS_2 = 0x26;
- public static final int MSG_GPS_LBS_STATUS_3 = 0x27;
- public static final int MSG_LBS_MULTIPLE = 0x28;
- public static final int MSG_LBS_WIFI = 0x2C;
- public static final int MSG_LBS_PHONE = 0x17;
- public static final int MSG_LBS_EXTEND = 0x18;
- public static final int MSG_LBS_STATUS = 0x19;
- public static final int MSG_GPS_PHONE = 0x1A;
- public static final int MSG_GPS_LBS_EXTEND = 0x1E;
- public static final int MSG_AZ735_GPS = 0x32;
- public static final int MSG_AZ735_ALARM = 0x33;
- public static final int MSG_X1_GPS = 0x34;
- public static final int MSG_X1_PHOTO_INFO = 0x35;
- public static final int MSG_X1_PHOTO_DATA = 0x36;
- public static final int MSG_WIFI_2 = 0x69;
- public static final int MSG_COMMAND_0 = 0x80;
- public static final int MSG_COMMAND_1 = 0x81;
- public static final int MSG_COMMAND_2 = 0x82;
- public static final int MSG_INFO = 0x94;
- public static final int MSG_STRING_INFO = 0x21;
-
- private static boolean isSupported(int type) {
- return hasGps(type) || hasLbs(type) || hasStatus(type);
- }
-
- private static boolean hasGps(int type) {
- return type == MSG_GPS || type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2
- || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2 || type == MSG_GPS_LBS_STATUS_3
- || type == MSG_GPS_PHONE || type == MSG_GPS_LBS_EXTEND;
- }
-
- private static boolean hasLbs(int type) {
- return type == MSG_LBS || type == MSG_LBS_STATUS || type == MSG_GPS_LBS_1 || type == MSG_GPS_LBS_2
- || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2 || type == MSG_GPS_LBS_STATUS_3;
- }
-
- private static boolean hasStatus(int type) {
- return type == MSG_STATUS || type == MSG_LBS_STATUS
- || type == MSG_GPS_LBS_STATUS_1 || type == MSG_GPS_LBS_STATUS_2 || type == MSG_GPS_LBS_STATUS_3;
- }
-
- private void sendResponse(Channel channel, boolean extended, int type, ChannelBuffer content) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- int length = 5 + (content != null ? content.readableBytes() : 0);
- if (extended) {
- response.writeShort(0x7979);
- response.writeShort(length);
- } else {
- response.writeShort(0x7878);
- response.writeByte(length);
- }
- response.writeByte(type);
- if (content != null) {
- response.writeBytes(content);
- }
- response.writeShort(++serverIndex);
- response.writeShort(Checksum.crc16(Checksum.CRC16_X25,
- response.toByteBuffer(2, response.writerIndex() - 2)));
- response.writeByte('\r'); response.writeByte('\n'); // ending
- channel.write(response);
- }
- }
-
- private void sendPhotoRequest(Channel channel, int pictureId) {
- ChannelBuffer photo = photos.get(pictureId);
- ChannelBuffer content = ChannelBuffers.dynamicBuffer();
- content.writeInt(pictureId);
- content.writeInt(photo.writerIndex());
- content.writeShort(Math.min(photo.writableBytes(), 1024));
- sendResponse(channel, false, MSG_X1_PHOTO_DATA, content);
- }
-
- private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength) {
-
- DateBuilder dateBuilder = new DateBuilder(timeZone)
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- if (hasLength && buf.readUnsignedByte() == 0) {
- return false;
- }
-
- position.set(Position.KEY_SATELLITES, BitUtil.to(buf.readUnsignedByte(), 4));
-
- double latitude = buf.readUnsignedInt() / 60.0 / 30000.0;
- double longitude = buf.readUnsignedInt() / 60.0 / 30000.0;
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
-
- int flags = buf.readUnsignedShort();
- position.setCourse(BitUtil.to(flags, 10));
- position.setValid(BitUtil.check(flags, 12));
-
- if (!BitUtil.check(flags, 10)) {
- latitude = -latitude;
- }
- if (BitUtil.check(flags, 11)) {
- longitude = -longitude;
- }
-
- position.setLatitude(latitude);
- position.setLongitude(longitude);
-
- if (BitUtil.check(flags, 14)) {
- position.set(Position.KEY_IGNITION, BitUtil.check(flags, 15));
- }
-
- return true;
- }
-
- private boolean decodeLbs(Position position, ChannelBuffer buf, boolean hasLength) {
-
- int length = 0;
- if (hasLength) {
- length = buf.readUnsignedByte();
- if (length == 0) {
- return false;
- }
- }
-
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedShort(), buf.readUnsignedMedium())));
-
- if (length > 0) {
- buf.skipBytes(length - (hasLength ? 9 : 8));
- }
-
- return true;
- }
-
- private boolean decodeStatus(Position position, ChannelBuffer buf) {
-
- int status = buf.readUnsignedByte();
-
- position.set(Position.KEY_STATUS, status);
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 1));
- position.set(Position.KEY_CHARGE, BitUtil.check(status, 2));
- position.set(Position.KEY_BLOCKED, BitUtil.check(status, 7));
-
- switch (BitUtil.between(status, 3, 6)) {
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_SHOCK);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case 3:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case 4:
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- default:
- break;
- }
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
-
- return true;
- }
-
- private String decodeAlarm(short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x02:
- return Position.ALARM_POWER_CUT;
- case 0x03:
- case 0x09:
- return Position.ALARM_VIBRATION;
- case 0x04:
- return Position.ALARM_GEOFENCE_ENTER;
- case 0x05:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x06:
- return Position.ALARM_OVERSPEED;
- case 0x0E:
- case 0x0F:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_POWER_OFF;
- default:
- return null;
- }
- }
-
- private static final Pattern PATTERN_FUEL = new PatternBuilder()
- .text("!AIOIL,")
- .number("d+,") // device address
- .number("d+.d+,") // output value
- .number("(d+.d+),") // temperature
- .expression("[^,]+,") // version
- .number("dd") // back wave
- .number("d") // software status code
- .number("d,") // hardware status code
- .number("(d+.d+),") // measured value
- .expression("[01],") // movement status
- .number("d+,") // excited wave times
- .number("xx") // checksum
- .compile();
-
- private Position decodeFuelData(Position position, String sentence) {
- Parser parser = new Parser(PATTERN_FUEL, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
- position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble(0));
-
- return position;
- }
-
- private static final Pattern PATTERN_LOCATION = new PatternBuilder()
- .text("Current position!")
- .number("Lat:([NS])(d+.d+),") // latitude
- .number("Lon:([EW])(d+.d+),") // longitude
- .text("Course:").number("(d+.d+),") // course
- .text("Speed:").number("(d+.d+),") // speed
- .text("DateTime:")
- .number("(dddd)-(dd)-(dd) ") // date
- .number("(dd):(dd):(dd)") // time
- .compile();
-
- private Position decodeLocationString(Position position, String sentence) {
- Parser parser = new Parser(PATTERN_LOCATION, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setCourse(parser.nextDouble());
- position.setSpeed(parser.nextDouble());
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.YMD_HMS));
-
- return position;
- }
-
- private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
-
- int length = buf.readUnsignedByte();
- int dataLength = length - 5;
- int type = buf.readUnsignedByte();
-
- DeviceSession deviceSession = null;
- if (type != MSG_LOGIN) {
- deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
- }
-
- if (type == MSG_LOGIN) {
-
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- buf.readUnsignedShort(); // type
-
- if (dataLength > 10) {
- int extensionBits = buf.readUnsignedShort();
- int hours = (extensionBits >> 4) / 100;
- int minutes = (extensionBits >> 4) % 100;
- int offset = (hours * 60 + minutes) * 60;
- if ((extensionBits & 0x8) != 0) {
- offset = -offset;
- }
- if (!forceTimeZone) {
- timeZone.setRawOffset(offset * 1000);
- }
- }
-
- if (getDeviceSession(channel, remoteAddress, imei) != null) {
- sendResponse(channel, false, type, null);
- }
-
- } else if (type == MSG_X1_GPS) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- buf.readUnsignedInt(); // data and alarm
-
- decodeGps(position, buf, false);
-
- buf.readUnsignedShort(); // terminal info
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedByte(),
- buf.readUnsignedShort(), buf.readUnsignedInt())));
-
- return position;
-
- } else if (type == MSG_X1_PHOTO_INFO) {
-
- buf.skipBytes(6); // time
- buf.readUnsignedByte(); // fix status
- buf.readUnsignedInt(); // latitude
- buf.readUnsignedInt(); // longitude
- buf.readUnsignedByte(); // camera id
- buf.readUnsignedByte(); // photo source
- buf.readUnsignedByte(); // picture format
-
- ChannelBuffer photo = ChannelBuffers.buffer(buf.readInt());
- int pictureId = buf.readInt();
- photos.put(pictureId, photo);
- sendPhotoRequest(channel, pictureId);
-
- } else if (type == MSG_WIFI || type == MSG_WIFI_2) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- getLastLocation(position, dateBuilder.getDate());
-
- Network network = new Network();
-
- int wifiCount = buf.getByte(2);
- for (int i = 0; i < wifiCount; i++) {
- String mac = String.format("%02x:%02x:%02x:%02x:%02x:%02x",
- buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(),
- buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- network.addWifiAccessPoint(WifiAccessPoint.from(mac, buf.readUnsignedByte()));
- }
-
- int cellCount = buf.readUnsignedByte();
- int mcc = buf.readUnsignedShort();
- int mnc = buf.readUnsignedByte();
- for (int i = 0; i < cellCount; i++) {
- network.addCellTower(CellTower.from(
- mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte()));
- }
-
- position.setNetwork(network);
-
- return position;
-
- } else {
-
- return decodeBasicOther(channel, buf, deviceSession, type, dataLength);
-
- }
-
- return null;
- }
-
- private Object decodeBasicOther(Channel channel, ChannelBuffer buf,
- DeviceSession deviceSession, int type, int dataLength) throws Exception {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- if (type == MSG_LBS_MULTIPLE || type == MSG_LBS_EXTEND || type == MSG_LBS_WIFI) {
-
- DateBuilder dateBuilder = new DateBuilder(timeZone)
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
-
- getLastLocation(position, dateBuilder.getDate());
-
- int mcc = buf.readUnsignedShort();
- int mnc = buf.readUnsignedByte();
- Network network = new Network();
- for (int i = 0; i < 7; i++) {
- int lac = buf.readUnsignedShort();
- int cid = buf.readUnsignedMedium();
- int rssi = -buf.readUnsignedByte();
- if (lac > 0) {
- network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi));
- }
- }
-
- buf.readUnsignedByte(); // time leads
-
- if (type != MSG_LBS_MULTIPLE) {
- int wifiCount = buf.readUnsignedByte();
- for (int i = 0; i < wifiCount; i++) {
- String mac = ChannelBuffers.hexDump(buf.readBytes(6)).replaceAll("(..)", "$1:");
- network.addWifiAccessPoint(WifiAccessPoint.from(
- mac.substring(0, mac.length() - 1), buf.readUnsignedByte()));
- }
- }
-
- position.setNetwork(network);
-
- } else if (type == MSG_STRING) {
-
- getLastLocation(position, null);
-
- int commandLength = buf.readUnsignedByte();
-
- if (commandLength > 0) {
- buf.readUnsignedByte(); // server flag (reserved)
- position.set(Position.KEY_RESULT,
- buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII));
- }
-
- } else if (isSupported(type)) {
-
- if (hasGps(type)) {
- decodeGps(position, buf, false);
- } else {
- getLastLocation(position, null);
- }
-
- if (hasLbs(type)) {
- decodeLbs(position, buf, hasStatus(type));
- }
-
- if (hasStatus(type)) {
- decodeStatus(position, buf);
- }
-
- if (type == MSG_GPS_LBS_1 && buf.readableBytes() >= 4 + 6) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- if (type == MSG_GPS_LBS_2 && buf.readableBytes() >= 3 + 6) {
- position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0);
- position.set(Position.KEY_EVENT, buf.readUnsignedByte()); // reason
- position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() > 0);
- }
-
- } else {
-
- buf.skipBytes(dataLength);
- if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
- sendResponse(channel, false, type, null);
- }
- return null;
-
- }
-
- sendResponse(channel, false, type, null);
-
- return position;
- }
-
- private Object decodeExtended(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- buf.readUnsignedShort(); // length
- int type = buf.readUnsignedByte();
-
- if (type == MSG_STRING_INFO) {
-
- buf.readUnsignedInt(); // server flag
- String data;
- if (buf.readUnsignedByte() == 1) {
- data = buf.readBytes(buf.readableBytes() - 6).toString(StandardCharsets.US_ASCII);
- } else {
- data = buf.readBytes(buf.readableBytes() - 6).toString(StandardCharsets.UTF_16BE);
- }
-
- if (decodeLocationString(position, data) == null) {
- getLastLocation(position, null);
- position.set(Position.KEY_RESULT, data);
- }
-
- return position;
-
- } else if (type == MSG_INFO) {
-
- int subType = buf.readUnsignedByte();
-
- getLastLocation(position, null);
-
- if (subType == 0x00) {
-
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
- return position;
-
- } else if (subType == 0x05) {
-
- int flags = buf.readUnsignedByte();
- position.set(Position.KEY_DOOR, BitUtil.check(flags, 0));
- position.set(Position.PREFIX_IO + 1, BitUtil.check(flags, 2));
- return position;
-
- } else if (subType == 0x0d) {
-
- buf.skipBytes(6);
- return decodeFuelData(position, buf.toString(
- buf.readerIndex(), buf.readableBytes() - 4 - 2, StandardCharsets.US_ASCII));
-
- }
-
- } else if (type == MSG_X1_PHOTO_DATA) {
-
- int pictureId = buf.readInt();
-
- ChannelBuffer photo = photos.get(pictureId);
-
- buf.readUnsignedInt(); // offset
- buf.readBytes(photo, buf.readUnsignedShort());
-
- if (photo.writableBytes() > 0) {
- sendPhotoRequest(channel, pictureId);
- } else {
- Device device = Context.getDeviceManager().getById(deviceSession.getDeviceId());
- Context.getMediaManager().writeFile(device.getUniqueId(), photo, "jpg");
- photos.remove(pictureId);
- }
-
- } else if (type == MSG_AZ735_GPS || type == MSG_AZ735_ALARM) {
-
- if (!decodeGps(position, buf, true)) {
- getLastLocation(position, position.getDeviceTime());
- }
-
- if (decodeLbs(position, buf, true)) {
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- }
-
- buf.skipBytes(buf.readUnsignedByte()); // additional cell towers
- buf.skipBytes(buf.readUnsignedByte()); // wifi access point
-
- int status = buf.readUnsignedByte();
- position.set(Position.KEY_STATUS, status);
-
- if (type == MSG_AZ735_ALARM) {
- switch (status) {
- case 0xA0:
- position.set(Position.KEY_ARMED, true);
- break;
- case 0xA1:
- position.set(Position.KEY_ARMED, false);
- break;
- case 0xA2:
- case 0xA3:
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case 0xA4:
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- break;
- case 0xA5:
- position.set(Position.KEY_ALARM, Position.ALARM_DOOR);
- break;
- default:
- break;
- }
- }
-
- buf.skipBytes(buf.readUnsignedByte()); // reserved extension
-
- sendResponse(channel, true, type, null);
-
- return position;
-
- }
-
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int header = buf.readShort();
-
- if (header == 0x7878) {
- return decodeBasic(channel, remoteAddress, buf);
- } else if (header == 0x7979) {
- return decodeExtended(channel, remoteAddress, buf);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt06ProtocolEncoder.java b/src/org/traccar/protocol/Gt06ProtocolEncoder.java
deleted file mode 100644
index a3e0a2264..000000000
--- a/src/org/traccar/protocol/Gt06ProtocolEncoder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.nio.charset.StandardCharsets;
-
-public class Gt06ProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeContent(String content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeByte(0x78);
- buf.writeByte(0x78);
-
- buf.writeByte(1 + 1 + 4 + content.length() + 2 + 2); // message length
-
- buf.writeByte(0x80); // message type
-
- buf.writeByte(4 + content.length()); // command length
- buf.writeInt(0);
- buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII)); // command
-
- buf.writeShort(0); // message index
-
- buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer(2, buf.writerIndex() - 2)));
-
- buf.writeByte('\r');
- buf.writeByte('\n');
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- boolean alternative = Context.getIdentityManager().lookupAttributeBoolean(
- command.getDeviceId(), "gt06.alternative", false, true);
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return encodeContent(alternative ? "DYD,123456#" : "Relay,1#");
- case Command.TYPE_ENGINE_RESUME:
- return encodeContent(alternative ? "HFYD,123456#" : "Relay,0#");
- case Command.TYPE_CUSTOM:
- return encodeContent(command.getString(Command.KEY_DATA));
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt30Protocol.java b/src/org/traccar/protocol/Gt30Protocol.java
deleted file mode 100644
index 186002a35..000000000
--- a/src/org/traccar/protocol/Gt30Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 Gt30Protocol extends BaseProtocol {
-
- public Gt30Protocol() {
- super("gt30");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Gt30ProtocolDecoder(Gt30Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Gt30ProtocolDecoder.java b/src/org/traccar/protocol/Gt30ProtocolDecoder.java
deleted file mode 100644
index 51135c80a..000000000
--- a/src/org/traccar/protocol/Gt30ProtocolDecoder.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 Gt30ProtocolDecoder extends BaseProtocolDecoder {
-
- public Gt30ProtocolDecoder(Gt30Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$$")
- .number("x{4}") // length
- .expression("(.{14})") // device id
- .number("x{4}") // type
- .expression("(.)?") // alarm
- .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss)
- .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 (ddmmyy)
- .expression("[^\\|]*")
- .number("|(d+.d+)") // hdop
- .number("|(-?d+)") // altitude
- .number("x{4}") // checksum
- .compile();
-
- private String decodeAlarm(int value) {
- switch (value) {
- case 0x01:
- case 0x02:
- case 0x03:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x12:
- return Position.ALARM_GEOFENCE;
- default:
- return null;
- }
- }
-
- @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().trim());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (parser.hasNext()) {
- position.set(Position.KEY_ALARM, decodeAlarm(parser.next().charAt(0)));
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_HDOP, parser.nextDouble());
-
- position.setAltitude(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java
deleted file mode 100644
index 391fccc87..000000000
--- a/src/org/traccar/protocol/H02FrameDecoder.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-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) {
- this.messageLength = messageLength;
- }
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- char marker = (char) buf.getByte(buf.readerIndex());
-
- while (marker != '*' && marker != '$' && marker != 'X' && buf.readableBytes() > 0) {
- buf.skipBytes(1);
- if (buf.readableBytes() > 0) {
- marker = (char) buf.getByte(buf.readerIndex());
- }
- }
-
- switch (marker) {
- case '*':
-
- // Return text message
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
- if (index != -1) {
- ChannelBuffer result = buf.readBytes(index + 1 - buf.readerIndex());
- while (buf.readable()
- && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) {
- buf.readByte(); // skip new line
- }
- return result;
- }
-
- break;
-
- case '$':
-
- if (messageLength == 0) {
- if (buf.readableBytes() == MESSAGE_LONG) {
- messageLength = MESSAGE_LONG;
- } else {
- messageLength = MESSAGE_SHORT;
- }
- }
-
- if (buf.readableBytes() >= messageLength) {
- return buf.readBytes(messageLength);
- }
-
- break;
-
- case 'X':
-
- if (buf.readableBytes() >= MESSAGE_SHORT) {
- return buf.readBytes(MESSAGE_SHORT);
- }
-
- break;
-
- default:
-
- return null;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/H02Protocol.java b/src/org/traccar/protocol/H02Protocol.java
deleted file mode 100644
index 66965e9db..000000000
--- a/src/org/traccar/protocol/H02Protocol.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.Context;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class H02Protocol extends BaseProtocol {
-
- public H02Protocol() {
- super("h02");
- setSupportedDataCommands(
- Command.TYPE_ALARM_ARM,
- Command.TYPE_ALARM_DISARM,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_POSITION_PERIODIC
- );
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- int messageLength = Context.getConfig().getInteger(getName() + ".messageLength");
- pipeline.addLast("frameDecoder", new H02FrameDecoder(messageLength));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new H02ProtocolEncoder());
- pipeline.addLast("objectDecoder", new H02ProtocolDecoder(H02Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new H02ProtocolEncoder());
- pipeline.addLast("objectDecoder", new H02ProtocolDecoder(H02Protocol.this));
- }
- });
- }
-}
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
deleted file mode 100644
index 4414870d2..000000000
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.BcdUtil;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class H02ProtocolDecoder extends BaseProtocolDecoder {
-
- public H02ProtocolDecoder(H02Protocol protocol) {
- super(protocol);
- }
-
- private static double readCoordinate(ChannelBuffer buf, boolean lon) {
-
- int degrees = BcdUtil.readInteger(buf, 2);
- if (lon) {
- degrees = degrees * 10 + (buf.getUnsignedByte(buf.readerIndex()) >> 4);
- }
-
- double result = 0;
- if (lon) {
- result = buf.readUnsignedByte() & 0x0f;
- }
-
- int length = 6;
- if (lon) {
- length = 5;
- }
-
- result = result * 10 + BcdUtil.readInteger(buf, length) * 0.0001;
-
- result /= 60;
- result += degrees;
-
- return result;
- }
-
- private void processStatus(Position position, long status) {
-
- if (!BitUtil.check(status, 0)) {
- position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
- } else if (!BitUtil.check(status, 1)) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- } else if (!BitUtil.check(status, 2)) {
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- } else if (!BitUtil.check(status, 19)) {
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- }
-
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 10));
- position.set(Position.KEY_STATUS, status);
-
- }
-
- private Integer decodeBattery(int value) {
- switch (value) {
- case 6:
- return 100;
- case 5:
- return 80;
- case 4:
- return 60;
- case 3:
- return 20;
- case 2:
- return 10;
- default:
- return null;
- }
- }
-
- private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- buf.readByte(); // marker
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, ChannelBuffers.hexDump(buf.readBytes(5)));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setYear(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
-
- double latitude = readCoordinate(buf, false);
- position.set(Position.KEY_BATTERY_LEVEL, decodeBattery(buf.readUnsignedByte()));
- double longitude = readCoordinate(buf, true);
-
- int flags = buf.readUnsignedByte() & 0x0f;
- position.setValid((flags & 0x02) != 0);
- if ((flags & 0x04) == 0) {
- latitude = -latitude;
- }
- if ((flags & 0x08) == 0) {
- longitude = -longitude;
- }
-
- position.setLatitude(latitude);
- position.setLongitude(longitude);
-
- position.setSpeed(BcdUtil.readInteger(buf, 3));
- position.setCourse((buf.readUnsignedByte() & 0x0f) * 100.0 + BcdUtil.readInteger(buf, 2));
-
- processStatus(position, buf.readUnsignedInt());
-
- return position;
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("*")
- .expression("..,") // manufacturer
- .number("(d+),") // imei
- .groupBegin()
- .text("VP1,")
- .or()
- .groupBegin()
- .text("V4,")
- .expression("(.*),") // response
- .or()
- .expression("V[^,]*,")
- .groupEnd()
- .number("(?:(dd)(dd)(dd))?,") // time (hhmmss)
- .groupEnd()
- .groupBegin()
- .expression("([ABV])?,") // validity
- .or()
- .number("(d+),") // coding scheme
- .groupEnd()
- .groupBegin()
- .number("-(d+)-(d+.d+),") // latitude
- .or()
- .number("(d+)(dd.d+),") // latitude
- .groupEnd()
- .expression("([NS]),")
- .groupBegin()
- .number("-(d+)-(d+.d+),") // longitude
- .or()
- .number("(d+)(dd.d+),") // longitude
- .groupEnd()
- .expression("([EW]),")
- .number("(d+.?d*),") // speed
- .number("(d+.?d*)?,") // course
- .number("(?:(dd)(dd)(dd))?") // date (ddmmyy)
- .groupBegin()
- .expression(",[^,]*,")
- .expression("[^,]*,")
- .expression("[^,]*") // sim info
- .groupEnd("?")
- .groupBegin()
- .number(",(x{8})")
- .groupBegin()
- .number(",(d+),") // odometer
- .number("(-?d+),") // temperature
- .number("(d+.d+),") // fuel
- .number("(-?d+),") // altitude
- .number("(x+),") // lac
- .number("(x+)") // cid
- .or()
- .text(",")
- .expression("(.*)") // data
- .or()
- .groupEnd()
- .or()
- .groupEnd()
- .text("#")
- .compile();
-
- private static final Pattern PATTERN_NBR = new PatternBuilder()
- .text("*")
- .expression("..,") // manufacturer
- .number("(d+),") // imei
- .text("NBR,")
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .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 static final Pattern PATTERN_LINK = new PatternBuilder()
- .text("*")
- .expression("..,") // manufacturer
- .number("(d+),") // imei
- .text("LINK,")
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d+),") // rssi
- .number("(d+),") // satellites
- .number("(d+),") // battery
- .number("(d+),") // steps
- .number("(d+),") // turnovers
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(x{8})") // status
- .any()
- .compile();
-
- private static final Pattern PATTERN_V3 = new PatternBuilder()
- .text("*")
- .expression("..,") // manufacturer
- .number("(d+),") // imei
- .text("V3,")
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(ddd)") // mcc
- .number("(d+),") // mnc
- .number("(d+),") // count
- .expression("(.*),") // cell info
- .number("(x{4}),") // battery
- .number("d+,") // reboot info
- .text("X,")
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(x{8})") // status
- .text("#").optional()
- .compile();
-
- private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (parser.hasNext()) {
- position.set(Position.KEY_RESULT, parser.next());
- }
-
- DateBuilder dateBuilder = new DateBuilder();
- if (parser.hasNext(3)) {
- dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- }
-
- if (parser.hasNext()) {
- position.setValid(parser.next().equals("A"));
- }
- if (parser.hasNext()) {
- parser.nextInt(); // coding scheme
- position.setValid(true);
- }
-
- if (parser.hasNext(2)) {
- position.setLatitude(-parser.nextCoordinate());
- }
- if (parser.hasNext(2)) {
- position.setLatitude(parser.nextCoordinate());
- }
-
- if (parser.hasNext(2)) {
- position.setLongitude(-parser.nextCoordinate());
- }
- if (parser.hasNext(2)) {
- position.setLongitude(parser.nextCoordinate());
- }
-
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- if (parser.hasNext(3)) {
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
- } else {
- position.setTime(new Date());
- }
-
- if (parser.hasNext()) {
- processStatus(position, parser.nextLong(16, 0));
- }
-
- if (parser.hasNext(6)) {
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
- position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble(0));
-
- position.setAltitude(parser.nextInt(0));
-
- position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
- }
-
- if (parser.hasNext(4)) {
- String[] values = parser.next().split(",");
- for (int i = 0; i < values.length; i++) {
- position.set(Position.PREFIX_IO + (i + 1), values[i].trim());
- }
- }
-
- 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(0), parser.nextInt(0), parser.nextInt(0));
-
- Network network = new Network();
- int mcc = parser.nextInt(0);
- int mnc = parser.nextInt(0);
-
- String[] cells = parser.next().split(",");
- for (int i = 0; i < cells.length / 3; i++) {
- network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(cells[i * 3]),
- Integer.parseInt(cells[i * 3 + 1]), Integer.parseInt(cells[i * 3 + 2])));
- }
-
- position.setNetwork(network);
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- getLastLocation(position, dateBuilder.getDate());
-
- processStatus(position, parser.nextLong(16, 0));
-
- return position;
- }
-
- private Position decodeLink(String sentence, Channel channel, SocketAddress remoteAddress) {
-
- Parser parser = new Parser(PATTERN_LINK, 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(0), parser.nextInt(0), parser.nextInt(0));
-
- position.set(Position.KEY_RSSI, parser.nextInt());
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
- position.set(Position.KEY_STEPS, parser.nextInt());
- position.set("turnovers", parser.nextInt());
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- getLastLocation(position, dateBuilder.getDate());
-
- processStatus(position, parser.nextLong(16, 0));
-
- return position;
- }
-
- private Position decodeV3(String sentence, Channel channel, SocketAddress remoteAddress) {
-
- Parser parser = new Parser(PATTERN_V3, 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(0), parser.nextInt(0), parser.nextInt(0));
-
- int mcc = parser.nextInt();
- int mnc = parser.nextInt();
-
- int count = parser.nextInt();
- Network network = new Network();
- String[] values = parser.next().split(",");
- for (int i = 0; i < count; i++) {
- network.addCellTower(CellTower.from(
- mcc, mnc, Integer.parseInt(values[i * 4]), Integer.parseInt(values[i * 4 + 1])));
- }
- position.setNetwork(network);
-
- position.set(Position.KEY_BATTERY, parser.nextHexInt());
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- getLastLocation(position, dateBuilder.getDate());
-
- processStatus(position, parser.nextLong(16, 0));
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
- String marker = buf.toString(0, 1, StandardCharsets.US_ASCII);
-
- switch (marker) {
- case "*":
- String sentence = buf.toString(StandardCharsets.US_ASCII);
- int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1;
- int typeEnd = sentence.indexOf(',', typeStart);
- if (typeEnd > 0) {
- String type = sentence.substring(typeStart, typeEnd);
- switch (type) {
- case "NBR":
- return decodeLbs(sentence, channel, remoteAddress);
- case "LINK":
- return decodeLink(sentence, channel, remoteAddress);
- case "V3":
- return decodeV3(sentence, channel, remoteAddress);
- default:
- return decodeText(sentence, channel, remoteAddress);
- }
- } else {
- return null;
- }
- case "$":
- return decodeBinary(buf, channel, remoteAddress);
- case "X":
- default:
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/H02ProtocolEncoder.java b/src/org/traccar/protocol/H02ProtocolEncoder.java
deleted file mode 100644
index 7b5ff13bb..000000000
--- a/src/org/traccar/protocol/H02ProtocolEncoder.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2016 Gabor Somogyi (gabor.g.somogyi@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.
- * 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.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.traccar.StringProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class H02ProtocolEncoder extends StringProtocolEncoder {
-
- private static final String MARKER = "HQ";
-
- private Object formatCommand(DateTime time, String uniqueId, String type, String... params) {
-
- StringBuilder result = new StringBuilder(String.format("*%s,%s,%s,%02d%02d%02d",
- MARKER, uniqueId, type, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute()));
-
- for (String param : params) {
- result.append(",").append(param);
- }
-
- result.append("#");
-
- return result.toString();
- }
-
- protected Object encodeCommand(Command command, DateTime time) {
- String uniqueId = getUniqueId(command.getDeviceId());
-
- switch (command.getType()) {
- case Command.TYPE_ALARM_ARM:
- return formatCommand(time, uniqueId, "SCF", "0", "0");
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(time, uniqueId, "SCF", "1", "1");
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(
- time, uniqueId, "S20", "1", "3", "10", "3", "5", "5", "3", "5", "3", "5", "3", "5");
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(time, uniqueId, "S20", "0", "0");
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(
- time, uniqueId, "S71", "22", command.getAttributes().get(Command.KEY_FREQUENCY).toString());
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
- return encodeCommand(command, new DateTime(DateTimeZone.UTC));
- }
-
-}
diff --git a/src/org/traccar/protocol/HaicomProtocol.java b/src/org/traccar/protocol/HaicomProtocol.java
deleted file mode 100644
index 4380dd2cc..000000000
--- a/src/org/traccar/protocol/HaicomProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 HaicomProtocol extends BaseProtocol {
-
- public HaicomProtocol() {
- super("haicom");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new HaicomProtocolDecoder(HaicomProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java
deleted file mode 100644
index 37898a9bc..000000000
--- a/src/org/traccar/protocol/HaicomProtocolDecoder.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-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 HaicomProtocolDecoder extends BaseProtocolDecoder {
-
- public HaicomProtocolDecoder(HaicomProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$GPRS")
- .number("(d+),") // imei
- .expression("([^,]+),") // version
- .number("(dd)(dd)(dd),") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d)") // flags
- .number("(dd)(d{5})") // latitude
- .number("(ddd)(d{5}),") // longitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(d+),") // status
- .number("(d+)?,") // gprs counting value
- .number("(d+)?,") // gps power saving counting value
- .number("(d+),") // switch status
- .number("(d+)") // relay status
- .expression("(?:[LH]{2})?") // power status
- .number("#V(d+)") // battery
- .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;
- }
-
- 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(Position.KEY_VERSION_FW, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- int flags = parser.nextInt(0);
-
- position.setValid(BitUtil.check(flags, 0));
-
- double latitude = parser.nextDouble(0) + parser.nextDouble(0) / 60000;
- if (BitUtil.check(flags, 2)) {
- position.setLatitude(latitude);
- } else {
- position.setLatitude(-latitude);
- }
-
- double longitude = parser.nextDouble(0) + parser.nextDouble(0) / 60000;
- if (BitUtil.check(flags, 1)) {
- position.setLongitude(longitude);
- } else {
- position.setLongitude(-longitude);
- }
-
- position.setSpeed(parser.nextDouble(0) / 10);
- position.setCourse(parser.nextDouble(0) / 10);
-
- position.set(Position.KEY_STATUS, parser.next());
- position.set("gprsCount", parser.next());
- position.set("powersaveCountdown", parser.next());
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
- position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/HomtecsProtocol.java b/src/org/traccar/protocol/HomtecsProtocol.java
deleted file mode 100644
index a9ea19c51..000000000
--- a/src/org/traccar/protocol/HomtecsProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.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 HomtecsProtocol extends BaseProtocol {
-
- public HomtecsProtocol() {
- super("homtecs");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new HomtecsProtocolDecoder(HomtecsProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/HomtecsProtocolDecoder.java b/src/org/traccar/protocol/HomtecsProtocolDecoder.java
deleted file mode 100644
index 508de173c..000000000
--- a/src/org/traccar/protocol/HomtecsProtocolDecoder.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class HomtecsProtocolDecoder extends BaseProtocolDecoder {
-
- public HomtecsProtocolDecoder(HomtecsProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("([^_]+)") // id
- .text("_R")
- .number("(x{8}),") // mac ending
- .number("(dd)(dd)(dd),") // date (yymmdd)
- .number("(dd)(dd)(dd).d+,") // time (hhmmss)
- .number("(d+),") // satellites
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(d),") // fix status
- .number("(d+.?d*)?,") // hdop
- .number("(d+.?d*)?") // altitude
- .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;
- }
-
- String id = parser.next();
- String mac = parser.next();
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id, id + "_R" + mac);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.YMD_HMS));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.setValid(parser.nextInt(0) > 0);
-
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
-
- position.setAltitude(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/HuaShengFrameDecoder.java b/src/org/traccar/protocol/HuaShengFrameDecoder.java
deleted file mode 100644
index 4c29b7915..000000000
--- a/src/org/traccar/protocol/HuaShengFrameDecoder.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class HuaShengFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 2) {
- return null;
- }
-
- int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xC0);
- if (index != -1) {
- ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());
-
- while (buf.readerIndex() <= index) {
- int b = buf.readUnsignedByte();
- if (b == 0xDB) {
- int ext = buf.readUnsignedByte();
- if (ext == 0xDC) {
- result.writeByte(0xC0);
- } else if (ext == 0xDD) {
- result.writeByte(0xDB);
- }
- } else {
- result.writeByte(b);
- }
- }
-
- return result;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/HuaShengProtocol.java b/src/org/traccar/protocol/HuaShengProtocol.java
deleted file mode 100644
index e0fddae20..000000000
--- a/src/org/traccar/protocol/HuaShengProtocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class HuaShengProtocol extends BaseProtocol {
-
- public HuaShengProtocol() {
- super("huasheng");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new HuaShengFrameDecoder());
- pipeline.addLast("objectDecoder", new HuaShengProtocolDecoder(HuaShengProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/org/traccar/protocol/HuaShengProtocolDecoder.java
deleted file mode 100644
index a0a1eb0ab..000000000
--- a/src/org/traccar/protocol/HuaShengProtocolDecoder.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class HuaShengProtocolDecoder extends BaseProtocolDecoder {
-
- public HuaShengProtocolDecoder(HuaShengProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_POSITION = 0xAA00;
- public static final int MSG_POSITION_RSP = 0xFF01;
- public static final int MSG_LOGIN = 0xAA02;
- public static final int MSG_LOGIN_RSP = 0xFF03;
-
- private static void sendResponse(Channel channel, int type, int index, ChannelBuffer content) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(0xC0);
- response.writeShort(0x0100);
- response.writeShort(12 + content.readableBytes());
- response.writeShort(type);
- response.writeShort(0);
- response.writeInt(index);
- response.writeBytes(content);
- response.writeByte(0xC0);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(1); // start marker
- buf.readUnsignedByte(); // flag
- buf.readUnsignedByte(); // reserved
- buf.readUnsignedShort(); // length
-
- int type = buf.readUnsignedShort();
-
- buf.readUnsignedShort(); // checksum
- int index = buf.readInt();
-
- if (type == MSG_LOGIN) {
-
- while (buf.readableBytes() > 4) {
- int subtype = buf.readUnsignedShort();
- int length = buf.readUnsignedShort() - 4;
- if (subtype == 0x0003) {
- String imei = buf.readBytes(length).toString(StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession != null && channel != null) {
- ChannelBuffer content = ChannelBuffers.dynamicBuffer();
- content.writeByte(0); // success
- sendResponse(channel, MSG_LOGIN_RSP, index, content);
- }
- } else {
- buf.skipBytes(length);
- }
- }
-
- } else if (type == MSG_POSITION) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- 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);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setYear(Integer.parseInt(time.substring(0, 2)))
- .setMonth(Integer.parseInt(time.substring(2, 4)))
- .setDay(Integer.parseInt(time.substring(4, 6)))
- .setHour(Integer.parseInt(time.substring(6, 8)))
- .setMinute(Integer.parseInt(time.substring(8, 10)))
- .setSecond(Integer.parseInt(time.substring(10, 12)));
- position.setTime(dateBuilder.getDate());
-
- position.setLongitude(buf.readInt() * 0.00001);
- position.setLatitude(buf.readInt() * 0.00001);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort());
- position.setAltitude(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
-
- while (buf.readableBytes() > 4) {
- buf.readUnsignedShort(); // subtype
- int length = buf.readUnsignedShort() - 4;
- buf.skipBytes(length);
- }
-
- sendResponse(channel, MSG_POSITION_RSP, index, ChannelBuffers.dynamicBuffer());
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/HuabaoFrameDecoder.java b/src/org/traccar/protocol/HuabaoFrameDecoder.java
deleted file mode 100644
index 8e9c9fe72..000000000
--- a/src/org/traccar/protocol/HuabaoFrameDecoder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class HuabaoFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 2) {
- return null;
- }
-
- int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x7e);
- if (index != -1) {
- ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());
-
- while (buf.readerIndex() <= index) {
- int b = buf.readUnsignedByte();
- if (b == 0x7d) {
- int ext = buf.readUnsignedByte();
- if (ext == 0x01) {
- result.writeByte(0x7d);
- } else if (ext == 0x02) {
- result.writeByte(0x7e);
- }
- } else {
- result.writeByte(b);
- }
- }
-
- return result;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/HuabaoProtocol.java b/src/org/traccar/protocol/HuabaoProtocol.java
deleted file mode 100644
index c74cb58c7..000000000
--- a/src/org/traccar/protocol/HuabaoProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class HuabaoProtocol extends BaseProtocol {
-
- public HuabaoProtocol() {
- super("huabao");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new HuabaoFrameDecoder());
- pipeline.addLast("objectEncoder", new HuabaoProtocolEncoder());
- pipeline.addLast("objectDecoder", new HuabaoProtocolDecoder(HuabaoProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
deleted file mode 100644
index c31c6af1c..000000000
--- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.BcdUtil;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.TimeZone;
-
-public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
-
- public HuabaoProtocolDecoder(HuabaoProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_GENERAL_RESPONSE = 0x8001;
- public static final int MSG_TERMINAL_REGISTER = 0x0100;
- public static final int MSG_TERMINAL_REGISTER_RESPONSE = 0x8100;
- public static final int MSG_TERMINAL_AUTH = 0x0102;
- public static final int MSG_LOCATION_REPORT = 0x0200;
- public static final int MSG_OIL_CONTROL = 0XA006;
-
- public static final int RESULT_SUCCESS = 0;
-
- public static ChannelBuffer formatMessage(int type, ChannelBuffer id, ChannelBuffer data) {
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
- buf.writeByte(0x7e);
- buf.writeShort(type);
- buf.writeShort(data.readableBytes());
- buf.writeBytes(id);
- buf.writeShort(1); // index
- buf.writeBytes(data);
- buf.writeByte(Checksum.xor(buf.toByteBuffer(1, buf.readableBytes() - 1)));
- buf.writeByte(0x7e);
- return buf;
- }
-
- private void sendGeneralResponse(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int type, int index) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeShort(index);
- response.writeShort(type);
- response.writeByte(RESULT_SUCCESS);
- channel.write(formatMessage(MSG_GENERAL_RESPONSE, id, response), remoteAddress);
- }
- }
-
- private String decodeAlarm(long value) {
- if (BitUtil.check(value, 0)) {
- return Position.ALARM_SOS;
- }
- if (BitUtil.check(value, 1)) {
- return Position.ALARM_OVERSPEED;
- }
- if (BitUtil.check(value, 5)) {
- return Position.ALARM_GPS_ANTENNA_CUT;
- }
- if (BitUtil.check(value, 4) || BitUtil.check(value, 9)
- || BitUtil.check(value, 10) || BitUtil.check(value, 11)) {
- return Position.ALARM_FAULT;
- }
- if (BitUtil.check(value, 8)) {
- return Position.ALARM_POWER_OFF;
- }
- if (BitUtil.check(value, 20)) {
- return Position.ALARM_GEOFENCE;
- }
- if (BitUtil.check(value, 29)) {
- return Position.ALARM_ACCIDENT;
- }
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // start marker
- int type = buf.readUnsignedShort();
- buf.readUnsignedShort(); // body length
- ChannelBuffer id = buf.readBytes(6); // phone number
- int index = buf.readUnsignedShort();
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(id));
- if (deviceSession == null) {
- return null;
- }
-
- if (type == MSG_TERMINAL_REGISTER) {
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeShort(index);
- response.writeByte(RESULT_SUCCESS);
- response.writeBytes("authentication".getBytes(StandardCharsets.US_ASCII));
- channel.write(formatMessage(MSG_TERMINAL_REGISTER_RESPONSE, id, response), remoteAddress);
- }
-
- } else if (type == MSG_TERMINAL_AUTH) {
-
- sendGeneralResponse(channel, remoteAddress, id, type, index);
-
- } else if (type == MSG_LOCATION_REPORT) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedInt()));
-
- int flags = buf.readInt();
-
- position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
-
- position.setValid(BitUtil.check(flags, 1));
-
- double lat = buf.readUnsignedInt() * 0.000001;
- double lon = buf.readUnsignedInt() * 0.000001;
-
- if (BitUtil.check(flags, 2)) {
- position.setLatitude(-lat);
- } else {
- position.setLatitude(lat);
- }
-
- if (BitUtil.check(flags, 3)) {
- position.setLongitude(-lon);
- } else {
- position.setLongitude(lon);
- }
-
- position.setAltitude(buf.readShort());
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
- position.setCourse(buf.readUnsignedShort());
-
- DateBuilder dateBuilder = new DateBuilder(TimeZone.getTimeZone("GMT+8"))
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
-
- // additional information
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
deleted file mode 100644
index 7d6f0510d..000000000
--- a/src/org/traccar/protocol/HuabaoProtocolEncoder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 javax.xml.bind.DatatypeConverter;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- ChannelBuffer id = ChannelBuffers.wrappedBuffer(
- DatatypeConverter.parseHexBinary(getUniqueId(command.getDeviceId())));
-
- ChannelBuffer data = ChannelBuffers.dynamicBuffer();
- byte[] time = DatatypeConverter.parseHexBinary(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- data.writeByte(0x01);
- data.writeBytes(time);
- return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
- case Command.TYPE_ENGINE_RESUME:
- data.writeByte(0x00);
- data.writeBytes(time);
- return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/HunterProProtocol.java b/src/org/traccar/protocol/HunterProProtocol.java
deleted file mode 100644
index 17352a0f3..000000000
--- a/src/org/traccar/protocol/HunterProProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 HunterProProtocol extends BaseProtocol {
-
- public HunterProProtocol() {
- super("hunterpro");
- }
-
- @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, "\r"));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new HunterProProtocolDecoder(HunterProProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/HunterProProtocolDecoder.java b/src/org/traccar/protocol/HunterProProtocolDecoder.java
deleted file mode 100644
index b1e3f84a2..000000000
--- a/src/org/traccar/protocol/HunterProProtocolDecoder.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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 HunterProProtocolDecoder extends BaseProtocolDecoder {
-
- public HunterProProtocolDecoder(HunterProProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number(">(d+)<") // identifier
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder();
- dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/IdplProtocol.java b/src/org/traccar/protocol/IdplProtocol.java
deleted file mode 100644
index f90d3fe7f..000000000
--- a/src/org/traccar/protocol/IdplProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 java.util.List;
-
-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;
-
-public class IdplProtocol extends BaseProtocol {
-
- public IdplProtocol() {
- super("idpl");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new IdplProtocolDecoder(IdplProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/IdplProtocolDecoder.java b/src/org/traccar/protocol/IdplProtocolDecoder.java
deleted file mode 100644
index e56a0f022..000000000
--- a/src/org/traccar/protocol/IdplProtocolDecoder.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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 java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-import org.jboss.netty.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.Protocol;
-import org.traccar.helper.Parser;
-import org.traccar.helper.Parser.CoordinateFormat;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-public class IdplProtocolDecoder extends BaseProtocolDecoder {
-
- public IdplProtocolDecoder(Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("*ID") // start of frame
- .number("(d+),") // command code
- .number("(d+),") // imei
- .number("(dd)(dd)(dd),") // current date (ddmmyy)
- .number("(dd)(dd)(dd),") // current time (hhmmss)
- .expression("([A|V]),") // gps fix
- .number("(dd)(dd).?(d+),([NS]),") // latitude
- .number("(ddd)(dd).?(d+),([EW]),") // longitude
- .number("(d{1,3}.dd),") // speed
- .number("(d{1,3}.dd),") // course
- .number("(d{1,2}),") // sats
- .number("(d{1,3}),") // gsm signal strength
- .expression("([A|N|S]),") // vehicle status
- .expression("([0|1]),") // main power status
- .number("(d.dd),") // internal battery voltage
- .expression("([0|1]),") // sos alert
- .expression("([0|1]),") // body tamper
- .expression("([0|1])([0|1]),") // ac status + ign status
- .expression("([0|1|2]),") // output1 status
- .number("(d{1,3}),") // adc1
- .number("(d{1,3}),") // adc2
- .expression("([0-9A-Z]{3}),") // software version
- .expression("([L|R]),") // message type
- .number("(x{4})#") // crc
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_TYPE, parser.nextInt(0));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate(CoordinateFormat.DEG_MIN_MIN_HEM));
- position.setLongitude(parser.nextCoordinate(CoordinateFormat.DEG_MIN_MIN_HEM));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set("vehicleStatus", parser.next());
- position.set(Position.KEY_POWER, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- if (parser.nextInt(0) == 1) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
- parser.nextInt(0); // body tamper
- position.set("acStatus", parser.nextInt(0));
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_OUTPUT, parser.nextInt(0));
- position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
- position.set(Position.PREFIX_ADC + 2, parser.nextInt(0));
- position.set(Position.KEY_VERSION_FW, parser.next());
- position.set(Position.KEY_ARCHIVE, parser.next().equals("R"));
-
- parser.next(); // checksum
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/IntellitracFrameDecoder.java b/src/org/traccar/protocol/IntellitracFrameDecoder.java
deleted file mode 100644
index 49f8b4a5d..000000000
--- a/src/org/traccar/protocol/IntellitracFrameDecoder.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
-
-public class IntellitracFrameDecoder extends LineBasedFrameDecoder {
-
- private static final int MESSAGE_MINIMUM_LENGTH = 0;
-
- public IntellitracFrameDecoder(int maxFrameLength) {
- super(maxFrameLength);
- }
-
- // example of sync header: 0xFA 0xF8 0x1B 0x01 0x81 0x60 0x33 0x3C
-
- @Override
- protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
- return null;
- }
-
- // Check for sync packet
- if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
- ChannelBuffer syncMessage = buf.readBytes(8);
- if (channel != null) {
- channel.write(syncMessage);
- }
- }
-
- return super.decode(ctx, channel, buf);
- }
-
-}
diff --git a/src/org/traccar/protocol/IntellitracProtocol.java b/src/org/traccar/protocol/IntellitracProtocol.java
deleted file mode 100644
index 2d9421636..000000000
--- a/src/org/traccar/protocol/IntellitracProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.TrackerServer;
-
-import java.util.List;
-
-public class IntellitracProtocol extends BaseProtocol {
-
- public IntellitracProtocol() {
- super("intellitrac");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new IntellitracFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new IntellitracProtocolDecoder(IntellitracProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
deleted file mode 100644
index 8f4e4c0d6..000000000
--- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
-
- public IntellitracProtocolDecoder(IntellitracProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression(".+,").optional()
- .number("(d+),") // identifier
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(-?d+.d+),") // longitude
- .number("(-?d+.d+),") // latitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(-?d+.?d*),") // altitude
- .number("(d+),") // satellites
- .number("(d+),") // index
- .number("(d+),") // input
- .number("(d+),?") // output
- .number("(d+.d+)?,?") // adc1
- .number("(d+.d+)?,?") // adc2
- .groupBegin()
- .number("d{14},d+,")
- .number("(d+),") // vss
- .number("(d+),") // rpm
- .number("(-?d+),") // coolant
- .number("(d+),") // fuel
- .number("(d+),") // fuel consumption
- .number("(-?d+),") // fuel temperature
- .number("(d+),") // charger pressure
- .number("(d+),") // tpl
- .number("(d+),") // axle weight
- .number("(d+)") // odometer
- .groupEnd("?")
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- int satellites = parser.nextInt(0);
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
-
- position.set(Position.KEY_INDEX, parser.nextLong(0));
- position.set(Position.KEY_INPUT, parser.nextInt(0));
- position.set(Position.KEY_OUTPUT, parser.nextInt(0));
-
- position.set(Position.PREFIX_ADC + 1, parser.nextDouble(0));
- position.set(Position.PREFIX_ADC + 2, parser.nextDouble(0));
-
- // J1939 data
- position.set(Position.KEY_OBD_SPEED, parser.nextInt(0));
- position.set(Position.KEY_RPM, parser.nextInt(0));
- position.set("coolant", parser.nextInt(0));
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
- position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextInt(0));
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
- position.set("chargerPressure", parser.nextInt(0));
- position.set("tpl", parser.nextInt(0));
- position.set("axle", parser.nextInt(0));
- position.set(Position.KEY_OBD_ODOMETER, parser.nextInt(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/JpKorjarFrameDecoder.java b/src/org/traccar/protocol/JpKorjarFrameDecoder.java
deleted file mode 100644
index 33a1b3f36..000000000
--- a/src/org/traccar/protocol/JpKorjarFrameDecoder.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2016 Nyash (nyashh@gmail.com)
- *
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class JpKorjarFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 80) {
- return null;
- }
-
- int spaceIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ' ');
- if (spaceIndex == -1) {
- return null;
- }
-
- int endIndex = buf.indexOf(spaceIndex, buf.writerIndex(), (byte) ',');
- if (endIndex == -1) {
- return null;
- }
-
- return buf.readBytes(endIndex + 1);
- }
-
-}
diff --git a/src/org/traccar/protocol/JpKorjarProtocol.java b/src/org/traccar/protocol/JpKorjarProtocol.java
deleted file mode 100644
index c54994708..000000000
--- a/src/org/traccar/protocol/JpKorjarProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2016 Nyash (nyashh@gmail.com)
- *
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class JpKorjarProtocol extends BaseProtocol {
-
- public JpKorjarProtocol() {
- super("jpkorjar");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), this.getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
-
- pipeline.addLast("frameDecoder", new JpKorjarFrameDecoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new JpKorjarProtocolDecoder(JpKorjarProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
deleted file mode 100644
index 654b3e3d0..000000000
--- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2016 Nyash (nyashh@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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class JpKorjarProtocolDecoder extends BaseProtocolDecoder {
-
- public JpKorjarProtocolDecoder(JpKorjarProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("KORJAR.PL,")
- .number("(d+),") // imei
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d+.d+)([NS]),") // latitude
- .number("(d+.d+)([EW]),") // longitude
- .number("(d+.d+),") // speed
- .number("(d+),") // course
- .number("[FL]:(d+.d+)V,") // battery
- .number("([01]) ") // valid
- .number("(d+) ") // mcc
- .number("(d+) ") // mnc
- .number("(x+) ") // lac
- .number("(x+),") // cid
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
-
- position.setValid(parser.nextInt(0) == 1);
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java
deleted file mode 100644
index 5606ae1fc..000000000
--- a/src/org/traccar/protocol/Jt600FrameDecoder.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.text.ParseException;
-
-public class Jt600FrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 10) {
- return null;
- }
-
- char type = (char) buf.getByte(buf.readerIndex());
-
- if (type == '$') {
- 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);
- }
- } else if (type == '(') {
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
- if (endIndex != -1) {
- return buf.readBytes(endIndex + 1);
- }
- } else {
- throw new ParseException(null, 0); // unknown message
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Jt600Protocol.java b/src/org/traccar/protocol/Jt600Protocol.java
deleted file mode 100644
index 8c71ca4f6..000000000
--- a/src/org/traccar/protocol/Jt600Protocol.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.
- * 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.StringEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class Jt600Protocol extends BaseProtocol {
-
- public Jt600Protocol() {
- super("jt600");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_SET_TIMEZONE,
- Command.TYPE_REBOOT_DEVICE);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @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
deleted file mode 100644
index f76fd8069..000000000
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.BcdUtil;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
-
- public Jt600ProtocolDecoder(Jt600Protocol protocol) {
- super(protocol);
- }
-
- private static double convertCoordinate(int raw) {
- int degrees = raw / 1000000;
- double minutes = (raw % 1000000) / 10000.0;
- return degrees + minutes / 60;
- }
-
- private List<Position> decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
-
- List<Position> positions = new LinkedList<>();
-
- 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) {
- return null;
- }
-
- if (longFormat) {
- buf.readUnsignedByte(); // protocol
- }
-
- int version = BitUtil.from(buf.readUnsignedByte(), 4);
- buf.readUnsignedShort(); // length
-
- while (buf.readableBytes() > 1) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDay(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setYear(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
-
- double latitude = convertCoordinate(BcdUtil.readInteger(buf, 8));
- double longitude = convertCoordinate(BcdUtil.readInteger(buf, 9));
-
- byte flags = buf.readByte();
- position.setValid((flags & 0x1) == 0x1);
- if ((flags & 0x2) == 0) {
- latitude = -latitude;
- }
- position.setLatitude(latitude);
- if ((flags & 0x4) == 0) {
- longitude = -longitude;
- }
- position.setLongitude(longitude);
-
- position.setSpeed(BcdUtil.readInteger(buf, 2));
- position.setCourse(buf.readUnsignedByte() * 2.0);
-
- 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_LEVEL, battery);
- }
-
- CellTower cellTower = CellTower.fromCidLac(buf.readUnsignedShort(), buf.readUnsignedShort());
- cellTower.setSignalStrength((int) buf.readUnsignedByte());
- position.setNetwork(new Network(cellTower));
-
- } else if (version == 1) {
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_POWER, buf.readUnsignedByte());
-
- buf.readByte(); // other flags and sensors
-
- position.setAltitude(buf.readUnsignedShort());
-
- int cid = buf.readUnsignedShort();
- int lac = buf.readUnsignedShort();
- int rssi = buf.readUnsignedByte();
-
- if (cid != 0 && lac != 0) {
- CellTower cellTower = CellTower.fromCidLac(cid, lac);
- cellTower.setSignalStrength(rssi);
- position.setNetwork(new Network(cellTower));
- } else {
- position.set(Position.KEY_RSSI, rssi);
- }
-
- } else if (version == 2) {
-
- int fuel = buf.readUnsignedByte() << 8;
-
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
-
- fuel += buf.readUnsignedByte();
- position.set(Position.KEY_FUEL_LEVEL, fuel);
-
- }
-
- positions.add(position);
-
- }
-
- buf.readUnsignedByte(); // index
-
- return positions;
- }
-
- private static final Pattern PATTERN_W01 = new PatternBuilder()
- .text("(")
- .number("(d+),") // id
- .text("W01,") // type
- .number("(ddd)(dd.dddd),") // longitude
- .expression("([EW]),")
- .number("(dd)(dd.dddd),") // latitude
- .expression("([NS]),")
- .expression("([AV]),") // validity
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(d+),") // power
- .number("(d+),") // gps signal
- .number("(d+),") // gsm signal
- .number("(d+),") // alert type
- .any()
- .compile();
-
- private Position decodeW01(String sentence, Channel channel, SocketAddress remoteAddress) {
-
- Parser parser = new Parser(PATTERN_W01, 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.setLongitude(parser.nextCoordinate());
- position.setLatitude(parser.nextCoordinate());
- position.setValid(parser.next().equals("A"));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- position.set(Position.KEY_GPS, parser.nextInt(0));
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set("alertType", parser.nextInt(0));
-
- 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 (hhmmss)
- .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());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- 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(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
- position.set(Position.KEY_STATUS, parser.nextBinInt(0));
-
- CellTower cellTower = CellTower.fromCidLac(parser.nextInt(0), parser.nextInt(0));
- cellTower.setSignalStrength(parser.nextInt(0));
- position.setNetwork(new Network(cellTower));
-
- position.set(Position.KEY_ODOMETER, parser.nextLong(0) * 1000);
- position.set(Position.KEY_INDEX, parser.nextInt(0));
-
- 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 {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
- char first = (char) buf.getByte(0);
-
- if (first == '$') {
- return decodeBinary(buf, channel, remoteAddress);
- } else if (first == '(') {
- 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
deleted file mode 100644
index 377f104a3..000000000
--- a/src/org/traccar/protocol/Jt600ProtocolEncoder.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 java.util.TimeZone;
-
-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 = TimeZone.getTimeZone(command.getString(Command.KEY_TIMEZONE)).getRawOffset() / 60000;
- 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/KenjiProtocol.java b/src/org/traccar/protocol/KenjiProtocol.java
deleted file mode 100644
index 8b196a9ed..000000000
--- a/src/org/traccar/protocol/KenjiProtocol.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2016 by Carlos Alvarez (carlos.alvarez.rozas@gmail.com)
- *
- * 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 KenjiProtocol extends BaseProtocol {
-
- public KenjiProtocol() {
- super("kenji");
- }
-
-
- @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 KenjiProtocolDecoder(KenjiProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/KenjiProtocolDecoder.java b/src/org/traccar/protocol/KenjiProtocolDecoder.java
deleted file mode 100644
index 4216da0c3..000000000
--- a/src/org/traccar/protocol/KenjiProtocolDecoder.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * 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.BitUtil;
-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 KenjiProtocolDecoder extends BaseProtocolDecoder {
-
- public KenjiProtocolDecoder(KenjiProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text(">")
- .number("C(d{6}),") // device id
- .number("M(x{6}),") // alarm
- .number("O(x{4}),") // output
- .number("I(x{4}),") // input
- .number("D(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AV]),") // valid
- .number("([NS])(dd)(dd.d+),") // latitude
- .number("([EW])(ddd)(dd.d+),") // longitude
- .number("T(d+.d+),") // speed
- .number("H(d+.d+),") // course
- .number("Y(dd)(dd)(dd),") // date (ddmmyy)
- .number("G(d+)") // satellites
- .any()
- .compile();
-
- private String decodeAlarm(int value) {
- if (BitUtil.check(value, 2)) {
- return Position.ALARM_SOS;
- }
- if (BitUtil.check(value, 4)) {
- return Position.ALARM_LOW_BATTERY;
- }
- if (BitUtil.check(value, 6)) {
- return Position.ALARM_MOVEMENT;
- }
- if (BitUtil.check(value, 1) || BitUtil.check(value, 10) || BitUtil.check(value, 11)) {
- return Position.ALARM_VIBRATION;
- }
-
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Parser parser = new Parser(PATTERN, (String) msg);
- 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(Position.KEY_ALARM, decodeAlarm(parser.nextHexInt(0)));
- position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
- position.set(Position.KEY_INPUT, parser.nextHexInt(0));
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/KhdProtocol.java b/src/org/traccar/protocol/KhdProtocol.java
deleted file mode 100644
index 167727191..000000000
--- a/src/org/traccar/protocol/KhdProtocol.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class KhdProtocol extends BaseProtocol {
-
- public KhdProtocol() {
- super("khd");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(512, 3, 2));
- pipeline.addLast("objectEncoder", new KhdProtocolEncoder());
- pipeline.addLast("objectDecoder", new KhdProtocolDecoder(KhdProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
deleted file mode 100644
index d63219736..000000000
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.BcdUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-
-public class KhdProtocolDecoder extends BaseProtocolDecoder {
-
- public KhdProtocolDecoder(KhdProtocol protocol) {
- super(protocol);
- }
-
- private String readSerialNumber(ChannelBuffer buf) {
- int b1 = buf.readUnsignedByte();
- int b2 = buf.readUnsignedByte();
- if (b2 > 0x80) {
- b2 -= 0x80;
- }
- int b3 = buf.readUnsignedByte();
- if (b3 > 0x80) {
- b3 -= 0x80;
- }
- int b4 = buf.readUnsignedByte();
- String serialNumber = String.format("%02d%02d%02d%02d", b1, b2, b3, b4);
- return String.valueOf(Long.parseLong(serialNumber));
- }
-
- public static final int MSG_LOGIN = 0xB1;
- public static final int MSG_CONFIRMATION = 0x21;
- public static final int MSG_ON_DEMAND = 0x81;
- public static final int MSG_POSITION_UPLOAD = 0x80;
- public static final int MSG_POSITION_REUPLOAD = 0x8E;
- public static final int MSG_ALARM = 0x82;
- public static final int MSG_REPLY = 0x85;
- public static final int MSG_PERIPHERAL = 0xA3;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- int type = buf.readUnsignedByte();
- buf.readUnsignedShort(); // size
-
- if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD
- || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readSerialNumber(buf));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
- position.setTime(dateBuilder.getDate());
-
- position.setLatitude(BcdUtil.readCoordinate(buf));
- position.setLongitude(BcdUtil.readCoordinate(buf));
- position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
- position.setCourse(BcdUtil.readInteger(buf, 4));
- position.setValid((buf.readUnsignedByte() & 0x80) != 0);
-
- if (type != MSG_ALARM) {
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
- position.set(Position.KEY_HDOP, buf.readUnsignedByte());
- position.set(Position.KEY_VDOP, buf.readUnsignedByte());
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- buf.skipBytes(5); // other location data
-
- if (type == MSG_PERIPHERAL) {
-
- buf.readUnsignedShort(); // data length
-
- int dataType = buf.readUnsignedByte();
-
- buf.readUnsignedByte(); // content length
-
- switch (dataType) {
- case 0x01:
- position.set(Position.KEY_FUEL_LEVEL,
- buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
- break;
- case 0x02:
- position.set(Position.PREFIX_TEMP + 1,
- buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
- break;
- default:
- break;
- }
-
- }
-
- }
-
- return position;
-
- } else if (type == MSG_LOGIN && channel != null) {
-
- buf.skipBytes(4); // serial number
- buf.readByte(); // reserved
-
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(0x29); response.writeByte(0x29); // header
- response.writeByte(MSG_CONFIRMATION);
- response.writeShort(5); // size
- response.writeByte(buf.readUnsignedByte());
- response.writeByte(type);
- response.writeByte(0); // reserved
- response.writeByte(Checksum.xor(response.toByteBuffer()));
- response.writeByte(0x0D); // ending
- channel.write(response);
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/KhdProtocolEncoder.java b/src/org/traccar/protocol/KhdProtocolEncoder.java
deleted file mode 100644
index 618e43dad..000000000
--- a/src/org/traccar/protocol/KhdProtocolEncoder.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class KhdProtocolEncoder extends BaseProtocolEncoder {
-
- public static final int MSG_CUT_OIL = 0x39;
- public static final int MSG_RESUME_OIL = 0x38;
-
- private ChannelBuffer encodeCommand(int command) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeByte(0x29);
- buf.writeByte(0x29);
-
- buf.writeByte(command);
- buf.writeShort(6); // size
-
- buf.writeInt(0); // terminal id
-
- buf.writeByte(Checksum.xor(buf.toByteBuffer()));
- buf.writeByte(0x0D); // ending
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return encodeCommand(MSG_CUT_OIL);
- case Command.TYPE_ENGINE_RESUME:
- return encodeCommand(MSG_RESUME_OIL);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/L100FrameDecoder.java b/src/org/traccar/protocol/L100FrameDecoder.java
deleted file mode 100644
index a597cbd7d..000000000
--- a/src/org/traccar/protocol/L100FrameDecoder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class L100FrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 80) {
- return null;
- }
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x02);
- if (index == -1) {
- index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x04);
- if (index == -1) {
- return null;
- }
- }
-
- index += 2; // checksum
-
- if (buf.readableBytes() >= index - buf.readerIndex()) {
- return buf.readBytes(index - buf.readerIndex());
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/L100Protocol.java b/src/org/traccar/protocol/L100Protocol.java
deleted file mode 100644
index 2bcef4caa..000000000
--- a/src/org/traccar/protocol/L100Protocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class L100Protocol extends BaseProtocol {
-
- public L100Protocol() {
- super("l100");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new L100FrameDecoder());
- pipeline.addLast("objectDecoder", new L100ProtocolDecoder(L100Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
deleted file mode 100644
index 618448080..000000000
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.regex.Pattern;
-
-public class L100ProtocolDecoder extends BaseProtocolDecoder {
-
- public L100ProtocolDecoder(L100Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("ATL")
- .number("(d{15}),") // imei
- .text("$GPRMC,")
- .number("(dd)(dd)(dd)") // time (hhmmss.sss)
- .number(".(ddd)").optional()
- .expression(",([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .any()
- .text("#")
- .number("([01]+),") // io status
- .number("(d+.?d*|N.C),") // adc
- .expression("[^,]*,") // reserved
- .expression("[^,]*,") // reserved
- .number("(d+.d+),") // odometer
- .number("(d+.d+),") // temperature
- .number("(d+.d+),") // battery
- .number("(d+),") // gsm
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(x+),") // lac
- .number("(x+)") // cid
- .text("ATL")
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // start marker
- buf.readUnsignedByte(); // type
-
- String sentence = buf.readBytes(buf.readableBytes() - 2).toString(StandardCharsets.US_ASCII);
-
- Parser parser = new Parser(PATTERN, 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());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_STATUS, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0));
- position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
-
- int rssi = parser.nextInt(0);
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/LaipacProtocol.java b/src/org/traccar/protocol/LaipacProtocol.java
deleted file mode 100644
index 45b803a0f..000000000
--- a/src/org/traccar/protocol/LaipacProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 LaipacProtocol extends BaseProtocol {
-
- public LaipacProtocol() {
- super("laipac");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new LaipacProtocolDecoder(LaipacProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
deleted file mode 100644
index 32d4ff0e6..000000000
--- a/src/org/traccar/protocol/LaipacProtocolDecoder.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.Checksum;
-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 LaipacProtocolDecoder extends BaseProtocolDecoder {
-
- public LaipacProtocolDecoder(LaipacProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$AVRMC,")
- .expression("([^,]+),") // identifier
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AVRPavrp]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .number("([EW]),")
- .number("(d+.d+),") // speed
- .number("(d+.d+),") // course
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .expression("(.),") // type
- .expression("[^*]+").text("*")
- .number("(xx)") // checksum
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("$ECHK") && channel != null) {
- channel.write(sentence + "\r\n"); // heartbeat
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- String status = parser.next();
- position.setValid(status.toUpperCase().equals("A"));
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- String type = parser.next();
- String checksum = parser.next();
-
- if (channel != null) {
-
- if (Character.isLowerCase(status.charAt(0))) {
- String response = "$EAVACK," + type + "," + checksum;
- response += Checksum.nmea(response);
- channel.write(response);
- }
-
- if (type.equals("S") || type.equals("T")) {
- channel.write("$AVCFG,00000000,t*21");
- } else if (type.equals("3")) {
- channel.write("$AVCFG,00000000,d*31");
- } else if (type.equals("X") || type.equals("4")) {
- channel.write("$AVCFG,00000000,x*2D");
- }
-
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/M2mProtocol.java b/src/org/traccar/protocol/M2mProtocol.java
deleted file mode 100644
index 09393fed0..000000000
--- a/src/org/traccar/protocol/M2mProtocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- * 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.FixedLengthFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class M2mProtocol extends BaseProtocol {
-
- public M2mProtocol() {
- super("m2m");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(23));
- pipeline.addLast("objectDecoder", new M2mProtocolDecoder(M2mProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java
deleted file mode 100644
index a3c2ada2f..000000000
--- a/src/org/traccar/protocol/M2mProtocolDecoder.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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.
- * 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.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 M2mProtocolDecoder extends BaseProtocolDecoder {
-
- public M2mProtocolDecoder(M2mProtocol protocol) {
- super(protocol);
- }
-
- private boolean firstPacket = true;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- // Remove offset
- for (int i = 0; i < buf.readableBytes(); i++) {
- int b = buf.getByte(i);
- if (b != 0x0b) {
- buf.setByte(i, b - 0x20);
- }
- }
-
- if (firstPacket) {
-
- firstPacket = false;
-
- StringBuilder imei = new StringBuilder();
- for (int i = 0; i < 8; i++) {
- int b = buf.readByte();
- if (i != 0) {
- imei.append(b / 10);
- }
- imei.append(b % 10);
- }
-
- getDeviceSession(channel, remoteAddress, imei.toString());
-
- } else {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDay(buf.readUnsignedByte() & 0x3f)
- .setMonth(buf.readUnsignedByte() & 0x3f)
- .setYear(buf.readUnsignedByte())
- .setHour(buf.readUnsignedByte() & 0x3f)
- .setMinute(buf.readUnsignedByte() & 0x7f)
- .setSecond(buf.readUnsignedByte() & 0x7f);
- position.setTime(dateBuilder.getDate());
-
- int degrees = buf.readUnsignedByte();
- double latitude = buf.readUnsignedByte();
- latitude += buf.readUnsignedByte() / 100.0;
- latitude += buf.readUnsignedByte() / 10000.0;
- latitude /= 60;
- latitude += degrees;
-
- int b = buf.readUnsignedByte();
-
- degrees = (b & 0x7f) * 100 + buf.readUnsignedByte();
- double longitude = buf.readUnsignedByte();
- longitude += buf.readUnsignedByte() / 100.0;
- longitude += buf.readUnsignedByte() / 10000.0;
- longitude /= 60;
- longitude += degrees;
-
- if ((b & 0x80) != 0) {
- longitude = -longitude;
- }
- if ((b & 0x40) != 0) {
- latitude = -latitude;
- }
-
- position.setValid(true);
- position.setLatitude(latitude);
- position.setLongitude(longitude);
- position.setSpeed(buf.readUnsignedByte());
-
- int satellites = buf.readUnsignedByte();
- if (satellites == 0) {
- return null; // cell information
- }
- position.set(Position.KEY_SATELLITES, satellites);
-
- // decode other data
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MaestroProtocol.java b/src/org/traccar/protocol/MaestroProtocol.java
deleted file mode 100644
index 5e0b69916..000000000
--- a/src/org/traccar/protocol/MaestroProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.FixedLengthFrameDecoder;
-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 MaestroProtocol extends BaseProtocol {
-
- public MaestroProtocol() {
- super("maestro");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(160));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new MaestroProtocolDecoder(MaestroProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/MaestroProtocolDecoder.java b/src/org/traccar/protocol/MaestroProtocolDecoder.java
deleted file mode 100644
index 7d779a0a0..000000000
--- a/src/org/traccar/protocol/MaestroProtocolDecoder.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.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 MaestroProtocolDecoder extends BaseProtocolDecoder {
-
- public MaestroProtocolDecoder(MaestroProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("@")
- .number("(d+),") // imei
- .number("d+,") // index
- .expression("[^,]+,") // profile
- .expression("([01]),") // validity
- .number("(d+.d+),") // battery
- .number("(d+),") // gsm
- .expression("([01]),") // starter
- .expression("([01]),") // ignition
- .number("(dd)/(dd)/(dd),") // date (yy/mm/dd)
- .number("(dd):(dd):(dd),") // time (hh:mm:ss)
- .number("(-?d+.d+),") // longitude
- .number("(-?d+.d+),") // latitude
- .number("(d+.?d*),") // altitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(d+),") // satellites
- .number("(d+.?d*),") // hdop
- .number("(d+.?d*)") // odometer
- .number(",(d+)").optional() // adc
- .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());
-
- position.setValid(parser.nextInt(0) == 1);
-
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1609.34);
-
- if (parser.hasNext()) {
- position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/ManPowerProtocol.java b/src/org/traccar/protocol/ManPowerProtocol.java
deleted file mode 100644
index 60ce8b282..000000000
--- a/src/org/traccar/protocol/ManPowerProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 ManPowerProtocol extends BaseProtocol {
-
- public ManPowerProtocol() {
- super("manpower");
- }
-
- @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 ManPowerProtocolDecoder(ManPowerProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
deleted file mode 100644
index 6cff8b961..000000000
--- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
-
- public ManPowerProtocolDecoder(ManPowerProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("simei:")
- .number("(d+),") // imei
- .expression("[^,]*,[^,]*,")
- .expression("([^,]*),") // status
- .number("d+,d+,d+.?d*,")
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.dddd),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.dddd),") // longitude
- .expression("([EW])?,")
- .number("(d+.?d*),") // speed
- .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;
- }
-
- 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(Position.KEY_STATUS, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/MegastekFrameDecoder.java b/src/org/traccar/protocol/MegastekFrameDecoder.java
deleted file mode 100644
index d9cb07108..000000000
--- a/src/org/traccar/protocol/MegastekFrameDecoder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
-
-import java.nio.charset.StandardCharsets;
-
-public class MegastekFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 10) {
- return null;
- }
-
- if (Character.isDigit(buf.getByte(buf.readerIndex()))) {
- int length = 4 + Integer.parseInt(buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII));
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
- } else {
- while (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n') {
- buf.skipBytes(1);
- }
- int delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
- if (delimiter == -1) {
- delimiter = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '!');
- }
- if (delimiter != -1) {
- ChannelBuffer result = buf.readBytes(delimiter - buf.readerIndex());
- buf.skipBytes(1);
- return result;
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MegastekProtocol.java b/src/org/traccar/protocol/MegastekProtocol.java
deleted file mode 100644
index b28a05b92..000000000
--- a/src/org/traccar/protocol/MegastekProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.TrackerServer;
-
-import java.util.List;
-
-public class MegastekProtocol extends BaseProtocol {
-
- public MegastekProtocol() {
- super("megastek");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new MegastekFrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new MegastekProtocolDecoder(MegastekProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
deleted file mode 100644
index 3ef52acd1..000000000
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- * 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.
- * 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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class MegastekProtocolDecoder extends BaseProtocolDecoder {
-
- public MegastekProtocolDecoder(MegastekProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_GPRMC = new PatternBuilder()
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss)
- .expression("([AV]),") // validity
- .number("(d+)(dd.d+),([NS]),") // latitude
- .number("(d+)(dd.d+),([EW]),") // longitude
- .number("(d+.d+)?,") // speed
- .number("(d+.d+)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any() // checksum
- .compile();
-
- private static final Pattern PATTERN_SIMPLE = new PatternBuilder()
- .expression("[FL],") // flag
- .expression("([^,]*),") // alarm
- .number("imei:(d+),") // imei
- .number("(d+/?d*)?,") // satellites
- .number("(d+.d+)?,") // altitude
- .number("Battery=(d+)%,,?") // battery
- .number("(d)?,") // charger
- .number("(d+)?,") // mcc
- .number("(d+)?,") // mnc
- .number("(xxxx),") // lac
- .number("(xxxx);") // cid
- .any() // checksum
- .compile();
-
- private static final Pattern PATTERN_ALTERNATIVE = new PatternBuilder()
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(xxxx),") // lac
- .number("(xxxx),") // cid
- .number("(d+),") // gsm signal
- .number("(d+),") // battery
- .number("(d+),") // flags
- .number("(d+),") // inputs
- .number("(?:(d+),)?") // outputs
- .number("(d.?d*),") // adc 1
- .groupBegin()
- .number("(d.dd),") // adc 2
- .number("(d.dd),") // adc 3
- .groupEnd("?")
- .expression("([^;]+);") // alarm
- .any() // checksum
- .compile();
-
- private boolean parseLocation(String location, Position position) {
-
- Parser parser = new Parser(PATTERN_GPRMC, location);
- if (!parser.matches()) {
- return false;
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return true;
- }
-
- private Position decodeOld(Channel channel, SocketAddress remoteAddress, String sentence) {
-
- // Detect type
- boolean simple = sentence.charAt(3) == ',' || sentence.charAt(6) == ',';
-
- // Split message
- String id;
- String location;
- String status;
- if (simple) {
-
- int beginIndex = sentence.indexOf(',') + 1;
- int endIndex = sentence.indexOf(',', beginIndex);
- id = sentence.substring(beginIndex, endIndex);
-
- beginIndex = endIndex + 1;
- endIndex = sentence.indexOf('*', beginIndex);
- if (endIndex != -1) {
- endIndex += 3;
- } else {
- endIndex = sentence.length();
- }
- location = sentence.substring(beginIndex, endIndex);
-
- beginIndex = endIndex + 1;
- if (beginIndex > sentence.length()) {
- beginIndex = endIndex;
- }
- status = sentence.substring(beginIndex);
-
- } else {
-
- int beginIndex = 3;
- int endIndex = beginIndex + 16;
- id = sentence.substring(beginIndex, endIndex).trim();
-
- beginIndex = endIndex + 2;
- endIndex = sentence.indexOf('*', beginIndex) + 3;
- location = sentence.substring(beginIndex, endIndex);
-
- beginIndex = endIndex + 1;
- status = sentence.substring(beginIndex);
-
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- if (!parseLocation(location, position)) {
- return null;
- }
-
- if (simple) {
-
- Parser parser = new Parser(PATTERN_SIMPLE, status);
- if (parser.matches()) {
-
- position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), id);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- String sat = parser.next();
- if (sat.contains("/")) {
- position.set(Position.KEY_SATELLITES, Integer.parseInt(sat.split("/")[0]));
- position.set(Position.KEY_SATELLITES_VISIBLE, Integer.parseInt(sat.split("/")[1]));
- } else {
- position.set(Position.KEY_SATELLITES, Integer.parseInt(sat));
- }
-
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextDouble(0));
-
- String charger = parser.next();
- if (charger != null) {
- position.set(Position.KEY_CHARGE, Integer.parseInt(charger) == 1);
- }
-
- if (parser.hasNext(4)) {
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
- }
-
- } else {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- }
-
- } else {
-
- Parser parser = new Parser(PATTERN_ALTERNATIVE, status);
- if (parser.matches()) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0),
- parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
-
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextDouble());
-
- position.set(Position.KEY_FLAGS, parser.next());
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- position.set(Position.PREFIX_ADC + 3, parser.next());
- position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
-
- }
- }
-
- return position;
- }
-
- private static final Pattern PATTERN_NEW = new PatternBuilder()
- .number("dddd").optional()
- .text("$MGV")
- .number("ddd,")
- .number("(d+),") // imei
- .expression("[^,]*,") // name
- .expression("([RS]),")
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(d+)(dd.d+),([NS]),") // latitude
- .number("(d+)(dd.d+),([EW]),") // longitude
- .number("dd,")
- .number("(dd),") // satellites
- .number("dd,")
- .number("(d+.d+),") // hdop
- .number("(d+.d+)?,") // speed
- .number("(d+.d+)?,") // course
- .number("(-?d+.d+),") // altitude
- .number("(d+.d+)?,") // odometer
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(xxxx),") // lac
- .number("(xxxx),") // cid
- .number("(d+)?,") // gsm
- .expression("([01]+)?,") // input
- .expression("([01]+)?,") // output
- .number("(d+)?,") // adc1
- .number("(d+)?,") // adc2
- .number("(d+)?,") // adc3
- .groupBegin()
- .number("(-?d+.?d*)") // temperature 1
- .or().text(" ")
- .groupEnd("?").text(",")
- .groupBegin()
- .number("(-?d+.?d*)") // temperature 2
- .or().text(" ")
- .groupEnd("?").text(",")
- .number("(d+)?,") // rfid
- .expression("[^,]*,")
- .number("(d+)?,") // battery
- .expression("([^,]*);") // alert
- .any()
- .compile();
-
- private Position decodeNew(Channel channel, SocketAddress remoteAddress, String sentence) {
-
- Parser parser = new Parser(PATTERN_NEW, 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());
-
- if (parser.next().equals("S")) {
- position.set(Position.KEY_ARCHIVE, true);
- }
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
-
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- if (parser.hasNext()) {
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- }
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
-
- position.set(Position.KEY_INPUT, parser.nextBinInt(0));
- position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
-
- for (int i = 1; i <= 3; i++) {
- position.set(Position.PREFIX_ADC + i, parser.nextInt(0));
- }
-
- for (int i = 1; i <= 2; i++) {
- String adc = parser.next();
- if (adc != null) {
- position.set(Position.PREFIX_TEMP + i, Double.parseDouble(adc));
- }
- }
-
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- String battery = parser.next();
- if (battery != null) {
- position.set(Position.KEY_BATTERY, Integer.parseInt(battery));
- }
-
- position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
-
- return position;
- }
-
- private String decodeAlarm(String value) {
- switch (value) {
- case "SOS":
- case "Help":
- return Position.ALARM_SOS;
- case "Over Speed":
- case "OverSpeed":
- return Position.ALARM_OVERSPEED;
- case "LowSpeed":
- return Position.ALARM_LOW_SPEED;
- case "Low Battery":
- case "LowBattery":
- return Position.ALARM_LOW_BATTERY;
- case "VIB":
- return Position.ALARM_VIBRATION;
- case "Move in":
- case "Geo in":
- case "Geo1 in":
- case "Geo2 in":
- return Position.ALARM_GEOFENCE_ENTER;
- case "Move out":
- case "Geo out":
- case "Geo1 out":
- case "Geo2 out":
- return Position.ALARM_GEOFENCE_EXIT;
- default:
- return null;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.contains("$MG")) {
- return decodeNew(channel, remoteAddress, sentence);
- } else {
- return decodeOld(channel, remoteAddress, sentence);
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/MeiligaoFrameDecoder.java b/src/org/traccar/protocol/MeiligaoFrameDecoder.java
deleted file mode 100644
index 9340b6198..000000000
--- a/src/org/traccar/protocol/MeiligaoFrameDecoder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class MeiligaoFrameDecoder extends FrameDecoder {
-
- private static final int MESSAGE_HEADER = 4;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- // Strip not '$' (0x24) bytes from the beginning
- while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
- buf.readByte();
- }
-
- // Check length and return buffer
- if (buf.readableBytes() >= MESSAGE_HEADER) {
- int length = buf.getUnsignedShort(buf.readerIndex() + 2);
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MeiligaoProtocol.java b/src/org/traccar/protocol/MeiligaoProtocol.java
deleted file mode 100644
index dbdd2619a..000000000
--- a/src/org/traccar/protocol/MeiligaoProtocol.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class MeiligaoProtocol extends BaseProtocol {
-
- public MeiligaoProtocol() {
- super("meiligao");
- setSupportedDataCommands(
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_POSITION_PERIODIC,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_ALARM_GEOFENCE,
- Command.TYPE_SET_TIMEZONE,
- Command.TYPE_REBOOT_DEVICE);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new MeiligaoFrameDecoder());
- pipeline.addLast("objectEncoder", new MeiligaoProtocolEncoder());
- pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(MeiligaoProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectEncoder", new MeiligaoProtocolEncoder());
- pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(MeiligaoProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
deleted file mode 100644
index b0793037f..000000000
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ /dev/null
@@ -1,448 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
-
- public MeiligaoProtocolDecoder(MeiligaoProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .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 (ddmmyy)
- .expression("[^\\|]*")
- .groupBegin()
- .number("|(d+.d+)?") // hdop
- .number("|(-?d+.?d*)?") // altitude
- .number("|(xxxx)?") // state
- .groupBegin()
- .number("|(xxxx),(xxxx)") // adc
- .number(",(xxxx)").optional()
- .number(",(xxxx)").optional()
- .number(",(xxxx)").optional()
- .number(",(xxxx)").optional()
- .number(",(xxxx)").optional()
- .number(",(xxxx)").optional()
- .groupBegin()
- .number("|x{16,20}") // cell
- .number("|(xx)") // rssi
- .number("|(x{8})") // odometer
- .groupBegin()
- .number("|(xx)") // satellites
- .groupEnd("?")
- .or()
- .number("|(x{9})") // odometer
- .groupBegin()
- .number("|(x{5,})") // rfid
- .groupEnd("?")
- .groupEnd("?")
- .groupEnd("?")
- .groupEnd("?")
- .any()
- .compile();
-
- private static final Pattern PATTERN_RFID = new PatternBuilder()
- .number("|(dd)(dd)(dd),") // time (hhmmss)
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(d+)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(d+)(dd.d+),") // longitude
- .expression("([EW])")
- .compile();
-
- private static final Pattern PATTERN_OBD = new PatternBuilder()
- .number("(d+.d+),") // battery
- .number("(d+),") // rpm
- .number("(d+),") // speed
- .number("(d+.d+),") // throttle
- .number("(d+.d+),") // engine load
- .number("(-?d+),") // coolant temp
- .number("(d+.d+),") // instantaneous fuel
- .number("(d+.d+),") // average fuel
- .number("(d+.d+),") // driving range
- .number("(d+.?d*),") // odometer
- .number("(d+.d+),") // single fuel consumption
- .number("(d+.d+),") // total fuel consumption
- .number("(d+),") // error code count
- .number("(d+),") // hard acceleration count
- .number("(d+)") // hard brake count
- .compile();
-
- private static final Pattern PATTERN_OBDA = new PatternBuilder()
- .number("(d+),") // total ignition
- .number("(d+.d+),") // total driving time
- .number("(d+.d+),") // total idling time
- .number("(d+),") // average hot start time
- .number("(d+),") // average speed
- .number("(d+),") // history highest speed
- .number("(d+),") // history highest rpm
- .number("(d+),") // total hard acceleration
- .number("(d+)") // total hard brake
- .compile();
-
- public static final int MSG_HEARTBEAT = 0x0001;
- public static final int MSG_SERVER = 0x0002;
- public static final int MSG_LOGIN = 0x5000;
- public static final int MSG_LOGIN_RESPONSE = 0x4000;
- public static final int MSG_POSITION = 0x9955;
- public static final int MSG_POSITION_LOGGED = 0x9016;
- public static final int MSG_ALARM = 0x9999;
- public static final int MSG_RFID = 0x9966;
- public static final int MSG_RETRANSMISSION = 0x6688;
-
- public static final int MSG_OBD_RT = 0x9901;
- public static final int MSG_OBD_RTA = 0x9902;
-
- private DeviceSession identify(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
- StringBuilder builder = new StringBuilder();
-
- for (int i = 0; i < 7; i++) {
- int b = buf.readUnsignedByte();
-
- // First digit
- int d1 = (b & 0xf0) >> 4;
- if (d1 == 0xf) {
- break;
- }
- builder.append(d1);
-
- // Second digit
- int d2 = b & 0x0f;
- if (d2 == 0xf) {
- break;
- }
- builder.append(d2);
- }
-
- String id = builder.toString();
-
- if (id.length() == 14) {
- return getDeviceSession(channel, remoteAddress, id, id + Checksum.luhn(Long.parseLong(id)));
- } else {
- return getDeviceSession(channel, remoteAddress, id);
- }
- }
-
- private static void sendResponse(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int type, ChannelBuffer msg) {
-
- if (channel != null) {
- ChannelBuffer buf = ChannelBuffers.buffer(
- 2 + 2 + id.readableBytes() + 2 + msg.readableBytes() + 2 + 2);
-
- buf.writeByte('@');
- buf.writeByte('@');
- buf.writeShort(buf.capacity());
- buf.writeBytes(id);
- buf.writeShort(type);
- buf.writeBytes(msg);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
- buf.writeByte('\r');
- buf.writeByte('\n');
-
- channel.write(buf, remoteAddress);
- }
- }
-
- private String getServer(Channel channel) {
- String server = Context.getConfig().getString(getProtocolName() + ".server");
- if (server == null) {
- InetSocketAddress address = (InetSocketAddress) channel.getLocalAddress();
- server = address.getAddress().getHostAddress() + ":" + address.getPort();
- }
- return server;
- }
-
- private String decodeAlarm(short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x12:
- return Position.ALARM_MOVEMENT;
- case 0x13:
- return Position.ALARM_GEOFENCE_ENTER;
- case 0x14:
- return Position.ALARM_ACCIDENT;
- case 0x50:
- return Position.ALARM_POWER_OFF;
- case 0x53:
- return Position.ALARM_GPS_ANTENNA_CUT;
- case 0x72:
- return Position.ALARM_BRAKING;
- case 0x73:
- return Position.ALARM_ACCELERATION;
- default:
- return null;
- }
- }
-
- private Position decodeRegular(Position position, String sentence) {
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- if (parser.hasNext()) {
- position.setSpeed(parser.nextDouble(0));
- }
-
- if (parser.hasNext()) {
- position.setCourse(parser.nextDouble(0));
- }
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_HDOP, parser.nextDouble());
-
- if (parser.hasNext()) {
- position.setAltitude(parser.nextDouble(0));
- }
-
- position.set(Position.KEY_STATUS, parser.next());
-
- for (int i = 1; i <= 8; i++) {
- position.set(Position.PREFIX_ADC + i, parser.nextHexInt());
- }
-
- position.set(Position.KEY_RSSI, parser.nextHexInt());
- position.set(Position.KEY_ODOMETER, parser.nextHexLong());
- position.set(Position.KEY_SATELLITES, parser.nextHexInt());
- position.set(Position.KEY_ODOMETER, parser.nextHexLong());
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- return position;
- }
-
- private Position decodeRfid(Position position, String sentence) {
- Parser parser = new Parser(PATTERN_RFID, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- return position;
- }
-
- private Position decodeObd(Position position, String sentence) {
- Parser parser = new Parser(PATTERN_OBD, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_BATTERY, parser.nextDouble());
- position.set(Position.KEY_RPM, parser.nextInt());
- position.set(Position.KEY_OBD_SPEED, parser.nextInt());
- position.set(Position.KEY_THROTTLE, parser.nextDouble());
- position.set(Position.KEY_ENGINE_LOAD, parser.nextDouble());
- position.set(Position.KEY_COOLANT_TEMP, parser.nextInt());
- position.set(Position.KEY_FUEL_CONSUMPTION, parser.nextDouble());
- position.set("averageFuelConsumption", parser.nextDouble());
- position.set("drivingRange", parser.nextDouble());
- position.set(Position.KEY_ODOMETER, parser.nextDouble());
- position.set("singleFuelConsumption", parser.nextDouble());
- position.set("totalFuelConsumption", parser.nextDouble());
- position.set(Position.KEY_DTCS, parser.nextInt());
- position.set("hardAccelerationCount", parser.nextInt());
- position.set("hardBrakingCount", parser.nextInt());
-
- return position;
- }
-
- private Position decodeObdA(Position position, String sentence) {
- Parser parser = new Parser(PATTERN_OBDA, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- getLastLocation(position, null);
-
- position.set("totalIgnitionNo", parser.nextInt(0));
- position.set("totalDrivingTime", parser.nextDouble(0));
- position.set("totalIdlingTime", parser.nextDouble(0));
- position.set("averageHotStartTime", parser.nextInt(0));
- position.set("averageSpeed", parser.nextInt(0));
- position.set("historyHighestSpeed", parser.nextInt(0));
- position.set("historyHighestRpm", parser.nextInt(0));
- position.set("totalHarshAccerleration", parser.nextInt(0));
- position.set("totalHarshBrake", parser.nextInt(0));
-
- return position;
- }
-
- private List<Position> decodeRetransmission(ChannelBuffer buf, DeviceSession deviceSession) {
- List<Position> positions = new LinkedList<>();
-
- int count = buf.readUnsignedByte();
- for (int i = 0; i < count; i++) {
-
- buf.readUnsignedByte(); // alarm
-
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\\');
- if (endIndex < 0) {
- endIndex = buf.writerIndex() - 4;
- }
-
- String sentence = buf.readBytes(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position = decodeRegular(position, sentence);
-
- if (position != null) {
- positions.add(position);
- }
-
- if (buf.readableBytes() > 4) {
- buf.readUnsignedByte(); // delimiter
- }
-
- }
-
- return positions;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
- buf.skipBytes(2); // header
- buf.readShort(); // length
- ChannelBuffer id = buf.readBytes(7);
- int command = buf.readUnsignedShort();
- ChannelBuffer response;
-
- if (channel != null) {
- if (command == MSG_LOGIN) {
- response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
- sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response);
- return null;
- } else if (command == MSG_HEARTBEAT) {
- response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
- sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response);
- return null;
- } else if (command == MSG_SERVER) {
- response = ChannelBuffers.copiedBuffer(getServer(channel), StandardCharsets.US_ASCII);
- sendResponse(channel, remoteAddress, id, MSG_SERVER, response);
- return null;
- }
- }
-
- DeviceSession deviceSession = identify(id, channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- if (command == MSG_RETRANSMISSION) {
-
- return decodeRetransmission(buf, deviceSession);
-
- } else {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- if (command == MSG_ALARM) {
- short alarmCode = buf.readUnsignedByte();
- position.set(Position.KEY_ALARM, decodeAlarm(alarmCode));
- if (alarmCode >= 0x02 && alarmCode <= 0x05) {
- position.set(Position.PREFIX_IN + alarmCode, 1);
- } else if (alarmCode >= 0x32 && alarmCode <= 0x35) {
- position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0);
- }
- } else if (command == MSG_POSITION_LOGGED) {
- buf.skipBytes(6);
- }
-
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (command == MSG_RFID) {
- for (int i = 0; i < 15; i++) {
- long rfid = buf.readUnsignedInt();
- if (rfid != 0) {
- String card = String.format("%010d", rfid);
- position.set("card" + (i + 1), card);
- position.set(Position.KEY_DRIVER_UNIQUE_ID, card);
- }
- }
- }
-
- String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);
-
- if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) {
- return decodeRegular(position, sentence);
- } else if (command == MSG_RFID) {
- return decodeRfid(position, sentence);
- } else if (command == MSG_OBD_RT) {
- return decodeObd(position, sentence);
- } else if (command == MSG_OBD_RTA) {
- return decodeObdA(position, sentence);
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
deleted file mode 100644
index 2e0a1e84c..000000000
--- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import javax.xml.bind.DatatypeConverter;
-import java.nio.charset.StandardCharsets;
-import java.util.TimeZone;
-
-public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
-
- public static final int MSG_TRACK_ON_DEMAND = 0x4101;
- public static final int MSG_TRACK_BY_INTERVAL = 0x4102;
- public static final int MSG_MOVEMENT_ALARM = 0x4106;
- public static final int MSG_OUTPUT_CONTROL = 0x4115;
- public static final int MSG_TIME_ZONE = 0x4132;
- public static final int MSG_REBOOT_GPS = 0x4902;
-
- private ChannelBuffer encodeContent(long deviceId, int type, ChannelBuffer content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeByte('@');
- buf.writeByte('@');
-
- buf.writeShort(2 + 2 + 7 + 2 + content.readableBytes() + 2 + 2); // message length
-
- buf.writeBytes(DatatypeConverter.parseHexBinary((getUniqueId(deviceId) + "FFFFFFFFFFFFFF").substring(0, 14)));
-
- buf.writeShort(type);
-
- buf.writeBytes(content);
-
- buf.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
-
- buf.writeByte('\r');
- buf.writeByte('\n');
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- ChannelBuffer content = ChannelBuffers.dynamicBuffer();
-
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return encodeContent(command.getDeviceId(), MSG_TRACK_ON_DEMAND, content);
- case Command.TYPE_POSITION_PERIODIC:
- content.writeShort(command.getInteger(Command.KEY_FREQUENCY) / 10);
- return encodeContent(command.getDeviceId(), MSG_TRACK_BY_INTERVAL, content);
- case Command.TYPE_ENGINE_STOP:
- content.writeByte(0x01);
- return encodeContent(command.getDeviceId(), MSG_OUTPUT_CONTROL, content);
- case Command.TYPE_ENGINE_RESUME:
- content.writeByte(0x00);
- return encodeContent(command.getDeviceId(), MSG_OUTPUT_CONTROL, content);
- case Command.TYPE_ALARM_GEOFENCE:
- content.writeShort(command.getInteger(Command.KEY_RADIUS));
- return encodeContent(command.getDeviceId(), MSG_MOVEMENT_ALARM, content);
- case Command.TYPE_SET_TIMEZONE:
- int offset = TimeZone.getTimeZone(command.getString(Command.KEY_TIMEZONE)).getRawOffset() / 60000;
- content.writeBytes(String.valueOf(offset).getBytes(StandardCharsets.US_ASCII));
- return encodeContent(command.getDeviceId(), MSG_TIME_ZONE, content);
- case Command.TYPE_REBOOT_DEVICE:
- return encodeContent(command.getDeviceId(), MSG_REBOOT_GPS, content);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java
deleted file mode 100644
index 1eb0dae0f..000000000
--- a/src/org/traccar/protocol/MeitrackFrameDecoder.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.nio.charset.StandardCharsets;
-
-public class MeitrackFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 10) {
- return null;
- }
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
- if (index != -1) {
- int length = index - buf.readerIndex() + Integer.parseInt(
- buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, StandardCharsets.US_ASCII));
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
deleted file mode 100644
index e89825da5..000000000
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.
- * 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.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.nio.ByteOrder;
-import java.util.List;
-
-public class MeitrackProtocol extends BaseProtocol {
-
- public MeitrackProtocol() {
- super("meitrack");
- setSupportedDataCommands(
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_ALARM_ARM,
- Command.TYPE_ALARM_DISARM,
- Command.TYPE_REQUEST_PHOTO,
- Command.TYPE_SEND_SMS);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new MeitrackFrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
- pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new MeitrackProtocolEncoder());
- pipeline.addLast("objectDecoder", new MeitrackProtocolDecoder(MeitrackProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
deleted file mode 100644
index 5b67aebe3..000000000
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
-
- private ChannelBuffer photo;
-
- public MeitrackProtocolDecoder(MeitrackProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$$").expression(".") // flag
- .number("d+,") // length
- .number("(d+),") // imei
- .number("xxx,") // command
- .number("d+,").optional()
- .number("(d+),") // event
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("([AV]),") // validity
- .number("(d+),") // satellites
- .number("(d+),") // rssi
- .number("(d+.?d*),") // speed
- .number("(d+),") // course
- .number("(d+.?d*),") // hdop
- .number("(-?d+),") // altitude
- .number("(d+),") // odometer
- .number("(d+),") // runtime
- .number("(d+)|") // mcc
- .number("(d+)|") // mnc
- .number("(x+)|") // lac
- .number("(x+),") // cid
- .number("(x+),") // state
- .number("(x+)?|") // adc1
- .number("(x+)?|") // adc2
- .number("(x+)?|") // adc3
- .number("(x+)|") // battery
- .number("(x+)?,") // power
- .groupBegin()
- .expression("([^,]+)?,") // event specific
- .expression("[^,]*,") // reserved
- .number("(d+)?,") // protocol
- .number("(x{4})?") // fuel
- .number("(?:,(x{6}(?:|x{6})*))?") // temperature
- .groupEnd("?")
- .any()
- .text("*")
- .number("xx")
- .text("\r\n").optional()
- .compile();
-
- private String decodeAlarm(int event) {
- switch (event) {
- case 1:
- return Position.ALARM_SOS;
- case 17:
- return Position.ALARM_LOW_BATTERY;
- case 18:
- return Position.ALARM_LOW_POWER;
- case 19:
- return Position.ALARM_OVERSPEED;
- case 20:
- return Position.ALARM_GEOFENCE_ENTER;
- case 21:
- return Position.ALARM_GEOFENCE_EXIT;
- case 22:
- return Position.ALARM_POWER_RESTORED;
- case 23:
- return Position.ALARM_POWER_CUT;
- case 36:
- return Position.ALARM_TOW;
- default:
- return null;
- }
- }
-
- private Position decodeRegular(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII));
- 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());
-
- int event = parser.nextInt(0);
- position.set(Position.KEY_EVENT, event);
- position.set(Position.KEY_ALARM, decodeAlarm(event));
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- int rssi = parser.nextInt(0);
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_HDOP, parser.nextDouble());
-
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- position.set("runtime", parser.next());
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
-
- position.set(Position.KEY_STATUS, parser.next());
-
- for (int i = 1; i <= 3; i++) {
- if (parser.hasNext()) {
- position.set(Position.PREFIX_ADC + i, parser.nextHexInt(0));
- }
- }
-
- String deviceModel = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getModel();
- if (deviceModel == null) {
- deviceModel = "";
- }
- switch (deviceModel.toUpperCase()) {
- case "MVT340":
- case "MVT380":
- position.set(Position.KEY_BATTERY, parser.nextHexInt(0) * 3.0 * 2.0 / 1024.0);
- position.set(Position.KEY_POWER, parser.nextHexInt(0) * 3.0 * 16.0 / 1024.0);
- break;
- case "MT90":
- position.set(Position.KEY_BATTERY, parser.nextHexInt(0) * 3.3 * 2.0 / 4096.0);
- position.set(Position.KEY_POWER, parser.nextHexInt(0));
- break;
- case "T1":
- case "T3":
- case "MVT100":
- case "MVT600":
- case "MVT800":
- case "TC68":
- case "TC68S":
- position.set(Position.KEY_BATTERY, parser.nextHexInt(0) * 3.3 * 2.0 / 4096.0);
- position.set(Position.KEY_POWER, parser.nextHexInt(0) * 3.3 * 16.0 / 4096.0);
- break;
- case "T311":
- case "T322X":
- case "T333":
- case "T355":
- position.set(Position.KEY_BATTERY, parser.nextHexInt(0) / 100.0);
- position.set(Position.KEY_POWER, parser.nextHexInt(0) / 100.0);
- break;
- default:
- position.set(Position.KEY_BATTERY, parser.nextHexInt(0));
- position.set(Position.KEY_POWER, parser.nextHexInt(0));
- break;
- }
-
- String eventData = parser.next();
- if (eventData != null && !eventData.isEmpty()) {
- switch (event) {
- case 37:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, eventData);
- break;
- default:
- position.set("eventData", eventData);
- break;
- }
- }
-
- int protocol = parser.nextInt(0);
-
- if (parser.hasNext()) {
- String fuel = parser.next();
- position.set(Position.KEY_FUEL_LEVEL,
- Integer.parseInt(fuel.substring(0, 2), 16) + Integer.parseInt(fuel.substring(2), 16) * 0.01);
- }
-
- if (parser.hasNext()) {
- for (String temp : parser.next().split("\\|")) {
- int index = Integer.parseInt(temp.substring(0, 2), 16);
- if (protocol >= 3) {
- double value = (short) Integer.parseInt(temp.substring(2), 16);
- position.set(Position.PREFIX_TEMP + index, value * 0.01);
- } else {
- double value = Byte.parseByte(temp.substring(2, 4), 16);
- value += (value < 0 ? -0.01 : 0.01) * Integer.parseInt(temp.substring(4), 16);
- position.set(Position.PREFIX_TEMP + index, value);
- }
- }
- }
-
- return position;
- }
-
- private List<Position> decodeBinaryC(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<>();
-
- String flag = buf.toString(2, 1, StandardCharsets.US_ASCII);
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
-
- String imei = buf.toString(index + 1, 15, StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4);
-
- while (buf.readableBytes() >= 0x34) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
-
- position.setLatitude(buf.readInt() * 0.000001);
- position.setLongitude(buf.readInt() * 0.000001);
-
- position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 946684800 = 2000-01-01
-
- position.setValid(buf.readUnsignedByte() == 1);
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- int rssi = buf.readUnsignedByte();
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort());
-
- position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
-
- position.setAltitude(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set("runtime", buf.readUnsignedInt());
-
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- rssi)));
-
- position.set(Position.KEY_STATUS, buf.readUnsignedShort());
-
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
- position.set(Position.KEY_POWER, buf.readUnsignedShort());
-
- buf.readUnsignedInt(); // geo-fence
-
- positions.add(position);
- }
-
- if (channel != null) {
- StringBuilder command = new StringBuilder("@@");
- command.append(flag).append(27 + positions.size() / 10).append(",");
- command.append(imei).append(",CCC,").append(positions.size()).append("*");
- int checksum = 0;
- for (int i = 0; i < command.length(); i += 1) {
- checksum += command.charAt(i);
- }
- command.append(String.format("%02x", checksum & 0xff).toUpperCase());
- command.append("\r\n");
- channel.write(command.toString()); // delete processed data
- }
-
- return positions;
- }
-
- private List<Position> decodeBinaryE(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<>();
-
- buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',') + 1);
- String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
- buf.skipBytes(1 + 3 + 1);
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- buf.readUnsignedInt(); // remaining cache
- int count = buf.readUnsignedShort();
-
- for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedShort(); // length
- buf.readUnsignedShort(); // index
-
- int paramCount = buf.readUnsignedByte();
- for (int j = 0; j < paramCount; j++) {
- int id = buf.readUnsignedByte();
- switch (id) {
- case 0x01:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- break;
- case 0x05:
- position.setValid(buf.readUnsignedByte() > 0);
- break;
- case 0x06:
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- default:
- buf.readUnsignedByte();
- break;
- }
- }
-
- paramCount = buf.readUnsignedByte();
- for (int j = 0; j < paramCount; j++) {
- int id = buf.readUnsignedByte();
- switch (id) {
- case 0x08:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- break;
- case 0x09:
- position.setCourse(buf.readUnsignedShort() * 0.1);
- break;
- case 0x0B:
- position.setAltitude(buf.readShort());
- break;
- default:
- buf.readUnsignedShort();
- break;
- }
- }
-
- paramCount = buf.readUnsignedByte();
- for (int j = 0; j < paramCount; j++) {
- int id = buf.readUnsignedByte();
- switch (id) {
- case 0x02:
- position.setLatitude(buf.readInt() * 0.000001);
- break;
- case 0x03:
- position.setLongitude(buf.readInt() * 0.000001);
- break;
- case 0x04:
- position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 2000-01-01
- break;
- default:
- buf.readUnsignedInt();
- break;
- }
- }
-
- paramCount = buf.readUnsignedByte();
- for (int j = 0; j < paramCount; j++) {
- buf.readUnsignedByte(); // id
- buf.skipBytes(buf.readUnsignedByte()); // value
- }
-
- positions.add(position);
- }
-
- return positions;
- }
-
- private void requestPhotoPacket(Channel channel, String imei, int index) {
- if (channel != null) {
- String content = "D00,camera_picture.jpg," + index;
- int length = 1 + imei.length() + 1 + content.length() + 5;
- String response = String.format("@@O%02d,%s,%s*", length, imei, content);
- response += Checksum.sum(response) + "\r\n";
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
- String imei = buf.toString(index + 1, 15, StandardCharsets.US_ASCII);
- index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ',');
- String type = buf.toString(index + 1, 3, StandardCharsets.US_ASCII);
-
- switch (type) {
- case "D00":
- index = buf.indexOf(index + 1 + type.length() + 1, buf.writerIndex(), (byte) ',') + 1;
- int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
- int total = Integer.parseInt(buf.toString(index, endIndex - index, StandardCharsets.US_ASCII));
- index = endIndex + 1;
- endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
- int current = Integer.parseInt(buf.toString(index, endIndex - index, StandardCharsets.US_ASCII));
-
- buf.readerIndex(endIndex + 1);
- photo.writeBytes(buf.readBytes(buf.readableBytes() - 1 - 2 - 2));
-
- if (current == total - 1) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(getDeviceSession(channel, remoteAddress, imei).getDeviceId());
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg"));
- photo = null;
-
- return position;
- } else {
- if ((current + 1) % 8 == 0) {
- requestPhotoPacket(channel, imei, current + 1);
- }
- return null;
- }
- case "D03":
- photo = ChannelBuffers.dynamicBuffer();
- requestPhotoPacket(channel, imei, 0);
- return null;
- case "CCC":
- return decodeBinaryC(channel, remoteAddress, buf);
- case "CCE":
- return decodeBinaryE(channel, remoteAddress, buf);
- default:
- return decodeRegular(channel, remoteAddress, buf);
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
deleted file mode 100644
index b10a751c1..000000000
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.util.Map;
-
-public class MeitrackProtocolEncoder extends StringProtocolEncoder {
-
- private Object formatCommand(Command command, char dataId, String content) {
- String uniqueId = getUniqueId(command.getDeviceId());
- int length = 1 + uniqueId.length() + 1 + content.length() + 5;
- String result = String.format("@@%c%02d,%s,%s*", dataId, length, uniqueId, content);
- result += Checksum.sum(result) + "\r\n";
- return result;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- Map<String, Object> attributes = command.getAttributes();
-
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, 'Q', "A10");
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, 'M', "C01,0,12222");
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, 'M', "C01,0,02222");
- case Command.TYPE_ALARM_ARM:
- return formatCommand(command, 'M', "C01,0,22122");
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, 'M', "C01,0,22022");
- case Command.TYPE_REQUEST_PHOTO:
- return formatCommand(command, 'D', "D03,1,camera_picture.jpg");
- case Command.TYPE_SEND_SMS:
- return formatCommand(command, 'f', "C02,0,"
- + attributes.get(Command.KEY_PHONE) + "," + attributes.get(Command.KEY_MESSAGE));
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MiniFinderProtocol.java b/src/org/traccar/protocol/MiniFinderProtocol.java
deleted file mode 100644
index c36acb238..000000000
--- a/src/org/traccar/protocol/MiniFinderProtocol.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.
- * 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 org.traccar.model.Command;
-
-import java.util.List;
-
-public class MiniFinderProtocol extends BaseProtocol {
-
- public MiniFinderProtocol() {
- super("minifinder");
- setSupportedDataCommands(
- Command.TYPE_SET_TIMEZONE,
- Command.TYPE_VOICE_MONITORING,
- Command.TYPE_ALARM_SPEED,
- Command.TYPE_ALARM_GEOFENCE,
- Command.TYPE_ALARM_VIBRATION,
- Command.TYPE_SET_AGPS,
- Command.TYPE_ALARM_FALL,
- Command.TYPE_MODE_POWER_SAVING,
- Command.TYPE_MODE_DEEP_SLEEP,
- Command.TYPE_SOS_NUMBER,
- Command.TYPE_SET_INDICATOR);
- }
-
- @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("objectEncoder", new MiniFinderProtocolEncoder());
- pipeline.addLast("objectDecoder", new MiniFinderProtocolDecoder(MiniFinderProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
deleted file mode 100644
index 05994b697..000000000
--- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.BitUtil;
-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 MiniFinderProtocolDecoder extends BaseProtocolDecoder {
-
- public MiniFinderProtocolDecoder(MiniFinderProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_FIX = new PatternBuilder()
- .number("(d+)/(d+)/(d+),") // date (dd/mm/yy)
- .number("(d+):(d+):(d+),") // time (hh:mm:ss)
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .compile();
-
- private static final Pattern PATTERN_STATE = new PatternBuilder()
- .number("(d+.?d*),") // speed (km/h)
- .number("(d+.?d*),") // course
- .number("(x+),") // flags
- .number("(-?d+.d+),") // altitude (meters)
- .number("(d+),") // battery (percentage)
- .compile();
-
- private static final Pattern PATTERN_A = new PatternBuilder()
- .text("!A,")
- .expression(PATTERN_FIX.pattern())
- .any() // unknown 3 fields
- .compile();
-
- private static final Pattern PATTERN_C = new PatternBuilder()
- .text("!C,")
- .expression(PATTERN_FIX.pattern())
- .expression(PATTERN_STATE.pattern())
- .any() // unknown 3 fields
- .compile();
-
- private static final Pattern PATTERN_BD = new PatternBuilder()
- .expression("![BD],") // B - buffered, D - live
- .expression(PATTERN_FIX.pattern())
- .expression(PATTERN_STATE.pattern())
- .number("(d+),") // satellites in use
- .number("(d+),") // satellites in view
- .number("(d+.?d*)") // hdop
- .compile();
-
- private void decodeFix(Position position, Parser parser) {
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- }
-
- private void decodeFlags(Position position, int flags) {
-
- position.setValid(BitUtil.to(flags, 2) > 0);
- if (BitUtil.check(flags, 1)) {
- position.set(Position.KEY_APPROXIMATE, true);
- }
-
- if (BitUtil.check(flags, 2)) {
- position.set(Position.KEY_ALARM, Position.ALARM_FAULT);
- }
- if (BitUtil.check(flags, 6)) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
- if (BitUtil.check(flags, 7)) {
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- }
- if (BitUtil.check(flags, 8)) {
- position.set(Position.KEY_ALARM, Position.ALARM_FALL_DOWN);
- }
- if (BitUtil.check(flags, 9) || BitUtil.check(flags, 10) || BitUtil.check(flags, 11)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE);
- }
- if (BitUtil.check(flags, 12)) {
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- }
- if (BitUtil.check(flags, 15) || BitUtil.check(flags, 14)) {
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- }
-
- position.set(Position.KEY_RSSI, BitUtil.between(flags, 16, 21));
- position.set(Position.KEY_CHARGE, BitUtil.check(flags, 22));
- }
-
- private void decodeState(Position position, Parser parser) {
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
-
- position.setCourse(parser.nextDouble(0));
- if (position.getCourse() > 360) {
- position.setCourse(0);
- }
-
- decodeFlags(position, parser.nextHexInt(0));
-
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("!1,")) {
- int index = sentence.indexOf(',', 3);
- if (index < 0) {
- index = sentence.length();
- }
- getDeviceSession(channel, remoteAddress, sentence.substring(3, index));
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null || !sentence.matches("![A-D],.*")) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- String type = sentence.substring(1, 2);
- position.set(Position.KEY_TYPE, type);
-
- if (type.equals("B") || type.equals("D")) {
-
- Parser parser = new Parser(PATTERN_BD, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- decodeFix(position, parser);
- decodeState(position, parser);
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0));
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
-
- return position;
-
- } else if (type.equals("C")) {
-
- Parser parser = new Parser(PATTERN_C, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- decodeFix(position, parser);
- decodeState(position, parser);
-
- return position;
-
- } else if (type.equals("A")) {
-
- Parser parser = new Parser(PATTERN_A, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- decodeFix(position, parser);
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
deleted file mode 100644
index 486f406a5..000000000
--- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 java.util.TimeZone;
-
-import org.traccar.StringProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
-
- @Override
- public String formatValue(String key, Object value) {
-
- if (key.equals(Command.KEY_ENABLE)) {
- return (Boolean) value ? "1" : "0";
- } else if (key.equals(Command.KEY_TIMEZONE)) {
- return String.format("%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000);
- } else if (key.equals(Command.KEY_INDEX)) {
- switch (((Number) value).intValue()) {
- case 0:
- return "A";
- case 1:
- return "B";
- case 2:
- return "C";
- default:
- return null;
- }
- }
-
- return null;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- initDevicePassword(command, "123456");
-
- switch (command.getType()) {
- case Command.TYPE_SET_TIMEZONE:
- return formatCommand(command, "{%s}L{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_TIMEZONE);
- case Command.TYPE_VOICE_MONITORING:
- return formatCommand(command, "{%s}P{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
- case Command.TYPE_ALARM_SPEED:
- return formatCommand(command, "{%s}J1{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA);
- case Command.TYPE_ALARM_GEOFENCE:
- return formatCommand(command, "{%s}R1{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_RADIUS);
- case Command.TYPE_ALARM_VIBRATION:
- return formatCommand(command, "{%s}W1,{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA);
- case Command.TYPE_SET_AGPS:
- return formatCommand(command, "{%s}AGPS{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
- case Command.TYPE_ALARM_FALL:
- return formatCommand(command, "{%s}F{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
- case Command.TYPE_MODE_POWER_SAVING:
- return formatCommand(command, "{%s}SP{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
- case Command.TYPE_MODE_DEEP_SLEEP:
- return formatCommand(command, "{%s}DS{%s}", this, Command.KEY_DEVICE_PASSWORD, Command.KEY_ENABLE);
- case Command.TYPE_SOS_NUMBER:
- return formatCommand(command, "{%s}{%s}1,{%s}", this,
- Command.KEY_DEVICE_PASSWORD, Command.KEY_INDEX, Command.KEY_PHONE);
- case Command.TYPE_SET_INDICATOR:
- return formatCommand(command, "{%s}LED{%s}", Command.KEY_DEVICE_PASSWORD, Command.KEY_DATA);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/Mta6Protocol.java b/src/org/traccar/protocol/Mta6Protocol.java
deleted file mode 100644
index 65a48808d..000000000
--- a/src/org/traccar/protocol/Mta6Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.Context;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class Mta6Protocol extends BaseProtocol {
-
- public Mta6Protocol() {
- super("mta6");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("objectDecoder", new Mta6ProtocolDecoder(
- Mta6Protocol.this, !Context.getConfig().getBoolean(getName() + ".can")));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
deleted file mode 100644
index 0fda94eef..000000000
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.Protocol;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
-
- private final boolean simple;
-
- public Mta6ProtocolDecoder(Protocol protocol, boolean simple) {
- super(protocol);
- this.simple = simple;
- }
-
- private void sendContinue(Channel channel) {
- HttpResponse response = new DefaultHttpResponse(
- HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
- channel.write(response);
- }
-
- private void sendResponse(Channel channel, short packetId, short packetCount) {
- HttpResponse response = new DefaultHttpResponse(
- HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
-
- ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
- ChannelBuffer end = ChannelBuffers.directBuffer(3);
- end.writeByte(packetId);
- end.writeByte(packetCount);
- end.writeByte(0);
-
- response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
- channel.write(response);
- }
-
- private static class FloatReader {
-
- private int previousFloat;
-
- public float readFloat(ChannelBuffer buf) {
- switch (buf.getUnsignedByte(buf.readerIndex()) >> 6) {
- case 0:
- previousFloat = buf.readInt() << 2;
- break;
- case 1:
- previousFloat = (previousFloat & 0xffffff00) + ((buf.readUnsignedByte() & 0x3f) << 2);
- break;
- case 2:
- previousFloat = (previousFloat & 0xffff0000) + ((buf.readUnsignedShort() & 0x3fff) << 2);
- break;
- case 3:
- previousFloat = (previousFloat & 0xff000000) + ((buf.readUnsignedMedium() & 0x3fffff) << 2);
- break;
- default:
- Log.warning(new IllegalArgumentException());
- break;
- }
- return Float.intBitsToFloat(previousFloat);
- }
-
- }
-
- private static class TimeReader extends FloatReader {
-
- private long weekNumber;
-
- public Date readTime(ChannelBuffer buf) {
- long weekTime = (long) (readFloat(buf) * 1000);
- if (weekNumber == 0) {
- weekNumber = buf.readUnsignedShort();
- }
-
- DateBuilder dateBuilder = new DateBuilder().setDate(1980, 1, 6);
- dateBuilder.addMillis(weekNumber * 7 * 24 * 60 * 60 * 1000 + weekTime);
-
- return dateBuilder.getDate();
- }
-
- }
-
- private List<Position> parseFormatA(DeviceSession deviceSession, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<>();
-
- FloatReader latitudeReader = new FloatReader();
- FloatReader longitudeReader = new FloatReader();
- TimeReader timeReader = new TimeReader();
-
- try {
- while (buf.readable()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- short flags = buf.readUnsignedByte();
-
- short event = buf.readUnsignedByte();
- if (BitUtil.check(event, 7)) {
- if (BitUtil.check(event, 6)) {
- buf.skipBytes(8);
- } else {
- while (BitUtil.check(event, 7)) {
- event = buf.readUnsignedByte();
- }
- }
- }
-
- position.setLatitude(latitudeReader.readFloat(buf) / Math.PI * 180);
- position.setLongitude(longitudeReader.readFloat(buf) / Math.PI * 180);
- position.setTime(timeReader.readTime(buf));
-
- if (BitUtil.check(flags, 0)) {
- buf.readUnsignedByte(); // status
- }
-
- if (BitUtil.check(flags, 1)) {
- position.setAltitude(buf.readUnsignedShort());
- }
-
- if (BitUtil.check(flags, 2)) {
- position.setSpeed(buf.readUnsignedShort() & 0x03ff);
- position.setCourse(buf.readUnsignedByte());
- }
-
- if (BitUtil.check(flags, 3)) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedShort() * 1000);
- }
-
- if (BitUtil.check(flags, 4)) {
- position.set(Position.KEY_FUEL_CONSUMPTION + "Accumulator1", buf.readUnsignedInt());
- position.set(Position.KEY_FUEL_CONSUMPTION + "Accumulator2", buf.readUnsignedInt());
- position.set("hours1", buf.readUnsignedShort());
- position.set("hours2", buf.readUnsignedShort());
- }
-
- if (BitUtil.check(flags, 5)) {
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() & 0x03ff);
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort() & 0x03ff);
- position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort() & 0x03ff);
- position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort() & 0x03ff);
- }
-
- if (BitUtil.check(flags, 6)) {
- position.set(Position.PREFIX_TEMP + 1, buf.readByte());
- buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
- position.set(Position.KEY_INPUT, buf.readUnsignedShort() & 0x0fff);
- buf.readUnsignedShort(); // old sensor state (& 0x0fff)
- }
-
- if (BitUtil.check(flags, 7)) {
- position.set(Position.KEY_BATTERY, buf.getUnsignedByte(buf.readerIndex()) >> 2);
- position.set(Position.KEY_POWER, buf.readUnsignedShort() & 0x03ff);
- position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
-
- position.set(Position.KEY_RSSI, (buf.getUnsignedByte(buf.readerIndex()) >> 4) & 0x07);
-
- int satellites = buf.readUnsignedByte() & 0x0f;
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
- }
- positions.add(position);
- }
- } catch (IndexOutOfBoundsException error) {
- Log.warning(error);
- }
-
- return positions;
- }
-
- private Position parseFormatA1(DeviceSession deviceSession, ChannelBuffer buf) {
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- short flags = buf.readUnsignedByte();
-
- // Skip events
- short event = buf.readUnsignedByte();
- if (BitUtil.check(event, 7)) {
- if (BitUtil.check(event, 6)) {
- buf.skipBytes(8);
- } else {
- while (BitUtil.check(event, 7)) {
- event = buf.readUnsignedByte();
- }
- }
- }
-
- position.setLatitude(new FloatReader().readFloat(buf) / Math.PI * 180);
- position.setLongitude(new FloatReader().readFloat(buf) / Math.PI * 180);
- position.setTime(new TimeReader().readTime(buf));
-
- position.set(Position.KEY_STATUS, buf.readUnsignedByte());
-
- if (BitUtil.check(flags, 0)) {
- position.setAltitude(buf.readUnsignedShort());
- position.setSpeed(buf.readUnsignedByte());
- position.setCourse(buf.readByte());
- position.set(Position.KEY_ODOMETER, new FloatReader().readFloat(buf));
- }
-
- if (BitUtil.check(flags, 1)) {
- position.set(Position.KEY_FUEL_CONSUMPTION, new FloatReader().readFloat(buf));
- position.set(Position.KEY_HOURS, new FloatReader().readFloat(buf));
- position.set("tank", buf.readUnsignedByte() * 0.4);
- }
-
- if (BitUtil.check(flags, 2)) {
- position.set("engine", buf.readUnsignedShort() * 0.125);
- position.set("pedals", buf.readUnsignedByte());
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() - 40);
- position.set(Position.KEY_ODOMETER_SERVICE, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(flags, 3)) {
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 3, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 4, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(flags, 4)) {
- position.set(Position.PREFIX_TEMP + 1, buf.readByte());
- buf.getUnsignedByte(buf.readerIndex()); // control (>> 4)
- position.set(Position.KEY_INPUT, buf.readUnsignedShort() & 0x0fff);
- buf.readUnsignedShort(); // old sensor state (& 0x0fff)
- }
-
- if (BitUtil.check(flags, 5)) {
- position.set(Position.KEY_BATTERY, buf.getUnsignedByte(buf.readerIndex()) >> 2);
- position.set(Position.KEY_POWER, buf.readUnsignedShort() & 0x03ff);
- position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
-
- position.set(Position.KEY_RSSI, buf.getUnsignedByte(buf.readerIndex()) >> 5);
-
- int satellites = buf.readUnsignedByte() & 0x1f;
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
- }
-
- // other data
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- ChannelBuffer buf = request.getContent();
-
- buf.skipBytes("id=".length());
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
- String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
- if (deviceSession == null) {
- return null;
- }
- buf.skipBytes(uniqueId.length());
- buf.skipBytes("&bin=".length());
-
- short packetId = buf.readUnsignedByte();
- short offset = buf.readUnsignedByte(); // dataOffset
- short packetCount = buf.readUnsignedByte();
- buf.readUnsignedByte(); // reserved
- buf.readUnsignedByte(); // timezone
- buf.skipBytes(offset - 5);
-
- if (channel != null) {
- sendContinue(channel);
- sendResponse(channel, packetId, packetCount);
- }
-
- if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
- if (simple) {
- return parseFormatA1(deviceSession, buf);
- } else {
- return parseFormatA(deviceSession, buf);
- }
- } //else if (0x34 0x38 0x4F 0x59)
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MtxProtocol.java b/src/org/traccar/protocol/MtxProtocol.java
deleted file mode 100644
index 58b2361cd..000000000
--- a/src/org/traccar/protocol/MtxProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 MtxProtocol extends BaseProtocol {
-
- public MtxProtocol() {
- super("mtx");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new MtxProtocolDecoder(MtxProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java
deleted file mode 100644
index d7b572670..000000000
--- a/src/org/traccar/protocol/MtxProtocolDecoder.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class MtxProtocolDecoder extends BaseProtocolDecoder {
-
- public MtxProtocolDecoder(MtxProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("#MTX,")
- .number("(d+),") // imei
- .number("(dddd)(dd)(dd),") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(d+.?d*),") // speed
- .number("(d+),") // course
- .number("(d+.?d*),") // odometer
- .groupBegin()
- .number("d+")
- .or()
- .text("X")
- .groupEnd()
- .text(",")
- .expression("(?:[01]|X),")
- .expression("([01]+),") // input
- .expression("([01]+),") // output
- .number("(d+),") // adc1
- .number("(d+)") // adc2
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- if (channel != null) {
- channel.write("#ACK");
- }
-
- Parser parser = new Parser(PATTERN, (String) msg);
- 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.setTime(parser.nextDateTime());
-
- position.setValid(true);
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/MxtFrameDecoder.java b/src/org/traccar/protocol/MxtFrameDecoder.java
deleted file mode 100644
index b2cd6de93..000000000
--- a/src/org/traccar/protocol/MxtFrameDecoder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.nio.ByteOrder;
-
-public class MxtFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 2) {
- return null;
- }
-
- int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0x04);
- if (index != -1) {
- ChannelBuffer result = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, index + 1 - buf.readerIndex());
-
- while (buf.readerIndex() <= index) {
- int b = buf.readUnsignedByte();
- if (b == 0x10) {
- result.writeByte(buf.readUnsignedByte() - 0x20);
- } else {
- result.writeByte(b);
- }
- }
-
- return result;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/MxtProtocol.java b/src/org/traccar/protocol/MxtProtocol.java
deleted file mode 100644
index 03c1da71e..000000000
--- a/src/org/traccar/protocol/MxtProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class MxtProtocol extends BaseProtocol {
-
- public MxtProtocol() {
- super("mxt");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new MxtFrameDecoder());
- pipeline.addLast("objectDecoder", new MxtProtocolDecoder(MxtProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java
deleted file mode 100644
index 6d82e4a4b..000000000
--- a/src/org/traccar/protocol/MxtProtocolDecoder.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-
-public class MxtProtocolDecoder extends BaseProtocolDecoder {
-
- public MxtProtocolDecoder(MxtProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_ACK = 0x02;
- public static final int MSG_NACK = 0x03;
- public static final int MSG_POSITION = 0x31;
-
- private static void sendResponse(Channel channel, int device, long id, int crc) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
- response.writeByte(device);
- response.writeByte(MSG_ACK);
- response.writeInt((int) id);
- response.writeShort(crc);
- response.writeShort(Checksum.crc16(
- Checksum.CRC16_XMODEM, response.toByteBuffer()));
-
- ChannelBuffer encoded = ChannelBuffers.dynamicBuffer();
- encoded.writeByte(0x01); // header
- while (response.readable()) {
- int b = response.readByte();
- if (b == 0x01 || b == 0x04 || b == 0x10 || b == 0x11 || b == 0x13) {
- encoded.writeByte(0x10);
- b += 0x20;
- }
- encoded.writeByte(b);
- }
- encoded.writeByte(0x04); // ending
- channel.write(encoded);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // start
- int device = buf.readUnsignedByte(); // device descriptor
- int type = buf.readUnsignedByte();
-
- long id = buf.readUnsignedInt();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
- if (deviceSession == null) {
- return null;
- }
-
- if (type == MSG_POSITION) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedByte(); // protocol
- int infoGroups = buf.readUnsignedByte();
-
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
-
- DateBuilder dateBuilder = new DateBuilder().setDate(2000, 1, 1);
-
- long date = buf.readUnsignedInt();
-
- long days = BitUtil.from(date, 6 + 6 + 5);
- long hours = BitUtil.between(date, 6 + 6, 6 + 6 + 5);
- long minutes = BitUtil.between(date, 6, 6 + 6);
- long seconds = BitUtil.to(date, 6);
-
- dateBuilder.addMillis((((days * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000);
-
- position.setTime(dateBuilder.getDate());
-
- position.setValid(true);
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
-
- long flags = buf.readUnsignedInt();
- position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
- if (BitUtil.check(flags, 1)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- position.set(Position.KEY_INPUT, BitUtil.between(flags, 2, 7));
- position.set(Position.KEY_OUTPUT, BitUtil.between(flags, 7, 10));
- position.setCourse(BitUtil.between(flags, 10, 13) * 45);
- //position.setValid(BitUtil.check(flags, 15));
- position.set(Position.KEY_CHARGE, BitUtil.check(flags, 20));
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
-
- buf.readUnsignedByte(); // input mask
-
- if (BitUtil.check(infoGroups, 0)) {
- buf.skipBytes(8); // waypoints
- }
-
- if (BitUtil.check(infoGroups, 1)) {
- buf.skipBytes(8); // wireless accessory
- }
-
- if (BitUtil.check(infoGroups, 2)) {
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_HDOP, buf.readUnsignedByte());
- position.setAccuracy(buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- buf.readUnsignedShort(); // time since boot
- position.set(Position.KEY_POWER, buf.readUnsignedByte());
- position.set(Position.PREFIX_TEMP + 1, buf.readByte());
- }
-
- if (BitUtil.check(infoGroups, 3)) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- if (BitUtil.check(infoGroups, 4)) {
- position.set(Position.KEY_HOURS, buf.readUnsignedInt());
- }
-
- if (BitUtil.check(infoGroups, 5)) {
- buf.readUnsignedInt(); // reason
- }
-
- if (BitUtil.check(infoGroups, 6)) {
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(infoGroups, 7)) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedInt()));
- }
-
- buf.readerIndex(buf.writerIndex() - 3);
- sendResponse(channel, device, id, buf.readUnsignedShort());
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NavigilFrameDecoder.java b/src/org/traccar/protocol/NavigilFrameDecoder.java
deleted file mode 100644
index 34eb28941..000000000
--- a/src/org/traccar/protocol/NavigilFrameDecoder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class NavigilFrameDecoder extends FrameDecoder {
-
- private static final int MESSAGE_HEADER = 20;
- private static final long PREAMBLE = 0x2477F5F6;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- if (buf.readableBytes() < MESSAGE_HEADER) {
- return null;
- }
-
- // Check for preamble
- boolean hasPreamble = false;
- if (buf.getUnsignedInt(buf.readerIndex()) == PREAMBLE) {
- hasPreamble = true;
- }
-
- // Check length and return buffer
- int length = buf.getUnsignedShort(buf.readerIndex() + 6);
- if (buf.readableBytes() >= length) {
- if (hasPreamble) {
- buf.readUnsignedInt();
- length -= 4;
- }
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NavigilProtocol.java b/src/org/traccar/protocol/NavigilProtocol.java
deleted file mode 100644
index 6646c6cc6..000000000
--- a/src/org/traccar/protocol/NavigilProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class NavigilProtocol extends BaseProtocol {
-
- public NavigilProtocol() {
- super("navigil");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new NavigilFrameDecoder());
- pipeline.addLast("objectDecoder", new NavigilProtocolDecoder(NavigilProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
deleted file mode 100644
index 360b9c81c..000000000
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * 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.
- * 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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.util.Date;
-
-public class NavigilProtocolDecoder extends BaseProtocolDecoder {
-
- public NavigilProtocolDecoder(NavigilProtocol protocol) {
- super(protocol);
- }
-
- private static final int LEAP_SECONDS_DELTA = 25;
-
- public static final int MSG_ERROR = 2;
- public static final int MSG_INDICATION = 4;
- public static final int MSG_CONN_OPEN = 5;
- public static final int MSG_CONN_CLOSE = 6;
- public static final int MSG_SYSTEM_REPORT = 7;
- public static final int MSG_UNIT_REPORT = 8;
- public static final int MSG_GEOFENCE_ALARM = 10;
- public static final int MSG_INPUT_ALARM = 11;
- public static final int MSG_TG2_REPORT = 12;
- public static final int MSG_POSITION_REPORT = 13;
- public static final int MSG_POSITION_REPORT_2 = 15;
- public static final int MSG_SNAPSHOT4 = 17;
- public static final int MSG_TRACKING_DATA = 18;
- public static final int MSG_MOTION_ALARM = 19;
- public static final int MSG_ACKNOWLEDGEMENT = 255;
-
- private static Date convertTimestamp(long timestamp) {
- return new Date((timestamp - LEAP_SECONDS_DELTA) * 1000);
- }
-
- private int senderSequenceNumber = 1;
-
- private void sendAcknowledgment(Channel channel, int sequenceNumber) {
- ChannelBuffer data = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 4);
- data.writeShort(sequenceNumber);
- data.writeShort(0); // OK
-
- ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 20);
- header.writeByte(1); header.writeByte(0);
- header.writeShort(senderSequenceNumber++);
- header.writeShort(MSG_ACKNOWLEDGEMENT);
- header.writeShort(header.capacity() + data.capacity());
- header.writeShort(0);
- header.writeShort(Checksum.crc16(Checksum.CRC16_CCITT_FALSE, data.toByteBuffer()));
- header.writeInt(0);
- header.writeInt((int) (System.currentTimeMillis() / 1000) + LEAP_SECONDS_DELTA);
-
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(header, data));
- }
- }
-
- private Position parseUnitReport(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.setValid(true);
- position.set(Position.KEY_INDEX, sequenceNumber);
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedShort(); // report trigger
- position.set(Position.KEY_FLAGS, buf.readUnsignedShort());
-
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readUnsignedShort());
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedShort());
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShort());
- position.set("gpsAntennaState", buf.readUnsignedShort());
-
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
-
- position.set(Position.KEY_CHARGE, buf.readUnsignedShort());
-
- position.setTime(convertTimestamp(buf.readUnsignedInt()));
-
- return position;
- }
-
- private Position parseTg2Report(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.setValid(true);
- position.set(Position.KEY_INDEX, sequenceNumber);
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedShort(); // report trigger
- buf.readUnsignedByte(); // reserved
- buf.readUnsignedByte(); // assisted GPS age
-
- position.setTime(convertTimestamp(buf.readUnsignedInt()));
-
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readUnsignedShort());
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
-
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- position.set("maximumSpeed", buf.readUnsignedShort());
- position.set("minimumSpeed", buf.readUnsignedShort());
-
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort()); // VSAUT1 voltage
- position.set(Position.PREFIX_IO + 2, buf.readUnsignedShort()); // VSAUT2 voltage
- position.set(Position.PREFIX_IO + 3, buf.readUnsignedShort()); // solar voltage
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
-
- return position;
- }
-
- private Position parsePositionReport(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, sequenceNumber);
- position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(convertTimestamp(timestamp));
-
- position.setLatitude(buf.readMedium() * 0.00002);
- position.setLongitude(buf.readMedium() * 0.00002);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedByte() * 2);
-
- short flags = buf.readUnsignedByte();
- position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
-
- buf.readUnsignedByte(); // reserved
-
- return position;
- }
-
- private Position parsePositionReport2(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, sequenceNumber);
- position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(convertTimestamp(timestamp));
-
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
-
- buf.readUnsignedByte(); // report trigger
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
-
- short flags = buf.readUnsignedByte();
- position.setValid((flags & 0x80) == 0x80 && (flags & 0x40) == 0x40);
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- return position;
- }
-
- private Position parseSnapshot4(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, sequenceNumber);
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedByte(); // report trigger
- buf.readUnsignedByte(); // position fix source
- buf.readUnsignedByte(); // GNSS fix quality
- buf.readUnsignedByte(); // GNSS assistance age
-
- long flags = buf.readUnsignedInt();
- position.setValid((flags & 0x0400) == 0x0400);
-
- position.setTime(convertTimestamp(buf.readUnsignedInt()));
-
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
- position.setAltitude(buf.readUnsignedShort());
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
-
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort() * 0.1);
-
- position.set("maximumSpeed", buf.readUnsignedByte());
- position.set("minimumSpeed", buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte()); // supply voltage 1
- position.set(Position.PREFIX_IO + 2, buf.readUnsignedByte()); // supply voltage 2
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
-
- return position;
- }
-
- private Position parseTrackingData(
- DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_INDEX, sequenceNumber);
- position.setDeviceId(deviceSession.getDeviceId());
- position.setTime(convertTimestamp(timestamp));
-
- buf.readUnsignedByte(); // tracking mode
-
- short flags = buf.readUnsignedByte();
- position.setValid((flags & 0x01) == 0x01);
-
- buf.readUnsignedShort(); // duration
-
- position.setLatitude(buf.readInt() * 0.0000001);
- position.setLongitude(buf.readInt() * 0.0000001);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedByte() * 2.0);
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // protocol version
- buf.readUnsignedByte(); // version id
- int sequenceNumber = buf.readUnsignedShort();
- int messageId = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
- int flags = buf.readUnsignedShort();
- buf.readUnsignedShort(); // checksum
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
- if (deviceSession == null) {
- return null;
- }
-
- long timestamp = buf.readUnsignedInt();
-
- if ((flags & 0x1) == 0x0) {
- sendAcknowledgment(channel, sequenceNumber);
- }
-
- switch (messageId) {
- case MSG_UNIT_REPORT:
- return parseUnitReport(deviceSession, buf, sequenceNumber);
- case MSG_TG2_REPORT:
- return parseTg2Report(deviceSession, buf, sequenceNumber);
- case MSG_POSITION_REPORT:
- return parsePositionReport(deviceSession, buf, sequenceNumber, timestamp);
- case MSG_POSITION_REPORT_2:
- return parsePositionReport2(deviceSession, buf, sequenceNumber, timestamp);
- case MSG_SNAPSHOT4:
- return parseSnapshot4(deviceSession, buf, sequenceNumber);
- case MSG_TRACKING_DATA:
- return parseTrackingData(deviceSession, buf, sequenceNumber, timestamp);
- default:
- Log.warning(new UnsupportedOperationException(String.valueOf(messageId)));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NavisProtocol.java b/src/org/traccar/protocol/NavisProtocol.java
deleted file mode 100644
index 771c9d61d..000000000
--- a/src/org/traccar/protocol/NavisProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class NavisProtocol extends BaseProtocol {
-
- public NavisProtocol() {
- super("navis");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0));
- pipeline.addLast("objectDecoder", new NavisProtocolDecoder(NavisProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
deleted file mode 100644
index 8d4e367ab..000000000
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-
-public class NavisProtocolDecoder extends BaseProtocolDecoder {
-
- private String prefix;
- private long deviceUniqueId, serverId;
-
- public NavisProtocolDecoder(NavisProtocol protocol) {
- super(protocol);
- }
-
- public static final int F10 = 0x01;
- public static final int F20 = 0x02;
- public static final int F30 = 0x03;
- public static final int F40 = 0x04;
- public static final int F50 = 0x05;
- public static final int F51 = 0x15;
- public static final int F52 = 0x25;
-
- private static boolean isFormat(int type, int... types) {
- for (int i : types) {
- if (type == i) {
- return true;
- }
- }
- return false;
- }
-
- private static final class ParseResult {
- private final long id;
- private final Position position;
-
- private ParseResult(long id, Position position) {
- this.id = id;
- this.position = position;
- }
-
- public long getId() {
- return id;
- }
-
- public Position getPosition() {
- return position;
- }
- }
-
- private ParseResult parsePosition(DeviceSession deviceSession, ChannelBuffer buf) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.setDeviceId(deviceSession.getDeviceId());
-
- int format;
- if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
- format = buf.readUnsignedShort();
- } else {
- format = buf.readUnsignedByte();
- }
- position.set("format", format);
-
- long index = buf.readUnsignedInt();
- position.set(Position.KEY_INDEX, index);
-
- position.set(Position.KEY_EVENT, buf.readUnsignedShort());
-
- buf.skipBytes(6); // event time
-
- short armedStatus = buf.readUnsignedByte();
- position.set(Position.KEY_ARMED, armedStatus & 0x7F);
- if (BitUtil.check(armedStatus, 7)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- position.set(Position.KEY_STATUS, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
-
- if (isFormat(format, F10, F20, F30)) {
- position.set(Position.KEY_OUTPUT, buf.readUnsignedShort());
- } else if (isFormat(format, F40, F50, F51, F52)) {
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
- }
-
- if (isFormat(format, F10, F20, F30, F40)) {
- position.set(Position.KEY_INPUT, buf.readUnsignedShort());
- } else if (isFormat(format, F50, F51, F52)) {
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- }
-
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
-
- if (isFormat(format, F10, F20, F30)) {
- position.set(Position.PREFIX_TEMP + 1, buf.readShort());
- }
-
- if (isFormat(format, F10, F20, F50, F52)) {
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
- }
-
- // Impulse counters
- if (isFormat(format, F20, F50, F51, F52)) {
- buf.readUnsignedInt();
- buf.readUnsignedInt();
- }
-
- if (isFormat(format, F20, F50, F51, F52)) {
- int locationStatus = buf.readUnsignedByte();
- position.setValid(BitUtil.check(locationStatus, 1));
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(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(UnitsConverter.knotsFromKph(buf.readFloat()));
- position.setCourse(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readFloat() * 1000);
- position.set(Position.KEY_DISTANCE, buf.readFloat());
-
- // Segment times
- buf.readUnsignedShort();
- buf.readUnsignedShort();
- }
-
- // Other
- if (isFormat(format, F51, F52)) {
- buf.readUnsignedShort();
- buf.readByte();
- buf.readUnsignedShort();
- buf.readUnsignedShort();
- buf.readByte();
- buf.readUnsignedShort();
- buf.readUnsignedShort();
- buf.readByte();
- buf.readUnsignedShort();
- }
-
- // Four temperature sensors
- if (isFormat(format, F40, F52)) {
- buf.readByte();
- buf.readByte();
- buf.readByte();
- buf.readByte();
- }
-
- return new ParseResult(index, position);
- }
-
- private Object processSingle(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
- ParseResult result = parsePosition(deviceSession, buf);
-
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
- response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<T", StandardCharsets.US_ASCII));
- response.writeInt((int) result.getId());
- sendReply(channel, response);
-
- if (result.getPosition().getFixTime() == null) {
- return null;
- }
-
- return result.getPosition();
- }
-
- private Object processArray(DeviceSession deviceSession, Channel channel, ChannelBuffer buf) {
- List<Position> positions = new LinkedList<>();
- int count = buf.readUnsignedByte();
-
- for (int i = 0; i < count; i++) {
- Position position = parsePosition(deviceSession, buf).getPosition();
- if (position.getFixTime() != null) {
- positions.add(position);
- }
- }
-
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 8);
- response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<A", StandardCharsets.US_ASCII));
- response.writeByte(count);
- sendReply(channel, response);
-
- if (positions.isEmpty()) {
- return null;
- }
-
- return positions;
- }
-
- private Object processHandshake(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- buf.readByte(); // semicolon symbol
- if (getDeviceSession(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII)) != null) {
- sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", StandardCharsets.US_ASCII));
- }
- return null;
- }
-
- private static short checksum(ChannelBuffer buf) {
- short sum = 0;
- for (int i = 0; i < buf.readableBytes(); i++) {
- sum ^= buf.getUnsignedByte(i);
- }
- return sum;
- }
-
- private void sendReply(Channel channel, ChannelBuffer data) {
- ChannelBuffer header = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 16);
- header.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, prefix, StandardCharsets.US_ASCII));
- header.writeInt((int) deviceUniqueId);
- header.writeInt((int) serverId);
- header.writeShort(data.readableBytes());
- header.writeByte(checksum(data));
- header.writeByte(checksum(header));
-
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(header, data));
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- prefix = buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII);
- buf.skipBytes(prefix.length()); // prefix @NTC by default
- serverId = buf.readUnsignedInt();
- deviceUniqueId = buf.readUnsignedInt();
- int length = buf.readUnsignedShort();
- buf.skipBytes(2); // header and data XOR checksum
-
- if (length == 0) {
- return null; // keep alive message
- }
-
- String type = buf.toString(buf.readerIndex(), 3, StandardCharsets.US_ASCII);
- buf.skipBytes(type.length());
-
- if (type.equals("*>S")) {
- return processHandshake(channel, remoteAddress, buf);
- } else {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession != null) {
- if (type.equals("*>T")) {
- return processSingle(deviceSession, channel, buf);
- } else if (type.equals("*>A")) {
- return processArray(deviceSession, channel, buf);
- }
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NoranProtocol.java b/src/org/traccar/protocol/NoranProtocol.java
deleted file mode 100644
index 7d3dc4852..000000000
--- a/src/org/traccar/protocol/NoranProtocol.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.
- * 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 org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class NoranProtocol extends BaseProtocol {
-
- public NoranProtocol() {
- super("noran");
- setSupportedDataCommands(
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_POSITION_PERIODIC,
- Command.TYPE_POSITION_STOP,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectEncoder", new NoranProtocolEncoder());
- pipeline.addLast("objectDecoder", new NoranProtocolDecoder(NoranProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
deleted file mode 100644
index 990f50484..000000000
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-
-public class NoranProtocolDecoder extends BaseProtocolDecoder {
-
- public NoranProtocolDecoder(NoranProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_UPLOAD_POSITION = 0x0008;
- public static final int MSG_UPLOAD_POSITION_NEW = 0x0032;
- public static final int MSG_CONTROL = 0x0002;
- public static final int MSG_CONTROL_RESPONSE = 0x8009;
- public static final int MSG_ALARM = 0x0003;
- public static final int MSG_SHAKE_HAND = 0x0000;
- public static final int MSG_SHAKE_HAND_RESPONSE = 0x8000;
- public static final int MSG_IMAGE_SIZE = 0x0200;
- public static final int MSG_IMAGE_PACKET = 0x0201;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedShort(); // length
- int type = buf.readUnsignedShort();
-
- if (type == MSG_SHAKE_HAND && channel != null) {
-
- ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 13);
- response.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
- response.writeByte(0);
- response.writeShort(response.capacity());
- response.writeShort(MSG_SHAKE_HAND_RESPONSE);
- response.writeByte(1); // status
- response.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));
-
- channel.write(response, remoteAddress);
-
- } else if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW
- || type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) {
-
- boolean newFormat = false;
- if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48
- || type == MSG_ALARM && buf.readableBytes() == 48
- || type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57) {
- newFormat = true;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- if (type == MSG_CONTROL_RESPONSE) {
- buf.readUnsignedInt(); // GIS ip
- buf.readUnsignedInt(); // GIS port
- }
-
- position.setValid(BitUtil.check(buf.readUnsignedByte(), 0));
-
- short alarm = buf.readUnsignedByte();
- switch (alarm) {
- case 1:
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case 2:
- position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
- break;
- case 3:
- position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT);
- break;
- case 9:
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
- break;
- default:
- break;
- }
-
- if (newFormat) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedInt()));
- position.setCourse(buf.readFloat());
- } else {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedShort());
- }
- position.setLongitude(buf.readFloat());
- position.setLatitude(buf.readFloat());
-
- if (!newFormat) {
- long timeValue = buf.readUnsignedInt();
- DateBuilder dateBuilder = new DateBuilder()
- .setYear((int) BitUtil.from(timeValue, 26))
- .setMonth((int) BitUtil.between(timeValue, 22, 26))
- .setDay((int) BitUtil.between(timeValue, 17, 22))
- .setHour((int) BitUtil.between(timeValue, 12, 17))
- .setMinute((int) BitUtil.between(timeValue, 6, 12))
- .setSecond((int) BitUtil.to(timeValue, 6));
- position.setTime(dateBuilder.getDate());
- }
-
- ChannelBuffer rawId;
- if (newFormat) {
- rawId = buf.readBytes(12);
- } else {
- rawId = buf.readBytes(11);
- }
- String id = rawId.toString(StandardCharsets.US_ASCII).replaceAll("[^\\p{Print}]", "");
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (newFormat) {
- DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
- position.setTime(dateFormat.parse(buf.readBytes(17).toString(StandardCharsets.US_ASCII)));
- buf.readByte();
- }
-
- if (!newFormat) {
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
- position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
- } else if (type == MSG_UPLOAD_POSITION_NEW) {
- position.set(Position.PREFIX_TEMP + 1, buf.readShort());
- position.set(Position.KEY_ODOMETER, buf.readFloat());
- }
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NoranProtocolEncoder.java b/src/org/traccar/protocol/NoranProtocolEncoder.java
deleted file mode 100644
index 25b510a73..000000000
--- a/src/org/traccar/protocol/NoranProtocolEncoder.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.ByteOrder;
-import java.nio.charset.StandardCharsets;
-
-public class NoranProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeContent(String content) {
-
- ChannelBuffer buf = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 12 + 56);
-
- buf.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", StandardCharsets.US_ASCII));
- buf.writeByte(0);
- buf.writeShort(buf.capacity());
- buf.writeShort(NoranProtocolDecoder.MSG_CONTROL);
- buf.writeInt(0); // gis ip
- buf.writeShort(0); // gis port
- buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
- buf.writerIndex(buf.writerIndex() + 50 - content.length());
- buf.writeBytes(
- ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", StandardCharsets.US_ASCII));
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_POSITION_SINGLE:
- return encodeContent("*KW,000,000,000000#");
- case Command.TYPE_POSITION_PERIODIC:
- int interval = command.getInteger(Command.KEY_FREQUENCY);
- return encodeContent("*KW,000,002,000000," + interval + "#");
- case Command.TYPE_POSITION_STOP:
- return encodeContent("*KW,000,002,000000,0#");
- case Command.TYPE_ENGINE_STOP:
- return encodeContent("*KW,000,007,000000,0#");
- case Command.TYPE_ENGINE_RESUME:
- return encodeContent("*KW,000,007,000000,1#");
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NvsFrameDecoder.java b/src/org/traccar/protocol/NvsFrameDecoder.java
deleted file mode 100644
index 598bb1e4c..000000000
--- a/src/org/traccar/protocol/NvsFrameDecoder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class NvsFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 4 + 2) {
- return null;
- }
-
- int length;
- if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
- length = 2 + buf.getUnsignedShort(buf.readerIndex());
- } else {
- length = 4 + 2 + buf.getUnsignedShort(buf.readerIndex() + 4) + 2;
- }
-
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/NvsProtocol.java b/src/org/traccar/protocol/NvsProtocol.java
deleted file mode 100644
index fdcb2bbcf..000000000
--- a/src/org/traccar/protocol/NvsProtocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class NvsProtocol extends BaseProtocol {
-
- public NvsProtocol() {
- super("nvs");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new NvsFrameDecoder());
- pipeline.addLast("objectDecoder", new NvsProtocolDecoder(NvsProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/NvsProtocolDecoder.java b/src/org/traccar/protocol/NvsProtocolDecoder.java
deleted file mode 100644
index 0e82fae69..000000000
--- a/src/org/traccar/protocol/NvsProtocolDecoder.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class NvsProtocolDecoder extends BaseProtocolDecoder {
-
- public NvsProtocolDecoder(NvsProtocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, String response) {
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(response, StandardCharsets.US_ASCII));
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
-
- buf.readUnsignedShort(); // length
-
- String imei = buf.toString(buf.readerIndex(), 15, StandardCharsets.US_ASCII);
-
- if (getDeviceSession(channel, remoteAddress, imei) != null) {
- sendResponse(channel, "OK");
- } else {
- sendResponse(channel, "NO01");
- }
-
- } else {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- buf.skipBytes(4); // marker
- buf.readUnsignedShort(); // length
- buf.readLong(); // imei
- buf.readUnsignedByte(); // codec
- int count = buf.readUnsignedByte();
-
- for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- position.set("reason", buf.readUnsignedByte());
-
- position.setLongitude(buf.readInt() / 10000000.0);
- position.setLatitude(buf.readInt() / 10000000.0);
- position.setAltitude(buf.readShort());
- position.setCourse(buf.readUnsignedShort());
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setValid(buf.readUnsignedByte() != 0);
-
- buf.readUnsignedByte(); // used systems
-
- buf.readUnsignedByte(); // cause element id
-
- // Read 1 byte data
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), 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());
- }
-
- // Read 4 byte data
- cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), 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());
- }
-
- positions.add(position);
- }
-
- return positions;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/ObdDongleProtocol.java b/src/org/traccar/protocol/ObdDongleProtocol.java
deleted file mode 100644
index 6547a31ab..000000000
--- a/src/org/traccar/protocol/ObdDongleProtocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class ObdDongleProtocol extends BaseProtocol {
-
- public ObdDongleProtocol() {
- super("obddongle");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1099, 20, 2, 3, 0));
- pipeline.addLast("objectDecoder", new ObdDongleProtocolDecoder(ObdDongleProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
deleted file mode 100644
index e5ae5e93f..000000000
--- a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-public class ObdDongleProtocolDecoder extends BaseProtocolDecoder {
-
- public ObdDongleProtocolDecoder(ObdDongleProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_TYPE_CONNECT = 0x01;
- public static final int MSG_TYPE_CONNACK = 0x02;
- public static final int MSG_TYPE_PUBLISH = 0x03;
- public static final int MSG_TYPE_PUBACK = 0x04;
- public static final int MSG_TYPE_PINGREQ = 0x0C;
- public static final int MSG_TYPE_PINGRESP = 0x0D;
- public static final int MSG_TYPE_DISCONNECT = 0x0E;
-
- private static void sendResponse(Channel channel, int type, int index, String imei, ChannelBuffer content) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeShort(0x5555); // header
- response.writeShort(index);
- response.writeBytes(imei.getBytes(StandardCharsets.US_ASCII));
- response.writeByte(type);
- response.writeShort(content.readableBytes());
- response.writeBytes(content);
- response.writeByte(0); // checksum
- response.writeShort(0xAAAA);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- int index = buf.readUnsignedShort();
-
- String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- int type = buf.readUnsignedByte();
-
- buf.readUnsignedShort(); // data length
-
- if (type == MSG_TYPE_CONNECT) {
-
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(1);
- response.writeShort(0);
- response.writeInt(0);
- sendResponse(channel, MSG_TYPE_CONNACK, index, imei, response);
-
- } else if (type == MSG_TYPE_PUBLISH) {
-
- int typeMajor = buf.readUnsignedByte();
- int typeMinor = buf.readUnsignedByte();
-
- buf.readUnsignedByte(); // event id
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- int flags = buf.readUnsignedByte();
-
- position.setValid(!BitUtil.check(flags, 6));
-
- position.set(Position.KEY_SATELLITES, BitUtil.to(flags, 4));
-
- double longitude = ((BitUtil.to(buf.readUnsignedShort(), 1) << 24) + buf.readUnsignedMedium()) * 0.00001;
- position.setLongitude(BitUtil.check(flags, 5) ? longitude : -longitude);
-
- double latitude = buf.readUnsignedMedium() * 0.00001;
- position.setLatitude(BitUtil.check(flags, 4) ? latitude : -latitude);
-
- int speedCourse = buf.readUnsignedMedium();
- position.setSpeed(UnitsConverter.knotsFromMph(BitUtil.from(speedCourse, 10) * 0.1));
- position.setCourse(BitUtil.to(speedCourse, 10));
-
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(typeMajor);
- response.writeByte(typeMinor);
- sendResponse(channel, MSG_TYPE_PUBACK, index, imei, response);
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/OigoProtocol.java b/src/org/traccar/protocol/OigoProtocol.java
deleted file mode 100644
index 4b6ad0dd0..000000000
--- a/src/org/traccar/protocol/OigoProtocol.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 OigoProtocol extends BaseProtocol {
-
- public OigoProtocol() {
- super("oigo");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new OigoProtocolDecoder(OigoProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java
deleted file mode 100644
index 54360c932..000000000
--- a/src/org/traccar/protocol/OigoProtocolDecoder.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class OigoProtocolDecoder extends BaseProtocolDecoder {
-
- public OigoProtocolDecoder(OigoProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_AR_LOCATION = 0x00;
- public static final int MSG_AR_REMOTE_START = 0x10;
-
- public static final int MSG_ACKNOWLEDGEMENT = 0xE0;
-
- private Position decodeArMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- buf.skipBytes(1); // header
- buf.readUnsignedShort(); // length
-
- int type = buf.readUnsignedByte();
-
- int tag = buf.readUnsignedByte();
-
- DeviceSession deviceSession;
- switch (BitUtil.to(tag, 3)) {
- case 0:
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- deviceSession = getDeviceSession(channel, remoteAddress, imei);
- break;
- case 1:
- buf.skipBytes(1);
- String meid = buf.readBytes(14).toString(StandardCharsets.US_ASCII);
- deviceSession = getDeviceSession(channel, remoteAddress, meid);
- break;
- default:
- deviceSession = getDeviceSession(channel, remoteAddress);
- break;
- }
-
- if (deviceSession == null || type != MSG_AR_LOCATION) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
-
- int mask = buf.readInt();
-
- if (BitUtil.check(mask, 0)) {
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(mask, 1)) {
- int date = buf.readUnsignedByte();
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(BitUtil.between(date, 4, 8) + 2010, BitUtil.to(date, 4), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
- }
-
- if (BitUtil.check(mask, 2)) {
- buf.skipBytes(5); // device time
- }
-
- if (BitUtil.check(mask, 3)) {
- position.setLatitude(buf.readUnsignedInt() * 0.000001 - 90);
- position.setLongitude(buf.readUnsignedInt() * 0.000001 - 180.0);
- }
-
- if (BitUtil.check(mask, 4)) {
- int status = buf.readUnsignedByte();
- position.setValid(BitUtil.between(status, 4, 8) != 0);
- position.set(Position.KEY_SATELLITES, BitUtil.to(status, 4));
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
- }
-
- if (BitUtil.check(mask, 5)) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- }
-
- if (BitUtil.check(mask, 6)) {
- position.setCourse(buf.readUnsignedShort());
- }
-
- if (BitUtil.check(mask, 7)) {
- position.setAltitude(buf.readShort());
- }
-
- if (BitUtil.check(mask, 8)) {
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- }
-
- if (BitUtil.check(mask, 9)) {
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- }
-
- if (BitUtil.check(mask, 10)) {
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
- }
-
- if (BitUtil.check(mask, 11)) {
- buf.skipBytes(2); // gpio
- }
-
- if (BitUtil.check(mask, 12)) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
- }
-
- if (BitUtil.check(mask, 13)) {
- buf.skipBytes(6); // software version
- }
-
- if (BitUtil.check(mask, 14)) {
- buf.skipBytes(5); // hardware version
- }
-
- if (BitUtil.check(mask, 15)) {
- buf.readUnsignedShort(); // device config
- }
-
- return position;
- }
-
- private double convertCoordinate(long value) {
- boolean negative = value < 0;
- value = Math.abs(value);
- double minutes = (value % 100000) * 0.001;
- value /= 100000;
- double degrees = value + minutes / 60;
- return negative ? -degrees : degrees;
- }
-
- private Position decodeMgMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- buf.readUnsignedByte(); // tag
- int flags = buf.getUnsignedByte(buf.readerIndex());
-
- DeviceSession deviceSession;
- if (BitUtil.check(flags, 6)) {
- buf.readUnsignedByte(); // flags
- deviceSession = getDeviceSession(channel, remoteAddress);
- } else {
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- deviceSession = getDeviceSession(channel, remoteAddress, imei);
- }
-
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.skipBytes(8); // imsi
-
- int date = buf.readUnsignedShort();
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(2010 + BitUtil.from(date, 12), BitUtil.between(date, 8, 12), BitUtil.to(date, 8))
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), 0);
-
- position.setValid(true);
- position.setLatitude(convertCoordinate(buf.readInt()));
- position.setLongitude(convertCoordinate(buf.readInt()));
-
- position.setAltitude(UnitsConverter.metersFromFeet(buf.readShort()));
- position.setCourse(buf.readUnsignedShort());
- position.setSpeed(UnitsConverter.knotsFromMph(buf.readUnsignedByte()));
-
- position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.1);
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedByte());
-
- dateBuilder.setSecond(buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
-
- int index = buf.readUnsignedByte();
-
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, (long) (buf.readUnsignedInt() * 1609.34));
-
- if (channel != null && BitUtil.check(flags, 7)) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(MSG_ACKNOWLEDGEMENT);
- response.writeByte(index);
- response.writeByte(0x00);
- channel.write(response, remoteAddress);
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0x7e) {
- return decodeArMessage(channel, remoteAddress, buf);
- } else {
- return decodeMgMessage(channel, remoteAddress, buf);
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java
deleted file mode 100644
index f7371747a..000000000
--- a/src/org/traccar/protocol/OrionFrameDecoder.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class OrionFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- int length = 6;
-
- if (buf.readableBytes() >= length) {
-
- int type = buf.getUnsignedByte(buf.readerIndex() + 2) & 0x0f;
-
- if (type == OrionProtocolDecoder.MSG_USERLOG && buf.readableBytes() >= length + 5) {
-
- int index = buf.readerIndex() + 3;
- int count = buf.getUnsignedByte(index) & 0x0f;
- index += 5;
- length += 5;
-
- for (int i = 0; i < count; i++) {
- if (buf.readableBytes() < length) {
- return null;
- }
- int logLength = buf.getUnsignedByte(index + 1);
- index += logLength;
- length += logLength;
- }
-
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- } else if (type == OrionProtocolDecoder.MSG_SYSLOG && buf.readableBytes() >= length + 12) {
-
- length += buf.getUnsignedShort(buf.readerIndex() + 8);
- if (buf.readableBytes() >= length) {
- return buf.readBytes(length);
- }
-
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/OrionProtocol.java b/src/org/traccar/protocol/OrionProtocol.java
deleted file mode 100644
index f4bfef985..000000000
--- a/src/org/traccar/protocol/OrionProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class OrionProtocol extends BaseProtocol {
-
- public OrionProtocol() {
- super("orion");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new OrionFrameDecoder());
- pipeline.addLast("objectDecoder", new OrionProtocolDecoder(OrionProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
deleted file mode 100644
index c65924337..000000000
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.
- * 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;
-import java.util.LinkedList;
-import java.util.List;
-
-public class OrionProtocolDecoder extends BaseProtocolDecoder {
-
- public OrionProtocolDecoder(OrionProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_USERLOG = 0;
- public static final int MSG_SYSLOG = 3;
-
- private static void sendResponse(Channel channel, ChannelBuffer buf) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(4);
- response.writeByte('*');
- response.writeShort(buf.getUnsignedShort(buf.writerIndex() - 2));
- response.writeByte(buf.getUnsignedByte(buf.writerIndex() - 3));
- channel.write(response);
- }
- }
-
- private static double convertCoordinate(int raw) {
- int degrees = raw / 1000000;
- double minutes = (raw % 1000000) / 10000.0;
- return degrees + minutes / 60;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- int type = buf.readUnsignedByte() & 0x0f;
-
- if (type == MSG_USERLOG) {
-
- int header = buf.readUnsignedByte();
-
- if ((header & 0x40) != 0) {
- sendResponse(channel, buf);
- }
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- for (int i = 0; i < (header & 0x0f); i++) {
-
- Position position = new Position();
- position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
-
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- buf.readUnsignedByte(); // length
- position.set(Position.KEY_FLAGS, buf.readUnsignedShort());
-
- position.setLatitude(convertCoordinate(buf.readInt()));
- position.setLongitude(convertCoordinate(buf.readInt()));
- position.setAltitude(buf.readShort() / 10.0);
- position.setCourse(buf.readUnsignedShort());
- position.setSpeed(buf.readUnsignedShort() * 0.0539957);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- int satellites = buf.readUnsignedByte();
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
-
- positions.add(position);
- }
-
- return positions;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/OsmAndProtocol.java b/src/org/traccar/protocol/OsmAndProtocol.java
deleted file mode 100644
index 785f4bd75..000000000
--- a/src/org/traccar/protocol/OsmAndProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class OsmAndProtocol extends BaseProtocol {
-
- public OsmAndProtocol() {
- super("osmand");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("objectDecoder", new OsmAndProtocolDecoder(OsmAndProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
deleted file mode 100644
index 15a71c88b..000000000
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpHeaders;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.jboss.netty.handler.codec.http.QueryStringDecoder;
-import org.joda.time.format.ISODateTimeFormat;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-public class OsmAndProtocolDecoder extends BaseProtocolDecoder {
-
- public OsmAndProtocolDecoder(OsmAndProtocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, HttpResponseStatus status) {
- if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
- response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
- Map<String, List<String>> params = decoder.getParameters();
- if (params.isEmpty()) {
- decoder = new QueryStringDecoder(request.getContent().toString(StandardCharsets.US_ASCII), false);
- params = decoder.getParameters();
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setValid(true);
-
- for (Map.Entry<String, List<String>> entry : params.entrySet()) {
- String value = entry.getValue().get(0);
- switch (entry.getKey()) {
- case "id":
- case "deviceid":
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
- if (deviceSession == null) {
- sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
- break;
- case "valid":
- position.setValid(Boolean.parseBoolean(value));
- break;
- case "timestamp":
- try {
- long timestamp = Long.parseLong(value);
- if (timestamp < Integer.MAX_VALUE) {
- timestamp *= 1000;
- }
- position.setTime(new Date(timestamp));
- } catch (NumberFormatException error) {
- if (value.contains("T")) {
- position.setTime(new Date(
- ISODateTimeFormat.dateTimeParser().parseMillis(value)));
- } else {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- position.setTime(dateFormat.parse(value));
- }
- }
- break;
- case "lat":
- position.setLatitude(Double.parseDouble(value));
- break;
- case "lon":
- position.setLongitude(Double.parseDouble(value));
- break;
- case "location":
- String[] location = value.split(",");
- position.setLatitude(Double.parseDouble(location[0]));
- position.setLongitude(Double.parseDouble(location[1]));
- break;
- case "speed":
- position.setSpeed(convertSpeed(Double.parseDouble(value), "kn"));
- break;
- case "bearing":
- case "heading":
- position.setCourse(Double.parseDouble(value));
- break;
- case "altitude":
- position.setAltitude(Double.parseDouble(value));
- break;
- case "accuracy":
- position.setAccuracy(Double.parseDouble(value));
- break;
- case "hdop":
- position.set(Position.KEY_HDOP, Double.parseDouble(value));
- break;
- case "batt":
- position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value));
- break;
- case "driverUniqueId":
- position.set(Position.KEY_DRIVER_UNIQUE_ID, value);
- break;
- default:
- try {
- position.set(entry.getKey(), Double.parseDouble(value));
- } catch (NumberFormatException e) {
- switch (value) {
- case "true":
- position.set(entry.getKey(), true);
- break;
- case "false":
- position.set(entry.getKey(), false);
- break;
- default:
- position.set(entry.getKey(), value);
- break;
- }
- }
- break;
- }
- }
-
- if (position.getFixTime() == null) {
- position.setTime(new Date());
- }
-
- if (position.getDeviceId() != 0) {
- sendResponse(channel, HttpResponseStatus.OK);
- return position;
- } else {
- sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
- return null;
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/OwnTracksProtocol.java b/src/org/traccar/protocol/OwnTracksProtocol.java
deleted file mode 100644
index c4a6ab163..000000000
--- a/src/org/traccar/protocol/OwnTracksProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Jan-Piet Mens (jpmens@gmail.com)
- * Copyright 2017 Anton Tananaev (anton@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.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class OwnTracksProtocol extends BaseProtocol {
-
- public OwnTracksProtocol() {
- super("owntracks");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("objectDecoder", new OwnTracksProtocolDecoder(OwnTracksProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
deleted file mode 100644
index f3284d9e2..000000000
--- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2017 Jan-Piet Mens (jpmens@gmail.com)
- * Copyright 2017 Anton Tananaev (anton@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.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpHeaders;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.model.Position;
-import org.traccar.helper.UnitsConverter;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-import java.io.StringReader;
-import javax.json.Json;
-import javax.json.JsonObject;
-
-public class OwnTracksProtocolDecoder extends BaseProtocolDecoder {
-
- public OwnTracksProtocolDecoder(OwnTracksProtocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, HttpResponseStatus status) {
- if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
- response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
- channel.write(response);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- JsonObject root = Json.createReader(
- new StringReader(request.getContent().toString(StandardCharsets.US_ASCII))).readObject();
-
- if (!root.containsKey("_type") || !root.getString("_type").equals("location")) {
- sendResponse(channel, HttpResponseStatus.OK);
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setValid(true);
-
- position.setLatitude(root.getJsonNumber("lat").doubleValue());
- position.setLongitude(root.getJsonNumber("lon").doubleValue());
-
- if (root.containsKey("vel")) {
- position.setSpeed(UnitsConverter.knotsFromKph(root.getInt("vel")));
- }
- if (root.containsKey("alt")) {
- position.setAltitude(root.getInt("alt"));
- }
- if (root.containsKey("cog")) {
- position.setCourse(root.getInt("cog"));
- }
- if (root.containsKey("acc")) {
- position.setAccuracy(root.getInt("acc"));
- }
- if (root.containsKey("t")) {
- position.set("t", root.getString("t"));
- }
- if (root.containsKey("batt")) {
- position.set(Position.KEY_BATTERY, root.getInt("batt"));
- }
-
- position.setTime(new Date(root.getJsonNumber("tst").longValue() * 1000));
-
- String uniqueId;
-
- if (root.containsKey("topic")) {
- uniqueId = root.getString("topic");
- if (root.containsKey("tid")) {
- position.set("tid", root.getString("tid"));
- }
- } else {
- uniqueId = root.getString("tid");
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
- if (deviceSession == null) {
- sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- sendResponse(channel, HttpResponseStatus.OK);
- return position;
- }
-}
diff --git a/src/org/traccar/protocol/PathAwayProtocol.java b/src/org/traccar/protocol/PathAwayProtocol.java
deleted file mode 100644
index a41692750..000000000
--- a/src/org/traccar/protocol/PathAwayProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class PathAwayProtocol extends BaseProtocol {
-
- public PathAwayProtocol() {
- super("pathaway");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("objectDecoder", new PathAwayProtocolDecoder(PathAwayProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/PathAwayProtocolDecoder.java b/src/org/traccar/protocol/PathAwayProtocolDecoder.java
deleted file mode 100644
index 1c4531612..000000000
--- a/src/org/traccar/protocol/PathAwayProtocolDecoder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.ChannelFutureListener;
-import org.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.jboss.netty.handler.codec.http.QueryStringDecoder;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-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 PathAwayProtocolDecoder extends BaseProtocolDecoder {
-
- public PathAwayProtocolDecoder(PathAwayProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$PWS,")
- .number("d+,") // version
- .expression("[^,]*,") // name
- .expression("[^,]*,") // icon
- .expression("[^,]*,") // color
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(-?d+.?d*),") // altitude
- .number("(-?d+.?d*),") // speed
- .number("(-?d+.?d*),") // course
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(true);
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
- channel.write(response).addListener(ChannelFutureListener.CLOSE);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/PiligrimProtocol.java b/src/org/traccar/protocol/PiligrimProtocol.java
deleted file mode 100644
index a2960f762..000000000
--- a/src/org/traccar/protocol/PiligrimProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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.http.HttpChunkAggregator;
-import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
-import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class PiligrimProtocol extends BaseProtocol {
-
- public PiligrimProtocol() {
- super("piligrim");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("httpEncoder", new HttpResponseEncoder());
- pipeline.addLast("httpDecoder", new HttpRequestDecoder());
- pipeline.addLast("httpAggregator", new HttpChunkAggregator(16384));
- pipeline.addLast("objectDecoder", new PiligrimProtocolDecoder(PiligrimProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
deleted file mode 100644
index 9d5bb9e24..000000000
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.handler.codec.http.DefaultHttpResponse;
-import org.jboss.netty.handler.codec.http.HttpRequest;
-import org.jboss.netty.handler.codec.http.HttpResponse;
-import org.jboss.netty.handler.codec.http.HttpResponseStatus;
-import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.jboss.netty.handler.codec.http.QueryStringDecoder;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedList;
-import java.util.List;
-
-public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
-
- public PiligrimProtocolDecoder(PiligrimProtocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, String message) {
- if (channel != null) {
- HttpResponse response = new DefaultHttpResponse(
- HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
- response.setContent(ChannelBuffers.copiedBuffer(
- ByteOrder.BIG_ENDIAN, message, StandardCharsets.US_ASCII));
- channel.write(response);
- }
- }
-
- public static final int MSG_GPS = 0xF1;
- public static final int MSG_GPS_SENSORS = 0xF2;
- public static final int MSG_EVENTS = 0xF3;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- HttpRequest request = (HttpRequest) msg;
- String uri = request.getUri();
-
- if (uri.startsWith("/config")) {
-
- sendResponse(channel, "CONFIG: OK");
-
- } else if (uri.startsWith("/addlog")) {
-
- sendResponse(channel, "ADDLOG: OK");
-
- } else if (uri.startsWith("/inform")) {
-
- sendResponse(channel, "INFORM: OK");
-
- } else if (uri.startsWith("/bingps")) {
-
- sendResponse(channel, "BINGPS: OK");
-
- QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, decoder.getParameters().get("imei").get(0));
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
- ChannelBuffer buf = request.getContent();
-
- while (buf.readableBytes() > 2) {
-
- buf.readUnsignedByte(); // header
- int type = buf.readUnsignedByte();
- buf.readUnsignedByte(); // length
-
- if (type == MSG_GPS || type == MSG_GPS_SENSORS) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDay(buf.readUnsignedByte())
- .setMonth(buf.getByte(buf.readerIndex()) & 0x0f)
- .setYear(2010 + (buf.readUnsignedByte() >> 4))
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- position.setTime(dateBuilder.getDate());
-
- double latitude = buf.readUnsignedByte();
- latitude += buf.readUnsignedByte() / 60.0;
- latitude += buf.readUnsignedByte() / 6000.0;
- latitude += buf.readUnsignedByte() / 600000.0;
-
- double longitude = buf.readUnsignedByte();
- longitude += buf.readUnsignedByte() / 60.0;
- longitude += buf.readUnsignedByte() / 6000.0;
- longitude += buf.readUnsignedByte() / 600000.0;
-
- int flags = buf.readUnsignedByte();
- if (BitUtil.check(flags, 0)) {
- latitude = -latitude;
- }
- if (BitUtil.check(flags, 1)) {
- longitude = -longitude;
- }
- position.setLatitude(latitude);
- position.setLongitude(longitude);
-
- int satellites = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, satellites);
- position.setValid(satellites >= 3);
-
- position.setSpeed(buf.readUnsignedByte());
-
- double course = buf.readUnsignedByte() << 1;
- course += (flags >> 2) & 1;
- course += buf.readUnsignedByte() / 100.0;
- position.setCourse(course);
-
- if (type == MSG_GPS_SENSORS) {
- double power = buf.readUnsignedByte();
- power += buf.readUnsignedByte() << 8;
- position.set(Position.KEY_POWER, power * 0.01);
-
- double battery = buf.readUnsignedByte();
- battery += buf.readUnsignedByte() << 8;
- position.set(Position.KEY_BATTERY, battery * 0.01);
-
- buf.skipBytes(6);
- }
-
- positions.add(position);
-
- } else if (type == MSG_EVENTS) {
-
- buf.skipBytes(13);
- }
- }
-
- return positions;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/PretraceProtocol.java b/src/org/traccar/protocol/PretraceProtocol.java
deleted file mode 100644
index 8f0a22851..000000000
--- a/src/org/traccar/protocol/PretraceProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 PretraceProtocol extends BaseProtocol {
-
- public PretraceProtocol() {
- super("pretrace");
- }
-
- @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 PretraceProtocolDecoder(PretraceProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/PretraceProtocolDecoder.java b/src/org/traccar/protocol/PretraceProtocolDecoder.java
deleted file mode 100644
index 77d94068f..000000000
--- a/src/org/traccar/protocol/PretraceProtocolDecoder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.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 PretraceProtocolDecoder extends BaseProtocolDecoder {
-
- public PretraceProtocolDecoder(PretraceProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("(")
- .number("(d{15})") // imei
- .number("Uddd") // type
- .number("d") // gps type
- .expression("([AV])") // validity
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(dd)(dd.dddd)") // latitude
- .expression("([NS])")
- .number("(ddd)(dd.dddd)") // longitude
- .expression("([EW])")
- .number("(ddd)") // speed
- .number("(ddd)") // course
- .number("(xxx)") // altitude
- .number("(x{8})") // odometer
- .number("(x)") // satellites
- .number("(dd)") // hdop
- .number("(dd)") // gsm
- .expression("(.{8})") // state
- .any()
- .text("^")
- .number("xx") // checksum
- .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());
-
- position.setValid(parser.next().equals("A"));
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
- position.setAltitude(parser.nextHexInt(0));
-
- position.set(Position.KEY_ODOMETER, parser.nextHexInt(0));
- position.set(Position.KEY_SATELLITES, parser.nextHexInt(0));
- position.set(Position.KEY_HDOP, parser.nextInt(0));
- position.set(Position.KEY_RSSI, parser.nextInt(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/PricolProtocol.java b/src/org/traccar/protocol/PricolProtocol.java
deleted file mode 100644
index 0005dc3c1..000000000
--- a/src/org/traccar/protocol/PricolProtocol.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.FixedLengthFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class PricolProtocol extends BaseProtocol {
-
- public PricolProtocol() {
- super("pricol");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new FixedLengthFrameDecoder(64));
- pipeline.addLast("objectDecoder", new PricolProtocolDecoder(PricolProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new PricolProtocolDecoder(PricolProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/PricolProtocolDecoder.java b/src/org/traccar/protocol/PricolProtocolDecoder.java
deleted file mode 100644
index a33e19b90..000000000
--- a/src/org/traccar/protocol/PricolProtocolDecoder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class PricolProtocolDecoder extends BaseProtocolDecoder {
-
- public PricolProtocolDecoder(PricolProtocol protocol) {
- super(protocol);
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // header
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, buf.readBytes(7).toString(StandardCharsets.US_ASCII));
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set("eventType", buf.readUnsignedByte());
- position.set("packetVersion", buf.readUnsignedByte());
- position.set(Position.KEY_STATUS, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- position.set(Position.KEY_GPS, buf.readUnsignedByte());
-
- position.setTime(new DateBuilder()
- .setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
-
- position.setValid(true);
-
- double lat = buf.getUnsignedShort(buf.readerIndex()) / 100;
- lat += (buf.readUnsignedShort() % 100 * 10000 + buf.readUnsignedShort()) / 600000.0;
- position.setLatitude(buf.readUnsignedByte() == 'S' ? -lat : lat);
-
- double lon = buf.getUnsignedMedium(buf.readerIndex()) / 100;
- lon += (buf.readUnsignedMedium() % 100 * 10000 + buf.readUnsignedShort()) / 600000.0;
- position.setLongitude(buf.readUnsignedByte() == 'W' ? -lon : lon);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
-
- position.set(Position.KEY_INPUT, buf.readUnsignedShort());
- position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
-
- position.set("analogAlerts", buf.readUnsignedByte());
- position.set("customAlertTypes", buf.readUnsignedShort());
-
- for (int i = 1; i <= 5; i++) {
- position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
- }
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
- position.set(Position.KEY_RPM, buf.readUnsignedShort());
-
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer("ACK", StandardCharsets.US_ASCII), remoteAddress);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/ProgressProtocol.java b/src/org/traccar/protocol/ProgressProtocol.java
deleted file mode 100644
index 6e2093346..000000000
--- a/src/org/traccar/protocol/ProgressProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class ProgressProtocol extends BaseProtocol {
-
- public ProgressProtocol() {
- super("progress");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, 4, 0));
- pipeline.addLast("objectDecoder", new ProgressProtocolDecoder(ProgressProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
deleted file mode 100644
index 1820ea926..000000000
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class ProgressProtocolDecoder extends BaseProtocolDecoder {
-
- private long lastIndex;
- private long newIndex;
-
- public ProgressProtocolDecoder(ProgressProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_NULL = 0;
- public static final int MSG_IDENT = 1;
- public static final int MSG_IDENT_FULL = 2;
- public static final int MSG_POINT = 10;
- public static final int MSG_LOG_SYNC = 100;
- public static final int MSG_LOGMSG = 101;
- public static final int MSG_TEXT = 102;
- public static final int MSG_ALARM = 200;
- public static final int MSG_ALARM_RECIEVED = 201;
-
- private void requestArchive(Channel channel) {
- if (lastIndex == 0) {
- lastIndex = newIndex;
- } else if (newIndex > lastIndex) {
- ChannelBuffer request = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 12);
- request.writeShort(MSG_LOG_SYNC);
- request.writeShort(4);
- request.writeInt((int) lastIndex);
- request.writeInt(0);
- channel.write(request);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
- int type = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
-
- if (type == MSG_IDENT || type == MSG_IDENT_FULL) {
-
- buf.readUnsignedInt(); // id
- int length = buf.readUnsignedShort();
- buf.skipBytes(length);
- length = buf.readUnsignedShort();
- buf.skipBytes(length);
- length = buf.readUnsignedShort();
- String imei = buf.readBytes(length).toString(StandardCharsets.US_ASCII);
- getDeviceSession(channel, remoteAddress, imei);
-
- } else if (type == MSG_POINT || type == MSG_ALARM || type == MSG_LOGMSG) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- int recordCount = 1;
- if (type == MSG_LOGMSG) {
- recordCount = buf.readUnsignedShort();
- }
-
- for (int j = 0; j < recordCount; j++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (type == MSG_LOGMSG) {
- position.set(Position.KEY_ARCHIVE, true);
- int subtype = buf.readUnsignedShort();
- if (subtype == MSG_ALARM) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- if (buf.readUnsignedShort() > buf.readableBytes()) {
- lastIndex += 1;
- break; // workaround for device bug
- }
- lastIndex = buf.readUnsignedInt();
- position.set(Position.KEY_INDEX, lastIndex);
- } else {
- newIndex = buf.readUnsignedInt();
- }
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- position.setLatitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
- position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
- position.setSpeed(buf.readUnsignedInt() * 0.01);
- position.setCourse(buf.readUnsignedShort() * 0.01);
- position.setAltitude(buf.readUnsignedShort() * 0.01);
-
- int satellites = buf.readUnsignedByte();
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
-
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- long extraFlags = buf.readLong();
-
- if (BitUtil.check(extraFlags, 0)) {
- int count = buf.readUnsignedShort();
- for (int i = 1; i <= count; i++) {
- position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
- }
- }
-
- if (BitUtil.check(extraFlags, 1)) {
- int size = buf.readUnsignedShort();
- position.set("can", buf.toString(buf.readerIndex(), size, StandardCharsets.US_ASCII));
- buf.skipBytes(size);
- }
-
- if (BitUtil.check(extraFlags, 2)) {
- position.set("passenger",
- ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedShort())));
- }
-
- if (type == MSG_ALARM) {
- position.set(Position.KEY_ALARM, true);
- byte[] response = {(byte) 0xC9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- channel.write(ChannelBuffers.wrappedBuffer(response));
- }
-
- buf.readUnsignedInt(); // crc
-
- positions.add(position);
- }
-
- requestArchive(channel);
-
- return positions;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Pt3000Protocol.java b/src/org/traccar/protocol/Pt3000Protocol.java
deleted file mode 100644
index 9c9da3301..000000000
--- a/src/org/traccar/protocol/Pt3000Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 Pt3000Protocol extends BaseProtocol {
-
- public Pt3000Protocol() {
- super("pt3000");
- }
-
- @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, 'd')); // probably wrong
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Pt3000ProtocolDecoder(Pt3000Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
deleted file mode 100644
index c36be7976..000000000
--- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.
- * 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 Pt3000ProtocolDecoder extends BaseProtocolDecoder {
-
- public Pt3000ProtocolDecoder(Pt3000Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("%(d+),") // imei
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java
deleted file mode 100644
index 252c8dd02..000000000
--- a/src/org/traccar/protocol/Pt502FrameDecoder.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class Pt502FrameDecoder extends FrameDecoder {
-
- private static final int BINARY_HEADER = 5;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < BINARY_HEADER) {
- return null;
- }
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
- buf.skipBytes(BINARY_HEADER);
- }
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
- if (index < 0) {
- index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\n');
- }
-
- if (index > 0) {
- ChannelBuffer result = buf.readBytes(index - buf.readerIndex());
- while (buf.readable()
- && (buf.getByte(buf.readerIndex()) == '\r' || buf.getByte(buf.readerIndex()) == '\n')) {
- buf.skipBytes(1);
- }
- return result;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Pt502Protocol.java b/src/org/traccar/protocol/Pt502Protocol.java
deleted file mode 100644
index 0116422c2..000000000
--- a/src/org/traccar/protocol/Pt502Protocol.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.TrackerServer;
-import org.traccar.model.Command;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class Pt502Protocol extends BaseProtocol {
-
- public Pt502Protocol() {
- super("pt502");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_SET_TIMEZONE,
- Command.TYPE_ALARM_SPEED,
- Command.TYPE_OUTPUT_CONTROL,
- Command.TYPE_REQUEST_PHOTO);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Pt502FrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new Pt502ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(Pt502Protocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
deleted file mode 100644
index 1d976dcd5..000000000
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2012 Luis Parada (luis.parada@gmail.com)
- *
- * 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 Pt502ProtocolDecoder extends BaseProtocolDecoder {
-
- private static final int MAX_CHUNK_SIZE = 960;
-
- private byte[] photo;
-
- public Pt502ProtocolDecoder(Pt502Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .any().text("$")
- .expression("([^,]+),") // type
- .number("(d+),") // id
- .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss)
- .expression("([AV]),") // validity
- .number("(d+)(dd.dddd),") // latitude
- .expression("([NS]),")
- .number("(d+)(dd.dddd),") // longitude
- .expression("([EW]),")
- .number("(d+.d+)?,") // speed
- .number("(d+.d+)?,") // course
- .number("(dd)(dd)(dd),,,") // date (ddmmyy)
- .expression("./")
- .expression("([01])+,") // input
- .expression("([01])+/") // output
- .expression("([^/]+)?/") // adc
- .number("(d+)") // odometer
- .expression("/([^/]+)?/") // rfid
- .number("(xxx)").optional(2) // state
- .any()
- .compile();
-
- private String decodeAlarm(String value) {
- switch (value) {
- case "IN1":
- return Position.ALARM_SOS;
- case "GOF":
- return Position.ALARM_GEOFENCE;
- case "TOW":
- return Position.ALARM_TOW;
- case "HDA":
- return Position.ALARM_ACCELERATION;
- case "HDB":
- return Position.ALARM_BRAKING;
- case "FDA":
- return Position.ALARM_FATIGUE_DRIVING;
- case "SKA":
- return Position.ALARM_VIBRATION;
- case "PMA":
- return Position.ALARM_MOVEMENT;
- default:
- return null;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Parser parser = new Parser(PATTERN, (String) msg);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- String type = parser.next();
-
- if (type.startsWith("PHO") && channel != null) {
- photo = new byte[Integer.parseInt(type.substring(3))];
- channel.write("#PHD0," + Math.min(photo.length, MAX_CHUNK_SIZE) + "\r\n");
- }
-
- position.set(Position.KEY_ALARM, decodeAlarm(type));
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
-
- if (parser.hasNext()) {
- String[] values = parser.next().split(",");
- for (int i = 0; i < values.length; i++) {
- position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(values[i], 16));
- }
- }
-
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- if (parser.hasNext()) {
- int value = parser.nextHexInt(0);
- position.set(Position.KEY_BATTERY, value >> 8);
- position.set(Position.KEY_RSSI, (value >> 4) & 0xf);
- position.set(Position.KEY_SATELLITES, value & 0xf);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Pt502ProtocolEncoder.java b/src/org/traccar/protocol/Pt502ProtocolEncoder.java
deleted file mode 100644
index bd56e306a..000000000
--- a/src/org/traccar/protocol/Pt502ProtocolEncoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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 java.util.TimeZone;
-
-import org.traccar.StringProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class Pt502ProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
-
- @Override
- public String formatValue(String key, Object value) {
- if (key.equals(Command.KEY_TIMEZONE)) {
- return String.valueOf(TimeZone.getTimeZone((String) value).getRawOffset() / 3600000);
- }
-
- return null;
- }
-
- @Override
- protected String formatCommand(Command command, String format, String... keys) {
- return formatCommand(command, format, this, keys);
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, "{%s}\r\n", Command.KEY_DATA);
- case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "#OPC{%s},{%s}\r\n", Command.KEY_INDEX, Command.KEY_DATA);
- case Command.TYPE_SET_TIMEZONE:
- return formatCommand(command, "#TMZ{%s}\r\n", Command.KEY_TIMEZONE);
- case Command.TYPE_ALARM_SPEED:
- return formatCommand(command, "#SPD{%s}\r\n", Command.KEY_DATA);
- case Command.TYPE_REQUEST_PHOTO:
- return formatCommand(command, "#PHO\r\n");
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/RaveonProtocol.java b/src/org/traccar/protocol/RaveonProtocol.java
deleted file mode 100644
index e4e100e0b..000000000
--- a/src/org/traccar/protocol/RaveonProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 RaveonProtocol extends BaseProtocol {
-
- public RaveonProtocol() {
- super("raveon");
- }
-
- @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 RaveonProtocolDecoder(RaveonProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/RaveonProtocolDecoder.java b/src/org/traccar/protocol/RaveonProtocolDecoder.java
deleted file mode 100644
index cbe6026a2..000000000
--- a/src/org/traccar/protocol/RaveonProtocolDecoder.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.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 RaveonProtocolDecoder extends BaseProtocolDecoder {
-
- public RaveonProtocolDecoder(RaveonProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$PRAVE,")
- .number("(d+),") // id
- .number("d+,")
- .number("(-?)(d+)(dd.d+),") // latitude
- .number("(-?)(d+)(dd.d+),") // longitude
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d),") // validity
- .number("(d+),") // satellites
- .number("(-?d+),") // altitude
- .number("(-?d+),") // temperature
- .number("(d+.d+),") // power
- .number("(d+),") // inputs
- .number("(-?d+),") // gsm
- .number("(d+),") // speed
- .number("(d+),") // course
- .expression("([PMACIVSX])?,") // status
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS));
-
- position.setValid(parser.nextInt(0) != 0);
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
-
- position.setAltitude(parser.nextInt(0));
-
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- position.set(Position.KEY_INPUT, parser.nextInt(0));
- position.set(Position.KEY_RSSI, parser.nextInt(0));
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
- position.setCourse(parser.nextInt(0));
-
- position.set(Position.KEY_ALARM, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/RecodaProtocol.java b/src/org/traccar/protocol/RecodaProtocol.java
deleted file mode 100644
index daf167fd9..000000000
--- a/src/org/traccar/protocol/RecodaProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class RecodaProtocol extends BaseProtocol {
-
- public RecodaProtocol() {
- super("recoda");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 4, 4, -8, 0));
- pipeline.addLast("objectDecoder", new RecodaProtocolDecoder(RecodaProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/RecodaProtocolDecoder.java b/src/org/traccar/protocol/RecodaProtocolDecoder.java
deleted file mode 100644
index 8db582d35..000000000
--- a/src/org/traccar/protocol/RecodaProtocolDecoder.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-public class RecodaProtocolDecoder extends BaseProtocolDecoder {
-
- public RecodaProtocolDecoder(RecodaProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_HEARTBEAT = 0x00001001;
- public static final int MSG_REQUEST_RESPONSE = 0x20000001;
- public static final int MSG_SIGNAL_LINK_REGISTRATION = 0x20001001;
- public static final int MSG_EVENT_NOTICE = 0x20002001;
- public static final int MSG_GPS_DATA = 0x20001011;
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int type = buf.readInt();
- buf.readUnsignedInt(); // length
-
- if (type != MSG_HEARTBEAT) {
- buf.readUnsignedShort(); // version
- buf.readUnsignedShort(); // index
- }
-
- if (type == MSG_SIGNAL_LINK_REGISTRATION) {
-
- getDeviceSession(channel, remoteAddress, buf.readBytes(12).toString(StandardCharsets.US_ASCII));
-
- } else if (type == MSG_GPS_DATA) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date(buf.readLong()));
-
- int flags = buf.readUnsignedByte();
-
- if (BitUtil.check(flags, 0)) {
-
- buf.readUnsignedShort(); // declination
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
-
- position.setLongitude(buf.readUnsignedByte() + buf.readUnsignedByte() / 60.0);
- position.setLatitude(buf.readUnsignedByte() + buf.readUnsignedByte() / 60.0);
-
- position.setLongitude(position.getLongitude() + buf.readUnsignedInt() / 3600.0);
- position.setLatitude(position.getLatitude() + buf.readUnsignedInt() / 3600.0);
-
- int status = buf.readUnsignedByte();
-
- position.setValid(BitUtil.check(status, 0));
- if (BitUtil.check(status, 1)) {
- position.setLongitude(-position.getLongitude());
- }
- if (!BitUtil.check(status, 2)) {
- position.setLatitude(-position.getLatitude());
- }
-
- } else {
-
- getLastLocation(position, position.getDeviceTime());
-
- }
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/RitiProtocol.java b/src/org/traccar/protocol/RitiProtocol.java
deleted file mode 100644
index 0ff3ce87b..000000000
--- a/src/org/traccar/protocol/RitiProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class RitiProtocol extends BaseProtocol {
-
- public RitiProtocol() {
- super("riti");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 105, 2, 3, 0));
- pipeline.addLast("objectDecoder", new RitiProtocolDecoder(RitiProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java
deleted file mode 100644
index 5c298e8c5..000000000
--- a/src/org/traccar/protocol/RitiProtocolDecoder.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.
- * 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.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.nio.charset.StandardCharsets;
-import java.util.regex.Pattern;
-
-public class RitiProtocolDecoder extends BaseProtocolDecoder {
-
- public RitiProtocolDecoder(RitiProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set("mode", buf.readUnsignedByte());
- position.set(Position.KEY_COMMAND, buf.readUnsignedByte());
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
-
- buf.skipBytes(5); // status
- buf.readUnsignedShort(); // idleCount
- buf.readUnsignedShort(); // idleTime in seconds
-
- position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
-
- // Parse GPRMC
- int end = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
- String gprmc = buf.toString(buf.readerIndex(), end - buf.readerIndex(), StandardCharsets.US_ASCII);
- Parser parser = new Parser(PATTERN, gprmc);
- if (!parser.matches()) {
- return null;
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/RuptelaProtocol.java b/src/org/traccar/protocol/RuptelaProtocol.java
deleted file mode 100644
index fc3b17dd9..000000000
--- a/src/org/traccar/protocol/RuptelaProtocol.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class RuptelaProtocol extends BaseProtocol {
-
- public RuptelaProtocol() {
- super("ruptela");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_CONFIGURATION,
- Command.TYPE_GET_VERSION,
- Command.TYPE_FIRMWARE_UPDATE,
- Command.TYPE_OUTPUT_CONTROL,
- Command.TYPE_SET_CONNECTION,
- Command.TYPE_SET_ODOMETER);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, 2, 0));
- pipeline.addLast("objectEncoder", new RuptelaProtocolEncoder());
- pipeline.addLast("objectDecoder", new RuptelaProtocolDecoder(RuptelaProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
deleted file mode 100644
index 8752d30c0..000000000
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.UnitsConverter;
-import org.traccar.model.Position;
-
-import javax.xml.bind.DatatypeConverter;
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
-
- public RuptelaProtocolDecoder(RuptelaProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_RECORDS = 1;
- public static final int MSG_DEVICE_CONFIGURATION = 2;
- public static final int MSG_DEVICE_VERSION = 3;
- public static final int MSG_FIRMWARE_UPDATE = 4;
- public static final int MSG_SET_CONNECTION = 5;
- public static final int MSG_SET_ODOMETER = 6;
- public static final int MSG_SMS_VIA_GPRS_RESPONSE = 7;
- public static final int MSG_SMS_VIA_GPRS = 8;
- public static final int MSG_DTCS = 9;
- public static final int MSG_SET_IO = 17;
- public static final int MSG_EXTENDED_RECORDS = 68;
-
- private Position decodeCommandResponse(DeviceSession deviceSession, int type, ChannelBuffer buf) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_TYPE, type);
-
- switch (type) {
- case MSG_DEVICE_CONFIGURATION:
- case MSG_DEVICE_VERSION:
- case MSG_FIRMWARE_UPDATE:
- case MSG_SMS_VIA_GPRS_RESPONSE:
- position.set(Position.KEY_RESULT,
- buf.toString(buf.readerIndex(), buf.readableBytes() - 2, StandardCharsets.US_ASCII).trim());
- return position;
- case MSG_SET_IO:
- position.set(Position.KEY_RESULT,
- String.valueOf(buf.readUnsignedByte()));
- return position;
- default:
- return null;
- }
- }
-
- private long readValue(ChannelBuffer buf, int length, boolean signed) {
- switch (length) {
- case 1:
- return signed ? buf.readByte() : buf.readUnsignedByte();
- case 2:
- return signed ? buf.readShort() : buf.readUnsignedShort();
- case 4:
- return signed ? buf.readInt() : buf.readUnsignedInt();
- default:
- return buf.readLong();
- }
- }
-
- private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) {
- switch (id) {
- case 2:
- case 3:
- case 4:
- position.set("di" + (id - 1), readValue(buf, length, false));
- break;
- case 5:
- position.set(Position.KEY_IGNITION, readValue(buf, length, false) == 1);
- break;
- case 74:
- position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1);
- break;
- case 78:
- case 79:
- case 80:
- position.set(Position.PREFIX_TEMP + (id - 78), readValue(buf, length, true) * 0.1);
- break;
- default:
- position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
- break;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedShort(); // data length
-
- String imei = String.format("%015d", buf.readLong());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- int type = buf.readUnsignedByte();
-
- if (type == MSG_RECORDS || type == MSG_EXTENDED_RECORDS) {
-
- List<Position> positions = new LinkedList<>();
-
- buf.readUnsignedByte(); // records left
- int count = buf.readUnsignedByte();
-
- for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- 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);
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
-
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() / 10.0);
-
- if (type == MSG_EXTENDED_RECORDS) {
- position.set(Position.KEY_EVENT, buf.readUnsignedShort());
- } else {
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- }
-
- // Read 1 byte data
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
- decodeParameter(position, id, buf, 1);
- }
-
- // Read 2 byte data
- cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
- decodeParameter(position, id, buf, 2);
- }
-
- // Read 4 byte data
- cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
- decodeParameter(position, id, buf, 4);
- }
-
- // Read 8 byte data
- cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- int id = type == MSG_EXTENDED_RECORDS ? buf.readUnsignedShort() : buf.readUnsignedByte();
- decodeParameter(position, id, buf, 8);
- }
-
- positions.add(position);
- }
-
- if (channel != null) {
- channel.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary("0002640113bc")));
- }
-
- return positions;
-
- } else if (type == MSG_DTCS) {
-
- List<Position> positions = new LinkedList<>();
-
- int count = buf.readUnsignedByte();
-
- for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedByte(); // reserved
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- position.setValid(true);
- position.setLongitude(buf.readInt() / 10000000.0);
- position.setLatitude(buf.readInt() / 10000000.0);
-
- if (buf.readUnsignedByte() == 2) {
- position.set(Position.KEY_ARCHIVE, true);
- }
-
- position.set(Position.KEY_DTCS, buf.readBytes(5).toString(StandardCharsets.US_ASCII));
-
- positions.add(position);
- }
-
- if (channel != null) {
- channel.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary("00026d01c4a4")));
- }
-
- return positions;
-
- } else {
-
- return decodeCommandResponse(deviceSession, type, buf);
-
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/RuptelaProtocolEncoder.java b/src/org/traccar/protocol/RuptelaProtocolEncoder.java
deleted file mode 100644
index 564d80869..000000000
--- a/src/org/traccar/protocol/RuptelaProtocolEncoder.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.nio.charset.StandardCharsets;
-
-public class RuptelaProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeContent(int type, ChannelBuffer content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeShort(1 + content.readableBytes());
- buf.writeByte(100 + type);
- buf.writeBytes(content);
- buf.writeShort(Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer(2, buf.writerIndex() - 2)));
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- ChannelBuffer content = ChannelBuffers.dynamicBuffer();
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- content.writeBytes(command.getString(Command.KEY_DATA).getBytes(StandardCharsets.US_ASCII));
- return encodeContent(RuptelaProtocolDecoder.MSG_SMS_VIA_GPRS, content);
- case Command.TYPE_CONFIGURATION:
- content.writeBytes((command.getString(Command.KEY_DATA) + "\r\n").getBytes(StandardCharsets.US_ASCII));
- return encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_CONFIGURATION, content);
- case Command.TYPE_GET_VERSION:
- return encodeContent(RuptelaProtocolDecoder.MSG_DEVICE_VERSION, content);
- case Command.TYPE_FIRMWARE_UPDATE:
- content.writeBytes("|FU_STRT*\r\n".getBytes(StandardCharsets.US_ASCII));
- return encodeContent(RuptelaProtocolDecoder.MSG_FIRMWARE_UPDATE, content);
- case Command.TYPE_OUTPUT_CONTROL:
- content.writeInt(command.getInteger(Command.KEY_INDEX));
- content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA)));
- return encodeContent(RuptelaProtocolDecoder.MSG_SET_IO, content);
- case Command.TYPE_SET_CONNECTION:
- String c = command.getString(Command.KEY_SERVER) + "," + command.getInteger(Command.KEY_PORT) + ",TCP";
- content.writeBytes(c.getBytes(StandardCharsets.US_ASCII));
- return encodeContent(RuptelaProtocolDecoder.MSG_SET_CONNECTION, content);
- case Command.TYPE_SET_ODOMETER:
- content.writeInt(Integer.parseInt(command.getString(Command.KEY_DATA)));
- return encodeContent(RuptelaProtocolDecoder.MSG_SET_ODOMETER, content);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/SanavProtocol.java b/src/org/traccar/protocol/SanavProtocol.java
deleted file mode 100644
index 4f463725e..000000000
--- a/src/org/traccar/protocol/SanavProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 SanavProtocol extends BaseProtocol {
-
- public SanavProtocol() {
- super("sanav");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new SanavProtocolDecoder(SanavProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java
deleted file mode 100644
index 151c55795..000000000
--- a/src/org/traccar/protocol/SanavProtocolDecoder.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.
- * 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 SanavProtocolDecoder extends BaseProtocolDecoder {
-
- public SanavProtocolDecoder(SanavProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .any()
- .expression("imei[:=]")
- .number("(d+)") // imei
- .expression("&?rmc[:=]")
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).d+,") // time (hhmmss.sss)
- .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 (ddmmyy)
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/SiwiProtocol.java b/src/org/traccar/protocol/SiwiProtocol.java
deleted file mode 100644
index 667e083f1..000000000
--- a/src/org/traccar/protocol/SiwiProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 SiwiProtocol extends BaseProtocol {
-
- public SiwiProtocol() {
- super("siwi");
- }
-
- @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 SiwiProtocolDecoder(SiwiProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/SiwiProtocolDecoder.java b/src/org/traccar/protocol/SiwiProtocolDecoder.java
deleted file mode 100644
index 198df24d5..000000000
--- a/src/org/traccar/protocol/SiwiProtocolDecoder.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.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 SiwiProtocolDecoder extends BaseProtocolDecoder {
-
- public SiwiProtocolDecoder(SiwiProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$").expression("[A-Z]+,") // header
- .number("(d+),") // device id
- .number("d+,") // unit no
- .expression("([A-Z]),") // reason
- .number("d+,") // command code
- .number("[^,]*,") // command value
- .expression("([01]),") // ignition
- .expression("[01],") // power cut
- .expression("[01],") // box open
- .number("d+,") // message key
- .number("(d+),") // odometer
- .number("(d+),") // speed
- .number("(d+),") // satellites
- .expression("([AV]),") // valid
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(-?d+),") // altitude
- .number("(d+),") // course
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .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());
-
- position.set(Position.KEY_EVENT, parser.next());
- position.set(Position.KEY_IGNITION, parser.next().equals("1"));
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setCourse(parser.nextInt(0));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "IST"));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/SkypatrolProtocol.java b/src/org/traccar/protocol/SkypatrolProtocol.java
deleted file mode 100644
index fba432522..000000000
--- a/src/org/traccar/protocol/SkypatrolProtocol.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- * 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 SkypatrolProtocol extends BaseProtocol {
-
- public SkypatrolProtocol() {
- super("skypatrol");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new SkypatrolProtocolDecoder(SkypatrolProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
deleted file mode 100644
index f4dded972..000000000
--- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Log;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
-
- private final long defaultMask;
-
- public SkypatrolProtocolDecoder(SkypatrolProtocol protocol) {
- super(protocol);
- defaultMask = Context.getConfig().getInteger(getProtocolName() + ".mask");
- }
-
- private static double convertCoordinate(long coordinate) {
- int sign = 1;
- if (coordinate > 0x7fffffffL) {
- sign = -1;
- coordinate = 0xffffffffL - coordinate;
- }
-
- long degrees = coordinate / 1000000;
- double minutes = (coordinate % 1000000) / 10000.0;
-
- return sign * (degrees + minutes / 60);
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int apiNumber = buf.readUnsignedShort();
- int commandType = buf.readUnsignedByte();
- int messageType = BitUtil.from(buf.readUnsignedByte(), 4);
- long mask = defaultMask;
- if (buf.readUnsignedByte() == 4) {
- mask = buf.readUnsignedInt();
- }
-
- // Binary position report
- if (apiNumber == 5 && commandType == 2 && messageType == 1 && BitUtil.check(mask, 0)) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- if (BitUtil.check(mask, 1)) {
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
- }
-
- String id;
- if (BitUtil.check(mask, 23)) {
- id = buf.toString(buf.readerIndex(), 8, StandardCharsets.US_ASCII).trim();
- buf.skipBytes(8);
- } else if (BitUtil.check(mask, 2)) {
- id = buf.toString(buf.readerIndex(), 22, StandardCharsets.US_ASCII).trim();
- buf.skipBytes(22);
- } else {
- Log.warning("No device id field");
- return null;
- }
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (BitUtil.check(mask, 3)) {
- position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(mask, 4)) {
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(mask, 5)) {
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(mask, 7)) {
- buf.readUnsignedByte(); // function category
- }
-
- DateBuilder dateBuilder = new DateBuilder();
-
- if (BitUtil.check(mask, 8)) {
- dateBuilder.setDateReverse(
- buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- }
-
- if (BitUtil.check(mask, 9)) {
- position.setValid(buf.readUnsignedByte() == 1); // gps status
- }
-
- if (BitUtil.check(mask, 10)) {
- position.setLatitude(convertCoordinate(buf.readUnsignedInt()));
- }
-
- if (BitUtil.check(mask, 11)) {
- position.setLongitude(convertCoordinate(buf.readUnsignedInt()));
- }
-
- if (BitUtil.check(mask, 12)) {
- position.setSpeed(buf.readUnsignedShort() / 10.0);
- }
-
- if (BitUtil.check(mask, 13)) {
- position.setCourse(buf.readUnsignedShort() / 10.0);
- }
-
- if (BitUtil.check(mask, 14)) {
- dateBuilder.setTime(
- buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
- }
-
- position.setTime(dateBuilder.getDate());
-
- if (BitUtil.check(mask, 15)) {
- position.setAltitude(buf.readMedium());
- }
-
- if (BitUtil.check(mask, 16)) {
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- }
-
- if (BitUtil.check(mask, 17)) {
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
- }
-
- if (BitUtil.check(mask, 20)) {
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
- }
-
- if (BitUtil.check(mask, 21)) {
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- }
-
- if (BitUtil.check(mask, 22)) {
- buf.skipBytes(6); // time of message generation
- }
-
- if (BitUtil.check(mask, 24)) {
- position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
- }
-
- if (BitUtil.check(mask, 25)) {
- buf.skipBytes(18); // gps overspeed
- }
-
- if (BitUtil.check(mask, 26)) {
- buf.skipBytes(54); // cell information
- }
-
- if (BitUtil.check(mask, 28)) {
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
- }
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/SmokeyProtocol.java b/src/org/traccar/protocol/SmokeyProtocol.java
deleted file mode 100644
index 4f9a8dd74..000000000
--- a/src/org/traccar/protocol/SmokeyProtocol.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 2dcfeb86f..000000000
--- a/src/org/traccar/protocol/SmokeyProtocolDecoder.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.joda.time.DateTime;
-import org.joda.time.DateTimeZone;
-import org.joda.time.Seconds;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.DateBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-import org.traccar.model.WifiAccessPoint;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-
-public class SmokeyProtocolDecoder extends BaseProtocolDecoder {
-
- public SmokeyProtocolDecoder(SmokeyProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_DATE_RECORD = 0;
- public static final int MSG_DATE_RECORD_ACK = 1;
-
- private static void sendResponse(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer id, int index, int report) {
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeBytes("SM".getBytes(StandardCharsets.US_ASCII));
- response.writeByte(3); // protocol version
- response.writeByte(MSG_DATE_RECORD_ACK);
- response.writeBytes(id);
- response.writeInt(Seconds.secondsBetween(
- new DateTime(2000, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(DateTimeZone.UTC)).getSeconds());
- response.writeByte(index);
- response.writeByte(report - 0x200);
-
- short checksum = (short) 0xF5A0;
- for (int i = 0; i < response.readableBytes(); i += 2) {
- checksum ^= ChannelBuffers.swapShort(response.getShort(i));
- }
- response.writeShort(checksum);
-
- channel.write(response, remoteAddress);
- }
- }
-
- @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();
-
- ChannelBuffer id = buf.readBytes(8);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(id));
- if (deviceSession == null) {
- return null;
- }
-
- if (type == MSG_DATE_RECORD) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_VERSION_FW, buf.readUnsignedShort());
-
- int status = buf.readUnsignedShort();
- position.set(Position.KEY_STATUS, status);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(2000, 1, 1).addSeconds(buf.readUnsignedInt());
-
- getLastLocation(position, dateBuilder.getDate());
-
- int index = buf.readUnsignedByte();
- position.set(Position.KEY_INDEX, index);
-
- int report = buf.readUnsignedShort();
-
- buf.readUnsignedShort(); // length
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
-
- Network network = new Network();
-
- if (report != 0x0203) {
-
- int count = 1;
- if (report != 0x0200) {
- count = buf.readUnsignedByte();
- }
-
- for (int i = 0; i < count; i++) {
- int mcc = buf.readUnsignedShort();
- int mnc = buf.readUnsignedShort();
- int lac = buf.readUnsignedShort();
- int cid = buf.readUnsignedShort();
- if (i == 0) {
- buf.readByte(); // timing advance
- }
- int rssi = buf.readByte();
- network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi));
- }
-
- }
-
- if (report == 0x0202 || report == 0x0203) {
-
- int count = buf.readUnsignedByte();
-
- for (int i = 0; i < count; i++) {
- buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0) + 1); // ssid
-
- String mac = String.format("%02x:%02x:%02x:%02x:%02x:%02x",
- buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(),
- buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
-
- network.addWifiAccessPoint(WifiAccessPoint.from(mac, buf.readByte()));
- }
-
- }
-
- position.setNetwork(network);
-
- sendResponse(channel, remoteAddress, id, index, report);
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/StarLinkProtocol.java b/src/org/traccar/protocol/StarLinkProtocol.java
deleted file mode 100644
index e71d94fd0..000000000
--- a/src/org/traccar/protocol/StarLinkProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 StarLinkProtocol extends BaseProtocol {
-
- public StarLinkProtocol() {
- super("starlink");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new StarLinkProtocolDecoder(StarLinkProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/org/traccar/protocol/StarLinkProtocolDecoder.java
deleted file mode 100644
index 79f013fac..000000000
--- a/src/org/traccar/protocol/StarLinkProtocolDecoder.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.TimeZone;
-import java.util.regex.Pattern;
-
-public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
-
- private String[] dataTags;
- private DateFormat dateFormat;
-
- public StarLinkProtocolDecoder(StarLinkProtocol protocol) {
- super(protocol);
-
- String format = Context.getConfig().getString(
- getProtocolName() + ".format", "#EDT#,#EID#,#PDT#,#LAT#,#LONG#,#SPD#,#HEAD#,#ODO#,"
- + "#IN1#,#IN2#,#IN3#,#IN4#,#OUT1#,#OUT2#,#OUT3#,#OUT4#,#LAC#,#CID#,#VIN#,#VBAT#,#DEST#,#IGN#,#ENG#");
- dataTags = format.split(",");
-
- dateFormat = new SimpleDateFormat(
- Context.getConfig().getString(getProtocolName() + ".dateFormat", "yyMMddHHmmss"));
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression(".") // protocol head
- .text("SLU") // message head
- .number("(x{6}|d{15}),") // id
- .number("(d+),") // type
- .number("(d+),") // index
- .expression("(.+)") // data
- .text("*")
- .number("xx") // checksum
- .compile();
-
- public static final int MSG_EVENT_REPORT = 6;
-
- private double parseCoordinate(String value) {
- int minutesIndex = value.indexOf('.') - 2;
- double result = Double.parseDouble(value.substring(1, minutesIndex));
- result += Double.parseDouble(value.substring(minutesIndex)) / 60;
- return value.charAt(0) == '+' ? result : -result;
- }
-
- private String decodeAlarm(int event) {
- switch (event) {
- case 6:
- return Position.ALARM_OVERSPEED;
- case 7:
- return Position.ALARM_GEOFENCE_ENTER;
- case 8:
- return Position.ALARM_GEOFENCE_EXIT;
- case 9:
- return Position.ALARM_POWER_CUT;
- case 11:
- return Position.ALARM_LOW_BATTERY;
- case 26:
- return Position.ALARM_TOW;
- case 36:
- return Position.ALARM_SOS;
- case 42:
- return Position.ALARM_JAMMING;
- default:
- return null;
- }
- }
-
- @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;
- }
-
- int type = parser.nextInt(0);
- if (type != MSG_EVENT_REPORT) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- position.setValid(true);
-
- position.set(Position.KEY_INDEX, parser.nextInt(0));
-
- String[] data = parser.next().split(",");
- Integer lac = null, cid = null;
- int event = 0;
-
- for (int i = 0; i < Math.min(data.length, dataTags.length); i++) {
- if (data[i].isEmpty()) {
- continue;
- }
- switch (dataTags[i]) {
- case "#EDT#":
- position.setDeviceTime(dateFormat.parse(data[i]));
- break;
- case "#EID#":
- event = Integer.parseInt(data[i]);
- position.set(Position.KEY_ALARM, decodeAlarm(event));
- position.set(Position.KEY_EVENT, event);
- break;
- case "#PDT#":
- position.setFixTime(dateFormat.parse(data[i]));
- break;
- case "#LAT#":
- position.setLatitude(parseCoordinate(data[i]));
- break;
- case "#LONG#":
- position.setLongitude(parseCoordinate(data[i]));
- break;
- case "#SPD#":
- position.setSpeed(Double.parseDouble(data[i]));
- break;
- case "#HEAD#":
- position.setCourse(Integer.parseInt(data[i]));
- break;
- case "#ODO#":
- position.set(Position.KEY_ODOMETER, Long.parseLong(data[i]) * 1000);
- break;
- case "#IN1#":
- position.set(Position.PREFIX_IN + 1, Integer.parseInt(data[i]));
- break;
- case "#IN2#":
- position.set(Position.PREFIX_IN + 2, Integer.parseInt(data[i]));
- break;
- case "#IN3#":
- position.set(Position.PREFIX_IN + 3, Integer.parseInt(data[i]));
- break;
- case "#IN4#":
- position.set(Position.PREFIX_IN + 4, Integer.parseInt(data[i]));
- break;
- case "#OUT1#":
- position.set(Position.PREFIX_OUT + 1, Integer.parseInt(data[i]));
- break;
- case "#OUT2#":
- position.set(Position.PREFIX_OUT + 2, Integer.parseInt(data[i]));
- break;
- case "#OUT3#":
- position.set(Position.PREFIX_OUT + 3, Integer.parseInt(data[i]));
- break;
- case "#OUT4#":
- position.set(Position.PREFIX_OUT + 4, Integer.parseInt(data[i]));
- break;
- case "#LAC#":
- if (!data[i].isEmpty()) {
- lac = Integer.parseInt(data[i]);
- }
- break;
- case "#CID#":
- if (!data[i].isEmpty()) {
- cid = Integer.parseInt(data[i]);
- }
- break;
- case "#VIN#":
- position.set(Position.KEY_POWER, Double.parseDouble(data[i]));
- break;
- case "#VBAT#":
- position.set(Position.KEY_BATTERY, Double.parseDouble(data[i]));
- break;
- case "#DEST#":
- position.set("destination", data[i]);
- break;
- case "#IGN#":
- position.set(Position.KEY_IGNITION, data[i].equals("1"));
- break;
- case "#ENG#":
- position.set("engine", data[i].equals("1"));
- break;
- default:
- break;
- }
- }
-
- if (position.getFixTime() == null) {
- getLastLocation(position, null);
- }
-
- if (lac != null && cid != null) {
- position.setNetwork(new Network(CellTower.fromLacCid(lac, cid)));
- }
-
- if (event == 20) {
- String rfid = data[data.length - 1];
- if (rfid.matches("0+")) {
- rfid = data[data.length - 2];
- }
- position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid);
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Stl060FrameDecoder.java b/src/org/traccar/protocol/Stl060FrameDecoder.java
deleted file mode 100644
index 455a869ee..000000000
--- a/src/org/traccar/protocol/Stl060FrameDecoder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.traccar.CharacterDelimiterFrameDecoder;
-
-public class Stl060FrameDecoder extends CharacterDelimiterFrameDecoder {
-
- public Stl060FrameDecoder(int maxFrameLength) {
- super(maxFrameLength, '#');
- }
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- ChannelBuffer result = (ChannelBuffer) super.decode(ctx, channel, buf);
-
- if (result != null) {
-
- int index = result.indexOf(result.readerIndex(), result.writerIndex(), (byte) '$');
- if (index == -1) {
- return result;
- } else {
- result.skipBytes(index);
- return result.readBytes(result.readableBytes());
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Stl060Protocol.java b/src/org/traccar/protocol/Stl060Protocol.java
deleted file mode 100644
index 6fe2c5181..000000000
--- a/src/org/traccar/protocol/Stl060Protocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.
- * 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.TrackerServer;
-
-import java.util.List;
-
-public class Stl060Protocol extends BaseProtocol {
-
- public Stl060Protocol() {
- super("stl060");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Stl060FrameDecoder(1024));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Stl060ProtocolDecoder(Stl060Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
deleted file mode 100644
index 26817a5c8..000000000
--- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class Stl060ProtocolDecoder extends BaseProtocolDecoder {
-
- public Stl060ProtocolDecoder(Stl060Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .any()
- .text("$1,")
- .number("(d+),") // imei
- .text("D001,") // type
- .expression("[^,]*,") // vehicle
- .number("(dd)/(dd)/(dd),") // date (dd/mm/yy)
- .number("(dd):(dd):(dd),") // time (hh:mm:ss)
- .number("(dd)(dd).?(d+)([NS]),") // latitude
- .number("(ddd)(dd).?(d+)([EW]),") // longitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .groupBegin()
- .number("(d+),") // odometer
- .number("(d+),") // Ignition
- .number("(d+),") // di1
- .number("(d+),") // di2
- .number("(d+),") // fuel
- .or()
- .expression("([01]),") // charging
- .expression("([01]),") // ignition
- .expression("0,0,") // reserved
- .number("(d+),") // di
- .expression("([^,]+),") // rfid
- .number("(d+),") // odometer
- .number("(d+),") // temperature
- .number("(d+),") // fuel
- .expression("([01]),") // accelerometer
- .expression("([01]),") // do1
- .expression("([01]),") // do2
- .groupEnd()
- .expression("([AV])") // validity
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- // Old format
- if (parser.hasNext(5)) {
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_INPUT, parser.nextInt(0) + parser.nextInt(0) << 1);
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
- }
-
- // New format
- if (parser.hasNext(10)) {
- position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_INPUT, parser.nextInt(0));
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
- position.set(Position.KEY_ODOMETER, parser.nextInt(0));
- position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
- position.set(Position.KEY_ACCELERATION, parser.nextInt(0) == 1);
- position.set(Position.KEY_OUTPUT, parser.nextInt(0) + parser.nextInt(0) << 1);
- }
-
- position.setValid(parser.next().equals("A"));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/SuntechProtocol.java b/src/org/traccar/protocol/SuntechProtocol.java
deleted file mode 100644
index 03a979d04..000000000
--- a/src/org/traccar/protocol/SuntechProtocol.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.
- * 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 org.traccar.model.Command;
-
-import java.util.List;
-
-public class SuntechProtocol extends BaseProtocol {
-
- public SuntechProtocol() {
- super("suntech");
- setSupportedDataCommands(
- Command.TYPE_OUTPUT_CONTROL,
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_ALARM_ARM,
- Command.TYPE_ALARM_DISARM);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new CharacterDelimiterFrameDecoder(1024, '\r'));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new SuntechProtocolEncoder());
- pipeline.addLast("objectDecoder", new SuntechProtocolDecoder(SuntechProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
deleted file mode 100644
index 6dfc6f77f..000000000
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.TimeZone;
-
-public class SuntechProtocolDecoder extends BaseProtocolDecoder {
-
- private int protocolType;
- private boolean hbm;
- private boolean includeAdc;
- private boolean includeTemp;
-
- public SuntechProtocolDecoder(SuntechProtocol protocol) {
- super(protocol);
-
- protocolType = Context.getConfig().getInteger(getProtocolName() + ".protocolType");
- hbm = Context.getConfig().getBoolean(getProtocolName() + ".hbm");
- includeAdc = Context.getConfig().getBoolean(getProtocolName() + ".includeAdc");
- includeTemp = Context.getConfig().getBoolean(getProtocolName() + ".includeTemp");
- }
-
- public void setProtocolType(int protocolType) {
- this.protocolType = protocolType;
- }
-
- public void setHbm(boolean hbm) {
- this.hbm = hbm;
- }
-
- public void setIncludeAdc(boolean includeAdc) {
- this.includeAdc = includeAdc;
- }
-
- public void setIncludeTemp(boolean includeTemp) {
- this.includeTemp = includeTemp;
- }
-
- private Position decode9(
- Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException {
- int index = 1;
-
- String type = values[index++];
-
- if (!type.equals("Location") && !type.equals("Emergency") && !type.equals("Alert")) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (type.equals("Emergency") || type.equals("Alert")) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
-
- if (!type.equals("Alert") || protocolType == 0) {
- position.set(Position.KEY_VERSION_FW, values[index++]);
- }
-
- DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- position.setTime(dateFormat.parse(values[index++] + values[index++]));
-
- if (protocolType == 1) {
- index += 1; // cell
- }
-
- position.setLatitude(Double.parseDouble(values[index++]));
- position.setLongitude(Double.parseDouble(values[index++]));
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
- position.setCourse(Double.parseDouble(values[index++]));
-
- position.setValid(values[index++].equals("1"));
-
- if (protocolType == 1) {
- position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++]));
- }
-
- return position;
- }
-
- private String decodeEmergency(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_SOS;
- case 2:
- return Position.ALARM_PARKING;
- case 3:
- return Position.ALARM_POWER_CUT;
- case 5:
- case 6:
- return Position.ALARM_DOOR;
- case 7:
- return Position.ALARM_MOVEMENT;
- case 8:
- return Position.ALARM_SHOCK;
- default:
- return null;
- }
- }
-
- private String decodeAlert(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_OVERSPEED;
- case 5:
- return Position.ALARM_GEOFENCE_EXIT;
- case 6:
- return Position.ALARM_GEOFENCE_ENTER;
- case 14:
- return Position.ALARM_LOW_BATTERY;
- case 15:
- return Position.ALARM_SHOCK;
- case 16:
- return Position.ALARM_ACCIDENT;
- case 46:
- return Position.ALARM_ACCELERATION;
- case 47:
- return Position.ALARM_BRAKING;
- case 48:
- return Position.ALARM_ACCIDENT;
- case 50:
- return Position.ALARM_JAMMING;
- default:
- return null;
- }
- }
-
- private Position decode235(
- Channel channel, SocketAddress remoteAddress, String protocol, String[] values) throws ParseException {
- int index = 0;
-
- String type = values[index++].substring(5);
-
- if (!type.equals("STT") && !type.equals("EMG") && !type.equals("EVT") && !type.equals("ALT")) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_TYPE, type);
-
- if (protocol.equals("ST300") || protocol.equals("ST500")) {
- index += 1; // model
- }
-
- position.set(Position.KEY_VERSION_FW, values[index++]);
-
- DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- position.setTime(dateFormat.parse(values[index++] + values[index++]));
-
- if (!protocol.equals("ST500")) {
- index += 1; // cell
- }
-
- position.setLatitude(Double.parseDouble(values[index++]));
- position.setLongitude(Double.parseDouble(values[index++]));
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
- position.setCourse(Double.parseDouble(values[index++]));
-
- position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++]));
-
- position.setValid(values[index++].equals("1"));
-
- position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++]));
- position.set(Position.KEY_POWER, Double.parseDouble(values[index++]));
-
- String io = values[index++];
- if (io.length() == 6) {
- position.set(Position.KEY_IGNITION, io.charAt(0) == '1');
- position.set(Position.PREFIX_IN + 1, io.charAt(1) == '1');
- position.set(Position.PREFIX_IN + 2, io.charAt(2) == '1');
- position.set(Position.PREFIX_IN + 3, io.charAt(3) == '1');
- position.set(Position.PREFIX_OUT + 1, io.charAt(4) == '1');
- position.set(Position.PREFIX_OUT + 2, io.charAt(5) == '1');
- }
-
- switch (type) {
- case "STT":
- index += 1; // mode
- position.set(Position.KEY_INDEX, Integer.parseInt(values[index++]));
- break;
- case "EMG":
- position.set(Position.KEY_ALARM, decodeEmergency(Integer.parseInt(values[index++])));
- break;
- case "EVT":
- position.set(Position.KEY_EVENT, Integer.parseInt(values[index++]));
- break;
- case "ALT":
- position.set(Position.KEY_ALARM, decodeAlert(Integer.parseInt(values[index++])));
- break;
- default:
- break;
- }
-
- if (hbm) {
-
- if (index < values.length) {
- position.set(Position.KEY_HOURS, Integer.parseInt(values[index++]));
- }
-
- if (index < values.length) {
- position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++]));
- }
-
- if (index < values.length && values[index++].equals("0")) {
- position.set(Position.KEY_ARCHIVE, true);
- }
-
- if (includeAdc) {
- position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++]));
- position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++]));
- position.set(Position.PREFIX_ADC + 3, Double.parseDouble(values[index++]));
- }
-
- if (values.length - index >= 2) {
- String driverUniqueId = values[index++];
- if (values[index++].equals("1") && !driverUniqueId.isEmpty()) {
- position.set(Position.KEY_DRIVER_UNIQUE_ID, driverUniqueId);
- }
- }
-
- if (includeTemp) {
- for (int i = 1; i <= 3; i++) {
- String temperature = values[index++];
- String value = temperature.substring(temperature.indexOf(':') + 1);
- if (!value.isEmpty()) {
- position.set(Position.PREFIX_TEMP + i, Double.parseDouble(value));
- }
- }
-
- }
-
- }
-
- return position;
- }
-
- private Position decodeUniversal(
- Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException {
- int index = 0;
-
- String type = values[index++];
-
- if (!type.equals("STT")) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_TYPE, type);
-
- int mask = Integer.parseInt(values[index++], 16);
-
- if (BitUtil.check(mask, 1)) {
- index += 1; // model
- }
-
- if (BitUtil.check(mask, 2)) {
- position.set(Position.KEY_VERSION_FW, values[index++]);
- }
-
- if (BitUtil.check(mask, 3) && values[index++].equals("0")) {
- position.set(Position.KEY_ARCHIVE, true);
- }
-
- if (BitUtil.check(mask, 4) && BitUtil.check(mask, 5)) {
- DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- position.setTime(dateFormat.parse(values[index++] + values[index++]));
- }
-
- if (BitUtil.check(mask, 6)) {
- index += 1; // cell
- }
-
- if (BitUtil.check(mask, 7)) {
- index += 1; // mcc
- }
-
- if (BitUtil.check(mask, 8)) {
- index += 1; // mnc
- }
-
- if (BitUtil.check(mask, 9)) {
- index += 1; // lac
- }
-
- if (BitUtil.check(mask, 10)) {
- position.set(Position.KEY_RSSI, Integer.parseInt(values[index++]));
- }
-
- if (BitUtil.check(mask, 11)) {
- position.setLatitude(Double.parseDouble(values[index++]));
- }
-
- if (BitUtil.check(mask, 12)) {
- position.setLongitude(Double.parseDouble(values[index++]));
- }
-
- if (BitUtil.check(mask, 13)) {
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
- }
-
- if (BitUtil.check(mask, 14)) {
- position.setCourse(Double.parseDouble(values[index++]));
- }
-
- if (BitUtil.check(mask, 15)) {
- position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++]));
- }
-
- if (BitUtil.check(mask, 16)) {
- position.setValid(values[index++].equals("1"));
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String[] values = ((String) msg).split(";");
-
- if (values[0].length() < 5) {
- return decodeUniversal(channel, remoteAddress, values);
- } else if (values[0].equals("ST910")) {
- return decode9(channel, remoteAddress, values);
- } else {
- return decode235(channel, remoteAddress, values[0].substring(0, 5), values);
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/SuntechProtocolEncoder.java b/src/org/traccar/protocol/SuntechProtocolEncoder.java
deleted file mode 100644
index 5b1c802fa..000000000
--- a/src/org/traccar/protocol/SuntechProtocolEncoder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * 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 SuntechProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "SA200CMD;{%s};02;Reboot\r", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "SA200GTR;{%s};02;\r", Command.KEY_UNIQUE_ID);
- case Command.TYPE_OUTPUT_CONTROL:
- if (command.getAttributes().containsKey(Command.KEY_DATA)) {
- if (command.getAttributes().get(Command.KEY_DATA).equals("1")) {
- return formatCommand(command, "SA200CMD;{%s};02;Enable{%s}\r",
- Command.KEY_UNIQUE_ID, Command.KEY_INDEX);
- } else {
- return formatCommand(command, "SA200CMD;{%s};02;Disable{%s}\r",
- Command.KEY_UNIQUE_ID, Command.KEY_INDEX);
- }
- }
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "SA200CMD;{%s};02;Enable1\r", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "SA200CMD;{%s};02;Disable1\r", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ALARM_ARM:
- return formatCommand(command, "SA200CMD;{%s};02;Enable2\r", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ALARM_DISARM:
- return formatCommand(command, "SA200CMD;{%s};02;Disable2\r", Command.KEY_UNIQUE_ID);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/SupermateProtocol.java b/src/org/traccar/protocol/SupermateProtocol.java
deleted file mode 100644
index c9ae86fc1..000000000
--- a/src/org/traccar/protocol/SupermateProtocol.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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 SupermateProtocol extends BaseProtocol {
-
- public SupermateProtocol() {
- super("supermate");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new SupermateProtocolDecoder(SupermateProtocol.this));
- }
- });
- }
-}
diff --git a/src/org/traccar/protocol/SupermateProtocolDecoder.java b/src/org/traccar/protocol/SupermateProtocolDecoder.java
deleted file mode 100644
index d9b58a7f4..000000000
--- a/src/org/traccar/protocol/SupermateProtocolDecoder.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.ChannelBuffers;
-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.nio.charset.StandardCharsets;
-import java.util.Calendar;
-import java.util.regex.Pattern;
-
-public class SupermateProtocolDecoder extends BaseProtocolDecoder {
-
- public SupermateProtocolDecoder(SupermateProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("d+:") // header
- .number("(d+):") // imei
- .number("d+:").text("*,")
- .number("(d+),") // command id
- .expression("([^,]{2}),") // command
- .expression("([AV]),") // validity
- .number("(xx)(xx)(xx),") // date (yymmdd)
- .number("(xx)(xx)(xx),") // time (hhmmss)
- .number("(x)(x{7}),") // latitude
- .number("(x)(x{7}),") // longitude
- .number("(x{4}),") // speed
- .number("(x{4}),") // course
- .number("(x{12}),") // status
- .number("(x+),") // signal
- .number("(d+),") // power
- .number("(x{4}),") // oil
- .number("(x+)?") // odometer
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- String imei = parser.next();
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set("commandId", parser.next());
- position.set(Position.KEY_COMMAND, parser.next());
-
- position.setValid(parser.next().equals("A"));
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0))
- .setTime(parser.nextHexInt(0), parser.nextHexInt(0), parser.nextHexInt(0));
- position.setTime(dateBuilder.getDate());
-
- if (parser.nextHexInt(0) == 8) {
- position.setLatitude(-parser.nextHexInt(0) / 600000.0);
- } else {
- position.setLatitude(parser.nextHexInt(0) / 600000.0);
- }
-
- if (parser.nextHexInt(0) == 8) {
- position.setLongitude(-parser.nextHexInt(0) / 600000.0);
- } else {
- position.setLongitude(parser.nextHexInt(0) / 600000.0);
- }
-
- position.setSpeed(parser.nextHexInt(0) / 100.0);
- position.setCourse(parser.nextHexInt(0) / 100.0);
-
- position.set(Position.KEY_STATUS, parser.next());
- position.set("signal", parser.next());
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- position.set("oil", parser.nextHexInt(0));
- position.set(Position.KEY_ODOMETER, parser.nextHexInt(0));
-
- if (channel != null) {
- Calendar calendar = Calendar.getInstance();
- String content = String.format("#1:%s:1:*,00000000,UP,%02x%02x%02x,%02x%02x%02x#", imei,
- calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH),
- calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND));
- channel.write(ChannelBuffers.copiedBuffer(content, StandardCharsets.US_ASCII));
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/T55Protocol.java b/src/org/traccar/protocol/T55Protocol.java
deleted file mode 100644
index 402fd46b8..000000000
--- a/src/org/traccar/protocol/T55Protocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.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 T55Protocol extends BaseProtocol {
-
- public T55Protocol() {
- super("t55");
- }
-
- @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 T55ProtocolDecoder(T55Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new T55ProtocolDecoder(T55Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
deleted file mode 100644
index 6b4ee6ebd..000000000
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.jboss.netty.channel.socket.DatagramChannel;
-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.Date;
-import java.util.regex.Pattern;
-
-public class T55ProtocolDecoder extends BaseProtocolDecoder {
-
- public T55ProtocolDecoder(T55Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_GPRMC = new PatternBuilder()
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(d{2,3})(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .expression("[^*]+")
- .text("*")
- .expression("[^,]+")
- .number(",(d+)") // satellites
- .number(",(d+)") // imei
- .expression(",([01])") // ignition
- .number(",(d+)") // fuel
- .number(",(d+)").optional(5) // battery
- .number("((?:,d+)+)?") // parameters
- .any()
- .compile();
-
- private static final Pattern PATTERN_GPGGA = new PatternBuilder()
- .text("$GPGGA,")
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .number("(d+)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(d+)(dd.d+),") // longitude
- .expression("([EW]),")
- .any()
- .compile();
-
- private static final Pattern PATTERN_GPRMA = new PatternBuilder()
- .text("$GPRMA,")
- .expression("([AV]),") // validity
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),,,")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .any()
- .compile();
-
- private static final Pattern PATTERN_TRCCR = new PatternBuilder()
- .text("$TRCCR,")
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd).?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(d+.d+),") // speed
- .number("(d+.d+),") // course
- .number("(-?d+.d+),") // altitude
- .number("(d+.?d*),") // battery
- .any()
- .compile();
-
- private Position position = null;
-
- private Position decodeGprmc(
- DeviceSession deviceSession, String sentence, SocketAddress remoteAddress, Channel channel) {
-
- if (deviceSession != null && channel != null && !(channel instanceof DatagramChannel)) {
- if (Context.getIdentityManager().lookupAttributeBoolean(
- deviceSession.getDeviceId(), getProtocolName() + ".ack", false, true)) {
- channel.write("OK1\r\n");
- }
- }
-
- Parser parser = new Parser(PATTERN_GPRMC, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- if (deviceSession != null) {
- position.setDeviceId(deviceSession.getDeviceId());
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- if (parser.hasNext(5)) {
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_IGNITION, parser.hasNext() && parser.next().equals("1"));
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt());
- }
-
- if (parser.hasNext()) {
- String[] parameters = parser.next().split(",");
- for (int i = 1; i < parameters.length; i++) {
- position.set(Position.PREFIX_IO + i, parameters[i]);
- }
- }
-
- if (deviceSession != null) {
- return position;
- } else {
- this.position = position; // save position
- return null;
- }
- }
-
- private Position decodeGpgga(DeviceSession deviceSession, String sentence) {
-
- Parser parser = new Parser(PATTERN_GPGGA, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setCurrentDate()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- return position;
- }
-
- private Position decodeGprma(DeviceSession deviceSession, String sentence) {
-
- Parser parser = new Parser(PATTERN_GPRMA, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date());
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- return position;
- }
-
- private Position decodeTrccr(DeviceSession deviceSession, String sentence) {
-
- Parser parser = new Parser(PATTERN_TRCCR, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- DeviceSession deviceSession;
-
- if (!sentence.startsWith("$") && sentence.contains("$")) {
- int index = sentence.indexOf("$");
- String id = sentence.substring(0, index);
- if (id.endsWith(",")) {
- id = id.substring(0, id.length() - 1);
- } else if (id.endsWith("/")) {
- id = id.substring(id.indexOf('/') + 1, id.length() - 1);
- }
- deviceSession = getDeviceSession(channel, remoteAddress, id);
- sentence = sentence.substring(index);
- } else {
- deviceSession = getDeviceSession(channel, remoteAddress);
- }
-
- if (sentence.startsWith("$PGID")) {
- getDeviceSession(channel, remoteAddress, sentence.substring(6, sentence.length() - 3));
- } else if (sentence.startsWith("$PCPTI")) {
- getDeviceSession(channel, remoteAddress, sentence.substring(7, sentence.indexOf(",", 7)));
- } else if (sentence.startsWith("IMEI")) {
- getDeviceSession(channel, remoteAddress, sentence.substring(5, sentence.length()));
- } else if (sentence.startsWith("$GPFID")) {
- deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(7, sentence.length()));
- if (deviceSession != null && position != null) {
- Position position = this.position;
- position.setDeviceId(deviceSession.getDeviceId());
- this.position = null;
- return position;
- }
- } else if (sentence.matches("^[0-9A-F]+$")) {
- getDeviceSession(channel, remoteAddress, sentence);
- } else if (sentence.startsWith("$GPRMC")) {
- return decodeGprmc(deviceSession, sentence, remoteAddress, channel);
- } else if (sentence.startsWith("$GPGGA") && deviceSession != null) {
- return decodeGpgga(deviceSession, sentence);
- } else if (sentence.startsWith("$GPRMA") && deviceSession != null) {
- return decodeGprma(deviceSession, sentence);
- } else if (sentence.startsWith("$TRCCR") && deviceSession != null) {
- return decodeTrccr(deviceSession, sentence);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/T800xProtocol.java b/src/org/traccar/protocol/T800xProtocol.java
deleted file mode 100644
index 830ff4de6..000000000
--- a/src/org/traccar/protocol/T800xProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class T800xProtocol extends BaseProtocol {
-
- public T800xProtocol() {
- super("t800x");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 3, 2, -5, 0));
- pipeline.addLast("objectEncoder", new T800xProtocolEncoder());
- pipeline.addLast("objectDecoder", new T800xProtocolDecoder(T800xProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java
deleted file mode 100644
index 6430b1344..000000000
--- a/src/org/traccar/protocol/T800xProtocolDecoder.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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.
- * 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.BcdUtil;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.ByteOrder;
-
-public class T800xProtocolDecoder extends BaseProtocolDecoder {
-
- public T800xProtocolDecoder(T800xProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_LOGIN = 0x01;
- public static final int MSG_GPS = 0x02;
- public static final int MSG_HEARTBEAT = 0x03;
- public static final int MSG_ALARM = 0x04;
- public static final int MSG_COMMAND = 0x81;
-
- private static float readSwappedFloat(ChannelBuffer buf) {
- byte[] bytes = new byte[4];
- buf.readBytes(bytes);
- return ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes).readFloat();
- }
-
- private void sendResponse(Channel channel, int type, ChannelBuffer imei) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(15);
- response.writeByte(0x23);
- response.writeByte(0x23); // header
- response.writeByte(type);
- response.writeShort(response.capacity()); // length
- response.writeShort(0x0001); // index
- response.writeBytes(imei);
- channel.write(response);
- }
- }
-
- private String decodeAlarm(short value) {
- switch (value) {
- case 3:
- return Position.ALARM_SOS;
- case 4:
- return Position.ALARM_OVERSPEED;
- case 5:
- return Position.ALARM_GEOFENCE_ENTER;
- case 6:
- return Position.ALARM_GEOFENCE_EXIT;
- case 8:
- case 10:
- return Position.ALARM_VIBRATION;
- default:
- break;
- }
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2);
- int type = buf.readUnsignedByte();
- buf.readUnsignedShort(); // length
- int index = buf.readUnsignedShort();
- ChannelBuffer imei = buf.readBytes(8);
-
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, ChannelBuffers.hexDump(imei).substring(1));
- if (deviceSession == null) {
- return null;
- }
-
- if (type == MSG_LOGIN || type == MSG_ALARM || type == MSG_HEARTBEAT) {
- sendResponse(channel, type, imei);
- }
-
- if (type == MSG_GPS || type == MSG_ALARM) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_INDEX, index);
-
- buf.readUnsignedShort(); // acc on interval
- buf.readUnsignedShort(); // acc off interval
- buf.readUnsignedByte(); // angle compensation
- buf.readUnsignedShort(); // distance compensation
- buf.readUnsignedShort(); // speed alarm
-
- int locationStatus = buf.readUnsignedByte();
-
- buf.readUnsignedByte(); // gsensor manager status
- buf.readUnsignedByte(); // other flags
- buf.readUnsignedByte(); // heartbeat
- buf.readUnsignedByte(); // relay status
- buf.readUnsignedShort(); // drag alarm setting
-
- int io = buf.readUnsignedShort();
- position.set(Position.KEY_IGNITION, BitUtil.check(io, 14));
- position.set("ac", BitUtil.check(io, 13));
-
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
-
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
-
- buf.readUnsignedByte(); // reserved
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- int battery = BcdUtil.readInteger(buf, 2);
- if (battery == 0) {
- battery = 100;
- }
- position.set(Position.KEY_BATTERY, battery);
-
- DateBuilder dateBuilder = new DateBuilder()
- .setYear(BcdUtil.readInteger(buf, 2))
- .setMonth(BcdUtil.readInteger(buf, 2))
- .setDay(BcdUtil.readInteger(buf, 2))
- .setHour(BcdUtil.readInteger(buf, 2))
- .setMinute(BcdUtil.readInteger(buf, 2))
- .setSecond(BcdUtil.readInteger(buf, 2));
-
- if (BitUtil.check(locationStatus, 6)) {
-
- position.setValid(!BitUtil.check(locationStatus, 7));
- position.setTime(dateBuilder.getDate());
- position.setAltitude(readSwappedFloat(buf));
- position.setLongitude(readSwappedFloat(buf));
- position.setLatitude(readSwappedFloat(buf));
- position.setSpeed(UnitsConverter.knotsFromKph(
- BcdUtil.readInteger(buf, 4) * 0.1));
- position.setCourse(buf.readUnsignedShort());
-
- } else {
-
- getLastLocation(position, dateBuilder.getDate());
-
- byte[] array = new byte[16];
- buf.readBytes(array);
- ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array);
-
- position.setNetwork(new Network(CellTower.from(
- swapped.readUnsignedShort(), swapped.readUnsignedShort(),
- swapped.readUnsignedShort(), swapped.readUnsignedShort())));
-
- // two more cell towers
-
- }
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/T800xProtocolEncoder.java b/src/org/traccar/protocol/T800xProtocolEncoder.java
deleted file mode 100644
index 6ed5dbccd..000000000
--- a/src/org/traccar/protocol/T800xProtocolEncoder.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 javax.xml.bind.DatatypeConverter;
-import java.nio.charset.StandardCharsets;
-
-public class T800xProtocolEncoder extends BaseProtocolEncoder {
-
- public static final int MODE_SETTING = 0x01;
- public static final int MODE_BROADCAST = 0x02;
- public static final int MODE_FORWARD = 0x03;
-
- private ChannelBuffer encodeContent(Command command, String content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeByte('#');
- buf.writeByte('#');
- buf.writeByte(T800xProtocolDecoder.MSG_COMMAND);
- buf.writeShort(7 + 8 + 1 + content.length());
- buf.writeShort(1); // serial number
- buf.writeBytes(DatatypeConverter.parseHexBinary("0" + getUniqueId(command.getDeviceId())));
- buf.writeByte(MODE_SETTING);
- buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeContent(command, command.getString(Command.KEY_DATA));
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TaipProtocol.java b/src/org/traccar/protocol/TaipProtocol.java
deleted file mode 100644
index cbfc44122..000000000
--- a/src/org/traccar/protocol/TaipProtocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.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 TaipProtocol extends BaseProtocol {
-
- public TaipProtocol() {
- super("taip");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new TaipProtocolDecoder(TaipProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new TaipProtocolDecoder(TaipProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java
deleted file mode 100644
index e7117a5c9..000000000
--- a/src/org/traccar/protocol/TaipProtocolDecoder.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.DateUtil;
-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.Date;
-import java.util.regex.Pattern;
-
-public class TaipProtocolDecoder extends BaseProtocolDecoder {
-
- public TaipProtocolDecoder(TaipProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .groupBegin()
- .expression("R[EP]V") // type
- .groupBegin()
- .number("(dd)") // event
- .number("(dddd)") // week
- .number("(d)") // day
- .groupEnd("?")
- .number("(d{5})") // seconds
- .or()
- .expression("(?:RGP|RCQ|RBR)") // type
- .number("(dd)?") // event
- .number("(dd)(dd)(dd)") // date (mmddyy)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .groupEnd()
- .groupBegin()
- .number("([-+]dd)(d{5})") // latitude
- .number("([-+]ddd)(d{5})") // longitude
- .or()
- .number("([-+])(dd)(dd.dddd)") // latitude
- .number("([-+])(ddd)(dd.dddd)") // longitude
- .groupEnd()
- .number("(ddd)") // speed
- .number("(ddd)") // course
- .groupBegin()
- .number("(xx)") // input
- .number("(xx)") // satellites
- .number("(ddd)") // battery
- .number("(x{8})") // odometer
- .number("[01]") // gps power
- .groupEnd("?")
- .any()
- .compile();
-
- private Date getTime(long week, long day, long seconds) {
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(1980, 1, 6)
- .addMillis(((week * 7 + day) * 24 * 60 * 60 + seconds) * 1000);
- return dateBuilder.getDate();
- }
-
- private Date getTime(long seconds) {
- DateBuilder dateBuilder = new DateBuilder(new Date())
- .setTime(0, 0, 0, 0)
- .addMillis(seconds * 1000);
- return DateUtil.correctDay(dateBuilder.getDate());
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- int beginIndex = sentence.indexOf('>');
- if (beginIndex != -1) {
- sentence = sentence.substring(beginIndex + 1);
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- Integer event = null;
-
- if (parser.hasNext(3)) {
- event = parser.nextInt();
- position.setTime(getTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)));
- } else if (parser.hasNext()) {
- position.setTime(getTime(parser.nextInt(0)));
- }
-
- if (parser.hasNext()) {
- event = parser.nextInt();
- }
-
- if (event != null) {
- switch (event) {
- case 22:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
- break;
- case 23:
- position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
- break;
- case 24:
- position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT);
- break;
- case 26:
- case 28:
- position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
- break;
- default:
- position.set(Position.KEY_EVENT, event);
- break;
- }
- }
-
- if (parser.hasNext(6)) {
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
- }
-
- if (parser.hasNext(4)) {
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
- }
- if (parser.hasNext(6)) {
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- }
-
- position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- if (parser.hasNext(4)) {
- position.set(Position.KEY_INPUT, parser.nextHexInt(0));
- position.set(Position.KEY_SATELLITES, parser.nextHexInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0));
- }
-
- position.setValid(true);
-
- String[] attributes = null;
- beginIndex = sentence.indexOf(';');
- if (beginIndex != -1) {
- int endIndex = sentence.indexOf('<', beginIndex);
- if (endIndex == -1) {
- endIndex = sentence.length();
- }
- attributes = sentence.substring(beginIndex, endIndex).split(";");
- }
-
- return decodeAttributes(channel, remoteAddress, position, attributes);
- }
-
- private Position decodeAttributes(
- Channel channel, SocketAddress remoteAddress, Position position, String[] attributes) {
-
- String uniqueId = null;
- DeviceSession deviceSession = null;
- String messageIndex = null;
-
- if (attributes != null) {
- for (String attribute : attributes) {
- int index = attribute.indexOf('=');
- if (index != -1) {
- String key = attribute.substring(0, index).toLowerCase();
- String value = attribute.substring(index + 1);
- switch (key) {
- case "id":
- uniqueId = value;
- deviceSession = getDeviceSession(channel, remoteAddress, value);
- if (deviceSession != null) {
- position.setDeviceId(deviceSession.getDeviceId());
- }
- break;
- case "io":
- position.set(Position.KEY_IGNITION, BitUtil.check(value.charAt(0) - '0', 0));
- position.set(Position.KEY_CHARGE, BitUtil.check(value.charAt(0) - '0', 1));
- position.set(Position.KEY_OUTPUT, value.charAt(1) - '0');
- position.set(Position.KEY_INPUT, value.charAt(2) - '0');
- break;
- case "ix":
- position.set(Position.PREFIX_IO + 1, value);
- break;
- case "ad":
- position.set(Position.PREFIX_ADC + 1, Integer.parseInt(value));
- break;
- case "sv":
- position.set(Position.KEY_SATELLITES, Integer.parseInt(value));
- break;
- case "bl":
- position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.001);
- break;
- case "vo":
- position.set(Position.KEY_ODOMETER, Long.parseLong(value));
- break;
- default:
- position.set(key, value);
- break;
- }
- } else if (attribute.startsWith("#")) {
- messageIndex = attribute;
- }
- }
- }
-
- if (deviceSession != null) {
- if (channel != null) {
- if (messageIndex != null) {
- String response = ">ACK;" + messageIndex + ";ID=" + uniqueId + ";*";
- response += String.format("%02X", Checksum.xor(response)) + "<";
- channel.write(response, remoteAddress);
- } else {
- channel.write(uniqueId, remoteAddress);
- }
- }
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TelicFrameDecoder.java b/src/org/traccar/protocol/TelicFrameDecoder.java
deleted file mode 100644
index 245be28fb..000000000
--- a/src/org/traccar/protocol/TelicFrameDecoder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class TelicFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 4) {
- return null;
- }
-
- long length = buf.getUnsignedInt(buf.readerIndex());
-
- if (length < 1024) {
- if (buf.readableBytes() >= length + 4) {
- buf.readUnsignedInt();
- return buf.readBytes((int) length);
- }
- } else {
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
- if (endIndex >= 0) {
- ChannelBuffer frame = buf.readBytes(endIndex - buf.readerIndex());
- buf.readByte();
- if (frame.readableBytes() > 0) {
- return frame;
- }
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TelicProtocol.java b/src/org/traccar/protocol/TelicProtocol.java
deleted file mode 100644
index fdd0b94c6..000000000
--- a/src/org/traccar/protocol/TelicProtocol.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.
- * 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.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class TelicProtocol extends BaseProtocol {
-
- public TelicProtocol() {
- super("telic");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new TelicFrameDecoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new TelicProtocolDecoder(TelicProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java
deleted file mode 100644
index 2c0d714c6..000000000
--- a/src/org/traccar/protocol/TelicProtocolDecoder.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.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 TelicProtocolDecoder extends BaseProtocolDecoder {
-
- public TelicProtocolDecoder(TelicProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("dddd")
- .number("(d{6}|d{15})") // device id
- .number("(d{1,2}),") // type
- .number("d{12},") // event time
- .number("d+,")
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .groupBegin()
- .number("(ddd)(dd)(dddd),") // longitude
- .number("(dd)(dd)(dddd),") // latitude
- .or()
- .number("(-?d+),") // longitude
- .number("(-?d+),") // latitude
- .groupEnd()
- .number("(d),") // validity
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(d+)?,") // satellites
- .expression("(?:[^,]*,){7}")
- .number("(d+),") // battery
- .any()
- .compile();
-
- private String decodeAlarm(int eventId) {
-
- switch (eventId) {
- case 1:
- return Position.ALARM_POWER_ON;
- case 2:
- return Position.ALARM_SOS;
- case 5:
- return Position.ALARM_POWER_OFF;
- case 7:
- return Position.ALARM_GEOFENCE_ENTER;
- case 8:
- return Position.ALARM_GEOFENCE_EXIT;
- case 22:
- return Position.ALARM_LOW_BATTERY;
- case 25:
- return Position.ALARM_MOVEMENT;
- default:
- return null;
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Parser parser = new Parser(PATTERN, (String) msg);
- 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());
-
- int event = parser.nextInt(0);
- position.set(Position.KEY_EVENT, event);
-
- position.set(Position.KEY_ALARM, decodeAlarm(event));
-
- if (event == 11) {
- position.set(Position.KEY_IGNITION, true);
- } else if (event == 12) {
- position.set(Position.KEY_IGNITION, false);
- }
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- if (parser.hasNext(6)) {
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN));
- }
-
- if (parser.hasNext(2)) {
- position.setLongitude(parser.nextDouble(0) / 10000);
- position.setLatitude(parser.nextDouble(0) / 10000);
- }
-
- position.setValid(parser.nextInt(0) != 1);
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- if (parser.hasNext()) {
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- }
-
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/TeltonikaFrameDecoder.java b/src/org/traccar/protocol/TeltonikaFrameDecoder.java
deleted file mode 100644
index e7313b722..000000000
--- a/src/org/traccar/protocol/TeltonikaFrameDecoder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class TeltonikaFrameDecoder extends FrameDecoder {
-
- private static final int MESSAGE_MINIMUM_LENGTH = 12;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- // Check minimum length
- if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
- return null;
- }
-
- // Read packet
- int length = buf.getUnsignedShort(buf.readerIndex());
- if (length > 0) {
- if (buf.readableBytes() >= (length + 2)) {
- return buf.readBytes(length + 2);
- }
- } else {
- int dataLength = buf.getInt(buf.readerIndex() + 4);
- if (buf.readableBytes() >= (dataLength + 12)) {
- return buf.readBytes(dataLength + 12);
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TeltonikaProtocol.java b/src/org/traccar/protocol/TeltonikaProtocol.java
deleted file mode 100644
index d0177da97..000000000
--- a/src/org/traccar/protocol/TeltonikaProtocol.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class TeltonikaProtocol extends BaseProtocol {
-
- public TeltonikaProtocol() {
- super("teltonika");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new TeltonikaFrameDecoder());
- pipeline.addLast("objectEncoder", new TeltonikaProtocolEncoder());
- pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this, false));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectEncoder", new TeltonikaProtocolEncoder());
- pipeline.addLast("objectDecoder", new TeltonikaProtocolDecoder(TeltonikaProtocol.this, true));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
deleted file mode 100644
index 80f0045d5..000000000
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
-
- private boolean connectionless;
- private boolean extended;
-
- public void setExtended(boolean extended) {
- this.extended = extended;
- }
-
- public TeltonikaProtocolDecoder(TeltonikaProtocol protocol, boolean connectionless) {
- super(protocol);
- this.connectionless = connectionless;
- this.extended = Context.getConfig().getBoolean(getProtocolName() + ".extended");
- }
-
- private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- int length = buf.readUnsignedShort();
- String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.directBuffer(1);
- if (deviceSession != null) {
- response.writeByte(1);
- } else {
- response.writeByte(0);
- }
- channel.write(response);
- }
- return deviceSession;
- }
-
- public static final int CODEC_GH3000 = 0x07;
- public static final int CODEC_FM4X00 = 0x08;
- public static final int CODEC_12 = 0x0C;
-
- private void decodeSerial(Position position, ChannelBuffer buf) {
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_TYPE, buf.readUnsignedByte());
-
- position.set(Position.KEY_RESULT, buf.readBytes(buf.readInt()).toString(StandardCharsets.US_ASCII));
-
- }
-
- private long readValue(ChannelBuffer buf, int length, boolean signed) {
- switch (length) {
- case 1:
- return signed ? buf.readByte() : buf.readUnsignedByte();
- case 2:
- return signed ? buf.readShort() : buf.readUnsignedShort();
- case 4:
- return signed ? buf.readInt() : buf.readUnsignedInt();
- default:
- return buf.readLong();
- }
- }
-
- private void decodeOtherParameter(Position position, int id, ChannelBuffer buf, int length) {
- switch (id) {
- case 1:
- case 2:
- case 3:
- case 4:
- position.set("di" + id, readValue(buf, length, false));
- break;
- case 9:
- position.set(Position.PREFIX_ADC + 1, readValue(buf, length, false));
- break;
- case 17:
- position.set("axisX", readValue(buf, length, true));
- break;
- case 18:
- position.set("axisY", readValue(buf, length, true));
- break;
- case 19:
- position.set("axisZ", readValue(buf, length, true));
- break;
- case 21:
- position.set(Position.KEY_RSSI, readValue(buf, length, false));
- break;
- case 66:
- position.set(Position.KEY_POWER, readValue(buf, length, false) * 0.001);
- break;
- case 67:
- position.set(Position.KEY_BATTERY, readValue(buf, length, false) * 0.001);
- break;
- case 72:
- position.set(Position.PREFIX_TEMP + 1, readValue(buf, length, true) * 0.1);
- break;
- case 73:
- position.set(Position.PREFIX_TEMP + 2, readValue(buf, length, true) * 0.1);
- break;
- case 74:
- position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1);
- break;
- case 78:
- position.set(Position.KEY_DRIVER_UNIQUE_ID, String.format("%016X", readValue(buf, length, false)));
- break;
- case 80:
- position.set("workMode", readValue(buf, length, false));
- break;
- case 179:
- position.set(Position.PREFIX_OUT + 1, readValue(buf, length, false) == 1);
- break;
- case 180:
- position.set(Position.PREFIX_OUT + 2, readValue(buf, length, false) == 1);
- break;
- case 181:
- position.set(Position.KEY_PDOP, readValue(buf, length, false) * 0.1);
- break;
- case 182:
- position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1);
- break;
- case 239:
- position.set(Position.KEY_IGNITION, readValue(buf, length, false) == 1);
- break;
- case 240:
- position.set(Position.KEY_MOTION, readValue(buf, length, false) == 1);
- break;
- case 241:
- position.set(Position.KEY_OPERATOR, readValue(buf, length, false));
- break;
- default:
- position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
- break;
- }
- }
-
- private void decodeGh3000Parameter(Position position, int id, ChannelBuffer buf, int length) {
- switch (id) {
- case 1:
- position.set(Position.KEY_BATTERY_LEVEL, readValue(buf, length, false));
- break;
- case 2:
- position.set("usbConnected", readValue(buf, length, false) == 1);
- break;
- case 5:
- position.set("uptime", readValue(buf, length, false));
- break;
- case 20:
- position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1);
- break;
- case 21:
- position.set(Position.KEY_VDOP, readValue(buf, length, false) * 0.1);
- break;
- case 22:
- position.set(Position.KEY_PDOP, readValue(buf, length, false) * 0.1);
- break;
- case 67:
- position.set(Position.KEY_BATTERY, readValue(buf, length, false) * 0.001);
- break;
- case 221:
- position.set("button", readValue(buf, length, false));
- break;
- case 222:
- if (readValue(buf, length, false) == 1) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
- break;
- case 240:
- position.set(Position.KEY_MOTION, readValue(buf, length, false) == 1);
- break;
- case 244:
- position.set(Position.KEY_ROAMING, readValue(buf, length, false) == 1);
- break;
- default:
- position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
- break;
- }
- }
-
- private void decodeParameter(Position position, int id, ChannelBuffer buf, int length, int codec) {
- if (codec == CODEC_GH3000) {
- decodeGh3000Parameter(position, id, buf, length);
- } else {
- decodeOtherParameter(position, id, buf, length);
- }
- }
-
- private void decodeNetwork(Position position) {
- long cid = position.getLong(Position.PREFIX_IO + 205);
- int lac = position.getInteger(Position.PREFIX_IO + 206);
- if (cid != 0 && lac != 0) {
- CellTower cellTower = CellTower.fromLacCid(lac, cid);
- long operator = position.getInteger(Position.KEY_OPERATOR);
- if (operator != 0) {
- cellTower.setOperator(operator);
- }
- position.setNetwork(new Network(cellTower));
- }
- }
-
- private void decodeLocation(Position position, ChannelBuffer buf, int codec) {
-
- int globalMask = 0x0f;
-
- if (codec == CODEC_GH3000) {
-
- long time = buf.readUnsignedInt() & 0x3fffffff;
- time += 1167609600; // 2007-01-01 00:00:00
-
- globalMask = buf.readUnsignedByte();
- if (BitUtil.check(globalMask, 0)) {
-
- position.setTime(new Date(time * 1000));
-
- int locationMask = buf.readUnsignedByte();
-
- if (BitUtil.check(locationMask, 0)) {
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- }
-
- if (BitUtil.check(locationMask, 1)) {
- position.setAltitude(buf.readUnsignedShort());
- }
-
- if (BitUtil.check(locationMask, 2)) {
- position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
- }
-
- if (BitUtil.check(locationMask, 3)) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- }
-
- if (BitUtil.check(locationMask, 4)) {
- int satellites = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, satellites);
- position.setValid(satellites >= 3);
- }
-
- if (BitUtil.check(locationMask, 5)) {
- CellTower cellTower = CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort());
-
- if (BitUtil.check(locationMask, 6)) {
- cellTower.setSignalStrength((int) buf.readUnsignedByte());
- }
-
- if (BitUtil.check(locationMask, 7)) {
- cellTower.setOperator(buf.readUnsignedInt());
- }
-
- position.setNetwork(new Network(cellTower));
-
- } else {
- if (BitUtil.check(locationMask, 6)) {
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- }
- if (BitUtil.check(locationMask, 7)) {
- position.set(Position.KEY_OPERATOR, buf.readUnsignedInt());
- }
- }
-
- } else {
-
- getLastLocation(position, new Date(time * 1000));
-
- }
-
- } else {
-
- position.setTime(new Date(buf.readLong()));
-
- position.set("priority", buf.readUnsignedByte());
-
- position.setLongitude(buf.readInt() / 10000000.0);
- position.setLatitude(buf.readInt() / 10000000.0);
- position.setAltitude(buf.readShort());
- position.setCourse(buf.readUnsignedShort());
-
- int satellites = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, satellites);
-
- position.setValid(satellites != 0);
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
-
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
-
- buf.readUnsignedByte(); // total IO data records
-
- }
-
- // Read 1 byte data
- if (BitUtil.check(globalMask, 1)) {
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 1, codec);
- }
- }
-
- // Read 2 byte data
- if (BitUtil.check(globalMask, 2)) {
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 2, codec);
- }
- }
-
- // Read 4 byte data
- if (BitUtil.check(globalMask, 3)) {
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 4, codec);
- }
- }
-
- // Read 8 byte data
- if (codec == CODEC_FM4X00) {
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- decodeOtherParameter(position, buf.readUnsignedByte(), buf, 8);
- }
- }
-
- // Read 16 byte data
- if (extended) {
- int cnt = buf.readUnsignedByte();
- for (int j = 0; j < cnt; j++) {
- position.set(Position.PREFIX_IO + buf.readUnsignedByte(), ChannelBuffers.hexDump(buf.readBytes(16)));
- }
- }
-
- decodeNetwork(position);
-
- }
-
- private List<Position> parseData(
- Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int locationPacketId, String... imei) {
- List<Position> positions = new LinkedList<>();
-
- if (!connectionless) {
- buf.readUnsignedInt(); // data length
- }
-
- int codec = buf.readUnsignedByte();
- int count = buf.readUnsignedByte();
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
-
- if (deviceSession == null) {
- return null;
- }
-
- for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (codec == CODEC_12) {
- decodeSerial(position, buf);
- } else {
- decodeLocation(position, buf, codec);
- }
-
- positions.add(position);
- }
-
- if (channel != null) {
- if (connectionless) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeShort(5);
- response.writeShort(0);
- response.writeByte(0x01);
- response.writeByte(locationPacketId);
- response.writeByte(count);
- channel.write(response, remoteAddress);
- } else {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeInt(count);
- channel.write(response);
- }
- }
-
- return positions;
- }
-
- @Override
- protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (connectionless) {
- return decodeUdp(channel, remoteAddress, buf);
- } else {
- return decodeTcp(channel, remoteAddress, buf);
- }
- }
-
- private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
-
- if (buf.getUnsignedShort(0) > 0) {
- parseIdentification(channel, remoteAddress, buf);
- } else {
- buf.skipBytes(4);
- return parseData(channel, remoteAddress, buf, 0);
- }
-
- return null;
- }
-
- private Object decodeUdp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
-
- buf.readUnsignedShort(); // length
- buf.readUnsignedShort(); // packet id
- buf.readUnsignedByte(); // packet type
- int locationPacketId = buf.readUnsignedByte();
- String imei = buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII);
-
- return parseData(channel, remoteAddress, buf, locationPacketId, imei);
-
- }
-
-}
diff --git a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java b/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
deleted file mode 100644
index fd6eae744..000000000
--- a/src/org/traccar/protocol/TeltonikaProtocolEncoder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.Checksum;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-import java.nio.charset.StandardCharsets;
-
-public class TeltonikaProtocolEncoder extends BaseProtocolEncoder {
-
- private ChannelBuffer encodeContent(String content) {
-
- ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
-
- buf.writeInt(0);
- buf.writeInt(content.length() + 10);
- buf.writeByte(TeltonikaProtocolDecoder.CODEC_12);
- buf.writeByte(1); // quantity
- buf.writeByte(5); // type
- buf.writeInt(content.length() + 2);
- buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
- buf.writeByte('\r');
- buf.writeByte('\n');
- buf.writeByte(1); // quantity
- buf.writeInt(Checksum.crc16(Checksum.CRC16_IBM, buf.toByteBuffer(8, buf.writerIndex() - 8)));
-
- return buf;
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return encodeContent(command.getString(Command.KEY_DATA));
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/ThinkRaceProtocol.java b/src/org/traccar/protocol/ThinkRaceProtocol.java
deleted file mode 100644
index 98f43e2e3..000000000
--- a/src/org/traccar/protocol/ThinkRaceProtocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class ThinkRaceProtocol extends BaseProtocol {
-
- public ThinkRaceProtocol() {
- super("thinkrace");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2 + 12 + 1 + 1, 2, 2, 0));
- pipeline.addLast("objectDecoder", new ThinkRaceProtocolDecoder(ThinkRaceProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
deleted file mode 100644
index 4a97fa1a1..000000000
--- a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-public class ThinkRaceProtocolDecoder extends BaseProtocolDecoder {
-
- public ThinkRaceProtocolDecoder(ThinkRaceProtocol protocol) {
- super(protocol);
- }
-
- public static final int MSG_LOGIN = 0x80;
- public static final int MSG_GPS = 0x90;
-
- private static double convertCoordinate(long raw, boolean negative) {
- long degrees = raw / 1000000;
- double minutes = (raw % 1000000) * 0.0001;
- double result = degrees + minutes / 60;
- if (negative) {
- result = -result;
- }
- return result;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- ChannelBuffer id = buf.readBytes(12);
- buf.readUnsignedByte(); // separator
- int type = buf.readUnsignedByte();
- buf.readUnsignedShort(); // length
-
- if (type == MSG_LOGIN) {
-
- int command = buf.readUnsignedByte(); // 0x00 - heartbeat
-
- if (command == 0x01) {
- String imei = buf.toString(buf.readerIndex(), 15, StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession != null && channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(0x48); response.writeByte(0x52); // header
- response.writeBytes(id);
- response.writeByte(0x2c); // separator
- response.writeByte(type);
- response.writeShort(0x0002); // length
- response.writeShort(0x8000);
- response.writeShort(0x0000); // checksum
- channel.write(response);
- }
- }
-
- } else if (type == MSG_GPS) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- int flags = buf.readUnsignedByte();
-
- position.setValid(true);
- position.setLatitude(convertCoordinate(buf.readUnsignedInt(), !BitUtil.check(flags, 0)));
- position.setLongitude(convertCoordinate(buf.readUnsignedInt(), !BitUtil.check(flags, 1)));
-
- position.setSpeed(buf.readUnsignedByte());
- position.setCourse(buf.readUnsignedByte());
-
- position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tk102Protocol.java b/src/org/traccar/protocol/Tk102Protocol.java
deleted file mode 100644
index 962f2401b..000000000
--- a/src/org/traccar/protocol/Tk102Protocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class Tk102Protocol extends BaseProtocol {
-
- public Tk102Protocol() {
- super("tk102");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- 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
deleted file mode 100644
index 41d5b7436..000000000
--- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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.
- * 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.helper.Parser;
-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 {
-
- public Tk102ProtocolDecoder(Tk102Protocol protocol) {
- 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("[A-Z]+")
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .expression("([AV])") // validity
- .number("(dd)(dd.dddd)([NS])") // latitude
- .number("(ddd)(dd.dddd)([EW])") // longitude
- .number("(ddd.ddd)") // speed
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any()
- .text(")")
- .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 {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(1); // header
- int type = buf.readUnsignedByte();
- ChannelBuffer dataSequence = buf.readBytes(10);
- int length = buf.readUnsignedByte();
-
- if (type == MSG_LOGIN_REQUEST || type == MSG_LOGIN_REQUEST_2) {
-
- 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);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, buf.readBytes(length).toString(StandardCharsets.US_ASCII));
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java
deleted file mode 100644
index 07a68e2d8..000000000
--- a/src/org/traccar/protocol/Tk103Protocol.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2017 Christoph Krey (c@ckrey.de)
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.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 org.traccar.model.Command;
-
-import java.util.List;
-
-public class Tk103Protocol extends BaseProtocol {
-
- public Tk103Protocol() {
- super("tk103");
- setSupportedDataCommands(
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_POSITION_PERIODIC,
- Command.TYPE_POSITION_STOP,
- Command.TYPE_GET_VERSION,
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_SET_ODOMETER,
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new Tk103ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(Tk103Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new Tk103ProtocolEncoder());
- pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(Tk103Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
deleted file mode 100644
index be3def453..000000000
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
-
- private boolean decodeLow;
-
- public Tk103ProtocolDecoder(Tk103Protocol protocol) {
- super(protocol);
- decodeLow = Context.getConfig().getBoolean(getProtocolName() + ".decodeLow");
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(d+)(,)?") // device id
- .expression("(.{4}),?") // command
- .number("(d*)")
- .number("(dd)(dd)(dd),?") // date (mmddyy if comma-delimited, otherwise yyddmm)
- .expression("([AV]),?") // validity
- .number("(d+)(dd.d+)") // latitude
- .expression("([NS]),?")
- .number("(d+)(dd.d+)") // longitude
- .expression("([EW]),?")
- .number("(d+.d)(?:d*,)?") // speed
- .number("(dd)(dd)(dd),?") // time (hhmmss)
- .number("(d+.?d{1,2}),?") // course
- .groupBegin()
- .number("([01])") // charge
- .number("([01])") // ignition
- .number("(x)") // io
- .number("(x)") // io
- .number("(x)") // io
- .number("(xxx),?") // fuel
- .groupEnd("?")
- .number("(?:L(x+))?") // odometer
- .any()
- .number("([+-]ddd.d)?") // temperature
- .text(")").optional()
- .compile();
-
- private static final Pattern PATTERN_BATTERY = new PatternBuilder()
- .number("(d+),") // device id
- .text("ZC20,")
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("d+,") // battery level
- .number("(d+),") // battery voltage
- .number("(d+),") // power voltage
- .number("d+") // installed
- .compile();
-
- private static final Pattern PATTERN_NETWORK = new PatternBuilder()
- .number("(d{12})") // device id
- .text("BZ00,")
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(x+),") // lac
- .number("(x+),") // cid
- .any()
- .compile();
-
- private String decodeAlarm(int value) {
- switch (value) {
- case 1:
- return Position.ALARM_ACCIDENT;
- case 2:
- return Position.ALARM_SOS;
- case 3:
- return Position.ALARM_VIBRATION;
- case 4:
- return Position.ALARM_LOW_SPEED;
- case 5:
- return Position.ALARM_OVERSPEED;
- case 6:
- return Position.ALARM_GEOFENCE_EXIT;
- default:
- return null;
- }
- }
-
- private void decodeType(Position position, String type, String data) {
- switch (type) {
- case "BO01":
- position.set(Position.KEY_ALARM, decodeAlarm(data.charAt(0) - '0'));
- break;
- case "ZC11":
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- break;
- case "ZC12":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "ZC13":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "ZC15":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "ZC16":
- position.set(Position.KEY_IGNITION, false);
- break;
- case "ZC17":
- position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
- break;
- case "ZC25":
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case "ZC26":
- position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
- break;
- case "ZC27":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- default:
- break;
- }
- }
-
- private Position decodeBattery(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_BATTERY, 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());
-
- getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- int battery = parser.nextInt(0);
- if (battery != 65535) {
- position.set(Position.KEY_BATTERY, battery * 0.01);
- }
-
- int power = parser.nextInt(0);
- if (power != 65535) {
- position.set(Position.KEY_POWER, power * 0.1);
- }
-
- return position;
- }
-
- private Position decodeNetwork(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_NETWORK, 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());
-
- getLastLocation(position, null);
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
-
- return position;
- }
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- int beginIndex = sentence.indexOf('(');
- if (beginIndex != -1) {
- sentence = sentence.substring(beginIndex + 1);
- }
-
- if (channel != null) {
- String id = sentence.substring(0, 12);
- String type = sentence.substring(12, 16);
- if (type.equals("BP00")) {
- channel.write("(" + id + "AP01HSO)");
- return null;
- } else if (type.equals("BP05")) {
- channel.write("(" + id + "AP05)");
- }
- }
-
- if (sentence.contains("ZC20")) {
- return decodeBattery(channel, remoteAddress, sentence);
- } else if (sentence.contains("BZ00")) {
- return decodeNetwork(channel, remoteAddress, sentence);
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- boolean alternative = parser.next() != null;
-
- decodeType(position, parser.next(), parser.next());
-
- DateBuilder dateBuilder = new DateBuilder();
- if (alternative) {
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- } else {
- dateBuilder.setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- }
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- position.setSpeed(convertSpeed(parser.nextDouble(0), "kmh"));
-
- dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.setCourse(parser.nextDouble(0));
-
- if (parser.hasNext(6)) {
- position.set(Position.KEY_CHARGE, parser.nextInt() == 0);
- position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
-
- int mask1 = parser.nextHexInt();
- position.set(Position.PREFIX_IN + 2, BitUtil.check(mask1, 0) ? 1 : 0);
- position.set("panic", BitUtil.check(mask1, 1) ? 1 : 0);
- position.set(Position.PREFIX_OUT + 2, BitUtil.check(mask1, 2) ? 1 : 0);
- if (decodeLow || BitUtil.check(mask1, 3)) {
- position.set(Position.KEY_BLOCKED, BitUtil.check(mask1, 3) ? 1 : 0);
- }
-
- int mask2 = parser.nextHexInt();
- for (int i = 0; i < 3; i++) {
- if (decodeLow || BitUtil.check(mask2, i)) {
- position.set("hs" + (3 - i), BitUtil.check(mask2, i) ? 1 : 0);
- }
- }
- if (decodeLow || BitUtil.check(mask2, 3)) {
- position.set(Position.KEY_DOOR, BitUtil.check(mask2, 3) ? 1 : 0);
- }
-
- int mask3 = parser.nextHexInt();
- for (int i = 1; i <= 3; i++) {
- if (decodeLow || BitUtil.check(mask3, i)) {
- position.set("ls" + (3 - i + 1), BitUtil.check(mask3, i) ? 1 : 0);
- }
- }
-
- position.set(Position.KEY_FUEL_LEVEL, parser.nextHexInt());
- }
-
- if (parser.hasNext()) {
- position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0));
- }
-
- if (parser.hasNext()) {
- position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java
deleted file mode 100644
index 9e49b6ff1..000000000
--- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2017 Christoph Krey (c@ckrey.de)
- * Copyright 2017 Anton Tananaev (anton@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 Tk103ProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_GET_VERSION:
- return formatCommand(command, "({%s}AP07)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "({%s}AT00)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_SET_ODOMETER:
- return formatCommand(command, "({%s}AX01)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "({%s}AP00)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(command, "({%s}AR00%s0000)", Command.KEY_UNIQUE_ID,
- String.format("%04X", command.getInteger(Command.KEY_FREQUENCY)));
- case Command.TYPE_POSITION_STOP:
- return formatCommand(command, "({%s}AR0000000000)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "({%s}AV011)", Command.KEY_UNIQUE_ID);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "({%s}AV010)", Command.KEY_UNIQUE_ID);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tlt2hProtocol.java b/src/org/traccar/protocol/Tlt2hProtocol.java
deleted file mode 100644
index 752b0d8ef..000000000
--- a/src/org/traccar/protocol/Tlt2hProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 Tlt2hProtocol extends BaseProtocol {
-
- public Tlt2hProtocol() {
- super("tlt2h");
- }
-
- @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(32 * 1024, "##\r\n"));
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tlt2hProtocolDecoder(Tlt2hProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
deleted file mode 100644
index cbc851de0..000000000
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
-
- public Tlt2hProtocolDecoder(Tlt2hProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_HEADER = new PatternBuilder()
- .number("#(d+)#") // imei
- .expression("[^#]*#")
- .number("d+#")
- .expression("([^#]+)#") // status
- .number("d+") // number of records
- .compile();
-
- private static final Pattern PATTERN_POSITION = new PatternBuilder()
- .number("#(x+)?") // cell info
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).d+,") // time (hhmmss.sss)
- .expression("([AV]),") // validity
- .number("(d+)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(d+)(dd.d+),") // longitude
- .number("([EW]),")
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
- sentence = sentence.trim();
-
- String header = sentence.substring(0, sentence.indexOf('\r'));
- Parser parser = new Parser(PATTERN_HEADER, header);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- String status = parser.next();
-
- String[] messages = sentence.substring(sentence.indexOf('\n') + 1).split("\r\n");
- List<Position> positions = new LinkedList<>();
-
- for (String message : messages) {
- parser = new Parser(PATTERN_POSITION, message);
- if (parser.matches()) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- parser.next(); // base station info
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_STATUS, status);
-
- positions.add(position);
- }
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/TlvProtocol.java b/src/org/traccar/protocol/TlvProtocol.java
deleted file mode 100644
index da8d88b8a..000000000
--- a/src/org/traccar/protocol/TlvProtocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.traccar.BaseProtocol;
-import org.traccar.CharacterDelimiterFrameDecoder;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class TlvProtocol extends BaseProtocol {
-
- public TlvProtocol() {
- super("tlv");
- }
-
- @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('\0'));
- pipeline.addLast("objectDecoder", new TlvProtocolDecoder(TlvProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TlvProtocolDecoder.java b/src/org/traccar/protocol/TlvProtocolDecoder.java
deleted file mode 100644
index 41d65be09..000000000
--- a/src/org/traccar/protocol/TlvProtocolDecoder.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-
-public class TlvProtocolDecoder extends BaseProtocolDecoder {
-
- public TlvProtocolDecoder(TlvProtocol protocol) {
- super(protocol);
- }
-
- private void sendResponse(Channel channel, String type, String... arguments) {
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeBytes(ChannelBuffers.copiedBuffer(type, StandardCharsets.US_ASCII));
- for (String argument : arguments) {
- response.writeByte(argument.length());
- response.writeBytes(ChannelBuffers.copiedBuffer(argument, StandardCharsets.US_ASCII));
- }
- response.writeByte(0);
- channel.write(response);
- }
- }
-
- private String readArgument(ChannelBuffer buf) {
- return buf.readBytes(buf.readUnsignedByte()).toString(StandardCharsets.US_ASCII);
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- String type = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
-
- if (channel != null) {
- switch (type) {
- case "0A":
- case "0C":
- sendResponse(channel, type);
- break;
- case "0B":
- sendResponse(channel, type, "1482202689", "10", "20", "15");
- break;
- case "0E":
- case "0F":
- sendResponse(channel, type, "30", "Unknown");
- break;
- default:
- break;
- }
- }
-
- if (type.equals("0E")) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readArgument(buf));
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(true);
- position.setTime(new Date(Long.parseLong(readArgument(buf)) * 1000));
-
- readArgument(buf); // location identifier
-
- position.setLongitude(Double.parseDouble(readArgument(buf)));
- position.setLatitude(Double.parseDouble(readArgument(buf)));
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(readArgument(buf))));
- position.setCourse(Double.parseDouble(readArgument(buf)));
-
- position.set(Position.KEY_SATELLITES, Integer.parseInt(readArgument(buf)));
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TmgProtocol.java b/src/org/traccar/protocol/TmgProtocol.java
deleted file mode 100644
index f30d61e9a..000000000
--- a/src/org/traccar/protocol/TmgProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 TmgProtocol extends BaseProtocol {
-
- public TmgProtocol() {
- super("tmg");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new TmgProtocolDecoder(TmgProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java
deleted file mode 100644
index b8458dd52..000000000
--- a/src/org/traccar/protocol/TmgProtocolDecoder.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.BitUtil;
-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 TmgProtocolDecoder extends BaseProtocolDecoder {
-
- public TmgProtocolDecoder(TmgProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$")
- .expression("(...),") // type
- .expression("[LH],") // history
- .number("(d+),") // imei
- .number("(dd)(dd)(dddd),") // date (ddmmyyyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(d),") // status
- .number("(dd)(dd.d+),") // latitude
- .expression("([NS]),")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([EW]),")
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(-?d+.?d*),") // altitude
- .number("(d+.d+),") // hdop
- .number("(d+),") // satellites
- .number("(d+),") // visible satellites
- .number("([^,]*),") // operator
- .number("(d+),") // rssi
- .number("[^,]*,") // cid
- .expression("([01]),") // ignition
- .number("(d+.?d*),") // battery
- .number("(d+.?d*),") // power
- .expression("([01]+),") // input
- .expression("([01]+),") // output
- .expression("[01]+,") // temper status
- .number("(d+.?d*)[^,]*,") // adc1
- .number("(d+.?d*)[^,]*,") // adc2
- .number("d+.?d*,") // trip meter
- .expression("([^,]*),") // software version
- .expression("([^,]*),").optional() // rfid
- .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;
- }
-
- String type = parser.next();
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- switch (type) {
- case "rmv":
- position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- break;
- case "ebl":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
- break;
- case "ibl":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "tmp":
- case "smt":
- case "btt":
- position.set(Position.KEY_ALARM, Position.ALARM_TAMPERING);
- break;
- case "ion":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "iof":
- position.set(Position.KEY_IGNITION, false);
- break;
- default:
- break;
- }
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(parser.nextInt(0) > 0);
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0));
- position.set(Position.KEY_OPERATOR, parser.next());
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_POWER, parser.nextDouble(0));
-
- int input = parser.nextBinInt(0);
- int output = parser.nextBinInt(0);
-
- if (!BitUtil.check(input, 0)) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
-
- position.set(Position.KEY_INPUT, input);
- position.set(Position.KEY_OUTPUT, output);
-
- position.set(Position.PREFIX_ADC + 1, parser.nextDouble(0));
- position.set(Position.PREFIX_ADC + 2, parser.nextDouble(0));
- position.set(Position.KEY_VERSION_FW, parser.next());
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/TopflytechProtocol.java b/src/org/traccar/protocol/TopflytechProtocol.java
deleted file mode 100644
index 7d4b13ee6..000000000
--- a/src/org/traccar/protocol/TopflytechProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 TopflytechProtocol extends BaseProtocol {
-
- public TopflytechProtocol() {
- super("topflytech");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new TopflytechProtocolDecoder(TopflytechProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
deleted file mode 100644
index 837ca2557..000000000
--- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
-
- public TopflytechProtocolDecoder(TopflytechProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("(")
- .number("(d+)") // imei
- .any()
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .expression("([AV])")
- .number("(dd)(dd.dddd)([NS])") // latitude
- .number("(ddd)(dd.dddd)([EW])") // longitude
- .number("(ddd.d)") // speed
- .number("(d+.d+)") // course
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java
deleted file mode 100644
index 6940d7b46..000000000
--- a/src/org/traccar/protocol/TotemFrameDecoder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
-
-import java.nio.charset.StandardCharsets;
-
-public class TotemFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 10) {
- return null;
- }
-
- int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("$$"));
- if (beginIndex == -1) {
- return null;
- } else if (beginIndex > buf.readerIndex()) {
- buf.readerIndex(beginIndex);
- }
-
- int length;
-
- int flagIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("AA"));
- if (flagIndex != -1 && flagIndex - beginIndex == 6) {
- length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 4, StandardCharsets.US_ASCII));
- } else {
- length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, StandardCharsets.US_ASCII), 16);
- }
-
- if (length <= buf.readableBytes()) {
- return buf.readBytes(length);
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TotemProtocol.java b/src/org/traccar/protocol/TotemProtocol.java
deleted file mode 100644
index 1c5cf5b02..000000000
--- a/src/org/traccar/protocol/TotemProtocol.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.
- * 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.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class TotemProtocol extends BaseProtocol {
-
- public TotemProtocol() {
- super("totem");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_RESUME,
- Command.TYPE_ENGINE_STOP
- );
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new TotemFrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new TotemProtocolEncoder());
- pipeline.addLast("objectDecoder", new TotemProtocolDecoder(TotemProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
deleted file mode 100644
index a3e8c9921..000000000
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * 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.
- * 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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class TotemProtocolDecoder extends BaseProtocolDecoder {
-
- public TotemProtocolDecoder(TotemProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN1 = new PatternBuilder()
- .text("$$") // header
- .number("xx") // length
- .number("(d+)|") // imei
- .expression("(..)") // alarm
- .text("$GPRMC,")
- .number("(dd)(dd)(dd).d+,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(d+)(dd.d+),([NS]),") // latitude
- .number("(d+)(dd.d+),([EW]),") // longitude
- .number("(d+.?d*)?,") // speed
- .number("(d+.?d*)?,") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .expression("[^*]*").text("*")
- .number("xx|") // checksum
- .number("(d+.d+)|") // pdop
- .number("(d+.d+)|") // hdop
- .number("(d+.d+)|") // vdop
- .number("(d+)|") // io status
- .number("d+|") // battery time
- .number("d") // charged
- .number("(ddd)") // battery
- .number("(dddd)|") // power
- .number("(d+)|").optional() // adc
- .number("x*(xxxx)") // lac
- .number("(xxxx)|") // cid
- .number("(d+)|") // temperature
- .number("(d+.d+)|") // odometer
- .number("d+|") // serial number
- .any()
- .number("xxxx") // checksum
- .any()
- .compile();
-
- private static final Pattern PATTERN2 = new PatternBuilder()
- .text("$$") // header
- .number("xx") // length
- .number("(d+)|") // imei
- .expression("(..)") // alarm type
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .number("(dd)(dd)(dd)|") // time (hhmmss)
- .expression("([AV])|") // validity
- .number("(d+)(dd.d+)|") // latitude
- .expression("([NS])|")
- .number("(d+)(dd.d+)|") // longitude
- .expression("([EW])|")
- .number("(d+.d+)?|") // speed
- .number("(d+)?|") // course
- .number("(d+.d+)|") // hdop
- .number("(d+)|") // io status
- .number("d") // charged
- .number("(dd)") // battery
- .number("(dd)|") // external power
- .number("(d+)|") // adc
- .number("(xxxx)") // lac
- .number("(xxxx)|") // cid
- .number("(d+)|") // temperature
- .number("(d+.d+)|") // odometer
- .number("d+|") // serial number
- .number("xxxx") // checksum
- .any()
- .compile();
-
- private static final Pattern PATTERN3 = new PatternBuilder()
- .text("$$") // header
- .number("xx") // length
- .number("(d+)|") // imei
- .expression("(..)") // alarm type
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(xxxx)") // io status
- .expression("[01]") // charging
- .number("(dd)") // battery
- .number("(dd)") // external power
- .number("(dddd)") // adc 1
- .number("(dddd)") // adc 2
- .number("(ddd)") // temperature 1
- .number("(ddd)") // temperature 2
- .number("(xxxx)") // lac
- .number("(xxxx)") // cid
- .expression("([AV])") // validity
- .number("(dd)") // satellites
- .number("(ddd)") // course
- .number("(ddd)") // speed
- .number("(dd.d)") // pdop
- .number("(d{7})") // odometer
- .number("(dd)(dd.dddd)([NS])") // latitude
- .number("(ddd)(dd.dddd)([EW])") // longitude
- .number("dddd") // serial number
- .number("xxxx") // checksum
- .any()
- .compile();
-
- private static final Pattern PATTERN4 = new PatternBuilder()
- .text("$$") // header
- .number("dddd") // length
- .expression("A[ABC]") // type
- .number("(d+)|") // imei
- .number("(x{8})") // status
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(dd)") // battery
- .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("?")
- .number("(xxxx)") // lac
- .number("(xxxx)") // cid
- .number("(dd)") // satellites
- .number("(dd)") // gsm (rssi)
- .number("(ddd)") // course
- .number("(ddd)") // speed
- .number("(dd.d)") // hdop
- .number("(d{7})") // odometer
- .number("(dd)(dd.dddd)([NS])") // latitude
- .number("(ddd)(dd.dddd)([EW])") // longitude
- .number("dddd") // serial number
- .number("xx") // checksum
- .any()
- .compile();
-
- private String decodeAlarm(Short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x30:
- return Position.ALARM_PARKING;
- case 0x42:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x43:
- return Position.ALARM_GEOFENCE_ENTER;
- default:
- return null;
- }
- }
-
- private boolean decode12(Position position, Parser parser, Pattern pattern) {
-
- if (parser.hasNext()) {
- position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16)));
- }
- DateBuilder dateBuilder = new DateBuilder();
- int year = 0, month = 0, day = 0;
- if (pattern == PATTERN2) {
- day = parser.nextInt(0);
- month = parser.nextInt(0);
- year = parser.nextInt(0);
- }
- dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- if (pattern == PATTERN1) {
- day = parser.nextInt(0);
- month = parser.nextInt(0);
- year = parser.nextInt(0);
- }
- if (year == 0) {
- return false; // ignore invalid data
- }
- dateBuilder.setDate(year, month, day);
- position.setTime(dateBuilder.getDate());
-
- if (pattern == PATTERN1) {
- position.set(Position.KEY_PDOP, parser.nextDouble());
- position.set(Position.KEY_HDOP, parser.nextDouble());
- position.set(Position.KEY_VDOP, parser.nextDouble());
- } else {
- position.set(Position.KEY_HDOP, parser.nextDouble());
- }
-
- position.set(Position.PREFIX_IO + 1, parser.next());
- if (pattern == PATTERN1) {
- position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.01);
- } else {
- position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
- }
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- position.set(Position.PREFIX_ADC + 1, parser.next());
-
- int lac = parser.nextHexInt(0);
- int cid = parser.nextHexInt(0);
- if (lac != 0 && cid != 0) {
- position.setNetwork(new Network(CellTower.fromLacCid(lac, cid)));
- }
-
- position.set(Position.PREFIX_TEMP + 1, parser.next());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
-
- return true;
- }
-
- private boolean decode3(Position position, Parser parser) {
-
- if (parser.hasNext()) {
- position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16)));
- }
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.set(Position.PREFIX_IO + 1, parser.next());
- position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- position.set(Position.PREFIX_TEMP + 1, parser.next());
- position.set(Position.PREFIX_TEMP + 2, parser.next());
-
- position.setNetwork(new Network(
- CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
-
- position.setValid(parser.next().equals("A"));
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.setCourse(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.set(Position.KEY_PDOP, parser.nextDouble());
- position.set(Position.KEY_ODOMETER, parser.nextInt(0) * 1000);
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- return true;
- }
-
- private boolean decode4(Position position, Parser parser) {
-
- position.set(Position.KEY_STATUS, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
- position.set(Position.KEY_POWER, parser.nextDouble(0));
-
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- position.set(Position.PREFIX_ADC + 3, parser.next());
- position.set(Position.PREFIX_ADC + 4, parser.next());
- position.set(Position.PREFIX_TEMP + 1, parser.next());
- position.set(Position.PREFIX_TEMP + 2, parser.next());
-
- CellTower cellTower = CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0));
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- cellTower.setSignalStrength(parser.nextInt(0));
- position.setNetwork(new Network(cellTower));
-
- position.setCourse(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.KEY_ODOMETER, parser.nextInt(0) * 1000);
-
- position.setValid(true);
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- return true;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
- Pattern pattern = PATTERN3;
- if (sentence.indexOf("A") == 6) {
- pattern = PATTERN4;
- } else if (sentence.contains("$GPRMC")) {
- pattern = PATTERN1;
- } else {
- int index = sentence.indexOf('|');
- if (index != -1 && sentence.indexOf('|', index + 1) != -1) {
- pattern = PATTERN2;
- }
- }
-
- Parser parser = new Parser(pattern, 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());
-
- boolean result;
- if (pattern == PATTERN1 || pattern == PATTERN2) {
- result = decode12(position, parser, pattern);
- } else if (pattern == PATTERN3) {
- result = decode3(position, parser);
- } else {
- result = decode4(position, parser);
- }
-
- if (channel != null) {
- if (pattern == PATTERN4) {
- channel.write("$$0014AA" + sentence.substring(sentence.length() - 6));
- } else {
- channel.write("ACK OK\r\n");
- }
- }
-
- return result ? position : null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TotemProtocolEncoder.java b/src/org/traccar/protocol/TotemProtocolEncoder.java
deleted file mode 100644
index ff41a7df3..000000000
--- a/src/org/traccar/protocol/TotemProtocolEncoder.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2015 Irving Gonzalez
- * 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.
- * 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 TotemProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- initDevicePassword(command, "000000");
-
- switch (command.getType()) {
- // Assuming PIN 8 (Output C) is the power wire, like manual says but it can be PIN 5,7,8
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "*{%s},025,C,1#", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "*{%s},025,C,0#", Command.KEY_DEVICE_PASSWORD);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tr20Protocol.java b/src/org/traccar/protocol/Tr20Protocol.java
deleted file mode 100644
index 8de004be9..000000000
--- a/src/org/traccar/protocol/Tr20Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 Tr20Protocol extends BaseProtocol {
-
- public Tr20Protocol() {
- super("tr20");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Tr20ProtocolDecoder(Tr20Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
deleted file mode 100644
index 403a2fda2..000000000
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.
- * 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.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 Tr20ProtocolDecoder extends BaseProtocolDecoder {
-
- public Tr20ProtocolDecoder(Tr20Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_PING = new PatternBuilder()
- .text("%%")
- .expression("[^,]+,")
- .number("(d+)")
- .compile();
-
- private static final Pattern PATTERN_DATA = new PatternBuilder()
- .text("%%")
- .expression("([^,]+),") // id
- .expression("([AL]),") // validity
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([NS])")
- .number("(dd)(dd.d+)") // latitude
- .expression("([EW])")
- .number("(ddd)(dd.d+),") // longitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Parser parser = new Parser(PATTERN_PING, (String) msg);
- if (parser.matches()) {
- if (channel != null) {
- channel.write("&&" + parser.next() + "\r\n"); // keep-alive response
- }
- return null;
- }
-
- parser = new Parser(PATTERN_DATA, (String) msg);
- 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.setValid(parser.next().equals("A"));
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tr900Protocol.java b/src/org/traccar/protocol/Tr900Protocol.java
deleted file mode 100644
index 40f287efa..000000000
--- a/src/org/traccar/protocol/Tr900Protocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.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 Tr900Protocol extends BaseProtocol {
-
- public Tr900Protocol() {
- super("tr900");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
deleted file mode 100644
index 7dbdc5697..000000000
--- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class Tr900ProtocolDecoder extends BaseProtocolDecoder {
-
- public Tr900ProtocolDecoder(Tr900Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number(">(d+),") // id
- .number("d+,") // period
- .number("(d),") // fix
- .number("(dd)(dd)(dd),") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([EW])")
- .number("(ddd)(dd.d+),") // longitude
- .expression("([NS])")
- .number("(dd)(dd.d+),") // latitude
- .expression("[^,]*,") // command
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(d+),") // gsm
- .number("(d+),") // event
- .number("(d+)-") // adc
- .number("(d+),") // battery
- .number("d+,") // impulses
- .number("(d+),") // input
- .number("(d+)") // status
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(parser.nextInt(0) == 1);
-
- position.setTime(parser.nextDateTime());
-
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_RSSI, parser.nextDouble());
- position.set(Position.KEY_EVENT, parser.nextInt(0));
- position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_STATUS, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/TrackboxProtocol.java b/src/org/traccar/protocol/TrackboxProtocol.java
deleted file mode 100644
index c1aa5ac6a..000000000
--- a/src/org/traccar/protocol/TrackboxProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 TrackboxProtocol extends BaseProtocol {
-
- public TrackboxProtocol() {
- super("trackbox");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new TrackboxProtocolDecoder(TrackboxProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
deleted file mode 100644
index 7e542af93..000000000
--- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.
- * 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 TrackboxProtocolDecoder extends BaseProtocolDecoder {
-
- public TrackboxProtocolDecoder(TrackboxProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(dd)(dd)(dd).(ddd),") // time (hhmmss.sss)
- .number("(dd)(dd.dddd)([NS]),") // latitude
- .number("(ddd)(dd.dddd)([EW]),") // longitude
- .number("(d+.d),") // hdop
- .number("(-?d+.?d*),") // altitude
- .number("(d),") // fix type
- .number("(d+.d+),") // course
- .number("d+.d+,") // speed (kph)
- .number("(d+.d+),") // speed (knots)
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(d+)") // satellites
- .compile();
-
- private void sendResponse(Channel channel) {
- if (channel != null) {
- channel.write("=OK=\r\n");
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("a=connect")) {
- String id = sentence.substring(sentence.indexOf("i=") + 2);
- if (getDeviceSession(channel, remoteAddress, id) != null) {
- sendResponse(channel);
- }
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
- sendResponse(channel);
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- position.set(Position.KEY_HDOP, parser.nextDouble());
-
- position.setAltitude(parser.nextDouble(0));
-
- int fix = parser.nextInt(0);
- position.set(Position.KEY_GPS, fix);
- position.setValid(fix > 0);
-
- position.setCourse(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/TrakMateProtocol.java b/src/org/traccar/protocol/TrakMateProtocol.java
deleted file mode 100644
index f6d9bf457..000000000
--- a/src/org/traccar/protocol/TrakMateProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 8965a18b4..000000000
--- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * 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.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 (hhmmss)
- .number("(dd)(dd)(dd)|") // date (ddmmyy)
- .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 (hhmmss)
- .number("(dd)(dd)(dd)|") // date (ddmmyy)
- .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 (hhmmss)
- .number("(dd)(dd)(dd)|") // date (ddmmyy)
- .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(0));
- position.setLongitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
-
- position.set(Position.KEY_VERSION_FW, parser.next());
- position.set(Position.KEY_VERSION_HW, parser.next());
-
- 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(0)));
- parser.next(); // alert status or data
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
-
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- 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(0));
- position.setLongitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
-
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
- position.set("dop1", parser.next());
- position.set("dop2", parser.next());
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_POWER, parser.nextDouble());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0));
- position.set("pulseOdometer", parser.next());
- position.set(Position.KEY_STATUS, parser.nextInt(0));
-
- position.setValid(parser.nextInt(0) != 0);
-
- position.set(Position.KEY_ARCHIVE, parser.nextInt(0) == 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
deleted file mode 100644
index 20992c04b..000000000
--- a/src/org/traccar/protocol/TramigoFrameDecoder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
-
-import java.nio.ByteOrder;
-
-public class TramigoFrameDecoder extends LengthFieldBasedFrameDecoder {
-
- public TramigoFrameDecoder() {
- super(1024, 6, 2, -8, 0);
- }
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 20) {
- return null;
- }
-
- // Swap byte order for legacy protocol
- if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) {
- int length = buf.readableBytes();
- byte[] bytes = new byte[length];
- buf.getBytes(buf.readerIndex(), bytes);
-
- ChannelBuffer result = (ChannelBuffer) super.decode(
- ctx, channel, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes));
- if (result != null) {
- buf.skipBytes(result.readableBytes());
- }
- return result;
- }
-
- return super.decode(ctx, channel, buf);
- }
-
-}
diff --git a/src/org/traccar/protocol/TramigoProtocol.java b/src/org/traccar/protocol/TramigoProtocol.java
deleted file mode 100644
index 28673c97b..000000000
--- a/src/org/traccar/protocol/TramigoProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
-
-public class TramigoProtocol extends BaseProtocol {
-
- public TramigoProtocol() {
- super("tramigo");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new TramigoFrameDecoder());
- pipeline.addLast("objectDecoder", new TramigoProtocolDecoder(TramigoProtocol.this));
- }
- };
- server.setEndianness(ByteOrder.LITTLE_ENDIAN);
- serverList.add(server);
- }
-
-}
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java
deleted file mode 100644
index b1e28e17d..000000000
--- a/src/org/traccar/protocol/TramigoProtocolDecoder.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@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.DateUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class TramigoProtocolDecoder extends BaseProtocolDecoder {
-
- public TramigoProtocolDecoder(TramigoProtocol protocol) {
- super(protocol);
- }
-
- 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 {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- int protocol = buf.readUnsignedByte();
- buf.readUnsignedByte(); // version id
- int index = buf.readUnsignedShort();
- int type = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
- buf.readUnsignedShort(); // mask
- buf.readUnsignedShort(); // checksum
- long id = buf.readUnsignedInt();
- buf.readUnsignedInt(); // time
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.set(Position.KEY_INDEX, index);
- position.setValid(true);
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (protocol == 0x01 && (type == MSG_COMPACT || type == MSG_FULL)) {
-
- // need to send ack?
-
- buf.readUnsignedShort(); // report trigger
- buf.readUnsignedShort(); // state flag
-
- position.setLatitude(buf.readUnsignedInt() * 0.0000001);
- position.setLongitude(buf.readUnsignedInt() * 0.0000001);
-
- position.set(Position.KEY_RSSI, buf.readUnsignedShort());
- position.set(Position.KEY_SATELLITES, buf.readUnsignedShort());
- position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedShort());
- position.set("gpsAntennaStatus", buf.readUnsignedShort());
-
- position.setSpeed(buf.readUnsignedShort() * 0.194384);
- position.setCourse(buf.readUnsignedShort());
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
-
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
-
- position.set(Position.KEY_CHARGE, buf.readUnsignedShort());
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- // parse other data
-
- return position;
-
- } else if (protocol == 0x80) {
-
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer("gprs,ack," + index, StandardCharsets.US_ASCII));
- }
-
- String sentence = buf.toString(StandardCharsets.US_ASCII);
-
- Pattern pattern = Pattern.compile("(-?\\d+\\.\\d+), (-?\\d+\\.\\d+)");
- Matcher matcher = pattern.matcher(sentence);
- if (!matcher.find()) {
- return null;
- }
- position.setLatitude(Double.parseDouble(matcher.group(1)));
- position.setLongitude(Double.parseDouble(matcher.group(2)));
-
- 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))));
- }
-
- pattern = Pattern.compile("(\\d{1,2}:\\d{2}(:\\d{2})? \\w{3} \\d{1,2})");
- matcher = pattern.matcher(sentence);
- if (!matcher.find()) {
- return null;
- }
- DateFormat dateFormat = new SimpleDateFormat(
- matcher.group(2) != null ? "HH:mm:ss MMM d yyyy" : "HH:mm MMM d yyyy", Locale.ENGLISH);
- position.setTime(DateUtil.correctYear(
- dateFormat.parse(matcher.group(1) + " " + Calendar.getInstance().get(Calendar.YEAR))));
-
- if (sentence.contains("Ignition on detected")) {
- position.set(Position.KEY_IGNITION, true);
- } else if (sentence.contains("Ignition off detected")) {
- position.set(Position.KEY_IGNITION, false);
- }
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/TrvProtocol.java b/src/org/traccar/protocol/TrvProtocol.java
deleted file mode 100644
index 348ccd92a..000000000
--- a/src/org/traccar/protocol/TrvProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 TrvProtocol extends BaseProtocol {
-
- public TrvProtocol() {
- super("trv");
- }
-
- @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 TrvProtocolDecoder(TrvProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java
deleted file mode 100644
index 918748f7b..000000000
--- a/src/org/traccar/protocol/TrvProtocolDecoder.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class TrvProtocolDecoder extends BaseProtocolDecoder {
-
- public TrvProtocolDecoder(TrvProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("[A-Z]{2,3}")
- .number("APdd")
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .expression("([AV])") // validity
- .number("(dd)(dd.d+)") // latitude
- .expression("([NS])")
- .number("(ddd)(dd.d+)") // longitude
- .expression("([EW])")
- .number("(ddd.d)") // speed
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("([d.]{6})") // course
- .number("(ddd)") // gsm
- .number("(ddd)") // satellites
- .number("(ddd)") // battery
- .number("(d)") // acc
- .number("(dd)") // arm status
- .number("(dd),") // working mode
- .number("(d+),") // mcc
- .number("(d+),") // mnc
- .number("(d+),") // lac
- .number("(d+)") // cell
- .any()
- .compile();
-
- private static final Pattern PATTERN_HEATRBEAT = new PatternBuilder()
- .expression("[A-Z]{2,3}")
- .text("CP01,")
- .number("(ddd)") // gsm
- .number("(ddd)") // gps
- .number("(ddd)") // battery
- .number("(d)") // acc
- .number("(dd)") // arm status
- .number("(dd)") // working mode
- .groupBegin()
- .number("(ddd)") // interval
- .number("d") // vibration alarm
- .number("ddd") // vibration sensitivity
- .number("d") // automatic arm
- .number("dddd") // automatic arm time
- .number("(d)") // blocked
- .number("(d)") // power status
- .number("(d)") // movement status
- .groupEnd("?")
- .any()
- .compile();
-
- private Boolean decodeOptionalValue(Parser parser, int activeValue) {
- int value = parser.nextInt();
- if (value != 0) {
- return value == activeValue;
- }
- return null;
- }
-
- private void decodeCommon(Position position, Parser parser) {
-
- position.set(Position.KEY_RSSI, parser.nextInt());
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_BATTERY, parser.nextInt());
- position.set(Position.KEY_IGNITION, decodeOptionalValue(parser, 1));
- position.set(Position.KEY_ARMED, decodeOptionalValue(parser, 1));
-
- int mode = parser.nextInt();
- if (mode != 0) {
- position.set("mode", mode);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- String id = sentence.startsWith("TRV") ? sentence.substring(0, 3) : sentence.substring(0, 2);
- String type = sentence.substring(id.length(), id.length() + 4);
-
- if (channel != null) {
- String responseHeader = id + (char) (type.charAt(0) + 1) + type.substring(1);
- if (type.equals("AP00") && id.equals("IW")) {
- String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
- channel.write(responseHeader + "," + time + ",0#");
- } else if (type.equals("AP14")) {
- channel.write(responseHeader + ",0.000,0.000#");
- } else {
- channel.write(responseHeader + "#");
- }
- }
-
- if (type.equals("AP00")) {
- getDeviceSession(channel, remoteAddress, sentence.substring(id.length() + type.length()));
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- if (type.equals("CP01")) {
-
- Parser parser = new Parser(PATTERN_HEATRBEAT, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- decodeCommon(position, parser);
-
- if (parser.hasNext(3)) {
- position.set(Position.KEY_BLOCKED, decodeOptionalValue(parser, 2));
- position.set(Position.KEY_CHARGE, decodeOptionalValue(parser, 1));
- position.set(Position.KEY_MOTION, decodeOptionalValue(parser, 1));
- }
-
- return position;
-
- } else if (type.equals("AP01") || type.equals("AP10")) {
-
- Parser parser = new Parser(PATTERN, 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());
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
-
- dateBuilder.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
- position.setTime(dateBuilder.getDate());
-
- position.setCourse(parser.nextDouble());
-
- decodeCommon(position, parser);
-
- position.setNetwork(new Network(CellTower.from(
- parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt())));
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Tt8850Protocol.java b/src/org/traccar/protocol/Tt8850Protocol.java
deleted file mode 100644
index 79dc031bc..000000000
--- a/src/org/traccar/protocol/Tt8850Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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 Tt8850Protocol extends BaseProtocol {
-
- public Tt8850Protocol() {
- super("tt8850");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new Tt8850ProtocolDecoder(Tt8850Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
deleted file mode 100644
index 5e30d0994..000000000
--- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class Tt8850ProtocolDecoder extends BaseProtocolDecoder {
-
- public Tt8850ProtocolDecoder(Tt8850Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .binary("0004,")
- .number("xxxx,")
- .expression("[01],")
- .expression("GT...,")
- .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
- .expression("([^,]+),") // imei
- .any()
- .number("(d{1,2})?,") // gps accuracy
- .number("(d{1,3}.d)?,") // speed
- .number("(d{1,3})?,") // course
- .number("(-?d{1,5}.d)?,") // altitude
- .number("(-?d{1,3}.d{6}),") // longitude
- .number("(-?d{1,2}.d{6}),") // latitude
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(0ddd)?,") // mcc
- .number("(0ddd)?,") // mnc
- .number("(xxxx)?,") // lac
- .number("(xxxx)?,") // cell
- .any()
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(xxxx)")
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setValid(true);
- position.setAccuracy(parser.nextInt(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
-
- position.setTime(parser.nextDateTime());
-
- if (parser.hasNext(4)) {
- position.setNetwork(new Network(
- CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/TytanProtocol.java b/src/org/traccar/protocol/TytanProtocol.java
deleted file mode 100644
index 0c27fb12b..000000000
--- a/src/org/traccar/protocol/TytanProtocol.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.
- * 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 TytanProtocol extends BaseProtocol {
-
- public TytanProtocol() {
- super("tytan");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new TytanProtocolDecoder(TytanProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
deleted file mode 100644
index 0ae669784..000000000
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-public class TytanProtocolDecoder extends BaseProtocolDecoder {
-
- public TytanProtocolDecoder(TytanProtocol protocol) {
- super(protocol);
- }
-
- private void decodeExtraData(Position position, ChannelBuffer buf, int end) {
- while (buf.readerIndex() < end) {
-
- int type = buf.readUnsignedByte();
- int length = buf.readUnsignedByte();
- if (length == 255) {
- length += buf.readUnsignedByte();
- }
-
- int n;
-
- switch (type) {
- case 2:
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedMedium());
- break;
- case 5:
- position.set(Position.KEY_INPUT, buf.readUnsignedByte());
- break;
- case 6:
- n = buf.readUnsignedByte() >> 4;
- if (n < 2) {
- position.set(Position.PREFIX_ADC + n, buf.readFloat());
- } else {
- position.set("di" + (n - 2), buf.readFloat());
- }
- break;
- case 7:
- int alarm = buf.readUnsignedByte();
- buf.readUnsignedByte();
- if (BitUtil.check(alarm, 5)) {
- position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- }
- break;
- case 8:
- position.set("antihijack", buf.readUnsignedByte());
- break;
- case 9:
- position.set("unauthorized", ChannelBuffers.hexDump(buf.readBytes(8)));
- break;
- case 10:
- position.set("authorized", ChannelBuffers.hexDump(buf.readBytes(8)));
- break;
- case 24:
- for (int i = 0; i < length / 2; i++) {
- position.set(Position.PREFIX_TEMP + buf.readUnsignedByte(), buf.readByte());
- }
- break;
- case 28:
- position.set("weight", buf.readUnsignedShort());
- buf.readUnsignedByte();
- break;
- case 90:
- position.set(Position.KEY_POWER, buf.readFloat());
- break;
- case 101:
- position.set(Position.KEY_OBD_SPEED, buf.readUnsignedByte());
- break;
- case 102:
- position.set(Position.KEY_RPM, buf.readUnsignedByte() * 50);
- break;
- case 107:
- int fuel = buf.readUnsignedShort();
- int fuelFormat = fuel >> 14;
- if (fuelFormat == 1) {
- position.set("fuelValue", (fuel & 0x3fff) * 0.4 + "%");
- } else if (fuelFormat == 2) {
- position.set("fuelValue", (fuel & 0x3fff) * 0.5 + " l");
- } else if (fuelFormat == 3) {
- position.set("fuelValue", (fuel & 0x3fff) * -0.5 + " l");
- }
- break;
- case 108:
- position.set(Position.KEY_OBD_ODOMETER, buf.readUnsignedInt() * 5);
- break;
- case 150:
- position.set(Position.KEY_DOOR, buf.readUnsignedByte());
- break;
- default:
- buf.skipBytes(length);
- break;
- }
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.readUnsignedByte(); // protocol
- buf.readUnsignedShort(); // length
- int index = buf.readUnsignedByte() >> 3;
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.copiedBuffer(
- "^" + index, StandardCharsets.US_ASCII);
- channel.write(response, remoteAddress);
- }
-
- String id = String.valueOf(buf.readUnsignedInt());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
-
- List<Position> positions = new LinkedList<>();
-
- while (buf.readableBytes() > 2) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- int end = buf.readerIndex() + buf.readUnsignedByte();
-
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
-
- int flags = buf.readUnsignedByte();
- position.set(Position.KEY_SATELLITES, BitUtil.from(flags, 2));
- position.setValid(BitUtil.to(flags, 2) > 0);
-
- // Latitude
- double lat = buf.readUnsignedMedium();
- lat = lat * -180 / 16777216 + 90;
- position.setLatitude(lat);
-
- // Longitude
- double lon = buf.readUnsignedMedium();
- lon = lon * 360 / 16777216 - 180;
- position.setLongitude(lon);
-
- // Status
- flags = buf.readUnsignedByte();
- position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
- position.set(Position.KEY_RSSI, BitUtil.between(flags, 2, 5));
- position.setCourse((BitUtil.from(flags, 5) * 45 + 180) % 360);
-
- // Speed
- int speed = buf.readUnsignedByte();
- if (speed < 250) {
- position.setSpeed(UnitsConverter.knotsFromKph(speed));
- }
-
- decodeExtraData(position, buf, end);
-
- positions.add(position);
- }
-
- return positions;
- }
-
-}
diff --git a/src/org/traccar/protocol/TzoneProtocol.java b/src/org/traccar/protocol/TzoneProtocol.java
deleted file mode 100644
index 38d5b139a..000000000
--- a/src/org/traccar/protocol/TzoneProtocol.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- * 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.LengthFieldBasedFrameDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class TzoneProtocol extends BaseProtocol {
-
- public TzoneProtocol() {
- super("tzone");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(256, 2, 2, 2, 0));
- pipeline.addLast("objectDecoder", new TzoneProtocolDecoder(TzoneProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java
deleted file mode 100644
index 079ad3126..000000000
--- a/src/org/traccar/protocol/TzoneProtocolDecoder.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-
-public class TzoneProtocolDecoder extends BaseProtocolDecoder {
-
- public TzoneProtocolDecoder(TzoneProtocol protocol) {
- super(protocol);
- }
-
- private String decodeAlarm(Short value) {
- switch (value) {
- case 0x01:
- return Position.ALARM_SOS;
- case 0x10:
- return Position.ALARM_LOW_BATTERY;
- case 0x11:
- return Position.ALARM_OVERSPEED;
- case 0x14:
- return Position.ALARM_BRAKING;
- case 0x15:
- return Position.ALARM_ACCELERATION;
- case 0x30:
- return Position.ALARM_PARKING;
- case 0x42:
- return Position.ALARM_GEOFENCE_EXIT;
- case 0x43:
- return Position.ALARM_GEOFENCE_ENTER;
- default:
- return null;
- }
- }
-
- private void decodeCards(Position position, ChannelBuffer buf) {
-
- int index = 1;
- for (int i = 0; i < 4; i++) {
-
- int blockLength = buf.readUnsignedShort();
- int blockEnd = buf.readerIndex() + blockLength;
-
- if (blockLength > 0) {
-
- int count = buf.readUnsignedByte();
- for (int j = 0; j < count; j++) {
-
- int length = buf.readUnsignedByte();
-
- boolean odd = length % 2 != 0;
- if (odd) {
- length += 1;
- }
-
- String num = ChannelBuffers.hexDump(buf.readBytes(length / 2));
-
- if (odd) {
- num = num.substring(1);
- }
-
- position.set("card" + index, num);
- }
- }
-
- buf.readerIndex(blockEnd);
- }
-
- }
-
- private void decodePassengers(Position position, ChannelBuffer buf) {
-
- int blockLength = buf.readUnsignedShort();
- int blockEnd = buf.readerIndex() + blockLength;
-
- if (blockLength > 0) {
-
- position.set("passengersOn", buf.readUnsignedMedium());
- position.set("passengersOff", buf.readUnsignedMedium());
-
- }
-
- buf.readerIndex(blockEnd);
-
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(2); // header
- buf.readUnsignedShort(); // length
- if (buf.readUnsignedShort() != 0x2424) {
- return null;
- }
- int hardware = buf.readUnsignedShort();
- long firmware = buf.readUnsignedInt();
-
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set(Position.KEY_VERSION_HW, hardware);
- position.set(Position.KEY_VERSION_FW, firmware);
-
- position.setDeviceTime(new DateBuilder()
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
-
- // GPS info
-
- int blockLength = buf.readUnsignedShort();
- int blockEnd = buf.readerIndex() + blockLength;
-
- if (blockLength < 22) {
- return null;
- }
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
-
- double lat;
- double lon;
-
- if (hardware == 0x10A || hardware == 0x10B) {
- lat = buf.readUnsignedInt() / 600000.0;
- lon = buf.readUnsignedInt() / 600000.0;
- } else {
- lat = buf.readUnsignedInt() / 100000.0 / 60.0;
- lon = buf.readUnsignedInt() / 100000.0 / 60.0;
- }
-
- position.setFixTime(new DateBuilder()
- .setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
- .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).getDate());
-
- position.setSpeed(buf.readUnsignedShort() * 0.01);
-
- position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
-
- int flags = buf.readUnsignedShort();
- position.setCourse(BitUtil.to(flags, 9));
- if (!BitUtil.check(flags, 10)) {
- lat = -lat;
- }
- position.setLatitude(lat);
- if (BitUtil.check(flags, 9)) {
- lon = -lon;
- }
- position.setLongitude(lon);
- position.setValid(BitUtil.check(flags, 11));
-
- buf.readerIndex(blockEnd);
-
- // LBS info
-
- blockLength = buf.readUnsignedShort();
- blockEnd = buf.readerIndex() + blockLength;
-
- if (blockLength > 0 && (hardware == 0x10A || hardware == 0x10B)) {
- position.setNetwork(new Network(
- CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
- }
-
- buf.readerIndex(blockEnd);
-
- // Status info
-
- blockLength = buf.readUnsignedShort();
- blockEnd = buf.readerIndex() + blockLength;
-
- if (blockLength >= 13) {
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
- position.set("terminalInfo", buf.readUnsignedByte());
-
- int status = buf.readUnsignedByte();
- position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 0));
- position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 1));
- status = buf.readUnsignedByte();
- position.set(Position.PREFIX_IN + 1, BitUtil.check(status, 4));
- if (BitUtil.check(status, 0)) {
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- }
-
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- position.set("gsmStatus", buf.readUnsignedByte());
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
- position.set(Position.KEY_POWER, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
- position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
- }
-
- if (blockLength >= 15) {
- position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
- }
-
- buf.readerIndex(blockEnd);
-
- if (hardware == 0x10A || hardware == 0x10B) {
-
- decodeCards(position, buf);
-
- buf.skipBytes(buf.readUnsignedShort()); // temperature
- buf.skipBytes(buf.readUnsignedShort()); // lock
-
- decodePassengers(position, buf);
-
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/UlbotechFrameDecoder.java b/src/org/traccar/protocol/UlbotechFrameDecoder.java
deleted file mode 100644
index 8e7b497c5..000000000
--- a/src/org/traccar/protocol/UlbotechFrameDecoder.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.
- * 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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class UlbotechFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 2) {
- return null;
- }
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) {
-
- int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xF8);
- if (index != -1) {
- ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex());
-
- while (buf.readerIndex() <= index) {
- int b = buf.readUnsignedByte();
- if (b == 0xF7) {
- int ext = buf.readUnsignedByte();
- if (ext == 0x00) {
- result.writeByte(0xF7);
- } else if (ext == 0x0F) {
- result.writeByte(0xF8);
- }
- } else {
- result.writeByte(b);
- }
- }
-
- return result;
- }
-
- } else {
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#');
- if (index != -1) {
- return buf.readBytes(index + 1 - buf.readerIndex());
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/UlbotechProtocol.java b/src/org/traccar/protocol/UlbotechProtocol.java
deleted file mode 100644
index 40f4594a5..000000000
--- a/src/org/traccar/protocol/UlbotechProtocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.
- * 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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class UlbotechProtocol extends BaseProtocol {
-
- public UlbotechProtocol() {
- super("ulbotech");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new UlbotechFrameDecoder());
- pipeline.addLast("objectDecoder", new UlbotechProtocolDecoder(UlbotechProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
deleted file mode 100644
index 31a3d2cfe..000000000
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.Checksum;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.ObdDecoder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
-
- private final long timeZone;
-
- public UlbotechProtocolDecoder(UlbotechProtocol protocol) {
- super(protocol);
- timeZone = Context.getConfig().getInteger(getProtocolName() + ".timezone", 0);
- }
-
- private static final short DATA_GPS = 0x01;
- private static final short DATA_LBS = 0x02;
- private static final short DATA_STATUS = 0x03;
- private static final short DATA_ODOMETER = 0x04;
- private static final short DATA_ADC = 0x05;
- private static final short DATA_GEOFENCE = 0x06;
- private static final short DATA_OBD2 = 0x07;
- private static final short DATA_FUEL = 0x08;
- private static final short DATA_OBD2_ALARM = 0x09;
- private static final short DATA_HARSH_DRIVER = 0x0A;
- private static final short DATA_CANBUS = 0x0B;
- private static final short DATA_J1708 = 0x0C;
- private static final short DATA_VIN = 0x0D;
- private static final short DATA_RFID = 0x0E;
- private static final short DATA_EVENT = 0x10;
-
- private void decodeObd(Position position, ChannelBuffer buf, int length) {
-
- int end = buf.readerIndex() + length;
-
- while (buf.readerIndex() < end) {
- int parameterLength = buf.getUnsignedByte(buf.readerIndex()) >> 4;
- int mode = buf.readUnsignedByte() & 0x0F;
- position.add(ObdDecoder.decode(mode, ChannelBuffers.hexDump(buf.readBytes(parameterLength - 1))));
- }
- }
-
- private void decodeJ1708(Position position, ChannelBuffer buf, int length) {
-
- int end = buf.readerIndex() + length;
-
- while (buf.readerIndex() < end) {
- int mark = buf.readUnsignedByte();
- int len = BitUtil.between(mark, 0, 6);
- int type = BitUtil.between(mark, 6, 8);
- int id = buf.readUnsignedByte();
- if (type == 3) {
- id += 256;
- }
- String value = ChannelBuffers.hexDump(buf.readBytes(len - 1));
- if (type == 2 || type == 3) {
- position.set("pid" + id, value);
- }
- }
- }
-
- private void decodeDriverBehavior(Position position, ChannelBuffer buf) {
-
- int value = buf.readUnsignedByte();
-
- if (BitUtil.check(value, 0)) {
- position.set("rapidAcceleration", true);
- }
- if (BitUtil.check(value, 1)) {
- position.set("roughBraking", true);
- }
- if (BitUtil.check(value, 2)) {
- position.set("harshCourse", true);
- }
- if (BitUtil.check(value, 3)) {
- position.set("noWarmUp", true);
- }
- if (BitUtil.check(value, 4)) {
- position.set("longIdle", true);
- }
- if (BitUtil.check(value, 5)) {
- position.set("fatigueDriving", true);
- }
- if (BitUtil.check(value, 6)) {
- position.set("roughTerrain", true);
- }
- if (BitUtil.check(value, 7)) {
- position.set("highRpm", true);
- }
- }
-
- private String decodeAlarm(int alarm) {
- if (BitUtil.check(alarm, 0)) {
- return Position.ALARM_POWER_OFF;
- }
- if (BitUtil.check(alarm, 1)) {
- return Position.ALARM_MOVEMENT;
- }
- if (BitUtil.check(alarm, 2)) {
- return Position.ALARM_OVERSPEED;
- }
- if (BitUtil.check(alarm, 4)) {
- return Position.ALARM_GEOFENCE;
- }
- if (BitUtil.check(alarm, 10)) {
- return Position.ALARM_SOS;
- }
- return null;
- }
-
- private void decodeAdc(Position position, ChannelBuffer buf, int length) {
- for (int i = 0; i < length / 2; i++) {
- int value = buf.readUnsignedShort();
- int id = BitUtil.from(value, 12);
- value = BitUtil.to(value, 12);
- switch (id) {
- case 0:
- position.set(Position.KEY_POWER, value * (100 + 10) / 4096.0 - 10);
- break;
- case 1:
- position.set(Position.PREFIX_TEMP + 1, value * (125 + 55) / 4096.0 - 55);
- break;
- case 2:
- position.set(Position.KEY_BATTERY, value * (100 + 10) / 4096.0 - 10);
- break;
- case 3:
- position.set(Position.PREFIX_ADC + 1, value * (100 + 10) / 4096.0 - 10);
- break;
- default:
- position.set(Position.PREFIX_IO + id, value);
- break;
- }
- }
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("*TS")
- .number("dd,") // protocol version
- .number("(d{15}),") // device id
- .number("(dd)(dd)(dd)") // time
- .number("(dd)(dd)(dd),") // date
- .expression("([^#]+)") // command
- .text("#")
- .compile();
-
- private Object decodeText(Channel channel, SocketAddress remoteAddress, String sentence) {
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))
- .setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- getLastLocation(position, dateBuilder.getDate());
-
- position.set(Position.KEY_RESULT, parser.next());
-
- return position;
- }
-
- private Object decodeBinary(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
-
- buf.readUnsignedByte(); // header
- buf.readUnsignedByte(); // version
- buf.readUnsignedByte(); // type
-
- String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- long seconds = buf.readUnsignedInt() & 0x7fffffffL;
- seconds += 946684800L; // 2000-01-01 00:00
- seconds -= timeZone;
- Date time = new Date(seconds * 1000);
-
- boolean hasLocation = false;
-
- while (buf.readableBytes() > 3) {
-
- int type = buf.readUnsignedByte();
- int length = type == DATA_CANBUS ? buf.readUnsignedShort() : buf.readUnsignedByte();
-
- switch (type) {
-
- case DATA_GPS:
- hasLocation = true;
- position.setValid(true);
- position.setLatitude(buf.readInt() / 1000000.0);
- position.setLongitude(buf.readInt() / 1000000.0);
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- position.setCourse(buf.readUnsignedShort());
- position.set(Position.KEY_HDOP, buf.readUnsignedShort());
- break;
-
- case DATA_LBS:
- if (length == 11) {
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedInt(), -buf.readUnsignedByte())));
- } else {
- position.setNetwork(new Network(CellTower.from(
- buf.readUnsignedShort(), buf.readUnsignedShort(),
- buf.readUnsignedShort(), buf.readUnsignedShort(), -buf.readUnsignedByte())));
- }
- if (length > 9 && length != 11) {
- buf.skipBytes(length - 9);
- }
- break;
-
- case DATA_STATUS:
- int status = buf.readUnsignedShort();
- position.set(Position.KEY_IGNITION, BitUtil.check(status, 9));
- position.set(Position.KEY_STATUS, status);
- position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedShort()));
- break;
-
- case DATA_ODOMETER:
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
- break;
-
- case DATA_ADC:
- decodeAdc(position, buf, length);
- break;
-
- case DATA_GEOFENCE:
- position.set("geofenceIn", buf.readUnsignedInt());
- position.set("geofenceAlarm", buf.readUnsignedInt());
- break;
-
- case DATA_OBD2:
- decodeObd(position, buf, length);
- break;
-
- case DATA_FUEL:
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt() / 10000.0);
- break;
-
- case DATA_OBD2_ALARM:
- decodeObd(position, buf, length);
- break;
-
- case DATA_HARSH_DRIVER:
- decodeDriverBehavior(position, buf);
- break;
-
- case DATA_CANBUS:
- position.set("can", ChannelBuffers.hexDump(buf.readBytes(length)));
- break;
-
- case DATA_J1708:
- decodeJ1708(position, buf, length);
- break;
-
- case DATA_VIN:
- position.set(Position.KEY_VIN, buf.readBytes(length).toString(StandardCharsets.US_ASCII));
- break;
-
- case DATA_RFID:
- position.set(Position.KEY_DRIVER_UNIQUE_ID,
- buf.readBytes(length - 1).toString(StandardCharsets.US_ASCII));
- position.set("authorized", buf.readUnsignedByte() != 0);
- break;
-
- case DATA_EVENT:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- if (length > 1) {
- position.set("eventMask", buf.readUnsignedInt());
- }
- break;
-
- default:
- buf.skipBytes(length);
- break;
- }
- }
-
- if (!hasLocation) {
- getLastLocation(position, time);
- } else {
- position.setTime(time);
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) {
-
- if (channel != null) {
- ChannelBuffer response = ChannelBuffers.dynamicBuffer();
- response.writeByte(0xF8);
- response.writeByte(DATA_GPS);
- response.writeByte(0xFE);
- response.writeShort(buf.getShort(response.writerIndex() - 1 - 2));
- response.writeShort(Checksum.crc16(Checksum.CRC16_XMODEM, response.toByteBuffer(1, 4)));
- response.writeByte(0xF8);
- channel.write(response);
- }
-
- return decodeBinary(channel, remoteAddress, buf);
- } else {
-
- if (channel != null) {
- channel.write(ChannelBuffers.copiedBuffer(String.format("*TS01,ACK:%04X#",
- Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer(1, buf.writerIndex() - 2))),
- StandardCharsets.US_ASCII));
- }
-
- return decodeText(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
- }
- }
-
-}
diff --git a/src/org/traccar/protocol/UproProtocol.java b/src/org/traccar/protocol/UproProtocol.java
deleted file mode 100644
index c00f859ee..000000000
--- a/src/org/traccar/protocol/UproProtocol.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.
- * 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.StringEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.CharacterDelimiterFrameDecoder;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class UproProtocol extends BaseProtocol {
-
- public UproProtocol() {
- super("upro");
- }
-
- @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("objectDecoder", new UproProtocolDecoder(UproProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java
deleted file mode 100644
index 7a0dca8a2..000000000
--- a/src/org/traccar/protocol/UproProtocolDecoder.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * 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.
- * 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.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.text.ParseException;
-import java.util.regex.Pattern;
-
-public class UproProtocolDecoder extends BaseProtocolDecoder {
-
- public UproProtocolDecoder(UproProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_HEADER = new PatternBuilder()
- .text("*")
- .expression("..20")
- .expression("([01])") // ack
- .number("(d+),") // device id
- .expression("(.)") // type
- .expression("(.)") // subtype
- .any()
- .compile();
-
- private static final Pattern PATTERN_LOCATION = new PatternBuilder()
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .number("(dd)(dd)(dddd)") // latitude
- .number("(ddd)(dd)(dddd)") // longitude
- .number("(d)") // flags
- .number("(dd)") // speed
- .number("(dd)") // course
- .number("(dd)(dd)(dd)") // date (ddmmyy)
- .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(0), parser.nextInt(0), parser.nextInt(0));
-
- 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(0);
- 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(0) * 2);
- position.setCourse(parser.nextInt(0) * 10);
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (buf.getByte(buf.readerIndex()) != '*') {
- throw new ParseException(null, 0);
- }
-
- int headerIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
- if (headerIndex < 0) {
- headerIndex = buf.writerIndex();
- }
- String header = buf.readBytes(headerIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
-
- Parser parser = new Parser(PATTERN_HEADER, header);
- if (!parser.matches()) {
- return null;
- }
-
- 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());
-
- String type = parser.next();
- String subtype = parser.next();
-
- if (reply && channel != null) {
- channel.write("*MG20Y" + type + subtype + "#");
- }
-
- while (buf.readable()) {
-
- buf.readByte(); // skip delimiter
-
- byte dataType = buf.readByte();
-
- int delimiterIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
- if (delimiterIndex < 0) {
- delimiterIndex = buf.writerIndex();
- }
-
- ChannelBuffer data = buf.readBytes(delimiterIndex - buf.readerIndex());
-
- switch (dataType) {
- case 'A':
- decodeLocation(position, data.toString(StandardCharsets.US_ASCII));
- break;
- case 'B':
- position.set(Position.KEY_STATUS, data.toString(StandardCharsets.US_ASCII));
- break;
- case 'C':
- long odometer = 0;
- while (data.readable()) {
- odometer <<= 4;
- odometer += data.readByte() - (byte) '0';
- }
- position.set(Position.KEY_ODOMETER, odometer * 2 * 1852 / 3600);
- break;
- case 'P':
- position.setNetwork(new Network(CellTower.from(
- Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII)),
- Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII)),
- Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16),
- Integer.parseInt(data.readBytes(4).toString(StandardCharsets.US_ASCII), 16))));
- break;
- case 'Q':
- position.set("obd-pid", ChannelBuffers.hexDump(data));
- break;
- case 'R':
- position.set("odb-travel", ChannelBuffers.hexDump(data));
- break;
- case 'S':
- position.set("obd-traffic", ChannelBuffers.hexDump(data));
- break;
- default:
- break;
- }
-
- }
-
- if (position.getLatitude() != 0 && position.getLongitude() != 0) {
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/V680Protocol.java b/src/org/traccar/protocol/V680Protocol.java
deleted file mode 100644
index 98c64830b..000000000
--- a/src/org/traccar/protocol/V680Protocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.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 V680Protocol extends BaseProtocol {
-
- public V680Protocol() {
- super("v680");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new V680ProtocolDecoder(V680Protocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new V680ProtocolDecoder(V680Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java
deleted file mode 100644
index 079a8eb08..000000000
--- a/src/org/traccar/protocol/V680ProtocolDecoder.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * 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.
- * 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 V680ProtocolDecoder extends BaseProtocolDecoder {
-
- public V680ProtocolDecoder(V680Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .groupBegin()
- .number("#(d+)#") // imei
- .expression("([^#]*)#") // user
- .groupEnd("?")
- .number("(d+)#") // fix
- .expression("([^#]+)#") // password
- .expression("([^#]+)#") // event
- .number("(d+)#") // packet number
- .expression("([^#]+)?#?") // gsm base station
- .expression("(?:[^#]+#)?")
- .number("(d+.d+),([EW]),") // longitude
- .number("(d+.d+),([NS]),") // latitude
- .number("(d+.d+),") // speed
- .number("(d+.?d*)?#") // course
- .number("(dd)(dd)(dd)#") // date (ddmmyy)
- .number("(dd)(dd)(dd)") // time (hhmmss)
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
- sentence = sentence.trim();
-
- if (sentence.length() == 16) {
-
- getDeviceSession(channel, remoteAddress, sentence.substring(1, sentence.length()));
-
- } else {
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession;
- if (parser.hasNext()) {
- deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- } else {
- deviceSession = getDeviceSession(channel, remoteAddress);
- }
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.set("user", parser.next());
- position.setValid(parser.nextInt(0) > 0);
- position.set("password", parser.next());
- position.set(Position.KEY_EVENT, parser.next());
- position.set("packet", parser.next());
- position.set("lbsData", parser.next());
-
- double lon = parser.nextDouble(0);
- boolean west = parser.next().equals("W");
- double lat = parser.nextDouble(0);
- 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(0));
- position.setCourse(parser.nextDouble(0));
-
- int day = parser.nextInt(0);
- int month = parser.nextInt(0);
- if (day == 0 && month == 0) {
- return null; // invalid date
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextInt(0), month, day)
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- return position;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/VisiontekProtocol.java b/src/org/traccar/protocol/VisiontekProtocol.java
deleted file mode 100644
index c6dd09562..000000000
--- a/src/org/traccar/protocol/VisiontekProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 VisiontekProtocol extends BaseProtocol {
-
- public VisiontekProtocol() {
- super("visiontek");
- }
-
- @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("stringDecoder", new StringDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectDecoder", new VisiontekProtocolDecoder(VisiontekProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
deleted file mode 100644
index f32c9fbfe..000000000
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.
- * 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.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 VisiontekProtocolDecoder extends BaseProtocolDecoder {
-
- public VisiontekProtocolDecoder(VisiontekProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("$1,")
- .expression("([^,]+),") // identifier
- .number("(d+),").optional() // imei
- .number("(dd),(dd),(dd),") // date (dd,mm,yy)
- .number("(dd),(dd),(dd),") // time (hh,mm,ss)
- .groupBegin()
- .number("(dd)(dd).?(d+)([NS]),") // latitude
- .number("(ddd)(dd).?(d+)([EW]),") // longitude
- .or()
- .number("(dd.d+)([NS]),") // latitude
- .number("(ddd.d+)([EW]),") // longitude
- .groupEnd()
- .number("(d+.?d+),") // speed
- .number("(d+),") // course
- .groupBegin()
- .number("(d+),") // altitude
- .number("(d+),") // satellites
- .number("(d+),") // odometer
- .number("([01]),") // ignition
- .number("([01]),") // input 1
- .number("([01]),") // input 2
- .number("([01]),") // immobilizer
- .number("([01]),") // external battery status
- .number("(d+),") // gsm
- .or()
- .number("(d+.d),") // hdop
- .number("(d+),") // altitude
- .number("(d+),") // odometer
- .number("([01],[01],[01],[01]),") // input
- .number("([01],[01],[01],[01]),") // output
- .number("(d+.?d*),") // adc 1
- .number("(d+.?d*),") // adc 2
- .groupEnd("?")
- .any()
- .expression("([AV])") // validity
- .number(",(d{10})").optional() // rfid
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- if (parser.hasNext(8)) {
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_MIN_MIN_HEM));
- }
- if (parser.hasNext(4)) {
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- }
-
- position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(
- parser.next().replace(".", "")) / 10));
-
- position.setCourse(parser.nextDouble(0));
-
- if (parser.hasNext(9)) {
- position.setAltitude(parser.nextDouble(0));
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_ODOMETER, parser.nextInt(0) * 1000);
- position.set(Position.KEY_IGNITION, parser.next().equals("1"));
- position.set(Position.PREFIX_IO + 1, parser.next());
- position.set(Position.PREFIX_IO + 2, parser.next());
- position.set("immobilizer", parser.next());
- position.set(Position.KEY_CHARGE, parser.next().equals("1"));
- position.set(Position.KEY_RSSI, parser.nextDouble());
- }
-
- if (parser.hasNext(7)) {
- position.set(Position.KEY_HDOP, parser.nextDouble());
- position.setAltitude(parser.nextDouble(0));
- position.set(Position.KEY_ODOMETER, parser.nextInt(0) * 1000);
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- }
-
- position.setValid(parser.next().equals("A"));
-
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Vt200FrameDecoder.java b/src/org/traccar/protocol/Vt200FrameDecoder.java
deleted file mode 100644
index adde12118..000000000
--- a/src/org/traccar/protocol/Vt200FrameDecoder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class Vt200FrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')') + 1;
- if (endIndex > 0) {
-
- ChannelBuffer frame = ChannelBuffers.dynamicBuffer();
-
- while (buf.readerIndex() < endIndex) {
- int b = buf.readByte();
- if (b == '=') {
- frame.writeByte(buf.readByte() ^ '=');
- } else {
- frame.writeByte(b);
- }
- }
-
- return frame;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/Vt200Protocol.java b/src/org/traccar/protocol/Vt200Protocol.java
deleted file mode 100644
index 59c61cb61..000000000
--- a/src/org/traccar/protocol/Vt200Protocol.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class Vt200Protocol extends BaseProtocol {
-
- public Vt200Protocol() {
- super("vt200");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new Vt200FrameDecoder());
- pipeline.addLast("objectDecoder", new Vt200ProtocolDecoder(Vt200Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java
deleted file mode 100644
index 2ae24efbb..000000000
--- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.BcdUtil;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.DateBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.Arrays;
-import java.util.Date;
-
-public class Vt200ProtocolDecoder extends BaseProtocolDecoder {
-
- public Vt200ProtocolDecoder(Vt200Protocol protocol) {
- super(protocol);
- }
-
- private static double decodeCoordinate(int value) {
- int degrees = value / 1000000;
- int minutes = value % 1000000;
- return degrees + minutes * 0.0001 / 60;
- }
-
- protected Date decodeDate(ChannelBuffer buf) {
- DateBuilder dateBuilder = new DateBuilder()
- .setDateReverse(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2))
- .setTime(BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2), BcdUtil.readInteger(buf, 2));
- return dateBuilder.getDate();
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(1); // header
-
- String id = ChannelBuffers.hexDump(buf.readBytes(6));
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
-
- int type = buf.readUnsignedShort();
- buf.readUnsignedShort(); // length
-
- if (type == 0x2086 || type == 0x2084 || type == 0x2082) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- buf.readUnsignedByte(); // data type
- buf.readUnsignedShort(); // trip id
-
- position.setTime(decodeDate(buf));
-
- position.setLatitude(decodeCoordinate(BcdUtil.readInteger(buf, 8)));
- position.setLongitude(decodeCoordinate(BcdUtil.readInteger(buf, 9)));
-
- int flags = buf.readUnsignedByte();
- position.setValid(BitUtil.check(flags, 0));
- if (!BitUtil.check(flags, 1)) {
- position.setLatitude(-position.getLatitude());
- }
- if (!BitUtil.check(flags, 1)) {
- position.setLongitude(-position.getLongitude());
- }
-
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.setCourse(buf.readUnsignedByte() * 2);
-
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
- position.set(Position.KEY_STATUS, buf.readUnsignedInt());
-
- // additional data
-
- return position;
-
- } else if (type == 0x3088) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- buf.readUnsignedShort(); // trip id
- buf.skipBytes(8); // imei
- buf.skipBytes(8); // imsi
-
- position.set("tripStart", decodeDate(buf).getTime());
- position.set("tripEnd", decodeDate(buf).getTime());
- position.set("drivingTime", buf.readUnsignedShort());
-
- position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
-
- position.set("maxSpeed", UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- position.set("maxRpm", buf.readUnsignedShort());
- position.set("maxTemp", buf.readUnsignedByte() - 40);
- position.set("hardAccelerationCount", buf.readUnsignedByte());
- position.set("hardBrakingCount", buf.readUnsignedByte());
-
- for (String speedType : Arrays.asList("over", "high", "normal", "low")) {
- position.set(speedType + "SpeedTime", buf.readUnsignedShort());
- position.set(speedType + "SpeedDistance", buf.readUnsignedInt());
- position.set(speedType + "SpeedFuel", buf.readUnsignedInt());
- }
-
- position.set("idleTime", buf.readUnsignedShort());
- position.set("idleFuel", buf.readUnsignedInt());
-
- position.set("hardCorneringCount", buf.readUnsignedByte());
- position.set("overspeedCount", buf.readUnsignedByte());
- position.set("overheatCount", buf.readUnsignedShort());
- position.set("laneChangeCount", buf.readUnsignedByte());
- position.set("emergencyRefueling", buf.readUnsignedByte());
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/VtfmsFrameDecoder.java b/src/org/traccar/protocol/VtfmsFrameDecoder.java
deleted file mode 100644
index 2e6033fcc..000000000
--- a/src/org/traccar/protocol/VtfmsFrameDecoder.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-public class VtfmsFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
- if (endIndex > 0) {
- endIndex += 1 + 3;
- if (buf.writerIndex() >= endIndex) {
- return buf.readBytes(endIndex - buf.readerIndex());
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/VtfmsProtocol.java b/src/org/traccar/protocol/VtfmsProtocol.java
deleted file mode 100644
index 61e0bf2b9..000000000
--- a/src/org/traccar/protocol/VtfmsProtocol.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.
- * 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.bootstrap.ServerBootstrap;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-
-import java.util.List;
-
-public class VtfmsProtocol extends BaseProtocol {
-
- public VtfmsProtocol() {
- super("vtfms");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new VtfmsFrameDecoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new VtfmsProtocolDecoder(VtfmsProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new VtfmsProtocolDecoder(VtfmsProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java
deleted file mode 100644
index 5fb687e6d..000000000
--- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.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 VtfmsProtocolDecoder extends BaseProtocolDecoder {
-
- private static final String[] DIRECTIONS = new String[] {"N", "NE", "E", "SE", "S", "SW", "W", "NW"};
-
- public VtfmsProtocolDecoder(VtfmsProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .text("(")
- .number("(d{15}),") // imei
- .number("[0-9A-Z]{3}dd,") // packet count
- .number("(dd),") // packet id
- .number("[^,]*,") // reserved
- .number("(d+)?,") // rssi
- .number("(?:d+)?,") // fix status
- .number("(d+)?,") // satellites
- .number("[^,]*,") // reserved
- .expression("([AV]),") // validity
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(dd)(dd)(dd),") // time (ddmmyy)
- .number("(-?d+.d+),") // latitude
- .number("(-?d+.d+),") // longitude
- .number("(?:(d+)|([NESW]{1,2})),") // course
- .number("(d+),") // speed
- .number("(d+),") // hours
- .number("(d+),") // idle hours
- .expression("[KNT],") // antenna status
- .number("(d+),") // odometer
- .expression("([01]),") // power status
- .number("(d+.d+),") // power voltage
- .number("[^,]*,") // reserved
- .number("(d+)?,") // fuel level
- .number("(d+.d+),") // adc 1
- .number("[^,]*,") // reserved
- .number("(d+.d+)?,") // adc 2
- .expression("([01]),") // di 1
- .expression("([01]),") // di 2
- .expression("([01]),") // di 3
- .expression("([01]),") // di 4
- .expression("([01]),") // do 1
- .expression("([01]),") // do 2
- .expression("([01]),") // do 3
- .number("[^,]*,") // reserved
- .number("[^,]*") // reserved
- .text(")")
- .number("ddd") // checksum
- .compile();
-
- private String decodeAlarm(int value) {
- switch (value) {
- case 10:
- return Position.ALARM_OVERSPEED;
- case 14:
- return Position.ALARM_POWER_CUT;
- case 15:
- return Position.ALARM_POWER_RESTORED;
- case 32:
- return Position.ALARM_BRAKING;
- case 33:
- return Position.ALARM_ACCELERATION;
- default:
- return null;
- }
- }
-
- @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());
-
- position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt()));
- position.set(Position.KEY_RSSI, parser.nextInt());
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- position.setValid(parser.next().equals("A"));
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY));
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
-
- if (parser.hasNext()) {
- position.setCourse(parser.nextDouble(0));
- }
- if (parser.hasNext()) {
- String direction = parser.next();
- for (int i = 0; i < DIRECTIONS.length; i++) {
- if (direction.equals(DIRECTIONS[i])) {
- position.setCourse(i * 45.0);
- break;
- }
- }
- }
-
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
-
- position.set(Position.KEY_HOURS, parser.nextInt());
- position.set("idleHours", parser.nextInt());
- position.set(Position.KEY_ODOMETER, parser.nextInt() * 100);
- position.set(Position.KEY_CHARGE, parser.next().equals("1"));
- position.set(Position.KEY_POWER, parser.nextDouble());
- position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
- position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
- position.set(Position.PREFIX_ADC + 2, parser.nextDouble());
- position.set(Position.PREFIX_IN + 1, parser.nextInt());
- position.set(Position.PREFIX_IN + 2, parser.nextInt());
- position.set(Position.PREFIX_IN + 3, parser.nextInt());
- position.set(Position.PREFIX_IN + 4, parser.nextInt());
- position.set(Position.PREFIX_OUT + 1, parser.nextInt());
- position.set(Position.PREFIX_OUT + 2, parser.nextInt());
- position.set(Position.PREFIX_OUT + 3, parser.nextInt());
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java
deleted file mode 100644
index 826a8b4d0..000000000
--- a/src/org/traccar/protocol/WatchFrameDecoder.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-
-import java.nio.charset.StandardCharsets;
-
-public class WatchFrameDecoder extends FrameDecoder {
-
- public static final int MESSAGE_HEADER = 20;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() >= MESSAGE_HEADER) {
- ChannelBuffer lengthBuffer = ChannelBuffers.dynamicBuffer();
- buf.getBytes(buf.readerIndex() + MESSAGE_HEADER - 4 - 1, lengthBuffer, 4);
- int length = Integer.parseInt(lengthBuffer.toString(StandardCharsets.US_ASCII), 16) + MESSAGE_HEADER + 1;
- if (buf.readableBytes() >= length) {
- ChannelBuffer frame = ChannelBuffers.dynamicBuffer();
- int endIndex = buf.readerIndex() + length;
- while (buf.readerIndex() < endIndex) {
- byte b = buf.readByte();
- if (b == 0x7D) {
- switch (buf.readByte()) {
- case 0x01:
- frame.writeByte(0x7D);
- break;
- case 0x02:
- frame.writeByte(0x5B);
- break;
- case 0x03:
- frame.writeByte(0x5D);
- break;
- case 0x04:
- frame.writeByte(0x2C);
- break;
- case 0x05:
- frame.writeByte(0x2A);
- break;
- default:
- throw new IllegalArgumentException();
- }
- } else {
- frame.writeByte(b);
- }
- }
- return frame;
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/WatchProtocol.java b/src/org/traccar/protocol/WatchProtocol.java
deleted file mode 100644
index 2be2dc9ae..000000000
--- a/src/org/traccar/protocol/WatchProtocol.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.StringEncoder;
-import org.traccar.BaseProtocol;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class WatchProtocol extends BaseProtocol {
-
- public WatchProtocol() {
- super("watch");
- setSupportedDataCommands(
- Command.TYPE_CUSTOM,
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_POSITION_PERIODIC,
- Command.TYPE_SOS_NUMBER,
- Command.TYPE_ALARM_SOS,
- Command.TYPE_ALARM_BATTERY,
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_ALARM_REMOVE,
- Command.TYPE_SILENCE_TIME,
- Command.TYPE_ALARM_CLOCK,
- Command.TYPE_SET_PHONEBOOK,
- Command.TYPE_VOICE_MESSAGE,
- Command.TYPE_SET_TIMEZONE,
- Command.TYPE_SET_INDICATOR);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new WatchFrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new WatchProtocolEncoder());
- pipeline.addLast("objectDecoder", new WatchProtocolDecoder(WatchProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
deleted file mode 100644
index 86dc9456d..000000000
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.BitUtil;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.CellTower;
-import org.traccar.model.Network;
-import org.traccar.model.Position;
-import org.traccar.model.WifiAccessPoint;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class WatchProtocolDecoder extends BaseProtocolDecoder {
-
- public WatchProtocolDecoder(WatchProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN_POSITION = new PatternBuilder()
- .number("(dd)(dd)(dd),") // date (ddmmyy)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([AV]),") // validity
- .number(" *(-?d+.d+),") // latitude
- .expression("([NS]),")
- .number(" *(-?d+.d+),") // longitude
- .expression("([EW])?,")
- .number("(d+.d+),") // speed
- .number("(d+.?d*),") // course
- .number("(d+.?d*),") // altitude
- .number("(d+),") // satellites
- .number("(d+),") // rssi
- .number("(d+),") // battery
- .number("(d+),") // steps
- .number("d+,") // tumbles
- .number("(x+),") // status
- .expression("(.*)") // cell and wifi
- .compile();
-
- private void sendResponse(Channel channel, String manufacturer, String id, String content) {
- if (channel != null) {
- channel.write(String.format(
- "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
- }
- }
-
- private String decodeAlarm(int status) {
- if (BitUtil.check(status, 0)) {
- return Position.ALARM_LOW_BATTERY;
- } else if (BitUtil.check(status, 1)) {
- return Position.ALARM_GEOFENCE_EXIT;
- } else if (BitUtil.check(status, 2)) {
- return Position.ALARM_GEOFENCE_ENTER;
- } else if (BitUtil.check(status, 3)) {
- return Position.ALARM_OVERSPEED;
- } else if (BitUtil.check(status, 16)) {
- return Position.ALARM_SOS;
- } else if (BitUtil.check(status, 17)) {
- return Position.ALARM_LOW_BATTERY;
- } else if (BitUtil.check(status, 18)) {
- return Position.ALARM_GEOFENCE_EXIT;
- } else if (BitUtil.check(status, 19)) {
- return Position.ALARM_GEOFENCE_ENTER;
- } else if (BitUtil.check(status, 20)) {
- return Position.ALARM_REMOVING;
- } else if (BitUtil.check(status, 21)) {
- return Position.ALARM_FALL_DOWN;
- }
- return null;
- }
-
- private void decodeTail(Position position, String data) {
- String[] values = data.split(",");
- int index = 0;
-
- Network network = new Network();
-
- int cellCount = Integer.parseInt(values[index++]);
- index += 1; // timing advance
- int mcc = Integer.parseInt(values[index++]);
- int mnc = Integer.parseInt(values[index++]);
-
- for (int i = 0; i < cellCount; i++) {
- network.addCellTower(CellTower.from(mcc, mnc,
- Integer.parseInt(values[index++]), Integer.parseInt(values[index++]),
- Integer.parseInt(values[index++])));
- }
-
- if (index < values.length && !values[index].isEmpty()) {
- int wifiCount = Integer.parseInt(values[index++]);
-
- for (int i = 0; i < wifiCount; i++) {
- index += 1; // wifi name
- network.addWifiAccessPoint(WifiAccessPoint.from(
- values[index++], Integer.parseInt(values[index++])));
- }
- }
-
- if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
- position.setNetwork(network);
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- buf.skipBytes(1); // header
- String manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
- buf.skipBytes(1); // delimiter
-
- String id = buf.readBytes(10).toString(StandardCharsets.US_ASCII);
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
- if (deviceSession == null) {
- return null;
- }
-
- buf.skipBytes(1); // delimiter
- buf.skipBytes(4); // length
- buf.skipBytes(1); // delimiter
-
- buf.writerIndex(buf.writerIndex() - 1); // ignore ending
-
- int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
- if (contentIndex < 0) {
- contentIndex = buf.writerIndex();
- }
-
- String type = buf.readBytes(contentIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
-
- if (contentIndex < buf.writerIndex()) {
- buf.readerIndex(contentIndex + 1);
- }
-
- if (type.equals("LK")) {
-
- sendResponse(channel, manufacturer, id, "LK");
-
- if (buf.readable()) {
- String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
- if (values.length >= 3) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_BATTERY_LEVEL, Integer.parseInt(values[2]));
-
- return position;
- }
- }
-
- } else if (type.equals("UD") || type.equals("UD2") || type.equals("UD3")
- || type.equals("AL") || type.equals("WT")) {
-
- if (type.equals("AL")) {
- sendResponse(channel, manufacturer, id, "AL");
- }
-
- Parser parser = new Parser(PATTERN_POSITION, buf.toString(StandardCharsets.US_ASCII));
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
-
- position.set(Position.KEY_STEPS, parser.nextInt(0));
-
- int status = parser.nextHexInt(0);
- position.set(Position.KEY_ALARM, decodeAlarm(status));
- if (BitUtil.check(status, 4)) {
- position.set(Position.KEY_MOTION, true);
- }
-
- decodeTail(position, parser.next());
-
- return position;
-
- } else if (type.equals("TKQ")) {
-
- sendResponse(channel, manufacturer, id, "TKQ");
-
- } else if (type.equals("PULSE") || type.equals("heart")) {
-
- if (buf.readable()) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, new Date());
-
- position.setValid(false);
- String pulse = buf.toString(StandardCharsets.US_ASCII);
- position.set("pulse", pulse);
- position.set(Position.KEY_RESULT, pulse);
-
- return position;
-
- }
-
- } else if (type.equals("img")) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- int timeIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
- buf.readerIndex(timeIndex + 12 + 2);
- position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(id, buf, "jpg"));
-
- return position;
-
- } else if (type.equals("TK")) {
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- getLastLocation(position, null);
-
- position.set(Position.KEY_AUDIO, Context.getMediaManager().writeFile(id, buf, "amr"));
-
- return position;
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
deleted file mode 100644
index d2d3b52d1..000000000
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@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;
-
-import javax.xml.bind.DatatypeConverter;
-import java.nio.charset.StandardCharsets;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.TimeZone;
-
-public class WatchProtocolEncoder extends StringProtocolEncoder implements StringProtocolEncoder.ValueFormatter {
-
- @Override
- public String formatValue(String key, Object value) {
- if (key.equals(Command.KEY_TIMEZONE)) {
- double offset = TimeZone.getTimeZone((String) value).getRawOffset() / 3600000.0;
- DecimalFormat fmt = new DecimalFormat("+#.##;-#.##", DecimalFormatSymbols.getInstance(Locale.US));
- return fmt.format(offset);
- }
-
- return null;
- }
-
-
- @Override
- protected String formatCommand(Command command, String format, String... keys) {
- String content = formatCommand(command, format, this, keys);
- return String.format("[CS*%s*%04x*%s]",
- getUniqueId(command.getDeviceId()), content.length(), content);
- }
-
- private int getEnableFlag(Command command) {
- if (command.getBoolean(Command.KEY_ENABLE)) {
- return 1;
- } else {
- return 0;
- }
- }
-
- private static Map<Byte, Byte> mapping = new HashMap<>();
-
- static {
- mapping.put((byte) 0x7d, (byte) 0x01);
- mapping.put((byte) 0x5B, (byte) 0x02);
- mapping.put((byte) 0x5D, (byte) 0x03);
- mapping.put((byte) 0x2C, (byte) 0x04);
- mapping.put((byte) 0x2A, (byte) 0x05);
- }
-
- private String getBinaryData(Command command) {
- byte[] data = DatatypeConverter.parseHexBinary(command.getString(Command.KEY_DATA));
-
- int encodedLength = data.length;
- for (byte b : data) {
- if (mapping.containsKey(b)) {
- encodedLength += 1;
- }
- }
-
- int index = 0;
- byte[] encodedData = new byte[encodedLength];
-
- for (byte b : data) {
- Byte replacement = mapping.get(b);
- if (replacement != null) {
- encodedData[index] = 0x7D;
- index += 1;
- encodedData[index] = replacement;
- } else {
- encodedData[index] = b;
- }
- index += 1;
- }
-
- return new String(encodedData, StandardCharsets.US_ASCII);
- }
-
- @Override
- protected Object encodeCommand(Command command) {
-
- switch (command.getType()) {
- case Command.TYPE_CUSTOM:
- return formatCommand(command, command.getString(Command.KEY_DATA));
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "RG");
- case Command.TYPE_SOS_NUMBER:
- return formatCommand(command, "SOS{%s},{%s}", Command.KEY_INDEX, Command.KEY_PHONE);
- case Command.TYPE_ALARM_SOS:
- return formatCommand(command, "SOSSMS," + getEnableFlag(command));
- case Command.TYPE_ALARM_BATTERY:
- return formatCommand(command, "LOWBAT," + getEnableFlag(command));
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "RESET");
- case Command.TYPE_ALARM_REMOVE:
- return formatCommand(command, "REMOVE," + getEnableFlag(command));
- case Command.TYPE_SILENCE_TIME:
- return formatCommand(command, "SILENCETIME,{%s}", Command.KEY_DATA);
- case Command.TYPE_ALARM_CLOCK:
- return formatCommand(command, "REMIND,{%s}", Command.KEY_DATA);
- case Command.TYPE_SET_PHONEBOOK:
- return formatCommand(command, "PHB,{%s}", Command.KEY_DATA);
- case Command.TYPE_VOICE_MESSAGE:
- return formatCommand(command, "TK," + getBinaryData(command));
- case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(command, "UPLOAD,{%s}", Command.KEY_FREQUENCY);
- case Command.TYPE_SET_TIMEZONE:
- return formatCommand(command, "LZ,,{%s}", Command.KEY_TIMEZONE);
- case Command.TYPE_SET_INDICATOR:
- return formatCommand(command, "FLOWER,{%s}", Command.KEY_DATA);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/WialonProtocol.java b/src/org/traccar/protocol/WialonProtocol.java
deleted file mode 100644
index 02da154e2..000000000
--- a/src/org/traccar/protocol/WialonProtocol.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.
- * 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.Context;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-
-public class WialonProtocol extends BaseProtocol {
-
- public WialonProtocol() {
- super("wialon");
- setSupportedDataCommands(
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_SEND_USSD,
- Command.TYPE_IDENTIFICATION,
- Command.TYPE_OUTPUT_CONTROL);
- }
-
- @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(4 * 1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- boolean utf8 = Context.getConfig().getBoolean(getName() + ".utf8");
- if (utf8) {
- pipeline.addLast("stringDecoder", new StringDecoder(StandardCharsets.UTF_8));
- } else {
- pipeline.addLast("stringDecoder", new StringDecoder());
- }
- pipeline.addLast("objectEncoder", new WialonProtocolEncoder());
- pipeline.addLast("objectDecoder", new WialonProtocolDecoder(WialonProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
deleted file mode 100644
index 4eb3b9b8e..000000000
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class WialonProtocolDecoder extends BaseProtocolDecoder {
-
- public WialonProtocolDecoder(WialonProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("(dd)(dd)(dd);") // date (ddmmyy)
- .number("(dd)(dd)(dd);") // time (hhmmss)
- .number("(dd)(dd.d+);") // latitude
- .expression("([NS]);")
- .number("(ddd)(dd.d+);") // longitude
- .expression("([EW]);")
- .number("(d+.?d*)?;") // speed
- .number("(d+.?d*)?;") // course
- .number("(?:NA|(d+.?d*));") // altitude
- .number("(?:NA|(d+))") // satellites
- .groupBegin().text(";")
- .number("(?:NA|(d+.?d*));") // hdop
- .number("(?:NA|(d+));") // inputs
- .number("(?:NA|(d+));") // outputs
- .expression("(?:NA|([^;]*));") // adc
- .expression("(?:NA|([^;]*));") // ibutton
- .expression("(?:NA|(.*))") // params
- .groupEnd("?")
- .compile();
-
- private void sendResponse(Channel channel, String prefix, Integer number) {
- if (channel != null) {
- StringBuilder response = new StringBuilder(prefix);
- if (number != null) {
- response.append(number);
- }
- response.append("\r\n");
- channel.write(response.toString());
- }
- }
-
- private Position decodePosition(Channel channel, SocketAddress remoteAddress, String substring) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
- }
-
- Parser parser = new Parser(PATTERN, substring);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
-
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- if (parser.hasNext()) {
- int satellites = parser.nextInt(0);
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
- }
-
- position.set(Position.KEY_HDOP, parser.nextDouble());
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
-
- if (parser.hasNext()) {
- String[] values = parser.next().split(",");
- for (int i = 0; i < values.length; i++) {
- position.set(Position.PREFIX_ADC + (i + 1), values[i]);
- }
- }
-
- position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
-
- if (parser.hasNext()) {
- String[] values = parser.next().split(",");
- for (String param : values) {
- Matcher paramParser = Pattern.compile("(.*):[1-3]:(.*)").matcher(param);
- if (paramParser.matches()) {
- try {
- position.set(paramParser.group(1).toLowerCase(), Double.parseDouble(paramParser.group(2)));
- } catch (NumberFormatException e) {
- position.set(paramParser.group(1).toLowerCase(), paramParser.group(2));
- }
- }
- }
- }
-
- return position;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- if (sentence.startsWith("#L#")) {
-
- String[] values = sentence.substring(3).split(";");
-
- String imei = values[0].indexOf('.') >= 0 ? values[1] : values[0];
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
- if (deviceSession != null) {
- sendResponse(channel, "#AL#", 1);
- }
-
- } else if (sentence.startsWith("#P#")) {
-
- sendResponse(channel, "#AP#", null); // heartbeat
-
- } else if (sentence.startsWith("#SD#") || sentence.startsWith("#D#")) {
-
- Position position = decodePosition(
- channel, remoteAddress, sentence.substring(sentence.indexOf('#', 1) + 1));
-
- if (position != null) {
- sendResponse(channel, "#AD#", 1);
- return position;
- }
-
- } else if (sentence.startsWith("#B#")) {
-
- String[] messages = sentence.substring(sentence.indexOf('#', 1) + 1).split("\\|");
- List<Position> positions = new LinkedList<>();
-
- for (String message : messages) {
- Position position = decodePosition(channel, remoteAddress, message);
- if (position != null) {
- position.set(Position.KEY_ARCHIVE, true);
- positions.add(position);
- }
- }
-
- sendResponse(channel, "#AB#", messages.length);
- if (!positions.isEmpty()) {
- return positions;
- }
-
- } else if (sentence.startsWith("#M#")) {
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession != null) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- getLastLocation(position, new Date());
- position.setValid(false);
- position.set(Position.KEY_RESULT, sentence.substring(sentence.indexOf('#', 1) + 1));
- sendResponse(channel, "#AM#", 1);
- return position;
- }
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/WialonProtocolEncoder.java b/src/org/traccar/protocol/WialonProtocolEncoder.java
deleted file mode 100644
index 9c60a1356..000000000
--- a/src/org/traccar/protocol/WialonProtocolEncoder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.protocol;
-
-import org.traccar.StringProtocolEncoder;
-import org.traccar.helper.Log;
-import org.traccar.model.Command;
-
-public class WialonProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
- switch (command.getType()) {
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "reboot\r\n");
- case Command.TYPE_SEND_USSD:
- return formatCommand(command, "USSD:{%s}\r\n", Command.KEY_PHONE);
- case Command.TYPE_IDENTIFICATION:
- return formatCommand(command, "VER?\r\n");
- case Command.TYPE_OUTPUT_CONTROL:
- return formatCommand(command, "L{%s}={%s}\r\n", Command.KEY_INDEX, Command.KEY_DATA);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
- return null;
- }
-}
diff --git a/src/org/traccar/protocol/WondexFrameDecoder.java b/src/org/traccar/protocol/WondexFrameDecoder.java
deleted file mode 100644
index db65ff80f..000000000
--- a/src/org/traccar/protocol/WondexFrameDecoder.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
-
-public class WondexFrameDecoder extends FrameDecoder {
-
- private static final int KEEP_ALIVE_LENGTH = 8;
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < KEEP_ALIVE_LENGTH) {
- return null;
- }
-
- if (buf.getUnsignedByte(buf.readerIndex()) == 0xD0) {
-
- // Send response
- ChannelBuffer frame = buf.readBytes(KEEP_ALIVE_LENGTH);
- if (channel != null) {
- channel.write(frame);
- }
- return frame;
-
- } else {
-
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
- if (index != -1) {
- ChannelBuffer frame = buf.readBytes(index - buf.readerIndex());
- buf.skipBytes(2);
- return frame;
- }
-
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/WondexProtocol.java b/src/org/traccar/protocol/WondexProtocol.java
deleted file mode 100644
index ef25265aa..000000000
--- a/src/org/traccar/protocol/WondexProtocol.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.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;
-
-public class WondexProtocol extends BaseProtocol {
-
- public WondexProtocol() {
- super("wondex");
- setTextCommandEncoder(new WondexProtocolEncoder());
- setSupportedCommands(
- Command.TYPE_GET_DEVICE_STATUS,
- Command.TYPE_GET_MODEM_STATUS,
- Command.TYPE_REBOOT_DEVICE,
- Command.TYPE_POSITION_SINGLE,
- Command.TYPE_GET_VERSION,
- Command.TYPE_IDENTIFICATION);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new WondexFrameDecoder());
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new WondexProtocolEncoder());
- pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("objectEncoder", new WondexProtocolEncoder());
- pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
deleted file mode 100644
index e27745f38..000000000
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.DeviceSession;
-import org.traccar.helper.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class WondexProtocolDecoder extends BaseProtocolDecoder {
-
- public WondexProtocolDecoder(WondexProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("[^d]*") // header
- .number("(d+),") // device identifier
- .number("(dddd)(dd)(dd)") // date (yyyymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("(-?d+.d+),") // longitude
- .number("(-?d+.d+),") // latitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(-?d+.?d*),") // altitude
- .number("(d+),") // satellites
- .number("(d+),?") // event
- .number("(d+.d+)V,").optional() // battery
- .number("(d+.d+)?,?") // odometer
- .number("(d+)?,?") // input
- .number("(d+.d+)?,?") // adc1
- .number("(d+.d+)?,?") // adc2
- .number("(d+)?") // output
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- if (buf.getUnsignedByte(0) == 0xD0) {
-
- long deviceId = ((Long.reverseBytes(buf.getLong(0))) >> 32) & 0xFFFFFFFFL;
- getDeviceSession(channel, remoteAddress, String.valueOf(deviceId));
-
- return null;
- } else if (buf.toString(StandardCharsets.US_ASCII).startsWith("$OK:")
- || buf.toString(StandardCharsets.US_ASCII).startsWith("$ERR:")
- || buf.toString(StandardCharsets.US_ASCII).startsWith("$MSG:")) {
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
- getLastLocation(position, new Date());
- position.set(Position.KEY_RESULT, buf.toString(StandardCharsets.US_ASCII));
-
- return position;
- } else {
-
- Parser parser = new Parser(PATTERN, buf.toString(StandardCharsets.US_ASCII));
- 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.setTime(parser.nextDateTime());
-
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
-
- int satellites = parser.nextInt(0);
- position.setValid(satellites != 0);
- position.set(Position.KEY_SATELLITES, satellites);
-
- position.set(Position.KEY_EVENT, parser.next());
- position.set(Position.KEY_BATTERY, parser.nextDouble());
- if (parser.hasNext()) {
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- }
- position.set(Position.KEY_INPUT, parser.next());
- position.set(Position.PREFIX_ADC + 1, parser.next());
- position.set(Position.PREFIX_ADC + 2, parser.next());
- position.set(Position.KEY_OUTPUT, parser.next());
-
- return position;
- }
-
- }
-
-}
diff --git a/src/org/traccar/protocol/WondexProtocolEncoder.java b/src/org/traccar/protocol/WondexProtocolEncoder.java
deleted file mode 100644
index 6258c1fe6..000000000
--- a/src/org/traccar/protocol/WondexProtocolEncoder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 WondexProtocolEncoder extends StringProtocolEncoder {
- @Override
- protected Object encodeCommand(Command command) {
-
- initDevicePassword(command, "0000");
-
- switch (command.getType()) {
- case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "$WP+REBOOT={%s}", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_GET_DEVICE_STATUS:
- return formatCommand(command, "$WP+TEST={%s}", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_GET_MODEM_STATUS:
- return formatCommand(command, "$WP+GSMINFO={%s}", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_IDENTIFICATION:
- return formatCommand(command, "$WP+IMEI={%s}", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "$WP+GETLOCATION={%s}", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_GET_VERSION:
- return formatCommand(command, "$WP+VER={%s}", Command.KEY_DEVICE_PASSWORD);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/XexunFrameDecoder.java b/src/org/traccar/protocol/XexunFrameDecoder.java
deleted file mode 100644
index 801fb4d59..000000000
--- a/src/org/traccar/protocol/XexunFrameDecoder.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.
- * 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.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.handler.codec.frame.FrameDecoder;
-import org.traccar.helper.StringFinder;
-
-public class XexunFrameDecoder extends FrameDecoder {
-
- @Override
- protected Object decode(
- ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
-
- if (buf.readableBytes() < 80) {
- return null;
- }
-
- int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
- if (beginIndex == -1) {
- beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GNRMC"));
- if (beginIndex == -1) {
- return null;
- }
- }
-
- int identifierIndex = buf.indexOf(beginIndex, buf.writerIndex(), new StringFinder("imei:"));
- if (identifierIndex == -1) {
- return null;
- }
-
- int endIndex = buf.indexOf(identifierIndex, buf.writerIndex(), (byte) ',');
- if (endIndex == -1) {
- return null;
- }
-
- buf.skipBytes(beginIndex - buf.readerIndex());
-
- return buf.readBytes(endIndex - beginIndex + 1);
- }
-
-}
diff --git a/src/org/traccar/protocol/XexunProtocol.java b/src/org/traccar/protocol/XexunProtocol.java
deleted file mode 100644
index b90cbfaaf..000000000
--- a/src/org/traccar/protocol/XexunProtocol.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * 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.Context;
-import org.traccar.TrackerServer;
-import org.traccar.model.Command;
-
-import java.util.List;
-
-public class XexunProtocol extends BaseProtocol {
-
- public XexunProtocol() {
- super("xexun");
- setSupportedDataCommands(
- Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- boolean full = Context.getConfig().getBoolean(getName() + ".extended");
- if (full) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024)); // tracker bug \n\r
- } else {
- pipeline.addLast("frameDecoder", new XexunFrameDecoder());
- }
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectEncoder", new XexunProtocolEncoder());
- pipeline.addLast("objectDecoder", new XexunProtocolDecoder(XexunProtocol.this, full));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java
deleted file mode 100644
index bb4b4f48c..000000000
--- a/src/org/traccar/protocol/XexunProtocolDecoder.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@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 XexunProtocolDecoder extends BaseProtocolDecoder {
-
- private final boolean full;
-
- public XexunProtocolDecoder(XexunProtocol protocol, boolean full) {
- super(protocol);
- this.full = full;
- }
-
- private static final Pattern PATTERN_BASIC = new PatternBuilder()
- .expression("G[PN]RMC,")
- .number("(?:(dd)(dd)(dd))?.?d*,") // time (hhmmss)
- .expression("([AV]),") // validity
- .number("(d*?)(d?d.d+),([NS]),") // latitude
- .number("(d*?)(d?d.d+),([EW])?,") // longitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*)?,") // course
- .number("(?:(dd)(dd)(dd))?,") // date (ddmmyy)
- .expression("[^*]*").text("*")
- .number("xx") // checksum
- .expression("\\r\\n").optional()
- .expression(",([FL]),") // signal
- .expression("([^,]*),").optional() // alarm
- .any()
- .number("imei:(d+),") // imei
- .compile();
-
- private static final Pattern PATTERN_FULL = new PatternBuilder()
- .any()
- .number("(d+),") // serial
- .expression("([^,]+)?,") // phone number
- .expression(PATTERN_BASIC.pattern())
- .number("(d+),") // satellites
- .number("(-?d+.d+)?,") // altitude
- .number("[FL]:(d+.d+)V") // power
- .any()
- .compile();
-
- private String decodeStatus(Position position, String value) {
- if (value != null) {
- switch (value.toLowerCase()) {
- case "acc on":
- case "accstart":
- position.set(Position.KEY_IGNITION, true);
- break;
- case "acc off":
- case "accstop":
- position.set(Position.KEY_IGNITION, false);
- break;
- case "help me!":
- position.set(Position.KEY_ALARM, Position.ALARM_SOS);
- break;
- case "low battery":
- position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
- break;
- case "move!":
- case "moved!":
- position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
- break;
- default:
- break;
- }
- }
- return null;
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- Pattern pattern = PATTERN_BASIC;
- if (full) {
- pattern = PATTERN_FULL;
- }
-
- Parser parser = new Parser(pattern, (String) msg);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- if (full) {
- position.set("serial", parser.next());
- position.set("number", parser.next());
- }
-
- DateBuilder dateBuilder = new DateBuilder()
- .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
-
- position.setValid(parser.next().equals("A"));
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
-
- position.setSpeed(convertSpeed(parser.nextDouble(0), "kn"));
-
- position.setCourse(parser.nextDouble(0));
-
- dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
- position.setTime(dateBuilder.getDate());
-
- position.set("signal", parser.next());
-
- decodeStatus(position, parser.next());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- if (full) {
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
- position.setAltitude(parser.nextDouble(0));
-
- position.set(Position.KEY_POWER, parser.nextDouble(0));
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/XexunProtocolEncoder.java b/src/org/traccar/protocol/XexunProtocolEncoder.java
deleted file mode 100644
index cdf3ac6f7..000000000
--- a/src/org/traccar/protocol/XexunProtocolEncoder.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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 XexunProtocolEncoder extends StringProtocolEncoder {
-
- @Override
- protected Object encodeCommand(Command command) {
-
- initDevicePassword(command, "123456");
-
- switch (command.getType()) {
- case Command.TYPE_ENGINE_STOP:
- return formatCommand(command, "powercar{%s} 11", Command.KEY_DEVICE_PASSWORD);
- case Command.TYPE_ENGINE_RESUME:
- return formatCommand(command, "powercar{%s} 00", Command.KEY_DEVICE_PASSWORD);
- default:
- Log.warning(new UnsupportedOperationException(command.getType()));
- break;
- }
-
- return null;
- }
-
-}
diff --git a/src/org/traccar/protocol/XirgoProtocol.java b/src/org/traccar/protocol/XirgoProtocol.java
deleted file mode 100644
index 9d7475308..000000000
--- a/src/org/traccar/protocol/XirgoProtocol.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.
- * 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.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 XirgoProtocol extends BaseProtocol {
-
- public XirgoProtocol() {
- super("xirgo");
- }
-
- @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 XirgoProtocolDecoder(XirgoProtocol.this));
- }
- });
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new XirgoProtocolDecoder(XirgoProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
deleted file mode 100644
index b1442170d..000000000
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@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.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 XirgoProtocolDecoder extends BaseProtocolDecoder {
-
- public XirgoProtocolDecoder(XirgoProtocol protocol) {
- super(protocol);
- }
-
- private Boolean newFormat;
-
- private static final Pattern PATTERN_OLD = new PatternBuilder()
- .text("$$")
- .number("(d+),") // imei
- .number("(d+),") // event
- .number("(dddd)/(dd)/(dd),") // date (yyyy/mm/dd)
- .number("(dd):(dd):(dd),") // time (hh:mm:ss)
- .number("(-?d+.?d*),") // latitude
- .number("(-?d+.?d*),") // longitude
- .number("(-?d+.?d*),") // altitude
- .number("(d+.?d*),") // speed
- .number("(d+.?d*),") // course
- .number("(d+),") // satellites
- .number("(d+.?d*),") // hdop
- .number("(d+.d+),") // battery
- .number("(d+),") // gsm
- .number("(d+.?d*),") // odometer
- .number("(d+),") // gps
- .any()
- .compile();
-
- private static final Pattern PATTERN_NEW = new PatternBuilder()
- .text("$$")
- .number("(d+),") // imei
- .number("(d+),") // event
- .number("(dddd)/(dd)/(dd),") // date (yyyy/mm/dd)
- .number("(dd):(dd):(dd),") // time (hh:mm:ss)
- .number("(-?d+.?d*),") // latitude
- .number("(-?d+.?d*),") // longitude
- .number("(-?d+.?d*),") // altitude
- .number("(d+.?d*),") // speed
- .number("d+.?d*,") // acceleration
- .number("d+.?d*,") // deceleration
- .number("d+,")
- .number("(d+.?d*),") // course
- .number("(d+),") // satellites
- .number("(d+.?d*),") // hdop
- .number("(d+.?d*),") // odometer
- .number("(d+.?d*),") // fuel consumption
- .number("(d+.d+),") // battery
- .number("(d+),") // gsm
- .number("(d+),") // gps
- .groupBegin()
- .number("d,") // reset mode
- .expression("([01])") // input 1
- .expression("([01])") // input 1
- .expression("([01])") // input 1
- .expression("([01]),") // output 1
- .number("(d+.?d*),") // adc 1
- .number("(d+.?d*),") // fuel level
- .number("d+,") // engine load
- .number("(d+),") // engine hours
- .number("(d+),") // oil pressure
- .number("(d+),") // oil level
- .number("(-?d+),") // oil temperature
- .number("(d+),") // coolant pressure
- .number("(d+),") // coolant level
- .number("(-?d+)") // coolant temperature
- .groupEnd("?")
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- Parser parser;
- if (newFormat == null) {
- parser = new Parser(PATTERN_NEW, sentence);
- if (parser.matches()) {
- newFormat = true;
- } else {
- parser = new Parser(PATTERN_OLD, sentence);
- if (parser.matches()) {
- newFormat = false;
- } else {
- return null;
- }
- }
- } else {
- if (newFormat) {
- parser = new Parser(PATTERN_NEW, sentence);
- } else {
- parser = new Parser(PATTERN_OLD, 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(Position.KEY_EVENT, parser.next());
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_HDOP, parser.nextDouble());
-
- if (newFormat) {
- position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(parser.nextDouble(0)));
- position.set(Position.KEY_FUEL_CONSUMPTION, parser.next());
- }
-
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_RSSI, parser.nextDouble());
-
- if (!newFormat) {
- position.set(Position.KEY_ODOMETER, UnitsConverter.metersFromMiles(parser.nextDouble(0)));
- }
-
- position.setValid(parser.nextInt(0) == 1);
-
- if (newFormat && parser.hasNext(13)) {
- position.set(Position.PREFIX_IN + 1, parser.nextInt());
- position.set(Position.PREFIX_IN + 2, parser.nextInt());
- position.set(Position.PREFIX_IN + 3, parser.nextInt());
- position.set(Position.PREFIX_OUT + 1, parser.nextInt());
- position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
- position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble());
- position.set(Position.KEY_HOURS, parser.nextInt());
- position.set("oilPressure", parser.nextInt());
- position.set("oilLevel", parser.nextInt());
- position.set("oilTemp", parser.nextInt());
- position.set("coolantPressure", parser.nextInt());
- position.set("coolantLevel", parser.nextInt());
- position.set("coolantTemp", parser.nextInt());
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Xt013Protocol.java b/src/org/traccar/protocol/Xt013Protocol.java
deleted file mode 100644
index ad3e24df0..000000000
--- a/src/org/traccar/protocol/Xt013Protocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 Xt013Protocol extends BaseProtocol {
-
- public Xt013Protocol() {
- super("xt013");
- }
-
- @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 Xt013ProtocolDecoder(Xt013Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
deleted file mode 100644
index f1214fdb4..000000000
--- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.
- * 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.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 Xt013ProtocolDecoder extends BaseProtocolDecoder {
-
- public Xt013ProtocolDecoder(Xt013Protocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .number("HI,d+").optional()
- .text("TK,")
- .number("(d+),") // imei
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .number("([+-]d+.d+),") // latitude
- .number("([+-]d+.d+),") // longitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("d+,")
- .number("(d+),") // altitude
- .expression("([FL]),") // gps fix
- .number("d+,")
- .number("(d+),") // gps level
- .number("x+,")
- .number("x+,")
- .number("(d+),") // gsm level
- .expression("[^,]*,")
- .number("(d+.d+),") // battery
- .number("(d),") // charging
- .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;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setLatitude(parser.nextDouble(0));
- position.setLongitude(parser.nextDouble(0));
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
- position.setCourse(parser.nextDouble(0));
- position.setAltitude(parser.nextDouble(0));
- position.setValid(parser.next().equals("F"));
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
- position.set(Position.KEY_RSSI, parser.nextDouble());
- position.set(Position.KEY_BATTERY, parser.nextDouble(0));
- position.set(Position.KEY_CHARGE, parser.next().equals("1"));
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/Xt2400Protocol.java b/src/org/traccar/protocol/Xt2400Protocol.java
deleted file mode 100644
index 0c5e9cd4c..000000000
--- a/src/org/traccar/protocol/Xt2400Protocol.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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 Xt2400Protocol extends BaseProtocol {
-
- public Xt2400Protocol() {
- super("xt2400");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("objectDecoder", new Xt2400ProtocolDecoder(Xt2400Protocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
deleted file mode 100644
index 15e8558be..000000000
--- a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@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.channel.Channel;
-import org.traccar.BaseProtocolDecoder;
-import org.traccar.Context;
-import org.traccar.DeviceSession;
-import org.traccar.helper.UnitsConverter;
-import org.traccar.model.Position;
-
-import javax.xml.bind.DatatypeConverter;
-import java.net.SocketAddress;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
-
- public Xt2400ProtocolDecoder(Xt2400Protocol protocol) {
- super(protocol);
-
- String config = Context.getConfig().getString(getProtocolName() + ".config");
- if (config != null) {
- setConfig(config);
- }
- }
-
- private static final Map<Integer, Integer> TAG_LENGTH_MAP = new HashMap<>();
-
- static {
- int[] l1 = {
- 0x01, 0x02, 0x04, 0x0b, 0x0c, 0x0d, 0x12, 0x13,
- 0x16, 0x17, 0x1c, 0x1f, 0x23, 0x2c, 0x2d, 0x30,
- 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
- 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x40, 0x41,
- 0x53, 0x66, 0x69, 0x6a, 0x93, 0x94, 0x96
- };
- int[] l2 = {
- 0x05, 0x09, 0x0a, 0x14, 0x15, 0x1d, 0x1e, 0x24,
- 0x26, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
- 0x49, 0x57, 0x58, 0x59, 0x5a, 0x6b, 0x6f, 0x7A,
- 0x7B, 0x7C, 0x7d, 0x7E, 0x7F, 0x80, 0x81, 0x82,
- 0x83, 0x84, 0x85, 0x86
- };
- int[] l4 = {
- 0x03, 0x06, 0x07, 0x08, 0x0e, 0x0f, 0x10, 0x11,
- 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x2e,
- 0x2f, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
- 0x51, 0x52, 0x54, 0x55, 0x56, 0x5b, 0x5c, 0x5d,
- 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x68, 0x6e, 0x71,
- 0x72, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x87,
- 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d
- };
- for (int i : l1) {
- TAG_LENGTH_MAP.put(i, 1);
- }
- for (int i : l2) {
- TAG_LENGTH_MAP.put(i, 2);
- }
- for (int i : l4) {
- TAG_LENGTH_MAP.put(i, 4);
- }
- TAG_LENGTH_MAP.put(0x95, 24);
- }
-
- private static int getTagLength(int tag) {
- Integer length = TAG_LENGTH_MAP.get(tag);
- if (length == null) {
- throw new IllegalArgumentException("Unknown tag: " + tag);
- }
- return length;
- }
-
- private Map<Short, byte[]> formats = new HashMap<>();
-
- public void setConfig(String configString) {
- Pattern pattern = Pattern.compile(":wycfg pcr\\[\\d+\\] ([0-9a-fA-F]{2})[0-9a-fA-F]{2}([0-9a-fA-F]+)");
- Matcher matcher = pattern.matcher(configString);
- while (matcher.find()) {
- formats.put(Short.parseShort(matcher.group(1), 16), DatatypeConverter.parseHexBinary(matcher.group(2)));
- }
- }
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- ChannelBuffer buf = (ChannelBuffer) msg;
-
- byte[] format = null;
- if (formats.size() > 1) {
- format = formats.get(buf.getUnsignedByte(buf.readerIndex()));
- } else if (!formats.isEmpty()) {
- format = formats.values().iterator().next();
- }
-
- if (format == null) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- for (byte tag : format) {
- switch ((int) tag) {
- case 0x03:
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
- break;
- case 0x04:
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- break;
- case 0x05:
- position.set(Position.KEY_INDEX, buf.readUnsignedShort());
- break;
- case 0x06:
- position.setTime(new Date(buf.readUnsignedInt() * 1000));
- break;
- case 0x07:
- position.setLatitude(buf.readInt() * 0.000001);
- break;
- case 0x08:
- position.setLongitude(buf.readInt() * 0.000001);
- break;
- case 0x09:
- position.setAltitude(buf.readShort() * 0.1);
- break;
- case 0x0a:
- position.setCourse(buf.readShort() * 0.1);
- break;
- case 0x0b:
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- break;
- case 0x10:
- position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
- break;
- case 0x12:
- position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
- break;
- case 0x13:
- position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
- break;
- case 0x14:
- position.set(Position.KEY_RSSI, buf.readShort());
- break;
- case 0x16:
- position.set(Position.KEY_BATTERY, buf.readUnsignedByte() * 0.1);
- break;
- case 0x17:
- position.set(Position.KEY_POWER, buf.readUnsignedByte() * 0.1);
- break;
- case 0x57:
- position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
- break;
- case 0x65:
- position.set(Position.KEY_VIN, buf.readBytes(17).toString(StandardCharsets.US_ASCII));
- break;
- case 0x73:
- position.set(Position.KEY_VERSION_FW, buf.readBytes(16).toString(StandardCharsets.US_ASCII).trim());
- break;
- default:
- buf.skipBytes(getTagLength(tag));
- break;
- }
- }
-
- if (position.getLatitude() != 0 && position.getLongitude() != 0) {
- position.setValid(true);
- } else {
- getLastLocation(position, position.getDeviceTime());
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/protocol/YwtProtocol.java b/src/org/traccar/protocol/YwtProtocol.java
deleted file mode 100644
index 412365ecb..000000000
--- a/src/org/traccar/protocol/YwtProtocol.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.
- * 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 YwtProtocol extends BaseProtocol {
-
- public YwtProtocol() {
- super("ywt");
- }
-
- @Override
- public void initTrackerServers(List<TrackerServer> serverList) {
- serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {
- @Override
- protected void addSpecificHandlers(ChannelPipeline pipeline) {
- pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
- pipeline.addLast("stringEncoder", new StringEncoder());
- pipeline.addLast("stringDecoder", new StringDecoder());
- pipeline.addLast("objectDecoder", new YwtProtocolDecoder(YwtProtocol.this));
- }
- });
- }
-
-}
diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java
deleted file mode 100644
index 6a98ab9e7..000000000
--- a/src/org/traccar/protocol/YwtProtocolDecoder.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.
- * 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.Parser;
-import org.traccar.helper.PatternBuilder;
-import org.traccar.model.Position;
-
-import java.net.SocketAddress;
-import java.util.regex.Pattern;
-
-public class YwtProtocolDecoder extends BaseProtocolDecoder {
-
- public YwtProtocolDecoder(YwtProtocol protocol) {
- super(protocol);
- }
-
- private static final Pattern PATTERN = new PatternBuilder()
- .expression("%(..),") // type
- .number("(d+):") // unit identifier
- .number("d+,") // subtype
- .number("(dd)(dd)(dd)") // date (yymmdd)
- .number("(dd)(dd)(dd),") // time (hhmmss)
- .expression("([EW])")
- .number("(ddd.d{6}),") // longitude
- .expression("([NS])")
- .number("(dd.d{6}),") // latitude
- .number("(d+)?,") // altitude
- .number("(d+),") // speed
- .number("(d+),") // course
- .number("(d+),") // satellite
- .expression("([^,]+),") // report identifier
- .expression("([-0-9a-fA-F]+)") // status
- .any()
- .compile();
-
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
-
- String sentence = (String) msg;
-
- // Synchronization
- if (sentence.startsWith("%SN") && channel != null) {
- int start = sentence.indexOf(':');
- int end = start;
- for (int i = 0; i < 4; i++) {
- end = sentence.indexOf(',', end + 1);
- }
- if (end == -1) {
- end = sentence.length();
- }
-
- channel.write("%AT+SN=" + sentence.substring(start, end));
- return null;
- }
-
- Parser parser = new Parser(PATTERN, sentence);
- if (!parser.matches()) {
- return null;
- }
-
- Position position = new Position();
- position.setProtocol(getProtocolName());
-
- String type = parser.next();
-
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
- if (deviceSession == null) {
- return null;
- }
- position.setDeviceId(deviceSession.getDeviceId());
-
- position.setTime(parser.nextDateTime());
-
- position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
- position.setAltitude(parser.nextDouble(0));
- position.setSpeed(parser.nextDouble(0));
- position.setCourse(parser.nextDouble(0));
-
- int satellites = parser.nextInt(0);
- position.setValid(satellites >= 3);
- position.set(Position.KEY_SATELLITES, satellites);
-
- String reportId = parser.next();
-
- position.set(Position.KEY_STATUS, parser.next());
-
- // Send response
- if ((type.equals("KP") || type.equals("EP")) && channel != null) {
- channel.write("%AT+" + type + "=" + reportId + "\r\n");
- }
-
- return position;
- }
-
-}
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
deleted file mode 100644
index a13aeeeb4..000000000
--- a/src/org/traccar/reports/Events.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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;
-
-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 org.apache.poi.ss.util.WorkbookUtil;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Event;
-import org.traccar.model.Geofence;
-import org.traccar.model.Group;
-import org.traccar.reports.model.DeviceReport;
-
-public final class Events {
-
- private Events() {
- }
-
- public static Collection<Event> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Collection<String> types, Date from, Date to) throws SQLException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<Event> result = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- 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().checkItemPermission(userId, geofenceId)) {
- result.add(event);
- }
- }
- }
- }
- return result;
- }
-
- public static void getExcel(OutputStream outputStream,
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Collection<String> types, Date from, Date to) throws SQLException, IOException {
- ReportUtils.checkPeriodLimit(from, to);
- 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);
- 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().checkItemPermission(userId, geofenceId)) {
- Geofence geofence = (Geofence) Context.getGeofenceManager().getById(geofenceId);
- if (geofence != null) {
- geofenceNames.put(geofenceId, geofence.getName());
- }
- } else {
- iterator.remove();
- }
- }
- } else {
- iterator.remove();
- }
- }
- DeviceReport deviceEvents = new DeviceReport();
- Device device = Context.getIdentityManager().getById(deviceId);
- deviceEvents.setDeviceName(device.getName());
- sheetNames.add(WorkbookUtil.createSafeSheetName(deviceEvents.getDeviceName()));
- if (device.getGroupId() != 0) {
- Group group = Context.getGroupsManager().getById(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 = ReportUtils.initializeContext(userId);
- jxlsContext.putVar("devices", devicesEvents);
- jxlsContext.putVar("sheetNames", sheetNames);
- jxlsContext.putVar("geofenceNames", geofenceNames);
- jxlsContext.putVar("from", from);
- jxlsContext.putVar("to", to);
- ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
- }
- }
-}
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
deleted file mode 100644
index f6f386e99..000000000
--- a/src/org/traccar/reports/ReportUtils.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 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;
-
-import org.apache.velocity.tools.generic.DateTool;
-import org.apache.velocity.tools.generic.NumberTool;
-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.events.MotionEventHandler;
-import org.traccar.model.DeviceState;
-import org.traccar.model.Driver;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-import org.traccar.reports.model.BaseReport;
-import org.traccar.reports.model.StopReport;
-import org.traccar.reports.model.TripReport;
-import org.traccar.reports.model.TripsConfig;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.TimeZone;
-
-public final class ReportUtils {
-
- private ReportUtils() {
- }
-
- public static void checkPeriodLimit(Date from, Date to) {
- long limit = Context.getConfig().getLong("report.periodLimit") * 1000;
- if (limit > 0 && to.getTime() - from.getTime() > limit) {
- throw new IllegalArgumentException("Time period exceeds the limit");
- }
- }
-
- public static String getDistanceUnit(long userId) {
- return (String) Context.getPermissionsManager().lookupAttribute(userId, "distanceUnit", "km");
- }
-
- public static String getSpeedUnit(long userId) {
- return (String) Context.getPermissionsManager().lookupAttribute(userId, "speedUnit", "kn");
- }
-
- public static String getVolumeUnit(long userId) {
- return (String) Context.getPermissionsManager().lookupAttribute(userId, "volumeUnit", "ltr");
- }
-
- public static TimeZone getTimezone(long userId) {
- String timezone = (String) Context.getPermissionsManager().lookupAttribute(userId, "timezone", null);
- return timezone != null ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault();
- }
-
- public static Collection<Long> getDeviceList(Collection<Long> deviceIds, Collection<Long> groupIds) {
- Collection<Long> result = new ArrayList<>();
- result.addAll(deviceIds);
- for (long groupId : groupIds) {
- result.addAll(Context.getPermissionsManager().getGroupDevices(groupId));
- }
- return result;
- }
-
- public static double calculateDistance(Position firstPosition, Position lastPosition) {
- return calculateDistance(firstPosition, lastPosition, true);
- }
-
- public static double calculateDistance(Position firstPosition, Position lastPosition, boolean useOdometer) {
- double distance = 0.0;
- double firstOdometer = firstPosition.getDouble(Position.KEY_ODOMETER);
- double lastOdometer = lastPosition.getDouble(Position.KEY_ODOMETER);
-
- if (useOdometer && (firstOdometer != 0.0 || lastOdometer != 0.0)) {
- distance = lastOdometer - firstOdometer;
- } else if (firstPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)
- && lastPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) {
- distance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE)
- - firstPosition.getDouble(Position.KEY_TOTAL_DISTANCE);
- }
- return distance;
- }
-
- public static double calculateFuel(Position firstPosition, Position lastPosition) {
-
- if (firstPosition.getAttributes().get(Position.KEY_FUEL_LEVEL) != null
- && lastPosition.getAttributes().get(Position.KEY_FUEL_LEVEL) != null) {
-
- BigDecimal value = new BigDecimal(firstPosition.getDouble(Position.KEY_FUEL_LEVEL)
- - lastPosition.getDouble(Position.KEY_FUEL_LEVEL));
- return value.setScale(1, RoundingMode.HALF_EVEN).doubleValue();
- }
- return 0;
- }
-
- public static String findDriver(Position firstPosition, Position lastPosition) {
- if (firstPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
- return firstPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
- } else if (lastPosition.getAttributes().containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
- return lastPosition.getString(Position.KEY_DRIVER_UNIQUE_ID);
- }
- return null;
- }
-
- public static String findDriverName(String driverUniqueId) {
- if (driverUniqueId != null && Context.getDriversManager() != null) {
- Driver driver = Context.getDriversManager().getDriverByUniqueId(driverUniqueId);
- if (driver != null) {
- return driver.getName();
- }
- }
- return null;
- }
-
- public static org.jxls.common.Context initializeContext(long userId) {
- org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
- jxlsContext.putVar("distanceUnit", getDistanceUnit(userId));
- jxlsContext.putVar("speedUnit", getSpeedUnit(userId));
- jxlsContext.putVar("volumeUnit", getVolumeUnit(userId));
- jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url"));
- jxlsContext.putVar("dateTool", new DateTool());
- jxlsContext.putVar("numberTool", new NumberTool());
- jxlsContext.putVar("timezone", getTimezone(userId));
- jxlsContext.putVar("locale", Locale.getDefault());
- jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]");
- return jxlsContext;
- }
-
- public static void processTemplateWithSheets(InputStream templateStream, OutputStream targetStream,
- org.jxls.common.Context jxlsContext) throws IOException {
- Transformer transformer = TransformerFactory.createTransformer(templateStream, targetStream);
- 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();
- }
-
- private static TripReport calculateTrip(
- ArrayList<Position> positions, int startIndex, int endIndex, boolean ignoreOdometer) {
- Position startTrip = positions.get(startIndex);
- Position endTrip = positions.get(endIndex);
-
- double speedMax = 0.0;
- double speedSum = 0.0;
- for (int i = startIndex; i <= endIndex; i++) {
- double speed = positions.get(i).getSpeed();
- speedSum += speed;
- if (speed > speedMax) {
- speedMax = speed;
- }
- }
-
- TripReport trip = new TripReport();
-
- long tripDuration = endTrip.getFixTime().getTime() - startTrip.getFixTime().getTime();
- long deviceId = startTrip.getDeviceId();
- trip.setDeviceId(deviceId);
- trip.setDeviceName(Context.getIdentityManager().getById(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());
-
- trip.setDistance(calculateDistance(startTrip, endTrip, !ignoreOdometer));
- trip.setDuration(tripDuration);
- trip.setAverageSpeed(speedSum / (endIndex - startIndex));
- trip.setMaxSpeed(speedMax);
- trip.setSpentFuel(calculateFuel(startTrip, endTrip));
-
- trip.setDriverUniqueId(findDriver(startTrip, endTrip));
- trip.setDriverName(findDriverName(trip.getDriverUniqueId()));
-
- return trip;
- }
-
- private static StopReport calculateStop(ArrayList<Position> positions, int startIndex, int endIndex) {
- Position startStop = positions.get(startIndex);
- Position endStop = positions.get(endIndex);
-
- StopReport stop = new StopReport();
-
- long deviceId = startStop.getDeviceId();
- stop.setDeviceId(deviceId);
- stop.setDeviceName(Context.getIdentityManager().getById(deviceId).getName());
-
- stop.setPositionId(startStop.getId());
- stop.setLatitude(startStop.getLatitude());
- stop.setLongitude(startStop.getLongitude());
- stop.setStartTime(startStop.getFixTime());
- stop.setAddress(startStop.getAddress());
- stop.setEndTime(endStop.getFixTime());
-
- long stopDuration = endStop.getFixTime().getTime() - startStop.getFixTime().getTime();
- stop.setDuration(stopDuration);
- stop.setSpentFuel(calculateFuel(startStop, endStop));
-
- long engineHours = 0;
- for (int i = startIndex + 1; i <= endIndex; i++) {
- if (positions.get(i).getBoolean(Position.KEY_IGNITION)
- && positions.get(i - 1).getBoolean(Position.KEY_IGNITION)) {
- engineHours += positions.get(i).getFixTime().getTime() - positions.get(i - 1).getFixTime().getTime();
- }
- }
- stop.setEngineHours(engineHours);
-
- return stop;
-
- }
-
- private static <T extends BaseReport> T calculateTripOrStop(ArrayList<Position> positions, int startIndex,
- int endIndex, boolean ignoreOdometer, Class<T> reportClass) {
- if (reportClass.equals(TripReport.class)) {
- return (T) calculateTrip(positions, startIndex, endIndex, ignoreOdometer);
- } else {
- return (T) calculateStop(positions, startIndex, endIndex);
- }
- }
-
- private static boolean isMoving(ArrayList<Position> positions, int index, TripsConfig tripsConfig) {
- if (tripsConfig.getMinimalNoDataDuration() > 0) {
- boolean beforeGap = index < positions.size() - 1
- && positions.get(index + 1).getFixTime().getTime() - positions.get(index).getFixTime().getTime()
- >= tripsConfig.getMinimalNoDataDuration();
- boolean afterGap = index > 0
- && positions.get(index).getFixTime().getTime() - positions.get(index - 1).getFixTime().getTime()
- >= tripsConfig.getMinimalNoDataDuration();
- if (beforeGap || afterGap) {
- return false;
- }
- }
- if (positions.get(index).getAttributes().containsKey(Position.KEY_MOTION)
- && positions.get(index).getAttributes().get(Position.KEY_MOTION) instanceof Boolean) {
- return positions.get(index).getBoolean(Position.KEY_MOTION);
- } else {
- return positions.get(index).getSpeed() > tripsConfig.getSpeedThreshold();
- }
- }
-
- public static <T extends BaseReport> Collection<T> detectTripsAndStops(Collection<Position> positionCollection,
- TripsConfig tripsConfig, boolean ignoreOdometer, Class<T> reportClass) {
- Collection<T> result = new ArrayList<>();
-
- ArrayList<Position> positions = new ArrayList<>(positionCollection);
- if (positions != null && !positions.isEmpty()) {
- boolean trips = reportClass.equals(TripReport.class);
- MotionEventHandler motionHandler = new MotionEventHandler(tripsConfig);
- DeviceState deviceState = new DeviceState();
- deviceState.setMotionState(isMoving(positions, 0, tripsConfig));
- int startEventIndex = trips == deviceState.getMotionState() ? 0 : -1;
- int startNoEventIndex = -1;
- for (int i = 0; i < positions.size(); i++) {
- Map<Event, Position> event = motionHandler.updateMotionState(deviceState, positions.get(i),
- isMoving(positions, i, tripsConfig));
- if (startEventIndex == -1
- && (trips != deviceState.getMotionState() && deviceState.getMotionPosition() != null
- || trips == deviceState.getMotionState() && event != null)) {
- startEventIndex = i;
- startNoEventIndex = -1;
- } else if (trips != deviceState.getMotionState() && startEventIndex != -1
- && deviceState.getMotionPosition() == null && event == null) {
- startEventIndex = -1;
- }
- if (startNoEventIndex == -1
- && (trips == deviceState.getMotionState() && deviceState.getMotionPosition() != null
- || trips != deviceState.getMotionState() && event != null)) {
- startNoEventIndex = i;
- } else if (startNoEventIndex != -1 && deviceState.getMotionPosition() == null && event == null) {
- startNoEventIndex = -1;
- }
- if (startEventIndex != -1 && startNoEventIndex != -1 && event != null
- && trips != deviceState.getMotionState()) {
- result.add(calculateTripOrStop(positions, startEventIndex, startNoEventIndex,
- ignoreOdometer, reportClass));
- startEventIndex = -1;
- }
- }
- if (startEventIndex != -1 && (startNoEventIndex != -1 || !trips)) {
- result.add(calculateTripOrStop(positions, startEventIndex,
- startNoEventIndex != -1 ? startNoEventIndex : positions.size() - 1,
- ignoreOdometer, reportClass));
- }
- }
- return result;
- }
-}
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java
deleted file mode 100644
index 6adb00aae..000000000
--- a/src/org/traccar/reports/Route.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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;
-
-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 org.apache.poi.ss.util.WorkbookUtil;
-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;
-
-public final class Route {
-
- private Route() {
- }
-
- public static Collection<Position> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<Position> result = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- result.addAll(Context.getDataManager().getPositions(deviceId, from, to));
- }
- return result;
- }
-
- public static void getExcel(OutputStream outputStream,
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException, IOException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<DeviceReport> devicesRoutes = new ArrayList<>();
- ArrayList<String> sheetNames = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- Collection<Position> positions = Context.getDataManager()
- .getPositions(deviceId, from, to);
- DeviceReport deviceRoutes = new DeviceReport();
- Device device = Context.getIdentityManager().getById(deviceId);
- deviceRoutes.setDeviceName(device.getName());
- sheetNames.add(WorkbookUtil.createSafeSheetName(deviceRoutes.getDeviceName()));
- if (device.getGroupId() != 0) {
- Group group = Context.getGroupsManager().getById(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 = ReportUtils.initializeContext(userId);
- jxlsContext.putVar("devices", devicesRoutes);
- jxlsContext.putVar("sheetNames", sheetNames);
- jxlsContext.putVar("from", from);
- jxlsContext.putVar("to", to);
- ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
- }
- }
-}
diff --git a/src/org/traccar/reports/Stops.java b/src/org/traccar/reports/Stops.java
deleted file mode 100644
index 14b3a2437..000000000
--- a/src/org/traccar/reports/Stops.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-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 org.apache.poi.ss.util.WorkbookUtil;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Group;
-import org.traccar.reports.model.DeviceReport;
-import org.traccar.reports.model.StopReport;
-
-public final class Stops {
-
- private Stops() {
- }
-
- private static Collection<StopReport> detectStops(long deviceId, Date from, Date to) throws SQLException {
- boolean ignoreOdometer = Context.getDeviceManager()
- .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
-
- Collection<StopReport> result = ReportUtils.detectTripsAndStops(
- Context.getDataManager().getPositions(deviceId, from, to),
- Context.getTripsConfig(), ignoreOdometer, StopReport.class);
-
- return result;
- }
-
- public static Collection<StopReport> getObjects(
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<StopReport> result = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- result.addAll(detectStops(deviceId, from, to));
- }
- return result;
- }
-
- public static void getExcel(
- OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException, IOException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<DeviceReport> devicesStops = new ArrayList<>();
- ArrayList<String> sheetNames = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- Collection<StopReport> stops = detectStops(deviceId, from, to);
- DeviceReport deviceStops = new DeviceReport();
- Device device = Context.getIdentityManager().getById(deviceId);
- deviceStops.setDeviceName(device.getName());
- sheetNames.add(WorkbookUtil.createSafeSheetName(deviceStops.getDeviceName()));
- if (device.getGroupId() != 0) {
- Group group = Context.getGroupsManager().getById(device.getGroupId());
- if (group != null) {
- deviceStops.setGroupName(group.getName());
- }
- }
- deviceStops.setObjects(stops);
- devicesStops.add(deviceStops);
- }
- String templatePath = Context.getConfig().getString("report.templatesPath",
- "templates/export/");
- try (InputStream inputStream = new FileInputStream(templatePath + "/stops.xlsx")) {
- org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
- jxlsContext.putVar("devices", devicesStops);
- jxlsContext.putVar("sheetNames", sheetNames);
- jxlsContext.putVar("from", from);
- jxlsContext.putVar("to", to);
- ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
- }
- }
-
-}
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java
deleted file mode 100644
index 366e40421..000000000
--- a/src/org/traccar/reports/Summary.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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;
-
-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 org.jxls.util.JxlsHelper;
-import org.traccar.Context;
-import org.traccar.model.Position;
-import org.traccar.reports.model.SummaryReport;
-
-public final class Summary {
-
- private Summary() {
- }
-
- private static SummaryReport calculateSummaryResult(long deviceId, Date from, Date to) throws SQLException {
- SummaryReport result = new SummaryReport();
- result.setDeviceId(deviceId);
- result.setDeviceName(Context.getIdentityManager().getById(deviceId).getName());
- Collection<Position> positions = Context.getDataManager().getPositions(deviceId, from, to);
- if (positions != null && !positions.isEmpty()) {
- Position firstPosition = null;
- Position previousPosition = null;
- double speedSum = 0;
- for (Position position : positions) {
- if (firstPosition == null) {
- firstPosition = position;
- }
- if (previousPosition != null && position.getBoolean(Position.KEY_IGNITION)
- && previousPosition.getBoolean(Position.KEY_IGNITION)) {
- result.addEngineHours(position.getFixTime().getTime()
- - previousPosition.getFixTime().getTime());
- }
- previousPosition = position;
- speedSum += position.getSpeed();
- result.setMaxSpeed(position.getSpeed());
- }
- boolean ignoreOdometer = Context.getDeviceManager()
- .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
- result.setDistance(ReportUtils.calculateDistance(firstPosition, previousPosition, !ignoreOdometer));
- result.setAverageSpeed(speedSum / positions.size());
- result.setSpentFuel(ReportUtils.calculateFuel(firstPosition, previousPosition));
- }
- return result;
- }
-
- public static Collection<SummaryReport> getObjects(long userId, Collection<Long> deviceIds,
- Collection<Long> groupIds, Date from, Date to) throws SQLException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<SummaryReport> result = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- result.add(calculateSummaryResult(deviceId, from, to));
- }
- return result;
- }
-
- public static void getExcel(OutputStream outputStream,
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException, IOException {
- ReportUtils.checkPeriodLimit(from, to);
- 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 = ReportUtils.initializeContext(userId);
- jxlsContext.putVar("summaries", summaries);
- jxlsContext.putVar("from", from);
- jxlsContext.putVar("to", to);
- JxlsHelper.getInstance().setUseFastFormulaProcessor(false)
- .processTemplate(inputStream, outputStream, jxlsContext);
- }
- }
-}
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
deleted file mode 100644
index 696defa94..000000000
--- a/src/org/traccar/reports/Trips.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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;
-
-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 org.apache.poi.ss.util.WorkbookUtil;
-import org.traccar.Context;
-import org.traccar.model.Device;
-import org.traccar.model.Group;
-import org.traccar.reports.model.DeviceReport;
-import org.traccar.reports.model.TripReport;
-
-public final class Trips {
-
- private Trips() {
- }
-
- private static Collection<TripReport> detectTrips(long deviceId, Date from, Date to) throws SQLException {
- boolean ignoreOdometer = Context.getDeviceManager()
- .lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
-
- Collection<TripReport> result = ReportUtils.detectTripsAndStops(
- Context.getDataManager().getPositions(deviceId, from, to),
- Context.getTripsConfig(), ignoreOdometer, TripReport.class);
-
- return result;
- }
-
- public static Collection<TripReport> getObjects(long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<TripReport> result = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- result.addAll(detectTrips(deviceId, from, to));
- }
- return result;
- }
-
- public static void getExcel(OutputStream outputStream,
- long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
- Date from, Date to) throws SQLException, IOException {
- ReportUtils.checkPeriodLimit(from, to);
- ArrayList<DeviceReport> devicesTrips = new ArrayList<>();
- ArrayList<String> sheetNames = new ArrayList<>();
- for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
- Context.getPermissionsManager().checkDevice(userId, deviceId);
- Collection<TripReport> trips = detectTrips(deviceId, from, to);
- DeviceReport deviceTrips = new DeviceReport();
- Device device = Context.getIdentityManager().getById(deviceId);
- deviceTrips.setDeviceName(device.getName());
- sheetNames.add(WorkbookUtil.createSafeSheetName(deviceTrips.getDeviceName()));
- if (device.getGroupId() != 0) {
- Group group = Context.getGroupsManager().getById(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 = ReportUtils.initializeContext(userId);
- jxlsContext.putVar("devices", devicesTrips);
- jxlsContext.putVar("sheetNames", sheetNames);
- jxlsContext.putVar("from", from);
- jxlsContext.putVar("to", to);
- ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
- }
- }
-
-}
diff --git a/src/org/traccar/reports/model/BaseReport.java b/src/org/traccar/reports/model/BaseReport.java
deleted file mode 100644
index 941e2757f..000000000
--- a/src/org/traccar/reports/model/BaseReport.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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;
-
-public class BaseReport {
-
- private long deviceId;
-
- public long getDeviceId() {
- return deviceId;
- }
-
- public void setDeviceId(long deviceId) {
- this.deviceId = deviceId;
- }
-
- private String deviceName;
-
- public String getDeviceName() {
- return deviceName;
- }
-
- public void setDeviceName(String deviceName) {
- this.deviceName = deviceName;
- }
-
- private double distance;
-
- public double getDistance() {
- return distance;
- }
-
- public void setDistance(double distance) {
- this.distance = distance;
- }
-
- public void addDistance(double distance) {
- this.distance += distance;
- }
-
- private double averageSpeed;
-
- public double getAverageSpeed() {
- return averageSpeed;
- }
-
- public void setAverageSpeed(Double averageSpeed) {
- this.averageSpeed = averageSpeed;
- }
-
- private double maxSpeed;
-
- public double getMaxSpeed() {
- return maxSpeed;
- }
-
- public void setMaxSpeed(double maxSpeed) {
- if (maxSpeed > this.maxSpeed) {
- this.maxSpeed = maxSpeed;
- }
- }
-
- private double spentFuel;
-
- public double getSpentFuel() {
- return spentFuel;
- }
-
- public void setSpentFuel(double spentFuel) {
- this.spentFuel = spentFuel;
- }
-
-}
diff --git a/src/org/traccar/reports/model/DeviceReport.java b/src/org/traccar/reports/model/DeviceReport.java
deleted file mode 100644
index 932753d15..000000000
--- a/src/org/traccar/reports/model/DeviceReport.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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/StopReport.java b/src/org/traccar/reports/model/StopReport.java
deleted file mode 100644
index 6b2e86299..000000000
--- a/src/org/traccar/reports/model/StopReport.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-public class StopReport extends BaseReport {
-
- private long positionId;
-
- public long getPositionId() {
- return positionId;
- }
-
- public void setPositionId(long positionId) {
- this.positionId = positionId;
- }
-
- private double latitude;
-
- public double getLatitude() {
- return latitude;
- }
-
- public void setLatitude(double latitude) {
- this.latitude = latitude;
- }
-
- private double longitude;
-
- public double getLongitude() {
- return longitude;
- }
-
- public void setLongitude(double longitude) {
- this.longitude = longitude;
- }
-
- private Date startTime;
-
- public Date getStartTime() {
- if (startTime != null) {
- return new Date(startTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setStartTime(Date startTime) {
- if (startTime != null) {
- this.startTime = new Date(startTime.getTime());
- } else {
- this.startTime = null;
- }
- }
-
- private Date endTime;
-
- public Date getEndTime() {
- if (endTime != null) {
- return new Date(endTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setEndTime(Date endTime) {
- if (endTime != null) {
- this.endTime = new Date(endTime.getTime());
- } else {
- this.endTime = null;
- }
- }
-
- private String address;
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- private long duration;
-
- public long getDuration() {
- return duration;
- }
-
- public void setDuration(long duration) {
- this.duration = duration;
- }
-
- private long engineHours; // milliseconds
-
- public long getEngineHours() {
- return engineHours;
- }
-
- public void setEngineHours(long engineHours) {
- this.engineHours = engineHours;
- }
-
- public void addEngineHours(long engineHours) {
- this.engineHours += engineHours;
- }
-}
diff --git a/src/org/traccar/reports/model/SummaryReport.java b/src/org/traccar/reports/model/SummaryReport.java
deleted file mode 100644
index 6f9e9459f..000000000
--- a/src/org/traccar/reports/model/SummaryReport.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 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;
-
-public class SummaryReport extends BaseReport {
-
- private long engineHours; // milliseconds
-
- public long getEngineHours() {
- return engineHours;
- }
-
- public void setEngineHours(long engineHours) {
- this.engineHours = engineHours;
- }
-
- public void addEngineHours(long engineHours) {
- this.engineHours += engineHours;
- }
-}
diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java
deleted file mode 100644
index 42a4240b7..000000000
--- a/src/org/traccar/reports/model/TripReport.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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;
-
-public class TripReport extends BaseReport {
-
- private long startPositionId;
-
- public long getStartPositionId() {
- return startPositionId;
- }
-
- public void setStartPositionId(long startPositionId) {
- this.startPositionId = startPositionId;
- }
-
- private long endPositionId;
-
- public long getEndPositionId() {
- return endPositionId;
- }
-
- public void setEndPositionId(long endPositionId) {
- 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) {
- return new Date(startTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setStartTime(Date startTime) {
- if (startTime != null) {
- this.startTime = new Date(startTime.getTime());
- } else {
- this.startTime = null;
- }
- }
-
- private String startAddress;
-
- public String getStartAddress() {
- return startAddress;
- }
-
- public void setStartAddress(String address) {
- this.startAddress = address;
- }
-
- private Date endTime;
-
- public Date getEndTime() {
- if (endTime != null) {
- return new Date(endTime.getTime());
- } else {
- return null;
- }
- }
-
- public void setEndTime(Date endTime) {
- if (endTime != null) {
- this.endTime = new Date(endTime.getTime());
- } else {
- this.endTime = null;
- }
- }
-
- private String endAddress;
-
- public String getEndAddress() {
- return endAddress;
- }
-
- public void setEndAddress(String address) {
- this.endAddress = address;
- }
-
- private long duration;
-
- public long getDuration() {
- return duration;
- }
-
- public void setDuration(long duration) {
- this.duration = duration;
- }
-
- private String driverUniqueId;
-
- public String getDriverUniqueId() {
- return driverUniqueId;
- }
-
- public void setDriverUniqueId(String driverUniqueId) {
- this.driverUniqueId = driverUniqueId;
- }
-
- private String driverName;
-
- public String getDriverName() {
- return driverName;
- }
-
- public void setDriverName(String driverName) {
- this.driverName = driverName;
- }
-}
diff --git a/src/org/traccar/reports/model/TripsConfig.java b/src/org/traccar/reports/model/TripsConfig.java
deleted file mode 100644
index 0f0c615d3..000000000
--- a/src/org/traccar/reports/model/TripsConfig.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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;
-
-public class TripsConfig {
-
- public TripsConfig() {
- }
-
- public TripsConfig(double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration,
- long minimalNoDataDuration, boolean useIgnition, boolean processInvalidPositions, double speedThreshold) {
- this.minimalTripDistance = minimalTripDistance;
- this.minimalTripDuration = minimalTripDuration;
- this.minimalParkingDuration = minimalParkingDuration;
- this.minimalNoDataDuration = minimalNoDataDuration;
- this.useIgnition = useIgnition;
- this.processInvalidPositions = processInvalidPositions;
- this.speedThreshold = speedThreshold;
- }
-
- private double minimalTripDistance;
-
- public double getMinimalTripDistance() {
- return minimalTripDistance;
- }
-
- public void setMinimalTripDistance(double minimalTripDistance) {
- this.minimalTripDistance = minimalTripDistance;
- }
-
- private long minimalTripDuration;
-
- public long getMinimalTripDuration() {
- return minimalTripDuration;
- }
-
- public void setMinimalTripDuration(long minimalTripDuration) {
- this.minimalTripDuration = minimalTripDuration;
- }
-
- private long minimalParkingDuration;
-
- public long getMinimalParkingDuration() {
- return minimalParkingDuration;
- }
-
- public void setMinimalParkingDuration(long minimalParkingDuration) {
- this.minimalParkingDuration = minimalParkingDuration;
- }
-
- private long minimalNoDataDuration;
-
- public long getMinimalNoDataDuration() {
- return minimalNoDataDuration;
- }
-
- public void setMinimalNoDataDuration(long minimalNoDataDuration) {
- this.minimalNoDataDuration = minimalNoDataDuration;
- }
-
- private boolean useIgnition;
-
- public boolean getUseIgnition() {
- return useIgnition;
- }
-
- public void setUseIgnition(boolean useIgnition) {
- this.useIgnition = useIgnition;
- }
-
- private boolean processInvalidPositions;
-
- public boolean getProcessInvalidPositions() {
- return processInvalidPositions;
- }
-
- public void setProcessInvalidPositions(boolean processInvalidPositions) {
- this.processInvalidPositions = processInvalidPositions;
- }
-
- private double speedThreshold;
-
- public double getSpeedThreshold() {
- return speedThreshold;
- }
-
- public void setSpeedThreshold(double speedThreshold) {
- this.speedThreshold = speedThreshold;
- }
-
-}
diff --git a/src/org/traccar/smpp/ClientSmppSessionHandler.java b/src/org/traccar/smpp/ClientSmppSessionHandler.java
deleted file mode 100644
index 77f75273e..000000000
--- a/src/org/traccar/smpp/ClientSmppSessionHandler.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.smpp;
-
-import org.traccar.events.TextMessageEventHandler;
-import org.traccar.helper.Log;
-
-import com.cloudhopper.commons.charset.CharsetUtil;
-import com.cloudhopper.smpp.SmppConstants;
-import com.cloudhopper.smpp.impl.DefaultSmppSessionHandler;
-import com.cloudhopper.smpp.pdu.DeliverSm;
-import com.cloudhopper.smpp.pdu.PduRequest;
-import com.cloudhopper.smpp.pdu.PduResponse;
-
-public class ClientSmppSessionHandler extends DefaultSmppSessionHandler {
-
- private SmppClient smppClient;
-
- public ClientSmppSessionHandler(SmppClient smppClient) {
- this.smppClient = smppClient;
- }
-
- @Override
- public void firePduRequestExpired(PduRequest pduRequest) {
- Log.warning("PDU request expired: " + pduRequest);
- }
-
- @Override
- public PduResponse firePduRequestReceived(PduRequest request) {
- PduResponse response = null;
- try {
- if (request instanceof DeliverSm) {
- if (request.getOptionalParameters() != null) {
- Log.debug("SMS Message Delivered: "
- + request.getOptionalParameter(SmppConstants.TAG_RECEIPTED_MSG_ID).getValueAsString()
- + ", State: "
- + request.getOptionalParameter(SmppConstants.TAG_MSG_STATE).getValueAsByte());
- } else {
- String sourceAddress = ((DeliverSm) request).getSourceAddress().getAddress();
- String message = CharsetUtil.decode(((DeliverSm) request).getShortMessage(),
- smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding()));
- Log.debug("SMS Message Received: " + message.trim() + ", Source Address: " + sourceAddress);
- TextMessageEventHandler.handleTextMessage(sourceAddress, message);
- }
- }
- response = request.createResponse();
- } catch (Throwable error) {
- Log.warning(error);
- response = request.createResponse();
- response.setResultMessage(error.getMessage());
- response.setCommandStatus(SmppConstants.STATUS_UNKNOWNERR);
- }
- return response;
- }
-
- @Override
- public void fireChannelUnexpectedlyClosed() {
- Log.warning("SMPP session channel unexpectedly closed");
- smppClient.scheduleReconnect();
- }
-}
diff --git a/src/org/traccar/smpp/EnquireLinkTask.java b/src/org/traccar/smpp/EnquireLinkTask.java
deleted file mode 100644
index affb712b3..000000000
--- a/src/org/traccar/smpp/EnquireLinkTask.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.smpp;
-
-import org.traccar.helper.Log;
-
-import com.cloudhopper.smpp.SmppSession;
-import com.cloudhopper.smpp.pdu.EnquireLink;
-import com.cloudhopper.smpp.type.RecoverablePduException;
-import com.cloudhopper.smpp.type.SmppChannelException;
-import com.cloudhopper.smpp.type.SmppTimeoutException;
-import com.cloudhopper.smpp.type.UnrecoverablePduException;
-
-public class EnquireLinkTask implements Runnable {
-
- private SmppClient smppClient;
- private Integer enquireLinkTimeout;
-
- public EnquireLinkTask(SmppClient smppClient, Integer enquireLinkTimeout) {
- this.smppClient = smppClient;
- this.enquireLinkTimeout = enquireLinkTimeout;
- }
-
- @Override
- public void run() {
- SmppSession smppSession = smppClient.getSession();
- if (smppSession != null && smppSession.isBound()) {
- try {
- smppSession.enquireLink(new EnquireLink(), enquireLinkTimeout);
- } catch (SmppTimeoutException | SmppChannelException
- | RecoverablePduException | UnrecoverablePduException error) {
- Log.warning("Enquire link failed, executing reconnect: ", error);
- smppClient.scheduleReconnect();
- } catch (InterruptedException error) {
- Log.info("Enquire link interrupted, probably killed by reconnecting");
- }
- } else {
- Log.warning("Enquire link running while session is not connected");
- }
- }
-
-}
diff --git a/src/org/traccar/smpp/ReconnectionTask.java b/src/org/traccar/smpp/ReconnectionTask.java
deleted file mode 100644
index c9d9173ae..000000000
--- a/src/org/traccar/smpp/ReconnectionTask.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.smpp;
-
-public class ReconnectionTask implements Runnable {
-
- private final SmppClient smppClient;
-
- protected ReconnectionTask(SmppClient smppClient) {
- this.smppClient = smppClient;
- }
-
- @Override
- public void run() {
- smppClient.reconnect();
- }
-}
diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java
deleted file mode 100644
index 122bbaea1..000000000
--- a/src/org/traccar/smpp/SmppClient.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 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.smpp;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-
-import org.traccar.Context;
-import org.traccar.helper.Log;
-
-import com.cloudhopper.commons.charset.CharsetUtil;
-import com.cloudhopper.smpp.SmppBindType;
-import com.cloudhopper.smpp.SmppConstants;
-import com.cloudhopper.smpp.SmppSession;
-import com.cloudhopper.smpp.SmppSessionConfiguration;
-import com.cloudhopper.smpp.impl.DefaultSmppClient;
-import com.cloudhopper.smpp.impl.DefaultSmppSessionHandler;
-import com.cloudhopper.smpp.pdu.SubmitSm;
-import com.cloudhopper.smpp.pdu.SubmitSmResp;
-import com.cloudhopper.smpp.type.Address;
-import com.cloudhopper.smpp.type.RecoverablePduException;
-import com.cloudhopper.smpp.type.SmppChannelException;
-import com.cloudhopper.smpp.type.SmppTimeoutException;
-import com.cloudhopper.smpp.type.UnrecoverablePduException;
-
-public class SmppClient {
-
- private SmppSessionConfiguration sessionConfig = new SmppSessionConfiguration();
- private SmppSession smppSession;
- private DefaultSmppSessionHandler sessionHandler = new ClientSmppSessionHandler(this);
- private ExecutorService executorService = Executors.newCachedThreadPool();
- private DefaultSmppClient clientBootstrap = new DefaultSmppClient(executorService, 1);
-
- private ScheduledExecutorService enquireLinkExecutor;
- private ScheduledFuture<?> enquireLinkTask;
- private Integer enquireLinkPeriod;
- private Integer enquireLinkTimeout;
-
- private ScheduledExecutorService reconnectionExecutor;
- private ScheduledFuture<?> reconnectionTask;
- private Integer reconnectionDelay;
-
- private String sourceAddress;
- private String commandSourceAddress;
- private int submitTimeout;
- private String notificationsCharsetName;
- private byte notificationsDataCoding;
- private String commandsCharsetName;
- private byte commandsDataCoding;
-
- private byte sourceTon;
- private byte sourceNpi;
- private byte commandSourceTon;
- private byte commandSourceNpi;
-
- private byte destTon;
- private byte destNpi;
-
- public SmppClient() {
- sessionConfig.setName("Traccar.smppSession");
- sessionConfig.setInterfaceVersion(
- (byte) Context.getConfig().getInteger("sms.smpp.version", SmppConstants.VERSION_3_4));
- sessionConfig.setType(SmppBindType.TRANSCEIVER);
- sessionConfig.setHost(Context.getConfig().getString("sms.smpp.host", "localhost"));
- sessionConfig.setPort(Context.getConfig().getInteger("sms.smpp.port", 2775));
- sessionConfig.setSystemId(Context.getConfig().getString("sms.smpp.username", "user"));
- sessionConfig.setPassword(Context.getConfig().getString("sms.smpp.password", "password"));
- sessionConfig.getLoggingOptions().setLogBytes(false);
- sessionConfig.getLoggingOptions().setLogPdu(Context.getConfig().getBoolean("sms.smpp.logPdu"));
-
- sourceAddress = Context.getConfig().getString("sms.smpp.sourceAddress", "");
- commandSourceAddress = Context.getConfig().getString("sms.smpp.commandSourceAddress", sourceAddress);
- submitTimeout = Context.getConfig().getInteger("sms.smpp.submitTimeout", 10000);
-
- notificationsCharsetName = Context.getConfig().getString("sms.smpp.notificationsCharset",
- CharsetUtil.NAME_UCS_2);
- notificationsDataCoding = (byte) Context.getConfig().getInteger("sms.smpp.notificationsDataCoding",
- SmppConstants.DATA_CODING_UCS2);
- commandsCharsetName = Context.getConfig().getString("sms.smpp.commandsCharset",
- CharsetUtil.NAME_GSM);
- commandsDataCoding = (byte) Context.getConfig().getInteger("sms.smpp.commandsDataCoding",
- SmppConstants.DATA_CODING_DEFAULT);
-
-
- sourceTon = (byte) Context.getConfig().getInteger("sms.smpp.sourceTon", SmppConstants.TON_ALPHANUMERIC);
- commandSourceTon = (byte) Context.getConfig().getInteger("sms.smpp.commandSourceTon", sourceTon);
- sourceNpi = (byte) Context.getConfig().getInteger("sms.smpp.sourceNpi", SmppConstants.NPI_UNKNOWN);
- commandSourceNpi = (byte) Context.getConfig().getInteger("sms.smpp.commandSourceNpi", sourceNpi);
-
- destTon = (byte) Context.getConfig().getInteger("sms.smpp.destTon", SmppConstants.TON_INTERNATIONAL);
- destNpi = (byte) Context.getConfig().getInteger("sms.smpp.destNpi", SmppConstants.NPI_E164);
-
- enquireLinkPeriod = Context.getConfig().getInteger("sms.smpp.enquireLinkPeriod", 60000);
- enquireLinkTimeout = Context.getConfig().getInteger("sms.smpp.enquireLinkTimeout", 10000);
- enquireLinkExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
- @Override
- public Thread newThread(Runnable runnable) {
- Thread thread = new Thread(runnable);
- String name = sessionConfig.getName();
- thread.setName("EnquireLink-" + name);
- return thread;
- }
- });
-
- reconnectionDelay = Context.getConfig().getInteger("sms.smpp.reconnectionDelay", 10000);
- reconnectionExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
- @Override
- public Thread newThread(Runnable runnable) {
- Thread thread = new Thread(runnable);
- String name = sessionConfig.getName();
- thread.setName("Reconnection-" + name);
- return thread;
- }
- });
-
- scheduleReconnect();
- }
-
- public synchronized SmppSession getSession() {
- return smppSession;
- }
-
- public String mapDataCodingToCharset(byte dataCoding) {
- switch (dataCoding) {
- case SmppConstants.DATA_CODING_LATIN1:
- return CharsetUtil.NAME_ISO_8859_1;
- case SmppConstants.DATA_CODING_UCS2:
- return CharsetUtil.NAME_UCS_2;
- default:
- return CharsetUtil.NAME_GSM;
- }
- }
-
- protected synchronized void reconnect() {
- try {
- disconnect();
- smppSession = clientBootstrap.bind(sessionConfig, sessionHandler);
- stopReconnectionkTask();
- runEnquireLinkTask();
- Log.info("SMPP session connected");
- } catch (SmppTimeoutException | SmppChannelException
- | UnrecoverablePduException | InterruptedException error) {
- Log.warning("Unable to connect to SMPP server: ", error);
- }
- }
-
- public void scheduleReconnect() {
- if (reconnectionTask == null || reconnectionTask.isDone()) {
- reconnectionTask = reconnectionExecutor.scheduleWithFixedDelay(
- new ReconnectionTask(this),
- reconnectionDelay, reconnectionDelay, TimeUnit.MILLISECONDS);
- }
- }
-
- private void stopReconnectionkTask() {
- if (reconnectionTask != null) {
- reconnectionTask.cancel(false);
- }
- }
-
- private void disconnect() {
- stopEnquireLinkTask();
- destroySession();
- }
-
- private void runEnquireLinkTask() {
- enquireLinkTask = enquireLinkExecutor.scheduleWithFixedDelay(
- new EnquireLinkTask(this, enquireLinkTimeout),
- enquireLinkPeriod, enquireLinkPeriod, TimeUnit.MILLISECONDS);
- }
-
- private void stopEnquireLinkTask() {
- if (enquireLinkTask != null) {
- enquireLinkTask.cancel(true);
- }
- }
-
- private void destroySession() {
- if (smppSession != null) {
- Log.debug("Cleaning up SMPP session... ");
- smppSession.destroy();
- smppSession = null;
- }
- }
-
- public synchronized void sendMessageSync(String destAddress, String message, boolean command)
- throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException,
- InterruptedException, IllegalStateException {
- if (getSession() != null && getSession().isBound()) {
- SubmitSm submit = new SubmitSm();
- byte[] textBytes;
- textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
- submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
- submit.setShortMessage(textBytes);
- submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress)
- : new Address(sourceTon, sourceNpi, sourceAddress));
- submit.setDestAddress(new Address(destTon, destNpi, destAddress));
- SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout);
- if (submitResponce.getCommandStatus() == SmppConstants.STATUS_OK) {
- Log.debug("SMS submitted, message id: " + submitResponce.getMessageId());
- } else {
- throw new IllegalStateException(submitResponce.getResultMessage());
- }
- } else {
- throw new SmppChannelException("SMPP session is not connected");
- }
- }
-
- public void sendMessageAsync(final String destAddress, final String message, final boolean command) {
- executorService.execute(new Runnable() {
- @Override
- public void run() {
- try {
- sendMessageSync(destAddress, message, command);
- } catch (InterruptedException | RecoverablePduException | UnrecoverablePduException
- | SmppTimeoutException | SmppChannelException | IllegalStateException error) {
- Log.warning(error);
- }
- }
- });
- }
-}
diff --git a/src/org/traccar/web/ConsoleServlet.java b/src/org/traccar/web/ConsoleServlet.java
deleted file mode 100644
index 9b3d8d54b..000000000
--- a/src/org/traccar/web/ConsoleServlet.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- * 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 org.h2.server.web.ConnectionInfo;
-import org.h2.server.web.WebServlet;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-public class ConsoleServlet extends WebServlet {
-
- @Override
- public void init() {
- super.init();
-
- try {
- Field field = WebServlet.class.getDeclaredField("server");
- field.setAccessible(true);
- org.h2.server.web.WebServer server = (org.h2.server.web.WebServer) field.get(this);
-
- ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|"
- + Context.getConfig().getString("database.driver") + "|"
- + Context.getConfig().getString("database.url") + "|"
- + Context.getConfig().getString("database.user"));
-
- 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
deleted file mode 100644
index 31b389873..000000000
--- a/src/org/traccar/web/CsvBuilder.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import org.joda.time.DateTime;
-import org.joda.time.format.DateTimeFormatter;
-import org.joda.time.format.ISODateTimeFormat;
-import org.traccar.Context;
-import org.traccar.helper.Log;
-
-public class CsvBuilder {
-
- private static final String LINE_ENDING = "\r\n";
- private static final String SEPARATOR = ";";
- private static final DateTimeFormatter DATE_FORMAT = ISODateTimeFormat.dateTime();
-
- private StringBuilder builder = new StringBuilder();
-
- private void addLineEnding() {
- builder.append(LINE_ENDING);
- }
- private void addSeparator() {
- builder.append(SEPARATOR);
- }
-
- private SortedSet<Method> getSortedMethods(Object object) {
- Method[] methodArray = object.getClass().getMethods();
- SortedSet<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
- @Override
- public int compare(Method m1, Method m2) {
- if (m1.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
- return 1;
- }
- if (m2.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
- return -1;
- }
- return m1.getName().compareTo(m2.getName());
- }
- });
- methods.addAll(Arrays.asList(methodArray));
- return methods;
- }
-
- public void addLine(Object object) {
-
- SortedSet<Method> methods = getSortedMethods(object);
-
- for (Method method : methods) {
- if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
- try {
- if (method.getReturnType().equals(boolean.class)) {
- builder.append((Boolean) method.invoke(object));
- addSeparator();
- } else if (method.getReturnType().equals(int.class)) {
- builder.append((Integer) method.invoke(object));
- addSeparator();
- } else if (method.getReturnType().equals(long.class)) {
- builder.append((Long) method.invoke(object));
- addSeparator();
- } else if (method.getReturnType().equals(double.class)) {
- builder.append((Double) method.invoke(object));
- addSeparator();
- } else if (method.getReturnType().equals(String.class)) {
- builder.append((String) method.invoke(object));
- addSeparator();
- } else if (method.getReturnType().equals(Date.class)) {
- Date value = (Date) method.invoke(object);
- builder.append(DATE_FORMAT.print(new DateTime(value)));
- addSeparator();
- } else if (method.getReturnType().equals(Map.class)) {
- Map value = (Map) method.invoke(object);
- if (value != null) {
- try {
- String map = Context.getObjectMapper().writeValueAsString(value);
- map = map.replaceAll("[\\{\\}\"]", "");
- map = map.replaceAll(",", " ");
- builder.append(map);
- addSeparator();
- } catch (JsonProcessingException e) {
- Log.warning(e);
- }
- }
- }
- } catch (IllegalAccessException | InvocationTargetException error) {
- Log.warning(error);
- }
- }
- }
- addLineEnding();
- }
-
- public void addHeaderLine(Object object) {
-
- SortedSet<Method> methods = getSortedMethods(object);
-
- for (Method method : methods) {
- if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
- String name = Introspector.decapitalize(method.getName().substring(3));
- if (!name.equals("class")) {
- builder.append(name);
- addSeparator();
- }
- }
- }
- addLineEnding();
- }
-
- public void addArray(Collection<?> array) {
- for (Object object : array) {
- switch (object.getClass().getSimpleName().toLowerCase()) {
- case "string":
- builder.append(object.toString());
- addLineEnding();
- break;
- case "long":
- builder.append((long) object);
- addLineEnding();
- break;
- case "double":
- builder.append((double) object);
- addLineEnding();
- break;
- case "boolean":
- builder.append((boolean) object);
- addLineEnding();
- break;
- default:
- addLine(object);
- break;
- }
- }
- }
-
- public String build() {
- return builder.toString();
- }
-}
diff --git a/src/org/traccar/web/GpxBuilder.java b/src/org/traccar/web/GpxBuilder.java
deleted file mode 100644
index bac7182dc..000000000
--- a/src/org/traccar/web/GpxBuilder.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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/WebServer.java b/src/org/traccar/web/WebServer.java
deleted file mode 100644
index e145ff554..000000000
--- a/src/org/traccar/web/WebServer.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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.
- * 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 org.eclipse.jetty.http.HttpMethod;
-import org.eclipse.jetty.http.HttpStatus;
-import org.eclipse.jetty.proxy.AsyncProxyServlet;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.SessionManager;
-import org.eclipse.jetty.server.handler.ErrorHandler;
-import org.eclipse.jetty.server.handler.HandlerList;
-import org.eclipse.jetty.server.handler.ResourceHandler;
-import org.eclipse.jetty.server.session.HashSessionManager;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.glassfish.jersey.jackson.JacksonFeature;
-import org.glassfish.jersey.server.ResourceConfig;
-import org.glassfish.jersey.servlet.ServletContainer;
-import org.traccar.Config;
-import org.traccar.Context;
-import org.traccar.api.AsyncSocketServlet;
-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.ServerResource;
-import org.traccar.helper.Log;
-
-import javax.naming.InitialContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.sql.DataSource;
-import java.io.IOException;
-import java.io.Writer;
-import java.net.InetSocketAddress;
-
-public class WebServer {
-
- private Server server;
- private final Config config;
- private final DataSource dataSource;
- private final HandlerList handlers = new HandlerList();
- private final SessionManager sessionManager;
-
- private void initServer() {
-
- String address = config.getString("web.address");
- int port = config.getInteger("web.port", 8082);
- if (address == null) {
- server = new Server(port);
- } else {
- server = new Server(new InetSocketAddress(address, port));
- }
- }
-
- public WebServer(Config config, DataSource dataSource) {
- this.config = config;
- this.dataSource = dataSource;
-
- sessionManager = new HashSessionManager();
- int sessionTimeout = config.getInteger("web.sessionTimeout");
- if (sessionTimeout != 0) {
- sessionManager.setMaxInactiveInterval(sessionTimeout);
- }
-
- initServer();
- initApi();
- if (config.getBoolean("web.console")) {
- initConsole();
- }
- switch (config.getString("web.type", "new")) {
- case "old":
- initOldWebApp();
- break;
- default:
- initWebApp();
- break;
- }
- initClientProxy();
- server.setHandler(handlers);
-
- server.addBean(new ErrorHandler() {
- @Override
- protected void handleErrorPage(
- HttpServletRequest request, Writer writer, int code, String message) throws IOException {
- writer.write("<!DOCTYPE<html><head><title>Error</title></head><html><body>"
- + code + " - " + HttpStatus.getMessage(code) + "</body></html>");
- }
- }, false);
- }
-
- private void initClientProxy() {
- int port = Context.getConfig().getInteger("osmand.port");
- if (port != 0) {
- ServletContextHandler servletHandler = new ServletContextHandler() {
- @Override
- public void doScope(
- String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
- throws IOException, ServletException {
- if (target.equals("/") && request.getMethod().equals(HttpMethod.POST.asString())) {
- super.doScope(target, baseRequest, request, response);
- }
- }
- };
- ServletHolder servletHolder = new ServletHolder(new AsyncProxyServlet.Transparent());
- servletHolder.setInitParameter("proxyTo", "http://localhost:" + port);
- servletHandler.addServlet(servletHolder, "/");
- handlers.addHandler(servletHandler);
- }
- }
-
- private void initWebApp() {
- ResourceHandler resourceHandler = new ResourceHandler();
- resourceHandler.setResourceBase(config.getString("web.path"));
- if (config.getBoolean("web.debug")) {
- resourceHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"});
- resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows
- } else {
- String cache = config.getString("web.cacheControl");
- if (cache != null && !cache.isEmpty()) {
- resourceHandler.setCacheControl(cache);
- }
- resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
- }
- handlers.addHandler(resourceHandler);
- }
-
- private void initOldWebApp() {
- try {
- javax.naming.Context context = new InitialContext();
- context.bind("java:/DefaultDS", dataSource);
- } catch (Exception error) {
- Log.warning(error);
- }
-
- WebAppContext app = new WebAppContext();
- app.setContextPath("/");
- app.getSessionHandler().setSessionManager(sessionManager);
- app.setWar(config.getString("web.application"));
- handlers.addHandler(app);
- }
-
- private void initApi() {
- ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
- servletHandler.setContextPath("/api");
- servletHandler.getSessionHandler().setSessionManager(sessionManager);
-
- servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
-
- ResourceConfig resourceConfig = new ResourceConfig();
- 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);
- }
-
- private void initConsole() {
- ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
- servletHandler.setContextPath("/console");
- servletHandler.addServlet(new ServletHolder(new ConsoleServlet()), "/*");
- handlers.addHandler(servletHandler);
- }
-
- public void start() {
- try {
- server.start();
- } catch (Exception error) {
- Log.warning(error);
- }
- }
-
- public void stop() {
- try {
- server.stop();
- } catch (Exception error) {
- Log.warning(error);
- }
- }
-
-}