Skip to content

Commit

Permalink
execute sleep only if we have the delay value greater than zero
Browse files Browse the repository at this point in the history
Signed-off-by: Jeeva Kandasamy <[email protected]>
  • Loading branch information
jkandasa committed Oct 27, 2023
1 parent 7dcaf7b commit a6f8d19
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion plugin/device/ethernet/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion plugin/device/mqtt/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion plugin/device/serial/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a6f8d19

Please sign in to comment.