QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
dylanembed123
Date:
Thu Apr 10 05:38:45 2014 +0000
Revision:
15:e3e03a9df89e
Parent:
14:6be57da62283
Child:
16:4f5d20b87dc3
Demo prep - The GPS, camera and XBEE stream with packet work.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stearnsc 8:28b866df62cf 1 #include "handleCamera.h"
dylanembed123 7:c75d5e5e6bfc 2
dylanembed123 7:c75d5e5e6bfc 3 void ImageHandle::setup(){
dylanembed123 12:e42985e3ea64 4 char* version = cam.getVersion();
dylanembed123 12:e42985e3ea64 5 outputDevice.printf("Version %s\n",version);
dylanembed123 14:6be57da62283 6 uint8_t targetSize=VC0706_320x240;//640x480;
dylanembed123 13:a6d3cf2b018e 7 // 320x240
dylanembed123 13:a6d3cf2b018e 8 //VC0706_640x480;//VC0706_160x120;
dylanembed123 7:c75d5e5e6bfc 9 cam.setImageSize(targetSize);
dylanembed123 7:c75d5e5e6bfc 10 uint8_t realSize=cam.getImageSize();
dylanembed123 7:c75d5e5e6bfc 11 }
dylanembed123 7:c75d5e5e6bfc 12
dylanembed123 7:c75d5e5e6bfc 13 void ImageHandle::take(){
dylanembed123 7:c75d5e5e6bfc 14 if (! cam.takePicture()) {
dylanembed123 12:e42985e3ea64 15 outputDevice.printf("Failed to snap!\n");
dylanembed123 7:c75d5e5e6bfc 16 while(1){}
dylanembed123 7:c75d5e5e6bfc 17 }
dylanembed123 15:e3e03a9df89e 18 unsigned int sID;
dylanembed123 15:e3e03a9df89e 19
dylanembed123 15:e3e03a9df89e 20 // Send location
dylanembed123 15:e3e03a9df89e 21 sID=getPS().getSuperID();
dylanembed123 15:e3e03a9df89e 22 DH::Locs().getC().getLat()=40.006145f;
dylanembed123 15:e3e03a9df89e 23 DH::Locs().getC().getLon()=-105.262173;
dylanembed123 15:e3e03a9df89e 24 DH::Locs().getC().getAlt()=5;
dylanembed123 15:e3e03a9df89e 25 DH::Locs().getC().getHeading()=5;
dylanembed123 15:e3e03a9df89e 26 DH::Locs().getC().getTilt()=5;
dylanembed123 15:e3e03a9df89e 27 getPS().sendPacket(0,NULL,0,PT_EMPTY);
dylanembed123 15:e3e03a9df89e 28 getPS().sendPacket(sID,NULL,0,PT_IMAGEHEAD);
dylanembed123 15:e3e03a9df89e 29 getPS().sendPacket(sID,(char*)(&DH::Locs().getC().getLoc()),sizeof(DataLocation));
dylanembed123 15:e3e03a9df89e 30 getPS().sendPacket(sID,NULL,0,PT_END);
dylanembed123 15:e3e03a9df89e 31
dylanembed123 15:e3e03a9df89e 32 // Send image
dylanembed123 15:e3e03a9df89e 33 sID=getPS().getSuperID();
dylanembed123 14:6be57da62283 34 getPS().sendPacket(0,NULL,0,PT_EMPTY);
dylanembed123 12:e42985e3ea64 35 getPS().sendPacket(sID,NULL,0,PT_IMAGE);
dylanembed123 7:c75d5e5e6bfc 36 int size=cam.frameLength();
dylanembed123 15:e3e03a9df89e 37 outputDevice.printf("Image Start %d %d\n",size,sizeof(PacketStruct));
dylanembed123 7:c75d5e5e6bfc 38 int i;
dylanembed123 13:a6d3cf2b018e 39 char backBuffer[PACKETSIZE];
dylanembed123 13:a6d3cf2b018e 40 int bloc=0;
dylanembed123 7:c75d5e5e6bfc 41 for(i=0;i<size;){
dylanembed123 7:c75d5e5e6bfc 42 // read 32 bytes at a time;
dylanembed123 9:da906eeac51e 43 uint8_t bytesToRead = std::min(64, size-i); // change 32 to 64 for a speedup but may not work with all setups!
dylanembed123 7:c75d5e5e6bfc 44 uint8_t bytesRead=0;
dylanembed123 12:e42985e3ea64 45 char* buffer = (char*)cam.readPicture(bytesToRead,&bytesRead);
dylanembed123 13:a6d3cf2b018e 46 for(int a=0;a<bytesRead;a++){
dylanembed123 13:a6d3cf2b018e 47 if(bloc==PACKETSIZE){
dylanembed123 13:a6d3cf2b018e 48 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 13:a6d3cf2b018e 49 bloc=0;
dylanembed123 13:a6d3cf2b018e 50 }
dylanembed123 13:a6d3cf2b018e 51 backBuffer[bloc++]=buffer[a];
dylanembed123 13:a6d3cf2b018e 52 }
dylanembed123 13:a6d3cf2b018e 53 //getPS().sendPacket(sID,buffer,bytesRead);
dylanembed123 12:e42985e3ea64 54 //for(int a=0;a<bytesRead;a++){outputDevice.putc(buffer[a]);}
dylanembed123 7:c75d5e5e6bfc 55 i+=bytesRead;
dylanembed123 7:c75d5e5e6bfc 56 }
dylanembed123 13:a6d3cf2b018e 57 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 12:e42985e3ea64 58 outputDevice.printf("Image End\n",size);
dylanembed123 12:e42985e3ea64 59 getPS().sendPacket(sID,NULL,0,PT_END);
dylanembed123 14:6be57da62283 60 cam.resumeVideo();
dylanembed123 7:c75d5e5e6bfc 61 }
dylanembed123 7:c75d5e5e6bfc 62
dylanembed123 7:c75d5e5e6bfc 63 bool ImageHandle::check(){
dylanembed123 7:c75d5e5e6bfc 64 return true;
dylanembed123 7:c75d5e5e6bfc 65 }
dylanembed123 7:c75d5e5e6bfc 66
dylanembed123 7:c75d5e5e6bfc 67 void ImageHandle::run(){
dylanembed123 7:c75d5e5e6bfc 68 if(!initialized){
dylanembed123 7:c75d5e5e6bfc 69 initialized=true;
dylanembed123 12:e42985e3ea64 70 outputDevice.printf("Setup cam\n");
dylanembed123 7:c75d5e5e6bfc 71 setup();
dylanembed123 7:c75d5e5e6bfc 72 }
dylanembed123 7:c75d5e5e6bfc 73 if(check()){
dylanembed123 7:c75d5e5e6bfc 74 take();
dylanembed123 14:6be57da62283 75 wait(2);
dylanembed123 14:6be57da62283 76 //while(true){}
dylanembed123 7:c75d5e5e6bfc 77 }
dylanembed123 7:c75d5e5e6bfc 78 }