Student project by David Berlin and Boris Dogadov made for the Embedded Systems Workshop course given in Tel-Aviv University on 2010 by Sivan Toledo. Visit the project website for more details: http://davidberlin.co.il/sadna/ .
Dependencies: EthernetNetIf NTPClient_NetServices mbed HTTPServer HTTPClient CyaSSL
Diff: main.cpp
- Revision:
- 1:b05231650f32
- Parent:
- 0:3e7d6f496a67
--- a/main.cpp Sun Apr 17 21:30:10 2011 +0000 +++ b/main.cpp Mon Apr 25 12:31:46 2011 +0000 @@ -1,6 +1,4 @@ /* -Copyright (c) 2010 Peter Barrett - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -26,19 +24,11 @@ #include "UsbStorage.h" #include "EthernetNetIf.h" -#include "HTTPClient.h" #include "Dropbox.h" #include "HTTPServer.h" +#include "HTTPServer.h" #include "HttpHandlerSetup.h" #include "HttpHandlerUsbBrowser.h" -#include "HTTPFileSender.h" -#include "base64.h" -#include "url.h" -#include "ctc_hmac.h" -#include "NTPClient.h" -#include "HTTPData.h" - -void test_dropbox(); // USB Serial pc(USBTX, USBRX); @@ -53,6 +43,7 @@ DigitalOut led2(LED2); DigitalOut led3(LED3); +// Occurs on usb flash disk connection int OnDiskInsert(int device) { printf("\r\nOnDiskInsert\r\n"); @@ -63,7 +54,7 @@ return 0; } - +// Setup ethernet connection bool setup_eth() { printf("\r\nSetting up...\r\n"); @@ -79,6 +70,7 @@ return true; } +// Setup HttpHandlers bool setup_httpServer(HTTPServer& svr) { svr.addHandler<HttpHandlerUsbBrowser>("/UsbBrowser"); @@ -90,14 +82,16 @@ return true; } +// Uploads a folder on usb flash-drive to dropbox bool upload_files(char* username, char* password) { - DIR *d = opendir("/usb/DROPBOX"); //TODO - global + DIR *d = opendir("/usb/DROPBOX"); int totalFiles = -1; + if (d) { char filenameSrc[64] = "/usb/DROPBOX/"; - char filenameDst[32] = "USBSYNC_"; //TODO - remove? + char filenameDst[32] = "USBSYNC_"; int c = 0; printf("Synchronize Start\n\r"); @@ -148,17 +142,17 @@ USBInit(); HTTPServer svr; - int i = 0; - + int i = 0; // loop counter led3 = 0; // clear error LED for (;;) { - if (i++ % 500000 == 0) printf("looping\r\n"); //TODO replace with time + if (i++ % 500000 == 0) printf("looping %d\r\n", time(NULL)); USBLoop(); - Net::poll(); + Net::poll(); + // Setup ethernet if (!ethSetup) { eth = new EthernetNetIf(); @@ -173,14 +167,15 @@ httpSetup = false; } + // Setup http-server if (ethSetup && !httpSetup) { - httpSetup = setup_httpServer(svr); - } - - // Cehck if Ethernet setup and USB-Disk connected + httpSetup = setup_httpServer(svr); + } + + // Check if Ethernet setup and USB-Disk connected if (usbDevice >= 0 && ethSetup) - { + { usbDevice = -1; led1 = 1; @@ -198,20 +193,30 @@ // Start synchronizing int totalFiles = upload_files(username, password); + if (totalFiles >= 0) + { + //send_email(username); + } + // Update the log file FILE* logFile = fopen("/usb/dbLog.txt", "a+"); if (logFile) { if (totalFiles >= 0) + { fprintf(logFile, "%d Synchronizing successfull %d files\r\n", time(NULL), totalFiles); + } else - fputs("Synchronizing failed\r\n", logFile); //TODO whats this? + { + fputs("Synchronizing failed\r\n", logFile); + } fclose(logFile); } led1 = 0; - ClearPortPower(); + + //ClearPortPower(); } } } \ No newline at end of file