Пример #1
0
/**
 * Download image from FireFly
 */
void FFMVCCD::grabImage()
{
   dc1394error_t err;
   dc1394video_frame_t *frame;
   uint32_t uheight, uwidth;
   int sub;
   uint16_t val;
   struct timeval start, end;

   // Let's get a pointer to the frame buffer
   uint8_t * image = PrimaryCCD.getFrameBuffer();

   // Get width and height
   int width = PrimaryCCD.getSubW() / PrimaryCCD.getBinX();
   int height = PrimaryCCD.getSubH() / PrimaryCCD.getBinY();

   memset(image, 0, PrimaryCCD.getFrameBufferSize());


   /*-----------------------------------------------------------------------
    *  stop data transmission
    *-----------------------------------------------------------------------*/


   gettimeofday(&start, NULL);
   for (sub = 0; sub < sub_count; ++sub) {
       IDMessage(getDeviceName(), "Getting sub %d of %d", sub, sub_count);
       err=dc1394_capture_dequeue(dcam, DC1394_CAPTURE_POLICY_WAIT, &frame);
       if (err != DC1394_SUCCESS) {
              IDMessage(getDeviceName(), "Could not capture frame");
       }
       dc1394_get_image_size_from_video_mode(dcam,DC1394_VIDEO_MODE_640x480_MONO16, &uwidth, &uheight);

       if (DC1394_TRUE == dc1394_capture_is_frame_corrupt(dcam, frame)) {
              IDMessage(getDeviceName(), "Corrupt frame!");
              continue;
       }
       // Fill buffer with random pattern
       for (int i=0; i < height ; i++) {
           for (int j=0; j < width; j++) {
               /* Detect unsigned overflow */
               val = ((uint16_t *) image)[i*width+j] + ntohs(((uint16_t*) (frame->image))[i*width+j]);
               if (val > ((uint16_t *) image)[i*width+j]) {
                   ((uint16_t *) image)[i*width+j] = val;
               } else {
                   ((uint16_t *) image)[i*width+j] = 0xFFFF;
               }
           }
       }

       dc1394_capture_enqueue(dcam, frame);
   }
   err=dc1394_video_set_transmission(dcam,DC1394_OFF);
   IDMessage(getDeviceName(), "Download complete.");
   gettimeofday(&end, NULL);
   IDMessage(getDeviceName(), "Download took %d uS", (int) ((end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec)));

   // Let INDI::CCD know we're done filling the image buffer
   ExposureComplete(&PrimaryCCD);
}
Пример #2
0
/* Downloads the image from the CCD. */
int MICCD::grabImage()
{
    unsigned char *image = (unsigned char *) PrimaryCCD.getFrameBuffer();

    if (isSimulation())
    {
        int height = PrimaryCCD.getSubH() / PrimaryCCD.getBinY();
        int width  = PrimaryCCD.getSubW() / PrimaryCCD.getBinX();

        uint16_t *buffer = (uint16_t *) image;

        for (int i = 0; i < height; i++)
          for (int j = 0; j < width; j++)
            buffer[i * width + j] = rand() % UINT16_MAX;
    }
    else
    {
        int ret = 0;
        if (gxccd_read_image(cameraHandle, image, PrimaryCCD.getFrameBufferSize()) < 0)
        {
            char errorStr[MAX_ERROR_LEN];
            gxccd_get_last_error(cameraHandle, errorStr, sizeof(errorStr));
            DEBUGF(INDI::Logger::DBG_ERROR, "Error getting image: %s.", errorStr);
        }
    }

    if (ExposureRequest > POLLMS * 5)
      DEBUG(INDI::Logger::DBG_SESSION, "Download complete.");

    downloading = false;
    ExposureComplete(&PrimaryCCD);

    return 0;
}
Пример #3
0
/* Downloads the image from the CCD. */
int QHYCCD::grabImage()
{  
  if (sim)
  {
      unsigned char * image = (unsigned char *) PrimaryCCD.getFrameBuffer();
      int width = PrimaryCCD.getSubW() / PrimaryCCD.getBinX() * PrimaryCCD.getBPP() / 8;
      int height = PrimaryCCD.getSubH() / PrimaryCCD.getBinY();

      for (int i = 0; i < height; i++)
          for (int j = 0; j < width; j++)
              image[i * width + j] = rand() % 255;
  } 
  else
  {

    uint32_t ret, w,h,bpp,channels;

    ret = GetQHYCCDSingleFrame(camhandle,&w,&h,&bpp,&channels,PrimaryCCD.getFrameBuffer());

    if (ret != QHYCCD_SUCCESS)
        DEBUGF(INDI::Logger::DBG_ERROR, "GetQHYCCDSingleFrame error (%d)", ret);
  }

  // Perform software binning if necessary
  //PrimaryCCD.binFrame();

  DEBUG(INDI::Logger::DBG_DEBUG, "Download complete.");
  if (ExposureRequest > POLLMS * 5)
      DEBUG(INDI::Logger::DBG_SESSION, "Download complete.");

  ExposureComplete(&PrimaryCCD);

  return 0;
}
Пример #4
0
/* Downloads the image from the CCD.
 N.B. No processing is done on the image */
int QSICCD::grabImage()
{
        unsigned short* image = (unsigned short *) PrimaryCCD.getFrameBuffer();

        int x,y,z;
        try {
            bool imageReady = false;
            QSICam.get_ImageReady(&imageReady);
            while(!imageReady)
            {
                usleep(500);
                QSICam.get_ImageReady(&imageReady);
            }

            QSICam.get_ImageArraySize(x,y,z);
            QSICam.get_ImageArray(image);
            imageBuffer = image;
            imageWidth  = x;
            imageHeight = y;
        } catch (std::runtime_error err)
        {
            DEBUGF(INDI::Logger::DBG_ERROR, "get_ImageArray() failed. %s.", err.what());
            return -1;
        }

        DEBUG(INDI::Logger::DBG_SESSION, "Download complete.");
	
        ExposureComplete(&PrimaryCCD);

	return 0;
}
Пример #5
0
/////////////////////////////////////////////////////////
/// Download from CCD
/////////////////////////////////////////////////////////
bool ATIKCCD::grabImage()
{
    //uint8_t *image = PrimaryCCD.getFrameBuffer();
    int x, y, w, h, binx, biny;

    int rc = ArtemisGetImageData(hCam, &x, &y, &w, &h, &binx, &biny);
    if (rc != ARTEMIS_OK)
        return false;

    int bufferSize = w * binx * h * biny * PrimaryCCD.getBPP() / 8;
    if ( bufferSize < PrimaryCCD.getFrameBufferSize())
    {
        LOGF_WARN("Image size is unexpected. Expecting %d bytes but received %d bytes.", PrimaryCCD.getFrameBufferSize(), bufferSize);
        PrimaryCCD.setFrameBufferSize(bufferSize, false);
    }

    std::unique_lock<std::mutex> guard(ccdBufferLock);
    PrimaryCCD.setFrameBuffer(reinterpret_cast<uint8_t*>(ArtemisImageBuffer(hCam)));
    guard.unlock();

    if (ExposureRequest > VERBOSE_EXPOSURE)
        LOG_INFO("Download complete.");

    ExposureComplete(&PrimaryCCD);
    return true;
}
Пример #6
0
/* Downloads the image from the CCD.*/
int FishCampCCD::grabImage()
{
    std::unique_lock<std::mutex> guard(ccdBufferLock);
    uint8_t *image = PrimaryCCD.getFrameBuffer();
    UInt16 *frameBuffer = (UInt16 *)image;
    int numBytes = fcUsb_cmd_getRawFrame(cameraNum, PrimaryCCD.getSubW(), PrimaryCCD.getSubH(), frameBuffer);
    guard.unlock();
    if(numBytes != 0)
    {
        LOG_INFO("Download complete.");
        ExposureComplete(&PrimaryCCD);
        return 0;
    }
    else
    {
        LOG_INFO("Download error. Please check the log for details.");
        ExposureComplete(&PrimaryCCD);  //This should be an error. It is not complete, it messed up!
        return -1;
    }

}
Пример #7
0
/* Downloads the image from the CCD.*/
int FishCampCCD::grabImage()
{
    uint8_t *image = PrimaryCCD.getFrameBuffer();

    UInt16 *frameBuffer = (UInt16 *)image;
    fcUsb_cmd_getRawFrame(cameraNum, PrimaryCCD.getSubW(), PrimaryCCD.getSubH(), frameBuffer);
    DEBUG(INDI::Logger::DBG_SESSION, "Download complete.");

    ExposureComplete(&PrimaryCCD);

    return 0;
}
Пример #8
0
/* Downloads the image from the CCD. */
int MICCD::grabImage()
{
    std::unique_lock<std::mutex> guard(ccdBufferLock);
    int ret              = 0;
    unsigned char *image = (unsigned char *)PrimaryCCD.getFrameBuffer();
    int width  = PrimaryCCD.getSubW() / PrimaryCCD.getBinX();
    int height = PrimaryCCD.getSubH() / PrimaryCCD.getBinY();

    if (isSimulation())
    {
        uint16_t *buffer = (uint16_t *)image;

        for (int i = 0; i < height; i++)
            for (int j = 0; j < width; j++)
                buffer[i * width + j] = rand() % UINT16_MAX;
    }
    else
    {
        ret = gxccd_read_image(cameraHandle, image, PrimaryCCD.getFrameBufferSize());
        if (ret < 0)
        {
            char errorStr[MAX_ERROR_LEN];
            gxccd_get_last_error(cameraHandle, errorStr, sizeof(errorStr));
            LOGF_ERROR("Error getting image: %s.", errorStr);
        }
        else
        {
            mirror_image(image, width, height);
        }
    }

    guard.unlock();

    if (ExposureRequest > POLLMS * 5 && !ret)
        LOG_INFO("Download complete.");

    downloading = false;
    ExposureComplete(&PrimaryCCD);

    return ret;
}
Пример #9
0
void DSICCD::grabImage()
{
   int sub;
   uint16_t val;
   struct timeval start, end;
   int rc;
   uint16_t *buf;
   int x, y;

   // Let's get a pointer to the frame buffer
   uint8_t * image = PrimaryCCD.getFrameBuffer();

   // Get width and height
   int width = PrimaryCCD.getSubW() / PrimaryCCD.getBinX();
   int height = PrimaryCCD.getSubH() / PrimaryCCD.getBinY();

   try {
       buf = (uint16_t *) dsi->ccdFramebuffer();
   } catch (...) {
       DEBUG(INDI::Logger::DBG_SESSION,  "Image download failed!");
       return;
   }

   for (y = 0; y < height; ++y) {
        for (x = 0; x < width; ++x) {
            ((uint16_t *) image)[x + width * y] = ntohs(buf[x + width * y]);
        }
   }
   
   delete buf;

   // Let INDI::CCD know we're done filling the image buffer
   ExposureComplete(&PrimaryCCD);

   DEBUG(INDI::Logger::DBG_SESSION, "Exposure complete.");
}
Пример #10
0
bool GPhotoCCD::grabImage()
{
    //char ext[16];
    uint8_t *memptr = PrimaryCCD.getFrameBuffer();
	size_t memsize;
    int fd, naxis=2, w, h, bpp=8;

    if (sim)
    {

      w= PrimaryCCD.getXRes();
      h= PrimaryCCD.getYRes();
      size_t fullbuf_size = w*h + 512;
      uint8_t * fullbuf = (uint8_t *) malloc(fullbuf_size);
      for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
          fullbuf[i * w + j] = rand() % 255;

      // Starting address if subframing
      memptr = fullbuf + (PrimaryCCD.getSubY() * PrimaryCCD.getXRes()) + PrimaryCCD.getSubX();
      memsize = PrimaryCCD.getSubW() * PrimaryCCD.getSubH() * PrimaryCCD.getBPP()/8;

      PrimaryCCD.setFrameBuffer(memptr);
      PrimaryCCD.setFrameBufferSize(memsize, false);
      //PrimaryCCD.setResolution(w, h);
      //PrimaryCCD.setFrame(0, 0, w, h);
      PrimaryCCD.setNAxis(naxis);
      PrimaryCCD.setBPP(bpp);

      ExposureComplete(&PrimaryCCD);
      return true;

    }

    // If only save to SD Card, let's not upload back to client
    /*if (UploadS[GP_UPLOAD_SDCARD].s == ISS_ON)
    {
        DEBUG(INDI::Logger::DBG_SESSION, "Exposure complete. Image saved to SD Card.");
        ExposureComplete(&PrimaryCCD);
        return true;
    }*/


    if (transferFormatS[0].s == ISS_ON)
    {
	    
        char tmpfile[] = "/tmp/indi_XXXXXX";

        //dcraw can't read from stdin, so we need to write to disk then read it back
        fd = mkstemp(tmpfile);

        int ret = gphoto_read_exposure_fd(gphotodrv, fd);

        if (ret != GP_OK || fd == -1)
        {
            if (fd == -1)
                DEBUGF(INDI::Logger::DBG_ERROR, "Exposure failed to save image. Cannot create temp file %s", tmpfile);
            else
                DEBUGF(INDI::Logger::DBG_ERROR, "Exposure failed to save image... %s", gp_result_as_string(ret));
            unlink(tmpfile);
            return false;
        }

        if (!strcmp(gphoto_get_file_extension(gphotodrv), "unknown"))
        {
                DEBUG(INDI::Logger::DBG_ERROR, "Exposure failed.");
                return false;
        }

        /* We're done exposing */
        DEBUG(INDI::Logger::DBG_SESSION, "Exposure done, downloading image...");
    
    
        if(strcasecmp(gphoto_get_file_extension(gphotodrv), "jpg") == 0 ||
           strcasecmp(gphoto_get_file_extension(gphotodrv), "jpeg") == 0)
        {
                if (read_jpeg(tmpfile, &memptr, &memsize, &naxis, &w, &h))
                {
                    DEBUG(INDI::Logger::DBG_ERROR, "Exposure failed to parse jpeg.");
                    unlink(tmpfile);
                    return false;
                }

                DEBUGF(INDI::Logger::DBG_DEBUG, "read_jpeg: memsize (%d) naxis (%d) w (%d) h (%d) bpp (%d)", memsize, naxis, w, h, bpp);
        }
        else
        {
                if (read_dcraw(tmpfile, &memptr, &memsize, &naxis, &w, &h, &bpp))
                {
                    DEBUG(INDI::Logger::DBG_ERROR, "Exposure failed to parse raw image.");
                    unlink(tmpfile);
                    return false;
                }
		
                DEBUGF(INDI::Logger::DBG_DEBUG, "read_dcraw: memsize (%d) naxis (%d) w (%d) h (%d) bpp (%d)", memsize, naxis, w, h, bpp);

                unlink(tmpfile);
        }

        PrimaryCCD.setImageExtension("fits");

        // If subframing is requested
        if (frameInitialized && (PrimaryCCD.getSubH() < PrimaryCCD.getYRes() || PrimaryCCD.getSubW() < PrimaryCCD.getXRes()))
        {
            int subFrameSize  = PrimaryCCD.getSubW() * PrimaryCCD.getSubH() * bpp/8 * ((naxis == 3) ? 3 : 1);
            int oneFrameSize  = PrimaryCCD.getSubW() * PrimaryCCD.getSubH() * bpp/8;
            uint8_t *subframeBuf = (uint8_t *) malloc(subFrameSize);

            int startY= PrimaryCCD.getSubY();
            int endY  = startY + PrimaryCCD.getSubH();
            int lineW = PrimaryCCD.getSubW() * bpp/8;
            int subX = PrimaryCCD.getSubX();

            if (naxis == 2)
            {
                for (int i=startY ; i < endY; i++)
                    memcpy(subframeBuf + (i - startY) * lineW, memptr + (i * w + subX) * bpp/8 , lineW);
            }
            else
            {
                uint8_t *subR = subframeBuf;
                uint8_t *subG = subframeBuf + oneFrameSize;
                uint8_t *subB = subframeBuf + oneFrameSize * 2;

                uint8_t *startR = memptr;
                uint8_t *startG = memptr + (w * h * bpp/8);
                uint8_t *startB = memptr + (w * h * bpp/8 * 2);

                for (int i=startY; i < endY; i++)
                {
                    memcpy(subR + (i-startY) * lineW, startR + (i * w + subX) * bpp/8 , lineW );
                    memcpy(subG + (i-startY) * lineW, startG + (i * w + subX) * bpp/8 , lineW );
                    memcpy(subB + (i-startY) * lineW, startB + (i * w + subX) * bpp/8 , lineW );
                }
            }

            PrimaryCCD.setFrameBuffer(subframeBuf);
            PrimaryCCD.setFrameBufferSize(subFrameSize, false);
            PrimaryCCD.setResolution(w, h);
            PrimaryCCD.setNAxis(naxis);
            PrimaryCCD.setBPP(bpp);

            ExposureComplete(&PrimaryCCD);

            // Restore old pointer and release memory
            PrimaryCCD.setFrameBuffer(memptr);
            PrimaryCCD.setFrameBufferSize(memsize, false);
            free(subframeBuf);
        }
        else
        {
            // We need to initially set the frame dimensions for the first time since it is unknown at the time of connection.
            frameInitialized = true;

            PrimaryCCD.setFrame(0, 0, w, h);
            PrimaryCCD.setFrameBuffer(memptr);
            PrimaryCCD.setFrameBufferSize(memsize, false);
            PrimaryCCD.setResolution(w, h);
            PrimaryCCD.setNAxis(naxis);
            PrimaryCCD.setBPP(bpp);

            ExposureComplete(&PrimaryCCD);
        }

    }
    else
    {        
        int rc = gphoto_read_exposure(gphotodrv);

        if (rc != 0)
        {
            DEBUG(INDI::Logger::DBG_ERROR, "Failed to expose.");
            return rc;
        }
	
        /* We're done exposing */
         DEBUG(INDI::Logger::DBG_DEBUG, "Exposure done, downloading image...");
         uint8_t *newMemptr = NULL;
         gphoto_get_buffer(gphotodrv, (const char **)&newMemptr, &memsize);
         memptr = (uint8_t *)realloc(memptr, memsize); // We copy the obtained memory pointer to avoid freeing some gphoto memory
         memcpy(memptr, newMemptr, memsize); //

         gphoto_get_dimensions(gphotodrv, &w, &h);

        PrimaryCCD.setImageExtension(gphoto_get_file_extension(gphotodrv));
        if (w > 0 && h > 0)
            PrimaryCCD.setFrame(0, 0, w, h);
        PrimaryCCD.setFrameBuffer(memptr);
        PrimaryCCD.setFrameBufferSize(memsize, false);
        if (w > 0 && h > 0)
            PrimaryCCD.setResolution(w, h);
        PrimaryCCD.setNAxis(naxis);
        PrimaryCCD.setBPP(bpp);

        ExposureComplete(&PrimaryCCD);
    }

    return true;
}
Пример #11
0
void CCDSim::TimerHit()
{
    int nexttimer=1000;

    if(isConnected() == false) return;  //  No need to reset timer if we are not connected anymore

    if(InExposure)
    {
        if (AbortPrimaryFrame)
        {
            InExposure = false;
            AbortPrimaryFrame = false;
        }
        else
        {
            float timeleft;
            timeleft=CalcTimeLeft(ExpStart,ExposureRequest);

            //IDLog("CCD Exposure left: %g - Requset: %g\n", timeleft, ExposureRequest);
            if (timeleft < 0)
                 timeleft = 0;

            PrimaryCCD.setExposureLeft(timeleft);

            if(timeleft < 1.0)
            {
                if(timeleft <= 0.001)
                {
                    InExposure=false;
                    ExposureComplete(&PrimaryCCD);
                } else
                {
                    nexttimer=timeleft*1000;    //  set a shorter timer
                }
            }
        }
    }

    if(InGuideExposure)
    {
        float timeleft;
        timeleft=CalcTimeLeft(GuideExpStart,GuideExposureRequest);


        //IDLog("GUIDE Exposure left: %g - Requset: %g\n", timeleft, GuideExposureRequest);

        if (timeleft < 0)
             timeleft = 0;

        //ImageExposureN[0].value = timeleft;
        //IDSetNumber(ImageExposureNP, NULL);
        GuideCCD.setExposureLeft(timeleft);

        if(timeleft < 1.0)
        {
            if(timeleft <= 0.001)
            {
                InGuideExposure=false;
                if(!AbortGuideFrame)
                {
                    //IDLog("Sending guider frame\n");
                    ExposureComplete(&GuideCCD);
                    if(InGuideExposure)
                    {    //  the call to complete triggered another exposure
                        timeleft=CalcTimeLeft(GuideExpStart,GuideExposureRequest);
                        if(timeleft <1.0)
                        {
                            nexttimer=timeleft*1000;
                        }
                    }
                } else
                {
                    IDLog("Not sending guide frame cuz of abort\n");
                }
                AbortGuideFrame=false;
            } else
            {
                nexttimer=timeleft*1000;    //  set a shorter timer
            }
        }
    }
    SetTimer(nexttimer);
    return;
}