OpenLCP/protocol/esta/rdm/basicdevice.h
2023-05-02 13:00:41 -04:00

92 lines
3.2 KiB
C++

/*
rdm/basicdevice.h
Copyright (c) 2023 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.
*/
#pragma once
#include "message.h"
#include "parameter.h"
#include "sensor.h"
#include "status.h"
#include <list>
#include <map>
#include <queue>
namespace RDM {
/**
* @brief The BasicDevice class
*/
class BasicDevice
{
public:
explicit BasicDevice();
virtual ~BasicDevice();
std::string deviceManufacturerLabel; //!< manufacturer label
std::string deviceModelDescription; //!< model description
uint16_t deviceModelID; //!< model ID number
uint16_t deviceProductCategory; //!< device category
virtual void identify(bool state);
virtual void reset(bool hard);
protected:
friend class Device;
friend class Responder;
virtual bool hasManufacturerPIDs() const; //!< device has non-standard PIDs @return
virtual bool hasDMXaddress() const { return false; } //!< device has a DMX address @return
virtual bool hasSubDevices() const { return false; } //!< device has subdevices @return
virtual bool hasSensors() const { return !sensors_.empty(); } //!< device as sensors @return
virtual void dispatch(MsgPair msg);
void enqueueStatus(StatusPtr status);
Parameter *addParameter(const ParameterDescription metadata);
virtual void actionGetSupportedParameters(MsgPair msg);
virtual void actionGetParameterDescription(MsgPair msg);
virtual void actionGetDeviceInfo(MsgPair msg);
virtual void actionGetSoftwareVersionLabel(MsgPair msg);
virtual void actionGetIdentifyDevice(MsgPair msg);
virtual void actionSetIdentifyDevice(MsgPair msg);
virtual void actionSetResetDevice(MsgPair msg);
/// \cite RDM 10.3.2 The responder shall maintain reported status information until it has
/// been successfully delivered to the controller.
std::unordered_map<uint8_t, std::queue<StatusPtr>> queued_statuses; //!< outbound status queue
private:
bool identifying_ = false;
uint8_t status_reporting_threshold_;
uint16_t last_rx_pid_ = 0;
uint32_t ack_overflow_page_ = 0;
std::map<PID, Parameter*> parameters_; //!< parameters
std::vector<Sensor*> sensors_; //!< sensors
};
} // namespace RDM