pin_pad.h
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef ETRADECLIENT_HARDWARE_PIN_PAD_H_INCLUDED
#define ETRADECLIENT_HARDWARE_PIN_PAD_H_INCLUDED
#include <cstdint>
#include <string>
#include <functional>
/*A PIN pad or PIN entry device is an electronic device used in a debit,
credit or smart card-based transaction to accept and encrypt the cardholder's
personal identification number (PIN).
*/
/*
密码键盘产品信息:
生产厂商:深圳市德卡科技有限公司
型号:P3AS000UB
内置显示文字之ID与文字对应关系:
1->请输入密码
2->请再次输入密码
语音提示之ID与语音对应关系:
1->请输入密码
2->请输入原密码
3->请再输入一次
4->请输入新密码
5->请确认新密码
6->密码修改成功
7->请插卡
8->请刷卡
9->密码错误
*/
class PINPad
{
public:
/*内置显示内容*/
enum class BuiltInText
{
kEnterPWD = 1, // "请输入密码"
kReEnterPWD // "请再次输入密码"
};
/*内置语音输出*/
enum class BuiltInVoice
{
kEnterPWD = 1, // "请输入密码"
kEnterOriginalPWD, // "请输入原密码"
kReEnterPWD, // "请再输入一次"
kEnterNewPWD, // "请输入新密码"
kConfirmNewPWD, // "请确认新密码"
kChangePWDSucceed, // "密码修改成功"
kInsertCard, // "请插卡"
kSwipeCard, // "请刷卡"
kPWDIncorrect // "密码错误"
};
/*Display mode on PIN pad's LCD of used inuput password.*/
enum class DispMode
{
kNone, // No display.
kEncrypted, // Display the encrypted password in form of '*'.
kPlain, // Display plain text on LCD.
};
enum class DispLine
{
kL1 = 1, // Display text on Line one.
kL2 // Display text on Line two.
};
enum class StatusCode
{
kOK = 0, // No error.
kTimeout = 1, // Timeout when get password.
kCancelled = 2, // User input cancelled.
kUnknown = 3 // Other unknown error.
};
typedef void* HANDLE;
public:
~PINPad();
bool Connect() const;
void Disconnect() const;
bool DisplayBuiltInText(const BuiltInText& text) const; // Display the PIN pad's built in text.
bool PlayVoice(const BuiltInVoice& voice) const;
bool SetPWDMaxLen(uint8_t len) const; // Max length should be between 1 & 16, why 16? I chose it because the manufacturer didn't provide this specification.
bool SwitchLCDLight(bool on_off) const; // Set 'true' to turn on the light and 'false' to turn it off.
StatusCode ReadUserInputPWD(const DispMode& disp_mode, const DispLine& disp_line, uint8_t timeout, std::string& pwd) const; // Timeout in seconds, minimum value is 1.
bool ClearScreen() const;
std::string GetVersion() const;
private:
typedef std::function<short(unsigned char, unsigned char*, unsigned char*)> ReadUserInputPWDFn;
bool DoConnect() const;
StatusCode DoReadUserInputPWD(ReadUserInputPWDFn fn, uint8_t timeout, std::string& pwd) const;
mutable HANDLE m_handle; // The hardware connection handle.
};
#endif // ETRADECLIENT_HARDWARE_PIN_PAD_H_INCLUDED