122 lines
3.7 KiB
C
122 lines
3.7 KiB
C
|
/*
|
|||
|
dmp.h
|
|||
|
|
|||
|
Copyright (c) 2020 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 <cstdint>
|
|||
|
#include <memory>
|
|||
|
#include <vector>
|
|||
|
#include "pdu.h"
|
|||
|
|
|||
|
// Architecture for Control Networks – Device Management Protocol
|
|||
|
namespace ACN {
|
|||
|
namespace DMP {
|
|||
|
|
|||
|
using std::uint8_t;
|
|||
|
using std::uint32_t;
|
|||
|
using std::vector;
|
|||
|
using std::pair;
|
|||
|
using PDU::Block;
|
|||
|
|
|||
|
// 5.1.4 Address and Data Types
|
|||
|
enum data_type {
|
|||
|
SINGLE = 0b00, // 0
|
|||
|
RANGE = 0b01, // 1
|
|||
|
ARRAY = 0b10, // 2
|
|||
|
SERIES = 0b11 // 3
|
|||
|
};
|
|||
|
|
|||
|
enum address_length {
|
|||
|
ONE = 0b00, // 0
|
|||
|
TWO = 0b01, // 1
|
|||
|
FOUR = 0b10, // 2
|
|||
|
ZERO = 0b11 // 3 (reserved)
|
|||
|
};
|
|||
|
|
|||
|
struct address_type : PDU::pdu_header {
|
|||
|
bool z_reserved : 1; // Z
|
|||
|
bool relative : 1; // R
|
|||
|
data_type type : 2; // D1, D0
|
|||
|
uint8_t x_reserved : 2; // X1, X0
|
|||
|
address_length width : 2; // A1, A0
|
|||
|
address_type(uint8_t);
|
|||
|
};
|
|||
|
|
|||
|
// 5.1.5
|
|||
|
struct range {
|
|||
|
uint32_t address;
|
|||
|
uint32_t incriment;
|
|||
|
uint32_t count;
|
|||
|
range() {};
|
|||
|
range(PDU::Stream, data_type, address_length);
|
|||
|
private:
|
|||
|
uint32_t read(PDU::Stream, address_length);
|
|||
|
};
|
|||
|
|
|||
|
typedef pair<range, vector<uint8_t>> set_property;
|
|||
|
struct dmp_set_data : PDU::pdu_data {
|
|||
|
vector<set_property> properties;
|
|||
|
};
|
|||
|
|
|||
|
// 7 Response Messages
|
|||
|
enum failure_reason {
|
|||
|
NONSPECIFIC = 1, // Non-specific or non-DMP reason.
|
|||
|
NOT_PROPERTY = 2, // The address does not correspond to a property.
|
|||
|
WRITE_ONLY = 3, // The property’s value may not be read.
|
|||
|
NOT_WRITABLE = 4, // The property’s value may not be written.
|
|||
|
DATA_ERROR = 5, // The data does not correspond to the property.
|
|||
|
SUBSCIRPTION_NOT_SUPPORTED = 10, // Subscriptions on the specified property are not supported by the device.
|
|||
|
NO_SUBSCRIPTIONS_SUPPORTED = 11, // Subscriptions not supported on any property.
|
|||
|
INSUFFICIENT_RESOURCES = 12, // The component cannot support more subscriptions due to resource limitations
|
|||
|
UNAVAILABLE = 13 // The property’s value is not available due to restrictions imposed by device specific functionality (e.g., access permission mechanisms).
|
|||
|
};
|
|||
|
|
|||
|
// 13.1 Protocol Codes
|
|||
|
static const uint32_t DMP_PROTOCOL_ID = 2; // PDU protocol value
|
|||
|
|
|||
|
// 13.2 Message Codes
|
|||
|
static const uint8_t GET_PROPERTY = 1;
|
|||
|
static const uint8_t SET_PROPERTY = 2;
|
|||
|
static const uint8_t GET_PROPERTY_REPLY = 3;
|
|||
|
static const uint8_t EVENT = 4;
|
|||
|
static const uint8_t SUBSCRIBE = 7;
|
|||
|
static const uint8_t UNSUBSCRIBE = 8;
|
|||
|
static const uint8_t GET_PROPERTY_FAIL = 9;
|
|||
|
static const uint8_t SET_PROPERTY_FAIL = 10;
|
|||
|
static const uint8_t SUBSCRIBE_ACCEPT = 12;
|
|||
|
static const uint8_t SUBSCRIBE_REJECT = 13;
|
|||
|
static const uint8_t SYNC_EVENT = 17;
|
|||
|
|
|||
|
class Pdu
|
|||
|
: public PDU::Pdu
|
|||
|
{
|
|||
|
public:
|
|||
|
Pdu(PDU::Stream);
|
|||
|
private:
|
|||
|
void readSetData();
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
} // DMP
|
|||
|
} // ACN
|