def test_create_from_log_msg_with_stamp(self): seconds_since_epoch = 100 msg = Log() msg.header.stamp = rospy.Time(secs=seconds_since_epoch, nsecs=0) msg.level = Log.DEBUG entry = Entry.from_ros_msg(msg) self.assertEqual(entry.date_time.toSecsSinceEpoch(), seconds_since_epoch)
def test_create_from_info_log_msg(self): content = 'test' msg = Log() msg.msg = content msg.level = Log.INFO entry = Entry.from_ros_msg(msg) self.assertEqual(entry.content, content) self.assertFalse(entry.is_error) self.assertAlmostEqual(entry.date_time.toSecsSinceEpoch(), QDateTime.currentSecsSinceEpoch(), 10)
def check_usv(self): output = subprocess.check_output("sudo /opt/susvd/susv -status", shell=True) for item in output.split("\n"): if "Charging circuit: ONLINE" in item: if self.percentage > 0.9: self.state_charging = BatteryState.POWER_SUPPLY_STATUS_FULL else: self.state_charging = BatteryState.POWER_SUPPLY_STATUS_CHARGING elif "Charging circuit: OFFLINE" in item: self.state_charging = BatteryState.POWER_SUPPLY_STATUS_DISCHARGING if "Charging current" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Charging current: ", '') charging_current = float(e.replace("mA", '')) self.charging_current = (charging_current / 1000.0) if "Power Battery" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Power Battery: ", '') power_battery = float(e.replace("mA", '')) self.power_battery = (power_battery / 1000.0) if self.power_battery > 0: self.power_battery *= -1.0 if "Battery voltage" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Battery voltage: ", '') voltage = float(e.replace("V", '')) self.voltage = voltage if "Battery capacity" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Battery capacity: ", '') percentage = float(e.replace("%",'')) # send event msg if something changed if abs(percentage - self.percentage) > 5: log = Log() log.msg = str(string) log.level = log.INFO self.pub_event.publish(log) self.percentage = percentage
def map_log(values): """ Map the values generated with the hypothesis-ros log strategy to a rospy header type. """ if not isinstance(values, _Log): raise TypeError('Wrong type. Use appropriate hypothesis-ros type.') ros_log = Log() ros_log.header = values.header ros_log.level = values.level ros_log.name = values.name ros_log.msg = values.msg ros_log.file = values.file ros_log.function = values.function ros_log.topics = values.topics return ros_log
def test_create_from_fatal_log_msg(self): msg = Log() msg.level = Log.FATAL entry = Entry.from_ros_msg(msg) self.assertTrue(entry.is_error)
def test_create_from_error_log_msg(self): msg = Log() msg.level = Log.ERROR entry = Entry.from_ros_msg(msg) self.assertTrue(entry.is_error)