in webserver_pkg/webserver_pkg/vehicle_control.py [0:0]
def api_set_start_stop():
"""API to call the enable_state service to start and stop the vehicle.
Returns:
dict: Execution status if the API call was successful and error
reason if failed.
"""
webserver_node = webserver_publisher_node.get_webserver_node()
start_stop = request.json.get("start_stop")
if start_stop is None:
return jsonify({"success": False, "reason": "start_stop must be set."})
webserver_node.get_logger().info(f"Changed the enable state to {start_stop}")
start_stop_state = False if start_stop == "stop" else True
try:
enable_state_req = EnableStateSrv.Request()
enable_state_req.is_active = start_stop_state
enable_state_res = call_service_sync(webserver_node.enable_state_cli, enable_state_req)
if enable_state_res and (enable_state_res.error == 0):
return jsonify({"success": True})
else:
return jsonify({"success": False, "reason": "Error"})
except Exception as ex:
webserver_node.get_logger().error(f"Unable to reach enable state server: {ex}")
return jsonify({"success": False,
"reason": "Unable to reach enable state server."})