From 6c01508457ac1a75c5b7683626a456df99b4c747 Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Fri, 9 Sep 2022 16:38:24 +1000 Subject: [PATCH] Fix test --- modbus-mqtt/src/modbus/register.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modbus-mqtt/src/modbus/register.rs b/modbus-mqtt/src/modbus/register.rs index c53b5b5..b50d005 100644 --- a/modbus-mqtt/src/modbus/register.rs +++ b/modbus-mqtt/src/modbus/register.rs @@ -49,9 +49,7 @@ impl Monitor { .await .unwrap(); - let value = self - .register - .parse_words(&self.register.apply_swaps(&words)); + let value = self.register.parse_words(&words); self.mqtt .publish("state", serde_json::to_vec(&value).unwrap()) @@ -504,10 +502,10 @@ impl Register { } pub fn parse_words(&self, words: &[u16]) -> serde_json::Value { - self.parse.value_type.parse_words(words) + self.parse.value_type.parse_words(&self.apply_swaps(words)) } - pub fn apply_swaps(&self, words: &[u16]) -> Vec { + fn apply_swaps(&self, words: &[u16]) -> Vec { let words: Vec = if self.parse.swap_bytes.0 { words.iter().map(|v| v.swap_bytes()).collect() } else { @@ -532,14 +530,14 @@ use crate::mqtt::{self, Payload}; fn test_parse_1() { use serde_json::json; - Register { + let reg = Register { name: None, interval: Default::default(), parse: RegisterParse { swap_bytes: Swap(false), - swap_words: Swap(false), + swap_words: Swap(true), value_type: RegisterValueType::Numeric { - of: RegisterNumeric::I32, + of: RegisterNumeric::U32, adjust: RegisterNumericAdjustment { scale: 0, offset: 0,