Protocols: Fix includes to use the explicit path of the header files
[remote/remote-mci.git] / protocols / motecontrol / MsgRequest.cc
blobb7d5a5b167d132592f32a82e855c864a3c91354b
1 #include "protocols/motecontrol/MsgRequest.h"
3 namespace remote { namespace protocols { namespace motecontrol {
5 MsgRequest::MsgRequest(uint8_t command) : command(command), flashImage()
10 MsgRequest::MsgRequest(uint8_t*& buffer, uint32_t& buflen) : flashImage()
12 buffer=this->read(buffer,buflen);
15 MsgRequest::~MsgRequest()
18 void MsgRequest::operator = (const MsgRequest& o)
20 command = o.command;
21 flashImage = o.flashImage;
24 uint32_t MsgRequest::getLength()
26 uint32_t length = sizeof(command);
29 if (command == MOTECOMMAND_PROGRAM)
31 length += flashImage.getLength();
33 return length;
36 uint8_t* MsgRequest::write(uint8_t* buffer, uint32_t& buflen)
38 buffer = writevalue(command,buffer,buflen);
39 if (command == MOTECOMMAND_PROGRAM)
41 buffer = flashImage.write(buffer,buflen);
43 return buffer;
46 void MsgRequest::print(FILE* s)
48 fprintf(s,"MESSAGE MsgRequest\n");
49 fprintf(s,"command: ");
50 switch(command)
52 case MOTECOMMAND_PROGRAM:
53 fprintf(s,"MOTECOMMAND_PROGRAM\n");
54 fprintf(s,"flashImage: ");
55 flashImage.print(s);
56 break;
57 case MOTECOMMAND_STATUS:
58 fprintf(s,"MOTECOMMAND_STATUS\n");
59 break;
60 case MOTECOMMAND_RESET:
61 fprintf(s,"MOTECOMMAND_RESET\n");
62 break;
63 case MOTECOMMAND_STOP:
64 fprintf(s,"MOTECOMMAND_STOP\n");
65 break;
66 case MOTECOMMAND_START:
67 fprintf(s,"MOTECOMMAND_START\n");
68 break;
69 case MOTECOMMAND_CANCELPROGRAMMING:
70 fprintf(s,"MOTECOMMAND_CANCELPROGRAMMING\n");
71 break;
72 default:
73 fprintf(s,"Invalid command!\n");
74 break;
78 uint8_t* MsgRequest::read(uint8_t* buffer, uint32_t& buflen)
80 buffer = readvalue(command,buffer,buflen);
81 if (command == MOTECOMMAND_PROGRAM)
83 buffer = flashImage.read(buffer,buflen);
85 return buffer;
88 uint8_t MsgRequest::getCommand()
90 return command;
93 MsgPayload& MsgRequest::getFlashImage()
95 if ( command != MOTECOMMAND_PROGRAM )
96 __THROW__ ("Cannot get flash image when command is not MOTE_PROGRAM!");
97 return flashImage;