NanoOcp
Minimal AES70 / OCP.1 TCP client/server library for d&b Soundscape devices
Loading...
Searching...
No Matches
NanoOcp1::Ocp1Message Class Referenceabstract

Abstract base class for all OCP.1 protocol messages. More...

#include <Ocp1Message.h>

+ Inheritance diagram for NanoOcp1::Ocp1Message:
+ Collaboration diagram for NanoOcp1::Ocp1Message:

Public Types

enum  MessageType {
  Command = 0 ,
  CommandResponseRequired = 1 ,
  Notification = 2 ,
  Response = 3 ,
  KeepAlive = 4
}
 OCP.1 message type codes as defined in AES70. More...
 

Public Member Functions

 Ocp1Message (std::uint8_t msgType, const ByteVector &parameterData)
 
virtual ~Ocp1Message ()=default
 
std::uint8_t GetMessageType () const
 
ByteVector GetParameterData () const
 
virtual ByteVector GetSerializedData ()=0
 

Static Public Member Functions

static std::unique_ptr< Ocp1MessageUnmarshalOcp1Message (const ByteVector &receivedData)
 

Protected Attributes

Ocp1Header m_header
 
ByteVector m_parameterData
 

Static Protected Attributes

static std::uint32_t m_nextHandle = 2
 

Detailed Description

Abstract base class for all OCP.1 protocol messages.

Every OCP.1 frame starts with a 10-byte Ocp1Header (sync byte 0x3b, protocol version 1, message size, message type, message count) followed by type-specific payload bytes. Ocp1Message stores both and provides GetSerializedData() to produce the complete binary frame for transmission.

Message flow in an OCA session

Client Device
│──Ocp1CommandResponseRequired(AddSub)──►│ subscribe to a property
│◄──────────────Ocp1Response(OK)─────────│
│──Ocp1CommandResponseRequired(GetValue)─►│ read current value
│◄──────────────Ocp1Response(value)───────│
│◄──────────────Ocp1Notification──────────│ value changed (unsolicited)
│──Ocp1CommandResponseRequired(SetValue)─►│ write new value
│◄──────────────Ocp1Response(OK)─────────│
│──Ocp1KeepAlive──────────────────────────►│ heartbeat
│◄──────────────Ocp1KeepAlive─────────────│

Receiving messages

UnmarshalOcp1Message() is the factory entry point. Pass the raw bytes received from the socket and it returns a typed unique_ptr<Ocp1Message> (or nullptr on parse error). Dispatch on GetMessageType():

auto msg = Ocp1Message::UnmarshalOcp1Message(rawBytes);
if (!msg) return;
switch (msg->GetMessageType())
{
{
auto* n = static_cast<Ocp1Notification*>(msg.get());
// match n->GetEmitterOno() against subscription table
break;
}
{
auto* r = static_cast<Ocp1Response*>(msg.get());
// match r->GetResponseHandle() against pending command handles
break;
}
case Ocp1Message::KeepAlive: break; // no action needed
default: break;
}
@ Response
Device reply to a CommandResponseRequired.
@ KeepAlive
Heartbeat for connection supervision.
@ Notification
Unsolicited property change from device to client.
static std::unique_ptr< Ocp1Message > UnmarshalOcp1Message(const ByteVector &receivedData)

Definition at line 304 of file Ocp1Message.h.

Member Enumeration Documentation

◆ MessageType

OCP.1 message type codes as defined in AES70.

Value Name Direction Description
0 Command Client→Device Fire-and-forget; no response expected.
1 CommandResponseRequired Client→Device Command that expects an Ocp1Response with a matching handle.
2 Notification Device→Client Unsolicited property-change event (requires prior AddSubscription).
3 Response Device→Client Reply to a CommandResponseRequired; carries status and return value.
4 KeepAlive Both Heartbeat for connection supervision; carries heartbeat interval.
Enumerator
Command 

Fire-and-forget command; no response expected.

CommandResponseRequired 

Command that expects a Response with a matching handle.

Notification 

Unsolicited property change from device to client.

Response 

Device reply to a CommandResponseRequired.

KeepAlive 

Heartbeat for connection supervision.

Definition at line 318 of file Ocp1Message.h.

Constructor & Destructor Documentation

◆ Ocp1Message()

NanoOcp1::Ocp1Message::Ocp1Message ( std::uint8_t  msgType,
const ByteVector parameterData 
)
inline

Class constructor.

Definition at line 330 of file Ocp1Message.h.

◆ ~Ocp1Message()

virtual NanoOcp1::Ocp1Message::~Ocp1Message ( )
virtualdefault

Class destructor.

Member Function Documentation

◆ GetMessageType()

std::uint8_t NanoOcp1::Ocp1Message::GetMessageType ( ) const
inline

Gets the type of the OCA message. (i.e. Notification, KeepAlive, etc).

Returns
Type of OCA message.

Definition at line 347 of file Ocp1Message.h.

References NanoOcp1::Ocp1Header::GetMessageType(), and m_header.

◆ GetParameterData()

ByteVector NanoOcp1::Ocp1Message::GetParameterData ( ) const
inline

Returns a vector of bytes representing the parameter data contained in the message.

Returns
A vector containing the OCA message including header.

Definition at line 357 of file Ocp1Message.h.

References m_parameterData.

Referenced by NanoOcp1Demo::MainComponent::OnOcp1MessageReceived().

◆ GetSerializedData()

virtual ByteVector NanoOcp1::Ocp1Message::GetSerializedData ( )
pure virtual

Returns a vector of bytes representing the binary contents of the complete message. Must be reimplemented for each message type.

Returns
A vector containing the OCA message including header.

Implemented in NanoOcp1::Ocp1CommandResponseRequired, NanoOcp1::Ocp1Response, NanoOcp1::Ocp1Notification, and NanoOcp1::Ocp1KeepAlive.

◆ UnmarshalOcp1Message()

std::unique_ptr< Ocp1Message > NanoOcp1::Ocp1Message::UnmarshalOcp1Message ( const ByteVector receivedData)
static

Factory method which creates a new Ocp1Message object based on a vector<std::uint8_t>.

Parameters
[in]receivedDataVector containing the received OCA message.
Returns
A unique pointer to the unmarshaled Ocp1Message object.

Definition at line 174 of file Ocp1Message.cpp.

References Command, CommandResponseRequired, NanoOcp1::Ocp1Header::GetMessageType(), NanoOcp1::Ocp1Header::IsValid(), KeepAlive, Notification, NanoOcp1::Ocp1Header::Ocp1HeaderSize, NanoOcp1::ReadUint16(), NanoOcp1::ReadUint32(), and Response.

Referenced by NanoOcp1Demo::MainComponent::OnOcp1MessageReceived().

Member Data Documentation

◆ m_header

◆ m_nextHandle

std::uint32_t NanoOcp1::Ocp1Message::m_nextHandle = 2
staticprotected

◆ m_parameterData


The documentation for this class was generated from the following files: