This repository was archived by the owner on Feb 28, 2019. It is now read-only.
forked from zhangh94/MAQSS_GCS
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathXbeeInterface.cpp
More file actions
114 lines (88 loc) · 3.26 KB
/
Copy pathXbeeInterface.cpp
File metadata and controls
114 lines (88 loc) · 3.26 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "XbeeInterface.hpp"
XbeeInterface::XbeeInterface(QObject *parent) : QObject(parent)
{
qDebug() << "Instantiating single_test class";
sleep(1);
serial_interface.ReadHandler = std::bind(&XbeeInterface::callbackFun, this, std::placeholders::_1);
// serial_interface.Connect();
// serial_interface.AsyncReadFrame();
qDebug() << "Finished instantiating single_test class";
}
void XbeeInterface::callbackFun(XBEE::Frame *item) {
qDebug() << "Entered Callback";
// ReceivePacket pointer
// dynamic cast to type of frame I think it is (ReceivePacket), store in pointer
XBEE::ReceivePacket *r_packet = dynamic_cast<XBEE::ReceivePacket*>(item);
std::string str_data;
// check if pointer is NULL
if (r_packet != NULL) {
qDebug() << "Starting GetData";
str_data = r_packet->GetData();
std::cout << "Data: " << str_data.c_str() << std::endl;
}
QString q_str = QString::fromUtf8(str_data.c_str());
emit newMsg(q_str);
// qDebug() << "Inside Here";
}
void XbeeInterface::writeMsg(QString msg) {
// Assumes msg is of the form NEWMSG,TYPE,QX,....
if (comms) {
// Split string by , to determine target
qDebug() << "Writing Msg: " << msg;
QStringList list1 = msg.split(',', QString::SkipEmptyParts);
QString target_vehicle = list1.at(2).at(1);
unsigned int target_id = target_vehicle.toUInt();
std::string str_data = msg.toStdString();
// TODO: Make this less hardcoded
XBEE::TransmitRequest frame_a(0x0013A20040A8157E);
XBEE::TransmitRequest frame_b(0x0013A20040F8063C);
XBEE::TransmitRequest frame_c(0x0013A20040F8064D);
XBEE::TransmitRequest frame_d(0x0013A20040A815D6);
qDebug() << "Target_id: " << target_id;
// TODO: Refactor to not be hardcoded
switch (target_id) {
case 0:
frame_a.SetData(str_data);
serial_interface.AsyncWriteFrame(&frame_a);
break;
case 1:
frame_b.SetData(str_data);
serial_interface.AsyncWriteFrame(&frame_b);
break;
case 2:
frame_c.SetData(str_data);
serial_interface.AsyncWriteFrame(&frame_c);
break;
case 3:
frame_d.SetData(str_data);
serial_interface.AsyncWriteFrame(&frame_d);
break;
}
}
else qDebug() << "Serial Interface not established. Start First";
}
void XbeeInterface::startComms() {
qDebug() << "Starting Serial Interface";
serial_interface.Connect();
serial_interface.AsyncReadFrame();
comms = true;
}
void XbeeInterface::stopComms() {
qDebug() << "Stopping Serial Interface";
serial_interface.Stop();
comms = false;
}
/*
void SingletonTest::handleSignalExample(const QVariant& object) {
//start button will pass in entire mainPage object
// qDebug() << "Signal Passes In - " << object;
// QQuickItem *item = qobject_cast<QQuickItem*>(object.value<QObject*>());
// qDebug() << item->width();
// cast as a QObject to gain access to property read and write
QObject *obj = object.value<QObject*>();
// qDebug() << QQmlProperty::read(obj, "angle");
// QQmlProperty::write(obj,"angle", 124);
qDebug() << QQmlProperty::read(obj, "searchChunkCoords");
// QJSValue* array = QQmlProperty::read(obj, "searchChunkCoords").value<QJSValue*>();
}
*/