diff --git a/bargraph.cpp b/bargraph.cpp
index 202c3d6..ab71ddb 100644
--- a/bargraph.cpp
+++ b/bargraph.cpp
@@ -23,7 +23,6 @@ along with Foobar. If not, see .
#include
#include "config.h"
-//#include "scandata.h"
#include "bargraph.h"
//extern ScanData scandata;
@@ -49,6 +48,8 @@ BarGraph::BarGraph(QWidget *parent) :
font = QFont("Arial",9);
font_h = QFontMetrics(font).height();
+
+ //setAutoFillBackground(true);
}
BarGraph::~BarGraph()
@@ -70,18 +71,18 @@ void BarGraph::Draw(QPainter &painter)
double scale;
int x/*,y*/;
- int xo = margin+font_h, yo=height()-margin-10-font_h,
- h=height()-2*(margin)-10-font_h,
+ int xo = margin+font_h, yo=height()-margin-6-font_h,
+ h=height()-2*(margin)-6-font_h,
w=width()-2*margin-2*font_h;
painter.setPen(Qt::NoPen);
//painter.setPen(pen);
painter.setBrush(brush);
- //painter.setFont(font);
+ painter.setFont(font);
//Bar
scale = (w) / (vmax-vmin);
- painter.drawRect(xo+(vorig-vmin)*scale,yo,(value-vorig)*scale,-h);
+ painter.drawRect(xo+(vorig-vmin)*scale,yo,(constrain(value,vmin,vmax)-vorig)*scale,-h);
//Scale
painter.setPen(pen);
@@ -95,10 +96,10 @@ void BarGraph::Draw(QPainter &painter)
x=xo + (v-vmin)*scale;
//printf("x=%d\n",x);
//printf("v=%f\n",v);
- painter.drawLine(x,yo,x,yo + 10);
+ painter.drawLine(x,yo,x,yo + 6);
x=x - QFontMetrics(font).boundingRect(s).width()/2;
- painter.drawText(x,yo + 10 + font_h,s);
+ painter.drawText(x,yo + 6 + font_h,s);
}
}
@@ -110,7 +111,8 @@ void BarGraph::paintEvent(QPaintEvent *)
////////////////////
painter.setBackgroundMode(Qt::OpaqueMode); //??
- painter.setBackground(Qt::white);
+ //painter.setBackground(Qt::white);
+ //painter.setAutoFillBackground(true);
painter.eraseRect(painter.viewport());
painter.setBackgroundMode(Qt::TransparentMode); //??
diff --git a/bargraph.h b/bargraph.h
index d0e3988..36994a6 100644
--- a/bargraph.h
+++ b/bargraph.h
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@@ -23,10 +23,8 @@ along with Foobar. If not, see .
#include
#include
#include
-//#include
-//#include "graph.h"
-//#include "graphcursor.h"
+#define constrain(v,v1,v2) ((v)<(v1)?v1:((v)>(v2)?v2:v))
class BarGraph : public QWidget
{
@@ -35,13 +33,6 @@ class BarGraph : public QWidget
explicit BarGraph(QWidget *parent = 0);
~BarGraph();
- //GraphCursor *cursor;
-
- //Graph graph;
- //GraphScale *xscale,*yscale1, *yscale2;
- //GraphTrace *swrtrace, *ztrace, *xtrace, *rtrace;
- //GraphVertLine *swrminline;
- //GraphHorizLine *ZZeroLine, *ZTargetline,*SWRTargetline;
void Draw(QPainter &painter);
void SetIncAuto();
@@ -50,18 +41,14 @@ class BarGraph : public QWidget
QBrush brush;
double vmin, vmax, vinc, value, labdiv, vorig;
QString labsuffix;
- QFont font;
-
-signals:
- //void cursorMoved(double pos);
public slots:
private:
+ QFont font;
int font_h;
void paintEvent(QPaintEvent *);
- //void mouseMoveEvent(QMouseEvent *ev);
};
#endif // BARGRAPH_H
diff --git a/mainwindow.cpp b/mainwindow.cpp
index ecb5ebe..c6d83af 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@@ -80,7 +80,7 @@ setlinebuf(stdout);
link = new SerialLink("/dev/ttyUSB0",57600);
if (link->IsUp())
- link->Cmd_Off(this);
+ link->Cmd_Off();
ui->band_cb->setCurrentIndex(16);
@@ -114,6 +114,7 @@ void MainWindow::RaiseEvent(event_t event,int arg)
{
case progress_event:
ui->progressBar->setValue(arg);
+ //draw_graph1();
break;
}
}
@@ -207,7 +208,7 @@ void MainWindow::Slot_scanBtn_click()
(long)((scandata.freq_end-scandata.freq_start)/scandata.GetPointCount()),
ui->useraw_chk->checkState()==Qt::Checked,
this);
- link->Cmd_Off(this);
+ link->Cmd_Off();
}
populate_table();
@@ -463,7 +464,7 @@ void MainWindow::Slot_menuDevice_Select(QAction *act)
link = new SerialLink(QString("/dev/" + act->text()).toLatin1().data(),57600);
if (link->IsUp())
- link->Cmd_Off(this);
+ link->Cmd_Off();
}
void MainWindow::Slot_about()
@@ -507,16 +508,19 @@ void MainWindow::Slot_monStart_click()
ui->SWR_Bar->SetIncAuto();
ui->SWR_Bar->value = 1;
+ ui->Z_Bar->brush = QBrush(qRgb(255,85,0));
ui->Z_Bar->vmin = 0;
ui->Z_Bar->vmax = 200;
ui->Z_Bar->value = 50;
ui->Z_Bar->SetIncAuto();
+ ui->R_Bar->brush = QBrush(Qt::darkGreen);
ui->R_Bar->vmin = 0;
ui->R_Bar->vmax = 200;
ui->R_Bar->value = 50;
ui->R_Bar->SetIncAuto();
+ ui->X_Bar->brush = QBrush(Qt::red);
ui->X_Bar->vmin = -100;
ui->X_Bar->vmax = 200;
ui->X_Bar->value = 0;
@@ -524,10 +528,11 @@ void MainWindow::Slot_monStart_click()
if (link->IsUp())
{
- link->Cmd_Freq((long)(ui->monfreq->value()*1000000),this);
- link->Cmd_On(this);
+ link->Cmd_Freq((long)(ui->monfreq->value()*1000000));
+ link->Cmd_On();
}
+ Slot_montimer_timeout();
montimer.start((long)(ui->monrate->value()));
}
@@ -536,9 +541,7 @@ void MainWindow::Slot_monStop_click()
montimer.stop();
if (link->IsUp())
- {
- link->Cmd_Off(this);
- }
+ link->Cmd_Off();
}
void MainWindow::Slot_montimer_timeout()
@@ -547,26 +550,22 @@ void MainWindow::Slot_montimer_timeout()
if (link->IsUp())
{
- link->Cmd_Raw(sample, this);
-
- ui->SWR_Bar->value = sample.swr;
- //ui->SWR_Bar->value += 1.0;
- //if (ui->SWR_Bar->value>ui->SWR_Bar->vmax) ui->SWR_Bar->value=ui->SWR_Bar->vmin;
- ui->SWR_lbl->setText(QString("%1:1").arg(sample.swr, 0,'f',1));
- ui->SWR_Bar->update();
-
- ui->Z_Bar->value = sample.Z;
- //ui->Z_Bar->value += 15.0;
- //if (ui->Z_Bar->value>ui->Z_Bar->vmax) ui->Z_Bar->value=ui->Z_Bar->vmin;
- ui->Z_lbl->setText(QString("%1").arg(sample.Z, 0,'f',1));
- ui->Z_Bar->update();
-
- ui->R_Bar->value = sample.R;
- ui->R_lbl->setText(QString("%1").arg(sample.R, 0,'f',1));
- ui->R_Bar->update();
-
- ui->X_Bar->value = sample.X;
- ui->X_lbl->setText(QString("%1").arg(sample.X, 0,'f',1));
- ui->X_Bar->update();
+ link->Cmd_Raw(sample);
+
+ ui->SWR_lbl->setText(QString("%1:1").arg(sample.swr, 0,'f',1));
+ ui->SWR_Bar->value = sample.swr;
+ ui->SWR_Bar->update();
+
+ ui->Z_lbl->setText(QString("%1").arg(sample.Z, 0,'f',1));
+ ui->Z_Bar->value = sample.Z;
+ ui->Z_Bar->update();
+
+ ui->R_lbl->setText(QString("%1").arg(sample.R, 0,'f',1));
+ ui->R_Bar->value = sample.R;
+ ui->R_Bar->update();
+
+ ui->X_lbl->setText(QString("%1").arg(sample.X, 0,'f',1));
+ ui->X_Bar->value = sample.X;
+ ui->X_Bar->update();
}
}
diff --git a/mainwindow.ui b/mainwindow.ui
index 49866f7..9f3d849 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -25,7 +25,7 @@
true
- 0
+ 1
diff --git a/serialdev.cpp b/serialdev.cpp
index a28b840..67ab50b 100644
--- a/serialdev.cpp
+++ b/serialdev.cpp
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@@ -82,9 +82,11 @@ int SerialDev::RxFlush()
{
pollfd fds[] = {{devfd, POLLIN, 0 }};
- int timeout = 500; //500msec, move somewhere
+ int timeout = 50; //500msec, move somewhere
int pstatus,rstatus;
+printf("%ld> RxFlush\n",time(NULL));
+
for (rxbufflen=0;;)
{
pstatus = poll(fds, 1, timeout);
@@ -105,7 +107,7 @@ int SerialDev::RxFlush()
}
else
{
-printf("RxFlush: %c\n",rxbuff[rxbufflen]);
+//printf("%ld> RxFlush: %c\n",time(NULL),rxbuff[rxbufflen]);
}
}
}
@@ -143,7 +145,7 @@ int SerialDev::RxLine()
}
else
{
-//printf("RxLine: c=%c (0x%02x)\n",rxbuff[rxbufflen],rxbuff[rxbufflen]);
+//printf("%ld> RxLine: c=%c (0x%02x)\n",time(NULL),rxbuff[rxbufflen],rxbuff[rxbufflen]);
switch (rxbuff[rxbufflen])
{
case '\r': break;
diff --git a/serialdev.h b/serialdev.h
index b4244ca..84e0878 100644
--- a/serialdev.h
+++ b/serialdev.h
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
diff --git a/seriallink.cpp b/seriallink.cpp
index 42bd505..b678c3d 100644
--- a/seriallink.cpp
+++ b/seriallink.cpp
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@@ -86,7 +86,7 @@ void SerialLink::TxCmd(const char *cmd)
{
if (IsUp())
{
-printf("TxCmd: %s\n",cmd);
+printf("%ld> TxCmd: %s\n",time(NULL),cmd);
TxData(cmd, strlen(cmd));
TxData("\n", 1);
}
@@ -94,6 +94,51 @@ printf("TxCmd: %s\n",cmd);
#endif
+//Handle standard OK/Error response from config commands
+//
+int SerialLink::RxResponse1()
+{
+ int state = 0,r,ret=0;
+
+ for (;state<10;)
+ {
+ r = RxLine();
+printf("%ld> RxLine=%d\n",time(NULL),r);
+ if (r==0)
+ {
+printf("\trxbuff: %s (%d)\n",rxbuff,rxbufflen);
+//printf("%ld> RxLine: %s (%d)\n",time(NULL), rxbuff,rxbufflen);
+printf("\tstate: %d\n",state);
+ switch (state)
+ {
+ case 0:
+ if (strcmp(rxbuff,"OK")==0)
+ {
+ state=10; //Success
+ }
+ else if (strncmp(rxbuff,"Error:",5)==0)
+ {
+ ret=2; //Error
+ state=1;
+ }
+ break;
+ case 1:
+ if (strcmp(rxbuff,">>")==0)
+ {
+ state=10; //Ready for next command
+ }
+ break;
+ }
+ }
+ else
+ {
+ ret=1; //Timeout
+ state=10;
+ }
+ }
+ return ret;
+}
+
void SerialLink::Cmd_Scan(long fstart, long fend, long fstep, bool useraw, EventReceiver *erx)
{
char cmd[64];
@@ -101,7 +146,7 @@ void SerialLink::Cmd_Scan(long fstart, long fend, long fstep, bool useraw, Event
Sample sample;
long frequency = fstart;
- //RxFlush();
+ RxFlush();
sprintf(cmd,"%s %ld %ld %ld\r", useraw?"scanr":"scan", fstart, fend>=FMAX ? FMAX : (fend+1), fstep); //Add 1Hz to end freq to make it inclusive
TxCmd(cmd);
@@ -111,11 +156,12 @@ void SerialLink::Cmd_Scan(long fstart, long fend, long fstep, bool useraw, Event
for (;state<10;)
{
r = RxLine();
-//printf("RxLine=%d\n",r);
+printf("%ld> RxLine=%d\n",time(NULL),r);
if (r==0)
{
-printf("RxLine: %s (%d)\n",rxbuff,rxbufflen);
-printf("state: %d\n",state);
+printf("\trxbuff: %s (%d)\n",rxbuff,rxbufflen);
+//printf("%ld> RxLine: %s (%d)\n",time(NULL),rxbuff,rxbufflen);
+printf("\tstate: %d\n",state);
switch (state)
{
case 0:
@@ -140,7 +186,7 @@ printf("state: %d\n",state);
}
else
{
-printf("f=%ld\n",frequency);
+printf("\tf: %ld\n",frequency);
sample.freq = (double)(frequency);
if (useraw)
{
@@ -168,152 +214,60 @@ printf("f=%ld\n",frequency);
scandata.UpdateStats();
}
-void SerialLink::Cmd_On(EventReceiver *erx)
+void SerialLink::Cmd_On()
{
- int state = 0,r;
-
- //RxFlush();
+ RxFlush();
TxCmd("on\r");
-
- for (;state<10;)
- {
- r = RxLine();
-printf("RxLine=%d\n",r);
- if (r==0)
- {
-printf("RxLine: %s (%d)\n",rxbuff,rxbufflen);
-printf("state: %d\n",state);
- switch (state)
- {
- case 0:
- if (strcmp(rxbuff,"OK")==0)
- {
- erx->RaiseEvent(EventReceiver::progress_event, 100);
- state=10; //Results
- }
- else if (strncmp(rxbuff,"Error:",5)==0)
- {
- state=10; //Error
- }
- else
- state=0; //Garbage ? Ignore
- break;
- }
- }
- else
- state=10; //Timeout
- }
+ RxResponse1();
}
-void SerialLink::Cmd_Off(EventReceiver *erx)
+void SerialLink::Cmd_Off()
{
- int state = 0,r;
-
- //RxFlush();
+ RxFlush();
TxCmd("off\r");
-
- for (;state<10;)
- {
- r = RxLine();
-printf("RxLine=%d\n",r);
- if (r==0)
- {
-printf("RxLine: %s (%d)\n",rxbuff,rxbufflen);
-printf("state: %d\n",state);
- switch (state)
- {
- case 0:
- if (strcmp(rxbuff,"OK")==0)
- {
- erx->RaiseEvent(EventReceiver::progress_event, 100);
- state=10; //Results
- }
- else if (strncmp(rxbuff,"Error:",5)==0)
- {
- state=10; //Error
- }
- else
- state=0; //Garbage ? Ignore
- break;
- }
- }
- else
- state=10; //Timeout
- }
+ RxResponse1();
}
-void SerialLink::Cmd_Freq(long f, EventReceiver *)
+void SerialLink::Cmd_Freq(long f)
{
- char cmd[64];
- int state = 0,r;
+ char cmd[32];
- //RxFlush();
+ RxFlush();
sprintf(cmd,"freq %ld\r", f);
TxCmd(cmd);
-
- for (;state<10;)
- {
- r = RxLine();
-printf("RxLine=%d\n",r);
- if (r==0)
- {
-printf("RxLine: %s (%d)\n",rxbuff,rxbufflen);
-printf("state: %d\n",state);
- switch (state)
- {
- case 0:
- if (strcmp(rxbuff,"OK")==0)
- {
- //erx->RaiseEvent(EventReceiver::progress_event, 100);
- state=10; //Results
- }
- else if (strncmp(rxbuff,"Error:",5)==0)
- {
- state=10; //Error
- }
- else
- state=0; //Garbage ? Ignore
- break;
- }
- }
- else
- state=10; //Timeout
- }
+ RxResponse1();
}
-void SerialLink::Cmd_Raw(Sample &sample, EventReceiver *)
+void SerialLink::Cmd_Raw(Sample &sample)
{
- //char cmd[64];
int state = 0,r;
- //RxFlush();
+ RxFlush();
TxCmd("raw\r");
for (;state<10;)
{
r = RxLine();
-printf("RxLine=%d\n",r);
+printf("%ld> RxLine=%d\n",time(NULL),r);
if (r==0)
{
-printf("RxLine: %s (%d)\n",rxbuff,rxbufflen);
-printf("state: %d\n",state);
+printf("\trxbuff: %s (%d)\n",rxbuff,rxbufflen);
+printf("\tstate: %d\n",state);
switch (state)
{
- case 0:
- double vf,vr,vz,va;
- sscanf(rxbuff,"%lf,%lf,%lf,%lf",&vf,&vr,&vz,&va);
- sample.fromRaw(vf,vr,vz,va);
-state=1; //End of Results
+ case 0: //Ignore one blank line
+ state=1;
break;
- case 1:
- if (strcmp(rxbuff,">>")==0)
+ case 1: //Results
{
- //erx->RaiseEvent(EventReceiver::progress_event, 100);
- state=10; //Done
+ double vf,vr,vz,va;
+ if (sscanf(rxbuff,"%lf,%lf,%lf,%lf",&vf,&vr,&vz,&va) == 4)
+ sample.fromRaw(vf,vr,vz,va);
+ state=10; //End of Results
}
break;
}
diff --git a/seriallink.h b/seriallink.h
index 507ccc6..08267a0 100644
--- a/seriallink.h
+++ b/seriallink.h
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
@@ -46,12 +46,13 @@ class SerialLink : public SerialDev
void TxCmd(const char *cmd);
void Cmd_Scan(long fstart, long fend, long fstep, bool useraw, EventReceiver *erx);
- void Cmd_On(EventReceiver *erx);
- void Cmd_Off(EventReceiver *erx);
- void Cmd_Freq(long f, EventReceiver *erx);
- void Cmd_Raw(Sample &sample, EventReceiver *erx);
+ void Cmd_On();
+ void Cmd_Off();
+ void Cmd_Freq(long f);
+ void Cmd_Raw(Sample &sample);
protected:
+ int RxResponse1();
};
#endif // SERIALLINK_H
diff --git a/settingsdlg.cpp b/settingsdlg.cpp
index ad1629b..b626825 100644
--- a/settingsdlg.cpp
+++ b/settingsdlg.cpp
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
diff --git a/settingsdlg.h b/settingsdlg.h
index bde4275..36fa5bb 100644
--- a/settingsdlg.h
+++ b/settingsdlg.h
@@ -8,7 +8,7 @@ and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
-Sark-100-antenna-analyzerr is distributed in the hope that it will be
+Sark-100-antenna-analyzer is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.