s-net-Tools
FloodingPacketSource.h
Go to the documentation of this file.
1 
22 #ifndef FLOODING_PACKET_SOURCE_H
23 #define FLOODING_PACKET_SOURCE_H
24 
25 #include "HdlcdClient.h"
26 #include "SnetPlatformRequest.h"
27 
29 public:
30  FloodingPacketSource(HdlcdClient& a_HdlcdClient, uint16_t a_UnicastSSA): m_HdlcdClient(a_HdlcdClient), m_UnicastSSA(a_UnicastSSA), m_usSeqNr(0) {
31  }
32 
33  void Start() {
34  // Trigger activity
35  SendNextPacket();
36  }
37 
38 private:
39  // Helpers
40  void SendNextPacket() {
41  // Create firmware request message
42  SnetPlatformRequest l_PlatformRequest(m_UnicastSSA);
43 
44  // Send one firmware request, and if done, call this method again via a provided lambda-callback
45  if (m_HdlcdClient.Send(std::move(HdlcdPacketData::CreatePacket(l_PlatformRequest.Serialize(), false)), [this](){ SendNextPacket(); })) {
46  // One packet is on its way
47  if (((++m_usSeqNr) % 1000) == 0) {
48  m_usSeqNr = 0;
49  std::cout << "1000 Packets written to the TCP socket" << std::endl;
50  } // if
51  } // if
52  }
53 
54  // Members
55  HdlcdClient& m_HdlcdClient;
56  uint16_t m_UnicastSSA;
57  unsigned short m_usSeqNr;
58 };
59 
60 #endif // FLOODING_PACKET_SOURCE_H
A set of tools to exchange and handle packets of s-net(r) devices via the HDLC Daemon. Copyright (C) 2016 Florian Evers, florian-evers@gmx.de.
bool Send(const HdlcdPacketData &a_PacketData, std::function< void()> a_OnSendDoneCallback=nullptr)
Send a single data packet to the peer entity.
Definition: HdlcdClient.h:203
static HdlcdPacketData CreatePacket(const std::vector< unsigned char > a_Payload, bool a_bReliable, bool a_bInvalid=false, bool a_bWasSent=false)
Class HdlcdClient.
Definition: HdlcdClient.h:54
std::vector< unsigned char > Serialize() const
Copyright (c) 2016, Florian Evers, florian-evers@gmx.de All rights reserved.
FloodingPacketSource(HdlcdClient &a_HdlcdClient, uint16_t a_UnicastSSA)