Toma de foto y descomprimir en HEX

Dependencies:   JPEGCamera SDFileSystem mbed

Fork of SaibiCansat2014 by Takashi SASAKI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SDFileSystem.h"
00003 #include "FastJpegCamera.h"
00004 #include<stdio.h>
00005 #include<string.h> 
00006 #include<iostream>
00007 #include<fstream>
00008 #include<errno.h>
00009 
00010 SDFileSystem sd(p5, p6, p7, p8, "sd");
00011 
00012 Serial pc(USBTX, USBRX);
00013 Serial xbee(p13,p14);
00014 Timer timer;
00015 DigitalOut h(LED3);
00016 DigitalOut t(LED4);
00017 #define archivof "/sd/pic%05d.jpg"
00018 using namespace std;
00019 int m=0;
00020 void send_image(int i){
00021 
00022    FILE *picture;
00023    FILE *respaldo=NULL;
00024    int size, read_size, packet_index;
00025    char send_buffer[10240];
00026    packet_index = 1;
00027    char file[32];
00028    sprintf(file, archivof, i); 
00029    picture = fopen(file, "r");
00030    printf("Getting Picture Size\n");   
00031     
00032     //PAra el respaldoç
00033      respaldo = fopen("/sd/respaldo.txt", "w");  
00034    if(picture == NULL) {
00035         printf("Error Opening Image File"); } 
00036 
00037    fseek(picture, 0, SEEK_END);
00038    size = ftell(picture);
00039    fseek(picture, 0, SEEK_SET);
00040    printf("Total Picture size: %i\n",size);
00041 
00042    //Send Picture Size
00043    printf("Sending Picture Size\n");
00044    fprintf(respaldo, "1. %d,\n\r",size);
00045 
00046    //Send Picture as Byte Array
00047    printf("Sending Picture as Byte Array\n");
00048 
00049    int t=2;
00050    while(!feof(picture)) {
00051    //while(packet_index = 1){
00052       //Read from the file into our send buffer
00053       read_size = fread(send_buffer, 1, sizeof(send_buffer)-1, picture);
00054 
00055       //Send data through our socket 
00056 
00057        fprintf(respaldo,"%d. ",t);  //checar
00058       while(m<read_size)
00059       {
00060           fprintf(respaldo,"%02hhx   ",send_buffer[m]);
00061           m++;
00062         }
00063         fprintf(respaldo,",%d,\n",read_size);
00064         m=0;
00065 
00066       printf("Packet Number: %i\n",packet_index);
00067       printf("Packet Size Sent: %i\n",read_size);     
00068       printf(" \n");
00069       printf(" \n");
00070 
00071 
00072       packet_index++;  
00073         t++;
00074       
00075      }
00076      fclose(respaldo);
00077      fclose(picture);
00078 }
00079 
00080 
00081 int loop_count;
00082 
00083 int main() {
00084     timer.start();
00085     pc.printf("main() started. pc.baud is 9600 at this time.");
00086     xbee.baud(115200);
00087     h = 1;
00088  
00089 
00090     FastJpegCamera fast_jpeg_camera(p9, p10, xbee);
00091     while (1) { 
00092        loop_count += 1;
00093        h=0; 
00094        t=1;
00095        pc.printf("%f\n\r",timer.read());
00096        timer.reset();
00097        fast_jpeg_camera.shoot(loop_count);
00098        h=1;
00099        t=0;
00100        send_image(loop_count);
00101         }
00102 }