Wyatt  1.0.1
MotorMessage.cpp
1 #include "messages/MotorMessage.h"
2 
3 
4 MotorMessage::MotorMessage(Hardware hardware, int data) : IMessage(hardware) {
5 
6  if((int)(hardware.messageLength) != sizeof(int)) {
7  throw MessageLengthException(hardware);
8  }
9 
10  if(data > FULL_FORWARD || data < FULL_BACKWARD) {
11  throw DataSizeException(data);
12  }
13 
14  this->data = data;
15 }
16 
18  // Nothing.
19 }
20 
22  return this->data;
23 }
24 
25 std::string MotorMessage::serialize() {
26  std::string serial;
27  serial.append(1, hardware.address);
28  serial.append((char*)(&(this->data)), sizeof(int));
29  return serial;
30 }
~MotorMessage() override
Hardware hardware
Definition: IMessage.h:45
MotorMessage(Hardware hardware, int data)
Definition: MotorMessage.cpp:4
std::string serialize() override