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