coban 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +7 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/ROADMAP.md +17 -0
- data/lib/coban/invalid_message.rb +4 -0
- data/lib/coban/tk103b.rb +79 -0
- data/lib/coban/version.rb +3 -0
- data/lib/coban.rb +7 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 040e0c7096f0a433fe05c3b1b80b4edaa94729d4
|
4
|
+
data.tar.gz: b828abd62fcd0c7457668fa976909ed736177b61
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 08f8e697775bf09af33fc41d80e0851e693abbe646f5eff9832f88fa9f378d7ac54fb6f8456e3674008970383fa2b8f519ae0696d07036626b36eb0fd0992013
|
7
|
+
data.tar.gz: 98fa2ffdf96fc1a151c74c9c3fa03a5f7d9aa51dc2b1d3ee25d6f37e3bb32b4c1dbf4e5e3c6939388d4a816e4c4b610030762350303b6eea7ad3e66bba5938b6
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Coban
|
2
|
+
|
3
|
+
Ruby protocol parser for coban trackers
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'coban'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install coban
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Login message:
|
22
|
+
```ruby
|
23
|
+
require 'coban'
|
24
|
+
response = Coban::TK103B.parse('##,imei:359710041775538,A;')
|
25
|
+
# { imei: '359710041775538', type: :logon, response: 'LOAD' }
|
26
|
+
```
|
27
|
+
|
28
|
+
Heartbeat:
|
29
|
+
```ruby
|
30
|
+
require 'coban'
|
31
|
+
response = Coban::TK103B.parse('359710041775538')
|
32
|
+
# { imei: '359710041775538', type: :heartbeat, response: 'ON' }
|
33
|
+
```
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( http://github.com/diegobernardes/coban/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/ROADMAP.md
ADDED
data/lib/coban/tk103b.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Coban
|
2
|
+
module TK103B
|
3
|
+
def self.parse(content)
|
4
|
+
result = nil
|
5
|
+
|
6
|
+
if content.start_with? '##'
|
7
|
+
result = self.message_logon(content)
|
8
|
+
elsif content.include? ','
|
9
|
+
result = self.message(content)
|
10
|
+
else
|
11
|
+
result = self.message_heartbeat(content)
|
12
|
+
end
|
13
|
+
|
14
|
+
return result
|
15
|
+
rescue
|
16
|
+
InvalidMessage.new "Error parsing message"
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.message(content)
|
20
|
+
message_headers = [
|
21
|
+
:imei, :type, :date, :phone, :gps_status, :time,
|
22
|
+
:gps_signal, :latitude, :north_south, :longitude,
|
23
|
+
:east_west, :speed, :direction, :elevation, :acc,
|
24
|
+
:door, :fuel, :oil, :temperatura
|
25
|
+
]
|
26
|
+
|
27
|
+
splited_content = content.gsub('imei:','').gsub(';','').split(',', -1)
|
28
|
+
|
29
|
+
result = {
|
30
|
+
imei: splited_content[message_headers.index(:imei)],
|
31
|
+
type: splited_content[message_headers.index(:type)],
|
32
|
+
phone: splited_content[message_headers.index(:phone)],
|
33
|
+
gps_status: splited_content[message_headers.index(:gps_status)],
|
34
|
+
gps_signal: splited_content[message_headers.index(:gps_signal)],
|
35
|
+
speed: splited_content[message_headers.index(:speed)],
|
36
|
+
direction: splited_content[message_headers.index(:direction)]
|
37
|
+
}
|
38
|
+
|
39
|
+
if splited_content.count > 13
|
40
|
+
result[:elevation] = splited_content[message_headers.index(:elevation)]
|
41
|
+
result[:acc] = splited_content[message_headers.index(:acc)]
|
42
|
+
result[:door] = splited_content[message_headers.index(:door)]
|
43
|
+
result[:fuel] = splited_content[message_headers.index(:fuel)]
|
44
|
+
result[:oil] = splited_content[message_headers.index(:oil)]
|
45
|
+
result[:temperatura] = splited_content[message_headers.index(:temperatura)]
|
46
|
+
end
|
47
|
+
|
48
|
+
pre_latitude = splited_content[message_headers.index(:latitude)]
|
49
|
+
latitude = pre_latitude[0...2].to_i(10) + ( pre_latitude[2...pre_latitude.size].to_f / 60 )
|
50
|
+
latitude *= -1 if splited_content[message_headers.index(:north_south)] == 'S'
|
51
|
+
|
52
|
+
pre_longitude = splited_content[message_headers.index(:longitude)]
|
53
|
+
longitude = pre_longitude[0...3].to_i(10) + ( pre_longitude[3...pre_longitude.size].to_f / 60 )
|
54
|
+
longitude *= -1 if splited_content[message_headers.index(:east_west)] == 'W'
|
55
|
+
|
56
|
+
result[:latitude] = latitude
|
57
|
+
result[:longitude] = longitude
|
58
|
+
|
59
|
+
date = splited_content[message_headers.index(:date)]
|
60
|
+
time = splited_content[message_headers.index(:time)]
|
61
|
+
unless date.size == date.count('0')
|
62
|
+
time = splited_content[message_headers.index(:time)]
|
63
|
+
result[:date] = DateTime.strptime('20' + date[0...6] + time.split('.').first,'%Y%m%d%H%M%S')
|
64
|
+
end
|
65
|
+
|
66
|
+
return result
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.message_logon(content)
|
70
|
+
result = /##,imei:(?<imei>\d*).*;/.match(content)
|
71
|
+
return { imei: result[:imei], type: :logon, response: 'LOAD' } if result
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.message_heartbeat(content)
|
75
|
+
result = /(?<imei>\d*)/.match(content)
|
76
|
+
return { imei: result[:imei], type: :heartbeat, response: 'ON' } if result
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/coban.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coban
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Diego Bernardes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: debugger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Parser for Coban trackers
|
70
|
+
email:
|
71
|
+
- diego.bernardes@outlook.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- CHANGELOG.md
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- ROADMAP.md
|
80
|
+
- lib/coban.rb
|
81
|
+
- lib/coban/invalid_message.rb
|
82
|
+
- lib/coban/tk103b.rb
|
83
|
+
- lib/coban/version.rb
|
84
|
+
homepage: https://github.com/diegobernardes/coban
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Parser for Coban trackers
|
108
|
+
test_files: []
|