@@ -1,1 +1,1 | |||||
1 | 023b503dbdc52f4214390519c35385722cd31f84 src/lppserial |
|
1 | 9fddeb704663451094926b8e3b10d18025c8fefb src/lppserial |
@@ -1,11 +1,38 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #include "mainwindow.h" |
|
24 | #include "mainwindow.h" | |
2 | #include <QApplication> |
|
25 | #include <QApplication> | |
|
26 | #include <uprobeprotocol.h> | |||
3 |
|
27 | |||
4 | int main(int argc, char *argv[]) |
|
28 | int main(int argc, char *argv[]) | |
5 | { |
|
29 | { | |
6 | QApplication a(argc, argv); |
|
30 | QApplication a(argc, argv); | |
7 | MainWindow w; |
|
31 | UProbeProtocol proto; | |
8 | w.show(); |
|
32 | proto.setPortName("/dev/ttyUSB0"); | |
|
33 | proto.setSpeed(38400); | |||
|
34 | proto.open(); | |||
|
35 | proto.start(); | |||
9 |
|
36 | |||
10 | return a.exec(); |
|
37 | return a.exec(); | |
11 | } |
|
38 | } |
@@ -1,14 +1,37 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #include "mainwindow.h" |
|
24 | #include "mainwindow.h" | |
2 | #include "ui_mainwindow.h" |
|
25 | #include "ui_mainwindow.h" | |
3 |
|
26 | |||
4 | MainWindow::MainWindow(QWidget *parent) : |
|
27 | MainWindow::MainWindow(QWidget *parent) : | |
5 | QMainWindow(parent), |
|
28 | QMainWindow(parent), | |
6 | ui(new Ui::MainWindow) |
|
29 | ui(new Ui::MainWindow) | |
7 | { |
|
30 | { | |
8 | ui->setupUi(this); |
|
31 | ui->setupUi(this); | |
9 | } |
|
32 | } | |
10 |
|
33 | |||
11 | MainWindow::~MainWindow() |
|
34 | MainWindow::~MainWindow() | |
12 | { |
|
35 | { | |
13 | delete ui; |
|
36 | delete ui; | |
14 | } |
|
37 | } |
@@ -1,22 +1,45 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #ifndef MAINWINDOW_H |
|
24 | #ifndef MAINWINDOW_H | |
2 | #define MAINWINDOW_H |
|
25 | #define MAINWINDOW_H | |
3 |
|
26 | |||
4 | #include <QMainWindow> |
|
27 | #include <QMainWindow> | |
5 |
|
28 | |||
6 | namespace Ui { |
|
29 | namespace Ui { | |
7 | class MainWindow; |
|
30 | class MainWindow; | |
8 | } |
|
31 | } | |
9 |
|
32 | |||
10 | class MainWindow : public QMainWindow |
|
33 | class MainWindow : public QMainWindow | |
11 | { |
|
34 | { | |
12 | Q_OBJECT |
|
35 | Q_OBJECT | |
13 |
|
36 | |||
14 | public: |
|
37 | public: | |
15 | explicit MainWindow(QWidget *parent = 0); |
|
38 | explicit MainWindow(QWidget *parent = 0); | |
16 | ~MainWindow(); |
|
39 | ~MainWindow(); | |
17 |
|
40 | |||
18 | private: |
|
41 | private: | |
19 | Ui::MainWindow *ui; |
|
42 | Ui::MainWindow *ui; | |
20 | }; |
|
43 | }; | |
21 |
|
44 | |||
22 | #endif // MAINWINDOW_H |
|
45 | #endif // MAINWINDOW_H |
@@ -1,88 +1,111 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #include "ucomport.h" |
|
24 | #include "ucomport.h" | |
2 |
|
25 | |||
3 | UComPort::UComPort() |
|
26 | UComPort::UComPort() | |
4 | { |
|
27 | { | |
5 | this->p_portMutex = new QMutex(); |
|
28 | this->p_portMutex = new QMutex(); | |
6 | this->p_opened = false; |
|
29 | this->p_opened = false; | |
7 | } |
|
30 | } | |
8 |
|
31 | |||
9 | QString UComPort::portName() |
|
32 | QString UComPort::portName() | |
10 | { |
|
33 | { | |
11 | QMutexLocker locker(this->p_portMutex); |
|
34 | QMutexLocker locker(this->p_portMutex); | |
12 | return p_PortName; |
|
35 | return p_PortName; | |
13 | } |
|
36 | } | |
14 |
|
37 | |||
15 | int UComPort::speed() |
|
38 | int UComPort::speed() | |
16 | { |
|
39 | { | |
17 | QMutexLocker locker(this->p_portMutex); |
|
40 | QMutexLocker locker(this->p_portMutex); | |
18 | return p_speed; |
|
41 | return p_speed; | |
19 | } |
|
42 | } | |
20 |
|
43 | |||
21 | void UComPort::setPortName(const QString &name) |
|
44 | void UComPort::setPortName(const QString &name) | |
22 | { |
|
45 | { | |
23 | QMutexLocker locker(this->p_portMutex); |
|
46 | QMutexLocker locker(this->p_portMutex); | |
24 | this->p_PortName = name; |
|
47 | this->p_PortName = name; | |
25 | } |
|
48 | } | |
26 |
|
49 | |||
27 | void UComPort::setSpeed(int speed) |
|
50 | void UComPort::setSpeed(int speed) | |
28 | { |
|
51 | { | |
29 | QMutexLocker locker(this->p_portMutex); |
|
52 | QMutexLocker locker(this->p_portMutex); | |
30 | this->p_speed = speed; |
|
53 | this->p_speed = speed; | |
31 | } |
|
54 | } | |
32 |
|
55 | |||
33 | bool UComPort::open() |
|
56 | bool UComPort::open() | |
34 | { |
|
57 | { | |
35 | QMutexLocker locker(this->p_portMutex); |
|
58 | QMutexLocker locker(this->p_portMutex); | |
36 | if(p_opened) |
|
59 | if(p_opened) | |
37 | { |
|
60 | { | |
38 | rs232close(this->p_port); |
|
61 | rs232close(this->p_port); | |
39 | this->p_opened = false; |
|
62 | this->p_opened = false; | |
40 | } |
|
63 | } | |
41 | this->p_port = rs232open((char*)p_PortName.toStdString().c_str()); |
|
64 | this->p_port = rs232open((char*)p_PortName.toStdString().c_str()); | |
42 | if(this->p_port!=badPortValue) |
|
65 | if(this->p_port!=badPortValue) | |
43 | { |
|
66 | { | |
44 | rs232setup(this->p_port,8,this->p_speed,rs232parityNo,rs232OneStop); |
|
67 | rs232setup(this->p_port,8,this->p_speed,rs232parityNo,rs232OneStop); | |
45 | p_opened = true; |
|
68 | p_opened = true; | |
46 | } |
|
69 | } | |
47 | return p_opened; |
|
70 | return p_opened; | |
48 | } |
|
71 | } | |
49 |
|
72 | |||
50 | bool UComPort::close() |
|
73 | bool UComPort::close() | |
51 | { |
|
74 | { | |
52 | if(p_opened) |
|
75 | if(p_opened) | |
53 | { |
|
76 | { | |
54 | p_opened = rs232close(this->p_port); |
|
77 | p_opened = rs232close(this->p_port); | |
55 | } |
|
78 | } | |
56 | return !p_opened; |
|
79 | return !p_opened; | |
57 | } |
|
80 | } | |
58 |
|
81 | |||
59 | bool UComPort::opened() |
|
82 | bool UComPort::opened() | |
60 | { |
|
83 | { | |
61 | return p_opened; |
|
84 | return p_opened; | |
62 | } |
|
85 | } | |
63 |
|
86 | |||
64 | bool UComPort::open(const QString &name, int speed) |
|
87 | bool UComPort::open(const QString &name, int speed) | |
65 | { |
|
88 | { | |
66 | setPortName(name); |
|
89 | setPortName(name); | |
67 | setSpeed(speed); |
|
90 | setSpeed(speed); | |
68 | return open(); |
|
91 | return open(); | |
69 | } |
|
92 | } | |
70 |
|
93 | |||
71 | int UComPort::availableBytes() |
|
94 | int UComPort::availableBytes() | |
72 | { |
|
95 | { | |
73 | if(p_opened) |
|
96 | if(p_opened) | |
74 | { |
|
97 | { | |
75 | return rs232availablebytes(this->p_port); |
|
98 | return rs232availablebytes(this->p_port); | |
76 | } |
|
99 | } | |
77 | return 0; |
|
100 | return 0; | |
78 | } |
|
101 | } | |
79 |
|
102 | |||
80 | int UComPort::readBytes(char *data, int count) |
|
103 | int UComPort::readBytes(char *data, int count) | |
81 | { |
|
104 | { | |
82 | return rs232read(this->p_port,data,count); |
|
105 | return rs232read(this->p_port,data,count); | |
83 | } |
|
106 | } | |
84 |
|
107 | |||
85 | int UComPort::writeBytes(char *data, int count) |
|
108 | int UComPort::writeBytes(char *data, int count) | |
86 | { |
|
109 | { | |
87 | return rs232write(this->p_port,data,count); |
|
110 | return rs232write(this->p_port,data,count); | |
88 | } |
|
111 | } |
@@ -1,37 +1,61 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
|
24 | ||||
1 | #ifndef UCOMPORT_H |
|
25 | #ifndef UCOMPORT_H | |
2 | #define UCOMPORT_H |
|
26 | #define UCOMPORT_H | |
3 |
|
27 | |||
4 | #include <QObject> |
|
28 | #include <QObject> | |
5 | #include <RS232.h> |
|
29 | #include <RS232.h> | |
6 | #include <QMutex> |
|
30 | #include <QMutex> | |
7 | #include <QMutexLocker> |
|
31 | #include <QMutexLocker> | |
8 |
|
32 | |||
9 | class UComPort |
|
33 | class UComPort | |
10 | { |
|
34 | { | |
11 | public: |
|
35 | public: | |
12 | explicit UComPort(); |
|
36 | explicit UComPort(); | |
13 |
|
37 | |||
14 | QString portName(); |
|
38 | QString portName(); | |
15 | int speed(); |
|
39 | int speed(); | |
16 | virtual void setPortName(const QString& name); |
|
40 | virtual void setPortName(const QString& name); | |
17 | virtual void setSpeed(int speed); |
|
41 | virtual void setSpeed(int speed); | |
18 |
|
42 | |||
19 | virtual bool open(); |
|
43 | virtual bool open(); | |
20 | virtual bool open(const QString& name,int speed); |
|
44 | virtual bool open(const QString& name,int speed); | |
21 | virtual bool close(); |
|
45 | virtual bool close(); | |
22 | bool opened(); |
|
46 | bool opened(); | |
23 | int availableBytes(); |
|
47 | int availableBytes(); | |
24 |
|
48 | |||
25 | int readBytes(char* data,int count); |
|
49 | int readBytes(char* data,int count); | |
26 | int writeBytes(char* data,int count); |
|
50 | int writeBytes(char* data,int count); | |
27 |
|
51 | |||
28 | private: |
|
52 | private: | |
29 | rs232port_t p_port; |
|
53 | rs232port_t p_port; | |
30 | QString p_PortName; |
|
54 | QString p_PortName; | |
31 | int p_speed; |
|
55 | int p_speed; | |
32 | QMutex* p_portMutex; |
|
56 | QMutex* p_portMutex; | |
33 | bool p_opened; |
|
57 | bool p_opened; | |
34 |
|
58 | |||
35 | }; |
|
59 | }; | |
36 |
|
60 | |||
37 | #endif // UCOMPORT_H |
|
61 | #endif // UCOMPORT_H |
@@ -1,21 +1,44 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #include "uprobe.h" |
|
24 | #include "uprobe.h" | |
2 |
|
25 | |||
3 | UProbe::UProbe(QObject *parent) : |
|
26 | UProbe::UProbe(QObject *parent) : | |
4 | QObject(parent) |
|
27 | QObject(parent) | |
5 | { |
|
28 | { | |
6 |
|
29 | |||
7 | } |
|
30 | } | |
8 |
|
31 | |||
9 | bool UProbe::setPortName(const QString &name) |
|
32 | bool UProbe::setPortName(const QString &name) | |
10 | { |
|
33 | { | |
11 | /* TODO implement this function */ |
|
34 | /* TODO implement this function */ | |
12 | Q_UNUSED(name) |
|
35 | Q_UNUSED(name) | |
13 | return false; |
|
36 | return false; | |
14 | } |
|
37 | } | |
15 |
|
38 | |||
16 | bool UProbe::setPortSpeed(int speed) |
|
39 | bool UProbe::setPortSpeed(int speed) | |
17 | { |
|
40 | { | |
18 | /* TODO implement this function */ |
|
41 | /* TODO implement this function */ | |
19 | Q_UNUSED(speed) |
|
42 | Q_UNUSED(speed) | |
20 | return false; |
|
43 | return false; | |
21 | } |
|
44 | } |
@@ -1,26 +1,49 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #ifndef UPROBE_H |
|
24 | #ifndef UPROBE_H | |
2 | #define UPROBE_H |
|
25 | #define UPROBE_H | |
3 |
|
26 | |||
4 | #include <QObject> |
|
27 | #include <QObject> | |
5 | #include <uprobeprotocol.h> |
|
28 | #include <uprobeprotocol.h> | |
6 |
|
29 | |||
7 | class UProbe : public QObject |
|
30 | class UProbe : public QObject | |
8 | { |
|
31 | { | |
9 | Q_OBJECT |
|
32 | Q_OBJECT | |
10 | public: |
|
33 | public: | |
11 | explicit UProbe(QObject *parent = 0); |
|
34 | explicit UProbe(QObject *parent = 0); | |
12 |
|
35 | |||
13 | signals: |
|
36 | signals: | |
14 | void updateChannelCount(int count); |
|
37 | void updateChannelCount(int count); | |
15 | void sendWaveFormData(int channel,float* data,int count); |
|
38 | void sendWaveFormData(int channel,float* data,int count); | |
16 |
|
39 | |||
17 | public slots: |
|
40 | public slots: | |
18 | bool setPortName(const QString& name); |
|
41 | bool setPortName(const QString& name); | |
19 | bool setPortSpeed(int speed); |
|
42 | bool setPortSpeed(int speed); | |
20 |
|
43 | |||
21 | private: |
|
44 | private: | |
22 | UProbeProtocol p_proto; |
|
45 | UProbeProtocol p_proto; | |
23 |
|
46 | |||
24 | }; |
|
47 | }; | |
25 |
|
48 | |||
26 | #endif // UPROBE_H |
|
49 | #endif // UPROBE_H |
@@ -1,159 +1,182 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #include "uprobeprotocol.h" |
|
24 | #include "uprobeprotocol.h" | |
2 |
|
25 | |||
3 | UProbeProtocol::UProbeProtocol(QObject *parent) : |
|
26 | UProbeProtocol::UProbeProtocol(QObject *parent) : | |
4 | QThread(parent),UComPort() |
|
27 | QThread(parent),UComPort(),p_datacount(0),p_index(0) | |
5 | { |
|
28 | { | |
6 | moveToThread((QThread*)this); |
|
29 | moveToThread((QThread*)this); | |
7 | } |
|
30 | } | |
8 |
|
31 | |||
9 | UProbeProtocol::~UProbeProtocol() |
|
32 | UProbeProtocol::~UProbeProtocol() | |
10 | { |
|
33 | { | |
11 | this->requestInterruption(); |
|
34 | this->requestInterruption(); | |
12 | while(isRunning()); |
|
35 | while(isRunning()); | |
13 | } |
|
36 | } | |
14 |
|
37 | |||
15 | void UProbeProtocol::run() |
|
38 | void UProbeProtocol::run() | |
16 | { |
|
39 | { | |
17 | p_buffer = (char*)malloc(bufferSize); |
|
40 | p_buffer = (char*)malloc(bufferSize); | |
18 | if(p_buffer==NULL)return; |
|
41 | if(p_buffer==NULL)return; | |
19 | while(!this->isInterruptionRequested()) |
|
42 | while(!this->isInterruptionRequested()) | |
20 | { |
|
43 | { | |
21 | getMoreData(); |
|
44 | getMoreData(); | |
22 | while(p_index<p_datacount) |
|
45 | while(p_index<p_datacount) | |
23 | { |
|
46 | { | |
24 | if(p_buffer[p_index]==(char)0xA5) |
|
47 | if(p_buffer[p_index]==(char)0xA5) | |
25 | { |
|
48 | { | |
26 | //got to Sync state |
|
49 | //got to Sync state | |
27 | while (p_datacount<(p_index+6)) |
|
50 | while (p_datacount<(p_index+6)) | |
28 | { |
|
51 | { | |
29 | getMoreData(); |
|
52 | getMoreData(); | |
30 | } |
|
53 | } | |
31 | if(FSM_SyncState()==true) |
|
54 | if(FSM_SyncState()==true) | |
32 | { |
|
55 | { | |
33 | p_index+=currentPacket->packetSize + 6; |
|
56 | p_index+=currentPacket->packetSize + 6; | |
34 | //forward DATA |
|
57 | //forward DATA | |
35 |
|
58 | emit packetReady(currentPacket); | ||
36 | } |
|
59 | } | |
37 | } |
|
60 | } | |
38 | p_index++; |
|
61 | p_index++; | |
39 | } |
|
62 | } | |
40 | } |
|
63 | } | |
41 | } |
|
64 | } | |
42 |
|
65 | |||
43 | void UProbeProtocol::setPortName(const QString &name) |
|
66 | void UProbeProtocol::setPortName(const QString &name) | |
44 | { |
|
67 | { | |
45 | UComPort::setPortName(name); |
|
68 | UComPort::setPortName(name); | |
46 | } |
|
69 | } | |
47 |
|
70 | |||
48 | void UProbeProtocol::setSpeed(int speed) |
|
71 | void UProbeProtocol::setSpeed(int speed) | |
49 | { |
|
72 | { | |
50 | UComPort::setSpeed(speed); |
|
73 | UComPort::setSpeed(speed); | |
51 | } |
|
74 | } | |
52 |
|
75 | |||
53 | bool UProbeProtocol::open() |
|
76 | bool UProbeProtocol::open() | |
54 | { |
|
77 | { | |
55 | return UComPort::open(); |
|
78 | return UComPort::open(); | |
56 | } |
|
79 | } | |
57 |
|
80 | |||
58 | bool UProbeProtocol::open(const QString &name, int speed) |
|
81 | bool UProbeProtocol::open(const QString &name, int speed) | |
59 | { |
|
82 | { | |
60 | return UComPort::open(name,speed); |
|
83 | return UComPort::open(name,speed); | |
61 | } |
|
84 | } | |
62 |
|
85 | |||
63 | bool UProbeProtocol::close() |
|
86 | bool UProbeProtocol::close() | |
64 | { |
|
87 | { | |
65 | return UComPort::close(); |
|
88 | return UComPort::close(); | |
66 | } |
|
89 | } | |
67 |
|
90 | |||
68 | void UProbeProtocol::getMoreData() |
|
91 | void UProbeProtocol::getMoreData() | |
69 | { |
|
92 | { | |
70 | int avail; |
|
93 | int avail; | |
71 | int maxCount=(bufferSize-32)-p_datacount; |
|
94 | int maxCount=(bufferSize-32)-p_datacount; | |
72 | if(p_index>(bufferSize/2)) |
|
95 | if(p_index>(bufferSize/2)) | |
73 | { |
|
96 | { | |
74 | memcpy(p_buffer,p_buffer+p_index,p_datacount-p_index); |
|
97 | memcpy(p_buffer,p_buffer+p_index,p_datacount-p_index); | |
75 | p_datacount = p_datacount-p_index; |
|
98 | p_datacount = p_datacount-p_index; | |
76 | p_index = 0; |
|
99 | p_index = 0; | |
77 | } |
|
100 | } | |
78 | if(opened()) |
|
101 | if(opened()) | |
79 | { |
|
102 | { | |
80 | avail=availableBytes(); |
|
103 | avail=availableBytes(); | |
81 | if(avail) |
|
104 | if(avail) | |
82 | { |
|
105 | { | |
83 | if(maxCount>=avail) |
|
106 | if(maxCount>=avail) | |
84 | { |
|
107 | { | |
85 | p_datacount += readBytes(p_buffer+p_datacount,avail); |
|
108 | p_datacount += readBytes(p_buffer+p_datacount,avail); | |
86 | } |
|
109 | } | |
87 | else |
|
110 | else | |
88 | { |
|
111 | { | |
89 | p_datacount += readBytes(p_buffer+p_datacount,maxCount); |
|
112 | p_datacount += readBytes(p_buffer+p_datacount,maxCount); | |
90 | } |
|
113 | } | |
91 | } |
|
114 | } | |
92 | } |
|
115 | } | |
93 | } |
|
116 | } | |
94 |
|
117 | |||
95 | bool UProbeProtocol::FSM_SyncState() |
|
118 | bool UProbeProtocol::FSM_SyncState() | |
96 | { |
|
119 | { | |
97 | if(p_buffer[p_index+1]==(char)0x0F0) |
|
120 | if(p_buffer[p_index+1]==(char)0x0F0) | |
98 | { |
|
121 | { | |
99 | return FSM_ExtractHeaderState(); |
|
122 | return FSM_ExtractHeaderState(); | |
100 | } |
|
123 | } | |
101 | else |
|
124 | else | |
102 | { |
|
125 | { | |
103 | return false; |
|
126 | return false; | |
104 | } |
|
127 | } | |
105 | } |
|
128 | } | |
106 |
|
129 | |||
107 | bool UProbeProtocol::FSM_ExtractHeaderState() |
|
130 | bool UProbeProtocol::FSM_ExtractHeaderState() | |
108 | { |
|
131 | { | |
109 |
|
132 | |||
110 | currentPacket = new UProbeProtocolPacket(); |
|
133 | currentPacket = new UProbeProtocolPacket(); | |
111 | currentPacket->packetNumber = p_buffer[p_index+2]; |
|
134 | currentPacket->packetNumber = p_buffer[p_index+2]; | |
112 | currentPacket->packetSize = ((unsigned int)p_buffer[p_index+3] + 1)*2; |
|
135 | currentPacket->packetSize = ((unsigned int)p_buffer[p_index+3] + 1)*2; | |
113 | currentPacket->channelCount = 0xF & (int)(p_buffer[p_index+4]>>4); |
|
136 | currentPacket->channelCount = 0xF & ((int)(p_buffer[p_index+4]>>4) +1); | |
114 | currentPacket->coding = (UProbeProtocol::UProbeProtocolPacket::PacketCoding)(0x3 & (int)(p_buffer[p_index+4]>>2)); |
|
137 | currentPacket->coding = (UProbeProtocol::UProbeProtocolPacket::PacketCoding)(0x3 & (int)(p_buffer[p_index+4]>>2)); | |
115 | currentPacket->resolution = (UProbeProtocol::UProbeProtocolPacket::PacketResolution)(0x3 & (int)(p_buffer[p_index+4])); |
|
138 | currentPacket->resolution = (UProbeProtocol::UProbeProtocolPacket::PacketResolution)(0x3 & (int)(p_buffer[p_index+4])); | |
116 | currentPacket->ID = (unsigned int)p_buffer[p_index+5]; |
|
139 | currentPacket->ID = (unsigned int)p_buffer[p_index+5]; | |
117 | while(p_datacount<(p_index+2+4+currentPacket->packetSize+1)) |
|
140 | while(p_datacount<(p_index+2+4+currentPacket->packetSize+1)) | |
118 | { |
|
141 | { | |
119 | getMoreData(); |
|
142 | getMoreData(); | |
120 | } |
|
143 | } | |
121 | return FSM_ExtractPayloadState(); |
|
144 | return FSM_ExtractPayloadState(); | |
122 | } |
|
145 | } | |
123 |
|
146 | |||
124 |
|
147 | |||
125 | bool UProbeProtocol::FSM_ExtractPayloadState() |
|
148 | bool UProbeProtocol::FSM_ExtractPayloadState() | |
126 | { |
|
149 | { | |
127 | if(!currentPacket || currentPacket->packetSize < 2 || (currentPacket->packetSize>UProbeProtocolMaxPacketSize)) |
|
150 | if(!currentPacket || currentPacket->packetSize < 2 || (currentPacket->packetSize>UProbeProtocolMaxPacketSize)) | |
128 | return false; |
|
151 | return false; | |
129 | currentPacket->data = (char*)malloc(currentPacket->packetSize); |
|
152 | currentPacket->data = (char*)malloc(currentPacket->packetSize); | |
130 | if(currentPacket->data != NULL) |
|
153 | if(currentPacket->data != NULL) | |
131 | { |
|
154 | { | |
132 | memcpy(currentPacket->data,p_buffer+p_index+6,currentPacket->packetSize); |
|
155 | memcpy(currentPacket->data,p_buffer+p_index+6,currentPacket->packetSize); | |
133 | return FSM_CheckCRCState(); |
|
156 | return FSM_CheckCRCState(); | |
134 | } |
|
157 | } | |
135 | return false; |
|
158 | return false; | |
136 | } |
|
159 | } | |
137 |
|
160 | |||
138 | bool UProbeProtocol::FSM_CheckCRCState() |
|
161 | bool UProbeProtocol::FSM_CheckCRCState() | |
139 | { |
|
162 | { | |
140 | currentPacket->receivedCRC = p_buffer[p_index+6+currentPacket->packetSize]; |
|
163 | currentPacket->receivedCRC = p_buffer[p_index+6+currentPacket->packetSize]; | |
141 | currentPacket->localCRC = spw_CRC(p_buffer+p_index,6+currentPacket->packetSize); |
|
164 | currentPacket->localCRC = spw_CRC(p_buffer+p_index,6+currentPacket->packetSize); | |
142 | if(currentPacket->localCRC == currentPacket->receivedCRC) |
|
165 | if(currentPacket->localCRC == currentPacket->receivedCRC) | |
143 | { |
|
166 | { | |
144 | currentPacket->correct = true; |
|
167 | currentPacket->correct = true; | |
145 | return true; |
|
168 | return true; | |
146 | } |
|
169 | } | |
147 | currentPacket->correct = false; |
|
170 | currentPacket->correct = false; | |
148 | return false; |
|
171 | return false; | |
149 | } |
|
172 | } | |
150 |
|
173 | |||
151 |
|
174 | |||
152 |
|
175 | |||
153 |
|
176 | |||
154 |
|
177 | |||
155 |
|
178 | |||
156 |
|
179 | |||
157 |
|
180 | |||
158 |
|
181 | |||
159 |
|
182 |
@@ -1,155 +1,179 | |||||
|
1 | /*------------------------------------------------------------------------------ | |||
|
2 | -- This file is a part of the Uprobe Software | |||
|
3 | -- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | |||
|
4 | -- | |||
|
5 | -- This program is free software; you can redistribute it and/or modify | |||
|
6 | -- it under the terms of the GNU General Public License as published by | |||
|
7 | -- the Free Software Foundation; either version 2 of the License, or | |||
|
8 | -- (at your option) any later version. | |||
|
9 | -- | |||
|
10 | -- This program is distributed in the hope that it will be useful, | |||
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
13 | -- GNU General Public License for more details. | |||
|
14 | -- | |||
|
15 | -- You should have received a copy of the GNU General Public License | |||
|
16 | -- along with this program; if not, write to the Free Software | |||
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
|
18 | -------------------------------------------------------------------------------*/ | |||
|
19 | /*-- Author : Alexis Jeandet | |||
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |||
|
21 | -- Author : Kaveh Mohamadabadi | |||
|
22 | -- Mail : kaveh.mohamadabadi@lpp.polytechnique.fr | |||
|
23 | --------------------------------------------------------------------------------*/ | |||
1 | #ifndef UPROBEPROTOCOL_H |
|
24 | #ifndef UPROBEPROTOCOL_H | |
2 | #define UPROBEPROTOCOL_H |
|
25 | #define UPROBEPROTOCOL_H | |
3 |
|
26 | |||
4 | #include <QObject> |
|
27 | #include <QObject> | |
5 | #include <QThread> |
|
28 | #include <QThread> | |
6 | #include <QMutex> |
|
29 | #include <QMutex> | |
7 | #include <QSemaphore> |
|
30 | #include <QSemaphore> | |
8 | #include <ucomport.h> |
|
31 | #include <ucomport.h> | |
9 | #define UProbeProtocolMaxPacketSize 512 |
|
32 | #define UProbeProtocolMaxPacketSize 512 | |
10 | #define bufferSize (((UProbeProtocolMaxPacketSize+7)+6)*2+32) |
|
33 | #define bufferSize (((UProbeProtocolMaxPacketSize+7)+6)*2+32) | |
11 |
|
34 | |||
12 | /* |
|
35 | /* | |
13 | =========================================================================================== |
|
36 | =========================================================================================== | |
14 | =========================================================================================== |
|
37 | =========================================================================================== | |
15 | βββ ββββββββββ βββββββ βββββββ βββββββββ βββββββ βββββββ βββββββ βββ |
|
38 | βββ ββββββββββ βββββββ βββββββ βββββββββ βββββββ βββββββ βββββββ βββ | |
16 | βββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
|
39 | βββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
17 | βββ ββββββββββββββββββββββ βββ βββ βββ ββββββ βββ ββββββ |
|
40 | βββ ββββββββββββββββββββββ βββ βββ βββ ββββββ βββ ββββββ | |
18 | βββ ββββββββββ βββββββββββ βββ βββ βββ ββββββ βββ ββββββ |
|
41 | βββ ββββββββββ βββββββββββ βββ βββ βββ ββββββ βββ ββββββ | |
19 | ββββββββββββ βββ ββββββββββββ βββ ββββββββββββββββββββββββββββββββββ |
|
42 | ββββββββββββ βββ ββββββββββββ βββ ββββββββββββββββββββββββββββββββββ | |
20 | βββββββ βββ βββ βββ βββββββ βββ βββββββ βββββββ βββββββ ββββββββ |
|
43 | βββββββ βββ βββ βββ βββββββ βββ βββββββ βββββββ βββββββ ββββββββ | |
21 | ------------------------------------------------------------------------------------------- |
|
44 | ------------------------------------------------------------------------------------------- | |
22 |
|
45 | |||
23 | || Sync (2Bytes) || Header(4 Bytes) || Payload Data (2 to 512 Bytes) || CRC(1 Byte) || |
|
46 | || Sync (2Bytes) || Header(4 Bytes) || Payload Data (2 to 512 Bytes) || CRC(1 Byte) || | |
24 |
|| 0xA5 0xF0 || PCPT | (PSZ-1 |
|
47 | || 0xA5 0xF0 || PCPT | (PSZ/2)-1 | SHAPE | ID || [...] || Uses SpaceWire CRC || | |
25 |
|
48 | |||
26 |
|
49 | |||
27 | Shape: |
|
50 | Shape: | |
28 | |msb lsb| |
|
51 | |msb lsb| | |
29 | | Channel count -1 [7:4] | Coding [3:2] | Channel resolution[1:0] -1 | |
|
52 | | Channel count -1 [7:4] | Coding [3:2] | Channel resolution[1:0] -1 | | |
30 |
|
53 | |||
31 | Coding: |
|
54 | Coding: | |
32 | 0 Unsigned integer |
|
55 | 0 Unsigned integer | |
33 | 1 Signed integer (Two complement) |
|
56 | 1 Signed integer (Two complement) | |
34 | 2 Signed integer (sign bit) |
|
57 | 2 Signed integer (sign bit) | |
35 | 3 floating point |
|
58 | 3 floating point | |
36 |
|
59 | |||
37 | =========================================================================================== |
|
60 | =========================================================================================== | |
38 | */ |
|
61 | */ | |
39 |
|
62 | |||
40 |
|
63 | |||
41 |
|
64 | |||
42 | static const unsigned char SPW_CRCTable[] = { |
|
65 | static const unsigned char SPW_CRCTable[] = { | |
43 | 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75, |
|
66 | 0x00, 0x91, 0xe3, 0x72, 0x07, 0x96, 0xe4, 0x75, | |
44 | 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b, |
|
67 | 0x0e, 0x9f, 0xed, 0x7c, 0x09, 0x98, 0xea, 0x7b, | |
45 | 0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69, |
|
68 | 0x1c, 0x8d, 0xff, 0x6e, 0x1b, 0x8a, 0xf8, 0x69, | |
46 | 0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67, |
|
69 | 0x12, 0x83, 0xf1, 0x60, 0x15, 0x84, 0xf6, 0x67, | |
47 | 0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d, |
|
70 | 0x38, 0xa9, 0xdb, 0x4a, 0x3f, 0xae, 0xdc, 0x4d, | |
48 | 0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43, |
|
71 | 0x36, 0xa7, 0xd5, 0x44, 0x31, 0xa0, 0xd2, 0x43, | |
49 | 0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51, |
|
72 | 0x24, 0xb5, 0xc7, 0x56, 0x23, 0xb2, 0xc0, 0x51, | |
50 | 0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f, |
|
73 | 0x2a, 0xbb, 0xc9, 0x58, 0x2d, 0xbc, 0xce, 0x5f, | |
51 | 0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05, |
|
74 | 0x70, 0xe1, 0x93, 0x02, 0x77, 0xe6, 0x94, 0x05, | |
52 | 0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b, |
|
75 | 0x7e, 0xef, 0x9d, 0x0c, 0x79, 0xe8, 0x9a, 0x0b, | |
53 | 0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19, |
|
76 | 0x6c, 0xfd, 0x8f, 0x1e, 0x6b, 0xfa, 0x88, 0x19, | |
54 | 0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17, |
|
77 | 0x62, 0xf3, 0x81, 0x10, 0x65, 0xf4, 0x86, 0x17, | |
55 | 0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d, |
|
78 | 0x48, 0xd9, 0xab, 0x3a, 0x4f, 0xde, 0xac, 0x3d, | |
56 | 0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33, |
|
79 | 0x46, 0xd7, 0xa5, 0x34, 0x41, 0xd0, 0xa2, 0x33, | |
57 | 0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21, |
|
80 | 0x54, 0xc5, 0xb7, 0x26, 0x53, 0xc2, 0xb0, 0x21, | |
58 | 0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f, |
|
81 | 0x5a, 0xcb, 0xb9, 0x28, 0x5d, 0xcc, 0xbe, 0x2f, | |
59 | 0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95, |
|
82 | 0xe0, 0x71, 0x03, 0x92, 0xe7, 0x76, 0x04, 0x95, | |
60 | 0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b, |
|
83 | 0xee, 0x7f, 0x0d, 0x9c, 0xe9, 0x78, 0x0a, 0x9b, | |
61 | 0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89, |
|
84 | 0xfc, 0x6d, 0x1f, 0x8e, 0xfb, 0x6a, 0x18, 0x89, | |
62 | 0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87, |
|
85 | 0xf2, 0x63, 0x11, 0x80, 0xf5, 0x64, 0x16, 0x87, | |
63 | 0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad, |
|
86 | 0xd8, 0x49, 0x3b, 0xaa, 0xdf, 0x4e, 0x3c, 0xad, | |
64 | 0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3, |
|
87 | 0xd6, 0x47, 0x35, 0xa4, 0xd1, 0x40, 0x32, 0xa3, | |
65 | 0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1, |
|
88 | 0xc4, 0x55, 0x27, 0xb6, 0xc3, 0x52, 0x20, 0xb1, | |
66 | 0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf, |
|
89 | 0xca, 0x5b, 0x29, 0xb8, 0xcd, 0x5c, 0x2e, 0xbf, | |
67 | 0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5, |
|
90 | 0x90, 0x01, 0x73, 0xe2, 0x97, 0x06, 0x74, 0xe5, | |
68 | 0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb, |
|
91 | 0x9e, 0x0f, 0x7d, 0xec, 0x99, 0x08, 0x7a, 0xeb, | |
69 | 0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9, |
|
92 | 0x8c, 0x1d, 0x6f, 0xfe, 0x8b, 0x1a, 0x68, 0xf9, | |
70 | 0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7, |
|
93 | 0x82, 0x13, 0x61, 0xf0, 0x85, 0x14, 0x66, 0xf7, | |
71 | 0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd, |
|
94 | 0xa8, 0x39, 0x4b, 0xda, 0xaf, 0x3e, 0x4c, 0xdd, | |
72 | 0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3, |
|
95 | 0xa6, 0x37, 0x45, 0xd4, 0xa1, 0x30, 0x42, 0xd3, | |
73 | 0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1, |
|
96 | 0xb4, 0x25, 0x57, 0xc6, 0xb3, 0x22, 0x50, 0xc1, | |
74 | 0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf |
|
97 | 0xba, 0x2b, 0x59, 0xc8, 0xbd, 0x2c, 0x5e, 0xcf | |
75 | }; |
|
98 | }; | |
76 | inline unsigned char _spw_CRC_(unsigned char INCR, unsigned char INBYTE) |
|
99 | inline unsigned char _spw_CRC_(unsigned char INCR, unsigned char INBYTE) | |
77 | { |
|
100 | { | |
78 | return SPW_CRCTable[INCR ^ INBYTE]; |
|
101 | return SPW_CRCTable[INCR ^ INBYTE]; | |
79 | } |
|
102 | } | |
80 |
|
103 | |||
81 | inline char spw_CRC(char* buffer, int size) |
|
104 | inline char spw_CRC(char* buffer, int size) | |
82 | { |
|
105 | { | |
83 | unsigned char CRC = 0; |
|
106 | unsigned char CRC = 0; | |
84 | for(int i=0;i<size;i++) |
|
107 | for(int i=0;i<size;i++) | |
85 | { |
|
108 | { | |
86 | CRC = _spw_CRC_(CRC,(unsigned char)buffer[i]); |
|
109 | CRC = _spw_CRC_(CRC,(unsigned char)buffer[i]); | |
87 | } |
|
110 | } | |
88 | return CRC; |
|
111 | return CRC; | |
89 | } |
|
112 | } | |
90 |
|
113 | |||
91 |
|
114 | |||
92 | class UProbeProtocol : public QThread , public UComPort |
|
115 | class UProbeProtocol : public QThread , public UComPort | |
93 | { |
|
116 | { | |
94 | class UProbeProtocolPacket |
|
117 | class UProbeProtocolPacket | |
95 | { |
|
118 | { | |
96 | public: |
|
119 | public: | |
97 | typedef enum {UProbeUint=0,UProdeInt=1,UProbeSInt=2,UProbeFloat=3}PacketCoding; |
|
120 | typedef enum {UProbeUint=0,UProdeInt=1,UProbeSInt=2,UProbeFloat=3}PacketCoding; | |
98 | typedef enum {res1Byte=0,res2Bytes=1,res3Bytes=2,res4Bytes=3}PacketResolution; |
|
121 | typedef enum {res1Byte=0,res2Bytes=1,res3Bytes=2,res4Bytes=3}PacketResolution; | |
99 |
|
122 | |||
100 | UProbeProtocolPacket() |
|
123 | UProbeProtocolPacket() | |
101 | :packetNumber(0),packetSize(0),channelCount(0), |
|
124 | :packetNumber(0),packetSize(0),channelCount(0), | |
102 | coding(UProbeUint),resolution(res1Byte),ID(0),data(NULL),correct(false) |
|
125 | coding(UProbeUint),resolution(res1Byte),ID(0),data(NULL),correct(false) | |
103 | { |
|
126 | { | |
104 |
|
127 | |||
105 | } |
|
128 | } | |
106 |
|
129 | |||
107 | int packetNumber; |
|
130 | int packetNumber; | |
108 | int packetSize; |
|
131 | int packetSize; | |
109 | int channelCount; |
|
132 | int channelCount; | |
110 | UProbeProtocolPacket::PacketCoding coding; |
|
133 | UProbeProtocolPacket::PacketCoding coding; | |
111 | UProbeProtocolPacket::PacketResolution resolution; |
|
134 | UProbeProtocolPacket::PacketResolution resolution; | |
112 | int ID; |
|
135 | int ID; | |
113 | char* data; |
|
136 | char* data; | |
114 | bool correct; |
|
137 | bool correct; | |
115 | char receivedCRC; |
|
138 | char receivedCRC; | |
116 | char localCRC; |
|
139 | char localCRC; | |
117 | }; |
|
140 | }; | |
118 |
|
141 | |||
119 | Q_OBJECT |
|
142 | Q_OBJECT | |
120 |
|
143 | |||
121 | public: |
|
144 | public: | |
122 | explicit UProbeProtocol(QObject *parent = 0); |
|
145 | explicit UProbeProtocol(QObject *parent = 0); | |
123 | ~UProbeProtocol(); |
|
146 | ~UProbeProtocol(); | |
124 | void run(); |
|
147 | void run(); | |
125 |
|
148 | |||
126 | signals: |
|
149 | signals: | |
|
150 | void packetReady(UProbeProtocolPacket* currentPacket); | |||
127 |
|
151 | |||
128 | public slots: |
|
152 | public slots: | |
129 | void setPortName(const QString& name); |
|
153 | void setPortName(const QString& name); | |
130 | void setSpeed(int speed); |
|
154 | void setSpeed(int speed); | |
131 | bool open(); |
|
155 | bool open(); | |
132 | bool open(const QString& name,int speed); |
|
156 | bool open(const QString& name,int speed); | |
133 | bool close(); |
|
157 | bool close(); | |
134 |
|
158 | |||
135 | private: |
|
159 | private: | |
136 | void getMoreData(); |
|
160 | void getMoreData(); | |
137 | bool FSM_SyncState(); |
|
161 | bool FSM_SyncState(); | |
138 | bool FSM_ExtractHeaderState(); |
|
162 | bool FSM_ExtractHeaderState(); | |
139 | bool FSM_ExtractPayloadState(); |
|
163 | bool FSM_ExtractPayloadState(); | |
140 | bool FSM_CheckCRCState(); |
|
164 | bool FSM_CheckCRCState(); | |
141 | char* p_buffer; |
|
165 | char* p_buffer; | |
142 | int p_datacount; |
|
166 | int p_datacount; | |
143 | int p_index; |
|
167 | int p_index; | |
144 | UProbeProtocolPacket* currentPacket; |
|
168 | UProbeProtocolPacket* currentPacket; | |
145 | }; |
|
169 | }; | |
146 |
|
170 | |||
147 | #endif // UPROBEPROTOCOL_H |
|
171 | #endif // UPROBEPROTOCOL_H | |
148 |
|
172 | |||
149 |
|
173 | |||
150 |
|
174 | |||
151 |
|
175 | |||
152 |
|
176 | |||
153 |
|
177 | |||
154 |
|
178 | |||
155 |
|
179 |
General Comments 0
You need to be logged in to leave comments.
Login now