Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCP-008-01: NMOS Receiver Status support #394

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Development/nmos-cpp-node/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int main(int argc, char* argv[])
.on_request_authorization_code(nmos::experimental::make_request_authorization_code_handler(gate)); // may be omitted, only required for OAuth client which is using the Authorization Code Flow to obtain the access token
}

nmos::experimental::control_protocol_state control_protocol_state(node_implementation.control_protocol_property_changed);
nmos::experimental::control_protocol_state control_protocol_state(node_implementation.get_lost_packet_counters, node_implementation.get_late_packet_counters, node_implementation.reset_packet_counters, node_implementation.control_protocol_property_changed);
if (0 <= nmos::fields::control_protocol_ws_port(node_model.settings))
{
node_implementation
Expand Down
40 changes: 39 additions & 1 deletion Development/nmos-cpp-node/node_implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,41 @@ nmos::control_protocol_property_changed_handler make_node_implementation_control
};
}

// Example Receiver Status Monitor callback for get_lost_packets method
nmos::get_lost_packet_counters_handler make_node_implementation_get_lost_packet_counters_handler()
{
return [&]()
{
// Implement polling of lost packet count here
uint16_t lost_packet_count(0);
return nmos::details::make_nc_method_result({ nmos::nc_method_status::ok }, lost_packet_count);
};
}

// Example Receiver Status Monitor callback for get_late_packets method
nmos::get_late_packet_counters_handler make_node_implementation_get_late_packet_counters_handler()
{
return [&]()
{
// Implement polling of late packet count here
uint16_t late_packet_count(0);
return nmos::details::make_nc_method_result({ nmos::nc_method_status::ok }, late_packet_count);
};
}

// Example Receiver Status Monitor callback for reset_packet_counters method
nmos::reset_packet_counters_handler make_node_implementation_reset_packet_counters_handler()
{
return [&]()
{
// Implement reset of lost and late packet counters
return nmos::details::make_nc_method_result({ nmos::nc_method_status::ok });
};
}




namespace impl
{
nmos::interlace_mode get_interlace_mode(const nmos::settings& settings)
Expand Down Expand Up @@ -1868,5 +1903,8 @@ nmos::experimental::node_implementation make_node_implementation(nmos::node_mode
.on_connection_activated(make_node_implementation_connection_activation_handler(model, gate))
.on_validate_channelmapping_output_map(make_node_implementation_map_validator()) // may be omitted if not required
.on_channelmapping_activated(make_node_implementation_channelmapping_activation_handler(gate))
.on_control_protocol_property_changed(make_node_implementation_control_protocol_property_changed_handler(gate)); // may be omitted if IS-12 not required
.on_control_protocol_property_changed(make_node_implementation_control_protocol_property_changed_handler(gate)) // may be omitted if IS-12 not required
.on_get_lost_packet_counters(make_node_implementation_get_lost_packet_counters_handler())
.on_get_late_packet_counters(make_node_implementation_get_late_packet_counters_handler())
.on_reset_packet_counters(make_node_implementation_reset_packet_counters_handler());
}
4 changes: 2 additions & 2 deletions Development/nmos/api_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ namespace nmos
{ U("nc_manager"), nmos::types::nc_manager },
{ U("nc_device_manager"), nmos::types::nc_device_manager },
{ U("nc_class_manager"), nmos::types::nc_class_manager },
{ U("nc_status_monitor"), nmos::types::nc_status_monitor },
{ U("nc_receiver_monitor"), nmos::types::nc_receiver_monitor },
{ U("nc_receiver_monitor_protected"), nmos::types::nc_receiver_monitor_protected },
{ U("nc_ident_beacon"), nmos::types::nc_ident_beacon }
};
return types_from_resourceType.at(resourceType);
Expand All @@ -195,8 +195,8 @@ namespace nmos
{ nmos::types::nc_manager, U("nc_manager") },
{ nmos::types::nc_device_manager, U("nc_device_manager") },
{ nmos::types::nc_class_manager, U("nc_class_manager") },
{ nmos::types::nc_status_monitor, U("nc_status_monitor") },
{ nmos::types::nc_receiver_monitor, U("nc_receiver_monitor") },
{ nmos::types::nc_receiver_monitor_protected, U("nc_receiver_monitor_protected") },
{ nmos::types::nc_ident_beacon, U("nc_ident_beacon") }
};
return resourceTypes_from_type.at(type);
Expand Down
8 changes: 4 additions & 4 deletions Development/nmos/control_protocol_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ namespace nmos
// update receiver-monitor's connectionStatus and payloadStatus properties

const auto active = nmos::fields::master_enable(nmos::fields::endpoint_active(connection_resource.data));
const web::json::value connection_status = active ? nc_connection_status::connected : nc_connection_status::disconnected;
const web::json::value payload_status = active ? nc_payload_status::payload_ok : nc_payload_status::undefined;
const web::json::value connection_status = active ? nc_connection_status::healthy : nc_connection_status::inactive;
const web::json::value stream_status = active ? nc_stream_status::healthy : nc_stream_status::inactive;

// hmm, maybe updating connectionStatusMessage and payloadStatusMessage too

const auto property_changed_event = make_property_changed_event(nmos::fields::nc::oid(found->data),
{
{ nc_receiver_monitor_connection_status_property_id, nc_property_change_type::type::value_changed, connection_status },
{ nc_receiver_monitor_payload_status_property_id, nc_property_change_type::type::value_changed, payload_status }
{ nc_receiver_monitor_stream_status_property_id, nc_property_change_type::type::value_changed, stream_status }
});

modify_control_protocol_resource(resources, found->id, [&](nmos::resource& resource)
{
resource.data[nmos::fields::nc::connection_status] = connection_status;
resource.data[nmos::fields::nc::payload_status] = payload_status;
resource.data[nmos::fields::nc::stream_status] = stream_status;

}, property_changed_event);
}
Expand Down
6 changes: 6 additions & 0 deletions Development/nmos/control_protocol_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ namespace nmos
// this callback should not throw exceptions, as the relevant property will already has been changed and those changes will not be rolled back
typedef std::function<void(const nmos::resource& resource, const utility::string_t& property_name, int index)> control_protocol_property_changed_handler;

// Receiver status callbacks
// these callbacks should not throw exceptions
typedef std::function<web::json::value(void)> get_lost_packet_counters_handler;
typedef std::function<web::json::value(void)> get_late_packet_counters_handler;
typedef std::function<web::json::value(void)> reset_packet_counters_handler;

namespace experimental
{
// control method handler definition
Expand Down
19 changes: 19 additions & 0 deletions Development/nmos/control_protocol_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,23 @@ namespace nmos

return details::make_nc_method_result_error({ nc_method_status::parameter_error }, U("name not found"));
}

// NcReceiverMonitor methods
web::json::value get_lost_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&)
{
// this will need to be defined in a user defined handler
return details::make_nc_method_result({ nc_method_status::ok });
}

web::json::value get_late_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&)
{
// this will need to be defined in a user defined handler
return details::make_nc_method_result({ nc_method_status::ok });
}

web::json::value reset_packet_counters(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&)
{
// this will need to be defined in a user defined handler
return details::make_nc_method_result({ nc_method_status::ok });
}
}
8 changes: 8 additions & 0 deletions Development/nmos/control_protocol_methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ namespace nmos
web::json::value get_control_class(nmos::resources&, const nmos::resource&, const web::json::value& arguments, bool is_deprecated, get_control_protocol_class_descriptor_handler get_control_protocol_class_descriptor, slog::base_gate& gate);
// Get a single datatype descriptor
web::json::value get_datatype(nmos::resources&, const nmos::resource&, const web::json::value& arguments, bool is_deprecated, get_control_protocol_datatype_descriptor_handler get_control_protocol_datatype, slog::base_gate& gate);

// NcReceiverMonitor methods implementation
// Gets the lost packets
web::json::value get_lost_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&);
// Gets the late packets
web::json::value get_late_packets(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&);
// Resets the packet counters
web::json::value reset_packet_counters(nmos::resources&, const nmos::resource&, const web::json::value&, bool, slog::base_gate&);
}

#endif
Loading
Loading