Class: Smartware::Driver::PinPad::ZT588

Inherits:
Object
  • Object
show all
Defined in:
lib/smartware/drivers/pin_pad/zt588.rb

Defined Under Namespace

Classes: ZT588Error

Constant Summary collapse

LOAD_PLAIN_KEY =

Commands

'1'
LOAD_ENCRYPTED_KEY =
'2'
USER_INFORMATION =
'3'
LOAD_SCANCODE_TABLE =
'4'
CONTROL =
'5'
START_PIN_INPUT =
'6'
GET_PIN_VALUE =
'7'
AUTH =
':'
MISC =

Control commands and values

'0'
RESET =
'0'
WIPE =
'1'
DISABLE_INPUT =
'2'
ENABLE_INPUT =
'3'
DISABLE_SOUND =
'4'
ENABLE_SOUND =
'5'
BEEP =
'='
SET_INPUT_TIME_LIMIT =
'2'
SET_PIN_MASK =
'3'
SET_MIN_LENGTH =
'4'
SET_MAX_LENGTH =
'5'
SET_COMMUNICATION =
'6'
SET_BROKEN_HEX =
'0'
SET_HEX =
'7'
SET_1200 =
'H'
SET_2400 =
'I'
SET_4800 =
'J'
SET_9600 =
'K'
SET_19200 =
'L'
SET_38400 =
'M'
SET_57600 =
'N'
SET_115200 =
'O'
SET_BEEP_TIME =
'8'
AUTH_GET_CHALLENGE =

Authentication commands

0xA0
AUTH_WITH_TMK =
0x90
AUTH_WITH_IMK =
0x91
REVERSE_BAUD_TABLE =

Settings layout data

{
  48 => 1200,
  49 => 2400,
  50 => 4800,
  51 => 9600,
  52 => 19200,
  53 => 38400,
  54 => 57600,
  55 => 115200
}
UID =

Authentication data

"\x11" * 8
KEY_TMK =

Keys

0x20
KEY_TPK =
0x30
KEY_IMK =
0x80
KEY_TYPE_IMK =

Key types, etc

1
KEY_TYPE_TMK =
2
KEY_TYPE_TPK =
3
KEY_TYPE_TAK =
5
KEY_TYPE_TDK =
6
KEY_TYPE_TDEK =
7
KEY_TYPE_TDDK =
8
KEY_TYPE_TDSK =
9
KEY_LENGTH_SINGLE =
0
KEY_LENGTH_DOUBLE =
1
KEY_LENGTH_TRIPLE =
2
PIN_TYPE_MAP =
{
  Smartware::Interface::PinPad::ASCII     => '@',
  Smartware::Interface::PinPad::ISO9564_0 => ' ',
  Smartware::Interface::PinPad::ISO9564_1 => '!',
  Smartware::Interface::PinPad::ISO9564_3 => '#',
  Smartware::Interface::PinPad::IBM3624   => '0'
}
DEFAULT_CONFIG =
{
  "sound"              => true,
  "input_time_limit"   => 30,
  "minimum_pin_length" => 1,
  "maximum_pin_length" => 16,
  "beep_time"          => 0.1
}
SCANCODES =

ZT88 keyboard matrix:

1
2
3
cancel
4
5
6
clear
7
8
9
.
0
00
enter
A
C
E
G
B
D
F
H

A-D - left-side application keys, E-H - right-side application keys.

%W{
  1 2 3 \e
  4 5 6 \b
  7 8 9 \a
  . 0 # \r
  A C E G
  B D F H
}.join
ERRORS =
{
  0xE0 => "Low battery",
  0xE1 => "IMK required",
  0xE2 => "TMK required",
  0xE3 => "Unexpected key size",
  0xE4 => "Key not found",
  0xE5 => "Key not found or not compatible",
  0xE6 => "Key parity check failed",
  0xE7 => "Key is not valid",
  0xE8 => "Unexpected command length",
  0xE9 => "Incorrect data",
  0xEB => "Incorrect parameter",
  0xEC => "Authorization required",
  0xED => "Authorization temporary locked",
  0xEE => "Input timed out",
  0xEF => "General error"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ZT588

Returns a new instance of ZT588.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 144

def initialize(config)
  @config = DEFAULT_CONFIG.merge(config)
  @plain_input = false
  @auto_stop = nil

  @port = SerialPort.new(config["port"], 9600, 8, 1, SerialPort::NONE)
  @port.flow_control = SerialPort::HARD

  @connection = EventMachine.attach @port, SZZTConnection
  @connection.baud_test_command = '3'
  @connection.baud_switch_command = ->(baud) {
    sprintf('56%d', baud + 41)
  }
  @connection.dsr_fall = method :dsr_fall
  @connection.initialize_device = method :initialize_device
  @connection.handle_keypad = method :handle_keypad

  @imk_source = nil
  @post_configuration = nil
  @device_ready = nil
  @device_not_ready = nil
  @input_event = nil
end

Instance Attribute Details

#device_not_readyObject

Returns the value of attribute device_not_ready.



141
142
143
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 141

def device_not_ready
  @device_not_ready
end

#device_readyObject

Returns the value of attribute device_ready.



140
141
142
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 140

def device_ready
  @device_ready
end

#imk_sourceObject

Returns the value of attribute imk_source.



140
141
142
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 140

def imk_source
  @imk_source
end

#input_eventObject

Returns the value of attribute input_event.



141
142
143
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 141

def input_event
  @input_event
end

#modelObject (readonly)

Returns the value of attribute model.



142
143
144
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 142

def model
  @model
end

#post_configurationObject

Returns the value of attribute post_configuration.



140
141
142
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 140

def post_configuration
  @post_configuration
end

#user_dataObject

Returns the value of attribute user_data.



142
143
144
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 142

def user_data
  @user_data
end

#versionObject (readonly)

Returns the value of attribute version.



142
143
144
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 142

def version
  @version
end

Instance Method Details

#get_pinObject



224
225
226
227
228
229
230
231
232
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 224

def get_pin
  response = safe_command GET_PIN_VALUE

  [
    response.slice(1, 2).to_i, # Track
    response.slice(3, 2).to_i, # Length
    bin(response[5..-1])       # Block
  ]
end

#load_working_keys(set, tpk_under_tmk) ⇒ Object



215
216
217
218
219
220
221
222
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 215

def load_working_keys(set, tpk_under_tmk)
  raise "unsupported key set" unless set == 0

  tpk_verify = load_encrypted_key KEY_TPK, KEY_TMK, KEY_TYPE_TPK, nil,
                                  tpk_under_tmk

  return tpk_verify
end

#restartObject

def wipe

  control MISC, WIPE
  sleep 3
  initialize_device true
end


182
183
184
185
186
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 182

def restart
  control MISC, RESET
  sleep 3
  initialize_device
end

#start_input(mode, options = {}) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 188

def start_input(mode, options = {})
  case mode
  when Interface::PinPad::INPUT_PLAINTEXT
    @plain_input = true
    @auto_stop = nil
    control MISC, ENABLE_INPUT

  when Interface::PinPad::INPUT_PIN
    raise "unsupported key set" unless options[:key_set] == 0
    @plain_input = false
    @auto_stop = options[:length]

    start_pin_input KEY_TPK, options[:format], 0, options[:length],
                    options[:pan]

  else
    raise ZT588Error, "unsupported input mode: #{mode}"
  end

  @input_event.call :start
end

#stop_inputObject



210
211
212
213
# File 'lib/smartware/drivers/pin_pad/zt588.rb', line 210

def stop_input
  do_stop_input
  @input_event.call :cancel
end