RFID door access with security camera

Dependencies:   EthernetNetIf mbed Camera_LS_Y201 ID12RFID SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
dburnham6
Date:
Thu Oct 13 20:44:31 2011 +0000
Commit message:

Changed in this revision

Camera_LS_Y201.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
FATFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
ID12RFID.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5536e07364a7 Camera_LS_Y201.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201.lib	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/Camera_LS_Y201/#43358d40f879
diff -r 000000000000 -r 5536e07364a7 EthernetNetIf.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r 5536e07364a7 FATFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FATFileSystem.lib	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_unsupported/code/fatfilesystem/
\ No newline at end of file
diff -r 000000000000 -r 5536e07364a7 HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#d0be6af2d1db
diff -r 000000000000 -r 5536e07364a7 ID12RFID.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ID12RFID.lib	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/ID12RFID/#f04afa911cf5
diff -r 000000000000 -r 5536e07364a7 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SDFileSystem/#b1ddfc9a9b25
diff -r 000000000000 -r 5536e07364a7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,174 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPClient.h"
+#include "ID12RFID.h"
+#include "Camera_LS_Y201.h"
+#include "SDFileSystem.h"
+
+#define DEBMSG      printf
+#define NEWLINE()   printf("\r\n")
+
+#define FILENAME    "/local/%08d.jpg"
+LocalFileSystem fs("local");
+Camera_LS_Y201 cam1(p9, p10);
+
+typedef struct work {
+    FILE *fp;
+} work_t;
+work_t work;
+
+ID12RFID rfid(p14); // uart rx
+EthernetNetIf eth;
+HTTPClient http;
+DigitalOut myled(LED1);
+DigitalOut myled2(p20);
+DigitalOut door(p21);
+int tagNum;
+
+bool CheckTag(int tag){
+    HTTPText txt;
+    const char * txtBuffer;
+    char* bufferCopy;
+    char* line;
+    
+    // retrieve authorized tag numbers, CSV format
+    HTTPResult r = http.get("http://www.prism.gatech.edu/~dburnham6/tags.txt", &txt);
+    if(r==HTTP_OK){
+        txtBuffer = txt.gets();
+        bufferCopy = const_cast<char *> (txtBuffer); // allow parsing of the text
+        line = strtok(bufferCopy, ","); // separate by commas
+        while (line != NULL) {
+            if(atoi(line) == tag) {
+                return true;
+            }
+            line = strtok(NULL, ",");
+        }
+        
+        printf("Tag Not Found.\r\n"); 
+    }
+    else
+    {
+        printf("HTTP Error %d\n", r);
+    }
+    return false;
+}
+
+/** [from the Camera_LS_Y201 test code]
+ * Callback function for readJpegFileContent.
+ *
+ * @param buf A pointer to a buffer.
+ * @param siz A size of the buffer.
+ */
+void callback_func(int done, int total, uint8_t *buf, size_t siz) {
+    fwrite(buf, siz, 1, work.fp);
+
+    static int n = 0;
+    int tmp = done * 100 / total;
+    if (n != tmp) {
+        n = tmp;
+        DEBMSG("Writing...: %3d%%", n);
+        NEWLINE();
+    }
+}
+
+/** [from the Camera_LS_Y201 test code]
+ * Capture.
+ *
+ * @param cam A pointer to a camera object.
+ * @param filename The file name.
+ *
+ * @return Return 0 if it succeed.
+ */
+int capture(Camera_LS_Y201 *cam, char *filename) {
+    /*
+     * Take a picture.
+     */
+    if (cam->takePicture() != 0) {
+        return -1;
+    }
+    DEBMSG("Captured.");
+    NEWLINE();
+
+    /*
+     * Open file.
+     */
+    work.fp = fopen(filename, "wb");
+    if (work.fp == NULL) {
+        return -2;
+    }
+
+    /*
+     * Read the content.
+     */
+    DEBMSG("%s", filename);
+    NEWLINE();
+    if (cam->readJpegFileContent(callback_func) != 0) {
+        fclose(work.fp);
+        return -3;
+    }
+    fclose(work.fp);
+
+    /*
+     * Stop taking pictures.
+     */
+    cam->stopTakingPictures();
+
+    return 0;
+}
+
+int main() {
+    // init ethernet
+    EthernetErr ethErr = eth.setup();
+    if(ethErr)
+    {
+        printf("Error %d in setup.\n", ethErr);
+    }
+    printf("Setup OK\n");
+    
+    // init camera
+    DEBMSG("Camera module");
+    NEWLINE();
+    DEBMSG("Resetting...");
+    NEWLINE();
+    wait(1);
+    if (cam1.reset() == 0) {
+        DEBMSG("Reset OK.");
+        NEWLINE();
+    } else {
+        DEBMSG("Reset fail.");
+        NEWLINE();
+        error("Reset fail.");
+    }
+    wait(1);
+    
+    // wait for tag
+    while(1) {
+        if(rfid.readable()) {
+            int tag = rfid.read();
+            printf("RFID Tag number : %d\r\n", tag);
+            if(CheckTag(tag)) {
+                printf("Authorized user confirmed. Unlocking door...\r\n");
+                door = 1;
+                myled = 1;
+                wait(10);
+                door = 0;
+                myled = 0;
+            } else {
+                printf("Unauthorized access tag. Picture for evidence... \r\n");
+                myled2 = 1;
+                char fname[64];
+                snprintf(fname, sizeof(fname) - 1, FILENAME, tag);
+                int r = capture(&cam1, fname); // take a picture
+                if (r == 0) {
+                    DEBMSG("[%04d]:OK.", tag);
+                    NEWLINE();
+                } else {
+                    DEBMSG("[%04d]:NG. (code=%d)", tag, r);
+                    NEWLINE();
+                    error("Picture failed.");
+                }
+                myled2 = 0;
+            }
+        }
+    }
+}
diff -r 000000000000 -r 5536e07364a7 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 13 20:44:31 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912