{"record":{"id":"70a79265ba2a364b","repo":"embassy-rs/embassy","slug":"invalid-transmission-power-value","errorCode":null,"errorMessage":"Invalid transmission power value","messagePattern":"Invalid transmission power value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-nrf/src/radio/ieee802154.rs","lineNumber":198,"sourceCode":"            -1 => TxPower::Neg1dBm,\n            #[cfg(feature = \"_nrf5340-net\")]\n            -2 => TxPower::Neg2dBm,\n            #[cfg(feature = \"_nrf5340-net\")]\n            -3 => TxPower::Neg3dBm,\n            -4 => TxPower::Neg4dBm,\n            #[cfg(feature = \"_nrf5340-net\")]\n            -5 => TxPower::Neg5dBm,\n            #[cfg(feature = \"_nrf5340-net\")]\n            -6 => TxPower::Neg6dBm,\n            #[cfg(feature = \"_nrf5340-net\")]\n            -7 => TxPower::Neg7dBm,\n            -8 => TxPower::Neg8dBm,\n            -12 => TxPower::Neg12dBm,\n            -16 => TxPower::Neg16dBm,\n            -20 => TxPower::Neg20dBm,\n            -30 => TxPower::Neg30dBm,\n            -40 => TxPower::Neg40dBm,\n            _ => panic!(\"Invalid transmission power value\"),\n        };\n\n        r.txpower().write(|w| w.set_txpower(tx_power));\n    }\n\n    /// Waits until the radio state matches the given `state`\n    fn wait_for_radio_state(&self, state: RadioState) {\n        while self.state() != state {}\n    }\n\n    /// Get the current radio state\n    fn state(&self) -> RadioState {\n        self.r.state().read().state()\n    }\n\n    /// Moves the radio from any state to the DISABLED state\n    fn disable(&mut self) {\n        let r = self.r;","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-nrf/src/radio/ieee802154.rs#L180-L216","documentation":"set_transmission_power panics when the requested dBm value is not one of the discrete power levels supported by the nRF radio: +8, +4, 0, -4, -8, -12, -16, -20, -30, or -40 dBm. The hardware has a fixed enum of TX power settings, so arbitrary intermediate values cannot be encoded.","triggerScenarios":"Calling ieee802154::Radio::set_transmission_power with any value other than the supported levels — e.g. set_transmission_power(-3), set_transmission_power(5), or a computed/config value like power = -2*iB.","commonSituations":"Porting drivers from radios with continuous or different power steps; computing power dynamically from link-quality feedback without snapping to a supported level; config files written in different units (e.g. -3 dBm) instead of the supported steps.","solutions":["Snap the requested power to the nearest supported level: [+8, +4, 0, -4, -8, -12, -16, -20, -30, -40] dBm.","Write a helper that maps any i8 to the closest valid level before calling set_transmission_power.","Validate config values at startup against the supported list rather than passing them through."],"exampleFix":"// before\nradio.set_transmission_power(power_dbm); // e.g. -3, panics\n// after\nconst LEVELS: [i8; 10] = [8, 4, 0, -4, -8, -12, -16, -20, -30, -40];\nlet snapped = *LEVELS.iter().min_by_key(|l| (l - power_dbm).abs()).unwrap();\nradio.set_transmission_power(snapped);","handlingStrategy":"validation","validationCode":"const TX_LEVELS: [i8; 10] = [8, 4, 0, -4, -8, -12, -16, -20, -30, -40];\nassert!(TX_LEVELS.contains(&power_dbm), \"unsupported TX power {}\", power_dbm);\nradio.set_transmission_power(power_dbm);","typeGuard":"fn is_supported_tx_power(dbm: i8) -> bool {\n    matches!(dbm, 8 | 4 | 0 | -4 | -8 | -12 | -16 | -20 | -30 | -40)\n}","tryCatchPattern":null,"preventionTips":["Snap arbitrary dBm values to the nearest supported level before calling.","Store TX power as a constants enum, not a free i8.","Convert config units carefully; only the listed steps are hardware-representable."],"tags":["embedded","nrf","radio","ieee802154","enum-value","panic"],"backgroundTag":"invalid-enum-value","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}