Toma de foto y descomprimir en HEX
Dependencies: JPEGCamera SDFileSystem mbed
Fork of SaibiCansat2014 by
main.cpp
- Committer:
- SolManB
- Date:
- 2015-11-10
- Revision:
- 14:f97c682b6fe5
- Parent:
- 13:aa50109c4cae
File content as of revision 14:f97c682b6fe5:
#include "mbed.h" #include "SDFileSystem.h" #include "FastJpegCamera.h" #include<stdio.h> #include<string.h> #include<iostream> #include<fstream> #include<errno.h> SDFileSystem sd(p5, p6, p7, p8, "sd"); Serial pc(USBTX, USBRX); Serial xbee(p13,p14); Timer timer; DigitalOut h(LED3); DigitalOut t(LED4); #define archivof "/sd/pic%05d.jpg" using namespace std; int m=0; void send_image(int i){ FILE *picture; FILE *respaldo=NULL; int size, read_size, packet_index; char send_buffer[10240]; packet_index = 1; char file[32]; sprintf(file, archivof, i); picture = fopen(file, "r"); printf("Getting Picture Size\n"); //PAra el respaldoç respaldo = fopen("/sd/respaldo.txt", "w"); if(picture == NULL) { printf("Error Opening Image File"); } fseek(picture, 0, SEEK_END); size = ftell(picture); fseek(picture, 0, SEEK_SET); printf("Total Picture size: %i\n",size); //Send Picture Size printf("Sending Picture Size\n"); fprintf(respaldo, "1. %d,\n\r",size); //Send Picture as Byte Array printf("Sending Picture as Byte Array\n"); int t=2; while(!feof(picture)) { //while(packet_index = 1){ //Read from the file into our send buffer read_size = fread(send_buffer, 1, sizeof(send_buffer)-1, picture); //Send data through our socket fprintf(respaldo,"%d. ",t); //checar while(m<read_size) { fprintf(respaldo,"%02hhx ",send_buffer[m]); m++; } fprintf(respaldo,",%d,\n",read_size); m=0; printf("Packet Number: %i\n",packet_index); printf("Packet Size Sent: %i\n",read_size); printf(" \n"); printf(" \n"); packet_index++; t++; } fclose(respaldo); fclose(picture); } int loop_count; int main() { timer.start(); pc.printf("main() started. pc.baud is 9600 at this time."); xbee.baud(115200); h = 1; FastJpegCamera fast_jpeg_camera(p9, p10, xbee); while (1) { loop_count += 1; h=0; t=1; pc.printf("%f\n\r",timer.read()); timer.reset(); fast_jpeg_camera.shoot(loop_count); h=1; t=0; send_image(loop_count); } }