Initial commit
[remote/remote-mci.git] / protocols / motecontrol / MsgRequest.cc
blob40d977e5d917628f444cea201f72526747240795
1 #include "MsgRequest.h"
2 #include "macros.h"
4 namespace remote { namespace protocols { namespace motecontrol {
6 MsgRequest::MsgRequest(uint8_t command) : command(command), flashImage()
11 MsgRequest::MsgRequest(uint8_t*& buffer, uint32_t& buflen) : flashImage()
13 buffer=this->read(buffer,buflen);
16 MsgRequest::~MsgRequest()
19 void MsgRequest::operator = (const MsgRequest& o)
21 command = o.command;
22 flashImage = o.flashImage;
25 uint32_t MsgRequest::getLength()
27 uint32_t length = sizeof(command);
30 if (command == MOTECOMMAND_PROGRAM)
32 length += flashImage.getLength();
34 return length;
37 uint8_t* MsgRequest::write(uint8_t* buffer, uint32_t& buflen)
39 buffer = writevalue(command,buffer,buflen);
40 if (command == MOTECOMMAND_PROGRAM)
42 buffer = flashImage.write(buffer,buflen);
44 return buffer;
47 void MsgRequest::print(_IO_FILE* s)
49 fprintf(s,"MESSAGE MsgRequest\n");
50 fprintf(s,"command: ");
51 switch(command)
53 case MOTECOMMAND_PROGRAM:
54 fprintf(s,"MOTECOMMAND_PROGRAM\n");
55 fprintf(s,"flashImage: ");
56 flashImage.print(s);
57 break;
58 case MOTECOMMAND_STATUS:
59 fprintf(s,"MOTECOMMAND_STATUS\n");
60 break;
61 case MOTECOMMAND_RESET:
62 fprintf(s,"MOTECOMMAND_RESET\n");
63 break;
64 case MOTECOMMAND_STOP:
65 fprintf(s,"MOTECOMMAND_STOP\n");
66 break;
67 case MOTECOMMAND_START:
68 fprintf(s,"MOTECOMMAND_START\n");
69 break;
70 case MOTECOMMAND_CANCELPROGRAMMING:
71 fprintf(s,"MOTECOMMAND_CANCELPROGRAMMING\n");
72 break;
73 default:
74 fprintf(s,"Invalid command!\n");
75 break;
79 uint8_t* MsgRequest::read(uint8_t* buffer, uint32_t& buflen)
81 buffer = readvalue(command,buffer,buflen);
82 if (command == MOTECOMMAND_PROGRAM)
84 buffer = flashImage.read(buffer,buflen);
86 return buffer;
89 uint8_t MsgRequest::getCommand()
91 return command;
94 MsgPayload& MsgRequest::getFlashImage()
96 if ( command != MOTECOMMAND_PROGRAM )
97 __THROW__ ("Cannot get flash image when command is not MOTE_PROGRAM!");
98 return flashImage;