tamashii-common 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6afdc81465395d22163335e5e1f7e746bdcb71be
4
- data.tar.gz: 5f64a2e9084beddf0c3ad572aed70fc0e3545af1
3
+ metadata.gz: fcc88eaa8ec67a5c9098396905962e21ceca0ba6
4
+ data.tar.gz: 25321f5d4b2c993f421caf122b4dcafe1e9a2122
5
5
  SHA512:
6
- metadata.gz: 2208cb0c2df290e09ee816639eeed7b2f3c030a183d0af6ecaccad36959fef84a20d7b0edda75341a6139edc47a0fd427ca39e60ac564f8d89ffffc5f166719a
7
- data.tar.gz: b0bcb56b8a65823620df49804cccb65652d6dad276b4c4d0a3db135ac5b40fc59101548c1964654affe01577dbbe952034e8a5786eaef131e28fff3d2c16929f
6
+ metadata.gz: 68ef0d4e242e1597d4cf9804fc1fd56507843720f8bd6dc12b4b1c37801b8b57a7850ec939eeccebe204edc65ee55fc37a92a6976983087cc4700ae18930235f
7
+ data.tar.gz: 9420294cb59cf5b8c8ae90641456d899bd6eef0ea29617c525b96c8d67cf682d2c185388abdc5983cbc42f08e33b1c2dfadea1062b5b143dda03e8f98badd192
data/README.md CHANGED
@@ -1,38 +1,143 @@
1
- # Tamashii::Common
1
+ Tamashii Common
2
+ ===
2
3
 
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/tamashii/common`. 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
4
+ Tamashii Common is a collection of some commonly used features in Tamashii, including recorded, setting, packet encapsulation, etc.
6
5
 
7
6
  ## Installation
8
7
 
9
- Add this line to your application's Gemfile:
8
+ Add the following code to your `Gemfile`:
10
9
 
11
10
  ```ruby
12
11
  gem 'tamashii-common'
13
12
  ```
14
13
 
15
14
  And then execute:
15
+ ```ruby
16
+ $ bundle install
17
+ ```
16
18
 
17
- $ bundle
19
+ Or install it yourself with:
20
+ ```ruby
21
+ $ gem install tamashii-common
22
+ ```
18
23
 
19
- Or install it yourself as:
24
+ ## Usage
20
25
 
21
- $ gem install tamashii-common
26
+ ### Tamashii::Resolver
22
27
 
23
- ## Usage
28
+ Used to handle with different types of packets in Tamashii.
29
+
30
+ ```ruby
31
+ Tamashii::Resolver.handle Tamashii::AUTH_TOKEN, Tamashii::Manager::Authorization
32
+ ```
33
+
34
+ #### Default processing
35
+
36
+ In the absence of a specified processing mode, we can specify the way the default processing.
37
+
38
+ ```ruby
39
+ Tamashii::Resolver.default_handler Tamashii::Manager::Handler::Broadcaster
40
+ ```
41
+
42
+ #### Hook
43
+
44
+ This is a mechanism similar to Rack Middleware, which can intercept or process packets before the Handler executes.
45
+
46
+ ```ruby
47
+ Tamashii::Resolver.hook TamashiiRailsHook
48
+ ```
49
+
50
+ When there are lots of items need to be setting, we can write the following way instead.
51
+
52
+ ```ruby
53
+ Tamashii::Resolver.config do
54
+ handler Tamashii::Manager::Authorization
55
+ # ...
56
+
57
+ hook MyRailsHook
58
+ # ...
59
+ end
60
+ ```
24
61
 
25
- TODO: Write usage instructions here
62
+ ### Tamashii::Packet
63
+
64
+ IoT devices need some information about the data when transferring, so define a simple format to encapsulate the data in Tamashii.
65
+
66
+ |Field |Size |Description
67
+ |--- |--- |-
68
+ |type | 1byte |control code(Octal)
69
+ |tag | 2bytes |tag, default 0 is broadcast(will be removed)
70
+ |size | 2bytes |data size
71
+ |body | ~ |data content
72
+
73
+ We can use `Tamashii::Packet` to encapsulate different types of information, e.g., String, JSON,and Binary.
74
+
75
+ ```ruby
76
+ packet = Tamashii::Packet.new(Tamashii::Type::AUTH_TOKEN, 0, '1234')
77
+ ```
78
+
79
+ When we transfer data, we will translate the data into a Binary format before the transmission. If you want to convert, then we can use `dump` and `load` these two methods.
80
+
81
+ ```ruby
82
+ buffer = packet.dump
83
+ recv_packet = Tamashii::Packet.load(buffer)
84
+ ```
85
+
86
+ To get the original content of the data, you can use `type` and` body` to determine what information you want to access.
87
+
88
+ ```ruby
89
+ if packet.type == Tamashii::Type::AUTH_TOKEN
90
+ puts packet.body # AUTH_TOKEN is a string
91
+ end
92
+ ```
93
+
94
+ ### Tamashii::Type
95
+
96
+ There are a wide variety of types data exchange in Tamashii. In order to access these packet easily, we define a series of settings to assist in accessing these types.
97
+
98
+ ```ruby
99
+ # System Action
100
+ Tamashii::Type::POWEROFF
101
+ Tamashii::Type::REBOOT
102
+ # ...
103
+ ```
104
+
105
+ |Type id|Name|Description
106
+ |------|---------|-
107
+ |000 |POWEROFF|Shut down
108
+ |001 |REBOOT|Restart
109
+ |002 |RESTART|Restart service
110
+ |003 |UPDATE|Update the software
111
+ |010 |AUTH_TOKEN|Token certification
112
+ |017 |AUTH_RESPONSE|Certification results
113
+ |030 |RFID_NUMBER|Authentication card number
114
+ |031 |RFID_DATA|Card information
115
+ |036 |RFID_RESPONSE_JSON|Card reader results
116
+ |037 |RFID_RESPONSE_STRING|Card reader results
117
+ |040 |BUZZER_SOUND|Make buzzer sound
118
+ |050 |LCD_MESSAGE|Display LCD text
119
+ |051 |LCD_SET_IDLE_TEXT|Set the display text when standby
26
120
 
27
121
  ## Development
28
122
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
123
+ To get the source code
124
+
125
+ $ git clone git@github.com:tamashii-io/tamashii-common.git
126
+
127
+ Initialize the development environment
128
+
129
+ $ ./bin/setup
130
+
131
+ Run the spec
132
+
133
+ $ rspec
30
134
 
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).
135
+ Installation the version of development on localhost
32
136
 
33
- ## Contributing
137
+ $ bundle exec rake install
138
+ ## Contribution
34
139
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/lctseng/tamashii-common.
140
+ Please report to us on [Github](https://github.com/tamashii-io/tamashii-common) if there is any bug or suggested modified.
36
141
 
37
- Contributed by [5xruby Inc.](https://5xruby.tw/)
142
+ The project was developed by [5xruby Inc.](https://5xruby.tw/)
38
143
 
@@ -3,10 +3,8 @@ require "tamashii/packet"
3
3
  require "tamashii/type"
4
4
  require "tamashii/agent_hint"
5
5
  require "tamashii/handler"
6
- require "tamashii/hook"
7
6
  require "tamashii/resolver"
8
7
  require "tamashii/logger"
9
- require "tamashii/config"
10
8
  require "tamashii/environment"
11
9
 
12
10
  module Tamashii
@@ -1,5 +1,5 @@
1
1
  module Tamashii
2
2
  module Common
3
- VERSION = "0.1.6"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ module Tamashii
7
7
  def method_missing(name, *args, &block)
8
8
  self.instance.send(name, *args, &block)
9
9
  end
10
-
10
+
11
11
  def instance
12
12
  @instance ||= self.new
13
13
  end
@@ -17,6 +17,7 @@ module Tamashii
17
17
  @handlers ||= {}
18
18
  end
19
19
 
20
+ # TODO: Rename hook to middleware
20
21
  def hooks
21
22
  @hooks ||= []
22
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tamashii-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-08-04 00:00:00.000000000 Z
13
+ date: 2017-11-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -118,10 +118,8 @@ files:
118
118
  - lib/tamashii/agent_hint.rb
119
119
  - lib/tamashii/common.rb
120
120
  - lib/tamashii/common/version.rb
121
- - lib/tamashii/config.rb
122
121
  - lib/tamashii/environment.rb
123
122
  - lib/tamashii/handler.rb
124
- - lib/tamashii/hook.rb
125
123
  - lib/tamashii/logger.rb
126
124
  - lib/tamashii/packet.rb
127
125
  - lib/tamashii/resolver.rb
@@ -1,55 +0,0 @@
1
- require "tamashii/environment"
2
-
3
- module Tamashii
4
- class Config < Hash
5
- SHARED_CONFIG = %i(auth_type token log_file log_level token env).freeze
6
-
7
- class << self
8
- attr_accessor :default_config
9
-
10
- def method_missing(name, *args, &block)
11
- (@instance ||= self.new).send(name, *args, &block)
12
- end
13
-
14
- def register(name, default = nil)
15
- self.default_config ||= {}
16
- self.default_config[name.to_sym] = default
17
- end
18
-
19
- def [](name)
20
- send(name.to_sym)
21
- end
22
- end
23
-
24
- def initialize
25
- @accept_config = Set.new(SHARED_CONFIG)
26
- (self.class.default_config || {}).each { |name, value| register(name, value) }
27
- end
28
-
29
- def method_missing(name, *args, &block)
30
- return unless accept?(name) || accept?(name[0..-2])
31
- return register(name[0..-2], args.first) if name[-1..-1] == "="
32
- return register(name, args.first) if args.size > 0
33
- return register(name, yield(self)) if block_given?
34
- self[name]
35
- end
36
-
37
- def register(key, default = nil)
38
- @accept_config.add(key.to_sym)
39
- self[key.to_sym] = default if default
40
- end
41
-
42
- def accept?(key)
43
- @accept_config.include?(key.to_sym)
44
- end
45
-
46
- def env(env = nil)
47
- return Environment.new(self[:env]) if env.nil?
48
- self[:env] = env.to_s
49
- end
50
-
51
- def env=(env)
52
- self[:env] = env.to_s
53
- end
54
- end
55
- end
@@ -1,13 +0,0 @@
1
- module Tamashii
2
- class Hook
3
- attr_reader :env
4
-
5
- def initialize(env)
6
- @env = env
7
- end
8
-
9
- def call(pkt)
10
- raise NotImplementedError.new("Hook should implement the #call method")
11
- end
12
- end
13
- end