2021-08-08 17:25:41 -04:00
|
|
|
/*
|
|
|
|
property.cpp
|
|
|
|
|
|
|
|
Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "parameter.h"
|
2023-05-02 12:59:26 -04:00
|
|
|
#include "E1.37-7.h"
|
2021-08-08 17:25:41 -04:00
|
|
|
|
|
|
|
namespace RDM {
|
|
|
|
|
|
|
|
/**
|
2023-04-28 20:46:13 -04:00
|
|
|
* @brief Parameter::Parameter
|
2023-05-02 12:59:26 -04:00
|
|
|
* @param metadata
|
2021-08-08 17:25:41 -04:00
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
Parameter::Parameter(const ParameterDescription metadata)
|
|
|
|
: info(metadata)
|
|
|
|
, action_discover_(nullptr)
|
|
|
|
, action_get_(nullptr)
|
|
|
|
, action_set_(nullptr)
|
|
|
|
, action_discover_response_(nullptr)
|
|
|
|
, action_get_response_(nullptr)
|
|
|
|
, action_set_response_(nullptr)
|
2021-08-08 17:25:41 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-09 15:39:35 -04:00
|
|
|
/**
|
2023-05-02 12:59:26 -04:00
|
|
|
* @brief Parameter::isManufacturer
|
|
|
|
* @return
|
2021-08-09 15:39:35 -04:00
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
bool Parameter::isManufacturer() const
|
2021-08-09 15:39:35 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
return info.pid >= 0x8000 && info.pid <= 0xFFDF; // \cite RDM 10.4.2 range
|
2021-08-09 15:39:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-11 01:26:51 -04:00
|
|
|
/**
|
|
|
|
* @brief Parameter::disc
|
2023-05-02 12:59:26 -04:00
|
|
|
* @param msg
|
2021-08-11 01:26:51 -04:00
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
void Parameter::dispatch(MsgPair msg) const
|
2021-08-11 01:26:51 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
auto exec = [this, &msg] (PidAction action, uint8_t min_pdl, uint8_t cc)
|
|
|
|
{
|
|
|
|
auto [command, response] = msg;
|
|
|
|
if (action)
|
|
|
|
if (command->mdb.pdl() < min_pdl)
|
|
|
|
return response->nak(NR_FORMAT_ERROR);
|
|
|
|
else
|
|
|
|
return action(msg);
|
|
|
|
else
|
|
|
|
if (info.command_class & cc)
|
|
|
|
return response->nak(NR_ACTION_NOT_SUPPORTED);
|
|
|
|
else
|
|
|
|
return response->nak(NR_UNSUPPORTED_COMMAND_CLASS);
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (msg.first->mdb.cc) {
|
|
|
|
case DISCOVERY_COMMAND:
|
|
|
|
exec(action_discover_, info.pdl.get, CC_DISC);
|
|
|
|
break;
|
|
|
|
case DISCOVERY_COMMAND_RESPONSE:
|
|
|
|
exec(action_discover_response_, info.pdl.get_response, CC_DISC);
|
|
|
|
break;
|
|
|
|
case GET_COMMAND:
|
|
|
|
exec(action_get_, info.pdl.get, CC_GET);
|
|
|
|
break;
|
|
|
|
case GET_COMMAND_RESPONSE:
|
|
|
|
exec(action_get_response_, info.pdl.get_response, CC_GET);
|
|
|
|
break;
|
|
|
|
case SET_COMMAND:
|
|
|
|
exec(action_set_, info.pdl.set, CC_SET);
|
|
|
|
break;
|
|
|
|
case SET_COMMAND_RESPONSE:
|
|
|
|
exec(action_set_response_, info.pdl.set_response, CC_SET);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-08-11 01:26:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-08 17:25:41 -04:00
|
|
|
/**
|
2023-05-02 12:59:26 -04:00
|
|
|
* @brief Parameter::onDisc
|
|
|
|
* @param action
|
2021-08-08 17:25:41 -04:00
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
void Parameter::onDisc(const PidAction action)
|
2021-08-08 17:25:41 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
if (info.command_class & CC_DISC)
|
|
|
|
action_discover_ = action;
|
|
|
|
};
|
2021-08-08 17:25:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-02 12:59:26 -04:00
|
|
|
* @brief Parameter::onDiscResponse
|
|
|
|
* @param action
|
2021-08-08 17:25:41 -04:00
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
void Parameter::onDiscResponse(const PidAction action)
|
2021-08-08 17:25:41 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
if (info.command_class & CC_DISC)
|
|
|
|
action_discover_response_ = action;
|
|
|
|
};
|
2021-08-08 17:25:41 -04:00
|
|
|
|
2021-08-25 17:20:33 -04:00
|
|
|
|
|
|
|
/**
|
2023-05-02 12:59:26 -04:00
|
|
|
* @brief Parameter::onGet
|
2021-08-25 17:20:33 -04:00
|
|
|
* @param action
|
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
void Parameter::onGet(const PidAction action)
|
2021-08-25 17:20:33 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
if (info.command_class & CC_GET)
|
|
|
|
action_get_ = action;
|
2021-08-25 17:20:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-02 12:59:26 -04:00
|
|
|
* @brief Parameter::onGetResponse
|
2021-08-25 17:20:33 -04:00
|
|
|
* @param action
|
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
void Parameter::onGetResponse(const PidAction action)
|
2021-08-25 17:20:33 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
if (info.command_class & CC_GET)
|
|
|
|
action_get_response_ = action;
|
2021-08-25 17:20:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-05-02 12:59:26 -04:00
|
|
|
* @brief Parameter::onSet
|
2021-08-25 17:20:33 -04:00
|
|
|
* @param action
|
|
|
|
*/
|
2023-05-02 12:59:26 -04:00
|
|
|
void Parameter::onSet(const PidAction action)
|
2021-08-25 17:20:33 -04:00
|
|
|
{
|
2023-05-02 12:59:26 -04:00
|
|
|
if (info.command_class & CC_SET)
|
|
|
|
action_set_ = action;
|
2021-08-25 17:20:33 -04:00
|
|
|
};
|
|
|
|
|
2023-05-02 12:59:26 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Parameter::onSetResponse
|
|
|
|
* @param action
|
|
|
|
*/
|
|
|
|
void Parameter::onSetResponse(const PidAction action)
|
|
|
|
{
|
|
|
|
if (info.command_class & CC_SET)
|
|
|
|
action_set_response_ = action;
|
|
|
|
};
|
2021-08-08 17:25:41 -04:00
|
|
|
} // namespace RDM
|