rbuspirate 0.1.2 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/rbuspirate.rb +11 -0
- data/lib/rbuspirate/commands.rb +10 -0
- data/lib/rbuspirate/interfaces/1wire.rb +50 -0
- data/lib/rbuspirate/interfaces/abstract.rb +4 -0
- data/lib/rbuspirate/responses.rb +4 -0
- data/lib/rbuspirate/timeouts.rb +8 -0
- data/lib/rbuspirate/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b41cd3f0836279a307505163fc2689965c89f1da8a9e526388b805727e85b41
|
4
|
+
data.tar.gz: 9f8f4bd005c80e96776d0527b1a5f521fa1a639b095585551812f9f48da4d11d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206e7ca0c8075ef15f23ec0bb0b8e0d772d4173eb9abaec99388e2de095ed2cbc72d48e745e62c257898a94b541a910723f4005c8e4de8f200c63a14cabc2d0b
|
7
|
+
data.tar.gz: 62672ed1d3ffc5168f38d70796cae79d6120a732507076ad16567c211620ba34404834a42cc8d3d3fb3f187a7daafa74cee4cabb1461ef8f1ae0c77df7194efe
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/rbuspirate.rb
CHANGED
@@ -7,6 +7,7 @@ require 'rbuspirate/timeouts'
|
|
7
7
|
require 'rbuspirate/interfaces/abstract'
|
8
8
|
require 'rbuspirate/interfaces/i2c'
|
9
9
|
require 'rbuspirate/interfaces/uart'
|
10
|
+
require 'rbuspirate/interfaces/1wire'
|
10
11
|
|
11
12
|
module Rbuspirate
|
12
13
|
class Client
|
@@ -67,6 +68,16 @@ module Rbuspirate
|
|
67
68
|
)
|
68
69
|
end
|
69
70
|
|
71
|
+
def enter_1wire
|
72
|
+
raise 'Device needs reset to change mode' if @needs_reset
|
73
|
+
|
74
|
+
switch_mode(
|
75
|
+
:'1wire', Commands::LE1WIRE::ENTER,
|
76
|
+
Timeouts::LE1WIRE::ENTER, Responses::LE1WIRE::ENTER,
|
77
|
+
Interfaces::LE1WIRE
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
70
81
|
private
|
71
82
|
|
72
83
|
def switch_mode(
|
data/lib/rbuspirate/commands.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Rbuspirate
|
5
|
+
module Interfaces
|
6
|
+
class LE1WIRE < Abstract
|
7
|
+
def initialize(serial, bup)
|
8
|
+
raise 'Bus pirate must be in 1wire mode' unless bup.mode == :'1wire'
|
9
|
+
@le_port = serial
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset
|
13
|
+
simplex_command(
|
14
|
+
Commands::LE1WIRE::RESET,
|
15
|
+
Timeouts::LE1WIRE::RESET,
|
16
|
+
'Unable to reset external device (comm timeout/no device)'
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def write(data, write_slice_timeout: Timeouts::LE1WIRE::WRITE)
|
21
|
+
!(data.is_a?(String) && !data.empty?) &&
|
22
|
+
raise(ArgumentError, 'data must be non empty String instance')
|
23
|
+
|
24
|
+
data = StringIO.new(data)
|
25
|
+
while (slice = data.read(16))
|
26
|
+
command = Commands::LE1WIRE::IO::WRITE | slice.bytesize - 1
|
27
|
+
simplex_command(
|
28
|
+
command, write_slice_timeout, 'Prepare slice write timeout'
|
29
|
+
)
|
30
|
+
@le_port.write(slice)
|
31
|
+
res = @le_port.expect(Responses::SUCCESS, write_slice_timeout)
|
32
|
+
raise 'Write timeout' unless res
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def read(bytes = 1, readbyte_timeout: Timeouts::LE1WIRE::READ)
|
38
|
+
result = ''.dup.b
|
39
|
+
bytes.times do
|
40
|
+
@le_port.write(Commands::LE1WIRE::IO::READ.chr)
|
41
|
+
Timeout.timeout(readbyte_timeout) do
|
42
|
+
result << @le_port.read(1)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# Encoding: binary
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
1
4
|
module Rbuspirate
|
2
5
|
module Interfaces
|
3
6
|
class Abstract
|
@@ -25,6 +28,7 @@ module Rbuspirate
|
|
25
28
|
protected
|
26
29
|
|
27
30
|
def simplex_command(command, tout, ex_message)
|
31
|
+
command = command.chr if command.instance_of?(Integer)
|
28
32
|
@le_port.write(command.chr)
|
29
33
|
resp = @le_port.expect(Responses::SUCCESS, tout)
|
30
34
|
return true if resp
|
data/lib/rbuspirate/responses.rb
CHANGED
data/lib/rbuspirate/timeouts.rb
CHANGED
data/lib/rbuspirate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbuspirate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sh7d
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/rbuspirate.rb
|
86
86
|
- lib/rbuspirate/commands.rb
|
87
87
|
- lib/rbuspirate/helpers.rb
|
88
|
+
- lib/rbuspirate/interfaces/1wire.rb
|
88
89
|
- lib/rbuspirate/interfaces/abstract.rb
|
89
90
|
- lib/rbuspirate/interfaces/i2c.rb
|
90
91
|
- lib/rbuspirate/interfaces/uart.rb
|