def verify_sensor_connection()

in deepracer_offroad_ws/webserver_pkg/webserver_pkg/models.py [0:0]


def verify_sensor_connection(sensors, sensor_resp):
    """Helper function to verify if the required sensors that the model trained with are
       connected to the vehicle.

    Args:
        sensors (list): List of SensorInputKeys enum values
        sensor_resp (SensorStatusCheckSrv.Response): Sensor data status for camera and
                                                     LiDAR sensors connected to the vehicle.

    Returns:
        tuple: A tuple of error code and error message.
    """
    webserver_node = webserver_publisher_node.get_webserver_node()
    required_sensors_not_connected = []
    try:
        if (constants.SensorInputKeys.SECTOR_LIDAR in sensors
           or constants.SensorInputKeys.LIDAR in sensors) and sensor_resp.lidar_status == 1:
            required_sensors_not_connected.append(
                constants.SENSOR_INPUT_NAME_MAPPING[constants.SensorInputKeys.LIDAR])

        if constants.SensorInputKeys.STEREO_CAMERAS in sensors \
           and sensor_resp.stereo_camera_status == 1:
            required_sensors_not_connected.append(
                constants.SENSOR_INPUT_NAME_MAPPING[constants.SensorInputKeys.STEREO_CAMERAS])

        if (constants.SensorInputKeys.FRONT_FACING_CAMERA in sensors
           or constants.SensorInputKeys.observation in sensors
           or constants.SensorInputKeys.LEFT_CAMERA in sensors) \
           and sensor_resp.single_camera_status == 1:
            required_sensors_not_connected.append(
                constants.SENSOR_INPUT_NAME_MAPPING[constants.SensorInputKeys.FRONT_FACING_CAMERA])

    except Exception as ex:
        webserver_node.get_logger().error(f"Unable to verify sensor connections: {ex}")
        return 1, "Unable to verify sensor connections."
    finally:
        if len(required_sensors_not_connected) > 0:
            return 1, (f"Check the connections for the {', '.join(required_sensors_not_connected)} "
                       f"{'sensors' if len(required_sensors_not_connected) > 1 else 'sensor'}")
        return 0, ""