kuro-rs 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -14,3 +14,4 @@ tasks/rspec.rake
14
14
  examples/read.rb
15
15
  examples/write.rb
16
16
  bin/kuro-rs
17
+ bin/kuro-rs-server
data/README.rdoc CHANGED
@@ -27,13 +27,25 @@ control KURO-RS (http://www.kuroutoshikou.com/modules/display/?iid=928) and PC-O
27
27
 
28
28
  == TOOLS:
29
29
 
30
- you can use simple command line application.
30
+ simple command line application.
31
31
 
32
32
  # read
33
- % kuro-rs /dev.tty.usbserial-0012a3b4
33
+ % kuro-rs /dev/tty.usbserial-0012a3b4
34
34
 
35
35
  # write
36
- % kuro-rs /dev.tty.usbserial-0012a3b4 ffffffff0300f0e0018083...
36
+ % kuro-rs /dev/tty.usbserial-0012a3b4 ffffffff0300f0e0018083...
37
+
38
+
39
+ http interface
40
+
41
+ # run server
42
+ % kuro-rs-server /dev/tty.usbserial-0012a3b4 -p 8080
43
+
44
+ # read
45
+ % curl 'http://localhost:8080'
46
+
47
+ # write
48
+ % curl -d 'ffffffff0300f0e0018083...' 'http://localhost:8080'
37
49
 
38
50
  == REQUIREMENTS:
39
51
 
data/Rakefile CHANGED
@@ -13,7 +13,10 @@ Hoe.plugin :newgem
13
13
  $hoe = Hoe.spec 'kuro-rs' do
14
14
  self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
15
  self.rubyforge_name = self.name # TODO this is default value
16
- self.extra_deps = [['serialport','>= 1.0.4']]
16
+ self.extra_deps = [['serialport','>= 1.0.4'],
17
+ ['ArgsParser'],
18
+ ['eventmachine_httpserver'],
19
+ ['eventmachine']]
17
20
 
18
21
  end
19
22
 
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'kuro-rs'
4
+ require 'eventmachine'
5
+ require 'evma_httpserver'
6
+ require 'ArgsParser'
7
+ require 'json'
8
+
9
+ parser = ArgsParser.parser
10
+ parser.comment(:port, 'http port', 8080)
11
+ parser.bind(:help, :h, 'show help')
12
+ device_name, params = parser.parse ARGV
13
+
14
+ if parser.has_option(:help) or device_name.to_s.size < 1
15
+ puts parser.help
16
+ puts "e.g. kuro-rs-server /det/tty.usbserial-0012a3b4 -port 8080"
17
+ exit 1
18
+ end
19
+
20
+ begin
21
+ @@kr = KuroRs.open device_name
22
+ rescue KuroRs::Error, StandardError => e
23
+ STDERR.puts e
24
+ exit 1
25
+ end
26
+
27
+ class KuroRsServer < EM::Connection
28
+ include EM::HttpServer
29
+
30
+ def process_http_request
31
+ res = EM::DelegatedHttpResponse.new self
32
+ puts "[http] #{@http_request_method} #{@http_path_info} #{@http_query_string} #{@http_post_content}"
33
+ begin
34
+ raise 'device busy' if @@kr.busy?
35
+ if @http_request_method == 'GET'
36
+ res.content = @@kr.read
37
+ elsif @http_request_method == 'POST'
38
+ @@kr.write @http_post_content
39
+ res.content = 'success'
40
+ end
41
+ res.status = 200
42
+ res.send_response
43
+ rescue StandardError, KuroRs::Error => e
44
+ res.status = 500
45
+ res.content = e.to_s
46
+ res.send_response
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ EM::run do
53
+ EM::start_server("0.0.0.0", params[:port].to_i, KuroRsServer)
54
+ puts "kuro-rs-server start, port #{params[:port].to_i}"
55
+ end
data/lib/kuro-rs.rb CHANGED
@@ -10,5 +10,5 @@ Dir.glob(File.dirname(__FILE__)+'/kuro-rs/*.rb').each do |f|
10
10
  end
11
11
 
12
12
  module KuroRs
13
- VERSION = '0.0.2'
13
+ VERSION = '0.0.3'
14
14
  end
data/lib/kuro-rs/main.rb CHANGED
@@ -2,7 +2,7 @@ module KuroRs
2
2
  def KuroRs.open(device_name)
3
3
  KuroRs.new(device_name)
4
4
  end
5
-
5
+
6
6
  class Error < Exception
7
7
  end
8
8
 
@@ -96,6 +96,7 @@ module KuroRs
96
96
  @sp.putc c
97
97
  }
98
98
  raise Error.new 'response is not E' unless @sp.getc.chr == 'E'
99
+ @busy = false
99
100
  rescue => e
100
101
  @busy = false
101
102
  raise Error.new e
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuro-rs
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sho Hashimoto
@@ -35,9 +35,51 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: hoe
38
+ name: ArgsParser
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: eventmachine_httpserver
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: eventmachine
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: hoe
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
41
83
  none: false
42
84
  requirements:
43
85
  - - ~>
@@ -48,12 +90,13 @@ dependencies:
48
90
  - 12
49
91
  version: "2.12"
50
92
  type: :development
51
- version_requirements: *id002
93
+ version_requirements: *id005
52
94
  description: control KURO-RS (http://www.kuroutoshikou.com/modules/display/?iid=928) and PC-OP-RS1 (http://buffalo.jp/products/catalog/item/p/pc-op-rs1/)
53
95
  email:
54
96
  - hashimoto@shokai.org
55
97
  executables:
56
98
  - kuro-rs
99
+ - kuro-rs-server
57
100
  extensions: []
58
101
 
59
102
  extra_rdoc_files:
@@ -76,6 +119,7 @@ files:
76
119
  - examples/read.rb
77
120
  - examples/write.rb
78
121
  - bin/kuro-rs
122
+ - bin/kuro-rs-server
79
123
  - .gemtest
80
124
  has_rdoc: true
81
125
  homepage: http://github.com/shokai/ruby-kuro-rs