| 1691 | |
| 1692 | impl ChannelSettingsRelay { |
| 1693 | pub fn to_bytes(&self) -> Result<[u8; 2]> { |
| 1694 | if self.start_stop > 1 { |
| 1695 | return Err(anyhow!("max value of start_stop is 1")); |
| 1696 | } |
| 1697 | if self.cad_periodicity > 7 { |
| 1698 | return Err(anyhow!("max value of cad_periodicity is 7")); |
| 1699 | } |
| 1700 | if self.default_ch_idx > 1 { |
| 1701 | return Err(anyhow!("max value of default_ch_idx is 1")); |
| 1702 | } |
| 1703 | if self.second_ch_idx > 1 { |
| 1704 | return Err(anyhow!("max value of second_ch_idx is 1")); |
| 1705 | } |
| 1706 | if self.second_ch_dr > 15 { |
| 1707 | return Err(anyhow!("max value of second_ch_dr is 15")); |
| 1708 | } |
| 1709 | if self.second_ch_ack_offset > 7 { |
| 1710 | return Err(anyhow!("max value of second_ch_ack_offset is 7")); |
| 1711 | } |
| 1712 | |
| 1713 | Ok([ |
| 1714 | self.second_ch_ack_offset | (self.second_ch_dr << 3) | (self.second_ch_idx << 7), |
| 1715 | (self.second_ch_idx >> 1) |
| 1716 | | (self.default_ch_idx << 1) |
| 1717 | | (self.cad_periodicity << 2) |
| 1718 | | (self.start_stop << 5), |
| 1719 | ]) |
| 1720 | } |
| 1721 | |
| 1722 | pub fn from_bytes(b: [u8; 2]) -> Self { |
| 1723 | ChannelSettingsRelay { |