Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __CTRFID_driver_H__
00013 #define __CTRFID_driver_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #pragma systemFile
00045
00046 #ifndef __COMMON_H__
00047 #include "drivers/common.h"
00048 #endif
00049
00050
00051 #define CTRFID_I2C_ADDR 0x04
00052
00053
00054 #define CTRFID_FIRM_VER 0x00
00055 #define CTRFID_MAN_NAME 0x08
00056 #define CTRFID_SENS_TYP 0x10
00057 #define CTRFID_STATUS 0x32
00058 #define CTRFID_OFFSET 0x41
00059 #define CTRFID_CMD 0x00
00060 #define CTRFID_BYTE1 0x01
00061 #define CTRFID_BYTE2 0x02
00062 #define CTRFID_BYTE3 0x03
00063 #define CTRFID_BYTE4 0x04
00064 #define CTRFID_BYTE5 0x05
00065 #define CTRFID_SERIAL 0xA0
00066
00067
00068 #define CTRFID_CMD_STOP 0x00
00069
00070 #define CTRFID_CMD_SINGLESHOT 0x01
00071
00072
00073
00074
00075
00076
00077 #define CTRFID_CMD_CONTINUOUS 0x02
00078
00079
00080
00081 #define CTRFID_CMD_BOOTLOADER 0x81
00082 #define CTRFID_CMD_STARTAPPFIRM 0x83
00083
00084
00085
00086
00087 bool CTRFIDinit(tSensors link);
00088 bool CTRFIDsetContinuous(tSensors link);
00089 bool CTRFIDsetSingleShot(tSensors link);
00090 bool CTRFIDreadTransponder (tSensors link, string &transponderID);
00091
00092
00093 bool _CTRFIDsendCommand(tSensors link, ubyte command);
00094 bool _CTRFIDsendDummy(tSensors link);
00095 bool _CTRFIDreadStatus(tSensors link, ubyte &_status);
00096
00097
00098
00099 tByteArray CTRFID_I2CRequest;
00100 tByteArray CTRFID_I2CReply;
00101
00102 bool CTRFIDreadContinuous[4] = {false, false, false, false};
00103 bool CTRFIDinitialised[4] = {false, false, false, false};
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 bool _CTRFIDsendCommand(tSensors link, ubyte command) {
00115 memset(CTRFID_I2CRequest, 0, sizeof(tByteArray));
00116
00117 if (!CTRFIDinitialised[link] && (command != CTRFID_CMD_STARTAPPFIRM))
00118 CTRFIDinit(link);
00119
00120 CTRFID_I2CRequest[0] = 3;
00121 CTRFID_I2CRequest[1] = CTRFID_I2C_ADDR;
00122 CTRFID_I2CRequest[2] = CTRFID_OFFSET + CTRFID_CMD;
00123 CTRFID_I2CRequest[3] = command;
00124
00125 return writeI2C(link, CTRFID_I2CRequest);
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 bool _CTRFIDsendDummy(tSensors link) {
00137 memset(CTRFID_I2CRequest, 0, sizeof(tByteArray));
00138
00139 CTRFID_I2CRequest[0] = 1;
00140 CTRFID_I2CRequest[1] = CTRFID_I2C_ADDR;
00141
00142 return writeI2C(link, CTRFID_I2CRequest);
00143 memset(CTRFID_I2CRequest, 0, sizeof(tByteArray));
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 bool _CTRFIDreadStatus(tSensors link, ubyte &_status) {
00155 memset(CTRFID_I2CRequest, 0, sizeof(tByteArray));
00156
00157 if(!_CTRFIDsendDummy(link))
00158 return false;
00159
00160 if (!CTRFIDinitialised[link])
00161 CTRFIDinit(link);
00162
00163 if (CTRFIDreadContinuous[link])
00164 return true;
00165
00166 CTRFID_I2CRequest[0] = 2;
00167 CTRFID_I2CRequest[1] = CTRFID_I2C_ADDR;
00168 CTRFID_I2CRequest[2] = CTRFID_STATUS;
00169
00170 if (!writeI2C(link, CTRFID_I2CRequest, CTRFID_I2CReply, 1))
00171 return false;
00172
00173 _status = CTRFID_I2CReply[0];
00174
00175 return true;
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 bool CTRFIDinit(tSensors link) {
00185 if (_CTRFIDsendCommand(link, CTRFID_CMD_STARTAPPFIRM)) {
00186 CTRFIDinitialised[link] = true;
00187 return true;
00188 } else {
00189 return false;
00190 }
00191 }
00192
00193
00194
00195
00196
00197
00198
00199
00200 bool CTRFIDsetContinuous(tSensors link) {
00201 if(!_CTRFIDsendDummy(link))
00202 return false;
00203
00204 if (_CTRFIDsendCommand(link, CTRFID_CMD_CONTINUOUS)) {
00205 CTRFIDreadContinuous[link] = true;
00206 return true;
00207 } else {
00208 return false;
00209 }
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 bool CTRFIDsetSingleShot(tSensors link) {
00219 if(!_CTRFIDsendDummy(link))
00220 return false;
00221
00222 if (_CTRFIDsendCommand(link, CTRFID_CMD_SINGLESHOT)) {
00223 CTRFIDreadContinuous[link] = false;
00224 return true;
00225 } else {
00226 return false;
00227 }
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237 bool CTRFIDreadTransponder(tSensors link, string &transponderID) {
00238 ubyte _status;
00239
00240
00241 if(!_CTRFIDsendDummy(link)) {
00242 return false;
00243 }
00244
00245 if (!CTRFIDinitialised[link]) {
00246 CTRFIDinit(link);
00247
00248 wait1Msec(100);
00249 }
00250
00251 if(CTRFIDreadContinuous[link] == false) {
00252
00253 CTRFIDsetSingleShot(link);
00254
00255
00256 wait1Msec(250);
00257 } else {
00258 _CTRFIDreadStatus(link, _status);
00259 if (_status == 0) {
00260 CTRFIDsetContinuous(link);
00261
00262 wait1Msec(250);
00263 }
00264 }
00265
00266
00267 memset(CTRFID_I2CRequest, 0, sizeof(tByteArray));
00268 CTRFID_I2CRequest[0] = 2;
00269 CTRFID_I2CRequest[1] = CTRFID_I2C_ADDR;
00270 CTRFID_I2CRequest[2] = CTRFID_OFFSET + CTRFID_BYTE1;
00271 if (!writeI2C(link, CTRFID_I2CRequest, CTRFID_I2CReply, 5))
00272 return false;
00273
00274
00275
00276
00277 strcpy(transponderID, "");
00278 for (int i=0;i<5;i++) {
00279
00280 StringFormat(transponderID, "%s%02x", transponderID, CTRFID_I2CReply[i]);
00281 }
00282 return true;
00283 }
00284
00285 #endif // __CODATEX_RFID_driver_H__
00286
00287
00288
00289
00290
00291