mm_gps 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -2
- data/ext/mm_gps/mm_gps.c +4 -4
- data/lib/mm_gps/mm_gps_beacon.rb +49 -0
- data/lib/mm_gps/mm_gps_module.rb +8 -5
- data/lib/mm_gps/version.rb +2 -2
- data/lib/mm_gps.rb +6 -4
- data/mm_gps.gemspec +2 -1
- data/test.rb +23 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d298aac2aca73d83fc9191f83fac4742cf672d5
|
4
|
+
data.tar.gz: 29f94747a2e57cafd333845eeb7ea26f03a69eb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b12093d8d971346ea2ee6955a8b432e09433ce4a187814cc7bc53fd2a54a3da25d19014a301fe89868e3a21a0d5dc0b721050b850c44dda5d51436a5028e0a78
|
7
|
+
data.tar.gz: 3cca41dcc61d525fd2e47fd70a8fd2398c45ff2b4c6471c5cf7f3f84ddfb47b759b65d5b27dfbe9a9d853dcdc2741ecc7bdddbd38c47952ef0bc2681e367409a
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# MmGPS
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/mm_gps.svg)](https://badge.fury.io/rb/mm_gps)
|
3
3
|
|
4
4
|
Ruby interface to [MarvelMind Indoor GPS System](http://www.marvelmind.com).
|
@@ -21,7 +21,32 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
|
24
|
+
Simple usage example:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'mm_gps'
|
28
|
+
|
29
|
+
PORT = "/dev/cu.usbmodem1411"
|
30
|
+
BAUD = 115200 # SerialPort class does not support non-standard 500 kbps
|
31
|
+
|
32
|
+
beacon = MmGPS::Beacon.new(PORT, BAUD)
|
33
|
+
beacon.trap # installs signal handler for CTRL-C
|
34
|
+
|
35
|
+
puts "Syncing..."
|
36
|
+
beacon.sync # discards any byte until the starting sequence "\xFFG" arrives
|
37
|
+
|
38
|
+
puts "Reading..."
|
39
|
+
while not beacon.closed? do
|
40
|
+
begin
|
41
|
+
p beacon.get_packet
|
42
|
+
rescue GPSException => e
|
43
|
+
puts "Packet Error: #{e.inspect}"
|
44
|
+
rescue IOError => e
|
45
|
+
puts "Port closed? #{e.inspect}"
|
46
|
+
exit
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
25
50
|
|
26
51
|
## Contributing
|
27
52
|
|
data/ext/mm_gps/mm_gps.c
CHANGED
@@ -48,12 +48,12 @@ static VALUE mm_gps_add_CRC16(VALUE klass, VALUE str)
|
|
48
48
|
}
|
49
49
|
|
50
50
|
|
51
|
-
VALUE
|
51
|
+
VALUE rb_mMmGPS;
|
52
52
|
|
53
53
|
void
|
54
54
|
Init_mm_gps(void)
|
55
55
|
{
|
56
|
-
|
57
|
-
rb_define_singleton_method(
|
58
|
-
rb_define_singleton_method(
|
56
|
+
rb_mMmGPS = rb_define_module("MmGPS");
|
57
|
+
rb_define_singleton_method(rb_mMmGPS, "crc16", mm_gps_CRC16, 1);
|
58
|
+
rb_define_singleton_method(rb_mMmGPS, "append_crc16", mm_gps_add_CRC16, 1);
|
59
59
|
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module MmGPS
|
2
|
+
class Beacon
|
3
|
+
START_TOKEN = "\xFFG".force_encoding(Encoding::BINARY)
|
4
|
+
EMPTY = ''.force_encoding(Encoding::BINARY)
|
5
|
+
|
6
|
+
def initialize(port, baud = 115200)
|
7
|
+
@sp = SerialPort.new(port, "baud" => baud)
|
8
|
+
@sp.read_timeout = 1000 #1 sec
|
9
|
+
@sp.binmode
|
10
|
+
end
|
11
|
+
|
12
|
+
def trap
|
13
|
+
Signal.trap("INT") do
|
14
|
+
@sp.close
|
15
|
+
puts "Beacon port: #{@sp.inspect}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def close
|
20
|
+
@sp.close
|
21
|
+
end
|
22
|
+
|
23
|
+
def closed?
|
24
|
+
return @sp.closed?
|
25
|
+
end
|
26
|
+
|
27
|
+
def sync
|
28
|
+
buf = EMPTY
|
29
|
+
begin
|
30
|
+
buf << (@sp.read(1) || EMPTY)
|
31
|
+
buf = buf[-2..-1] if buf.size > 2
|
32
|
+
end while buf != START_TOKEN
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_raw_packet
|
36
|
+
buf = START_TOKEN.dup
|
37
|
+
while true do
|
38
|
+
buf << (@sp.read(1) || EMPTY)
|
39
|
+
break if buf[-2..-1] == START_TOKEN
|
40
|
+
end
|
41
|
+
return buf[0...-2]
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_packet
|
45
|
+
return MmGPS::parse_packet(self.get_raw_packet)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
data/lib/mm_gps/mm_gps_module.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
class GPSException < Exception; end
|
2
2
|
|
3
|
-
module
|
3
|
+
module MmGPS
|
4
4
|
def self.valid_crc16?(str)
|
5
5
|
crc16(str) == 0
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.parse_packet(buf)
|
9
9
|
raise GPSException, "Invalid CRC" unless valid_crc16?(buf)
|
10
|
-
|
11
|
-
|
10
|
+
# warn "Invalid CRC" unless valid_crc16?(buf)
|
11
|
+
header = buf[0..5].unpack('CCS<C')
|
12
12
|
if header[2] == 1 then # Regular GPS Data
|
13
13
|
result = {}
|
14
|
-
payload = buf[5...16].unpack('L
|
14
|
+
payload = buf[5...16].unpack('L<s<3C')
|
15
15
|
result = %I(ts x y z f).zip(payload).to_h
|
16
|
+
result[:ts] /= 64.0
|
17
|
+
%I(x y z).each {|k| result[k] /= 100.0}
|
16
18
|
elsif header[2] == 2 then # Frozen
|
17
19
|
len = buf[5].unpack('C')[0]
|
18
20
|
result = []
|
19
21
|
len.times do |i|
|
20
22
|
offset = 6 + i * 8
|
21
|
-
payload = buf[offset...(offset + 8)].unpack('
|
23
|
+
payload = buf[offset...(offset + 8)].unpack('Cs<3C')
|
22
24
|
result << %I(address x y z reserved).zip(payload).to_h
|
25
|
+
%I(x y z).each {|k| result.last[k] /= 100.0}
|
23
26
|
end
|
24
27
|
else
|
25
28
|
raise GPSException, "Unexpected packet type #{header[2]}"
|
data/lib/mm_gps/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.1.
|
1
|
+
module MmGPS
|
2
|
+
VERSION = "0.1.2"
|
3
3
|
end
|
data/lib/mm_gps.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'serialport'
|
2
|
+
require 'mm_gps/version'
|
3
|
+
require 'mm_gps/mm_gps_module'
|
4
|
+
require 'mm_gps/mm_gps_beacon'
|
5
|
+
require 'mm_gps/mm_gps'
|
4
6
|
|
5
|
-
module
|
7
|
+
module MmGPS
|
6
8
|
# Your code goes here...
|
7
9
|
end
|
data/mm_gps.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'mm_gps/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "mm_gps"
|
8
|
-
spec.version =
|
8
|
+
spec.version = MmGPS::VERSION
|
9
9
|
spec.authors = ["Paolo Bosetti"]
|
10
10
|
spec.email = ["paolo.bosetti@unitn.it"]
|
11
11
|
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
spec.extensions = ["ext/mm_gps/extconf.rb"]
|
30
|
+
spec.add_dependency "serialport", "~> 1.3.1"
|
30
31
|
|
31
32
|
spec.add_development_dependency "bundler", "~> 1.12"
|
32
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/test.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'mm_gps'
|
3
|
+
|
4
|
+
PORT = "/dev/cu.usbmodem1411"
|
5
|
+
BAUD = 115200 # SerialPort class does not support non-standard 500 kbps
|
6
|
+
|
7
|
+
beacon = MmGPS::Beacon.new(PORT, BAUD)
|
8
|
+
beacon.trap # installs signal handler for CTRL-C
|
9
|
+
|
10
|
+
puts "Syncing..."
|
11
|
+
beacon.sync # discards any byte until the starting sequence "\xFFG" arrives
|
12
|
+
|
13
|
+
puts "Reading..."
|
14
|
+
while not beacon.closed? do
|
15
|
+
begin
|
16
|
+
p beacon.get_packet
|
17
|
+
rescue GPSException => e
|
18
|
+
puts "Packet Error: #{e.inspect}"
|
19
|
+
rescue IOError => e
|
20
|
+
puts "Port closed? #{e.inspect}"
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm_gps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paolo Bosetti
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: serialport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.1
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,9 +85,11 @@ files:
|
|
71
85
|
- ext/mm_gps/mm_gps.c
|
72
86
|
- ext/mm_gps/mm_gps.h
|
73
87
|
- lib/mm_gps.rb
|
88
|
+
- lib/mm_gps/mm_gps_beacon.rb
|
74
89
|
- lib/mm_gps/mm_gps_module.rb
|
75
90
|
- lib/mm_gps/version.rb
|
76
91
|
- mm_gps.gemspec
|
92
|
+
- test.rb
|
77
93
|
homepage: https://github.com/pbosetti/ruby_mm_gps
|
78
94
|
licenses:
|
79
95
|
- MIT
|