rbuspirate 0.1.2 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4ff50218ea5120cf13b9bdb2023de3ab94c6130f4bf574d00cbb42509bfb133
4
- data.tar.gz: 7f9de8009ee5136201f82eb6a07c7b68d2a68f039519f2b2776ca25a74a58184
3
+ metadata.gz: 0b41cd3f0836279a307505163fc2689965c89f1da8a9e526388b805727e85b41
4
+ data.tar.gz: 9f8f4bd005c80e96776d0527b1a5f521fa1a639b095585551812f9f48da4d11d
5
5
  SHA512:
6
- metadata.gz: f66a9ea057a856b01ef13e8a91b982869f479308e488ea29df1f6a562987514aa5ef99e0740fa78a4a9610cab2b07164764baf8fdee263fd3c047cc8ccd18147
7
- data.tar.gz: 34850f9a893ccc19b098bd2551425e36eb1d735636ecfd8617b374263c73da21385e856a256f86a07000b657f51f8b36349ff0d7e8fe560f944b77879e82bc0d
6
+ metadata.gz: 206e7ca0c8075ef15f23ec0bb0b8e0d772d4173eb9abaec99388e2de095ed2cbc72d48e745e62c257898a94b541a910723f4005c8e4de8f200c63a14cabc2d0b
7
+ data.tar.gz: 62672ed1d3ffc5168f38d70796cae79d6120a732507076ad16567c211620ba34404834a42cc8d3d3fb3f187a7daafa74cee4cabb1461ef8f1ae0c77df7194efe
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbuspirate (0.1.2)
4
+ rbuspirate (0.2.2)
5
5
  serialport (~> 1.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -25,6 +25,7 @@ See examples/ dir
25
25
 
26
26
  I2C: Full support
27
27
  UART: Basic support (only bridge mode, no custom speed)
28
+ 1WIRE: Full support
28
29
  Windows not supported, contributions are welcomed
29
30
 
30
31
  ## Development
@@ -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(
@@ -15,6 +15,16 @@ module Rbuspirate
15
15
  end
16
16
  end
17
17
 
18
+ module LE1WIRE
19
+ ENTER = 0b00000100
20
+ RESET = 0b00000010
21
+
22
+ module IO
23
+ READ = 0b00000100
24
+ WRITE = 0b00010000
25
+ end
26
+ end
27
+
18
28
  module I2C
19
29
  ENTER = 0b00000010
20
30
  PREPARE_WRITE = 0b00010000
@@ -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
@@ -6,6 +6,10 @@ module Rbuspirate
6
6
  BITBANG_MODE = 'BBIO1'
7
7
  SUCCESS = 0x01.chr
8
8
 
9
+ module LE1WIRE
10
+ ENTER = '1W01'
11
+ end
12
+
9
13
  module I2C
10
14
  ENTER = 'I2C1'
11
15
  end
@@ -5,6 +5,14 @@ module Rbuspirate
5
5
  module Timeouts
6
6
  BINARY_RESET = 0.05
7
7
  SUCCESS = 0.1
8
+
9
+ module LE1WIRE
10
+ ENTER = 0.2
11
+ RESET = 0.5
12
+ WRITE = 1
13
+ READ = 1
14
+ end
15
+
8
16
  module I2C
9
17
  ENTER = 0.2
10
18
  STARTSTOP = 0.5
@@ -1,3 +1,3 @@
1
1
  module Rbuspirate
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.2'
3
3
  end
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.1.2
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-01-27 00:00:00.000000000 Z
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