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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
#ifndef __CPHIDGETRFID
#define __CPHIDGETRFID
#include "cphidget.h"
/** \defgroup phidrfid Phidget RFID
* \ingroup phidgets
* These calls are specific to the Phidget RFID object. See your device's User Guide for more specific API details, technical information, and revision details. The User Guide, along with other resources, can be found on the product page for your device.
* @{
*/
DPHANDLE(RFID)
CHDRSTANDARD(RFID)
/**
* Gets the number of outputs supported by this board.
* @param phid An attached phidget rfid handle.
* @param count The output count.
*/
CHDRGET(RFID,OutputCount,int *count)
/**
* Gets the state of an output.
* @param phid An attached phidget rfid handle.
* @param index The output index.
* @param outputState The output state. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRGETINDEX(RFID,OutputState,int *outputState)
/**
* Sets the state of an output.
* @param phid An attached phidget rfid handle.
* @param index The output index.
* @param outputState The output state. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRSETINDEX(RFID,OutputState,int outputState)
/**
* Set an output change handler. This is called when an output changes.
* @param phid An attached phidget rfid handle.
* @param fptr Callback function pointer.
* @param userPtr A pointer for use by the user - this value is passed back into the callback function.
*/
CHDREVENTINDEX(RFID,OutputChange,int outputState)
/**
* Gets the state of the antenna.
* @param phid An attached phidget rfid handle.
* @param antennaState The antenna state. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRGET(RFID,AntennaOn,int *antennaState)
/**
* Sets the state of the antenna. Note that the antenna must be enabled before tags will be read.
* @param phid An attached phidget rfid handle.
* @param antennaState The antenna state. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRSET(RFID,AntennaOn,int antennaState)
/**
* Gets the state of the onboard LED.
* @param phid An attached phidget rfid handle.
* @param LEDState The LED state. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRGET(RFID,LEDOn,int *LEDState)
/**
* Sets the state of the onboard LED.
* @param phid An attached phidget rfid handle.
* @param LEDState The LED state. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRSET(RFID,LEDOn,int LEDState)
/**
* Gets the last tag read by the reader. This tag may or may not still be on the reader.
* @param phid An attached phidget rfid handle.
* @param tag The tag. This must be an unsigned char array of size 5.
*/
CHDRGET(RFID,LastTag,unsigned char *tag)
/**
* Gets the tag present status. This is whether or not a tag is being read by the reader.
* @param phid An attached phidget rfid handle.
* @param status The tag status. Possible values are \ref PTRUE and \ref PFALSE.
*/
CHDRGET(RFID,TagStatus,int *status)
/**
* Set a tag handler. This is called when a tag is first detected by the reader.
* @param phid An attached phidget rfid handle.
* @param fptr Callback function pointer.
* @param userPtr A pointer for use by the user - this value is passed back into the callback function.
*/
CHDREVENT(RFID,Tag,unsigned char *tag)
/**
* Set a tag lost handler. This is called when a tag is no longer detected by the reader.
* @param phid An attached phidget rfid handle.
* @param fptr Callback function pointer.
* @param userPtr A pointer for use by the user - this value is passed back into the callback function.
*/
CHDREVENT(RFID,TagLost,unsigned char *tag)
#ifndef REMOVE_DEPRECATED
DEP_CHDRGET("Deprecated - use CPhidgetRFID_getOutputCount",RFID,NumOutputs,int *)
#endif
//These are for a prototype device - hide until it's released
#if !defined(EXTERNALPROTO) || defined(DEBUG)
typedef enum {
PHIDGET_RFID_ENCODING_MANCHESTER = 1,
PHIDGET_RFID_ENCODING_BIPHASE,
PHIDGET_RFID_ENCODING_AC
} CPhidgetRFID_Encoding;
typedef enum {
PHIDGET_RFID_TAG_ISO11784 = 1,
PHIDGET_RFID_TAG_EM4102,
PHIDGET_RFID_TAG_HITAGS
} CPhidgetRFID_TagType;
typedef struct _CPhidgetRFID_TagInfo
{
int bitRate;
CPhidgetRFID_TagType tagType;
CPhidgetRFID_Encoding encoding;
} CPhidgetRFID_TagInfo, *CPhidgetRFID_TagInfoHandle;
typedef struct _CPhidgetRFID_TagOptions
{
unsigned char writable;
unsigned char encrypted;
int memSize;
} CPhidgetRFID_TagOptions, *CPhidgetRFID_TagOptionsHandle;
CHDRSET(RFID,PollingOn,int pollingState)
PHIDGET21_API int CCONV CPhidgetRFID_writeRaw(CPhidgetRFIDHandle phid, unsigned char *data, int bitlength, int pregap, int space, int postgap, int zero, int one);
PHIDGET21_API int CCONV CPhidgetRFID_getRawData(CPhidgetRFIDHandle phid, int *data, int *dataLength);
PHIDGET21_API int CCONV CPhidgetRFID_getTagOptions(CPhidgetRFIDHandle phid, char *tagString, CPhidgetRFID_TagOptionsHandle options);
PHIDGET21_API int CCONV CPhidgetRFID_read(CPhidgetRFIDHandle phid, char *tagString, unsigned char *data, int *dataLength, char *password);
PHIDGET21_API int CCONV CPhidgetRFID_write(CPhidgetRFIDHandle phid, char *tagString, unsigned char *data, int dataLength, int offset, char *password);
CHDREVENT(RFID, RawData, int *data, int dataLength)
CHDREVENT(RFID, ManchesterData, unsigned char *data, int dataLength)
CHDREVENT(RFID, TagAdvanced, char *tagString, CPhidgetRFID_TagInfoHandle tagInfo)
CHDREVENT(RFID, TagLostAdvanced, char *tagString, CPhidgetRFID_TagInfoHandle tagInfo)
#endif
#ifndef EXTERNALPROTO
#define RFID_PACKET_TAG 0
#define RFID_PACKET_OUTPUT_ECHO 1
#define RFID_LED_FLAG 0x04
#define RFID_ANTENNA_FLAG 0x08
//RFID Advanced Constants
#define RFID_WRITE_DATA_OUT_PACKET 0x00
#define RFID_CONTROL_OUT_PACKET 0x40
#define RFID_READ_DATA_IN_PACKET 0x00
#define RFID_ECHO_IN_PACKET 0x40
//4097 constants
#define RFID_4097_AmpDemod 0x00 //Amplitude demodulation
#define RFID_4097_PhaseDemod 0x01 //Phase demodulation
#define RFID_4097_PowerDown 0x00
#define RFID_4097_Active 0x02
#define RFID_4097_DataOut 0x00 //DATA_OUT is data from the rfid card
#define RFID_4097_ClkOut 0x04 //DATA_OUT is the internal clock/32
#define RFID_4097_IntPLL 0x00
#define RFID_4097_ExtClk 0x08
#define RFID_4097_FastStart 0x10
#define RFID_4097_Gain960 0x40
#define RFID_4097_Gain480 0x00
#define RFID_4097_Gain240 0x60
#define RFID_4097_Gain120 0x20
#define RFID_4097_TestMode 0x80
#define RFID_MAX_DATA_PER_PACKET 62
#define RFID_DATA_ARRAY_SIZE 2048
#define RFID_DATA_ARRAY_MASK 0x7ff
#define RFID_MAXOUTPUTS 2
typedef enum _CPhidgetRFID_Hitag_State
{
RFID_HITAG_STATE_NONE = 0,
RFID_HITAG_STATE_UID_REQUEST,
RFID_HITAG_STATE_AC_SEQUENCE,
RFID_HITAG_STATE_SELECT,
RFID_HITAG_STATE_READ,
RFID_HITAG_STATE_WRITE
} CPhidgetRFID_Hitag_State;
typedef struct _CPhidgetRFID_Tag
{
char tagString[256];
CPhidgetRFID_TagInfo tagInfo;
TIME lastTagTime;
unsigned char tagEventPending;
unsigned char tagOptionsValid;
CPhidgetRFID_TagOptions tagOptions;
unsigned char tagDataValid;
unsigned char tagData[256];
} CPhidgetRFID_Tag, *CPhidgetRFID_TagHandle;
typedef struct _CPhidgetRFID_TagList
{
struct _CPhidgetRFID_TagList *next;
CPhidgetRFID_TagHandle tag;
} CPhidgetRFID_TagList, *CPhidgetRFID_TagListHandle;
typedef struct _CPhidgetRFID_HitagAC
{
unsigned char uid[4];
int colPos;
} CPhidgetRFID_HitagAC, *CPhidgetRFID_HitagACHandle;
typedef struct _CPhidgetRFID_HitagACList
{
struct _CPhidgetRFID_HitagACList *next;
CPhidgetRFID_HitagACHandle hitagAC;
} CPhidgetRFID_HitagACList, *CPhidgetRFID_HitagACListHandle;
struct _CPhidgetRFID {
CPhidget phid;
int (CCONV *fptrOutputChange)(CPhidgetRFIDHandle, void *, int, int);
int (CCONV *fptrTag)(CPhidgetRFIDHandle, void *, unsigned char *);
int (CCONV *fptrTagLost)(CPhidgetRFIDHandle, void *, unsigned char *);
int (CCONV *fptrRawData)(CPhidgetRFIDHandle, void *, int *, int);
int (CCONV *fptrManchesterData)(CPhidgetRFIDHandle, void *, unsigned char *, int);
int (CCONV *fptrTagAdvanced)(CPhidgetRFIDHandle, void *, char *, CPhidgetRFID_TagInfoHandle);
int (CCONV *fptrTagLostAdvanced)(CPhidgetRFIDHandle, void *, char *, CPhidgetRFID_TagInfoHandle);
void *fptrOutputChangeptr;
void *fptrTagptr;
void *fptrTagLostptr;
void *fptrRawDataptr;
void *fptrManchesterDataptr;
void *fptrTagAdvancedptr;
void *fptrTagLostAdvancedptr;
// Values returned from the device
unsigned char outputEchoState[RFID_MAXOUTPUTS];
unsigned char antennaEchoState;
unsigned char ledEchoState;
unsigned char outputState[RFID_MAXOUTPUTS];
unsigned char antennaState;
unsigned char ledState;
unsigned char lastTag[5];
unsigned char lastTagValid;
TIME lastTagTime;
unsigned char tagPresent;
//unsigned char tagEvent;
unsigned char pendingTag[5];
unsigned char tagEventPending;
EVENT tagAvailableEvent;
void *respData;
int respStatus;
EVENT respEvent;
EVENT respEvent2;
//Advanced Tag Events
int tagAdvancedCount;
CThread_mutex_t tagthreadlock; /* protects tag thread access to things */
CPhidgetRFID_TagListHandle tagAdvancedList;
CPhidgetRFID_Tag lastTagAdvanced;
TIME lastDataTime;
TIME hitagReqTime;
unsigned char ACCodingOK;
unsigned char fullStateEcho;
CThread tagTimerThread;
//RFID Advanced stuff
int spaceClocks, pregapClocks, postgapClocks, oneClocks, zeroClocks;
int spaceClocksEcho, pregapClocksEcho, postgapClocksEcho, oneClocksEcho, zeroClocksEcho;
int _4097Conf, _4097ConfEcho;
int frequencyEcho;
int dataBuffer[RFID_DATA_ARRAY_SIZE];
int dataBufferNormalized[RFID_DATA_ARRAY_SIZE];
unsigned int dataReadPtr, dataWritePtr, dataReadACPtr;
unsigned int userReadPtr; //for the getRawData function
unsigned char manBuffer[RFID_DATA_ARRAY_SIZE];
int manReadPtr, manWritePtr;
unsigned char biphaseBuffer[RFID_DATA_ARRAY_SIZE];
int biphaseReadPtr, biphaseWritePtr;
unsigned char manLockedIn;
unsigned char manShortChange;
unsigned char biphaseLockedIn;
unsigned char biphaseShortChange;
int one, two;
int oneCount, twoCount;
CPhidgetRFID_Hitag_State hitagState;
int hitagOffset;
//Hitag AC queue
CPhidgetRFID_HitagACListHandle hitagACList;
CPhidgetRFID_HitagAC lastHitagAC;
unsigned char atGap, polling;
unsigned char outputPacket[MAX_OUT_PACKET_SIZE];
unsigned int outputPacketLen;
int manEventReadPtr;
} typedef CPhidgetRFIDInfo;
#endif
/** @} */
#endif
|