def send_msgs(data): '''Send messages from user input (in terminal) to screen''' cmd = LinkMessage() cmd.uuid = 0 cmd.id = 1 # Temp ID cmd.data = input() pub_to_despatcher.publish(cmd)
def send_regular_payload_tele(self, data): '''Send regular payload over Telegram link''' message = LinkMessage() message.uuid = 0 message.data, message.id = self._prep_regular_payload() self.pub_to_telegram.publish(message) rospy.sleep(self._tele_interval)
def send_regular_payload_sms(self, data): '''Send regular payload over sms link''' message = LinkMessage() message.uuid = 0 message.data, message.id = self._prep_regular_payload() self.pub_to_sms.publish(message) rospy.sleep(self._sms_interval)
def _send_heartbeat_sms(self, data): msg = LinkMessage() msg.uuid = 0 msg.data = self._prep_heartbeat() msg.id = self._air_id self._pub_to_sms.publish(msg) rospy.sleep(self._sms_interval)
def create_link_message(self, destination_id, data): '''Create a custom Link Message''' message = LinkMessage() message.uuid = feedback_util.increment() message.id = destination_id message.data = data self.command_publisher.publish(message)
def send_to_rqt(message_id, data): '''Handles sending LinkMessage to rqt''' message = LinkMessage() message.id = message_id message.data = data message.uuid = 0 # 0 is for uuid for non-A2G message pub_to_rqt.publish(message)
def check_incoming_msgs(self, data): '''Check for incoming A2G messages from ogc/from_sms, from_sbd or from_telegram topics''' try: # Handle msg prefixes msgtype, devicetype, sysid, uuid, timestamp, entries \ = headers.split_headers(data.data) if not self._new_msg_chk.is_new_msg(timestamp, sysid): # Check if it is new msg return # Check if it is regular msg. This requires a list of the msg with all its headers attached data_list = data.data.split() # Msg + Headers, split into a list if regular.is_regular(msgtype, len(data_list)): # Check if it is regular payload msg = regular.convert_to_rosmsg(data_list) self.rqt_recovery_log(data_list, sysid) self.pub_to_rqt_regular.publish(msg) else: # Check if the incoming message is an acknowledgment message if uuid != 0: ack_msg = LinkMessage() ack_msg.uuid = uuid ack_msg.data = "" ack_msg.id = 1 ack = feedback_util.ack_converter(ack_msg, 2) if ack != None: self.pub_to_timeout.publish(ack) return 0 # Prevent the message to get sent through ondemand if msgtype == 's': # Check if it is statustext self.pub_to_statustext.publish(data.data) elif msgtype == 'm': # Check if it is mission update message reqFile = LinkMessage() reqFile.uuid = 0 reqFile.id = sysid if entries == ["No", "update", "required"]: return for i in entries: reqFile.data = "Waypoints/" + i self.file_to_telegram.publish(reqFile) rospy.sleep(1) else: self.pub_to_rqt_ondemand.publish(data.data) except (ValueError, IndexError, TypeError): rospy.logerr("Despatcher: Invalid message format")
def rockBlockTxSuccess(self, momsg, target_id, uuid): # Acknowledgment message sending. Create a LinkMessage to be compatible with feedback_util's ack converter msg = LinkMessage() msg.data = momsg msg.id = target_id msg.uuid = uuid ack = feedback_util.ack_converter(msg, 1) if ack != None: self._pub_to_timeout.publish(ack) rospy.loginfo("SBD: Msg sent: " + momsg) self._msg_send_success = 1
def sendmsg(self, msgtype, uuid=0): '''Send any msg that's not a regular payload''' self._attach_headers(msgtype, uuid) message = LinkMessage() message.uuid = 0 # This UUID does get passed through to the links message.id = self.ground_id message.data = self._msg if self.link_select == 0: self.pub_to_telegram.publish(message) elif self.link_select == 1: self.pub_to_sms.publish(message) else: self.pub_to_sbd.publish(message)
def ack_converter(data, state): '''Converts status of a message to a recognised status''' if data.uuid == 0: return None else: message = LinkMessage() message.uuid = data.uuid message.id = 0 if state == 0: message.data = "pending" elif state == 1: message.data = "single tick" elif state == 2: message.data = "double tick" return message
def _switch_cmd_handler(self): '''Send cmds to all aircraft, telling them to switch between server and RB-2-RB methods''' air_ids = self._get_valid_ids().ids switch_cmd = LinkMessage() switch_cmd.uuid = 0 prefixes = ["e", 0, self._id, switch_cmd.uuid] for i in air_ids: switch_cmd.id = i rospy.loginfo("SBD: Sending switch cmd to aircraft " + str(i)) if self._thr_server: switch_cmd.data = headers.attach_headers( prefixes, [rospy.get_rostime().secs], "sbd switch 1") self._server_send_msg(switch_cmd) else: # Sending from gnd Rockblock is likely to fail. We need to ensure that all switch cmds are sent while not self._msg_send_success == 1: switch_cmd.data = headers.attach_headers( prefixes, [rospy.get_rostime().secs], "sbd switch 0") self.sbd_get_mo_msg(switch_cmd) self.sbd_check_mailbox("")
def handle_outgoing_msgs(self, data): '''Check that outgoing G2A messages are valid before forwarding them to the links''' dummy_prefixes = [ "i", 1, data.id, 0 ] # Dummy prefixes for publishing local msgs to on_demand topic feedback_to_rqt = "" if data.data.split()[0] not in recognised_commands: feedback_to_rqt = "Invalid command: " + data.data else: msg = LinkMessage() msg.uuid = data.uuid msg.id = data.id # Add msg headers prefixes = ["i", self._is_air, self._id, data.uuid] msg.data = headers.attach_headers(prefixes, [rospy.get_rostime().secs], data.data) try: link = self._aircrafts[data.id].link_status() if link == TELE: self.pub_to_telegram.publish(msg) feedback_to_rqt = "Command sent to Tele: " + data.data elif link == SMS: self.pub_to_sms.publish(msg) feedback_to_rqt = "Command sent to SMS: " + data.data elif link == SBD: self.pub_to_sbd.publish(msg) feedback_to_rqt = "Command sent to SBD: " + data.data else: rospy.logerr("Despatcher: Invalid link") feedback_to_rqt = "Invalid Link. Command " + data.data + " not sent" except KeyError: rospy.logerr("Despatcher: Invalid aircraft ID") feedback_to_rqt = "Invalid Aircraft ID. Command " + data.data + " not sent" self.pub_to_rqt_ondemand.publish(\ headers.attach_headers(dummy_prefixes, [rospy.get_rostime().secs], feedback_to_rqt))
def send_regular_payload_sbd(self, data): '''Send regular payload over SBD Satcomms link''' message = LinkMessage() message.uuid = 0 message.data, message.id = self._prep_regular_payload() self.pub_to_sbd.publish(message)