1 from __future__
import print_function
13 from std_srvs.srv
import Trigger
14 from rosmon_msgs.srv
import StartStop, StartStopRequest
16 from .utils
import is_tool, write_flush, query_yes_no
20 bootloader_path, firmware_path, firmware_version="<unknown>", check_version=True
22 write_flush(
"--> Checking if stm32loader is installed.. ")
29 "ERROR: Cannot find the stm32loader tool. " 30 "Make sure the python3-stm32loader package is installed." 34 write_flush(
"--> Checking if ROS Master is online.. ")
36 if rosgraph.is_master_online():
44 "ROS Master is not running. " 45 "Will not be able to check the current firmware version." 47 if not query_yes_no(
"Are you sure you want to continue?", default=
"no"):
52 rospy.init_node(
"firmware_flasher", anonymous=
True)
56 write_flush(
"--> Checking if rosserial node is active.. ")
58 if "/serial_node" in rosnode.get_node_names():
60 serial_node_active =
True 63 serial_node_active =
False 66 "Rosserial node is not active. " 67 "Will not be able to check the current firmware version." 69 if not query_yes_no(
"Are you sure you want to continue?", default=
"no"):
72 current_firmware_version =
"<unknown>" 74 if check_version
and master_online
and serial_node_active:
75 write_flush(
"--> Checking the current firmware version.. ")
77 if "/core2/get_firmware_version" in rosservice.get_service_list():
78 get_firmware_version = rospy.ServiceProxy(
79 "/core2/get_firmware_version", Trigger
81 current_firmware_version = get_firmware_version().message
86 "WARNING: Could not get the current firmware version: " 87 "/core2/get_firmware_version service is not available." 90 print(
"Current firmware version: {}".format(current_firmware_version))
91 print(
"Version of the firmware to flash: {}".format(firmware_version))
93 if master_online
and serial_node_active:
94 write_flush(
"--> Checking if rosmon service is available.. ")
96 if "/rosmon/start_stop" in rosservice.get_service_list():
97 start_stop = rospy.ServiceProxy(
"/rosmon/start_stop", StartStop)
99 rosmon_available =
True 102 rosmon_available =
False 107 if master_online
and serial_node_active:
110 start_stop(
"serial_node",
"", StartStopRequest.STOP)
115 "WARNING: rosserial node is active, but rosmon service " 116 "is not available. You have to manually stop rosserial node " 117 "before flashing the firmware." 122 print(
"--> Disabling flash write protection")
123 subprocess.check_call(
"stm32loader -c rpi -f F4 -W", shell=
True)
125 print(
"--> Erasing flash and flashing bootloader")
126 subprocess.check_call(
127 "stm32loader -c rpi -f F4 -e -w -v {}".format(bootloader_path), shell=
True 130 print(
"--> Flashing firmware")
131 subprocess.check_call(
132 "stm32loader -c rpi -f F4 -a 0x08010000 -w -v {}".format(firmware_path),
136 print(
"Flashing completed!")
138 if master_online
and serial_node_active:
141 start_stop(
"serial_node",
"", StartStopRequest.START)
144 print(
"You can now start the rosserial node.")
def write_flush(msg)
Write a message to standard output and flush the buffer.
def is_tool(name)
Check whether an executable exists on PATH.
def flash_firmware(bootloader_path, firmware_path, firmware_version="<unknown>", check_version=True)
def query_yes_no(question, default="yes")
Ask a yes/no question via raw_input() and return their answer.