sphero_pwn 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.travis.yml +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +25 -0
- data/Rakefile +39 -0
- data/VERSION +1 -0
- data/lib/sphero_pwn.rb +20 -0
- data/lib/sphero_pwn/async.rb +10 -0
- data/lib/sphero_pwn/asyncs.rb +34 -0
- data/lib/sphero_pwn/asyncs/l1_diagnostics.rb +21 -0
- data/lib/sphero_pwn/channel.rb +65 -0
- data/lib/sphero_pwn/channel_recorder.rb +60 -0
- data/lib/sphero_pwn/command.rb +54 -0
- data/lib/sphero_pwn/commands.rb +3 -0
- data/lib/sphero_pwn/commands/get_versions.rb +44 -0
- data/lib/sphero_pwn/commands/l1_diagnostics.rb +16 -0
- data/lib/sphero_pwn/commands/ping.rb +15 -0
- data/lib/sphero_pwn/replay_channel.rb +81 -0
- data/lib/sphero_pwn/response.rb +47 -0
- data/lib/sphero_pwn/session.rb +160 -0
- data/lib/sphero_pwn/test_channel.rb +18 -0
- data/test/channel_recorder_test.rb +102 -0
- data/test/command_test.rb +35 -0
- data/test/commands/get_versions_test.rb +34 -0
- data/test/commands/l1_diagnostics_test.rb +40 -0
- data/test/commands/ping_test.rb +25 -0
- data/test/data/get_version.txt +2 -0
- data/test/data/l1_diagnostics.txt +2 -0
- data/test/data/ping.txt +2 -0
- data/test/helper.rb +37 -0
- data/test/replay_channel_test.rb +147 -0
- data/test/response_test.rb +15 -0
- data/test/session_test.rb +15 -0
- data/test/sphero_pwn_test.rb +4 -0
- metadata +181 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative './helper.rb'
|
2
|
+
|
3
|
+
describe SpheroPwn::Command do
|
4
|
+
it 'stringifies the ping example correctly' do
|
5
|
+
ping = SpheroPwn::Command.new 0x00, 0x01, nil
|
6
|
+
sequence = 0x52
|
7
|
+
|
8
|
+
bytes = ping.to_bytes sequence
|
9
|
+
assert_equal [0xFF, 0xFF, 0x00, 0x01, 0x52, 0x01, 0xAB], bytes.unpack('C*')
|
10
|
+
assert_equal Encoding::BINARY, bytes.encoding
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'clears the response bit correctly' do
|
14
|
+
ping = SpheroPwn::Command.new 0x00, 0x01, nil
|
15
|
+
assert_equal true, ping.expects_response?
|
16
|
+
|
17
|
+
ping.no_response!
|
18
|
+
assert_equal false, ping.expects_response?
|
19
|
+
sequence = 0x52
|
20
|
+
|
21
|
+
bytes = ping.to_bytes sequence
|
22
|
+
assert_equal [0xFF, 0xFE, 0x00, 0x01, 0x52, 0x01, 0xAB], bytes.unpack('C*')
|
23
|
+
assert_equal Encoding::BINARY, bytes.encoding
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'clears the timeout bit correctly' do
|
27
|
+
ping = SpheroPwn::Command.new 0x00, 0x01, nil
|
28
|
+
ping.no_timeout_reset!
|
29
|
+
sequence = 0x52
|
30
|
+
|
31
|
+
bytes = ping.to_bytes sequence
|
32
|
+
assert_equal [0xFF, 0xFD, 0x00, 0x01, 0x52, 0x01, 0xAB], bytes.unpack('C*')
|
33
|
+
assert_equal Encoding::BINARY, bytes.encoding
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../helper.rb'
|
2
|
+
|
3
|
+
describe SpheroPwn::Commands::GetVersions do
|
4
|
+
it 'parses a v1 response record correctly' do
|
5
|
+
response = SpheroPwn::Commands::GetVersions::Response.new 0x01, 0x00,
|
6
|
+
[0x02, 0x03, 0x01, 0xaa, 0xbb, 0x51, 0x67, 0x89]
|
7
|
+
|
8
|
+
assert_equal 3, response.versions[:model]
|
9
|
+
assert_equal 1, response.versions[:hardware]
|
10
|
+
assert_equal({ version: 0xaa, revision: 0xbb },
|
11
|
+
response.versions[:sphero_app])
|
12
|
+
assert_equal({ major: 5, minor: 1}, response.versions[:bootloader])
|
13
|
+
assert_equal({ major: 6, minor: 7}, response.versions[:basic])
|
14
|
+
assert_equal({ major: 8, minor: 9}, response.versions[:macros])
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'when sent to the robot' do
|
18
|
+
before { @session = new_test_session :get_version }
|
19
|
+
after { @session.close }
|
20
|
+
|
21
|
+
it 'receives a response with version numbers' do
|
22
|
+
@session.send_command SpheroPwn::Commands::GetVersions.new
|
23
|
+
response = @session.recv_until_response
|
24
|
+
assert_kind_of SpheroPwn::Commands::GetVersions::Response, response
|
25
|
+
|
26
|
+
assert_equal :ok, response.code
|
27
|
+
refute_nil response.versions[:model]
|
28
|
+
refute_nil response.versions[:hardware]
|
29
|
+
refute_nil response.versions[:bootloader]
|
30
|
+
refute_nil response.versions[:basic]
|
31
|
+
refute_nil response.versions[:macros]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../helper.rb'
|
2
|
+
|
3
|
+
describe SpheroPwn::Commands::L1Diagnostics do
|
4
|
+
it 'parses an async response correctly' do
|
5
|
+
async = SpheroPwn::Asyncs.create 0x02, [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0A]
|
6
|
+
|
7
|
+
assert_kind_of SpheroPwn::Asyncs::L1Diagnostics, async
|
8
|
+
assert_equal "Hello\n", async.text
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'when sent to the robot' do
|
12
|
+
before { @session = new_test_session :l1_diagnostics }
|
13
|
+
after { @session.close }
|
14
|
+
|
15
|
+
it 'receives a response and an async result' do
|
16
|
+
@session.send_command SpheroPwn::Commands::L1Diagnostics.new
|
17
|
+
|
18
|
+
response = nil
|
19
|
+
async = nil
|
20
|
+
while response.nil? || async.nil?
|
21
|
+
message = @session.recv_message
|
22
|
+
if message.nil?
|
23
|
+
sleep 0.05
|
24
|
+
next
|
25
|
+
end
|
26
|
+
|
27
|
+
if message.kind_of? SpheroPwn::Response
|
28
|
+
response = message
|
29
|
+
assert_kind_of SpheroPwn::Commands::L1Diagnostics::Response, response
|
30
|
+
assert_equal :ok, response.code
|
31
|
+
else
|
32
|
+
async = message
|
33
|
+
assert_kind_of SpheroPwn::Asyncs::L1Diagnostics, async
|
34
|
+
assert_operator async.text.length, :>=, 200
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../helper.rb'
|
2
|
+
|
3
|
+
describe SpheroPwn::Commands::Ping do
|
4
|
+
it 'stringifies the ping example correctly' do
|
5
|
+
ping = SpheroPwn::Commands::Ping.new
|
6
|
+
sequence = 0x52
|
7
|
+
|
8
|
+
bytes = ping.to_bytes sequence
|
9
|
+
assert_equal [0xFF, 0xFF, 0x00, 0x01, 0x52, 0x01, 0xAB], bytes.unpack('C*')
|
10
|
+
assert_equal Encoding::BINARY, bytes.encoding
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'when sent to the robot' do
|
14
|
+
before { @session = new_test_session :ping }
|
15
|
+
after { @session.close }
|
16
|
+
|
17
|
+
it 'receives a response' do
|
18
|
+
@session.send_command SpheroPwn::Commands::Ping.new
|
19
|
+
response = @session.recv_until_response
|
20
|
+
|
21
|
+
assert_kind_of SpheroPwn::Commands::Ping::Response, response
|
22
|
+
assert_equal :ok, response.code
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,2 @@
|
|
1
|
+
> FF FF 00 40 01 01 BD
|
2
|
+
< FF FF 00 01 01 FD FF FE 02 05 E5 5B 53 79 73 74 65 6D 5D 0A 4D 6F 64 65 20 4E 2C 20 4C 61 73 74 20 62 6F 6F 74 20 43 4F 4C 44 0A 0A 33 38 20 72 65 63 68 72 67 2C 20 37 20 6D 69 6E 20 73 69 6E 63 65 20 6C 61 73 74 2C 20 35 3A 32 37 20 61 6C 69 76 65 0A 43 6F 6C 64 3A 33 35 2C 20 57 61 72 6D 3A 31 2C 20 57 61 6B 65 75 70 3A 30 2C 20 46 61 75 6C 74 3A 30 0A 44 69 73 74 20 72 6F 6C 6C 65 64 3A 20 31 39 38 34 20 6D 65 74 65 72 73 0A 56 62 61 74 74 20 38 2E 30 35 2C 20 73 74 61 74 65 3A 20 4F 4B 0A 53 65 6E 73 6F 72 73 48 74 68 79 3A 31 2C 20 42 54 45 72 72 6F 72 3A 31 2C 20 41 75 74 68 4F 4B 3A 31 2C 20 53 74 61 62 69 6C 69 7A 65 3A 31 2C 20 54 65 73 74 50 69 6E 3A 30 2C 20 4D 61 63 72 6F 3A 30 2C 20 6F 72 62 42 61 73 69 63 3A 4E 20 28 30 29 0A 42 6F 6F 74 6C 64 72 3D 33 2E 33 2C 20 4D 41 3D 33 2E 37 33 2C 20 42 6F 61 72 64 3D 31 2C 20 6F 72 62 42 61 73 69 63 3D 31 2E 39 0A 4D 61 63 45 78 65 63 3D 36 2C 20 43 42 3D 32 31 37 2C 20 43 68 61 73 73 69 73 20 49 44 3D 35 0A 0A 42 75 69 6C 74 3A 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 42 54 3A 20 30 38 4A 75 6C 32 30 31 35 20 20 0A 41 75 74 6F 52 65 63 6F 6E 20 45 6E 3D 31 20 41 75 74 6F 52 65 63 6F 6E 44 65 6C 3D 30 0A 43 6C 69 65 6E 74 54 69 6D 65 4F 75 74 3D 36 30 30 20 57 61 6B 65 55 70 53 65 63 3D 30 0A 50 65 72 6D 20 4F 70 74 69 6F 6E 20 46 6C 61 67 73 3D 30 78 30 30 30 30 30 30 31 32 2C 20 54 65 6D 70 3D 30 78 30 30 30 30 30 30 30 30 0A 0A 5B 4E 65 74 77 6F 72 6B 5D 0A 47 6F 6F 64 20 52 78 3A 31 31 38 37 31 33 2C 20 54 78 3A 39 34 38 38 0A 42 61 64 20 44 49 44 3A 31 30 2C 20 43 49 44 3A 32 34 2C 20 4C 45 4E 3A 30 2C 20 43 48 4B 3A 30 0A 4F 76 65 72 72 75 6E 73 20 52 78 3A 34 2C 20 54 78 3A 30 0A 44 65 76 20 6E 61 6D 65 3A 70 77 6E 61 6C 6C 2C 20 42 54 41 3A 36 38 38 36 65 37 30 36 31 32 33 34 0A 42 54 76 65 72 3A 42 75 69 6C 64 20 31 33 30 38 31 32 41 20 49 44 50 53 0A 0A 5B 53 65 6E 73 6F 72 73 5D 0A 46 61 69 6C 3A 20 30 20 4C 6F 63 3A 20 30 20 43 6F 64 65 3A 20 30 20 52 65 63 3A 20 30 0A 0A 5B 41 63 63 65 6C 20 78 31 30 30 30 5D 0A 6D 31 31 3D 33 2E 39 33 34 39 20 6D 31 32 3D 30 2E 30 34 37 32 20 6D 31 33 3D 2D 30 2E 30 32 33 38 0A 6D 32 31 3D 2D 30 2E 30 37 33 33 20 6D 32 32 3D 33 2E 39 34 31 30 20 6D 32 33 3D 30 2E 30 31 32 33 0A 6D 33 31 3D 2D 30 2E 30 37 31 31 20 6D 33 32 3D 30 2E 30 31 32 36 20 6D 33 33 3D 33 2E 39 34 33 36 0A 58 62 3D 30 2E 30 31 38 38 20 59 62 3D 2D 30 2E 30 30 37 30 20 5A 62 3D 2D 30 2E 30 34 34 32 0A 52 61 6E 67 65 3D 38 47 0A 0A 5B 47 79 72 6F 5D 0A 42 30 20 58 20 43 57 3A 4C 3D 2D 31 39 36 37 20 53 3D 30 2E 30 36 31 30 20 43 43 57 3A 4C 3D 31 39 36 36 20 53 3D 30 2E 30 36 31 30 0A 42 30 20 59 20 43 57 3A 4C 3D 2D 31 39 35 38 20 53 3D 30 2E 30 36 31 33 20 43 43 57 3A 4C 3D 31 39 35 38 20 53 3D 30 2E 30 36 31 33 0A 42 30 20 5A 20 43 57 3A 4C 3D 2D 31 39 35 35 20 53 3D 30 2E 30 36 31 34 20 43 43 57 3A 4C 3D 31 39 35 34 20 53 3D 30 2E 30 36 31 34 0A 42 31 20 58 20 43 57 3A 4C 3D 2D 33 32 37 36 38 20 53 3D 30 2E 30 36 31 30 20 43 43 57 3A 4C 3D 33 32 37 36 37 20 53 3D 30 2E 30 36 31 30 0A 42 31 20 59 20 43 57 3A 4C 3D 2D 33 32 37 36 38 20 53 3D 30 2E 30 36 31 30 20 43 43 57 3A 4C 3D 33 32 37 36 37 20 53 3D 30 2E 30 36 31 30 0A 42 31 20 5A 20 43 57 3A 4C 3D 2D 33 32 37 36 38 20 53 3D 30 2E 30 36 31 30 20 43 43 57 3A 4C 3D 33 32 37 36 37 20 53 3D 30 2E 30 36 31 30 0A 58 47 62 3D 2D 32 2E 37 32 34 34 20 59 47 62 3D 30 2E 32 30 36 37 20 5A 47 62 3D 30 2E 34 31 32 37 0A 47 79 72 6F 41 64 6A 43 6E 74 3D 32 31 31 32 20 41 63 74 69 76 65 3D 79 65 73 0A 4D 61 78 20 67 79 72 6F 20 58 3D 39 37 20 59 3D 32 35 34 20 5A 3D 34 37 0A 4D 69 6E 20 67 79 72 6F 20 58 3D 2D 32 32 34 20 59 3D 2D 32 34 39 20 5A 3D 2D 31 36 0A 52 65 61 6C 74 69 6D 65 20 4F 76 65 72 66 6C 6F 77 3D 33 20 4D 61 78 54 3D 30 2E 30 30 33 37 33 36 0A 0A 5B 43 6F 6E 74 72 6F 6C 5D 0A 50 69 74 63 68 20 50 3D 32 30 2E 30 30 30 20 49 3D 30 2E 32 30 30 20 44 3D 31 35 30 2E 30 30 30 0A 52 6F 6C 6C 20 50 3D 32 31 2E 30 30 30 20 49 3D 30 2E 33 30 30 20 44 3D 35 30 2E 30 30 30 0A 59 61 77 20 50 3D 39 30 2E 30 30 30 20 49 3D 30 2E 30 35 30 20 44 3D 31 32 30 30 2E 30 30 30 0A 52 6F 74 52 61 74 65 3D 32 34 30 20 46 61 73 74 52 6F 74 52 61 74 65 3D 31 30 30 30 20 64 70 73 0A 0A 5B 54 65 73 74 20 52 65 73 5D 0A 50 43 42 41 74 72 3D 30 78 37 66 66 20 53 74 6E 3D 32 0A 41 47 74 72 3D 30 78 33 20 53 74 6E 3D 31 0A 0A 5B 49 64 6C 65 20 6C 6F 6F 70 5D 0A 4D 69 6E 43 6C 6B 73 3A 33 32 39 20 4D 61 78 43 6C 6B 73 3A 36 30 33 36 39 20 4D 69 6E 46 72 65 71 3A 31 32 37 39 34 37 20 4D 61 78 46 72 65 71 3A 32 38 34 38 31 37 0A 43 50 55 20 36 35 25 20 69 64 6C 65 0A 69
|
data/test/data/ping.txt
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'minitest/autorun'
|
11
|
+
require 'minitest/unit'
|
12
|
+
require 'minitest/spec'
|
13
|
+
require 'mocha/mini_test'
|
14
|
+
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
17
|
+
require 'sphero_pwn'
|
18
|
+
|
19
|
+
class MiniTest::Test
|
20
|
+
# Creates a test channel that records to a file inside the data directory.
|
21
|
+
#
|
22
|
+
# The caller is responsible for closing the channel at the end of the test.
|
23
|
+
#
|
24
|
+
# @param {Symbol} test_case_name used to derive the path to the recording
|
25
|
+
# file
|
26
|
+
# @return {SpheroPwn::Session} a session whose backing channel records to /
|
27
|
+
# replays from the recording file for the given test case
|
28
|
+
def new_test_session(test_case_name)
|
29
|
+
rfconn_path = ENV['SPHERO_DEV']
|
30
|
+
recording_path = File.join File.dirname(__FILE__), 'data',
|
31
|
+
"#{test_case_name}.txt"
|
32
|
+
channel = SpheroPwn.new_test_channel rfconn_path, recording_path
|
33
|
+
SpheroPwn::Session.new channel
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
MiniTest.autorun
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require_relative './helper.rb'
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
describe SpheroPwn::ReplayChannel do
|
6
|
+
describe 'with one send operation' do
|
7
|
+
let :replay do
|
8
|
+
input = StringIO.new "> 48 65 6c 6c 6f 0a\n"
|
9
|
+
File.stub :open, input do
|
10
|
+
SpheroPwn::ReplayChannel.new '/tmp/stubbed'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns self when data is sent correctly' do
|
15
|
+
assert_equal replay, replay.send_bytes("Hello\n")
|
16
|
+
assert_equal replay, replay.close
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'compares sent data against recording' do
|
20
|
+
exception = assert_raises ArgumentError do
|
21
|
+
replay.send_bytes "Hwlo"
|
22
|
+
end
|
23
|
+
|
24
|
+
golden_error = 'Incorrect bytes sent! ' +
|
25
|
+
'Expected: [72, 101, 108, 108, 111, 10] Got: [72, 119, 108, 111]'
|
26
|
+
assert_equal golden_error, exception.message
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'complains if closed early' do
|
30
|
+
exception = assert_raises RuntimeError do
|
31
|
+
replay.close
|
32
|
+
end
|
33
|
+
assert_equal 'Closed before performing 1 operations!', exception.message
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'complains if attempting to receive' do
|
37
|
+
exception = assert_raises RuntimeError do
|
38
|
+
replay.recv_bytes 1
|
39
|
+
end
|
40
|
+
assert_equal 'Received data at an unexpected time!', exception.message
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'with one receive operation' do
|
45
|
+
let :replay do
|
46
|
+
input = StringIO.new "< 48 65 6c 6c 6f 20 74 6f 6f 21 0a\n"
|
47
|
+
File.stub :open, input do
|
48
|
+
SpheroPwn::ReplayChannel.new '/tmp/stubbed'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'receives correctly in one shot' do
|
53
|
+
assert_equal "Hello too!\n", replay.recv_bytes(11)
|
54
|
+
assert_equal replay, replay.close
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'receives correctly in two shots' do
|
58
|
+
assert_equal 'Hello', replay.recv_bytes(5)
|
59
|
+
assert_equal " too!\n", replay.recv_bytes(6)
|
60
|
+
assert_equal replay, replay.close
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'receives correctly in three shots' do
|
64
|
+
assert_equal 'Hello', replay.recv_bytes(5)
|
65
|
+
assert_equal ' ', replay.recv_bytes(1)
|
66
|
+
assert_equal "too!\n", replay.recv_bytes(5)
|
67
|
+
assert_equal replay, replay.close
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'complains if closed early' do
|
71
|
+
exception = assert_raises RuntimeError do
|
72
|
+
replay.close
|
73
|
+
end
|
74
|
+
assert_equal 'Closed before performing 1 operations!', exception.message
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'complains if attempting to send before receiving anything' do
|
78
|
+
exception = assert_raises RuntimeError do
|
79
|
+
replay.send_bytes "Hello"
|
80
|
+
end
|
81
|
+
assert_equal 'Sent data before receiving 11 of 11 bytes!',
|
82
|
+
exception.message
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'complains if attempting to send before receiving everything' do
|
86
|
+
assert_equal 'Hello', replay.recv_bytes(5)
|
87
|
+
exception = assert_raises RuntimeError do
|
88
|
+
replay.send_bytes "Hello"
|
89
|
+
end
|
90
|
+
assert_equal 'Sent data before receiving 6 of 11 bytes!',
|
91
|
+
exception.message
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'with no operation' do
|
96
|
+
let :replay do
|
97
|
+
input = StringIO.new ''
|
98
|
+
File.stub :open, input do
|
99
|
+
SpheroPwn::ReplayChannel.new '/tmp/stubbed'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'closes correctly' do
|
104
|
+
assert_equal replay, replay.close
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'complaints if attempting to send' do
|
108
|
+
exception = assert_raises RuntimeError do
|
109
|
+
replay.send_bytes "Hello\n"
|
110
|
+
end
|
111
|
+
assert_equal 'Sent data at an unexpected time!', exception.message
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'complains if attempting to receive' do
|
115
|
+
exception = assert_raises RuntimeError do
|
116
|
+
replay.recv_bytes 1
|
117
|
+
end
|
118
|
+
assert_equal 'Received data at an unexpected time!', exception.message
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'with a sequence of operations' do
|
123
|
+
let :replay do
|
124
|
+
input = StringIO.new <<END_STRING
|
125
|
+
> 48 65 6c 6c 6f 0a
|
126
|
+
< 48 65 6c 6c 6f 20 74 6f 6f 21 0a
|
127
|
+
> 4f 4b
|
128
|
+
> 42 79 65 0a
|
129
|
+
< 42 79 65 20 62 79 65 0a
|
130
|
+
END_STRING
|
131
|
+
File.stub :open, input do
|
132
|
+
SpheroPwn::ReplayChannel.new '/tmp/stubbed'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'replays the operations correctly' do
|
137
|
+
assert_equal replay, replay.send_bytes("Hello\n")
|
138
|
+
assert_equal 'Hello', replay.recv_bytes(5)
|
139
|
+
assert_equal " too!\n", replay.recv_bytes(6)
|
140
|
+
assert_equal replay, replay.send_bytes('OK')
|
141
|
+
assert_equal replay, replay.send_bytes("Bye\n")
|
142
|
+
assert_equal 'Bye', replay.recv_bytes(3)
|
143
|
+
assert_equal " bye\n", replay.recv_bytes(5)
|
144
|
+
assert_equal replay, replay.close
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './helper.rb'
|
2
|
+
|
3
|
+
describe SpheroPwn::Response do
|
4
|
+
it 'saves constructor args correctly' do
|
5
|
+
response = SpheroPwn::Response.new 0x00, 0x52, [0xAA, 0xBB]
|
6
|
+
assert_equal :ok, response.code
|
7
|
+
assert_equal 0x52, response.sequence
|
8
|
+
assert_equal [0xAA, 0xBB], response.data_bytes
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'handles unknown response codes correctly' do
|
12
|
+
response = SpheroPwn::Response.new 0xFA, 0x52, [0xAA, 0xBB]
|
13
|
+
assert_equal :unknown, response.code
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative './helper.rb'
|
2
|
+
|
3
|
+
describe SpheroPwn::Session do
|
4
|
+
describe '#valid_checksum?' do
|
5
|
+
it 'works on a correct example without data' do
|
6
|
+
assert_equal true, SpheroPwn::Session.valid_checksum?([0x00, 0x01, 0x01],
|
7
|
+
[], 0xfd)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'fails an incorrect example without data' do
|
11
|
+
assert_equal false, SpheroPwn::Session.valid_checksum?(
|
12
|
+
[0x00, 0x01, 0x01], [], 0xfa)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sphero_pwn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Costan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyserial
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.4
|
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.3.5
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jeweler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.8.3
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.8.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.8.7.6
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.8.7.6
|
111
|
+
description: |-
|
112
|
+
This library is currently focused on reverse-engineering
|
113
|
+
the undocumented parts of Sphero
|
114
|
+
email: victor@costan.us
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.markdown
|
120
|
+
files:
|
121
|
+
- ".document"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.markdown
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- lib/sphero_pwn.rb
|
130
|
+
- lib/sphero_pwn/async.rb
|
131
|
+
- lib/sphero_pwn/asyncs.rb
|
132
|
+
- lib/sphero_pwn/asyncs/l1_diagnostics.rb
|
133
|
+
- lib/sphero_pwn/channel.rb
|
134
|
+
- lib/sphero_pwn/channel_recorder.rb
|
135
|
+
- lib/sphero_pwn/command.rb
|
136
|
+
- lib/sphero_pwn/commands.rb
|
137
|
+
- lib/sphero_pwn/commands/get_versions.rb
|
138
|
+
- lib/sphero_pwn/commands/l1_diagnostics.rb
|
139
|
+
- lib/sphero_pwn/commands/ping.rb
|
140
|
+
- lib/sphero_pwn/replay_channel.rb
|
141
|
+
- lib/sphero_pwn/response.rb
|
142
|
+
- lib/sphero_pwn/session.rb
|
143
|
+
- lib/sphero_pwn/test_channel.rb
|
144
|
+
- test/channel_recorder_test.rb
|
145
|
+
- test/command_test.rb
|
146
|
+
- test/commands/get_versions_test.rb
|
147
|
+
- test/commands/l1_diagnostics_test.rb
|
148
|
+
- test/commands/ping_test.rb
|
149
|
+
- test/data/get_version.txt
|
150
|
+
- test/data/l1_diagnostics.txt
|
151
|
+
- test/data/ping.txt
|
152
|
+
- test/helper.rb
|
153
|
+
- test/replay_channel_test.rb
|
154
|
+
- test/response_test.rb
|
155
|
+
- test/session_test.rb
|
156
|
+
- test/sphero_pwn_test.rb
|
157
|
+
homepage: http://github.com/pwnall/sphero_pwn
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.4.5.1
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Wrapper for Sphero's bluetooth protocol
|
181
|
+
test_files: []
|