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++) {

Také k dispozici: Unified diff