Changeset 642 for BAORadio/libindi/libindi/drivers/ccd/ccd_simulator.cpp
- Timestamp:
- Feb 24, 2012, 12:37:36 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BAORadio/libindi/libindi/drivers/ccd/ccd_simulator.cpp
r504 r642 2 2 Copyright(c) 2010 Gerry Rozema. All rights reserved. 3 3 4 This program is free software; you can redistribute it and/or modify it 5 under the terms of the GNU General Public License as published by the Free 6 Software Foundation; either version 2 of the License, or (at your option) 7 any later version. 8 9 This program is distributed in the hope that it will be useful, but WITHOUT 10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program; if not, write to the Free Software Foundation, Inc., 59 16 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 The full GNU General Public License is included in this distribution in the 19 file called LICENSE. 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License version 2 as published by the Free Software Foundation. 7 . 8 This library is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 Library General Public License for more details. 12 . 13 You should have received a copy of the GNU Library General Public License 14 along with this library; see the file COPYING.LIB. If not, write to 15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 Boston, MA 02110-1301, USA. 20 17 *******************************************************************************/ 21 18 #include "ccd_simulator.h" … … 84 81 void ISSnoopDevice (XMLEle *root) 85 82 { 86 INDI_UNUSED(root); 83 ISInit(); 84 ccdsim->ISSnoopDevice(root); 87 85 } 88 86 … … 125 123 TimeFactor=1; 126 124 125 SimulatorSettingsNV = new INumberVectorProperty; 126 TimeFactorSV = new ISwitchVectorProperty; 127 127 128 } 128 129 129 130 bool CCDSim::SetupParms() 130 131 { 132 int nbuf; 131 133 SetCCDParams(SimulatorSettingsN[0].value,SimulatorSettingsN[1].value,16,SimulatorSettingsN[2].value,SimulatorSettingsN[3].value); 132 134 // Kwiq … … 141 143 seeing=SimulatorSettingsN[9].value; // we get real fat stars in this one 142 144 143 144 if(RawFrame != NULL) delete RawFrame; 145 RawFrameSize=XRes*YRes; // this is pixel count 146 RawFrameSize=RawFrameSize*2; // Each pixel is 2 bytes 147 RawFrameSize+=512; // leave a little extra at the end 148 RawFrame=new char[RawFrameSize]; 145 nbuf = PrimaryCCD.getXRes() * PrimaryCCD.getYRes() * PrimaryCCD.getBPP(); 146 nbuf += 512; 147 PrimaryCCD.setFrameBufferSize(nbuf); 149 148 150 149 return true; … … 154 153 { 155 154 155 int nbuf; 156 156 SetupParms(); 157 157 158 if(HasGuideHead) { 158 if(HasGuideHead) 159 { 159 160 SetGuidHeadParams(500,290,8,9.8,12.6); 160 RawGuideSize=GXRes*GYRes; // this is pixel count 161 RawGuideSize+=512; // leave a little extra at the end 162 RawGuiderFrame=new char[RawGuideSize]; 161 nbuf = GuideCCD.getXRes() * GuideCCD.getYRes(); 162 GuideCCD.setFrameBufferSize(nbuf); 163 163 } 164 164 … … 174 174 const char * CCDSim::getDefaultName() 175 175 { 176 //fprintf(stderr,"Arrived in getDefaultName and deviceName returns '%s'\n",deviceName());177 //if(strlen(deviceName())==0) {178 176 return (char *)"CCD Simulator"; 179 //} else {180 // char n[500];181 // strcpy(n,deviceName());182 // return n;183 //}184 177 } 185 178 … … 190 183 INDI::CCD::initProperties(); 191 184 192 IUFillNumber(&EqN[0],"RA","Ra (hh:mm:ss)","%010.6m",0,24,0,0); 193 IUFillNumber(&EqN[1],"DEC","Dec (dd:mm:ss)","%010.6m",-90,90,0,0); 194 IUFillNumberVector(&EqNV,EqN,2,"","EQUATORIAL_EOD_COORD","Eq. Coordinates","Main Control",IP_RW,60,IPS_IDLE); 195 //IUFillNumberVector(&EqNV,EqN,2,deviceName(),"EQUATORIAL_EOD_COORD","Eq. Coordinates","Main Control",IP_RW,60,IPS_IDLE); 196 197 SimulatorSettingsNV = new INumberVectorProperty; 198 IUFillNumber(&SimulatorSettingsN[0],"SIM_XRES","CCD X resolution","%4.0f",0,2048,0,1280); 199 IUFillNumber(&SimulatorSettingsN[1],"SIM_YRES","CCD Y resolution","%4.0f",0,2048,0,1024); 185 IUFillNumber(&SimulatorSettingsN[0],"SIM_PrimarCCD.getXRes()","CCD X resolution","%4.0f",0,2048,0,1280); 186 IUFillNumber(&SimulatorSettingsN[1],"SIM_PrimarCCD.getYRes()","CCD Y resolution","%4.0f",0,2048,0,1024); 200 187 IUFillNumber(&SimulatorSettingsN[2],"SIM_XSIZE","CCD X Pixel Size","%4.2f",0,60,0,5.2); 201 188 IUFillNumber(&SimulatorSettingsN[3],"SIM_YSIZE","CCD Y Pixel Size","%4.2f",0,60,0,5.2); … … 209 196 IUFillNumber(&SimulatorSettingsN[11],"SIM_SKYGLOW","Sky Glow (magnitudes)","%4.1f",0,6000,0,19.5); 210 197 IUFillNumber(&SimulatorSettingsN[12],"SIM_OAGOFFSET","Oag Offset (arminutes)","%4.1f",0,6000,0,0); 211 IUFillNumberVector(SimulatorSettingsNV,SimulatorSettingsN,13,deviceName(),"SIMULATOR_SETTINGS","Simulator Settings","SimSettings",IP_RW,60,IPS_IDLE); 212 213 214 TelescopeTV = new ITextVectorProperty; 215 IUFillText(&TelescopeT[0],"ACTIVE_TELESCOPE","Telescope",""); 216 IUFillTextVector(TelescopeTV,TelescopeT,1,deviceName(),"ACTIVE_DEVICES","Snoop Scope","Simulator Config",IP_RW,60,IPS_IDLE); 217 218 TimeFactorSV = new ISwitchVectorProperty; 198 IUFillNumberVector(SimulatorSettingsNV,SimulatorSettingsN,13,deviceName(),"SIMULATOR_SETTINGS","Simulator Settings","Simulator Config",IP_RW,60,IPS_IDLE); 199 219 200 220 201 IUFillSwitch(&TimeFactorS[0],"1X","Actual Time",ISS_ON); … … 224 205 225 206 226 loadConfig();207 //loadConfig(); 227 208 228 209 return true; … … 238 219 defineNumber(SimulatorSettingsNV); 239 220 defineSwitch(TimeFactorSV); 240 defineText(TelescopeTV);241 221 //IDDefText(&ConfigFileTV, NULL); 242 222 //IDDefSwitch(&ConfigSaveRestoreSV, NULL); … … 257 237 bool CCDSim::Disconnect() 258 238 { 259 delete RawFrame;260 RawFrameSize=0;261 RawFrame=NULL;262 263 264 if(RawGuiderFrame != NULL) {265 delete RawGuiderFrame;266 RawGuideSize=0;267 }268 269 239 return true; 270 240 } … … 335 305 float timeleft; 336 306 timeleft=CalcTimeLeft(ExpStart,ExposureRequest); 307 308 if (timeleft < 0) 309 timeleft = 0; 310 311 PrimaryCCD.setExposure(timeleft); 312 //ImageExposureN[0].value = timeleft; 313 //IDSetNumber(ImageExposureNP, NULL); 314 337 315 if(timeleft < 1.0) 338 316 { … … 347 325 } 348 326 } 327 349 328 if(InGuideExposure) 350 329 { 351 330 float timeleft; 352 331 timeleft=CalcTimeLeft(GuideExpStart,GuideExposureRequest); 332 333 334 if (timeleft < 0) 335 timeleft = 0; 336 337 //ImageExposureN[0].value = timeleft; 338 //IDSetNumber(ImageExposureNP, NULL); 339 GuideCCD.setExposure(timeleft); 340 353 341 if(timeleft < 1.0) 354 342 { … … 390 378 unsigned short int val; 391 379 392 ptr=(unsigned short int *)RawFrame; 393 394 if(ShowStarField) { 380 ptr=(unsigned short int *) PrimaryCCD.getFrameBuffer(); 381 382 if(ShowStarField) 383 { 395 384 char gsccmd[250]; 396 385 FILE *pp; … … 423 412 424 413 // Start by clearing the frame buffer 425 memset( RawFrame,0,RawFrameSize);414 memset(PrimaryCCD.getFrameBuffer(),0,PrimaryCCD.getFrameBufferSize()); 426 415 427 416 … … 439 428 // no offset or rotation for and y axis means 440 429 pb=0.0; 441 pc= XRes/2/BinX;430 pc=PrimaryCCD.getXRes()/2/PrimaryCCD.getBinX(); 442 431 pd=0.0; 443 pf= YRes/2/BinY;432 pf=PrimaryCCD.getYRes()/2/PrimaryCCD.getBinY(); 444 433 // and we do a simple scale for x and y locations 445 434 // based on the focal length and pixel size 446 435 // focal length in mm, pixels in microns 447 pa=focallength/P ixelSizex*1000/BinX;448 pe=focallength/P ixelSizey*1000/BinY;436 pa=focallength/PrimaryCCD.getPixelSizeX()*1000/PrimaryCCD.getBinX(); 437 pe=focallength/PrimaryCCD.getPixelSizeY()*1000/PrimaryCCD.getBinY(); 449 438 450 439 //IDLog("Pixels are %4.2f %4.2f pa %6.4f pe %6.4f\n",PixelSizex,PixelSizey,pa,pe); … … 478 467 float radius; 479 468 480 radius=sqrt((Scalex*Scalex* XRes/2.0*XRes/2.0)+(Scaley*Scaley*YRes/2.0*YRes/2.0));469 radius=sqrt((Scalex*Scalex*PrimaryCCD.getXRes()/2.0*PrimaryCCD.getXRes()/2.0)+(Scaley*Scaley*PrimaryCCD.getYRes()/2.0*PrimaryCCD.getYRes()/2.0)); 481 470 // we have radius in arcseconds now 482 471 radius=radius/60; // convert to arcminutes … … 505 494 506 495 // if this is a light frame, we need a star field drawn 507 if( FrameType==FRAME_TYPE_LIGHT)496 if(PrimaryCCD.getFrameType()==CCDChip::LIGHT_FRAME) 508 497 { 509 498 //sprintf(gsccmd,"gsc -c %8.6f %+8.6f -r 120 -m 0 9.1",rad+PEOffset,Dec); … … 593 582 // fwhm equivalent to the full field of view 594 583 595 if((FrameType==FRAME_TYPE_LIGHT)||(FrameType==FRAME_TYPE_FLAT)) 584 CCDChip::CCD_FRAME ftype = PrimaryCCD.getFrameType(); 585 586 if((ftype==CCDChip::LIGHT_FRAME)||(ftype==CCDChip::FLAT_FRAME)) 596 587 { 597 588 float skyflux; … … 599 590 // calculate flux from our zero point and gain values 600 591 glow=skyglow; 601 if( FrameType==FRAME_TYPE_FLAT)592 if(ftype==CCDChip::FLAT_FRAME) 602 593 { 603 594 // Assume flats are done with a diffuser … … 610 601 // ok, flux represents one second now 611 602 // scale up linearly for exposure time 612 skyflux=skyflux*ExposureRequest* BinX*BinY;603 skyflux=skyflux*ExposureRequest*PrimaryCCD.getBinX()*PrimaryCCD.getBinY(); 613 604 //IDLog("SkyFlux = %4.2f ExposureRequest %4.2f\n",skyflux,ExposureRequest); 614 605 615 606 unsigned short *pt; 616 pt=(unsigned short int *)RawFrame; 617 for(int y=0; y<YRes/BinY; y++) { 618 for(int x=0; x<XRes/BinX; x++) { 607 608 int nwidth = PrimaryCCD.getXRes()/PrimaryCCD.getBinX(); 609 int nheight = PrimaryCCD.getYRes()/PrimaryCCD.getBinY(); 610 pt=(unsigned short int *)PrimaryCCD.getFrameBuffer(); 611 for(int y=0; y< nheight; y++) { 612 for(int x=0; x< nwidth; x++) { 619 613 float dc; // distance from center 620 614 float fp; // flux this pixel; … … 622 616 float vig; 623 617 624 sx= XRes/2/BinX;618 sx=PrimaryCCD.getXRes()/2/PrimaryCCD.getBinX(); 625 619 sx=sx-x; 626 sy= YRes/2/BinY;620 sy=PrimaryCCD.getYRes()/2/PrimaryCCD.getBinY(); 627 621 sy=sy-y; 628 622 629 vig= XRes/BinX;623 vig=PrimaryCCD.getXRes()/PrimaryCCD.getBinX(); 630 624 vig=vig*ImageScalex; 631 625 // need to make this account for actual pixel size … … 654 648 655 649 // Now we add some bias and read noise 656 for(x=0; x< XRes; x++) {657 for(y=0; y< YRes; y++) {650 for(x=0; x<PrimaryCCD.getXRes(); x++) { 651 for(y=0; y<PrimaryCCD.getYRes(); y++) { 658 652 int noise; 659 653 … … 671 665 val=testvalue; 672 666 673 for(int x=0; x<XRes*YRes; x++) 667 int nbuf = PrimaryCCD.getXRes()*PrimaryCCD.getYRes(); 668 669 for(int x=0; x<nbuf; x++) 674 670 { 675 671 *ptr=val++; … … 686 682 unsigned char val; 687 683 688 ptr=(unsigned char *) RawGuiderFrame;684 ptr=(unsigned char *) GuideCCD.getFrameBuffer(); 689 685 testvalue++; 690 686 if(testvalue > 255) testvalue=0; 691 687 val=testvalue; 692 688 693 for(int x=0; x<GXRes*GYRes; x++) { 689 int nbuf = GuideCCD.getXRes()*GuideCCD.getYRes(); 690 for(int x=0; x< nbuf; x++) 691 { 694 692 *ptr=val++; 695 693 ptr++; … … 708 706 float flux; 709 707 710 if((x<0)||(x> XRes/BinX)||(y<0)||(y>YRes/BinY))708 if((x<0)||(x>PrimaryCCD.getXRes()/PrimaryCCD.getBinX())||(y<0)||(y>PrimaryCCD.getYRes()/PrimaryCCD.getBinY())) 711 709 { 712 710 // this star is not on the ccd frame anyways … … 750 748 float fa; 751 749 fa=exp(-2.0*0.7*(dc*dc)/seeing/seeing); 752 fp=fa*flux* BinX*BinY;750 fp=fa*flux*PrimaryCCD.getBinX()*PrimaryCCD.getBinY(); 753 751 if(fp < 0) fp=0; 754 752 … … 773 771 int drew=0; 774 772 if(x >= 0) { 775 if(x < XRes/BinX) {773 if(x < PrimaryCCD.getXRes()/PrimaryCCD.getBinX()) { 776 774 if(y >= 0) { 777 if(y < YRes/BinY) {775 if(y < PrimaryCCD.getYRes()/PrimaryCCD.getBinY()) { 778 776 unsigned short *pt; 779 777 int newval; 780 778 drew++; 781 pt=(unsigned short int *) RawFrame;782 pt+=(y* XRes/BinX);779 pt=(unsigned short int *)PrimaryCCD.getFrameBuffer(); 780 pt+=(y*PrimaryCCD.getXRes()/PrimaryCCD.getBinX()); 783 781 pt+=x; 784 782 newval=pt[0]; … … 793 791 } 794 792 795 intCCDSim::GuideNorth(float v)793 bool CCDSim::GuideNorth(float v) 796 794 { 797 795 float c; … … 801 799 Dec=Dec+c; 802 800 803 return 0;804 } 805 intCCDSim::GuideSouth(float v)801 return true; 802 } 803 bool CCDSim::GuideSouth(float v) 806 804 { 807 805 float c; … … 811 809 Dec=Dec-c; 812 810 813 return 0;814 } 815 816 intCCDSim::GuideEast(float v)811 return true; 812 } 813 814 bool CCDSim::GuideEast(float v) 817 815 { 818 816 float c; … … 823 821 RA=RA-c; 824 822 825 return 0;826 } 827 intCCDSim::GuideWest(float v)823 return true; 824 } 825 bool CCDSim::GuideWest(float v) 828 826 { 829 827 float c; … … 834 832 RA=RA+c; 835 833 836 return 0; 837 } 838 839 void CCDSim::ISSnoopDevice (XMLEle *root) 840 { 841 //fprintf(stderr,"CCDSim handling snoop\n"); 842 if(IUSnoopNumber(root,&EqNV)==0) { 843 float newra,newdec; 844 newra=EqN[0].value; 845 newdec=EqN[1].value; 846 if((newra != RA)||(newdec != Dec)) { 847 //fprintf(stderr,"RA %4.2f Dec %4.2f Snooped RA %4.2f Dec %4.2f\n",RA,Dec,newra,newdec); 848 RA=newra; 849 Dec=newdec; 850 851 } 852 } else { 853 //fprintf(stderr,"Snoop Failed\n"); 854 } 855 } 834 return true; 835 } 856 836 857 837 bool CCDSim::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) … … 859 839 // first check if it's for our device 860 840 //IDLog("INDI::CCD::ISNewNumber %s\n",name); 861 if(strcmp(dev,deviceName())==0) { 841 if(strcmp(dev,deviceName())==0) 842 { 862 843 // This is for our device 863 844 // Now lets see if it's something we process here … … 899 880 return INDI::CCD::ISNewNumber(dev,name,values,names,n); 900 881 } 901 bool CCDSim::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)902 {903 // Ok, lets see if this is a property wer process904 //IDLog("IndiTelescope got %d new text items name %s\n",n,name);905 // first check if it's for our device906 if(strcmp(dev,deviceName())==0) {907 // This is for our device908 // Now lets see if it's something we process here909 if(strcmp(name,TelescopeTV->name)==0) {910 int rc;911 //IDLog("calling update text\n");912 TelescopeTV->s=IPS_OK;913 rc=IUUpdateText(TelescopeTV,texts,names,n);914 //IDLog("update text returns %d\n",rc);915 // Update client display916 IDSetText(TelescopeTV,NULL);917 saveConfig();918 IUFillNumberVector(&EqNV,EqN,2,TelescopeT[0].text,"EQUATORIAL_EOD_COORD","Eq. Coordinates","Main Control",IP_RW,60,IPS_IDLE);919 IDSnoopDevice(TelescopeT[0].text,"EQUATORIAL_EOD_COORD");920 // We processed this one, so, tell the world we did it921 return true;922 }923 924 }925 926 return INDI::DefaultDriver::ISNewText(dev,name,texts,names,n);927 }928 882 929 883
Note: See TracChangeset
for help on using the changeset viewer.