in deepracer_systems_pkg/deepracer_systems_pkg/network_monitor_module/network_monitor_node.py [0:0]
def __init__(self):
"""Create a NetworkMonitorNode.
"""
super().__init__("network_monitor_node")
self.get_logger().info("network_monitor_node started")
self.state_dir = ""
# Threading Event object to stop calling status LED update until the WiFi configuration
# update is completed.
self.led_update_pause = threading.Event()
# Scheduler to queue the function calls and run them in a separate thread.
self.scheduler = scheduler.Scheduler(self.get_logger())
# Timer to periodically update the WIFI_LED light with right color.
if network_config.ENABLE_NETWORK_LED_UPDATE:
self.update_status_LED_timer = self.create_timer(
network_config.NETWORK_UPDATE_LED_PERIOD_IN_SECONDS,
self.schedule_update_status_LED)
# Timer to periodically attempt to write the connection status report to USB.
if network_config.ENABLE_REPORT_STATE_UPDATE:
self.report_state_timer = self.create_timer(
network_config.REPORT_STATE_PERIOD_IN_SECONDS,
self.schedule_report_state)
# Publisher that broadcasts network connection status.
self.network_status_pub_cb = ReentrantCallbackGroup()
self.network_status_message_publisher = \
self.create_publisher(NetworkConnectionStatus,
network_config.NETWORK_CONNECTION_STATUS_TOPIC_NAME,
1,
callback_group=self.network_status_pub_cb)
# Timer to periodically publish the network connection status.
self.status_publisher_timer = self.create_timer(network_config.NETWORK_CONNECTION_PUBLISHER_PERIOD_IN_SECONDS,
self.publish_network_connection_status,
callback_group=self.network_status_pub_cb)
# Clients to Status LED services that are called to indicate progress/success/failure
# status while loading model.
self.led_cb_group = MutuallyExclusiveCallbackGroup()
self.led_blink_service = self.create_client(SetStatusLedBlinkSrv,
constants.LED_BLINK_SERVICE_NAME,
callback_group=self.led_cb_group)
self.led_solid_service = self.create_client(SetStatusLedSolidSrv,
constants.LED_SOLID_SERVICE_NAME,
callback_group=self.led_cb_group)
while not self.led_blink_service.wait_for_service(timeout_sec=1.0):
self.get_logger().info("Led blink service not available, waiting again...")
while not self.led_solid_service.wait_for_service(timeout_sec=1.0):
self.get_logger().info("Led solid service not available, waiting again...")
self.led_blink_request = SetStatusLedBlinkSrv.Request()
self.led_solid_request = SetStatusLedSolidSrv.Request()
# Client to USB File system subscription service that allows the node to connect to WiFi
# based on the contents in the WiFi configuration file in the USB. The usb_monitor_node
# will trigger notification if it finds the WiFi configuration file from the watchlist
# in the USB drive.
self.usb_sub_cb_group = ReentrantCallbackGroup()
self.usb_file_system_subscribe_client = self.create_client(USBFileSystemSubscribeSrv,
constants.USB_FILE_SYSTEM_SUBSCRIBE_SERVICE_NAME,
callback_group=self.usb_sub_cb_group)
while not self.usb_file_system_subscribe_client.wait_for_service(timeout_sec=1.0):
self.get_logger().info("File System Subscribe not available, waiting again...")
# Client to USB Mount point manager service to indicate that the usb_monitor_node can safely
# decrement the counter for the mount point once the action function for the WiFi configuration
# file being watched by network_monitor_node is succesfully executed.
self.usb_mpm_cb_group = ReentrantCallbackGroup()
self.usb_mount_point_manager_client = self.create_client(USBMountPointManagerSrv,
constants.USB_MOUNT_POINT_MANAGER_SERVICE_NAME,
callback_group=self.usb_mpm_cb_group)
while not self.usb_mount_point_manager_client.wait_for_service(timeout_sec=1.0):
self.get_logger().info("USB mount point manager service not available, waiting again...")
# Subscriber to USB File system notification publisher to recieve the broadcasted messages
# with file/folder details, whenever a watched file is identified in the USB connected.
self.usb_notif_cb_group = ReentrantCallbackGroup()
self.usb_file_system_notification_sub = self.create_subscription(USBFileSystemNotificationMsg,
constants.USB_FILE_SYSTEM_NOTIFICATION_TOPIC,
self.usb_file_system_notification_cb,
10,
callback_group=self.usb_notif_cb_group)
# Add the "wifi-creds.txt" file to the watchlist.
usb_file_system_subscribe_request = USBFileSystemSubscribeSrv.Request()
usb_file_system_subscribe_request.file_name = network_config.WIFI_CONFIG_NAME
usb_file_system_subscribe_request.callback_name = network_config.SCHEDULE_CONFIG_UPDATE_CB
usb_file_system_subscribe_request.verify_name_exists = True
self.usb_file_system_subscribe_client.call_async(usb_file_system_subscribe_request)
# Heartbeat timer.
self.timer_count = 0
self.timer = self.create_timer(5.0, self.timer_callback)
self.get_logger().info("Network Monitor node successfully created")