forked from tkalbitz/NaoFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfocast.cpp
70 lines (52 loc) · 1.49 KB
/
infocast.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* NaoFinder - Make robots visible
* Copyright 2012-2013 Tobias Kalbitz.
* Subject to the AGPL, version 3.
*/
#include "infocast.h"
#include <stdint.h>
#include <stdio.h>
#include <arpa/inet.h>
bool Infocast::parse(QByteArray arr)
{
const uint8_t MAGIC_BYTE = 0x11;
const uint8_t VERSION = 0x02;
const char* buf = arr.constData();
if(arr.size() < 25)
return false;
if(*buf != MAGIC_BYTE)
return false;
buf++;
if(*buf != VERSION)
return false;
buf++;
quint32 ip;
memcpy(&ip, buf, sizeof(ip));
buf += sizeof(ip);
ip = ntohl(ip);
lanIp = QHostAddress(ip).toString();
memcpy(&ip, buf, sizeof(ip));
buf += sizeof(ip);
ip = ntohl(ip);
wifiIp = QHostAddress(ip).toString();
battery = *buf; buf++;
cpuTemp = *buf; buf++;
wifiSignal = *buf; buf++;
char cBuffer[100] = {0};
char mac[6];
memcpy(&mac, buf, sizeof(mac));
buf += sizeof(mac);
snprintf(cBuffer, sizeof(cBuffer), "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0]&0xff, mac[1]&0xff, mac[2]&0xff, mac[3]&0xff, mac[4]&0xff, mac[5]&0xff);
lanMac.append(cBuffer);
memcpy(&mac, buf, sizeof(mac));
buf += sizeof(mac);
snprintf(cBuffer, sizeof(cBuffer), "%02X:%02X:%02X:%02X:%02X:%02X",
mac[0]&0xff, mac[1]&0xff, mac[2]&0xff, mac[3]&0xff, mac[4]&0xff, mac[5]&0xff);
wifiMac.append(cBuffer);
while(*buf != '\0') {
robotName.append(*buf);
buf++;
}
return true;
}