Changeset View
Changeset View
Standalone View
Standalone View
kstars/ekos/guide/externalguide/phd2.cpp
Show First 20 Lines • Show All 765 Lines • ▼ Show 20 Line(s) | |||||
766 | } | 766 | } | ||
767 | 767 | | |||
768 | void PHD2::processStarImage(const QJsonObject &jsonStarFrame) | 768 | void PHD2::processStarImage(const QJsonObject &jsonStarFrame) | ||
769 | { | 769 | { | ||
770 | //The width and height of the received PHD2 Star Image | 770 | //The width and height of the received PHD2 Star Image | ||
771 | int width = jsonStarFrame["width"].toInt(); | 771 | int width = jsonStarFrame["width"].toInt(); | ||
772 | int height = jsonStarFrame["height"].toInt(); | 772 | int height = jsonStarFrame["height"].toInt(); | ||
773 | 773 | | |||
774 | QTemporaryFile tempfile(KSPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("phd2_XXXXXX")); | | |||
775 | tempfile.setAutoRemove(false); | | |||
776 | if (!tempfile.open()) | | |||
777 | { | | |||
778 | qCWarning(KSTARS_EKOS_GUIDE) << "could not create temp file for PHD2 star image"; | | |||
779 | return; | | |||
780 | } | | |||
781 | QString filename = tempfile.fileName(); | | |||
782 | | ||||
783 | //This section sets up the FITS File | 774 | //This section sets up the FITS File | ||
784 | fitsfile *fptr = nullptr; | 775 | fitsfile *fptr = nullptr; | ||
785 | int status = 0; | 776 | int status = 0; | ||
786 | long fpixel = 1, naxis = 2, nelements, exposure; | 777 | long fpixel = 1, naxis = 2, nelements, exposure; | ||
787 | long naxes[2] = { width, height }; | 778 | long naxes[2] = { width, height }; | ||
788 | char error_status[512] = {0}; | 779 | char error_status[512] = {0}; | ||
789 | 780 | | |||
790 | if (fits_create_file(&fptr, QString('!' + filename).toLatin1().data(), &status)) | 781 | void* fits_buffer = nullptr; | ||
782 | size_t fits_buffer_size = 0; | ||||
783 | if (fits_create_memfile(&fptr, &fits_buffer, &fits_buffer_size, 4096, realloc, &status)) | ||||
791 | { | 784 | { | ||
792 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_create_file failed:" << error_status; | 785 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_create_file failed:" << error_status; | ||
793 | return; | 786 | return; | ||
794 | } | 787 | } | ||
795 | 788 | | |||
796 | if (fits_create_img(fptr, USHORT_IMG, naxis, naxes, &status)) | 789 | if (fits_create_img(fptr, USHORT_IMG, naxis, naxes, &status)) | ||
797 | { | 790 | { | ||
798 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_create_img failed:" << error_status; | 791 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_create_img failed:" << error_status; | ||
799 | status = 0; | 792 | status = 0; | ||
800 | fits_close_file(fptr, &status); | 793 | fits_close_file(fptr, &status); | ||
794 | free(fits_buffer); | ||||
801 | return; | 795 | return; | ||
802 | } | 796 | } | ||
803 | 797 | | |||
804 | //Note, this is made up. If you want the actual exposure time, you have to request it from PHD2 | 798 | //Note, this is made up. If you want the actual exposure time, you have to request it from PHD2 | ||
805 | exposure = 1; | 799 | exposure = 1; | ||
806 | fits_update_key(fptr, TLONG, "EXPOSURE", &exposure, "Total Exposure Time", &status); | 800 | fits_update_key(fptr, TLONG, "EXPOSURE", &exposure, "Total Exposure Time", &status); | ||
807 | 801 | | |||
808 | //This section takes the Pixels from the JSON Document | 802 | //This section takes the Pixels from the JSON Document | ||
809 | //Then it converts from base64 to a QByteArray | 803 | //Then it converts from base64 to a QByteArray | ||
810 | //Then it creates a datastream from the QByteArray to the pixel array for the FITS File | 804 | //Then it creates a datastream from the QByteArray to the pixel array for the FITS File | ||
811 | QByteArray converted = QByteArray::fromBase64(jsonStarFrame["pixels"].toString().toLocal8Bit()); | 805 | QByteArray converted = QByteArray::fromBase64(jsonStarFrame["pixels"].toString().toLocal8Bit()); | ||
812 | 806 | | |||
813 | //This finishes up and closes the FITS file | 807 | //This finishes up and closes the FITS file | ||
814 | nelements = naxes[0] * naxes[1]; | 808 | nelements = naxes[0] * naxes[1]; | ||
815 | if (fits_write_img(fptr, TUSHORT, fpixel, nelements, converted.data(), &status)) | 809 | if (fits_write_img(fptr, TUSHORT, fpixel, nelements, converted.data(), &status)) | ||
816 | { | 810 | { | ||
817 | fits_get_errstatus(status, error_status); | 811 | fits_get_errstatus(status, error_status); | ||
818 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_write_img failed:" << error_status; | 812 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_write_img failed:" << error_status; | ||
819 | status = 0; | 813 | status = 0; | ||
820 | fits_close_file(fptr, &status); | 814 | fits_close_file(fptr, &status); | ||
815 | free(fits_buffer); | ||||
821 | return; | 816 | return; | ||
822 | } | 817 | } | ||
823 | 818 | | |||
824 | if (fits_flush_file(fptr, &status)) | 819 | if (fits_flush_file(fptr, &status)) | ||
825 | { | 820 | { | ||
826 | fits_get_errstatus(status, error_status); | 821 | fits_get_errstatus(status, error_status); | ||
827 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_flush_file failed:" << error_status; | 822 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_flush_file failed:" << error_status; | ||
828 | status = 0; | 823 | status = 0; | ||
829 | fits_close_file(fptr, &status); | 824 | fits_close_file(fptr, &status); | ||
825 | free(fits_buffer); | ||||
830 | return; | 826 | return; | ||
831 | } | 827 | } | ||
832 | 828 | | |||
833 | if (fits_close_file(fptr, &status)) | 829 | if (fits_close_file(fptr, &status)) | ||
834 | { | 830 | { | ||
835 | fits_get_errstatus(status, error_status); | 831 | fits_get_errstatus(status, error_status); | ||
836 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_close_file failed:" << error_status; | 832 | qCWarning(KSTARS_EKOS_GUIDE) << "fits_close_file failed:" << error_status; | ||
833 | free(fits_buffer); | ||||
837 | return; | 834 | return; | ||
838 | } | 835 | } | ||
839 | 836 | | |||
840 | //This loads the FITS file in the Guide FITSView | 837 | //This loads the FITS file in the Guide FITSView | ||
841 | //Then it updates the Summary Screen | 838 | //Then it updates the Summary Screen | ||
842 | auto conn = std::make_shared<QMetaObject::Connection>(); | 839 | FITSData* fdata = new FITSData(); | ||
843 | *conn = connect(guideFrame, &FITSView::loaded, [this, conn, width, height]() | 840 | fdata->loadFITSFromMemory("guideframe.fits", fits_buffer, fits_buffer_size, true); | ||
844 | { | 841 | free(fits_buffer); | ||
845 | // we'll take care of deleting the temp file | 842 | guideFrame->loadFITSFromData(fdata, "guideframe.fits"); | ||
846 | //guideFrame->getImageData()->setAutoRemoveTemporaryFITS(false); | 843 | | ||
847 | guideFrame->updateFrame(); | 844 | guideFrame->updateFrame(); | ||
848 | guideFrame->setTrackingBox(QRect(0, 0, width, height)); | 845 | guideFrame->setTrackingBox(QRect(0, 0, width, height)); | ||
849 | emit newStarPixmap(guideFrame->getTrackingBoxPixmap()); | 846 | emit newStarPixmap(guideFrame->getTrackingBoxPixmap()); | ||
850 | | ||||
851 | QObject::disconnect(*conn); | | |||
852 | }); | | |||
853 | | ||||
854 | guideFrame->loadFITS(filename, true); | | |||
855 | } | 847 | } | ||
856 | 848 | | |||
857 | void PHD2::setEquipmentConnected() | 849 | void PHD2::setEquipmentConnected() | ||
858 | { | 850 | { | ||
859 | if (connection != EQUIPMENT_CONNECTED) | 851 | if (connection != EQUIPMENT_CONNECTED) | ||
860 | { | 852 | { | ||
861 | setConnectedRetries = 0; | 853 | setConnectedRetries = 0; | ||
862 | connection = EQUIPMENT_CONNECTED; | 854 | connection = EQUIPMENT_CONNECTED; | ||
▲ Show 20 Lines • Show All 469 Lines • Show Last 20 Lines |