aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--findbugs.xml8
-rw-r--r--pom.xml29
-rw-r--r--schema/changelog-3.16.xml14
-rw-r--r--schema/changelog-3.17.xml73
-rw-r--r--schema/changelog-master.xml1
-rw-r--r--setup/default.xml11
-rwxr-xr-xsetup/setup.sh1
-rw-r--r--setup/traccar.iss2
-rw-r--r--src/org/traccar/BasePipelineFactory.java3
-rw-r--r--src/org/traccar/BaseProtocol.java4
-rw-r--r--src/org/traccar/BaseProtocolDecoder.java25
-rw-r--r--src/org/traccar/BaseProtocolEncoder.java12
-rw-r--r--src/org/traccar/Config.java29
-rw-r--r--src/org/traccar/Context.java17
-rw-r--r--src/org/traccar/DefaultDataHandler.java2
-rw-r--r--src/org/traccar/DeviceSession.java14
-rw-r--r--src/org/traccar/ExtendedObjectDecoder.java4
-rw-r--r--src/org/traccar/FilterHandler.java36
-rw-r--r--src/org/traccar/MainEventHandler.java19
-rw-r--r--src/org/traccar/ServerManager.java14
-rw-r--r--src/org/traccar/WebDataHandler.java41
-rw-r--r--src/org/traccar/api/BaseObjectResource.java26
-rw-r--r--src/org/traccar/api/MediaFilter.java90
-rw-r--r--src/org/traccar/api/SecurityRequestFilter.java4
-rw-r--r--src/org/traccar/api/resource/AttributeResource.java6
-rw-r--r--src/org/traccar/api/resource/DeviceResource.java7
-rw-r--r--src/org/traccar/api/resource/EventResource.java4
-rw-r--r--src/org/traccar/api/resource/MaintenanceResource.java36
-rw-r--r--src/org/traccar/api/resource/SessionResource.java17
-rw-r--r--src/org/traccar/database/DataManager.java26
-rw-r--r--src/org/traccar/database/DeviceManager.java4
-rw-r--r--src/org/traccar/database/ExtendedObjectManager.java2
-rw-r--r--src/org/traccar/database/GroupsManager.java6
-rw-r--r--src/org/traccar/database/LdapProvider.java2
-rw-r--r--src/org/traccar/database/MaintenancesManager.java27
-rw-r--r--src/org/traccar/database/MediaManager.java33
-rw-r--r--src/org/traccar/database/NotificationManager.java31
-rw-r--r--src/org/traccar/database/PermissionsManager.java13
-rw-r--r--src/org/traccar/events/AlertEventHandler.java24
-rw-r--r--src/org/traccar/events/MaintenanceEventHandler.java55
-rw-r--r--src/org/traccar/geocoder/Address.java10
-rw-r--r--src/org/traccar/geocoder/AddressFormat.java1
-rw-r--r--src/org/traccar/geocoder/BingMapsGeocoder.java3
-rw-r--r--src/org/traccar/geocoder/GeocodeFarmGeocoder.java28
-rw-r--r--src/org/traccar/geocoder/GisgraphyGeocoder.java3
-rw-r--r--src/org/traccar/geocoder/GoogleGeocoder.java4
-rw-r--r--src/org/traccar/geocoder/NominatimGeocoder.java4
-rw-r--r--src/org/traccar/geocoder/OpenCageGeocoder.java3
-rw-r--r--src/org/traccar/geofence/GeofenceCircle.java6
-rw-r--r--src/org/traccar/helper/Checksum.java242
-rw-r--r--src/org/traccar/helper/DataConverter.java47
-rw-r--r--src/org/traccar/helper/Hashing.java9
-rw-r--r--src/org/traccar/helper/ObdDecoder.java31
-rw-r--r--src/org/traccar/model/Device.java14
-rw-r--r--src/org/traccar/model/Event.java22
-rw-r--r--src/org/traccar/model/Geofence.java16
-rw-r--r--src/org/traccar/model/Group.java14
-rw-r--r--src/org/traccar/model/GroupedModel.java31
-rw-r--r--src/org/traccar/model/Maintenance.java61
-rw-r--r--src/org/traccar/model/Notification.java4
-rw-r--r--src/org/traccar/model/Position.java46
-rw-r--r--src/org/traccar/model/ScheduledModel.java30
-rw-r--r--src/org/traccar/model/Server.java12
-rw-r--r--src/org/traccar/model/Statistics.java12
-rw-r--r--src/org/traccar/model/User.java24
-rw-r--r--src/org/traccar/notification/EventForwarder.java37
-rw-r--r--src/org/traccar/notification/JsonTypeEventForwarder.java6
-rw-r--r--src/org/traccar/notification/MultiPartEventForwarder.java5
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java7
-rw-r--r--src/org/traccar/processing/ComputedAttributesHandler.java6
-rw-r--r--src/org/traccar/protocol/AdmProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/AisProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AlematicsProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ApelProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AplicomProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AppelloProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AquilaProtocolDecoder.java152
-rw-r--r--src/org/traccar/protocol/Ardi01ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ArknavProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ArknavX8ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ArnaviProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AstraProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/At2000ProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java23
-rw-r--r--src/org/traccar/protocol/AuroProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/AutoFonProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/AutoGradeProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Avl301ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/BceProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/BlackKiteProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/BoxProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CalAmpProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CarTrackProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CarcellProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CarscopProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CastelProtocol.java8
-rw-r--r--src/org/traccar/protocol/CastelProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/CastelProtocolEncoder.java73
-rw-r--r--src/org/traccar/protocol/CautelaProtocol.java47
-rw-r--r--src/org/traccar/protocol/CautelaProtocolDecoder.java77
-rw-r--r--src/org/traccar/protocol/CellocatorProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/CguardProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/CityeasyProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ContinentalProtocol.java43
-rw-r--r--src/org/traccar/protocol/ContinentalProtocolDecoder.java113
-rw-r--r--src/org/traccar/protocol/CradlepointProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/DishaProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/DmtHttpProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/DmtProtocolDecoder.java288
-rw-r--r--src/org/traccar/protocol/DwayProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/EasyTrackProtocolDecoder.java35
-rw-r--r--src/org/traccar/protocol/EelinkProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/EelinkProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/EgtsFrameDecoder.java45
-rw-r--r--src/org/traccar/protocol/EgtsProtocol.java45
-rw-r--r--src/org/traccar/protocol/EgtsProtocolDecoder.java256
-rw-r--r--src/org/traccar/protocol/EnforaProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/EskyProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ExtremTracProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/FifotrackProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/FlespiProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/FlexCommProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/FlextrackProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/FoxProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/FreedomProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GalileoProtocolDecoder.java24
-rw-r--r--src/org/traccar/protocol/GatorProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GenxProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Gl100ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/Gl200TextProtocolDecoder.java171
-rw-r--r--src/org/traccar/protocol/GlobalSatProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/GlobeKeeperProtocol.java45
-rw-r--r--src/org/traccar/protocol/GlobeKeeperProtocolDecoder.java69
-rw-r--r--src/org/traccar/protocol/GnxProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GoSafeProtocolDecoder.java256
-rw-r--r--src/org/traccar/protocol/GotopProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Gps056ProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/Gps103ProtocolDecoder.java234
-rw-r--r--src/org/traccar/protocol/GpsGateProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/GpsMarkerProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GpsmtaProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/GranitProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/Gt02ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Gt06ProtocolDecoder.java85
-rw-r--r--src/org/traccar/protocol/Gt30ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java17
-rw-r--r--src/org/traccar/protocol/HaicomProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/HomtecsProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/HuaShengProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolEncoder.java6
-rw-r--r--src/org/traccar/protocol/HunterProProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/IdplProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/IntellitracProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Ivt401ProtocolDecoder.java103
-rw-r--r--src/org/traccar/protocol/JpKorjarProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Jt600ProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/KenjiProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/KhdProtocolEncoder.java17
-rw-r--r--src/org/traccar/protocol/L100ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/LaipacProtocolDecoder.java86
-rw-r--r--src/org/traccar/protocol/M2cProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/M2mProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/MaestroProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ManPowerProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java12
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java41
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java5
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/MiniFinderProtocolEncoder.java36
-rw-r--r--src/org/traccar/protocol/Mta6ProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/MtxProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/MxtProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/NavigilProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/NvsProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ObdDongleProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/OigoProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/OkoProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/OpenGtsProtocol.java45
-rw-r--r--src/org/traccar/protocol/OpenGtsProtocolDecoder.java115
-rw-r--r--src/org/traccar/protocol/OrionProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/OsmAndProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/OwnTracksProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/PathAwayProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/PiligrimProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/PretraceProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/PricolProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/ProgressProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Pt3000ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Pt502FrameDecoder.java47
-rw-r--r--src/org/traccar/protocol/Pt502Protocol.java4
-rw-r--r--src/org/traccar/protocol/Pt502ProtocolDecoder.java94
-rw-r--r--src/org/traccar/protocol/Pt60Protocol.java47
-rw-r--r--src/org/traccar/protocol/Pt60ProtocolDecoder.java83
-rw-r--r--src/org/traccar/protocol/RaveonProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/RecodaProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/RitiProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/RoboTrackFrameDecoder.java57
-rw-r--r--src/org/traccar/protocol/RoboTrackProtocol.java45
-rw-r--r--src/org/traccar/protocol/RoboTrackProtocolDecoder.java130
-rw-r--r--src/org/traccar/protocol/RuptelaProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/SanavProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SigfoxProtocolDecoder.java7
-rw-r--r--src/org/traccar/protocol/SiwiProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SkypatrolProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SmokeyProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SpotProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/StarLinkProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Stl060ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/SuntechProtocolDecoder.java24
-rw-r--r--src/org/traccar/protocol/SupermateProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/T55ProtocolDecoder.java20
-rw-r--r--src/org/traccar/protocol/T57ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/T800xProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/T800xProtocolEncoder.java4
-rw-r--r--src/org/traccar/protocol/TaipProtocolDecoder.java93
-rw-r--r--src/org/traccar/protocol/TelicProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java13
-rw-r--r--src/org/traccar/protocol/ThinkRaceProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Tk102ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Tk103Protocol.java3
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java15
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolEncoder.java2
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java44
-rw-r--r--src/org/traccar/protocol/TlvProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TmgFrameDecoder.java7
-rw-r--r--src/org/traccar/protocol/TmgProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TopflytechProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java74
-rw-r--r--src/org/traccar/protocol/Tr20ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Tr900ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TrackboxProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TrakMateProtocolDecoder.java16
-rw-r--r--src/org/traccar/protocol/TramigoProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/Tt8850ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/TzoneProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java18
-rw-r--r--src/org/traccar/protocol/UproProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/V680ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/VisiontekProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Vt200ProtocolDecoder.java8
-rw-r--r--src/org/traccar/protocol/VtfmsProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/WatchFrameDecoder.java89
-rw-r--r--src/org/traccar/protocol/WatchProtocolDecoder.java155
-rw-r--r--src/org/traccar/protocol/WatchProtocolEncoder.java58
-rw-r--r--src/org/traccar/protocol/WialonProtocolDecoder.java6
-rw-r--r--src/org/traccar/protocol/WondexProtocolDecoder.java10
-rw-r--r--src/org/traccar/protocol/XexunProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/XirgoProtocolDecoder.java72
-rw-r--r--src/org/traccar/protocol/Xt013ProtocolDecoder.java3
-rw-r--r--src/org/traccar/protocol/Xt2400ProtocolDecoder.java9
-rw-r--r--src/org/traccar/protocol/YwtProtocolDecoder.java3
-rw-r--r--src/org/traccar/reports/Events.java24
-rw-r--r--src/org/traccar/reports/Stops.java4
-rw-r--r--src/org/traccar/reports/Trips.java4
-rw-r--r--src/org/traccar/reports/model/StopReport.java24
-rw-r--r--src/org/traccar/reports/model/TripReport.java24
-rw-r--r--src/org/traccar/smpp/ClientSmppSessionHandler.java22
-rw-r--r--src/org/traccar/smpp/SmppClient.java26
-rw-r--r--src/org/traccar/web/CsvBuilder.java10
-rw-r--r--src/org/traccar/web/WebServer.java16
-rw-r--r--swagger.json2
-rw-r--r--templates/export/events.xlsxbin12336 -> 8738 bytes
-rw-r--r--templates/mail/maintenance.vm2
-rw-r--r--templates/mail/test.vm2
-rw-r--r--templates/sms/maintenance.vm2
-rw-r--r--templates/sms/test.vm2
-rw-r--r--test/org/traccar/FilterHandlerTest.java2
-rw-r--r--test/org/traccar/ProtocolTest.java131
-rw-r--r--test/org/traccar/WebDataHandlerTest.java22
-rw-r--r--test/org/traccar/calendar/CalendarTest.java11
-rw-r--r--test/org/traccar/database/DataManagerTest.java53
-rw-r--r--test/org/traccar/database/GroupTreeTest.java17
-rw-r--r--test/org/traccar/geocoder/AddressFormatTest.java5
-rw-r--r--test/org/traccar/geocoder/GeocoderTest.java23
-rw-r--r--test/org/traccar/geofence/GeofenceCircleTest.java10
-rw-r--r--test/org/traccar/geofence/GeofencePolygonTest.java22
-rw-r--r--test/org/traccar/geofence/GeofencePolylineTest.java22
-rw-r--r--test/org/traccar/geolocation/GeolocationProviderTest.java10
-rw-r--r--test/org/traccar/helper/BcdUtilTest.java7
-rw-r--r--test/org/traccar/helper/BitUtilTest.java27
-rw-r--r--test/org/traccar/helper/ChecksumTest.java30
-rw-r--r--test/org/traccar/helper/DateBuilderTest.java5
-rw-r--r--test/org/traccar/helper/DateUtilTest.java9
-rw-r--r--test/org/traccar/helper/DistanceCalculatorTest.java9
-rw-r--r--test/org/traccar/helper/LocationTreeTest.java11
-rw-r--r--test/org/traccar/helper/LogTest.java5
-rw-r--r--test/org/traccar/helper/ObdDecoderTest.java17
-rw-r--r--test/org/traccar/helper/PatternBuilderTest.java17
-rw-r--r--test/org/traccar/helper/StringFinderTest.java13
-rw-r--r--test/org/traccar/notification/NotificiationMailTest.java4
-rw-r--r--test/org/traccar/processing/ComputedAttributesTest.java25
-rw-r--r--test/org/traccar/protocol/AdmProtocolEncoderTest.java7
-rw-r--r--test/org/traccar/protocol/AplicomFrameDecoderTest.java7
-rw-r--r--test/org/traccar/protocol/AquilaProtocolDecoderTest.java21
-rw-r--r--test/org/traccar/protocol/At2000FrameDecoderTest.java7
-rw-r--r--test/org/traccar/protocol/AtrackFrameDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/AtrackProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/CastelProtocolDecoderTest.java12
-rw-r--r--test/org/traccar/protocol/CastelProtocolEncoderTest.java22
-rw-r--r--test/org/traccar/protocol/CautelaProtocolDecoderTest.java18
-rw-r--r--test/org/traccar/protocol/ContinentalProtocolDecoderTest.java25
-rw-r--r--test/org/traccar/protocol/DmtProtocolDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/EgtsFrameDecoderTest.java21
-rw-r--r--test/org/traccar/protocol/EgtsProtocolDecoderTest.java36
-rw-r--r--test/org/traccar/protocol/EskyFrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/GalileoFrameDecoderTest.java7
-rw-r--r--test/org/traccar/protocol/GalileoProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/GatorProtocolDecoderTest.java5
-rw-r--r--test/org/traccar/protocol/Gl200FrameDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/GlobeKeeperProtocolDecoderTest.java33
-rw-r--r--test/org/traccar/protocol/GoSafeProtocolDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/Gps056FrameDecoderTest.java7
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolDecoderTest.java6
-rw-r--r--test/org/traccar/protocol/Gps103ProtocolEncoderTest.java7
-rw-r--r--test/org/traccar/protocol/GranitFrameDecoderTest.java17
-rw-r--r--test/org/traccar/protocol/Gt06FrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/H02FrameDecoderTest.java23
-rw-r--r--test/org/traccar/protocol/H02ProtocolDecoderTest.java2
-rw-r--r--test/org/traccar/protocol/H02ProtocolEncoderTest.java15
-rw-r--r--test/org/traccar/protocol/HuaShengFrameDecoderTest.java11
-rw-r--r--test/org/traccar/protocol/HuaShengProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/HuabaoFrameDecoderTest.java5
-rw-r--r--test/org/traccar/protocol/Ivt401ProtocolDecoderTest.java27
-rw-r--r--test/org/traccar/protocol/Jt600FrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/KhdProtocolEncoderTest.java2
-rw-r--r--test/org/traccar/protocol/L100FrameDecoderTest.java7
-rw-r--r--test/org/traccar/protocol/LaipacProtocolDecoderTest.java25
-rw-r--r--test/org/traccar/protocol/MegastekFrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/MegastekProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/MeiligaoFrameDecoderTest.java10
-rw-r--r--test/org/traccar/protocol/MeitrackFrameDecoderTest.java5
-rw-r--r--test/org/traccar/protocol/MeitrackProtocolDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/MeitrackProtocolEncoderTest.java12
-rw-r--r--test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java7
-rw-r--r--test/org/traccar/protocol/NvsFrameDecoderTest.java7
-rw-r--r--test/org/traccar/protocol/OpenGtsProtocolDecoderTest.java18
-rw-r--r--test/org/traccar/protocol/ProgressProtocolDecoderTest.java6
-rw-r--r--test/org/traccar/protocol/Pt502FrameDecoderTest.java5
-rw-r--r--test/org/traccar/protocol/Pt502ProtocolDecoderTest.java48
-rw-r--r--test/org/traccar/protocol/Pt502ProtocolEncoderTest.java11
-rw-r--r--test/org/traccar/protocol/Pt60ProtocolDecoderTest.java24
-rw-r--r--test/org/traccar/protocol/RoboTrackFrameDecoderTest.java19
-rw-r--r--test/org/traccar/protocol/RoboTrackProtocolDecoderTest.java26
-rw-r--r--test/org/traccar/protocol/SuntechProtocolDecoderTest.java12
-rw-r--r--test/org/traccar/protocol/T55ProtocolDecoderTest.java6
-rw-r--r--test/org/traccar/protocol/TaipProtocolDecoderTest.java18
-rw-r--r--test/org/traccar/protocol/TelicFrameDecoderTest.java2
-rw-r--r--test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java6
-rw-r--r--test/org/traccar/protocol/Tk103ProtocolEncoderTest.java55
-rw-r--r--test/org/traccar/protocol/TmgFrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/TotemFrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/TotemProtocolEncoderTest.java5
-rw-r--r--test/org/traccar/protocol/TramigoProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/TzoneProtocolDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/UlbotechFrameDecoderTest.java9
-rw-r--r--test/org/traccar/protocol/Vt200FrameDecoderTest.java1
-rw-r--r--test/org/traccar/protocol/Vt200ProtocolDecoderTest.java3
-rw-r--r--test/org/traccar/protocol/VtfmsFrameDecoderTest.java5
-rw-r--r--test/org/traccar/protocol/WatchFrameDecoderTest.java8
-rw-r--r--test/org/traccar/protocol/WatchProtocolDecoderTest.java18
-rw-r--r--test/org/traccar/protocol/WatchProtocolEncoderTest.java19
-rw-r--r--test/org/traccar/protocol/WondexFrameDecoderTest.java10
-rw-r--r--test/org/traccar/protocol/WondexProtocolEncoderTest.java5
-rw-r--r--test/org/traccar/protocol/XexunFrameDecoderTest.java7
-rw-r--r--test/org/traccar/reports/ReportUtilsTest.java13
m---------traccar-web0
377 files changed, 5262 insertions, 2181 deletions
diff --git a/findbugs.xml b/findbugs.xml
index 18fba5c9a..d7890baac 100644
--- a/findbugs.xml
+++ b/findbugs.xml
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
<Match>
+ <Method name="~get.*Time" />
+ <Bug pattern="EI_EXPOSE_REP" />
+ </Match>
+ <Match>
+ <Method name="~set.*Time" />
+ <Bug pattern="EI_EXPOSE_REP2" />
+ </Match>
+ <Match>
<Class name="org.traccar.notification.PropertiesProvider" />
<Method name="getBoolean" />
<Bug pattern="NP_BOOLEAN_RETURN_NULL" />
diff --git a/pom.xml b/pom.xml
index 33b3a8092..14de784f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,14 +4,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.traccar</groupId>
<artifactId>traccar</artifactId>
- <version>3.15-SNAPSHOT</version>
+ <version>3.16-SNAPSHOT</version>
<name>traccar</name>
<url>https://www.traccar.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <jetty.version>9.2.22.v20170606</jetty.version> <!-- Jetty 9.3+ requires Java 8 -->
+ <jetty.version>9.2.24.v20180105</jetty.version> <!-- Jetty 9.3+ requires Java 8 -->
<jersey.version>2.25.1</jersey.version>
</properties>
@@ -33,6 +33,11 @@
<version>2.9.9</version>
</dependency>
<dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.11</version>
+ </dependency>
+ <dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.196</version>
@@ -45,12 +50,12 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
- <version>42.1.4.jre7</version>
+ <version>42.2.1.jre7</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
- <version>6.2.2.jre7</version>
+ <version>6.4.0.jre7</version>
<exclusions>
<exclusion>
<groupId>com.microsoft.azure</groupId>
@@ -61,7 +66,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP-java7</artifactId>
- <version>2.4.13</version> <!-- Version 2.6 requires Java 8 -->
+ <version>2.4.13</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
@@ -126,7 +131,7 @@
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
- <version>3.5.3</version>
+ <version>3.5.5</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
@@ -136,12 +141,12 @@
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls</artifactId>
- <version>2.4.2</version>
+ <version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.jxls</groupId>
<artifactId>jxls-poi</artifactId>
- <version>1.0.13</version>
+ <version>1.0.14</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
@@ -161,7 +166,7 @@
<dependency>
<groupId>org.mnode.ical4j</groupId>
<artifactId>ical4j</artifactId>
- <version>2.0.4</version>
+ <version>2.0.5</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
@@ -187,7 +192,7 @@
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
- <version>2.17</version>
+ <version>3.0.0</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
@@ -290,7 +295,7 @@
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
- <version>1.0-beta-6</version>
+ <version>1.0-beta-7</version>
</dependency>
</dependencies>
</plugin>
@@ -320,7 +325,7 @@
</plugin>
<plugin>
<artifactId>maven-pmd-plugin</artifactId>
- <version>3.8</version>
+ <version>3.9.0</version>
</plugin>
</plugins>
</reporting>
diff --git a/schema/changelog-3.16.xml b/schema/changelog-3.16.xml
index f95156133..74fe35c3d 100644
--- a/schema/changelog-3.16.xml
+++ b/schema/changelog-3.16.xml
@@ -12,5 +12,19 @@
<column name="disabled" type="BOOLEAN" defaultValueBoolean="false" />
</addColumn>
+ <addColumn tableName="users">
+ <column name="poilayer" type="VARCHAR(512)" />
+ </addColumn>
+
+ <addColumn tableName="servers">
+ <column name="poilayer" type="VARCHAR(512)" />
+ </addColumn>
+
+ <addColumn tableName="notifications">
+ <column name="calendarid" type="INT" />
+ </addColumn>
+
+ <addForeignKeyConstraint baseColumnNames="calendarid" baseTableName="notifications" constraintName="fk_notification_calendar_calendarid" onDelete="SET NULL" onUpdate="RESTRICT" referencedColumnNames="id" referencedTableName="calendars" />
+
</changeSet>
</databaseChangeLog>
diff --git a/schema/changelog-3.17.xml b/schema/changelog-3.17.xml
new file mode 100644
index 000000000..ef296fe25
--- /dev/null
+++ b/schema/changelog-3.17.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"
+ logicalFilePath="changelog-3.17">
+
+ <changeSet author="author" id="changelog-3.17">
+
+ <addColumn tableName="events">
+ <column name="maintenanceid" type="INT" />
+ </addColumn>
+
+ <createTable tableName="maintenances">
+ <column name="id" type="INT" autoIncrement="true">
+ <constraints primaryKey="true" />
+ </column>
+ <column name="name" type="VARCHAR(4000)">
+ <constraints nullable="false" />
+ </column>
+ <column name="type" type="VARCHAR(128)">
+ <constraints nullable="false" />
+ </column>
+ <column name="start" type="DOUBLE" defaultValueNumeric="0">
+ <constraints nullable="false" />
+ </column>
+ <column name="period" type="DOUBLE" defaultValueNumeric="0">
+ <constraints nullable="false" />
+ </column>
+ <column name="attributes" type="VARCHAR(4000)">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <createTable tableName="user_maintenance">
+ <column name="userid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ <column name="maintenanceid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addForeignKeyConstraint baseTableName="user_maintenance" baseColumnNames="userid" constraintName="fk_user_maintenance_userid" referencedTableName="users" referencedColumnNames="id" onDelete="CASCADE" />
+ <addForeignKeyConstraint baseTableName="user_maintenance" baseColumnNames="maintenanceid" constraintName="fk_user_maintenance_maintenanceid" referencedTableName="maintenances" referencedColumnNames="id" onDelete="CASCADE" />
+
+ <createTable tableName="group_maintenance">
+ <column name="groupid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ <column name="maintenanceid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addForeignKeyConstraint baseTableName="group_maintenance" baseColumnNames="groupid" constraintName="fk_group_maintenance_groupid" referencedTableName="groups" referencedColumnNames="id" onDelete="CASCADE" />
+ <addForeignKeyConstraint baseTableName="group_maintenance" baseColumnNames="maintenanceid" constraintName="fk_group_maintenance_maintenanceid" referencedTableName="maintenances" referencedColumnNames="id" onDelete="CASCADE" />
+
+ <createTable tableName="device_maintenance">
+ <column name="deviceid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ <column name="maintenanceid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addForeignKeyConstraint baseTableName="device_maintenance" baseColumnNames="deviceid" constraintName="fk_device_maintenance_deviceid" referencedTableName="devices" referencedColumnNames="id" onDelete="CASCADE" />
+ <addForeignKeyConstraint baseTableName="device_maintenance" baseColumnNames="maintenanceid" constraintName="fk_device_maintenance_maintenanceid" referencedTableName="maintenances" referencedColumnNames="id" onDelete="CASCADE" />
+
+ </changeSet>
+</databaseChangeLog>
diff --git a/schema/changelog-master.xml b/schema/changelog-master.xml
index 0c6941eed..3e7944238 100644
--- a/schema/changelog-master.xml
+++ b/schema/changelog-master.xml
@@ -17,4 +17,5 @@
<include file="changelog-3.14.xml" relativeToChangelogFile="true" />
<include file="changelog-3.15.xml" relativeToChangelogFile="true" />
<include file="changelog-3.16.xml" relativeToChangelogFile="true" />
+ <include file="changelog-3.17.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
diff --git a/setup/default.xml b/setup/default.xml
index 72e6de9af..6bab81401 100644
--- a/setup/default.xml
+++ b/setup/default.xml
@@ -18,7 +18,11 @@
<entry key='logger.level'>all</entry>
<entry key='logger.file'>./logs/tracker-server.log</entry>
+ <entry key='filter.enable'>true</entry>
+ <entry key='filter.future'>3600</entry>
+
<entry key='event.enable'>true</entry>
+ <entry key='event.ignoreDuplicateAlerts'>true</entry>
<entry key='processing.computedAttributes.enable'>true</entry>
<entry key='media.path'>./media</entry>
@@ -226,5 +230,12 @@
<entry key='t57.port'>5155</entry>
<entry key='spot.port'>5156</entry>
<entry key='m2c.port'>5157</entry>
+ <entry key='globekeeper.port'>5158</entry>
+ <entry key='opengts.port'>5159</entry>
+ <entry key='cautela.port'>5160</entry>
+ <entry key='continental.port'>5161</entry>
+ <entry key='egts.port'>5162</entry>
+ <entry key='robotrack.port'>5163</entry>
+ <entry key='pt60.port'>5164</entry>
</properties>
diff --git a/setup/setup.sh b/setup/setup.sh
index 39a00d8e8..51a139dd1 100755
--- a/setup/setup.sh
+++ b/setup/setup.sh
@@ -9,6 +9,7 @@ then
rm -r ../out
rm /opt/traccar/setup.sh
chmod -R go+rX /opt/traccar
+ cd /opt/traccar/bin/
/opt/traccar/bin/installDaemon.sh
else
echo 'Java 7 or higher is required'
diff --git a/setup/traccar.iss b/setup/traccar.iss
index 96cd5fdc0..1d6501d31 100644
--- a/setup/traccar.iss
+++ b/setup/traccar.iss
@@ -1,6 +1,6 @@
[Setup]
AppName=Traccar
-AppVersion=3.15
+AppVersion=3.16
DefaultDirName={pf}\Traccar
AlwaysRestart=yes
OutputBaseFilename=traccar-setup
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index aa188d209..5a077da7c 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -238,7 +238,8 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
}
if (Context.getConfig().getBoolean("forward.enable")) {
- pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url")));
+ pipeline.addLast("webHandler", new WebDataHandler(Context.getConfig().getString("forward.url"),
+ Context.getConfig().getBoolean("forward.json")));
}
if (commandResultEventHandler != null) {
diff --git a/src/org/traccar/BaseProtocol.java b/src/org/traccar/BaseProtocol.java
index 90b9f21f2..07adbea5e 100644
--- a/src/org/traccar/BaseProtocol.java
+++ b/src/org/traccar/BaseProtocol.java
@@ -18,9 +18,9 @@ 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.helper.DataConverter;
import org.traccar.model.Command;
-import javax.xml.bind.DatatypeConverter;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -79,7 +79,7 @@ public abstract class BaseProtocol implements Protocol {
if (activeDevice.getChannel().getPipeline().get(StringEncoder.class) != null) {
activeDevice.write(data);
} else {
- activeDevice.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary(data)));
+ activeDevice.write(ChannelBuffers.wrappedBuffer(DataConverter.parseHex(data)));
}
} else {
throw new RuntimeException("Command " + command.getType() + " is not supported in protocol " + getName());
diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java
index e412134d1..3ea1208ca 100644
--- a/src/org/traccar/BaseProtocolDecoder.java
+++ b/src/org/traccar/BaseProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
+import java.util.TimeZone;
import java.sql.SQLException;
public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
@@ -81,6 +82,25 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
}
}
+ protected TimeZone getTimeZone(long deviceId) {
+ TimeZone result = TimeZone.getTimeZone("UTC");
+ String timeZoneName = null;
+ if (Context.getDeviceManager() != null) {
+ timeZoneName = Context.getDeviceManager().lookupAttributeString(
+ deviceId, "decoder.timezone", null, true);
+ }
+ if (timeZoneName != null) {
+ result = TimeZone.getTimeZone(timeZoneName);
+ } else {
+ int timeZoneOffset = Context.getConfig().getInteger(getProtocolName() + ".timezone", 0);
+ if (timeZoneOffset != 0) {
+ result.setRawOffset(timeZoneOffset * 1000);
+ Log.warning("Config parameter " + getProtocolName() + ".timezone is deprecated");
+ }
+ }
+ return result;
+ }
+
private DeviceSession channelDeviceSession; // connection-based protocols
private Map<SocketAddress, DeviceSession> addressDeviceSessions = new HashMap<>(); // connectionless protocols
@@ -229,8 +249,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder {
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 position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
return position;
diff --git a/src/org/traccar/BaseProtocolEncoder.java b/src/org/traccar/BaseProtocolEncoder.java
index 2c8a81868..18544fd28 100644
--- a/src/org/traccar/BaseProtocolEncoder.java
+++ b/src/org/traccar/BaseProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
if (msg instanceof Command) {
Command command = (Command) msg;
- Object encodedCommand = encodeCommand(command);
+ Object encodedCommand = encodeCommand(channel, command);
// Log command
StringBuilder s = new StringBuilder();
@@ -65,6 +65,12 @@ public abstract class BaseProtocolEncoder extends OneToOneEncoder {
return msg;
}
- protected abstract Object encodeCommand(Command command);
+ protected Object encodeCommand(Channel channel, Command command) {
+ return encodeCommand(command);
+ }
+
+ protected Object encodeCommand(Command command) {
+ return null;
+ }
}
diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java
index 43f4632da..370123ae1 100644
--- a/src/org/traccar/Config.java
+++ b/src/org/traccar/Config.java
@@ -18,6 +18,7 @@ package org.traccar;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
public class Config {
@@ -27,22 +28,26 @@ public class Config {
private boolean useEnvironmentVariables;
void load(String file) throws IOException {
- Properties mainProperties = new Properties();
- try (InputStream inputStream = new FileInputStream(file)) {
- mainProperties.loadFromXML(inputStream);
- }
+ try {
+ 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);
+ String defaultConfigFile = mainProperties.getProperty("config.default");
+ if (defaultConfigFile != null) {
+ try (InputStream inputStream = new FileInputStream(defaultConfigFile)) {
+ properties.loadFromXML(inputStream);
+ }
}
- }
- properties.putAll(mainProperties); // override defaults
+ properties.putAll(mainProperties); // override defaults
- useEnvironmentVariables = Boolean.parseBoolean(System.getenv("CONFIG_USE_ENVIRONMENT_VARIABLES"))
- || Boolean.parseBoolean(properties.getProperty("config.useEnvironmentVariables"));
+ useEnvironmentVariables = Boolean.parseBoolean(System.getenv("CONFIG_USE_ENVIRONMENT_VARIABLES"))
+ || Boolean.parseBoolean(properties.getProperty("config.useEnvironmentVariables"));
+ } catch (InvalidPropertiesFormatException e) {
+ throw new RuntimeException("Configuration file is not a valid XML document", e);
+ }
}
public boolean hasKey(String key) {
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index 3681cc2cc..67fd02f75 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@ import org.traccar.database.DeviceManager;
import org.traccar.database.DriversManager;
import org.traccar.database.IdentityManager;
import org.traccar.database.LdapProvider;
+import org.traccar.database.MaintenancesManager;
import org.traccar.database.MediaManager;
import org.traccar.database.NotificationManager;
import org.traccar.database.PermissionsManager;
@@ -64,6 +65,7 @@ import org.traccar.model.Device;
import org.traccar.model.Driver;
import org.traccar.model.Geofence;
import org.traccar.model.Group;
+import org.traccar.model.Maintenance;
import org.traccar.model.Notification;
import org.traccar.model.User;
import org.traccar.geolocation.GoogleGeolocationProvider;
@@ -232,6 +234,12 @@ public final class Context {
return commandsManager;
}
+ private static MaintenancesManager maintenancesManager;
+
+ public static MaintenancesManager getMaintenancesManager() {
+ return maintenancesManager;
+ }
+
private static StatisticsManager statisticsManager;
public static StatisticsManager getStatisticsManager() {
@@ -337,9 +345,7 @@ public final class Context {
ldapProvider = new LdapProvider(config);
}
- if (config.hasKey("media.path")) {
- mediaManager = new MediaManager(config);
- }
+ mediaManager = new MediaManager(config.getString("media.path"));
if (dataManager != null) {
usersManager = new UsersManager(dataManager);
@@ -421,6 +427,7 @@ public final class Context {
geofenceManager = new GeofenceManager(dataManager);
calendarManager = new CalendarManager(dataManager);
+ maintenancesManager = new MaintenancesManager(dataManager);
notificationManager = new NotificationManager(dataManager);
Properties velocityProperties = new Properties();
velocityProperties.setProperty("file.resource.loader.path",
@@ -471,6 +478,8 @@ public final class Context {
return (BaseObjectManager<T>) driversManager;
} else if (clazz.equals(Command.class)) {
return (BaseObjectManager<T>) commandsManager;
+ } else if (clazz.equals(Maintenance.class)) {
+ return (BaseObjectManager<T>) maintenancesManager;
} else if (clazz.equals(Notification.class)) {
return (BaseObjectManager<T>) notificationManager;
}
diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/DefaultDataHandler.java
index e32fe0e7d..1ac3efc77 100644
--- a/src/org/traccar/DefaultDataHandler.java
+++ b/src/org/traccar/DefaultDataHandler.java
@@ -24,7 +24,7 @@ public class DefaultDataHandler extends BaseDataHandler {
protected Position handlePosition(Position position) {
try {
- Context.getDataManager().addPosition(position);
+ Context.getDataManager().addObject(position);
} catch (Exception error) {
Log.warning(error);
}
diff --git a/src/org/traccar/DeviceSession.java b/src/org/traccar/DeviceSession.java
index 36958287d..322381807 100644
--- a/src/org/traccar/DeviceSession.java
+++ b/src/org/traccar/DeviceSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/
package org.traccar;
+import java.util.TimeZone;
+
public class DeviceSession {
private final long deviceId;
@@ -27,4 +29,14 @@ public class DeviceSession {
return deviceId;
}
+ private TimeZone timeZone;
+
+ public void setTimeZone(TimeZone timeZone) {
+ this.timeZone = timeZone;
+ }
+
+ public TimeZone getTimeZone() {
+ return timeZone;
+ }
+
}
diff --git a/src/org/traccar/ExtendedObjectDecoder.java b/src/org/traccar/ExtendedObjectDecoder.java
index 268e6f688..75a24212f 100644
--- a/src/org/traccar/ExtendedObjectDecoder.java
+++ b/src/org/traccar/ExtendedObjectDecoder.java
@@ -23,9 +23,9 @@ 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.DataConverter;
import org.traccar.model.Position;
-import javax.xml.bind.DatatypeConverter;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
@@ -39,7 +39,7 @@ public abstract class ExtendedObjectDecoder implements ChannelUpstreamHandler {
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(
+ position.set(Position.KEY_ORIGINAL, DataConverter.printHex(
((String) originalMessage).getBytes(StandardCharsets.US_ASCII)));
}
}
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index 4cd3eb0eb..c6363813c 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,9 +26,11 @@ public class FilterHandler extends BaseDataHandler {
private boolean filterDuplicate;
private long filterFuture;
private boolean filterApproximate;
+ private int filterAccuracy;
private boolean filterStatic;
private int filterDistance;
private int filterMaxSpeed;
+ private long filterMinPeriod;
private long skipLimit;
private boolean skipAttributes;
@@ -48,6 +50,10 @@ public class FilterHandler extends BaseDataHandler {
this.filterFuture = filterFuture;
}
+ public void setFilterAccuracy(int filterAccuracy) {
+ this.filterAccuracy = filterAccuracy;
+ }
+
public void setFilterApproximate(boolean filterApproximate) {
this.filterApproximate = filterApproximate;
}
@@ -64,6 +70,10 @@ public class FilterHandler extends BaseDataHandler {
this.filterMaxSpeed = filterMaxSpeed;
}
+ public void setFilterMinPeriod(int filterMinPeriod) {
+ this.filterMinPeriod = filterMinPeriod;
+ }
+
public void setSkipLimit(long skipLimit) {
this.skipLimit = skipLimit;
}
@@ -79,10 +89,12 @@ public class FilterHandler extends BaseDataHandler {
filterZero = config.getBoolean("filter.zero");
filterDuplicate = config.getBoolean("filter.duplicate");
filterFuture = config.getLong("filter.future") * 1000;
+ filterAccuracy = config.getInteger("filter.accuracy");
filterApproximate = config.getBoolean("filter.approximate");
filterStatic = config.getBoolean("filter.static");
filterDistance = config.getInteger("filter.distance");
filterMaxSpeed = config.getInteger("filter.maxSpeed");
+ filterMinPeriod = config.getInteger("filter.minPeriod") * 1000;
skipLimit = config.getLong("filter.skipLimit") * 1000;
skipAttributes = config.getBoolean("filter.skipAttributes.enable");
}
@@ -114,6 +126,10 @@ public class FilterHandler extends BaseDataHandler {
return filterFuture != 0 && position.getFixTime().getTime() > System.currentTimeMillis() + filterFuture;
}
+ private boolean filterAccuracy(Position position) {
+ return filterAccuracy != 0 && position.getAccuracy() > filterAccuracy;
+ }
+
private boolean filterApproximate(Position position) {
return filterApproximate && position.getBoolean(Position.KEY_APPROXIMATE);
}
@@ -138,9 +154,17 @@ public class FilterHandler extends BaseDataHandler {
return false;
}
+ private boolean filterMinPeriod(Position position, Position last) {
+ if (filterMinPeriod != 0 && last != null) {
+ long time = position.getFixTime().getTime() - last.getFixTime().getTime();
+ return time > 0 && time < filterMinPeriod;
+ }
+ return false;
+ }
+
private boolean skipLimit(Position position, Position last) {
if (skipLimit != 0 && last != null) {
- return (position.getFixTime().getTime() - last.getFixTime().getTime()) > skipLimit;
+ return (position.getServerTime().getTime() - last.getServerTime().getTime()) > skipLimit;
}
return false;
}
@@ -183,6 +207,9 @@ public class FilterHandler extends BaseDataHandler {
if (filterFuture(position)) {
filterType.append("Future ");
}
+ if (filterAccuracy(position)) {
+ filterType.append("Accuracy ");
+ }
if (filterApproximate(position)) {
filterType.append("Approximate ");
}
@@ -195,6 +222,9 @@ public class FilterHandler extends BaseDataHandler {
if (filterMaxSpeed(position, last)) {
filterType.append("MaxSpeed ");
}
+ if (filterMinPeriod(position, last)) {
+ filterType.append("MinPeriod ");
+ }
if (filterType.length() > 0) {
@@ -203,8 +233,6 @@ public class FilterHandler extends BaseDataHandler {
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;
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 8e88e15b9..6228f3709 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -60,13 +60,18 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
// 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()));
+ s.append("id: ").append(uniqueId);
+ s.append(", time: ").append(
+ new SimpleDateFormat(Log.DATE_FORMAT).format(position.getFixTime()));
+ s.append(", lat: ").append(String.format("%.5f", position.getLatitude()));
+ s.append(", lon: ").append(String.format("%.5f", position.getLongitude()));
+ if (position.getSpeed() > 0) {
+ s.append(", speed: ").append(String.format("%.1f", position.getSpeed()));
+ }
+ s.append(", course: ").append(String.format("%.1f", position.getCourse()));
+ if (position.getAccuracy() > 0) {
+ s.append(", accuracy: ").append(String.format("%.1f", position.getAccuracy()));
+ }
Object cmdResult = position.getAttributes().get(Position.KEY_RESULT);
if (cmdResult != null) {
s.append(", result: ").append(cmdResult);
diff --git a/src/org/traccar/ServerManager.java b/src/org/traccar/ServerManager.java
index 9b1e2650d..45503b717 100644
--- a/src/org/traccar/ServerManager.java
+++ b/src/org/traccar/ServerManager.java
@@ -15,7 +15,11 @@
*/
package org.traccar;
+import org.jboss.netty.channel.ChannelException;
+import org.traccar.helper.Log;
+
import java.io.File;
+import java.net.BindException;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
@@ -78,7 +82,13 @@ public class ServerManager {
public void start() {
for (TrackerServer server: serverList) {
- server.start();
+ try {
+ server.start();
+ } catch (ChannelException e) {
+ if (e.getCause() instanceof BindException) {
+ Log.warning("One of the protocols is disabled due to port conflict");
+ }
+ }
}
}
@@ -86,8 +96,6 @@ public class ServerManager {
for (TrackerServer server: serverList) {
server.stop();
}
-
- // Release resources
GlobalChannelFactory.release();
GlobalTimer.release();
}
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
index c64dcc81b..cdd9d0c11 100644
--- a/src/org/traccar/WebDataHandler.java
+++ b/src/org/traccar/WebDataHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,11 +16,14 @@
package org.traccar;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.ning.http.client.AsyncHttpClient;
import org.traccar.helper.Checksum;
import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Position;
+import java.util.HashMap;
+import java.util.Map;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@@ -32,9 +35,13 @@ import java.util.TimeZone;
public class WebDataHandler extends BaseDataHandler {
private final String url;
+ private final boolean json;
+ private static final String KEY_POSITION = "position";
+ private static final String KEY_DEVICE = "device";
- public WebDataHandler(String url) {
+ public WebDataHandler(String url, boolean json) {
this.url = url;
+ this.json = json;
}
private static String formatSentence(Position position) {
@@ -80,6 +87,7 @@ public class WebDataHandler extends BaseDataHandler {
String request = url
.replace("{name}", device.getName())
.replace("{uniqueId}", device.getUniqueId())
+ .replace("{status}", device.getStatus())
.replace("{deviceId}", String.valueOf(position.getDeviceId()))
.replace("{protocol}", String.valueOf(position.getProtocol()))
.replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime()))
@@ -120,10 +128,37 @@ public class WebDataHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
+ if (json) {
+ AsyncHttpClient.BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url);
+ requestBuilder.setBodyEncoding(StandardCharsets.UTF_8.name());
- Context.getAsyncHttpClient().prepareGet(formatRequest(position)).execute();
+ requestBuilder.addHeader("Content-Type", "application/json; charset=utf-8");
+ requestBuilder.setBody(prepareJsonPayload(position));
+ requestBuilder.execute();
+
+ } else {
+ Context.getAsyncHttpClient().prepareGet(formatRequest(position)).execute();
+ }
return position;
}
+ protected String prepareJsonPayload(Position position) {
+
+ Map<String, Object> data = new HashMap<>();
+ Device device = Context.getIdentityManager().getById(position.getDeviceId());
+
+ data.put(KEY_POSITION, position);
+
+ if (device != null) {
+ data.put(KEY_DEVICE, device);
+ }
+
+ try {
+ return Context.getObjectMapper().writeValueAsString(data);
+ } catch (JsonProcessingException e) {
+ Log.warning(e);
+ return null;
+ }
+ }
}
diff --git a/src/org/traccar/api/BaseObjectResource.java b/src/org/traccar/api/BaseObjectResource.java
index 806c78624..7de6a3877 100644
--- a/src/org/traccar/api/BaseObjectResource.java
+++ b/src/org/traccar/api/BaseObjectResource.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 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.
@@ -33,9 +33,12 @@ import org.traccar.database.ManagableObjects;
import org.traccar.database.SimpleObjectManager;
import org.traccar.helper.LogAction;
import org.traccar.model.BaseModel;
+import org.traccar.model.Calendar;
import org.traccar.model.Command;
import org.traccar.model.Device;
import org.traccar.model.Group;
+import org.traccar.model.GroupedModel;
+import org.traccar.model.ScheduledModel;
import org.traccar.model.User;
public abstract class BaseObjectResource<T extends BaseModel> extends BaseResource {
@@ -77,6 +80,12 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
Context.getPermissionsManager().checkDeviceLimit(getUserId());
} else if (baseClass.equals(Command.class)) {
Context.getPermissionsManager().checkLimitCommands(getUserId());
+ } else if (entity instanceof GroupedModel && ((GroupedModel) entity).getGroupId() != 0) {
+ Context.getPermissionsManager().checkPermission(
+ Group.class, getUserId(), ((GroupedModel) entity).getGroupId());
+ } else if (entity instanceof ScheduledModel && ((ScheduledModel) entity).getCalendarId() != 0) {
+ Context.getPermissionsManager().checkPermission(
+ Calendar.class, getUserId(), ((ScheduledModel) entity).getCalendarId());
}
BaseObjectManager<T> manager = Context.getManager(baseClass);
@@ -106,6 +115,12 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
Context.getPermissionsManager().checkUserUpdate(getUserId(), before, (User) entity);
} else if (baseClass.equals(Command.class)) {
Context.getPermissionsManager().checkLimitCommands(getUserId());
+ } else if (entity instanceof GroupedModel && ((GroupedModel) entity).getGroupId() != 0) {
+ Context.getPermissionsManager().checkPermission(
+ Group.class, getUserId(), ((GroupedModel) entity).getGroupId());
+ } else if (entity instanceof ScheduledModel && ((ScheduledModel) entity).getCalendarId() != 0) {
+ Context.getPermissionsManager().checkPermission(
+ Calendar.class, getUserId(), ((ScheduledModel) entity).getCalendarId());
}
Context.getPermissionsManager().checkPermission(baseClass, getUserId(), entity.getId());
@@ -141,12 +156,19 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
}
}
if (baseClass.equals(Group.class) || baseClass.equals(Device.class) || baseClass.equals(User.class)) {
+ if (baseClass.equals(Group.class)) {
+ Context.getGroupsManager().updateGroupCache(true);
+ Context.getDeviceManager().updateDeviceCache(true);
+ }
Context.getPermissionsManager().refreshDeviceAndGroupPermissions();
if (baseClass.equals(User.class)) {
Context.getPermissionsManager().refreshAllUsersPermissions();
} else {
Context.getPermissionsManager().refreshAllExtendedPermissions();
}
+ } else if (baseClass.equals(Calendar.class)) {
+ Context.getGeofenceManager().refreshItems();
+ Context.getNotificationManager().refreshItems();
}
return Response.noContent().build();
}
diff --git a/src/org/traccar/api/MediaFilter.java b/src/org/traccar/api/MediaFilter.java
new file mode 100644
index 000000000..25e242b01
--- /dev/null
+++ b/src/org/traccar/api/MediaFilter.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 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.io.IOException;
+import java.sql.SQLException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.traccar.Context;
+import org.traccar.api.resource.SessionResource;
+import org.traccar.helper.Log;
+import org.traccar.model.Device;
+
+public class MediaFilter implements Filter {
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
+ HttpServletResponse httpResponse = (HttpServletResponse) response;
+ try {
+ HttpSession session = ((HttpServletRequest) request).getSession(false);
+ Long userId = null;
+ if (session != null) {
+ userId = (Long) session.getAttribute(SessionResource.USER_ID_KEY);
+ if (userId != null) {
+ Context.getPermissionsManager().checkUserEnabled(userId);
+ Context.getStatisticsManager().registerRequest(userId);
+ }
+ }
+ if (userId == null) {
+ httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+ return;
+ }
+
+ String path = ((HttpServletRequest) request).getPathInfo();
+ String[] parts = path.split("/");
+ if (parts.length < 2 || parts.length == 2 && !path.endsWith("/")) {
+ Context.getPermissionsManager().checkAdmin(userId);
+ } else {
+ Device device = Context.getDeviceManager().getByUniqueId(parts[1]);
+ if (device != null) {
+ Context.getPermissionsManager().checkDevice(userId, device.getId());
+ } else {
+ httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+ }
+
+ chain.doFilter(request, response);
+ } catch (SecurityException e) {
+ httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
+ httpResponse.getWriter().println(Log.exceptionStack(e));
+ } catch (SQLException e) {
+ httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ httpResponse.getWriter().println(Log.exceptionStack(e));
+ }
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+}
diff --git a/src/org/traccar/api/SecurityRequestFilter.java b/src/org/traccar/api/SecurityRequestFilter.java
index 7024bdbc9..aace9f705 100644
--- a/src/org/traccar/api/SecurityRequestFilter.java
+++ b/src/org/traccar/api/SecurityRequestFilter.java
@@ -17,6 +17,7 @@ package org.traccar.api;
import org.traccar.Context;
import org.traccar.api.resource.SessionResource;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.Log;
import org.traccar.model.User;
@@ -28,7 +29,6 @@ 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;
@@ -43,7 +43,7 @@ public class SecurityRequestFilter implements ContainerRequestFilter {
public static String[] decodeBasicAuth(String auth) {
auth = auth.replaceFirst("[B|b]asic ", "");
- byte[] decodedBytes = DatatypeConverter.parseBase64Binary(auth);
+ byte[] decodedBytes = DataConverter.parseBase64(auth);
if (decodedBytes != null && decodedBytes.length > 0) {
return new String(decodedBytes, StandardCharsets.US_ASCII).split(":", 2);
}
diff --git a/src/org/traccar/api/resource/AttributeResource.java b/src/org/traccar/api/resource/AttributeResource.java
index 26a1f6931..8f0bac473 100644
--- a/src/org/traccar/api/resource/AttributeResource.java
+++ b/src/org/traccar/api/resource/AttributeResource.java
@@ -52,9 +52,11 @@ public class AttributeResource extends ExtendedObjectResource<Attribute> {
if (result != null) {
switch (entity.getType()) {
case "number":
- return Response.ok((Number) result).build();
+ Number numberValue = (Number) result;
+ return Response.ok(numberValue).build();
case "boolean":
- return Response.ok((Boolean) result).build();
+ Boolean booleanValue = (Boolean) result;
+ return Response.ok(booleanValue).build();
default:
return Response.ok(result.toString()).build();
}
diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java
index 0ea532567..87927e45b 100644
--- a/src/org/traccar/api/resource/DeviceResource.java
+++ b/src/org/traccar/api/resource/DeviceResource.java
@@ -71,7 +71,7 @@ public class DeviceResource extends BaseObjectResource<Device> {
result = deviceManager.getUserItems(userId);
}
} else {
- result = new HashSet<Long>();
+ result = new HashSet<>();
for (String uniqueId : uniqueIds) {
Device device = deviceManager.getByUniqueId(uniqueId);
Context.getPermissionsManager().checkDevice(getUserId(), device.getId());
@@ -88,7 +88,10 @@ public class DeviceResource extends BaseObjectResource<Device> {
@Path("{id}/distance")
@PUT
public Response updateTotalDistance(DeviceTotalDistance entity) throws SQLException {
- Context.getPermissionsManager().checkAdmin(getUserId());
+ if (!Context.getPermissionsManager().getUserAdmin(getUserId())) {
+ Context.getPermissionsManager().checkManager(getUserId());
+ Context.getPermissionsManager().checkPermission(Device.class, getUserId(), entity.getDeviceId());
+ }
Context.getDeviceManager().resetTotalDistance(entity);
LogAction.resetTotalDistance(getUserId(), entity.getDeviceId());
return Response.noContent().build();
diff --git a/src/org/traccar/api/resource/EventResource.java b/src/org/traccar/api/resource/EventResource.java
index a7cf9edbd..e0ccf7020 100644
--- a/src/org/traccar/api/resource/EventResource.java
+++ b/src/org/traccar/api/resource/EventResource.java
@@ -13,6 +13,7 @@ import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
+import org.traccar.model.Maintenance;
@Path("events")
@Produces(MediaType.APPLICATION_JSON)
@@ -28,6 +29,9 @@ public class EventResource extends BaseResource {
if (event.getGeofenceId() != 0) {
Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId());
}
+ if (event.getMaintenanceId() != 0) {
+ Context.getPermissionsManager().checkPermission(Maintenance.class, getUserId(), event.getMaintenanceId());
+ }
return event;
}
diff --git a/src/org/traccar/api/resource/MaintenanceResource.java b/src/org/traccar/api/resource/MaintenanceResource.java
new file mode 100644
index 000000000..b3726b429
--- /dev/null
+++ b/src/org/traccar/api/resource/MaintenanceResource.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 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.Maintenance;
+
+@Path("maintenances")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class MaintenanceResource extends ExtendedObjectResource<Maintenance> {
+
+ public MaintenanceResource() {
+ super(Maintenance.class);
+ }
+
+}
diff --git a/src/org/traccar/api/resource/SessionResource.java b/src/org/traccar/api/resource/SessionResource.java
index 3f7842626..fd331c766 100644
--- a/src/org/traccar/api/resource/SessionResource.java
+++ b/src/org/traccar/api/resource/SessionResource.java
@@ -17,6 +17,7 @@ package org.traccar.api.resource;
import org.traccar.Context;
import org.traccar.api.BaseResource;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.LogAction;
import org.traccar.model.User;
@@ -34,7 +35,6 @@ 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;
@@ -61,15 +61,14 @@ public class SessionResource extends BaseResource {
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()));
+ for (Cookie cookie : cookies) {
+ if (cookie.getName().equals(USER_COOKIE_KEY)) {
+ byte[] emailBytes = DataConverter.parseBase64(
+ URLDecoder.decode(cookie.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()));
+ } else if (cookie.getName().equals(PASS_COOKIE_KEY)) {
+ byte[] passwordBytes = DataConverter.parseBase64(
+ URLDecoder.decode(cookie.getValue(), StandardCharsets.US_ASCII.name()));
password = new String(passwordBytes, StandardCharsets.UTF_8);
}
}
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index f813426d3..84f8f0394 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -48,6 +48,7 @@ import org.traccar.model.Driver;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Group;
+import org.traccar.model.Maintenance;
import org.traccar.model.ManagedUser;
import org.traccar.model.Notification;
import org.traccar.model.Permission;
@@ -242,12 +243,16 @@ public class DataManager {
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();
+ switch (action) {
+ case ACTION_SELECT_ALL:
+ queryName = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s";
+ break;
+ case ACTION_INSERT:
+ queryName = "database.link" + owner.getSimpleName() + property.getSimpleName();
+ break;
+ default:
+ queryName = "database.unlink" + owner.getSimpleName() + property.getSimpleName();
+ break;
}
String query = config.getString(queryName);
if (query == null) {
@@ -335,13 +340,6 @@ public class DataManager {
.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())
@@ -408,6 +406,8 @@ public class DataManager {
return Calendar.class;
case "command":
return Command.class;
+ case "maintenance":
+ return Maintenance.class;
case "notification":
return Notification.class;
default:
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index cb410b7c0..c59061b7f 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -65,7 +65,7 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
refreshLastPositions();
}
- private void updateDeviceCache(boolean force) throws SQLException {
+ public void updateDeviceCache(boolean force) throws SQLException {
long lastUpdate = devicesLastUpdate.get();
if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
&& devicesLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
@@ -355,7 +355,7 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
Position last = positions.get(deviceTotalDistance.getDeviceId());
if (last != null) {
last.getAttributes().put(Position.KEY_TOTAL_DISTANCE, deviceTotalDistance.getTotalDistance());
- getDataManager().addPosition(last);
+ getDataManager().addObject(last);
updateLatestPosition(last);
} else {
throw new IllegalArgumentException();
diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java
index 16785cb37..c9e349136 100644
--- a/src/org/traccar/database/ExtendedObjectManager.java
+++ b/src/org/traccar/database/ExtendedObjectManager.java
@@ -95,7 +95,7 @@ public abstract class ExtendedObjectManager<T extends BaseModel> extends SimpleO
long groupId = device.getGroupId();
while (groupId != 0) {
getAllDeviceItems(device.getId()).addAll(getGroupItems(groupId));
- Group group = (Group) Context.getGroupsManager().getById(groupId);
+ Group group = Context.getGroupsManager().getById(groupId);
if (group != null) {
groupId = group.getGroupId();
} else {
diff --git a/src/org/traccar/database/GroupsManager.java b/src/org/traccar/database/GroupsManager.java
index c0456085b..262f15519 100644
--- a/src/org/traccar/database/GroupsManager.java
+++ b/src/org/traccar/database/GroupsManager.java
@@ -47,7 +47,7 @@ public class GroupsManager extends BaseObjectManager<Group> implements Managable
}
}
- private void updateGroupCache(boolean force) throws SQLException {
+ public void updateGroupCache(boolean force) throws SQLException {
long lastUpdate = groupsLastUpdate.get();
if ((force || System.currentTimeMillis() - lastUpdate > dataRefreshDelay)
&& groupsLastUpdate.compareAndSet(lastUpdate, System.currentTimeMillis())) {
@@ -76,9 +76,9 @@ public class GroupsManager extends BaseObjectManager<Group> implements Managable
}
@Override
- protected void updateCachedItem(Group group) {
+ public void updateItem(Group group) throws SQLException {
checkGroupCycles(group);
- super.updateCachedItem(group);
+ super.updateItem(group);
}
@Override
diff --git a/src/org/traccar/database/LdapProvider.java b/src/org/traccar/database/LdapProvider.java
index 2c4b7ceb1..44dd386ed 100644
--- a/src/org/traccar/database/LdapProvider.java
+++ b/src/org/traccar/database/LdapProvider.java
@@ -115,7 +115,7 @@ public class LdapProvider {
SearchResult searchResult = null;
if (results.hasMoreElements()) {
- searchResult = (SearchResult) results.nextElement();
+ searchResult = results.nextElement();
if (results.hasMoreElements()) {
Log.warning("Matched multiple users for the accountName: " + accountName);
return null;
diff --git a/src/org/traccar/database/MaintenancesManager.java b/src/org/traccar/database/MaintenancesManager.java
new file mode 100644
index 000000000..4e266cb78
--- /dev/null
+++ b/src/org/traccar/database/MaintenancesManager.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 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.Maintenance;
+
+public class MaintenancesManager extends ExtendedObjectManager<Maintenance> {
+
+ public MaintenancesManager(DataManager dataManager) {
+ super(dataManager, Maintenance.class);
+ }
+
+}
diff --git a/src/org/traccar/database/MediaManager.java b/src/org/traccar/database/MediaManager.java
index 2c448a20c..482442735 100644
--- a/src/org/traccar/database/MediaManager.java
+++ b/src/org/traccar/database/MediaManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.traccar.database;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.traccar.Config;
import org.traccar.helper.Log;
import java.io.File;
@@ -34,8 +33,8 @@ public class MediaManager {
private String path;
- public MediaManager(Config config) {
- path = config.getString("media.path");
+ public MediaManager(String path) {
+ this.path = path;
}
private File createFile(String uniqueId, String name) throws IOException {
@@ -48,19 +47,21 @@ public class MediaManager {
}
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);
+ if (path != null) {
+ 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);
}
- 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
index 4e6114001..3bc048356 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 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.
@@ -19,6 +19,7 @@ package org.traccar.database;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.sql.SQLException;
+import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
@@ -26,6 +27,7 @@ import java.util.Set;
import org.traccar.Context;
import org.traccar.helper.Log;
+import org.traccar.model.Calendar;
import org.traccar.model.Event;
import org.traccar.model.Notification;
import org.traccar.model.Position;
@@ -42,12 +44,16 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
geocodeOnRequest = Context.getConfig().getBoolean("geocoder.onRequest");
}
- private Set<Long> getEffectiveNotifications(long userId, long deviceId) {
+ private Set<Long> getEffectiveNotifications(long userId, long deviceId, Date time) {
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);
+ long calendarId = getById(itemId).getCalendarId();
+ Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
+ if (calendar == null || calendar.checkMoment(time)) {
+ result.add(itemId);
+ }
}
}
return result;
@@ -67,13 +73,22 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
long deviceId = event.getDeviceId();
Set<Long> users = Context.getPermissionsManager().getDeviceUsers(deviceId);
+ Set<Long> usersToForward = null;
+ if (Context.getEventForwarder() != null) {
+ usersToForward = new HashSet<>();
+ }
for (long userId : users) {
- if (event.getGeofenceId() == 0 || Context.getGeofenceManager() != null
- && Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId())) {
+ if ((event.getGeofenceId() == 0
+ || Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId()))
+ && (event.getMaintenanceId() == 0
+ || Context.getMaintenancesManager().checkItemPermission(userId, event.getMaintenanceId()))) {
+ if (usersToForward != null) {
+ usersToForward.add(userId);
+ }
boolean sentWeb = false;
boolean sentMail = false;
boolean sentSms = Context.getSmppManager() == null;
- for (long notificationId : getEffectiveNotifications(userId, deviceId)) {
+ for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getServerTime())) {
Notification notification = getById(notificationId);
if (getById(notificationId).getType().equals(event.getType())) {
if (!sentWeb && notification.getWeb()) {
@@ -96,7 +111,7 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
}
}
if (Context.getEventForwarder() != null) {
- Context.getEventForwarder().forwardEvent(event, position);
+ Context.getEventForwarder().forwardEvent(event, position, usersToForward);
}
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 60bda99ce..b5f062d2b 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import org.traccar.model.Device;
import org.traccar.model.Driver;
import org.traccar.model.Geofence;
import org.traccar.model.Group;
+import org.traccar.model.Maintenance;
import org.traccar.model.ManagedUser;
import org.traccar.model.Notification;
import org.traccar.model.Permission;
@@ -57,7 +58,7 @@ public class PermissionsManager {
}
public User getUser(long userId) {
- return (User) usersManager.getById(userId);
+ return usersManager.getById(userId);
}
public Set<Long> getGroupPermissions(long userId) {
@@ -337,6 +338,8 @@ public class PermissionsManager {
manager = Context.getCalendarManager();
} else if (object.equals(Command.class)) {
manager = Context.getCommandsManager();
+ } else if (object.equals(Maintenance.class)) {
+ manager = Context.getMaintenancesManager();
} else if (object.equals(Notification.class)) {
manager = Context.getNotificationManager();
} else {
@@ -362,6 +365,7 @@ public class PermissionsManager {
Context.getDriversManager().refreshUserItems();
Context.getAttributesManager().refreshUserItems();
Context.getCommandsManager().refreshUserItems();
+ Context.getMaintenancesManager().refreshUserItems();
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshUserItems();
}
@@ -374,6 +378,7 @@ public class PermissionsManager {
Context.getDriversManager().refreshExtendedPermissions();
Context.getAttributesManager().refreshExtendedPermissions();
Context.getCommandsManager().refreshExtendedPermissions();
+ Context.getMaintenancesManager().refreshExtendedPermissions();
}
public void refreshPermissions(Permission permission) {
@@ -394,6 +399,8 @@ public class PermissionsManager {
Context.getCalendarManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Command.class)) {
Context.getCommandsManager().refreshUserItems();
+ } else if (permission.getPropertyClass().equals(Maintenance.class)) {
+ Context.getMaintenancesManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Notification.class)
&& Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshUserItems();
@@ -407,6 +414,8 @@ public class PermissionsManager {
Context.getAttributesManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Command.class)) {
Context.getCommandsManager().refreshExtendedPermissions();
+ } else if (permission.getPropertyClass().equals(Maintenance.class)) {
+ Context.getMaintenancesManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Notification.class)
&& Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshExtendedPermissions();
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
index 003ccb662..7db371c70 100644
--- a/src/org/traccar/events/AlertEventHandler.java
+++ b/src/org/traccar/events/AlertEventHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,18 +19,34 @@ 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 AlertEventHandler extends BaseEventHandler {
+ private final boolean ignoreDuplicateAlerts;
+
+ public AlertEventHandler() {
+ ignoreDuplicateAlerts = Context.getConfig().getBoolean("event.ignoreDuplicateAlerts");
+ }
+
@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);
+ boolean ignoreAlert = false;
+ if (ignoreDuplicateAlerts) {
+ Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null && alarm.equals(lastPosition.getAttributes().get(Position.KEY_ALARM))) {
+ ignoreAlert = true;
+ }
+ }
+ if (!ignoreAlert) {
+ 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/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java
index 86abf7c17..4a6122826 100644
--- a/src/org/traccar/events/MaintenanceEventHandler.java
+++ b/src/org/traccar/events/MaintenanceEventHandler.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,54 +16,47 @@
*/
package org.traccar.events;
-import java.util.Collections;
+import java.util.HashMap;
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.Maintenance;
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) {
+ if (Context.getIdentityManager().getById(position.getDeviceId()) == null
+ || !Context.getIdentityManager().isLatestPosition(position)) {
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);
+ if (lastPosition == null) {
+ return null;
}
- 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);
+ Map<Event, Position> events = new HashMap<>();
+ for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) {
+ Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId);
+ if (maintenance.getPeriod() != 0) {
+ double oldValue = lastPosition.getDouble(maintenance.getType());
+ double newValue = position.getDouble(maintenance.getType());
+ if (oldValue != 0.0 && newValue != 0.0
+ && (long) ((oldValue - maintenance.getStart()) / maintenance.getPeriod())
+ < (long) ((newValue - maintenance.getStart()) / maintenance.getPeriod())) {
+ Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId());
+ event.setMaintenanceId(maintenanceId);
+ event.set(maintenance.getType(), newValue);
+ events.put(event, position);
+ }
+ }
}
- return null;
+ return events;
}
}
diff --git a/src/org/traccar/geocoder/Address.java b/src/org/traccar/geocoder/Address.java
index d542d1b19..fe39da8e1 100644
--- a/src/org/traccar/geocoder/Address.java
+++ b/src/org/traccar/geocoder/Address.java
@@ -97,4 +97,14 @@ public class Address {
this.house = house;
}
+ private String formattedAddress;
+
+ public String getFormattedAddress() {
+ return formattedAddress;
+ }
+
+ public void setFormattedAddress(String formattedAddress) {
+ this.formattedAddress = formattedAddress;
+ }
+
}
diff --git a/src/org/traccar/geocoder/AddressFormat.java b/src/org/traccar/geocoder/AddressFormat.java
index 0800d6dcc..220f268f1 100644
--- a/src/org/traccar/geocoder/AddressFormat.java
+++ b/src/org/traccar/geocoder/AddressFormat.java
@@ -66,6 +66,7 @@ public class AddressFormat extends Format {
result = replace(result, "%u", address.getSuburb());
result = replace(result, "%r", address.getStreet());
result = replace(result, "%h", address.getHouse());
+ result = replace(result, "%f", address.getFormattedAddress());
result = result.replaceAll("^[, ]*", "");
diff --git a/src/org/traccar/geocoder/BingMapsGeocoder.java b/src/org/traccar/geocoder/BingMapsGeocoder.java
index fbfb5394a..32a26ee0c 100644
--- a/src/org/traccar/geocoder/BingMapsGeocoder.java
+++ b/src/org/traccar/geocoder/BingMapsGeocoder.java
@@ -51,6 +51,9 @@ public class BingMapsGeocoder extends JsonGeocoder {
if (location.containsKey("postalCode")) {
address.setPostcode(location.getString("postalCode"));
}
+ if (location.containsKey("formattedAddress")) {
+ address.setFormattedAddress(location.getString("formattedAddress"));
+ }
return address;
}
}
diff --git a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
index 4fb956af9..39a3300a0 100644
--- a/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
+++ b/src/org/traccar/geocoder/GeocodeFarmGeocoder.java
@@ -41,23 +41,27 @@ public class GeocodeFarmGeocoder extends JsonGeocoder {
JsonObject result = json
.getJsonObject("geocoding_results")
.getJsonArray("RESULTS")
- .getJsonObject(0)
- .getJsonObject("ADDRESS");
+ .getJsonObject(0);
- if (result.containsKey("street_number")) {
- address.setStreet(result.getString("street_number"));
+ JsonObject resultAddress = result.getJsonObject("ADDRESS");
+
+ if (result.containsKey("formatted_address")) {
+ address.setFormattedAddress(result.getString("formatted_address"));
+ }
+ if (resultAddress.containsKey("street_number")) {
+ address.setStreet(resultAddress.getString("street_number"));
}
- if (result.containsKey("street_name")) {
- address.setStreet(result.getString("street_name"));
+ if (resultAddress.containsKey("street_name")) {
+ address.setStreet(resultAddress.getString("street_name"));
}
- if (result.containsKey("locality")) {
- address.setSettlement(result.getString("locality"));
+ if (resultAddress.containsKey("locality")) {
+ address.setSettlement(resultAddress.getString("locality"));
}
- if (result.containsKey("admin_1")) {
- address.setState(result.getString("admin_1"));
+ if (resultAddress.containsKey("admin_1")) {
+ address.setState(resultAddress.getString("admin_1"));
}
- if (result.containsKey("country")) {
- address.setCountry(result.getString("country"));
+ if (resultAddress.containsKey("country")) {
+ address.setCountry(resultAddress.getString("country"));
}
return address;
diff --git a/src/org/traccar/geocoder/GisgraphyGeocoder.java b/src/org/traccar/geocoder/GisgraphyGeocoder.java
index a0c831966..3a173f985 100644
--- a/src/org/traccar/geocoder/GisgraphyGeocoder.java
+++ b/src/org/traccar/geocoder/GisgraphyGeocoder.java
@@ -45,6 +45,9 @@ public class GisgraphyGeocoder extends JsonGeocoder {
if (result.containsKey("countryCode")) {
address.setCountry(result.getString("countryCode"));
}
+ if (result.containsKey("formatedFull")) {
+ address.setFormattedAddress(result.getString("formatedFull"));
+ }
return address;
}
diff --git a/src/org/traccar/geocoder/GoogleGeocoder.java b/src/org/traccar/geocoder/GoogleGeocoder.java
index 235ea9ea9..af9b58a90 100644
--- a/src/org/traccar/geocoder/GoogleGeocoder.java
+++ b/src/org/traccar/geocoder/GoogleGeocoder.java
@@ -46,6 +46,10 @@ public class GoogleGeocoder extends JsonGeocoder {
JsonObject result = (JsonObject) results.get(0);
JsonArray components = result.getJsonArray("address_components");
+ if (result.containsKey("formatted_address")) {
+ address.setFormattedAddress(result.getString("formatted_address"));
+ }
+
for (JsonObject component : components.getValuesAs(JsonObject.class)) {
String value = component.getString("short_name");
diff --git a/src/org/traccar/geocoder/NominatimGeocoder.java b/src/org/traccar/geocoder/NominatimGeocoder.java
index 75d2e9f99..c0142ae27 100644
--- a/src/org/traccar/geocoder/NominatimGeocoder.java
+++ b/src/org/traccar/geocoder/NominatimGeocoder.java
@@ -44,6 +44,10 @@ public class NominatimGeocoder extends JsonGeocoder {
if (result != null) {
Address address = new Address();
+ if (json.containsKey("display_name")) {
+ address.setFormattedAddress(json.getString("display_name"));
+ }
+
if (result.containsKey("house_number")) {
address.setHouse(result.getString("house_number"));
}
diff --git a/src/org/traccar/geocoder/OpenCageGeocoder.java b/src/org/traccar/geocoder/OpenCageGeocoder.java
index 894397ee3..c21d5562a 100644
--- a/src/org/traccar/geocoder/OpenCageGeocoder.java
+++ b/src/org/traccar/geocoder/OpenCageGeocoder.java
@@ -33,6 +33,9 @@ public class OpenCageGeocoder extends JsonGeocoder {
if (location != null) {
Address address = new Address();
+ if (result.getJsonObject(0).containsKey("formatted")) {
+ address.setFormattedAddress(result.getJsonObject(0).getString("formatted"));
+ }
if (location.containsKey("building")) {
address.setHouse(location.getString("building"));
}
diff --git a/src/org/traccar/geofence/GeofenceCircle.java b/src/org/traccar/geofence/GeofenceCircle.java
index d78734714..f6fca63ca 100644
--- a/src/org/traccar/geofence/GeofenceCircle.java
+++ b/src/org/traccar/geofence/GeofenceCircle.java
@@ -39,9 +39,13 @@ public class GeofenceCircle extends GeofenceGeometry {
this.radius = radius;
}
+ public double distanceFromCenter(double latitude, double longitude) {
+ return DistanceCalculator.distance(centerLatitude, centerLongitude, latitude, longitude);
+ }
+
@Override
public boolean containsPoint(double latitude, double longitude) {
- return DistanceCalculator.distance(centerLatitude, centerLongitude, latitude, longitude) <= radius;
+ return distanceFromCenter(latitude, longitude) <= radius;
}
@Override
diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java
index 43ba6a689..5aed84bf8 100644
--- a/src/org/traccar/helper/Checksum.java
+++ b/src/org/traccar/helper/Checksum.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,163 +24,109 @@ 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);
+ public static class Algorithm {
+
+ private int poly;
+ private int init;
+ private boolean refIn;
+ private boolean refOut;
+ private int xorOut;
+ private int[] table;
+
+ public Algorithm(int bits, int poly, int init, boolean refIn, boolean refOut, int xorOut) {
+ this.poly = poly;
+ this.init = init;
+ this.refIn = refIn;
+ this.refOut = refOut;
+ this.xorOut = xorOut;
+ this.table = bits == 8 ? initTable8() : initTable16();
+ }
+
+ private int[] initTable8() {
+ int[] table = new int[256];
+ int crc;
+ for (int i = 0; i < 256; i++) {
+ crc = i;
+ for (int j = 0; j < 8; j++) {
+ boolean bit = (crc & 0x80) != 0;
+ crc <<= 1;
+ if (bit) {
+ crc ^= poly;
+ }
+ }
+ table[i] = crc & 0xFF;
+ }
+ return table;
+ }
+
+ private int[] initTable16() {
+ int[] table = new int[256];
+ int crc;
+ for (int i = 0; i < 256; i++) {
+ crc = i << 8;
+ for (int j = 0; j < 8; j++) {
+ boolean bit = (crc & 0x8000) != 0;
+ crc <<= 1;
+ if (bit) {
+ crc ^= poly;
+ }
+ }
+ table[i] = crc & 0xFFFF;
+ }
+ return table;
+ }
+
+ }
+
+ private static int reverse(int value, int bits) {
+ int result = 0;
+ for (int i = 0; i < bits; i++) {
+ result = (result << 1) | (value & 1);
+ value >>= 1;
}
- return crc16 & 0xFFFF;
+ return result;
}
- private static int crc16Reflected(ByteBuffer buf, int crcIn, int[] table) {
- int crc16 = crcIn;
+ public static int crc8(Algorithm algorithm, ByteBuffer buf) {
+ int crc = algorithm.init;
while (buf.hasRemaining()) {
- crc16 = table[(crc16 ^ buf.get()) & 0xff] ^ (crc16 >> 8);
+ int b = buf.get() & 0xFF;
+ if (algorithm.refIn) {
+ b = reverse(b, 8);
+ }
+ crc = algorithm.table[(crc & 0xFF) ^ b];
+ }
+ if (algorithm.refOut) {
+ crc = reverse(crc, 8);
}
- return crc16 & 0xFFFF;
+ return (crc ^ algorithm.xorOut) & 0xFF;
}
- 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 crc16(Algorithm algorithm, ByteBuffer buf) {
+ int crc = algorithm.init;
+ while (buf.hasRemaining()) {
+ int b = buf.get() & 0xFF;
+ if (algorithm.refIn) {
+ b = reverse(b, 8);
+ }
+ crc = (crc << 8) ^ algorithm.table[((crc >> 8) & 0xFF) ^ b];
+ }
+ if (algorithm.refOut) {
+ crc = reverse(crc, 16);
}
+ return (crc ^ algorithm.xorOut) & 0xFFFF;
}
+ public static final Algorithm CRC8_EGTS = new Algorithm(8, 0x31, 0xFF, false, false, 0x00);
+ public static final Algorithm CRC8_ROHC = new Algorithm(8, 0x07, 0xFF, true, true, 0x00);
+
+ public static final Algorithm CRC16_IBM = new Algorithm(16, 0x8005, 0x0000, true, true, 0x0000);
+ public static final Algorithm CRC16_X25 = new Algorithm(16, 0x1021, 0xFFFF, true, true, 0xFFFF);
+ public static final Algorithm CRC16_MODBUS = new Algorithm(16, 0x8005, 0xFFFF, true, true, 0x0000);
+ public static final Algorithm CRC16_CCITT_FALSE = new Algorithm(16, 0x1021, 0xFFFF, false, false, 0x0000);
+ public static final Algorithm CRC16_KERMIT = new Algorithm(16, 0x1021, 0x0000, true, true, 0x0000);
+ public static final Algorithm CRC16_XMODEM = new Algorithm(16, 0x1021, 0x0000, false, false, 0x0000);
+
public static int crc32(ByteBuffer buf) {
CRC32 checksum = new CRC32();
while (buf.hasRemaining()) {
diff --git a/src/org/traccar/helper/DataConverter.java b/src/org/traccar/helper/DataConverter.java
new file mode 100644
index 000000000..7abd4ae93
--- /dev/null
+++ b/src/org/traccar/helper/DataConverter.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS 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.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+
+public final class DataConverter {
+
+ private DataConverter() {
+ }
+
+ public static byte[] parseHex(String string) {
+ try {
+ return Hex.decodeHex(string);
+ } catch (DecoderException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static String printHex(byte[] data) {
+ return Hex.encodeHexString(data);
+ }
+
+ public static byte[] parseBase64(String string) {
+ return Base64.decodeBase64(string);
+ }
+
+ public static String printBase64(byte[] data) {
+ return Base64.encodeBase64String(data);
+ }
+
+}
diff --git a/src/org/traccar/helper/Hashing.java b/src/org/traccar/helper/Hashing.java
index 3fcc124fa..e91310eda 100644
--- a/src/org/traccar/helper/Hashing.java
+++ b/src/org/traccar/helper/Hashing.java
@@ -17,7 +17,6 @@ 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;
@@ -75,13 +74,13 @@ public final class Hashing {
RANDOM.nextBytes(salt);
byte[] hash = function(password.toCharArray(), salt);
return new HashingResult(
- DatatypeConverter.printHexBinary(hash),
- DatatypeConverter.printHexBinary(salt));
+ DataConverter.printHex(hash),
+ DataConverter.printHex(salt));
}
public static boolean validatePassword(String password, String hashHex, String saltHex) {
- byte[] hash = DatatypeConverter.parseHexBinary(hashHex);
- byte[] salt = DatatypeConverter.parseHexBinary(saltHex);
+ byte[] hash = DataConverter.parseHex(hashHex);
+ byte[] salt = DataConverter.parseHex(saltHex);
return slowEquals(hash, function(password.toCharArray(), salt));
}
diff --git a/src/org/traccar/helper/ObdDecoder.java b/src/org/traccar/helper/ObdDecoder.java
index 4bc3bcdfb..1bdcce352 100644
--- a/src/org/traccar/helper/ObdDecoder.java
+++ b/src/org/traccar/helper/ObdDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,15 +29,6 @@ public final class ObdDecoder {
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:
@@ -86,21 +77,25 @@ public final class ObdDecoder {
public static Map.Entry<String, Object> decodeData(int pid, int value, boolean convert) {
switch (pid) {
- case PID_ENGINE_LOAD:
+ case 0x04:
return createEntry(Position.KEY_ENGINE_LOAD, convert ? value * 100 / 255 : value);
- case PID_COOLANT_TEMPERATURE:
+ case 0x05:
return createEntry(Position.KEY_COOLANT_TEMP, convert ? value - 40 : value);
- case PID_ENGINE_RPM:
+ case 0x0B:
+ return createEntry("mapIntake", value);
+ case 0x0C:
return createEntry(Position.KEY_RPM, convert ? value / 4 : value);
- case PID_VEHICLE_SPEED:
+ case 0x0D:
return createEntry(Position.KEY_OBD_SPEED, value);
- case PID_THROTTLE_POSITION:
+ case 0x0F:
+ return createEntry("intakeTemp", convert ? value - 40 : value);
+ case 0x11:
return createEntry(Position.KEY_THROTTLE, convert ? value * 100 / 255 : value);
- case PID_MIL_DISTANCE:
+ case 0x21:
return createEntry("milDistance", value);
- case PID_FUEL_LEVEL:
+ case 0x2F:
return createEntry(Position.KEY_FUEL_LEVEL, convert ? value * 100 / 255 : value);
- case PID_DISTANCE_CLEARED:
+ case 0x31:
return createEntry("clearedDistance", value);
default:
return null;
diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java
index 51b479b09..0c9be932d 100644
--- a/src/org/traccar/model/Device.java
+++ b/src/org/traccar/model/Device.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@ import java.util.List;
import org.traccar.database.QueryExtended;
import org.traccar.database.QueryIgnore;
-public class Device extends ExtendedModel {
+public class Device extends GroupedModel {
private String name;
@@ -88,16 +88,6 @@ public class Device extends ExtendedModel {
this.positionId = positionId;
}
- private long groupId;
-
- public long getGroupId() {
- return groupId;
- }
-
- public void setGroupId(long groupId) {
- this.groupId = groupId;
- }
-
private List<Long> geofenceIds;
@QueryIgnore
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 47b60af01..ee7fcc679 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -64,19 +64,11 @@ public class Event extends Message {
private Date serverTime;
public Date getServerTime() {
- if (serverTime != null) {
- return new Date(serverTime.getTime());
- } else {
- return null;
- }
+ return serverTime;
}
public void setServerTime(Date serverTime) {
- if (serverTime != null) {
- this.serverTime = new Date(serverTime.getTime());
- } else {
- this.serverTime = null;
- }
+ this.serverTime = serverTime;
}
private long positionId;
@@ -99,4 +91,14 @@ public class Event extends Message {
this.geofenceId = geofenceId;
}
+ private long maintenanceId = 0;
+
+ public long getMaintenanceId() {
+ return maintenanceId;
+ }
+
+ public void setMaintenanceId(long maintenanceId) {
+ this.maintenanceId = maintenanceId;
+ }
+
}
diff --git a/src/org/traccar/model/Geofence.java b/src/org/traccar/model/Geofence.java
index 21c196da9..8560d22e9 100644
--- a/src/org/traccar/model/Geofence.java
+++ b/src/org/traccar/model/Geofence.java
@@ -26,7 +26,7 @@ import org.traccar.geofence.GeofencePolyline;
import com.fasterxml.jackson.annotation.JsonIgnore;
-public class Geofence extends ExtendedModel {
+public class Geofence extends ScheduledModel {
public static final String TYPE_GEOFENCE_CILCLE = "geofenceCircle";
public static final String TYPE_GEOFENCE_POLYGON = "geofencePolygon";
@@ -65,7 +65,9 @@ public class Geofence extends ExtendedModel {
} else if (area.startsWith("POLYGON")) {
geometry = new GeofencePolygon(area);
} else if (area.startsWith("LINESTRING")) {
- geometry = new GeofencePolyline(area, Context.getConfig().getDouble("geofence.polylineDistance", 25));
+ final double distance = getDouble("polylineDistance");
+ geometry = new GeofencePolyline(area, distance > 0 ? distance
+ : Context.getConfig().getDouble("geofence.polylineDistance", 25));
} else {
throw new ParseException("Unknown geometry type", 0);
}
@@ -87,14 +89,4 @@ public class Geofence extends ExtendedModel {
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
index aad206aad..91ea2319d 100644
--- a/src/org/traccar/model/Group.java
+++ b/src/org/traccar/model/Group.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.model;
-public class Group extends ExtendedModel {
+public class Group extends GroupedModel {
private String name;
@@ -27,14 +27,4 @@ public class Group extends ExtendedModel {
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/GroupedModel.java b/src/org/traccar/model/GroupedModel.java
new file mode 100644
index 000000000..6b1aa75b1
--- /dev/null
+++ b/src/org/traccar/model/GroupedModel.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 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 GroupedModel extends ExtendedModel {
+
+ private long groupId;
+
+ public long getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(long groupId) {
+ this.groupId = groupId;
+ }
+
+}
diff --git a/src/org/traccar/model/Maintenance.java b/src/org/traccar/model/Maintenance.java
new file mode 100644
index 000000000..73f67ea96
--- /dev/null
+++ b/src/org/traccar/model/Maintenance.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 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 Maintenance extends ExtendedModel {
+
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ private String type;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ private double start;
+
+ public double getStart() {
+ return start;
+ }
+
+ public void setStart(double start) {
+ this.start = start;
+ }
+
+ private double period;
+
+ public double getPeriod() {
+ return period;
+ }
+
+ public void setPeriod(double period) {
+ this.period = period;
+ }
+
+}
diff --git a/src/org/traccar/model/Notification.java b/src/org/traccar/model/Notification.java
index 9d6034fff..cc80f2ae2 100644
--- a/src/org/traccar/model/Notification.java
+++ b/src/org/traccar/model/Notification.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
package org.traccar.model;
-public class Notification extends ExtendedModel {
+public class Notification extends ScheduledModel {
private boolean always;
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index 4f78867c2..fca0f16e3 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -58,6 +58,7 @@ public class Position extends Message {
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_ANTENNA = "antenna";
public static final String KEY_CHARGE = "charge";
public static final String KEY_IP = "ip";
public static final String KEY_ARCHIVE = "archive";
@@ -115,6 +116,7 @@ public class Position extends Message {
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_IDLE = "idle";
public static final String ALARM_ACCELERATION = "hardAcceleration";
public static final String ALARM_BRAKING = "hardBraking";
public static final String ALARM_CORNERING = "hardCornering";
@@ -131,6 +133,14 @@ public class Position extends Message {
public static final String ALARM_TAMPERING = "tampering";
public static final String ALARM_REMOVING = "removing";
+ public Position() {
+ }
+
+ public Position(String protocol) {
+ this.protocol = protocol;
+ this.serverTime = new Date();
+ }
+
private String protocol;
public String getProtocol() {
@@ -144,55 +154,31 @@ public class Position extends Message {
private Date serverTime;
public Date getServerTime() {
- if (serverTime != null) {
- return new Date(serverTime.getTime());
- } else {
- return null;
- }
+ return serverTime;
}
public void setServerTime(Date serverTime) {
- if (serverTime != null) {
- this.serverTime = new Date(serverTime.getTime());
- } else {
- this.serverTime = null;
- }
+ this.serverTime = serverTime;
}
private Date deviceTime;
public Date getDeviceTime() {
- if (deviceTime != null) {
- return new Date(deviceTime.getTime());
- } else {
- return null;
- }
+ return deviceTime;
}
public void setDeviceTime(Date deviceTime) {
- if (deviceTime != null) {
- this.deviceTime = new Date(deviceTime.getTime());
- } else {
- this.deviceTime = null;
- }
+ this.deviceTime = deviceTime;
}
private Date fixTime;
public Date getFixTime() {
- if (fixTime != null) {
- return new Date(fixTime.getTime());
- } else {
- return null;
- }
+ return fixTime;
}
public void setFixTime(Date fixTime) {
- if (fixTime != null) {
- this.fixTime = new Date(fixTime.getTime());
- } else {
- this.fixTime = null;
- }
+ this.fixTime = fixTime;
}
public void setTime(Date time) {
diff --git a/src/org/traccar/model/ScheduledModel.java b/src/org/traccar/model/ScheduledModel.java
new file mode 100644
index 000000000..9e6a4b9a6
--- /dev/null
+++ b/src/org/traccar/model/ScheduledModel.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 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 ScheduledModel extends ExtendedModel {
+
+ private long calendarId;
+
+ public long getCalendarId() {
+ return calendarId;
+ }
+
+ public void setCalendarId(long calendarId) {
+ this.calendarId = calendarId;
+ }
+}
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
index 072e85d55..c6161397b 100644
--- a/src/org/traccar/model/Server.java
+++ b/src/org/traccar/model/Server.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,4 +157,14 @@ public class Server extends ExtendedModel {
public void setLimitCommands(boolean limitCommands) {
this.limitCommands = limitCommands;
}
+
+ private String poiLayer;
+
+ public String getPoiLayer() {
+ return poiLayer;
+ }
+
+ public void setPoiLayer(String poiLayer) {
+ this.poiLayer = poiLayer;
+ }
}
diff --git a/src/org/traccar/model/Statistics.java b/src/org/traccar/model/Statistics.java
index 2acf8514f..cb72c91dd 100644
--- a/src/org/traccar/model/Statistics.java
+++ b/src/org/traccar/model/Statistics.java
@@ -22,19 +22,11 @@ public class Statistics extends ExtendedModel {
private Date captureTime;
public Date getCaptureTime() {
- if (captureTime != null) {
- return new Date(captureTime.getTime());
- } else {
- return null;
- }
+ return captureTime;
}
public void setCaptureTime(Date captureTime) {
- if (captureTime != null) {
- this.captureTime = new Date(captureTime.getTime());
- } else {
- this.captureTime = null;
- }
+ this.captureTime = captureTime;
}
private int activeUsers;
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index b1883213c..1a131a4e8 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -158,19 +158,11 @@ public class User extends ExtendedModel {
private Date expirationTime;
public Date getExpirationTime() {
- if (expirationTime != null) {
- return new Date(expirationTime.getTime());
- } else {
- return null;
- }
+ return expirationTime;
}
public void setExpirationTime(Date expirationTime) {
- if (expirationTime != null) {
- this.expirationTime = new Date(expirationTime.getTime());
- } else {
- this.expirationTime = null;
- }
+ this.expirationTime = expirationTime;
}
private int deviceLimit;
@@ -230,6 +222,16 @@ public class User extends ExtendedModel {
this.limitCommands = limitCommands;
}
+ private String poiLayer;
+
+ public String getPoiLayer() {
+ return poiLayer;
+ }
+
+ public void setPoiLayer(String poiLayer) {
+ this.poiLayer = poiLayer;
+ }
+
@QueryIgnore
public String getPassword() {
return null;
diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java
index 68c3ea221..9d2181e21 100644
--- a/src/org/traccar/notification/EventForwarder.java
+++ b/src/org/traccar/notification/EventForwarder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@ package org.traccar.notification;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.traccar.Context;
@@ -25,11 +25,14 @@ import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
+import org.traccar.model.Maintenance;
import org.traccar.model.Position;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
+
import com.ning.http.client.FluentCaseInsensitiveStringsMap;
public abstract class EventForwarder {
@@ -46,8 +49,10 @@ public abstract class EventForwarder {
private static final String KEY_EVENT = "event";
private static final String KEY_GEOFENCE = "geofence";
private static final String KEY_DEVICE = "device";
+ private static final String KEY_MAINTENANCE = "maintenance";
+ private static final String KEY_USERS = "users";
- public final void forwardEvent(Event event, Position position) {
+ public final void forwardEvent(Event event, Position position, Set<Long> users) {
BoundRequestBuilder requestBuilder = Context.getAsyncHttpClient().preparePost(url);
requestBuilder.setBodyEncoding(StandardCharsets.UTF_8.name());
@@ -60,7 +65,7 @@ public abstract class EventForwarder {
requestBuilder.setHeaders(params);
}
- setContent(event, position, requestBuilder);
+ setContent(event, position, users, requestBuilder);
requestBuilder.execute();
}
@@ -73,30 +78,35 @@ public abstract class EventForwarder {
for (String paramLine: paramsLines) {
splitedLine = paramLine.split(separator, 2);
if (splitedLine.length == 2) {
- paramsMap.put(splitedLine[0].trim(), Arrays.asList(splitedLine[1].trim()));
+ paramsMap.put(splitedLine[0].trim(), Collections.singletonList(splitedLine[1].trim()));
}
}
return paramsMap;
}
- protected String prepareJsonPayload(Event event, Position position) {
+ protected String prepareJsonPayload(Event event, Position position, Set<Long> users) {
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);
- }
+ 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());
+ Geofence geofence = Context.getGeofenceManager().getById(event.getGeofenceId());
if (geofence != null) {
data.put(KEY_GEOFENCE, geofence);
}
}
+ if (event.getMaintenanceId() != 0) {
+ Maintenance maintenance = Context.getMaintenancesManager().getById(event.getMaintenanceId());
+ if (maintenance != null) {
+ data.put(KEY_MAINTENANCE, maintenance);
+ }
+ }
+ data.put(KEY_USERS, Context.getUsersManager().getItems(users));
try {
return Context.getObjectMapper().writeValueAsString(data);
} catch (JsonProcessingException e) {
@@ -106,6 +116,7 @@ public abstract class EventForwarder {
}
protected abstract String getContentType();
- protected abstract void setContent(Event event, Position position, BoundRequestBuilder requestBuilder);
+ protected abstract void setContent(
+ Event event, Position position, Set<Long> users, BoundRequestBuilder requestBuilder);
}
diff --git a/src/org/traccar/notification/JsonTypeEventForwarder.java b/src/org/traccar/notification/JsonTypeEventForwarder.java
index c1e4220d0..27ef61af1 100644
--- a/src/org/traccar/notification/JsonTypeEventForwarder.java
+++ b/src/org/traccar/notification/JsonTypeEventForwarder.java
@@ -1,5 +1,7 @@
package org.traccar.notification;
+import java.util.Set;
+
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -13,8 +15,8 @@ public class JsonTypeEventForwarder extends EventForwarder {
}
@Override
- protected void setContent(Event event, Position position, BoundRequestBuilder requestBuilder) {
- requestBuilder.setBody(prepareJsonPayload(event, position));
+ protected void setContent(Event event, Position position, Set<Long> users, BoundRequestBuilder requestBuilder) {
+ requestBuilder.setBody(prepareJsonPayload(event, position, users));
}
}
diff --git a/src/org/traccar/notification/MultiPartEventForwarder.java b/src/org/traccar/notification/MultiPartEventForwarder.java
index f4c36d3e4..6227c66cc 100644
--- a/src/org/traccar/notification/MultiPartEventForwarder.java
+++ b/src/org/traccar/notification/MultiPartEventForwarder.java
@@ -3,6 +3,7 @@ package org.traccar.notification;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.Map.Entry;
import org.traccar.Context;
@@ -28,7 +29,7 @@ public class MultiPartEventForwarder extends EventForwarder {
}
@Override
- protected void setContent(Event event, Position position, BoundRequestBuilder requestBuilder) {
+ protected void setContent(Event event, Position position, Set<Long> users, BoundRequestBuilder requestBuilder) {
if (additionalParams != null && !additionalParams.isEmpty()) {
Map<String, List<String>> paramsToAdd = splitIntoKeyValues(additionalParams, "=");
@@ -41,6 +42,6 @@ public class MultiPartEventForwarder extends EventForwarder {
}
}
requestBuilder.addBodyPart(new StringPart(payloadParamName,
- prepareJsonPayload(event, position), "application/json", StandardCharsets.UTF_8));
+ prepareJsonPayload(event, position, users), "application/json", StandardCharsets.UTF_8));
}
}
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index 114825a83..524153721 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 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.
@@ -57,6 +57,9 @@ public final class NotificationFormatter {
if (event.getGeofenceId() != 0) {
velocityContext.put("geofence", Context.getGeofenceManager().getById(event.getGeofenceId()));
}
+ if (event.getMaintenanceId() != 0) {
+ velocityContext.put("maintenance", Context.getMaintenancesManager().getById(event.getMaintenanceId()));
+ }
String driverUniqueId = event.getString(Position.KEY_DRIVER_UNIQUE_ID);
if (driverUniqueId != null) {
velocityContext.put("driver", Context.getDriversManager().getDriverByUniqueId(driverUniqueId));
diff --git a/src/org/traccar/processing/ComputedAttributesHandler.java b/src/org/traccar/processing/ComputedAttributesHandler.java
index 1e702d17f..b37db05bf 100644
--- a/src/org/traccar/processing/ComputedAttributesHandler.java
+++ b/src/org/traccar/processing/ComputedAttributesHandler.java
@@ -102,10 +102,12 @@ public class ComputedAttributesHandler extends BaseDataHandler {
try {
switch (attribute.getType()) {
case "number":
- position.getAttributes().put(attribute.getAttribute(), (Number) result);
+ Number numberValue = (Number) result;
+ position.getAttributes().put(attribute.getAttribute(), numberValue);
break;
case "boolean":
- position.getAttributes().put(attribute.getAttribute(), (Boolean) result);
+ Boolean booleanValue = (Boolean) result;
+ position.getAttributes().put(attribute.getAttribute(), booleanValue);
break;
default:
position.getAttributes().put(attribute.getAttribute(), result.toString());
diff --git a/src/org/traccar/protocol/AdmProtocolDecoder.java b/src/org/traccar/protocol/AdmProtocolDecoder.java
index f93c55e18..4ae16017a 100644
--- a/src/org/traccar/protocol/AdmProtocolDecoder.java
+++ b/src/org/traccar/protocol/AdmProtocolDecoder.java
@@ -46,8 +46,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder {
}
if (BitUtil.to(type, 2) == 0) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
@@ -124,8 +123,7 @@ public class AdmProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
diff --git a/src/org/traccar/protocol/AisProtocolDecoder.java b/src/org/traccar/protocol/AisProtocolDecoder.java
index 1f7a12595..842260e98 100644
--- a/src/org/traccar/protocol/AisProtocolDecoder.java
+++ b/src/org/traccar/protocol/AisProtocolDecoder.java
@@ -61,8 +61,7 @@ public class AisProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date());
diff --git a/src/org/traccar/protocol/AlematicsProtocolDecoder.java b/src/org/traccar/protocol/AlematicsProtocolDecoder.java
index da0704242..b83081cc1 100644
--- a/src/org/traccar/protocol/AlematicsProtocolDecoder.java
+++ b/src/org/traccar/protocol/AlematicsProtocolDecoder.java
@@ -113,8 +113,7 @@ public class AlematicsProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_TYPE, parser.nextInt());
position.set(Position.KEY_INDEX, parser.nextInt());
diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java
index 6e16e02be..a107f7d6f 100644
--- a/src/org/traccar/protocol/ApelProtocolDecoder.java
+++ b/src/org/traccar/protocol/ApelProtocolDecoder.java
@@ -136,8 +136,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder {
}
for (int j = 0; j < recordCount; j++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int subtype = type;
diff --git a/src/org/traccar/protocol/AplicomProtocolDecoder.java b/src/org/traccar/protocol/AplicomProtocolDecoder.java
index c1d7ab087..7ed187937 100644
--- a/src/org/traccar/protocol/AplicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/AplicomProtocolDecoder.java
@@ -608,8 +608,7 @@ public class AplicomProtocolDecoder extends BaseProtocolDecoder {
selector = buf.readUnsignedMedium();
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
diff --git a/src/org/traccar/protocol/AppelloProtocolDecoder.java b/src/org/traccar/protocol/AppelloProtocolDecoder.java
index 30dec3941..bf95b4068 100644
--- a/src/org/traccar/protocol/AppelloProtocolDecoder.java
+++ b/src/org/traccar/protocol/AppelloProtocolDecoder.java
@@ -65,8 +65,7 @@ public class AppelloProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext(6)) {
diff --git a/src/org/traccar/protocol/AquilaProtocolDecoder.java b/src/org/traccar/protocol/AquilaProtocolDecoder.java
index 773210b04..960139b3f 100644
--- a/src/org/traccar/protocol/AquilaProtocolDecoder.java
+++ b/src/org/traccar/protocol/AquilaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ 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;
@@ -32,7 +34,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN = new PatternBuilder()
+ private static final Pattern PATTERN_A = new PatternBuilder()
.text("$$")
.expression("[^,]*,") // client
.number("(d+),") // device serial number
@@ -42,6 +44,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
.number("(dd)(dd)(dd)") // date (yymmdd)
.number("(dd)(dd)(dd),") // time (hhmmss)
.expression("([AV]),") // validity
+ .groupBegin()
.number("(d+),") // gsm
.number("(d+),") // speed
.number("(d+),") // distance
@@ -120,15 +123,17 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // external voltage
.number("(d+),") // internal voltage
.groupEnd()
+ .or()
+ .number("(d+),") // sensor id
+ .expression("([^,]+),") // sensor data
+ .groupEnd()
.text("*")
.number("xx") // checksum
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private Position decodeA(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN_A, sentence);
if (!parser.matches()) {
return null;
}
@@ -138,8 +143,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, parser.nextInt(0));
@@ -151,11 +155,11 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
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(3)) {
+ 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)) {
@@ -187,7 +191,7 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
String dtcs = parser.next();
position.set(Position.KEY_DTCS, dtcs.substring(1, dtcs.length() - 1).replace('|', ' '));
- } else {
+ } else if (parser.hasNext(10)) {
position.setCourse(parser.nextInt(0));
@@ -201,9 +205,129 @@ public class AquilaProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_POWER, parser.nextInt(0));
position.set(Position.KEY_BATTERY, parser.nextInt(0));
+ } else if (parser.hasNext(2)) {
+
+ position.set("sensorId", parser.nextInt());
+ position.set("sensorData", parser.next());
+
+ }
+
+ return position;
+ }
+
+ private static final Pattern PATTERN_B = new PatternBuilder()
+ .text("$Header,")
+ .expression("[^,]+,") // client
+ .expression("[^,]+,") // firmware version
+ .expression(".{2},") // type
+ .number("d+,") // message id
+ .expression("[LH],") // status
+ .number("(d+),") // imei
+ .expression("[^,]+,") // registration number
+ .number("([01]),") // validity
+ .number("(dd)(dd)(dddd),") // date (ddmmyyyy)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(-?d+.d+),") // latitude
+ .expression("([NS]),")
+ .number("(-?d+.d+),") // longitude
+ .expression("([EW]),")
+ .number("(d+.d+),") // speed
+ .number("(d+),") // course
+ .number("(d+),") // satellites
+ .number("(-?d+.d+),") // altitude
+ .number("(d+.d+),") // pdop
+ .number("(d+.d+),") // hdop
+ .expression("[^,]+,") // operator
+ .number("([01]),") // ignition
+ .number("([01]),") // charge
+ .number("(d+.d+),") // power
+ .number("(d+.d+),") // battery
+ .number("[01],") // emergency
+ .expression("[CO],") // tamper
+ .number("(d+),") // rssi
+ .number("(d+),") // mcc
+ .number("(d+),") // mnc
+ .number("(x+),") // lac
+ .number("(x+),") // cid
+ .number("(d+),(x+),(x+),") // cell 1
+ .number("(d+),(x+),(x+),") // cell 2
+ .number("(d+),(x+),(x+),") // cell 3
+ .number("(d+),(x+),(x+),") // cell 4
+ .number("([01])+,") // inputs
+ .number("([01])+,") // outputs
+ .number("d+,") // frame number
+ .number("(d+.d+),") // adc1
+ .number("(d+.d+),") // adc2
+ .number("d+,") // delta distance
+ .any()
+ .compile();
+
+ private Position decodeB(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_B, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setValid(parser.nextInt() == 1);
+ position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
+ position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
+ position.setCourse(parser.nextInt());
+
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+
+ position.setAltitude(parser.nextDouble());
+
+ position.set(Position.KEY_PDOP, parser.nextDouble());
+ position.set(Position.KEY_HDOP, parser.nextDouble());
+ position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
+ position.set(Position.KEY_CHARGE, parser.nextInt() == 1);
+ position.set(Position.KEY_POWER, parser.nextDouble());
+ position.set(Position.KEY_BATTERY, parser.nextDouble());
+
+ Network network = new Network();
+
+ int rssi = parser.nextInt();
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
+
+ network.addCellTower(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt(), rssi));
+ for (int i = 0; i < 4; i++) {
+ rssi = parser.nextInt();
+ network.addCellTower(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt(), rssi));
}
+ position.setNetwork(network);
+
+ position.set(Position.KEY_INPUT, parser.nextBinInt());
+ position.set(Position.KEY_OUTPUT, parser.nextBinInt());
+ position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
+ position.set(Position.PREFIX_ADC + 2, parser.nextDouble());
+
return position;
}
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ if (sentence.startsWith("$$")) {
+ return decodeA(channel, remoteAddress, sentence);
+ } else {
+ return decodeB(channel, remoteAddress, sentence);
+ }
+ }
+
}
diff --git a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
index 7a5bd217c..dea9e3483 100644
--- a/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ardi01ProtocolDecoder.java
@@ -56,8 +56,7 @@ public class Ardi01ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/ArknavProtocolDecoder.java b/src/org/traccar/protocol/ArknavProtocolDecoder.java
index 927c50c29..aeea4a734 100644
--- a/src/org/traccar/protocol/ArknavProtocolDecoder.java
+++ b/src/org/traccar/protocol/ArknavProtocolDecoder.java
@@ -58,8 +58,7 @@ public class ArknavProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
index 8a80901b5..47cc267fe 100644
--- a/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
+++ b/src/org/traccar/protocol/ArknavX8ProtocolDecoder.java
@@ -65,8 +65,7 @@ public class ArknavX8ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_TYPE, parser.next());
diff --git a/src/org/traccar/protocol/ArnaviProtocolDecoder.java b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
index 9c4ab5d05..ec96343fe 100644
--- a/src/org/traccar/protocol/ArnaviProtocolDecoder.java
+++ b/src/org/traccar/protocol/ArnaviProtocolDecoder.java
@@ -65,8 +65,7 @@ public class ArnaviProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/AstraProtocolDecoder.java b/src/org/traccar/protocol/AstraProtocolDecoder.java
index 8d86cd2be..79c7eba3f 100644
--- a/src/org/traccar/protocol/AstraProtocolDecoder.java
+++ b/src/org/traccar/protocol/AstraProtocolDecoder.java
@@ -63,8 +63,7 @@ public class AstraProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 2) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // index
diff --git a/src/org/traccar/protocol/At2000ProtocolDecoder.java b/src/org/traccar/protocol/At2000ProtocolDecoder.java
index 70840c37d..e0f2b4278 100644
--- a/src/org/traccar/protocol/At2000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/At2000ProtocolDecoder.java
@@ -20,13 +20,13 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.DataConverter;
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;
@@ -84,7 +84,7 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder {
IvParameterSpec ivSpec = new IvParameterSpec(iv);
SecretKeySpec keySpec = new SecretKeySpec(
- DatatypeConverter.parseHexBinary("000102030405060708090a0b0c0d0e0f"), "AES");
+ DataConverter.parseHex("000102030405060708090a0b0c0d0e0f"), "AES");
cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
@@ -114,8 +114,7 @@ public class At2000ProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() >= 63) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedShort(); // index
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 23cb67e15..8138f0fcb 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class AtrackProtocolDecoder extends BaseProtocolDecoder {
@@ -43,6 +44,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
private static final int MIN_DATA_LENGTH = 40;
private boolean longDate;
+ private boolean decimalFuel;
private boolean custom;
private String form;
@@ -52,6 +54,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
longDate = Context.getConfig().getBoolean(getProtocolName() + ".longDate");
+ decimalFuel = Context.getConfig().getBoolean(getProtocolName() + ".decimalFuel");
custom = Context.getConfig().getBoolean(getProtocolName() + ".custom");
form = Context.getConfig().getString(getProtocolName() + ".form");
@@ -217,8 +220,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
.compile();
private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
getLastLocation(position, null);
@@ -288,8 +290,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() >= MIN_DATA_LENGTH) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (longDate) {
@@ -332,7 +333,17 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
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));
+ String message = readString(buf);
+ if (message != null && !message.isEmpty()) {
+ Pattern pattern = Pattern.compile("FULS:F=(\\p{XDigit}+) t=(\\p{XDigit}+) N=(\\p{XDigit}+)");
+ Matcher matcher = pattern.matcher(message);
+ if (matcher.find()) {
+ int value = Integer.parseInt(matcher.group(3), decimalFuel ? 10 : 16);
+ position.set(Position.KEY_FUEL_LEVEL, value * 0.1);
+ } else {
+ position.set("message", message);
+ }
+ }
if (custom) {
String form = this.form;
diff --git a/src/org/traccar/protocol/AuroProtocolDecoder.java b/src/org/traccar/protocol/AuroProtocolDecoder.java
index a45d14709..3cb3a440c 100644
--- a/src/org/traccar/protocol/AuroProtocolDecoder.java
+++ b/src/org/traccar/protocol/AuroProtocolDecoder.java
@@ -62,8 +62,7 @@ public class AuroProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, parser.nextInt(0));
diff --git a/src/org/traccar/protocol/AutoFonProtocolDecoder.java b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
index 32b4bfa74..e243b93ea 100644
--- a/src/org/traccar/protocol/AutoFonProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoFonProtocolDecoder.java
@@ -62,8 +62,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (!history) {
@@ -167,8 +166,7 @@ public class AutoFonProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_45_LOCATION) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
short status = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
index 753509f31..b98c68cbd 100644
--- a/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
+++ b/src/org/traccar/protocol/AutoGradeProtocolDecoder.java
@@ -72,8 +72,7 @@ public class AutoGradeProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/Avl301ProtocolDecoder.java b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
index cc61be91b..056395d35 100644
--- a/src/org/traccar/protocol/Avl301ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Avl301ProtocolDecoder.java
@@ -88,9 +88,8 @@ public class Avl301ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
DateBuilder dateBuilder = new DateBuilder()
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
diff --git a/src/org/traccar/protocol/BceProtocolDecoder.java b/src/org/traccar/protocol/BceProtocolDecoder.java
index b472ac6c9..a023e60c5 100644
--- a/src/org/traccar/protocol/BceProtocolDecoder.java
+++ b/src/org/traccar/protocol/BceProtocolDecoder.java
@@ -21,6 +21,7 @@ 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;
@@ -67,8 +68,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
while (buf.readerIndex() < dataEnd) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int structEnd = buf.readUnsignedByte() + buf.readerIndex();
@@ -94,7 +94,7 @@ public class BceProtocolDecoder extends BaseProtocolDecoder {
position.setValid(true);
position.setLongitude(buf.readFloat());
position.setLatitude(buf.readFloat());
- position.setSpeed(buf.readUnsignedByte());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
int gps = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, gps & 0xf);
diff --git a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
index 561d7c18b..7fc39fc7c 100644
--- a/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
+++ b/src/org/traccar/protocol/BlackKiteProtocolDecoder.java
@@ -76,8 +76,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<>();
Set<Integer> tags = new HashSet<>();
boolean hasLocation = false;
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
while (buf.readerIndex() < length) {
@@ -89,7 +88,7 @@ public class BlackKiteProtocolDecoder extends BaseProtocolDecoder {
}
tags.clear();
hasLocation = false;
- position = new Position();
+ position = new Position(getProtocolName());
}
tags.add(tag);
diff --git a/src/org/traccar/protocol/BoxProtocolDecoder.java b/src/org/traccar/protocol/BoxProtocolDecoder.java
index 562731657..63238bcef 100644
--- a/src/org/traccar/protocol/BoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/BoxProtocolDecoder.java
@@ -77,9 +77,8 @@ public class BoxProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.setTime(parser.nextDateTime());
diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
index 557e2d6e6..f717d3c5d 100644
--- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java
+++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java
@@ -66,9 +66,8 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder {
private Position decodePosition(DeviceSession deviceSession, int type, ChannelBuffer buf) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
if (type != MSG_MINI_EVENT_REPORT) {
diff --git a/src/org/traccar/protocol/CarTrackProtocolDecoder.java b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
index 3064bbb35..94215379d 100644
--- a/src/org/traccar/protocol/CarTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarTrackProtocolDecoder.java
@@ -65,8 +65,7 @@ public class CarTrackProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/CarcellProtocolDecoder.java b/src/org/traccar/protocol/CarcellProtocolDecoder.java
index fc5710f09..52b777b81 100644
--- a/src/org/traccar/protocol/CarcellProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarcellProtocolDecoder.java
@@ -85,8 +85,7 @@ public class CarcellProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_ARCHIVE, parser.next().equals("%"));
position.setValid(true);
diff --git a/src/org/traccar/protocol/CarscopProtocolDecoder.java b/src/org/traccar/protocol/CarscopProtocolDecoder.java
index 2a081bcdd..7f9dcc3b7 100644
--- a/src/org/traccar/protocol/CarscopProtocolDecoder.java
+++ b/src/org/traccar/protocol/CarscopProtocolDecoder.java
@@ -73,9 +73,8 @@ public class CarscopProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
diff --git a/src/org/traccar/protocol/CastelProtocol.java b/src/org/traccar/protocol/CastelProtocol.java
index db9df0674..d5ba5cd55 100644
--- a/src/org/traccar/protocol/CastelProtocol.java
+++ b/src/org/traccar/protocol/CastelProtocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
+import org.traccar.model.Command;
import java.nio.ByteOrder;
import java.util.List;
@@ -29,6 +30,9 @@ public class CastelProtocol extends BaseProtocol {
public CastelProtocol() {
super("castel");
+ setSupportedDataCommands(
+ Command.TYPE_ENGINE_STOP,
+ Command.TYPE_ENGINE_RESUME);
}
@Override
@@ -37,6 +41,7 @@ public class CastelProtocol extends BaseProtocol {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 0));
+ pipeline.addLast("objectEncoder", new CastelProtocolEncoder());
pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
}
};
@@ -46,6 +51,7 @@ public class CastelProtocol extends BaseProtocol {
server = new TrackerServer(new ConnectionlessBootstrap(), getName()) {
@Override
protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("objectEncoder", new CastelProtocolEncoder());
pipeline.addLast("objectDecoder", new CastelProtocolDecoder(CastelProtocol.this));
}
};
diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java
index 5eedc69f9..44a5e213c 100644
--- a/src/org/traccar/protocol/CastelProtocolDecoder.java
+++ b/src/org/traccar/protocol/CastelProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -96,12 +96,12 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
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_PETROL_CONTROL = 0x4583;
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 position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -131,8 +131,7 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
private Position createPosition(DeviceSession deviceSession) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
@@ -401,7 +400,6 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return null;
}
-
private Object decodeCc(
Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
@@ -459,6 +457,47 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ private Object decodeMpip(
+ Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
+ int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
+
+ if (type == 0x4001) {
+
+ sendResponse(channel, remoteAddress, version, id, (short) type, null);
+
+ return readPosition(deviceSession, buf);
+
+ } else if (type == 0x2001) {
+
+ sendResponse(channel, remoteAddress, id, (short) 0x1001);
+
+ buf.readUnsignedInt(); // index
+ buf.readUnsignedInt(); // unix time
+ buf.readUnsignedByte();
+
+ return readPosition(deviceSession, buf);
+
+ } else if (type == 0x4201 || type == 0x4202 || type == 0x4206) {
+
+ return readPosition(deviceSession, buf);
+
+ } else if (type == 0x4204) {
+
+ List<Position> positions = new LinkedList<>();
+
+ for (int i = 0; i < 8; i++) {
+ Position position = readPosition(deviceSession, buf);
+ buf.skipBytes(31);
+ positions.add(position);
+ }
+
+ return positions;
+
+ }
+
+ return null;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -482,31 +521,15 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder {
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);
-
+ switch (version) {
+ case -1:
+ return decodeMpip(channel, remoteAddress, buf, version, id, type, deviceSession);
+ case 3:
+ case 4:
+ return decodeSc(channel, remoteAddress, buf, version, id, type, deviceSession);
+ default:
+ return decodeCc(channel, remoteAddress, buf, version, id, type, deviceSession);
}
-
- return null;
}
}
diff --git a/src/org/traccar/protocol/CastelProtocolEncoder.java b/src/org/traccar/protocol/CastelProtocolEncoder.java
new file mode 100644
index 000000000..806dac19e
--- /dev/null
+++ b/src/org/traccar/protocol/CastelProtocolEncoder.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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.ByteOrder;
+import java.nio.charset.StandardCharsets;
+
+public class CastelProtocolEncoder extends BaseProtocolEncoder {
+
+ private ChannelBuffer encodeContent(long deviceId, short type, ChannelBuffer content) {
+ ChannelBuffer buf = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ String uniqueId = Context.getIdentityManager().getById(deviceId).getUniqueId();
+
+ buf.writeByte('@');
+ buf.writeByte('@');
+
+ buf.writeShort(2 + 2 + 1 + 20 + 2 + content.readableBytes() + 2 + 2); // length
+
+ buf.writeByte(1); // protocol version
+
+ buf.writeBytes(uniqueId.getBytes(StandardCharsets.US_ASCII));
+ buf.writeZero(20 - uniqueId.length());
+
+ buf.writeShort(ChannelBuffers.swapShort(type));
+ buf.writeBytes(content);
+
+ buf.writeShort(Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
+
+ buf.writeByte('\r');
+ buf.writeByte('\n');
+
+ return buf;
+ }
+
+ @Override
+ protected Object encodeCommand(Command command) {
+ ChannelBuffer content = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP:
+ content.writeByte(1);
+ return encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content);
+ case Command.TYPE_ENGINE_RESUME:
+ content.writeByte(0);
+ return encodeContent(command.getDeviceId(), CastelProtocolDecoder.MSG_CC_PETROL_CONTROL, content);
+ default:
+ Log.warning(new UnsupportedOperationException(command.getType()));
+ break;
+ }
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/CautelaProtocol.java b/src/org/traccar/protocol/CautelaProtocol.java
new file mode 100644
index 000000000..89ab7a1d0
--- /dev/null
+++ b/src/org/traccar/protocol/CautelaProtocol.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 CautelaProtocol extends BaseProtocol {
+
+ public CautelaProtocol() {
+ super("cautela");
+ }
+
+ @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 CautelaProtocolDecoder(CautelaProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/CautelaProtocolDecoder.java b/src/org/traccar/protocol/CautelaProtocolDecoder.java
new file mode 100644
index 000000000..d7bf4fb51
--- /dev/null
+++ b/src/org/traccar/protocol/CautelaProtocolDecoder.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 CautelaProtocolDecoder extends BaseProtocolDecoder {
+
+ public CautelaProtocolDecoder(CautelaProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .number("(d+),") // type
+ .number("(d+),") // imei
+ .number("(dd),(dd),(dd),") // date (ddmmyy)
+ .number("(-?d+.d+),") // latitude
+ .number("(-?d+.d+),") // longitude
+ .number("(dd)(dd),") // time (hhmm)
+ .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(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ DateBuilder dateBuilder = new DateBuilder();
+ dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
+
+ position.setValid(true);
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+
+ dateBuilder.setHour(parser.nextInt()).setMinute(parser.nextInt());
+ position.setTime(dateBuilder.getDate());
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/CellocatorProtocolDecoder.java b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
index 7ef013e28..67db9aa7d 100644
--- a/src/org/traccar/protocol/CellocatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/CellocatorProtocolDecoder.java
@@ -100,8 +100,7 @@ public class CellocatorProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_CLIENT_STATUS) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(deviceUniqueId));
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/CguardProtocolDecoder.java b/src/org/traccar/protocol/CguardProtocolDecoder.java
index 54f83fb73..2e20537c8 100644
--- a/src/org/traccar/protocol/CguardProtocolDecoder.java
+++ b/src/org/traccar/protocol/CguardProtocolDecoder.java
@@ -58,8 +58,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime());
@@ -84,8 +83,7 @@ public class CguardProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime());
diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
index 9a614730f..7a1d8119d 100644
--- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java
+++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java
@@ -91,8 +91,7 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext(15)) {
diff --git a/src/org/traccar/protocol/ContinentalProtocol.java b/src/org/traccar/protocol/ContinentalProtocol.java
new file mode 100644
index 000000000..e2b1226cf
--- /dev/null
+++ b/src/org/traccar/protocol/ContinentalProtocol.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 ContinentalProtocol extends BaseProtocol {
+
+ public ContinentalProtocol() {
+ super("continental");
+ }
+
+ @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));
+ pipeline.addLast("objectDecoder", new ContinentalProtocolDecoder(ContinentalProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/ContinentalProtocolDecoder.java b/src/org/traccar/protocol/ContinentalProtocolDecoder.java
new file mode 100644
index 000000000..726d9e16b
--- /dev/null
+++ b/src/org/traccar/protocol/ContinentalProtocolDecoder.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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.util.Date;
+
+public class ContinentalProtocolDecoder extends BaseProtocolDecoder {
+
+ public ContinentalProtocolDecoder(ContinentalProtocol protocol) {
+ super(protocol);
+ }
+
+ public static final int MSG_KEEPALIVE = 0x00;
+ public static final int MSG_STATUS = 0x02;
+ public static final int MSG_ACK = 0x06;
+ public static final int MSG_NACK = 0x15;
+
+ private void sendResponse(Channel channel, long serialNumber) {
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer();
+
+ response.writeByte('S');
+ response.writeByte('V');
+ response.writeShort(2 + 2 + 1 + 4 + 2); // length
+ response.writeByte(1); // version
+ response.writeInt((int) serialNumber);
+ response.writeByte(0); // product
+ response.writeByte(MSG_ACK);
+
+ channel.write(response);
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.skipBytes(2); // header
+ buf.readUnsignedShort(); // length
+ buf.readUnsignedByte(); // software version
+
+ long serialNumber = buf.readUnsignedInt();
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(serialNumber));
+ if (deviceSession == null) {
+ return null;
+ }
+
+ sendResponse(channel, serialNumber);
+
+ buf.readUnsignedByte(); // product
+
+ int type = buf.readUnsignedByte();
+
+ if (type == MSG_STATUS) {
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setFixTime(new Date(buf.readUnsignedInt() * 1000L));
+
+ buf.readUnsignedByte();
+ position.setLatitude(buf.readMedium() / 3600.0);
+
+ buf.readUnsignedByte();
+ position.setLongitude(buf.readMedium() / 3600.0);
+
+ position.setCourse(buf.readUnsignedShort());
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
+
+ position.setValid(buf.readUnsignedByte() > 0);
+
+ position.setDeviceTime(new Date(buf.readUnsignedInt() * 1000L));
+
+ position.set(Position.KEY_EVENT, buf.readUnsignedShort());
+ position.set(Position.KEY_INPUT, buf.readUnsignedShort());
+ position.set(Position.KEY_OUTPUT, buf.readUnsignedShort());
+ position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
+ position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
+
+ buf.readUnsignedShort(); // reserved
+
+ return position;
+
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/CradlepointProtocolDecoder.java b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
index e8f95a60c..f74830756 100644
--- a/src/org/traccar/protocol/CradlepointProtocolDecoder.java
+++ b/src/org/traccar/protocol/CradlepointProtocolDecoder.java
@@ -65,8 +65,7 @@ public class CradlepointProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int time = parser.nextInt();
diff --git a/src/org/traccar/protocol/DishaProtocolDecoder.java b/src/org/traccar/protocol/DishaProtocolDecoder.java
index ab0a63215..a4e567b34 100644
--- a/src/org/traccar/protocol/DishaProtocolDecoder.java
+++ b/src/org/traccar/protocol/DishaProtocolDecoder.java
@@ -65,8 +65,7 @@ public class DishaProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/DmtHttpProtocolDecoder.java b/src/org/traccar/protocol/DmtHttpProtocolDecoder.java
index dbcc7a6f8..200a20759 100644
--- a/src/org/traccar/protocol/DmtHttpProtocolDecoder.java
+++ b/src/org/traccar/protocol/DmtHttpProtocolDecoder.java
@@ -64,8 +64,7 @@ public class DmtHttpProtocolDecoder extends BaseHttpProtocolDecoder {
JsonArray records = root.getJsonArray("Records");
for (int i = 0; i < records.size(); i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
JsonObject record = records.getJsonObject(i);
diff --git a/src/org/traccar/protocol/DmtProtocolDecoder.java b/src/org/traccar/protocol/DmtProtocolDecoder.java
index 39462a469..30a6ae13a 100644
--- a/src/org/traccar/protocol/DmtProtocolDecoder.java
+++ b/src/org/traccar/protocol/DmtProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ 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;
@@ -42,144 +43,241 @@ public class DmtProtocolDecoder extends BaseProtocolDecoder {
public static final int MSG_DATA_RECORD = 0x04;
public static final int MSG_COMMIT = 0x05;
public static final int MSG_COMMIT_RESPONSE = 0x06;
+ public static final int MSG_DATA_RECORD_64 = 0x10;
+
+ public static final int MSG_CANNED_REQUEST_1 = 0x14;
+ public static final int MSG_CANNED_RESPONSE_1 = 0x15;
+ public static final int MSG_CANNED_REQUEST_2 = 0x22;
+ public static final int MSG_CANNED_RESPONSE_2 = 0x23;
+
+ private void sendResponse(Channel channel, int type, ChannelBuffer content) {
+ if (channel != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeByte(0x02); response.writeByte(0x55); // header
+ response.writeByte(type);
+ response.writeShort(content != null ? content.readableBytes() : 0);
+ if (content != null) {
+ response.writeBytes(content);
+ }
+ channel.write(response);
+ }
+ }
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private List<Position> decodeFixed64(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- ChannelBuffer buf = (ChannelBuffer) msg;
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
- buf.skipBytes(2); // header
+ List<Position> positions = new LinkedList<>();
- int type = buf.readUnsignedByte();
+ while (buf.readableBytes() >= 64) {
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
- buf.readUnsignedShort(); // length
+ buf.readByte(); // type
- if (type == MSG_HELLO) {
+ position.set(Position.KEY_INDEX, buf.readUnsignedInt());
- buf.readUnsignedInt(); // device serial number
+ long time = buf.readUnsignedInt();
+ position.setTime(new DateBuilder()
+ .setYear((int) (2000 + (time & 0x3F)))
+ .setMonth((int) (time >> 6) & 0xF)
+ .setDay((int) (time >> 10) & 0x1F)
+ .setHour((int) (time >> 15) & 0x1F)
+ .setMinute((int) (time >> 20) & 0x3F)
+ .setSecond((int) (time >> 26) & 0x3F)
+ .getDate());
- DeviceSession deviceSession = getDeviceSession(
- channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII));
+ position.setLongitude(buf.readInt() * 0.0000001);
+ position.setLatitude(buf.readInt() * 0.0000001);
+ position.setSpeed(UnitsConverter.knotsFromCps(buf.readUnsignedShort()));
+ position.setCourse(buf.readUnsignedByte() * 2);
+ position.setAltitude(buf.readShort());
- 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);
- }
+ buf.readUnsignedShort(); // position accuracy
+ buf.readUnsignedByte(); // speed accuracy
- } else if (type == MSG_COMMIT) {
+ position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- 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);
- }
+ position.setValid(BitUtil.check(buf.readByte(), 0));
- } else if (type == MSG_DATA_RECORD) {
+ position.set(Position.KEY_INPUT, buf.readUnsignedInt());
+ position.set(Position.KEY_OUTPUT, buf.readUnsignedShort());
- DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- if (deviceSession == null) {
- return null;
+ for (int i = 1; i <= 5; i++) {
+ position.set(Position.PREFIX_ADC + i, buf.readShort());
}
- List<Position> positions = new LinkedList<>();
+ position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
- while (buf.readable()) {
+ buf.readShort(); // accelerometer x
+ buf.readShort(); // accelerometer y
+ buf.readShort(); // accelerometer z
- int recordEnd = buf.readerIndex() + buf.readUnsignedShort();
+ buf.skipBytes(8); // device id
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
+ position.set(Position.KEY_PDOP, buf.readUnsignedShort() * 0.01);
- position.set(Position.KEY_INDEX, buf.readUnsignedInt());
+ buf.skipBytes(2); // reserved
- position.setDeviceTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000)); // since 1 Jan 2013
+ buf.readUnsignedShort(); // checksum
- position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+ positions.add(position);
+ }
- while (buf.readerIndex() < recordEnd) {
+ return positions;
+ }
- int fieldId = buf.readUnsignedByte();
- int fieldLength = buf.readUnsignedByte();
- int fieldEnd = buf.readerIndex() + (fieldLength == 255 ? buf.readUnsignedShort() : fieldLength);
+ private List<Position> decodeStandard(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- if (fieldId == 0) {
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
- 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()));
+ List<Position> positions = new LinkedList<>();
- buf.readUnsignedByte(); // speed accuracy
+ while (buf.readable()) {
+ int recordEnd = buf.readerIndex() + buf.readUnsignedShort();
- position.setCourse(buf.readUnsignedByte() * 2);
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_PDOP, buf.readUnsignedByte() * 0.1);
+ position.set(Position.KEY_INDEX, buf.readUnsignedInt());
- position.setAccuracy(buf.readUnsignedByte());
- position.setValid(buf.readUnsignedByte() != 0);
+ position.setDeviceTime(new Date(1356998400000L + buf.readUnsignedInt() * 1000)); // since 1 Jan 2013
- } else if (fieldId == 2) {
+ position.set(Position.KEY_EVENT, buf.readUnsignedByte());
- int input = buf.readInt();
- int output = buf.readUnsignedShort();
- int status = buf.readUnsignedShort();
+ while (buf.readerIndex() < recordEnd) {
- position.set(Position.KEY_IGNITION, BitUtil.check(input, 0));
+ int fieldId = buf.readUnsignedByte();
+ int fieldLength = buf.readUnsignedByte();
+ int fieldEnd = buf.readerIndex() + (fieldLength == 255 ? buf.readUnsignedShort() : fieldLength);
- position.set(Position.KEY_INPUT, input);
- position.set(Position.KEY_OUTPUT, output);
- position.set(Position.KEY_STATUS, status);
+ if (fieldId == 0) {
- } else if (fieldId == 6) {
+ 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()));
- 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.readUnsignedByte(); // speed accuracy
- }
+ position.setCourse(buf.readUnsignedByte() * 2);
- buf.readerIndex(fieldEnd);
+ 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;
+ }
+ }
- if (position.getFixTime() == null) {
- getLastLocation(position, position.getDeviceTime());
}
- positions.add(position);
+ buf.readerIndex(fieldEnd);
+
+ }
+ if (position.getFixTime() == null) {
+ getLastLocation(position, position.getDeviceTime());
}
- return positions;
+ positions.add(position);
+ }
+
+ return positions;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.skipBytes(2); // header
+
+ int type = buf.readUnsignedByte();
+ int length = buf.readUnsignedShort();
+
+ if (type == MSG_HELLO) {
+
+ buf.readUnsignedInt(); // device serial number
+
+ DeviceSession deviceSession = getDeviceSession(
+ channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII));
+
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ if (length == 51) {
+ response.writeByte(0); // reserved
+ response.writeInt(0); // reserved
+ } else {
+ response.writeInt((int) ((System.currentTimeMillis() - 1356998400000L) / 1000));
+ response.writeInt(deviceSession != null ? 0 : 1); // flags
+ }
+
+ sendResponse(channel, MSG_HELLO_RESPONSE, response);
+
+ } else if (type == MSG_COMMIT) {
+
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeByte(1); // flags (success)
+ sendResponse(channel, MSG_COMMIT_RESPONSE, response);
+
+ } else if (type == MSG_CANNED_REQUEST_1) {
+
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeBytes(new byte[12]);
+ sendResponse(channel, MSG_CANNED_RESPONSE_1, response);
+
+ } else if (type == MSG_CANNED_REQUEST_2) {
+
+ sendResponse(channel, MSG_CANNED_RESPONSE_2, null);
+
+ } else if (type == MSG_DATA_RECORD_64) {
+
+ return decodeFixed64(channel, remoteAddress, buf);
+
+ } else if (type == MSG_DATA_RECORD) {
+
+ return decodeStandard(channel, remoteAddress, buf);
}
diff --git a/src/org/traccar/protocol/DwayProtocolDecoder.java b/src/org/traccar/protocol/DwayProtocolDecoder.java
index 121681588..8ddd62b83 100644
--- a/src/org/traccar/protocol/DwayProtocolDecoder.java
+++ b/src/org/traccar/protocol/DwayProtocolDecoder.java
@@ -76,8 +76,7 @@ public class DwayProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
diff --git a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
index 799254b65..16ced37ae 100644
--- a/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/EasyTrackProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,6 +54,31 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private String decodeAlarm(long status) {
+ if ((status & 0x02000000) > 0) {
+ return Position.ALARM_GEOFENCE_ENTER;
+ }
+ if ((status & 0x04000000) > 0) {
+ return Position.ALARM_GEOFENCE_EXIT;
+ }
+ if ((status & 0x08000000) > 0) {
+ return Position.ALARM_LOW_BATTERY;
+ }
+ if ((status & 0x20000000) > 0) {
+ return Position.ALARM_VIBRATION;
+ }
+ if ((status & 0x80000000) > 0) {
+ return Position.ALARM_OVERSPEED;
+ }
+ if ((status & 0x00010000) > 0) {
+ return Position.ALARM_SOS;
+ }
+ if ((status & 0x00040000) > 0) {
+ return Position.ALARM_POWER_CUT;
+ }
+ return null;
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -63,8 +88,7 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
@@ -96,7 +120,10 @@ public class EasyTrackProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextHexInt(0) / 100.0));
position.setCourse(parser.nextHexInt(0) / 100.0);
- position.set(Position.KEY_STATUS, parser.next());
+ long status = parser.nextHexLong();
+ position.set(Position.KEY_STATUS, status);
+ position.set(Position.KEY_ALARM, decodeAlarm(status));
+
position.set("signal", parser.next());
position.set(Position.KEY_POWER, parser.nextDouble(0));
position.set("oil", parser.nextHexInt(0));
diff --git a/src/org/traccar/protocol/EelinkProtocolDecoder.java b/src/org/traccar/protocol/EelinkProtocolDecoder.java
index 98a9f7d6d..0ed81c925 100644
--- a/src/org/traccar/protocol/EelinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolDecoder.java
@@ -115,9 +115,8 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
private Position decodeOld(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.set(Position.KEY_INDEX, index);
@@ -173,9 +172,8 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int index) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.set(Position.KEY_INDEX, index);
@@ -282,9 +280,8 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
private Position decodeResult(DeviceSession deviceSession, ChannelBuffer buf, int index) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.set(Position.KEY_INDEX, index);
@@ -362,9 +359,8 @@ public class EelinkProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_HEARTBEAT && buf.readableBytes() >= 2) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
getLastLocation(position, null);
diff --git a/src/org/traccar/protocol/EelinkProtocolEncoder.java b/src/org/traccar/protocol/EelinkProtocolEncoder.java
index 76865a039..4d2d86e68 100644
--- a/src/org/traccar/protocol/EelinkProtocolEncoder.java
+++ b/src/org/traccar/protocol/EelinkProtocolEncoder.java
@@ -18,10 +18,10 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.traccar.BaseProtocolEncoder;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-import javax.xml.bind.DatatypeConverter;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@@ -47,7 +47,7 @@ public class EelinkProtocolEncoder extends BaseProtocolEncoder {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
if (connectionless) {
- buf.writeBytes(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary('0' + uniqueId)));
+ buf.writeBytes(ChannelBuffers.wrappedBuffer(DataConverter.parseHex('0' + uniqueId)));
}
buf.writeByte(0x67);
diff --git a/src/org/traccar/protocol/EgtsFrameDecoder.java b/src/org/traccar/protocol/EgtsFrameDecoder.java
new file mode 100644
index 000000000..71ffc1811
--- /dev/null
+++ b/src/org/traccar/protocol/EgtsFrameDecoder.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 EgtsFrameDecoder extends FrameDecoder {
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
+ if (buf.readableBytes() < 10) {
+ return null;
+ }
+
+ int headerLength = buf.getUnsignedByte(buf.readerIndex() + 3);
+ int frameLength = buf.getUnsignedShort(buf.readerIndex() + 5);
+
+ int length = headerLength + frameLength + (frameLength > 0 ? 2 : 0);
+
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/EgtsProtocol.java b/src/org/traccar/protocol/EgtsProtocol.java
new file mode 100644
index 000000000..13ec6c9a7
--- /dev/null
+++ b/src/org/traccar/protocol/EgtsProtocol.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 EgtsProtocol extends BaseProtocol {
+
+ public EgtsProtocol() {
+ super("egts");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new EgtsFrameDecoder());
+ pipeline.addLast("objectDecoder", new EgtsProtocolDecoder(EgtsProtocol.this));
+ }
+ };
+ server.setEndianness(ByteOrder.LITTLE_ENDIAN);
+ serverList.add(server);
+ }
+
+}
diff --git a/src/org/traccar/protocol/EgtsProtocolDecoder.java b/src/org/traccar/protocol/EgtsProtocolDecoder.java
new file mode 100644
index 000000000..420701e6c
--- /dev/null
+++ b/src/org/traccar/protocol/EgtsProtocolDecoder.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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.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 EgtsProtocolDecoder extends BaseProtocolDecoder {
+
+ public EgtsProtocolDecoder(EgtsProtocol protocol) {
+ super(protocol);
+ }
+
+ public static final int PT_RESPONSE = 0;
+ public static final int PT_APPDATA = 1;
+ public static final int PT_SIGNED_APPDATA = 2;
+
+ public static final int SERVICE_AUTH = 1;
+ public static final int SERVICE_TELEDATA = 2;
+ public static final int SERVICE_COMMANDS = 4;
+ public static final int SERVICE_FIRMWARE = 9;
+ public static final int SERVICE_ECALL = 10;
+
+ public static final int MSG_RECORD_RESPONSE = 0;
+ public static final int MSG_TERM_IDENTITY = 1;
+ public static final int MSG_MODULE_DATA = 2;
+ public static final int MSG_VEHICLE_DATA = 3;
+ public static final int MSG_AUTH_PARAMS = 4;
+ public static final int MSG_AUTH_INFO = 5;
+ public static final int MSG_SERVICE_INFO = 6;
+ public static final int MSG_RESULT_CODE = 7;
+ public static final int MSG_POS_DATA = 16;
+ public static final int MSG_EXT_POS_DATA = 17;
+ public static final int MSG_AD_SENSORS_DATA = 18;
+ public static final int MSG_COUNTERS_DATA = 19;
+ public static final int MSG_STATE_DATA = 20;
+ public static final int MSG_LOOPIN_DATA = 22;
+ public static final int MSG_ABS_DIG_SENS_DATA = 23;
+ public static final int MSG_ABS_AN_SENS_DATA = 24;
+ public static final int MSG_ABS_CNTR_DATA = 25;
+ public static final int MSG_ABS_LOOPIN_DATA = 26;
+ public static final int MSG_LIQUID_LEVEL_SENSOR = 27;
+ public static final int MSG_PASSENGERS_COUNTERS = 28;
+
+ private int packetId;
+
+ private void sendResponse(
+ Channel channel, int packetType, int index, int serviceType, int type, ChannelBuffer content) {
+ if (channel != null) {
+
+ ChannelBuffer data = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ data.writeByte(type);
+ data.writeShort(content.readableBytes());
+ data.writeBytes(content);
+
+ ChannelBuffer record = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ record.writeShort(data.readableBytes());
+ record.writeShort(index);
+ record.writeByte(1 << 6); // flags
+ record.writeByte(serviceType);
+ record.writeByte(serviceType);
+ record.writeBytes(data);
+ int recordChecksum = Checksum.crc16(Checksum.CRC16_CCITT_FALSE, record.toByteBuffer());
+
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeByte(1); // protocol version
+ response.writeByte(0); // security key id
+ response.writeByte(0); // flags
+ response.writeByte(5 + 2 + 2 + 2); // header length
+ response.writeByte(0); // encoding
+ response.writeShort(record.readableBytes());
+ response.writeShort(packetId++);
+ response.writeByte(packetType);
+ response.writeByte(Checksum.crc8(Checksum.CRC8_EGTS, response.toByteBuffer()));
+ response.writeBytes(record);
+ response.writeShort(recordChecksum);
+
+ channel.write(response);
+
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ buf.skipBytes(buf.getUnsignedByte(buf.readerIndex() + 3));
+
+ List<Position> positions = new LinkedList<>();
+
+ while (buf.readableBytes() > 2) {
+
+ int length = buf.readUnsignedShort();
+ int index = buf.readUnsignedShort();
+ int recordFlags = buf.readUnsignedByte();
+
+ if (BitUtil.check(recordFlags, 0)) {
+ buf.readUnsignedInt(); // object id
+ }
+
+ if (BitUtil.check(recordFlags, 1)) {
+ buf.readUnsignedInt(); // event id
+ }
+ if (BitUtil.check(recordFlags, 2)) {
+ buf.readUnsignedInt(); // time
+ }
+
+ int serviceType = buf.readUnsignedByte();
+ buf.readUnsignedByte(); // recipient service type
+
+ int recordEnd = buf.readerIndex() + length;
+
+ Position position = new Position(getProtocolName());
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession != null) {
+ position.setDeviceId(deviceSession.getDeviceId());
+ }
+
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeShort(index);
+ response.writeByte(0); // success
+ sendResponse(channel, PT_RESPONSE, index, serviceType, MSG_RECORD_RESPONSE, response);
+
+ while (buf.readerIndex() < recordEnd) {
+ int type = buf.readUnsignedByte();
+ int end = buf.readUnsignedShort() + buf.readerIndex();
+
+ if (type == MSG_TERM_IDENTITY) {
+
+ buf.readUnsignedInt(); // object id
+ int flags = buf.readUnsignedByte();
+
+ if (BitUtil.check(flags, 0)) {
+ buf.readUnsignedShort(); // home dispatcher identifier
+ }
+ if (BitUtil.check(flags, 1)) {
+ getDeviceSession(
+ channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII).trim());
+ }
+ if (BitUtil.check(flags, 2)) {
+ getDeviceSession(
+ channel, remoteAddress, buf.readBytes(16).toString(StandardCharsets.US_ASCII).trim());
+ }
+ if (BitUtil.check(flags, 3)) {
+ buf.skipBytes(3); // language identifier
+ }
+ if (BitUtil.check(flags, 5)) {
+ buf.skipBytes(3); // network identifier
+ }
+ if (BitUtil.check(flags, 6)) {
+ buf.readUnsignedShort(); // buffer size
+ }
+ if (BitUtil.check(flags, 7)) {
+ getDeviceSession(
+ channel, remoteAddress, buf.readBytes(15).toString(StandardCharsets.US_ASCII).trim());
+ }
+
+ response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeByte(0); // success
+ sendResponse(channel, PT_APPDATA, index, serviceType, MSG_RESULT_CODE, response);
+
+ } else if (type == MSG_POS_DATA) {
+
+ position.setTime(new Date((buf.readUnsignedInt() + 1262304000) * 1000)); // since 2010-01-01
+ position.setLatitude(buf.readUnsignedInt() * 90.0 / 0xFFFFFFFFL);
+ position.setLongitude(buf.readUnsignedInt() * 180.0 / 0xFFFFFFFFL);
+
+ int flags = buf.readUnsignedByte();
+ position.setValid(BitUtil.check(flags, 0));
+ if (BitUtil.check(flags, 5)) {
+ position.setLatitude(-position.getLatitude());
+ }
+ if (BitUtil.check(flags, 6)) {
+ position.setLongitude(-position.getLongitude());
+ }
+
+ int speed = buf.readUnsignedShort();
+ position.setSpeed(UnitsConverter.knotsFromKph(BitUtil.to(speed, 14) * 0.1));
+ position.setCourse(buf.readUnsignedByte() + (BitUtil.check(speed, 15) ? 0x100 : 0));
+
+ position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium() * 100);
+ position.set(Position.KEY_INPUT, buf.readUnsignedByte());
+ position.set(Position.KEY_EVENT, buf.readUnsignedByte());
+
+ if (BitUtil.check(flags, 7)) {
+ position.setAltitude(buf.readMedium());
+ }
+
+ } else if (type == MSG_EXT_POS_DATA) {
+
+ int flags = buf.readUnsignedByte();
+
+ if (BitUtil.check(flags, 0)) {
+ position.set(Position.KEY_VDOP, buf.readUnsignedShort());
+ }
+ if (BitUtil.check(flags, 1)) {
+ position.set(Position.KEY_HDOP, buf.readUnsignedShort());
+ }
+ if (BitUtil.check(flags, 2)) {
+ position.set(Position.KEY_PDOP, buf.readUnsignedShort());
+ }
+ if (BitUtil.check(flags, 3)) {
+ position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
+ }
+
+ } else if (type == MSG_AD_SENSORS_DATA) {
+
+ buf.readUnsignedByte(); // inputs flags
+
+ position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
+
+ buf.readUnsignedByte(); // adc flags
+
+ }
+
+ buf.readerIndex(end);
+ }
+
+ if (serviceType == SERVICE_TELEDATA && deviceSession != null) {
+ positions.add(position);
+ }
+ }
+
+ return positions.isEmpty() ? null : positions;
+ }
+
+}
diff --git a/src/org/traccar/protocol/EnforaProtocolDecoder.java b/src/org/traccar/protocol/EnforaProtocolDecoder.java
index f0b79aa1f..c5500c3b3 100644
--- a/src/org/traccar/protocol/EnforaProtocolDecoder.java
+++ b/src/org/traccar/protocol/EnforaProtocolDecoder.java
@@ -95,8 +95,7 @@ public class EnforaProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/EskyProtocolDecoder.java b/src/org/traccar/protocol/EskyProtocolDecoder.java
index b509d821f..60ef4f846 100644
--- a/src/org/traccar/protocol/EskyProtocolDecoder.java
+++ b/src/org/traccar/protocol/EskyProtocolDecoder.java
@@ -65,8 +65,7 @@ public class EskyProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_SATELLITES, parser.nextInt());
diff --git a/src/org/traccar/protocol/ExtremTracProtocolDecoder.java b/src/org/traccar/protocol/ExtremTracProtocolDecoder.java
index 79e3306df..553720f1e 100644
--- a/src/org/traccar/protocol/ExtremTracProtocolDecoder.java
+++ b/src/org/traccar/protocol/ExtremTracProtocolDecoder.java
@@ -61,8 +61,7 @@ public class ExtremTracProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/FifotrackProtocolDecoder.java b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
index 304f6a2c3..cb7a23315 100644
--- a/src/org/traccar/protocol/FifotrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/FifotrackProtocolDecoder.java
@@ -78,8 +78,7 @@ public class FifotrackProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_ALARM, parser.next());
diff --git a/src/org/traccar/protocol/FlespiProtocolDecoder.java b/src/org/traccar/protocol/FlespiProtocolDecoder.java
index 6cba234e5..526e10fa2 100644
--- a/src/org/traccar/protocol/FlespiProtocolDecoder.java
+++ b/src/org/traccar/protocol/FlespiProtocolDecoder.java
@@ -60,9 +60,8 @@ public class FlespiProtocolDecoder extends BaseHttpProtocolDecoder {
if (deviceSession == null) {
continue;
}
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
decodePosition(message, position);
positions.add(position);
}
@@ -124,7 +123,7 @@ public class FlespiProtocolDecoder extends BaseHttpProtocolDecoder {
return true;
case "din":
case "dout":
- position.set((name.equals("din") ? Position.KEY_INPUT : Position.KEY_OUTPUT),
+ position.set(name.equals("din") ? Position.KEY_INPUT : Position.KEY_OUTPUT,
((JsonNumber) value).intValue());
return true;
case "gps.vehicle.mileage":
diff --git a/src/org/traccar/protocol/FlexCommProtocolDecoder.java b/src/org/traccar/protocol/FlexCommProtocolDecoder.java
index f401145b9..8bd4dcee0 100644
--- a/src/org/traccar/protocol/FlexCommProtocolDecoder.java
+++ b/src/org/traccar/protocol/FlexCommProtocolDecoder.java
@@ -78,8 +78,7 @@ public class FlexCommProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_STATUS, parser.nextInt());
diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
index ab2e4d24c..8f7525147 100644
--- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java
@@ -103,8 +103,7 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
sendAcknowledgement(channel, parser.next());
diff --git a/src/org/traccar/protocol/FoxProtocolDecoder.java b/src/org/traccar/protocol/FoxProtocolDecoder.java
index 9b2cf0e1d..16f8fce27 100644
--- a/src/org/traccar/protocol/FoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/FoxProtocolDecoder.java
@@ -88,8 +88,7 @@ public class FoxProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_STATUS, parser.nextInt(0));
diff --git a/src/org/traccar/protocol/FreedomProtocolDecoder.java b/src/org/traccar/protocol/FreedomProtocolDecoder.java
index 56b6b9e19..28456c617 100644
--- a/src/org/traccar/protocol/FreedomProtocolDecoder.java
+++ b/src/org/traccar/protocol/FreedomProtocolDecoder.java
@@ -53,8 +53,7 @@ public class FreedomProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java
index 3944b37de..d8a1651bb 100644
--- a/src/org/traccar/protocol/GalileoProtocolDecoder.java
+++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java
@@ -20,6 +20,7 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import java.net.SocketAddress;
@@ -117,7 +118,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
position.setTime(new Date(buf.readUnsignedInt() * 1000));
break;
case 0x33:
- position.setSpeed(buf.readUnsignedShort() * 0.0539957);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
position.setCourse(buf.readUnsignedShort() * 0.1);
break;
case 0x34:
@@ -248,11 +249,10 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
boolean hasLocation = false;
DeviceSession deviceSession = null;
- Position position = new Position();
+ Position position = new Position(getProtocolName());
while (buf.readerIndex() < length) {
- // Check if new message started
int tag = buf.readUnsignedByte();
if (tags.contains(tag)) {
if (hasLocation && position.getFixTime() != null) {
@@ -260,7 +260,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
}
tags.clear();
hasLocation = false;
- position = new Position();
+ position = new Position(getProtocolName()); // new position starts
}
tags.add(tag);
@@ -278,13 +278,6 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
}
- 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) {
@@ -292,10 +285,17 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder {
}
}
+ if (hasLocation && position.getFixTime() != null) {
+ positions.add(position);
+ } else if (position.getAttributes().containsKey(Position.KEY_RESULT)) {
+ position.setDeviceId(deviceSession.getDeviceId());
+ getLastLocation(position, null);
+ positions.add(position);
+ }
+
sendReply(channel, buf.readUnsignedShort());
for (Position p : positions) {
- p.setProtocol(getProtocolName());
p.setDeviceId(deviceSession.getDeviceId());
}
diff --git a/src/org/traccar/protocol/GatorProtocolDecoder.java b/src/org/traccar/protocol/GatorProtocolDecoder.java
index 2ad4be3d3..9cd746f51 100644
--- a/src/org/traccar/protocol/GatorProtocolDecoder.java
+++ b/src/org/traccar/protocol/GatorProtocolDecoder.java
@@ -90,8 +90,7 @@ public class GatorProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_POSITION_DATA || type == MSG_ROLLCALL_RESPONSE
|| type == MSG_ALARM_DATA || type == MSG_BLIND_AREA) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, "1" + id, id);
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GenxProtocolDecoder.java b/src/org/traccar/protocol/GenxProtocolDecoder.java
index 3b38227dc..d4a348ce1 100644
--- a/src/org/traccar/protocol/GenxProtocolDecoder.java
+++ b/src/org/traccar/protocol/GenxProtocolDecoder.java
@@ -48,8 +48,7 @@ public class GenxProtocolDecoder extends BaseProtocolDecoder {
String[] values = ((String) msg).split(",");
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setValid(true);
for (int i = 0; i < Math.min(values.length, reportColumns.length); i++) {
diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
index 945edfff0..405090695 100644
--- a/src/org/traccar/protocol/Gl100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java
@@ -72,8 +72,7 @@ public class Gl100ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java b/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java
index 071960e49..ba3baaa75 100644
--- a/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200BinaryProtocolDecoder.java
@@ -108,8 +108,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder {
time += 1;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
switch (BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 8 - 2)) {
@@ -156,8 +155,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_BATTERY_LEVEL, battery);
@@ -206,8 +204,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder {
private Position decodeEvent(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
int type = buf.readUnsignedByte();
@@ -313,8 +310,7 @@ public class Gl200BinaryProtocolDecoder extends BaseProtocolDecoder {
private Position decodeInformation(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
int type = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
index 9429cff2f..ff300d429 100644
--- a/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200TextProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -210,7 +210,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
.number("(d{15}|x{14}),") // imei
.expression("[^,]*,") // device name
- .number("x{8},") // mask
+ .number("(x{8}),") // mask
.number("(d+)?,") // power
.number("d{1,2},") // report type
.number("d{1,2},") // count
@@ -356,8 +356,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
channel.write("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress);
}
} else {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime());
position.setValid(false);
@@ -372,8 +371,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
if (parser.matches()) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession != null) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
return position;
}
@@ -431,8 +429,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
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, parser.nextDouble());
+ position.set(Position.KEY_CHARGE, parser.nextInt() == 1);
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
@@ -446,7 +444,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, parser.nextDateTime());
- position.set(Position.KEY_INDEX, parser.nextHexInt(0));
+ position.set(Position.KEY_INDEX, parser.nextHexInt());
return position;
}
@@ -459,8 +457,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
}
position.set("deviceType", parser.next());
- position.set(Position.KEY_VERSION_FW, parser.nextHexInt(0));
- position.set(Position.KEY_VERSION_HW, parser.nextHexInt(0));
+ position.set(Position.KEY_VERSION_FW, parser.nextHexInt());
+ position.set(Position.KEY_VERSION_HW, parser.nextHexInt());
getLastLocation(position, parser.nextDateTime());
@@ -468,8 +466,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
}
private void decodeLocation(Position position, Parser parser) {
- int hdop = parser.nextInt(0);
- position.setValid(hdop > 0);
+ Integer hdop = parser.nextInt();
+ position.setValid(hdop == null || hdop > 0);
position.set(Position.KEY_HDOP, hdop);
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
@@ -478,25 +476,27 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext(8)) {
position.setValid(true);
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
+ position.setLongitude(parser.nextDouble());
+ position.setLatitude(parser.nextDouble());
position.setTime(parser.nextDateTime());
} else {
getLastLocation(position, null);
}
if (parser.hasNext(6)) {
- int mcc = parser.nextInt(0);
- int mnc = parser.nextInt(0);
+ int mcc = parser.nextInt();
+ int mnc = parser.nextInt();
if (parser.hasNext(2)) {
- position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(0), parser.nextInt(0))));
+ position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextInt(), parser.nextInt())));
}
if (parser.hasNext(2)) {
- position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0))));
+ position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(), parser.nextHexInt())));
}
}
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ if (parser.hasNext()) {
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ }
}
private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
@@ -511,16 +511,22 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
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);
+ if (parser.hasNext()) {
+ position.set("odbConnect", parser.nextInt() == 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);
+ if (parser.hasNext()) {
+ position.set(Position.KEY_OBD_ODOMETER, parser.nextInt() * 1000);
+ }
decodeLocation(position, parser);
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ if (parser.hasNext()) {
+ position.set(Position.KEY_OBD_ODOMETER, (int) (parser.nextDouble() * 1000));
+ }
decodeDeviceTime(position, parser);
@@ -528,8 +534,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
}
private Object decodeCan(Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
int index = 0;
String[] values = sentence.split(",");
@@ -557,14 +562,14 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(reportMask, 3)) {
position.set("totalFuelConsumption", Double.parseDouble(values[index++]));
}
- if (BitUtil.check(reportMask, 5)) {
- position.set(Position.KEY_RPM, Integer.parseInt(values[index++]));
+ if (BitUtil.check(reportMask, 5) && !values[index++].isEmpty()) {
+ position.set(Position.KEY_RPM, Integer.parseInt(values[index - 1]));
}
- if (BitUtil.check(reportMask, 4)) {
- position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(values[index++])));
+ if (BitUtil.check(reportMask, 4) && !values[index++].isEmpty()) {
+ position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));
}
- if (BitUtil.check(reportMask, 6)) {
- position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[index++]));
+ if (BitUtil.check(reportMask, 6) && !values[index++].isEmpty()) {
+ position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 7) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_CONSUMPTION, Double.parseDouble(values[index - 1].substring(1)));
@@ -652,14 +657,14 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
private void decodeStatus(Position position, Parser parser) {
if (parser.hasNext(3)) {
- int ignition = parser.nextHexInt(0);
+ int ignition = parser.nextHexInt();
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));
+ position.set(Position.KEY_INPUT, parser.nextHexInt());
+ position.set(Position.KEY_OUTPUT, parser.nextHexInt());
}
}
@@ -677,12 +682,11 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
LinkedList<Position> positions = new LinkedList<>();
String vin = parser.next();
- int power = parser.nextInt(0);
+ Integer power = parser.nextInt();
Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
while (itemParser.find()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VIN, vin);
@@ -696,15 +700,18 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
- // power value only on some devices
- if (power > 10) {
- position.set(Position.KEY_POWER, power);
+ if (power != null && power > 10) {
+ position.set(Position.KEY_POWER, power * 0.001); // only on some devices
}
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ if (parser.hasNext()) {
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ }
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ if (parser.hasNext()) {
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ }
position.set(Position.KEY_HOURS, parser.next());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.PREFIX_ADC + 2, parser.next());
@@ -735,14 +742,15 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
return null;
}
+ long mask = parser.nextHexLong();
+
LinkedList<Position> positions = new LinkedList<>();
- int power = parser.nextInt(0);
+ Integer power = parser.nextInt();
Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
while (itemParser.find()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
decodeLocation(position, itemParser);
@@ -754,8 +762,10 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
- position.set(Position.KEY_POWER, power);
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ if (power != null) {
+ position.set(Position.KEY_POWER, power * 0.001);
+ }
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
position.set(Position.KEY_HOURS, parser.next());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.PREFIX_ADC + 2, parser.next());
@@ -765,14 +775,37 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
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);
+
+ index += 1; // device type
+
+ if (BitUtil.check(mask, 0)) {
+ index += 1; // digital fuel sensor data
+ }
+
+ if (BitUtil.check(mask, 1)) {
+ int deviceCount = Integer.parseInt(data[index++]);
+ for (int i = 1; i <= deviceCount; i++) {
+ index += 1; // id
+ index += 1; // type
+ if (!data[index++].isEmpty()) {
+ position.set(Position.PREFIX_TEMP + i, (short) Integer.parseInt(data[index - 1], 16) * 0.0625);
+ }
+ }
+ }
+
+ if (BitUtil.check(mask, 2)) {
+ index += 1; // can data
+ }
+
+ if (BitUtil.check(mask, 3) || BitUtil.check(mask, 4)) {
+ int deviceCount = Integer.parseInt(data[index++]);
+ for (int i = 1; i <= deviceCount; i++) {
+ index += 1; // type
+ if (BitUtil.check(mask, 3)) {
+ position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(data[index++]));
+ }
+ if (BitUtil.check(mask, 4)) {
+ index += 1; // volume
}
}
}
@@ -796,7 +829,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
position.set(Position.KEY_HOURS, parser.next());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
decodeDeviceTime(position, parser);
@@ -814,7 +847,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
decodeDeviceTime(position, parser);
@@ -832,7 +865,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
Network network = new Network();
- parser.nextInt(0); // count
+ parser.nextInt(); // count
Matcher matcher = Pattern.compile("([0-9a-fA-F]{12}),(-?\\d+),,,,").matcher(parser.next());
while (matcher.find()) {
String mac = matcher.group(1).replaceAll("(..)", "$1:");
@@ -842,7 +875,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
position.setNetwork(network);
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
+ position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
return position;
}
@@ -880,7 +913,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- int reportType = parser.nextInt(0);
+ int reportType = parser.nextInt();
if (type.equals("NMR")) {
position.set(Position.KEY_MOTION, reportType == 1);
} else if (type.equals("SOS")) {
@@ -889,10 +922,14 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
- position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
+ if (parser.hasNext()) {
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ }
+ position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
- position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
+ if (parser.hasNext()) {
+ position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
+ }
decodeDeviceTime(position, parser);
@@ -910,7 +947,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- int hdop = parser.nextInt(0);
+ int hdop = parser.nextInt();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop);
@@ -919,8 +956,8 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
position.setAltitude(parser.nextDouble(0));
if (parser.hasNext(2)) {
- position.setLongitude(parser.nextDouble(0));
- position.setLatitude(parser.nextDouble(0));
+ position.setLongitude(parser.nextDouble());
+ position.setLatitude(parser.nextDouble());
} else {
getLastLocation(position, null);
}
@@ -931,7 +968,7 @@ public class Gl200TextProtocolDecoder extends BaseProtocolDecoder {
if (parser.hasNext(4)) {
position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
+ parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
}
decodeDeviceTime(position, parser);
diff --git a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
index c45a937d4..4361e0c2f 100644
--- a/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
+++ b/src/org/traccar/protocol/GlobalSatProtocolDecoder.java
@@ -76,8 +76,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
}
String[] values = sentence.split(",");
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
for (int formatIndex = 0, valueIndex = 1; formatIndex < format.length()
&& valueIndex < values.length; formatIndex++) {
@@ -207,8 +206,7 @@ public class GlobalSatProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GlobeKeeperProtocol.java b/src/org/traccar/protocol/GlobeKeeperProtocol.java
new file mode 100644
index 000000000..9231c067c
--- /dev/null
+++ b/src/org/traccar/protocol/GlobeKeeperProtocol.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 GlobeKeeperProtocol extends BaseProtocol {
+
+ public GlobeKeeperProtocol() {
+ super("globekeeper");
+ }
+
+ @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 GlobeKeeperProtocolDecoder(GlobeKeeperProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/GlobeKeeperProtocolDecoder.java b/src/org/traccar/protocol/GlobeKeeperProtocolDecoder.java
new file mode 100644
index 000000000..c4daf4409
--- /dev/null
+++ b/src/org/traccar/protocol/GlobeKeeperProtocolDecoder.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 GlobeKeeperProtocolDecoder extends BaseProtocolDecoder {
+
+ public GlobeKeeperProtocolDecoder(GlobeKeeperProtocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .number("(d+);") // imei
+ .number("(dddd)-(dd)-(dd) ") // date
+ .number("(dd):(dd):(dd);") // time
+ .number("(-?d+,d+);") // latitude
+ .number("(-?d+,d+);") // longitude
+ .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(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setTime(parser.nextDateTime());
+
+ position.setValid(true);
+ position.setLongitude(Double.parseDouble(parser.next().replace(',', '.')));
+ position.setLatitude(Double.parseDouble(parser.next().replace(',', '.')));
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/GnxProtocolDecoder.java b/src/org/traccar/protocol/GnxProtocolDecoder.java
index 2274ec164..b3a636d14 100644
--- a/src/org/traccar/protocol/GnxProtocolDecoder.java
+++ b/src/org/traccar/protocol/GnxProtocolDecoder.java
@@ -80,8 +80,7 @@ public class GnxProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GoSafeProtocolDecoder.java b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
index 62f6212e2..0fa1934da 100644
--- a/src/org/traccar/protocol/GoSafeProtocolDecoder.java
+++ b/src/org/traccar/protocol/GoSafeProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,75 +45,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.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("?")
+ .expression("([^#]*)#?") // data
.compile();
private static final Pattern PATTERN_OLD = new PatternBuilder()
@@ -133,71 +65,138 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private Position decodePosition(DeviceSession deviceSession, Parser parser, Date time) {
+ private void decodeFragment(Position position, String fragment) {
+ int dataIndex = fragment.indexOf(':');
+ int index = 0;
+ String[] values = fragment.substring(dataIndex + 1).split(";");
+ switch (fragment.substring(0, dataIndex)) {
+ case "GPS":
+ position.setValid(values[index++].equals("A"));
+ position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++]));
+ position.setLatitude(Double.parseDouble(values[index].substring(1)));
+ if (values[index++].charAt(0) == 'S') {
+ position.setLatitude(-position.getLatitude());
+ }
+ position.setLongitude(Double.parseDouble(values[index].substring(1)));
+ if (values[index++].charAt(0) == 'W') {
+ position.setLongitude(-position.getLongitude());
+ }
+ if (!values[index++].isEmpty()) {
+ position.setSpeed(UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));
+ }
+ position.setCourse(Integer.parseInt(values[index++]));
+ position.setAltitude(Integer.parseInt(values[index++]));
+ if (index < values.length) {
+ position.set(Position.KEY_HDOP, Double.parseDouble(values[index++]));
+ }
+ if (index < values.length) {
+ position.set(Position.KEY_VDOP, Double.parseDouble(values[index++]));
+ }
+ break;
+ case "GSM":
+ index += 1; // registration status
+ index += 1; // signal strength
+ position.setNetwork(new Network(CellTower.from(
+ Integer.parseInt(values[index++]), Integer.parseInt(values[index++]),
+ Integer.parseInt(values[index++], 16), Integer.parseInt(values[index++], 16),
+ Integer.parseInt(values[index++]))));
+ break;
+ case "COT":
+ if (index < values.length) {
+ position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++]));
+ }
+ if (index < values.length) {
+ String[] hours = values[index].split("-");
+ position.set(Position.KEY_HOURS, Integer.parseInt(hours[0])
+ + Integer.parseInt(hours[0]) / 60.0 + Integer.parseInt(hours[0]) / 3600.0);
+ }
+ break;
+ case "ADC":
+ position.set(Position.KEY_POWER, Double.parseDouble(values[index++]));
+ if (index < values.length) {
+ position.set(Position.KEY_BATTERY, Double.parseDouble(values[index++]));
+ }
+ if (index < values.length) {
+ position.set(Position.PREFIX_ADC + 1, Double.parseDouble(values[index++]));
+ }
+ if (index < values.length) {
+ position.set(Position.PREFIX_ADC + 2, Double.parseDouble(values[index++]));
+ }
+ break;
+ case "DTT":
+ position.set(Position.KEY_STATUS, Integer.parseInt(values[index++], 16));
+ if (!values[index++].isEmpty()) {
+ int io = Integer.parseInt(values[index - 1], 16);
+ position.set(Position.KEY_IGNITION, BitUtil.check(io, 0));
+ position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1));
+ position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2));
+ position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3));
+ position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4));
+ position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5));
+ position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6));
+ position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7));
+ }
+ position.set(Position.KEY_GEOFENCE, values[index++] + values[index++]);
+ position.set("eventStatus", values[index++]);
+ if (index < values.length) {
+ position.set("packetType", values[index++]);
+ }
+ break;
+ case "ETD":
+ position.set("eventData", values[index++]);
+ break;
+ case "OBD":
+ position.set("obd", values[index++]);
+ break;
+ case "TAG":
+ position.set("tagData", values[index++]);
+ break;
+ case "IWD":
+ if (index < values.length && values[index + 1].equals("0")) {
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, values[index + 2]);
+ }
+ break;
+ default:
+ break;
+ }
+ }
- Position position = new Position();
- position.setProtocol(getProtocolName());
- position.setDeviceId(deviceSession.getDeviceId());
+ private Object decodeData(DeviceSession deviceSession, Date time, String data) {
- if (time != null) {
- position.setTime(time);
- }
+ List<Position> positions = new LinkedList<>();
+ Position position = null;
+ int index = 0;
+ String[] fragments = data.split(",");
- position.set(Position.KEY_EVENT, parser.next());
+ while (index < fragments.length) {
- position.setValid(parser.next().equals("A"));
- position.set(Position.KEY_SATELLITES, parser.nextInt());
+ if (fragments[index].isEmpty() || Character.isDigit(fragments[index].charAt(0))) {
- 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));
+ if (position != null) {
+ positions.add(position);
+ }
- position.set(Position.KEY_HDOP, parser.nextDouble(0));
- position.set(Position.KEY_VDOP, parser.nextDouble(0));
+ position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+ position.setTime(time);
- 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)) {
- position.set(Position.KEY_STATUS, parser.nextHexLong());
- Integer io = parser.nextHexInt();
- if (io != null) {
- position.set(Position.KEY_IGNITION, BitUtil.check(io, 0));
- position.set(Position.PREFIX_IN + 1, BitUtil.check(io, 1));
- position.set(Position.PREFIX_IN + 2, BitUtil.check(io, 2));
- position.set(Position.PREFIX_IN + 3, BitUtil.check(io, 3));
- position.set(Position.PREFIX_IN + 4, BitUtil.check(io, 4));
- position.set(Position.PREFIX_OUT + 1, BitUtil.check(io, 5));
- position.set(Position.PREFIX_OUT + 2, BitUtil.check(io, 6));
- position.set(Position.PREFIX_OUT + 3, BitUtil.check(io, 7));
- }
- position.set(Position.KEY_GEOFENCE, parser.next() + parser.next());
- position.set("eventStatus", parser.next());
- position.set("packetType", parser.next());
- }
+ if (!fragments[index++].isEmpty()) {
+ position.set(Position.KEY_EVENT, Integer.parseInt(fragments[index - 1]));
+ }
- if (parser.hasNext()) {
- position.set("eventData", parser.next());
- }
+ } else {
+
+ decodeFragment(position, fragments[index++]);
+
+ }
- if (parser.hasNext()) {
- position.set("obd", parser.next());
}
- if (parser.hasNext()) {
- position.set("tagData", parser.next());
+ if (position != null) {
+ positions.add(position);
}
- return position;
+ return positions;
}
@Override
@@ -226,8 +225,7 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
if (pattern == PATTERN_OLD) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -248,18 +246,12 @@ public class GoSafeProtocolDecoder extends BaseProtocolDecoder {
} else {
- Date time = null;
+ Date time = new Date();
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;
+ return decodeData(deviceSession, time, parser.next());
}
}
diff --git a/src/org/traccar/protocol/GotopProtocolDecoder.java b/src/org/traccar/protocol/GotopProtocolDecoder.java
index f938887e2..29e8d87dd 100644
--- a/src/org/traccar/protocol/GotopProtocolDecoder.java
+++ b/src/org/traccar/protocol/GotopProtocolDecoder.java
@@ -55,8 +55,7 @@ public class GotopProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Gps056ProtocolDecoder.java b/src/org/traccar/protocol/Gps056ProtocolDecoder.java
index 7248365b0..ccb389250 100644
--- a/src/org/traccar/protocol/Gps056ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps056ProtocolDecoder.java
@@ -93,8 +93,7 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder {
} else if (type.startsWith("GPSL")) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -116,8 +115,7 @@ public class Gps056ProtocolDecoder extends BaseProtocolDecoder {
} else if (type.startsWith("SYNC")) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
index 099047aa0..f32d22c00 100644
--- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import org.traccar.model.Network;
import org.traccar.model.Position;
import java.net.SocketAddress;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
@@ -38,10 +39,19 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.text("imei:")
.number("(d+),") // imei
.expression("([^,]+),") // alarm
+ .groupBegin()
.number("(dd)/?(dd)/?(dd) ?") // local date (yymmdd)
.number("(dd):?(dd)(?:dd)?,") // local time (hhmmss)
+ .or()
+ .number("d*,")
+ .groupEnd()
.expression("([^,]+)?,") // rfid
- .expression("[FL],") // full / low
+ .groupBegin()
+ .text("L,,,")
+ .number("(x+),,") // lac
+ .number("(x+),,,") // cid
+ .or()
+ .text("F,")
.groupBegin()
.number("(dd)(dd)(dd).d+") // time utc (hhmmss)
.or()
@@ -63,24 +73,10 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
.expression("([^,;]+)?,?")
.expression("([^,;]+)?,?")
.expression("([^,;]+)?,?")
+ .groupEnd()
.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
@@ -143,86 +139,9 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
}
}
- @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;
- }
- }
+ private Position decodeRegular(Channel channel, SocketAddress remoteAddress, String sentence) {
- 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);
+ Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
@@ -232,6 +151,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
if (deviceSession == null) {
return null;
}
+
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
String alarm = parser.next();
@@ -263,36 +184,115 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid);
}
- String utcHours = parser.next();
- String utcMinutes = parser.next();
+ if (parser.hasNext(2)) {
- dateBuilder.setTime(localHours, localMinutes, parser.nextInt(0));
+ getLastLocation(position, null);
- // 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;
+ position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
+
+ } else {
+
+ 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.setFixTime(position.getDeviceTime());
+ 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());
}
- 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));
+ return position;
+ }
+
+ private Position decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) {
+
+ Parser parser = new Parser(PATTERN_OBD, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
- for (int i = 1; i <= 5; i++) {
- position.set(Position.PREFIX_IO + i, parser.next());
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
+ if (deviceSession == null) {
+ return null;
}
+ Position position = new Position(getProtocolName());
+ 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;
}
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ if (sentence.contains("##")) {
+ if (channel != null) {
+ channel.write("LOAD", remoteAddress);
+ Matcher matcher = Pattern.compile("##,imei:(\\d+),A").matcher(sentence);
+ if (matcher.matches()) {
+ getDeviceSession(channel, remoteAddress, matcher.group(1));
+ }
+ }
+ return null;
+ }
+
+ 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;
+ }
+ }
+
+ if (sentence.contains("OBD")) {
+ return decodeObd(channel, remoteAddress, sentence);
+ } else {
+ return decodeRegular(channel, remoteAddress, sentence);
+ }
+ }
+
}
diff --git a/src/org/traccar/protocol/GpsGateProtocolDecoder.java b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
index ca1d6453e..5c7096276 100644
--- a/src/org/traccar/protocol/GpsGateProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsGateProtocolDecoder.java
@@ -118,8 +118,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -143,8 +142,7 @@ public class GpsGateProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
index f65f5b2bb..ca5bdcbed 100644
--- a/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsMarkerProtocolDecoder.java
@@ -61,8 +61,7 @@ public class GpsMarkerProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
index 11777bece..c71162078 100644
--- a/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
+++ b/src/org/traccar/protocol/GpsmtaProtocolDecoder.java
@@ -57,8 +57,7 @@ public class GpsmtaProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/GranitProtocolDecoder.java b/src/org/traccar/protocol/GranitProtocolDecoder.java
index 8e935ae9e..50d879bb4 100644
--- a/src/org/traccar/protocol/GranitProtocolDecoder.java
+++ b/src/org/traccar/protocol/GranitProtocolDecoder.java
@@ -158,8 +158,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
if (deviceSession != null && indexTilde == -1) {
String bufString = buf.toString(StandardCharsets.US_ASCII);
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date());
@@ -186,8 +185,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
if (channel != null) {
sendResponseCurrent(channel, deviceId, unixTime);
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(unixTime * 1000));
@@ -219,8 +217,7 @@ public class GranitProtocolDecoder extends BaseProtocolDecoder {
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 position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date((unixTime + i * timeIncrement) * 1000));
decodeStructure(buf, position);
diff --git a/src/org/traccar/protocol/Gt02ProtocolDecoder.java b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
index a520bff13..a4f1a4161 100644
--- a/src/org/traccar/protocol/Gt02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt02ProtocolDecoder.java
@@ -47,8 +47,7 @@ public class Gt02ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(2); // header
buf.readByte(); // size
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
// Zero for location messages
int power = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
index 37f64ee02..3e5ebc8c5 100644
--- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,20 +44,10 @@ 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;
@@ -172,7 +162,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
}
}
- private void sendResponse(Channel channel, boolean extended, int type, ChannelBuffer content) {
+ private void sendResponse(Channel channel, boolean extended, int type, int index, ChannelBuffer content) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer();
int length = 5 + (content != null ? content.readableBytes() : 0);
@@ -187,7 +177,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
if (content != null) {
response.writeBytes(content);
}
- response.writeShort(++serverIndex);
+ response.writeShort(index);
response.writeShort(Checksum.crc16(Checksum.CRC16_X25,
response.toByteBuffer(2, response.writerIndex() - 2)));
response.writeByte('\r'); response.writeByte('\n'); // ending
@@ -201,12 +191,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
content.writeInt(pictureId);
content.writeInt(photo.writerIndex());
content.writeShort(Math.min(photo.writableBytes(), 1024));
- sendResponse(channel, false, MSG_X1_PHOTO_DATA, content);
+ sendResponse(channel, false, MSG_X1_PHOTO_DATA, 0, content);
}
- private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength) {
+ private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength, TimeZone timezone) {
- DateBuilder dateBuilder = new DateBuilder(timeZone)
+ DateBuilder dateBuilder = new DateBuilder(timezone)
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
@@ -389,6 +379,9 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
if (deviceSession == null) {
return null;
}
+ if (deviceSession.getTimeZone() == null) {
+ deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId()));
+ }
}
if (type == MSG_LOGIN) {
@@ -396,6 +389,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
buf.readUnsignedShort(); // type
+ deviceSession = getDeviceSession(channel, remoteAddress, imei);
+ if (deviceSession != null && deviceSession.getTimeZone() == null) {
+ deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId()));
+ }
+
if (dataLength > 10) {
int extensionBits = buf.readUnsignedShort();
int hours = (extensionBits >> 4) / 100;
@@ -404,20 +402,24 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
if ((extensionBits & 0x8) != 0) {
offset = -offset;
}
- if (!forceTimeZone) {
- timeZone.setRawOffset(offset * 1000);
+ if (deviceSession != null) {
+ TimeZone timeZone = deviceSession.getTimeZone();
+ if (timeZone.getRawOffset() == 0) {
+ timeZone.setRawOffset(offset * 1000);
+ deviceSession.setTimeZone(timeZone);
+ }
}
+
}
- if (getDeviceSession(channel, remoteAddress, imei) != null) {
- sendResponse(channel, false, type, null);
+ if (deviceSession != null) {
+ sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
}
} else if (type == MSG_HEARTBEAT) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
getLastLocation(position, null);
@@ -426,7 +428,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_IGNITION, BitUtil.check(status, 1));
position.set(Position.KEY_CHARGE, BitUtil.check(status, 2));
- sendResponse(channel, false, type, null);
+ sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
return position;
@@ -437,7 +439,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
content.writeByte(response.length());
content.writeInt(0);
content.writeBytes(response.getBytes(StandardCharsets.US_ASCII));
- sendResponse(channel, true, MSG_ADDRESS_RESPONSE, content);
+ sendResponse(channel, true, MSG_ADDRESS_RESPONSE, 0, content);
} else if (type == MSG_TIME_REQUEST) {
@@ -449,17 +451,16 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
content.writeByte(calendar.get(Calendar.HOUR_OF_DAY));
content.writeByte(calendar.get(Calendar.MINUTE));
content.writeByte(calendar.get(Calendar.SECOND));
- sendResponse(channel, false, MSG_TIME_REQUEST, content);
+ sendResponse(channel, false, MSG_TIME_REQUEST, 0, content);
} else if (type == MSG_X1_GPS) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
buf.readUnsignedInt(); // data and alarm
- decodeGps(position, buf, false);
+ decodeGps(position, buf, false, deviceSession.getTimeZone());
buf.readUnsignedShort(); // terminal info
@@ -501,9 +502,8 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeWifi(ChannelBuffer buf, DeviceSession deviceSession) throws Exception {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
DateBuilder dateBuilder = new DateBuilder()
.setYear(BcdUtil.readInteger(buf, 2))
@@ -540,16 +540,15 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
private Object decodeBasicOther(Channel channel, ChannelBuffer buf,
DeviceSession deviceSession, int type, int dataLength) throws Exception {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
if (type == MSG_LBS_MULTIPLE || type == MSG_LBS_EXTEND || type == MSG_LBS_WIFI
|| type == MSG_LBS_2 || type == MSG_WIFI_3) {
boolean longFormat = type == MSG_LBS_2 || type == MSG_WIFI_3;
- DateBuilder dateBuilder = new DateBuilder(timeZone)
+ DateBuilder dateBuilder = new DateBuilder(deviceSession.getTimeZone())
.setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte())
.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
@@ -595,7 +594,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
} else if (isSupported(type)) {
if (hasGps(type)) {
- decodeGps(position, buf, false);
+ decodeGps(position, buf, false, deviceSession.getTimeZone());
} else {
getLastLocation(position, null);
}
@@ -622,7 +621,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(dataLength);
if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
- sendResponse(channel, false, type, null);
+ sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
}
return null;
@@ -636,7 +635,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_GEOFENCE, buf.readUnsignedByte());
}
- sendResponse(channel, false, type, null);
+ sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
return position;
}
@@ -648,9 +647,12 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
+ if (deviceSession.getTimeZone() == null) {
+ deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId()));
+ }
+
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
buf.readUnsignedShort(); // length
int type = buf.readUnsignedByte();
@@ -711,13 +713,14 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
sendPhotoRequest(channel, pictureId);
} else {
Device device = Context.getDeviceManager().getById(deviceSession.getDeviceId());
- Context.getMediaManager().writeFile(device.getUniqueId(), photo, "jpg");
+ position.set(
+ Position.KEY_IMAGE, 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)) {
+ if (!decodeGps(position, buf, true, deviceSession.getTimeZone())) {
getLastLocation(position, position.getDeviceTime());
}
@@ -756,7 +759,7 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(buf.readUnsignedByte()); // reserved extension
- sendResponse(channel, true, type, null);
+ sendResponse(channel, true, type, buf.getShort(buf.writerIndex() - 6), null);
return position;
diff --git a/src/org/traccar/protocol/Gt30ProtocolDecoder.java b/src/org/traccar/protocol/Gt30ProtocolDecoder.java
index 51135c80a..27081a108 100644
--- a/src/org/traccar/protocol/Gt30ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gt30ProtocolDecoder.java
@@ -84,8 +84,7 @@ public class Gt30ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext()) {
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 4414870d2..9764adf04 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -101,8 +101,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
private Position decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
buf.readByte(); // marker
@@ -267,8 +266,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext()) {
@@ -348,8 +346,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -388,8 +385,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -422,8 +418,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -461,7 +456,7 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
switch (marker) {
case "*":
- String sentence = buf.toString(StandardCharsets.US_ASCII);
+ String sentence = buf.toString(StandardCharsets.US_ASCII).trim();
int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1;
int typeEnd = sentence.indexOf(',', typeStart);
if (typeEnd > 0) {
diff --git a/src/org/traccar/protocol/HaicomProtocolDecoder.java b/src/org/traccar/protocol/HaicomProtocolDecoder.java
index 37898a9bc..94ec93cfb 100644
--- a/src/org/traccar/protocol/HaicomProtocolDecoder.java
+++ b/src/org/traccar/protocol/HaicomProtocolDecoder.java
@@ -62,8 +62,7 @@ public class HaicomProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/HomtecsProtocolDecoder.java b/src/org/traccar/protocol/HomtecsProtocolDecoder.java
index 508de173c..f4ae54d1f 100644
--- a/src/org/traccar/protocol/HomtecsProtocolDecoder.java
+++ b/src/org/traccar/protocol/HomtecsProtocolDecoder.java
@@ -66,8 +66,7 @@ public class HomtecsProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.YMD_HMS));
diff --git a/src/org/traccar/protocol/HuaShengProtocolDecoder.java b/src/org/traccar/protocol/HuaShengProtocolDecoder.java
index 96f87fd94..88f23b28c 100644
--- a/src/org/traccar/protocol/HuaShengProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuaShengProtocolDecoder.java
@@ -103,8 +103,7 @@ public class HuaShengProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int status = buf.readUnsignedShort();
diff --git a/src/org/traccar/protocol/HuabaoProtocolDecoder.java b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
index c31c6af1c..8643f39af 100644
--- a/src/org/traccar/protocol/HuabaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolDecoder.java
@@ -129,8 +129,7 @@ public class HuabaoProtocolDecoder extends BaseProtocolDecoder {
} else if (type == MSG_LOCATION_REPORT) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedInt()));
diff --git a/src/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
index 7d6f0510d..d1889bf5e 100644
--- a/src/org/traccar/protocol/HuabaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/HuabaoProtocolEncoder.java
@@ -18,10 +18,10 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.traccar.BaseProtocolEncoder;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-import javax.xml.bind.DatatypeConverter;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -31,10 +31,10 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder {
protected Object encodeCommand(Command command) {
ChannelBuffer id = ChannelBuffers.wrappedBuffer(
- DatatypeConverter.parseHexBinary(getUniqueId(command.getDeviceId())));
+ DataConverter.parseHex(getUniqueId(command.getDeviceId())));
ChannelBuffer data = ChannelBuffers.dynamicBuffer();
- byte[] time = DatatypeConverter.parseHexBinary(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
+ byte[] time = DataConverter.parseHex(new SimpleDateFormat("yyMMddHHmmss").format(new Date()));
switch (command.getType()) {
case Command.TYPE_ENGINE_STOP:
diff --git a/src/org/traccar/protocol/HunterProProtocolDecoder.java b/src/org/traccar/protocol/HunterProProtocolDecoder.java
index b1e3f84a2..fa470c065 100644
--- a/src/org/traccar/protocol/HunterProProtocolDecoder.java
+++ b/src/org/traccar/protocol/HunterProProtocolDecoder.java
@@ -56,8 +56,7 @@ public class HunterProProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/IdplProtocolDecoder.java b/src/org/traccar/protocol/IdplProtocolDecoder.java
index e56a0f022..9990e0da5 100644
--- a/src/org/traccar/protocol/IdplProtocolDecoder.java
+++ b/src/org/traccar/protocol/IdplProtocolDecoder.java
@@ -69,8 +69,7 @@ public class IdplProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_TYPE, parser.nextInt(0));
diff --git a/src/org/traccar/protocol/IntellitracProtocolDecoder.java b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
index 4a526376e..5b66fa7ec 100644
--- a/src/org/traccar/protocol/IntellitracProtocolDecoder.java
+++ b/src/org/traccar/protocol/IntellitracProtocolDecoder.java
@@ -72,8 +72,7 @@ public class IntellitracProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Ivt401ProtocolDecoder.java b/src/org/traccar/protocol/Ivt401ProtocolDecoder.java
index f209ee09e..d2f1d3d69 100644
--- a/src/org/traccar/protocol/Ivt401ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Ivt401ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public class Ivt401ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // speed
.number("(d+),") // course
.number("(-?d+.?d*),") // altitude
- .number("(d+),") // satellites
+ .number("d+,") // satellites or battery status
.number("(d),") // gps status
.number("(d+),") // rssi
.number("(d+),") // input
@@ -51,6 +51,30 @@ public class Ivt401ProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.d+),") // adc
.number("(d+.d+),") // power
.number("(d+.d+),") // battery
+ .number("(-?d+.?d*),") // pcb temp
+ .expression("([^,]+),") // temp
+ .number("(d+),") // movement
+ .number("(d+.d+),") // acceleration
+ .number("(-?d+),") // tilt
+ .number("(d+),") // trip
+ .number("(d+),") // odometer
+ .groupBegin()
+ .number("([01]),") // overspeed
+ .number("[01],") // input 2 misuse
+ .number("[01],") // immobilizer
+ .number("[01],") // temperature alert
+ .number("[0-2]+,") // geofence
+ .number("([0-3]),") // harsh driving
+ .number("[01],") // reconnect
+ .number("([01]),") // low battery
+ .number("([01]),") // power disconnected
+ .number("[01],") // gps failure
+ .number("([01]),") // towing
+ .number("[01],") // server unreachable
+ .number("[128],") // sleep mode
+ .expression("([^,]+)?,") // driver id
+ .number("d+,") // sms count
+ .groupEnd("?")
.any()
.compile();
@@ -68,8 +92,7 @@ public class Ivt401ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
@@ -79,17 +102,79 @@ public class Ivt401ProtocolDecoder extends BaseProtocolDecoder {
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.setCourse(parser.nextInt());
position.setAltitude(parser.nextDouble());
-
- position.set(Position.KEY_SATELLITES, parser.nextInt());
-
position.setValid(parser.nextInt() > 0);
position.set(Position.KEY_RSSI, parser.nextInt());
- position.set(Position.KEY_INPUT, parser.nextBinInt());
- position.set(Position.KEY_OUTPUT, parser.nextBinInt());
+
+ String input = parser.next();
+ for (int i = 0; i < input.length(); i++) {
+ int value = Character.getNumericValue(input.charAt(i));
+ if (value < 2) {
+ position.set(Position.PREFIX_IN + (i + 1), value > 0);
+ }
+ }
+
+ String output = parser.next();
+ for (int i = 0; i < output.length(); i++) {
+ position.set(Position.PREFIX_OUT + (i + 1), Character.getNumericValue(output.charAt(i)) > 0);
+ }
+
position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
position.set(Position.KEY_POWER, parser.nextDouble());
position.set(Position.KEY_BATTERY, parser.nextDouble());
+ position.set(Position.KEY_DEVICE_TEMP, parser.nextDouble());
+
+ String temp = parser.next();
+ if (temp.startsWith("M")) {
+ int index = 1;
+ int startIndex = 1;
+ int endIndex;
+ while (startIndex < temp.length()) {
+ endIndex = temp.indexOf('-', startIndex + 1);
+ if (endIndex < 0) {
+ endIndex = temp.indexOf('+', startIndex + 1);
+ }
+ if (endIndex < 0) {
+ endIndex = temp.length();
+ }
+ if (endIndex > 0) {
+ double value = Double.parseDouble(temp.substring(startIndex, endIndex));
+ position.set(Position.PREFIX_TEMP + index++, value);
+ }
+ startIndex = endIndex;
+ }
+ } else {
+ position.set(Position.PREFIX_TEMP + 1, Double.parseDouble(temp));
+ }
+
+ position.set(Position.KEY_MOTION, parser.nextInt() > 0);
+ position.set(Position.KEY_ACCELERATION, parser.nextDouble());
+
+ parser.nextInt(); // tilt
+ parser.nextInt(); // trip state
+
+ position.set(Position.KEY_ODOMETER, parser.nextLong());
+
+ if (parser.hasNext(6)) {
+ position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_OVERSPEED : null);
+ switch (parser.nextInt()) {
+ case 1:
+ position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ break;
+ case 2:
+ position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ break;
+ case 3:
+ position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
+ break;
+ default:
+ break;
+ }
+ position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_LOW_BATTERY : null);
+ position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_POWER_CUT : null);
+ position.set(Position.KEY_ALARM, parser.nextInt() == 1 ? Position.ALARM_TOW : null);
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
+ }
return position;
}
diff --git a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
index 654b3e3d0..8766115ce 100644
--- a/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
+++ b/src/org/traccar/protocol/JpKorjarProtocolDecoder.java
@@ -60,8 +60,7 @@ public class JpKorjarProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
index e935c1449..f5d8a79a4 100644
--- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java
@@ -73,8 +73,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 1) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -215,8 +214,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setLongitude(parser.nextCoordinate());
@@ -274,8 +272,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder {
String type = parser.next();
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
diff --git a/src/org/traccar/protocol/KenjiProtocolDecoder.java b/src/org/traccar/protocol/KenjiProtocolDecoder.java
index 4216da0c3..374cb9c25 100644
--- a/src/org/traccar/protocol/KenjiProtocolDecoder.java
+++ b/src/org/traccar/protocol/KenjiProtocolDecoder.java
@@ -76,8 +76,7 @@ public class KenjiProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index d63219736..2f29a16f8 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -36,17 +36,10 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
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 b2 = buf.readUnsignedByte() - 0x80;
+ int b3 = buf.readUnsignedByte() - 0x80;
int b4 = buf.readUnsignedByte();
- String serialNumber = String.format("%02d%02d%02d%02d", b1, b2, b3, b4);
- return String.valueOf(Long.parseLong(serialNumber));
+ return String.format("%02d%02d%02d%02d", b1, b2, b3, b4);
}
public static final int MSG_LOGIN = 0xB1;
@@ -71,8 +64,7 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
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());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readSerialNumber(buf));
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/KhdProtocolEncoder.java b/src/org/traccar/protocol/KhdProtocolEncoder.java
index 618e43dad..cb26c757a 100644
--- a/src/org/traccar/protocol/KhdProtocolEncoder.java
+++ b/src/org/traccar/protocol/KhdProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ 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) {
+ private ChannelBuffer encodeCommand(int command, String uniqueId) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
@@ -37,7 +37,12 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder {
buf.writeByte(command);
buf.writeShort(6); // size
- buf.writeInt(0); // terminal id
+ uniqueId = "00000000".concat(uniqueId);
+ uniqueId = uniqueId.substring(uniqueId.length() - 8);
+ buf.writeByte(Integer.parseInt(uniqueId.substring(0, 2)));
+ buf.writeByte(Integer.parseInt(uniqueId.substring(2, 4)) + 0x80);
+ buf.writeByte(Integer.parseInt(uniqueId.substring(4, 6)) + 0x80);
+ buf.writeByte(Integer.parseInt(uniqueId.substring(6, 8)));
buf.writeByte(Checksum.xor(buf.toByteBuffer()));
buf.writeByte(0x0D); // ending
@@ -48,11 +53,13 @@ public class KhdProtocolEncoder extends BaseProtocolEncoder {
@Override
protected Object encodeCommand(Command command) {
+ String uniqueId = getUniqueId(command.getDeviceId());
+
switch (command.getType()) {
case Command.TYPE_ENGINE_STOP:
- return encodeCommand(MSG_CUT_OIL);
+ return encodeCommand(MSG_CUT_OIL, uniqueId);
case Command.TYPE_ENGINE_RESUME:
- return encodeCommand(MSG_RESUME_OIL);
+ return encodeCommand(MSG_RESUME_OIL, uniqueId);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/L100ProtocolDecoder.java b/src/org/traccar/protocol/L100ProtocolDecoder.java
index 618448080..de966d7af 100644
--- a/src/org/traccar/protocol/L100ProtocolDecoder.java
+++ b/src/org/traccar/protocol/L100ProtocolDecoder.java
@@ -83,8 +83,7 @@ public class L100ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/LaipacProtocolDecoder.java b/src/org/traccar/protocol/LaipacProtocolDecoder.java
index 32d4ff0e6..bfaff9ec4 100644
--- a/src/org/traccar/protocol/LaipacProtocolDecoder.java
+++ b/src/org/traccar/protocol/LaipacProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@ import org.traccar.helper.Checksum;
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;
@@ -45,11 +47,45 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
.number("(d+.d+),") // speed
.number("(d+.d+),") // course
.number("(dd)(dd)(dd),") // date (ddmmyy)
- .expression("(.),") // type
- .expression("[^*]+").text("*")
+ .expression("([abZXTSMHFE86430]),") // event code
+ .expression("([\\d.]+),") // battery voltage
+ .number("(d+),") // current mileage
+ .number("(d),") // gps status
+ .number("(d+),") // adc1
+ .number("(d+)") // adc2
+ .number(",(xxxx)") // lac
+ .number("(xxxx),") // cid
+ .number("(ddd)") // mcc
+ .number("(ddd)") // mnc
+ .optional(4)
+ .text("*")
.number("(xx)") // checksum
.compile();
+ private String decodeAlarm(String event) {
+ switch (event) {
+ case "Z":
+ return Position.ALARM_LOW_BATTERY;
+ case "X":
+ return Position.ALARM_GEOFENCE_ENTER;
+ case "T":
+ return Position.ALARM_TAMPERING;
+ case "H":
+ return Position.ALARM_POWER_OFF;
+ case "8":
+ return Position.ALARM_SHOCK;
+ case "7":
+ case "4":
+ return Position.ALARM_GEOFENCE_EXIT;
+ case "6":
+ return Position.ALARM_OVERSPEED;
+ case "3":
+ return Position.ALARM_SOS;
+ default:
+ return null;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -71,8 +107,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -80,6 +115,7 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
String status = parser.next();
position.setValid(status.toUpperCase().equals("A"));
+ position.set(Position.KEY_STATUS, status);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
@@ -89,25 +125,37 @@ public class LaipacProtocolDecoder extends BaseProtocolDecoder {
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
- String type = parser.next();
+ String event = parser.next();
+ position.set(Position.KEY_ALARM, decodeAlarm(event));
+ position.set(Position.KEY_EVENT, event);
+ position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001);
+ position.set(Position.KEY_ODOMETER, parser.nextDouble());
+ position.set(Position.KEY_GPS, parser.nextInt());
+ position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);
+ position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);
+
+ Integer lac = parser.nextHexInt();
+ Integer cid = parser.nextHexInt();
+ Integer mcc = parser.nextInt();
+ Integer mnc = parser.nextInt();
+ if (lac != null && cid != null && mcc != null && mnc != null) {
+ position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
+ }
+
String checksum = parser.next();
if (channel != null) {
-
- if (Character.isLowerCase(status.charAt(0))) {
- String response = "$EAVACK," + type + "," + checksum;
- response += Checksum.nmea(response);
+ if (event.equals("3")) {
+ channel.write("$AVCFG,00000000,d*31\r\n");
+ } else if (event.equals("X") || event.equals("4")) {
+ channel.write("$AVCFG,00000000,x*2D\r\n");
+ } else if (event.equals("Z")) {
+ channel.write("$AVCFG,00000000,z*2F\r\n");
+ } else if (Character.isLowerCase(status.charAt(0))) {
+ String response = "$EAVACK," + event + "," + checksum;
+ response += Checksum.nmea(response) + "\r\n";
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/M2cProtocolDecoder.java b/src/org/traccar/protocol/M2cProtocolDecoder.java
index b0f40a88c..c11136f4c 100644
--- a/src/org/traccar/protocol/M2cProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2cProtocolDecoder.java
@@ -75,8 +75,7 @@ public class M2cProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, parser.nextInt());
diff --git a/src/org/traccar/protocol/M2mProtocolDecoder.java b/src/org/traccar/protocol/M2mProtocolDecoder.java
index a3c2ada2f..b30919865 100644
--- a/src/org/traccar/protocol/M2mProtocolDecoder.java
+++ b/src/org/traccar/protocol/M2mProtocolDecoder.java
@@ -68,8 +68,7 @@ public class M2mProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/MaestroProtocolDecoder.java b/src/org/traccar/protocol/MaestroProtocolDecoder.java
index 7d779a0a0..6068c93b9 100644
--- a/src/org/traccar/protocol/MaestroProtocolDecoder.java
+++ b/src/org/traccar/protocol/MaestroProtocolDecoder.java
@@ -70,8 +70,7 @@ public class MaestroProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(parser.nextInt(0) == 1);
diff --git a/src/org/traccar/protocol/ManPowerProtocolDecoder.java b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
index 6cff8b961..0b1c410c3 100644
--- a/src/org/traccar/protocol/ManPowerProtocolDecoder.java
+++ b/src/org/traccar/protocol/ManPowerProtocolDecoder.java
@@ -57,8 +57,7 @@ public class ManPowerProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index ad0f20a24..14d39e0cc 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -147,8 +147,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
if (!parseLocation(location, position)) {
return null;
}
@@ -251,7 +250,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("(d+),") // mcc
.number("(d+),") // mnc
.number("(xxxx),") // lac
- .number("(xxxx),") // cid
+ .number("(x+),") // cid
.number("(d+)?,") // gsm
.expression("([01]+)?,") // input
.expression("([01]+)?,") // output
@@ -269,7 +268,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
.number("(d+)?,") // rfid
.expression("[^,]*,")
.number("(d+)?,") // battery
- .expression("([^,]*);") // alert
+ .expression("([^,]*)") // alert
.any()
.compile();
@@ -285,8 +284,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.next().equals("S")) {
diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
index 435e2ab14..9f7b8abf7 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java
@@ -346,8 +346,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
String sentence = buf.readBytes(endIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position = decodeRegular(position, sentence);
@@ -403,8 +402,7 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder {
} else {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
if (command == MSG_ALARM) {
short alarmCode = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
index 2e0a1e84c..340d947e3 100644
--- a/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeiligaoProtocolEncoder.java
@@ -19,10 +19,10 @@ 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.DataConverter;
import org.traccar.helper.Log;
import org.traccar.model.Command;
-import javax.xml.bind.DatatypeConverter;
import java.nio.charset.StandardCharsets;
import java.util.TimeZone;
@@ -44,7 +44,7 @@ public class MeiligaoProtocolEncoder extends BaseProtocolEncoder {
buf.writeShort(2 + 2 + 7 + 2 + content.readableBytes() + 2 + 2); // message length
- buf.writeBytes(DatatypeConverter.parseHexBinary((getUniqueId(deviceId) + "FFFFFFFFFFFFFF").substring(0, 14)));
+ buf.writeBytes(DataConverter.parseHex((getUniqueId(deviceId) + "FFFFFFFFFFFFFF").substring(0, 14)));
buf.writeShort(type);
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index b0195d09f..6fee0fd9f 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -126,8 +126,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
@@ -257,7 +256,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
if (values.length > 5 && !values[5].isEmpty()) {
String[] data = values[5].split("\\|");
- boolean started = data[0].charAt(0) == '0';
+ boolean started = data[0].charAt(1) == '0';
position.set("taximeterOn", started);
position.set("taximeterStart", data[1]);
if (data.length > 2) {
@@ -287,8 +286,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() >= 0x34) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
@@ -361,8 +359,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
int count = buf.readUnsignedShort();
for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedShort(); // length
@@ -381,6 +378,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
case 0x06:
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
+ case 0x07:
+ position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ break;
default:
buf.readUnsignedByte();
break;
@@ -400,6 +400,12 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
case 0x0B:
position.setAltitude(buf.readShort());
break;
+ case 0x19:
+ position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
+ break;
+ case 0x1A:
+ position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.01);
+ break;
default:
buf.readUnsignedShort();
break;
@@ -419,6 +425,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
case 0x04:
position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 2000-01-01
break;
+ case 0x0D:
+ position.set("runtime", buf.readUnsignedInt());
+ break;
default:
buf.readUnsignedInt();
break;
@@ -437,9 +446,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
return positions;
}
- private void requestPhotoPacket(Channel channel, String imei, int index) {
+ private void requestPhotoPacket(Channel channel, String imei, String file, int index) {
if (channel != null) {
- String content = "D00,camera_picture.jpg," + index;
+ String content = "D00," + file + "," + 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";
@@ -461,11 +470,14 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
switch (type) {
case "D00":
if (photo == null) {
- return null;
+ photo = ChannelBuffers.dynamicBuffer();
}
- index = buf.indexOf(index + 1 + type.length() + 1, buf.writerIndex(), (byte) ',') + 1;
+ index = index + 1 + type.length() + 1;
int endIndex = buf.indexOf(index, buf.writerIndex(), (byte) ',');
+ String file = buf.toString(index, endIndex - index, StandardCharsets.US_ASCII);
+ index = endIndex + 1;
+ 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) ',');
@@ -475,8 +487,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
photo.writeBytes(buf.readBytes(buf.readableBytes() - 1 - 2 - 2));
if (current == total - 1) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(getDeviceSession(channel, remoteAddress, imei).getDeviceId());
getLastLocation(position, null);
@@ -487,13 +498,13 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
return position;
} else {
if ((current + 1) % 8 == 0) {
- requestPhotoPacket(channel, imei, current + 1);
+ requestPhotoPacket(channel, imei, file, current + 1);
}
return null;
}
case "D03":
photo = ChannelBuffers.dynamicBuffer();
- requestPhotoPacket(channel, imei, 0);
+ requestPhotoPacket(channel, imei, "camera_picture.jpg", 0);
return null;
case "CCC":
return decodeBinaryC(channel, remoteAddress, buf);
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
index b10a751c1..f73d74de9 100644
--- a/src/org/traccar/protocol/MeitrackProtocolEncoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,7 +49,8 @@ public class MeitrackProtocolEncoder extends StringProtocolEncoder {
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");
+ int index = command.getInteger(Command.KEY_INDEX);
+ return formatCommand(command, 'D', "D03," + (index > 0 ? index : 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));
diff --git a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
index 8e6e56e80..ab046eca3 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolDecoder.java
@@ -146,8 +146,7 @@ public class MiniFinderProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
String type = sentence.substring(1, 2);
diff --git a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
index 486f406a5..d3f49b4e4 100644
--- a/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
+++ b/src/org/traccar/protocol/MiniFinderProtocolEncoder.java
@@ -25,25 +25,25 @@ public class MiniFinderProtocolEncoder extends StringProtocolEncoder implements
@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;
- }
+ switch (key) {
+ case Command.KEY_ENABLE:
+ return (Boolean) value ? "1" : "0";
+ case Command.KEY_TIMEZONE:
+ return String.format("%+03d", TimeZone.getTimeZone((String) value).getRawOffset() / 3600000);
+ case Command.KEY_INDEX:
+ switch (((Number) value).intValue()) {
+ case 0:
+ return "A";
+ case 1:
+ return "B";
+ case 2:
+ return "C";
+ default:
+ return null;
+ }
+ default:
+ return null;
}
-
- return null;
}
@Override
diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
index 0fda94eef..c26e00c56 100644
--- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java
@@ -120,8 +120,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
try {
while (buf.readable()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
short flags = buf.readUnsignedByte();
@@ -200,9 +199,8 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder {
}
private Position parseFormatA1(DeviceSession deviceSession, ChannelBuffer buf) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
short flags = buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/MtxProtocolDecoder.java b/src/org/traccar/protocol/MtxProtocolDecoder.java
index d7b572670..412eac493 100644
--- a/src/org/traccar/protocol/MtxProtocolDecoder.java
+++ b/src/org/traccar/protocol/MtxProtocolDecoder.java
@@ -68,8 +68,7 @@ public class MtxProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java
index 6d82e4a4b..9fe1924c0 100644
--- a/src/org/traccar/protocol/MxtProtocolDecoder.java
+++ b/src/org/traccar/protocol/MxtProtocolDecoder.java
@@ -82,8 +82,7 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_POSITION) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // protocol
diff --git a/src/org/traccar/protocol/NavigilProtocolDecoder.java b/src/org/traccar/protocol/NavigilProtocolDecoder.java
index 360b9c81c..4f3b4ad74 100644
--- a/src/org/traccar/protocol/NavigilProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavigilProtocolDecoder.java
@@ -81,8 +81,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private Position parseUnitReport(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setValid(true);
position.set(Position.KEY_INDEX, sequenceNumber);
@@ -116,8 +115,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private Position parseTg2Report(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setValid(true);
position.set(Position.KEY_INDEX, sequenceNumber);
@@ -154,8 +152,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private Position parsePositionReport(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
@@ -177,8 +174,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private Position parsePositionReport2(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
@@ -202,8 +198,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private Position parseSnapshot4(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
@@ -241,8 +236,7 @@ public class NavigilProtocolDecoder extends BaseProtocolDecoder {
private Position parseTrackingData(
DeviceSession deviceSession, ChannelBuffer buf, int sequenceNumber, long timestamp) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, sequenceNumber);
position.setDeviceId(deviceSession.getDeviceId());
diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java
index 8d4e367ab..6881fb8ed 100644
--- a/src/org/traccar/protocol/NavisProtocolDecoder.java
+++ b/src/org/traccar/protocol/NavisProtocolDecoder.java
@@ -76,8 +76,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder {
}
private ParseResult parsePosition(DeviceSession deviceSession, ChannelBuffer buf) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index 990f50484..e10332ece 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -80,8 +80,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
newFormat = true;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
if (type == MSG_CONTROL_RESPONSE) {
buf.readUnsignedInt(); // GIS ip
diff --git a/src/org/traccar/protocol/NvsProtocolDecoder.java b/src/org/traccar/protocol/NvsProtocolDecoder.java
index 0e82fae69..db8347d3c 100644
--- a/src/org/traccar/protocol/NvsProtocolDecoder.java
+++ b/src/org/traccar/protocol/NvsProtocolDecoder.java
@@ -76,8 +76,7 @@ public class NvsProtocolDecoder extends BaseProtocolDecoder {
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
index e5ae5e93f..5310c90fd 100644
--- a/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
+++ b/src/org/traccar/protocol/ObdDongleProtocolDecoder.java
@@ -91,8 +91,7 @@ public class ObdDongleProtocolDecoder extends BaseProtocolDecoder {
buf.readUnsignedByte(); // event id
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/OigoProtocolDecoder.java b/src/org/traccar/protocol/OigoProtocolDecoder.java
index 54360c932..2874d0455 100644
--- a/src/org/traccar/protocol/OigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/OigoProtocolDecoder.java
@@ -68,8 +68,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
@@ -178,8 +177,7 @@ public class OigoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.skipBytes(8); // imsi
diff --git a/src/org/traccar/protocol/OkoProtocolDecoder.java b/src/org/traccar/protocol/OkoProtocolDecoder.java
index e86acf0b8..0ebe63ca3 100644
--- a/src/org/traccar/protocol/OkoProtocolDecoder.java
+++ b/src/org/traccar/protocol/OkoProtocolDecoder.java
@@ -72,8 +72,7 @@ public class OkoProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/OpenGtsProtocol.java b/src/org/traccar/protocol/OpenGtsProtocol.java
new file mode 100644
index 000000000..a0246ba1b
--- /dev/null
+++ b/src/org/traccar/protocol/OpenGtsProtocol.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 OpenGtsProtocol extends BaseProtocol {
+
+ public OpenGtsProtocol() {
+ super("opengts");
+ }
+
+ @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 OpenGtsProtocolDecoder(OpenGtsProtocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/OpenGtsProtocolDecoder.java b/src/org/traccar/protocol/OpenGtsProtocolDecoder.java
new file mode 100644
index 000000000..ba8f434d8
--- /dev/null
+++ b/src/org/traccar/protocol/OpenGtsProtocolDecoder.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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.HttpRequest;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+import org.jboss.netty.handler.codec.http.QueryStringDecoder;
+import org.traccar.BaseHttpProtocolDecoder;
+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.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+public class OpenGtsProtocolDecoder extends BaseHttpProtocolDecoder {
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("$GPRMC,")
+ .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+.d+),") // course
+ .number("(dd)(dd)(dd),") // date (ddmmyy)
+ .any()
+ .compile();
+
+ public OpenGtsProtocolDecoder(OpenGtsProtocol protocol) {
+ super(protocol);
+ }
+
+ @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();
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ for (Map.Entry<String, List<String>> entry : params.entrySet()) {
+ String value = entry.getValue().get(0);
+ switch (entry.getKey()) {
+ case "id":
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, value);
+ if (deviceSession == null) {
+ sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+ break;
+ case "gprmc":
+ Parser parser = new Parser(PATTERN, value);
+ if (!parser.matches()) {
+ sendResponse(channel, HttpResponseStatus.BAD_REQUEST);
+ 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());
+ break;
+ case "alt":
+ position.setAltitude(Double.parseDouble(value));
+ break;
+ case "batt":
+ position.set(Position.KEY_BATTERY_LEVEL, Double.parseDouble(value));
+ break;
+ default:
+ break;
+ }
+ }
+
+ 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/OrionProtocolDecoder.java b/src/org/traccar/protocol/OrionProtocolDecoder.java
index c65924337..ada864fba 100644
--- a/src/org/traccar/protocol/OrionProtocolDecoder.java
+++ b/src/org/traccar/protocol/OrionProtocolDecoder.java
@@ -79,9 +79,8 @@ public class OrionProtocolDecoder extends BaseProtocolDecoder {
for (int i = 0; i < (header & 0x0f); i++) {
- Position position = new Position();
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setProtocol(getProtocolName());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
buf.readUnsignedByte(); // length
diff --git a/src/org/traccar/protocol/OsmAndProtocolDecoder.java b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
index 61855311a..03abdd588 100644
--- a/src/org/traccar/protocol/OsmAndProtocolDecoder.java
+++ b/src/org/traccar/protocol/OsmAndProtocolDecoder.java
@@ -53,8 +53,7 @@ public class OsmAndProtocolDecoder extends BaseHttpProtocolDecoder {
params = decoder.getParameters();
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setValid(true);
Network network = new Network();
diff --git a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
index 49d1cff96..120995dfb 100644
--- a/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
+++ b/src/org/traccar/protocol/OwnTracksProtocolDecoder.java
@@ -50,8 +50,7 @@ public class OwnTracksProtocolDecoder extends BaseHttpProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setValid(true);
position.setLatitude(root.getJsonNumber("lat").doubleValue());
diff --git a/src/org/traccar/protocol/PathAwayProtocolDecoder.java b/src/org/traccar/protocol/PathAwayProtocolDecoder.java
index 1c4531612..845a5e892 100644
--- a/src/org/traccar/protocol/PathAwayProtocolDecoder.java
+++ b/src/org/traccar/protocol/PathAwayProtocolDecoder.java
@@ -72,8 +72,7 @@ public class PathAwayProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
diff --git a/src/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
index 9d5bb9e24..f2ec16c59 100644
--- a/src/org/traccar/protocol/PiligrimProtocolDecoder.java
+++ b/src/org/traccar/protocol/PiligrimProtocolDecoder.java
@@ -97,8 +97,7 @@ public class PiligrimProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_GPS || type == MSG_GPS_SENSORS) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/PretraceProtocolDecoder.java b/src/org/traccar/protocol/PretraceProtocolDecoder.java
index 77d94068f..24d707a1c 100644
--- a/src/org/traccar/protocol/PretraceProtocolDecoder.java
+++ b/src/org/traccar/protocol/PretraceProtocolDecoder.java
@@ -71,8 +71,7 @@ public class PretraceProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(parser.next().equals("A"));
diff --git a/src/org/traccar/protocol/PricolProtocolDecoder.java b/src/org/traccar/protocol/PricolProtocolDecoder.java
index a33e19b90..577665dcc 100644
--- a/src/org/traccar/protocol/PricolProtocolDecoder.java
+++ b/src/org/traccar/protocol/PricolProtocolDecoder.java
@@ -47,8 +47,7 @@ public class PricolProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set("eventType", buf.readUnsignedByte());
diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java
index 1820ea926..d85b6acb3 100644
--- a/src/org/traccar/protocol/ProgressProtocolDecoder.java
+++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java
@@ -96,8 +96,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder {
}
for (int j = 0; j < recordCount; j++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (type == MSG_LOGMSG) {
diff --git a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
index c36be7976..f4540afe8 100644
--- a/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt3000ProtocolDecoder.java
@@ -56,8 +56,7 @@ public class Pt3000ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Pt502FrameDecoder.java b/src/org/traccar/protocol/Pt502FrameDecoder.java
index 252c8dd02..4d3e9b4d5 100644
--- a/src/org/traccar/protocol/Pt502FrameDecoder.java
+++ b/src/org/traccar/protocol/Pt502FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2014 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ 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 Pt502FrameDecoder extends FrameDecoder {
private static final int BINARY_HEADER = 5;
@@ -28,26 +30,41 @@ public class Pt502FrameDecoder extends FrameDecoder {
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
- if (buf.readableBytes() < BINARY_HEADER) {
+ if (buf.readableBytes() < 10) {
return null;
}
- if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
- buf.skipBytes(BINARY_HEADER);
- }
+ if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf
+ && buf.toString(buf.readerIndex() + BINARY_HEADER, 4, StandardCharsets.US_ASCII).equals("$PHD")) {
- int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
- if (index < 0) {
- index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\n');
- }
+ int length = buf.getUnsignedShort(buf.readerIndex() + 3);
+ if (buf.readableBytes() >= length) {
+ buf.skipBytes(BINARY_HEADER);
+ ChannelBuffer result = buf.readBytes(length - BINARY_HEADER - 2);
+ buf.skipBytes(2); // line break
+ return result;
+ }
+
+ } else {
- 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);
+ if (buf.getUnsignedByte(buf.readerIndex()) == 0xbf) {
+ buf.skipBytes(BINARY_HEADER);
}
- return result;
+
+ 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
index 0116422c2..f7d0d04a2 100644
--- a/src/org/traccar/protocol/Pt502Protocol.java
+++ b/src/org/traccar/protocol/Pt502Protocol.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ 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;
@@ -45,7 +44,6 @@ public class Pt502Protocol extends BaseProtocol {
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));
}
diff --git a/src/org/traccar/protocol/Pt502ProtocolDecoder.java b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
index 330ba7643..76e7ee1bf 100644
--- a/src/org/traccar/protocol/Pt502ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Pt502ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
* Copyright 2012 Luis Parada (luis.parada@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,11 @@
*/
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;
@@ -25,13 +28,14 @@ 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 Pt502ProtocolDecoder extends BaseProtocolDecoder {
private static final int MAX_CHUNK_SIZE = 960;
- private byte[] photo;
+ private ChannelBuffer photo;
public Pt502ProtocolDecoder(Pt502Protocol protocol) {
super(protocol);
@@ -85,26 +89,15 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
}
}
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ private Position decodePosition(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN, (String) msg);
+ Parser parser = new Parser(PATTERN, sentence);
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));
+ Position position = new Position(getProtocolName());
+ position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
@@ -147,4 +140,71 @@ public class Pt502ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private void requestPhotoFragment(Channel channel) {
+ if (channel != null) {
+ int offset = photo.writerIndex();
+ int size = Math.min(photo.writableBytes(), MAX_CHUNK_SIZE);
+ channel.write("#PHD" + offset + "," + size + "\r\n");
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ int typeEndIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
+ String type = buf.toString(buf.readerIndex(), typeEndIndex - buf.readerIndex(), StandardCharsets.US_ASCII);
+
+ if (type.startsWith("$PHD")) {
+
+ int dataIndex = buf.indexOf(typeEndIndex + 1, buf.writerIndex(), (byte) ',') + 1;
+ buf.readerIndex(dataIndex);
+
+ if (photo != null) {
+
+ photo.writeBytes(buf.readBytes(buf.readableBytes()));
+
+ if (photo.writableBytes() > 0) {
+
+ requestPhotoFragment(channel);
+
+ } else {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ String uniqueId = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getUniqueId();
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ getLastLocation(position, null);
+
+ position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(uniqueId, photo, "jpg"));
+
+ photo = null;
+
+ return position;
+
+ }
+
+ }
+
+ } else {
+
+ if (type.startsWith("$PHO")) {
+ int size = Integer.parseInt(type.split("-")[0].substring(4));
+ if (size > 0) {
+ photo = ChannelBuffers.buffer(size);
+ requestPhotoFragment(channel);
+ }
+ }
+
+ return decodePosition(channel, remoteAddress, buf.toString(StandardCharsets.US_ASCII));
+
+ }
+
+ return null;
+ }
+
}
diff --git a/src/org/traccar/protocol/Pt60Protocol.java b/src/org/traccar/protocol/Pt60Protocol.java
new file mode 100644
index 000000000..857790efd
--- /dev/null
+++ b/src/org/traccar/protocol/Pt60Protocol.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 Pt60Protocol extends BaseProtocol {
+
+ public Pt60Protocol() {
+ super("pt60");
+ }
+
+ @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 Pt60ProtocolDecoder(Pt60Protocol.this));
+ }
+ });
+ }
+
+}
diff --git a/src/org/traccar/protocol/Pt60ProtocolDecoder.java b/src/org/traccar/protocol/Pt60ProtocolDecoder.java
new file mode 100644
index 000000000..c87c22c5f
--- /dev/null
+++ b/src/org/traccar/protocol/Pt60ProtocolDecoder.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.regex.Pattern;
+
+public class Pt60ProtocolDecoder extends BaseProtocolDecoder {
+
+ public Pt60ProtocolDecoder(Pt60Protocol protocol) {
+ super(protocol);
+ }
+
+ private static final Pattern PATTERN = new PatternBuilder()
+ .text("@G#@,") // header
+ .number("Vdd,") // protocol version
+ .number("d,") // type
+ .number("(d+),") // imei
+ .number("(d+),") // imsi
+ .number("(dddd)(dd)(dd)") // date (yyyymmdd)
+ .number("(dd)(dd)(dd),") // time (hhmmss)
+ .number("(-?d+.d+);") // latitude
+ .number("(-?d+.d+),") // longitude
+ .compile();
+
+ private void sendResponse(Channel channel) {
+ if (channel != null) {
+ DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
+ channel.write("@G#@,V01,38," + dateFormat.format(new Date()) + ",@R#@");
+ }
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ sendResponse(channel);
+
+ Parser parser = new Parser(PATTERN, (String) msg);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), parser.next());
+ if (deviceSession == null) {
+ return null;
+ }
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setValid(true);
+ position.setTime(parser.nextDateTime());
+ position.setLatitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+
+ return position;
+ }
+
+}
diff --git a/src/org/traccar/protocol/RaveonProtocolDecoder.java b/src/org/traccar/protocol/RaveonProtocolDecoder.java
index cbe6026a2..ac52493ad 100644
--- a/src/org/traccar/protocol/RaveonProtocolDecoder.java
+++ b/src/org/traccar/protocol/RaveonProtocolDecoder.java
@@ -68,8 +68,7 @@ public class RaveonProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
diff --git a/src/org/traccar/protocol/RecodaProtocolDecoder.java b/src/org/traccar/protocol/RecodaProtocolDecoder.java
index 8db582d35..7bd4d3dae 100644
--- a/src/org/traccar/protocol/RecodaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RecodaProtocolDecoder.java
@@ -64,8 +64,7 @@ public class RecodaProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readLong()));
diff --git a/src/org/traccar/protocol/RitiProtocolDecoder.java b/src/org/traccar/protocol/RitiProtocolDecoder.java
index 5c298e8c5..637867908 100644
--- a/src/org/traccar/protocol/RitiProtocolDecoder.java
+++ b/src/org/traccar/protocol/RitiProtocolDecoder.java
@@ -56,8 +56,7 @@ public class RitiProtocolDecoder extends BaseProtocolDecoder {
buf.skipBytes(2); // header
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/RoboTrackFrameDecoder.java b/src/org/traccar/protocol/RoboTrackFrameDecoder.java
new file mode 100644
index 000000000..af215103c
--- /dev/null
+++ b/src/org/traccar/protocol/RoboTrackFrameDecoder.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 RoboTrackFrameDecoder extends FrameDecoder {
+
+ private int messageLength(ChannelBuffer buf) {
+ switch ((int) buf.getByte(buf.readerIndex())) {
+ case RoboTrackProtocolDecoder.MSG_ID:
+ return 69;
+ case RoboTrackProtocolDecoder.MSG_ACK:
+ return 3;
+ case RoboTrackProtocolDecoder.MSG_GPS:
+ case RoboTrackProtocolDecoder.MSG_GSM:
+ case RoboTrackProtocolDecoder.MSG_IMAGE_START:
+ return 24;
+ case RoboTrackProtocolDecoder.MSG_IMAGE_DATA:
+ return 8 + buf.getUnsignedShort(buf.readerIndex() + 1);
+ case RoboTrackProtocolDecoder.MSG_IMAGE_END:
+ return 6;
+ default:
+ return Integer.MAX_VALUE;
+ }
+ }
+
+ @Override
+ protected Object decode(
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
+
+ int length = messageLength(buf);
+
+ if (buf.readableBytes() >= length) {
+ return buf.readBytes(length);
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/RoboTrackProtocol.java b/src/org/traccar/protocol/RoboTrackProtocol.java
new file mode 100644
index 000000000..382cb1c2f
--- /dev/null
+++ b/src/org/traccar/protocol/RoboTrackProtocol.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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 RoboTrackProtocol extends BaseProtocol {
+
+ public RoboTrackProtocol() {
+ super("robotrack");
+ }
+
+ @Override
+ public void initTrackerServers(List<TrackerServer> serverList) {
+ TrackerServer server = new TrackerServer(new ServerBootstrap(), getName()) {
+ @Override
+ protected void addSpecificHandlers(ChannelPipeline pipeline) {
+ pipeline.addLast("frameDecoder", new RoboTrackFrameDecoder());
+ pipeline.addLast("objectDecoder", new RoboTrackProtocolDecoder(RoboTrackProtocol.this));
+ }
+ };
+ server.setEndianness(ByteOrder.LITTLE_ENDIAN);
+ serverList.add(server);
+ }
+
+}
diff --git a/src/org/traccar/protocol/RoboTrackProtocolDecoder.java b/src/org/traccar/protocol/RoboTrackProtocolDecoder.java
new file mode 100644
index 000000000..4f27fb08e
--- /dev/null
+++ b/src/org/traccar/protocol/RoboTrackProtocolDecoder.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 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.nio.ByteOrder;
+import java.nio.charset.StandardCharsets;
+import java.util.Date;
+
+public class RoboTrackProtocolDecoder extends BaseProtocolDecoder {
+
+ public RoboTrackProtocolDecoder(RoboTrackProtocol protocol) {
+ super(protocol);
+ }
+
+ public static final int MSG_ID = 0x00;
+ public static final int MSG_ACK = 0x80;
+ public static final int MSG_GPS = 0x03;
+ public static final int MSG_GSM = 0x04;
+ public static final int MSG_IMAGE_START = 0x06;
+ public static final int MSG_IMAGE_DATA = 0x07;
+ public static final int MSG_IMAGE_END = 0x08;
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ ChannelBuffer buf = (ChannelBuffer) msg;
+
+ int type = buf.readUnsignedByte();
+
+ if (type == MSG_ID) {
+
+ buf.skipBytes(16); // name
+
+ String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
+
+ if (getDeviceSession(channel, remoteAddress, imei) != null && channel != null) {
+ ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 0);
+ response.writeByte(MSG_ACK);
+ response.writeByte(0x01); // success
+ response.writeByte(0x66); // checksum
+ channel.write(response);
+ }
+
+ } else if (type == MSG_GPS || type == MSG_GSM) {
+
+ DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
+ if (deviceSession == null) {
+ return null;
+ }
+
+ Position position = new Position(getProtocolName());
+ position.setDeviceId(deviceSession.getDeviceId());
+
+ position.setDeviceTime(new Date(buf.readUnsignedInt() * 1000));
+
+ if (type == MSG_GPS) {
+
+ position.setValid(true);
+ position.setFixTime(position.getDeviceTime());
+ position.setLatitude(buf.readInt() * 0.000001);
+ position.setLongitude(buf.readInt() * 0.000001);
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readByte()));
+
+ } else {
+
+ getLastLocation(position, position.getDeviceTime());
+
+ position.setNetwork(new Network(CellTower.from(
+ buf.readUnsignedShort(), buf.readUnsignedShort(),
+ buf.readUnsignedShort(), buf.readUnsignedShort())));
+
+ buf.readUnsignedByte(); // reserved
+
+ }
+
+ int value = buf.readUnsignedByte();
+
+ position.set(Position.KEY_SATELLITES, BitUtil.to(value, 4));
+ position.set(Position.KEY_RSSI, BitUtil.between(value, 4, 7));
+ position.set(Position.KEY_MOTION, BitUtil.check(value, 7));
+
+ value = buf.readUnsignedByte();
+
+ position.set(Position.KEY_CHARGE, BitUtil.check(value, 0));
+
+ for (int i = 1; i <= 4; i++) {
+ position.set(Position.PREFIX_IN + i, BitUtil.check(value, i));
+ }
+
+ position.set(Position.KEY_BATTERY_LEVEL, BitUtil.from(value, 5) * 100 / 7);
+ position.set(Position.KEY_DEVICE_TEMP, buf.readByte());
+
+ for (int i = 1; i <= 3; i++) {
+ position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
+ }
+
+ return position;
+
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/RuptelaProtocolDecoder.java b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
index 8752d30c0..7b11cc5c3 100644
--- a/src/org/traccar/protocol/RuptelaProtocolDecoder.java
+++ b/src/org/traccar/protocol/RuptelaProtocolDecoder.java
@@ -20,10 +20,10 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.DataConverter;
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;
@@ -49,8 +49,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
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 position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
@@ -135,8 +134,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
@@ -198,7 +196,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
}
if (channel != null) {
- channel.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary("0002640113bc")));
+ channel.write(ChannelBuffers.wrappedBuffer(DataConverter.parseHex("0002640113bc")));
}
return positions;
@@ -210,8 +208,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // reserved
@@ -232,7 +229,7 @@ public class RuptelaProtocolDecoder extends BaseProtocolDecoder {
}
if (channel != null) {
- channel.write(ChannelBuffers.wrappedBuffer(DatatypeConverter.parseHexBinary("00026d01c4a4")));
+ channel.write(ChannelBuffers.wrappedBuffer(DataConverter.parseHex("00026d01c4a4")));
}
return positions;
diff --git a/src/org/traccar/protocol/SanavProtocolDecoder.java b/src/org/traccar/protocol/SanavProtocolDecoder.java
index 151c55795..714bb15d5 100644
--- a/src/org/traccar/protocol/SanavProtocolDecoder.java
+++ b/src/org/traccar/protocol/SanavProtocolDecoder.java
@@ -59,8 +59,7 @@ public class SanavProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/SigfoxProtocolDecoder.java b/src/org/traccar/protocol/SigfoxProtocolDecoder.java
index 7cf57681f..b454e00fa 100644
--- a/src/org/traccar/protocol/SigfoxProtocolDecoder.java
+++ b/src/org/traccar/protocol/SigfoxProtocolDecoder.java
@@ -22,12 +22,12 @@ import org.jboss.netty.handler.codec.http.HttpRequest;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.traccar.BaseHttpProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.DataConverter;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Position;
import javax.json.Json;
import javax.json.JsonObject;
-import javax.xml.bind.DatatypeConverter;
import java.io.StringReader;
import java.net.SocketAddress;
import java.net.URLDecoder;
@@ -55,14 +55,13 @@ public class SigfoxProtocolDecoder extends BaseHttpProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(json.getInt("time") * 1000L));
ChannelBuffer buf = ChannelBuffers.wrappedBuffer(
- ByteOrder.LITTLE_ENDIAN, DatatypeConverter.parseHexBinary(json.getString("data")));
+ ByteOrder.LITTLE_ENDIAN, DataConverter.parseHex(json.getString("data")));
int type = buf.readUnsignedByte() >> 4;
if (type == 0) {
diff --git a/src/org/traccar/protocol/SiwiProtocolDecoder.java b/src/org/traccar/protocol/SiwiProtocolDecoder.java
index 198df24d5..66b6465fa 100644
--- a/src/org/traccar/protocol/SiwiProtocolDecoder.java
+++ b/src/org/traccar/protocol/SiwiProtocolDecoder.java
@@ -70,8 +70,7 @@ public class SiwiProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, parser.next());
diff --git a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
index f4dded972..a85595a07 100644
--- a/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
+++ b/src/org/traccar/protocol/SkypatrolProtocolDecoder.java
@@ -67,8 +67,7 @@ public class SkypatrolProtocolDecoder extends BaseProtocolDecoder {
// Binary position report
if (apiNumber == 5 && commandType == 2 && messageType == 1 && BitUtil.check(mask, 0)) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
if (BitUtil.check(mask, 1)) {
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
diff --git a/src/org/traccar/protocol/SmokeyProtocolDecoder.java b/src/org/traccar/protocol/SmokeyProtocolDecoder.java
index 2dcfeb86f..9c4cb4e21 100644
--- a/src/org/traccar/protocol/SmokeyProtocolDecoder.java
+++ b/src/org/traccar/protocol/SmokeyProtocolDecoder.java
@@ -84,8 +84,7 @@ public class SmokeyProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_DATE_RECORD) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_FW, buf.readUnsignedShort());
diff --git a/src/org/traccar/protocol/SpotProtocolDecoder.java b/src/org/traccar/protocol/SpotProtocolDecoder.java
index ed6a03c5f..a8e666a32 100644
--- a/src/org/traccar/protocol/SpotProtocolDecoder.java
+++ b/src/org/traccar/protocol/SpotProtocolDecoder.java
@@ -72,8 +72,7 @@ public class SpotProtocolDecoder extends BaseHttpProtocolDecoder {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, xPath.evaluate("esnName", node));
if (deviceSession != null) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
@@ -81,6 +80,8 @@ public class SpotProtocolDecoder extends BaseHttpProtocolDecoder {
position.setLatitude(Double.parseDouble(xPath.evaluate("latitude", node)));
position.setLongitude(Double.parseDouble(xPath.evaluate("longitude", node)));
+ position.set(Position.KEY_EVENT, xPath.evaluate("messageType", node));
+
positions.add(position);
}
diff --git a/src/org/traccar/protocol/StarLinkProtocolDecoder.java b/src/org/traccar/protocol/StarLinkProtocolDecoder.java
index 79f013fac..f2c9d2c50 100644
--- a/src/org/traccar/protocol/StarLinkProtocolDecoder.java
+++ b/src/org/traccar/protocol/StarLinkProtocolDecoder.java
@@ -111,8 +111,7 @@ public class StarLinkProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
diff --git a/src/org/traccar/protocol/Stl060ProtocolDecoder.java b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
index 26817a5c8..64d4655c5 100644
--- a/src/org/traccar/protocol/Stl060ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Stl060ProtocolDecoder.java
@@ -75,8 +75,7 @@ public class Stl060ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/SuntechProtocolDecoder.java b/src/org/traccar/protocol/SuntechProtocolDecoder.java
index 6dfc6f77f..b739e699b 100644
--- a/src/org/traccar/protocol/SuntechProtocolDecoder.java
+++ b/src/org/traccar/protocol/SuntechProtocolDecoder.java
@@ -21,6 +21,8 @@ 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;
@@ -76,8 +78,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (type.equals("Emergency") || type.equals("Alert")) {
@@ -157,7 +158,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
}
}
- private Position decode235(
+ private Position decode2356(
Channel channel, SocketAddress remoteAddress, String protocol, String[] values) throws ParseException {
int index = 0;
@@ -172,12 +173,11 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_TYPE, type);
- if (protocol.equals("ST300") || protocol.equals("ST500")) {
+ if (protocol.equals("ST300") || protocol.equals("ST500") || protocol.equals("ST600")) {
index += 1; // model
}
@@ -188,7 +188,12 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
position.setTime(dateFormat.parse(values[index++] + values[index++]));
if (!protocol.equals("ST500")) {
- index += 1; // cell
+ int cid = Integer.parseInt(values[index++], 16);
+ if (protocol.equals("ST600")) {
+ position.setNetwork(new Network(CellTower.from(
+ Integer.parseInt(values[index++]), Integer.parseInt(values[index++]),
+ Integer.parseInt(values[index++], 16), cid, Integer.parseInt(values[index++]))));
+ }
}
position.setLatitude(Double.parseDouble(values[index++]));
@@ -289,8 +294,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_TYPE, type);
@@ -372,7 +376,7 @@ public class SuntechProtocolDecoder extends BaseProtocolDecoder {
} else if (values[0].equals("ST910")) {
return decode9(channel, remoteAddress, values);
} else {
- return decode235(channel, remoteAddress, values[0].substring(0, 5), values);
+ return decode2356(channel, remoteAddress, values[0].substring(0, 5), values);
}
}
diff --git a/src/org/traccar/protocol/SupermateProtocolDecoder.java b/src/org/traccar/protocol/SupermateProtocolDecoder.java
index d9b58a7f4..be325ea29 100644
--- a/src/org/traccar/protocol/SupermateProtocolDecoder.java
+++ b/src/org/traccar/protocol/SupermateProtocolDecoder.java
@@ -65,8 +65,7 @@ public class SupermateProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
String imei = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java
index bfddf74ac..be3cb5f67 100644
--- a/src/org/traccar/protocol/T55ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T55ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,8 +110,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
if (deviceSession != null) {
position.setDeviceId(deviceSession.getDeviceId());
@@ -165,8 +164,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -188,8 +186,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date());
@@ -209,8 +206,7 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime());
@@ -254,9 +250,11 @@ public class T55ProtocolDecoder extends BaseProtocolDecoder {
} 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()));
+ getDeviceSession(channel, remoteAddress, sentence.substring(5));
+ } else if (sentence.startsWith("$IMEI")) {
+ getDeviceSession(channel, remoteAddress, sentence.substring(6));
} else if (sentence.startsWith("$GPFID")) {
- deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(7, sentence.length()));
+ deviceSession = getDeviceSession(channel, remoteAddress, sentence.substring(7));
if (deviceSession != null && position != null) {
Position position = this.position;
position.setDeviceId(deviceSession.getDeviceId());
diff --git a/src/org/traccar/protocol/T57ProtocolDecoder.java b/src/org/traccar/protocol/T57ProtocolDecoder.java
index db5f94cbb..65dfc46e3 100644
--- a/src/org/traccar/protocol/T57ProtocolDecoder.java
+++ b/src/org/traccar/protocol/T57ProtocolDecoder.java
@@ -63,8 +63,7 @@ public class T57ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
diff --git a/src/org/traccar/protocol/T800xProtocolDecoder.java b/src/org/traccar/protocol/T800xProtocolDecoder.java
index 6430b1344..1fd37864e 100644
--- a/src/org/traccar/protocol/T800xProtocolDecoder.java
+++ b/src/org/traccar/protocol/T800xProtocolDecoder.java
@@ -105,8 +105,7 @@ public class T800xProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_GPS || type == MSG_ALARM) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
diff --git a/src/org/traccar/protocol/T800xProtocolEncoder.java b/src/org/traccar/protocol/T800xProtocolEncoder.java
index 6ed5dbccd..038a5e51a 100644
--- a/src/org/traccar/protocol/T800xProtocolEncoder.java
+++ b/src/org/traccar/protocol/T800xProtocolEncoder.java
@@ -18,10 +18,10 @@ package org.traccar.protocol;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.traccar.BaseProtocolEncoder;
+import org.traccar.helper.DataConverter;
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 {
@@ -39,7 +39,7 @@ public class T800xProtocolEncoder extends BaseProtocolEncoder {
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.writeBytes(DataConverter.parseHex("0" + getUniqueId(command.getDeviceId())));
buf.writeByte(MODE_SETTING);
buf.writeBytes(content.getBytes(StandardCharsets.US_ASCII));
diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java
index e7117a5c9..a7aa9dd96 100644
--- a/src/org/traccar/protocol/TaipProtocolDecoder.java
+++ b/src/org/traccar/protocol/TaipProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
.groupEnd("?")
.number("(d{5})") // seconds
.or()
- .expression("(?:RGP|RCQ|RBR)") // type
+ .expression("(?:RGP|RCQ|RCV|RBR)") // type
.number("(dd)?") // event
.number("(dd)(dd)(dd)") // date (mmddyy)
.number("(dd)(dd)(dd)") // time (hhmmss)
@@ -62,12 +62,33 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
.number("(ddd)") // speed
.number("(ddd)") // course
.groupBegin()
+ .number("([023])") // fix mode
+ .number("xx") // data age
+ .number("(xx)") // input
+ .number("(dd)") // event
+ .number("(dd)") // hdop
+ .or()
+ .groupBegin()
.number("(xx)") // input
.number("(xx)") // satellites
.number("(ddd)") // battery
.number("(x{8})") // odometer
.number("[01]") // gps power
+ .groupBegin()
+ .number("([023])") // fix mode
+ .number("(dd)") // pdop
+ .number("dd") // satellites
+ .number("xxxx") // data age
+ .number("[01]") // modem power
+ .number("[0-5]") // gsm status
+ .number("(dd)") // rssi
+ .number("([-+]dddd)") // temperature 1
+ .number("xx") // seconds from last
+ .number("([-+]dddd)") // temperature 2
+ .number("xx") // seconds from last
+ .groupEnd("?")
.groupEnd("?")
+ .groupEnd()
.any()
.compile();
@@ -101,9 +122,9 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
+ Boolean valid = null;
Integer event = null;
if (parser.hasNext(3)) {
@@ -117,27 +138,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
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));
}
@@ -155,13 +155,51 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
position.setCourse(parser.nextDouble(0));
if (parser.hasNext(4)) {
+ valid = parser.nextInt() > 0;
+ int input = parser.nextHexInt();
+ position.set(Position.KEY_IGNITION, BitUtil.check(input, 7));
+ position.set(Position.KEY_INPUT, input);
+ event = parser.nextInt();
+ position.set(Position.KEY_HDOP, parser.nextInt());
+ }
+
+ 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);
+ if (parser.hasNext(4)) {
+ valid = parser.nextInt() > 0;
+ position.set(Position.KEY_PDOP, parser.nextInt());
+ position.set(Position.KEY_RSSI, parser.nextInt());
+ position.set(Position.PREFIX_TEMP + 1, parser.nextInt() * 0.01);
+ position.set(Position.PREFIX_TEMP + 2, parser.nextInt() * 0.01);
+ }
+
+ position.setValid(valid != null ? valid : true);
+
+ if (event != null) {
+ position.set(Position.KEY_EVENT, event);
+ 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:
+ break;
+ }
+ }
String[] attributes = null;
beginIndex = sentence.indexOf(';');
@@ -231,14 +269,13 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder {
if (deviceSession != null) {
if (channel != null) {
if (messageIndex != null) {
- String response = ">ACK;" + messageIndex + ";ID=" + uniqueId + ";*";
+ String response = ">ACK;ID=" + uniqueId + ";" + messageIndex + ";*";
response += String.format("%02X", Checksum.xor(response)) + "<";
channel.write(response, remoteAddress);
} else {
channel.write(uniqueId, remoteAddress);
}
}
-
return position;
}
diff --git a/src/org/traccar/protocol/TelicProtocolDecoder.java b/src/org/traccar/protocol/TelicProtocolDecoder.java
index 2c0d714c6..197db059b 100644
--- a/src/org/traccar/protocol/TelicProtocolDecoder.java
+++ b/src/org/traccar/protocol/TelicProtocolDecoder.java
@@ -87,8 +87,7 @@ public class TelicProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 80f0045d5..d2069e6c9 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
public static final int CODEC_GH3000 = 0x07;
public static final int CODEC_FM4X00 = 0x08;
public static final int CODEC_12 = 0x0C;
+ public static final int CODEC_16 = 0x10;
private void decodeSerial(Position position, ChannelBuffer buf) {
@@ -132,7 +133,10 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
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)));
+ long driverUniqueId = readValue(buf, length, false);
+ if (driverUniqueId != 0) {
+ position.set(Position.KEY_DRIVER_UNIQUE_ID, String.format("%016X", driverUniqueId));
+ }
break;
case 80:
position.set("workMode", readValue(buf, length, false));
@@ -344,7 +348,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
// Read 8 byte data
- if (codec == CODEC_FM4X00) {
+ if (codec == CODEC_FM4X00 || codec == CODEC_16) {
int cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
decodeOtherParameter(position, buf.readUnsignedByte(), buf, 8);
@@ -381,8 +385,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
for (int i = 0; i < count; i++) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
diff --git a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
index 4a97fa1a1..f7dd18f51 100644
--- a/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
+++ b/src/org/traccar/protocol/ThinkRaceProtocolDecoder.java
@@ -87,8 +87,7 @@ public class ThinkRaceProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date(buf.readUnsignedInt() * 1000));
diff --git a/src/org/traccar/protocol/Tk102ProtocolDecoder.java b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
index 41d5b7436..50dd45676 100644
--- a/src/org/traccar/protocol/Tk102ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk102ProtocolDecoder.java
@@ -117,8 +117,7 @@ public class Tk102ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/Tk103Protocol.java b/src/org/traccar/protocol/Tk103Protocol.java
index 6ef9c0a56..e23982c74 100644
--- a/src/org/traccar/protocol/Tk103Protocol.java
+++ b/src/org/traccar/protocol/Tk103Protocol.java
@@ -47,7 +47,8 @@ public class Tk103Protocol extends BaseProtocol {
Command.TYPE_REBOOT_DEVICE,
Command.TYPE_SET_ODOMETER,
Command.TYPE_ENGINE_STOP,
- Command.TYPE_ENGINE_RESUME);
+ Command.TYPE_ENGINE_RESUME,
+ Command.TYPE_OUTPUT_CONTROL);
}
@Override
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index eda29e3f8..22a73469f 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -228,8 +228,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
@@ -263,8 +262,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
@@ -286,8 +284,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
decodeType(position, parser.next(), "0");
@@ -331,8 +328,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
@@ -380,8 +376,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
boolean alternative = parser.next() != null;
diff --git a/src/org/traccar/protocol/Tk103ProtocolEncoder.java b/src/org/traccar/protocol/Tk103ProtocolEncoder.java
index 946f3ad73..3ec562cc3 100644
--- a/src/org/traccar/protocol/Tk103ProtocolEncoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolEncoder.java
@@ -97,6 +97,8 @@ public class Tk103ProtocolEncoder extends StringProtocolEncoder {
return formatCommand(command, "({%s}AV010)", Command.KEY_UNIQUE_ID);
case Command.TYPE_ENGINE_RESUME:
return formatCommand(command, "({%s}AV011)", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_OUTPUT_CONTROL:
+ return formatCommand(command, "({%s}AV00{%s})", Command.KEY_UNIQUE_ID, Command.KEY_DATA);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
return null;
diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
index cbc851de0..a5a195afa 100644
--- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java
@@ -57,6 +57,45 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private void decodeStatus(Position position, String status) {
+ switch (status) {
+ case "AUTOSTART":
+ case "AUTO":
+ position.set(Position.KEY_IGNITION, true);
+ break;
+ case "AUTOSTOP":
+ case "AUTOLOW":
+ position.set(Position.KEY_IGNITION, false);
+ break;
+ case "TOWED":
+ position.set(Position.KEY_ALARM, Position.ALARM_TOW);
+ break;
+ case "SOS":
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ break;
+ case "DEF":
+ position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ break;
+ case "BLP":
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ break;
+ case "CLP":
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ break;
+ case "OS":
+ position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_EXIT);
+ break;
+ case "RS":
+ position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE_ENTER);
+ break;
+ case "OVERSPEED":
+ position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ break;
+ default:
+ break;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -84,8 +123,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
parser = new Parser(PATTERN_POSITION, message);
if (parser.matches()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
parser.next(); // base station info
@@ -102,7 +140,7 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder {
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
- position.set(Position.KEY_STATUS, status);
+ decodeStatus(position, status);
positions.add(position);
}
diff --git a/src/org/traccar/protocol/TlvProtocolDecoder.java b/src/org/traccar/protocol/TlvProtocolDecoder.java
index 41d65be09..0cf68acb8 100644
--- a/src/org/traccar/protocol/TlvProtocolDecoder.java
+++ b/src/org/traccar/protocol/TlvProtocolDecoder.java
@@ -83,8 +83,7 @@ public class TlvProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
diff --git a/src/org/traccar/protocol/TmgFrameDecoder.java b/src/org/traccar/protocol/TmgFrameDecoder.java
index 549c42466..c39cf03ac 100644
--- a/src/org/traccar/protocol/TmgFrameDecoder.java
+++ b/src/org/traccar/protocol/TmgFrameDecoder.java
@@ -37,13 +37,10 @@ public class TmgFrameDecoder extends FrameDecoder {
if (buffer.getByte(guessedIndex) != (byte) '$' || buffer.writerIndex() - guessedIndex < 5) {
return false;
}
- if (buffer.getByte(guessedIndex + 4) == ','
+ return buffer.getByte(guessedIndex + 4) == ','
&& isLetter(buffer.getByte(guessedIndex + 1))
&& isLetter(buffer.getByte(guessedIndex + 2))
- && isLetter(buffer.getByte(guessedIndex + 3))) {
- return true;
- }
- return false;
+ && isLetter(buffer.getByte(guessedIndex + 3));
}
});
diff --git a/src/org/traccar/protocol/TmgProtocolDecoder.java b/src/org/traccar/protocol/TmgProtocolDecoder.java
index 4a3055932..cb10eedd7 100644
--- a/src/org/traccar/protocol/TmgProtocolDecoder.java
+++ b/src/org/traccar/protocol/TmgProtocolDecoder.java
@@ -99,8 +99,7 @@ public class TmgProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
switch (type) {
diff --git a/src/org/traccar/protocol/TopflytechProtocolDecoder.java b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
index 837ca2557..b3a8fa845 100644
--- a/src/org/traccar/protocol/TopflytechProtocolDecoder.java
+++ b/src/org/traccar/protocol/TopflytechProtocolDecoder.java
@@ -53,8 +53,7 @@ public class TopflytechProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index a3e8c9921..5a2c203d2 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.traccar.protocol;
import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
@@ -131,7 +132,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
private static final Pattern PATTERN4 = new PatternBuilder()
.text("$$") // header
.number("dddd") // length
- .expression("A[ABC]") // type
+ .number("(xx)") // type
.number("(d+)|") // imei
.number("(x{8})") // status
.number("(dd)(dd)(dd)") // date (yymmdd)
@@ -163,7 +164,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
- private String decodeAlarm(Short value) {
+ private String decodeAlarm123(int value) {
switch (value) {
case 0x01:
return Position.ALARM_SOS;
@@ -182,10 +183,31 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
}
}
+ private String decodeAlarm4(int value) {
+ switch (value) {
+ case 0x01:
+ return Position.ALARM_SOS;
+ case 0x02:
+ return Position.ALARM_OVERSPEED;
+ case 0x04:
+ return Position.ALARM_GEOFENCE_EXIT;
+ case 0x05:
+ return Position.ALARM_GEOFENCE_ENTER;
+ case 0x40:
+ return Position.ALARM_SHOCK;
+ case 0x42:
+ return Position.ALARM_ACCELERATION;
+ case 0x43:
+ return Position.ALARM_BRAKING;
+ 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)));
+ position.set(Position.KEY_ALARM, decodeAlarm123(Short.parseShort(parser.next(), 16)));
}
DateBuilder dateBuilder = new DateBuilder();
int year = 0, month = 0, day = 0;
@@ -221,12 +243,23 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_HDOP, parser.nextDouble());
}
- position.set(Position.PREFIX_IO + 1, parser.next());
+ int io = parser.nextBinInt();
if (pattern == PATTERN1) {
+ for (int i = 1; i <= 4; i++) {
+ position.set(Position.PREFIX_IN + i, BitUtil.check(io, 3 + i));
+ }
position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.01);
} else {
+ position.set(Position.KEY_ANTENNA, BitUtil.check(io, 0));
+ position.set(Position.KEY_CHARGE, BitUtil.check(io, 1));
+ for (int i = 1; i <= 6; i++) {
+ position.set(Position.PREFIX_IN + i, BitUtil.check(io, 1 + i));
+ }
position.set(Position.KEY_BATTERY, parser.nextDouble(0) * 0.1);
}
+ for (int i = 1; i <= 4; i++) {
+ position.set(Position.PREFIX_OUT + i, BitUtil.check(io, 7 + i));
+ }
position.set(Position.KEY_POWER, parser.nextDouble(0));
position.set(Position.PREFIX_ADC + 1, parser.next());
@@ -245,7 +278,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
private boolean decode3(Position position, Parser parser) {
if (parser.hasNext()) {
- position.set(Position.KEY_ALARM, decodeAlarm(Short.parseShort(parser.next(), 16)));
+ position.set(Position.KEY_ALARM, decodeAlarm123(Short.parseShort(parser.next(), 16)));
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
@@ -276,7 +309,26 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
private boolean decode4(Position position, Parser parser) {
- position.set(Position.KEY_STATUS, parser.next());
+ long status = parser.nextHexLong();
+
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 1) ? Position.ALARM_SOS : null);
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 32 - 2));
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 3) ? Position.ALARM_OVERSPEED : null);
+ position.set(Position.KEY_CHARGE, BitUtil.check(status, 32 - 4));
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 5) ? Position.ALARM_GEOFENCE_EXIT : null);
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 6) ? Position.ALARM_GEOFENCE_ENTER : null);
+ position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 32 - 9));
+ position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 32 - 10));
+ position.set(Position.PREFIX_OUT + 3, BitUtil.check(status, 32 - 11));
+ position.set(Position.PREFIX_OUT + 4, BitUtil.check(status, 32 - 12));
+ position.set(Position.PREFIX_IN + 2, BitUtil.check(status, 32 - 13));
+ position.set(Position.PREFIX_IN + 3, BitUtil.check(status, 32 - 14));
+ position.set(Position.PREFIX_IN + 4, BitUtil.check(status, 32 - 15));
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 16) ? Position.ALARM_SHOCK : null);
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 18) ? Position.ALARM_LOW_BATTERY : null);
+ position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 22) ? Position.ALARM_JAMMING : null);
+
+ position.setValid(BitUtil.check(status, 32 - 20));
position.setTime(parser.nextDateTime());
@@ -300,7 +352,6 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
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());
@@ -329,8 +380,11 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
+
+ if (pattern == PATTERN4) {
+ position.set(Position.KEY_ALARM, decodeAlarm4(parser.nextHexInt()));
+ }
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Tr20ProtocolDecoder.java b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
index 403a2fda2..579d575b0 100644
--- a/src/org/traccar/protocol/Tr20ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr20ProtocolDecoder.java
@@ -70,8 +70,7 @@ public class Tr20ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Tr900ProtocolDecoder.java b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
index 7dbdc5697..0ce4158e4 100644
--- a/src/org/traccar/protocol/Tr900ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tr900ProtocolDecoder.java
@@ -63,8 +63,7 @@ public class Tr900ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/TrackboxProtocolDecoder.java b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
index 7e542af93..2c113fb76 100644
--- a/src/org/traccar/protocol/TrackboxProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrackboxProtocolDecoder.java
@@ -77,8 +77,7 @@ public class TrackboxProtocolDecoder extends BaseProtocolDecoder {
}
sendResponse(channel);
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/TrakMateProtocolDecoder.java b/src/org/traccar/protocol/TrakMateProtocolDecoder.java
index 8965a18b4..293c13fad 100644
--- a/src/org/traccar/protocol/TrakMateProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrakMateProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * 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.
@@ -17,23 +17,18 @@ 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()
@@ -112,8 +107,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setLatitude(parser.nextDouble(0));
@@ -139,8 +133,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
parser.next(); // seq
@@ -170,8 +163,7 @@ public class TrakMateProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
parser.next(); // seq
diff --git a/src/org/traccar/protocol/TramigoProtocolDecoder.java b/src/org/traccar/protocol/TramigoProtocolDecoder.java
index b1e28e17d..2605346a9 100644
--- a/src/org/traccar/protocol/TramigoProtocolDecoder.java
+++ b/src/org/traccar/protocol/TramigoProtocolDecoder.java
@@ -61,8 +61,7 @@ public class TramigoProtocolDecoder extends BaseProtocolDecoder {
long id = buf.readUnsignedInt();
buf.readUnsignedInt(); // time
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.set(Position.KEY_INDEX, index);
position.setValid(true);
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java
index 918748f7b..e0cebc9a5 100644
--- a/src/org/traccar/protocol/TrvProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrvProtocolDecoder.java
@@ -144,8 +144,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
@@ -167,8 +166,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
diff --git a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
index 5e30d0994..0134f4764 100644
--- a/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tt8850ProtocolDecoder.java
@@ -69,8 +69,7 @@ public class Tt8850ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index de0330250..a65ad4cfc 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -146,8 +146,7 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
while (buf.readableBytes() > 2) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int end = buf.readerIndex() + buf.readUnsignedByte();
diff --git a/src/org/traccar/protocol/TzoneProtocolDecoder.java b/src/org/traccar/protocol/TzoneProtocolDecoder.java
index 079ad3126..984891bb6 100644
--- a/src/org/traccar/protocol/TzoneProtocolDecoder.java
+++ b/src/org/traccar/protocol/TzoneProtocolDecoder.java
@@ -128,8 +128,7 @@ public class TzoneProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_HW, hardware);
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index 31a3d2cfe..5499518a1 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ 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;
@@ -39,11 +38,8 @@ 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;
@@ -188,8 +184,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
@@ -216,13 +211,16 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ if (deviceSession.getTimeZone() == null) {
+ deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId()));
+ }
+
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
long seconds = buf.readUnsignedInt() & 0x7fffffffL;
seconds += 946684800L; // 2000-01-01 00:00
- seconds -= timeZone;
+ seconds -= deviceSession.getTimeZone().getRawOffset() / 1000;
Date time = new Date(seconds * 1000);
boolean hasLocation = false;
diff --git a/src/org/traccar/protocol/UproProtocolDecoder.java b/src/org/traccar/protocol/UproProtocolDecoder.java
index 7a0dca8a2..28f3d0249 100644
--- a/src/org/traccar/protocol/UproProtocolDecoder.java
+++ b/src/org/traccar/protocol/UproProtocolDecoder.java
@@ -116,8 +116,7 @@ public class UproProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
String type = parser.next();
diff --git a/src/org/traccar/protocol/V680ProtocolDecoder.java b/src/org/traccar/protocol/V680ProtocolDecoder.java
index 079a8eb08..caa06a863 100644
--- a/src/org/traccar/protocol/V680ProtocolDecoder.java
+++ b/src/org/traccar/protocol/V680ProtocolDecoder.java
@@ -70,8 +70,7 @@ public class V680ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession;
if (parser.hasNext()) {
diff --git a/src/org/traccar/protocol/VisiontekProtocolDecoder.java b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
index f32c9fbfe..33c555c6b 100644
--- a/src/org/traccar/protocol/VisiontekProtocolDecoder.java
+++ b/src/org/traccar/protocol/VisiontekProtocolDecoder.java
@@ -81,8 +81,7 @@ public class VisiontekProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Vt200ProtocolDecoder.java b/src/org/traccar/protocol/Vt200ProtocolDecoder.java
index 2ae24efbb..d08107b16 100644
--- a/src/org/traccar/protocol/Vt200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Vt200ProtocolDecoder.java
@@ -68,8 +68,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder {
if (type == 0x2086 || type == 0x2084 || type == 0x2082) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
buf.readUnsignedByte(); // data type
@@ -85,7 +84,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder {
if (!BitUtil.check(flags, 1)) {
position.setLatitude(-position.getLatitude());
}
- if (!BitUtil.check(flags, 1)) {
+ if (!BitUtil.check(flags, 2)) {
position.setLongitude(-position.getLongitude());
}
@@ -103,8 +102,7 @@ public class Vt200ProtocolDecoder extends BaseProtocolDecoder {
} else if (type == 0x3088) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
diff --git a/src/org/traccar/protocol/VtfmsProtocolDecoder.java b/src/org/traccar/protocol/VtfmsProtocolDecoder.java
index 5fb687e6d..dc2171022 100644
--- a/src/org/traccar/protocol/VtfmsProtocolDecoder.java
+++ b/src/org/traccar/protocol/VtfmsProtocolDecoder.java
@@ -106,8 +106,7 @@ public class VtfmsProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_ALARM, decodeAlarm(parser.nextInt()));
diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java
index 826a8b4d0..0009ef30f 100644
--- a/src/org/traccar/protocol/WatchFrameDecoder.java
+++ b/src/org/traccar/protocol/WatchFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,47 +25,66 @@ 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);
+ int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') + 1;
+ if (idIndex <= 0) {
+ return null;
+ }
+
+ int lengthIndex = buf.indexOf(idIndex, buf.writerIndex(), (byte) '*') + 1;
+ if (lengthIndex <= 0) {
+ return null;
+ }
+
+ int payloadIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*');
+ if (payloadIndex < 0) {
+ return null;
+ }
+
+ if (payloadIndex + 5 < buf.writerIndex() && buf.getByte(payloadIndex + 5) == '*'
+ && buf.toString(payloadIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
+ lengthIndex = payloadIndex + 1;
+ payloadIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*');
+ if (payloadIndex < 0) {
+ return null;
+ }
+ }
+
+ int length = Integer.parseInt(
+ buf.toString(lengthIndex, payloadIndex - lengthIndex, StandardCharsets.US_ASCII), 16);
+ if (buf.readableBytes() >= payloadIndex + 1 + length + 1) {
+ ChannelBuffer frame = ChannelBuffers.dynamicBuffer();
+ int endIndex = buf.readerIndex() + payloadIndex + 1 + length + 1;
+ 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 frame;
}
return null;
diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java
index 86dc9456d..b58c3b6a1 100644
--- a/src/org/traccar/protocol/WatchProtocolDecoder.java
+++ b/src/org/traccar/protocol/WatchProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.expression("([NS]),")
.number(" *(-?d+.d+),") // longitude
.expression("([EW])?,")
- .number("(d+.d+),") // speed
+ .number("(d+.?d*),") // speed
.number("(d+.?d*),") // course
.number("(d+.?d*),") // altitude
.number("(d+),") // satellites
@@ -60,10 +60,15 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
.expression("(.*)") // cell and wifi
.compile();
- private void sendResponse(Channel channel, String manufacturer, String id, String content) {
+ private void sendResponse(Channel channel, String id, String index, String content) {
if (channel != null) {
- channel.write(String.format(
- "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
+ if (index != null) {
+ channel.write(String.format(
+ "[%s*%s*%s*%04x*%s]", manufacturer, id, index, content.length(), content));
+ } else {
+ channel.write(String.format(
+ "[%s*%s*%04x*%s]", manufacturer, id, content.length(), content));
+ }
}
}
@@ -92,8 +97,38 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- private void decodeTail(Position position, String data) {
- String[] values = data.split(",");
+ private Position decodePosition(DeviceSession deviceSession, String data) {
+
+ Parser parser = new Parser(PATTERN_POSITION, data);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position(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);
+ }
+
+ String[] values = parser.next().split(",");
int index = 0;
Network network = new Network();
@@ -122,6 +157,19 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
+
+ return position;
+ }
+
+ private boolean hasIndex;
+ private String manufacturer;
+
+ public boolean getHasIndex() {
+ return hasIndex;
+ }
+
+ public String getManufacturer() {
+ return manufacturer;
}
@Override
@@ -131,22 +179,34 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.skipBytes(1); // header
- String manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
+ manufacturer = buf.readBytes(2).toString(StandardCharsets.US_ASCII);
buf.skipBytes(1); // delimiter
- String id = buf.readBytes(10).toString(StandardCharsets.US_ASCII);
+ int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ String id = buf.readBytes(idIndex - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
buf.skipBytes(1); // delimiter
+
+ String index = null;
+ int contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
+ if (contentIndex + 5 < buf.writerIndex() && buf.getByte(contentIndex + 5) == '*'
+ && buf.toString(contentIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) {
+ int indexLength = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') - buf.readerIndex();
+ hasIndex = true;
+ index = buf.readBytes(indexLength).toString(StandardCharsets.US_ASCII);
+ 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) ',');
+ contentIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
if (contentIndex < 0) {
contentIndex = buf.writerIndex();
}
@@ -157,15 +217,18 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
buf.readerIndex(contentIndex + 1);
}
- if (type.equals("LK")) {
+ if (type.equals("INIT")) {
+
+ sendResponse(channel, id, index, "INIT,1");
+
+ } else if (type.equals("LK")) {
- sendResponse(channel, manufacturer, id, "LK");
+ sendResponse(channel, id, index, "LK");
if (buf.readable()) {
String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
if (values.length >= 3) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
@@ -179,62 +242,38 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
} 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 position = decodePosition(deviceSession, buf.toString(StandardCharsets.US_ASCII));
- 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);
+ if (type.equals("AL")) {
+ if (position != null) {
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ }
+ sendResponse(channel, id, index, "AL");
}
- decodeTail(position, parser.next());
-
return position;
} else if (type.equals("TKQ")) {
- sendResponse(channel, manufacturer, id, "TKQ");
+ sendResponse(channel, id, index, "TKQ");
- } else if (type.equals("PULSE") || type.equals("heart")) {
+ } else if (type.equals("PULSE") || type.equals("heart") || type.equals("bphrt")) {
if (buf.readable()) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(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);
+ String[] values = buf.toString(StandardCharsets.US_ASCII).split(",");
+ int valueIndex = 0;
+
+ if (type.equals("bphrt")) {
+ position.set("pressureHigh", values[valueIndex++]);
+ position.set("pressureLow", values[valueIndex++]);
+ }
+ position.set("pulse", values[valueIndex]);
return position;
@@ -242,8 +281,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
} else if (type.equals("img")) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
@@ -256,8 +294,7 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder {
} else if (type.equals("TK")) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
diff --git a/src/org/traccar/protocol/WatchProtocolEncoder.java b/src/org/traccar/protocol/WatchProtocolEncoder.java
index d2d3b52d1..4c87f3abd 100644
--- a/src/org/traccar/protocol/WatchProtocolEncoder.java
+++ b/src/org/traccar/protocol/WatchProtocolEncoder.java
@@ -15,11 +15,12 @@
*/
package org.traccar.protocol;
+import org.jboss.netty.channel.Channel;
import org.traccar.StringProtocolEncoder;
+import org.traccar.helper.DataConverter;
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;
@@ -41,12 +42,27 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin
return null;
}
+ protected String formatCommand(Channel channel, Command command, String format, String... keys) {
+
+ boolean hasIndex = false;
+ String manufacturer = "CS";
+ if (channel != null) {
+ WatchProtocolDecoder decoder = channel.getPipeline().get(WatchProtocolDecoder.class);
+ if (decoder != null) {
+ hasIndex = decoder.getHasIndex();
+ manufacturer = decoder.getManufacturer();
+ }
+ }
- @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);
+
+ if (hasIndex) {
+ return String.format("[%s*%s*0001*%04x*%s]",
+ manufacturer, getUniqueId(command.getDeviceId()), content.length(), content);
+ } else {
+ return String.format("[%s*%s*%04x*%s]",
+ manufacturer, getUniqueId(command.getDeviceId()), content.length(), content);
+ }
}
private int getEnableFlag(Command command) {
@@ -68,7 +84,7 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin
}
private String getBinaryData(Command command) {
- byte[] data = DatatypeConverter.parseHexBinary(command.getString(Command.KEY_DATA));
+ byte[] data = DataConverter.parseHex(command.getString(Command.KEY_DATA));
int encodedLength = data.length;
for (byte b : data) {
@@ -96,37 +112,37 @@ public class WatchProtocolEncoder extends StringProtocolEncoder implements Strin
}
@Override
- protected Object encodeCommand(Command command) {
+ protected Object encodeCommand(Channel channel, Command command) {
switch (command.getType()) {
case Command.TYPE_CUSTOM:
- return formatCommand(command, command.getString(Command.KEY_DATA));
+ return formatCommand(channel, command, command.getString(Command.KEY_DATA));
case Command.TYPE_POSITION_SINGLE:
- return formatCommand(command, "RG");
+ return formatCommand(channel, command, "RG");
case Command.TYPE_SOS_NUMBER:
- return formatCommand(command, "SOS{%s},{%s}", Command.KEY_INDEX, Command.KEY_PHONE);
+ return formatCommand(channel, command, "SOS{%s},{%s}", Command.KEY_INDEX, Command.KEY_PHONE);
case Command.TYPE_ALARM_SOS:
- return formatCommand(command, "SOSSMS," + getEnableFlag(command));
+ return formatCommand(channel, command, "SOSSMS," + getEnableFlag(command));
case Command.TYPE_ALARM_BATTERY:
- return formatCommand(command, "LOWBAT," + getEnableFlag(command));
+ return formatCommand(channel, command, "LOWBAT," + getEnableFlag(command));
case Command.TYPE_REBOOT_DEVICE:
- return formatCommand(command, "RESET");
+ return formatCommand(channel, command, "RESET");
case Command.TYPE_ALARM_REMOVE:
- return formatCommand(command, "REMOVE," + getEnableFlag(command));
+ return formatCommand(channel, command, "REMOVE," + getEnableFlag(command));
case Command.TYPE_SILENCE_TIME:
- return formatCommand(command, "SILENCETIME,{%s}", Command.KEY_DATA);
+ return formatCommand(channel, command, "SILENCETIME,{%s}", Command.KEY_DATA);
case Command.TYPE_ALARM_CLOCK:
- return formatCommand(command, "REMIND,{%s}", Command.KEY_DATA);
+ return formatCommand(channel, command, "REMIND,{%s}", Command.KEY_DATA);
case Command.TYPE_SET_PHONEBOOK:
- return formatCommand(command, "PHB,{%s}", Command.KEY_DATA);
+ return formatCommand(channel, command, "PHB,{%s}", Command.KEY_DATA);
case Command.TYPE_VOICE_MESSAGE:
- return formatCommand(command, "TK," + getBinaryData(command));
+ return formatCommand(channel, command, "TK," + getBinaryData(command));
case Command.TYPE_POSITION_PERIODIC:
- return formatCommand(command, "UPLOAD,{%s}", Command.KEY_FREQUENCY);
+ return formatCommand(channel, command, "UPLOAD,{%s}", Command.KEY_FREQUENCY);
case Command.TYPE_SET_TIMEZONE:
- return formatCommand(command, "LZ,,{%s}", Command.KEY_TIMEZONE);
+ return formatCommand(channel, command, "LZ,,{%s}", Command.KEY_TIMEZONE);
case Command.TYPE_SET_INDICATOR:
- return formatCommand(command, "FLOWER,{%s}", Command.KEY_DATA);
+ return formatCommand(channel, command, "FLOWER,{%s}", Command.KEY_DATA);
default:
Log.warning(new UnsupportedOperationException(command.getType()));
break;
diff --git a/src/org/traccar/protocol/WialonProtocolDecoder.java b/src/org/traccar/protocol/WialonProtocolDecoder.java
index 4eb3b9b8e..5bc3e9972 100644
--- a/src/org/traccar/protocol/WialonProtocolDecoder.java
+++ b/src/org/traccar/protocol/WialonProtocolDecoder.java
@@ -80,8 +80,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
@@ -179,8 +178,7 @@ public class WialonProtocolDecoder extends BaseProtocolDecoder {
} else if (sentence.startsWith("#M#")) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession != null) {
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, new Date());
position.setValid(false);
diff --git a/src/org/traccar/protocol/WondexProtocolDecoder.java b/src/org/traccar/protocol/WondexProtocolDecoder.java
index e27745f38..a0fa436e4 100644
--- a/src/org/traccar/protocol/WondexProtocolDecoder.java
+++ b/src/org/traccar/protocol/WondexProtocolDecoder.java
@@ -70,17 +70,17 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
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:")) {
+ || buf.toString(StandardCharsets.US_ASCII).startsWith("$MSG:")) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(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));
@@ -88,8 +88,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
@@ -120,6 +119,7 @@ public class WondexProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_OUTPUT, parser.next());
return position;
+
}
}
diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java
index bb4b4f48c..a06a86021 100644
--- a/src/org/traccar/protocol/XexunProtocolDecoder.java
+++ b/src/org/traccar/protocol/XexunProtocolDecoder.java
@@ -106,8 +106,7 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
if (full) {
position.set("serial", parser.next());
diff --git a/src/org/traccar/protocol/XirgoProtocolDecoder.java b/src/org/traccar/protocol/XirgoProtocolDecoder.java
index b1442170d..461503af1 100644
--- a/src/org/traccar/protocol/XirgoProtocolDecoder.java
+++ b/src/org/traccar/protocol/XirgoProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,6 +95,71 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
.any()
.compile();
+ private void decodeEvent(Position position, int event) {
+
+ position.set(Position.KEY_EVENT, event);
+
+ switch (event) {
+ case 4001:
+ case 4003:
+ case 6011:
+ case 6013:
+ position.set(Position.KEY_IGNITION, true);
+ break;
+ case 4002:
+ case 4004:
+ case 6012:
+ case 6014:
+ position.set(Position.KEY_IGNITION, false);
+ break;
+ case 4005:
+ position.set(Position.KEY_CHARGE, false);
+ break;
+ case 6002:
+ position.set(Position.KEY_ALARM, Position.ALARM_OVERSPEED);
+ break;
+ case 6006:
+ position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ break;
+ case 6007:
+ position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ break;
+ case 6008:
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
+ break;
+ case 6009:
+ position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
+ break;
+ case 6010:
+ position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
+ break;
+ case 6016:
+ position.set(Position.KEY_ALARM, Position.ALARM_IDLE);
+ break;
+ case 6017:
+ position.set(Position.KEY_ALARM, Position.ALARM_TOW);
+ break;
+ case 6030:
+ case 6071:
+ position.set(Position.KEY_MOTION, true);
+ break;
+ case 6031:
+ position.set(Position.KEY_MOTION, false);
+ break;
+ case 6032:
+ position.set(Position.KEY_ALARM, Position.ALARM_PARKING);
+ break;
+ case 6090:
+ position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
+ break;
+ case 6091:
+ position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
+ break;
+ default:
+ break;
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -125,8 +190,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
}
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
@@ -134,7 +198,7 @@ public class XirgoProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(deviceSession.getDeviceId());
- position.set(Position.KEY_EVENT, parser.next());
+ decodeEvent(position, parser.nextInt());
position.setTime(parser.nextDateTime());
diff --git a/src/org/traccar/protocol/Xt013ProtocolDecoder.java b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
index f1214fdb4..a92afd778 100644
--- a/src/org/traccar/protocol/Xt013ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt013ProtocolDecoder.java
@@ -65,8 +65,7 @@ public class Xt013ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
diff --git a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
index 15e8558be..1be943e98 100644
--- a/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Xt2400ProtocolDecoder.java
@@ -20,10 +20,10 @@ import org.jboss.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.Context;
import org.traccar.DeviceSession;
+import org.traccar.helper.DataConverter;
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;
@@ -95,7 +95,7 @@ public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
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)));
+ formats.put(Short.parseShort(matcher.group(1), 16), DataConverter.parseHex(matcher.group(2)));
}
}
@@ -116,11 +116,10 @@ public class Xt2400ProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
for (byte tag : format) {
- switch ((int) tag) {
+ switch (tag) {
case 0x03:
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java
index 6a98ab9e7..3182b838d 100644
--- a/src/org/traccar/protocol/YwtProtocolDecoder.java
+++ b/src/org/traccar/protocol/YwtProtocolDecoder.java
@@ -76,8 +76,7 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder {
return null;
}
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ Position position = new Position(getProtocolName());
String type = parser.next();
diff --git a/src/org/traccar/reports/Events.java b/src/org/traccar/reports/Events.java
index a13aeeeb4..66d9e708d 100644
--- a/src/org/traccar/reports/Events.java
+++ b/src/org/traccar/reports/Events.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2018 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.
@@ -33,6 +33,7 @@ import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Group;
+import org.traccar.model.Maintenance;
import org.traccar.reports.model.DeviceReport;
public final class Events {
@@ -51,7 +52,10 @@ public final class Events {
for (Event event : events) {
if (all || types.contains(event.getType())) {
long geofenceId = event.getGeofenceId();
- if (geofenceId == 0 || Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) {
+ long maintenanceId = event.getMaintenanceId();
+ if ((geofenceId == 0 || Context.getGeofenceManager().checkItemPermission(userId, geofenceId))
+ && (maintenanceId == 0
+ || Context.getMaintenancesManager().checkItemPermission(userId, maintenanceId))) {
result.add(event);
}
}
@@ -67,6 +71,7 @@ public final class Events {
ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
HashMap<Long, String> geofenceNames = new HashMap<>();
+ HashMap<Long, String> maintenanceNames = new HashMap<>();
for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
@@ -75,15 +80,25 @@ public final class Events {
Event event = iterator.next();
if (all || types.contains(event.getType())) {
long geofenceId = event.getGeofenceId();
+ long maintenanceId = event.getMaintenanceId();
if (geofenceId != 0) {
if (Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) {
- Geofence geofence = (Geofence) Context.getGeofenceManager().getById(geofenceId);
+ Geofence geofence = Context.getGeofenceManager().getById(geofenceId);
if (geofence != null) {
geofenceNames.put(geofenceId, geofence.getName());
}
} else {
iterator.remove();
}
+ } else if (maintenanceId != 0) {
+ if (Context.getMaintenancesManager().checkItemPermission(userId, maintenanceId)) {
+ Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId);
+ if (maintenance != null) {
+ maintenanceNames.put(maintenanceId, maintenance.getName());
+ }
+ } else {
+ iterator.remove();
+ }
}
} else {
iterator.remove();
@@ -109,6 +124,7 @@ public final class Events {
jxlsContext.putVar("devices", devicesEvents);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("geofenceNames", geofenceNames);
+ jxlsContext.putVar("maintenanceNames", maintenanceNames);
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
index 14b3a2437..aa7a1ef20 100644
--- a/src/org/traccar/reports/Stops.java
+++ b/src/org/traccar/reports/Stops.java
@@ -42,11 +42,9 @@ public final class Stops {
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
- Collection<StopReport> result = ReportUtils.detectTripsAndStops(
+ return ReportUtils.detectTripsAndStops(
Context.getDataManager().getPositions(deviceId, from, to),
Context.getTripsConfig(), ignoreOdometer, StopReport.class);
-
- return result;
}
public static Collection<StopReport> getObjects(
diff --git a/src/org/traccar/reports/Trips.java b/src/org/traccar/reports/Trips.java
index 696defa94..792833c27 100644
--- a/src/org/traccar/reports/Trips.java
+++ b/src/org/traccar/reports/Trips.java
@@ -41,11 +41,9 @@ public final class Trips {
boolean ignoreOdometer = Context.getDeviceManager()
.lookupAttributeBoolean(deviceId, "report.ignoreOdometer", false, true);
- Collection<TripReport> result = ReportUtils.detectTripsAndStops(
+ return 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,
diff --git a/src/org/traccar/reports/model/StopReport.java b/src/org/traccar/reports/model/StopReport.java
index 6b2e86299..245292b63 100644
--- a/src/org/traccar/reports/model/StopReport.java
+++ b/src/org/traccar/reports/model/StopReport.java
@@ -53,37 +53,21 @@ public class StopReport extends BaseReport {
private Date startTime;
public Date getStartTime() {
- if (startTime != null) {
- return new Date(startTime.getTime());
- } else {
- return null;
- }
+ return startTime;
}
public void setStartTime(Date startTime) {
- if (startTime != null) {
- this.startTime = new Date(startTime.getTime());
- } else {
- this.startTime = null;
- }
+ this.startTime = startTime;
}
private Date endTime;
public Date getEndTime() {
- if (endTime != null) {
- return new Date(endTime.getTime());
- } else {
- return null;
- }
+ return endTime;
}
public void setEndTime(Date endTime) {
- if (endTime != null) {
- this.endTime = new Date(endTime.getTime());
- } else {
- this.endTime = null;
- }
+ this.endTime = endTime;
}
private String address;
diff --git a/src/org/traccar/reports/model/TripReport.java b/src/org/traccar/reports/model/TripReport.java
index 42a4240b7..3140f3019 100644
--- a/src/org/traccar/reports/model/TripReport.java
+++ b/src/org/traccar/reports/model/TripReport.java
@@ -83,19 +83,11 @@ public class TripReport extends BaseReport {
private Date startTime;
public Date getStartTime() {
- if (startTime != null) {
- return new Date(startTime.getTime());
- } else {
- return null;
- }
+ return startTime;
}
public void setStartTime(Date startTime) {
- if (startTime != null) {
- this.startTime = new Date(startTime.getTime());
- } else {
- this.startTime = null;
- }
+ this.startTime = startTime;
}
private String startAddress;
@@ -111,19 +103,11 @@ public class TripReport extends BaseReport {
private Date endTime;
public Date getEndTime() {
- if (endTime != null) {
- return new Date(endTime.getTime());
- } else {
- return null;
- }
+ return endTime;
}
public void setEndTime(Date endTime) {
- if (endTime != null) {
- this.endTime = new Date(endTime.getTime());
- } else {
- this.endTime = null;
- }
+ this.endTime = endTime;
}
private String endAddress;
diff --git a/src/org/traccar/smpp/ClientSmppSessionHandler.java b/src/org/traccar/smpp/ClientSmppSessionHandler.java
index 77f75273e..3585f8376 100644
--- a/src/org/traccar/smpp/ClientSmppSessionHandler.java
+++ b/src/org/traccar/smpp/ClientSmppSessionHandler.java
@@ -25,6 +25,7 @@ import com.cloudhopper.smpp.impl.DefaultSmppSessionHandler;
import com.cloudhopper.smpp.pdu.DeliverSm;
import com.cloudhopper.smpp.pdu.PduRequest;
import com.cloudhopper.smpp.pdu.PduResponse;
+import com.cloudhopper.smpp.util.SmppUtil;
public class ClientSmppSessionHandler extends DefaultSmppSessionHandler {
@@ -44,16 +45,19 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler {
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());
+ 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);
+
+ boolean isDeliveryReceipt = false;
+ if (smppClient.getDetectDlrByOpts()) {
+ isDeliveryReceipt = request.getOptionalParameters() != null;
} 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);
+ isDeliveryReceipt = SmppUtil.isMessageTypeAnyDeliveryReceipt(((DeliverSm) request).getEsmClass());
+ }
+
+ if (!isDeliveryReceipt) {
TextMessageEventHandler.handleTextMessage(sourceAddress, message);
}
}
diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java
index 122bbaea1..bf395f90e 100644
--- a/src/org/traccar/smpp/SmppClient.java
+++ b/src/org/traccar/smpp/SmppClient.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2018 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.
@@ -35,6 +35,7 @@ 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.tlv.Tlv;
import com.cloudhopper.smpp.type.Address;
import com.cloudhopper.smpp.type.RecoverablePduException;
import com.cloudhopper.smpp.type.SmppChannelException;
@@ -61,6 +62,8 @@ public class SmppClient {
private String sourceAddress;
private String commandSourceAddress;
private int submitTimeout;
+ private boolean requestDlr;
+ private boolean detectDlrByOpts;
private String notificationsCharsetName;
private byte notificationsDataCoding;
private String commandsCharsetName;
@@ -82,6 +85,7 @@ public class SmppClient {
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.setSystemType(Context.getConfig().getString("sms.smpp.systemType", null));
sessionConfig.setPassword(Context.getConfig().getString("sms.smpp.password", "password"));
sessionConfig.getLoggingOptions().setLogBytes(false);
sessionConfig.getLoggingOptions().setLogPdu(Context.getConfig().getBoolean("sms.smpp.logPdu"));
@@ -90,6 +94,9 @@ public class SmppClient {
commandSourceAddress = Context.getConfig().getString("sms.smpp.commandSourceAddress", sourceAddress);
submitTimeout = Context.getConfig().getInteger("sms.smpp.submitTimeout", 10000);
+ requestDlr = Context.getConfig().getBoolean("sms.smpp.requestDlr");
+ detectDlrByOpts = Context.getConfig().getBoolean("sms.smpp.detectDlrByOpts");
+
notificationsCharsetName = Context.getConfig().getString("sms.smpp.notificationsCharset",
CharsetUtil.NAME_UCS_2);
notificationsDataCoding = (byte) Context.getConfig().getInteger("sms.smpp.notificationsDataCoding",
@@ -149,6 +156,10 @@ public class SmppClient {
}
}
+ public boolean getDetectDlrByOpts() {
+ return detectDlrByOpts;
+ }
+
protected synchronized void reconnect() {
try {
disconnect();
@@ -209,7 +220,16 @@ public class SmppClient {
byte[] textBytes;
textBytes = CharsetUtil.encode(message, command ? commandsCharsetName : notificationsCharsetName);
submit.setDataCoding(command ? commandsDataCoding : notificationsDataCoding);
- submit.setShortMessage(textBytes);
+ if (requestDlr) {
+ submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED);
+ }
+
+ if (textBytes != null && textBytes.length > 255) {
+ submit.addOptionalParameter(new Tlv(SmppConstants.TAG_MESSAGE_PAYLOAD, textBytes, "message_payload"));
+ } else {
+ submit.setShortMessage(textBytes);
+ }
+
submit.setSourceAddress(command ? new Address(commandSourceTon, commandSourceNpi, commandSourceAddress)
: new Address(sourceTon, sourceNpi, sourceAddress));
submit.setDestAddress(new Address(destTon, destNpi, destAddress));
diff --git a/src/org/traccar/web/CsvBuilder.java b/src/org/traccar/web/CsvBuilder.java
index 31b389873..fa99f1b18 100644
--- a/src/org/traccar/web/CsvBuilder.java
+++ b/src/org/traccar/web/CsvBuilder.java
@@ -51,7 +51,7 @@ public class CsvBuilder {
private SortedSet<Method> getSortedMethods(Object object) {
Method[] methodArray = object.getClass().getMethods();
- SortedSet<Method> methods = new TreeSet<Method>(new Comparator<Method>() {
+ SortedSet<Method> methods = new TreeSet<>(new Comparator<Method>() {
@Override
public int compare(Method m1, Method m2) {
if (m1.getName().equals("getAttributes") && !m1.getName().equals(m2.getName())) {
@@ -75,16 +75,16 @@ public class CsvBuilder {
if (method.getName().startsWith("get") && method.getParameterTypes().length == 0) {
try {
if (method.getReturnType().equals(boolean.class)) {
- builder.append((Boolean) method.invoke(object));
+ builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(int.class)) {
- builder.append((Integer) method.invoke(object));
+ builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(long.class)) {
- builder.append((Long) method.invoke(object));
+ builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(double.class)) {
- builder.append((Double) method.invoke(object));
+ builder.append(method.invoke(object));
addSeparator();
} else if (method.getReturnType().equals(String.class)) {
builder.append((String) method.invoke(object));
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index e145ff554..13eebf34f 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ 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.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
@@ -35,6 +36,7 @@ import org.traccar.Config;
import org.traccar.Context;
import org.traccar.api.AsyncSocketServlet;
import org.traccar.api.CorsResponseFilter;
+import org.traccar.api.MediaFilter;
import org.traccar.api.ObjectMapperProvider;
import org.traccar.api.ResourceErrorHandler;
import org.traccar.api.SecurityRequestFilter;
@@ -42,6 +44,7 @@ import org.traccar.api.resource.ServerResource;
import org.traccar.helper.Log;
import javax.naming.InitialContext;
+import javax.servlet.DispatcherType;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -49,6 +52,7 @@ import javax.sql.DataSource;
import java.io.IOException;
import java.io.Writer;
import java.net.InetSocketAddress;
+import java.util.EnumSet;
public class WebServer {
@@ -163,11 +167,19 @@ public class WebServer {
servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket");
+ if (config.hasKey("media.path")) {
+ ServletHolder servletHolder = new ServletHolder("media", DefaultServlet.class);
+ servletHolder.setInitParameter("resourceBase", config.getString("media.path"));
+ servletHolder.setInitParameter("dirAllowed", config.getString("media.dirAllowed", "false"));
+ servletHolder.setInitParameter("pathInfoOnly", "true");
+ servletHandler.addServlet(servletHolder, "/media/*");
+ servletHandler.addFilter(MediaFilter.class, "/media/*", EnumSet.allOf(DispatcherType.class));
+ }
+
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);
diff --git a/swagger.json b/swagger.json
index 265e7bfd5..e6c242a3e 100644
--- a/swagger.json
+++ b/swagger.json
@@ -1,7 +1,7 @@
{
"swagger": "2.0",
"info": {
- "version": "3.15",
+ "version": "3.16",
"title": "traccar"
},
"host": "demo.traccar.org",
diff --git a/templates/export/events.xlsx b/templates/export/events.xlsx
index f3151d11c..5c5633f3a 100644
--- a/templates/export/events.xlsx
+++ b/templates/export/events.xlsx
Binary files differ
diff --git a/templates/mail/maintenance.vm b/templates/mail/maintenance.vm
index 7f69b6c0d..c6973f97a 100644
--- a/templates/mail/maintenance.vm
+++ b/templates/mail/maintenance.vm
@@ -3,7 +3,7 @@
<html>
<body>
Device: $device.name<br>
-Maintenance is required<br>
+Maintenance is required: $maintenance.name<br>
Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone)<br>
Point: <a href="$webUrl?eventId=$event.id">#{if}($position.address)$position.address#{else}$position.latitude&deg;, $position.longitude&deg;#{end}</a><br>
</body>
diff --git a/templates/mail/test.vm b/templates/mail/test.vm
index 8c06f96a7..93cbdc549 100644
--- a/templates/mail/test.vm
+++ b/templates/mail/test.vm
@@ -1,4 +1,4 @@
-#set($subject = "Traccar test message")
+#set($subject = "Test message")
<!DOCTYPE html>
<html>
<body>
diff --git a/templates/sms/maintenance.vm b/templates/sms/maintenance.vm
index 554b74400..621beae46 100644
--- a/templates/sms/maintenance.vm
+++ b/templates/sms/maintenance.vm
@@ -1 +1 @@
-$device.name maintenance is required at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone)
+$device.name maintenance $maintenance.name is required at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.serverTime, $locale, $timezone)
diff --git a/templates/sms/test.vm b/templates/sms/test.vm
index 0311b6203..d25f218ce 100644
--- a/templates/sms/test.vm
+++ b/templates/sms/test.vm
@@ -1 +1 @@
-Traccar test message
+Test message
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java
index 0d488a7fb..8b1ba3b1f 100644
--- a/test/org/traccar/FilterHandlerTest.java
+++ b/test/org/traccar/FilterHandlerTest.java
@@ -3,8 +3,6 @@ package org.traccar;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.traccar.database.IdentityManager;
-import org.traccar.model.Device;
import org.traccar.model.Position;
import java.util.Date;
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 1daefabd6..75a98000b 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -5,12 +5,11 @@ import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpVersion;
-import org.junit.Assert;
+import org.traccar.helper.DataConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Command;
import org.traccar.model.Position;
-import javax.xml.bind.DatatypeConverter;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
@@ -21,17 +20,21 @@ import java.util.List;
import java.util.Map;
import java.util.TimeZone;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
public class ProtocolTest extends BaseTest {
protected Position position(String time, boolean valid, double lat, double lon) throws ParseException {
Position position = new Position();
- if (time != null) {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- position.setTime(dateFormat.parse(time));
- }
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ position.setTime(dateFormat.parse(time));
position.setValid(valid);
position.setLatitude(lat);
position.setLongitude(lon);
@@ -53,7 +56,7 @@ public class ProtocolTest extends BaseTest {
protected ChannelBuffer binary(ByteOrder endianness, String... data) {
return ChannelBuffers.wrappedBuffer(
- endianness, DatatypeConverter.parseHexBinary(concatenateStrings(data)));
+ endianness, DataConverter.parseHex(concatenateStrings(data)));
}
protected String text(String... data) {
@@ -79,19 +82,19 @@ public class ProtocolTest extends BaseTest {
}
protected void verifyNotNull(BaseProtocolDecoder decoder, Object object) throws Exception {
- Assert.assertNotNull(decoder.decode(null, null, object));
+ assertNotNull(decoder.decode(null, null, object));
}
protected void verifyNull(Object object) throws Exception {
- Assert.assertNull(object);
+ assertNull(object);
}
protected void verifyNull(BaseProtocolDecoder decoder, Object object) throws Exception {
- Assert.assertNull(decoder.decode(null, null, object));
+ assertNull(decoder.decode(null, null, object));
}
protected void verifyAttribute(BaseProtocolDecoder decoder, Object object, String key, Object expected) throws Exception {
- Assert.assertEquals(expected, ((Position) decoder.decode(null, null, object)).getAttributes().get(key));
+ assertEquals(expected, ((Position) decoder.decode(null, null, object)).getAttributes().get(key));
}
protected void verifyAttributes(BaseProtocolDecoder decoder, Object object) throws Exception {
@@ -120,9 +123,9 @@ public class ProtocolTest extends BaseTest {
private void verifyDecodedList(Object decodedObject, boolean checkLocation, Position expected) {
- Assert.assertNotNull("list is null", decodedObject);
- Assert.assertTrue("not a list", decodedObject instanceof List);
- Assert.assertFalse("list is empty", ((List) decodedObject).isEmpty());
+ assertNotNull("list is null", decodedObject);
+ assertTrue("not a list", decodedObject instanceof List);
+ assertFalse("list is empty", ((List) decodedObject).isEmpty());
for (Object item : (List) decodedObject) {
verifyDecodedPosition(item, checkLocation, false, expected);
@@ -132,8 +135,8 @@ public class ProtocolTest extends BaseTest {
private void verifyDecodedPosition(Object decodedObject, boolean checkLocation, boolean checkAttributes, Position expected) {
- Assert.assertNotNull("position is null", decodedObject);
- Assert.assertTrue("not a position", decodedObject instanceof Position);
+ assertNotNull("position is null", decodedObject);
+ assertTrue("not a position", decodedObject instanceof Position);
Position position = (Position) decodedObject;
@@ -144,125 +147,125 @@ public class ProtocolTest extends BaseTest {
if (expected.getFixTime() != null) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- Assert.assertEquals("time", dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime()));
+ assertEquals("time", dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime()));
}
- Assert.assertEquals("valid", expected.getValid(), position.getValid());
- Assert.assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001);
- Assert.assertEquals("longitude", expected.getLongitude(), position.getLongitude(), 0.00001);
+ assertEquals("valid", expected.getValid(), position.getValid());
+ assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001);
+ assertEquals("longitude", expected.getLongitude(), position.getLongitude(), 0.00001);
} else {
- Assert.assertNotNull(position.getFixTime());
- Assert.assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L)));
- Assert.assertTrue("time < +25 hours",
+ assertNotNull(position.getFixTime());
+ assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L)));
+ assertTrue("time < +25 hours",
position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000);
- Assert.assertTrue("latitude >= -90", position.getLatitude() >= -90);
- Assert.assertTrue("latitude <= 90", position.getLatitude() <= 90);
+ assertTrue("latitude >= -90", position.getLatitude() >= -90);
+ assertTrue("latitude <= 90", position.getLatitude() <= 90);
- Assert.assertTrue("longitude >= -180", position.getLongitude() >= -180);
- Assert.assertTrue("longitude <= 180", position.getLongitude() <= 180);
+ assertTrue("longitude >= -180", position.getLongitude() >= -180);
+ assertTrue("longitude <= 180", position.getLongitude() <= 180);
}
- Assert.assertTrue("altitude >= -12262", position.getAltitude() >= -12262);
- Assert.assertTrue("altitude <= 18000", position.getAltitude() <= 18000);
+ assertTrue("altitude >= -12262", position.getAltitude() >= -12262);
+ assertTrue("altitude <= 18000", position.getAltitude() <= 18000);
- Assert.assertTrue("speed >= 0", position.getSpeed() >= 0);
- Assert.assertTrue("speed <= 869", position.getSpeed() <= 869);
+ assertTrue("speed >= 0", position.getSpeed() >= 0);
+ assertTrue("speed <= 869", position.getSpeed() <= 869);
- Assert.assertTrue("course >= 0", position.getCourse() >= 0);
- Assert.assertTrue("course <= 360", position.getCourse() <= 360);
+ assertTrue("course >= 0", position.getCourse() >= 0);
+ assertTrue("course <= 360", position.getCourse() <= 360);
- Assert.assertNotNull("protocol is null", position.getProtocol());
+ assertNotNull("protocol is null", position.getProtocol());
}
Map<String, Object> attributes = position.getAttributes();
if (checkAttributes) {
- Assert.assertFalse("no attributes", attributes.isEmpty());
+ assertFalse("no attributes", attributes.isEmpty());
}
if (attributes.containsKey(Position.KEY_INDEX)) {
- Assert.assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number);
}
if (attributes.containsKey(Position.KEY_HDOP)) {
- Assert.assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_VDOP)) {
- Assert.assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_PDOP)) {
- Assert.assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES)) {
- Assert.assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES_VISIBLE)) {
- Assert.assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RSSI)) {
- Assert.assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ODOMETER)) {
- Assert.assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RPM)) {
- Assert.assertTrue(attributes.get(Position.KEY_RPM) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_RPM) instanceof Number);
}
if (attributes.containsKey(Position.KEY_FUEL_LEVEL)) {
- Assert.assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number);
}
if (attributes.containsKey(Position.KEY_POWER)) {
- Assert.assertTrue(attributes.get(Position.KEY_POWER) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_POWER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY)) {
- Assert.assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY_LEVEL)) {
int batteryLevel = ((Number) attributes.get(Position.KEY_BATTERY_LEVEL)).intValue();
- Assert.assertTrue(batteryLevel <= 100 && batteryLevel >= 0);
+ assertTrue(batteryLevel <= 100 && batteryLevel >= 0);
}
if (attributes.containsKey(Position.KEY_CHARGE)) {
- Assert.assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_IGNITION)) {
- Assert.assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_MOTION)) {
- Assert.assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_ARCHIVE)) {
- Assert.assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
- Assert.assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
+ assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
}
if (attributes.containsKey(Position.KEY_STEPS)) {
- Assert.assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
+ assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ROAMING)) {
- Assert.assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
+ assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
}
if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) {
@@ -277,11 +280,11 @@ public class ProtocolTest extends BaseTest {
}
private void checkInteger(Object value, int min, int max) {
- Assert.assertNotNull("value is null", value);
- Assert.assertTrue("not int or long", value instanceof Integer || value instanceof Long);
+ assertNotNull("value is null", value);
+ assertTrue("not int or long", value instanceof Integer || value instanceof Long);
long number = ((Number) value).longValue();
- Assert.assertTrue("value too low", number >= min);
- Assert.assertTrue("value too high", number <= max);
+ assertTrue("value too low", number >= min);
+ assertTrue("value too high", number <= max);
}
protected void verifyCommand(
@@ -290,11 +293,9 @@ public class ProtocolTest extends BaseTest {
}
protected void verifyFrame(ChannelBuffer expected, Object object) {
-
- Assert.assertNotNull("buffer is null", object);
- Assert.assertTrue("not a buffer", object instanceof ChannelBuffer);
- Assert.assertEquals(ChannelBuffers.hexDump(expected), ChannelBuffers.hexDump((ChannelBuffer) object));
-
+ assertNotNull("buffer is null", object);
+ assertTrue("not a buffer", object instanceof ChannelBuffer);
+ assertEquals(ChannelBuffers.hexDump(expected), ChannelBuffers.hexDump((ChannelBuffer) object));
}
}
diff --git a/test/org/traccar/WebDataHandlerTest.java b/test/org/traccar/WebDataHandlerTest.java
index 2a8205ad1..9c8f036b0 100644
--- a/test/org/traccar/WebDataHandlerTest.java
+++ b/test/org/traccar/WebDataHandlerTest.java
@@ -1,9 +1,12 @@
package org.traccar;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Position;
+import java.text.ParseException;
+
+import static org.junit.Assert.assertEquals;
+
public class WebDataHandlerTest extends ProtocolTest {
@Test
@@ -11,12 +14,25 @@ public class WebDataHandlerTest extends ProtocolTest {
Position p = position("2016-01-01 01:02:03.000", true, 20, 30);
- WebDataHandler handler = new WebDataHandler("http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}");
+ WebDataHandler handler = new WebDataHandler("http://localhost/?fixTime={fixTime}&gprmc={gprmc}&name={name}", false);
- Assert.assertEquals(
+ assertEquals(
"http://localhost/?fixTime=1451610123000&gprmc=$GPRMC,010203.000,A,2000.0000,N,03000.0000,E,0.00,0.00,010116,,*05&name=test",
handler.formatRequest(p));
}
+ @Test
+ public void testPrepareJsonPayload() throws ParseException {
+
+ Position p = position("2016-01-01 01:02:03.000", true, 20, 30);
+
+ WebDataHandler handler = new WebDataHandler("http://localhost/", true);
+
+ assertEquals(
+ "{\"position\":{\"id\":0,\"attributes\":{},\"deviceId\":0,\"type\":null,\"protocol\":null,\"serverTime\":null,\"deviceTime\":1451610123000,\"fixTime\":1451610123000,\"outdated\":false,\"valid\":true,\"latitude\":20.0,\"longitude\":30.0,\"altitude\":0.0,\"speed\":0.0,\"course\":0.0,\"address\":null,\"accuracy\":0.0,\"network\":null},\"device\":{\"id\":1,\"attributes\":{},\"groupId\":0,\"name\":\"test\",\"uniqueId\":\"123456789012345\",\"status\":\"offline\",\"lastUpdate\":null,\"positionId\":0,\"geofenceIds\":null,\"phone\":null,\"model\":null,\"contact\":null,\"category\":null,\"disabled\":false}}",
+ handler.prepareJsonPayload(p));
+
+ }
+
}
diff --git a/test/org/traccar/calendar/CalendarTest.java b/test/org/traccar/calendar/CalendarTest.java
index 0c8e1830b..0de89f97f 100644
--- a/test/org/traccar/calendar/CalendarTest.java
+++ b/test/org/traccar/calendar/CalendarTest.java
@@ -7,12 +7,13 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Calendar;
import net.fortuna.ical4j.data.ParserException;
+import static org.junit.Assert.assertTrue;
+
public class CalendarTest {
@Test
@@ -46,13 +47,13 @@ public class CalendarTest {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ssX");
Date date = format.parse("2016-12-13 22:59:59+05");
- Assert.assertTrue(!calendar.checkMoment(date));
+ assertTrue(!calendar.checkMoment(date));
date = format.parse("2016-12-13 23:00:01+05");
- Assert.assertTrue(calendar.checkMoment(date));
+ assertTrue(calendar.checkMoment(date));
date = format.parse("2016-12-13 06:59:59+05");
- Assert.assertTrue(calendar.checkMoment(date));
+ assertTrue(calendar.checkMoment(date));
date = format.parse("2016-12-13 07:00:01+05");
- Assert.assertTrue(!calendar.checkMoment(date));
+ assertTrue(!calendar.checkMoment(date));
}
}
diff --git a/test/org/traccar/database/DataManagerTest.java b/test/org/traccar/database/DataManagerTest.java
index 3d6f5201e..f9945c994 100644
--- a/test/org/traccar/database/DataManagerTest.java
+++ b/test/org/traccar/database/DataManagerTest.java
@@ -1,6 +1,5 @@
package org.traccar.database;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Attribute;
import org.traccar.model.Device;
@@ -11,66 +10,70 @@ import org.traccar.model.ManagedUser;
import org.traccar.model.Position;
import org.traccar.model.User;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class DataManagerTest {
@Test
public void constructObjectQuery() {
- Assert.assertEquals("SELECT * FROM users",
+ assertEquals("SELECT * FROM users",
DataManager.constructObjectQuery(DataManager.ACTION_SELECT_ALL, User.class, false));
- Assert.assertEquals("DELETE FROM groups WHERE id = :id",
+ assertEquals("DELETE FROM groups WHERE id = :id",
DataManager.constructObjectQuery(DataManager.ACTION_DELETE, Group.class, false));
- Assert.assertEquals("SELECT * FROM positions WHERE id = :id",
+ assertEquals("SELECT * FROM positions WHERE id = :id",
DataManager.constructObjectQuery(DataManager.ACTION_SELECT, Position.class, false));
String insertDevice = DataManager.constructObjectQuery(DataManager.ACTION_INSERT, Device.class, false);
- Assert.assertFalse(insertDevice.contains("class"));
- Assert.assertFalse(insertDevice.contains("id"));
- Assert.assertFalse(insertDevice.contains("status"));
- Assert.assertFalse(insertDevice.contains("geofenceIds"));
+ assertFalse(insertDevice.contains("class"));
+ assertFalse(insertDevice.contains("id"));
+ assertFalse(insertDevice.contains("status"));
+ assertFalse(insertDevice.contains("geofenceIds"));
String updateDeviceStatus = DataManager.constructObjectQuery("update", Device.class, true);
- Assert.assertTrue(updateDeviceStatus.contains("lastUpdate"));
+ assertTrue(updateDeviceStatus.contains("lastUpdate"));
String updateUser = DataManager.constructObjectQuery(DataManager.ACTION_UPDATE, User.class, false);
- Assert.assertFalse(updateUser.contains("class"));
- Assert.assertFalse(updateUser.contains("password"));
- Assert.assertFalse(updateUser.contains("salt"));
+ assertFalse(updateUser.contains("class"));
+ assertFalse(updateUser.contains("password"));
+ assertFalse(updateUser.contains("salt"));
String updateUserPassword = DataManager.constructObjectQuery(DataManager.ACTION_UPDATE, User.class, true);
- Assert.assertFalse(updateUserPassword.contains("name"));
- Assert.assertTrue(updateUserPassword.contains("hashedPassword"));
- Assert.assertTrue(updateUserPassword.contains("salt"));
+ assertFalse(updateUserPassword.contains("name"));
+ assertTrue(updateUserPassword.contains("hashedPassword"));
+ assertTrue(updateUserPassword.contains("salt"));
String insertPosition = DataManager.constructObjectQuery(DataManager.ACTION_INSERT, Position.class, false);
- Assert.assertFalse(insertPosition.contains("type"));
- Assert.assertFalse(insertPosition.contains("outdated"));
+ assertFalse(insertPosition.contains("type"));
+ assertFalse(insertPosition.contains("outdated"));
}
@Test
public void constructPermissionsQuery() {
- Assert.assertEquals("SELECT userId, deviceId FROM user_device",
+ assertEquals("SELECT userId, deviceId FROM user_device",
DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, User.class, Device.class));
- Assert.assertEquals("SELECT userId, managedUserId FROM user_user",
+ assertEquals("SELECT userId, managedUserId FROM user_user",
DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, User.class, ManagedUser.class));
- Assert.assertEquals("SELECT deviceId, driverId FROM device_driver",
+ assertEquals("SELECT deviceId, driverId FROM device_driver",
DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, Device.class, Driver.class));
- Assert.assertEquals("SELECT groupId, geofenceId FROM group_geofence",
+ assertEquals("SELECT groupId, geofenceId FROM group_geofence",
DataManager.constructPermissionQuery(DataManager.ACTION_SELECT_ALL, Group.class, Geofence.class));
- Assert.assertEquals("INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId)",
+ assertEquals("INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId)",
DataManager.constructPermissionQuery(DataManager.ACTION_INSERT, User.class, Device.class));
- Assert.assertEquals("DELETE FROM user_user WHERE userId = :userId AND managedUserId = :managedUserId",
+ assertEquals("DELETE FROM user_user WHERE userId = :userId AND managedUserId = :managedUserId",
DataManager.constructPermissionQuery(DataManager.ACTION_DELETE, User.class, ManagedUser.class));
- Assert.assertEquals("INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId)",
+ assertEquals("INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId)",
DataManager.constructPermissionQuery(DataManager.ACTION_INSERT, Device.class, Geofence.class));
- Assert.assertEquals("DELETE FROM group_attribute WHERE groupId = :groupId AND attributeId = :attributeId",
+ assertEquals("DELETE FROM group_attribute WHERE groupId = :groupId AND attributeId = :attributeId",
DataManager.constructPermissionQuery(DataManager.ACTION_DELETE, Group.class, Attribute.class));
}
diff --git a/test/org/traccar/database/GroupTreeTest.java b/test/org/traccar/database/GroupTreeTest.java
index f73cb75b6..b547aab60 100644
--- a/test/org/traccar/database/GroupTreeTest.java
+++ b/test/org/traccar/database/GroupTreeTest.java
@@ -1,6 +1,5 @@
package org.traccar.database;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Device;
import org.traccar.model.Group;
@@ -8,6 +7,8 @@ import org.traccar.model.Group;
import java.util.ArrayList;
import java.util.Collection;
+import static org.junit.Assert.assertEquals;
+
public class GroupTreeTest {
private static Group createGroup(long id, String name, long parent) {
@@ -42,14 +43,14 @@ public class GroupTreeTest {
GroupTree groupTree = new GroupTree(groups, devices);
- Assert.assertEquals(4, groupTree.getGroups(1).size());
- Assert.assertEquals(3, groupTree.getGroups(2).size());
- Assert.assertEquals(0, groupTree.getGroups(3).size());
- Assert.assertEquals(1, groupTree.getGroups(4).size());
+ assertEquals(4, groupTree.getGroups(1).size());
+ assertEquals(3, groupTree.getGroups(2).size());
+ assertEquals(0, groupTree.getGroups(3).size());
+ assertEquals(1, groupTree.getGroups(4).size());
- Assert.assertEquals(3, groupTree.getDevices(1).size());
- Assert.assertEquals(1, groupTree.getDevices(3).size());
- Assert.assertEquals(2, groupTree.getDevices(4).size());
+ assertEquals(3, groupTree.getDevices(1).size());
+ assertEquals(1, groupTree.getDevices(3).size());
+ assertEquals(2, groupTree.getDevices(4).size());
}
}
diff --git a/test/org/traccar/geocoder/AddressFormatTest.java b/test/org/traccar/geocoder/AddressFormatTest.java
index 85bb44fd1..0cc5168ef 100644
--- a/test/org/traccar/geocoder/AddressFormatTest.java
+++ b/test/org/traccar/geocoder/AddressFormatTest.java
@@ -1,12 +1,13 @@
package org.traccar.geocoder;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class AddressFormatTest {
private void test(Address address, String format, String expected) {
- Assert.assertEquals(expected, new AddressFormat(format).format(address));
+ assertEquals(expected, new AddressFormat(format).format(address));
}
@Test
diff --git a/test/org/traccar/geocoder/GeocoderTest.java b/test/org/traccar/geocoder/GeocoderTest.java
index 7c6208048..8cf6ac524 100644
--- a/test/org/traccar/geocoder/GeocoderTest.java
+++ b/test/org/traccar/geocoder/GeocoderTest.java
@@ -2,10 +2,11 @@ package org.traccar.geocoder;
import java.util.Locale;
-import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class GeocoderTest {
@Ignore
@@ -44,9 +45,9 @@ public class GeocoderTest {
public void onFailure(final Throwable e) {
}
});
- Assert.assertEquals("1 Ibn Shaprut St, Jerusalem, Jerusalem District, IL", waitAddress());
+ assertEquals("1 Ibn Shaprut St, Jerusalem, Jerusalem District, IL", waitAddress());
- Assert.assertEquals("1 Ibn Shaprut St, Jerusalem, Jerusalem District, IL",
+ assertEquals("1 Ibn Shaprut St, Jerusalem, Jerusalem District, IL",
geocoder.getAddress(31.776797, 35.211489, null));
}
@@ -63,9 +64,9 @@ public class GeocoderTest {
public void onFailure(Throwable e) {
}
});
- Assert.assertEquals("35 West 9th Street, NYC, New York, US", waitAddress());
+ assertEquals("35 West 9th Street, NYC, New York, US", waitAddress());
- Assert.assertEquals("35 West 9th Street, NYC, New York, US",
+ assertEquals("35 West 9th Street, NYC, New York, US",
geocoder.getAddress(40.7337807, -73.9974401, null));
}
@@ -82,9 +83,9 @@ public class GeocoderTest {
public void onFailure(Throwable e) {
}
});
- Assert.assertEquals("Rue du Jardinet, Paris, FR", waitAddress());
+ assertEquals("Rue du Jardinet, Paris, ÃŽle-de-France, FR", waitAddress());
- Assert.assertEquals("Rue du Jardinet, Paris, FR", geocoder.getAddress(48.8530000, 2.3400000, null));
+ assertEquals("Rue du Jardinet, Paris, ÃŽle-de-France, FR", geocoder.getAddress(48.8530000, 2.3400000, null));
}
public void testOpenCage() throws InterruptedException {
@@ -101,9 +102,9 @@ public class GeocoderTest {
public void onFailure(Throwable e) {
}
});
- Assert.assertEquals("Charleston Road, California, US", waitAddress());
+ assertEquals("Charleston Road, California, US", waitAddress());
- Assert.assertEquals("Charleston Road, California, US", geocoder.getAddress(34.116302, -118.051519, null));
+ assertEquals("Charleston Road, California, US", geocoder.getAddress(34.116302, -118.051519, null));
}
public void testGeocodeFarm() throws InterruptedException {
@@ -119,9 +120,9 @@ public class GeocoderTest {
public void onFailure(Throwable e) {
}
});
- Assert.assertEquals("Estrella Avenue, Arcadia, California, United States", waitAddress());
+ assertEquals("Estrella Avenue, Arcadia, California, United States", waitAddress());
- Assert.assertEquals("Estrella Avenue, Arcadia, California, United States",
+ assertEquals("Estrella Avenue, Arcadia, California, United States",
geocoder.getAddress(34.116302, -118.051519, null));
}
diff --git a/test/org/traccar/geofence/GeofenceCircleTest.java b/test/org/traccar/geofence/GeofenceCircleTest.java
index 133ca1db8..259a8fb77 100644
--- a/test/org/traccar/geofence/GeofenceCircleTest.java
+++ b/test/org/traccar/geofence/GeofenceCircleTest.java
@@ -2,9 +2,11 @@ package org.traccar.geofence;
import java.text.ParseException;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class GeofenceCircleTest {
@Test
@@ -12,7 +14,7 @@ public class GeofenceCircleTest {
String test = "CIRCLE (55.75414 37.6204, 100)";
GeofenceGeometry geofenceGeometry = new GeofenceCircle();
geofenceGeometry.fromWkt(test);
- Assert.assertEquals(geofenceGeometry.toWkt(), test);
+ assertEquals(geofenceGeometry.toWkt(), test);
}
@Test
@@ -20,7 +22,7 @@ public class GeofenceCircleTest {
String test = "CIRCLE (55.75414 37.6204, 100)";
GeofenceGeometry geofenceGeometry = new GeofenceCircle();
geofenceGeometry.fromWkt(test);
- Assert.assertTrue(geofenceGeometry.containsPoint(55.75477, 37.62025));
- Assert.assertTrue(!geofenceGeometry.containsPoint(55.75545, 37.61921));
+ assertTrue(geofenceGeometry.containsPoint(55.75477, 37.62025));
+ assertTrue(!geofenceGeometry.containsPoint(55.75545, 37.61921));
}
}
diff --git a/test/org/traccar/geofence/GeofencePolygonTest.java b/test/org/traccar/geofence/GeofencePolygonTest.java
index 361e7b70f..94b73af3a 100644
--- a/test/org/traccar/geofence/GeofencePolygonTest.java
+++ b/test/org/traccar/geofence/GeofencePolygonTest.java
@@ -2,9 +2,11 @@ package org.traccar.geofence;
import java.text.ParseException;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class GeofencePolygonTest {
@Test
@@ -12,7 +14,7 @@ public class GeofencePolygonTest {
String test = "POLYGON ((55.75474 37.61823, 55.75513 37.61888, 55.7535 37.6222, 55.75315 37.62165))";
GeofenceGeometry geofenceGeometry = new GeofencePolygon();
geofenceGeometry.fromWkt(test);
- Assert.assertEquals(geofenceGeometry.toWkt(), test);
+ assertEquals(geofenceGeometry.toWkt(), test);
}
@Test
@@ -20,8 +22,8 @@ public class GeofencePolygonTest {
String test = "POLYGON ((55.75474 37.61823, 55.75513 37.61888, 55.7535 37.6222, 55.75315 37.62165))";
GeofenceGeometry geofenceGeometry = new GeofencePolygon();
geofenceGeometry.fromWkt(test);
- Assert.assertTrue(geofenceGeometry.containsPoint(55.75476, 37.61915));
- Assert.assertTrue(!geofenceGeometry.containsPoint(55.75545, 37.61921));
+ assertTrue(geofenceGeometry.containsPoint(55.75476, 37.61915));
+ assertTrue(!geofenceGeometry.containsPoint(55.75545, 37.61921));
}
@@ -30,9 +32,9 @@ public class GeofencePolygonTest {
String test = "POLYGON ((66.9494 179.838, 66.9508 -179.8496, 66.8406 -180.0014))";
GeofenceGeometry geofenceGeometry = new GeofencePolygon();
geofenceGeometry.fromWkt(test);
- Assert.assertTrue(geofenceGeometry.containsPoint(66.9015, -180.0096));
- Assert.assertTrue(geofenceGeometry.containsPoint(66.9015, 179.991));
- Assert.assertTrue(!geofenceGeometry.containsPoint(66.8368, -179.8792));
+ assertTrue(geofenceGeometry.containsPoint(66.9015, -180.0096));
+ assertTrue(geofenceGeometry.containsPoint(66.9015, 179.991));
+ assertTrue(!geofenceGeometry.containsPoint(66.8368, -179.8792));
}
@@ -41,9 +43,9 @@ public class GeofencePolygonTest {
String test = "POLYGON ((51.1966 -0.6207, 51.1897 0.4147, 50.9377 0.5136, 50.8675 -0.6082))";
GeofenceGeometry geofenceGeometry = new GeofencePolygon();
geofenceGeometry.fromWkt(test);
- Assert.assertTrue(geofenceGeometry.containsPoint(51.0466, -0.0165));
- Assert.assertTrue(geofenceGeometry.containsPoint(51.0466, 0.018));
- Assert.assertTrue(!geofenceGeometry.containsPoint(50.9477, 0.5836));
+ assertTrue(geofenceGeometry.containsPoint(51.0466, -0.0165));
+ assertTrue(geofenceGeometry.containsPoint(51.0466, 0.018));
+ assertTrue(!geofenceGeometry.containsPoint(50.9477, 0.5836));
}
diff --git a/test/org/traccar/geofence/GeofencePolylineTest.java b/test/org/traccar/geofence/GeofencePolylineTest.java
index 71aeb4081..1e9dcb7c3 100644
--- a/test/org/traccar/geofence/GeofencePolylineTest.java
+++ b/test/org/traccar/geofence/GeofencePolylineTest.java
@@ -2,9 +2,11 @@ package org.traccar.geofence;
import java.text.ParseException;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class GeofencePolylineTest {
@Test
@@ -12,25 +14,25 @@ public class GeofencePolylineTest {
String test = "LINESTRING (55.75474 37.61823, 55.75513 37.61888, 55.7535 37.6222, 55.75315 37.62165)";
GeofenceGeometry geofenceGeometry = new GeofencePolyline();
geofenceGeometry.fromWkt(test);
- Assert.assertEquals(geofenceGeometry.toWkt(), test);
+ assertEquals(geofenceGeometry.toWkt(), test);
}
@Test
public void testContainsPolyline1Interval() throws ParseException {
String test = "LINESTRING (56.83777 60.59833, 56.83766 60.5968)";
GeofenceGeometry geofenceGeometry = new GeofencePolyline(test, 35);
- Assert.assertTrue(geofenceGeometry.containsPoint(56.83801, 60.59748));
+ assertTrue(geofenceGeometry.containsPoint(56.83801, 60.59748));
((GeofencePolyline) geofenceGeometry).setDistance(15);
- Assert.assertTrue(!geofenceGeometry.containsPoint(56.83801, 60.59748));
+ assertTrue(!geofenceGeometry.containsPoint(56.83801, 60.59748));
}
@Test
public void testContainsPolyline3Intervals() throws ParseException {
String test = "LINESTRING (56.836 60.6126, 56.8393 60.6114, 56.83887 60.60811, 56.83782 60.5988)";
GeofenceGeometry geofenceGeometry = new GeofencePolyline(test, 15);
- Assert.assertTrue(geofenceGeometry.containsPoint(56.83847, 60.60458));
- Assert.assertTrue(!geofenceGeometry.containsPoint(56.83764, 60.59725));
- Assert.assertTrue(!geofenceGeometry.containsPoint(56.83861, 60.60822));
+ assertTrue(geofenceGeometry.containsPoint(56.83847, 60.60458));
+ assertTrue(!geofenceGeometry.containsPoint(56.83764, 60.59725));
+ assertTrue(!geofenceGeometry.containsPoint(56.83861, 60.60822));
}
@@ -38,8 +40,8 @@ public class GeofencePolylineTest {
public void testContainsPolylineNear180() throws ParseException {
String test = "LINESTRING (66.9494 179.838, 66.9508 -179.8496)";
GeofenceGeometry geofenceGeometry = new GeofencePolyline(test, 25);
- Assert.assertTrue(geofenceGeometry.containsPoint(66.95, 180.0));
- Assert.assertTrue(!geofenceGeometry.containsPoint(66.96, 180.0));
- Assert.assertTrue(!geofenceGeometry.containsPoint(66.9509, -179.83));
+ assertTrue(geofenceGeometry.containsPoint(66.95, 180.0));
+ assertTrue(!geofenceGeometry.containsPoint(66.96, 180.0));
+ assertTrue(!geofenceGeometry.containsPoint(66.9509, -179.83));
}
}
diff --git a/test/org/traccar/geolocation/GeolocationProviderTest.java b/test/org/traccar/geolocation/GeolocationProviderTest.java
index 6a557e5c2..2729052d6 100644
--- a/test/org/traccar/geolocation/GeolocationProviderTest.java
+++ b/test/org/traccar/geolocation/GeolocationProviderTest.java
@@ -1,12 +1,14 @@
package org.traccar.geolocation;
-import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.traccar.BaseTest;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
public class GeolocationProviderTest extends BaseTest {
@Ignore
@@ -23,13 +25,13 @@ public class GeolocationProviderTest extends BaseTest {
provider.getLocation(network, new GeolocationProvider.LocationProviderCallback() {
@Override
public void onSuccess(double latitude, double longitude, double accuracy) {
- Assert.assertEquals(60.07254, latitude, 0.00001);
- Assert.assertEquals(30.30996, longitude, 0.00001);
+ assertEquals(60.07254, latitude, 0.00001);
+ assertEquals(30.30996, longitude, 0.00001);
}
@Override
public void onFailure(Throwable e) {
- Assert.fail();
+ fail();
}
});
diff --git a/test/org/traccar/helper/BcdUtilTest.java b/test/org/traccar/helper/BcdUtilTest.java
index 8767ac890..e97aad09f 100644
--- a/test/org/traccar/helper/BcdUtilTest.java
+++ b/test/org/traccar/helper/BcdUtilTest.java
@@ -1,9 +1,10 @@
package org.traccar.helper;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class BcdUtilTest {
@Test
@@ -11,7 +12,7 @@ public class BcdUtilTest {
byte[] buf = {0x01, (byte) 0x90, 0x34};
int result = BcdUtil.readInteger(
ChannelBuffers.wrappedBuffer(buf), 5);
- Assert.assertEquals(1903, result);
+ assertEquals(1903, result);
}
@Test
@@ -19,7 +20,7 @@ public class BcdUtilTest {
byte[] buf = {0x03, (byte) 0x85, 0x22, 0x59, 0x34};
double result = BcdUtil.readCoordinate(
ChannelBuffers.wrappedBuffer(buf));
- Assert.assertEquals(38.870989, result, 0.00001);
+ assertEquals(38.870989, result, 0.00001);
}
}
diff --git a/test/org/traccar/helper/BitUtilTest.java b/test/org/traccar/helper/BitUtilTest.java
index 4aa295e12..90431bf55 100644
--- a/test/org/traccar/helper/BitUtilTest.java
+++ b/test/org/traccar/helper/BitUtilTest.java
@@ -1,35 +1,38 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class BitUtilTest {
@Test
public void testCheck() {
- Assert.assertFalse(BitUtil.check(0, 0));
- Assert.assertTrue(BitUtil.check(1, 0));
- Assert.assertFalse(BitUtil.check(2, 0));
+ assertFalse(BitUtil.check(0, 0));
+ assertTrue(BitUtil.check(1, 0));
+ assertFalse(BitUtil.check(2, 0));
}
@Test
public void testBetween() {
- Assert.assertEquals(0, BitUtil.between(0, 0, 0));
- Assert.assertEquals(1, BitUtil.between(1, 0, 1));
- Assert.assertEquals(2, BitUtil.between(2, 0, 2));
- Assert.assertEquals(2, BitUtil.between(6, 0, 2));
+ assertEquals(0, BitUtil.between(0, 0, 0));
+ assertEquals(1, BitUtil.between(1, 0, 1));
+ assertEquals(2, BitUtil.between(2, 0, 2));
+ assertEquals(2, BitUtil.between(6, 0, 2));
}
@Test
public void testFrom() {
- Assert.assertEquals(1, BitUtil.from(1, 0));
- Assert.assertEquals(0, BitUtil.from(1, 1));
+ assertEquals(1, BitUtil.from(1, 0));
+ assertEquals(0, BitUtil.from(1, 1));
}
@Test
public void testTo() {
- Assert.assertEquals(2, BitUtil.to(2, 2));
- Assert.assertEquals(0, BitUtil.to(2, 1));
+ assertEquals(2, BitUtil.to(2, 2));
+ assertEquals(0, BitUtil.to(2, 1));
}
}
diff --git a/test/org/traccar/helper/ChecksumTest.java b/test/org/traccar/helper/ChecksumTest.java
index c37eda88d..3bd51448d 100644
--- a/test/org/traccar/helper/ChecksumTest.java
+++ b/test/org/traccar/helper/ChecksumTest.java
@@ -2,30 +2,38 @@ package org.traccar.helper;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.junit.Assert;
import org.junit.Test;
import java.nio.charset.StandardCharsets;
+import static org.junit.Assert.assertEquals;
+
public class ChecksumTest {
@Test
+ public void testCrc8() {
+ ChannelBuffer buf = ChannelBuffers.copiedBuffer("123456789", StandardCharsets.US_ASCII);
+
+ assertEquals(0xF7, Checksum.crc8(Checksum.CRC8_EGTS, buf.toByteBuffer()));
+ assertEquals(0xD0, Checksum.crc8(Checksum.CRC8_ROHC, buf.toByteBuffer()));
+ }
+
+ @Test
public void testCrc16() {
ChannelBuffer buf = ChannelBuffers.copiedBuffer("123456789", StandardCharsets.US_ASCII);
- Assert.assertEquals(0x906e, Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
- Assert.assertEquals(0x29b1, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
- Assert.assertEquals(0x2189, Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
- Assert.assertEquals(0x31c3, Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer()));
- Assert.assertEquals(0xe5cc, Checksum.crc16(Checksum.CRC16_AUG_CCITT, buf.toByteBuffer()));
- Assert.assertEquals(0xd64e, Checksum.crc16(Checksum.CRC16_GENIBUS, buf.toByteBuffer()));
- Assert.assertEquals(0x6f91, Checksum.crc16(Checksum.CRC16_MCRF4XX, buf.toByteBuffer()));
+ assertEquals(0xBB3D, Checksum.crc16(Checksum.CRC16_IBM, buf.toByteBuffer()));
+ assertEquals(0x4B37, Checksum.crc16(Checksum.CRC16_MODBUS, buf.toByteBuffer()));
+ assertEquals(0x906e, Checksum.crc16(Checksum.CRC16_X25, buf.toByteBuffer()));
+ assertEquals(0x29b1, Checksum.crc16(Checksum.CRC16_CCITT_FALSE, buf.toByteBuffer()));
+ assertEquals(0x2189, Checksum.crc16(Checksum.CRC16_KERMIT, buf.toByteBuffer()));
+ assertEquals(0x31c3, Checksum.crc16(Checksum.CRC16_XMODEM, buf.toByteBuffer()));
}
-
+
@Test
public void testLuhn() {
- Assert.assertEquals(7, Checksum.luhn(12345678901234L));
- Assert.assertEquals(0, Checksum.luhn(63070019470771L));
+ assertEquals(7, Checksum.luhn(12345678901234L));
+ assertEquals(0, Checksum.luhn(63070019470771L));
}
}
diff --git a/test/org/traccar/helper/DateBuilderTest.java b/test/org/traccar/helper/DateBuilderTest.java
index 74936208b..b6323cc1d 100644
--- a/test/org/traccar/helper/DateBuilderTest.java
+++ b/test/org/traccar/helper/DateBuilderTest.java
@@ -1,6 +1,5 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
import java.text.DateFormat;
@@ -8,6 +7,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
+import static org.junit.Assert.assertEquals;
+
public class DateBuilderTest {
@Test
@@ -19,7 +20,7 @@ public class DateBuilderTest {
DateBuilder dateBuilder = new DateBuilder()
.setDate(2015, 10, 20).setTime(1, 21, 11);
- Assert.assertEquals(dateFormat.parse("2015-10-20 01:21:11"), dateBuilder.getDate());
+ assertEquals(dateFormat.parse("2015-10-20 01:21:11"), dateBuilder.getDate());
}
diff --git a/test/org/traccar/helper/DateUtilTest.java b/test/org/traccar/helper/DateUtilTest.java
index ae5f20696..ec42e71ae 100644
--- a/test/org/traccar/helper/DateUtilTest.java
+++ b/test/org/traccar/helper/DateUtilTest.java
@@ -1,6 +1,5 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
import java.text.DateFormat;
@@ -8,6 +7,8 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
+import static org.junit.Assert.assertEquals;
+
public class DateUtilTest {
@Test
@@ -15,13 +16,13 @@ public class DateUtilTest {
DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Assert.assertEquals(f.parse("2015-12-31 23:59:59"),
+ assertEquals(f.parse("2015-12-31 23:59:59"),
DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2016-01-01 23:59:59"), Calendar.DAY_OF_MONTH));
- Assert.assertEquals(f.parse("2016-01-01 00:00:02"),
+ assertEquals(f.parse("2016-01-01 00:00:02"),
DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2016-01-01 00:00:02"), Calendar.DAY_OF_MONTH));
- Assert.assertEquals(f.parse("2016-01-01 00:00:02"),
+ assertEquals(f.parse("2016-01-01 00:00:02"),
DateUtil.correctDate(f.parse("2016-01-01 00:00:01"), f.parse("2015-12-31 00:00:02"), Calendar.DAY_OF_MONTH));
}
diff --git a/test/org/traccar/helper/DistanceCalculatorTest.java b/test/org/traccar/helper/DistanceCalculatorTest.java
index 22e41c9a3..a7457b6c4 100644
--- a/test/org/traccar/helper/DistanceCalculatorTest.java
+++ b/test/org/traccar/helper/DistanceCalculatorTest.java
@@ -1,22 +1,23 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class DistanceCalculatorTest {
@Test
public void testDistance() {
- Assert.assertEquals(
+ assertEquals(
DistanceCalculator.distance(0.0, 0.0, 0.05, 0.05), 7863.0, 10.0);
}
@Test
public void testDistanceToLine() {
- Assert.assertEquals(DistanceCalculator.distanceToLine(
+ assertEquals(DistanceCalculator.distanceToLine(
56.83801, 60.59748, 56.83777, 60.59833, 56.83766, 60.5968), 33.0, 5.0);
- Assert.assertEquals(DistanceCalculator.distanceToLine(
+ assertEquals(DistanceCalculator.distanceToLine(
56.83753, 60.59508, 56.83777, 60.59833, 56.83766, 60.5968), 105.0, 5.0);
}
diff --git a/test/org/traccar/helper/LocationTreeTest.java b/test/org/traccar/helper/LocationTreeTest.java
index afbbbc94c..21604144a 100644
--- a/test/org/traccar/helper/LocationTreeTest.java
+++ b/test/org/traccar/helper/LocationTreeTest.java
@@ -1,11 +1,12 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+
public class LocationTreeTest {
@Test
@@ -19,10 +20,10 @@ public class LocationTreeTest {
LocationTree tree = new LocationTree(items);
- Assert.assertEquals("a", tree.findNearest(new LocationTree.Item(1f, 1f)).getData());
- Assert.assertEquals("d", tree.findNearest(new LocationTree.Item(10f, 10f)).getData());
- Assert.assertEquals("c", tree.findNearest(new LocationTree.Item(1f, 2.5f)).getData());
- Assert.assertEquals("a", tree.findNearest(new LocationTree.Item(1.5f, 1.5f)).getData());
+ assertEquals("a", tree.findNearest(new LocationTree.Item(1f, 1f)).getData());
+ assertEquals("d", tree.findNearest(new LocationTree.Item(10f, 10f)).getData());
+ assertEquals("c", tree.findNearest(new LocationTree.Item(1f, 2.5f)).getData());
+ assertEquals("a", tree.findNearest(new LocationTree.Item(1.5f, 1.5f)).getData());
}
diff --git a/test/org/traccar/helper/LogTest.java b/test/org/traccar/helper/LogTest.java
index 579c13e7d..853eb05c9 100644
--- a/test/org/traccar/helper/LogTest.java
+++ b/test/org/traccar/helper/LogTest.java
@@ -1,13 +1,14 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class LogTest {
@Test
public void testLog() {
- Assert.assertEquals("test - Exception (LogTest:10 < ...)", Log.exceptionStack(new Exception("test")));
+ assertEquals("test - Exception (LogTest:11 < ...)", Log.exceptionStack(new Exception("test")));
}
}
diff --git a/test/org/traccar/helper/ObdDecoderTest.java b/test/org/traccar/helper/ObdDecoderTest.java
index db84d46d7..1ffe68c8b 100644
--- a/test/org/traccar/helper/ObdDecoderTest.java
+++ b/test/org/traccar/helper/ObdDecoderTest.java
@@ -1,25 +1,26 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class ObdDecoderTest {
@Test
public void testDecode() {
- Assert.assertEquals(83, ObdDecoder.decode(0x01, "057b").getValue());
- Assert.assertEquals(1225, ObdDecoder.decode(0x01, "0C1324").getValue());
- Assert.assertEquals(20, ObdDecoder.decode(0x01, "0D14").getValue());
- Assert.assertEquals(64050, ObdDecoder.decode(0x01, "31fa32").getValue());
- Assert.assertEquals(25, ObdDecoder.decode(0x01, "2F41").getValue());
+ assertEquals(83, ObdDecoder.decode(0x01, "057b").getValue());
+ assertEquals(1225, ObdDecoder.decode(0x01, "0C1324").getValue());
+ assertEquals(20, ObdDecoder.decode(0x01, "0D14").getValue());
+ assertEquals(64050, ObdDecoder.decode(0x01, "31fa32").getValue());
+ assertEquals(25, ObdDecoder.decode(0x01, "2F41").getValue());
}
@Test
public void testDecodeCodes() throws Exception {
- Assert.assertEquals("P0D14", ObdDecoder.decodeCodes("0D14").getValue());
- Assert.assertEquals("dtcs", ObdDecoder.decodeCodes("0D14").getKey());
+ assertEquals("P0D14", ObdDecoder.decodeCodes("0D14").getValue());
+ assertEquals("dtcs", ObdDecoder.decodeCodes("0D14").getKey());
}
}
diff --git a/test/org/traccar/helper/PatternBuilderTest.java b/test/org/traccar/helper/PatternBuilderTest.java
index 975cc1621..4c76bc463 100644
--- a/test/org/traccar/helper/PatternBuilderTest.java
+++ b/test/org/traccar/helper/PatternBuilderTest.java
@@ -1,19 +1,20 @@
package org.traccar.helper;
-import org.junit.Assert;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class PatternBuilderTest {
@Test
public void testPatternBuilder() {
- Assert.assertEquals("\\$GPRMC", new PatternBuilder().text("$GPRMC").toString());
- Assert.assertEquals("(\\d{2}\\.[0-9a-fA-F]+)", new PatternBuilder().number("(dd.x+)").toString());
- Assert.assertEquals("a(?:bc)?", new PatternBuilder().text("a").text("b").text("c").optional(2).toString());
- Assert.assertEquals("a|b", new PatternBuilder().expression("a|b").toString());
- Assert.assertEquals("ab\\|", new PatternBuilder().expression("ab|").toString());
- Assert.assertEquals("|", new PatternBuilder().or().toString());
- Assert.assertEquals("\\|\\d|\\d\\|", new PatternBuilder().number("|d|d|").toString());
+ assertEquals("\\$GPRMC", new PatternBuilder().text("$GPRMC").toString());
+ assertEquals("(\\d{2}\\.[0-9a-fA-F]+)", new PatternBuilder().number("(dd.x+)").toString());
+ assertEquals("a(?:bc)?", new PatternBuilder().text("a").text("b").text("c").optional(2).toString());
+ assertEquals("a|b", new PatternBuilder().expression("a|b").toString());
+ assertEquals("ab\\|", new PatternBuilder().expression("ab|").toString());
+ assertEquals("|", new PatternBuilder().or().toString());
+ assertEquals("\\|\\d|\\d\\|", new PatternBuilder().number("|d|d|").toString());
}
}
diff --git a/test/org/traccar/helper/StringFinderTest.java b/test/org/traccar/helper/StringFinderTest.java
index 1c8234db1..f35f9a759 100644
--- a/test/org/traccar/helper/StringFinderTest.java
+++ b/test/org/traccar/helper/StringFinderTest.java
@@ -1,16 +1,11 @@
package org.traccar.helper;
import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBufferFactory;
import org.jboss.netty.buffer.ChannelBuffers;
-import org.jboss.netty.buffer.HeapChannelBufferFactory;
-import org.junit.Assert;
import org.junit.Test;
-import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class StringFinderTest {
@@ -20,10 +15,10 @@ public class StringFinderTest {
ChannelBuffer buf = ChannelBuffers.copiedBuffer("hello world", StandardCharsets.US_ASCII);
- Assert.assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("bar")));
- Assert.assertEquals(6, buf.indexOf(0, buf.writerIndex(), new StringFinder("world")));
- Assert.assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("worlds")));
- Assert.assertEquals(0, buf.indexOf(0, buf.writerIndex(), new StringFinder("hell")));
+ assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("bar")));
+ assertEquals(6, buf.indexOf(0, buf.writerIndex(), new StringFinder("world")));
+ assertEquals(-1, buf.indexOf(0, buf.writerIndex(), new StringFinder("worlds")));
+ assertEquals(0, buf.indexOf(0, buf.writerIndex(), new StringFinder("hell")));
}
diff --git a/test/org/traccar/notification/NotificiationMailTest.java b/test/org/traccar/notification/NotificiationMailTest.java
index 975505a3a..b82bec02e 100644
--- a/test/org/traccar/notification/NotificiationMailTest.java
+++ b/test/org/traccar/notification/NotificiationMailTest.java
@@ -1,5 +1,6 @@
package org.traccar.notification;
+import org.junit.Ignore;
import org.junit.Test;
import javax.mail.Message;
@@ -24,7 +25,8 @@ public class NotificiationMailTest {
private static final int PORT = 25;
- //@Test
+ @Ignore
+ @Test
public void test() throws Exception {
Properties props = System.getProperties();
diff --git a/test/org/traccar/processing/ComputedAttributesTest.java b/test/org/traccar/processing/ComputedAttributesTest.java
index fe898ff54..160067915 100644
--- a/test/org/traccar/processing/ComputedAttributesTest.java
+++ b/test/org/traccar/processing/ComputedAttributesTest.java
@@ -2,11 +2,12 @@ package org.traccar.processing;
import java.util.Date;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.model.Attribute;
import org.traccar.model.Position;
+import static org.junit.Assert.assertEquals;
+
public class ComputedAttributesTest {
@Test
@@ -26,41 +27,41 @@ public class ComputedAttributesTest {
Attribute attribute = new Attribute();
attribute.setExpression("adc1");
- Assert.assertEquals(128, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(128, computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("!booleanFlag");
- Assert.assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("adc2 * 2 + 50");
- Assert.assertEquals(250, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(250, computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("(bitFlag & 4) != 0");
- Assert.assertEquals(true, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(true, computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("if (event == 42) \"lowBattery\"");
- Assert.assertEquals("lowBattery", computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals("lowBattery", computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("speed > 5 && valid");
- Assert.assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(false, computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("fixTime");
- Assert.assertEquals(date, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(date, computedAttributesHandler.computeAttribute(attribute, position));
attribute.setExpression("math:pow(adc1, 2)");
- Assert.assertEquals(16384.0, computedAttributesHandler.computeAttribute(attribute, position));
+ assertEquals(16384.0, computedAttributesHandler.computeAttribute(attribute, position));
// modification tests
attribute.setExpression("adc1 = 256");
computedAttributesHandler.computeAttribute(attribute, position);
- Assert.assertEquals(128, position.getInteger("adc1"));
+ assertEquals(128, position.getInteger("adc1"));
attribute.setExpression("result = \"fail\"");
computedAttributesHandler.computeAttribute(attribute, position);
- Assert.assertEquals("success", position.getString("result"));
+ assertEquals("success", position.getString("result"));
attribute.setExpression("fixTime = \"2017-10-18 10:00:01\"");
computedAttributesHandler.computeAttribute(attribute, position);
- Assert.assertEquals(date, position.getFixTime());
+ assertEquals(date, position.getFixTime());
}
diff --git a/test/org/traccar/protocol/AdmProtocolEncoderTest.java b/test/org/traccar/protocol/AdmProtocolEncoderTest.java
index 6d2452e26..cb0a31ceb 100644
--- a/test/org/traccar/protocol/AdmProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/AdmProtocolEncoderTest.java
@@ -16,11 +16,12 @@
*/
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class AdmProtocolEncoderTest extends ProtocolTest {
@Test
@@ -31,13 +32,13 @@ public class AdmProtocolEncoderTest extends ProtocolTest {
Command command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_GET_DEVICE_STATUS);
- Assert.assertEquals("STATUS\r\n", encoder.encodeCommand(command));
+ assertEquals("STATUS\r\n", encoder.encodeCommand(command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "INPUT 0");
- Assert.assertEquals("INPUT 0\r\n", encoder.encodeCommand(command));
+ assertEquals("INPUT 0\r\n", encoder.encodeCommand(command));
}
}
diff --git a/test/org/traccar/protocol/AplicomFrameDecoderTest.java b/test/org/traccar/protocol/AplicomFrameDecoderTest.java
index e000674db..581f7696f 100644
--- a/test/org/traccar/protocol/AplicomFrameDecoderTest.java
+++ b/test/org/traccar/protocol/AplicomFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class AplicomFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,11 +12,11 @@ public class AplicomFrameDecoderTest extends ProtocolTest {
AplicomFrameDecoder decoder = new AplicomFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("44C20146B710C158DA009500B09F7700C054CA0EA454CA0EA403BE0BF6015D706B070000142A600000000000000002434946010801000754CA0EA4000000000000008400000000000000000000000000000000300000FE00FE0000000000000000000000000000000000000000000000000000000000000000000040502035000000000000020D0000030D0000040C0000040D0000050C0000050D0000058C0000060C"),
decoder.decode(null, null, binary("33353733303030373030393233333644C20146B710C158DA009500B09F7700C054CA0EA454CA0EA403BE0BF6015D706B070000142A600000000000000002434946010801000754CA0EA4000000000000008400000000000000000000000000000000300000FE00FE0000000000000000000000000000000000000000000000000000000000000000000040502035000000000000020D0000030D0000040C0000040D0000050C0000050D0000058C0000060C")));
- Assert.assertEquals(
+ assertEquals(
binary("44C20146B710C158DA009500B09F7700C054CA0EA454CA0EA403BE0BF6015D706B070000142A600000000000000002434946010801000754CA0EA4000000000000008400000000000000000000000000000000300000FE00FE0000000000000000000000000000000000000000000000000000000000000000000040502035000000000000020D0000030D0000040C0000040D0000050C0000050D0000058C0000060C"),
decoder.decode(null, null, binary("44C20146B710C158DA009500B09F7700C054CA0EA454CA0EA403BE0BF6015D706B070000142A600000000000000002434946010801000754CA0EA4000000000000008400000000000000000000000000000000300000FE00FE0000000000000000000000000000000000000000000000000000000000000000000040502035000000000000020D0000030D0000040C0000040D0000050C0000050D0000058C0000060C")));
diff --git a/test/org/traccar/protocol/AquilaProtocolDecoderTest.java b/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
index 8844dafd2..8984cfcb3 100644
--- a/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/AquilaProtocolDecoderTest.java
@@ -6,11 +6,14 @@ import org.traccar.ProtocolTest;
public class AquilaProtocolDecoderTest extends ProtocolTest {
@Test
- public void testDecode() throws Exception {
+ public void testDecodeA() throws Exception {
AquilaProtocolDecoder decoder = new AquilaProtocolDecoder(new AquilaProtocol());
verifyPosition(decoder, text(
+ "$$CLIENT_1ZF,170215089,20,18.462809,73.824188,170613182744,A,01,123456,*37"));
+
+ verifyPosition(decoder, text(
"$$CLIENT_1ZF,170215089,1,18.462809,73.824188,170613182744,A,19,0,0,256,4,4.860000,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,259,3731,*37"));
verifyPosition(decoder, text(
@@ -48,4 +51,20 @@ public class AquilaProtocolDecoderTest extends ProtocolTest {
}
+ @Test
+ public void testDecodeB() throws Exception {
+
+ AquilaProtocolDecoder decoder = new AquilaProtocolDecoder(new AquilaProtocol());
+
+ verifyPosition(decoder, text(
+ "$Header,nliven,1_37T02B0164MAIS,BR,6,L,861693034634154,KA01I2000,1,09112017,160702,12.976593,N,77.549782,E,25.1,344,15,911.0,1.04,0.68,Airtel,1,1,11.8,3.8,1,C,24,404,45,61b4,9ad9,31,9adb,61b4,35,ffff,0000,33,ffff,0000,31,ffff,0000,0001,00,000014,0.0,0.1,4,()*1E"));
+
+ verifyPosition(decoder, text(
+ "$Header,iTriangle,1_37T02B0164MAIS_2,NR,1,L,864495034490141,KA01I2000,1,31032018,122247,22.845999,N,75.949005,E,0.0,44,16,545.0,1.19,0.65,AirTel,1,1,12.0,4.3,0,C,13,404,93,0456,16db,27,16dd,0456,22,3843,18ab,19,ebd8,0458,14,072c,18ab,0101,00,003735,0.0,0.0,0,()*48"));
+
+ verifyNull(decoder, text(
+ "$Header,nliven,KA01I2000,861693034634154,1_37T02B0164MAIS,AIS140,12.976545,N,77.549759,E*50"));
+
+ }
+
}
diff --git a/test/org/traccar/protocol/At2000FrameDecoderTest.java b/test/org/traccar/protocol/At2000FrameDecoderTest.java
index c7a3dc0b1..5613f832e 100644
--- a/test/org/traccar/protocol/At2000FrameDecoderTest.java
+++ b/test/org/traccar/protocol/At2000FrameDecoderTest.java
@@ -1,11 +1,12 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import java.nio.ByteOrder;
+import static org.junit.Assert.assertEquals;
+
public class At2000FrameDecoderTest extends ProtocolTest {
@Test
@@ -13,11 +14,11 @@ public class At2000FrameDecoderTest extends ProtocolTest {
At2000FrameDecoder decoder = new At2000FrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary(ByteOrder.LITTLE_ENDIAN, "01012f00000000000000000000000000003335363137333036343430373439320fad981997ae8e031fe10c0ea7641903ca32c0331df467233d2a9cd886fbeef8"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "01012f00000000000000000000000000003335363137333036343430373439320fad981997ae8e031fe10c0ea7641903ca32c0331df467233d2a9cd886fbeef8")));
- Assert.assertEquals(
+ assertEquals(
binary(ByteOrder.LITTLE_ENDIAN, "893f0000000000000000000000000000e048b1a31deba3f5dbe8877f574877e6ed4d022b6611a10d80dfc4c0c11fa8aacf4a9de61528327e2b66843dd9c5d3a7cc9ee1d9c71a34bb482145d88b4fda3e"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "893f0000000000000000000000000000e048b1a31deba3f5dbe8877f574877e6ed4d022b6611a10d80dfc4c0c11fa8aacf4a9de61528327e2b66843dd9c5d3a7cc9ee1d9c71a34bb482145d88b4fda3e")));
diff --git a/test/org/traccar/protocol/AtrackFrameDecoderTest.java b/test/org/traccar/protocol/AtrackFrameDecoderTest.java
index 93e804dc9..9db4fd052 100644
--- a/test/org/traccar/protocol/AtrackFrameDecoderTest.java
+++ b/test/org/traccar/protocol/AtrackFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class AtrackFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,15 +12,15 @@ public class AtrackFrameDecoderTest extends ProtocolTest {
AtrackFrameDecoder decoder = new AtrackFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("244F4B0D0A"),
decoder.decode(null, null, binary("244F4B0D0A")));
- Assert.assertEquals(
+ assertEquals(
binary("fe0200014104d8f196820001"),
decoder.decode(null, null, binary("fe0200014104d8f196820001")));
- Assert.assertEquals(
+ assertEquals(
binary("40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000"),
decoder.decode(null, null, binary("40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000")));
diff --git a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java
index b5271f511..bd606c320 100644
--- a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class AtrackProtocolDecoderTest extends ProtocolTest {
AtrackProtocolDecoder decoder = new AtrackProtocolDecoder(new AtrackProtocol());
+ verifyPositions(decoder, binary(
+ "4050b5ed004a2523000310c83713f8c05a88b43e5a88b43f5a88b43f021e0ad5fffdc0a800f3020003059100080000000000000007d007d046554c533a463d3230393120743d3137204e3d3039303100"));
+
verifyAttributes(decoder, buffer(
"$INFO=358683066267395,AX7,Rev.0.61 Build.1624,358683066267395,466924131626767,89886920041316267670,144,0,9,1,12,1,0\r\n"));
diff --git a/test/org/traccar/protocol/CastelProtocolDecoderTest.java b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
index bdf69e1af..cb44087a1 100644
--- a/test/org/traccar/protocol/CastelProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/CastelProtocolDecoderTest.java
@@ -12,6 +12,18 @@ public class CastelProtocolDecoderTest extends ProtocolTest {
CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol());
+ verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "4040560004323133474c3230313630303033363400000000004002a122a05a5423a05abe0f2a000000000007f1f90014000000040001640011170003001e000505210b210c210d210f2101062b58ef02001a25950d0a"));
+
+ verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "404057000431303031313132353239393837000000000000004002C1F06952F0F169529C9111000000000069830000470000000400036401014C01030078000505210C210D210F21102101073BE8030064280AEB930D0A"));
+
+ verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "40405f000536303331353030303335313200000000000000004001040212102a2f72b29302a0af8512b40787018e000000000043e4ae000000007ca0f7224d5049503632305f56312e312e30004d5049502d3632302056322e300072140d0a"));
+
+ verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "24245000363137313135313243333133360000000000000040011b011207133ac49a390464514a15000000008e480c00000917000000000000ffafffaf00010000ffff7800ffffffffffffff003c0d0a"));
+
verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"40408200033231334c32303137303031313039000000000000100136477b5964477b590400000000000000dc410f000000000204000709207910008304011c07110e110dd41a160714a95a0f00001e058c4944442d3231334c2056312e312e3120323031372d30352d3038004944442d3231334c2056312e312e300000006da10d0a"));
diff --git a/test/org/traccar/protocol/CastelProtocolEncoderTest.java b/test/org/traccar/protocol/CastelProtocolEncoderTest.java
new file mode 100644
index 000000000..bcb93a010
--- /dev/null
+++ b/test/org/traccar/protocol/CastelProtocolEncoderTest.java
@@ -0,0 +1,22 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+import org.traccar.model.Command;
+
+public class CastelProtocolEncoderTest extends ProtocolTest {
+
+ @Test
+ public void testEncode() throws Exception {
+
+ CastelProtocolEncoder encoder = new CastelProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_ENGINE_STOP);
+
+ verifyCommand(encoder, command, binary("40402000013132333435363738393031323334350000000000458301a94a0d0a"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/CautelaProtocolDecoderTest.java b/test/org/traccar/protocol/CautelaProtocolDecoderTest.java
new file mode 100644
index 000000000..4fd785c9f
--- /dev/null
+++ b/test/org/traccar/protocol/CautelaProtocolDecoderTest.java
@@ -0,0 +1,18 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class CautelaProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ CautelaProtocolDecoder decoder = new CautelaProtocolDecoder(new CautelaProtocol());
+
+ verifyPosition(decoder, text(
+ "20,010907000000,14,02,18,16.816667,96.166667,1325,S,*2E"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/ContinentalProtocolDecoderTest.java b/test/org/traccar/protocol/ContinentalProtocolDecoderTest.java
new file mode 100644
index 000000000..fbc7c3219
--- /dev/null
+++ b/test/org/traccar/protocol/ContinentalProtocolDecoderTest.java
@@ -0,0 +1,25 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class ContinentalProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ ContinentalProtocolDecoder decoder = new ContinentalProtocolDecoder(new ContinentalProtocol());
+
+ verifyPosition(decoder, binary(
+ "5356002A1100003039030243A68B5700FEB5AB00FD715F012700000143A68B57000E000000000C2F00000130"),
+ position("2005-12-19 10:28:39.000", true, -23.49027, -46.55138));
+
+ verifyPosition(decoder, binary(
+ "5356002a0d0010a12403025a9ea47f00feb48400fd6e63000c0000015a9ea480000e000100000c000000"));
+
+ verifyPosition(decoder, binary(
+ "5356002a0d0010a1240302581b944100febed800fd9fa30139001300581c73fa000e000000000d000001"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/DmtProtocolDecoderTest.java b/test/org/traccar/protocol/DmtProtocolDecoderTest.java
index 2575d77ed..2e386c48e 100644
--- a/test/org/traccar/protocol/DmtProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/DmtProtocolDecoderTest.java
@@ -13,6 +13,15 @@ public class DmtProtocolDecoderTest extends ProtocolTest {
DmtProtocolDecoder decoder = new DmtProtocolDecoder(new DmtProtocol());
verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0255003300001b00003335333232393032373533393235310038393931353030303030303030313330343539340000000403041910780603"));
+
+ verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN,
+ "02551040000eaca40d00d2b8e562c51f9912f39a6bee00007e420091090903070100000000008b1065360000000000007fd401c4fcf2feffffffffffffffffee0000003f1b"));
+
+ verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN,
+ "02551080000eada40d00d2b8e58ac51f9912f39a6bee00007e42007e090709070000000000009010fc330000000000007fc201a0fc04ffffffffffffffffffe5000000c5d00eaea40d00d2b8e58ac51f9912f39a6bee00007e42007e09070207000000000000851008340000000000007fc201a0fc04ff0000000000000000e5000000c96d"));
+
+ verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"025500310038f90100333533333233303831363639373330003839363130313835303031383234383434363330002202010900000000"));
verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
diff --git a/test/org/traccar/protocol/EgtsFrameDecoderTest.java b/test/org/traccar/protocol/EgtsFrameDecoderTest.java
new file mode 100644
index 000000000..91a53525e
--- /dev/null
+++ b/test/org/traccar/protocol/EgtsFrameDecoderTest.java
@@ -0,0 +1,21 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+import java.nio.ByteOrder;
+
+public class EgtsFrameDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ EgtsFrameDecoder decoder = new EgtsFrameDecoder();
+
+ verifyFrame(
+ binary("0100020B0025003A5701C91A003A5701CD6E68490202101700CBB4740F7617FD924364104F116A0000000000010300001EC2"),
+ decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "0100020B0025003A5701C91A003A5701CD6E68490202101700CBB4740F7617FD924364104F116A0000000000010300001EC2")));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/EgtsProtocolDecoderTest.java b/test/org/traccar/protocol/EgtsProtocolDecoderTest.java
new file mode 100644
index 000000000..af69f321e
--- /dev/null
+++ b/test/org/traccar/protocol/EgtsProtocolDecoderTest.java
@@ -0,0 +1,36 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+import java.nio.ByteOrder;
+
+public class EgtsProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ EgtsProtocolDecoder decoder = new EgtsProtocolDecoder(new EgtsProtocol());
+
+ verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0100010b002200c06401f21700c1640171360d00010101140071360d000238363539303500000000000000000047fc"));
+
+ verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0100000b002400a0d601f01900030081030000000101011600030000004238363434393530333436343333373600014cdc"));
+
+ verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0100010b00a308c26401029808c3640171360d000202101800e19a7b0fcfb4c49a0bfdb87a911801b70000000010d90000180400021c0000120300000000101800f39a7b0f2fc9c39a9bf2b87a914001b50000000010da0000180400021c0000120300000000101800fa9a7b0fc663c39a21eeb87a914001b60000000010da0000180400021c0000120300000000101800069b7b0f56d8c29a26ebb87a919600ab0000000010da0000180400021c00001203000000001018000a9b7b0fb2c5c29a19f4b87a915a007d0000000010da0000180400021c0000120300000000101800089b7b0f68ccc29a21eeb87a9164008f0000000010da0000180400021c0000120300000000101800079b7b0fa0d1c29aa4ecb87a918200980000000010da0000180400021c00001203000000001018000b9b7b0f34c4c29ad3f7b87a915a00670000000010da0000180400021c00001203000000001018000f9b7b0f3dbec29aaf0fb97a91c8005e0000000010dc0000180400021c0000120300000000101800199b7b0f42bbc29a0855b97a9178006b0000000010db0000180400021c00001203000000001018001b9b7b0fc8b6c29a3c5db97a916e007e0000000010db0000180400021c00001203000000001018001a9b7b0fc4b9c29a8159b97a916e00750000000010db0000180400021c00001203000000001018001d9b7b0f94aec29a3363b97a916400930000000010db0000180400021c00001203000000001018001c9b7b0fcdb3c29a3760b97a916e008a0000000010db0000180400021c0000120300000000101800209b7b0f28a1c29af263b97a918200ba0000000010db0000180400021c00001203000000001018001f9b7b0f61a6c29af263b97a917800b30000000010db0000180400021c00001203000000001018001e9b7b0f58acc29af263b97a916400a50000000010db0000180400021c0000120300000000101800299b7b0ff26fc29ab561b97a916e00b20000000010d90000180400021c00001203000000001018002d9b7b0fd05bc29a3760b97a916e00bd0000000010d80000180400021c0000120300000000101800359b7b0f4f31c29abe5bb97a916400b50000000010d70000180400021c0000120300000000101800379b7b0f5d28c29abe5bb97a916e00b40000000010d60000180400021c0000120300000000101800369b7b0fd62cc29abe5bb97a916400bd0000000010d60000180400021c00001203000000001018003c9b7b0fca09c29a0358b97a918c00bc0000000010d50000180400021c0000120300000000101800419b7b0f38ebc19a0855b97a916e00b40000000010d60000180400021c0000120300000000101800449b7b0f4edcc19a8a53b97a916400c30000000010d60000180400021c0000120300000000101800469b7b0fded1c19acb52b97a916e00b70000000010d60000180400021c0000120300000000101800649b7b0f7a69c19a154cb97a810000bc0000000010d60000180400021c0000120300000000101800709b7b0fcc5cc19a114fb97a915000970000000010d70000180400021c0000120300000000101800729b7b0fda53c19a8a53b97a91a0007d0000000010d70000180400021c0000120300000000101800749b7b0fa24ec19a3c5db97a91a000650000000010d70000180400021c0000120300000000101800789b7b0fe74ac19aca7eb97a910e015c0000000010d80000180400021c00001203000000001018007f9b7b0f6e46c19a78e0b97a9190015c0000000010d80000180400021c0000120300000000101800869b7b0f3641c19a144eba7a9190015c0000000010d60000180400021c00001203000000001018008d9b7b0ffd3bc19a74b9ba7a9190015c0000000010d40000180400021c0000120300000000101800949b7b0fc536c19a1524bb7a9186015b0000000010d20000180400021c00001203000000001018009b9b7b0fce30c19af78dbb7a919a015c0000000010d00000180400021c0000120300000000101800a29b7b0f552cc19a93fbbb7a9172015d0000000010cd0000180400021c0000120300000000101800b09b7b0f2521c19a6ec0bc7a9186015b0000000010c90000180400021c0000120300000000101800a99b7b0f5e26c19a8759bc7a915e015b0000000010cb0000180400021c0000120300000000101800b79b7b0fa81fc19a1328bd7a9172015b0000000010c70000180400021c0000120300000000101800be9b7b0f6b1dc19ac686bd7a914a015c0000000010c60000180400021c0000120300000000101800c19b7b0fed1bc19ad2a9bd7a912201530000000010c60000180400021c0000120300000000101800c39b7b0f6223c19af4bdbd7a910401420000000010c60000180400021c0000120300000000101800c29b7b0fe91ec19a42b4bd7a910e014c0000000010c60000180400021c0000120300000000101800c59b7b0f502fc19a1acfbd7a91fa00300000000010c60000180400021c0000120300000000101800c49b7b0fdb27c19ae6c6bd7a91fa00390000000010c60000180400021c0000120300000000101800c79b7b0fb83fc19a8ad9bd7a91f000180000000010c60000180400021b0000120300000000101800c69b7b0fc536c19a52d4bd7a91f000250000000010c60000180400021b0000120300000000101800ca9b7b0fc85fc19a81dfbd7a910401030000000010c50000180400021b0000120300000000101800c89b7b0fe74ac19a86dcbd7a91fa000e0000000010c50000180400021b0000120300000000101800d29b7b0f06b7c19afbe3bd7a91a000100000000010c50000180400021c0000120300000000101800d59b7b0ff0c5c19a6beebd7a91b400410000000010c40000180400021c0000120300000000101800d49b7b0ff4c2c19af2e9bd7a91a000310000000010c40000180400021c0000120300000000101800d39b7b0f3ebcc19a79e5bd7a9196001e0000000010c40000180400021c0000120300000000101800d69b7b0f6dc7c19ae0f5bd7a91c800570000000010c40000180400021c000012030000000016b7"));
+
+ verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0100020B0025003A5701C91A003A5701CD6E68490202101700CBB4740F7617FD924364104F116A0000000000010300001EC2"),
+ position("2018-03-21 05:38:19.000", true, 51.67569, 55.59189));
+
+ verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0100020B0079000000011F6A001424951CA5CB0F23B5740F020210180023B5740F0A301994DA9C524C9128000A000000100082000011040018110300120900000003150100E803001B0700010000340900001B0700420000000000001B0700430000000000001B0700440000000000001B0700450000000000001B0700460000000000008020"));
+
+ verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "0100020B00F200000001D66A001224951CA5CB0FFCB4740F0202101800FCB4740F502119943D9F524C9119805C000000100084000011040018110300120900000003150100E803001B0700410000000000001B0700420000000000001B0700430000000000001B0700440000000000001B0700450000000000001B0700460000000000006A001324951CA5CB0F05B5740F020210180005B5740F222519942D9E524C9100008B000000100083000011040018110300120900000003160100E803001B0700010000310900001B0700420000000000001B0700430000000000001B0700440000000000001B0700450000000000001B070046000000000000134E"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/EskyFrameDecoderTest.java b/test/org/traccar/protocol/EskyFrameDecoderTest.java
index e8902e8be..3b16a9051 100644
--- a/test/org/traccar/protocol/EskyFrameDecoderTest.java
+++ b/test/org/traccar/protocol/EskyFrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/GalileoFrameDecoderTest.java b/test/org/traccar/protocol/GalileoFrameDecoderTest.java
index 1decd73d3..7a7c97ba6 100644
--- a/test/org/traccar/protocol/GalileoFrameDecoderTest.java
+++ b/test/org/traccar/protocol/GalileoFrameDecoderTest.java
@@ -1,11 +1,12 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import java.nio.ByteOrder;
+import static org.junit.Assert.assertEquals;
+
public class GalileoFrameDecoderTest extends ProtocolTest {
@Test
@@ -13,11 +14,11 @@ public class GalileoFrameDecoderTest extends ProtocolTest {
GalileoFrameDecoder decoder = new GalileoFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary(ByteOrder.LITTLE_ENDIAN, "011780011102e603383633353931303238393630323437043200801c"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "011780011102e603383633353931303238393630323437043200801c")));
- Assert.assertEquals(
+ assertEquals(
binary(ByteOrder.LITTLE_ENDIAN, "01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "01d48304320010020520a5829f58300f50dc8a024c0965013300000000344102350740003a41e14b426610431b4459fa672a4500004601a050364c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e293000000043200100105202d829f58300f50dc8a024c0965013300000000344102350740003a41d04b426110431b445702882a4500004601a050374c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29400000004320010000520b5819f58300f50dc8a024c0965013300000000344102350740003a419e4b426a10431c4456fab72a4500004601a050434c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010ff04203d819f58300f50dc8a024c0965013300000000344102350740003a41874b426310431c4454fe572a4500004601a050334c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29600000004320010fe0420c5809f58300f50dc8a024c0965013300000000344102350840003a41a24b426710431c4457fea72a4500004601a050214c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fd04204d809f58300f50dc8a024c0965013300000000344102350840003a41a34b426310431c4455f6772a4500004601a0502e4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29900000004320010fc0420d57f9f58300f50dc8a024c0965013300000000344102350840003a41bd4b426510431d4458fe672a4500004601a0501f4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29700000004320010fb04205d7f9f58300f50dc8a024c0965013300000000344102350840003a41b54b426310431d4456fa772a4500004601a0502d4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29500000004320010fa0420e57e9f58300f50dc8a024c0965013300000000344102350840003a41b24b426210431e4454fa872a4500004601a050fe4b510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e29000000004320010f904206d7e9f58300f50dc8a024c0965013300000000344102350a40003a41af4b426710431f4458fea72a4500004601a0500a4c510000520000530000c000000000c100000000c200000000c300000000d80000dd00000000e28900000067c5")));
diff --git a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java
index e2e9f0ca3..6f2f1f90a 100644
--- a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java
@@ -13,6 +13,9 @@ public class GalileoProtocolDecoderTest extends ProtocolTest {
GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(new GalileoProtocol());
verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN,
+ "01560003383636303530303338343337353836044701e000000000e13c494e414c4c3a696e303d31313230362c696e313d302c696e323d302c696e333d302c696e343d302c696e353d302c4163633d3536363932343732353bfdef"));
+
+ verifyPositions(decoder, false, binary(ByteOrder.LITTLE_ENDIAN,
"012a0003383633353931303233353137333732046600e000000000e1104f555428332e2e3029203d2031313130bb29"));
verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
diff --git a/test/org/traccar/protocol/GatorProtocolDecoderTest.java b/test/org/traccar/protocol/GatorProtocolDecoderTest.java
index 6d4dc06e8..360a3abed 100644
--- a/test/org/traccar/protocol/GatorProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GatorProtocolDecoderTest.java
@@ -1,15 +1,16 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class GatorProtocolDecoderTest extends ProtocolTest {
@Test
public void testDecodeId() {
- Assert.assertEquals("3512345006", GatorProtocolDecoder.decodeId(12, 162, 50, 134));
+ assertEquals("3512345006", GatorProtocolDecoder.decodeId(12, 162, 50, 134));
}
diff --git a/test/org/traccar/protocol/Gl200FrameDecoderTest.java b/test/org/traccar/protocol/Gl200FrameDecoderTest.java
index 54c35f084..e90c6495a 100644
--- a/test/org/traccar/protocol/Gl200FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Gl200FrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class Gl200FrameDecoderTest extends ProtocolTest {
@Test
@@ -11,15 +12,15 @@ public class Gl200FrameDecoderTest extends ProtocolTest {
Gl200FrameDecoder decoder = new Gl200FrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("2b41434b017f244501010108676231303000000000ffff07e1070b03112d054dfe030d0a"),
decoder.decode(null, null, binary("2b41434b017f244501010108676231303000000000ffff07e1070b03112d054dfe030d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2b4556540c00fc1fbf005c4501010108563254030003430564312a41090100000000003f007dff75a11a025c6a7807e1070a14041202680003189c1ac500000000000000000000000000000000000007e1070b041134054e5c6e0d0a"),
decoder.decode(null, null, binary("2b4556540c00fc1fbf005c4501010108563254030003430564312a41090100000000003f007dff75a11a025c6a7807e1070a14041202680003189c1ac500000000000000000000000000000000000007e1070b041134054e5c6e0d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2b524553503a47545354522c3430303330302c3836323336353033303134323238392c474c3530302c302c302c302c33392e342c39332c312c302e332c31372c3130352e382c32352e3934343234302c34342e3430333733362c32303137303532393134303533302c303232362c303030312c353643322c373038342c2c2c2c32303137303532393136303533302c30324441"),
decoder.decode(null, null, binary("2b524553503a47545354522c3430303330302c3836323336353033303134323238392c474c3530302c302c302c302c33392e342c39332c312c302e332c31372c3130352e382c32352e3934343234302c34342e3430333733362c32303137303532393134303533302c303232362c303030312c353643322c373038342c2c2c2c32303137303532393136303533302c3032444124")));
diff --git a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java
index d9e36ef47..56a159768 100644
--- a/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gl200TextProtocolDecoderTest.java
@@ -10,6 +10,15 @@ public class Gl200TextProtocolDecoderTest extends ProtocolTest {
Gl200TextProtocolDecoder decoder = new Gl200TextProtocolDecoder(new Gl200Protocol());
+ verifyPositions(decoder, buffer(
+ "+RESP:GTERI,310603,863286023345490,,00000002,,10,1,2,0.3,0,155.7,8.000000,52.000000,20171215213040,0262,0002,1450,9F13,00,1130.3,00539:27:19,,,110000,2,1,28FFD5239115034E,1,,20171215213041,27C7$"));
+
+ verifyPositions(decoder, buffer(
+ "+RESP:GTERI,250C02,868789023691057,,00000019,,10,1,1,0.0,196,2258.0,-99.201807,19.559242,20180214002957,0334,0003,235B,7F8D,00,6786.7,,,,100,110000,1,0394,1,4,100.0,100.0,20180214003006,C72B$"));
+
+ verifyAttributes(decoder, buffer(
+ "+RESP:GTCAN,310603,863286023335723,gv65,00,1,C03FFFFF,,0,,719601.00,,,,,,,,274.99,179.02,95.98,84761.00,,,0,,0,,,0,0.0,216,29.8,-2.155296,51.899400,20180209172714,0234,0010,53F3,8D38,00,20180211002128,E94E$"));
+
verifyAttributes(decoder, buffer(
"+RESP:GTCAN,310201,153759012347650,gv65,0,1,C03FFFFF,,2,H89394,63.14,200,0,87,,P43.60,0,0,17.53,11.61,5.92,0.00,0,0,4002,0,1,0.76,35.00,0,,,,0,0,,0000,0000,0000,0000,00,20040101000052,05A6$"));
diff --git a/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java b/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java
index fb9928d75..c2d5ba4e2 100644
--- a/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GlobalSatProtocolDecoderTest.java
@@ -38,9 +38,6 @@ public class GlobalSatProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"$353681041893264,9,3,240913,100833,E08513.0122,N5232.9395,181.3,22.02,251.30,9,1.00"));
- /*verifyPosition(decoder, text(
- "$353681041893264,9,4,230913,052449,\"250,99,B443,422E,42,37\",\"250,99,B443,4232,43,44\",\"250,99,B443,7910,40,32\",\"250,99,B443,B456,40,28\",\"250,99,B443,B455,40,27\""));*/
-
decoder.setFormat0("SPRXYAB27GHKLMmnaefghiotuvwb*U!");
verifyPosition(decoder, text(
diff --git a/test/org/traccar/protocol/GlobeKeeperProtocolDecoderTest.java b/test/org/traccar/protocol/GlobeKeeperProtocolDecoderTest.java
new file mode 100644
index 000000000..918fd9083
--- /dev/null
+++ b/test/org/traccar/protocol/GlobeKeeperProtocolDecoderTest.java
@@ -0,0 +1,33 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class GlobeKeeperProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ GlobeKeeperProtocolDecoder decoder = new GlobeKeeperProtocolDecoder(new GlobeKeeperProtocol());
+
+ verifyPosition(decoder, text(
+ "48666666666;2017-01-01 16:31:01;52,1133308410645;21,1000003814697;310;120;2292;1"));
+
+ verifyPosition(decoder, text(
+ "48666666666;2017-01-01 16:55:00;52,1636123657227;21,0827789306641;0;90;4000;0"));
+
+ verifyPosition(decoder, text(
+ "48666666666;2017-01-01 17:32:01;52,1711120605469;21,0866680145264;70;90;1199;0"));
+
+ verifyPosition(decoder, text(
+ "48601601601;2017-01-01 16:31:01;52,1133308410645;21,1000003814697;310;360;2292;1"));
+
+ verifyPosition(decoder, text(
+ "48601601601;2017-01-01 16:55:00;52,1636123657227;21,0827789306641;0;360;4000;0"));
+
+ verifyPosition(decoder, text(
+ "48601601601;2017-01-01 17:32:01;52,1711120605469;21,0866680145264;70;360;1199;0"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
index 42293f7ec..5485368b9 100644
--- a/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/GoSafeProtocolDecoderTest.java
@@ -11,6 +11,15 @@ public class GoSafeProtocolDecoderTest extends ProtocolTest {
GoSafeProtocolDecoder decoder = new GoSafeProtocolDecoder(new GoSafeProtocol());
verifyPositions(decoder, text(
+ "*GS06,860078024287174,070120310318,,SYS:G3SC;V3.32;V1.1.8,GPS:A;9;N23.169946;E113.450568;0;0;23;0.86,COT:65;20,ADC:4.27;3.73;0.01;0.02,DTT:4004;E0;0;0;0;1,IWD:0;0;000000000000#"));
+
+ verifyPositions(decoder, text(
+ "*GS06,860078024213915,032544190318,,SYS:G3SC;V3.32;V1.1.8,GPS:A;7;N3.052417;E101.787112;0;0;94;1.38,COT:686;0-0-0,ADC:16.25;4.09,DTT:4000;E0;0;0;0;1#"));
+
+ verifyPositions(decoder, text(
+ "*GS06,351535058659335,062728190318,,SYS:G6S;V3.32;V1.0.5,GPS:A;10;N23.169806;E113.450760;0;0;81;0.77,COT:0,ADC:0.00;0.16,DTT:80;E0;0;0;0;1#"));
+
+ verifyPositions(decoder, text(
"*GS26,356449061046586,082522030117,,SYS:G737IC;V1.13;V1.0.5,GPS:V;5;N42.594136;W70.723832;0;0;8;2.06,GSM:;;310;260;C76D;9F1D;-85,ADC:3.86,DTT:3918C;;0;0;0;1,#"));
verifyPositions(decoder, text(
diff --git a/test/org/traccar/protocol/Gps056FrameDecoderTest.java b/test/org/traccar/protocol/Gps056FrameDecoderTest.java
index a5b5c5bbd..ce21f733f 100644
--- a/test/org/traccar/protocol/Gps056FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Gps056FrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class Gps056FrameDecoderTest extends ProtocolTest {
@Test
@@ -11,11 +12,11 @@ public class Gps056FrameDecoderTest extends ProtocolTest {
Gps056FrameDecoder decoder = new Gps056FrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("242435314750534c5f30323836323436323033333738323934361905110f160b0b7710584e1cbd1b9b4500005b100300fb0a071700ffff23"),
decoder.decode(null, null, binary("242435314750534c5f30323836323436323033333738323934361905110f160b0b7710584e1cbd1b9b4500005b100300fb0a071700ffff230030")));
- Assert.assertEquals(
+ assertEquals(
binary("242432354c4f474e5f3131383632343632303333373832393436322e3123"),
decoder.decode(null, null, binary("242432354c4f474e5f3131383632343632303333373832393436322e3123")));
diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
index acafe3982..17ed8da56 100644
--- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java
@@ -10,6 +10,12 @@ public class Gps103ProtocolDecoderTest extends ProtocolTest {
Gps103ProtocolDecoder decoder = new Gps103ProtocolDecoder(new Gps103Protocol());
+ verifyNotNull(decoder, text(
+ "imei:864895030279986,ac alarm,180404174252,,L,,,296a,,51f7,,,"));
+
+ verifyAttributes(decoder, text(
+ "imei:359710048977327,OBD,180301094003,5000000,0.00,0.00,98,18,68.63%,55,25.10%,1368,14.24,,,,;"));
+
verifyAttributes(decoder, text(
"imei:862106025092216,OBD,170605095949,195874,,370.8,808,066,30.0%,+87,13.0%,02444,14.3,,,,;"));
diff --git a/test/org/traccar/protocol/Gps103ProtocolEncoderTest.java b/test/org/traccar/protocol/Gps103ProtocolEncoderTest.java
index 54c520c21..f888ee252 100644
--- a/test/org/traccar/protocol/Gps103ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Gps103ProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class Gps103ProtocolEncoderTest extends ProtocolTest {
@Test
@@ -17,7 +18,7 @@ public class Gps103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_POSITION_PERIODIC);
command.set(Command.KEY_FREQUENCY, 300);
- Assert.assertEquals("**,imei:123456789012345,C,05m", encoder.encodeCommand(command));
+ assertEquals("**,imei:123456789012345,C,05m", encoder.encodeCommand(command));
}
@@ -31,7 +32,7 @@ public class Gps103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "H,080");
- Assert.assertEquals("**,imei:123456789012345,H,080", encoder.encodeCommand(command));
+ assertEquals("**,imei:123456789012345,H,080", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/GranitFrameDecoderTest.java b/test/org/traccar/protocol/GranitFrameDecoderTest.java
index cf84c2026..130b9dbd7 100644
--- a/test/org/traccar/protocol/GranitFrameDecoderTest.java
+++ b/test/org/traccar/protocol/GranitFrameDecoderTest.java
@@ -2,10 +2,11 @@ package org.traccar.protocol;
import java.nio.ByteOrder;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class GranitFrameDecoderTest extends ProtocolTest {
@Test
@@ -13,33 +14,33 @@ public class GranitFrameDecoderTest extends ProtocolTest {
GranitFrameDecoder decoder = new GranitFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("2b525243427e1a003e2934757c57b8b03c38d279b4e61e9bd7006b000000001c00002a4533"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "2b525243427e1a003e2934757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a4533"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("4f4b"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "4f4b0d0a2b525243427e1a000d0a34757c57b8b03c38d279b4e61e9bd7006b000000001c00002a45330d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2b444441547e84003e290401d01690737c57b8903c383c7fa0e5081b64006b000000001c0000b8803c388e7fe7e5102197006c000000001c0000b8813c38ad7f02e6042035006c000000001d0000b8813c38bf7f13e6001d1e006c000000001d0000b8813c38bf7f13e6001d00006c000000001d0000b8903c38977f34e6091065006c000000001e000014002a3932"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN,
"2b444441547e84003e290401d01690737c57b8903c383c7fa0e5081b64006b000000001c0000b8803c388e7fe7e5102197006c000000001c0000b8813c38ad7f02e6042035006c000000001d0000b8813c38bf7f13e6001d1e006c000000001d0000b8813c38bf7f13e6001d00006c000000001d0000b8903c38977f34e6091065006c000000001e000014002a39320d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2b444441547e84003e290401d41680747c57f8a03c38987f50e6005300006c000000001c0000f8b03c38987f50e6005300006c000000001c0000fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe14002a4346"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN,
"2b444441547e84003e290401d41680747c57f8a03c38987f50e6005300006c000000001c0000f8b03c38987f50e6005300006c000000001c0000fefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefefe14002a43460d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2b49444e543a204e6176696761746f722e30347820204669726d776172652076657273696f6e202030373132474c4e202a3231"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "2b49444e543a204e6176696761746f722e30347820204669726d776172652076657273696f6e202030373132474c4e202a32310d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("4552524f522057524f4e4720434845434b53554d5f31"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "4552524f522057524f4e4720434845434b53554d5f310d0a")));
diff --git a/test/org/traccar/protocol/Gt06FrameDecoderTest.java b/test/org/traccar/protocol/Gt06FrameDecoderTest.java
index 97230695a..cf6d1cfd7 100644
--- a/test/org/traccar/protocol/Gt06FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Gt06FrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/H02FrameDecoderTest.java b/test/org/traccar/protocol/H02FrameDecoderTest.java
index 3ced35d53..bdb2ff37b 100644
--- a/test/org/traccar/protocol/H02FrameDecoderTest.java
+++ b/test/org/traccar/protocol/H02FrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class H02FrameDecoderTest extends ProtocolTest {
@Test
@@ -11,23 +12,23 @@ public class H02FrameDecoderTest extends ProtocolTest {
H02FrameDecoder decoder = new H02FrameDecoder(0);
- Assert.assertEquals(
+ assertEquals(
binary("2a48512c3335353438383032303131333931312c56312c3031323934352c412c353233312e37393238332c4e2c30313332342e31303731382c452c302e30352c302c3137303231372c464646464646464623"),
decoder.decode(null, null, binary("2a48512c3335353438383032303131333931312c56312c3031323934352c412c353233312e37393238332c4e2c30313332342e31303731382c452c302e30352c302c3137303231372c4646464646464646230d0a")));
- Assert.assertEquals(
+ assertEquals(
binary("2441060116601245431311165035313006004318210e000000fffffbffff0024"),
decoder.decode(null, null, binary("2441060116601245431311165035313006004318210e000000fffffbffff0024")));
- Assert.assertEquals(
+ assertEquals(
binary("2441060116601245431311165035313006004318210e000000fffffbffff0024"),
decoder.decode(null, null, binary("2441060116601245431311165035313006004318210e000000fffffbffff00242a48512c343130363031313636302c56312c3132343535322c412c353033352e333132392c4e2c30303433312e383231312c452c3030302e32302c3030302c3133313131362c464646464642464623")));
- Assert.assertEquals(
+ assertEquals(
binary("2a48512c3335333538383036303031353536382c56312c3139333530352c412c3830392e303031302c532c333435342e383939372c572c302e30302c302e30302c3239313031332c65666666666266662c3030303264342c3030303030622c3030353338352c3030353261612c323523"),
decoder.decode(null, null, binary("2a48512c3335333538383036303031353536382c56312c3139333530352c412c3830392e303031302c532c333435342e383939372c572c302e30302c302e30302c3239313031332c65666666666266662c3030303264342c3030303030622c3030353338352c3030353261612c323523")));
- Assert.assertEquals(
+ assertEquals(
binary("24430025645511183817091319355128000465632432000100ffe7fbffff0000"),
decoder.decode(null, null, binary("24430025645511183817091319355128000465632432000100ffe7fbffff0000")));
@@ -38,7 +39,7 @@ public class H02FrameDecoderTest extends ProtocolTest {
H02FrameDecoder decoder = new H02FrameDecoder(0);
- Assert.assertEquals(
+ assertEquals(
binary("24410600082621532131081504419390060740418306000000fffffbfdff0015060000002c02dc0c000000001f"),
decoder.decode(null, null, binary("24410600082621532131081504419390060740418306000000fffffbfdff0015060000002c02dc0c000000001f")));
@@ -49,19 +50,19 @@ public class H02FrameDecoderTest extends ProtocolTest {
H02FrameDecoder decoder = new H02FrameDecoder(0);
- Assert.assertEquals(
+ assertEquals(
binary("2a48512c343230363131393133302c4e42522c3130323430332c3233382c312c302c372c313131312c323236342c36332c313131312c323236352c35382c313131312c323236362c35302c313131312c333133352c33372c313131312c3630352c33332c313131312c343932302c33302c313131312c3630372c32382c3131303131372c46464646444646462c3623"),
decoder.decode(null, null, binary("2a48512c343230363131393133302c4e42522c3130323430332c3233382c312c302c372c313131312c323236342c36332c313131312c323236352c35382c313131312c323236362c35302c313131312c333133352c33372c313131312c3630352c33332c313131312c343932302c33302c313131312c3630372c32382c3131303131372c46464646444646462c3623")));
- Assert.assertEquals(
+ assertEquals(
binary("2442061191301024031101175540227006012321670c000095fffffbffff001f00000001f800ee010000000032"),
decoder.decode(null, null, binary("2442061191301024031101175540227006012321670c000095fffffbffff001f00000001f800ee010000000032")));
- Assert.assertEquals(
+ assertEquals(
binary("5800009814991024031101175540227006012321670c000095fffffbffff0033"),
decoder.decode(null, null, binary("5800009814991024031101175540227006012321670c000095fffffbffff0033")));
- Assert.assertEquals(
+ assertEquals(
binary("2a48512c343230363131393133302c4e42522c3130323431362c3233382c312c302c372c313131312c323236342c35332c313131312c323236352c36302c313131312c323236362c34342c313131312c333133352c34332c313131312c3630352c33392c313131312c343932302c32392c313131312c3630372c32342c3131303131372c46464646464246462c3623"),
decoder.decode(null, null, binary("2a48512c343230363131393133302c4e42522c3130323431362c3233382c312c302c372c313131312c323236342c35332c313131312c323236352c36302c313131312c323236362c34342c313131312c333133352c34332c313131312c3630352c33392c313131312c343932302c32392c313131312c3630372c32342c3131303131372c46464646464246462c3623")));
diff --git a/test/org/traccar/protocol/H02ProtocolDecoderTest.java b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
index b5dcd9ffe..adbdc0a07 100644
--- a/test/org/traccar/protocol/H02ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolDecoderTest.java
@@ -156,7 +156,7 @@ public class H02ProtocolDecoderTest extends ProtocolTest {
"*HQ,2705171109,V1,213324,A,5002.5849,N,01433.7822,E,0.00,000,140613,FFFFFFFF#"));
verifyPosition(decoder, buffer(
- "*TH,2020916012,V1,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFF#"));
+ "*TH,2020916012,V1,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFF#\r\n"));
verifyPosition(decoder, buffer(
"*TH,2020916012,V4,S17,130305,050316,A,2212.8745,N,11346.6574,E,14.28,028,220902,FFFFFBFF#"));
diff --git a/test/org/traccar/protocol/H02ProtocolEncoderTest.java b/test/org/traccar/protocol/H02ProtocolEncoderTest.java
index 5a9f58827..e7b409a88 100644
--- a/test/org/traccar/protocol/H02ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/H02ProtocolEncoderTest.java
@@ -1,15 +1,16 @@
package org.traccar.protocol;
import org.joda.time.DateTime;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class H02ProtocolEncoderTest extends ProtocolTest {
private H02ProtocolEncoder encoder = new H02ProtocolEncoder();
- private DateTime time = new DateTime().withHourOfDay(1).withMinuteOfHour(2).withSecondOfMinute(3);;
+ private DateTime time = new DateTime().withHourOfDay(1).withMinuteOfHour(2).withSecondOfMinute(3);
@Test
public void testAlarmArmEncode() throws Exception {
@@ -18,7 +19,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ALARM_ARM);
- Assert.assertEquals("*HQ,123456789012345,SCF,010203,0,0#", encoder.encodeCommand(command, time));
+ assertEquals("*HQ,123456789012345,SCF,010203,0,0#", encoder.encodeCommand(command, time));
}
@Test
@@ -28,7 +29,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ALARM_DISARM);
- Assert.assertEquals("*HQ,123456789012345,SCF,010203,1,1#", encoder.encodeCommand(command, time));
+ assertEquals("*HQ,123456789012345,SCF,010203,1,1#", encoder.encodeCommand(command, time));
}
@Test
@@ -38,7 +39,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- Assert.assertEquals("*HQ,123456789012345,S20,010203,1,3,10,3,5,5,3,5,3,5,3,5#", encoder.encodeCommand(command, time));
+ assertEquals("*HQ,123456789012345,S20,010203,1,3,10,3,5,5,3,5,3,5,3,5#", encoder.encodeCommand(command, time));
}
@Test
@@ -48,7 +49,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_RESUME);
- Assert.assertEquals("*HQ,123456789012345,S20,010203,0,0#", encoder.encodeCommand(command, time));
+ assertEquals("*HQ,123456789012345,S20,010203,0,0#", encoder.encodeCommand(command, time));
}
@Test
@@ -59,7 +60,7 @@ public class H02ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_FREQUENCY, 10);
command.setType(Command.TYPE_POSITION_PERIODIC);
- Assert.assertEquals("*HQ,123456789012345,S71,010203,22,10#", encoder.encodeCommand(command, time));
+ assertEquals("*HQ,123456789012345,S71,010203,22,10#", encoder.encodeCommand(command, time));
}
}
diff --git a/test/org/traccar/protocol/HuaShengFrameDecoderTest.java b/test/org/traccar/protocol/HuaShengFrameDecoderTest.java
index c3f5c585f..0f24d4b5c 100644
--- a/test/org/traccar/protocol/HuaShengFrameDecoderTest.java
+++ b/test/org/traccar/protocol/HuaShengFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class HuaShengFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,19 +12,19 @@ public class HuaShengFrameDecoderTest extends ProtocolTest {
HuaShengFrameDecoder decoder = new HuaShengFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("c0010c00120060000000000004000600010100c0"),
decoder.decode(null, null, binary("c0010c00120060000000000004000600010100c0")));
- Assert.assertEquals(
+ assertEquals(
binary("c0010c003e0002000000000010020012a0014f42445f3347315f56312e302e330013a0043335353835353035303434303635380006a08701000006a0a1035fc0"),
decoder.decode(null, null, binary("c0010c003e0002000000000010020012a0014f42445f3347315f56312e302e330013a0043335353835353035303434303635380006a08701000006a0a1035fc0")));
- Assert.assertEquals(
+ assertEquals(
binary("c00000003faa0000000000003ea5a5005a3f00c000000031363037303530373132353700e6d186ffcc7a25002201160010000000010015000000000000000000c0"),
decoder.decode(null, null, binary("c00000003faa0000000000003ea5a5005a3f00dbdc00000031363037303530373132353700e6d186ffcc7a25002201160010000000010015000000000000000000c0")));
- Assert.assertEquals(
+ assertEquals(
binary("C000000041AA00000000000030C000000031353035323630373538323800ADDCC100226AEF0000000000120005000100151206EF0504E99975002903EB80556492CEC0"),
decoder.decode(null, null, binary("C000000041AA00000000000030DBDC00000031353035323630373538323800ADDCC100226AEF0000000000120005000100151206EF0504E99975002903EB80556492CEC0")));
diff --git a/test/org/traccar/protocol/HuaShengProtocolDecoderTest.java b/test/org/traccar/protocol/HuaShengProtocolDecoderTest.java
index 97bcf9954..3263c5ad3 100644
--- a/test/org/traccar/protocol/HuaShengProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/HuaShengProtocolDecoderTest.java
@@ -22,9 +22,6 @@ public class HuaShengProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, binary(
"c00000004baa000000000000098000000031363130303732323236343700e6d4efffcc789f000000000026000000010015000000000000000000000488ffffffffff0005000a10060000008dc0"));
- /*verifyPosition(decoder, binary(
- "c00000004baa0000000000000aa5a5a55a3f008000000031363130303732333139343600e61e4fffcc33fe0000000000470000000100150000000000000000000004b4ffffffffff0005000ac0"));*/
-
verifyPosition(decoder, binary(
"c00000004baa000000000000098000000031363130303732323236343700e6d4efffcc789f000000000026000000010015000000000000000000000488ffffffffff0005000a10060000008dc0"));
diff --git a/test/org/traccar/protocol/HuabaoFrameDecoderTest.java b/test/org/traccar/protocol/HuabaoFrameDecoderTest.java
index ad828bdb4..2d3937903 100644
--- a/test/org/traccar/protocol/HuabaoFrameDecoderTest.java
+++ b/test/org/traccar/protocol/HuabaoFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class HuabaoFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,7 +12,7 @@ public class HuabaoFrameDecoderTest extends ProtocolTest {
HuabaoFrameDecoder decoder = new HuabaoFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("7e307e087d557e"),
decoder.decode(null, null, binary("7e307d02087d01557e")));
diff --git a/test/org/traccar/protocol/Ivt401ProtocolDecoderTest.java b/test/org/traccar/protocol/Ivt401ProtocolDecoderTest.java
index c0f076014..d8a67ad7b 100644
--- a/test/org/traccar/protocol/Ivt401ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Ivt401ProtocolDecoderTest.java
@@ -11,6 +11,33 @@ public class Ivt401ProtocolDecoderTest extends ProtocolTest {
Ivt401ProtocolDecoder decoder = new Ivt401ProtocolDecoder(new Ivt401Protocol());
verifyPosition(decoder, text(
+ "(TLA,356917051007891,190118,090211,+16.986606,+82.242416,0,66,4,13,1,5,000,00,0.0,11.59,8.30,37.77,0.0,1,1.02,0,0,208,0,0,0,0,000000000,0,0,0,0,0,0,0,1,8654604,5,9,114)"));
+
+ verifyPosition(decoder, text(
+ "(TLN,862107032006249,230218,180500,+18.479728,+73.896339,30,0,944,13,1,5,111,11,0.00,10.88,6.31,29.55,0.00,0,0.99,66,0,0,88,95)"));
+
+ verifyPosition(decoder, text(
+ "(TLN,865933030026336,250118,063827,+18.598098,+73.806518,0,79,0,1,1,5,1200,0,0.0,11.50,4.00,36,0,0,1.00,0,0,12702,202,0)"));
+
+ verifyPosition(decoder, text(
+ "(TLA,865933030026336,250118,063838,+18.598110,+73.806518,0,334,0,1,1,5,1200,0,0.0,12.20,4.10,36,0,0,1.00,0,0,12704,0,0,0,0,0,0,0,0,0,0,0,0,1,0,3,203,0)"));
+
+ verifyNull(decoder, text(
+ "(TLB,356917050440515,0,0,+0.0,+0.0,0,0,0,0,0,0,000,00,0.00,12.21,7.95,26.57,0.0,1,1.12,0,0,0,1,90)"));
+
+ verifyPosition(decoder, text(
+ "(TLN,356917050440515,250118,094723,+0.0,+0.0,0,0,0,0,3,5,000,00,0.00,12.25,7.95,27.11,0.0,0,1.13,0,0,0,4,86)"));
+
+ verifyPosition(decoder, text(
+ "(TLA,356917050440515,250118,094733,+0.0,+0.0,0,0,0,0,3,5,000,00,0.00,12.25,7.95,27.20,0.0,0,1.12,0,0,0,0,0,0,0,000000000,0,1,0,0,0,0,0,1,0,0,5,70)"));
+
+ verifyPosition(decoder, text(
+ "(TLN,356917050440515,250118,094733,+0.0,+0.0,0,0,0,0,3,5,000,00,0.00,12.25,7.95,27.20,0.0,0,1.13,0,0,0,6,87)"));
+
+ verifyPosition(decoder, text(
+ "(TLN,356917050440515,250118,103541,+17.015546,+54.080841,0,0,31,12,1,5,000,00,0.0,0.00,8.04,28.59,M+0+0+0+0+0,0,1.12,0,0,2,48,30)"));
+
+ verifyPosition(decoder, text(
"(TLN,356917050291991,090315,133525,+12.990582,+77.589080,0,0,944,13,1,5,000,00,0.00,10.88,6.31,29.55,0.00,0,0.99,66,0,0,88,95)"));
verifyPosition(decoder, text(
diff --git a/test/org/traccar/protocol/Jt600FrameDecoderTest.java b/test/org/traccar/protocol/Jt600FrameDecoderTest.java
index 15e6ec18c..ae0948987 100644
--- a/test/org/traccar/protocol/Jt600FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Jt600FrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/KhdProtocolEncoderTest.java b/test/org/traccar/protocol/KhdProtocolEncoderTest.java
index 078b7c22e..ab858041a 100644
--- a/test/org/traccar/protocol/KhdProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/KhdProtocolEncoderTest.java
@@ -15,7 +15,7 @@ public class KhdProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- verifyCommand(encoder, command, binary("2929390006000000003F0D"));
+ verifyCommand(encoder, command, binary("29293900065981972d5d0d"));
}
diff --git a/test/org/traccar/protocol/L100FrameDecoderTest.java b/test/org/traccar/protocol/L100FrameDecoderTest.java
index f474fa678..fc6a892dc 100644
--- a/test/org/traccar/protocol/L100FrameDecoderTest.java
+++ b/test/org/traccar/protocol/L100FrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class L100FrameDecoderTest extends ProtocolTest {
@Test
@@ -11,11 +12,11 @@ public class L100FrameDecoderTest extends ProtocolTest {
L100FrameDecoder decoder = new L100FrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735242c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c027a"),
decoder.decode(null, null, binary("200141544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735242c2330313130303131313030313031302c4e2e432c4e2e432c4e2e432c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c027a")));
- Assert.assertEquals(
+ assertEquals(
binary("200341544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735244c4f432c436f6e6e61756768742043697263757320c2a0436f6e6e617567687420506c61636520c2a04e65772044656c686920c2a044656c6869c2a0496e6469612c2330313130303130313130313031302c322e332c33352e36372c38302c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c047a"),
decoder.decode(null, null, binary("200341544c3335363839353033373533333734352c244750524d432c3131313731392e3030302c412c323833382e303034352c4e2c30373731332e333730372c452c302e30302c2c3132303831302c2c2c412a3735244c4f432c436f6e6e61756768742043697263757320c2a0436f6e6e617567687420506c61636520c2a04e65772044656c686920c2a044656c6869c2a0496e6469612c2330313130303130313130313031302c322e332c33352e36372c38302c31323334352e36372c33312e342c342e322c32312c4d43432c4d4e432c4c41432c43656c6c494441544c047a")));
diff --git a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java
index 787f33e65..41925040e 100644
--- a/test/org/traccar/protocol/LaipacProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/LaipacProtocolDecoderTest.java
@@ -95,6 +95,31 @@ public class LaipacProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"$AVRMC,96414215,170046,p,4310.7965,N,07652.0816,E,0.00,0.00,071016,0,4069,98,1,0,0*04"));
+ verifyPosition(decoder, text(
+ "$AVRMC,999999999999999,111602,r,5050.1262,N,00419.9660,E,0.00,0.00,120318,0,3843,95,1,0,0,3EE4A617,020610*47"));
+
+ verifyPosition(decoder, text(
+ "$AVRMC,358174067149865,143456,R,5050.1285,N,00420.0620,E,0.00,309.27,190318,0,3455,119,1,0,0,3EE4A617,020610*54"));
+
+ verifyPosition(decoder, text(
+ "$AVRMC,999999999999999,084514,r,5050.1314,N,00419.9719,E,0.68,306.39,120318,0,3882,84,1,0,0,3EE4A617,020610*4D"));
+
+ //Alarm button
+ verifyPosition(decoder, text(
+ "$AVRMC,358174067149865,142945,R,5050.1254,N,00420.0490,E,0.00,0.00,190318,3,3455,119,1,0,0,3EE4A617,020610*53"));
+
+ //G-Sensor
+ verifyPosition(decoder, text(
+ "$AVRMC,358174067149865,143407,R,5050.1254,N,00420.0490,E,0.00,0.00,190318,8,3455,119,1,0,0,3EE4A617,020610*52"));
+
+ //Powered off
+ verifyPosition(decoder, text(
+ "$AVRMC,358174067149865,143648,A,5050.1141,N,00420.0525,E,1.24,174.38,190318,H,3455,119,1,0,0,3EE4A617,020610*3E"));
+
+ //No network
+ verifyPosition(decoder, text(
+ "$AVRMC,358174067149865,143747,R,5050.1124,N,00420.0542,E,1.34,161.96,190318,a,3416,119,1,0,0*7D"));
+
}
}
diff --git a/test/org/traccar/protocol/MegastekFrameDecoderTest.java b/test/org/traccar/protocol/MegastekFrameDecoderTest.java
index 9a327bb1f..68606a98a 100644
--- a/test/org/traccar/protocol/MegastekFrameDecoderTest.java
+++ b/test/org/traccar/protocol/MegastekFrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
index 9bb705f17..d10432b38 100644
--- a/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MegastekProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class MegastekProtocolDecoderTest extends ProtocolTest {
MegastekProtocolDecoder decoder = new MegastekProtocolDecoder(new MegastekProtocol());
+ verifyPosition(decoder, text(
+ "0174$MGV002,014682001957744,014682001957744,R,260318,042537,A,3853.77301,N,07728.66673,W,00,09,00,1.06,0.147,329.51,123.3,,310,26,B46C,5E69375,5,0000,0000,0,,,,,,10,019,Timer,,;!"));
+
verifyNull(decoder, text(
"0112$MGV002,,GVT900-3,S,010114,000003,,,,,,00,00,00,,0.000,0.00,,0.0,,,,,,0000,0000,14,10,0, , ,,1-0,0,Low Ext Vol;!"));
diff --git a/test/org/traccar/protocol/MeiligaoFrameDecoderTest.java b/test/org/traccar/protocol/MeiligaoFrameDecoderTest.java
index 9b02b646c..2d09c626b 100644
--- a/test/org/traccar/protocol/MeiligaoFrameDecoderTest.java
+++ b/test/org/traccar/protocol/MeiligaoFrameDecoderTest.java
@@ -1,9 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
public class MeiligaoFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,14 +13,14 @@ public class MeiligaoFrameDecoderTest extends ProtocolTest {
MeiligaoFrameDecoder decoder = new MeiligaoFrameDecoder();
- Assert.assertNull(
+ assertNull(
decoder.decode(null, null, binary("00")));
- Assert.assertEquals(
+ assertEquals(
binary("2424007b8621700151517899553233323835372e3030302c562c333632372e313835342c4e2c30313034352e323130392c452c302e30302c372c3239303131332c2c2a31347c302e307c347c303030307c303030382c303030357c303235443030303230303541374432327c30367c303030314530353527f40d0a"),
decoder.decode(null, null, binary("2424007B8621700151517899553233323835372E3030302C562C333632372E313835342C4E2C30313034352E323130392C452C302E30302C372C3239303131332C2C2A31347C302E307C347C303030307C303030382C303030357C303235443030303230303541374432327C30367C303030314530353527F40D0A")));
- Assert.assertEquals(
+ assertEquals(
binary("2424007b8621700151517899553233323835372e3030302c562c333632372e313835342c4e2c30313034352e323130392c452c302e30302c372c3239303131332c2c2a31347c302e307c347c303030307c303030382c303030357c303235443030303230303541374432327c30367c303030314530353527f40d0a"),
decoder.decode(null, null, binary("002424007B8621700151517899553233323835372E3030302C562C333632372E313835342C4E2C30313034352E323130392C452C302E30302C372C3239303131332C2C2A31347C302E307C347C303030307C303030382C303030357C303235443030303230303541374432327C30367C303030314530353527F40D0A")));
diff --git a/test/org/traccar/protocol/MeitrackFrameDecoderTest.java b/test/org/traccar/protocol/MeitrackFrameDecoderTest.java
index d86e532c3..53749816e 100644
--- a/test/org/traccar/protocol/MeitrackFrameDecoderTest.java
+++ b/test/org/traccar/protocol/MeitrackFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class MeitrackFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,7 +12,7 @@ public class MeitrackFrameDecoderTest extends ProtocolTest {
MeitrackFrameDecoder decoder = new MeitrackFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("24244e3132372c3836333037313031333830333036362c4141412c33352c2d312e3330323638302c33362e3835323133352c3135303430393231313032362c412c392c302c302e312c302c352c313635332c343039362c33323634382c3633397c30327c313030347c3930432c303030302c307c307c307c3346467c3330302c2a37430d0a"),
decoder.decode(null, null, binary("24244e3132372c3836333037313031333830333036362c4141412c33352c2d312e3330323638302c33362e3835323133352c3135303430393231313032362c412c392c302c302e312c302c352c313635332c343039362c33323634382c3633397c30327c313030347c3930432c303030302c307c307c307c3346467c3330302c2a37430d0a")));
diff --git a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java
index 9021da8f9..8748c751c 100644
--- a/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/MeitrackProtocolDecoderTest.java
@@ -11,6 +11,12 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest {
MeitrackProtocolDecoder decoder = new MeitrackProtocolDecoder(new MeitrackProtocol());
+ verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "242441313038362c3836343530373033313231393937342c4430302c3138303232343037323631345f4331453130395f4e31553144312e6a70672c31342c302cffd8ffdb008400140e0f120f0d14121012171514181e32211e1c1c1e3d2c2e243249404c4b47404645505a736250556d5645466488656d777b8182814e608d978c7d96737e817c011517171e1a1e3b21213b7c5346537c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7cffc000110801e0028003012100021101031101ffdd0004000affc401a20000010501010101010100000000000000000102030405060708090a0b100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9fa0100030101010101010101010000000000000102030405060708090a0b1100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00cca69ac8d06e3348569884db4845021b498a60371494008692980119a8ca7a5342101a5cd5221a0ab312ed1ee68b943e80dce2a467ffd0c806a48e592270f13b230e841a0096eeea7bb09e6c85b667033552800069c2980e14f15422418a916ad099228a95455089505584140993a2d5fb598a7cae72bd8fa536ae892e8e69e2b9d971168a459fffd1ece8a0028a006b534f4a68ce5b9130a89ab444919a61a6c634d34d21894952310d25002514084a4a00ffd2d2349564086929082929805250025140094940c4a4a04251400949408292819fffd3cca31591a098a5c62801a45464531098a69a6210d371400629a6980628eb400c64cd3791c1aa16c491479393563343105424fcc4d007ffd4c3463c0a94500381a5e3b8cd000c99e57f2a8f3835402834e0d4d08914d4aa6ac4c954d4aad4c4c955aa647a6496236ab51b552132e412e383d3f955b0722b09ab32a0c5a2a0d0ffd5ece8a0028a0061a6d5193dc8daa36ab422334c34c634"));
+
+ verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "24246b3131342c3836353738393032343134303439352c4343452c0000000001005000130006011f05010607071415001b00060800000949010a0c000b9b0119a1011afe010602e934ce0203fc9aeb0004309f13220cafc503000d97741e001c01000000010e0ce8000300092f2e060000b7ff2a33330d0a"));
+
verifyPosition(decoder, buffer(
"$$^182,864507031245110,AAA,109,13.844553,100.644360,171227173141,A,11,19,0,359,0.8,8,15075,934591,520|4|0643|07D20555,8400,0000|0000|0000|018D|04CB,,,108,0000,,6,0,,,,,10|171227173100*7C"));
@@ -100,9 +106,6 @@ public class MeitrackProtocolDecoderTest extends ProtocolTest {
verifyPositions(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"2424473937302c3336393830303031333436303637342c4343432c020134005b000000010ce304035db9e000ec6f591a000013000000000c001801edb70200c96d0100e60001004838576501000300a101c20400000000010ce304035db9e000ee6f591a000013000000000c001801edb70200ca6d0100e60001004838576501000300a101c20400000000010ce304035db9e000ef6f591a000013000000000c001801edb70200cc6d0100e60001004838576501000300a101c20400000000020ce304035db9e000f76f591a000016000000000c001801edb70200d36d0100e60001004838576502000300a101bf04000000000a0ce304035db9e000f76f591a000016000000000c001801edb70200d46d0100e60001004838576500000300a101bf0400000000020ce304035db9e000fb6f591a000016000000000c001801edb70200d86d0100e60001004838576502000300a101760400000000180ce304035db9e000fc6f591a0000120000000000008c00edb70200d96d0100e60001004838576502000300a10176040000000019b1e2040323b9e0000b70591a0105150600bb0012002901edb70200e76d0100e60001004838576502000300a2017005000000002023e304031fb9e0001070591a010615070027010d001601fcb70200ec6d0100e60001004838576502000300a201800500000000201fe3040302b9e0001170591a010615090019010d001501feb70200ed6d0100e60001004838576502000300a2018005000000002018e30403dcb8e0001270591a0106150b0011010d00150100b80200ee6d0100e60001004838576502000300a2018005000000002036e3040345b8e0001570591a0107150b002d010b0013010ab80200f16d0100e60001004838576502000300a2018005000000002053e3040326b8e0001670591a0107150d0041010b0013010eb80200f26d0100e60001004838576502000300a2018005000000002070e3040310b8e0001770591a0107150e004f010b00130111b80200f36d0100e60001004838576502000300a2018005000000002095e3040306b8e0001870591a0107150d005a010b00140115b80200f46d0100e60001004838576502000300a20180050000000020b3e3040305b8e0001970591a0107150b0060010b00140118b80200f56d0100e60001004838576502000300a20183050000000020cfe3040308b8e0001a70591a0107150b0066010b0014011bb80200f66d0100e60001004838576502000300a20183050000000020eee304030cb8e0001b70591a0106170b0004000d0014011eb80200f76d0100e60001004838576502000300a2018305000000002a62350d0a"));
- /*verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
- "2424473937302C3336393830303031333232303032302C4343432C02013400540000001F0E885701225FCC06F574A419000614000000001200280012390C0081080000CC01000062305446000000007901000000000000000000000000000000000000000000008004000080040000800400008004000000000000000000000000000000000000FEEE00001F0E885701225FCC06CD7AA419000614000000001200280012390C00260D0000CC01000062305446000000007801A403000000001F0E885701225FCC06257DA419000617000000001200280012390C007E0F0000CC01000062305446000000007701A403000000001F0E885701225FCC067E7FA419000016000000001200280012390C00D6110000CC01000062305446000000007701A603000000001F0E885701225FCC06D681A419000017000000001200280012390C002E140000CC01000062305446000000007601A603000000001F0E885701225FCC062E84A419000015000000001200280012390C0086160000CC01000062305446000000007501A603000000001F0E885701225FCC067A83A51900060E000000001200280012390C0065190000CC0100006230EAB7000000007301A403000000001F0E885701225FCC06D285A51900060E000000001200280012390C00BD1B0000CC01000062305446000000007101A203000000001F0E885701225FCC062B88A51900060F000000001200280012390C00151E0000CC01000062305446000000007001A203000000001F0E885701225FCC06838AA519000613000000001200280012390C006D200000CC01000062305446000000007001A603000000001F0E885701225FCC06DB8CA519000010000000001200280012390C00C5220000CC01000062305446000000006E01A603000000001F0E885701225FCC06348FA519000016000000001200280012390C001D250000CC01000062305446000000006401000000000000020E885701225FCC06D9D9A519000600000000001200280012390C007828000000000000000000000200000054010000000000001F0E885701225FCC062DDCA519000616000000001200280012390C00CC2A0000CC01000062305446020000007B010000000000000A0E885701225FCC065BDDA519000613000000001200280012390C00F92B0000CC01000062305446000000007C01000000000000020E885701225FCC065CDDA519000010000000001200280012390C00FB2B0000CC01000062305446020000007C010000000000001F0E885701225FCC0685DEA519000013000000001200280012390C00242D0000CC01000062305446020000007D010000000000002A35620D0A"));*/
-
}
}
diff --git a/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java b/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
index 771712420..b63ce5051 100644
--- a/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/MeitrackProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class MeitrackProtocolEncoderTest extends ProtocolTest {
@Test
@@ -16,14 +17,19 @@ public class MeitrackProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_SINGLE);
- Assert.assertEquals("@@Q25,123456789012345,A10*68\r\n", encoder.encodeCommand(command));
+ assertEquals("@@Q25,123456789012345,A10*68\r\n", encoder.encodeCommand(command));
+
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_REQUEST_PHOTO);
+
+ assertEquals("@@D46,123456789012345,D03,1,camera_picture.jpg*1F\r\n", encoder.encodeCommand(command));
command.setDeviceId(1);
command.setType(Command.TYPE_SEND_SMS);
command.set(Command.KEY_PHONE, "15360853789");
command.set(Command.KEY_MESSAGE, "Meitrack");
- Assert.assertEquals("@@f48,123456789012345,C02,0,15360853789,Meitrack*B0\r\n", encoder.encodeCommand(command));
+ assertEquals("@@f48,123456789012345,C02,0,15360853789,Meitrack*B0\r\n", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java b/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java
index 360ea0008..e9422da9f 100644
--- a/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/MiniFinderProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class MiniFinderProtocolEncoderTest extends ProtocolTest {
@Test
@@ -17,7 +18,7 @@ public class MiniFinderProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_SET_TIMEZONE);
command.set(Command.KEY_TIMEZONE, "GMT+1");
- Assert.assertEquals("123456L+01", encoder.encodeCommand(command));
+ assertEquals("123456L+01", encoder.encodeCommand(command));
command = new Command();
command.setDeviceId(1);
@@ -25,7 +26,7 @@ public class MiniFinderProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_INDEX, 2);
command.set(Command.KEY_PHONE, "1111111111");
- Assert.assertEquals("123456C1,1111111111", encoder.encodeCommand(command));
+ assertEquals("123456C1,1111111111", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/NvsFrameDecoderTest.java b/test/org/traccar/protocol/NvsFrameDecoderTest.java
index 54dc0fbdd..8a00207eb 100644
--- a/test/org/traccar/protocol/NvsFrameDecoderTest.java
+++ b/test/org/traccar/protocol/NvsFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class NvsFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,11 +12,11 @@ public class NvsFrameDecoderTest extends ProtocolTest {
NvsFrameDecoder decoder = new NvsFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("0012333537303430303630303137383234312e38"),
decoder.decode(null, null, binary("0012333537303430303630303137383234312e38")));
- Assert.assertEquals(
+ assertEquals(
binary("cccccccc0073000144b9ddf2aca002015694823d1f165d80902139a44f00aa001e1400000103000a080115001a001d001e0141004001f00065001301061600001700001800004231da430000440000085000000000480000000049000000004a0000000047ffffffff6900000004c700000000e10000000100954a"),
decoder.decode(null, null, binary("cccccccc0073000144b9ddf2aca002015694823d1f165d80902139a44f00aa001e1400000103000a080115001a001d001e0141004001f00065001301061600001700001800004231da430000440000085000000000480000000049000000004a0000000047ffffffff6900000004c700000000e10000000100954a")));
diff --git a/test/org/traccar/protocol/OpenGtsProtocolDecoderTest.java b/test/org/traccar/protocol/OpenGtsProtocolDecoderTest.java
new file mode 100644
index 000000000..0e6be8d10
--- /dev/null
+++ b/test/org/traccar/protocol/OpenGtsProtocolDecoderTest.java
@@ -0,0 +1,18 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class OpenGtsProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ OpenGtsProtocolDecoder decoder = new OpenGtsProtocolDecoder(new OpenGtsProtocol());
+
+ verifyPosition(decoder, request(
+ "/?id=123456789012345&dev=dev_name&acct=account&batt=0&code=0xF020&alt=160.5&gprmc=$GPRMC,191555,A,5025.46624,N,3030.39937,E,0.000000,0.000000,200218,,*2F"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/ProgressProtocolDecoderTest.java b/test/org/traccar/protocol/ProgressProtocolDecoderTest.java
index b080355fb..deaa8645a 100644
--- a/test/org/traccar/protocol/ProgressProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/ProgressProtocolDecoderTest.java
@@ -16,12 +16,6 @@ public class ProgressProtocolDecoderTest extends ProtocolTest {
verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"020037000100000003003131310f003335343836383035313339303036320f00323530303136333832383531353535010000000100000000000000e6bb97b6"));
- /*verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
- "0a009f00700d000076b1345580feaf2720b7e71a0301000000327f39031f15d2b900ffffffffffffffff00ac2600000900040000000000000000000000000000e52a6810c20000000000001c49010000000000000000000000000d00000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000019000500eefff1ff0000000000000000000000000000000016151c91"));
-
- verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
- "0a009f00720d00008ab1345580feaf2720b7e71a0301000000327f39031f15d2b900ffffffffffffffff00ac2600000800050000000000000000000000000000e12a6810c10000000000001c49010000000000000000000000000d00000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000019000500eefff1ff00000000000000000000000000000000052a49f2"));*/
-
}
}
diff --git a/test/org/traccar/protocol/Pt502FrameDecoderTest.java b/test/org/traccar/protocol/Pt502FrameDecoderTest.java
index d654c0c61..6c4dd03bd 100644
--- a/test/org/traccar/protocol/Pt502FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Pt502FrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
@@ -14,6 +13,10 @@ public class Pt502FrameDecoderTest extends ProtocolTest {
Pt502FrameDecoder decoder = new Pt502FrameDecoder();
verifyFrame(
+ binary("24504844302c3936302cffd8ffdb008400140e0f120f0d14121012171514181e32211e1c1c1e3d2c2e243249404c4b47404645505a736250556d5645466488656d777b8182814e608d978c7d96737e817c011517171e1a1e3b21213b7c5346537c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7cffc000110800f0014003012100021101031101ffdd0004000affc401a20000010501010101010100000000000000000102030405060708090a0b100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9fa0100030101010101010101010000000000000102030405060708090a0b1100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00e5292800ef450020a2800a2801d49400b450014b40052e2800a69340094a05007fffd0e5d14b10055b51b00c76a00527273494005250014500251400525001450015347c25003a928010d25007ffd1e52909a00290d0014b40052d0014500145002e297b50018a280109a6d002d2e2803fffd2e7a04da3777a94fbd0025140052500145002514005250014940054e381400b494008690d007fffd3e4f345001486800a5a005a2800a2801680280168a002909e280100cd028016a48937bfb5007fffd4c5038a42280128a004a280128a003ad2500251400945002a8cb0a9a80133450026692803ffd5e4e8a004a2801694500145002d18a005c5140052e280109a69a0029680140abb147b139eb401ffd6c62290d00251400949400114940052500252d002525003e31c93525002521a004a4a00ffd7e4a8a00281400a29d40094b40053ba500252d0018a31400d3cd250018cd2d005ab58777ccdd074ab645007ffd0c72290d00348a2801280"),
+ decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "bffbf6d10324504844302c3936302cffd8ffdb008400140e0f120f0d14121012171514181e32211e1c1c1e3d2c2e243249404c4b47404645505a736250556d5645466488656d777b8182814e608d978c7d96737e817c011517171e1a1e3b21213b7c5346537c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7cffc000110800f0014003012100021101031101ffdd0004000affc401a20000010501010101010100000000000000000102030405060708090a0b100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9fa0100030101010101010101010000000000000102030405060708090a0b1100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00e5292800ef450020a2800a2801d49400b450014b40052e2800a69340094a05007fffd0e5d14b10055b51b00c76a00527273494005250014500251400525001450015347c25003a928010d25007ffd1e52909a00290d0014b40052d0014500145002e297b50018a280109a6d002d2e2803fffd2e7a04da3777a94fbd0025140052500145002514005250014940054e381400b494008690d007fffd3e4f345001486800a5a005a2800a2801680280168a002909e280100cd028016a48937bfb5007fffd4c5038a42280128a004a280128a003ad2500251400945002a8cb0a9a80133450026692803ffd5e4e8a004a2801694500145002d18a005c5140052e280109a69a0029680140abb147b139eb401ffd6c62290d00251400949400114940052500252d002525003e31c93525002521a004a4a00ffd7e4a8a00281400a29d40094b40053ba500252d0018a31400d3cd250018cd2d005ab58777ccdd074ab645007ffd0c72290d00348a28012800d0a")));
+
+ verifyFrame(
binary("244655533836353332383032363234333836342c3531302d56312e31322c4131312d56332e30"),
decoder.decode(null, null, binary(ByteOrder.LITTLE_ENDIAN, "bffb192d00244655533836353332383032363234333836342c3531302d56312e31322c4131312d56332e300d0d")));
diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java
index 8fd1b4ff7..cca264faa 100644
--- a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java
@@ -11,68 +11,74 @@ public class Pt502ProtocolDecoderTest extends ProtocolTest {
Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new Pt502Protocol());
- verifyPosition(decoder, text(
+ verifyNull(decoder, binary(
+ "24504844302c3936302cffd8ffdb008400140e0f120f0d14121012171514181e32211e1c1c1e3d2c2e243249404c4b47404645505a736250556d5645466488656d777b8182814e608d978c7d96737e817c011517171e1a1e3b21213b7c5346537c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7c7cffc000110800f0014003012100021101031101ffdd0004000affc401a20000010501010101010100000000000000000102030405060708090a0b100002010303020403050504040000017d01020300041105122131410613516107227114328191a1082342b1c11552d1f02433627282090a161718191a25262728292a3435363738393a434445464748494a535455565758595a636465666768696a737475767778797a838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae1e2e3e4e5e6e7e8e9eaf1f2f3f4f5f6f7f8f9fa0100030101010101010101010000000000000102030405060708090a0b1100020102040403040705040400010277000102031104052131061241510761711322328108144291a1b1c109233352f0156272d10a162434e125f11718191a262728292a35363738393a434445464748494a535455565758595a636465666768696a737475767778797a82838485868788898a92939495969798999aa2a3a4a5a6a7a8a9aab2b3b4b5b6b7b8b9bac2c3c4c5c6c7c8c9cad2d3d4d5d6d7d8d9dae2e3e4e5e6e7e8e9eaf2f3f4f5f6f7f8f9faffda000c03010002110311003f00e5292800ef450020a2800a2801d49400b450014b40052e2800a69340094a05007fffd0e5d14b10055b51b00c76a00527273494005250014500251400525001450015347c25003a928010d25007ffd1e52909a00290d0014b40052d0014500145002e297b50018a280109a6d002d2e2803fffd2e7a04da3777a94fbd0025140052500145002514005250014940054e381400b494008690d007fffd3e4f345001486800a5a005a2800a2801680280168a002909e280100cd028016a48937bfb5007fffd4c5038a42280128a004a280128a003ad2500251400945002a8cb0a9a80133450026692803ffd5e4e8a004a2801694500145002d18a005c5140052e280109a69a0029680140abb147b139eb401ffd6c62290d00251400949400114940052500252d002525003e31c93525002521a004a4a00ffd7e4a8a00281400a29d40094b40053ba500252d0018a31400d3cd250018cd2d005ab58777ccdd074ab645007ffd0c72290d00348a2801280"));
+
+ verifyPosition(decoder, buffer(
+ "$PHO3821-1,1156802639,022125.000,A,0707.0014,N,07307.3725,W,0.0,0.1,110418,,,A/00000,00000/0,0,0,0/500//fd4//"));
+
+ verifyPosition(decoder, buffer(
"$POS,1360000277,182241.000,A,0846.0896,N,07552.1738,W,13.58,26.88,291017,,,A/00000,00000/142,0,0,0/62792900//f65//#"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$PHO0-1,1360000260,123012.000,A,0913.9644,N,07548.8345,W,0.0,309.8,111017,,,A/00000,10000/0,0,0,0/64551600//f98//"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,865328026243864,151105.000,A,1332.7096,N,204.6787,E,0.0,10.00,050517,,,A/00000,10/1,0/234//FD9/"));
- verifyNull(decoder, text(
+ verifyNull(decoder, buffer(
"$FUS865328026243864,510-V1.12,A11-V3.0"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$HDA,20007,134657.000,A,0626.1607,N,00330.2245,E,33.38,81.79,041016,,,A/00010,00000/270,0,0,0/19948900//fa4//"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$HDB,20007,134708.000,A,0626.1759,N,00330.3192,E,26.55,80.37,041016,,,A/00010,00000/23b,0,0,0/19949100//fa4//"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,20007,134704.000,A,0626.1698,N,00330.2870,E,31.23,79.58,041016,,,A/00010,00000/26c,0,0,0/19949100//fa4//#"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$PHO6608,115099,133140.000,A,1307.1238,N,05936.4194,W,0.00,21.50,290816,,,A/00010,00000/0,0,0,0/185100//f59/"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$DFR,40456789,083125.000,A,2232.0971,N,11400.9504,E,0.0,5.00,090714,,,A/00000,00/0,0/200076//FE7/"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$FDA,40456789,083125.000,A,2232.0971,N,11400.9504,E,0.0,5.00,090714,,,A/00000,00/0,0/200076//FE7/"));
- verifyAttribute(decoder, text(
+ verifyAttribute(decoder, buffer(
"$CPA,40456789,083125.000,A,2232.0971,N,11400.9504,E,7.62,265.24,291117,,,A/00000,00000/0/1200//#"), Position.KEY_ALARM, Position.ALARM_POWER_CUT);
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,216769295715,163237.000,A,3258.1738,S,02755.4350,E,0.00,215.88,100915,,,A/0000,0//232300//5b3/"),
position("2015-09-10 16:32:37.000", true, -32.96956, 27.92392));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,11023456,033731.000,A,0335.2617,N,09841.1587,E,0.00,88.12,210615,,,A/0000,0/1f8/388900//f33//"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000//"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,6120,233326.000,V,0935.1201,N,06914.6933,W,0.00,,151112,,,A/00000,00000/0/0/"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,6002,233257.000,A,0931.0430,N,06912.8707,W,0.05,146.98,141112,,,A/00010,00000/0/5360872"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,6095,233344.000,V,0933.0451,N,06912.3360,W,,,151112,,,N/00000,00000/0/1677600/"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$PHO0,6091,233606.000,A,0902.9855,N,06944.3654,W,0.0,43.8,141112,,,A/00010,00000/0/224000//"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,353451000164,082405.000,A,1254.8501,N,10051.6752,E,0.00,237.99,160513,,,A/0000,0/0/55000//a71/"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,012896008586486,154215.000,A,0118.0143,S,03646.9144,E,0.00,83.29,180714,,,A/0000,0/0/29200//644/"));
- verifyPosition(decoder, text(
+ verifyPosition(decoder, buffer(
"$POS,1151000,205326.000,A,0901.3037,N,07928.2751,W,48.79,30.55,170814,,,A/00010,10000/0,0,0,0/15986500//fb8/"));
}
diff --git a/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java b/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java
index 39ca2fe65..9d591bceb 100644
--- a/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Pt502ProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class Pt502ProtocolEncoderTest extends ProtocolTest {
@Test
@@ -17,7 +18,7 @@ public class Pt502ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "#PTI300");
- Assert.assertEquals("#PTI300\r\n", encoder.encodeCommand(command));
+ assertEquals("#PTI300\r\n", encoder.encodeCommand(command));
}
@@ -32,7 +33,7 @@ public class Pt502ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_INDEX, 2);
command.set(Command.KEY_DATA, 1);
- Assert.assertEquals("#OPC2,1\r\n", encoder.encodeCommand(command));
+ assertEquals("#OPC2,1\r\n", encoder.encodeCommand(command));
}
@@ -46,7 +47,7 @@ public class Pt502ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_SET_TIMEZONE);
command.set(Command.KEY_TIMEZONE, "GMT+8");
- Assert.assertEquals("#TMZ8\r\n", encoder.encodeCommand(command));
+ assertEquals("#TMZ8\r\n", encoder.encodeCommand(command));
}
@@ -61,7 +62,7 @@ public class Pt502ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_ALARM_SPEED);
command.set(Command.KEY_DATA, 120);
- Assert.assertEquals("#SPD120\r\n", encoder.encodeCommand(command));
+ assertEquals("#SPD120\r\n", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java
new file mode 100644
index 000000000..08fe7658e
--- /dev/null
+++ b/test/org/traccar/protocol/Pt60ProtocolDecoderTest.java
@@ -0,0 +1,24 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class Pt60ProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ Pt60ProtocolDecoder decoder = new Pt60ProtocolDecoder(new Pt60Protocol());
+
+ verifyPosition(decoder, text(
+ "@G#@,V01,6,111112222233333,8888888888888888,20150312010203,23.2014050;104.235212,"));
+
+ verifyNull(decoder, text(
+ "@G#@,V01,1,353882080015633,9460025014649193,"));
+
+ verifyNull(decoder, text(
+ "@G#@,V01,43,105681639001701,9460000412618231,20180410092923,5,460;0;9763;3852;-63|460;0;9763;3851;-26|460;0;9763;4080;-22|460;0;9763;3593;-18|460;0;9763;3591;-10,5,14:b8:37:26:64:88;004300680069006e0061004e00650074002d006e0047006e0058;-76|08:9b:4b:93:b5:b1;005400480049004e004b0052004100430045;-77|ec:3d:fd:c9:38:4a;004b00460052006f0075007400650072;-78|b0:d5:9d:c6:f8:82;003300360030514d8d390057006900460069002d00380032;-81|02:fa:84:3b:fa:6a;00470075006500730074005f0032002e003400470048007a;-82,"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/RoboTrackFrameDecoderTest.java b/test/org/traccar/protocol/RoboTrackFrameDecoderTest.java
new file mode 100644
index 000000000..2e3853f86
--- /dev/null
+++ b/test/org/traccar/protocol/RoboTrackFrameDecoderTest.java
@@ -0,0 +1,19 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+public class RoboTrackFrameDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ RoboTrackFrameDecoder decoder = new RoboTrackFrameDecoder();
+
+ verifyFrame(
+ binary("00524f424f545241434b00000000000000383638323034303032323533343136313233343536373839303132312e313261000000312e353761000000312e3030000000003e"),
+ decoder.decode(null, null, binary("00524f424f545241434b00000000000000383638323034303032323533343136313233343536373839303132312e313261000000312e353761000000312e3030000000003e")));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/RoboTrackProtocolDecoderTest.java b/test/org/traccar/protocol/RoboTrackProtocolDecoderTest.java
new file mode 100644
index 000000000..bd260597f
--- /dev/null
+++ b/test/org/traccar/protocol/RoboTrackProtocolDecoderTest.java
@@ -0,0 +1,26 @@
+package org.traccar.protocol;
+
+import org.junit.Test;
+import org.traccar.ProtocolTest;
+
+import java.nio.ByteOrder;
+
+public class RoboTrackProtocolDecoderTest extends ProtocolTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ RoboTrackProtocolDecoder decoder = new RoboTrackProtocolDecoder(new RoboTrackProtocol());
+
+ verifyNull(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "00524f424f545241434b00000000000000383638323034303032323533343136313233343536373839303132312e313261000000312e353761000000312e3030000000003e"));
+
+ verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "03e020bb5a034409034862120210a9e105000000000000b9"));
+
+ verifyPosition(decoder, binary(ByteOrder.LITTLE_ENDIAN,
+ "03f120bb5a30460903426312021798e105000000000000cd"));
+
+ }
+
+}
diff --git a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java
index 45230a339..bbcead2d0 100644
--- a/test/org/traccar/protocol/SuntechProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/SuntechProtocolDecoderTest.java
@@ -14,9 +14,6 @@ public class SuntechProtocolDecoderTest extends ProtocolTest {
decoder.setIncludeAdc(true);
decoder.setIncludeTemp(true);
- /*verifyPosition(decoder, text(
- "ST300STT;205170303;12;561;20170816;09:10:34;173f53;+19.082370;-098.214287;006.776;000.00;0;0;52982186;12.75;100000;2;6328;155747;4.2;1;0.00;0;0.00;0.00;00000000000000;0;28F2B7600600005D:+5.2;:;:"));*/
-
verifyPosition(decoder, text(
"ST300STT;205173382;07;564;20160322;23:23:18;232e19;+19.288278;-099.128750;000.122;000.00;9;1;478391;11.53;000100;1;9498;079324;4.3;1;0.00;0.00;0.00;00000000000000;0;2898E16006000058:-20.8;2861626006000039:+2.5;:"));
@@ -31,6 +28,15 @@ public class SuntechProtocolDecoderTest extends ProtocolTest {
SuntechProtocolDecoder decoder = new SuntechProtocolDecoder(new SuntechProtocol());
verifyPosition(decoder, text(
+ "ST600STT;008084783;20;419;20180308;18:00:36;0032cc3e;736;3;445c;41;-16.530023;-068.084267;018.640;267.99;10;1;11655;13.33;100000;2;0336;000061;4.5;0;0.00"));
+
+ verifyPosition(decoder, text(
+ "ST600STT;107850496;20;419;20180227;14:30:45;00462b08;736;3;4524;50;-16.479091;-068.119119;000.346;000.00;4;1;0;13.89;000000;1;0223;000003;0.0;0;0.00"));
+
+ verifyPosition(decoder, text(
+ "ST600STT;100850000;01;010;20081017;07:41:56;0000004f;450;20;0023;24;+37.478519;+126.886819;000.012;000.00;9;1;0;15.30;00110000;1;0072;0;4.5;1;12.35"));
+
+ verifyPosition(decoder, text(
"STT;100850000;3FFFFF;26;010;1;20161117;08:37:39;0000004F;450;0;0014;20;+37.479323;+126.887827;62.03;65.43;10;1;00000101;00001000;1;2;0492"));
verifyPosition(decoder, text(
diff --git a/test/org/traccar/protocol/T55ProtocolDecoderTest.java b/test/org/traccar/protocol/T55ProtocolDecoderTest.java
index 7f60a1807..ec699f111 100644
--- a/test/org/traccar/protocol/T55ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/T55ProtocolDecoderTest.java
@@ -11,12 +11,18 @@ public class T55ProtocolDecoderTest extends ProtocolTest {
T55ProtocolDecoder decoder = new T55ProtocolDecoder(new T55Protocol());
verifyNull(decoder, text(
+ "$IMEI=355797031609284"));
+
+ verifyNull(decoder, text(
"086415031C20"));
verifyNull(decoder, text(
"358244017671308"));
verifyPosition(decoder, text(
+ "$GPRMC,192350.000,V,0000.0000,N,00000.0000,E,,,110318,,*12"));
+
+ verifyPosition(decoder, text(
"$GPRMC,073446.000,A,1255.5125,N,07738.2948,E,0.00,0.53,080316,D*71,11,865733027593268,1,090,086,123,456,789,987,12345"));
verifyNotNull(decoder, text(
diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java
index beba54d74..264724ce9 100644
--- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java
@@ -11,6 +11,24 @@ public class TaipProtocolDecoderTest extends ProtocolTest {
TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol());
verifyPosition(decoder, text(
+ ">RGP211217112154-2748332-058946350000000FF7F2100;ID=AA01;#0002;*2D<"));
+
+ verifyPosition(decoder, text(
+ ">RCV12270218010247-3471349-058400030002057F001200020A1D013010600001509+0000FF+0000FF;#1DE2;ID=7196;*03<"));
+
+ verifyPosition(decoder, text(
+ ">RPV03874+3477708-0923453100029212;ID=0017;*71<"));
+
+ verifyNull(decoder, text(
+ ">RAL03874+00185+00012;ID=0017;*4A<"));
+
+ verifyNull(decoder, text(
+ ">RCP03874+347771-092345312;ID=0017;*65<"));
+
+ verifyNull(decoder, text(
+ ">RLN03874000+347770828-0923453071+000608270000+0000292309000000000000000000000000000000000000000000000012;ID=0017;*49<"));
+
+ verifyPosition(decoder, text(
">RPV46640+4197412-0752857900015802;ID=5102;*71<"));
verifyNull(decoder, text(
diff --git a/test/org/traccar/protocol/TelicFrameDecoderTest.java b/test/org/traccar/protocol/TelicFrameDecoderTest.java
index 711014c46..dd0efacb6 100644
--- a/test/org/traccar/protocol/TelicFrameDecoderTest.java
+++ b/test/org/traccar/protocol/TelicFrameDecoderTest.java
@@ -1,7 +1,5 @@
package org.traccar.protocol;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
index beae48d67..d62eef4a0 100644
--- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
@@ -15,6 +15,12 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest {
"000F313233343536373839303132333435"));
verifyPositions(decoder, false, binary(
+ "0000000000000035080100000161f37c50500020de5ba60ef11450000000000000000006040100b300b400ef000109002000014e0000000000000000010000be52"));
+
+ verifyPositions(decoder, false, binary(
+ "000000000000008c08010000013feb55ff74000f0ea850209a690000940000120000001e09010002000300040016014703f0001504c8000c0900730a00460b00501300464306d7440000b5000bb60007422e9f180000cd0386ce000107c700000000f10000601a46000001344800000bb84900000bb84a00000bb84c00000000024e0000000000000000cf00000000000000000100003fca"));
+
+ verifyPositions(decoder, false, binary(
"0000000000000401080e0000015d12cc211000fadaf627186742f5000d0048080006000a040100f001500515000342318a430fe344000003c700000000f1000068b61000001b05000000015d12c6683800fadaf72118673f82000000000000000007030100f00050040342318a430fe344000001f1000068b6000000015d12bd407800fadaf72118673f82000000000000000007030100f000500403423179430fe144000001f1000068b6000000015d12b414d000fadaf72118673f82000400900c0000fa120a0100f00050051502080007010552090e6f4bfa000542316a430fe14400000600006202b203c700002328f1000068b61000001b05000000015d12b3074800fadaf2821867436a000400890d00170011090100f00150011502081007010553090e6f4d054231fb430fe14400000603ae6202a003c700002328f1000068b61000001b05000000015d12b2ff7800fadaee89186747c60005009a0d001d0011090100f00150011502081b07010553090e6f4d05423125430fe144000006050862029e03c700002328f1000068b61000001b05000000015d12b2e42000fadae8cf18675e0a000300a60d00210011090101f00150011502082407030554090e6f4d0542310a430fe14400000606cf62029703c700002328f1000068b61000001b05000000015d12b2d48000fadae05818676a16000400930c00240011090100f00150011502082207010554090e6f4e05423738430fe144000006066a62029303c700002328f1000068b61000001b05000000015d12b2a1b800fadac33e18678e48000600940d00150011090101f00150051500081907030553090e6f4e054239cc430fe14400000607c662028603c700002328f1000000001000001b05000000015d12b29dd000fadac19d18678fc8000700820d00110011090100f00150051500081607030553090e6f4e054238c8430fe14400000606d962028503c700002328f1000000001000001b05000000015d12b299e800fadabfa9186790e3000700670d00110011090101f00150051500081407030553090e6f4e054231e5430fe144000006060a62028403c700002328f1000000001000001b05000000015d12b2960000fadabd4018679104000600510d00120011090101f00150051500081207030553090e6f4e054231ce430fe144000006057062028303c700002328f1000000001000001b05000000015d12b27aa800fadaa96518678b7c000600470d00120011090101f00150051500081807030551090e6f4e05423a70430fe144000006074462027c03c700002328f1000000001000001b05000000015d12b276c000fadaa73f18678ae60006003b0d000e0011090101f00150051500081607030551090e6f4e05423a5a430fe14400000606b762027b03c700002328f1000000001000001b05000e000007a4"));
verifyPositions(decoder, false, binary(
diff --git a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
index 7e04dcb81..25968a0fe 100644
--- a/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/Tk103ProtocolEncoderTest.java
@@ -1,15 +1,28 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
-import org.traccar.TestIdentityManager;
import org.traccar.model.Command;
-import org.traccar.model.Device;
+
+import static org.junit.Assert.assertEquals;
public class Tk103ProtocolEncoderTest extends ProtocolTest {
@Test
+ public void testEncodeOutputControl() {
+
+ Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
+
+ Command command = new Command();
+ command.setDeviceId(1);
+ command.setType(Command.TYPE_OUTPUT_CONTROL);
+ command.set(Command.KEY_DATA, "1");
+
+ assertEquals("(123456789012345AV001)", encoder.encodeCommand(command));
+
+ }
+
+ @Test
public void testEncodeEngineStop() throws Exception {
Tk103ProtocolEncoder encoder = new Tk103ProtocolEncoder();
@@ -18,7 +31,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_ENGINE_STOP);
- Assert.assertEquals("(123456789012345AV010)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AV010)", encoder.encodeCommand(command));
}
@@ -31,7 +44,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_SINGLE);
- Assert.assertEquals("(123456789012345AP00)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AP00)", encoder.encodeCommand(command));
}
@@ -45,7 +58,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_POSITION_PERIODIC);
command.set(Command.KEY_FREQUENCY, 60);
- Assert.assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AR00003C0000)", encoder.encodeCommand(command));
}
@@ -58,7 +71,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_STOP);
- Assert.assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AR0000000000)", encoder.encodeCommand(command));
}
@@ -71,7 +84,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_GET_VERSION);
- Assert.assertEquals("(123456789012345AP07)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AP07)", encoder.encodeCommand(command));
}
@@ -84,7 +97,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
- Assert.assertEquals("(123456789012345AT00)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AT00)", encoder.encodeCommand(command));
}
@@ -97,7 +110,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_SET_ODOMETER);
- Assert.assertEquals("(123456789012345AX01)", encoder.encodeCommand(command));
+ assertEquals("(123456789012345AX01)", encoder.encodeCommand(command));
}
@@ -110,7 +123,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_SINGLE);
- Assert.assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*getposl*,[end]", encoder.encodeCommand(command));
}
@@ -123,7 +136,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_PERIODIC);
- Assert.assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*routetrack*99*,[end]", encoder.encodeCommand(command));
}
@@ -136,7 +149,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_POSITION_STOP);
- Assert.assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*routetrackoff*,[end]", encoder.encodeCommand(command));
}
@@ -149,7 +162,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_GET_VERSION);
- Assert.assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*about*,[end]", encoder.encodeCommand(command));
}
@@ -162,7 +175,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
- Assert.assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,88888888,[end]", encoder.encodeCommand(command));
}
@@ -175,7 +188,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setDeviceId(1);
command.setType(Command.TYPE_IDENTIFICATION);
- Assert.assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,999999,[end]", encoder.encodeCommand(command));
}
@@ -189,7 +202,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_ALARM_SOS);
command.set(Command.KEY_ENABLE, true);
- Assert.assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*soson*,[end]", encoder.encodeCommand(command));
}
@@ -203,7 +216,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_ALARM_SOS);
command.set(Command.KEY_ENABLE, false);
- Assert.assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*sosoff*,[end]", encoder.encodeCommand(command));
}
@@ -217,7 +230,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "any text is ok");
- Assert.assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,any text is ok,[end]", encoder.encodeCommand(command));
}
@@ -232,7 +245,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_SERVER, "1.2.3.4");
command.set(Command.KEY_PORT, "5555");
- Assert.assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*setip*1*2*3*4*5555*,[end]", encoder.encodeCommand(command));
}
@@ -248,7 +261,7 @@ public class Tk103ProtocolEncoderTest extends ProtocolTest {
command.set(Command.KEY_PHONE, "+55555555555");
command.set(Command.KEY_DEVICE_PASSWORD, "232323");
- Assert.assertEquals("[begin]sms2,*master*232323*+55555555555*,[end]", encoder.encodeCommand(command));
+ assertEquals("[begin]sms2,*master*232323*+55555555555*,[end]", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/TmgFrameDecoderTest.java b/test/org/traccar/protocol/TmgFrameDecoderTest.java
index 7a6c47fb9..4f7be1b28 100644
--- a/test/org/traccar/protocol/TmgFrameDecoderTest.java
+++ b/test/org/traccar/protocol/TmgFrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/TotemFrameDecoderTest.java b/test/org/traccar/protocol/TotemFrameDecoderTest.java
index 0d3e69465..8fb5f8d54 100644
--- a/test/org/traccar/protocol/TotemFrameDecoderTest.java
+++ b/test/org/traccar/protocol/TotemFrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/TotemProtocolEncoderTest.java b/test/org/traccar/protocol/TotemProtocolEncoderTest.java
index 4415f6c0a..5a47f74cc 100644
--- a/test/org/traccar/protocol/TotemProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/TotemProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class TotemProtocolEncoderTest extends ProtocolTest {
@Test
@@ -17,7 +18,7 @@ public class TotemProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_ENGINE_STOP);
command.set(Command.KEY_DEVICE_PASSWORD, "000000");
- Assert.assertEquals("*000000,025,C,1#", encoder.encodeCommand(command));
+ assertEquals("*000000,025,C,1#", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java
index 5e1f09543..3bbfcb126 100644
--- a/test/org/traccar/protocol/TramigoProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TramigoProtocolDecoderTest.java
@@ -30,9 +30,6 @@ public class TramigoProtocolDecoderTest extends ProtocolTest {
verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"8000d316b000860001018f8703771bee11fdf2585472616d69676f3a205061726b65642c20302e3131206b6d2053206f6620492e452e532e2050756572746120426f6e6974612c204361726162616e6368656c2c204d61647269642c2045532c2034302e33373736362c202d332e37333833352c2030353a3131204170722031362020454f46"));
- /*verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
- "8000d116b000a2000101953203771beefa0bf2585472616d69676f3a204573746163696f6e61646f2c20302e3137206b6d20534f20646573646520492e452e532e2050756572746120426f6e6974612c204361726162616e6368656c2c204d61647269642c2045532c2034302e33373733322c202d332e37333931342c20756269636163696f6e20616e74696775612c2031313a3538204162722031352020454f46"));*/
-
verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"80009e08b00086000101bc1803778a59c58dea57546573742054323320547261636b65723a204d6f76696e672c20312e3639206b6d204e57206f66205574656b6f6e2c2045646f2c204e472c20362e34363137302c20352e36313938322c20452077697468207370656564203333206b6d2f682c2031363a3138205365702032372020454f46"));
diff --git a/test/org/traccar/protocol/TzoneProtocolDecoderTest.java b/test/org/traccar/protocol/TzoneProtocolDecoderTest.java
index 68c8bbdbc..c309abce1 100644
--- a/test/org/traccar/protocol/TzoneProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TzoneProtocolDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/UlbotechFrameDecoderTest.java b/test/org/traccar/protocol/UlbotechFrameDecoderTest.java
index 03a4fb336..d3d0429d6 100644
--- a/test/org/traccar/protocol/UlbotechFrameDecoderTest.java
+++ b/test/org/traccar/protocol/UlbotechFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class UlbotechFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,15 +12,15 @@ public class UlbotechFrameDecoderTest extends ProtocolTest {
UlbotechFrameDecoder decoder = new UlbotechFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("f8010103515810532780699f7e2e3f010e015ee4c906bde45c00000000008b0304004000000404002c776005060373193622110b00240b00fee8ffff807dffff606d0b00fee9af000000af0000000b00feee7d78807dffffffff100101cc2af8"),
decoder.decode(null, null, binary("f8010103515810532780699f7e2e3f010e015ee4c906bde45c00000000008b0304004000000404002c776005060373193622110b00240b00fee8ffff807dffff606d0b00fee9af000000af0000000b00feee7d78807dffffffff100101cc2af8")));
- Assert.assertEquals(
+ assertEquals(
binary("2a545330312c33353430343330353133383934363023"),
decoder.decode(null, null, binary("2a545330312c33353430343330353133383934363023")));
- Assert.assertEquals(
+ assertEquals(
binary("f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f705060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8"),
decoder.decode(null, null, binary("f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f70005060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8")));
diff --git a/test/org/traccar/protocol/Vt200FrameDecoderTest.java b/test/org/traccar/protocol/Vt200FrameDecoderTest.java
index a9fff6c33..9422f6d74 100644
--- a/test/org/traccar/protocol/Vt200FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Vt200FrameDecoderTest.java
@@ -1,6 +1,5 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
diff --git a/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java b/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java
index 42ed4a652..9ce01c966 100644
--- a/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Vt200ProtocolDecoderTest.java
@@ -10,6 +10,9 @@ public class Vt200ProtocolDecoderTest extends ProtocolTest {
Vt200ProtocolDecoder decoder = new Vt200ProtocolDecoder(new Vt200Protocol());
+ verifyPosition(decoder, binary(
+ "28192030961807208200210101b919011818375801245774036424612500160917000003aa008800007b00aa3429"));
+
verifyNull(decoder, binary(
"286310373094563082002701033d010817143327c68a14841e00c27f550e9a000000000c000000084700200120007d01af260b29"));
diff --git a/test/org/traccar/protocol/VtfmsFrameDecoderTest.java b/test/org/traccar/protocol/VtfmsFrameDecoderTest.java
index e5897549b..a5eb0b49b 100644
--- a/test/org/traccar/protocol/VtfmsFrameDecoderTest.java
+++ b/test/org/traccar/protocol/VtfmsFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class VtfmsFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,7 +12,7 @@ public class VtfmsFrameDecoderTest extends ProtocolTest {
VtfmsFrameDecoder decoder = new VtfmsFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
buffer("(863071010087648,0HK44,00,000,14,2,9,,A,114946,180313,11.0244,076.9768,282,000,00000,00000,K,0000128,1,12.8,,200,2.501,,4.001,0,0,0,0,0,0,0,,)105"),
decoder.decode(null, null, buffer("(863071010087648,0HK44,00,000,14,2,9,,A,114946,180313,11.0244,076.9768,282,000,00000,00000,K,0000128,1,12.8,,200,2.501,,4.001,0,0,0,0,0,0,0,,)105")));
diff --git a/test/org/traccar/protocol/WatchFrameDecoderTest.java b/test/org/traccar/protocol/WatchFrameDecoderTest.java
index 664501a43..741807de2 100644
--- a/test/org/traccar/protocol/WatchFrameDecoderTest.java
+++ b/test/org/traccar/protocol/WatchFrameDecoderTest.java
@@ -11,6 +11,10 @@ public class WatchFrameDecoderTest extends ProtocolTest {
WatchFrameDecoder decoder = new WatchFrameDecoder();
verifyFrame(
+ binary("5b33472a3335323636313039303134333135302a303030412a4c4b2c302c302c3130305d"),
+ decoder.decode(null, null, binary("5b33472a3335323636313039303134333135302a303030412a4c4b2c302c302c3130305d")));
+
+ verifyFrame(
binary("5b33472a383330383430363237392a303030382a72636170747572655d"),
decoder.decode(null, null, binary("5b33472a383330383430363237392a303030382a72636170747572655d")));
@@ -18,6 +22,10 @@ public class WatchFrameDecoderTest extends ProtocolTest {
binary("5b33472a383330383430363237392a303030392a4c4b2c302c302c38345d"),
decoder.decode(null, null, binary("5b33472a383330383430363237392a303030392a4c4b2c302c302c38345d")));
+ verifyFrame(
+ binary("5b5a4a2a3031343131313030313335303330342a303033342a303030392a4c4b2c302c302c31395d"),
+ decoder.decode(null, null, binary("5b5a4a2a3031343131313030313335303330342a303033342a303030392a4c4b2c302c302c31395d")));
+
}
}
diff --git a/test/org/traccar/protocol/WatchProtocolDecoderTest.java b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
index c960ccc25..bc567bc4d 100644
--- a/test/org/traccar/protocol/WatchProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolDecoderTest.java
@@ -11,6 +11,15 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
WatchProtocolDecoder decoder = new WatchProtocolDecoder(new WatchProtocol());
verifyPosition(decoder, buffer(
+ "[ZJ*014111001332708*0075*0064*AL,040418,052156,A,22.536207,N,113.938673,E,0,0,0,5,100,82,1000,50,00100000,1,255,460,0,9340,3663,35]"));
+
+ verifyPosition(decoder, buffer(
+ "[SG*352661090143150*006C*UD,150817,132115,V,28.435142,N,81.354333,W,2.2038,000,99,00,70,100,0,50,00000000,1,1,310,260,1091,30082,139,,00]"));
+
+ verifyAttributes(decoder, buffer(
+ "[3G*4700609403*0013*bphrt,120,79,73,,,,]"));
+
+ verifyPosition(decoder, buffer(
"[3G*8308373902*0080*AL,230817,095346,A,47.083950,N,15.4821850,E,7.60,273.8,0.0,4,15,44,0,0,00200010,2,255,232,1,7605,42530,118,7605,58036,119,0,65.8]"));
verifyPosition(decoder, buffer(
@@ -84,6 +93,15 @@ public class WatchProtocolDecoderTest extends ProtocolTest {
verifyAttributes(decoder, buffer(
"[3G*6005412902*0008*heart,71]"));
+ verifyPosition(decoder, buffer(
+ "[ZJ*014111001350304*0033*0064*UD,070318,020827,V,00.000000,N,000.000000,E,0,0,0,0,100,19,1000,50,00000000,1,255,460,0,9346,5223,42]"));
+
+ verifyPosition(decoder, buffer(
+ "[ZJ*014111001350304*0035*0097*UD,070318,020857,V,00.000000,N,000.000000,E,0,0,0,0,100,19,1000,50,00000000,5,255,460,0,9346,5223,42,9346,5214,21,9784,4083,13,9346,5222,11,9346,5221,8]"));
+
+ verifyPosition(decoder, buffer(
+ "[ZJ*014111001350304*0038*008a*UD,070318,021027,V,00.000000,N,000.000000,E,0,0,0,0,100,18,1000,50,00000000,4,255,460,0,9346,5223,42,9346,5214,20,9784,4083,11,9346,5221,5]"));
+
}
}
diff --git a/test/org/traccar/protocol/WatchProtocolEncoderTest.java b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
index cffe373cf..d7784f50b 100644
--- a/test/org/traccar/protocol/WatchProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/WatchProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class WatchProtocolEncoderTest extends ProtocolTest {
@Test
@@ -17,41 +18,41 @@ public class WatchProtocolEncoderTest extends ProtocolTest {
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_REBOOT_DEVICE);
- Assert.assertEquals("[CS*123456789012345*0005*RESET]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*0005*RESET]", encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_SOS_NUMBER);
command.set(Command.KEY_INDEX, 1);
command.set(Command.KEY_PHONE, "123456789");
- Assert.assertEquals("[CS*123456789012345*000e*SOS1,123456789]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*000e*SOS1,123456789]", encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_VOICE_MESSAGE);
command.set(Command.KEY_DATA, "3333");
- Assert.assertEquals("[CS*123456789012345*0005*TK,33]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*0005*TK,33]", encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_CUSTOM);
command.set(Command.KEY_DATA, "WORK,6-9,11-13,13-15,17-19");
- Assert.assertEquals("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*001a*WORK,6-9,11-13,13-15,17-19]", encoder.encodeCommand(null, command));
command = new Command();
command.setDeviceId(1);
command.setType(Command.TYPE_SET_TIMEZONE);
command.set(Command.KEY_TIMEZONE, "Europe/Amsterdam");
- Assert.assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*0006*LZ,,+1]", encoder.encodeCommand(null, command));
command.set(Command.KEY_TIMEZONE, "GMT+01:30");
- Assert.assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*0008*LZ,,+1.5]", encoder.encodeCommand(null, command));
command.set(Command.KEY_TIMEZONE, "Atlantic/Azores");
- Assert.assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*0006*LZ,,-1]", encoder.encodeCommand(null, command));
command.set(Command.KEY_TIMEZONE, "GMT-11:30");
- Assert.assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(command));
+ assertEquals("[CS*123456789012345*0009*LZ,,-11.5]", encoder.encodeCommand(null, command));
}
diff --git a/test/org/traccar/protocol/WondexFrameDecoderTest.java b/test/org/traccar/protocol/WondexFrameDecoderTest.java
index 2b401aa18..642473f2d 100644
--- a/test/org/traccar/protocol/WondexFrameDecoderTest.java
+++ b/test/org/traccar/protocol/WondexFrameDecoderTest.java
@@ -1,9 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
public class WondexFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,14 +13,14 @@ public class WondexFrameDecoderTest extends ProtocolTest {
WondexFrameDecoder decoder = new WondexFrameDecoder();
- Assert.assertNull(
+ assertNull(
decoder.decode(null, null, binary("f0d70b0001ca9a3b")));
- Assert.assertEquals(
+ assertEquals(
binary("313034343938393630312c32303133303332333039353531352c31332e3537323737362c35322e3430303833382c302c3030302c37322c302c32"),
decoder.decode(null, null, binary("313034343938393630312c32303133303332333039353531352c31332e3537323737362c35322e3430303833382c302c3030302c37322c302c320d0a")));
- Assert.assertEquals(binary("d0d70b0001ca9a3b"),
+ assertEquals(binary("d0d70b0001ca9a3b"),
decoder.decode(null, null, binary("d0d70b0001ca9a3b")));
}
diff --git a/test/org/traccar/protocol/WondexProtocolEncoderTest.java b/test/org/traccar/protocol/WondexProtocolEncoderTest.java
index fb038a18b..3d76cb677 100644
--- a/test/org/traccar/protocol/WondexProtocolEncoderTest.java
+++ b/test/org/traccar/protocol/WondexProtocolEncoderTest.java
@@ -1,10 +1,11 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
import org.traccar.model.Command;
+import static org.junit.Assert.assertEquals;
+
public class WondexProtocolEncoderTest extends ProtocolTest {
@Test
public void testEncode() throws Exception {
@@ -16,7 +17,7 @@ public class WondexProtocolEncoderTest extends ProtocolTest {
command.setType(Command.TYPE_POSITION_SINGLE);
command.set(Command.KEY_DEVICE_PASSWORD, "0000");
- Assert.assertEquals("$WP+GETLOCATION=0000", encoder.encodeCommand(command));
+ assertEquals("$WP+GETLOCATION=0000", encoder.encodeCommand(command));
}
diff --git a/test/org/traccar/protocol/XexunFrameDecoderTest.java b/test/org/traccar/protocol/XexunFrameDecoderTest.java
index 5627623ba..8fc628bdb 100644
--- a/test/org/traccar/protocol/XexunFrameDecoderTest.java
+++ b/test/org/traccar/protocol/XexunFrameDecoderTest.java
@@ -1,9 +1,10 @@
package org.traccar.protocol;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import static org.junit.Assert.assertEquals;
+
public class XexunFrameDecoderTest extends ProtocolTest {
@Test
@@ -11,11 +12,11 @@ public class XexunFrameDecoderTest extends ProtocolTest {
XexunFrameDecoder decoder = new XexunFrameDecoder();
- Assert.assertEquals(
+ assertEquals(
binary("4750524d432c3230353933352e3030302c412c353134302e343335302c4e2c3530312e303638362c452c302e30302c302e30302c3132313031352c30302c303030302e302c412a37302c462c2c696d65693a3335393538373031343731383339322c"),
decoder.decode(null, null, binary("313531303132313435392c2b33313635323435343932372c4750524d432c3230353933352e3030302c412c353134302e343335302c4e2c3530312e303638362c452c302e30302c302e30302c3132313031352c30302c303030302e302c412a37302c462c2c696d65693a3335393538373031343731383339322c31323249")));
- Assert.assertEquals(
+ assertEquals(
binary("4750524d432c3130333733312e3633362c412c343534352e353236362c4e2c30303434382e383235392c452c32312e31322c3237362e30312c3135303631352c2c2c412a35372c4c2c2c20696d65693a3031333934393030323032363637352c"),
decoder.decode(null, null, binary("3135303631353132333733312c2b33333634373338343631312c4750524d432c3130333733312e3633362c412c343534352e353236362c4e2c30303434382e383235392c452c32312e31322c3237362e30312c3135303631352c2c2c412a35372c4c2c2c20696d65693a3031333934393030323032363637352c30342c333532322e392c463a332e3732562c302c3134322c32313734342c3230382c30312c303730322c394338430a0d")));
diff --git a/test/org/traccar/reports/ReportUtilsTest.java b/test/org/traccar/reports/ReportUtilsTest.java
index 4f7a4eb68..a8ff653c9 100644
--- a/test/org/traccar/reports/ReportUtilsTest.java
+++ b/test/org/traccar/reports/ReportUtilsTest.java
@@ -15,7 +15,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
-import org.junit.Assert;
import org.junit.Test;
import org.traccar.BaseTest;
import org.traccar.model.Position;
@@ -35,9 +34,7 @@ public class ReportUtilsTest extends BaseTest {
Position position = new Position();
- if (time != null) {
- position.setTime(date(time));
- }
+ position.setTime(date(time));
position.setValid(true);
position.setSpeed(speed);
position.set(Position.KEY_TOTAL_DISTANCE, totalDistance);
@@ -51,20 +48,20 @@ public class ReportUtilsTest extends BaseTest {
startPosition.set(Position.KEY_TOTAL_DISTANCE, 500.0);
Position endPosition = new Position();
endPosition.set(Position.KEY_TOTAL_DISTANCE, 700.0);
- Assert.assertEquals(ReportUtils.calculateDistance(startPosition, endPosition), 200.0, 10);
+ assertEquals(ReportUtils.calculateDistance(startPosition, endPosition), 200.0, 10);
startPosition.set(Position.KEY_ODOMETER, 50000);
endPosition.set(Position.KEY_ODOMETER, 51000);
- Assert.assertEquals(ReportUtils.calculateDistance(startPosition, endPosition), 1000.0, 10);
+ assertEquals(ReportUtils.calculateDistance(startPosition, endPosition), 1000.0, 10);
}
@Test
public void testCalculateSpentFuel() {
Position startPosition = new Position();
Position endPosition = new Position();
- Assert.assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), 0.0, 0.01);
+ assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), 0.0, 0.01);
startPosition.set(Position.KEY_FUEL_LEVEL, 0.7);
endPosition.set(Position.KEY_FUEL_LEVEL, 0.5);
- Assert.assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), 0.2, 0.01);
+ assertEquals(ReportUtils.calculateFuel(startPosition, endPosition), 0.2, 0.01);
}
@Test
diff --git a/traccar-web b/traccar-web
-Subproject f08f6fa4b20f003dd624656746a49237bbff244
+Subproject 464aa58c49ac5e04d419a68b6ee5bcf9d0c3679