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

Refactor printing of current configuration settings #84

144 changes: 98 additions & 46 deletions src/ConfigFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ typedef struct
Value_Type typeOfValue;
} Configuration_Item;

typedef struct
{
const char* QosString;
Ros_QoS_Profile_Setting QosValue;
} QoSMapping;

Configuration_Item Ros_ConfigFile_Items[] =
{
{ "ros_domain_id", &g_nodeConfigSettings.ros_domain_id, Value_Int },
Expand Down Expand Up @@ -122,6 +128,35 @@ Configuration_Item Ros_ConfigFile_Items[] =
{ "userlan_monitor_port", &g_nodeConfigSettings.userlan_monitor_port, Value_UserLanPort },
};

const QoSMapping Ros_QosMappings[] =
{
{ "sensor_data", ROS_QOS_PROFILE_SENSOR_DATA },
{ "parameters", ROS_QOS_PROFILE_PARAMETERS },
{ "default", ROS_QOS_PROFILE_DEFAULT },
{ "services", ROS_QOS_PROFILE_SERVICES},
{ "parameter events", ROS_QOS_PROFILE_PARAMETER_EVENTS},
{ "system Default", ROS_QOS_PROFILE_SYSTEM_DEFAULT},
};

const char* Ros_QosString(Ros_QoS_Profile_Setting profile)
{
switch (profile)
{
case ROS_QOS_PROFILE_SENSOR_DATA:
return "sensor_data";
case ROS_QOS_PROFILE_PARAMETERS:
return "parameters";
case ROS_QOS_PROFILE_DEFAULT:
return "default";
case ROS_QOS_PROFILE_SERVICES:
return "services";
case ROS_QOS_PROFILE_PARAMETER_EVENTS:
return "parameter events";
case ROS_QOS_PROFILE_SYSTEM_DEFAULT:
return "system Default";
}
}

void Ros_ConfigFile_SetAllDefaultValues()
{
//=========
Expand Down Expand Up @@ -303,22 +338,35 @@ void Ros_ConfigFile_CheckYamlEvent(yaml_event_t* event)
break;

case Value_Qos:
if (strcmp((char*)event->data.scalar.value, "sensor_data") == 0)
*(Ros_QoS_Profile_Setting*)activeItem->valueToSet = ROS_QOS_PROFILE_SENSOR_DATA;
else if (strcmp((char*)event->data.scalar.value, "default") == 0)
*(Ros_QoS_Profile_Setting*)activeItem->valueToSet = ROS_QOS_PROFILE_DEFAULT;
else
{
const char* QosProfileValue = (char*)event->data.scalar.value;
Ros_QoS_Profile_Setting enumValue = ROS_QOS_PROFILE_SENSOR_DATA;
bool valueFound = false;

// Finds enum value in the lookup table
for (size_t i = 0; i < sizeof(Ros_QosMappings) / sizeof(Ros_QosMappings[0]); i++)
{
mpSetAlarm(ALARM_CONFIGURATION_FAIL, "Invalid QOS in motoros2_config", SUBCODE_CONFIGURATION_INVALID_QOS_VALUE);
if (strncmp(Ros_QosMappings[i].Ros_QosString, QosProfileValue, strnlen(QosProfileValue)) == 0)
{
enumValue = Ros_QosMappings[i].QosValue;
valueFound = true;
break;
}
}

*(Ros_QoS_Profile_Setting*)activeItem->valueToSet = ROS_QOS_PROFILE_DEFAULT;
// In case the value is not found in the lookup table or is invalid
if (!valueFound)
{
mpSetAlarm(ALARM_CONFIGURATION_FAIL, "Invalid QOS in motoros2_config", SUBCODE_CONFIGURATION_INVALID_QOS_VALUE);
enumValue = ROS_QOS_PROFILE_DEFAULT;
*(Ros_QoS_Profile_Setting*)activeItem->valueToSet = enumValue;
Ros_Debug_BroadcastMsg(
"Falling back to '%s' profile for '%s': unrecognised profile: '%s'",
"default",
"Falling back to 'default' profile for '%s': unrecognised profile: '%s'",
(char*)activeItem->yamlKey,
(char*)event->data.scalar.value);
QosProfileValue);
}
break;
}

case Value_UserLanPort:
#if defined (DX200) || defined (FS100)
Expand Down Expand Up @@ -697,6 +745,45 @@ void Ros_ConfigFile_ValidateNonCriticalSettings()
}
}

void Ros_ConfigFile_PrintActiveConfiguration()
{
Ros_Debug_BroadcastMsg("Config: ros_domain_id = %d", g_nodeConfigSettings.ros_domain_id);
Ros_Debug_BroadcastMsg("Config: node_name = '%s'", g_nodeConfigSettings.node_name);
Ros_Debug_BroadcastMsg("Config: node_namespace = '%s'", g_nodeConfigSettings.node_namespace);
Ros_Debug_BroadcastMsg("Config: remap_rules = '%s'", g_nodeConfigSettings.remap_rules);
Ros_Debug_BroadcastMsg("Config: agent_ip_address = '%s'", g_nodeConfigSettings.agent_ip_address);
Ros_Debug_BroadcastMsg("Config: agent_port_number = '%s'", g_nodeConfigSettings.agent_port_number);
Ros_Debug_BroadcastMsg("Config: sync_timeclock_with_agent = %d", g_nodeConfigSettings.sync_timeclock_with_agent);
Ros_Debug_BroadcastMsg("Config: namespace_tf = %d", g_nodeConfigSettings.namespace_tf);
Ros_Debug_BroadcastMsg("Config: publish_tf = %d", g_nodeConfigSettings.publish_tf);
Ros_Debug_BroadcastMsg("List of configured joint names:");
for (int i = 0; i < MAX_CONTROLLABLE_GROUPS; i += 1)
{
Ros_Debug_BroadcastMsg("---");
for (int j = 0; j < MP_GRP_AXES_NUM; j += 1)
{
if (strlen(g_nodeConfigSettings.joint_names[(i * MP_GRP_AXES_NUM) + j]) > 0)
Ros_Debug_BroadcastMsg(g_nodeConfigSettings.joint_names[(i * MP_GRP_AXES_NUM) + j]);
else
Ros_Debug_BroadcastMsg("x");
}
}
Ros_Debug_BroadcastMsg("---");
Ros_Debug_BroadcastMsg("Config: logging.log_to_stdout = %d", g_nodeConfigSettings.log_to_stdout);
Ros_Debug_BroadcastMsg("Config: update_periods.executor_sleep_period = %d", g_nodeConfigSettings.executor_sleep_period);
Ros_Debug_BroadcastMsg("Config: update_periods.action_feedback_publisher_period = %d", g_nodeConfigSettings.action_feedback_publisher_period);
Ros_Debug_BroadcastMsg("Config: update_periods.controller_status_monitor_period = %d", g_nodeConfigSettings.controller_status_monitor_period);
Ros_Debug_BroadcastMsg("Config: publisher_qos.robot_status = '%s'", Ros_QosString(g_nodeConfigSettings.qos_robot_status));
Ros_Debug_BroadcastMsg("Config: publisher_qos.joint_states = '%s'", Ros_QosString(g_nodeConfigSettings.qos_joint_states));
Ros_Debug_BroadcastMsg("Config: publisher_qos.tf = '%s'", Ros_QosString(g_nodeConfigSettings.qos_tf));
Ros_Debug_BroadcastMsg("Config: tf_frame_prefix = '%s'", g_nodeConfigSettings.tf_frame_prefix);
Ros_Debug_BroadcastMsg("Config: stop_motion_on_disconnect = %d", g_nodeConfigSettings.stop_motion_on_disconnect);
Ros_Debug_BroadcastMsg("Config: inform_job_name = '%s'", g_nodeConfigSettings.inform_job_name);
Ros_Debug_BroadcastMsg("Config: allow_custom_inform_job = %d", g_nodeConfigSettings.allow_custom_inform_job);
Ros_Debug_BroadcastMsg("Config: userlan_monitor_enabled = %d", g_nodeConfigSettings.userlan_monitor_enabled);
Ros_Debug_BroadcastMsg("Config: userlan_monitor_port = %d", g_nodeConfigSettings.userlan_monitor_port);
gavanderhoorn marked this conversation as resolved.
Show resolved Hide resolved
}

void Ros_ConfigFile_Parse()
{
BOOL bAlarmOnce = TRUE;
Expand Down Expand Up @@ -776,42 +863,7 @@ void Ros_ConfigFile_Parse()

Ros_ConfigFile_ValidateCriticalSettings();
Ros_ConfigFile_ValidateNonCriticalSettings();

Ros_Debug_BroadcastMsg("Config: ros_domain_id = %d", g_nodeConfigSettings.ros_domain_id);
Ros_Debug_BroadcastMsg("Config: node_name = %s", g_nodeConfigSettings.node_name);
Ros_Debug_BroadcastMsg("Config: node_namespace = %s", g_nodeConfigSettings.node_namespace);
Ros_Debug_BroadcastMsg("Config: remap_rules = %s", g_nodeConfigSettings.remap_rules);
Ros_Debug_BroadcastMsg("Config: agent_ip_address = %s", g_nodeConfigSettings.agent_ip_address);
Ros_Debug_BroadcastMsg("Config: agent_port_number = %s", g_nodeConfigSettings.agent_port_number);
Ros_Debug_BroadcastMsg("Config: sync_timeclock_with_agent = %d", g_nodeConfigSettings.sync_timeclock_with_agent);
Ros_Debug_BroadcastMsg("Config: namespace_tf = %d", g_nodeConfigSettings.namespace_tf);
Ros_Debug_BroadcastMsg("Config: publish_tf = %d", g_nodeConfigSettings.publish_tf);
Ros_Debug_BroadcastMsg("List of configured joint names:");
for (int i = 0; i < MAX_CONTROLLABLE_GROUPS; i += 1)
{
Ros_Debug_BroadcastMsg("---");
for (int j = 0; j < MP_GRP_AXES_NUM; j += 1)
{
if (strlen(g_nodeConfigSettings.joint_names[(i * MP_GRP_AXES_NUM) + j]) > 0)
Ros_Debug_BroadcastMsg(g_nodeConfigSettings.joint_names[(i * MP_GRP_AXES_NUM) + j]);
else
Ros_Debug_BroadcastMsg("x");
}
}
Ros_Debug_BroadcastMsg("---");
Ros_Debug_BroadcastMsg("Config: log_to_stdout = %d", g_nodeConfigSettings.log_to_stdout);
Ros_Debug_BroadcastMsg("Config: executor_sleep_period = %d", g_nodeConfigSettings.executor_sleep_period);
Ros_Debug_BroadcastMsg("Config: action_feedback_publisher_period = %d", g_nodeConfigSettings.action_feedback_publisher_period);
Ros_Debug_BroadcastMsg("Config: controller_status_monitor_period = %d", g_nodeConfigSettings.controller_status_monitor_period);
Ros_Debug_BroadcastMsg("Config: robot_status = %d", g_nodeConfigSettings.qos_robot_status);
Ros_Debug_BroadcastMsg("Config: joint_states = %d", g_nodeConfigSettings.qos_joint_states);
Ros_Debug_BroadcastMsg("Config: tf = %d", g_nodeConfigSettings.qos_tf);
Ros_Debug_BroadcastMsg("Config: tf_frame_prefix = %s", g_nodeConfigSettings.tf_frame_prefix);
Ros_Debug_BroadcastMsg("Config: stop_motion_on_disconnect = %d", g_nodeConfigSettings.stop_motion_on_disconnect);
Ros_Debug_BroadcastMsg("Config: inform_job_name = %s", g_nodeConfigSettings.inform_job_name);
Ros_Debug_BroadcastMsg("Config: allow_custom_inform_job = %d", g_nodeConfigSettings.allow_custom_inform_job);
Ros_Debug_BroadcastMsg("Config: userlan_monitor_enabled = %d", g_nodeConfigSettings.userlan_monitor_enabled);
Ros_Debug_BroadcastMsg("Config: userlan_monitor_port = %d", g_nodeConfigSettings.userlan_monitor_port);
Ros_ConfigFile_PrintActiveConfiguration();
}

rmw_qos_profile_t const* const Ros_ConfigFile_To_Rmw_Qos_Profile(Ros_QoS_Profile_Setting val)
Expand Down