{"action":"created","comment":{"url":"https://api.github.com/repos/traccar/traccar/pulls/comments/300019915","pull_request_review_id":257567441,"id":300019915,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMwMDAxOTkxNQ==","diff_hunk":"@@ -81,81 +100,166 @@ private String decodeAlarm(String event) {\n                 return Position.ALARM_GEOFENCE_EXIT;\n             case \"6\":\n                 return Position.ALARM_OVERSPEED;\n+            case \"5\":\n+                return Position.ALARM_POWER_CUT;\n             case \"3\":\n                 return Position.ALARM_SOS;\n             default:\n                 return null;\n         }\n     }\n \n-    @Override\n-    protected Object decode(\n-            Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {\n+    private String decodeEvent(String event, Position position) {\n \n-        String sentence = (String) msg;\n+        if (event.length() == 1) {\n+            char inputStatus = event.charAt(0);\n+            if (inputStatus >= 'A' && inputStatus <= 'D') {\n+                int inputStatusInt = inputStatus - 'A';\n+                position.set(Position.PREFIX_IN + 1, inputStatusInt & 1);\n+                position.set(Position.PREFIX_IN + 2, inputStatusInt & 2);\n+                position.set(Position.KEY_IGNITION, ((inputStatusInt & 1) != 0) ? true : false);\n+                return null;\n+            }\n+        }\n \n-        if (sentence.startsWith(\"$ECHK\") && channel != null) {\n-            channel.writeAndFlush(new NetworkMessage(sentence + \"\\r\\n\", remoteAddress)); // heartbeat\n-            return null;\n+        return event;\n+    }\n+\n+    private String getDevicePassword(DeviceSession deviceSession) {\n+\n+        String devicePassword = defaultDevicePassword;\n+\n+        Device device = Context.getIdentityManager().getById(deviceSession.getDeviceId());\n+        if (device != null) {\n+            String password = device.getString(Command.KEY_DEVICE_PASSWORD);\n+            if (password != null) {\n+                devicePassword = password;\n+            }\n         }\n \n-        Parser parser = new Parser(PATTERN, sentence);\n-        if (!parser.matches()) {\n-            return null;\n+        return devicePassword;\n+    }\n+\n+    private Object handleEchk(\n+            String sentence, int checksum, Parser parser, Channel channel, SocketAddress remoteAddress) {\n+\n+        if (channel != null) {\n+            channel.writeAndFlush(new NetworkMessage(sentence + \"\\r\\n\", remoteAddress));\n         }\n \n-        DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());\n+        DeviceSession deviceSession =\n+            getDeviceSession(channel, remoteAddress, parser.next());\n+        if (deviceSession != null) {\n+            ConnectionManager cm = Context.getConnectionManager();\n+            if (cm != null) {\n+                cm.updateDevice(deviceSession.getDeviceId(),\n+                    Device.STATUS_ONLINE, new Date());\n+            }\n+        }\n+\n+        return null;\n+    }\n+\n+    protected Object handleAvrmc(\n+            String sentence, int checksum, Parser parser, Channel channel, SocketAddress remoteAddress) {\n+\n+        DeviceSession deviceSession =\n+            getDeviceSession(channel, remoteAddress, parser.next());\n         if (deviceSession == null) {\n             return null;\n         }\n \n         Position position = new Position(getProtocolName());\n+\n+        // Device ID\n         position.setDeviceId(deviceSession.getDeviceId());\n \n+        // Time\n         DateBuilder dateBuilder = new DateBuilder()\n                 .setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));\n \n+        // Status [ V: Invalid | A: Valid | R: Not realtime | P: Parked ]\n         String status = parser.next();\n         String upperCaseStatus = status.toUpperCase();\n-        position.setValid(upperCaseStatus.equals(\"A\") || upperCaseStatus.equals(\"R\") || upperCaseStatus.equals(\"P\"));\n+        position.setValid(upperCaseStatus.equals(\"A\"));\n         position.set(Position.KEY_STATUS, status);\n \n+        // Position\n         position.setLatitude(parser.nextCoordinate());\n         position.setLongitude(parser.nextCoordinate());\n+\n+        // Speed\n         position.setSpeed(parser.nextDouble(0));\n+\n+        // Course\n         position.setCourse(parser.nextDouble(0));\n \n+        // Date\n         dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));\n         position.setTime(dateBuilder.getDate());\n \n+        // Alarm / Event\n         String event = parser.next();\n         position.set(Position.KEY_ALARM, decodeAlarm(event));\n-        position.set(Position.KEY_EVENT, event);\n+        position.set(Position.KEY_EVENT, decodeEvent(event, position));\n+\n+        // Battery\n         position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll(\"\\\\.\", \"\")) * 0.001);\n+\n+        // Odometer\n         position.set(Position.KEY_ODOMETER, parser.nextDouble());\n+\n+        // GPS status\n         position.set(Position.KEY_GPS, parser.nextInt());\n+\n+        // ADC1 / ADC2\n         position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);\n         position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);\n \n-        Integer lac = parser.nextHexInt();\n-        Integer cid = parser.nextHexInt();\n-        Integer mcc = parser.nextInt();\n-        Integer mnc = parser.nextInt();\n-        if (lac != null && cid != null && mcc != null && mnc != null) {\n+        // LAC, CID, MCC, MNC\n+        Integer laccid = parser.nextHexInt();\n+        Integer mccmnc = parser.nextInt();\n+        if (laccid != null && laccid != 0 && mccmnc != null && mccmnc != 0) {\n+            Integer lac = (laccid >> 16) & 0xFFFF;\n+            Integer cid = laccid & 0xFFFF;\n+            Integer mcc = mccmnc / 10000;\n+            Integer mnc = mccmnc % 100;\n             position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));\n         }\n \n-        String checksum = parser.next();\n+        // Skip remaining parameters\n+        String unused = parser.next();\n+\n+        // Checksum\n+        String checksumStr = parser.next();\n+        if (checksum != Integer.parseInt(checksumStr, 16)) {","path":"src/main/java/org/traccar/protocol/LaipacProtocolDecoder.java","position":253,"original_position":253,"commit_id":"efb64c30835eccf1e532ea7d7618d2d40ce7b761","original_commit_id":"efb64c30835eccf1e532ea7d7618d2d40ce7b761","user":{"login":"edvalley","id":52469633,"node_id":"MDQ6VXNlcjUyNDY5NjMz","avatar_url":"https://avatars2.githubusercontent.com/u/52469633?v=4","gravatar_id":"","url":"https://api.github.com/users/edvalley","html_url":"https://github.com/edvalley","followers_url":"https://api.github.com/users/edvalley/followers","following_url":"https://api.github.com/users/edvalley/following{/other_user}","gists_url":"https://api.github.com/users/edvalley/gists{/gist_id}","starred_url":"https://api.github.com/users/edvalley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edvalley/subscriptions","organizations_url":"https://api.github.com/users/edvalley/orgs","repos_url":"https://api.github.com/users/edvalley/repos","events_url":"https://api.github.com/users/edvalley/events{/privacy}","received_events_url":"https://api.github.com/users/edvalley/received_events","type":"User","site_admin":false},"body":"Just double checking that the parser is in the right position, not verifying checksums. You tell me. Thanks.","created_at":"2019-07-03T15:26:04Z","updated_at":"2019-07-03T15:26:05Z","html_url":"https://github.com/traccar/traccar/pull/4342#discussion_r300019915","pull_request_url":"https://api.github.com/repos/traccar/traccar/pulls/4342","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/traccar/traccar/pulls/comments/300019915"},"html":{"href":"https://github.com/traccar/traccar/pull/4342#discussion_r300019915"},"pull_request":{"href":"https://api.github.com/repos/traccar/traccar/pulls/4342"}},"in_reply_to_id":299792336},"pull_request":{"url":"https://api.github.com/repos/traccar/traccar/pulls/4342","id":293995025,"node_id":"MDExOlB1bGxSZXF1ZXN0MjkzOTk1MDI1","html_url":"https://github.com/traccar/traccar/pull/4342","diff_url":"https://github.com/traccar/traccar/pull/4342.diff","patch_url":"https://github.com/traccar/traccar/pull/4342.patch","issue_url":"https://api.github.com/repos/traccar/traccar/issues/4342","number":4342,"state":"open","locked":false,"title":"Enhance Laipac protocol decoder and encoder","user":{"login":"edvalley","id":52469633,"node_id":"MDQ6VXNlcjUyNDY5NjMz","avatar_url":"https://avatars2.githubusercontent.com/u/52469633?v=4","gravatar_id":"","url":"https://api.github.com/users/edvalley","html_url":"https://github.com/edvalley","followers_url":"https://api.github.com/users/edvalley/followers","following_url":"https://api.github.com/users/edvalley/following{/other_user}","gists_url":"https://api.github.com/users/edvalley/gists{/gist_id}","starred_url":"https://api.github.com/users/edvalley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edvalley/subscriptions","organizations_url":"https://api.github.com/users/edvalley/orgs","repos_url":"https://api.github.com/users/edvalley/repos","events_url":"https://api.github.com/users/edvalley/events{/privacy}","received_events_url":"https://api.github.com/users/edvalley/received_events","type":"User","site_admin":false},"body":"Enhance Laipac protocol decoder and encoder","created_at":"2019-07-03T04:15:59Z","updated_at":"2019-07-03T15:26:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4075887d7f2cbc743bb14e7aa54305142d133629","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/traccar/traccar/pulls/4342/commits","review_comments_url":"https://api.github.com/repos/traccar/traccar/pulls/4342/comments","review_comment_url":"https://api.github.com/repos/traccar/traccar/pulls/comments{/number}","comments_url":"https://api.github.com/repos/traccar/traccar/issues/4342/comments","statuses_url":"https://api.github.com/repos/traccar/traccar/statuses/efb64c30835eccf1e532ea7d7618d2d40ce7b761","head":{"label":"edvalley:proposed","ref":"proposed","sha":"efb64c30835eccf1e532ea7d7618d2d40ce7b761","user":{"login":"edvalley","id":52469633,"node_id":"MDQ6VXNlcjUyNDY5NjMz","avatar_url":"https://avatars2.githubusercontent.com/u/52469633?v=4","gravatar_id":"","url":"https://api.github.com/users/edvalley","html_url":"https://github.com/edvalley","followers_url":"https://api.github.com/users/edvalley/followers","following_url":"https://api.github.com/users/edvalley/following{/other_user}","gists_url":"https://api.github.com/users/edvalley/gists{/gist_id}","starred_url":"https://api.github.com/users/edvalley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edvalley/subscriptions","organizations_url":"https://api.github.com/users/edvalley/orgs","repos_url":"https://api.github.com/users/edvalley/repos","events_url":"https://api.github.com/users/edvalley/events{/privacy}","received_events_url":"https://api.github.com/users/edvalley/received_events","type":"User","site_admin":false},"repo":{"id":194927816,"node_id":"MDEwOlJlcG9zaXRvcnkxOTQ5Mjc4MTY=","name":"traccar","full_name":"edvalley/traccar","private":false,"owner":{"login":"edvalley","id":52469633,"node_id":"MDQ6VXNlcjUyNDY5NjMz","avatar_url":"https://avatars2.githubusercontent.com/u/52469633?v=4","gravatar_id":"","url":"https://api.github.com/users/edvalley","html_url":"https://github.com/edvalley","followers_url":"https://api.github.com/users/edvalley/followers","following_url":"https://api.github.com/users/edvalley/following{/other_user}","gists_url":"https://api.github.com/users/edvalley/gists{/gist_id}","starred_url":"https://api.github.com/users/edvalley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edvalley/subscriptions","organizations_url":"https://api.github.com/users/edvalley/orgs","repos_url":"https://api.github.com/users/edvalley/repos","events_url":"https://api.github.com/users/edvalley/events{/privacy}","received_events_url":"https://api.github.com/users/edvalley/received_events","type":"User","site_admin":false},"html_url":"https://github.com/edvalley/traccar","description":"Traccar GPS Tracking System","fork":true,"url":"https://api.github.com/repos/edvalley/traccar","forks_url":"https://api.github.com/repos/edvalley/traccar/forks","keys_url":"https://api.github.com/repos/edvalley/traccar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edvalley/traccar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edvalley/traccar/teams","hooks_url":"https://api.github.com/repos/edvalley/traccar/hooks","issue_events_url":"https://api.github.com/repos/edvalley/traccar/issues/events{/number}","events_url":"https://api.github.com/repos/edvalley/traccar/events","assignees_url":"https://api.github.com/repos/edvalley/traccar/assignees{/user}","branches_url":"https://api.github.com/repos/edvalley/traccar/branches{/branch}","tags_url":"https://api.github.com/repos/edvalley/traccar/tags","blobs_url":"https://api.github.com/repos/edvalley/traccar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edvalley/traccar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edvalley/traccar/git/refs{/sha}","trees_url":"https://api.github.com/repos/edvalley/traccar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edvalley/traccar/statuses/{sha}","languages_url":"https://api.github.com/repos/edvalley/traccar/languages","stargazers_url":"https://api.github.com/repos/edvalley/traccar/stargazers","contributors_url":"https://api.github.com/repos/edvalley/traccar/contributors","subscribers_url":"https://api.github.com/repos/edvalley/traccar/subscribers","subscription_url":"https://api.github.com/repos/edvalley/traccar/subscription","commits_url":"https://api.github.com/repos/edvalley/traccar/commits{/sha}","git_commits_url":"https://api.github.com/repos/edvalley/traccar/git/commits{/sha}","comments_url":"https://api.github.com/repos/edvalley/traccar/comments{/number}","issue_comment_url":"https://api.github.com/repos/edvalley/traccar/issues/comments{/number}","contents_url":"https://api.github.com/repos/edvalley/traccar/contents/{+path}","compare_url":"https://api.github.com/repos/edvalley/traccar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edvalley/traccar/merges","archive_url":"https://api.github.com/repos/edvalley/traccar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edvalley/traccar/downloads","issues_url":"https://api.github.com/repos/edvalley/traccar/issues{/number}","pulls_url":"https://api.github.com/repos/edvalley/traccar/pulls{/number}","milestones_url":"https://api.github.com/repos/edvalley/traccar/milestones{/number}","notifications_url":"https://api.github.com/repos/edvalley/traccar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edvalley/traccar/labels{/name}","releases_url":"https://api.github.com/repos/edvalley/traccar/releases{/id}","deployments_url":"https://api.github.com/repos/edvalley/traccar/deployments","created_at":"2019-07-02T20:06:29Z","updated_at":"2019-07-02T20:06:34Z","pushed_at":"2019-07-03T04:10:55Z","git_url":"git://github.com/edvalley/traccar.git","ssh_url":"git@github.com:edvalley/traccar.git","clone_url":"https://github.com/edvalley/traccar.git","svn_url":"https://github.com/edvalley/traccar","homepage":"https://www.traccar.org","size":14785,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"traccar:master","ref":"master","sha":"612a78517f08362c7be94b62d6b4d5e108cfd665","user":{"login":"traccar","id":37892282,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3ODkyMjgy","avatar_url":"https://avatars1.githubusercontent.com/u/37892282?v=4","gravatar_id":"","url":"https://api.github.com/users/traccar","html_url":"https://github.com/traccar","followers_url":"https://api.github.com/users/traccar/followers","following_url":"https://api.github.com/users/traccar/following{/other_user}","gists_url":"https://api.github.com/users/traccar/gists{/gist_id}","starred_url":"https://api.github.com/users/traccar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/traccar/subscriptions","organizations_url":"https://api.github.com/users/traccar/orgs","repos_url":"https://api.github.com/users/traccar/repos","events_url":"https://api.github.com/users/traccar/events{/privacy}","received_events_url":"https://api.github.com/users/traccar/received_events","type":"Organization","site_admin":false},"repo":{"id":4038949,"node_id":"MDEwOlJlcG9zaXRvcnk0MDM4OTQ5","name":"traccar","full_name":"traccar/traccar","private":false,"owner":{"login":"traccar","id":37892282,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM3ODkyMjgy","avatar_url":"https://avatars1.githubusercontent.com/u/37892282?v=4","gravatar_id":"","url":"https://api.github.com/users/traccar","html_url":"https://github.com/traccar","followers_url":"https://api.github.com/users/traccar/followers","following_url":"https://api.github.com/users/traccar/following{/other_user}","gists_url":"https://api.github.com/users/traccar/gists{/gist_id}","starred_url":"https://api.github.com/users/traccar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/traccar/subscriptions","organizations_url":"https://api.github.com/users/traccar/orgs","repos_url":"https://api.github.com/users/traccar/repos","events_url":"https://api.github.com/users/traccar/events{/privacy}","received_events_url":"https://api.github.com/users/traccar/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/traccar/traccar","description":"Traccar GPS Tracking System","fork":false,"url":"https://api.github.com/repos/traccar/traccar","forks_url":"https://api.github.com/repos/traccar/traccar/forks","keys_url":"https://api.github.com/repos/traccar/traccar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/traccar/traccar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/traccar/traccar/teams","hooks_url":"https://api.github.com/repos/traccar/traccar/hooks","issue_events_url":"https://api.github.com/repos/traccar/traccar/issues/events{/number}","events_url":"https://api.github.com/repos/traccar/traccar/events","assignees_url":"https://api.github.com/repos/traccar/traccar/assignees{/user}","branches_url":"https://api.github.com/repos/traccar/traccar/branches{/branch}","tags_url":"https://api.github.com/repos/traccar/traccar/tags","blobs_url":"https://api.github.com/repos/traccar/traccar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/traccar/traccar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/traccar/traccar/git/refs{/sha}","trees_url":"https://api.github.com/repos/traccar/traccar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/traccar/traccar/statuses/{sha}","languages_url":"https://api.github.com/repos/traccar/traccar/languages","stargazers_url":"https://api.github.com/repos/traccar/traccar/stargazers","contributors_url":"https://api.github.com/repos/traccar/traccar/contributors","subscribers_url":"https://api.github.com/repos/traccar/traccar/subscribers","subscription_url":"https://api.github.com/repos/traccar/traccar/subscription","commits_url":"https://api.github.com/repos/traccar/traccar/commits{/sha}","git_commits_url":"https://api.github.com/repos/traccar/traccar/git/commits{/sha}","comments_url":"https://api.github.com/repos/traccar/traccar/comments{/number}","issue_comment_url":"https://api.github.com/repos/traccar/traccar/issues/comments{/number}","contents_url":"https://api.github.com/repos/traccar/traccar/contents/{+path}","compare_url":"https://api.github.com/repos/traccar/traccar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/traccar/traccar/merges","archive_url":"https://api.github.com/repos/traccar/traccar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/traccar/traccar/downloads","issues_url":"https://api.github.com/repos/traccar/traccar/issues{/number}","pulls_url":"https://api.github.com/repos/traccar/traccar/pulls{/number}","milestones_url":"https://api.github.com/repos/traccar/traccar/milestones{/number}","notifications_url":"https://api.github.com/repos/traccar/traccar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/traccar/traccar/labels{/name}","releases_url":"https://api.github.com/repos/traccar/traccar/releases{/id}","deployments_url":"https://api.github.com/repos/traccar/traccar/deployments","created_at":"2012-04-16T08:33:49Z","updated_at":"2019-07-03T09:29:16Z","pushed_at":"2019-07-03T06:11:54Z","git_url":"git://github.com/traccar/traccar.git","ssh_url":"git@github.com:traccar/traccar.git","clone_url":"https://github.com/traccar/traccar.git","svn_url":"https://github.com/traccar/traccar","homepage":"https://www.traccar.org","size":14774,"stargazers_count":1948,"watchers_count":1948,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1327,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":1272,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1327,"open_issues":1272,"watchers":1948,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/traccar/traccar/pulls/4342"},"html":{"href":"https://github.com/traccar/traccar/pull/4342"},"issue":{"href":"https://api.github.com/repos/traccar/traccar/issues/4342"},"comments":{"href":"https://api.github.com/repos/traccar/traccar/issues/4342/comments"},"review_comments":{"href":"https://api.github.com/repos/traccar/traccar/pulls/4342/comments"},"review_comment":{"href":"https://api.github.com/repos/traccar/traccar/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/traccar/traccar/pulls/4342/commits"},"statuses":{"href":"https://api.github.com/repos/traccar/traccar/statuses/efb64c30835eccf1e532ea7d7618d2d40ce7b761"}},"author_association":"NONE"}}
{"actor":{"display_login":"edvalley"}}