CSE477 / swimate_v2

Dependencies:   Adafruit_GFX_128x64 DS3231 PinDetect SDFileSystem USBDevice mbed RealtimeMath MODSERIAL

Revision:
22:9350752f5414
Parent:
21:2fa676f214fe
Parent:
18:06b718f8e6fd
Child:
23:80083138d609
--- a/sync.cpp	Sat Jun 07 07:12:25 2014 +0000
+++ b/sync.cpp	Sat Jun 07 07:46:38 2014 +0000
@@ -76,6 +76,12 @@
 {
     PC_PRINTLNF("sendFile: Trying to open file %s", filename.c_str());
     FILE *fp = fopen(filename.c_str(), "r");
+    if (fp == NULL) {
+        PC_PRINTLNF("sendFile: Error opening file %s", filename.c_str());
+        return false;
+    }
+
+    uint8_t *d = new uint8_t[PACKET_MAX_DATA];
     
     if (fp == NULL) {
         PC_PRINTLNF("sendFile: Error opening file %s", filename.c_str());
@@ -115,9 +121,11 @@
     PC_PRINTLN("sendFile: created buffer");
     int len;
     int numPackets = 0;
+
     while ( (len = fread(d, 1, PACKET_MAX_DATA, fp) ) > 0 ) {
         PC_PRINTLNF("sendFile: packet number: %d ", numPackets);
         PC_PRINTLNF("length: %d", len);
+        PC_PRINTLNF("sendFile: sending packet of length %d", len);
 
         Packet *p = Packet::create(CMD_SYNCOLDEST, 0x00, len, d);
         PC_PRINTLNF("sendFile: packet checksum = %x", p->checkSum);
@@ -156,6 +164,7 @@
 
     PC_PRINTLNF("sendFile: done sending %s in ", filename.c_str());
     PC_PRINTLNF("%d packets.", numPackets);
+    PC_PRINTLNF("sendFile: done sending %s", filename.c_str());
     // Appears to be a bug where feof isn't defined, so no error checking :(
 //    if (!feof(fp)) {
 //        PC_PRINTLNF("sendFile: Error reading file %s", absolute_filename.c_str());
@@ -250,6 +259,7 @@
     while(State == SYNC) {
         PC_PRINTLN("Waiting for packet...")
         Packet *p; 
+
         int ret = btComm.receivePacket(&p, TIMEOUT);
         if (ret == 0) {
             PC_PRINTLN("Timeout!");
@@ -267,6 +277,7 @@
             PC_PRINTLNF("%x", p->data[i]);
         }
         PC_PRINTLNF("check: %x", p->checkSum);
+
         switch(p->cmd) {
             case CMD_SYNCOLDEST:
                 if (!syncOldestSession())