LazGem 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at TODO: Write your email address. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in LazGem.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) <year> <copyright holders>
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6
+
7
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 NaotakaSaito
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/LazGem.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'LazGem/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "LazGem"
8
+ spec.version = LazGem::VERSION
9
+ spec.authors = ["NaotakaSaito"]
10
+ spec.email = ["saitou088@dsn.lapis-semi.com"]
11
+
12
+ spec.summary = %q{Lazurite ruby gem}
13
+ spec.description = %q{low power IoT device }
14
+ spec.homepage = "https://github.com/NaotakaSaito/LazGem"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
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
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ end
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # LazGem
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/LazGem`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'LazGem'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install LazGem
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/LazGem. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "LazGem"
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,242 @@
1
+ # -*- coding: utf-8; mode: ruby -*-
2
+ #
3
+ # Function:
4
+ # Lazurite Pi Gateway SubGHz library
5
+
6
+
7
+ class LAZURITE_ERROR < StandardError; end
8
+ class LazGem::Client
9
+ ##
10
+ # func : Read the data from the receiving pipe
11
+ # input : Receive pipe fp
12
+ # return : Receive data
13
+ ##
14
+
15
+ @@device_rd=nil
16
+ @@device_wr=nil
17
+
18
+ # LAZURITE.open(ch=36,panid=0xabcd,pwr=20,rate=100),mode=2)
19
+ # function
20
+ # open device deriver
21
+ # parameter
22
+ # ch: frequency 24-61. 36 is in default
23
+ # panid: pan id
24
+ # pwr: tx power
25
+ # rate: bit rate 50 or 100
26
+ # pwr: tx power 1 or 20
27
+ # mode: must be 2
28
+ # return
29
+ # none
30
+ def device_open(ch=36, panid=0xabcd, pwr=20, rate=100, mode=2, callback=nil)
31
+ if(ch < 24) || (ch > 61) then
32
+ puts "ch is invalid. it must be 24-61"
33
+ raise LAZURITE_ERROR
34
+ return
35
+ end
36
+ if(pwr != 1) && (pwr != 20) then
37
+ puts "pwr is invalid. it must be 1 or 20"
38
+ raise LAZURITE_ERROR
39
+ return
40
+ end
41
+ if(rate != 50) && (rate != 100) then
42
+ puts "rate is invalid. it must be 50 or 100"
43
+ raise LAZURITE_ERROR
44
+ return
45
+ end
46
+ cmd = "sudo insmod /home/pi/driver/sub-ghz/DRV_802154.ko ch=" +ch.to_s+" panid=0x"+panid.to_s(16)+ " pwr="+pwr.to_s+" rate="+rate.to_s + " mode="+mode.to_s(16)
47
+ result = system(cmd)
48
+ bp3596_dev = "/dev/bp3596"
49
+ sleep(0.1)
50
+ result = system("sudo chmod 777 "+bp3596_dev)
51
+ # p result
52
+ sleep(0.1)
53
+ @@device_rd = open(bp3596_dev,"rb")
54
+ @@device_wr = open(bp3596_dev,"wb")
55
+ result = system("tail -n -2 /var/log/messages")
56
+ print("\n")
57
+ # p result
58
+ print("Success to load SubGHz module\n")
59
+ end
60
+
61
+ # LAZURITE.close()
62
+ # function
63
+ # close device deriver
64
+ # parameter
65
+ # none
66
+ # return
67
+ # none
68
+ def device_close()
69
+ @@device_rd.close
70
+ @@device_wr.close
71
+ @@devie_rd = nil
72
+ @@device_wr = nil
73
+ cmd = "sudo rmmod DRV_802154"
74
+ system(cmd)
75
+ p cmd
76
+ end
77
+
78
+
79
+ # LAZURITE.read()
80
+ # function
81
+ # try to read data from SubGHz module
82
+ # parameter
83
+ # none
84
+ # return
85
+ # -1: no data
86
+ # Hash[]: receiving data
87
+ # key
88
+ # "command" => command it should be fixed to 0x03
89
+ # "Time" => Time class of receiving time
90
+ # "usec" => integer type data of usec for receiving time
91
+ # "rxPanid" => unsigned long type data of panid for receiving
92
+ # if packet does not include panid, data is -1.
93
+ # "rxAddrType" => unsigned char type deta of address type
94
+ # 0 = packet no rxAddr
95
+ # 1 = rxAddr = 8 bit integer type
96
+ # 2 = rxAddr = 16bit include rxAddr
97
+ # 3 = rxAddr = 64bit rxAddr String type
98
+ # "rxAddr" => rx address. data type is determined by rxAddrType
99
+ # "txPanid" => long type data of panid for sending
100
+ # if packet does not include panid, data is -1.
101
+ # "txAddrType" => unsigned char type deta of address type
102
+ # same meaning of data as rxAddrType
103
+ # "txAddr" => tx Address. data type is determind by txAddrType
104
+ # "rssi" => RF power, when receiving
105
+ # "payload" => binary stream type of data. need to unpack for using as strings
106
+
107
+ def read()
108
+ # Data reception wait (timeout = 100ms)
109
+ ret = select([@@device_rd], nil, nil, 0.1)
110
+ # Reads the size of the received data
111
+ len = @@device_rd.read(2)
112
+ if ((len == "") || (len == nil)) then # read result is empty
113
+ return -1
114
+ end
115
+ size = len.unpack("S*")[0]
116
+ # The received data is read
117
+ recv_buf = @@device_rd.read(size)
118
+ if ((recv_buf == "") || (recv_buf == nil)) then # read result is empty
119
+ return -1
120
+ end
121
+ return recv_dec(recv_buf,size)
122
+ end
123
+
124
+ def recv_dec(raw,size)
125
+ # PANID
126
+ command = raw[0..1].unpack("S*")[0]
127
+ tv_sec = raw[2..5].unpack("L*")[0]
128
+ tv_usec = raw[6..9].unpack("L*")[0]/1000
129
+ t = Time.at(tv_sec,tv_usec)
130
+ area = raw[10..11].unpack("a2")[0]
131
+ ch = raw[12..13].unpack("S*")[0]
132
+ rate = raw[14..15].unpack("S*")[0]
133
+ pwr = raw[16..17].unpack("S*")[0]
134
+ header = raw[18..21].unpack("L*")[0]
135
+ rxPanid = raw[22..25].unpack("L*")[0]
136
+ rxAddrType = raw[26].unpack("C*")[0]
137
+ if rxAddrType == 0 then
138
+ rxAddr = -1
139
+ elsif rxAddrType == 1 then
140
+ rxAddr = raw[34].unpack("n*")[0]
141
+ elsif rxAddrType == 2 then
142
+ rxAddr = raw[33..34].unpack("n*")[0]
143
+ elsif rxAddrType == 3 then
144
+ rxAddr = raw[27..34].unpack("a8*")[0]
145
+ end
146
+ txPanid = raw[35..38].unpack("L*")[0]
147
+ txAddrType = raw[39].unpack("C*")[0]
148
+
149
+ if txAddrType == 0 then
150
+ txAddr = -1
151
+ elsif txAddrType == 1 then
152
+ txAddr = raw[47].unpack("n*")[0]
153
+ elsif txAddrType == 2 then
154
+ txAddr = raw[46..47].unpack("n*")[0]
155
+ elsif txAddrType == 3 then
156
+ txAddr = raw[40..47].unpack("a8*")[0]
157
+ end
158
+
159
+ rssi = raw[48].unpack("C*")[0]
160
+ payload = raw[49..size-2]
161
+
162
+ out = Hash["Command" => command,
163
+ "Time" => t,
164
+ "usec" => tv_usec,
165
+ "Area" => area,
166
+ "ch" => ch,
167
+ "rate" => rate,
168
+ "pwr" => pwr,
169
+ "header" => header,
170
+ "rxPanid" => rxPanid,
171
+ "rxAddrType" => rxAddrType,
172
+ "rxAddr" => rxAddr,
173
+ "txPanid" => txPanid,
174
+ "txAddrType" => txAddrType,
175
+ "txAddr" => txAddr,
176
+ "rssi" => rssi,
177
+ "payload" => payload,
178
+ ]
179
+ end
180
+
181
+ # LAZURITE.write()
182
+ # function
183
+ # sending data by SubGHz
184
+ # currently only one format is supported.
185
+ # parameter
186
+ # HASH[]
187
+ # currently two parameter should be included.
188
+ # "rxAddr" => Integer type of rxAddress
189
+ # "payload" => binary array of sending data
190
+ # <option>
191
+ # "rxPanid" => rxPanid. If it is not included, rxPanid = 0xABCD
192
+ # return
193
+ # none
194
+ # Exception
195
+ # KeyError : if hash data does not include rxAddr, this error is raisen.
196
+ # PAYLOAD_SIZE_OVER : payload length is over
197
+ def write(packet)
198
+ begin
199
+ rxAddrType =packet.fetch("header")
200
+ rescue KeyError
201
+ header =0xa821
202
+ end
203
+ seq = 0
204
+
205
+ # panid
206
+ begin
207
+ rxPanid =packet.fetch("rxPanid")
208
+ rescue KeyError
209
+ rxPanid = 0xABCD
210
+ end
211
+
212
+ # rxAddr
213
+ rxAddr =packet.fetch("rxAddr")
214
+
215
+ # txAddr
216
+ txAddr = 0
217
+
218
+ #payload
219
+ payload =packet["payload"]
220
+ if payload.length > 235 then
221
+ raise PAYLOAD_SIZE_OVER
222
+ return
223
+ end
224
+
225
+ raw = [header,seq,rxPanid,rxAddr,txAddr,payload].pack("scsssa*")
226
+
227
+ ret = select(nil, [@@device_wr], nil, 0.1)
228
+ begin
229
+ len = @@device_wr.write(raw)
230
+ rescue
231
+ raise EACK
232
+ end
233
+ return len
234
+ end
235
+ def print_bin(data)
236
+ out = ""
237
+ for i in 0..data.length-1 do
238
+ print(data[i].unpack("H*")[0]," ")
239
+ end
240
+ print("\n")
241
+ end
242
+ end
@@ -0,0 +1,3 @@
1
+ module LazGem
2
+ VERSION = "0.0.0"
3
+ end
data/lib/LazGem.rb ADDED
@@ -0,0 +1,5 @@
1
+ module LazGem; end
2
+
3
+ require_relative "LazGem/version"
4
+ require_relative "LazGem/client"
5
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: LazGem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - NaotakaSaito
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.11'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '5.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ description: ! 'low power IoT device '
63
+ email:
64
+ - saitou088@dsn.lapis-semi.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .travis.yml
71
+ - CODE_OF_CONDUCT.md
72
+ - Gemfile
73
+ - LICENSE
74
+ - LICENSE.txt
75
+ - LazGem.gemspec
76
+ - README.md
77
+ - Rakefile
78
+ - bin/console
79
+ - bin/setup
80
+ - lib/LazGem.rb
81
+ - lib/LazGem/client.rb
82
+ - lib/LazGem/version.rb
83
+ homepage: https://github.com/NaotakaSaito/LazGem
84
+ licenses:
85
+ - MIT
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.23
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Lazurite ruby gem
108
+ test_files: []