AdsLib
Loading...
Searching...
No Matches
AdsNotification.h
1// SPDX-License-Identifier: MIT
6#pragma once
7
8#include "AdsDef.h"
9#include "RingBuffer.h"
10
11#include <utility>
12
13using VirtualConnection = std::pair<uint16_t, AmsAddr>;
14
16 const VirtualConnection connection;
17
19 uint32_t __hUser,
20 uint32_t length,
21 AmsAddr __amsAddr,
22 uint16_t __port)
23 : connection({__port, __amsAddr}),
24 callback(__func),
25 buffer(new uint8_t[sizeof(AdsNotificationHeader) + length]),
26 hUser(__hUser)
27 {
28 auto header = reinterpret_cast<AdsNotificationHeader*>(buffer.get());
29 header->hNotification = 0;
30 header->cbSampleSize = length;
31 }
32
33 void Notify(uint64_t timestamp, RingBuffer& ring) const
34 {
35 auto header = reinterpret_cast<AdsNotificationHeader*>(buffer.get());
36 uint8_t* data = reinterpret_cast<uint8_t*>(header + 1);
37 for (size_t i = 0; i < header->cbSampleSize; ++i) {
38 data[i] = ring.ReadFromLittleEndian<uint8_t>();
39 }
40 header->nTimeStamp = timestamp;
41 callback(&connection.second, header, hUser);
42 }
43
44 uint32_t Size() const
45 {
46 auto header = reinterpret_cast<AdsNotificationHeader*>(buffer.get());
47 return header->cbSampleSize;
48 }
49
50 void hNotify(uint32_t value)
51 {
52 auto header = reinterpret_cast<AdsNotificationHeader*>(buffer.get());
53 header->hNotification = value;
54 }
55
56private:
57 const PAdsNotificationFuncEx callback;
58 const std::shared_ptr<uint8_t> buffer;
59 const uint32_t hUser;
60};
void(* PAdsNotificationFuncEx)(const AmsAddr *pAddr, const AdsNotificationHeader *pNotification, uint32_t hUser)
Type definition of the callback function required by the AdsSyncAddDeviceNotificationReqEx() function...
Definition: AdsDef.h:363
This structure is also passed to the callback function.
Definition: AdsDef.h:346
uint32_t hNotification
Definition: AdsDef.h:351
uint32_t cbSampleSize
Definition: AdsDef.h:354
The complete address of an ADS device can be stored in this structure.
Definition: AdsDef.h:237
Definition: AdsNotification.h:15
Definition: RingBuffer.h:12