From a6f8d19fe03671779524ce1cc95000d27cbb6c2d Mon Sep 17 00:00:00 2001 From: Jeeva Kandasamy Date: Fri, 27 Oct 2023 14:57:24 +0530 Subject: [PATCH] execute sleep only if we have the delay value greater than zero Signed-off-by: Jeeva Kandasamy --- plugin/device/ethernet/device.go | 6 +++++- plugin/device/mqtt/device.go | 4 +++- plugin/device/serial/device.go | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugin/device/ethernet/device.go b/plugin/device/ethernet/device.go index 689bf6a..9544fe9 100644 --- a/plugin/device/ethernet/device.go +++ b/plugin/device/ethernet/device.go @@ -91,7 +91,11 @@ func (ep *Endpoint) Write(message *types.Message) error { if message == nil || len(message.Data) == 0 { return nil } - time.Sleep(ep.txPreDelay) // transmit pre delay + + if ep.txPreDelay > 0 { + time.Sleep(ep.txPreDelay) // transmit pre delay + } + _, err := ep.conn.Write(append(message.Data, *ep.Config.MessageSplitter)) return err } diff --git a/plugin/device/mqtt/device.go b/plugin/device/mqtt/device.go index 5d096b6..f0e93a1 100644 --- a/plugin/device/mqtt/device.go +++ b/plugin/device/mqtt/device.go @@ -135,7 +135,9 @@ func (ep *Endpoint) Write(message *model.Message) error { topic := message.Others.GetString(model.KeyMqttTopic) qos := byte(ep.Config.QoS) - time.Sleep(ep.txPreDelay) // transmit pre delay + if ep.txPreDelay > 0 { + time.Sleep(ep.txPreDelay) // transmit pre delay + } for _, rawtopic := range strings.Split(ep.Config.Publish, ",") { _topic := strings.TrimSpace(rawtopic) diff --git a/plugin/device/serial/device.go b/plugin/device/serial/device.go index 00f1bab..2bff835 100644 --- a/plugin/device/serial/device.go +++ b/plugin/device/serial/device.go @@ -90,7 +90,10 @@ func (ep *Endpoint) Write(message *types.Message) error { if message == nil && len(message.Data) > 0 { return nil } - time.Sleep(ep.txPreDelay) // transmit pre delay + + if ep.txPreDelay > 0 { + time.Sleep(ep.txPreDelay) // transmit pre delay + } _, err := ep.Port.Write(append(message.Data, *ep.Config.MessageSplitter)) if err != nil { ep.statusFunc(&types.State{