Projekt

Obecné

Profil

« Předchozí | Další » 

Revize f06d5ae1

Přidáno uživatelem Jakub Hejman před téměř 4 roky(ů)

Re #8736 - Implement Additional Messages

Zobrazit rozdíly:

deltarobot/curvedataserver.cpp
3 3
#include <QDebug>
4 4
#include <QHostAddress>
5 5
#include <QAbstractSocket>
6
#include <QVector4D>
6 7
#include <chrono>
7 8

  
8 9

  
......
252 253
    }
253 254
}
254 255

  
256
void CurveDataServer::sendActualDirection(float x, float y, float z)
257
{
258
    QByteArray message = message128(0x4007,
259
                                    *((uint32_t*) &x),
260
                                    *((uint32_t*) &y),
261
                                    *((uint32_t*) &z));
262

  
263
    {
264
        std::lock_guard<decltype (_socketsLock)> l(_socketsLock);
265
        for (auto& client : _sockets) {
266
                client.socket->write(message);
267
        }
268
    }
269
}
270

  
271
void CurveDataServer::sendTargetDirection(float x, float y, float z)
272
{
273
    QByteArray message = message128(0x4008,
274
                                    *((uint32_t*) &x),
275
                                    *((uint32_t*) &y),
276
                                    *((uint32_t*) &z));
277

  
278
    {
279
        std::lock_guard<decltype (_socketsLock)> l(_socketsLock);
280
        for (auto& client : _sockets) {
281
                client.socket->write(message);
282
        }
283
    }
284
}
285

  
286
void CurveDataServer::sendNewCurve(QList<QVector3D> points)
287
{
288
    int size = points.size();
289

  
290
    QByteArray message = messageVarLength(0xF009, (uint32_t) size * 12);
291

  
292
    for (int i = 0; i < size; i++)
293
    {
294
        float xf = points[i].x();
295
        float yf = points[i].y();
296
        float zf = points[i].z();
297

  
298
        uint8_t *x = ((uint8_t*) &xf);
299
        uint8_t *y = ((uint8_t*) &yf);
300
        uint8_t *z = ((uint8_t*) &zf);
301

  
302
        message[2 + 4 + i*12 + 0] = x[0];
303
        message[2 + 4 + i*12 + 1] = x[1];
304
        message[2 + 4 + i*12 + 2] = x[2];
305
        message[2 + 4 + i*12 + 3] = x[3];
306

  
307
        message[2 + 4 + i*12 + 4] = y[0];
308
        message[2 + 4 + i*12 + 5] = y[1];
309
        message[2 + 4 + i*12 + 6] = y[2];
310
        message[2 + 4 + i*12 + 7] = y[3];
311

  
312
        message[2 + 4 + i*12 + 8] = z[0];
313
        message[2 + 4 + i*12 + 9] = z[1];
314
        message[2 + 4 + i*12 + 10] = z[2];
315
        message[2 + 4 + i*12 + 11] = z[3];
316
    }
317

  
318
    {
319
        std::lock_guard<decltype (_socketsLock)> l(_socketsLock);
320
        for (auto& client : _sockets) {
321
                client.socket->write(message);
322
        }
323
    }
324
}
325

  
326
void CurveDataServer::sendNewCurve(QList<QVector4D> points)
327
{
328
    QList<QVector3D> curve3d;
329
    int itemCount = points.size();
330

  
331
    curve3d.clear();
332
    if (itemCount > MAX_CURVE_SIZE)
333
        itemCount = MAX_CURVE_SIZE;
334
    for (int i = 0; i < itemCount; i++)
335
    {
336
        curve3d.append(points[i].toVector3D());
337
    }
338

  
339
    sendNewCurve(curve3d);
340
}
341

  
255 342
QList<CurveDataServer::Client>::iterator CurveDataServer::clientOf(QTcpSocket *socket) {
256 343
    std::lock_guard<decltype (_socketsLock)> l(_socketsLock);
257 344
    for (auto it = _sockets.begin(); it != _sockets.end(); it++) {
deltarobot/curvedataserver.h
7 7
#include <map>
8 8
#include <mutex>
9 9

  
10

  
11
#include "../element/trajectory.hpp" //obsahuje MAX_CURVE_SIZE kterou se ridi sendNewCurve 4D
12

  
10 13
class CurveDataServer : QObject
11 14
{
12 15
    Q_OBJECT
......
31 34
    ~CurveDataServer();
32 35

  
33 36
    void sendActuatorPosition(float x, float y, float z);
37
    void sendActualDirection(float x, float y, float z);
38
    void sendTargetDirection(float x, float y, float z);
39
    void sendNewCurve(QList<QVector4D> points);
40
    void sendNewCurve(QList<QVector3D> points);
34 41

  
35 42
public slots:
36 43
    void onNewConnection();
deltarobot/gl/scene.cpp
1 1
#include "scene.hpp"
2 2

  
3
#include "../curvedataserver.h"
4

  
3 5
const int Scene::TRAJECTORY_I = 0;
4 6
const int Scene::SPHERE_I = 1;
5 7
const int Scene::SPHERE_II = 2;
......
58 60
    }
59 61
}
60 62

  
61
void Scene::setCurve(QList<QVector4D> curve)
63
void Scene::setCurve(QList<QVector4D> curve, CurveDataServer * cdServer)
62 64
{
63 65
    // Vyhledani minimalnich a maximalnich souradnic.
64 66
    QList<QVector3D> curve3d;
......
149 151
    
150 152
    // Vykreslit.
151 153
    update();
154

  
155
    if (cdServer) {
156
        cdServer->sendNewCurve(curve3d);
157
    }
152 158
}
153 159

  
154 160
void Scene::setSphereData(const QVector3D &position, const QVector3D &fArrow, const QVector3D &sArrow)
deltarobot/gl/scene.hpp
18 18
#include "../element/arrow.hpp"
19 19
#include "../element/wall.hpp"
20 20

  
21

  
22
#include "../curvedataserver.h"
23

  
24

  
21 25
/// Instance třídy představuje vykreslovanou 3D scénu.
22 26
class Scene: public QOpenGLWidget
23 27
{
......
39 43
        /// hodnot pro dráhu, kouli a zdi. Změna kamery, pozice světla. Vynulování
40 44
        /// rotace.
41 45
        /// @param QList<QVector4D> curve - seznam bodů definující křivku.
42
        void setCurve(QList<QVector4D> curve);
46
        void setCurve(QList<QVector4D> curve, CurveDataServer * cdServer);
43 47
        
44 48
        /// Nastaveni pozice koule a vektoru pro obě šipky.
45 49
        /// @param const QVector3D &position - pozice koule.
deltarobot/mainwindow.cpp
485 485
#endif
486 486
        ui->glwidget->setTubusColor(QVector4D(1, 0.737f, 0.231f, 0.7f));
487 487
        if (actCurveType != CURVE_NONE)
488
            ui->glwidget->setCurve(calculatedCurve);
488
            ui->glwidget->setCurve(calculatedCurve, cdServer);
489 489
        currState = SEND_CURVE;
490 490
    }
491 491
}
......
609 609
        file.close();
610 610
        if (calculatedCurve.size() > 0) {
611 611
            ui->glwidget->setTubusColor(QVector4D(1, 0.737f, 0.231f, 0.7f));
612
            ui->glwidget->setCurve(calculatedCurve);
612
            ui->glwidget->setCurve(calculatedCurve, cdServer);
613 613
        }
614 614
        actCurveFileName = fileName;
615 615
        actCurveType = CURVE_EXTERN;
......
1072 1072
    }
1073 1073
#endif
1074 1074
    cdServer->sendActuatorPosition(spherePos.x(), spherePos.y(), spherePos.z());
1075
    cdServer->sendActualDirection(actualArrow.x(), actualArrow.y(), actualArrow.z());
1076
    cdServer->sendTargetDirection(dirArrow.x(), dirArrow.y(), dirArrow.z());
1075 1077
}
1076 1078

  
1077 1079
//! Příjem dat ze stroje
......
1314 1316
                            dlg.exec();
1315 1317
                        }
1316 1318
                        if (calculatedCurve.size() > 0) {
1317
                            ui->glwidget->setCurve(calculatedCurve);
1319
                            ui->glwidget->setCurve(calculatedCurve, cdServer);
1318 1320
                        } else {
1319 1321
                            infoDialog dlg;
1320 1322
                            dlg.setInfoText(tr("Velikost křivky"), tr("Naučená křivka nelze použít. Neplatná data."));
......
1477 1479
    calculatedCurve.append(QVector4D(0,0,-4900,0.0));
1478 1480
    calculatedCurve.append(QVector4D(0,0,-4900,0.0));
1479 1481
    calculatedCurve.append(QVector4D(0,0,-4000,0.0));
1480
    ui->glwidget->setCurve(calculatedCurve);
1482
    ui->glwidget->setCurve(calculatedCurve, cdServer);
1481 1483
}
1482 1484

  
1483 1485
//! Aktualizace času při asistovaném cvičení pacienta

Také k dispozici: Unified diff