msr 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: db0608761faf290f7fb9eceac6be19f584a8b050
4
- data.tar.gz: 91a207db5a02beba3ebfa044e5bc10a2e22f34f8
3
+ metadata.gz: 81af545812e6fab9ed1c61e8b69d1e82b961b068
4
+ data.tar.gz: fcd4c2cd3216794423db08a215db459739f2a7a0
5
5
  SHA512:
6
- metadata.gz: f834b5ee6d3c3771b7d3214676b1d3e27caf3b2d66cd40a3a927d8485092eac8c5743dbc58dca2a2e5619555a8930f5aba97ae4f7917878ca907e3becda38b0a
7
- data.tar.gz: 3be025af516e630802c1916e2a40504bc4d95702e6cb6f8fbb9899edf7afa545d19603e820267ac54196732dc45a598b4ef07807606a7857fb89241f4fb994a0
6
+ metadata.gz: 4179c29875a10c5d015a27ffffc80e1297a67e829385a8de3166aa903287d2640635c26242120e9982a05447bc6a3d8adb83a5af16bc698eb1851d894265aa73
7
+ data.tar.gz: a398a654f8304bdc7ad1dec138917d9bf29fb95fcfe34b7e4c5a86a4890f533e07ae7e06101e0e193b67f461945a302fb4e9b362dee3ce2e17e928defe616a16
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --no-private --markup-provider=redcarpet --markup=markdown - README.md LICENSE
data/ext/msr/msr206.c CHANGED
@@ -4,25 +4,114 @@ VALUE cMSR_MSR206 = Qnil;
4
4
 
5
5
  static VALUE allocate(VALUE klass);
6
6
  static void deallocate_206_ctx(msr206_ctx_t *ctx);
7
+
8
+ /*
9
+ Create a new {MSR::MSR206} instance for a serial device.
10
+ @param device [String] the serial device to connect to
11
+ @raise [RuntimeError] if the device can't be opened and/or initialized
12
+ @example
13
+ msr = MSR::MSR206.new("/dev/ttyUSB0")
14
+ */
7
15
  static VALUE initialize(VALUE self, VALUE rb_string);
16
+
17
+ /*
18
+ Run a communications test between the system and the device.
19
+ @return [Symbol] `:pass` if the test succeeded, or `:fail` if it failed
20
+ */
8
21
  static VALUE comm_test(VALUE self);
22
+
23
+ /*
24
+ Run a test of the device's magnetic sensor.
25
+ @return [Symbol] `:pass` if the test succeeded, or `:fail` if it failed
26
+ @note This method is interactive.
27
+ */
9
28
  static VALUE sensor_test(VALUE self);
29
+
30
+ /*
31
+ Run a test of the device's internal RAM.
32
+ @return [Symbol] `:pass` if the test succeeded, or `:fail` if it failed
33
+ */
10
34
  static VALUE ram_test(VALUE self);
35
+
36
+
37
+ /*
38
+ Reset the device to a ready state.
39
+ @note This method pauses for 100ms.
40
+ */
11
41
  static VALUE reset(VALUE self);
42
+
43
+ /*
44
+ Get the device's current coercivity level.
45
+ @return [Symbol] `:hi` if the device is in Hi-Co mode, `:lo` if Lo-Co
46
+ @raise [RuntimeError] if the device returns a bad response
47
+ */
12
48
  static VALUE get_coercivity(VALUE self);
49
+
50
+ /*
51
+ Set the device's coercivity level.
52
+ @param coercivity [Symbol] `:hi` for Hi-Co, and `:lo` for Lo-Co
53
+ @raise [ArgumentError] if the coercivity level is unrecognized
54
+ @raise [RuntimeError] if the device returns a bad response
55
+ */
13
56
  static VALUE set_coercivity(VALUE self, VALUE co_sym);
57
+
58
+ /*
59
+ Set the bits-per-inch on the second track.
60
+ @param bpi [Fixnum] the BPI setting, either 75 or 210
61
+ @raise [RuntimeError] if the device returns a bad response
62
+ @note This only applies to the second track.
63
+ */
14
64
  static VALUE set_bpi(VALUE self, VALUE bpi);
15
- static VALUE set_bpc(VALUE self, VALUE bpc1, VALUE bpc2, VALUE bpc3);
65
+
66
+ /*
67
+ Set the bits-per-character on each track.
68
+ @param bpc_ary [Array<Fixnum>] the array of BPC values
69
+ @raise [RuntimeError] if the device returns a bad response
70
+ */
71
+ static VALUE set_bpc(VALUE self, VALUE bpc_ary);
72
+
73
+ /*
74
+ Control the LEDs on the device.
75
+ @param led [Symbol] the LED command (`:green`, `:yellow`, `:red`, `:all`,
76
+ `:none`)
77
+ @raise [ArgumentError] if the LED command is unrecognized
78
+ */
16
79
  static VALUE set_led(VALUE self, VALUE led_sym);
80
+
81
+ /*
82
+ Read raw data from a card.
83
+ @return [MSR::Tracks] a new tracks object containing the raw card data
84
+ @note This method is interactive.
85
+ */
17
86
  static VALUE raw_read(VALUE self);
87
+
88
+ /*
89
+ Read ISO-formatted data from a card.
90
+ @return [MSR::Tracks] a new tracks object containing the ISO card data
91
+ @note This method is interactive.
92
+ */
18
93
  static VALUE iso_read(VALUE self);
94
+
95
+ /*
96
+ Write raw data to a card.
97
+ @param tracks [MSR::Tracks] the raw tracks to write to the card
98
+ @note This method is interactive.
99
+ */
19
100
  static VALUE raw_write(VALUE self, VALUE tks_obj);
101
+
102
+ /*
103
+ Write ISO-formatted data to a card.
104
+ @param tracks [MSR::Tracks] the ISO tracks to write to the card
105
+ @note This method is interactive.
106
+ */
20
107
  static VALUE iso_write(VALUE self, VALUE tks_obj);
21
108
 
109
+
22
110
  void Init_msr_msr206()
23
111
  {
24
112
  cMSR_MSR206 = rb_define_class_under(mMSR, "MSR206", rb_cObject);
25
113
  rb_define_alloc_func(cMSR_MSR206, allocate);
114
+
26
115
  rb_define_method(cMSR_MSR206, "initialize", initialize, 1);
27
116
  rb_define_method(cMSR_MSR206, "comm_test!", comm_test, 0);
28
117
  rb_define_method(cMSR_MSR206, "sensor_test!", sensor_test, 0);
@@ -31,7 +120,7 @@ void Init_msr_msr206()
31
120
  rb_define_method(cMSR_MSR206, "coercivity", get_coercivity, 0);
32
121
  rb_define_method(cMSR_MSR206, "coercivity=", set_coercivity, 1);
33
122
  rb_define_method(cMSR_MSR206, "bpi=", set_bpi, 1);
34
- rb_define_method(cMSR_MSR206, "bpc=", set_bpc, 3);
123
+ rb_define_method(cMSR_MSR206, "bpc=", set_bpc, 1);
35
124
  rb_define_method(cMSR_MSR206, "led=", set_led, 1);
36
125
  rb_define_method(cMSR_MSR206, "raw_read", raw_read, 0);
37
126
  rb_define_method(cMSR_MSR206, "iso_read", iso_read, 0);
@@ -217,22 +306,26 @@ static VALUE set_bpi(VALUE self, VALUE bpi)
217
306
  return self;
218
307
  }
219
308
 
220
- static VALUE set_bpc(VALUE self, VALUE bpc1, VALUE bpc2, VALUE bpc3)
309
+ static VALUE set_bpc(VALUE self, VALUE bpc_ary)
221
310
  {
222
- uint8_t bpc_tk1, bpc_tk2, bpc_tk3;
311
+ uint8_t bpcs[3] = {0};
223
312
  msr206_ctx_t *ctx;
224
313
  int ret;
225
314
 
226
- Check_Type(bpc1, T_FIXNUM);
227
- Check_Type(bpc2, T_FIXNUM);
228
- Check_Type(bpc3, T_FIXNUM);
315
+ Check_Type(bpc_ary, T_ARRAY);
229
316
  Data_Get_Struct(self, msr206_ctx_t, ctx);
230
317
 
231
- bpc_tk1 = NUM2CHR(bpc1);
232
- bpc_tk2 = NUM2CHR(bpc2);
233
- bpc_tk3 = NUM2CHR(bpc3);
318
+ if (RARRAY_LEN(bpc_ary) != MSR_MAX_TRACKS) {
319
+ rb_raise(rb_eArgError, "Expected %d BPC values, got %ld",
320
+ MSR_MAX_TRACKS, RARRAY_LEN(bpc_ary));
321
+ }
322
+
323
+ for (int i = 0; i < MSR_MAX_TRACKS; i++) {
324
+ Check_Type(rb_ary_entry(bpc_ary, i), T_FIXNUM);
325
+ bpcs[i] = (uint8_t) NUM2CHR(rb_ary_entry(bpc_ary, i));
326
+ }
234
327
 
235
- ret = msr_set_bpc(ctx->fd, bpc_tk1, bpc_tk2, bpc_tk3);
328
+ ret = msr_set_bpc(ctx->fd, bpcs[0], bpcs[1], bpcs[2]);
236
329
 
237
330
  if (ret != LIBMSR_ERR_OK) {
238
331
  rb_raise(rb_eRuntimeError, "Couldn't change bpc (%d)", ret);
data/ext/msr/track.c CHANGED
@@ -1,8 +1,23 @@
1
1
  #include "msr.h"
2
2
 
3
+ /*
4
+ The data associated with the track.
5
+ @return [Array<Fixnum>] the track data
6
+ */
3
7
  static VALUE msr_track_data(VALUE self);
8
+
9
+ /*
10
+ The length of the track's data.
11
+ @return [Fixnum] the track length
12
+ */
4
13
  static VALUE msr_track_length(VALUE self);
5
14
 
15
+ /*
16
+ Reverse the direction of the track, returning a new object.
17
+ @return [MSR::Track] the reversed track
18
+ */
19
+ static VALUE msr_track_reverse(VALUE self);
20
+
6
21
  VALUE c_MSR_Track = Qnil;
7
22
 
8
23
  void Init_msr_track()
@@ -14,6 +29,7 @@ void Init_msr_track()
14
29
  rb_define_method(c_MSR_Track, "initialize", msr_track_initialize, 1);
15
30
  rb_define_method(c_MSR_Track, "data", msr_track_data, 0);
16
31
  rb_define_method(c_MSR_Track, "length", msr_track_length, 0);
32
+ rb_define_method(c_MSR_Track, "reverse", msr_track_reverse, 0);
17
33
  }
18
34
 
19
35
  VALUE msr_track_initialize(VALUE self, VALUE tk_data_ary)
@@ -48,3 +64,14 @@ static VALUE msr_track_length(VALUE self)
48
64
 
49
65
  return INT2NUM(RARRAY_LEN(tk_data_ary));
50
66
  }
67
+
68
+ static VALUE msr_track_reverse(VALUE self)
69
+ {
70
+ msr_track_t tk;
71
+
72
+ msr_unwrap_track(self, &tk);
73
+
74
+ msr_reverse_track(&tk);
75
+
76
+ return msr_track_new(tk);
77
+ }
data/ext/msr/tracks.c CHANGED
@@ -1,9 +1,29 @@
1
1
  #include "msr.h"
2
2
 
3
+ /*
4
+ The first track on the card.
5
+ @return [MSR::Track] the track object
6
+ */
3
7
  static VALUE msr_tracks_track1(VALUE self);
8
+
9
+ /*
10
+ The second track on the card.
11
+ @return [MSR::Track] the track object
12
+ */
4
13
  static VALUE msr_tracks_track2(VALUE self);
14
+
15
+ /*
16
+ The third track on the card.
17
+ @return [MSR::Track] the track object
18
+ */
5
19
  static VALUE msr_tracks_track3(VALUE self);
6
20
 
21
+ /*
22
+ Reverse the direction of the tracks, returning a new object.
23
+ @return [MSR::Tracks] the reversed tracks
24
+ */
25
+ static VALUE msr_tracks_reverse(VALUE self);
26
+
7
27
  VALUE c_MSR_Tracks = Qnil;
8
28
 
9
29
  void Init_msr_tracks()
@@ -14,6 +34,7 @@ void Init_msr_tracks()
14
34
  rb_define_method(c_MSR_Tracks, "track1", msr_tracks_track1, 0);
15
35
  rb_define_method(c_MSR_Tracks, "track2", msr_tracks_track2, 0);
16
36
  rb_define_method(c_MSR_Tracks, "track3", msr_tracks_track3, 0);
37
+ rb_define_method(c_MSR_Tracks, "reverse", msr_tracks_reverse, 0);
17
38
  }
18
39
 
19
40
  VALUE msr_tracks_initialize(VALUE self, VALUE tk1, VALUE tk2, VALUE tk3)
@@ -51,3 +72,14 @@ static VALUE msr_tracks_track3(VALUE self)
51
72
  {
52
73
  return rb_iv_get(self, "@track3");
53
74
  }
75
+
76
+ static VALUE msr_tracks_reverse(VALUE self)
77
+ {
78
+ msr_tracks_t tks;
79
+
80
+ msr_unwrap_tracks(self, &tks);
81
+
82
+ msr_reverse_tracks(&tks);
83
+
84
+ return msr_tracks_new(tks);
85
+ }
data/lib/msr.rb CHANGED
@@ -2,7 +2,8 @@ require_relative "../ext/msr/msr"
2
2
  require_relative "msr/track"
3
3
  require_relative "msr/tracks"
4
4
  require_relative "msr/msr206"
5
+ require_relative "msr/msr505c"
5
6
 
6
7
  module MSR
7
- VERSION = "0.0.2".freeze
8
+ VERSION = "0.0.3".freeze
8
9
  end
data/lib/msr/msr206.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module MSR
2
+ # Represents a connection to an MSR206 (or MSR206-compatible device).
2
3
  class MSR206
4
+ # Whether or not the device is currently linked.
5
+ # Corresponds to {#comm_test!} being passed.
6
+ # @return [Boolean] `true` if linked, `false` otherwise
3
7
  def linked?
4
8
  comm_test! == :pass
5
9
  end
@@ -0,0 +1,5 @@
1
+ module MSR
2
+ # Alias MSR505C to MSR206, since the two are firmware compatible.
3
+ # @see MSR206
4
+ MSR505C = MSR206
5
+ end
data/lib/msr/track.rb CHANGED
@@ -1,5 +1,19 @@
1
1
  module MSR
2
+ # Represents a single track from a magnetic stripe card.
2
3
  class Track
4
+ # Reverse the direction of the track, in place.
5
+ # @return [MSR::Tracks] the current instance
6
+ def reverse!
7
+ reversed = self.reverse
8
+
9
+ @data = reversed.data
10
+
11
+ self # return ourself, just for convenience
12
+ end
13
+
14
+ # Compare two tracks for equality. Two tracks are said to be equal if they
15
+ # contain the same data, in the same order.
16
+ # @return [Boolean] `true` if the two are equal, `false` otherwise
3
17
  def ==(o)
4
18
  return unless o.is_a?(self.class)
5
19
  data == o.data
data/lib/msr/tracks.rb CHANGED
@@ -1,5 +1,21 @@
1
1
  module MSR
2
+ # Represents (up to) three tracks from a magnetic stripe card.
2
3
  class Tracks
4
+ # Reverse the direction of the tracks, in place.
5
+ # @return [MSR::Tracks] the current instance
6
+ def reverse!
7
+ reversed = self.reverse
8
+
9
+ @track1 = reversed.track1
10
+ @track2 = reversed.track2
11
+ @track3 = reversed.track3
12
+
13
+ self # return ourself, just for convenience
14
+ end
15
+
16
+ # Compare two sets of tracks for equality. Two sets are said to be equal
17
+ # if all of their corresponding pairs are equal.
18
+ # @return [Boolean] `true` if the two are equal, `false` otherwise
3
19
  def ==(o)
4
20
  return unless o.is_a?(self.class)
5
21
  track1 == o.track1 && track2 == o.track2 && track3 == o.track3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Woodruff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-21 00:00:00.000000000 Z
11
+ date: 2016-11-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A library for controlling magnetic stripe reader/writers.
14
14
  email: william@tuffbizz.com
@@ -17,6 +17,7 @@ extensions:
17
17
  - ext/msr/extconf.rb
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".yardopts"
20
21
  - LICENSE
21
22
  - README.md
22
23
  - ext/msr/extconf.rb
@@ -27,6 +28,7 @@ files:
27
28
  - ext/msr/tracks.c
28
29
  - lib/msr.rb
29
30
  - lib/msr/msr206.rb
31
+ - lib/msr/msr505c.rb
30
32
  - lib/msr/track.rb
31
33
  - lib/msr/tracks.rb
32
34
  homepage: https://github.com/woodruffw/ruby-msr