MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / Finalize

Method Finalize

cpp/src/Msg.cpp:159–202  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Fill in the length and checksum values for the message -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

157// Fill in the length and checksum values for the message
158//-----------------------------------------------------------------------------
159void Msg::Finalize()
160{
161 if( m_bFinal )
162 {
163 // Already finalized
164 return;
165 }
166
167 // Deal with Multi-Channel/Instance encapsulation
168 if( ( m_flags & ( m_MultiChannel | m_MultiInstance ) ) != 0 )
169 {
170 MultiEncap();
171 }
172
173 // Add the callback id
174 if( m_bCallbackRequired )
175 {
176 // Set the length byte
177 m_buffer[1] = m_length; // Length of following data
178
179 if( 0 == s_nextCallbackId )
180 {
181 s_nextCallbackId = 10;
182 }
183
184 m_buffer[m_length++] = s_nextCallbackId;
185 m_callbackId = s_nextCallbackId++;
186 }
187 else
188 {
189 // Set the length byte
190 m_buffer[1] = m_length - 1; // Length of following data
191 }
192
193 // Calculate the checksum
194 uint8 checksum = 0xff;
195 for( uint32 i=1; i<m_length; ++i )
196 {
197 checksum ^= m_buffer[i];
198 }
199 m_buffer[m_length++] = checksum;
200
201 m_bFinal = true;
202}
203
204
205//-----------------------------------------------------------------------------

Callers 1

SendMsgMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected