Ignore:
Timestamp:
Feb 24, 2012, 12:37:36 PM (12 years ago)
Author:
frichard
Message:

-Alignement des antennes
-Version 0.0.9 de libindi

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BAORadio/libindi/libindi/drivers/ccd/ccd_simulator.cpp

    r504 r642  
    22  Copyright(c) 2010 Gerry Rozema. All rights reserved.
    33
    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.
    2017*******************************************************************************/
    2118#include "ccd_simulator.h"
     
    8481void ISSnoopDevice (XMLEle *root)
    8582{
    86     INDI_UNUSED(root);
     83    ISInit();
     84    ccdsim->ISSnoopDevice(root);
    8785}
    8886
     
    125123    TimeFactor=1;
    126124
     125    SimulatorSettingsNV = new INumberVectorProperty;
     126    TimeFactorSV = new ISwitchVectorProperty;
     127
    127128}
    128129
    129130bool CCDSim::SetupParms()
    130131{
     132    int nbuf;
    131133    SetCCDParams(SimulatorSettingsN[0].value,SimulatorSettingsN[1].value,16,SimulatorSettingsN[2].value,SimulatorSettingsN[3].value);
    132134    //  Kwiq
     
    141143    seeing=SimulatorSettingsN[9].value;        //  we get real fat stars in this one
    142144
    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);
    149148
    150149    return true;
     
    154153{
    155154
     155    int nbuf;
    156156    SetupParms();
    157157
    158     if(HasGuideHead) {
     158    if(HasGuideHead)
     159    {
    159160        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);
    163163    }
    164164
     
    174174const char * CCDSim::getDefaultName()
    175175{
    176     //fprintf(stderr,"Arrived in getDefaultName and deviceName returns '%s'\n",deviceName());
    177     //if(strlen(deviceName())==0) {
    178176        return (char *)"CCD Simulator";
    179     //} else {
    180     //    char n[500];
    181     //    strcpy(n,deviceName());
    182     //    return n;
    183     //}
    184177}
    185178
     
    190183    INDI::CCD::initProperties();
    191184
    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);
    200187    IUFillNumber(&SimulatorSettingsN[2],"SIM_XSIZE","CCD X Pixel Size","%4.2f",0,60,0,5.2);
    201188    IUFillNumber(&SimulatorSettingsN[3],"SIM_YSIZE","CCD Y Pixel Size","%4.2f",0,60,0,5.2);
     
    209196    IUFillNumber(&SimulatorSettingsN[11],"SIM_SKYGLOW","Sky Glow (magnitudes)","%4.1f",0,6000,0,19.5);
    210197    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
    219200
    220201    IUFillSwitch(&TimeFactorS[0],"1X","Actual Time",ISS_ON);
     
    224205
    225206
    226     loadConfig();
     207    //loadConfig();
    227208
    228209    return true;
     
    238219    defineNumber(SimulatorSettingsNV);
    239220    defineSwitch(TimeFactorSV);
    240     defineText(TelescopeTV);
    241221    //IDDefText(&ConfigFileTV, NULL);
    242222    //IDDefSwitch(&ConfigSaveRestoreSV, NULL);
     
    257237bool CCDSim::Disconnect()
    258238{
    259     delete RawFrame;
    260     RawFrameSize=0;
    261     RawFrame=NULL;
    262 
    263 
    264     if(RawGuiderFrame != NULL) {
    265         delete RawGuiderFrame;
    266         RawGuideSize=0;
    267     }
    268 
    269239    return true;
    270240}
     
    335305        float timeleft;
    336306        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
    337315        if(timeleft < 1.0)
    338316        {
     
    347325        }
    348326    }
     327
    349328    if(InGuideExposure)
    350329    {
    351330        float timeleft;
    352331        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
    353341        if(timeleft < 1.0)
    354342        {
     
    390378    unsigned short int val;
    391379
    392     ptr=(unsigned short int *)RawFrame;
    393 
    394     if(ShowStarField) {
     380    ptr=(unsigned short int *) PrimaryCCD.getFrameBuffer();
     381
     382    if(ShowStarField)
     383    {
    395384        char gsccmd[250];
    396385        FILE *pp;
     
    423412
    424413        //  Start by clearing the frame buffer
    425         memset(RawFrame,0,RawFrameSize);
     414        memset(PrimaryCCD.getFrameBuffer(),0,PrimaryCCD.getFrameBufferSize());
    426415
    427416
     
    439428        //  no offset or rotation for and y axis means
    440429        pb=0.0;
    441         pc=XRes/2/BinX;
     430        pc=PrimaryCCD.getXRes()/2/PrimaryCCD.getBinX();
    442431        pd=0.0;
    443         pf=YRes/2/BinY;
     432        pf=PrimaryCCD.getYRes()/2/PrimaryCCD.getBinY();
    444433        //  and we do a simple scale for x and y locations
    445434        //  based on the focal length and pixel size
    446435        //  focal length in mm, pixels in microns
    447         pa=focallength/PixelSizex*1000/BinX;
    448         pe=focallength/PixelSizey*1000/BinY;
     436        pa=focallength/PrimaryCCD.getPixelSizeX()*1000/PrimaryCCD.getBinX();
     437        pe=focallength/PrimaryCCD.getPixelSizeY()*1000/PrimaryCCD.getBinY();
    449438
    450439        //IDLog("Pixels are %4.2f %4.2f  pa %6.4f  pe %6.4f\n",PixelSizex,PixelSizey,pa,pe);
     
    478467        float radius;
    479468
    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));
    481470        //  we have radius in arcseconds now
    482471        radius=radius/60;   //  convert to arcminutes
     
    505494
    506495        //  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)
    508497        {
    509498            //sprintf(gsccmd,"gsc -c %8.6f %+8.6f -r 120 -m 0 9.1",rad+PEOffset,Dec);
     
    593582        //  fwhm equivalent to the full field of view
    594583
    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))
    596587        {
    597588            float skyflux;
     
    599590            //  calculate flux from our zero point and gain values
    600591            glow=skyglow;
    601             if(FrameType==FRAME_TYPE_FLAT)
     592            if(ftype==CCDChip::FLAT_FRAME)
    602593            {
    603594                //  Assume flats are done with a diffuser
     
    610601            //  ok, flux represents one second now
    611602            //  scale up linearly for exposure time
    612             skyflux=skyflux*ExposureRequest*BinX*BinY;
     603            skyflux=skyflux*ExposureRequest*PrimaryCCD.getBinX()*PrimaryCCD.getBinY();
    613604            //IDLog("SkyFlux = %4.2f ExposureRequest %4.2f\n",skyflux,ExposureRequest);
    614605
    615606            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++) {
    619613                    float dc;   //  distance from center
    620614                    float fp;   //  flux this pixel;
     
    622616                    float vig;
    623617
    624                     sx=XRes/2/BinX;
     618                    sx=PrimaryCCD.getXRes()/2/PrimaryCCD.getBinX();
    625619                    sx=sx-x;
    626                     sy=YRes/2/BinY;
     620                    sy=PrimaryCCD.getYRes()/2/PrimaryCCD.getBinY();
    627621                    sy=sy-y;
    628622
    629                     vig=XRes/BinX;
     623                    vig=PrimaryCCD.getXRes()/PrimaryCCD.getBinX();
    630624                    vig=vig*ImageScalex;
    631625                    //  need to make this account for actual pixel size
     
    654648
    655649        //  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++) {
    658652                int noise;
    659653
     
    671665        val=testvalue;
    672666
    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++)
    674670        {
    675671            *ptr=val++;
     
    686682    unsigned char val;
    687683
    688     ptr=(unsigned char *)RawGuiderFrame;
     684    ptr=(unsigned char *) GuideCCD.getFrameBuffer();
    689685    testvalue++;
    690686    if(testvalue > 255) testvalue=0;
    691687    val=testvalue;
    692688
    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    {
    694692        *ptr=val++;
    695693        ptr++;
     
    708706    float flux;
    709707
    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()))
    711709    {
    712710        //  this star is not on the ccd frame anyways
     
    750748            float fa;
    751749            fa=exp(-2.0*0.7*(dc*dc)/seeing/seeing);
    752             fp=fa*flux*BinX*BinY;
     750            fp=fa*flux*PrimaryCCD.getBinX()*PrimaryCCD.getBinY();
    753751            if(fp < 0) fp=0;
    754752
     
    773771    int drew=0;
    774772    if(x >= 0) {
    775         if(x < XRes/BinX) {
     773        if(x < PrimaryCCD.getXRes()/PrimaryCCD.getBinX()) {
    776774            if(y >= 0) {
    777                 if(y < YRes/BinY) {
     775                if(y < PrimaryCCD.getYRes()/PrimaryCCD.getBinY()) {
    778776                    unsigned short *pt;
    779777                    int newval;
    780778                    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());
    783781                    pt+=x;
    784782                    newval=pt[0];
     
    793791}
    794792
    795 int CCDSim::GuideNorth(float v)
     793bool CCDSim::GuideNorth(float v)
    796794{
    797795    float c;
     
    801799    Dec=Dec+c;
    802800
    803     return 0;
    804 }
    805 int CCDSim::GuideSouth(float v)
     801    return true;
     802}
     803bool CCDSim::GuideSouth(float v)
    806804{
    807805    float c;
     
    811809    Dec=Dec-c;
    812810
    813     return 0;
    814 }
    815 
    816 int CCDSim::GuideEast(float v)
     811    return true;
     812}
     813
     814bool CCDSim::GuideEast(float v)
    817815{
    818816    float c;
     
    823821    RA=RA-c;
    824822
    825     return 0;
    826 }
    827 int CCDSim::GuideWest(float v)
     823    return true;
     824}
     825bool CCDSim::GuideWest(float v)
    828826{
    829827    float c;
     
    834832    RA=RA+c;
    835833
    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}
    856836
    857837bool CCDSim::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
     
    859839    //  first check if it's for our device
    860840    //IDLog("INDI::CCD::ISNewNumber %s\n",name);
    861     if(strcmp(dev,deviceName())==0) {
     841    if(strcmp(dev,deviceName())==0)
     842    {
    862843        //  This is for our device
    863844        //  Now lets see if it's something we process here
     
    899880    return INDI::CCD::ISNewNumber(dev,name,values,names,n);
    900881}
    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 process
    904     //IDLog("IndiTelescope got %d new text items name %s\n",n,name);
    905     //  first check if it's for our device
    906     if(strcmp(dev,deviceName())==0) {
    907         //  This is for our device
    908         //  Now lets see if it's something we process here
    909         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 display
    916             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 it
    921             return true;
    922         }
    923 
    924     }
    925 
    926     return INDI::DefaultDriver::ISNewText(dev,name,texts,names,n);
    927 }
    928882
    929883
Note: See TracChangeset for help on using the changeset viewer.