/* 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" #include "E1.37-7.h" namespace RDM { /** * @brief Parameter::Parameter * @param metadata */ 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) { } /** * @brief Parameter::isManufacturer * @return */ bool Parameter::isManufacturer() const { return info.pid >= 0x8000 && info.pid <= 0xFFDF; // \cite RDM 10.4.2 range } /** * @brief Parameter::disc * @param msg */ void Parameter::dispatch(MsgPair msg) const { 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; } } /** * @brief Parameter::onDisc * @param action */ void Parameter::onDisc(const PidAction action) { if (info.command_class & CC_DISC) action_discover_ = action; }; /** * @brief Parameter::onDiscResponse * @param action */ void Parameter::onDiscResponse(const PidAction action) { if (info.command_class & CC_DISC) action_discover_response_ = action; }; /** * @brief Parameter::onGet * @param action */ void Parameter::onGet(const PidAction action) { if (info.command_class & CC_GET) action_get_ = action; }; /** * @brief Parameter::onGetResponse * @param action */ void Parameter::onGetResponse(const PidAction action) { if (info.command_class & CC_GET) action_get_response_ = action; }; /** * @brief Parameter::onSet * @param action */ void Parameter::onSet(const PidAction action) { if (info.command_class & CC_SET) action_set_ = action; }; /** * @brief Parameter::onSetResponse * @param action */ void Parameter::onSetResponse(const PidAction action) { if (info.command_class & CC_SET) action_set_response_ = action; }; } // namespace RDM