@@ -87,14 +87,12 @@ func (p *Proxy) Shutdown(timeout time.Duration) error {
8787
8888// HandleRequest implements modbus.Handler interface.
8989func (p * Proxy ) HandleRequest (ctx context.Context , req * modbus.Request ) ([]byte , error ) {
90- start := time .Now ()
91-
9290 if modbus .IsWriteFunction (req .FunctionCode ) {
93- return p .handleWrite (ctx , req , start )
91+ return p .handleWrite (ctx , req )
9492 }
9593
9694 if modbus .IsReadFunction (req .FunctionCode ) {
97- return p .handleRead (ctx , req , start )
95+ return p .handleRead (ctx , req )
9896 }
9997
10098 // Unknown function code
@@ -105,7 +103,7 @@ func (p *Proxy) HandleRequest(ctx context.Context, req *modbus.Request) ([]byte,
105103 return modbus .BuildExceptionResponse (req .FunctionCode , modbus .ExcIllegalFunction ), nil
106104}
107105
108- func (p * Proxy ) handleRead (ctx context.Context , req * modbus.Request , start time. Time ) ([]byte , error ) {
106+ func (p * Proxy ) handleRead (ctx context.Context , req * modbus.Request ) ([]byte , error ) {
109107 key := cache .Key (req .SlaveID , req .FunctionCode , req .Address , req .Quantity )
110108
111109 // Use GetOrFetch for request coalescing
@@ -117,20 +115,7 @@ func (p *Proxy) handleRead(ctx context.Context, req *modbus.Request, start time.
117115 "qty" , req .Quantity ,
118116 )
119117
120- resp , err := p .client .Execute (ctx , req )
121- if err != nil {
122- return nil , err
123- }
124-
125- p .logger .Debug ("upstream read" ,
126- "slave_id" , req .SlaveID ,
127- "func" , fmt .Sprintf ("0x%02X" , req .FunctionCode ),
128- "addr" , req .Address ,
129- "qty" , req .Quantity ,
130- "duration" , time .Since (start ),
131- )
132-
133- return resp , nil
118+ return p .client .Execute (ctx , req )
134119 })
135120
136121 if err != nil {
@@ -159,7 +144,7 @@ func (p *Proxy) handleRead(ctx context.Context, req *modbus.Request, start time.
159144 return data , nil
160145}
161146
162- func (p * Proxy ) handleWrite (ctx context.Context , req * modbus.Request , start time. Time ) ([]byte , error ) {
147+ func (p * Proxy ) handleWrite (ctx context.Context , req * modbus.Request ) ([]byte , error ) {
163148 switch p .cfg .ReadOnly {
164149 case config .ReadOnlyOn :
165150 // Silently ignore, return success response
@@ -186,14 +171,6 @@ func (p *Proxy) handleWrite(ctx context.Context, req *modbus.Request, start time
186171 return nil , err
187172 }
188173
189- p .logger .Debug ("upstream write" ,
190- "slave_id" , req .SlaveID ,
191- "func" , fmt .Sprintf ("0x%02X" , req .FunctionCode ),
192- "addr" , req .Address ,
193- "qty" , req .Quantity ,
194- "duration" , time .Since (start ),
195- )
196-
197174 // Invalidate exact matching cache entries for all read function codes
198175 p .invalidateCache (req )
199176
0 commit comments