Esempio n. 1
0
bool LX200SS2000PC::setCalenderDate(int year, int month, int day) {
  // This method differs from the setCalenderDate function in lx200driver.cpp
  // in that it reads and checks the complete respons from the SkySensor2000PC.
  // In addition, this method only sends the date when it differs from the date
  // of the SkySensor2000PC because the resulting update of the planetary data
  // takes quite some time.
  bool result = true;
  int  ss_year, ss_month, ss_day;
  const bool send_to_skysensor = (!getCalenderDate(ss_year,ss_month,ss_day) || year != ss_year || month != ss_month || day != ss_day );
  DEBUGF(INDI::Logger::DBG_DEBUG, "LX200SS2000PC::setCalenderDate(): Driver date %02d/%02d/%02d, SS2000PC date %02d/%02d/%02d.", month, day, year, ss_month, ss_day, ss_year);
  if (send_to_skysensor) {
    char buffer[64];
    int  nbytes_written = 0;
    snprintf(buffer, sizeof(buffer), ":SC %02d/%02d/%02d#", month, day, (year%100));
    result = ( tty_write_string(PortFD, buffer, &nbytes_written) == TTY_OK && nbytes_written == strlen(buffer) );
    if (result) {
      int nbytes_read = 0;
      result = ( tty_read(PortFD, buffer, 1, ShortTimeOut, &nbytes_read) == TTY_OK && nbytes_read == 1 && buffer[0] == '1' );    
      if (result) {
	if (tty_read_section(PortFD, buffer, '#', ShortTimeOut, &nbytes_read) != TTY_OK || strncmp(buffer,"Updating        planetary data#",24) != 0) {
	  DEBUGF(INDI::Logger::DBG_ERROR, "LX200SS2000PC::setCalenderDate(): Received unexpected first line '%s'.", buffer);
	  result = false;
	}
	else if (tty_read_section(PortFD, buffer, '#', LongTimeOut, &nbytes_read) != TTY_OK && strncmp(buffer,"                              #",24) != 0) {
	  DEBUGF(INDI::Logger::DBG_ERROR, "LX200SS2000PC::setCalenderDate(): Received unexpected second line '%s'.", buffer);
	  result = false;
	}
      }
    }
  }
  return result;
}
Esempio n. 2
0
int ioptronHC8406::ioptronHC8406SyncCMR(char *matchedObject)
{
    int error_type;
    int nbytes_write = 0;
    int nbytes_read  = 0;

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD <%s>", ":CMR#");

    if ((error_type = tty_write_string(PortFD, ":CMR#", &nbytes_write)) != TTY_OK)
        return error_type;

    if ((error_type = tty_read_section(PortFD, matchedObject, '#', 3, &nbytes_read)) != TTY_OK)
        return error_type;

    matchedObject[nbytes_read - 1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES <%s>", matchedObject);

    /* Sleep 10ms before flushing. This solves some issues with LX200 compatible devices. */
    usleep(10000);

    tcflush(PortFD, TCIFLUSH);

    return 0;
}
Esempio n. 3
0
bool ArmPlat::slpSendRxInt( char *command, int *rcode )
{
    int nbytes_wrrd = 0;
    int rc;
    char errstr[MAXRBUF];
    char res[SLP_SEND_BUF_SIZE]={0};

    LOGF_DEBUG("Tx [%s]", command);
    //tty_set_debug( 1 );
    if ((rc = tty_write_string(PortFD, command, &nbytes_wrrd)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        //IDLog( "ERROR Tx: <%s>\n", errstr );
        LOGF_ERROR("Send error: %s.", errstr);
        return false;
    }

    if ((rc = tty_read_section(PortFD, res, '#', ArmPlat_TIMEOUT, &nbytes_wrrd)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        //IDLog( "ERROR Rx: <%s> error msg <%s>\n", res, errstr );
        LOGF_ERROR("Echo receiving error: %s.", errstr);
        return false;
    }
    LOGF_DEBUG("Rx [%s]", res);
    //if ( ( strstr( command, "getpos" ) == nullptr ) && ( strstr( command, "temps" ) == nullptr ) )
        //IDLog( "Rx: <%s>\n", res );
    return getIntResultCode( command, res, rcode );
}
Esempio n. 4
0
bool lacerta_mfoc::Handshake()
{
    char MFOC_cmd[32] = ": Q #";
    char MFOC_res[32] = {0};
    char MFOC_res_type[32] = "0";
    int MFOC_pos_measd = 0;
    int nbytes_written = 0;
    int nbytes_read = 0;


    tty_write_string(PortFD, MFOC_cmd, &nbytes_written);
    LOGF_INFO("CMD <%s>", MFOC_cmd);
    tty_read_section(PortFD, MFOC_res, 0xD, FOCUSMFOC_TIMEOUT, &nbytes_read);
    LOGF_DEBUG("RES <%s>", MFOC_res_type);

    sscanf(MFOC_res, "%s %d", MFOC_res_type, &MFOC_pos_measd);

    if (MFOC_res_type[0] == 'P')
    {
        FocusAbsPosN[0].value = MFOC_pos_measd;
        FocusAbsPosNP.s = IPS_OK;
        return true;
    }

    return false;
}
Esempio n. 5
0
// Send a command to the mount. Return the number of bytes received or 0 if
// case of error
// commands are null terminated, replies end with /n
int QFW::send_command(int fd, const char* cmd, char *resp)
{
    int err;
    int nbytes = 0;
    char errmsg[MAXRBUF];
    int cmd_len = strlen(cmd);
    char dmp[255];

    dump(dmp, cmd);
    LOGF_DEBUG("CMD <%s>", dmp);

    tcflush(fd, TCIOFLUSH);
    if ((err = tty_write(fd, cmd, cmd_len, &nbytes)) != TTY_OK)
    {
        tty_error_msg(err, errmsg, MAXRBUF);
        LOGF_ERROR("Serial write error: %s", errmsg);
        return 0;
    }

    err = tty_read_section(fd, resp, '\n', QUANTUM_TIMEOUT, &nbytes);
    if (err)
    {
        tty_error_msg(err, errmsg, MAXRBUF);
        LOGF_ERROR("Serial read error: %s", errmsg);
        return 0;
    }

    resp[nbytes] = 0;
    dump(dmp, resp);
    LOGF_DEBUG("RES <%s>", dmp);
    return nbytes;
}
Esempio n. 6
0
File: tcfs.cpp Progetto: djibb/indi
bool TCFS::read_tcfs(char *response, bool silent)
{
    int err_code = 0, nbytes_read = 0;
    char err_msg[TCFS_ERROR_BUFFER];

    if (isSimulation())
    {
        strncpy(response, "SIMULATION", TCFS_MAX_CMD);
        return true;
    }

    // Read until encountring a CR
    if ((err_code = tty_read_section(PortFD, response, 0x0D, 2, &nbytes_read)) != TTY_OK)
    {
        if (!silent)
        {
            tty_error_msg(err_code, err_msg, 32);
            LOGF_ERROR("TTY error detected: %s", err_msg);
        }

        return false;
    }

    // Remove LF & CR
    response[nbytes_read - 2] = '\0';

    LOGF_DEBUG("RES <%s>", response);

    return true;
}
Esempio n. 7
0
bool SestoSenso::isCommandOK(const char *cmd)
{
    int nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF], resp[16];

    char expectedResp[16];
    snprintf(expectedResp, 16, "%sok!", cmd);

    if (isSimulation())
    {
        strncpy(resp, expectedResp, 16);
        nbytes_read = strlen(resp)+1;
    }
    else
    {
        if ((rc = tty_read_section(PortFD, resp, 0xD, SESTOSENSO_TIMEOUT, &nbytes_read)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error for command %s: %s.", __FUNCTION__, cmd, errstr);
            return false;
        }
    }

    resp[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES <%s>", resp);

    return (!strcmp(resp, expectedResp));
}
Esempio n. 8
0
bool lacerta_mfoc::SetBacklash(double values[], char *names[], int n)
{
    LOGF_DEBUG("-> BACKLASH_SETTINGS", 0);
    char MFOC_cmd[32]  = ": B ";
    char MFOC_res[32]  = {0};
    int nbytes_read    =  0;
    int nbytes_written =  0;
    int MFOC_tdir_measd = 0;
    int bl_int = 0;
    char bl_char[32]  = {0};
    char MFOC_res_type[32]  = "0";
    BacklashNP.s = IPS_OK;
    IUUpdateNumber(&BacklashNP, values, names, n);
    bl_int = BacklashN[0].value;
    sprintf(bl_char, "%d", bl_int);
    strcat(bl_char, " #");
    strcat(MFOC_cmd, bl_char);

    tty_write_string(PortFD, MFOC_cmd, &nbytes_written);
    LOGF_DEBUG("CMD <%s>", MFOC_cmd);
    tty_write_string(PortFD, ": J #", &nbytes_written);

    tty_read_section(PortFD, MFOC_res, 0xD, FOCUSMFOC_TIMEOUT, &nbytes_read);

    sscanf (MFOC_res, "%s %d", MFOC_res_type, &MFOC_tdir_measd);

    LOGF_DEBUG("RES <%s>", MFOC_res);

    IDSetNumber(&BacklashNP, nullptr);

    return true;
}
Esempio n. 9
0
bool lacerta_mfoc::SetTempComp(double values[], char *names[], int n)
{
    LOGF_INFO("-> TEMPCOMP_SETTINGS", 0);
    char MFOC_cmd[32]  = ": D ";
    char MFOC_res[32]  = {0};
    int nbytes_read    =  0;
    int nbytes_written =  0;
    int MFOC_tc_measd = 0;
    int tc_int = 0;
    char tc_char[32]  = {0};
    char MFOC_res_type[32]  = "0";
    TempCompNP.s = IPS_OK;
    IUUpdateNumber(&TempCompNP, values, names, n);
    tc_int = TempCompN[0].value;
    sprintf(tc_char, "%d", tc_int);
    strcat(tc_char, " #");
    strcat(MFOC_cmd, tc_char);

    tty_write_string(PortFD, MFOC_cmd, &nbytes_written);
    LOGF_DEBUG("CMD <%s>", MFOC_cmd);
    tty_write_string(PortFD, ": U #", &nbytes_written);

    tty_read_section(PortFD, MFOC_res, 0xD, FOCUSMFOC_TIMEOUT, &nbytes_read);

    sscanf (MFOC_res, "%s %d", MFOC_res_type, &MFOC_tc_measd);

    LOGF_DEBUG("RES <%s>", MFOC_res);

    IDSetNumber(&TempCompNP, nullptr);

    return true;
}
Esempio n. 10
0
bool lacerta_mfoc::SetFocuserMaxPosition(uint32_t ticks)
{
    char MFOC_cmd[32]  = ": G ";
    char MFOC_res[32]  = {0};
    int nbytes_read    =  0;
    int nbytes_written =  0;
    int MFOC_pm_measd = 0;
    char pm_char[32]  = {0};
    char MFOC_res_type[32]  = "0";

    sprintf(pm_char, "%d", ticks);
    strcat(pm_char, " #");
    strcat(MFOC_cmd, pm_char);

    tty_write_string(PortFD, MFOC_cmd, &nbytes_written);
    LOGF_DEBUG("CMD <%s>", MFOC_cmd);
    tty_write_string(PortFD, ": O #", &nbytes_written);

    tty_read_section(PortFD, MFOC_res, 0xD, FOCUSMFOC_TIMEOUT, &nbytes_read);

    sscanf (MFOC_res, "%s %d", MFOC_res_type, &MFOC_pm_measd);

    LOGF_DEBUG("RES <%s>", MFOC_res);
    return true;
}
Esempio n. 11
0
int ioptronHC8406::getCommandString(int fd, char *data, const char *cmd)
{
    char *term;
    int error_type;
    int nbytes_write = 0, nbytes_read = 0;


    if ((error_type = tty_write_string(fd, cmd, &nbytes_write)) != TTY_OK)
        return error_type;

    error_type = tty_read_section(fd, data, '#', ioptronHC8406_TIMEOUT, &nbytes_read);
    tcflush(fd, TCIFLUSH);

    if (error_type != TTY_OK)
        return error_type;

    term = strchr(data, '#');
    if (term)
        *term = '\0';



    return 0;

}
Esempio n. 12
0
bool FlipFlat::ping()
{    
    int nbytes_written=0, nbytes_read=0, rc=-1;
    char errstr[MAXRBUF];
    char command[FLAT_CMD];
    char response[FLAT_RES];
    int i=0;

    tcflush(PortFD, TCIOFLUSH);

    strncpy(command, ">P000", FLAT_CMD);

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", command);

    command[FLAT_CMD-1] = 0xA;

    for (i=0; i < 3; i++)
    {
        if ( (rc = tty_write(PortFD, command, FLAT_CMD, &nbytes_written)) != TTY_OK)
            continue;

        if ( (rc = tty_read_section(PortFD, response, 0xA, 1, &nbytes_read)) != TTY_OK)
            continue;
        else
            break;
    }

    if (i==3)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s: %s.", command, errstr);
        return false;
    }

    response[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", response);

    char productString[3];
    snprintf(productString, 3, "%s", response+2);

    rc = sscanf(productString, "%d", &productID);

    if (rc <= 0)
    {
        DEBUGF(INDI::Logger::DBG_ERROR, "Unable to parse input (%s)", response);
        return false;
    }

    if (productID == 99)
    {
        setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE | DUSTCAP_INTERFACE);
        isFlipFlat = true;
    }
    else
        isFlipFlat = false;

    return true;
}
Esempio n. 13
0
bool get_ieqpro_radec_firmware(int fd, FirmwareInfo *info)
{
    char cmd[] = ":FW2#";
    int errcode = 0;
    char errmsg[MAXRBUF];
    char response[16];
    int nbytes_read=0;
    int nbytes_written=0;

    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);

    if (ieqpro_simulation)
    {
        strcpy(response, "140324140101#");
        nbytes_read = strlen(response);
    }
    else
    {
        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
        {
            tty_error_msg(errcode, errmsg, MAXRBUF);
            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
            return false;
        }

        if ( (errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
        {
            tty_error_msg(errcode, errmsg, MAXRBUF);
            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
            return false;
        }
    }

    if (nbytes_read > 0)
    {
      response[nbytes_read] = '\0';
      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);

      if (nbytes_read == 13)
      {
          char ra[6], dec[6];

          strncpy(ra, response, 6);
          strncpy(dec, response + 6, 6);

          info->RAFirmware.assign(ra, 6);
          info->DEFirmware.assign(dec, 6);

          tcflush(fd, TCIFLUSH);

          return true;
      }
    }

    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 13.", nbytes_read);
    return false;
}
Esempio n. 14
0
bool get_ieqpro_status(int fd, IEQInfo *info)
{
    char cmd[] = ":GAS#";
    int errcode = 0;
    char errmsg[MAXRBUF];
    char response[8];
    int nbytes_read=0;
    int nbytes_written=0;

    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_EXTRA_1, "CMD (%s)", cmd);

    if (ieqpro_simulation)
    {
        snprintf(response, 8, "%d%d%d%d%d%d#", simInfo.gpsStatus, simInfo.systemStatus, simInfo.trackRate, simInfo.slewRate+1, simInfo.timeSource+1, simInfo.hemisphere);
        nbytes_read = strlen(response);
    }
    else
    {
        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
        {
            tty_error_msg(errcode, errmsg, MAXRBUF);
            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
            return false;
        }

        if ( (errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
        {
            tty_error_msg(errcode, errmsg, MAXRBUF);
            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
            return false;
        }
    }

    if (nbytes_read > 0)
    {
      response[nbytes_read] = '\0';
      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_EXTRA_1, "RES (%s)", response);

      if (nbytes_read == 7)
      {
          info->gpsStatus       = (IEQ_GPS_STATUS)      (response[0] - '0');
          info->systemStatus    = (IEQ_SYSTEM_STATUS)   (response[1] - '0');
          info->trackRate       = (IEQ_TRACK_RATE)      (response[2] - '0');
          info->slewRate        = (IEQ_SLEW_RATE)       (response[3] - '0' - 1);
          info->timeSource      = (IEQ_TIME_SOURCE)     (response[4] - '0' - 1);
          info->hemisphere      = (IEQ_HEMISPHERE)      (response[5] - '0');

         tcflush(fd, TCIFLUSH);

          return true;
      }
    }

    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 7.", nbytes_read);
    return false;
}
Esempio n. 15
0
bool FlipFlat::SetLightBoxBrightness(uint16_t value)
{    
    int nbytes_written=0, nbytes_read=0, rc=-1;
    char errstr[MAXRBUF];
    char command[FLAT_CMD];
    char response[FLAT_RES];

    tcflush(PortFD, TCIOFLUSH);

    snprintf(command, FLAT_CMD, ">B%03d", value);

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", command);

    command[FLAT_CMD-1] = 0xA;

    if ( (rc = tty_write(PortFD, command, FLAT_CMD, &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", command, errstr);
        return false;
    }

    if ( (rc = tty_read_section(PortFD, response, 0xA, FLAT_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s: %s.", command, errstr);
        return false;
    }

    response[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", response);

    char brightnessString[4];
    snprintf(brightnessString, 4, "%s", response+4 );

    int brightnessValue=0;
    rc = sscanf(brightnessString, "%d", &brightnessValue);

    if (rc <= 0)
    {
        DEBUGF(INDI::Logger::DBG_ERROR, "Unable to parse brightness value (%s)", response);
        return false;
    }

    if (brightnessValue != prevBrightness)
    {
        prevBrightness = brightnessValue;
        LightIntensityN[0].value = brightnessValue;
        IDSetNumber(&LightIntensityNP, NULL);
    }

    return true;

}
Esempio n. 16
0
bool FlipFlat::EnableLightBox(bool enable)
{    
    int nbytes_written=0, nbytes_read=0, rc=-1;
    char errstr[MAXRBUF];
    char command[FLAT_CMD];
    char response[FLAT_RES];

    if (isFlipFlat && ParkCapS[1].s == ISS_ON)
    {
        DEBUG(INDI::Logger::DBG_ERROR, "Cannot control light while cap is unparked.");
        return false;
    }

    tcflush(PortFD, TCIOFLUSH);

    if (enable)
        strncpy(command, ">L000", FLAT_CMD);
    else
        strncpy(command, ">D000", FLAT_CMD);

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", command);

    command[FLAT_CMD-1] = 0xA;

    if ( (rc = tty_write(PortFD, command, FLAT_CMD, &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", command, errstr);
        return false;
    }

    if ( (rc = tty_read_section(PortFD, response, 0xA, FLAT_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s: %s.", command, errstr);
        return false;
    }

    response[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", response);

    char expectedResponse[FLAT_RES];
    if (enable)
        snprintf(expectedResponse, FLAT_RES, "*L%02d000", productID);
    else
        snprintf(expectedResponse, FLAT_RES, "*D%02d000", productID);

    if (!strcmp(response, expectedResponse))
        return true;
    else
        return false;

}
Esempio n. 17
0
bool Driver::sendCommand(const char *command, int count, char *response, uint8_t timeout, uint8_t debugLog)
{
    int errCode = 0;
    int nbytes_read    = 0;
    int nbytes_written = 0;
    char errMsg[MAXRBUF];
    char res[IOP_BUFFER] = {0};

    DEBUGFDEVICE(m_DeviceName, debugLog, "CMD <%s>", command);

    if (m_Simulation)
        return true;

    tcflush(PortFD, TCIOFLUSH);

    if ((errCode = tty_write(PortFD, command, strlen(command), &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(errCode, errMsg, MAXRBUF);
        DEBUGFDEVICE(m_DeviceName, INDI::Logger::DBG_ERROR, "Write Command Error: %s", errMsg);
        return false;
    }

    if (count == 0)
        return true;

    if (count == -1)
        errCode = tty_read_section(PortFD, res, '#', timeout, &nbytes_read);
    else
        errCode = tty_read(PortFD, res, count, timeout, &nbytes_read);

    if (errCode != TTY_OK)
    {
        tty_error_msg(errCode, errMsg, MAXRBUF);
        DEBUGFDEVICE(m_DeviceName, INDI::Logger::DBG_ERROR, "Read Command Error: %s", errMsg);
        return false;
    }

    // Remove the extra #
    if (count == -1)
        res[nbytes_read-1] = 0;

    DEBUGFDEVICE(m_DeviceName, debugLog, "RES <%s>", res);

    tcflush(PortFD, TCIOFLUSH);

    // Copy response to buffer
    if (response)
        strncpy(response, res, IOP_BUFFER);

    if (count == -1 || (count == 1 && res[0] == '1') || count == nbytes_read)
        return true;

    return false;
}
Esempio n. 18
0
bool check_ieqpro_connection(int fd)
{
  char initCMD[] = ":V#";
  int errcode = 0;
  char errmsg[MAXRBUF];
  char response[8];
  int nbytes_read=0;
  int nbytes_written=0;

  DEBUGDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "Initializing IOptron using :V# CMD...");

  for (int i=0; i < 2; i++)
  {
      if (ieqpro_simulation)
      {
          strcpy(response, "V1.00#");
          nbytes_read= strlen(response);
      }
      else
      {
          if ( (errcode = tty_write(fd, initCMD, 3, &nbytes_written)) != TTY_OK)
          {
              tty_error_msg(errcode, errmsg, MAXRBUF);
              DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
              usleep(50000);
              continue;
          }

          if ( (errcode = tty_read_section(fd, response, '#', IEQPRO_TIMEOUT, &nbytes_read)))
          {
              tty_error_msg(errcode, errmsg, MAXRBUF);
              DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);
              usleep(50000);
              continue;
          }
      }

      if (nbytes_read > 0)
      {
        response[nbytes_read] = '\0';
        DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);

        if (!strcmp(response, "V1.00#"))
            return true;
      }

      usleep(50000);
  }

  return false;
}
Esempio n. 19
0
bool SestoSenso::isMotionComplete()
{
    int nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF];
    char resp[16]={0};

    if (isSimulation())
    {
        int32_t nextPos = FocusAbsPosN[0].value;
        int32_t targPos = static_cast<int32_t>(targetPos);

        if (targPos > nextPos)
            nextPos += 250;
        else if (targPos < nextPos)
            nextPos -= 250;

        if (abs(nextPos-targPos) < 250)
            nextPos = targetPos;
        else if (nextPos < 0)
            nextPos = 0;
        else if (nextPos > FocusAbsPosN[0].max)
            nextPos = FocusAbsPosN[0].max;

        snprintf(resp, 16, "%d", nextPos);
        nbytes_read = strlen(resp)+1;
    }
    else
    {
        if ((rc = tty_read_section(PortFD, resp, 0xD, SESTOSENSO_TIMEOUT, &nbytes_read)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            return false;
        }
    }

    resp[nbytes_read-1] = '\0';

    if (!strcmp(resp, "GTok!"))
        return true;

    uint32_t newPos = atoi(resp);
    FocusAbsPosN[0].value = newPos;

    if (newPos == targetPos)
        return true;

    return false;
}
Esempio n. 20
0
bool MoonLiteDRO::updateStepDelay()
{
    int nbytes_written = 0, nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF];
    char resp[3]={0};
    char cmd[DRO_CMD]={0};
    short speed;

    if (m_ID == 1)
        strncpy(cmd, ":GD#", DRO_CMD);
    else
        strncpy(cmd, ":2GD#", DRO_CMD);

    LOGF_DEBUG("CMD <%s>", cmd);

    tcflush(PortFD, TCIOFLUSH);

    if ((rc = tty_write_string(PortFD, cmd, &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        LOGF_ERROR("updateStepDelay error: %s.", errstr);
        return false;
    }

    if ((rc = tty_read_section(PortFD, resp, '#', MOONLITEDRO_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        LOGF_ERROR("updateStepDelay error: %s.", errstr);
        return false;
    }

    tcflush(PortFD, TCIOFLUSH);

    LOGF_DEBUG("RES <%s>", resp);

    rc = sscanf(resp, "%hX", &speed);

    if (rc > 0)
    {
        int focus_speed = -1;
        while (speed > 0)
        {
            speed >>= 1;
            focus_speed++;
        }

        StepDelayN[0].value = focus_speed;
    }
Esempio n. 21
0
bool XAGYLWheel::getOffset(int filter)
{
    int nbytes_written=0, nbytes_read=0, rc=-1;
    char errstr[MAXRBUF];
    char command[XAGYL_MAXBUF];
    char resp[XAGYL_MAXBUF];

    tcflush(PortFD, TCIOFLUSH);

    snprintf(command, XAGYL_MAXBUF, "O%d", filter+1);

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", command);

    if (!sim && (rc = tty_write(PortFD, command, strlen(command), &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", command, errstr);
        return false;
    }

    if (sim)
           snprintf(resp, XAGYL_MAXBUF, "P%d Offset %02d", filter+1, simData.offset[filter]);
    else
    {
        if ( (rc = tty_read_section(PortFD, resp, 0xA, XAGYL_MAXBUF, &nbytes_read)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s: %s.", command, errstr);
            return false;
        }

        resp[nbytes_read-1] = '\0';

    }

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", resp);

    int filter_num=0, offset=0;
    rc = sscanf(resp, "P%d Offset %d", &filter_num, &offset);

    if (rc > 0)
    {
        OffsetN[filter_num-1].value = offset;
        return true;
    }
    else
        return false;
}
Esempio n. 22
0
bool ioptronHC8406::checkConnection()
{
    if (isSimulation())
        return true;

    char initCMD[] = ":V#";
    int errcode    = 0;
    char errmsg[MAXRBUF];
    char response[8];
    int nbytes_read    = 0;
    int nbytes_written = 0;

    DEBUG(INDI::Logger::DBG_DEBUG, "Initializing iOptron using :V# CMD...");

    for (int i = 0; i < 2; i++)
    {
        if ((errcode = tty_write(PortFD, initCMD, 3, &nbytes_written)) != TTY_OK)
        {
            tty_error_msg(errcode, errmsg, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s", errmsg);
            usleep(50000);
            continue;
        }

        if ((errcode = tty_read_section(PortFD, response, '#', 3, &nbytes_read)))
        {
            tty_error_msg(errcode, errmsg, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s", errmsg);
            usleep(50000);
            continue;
        }

        if (nbytes_read > 0)
        {
            response[nbytes_read] = '\0';
            DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", response);

            if (!strcmp(response, "V1.00#"))
                return true;
        }

        usleep(50000);
    }

    return false;
}
Esempio n. 23
0
bool SestoSenso::updateTemperature()
{
    int nbytes_written = 0, nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF];
    char resp[16]={0};

    DEBUG(INDI::Logger::DBG_DEBUG, "CMD <#QT!>");

    if (isSimulation())
    {
        strncpy(resp, "23.45", 16);
        nbytes_read = strlen(resp) + 1;
    }
    else
    {
        tcflush(PortFD, TCIOFLUSH);

        if ((rc = tty_write(PortFD, "#QT!", 4, &nbytes_written)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            TemperatureNP.s = IPS_ALERT;
            return false;
        }

        if ((rc = tty_read_section(PortFD, resp, 0xD, SESTOSENSO_TIMEOUT, &nbytes_read)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            TemperatureNP.s = IPS_ALERT;
            return false;
        }

        tcflush(PortFD, TCIOFLUSH);
    }

    resp[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES <%s>", resp);

    TemperatureN[0].value = atof(resp);
    TemperatureNP.s = (TemperatureN[0].value == 99.00) ? IPS_IDLE : IPS_OK;

    return true;
}
Esempio n. 24
0
bool SestoSenso::updatePosition()
{
    int nbytes_written = 0, nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF];
    char resp[16]={0};

    DEBUG(INDI::Logger::DBG_DEBUG, "CMD <#QP!>");

    if (isSimulation())
    {
        snprintf(resp, 16, "%d", static_cast<uint32_t>(FocusAbsPosN[0].value));
        nbytes_read = strlen(resp)+1;
    }
    else
    {
        tcflush(PortFD, TCIOFLUSH);

        if ((rc = tty_write(PortFD, "#QP!", 4, &nbytes_written)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            FocusAbsPosNP.s = IPS_ALERT;
            return false;
        }

        if ((rc = tty_read_section(PortFD, resp, 0xD, SESTOSENSO_TIMEOUT, &nbytes_read)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            FocusAbsPosNP.s = IPS_ALERT;
            return false;
        }

        tcflush(PortFD, TCIOFLUSH);
    }

    resp[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES <%s>", resp);

    FocusAbsPosN[0].value = atoi(resp);
    FocusAbsPosNP.s = IPS_OK;

    return true;
}
Esempio n. 25
0
bool Paramount::Handshake()
{
    if (isSimulation())
        return true;

    int rc = 0, nbytes_written = 0, nbytes_read = 0;
    char pCMD[MAXRBUF]={0}, pRES[MAXRBUF]={0};

    strncpy(pCMD,
            "/* Java Script */"
            "var Out;"
            "sky6RASCOMTele.ConnectAndDoNotUnpark();"
            "Out = sky6RASCOMTele.IsConnected;",
            MAXRBUF);

    LOGF_DEBUG("CMD: %s", pCMD);

    if ((rc = tty_write_string(PortFD, pCMD, &nbytes_written)) != TTY_OK)
    {
        LOG_ERROR("Error writing to TheSky6 TCP server.");
        return false;
    }

    // Should we read until we encounter string terminator? or what?
    if (static_cast<int>(rc == tty_read_section(PortFD, pRES, '\0', PARAMOUNT_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        LOG_ERROR("Error reading from TheSky6 TCP server.");
        return false;
    }

    LOGF_DEBUG("RES: %s", pRES);
    int isTelescopeConnected = -1;

    std::regex rgx(R"((\d+)\|(.+)\. Error = (\d+)\.)");
    std::smatch match;
    std::string input(pRES);
    if (std::regex_search(input, match, rgx))
        isTelescopeConnected = atoi(match.str(1).c_str());

    if (isTelescopeConnected <= 0)
    {
        LOGF_ERROR("Error connecting to telescope: %s (%d).", match.str(1).c_str(),
               atoi(match.str(2).c_str()));
        return false;
    }
Esempio n. 26
0
IPState FlipFlat::UnParkCap()
{
    int nbytes_written=0, nbytes_read=0, rc=-1;
    char errstr[MAXRBUF];
    char command[FLAT_CMD];
    char response[FLAT_RES];

    tcflush(PortFD, TCIOFLUSH);

    strncpy(command, ">O000", FLAT_CMD);

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", command);

    command[FLAT_CMD-1] = 0xA;

    if ( (rc = tty_write(PortFD, command, FLAT_CMD, &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", command, errstr);
        return IPS_ALERT;
    }

    if ( (rc = tty_read_section(PortFD, response, 0xA, FLAT_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s: %s.", command, errstr);
        return IPS_ALERT;
    }

    response[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", response);

    char expectedResponse[FLAT_RES];
    snprintf(expectedResponse, FLAT_RES, "*O%02d000", productID);

    if (!strcmp(response, expectedResponse))
    {
        // Set cover status to random value outside of range to force it to refresh
        prevCoverStatus = 10;
        return IPS_BUSY;
    }
    else
        return IPS_ALERT;
}
Esempio n. 27
0
bool MoonLite::updateTemperature()
{
    int nbytes_written = 0, nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF];
    char resp[16]={0};

    tcflush(PortFD, TCIOFLUSH);

    tty_write(PortFD, ":C#", 3, &nbytes_written);

    if ((rc = tty_write(PortFD, ":GT#", 4, &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        LOGF_ERROR("updateTemperature error: %s.", errstr);
        return false;
    }

    if ((rc = tty_read_section(PortFD, resp, '#', MOONLITE_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        LOGF_ERROR("updateTemperature error: %s.", errstr);
        return false;
    }

    tcflush(PortFD, TCIOFLUSH);

    resp[nbytes_read-1] = '\0';

    uint32_t temp = 0;
    rc = sscanf(resp, "%X", &temp);

    if (rc > 0)
    {
        // Signed hex
        TemperatureN[0].value = static_cast<int16_t>(temp) / 2.0;
    }
    else
    {
        LOGF_ERROR("Unknown error: focuser temperature value (%s)", resp);
        return false;
    }

    return true;
}
Esempio n. 28
0
bool SestoSenso::Ack()
{
    int nbytes_written = 0, nbytes_read = 0, rc = -1;
    char errstr[MAXRBUF];
    char resp[16]={0};

    DEBUG(INDI::Logger::DBG_DEBUG, "CMD <#QF!>");

    if (isSimulation())
    {
        strncpy(resp, "1.0 Simulation", 16);
        nbytes_read = strlen(resp) + 1;
    }
    else
    {
        tcflush(PortFD, TCIOFLUSH);

        if ((rc = tty_write(PortFD, "#QF!", 4, &nbytes_written)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            return false;
        }

        if ((rc = tty_read_section(PortFD, resp, 0xD, SESTOSENSO_TIMEOUT, &nbytes_read)) != TTY_OK)
        {
            tty_error_msg(rc, errstr, MAXRBUF);
            DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", __FUNCTION__, errstr);
            return false;
        }

        tcflush(PortFD, TCIOFLUSH);
    }

    resp[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES <%s>", resp);

    IUSaveText(&FirmwareT[0], resp);

    return true;
}
Esempio n. 29
0
void ioptronHC8406::syncSideOfPier()
{
    const char *cmd = ":pS#";
    // Response
    char response[16] = { 0 };
    int rc = 0, nbytes_read = 0, nbytes_written = 0;

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD: <%s>", cmd);

    tcflush(PortFD, TCIOFLUSH);

    if ((rc = tty_write(PortFD, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)
    {
        char errmsg[256];
        tty_error_msg(rc, errmsg, 256);
        DEBUGF(INDI::Logger::DBG_ERROR, "Error writing to device %s (%d)", errmsg, rc);
        return;
    }

    // Read Side
    if ((rc = tty_read_section(PortFD, response, '#', 3, &nbytes_read)) != TTY_OK)
    {
        char errmsg[256];
        tty_error_msg(rc, errmsg, 256);
        DEBUGF(INDI::Logger::DBG_ERROR, "Error reading from device %s (%d)", errmsg, rc);
        return;
    }

    response[nbytes_read - 1] = '\0';

    tcflush(PortFD, TCIOFLUSH);

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES: <%s>", response);

    if (!strcmp(response, "East"))
        setPierSide(INDI::Telescope::PIER_EAST);
    else
        setPierSide(INDI::Telescope::PIER_WEST);

}
Esempio n. 30
0
bool FlipFlat::getFirmwareVersion()
{
    int nbytes_written=0, nbytes_read=0, rc=-1;
    char errstr[MAXRBUF];
    char command[FLAT_CMD];
    char response[FLAT_RES];

    tcflush(PortFD, TCIOFLUSH);

    strncpy(command, ">V000", FLAT_CMD);

    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", command);

    command[FLAT_CMD-1] = 0xA;

    if ( (rc = tty_write(PortFD, command, FLAT_CMD, &nbytes_written)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s error: %s.", command, errstr);
        return false;
    }

    if ( (rc = tty_read_section(PortFD, response, 0xA, FLAT_TIMEOUT, &nbytes_read)) != TTY_OK)
    {
        tty_error_msg(rc, errstr, MAXRBUF);
        DEBUGF(INDI::Logger::DBG_ERROR, "%s: %s.", command, errstr);
        return false;
    }

    response[nbytes_read-1] = '\0';

    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", response);

    char versionString[4];
    snprintf(versionString, 4, "%s", response+4 );
    IUSaveText(&FirmwareT[0], versionString);
    IDSetText(&FirmwareTP, NULL);

    return true;
}