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.
Showing
2 changed files
with
189 additions
and
0 deletions.
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,89 @@ | ||
/* | ||
* 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. | ||
* | ||
* BrokerClientEntryRPTInflator.cpp | ||
* The Inflator for BrokerClientEntryRPT PDU | ||
* Copyright (C) 2023 Peter Newman | ||
*/ | ||
|
||
#include <iostream> | ||
#include <memory> | ||
|
||
#include "ola/Logging.h" | ||
#include "ola/acn/CID.h" | ||
#include "ola/e133/E133Helper.h" | ||
#include "ola/network/NetworkUtils.h" | ||
#include "ola/rdm/UID.h" | ||
#include "include/ola/strings/Format.h" | ||
#include "libs/acn/BrokerClientEntryRPTInflator.h" | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
using ola::acn::CID; | ||
using ola::network::NetworkToHost; | ||
using ola::rdm::UID; | ||
using ola::strings::IntToString; | ||
|
||
/** | ||
* Set a BrokerClientEntryRPTHandler to run when receiving a Broker Client | ||
* Entry RPT message. | ||
* @param handler the callback to invoke when there is a Broker Client Entry | ||
* RPT. | ||
*/ | ||
void BrokerClientEntryRPTInflator::SetBrokerClientEntryRPTHandler( | ||
BrokerClientEntryRPTHandler *handler) { | ||
m_broker_client_entry_rpt_handler.reset(handler); | ||
} | ||
|
||
|
||
unsigned int BrokerClientEntryRPTInflator::InflatePDUBlock( | ||
OLA_UNUSED HeaderSet *headers, | ||
const uint8_t *data, | ||
unsigned int len) { | ||
broker_client_entry_rpt_pdu_data pdu_data; | ||
if (len > sizeof(pdu_data)) { | ||
OLA_WARN << "Got too much data, received " << len << " only expecting " | ||
<< sizeof(pdu_data); | ||
return 0; | ||
} | ||
|
||
memcpy(reinterpret_cast<uint8_t*>(&pdu_data), data, sizeof(pdu_data)); | ||
|
||
OLA_DEBUG << "Client Entry RPT from " << CID::FromData(pdu_data.client_cid) | ||
<< " (" << UID(pdu_data.client_uid) << ") of RPT Client Type " | ||
<< IntToString(pdu_data.rpt_client_type); | ||
|
||
ola::e133::E133RPTClientTypeCode client_type; | ||
if (!ola::e133::IntToRPTClientType(pdu_data.rpt_client_type, &client_type)) { | ||
OLA_WARN << "Unknown E1.33 RPT Client Type code " | ||
<< IntToString(pdu_data.rpt_client_type); | ||
} | ||
|
||
BrokerClientEntryRPT client_entry(CID::FromData(pdu_data.client_cid), | ||
UID(pdu_data.client_uid), | ||
client_type, | ||
CID::FromData(pdu_data.binding_cid)); | ||
|
||
if (m_broker_client_entry_rpt_handler.get()) { | ||
m_broker_client_entry_rpt_handler->Run(headers, | ||
client_entry); | ||
} else { | ||
OLA_WARN << "No Broker Client Entry RPT handler defined!"; | ||
} | ||
return sizeof(pdu_data); | ||
} | ||
} // 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,100 @@ | ||
/* | ||
* 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. | ||
* | ||
* BrokerClientEntryRPTInflator.h | ||
* Interface for the BrokerClientEntryRPTInflator class. | ||
* Copyright (C) 2023 Peter Newman | ||
*/ | ||
|
||
#ifndef LIBS_ACN_BROKERCLIENTENTRYRPTINFLATOR_H_ | ||
#define LIBS_ACN_BROKERCLIENTENTRYRPTINFLATOR_H_ | ||
|
||
#include "ola/Callback.h" | ||
#include "ola/acn/ACNVectors.h" | ||
#include "ola/e133/E133Enums.h" | ||
#include "ola/rdm/UID.h" | ||
#include "libs/acn/BaseInflator.h" | ||
|
||
namespace ola { | ||
namespace acn { | ||
|
||
class BrokerClientEntryRPTInflator: public BaseInflator { | ||
friend class BrokerClientEntryRPTInflatorTest; | ||
|
||
public: | ||
struct BrokerClientEntryRPT { | ||
BrokerClientEntryRPT(const ola::acn::CID &_client_cid, | ||
const ola::rdm::UID &_client_uid, | ||
ola::e133::E133RPTClientTypeCode _client_type_code, | ||
const ola::acn::CID &_binding_cid) | ||
: client_cid(_client_cid), | ||
client_uid(_client_uid), | ||
client_type_code(_client_type_code), | ||
binding_cid(_binding_cid) { | ||
} | ||
ola::acn::CID client_cid; | ||
ola::rdm::UID client_uid; | ||
ola::e133::E133RPTClientTypeCode client_type_code; | ||
ola::acn::CID binding_cid; | ||
}; | ||
|
||
|
||
// These are pointers so the callers don't have to pull in all the headers. | ||
typedef ola::Callback2<void, | ||
const HeaderSet*, // the HeaderSet | ||
const BrokerClientEntryRPT& // RPT Client Entry Data | ||
> BrokerClientEntryRPTHandler; | ||
|
||
BrokerClientEntryRPTInflator() | ||
: BaseInflator() { | ||
} | ||
~BrokerClientEntryRPTInflator() {} | ||
|
||
uint32_t Id() const { return ola::acn::CLIENT_PROTOCOL_RPT; } | ||
|
||
PACK( | ||
struct broker_client_entry_rpt_pdu_data_s { | ||
uint8_t client_cid[ola::acn::CID::CID_LENGTH]; | ||
uint8_t client_uid[ola::rdm::UID::LENGTH]; | ||
uint8_t rpt_client_type; | ||
uint8_t binding_cid[ola::acn::CID::CID_LENGTH]; | ||
}); | ||
typedef struct broker_client_entry_rpt_pdu_data_s | ||
broker_client_entry_rpt_pdu_data; | ||
|
||
void SetBrokerClientEntryRPTHandler(BrokerClientEntryRPTHandler *handler); | ||
|
||
protected: | ||
// The 'header' is 0 bytes in length. | ||
bool DecodeHeader(HeaderSet*, | ||
const uint8_t*, | ||
unsigned int, | ||
unsigned int *bytes_used) { | ||
*bytes_used = 0; | ||
return true; | ||
} | ||
|
||
void ResetHeaderField() {} // namespace noop | ||
|
||
unsigned int InflatePDUBlock(HeaderSet *headers, | ||
const uint8_t *data, | ||
unsigned int len); | ||
|
||
private: | ||
std::auto_ptr<BrokerClientEntryRPTHandler> m_broker_client_entry_rpt_handler; | ||
}; | ||
} // namespace acn | ||
} // namespace ola | ||
#endif // LIBS_ACN_BROKERCLIENTENTRYRPTINFLATOR_H_ |