![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Toma de foto y descomprimir en HEX
Dependencies: JPEGCamera SDFileSystem mbed
Fork of SaibiCansat2014 by
main.cpp@14:f97c682b6fe5, 2015-11-10 (annotated)
- Committer:
- SolManB
- Date:
- Tue Nov 10 16:48:05 2015 +0000
- Revision:
- 14:f97c682b6fe5
- Parent:
- 13:aa50109c4cae
foto;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emanon | 0:e4ca6571a751 | 1 | #include "mbed.h" |
emanon | 0:e4ca6571a751 | 2 | #include "SDFileSystem.h" |
TakashiSasaki | 6:9824d4e2f29b | 3 | #include "FastJpegCamera.h" |
SolManB | 14:f97c682b6fe5 | 4 | #include<stdio.h> |
SolManB | 14:f97c682b6fe5 | 5 | #include<string.h> |
SolManB | 14:f97c682b6fe5 | 6 | #include<iostream> |
SolManB | 14:f97c682b6fe5 | 7 | #include<fstream> |
SolManB | 14:f97c682b6fe5 | 8 | #include<errno.h> |
TakashiSasaki | 6:9824d4e2f29b | 9 | |
emanon | 0:e4ca6571a751 | 10 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
emanon | 0:e4ca6571a751 | 11 | |
SolManB | 14:f97c682b6fe5 | 12 | Serial pc(USBTX, USBRX); |
SolManB | 14:f97c682b6fe5 | 13 | Serial xbee(p13,p14); |
SolManB | 14:f97c682b6fe5 | 14 | Timer timer; |
SolManB | 14:f97c682b6fe5 | 15 | DigitalOut h(LED3); |
SolManB | 14:f97c682b6fe5 | 16 | DigitalOut t(LED4); |
SolManB | 14:f97c682b6fe5 | 17 | #define archivof "/sd/pic%05d.jpg" |
SolManB | 14:f97c682b6fe5 | 18 | using namespace std; |
SolManB | 14:f97c682b6fe5 | 19 | int m=0; |
SolManB | 14:f97c682b6fe5 | 20 | void send_image(int i){ |
emanon | 0:e4ca6571a751 | 21 | |
SolManB | 14:f97c682b6fe5 | 22 | FILE *picture; |
SolManB | 14:f97c682b6fe5 | 23 | FILE *respaldo=NULL; |
SolManB | 14:f97c682b6fe5 | 24 | int size, read_size, packet_index; |
SolManB | 14:f97c682b6fe5 | 25 | char send_buffer[10240]; |
SolManB | 14:f97c682b6fe5 | 26 | packet_index = 1; |
SolManB | 14:f97c682b6fe5 | 27 | char file[32]; |
SolManB | 14:f97c682b6fe5 | 28 | sprintf(file, archivof, i); |
SolManB | 14:f97c682b6fe5 | 29 | picture = fopen(file, "r"); |
SolManB | 14:f97c682b6fe5 | 30 | printf("Getting Picture Size\n"); |
SolManB | 14:f97c682b6fe5 | 31 | |
SolManB | 14:f97c682b6fe5 | 32 | //PAra el respaldoç |
SolManB | 14:f97c682b6fe5 | 33 | respaldo = fopen("/sd/respaldo.txt", "w"); |
SolManB | 14:f97c682b6fe5 | 34 | if(picture == NULL) { |
SolManB | 14:f97c682b6fe5 | 35 | printf("Error Opening Image File"); } |
emanon | 0:e4ca6571a751 | 36 | |
SolManB | 14:f97c682b6fe5 | 37 | fseek(picture, 0, SEEK_END); |
SolManB | 14:f97c682b6fe5 | 38 | size = ftell(picture); |
SolManB | 14:f97c682b6fe5 | 39 | fseek(picture, 0, SEEK_SET); |
SolManB | 14:f97c682b6fe5 | 40 | printf("Total Picture size: %i\n",size); |
SolManB | 14:f97c682b6fe5 | 41 | |
SolManB | 14:f97c682b6fe5 | 42 | //Send Picture Size |
SolManB | 14:f97c682b6fe5 | 43 | printf("Sending Picture Size\n"); |
SolManB | 14:f97c682b6fe5 | 44 | fprintf(respaldo, "1. %d,\n\r",size); |
SolManB | 14:f97c682b6fe5 | 45 | |
SolManB | 14:f97c682b6fe5 | 46 | //Send Picture as Byte Array |
SolManB | 14:f97c682b6fe5 | 47 | printf("Sending Picture as Byte Array\n"); |
TakashiSasaki | 12:495d513bb022 | 48 | |
SolManB | 14:f97c682b6fe5 | 49 | int t=2; |
SolManB | 14:f97c682b6fe5 | 50 | while(!feof(picture)) { |
SolManB | 14:f97c682b6fe5 | 51 | //while(packet_index = 1){ |
SolManB | 14:f97c682b6fe5 | 52 | //Read from the file into our send buffer |
SolManB | 14:f97c682b6fe5 | 53 | read_size = fread(send_buffer, 1, sizeof(send_buffer)-1, picture); |
SolManB | 14:f97c682b6fe5 | 54 | |
SolManB | 14:f97c682b6fe5 | 55 | //Send data through our socket |
SolManB | 14:f97c682b6fe5 | 56 | |
SolManB | 14:f97c682b6fe5 | 57 | fprintf(respaldo,"%d. ",t); //checar |
SolManB | 14:f97c682b6fe5 | 58 | while(m<read_size) |
SolManB | 14:f97c682b6fe5 | 59 | { |
SolManB | 14:f97c682b6fe5 | 60 | fprintf(respaldo,"%02hhx ",send_buffer[m]); |
SolManB | 14:f97c682b6fe5 | 61 | m++; |
SolManB | 14:f97c682b6fe5 | 62 | } |
SolManB | 14:f97c682b6fe5 | 63 | fprintf(respaldo,",%d,\n",read_size); |
SolManB | 14:f97c682b6fe5 | 64 | m=0; |
SolManB | 14:f97c682b6fe5 | 65 | |
SolManB | 14:f97c682b6fe5 | 66 | printf("Packet Number: %i\n",packet_index); |
SolManB | 14:f97c682b6fe5 | 67 | printf("Packet Size Sent: %i\n",read_size); |
SolManB | 14:f97c682b6fe5 | 68 | printf(" \n"); |
SolManB | 14:f97c682b6fe5 | 69 | printf(" \n"); |
emanon | 1:31e810237ac1 | 70 | |
emanon | 1:31e810237ac1 | 71 | |
SolManB | 14:f97c682b6fe5 | 72 | packet_index++; |
SolManB | 14:f97c682b6fe5 | 73 | t++; |
SolManB | 14:f97c682b6fe5 | 74 | |
SolManB | 14:f97c682b6fe5 | 75 | } |
SolManB | 14:f97c682b6fe5 | 76 | fclose(respaldo); |
SolManB | 14:f97c682b6fe5 | 77 | fclose(picture); |
emanon | 0:e4ca6571a751 | 78 | } |
emanon | 0:e4ca6571a751 | 79 | |
emanon | 0:e4ca6571a751 | 80 | |
SolManB | 14:f97c682b6fe5 | 81 | int loop_count; |
SolManB | 14:f97c682b6fe5 | 82 | |
emanon | 0:e4ca6571a751 | 83 | int main() { |
TakashiSasaki | 12:495d513bb022 | 84 | timer.start(); |
TakashiSasaki | 6:9824d4e2f29b | 85 | pc.printf("main() started. pc.baud is 9600 at this time."); |
TakashiSasaki | 9:3a2d25f4700b | 86 | xbee.baud(115200); |
SolManB | 14:f97c682b6fe5 | 87 | h = 1; |
emanon | 0:e4ca6571a751 | 88 | |
emanon | 0:e4ca6571a751 | 89 | |
TakashiSasaki | 9:3a2d25f4700b | 90 | FastJpegCamera fast_jpeg_camera(p9, p10, xbee); |
emanon | 0:e4ca6571a751 | 91 | while (1) { |
SolManB | 14:f97c682b6fe5 | 92 | loop_count += 1; |
SolManB | 14:f97c682b6fe5 | 93 | h=0; |
SolManB | 14:f97c682b6fe5 | 94 | t=1; |
SolManB | 14:f97c682b6fe5 | 95 | pc.printf("%f\n\r",timer.read()); |
SolManB | 14:f97c682b6fe5 | 96 | timer.reset(); |
SolManB | 14:f97c682b6fe5 | 97 | fast_jpeg_camera.shoot(loop_count); |
SolManB | 14:f97c682b6fe5 | 98 | h=1; |
SolManB | 14:f97c682b6fe5 | 99 | t=0; |
SolManB | 14:f97c682b6fe5 | 100 | send_image(loop_count); |
SolManB | 14:f97c682b6fe5 | 101 | } |
emanon | 0:e4ca6571a751 | 102 | } |