1 #include "MsgRequest.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
)
22 flashImage
= o
.flashImage
;
25 uint32_t MsgRequest::getLength()
27 uint32_t length
= sizeof(command
);
30 if (command
== MOTECOMMAND_PROGRAM
)
32 length
+= flashImage
.getLength();
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
);
47 void MsgRequest::print(_IO_FILE
* s
)
49 fprintf(s
,"MESSAGE MsgRequest\n");
50 fprintf(s
,"command: ");
53 case MOTECOMMAND_PROGRAM
:
54 fprintf(s
,"MOTECOMMAND_PROGRAM\n");
55 fprintf(s
,"flashImage: ");
58 case MOTECOMMAND_STATUS
:
59 fprintf(s
,"MOTECOMMAND_STATUS\n");
61 case MOTECOMMAND_RESET
:
62 fprintf(s
,"MOTECOMMAND_RESET\n");
64 case MOTECOMMAND_STOP
:
65 fprintf(s
,"MOTECOMMAND_STOP\n");
67 case MOTECOMMAND_START
:
68 fprintf(s
,"MOTECOMMAND_START\n");
70 case MOTECOMMAND_CANCELPROGRAMMING
:
71 fprintf(s
,"MOTECOMMAND_CANCELPROGRAMMING\n");
74 fprintf(s
,"Invalid command!\n");
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
);
89 uint8_t MsgRequest::getCommand()
94 MsgPayload
& MsgRequest::getFlashImage()
96 if ( command
!= MOTECOMMAND_PROGRAM
)
97 __THROW__ ("Cannot get flash image when command is not MOTE_PROGRAM!");