-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.cpp
28 lines (24 loc) · 852 Bytes
/
packet.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
#include "packet.h"
Packet::Packet(char type)
{
this->type = type;
}
std::shared_ptr<Packet> Packet::parsePacket(QString string)
{
switch (string.toStdString()[0]) {
case ERROR_PACKET:
return std::make_shared<ErrorPacket>(string);
case MEASUREMENT_RESULT_PACKET:
return std::make_shared<MeasuremetResultPacket>(string);
case CURRENT_POSITION_PACKET:
return std::make_shared<CurrentPositionPacket>(string);
case ENDSTOP_STATE_PACKET:
return std::make_shared<EndstopStatePacket>(string);
default:
return std::make_shared<ErrorPacket>("E Unrecognized packet: " + string);
}
}
SendablePacket::SendablePacket(char type) : Packet(type) {}
QString SendablePacket::appendType(QString string) {
return (QString)type + " " + string + "\n";
}