Skip to content

Commit

Permalink
Gros commit en approche
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLortex committed Mar 29, 2014
1 parent 7eaae8d commit 2f2df11
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 164 deletions.
29 changes: 26 additions & 3 deletions FenPrincipale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ FenPrincipale::FenPrincipale(Serial* _com) {

myDecoder = new CookieDecoder();
connect(myDecoder, SIGNAL(newValue(int,int,double)), sensormgr, SLOT(newValue(int,int,double)));
connect(myDecoder,SIGNAL(error_frame()), this, SLOT(error_frame()));
//connect(myDecoder,SIGNAL(error_frame()), this, SLOT(error_frame()));
message("[INFO] All started !");


Expand Down Expand Up @@ -153,8 +153,31 @@ void FenPrincipale::resizeEvent(QResizeEvent *) {
}

void FenPrincipale::requestAct() {
if(get_infos->isChecked())
com->readData();
/* if(get_infos->isChecked())
com->readData();*/
}


class BalayageDialog : QDialog {
public:
BalayageDialog(BalaiFrequenciel* b);
void show();
};

BalayageDialog::BalayageDialog(BalaiFrequenciel* b) {
QGridLayout *layout = new QGridLayout;
layout->addWidget(b);
setLayout(layout);
}

void BalayageDialog::show() {
QDialog::show();
}

void FenPrincipale::on_actionBalayage_frequentiel_triggered()
{
BalayageDialog* tamer = new BalayageDialog(new BalaiFrequenciel(com,this));
tamer->show();
}

void FenPrincipale::syncTime() {
Expand Down
2 changes: 2 additions & 0 deletions FenPrincipale.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "UI/boardingtable.h"
#include "UI/graphicview.h"
#include "UI/mapsview.h"
#include "balaifrequenciel.h"
#include "defines.h"
#include "tablemgr.h"

Expand Down Expand Up @@ -113,6 +114,7 @@ private slots:
void on_actionHaut_parleurs_toggled(bool arg1);
void on_action137050_triggered();
void on_action137500_triggered();
void on_actionBalayage_frequentiel_triggered();
};

#endif // FENPRINCIPALE_H
Expand Down
39 changes: 38 additions & 1 deletion FenPrincipale.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>792</width>
<height>702</height>
<height>718</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -601,7 +601,29 @@
<addaction name="separator"/>
<addaction name="actionQuitter"/>
</widget>
<widget class="QMenu" name="menuS_rie">
<property name="title">
<string>Série</string>
</property>
<widget class="QMenu" name="menuPort">
<property name="title">
<string>Port</string>
</property>
<addaction name="actionTodo_bosser"/>
</widget>
<widget class="QMenu" name="menuBaudrate">
<property name="title">
<string>Baudrate</string>
</property>
<addaction name="actionTodo_bosser_2"/>
</widget>
<addaction name="menuPort"/>
<addaction name="menuBaudrate"/>
<addaction name="separator"/>
<addaction name="actionBalayage_frequentiel"/>
</widget>
<addaction name="menuLogger"/>
<addaction name="menuS_rie"/>
</widget>
<action name="actionQuitter">
<property name="text">
Expand Down Expand Up @@ -643,6 +665,21 @@
<string>Haut-parleurs</string>
</property>
</action>
<action name="actionBalayage_frequentiel">
<property name="text">
<string>Balayage fréquentiel</string>
</property>
</action>
<action name="actionTodo_bosser">
<property name="text">
<string>Todo: bosser</string>
</property>
</action>
<action name="actionTodo_bosser_2">
<property name="text">
<string>Todo: bosser</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
Expand Down
90 changes: 70 additions & 20 deletions InPut/serial.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "serialdecoder.h"
#include "serial.h"

Serial::Serial(QString _port,qint32 _baudrate, QThread * parent) : QThread(parent)
Serial::Serial(QString _port,qint32 _baudrate)
{
port = _port;
baudrate = _baudrate;

speakers_enabled = true;
current_channel = 0;
doingBalayage = false;
}


Expand All @@ -16,11 +17,6 @@ Serial::~Serial() {
serial_port->close();
}

void Serial::run() {
init();
}


bool Serial::init() {

serial_port = new QSerialPort(this);
Expand All @@ -33,6 +29,9 @@ bool Serial::init() {
if(!serial_port->open(QIODevice::ReadWrite))
qDebug() << "yolo";


QObject::connect(serial_port, SIGNAL(readyRead()), this, SLOT(readData()));

return true;
}

Expand All @@ -55,44 +54,95 @@ void Serial::setChannel(int id) {
}

void Serial::setSpeakersEnabled(bool enabled) {
// if(enabled != speakers_enabled) {
// if(enabled != speakers_enabled) {
speakers_enabled = enabled;

QString str = enabled?"$HF":"$HM";
str = str + QChar(0x0D) + QChar(0x0A);
serial_port->write(str.toStdString().c_str());

// }
// }
}

QVector<double> Serial::balayageFrequenciel() {
qDebug() << "Balayage en cours";

doingBalayage = true;
QVector<double> data;

int nvalues = 9;

QString str = "$S";
str = str+ QChar(0x0D) + QChar(0x0A);
serial_port->write(str.toStdString().c_str());
bool finished = false;

QByteArray buffer;
QByteArray data_read;

QList<QByteArray> content;

QTime time;
time.start();


while(!finished) {
if(serial_port->bytesAvailable() > 0) {
data_read = serial_port->readAll();
qDebug() << "read:";
qDebug() << data_read;
}

buffer.append(data_read);
content = buffer.split('#');

if(content.last().size() < 2) {
buffer = content.last();
content.removeLast();
}

for(int i=0;i<content.size();i++)
data.append((content.at(i).toDouble()));

if(data.size() >= nvalues) {
finished = true;
} else if(time.elapsed() > 15000) {
finished = true;
qDebug() << " timeout";
}
}

doingBalayage = false;
qDebug() << "fin balayage";
return data;
}

void Serial::readData() {
if(doingBalayage)
return;

qDebug("===== lecture série ======");
// qDebug("l");
QList<QByteArray> trames;
/* for(int i=0;i<1024;++i)
buffer[i] = 0x00;

nb_read = read(tty_fd, buffer, 1024);*/
//int eol=0;
QByteArray dataread = serial_port->readAll();

/*for(int i=0;(i<1024)&&(eol==0);++i)
if(buffer[i] == 0x00)
eol = i;*/
// qDebug() << dataread;

QByteArray dataread = serial_port->readAll();

QByteArray data(skipped_buf);
data.append(dataread);

//qDebug() << "read: " << dataread;
qDebug() << "Buffer: " << skipped_buf;

trames = data.split('@');

if(trames.last().size() < 10) {
if(trames.last().size() < 19) {
skipped_buf = trames.last();
// qDebug() << "Buffer: " << skipped_buf;
trames.removeLast();
}

qDebug() << "===== fin lecture série =====";
// qDebug() << "f";
emit dataRead(trames);
}

Expand Down
26 changes: 6 additions & 20 deletions InPut/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,27 @@
#define SERIAL_H

#include "defines.h"
#include <QThread>
#include <QStringList>
#include <string>
//#include <windows.h>
#include <cstdio>
#include <cstdlib>
//#include <conio.h>
#include <QDebug>
#include <QFile>

#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <iostream>
#include <pthread.h>


#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>

class Serial : public QThread
class Serial : public QObject
{
Q_OBJECT

public:
Serial(QString _port="TTYUSB0",qint32 _baudrate=600,QThread * parent = 0);
Serial(QString _port="TTYUSB0",qint32 _baudrate=600);
~Serial();
void run();
bool init();
static QString toString(QByteArray str);

void setChannel(int id);
void setSpeakersEnabled(bool enabled);
QVector<double> balayageFrequenciel();


public slots:
Expand All @@ -58,9 +42,11 @@ public slots:
QByteArray skipped_buf;


bool doingBalayage;

int nb_read;
unsigned char buffer[1024];
struct termios tio;

int tty_fd;
qint32 baudrate;

Expand Down
11 changes: 8 additions & 3 deletions Logger21.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ SOURCES += \
InPut/yolodecoder.cpp \
InPut/databasecontroller.cpp \
InPut/sensor.cpp \
InPut/sensorvalue.cpp
InPut/sensorvalue.cpp \
balaifrequenciel.cpp \
UI/histogram.cpp

HEADERS += \
tablemgr.h \
Expand All @@ -53,14 +55,17 @@ HEADERS += \
UI/graphicview.h \
InPut/cookiedecoder.h \
InPut/yolodecoder.h \
InPut/databasecontroller.h
InPut/databasecontroller.h \
balaifrequenciel.h \
UI/histogram.h

FORMS += \
FenPrincipale.ui \
dialog.ui \
InPut/fileimportdialog.ui \
ChronoReader/chronoreaderwidget.ui \
ChronoReader/eventbox.ui
ChronoReader/eventbox.ui \
balaifrequenciel.ui

RESOURCES += \
res.qrc
Expand Down
13 changes: 7 additions & 6 deletions UI/graphicview.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@



#include <Qwt/qwt_plot.h>
#include <Qwt/qwt_plot_curve.h>
#include <Qwt/qwt_curve_fitter.h>
#include <Qwt/qwt_legend.h>
#include <Qwt/qwt_plot_zoomer.h>
#include <Qwt/qwt_scale_draw.h>
#include <qwt/qwt_plot_canvas.h>
#include <qwt/qwt_plot.h>
#include <qwt/qwt_plot_curve.h>
#include <qwt/qwt_curve_fitter.h>
#include <qwt/qwt_legend.h>
#include <qwt/qwt_plot_zoomer.h>
#include <qwt/qwt_scale_draw.h>

#include <FenPrincipale.h>
#include <InPut/sensorvalue.h>
Expand Down
Loading

0 comments on commit 2f2df11

Please sign in to comment.