-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmsr206.h
198 lines (152 loc) · 4.78 KB
/
msr206.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef _MSR206_H_
/* ESC is frequently used as a start delimiter character */
#define MSR_ESC 0x1B /* Escape character */
/* ASCII file separator character is used to separate track data */
#define MSR_FS 0x1C /* File separator */
#define MSR_STS_OK 0x30 /* Ok */
#define MSR_STS_ERR 0x41 /* General error */
typedef struct msr_cmd {
uint8_t msr_esc;
uint8_t msr_cmd;
} msr_cmd_t;
/* Read/write commands */
#define MSR_CMD_READ 0x72 /* Formatted read */
#define MSR_CMD_WRITE 0x77 /* Formatted write */
#define MSR_CMD_RAW_READ 0x6D /* Raw read */
#define MSR_CMD_RAW_WRITE 0x6E /* Raw write */
/* Status byte values from read/write commands */
#define MSR_STS_RW_ERR 0x31 /* Read/write error */
#define MSR_STS_RW_CMDFMT_ERR 0x32 /* Command format error */
#define MSR_STS_RW_CMDBAD_ERR 0x34 /* Invalid command */
#define MSR_STS_RW_SWIPEBAD_ERR 0x39 /* Invalud card swipe in write mode */
typedef struct msr_end {
uint8_t msr_enddelim;
uint8_t msr_fs;
uint8_t msr_esc;
uint8_t msr_sts;
} msr_end_t;
/*
* Read/write start and end delimiters.
* The empty delimiter occurs when reading a track with no data.
*/
#define MSR_RW_START 0x73 /* 's' */
#define MSR_RW_END 0x3F /* '?' */
#define MSR_RW_BAD 0x2A /* '*' */
#define MSR_RW_EMPTY 0x2B /* '+' */
/*
* Serial port communications test
* If serial communications are working properly, the device
* should respond with a 'y' command.
*/
#define MSR_CMD_DIAG_COMM 0x65 /* Communications test */
#define MSR_STS_COMM_OK 0x79
/*
* Sensor diagnostic command. Will respond with MSR_STS_OK once
* a card swipe is detected. Can be interrupted by a reset.
*/
#define MSR_CMD_DIAG_SENSOR 0x86 /* Card sensor test */
#define MSR_STS_SENSOR_OK MSR_STS_OK
/*
* RAM diagnostic command. Will return MSR_STS_OK if RAM checks
* good, otherwise MSR_STS_ERR.
*/
#define MSR_CMD_DIAG_RAM 0x87 /* RAM test */
#define MSR_STS_RAM_OK MSR_STS_OK
#define MSR_STS_RAM_ERR MSR_STS_ERR
/*
* Set leading zero count. Responds with MSR_STS_OK if values
* set ok, otherwise MSR_STS_ERR
*/
#define MSR_CMD_SLZ 0x7A /* Set leading zeros */
#define MSR_STS_SLZ_OK MSR_STS_OK
#define MSR_STS_SLZ_ERR MSR_STS_ERR
/*
* Get leading zero count. Returns leading zero counts for
* track 1/3 and 2.
*/
#define MSR_CMD_CLZ 0x6C /* Check leading zeros */
typedef struct msr_lz {
uint8_t msr_esc;
uint8_t msr_lz_tk1_3;
uint8_t msr_lz_tk2;
} msr_lz_t;
/*
* Erase card tracks. Returns MSR_STS_OK on success or
* MSR_STS_ERR.
*/
#define MSR_CMD_ERASE 0x63 /* Erase card tracks */
#define MSR_STS_ERASE_OK MSR_STS_OK
#define MSR_STS_ERASE_ERR MSR_STS_ERR
#define MSR_ERASE_TK1 0x00
#define MSR_ERASE_TK2 0x02
#define MSR_ERASE_TK3 0x04
#define MSR_ERASE_TK1_TK2 0x03
#define MSR_ERASE_TK1_TK3 0x05
#define MSR_ERASE_TK2_TK3 0x06
#define MSR_ERASE_ALL 0x07
/*
* Set bits per inch. Returns MSR_STS_OK on success or
* MSR_STS_ERR.
*/
#define MSR_CMD_SETBPI 0x62 /* Set bits per inch */
#define MSR_STS_BPI_OK MSR_STS_OK
#define MSR_STS_BPI_ERR MSR_STS_ERR
/*
* Get device model number. Returns a value indicating a model
* number, plus an 'S'.
*/
#define MSR_CMD_MODEL 0x74 /* Read model */
#define MSR_STS_MODEL_OK 0x53
#define MSR_MODEL_MSR206_1 0x31
#define MSR_MODEL_MSR206_2 0x32
#define MSR_MODEL_MSR206_3 0x33
#define MSR_MODEL_MSR206_5 0x35
typedef struct msr_model {
uint8_t msr_esc;
uint8_t msr_model;
uint8_t msr_s;
} msr_model_t;
/*
* Get firmware revision. Response is a string in
* the form of "REV?X.XX" where X.XX is the firmware
* rev, and ? can be:
*
* MSR206: '0'
* MSR206HC: 'H'
* MSR206HC: 'L'
*/
#define MSR_CMD_FWREV 0x76 /* Read firmware revision */
#define MSR_FWREV_FMT "REV?X.XX"
/*
* Set bits per character. Returns MSR_STS_OK on success, accompanied
* by resulting per-track BPC settings.
*/
#define MSR_CMD_SETBPC 0x6F /* Set bits per character */
#define MSR_STS_BPC_OK MSR_STS_OK
#define MSR_STS_BPC_ERR MSR_STS_ERR
typedef struct msr_bpc {
uint8_t msr_bpctk1;
uint8_t msr_bpctk2;
uint8_t msr_bpctk3;
} msr_bpc_t;
/*
* Set coercivity high or low. Returns MSR_STS_OK on success.
*/
#define MSR_CMD_SETCO_HI 0x78 /* Set coercivity high */
#define MSR_CMD_SETCO_LO 0x79 /* Set coercivity low */
#define MSR_STS_CO_OK MSR_STS_OK
#define MSR_STS_CO_ERR MSR_STS_ERR
/*
* Get coercivity. Returns 'H' for high coercivity, 'L' for low.
*/
#define MSR_CMD_GETGO 0x64 /* Read coercivity setting */
#define MSR_CO_HI 0x48
#define MSR_CO_LO 0x4C
/* The following commands have no response codes */
#define MSR_CMD_RESET 0x61 /* Reset device */
#define MSR_CMD_LED_OFF 0x81 /* All LEDs off */
#define MSR_CMD_LED_ON 0x82 /* All LEDs on */
#define MSR_CMD_LED_GRN_ON 0x83 /* Green LED on */
#define MSR_CMD_LED_YLW_ON 0x84 /* Yellow LED on */
#define MSR_CMD_LED_RED_ON 0x85 /* Red LED on */
#endif /* _MSR206_H_ */