QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
krobertson
Date:
Tue Apr 22 04:26:31 2014 +0000
Revision:
20:81d5655fecc2
Parent:
18:e72ee7aed088
Child:
62:31ed14d02627
send and receive commands.; waypoint processing; get locationions; send images

Who changed what in which revision?

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