mqtt_mux: fixed singletone parameter bug

This commit is contained in:
occheung 2020-09-23 10:41:54 +08:00
parent 39969e602c
commit f1376cab07
1 changed files with 8 additions and 27 deletions

View File

@ -70,35 +70,13 @@ impl<SPI, E> MqttMux<SPI> where SPI: Transfer<u8, Error = E> {
pub fn process_mqtt(&mut self, topic: &str, message: &[u8]) -> Result<(), Error<E>> {
let header = self.parse_topic(topic)
.map_err(|_| Error::MqttTopicError)?;
info!("{:?}", header);
info!("Parsed command topic: {:?}", header);
let (_, command) = self.parse_message(header, message)
.map_err(|_| Error::MqttCommandError)?;
info!("{:?}", command);
info!("Parsed comamnd message: {:?}", command);
self.execute(command)
}
/*
fn parse_header<'a>(&mut self, topic: &'a str) -> IResult<&'a str, MqttTopic> {
preceded(
alt((
tag("Urukul/Control/"),
tag("/Urukul/Control/")
)),
alt((
switch,
attenuation,
clock,
clock_source,
clock_frequency,
clock_division,
singletone,
singletone_frequency,
singletone_amplitude,
singletone_phase,
profile
))
)(topic)
}
*/
fn parse_topic<'a>(&mut self, topic: &'a str) -> Result<MqttTopic, Error<E>> {
let mut assigned_channel = false;
let mut assigned_profile = false;
@ -423,6 +401,8 @@ fn clock_division_message(message: &[u8]) -> IResult<&[u8], MqttCommand> {
}
// Parser for one-command master clock setup message
// Possible improvements: Chop off redundant braces and quotes
// Allow optional parameters/permutation of parameters
fn clock_message(message: &[u8]) -> IResult<&[u8], MqttCommand> {
all_consuming(
map(
@ -533,7 +513,8 @@ fn singletone_phase_message(channel: u8, profile: u8, message: &[u8]) -> IResult
// Parser for one-command singletone profile Command
// Using JSON like command structure
// Possible enhancement: further modularize parsing of all separate fields
// Possible improvements: Chop off redundant braces and quotes
// Allow optional parameters/permutation of parameters
fn singletone_message(channel: u8, profile: u8, message: &[u8]) -> IResult<&[u8], MqttCommand> {
all_consuming(
map(
@ -592,7 +573,7 @@ fn singletone_message(channel: u8, profile: u8, message: &[u8]) -> IResult<&[u8]
)
)
)),
|(freq, ampl, phase): (f64, f64, f64)| MqttCommand::Singletone(channel, profile, freq, ampl, phase)
|(freq, ampl, phase): (f64, f64, f64)| MqttCommand::Singletone(channel, profile, freq, phase, ampl)
)
)(message)
}