mm_gps 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f421d76d52b1d166ba48c7297133442e1d1d14f
4
+ data.tar.gz: 07eae466b465b8fcf74a39b4fde01f27c08cc120
5
+ SHA512:
6
+ metadata.gz: 014223691ed7495d9e02994a500f76d9e16da35b17d04bc52cb1b24de0001c9e6dbd3c3307b755da9d1278bf1b55e9170cd081818b96d98f66d39e14b70e3f61
7
+ data.tar.gz: a203d83b7b478948b2f1ae91381cd93580b24ef41417a6d71a15581beb1e21c6295ac19625243bfa3e691c322b2b55cb2fc597801fb165f3d0a946bdd6b60e45
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mm_gps.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Paolo Bosetti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # MmGps
2
+ [![Gem Version](https://badge.fury.io/rb/mm_gps.svg)](https://badge.fury.io/rb/mm_gps)
3
+
4
+ Ruby interface to [MarvelMind Indoor GPS System](http://www.marvelmind.com).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'mm_gps'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install mm_gps
21
+
22
+ ## Usage
23
+
24
+ Definitely a TODO section :(
25
+
26
+ ## Contributing
27
+
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mm_gps.
29
+
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
34
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/extensiontask"
3
+
4
+ task :build => :compile
5
+
6
+ Rake::ExtensionTask.new("mm_gps") do |ext|
7
+ ext.lib_dir = "lib/mm_gps"
8
+ end
9
+
10
+ task :default => [:clobber, :compile, :spec]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mm_gps"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+
3
+ create_makefile("mm_gps/mm_gps")
@@ -0,0 +1,59 @@
1
+ #include "mm_gps.h"
2
+
3
+ typedef unsigned char uchar;
4
+
5
+ typedef union {
6
+ ushort w;
7
+ struct{
8
+ uchar lo;
9
+ uchar hi;
10
+ } b;
11
+ uchar bs[2];
12
+ } bytes_t;
13
+
14
+ static ushort CRC16(const void *buf, ushort length) {
15
+ uchar *arr = (uchar *)buf;
16
+ bytes_t crc;
17
+ crc.w = 0xffff;
18
+ while(length--) {
19
+ char i;
20
+ ushort odd;
21
+ crc.b.lo ^= *arr++;
22
+ for(i = 0; i< 8; i++) {
23
+ odd = crc.w& 0x01;
24
+ crc.w >>= 1;
25
+ if(odd)
26
+ crc.w ^= 0xa001;
27
+ }
28
+ }
29
+ return (ushort)crc.w;
30
+ }
31
+
32
+ static VALUE mm_gps_CRC16(VALUE klass, VALUE str)
33
+ {
34
+ Check_Type(str, T_STRING);
35
+ return rb_fix_new(CRC16(RSTRING_PTR(str), RSTRING_LEN(str)));
36
+ }
37
+
38
+ static VALUE mm_gps_add_CRC16(VALUE klass, VALUE str)
39
+ {
40
+ union {
41
+ ushort u;
42
+ char s[2];
43
+ } crc;
44
+
45
+ Check_Type(str, T_STRING);
46
+ crc.u = CRC16(RSTRING_PTR(str), RSTRING_LEN(str));
47
+ return rb_str_buf_cat(str, crc.s, 2);
48
+ }
49
+
50
+
51
+ VALUE rb_mMmGps;
52
+
53
+ void
54
+ Init_mm_gps(void)
55
+ {
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
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef MM_GPS_H
2
+ #define MM_GPS_H 1
3
+
4
+ #include "ruby.h"
5
+
6
+ #endif /* MM_GPS_H */
@@ -0,0 +1,29 @@
1
+ class GPSException < Exception; end
2
+
3
+ module MmGps
4
+ def self.valid_crc16?(str)
5
+ crc16(str) == 0
6
+ end
7
+
8
+ def self.parse_packet(buf)
9
+ raise GPSException, "Invalid CRC" unless valid_crc16?(buf)
10
+ header = buf[0...5].unpack('CCS>C')
11
+
12
+ if header[2] == 1 then # Regular GPS Data
13
+ result = {}
14
+ payload = buf[5...16].unpack('L>S>3C')
15
+ result = %I(ts x y z f).zip(payload).to_h
16
+ elsif header[2] == 2 then # Frozen
17
+ len = buf[5].unpack('C')[0]
18
+ result = []
19
+ len.times do |i|
20
+ offset = 6 + i * 8
21
+ payload = buf[offset...(offset + 8)].unpack('CS>3C')
22
+ result << %I(address x y z reserved).zip(payload).to_h
23
+ end
24
+ else
25
+ raise GPSException, "Unexpected packet type #{header[2]}"
26
+ end
27
+ return result
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module MmGps
2
+ VERSION = "0.1.1"
3
+ end
data/lib/mm_gps.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "mm_gps/version"
2
+ require "mm_gps/mm_gps_module"
3
+ require "mm_gps/mm_gps"
4
+
5
+ module MmGps
6
+ # Your code goes here...
7
+ end
data/mm_gps.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mm_gps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mm_gps"
8
+ spec.version = MmGps::VERSION
9
+ spec.authors = ["Paolo Bosetti"]
10
+ spec.email = ["paolo.bosetti@unitn.it"]
11
+
12
+ spec.summary = %q{MarvelMind Indoor GPS driver.}
13
+ spec.description = %q{MarvelMind Indoor GPS driver.}
14
+ spec.homepage = "https://github.com/pbosetti/ruby_mm_gps"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ #spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.extensions = ["ext/mm_gps/extconf.rb"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.12"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rake-compiler"
34
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mm_gps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Paolo Bosetti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-21 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
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
+ description: MarvelMind Indoor GPS driver.
56
+ email:
57
+ - paolo.bosetti@unitn.it
58
+ executables: []
59
+ extensions:
60
+ - ext/mm_gps/extconf.rb
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - ext/mm_gps/extconf.rb
71
+ - ext/mm_gps/mm_gps.c
72
+ - ext/mm_gps/mm_gps.h
73
+ - lib/mm_gps.rb
74
+ - lib/mm_gps/mm_gps_module.rb
75
+ - lib/mm_gps/version.rb
76
+ - mm_gps.gemspec
77
+ homepage: https://github.com/pbosetti/ruby_mm_gps
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.5.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: MarvelMind Indoor GPS driver.
101
+ test_files: []