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
)
21 flashImage
= o
.flashImage
;
24 uint32_t MsgRequest::getLength()
26 uint32_t length
= sizeof(command
);
29 if (command
== MOTECOMMAND_PROGRAM
)
31 length
+= flashImage
.getLength();
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
);
46 void MsgRequest::print(FILE* s
)
48 fprintf(s
,"MESSAGE MsgRequest\n");
49 fprintf(s
,"command: ");
52 case MOTECOMMAND_PROGRAM
:
53 fprintf(s
,"MOTECOMMAND_PROGRAM\n");
54 fprintf(s
,"flashImage: ");
57 case MOTECOMMAND_STATUS
:
58 fprintf(s
,"MOTECOMMAND_STATUS\n");
60 case MOTECOMMAND_RESET
:
61 fprintf(s
,"MOTECOMMAND_RESET\n");
63 case MOTECOMMAND_STOP
:
64 fprintf(s
,"MOTECOMMAND_STOP\n");
66 case MOTECOMMAND_START
:
67 fprintf(s
,"MOTECOMMAND_START\n");
69 case MOTECOMMAND_CANCELPROGRAMMING
:
70 fprintf(s
,"MOTECOMMAND_CANCELPROGRAMMING\n");
73 fprintf(s
,"Invalid command!\n");
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
);
88 uint8_t MsgRequest::getCommand()
93 MsgPayload
& MsgRequest::getFlashImage()
95 if ( command
!= MOTECOMMAND_PROGRAM
)
96 __THROW__ ("Cannot get flash image when command is not MOTE_PROGRAM!");