forked from OpenLightingProject/ola
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to inflate an LLRP Probe Reply and build a Probe Request
- Loading branch information
1 parent
ed113e1
commit 8db5131
Showing
6 changed files
with
383 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* LLRPProbeReplyInflator.cpp | ||
* The Inflator for the LLRP Probe Reply PDUs | ||
* Copyright (C) 2020 Peter Newman | ||
*/ | ||
|
||
#include <iostream> | ||
#include <memory> | ||
#include "ola/Logging.h" | ||
#include "include/ola/rdm/UID.h" | ||
#include "include/ola/rdm/UIDSet.h" | ||
#include "include/ola/strings/Format.h" | ||
#include "libs/acn/LLRPProbeReplyInflator.h" | ||
#include "libs/acn/LLRPProbeReplyPDU.h" | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
using ola::acn::LLRPProbeReplyPDU; | ||
using ola::rdm::UID; | ||
using ola::rdm::UIDSet; | ||
|
||
/** | ||
* Create a new LLRP Probe Reply inflator | ||
*/ | ||
LLRPProbeReplyInflator::LLRPProbeReplyInflator() | ||
: BaseInflator(PDU::ONE_BYTE) { | ||
} | ||
|
||
/** | ||
* Set an LLRPProbeReplyHandler to run when receiving an LLRP Probe Reply | ||
* message. | ||
* @param handler the callback to invoke when there is and LLRP Probe Reply. | ||
*/ | ||
void LLRPProbeReplyInflator::SetLLRPProbeReplyHandler( | ||
LLRPProbeReplyHandler *handler) { | ||
m_llrp_probe_reply_handler.reset(handler); | ||
} | ||
|
||
|
||
/* | ||
* Decode the LLRP Probe Reply 'header', which is 0 bytes in length. | ||
* @param headers the HeaderSet to add to | ||
* @param data a pointer to the data | ||
* @param length length of the data | ||
* @returns true if successful, false otherwise | ||
*/ | ||
bool LLRPProbeReplyInflator::DecodeHeader(HeaderSet *, | ||
const uint8_t*, | ||
unsigned int, | ||
unsigned int *bytes_used) { | ||
*bytes_used = 0; | ||
return true; | ||
} | ||
|
||
|
||
/* | ||
* Handle a LLRP Probe Reply PDU for E1.33. | ||
*/ | ||
bool LLRPProbeReplyInflator::HandlePDUData(uint32_t vector, | ||
const HeaderSet &headers, | ||
const uint8_t *data, | ||
unsigned int pdu_len) { | ||
if (vector != LLRPProbeReplyPDU::VECTOR_PROBE_REPLY_DATA) { | ||
OLA_INFO << "Not a probe reply, vector was " << vector; | ||
return true; | ||
} | ||
|
||
ola::strings::FormatData(&std::cout, data, pdu_len); | ||
|
||
LLRPProbeReplyPDU::llrp_probe_reply_pdu_data pdu_data; | ||
if (pdu_len > sizeof(pdu_data)) { | ||
OLA_WARN << "Got too much data, received " << pdu_len << " only expecting " | ||
<< sizeof(pdu_data); | ||
return false; | ||
} | ||
|
||
memcpy(reinterpret_cast<uint8_t*>(&pdu_data), data, sizeof(pdu_data)); | ||
|
||
OLA_DEBUG << "Probe from " << UID(pdu_data.target_uid); | ||
|
||
LLRPProbeReply reply(UID(pdu_data.target_uid)); | ||
|
||
if (m_llrp_probe_reply_handler.get()) { | ||
m_llrp_probe_reply_handler->Run(&headers, | ||
reply); | ||
} else { | ||
OLA_WARN << "No LLRP Probe Reply handler defined!"; | ||
} | ||
return true; | ||
} | ||
} // namespace acn | ||
} // namespace ola |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* LLRPProbeReplyInflator.h | ||
* Copyright (C) 2020 Peter Newman | ||
*/ | ||
|
||
#ifndef LIBS_ACN_LLRPPROBEREPLYINFLATOR_H_ | ||
#define LIBS_ACN_LLRPPROBEREPLYINFLATOR_H_ | ||
|
||
#include "ola/Callback.h" | ||
#include "ola/acn/ACNVectors.h" | ||
#include "ola/rdm/UID.h" | ||
#include "ola/rdm/UIDSet.h" | ||
#include "libs/acn/BaseInflator.h" | ||
#include "libs/acn/HeaderSet.h" | ||
#include "libs/acn/LLRPProbeReplyPDU.h" | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
class LLRPProbeReplyInflator: public BaseInflator { | ||
friend class LLRPProbeReplyInflatorTest; | ||
|
||
public: | ||
struct LLRPProbeReply { | ||
LLRPProbeReply(const ola::rdm::UID &_uid) | ||
: uid(_uid) { | ||
} | ||
ola::rdm::UID uid; | ||
ola::network::MACAddress hardware_address; | ||
ola::acn::LLRPProbeReplyPDU::LLRPComponentType component_type; | ||
}; | ||
|
||
|
||
// These are pointers so the callers don't have to pull in all the headers. | ||
typedef ola::Callback2<void, | ||
const HeaderSet*, // the HeaderSet | ||
const LLRPProbeReply& // Probe Reply Data | ||
> LLRPProbeReplyHandler; | ||
|
||
LLRPProbeReplyInflator(); | ||
~LLRPProbeReplyInflator() {} | ||
|
||
uint32_t Id() const { return ola::acn::VECTOR_LLRP_PROBE_REPLY; } | ||
|
||
void SetLLRPProbeReplyHandler(LLRPProbeReplyHandler *handler); | ||
|
||
protected: | ||
bool DecodeHeader(HeaderSet *headers, | ||
const uint8_t *data, | ||
unsigned int len, | ||
unsigned int *bytes_used); | ||
|
||
void ResetHeaderField() {} // namespace noop | ||
|
||
virtual bool HandlePDUData(uint32_t vector, | ||
const HeaderSet &headers, | ||
const uint8_t *data, | ||
unsigned int pdu_len); | ||
|
||
private: | ||
std::auto_ptr<LLRPProbeReplyHandler> m_llrp_probe_reply_handler; | ||
}; | ||
} // namespace acn | ||
} // namespace ola | ||
#endif // LIBS_ACN_LLRPPROBEREPLYINFLATOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.