-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🍺 Extend Sample to RoutingActivation
- Loading branch information
Showing
4 changed files
with
195 additions
and
24 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <utility> | ||
#include "./routing_activation_handler.h" | ||
|
||
namespace DoipLib | ||
{ | ||
const uint8_t RoutingActivationHandler::cSupportedActivationType; | ||
const bool RoutingActivationHandler::cHasOemSpecificData; | ||
|
||
RoutingActivationHandler::RoutingActivationHandler( | ||
uint8_t protocolVersion, | ||
uint16_t logicalAddress) : cProtocolVersion{protocolVersion}, cLogicalAddress{logicalAddress} | ||
{ | ||
} | ||
|
||
Message *RoutingActivationHandler::GetMessage() | ||
{ | ||
return static_cast<Message *>(&mRequest); | ||
} | ||
|
||
bool RoutingActivationHandler::TryHandle( | ||
const Message *request, std::vector<uint8_t> &response) const | ||
{ | ||
auto _routingActivationRequest{ | ||
dynamic_cast<const RoutingActivationRequest *>(request)}; | ||
|
||
if (_routingActivationRequest == nullptr) | ||
{ | ||
return false; | ||
} | ||
|
||
const uint16_t cTesterAddress{_routingActivationRequest->GetSourceAddress()}; | ||
RoutingActivationResponseType _responseCode; | ||
|
||
if (_routingActivationRequest->GetActivationType() != cSupportedActivationType) | ||
{ | ||
_responseCode = RoutingActivationResponseType::UnsupportedActivationType; | ||
} | ||
else if (mActiveTesters.find(cTesterAddress) != mActiveTesters.end()) | ||
{ | ||
_responseCode = RoutingActivationResponseType::AlreadyRegisteredTester; | ||
} | ||
else | ||
{ | ||
mActiveTesters.emplace(cTesterAddress); | ||
_responseCode = RoutingActivationResponseType::Successful; | ||
} | ||
|
||
RoutingActivationResponse _routingActivationResponse( | ||
cProtocolVersion, | ||
cTesterAddress, | ||
cLogicalAddress, | ||
_responseCode); | ||
|
||
_routingActivationResponse.Serialize(response); | ||
|
||
return true; | ||
} | ||
} |
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,36 @@ | ||
#ifndef ROUTING_ACTIVATION_HANDLER_H | ||
#define ROUTING_ACTIVATION_HANDLER_H | ||
|
||
#include<set> | ||
|
||
#include "../include/doiplib/message_handler.h" | ||
#include "../include/doiplib/routing_activation_request.h" | ||
#include "../include/doiplib/routing_activation_response.h" | ||
|
||
namespace DoipLib | ||
{ | ||
class RoutingActivationHandler : public MessageHandler | ||
{ | ||
private: | ||
static const uint8_t cSupportedActivationType{0x00U}; | ||
static const bool cHasOemSpecificData{false}; | ||
|
||
const uint8_t cProtocolVersion; | ||
const uint16_t cLogicalAddress; | ||
|
||
mutable std::set<uint16_t> mActiveTesters; | ||
RoutingActivationRequest mRequest; | ||
|
||
public: | ||
RoutingActivationHandler( | ||
uint8_t protocolVersion, | ||
uint16_t logicalAddress); | ||
|
||
Message *GetMessage() override; | ||
|
||
bool TryHandle( | ||
const Message *request, std::vector<uint8_t> &response) const override; | ||
}; | ||
} | ||
|
||
#endif |