1
0
Fork 0

sensor PIDs

This commit is contained in:
Kevin Matz 2021-08-10 00:56:43 -04:00
parent 0202dc9422
commit 1bd99631a9
4 changed files with 289 additions and 0 deletions

View File

@ -138,6 +138,32 @@ Device::Device(Device* parent)
&Device::actionSetDmxStartAddress,
this, std::placeholders::_1,
std::placeholders::_2));
/// 10.7.1 Get Sensor Definition (SENSOR_DEFINITION)
/// This parameter is used to retrieve the definition of a specific sensor.
parameters_.try_emplace(SENSOR_DEFINITION, new Parameter());
parameters_.at(SENSOR_DEFINITION)->getAction(std::bind(
&Device::actionGetSensorDefinition,
this, std::placeholders::_1,
std::placeholders::_2));
/// 10.7.2 Get/Set Sensor (SENSOR_VALUE)
/// This parameter shall be used to retrieve or reset sensor data.
parameters_.try_emplace(SENSOR_VALUE, new Parameter());
parameters_.at(SENSOR_VALUE)->getAction(std::bind(
&Device::actionGetSensorValue,
this, std::placeholders::_1,
std::placeholders::_2));
parameters_.at(SENSOR_VALUE)->setAction(std::bind(
&Device::actionSetSensorValue,
this, std::placeholders::_1,
std::placeholders::_2));
/// 10.7.3 Record Sensors (RECORD_SENSORS)
/// This parameter instructs devices such as dimming racks that monitor load
/// changes to store the current value for monitoring sensor changes.
parameters_.try_emplace(RECORD_SENSORS, new Parameter());
parameters_.at(RECORD_SENSORS)->setAction(std::bind(
&Device::actionSetRecordSensors,
this, std::placeholders::_1,
std::placeholders::_2));
/// 10.11.1 Get/Set Identify Device (IDENTIFY_DEVICE)
/// This parameter is used for the user to physically identify the device
/// represented by the UID.
@ -560,6 +586,151 @@ void Device::actionSetDmxStartAddress(const Message *message, Message *response)
}
/**
* @brief Device::actionGetSensorDefinition
* @param message
* @param response
*/
void Device::actionGetSensorDefinition(const Message *message, Message *response)
{
if (message->data()->size() != 1)
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_FORMAT_ERROR);
return;
}
uint8_t index = message->data()->front();
if (index == 0xFF || index >= sensors_.size())
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_DATA_OUT_OF_RANGE);
return;
}
auto sensor = sensors_.at(index);
response->responseType = RESPONSE_TYPE_ACK;
response->appendData<uint8_t>(index);
response->appendData<uint8_t>(sensor->type);
response->appendData<uint8_t>(sensor->unit);
response->appendData<uint8_t>(sensor->unitPrefix);
response->appendData<int16_t>(sensor->minLimit);
response->appendData<int16_t>(sensor->maxLimit);
response->appendData<int16_t>(sensor->minNominal);
response->appendData<int16_t>(sensor->maxNominal);
response->appendData<uint8_t>(sensor->recordedValueSupport);
for (size_t i = 0; i < sensor->description.size(); i++)
{
if (i > 32)
break;
response->appendData<char>(sensor->description.at(i));
}
}
/**
* @brief Device::actionGetSensorValue
* @param message
* @param response
*/
void Device::actionGetSensorValue(const Message *message, Message *response)
{
if (message->data()->size() != 1)
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_FORMAT_ERROR);
return;
}
uint8_t index = message->data()->front();
if (index == 0xFF || index >= sensors_.size())
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_DATA_OUT_OF_RANGE);
return;
}
auto sensor = sensors_.at(index);
response->responseType = RESPONSE_TYPE_ACK;
response->appendData<uint8_t>(index);
response->appendData<int16_t>(sensor->value());
response->appendData<int16_t>(sensor->minimum());
response->appendData<int16_t>(sensor->maximum());
response->appendData<int16_t>(sensor->saved());
}
/**
* @brief Device::actionSetSensorValue
* @param message
* @param response
*/
void Device::actionSetSensorValue(const Message *message, Message *response)
{
if (message->data()->size() != 1)
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_FORMAT_ERROR);
return;
}
uint8_t index = message->data()->front();
if (index >= sensors_.size() && index != 0xFF)
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_DATA_OUT_OF_RANGE);
return;
}
int16_t val = 0, min = 0, max = 0, mem = 0;
if (index == 0xFF)
for ( Sensor * s : sensors_ )
s->clearMemory();
else
{
auto sensor = sensors_.at(index);
sensor->clearMemory();
val = sensor->value();
min = sensor->minimum();
max = sensor->maximum();
mem = sensor->saved();
}
response->responseType = RESPONSE_TYPE_ACK;
response->appendData<uint8_t>(index);
response->appendData<int16_t>(val);
response->appendData<int16_t>(min);
response->appendData<int16_t>(max);
response->appendData<int16_t>(mem);
}
/**
* @brief Device::actionSetRecordSensors
* @param message
* @param response
*/
void Device::actionSetRecordSensors(const Message *message, Message *response)
{
if (message->data()->size() != 1)
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_FORMAT_ERROR);
return;
}
uint8_t index = message->data()->front();
if (index >= sensors_.size() && index != 0xFF)
{
response->responseType = RESPONSE_TYPE_NACK_REASON;
response->appendData<uint16_t>(NR_DATA_OUT_OF_RANGE);
return;
}
if (index == 0xFF)
for ( Sensor* s : sensors_ )
s->save();
else
sensors_.at(index)->save();
response->responseType = RESPONSE_TYPE_ACK;
}
/**
* @brief Device::actionGetIdentifyDevice
* @param message

View File

@ -78,6 +78,10 @@ protected:
void actionGetDmxPersonalityDesc (const Message *message, Message *response);
void actionGetDmxStartAddress (const Message *message, Message *response);
void actionSetDmxStartAddress (const Message *message, Message *response);
void actionGetSensorDefinition (const Message *message, Message *response);
void actionGetSensorValue (const Message *message, Message *response);
void actionSetSensorValue (const Message *message, Message *response);
void actionSetRecordSensors (const Message *message, Message *response);
void actionGetIdentifyDevice (const Message *message, Message *response);
void actionSetIdentifyDevice (const Message *message, Message *response);

View File

@ -23,12 +23,91 @@
*/
#include "sensor.h"
#include "rdm.h"
namespace RDM {
/**
* @brief Sensor::Sensor
*/
Sensor::Sensor()
: type(SENS_OTHER)
, unit(UNITS_NONE)
, unitPrefix(PREFIX_NONE)
, minLimit(-32768)
, maxLimit(32767)
, minNominal(-32768)
, maxNominal(32767)
, recordedValue(true)
, minMaxDetectedValue(true)
, reserved(0)
, description("Null Sensor")
, min_(32767)
, max_(-32768)
, memory_(0)
, value_(0)
{
}
/**
* @brief Sensor::setValue
* @param val
*/
void Sensor::setValue(int16_t &val)
{
if (val < min_)
min_ = val;
if (val > max_)
max_ = val;
value_ = val;
}
/**
* @brief Sensor::minimum
* @return
*/
int16_t Sensor::minimum() const
{
if (!minMaxDetectedValue)
return 0;
return min_;
}
/**
* @brief Sensor::maximum
* @return
*/
int16_t Sensor::maximum() const
{
if (!minMaxDetectedValue)
return 0;
return max_;
}
/**
* @brief Sensor::saved
* @return
*/
int16_t Sensor::saved() const
{
if (!recordedValue)
return 0;
return memory_;
}
/**
* @brief Sensor::resetMinMax
*/
void Sensor::clearMemory()
{
min_ = value_;
max_ = value_;
memory_ = value_;
}
} // namespace RDM

View File

@ -23,12 +23,47 @@
*/
#pragma once
#include <cstdint>
#include <string>
namespace RDM {
class Sensor
{
public:
Sensor();
virtual ~Sensor() {};
uint8_t type;
uint8_t unit;
uint8_t unitPrefix;
int16_t minLimit;
int16_t maxLimit;
int16_t minNominal;
int16_t maxNominal;
union {
uint8_t recordedValueSupport;
struct {
bool recordedValue : 1;
bool minMaxDetectedValue : 1;
uint8_t reserved : 6;
};
};
std::string description;
void setValue(int16_t &val);
int16_t value() const { return value_; }
int16_t minimum() const;
int16_t maximum() const;
int16_t saved() const;
void save() { memory_ = value_; }
void clearMemory();
private:
int16_t min_;
int16_t max_;
int16_t memory_;
int16_t value_;
};
} // namespace RDM