rfid4r 1.0.0-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = rfid4r
2
+ An RFID middleware using a Ruby wrapper for the PhidgetRFID-1023 reader.
3
+
4
+ == System Configuration
5
+ Para el correcto funcionamiento de este gem, sera necesario instalar en nuestro ambiente de desarrollo la libreria del lector
6
+ RFID PhidgetRFID-1023 (http://www.phidgets.com/) y la libreria SQLite3 (http://www.sqlite.org/) para manejo de bases de datos.
7
+ Por otra parte, nuestro gem depende del gem sqlit3-ruby (http://rubyforge.org/projects/sqlite-ruby/) para un funcionamiento optimo
8
+ en el manejo de la base de datos SQLite.
9
+
10
+ == Installing
11
+ La instalación es muy sencilla, simplemente se debe descargar el gem con los archivos necesarios e instalarlo (enlace rubyforge)
12
+ usando los comandos provistos por Rubygems, por ejemplo, una vez descargado el paquete rfid4r-1.0.0-x86-linux.gem
13
+ basta con ejecutar el siguiente comando:
14
+ > sudo gem install rfid4r-1.0.0-x86-linux.gem
15
+
16
+ == Middleware Setup
17
+ Una vez instalado nuestro gem podrá ser usado para el desarrollo de cualquier aplicacion o Middleware RFID que se desee,
18
+ basta con importar en el codigo los gems necesario, por ejemplo:
19
+ #Rubygems
20
+ require 'rubygems'
21
+ #Nuestor gem Rfid4r para el manejo de lectores PhidgetRFID-1023
22
+ require 'rfid4r'
23
+ En este punto podrá usar las funcionalidades provistas por nuestro gem y que se especifican en esta documentación.
24
+ Un aspecto importante para el correcto funcionamiento del gem, esta relacionado al RfidServer, que representa un pequeño
25
+ servidor para el manejo del lector RFID, por lo que siempre será necesario configurar e iniciar el servidor para la utilización
26
+ del lector RFID asociado. Finalmente para la configuración del servidor se requiere de un archivo de configuracion YAML, y deberá cumplir
27
+ con la siguiente sintaxis:
28
+ #filename: rfid_config.yml
29
+
30
+ #configuracion local del servidor
31
+ local_config:
32
+ id_server: [id]
33
+ ip_address: [ip_address]
34
+ port: [port]
35
+
36
+ #Configuracion de los otros servidores que podran comunicarse e intercambiar consultas con el servidor local
37
+ server[id_of_server_1]:
38
+ id_server: [id_1]
39
+ ip_address: [ip_address_1]
40
+ port: [port_1]
41
+ .
42
+ .
43
+ .
44
+ server[id_of_server_n]:
45
+ id_server: [id_n]
46
+ ip_address: [ip_address_n]
47
+ port: [port_n]
48
+
data/ext/Makefile ADDED
@@ -0,0 +1,150 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /usr/local/lib/ruby/1.8/i686-linux
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ prefix = $(DESTDIR)/usr/local
11
+ exec_prefix = $(prefix)
12
+ sitedir = $(prefix)/lib/ruby/site_ruby
13
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
14
+ docdir = $(datarootdir)/doc/$(PACKAGE)
15
+ dvidir = $(docdir)
16
+ datarootdir = $(prefix)/share
17
+ archdir = $(rubylibdir)/$(arch)
18
+ sbindir = $(exec_prefix)/sbin
19
+ psdir = $(docdir)
20
+ localedir = $(datarootdir)/locale
21
+ htmldir = $(docdir)
22
+ datadir = $(datarootdir)
23
+ includedir = $(prefix)/include
24
+ infodir = $(datarootdir)/info
25
+ sysconfdir = $(prefix)/etc
26
+ mandir = $(datarootdir)/man
27
+ libdir = $(exec_prefix)/lib
28
+ sharedstatedir = $(prefix)/com
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ pdfdir = $(docdir)
31
+ sitearchdir = $(sitelibdir)/$(sitearch)
32
+ bindir = $(exec_prefix)/bin
33
+ localstatedir = $(prefix)/var
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ libexecdir = $(exec_prefix)/libexec
36
+
37
+ CC = gcc
38
+ LIBRUBY = $(LIBRUBY_A)
39
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
+ LIBRUBYARG_SHARED = -Wl,-R -Wl,$(libdir) -L$(libdir)
41
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
42
+
43
+ RUBY_EXTCONF_H =
44
+ CFLAGS = -fPIC -g -O2
45
+ INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
46
+ DEFS = -D_FILE_OFFSET_BITS=64
47
+ CPPFLAGS = $(DEFS)
48
+ CXXFLAGS = $(CFLAGS)
49
+ DLDFLAGS = -L. -rdynamic -Wl,-export-dynamic
50
+ LDSHARED = $(CC) -shared
51
+ AR = ar
52
+ EXEEXT =
53
+
54
+ RUBY_INSTALL_NAME = ruby
55
+ RUBY_SO_NAME = ruby
56
+ arch = i686-linux
57
+ sitearch = i686-linux
58
+ ruby_version = 1.8
59
+ ruby = /usr/local/bin/ruby
60
+ RUBY = $(ruby)
61
+ RM = rm -f
62
+ MAKEDIRS = mkdir -p
63
+ INSTALL = /usr/bin/install -c
64
+ INSTALL_PROG = $(INSTALL) -m 0755
65
+ INSTALL_DATA = $(INSTALL) -m 644
66
+ COPY = cp
67
+
68
+ #### End of system configuration section. ####
69
+
70
+ preload =
71
+
72
+ libpath = . $(libdir)
73
+ LIBPATH = -L. -L$(libdir) -Wl,-R$(libdir)
74
+ DEFFILE =
75
+
76
+ CLEANFILES = mkmf.log
77
+ DISTCLEANFILES =
78
+
79
+ extout =
80
+ extout_prefix =
81
+ target_prefix =
82
+ LOCAL_LIBS =
83
+ LIBS = -ldl -lcrypt -lm -lc -lphidget21 -lsqlite3
84
+ SRCS = phid_wrap.c
85
+ OBJS = phid_wrap.o
86
+ TARGET = phid
87
+ DLLIB = $(TARGET).so
88
+ EXTSTATIC =
89
+ STATIC_LIB =
90
+
91
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
92
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
93
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
94
+
95
+ TARGET_SO = $(DLLIB)
96
+ CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
97
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
98
+
99
+ all: $(DLLIB)
100
+ static: $(STATIC_LIB)
101
+
102
+ clean:
103
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
104
+
105
+ distclean: clean
106
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
107
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
108
+
109
+ realclean: distclean
110
+ install: install-so install-rb
111
+
112
+ install-so: $(RUBYARCHDIR)
113
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
114
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
115
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
116
+ install-rb: pre-install-rb install-rb-default
117
+ install-rb-default: pre-install-rb-default
118
+ pre-install-rb: Makefile
119
+ pre-install-rb-default: Makefile
120
+ $(RUBYARCHDIR):
121
+ $(MAKEDIRS) $@
122
+
123
+ site-install: site-install-so site-install-rb
124
+ site-install-so: install-so
125
+ site-install-rb: install-rb
126
+
127
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
128
+
129
+ .cc.o:
130
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
131
+
132
+ .cxx.o:
133
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
134
+
135
+ .cpp.o:
136
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
137
+
138
+ .C.o:
139
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
140
+
141
+ .c.o:
142
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
143
+
144
+ $(DLLIB): $(OBJS)
145
+ @-$(RM) $@
146
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
147
+
148
+
149
+
150
+ $(OBJS): ruby.h defines.h
data/ext/extconf.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ $LIBS += " -lphidget21 -lsqlite3"
4
+
5
+ create_makefile('phid')
6
+
data/ext/phid.h ADDED
@@ -0,0 +1,156 @@
1
+ /*
2
+ * File: phid.h
3
+ * Author: daniel
4
+ *
5
+ * Created on August 15, 2008, 5:13 PM
6
+ */
7
+
8
+ #include <stdio.h>
9
+ #include <phidget21.h>
10
+ #include <sqlite3.h>
11
+
12
+ CPhidgetRFIDHandle rfid = 0;
13
+
14
+ sqlite3 *db;
15
+ char *zErrMsg = 0;
16
+ int rc;
17
+ char last_tag[25];
18
+ int tags=0;
19
+
20
+ CPhidgetLog_level level = PHIDGET_LOG_VERBOSE;
21
+
22
+ void enable_loggin(char *outputFile) {
23
+ CPhidget_enableLogging(level, outputFile);
24
+ }
25
+
26
+ void disable_loggin() {
27
+ CPhidget_disableLogging();
28
+ }
29
+
30
+ void log_message(char* id, char* message) {
31
+ CPhidget_log(level, id, message);
32
+ }
33
+
34
+ const char* get_device_name() {
35
+ const char *name;
36
+ CPhidget_getDeviceName((CPhidgetHandle) rfid, &name);
37
+ return name;
38
+ }
39
+
40
+ const char* get_device_type() {
41
+ const char *name;
42
+ CPhidget_getDeviceType((CPhidgetHandle) rfid, &name);
43
+ return name;
44
+ }
45
+
46
+ int get_serial_number() {
47
+ int serialNo;
48
+ CPhidget_getSerialNumber((CPhidgetHandle) rfid, &serialNo);
49
+ return serialNo;
50
+ }
51
+
52
+ int get_device_version() {
53
+ int version;
54
+ CPhidget_getDeviceVersion((CPhidgetHandle) rfid, &version);
55
+ return version;
56
+ }
57
+
58
+ void turn_led_on() {
59
+ CPhidgetRFID_setLEDOn(rfid, 1);
60
+ }
61
+
62
+ void turn_led_off() {
63
+ CPhidgetRFID_setLEDOn(rfid, 0);
64
+ }
65
+
66
+ static int callback(void *NotUsed, int argc, char **argv, char **azColName){
67
+ int i;
68
+ for(i=0; i<argc; i++){
69
+ printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
70
+ }
71
+ printf("\n");
72
+ return 0;
73
+ }
74
+
75
+ int tag_handler(CPhidgetRFIDHandle RFID, void *usrptr, unsigned char *TagVal) {
76
+ turn_led_on();
77
+
78
+ char id[255];
79
+ //char message[25];
80
+ char sql[512];
81
+
82
+ tags++;
83
+
84
+ sprintf(id, "Reader Serial:%d", get_serial_number());
85
+ sprintf(last_tag, "Tag Read:%02x%02x%02x%02x%02x", TagVal[0], TagVal[1], TagVal[2], TagVal[3], TagVal[4]);
86
+ sprintf(sql, "INSERT INTO log VALUES('%d','%02x%02x%02x%02x%02x',DATETIME('now'));", get_serial_number(), TagVal[0], TagVal[1], TagVal[2], TagVal[3], TagVal[4]);
87
+
88
+ printf("%s\n", last_tag);
89
+
90
+ log_message(id, last_tag);
91
+ rc = sqlite3_exec(db, sql, callback, 0, &zErrMsg);
92
+ return 0;
93
+ }
94
+
95
+ int tag_lost_handler(CPhidgetRFIDHandle RFID, void *usrptr, unsigned char *TagVal) {
96
+ turn_led_off();
97
+
98
+ char id[255];
99
+ //char message[25];
100
+ char sql[512];
101
+
102
+ tags++;
103
+
104
+ sprintf(id, "Reader Serial:%d", get_serial_number());
105
+ sprintf(last_tag, "Tag Lost:%02x%02x%02x%02x%02x", TagVal[0], TagVal[1], TagVal[2], TagVal[3], TagVal[4]);
106
+
107
+ printf("%s\n", last_tag);
108
+
109
+ log_message(id, last_tag);
110
+ return 0;
111
+ }
112
+
113
+ void turn_antenna_on() {
114
+ CPhidgetRFID_setAntennaOn(rfid, 1);
115
+ CPhidgetRFID_set_OnTag_Handler(rfid, tag_handler, NULL);
116
+ CPhidgetRFID_set_OnTagLost_Handler(rfid, tag_lost_handler, NULL);
117
+ }
118
+
119
+ void turn_antenna_off() {
120
+ CPhidgetRFID_setAntennaOn(rfid, 0);
121
+ }
122
+
123
+ void rfid_create(char *dbname) {
124
+ tags=0;
125
+ CPhidgetRFID_create(&rfid);
126
+ CPhidget_open((CPhidgetHandle)rfid, -1);
127
+ rc = sqlite3_open(dbname, &db);
128
+ rc = sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS log (reader_id TEXT NOT NULL, tag_read_id TEXT NOT NULL, read_at DATETIME NOT NULL, PRIMARY KEY (reader_id, tag_read_id, read_at));", callback, 0, &zErrMsg);
129
+ }
130
+
131
+ void rfid_delete() {
132
+ CPhidget_close((CPhidgetHandle)rfid);
133
+ CPhidget_delete((CPhidgetHandle)rfid);
134
+ disable_loggin();
135
+ sqlite3_close(db);
136
+ }
137
+
138
+ int wait_attachment(int time) {
139
+ int result = CPhidget_waitForAttachment((CPhidgetHandle)rfid, time);
140
+ return result;
141
+ }
142
+
143
+ const char* get_error_description(int result) {
144
+ const char *err;
145
+ CPhidget_getErrorDescription(result, &err);
146
+ return err;
147
+ }
148
+
149
+ char* get_lastTag(){
150
+ return last_tag;
151
+ }
152
+
153
+ int count_tags(){
154
+ return tags;
155
+ }
156
+
data/ext/phid.i ADDED
@@ -0,0 +1,9 @@
1
+ %module phid
2
+
3
+ %{
4
+ #include <phidget21.h>
5
+ #include <phid.h>
6
+ %}
7
+
8
+ %include <phid.h>
9
+
data/ext/phid.so ADDED
Binary file