Skip to content

Commit a898434

Browse files
committed
AdsNotification: allow dynamic sized samples
It seems some ADS devices like AMSPORT_LOGGER will send notifications with variable sizes. To support them we can lessen our size check, but we have to pass the real size to Notification::Notify() Signed-off-by: Patrick Bruenn <[email protected]>
1 parent e85ef69 commit a898434

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

AdsLib/AdsNotification.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@ struct Notification {
2323
: connection({__port, __amsAddr}),
2424
callback(__func),
2525
buffer(sizeof(AdsNotificationHeader) + length),
26-
hUser(__hUser)
26+
hUser(__hUser),
27+
size(length)
2728
{
2829
auto header = reinterpret_cast<AdsNotificationHeader*>(buffer.data());
2930
header->hNotification = 0;
3031
header->cbSampleSize = length;
3132
}
3233

33-
void Notify(uint64_t timestamp, RingBuffer& ring)
34+
void Notify(RingBuffer& ring, const uint64_t timestamp, const uint32_t sampleSize)
3435
{
3536
auto header = reinterpret_cast<AdsNotificationHeader*>(buffer.data());
3637
uint8_t* data = reinterpret_cast<uint8_t*>(header + 1);
37-
for (size_t i = 0; i < header->cbSampleSize; ++i) {
38+
header->cbSampleSize = sampleSize;
39+
header->nTimeStamp = timestamp;
40+
for (size_t i = 0; i < sampleSize; ++i) {
3841
data[i] = ring.ReadFromLittleEndian<uint8_t>();
3942
}
40-
header->nTimeStamp = timestamp;
4143
callback(&connection.second, header, hUser);
4244
}
4345

4446
uint32_t Size() const
4547
{
46-
auto header = reinterpret_cast<const AdsNotificationHeader*>(buffer.data());
47-
return header->cbSampleSize;
48+
return size;
4849
}
4950

5051
void hNotify(uint32_t value)
@@ -57,4 +58,5 @@ struct Notification {
5758
const PAdsNotificationFuncEx callback;
5859
std::vector<uint8_t> buffer;
5960
const uint32_t hUser;
61+
const uint32_t size;
6062
};

AdsLib/standalone/NotificationDispatcher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ void NotificationDispatcher::Run()
7272
fullLength -= sizeof(hNotify) + sizeof(size);
7373
const auto notification = Find(hNotify);
7474
if (notification) {
75-
if (size != notification->Size()) {
76-
LOG_WARN("Notification sample size: " << size << " doesn't match: " << notification->Size());
75+
if (size > notification->Size()) {
76+
LOG_WARN("Notification sample size: " << size << " to large: " << notification->Size());
7777
goto cleanup;
7878
}
79-
notification->Notify(timestamp, ring);
79+
notification->Notify(ring, timestamp, size);
8080
} else {
8181
ring.Read(size);
8282
}

0 commit comments

Comments
 (0)