#include "adif.h" #include #include #include #include /* W1XT20m14.076DM33JT65-21-142011042204171204243541st JT65A QSO. Him: mag loop 20WVK3ACFqf22lb IK1SOW20m14.076JN35JT65-19-11201104220525010533593VK3ACFqf22lb W4ABC> ... */ void ADIF::init(QString const& filename) { _filename = filename; _data.clear(); } QString ADIF::extractField(QString const& record, QString const& fieldName) const { int fieldNameIndex = record.indexOf (fieldName + ':', 0, Qt::CaseInsensitive); if (fieldNameIndex >=0) { int closingBracketIndex = record.indexOf('>',fieldNameIndex); int fieldLengthIndex = record.indexOf(':',fieldNameIndex); // find the size delimiter int dataTypeIndex = -1; if (fieldLengthIndex >= 0) { dataTypeIndex = record.indexOf(':',fieldLengthIndex+1); // check for a second : indicating there is a data type if (dataTypeIndex > closingBracketIndex) dataTypeIndex = -1; // second : was found but it was beyond the closing > } if ((closingBracketIndex > fieldNameIndex) && (fieldLengthIndex > fieldNameIndex) && (fieldLengthIndex< closingBracketIndex)) { int fieldLengthCharCount = closingBracketIndex - fieldLengthIndex -1; if (dataTypeIndex >= 0) fieldLengthCharCount -= 2; // data type indicator is always a colon followed by a single character QString fieldLengthString = record.mid(fieldLengthIndex+1,fieldLengthCharCount); int fieldLength = fieldLengthString.toInt(); if (fieldLength > 0) { QString field = record.mid(closingBracketIndex+1,fieldLength); return field; } } } return ""; } void ADIF::load() { _data.clear(); QFile inputFile(_filename); if (inputFile.open(QIODevice::ReadOnly)) { QTextStream in(&inputFile); QString buffer; bool pre_read {false}; int end_position {-1}; // skip optional header record do { buffer += in.readLine () + '\n'; if (buffer.startsWith (QChar {'<'})) // denotes no header { pre_read = true; } else { end_position = buffer.indexOf ("", 0, Qt::CaseInsensitive); } } while (!in.atEnd () && !pre_read && end_position < 0); if (!pre_read) // found header { buffer.remove (0, end_position + 5); } while (buffer.size () || !in.atEnd ()) { do { end_position = buffer.indexOf ("", 0, Qt::CaseInsensitive); if (!in.atEnd () && end_position < 0) { buffer += in.readLine () + '\n'; } } while (!in.atEnd () && end_position < 0); int record_length {end_position >= 0 ? end_position + 5 : -1}; auto record = buffer.left (record_length).trimmed (); auto next_record = buffer.indexOf (QChar {'<'}, record_length); buffer.remove (0, next_record >=0 ? next_record : buffer.size ()); record = record.mid (record.indexOf (QChar {'<'})); add (extractField (record, "CALL") , extractField (record, "BAND") , extractField (record, "MODE") , extractField (record, "QSO_DATE")); } inputFile.close (); } } void ADIF::add(QString const& call, QString const& band, QString const& mode, QString const& date) { QSO q; q.call = call; q.band = band; q.mode = mode; q.date = date; if (q.call.size ()) { _data.insert(q.call,q); // qDebug() << "Added as worked:" << call << band << mode << date; } } // return true if in the log same band and mode (where JT65 == JT9) bool ADIF::match(QString const& call, QString const& band, QString const& mode) const { QList qsos = _data.values(call); if (qsos.size()>0) { QSO q; foreach(q,qsos) { if ( (band.compare(q.band,Qt::CaseInsensitive) == 0) || (band=="") || (q.band=="")) { if ( ( ((mode.compare("JT65",Qt::CaseInsensitive)==0) || (mode.compare("JT9",Qt::CaseInsensitive)==0) || (mode.compare("FT8",Qt::CaseInsensitive)==0)) && ((q.mode.compare("JT65",Qt::CaseInsensitive)==0) || (q.mode.compare("JT9",Qt::CaseInsensitive)==0) || (q.mode.compare("FT8",Qt::CaseInsensitive)==0)) ) || (mode.compare(q.mode,Qt::CaseInsensitive)==0) || (mode=="") || (q.mode=="") ) return true; } } } return false; } QList ADIF::getCallList() const { QList p; QMultiHash::const_iterator i = _data.constBegin(); while (i != _data.constEnd()) { p << i.key(); ++i; } return p; } int ADIF::getCount() const { return _data.size(); } // open ADIF file and append the QSO details. Return true on success bool ADIF::addQSOToFile(QString const& hisCall, QString const& hisGrid, QString const& mode, QString const& rptSent, QString const& rptRcvd, QDateTime const& dateTimeOn, QDateTime const& dateTimeOff, QString const& band, QString const& comments, QString const& name, QString const& strDialFreq, QString const& m_myCall, QString const& m_myGrid, QString const& m_txPower) { QFile f2(_filename); if (!f2.open(QIODevice::Text | QIODevice::Append)) return false; else { QTextStream out(&f2); if (f2.size()==0) out << "WSJT-X ADIF Export" << endl; // new file QString t; t="" + hisCall; t+=" " + hisGrid; t+=" " + mode; t+=" " + rptSent; t+=" " + rptRcvd; t+=" " + dateTimeOn.date ().toString ("yyyyMMdd"); t+=" " + dateTimeOn.time ().toString ("hhmmss"); t+=" " + dateTimeOff.date ().toString ("yyyyMMdd"); t+=" " + dateTimeOff.time ().toString ("hhmmss"); t+=" " + band; t+=" " + strDialFreq; t+=" " + m_myCall; t+=" " + m_myGrid; if(m_txPower!="") t+= " " + m_txPower; if(comments!="") t+=" " + comments; if(name!="") t+=" " + name; t+=" "; out << t << endl; f2.close(); } return true; } QString ADIF::bandFromFrequency(double dialFreq) { QString band=""; if(dialFreq>0.135 and dialFreq<0.139) band="2200m"; else if(dialFreq>0.45 and dialFreq<0.55) band="630m"; else if(dialFreq>1.8 and dialFreq<2.0) band="160m"; else if(dialFreq>3.5 and dialFreq<4.0) band="80m"; else if(dialFreq>5.1 and dialFreq<5.45) band="60m"; else if(dialFreq>7.0 and dialFreq<7.3) band="40m"; else if(dialFreq>10.0 and dialFreq<10.15) band="30m"; else if(dialFreq>14.0 and dialFreq<14.35) band="20m"; else if(dialFreq>18.068 and dialFreq<18.168) band="17m"; else if(dialFreq>21.0 and dialFreq<21.45) band="15m"; else if(dialFreq>24.890 and dialFreq<24.990) band="12m"; else if(dialFreq>28.0 and dialFreq<29.7) band="10m"; else if(dialFreq>50.0 and dialFreq<54.0) band="6m"; else if(dialFreq>70.0 and dialFreq<71.0) band="4m"; else if(dialFreq>144.0 and dialFreq<148.0) band="2m"; else if(dialFreq>222.0 and dialFreq<225.0) band="1.25m"; else if(dialFreq>420.0 and dialFreq<450.0) band="70cm"; else if(dialFreq>902.0 and dialFreq<928.0) band="33cm"; else if(dialFreq>1240.0 and dialFreq<1300.0) band="23cm"; else if(dialFreq>2300.0 and dialFreq<2450.0) band="13cm"; else if(dialFreq>3300.0 and dialFreq<3500.0) band="9cm"; else if(dialFreq>5650.0 and dialFreq<5925.0) band="6cm"; else if(dialFreq>10000.0 and dialFreq<10500.0) band="3cm"; else if(dialFreq>24000.0 and dialFreq<24250.0) band="1.25cm"; else if(dialFreq>47000.0 and dialFreq<47200.0) band="6mm"; else if(dialFreq>75500.0 and dialFreq<81000.0) band="4mm"; return band; }