forked from milanbella/gocosem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
745 lines (609 loc) · 19.4 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
package gocosem
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"time"
)
var ErrorRequestTimeout = errors.New("request timeout")
var ErrorBlockTimeout = errors.New("block receive timeout")
type DlmsRequest struct {
ClassId DlmsClassId
InstanceId *DlmsOid
AttributeId DlmsAttributeId // If > 0 then GetRequest or SetRequest is sent. SetRequest is sent if 'Data' is non nil otherwise GetRequest is sent.
MethodId DlmsMethodId // If > 0 then ActionRequest is sent.
AccessSelector DlmsAccessSelector
AccessParameter *DlmsData
Data *DlmsData // Data to be sent with SetRequest. If non-nil and 'AttributeId' > 0 then SetRequest is sent.
MethodParameters *DlmsData // Optional method invokation parameters used with ActionRequest.
BlockSize int // If > 0 then data sent with SetReuqest are sent in bolocks.
rawData []byte // Remaining data to be sent using block transfer.
blockNumber uint32 // Number of last block sent.
}
type DlmsResponse struct {
DataAccessResult DlmsDataAccessResult
ActionResult DlmsActionResult
Data *DlmsData
}
type DlmsRequestResponse struct {
Req *DlmsRequest
Rep *DlmsResponse
RequestSubmittedAt time.Time
ReplyDeliveredAt time.Time
highPriority bool
rawData []byte
}
type DlmsAppLevelSendRequest struct {
ch chan *DlmsMessage // reply channel
invokeId uint8
rips []*DlmsRequestResponse
pdu []byte
}
type DlmsAppLevelReceiveRequest struct {
ch chan *DlmsMessage // reply channel
}
type AppConn struct {
dconn *DlmsConn
applicationClient uint16
logicalDevice uint16
invokeId uint8
}
type DlmsResultResponse []*DlmsRequestResponse
func (rep DlmsResultResponse) RequestAt(i int) (req *DlmsRequest) {
return rep[i].Req
}
func (rep DlmsResultResponse) DataAt(i int) *DlmsData {
return rep[i].Rep.Data
}
func (rep DlmsResultResponse) DataAccessResultAt(i int) DlmsDataAccessResult {
return rep[i].Rep.DataAccessResult
}
func (rep DlmsResultResponse) ActionResultAt(i int) DlmsActionResult {
return rep[i].Rep.ActionResult
}
func (rep DlmsResultResponse) DeliveredIn() time.Duration {
return rep[0].ReplyDeliveredAt.Sub(rep[0].RequestSubmittedAt)
}
func NewAppConn(dconn *DlmsConn, applicationClient uint16, logicalDevice uint16, invokeId uint8) (aconn *AppConn) {
aconn = new(AppConn)
aconn.dconn = dconn
aconn.applicationClient = applicationClient
aconn.logicalDevice = logicalDevice
aconn.invokeId = invokeId
return aconn
}
func (aconn *AppConn) Close() {
debugLog("closing application connection ...")
if !aconn.dconn.closed {
aconn.dconn.Close()
}
debugLog("application connection closed")
}
func (aconn *AppConn) processGetResponseNormal(rips []*DlmsRequestResponse, r io.Reader, errr error) error {
err, dataAccessResult, data := decode_GetResponseNormal(r)
rips[0].Rep = new(DlmsResponse)
rips[0].Rep.DataAccessResult = dataAccessResult
rips[0].Rep.Data = data
if nil == err {
return nil
} else {
if nil != errr {
return errr
} else {
return err
}
}
}
func (aconn *AppConn) processGetResponseNormalBlock(rips []*DlmsRequestResponse, r io.Reader, errr error) error {
err, data := decode_GetResponseNormalBlock(r)
rips[0].Rep = new(DlmsResponse)
rips[0].Rep.DataAccessResult = dataAccessResult_success
rips[0].Rep.Data = data
if nil == err {
return nil
} else {
if nil != errr {
return errr
} else {
return err
}
}
}
func (aconn *AppConn) processGetResponseWithList(rips []*DlmsRequestResponse, r io.Reader, errr error) error {
err, dataAccessResults, datas := decode_GetResponseWithList(r)
if len(dataAccessResults) != len(rips) {
err = fmt.Errorf("unexpected count of received list entries")
errorLog("%s", err)
if len(dataAccessResults) > len(rips) {
dataAccessResults = dataAccessResults[0:len(rips)]
}
}
for i := 0; i < len(dataAccessResults); i += 1 {
rip := rips[i]
rip.Rep = new(DlmsResponse)
rip.Rep.DataAccessResult = dataAccessResults[i]
rip.Rep.Data = datas[i]
}
if nil == err {
return nil
} else {
if nil != errr {
return errr
} else {
return err
}
}
}
func (aconn *AppConn) processBlockResponse(rips []*DlmsRequestResponse, r io.Reader, err error) error {
if 1 == len(rips) {
debugLog("blocks received, processing ResponseNormal")
return aconn.processGetResponseNormalBlock(rips, r, err)
} else {
debugLog("blocks received, processing ResponseWithList")
return aconn.processGetResponseWithList(rips, r, err)
}
}
func (aconn *AppConn) processSetResponseNormal(rips []*DlmsRequestResponse, r io.Reader, errr error) error {
err, dataAccessResult := decode_SetResponseNormal(r)
rips[0].Rep = new(DlmsResponse)
rips[0].Rep.DataAccessResult = dataAccessResult
if nil == err {
return nil
} else {
if nil != errr {
return errr
} else {
return err
}
}
}
func (aconn *AppConn) processSetResponseWithList(rips []*DlmsRequestResponse, r io.Reader, errr error) error {
err, dataAccessResults := decode_SetResponseWithList(r)
if len(dataAccessResults) != len(rips) {
err = fmt.Errorf("unexpected count of received list entries")
errorLog("%s", err)
if len(dataAccessResults) > len(rips) {
dataAccessResults = dataAccessResults[0:len(rips)]
}
}
for i := 0; i < len(dataAccessResults); i += 1 {
rip := rips[i]
rip.Rep = new(DlmsResponse)
rip.Rep.DataAccessResult = dataAccessResults[i]
}
if nil == err {
return nil
} else {
if nil != errr {
return errr
} else {
return err
}
}
}
func (aconn *AppConn) processActionResponseNormal(rips []*DlmsRequestResponse, r io.Reader, errr error) error {
err, actionResult, dataAccessResult, data := decode_ActionResponseNormal(r)
rips[0].Rep = new(DlmsResponse)
rips[0].Rep.ActionResult = actionResult
if nil != dataAccessResult {
// Method returns data (non-void method). Retuned data may stil be nil id dataAccessResult indicates error (if it is non 0).
rips[0].Rep.DataAccessResult = *dataAccessResult
rips[0].Rep.Data = data
} else {
// Method returns no data (void method). void method. Returned data is always nil.
rips[0].Rep.DataAccessResult = dataAccessResult_success
rips[0].Rep.Data = nil
}
if nil == err {
return nil
} else {
if nil != errr {
return errr
} else {
return err
}
}
}
func (aconn *AppConn) processReply(rips []*DlmsRequestResponse, p []byte, r io.Reader) error {
invokeId := uint8((p[2] & 0xF0) >> 4)
debugLog("invokeId %d\n", invokeId)
if (0xC4 == p[0]) && (0x01 == p[1]) {
debugLog("processing GetResponseNormal")
return aconn.processGetResponseNormal(rips, r, nil)
} else if (0xC4 == p[0]) && (0x03 == p[1]) {
debugLog("processing GetResponseWithList")
return aconn.processGetResponseWithList(rips, r, nil)
} else if (0xC4 == p[0]) && (0x02 == p[1]) {
// data blocks response
debugLog("processing GetResponsewithDataBlock")
err, lastBlock, blockNumber, dataAccessResult, rawData := decode_GetResponsewithDataBlock(r)
if nil != err {
return err
}
if 0 != dataAccessResult {
err = fmt.Errorf("error occured receiving response block, invokeId: %d, blockNumber: %d, dataAccessResult: %d", invokeId, blockNumber, dataAccessResult)
errorLog("%s", err)
return err
}
if nil == rips[0].rawData {
rips[0].rawData = rawData
} else {
rips[0].rawData = append(rips[0].rawData, rawData...)
}
_pdu := rips[0].rawData
if lastBlock {
return aconn.processBlockResponse(rips, bytes.NewBuffer(_pdu), nil)
} else {
// requests next data block
debugLog("requesting next data block after block %d", blockNumber)
buf := new(bytes.Buffer)
invokeIdAndPriority := p[2]
_, err := buf.Write([]byte{0xC0, 0x02, byte(invokeIdAndPriority)})
if nil != err {
return err
}
err = encode_GetRequestForNextDataBlock(buf, blockNumber)
if nil != err {
return err
}
err = aconn.dconn.transportSend(aconn.applicationClient, aconn.logicalDevice, buf.Bytes())
if nil != err {
return err
}
pdu, err := aconn.dconn.transportReceive(aconn.logicalDevice, aconn.applicationClient)
if nil != err {
return err
}
buf = bytes.NewBuffer(pdu)
p = make([]byte, 3)
err = binary.Read(buf, binary.BigEndian, p)
if nil != err {
errorLog("io.Read() failed: %v", err)
return err
}
invokeIdRcv := uint8((p[2] & 0xF0) >> 4)
if invokeIdRcv != invokeId {
err := fmt.Errorf("invoke ids differs: invokeId sent: %v, invokeId received: %v", invokeId, invokeIdRcv)
errorLog("%s", err)
return err
}
return aconn.processReply(rips, p, buf)
}
} else if (0xC5 == p[0]) && (0x01 == p[1]) {
debugLog("processing SetResponseNormal")
return aconn.processSetResponseNormal(rips, r, nil)
} else if (0xC5 == p[0]) && (0x05 == p[1]) {
debugLog("processing SetResponseWithList")
return aconn.processSetResponseWithList(rips, r, nil)
} else if (0xC5 == p[0]) && (0x02 == p[1]) {
debugLog("processing SetResponseForDataBlock")
req := rips[0].Req
err, blockNumber := decode_SetResponseForDataBlock(r)
if nil != err {
return err
}
if req.blockNumber != blockNumber {
err = fmt.Errorf("error occured receiving response block: received unexpected blockNumber: %d, invokeId: %d ", blockNumber, invokeId)
errorLog("%s", err)
return err
}
// set next block
n := req.BlockSize
if n > len(req.rawData) {
n = len(req.rawData)
}
rawData := req.rawData[0:n]
req.rawData = req.rawData[n:]
lastBlock := false
if 0 == len(req.rawData) {
lastBlock = true
}
debugLog("setting next data block (current block is %d)", blockNumber)
buf := new(bytes.Buffer)
invokeIdAndPriority := p[2]
_, err = buf.Write([]byte{0xC1, 0x03, byte(invokeIdAndPriority)})
if nil != err {
return err
}
err = encode_SetRequestWithDataBlock(buf, lastBlock, blockNumber+1, rawData)
if nil != err {
return err
}
req.blockNumber += 1
err = aconn.dconn.transportSend(aconn.applicationClient, aconn.logicalDevice, buf.Bytes())
if nil != err {
return err
}
pdu, err := aconn.dconn.transportReceive(aconn.logicalDevice, aconn.applicationClient)
if nil != err {
return err
}
buf = bytes.NewBuffer(pdu)
p = make([]byte, 3)
err = binary.Read(buf, binary.BigEndian, p)
if nil != err {
errorLog("io.Read() failed: %v", err)
aconn.Close()
return err
}
invokeIdRcv := uint8((p[2] & 0xF0) >> 4)
if invokeIdRcv != invokeId {
err := fmt.Errorf("invoke ids differs: invokeId sent: %v, invokeId received: %v", invokeId, invokeIdRcv)
errorLog("%s", err)
return err
}
return aconn.processReply(rips, p, buf)
} else if (0xC5 == p[0]) && (0x03 == p[1]) {
debugLog("processing SetResponseForLastDataBlock")
req := rips[0].Req
err, dataAccessResult, blockNumber := decode_SetResponseForLastDataBlock(r)
if nil != err {
return err
}
if req.blockNumber != blockNumber {
err = fmt.Errorf("error occured receiving response block: received unexpected blockNumber: %d, invokeId: %d ", blockNumber, invokeId)
errorLog("%s", err)
return err
}
rips[0].Rep = new(DlmsResponse)
rips[0].Rep.DataAccessResult = dataAccessResult
return nil
} else if (0xC5 == p[0]) && (0x04 == p[1]) {
debugLog("processing SetResponseForLastDataBlockWithList")
req := rips[0].Req
err, dataAccessResults, blockNumber := decode_SetResponseForLastDataBlockWithList(r)
if nil != err {
return err
}
if req.blockNumber != blockNumber {
err = fmt.Errorf("error occured receiving response block: received unexpected blockNumber: %d, invokeId: %d ", blockNumber, invokeId)
errorLog("%s", err)
return err
}
if len(rips) != len(dataAccessResults) {
err = fmt.Errorf("error occured receiving response block: received unexpected number of results: %d, expected: %d, invokeId: %d ", len(dataAccessResults), len(rips), invokeId)
errorLog("%s", err)
return err
}
for i := 0; i < len(rips); i++ {
rips[i].Rep = new(DlmsResponse)
rips[i].Rep.DataAccessResult = dataAccessResults[i]
}
return nil
} else if (0xC7 == p[0]) && (0x01 == p[1]) {
debugLog("processing ActionResponseNormal")
return aconn.processActionResponseNormal(rips, r, nil)
} else {
err := fmt.Errorf("received pdu discarded due to unknown tag: % 02X % 02X", p[0], p[1])
errorLog("%s", err)
return err
}
}
func (aconn *AppConn) SendRequest(vals []*DlmsRequest) (response DlmsResultResponse, err error) {
debugLog("enter")
highPriority := true
invokeId := aconn.invokeId
if 0 == len(vals) {
return nil, nil
}
debugLog("invokeId %d\n", invokeId)
if invokeId > 0x0F {
err := fmt.Errorf("invokeId exceeds limit")
errorLog("%s", err)
return nil, err
}
rips := make([]*DlmsRequestResponse, len(vals))
for i := 0; i < len(vals); i += 1 {
rip := new(DlmsRequestResponse)
rip.Req = vals[i]
rip.RequestSubmittedAt = time.Now()
rip.highPriority = highPriority
rips[i] = rip
}
// build and forward pdu to transport
var invokeIdAndPriority tDlmsInvokeIdAndPriority
if highPriority {
invokeIdAndPriority = tDlmsInvokeIdAndPriority((invokeId << 4) | 0x01)
} else {
invokeIdAndPriority = tDlmsInvokeIdAndPriority(invokeId << 4)
}
buf := new(bytes.Buffer) // buffer for encoded application layer data pdu
// encode application layer data pdu
if 1 == len(vals) { // normal request
if nil == vals[0].Data {
if vals[0].AttributeId > 0 {
// get request normat
_, err = buf.Write([]byte{0xC0, 0x01, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
err = encode_GetRequestNormal(buf, vals[0].ClassId, vals[0].InstanceId, vals[0].AttributeId, vals[0].AccessSelector, vals[0].AccessParameter)
if nil != err {
return nil, err
}
} else if vals[0].MethodId > 0 {
// action request normal
_, err = buf.Write([]byte{0xC3, 0x01, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
err = encode_ActionRequestNormal(buf, vals[0].ClassId, vals[0].InstanceId, vals[0].MethodId, vals[0].MethodParameters)
if nil != err {
return nil, err
}
} else {
panic("assertion failed")
}
} else {
if 0 == vals[0].BlockSize {
_, err = buf.Write([]byte{0xC1, 0x01, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
err = encode_SetRequestNormal(buf, vals[0].ClassId, vals[0].InstanceId, vals[0].AttributeId, vals[0].AccessSelector, vals[0].AccessParameter, vals[0].Data)
if nil != err {
return nil, err
}
} else {
_, err = buf.Write([]byte{0xC1, 0x02, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
var _buf bytes.Buffer
err = vals[0].Data.Encode(&_buf)
if nil != err {
return nil, err
}
vals[0].rawData = _buf.Bytes()
n := vals[0].BlockSize
if n > len(vals[0].rawData) {
n = len(vals[0].rawData)
}
rawData := vals[0].rawData[0:n]
vals[0].rawData = vals[0].rawData[n:]
lastBlock := false
if 0 == len(vals[0].rawData) {
lastBlock = true
}
// TODO: unit test
err = encode_SetRequestNormalBlock(buf, vals[0].ClassId, vals[0].InstanceId, vals[0].AttributeId, vals[0].AccessSelector, vals[0].AccessParameter, lastBlock, vals[0].blockNumber+1, rawData)
if nil != err {
return nil, err
} else {
vals[0].blockNumber += 1
}
}
}
} else if len(vals) > 1 { // request with list
if nil == vals[0].Data {
_, err = buf.Write([]byte{0xC0, 0x03, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
var (
classIds []DlmsClassId = make([]DlmsClassId, len(vals))
instanceIds []*DlmsOid = make([]*DlmsOid, len(vals))
attributeIds []DlmsAttributeId = make([]DlmsAttributeId, len(vals))
accessSelectors []DlmsAccessSelector = make([]DlmsAccessSelector, len(vals))
accessParameters []*DlmsData = make([]*DlmsData, len(vals))
)
for i := 0; i < len(vals); i += 1 {
classIds[i] = vals[i].ClassId
instanceIds[i] = vals[i].InstanceId
attributeIds[i] = vals[i].AttributeId
accessSelectors[i] = vals[i].AccessSelector
accessParameters[i] = vals[i].AccessParameter
}
err = encode_GetRequestWithList(buf, classIds, instanceIds, attributeIds, accessSelectors, accessParameters)
if nil != err {
return nil, err
}
} else {
var (
classIds []DlmsClassId = make([]DlmsClassId, len(vals))
instanceIds []*DlmsOid = make([]*DlmsOid, len(vals))
attributeIds []DlmsAttributeId = make([]DlmsAttributeId, len(vals))
accessSelectors []DlmsAccessSelector = make([]DlmsAccessSelector, len(vals))
accessParameters []*DlmsData = make([]*DlmsData, len(vals))
datas []*DlmsData = make([]*DlmsData, len(vals))
)
for i := 0; i < len(vals); i += 1 {
classIds[i] = vals[i].ClassId
instanceIds[i] = vals[i].InstanceId
attributeIds[i] = vals[i].AttributeId
accessSelectors[i] = vals[i].AccessSelector
accessParameters[i] = vals[i].AccessParameter
datas[i] = vals[i].Data
}
if 0 == vals[0].BlockSize {
_, err = buf.Write([]byte{0xC1, 0x04, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
err = encode_SetRequestWithList(buf, classIds, instanceIds, attributeIds, accessSelectors, accessParameters, datas)
if nil != err {
return nil, err
}
} else {
_, err = buf.Write([]byte{0xC1, 0x05, byte(invokeIdAndPriority)})
if nil != err {
errorLog("buf.Write() failed: %v\n", err)
return nil, err
}
var _buf bytes.Buffer
count := uint8(len(classIds))
err = binary.Write(&_buf, binary.BigEndian, count)
if nil != err {
panic(fmt.Sprintf("binary.Write() failed: %v", err))
}
for i := 0; i < int(count); i++ {
err = vals[i].Data.Encode(&_buf)
if nil != err {
return nil, err
}
}
vals[0].rawData = _buf.Bytes()
n := vals[0].BlockSize
if n > len(vals[0].rawData) {
n = len(vals[0].rawData)
}
rawData := vals[0].rawData[0:n]
vals[0].rawData = vals[0].rawData[n:]
lastBlock := false
if 0 == len(vals[0].rawData) {
lastBlock = true
}
// TODO: unit test
err = encode_SetRequestWithListBlock(buf, classIds, instanceIds, attributeIds, accessSelectors, accessParameters, lastBlock, vals[0].blockNumber+1, rawData)
if nil != err {
return nil, err
} else {
vals[0].blockNumber += 1
}
}
}
} else {
panic("assertion failed")
}
// send request
debugLog("send request")
err = aconn.dconn.transportSend(aconn.applicationClient, aconn.logicalDevice, buf.Bytes())
if nil != err {
return nil, err
}
// receive reply
debugLog("receive request")
pdu, err := aconn.dconn.transportReceive(aconn.logicalDevice, aconn.applicationClient)
if nil != err {
return nil, err
}
buf = bytes.NewBuffer(pdu)
p := make([]byte, 3)
err = binary.Read(buf, binary.BigEndian, p)
if nil != err {
errorLog("io.Read() failed: %v", err)
return nil, err
}
invokeIdRcv := uint8((p[2] & 0xF0) >> 4)
if invokeIdRcv != invokeId {
err := fmt.Errorf("invoke ids differs: invokeId sent: %v, invokeId received: %v", invokeId, invokeIdRcv)
errorLog("%s", err)
return nil, err
}
err = aconn.processReply(rips, p, buf)
if nil == err {
t := time.Now()
for i := 0; i < len(rips); i++ {
rips[i].ReplyDeliveredAt = t
}
}
return DlmsResultResponse(rips), err
}