xremotebot 0.1.0

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: 68c01bdb688bc6396fad2e903253c9cde49ec661
4
+ data.tar.gz: ac0874346c2ae60110ca1bf6fb22f4408b2a1520
5
+ SHA512:
6
+ metadata.gz: a38b9ee64c67bc5749920b0535be85a093801bc78a105a32259976c29eb4cc2cd04b730941c07beb38cfcb066ef2c16bd73722b75960c3dc52512b84f6bcbb67
7
+ data.tar.gz: 7524d2da011156e8bd6fac20d88239cb86b5e971a2cb71dd4663ee77c79b8fa6b9296f464ab7370be35cdc144e4b12761b97479fcd88c041c468a4e3385f3ac7
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,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xremotebot.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Xremotebot
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/xremotebot`. 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 'xremotebot'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install xremotebot
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 `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` to 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
+ 1. Fork it ( https://github.com/[my-github-username]/xremotebot/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+
5
+ # You can add fixtures and/or initialization code here to make experimenting
6
+ # with your gem easier. You can also use a different console, if you like.
7
+
8
+ # (If you use this, don't forget to add pry to your Gemfile!)
9
+ # require "pry"
10
+ # Pry.start
11
+ require "xremotebot"
12
+ #require "irb"
13
+ #IRB.start
14
+ require "pry"
15
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/lib/xremotebot.rb ADDED
@@ -0,0 +1,172 @@
1
+ require 'xremotebot/version'
2
+ require 'websocket'
3
+ require 'json'
4
+
5
+ module XRemoteBot
6
+ alias :wait :sleep
7
+
8
+ class WS
9
+ def initialize(host, port, path)
10
+ @sock = TCPSocket.new host, port
11
+ url = %Q(ws://#{host}:#{port}/#{path})
12
+ @handshake = WebSocket::Handshake::Client.new(url: url)
13
+ @sock.puts(@handshake)
14
+
15
+ @handshake << @sock.recv(4096)
16
+ while !@handshake.finished?
17
+ @handshake << @sock.recv(4096)
18
+ end
19
+
20
+ raise Exception unless @handshake.valid?
21
+
22
+ end
23
+
24
+ def send(data)
25
+ frame = WebSocket::Frame::Outgoing::Server.new(
26
+ version: @handshake.version,
27
+ data: data,
28
+ type: :text
29
+ )
30
+ @sock.send frame.to_s, 0
31
+ end
32
+
33
+ def receive()
34
+ frame = WebSocket::Frame::Incoming::Server.new(
35
+ version: @handshake.version
36
+ )
37
+ frame << @sock.recv(4096)
38
+ data = ''
39
+ loop do
40
+ part = frame.next
41
+ break if part.nil?
42
+ data += part.to_s
43
+ end
44
+ return data
45
+ end
46
+
47
+ end
48
+ class Server
49
+ attr_reader :ws
50
+ def initialize(host, port, path, api_key)
51
+ @ws = WS.new(host, port, path)
52
+ if authentication_required
53
+ raise Exception, 'Authentication failed' unless authenticate(api_key)
54
+ end
55
+ end
56
+
57
+ def send_ws_msg(entity, method, *args)
58
+ msg = JSON.dump({
59
+ entity: entity,
60
+ method: method,
61
+ args: args,
62
+ })
63
+ ws.send(msg)
64
+ response = JSON.load ws.receive
65
+ raise Exception, response['message'] if response['response'] == 'error'
66
+ response['value']
67
+ end
68
+
69
+ def authentication_required
70
+ send_ws_msg 'global', 'authentication_required'
71
+ end
72
+
73
+ def authenticate(api_key)
74
+ send_ws_msg 'global', 'authenticate', api_key
75
+ end
76
+
77
+ def get_robots
78
+ send_ws_msg 'global', 'get_robots'
79
+ end
80
+
81
+ def fetch_robot
82
+ send_ws_msg 'global', 'fetch_robot'
83
+ end
84
+
85
+ def reserve(robot_model, robot_id)
86
+ send_ws_msg 'global', 'reserve', robot_model, robot_id
87
+ end
88
+ end
89
+
90
+ class Robot
91
+ def initialize(server, robot_obj)
92
+ @server = server
93
+ @robot_model = robot_obj['robot_model']
94
+ @robot_id = robot_obj['robot_id']
95
+ end
96
+
97
+ def send_ws_msg(msg, *args)
98
+ @server.send_ws_msg('robot',
99
+ msg,
100
+ {
101
+ robot_model: @robot_model,
102
+ robot_id: @robot_id,
103
+ },
104
+ *args)
105
+ end
106
+
107
+ def forward(speed=50, time=-1)
108
+ move('forward', speed, time)
109
+ end
110
+
111
+ def backward(speed=50, time=-1)
112
+ move('backward', speed, time)
113
+ end
114
+
115
+ def turnLeft(speed=50, time=-1)
116
+ move('turnLeft', speed, time)
117
+ end
118
+
119
+ def turnRight(speed=50, time=-1)
120
+ move('turnRight', speed, time)
121
+ end
122
+
123
+ def stop()
124
+ send_ws_msg 'stop'
125
+ end
126
+
127
+ def ping()
128
+ send_ws_msg 'ping'
129
+ end
130
+
131
+ def getObstacle()
132
+ send_ws_msg 'getObstacle'
133
+ end
134
+
135
+ def getLine()
136
+ send_ws_msg 'getLine'
137
+ end
138
+
139
+ private
140
+ def move(direction, speed=50, time=-1)
141
+ timed(time, self, :stop) do
142
+ send_ws_msg(direction, speed)
143
+ end
144
+ end
145
+
146
+ def timed(time, instance, method)
147
+ yield
148
+ if time >= 0
149
+ sleep time
150
+ instance.send method
151
+ end
152
+ end
153
+ end
154
+
155
+ def self.main
156
+ puts 'api_key:'
157
+ server = XRemoteBot::Server.new('xremotebot.example',
158
+ 8000,
159
+ 'api',
160
+ gets.strip)
161
+ print "Robots #{server.get_robots}\n"
162
+ robot = Robot.new server, server.fetch_robot
163
+ robot.forward 100, 1
164
+ robot.turnRight 100, 1
165
+ p robot.getLine
166
+ p robot.getObstacle
167
+ end
168
+ end
169
+
170
+ if __FILE__ == $0
171
+ XRemoteBot.main
172
+ end
@@ -0,0 +1,3 @@
1
+ module XRemoteBot
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xremotebot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xremotebot"
8
+ spec.version = XRemoteBot::VERSION
9
+ spec.authors = ["'Fernando López'"]
10
+ spec.email = ["'soportelihuen@linti.unlp.edu.ar'"]
11
+
12
+ spec.summary = %q{Ruby client for XRemoteBot}
13
+ spec.description = %q{Ruby client to control robots through the XRemoteBot server.}
14
+ spec.homepage = "https://github.com/fernandolopez/xremotebot-clients"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.licenses = ["MIT"]
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "websocket", "~> 1.2"
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry", "~> 0.10"
26
+ spec.add_development_dependency "rb-readline", "~> 0.5"
27
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xremotebot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Fernando López'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: websocket
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rb-readline
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ description: Ruby client to control robots through the XRemoteBot server.
84
+ email:
85
+ - "'soportelihuen@linti.unlp.edu.ar'"
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/xremotebot.rb
99
+ - lib/xremotebot/version.rb
100
+ - xremotebot.gemspec
101
+ homepage: https://github.com/fernandolopez/xremotebot-clients
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.5
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Ruby client for XRemoteBot
125
+ test_files: []