23#include <libnova/julian_day.h>
43static pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
44static pthread_mutex_t condMutex = PTHREAD_MUTEX_INITIALIZER;
46static std::unique_ptr<CCDSim> ccdsim(
new CCDSim());
111 pthread_mutex_lock(&condMutex);
114 pthread_cond_signal(&cv);
115 pthread_mutex_unlock(&condMutex);
122 return "CCD Simulator";
195 EqPENP[
AXIS_RA].fill(
"RA_PE",
"RA (hh:mm:ss)",
"%010.6m", 0, 24, 0, 0);
196 EqPENP[
AXIS_DE].fill(
"DEC_PE",
"DEC (dd:mm:ss)",
"%010.6m", -90, 90, 0, 0);
201 FieldRotationNP[0].fill(
"SIM_PARALLACTIC_ANGLE",
"Parallactic Angle",
"%.3f", -180, 180, 0, 0);
214 IUFillNumber(&
FWHMN[0],
"SIM_FWHM",
"FWHM (arcseconds)",
"%4.2f", 0, 60, 0, 7.5);
224 GainNP[0].fill(
"GAIN",
"value",
"%.f", 0, 300, 10, 90);
228 OffsetNP[0].fill(
"OFFSET",
"value",
"%.f", 0, 6000, 500, 0);
233 DirectoryTP[0].fill(
"LOCATION",
"Location", getenv(
"HOME"));
245 std::ostringstream ss;
256#ifdef USE_EQUATORIAL_PE
454 if (
PrimaryCCD.getFrameBufferSize() !=
static_cast<int>(rgbBufSize))
458 uint16_t *buffer =
reinterpret_cast<uint16_t *
>(
PrimaryCCD.getFrameBuffer());
461 double centerX, centerY;
468 memset(buffer, 0,
PrimaryCCD.getFrameBufferSize());
557 if (timeleft <= 0.001)
568 nextTimer = timeleft * 1000;
584 if (timeleft <= 0.001)
597 nextTimer = timeleft * 1000;
609 nextTimer = timeleft * 1000;
617 constexpr double AMBIENT_TEMPERATURE = 25.0;
618 constexpr double MIN_TEC_TEMPERATURE = -15.0;
622 const double targetTemp = std::clamp(
TemperatureRequest, MIN_TEC_TEMPERATURE, AMBIENT_TEMPERATURE);
632 double newTemp = currentTemp;
634 if (targetTemp < newTemp)
637 newTemp = std::max(targetTemp, newTemp - 0.5);
639 else if (targetTemp > newTemp)
643 double deltaT = AMBIENT_TEMPERATURE - newTemp;
646 double warmingStep = deltaT * 0.2;
647 if (warmingStep < 0.02)
649 if (warmingStep > 0.5)
651 newTemp = std::min(targetTemp, newTemp + warmingStep);
663 if (newTemp >= AMBIENT_TEMPERATURE - 0.1 &&
CoolerSP.getState() !=
IPS_IDLE)
680 uint16_t * ptr =
reinterpret_cast<uint16_t *
>(targetChip->
getFrameBuffer());
682 if (targetChip->
getXRes() == 500)
689 exposure_time *= (1 + sqrt(
GainNP[0].getValue()));
703 double ra_deg =
currentRA * 15.0 + PEOffset;
705 double decr = cameradec * 0.0174532925;
707 double dec_deg = cameradec + decDrift / 3600.0;
726 if (isLight || isFlat)
728 int drawn =
m_Renderer.renderFrame(targetChip, ra_deg, dec_deg,
729 targetFocalLength, theta, exposure_time, isLight);
730 if (isLight && drawn < 0)
731 LOG_ERROR(
"Error launching gsc, is it installed with appropriate environment variables set?");
732 else if (isLight && drawn == 0)
733 LOG_WARN(
"No stars found in field -- check gsc catalog coverage for this region.");
758 for (
int x = 0; x < nbuf; x++)
785 if (hot > 0 || cold > 0)
786 LOGF_DEBUG(
"Simulating %d hot and %d cold pixels on a %dx%d sensor.", hot, cold, xres, yres);
796 double timesince = difftime(now,
RunStart);
797 double PESpot = timesince /
m_PEPeriod * 2.0 * 3.14159;
798 return m_PEMax * std::sin(PESpot) / 3600.0f;
819#ifdef USE_EQUATORIAL_PE
831 const double dec = de * (
M_PI / 180.0);
833 const double q = std::atan2(std::sin(ha), std::tan(lat) * std::cos(
dec) - std::sin(
dec) * std::cos(ha))
845#ifdef USE_EQUATORIAL_PE
853 static bool s_warnedNoSnoop =
false;
854 if (!s_warnedNoSnoop)
856 LOG_WARN(
"EQUATORIAL_PE not yet snooped -- rendering at raw EQUATORIAL_EOD_COORD (mount errors not active)");
857 s_warnedNoSnoop =
true;
883 if (de > 90 || de < -90)
885 de = (de > 0 ? 180 : -180) - de;
896 gettimeofday(&now,
nullptr);
897 double const timesince = (now.tv_sec * 1000.0 + now.tv_usec / 1000.0)
898 - (start.tv_sec * 1000.0 + start.tv_usec / 1000.0);
899 return static_cast<float>(req - timesince / 1000.0);
917 c = c / 3600.0 / 15.0;
928 c = c / 3600.0 / 15.0;
945 if (
m_Clock.processText(name, texts, names,
n))
984 if (
GainNP.isNameMatch(name))
986 GainNP.update(values, names,
n);
1014 else if (
EqPENP.isNameMatch(name))
1016 EqPENP.update(values, names,
n);
1127 else if (
CoolerSP.isNameMatch(name))
1137 constexpr double AMBIENT_TEMPERATURE = 25.0;
1172 LOG_INFO(
"Directory-based images are disabled.");
1184 if (index >= 0 && index <
static_cast<int>(
Resolutions.size() - 1))
1221 rgbIndex =
static_cast<int>(i);
1251 monoIndex =
static_cast<int>(i);
1265 LOG_INFO(
"Planet simulation disabled. Returning to star field mode.");
1285 static const char* planetNames[] =
1287 "mercury",
"venus",
"mars",
"jupiter",
"saturn",
1288 "uranus",
"neptune",
"moon",
"sun"
1290 if (index >= 0 && index < 9)
1310 if (dirp ==
nullptr)
1319 if (directory[std::string(directory).length() - 1] !=
'/')
1323 static const std::vector<std::string> supportedExtensions =
1331 auto hasSupportedExtension = [](
const std::string &name)
1333 for (
const auto &extension : supportedExtensions)
1335 if (name.size() < extension.size())
1337 if (strcasecmp(name.c_str() + name.size() - extension.size(), extension.c_str()) == 0)
1343 while ((dp = readdir(dirp)) != NULL)
1345 if (hasSupportedExtension(dp->d_name))
1352 LOGF_ERROR(
"No supported image files (.fit, .fits%s) found in directory %s",
1365 LOGF_INFO(
"Directory-based images are enabled. Subsequent exposures will be loaded from directory %s",
1374#ifdef USE_EQUATORIAL_PE
1397 if (!strcmp(propName,
"ABS_FOCUS_POSITION"))
1403 if (!strcmp(name,
"FOCUS_ABSOLUTE_POSITION"))
1415 m_Seeing = 0.5625 * ticks * ticks + optimalFWHM;
1420 else if (!strcmp(propName,
"ABS_ROTATOR_ANGLE"))
1426 if (!strcmp(name,
"ANGLE"))
1434 else if (!strcmp(propName,
"TELESCOPE_MOUNT_TYPE"))
1443 LOGF_INFO(
"Mount is %s, field rotation is %s.", altAz ?
"Alt-Az" :
"equatorial",
1444 altAz ?
"simulated" :
"off");
1457 if (!strcmp(propName,
"EQUATORIAL_EOD_COORD"))
1459 const bool slewing = !strcmp(
findXMLAttValu(root,
"state"),
"Busy");
1467#ifdef USE_EQUATORIAL_PE
1468 if (!strcmp(propName,
"EQUATORIAL_PE"))
1470 int rc_ra = -1, rc_de = -1;
1471 double newra = 0, newdec = 0;
1477 if (!strcmp(elemName,
"RA_PE"))
1479 else if (!strcmp(elemName,
"DEC_PE"))
1483 if (rc_ra == 0 && rc_de == 0)
1491 if (!
usePE && strcmp(state,
"Ok") == 0)
1493 LOGF_INFO(
"EQUATORIAL_PE snoop active: JNow RA %.4f Dec %.4f", newra, newdec);
1501 LOGF_DEBUG(
"Snooped EQUATORIAL_PE JNow RA %g Dec %g", newra, newdec);
1553 std::random_device rd;
1554 std::mt19937 gen(rd());
1555 std::uniform_int_distribution<> dist(1500, 2000);
1556 std::this_thread::sleep_for(std::chrono::milliseconds(dist(gen)));
1585 pthread_mutex_lock(&condMutex);
1587 pthread_mutex_unlock(&condMutex);
1588 pthread_cond_signal(&cv);
1595 pthread_mutex_lock(&condMutex);
1597 pthread_mutex_unlock(&condMutex);
1598 pthread_cond_signal(&cv);
1608 bin_width = bin_width - (bin_width % 2);
1609 bin_height = bin_height - (bin_height % 2);
1611 Streamer->setSize(bin_width, bin_height);
1621 LOG_ERROR(
"Binning is not supported in planet mode.");
1627 LOGF_ERROR(
"%dx%d binning is not supported.", hor, ver);
1631 uint32_t bin_width =
PrimaryCCD.getSubW() / hor;
1632 uint32_t bin_height =
PrimaryCCD.getSubH() / ver;
1633 Streamer->setSize(bin_width, bin_height);
1642 LOGF_ERROR(
"%dx%d binning is not supported.", hor, ver);
1656 auto start = std::chrono::high_resolution_clock::now();
1660 pthread_mutex_lock(&condMutex);
1664 pthread_cond_wait(&cv, &condMutex);
1672 pthread_mutex_unlock(&condMutex);
1683 double centerX, centerY;
1691 auto finish = std::chrono::high_resolution_clock::now();
1692 std::chrono::duration<double> elapsed = finish - start;
1704 auto finish = std::chrono::high_resolution_clock::now();
1705 std::chrono::duration<double> elapsed = finish - start;
1709 uint32_t size =
PrimaryCCD.getFrameBufferSize();
1713 start = std::chrono::high_resolution_clock::now();
1716 pthread_mutex_unlock(&condMutex);
1727 if (!(focalLength > 0))
1728 focalLength = 1000.0f;
1729 float arcsecPerPixelX = 206.265f * pixelSizeX / focalLength;
1730 float arcsecPerPixelY = 206.265f * pixelSizeY / focalLength;
1740 if (!stale && !paramsChanged)
1751 float planetDiameterArcsec = 0;
1760 planetDiameterArcsec = it->second;
1762 planetDiameterArcsec = 42.0f;
1766 float planetPixelsX = planetDiameterArcsec / arcsecPerPixelX;
1767 float planetPixelsY = planetDiameterArcsec / arcsecPerPixelY;
1768 float avgPlanetPixels = (planetPixelsX + planetPixelsY) / 2.0f;
1774 const int renderSize = 1024;
1775 const float planetRange = 0.05f;
1778 float planetDiamDeg = planetDiameterArcsec / 3600.0f;
1779 float planetFracOfFrame = planetDiamDeg / planetRange;
1780 float srcPlanetRadius = planetFracOfFrame * renderSize / 2.0f;
1781 if (srcPlanetRadius < 10.0f) srcPlanetRadius = 10.0f;
1784 std::string searchDir;
1786 if (configPos != std::string::npos)
1789 const char *pngPath =
"/tmp/indi_planet.png";
1791 const bool useCustomConfig = (
m_XPlanetConfig !=
"/usr/share/xplanet/config/default");
1793 if (!searchDir.empty() && useCustomConfig)
1795 snprintf(
cmd,
sizeof(
cmd),
1796 "%s -body %s -geometry %dx%d -range %.4f "
1797 "-num_times 1 -projection orthographic "
1798 "-config %s -searchdir %s "
1799 "-output %s 2>/dev/null",
1801 renderSize, renderSize,
static_cast<double>(planetRange),
1804 else if (!searchDir.empty())
1806 snprintf(
cmd,
sizeof(
cmd),
1807 "%s -body %s -geometry %dx%d -range %.4f "
1808 "-num_times 1 -projection orthographic "
1810 "-output %s 2>/dev/null",
1812 renderSize, renderSize,
static_cast<double>(planetRange),
1813 searchDir.c_str(), pngPath);
1817 snprintf(
cmd,
sizeof(
cmd),
1818 "%s -body %s -geometry %dx%d -range %.4f "
1819 "-num_times 1 -projection orthographic "
1820 "-output %s 2>/dev/null",
1822 renderSize, renderSize,
static_cast<double>(planetRange), pngPath);
1826 int ret = system(
cmd);
1829 LOGF_ERROR(
"xplanet failed with exit code %d. Is xplanet installed?", ret);
1833 ret = system(
"convert /tmp/indi_planet.png /tmp/indi_planet.ppm 2>/dev/null");
1836 LOG_ERROR(
"Failed to convert PNG to PPM. Is ImageMagick installed?");
1841 FILE *fp = fopen(
"/tmp/indi_planet.ppm",
"rb");
1844 LOG_ERROR(
"Failed to open /tmp/indi_planet.ppm");
1849 if (fscanf(fp,
"%2s\n", magic) != 1 || strcmp(magic,
"P6") != 0)
1851 LOG_ERROR(
"PPM file is not P6 format (binary RGB)");
1856 int ppmWidth, ppmHeight, maxVal;
1861 while (fgetc(fp) !=
'\n');
1865 if (fscanf(fp,
"%d %d\n%d\n", &ppmWidth, &ppmHeight, &maxVal) != 3)
1867 LOG_ERROR(
"Failed to parse PPM header");
1872 std::vector<uint8_t> rgbData(ppmWidth * ppmHeight * 3);
1873 size_t bytesRead = fread(rgbData.data(), 1, rgbData.size(), fp);
1876 if (bytesRead != rgbData.size())
1878 LOGF_ERROR(
"PPM read error: expected %zu bytes, got %zu", rgbData.size(), bytesRead);
1883 float dstPlanetRadius = avgPlanetPixels / 2.0f;
1884 if (dstPlanetRadius < 1.0f)
1885 dstPlanetRadius = 1.0f;
1886 float scale = srcPlanetRadius / dstPlanetRadius;
1888 const uint32_t spriteSize =
static_cast<uint32_t
>(std::ceil(dstPlanetRadius * 2)) + 2;
1889 const float spriteCenter = spriteSize / 2.0f;
1890 std::vector<uint8_t> sprite(spriteSize * spriteSize * 3, 0);
1892 for (uint32_t y = 0; y < spriteSize; y++)
1894 for (uint32_t x = 0; x < spriteSize; x++)
1896 float dx = (x - spriteCenter) * scale;
1897 float dy = (y - spriteCenter) * scale;
1898 if (sqrtf(dx * dx + dy * dy) > srcPlanetRadius)
1901 int ix =
static_cast<int>(dx + ppmWidth / 2.0f);
1902 int iy =
static_cast<int>(dy + ppmHeight / 2.0f);
1903 if (ix < 0 || ix >= ppmWidth || iy < 0 || iy >= ppmHeight)
1906 memcpy(&sprite[(y * spriteSize + x) * 3], &rgbData[(iy * ppmWidth + ix) * 3], 3);
1913 LOGF_INFO(
"Rendered planet %s: diameter=%.1f arcsec, pixels=%.1f, scale=%.1f arcsec/px",
1914 m_SelectedPlanet.c_str(), planetDiameterArcsec, planetPixelsX, arcsecPerPixelX);
1940 const double rar = pointingRA * (
M_PI / 180.0);
1941 const double decr = pointingDE * (
M_PI / 180.0);
1944 const double denom = cos(decr) * cos(sdecr) * cos(srar - rar) + sin(decr) * sin(sdecr);
1945 double sx = cos(sdecr) * sin(srar - rar) / denom;
1946 double sy = (sin(decr) * cos(sdecr) * cos(srar - rar) - cos(decr) * sin(sdecr)) / denom;
1949 const double minutes = std::chrono::duration<double>(std::chrono::steady_clock::now() -
m_PlanetDriftStart).count() / 60.0;
1950 const double arcsecToRad =
M_PI / (180.0 * 3600.0);
1956 std::normal_distribution<double> seeing(0, jitter * arcsecToRad);
1963 if (!(focalLength > 0))
1964 focalLength = 1000.0;
1966 const double pprx = focalLength /
PrimaryCCD.getPixelSizeX() * 1000.0;
1967 const double ppry = focalLength /
PrimaryCCD.getPixelSizeY() * 1000.0;
1968 const double pa = pprx * std::cos(theta);
1969 const double pb = ppry * std::sin(theta);
1970 const double pd = -pprx * std::sin(theta);
1971 const double pe = ppry * std::cos(theta);
1973 x =
PrimaryCCD.getXRes() / 2.0 - (pa * sx + pb * sy);
1974 y =
PrimaryCCD.getYRes() / 2.0 + (pd * sx + pe * sy);
1981 memset(buffer, 0,
static_cast<size_t>(subW) * subH * 3);
1985 const int originX =
static_cast<int>(std::lround(centerX - size / 2.0)) - subX;
1986 const int originY =
static_cast<int>(std::lround(centerY - size / 2.0)) - subY;
1987 const int x0 = std::max(0, originX), x1 = std::min(subW, originX + size);
1988 const int y0 = std::max(0, originY), y1 = std::min(subH, originY + size);
1991 for (
int y = y0; y < y1; y++)
1993 const uint8_t *src = &
m_PlanetSprite[((y - originY) * size + (x0 - originX)) * 3];
1994 uint8_t *dst = buffer + (
static_cast<size_t>(y) * subW + x0) * 3;
1995 for (
int i = 0; i < (x1 - x0) * 3; i++)
1996 dst[i] = src[i] * transparency / 100;
2004 const size_t planeSize =
static_cast<size_t>(subW) * subH;
2005 memset(buffer, 0, planeSize * 3 *
sizeof(uint16_t));
2008 const int originX =
static_cast<int>(std::lround(centerX - size / 2.0)) - subX;
2009 const int originY =
static_cast<int>(std::lround(centerY - size / 2.0)) - subY;
2010 const int x0 = std::max(0, originX), x1 = std::min(subW, originX + size);
2011 const int y0 = std::max(0, originY), y1 = std::min(subH, originY + size);
2016 for (
int y = y0; y < y1; y++)
2018 for (
int x = x0; x < x1; x++)
2020 const uint8_t *src = &
m_PlanetSprite[((y - originY) * size + (x - originX)) * 3];
2021 const size_t px =
static_cast<size_t>(y) * subW + x;
2022 for (
int c = 0; c < 3; c++)
2024 uint32_t value = src[c] * 256u * transparency / 100;
2025 buffer[c * planeSize + px] =
static_cast<uint16_t
>(std::min<uint32_t>(value,
m_MaxVal));
2035 fitsKeyword.push_back({
"GAIN",
GainNP[0].getValue(), 3,
"Gain"});
2039 fitsKeyword.emplace_back(
"OBJECT",
m_SelectedPlanet.c_str(),
"Target planet");
2040 fitsKeyword.emplace_back(
"XPLANET",
static_cast<int64_t
>(1),
"Generated by xplanet");
2041 fitsKeyword.emplace_back(
"COLORSPC",
"RGB",
"Color space");
2053 if (filename.size() >= 5 && strcasecmp(filename.c_str() + filename.size() - 5,
".xisf") == 0)
2054 return loadNextXISFImage(filename);
2062 char comment[512] = {0}, bayer_pattern[16] = {0};
2063 int status = 0, anynull = 0;
2064 double pixel_size = 5.2;
2065 int ndim {2}, bitpix {8};
2067 fitsfile *fptr =
nullptr;
2069 if (fits_open_diskfile(&fptr, filename.c_str(), READONLY, &status))
2071 char error_status[512] = {0};
2072 fits_get_errstatus(status, error_status);
2073 LOGF_WARN(
"Error opening file %s due to error %s", filename.c_str(), error_status);
2077 if (fits_get_img_param(fptr, 3, &bitpix, &ndim, naxes, &status))
2079 char error_status[512] = {0};
2080 fits_get_errstatus(status, error_status);
2081 LOGF_WARN(
"Error reading image parameters from %s due to error %s", filename.c_str(), error_status);
2082 fits_close_file(fptr, &status);
2090 int samples_per_channel = naxes[0] * naxes[1];
2091 int channels = naxes[2];
2092 int elements = samples_per_channel * channels;
2093 int size = elements * bitpix / 8;
2096 if (fits_read_img(fptr, bitpix == 8 ? TBYTE : TUSHORT, 1, elements, 0,
PrimaryCCD.getFrameBuffer(), &anynull, &status))
2098 char error_status[512] = {0};
2099 fits_get_errstatus(status, error_status);
2100 LOGF_WARN(
"Error reading pixel data from %s due to error %s", filename.c_str(), error_status);
2101 fits_close_file(fptr, &status);
2109 if (fits_read_key_dbl(fptr,
"PIXSIZE1", &pixel_size, comment, &status))
2112 if (fits_read_key_dbl(fptr,
"XPIXSZ", &pixel_size, comment, &status))
2114 LOGF_DEBUG(
"No PIXSIZE1 or XPIXSZ keyword found in %s, defaulting pixel size to %.2f microns",
2115 filename.c_str(), pixel_size);
2120 if (fits_read_key_str(fptr,
"BAYERPAT", bayer_pattern, comment, &status))
2122 char error_status[512] = {0};
2123 fits_get_errstatus(status, error_status);
2124 LOGF_DEBUG(
"No BAYERPAT keyword found in %s (%s)", filename.c_str(), error_status);
2126 SetCCDParams(naxes[0], naxes[1], bitpix, pixel_size, pixel_size);
2129 if (channels == 1 && strlen(bayer_pattern) == 4)
2142 fits_close_file(fptr, &status);
2147bool CCDSim::loadNextXISFImage(
const std::string &filename)
2151 LibXISF::XISFReader reader;
2152 reader.open(filename);
2154 if (reader.imagesCount() < 1)
2156 LOGF_WARN(
"No images found in XISF file %s", filename.c_str());
2161 LibXISF::Image image = reader.getImage(0);
2163 const auto sampleFormat = image.sampleFormat();
2164 const bool isFloat = (sampleFormat == LibXISF::Image::Float32 || sampleFormat == LibXISF::Image::Float64);
2166 switch (sampleFormat)
2168 case LibXISF::Image::UInt8:
2171 case LibXISF::Image::UInt16:
2174 case LibXISF::Image::Float32:
2175 case LibXISF::Image::Float64:
2182 LOGF_WARN(
"Unsupported XISF sample format '%s' in %s. Only 8/16-bit integer and 32/64-bit "
2183 "normalized float samples are supported.",
2184 LibXISF::Image::sampleFormatString(sampleFormat).c_str(), filename.c_str());
2188 int channels =
static_cast<int>(image.channelCount());
2193 if (image.pixelStorage() != LibXISF::Image::Planar)
2194 image.convertPixelStorageTo(LibXISF::Image::Planar);
2196 const size_t elementCount = image.width() * image.height() * channels;
2199 PrimaryCCD.setFrameBufferSize(elementCount * 2);
2200 auto * dest =
reinterpret_cast<uint16_t *
>(
PrimaryCCD.getFrameBuffer());
2201 auto scaleClamp = [](
double value) -> uint16_t
2207 return static_cast<uint16_t
>(std::lround(value * 65535.0));
2210 if (sampleFormat == LibXISF::Image::Float32)
2212 const float * src = image.imageData<
float>();
2213 for (
size_t i = 0; i < elementCount; i++)
2214 dest[i] = scaleClamp(src[i]);
2218 const double * src = image.imageData<
double>();
2219 for (
size_t i = 0; i < elementCount; i++)
2220 dest[i] = scaleClamp(src[i]);
2225 PrimaryCCD.setFrameBufferSize(image.imageDataSize());
2226 memcpy(
PrimaryCCD.getFrameBuffer(), image.imageData(), image.imageDataSize());
2230 double pixel_size = 5.2;
2231 bool foundPixelSize =
false;
2232 for (
const auto &keyword : image.fitsKeywords())
2234 if (keyword.name ==
"PIXSIZE1" || keyword.name ==
"XPIXSZ")
2236 pixel_size = std::stod(keyword.value);
2237 foundPixelSize =
true;
2241 if (!foundPixelSize)
2242 LOGF_DEBUG(
"No PIXSIZE1 or XPIXSZ keyword found in %s, defaulting pixel size to %.2f microns",
2243 filename.c_str(), pixel_size);
2245 SetCCDParams(image.width(), image.height(), bitpix, pixel_size, pixel_size);
2248 const auto cfa = image.colorFilterArray();
2249 if (channels == 1 && cfa.pattern.size() == 4)
2261 catch (LibXISF::Error &error)
2263 LOGF_WARN(
"Error reading XISF file %s due to error: %s", filename.c_str(),
error.what());
2278 bool isRGB = (format.name ==
"INDI_RGB");
The CCDSim class provides an advanced simulator for a CCD that includes a dedicated on-board guide ch...
virtual bool UpdateCCDFrame(int x, int y, int w, int h) override
CCD calls this function when CCD Frame dimension needs to be updated in the hardware....
INDI::PropertyNumber TiltSimulationNP
float periodicErrorOffset()
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
INDI::PropertySwitch PlanetRecenterSP
INDI::PropertyNumber PlanetDriftNP
void setBayerEnabled(bool onOff)
INDI::PropertyNumber FocusSimulationNP
bool StartExposure(float duration) override
Start exposing primary CCD chip.
bool loadNextFITSImage(const std::string &filename)
void applyPointingOffset(double &ra, double &de)
virtual IPState GuideSouth(uint32_t) override
Guide southward for ms milliseconds.
INDI::PropertyText PlanetPathsTP
INDI::PropertyText DirectoryTP
INDI::PropertyNumber GainNP
bool m_PlanetPositionValid
std::chrono::steady_clock::time_point m_PlanetDriftStart
static const constexpr char * SIMULATOR_TAB
std::string m_XPlanetConfig
float GuideRate
Guide rate is 7 arcseconds per second.
double parallacticAngle()
bool Disconnect() override
Disconnect from device.
INDI::PropertyNumber EqPENP
void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool StartGuideExposure(float) override
Start exposing guide CCD chip.
virtual bool SetCaptureFormat(uint8_t index) override
SetCaptureFormat Set Active Capture format.
INDI::PropertySwitch SimTestsSP
std::vector< uint8_t > m_PlanetSprite
std::string m_XPlanetBinary
void drawPlanetRGB16(uint16_t *buffer, double centerX, double centerY)
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual int SetTemperature(double temperature) override
Set CCD temperature.
static const std::map< std::string, float > PlanetAngularDiameter
const char * getDefaultName() override
std::deque< std::string > m_AllFiles
INDI::PropertySwitch CoolerSP
virtual bool StartStreaming() override
StartStreaming Start live video streaming.
INDI::PropertyNumber SimulatorSettingsNP
static void * streamVideoHelper(void *context)
void drawPlanetRGB8(uint8_t *buffer, double centerX, double centerY)
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
std::atomic< time_t > m_LastPlanetRenderTime
float m_PlanetRefreshMinutes
virtual IPState GuideEast(uint32_t) override
Guide easward for ms milliseconds.
void planetPosition(double &x, double &y)
float m_PlanetSizeOverride
virtual IPState GuideWest(uint32_t) override
Guide westward for ms milliseconds.
std::mt19937 m_PlanetRandom
int QueryFilter() override
Return current filter position.
virtual bool StopStreaming() override
StopStreaming Stop live video streaming.
float m_PEPeriod
PEPeriod in minutes.
std::vector< uint8_t > m_PlanetStreamFrame
bool SelectFilter(int) override
Select a new filter position.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
std::vector< SensorDefect > m_Defects
INDI::PropertyNumber FieldRotationNP
INDI::PropertyNumber OffsetNP
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
virtual bool UpdateCCDBin(int hor, int ver) override
CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should ...
static const std::vector< std::pair< uint32_t, uint32_t > > Resolutions
INDI::PropertySwitch ResolutionSP
INumberVectorProperty FWHMNP
std::string m_SelectedPlanet
virtual IPState GuideNorth(uint32_t) override
Guide northward for ms milliseconds.
bool AbortExposure() override
Abort ongoing exposure.
INDI::PropertyNumber PlanetSettingsNP
INDI::PropertySwitch PlanetSelectSP
INDI::PropertyNumber DefectSimulationNP
float m_CachedFocalLength
INDI::PropertyNumber PointingOffsetNP
std::string m_CachedPlanet
double TemperatureRequest
uint32_t m_PlanetSpriteSize
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
INDI::PropertySwitch DirectorySP
virtual void activeDevicesUpdated() override
activeDevicesUpdated Inform children that ActiveDevices property was updated so they can snoop on the...
std::deque< std::string > m_RemainingFiles
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
INDI::PropertySwitch PlanetModeSP
float CalcTimeLeft(timeval start, float req)
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
virtual bool UpdateGuiderBin(int hor, int ver) override
CCD calls this function when Guide head binning is updated by the client. Derived classes should impl...
float GuideExposureRequest
virtual void addFITSKeywords(INDI::CCDChip *targetChip, std::vector< INDI::FITSRecord > &fitsKeyword) override
Generate FITS keywords that will be added to FIST/XISF file.
bool AbortGuideExposure() override
Abort ongoing exposure.
int DrawCcdFrame(INDI::CCDChip *targetChip)
static const constexpr char * PLANET_TAB
INDI::PropertyText getText(const char *name) const
The CCDChip class provides functionality of a CCD Chip within a CCD.
int getSubH() const
getSubH Get the height of the frame
CCD_FRAME getFrameType() const
isInterlaced
int getXRes() const
getXRes Get the horizontal resolution in pixels of the CCD Chip.
uint8_t * getFrameBuffer()
getFrameBuffer Get raw frame buffer of the CCD chip.
int getSubW() const
getSubW Get the width of the frame
int getFrameBufferSize() const
getFrameBufferSize Get allocated frame buffer size to hold the CCD image frame.
double m_InitialRampTemperature
uint32_t GetCCDCapability() const
GetCCDCapability returns the CCD capabilities.
std::unique_ptr< StreamManager > Streamer
double m_TemperatureStabilizationValue
INDI::Timer m_TemperatureCheckTimer
INDI::PropertyText ActiveDeviceTP
ActiveDeviceTP defines 4 devices the camera driver can listen to (snoop) for properties of interest s...
virtual bool UpdateCCDFrame(int x, int y, int w, int h)
CCD calls this function when CCD Frame dimension needs to be updated in the hardware....
virtual void addFITSKeywords(CCDChip *targetChip, std::vector< FITSRecord > &fitsKeywords)
Generate FITS keywords that will be added to FIST/XISF file.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool ExposureComplete(CCDChip *targetChip)
Uploads target Chip exposed buffer as FITS to the client. Derived classes should class this function ...
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
INDI::PropertyNumber TemperatureNP
TemperatureNP Camera Temperature in Celcius.
INDI::PropertyNumber ScopeInfoNP
virtual bool UpdateCCDBin(int hor, int ver)
CCD calls this function when CCD Binning needs to be updated in the hardware. Derived classes should ...
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
INDI::PropertyText BayerTP
BayerTP Bayer pattern offset and type.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual void addCaptureFormat(const CaptureFormat &format)
addCaptureFormat Add a supported camera native capture format (e.g. Mono, Bayer8.....
virtual void SetGuiderParams(int x, int y, int bpp, float xf, float yf)
Setup CCD parameters for guide head CCD. Child classes call this function to update CCD parameters.
INDI::ElapsedTimer m_TemperatureElapsedTimer
virtual bool UpdateGuiderBin(int hor, int ver)
CCD calls this function when Guide head binning is updated by the client. Derived classes should impl...
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save configuration items in XML file.
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
INDI::PropertySwitch CaptureFormatSP
Specifies Camera NATIVE capture format (e.g. Mono, RGB, RAW8..etc).
void SetCCDCapability(uint32_t cap)
SetCCDCapability Set the CCD capabilities. All fields must be initialized.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
INDI::ElapsedTimer m_TemperatureRampTimer
virtual void SetCCDParams(int x, int y, int bpp, float xf, float yf)
Setup CCD parameters for primary CCD. Child classes call this function to update CCD parameters.
double snoopedFocalLength
std::vector< CaptureFormat > m_CaptureFormats
double m_TargetTemperature
INDI::ElapsedTimer m_TemperatureStabilizationTimer
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
void setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
uint32_t getDriverInterface() const
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
void addDebugControl()
Add Debug control to the driver.
FilterInterface(DefaultDevice *defaultDevice)
FilterInterface Initiailize Filter Interface.
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process text properties.
INDI::PropertyNumber FilterSlotNP
bool updateProperties()
updateProperties Defines or Delete properties based on default device connection status
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process number properties.
void SelectFilterDone(int newpos)
The child class calls this function when the hardware successfully finished selecting a new filter wh...
void initProperties(const char *groupName)
Initialize filter wheel properties. It is recommended to call this function within initProperties() o...
bool saveConfigItems(FILE *fp)
saveConfigItems save Filter Names in config file
static std::vector< SensorDefect > generateDefects(int xres, int yres, int hotCount, int coldCount, float hotRate, uint32_t seed=1)
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * SITE_TAB
SITE_TAB Where all site information setting are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
int f_scansexa(const char *str0, double *dp)
convert sexagesimal string str AxBxC to double. x can be anything non-numeric. Any missing A,...
double range24(double r)
range24 Limits a number to be between 0-24 range.
double range360(double r)
range360 Limits an angle to be between 0-360 degrees.
Implementations for common driver routines.
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
int IUSnoopNumber(XMLEle *root, INumberVectorProperty *nvp)
Update a snooped number vector property from the given XML root element.
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
void IDSnoopDevice(const char *snooped_device, const char *snooped_property)
Function a Driver calls to snoop on another Device. Snooped messages will then arrive via ISSnoopDevi...
*brief user defined string literal for JSON values *sa std::size_t n
#define LOGF_INFO(fmt,...)
#define LOGF_WARN(fmt,...)
#define LOGF_DEBUG(fmt,...)
#define LOG_ERROR(txt)
Shorter logging macros. In order to use these macros, the function (or method) "getDeviceName()" must...
#define LOGF_ERROR(fmt,...)
const char * findXMLAttValu(XMLEle *ep, const char *name)
Find an XML element's attribute value.
XMLEle * nextXMLEle(XMLEle *ep, int init)
Iterate an XML element for a list of nesetd XML elements.
char * pcdataXMLEle(XMLEle *ep)
Return the pcdata of an XML element.
Namespace to encapsulate INDI client, drivers, and mediator classes.
void ObservedToJ2000(IEquatorialCoordinates *observed, double jd, IEquatorialCoordinates *J2000pos)
ObservedToJ2000 converts an observed position to a J2000 catalogue position removes aberration,...
@ error
throw a parse_error exception in case of a tag