Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RDMCommandSerializer.h
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * RDMCommandSerializer.h
17  * Write RDMCommands to a memory buffer.
18  * Copyright (C) 2012 Simon Newton
19  */
20 
29 #ifndef INCLUDE_OLA_RDM_RDMCOMMANDSERIALIZER_H_
30 #define INCLUDE_OLA_RDM_RDMCOMMANDSERIALIZER_H_
31 
32 #include <stdint.h>
33 #include <ola/io/IOStack.h>
34 #include <ola/rdm/RDMCommand.h>
35 #include <ola/rdm/UID.h>
36 
37 namespace ola {
38 namespace rdm {
39 
40 
41 /*
42  * Serializes a RDMCommand to a memory buffer. This restricts the serialized
43  * command to 231 bytes of paramater data. If the message is more than 231
44  * bytes then Pack will return false.
45  */
47  public:
48  static unsigned int RequiredSize(const RDMCommand &command);
49 
50  static bool Pack(const RDMCommand &command,
51  uint8_t *buffer,
52  unsigned int *size);
53  static bool Pack(const RDMRequest &request,
54  uint8_t *buffer,
55  unsigned int *size,
56  const UID &source,
57  uint8_t transaction_number,
58  uint8_t port_id);
59 
60  // TODO(simon): Add IOQueue Write() methods here
61 
62  // Similar to above but we write the output to an IOStack
63  static bool Write(const RDMCommand &command,
64  ola::io::IOStack *stack);
65  static bool Write(const RDMRequest &request,
66  ola::io::IOStack *stack,
67  const UID &source,
68  uint8_t transaction_number,
69  uint8_t port_id);
70 
71  enum { MAX_PARAM_DATA_LENGTH = 231 };
72 
73  private:
74  static const unsigned int CHECKSUM_LENGTH = 2;
75 
76  static bool PackWithParams(const RDMCommand &command,
77  uint8_t *buffer,
78  unsigned int *size,
79  const UID &source,
80  uint8_t transaction_number,
81  uint8_t port_id);
82 
83  static bool WriteToStack(const RDMCommand &command,
84  ola::io::IOStack *stack,
85  const UID &source,
86  uint8_t transaction_number,
87  uint8_t port_id);
88 
89  static void PopulateHeader(RDMCommandHeader *header,
90  const RDMCommand &command,
91  unsigned int packet_length,
92  const UID &source,
93  uint8_t transaction_number,
94  uint8_t port_id);
95 };
96 } // namespace rdm
97 } // namespace ola
98 #endif // INCLUDE_OLA_RDM_RDMCOMMANDSERIALIZER_H_