Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._node.defer(0.1, lambda: self._node.request(uavcan.protocol.param.GetSet.Request(index=index),
self._target_node_id,
partial(self._on_fetch_response, index),
priority=REQUEST_PRIORITY))
except Exception as ex:
def set_param(self, target_id, name, value, value_type):
req = uavcan.protocol.param.GetSet.Request(
name=name,
value=value_to_uavcan(value, value_type)
)
self.node.request(req, target_id, self._param_changed)
def set_antenna_delay(node, value):
request = uavcan.protocol.param.GetSet.Request()
request.name = '/uwb/antenna_delay'
request.value = uavcan.protocol.param.Value(real_value=value)
def save_params(self, target_id):
OPCODE_SAVE = 0
request = uavcan.protocol.param.ExecuteOpcode.Request(opcode=OPCODE_SAVE)
self.node.request(request, target_id, self._save_params_callback)
self.logger.info('Asked node {} to save its parameters on flash'.format(target_id))
# value_to_constant_name()
print(value_to_constant_name(
uavcan.protocol.NodeStatus(mode=uavcan.protocol.NodeStatus().MODE_OPERATIONAL),
'mode'
))
print(value_to_constant_name(
uavcan.protocol.NodeStatus(mode=uavcan.protocol.NodeStatus().HEALTH_OK),
'health'
))
print(value_to_constant_name(
uavcan.equipment.range_sensor.Measurement(reading_type=uavcan.equipment.range_sensor.Measurement()
.READING_TYPE_TOO_FAR),
'reading_type'
))
print(value_to_constant_name(
uavcan.protocol.param.ExecuteOpcode.Request(opcode=uavcan.protocol.param.ExecuteOpcode.Request().OPCODE_ERASE),
'opcode'
))
print(value_to_constant_name(
uavcan.protocol.file.Error(value=uavcan.protocol.file.Error().ACCESS_DENIED),
'value'
))
print(value_to_constant_name(
uavcan.equipment.power.BatteryInfo(status_flags=
uavcan.equipment.power.BatteryInfo().STATUS_FLAG_NEED_SERVICE),
'status_flags'
))
print(value_to_constant_name(
uavcan.equipment.power.BatteryInfo(status_flags=
uavcan.equipment.power.BatteryInfo().STATUS_FLAG_NEED_SERVICE |
uavcan.equipment.power.BatteryInfo().STATUS_FLAG_TEMP_HOT |
uavcan.equipment.power.BatteryInfo().STATUS_FLAG_CHARGED),
def value_to_uavcan(value, value_type):
"""
Given a value and its type, returns a UAVCAN Value object
"""
if value_type == bool: return uavcan.protocol.param.Value(boolean_value=bool(value))
elif value_type == int: return uavcan.protocol.param.Value(integer_value=int(value))
elif value_type == float: return uavcan.protocol.param.Value(real_value=float(value))
elif value_type == str: return uavcan.protocol.param.Value(string_value=str(value))
else: return uavcan.protocol.param.Value()
print(to_yaml(info))
lights = uavcan.equipment.indication.LightsCommand()
lcmd = uavcan.equipment.indication.SingleLightCommand(light_id=123)
lcmd.color.red = 1
lcmd.color.green = 2
lcmd.color.blue = 3
lights.commands.append(lcmd)
lcmd.light_id += 1
lights.commands.append(lcmd)
print(to_yaml(lights))
print(to_yaml(uavcan.equipment.power.BatteryInfo()))
print(to_yaml(uavcan.protocol.param.Empty()))
getset = uavcan.protocol.param.GetSet.Response()
print(to_yaml(getset))
uavcan.switch_union_field(getset.value, 'empty')
print(to_yaml(getset))
# value_to_constant_name()
print(value_to_constant_name(
uavcan.protocol.NodeStatus(mode=uavcan.protocol.NodeStatus().MODE_OPERATIONAL),
'mode'
))
print(value_to_constant_name(
uavcan.protocol.NodeStatus(mode=uavcan.protocol.NodeStatus().HEALTH_OK),
'health'
))
print(value_to_constant_name(
uavcan.equipment.range_sensor.Measurement(reading_type=uavcan.equipment.range_sensor.Measurement()
.READING_TYPE_TOO_FAR),
def value_to_uavcan(value, value_type):
"""
Given a value and its type, returns a UAVCAN Value object
"""
if value_type == bool: return uavcan.protocol.param.Value(boolean_value=bool(value))
elif value_type == int: return uavcan.protocol.param.Value(integer_value=int(value))
elif value_type == float: return uavcan.protocol.param.Value(real_value=float(value))
elif value_type == str: return uavcan.protocol.param.Value(string_value=str(value))
else: return uavcan.protocol.param.Value()
info = uavcan.protocol.GetNodeInfo.Response(name='legion')
info.hardware_version.certificate_of_authenticity = b'\x01\x02\x03\xff'
print(to_yaml(info))
lights = uavcan.equipment.indication.LightsCommand()
lcmd = uavcan.equipment.indication.SingleLightCommand(light_id=123)
lcmd.color.red = 1
lcmd.color.green = 2
lcmd.color.blue = 3
lights.commands.append(lcmd)
lcmd.light_id += 1
lights.commands.append(lcmd)
print(to_yaml(lights))
print(to_yaml(uavcan.equipment.power.BatteryInfo()))
print(to_yaml(uavcan.protocol.param.Empty()))
getset = uavcan.protocol.param.GetSet.Response()
print(to_yaml(getset))
uavcan.switch_union_field(getset.value, 'empty')
print(to_yaml(getset))
# value_to_constant_name()
print(value_to_constant_name(
uavcan.protocol.NodeStatus(mode=uavcan.protocol.NodeStatus().MODE_OPERATIONAL),
'mode'
))
print(value_to_constant_name(
uavcan.protocol.NodeStatus(mode=uavcan.protocol.NodeStatus().HEALTH_OK),
'health'
))
print(value_to_constant_name(
def send_parameter(self, name, value, board_name):
with self.node_lock:
request = uavcan.protocol.param.GetSet.Request(name=name)
# TODO other types
if type(value) == bool:
request.value.boolean_value = value
elif type(value) == int:
request.value.integer_value = value
else:
request.value.real_value = value
self.node.request(request, self.boards_id_by_name[board_name],
self._send_parameter_callback)
# Wait for an answer
self.rpc_answered.acquire()