示例#1
0
文件: gphoto_ccd.cpp 项目: A-j-K/indi
bool GPhotoCCD::capturePreview()
{

    if (sim)
        return false;

    int rc = GP_OK;
    char errMsg[MAXRBUF];
    const char* previewData;
    unsigned long int previewSize;

    CameraFile* previewFile = NULL;

    rc = gp_file_new(&previewFile);
    if (rc != GP_OK)
    {
       DEBUGF(INDI::Logger::DBG_ERROR, "Error creating gphoto file: %s", gp_result_as_string(rc));
      return false;
    }

    for (int i=0; i < MAX_RETRIES; i++)
    {
        rc = gphoto_capture_preview(gphotodrv, previewFile, errMsg);
        if (rc == true)
            break;
    }

    if (rc != GP_OK)
    {
        DEBUGF(INDI::Logger::DBG_ERROR, "%s", errMsg);
        return false;
    }

    if (rc >= GP_OK)
    {
       rc = gp_file_get_data_and_size(previewFile, &previewData, &previewSize);
       if (rc != GP_OK)
       {
           DEBUGF(INDI::Logger::DBG_ERROR, "Error getting preview image data and size: %s", gp_result_as_string(rc));
           return false;
       }
    }

    //DEBUGF(INDI::Logger::DBG_DEBUG, "Preview capture size %d bytes.", previewSize);

   char *previewBlob = (char *) previewData;

   imageB->blob = previewBlob;
   imageB->bloblen = previewSize;
   imageB->size = previewSize;
   strncpy(imageB->format, "stream_jpeg", MAXINDIBLOBFMT);

   IDSetBLOB (imageBP, NULL);

    if (previewFile)
    {
       gp_file_unref(previewFile);
       previewFile = NULL;
    }

    return true;
}
示例#2
0
bool INDI::CCD::ExposureComplete(CCDChip *targetChip)
{
    void *memptr;
    size_t memsize;
    int img_type=0;
    int byte_type=0;
    int status=0;
    long naxes[2];
    long naxis=2;
    int nelements=0;

    fitsfile *fptr=NULL;

    naxes[0]=targetChip->getSubW()/targetChip->getBinX();
    naxes[1]=targetChip->getSubH()/targetChip->getBinY();

    switch (targetChip->getBPP())
    {
        case 8:
            byte_type = TBYTE;
            img_type  = BYTE_IMG;
            break;

        case 16:
            byte_type = TUSHORT;
            img_type = USHORT_IMG;
            break;

        case 32:
            byte_type = TULONG;
            img_type = ULONG_IMG;
            break;

         default:
            IDLog("Unsupported bits per pixel value %d\n", targetChip->getBPP() );
            return false;
            break;
    }


    nelements = naxes[0] * naxes[1];

    //  Now we have to send fits format data to the client
    memsize=5760;
    memptr=malloc(memsize);
    if(!memptr)
    {
        IDLog("Error: failed to allocate memory: %lu\n",(unsigned long)memsize);
    }

    fits_create_memfile(&fptr,&memptr,&memsize,2880,realloc,&status);

    if(status)
    {
		IDLog("Error: Failed to create FITS image\n");
		fits_report_error(stderr, status);  /* print out any error messages */
		return false;
    }

    fits_create_img(fptr, img_type , naxis, naxes, &status);

    if (status)
    {
		IDLog("Error: Failed to create FITS image\n");
		fits_report_error(stderr, status);  /* print out any error messages */
		return false;
    }

    addFITSKeywords(fptr, targetChip);

    fits_write_img(fptr,byte_type,1,nelements,targetChip->getFrameBuffer(),&status);

    if (status)
    {
		IDLog("Error: Failed to write FITS image\n");
		fits_report_error(stderr, status);  /* print out any error messages */
		return false;
    }

    fits_close_file(fptr,&status);

    targetChip->ImageExposureNP->s=IPS_OK;
    IDSetNumber(targetChip->ImageExposureNP,NULL);


    targetChip->FitsB.blob=memptr;
    targetChip->FitsB.bloblen=memsize;
    targetChip->FitsB.size=memsize;
    strcpy(targetChip->FitsB.format,".fits");
    targetChip->FitsBP->s=IPS_OK;
    //IDLog("Enter Uploadfile with %d total sending via %s, and format %s\n",total,targetChip->FitsB.name, targetChip->FitsB.format);
    IDSetBLOB(targetChip->FitsBP,NULL);

    free(memptr);
    return true;
}