Cybersecurity Project / Mbed 2 deprecated sd_duplicator

Dependencies:   mbed-rtos mbed wolfSSL

Fork of sd_duplicator by Titi Asrat

main.cpp

Committer:
jlharper
Date:
2016-11-29
Revision:
1:7827a11dc627
Parent:
0:b453be3137c7
Child:
2:166e98bcd1cc

File content as of revision 1:7827a11dc627:

#include "mbed.h"
#include "SDBlock.h"
#include "Crypto.h"

DigitalOut led1(LED1);

int main() 
{   
    SDBlock original(p5, p6, p7, p22);
    SDBlock duplicate(p11, p12, p13, p21);   
    const int x = original.disk_initialize();
    const int z = duplicate.disk_initialize();
    printf("************\n");
    printf("%d\n", x);
    printf("%d\n", z);
    const int y = original.disk_status();
    printf("%d\n", y);
    //s is sector 
    const uint32_t s = original.disk_sectors();
    printf("secotr size %d\n", s);
    uint8_t buffer[512];
    printf("buffer %d\n", buffer);
    const uint32_t block = 0;
    //start time
    time_t time_start = time(NULL);
    for (int i = 0; i <= s; ++i)
    {
        const int r = original.disk_read(buffer, i, 1);
        if (r !=0)
        {
            printf("%d\n", r);
        }   
        const int rd2 = original.disk_write(buffer, i, 1);
        if (rd2 != 0)
        {
           printf("%d\n", rd2);
        }
        if(i % 100 == 0)
        {
            //status update
           double percentage = (i/s) * 100;
            printf("percent copied: %d\n", percentage);
            //time elapsed
            time_t time_current = time(NULL);
            int time_working = time_start - time_current;
            double speed = (i * 512) / time_working;
            
            printf("speed (bytes/s): %d\n", speed);
        }
    }
    printf("finished");
    
   // printf("%d\n", r);
    //printf("%d\n", buffer);
    
    //printf("%d\n", rd2);
    //const int w = 
}