+
+ pub fn set_destination(&mut self, destination: &Address) {
+ self.0[0..6].copy_from_slice(&encode_address(&destination));
+ self.recalculate_crc();
+ }
+
+ pub fn set_source(&mut self, source: &Address) {
+ self.0[6..12].copy_from_slice(&encode_address(&source));
+ self.recalculate_crc();
+ }
+
+ pub fn set_mode(&mut self, mode: Mode) {
+ let existing_type = self.lsf_type();
+ let new_type = (existing_type & !0x0001) | if mode == Mode::Stream { 1 } else { 0 };
+ self.0[12..14].copy_from_slice(&new_type.to_be_bytes());
+ self.recalculate_crc();
+ }
+
+ pub fn set_data_type(&mut self, data_type: DataType) {
+ let type_part = match data_type {
+ DataType::Reserved => 0b00 << 1,
+ DataType::Data => 0b01 << 1,
+ DataType::Voice => 0b10 << 1,
+ DataType::VoiceAndData => 0b11 << 1,
+ };
+ let existing_type = self.lsf_type();
+ let new_type = (existing_type & !0x0006) | type_part;
+ self.0[12..14].copy_from_slice(&new_type.to_be_bytes());
+ self.recalculate_crc();
+ }
+
+ pub fn set_encryption_type(&mut self, encryption_type: EncryptionType) {
+ let type_part = match encryption_type {
+ EncryptionType::None => 0b00 << 3,
+ EncryptionType::Scrambler => 0b01 << 3,
+ EncryptionType::Aes => 0b10 << 3,
+ EncryptionType::Other => 0b11 << 3,
+ };
+ let existing_type = self.lsf_type();
+ let new_type = (existing_type & !0x0018) | type_part;
+ self.0[12..14].copy_from_slice(&new_type.to_be_bytes());
+ self.recalculate_crc();
+ }
+
+ fn recalculate_crc(&mut self) {
+ let new_crc = crate::crc::m17_crc(&self.0[0..28]);
+ self.0[28..30].copy_from_slice(&new_crc.to_be_bytes());
+ debug_assert_eq!(self.check_crc(), 0);
+ }
+
+ fn lsf_type(&self) -> u16 {
+ u16::from_be_bytes([self.0[12], self.0[13]])
+ }