1 #include "MsgClientRequest.h"
3 namespace remote
{ namespace protocols
{ namespace client_server
{
5 MsgClientRequest::MsgClientRequest(uint8_t command
)
6 : command(command
), msgMoteIdList(), moteMsg()
10 MsgClientRequest::MsgClientRequest(uint8_t*& buffer
, uint32_t& buflen
) : msgMoteIdList(), moteMsg()
12 buffer
= this->read(buffer
,buflen
);
15 uint32_t MsgClientRequest::getLength()
17 uint32_t length
= sizeof(command
);
18 length
+= msgMoteIdList
.getLength();
21 case MSGCLIENTCOMMAND_MOTEMESSAGE
:
22 length
+= moteMsg
.getLength();
24 case MSGCLIENTCOMMAND_GETMOTECONTROL
:
25 case MSGCLIENTCOMMAND_DROPMOTECONTROL
:
28 __THROW__ ("Invalid command");
34 uint8_t* MsgClientRequest::write(uint8_t* buffer
, uint32_t& buflen
)
36 buffer
= writevalue(command
,buffer
,buflen
);
37 buffer
= msgMoteIdList
.write(buffer
,buflen
);
40 case MSGCLIENTCOMMAND_MOTEMESSAGE
:
41 buffer
= moteMsg
.write(buffer
,buflen
);
43 case MSGCLIENTCOMMAND_GETMOTECONTROL
:
44 case MSGCLIENTCOMMAND_DROPMOTECONTROL
:
47 __THROW__ ("Invalid command");
53 uint8_t* MsgClientRequest::read(uint8_t* buffer
, uint32_t& buflen
)
55 buffer
= readvalue(command
,buffer
,buflen
);
56 buffer
= msgMoteIdList
.read(buffer
,buflen
);
59 case MSGCLIENTCOMMAND_MOTEMESSAGE
:
60 buffer
= moteMsg
.read(buffer
,buflen
);
62 case MSGCLIENTCOMMAND_GETMOTECONTROL
:
64 case MSGCLIENTCOMMAND_DROPMOTECONTROL
:
67 __THROW__ ("Invalid command");
73 void MsgClientRequest::print(FILE* s
)
75 fprintf(s
,"MESSAGE MsgServerRequest\n");
76 fprintf(s
,"command: ");
79 case MSGCLIENTCOMMAND_MOTEMESSAGE
:
80 fprintf(s
,"MSGSERVERCOMMAND_MOTEMESSAGE\n");
83 case MSGCLIENTCOMMAND_GETMOTECONTROL
:
84 fprintf(s
,"MSGSERVERCOMMAND_GETMOTECONTROL\n");
86 case MSGCLIENTCOMMAND_DROPMOTECONTROL
:
87 fprintf(s
,"MSGSERVERCOMMAND_DROPMOTECONTROL\n");
90 __THROW__ ("Invalid command");
93 msgMoteIdList
.print(s
);
96 uint8_t MsgClientRequest::getCommand()
101 MsgMoteIdList
& MsgClientRequest::getMoteIdList()
103 if ( command
!= MSGCLIENTCOMMAND_GETMOTECONTROL
104 && command
!= MSGCLIENTCOMMAND_DROPMOTECONTROL
105 && command
!= MSGCLIENTCOMMAND_MOTEMESSAGE
)
106 __THROW__ ("Cannot getMoteIdList when command is not set correctly.");
107 return msgMoteIdList
;
110 MsgPayload
& MsgClientRequest::getMoteMsg()
112 if (command
!= MSGCLIENTCOMMAND_MOTEMESSAGE
)
113 __THROW__ ("Cannot get motemsg when type is not MSGSERVERCOMMAND_MOTEMESSAGE!");