msr 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -3
- data/ext/msr/msr206.c +50 -2
- data/ext/msr/tracks.c +2 -0
- data/lib/msr.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23d6988a2d59a42e9eb5c923d392e59d1ae186ef
|
4
|
+
data.tar.gz: 52d9c1e5eb38d71a7bae4a114cad60e053989de6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2d87225574756678fc7b19f4deb5fe8babb5941b0160caec2b6ee3dbacc65f5e9205e1db8090ab16fa0eb597b897fa8c89af415a396311af4bb94068b5b8500
|
7
|
+
data.tar.gz: e0e3ac7659268b2c6e82c904b7854ab91f5b2941b92089aea468fed7fbca844b657ed3b38d3205cb2c4dfaf4924f099fad8d65b23b9680ac1fcab9876ce6ee1b
|
data/README.md
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
msr
|
2
2
|
===
|
3
3
|
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/msr.svg)](https://badge.fury.io/rb/msr)
|
5
|
+
|
4
6
|
A ruby gem for controlling magnetic stripe reader-writers (on UNIX/UNIX-likes).
|
5
7
|
|
6
8
|
Uses [libmsr](https://github.com/woodruffw/libmsr).
|
7
9
|
|
8
|
-
##
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install msr # make sure you have libmsr and ruby development headers
|
14
|
+
```
|
15
|
+
|
16
|
+
## Example
|
17
|
+
|
18
|
+
Full documentation is
|
19
|
+
[available on RubyDoc](http://www.rubydoc.info/gems/msr/).
|
9
20
|
|
10
21
|
```ruby
|
11
22
|
require 'msr'
|
@@ -15,12 +26,21 @@ msr = MSR::MSR505C.new("/dev/ttyS0") # or your serial device
|
|
15
26
|
puts "OK" if msr.linked?
|
16
27
|
|
17
28
|
# control an LED on the reader
|
18
|
-
msr.led
|
29
|
+
msr.led = :all # :green, :yellow, :red, :all, :none
|
19
30
|
|
20
31
|
# get and set coercivity
|
21
32
|
msr.coercivity # => :high, :low
|
22
33
|
msr.coercivity = :high # :low
|
23
34
|
|
24
|
-
#
|
35
|
+
tracks = msr.raw_read # => MSR::Tracks
|
36
|
+
|
37
|
+
tracks.reverse!
|
38
|
+
|
39
|
+
msr.raw_write tracks
|
25
40
|
```
|
26
41
|
|
42
|
+
## License
|
43
|
+
|
44
|
+
`ruby-msr` is licensed under the MIT License.
|
45
|
+
|
46
|
+
For the exact terms, see the [license](./LICENSE) file.
|
data/ext/msr/msr206.c
CHANGED
@@ -33,13 +33,26 @@ static VALUE sensor_test(VALUE self);
|
|
33
33
|
*/
|
34
34
|
static VALUE ram_test(VALUE self);
|
35
35
|
|
36
|
-
|
37
36
|
/*
|
38
37
|
Reset the device to a ready state.
|
39
38
|
@note This method pauses for 100ms.
|
40
39
|
*/
|
41
40
|
static VALUE reset(VALUE self);
|
42
41
|
|
42
|
+
/*
|
43
|
+
Get the device's firmware version.
|
44
|
+
@return [String] the firmware version, in "REV?X.XX" format
|
45
|
+
@raise [RuntimeError] if the device returns a bad response
|
46
|
+
*/
|
47
|
+
static VALUE firmware(VALUE self);
|
48
|
+
|
49
|
+
/*
|
50
|
+
Get the device's model.
|
51
|
+
@return [String] the model, in "MSR-206-?" format
|
52
|
+
@raise [RuntimeError] if the device returns a bad response
|
53
|
+
*/
|
54
|
+
static VALUE model(VALUE self);
|
55
|
+
|
43
56
|
/*
|
44
57
|
Get the device's current coercivity level.
|
45
58
|
@return [Symbol] `:hi` if the device is in Hi-Co mode, `:lo` if Lo-Co
|
@@ -106,7 +119,6 @@ static VALUE raw_write(VALUE self, VALUE tks_obj);
|
|
106
119
|
*/
|
107
120
|
static VALUE iso_write(VALUE self, VALUE tks_obj);
|
108
121
|
|
109
|
-
|
110
122
|
void Init_msr_msr206()
|
111
123
|
{
|
112
124
|
cMSR_MSR206 = rb_define_class_under(mMSR, "MSR206", rb_cObject);
|
@@ -117,6 +129,8 @@ void Init_msr_msr206()
|
|
117
129
|
rb_define_method(cMSR_MSR206, "sensor_test!", sensor_test, 0);
|
118
130
|
rb_define_method(cMSR_MSR206, "ram_test!", ram_test, 0);
|
119
131
|
rb_define_method(cMSR_MSR206, "reset!", reset, 0);
|
132
|
+
rb_define_method(cMSR_MSR206, "firmware", firmware, 0);
|
133
|
+
rb_define_method(cMSR_MSR206, "model", model, 0);
|
120
134
|
rb_define_method(cMSR_MSR206, "coercivity", get_coercivity, 0);
|
121
135
|
rb_define_method(cMSR_MSR206, "coercivity=", set_coercivity, 1);
|
122
136
|
rb_define_method(cMSR_MSR206, "bpi=", set_bpi, 1);
|
@@ -237,6 +251,40 @@ static VALUE reset(VALUE self)
|
|
237
251
|
return self;
|
238
252
|
}
|
239
253
|
|
254
|
+
static VALUE firmware(VALUE self)
|
255
|
+
{
|
256
|
+
msr206_ctx_t *ctx;
|
257
|
+
uint8_t buf[9];
|
258
|
+
int ret;
|
259
|
+
|
260
|
+
Data_Get_Struct(self, msr206_ctx_t, ctx);
|
261
|
+
|
262
|
+
ret = msr_fwrev(ctx->fd, buf);
|
263
|
+
|
264
|
+
if (ret != LIBMSR_ERR_OK) {
|
265
|
+
rb_raise(rb_eRuntimeError, "Couldn't get device firmware (%d)", ret);
|
266
|
+
}
|
267
|
+
|
268
|
+
return rb_str_new_cstr(buf);
|
269
|
+
}
|
270
|
+
|
271
|
+
static VALUE model(VALUE self)
|
272
|
+
{
|
273
|
+
msr206_ctx_t *ctx;
|
274
|
+
uint8_t buf[10];
|
275
|
+
int ret;
|
276
|
+
|
277
|
+
Data_Get_Struct(self, msr206_ctx_t, ctx);
|
278
|
+
|
279
|
+
ret = msr_model(ctx->fd, buf);
|
280
|
+
|
281
|
+
if (ret != LIBMSR_ERR_OK) {
|
282
|
+
rb_raise(rb_eRuntimeError, "Couldn't get device model (%d)", ret);
|
283
|
+
}
|
284
|
+
|
285
|
+
return rb_str_new_cstr(buf);
|
286
|
+
}
|
287
|
+
|
240
288
|
static VALUE get_coercivity(VALUE self)
|
241
289
|
{
|
242
290
|
VALUE hi_co = ID2SYM(rb_intern("hi"));
|
data/ext/msr/tracks.c
CHANGED
@@ -30,6 +30,8 @@ void Init_msr_tracks()
|
|
30
30
|
{
|
31
31
|
c_MSR_Tracks = rb_define_class_under(mMSR, "Tracks", rb_cObject);
|
32
32
|
|
33
|
+
rb_define_const(c_MSR_Tracks, "MAX_TRACKS", INT2NUM(MSR_MAX_TRACKS));
|
34
|
+
|
33
35
|
rb_define_method(c_MSR_Tracks, "initialize", msr_tracks_initialize, 3);
|
34
36
|
rb_define_method(c_MSR_Tracks, "track1", msr_tracks_track1, 0);
|
35
37
|
rb_define_method(c_MSR_Tracks, "track2", msr_tracks_track2, 0);
|
data/lib/msr.rb
CHANGED
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.
|
4
|
+
version: 0.0.4
|
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-11-
|
11
|
+
date: 2016-11-04 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
|