QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
krobertson
Date:
Sun Apr 20 08:04:37 2014 +0000
Revision:
18:e72ee7aed088
Parent:
16:4f5d20b87dc3
Child:
20:81d5655fecc2
new communication module. Need to add open and close connection to sync packet and end packet but otherwise looks like it will 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 16:4f5d20b87dc3 22 //DH::Locs().getC().getLat()=40.006145f;
dylanembed123 16:4f5d20b87dc3 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;
krobertson 18:e72ee7aed088 27 getPS().openConnection();
dylanembed123 15:e3e03a9df89e 28 getPS().sendPacket(0,NULL,0,PT_EMPTY);
dylanembed123 15:e3e03a9df89e 29 getPS().sendPacket(sID,NULL,0,PT_IMAGEHEAD);
dylanembed123 15:e3e03a9df89e 30 getPS().sendPacket(sID,(char*)(&DH::Locs().getC().getLoc()),sizeof(DataLocation));
dylanembed123 15:e3e03a9df89e 31 getPS().sendPacket(sID,NULL,0,PT_END);
krobertson 18:e72ee7aed088 32 getPS().closeConnection();
dylanembed123 15:e3e03a9df89e 33
dylanembed123 15:e3e03a9df89e 34 // Send image
dylanembed123 15:e3e03a9df89e 35 sID=getPS().getSuperID();
krobertson 18:e72ee7aed088 36 getPS().openConnection();
dylanembed123 14:6be57da62283 37 getPS().sendPacket(0,NULL,0,PT_EMPTY);
dylanembed123 12:e42985e3ea64 38 getPS().sendPacket(sID,NULL,0,PT_IMAGE);
dylanembed123 7:c75d5e5e6bfc 39 int size=cam.frameLength();
dylanembed123 15:e3e03a9df89e 40 outputDevice.printf("Image Start %d %d\n",size,sizeof(PacketStruct));
dylanembed123 7:c75d5e5e6bfc 41 int i;
dylanembed123 13:a6d3cf2b018e 42 char backBuffer[PACKETSIZE];
dylanembed123 13:a6d3cf2b018e 43 int bloc=0;
dylanembed123 7:c75d5e5e6bfc 44 for(i=0;i<size;){
dylanembed123 7:c75d5e5e6bfc 45 // read 32 bytes at a time;
dylanembed123 9:da906eeac51e 46 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 47 uint8_t bytesRead=0;
dylanembed123 12:e42985e3ea64 48 char* buffer = (char*)cam.readPicture(bytesToRead,&bytesRead);
dylanembed123 13:a6d3cf2b018e 49 for(int a=0;a<bytesRead;a++){
dylanembed123 13:a6d3cf2b018e 50 if(bloc==PACKETSIZE){
dylanembed123 13:a6d3cf2b018e 51 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 13:a6d3cf2b018e 52 bloc=0;
dylanembed123 13:a6d3cf2b018e 53 }
dylanembed123 13:a6d3cf2b018e 54 backBuffer[bloc++]=buffer[a];
dylanembed123 13:a6d3cf2b018e 55 }
dylanembed123 13:a6d3cf2b018e 56 //getPS().sendPacket(sID,buffer,bytesRead);
dylanembed123 12:e42985e3ea64 57 //for(int a=0;a<bytesRead;a++){outputDevice.putc(buffer[a]);}
dylanembed123 7:c75d5e5e6bfc 58 i+=bytesRead;
dylanembed123 7:c75d5e5e6bfc 59 }
dylanembed123 13:a6d3cf2b018e 60 getPS().sendPacket(sID,backBuffer,bloc);
dylanembed123 12:e42985e3ea64 61 outputDevice.printf("Image End\n",size);
dylanembed123 12:e42985e3ea64 62 getPS().sendPacket(sID,NULL,0,PT_END);
krobertson 18:e72ee7aed088 63 getPS().closeConnection();
dylanembed123 14:6be57da62283 64 cam.resumeVideo();
dylanembed123 7:c75d5e5e6bfc 65 }
dylanembed123 7:c75d5e5e6bfc 66
dylanembed123 7:c75d5e5e6bfc 67 bool ImageHandle::check(){
dylanembed123 7:c75d5e5e6bfc 68 return true;
dylanembed123 7:c75d5e5e6bfc 69 }
dylanembed123 7:c75d5e5e6bfc 70
dylanembed123 7:c75d5e5e6bfc 71 void ImageHandle::run(){
dylanembed123 7:c75d5e5e6bfc 72 if(!initialized){
dylanembed123 7:c75d5e5e6bfc 73 initialized=true;
dylanembed123 12:e42985e3ea64 74 outputDevice.printf("Setup cam\n");
dylanembed123 7:c75d5e5e6bfc 75 setup();
dylanembed123 7:c75d5e5e6bfc 76 }
dylanembed123 7:c75d5e5e6bfc 77 if(check()){
dylanembed123 7:c75d5e5e6bfc 78 take();
dylanembed123 14:6be57da62283 79 wait(2);
dylanembed123 14:6be57da62283 80 //while(true){}
dylanembed123 7:c75d5e5e6bfc 81 }
dylanembed123 7:c75d5e5e6bfc 82 }