----------------------------------------------------------------------------- Fill in the length and checksum values for the message -----------------------------------------------------------------------------
| 157 | // Fill in the length and checksum values for the message |
| 158 | //----------------------------------------------------------------------------- |
| 159 | void 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 | //----------------------------------------------------------------------------- |