void NeoControl::updateRtc() { if(screen != ScreenRtc) return; QDateTime rtcNow = Qtopia::rtcNow(); QString rtcDate = Qtopia::readFile("/sys/class/rtc/rtc0/date").trimmed(); QString rtcTime = Qtopia::readFile("/sys/class/rtc/rtc0/time").trimmed(); QByteArray wakealarmStr = Qtopia::readFile("/sys/class/rtc/rtc0/wakealarm").trimmed(); QString alarmStr; if(wakealarmStr.isEmpty()) { alarmStr = tr("not set"); } else { uint wakealarmSecs = wakealarmStr.toUInt(); QDateTime wakealarmDt = QDateTime::fromTime_t(wakealarmSecs); alarmStr = wakealarmDt.toString(); } label->setText(QString(tr("RTC (Real time clock)\n\nDate: %1\nTime: %2\nLocal: %3\nAlarm: %4")) .arg(rtcDate) .arg(rtcTime) .arg(rtcNow.toString()) .arg(alarmStr)); QTimer::singleShot(1000, this, SLOT(updateRtc())); }
void ForgetPwdVerifyPage::on_btnNextStep_clicked() { if(editValidate->text().length() != 6){ QString strText = tr("请输入6位验证码"); hintMsgPage->setText(strText); hintMsgPage->show(); editValidate->setFocus(); return; } QString strValidationCode = editValidate->text().trimmed(); QByteArray byteValidationCode = strValidationCode.toLatin1(); verifyCode = byteValidationCode.toUInt(); AssemblyData assemblyData; assemblyData.append(verifyCode); char* data = assemblyData.getAssemblyData(); quint16 dataLen = assemblyData.getAssemblyDataLen(); emit readyRead(CommandCode::FORGET_PASSWORD_VERIFY, data, dataLen); if(loadingPage == NULL){ loadingPage = new LoadingPage(this); loadingPage->show(); } }
/**@brief convert QString to int (4 bytes, 32 bits); * *@param str [IN]: the string to convert; *@param data [OUT]: the result is stored in this parm; *@return bool: if convert succeed, return true; else, return false; *@note there is a bug in qt library, so hex->int16->int32. */ bool Lms511Thread::Str2Int_32(QByteArray str, int* data) { bool ok; unsigned int temp = str.toUInt(&ok, 16); memcpy(data, &temp, sizeof(int)); return ok; }
// The reason we don't store stuff in a QString is because BitTorrent // b-encoded strings may contain zeroes within the string, which makes // a BString more of a buffer than a true string. BString::BString (ByteStream &stream) : m_data() { // A BString is \d+:.{n}, where n is whatever \d+ converted to. // So, read in the number part first. QByteArray numberData; while(*stream != ':') { numberData.append(*stream); ++stream; } ++stream; // Read past ':' bool validNumber = false; quint32 length = numberData.toUInt(&validNumber); if(!validNumber) throw std::runtime_error("Invalid number in string data"); for(quint32 i = 0; i < length; ++i) { m_data.append(*stream); ++stream; } }
void Bdecoder::read(QByteArray *buf) { int end = m_buf.indexOf(':', m_pos); if (end <= m_pos || end >= m_len) { setError("buffer overrun"); return; } QByteArray s = m_buf.mid(m_pos, end - m_pos); m_pos = end + 1; if (!validateInt(s)) return; bool ok; int strlen = s.toUInt(&ok, 10); if (!ok) { setError("Invalid string length (%s)", s.constData()); return; } if (strlen + m_pos > m_len) { setError("buffer overrun"); return; } if (buf) *buf = m_buf.mid(m_pos, strlen); m_pos += strlen; }
static QString transcode(const QString &str, bool utf8) { // Removed a and \a from here because it is not handled correctly by the linguist in our case static const char tab[] = "bfnrtv"; // removed a static const char backTab[] = "\b\f\n\r\t\v"; // removed \a const QString in = (!utf8 || yySourceIsUnicode) ? str : QString::fromUtf8(yySourceCodec->fromUnicode(str).data()); QString out; out.reserve(in.length()); for (int i = 0; i < in.length();) { ushort c = in[i++].unicode(); if (c == '\\') { if (i >= in.length()) break; c = in[i++].unicode(); if (c == '\n') continue; if (c == 'x') { QByteArray hex; while (i < in.length() && isxdigit((c = in[i].unicode()))) { hex += c; i++; } out += hex.toUInt(0, 16); } else if (c >= '0' && c < '8') { QByteArray oct; int n = 0; oct += c; while (n < 2 && i < in.length() && (c = in[i].unicode()) >= '0' && c < '8') { i++; n++; oct += c; } out += oct.toUInt(0, 8); } else { const char *p = strchr(tab, c); out += QString("\\") + QChar(QLatin1Char(!p ? c : backTab[p - tab])); } } else { out += c; } } return out; }
bool NodeInstanceServerProxy::checkPuppetVersion(const QString &qmlPuppetPath) { QProcess qmlPuppetVersionProcess; qmlPuppetVersionProcess.start(qmlPuppetPath, QStringList() << "--version"); qmlPuppetVersionProcess.waitForReadyRead(6000); QByteArray versionString = qmlPuppetVersionProcess.readAll(); bool canConvert; unsigned int versionNumber = versionString.toUInt(&canConvert); return canConvert && versionNumber == 2; }
GpsdMasterDevice::GpsdMasterDevice() : _socket( new QTcpSocket(this)) , _hostname("localhost") , _port(2947) , _gpsdStarted(false) { connect(_socket, SIGNAL( readyRead()), this, SLOT( readFromSocketAndCopy())); QByteArray hostname = qgetenv("GPSD_HOST"); if( !hostname.isEmpty()) _hostname = hostname; QByteArray port = qgetenv("GPSD_PORT"); if( !port.isEmpty()) { bool ok = false; uint tmp = port.toUInt(&ok); if(ok) _port = tmp; } }
QDateTime Qtopia::rtcNow() { QByteArray secsStr = readFile("/sys/class/rtc/rtc0/since_epoch").trimmed(); uint secs = secsStr.toUInt(); return QDateTime::fromTime_t(secs); }
bool Lexer::fetchNumber( double &d) { char ch; d_source.peek( &ch, 1 ); QByteArray number; enum State { Vorkomma, Nachkomma, Exponent2, Exponent1 }; State state = Vorkomma; // Erstes Zeichen if( ch == '.' ) { state = Nachkomma; }else if( !::isdigit( ch ) ) { d_source.rewind(); return false; } char ch2; d_source.peek( &ch2, 1 ); if( state == Nachkomma && !::isdigit(ch2) ) { d_source.rewind(); return false; // wir haben einen Punkt gefunden, der aber nicht von einer Zahl gefolgt wird } bool ok; if( ch2 == 'x' ) { if( ch != '0') return error("invalid number format"); // Parse Hex while( true ) { d_source.peek( &ch2, 1 ); if( ::isdigit( ch2 ) || _isHexChar( ch2 ) ) number += ch2; else { // Zahl ist fertig d = number.toUInt( &ok, 16 ); if( !ok ) return error("invalid hex format"); else { d_source.eat( number.size() + 2 ); return true; } } } }else { // Parse Decimal number += ch; int anzNachkomma = 0; while( true ) { switch( state ) { case Vorkomma: if( ch2 == '.' ) { state = Nachkomma; }else if( ::isdigit( ch2 ) ) ; else if( ch2 == 'e' || ch2 == 'E' ) { state = Exponent1; ch2 = 'e'; }else { d = number.toUInt( &ok ); if( !ok ) return error("invalid integer"); else { d_source.eat( number.size() ); return true; } } number += ch2; break; case Nachkomma: if( ::isdigit( ch2 ) ) ; else if( ch2 == 'e' || ch2 == 'E' ) { if( anzNachkomma == 0 ) return error("invalid number format"); state = Exponent1; ch2 = 'e'; }else { // Zahl ist fertig if( anzNachkomma == 0 ) return error("invalid number format"); d = number.toDouble( &ok ); if( !ok ) return error("invalid decimal format"); else { d_source.eat( number.size() ); return true; } } anzNachkomma++; number += ch2; break; case Exponent1: if( ::isdigit( ch2 ) || ch2 == '+' || ch2 == '-' ) state = Exponent2; else return error("invalid number format"); number += ch2; break; case Exponent2: if( ::isdigit( ch2 ) ) ; else { // Zahl ist fertig d = number.toDouble( &ok ); if( !ok ) return error("invalid exponential format"); else { d_source.eat( number.size() ); return true; } } number += ch2; break; } d_source.peek( &ch2, 1 ); } } d_source.rewind(); return false; }
/**@brief convert QString to unsigned int (4 bytes, 32 bits); * *@param str [IN]: the string to convert;; *@param data [OUT]: the result is stored in this parm; *@return bool, if convert succeed, return true; else, return false; *@note */ bool Lms511Thread::Str2Uint_32(QByteArray str, unsigned int * data) { bool ok; *data = str.toUInt(&ok, 16); return ok; }
void EngineShoutcast::updateFromPreferences() { qDebug() << "EngineShoutcast: updating from preferences"; m_pUpdateShoutcastFromPrefs->slotSet(0.0f); m_format_is_mp3 = false; m_format_is_ov = false; m_protocol_is_icecast1 = false; m_protocol_is_icecast2 = false; m_protocol_is_shoutcast = false; m_ogg_dynamic_update = false; // Convert a bunch of QStrings to QByteArrays so we can get regular C char* // strings to pass to libshout. QString codec = m_pConfig->getValueString(ConfigKey(SHOUTCAST_PREF_KEY, "metadata_charset")); QByteArray baCodec = codec.toLatin1(); m_pTextCodec = QTextCodec::codecForName(baCodec); if (!m_pTextCodec) { qDebug() << "Couldn't find shoutcast metadata codec for codec:" << codec << " defaulting to ISO-8859-1."; } // Indicates our metadata is in the provided charset. shout_metadata_add(m_pShoutMetaData, "charset", baCodec.constData()); // Host, server type, port, mountpoint, login, password should be latin1. QByteArray baHost = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "host")).toLatin1(); QByteArray baServerType = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "servertype")).toLatin1(); QByteArray baPort = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "port")).toLatin1(); QByteArray baMountPoint = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "mountpoint")).toLatin1(); QByteArray baLogin = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "login")).toLatin1(); QByteArray baPassword = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "password")).toLatin1(); QByteArray baFormat = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "format")).toLatin1(); QByteArray baBitrate = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "bitrate")).toLatin1(); // Encode metadata like stream name, website, desc, genre, title/author with // the chosen TextCodec. QByteArray baStreamName = encodeString(m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "stream_name"))); QByteArray baStreamWebsite = encodeString(m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "stream_website"))); QByteArray baStreamDesc = encodeString(m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "stream_desc"))); QByteArray baStreamGenre = encodeString(m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "stream_genre"))); QByteArray baStreamPublic = encodeString(m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "stream_public"))); // Dynamic Ogg metadata update m_ogg_dynamic_update = (bool)m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY,"ogg_dynamicupdate")).toInt(); m_custom_metadata = (bool)m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "enable_metadata")).toInt(); m_customTitle = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "custom_title")); m_customArtist = m_pConfig->getValueString( ConfigKey(SHOUTCAST_PREF_KEY, "custom_artist")); int format; int protocol; if (shout_set_host(m_pShout, baHost.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting hostname!"), shout_get_error(m_pShout)); return; } // WTF? Why SHOUT_PROTOCOL_HTTP and not.. the chosen protocol? if (shout_set_protocol(m_pShout, SHOUT_PROTOCOL_HTTP) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting protocol!"), shout_get_error(m_pShout)); return; } if (shout_set_port(m_pShout, baPort.toUInt()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting port!"), shout_get_error(m_pShout)); return; } if (shout_set_password(m_pShout, baPassword.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting password!"), shout_get_error(m_pShout)); return; } if (shout_set_mount(m_pShout, baMountPoint.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting mount!"), shout_get_error(m_pShout)); return; } if (shout_set_user(m_pShout, baLogin.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting username!"), shout_get_error(m_pShout)); return; } if (shout_set_name(m_pShout, baStreamName.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting stream name!"), shout_get_error(m_pShout)); return; } if (shout_set_description(m_pShout, baStreamDesc.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting stream description!"), shout_get_error(m_pShout)); return; } if (shout_set_genre(m_pShout, baStreamGenre.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting stream genre!"), shout_get_error(m_pShout)); return; } if (shout_set_url(m_pShout, baStreamWebsite.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting stream url!"), shout_get_error(m_pShout)); return; } m_format_is_mp3 = !qstrcmp(baFormat.constData(), SHOUTCAST_FORMAT_MP3); m_format_is_ov = !qstrcmp(baFormat.constData(), SHOUTCAST_FORMAT_OV); if (m_format_is_mp3) { format = SHOUT_FORMAT_MP3; } else if (m_format_is_ov) { format = SHOUT_FORMAT_OGG; } else { qDebug() << "Error: unknown format:" << baFormat.constData(); return; } if (shout_set_format(m_pShout, format) != SHOUTERR_SUCCESS) { errorDialog("Error setting soutcast format!", shout_get_error(m_pShout)); return; } bool bitrate_is_int = false; int iBitrate = baBitrate.toInt(&bitrate_is_int); if (!bitrate_is_int) { qDebug() << "Error: unknown bitrate:" << baBitrate.constData(); } int iMasterSamplerate = m_pMasterSamplerate->get(); if (m_format_is_ov && iMasterSamplerate == 96000) { errorDialog(tr("Broadcasting at 96kHz with Ogg Vorbis is not currently " "supported. Please try a different sample-rate or switch " "to a different encoding."), tr("See https://bugs.launchpad.net/mixxx/+bug/686212 for more " "information.")); return; } if (shout_set_audio_info(m_pShout, SHOUT_AI_BITRATE, baBitrate.constData()) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting bitrate"), shout_get_error(m_pShout)); return; } m_protocol_is_icecast2 = !qstricmp(baServerType.constData(), SHOUTCAST_SERVER_ICECAST2); m_protocol_is_shoutcast = !qstricmp(baServerType.constData(), SHOUTCAST_SERVER_SHOUTCAST); m_protocol_is_icecast1 = !qstricmp(baServerType.constData(), SHOUTCAST_SERVER_ICECAST1); if (m_protocol_is_icecast2) { protocol = SHOUT_PROTOCOL_HTTP; } else if (m_protocol_is_shoutcast) { protocol = SHOUT_PROTOCOL_ICY; } else if (m_protocol_is_icecast1) { protocol = SHOUT_PROTOCOL_XAUDIOCAST; } else { errorDialog(tr("Error: unknown server protocol!"), shout_get_error(m_pShout)); return; } if (m_protocol_is_shoutcast && !m_format_is_mp3) { errorDialog(tr("Error: libshout only supports Shoutcast with MP3 format!"), shout_get_error(m_pShout)); return; } if (shout_set_protocol(m_pShout, protocol) != SHOUTERR_SUCCESS) { errorDialog(tr("Error setting protocol!"), shout_get_error(m_pShout)); return; } // Initialize m_encoder if (m_encoder) { // delete m_encoder if it has been initalized (with maybe) different bitrate delete m_encoder; m_encoder = NULL; } if (m_format_is_mp3) { m_encoder = new EncoderMp3(this); } else if (m_format_is_ov) { m_encoder = new EncoderVorbis(this); } else { qDebug() << "**** Unknown Encoder Format"; return; } if (m_encoder->initEncoder(iBitrate, iMasterSamplerate) < 0) { //e.g., if lame is not found //init m_encoder itself will display a message box qDebug() << "**** Encoder init failed"; delete m_encoder; m_encoder = NULL; } }
void MigrateDialog::process() { unsigned size = 0; for (list<QCheckBox*>::iterator it = m_boxes.begin(); it != m_boxes.end(); ++it){ if (!(*it)->isChecked()) continue; QString path = user_file((*it)->text()); path += '/'; icqConf.close(); clientsConf.close(); contactsConf.close(); icqConf.setFileName(path + "icq.conf"); clientsConf.setFileName(path + "clients.conf"); contactsConf.setFileName(path + "contacts.conf"); lblStatus->setText(path + "icq.conf"); if (!icqConf.open(QIODevice::ReadOnly)){ error(i18n("Can't open %1") .arg(path + "icq.conf")); return; } if (!clientsConf.open(QIODevice::WriteOnly | QIODevice::Truncate)){ error(i18n("Can't open %1") .arg(path + "clients.conf")); return; } if (!contactsConf.open(QIODevice::WriteOnly | QIODevice::Truncate)){ error(i18n("Can't open %1") .arg(path + "contacts.conf")); return; } m_uin = 0; m_passwd = ""; m_state = 0; m_grpId = 0; m_contactId = 0; Buffer cfg; cfg.init(icqConf.size()); icqConf.read(cfg.data(), icqConf.size()); for (;;){ QByteArray section = cfg.getSection(); if (section.isEmpty()) break; m_state = 3; if (section == "Group") m_state = 1; if (section == "User") m_state = 2; if (!m_bProcess) return; for (;;){ QByteArray l = cfg.getLine(); if (l.isEmpty()) break; QByteArray line = l; QByteArray name = getToken(line, '='); if (name == "UIN") m_uin = line.toUInt(); if (name == "EncryptPassword") m_passwd = line; if (name == "Name") m_name = line; if (name == "Alias") m_name = line; } flush(); barCnv->setValue(cfg.readPos()); qApp->processEvents(); } icqConf.close(); clientsConf.close(); contactsConf.close(); m_state = 3; size += icqConf.size(); if (!m_bProcess) return; barCnv->setValue(size); qApp->processEvents(); QString h_path = path; #ifdef WIN32 h_path += "history\\"; #else h_path += "history/"; #endif QDir history(h_path); QStringList l = history.entryList(QStringList("*.history"), QDir::Files); for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){ hFrom.close(); hTo.close(); hFrom.setFileName(h_path + (*it)); lblStatus->setText(h_path + (*it)); hTo.setFileName(h_path + QString(m_owner) + '.' + it->left(it->indexOf('.'))); if (!hFrom.open(QIODevice::ReadOnly)){ error(i18n("Can't open %1") .arg(hFrom.fileName())); return; } if (!hTo.open(QIODevice::WriteOnly | QIODevice::Truncate)){ error(i18n("Can't open %1") .arg(hTo.fileName())); return; } cfg.init(hFrom.size()); hFrom.read(cfg.data(), hFrom.size()); for (;;){ QByteArray section = cfg.getSection(); if (section.isEmpty()) break; m_state = 3; if (section == "Message") m_state = 4; if (!m_bProcess) return; for (;;){ QByteArray l = cfg.getLine(); if (l.isEmpty()) break; QByteArray line = l; QByteArray name = getToken(line, '='); if (name == "Message") m_message = line; if (name == "Time") m_time = line; if (name == "Direction") m_direction = line; if (name == "Charset") m_charset = line; } flush(); barCnv->setValue(cfg.readPos()); qApp->processEvents(); } hFrom.close(); hTo.close(); m_state = 3; size += hFrom.size(); if (!m_bProcess) return; barCnv->setValue(size); qApp->processEvents(); } if (chkRemove->isChecked()){ icqConf.remove(); icqConf.setFileName(path + "sim.conf"); icqConf.remove(); for (QStringList::Iterator it = l.begin(); it != l.end(); ++it){ hFrom.setFileName(h_path + (*it)); hFrom.remove(); } } } m_bProcess = false; accept(); }
bool Field::setDefaultValue(const QByteArray& def) { if (def.isNull()) { m_defaultValue = QVariant(); return true; } bool ok; switch (type()) { case Byte: { unsigned int v = def.toUInt(&ok); if (!ok || v > 255) m_defaultValue = QVariant(); else m_defaultValue = QVariant(v); break; } case ShortInteger: { int v = def.toInt(&ok); if (!ok || (!(m_options & Unsigned) && (v < -32768 || v > 32767)) || ((m_options & Unsigned) && (v < 0 || v > 65535))) m_defaultValue = QVariant(); else m_defaultValue = QVariant(v); break; } case Integer: {//4 bytes long v = def.toLong(&ok); //js: FIXME if (!ok || (!(m_options & Unsigned) && (-v > 0x080000000 || v > (0x080000000-1))) || ((m_options & Unsigned) && (v < 0 || v > 0x100000000))) if (!ok || (!(m_options & Unsigned) && (-v > (int)0x07FFFFFFF || v > (int)(0x080000000 - 1)))) m_defaultValue = QVariant(); else m_defaultValue = QVariant((qint64)v); break; } case BigInteger: {//8 bytes //! @todo BigInteger support /* qint64 long v = def.toLongLong(&ok); //TODO: 2-part decoding if (!ok || (!(m_options & Unsigned) && (-v > 0x080000000 || v > (0x080000000-1)))) m_defaultValue = QVariant(); else if (m_options & Unsigned) m_defaultValue=QVariant((quint64) v); else m_defaultValue = QVariant((qint64)v);*/ break; } case Boolean: { unsigned short v = def.toUShort(&ok); if (!ok || v > 1) m_defaultValue = QVariant(); else m_defaultValue = QVariant((bool)v); break; } case Date: {//YYYY-MM-DD QDate date = QDate::fromString(def, Qt::ISODate); if (!date.isValid()) m_defaultValue = QVariant(); else m_defaultValue = QVariant(date); break; } case DateTime: {//YYYY-MM-DDTHH:MM:SS QDateTime dt = QDateTime::fromString(def, Qt::ISODate); if (!dt.isValid()) m_defaultValue = QVariant(); else m_defaultValue = QVariant(dt); break; } case Time: {//HH:MM:SS QTime time = QTime::fromString(def, Qt::ISODate); if (!time.isValid()) m_defaultValue = QVariant(); else m_defaultValue = QVariant(time); break; } case Float: { float v = def.toFloat(&ok); if (!ok || ((m_options & Unsigned) && (v < 0.0))) m_defaultValue = QVariant(); else m_defaultValue = QVariant(v); break; } case Double: { double v = def.toDouble(&ok); if (!ok || ((m_options & Unsigned) && (v < 0.0))) m_defaultValue = QVariant(); else m_defaultValue = QVariant(v); break; } case Text: { if (def.isNull() || (uint(def.length()) > maxLength())) m_defaultValue = QVariant(); else m_defaultValue = QVariant((QString)def); break; } case LongText: { if (def.isNull()) m_defaultValue = QVariant(); else m_defaultValue = QVariant((QString)def); break; } case BLOB: { //TODO if (def.isNull()) m_defaultValue = QVariant(); else m_defaultValue = QVariant(def); break; } default: m_defaultValue = QVariant(); } return m_defaultValue.isNull(); }
/*! read data from TCP socket. Connects to signal readyRead of socket */ void So2sdrBandmap::readData() { // continue on as long as data is available while (socket->bytesAvailable()) { // first read command and length char buff[2]; if (cmdLen==0) { if (socket->bytesAvailable()<2) return; int n=socket->read(buff,2); if (n==2) { cmd=buff[0]; cmdLen=buff[1]; } } QByteArray data; data.clear(); if (cmdLen>0) { if (socket->bytesAvailable()<cmdLen) return; data=socket->read(cmdLen); } bool ok=false; int f; unsigned int ff; switch (cmd) { case BANDMAP_CMD_SET_FREQ: // set frequency f=data.toInt(&ok); if (ok) { centerFreq=f; int b=getBand(f); setBandName(b); endFreqs[0] = centerFreq- settings->value(s_sdr_sample_freq,s_sdr_sample_freq_def).toInt()/2 -settings->value(s_sdr_offset,s_sdr_offset_def).toInt(); endFreqs[1] = centerFreq+ settings->value(s_sdr_sample_freq,s_sdr_sample_freq_def).toInt()/2 -settings->value(s_sdr_offset,s_sdr_offset_def).toInt(); setWindowTitle("Bandmap "+bandName+" ["+QString::number(endFreqs[0]/1000)+"-"+QString::number(endFreqs[1]/1000)+"]"); if (band != b) { // if band changed, clear all signals spectrumProcessor->clearSigs(); spectrumProcessor->clearCQ(); band=b; } spectrumProcessor->setFreq(centerFreq, band, endFreqs[0], endFreqs[1]); spectrumProcessor->resetAvg(); makeFreqScaleAbsolute(); FreqLabel->setPixmap(freqPixmap); FreqLabel->update(); } break; case BANDMAP_CMD_SET_LOWER_FREQ: // set freq finder lower limit ff=data.toUInt(&ok); if (ok) { flow=ff; } break; case BANDMAP_CMD_SET_UPPER_FREQ: // set freq finder upper limit ff=data.toUInt(&ok); if (ok) { fhigh=ff; } break; case BANDMAP_CMD_QUIT: // quit program quit(); break; case BANDMAP_CMD_TX: // set transmit state tx=true; txLabel.setText("<font color=#FF0000>TX"); settings->setValue(s_sdr_peakdetect,false); break; case BANDMAP_CMD_RX: // cancel transmit state tx=false; txLabel.setText("<font color=#000000>TX"); settings->setValue(s_sdr_peakdetect,true); break; case BANDMAP_CMD_FIND_FREQ: // find open frequency if (centerFreq!=0 && flow!=0 && fhigh!=0) { spectrumProcessor->startFindCQ(flow,fhigh,callList); } break; case BANDMAP_CMD_SET_INVERT: // invert spectrum if (data[0]==char(0x00)) { setInvert(false); } else { setInvert(true); } break; case BANDMAP_CMD_SET_ADD_OFFSET: // set additional IF offset f=data.toInt(&ok); if (ok) { spectrumProcessor->setAddOffset(f); } break; case BANDMAP_CMD_ADD_CALL: // add callsign addCall(data); break; case BANDMAP_CMD_CLEAR: // clear callsign list callList.clear(); break; case BANDMAP_CMD_DELETE_CALL: // delete callsign deleteCall(data); break; case BANDMAP_CMD_QSY_UP: // qsy to next higher signal qsyNext(true); break; case BANDMAP_CMD_QSY_DOWN: // qsy to next lower signal qsyNext(false); break; } cmd=0; cmdLen=0; } }