| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | #include "decodedtext.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-05 19:41:03 +00:00
										 |  |  | #include <QStringList>
 | 
					
						
							|  |  |  | #include <QRegularExpression>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | QString DecodedText::CQersCall() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |     // extract the CQer's call   TODO: does this work with all call formats?
 | 
					
						
							| 
									
										
										
										
											2015-03-14 22:19:22 +00:00
										 |  |  |   int s1 {0}; | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |   int position; | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |   QString t=_string; | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |   if ((position = _string.indexOf (" CQ DX ")) >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       s1 = 7 + position; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-09 23:39:48 +00:00
										 |  |  |   else if ((position = _string.indexOf (" CQDX ")) >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       s1 = 6 + position; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |   else if ((position = _string.indexOf (" CQ ")) >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       s1 = 4 + position; | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |       if(_string.mid(s1,3).toInt() > 0 and _string.mid(s1,3).toInt() <= 999) s1 += 4; | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   else if ((position = _string.indexOf (" DE ")) >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       s1 = 4 + position; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else if ((position = _string.indexOf (" QRZ ")) >= 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       s1 = 5 + position; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   auto s2 = _string.indexOf (" ", s1); | 
					
						
							|  |  |  |   return _string.mid (s1, s2 - s1); | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DecodedText::isJT65() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _string.indexOf("#") == column_mode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DecodedText::isJT9() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _string.indexOf("@") == column_mode; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DecodedText::isTX() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int i = _string.indexOf("Tx"); | 
					
						
							|  |  |  |     return (i >= 0 && i < 15); // TODO guessing those numbers. Does Tx ever move?
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DecodedText::frequencyOffset() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _string.mid(column_freq,4).toInt(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DecodedText::snr() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-11-18 01:28:12 +00:00
										 |  |  |   int i1=_string.indexOf(" ")+1; | 
					
						
							|  |  |  |   return _string.mid(i1,3).toInt(); | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-22 17:48:03 +00:00
										 |  |  | float DecodedText::dt() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return _string.mid(column_dt,5).toFloat(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | 2343 -11  0.8 1259 # YV6BFE F6GUU R-08 | 
					
						
							|  |  |  | 2343 -19  0.3  718 # VE6WQ SQ2NIJ -14 | 
					
						
							|  |  |  | 2343  -7  0.3  815 # KK4DSD W7VP -16 | 
					
						
							|  |  |  | 2343 -13  0.1 3627 @ CT1FBK IK5YZT R+02 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 0605  Tx      1259 # CQ VK3ACF QF22 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // find and extract any report. Returns true if this is a standard message
 | 
					
						
							| 
									
										
										
										
											2015-03-04 12:22:33 +00:00
										 |  |  | bool DecodedText::report(QString const& myBaseCall, QString const& dxBaseCall, /*mod*/QString& report) | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-01 19:32:16 +00:00
										 |  |  |     QString msg=_string.mid(column_qsoText).trimmed(); | 
					
						
							|  |  |  |     if(msg.length() < 1) return false; | 
					
						
							| 
									
										
										
										
											2016-12-04 00:54:58 +00:00
										 |  |  |     msg = msg.remove (QRegularExpression {"[<>]"}); | 
					
						
							|  |  |  |     int i1=msg.indexOf('\r'); | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  |     if (i1>0) | 
					
						
							| 
									
										
										
										
											2016-12-04 00:54:58 +00:00
										 |  |  |       msg=msg.left (i1-1); | 
					
						
							|  |  |  |     bool b = stdmsg_ ((msg + "                      ").toLatin1().constData(),22);  // stdmsg is a fortran routine that packs the text, unpacks it and compares the result
 | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QStringList w=msg.split(" ",QString::SkipEmptyParts); | 
					
						
							| 
									
										
										
										
											2016-07-01 11:37:10 +00:00
										 |  |  |     if(w.size () | 
					
						
							|  |  |  |        && b && (w[0] == myBaseCall | 
					
						
							| 
									
										
										
										
											2015-03-04 12:22:33 +00:00
										 |  |  |              || w[0].endsWith ("/" + myBaseCall) | 
					
						
							|  |  |  |              || w[0].startsWith (myBaseCall + "/") | 
					
						
							|  |  |  |              || (w.size () > 1 && !dxBaseCall.isEmpty () | 
					
						
							|  |  |  |                  && (w[1] == dxBaseCall | 
					
						
							|  |  |  |                      || w[1].endsWith ("/" + dxBaseCall) | 
					
						
							|  |  |  |                      || w[1].startsWith (dxBaseCall + "/"))))) | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         QString tt=""; | 
					
						
							| 
									
										
										
										
											2015-03-04 12:22:33 +00:00
										 |  |  |         if(w.size() > 2) tt=w[2]; | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  |         bool ok; | 
					
						
							|  |  |  |         i1=tt.toInt(&ok); | 
					
						
							|  |  |  |         if (ok and i1>=-50 and i1<50) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             report = tt; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (tt.mid(0,1)=="R") | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 i1=tt.mid(1).toInt(&ok); | 
					
						
							|  |  |  |                 if(ok and i1>=-50 and i1<50) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     report = tt.mid(1); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return b; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // get the first text word, usually the call
 | 
					
						
							|  |  |  | QString DecodedText::call() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |   auto call = _string; | 
					
						
							| 
									
										
										
										
											2016-12-04 00:54:58 +00:00
										 |  |  |   call = call.replace (QRegularExpression {" CQ ([A-Z]{2,2}|[0-9]{3,3}) "}, " CQ_\\1 ").mid (column_qsoText); | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |   int i = call.indexOf(" "); | 
					
						
							|  |  |  |   return call.mid(0,i); | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // get the second word, most likely the de call and the third word, most likely grid
 | 
					
						
							| 
									
										
										
										
											2016-10-03 17:08:02 +00:00
										 |  |  | void DecodedText::deCallAndGrid(/*out*/QString& call, QString& grid) | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-03-14 19:13:18 +00:00
										 |  |  |   auto msg = _string; | 
					
						
							| 
									
										
										
										
											2016-12-04 00:54:58 +00:00
										 |  |  |   msg = msg.replace (QRegularExpression {" CQ ([A-Z]{2,2}|[0-9]{3,3}) "}, " CQ_\\1 ").mid (column_qsoText); | 
					
						
							| 
									
										
										
										
											2016-12-18 22:20:07 +00:00
										 |  |  |   int i1 = msg.indexOf (" "); | 
					
						
							|  |  |  |   call = msg.mid (i1 + 1); | 
					
						
							|  |  |  |   int i2 = call.indexOf (" "); | 
					
						
							|  |  |  |   if (" R " == call.mid (i2, 3)) // MSK144 contest mode report
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       grid = call.mid (i2 + 3, 4); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       grid = call.mid (i2 + 1, 4); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   call = call.left (i2).replace (">", ""); | 
					
						
							| 
									
										
										
										
											2013-08-25 01:48:45 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DecodedText::timeInSeconds() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return 60*_string.mid(column_time,2).toInt() + _string.mid(2,2).toInt(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | 2343 -11  0.8 1259 # YV6BFE F6GUU R-08 | 
					
						
							|  |  |  | 2343 -19  0.3  718 # VE6WQ SQ2NIJ -14 | 
					
						
							|  |  |  | 2343  -7  0.3  815 # KK4DSD W7VP -16 | 
					
						
							|  |  |  | 2343 -13  0.1 3627 @ CT1FBK IK5YZT R+02 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 0605  Tx      1259 # CQ VK3ACF QF22 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DecodedText::report()  // returns a string of the SNR field with a leading + or - followed by two digits
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int sr = snr(); | 
					
						
							|  |  |  |     if (sr<-50) | 
					
						
							|  |  |  |         sr = -50; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         if (sr > 49) | 
					
						
							|  |  |  |             sr = 49; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString rpt; | 
					
						
							|  |  |  |     rpt.sprintf("%d",abs(sr)); | 
					
						
							|  |  |  |     if (sr > 9) | 
					
						
							|  |  |  |         rpt = "+" + rpt; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         if (sr >= 0) | 
					
						
							|  |  |  |             rpt = "+0" + rpt; | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             if (sr >= -9) | 
					
						
							|  |  |  |                 rpt = "-0" + rpt; | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 rpt = "-" + rpt; | 
					
						
							|  |  |  |     return rpt; | 
					
						
							|  |  |  | } |