///////////////////////////////////////////////////////// /// 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; }
bool SynscanDriver::readFirmware() { // Read the handset version char res[SYN_RES] = {0}; if (sendCommand("V", res)) { m_FirmwareVersion = static_cast<double>(hexStrToInteger(std::string(&res[0], 2))); m_FirmwareVersion += static_cast<double>(hexStrToInteger(std::string(&res[2], 2))) / 100; m_FirmwareVersion += static_cast<double>(hexStrToInteger(std::string(&res[4], 2))) / 10000; LOGF_INFO("Firmware version: %lf", m_FirmwareVersion); m_MountInfo[MI_FW_VERSION] = std::to_string(m_FirmwareVersion); IUSaveText(&StatusT[MI_FW_VERSION], m_MountInfo[MI_FW_VERSION].c_str()); if (m_FirmwareVersion < 3.38 || (m_FirmwareVersion >= 4.0 && m_FirmwareVersion < 4.38)) { LOGF_WARN("Firmware version is too old. Update Synscan firmware to %s", m_FirmwareVersion < 3.38 ? "v3.38+" : "v4.38+"); return false; } else return true; } else LOG_WARN("Firmware version is too old. Update Synscan firmware to v4.38+"); return false; }
void TCFS::GetFocusParams() { char response[TCFS_MAX_CMD] = { 0 }; int slope; int is_negative; dispatch_command(FRSLOP, 0, MODE_A); read_tcfs(response); if(sscanf(response, "A=%04d", &slope)<=0) { LOGF_WARN("Failed to read slope A from response: %s", response); return; } response[0] = '\0'; dispatch_command(FRSIGN, 0, MODE_A); read_tcfs(response); if(sscanf(response, "A=%01d", &is_negative)<=0) { LOGF_WARN("Failed to read slope sign A from response: %s", response); return; } FocusModeANP.np[0].value = slope * (is_negative==1?-1:1); IDSetNumber(&FocusModeANP, nullptr); response[0] = '\0'; dispatch_command(FRSLOP, 0, MODE_B); read_tcfs(response); if(sscanf(response, "B=%04d", &slope)<=0) { LOGF_WARN("Failed to read slope B from response: %s", response); return; } response[0] = '\0'; dispatch_command(FRSIGN, 0, MODE_B); read_tcfs(response); if(sscanf(response, "B=%01d", &is_negative)<=0) { LOGF_WARN("Failed to read slope sign B from response: %s", response); return; } FocusModeBNP.np[0].value = slope * (is_negative==1?-1:1); IDSetNumber(&FocusModeBNP, nullptr); }
bool StarbookDriver::updateLocation(double latitude, double longitude, double elevation) { INDI_UNUSED(elevation); if (last_known_state != starbook::INIT) { LOGF_WARN("Can't update location in %s state", starbook::STATE_TO_STR.at(last_known_state).c_str()); return false; } if (TimeT[1].text == nullptr) { LOG_WARN("Can't update location before time"); return false; } auto utc_offset = static_cast<short>(std::floor(std::strtof(TimeT[1].text, nullptr))); LOGF_WARN("UTC offset for location: %i", utc_offset); starbook::LnLat posn(latitude, longitude); starbook::ResponseCode rc = cmd_interface->SetPlace(posn, utc_offset); LogResponse("Updating location", rc); return rc == starbook::OK; }
bool StarbookDriver::performStart() { IUResetSwitch(&StartSP); if (last_known_state == starbook::INIT) { if (cmd_interface->Start()) { StartSP.s = IPS_OK; } } else { LOGF_WARN("Can't initialize in %s state, must be INIT", starbook::STATE_TO_STR.at(last_known_state).c_str()); StartSP.s = IPS_ALERT; } IDSetSwitch(&StartSP, nullptr); return true; }
bool StarbookDriver::updateTime(ln_date *utc, double utc_offset) { INDI_UNUSED(utc_offset); if (last_known_state != starbook::INIT) { LOGF_WARN("Can't update time in %s state", starbook::STATE_TO_STR.at(last_known_state).c_str()); return false; } starbook::ResponseCode rc; utc->hours += floor(utc_offset); // starbook stores local time, go figure rc = cmd_interface->SetTime(*utc); LogResponse("Updating time", rc); return rc == starbook::OK; }
bool StarbookDriver::getFirmwareVersion() { starbook::VersionResponse res; starbook::ResponseCode rc = cmd_interface->Version(res); if (rc != starbook::OK) { LogResponse("Get version", rc); return false; } if (res.major_minor < 2.7) { LOGF_WARN("Get version [OK]: %s (< 2.7) not well supported", res.full_str.c_str()); } else { LOGF_INFO("Get version [OK]: %s", res.full_str.c_str()); } IUSaveText(&VersionT[0], res.full_str.c_str()); IDSetText(&VersionTP, nullptr); return true; }
// Called by Weather::TimerHit every UpdatePeriodN[0].value seconds if we return IPS_OK or every 5 seconds otherwise IPState WeatherSafetyProxy::updateWeather() { IPState ret = IPS_ALERT; if (ScriptOrCurlS[WSP_USE_SCRIPT].s == ISS_ON) { ret = executeScript(); } else { ret = executeCurl(); } if (ret != IPS_OK) { if (Safety == WSP_SAFE) { SofterrorCount++; LOGF_WARN("Soft error %d occured during SAFE conditions, counting", SofterrorCount); if (SofterrorCount > softErrorHysteresisN[WSP_SOFT_ERROR_MAX].value) { char Warning[] = "Max softerrors reached while Weather was SAFE"; LOG_WARN(Warning); Safety = WSP_UNSAFE; setParameterValue("WEATHER_SAFETY", WSP_UNSAFE); IUSaveText(&reasonsT[0], Warning); reasonsTP.s = IPS_OK; IDSetText(&reasonsTP, nullptr); SofterrorRecoveryMode = true; ret = IPS_OK; // So that indiweather actually syncs the CriticalParameters we just set } } else { LOG_WARN("Soft error occured during UNSAFE conditions, ignore"); SofterrorCount = 0; SofterrorRecoveryCount = 0; } } else { SofterrorCount = 0; } return ret; }
bool ATIKCCD::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { if (dev != nullptr && !strcmp(dev, getDeviceName())) { // Gain/Offset Presets if (!strcmp(name, ControlPresetsSP.name)) { int prevIndex = IUFindOnSwitchIndex(&ControlPresetsSP); IUUpdateSwitch(&ControlPresetsSP, states, names, n); int targetIndex = IUFindOnSwitchIndex(&ControlPresetsSP); uint16_t value = static_cast<uint16_t>(targetIndex + 2); uint8_t *data = reinterpret_cast<uint8_t*>(&value); int rc = ArtemisCameraSpecificOptionSetData(hCam, ID_AtikHorizonGOPresetMode, data, 2); if (rc != ARTEMIS_OK) { ControlPresetsSP.s = IPS_ALERT; IUResetSwitch(&ControlPresetsSP); ControlPresetsS[prevIndex].s = ISS_ON; } else ControlPresetsSP.s = IPS_OK; IDSetSwitch(&ControlPresetsSP, nullptr); return true; } // Cooler controler if (!strcmp(name, CoolerSP.name)) { if (IUUpdateSwitch(&CoolerSP, states, names, n) < 0) { CoolerSP.s = IPS_ALERT; IDSetSwitch(&CoolerSP, nullptr); return true; } bool enabled = (CoolerS[COOLER_ON].s == ISS_ON); // If user turns on cooler, but the requested temperature is higher than current temperature // then we set temperature to zero degrees. If that was still higher than current temperature // we return an error if (enabled && TemperatureRequest > TemperatureN[0].value) { TemperatureRequest = 0; // If current temperature is still lower than zero, then we shouldn't risk // setting temperature to any arbitrary value. Instead, we report an error and ask // user to explicitly set the requested temperature. if (TemperatureRequest > TemperatureN[0].value) { CoolerS[COOLER_ON].s = ISS_OFF; CoolerS[COOLER_OFF].s = ISS_OFF; CoolerSP.s = IPS_ALERT; LOGF_WARN("Cannot manually activate cooler since current temperature is %.2f. To activate cooler, request a lower temperature.", TemperatureN[0].value); IDSetSwitch(&CoolerSP, nullptr); return true; } SetTemperature(0); return true; } return activateCooler(enabled); } } return INDI::CCD::ISNewSwitch(dev, name, states, names, n); }