mqtt_mux: profile independent output

This commit is contained in:
occheung 2020-09-30 16:43:39 +08:00
parent f8ccb66077
commit 41d3df26f2
1 changed files with 6 additions and 18 deletions

View File

@ -246,11 +246,11 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
MqttCommand::SingletoneAmplitude(ch, pr, _) | MqttCommand::SingletoneAmplitude(ch, pr, _) |
MqttCommand::SingletonePhase(ch, pr, _) => { MqttCommand::SingletonePhase(ch, pr, _) => {
let (f_out, phase, ampl) = self.urukul.get_channel_single_tone_profile(ch, pr)?; let (f_out, phase, ampl) = self.urukul.get_channel_single_tone_profile(ch, pr)?;
vec.push(self.get_single_tone_frequency_message(ch, pr, f_out)?) vec.push(self.get_single_tone_frequency_message(ch, f_out)?)
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
vec.push(self.get_single_tone_phase_message(ch, pr, phase)?) vec.push(self.get_single_tone_phase_message(ch, phase)?)
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
vec.push(self.get_single_tone_amplitude_message(ch, pr, ampl)?) vec.push(self.get_single_tone_amplitude_message(ch, ampl)?)
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
Ok(vec) Ok(vec)
} }
@ -556,7 +556,7 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
)) ))
} }
fn get_single_tone_frequency_message(&mut self, ch: u8, pr: u8, f_out: f64) -> Result<(String<U128>, String<U64>), Error<E>> { fn get_single_tone_frequency_message(&mut self, ch: u8, f_out: f64) -> Result<(String<U128>, String<U64>), Error<E>> {
Ok(( Ok((
{ {
let mut topic_string = String::from(self.name); let mut topic_string = String::from(self.name);
@ -564,10 +564,6 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string.push(char::from_digit(ch.into(), 10).unwrap()) topic_string.push(char::from_digit(ch.into(), 10).unwrap())
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string.push_str("/Profile")
.map_err(|_| Error::StringOutOfSpace)?;
topic_string.push(char::from_digit(pr.into(), 10).unwrap())
.map_err(|_| Error::StringOutOfSpace)?;
topic_string.push_str("/Singletone/Frequency") topic_string.push_str("/Singletone/Frequency")
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string topic_string
@ -583,7 +579,7 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
)) ))
} }
fn get_single_tone_amplitude_message(&mut self, ch: u8, pr: u8, ampl: f64) -> Result<(String<U128>, String<U64>), Error<E>> { fn get_single_tone_amplitude_message(&mut self, ch: u8, ampl: f64) -> Result<(String<U128>, String<U64>), Error<E>> {
Ok(( Ok((
{ {
let mut topic_string = String::from(self.name); let mut topic_string = String::from(self.name);
@ -591,10 +587,6 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string.push(char::from_digit(ch.into(), 10).unwrap()) topic_string.push(char::from_digit(ch.into(), 10).unwrap())
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string.push_str("/Profile")
.map_err(|_| Error::StringOutOfSpace)?;
topic_string.push(char::from_digit(pr.into(), 10).unwrap())
.map_err(|_| Error::StringOutOfSpace)?;
topic_string.push_str("/Singletone/Amplitude") topic_string.push_str("/Singletone/Amplitude")
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string topic_string
@ -608,7 +600,7 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
)) ))
} }
fn get_single_tone_phase_message(&mut self, ch: u8, pr: u8, phase: f64) -> Result<(String<U128>, String<U64>), Error<E>> { fn get_single_tone_phase_message(&mut self, ch: u8, phase: f64) -> Result<(String<U128>, String<U64>), Error<E>> {
Ok(( Ok((
{ {
let mut topic_string = String::from(self.name); let mut topic_string = String::from(self.name);
@ -616,10 +608,6 @@ impl<'s, SPI, E> MqttMux<'s, SPI> where SPI: Transfer<u8, Error = E> {
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string.push(char::from_digit(ch.into(), 10).unwrap()) topic_string.push(char::from_digit(ch.into(), 10).unwrap())
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string.push_str("/Profile")
.map_err(|_| Error::StringOutOfSpace)?;
topic_string.push(char::from_digit(pr.into(), 10).unwrap())
.map_err(|_| Error::StringOutOfSpace)?;
topic_string.push_str("/Singletone/Phase") topic_string.push_str("/Singletone/Phase")
.map_err(|_| Error::StringOutOfSpace)?; .map_err(|_| Error::StringOutOfSpace)?;
topic_string topic_string