def parse_startstop_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.START_STOP_MSG: return pubsub_message.startstop.cmd return None
def create_steering_msg(cmd, angle): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.STEERING_MSG pubsub_message.steering.cmd = cmd pubsub_message.steering.angle = angle return pubsub_message.SerializeToString()
def parse_all_type_messages(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) #handles with message type and returns the parsed data. if pubsub_message.msg_type is process_pb2.pub_sub_message.GPS_MSG: return pubsub_message.location.latitude, pubsub_message.location.longitude elif pubsub_message.msg_type is process_pb2.pub_sub_message.HCSR4_MSG: return pubsub_message.hcsr4_dis.distance elif pubsub_message.msg_type is process_pb2.pub_sub_message.BRAKE_MSG: return pubsub_message.brake.brakeValue elif pubsub_message.msg_type is process_pb2.pub_sub_message.THROTTLE_MSG: return pubsub_message.throttle.throttleValue elif pubsub_message.msg_type is process_pb2.pub_sub_message.STATE_WORKING_MSG: return pubsub_message.statework.cmd elif pubsub_message.msg_type is process_pb2.pub_sub_message.STEERING_MSG: return pubsub_message.steering.cmd, pubsub_message.steering.angle elif pubsub_message.msg_type is process_pb2.pub_sub_message.START_STOP_MSG: return pubsub_message.startstop.cmd else: logging.warning("Invalid parse type!") return None
def create_GPS_msg(latitudeVal, longitudeVal): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.GPS_MSG pubsub_message.location.latitude = latitudeVal pubsub_message.location.longitude = longitudeVal return pubsub_message.SerializeToString()
def create_message(message_type, val_1, val_2=None): pubsub_message = process_pb2.pub_sub() if message_type == process_pb2.pub_sub_message.START_STOP_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.START_STOP_MSG pubsub_message.startstop.cmd = val_1 # val1 is cmd in here elif message_type == process_pb2.pub_sub_message.THROTTLE_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.THROTTLE_MSG pubsub_message.throttle.throttleValue = val_1 # val1 is throttleVal in here elif message_type == process_pb2.pub_sub_message.STEERING_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.STEERING_MSG pubsub_message.steering.cmd = val_1 # val1 is cmd in here pubsub_message.steering.angle = val_2 # val2 is angle in here elif message_type == process_pb2.pub_sub_message.BRAKE_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.BRAKE_MSG pubsub_message.brake.brakeValue = val_1 # val1 is brakeValue in here elif message_type == process_pb2.pub_sub_message.STATE_WORKING_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.STATE_WORKING_MSG pubsub_message.statework.cmd = val_1 # val1 is cmd in here elif message_type == process_pb2.pub_sub_message.HSCR4_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.HCSR4_MSG pubsub_message.hcsr4_dis.distance = val_1 # val1 is distance in here elif message_type == process_pb2.pub_sub_message.GPS_MSG: pubsub_message.msg_type = process_pb2.pub_sub_message.GPS_MSG pubsub_message.location.latitude = val_1 # val1 is latitude in here pubsub_message.location.longitude = val_2 # val1 is longitude in here else: logging.warning("Invalid message type!") return pubsub_message.SerializeToString()
def parse_brake_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.BRAKE_MSG: return pubsub_message.brake.brakeValue return None
def create_brake_msg(brakeValue): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.BRAKE_MSG pubsub_message.brake.brakeValue = brakeValue return pubsub_message.SerializeToString()
def parse_throttle_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.THROTTLE_MSG: return pubsub_message.throttle.throttleValue return None
def create_throttle_msg(throttleValue): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.THROTTLE_MSG pubsub_message.throttle.throttleValue = throttleValue return pubsub_message.SerializeToString()
def parse_stateWorking_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.STATE_WORKING_MSG: return pubsub_message.statework.cmd return None
def create_stateWorking_msg(cmd): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.STATE_WORKING_MSG pubsub_message.statework.cmd = cmd return pubsub_message.SerializeToString()
def parse_steering_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.STEERING_MSG: return pubsub_message.steering.cmd, pubsub_message.steering.angle return None
def create_startstop_msg(cmd): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.START_STOP_MSG pubsub_message.startstop.cmd = cmd return pubsub_message.SerializeToString()
def parse_GPS_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.GPS_MSG: return pubsub_message.location.latitude, pubsub_message.location.longitude return None
def parse_HCSR4_msg(msg): pubsub_message = process_pb2.pub_sub() pubsub_message.ParseFromString(msg) if pubsub_message.msg_type is process_pb2.pub_sub_message.HCSR4_MSG: return pubsub_message.hcsr4_dis.distance return None
def create_HCSR4_msg(distanceVal): pubsub_message = process_pb2.pub_sub() pubsub_message.msg_type = process_pb2.pub_sub_message.HCSR4_MSG pubsub_message.hcsr4_dis.distance = distanceVal return pubsub_message.SerializeToString()