From 29a0ae6bd5b43cbf7d93e8be0c0225f0dea2cd57 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 1 Apr 2025 19:11:25 -0400 Subject: [PATCH 01/30] Initial implementation of DBC messages in subsystems --- subsystems/lib/src/devices/can_bus.dart | 249 +++ .../lib/src/generated/rover_messages.dbc.dart | 1824 +++++++++++++++++ subsystems/lib/subsystems.dart | 6 + subsystems/pubspec.yaml | 3 + 4 files changed, 2082 insertions(+) create mode 100644 subsystems/lib/src/devices/can_bus.dart create mode 100644 subsystems/lib/src/generated/rover_messages.dbc.dart diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart new file mode 100644 index 00000000..c9bbcc41 --- /dev/null +++ b/subsystems/lib/src/devices/can_bus.dart @@ -0,0 +1,249 @@ +import "dart:async"; +import "dart:io"; + +import "package:burt_network/protobuf.dart"; +import "package:burt_network/service.dart"; +import "package:dart_dbc_generator/dart_dbc_generator.dart"; +import "package:linux_can/linux_can.dart"; +import "package:subsystems/src/generated/rover_messages.dbc.dart"; +import "package:subsystems/subsystems.dart" hide CanSocket; + +extension on num { + bool get boolValue => this == 1; + + BoolState get boolState => boolValue ? BoolState.YES : BoolState.NO; +} + +extension on bool { + int get intValue => this ? 1 : 0; +} + +extension on BoolState { + int get intValue => this == BoolState.YES ? 1 : 0; +} + +extension on DriveAppliedOutputMessage { + DriveData toDriveProto() => DriveData( + throttle: throttle.toDouble(), + left: leftSpeed.toDouble(), + right: rightSpeed.toDouble(), + setLeft: true, + setRight: true, + setThrottle: true, + ); +} + +extension on DriveBatteryMessage { + DriveData toDriveProto() => DriveData( + batteryVoltage: voltage.toDouble(), + batteryTemperature: temperature.toDouble(), + batteryCurrent: current.toDouble(), + ); +} + +extension on DriveCommand { + DBCMessage get asSetSpeeds => DriveSetSpeedsMessage( + shouldSetLeft: setLeft.intValue, + shouldSetRight: setRight.intValue, + shouldSetThrottle: setThrottle.intValue, + leftSpeed: left, + rightSpeed: right, + throttle: throttle, + ); + + DBCMessage get asSetLEDS => DriveSetLedMessage( + color: color.value, + blink: blink.intValue, + ); + + DBCMessage get asSetSwivels => DriveSetSwivelMessage( + setFrontSwivel: hasFrontSwivel().intValue, + setFrontTilt: hasFrontTilt().intValue, + setRearSwivel: hasRearSwivel().intValue, + setRearTilt: hasRearTilt().intValue, + frontSwivel: frontSwivel, + frontTilt: frontTilt, + rearSwivel: rearSwivel, + rearTilt: rearTilt, + ); + + List toDBC() { + final output = []; + if (setLeft || setRight || setThrottle) { + output.add(asSetSpeeds); + } + if (hasColor() || hasBlink()) { + output.add(asSetLEDS); + } + if (hasFrontSwivel() || + hasFrontTilt() || + hasRearSwivel() || + hasRearTilt()) { + output.add(asSetSwivels); + } + return output; + } +} + +extension on RelayStateMessage { + RelaysData toRelayProto() => RelaysData( + frontLeftMotor: frontLeftMotor.boolState, + frontRightMotor: frontRightMotor.boolState, + backLeftMotor: backLeftMotor.boolState, + backRightMotor: backRightMotor.boolState, + arm: arm.boolState, + drive: drive.boolState, + science: science.boolState, + ); +} + +extension on RelaysCommand { + DBCMessage get asSetState => RelaySetStateMessage( + updateArm: hasArm().intValue, + updateFrontLeftMotor: hasFrontLeftMotor().intValue, + updateFrontRightMotor: hasFrontRightMotor().intValue, + updateBackLeftMotor: hasBackLeftMotor().intValue, + updateBackRightMotor: hasBackRightMotor().intValue, + ); + + List toDBC() => [asSetState]; +} + +/// A service to forward messages between CAN and UDP +class CanBus extends Service { + /// How often to send a rover heartbeat over the CAN bus + static const Duration heartbeatPeriod = Duration(milliseconds: 100); + + /// The maximum time the program should wait for a device's heartbeat before + /// it's considered disconnected + static const Duration heartbeatTimeout = Duration(milliseconds: 500); + + /// A map of devices and the last time their broadcast message was received + final Map deviceHeartbeats = {}; + + /// The CAN socket for the CAN bus + CanSocket? socket; + Timer? _heartbeatTimer; + + StreamSubscription? _frameSubscription; + + @override + Future init() async { + if (Platform.isWindows) { + return true; + } + await Process.run("sudo", ["ip", "link", "set", "can0", "down"]); + await Process.run("sudo", [ + "ip", + "link", + "set", + "can0", + "up", + "type", + "can", + "bitrate", + "500000", + ]); + final canDevice = LinuxCan.instance.devices.singleWhere( + (device) => device.networkInterface.name == "can0", + ); + if (!canDevice.isUp) { + logger.error( + "CAN0 is not up", + body: "Device state: ${canDevice.state}", + ); + return false; + } + socket = canDevice.open(); + _frameSubscription = socket!.receive().listen(_onCanFrame); + _heartbeatTimer = Timer.periodic(heartbeatPeriod, (_) => sendHeartbeat()); + + return true; + } + + @override + Future dispose() async { + await _frameSubscription?.cancel(); + await socket?.close(); + _heartbeatTimer?.cancel(); + } + + /// Sends a message's DBC equivalent over the CAN bus + void send(Message message) { + if (message is DriveCommand) { + message.toDBC().forEach(sendDBCMessage); + } else if (message is RelaysCommand) { + message.toDBC().forEach(sendDBCMessage); + } + } + + /// Sends a heartbeat message over the CAN bus + void sendHeartbeat() { + final heartbeat = RoverHeartbeatMessage(); + sendDBCMessage(heartbeat); + + final now = DateTime.timestamp(); + deviceHeartbeats.removeWhere((device, time) { + if (now.difference(time) > heartbeatTimeout) { + logger.warning( + "${device.name} disconnected.", + body: "Broadcast message not received after $heartbeatTimeout", + ); + return true; + } + return false; + }); + } + + /// Sends a DBC message over the CAN bus + void sendDBCMessage(DBCMessage message) { + try { + socket?.send( + CanFrame.standard( + id: message.canId, + data: message.writeToBuffer(), + ), + ); + } catch (e) { + logger.error("Error when sending CAN message", body: e.toString()); + } + } + + void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { + final device = Device.valueOf(broadcast.deviceName.toInt()); + if (device == null) { + logger.warning( + "Unknown Device Number", + body: "Received broadcast from device ${broadcast.deviceName.toInt()}", + ); + return; + } + if (!deviceHeartbeats.containsKey(device)) { + logger.info("${device.name} connected via CAN bus"); + } + deviceHeartbeats[device] = DateTime.timestamp(); + } + + void _onCanFrame(CanFrame frame) { + switch (frame) { + case CanDataFrame(:final id, :final data): + if (id == DeviceBroadcastMessage().canId) { + _handleDeviceBroadcast(DeviceBroadcastMessage.fromBuffer(data)); + } else if (id == DriveAppliedOutputMessage().canId) { + collection.server.sendMessage( + DriveAppliedOutputMessage.fromBuffer(data).toDriveProto(), + ); + } else if (id == DriveBatteryMessage().canId) { + collection.server.sendMessage( + DriveBatteryMessage.fromBuffer(data).toDriveProto(), + ); + } else if (id == RelayStateMessage().canId) { + collection.server.sendMessage( + RelayStateMessage.fromBuffer(data).toRelayProto(), + ); + } + case CanRemoteFrame _: + break; + } + } +} diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart new file mode 100644 index 00000000..9ad1764d --- /dev/null +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -0,0 +1,1824 @@ +// AUTO GENERATED FILE, DO NOT MODIFY + +// ignore_for_file: type=lint +// ignore_for_file: annotate_overrides, camel_case_types, comment_references +// ignore_for_file: constant_identifier_names, library_prefixes +// ignore_for_file: non_constant_identifier_names, prefer_final_fields +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import + +import 'dart:math' as $_math; +import 'dart:typed_data' as $_typed; + +import 'package:dart_dbc_generator/dart_dbc_generator.dart' as $_dbc; + +class RoverHeartbeatMessage extends $_dbc.DBCMessage { + @override + String messageName = "Rover_Heartbeat"; + + @override + int messageLength = 1; + + @override + int canId = 0x0; + + /// Whether or not "Rover_Heartbeat" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Rover_Heartbeat" + static const String multiplexor = ""; + + /// Value of signal "Rover_Status" + num roverStatus; + + final $_dbc.DBCSignal _roverStatusSignal = $_dbc.DBCSignal( + name: "Rover_Status", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 4, + mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 5.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _roverStatusSignal, + ]; + + RoverHeartbeatMessage({ + this.roverStatus = 0, + }); + + /// Creates a clone of this [RoverHeartbeatMessage] with the non-null values replaced + RoverHeartbeatMessage copyWith({ + num? roverStatus, + }) { + return RoverHeartbeatMessage( + roverStatus: roverStatus ?? this.roverStatus, + ); + } + + factory RoverHeartbeatMessage.fromBuffer(List buffer) { + final message = RoverHeartbeatMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.roverStatus = + message._roverStatusSignal.decode(bitField) ?? + $_math.max(0, message._roverStatusSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _roverStatusSignal: roverStatus, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Rover_Heartbeat(\n Rover_Status=$roverStatus\n)"; + } +} + +class DeviceBroadcastMessage extends $_dbc.DBCMessage { + @override + String messageName = "Device_Broadcast"; + + @override + int messageLength = 2; + + @override + int canId = 0x1; + + /// Whether or not "Device_Broadcast" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Device_Broadcast" + static const String multiplexor = ""; + + /// Value of signal "Device_Name" + num deviceName; + + /// Value of signal "FW_Version_Major" + num fwVersionMajor; + + /// Value of signal "FW_Version_Minor" + num fwVersionMinor; + + final $_dbc.DBCSignal _deviceNameSignal = $_dbc.DBCSignal( + name: "Device_Name", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 5, + mapping: [1, 2, 4, 8, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 15.0, + unit: "", + ); + + final $_dbc.DBCSignal _fwVersionMajorSignal = $_dbc.DBCSignal( + name: "FW_Version_Major", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 5, + length: 4, + mapping: [0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [5, 6, 7, 8], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 8.0, + unit: "", + ); + + final $_dbc.DBCSignal _fwVersionMinorSignal = $_dbc.DBCSignal( + name: "FW_Version_Minor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 9, + length: 4, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [9, 10, 11, 12], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 8.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _deviceNameSignal, + _fwVersionMajorSignal, + _fwVersionMinorSignal, + ]; + + DeviceBroadcastMessage({ + this.deviceName = 0, + this.fwVersionMajor = 0, + this.fwVersionMinor = 0, + }); + + /// Creates a clone of this [DeviceBroadcastMessage] with the non-null values replaced + DeviceBroadcastMessage copyWith({ + num? deviceName, + num? fwVersionMajor, + num? fwVersionMinor, + }) { + return DeviceBroadcastMessage( + deviceName: deviceName ?? this.deviceName, + fwVersionMajor: fwVersionMajor ?? this.fwVersionMajor, + fwVersionMinor: fwVersionMinor ?? this.fwVersionMinor, + ); + } + + factory DeviceBroadcastMessage.fromBuffer(List buffer) { + final message = DeviceBroadcastMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.deviceName = + message._deviceNameSignal.decode(bitField) ?? + $_math.max(0, message._deviceNameSignal.min); + message.fwVersionMajor = + message._fwVersionMajorSignal.decode(bitField) ?? + $_math.max(0, message._fwVersionMajorSignal.min); + message.fwVersionMinor = + message._fwVersionMinorSignal.decode(bitField) ?? + $_math.max(0, message._fwVersionMinorSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _deviceNameSignal: deviceName, + _fwVersionMajorSignal: fwVersionMajor, + _fwVersionMinorSignal: fwVersionMinor, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Device_Broadcast(\n Device_Name=$deviceName\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)"; + } +} + +class DriveSetSpeedsMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_Set_Speeds"; + + @override + int messageLength = 7; + + @override + int canId = 0x10; + + /// Whether or not "Drive_Set_Speeds" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_Set_Speeds" + static const String multiplexor = ""; + + /// Value of signal "Should_Set_Left" + num shouldSetLeft; + + /// Value of signal "Should_Set_Right" + num shouldSetRight; + + /// Value of signal "Should_Set_Throttle" + num shouldSetThrottle; + + /// Value of signal "Left_Speed" + num leftSpeed; + + /// Value of signal "Right_Speed" + num rightSpeed; + + /// Value of signal "Throttle" + num throttle; + + final $_dbc.DBCSignal _shouldSetLeftSignal = $_dbc.DBCSignal( + name: "Should_Set_Left", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 1, + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _shouldSetRightSignal = $_dbc.DBCSignal( + name: "Should_Set_Right", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 1, + length: 1, + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _shouldSetThrottleSignal = $_dbc.DBCSignal( + name: "Should_Set_Throttle", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _leftSpeedSignal = $_dbc.DBCSignal( + name: "Left_Speed", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 16, + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], + factor: 0.000062, + offset: 0.0, + min: -1.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _rightSpeedSignal = $_dbc.DBCSignal( + name: "Right_Speed", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 19, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], + factor: 0.000062, + offset: 0.0, + min: -1.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( + name: "Throttle", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 35, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], + factor: 0.000016, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _shouldSetLeftSignal, + _shouldSetRightSignal, + _shouldSetThrottleSignal, + _leftSpeedSignal, + _rightSpeedSignal, + _throttleSignal, + ]; + + DriveSetSpeedsMessage({ + this.shouldSetLeft = 0, + this.shouldSetRight = 0, + this.shouldSetThrottle = 0, + this.leftSpeed = 0, + this.rightSpeed = 0, + this.throttle = 0, + }); + + /// Creates a clone of this [DriveSetSpeedsMessage] with the non-null values replaced + DriveSetSpeedsMessage copyWith({ + num? shouldSetLeft, + num? shouldSetRight, + num? shouldSetThrottle, + num? leftSpeed, + num? rightSpeed, + num? throttle, + }) { + return DriveSetSpeedsMessage( + shouldSetLeft: shouldSetLeft ?? this.shouldSetLeft, + shouldSetRight: shouldSetRight ?? this.shouldSetRight, + shouldSetThrottle: shouldSetThrottle ?? this.shouldSetThrottle, + leftSpeed: leftSpeed ?? this.leftSpeed, + rightSpeed: rightSpeed ?? this.rightSpeed, + throttle: throttle ?? this.throttle, + ); + } + + factory DriveSetSpeedsMessage.fromBuffer(List buffer) { + final message = DriveSetSpeedsMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.shouldSetLeft = + message._shouldSetLeftSignal.decode(bitField) ?? + $_math.max(0, message._shouldSetLeftSignal.min); + message.shouldSetRight = + message._shouldSetRightSignal.decode(bitField) ?? + $_math.max(0, message._shouldSetRightSignal.min); + message.shouldSetThrottle = + message._shouldSetThrottleSignal.decode(bitField) ?? + $_math.max(0, message._shouldSetThrottleSignal.min); + message.leftSpeed = + message._leftSpeedSignal.decode(bitField) ?? + $_math.max(0, message._leftSpeedSignal.min); + message.rightSpeed = + message._rightSpeedSignal.decode(bitField) ?? + $_math.max(0, message._rightSpeedSignal.min); + message.throttle = + message._throttleSignal.decode(bitField) ?? + $_math.max(0, message._throttleSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _shouldSetLeftSignal: shouldSetLeft, + _shouldSetRightSignal: shouldSetRight, + _shouldSetThrottleSignal: shouldSetThrottle, + _leftSpeedSignal: leftSpeed, + _rightSpeedSignal: rightSpeed, + _throttleSignal: throttle, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_Set_Speeds(\n Should_Set_Left=$shouldSetLeft\n Should_Set_Right=$shouldSetRight\n Should_Set_Throttle=$shouldSetThrottle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n Throttle=$throttle\n)"; + } +} + +class DriveSetLedMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_SetLED"; + + @override + int messageLength = 1; + + @override + int canId = 0x11; + + /// Whether or not "Drive_SetLED" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_SetLED" + static const String multiplexor = ""; + + /// Value of signal "Color" + num color; + + /// Value of signal "Blink" + num blink; + + final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( + name: "Color", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 4, + mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 8.0, + unit: "", + ); + + final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( + name: "Blink", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _colorSignal, + _blinkSignal, + ]; + + DriveSetLedMessage({ + this.color = 0, + this.blink = 0, + }); + + /// Creates a clone of this [DriveSetLedMessage] with the non-null values replaced + DriveSetLedMessage copyWith({ + num? color, + num? blink, + }) { + return DriveSetLedMessage( + color: color ?? this.color, + blink: blink ?? this.blink, + ); + } + + factory DriveSetLedMessage.fromBuffer(List buffer) { + final message = DriveSetLedMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.color = + message._colorSignal.decode(bitField) ?? + $_math.max(0, message._colorSignal.min); + message.blink = + message._blinkSignal.decode(bitField) ?? + $_math.max(0, message._blinkSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _colorSignal: color, + _blinkSignal: blink, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_SetLED(\n Color=$color\n Blink=$blink\n)"; + } +} + +class DriveAppliedOutputMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_Applied_Output"; + + @override + int messageLength = 6; + + @override + int canId = 0x15; + + /// Whether or not "Drive_Applied_Output" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_Applied_Output" + static const String multiplexor = ""; + + /// Value of signal "Throttle" + num throttle; + + /// Value of signal "Left_Speed" + num leftSpeed; + + /// Value of signal "Right_Speed" + num rightSpeed; + + final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( + name: "Throttle", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 16, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + factor: 0.000016, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _leftSpeedSignal = $_dbc.DBCSignal( + name: "Left_Speed", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 16, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], + factor: 0.000062, + offset: 0.0, + min: -1.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _rightSpeedSignal = $_dbc.DBCSignal( + name: "Right_Speed", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 32, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], + factor: 0.000062, + offset: 0.0, + min: -1.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _throttleSignal, + _leftSpeedSignal, + _rightSpeedSignal, + ]; + + DriveAppliedOutputMessage({ + this.throttle = 0, + this.leftSpeed = 0, + this.rightSpeed = 0, + }); + + /// Creates a clone of this [DriveAppliedOutputMessage] with the non-null values replaced + DriveAppliedOutputMessage copyWith({ + num? throttle, + num? leftSpeed, + num? rightSpeed, + }) { + return DriveAppliedOutputMessage( + throttle: throttle ?? this.throttle, + leftSpeed: leftSpeed ?? this.leftSpeed, + rightSpeed: rightSpeed ?? this.rightSpeed, + ); + } + + factory DriveAppliedOutputMessage.fromBuffer(List buffer) { + final message = DriveAppliedOutputMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.throttle = + message._throttleSignal.decode(bitField) ?? + $_math.max(0, message._throttleSignal.min); + message.leftSpeed = + message._leftSpeedSignal.decode(bitField) ?? + $_math.max(0, message._leftSpeedSignal.min); + message.rightSpeed = + message._rightSpeedSignal.decode(bitField) ?? + $_math.max(0, message._rightSpeedSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _throttleSignal: throttle, + _leftSpeedSignal: leftSpeed, + _rightSpeedSignal: rightSpeed, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_Applied_Output(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)"; + } +} + +class DriveBatteryMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_Battery"; + + @override + int messageLength = 6; + + @override + int canId = 0x16; + + /// Whether or not "Drive_Battery" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_Battery" + static const String multiplexor = ""; + + /// Value of signal "Voltage" + num voltage; + + /// Value of signal "Temperature" + num temperature; + + /// Value of signal "Current" + num current; + + final $_dbc.DBCSignal _voltageSignal = $_dbc.DBCSignal( + name: "Voltage", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 16, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + factor: 0.001, + offset: 0.0, + min: 0.0, + max: 36.0, + unit: "V", + ); + + final $_dbc.DBCSignal _temperatureSignal = $_dbc.DBCSignal( + name: "Temperature", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 16, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + factor: 0.09, + offset: 50.0, + min: -40.0, + max: 150.0, + unit: "C", + ); + + final $_dbc.DBCSignal _currentSignal = $_dbc.DBCSignal( + name: "Current", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 28, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], + factor: 0.1, + offset: 0.0, + min: 0.0, + max: 30.0, + unit: "A", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _voltageSignal, + _temperatureSignal, + _currentSignal, + ]; + + DriveBatteryMessage({ + this.voltage = 0, + this.temperature = 50, + this.current = 0, + }); + + /// Creates a clone of this [DriveBatteryMessage] with the non-null values replaced + DriveBatteryMessage copyWith({ + num? voltage, + num? temperature, + num? current, + }) { + return DriveBatteryMessage( + voltage: voltage ?? this.voltage, + temperature: temperature ?? this.temperature, + current: current ?? this.current, + ); + } + + factory DriveBatteryMessage.fromBuffer(List buffer) { + final message = DriveBatteryMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.voltage = + message._voltageSignal.decode(bitField) ?? + $_math.max(0, message._voltageSignal.min); + message.temperature = + message._temperatureSignal.decode(bitField) ?? + $_math.max(0, message._temperatureSignal.min); + message.current = + message._currentSignal.decode(bitField) ?? + $_math.max(0, message._currentSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _voltageSignal: voltage, + _temperatureSignal: temperature, + _currentSignal: current, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_Battery(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)"; + } +} + +class RelaySetStateMessage extends $_dbc.DBCMessage { + @override + String messageName = "Relay_Set_State"; + + @override + int messageLength = 2; + + @override + int canId = 0x20; + + /// Whether or not "Relay_Set_State" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Relay_Set_State" + static const String multiplexor = ""; + + /// Value of signal "Update_Front_Left_Motor" + num updateFrontLeftMotor; + + /// Value of signal "Front_Left_Motor" + num frontLeftMotor; + + /// Value of signal "Update_Front_Right_Motor" + num updateFrontRightMotor; + + /// Value of signal "Front_Right_Motor" + num frontRightMotor; + + /// Value of signal "Update_Back_Left_Motor" + num updateBackLeftMotor; + + /// Value of signal "Back_Left_Motor" + num backLeftMotor; + + /// Value of signal "Update_Back_Right_Motor" + num updateBackRightMotor; + + /// Value of signal "Back_Right_Motor" + num backRightMotor; + + /// Value of signal "Update_Arm" + num updateArm; + + /// Value of signal "Arm" + num arm; + + /// Value of signal "Update_Science" + num updateScience; + + /// Value of signal "Science" + num science; + + /// Value of signal "Update_Drive" + num updateDrive; + + /// Value of signal "Drive" + num drive; + + final $_dbc.DBCSignal _updateFrontLeftMotorSignal = $_dbc.DBCSignal( + name: "Update_Front_Left_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 1, + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( + name: "Front_Left_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 1, + length: 1, + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _updateFrontRightMotorSignal = $_dbc.DBCSignal( + name: "Update_Front_Right_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( + name: "Front_Right_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 1, + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _updateBackLeftMotorSignal = $_dbc.DBCSignal( + name: "Update_Back_Left_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( + name: "Back_Left_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 5, + length: 1, + mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [5], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _updateBackRightMotorSignal = $_dbc.DBCSignal( + name: "Update_Back_Right_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 6, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [6], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( + name: "Back_Right_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 7, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [7], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _updateArmSignal = $_dbc.DBCSignal( + name: "Update_Arm", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 8, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [8], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( + name: "Arm", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 9, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [9], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _updateScienceSignal = $_dbc.DBCSignal( + name: "Update_Science", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 10, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [10], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( + name: "Science", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 11, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [11], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _updateDriveSignal = $_dbc.DBCSignal( + name: "Update_Drive", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 12, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [12], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( + name: "Drive", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 13, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [13], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _updateFrontLeftMotorSignal, + _frontLeftMotorSignal, + _updateFrontRightMotorSignal, + _frontRightMotorSignal, + _updateBackLeftMotorSignal, + _backLeftMotorSignal, + _updateBackRightMotorSignal, + _backRightMotorSignal, + _updateArmSignal, + _armSignal, + _updateScienceSignal, + _scienceSignal, + _updateDriveSignal, + _driveSignal, + ]; + + RelaySetStateMessage({ + this.updateFrontLeftMotor = 0, + this.frontLeftMotor = 0, + this.updateFrontRightMotor = 0, + this.frontRightMotor = 0, + this.updateBackLeftMotor = 0, + this.backLeftMotor = 0, + this.updateBackRightMotor = 0, + this.backRightMotor = 0, + this.updateArm = 0, + this.arm = 0, + this.updateScience = 0, + this.science = 0, + this.updateDrive = 0, + this.drive = 0, + }); + + /// Creates a clone of this [RelaySetStateMessage] with the non-null values replaced + RelaySetStateMessage copyWith({ + num? updateFrontLeftMotor, + num? frontLeftMotor, + num? updateFrontRightMotor, + num? frontRightMotor, + num? updateBackLeftMotor, + num? backLeftMotor, + num? updateBackRightMotor, + num? backRightMotor, + num? updateArm, + num? arm, + num? updateScience, + num? science, + num? updateDrive, + num? drive, + }) { + return RelaySetStateMessage( + updateFrontLeftMotor: updateFrontLeftMotor ?? this.updateFrontLeftMotor, + frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, + updateFrontRightMotor: updateFrontRightMotor ?? this.updateFrontRightMotor, + frontRightMotor: frontRightMotor ?? this.frontRightMotor, + updateBackLeftMotor: updateBackLeftMotor ?? this.updateBackLeftMotor, + backLeftMotor: backLeftMotor ?? this.backLeftMotor, + updateBackRightMotor: updateBackRightMotor ?? this.updateBackRightMotor, + backRightMotor: backRightMotor ?? this.backRightMotor, + updateArm: updateArm ?? this.updateArm, + arm: arm ?? this.arm, + updateScience: updateScience ?? this.updateScience, + science: science ?? this.science, + updateDrive: updateDrive ?? this.updateDrive, + drive: drive ?? this.drive, + ); + } + + factory RelaySetStateMessage.fromBuffer(List buffer) { + final message = RelaySetStateMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.updateFrontLeftMotor = + message._updateFrontLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateFrontLeftMotorSignal.min); + message.frontLeftMotor = + message._frontLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._frontLeftMotorSignal.min); + message.updateFrontRightMotor = + message._updateFrontRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateFrontRightMotorSignal.min); + message.frontRightMotor = + message._frontRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._frontRightMotorSignal.min); + message.updateBackLeftMotor = + message._updateBackLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateBackLeftMotorSignal.min); + message.backLeftMotor = + message._backLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._backLeftMotorSignal.min); + message.updateBackRightMotor = + message._updateBackRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateBackRightMotorSignal.min); + message.backRightMotor = + message._backRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._backRightMotorSignal.min); + message.updateArm = + message._updateArmSignal.decode(bitField) ?? + $_math.max(0, message._updateArmSignal.min); + message.arm = + message._armSignal.decode(bitField) ?? + $_math.max(0, message._armSignal.min); + message.updateScience = + message._updateScienceSignal.decode(bitField) ?? + $_math.max(0, message._updateScienceSignal.min); + message.science = + message._scienceSignal.decode(bitField) ?? + $_math.max(0, message._scienceSignal.min); + message.updateDrive = + message._updateDriveSignal.decode(bitField) ?? + $_math.max(0, message._updateDriveSignal.min); + message.drive = + message._driveSignal.decode(bitField) ?? + $_math.max(0, message._driveSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _updateFrontLeftMotorSignal: updateFrontLeftMotor, + _frontLeftMotorSignal: frontLeftMotor, + _updateFrontRightMotorSignal: updateFrontRightMotor, + _frontRightMotorSignal: frontRightMotor, + _updateBackLeftMotorSignal: updateBackLeftMotor, + _backLeftMotorSignal: backLeftMotor, + _updateBackRightMotorSignal: updateBackRightMotor, + _backRightMotorSignal: backRightMotor, + _updateArmSignal: updateArm, + _armSignal: arm, + _updateScienceSignal: updateScience, + _scienceSignal: science, + _updateDriveSignal: updateDrive, + _driveSignal: drive, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Relay_Set_State(\n Update_Front_Left_Motor=$updateFrontLeftMotor\n Front_Left_Motor=$frontLeftMotor\n Update_Front_Right_Motor=$updateFrontRightMotor\n Front_Right_Motor=$frontRightMotor\n Update_Back_Left_Motor=$updateBackLeftMotor\n Back_Left_Motor=$backLeftMotor\n Update_Back_Right_Motor=$updateBackRightMotor\n Back_Right_Motor=$backRightMotor\n Update_Arm=$updateArm\n Arm=$arm\n Update_Science=$updateScience\n Science=$science\n Update_Drive=$updateDrive\n Drive=$drive\n)"; + } +} + +class RelayStateMessage extends $_dbc.DBCMessage { + @override + String messageName = "Relay_State"; + + @override + int messageLength = 1; + + @override + int canId = 0x25; + + /// Whether or not "Relay_State" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Relay_State" + static const String multiplexor = ""; + + /// Value of signal "Front_Left_Motor" + num frontLeftMotor; + + /// Value of signal "Front_Right_Motor" + num frontRightMotor; + + /// Value of signal "Back_Left_Motor" + num backLeftMotor; + + /// Value of signal "Back_Right_Motor" + num backRightMotor; + + /// Value of signal "Drive" + num drive; + + /// Value of signal "Arm" + num arm; + + /// Value of signal "Science" + num science; + + /// Value of signal "Physical_Override" + num physicalOverride; + + final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( + name: "Front_Left_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 1, + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( + name: "Front_Right_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 1, + length: 1, + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( + name: "Back_Left_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( + name: "Back_Right_Motor", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 1, + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( + name: "Drive", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( + name: "Arm", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 5, + length: 1, + mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [5], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( + name: "Science", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 6, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [6], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _physicalOverrideSignal = $_dbc.DBCSignal( + name: "Physical_Override", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 7, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [7], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _frontLeftMotorSignal, + _frontRightMotorSignal, + _backLeftMotorSignal, + _backRightMotorSignal, + _driveSignal, + _armSignal, + _scienceSignal, + _physicalOverrideSignal, + ]; + + RelayStateMessage({ + this.frontLeftMotor = 0, + this.frontRightMotor = 0, + this.backLeftMotor = 0, + this.backRightMotor = 0, + this.drive = 0, + this.arm = 0, + this.science = 0, + this.physicalOverride = 0, + }); + + /// Creates a clone of this [RelayStateMessage] with the non-null values replaced + RelayStateMessage copyWith({ + num? frontLeftMotor, + num? frontRightMotor, + num? backLeftMotor, + num? backRightMotor, + num? drive, + num? arm, + num? science, + num? physicalOverride, + }) { + return RelayStateMessage( + frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, + frontRightMotor: frontRightMotor ?? this.frontRightMotor, + backLeftMotor: backLeftMotor ?? this.backLeftMotor, + backRightMotor: backRightMotor ?? this.backRightMotor, + drive: drive ?? this.drive, + arm: arm ?? this.arm, + science: science ?? this.science, + physicalOverride: physicalOverride ?? this.physicalOverride, + ); + } + + factory RelayStateMessage.fromBuffer(List buffer) { + final message = RelayStateMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.frontLeftMotor = + message._frontLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._frontLeftMotorSignal.min); + message.frontRightMotor = + message._frontRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._frontRightMotorSignal.min); + message.backLeftMotor = + message._backLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._backLeftMotorSignal.min); + message.backRightMotor = + message._backRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._backRightMotorSignal.min); + message.drive = + message._driveSignal.decode(bitField) ?? + $_math.max(0, message._driveSignal.min); + message.arm = + message._armSignal.decode(bitField) ?? + $_math.max(0, message._armSignal.min); + message.science = + message._scienceSignal.decode(bitField) ?? + $_math.max(0, message._scienceSignal.min); + message.physicalOverride = + message._physicalOverrideSignal.decode(bitField) ?? + $_math.max(0, message._physicalOverrideSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _frontLeftMotorSignal: frontLeftMotor, + _frontRightMotorSignal: frontRightMotor, + _backLeftMotorSignal: backLeftMotor, + _backRightMotorSignal: backRightMotor, + _driveSignal: drive, + _armSignal: arm, + _scienceSignal: science, + _physicalOverrideSignal: physicalOverride, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Relay_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)"; + } +} + +class DriveSetSwivelMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_SetSwivel"; + + @override + int messageLength = 7; + + @override + int canId = 0x12; + + /// Whether or not "Drive_SetSwivel" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_SetSwivel" + static const String multiplexor = ""; + + /// Value of signal "Set_Front_Swivel" + num setFrontSwivel; + + /// Value of signal "Set_Front_Tilt" + num setFrontTilt; + + /// Value of signal "Set_Rear_Swivel" + num setRearSwivel; + + /// Value of signal "Set_Rear_Tilt" + num setRearTilt; + + /// Value of signal "Front_Swivel" + num frontSwivel; + + /// Value of signal "Front_Tilt" + num frontTilt; + + /// Value of signal "Rear_Swivel" + num rearSwivel; + + /// Value of signal "Rear_Tilt" + num rearTilt; + + final $_dbc.DBCSignal _setFrontSwivelSignal = $_dbc.DBCSignal( + name: "Set_Front_Swivel", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 1, + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _setFrontTiltSignal = $_dbc.DBCSignal( + name: "Set_Front_Tilt", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 1, + length: 1, + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _setRearSwivelSignal = $_dbc.DBCSignal( + name: "Set_Rear_Swivel", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _setRearTiltSignal = $_dbc.DBCSignal( + name: "Set_Rear_Tilt", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 1, + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( + name: "Front_Swivel", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 12, + mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + factor: 0.0878, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "Degrees", + ); + + final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( + name: "Front_Tilt", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 16, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + factor: 0.0878, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "Degrees", + ); + + final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( + name: "Rear_Swivel", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 28, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], + factor: 0.0878, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "Degrees", + ); + + final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( + name: "Rear_Tilt", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 40, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], + factor: 0.0878, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "Degrees", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _setFrontSwivelSignal, + _setFrontTiltSignal, + _setRearSwivelSignal, + _setRearTiltSignal, + _frontSwivelSignal, + _frontTiltSignal, + _rearSwivelSignal, + _rearTiltSignal, + ]; + + DriveSetSwivelMessage({ + this.setFrontSwivel = 0, + this.setFrontTilt = 0, + this.setRearSwivel = 0, + this.setRearTilt = 0, + this.frontSwivel = 0, + this.frontTilt = 0, + this.rearSwivel = 0, + this.rearTilt = 0, + }); + + /// Creates a clone of this [DriveSetSwivelMessage] with the non-null values replaced + DriveSetSwivelMessage copyWith({ + num? setFrontSwivel, + num? setFrontTilt, + num? setRearSwivel, + num? setRearTilt, + num? frontSwivel, + num? frontTilt, + num? rearSwivel, + num? rearTilt, + }) { + return DriveSetSwivelMessage( + setFrontSwivel: setFrontSwivel ?? this.setFrontSwivel, + setFrontTilt: setFrontTilt ?? this.setFrontTilt, + setRearSwivel: setRearSwivel ?? this.setRearSwivel, + setRearTilt: setRearTilt ?? this.setRearTilt, + frontSwivel: frontSwivel ?? this.frontSwivel, + frontTilt: frontTilt ?? this.frontTilt, + rearSwivel: rearSwivel ?? this.rearSwivel, + rearTilt: rearTilt ?? this.rearTilt, + ); + } + + factory DriveSetSwivelMessage.fromBuffer(List buffer) { + final message = DriveSetSwivelMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.setFrontSwivel = + message._setFrontSwivelSignal.decode(bitField) ?? + $_math.max(0, message._setFrontSwivelSignal.min); + message.setFrontTilt = + message._setFrontTiltSignal.decode(bitField) ?? + $_math.max(0, message._setFrontTiltSignal.min); + message.setRearSwivel = + message._setRearSwivelSignal.decode(bitField) ?? + $_math.max(0, message._setRearSwivelSignal.min); + message.setRearTilt = + message._setRearTiltSignal.decode(bitField) ?? + $_math.max(0, message._setRearTiltSignal.min); + message.frontSwivel = + message._frontSwivelSignal.decode(bitField) ?? + $_math.max(0, message._frontSwivelSignal.min); + message.frontTilt = + message._frontTiltSignal.decode(bitField) ?? + $_math.max(0, message._frontTiltSignal.min); + message.rearSwivel = + message._rearSwivelSignal.decode(bitField) ?? + $_math.max(0, message._rearSwivelSignal.min); + message.rearTilt = + message._rearTiltSignal.decode(bitField) ?? + $_math.max(0, message._rearTiltSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _setFrontSwivelSignal: setFrontSwivel, + _setFrontTiltSignal: setFrontTilt, + _setRearSwivelSignal: setRearSwivel, + _setRearTiltSignal: setRearTilt, + _frontSwivelSignal: frontSwivel, + _frontTiltSignal: frontTilt, + _rearSwivelSignal: rearSwivel, + _rearTiltSignal: rearTilt, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)"; + } +} diff --git a/subsystems/lib/subsystems.dart b/subsystems/lib/subsystems.dart index ce023b35..ca78ffeb 100644 --- a/subsystems/lib/subsystems.dart +++ b/subsystems/lib/subsystems.dart @@ -1,6 +1,7 @@ import "dart:async"; import "package:burt_network/burt_network.dart"; +import "package:subsystems/src/devices/can_bus.dart"; import "src/devices/gps.dart"; import "src/devices/imu.dart"; @@ -33,6 +34,9 @@ class SubsystemsCollection extends Service { /// The IMU reader. final imu = ImuReader(); + /// The CAN bus + final can = CanBus(); + /// Timer for sending the subsystems status Timer? dataSendTimer; @@ -49,6 +53,7 @@ class SubsystemsCollection extends Service { result &= await firmware.init(); result &= await gps.init(); result &= await imu.init(); + result &= await can.init(); if (result) { logger.info("Subsystems initialized"); } else { @@ -70,6 +75,7 @@ class SubsystemsCollection extends Service { await firmware.dispose(); await imu.dispose(); await gps.dispose(); + await can.dispose(); await server.dispose(); dataSendTimer?.cancel(); logger.socket = null; diff --git a/subsystems/pubspec.yaml b/subsystems/pubspec.yaml index 463c202f..f37cc2d3 100644 --- a/subsystems/pubspec.yaml +++ b/subsystems/pubspec.yaml @@ -13,7 +13,10 @@ dependencies: burt_network: ^2.7.0 collection: ^1.19.0 csv: ^6.0.0 + dart_dbc_generator: + git: https://github.com/Gold872/dart_dbc_generator.git ffi: ^2.1.3 + linux_can: ^0.2.0 osc: ^1.0.0 dev_dependencies: From a3a44b6b84dee4e1bdae78d4f71b7bd337b0279d Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 1 Apr 2025 23:45:41 -0400 Subject: [PATCH 02/30] Updated messages and added network streaming + other fixes --- subsystems/lib/src/devices/can_bus.dart | 109 ++++++++++++++--- .../lib/src/generated/rover_messages.dbc.dart | 110 +++++++++++++++++- 2 files changed, 203 insertions(+), 16 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index c9bbcc41..60c3e15a 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -22,6 +22,26 @@ extension on BoolState { int get intValue => this == BoolState.YES ? 1 : 0; } +extension on DeviceBroadcastMessage { + Message toDriveProto() => DriveData(version: version); + + Message toRelayProto() => RelaysData(); + + Message? toProtoMessage() { + if (deviceName.toInt() == Device.DRIVE.value) { + return toDriveProto(); + } else if (deviceName.toInt() == Device.RELAY.value) { + return toRelayProto(); + } + return null; + } + + Version get version => Version( + major: fwVersionMajor.toInt(), + minor: fwVersionMinor.toInt(), + ); +} + extension on DriveAppliedOutputMessage { DriveData toDriveProto() => DriveData( throttle: throttle.toDouble(), @@ -41,6 +61,12 @@ extension on DriveBatteryMessage { ); } +extension on DriveLedMessage { + DriveData toDriveProto() => DriveData( + color: ProtoColor.valueOf(color.toInt()), + ); +} + extension on DriveCommand { DBCMessage get asSetSpeeds => DriveSetSpeedsMessage( shouldSetLeft: setLeft.intValue, @@ -110,22 +136,34 @@ extension on RelaysCommand { } /// A service to forward messages between CAN and UDP +/// +/// Simliar to the firmware service, this service will stream incoming +/// messages from the network, and send specific types of messages over +/// the CAN bus as its corresponding DBC message. +/// +/// For safety reasons, this service will send and receive heartbeats +/// over the CAN bus, to ensure every device knows it's connected to the +/// rover, and so the rover can determine every device connected, and their +/// firmware versions. class CanBus extends Service { /// How often to send a rover heartbeat over the CAN bus static const Duration heartbeatPeriod = Duration(milliseconds: 100); /// The maximum time the program should wait for a device's heartbeat before /// it's considered disconnected - static const Duration heartbeatTimeout = Duration(milliseconds: 500); + static const Duration heartbeatTimeout = Duration(milliseconds: 250); /// A map of devices and the last time their broadcast message was received final Map deviceHeartbeats = {}; /// The CAN socket for the CAN bus CanSocket? socket; - Timer? _heartbeatTimer; + Timer? _sendHeartbeatTimer; + Timer? _checkHeartbeatsTimer; StreamSubscription? _frameSubscription; + StreamSubscription? _driveSubscription; + StreamSubscription? _relaySubscription; @override Future init() async { @@ -156,16 +194,41 @@ class CanBus extends Service { } socket = canDevice.open(); _frameSubscription = socket!.receive().listen(_onCanFrame); - _heartbeatTimer = Timer.periodic(heartbeatPeriod, (_) => sendHeartbeat()); + _sendHeartbeatTimer = Timer.periodic( + heartbeatPeriod, + (_) => sendHeartbeat(), + ); + _checkHeartbeatsTimer = Timer.periodic( + heartbeatTimeout, + (_) => checkHeartbeats(), + ); + + _driveSubscription = collection.server.messages.onMessage( + name: DriveCommand().messageName, + constructor: DriveCommand.fromBuffer, + callback: send, + ); + + _relaySubscription = collection.server.messages.onMessage( + name: RelaysCommand().messageName, + constructor: RelaysCommand.fromBuffer, + callback: send, + ); return true; } @override Future dispose() async { + _sendHeartbeatTimer?.cancel(); + _checkHeartbeatsTimer?.cancel(); + + await _driveSubscription?.cancel(); + await _relaySubscription?.cancel(); await _frameSubscription?.cancel(); await socket?.close(); - _heartbeatTimer?.cancel(); + + deviceHeartbeats.clear(); } /// Sends a message's DBC equivalent over the CAN bus @@ -181,12 +244,15 @@ class CanBus extends Service { void sendHeartbeat() { final heartbeat = RoverHeartbeatMessage(); sendDBCMessage(heartbeat); + } + /// Checks all device's heartbeats and determines if they are still connected + void checkHeartbeats() { final now = DateTime.timestamp(); deviceHeartbeats.removeWhere((device, time) { if (now.difference(time) > heartbeatTimeout) { logger.warning( - "${device.name} disconnected.", + "${device.name} disconnected from CAN bus", body: "Broadcast message not received after $heartbeatTimeout", ); return true; @@ -197,16 +263,20 @@ class CanBus extends Service { /// Sends a DBC message over the CAN bus void sendDBCMessage(DBCMessage message) { - try { - socket?.send( - CanFrame.standard( - id: message.canId, - data: message.writeToBuffer(), - ), - ); - } catch (e) { - logger.error("Error when sending CAN message", body: e.toString()); - } + socket + ?.send( + CanFrame.standard( + id: message.canId, + data: message.writeToBuffer(), + ), + ) + .catchError((Object e) { + if (e.toString().contains("No buffer space")) { + logger.debug("Error when sending CAN message", body: e.toString()); + } else { + logger.error("Error when sending CAN message", body: e.toString()); + } + }); } void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { @@ -222,6 +292,11 @@ class CanBus extends Service { logger.info("${device.name} connected via CAN bus"); } deviceHeartbeats[device] = DateTime.timestamp(); + + final versionProto = broadcast.toProtoMessage(); + if (versionProto != null) { + collection.server.sendMessage(versionProto); + } } void _onCanFrame(CanFrame frame) { @@ -237,6 +312,10 @@ class CanBus extends Service { collection.server.sendMessage( DriveBatteryMessage.fromBuffer(data).toDriveProto(), ); + } else if (id == DriveLedMessage().canId) { + collection.server.sendMessage( + DriveLedMessage.fromBuffer(data).toDriveProto(), + ); } else if (id == RelayStateMessage().canId) { collection.server.sendMessage( RelayStateMessage.fromBuffer(data).toRelayProto(), diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 9ad1764d..cac0a11f 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -726,7 +726,7 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { length: 16, mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.001, + factor: 0.00055, offset: 0.0, min: 0.0, max: 36.0, @@ -1822,3 +1822,111 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { return "Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)"; } } + +class DriveLedMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_LED"; + + @override + int messageLength = 1; + + @override + int canId = 0x17; + + /// Whether or not "Drive_LED" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_LED" + static const String multiplexor = ""; + + /// Value of signal "Color" + num color; + + /// Value of signal "Blink" + num blink; + + final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( + name: "Color", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 4, + mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 8.0, + unit: "", + ); + + final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( + name: "Blink", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _colorSignal, + _blinkSignal, + ]; + + DriveLedMessage({ + this.color = 0, + this.blink = 0, + }); + + /// Creates a clone of this [DriveLedMessage] with the non-null values replaced + DriveLedMessage copyWith({ + num? color, + num? blink, + }) { + return DriveLedMessage( + color: color ?? this.color, + blink: blink ?? this.blink, + ); + } + + factory DriveLedMessage.fromBuffer(List buffer) { + final message = DriveLedMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.color = + message._colorSignal.decode(bitField) ?? + $_math.max(0, message._colorSignal.min); + message.blink = + message._blinkSignal.decode(bitField) ?? + $_math.max(0, message._blinkSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _colorSignal: color, + _blinkSignal: blink, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_LED(\n Color=$color\n Blink=$blink\n)"; + } +} From 3bfba2400d4ba5191e16d6938f6afa3b98a1293c Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 6 Apr 2025 00:09:52 -0400 Subject: [PATCH 03/30] Updated messages --- .../lib/src/generated/rover_messages.dbc.dart | 402 ++++++++++++------ 1 file changed, 283 insertions(+), 119 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index cac0a11f..4202997e 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -555,6 +555,114 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { } } +class DriveLedMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_LED"; + + @override + int messageLength = 1; + + @override + int canId = 0x17; + + /// Whether or not "Drive_LED" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_LED" + static const String multiplexor = ""; + + /// Value of signal "Color" + num color; + + /// Value of signal "Blink" + num blink; + + final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( + name: "Color", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 4, + mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 8.0, + unit: "", + ); + + final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( + name: "Blink", + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4], + factor: 1.0, + offset: 0.0, + min: 0.0, + max: 1.0, + unit: "", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _colorSignal, + _blinkSignal, + ]; + + DriveLedMessage({ + this.color = 0, + this.blink = 0, + }); + + /// Creates a clone of this [DriveLedMessage] with the non-null values replaced + DriveLedMessage copyWith({ + num? color, + num? blink, + }) { + return DriveLedMessage( + color: color ?? this.color, + blink: blink ?? this.blink, + ); + } + + factory DriveLedMessage.fromBuffer(List buffer) { + final message = DriveLedMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.color = + message._colorSignal.decode(bitField) ?? + $_math.max(0, message._colorSignal.min); + message.blink = + message._blinkSignal.decode(bitField) ?? + $_math.max(0, message._blinkSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _colorSignal: color, + _blinkSignal: blink, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_LED(\n Color=$color\n Blink=$blink\n)"; + } +} + class DriveAppliedOutputMessage extends $_dbc.DBCMessage { @override String messageName = "Drive_Applied_Output"; @@ -827,6 +935,170 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { } } +class DriveSwivelMessage extends $_dbc.DBCMessage { + @override + String messageName = "Drive_Swivel"; + + @override + int messageLength = 6; + + @override + int canId = 0x18; + + /// Whether or not "Drive_Swivel" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_Swivel" + static const String multiplexor = ""; + + /// Value of signal "Front_Swivel" + num frontSwivel; + + /// Value of signal "Front_Tilt" + num frontTilt; + + /// Value of signal "Rear_Swivel" + num rearSwivel; + + /// Value of signal "Rear_Tilt" + num rearTilt; + + final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( + name: "Front_Swivel", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 12, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + factor: 0.044, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "°", + ); + + final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( + name: "Front_Tilt", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 12, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], + factor: 0.044, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "°", + ); + + final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( + name: "Rear_Swivel", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 24, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], + factor: 0.044, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "°", + ); + + final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( + name: "Rear_Tilt", + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 36, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], + factor: 0.044, + offset: 0.0, + min: -90.0, + max: 90.0, + unit: "°", + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _frontSwivelSignal, + _frontTiltSignal, + _rearSwivelSignal, + _rearTiltSignal, + ]; + + DriveSwivelMessage({ + this.frontSwivel = 0, + this.frontTilt = 0, + this.rearSwivel = 0, + this.rearTilt = 0, + }); + + /// Creates a clone of this [DriveSwivelMessage] with the non-null values replaced + DriveSwivelMessage copyWith({ + num? frontSwivel, + num? frontTilt, + num? rearSwivel, + num? rearTilt, + }) { + return DriveSwivelMessage( + frontSwivel: frontSwivel ?? this.frontSwivel, + frontTilt: frontTilt ?? this.frontTilt, + rearSwivel: rearSwivel ?? this.rearSwivel, + rearTilt: rearTilt ?? this.rearTilt, + ); + } + + factory DriveSwivelMessage.fromBuffer(List buffer) { + final message = DriveSwivelMessage(); + final typedBuffer = $_typed.Uint8List.fromList(buffer); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.frontSwivel = + message._frontSwivelSignal.decode(bitField) ?? + $_math.max(0, message._frontSwivelSignal.min); + message.frontTilt = + message._frontTiltSignal.decode(bitField) ?? + $_math.max(0, message._frontTiltSignal.min); + message.rearSwivel = + message._rearSwivelSignal.decode(bitField) ?? + $_math.max(0, message._rearSwivelSignal.min); + message.rearTilt = + message._rearTiltSignal.decode(bitField) ?? + $_math.max(0, message._rearTiltSignal.min); + + return message; + } + + @override + $_typed.Uint8List writeToBuffer() { + final Map<$_dbc.DBCSignal, num> values = { + _frontSwivelSignal: frontSwivel, + _frontTiltSignal: frontTilt, + _rearSwivelSignal: rearSwivel, + _rearTiltSignal: rearTilt, + }; + + return encodeMessage(values); + } + + @override + String toString() { + return "Drive_Swivel(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)"; + } +} + class RelaySetStateMessage extends $_dbc.DBCMessage { @override String messageName = "Relay_Set_State"; @@ -1665,16 +1937,16 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.0878, + factor: 0.044, offset: 0.0, min: -90.0, max: 90.0, - unit: "Degrees", + unit: "°", ); final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( name: "Front_Tilt", - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, @@ -1682,16 +1954,16 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 0.0878, + factor: 0.044, offset: 0.0, min: -90.0, max: 90.0, - unit: "Degrees", + unit: "°", ); final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( name: "Rear_Swivel", - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, @@ -1699,16 +1971,16 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], - factor: 0.0878, + factor: 0.044, offset: 0.0, min: -90.0, max: 90.0, - unit: "Degrees", + unit: "°", ); final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( name: "Rear_Tilt", - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, @@ -1716,11 +1988,11 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], - factor: 0.0878, + factor: 0.044, offset: 0.0, min: -90.0, max: 90.0, - unit: "Degrees", + unit: "°", ); @override @@ -1822,111 +2094,3 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { return "Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)"; } } - -class DriveLedMessage extends $_dbc.DBCMessage { - @override - String messageName = "Drive_LED"; - - @override - int messageLength = 1; - - @override - int canId = 0x17; - - /// Whether or not "Drive_LED" is multiplex - static const bool isMultiplex = false; - - /// The multiplexor for "Drive_LED" - static const String multiplexor = ""; - - /// Value of signal "Color" - num color; - - /// Value of signal "Blink" - num blink; - - final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( - name: "Color", - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 0, - length: 4, - mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 8.0, - unit: "", - ); - - final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( - name: "Blink", - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 4, - length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [4], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", - ); - - @override - List<$_dbc.DBCSignal> get signals => [ - _colorSignal, - _blinkSignal, - ]; - - DriveLedMessage({ - this.color = 0, - this.blink = 0, - }); - - /// Creates a clone of this [DriveLedMessage] with the non-null values replaced - DriveLedMessage copyWith({ - num? color, - num? blink, - }) { - return DriveLedMessage( - color: color ?? this.color, - blink: blink ?? this.blink, - ); - } - - factory DriveLedMessage.fromBuffer(List buffer) { - final message = DriveLedMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.color = - message._colorSignal.decode(bitField) ?? - $_math.max(0, message._colorSignal.min); - message.blink = - message._blinkSignal.decode(bitField) ?? - $_math.max(0, message._blinkSignal.min); - - return message; - } - - @override - $_typed.Uint8List writeToBuffer() { - final Map<$_dbc.DBCSignal, num> values = { - _colorSignal: color, - _blinkSignal: blink, - }; - - return encodeMessage(values); - } - - @override - String toString() { - return "Drive_LED(\n Color=$color\n Blink=$blink\n)"; - } -} From 39903538bcac2d1aa3e73cb31e59671b22b92386 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 6 Apr 2025 00:10:07 -0400 Subject: [PATCH 04/30] Only send CAN commands if device is connected --- subsystems/lib/src/devices/can_bus.dart | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 60c3e15a..6406be60 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -156,6 +156,9 @@ class CanBus extends Service { /// A map of devices and the last time their broadcast message was received final Map deviceHeartbeats = {}; + /// A list of all the devices connected to the CAN bus + List get connectedDevices => deviceHeartbeats.keys.toList(); + /// The CAN socket for the CAN bus CanSocket? socket; Timer? _sendHeartbeatTimer; @@ -231,11 +234,19 @@ class CanBus extends Service { deviceHeartbeats.clear(); } + bool _deviceConnected(Device device) => deviceHeartbeats.containsKey(device); + /// Sends a message's DBC equivalent over the CAN bus void send(Message message) { if (message is DriveCommand) { + if (!_deviceConnected(Device.DRIVE)) { + return; + } message.toDBC().forEach(sendDBCMessage); } else if (message is RelaysCommand) { + if (!_deviceConnected(Device.RELAY)) { + return; + } message.toDBC().forEach(sendDBCMessage); } } From fb4dcf4b337f272593123bcf056d6af8e42a2203 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 7 Apr 2025 19:19:18 -0400 Subject: [PATCH 05/30] Reformat and simplified send() --- subsystems/lib/src/devices/can_bus.dart | 161 ++++++++++++------------ 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 6406be60..033464af 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -36,62 +36,57 @@ extension on DeviceBroadcastMessage { return null; } - Version get version => Version( - major: fwVersionMajor.toInt(), - minor: fwVersionMinor.toInt(), - ); + Version get version => + Version(major: fwVersionMajor.toInt(), minor: fwVersionMinor.toInt()); } extension on DriveAppliedOutputMessage { DriveData toDriveProto() => DriveData( - throttle: throttle.toDouble(), - left: leftSpeed.toDouble(), - right: rightSpeed.toDouble(), - setLeft: true, - setRight: true, - setThrottle: true, - ); + throttle: throttle.toDouble(), + left: leftSpeed.toDouble(), + right: rightSpeed.toDouble(), + setLeft: true, + setRight: true, + setThrottle: true, + ); } extension on DriveBatteryMessage { DriveData toDriveProto() => DriveData( - batteryVoltage: voltage.toDouble(), - batteryTemperature: temperature.toDouble(), - batteryCurrent: current.toDouble(), - ); + batteryVoltage: voltage.toDouble(), + batteryTemperature: temperature.toDouble(), + batteryCurrent: current.toDouble(), + ); } extension on DriveLedMessage { - DriveData toDriveProto() => DriveData( - color: ProtoColor.valueOf(color.toInt()), - ); + DriveData toDriveProto() => + DriveData(color: ProtoColor.valueOf(color.toInt())); } extension on DriveCommand { DBCMessage get asSetSpeeds => DriveSetSpeedsMessage( - shouldSetLeft: setLeft.intValue, - shouldSetRight: setRight.intValue, - shouldSetThrottle: setThrottle.intValue, - leftSpeed: left, - rightSpeed: right, - throttle: throttle, - ); + shouldSetLeft: setLeft.intValue, + shouldSetRight: setRight.intValue, + shouldSetThrottle: setThrottle.intValue, + leftSpeed: left, + rightSpeed: right, + throttle: throttle, + ); - DBCMessage get asSetLEDS => DriveSetLedMessage( - color: color.value, - blink: blink.intValue, - ); + DBCMessage get asSetLEDS => + DriveSetLedMessage(color: color.value, blink: blink.intValue); DBCMessage get asSetSwivels => DriveSetSwivelMessage( - setFrontSwivel: hasFrontSwivel().intValue, - setFrontTilt: hasFrontTilt().intValue, - setRearSwivel: hasRearSwivel().intValue, - setRearTilt: hasRearTilt().intValue, - frontSwivel: frontSwivel, - frontTilt: frontTilt, - rearSwivel: rearSwivel, - rearTilt: rearTilt, - ); + setFrontSwivel: hasFrontSwivel().intValue, + setFrontTilt: hasFrontTilt().intValue, + setRearSwivel: hasRearSwivel().intValue, + setRearTilt: hasRearTilt().intValue, + frontSwivel: frontSwivel, + frontTilt: frontTilt, + rearSwivel: rearSwivel, + rearTilt: rearTilt, + ); List toDBC() { final output = []; @@ -113,24 +108,24 @@ extension on DriveCommand { extension on RelayStateMessage { RelaysData toRelayProto() => RelaysData( - frontLeftMotor: frontLeftMotor.boolState, - frontRightMotor: frontRightMotor.boolState, - backLeftMotor: backLeftMotor.boolState, - backRightMotor: backRightMotor.boolState, - arm: arm.boolState, - drive: drive.boolState, - science: science.boolState, - ); + frontLeftMotor: frontLeftMotor.boolState, + frontRightMotor: frontRightMotor.boolState, + backLeftMotor: backLeftMotor.boolState, + backRightMotor: backRightMotor.boolState, + arm: arm.boolState, + drive: drive.boolState, + science: science.boolState, + ); } extension on RelaysCommand { DBCMessage get asSetState => RelaySetStateMessage( - updateArm: hasArm().intValue, - updateFrontLeftMotor: hasFrontLeftMotor().intValue, - updateFrontRightMotor: hasFrontRightMotor().intValue, - updateBackLeftMotor: hasBackLeftMotor().intValue, - updateBackRightMotor: hasBackRightMotor().intValue, - ); + updateArm: hasArm().intValue, + updateFrontLeftMotor: hasFrontLeftMotor().intValue, + updateFrontRightMotor: hasFrontRightMotor().intValue, + updateBackLeftMotor: hasBackLeftMotor().intValue, + updateBackRightMotor: hasBackRightMotor().intValue, + ); List toDBC() => [asSetState]; } @@ -189,10 +184,7 @@ class CanBus extends Service { (device) => device.networkInterface.name == "can0", ); if (!canDevice.isUp) { - logger.error( - "CAN0 is not up", - body: "Device state: ${canDevice.state}", - ); + logger.error("CAN0 is not up", body: "Device state: ${canDevice.state}"); return false; } socket = canDevice.open(); @@ -209,13 +201,13 @@ class CanBus extends Service { _driveSubscription = collection.server.messages.onMessage( name: DriveCommand().messageName, constructor: DriveCommand.fromBuffer, - callback: send, + callback: sendDriveCommand, ); _relaySubscription = collection.server.messages.onMessage( name: RelaysCommand().messageName, constructor: RelaysCommand.fromBuffer, - callback: send, + callback: sendRelaysCommand, ); return true; @@ -236,18 +228,36 @@ class CanBus extends Service { bool _deviceConnected(Device device) => deviceHeartbeats.containsKey(device); + /// Sends a drive command over the CAN bus + /// + /// If [override] is set to false, the command will only be sent if the rover + /// has received heartbeats from the drive device. The [override] should only + /// be true if this is a stop command. + void sendDriveCommand(DriveCommand command, {bool override = false}) { + if (!_deviceConnected(Device.DRIVE) && !override) { + return; + } + command.toDBC().forEach(sendDBCMessage); + } + + /// Sends a relay command over the CAN bus + /// + /// If [override] is set to false, the command will only be sent if the rover + /// has received heartbeats from the relay device. The [override] should only + /// be true if this is a stop command. + void sendRelaysCommand(RelaysCommand command, {bool override = false}) { + if (!_deviceConnected(Device.RELAY) && !override) { + return; + } + command.toDBC().forEach(sendDBCMessage); + } + /// Sends a message's DBC equivalent over the CAN bus void send(Message message) { if (message is DriveCommand) { - if (!_deviceConnected(Device.DRIVE)) { - return; - } - message.toDBC().forEach(sendDBCMessage); + sendDriveCommand(message); } else if (message is RelaysCommand) { - if (!_deviceConnected(Device.RELAY)) { - return; - } - message.toDBC().forEach(sendDBCMessage); + sendRelaysCommand(message); } } @@ -276,18 +286,15 @@ class CanBus extends Service { void sendDBCMessage(DBCMessage message) { socket ?.send( - CanFrame.standard( - id: message.canId, - data: message.writeToBuffer(), - ), - ) + CanFrame.standard(id: message.canId, data: message.writeToBuffer()), + ) .catchError((Object e) { - if (e.toString().contains("No buffer space")) { - logger.debug("Error when sending CAN message", body: e.toString()); - } else { - logger.error("Error when sending CAN message", body: e.toString()); - } - }); + if (e.toString().contains("No buffer space")) { + logger.debug("Error when sending CAN message", body: e.toString()); + } else { + logger.error("Error when sending CAN message", body: e.toString()); + } + }); } void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { From f8228f4c2fb0dc91f60bc638694d439d8221aa28 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 8 Apr 2025 01:41:55 -0400 Subject: [PATCH 06/30] Fix relays and add auto restart on failure --- subsystems/lib/src/devices/can_bus.dart | 74 +++++++++++++++++++------ 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 033464af..878955bc 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -121,10 +121,19 @@ extension on RelayStateMessage { extension on RelaysCommand { DBCMessage get asSetState => RelaySetStateMessage( updateArm: hasArm().intValue, + arm: arm.intValue, updateFrontLeftMotor: hasFrontLeftMotor().intValue, + frontLeftMotor: frontLeftMotor.intValue, updateFrontRightMotor: hasFrontRightMotor().intValue, + frontRightMotor: frontRightMotor.intValue, updateBackLeftMotor: hasBackLeftMotor().intValue, + backLeftMotor: backLeftMotor.intValue, updateBackRightMotor: hasBackRightMotor().intValue, + backRightMotor: backRightMotor.intValue, + updateDrive: hasDrive().intValue, + drive: drive.intValue, + updateScience: hasScience().intValue, + science: science.intValue, ); List toDBC() => [asSetState]; @@ -154,6 +163,9 @@ class CanBus extends Service { /// A list of all the devices connected to the CAN bus List get connectedDevices => deviceHeartbeats.keys.toList(); + /// The CAN device for the CAN bus + CanDevice? device; + /// The CAN socket for the CAN bus CanSocket? socket; Timer? _sendHeartbeatTimer; @@ -180,14 +192,17 @@ class CanBus extends Service { "bitrate", "500000", ]); - final canDevice = LinuxCan.instance.devices.singleWhere( + device = LinuxCan.instance.devices.singleWhere( (device) => device.networkInterface.name == "can0", ); - if (!canDevice.isUp) { - logger.error("CAN0 is not up", body: "Device state: ${canDevice.state}"); + if (!device!.isUp) { + logger.error("CAN0 is not up", body: "Device state: ${device!.state}"); return false; } - socket = canDevice.open(); + logger.info( + "Initializing CAN socket for device ${device!.networkInterface.name}", + ); + socket = device!.open(); _frameSubscription = socket!.receive().listen(_onCanFrame); _sendHeartbeatTimer = Timer.periodic( heartbeatPeriod, @@ -218,10 +233,12 @@ class CanBus extends Service { _sendHeartbeatTimer?.cancel(); _checkHeartbeatsTimer?.cancel(); + await socket?.close(); + socket = null; + await _driveSubscription?.cancel(); await _relaySubscription?.cancel(); await _frameSubscription?.cancel(); - await socket?.close(); deviceHeartbeats.clear(); } @@ -233,11 +250,14 @@ class CanBus extends Service { /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the drive device. The [override] should only /// be true if this is a stop command. - void sendDriveCommand(DriveCommand command, {bool override = false}) { + Future sendDriveCommand( + DriveCommand command, { + bool override = false, + }) async { if (!_deviceConnected(Device.DRIVE) && !override) { return; } - command.toDBC().forEach(sendDBCMessage); + return Future.forEach(command.toDBC(), sendDBCMessage); } /// Sends a relay command over the CAN bus @@ -245,26 +265,29 @@ class CanBus extends Service { /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the relay device. The [override] should only /// be true if this is a stop command. - void sendRelaysCommand(RelaysCommand command, {bool override = false}) { + Future sendRelaysCommand( + RelaysCommand command, { + bool override = false, + }) async { if (!_deviceConnected(Device.RELAY) && !override) { return; } - command.toDBC().forEach(sendDBCMessage); + return Future.forEach(command.toDBC(), sendDBCMessage); } /// Sends a message's DBC equivalent over the CAN bus - void send(Message message) { + Future send(Message message) async { if (message is DriveCommand) { - sendDriveCommand(message); + return sendDriveCommand(message); } else if (message is RelaysCommand) { - sendRelaysCommand(message); + return sendRelaysCommand(message); } } /// Sends a heartbeat message over the CAN bus - void sendHeartbeat() { + Future sendHeartbeat() { final heartbeat = RoverHeartbeatMessage(); - sendDBCMessage(heartbeat); + return sendDBCMessage(heartbeat); } /// Checks all device's heartbeats and determines if they are still connected @@ -283,17 +306,34 @@ class CanBus extends Service { } /// Sends a DBC message over the CAN bus - void sendDBCMessage(DBCMessage message) { - socket + Future sendDBCMessage(DBCMessage message) async { + if (socket == null) { + return; + } + if (!(device?.isUp ?? false)) { + logger.warning( + "Device is not up while trying to send message, restarting CAN socket", + ); + await dispose(); + await Future.delayed(const Duration(milliseconds: 1000)); + await init(); + return; + } + return socket ?.send( CanFrame.standard(id: message.canId, data: message.writeToBuffer()), ) - .catchError((Object e) { + .catchError((Object e) async { if (e.toString().contains("No buffer space")) { logger.debug("Error when sending CAN message", body: e.toString()); } else { logger.error("Error when sending CAN message", body: e.toString()); } + + if (!(device?.isUp ?? false)) { + await dispose(); + await init(); + } }); } From 6ee4beaacd98110d1e1df02f1ab378236320c8d0 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 8 Apr 2025 01:45:56 -0400 Subject: [PATCH 07/30] Add drive swivel data decoding --- subsystems/lib/src/devices/can_bus.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 878955bc..11742f91 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -64,6 +64,15 @@ extension on DriveLedMessage { DriveData(color: ProtoColor.valueOf(color.toInt())); } +extension on DriveSwivelMessage { + DriveData toDriveProto() => DriveData( + frontSwivel: frontSwivel.toDouble(), + frontTilt: frontTilt.toDouble(), + rearSwivel: rearSwivel.toDouble(), + rearTilt: rearTilt.toDouble(), + ); +} + extension on DriveCommand { DBCMessage get asSetSpeeds => DriveSetSpeedsMessage( shouldSetLeft: setLeft.intValue, @@ -374,6 +383,10 @@ class CanBus extends Service { collection.server.sendMessage( DriveLedMessage.fromBuffer(data).toDriveProto(), ); + } else if (id == DriveSwivelMessage().canId) { + collection.server.sendMessage( + DriveSwivelMessage.fromBuffer(data).toDriveProto(), + ); } else if (id == RelayStateMessage().canId) { collection.server.sendMessage( RelayStateMessage.fromBuffer(data).toRelayProto(), From 0573a4950b5538acbb04cfbfb2ce3b4226395ff4 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 15 Apr 2025 03:11:14 -0400 Subject: [PATCH 08/30] Updated dart dbc generator --- subsystems/lib/src/devices/can_bus.dart | 16 +- .../lib/src/generated/rover_messages.dbc.dart | 1293 ++++++++++------- 2 files changed, 746 insertions(+), 563 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 11742f91..05dd3cc1 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -329,9 +329,7 @@ class CanBus extends Service { return; } return socket - ?.send( - CanFrame.standard(id: message.canId, data: message.writeToBuffer()), - ) + ?.send(CanFrame.standard(id: message.canId, data: message.encode())) .catchError((Object e) async { if (e.toString().contains("No buffer space")) { logger.debug("Error when sending CAN message", body: e.toString()); @@ -370,26 +368,26 @@ class CanBus extends Service { switch (frame) { case CanDataFrame(:final id, :final data): if (id == DeviceBroadcastMessage().canId) { - _handleDeviceBroadcast(DeviceBroadcastMessage.fromBuffer(data)); + _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); } else if (id == DriveAppliedOutputMessage().canId) { collection.server.sendMessage( - DriveAppliedOutputMessage.fromBuffer(data).toDriveProto(), + DriveAppliedOutputMessage.decode(data).toDriveProto(), ); } else if (id == DriveBatteryMessage().canId) { collection.server.sendMessage( - DriveBatteryMessage.fromBuffer(data).toDriveProto(), + DriveBatteryMessage.decode(data).toDriveProto(), ); } else if (id == DriveLedMessage().canId) { collection.server.sendMessage( - DriveLedMessage.fromBuffer(data).toDriveProto(), + DriveLedMessage.decode(data).toDriveProto(), ); } else if (id == DriveSwivelMessage().canId) { collection.server.sendMessage( - DriveSwivelMessage.fromBuffer(data).toDriveProto(), + DriveSwivelMessage.decode(data).toDriveProto(), ); } else if (id == RelayStateMessage().canId) { collection.server.sendMessage( - RelayStateMessage.fromBuffer(data).toRelayProto(), + RelayStateMessage.decode(data).toRelayProto(), ); } case CanRemoteFrame _: diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 4202997e..4c7525ae 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -13,7 +13,7 @@ import 'package:dart_dbc_generator/dart_dbc_generator.dart' as $_dbc; class RoverHeartbeatMessage extends $_dbc.DBCMessage { @override - String messageName = "Rover_Heartbeat"; + String messageName = 'Rover_Heartbeat'; @override int messageLength = 1; @@ -25,26 +25,26 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Rover_Heartbeat" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Rover_Status" num roverStatus; final $_dbc.DBCSignal _roverStatusSignal = $_dbc.DBCSignal( - name: "Rover_Status", + name: 'Rover_Status', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 4, - mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 5.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 5, + unit: '', ); @override @@ -59,16 +59,15 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { /// Creates a clone of this [RoverHeartbeatMessage] with the non-null values replaced RoverHeartbeatMessage copyWith({ num? roverStatus, - }) { - return RoverHeartbeatMessage( - roverStatus: roverStatus ?? this.roverStatus, - ); - } + }) => RoverHeartbeatMessage( + roverStatus: roverStatus ?? this.roverStatus, + ); - factory RoverHeartbeatMessage.fromBuffer(List buffer) { + factory RoverHeartbeatMessage.decode(List payload) { final message = RoverHeartbeatMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.roverStatus = message._roverStatusSignal.decode(bitField) ?? $_math.max(0, message._roverStatusSignal.min); @@ -76,24 +75,34 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { return message; } + factory RoverHeartbeatMessage.fromJson(Map json) => + RoverHeartbeatMessage( + roverStatus: json['Rover_Status'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _roverStatusSignal: roverStatus, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Rover_Status': roverStatus, + }; + @override String toString() { - return "Rover_Heartbeat(\n Rover_Status=$roverStatus\n)"; + return 'Rover_Heartbeat(\n Rover_Status=$roverStatus\n)'; } } class DeviceBroadcastMessage extends $_dbc.DBCMessage { @override - String messageName = "Device_Broadcast"; + String messageName = 'Device_Broadcast'; @override int messageLength = 2; @@ -105,7 +114,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Device_Broadcast" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Device_Name" num deviceName; @@ -117,54 +126,54 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { num fwVersionMinor; final $_dbc.DBCSignal _deviceNameSignal = $_dbc.DBCSignal( - name: "Device_Name", + name: 'Device_Name', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 5, - mapping: [1, 2, 4, 8, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 15.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 15, + unit: '', ); final $_dbc.DBCSignal _fwVersionMajorSignal = $_dbc.DBCSignal( - name: "FW_Version_Major", + name: 'FW_Version_Major', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 5, length: 4, - mapping: [0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [5, 6, 7, 8], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 8.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', ); final $_dbc.DBCSignal _fwVersionMinorSignal = $_dbc.DBCSignal( - name: "FW_Version_Minor", + name: 'FW_Version_Minor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 9, length: 4, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0], mappingIndexes: [9, 10, 11, 12], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 8.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', ); @override @@ -185,18 +194,17 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { num? deviceName, num? fwVersionMajor, num? fwVersionMinor, - }) { - return DeviceBroadcastMessage( - deviceName: deviceName ?? this.deviceName, - fwVersionMajor: fwVersionMajor ?? this.fwVersionMajor, - fwVersionMinor: fwVersionMinor ?? this.fwVersionMinor, - ); - } + }) => DeviceBroadcastMessage( + deviceName: deviceName ?? this.deviceName, + fwVersionMajor: fwVersionMajor ?? this.fwVersionMajor, + fwVersionMinor: fwVersionMinor ?? this.fwVersionMinor, + ); - factory DeviceBroadcastMessage.fromBuffer(List buffer) { + factory DeviceBroadcastMessage.decode(List payload) { final message = DeviceBroadcastMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.deviceName = message._deviceNameSignal.decode(bitField) ?? $_math.max(0, message._deviceNameSignal.min); @@ -210,26 +218,40 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { return message; } + factory DeviceBroadcastMessage.fromJson(Map json) => + DeviceBroadcastMessage( + deviceName: json['Device_Name'] ?? 0, + fwVersionMajor: json['FW_Version_Major'] ?? 0, + fwVersionMinor: json['FW_Version_Minor'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _deviceNameSignal: deviceName, _fwVersionMajorSignal: fwVersionMajor, _fwVersionMinorSignal: fwVersionMinor, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Device_Name': deviceName, + 'FW_Version_Major': fwVersionMajor, + 'FW_Version_Minor': fwVersionMinor, + }; + @override String toString() { - return "Device_Broadcast(\n Device_Name=$deviceName\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)"; + return 'Device_Broadcast(\n Device_Name=$deviceName\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)'; } } class DriveSetSpeedsMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_Set_Speeds"; + String messageName = 'Drive_Set_Speeds'; @override int messageLength = 7; @@ -241,7 +263,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_Set_Speeds" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Should_Set_Left" num shouldSetLeft; @@ -262,105 +284,105 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { num throttle; final $_dbc.DBCSignal _shouldSetLeftSignal = $_dbc.DBCSignal( - name: "Should_Set_Left", + name: 'Should_Set_Left', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _shouldSetRightSignal = $_dbc.DBCSignal( - name: "Should_Set_Right", + name: 'Should_Set_Right', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 1, length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _shouldSetThrottleSignal = $_dbc.DBCSignal( - name: "Should_Set_Throttle", + name: 'Should_Set_Throttle', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 2, length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [2], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _leftSpeedSignal = $_dbc.DBCSignal( - name: "Left_Speed", + name: 'Left_Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, length: 16, - mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], - factor: 0.000062, - offset: 0.0, - min: -1.0, - max: 1.0, - unit: "", + factor: 0000062, + offset: 0, + min: -1, + max: 1, + unit: '', ); final $_dbc.DBCSignal _rightSpeedSignal = $_dbc.DBCSignal( - name: "Right_Speed", + name: 'Right_Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 19, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], - factor: 0.000062, - offset: 0.0, - min: -1.0, - max: 1.0, - unit: "", + factor: 0000062, + offset: 0, + min: -1, + max: 1, + unit: '', ); final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( - name: "Throttle", + name: 'Throttle', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 35, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], - factor: 0.000016, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 0000016, + offset: 0, + min: 0, + max: 1, + unit: '', ); @override @@ -390,21 +412,20 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { num? leftSpeed, num? rightSpeed, num? throttle, - }) { - return DriveSetSpeedsMessage( - shouldSetLeft: shouldSetLeft ?? this.shouldSetLeft, - shouldSetRight: shouldSetRight ?? this.shouldSetRight, - shouldSetThrottle: shouldSetThrottle ?? this.shouldSetThrottle, - leftSpeed: leftSpeed ?? this.leftSpeed, - rightSpeed: rightSpeed ?? this.rightSpeed, - throttle: throttle ?? this.throttle, - ); - } + }) => DriveSetSpeedsMessage( + shouldSetLeft: shouldSetLeft ?? this.shouldSetLeft, + shouldSetRight: shouldSetRight ?? this.shouldSetRight, + shouldSetThrottle: shouldSetThrottle ?? this.shouldSetThrottle, + leftSpeed: leftSpeed ?? this.leftSpeed, + rightSpeed: rightSpeed ?? this.rightSpeed, + throttle: throttle ?? this.throttle, + ); - factory DriveSetSpeedsMessage.fromBuffer(List buffer) { + factory DriveSetSpeedsMessage.decode(List payload) { final message = DriveSetSpeedsMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.shouldSetLeft = message._shouldSetLeftSignal.decode(bitField) ?? $_math.max(0, message._shouldSetLeftSignal.min); @@ -427,8 +448,18 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { return message; } + factory DriveSetSpeedsMessage.fromJson(Map json) => + DriveSetSpeedsMessage( + shouldSetLeft: json['Should_Set_Left'] ?? 0, + shouldSetRight: json['Should_Set_Right'] ?? 0, + shouldSetThrottle: json['Should_Set_Throttle'] ?? 0, + leftSpeed: json['Left_Speed'] ?? 0, + rightSpeed: json['Right_Speed'] ?? 0, + throttle: json['Throttle'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _shouldSetLeftSignal: shouldSetLeft, _shouldSetRightSignal: shouldSetRight, @@ -438,18 +469,28 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { _throttleSignal: throttle, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Should_Set_Left': shouldSetLeft, + 'Should_Set_Right': shouldSetRight, + 'Should_Set_Throttle': shouldSetThrottle, + 'Left_Speed': leftSpeed, + 'Right_Speed': rightSpeed, + 'Throttle': throttle, + }; + @override String toString() { - return "Drive_Set_Speeds(\n Should_Set_Left=$shouldSetLeft\n Should_Set_Right=$shouldSetRight\n Should_Set_Throttle=$shouldSetThrottle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n Throttle=$throttle\n)"; + return 'Drive_Set_Speeds(\n Should_Set_Left=$shouldSetLeft\n Should_Set_Right=$shouldSetRight\n Should_Set_Throttle=$shouldSetThrottle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n Throttle=$throttle\n)'; } } class DriveSetLedMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_SetLED"; + String messageName = 'Drive_SetLED'; @override int messageLength = 1; @@ -461,7 +502,7 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_SetLED" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Color" num color; @@ -470,37 +511,37 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { num blink; final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( - name: "Color", + name: 'Color', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 4, - mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 8.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', ); final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( - name: "Blink", + name: 'Blink', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 4, length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [4], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); @override @@ -518,17 +559,16 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { DriveSetLedMessage copyWith({ num? color, num? blink, - }) { - return DriveSetLedMessage( - color: color ?? this.color, - blink: blink ?? this.blink, - ); - } + }) => DriveSetLedMessage( + color: color ?? this.color, + blink: blink ?? this.blink, + ); - factory DriveSetLedMessage.fromBuffer(List buffer) { + factory DriveSetLedMessage.decode(List payload) { final message = DriveSetLedMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.color = message._colorSignal.decode(bitField) ?? $_math.max(0, message._colorSignal.min); @@ -539,25 +579,37 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { return message; } + factory DriveSetLedMessage.fromJson(Map json) => + DriveSetLedMessage( + color: json['Color'] ?? 0, + blink: json['Blink'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _colorSignal: color, _blinkSignal: blink, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Color': color, + 'Blink': blink, + }; + @override String toString() { - return "Drive_SetLED(\n Color=$color\n Blink=$blink\n)"; + return 'Drive_SetLED(\n Color=$color\n Blink=$blink\n)'; } } class DriveLedMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_LED"; + String messageName = 'Drive_LED'; @override int messageLength = 1; @@ -569,7 +621,7 @@ class DriveLedMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_LED" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Color" num color; @@ -578,37 +630,37 @@ class DriveLedMessage extends $_dbc.DBCMessage { num blink; final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( - name: "Color", + name: 'Color', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 4, - mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 8.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', ); final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( - name: "Blink", + name: 'Blink', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 4, length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [4], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); @override @@ -626,17 +678,16 @@ class DriveLedMessage extends $_dbc.DBCMessage { DriveLedMessage copyWith({ num? color, num? blink, - }) { - return DriveLedMessage( - color: color ?? this.color, - blink: blink ?? this.blink, - ); - } + }) => DriveLedMessage( + color: color ?? this.color, + blink: blink ?? this.blink, + ); - factory DriveLedMessage.fromBuffer(List buffer) { + factory DriveLedMessage.decode(List payload) { final message = DriveLedMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.color = message._colorSignal.decode(bitField) ?? $_math.max(0, message._colorSignal.min); @@ -647,25 +698,37 @@ class DriveLedMessage extends $_dbc.DBCMessage { return message; } + factory DriveLedMessage.fromJson(Map json) => + DriveLedMessage( + color: json['Color'] ?? 0, + blink: json['Blink'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _colorSignal: color, _blinkSignal: blink, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Color': color, + 'Blink': blink, + }; + @override String toString() { - return "Drive_LED(\n Color=$color\n Blink=$blink\n)"; + return 'Drive_LED(\n Color=$color\n Blink=$blink\n)'; } } class DriveAppliedOutputMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_Applied_Output"; + String messageName = 'Drive_Applied_Output'; @override int messageLength = 6; @@ -677,7 +740,7 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_Applied_Output" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Throttle" num throttle; @@ -689,54 +752,54 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { num rightSpeed; final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( - name: "Throttle", + name: 'Throttle', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 16, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.000016, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 0000016, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _leftSpeedSignal = $_dbc.DBCSignal( - name: "Left_Speed", + name: 'Left_Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 16, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], - factor: 0.000062, - offset: 0.0, - min: -1.0, - max: 1.0, - unit: "", + factor: 0000062, + offset: 0, + min: -1, + max: 1, + unit: '', ); final $_dbc.DBCSignal _rightSpeedSignal = $_dbc.DBCSignal( - name: "Right_Speed", + name: 'Right_Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 32, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], - factor: 0.000062, - offset: 0.0, - min: -1.0, - max: 1.0, - unit: "", + factor: 0000062, + offset: 0, + min: -1, + max: 1, + unit: '', ); @override @@ -757,18 +820,17 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { num? throttle, num? leftSpeed, num? rightSpeed, - }) { - return DriveAppliedOutputMessage( - throttle: throttle ?? this.throttle, - leftSpeed: leftSpeed ?? this.leftSpeed, - rightSpeed: rightSpeed ?? this.rightSpeed, - ); - } + }) => DriveAppliedOutputMessage( + throttle: throttle ?? this.throttle, + leftSpeed: leftSpeed ?? this.leftSpeed, + rightSpeed: rightSpeed ?? this.rightSpeed, + ); - factory DriveAppliedOutputMessage.fromBuffer(List buffer) { + factory DriveAppliedOutputMessage.decode(List payload) { final message = DriveAppliedOutputMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.throttle = message._throttleSignal.decode(bitField) ?? $_math.max(0, message._throttleSignal.min); @@ -782,26 +844,40 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { return message; } + factory DriveAppliedOutputMessage.fromJson(Map json) => + DriveAppliedOutputMessage( + throttle: json['Throttle'] ?? 0, + leftSpeed: json['Left_Speed'] ?? 0, + rightSpeed: json['Right_Speed'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _throttleSignal: throttle, _leftSpeedSignal: leftSpeed, _rightSpeedSignal: rightSpeed, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Throttle': throttle, + 'Left_Speed': leftSpeed, + 'Right_Speed': rightSpeed, + }; + @override String toString() { - return "Drive_Applied_Output(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)"; + return 'Drive_Applied_Output(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; } } class DriveBatteryMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_Battery"; + String messageName = 'Drive_Battery'; @override int messageLength = 6; @@ -813,7 +889,7 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_Battery" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Voltage" num voltage; @@ -825,54 +901,54 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { num current; final $_dbc.DBCSignal _voltageSignal = $_dbc.DBCSignal( - name: "Voltage", + name: 'Voltage', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 16, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.00055, - offset: 0.0, - min: 0.0, - max: 36.0, - unit: "V", + factor: 000055, + offset: 0, + min: 0, + max: 36, + unit: 'V', ); final $_dbc.DBCSignal _temperatureSignal = $_dbc.DBCSignal( - name: "Temperature", + name: 'Temperature', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 16, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 0.09, - offset: 50.0, - min: -40.0, - max: 150.0, - unit: "C", + factor: 009, + offset: 50, + min: -40, + max: 150, + unit: 'C', ); final $_dbc.DBCSignal _currentSignal = $_dbc.DBCSignal( - name: "Current", + name: 'Current', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 28, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], - factor: 0.1, - offset: 0.0, - min: 0.0, - max: 30.0, - unit: "A", + factor: 01, + offset: 0, + min: 0, + max: 30, + unit: 'A', ); @override @@ -893,18 +969,17 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { num? voltage, num? temperature, num? current, - }) { - return DriveBatteryMessage( - voltage: voltage ?? this.voltage, - temperature: temperature ?? this.temperature, - current: current ?? this.current, - ); - } + }) => DriveBatteryMessage( + voltage: voltage ?? this.voltage, + temperature: temperature ?? this.temperature, + current: current ?? this.current, + ); - factory DriveBatteryMessage.fromBuffer(List buffer) { + factory DriveBatteryMessage.decode(List payload) { final message = DriveBatteryMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.voltage = message._voltageSignal.decode(bitField) ?? $_math.max(0, message._voltageSignal.min); @@ -918,26 +993,40 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { return message; } + factory DriveBatteryMessage.fromJson(Map json) => + DriveBatteryMessage( + voltage: json['Voltage'] ?? 0, + temperature: json['Temperature'] ?? 50, + current: json['Current'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _voltageSignal: voltage, _temperatureSignal: temperature, _currentSignal: current, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Voltage': voltage, + 'Temperature': temperature, + 'Current': current, + }; + @override String toString() { - return "Drive_Battery(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)"; + return 'Drive_Battery(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; } } class DriveSwivelMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_Swivel"; + String messageName = 'Drive_Swivel'; @override int messageLength = 6; @@ -949,7 +1038,7 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_Swivel" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Front_Swivel" num frontSwivel; @@ -964,71 +1053,71 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { num rearTilt; final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( - name: "Front_Swivel", + name: 'Front_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 12, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( - name: "Front_Tilt", + name: 'Front_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 12, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( - name: "Rear_Swivel", + name: 'Rear_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 24, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( - name: "Rear_Tilt", + name: 'Rear_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 36, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); @override @@ -1052,19 +1141,18 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { num? frontTilt, num? rearSwivel, num? rearTilt, - }) { - return DriveSwivelMessage( - frontSwivel: frontSwivel ?? this.frontSwivel, - frontTilt: frontTilt ?? this.frontTilt, - rearSwivel: rearSwivel ?? this.rearSwivel, - rearTilt: rearTilt ?? this.rearTilt, - ); - } + }) => DriveSwivelMessage( + frontSwivel: frontSwivel ?? this.frontSwivel, + frontTilt: frontTilt ?? this.frontTilt, + rearSwivel: rearSwivel ?? this.rearSwivel, + rearTilt: rearTilt ?? this.rearTilt, + ); - factory DriveSwivelMessage.fromBuffer(List buffer) { + factory DriveSwivelMessage.decode(List payload) { final message = DriveSwivelMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.frontSwivel = message._frontSwivelSignal.decode(bitField) ?? $_math.max(0, message._frontSwivelSignal.min); @@ -1081,8 +1169,16 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { return message; } + factory DriveSwivelMessage.fromJson(Map json) => + DriveSwivelMessage( + frontSwivel: json['Front_Swivel'] ?? 0, + frontTilt: json['Front_Tilt'] ?? 0, + rearSwivel: json['Rear_Swivel'] ?? 0, + rearTilt: json['Rear_Tilt'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _frontSwivelSignal: frontSwivel, _frontTiltSignal: frontTilt, @@ -1090,18 +1186,26 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { _rearTiltSignal: rearTilt, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Front_Swivel': frontSwivel, + 'Front_Tilt': frontTilt, + 'Rear_Swivel': rearSwivel, + 'Rear_Tilt': rearTilt, + }; + @override String toString() { - return "Drive_Swivel(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)"; + return 'Drive_Swivel(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } } class RelaySetStateMessage extends $_dbc.DBCMessage { @override - String messageName = "Relay_Set_State"; + String messageName = 'Relay_Set_State'; @override int messageLength = 2; @@ -1113,7 +1217,7 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Relay_Set_State" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Update_Front_Left_Motor" num updateFrontLeftMotor; @@ -1158,241 +1262,241 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { num drive; final $_dbc.DBCSignal _updateFrontLeftMotorSignal = $_dbc.DBCSignal( - name: "Update_Front_Left_Motor", + name: 'Update_Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( - name: "Front_Left_Motor", + name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 1, length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _updateFrontRightMotorSignal = $_dbc.DBCSignal( - name: "Update_Front_Right_Motor", + name: 'Update_Front_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 2, length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [2], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( - name: "Front_Right_Motor", + name: 'Front_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _updateBackLeftMotorSignal = $_dbc.DBCSignal( - name: "Update_Back_Left_Motor", + name: 'Update_Back_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 4, length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( - name: "Back_Left_Motor", + name: 'Back_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 5, length: 1, - mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [5], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _updateBackRightMotorSignal = $_dbc.DBCSignal( - name: "Update_Back_Right_Motor", + name: 'Update_Back_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 6, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [6], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( - name: "Back_Right_Motor", + name: 'Back_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 7, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [7], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _updateArmSignal = $_dbc.DBCSignal( - name: "Update_Arm", + name: 'Update_Arm', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 8, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [8], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( - name: "Arm", + name: 'Arm', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 9, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], mappingIndexes: [9], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _updateScienceSignal = $_dbc.DBCSignal( - name: "Update_Science", + name: 'Update_Science', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 10, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], mappingIndexes: [10], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( - name: "Science", + name: 'Science', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 11, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], mappingIndexes: [11], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _updateDriveSignal = $_dbc.DBCSignal( - name: "Update_Drive", + name: 'Update_Drive', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 12, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [12], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( - name: "Drive", + name: 'Drive', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 13, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], mappingIndexes: [13], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); @override @@ -1446,29 +1550,28 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { num? science, num? updateDrive, num? drive, - }) { - return RelaySetStateMessage( - updateFrontLeftMotor: updateFrontLeftMotor ?? this.updateFrontLeftMotor, - frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, - updateFrontRightMotor: updateFrontRightMotor ?? this.updateFrontRightMotor, - frontRightMotor: frontRightMotor ?? this.frontRightMotor, - updateBackLeftMotor: updateBackLeftMotor ?? this.updateBackLeftMotor, - backLeftMotor: backLeftMotor ?? this.backLeftMotor, - updateBackRightMotor: updateBackRightMotor ?? this.updateBackRightMotor, - backRightMotor: backRightMotor ?? this.backRightMotor, - updateArm: updateArm ?? this.updateArm, - arm: arm ?? this.arm, - updateScience: updateScience ?? this.updateScience, - science: science ?? this.science, - updateDrive: updateDrive ?? this.updateDrive, - drive: drive ?? this.drive, - ); - } + }) => RelaySetStateMessage( + updateFrontLeftMotor: updateFrontLeftMotor ?? this.updateFrontLeftMotor, + frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, + updateFrontRightMotor: updateFrontRightMotor ?? this.updateFrontRightMotor, + frontRightMotor: frontRightMotor ?? this.frontRightMotor, + updateBackLeftMotor: updateBackLeftMotor ?? this.updateBackLeftMotor, + backLeftMotor: backLeftMotor ?? this.backLeftMotor, + updateBackRightMotor: updateBackRightMotor ?? this.updateBackRightMotor, + backRightMotor: backRightMotor ?? this.backRightMotor, + updateArm: updateArm ?? this.updateArm, + arm: arm ?? this.arm, + updateScience: updateScience ?? this.updateScience, + science: science ?? this.science, + updateDrive: updateDrive ?? this.updateDrive, + drive: drive ?? this.drive, + ); - factory RelaySetStateMessage.fromBuffer(List buffer) { + factory RelaySetStateMessage.decode(List payload) { final message = RelaySetStateMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.updateFrontLeftMotor = message._updateFrontLeftMotorSignal.decode(bitField) ?? $_math.max(0, message._updateFrontLeftMotorSignal.min); @@ -1515,8 +1618,26 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { return message; } - @override - $_typed.Uint8List writeToBuffer() { + factory RelaySetStateMessage.fromJson(Map json) => + RelaySetStateMessage( + updateFrontLeftMotor: json['Update_Front_Left_Motor'] ?? 0, + frontLeftMotor: json['Front_Left_Motor'] ?? 0, + updateFrontRightMotor: json['Update_Front_Right_Motor'] ?? 0, + frontRightMotor: json['Front_Right_Motor'] ?? 0, + updateBackLeftMotor: json['Update_Back_Left_Motor'] ?? 0, + backLeftMotor: json['Back_Left_Motor'] ?? 0, + updateBackRightMotor: json['Update_Back_Right_Motor'] ?? 0, + backRightMotor: json['Back_Right_Motor'] ?? 0, + updateArm: json['Update_Arm'] ?? 0, + arm: json['Arm'] ?? 0, + updateScience: json['Update_Science'] ?? 0, + science: json['Science'] ?? 0, + updateDrive: json['Update_Drive'] ?? 0, + drive: json['Drive'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _updateFrontLeftMotorSignal: updateFrontLeftMotor, _frontLeftMotorSignal: frontLeftMotor, @@ -1534,18 +1655,36 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { _driveSignal: drive, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Update_Front_Left_Motor': updateFrontLeftMotor, + 'Front_Left_Motor': frontLeftMotor, + 'Update_Front_Right_Motor': updateFrontRightMotor, + 'Front_Right_Motor': frontRightMotor, + 'Update_Back_Left_Motor': updateBackLeftMotor, + 'Back_Left_Motor': backLeftMotor, + 'Update_Back_Right_Motor': updateBackRightMotor, + 'Back_Right_Motor': backRightMotor, + 'Update_Arm': updateArm, + 'Arm': arm, + 'Update_Science': updateScience, + 'Science': science, + 'Update_Drive': updateDrive, + 'Drive': drive, + }; + @override String toString() { - return "Relay_Set_State(\n Update_Front_Left_Motor=$updateFrontLeftMotor\n Front_Left_Motor=$frontLeftMotor\n Update_Front_Right_Motor=$updateFrontRightMotor\n Front_Right_Motor=$frontRightMotor\n Update_Back_Left_Motor=$updateBackLeftMotor\n Back_Left_Motor=$backLeftMotor\n Update_Back_Right_Motor=$updateBackRightMotor\n Back_Right_Motor=$backRightMotor\n Update_Arm=$updateArm\n Arm=$arm\n Update_Science=$updateScience\n Science=$science\n Update_Drive=$updateDrive\n Drive=$drive\n)"; + return 'Relay_Set_State(\n Update_Front_Left_Motor=$updateFrontLeftMotor\n Front_Left_Motor=$frontLeftMotor\n Update_Front_Right_Motor=$updateFrontRightMotor\n Front_Right_Motor=$frontRightMotor\n Update_Back_Left_Motor=$updateBackLeftMotor\n Back_Left_Motor=$backLeftMotor\n Update_Back_Right_Motor=$updateBackRightMotor\n Back_Right_Motor=$backRightMotor\n Update_Arm=$updateArm\n Arm=$arm\n Update_Science=$updateScience\n Science=$science\n Update_Drive=$updateDrive\n Drive=$drive\n)'; } } class RelayStateMessage extends $_dbc.DBCMessage { @override - String messageName = "Relay_State"; + String messageName = 'Relay_State'; @override int messageLength = 1; @@ -1557,7 +1696,7 @@ class RelayStateMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Relay_State" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Front_Left_Motor" num frontLeftMotor; @@ -1584,139 +1723,139 @@ class RelayStateMessage extends $_dbc.DBCMessage { num physicalOverride; final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( - name: "Front_Left_Motor", + name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( - name: "Front_Right_Motor", + name: 'Front_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 1, length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 1, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( - name: "Back_Left_Motor", + name: 'Back_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 2, length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 1, 0, 0, 0, 0, 0], mappingIndexes: [2], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( - name: "Back_Right_Motor", + name: 'Back_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 1, 0, 0, 0, 0], mappingIndexes: [3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( - name: "Drive", + name: 'Drive', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 4, length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [4], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( - name: "Arm", + name: 'Arm', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 5, length: 1, - mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 1, 0, 0], mappingIndexes: [5], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( - name: "Science", + name: 'Science', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 6, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 1, 0], mappingIndexes: [6], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _physicalOverrideSignal = $_dbc.DBCSignal( - name: "Physical_Override", + name: 'Physical_Override', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 7, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 1], mappingIndexes: [7], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); @override @@ -1752,23 +1891,22 @@ class RelayStateMessage extends $_dbc.DBCMessage { num? arm, num? science, num? physicalOverride, - }) { - return RelayStateMessage( - frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, - frontRightMotor: frontRightMotor ?? this.frontRightMotor, - backLeftMotor: backLeftMotor ?? this.backLeftMotor, - backRightMotor: backRightMotor ?? this.backRightMotor, - drive: drive ?? this.drive, - arm: arm ?? this.arm, - science: science ?? this.science, - physicalOverride: physicalOverride ?? this.physicalOverride, - ); - } + }) => RelayStateMessage( + frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, + frontRightMotor: frontRightMotor ?? this.frontRightMotor, + backLeftMotor: backLeftMotor ?? this.backLeftMotor, + backRightMotor: backRightMotor ?? this.backRightMotor, + drive: drive ?? this.drive, + arm: arm ?? this.arm, + science: science ?? this.science, + physicalOverride: physicalOverride ?? this.physicalOverride, + ); - factory RelayStateMessage.fromBuffer(List buffer) { + factory RelayStateMessage.decode(List payload) { final message = RelayStateMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.frontLeftMotor = message._frontLeftMotorSignal.decode(bitField) ?? $_math.max(0, message._frontLeftMotorSignal.min); @@ -1797,8 +1935,20 @@ class RelayStateMessage extends $_dbc.DBCMessage { return message; } + factory RelayStateMessage.fromJson(Map json) => + RelayStateMessage( + frontLeftMotor: json['Front_Left_Motor'] ?? 0, + frontRightMotor: json['Front_Right_Motor'] ?? 0, + backLeftMotor: json['Back_Left_Motor'] ?? 0, + backRightMotor: json['Back_Right_Motor'] ?? 0, + drive: json['Drive'] ?? 0, + arm: json['Arm'] ?? 0, + science: json['Science'] ?? 0, + physicalOverride: json['Physical_Override'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _frontLeftMotorSignal: frontLeftMotor, _frontRightMotorSignal: frontRightMotor, @@ -1810,18 +1960,30 @@ class RelayStateMessage extends $_dbc.DBCMessage { _physicalOverrideSignal: physicalOverride, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Front_Left_Motor': frontLeftMotor, + 'Front_Right_Motor': frontRightMotor, + 'Back_Left_Motor': backLeftMotor, + 'Back_Right_Motor': backRightMotor, + 'Drive': drive, + 'Arm': arm, + 'Science': science, + 'Physical_Override': physicalOverride, + }; + @override String toString() { - return "Relay_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)"; + return 'Relay_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; } } class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override - String messageName = "Drive_SetSwivel"; + String messageName = 'Drive_SetSwivel'; @override int messageLength = 7; @@ -1833,7 +1995,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { static const bool isMultiplex = false; /// The multiplexor for "Drive_SetSwivel" - static const String multiplexor = ""; + static const String multiplexor = ''; /// Value of signal "Set_Front_Swivel" num setFrontSwivel; @@ -1860,139 +2022,139 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { num rearTilt; final $_dbc.DBCSignal _setFrontSwivelSignal = $_dbc.DBCSignal( - name: "Set_Front_Swivel", + name: 'Set_Front_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _setFrontTiltSignal = $_dbc.DBCSignal( - name: "Set_Front_Tilt", + name: 'Set_Front_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 1, length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _setRearSwivelSignal = $_dbc.DBCSignal( - name: "Set_Rear_Swivel", + name: 'Set_Rear_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 2, length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [2], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _setRearTiltSignal = $_dbc.DBCSignal( - name: "Set_Rear_Tilt", + name: 'Set_Rear_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3], - factor: 1.0, - offset: 0.0, - min: 0.0, - max: 1.0, - unit: "", + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( - name: "Front_Swivel", + name: 'Front_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 4, length: 12, - mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( - name: "Front_Tilt", + name: 'Front_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 16, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( - name: "Rear_Swivel", + name: 'Rear_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 28, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( - name: "Rear_Tilt", + name: 'Rear_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 40, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0], mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], - factor: 0.044, - offset: 0.0, - min: -90.0, - max: 90.0, - unit: "°", + factor: 0044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); @override @@ -2028,23 +2190,22 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { num? frontTilt, num? rearSwivel, num? rearTilt, - }) { - return DriveSetSwivelMessage( - setFrontSwivel: setFrontSwivel ?? this.setFrontSwivel, - setFrontTilt: setFrontTilt ?? this.setFrontTilt, - setRearSwivel: setRearSwivel ?? this.setRearSwivel, - setRearTilt: setRearTilt ?? this.setRearTilt, - frontSwivel: frontSwivel ?? this.frontSwivel, - frontTilt: frontTilt ?? this.frontTilt, - rearSwivel: rearSwivel ?? this.rearSwivel, - rearTilt: rearTilt ?? this.rearTilt, - ); - } + }) => DriveSetSwivelMessage( + setFrontSwivel: setFrontSwivel ?? this.setFrontSwivel, + setFrontTilt: setFrontTilt ?? this.setFrontTilt, + setRearSwivel: setRearSwivel ?? this.setRearSwivel, + setRearTilt: setRearTilt ?? this.setRearTilt, + frontSwivel: frontSwivel ?? this.frontSwivel, + frontTilt: frontTilt ?? this.frontTilt, + rearSwivel: rearSwivel ?? this.rearSwivel, + rearTilt: rearTilt ?? this.rearTilt, + ); - factory DriveSetSwivelMessage.fromBuffer(List buffer) { + factory DriveSetSwivelMessage.decode(List payload) { final message = DriveSetSwivelMessage(); - final typedBuffer = $_typed.Uint8List.fromList(buffer); + final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.setFrontSwivel = message._setFrontSwivelSignal.decode(bitField) ?? $_math.max(0, message._setFrontSwivelSignal.min); @@ -2073,8 +2234,20 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { return message; } + factory DriveSetSwivelMessage.fromJson(Map json) => + DriveSetSwivelMessage( + setFrontSwivel: json['Set_Front_Swivel'] ?? 0, + setFrontTilt: json['Set_Front_Tilt'] ?? 0, + setRearSwivel: json['Set_Rear_Swivel'] ?? 0, + setRearTilt: json['Set_Rear_Tilt'] ?? 0, + frontSwivel: json['Front_Swivel'] ?? 0, + frontTilt: json['Front_Tilt'] ?? 0, + rearSwivel: json['Rear_Swivel'] ?? 0, + rearTilt: json['Rear_Tilt'] ?? 0, + ); + @override - $_typed.Uint8List writeToBuffer() { + $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _setFrontSwivelSignal: setFrontSwivel, _setFrontTiltSignal: setFrontTilt, @@ -2086,11 +2259,23 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { _rearTiltSignal: rearTilt, }; - return encodeMessage(values); + return encodeWithValues(values); } + @override + Map toJson() => { + 'Set_Front_Swivel': setFrontSwivel, + 'Set_Front_Tilt': setFrontTilt, + 'Set_Rear_Swivel': setRearSwivel, + 'Set_Rear_Tilt': setRearTilt, + 'Front_Swivel': frontSwivel, + 'Front_Tilt': frontTilt, + 'Rear_Swivel': rearSwivel, + 'Rear_Tilt': rearTilt, + }; + @override String toString() { - return "Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)"; + return 'Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } } From c826e2d66dc89d4ede683f3ced072749a6c24716 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Wed, 16 Apr 2025 15:52:45 -0400 Subject: [PATCH 09/30] Regenerated rover messages with correct factor --- .../lib/src/generated/rover_messages.dbc.dart | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 4c7525ae..2ceb9cad 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -344,7 +344,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { length: 16, mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], - factor: 0000062, + factor: 0.000062, offset: 0, min: -1, max: 1, @@ -361,7 +361,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { length: 16, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], - factor: 0000062, + factor: 0.000062, offset: 0, min: -1, max: 1, @@ -378,7 +378,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { length: 16, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], - factor: 0000016, + factor: 0.000016, offset: 0, min: 0, max: 1, @@ -761,7 +761,7 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { length: 16, mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0000016, + factor: 0.000016, offset: 0, min: 0, max: 1, @@ -778,7 +778,7 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { length: 16, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], - factor: 0000062, + factor: 0.000062, offset: 0, min: -1, max: 1, @@ -795,7 +795,7 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { length: 16, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], - factor: 0000062, + factor: 0.000062, offset: 0, min: -1, max: 1, @@ -910,7 +910,7 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { length: 16, mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 000055, + factor: 0.00055, offset: 0, min: 0, max: 36, @@ -927,7 +927,7 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 009, + factor: 0.09, offset: 50, min: -40, max: 150, @@ -944,7 +944,7 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { length: 16, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], - factor: 01, + factor: 0.1, offset: 0, min: 0, max: 30, @@ -1062,7 +1062,7 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -1079,7 +1079,7 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -1096,7 +1096,7 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -1113,7 +1113,7 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -2099,7 +2099,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -2116,7 +2116,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -2133,7 +2133,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, @@ -2150,7 +2150,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { length: 12, mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0], mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], - factor: 0044, + factor: 0.044, offset: 0, min: -90, max: 90, From 7c7fc944d975810dc674c18dc37eecbe9a92a342 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 21 Apr 2025 21:01:39 -0400 Subject: [PATCH 10/30] Renamed deviceId to deviceValue --- subsystems/lib/src/devices/can_bus.dart | 8 ++--- .../lib/src/generated/rover_messages.dbc.dart | 30 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 05dd3cc1..6e16b0e7 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -28,9 +28,9 @@ extension on DeviceBroadcastMessage { Message toRelayProto() => RelaysData(); Message? toProtoMessage() { - if (deviceName.toInt() == Device.DRIVE.value) { + if (deviceValue.toInt() == Device.DRIVE.value) { return toDriveProto(); - } else if (deviceName.toInt() == Device.RELAY.value) { + } else if (deviceValue.toInt() == Device.RELAY.value) { return toRelayProto(); } return null; @@ -345,11 +345,11 @@ class CanBus extends Service { } void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { - final device = Device.valueOf(broadcast.deviceName.toInt()); + final device = Device.valueOf(broadcast.deviceValue.toInt()); if (device == null) { logger.warning( "Unknown Device Number", - body: "Received broadcast from device ${broadcast.deviceName.toInt()}", + body: "Received broadcast from device ${broadcast.deviceValue.toInt()}", ); return; } diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 2ceb9cad..be514455 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -116,8 +116,8 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { /// The multiplexor for "Device_Broadcast" static const String multiplexor = ''; - /// Value of signal "Device_Name" - num deviceName; + /// Value of signal "Device_Value" + num deviceValue; /// Value of signal "FW_Version_Major" num fwVersionMajor; @@ -125,8 +125,8 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { /// Value of signal "FW_Version_Minor" num fwVersionMinor; - final $_dbc.DBCSignal _deviceNameSignal = $_dbc.DBCSignal( - name: 'Device_Name', + final $_dbc.DBCSignal _deviceValueSignal = $_dbc.DBCSignal( + name: 'Device_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, @@ -178,24 +178,24 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { @override List<$_dbc.DBCSignal> get signals => [ - _deviceNameSignal, + _deviceValueSignal, _fwVersionMajorSignal, _fwVersionMinorSignal, ]; DeviceBroadcastMessage({ - this.deviceName = 0, + this.deviceValue = 0, this.fwVersionMajor = 0, this.fwVersionMinor = 0, }); /// Creates a clone of this [DeviceBroadcastMessage] with the non-null values replaced DeviceBroadcastMessage copyWith({ - num? deviceName, + num? deviceValue, num? fwVersionMajor, num? fwVersionMinor, }) => DeviceBroadcastMessage( - deviceName: deviceName ?? this.deviceName, + deviceValue: deviceValue ?? this.deviceValue, fwVersionMajor: fwVersionMajor ?? this.fwVersionMajor, fwVersionMinor: fwVersionMinor ?? this.fwVersionMinor, ); @@ -205,9 +205,9 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.deviceName = - message._deviceNameSignal.decode(bitField) ?? - $_math.max(0, message._deviceNameSignal.min); + message.deviceValue = + message._deviceValueSignal.decode(bitField) ?? + $_math.max(0, message._deviceValueSignal.min); message.fwVersionMajor = message._fwVersionMajorSignal.decode(bitField) ?? $_math.max(0, message._fwVersionMajorSignal.min); @@ -220,7 +220,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { factory DeviceBroadcastMessage.fromJson(Map json) => DeviceBroadcastMessage( - deviceName: json['Device_Name'] ?? 0, + deviceValue: json['Device_Value'] ?? 0, fwVersionMajor: json['FW_Version_Major'] ?? 0, fwVersionMinor: json['FW_Version_Minor'] ?? 0, ); @@ -228,7 +228,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _deviceNameSignal: deviceName, + _deviceValueSignal: deviceValue, _fwVersionMajorSignal: fwVersionMajor, _fwVersionMinorSignal: fwVersionMinor, }; @@ -238,14 +238,14 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Device_Name': deviceName, + 'Device_Value': deviceValue, 'FW_Version_Major': fwVersionMajor, 'FW_Version_Minor': fwVersionMinor, }; @override String toString() { - return 'Device_Broadcast(\n Device_Name=$deviceName\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)'; + return 'Device_Broadcast(\n Device_Value=$deviceValue\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)'; } } From b2ef34cd5ee3ced1b71f128f1aee1b8797644882 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:59:53 -0400 Subject: [PATCH 11/30] Added arm messages --- burt_network/lib/src/generated/arm.pb.dart | 2 + .../lib/src/generated/arm.pbenum.dart | 31 +++ .../lib/src/generated/arm.pbjson.dart | 17 ++ subsystems/lib/src/devices/can_bus.dart | 217 ++++++++++++++++++ 4 files changed, 267 insertions(+) diff --git a/burt_network/lib/src/generated/arm.pb.dart b/burt_network/lib/src/generated/arm.pb.dart index a2dd96b2..c8f736ba 100644 --- a/burt_network/lib/src/generated/arm.pb.dart +++ b/burt_network/lib/src/generated/arm.pb.dart @@ -21,6 +21,8 @@ import 'version.pb.dart' as $2; export 'package:protobuf/protobuf.dart' show GeneratedMessageGenericExtensions; +export 'arm.pbenum.dart'; + class ArmData extends $pb.GeneratedMessage { factory ArmData({ $0.Coordinates? currentPosition, diff --git a/burt_network/lib/src/generated/arm.pbenum.dart b/burt_network/lib/src/generated/arm.pbenum.dart index edec8f7a..bbabbb18 100644 --- a/burt_network/lib/src/generated/arm.pbenum.dart +++ b/burt_network/lib/src/generated/arm.pbenum.dart @@ -5,6 +5,37 @@ // @dart = 3.3 // ignore_for_file: annotate_overrides, camel_case_types, comment_references +// ignore_for_file: constant_identifier_names, library_prefixes +// ignore_for_file: non_constant_identifier_names, prefer_final_fields +// ignore_for_file: unnecessary_import, unnecessary_this, unused_import + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +class ArmMotor extends $pb.ProtobufEnum { + static const ArmMotor ARM_MOTOR_UNDEFINED = ArmMotor._(0, _omitEnumNames ? '' : 'ARM_MOTOR_UNDEFINED'); + static const ArmMotor SWIVEL = ArmMotor._(1, _omitEnumNames ? '' : 'SWIVEL'); + static const ArmMotor SHOULDER = ArmMotor._(2, _omitEnumNames ? '' : 'SHOULDER'); + static const ArmMotor ELBOW = ArmMotor._(3, _omitEnumNames ? '' : 'ELBOW'); + static const ArmMotor WRIST = ArmMotor._(4, _omitEnumNames ? '' : 'WRIST'); + + static const $core.List values = [ + ARM_MOTOR_UNDEFINED, + SWIVEL, + SHOULDER, + ELBOW, + WRIST, + ]; + + static final $core.Map<$core.int, ArmMotor> _byValue = $pb.ProtobufEnum.initByValue(values); + static ArmMotor? valueOf($core.int value) => _byValue[value]; + + const ArmMotor._($core.int v, $core.String n) : super(v, n); +} + + +const _omitEnumNames = $core.bool.fromEnvironment('protobuf.omit_enum_names'); // ignore_for_file: constant_identifier_names // ignore_for_file: curly_braces_in_flow_control_structures // ignore_for_file: deprecated_member_use_from_same_package, library_prefixes diff --git a/burt_network/lib/src/generated/arm.pbjson.dart b/burt_network/lib/src/generated/arm.pbjson.dart index 279ff866..da9350ca 100644 --- a/burt_network/lib/src/generated/arm.pbjson.dart +++ b/burt_network/lib/src/generated/arm.pbjson.dart @@ -15,6 +15,23 @@ import 'dart:convert' as $convert; import 'dart:core' as $core; import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use armMotorDescriptor instead') +const ArmMotor$json = { + '1': 'ArmMotor', + '2': [ + {'1': 'ARM_MOTOR_UNDEFINED', '2': 0}, + {'1': 'SWIVEL', '2': 1}, + {'1': 'SHOULDER', '2': 2}, + {'1': 'ELBOW', '2': 3}, + {'1': 'WRIST', '2': 4}, + ], +}; + +/// Descriptor for `ArmMotor`. Decode as a `google.protobuf.EnumDescriptorProto`. +final $typed_data.Uint8List armMotorDescriptor = $convert.base64Decode( + 'CghBcm1Nb3RvchIXChNBUk1fTU9UT1JfVU5ERUZJTkVEEAASCgoGU1dJVkVMEAESDAoIU0hPVU' + 'xERVIQAhIJCgVFTEJPVxADEgkKBVdSSVNUEAQ='); + @$core.Deprecated('Use armDataDescriptor instead') const ArmData$json = { '1': 'ArmData', diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 6e16b0e7..307d77fb 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -12,6 +12,13 @@ extension on num { bool get boolValue => this == 1; BoolState get boolState => boolValue ? BoolState.YES : BoolState.NO; + + BoolState get armBoolState => + this == 1 + ? BoolState.YES + : this == 2 + ? BoolState.NO + : BoolState.BOOL_UNDEFINED; } extension on bool { @@ -27,11 +34,23 @@ extension on DeviceBroadcastMessage { Message toRelayProto() => RelaysData(); + Message toArmProto() => ArmData(version: version); + + Message toGripperProto() => GripperData(version: version); + + Message toScienceProto() => ScienceData(version: version); + Message? toProtoMessage() { if (deviceValue.toInt() == Device.DRIVE.value) { return toDriveProto(); } else if (deviceValue.toInt() == Device.RELAY.value) { return toRelayProto(); + } else if (deviceValue.toInt() == Device.ARM.value) { + return toArmProto(); + } else if (deviceValue.toInt() == Device.GRIPPER.value) { + return toGripperProto(); + } else if (deviceValue.toInt() == Device.SCIENCE.value) { + return toScienceProto(); } return null; } @@ -148,6 +167,119 @@ extension on RelaysCommand { List toDBC() => [asSetState]; } +extension on ArmMotorMoveDataMessage { + MotorData toMotorData() => MotorData( + isMoving: isMoving.armBoolState, + isLimitSwitchPressed: isLimitSwitchPressed.armBoolState, + direction: MotorDirection.valueOf(motorDirection.toInt()), + ); + + ArmData toArmProto() { + final data = ArmData(); + + if (motorValue == ArmMotor.SWIVEL.value) { + data.base = toMotorData(); + } else if (motorValue == ArmMotor.SHOULDER.value) { + data.shoulder = toMotorData(); + } else if (motorValue == ArmMotor.ELBOW.value) { + data.elbow = toMotorData(); + } + + return data; + } +} + +extension on ArmMotorStepDataMessage { + MotorData toMotorData() => MotorData( + currentStep: currentStep.toInt(), + targetStep: targetStep.toInt(), + ); + + ArmData toArmProto() { + final data = ArmData(); + + if (motorValue == ArmMotor.SWIVEL.value) { + data.base = toMotorData(); + } else if (motorValue == ArmMotor.SHOULDER.value) { + data.shoulder = toMotorData(); + } else if (motorValue == ArmMotor.ELBOW.value) { + data.elbow = toMotorData(); + } + + return data; + } +} + +extension on ArmMotorAngleDataMessage { + MotorData toMotorData() => MotorData( + currentAngle: currentAngle.toDouble(), + targetAngle: targetAngle.toDouble(), + ); + + ArmData toArmProto() { + final data = ArmData(); + + if (motorValue == ArmMotor.SWIVEL.value) { + data.base = toMotorData(); + } else if (motorValue == ArmMotor.SHOULDER.value) { + data.shoulder = toMotorData(); + } else if (motorValue == ArmMotor.ELBOW.value) { + data.elbow = toMotorData(); + } + + return data; + } +} + +extension on ArmCommand { + DBCMessage asAsSetSwivel() => ArmSetMotorMessage( + motorValue: ArmMotor.SWIVEL.value, + angle: swivel.angle, + moveRadians: swivel.moveRadians, + moveSteps: swivel.moveSteps, + ); + + DBCMessage asAsSetShoulder() => ArmSetMotorMessage( + motorValue: ArmMotor.SHOULDER.value, + angle: shoulder.angle, + moveRadians: shoulder.moveRadians, + moveSteps: shoulder.moveSteps, + ); + + DBCMessage asAsSetElbow() => ArmSetMotorMessage( + motorValue: ArmMotor.ELBOW.value, + angle: elbow.angle, + moveRadians: elbow.moveRadians, + moveSteps: elbow.moveSteps, + ); + + DBCMessage asSystemAction() => ArmSystemActionMessage( + stop: stop.intValue, + calibrate: calibrate.intValue, + jab: jab.intValue, + ); + + List toDBC() { + final output = []; + + if (hasSwivel()) { + output.add(asAsSetSwivel()); + } + if (hasShoulder()) { + output.add(asAsSetShoulder()); + } + if (hasElbow()) { + output.add(asAsSetElbow()); + } + + if (stop == true || calibrate == true || jab == true) { + output.add(asSystemAction()); + } + + return output; + } +} + /// A service to forward messages between CAN and UDP /// /// Simliar to the firmware service, this service will stream incoming @@ -183,6 +315,9 @@ class CanBus extends Service { StreamSubscription? _frameSubscription; StreamSubscription? _driveSubscription; StreamSubscription? _relaySubscription; + StreamSubscription? _armSubscription; + StreamSubscription? _gripperSubscription; + StreamSubscription? _scienceSubscription; @override Future init() async { @@ -234,6 +369,24 @@ class CanBus extends Service { callback: sendRelaysCommand, ); + _armSubscription = collection.server.messages.onMessage( + name: ArmCommand().messageName, + constructor: ArmCommand.fromBuffer, + callback: sendArmCommand, + ); + + _gripperSubscription = collection.server.messages.onMessage( + name: GripperCommand().messageName, + constructor: GripperCommand.fromBuffer, + callback: sendGripperCommand, + ); + + _scienceSubscription = collection.server.messages.onMessage( + name: ScienceCommand().messageName, + constructor: ScienceCommand.fromBuffer, + callback: sendScienceCommand, + ); + return true; } @@ -247,6 +400,9 @@ class CanBus extends Service { await _driveSubscription?.cancel(); await _relaySubscription?.cancel(); + await _armSubscription?.cancel(); + await _gripperSubscription?.cancel(); + await _scienceSubscription?.cancel(); await _frameSubscription?.cancel(); deviceHeartbeats.clear(); @@ -284,12 +440,61 @@ class CanBus extends Service { return Future.forEach(command.toDBC(), sendDBCMessage); } + /// Sends an arm command over the CAN bus + /// + /// If [override] is set to false, the command will only be sent if the rover + /// has received heartbeats from the arm device. The [override] should only + /// be true if this is a stop command. + Future sendArmCommand( + ArmCommand command, { + bool override = false, + }) async { + if (!_deviceConnected(Device.ARM) && !override) { + return; + } + return Future.forEach(command.toDBC(), sendDBCMessage); + } + + /// Sends a gripper command over the CAN bus + /// + /// If [override] is set to false, the command will only be sent if the rover + /// has received heartbeats from the gripper device. The [override] should only + /// be true if this is a stop command. + Future sendGripperCommand( + GripperCommand command, { + bool override = false, + }) async { + if (!_deviceConnected(Device.GRIPPER) && !override) { + return; + } + } + + /// Sends a science command over the CAN bus + /// + /// If [override] is set to false, the command will only be sent if the rover + /// has received heartbeats from the science device. The [override] should only + /// be true if this is a stop command. + Future sendScienceCommand( + ScienceCommand command, { + bool override = false, + }) async { + if (!_deviceConnected(Device.SCIENCE) && !override) { + return; + } + } + /// Sends a message's DBC equivalent over the CAN bus Future send(Message message) async { if (message is DriveCommand) { return sendDriveCommand(message); } else if (message is RelaysCommand) { return sendRelaysCommand(message); + } else if (message is ArmCommand) { + return sendArmCommand(message); + } else if (message is GripperCommand) { + return sendGripperCommand(message); + } else if (message is ScienceCommand) { + return sendScienceCommand(message); } } @@ -389,6 +594,18 @@ class CanBus extends Service { collection.server.sendMessage( RelayStateMessage.decode(data).toRelayProto(), ); + } else if (id == ArmMotorMoveDataMessage().canId) { + collection.server.sendMessage( + ArmMotorMoveDataMessage.decode(data).toArmProto(), + ); + } else if (id == ArmMotorStepDataMessage().canId) { + collection.server.sendMessage( + ArmMotorStepDataMessage.decode(data).toArmProto(), + ); + } else if (id == ArmMotorAngleDataMessage().canId) { + collection.server.sendMessage( + ArmMotorAngleDataMessage.decode(data).toArmProto(), + ); } case CanRemoteFrame _: break; From 27d5d68dc5acc1d8330bdd2930208c869527bdf9 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 12:00:20 -0400 Subject: [PATCH 12/30] Regenerated rover messages --- .../lib/src/generated/rover_messages.dbc.dart | 805 ++++++++++++++++++ 1 file changed, 805 insertions(+) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index be514455..f0799449 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -2279,3 +2279,808 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { return 'Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } } + +class ArmSetMotorMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Arm_Set_Motor'; + + @override + int messageLength = 8; + + @override + int canId = 0x30; + + /// Whether or not "Arm_Set_Motor" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Arm_Set_Motor" + static const String multiplexor = ''; + + /// Value of signal "Motor_Value" + num motorValue; + + /// Value of signal "Move_Steps" + num moveSteps; + + /// Value of signal "Move_Radians" + num moveRadians; + + /// Value of signal "Angle" + num angle; + + final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( + name: 'Motor_Value', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 3, + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2], + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', + ); + + final $_dbc.DBCSignal _moveStepsSignal = $_dbc.DBCSignal( + name: 'Move_Steps', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 24, + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26], + factor: 1, + offset: 0, + min: -8388608, + max: 8388608, + unit: '', + ); + + final $_dbc.DBCSignal _moveRadiansSignal = $_dbc.DBCSignal( + name: 'Move_Radians', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 27, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], + factor: 0.0000958738, + offset: 0, + min: -3.1415, + max: 3.1415, + unit: '', + ); + + final $_dbc.DBCSignal _angleSignal = $_dbc.DBCSignal( + name: 'Angle', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 43, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], + mappingIndexes: [43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], + factor: 0.0000958738, + offset: 0, + min: -3.1415, + max: -3.1415, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _motorValueSignal, + _moveStepsSignal, + _moveRadiansSignal, + _angleSignal, + ]; + + ArmSetMotorMessage({ + this.motorValue = 0, + this.moveSteps = 0, + this.moveRadians = 0, + this.angle = 0, + }); + + /// Creates a clone of this [ArmSetMotorMessage] with the non-null values replaced + ArmSetMotorMessage copyWith({ + num? motorValue, + num? moveSteps, + num? moveRadians, + num? angle, + }) => ArmSetMotorMessage( + motorValue: motorValue ?? this.motorValue, + moveSteps: moveSteps ?? this.moveSteps, + moveRadians: moveRadians ?? this.moveRadians, + angle: angle ?? this.angle, + ); + + factory ArmSetMotorMessage.decode(List payload) { + final message = ArmSetMotorMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + + message.motorValue = + message._motorValueSignal.decode(bitField) ?? + $_math.max(0, message._motorValueSignal.min); + message.moveSteps = + message._moveStepsSignal.decode(bitField) ?? + $_math.max(0, message._moveStepsSignal.min); + message.moveRadians = + message._moveRadiansSignal.decode(bitField) ?? + $_math.max(0, message._moveRadiansSignal.min); + message.angle = + message._angleSignal.decode(bitField) ?? + $_math.max(0, message._angleSignal.min); + + return message; + } + + factory ArmSetMotorMessage.fromJson(Map json) => + ArmSetMotorMessage( + motorValue: json['Motor_Value'] ?? 0, + moveSteps: json['Move_Steps'] ?? 0, + moveRadians: json['Move_Radians'] ?? 0, + angle: json['Angle'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _motorValueSignal: motorValue, + _moveStepsSignal: moveSteps, + _moveRadiansSignal: moveRadians, + _angleSignal: angle, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Motor_Value': motorValue, + 'Move_Steps': moveSteps, + 'Move_Radians': moveRadians, + 'Angle': angle, + }; + + @override + String toString() { + return 'Arm_Set_Motor(\n Motor_Value=$motorValue\n Move_Steps=$moveSteps\n Move_Radians=$moveRadians\n Angle=$angle\n)'; + } +} + +class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Arm_Motor_Move_Data'; + + @override + int messageLength = 2; + + @override + int canId = 0x35; + + /// Whether or not "Arm_Motor_Move_Data" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Arm_Motor_Move_Data" + static const String multiplexor = ''; + + /// Value of signal "Motor_Value" + num motorValue; + + /// Value of signal "Is_Moving" + num isMoving; + + /// Value of signal "Is_Limit_Switch_Pressed" + num isLimitSwitchPressed; + + /// Value of signal "Motor_Direction" + num motorDirection; + + final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( + name: 'Motor_Value', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 3, + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2], + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', + ); + + final $_dbc.DBCSignal _isMovingSignal = $_dbc.DBCSignal( + name: 'Is_Moving', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 2, + mapping: [0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4], + factor: 1, + offset: 0, + min: 0, + max: 3, + unit: '', + ); + + final $_dbc.DBCSignal _isLimitSwitchPressedSignal = $_dbc.DBCSignal( + name: 'Is_Limit_Switch_Pressed', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 5, + length: 2, + mapping: [0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [5, 6], + factor: 1, + offset: 0, + min: 0, + max: 0, + unit: '', + ); + + final $_dbc.DBCSignal _motorDirectionSignal = $_dbc.DBCSignal( + name: 'Motor_Direction', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 7, + length: 4, + mapping: [0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0], + mappingIndexes: [7, 8, 9, 10], + factor: 1, + offset: 0, + min: 0, + max: 9, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _motorValueSignal, + _isMovingSignal, + _isLimitSwitchPressedSignal, + _motorDirectionSignal, + ]; + + ArmMotorMoveDataMessage({ + this.motorValue = 0, + this.isMoving = 0, + this.isLimitSwitchPressed = 0, + this.motorDirection = 0, + }); + + /// Creates a clone of this [ArmMotorMoveDataMessage] with the non-null values replaced + ArmMotorMoveDataMessage copyWith({ + num? motorValue, + num? isMoving, + num? isLimitSwitchPressed, + num? motorDirection, + }) => ArmMotorMoveDataMessage( + motorValue: motorValue ?? this.motorValue, + isMoving: isMoving ?? this.isMoving, + isLimitSwitchPressed: isLimitSwitchPressed ?? this.isLimitSwitchPressed, + motorDirection: motorDirection ?? this.motorDirection, + ); + + factory ArmMotorMoveDataMessage.decode(List payload) { + final message = ArmMotorMoveDataMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + + message.motorValue = + message._motorValueSignal.decode(bitField) ?? + $_math.max(0, message._motorValueSignal.min); + message.isMoving = + message._isMovingSignal.decode(bitField) ?? + $_math.max(0, message._isMovingSignal.min); + message.isLimitSwitchPressed = + message._isLimitSwitchPressedSignal.decode(bitField) ?? + $_math.max(0, message._isLimitSwitchPressedSignal.min); + message.motorDirection = + message._motorDirectionSignal.decode(bitField) ?? + $_math.max(0, message._motorDirectionSignal.min); + + return message; + } + + factory ArmMotorMoveDataMessage.fromJson(Map json) => + ArmMotorMoveDataMessage( + motorValue: json['Motor_Value'] ?? 0, + isMoving: json['Is_Moving'] ?? 0, + isLimitSwitchPressed: json['Is_Limit_Switch_Pressed'] ?? 0, + motorDirection: json['Motor_Direction'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _motorValueSignal: motorValue, + _isMovingSignal: isMoving, + _isLimitSwitchPressedSignal: isLimitSwitchPressed, + _motorDirectionSignal: motorDirection, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Motor_Value': motorValue, + 'Is_Moving': isMoving, + 'Is_Limit_Switch_Pressed': isLimitSwitchPressed, + 'Motor_Direction': motorDirection, + }; + + @override + String toString() { + return 'Arm_Motor_Move_Data(\n Motor_Value=$motorValue\n Is_Moving=$isMoving\n Is_Limit_Switch_Pressed=$isLimitSwitchPressed\n Motor_Direction=$motorDirection\n)'; + } +} + +class ArmMotorStepDataMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Arm_Motor_Step_Data'; + + @override + int messageLength = 7; + + @override + int canId = 0x36; + + /// Whether or not "Arm_Motor_Step_Data" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Arm_Motor_Step_Data" + static const String multiplexor = ''; + + /// Value of signal "Motor_Value" + num motorValue; + + /// Value of signal "Current_Step" + num currentStep; + + /// Value of signal "Target_Step" + num targetStep; + + final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( + name: 'Motor_Value', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 4, + mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', + ); + + final $_dbc.DBCSignal _currentStepSignal = $_dbc.DBCSignal( + name: 'Current_Step', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 24, + mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + factor: 1, + offset: 0, + min: -8388608, + max: 8388608, + unit: '', + ); + + final $_dbc.DBCSignal _targetStepSignal = $_dbc.DBCSignal( + name: 'Target_Step', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 28, + length: 24, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0], + mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], + factor: 1, + offset: 0, + min: -8388608, + max: 8388608, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _motorValueSignal, + _currentStepSignal, + _targetStepSignal, + ]; + + ArmMotorStepDataMessage({ + this.motorValue = 0, + this.currentStep = 0, + this.targetStep = 0, + }); + + /// Creates a clone of this [ArmMotorStepDataMessage] with the non-null values replaced + ArmMotorStepDataMessage copyWith({ + num? motorValue, + num? currentStep, + num? targetStep, + }) => ArmMotorStepDataMessage( + motorValue: motorValue ?? this.motorValue, + currentStep: currentStep ?? this.currentStep, + targetStep: targetStep ?? this.targetStep, + ); + + factory ArmMotorStepDataMessage.decode(List payload) { + final message = ArmMotorStepDataMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + + message.motorValue = + message._motorValueSignal.decode(bitField) ?? + $_math.max(0, message._motorValueSignal.min); + message.currentStep = + message._currentStepSignal.decode(bitField) ?? + $_math.max(0, message._currentStepSignal.min); + message.targetStep = + message._targetStepSignal.decode(bitField) ?? + $_math.max(0, message._targetStepSignal.min); + + return message; + } + + factory ArmMotorStepDataMessage.fromJson(Map json) => + ArmMotorStepDataMessage( + motorValue: json['Motor_Value'] ?? 0, + currentStep: json['Current_Step'] ?? 0, + targetStep: json['Target_Step'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _motorValueSignal: motorValue, + _currentStepSignal: currentStep, + _targetStepSignal: targetStep, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Motor_Value': motorValue, + 'Current_Step': currentStep, + 'Target_Step': targetStep, + }; + + @override + String toString() { + return 'Arm_Motor_Step_Data(\n Motor_Value=$motorValue\n Current_Step=$currentStep\n Target_Step=$targetStep\n)'; + } +} + +class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Arm_Motor_Angle_Data'; + + @override + int messageLength = 5; + + @override + int canId = 0x37; + + /// Whether or not "Arm_Motor_Angle_Data" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Arm_Motor_Angle_Data" + static const String multiplexor = ''; + + /// Value of signal "Motor_Value" + num motorValue; + + /// Value of signal "Current_Angle" + num currentAngle; + + /// Value of signal "Target_Angle" + num targetAngle; + + final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( + name: 'Motor_Value', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 3, + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2], + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', + ); + + final $_dbc.DBCSignal _currentAngleSignal = $_dbc.DBCSignal( + name: 'Current_Angle', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 16, + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], + factor: 0.00009587379, + offset: 0, + min: -3.14159, + max: 3.14159, + unit: '', + ); + + final $_dbc.DBCSignal _targetAngleSignal = $_dbc.DBCSignal( + name: 'Target_Angle', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 19, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], + mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], + factor: 0.00009587379, + offset: 0, + min: -3.14159, + max: 3.14159, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _motorValueSignal, + _currentAngleSignal, + _targetAngleSignal, + ]; + + ArmMotorAngleDataMessage({ + this.motorValue = 0, + this.currentAngle = 0, + this.targetAngle = 0, + }); + + /// Creates a clone of this [ArmMotorAngleDataMessage] with the non-null values replaced + ArmMotorAngleDataMessage copyWith({ + num? motorValue, + num? currentAngle, + num? targetAngle, + }) => ArmMotorAngleDataMessage( + motorValue: motorValue ?? this.motorValue, + currentAngle: currentAngle ?? this.currentAngle, + targetAngle: targetAngle ?? this.targetAngle, + ); + + factory ArmMotorAngleDataMessage.decode(List payload) { + final message = ArmMotorAngleDataMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + + message.motorValue = + message._motorValueSignal.decode(bitField) ?? + $_math.max(0, message._motorValueSignal.min); + message.currentAngle = + message._currentAngleSignal.decode(bitField) ?? + $_math.max(0, message._currentAngleSignal.min); + message.targetAngle = + message._targetAngleSignal.decode(bitField) ?? + $_math.max(0, message._targetAngleSignal.min); + + return message; + } + + factory ArmMotorAngleDataMessage.fromJson(Map json) => + ArmMotorAngleDataMessage( + motorValue: json['Motor_Value'] ?? 0, + currentAngle: json['Current_Angle'] ?? 0, + targetAngle: json['Target_Angle'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _motorValueSignal: motorValue, + _currentAngleSignal: currentAngle, + _targetAngleSignal: targetAngle, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Motor_Value': motorValue, + 'Current_Angle': currentAngle, + 'Target_Angle': targetAngle, + }; + + @override + String toString() { + return 'Arm_Motor_Angle_Data(\n Motor_Value=$motorValue\n Current_Angle=$currentAngle\n Target_Angle=$targetAngle\n)'; + } +} + +class ArmSystemActionMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Arm_System_Action'; + + @override + int messageLength = 1; + + @override + int canId = 0x31; + + /// Whether or not "Arm_System_Action" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Arm_System_Action" + static const String multiplexor = ''; + + /// Value of signal "Stop" + num stop; + + /// Value of signal "Calibrate" + num calibrate; + + /// Value of signal "Jab" + num jab; + + final $_dbc.DBCSignal _stopSignal = $_dbc.DBCSignal( + name: 'Stop', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 1, + mapping: [1, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _calibrateSignal = $_dbc.DBCSignal( + name: 'Calibrate', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 1, + length: 1, + mapping: [0, 1, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _jabSignal = $_dbc.DBCSignal( + name: 'Jab', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _stopSignal, + _calibrateSignal, + _jabSignal, + ]; + + ArmSystemActionMessage({ + this.stop = 0, + this.calibrate = 0, + this.jab = 0, + }); + + /// Creates a clone of this [ArmSystemActionMessage] with the non-null values replaced + ArmSystemActionMessage copyWith({ + num? stop, + num? calibrate, + num? jab, + }) => ArmSystemActionMessage( + stop: stop ?? this.stop, + calibrate: calibrate ?? this.calibrate, + jab: jab ?? this.jab, + ); + + factory ArmSystemActionMessage.decode(List payload) { + final message = ArmSystemActionMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + + message.stop = + message._stopSignal.decode(bitField) ?? + $_math.max(0, message._stopSignal.min); + message.calibrate = + message._calibrateSignal.decode(bitField) ?? + $_math.max(0, message._calibrateSignal.min); + message.jab = + message._jabSignal.decode(bitField) ?? + $_math.max(0, message._jabSignal.min); + + return message; + } + + factory ArmSystemActionMessage.fromJson(Map json) => + ArmSystemActionMessage( + stop: json['Stop'] ?? 0, + calibrate: json['Calibrate'] ?? 0, + jab: json['Jab'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _stopSignal: stop, + _calibrateSignal: calibrate, + _jabSignal: jab, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Stop': stop, + 'Calibrate': calibrate, + 'Jab': jab, + }; + + @override + String toString() { + return 'Arm_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; + } +} From 077de7447562d075562e9a8060e8ecb68f09cc74 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 14:22:36 -0400 Subject: [PATCH 13/30] Add CAN devices to subsystems data message --- subsystems/lib/subsystems.dart | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/subsystems/lib/subsystems.dart b/subsystems/lib/subsystems.dart index ca78ffeb..987ef9e5 100644 --- a/subsystems/lib/subsystems.dart +++ b/subsystems/lib/subsystems.dart @@ -99,9 +99,12 @@ class SubsystemsCollection extends Service { server.sendMessage( SubsystemsData( version: Version(major: 1, minor: 0), - connectedDevices: firmware.devices - .where((e) => e.isReady) - .map((firmware) => firmware.device), + connectedDevices: { + ...can.connectedDevices, + ...firmware.devices + .where((e) => e.isReady) + .map((firmware) => firmware.device), + }, gpsConnected: gps.isConnected ? BoolState.YES : BoolState.NO, imuConnected: imu.isConnected ? BoolState.YES : BoolState.NO, ), From 59ac1d91995793bea91843b11ee81ec4b3b88eac Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 14:32:03 -0400 Subject: [PATCH 14/30] Fix ranges of arm motor values --- .../lib/src/generated/rover_messages.dbc.dart | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index f0799449..e0d5bbad 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -2321,7 +2321,7 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 8, + max: 7, unit: '', ); @@ -2500,7 +2500,7 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 8, + max: 7, unit: '', ); @@ -2670,13 +2670,13 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, - length: 4, - mapping: [1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3], + length: 3, + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2], factor: 1, offset: 0, min: 0, - max: 8, + max: 7, unit: '', ); @@ -2686,10 +2686,10 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 4, + start: 3, length: 24, - mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26], factor: 1, offset: 0, min: -8388608, @@ -2703,10 +2703,10 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 28, + start: 27, length: 24, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0], - mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0], + mappingIndexes: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], factor: 1, offset: 0, min: -8388608, @@ -2825,7 +2825,7 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 8, + max: 7, unit: '', ); From 08837193fc9a848ca52c0223d129b9cdba952ada Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:04:43 -0400 Subject: [PATCH 15/30] Fixed sign of arm angle data --- subsystems/lib/src/generated/rover_messages.dbc.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index e0d5bbad..76a6c2de 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -2831,7 +2831,7 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { final $_dbc.DBCSignal _currentAngleSignal = $_dbc.DBCSignal( name: 'Current_Angle', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, @@ -2848,7 +2848,7 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { final $_dbc.DBCSignal _targetAngleSignal = $_dbc.DBCSignal( name: 'Target_Angle', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, From 81c1e394817b2788938f66dd708ad990741a3267 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 17:06:22 -0400 Subject: [PATCH 16/30] Fixed motor move data range and boolstate decoding --- subsystems/lib/src/devices/can_bus.dart | 14 ++++++++------ .../lib/src/generated/rover_messages.dbc.dart | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 307d77fb..d01509f1 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -13,12 +13,14 @@ extension on num { BoolState get boolState => boolValue ? BoolState.YES : BoolState.NO; - BoolState get armBoolState => - this == 1 - ? BoolState.YES - : this == 2 - ? BoolState.NO - : BoolState.BOOL_UNDEFINED; + BoolState get armBoolState { + if (this == 1) { + return BoolState.YES; + } else if (this == 2) { + return BoolState.NO; + } + return BoolState.BOOL_UNDEFINED; + } } extension on bool { diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 76a6c2de..338dd962 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -2517,7 +2517,7 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 3, + max: 2, unit: '', ); @@ -2534,7 +2534,7 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 0, + max: 2, unit: '', ); From 960744dea6f9a7d8630eeb0c35aaa71bcda4e1bc Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 28 Apr 2025 17:22:52 -0400 Subject: [PATCH 17/30] Increased bit count and range of arm step data --- .../lib/src/generated/rover_messages.dbc.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 338dd962..fad3b358 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -2687,13 +2687,13 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, - length: 24, - mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26], + length: 26, + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28], factor: 1, offset: 0, - min: -8388608, - max: 8388608, + min: -33554432, + max: 33554432, unit: '', ); @@ -2703,14 +2703,14 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 27, - length: 24, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0], - mappingIndexes: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], + start: 29, + length: 26, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 0], + mappingIndexes: [29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54], factor: 1, offset: 0, - min: -8388608, - max: 8388608, + min: -33554432, + max: 3355443208, unit: '', ); From bc74f370f9888dad80b914f86871472d523d8b5f Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Wed, 7 May 2025 22:12:32 -0400 Subject: [PATCH 18/30] Regenerated file with new dbc --- .../lib/src/generated/rover_messages.dbc.dart | 2193 +++++++++-------- 1 file changed, 1201 insertions(+), 992 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index fad3b358..8023adf6 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -154,8 +154,8 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { mappingIndexes: [5, 6, 7, 8], factor: 1, offset: 0, - min: 0, - max: 8, + min: 1, + max: 15, unit: '', ); @@ -172,7 +172,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 8, + max: 15, unit: '', ); @@ -185,7 +185,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { DeviceBroadcastMessage({ this.deviceValue = 0, - this.fwVersionMajor = 0, + this.fwVersionMajor = 1, this.fwVersionMinor = 0, }); @@ -221,7 +221,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { factory DeviceBroadcastMessage.fromJson(Map json) => DeviceBroadcastMessage( deviceValue: json['Device_Value'] ?? 0, - fwVersionMajor: json['FW_Version_Major'] ?? 0, + fwVersionMajor: json['FW_Version_Major'] ?? 1, fwVersionMinor: json['FW_Version_Minor'] ?? 0, ); @@ -607,55 +607,73 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { } } -class DriveLedMessage extends $_dbc.DBCMessage { +class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_LED'; + String messageName = 'Drive_SetSwivel'; @override - int messageLength = 1; + int messageLength = 7; @override - int canId = 0x17; + int canId = 0x12; - /// Whether or not "Drive_LED" is multiplex + /// Whether or not "Drive_SetSwivel" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_LED" + /// The multiplexor for "Drive_SetSwivel" static const String multiplexor = ''; - /// Value of signal "Color" - num color; + /// Value of signal "Set_Front_Swivel" + num setFrontSwivel; - /// Value of signal "Blink" - num blink; + /// Value of signal "Set_Front_Tilt" + num setFrontTilt; - final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( - name: 'Color', + /// Value of signal "Set_Rear_Swivel" + num setRearSwivel; + + /// Value of signal "Set_Rear_Tilt" + num setRearTilt; + + /// Value of signal "Front_Swivel" + num frontSwivel; + + /// Value of signal "Front_Tilt" + num frontTilt; + + /// Value of signal "Rear_Swivel" + num rearSwivel; + + /// Value of signal "Rear_Tilt" + num rearTilt; + + final $_dbc.DBCSignal _setFrontSwivelSignal = $_dbc.DBCSignal( + name: 'Set_Front_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, - length: 4, - mapping: [1, 2, 4, 8, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3], + length: 1, + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], factor: 1, offset: 0, min: 0, - max: 8, + max: 1, unit: '', ); - final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( - name: 'Blink', + final $_dbc.DBCSignal _setFrontTiltSignal = $_dbc.DBCSignal( + name: 'Set_Front_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 4, + start: 1, length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0], - mappingIndexes: [4], + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], factor: 1, offset: 0, min: 0, @@ -663,200 +681,208 @@ class DriveLedMessage extends $_dbc.DBCMessage { unit: '', ); - @override - List<$_dbc.DBCSignal> get signals => [ - _colorSignal, - _blinkSignal, - ]; - - DriveLedMessage({ - this.color = 0, - this.blink = 0, - }); - - /// Creates a clone of this [DriveLedMessage] with the non-null values replaced - DriveLedMessage copyWith({ - num? color, - num? blink, - }) => DriveLedMessage( - color: color ?? this.color, - blink: blink ?? this.blink, + final $_dbc.DBCSignal _setRearSwivelSignal = $_dbc.DBCSignal( + name: 'Set_Rear_Swivel', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', ); - factory DriveLedMessage.decode(List payload) { - final message = DriveLedMessage(); - final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.color = - message._colorSignal.decode(bitField) ?? - $_math.max(0, message._colorSignal.min); - message.blink = - message._blinkSignal.decode(bitField) ?? - $_math.max(0, message._blinkSignal.min); - - return message; - } - - factory DriveLedMessage.fromJson(Map json) => - DriveLedMessage( - color: json['Color'] ?? 0, - blink: json['Blink'] ?? 0, - ); - - @override - $_typed.Uint8List encode() { - final Map<$_dbc.DBCSignal, num> values = { - _colorSignal: color, - _blinkSignal: blink, - }; - - return encodeWithValues(values); - } - - @override - Map toJson() => { - 'Color': color, - 'Blink': blink, - }; - - @override - String toString() { - return 'Drive_LED(\n Color=$color\n Blink=$blink\n)'; - } -} - -class DriveAppliedOutputMessage extends $_dbc.DBCMessage { - @override - String messageName = 'Drive_Applied_Output'; - - @override - int messageLength = 6; - - @override - int canId = 0x15; - - /// Whether or not "Drive_Applied_Output" is multiplex - static const bool isMultiplex = false; - - /// The multiplexor for "Drive_Applied_Output" - static const String multiplexor = ''; - - /// Value of signal "Throttle" - num throttle; - - /// Value of signal "Left_Speed" - num leftSpeed; - - /// Value of signal "Right_Speed" - num rightSpeed; - - final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( - name: 'Throttle', + final $_dbc.DBCSignal _setRearTiltSignal = $_dbc.DBCSignal( + name: 'Set_Rear_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 0, - length: 16, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.000016, + start: 3, + length: 1, + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3], + factor: 1, offset: 0, min: 0, max: 1, unit: '', ); - final $_dbc.DBCSignal _leftSpeedSignal = $_dbc.DBCSignal( - name: 'Left_Speed', + final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( + name: 'Front_Swivel', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 12, + mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + factor: 0.044, + offset: 0, + min: -90, + max: 90, + unit: '°', + ); + + final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( + name: 'Front_Tilt', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 16, - length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], - factor: 0.000062, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + factor: 0.044, offset: 0, - min: -1, - max: 1, - unit: '', + min: -90, + max: 90, + unit: '°', ); - final $_dbc.DBCSignal _rightSpeedSignal = $_dbc.DBCSignal( - name: 'Right_Speed', + final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( + name: 'Rear_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 32, - length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], - mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], - factor: 0.000062, + start: 28, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], + factor: 0.044, offset: 0, - min: -1, - max: 1, - unit: '', + min: -90, + max: 90, + unit: '°', + ); + + final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( + name: 'Rear_Tilt', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 40, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0], + mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], + factor: 0.044, + offset: 0, + min: -90, + max: 90, + unit: '°', ); @override List<$_dbc.DBCSignal> get signals => [ - _throttleSignal, - _leftSpeedSignal, - _rightSpeedSignal, - ]; + _setFrontSwivelSignal, + _setFrontTiltSignal, + _setRearSwivelSignal, + _setRearTiltSignal, + _frontSwivelSignal, + _frontTiltSignal, + _rearSwivelSignal, + _rearTiltSignal, + ]; - DriveAppliedOutputMessage({ - this.throttle = 0, - this.leftSpeed = 0, - this.rightSpeed = 0, + DriveSetSwivelMessage({ + this.setFrontSwivel = 0, + this.setFrontTilt = 0, + this.setRearSwivel = 0, + this.setRearTilt = 0, + this.frontSwivel = 0, + this.frontTilt = 0, + this.rearSwivel = 0, + this.rearTilt = 0, }); - /// Creates a clone of this [DriveAppliedOutputMessage] with the non-null values replaced - DriveAppliedOutputMessage copyWith({ - num? throttle, - num? leftSpeed, - num? rightSpeed, - }) => DriveAppliedOutputMessage( - throttle: throttle ?? this.throttle, - leftSpeed: leftSpeed ?? this.leftSpeed, - rightSpeed: rightSpeed ?? this.rightSpeed, + /// Creates a clone of this [DriveSetSwivelMessage] with the non-null values replaced + DriveSetSwivelMessage copyWith({ + num? setFrontSwivel, + num? setFrontTilt, + num? setRearSwivel, + num? setRearTilt, + num? frontSwivel, + num? frontTilt, + num? rearSwivel, + num? rearTilt, + }) => DriveSetSwivelMessage( + setFrontSwivel: setFrontSwivel ?? this.setFrontSwivel, + setFrontTilt: setFrontTilt ?? this.setFrontTilt, + setRearSwivel: setRearSwivel ?? this.setRearSwivel, + setRearTilt: setRearTilt ?? this.setRearTilt, + frontSwivel: frontSwivel ?? this.frontSwivel, + frontTilt: frontTilt ?? this.frontTilt, + rearSwivel: rearSwivel ?? this.rearSwivel, + rearTilt: rearTilt ?? this.rearTilt, ); - factory DriveAppliedOutputMessage.decode(List payload) { - final message = DriveAppliedOutputMessage(); + factory DriveSetSwivelMessage.decode(List payload) { + final message = DriveSetSwivelMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.throttle = - message._throttleSignal.decode(bitField) ?? - $_math.max(0, message._throttleSignal.min); - message.leftSpeed = - message._leftSpeedSignal.decode(bitField) ?? - $_math.max(0, message._leftSpeedSignal.min); - message.rightSpeed = - message._rightSpeedSignal.decode(bitField) ?? - $_math.max(0, message._rightSpeedSignal.min); + message.setFrontSwivel = + message._setFrontSwivelSignal.decode(bitField) ?? + $_math.max(0, message._setFrontSwivelSignal.min); + message.setFrontTilt = + message._setFrontTiltSignal.decode(bitField) ?? + $_math.max(0, message._setFrontTiltSignal.min); + message.setRearSwivel = + message._setRearSwivelSignal.decode(bitField) ?? + $_math.max(0, message._setRearSwivelSignal.min); + message.setRearTilt = + message._setRearTiltSignal.decode(bitField) ?? + $_math.max(0, message._setRearTiltSignal.min); + message.frontSwivel = + message._frontSwivelSignal.decode(bitField) ?? + $_math.max(0, message._frontSwivelSignal.min); + message.frontTilt = + message._frontTiltSignal.decode(bitField) ?? + $_math.max(0, message._frontTiltSignal.min); + message.rearSwivel = + message._rearSwivelSignal.decode(bitField) ?? + $_math.max(0, message._rearSwivelSignal.min); + message.rearTilt = + message._rearTiltSignal.decode(bitField) ?? + $_math.max(0, message._rearTiltSignal.min); return message; } - factory DriveAppliedOutputMessage.fromJson(Map json) => - DriveAppliedOutputMessage( - throttle: json['Throttle'] ?? 0, - leftSpeed: json['Left_Speed'] ?? 0, - rightSpeed: json['Right_Speed'] ?? 0, + factory DriveSetSwivelMessage.fromJson(Map json) => + DriveSetSwivelMessage( + setFrontSwivel: json['Set_Front_Swivel'] ?? 0, + setFrontTilt: json['Set_Front_Tilt'] ?? 0, + setRearSwivel: json['Set_Rear_Swivel'] ?? 0, + setRearTilt: json['Set_Rear_Tilt'] ?? 0, + frontSwivel: json['Front_Swivel'] ?? 0, + frontTilt: json['Front_Tilt'] ?? 0, + rearSwivel: json['Rear_Swivel'] ?? 0, + rearTilt: json['Rear_Tilt'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _throttleSignal: throttle, - _leftSpeedSignal: leftSpeed, - _rightSpeedSignal: rightSpeed, + _setFrontSwivelSignal: setFrontSwivel, + _setFrontTiltSignal: setFrontTilt, + _setRearSwivelSignal: setRearSwivel, + _setRearTiltSignal: setRearTilt, + _frontSwivelSignal: frontSwivel, + _frontTiltSignal: frontTilt, + _rearSwivelSignal: rearSwivel, + _rearTiltSignal: rearTilt, }; return encodeWithValues(values); @@ -864,148 +890,124 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Throttle': throttle, - 'Left_Speed': leftSpeed, - 'Right_Speed': rightSpeed, + 'Set_Front_Swivel': setFrontSwivel, + 'Set_Front_Tilt': setFrontTilt, + 'Set_Rear_Swivel': setRearSwivel, + 'Set_Rear_Tilt': setRearTilt, + 'Front_Swivel': frontSwivel, + 'Front_Tilt': frontTilt, + 'Rear_Swivel': rearSwivel, + 'Rear_Tilt': rearTilt, }; @override String toString() { - return 'Drive_Applied_Output(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; + return 'Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } } -class DriveBatteryMessage extends $_dbc.DBCMessage { +class DriveLedMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Battery'; + String messageName = 'Drive_LED'; @override - int messageLength = 6; + int messageLength = 1; @override - int canId = 0x16; + int canId = 0x17; - /// Whether or not "Drive_Battery" is multiplex + /// Whether or not "Drive_LED" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_Battery" + /// The multiplexor for "Drive_LED" static const String multiplexor = ''; - /// Value of signal "Voltage" - num voltage; - - /// Value of signal "Temperature" - num temperature; + /// Value of signal "Color" + num color; - /// Value of signal "Current" - num current; + /// Value of signal "Blink" + num blink; - final $_dbc.DBCSignal _voltageSignal = $_dbc.DBCSignal( - name: 'Voltage', + final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( + name: 'Color', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, - length: 16, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.00055, + length: 4, + mapping: [1, 2, 4, 8, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + factor: 1, offset: 0, min: 0, - max: 36, - unit: 'V', - ); - - final $_dbc.DBCSignal _temperatureSignal = $_dbc.DBCSignal( - name: 'Temperature', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 16, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 0.09, - offset: 50, - min: -40, - max: 150, - unit: 'C', + max: 8, + unit: '', ); - final $_dbc.DBCSignal _currentSignal = $_dbc.DBCSignal( - name: 'Current', + final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( + name: 'Blink', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 28, - length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0], - mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], - factor: 0.1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0], + mappingIndexes: [4], + factor: 1, offset: 0, min: 0, - max: 30, - unit: 'A', + max: 1, + unit: '', ); @override List<$_dbc.DBCSignal> get signals => [ - _voltageSignal, - _temperatureSignal, - _currentSignal, + _colorSignal, + _blinkSignal, ]; - DriveBatteryMessage({ - this.voltage = 0, - this.temperature = 50, - this.current = 0, + DriveLedMessage({ + this.color = 0, + this.blink = 0, }); - /// Creates a clone of this [DriveBatteryMessage] with the non-null values replaced - DriveBatteryMessage copyWith({ - num? voltage, - num? temperature, - num? current, - }) => DriveBatteryMessage( - voltage: voltage ?? this.voltage, - temperature: temperature ?? this.temperature, - current: current ?? this.current, + /// Creates a clone of this [DriveLedMessage] with the non-null values replaced + DriveLedMessage copyWith({ + num? color, + num? blink, + }) => DriveLedMessage( + color: color ?? this.color, + blink: blink ?? this.blink, ); - factory DriveBatteryMessage.decode(List payload) { - final message = DriveBatteryMessage(); + factory DriveLedMessage.decode(List payload) { + final message = DriveLedMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.voltage = - message._voltageSignal.decode(bitField) ?? - $_math.max(0, message._voltageSignal.min); - message.temperature = - message._temperatureSignal.decode(bitField) ?? - $_math.max(0, message._temperatureSignal.min); - message.current = - message._currentSignal.decode(bitField) ?? - $_math.max(0, message._currentSignal.min); + message.color = + message._colorSignal.decode(bitField) ?? + $_math.max(0, message._colorSignal.min); + message.blink = + message._blinkSignal.decode(bitField) ?? + $_math.max(0, message._blinkSignal.min); return message; } - factory DriveBatteryMessage.fromJson(Map json) => - DriveBatteryMessage( - voltage: json['Voltage'] ?? 0, - temperature: json['Temperature'] ?? 50, - current: json['Current'] ?? 0, + factory DriveLedMessage.fromJson(Map json) => + DriveLedMessage( + color: json['Color'] ?? 0, + blink: json['Blink'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _voltageSignal: voltage, - _temperatureSignal: temperature, - _currentSignal: current, + _colorSignal: color, + _blinkSignal: blink, }; return encodeWithValues(values); @@ -1013,177 +1015,147 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Voltage': voltage, - 'Temperature': temperature, - 'Current': current, + 'Color': color, + 'Blink': blink, }; @override String toString() { - return 'Drive_Battery(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; + return 'Drive_LED(\n Color=$color\n Blink=$blink\n)'; } } -class DriveSwivelMessage extends $_dbc.DBCMessage { +class DriveAppliedOutputMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Swivel'; + String messageName = 'Drive_Applied_Output'; @override int messageLength = 6; @override - int canId = 0x18; + int canId = 0x15; - /// Whether or not "Drive_Swivel" is multiplex + /// Whether or not "Drive_Applied_Output" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_Swivel" + /// The multiplexor for "Drive_Applied_Output" static const String multiplexor = ''; - /// Value of signal "Front_Swivel" - num frontSwivel; - - /// Value of signal "Front_Tilt" - num frontTilt; + /// Value of signal "Throttle" + num throttle; - /// Value of signal "Rear_Swivel" - num rearSwivel; + /// Value of signal "Left_Speed" + num leftSpeed; - /// Value of signal "Rear_Tilt" - num rearTilt; + /// Value of signal "Right_Speed" + num rightSpeed; - final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( - name: 'Front_Swivel', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( + name: 'Throttle', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, - length: 12, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], - factor: 0.044, - offset: 0, - min: -90, - max: 90, - unit: '°', - ); - - final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( - name: 'Front_Tilt', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 12, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], - factor: 0.044, + length: 16, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + factor: 0.000016, offset: 0, - min: -90, - max: 90, - unit: '°', + min: 0, + max: 1, + unit: '', ); - final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( - name: 'Rear_Swivel', + final $_dbc.DBCSignal _leftSpeedSignal = $_dbc.DBCSignal( + name: 'Left_Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 24, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], - factor: 0.044, + start: 16, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], + factor: 0.000062, offset: 0, - min: -90, - max: 90, - unit: '°', + min: -1, + max: 1, + unit: '', ); - final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( - name: 'Rear_Tilt', + final $_dbc.DBCSignal _rightSpeedSignal = $_dbc.DBCSignal( + name: 'Right_Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 36, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], - mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], - factor: 0.044, + start: 32, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], + mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], + factor: 0.000062, offset: 0, - min: -90, - max: 90, - unit: '°', + min: -1, + max: 1, + unit: '', ); @override List<$_dbc.DBCSignal> get signals => [ - _frontSwivelSignal, - _frontTiltSignal, - _rearSwivelSignal, - _rearTiltSignal, + _throttleSignal, + _leftSpeedSignal, + _rightSpeedSignal, ]; - DriveSwivelMessage({ - this.frontSwivel = 0, - this.frontTilt = 0, - this.rearSwivel = 0, - this.rearTilt = 0, + DriveAppliedOutputMessage({ + this.throttle = 0, + this.leftSpeed = 0, + this.rightSpeed = 0, }); - /// Creates a clone of this [DriveSwivelMessage] with the non-null values replaced - DriveSwivelMessage copyWith({ - num? frontSwivel, - num? frontTilt, - num? rearSwivel, - num? rearTilt, - }) => DriveSwivelMessage( - frontSwivel: frontSwivel ?? this.frontSwivel, - frontTilt: frontTilt ?? this.frontTilt, - rearSwivel: rearSwivel ?? this.rearSwivel, - rearTilt: rearTilt ?? this.rearTilt, + /// Creates a clone of this [DriveAppliedOutputMessage] with the non-null values replaced + DriveAppliedOutputMessage copyWith({ + num? throttle, + num? leftSpeed, + num? rightSpeed, + }) => DriveAppliedOutputMessage( + throttle: throttle ?? this.throttle, + leftSpeed: leftSpeed ?? this.leftSpeed, + rightSpeed: rightSpeed ?? this.rightSpeed, ); - factory DriveSwivelMessage.decode(List payload) { - final message = DriveSwivelMessage(); + factory DriveAppliedOutputMessage.decode(List payload) { + final message = DriveAppliedOutputMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.frontSwivel = - message._frontSwivelSignal.decode(bitField) ?? - $_math.max(0, message._frontSwivelSignal.min); - message.frontTilt = - message._frontTiltSignal.decode(bitField) ?? - $_math.max(0, message._frontTiltSignal.min); - message.rearSwivel = - message._rearSwivelSignal.decode(bitField) ?? - $_math.max(0, message._rearSwivelSignal.min); - message.rearTilt = - message._rearTiltSignal.decode(bitField) ?? - $_math.max(0, message._rearTiltSignal.min); + message.throttle = + message._throttleSignal.decode(bitField) ?? + $_math.max(0, message._throttleSignal.min); + message.leftSpeed = + message._leftSpeedSignal.decode(bitField) ?? + $_math.max(0, message._leftSpeedSignal.min); + message.rightSpeed = + message._rightSpeedSignal.decode(bitField) ?? + $_math.max(0, message._rightSpeedSignal.min); return message; } - factory DriveSwivelMessage.fromJson(Map json) => - DriveSwivelMessage( - frontSwivel: json['Front_Swivel'] ?? 0, - frontTilt: json['Front_Tilt'] ?? 0, - rearSwivel: json['Rear_Swivel'] ?? 0, - rearTilt: json['Rear_Tilt'] ?? 0, + factory DriveAppliedOutputMessage.fromJson(Map json) => + DriveAppliedOutputMessage( + throttle: json['Throttle'] ?? 0, + leftSpeed: json['Left_Speed'] ?? 0, + rightSpeed: json['Right_Speed'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _frontSwivelSignal: frontSwivel, - _frontTiltSignal: frontTilt, - _rearSwivelSignal: rearSwivel, - _rearTiltSignal: rearTilt, + _throttleSignal: throttle, + _leftSpeedSignal: leftSpeed, + _rightSpeedSignal: rightSpeed, }; return encodeWithValues(values); @@ -1191,468 +1163,534 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Front_Swivel': frontSwivel, - 'Front_Tilt': frontTilt, - 'Rear_Swivel': rearSwivel, - 'Rear_Tilt': rearTilt, + 'Throttle': throttle, + 'Left_Speed': leftSpeed, + 'Right_Speed': rightSpeed, }; @override String toString() { - return 'Drive_Swivel(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; + return 'Drive_Applied_Output(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; } } -class RelaySetStateMessage extends $_dbc.DBCMessage { +class DriveBatteryMessage extends $_dbc.DBCMessage { @override - String messageName = 'Relay_Set_State'; + String messageName = 'Drive_Battery'; @override - int messageLength = 2; + int messageLength = 6; @override - int canId = 0x20; + int canId = 0x16; - /// Whether or not "Relay_Set_State" is multiplex + /// Whether or not "Drive_Battery" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Relay_Set_State" + /// The multiplexor for "Drive_Battery" static const String multiplexor = ''; - /// Value of signal "Update_Front_Left_Motor" - num updateFrontLeftMotor; - - /// Value of signal "Front_Left_Motor" - num frontLeftMotor; - - /// Value of signal "Update_Front_Right_Motor" - num updateFrontRightMotor; - - /// Value of signal "Front_Right_Motor" - num frontRightMotor; - - /// Value of signal "Update_Back_Left_Motor" - num updateBackLeftMotor; + /// Value of signal "Voltage" + num voltage; - /// Value of signal "Back_Left_Motor" - num backLeftMotor; + /// Value of signal "Temperature" + num temperature; - /// Value of signal "Update_Back_Right_Motor" - num updateBackRightMotor; + /// Value of signal "Current" + num current; - /// Value of signal "Back_Right_Motor" - num backRightMotor; + final $_dbc.DBCSignal _voltageSignal = $_dbc.DBCSignal( + name: 'Voltage', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 0, + length: 16, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + factor: 0.00055, + offset: 0, + min: 0, + max: 36, + unit: 'V', + ); - /// Value of signal "Update_Arm" - num updateArm; + final $_dbc.DBCSignal _temperatureSignal = $_dbc.DBCSignal( + name: 'Temperature', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 16, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + factor: 0.09, + offset: 50, + min: -40, + max: 150, + unit: 'C', + ); - /// Value of signal "Arm" - num arm; + final $_dbc.DBCSignal _currentSignal = $_dbc.DBCSignal( + name: 'Current', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 28, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0], + mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], + factor: 0.1, + offset: 0, + min: 0, + max: 30, + unit: 'A', + ); - /// Value of signal "Update_Science" - num updateScience; + @override + List<$_dbc.DBCSignal> get signals => [ + _voltageSignal, + _temperatureSignal, + _currentSignal, + ]; - /// Value of signal "Science" - num science; + DriveBatteryMessage({ + this.voltage = 0, + this.temperature = 50, + this.current = 0, + }); - /// Value of signal "Update_Drive" - num updateDrive; + /// Creates a clone of this [DriveBatteryMessage] with the non-null values replaced + DriveBatteryMessage copyWith({ + num? voltage, + num? temperature, + num? current, + }) => DriveBatteryMessage( + voltage: voltage ?? this.voltage, + temperature: temperature ?? this.temperature, + current: current ?? this.current, + ); - /// Value of signal "Drive" - num drive; + factory DriveBatteryMessage.decode(List payload) { + final message = DriveBatteryMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - final $_dbc.DBCSignal _updateFrontLeftMotorSignal = $_dbc.DBCSignal( - name: 'Update_Front_Left_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + message.voltage = + message._voltageSignal.decode(bitField) ?? + $_math.max(0, message._voltageSignal.min); + message.temperature = + message._temperatureSignal.decode(bitField) ?? + $_math.max(0, message._temperatureSignal.min); + message.current = + message._currentSignal.decode(bitField) ?? + $_math.max(0, message._currentSignal.min); + + return message; + } + + factory DriveBatteryMessage.fromJson(Map json) => + DriveBatteryMessage( + voltage: json['Voltage'] ?? 0, + temperature: json['Temperature'] ?? 50, + current: json['Current'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _voltageSignal: voltage, + _temperatureSignal: temperature, + _currentSignal: current, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Voltage': voltage, + 'Temperature': temperature, + 'Current': current, + }; + + @override + String toString() { + return 'Drive_Battery(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; + } +} + +class DriveSwivelMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Drive_Swivel'; + + @override + int messageLength = 6; + + @override + int canId = 0x18; + + /// Whether or not "Drive_Swivel" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_Swivel" + static const String multiplexor = ''; + + /// Value of signal "Front_Swivel" + num frontSwivel; + + /// Value of signal "Front_Tilt" + num frontTilt; + + /// Value of signal "Rear_Swivel" + num rearSwivel; + + /// Value of signal "Rear_Tilt" + num rearTilt; + + final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( + name: 'Front_Swivel', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, - length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0], - factor: 1, + length: 12, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + factor: 0.044, offset: 0, - min: 0, - max: 1, - unit: '', + min: -90, + max: 90, + unit: '°', ); - final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( - name: 'Front_Left_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( + name: 'Front_Tilt', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 1, - length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [1], - factor: 1, + start: 12, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], + factor: 0.044, offset: 0, - min: 0, - max: 1, - unit: '', + min: -90, + max: 90, + unit: '°', ); - final $_dbc.DBCSignal _updateFrontRightMotorSignal = $_dbc.DBCSignal( - name: 'Update_Front_Right_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 2, - length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [2], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( + name: 'Rear_Swivel', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 24, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], + factor: 0.044, + offset: 0, + min: -90, + max: 90, + unit: '°', + ); + + final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( + name: 'Rear_Tilt', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 36, + length: 12, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], + mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], + factor: 0.044, + offset: 0, + min: -90, + max: 90, + unit: '°', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _frontSwivelSignal, + _frontTiltSignal, + _rearSwivelSignal, + _rearTiltSignal, + ]; + + DriveSwivelMessage({ + this.frontSwivel = 0, + this.frontTilt = 0, + this.rearSwivel = 0, + this.rearTilt = 0, + }); + + /// Creates a clone of this [DriveSwivelMessage] with the non-null values replaced + DriveSwivelMessage copyWith({ + num? frontSwivel, + num? frontTilt, + num? rearSwivel, + num? rearTilt, + }) => DriveSwivelMessage( + frontSwivel: frontSwivel ?? this.frontSwivel, + frontTilt: frontTilt ?? this.frontTilt, + rearSwivel: rearSwivel ?? this.rearSwivel, + rearTilt: rearTilt ?? this.rearTilt, + ); + + factory DriveSwivelMessage.decode(List payload) { + final message = DriveSwivelMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + + message.frontSwivel = + message._frontSwivelSignal.decode(bitField) ?? + $_math.max(0, message._frontSwivelSignal.min); + message.frontTilt = + message._frontTiltSignal.decode(bitField) ?? + $_math.max(0, message._frontTiltSignal.min); + message.rearSwivel = + message._rearSwivelSignal.decode(bitField) ?? + $_math.max(0, message._rearSwivelSignal.min); + message.rearTilt = + message._rearTiltSignal.decode(bitField) ?? + $_math.max(0, message._rearTiltSignal.min); + + return message; + } + + factory DriveSwivelMessage.fromJson(Map json) => + DriveSwivelMessage( + frontSwivel: json['Front_Swivel'] ?? 0, + frontTilt: json['Front_Tilt'] ?? 0, + rearSwivel: json['Rear_Swivel'] ?? 0, + rearTilt: json['Rear_Tilt'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _frontSwivelSignal: frontSwivel, + _frontTiltSignal: frontTilt, + _rearSwivelSignal: rearSwivel, + _rearTiltSignal: rearTilt, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Front_Swivel': frontSwivel, + 'Front_Tilt': frontTilt, + 'Rear_Swivel': rearSwivel, + 'Rear_Tilt': rearTilt, + }; + + @override + String toString() { + return 'Drive_Swivel(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; + } +} + +class DriveMotorDataMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Drive_Motor_Data'; + + @override + int messageLength = 8; + + @override + int canId = 0x19; + + /// Whether or not "Drive_Motor_Data" is multiplex + static const bool isMultiplex = false; - final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( - name: 'Front_Right_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 3, - length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [3], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + /// The multiplexor for "Drive_Motor_Data" + static const String multiplexor = ''; - final $_dbc.DBCSignal _updateBackLeftMotorSignal = $_dbc.DBCSignal( - name: 'Update_Back_Left_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 4, - length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [4], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + /// Value of signal "Motor_Value" + num motorValue; - final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( - name: 'Back_Left_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 5, - length: 1, - mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [5], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + /// Value of signal "Motor_Position" + num motorPosition; - final $_dbc.DBCSignal _updateBackRightMotorSignal = $_dbc.DBCSignal( - name: 'Update_Back_Right_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 6, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [6], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + /// Value of signal "Motor_Speed" + num motorSpeed; - final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( - name: 'Back_Right_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 7, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [7], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + /// Value of signal "Motor_Current" + num motorCurrent; - final $_dbc.DBCSignal _updateArmSignal = $_dbc.DBCSignal( - name: 'Update_Arm', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 8, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [8], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); + /// Value of signal "Motor_Temperature" + num motorTemperature; - final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( - name: 'Arm', + final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( + name: 'Motor_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 9, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], - mappingIndexes: [9], + start: 0, + length: 3, + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2], factor: 1, offset: 0, min: 0, - max: 1, + max: 6, unit: '', ); - final $_dbc.DBCSignal _updateScienceSignal = $_dbc.DBCSignal( - name: 'Update_Science', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + final $_dbc.DBCSignal _motorPositionSignal = $_dbc.DBCSignal( + name: 'Motor_Position', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 10, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], - mappingIndexes: [10], - factor: 1, + start: 3, + length: 16, + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], + factor: 0.1, offset: 0, - min: 0, - max: 1, - unit: '', + min: -3200, + max: 3200, + unit: '°', ); - final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( - name: 'Science', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + final $_dbc.DBCSignal _motorSpeedSignal = $_dbc.DBCSignal( + name: 'Motor_Speed', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 11, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], - mappingIndexes: [11], - factor: 1, + start: 19, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], + factor: 10, offset: 0, - min: 0, - max: 1, - unit: '', + min: -320000, + max: 320000, + unit: 'RPM', ); - final $_dbc.DBCSignal _updateDriveSignal = $_dbc.DBCSignal( - name: 'Update_Drive', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + final $_dbc.DBCSignal _motorCurrentSignal = $_dbc.DBCSignal( + name: 'Motor_Current', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 12, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], - mappingIndexes: [12], - factor: 1, + start: 35, + length: 16, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], + factor: 0.01, offset: 0, - min: 0, - max: 1, - unit: '', + min: -60, + max: 60, + unit: 'A', ); - final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( - name: 'Drive', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + final $_dbc.DBCSignal _motorTemperatureSignal = $_dbc.DBCSignal( + name: 'Motor_Temperature', + signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 13, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], - mappingIndexes: [13], + start: 51, + length: 8, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0], + mappingIndexes: [51, 52, 53, 54, 55, 56, 57, 58], factor: 1, offset: 0, - min: 0, - max: 1, - unit: '', + min: -20, + max: 127, + unit: '°C', ); - - @override - List<$_dbc.DBCSignal> get signals => [ - _updateFrontLeftMotorSignal, - _frontLeftMotorSignal, - _updateFrontRightMotorSignal, - _frontRightMotorSignal, - _updateBackLeftMotorSignal, - _backLeftMotorSignal, - _updateBackRightMotorSignal, - _backRightMotorSignal, - _updateArmSignal, - _armSignal, - _updateScienceSignal, - _scienceSignal, - _updateDriveSignal, - _driveSignal, - ]; - - RelaySetStateMessage({ - this.updateFrontLeftMotor = 0, - this.frontLeftMotor = 0, - this.updateFrontRightMotor = 0, - this.frontRightMotor = 0, - this.updateBackLeftMotor = 0, - this.backLeftMotor = 0, - this.updateBackRightMotor = 0, - this.backRightMotor = 0, - this.updateArm = 0, - this.arm = 0, - this.updateScience = 0, - this.science = 0, - this.updateDrive = 0, - this.drive = 0, - }); - - /// Creates a clone of this [RelaySetStateMessage] with the non-null values replaced - RelaySetStateMessage copyWith({ - num? updateFrontLeftMotor, - num? frontLeftMotor, - num? updateFrontRightMotor, - num? frontRightMotor, - num? updateBackLeftMotor, - num? backLeftMotor, - num? updateBackRightMotor, - num? backRightMotor, - num? updateArm, - num? arm, - num? updateScience, - num? science, - num? updateDrive, - num? drive, - }) => RelaySetStateMessage( - updateFrontLeftMotor: updateFrontLeftMotor ?? this.updateFrontLeftMotor, - frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, - updateFrontRightMotor: updateFrontRightMotor ?? this.updateFrontRightMotor, - frontRightMotor: frontRightMotor ?? this.frontRightMotor, - updateBackLeftMotor: updateBackLeftMotor ?? this.updateBackLeftMotor, - backLeftMotor: backLeftMotor ?? this.backLeftMotor, - updateBackRightMotor: updateBackRightMotor ?? this.updateBackRightMotor, - backRightMotor: backRightMotor ?? this.backRightMotor, - updateArm: updateArm ?? this.updateArm, - arm: arm ?? this.arm, - updateScience: updateScience ?? this.updateScience, - science: science ?? this.science, - updateDrive: updateDrive ?? this.updateDrive, - drive: drive ?? this.drive, + + @override + List<$_dbc.DBCSignal> get signals => [ + _motorValueSignal, + _motorPositionSignal, + _motorSpeedSignal, + _motorCurrentSignal, + _motorTemperatureSignal, + ]; + + DriveMotorDataMessage({ + this.motorValue = 0, + this.motorPosition = 0, + this.motorSpeed = 0, + this.motorCurrent = 0, + this.motorTemperature = 0, + }); + + /// Creates a clone of this [DriveMotorDataMessage] with the non-null values replaced + DriveMotorDataMessage copyWith({ + num? motorValue, + num? motorPosition, + num? motorSpeed, + num? motorCurrent, + num? motorTemperature, + }) => DriveMotorDataMessage( + motorValue: motorValue ?? this.motorValue, + motorPosition: motorPosition ?? this.motorPosition, + motorSpeed: motorSpeed ?? this.motorSpeed, + motorCurrent: motorCurrent ?? this.motorCurrent, + motorTemperature: motorTemperature ?? this.motorTemperature, ); - factory RelaySetStateMessage.decode(List payload) { - final message = RelaySetStateMessage(); + factory DriveMotorDataMessage.decode(List payload) { + final message = DriveMotorDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.updateFrontLeftMotor = - message._updateFrontLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateFrontLeftMotorSignal.min); - message.frontLeftMotor = - message._frontLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._frontLeftMotorSignal.min); - message.updateFrontRightMotor = - message._updateFrontRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateFrontRightMotorSignal.min); - message.frontRightMotor = - message._frontRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._frontRightMotorSignal.min); - message.updateBackLeftMotor = - message._updateBackLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateBackLeftMotorSignal.min); - message.backLeftMotor = - message._backLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._backLeftMotorSignal.min); - message.updateBackRightMotor = - message._updateBackRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateBackRightMotorSignal.min); - message.backRightMotor = - message._backRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._backRightMotorSignal.min); - message.updateArm = - message._updateArmSignal.decode(bitField) ?? - $_math.max(0, message._updateArmSignal.min); - message.arm = - message._armSignal.decode(bitField) ?? - $_math.max(0, message._armSignal.min); - message.updateScience = - message._updateScienceSignal.decode(bitField) ?? - $_math.max(0, message._updateScienceSignal.min); - message.science = - message._scienceSignal.decode(bitField) ?? - $_math.max(0, message._scienceSignal.min); - message.updateDrive = - message._updateDriveSignal.decode(bitField) ?? - $_math.max(0, message._updateDriveSignal.min); - message.drive = - message._driveSignal.decode(bitField) ?? - $_math.max(0, message._driveSignal.min); + message.motorValue = + message._motorValueSignal.decode(bitField) ?? + $_math.max(0, message._motorValueSignal.min); + message.motorPosition = + message._motorPositionSignal.decode(bitField) ?? + $_math.max(0, message._motorPositionSignal.min); + message.motorSpeed = + message._motorSpeedSignal.decode(bitField) ?? + $_math.max(0, message._motorSpeedSignal.min); + message.motorCurrent = + message._motorCurrentSignal.decode(bitField) ?? + $_math.max(0, message._motorCurrentSignal.min); + message.motorTemperature = + message._motorTemperatureSignal.decode(bitField) ?? + $_math.max(0, message._motorTemperatureSignal.min); return message; } - factory RelaySetStateMessage.fromJson(Map json) => - RelaySetStateMessage( - updateFrontLeftMotor: json['Update_Front_Left_Motor'] ?? 0, - frontLeftMotor: json['Front_Left_Motor'] ?? 0, - updateFrontRightMotor: json['Update_Front_Right_Motor'] ?? 0, - frontRightMotor: json['Front_Right_Motor'] ?? 0, - updateBackLeftMotor: json['Update_Back_Left_Motor'] ?? 0, - backLeftMotor: json['Back_Left_Motor'] ?? 0, - updateBackRightMotor: json['Update_Back_Right_Motor'] ?? 0, - backRightMotor: json['Back_Right_Motor'] ?? 0, - updateArm: json['Update_Arm'] ?? 0, - arm: json['Arm'] ?? 0, - updateScience: json['Update_Science'] ?? 0, - science: json['Science'] ?? 0, - updateDrive: json['Update_Drive'] ?? 0, - drive: json['Drive'] ?? 0, + factory DriveMotorDataMessage.fromJson(Map json) => + DriveMotorDataMessage( + motorValue: json['Motor_Value'] ?? 0, + motorPosition: json['Motor_Position'] ?? 0, + motorSpeed: json['Motor_Speed'] ?? 0, + motorCurrent: json['Motor_Current'] ?? 0, + motorTemperature: json['Motor_Temperature'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _updateFrontLeftMotorSignal: updateFrontLeftMotor, - _frontLeftMotorSignal: frontLeftMotor, - _updateFrontRightMotorSignal: updateFrontRightMotor, - _frontRightMotorSignal: frontRightMotor, - _updateBackLeftMotorSignal: updateBackLeftMotor, - _backLeftMotorSignal: backLeftMotor, - _updateBackRightMotorSignal: updateBackRightMotor, - _backRightMotorSignal: backRightMotor, - _updateArmSignal: updateArm, - _armSignal: arm, - _updateScienceSignal: updateScience, - _scienceSignal: science, - _updateDriveSignal: updateDrive, - _driveSignal: drive, + _motorValueSignal: motorValue, + _motorPositionSignal: motorPosition, + _motorSpeedSignal: motorSpeed, + _motorCurrentSignal: motorCurrent, + _motorTemperatureSignal: motorTemperature, }; return encodeWithValues(values); @@ -1660,77 +1698,86 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Update_Front_Left_Motor': updateFrontLeftMotor, - 'Front_Left_Motor': frontLeftMotor, - 'Update_Front_Right_Motor': updateFrontRightMotor, - 'Front_Right_Motor': frontRightMotor, - 'Update_Back_Left_Motor': updateBackLeftMotor, - 'Back_Left_Motor': backLeftMotor, - 'Update_Back_Right_Motor': updateBackRightMotor, - 'Back_Right_Motor': backRightMotor, - 'Update_Arm': updateArm, - 'Arm': arm, - 'Update_Science': updateScience, - 'Science': science, - 'Update_Drive': updateDrive, - 'Drive': drive, + 'Motor_Value': motorValue, + 'Motor_Position': motorPosition, + 'Motor_Speed': motorSpeed, + 'Motor_Current': motorCurrent, + 'Motor_Temperature': motorTemperature, }; @override String toString() { - return 'Relay_Set_State(\n Update_Front_Left_Motor=$updateFrontLeftMotor\n Front_Left_Motor=$frontLeftMotor\n Update_Front_Right_Motor=$updateFrontRightMotor\n Front_Right_Motor=$frontRightMotor\n Update_Back_Left_Motor=$updateBackLeftMotor\n Back_Left_Motor=$backLeftMotor\n Update_Back_Right_Motor=$updateBackRightMotor\n Back_Right_Motor=$backRightMotor\n Update_Arm=$updateArm\n Arm=$arm\n Update_Science=$updateScience\n Science=$science\n Update_Drive=$updateDrive\n Drive=$drive\n)'; + return 'Drive_Motor_Data(\n Motor_Value=$motorValue\n Motor_Position=$motorPosition\n Motor_Speed=$motorSpeed\n Motor_Current=$motorCurrent\n Motor_Temperature=$motorTemperature\n)'; } } -class RelayStateMessage extends $_dbc.DBCMessage { +class RelaySetStateMessage extends $_dbc.DBCMessage { @override - String messageName = 'Relay_State'; + String messageName = 'Relay_Set_State'; @override - int messageLength = 1; + int messageLength = 2; @override - int canId = 0x25; + int canId = 0x20; - /// Whether or not "Relay_State" is multiplex + /// Whether or not "Relay_Set_State" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Relay_State" + /// The multiplexor for "Relay_Set_State" static const String multiplexor = ''; + /// Value of signal "Update_Front_Left_Motor" + num updateFrontLeftMotor; + /// Value of signal "Front_Left_Motor" num frontLeftMotor; + /// Value of signal "Update_Front_Right_Motor" + num updateFrontRightMotor; + /// Value of signal "Front_Right_Motor" num frontRightMotor; + /// Value of signal "Update_Back_Left_Motor" + num updateBackLeftMotor; + /// Value of signal "Back_Left_Motor" num backLeftMotor; + /// Value of signal "Update_Back_Right_Motor" + num updateBackRightMotor; + /// Value of signal "Back_Right_Motor" num backRightMotor; - /// Value of signal "Drive" - num drive; + /// Value of signal "Update_Arm" + num updateArm; /// Value of signal "Arm" num arm; + /// Value of signal "Update_Science" + num updateScience; + /// Value of signal "Science" num science; - /// Value of signal "Physical_Override" - num physicalOverride; + /// Value of signal "Update_Drive" + num updateDrive; - final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( - name: 'Front_Left_Motor', + /// Value of signal "Drive" + num drive; + + final $_dbc.DBCSignal _updateFrontLeftMotorSignal = $_dbc.DBCSignal( + name: 'Update_Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], factor: 1, offset: 0, @@ -1739,15 +1786,15 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( - name: 'Front_Right_Motor', + final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( + name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 1, length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0], + mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], factor: 1, offset: 0, @@ -1756,16 +1803,118 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); + final $_dbc.DBCSignal _updateFrontRightMotorSignal = $_dbc.DBCSignal( + name: 'Update_Front_Right_Motor', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 2, + length: 1, + mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( + name: 'Front_Right_Motor', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 3, + length: 1, + mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _updateBackLeftMotorSignal = $_dbc.DBCSignal( + name: 'Update_Back_Left_Motor', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( name: 'Back_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 2, + start: 5, + length: 1, + mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [5], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _updateBackRightMotorSignal = $_dbc.DBCSignal( + name: 'Update_Back_Right_Motor', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 6, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [6], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( + name: 'Back_Right_Motor', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 7, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [7], + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _updateArmSignal = $_dbc.DBCSignal( + name: 'Update_Arm', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 8, length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0], - mappingIndexes: [2], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [8], factor: 1, offset: 0, min: 0, @@ -1773,16 +1922,16 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( - name: 'Back_Right_Motor', + final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( + name: 'Arm', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 3, + start: 9, length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0], - mappingIndexes: [3], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], + mappingIndexes: [9], factor: 1, offset: 0, min: 0, @@ -1790,16 +1939,16 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( - name: 'Drive', + final $_dbc.DBCSignal _updateScienceSignal = $_dbc.DBCSignal( + name: 'Update_Science', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 4, + start: 10, length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0], - mappingIndexes: [4], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], + mappingIndexes: [10], factor: 1, offset: 0, min: 0, @@ -1807,16 +1956,16 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( - name: 'Arm', + final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( + name: 'Science', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 5, + start: 11, length: 1, - mapping: [0, 0, 0, 0, 0, 1, 0, 0], - mappingIndexes: [5], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], + mappingIndexes: [11], factor: 1, offset: 0, min: 0, @@ -1824,16 +1973,16 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( - name: 'Science', + final $_dbc.DBCSignal _updateDriveSignal = $_dbc.DBCSignal( + name: 'Update_Drive', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 6, + start: 12, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 1, 0], - mappingIndexes: [6], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], + mappingIndexes: [12], factor: 1, offset: 0, min: 0, @@ -1841,16 +1990,16 @@ class RelayStateMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _physicalOverrideSignal = $_dbc.DBCSignal( - name: 'Physical_Override', + final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( + name: 'Drive', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 7, + start: 13, length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 1], - mappingIndexes: [7], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], + mappingIndexes: [13], factor: 1, offset: 0, min: 0, @@ -1860,104 +2009,158 @@ class RelayStateMessage extends $_dbc.DBCMessage { @override List<$_dbc.DBCSignal> get signals => [ + _updateFrontLeftMotorSignal, _frontLeftMotorSignal, + _updateFrontRightMotorSignal, _frontRightMotorSignal, + _updateBackLeftMotorSignal, _backLeftMotorSignal, + _updateBackRightMotorSignal, _backRightMotorSignal, - _driveSignal, + _updateArmSignal, _armSignal, + _updateScienceSignal, _scienceSignal, - _physicalOverrideSignal, + _updateDriveSignal, + _driveSignal, ]; - RelayStateMessage({ + RelaySetStateMessage({ + this.updateFrontLeftMotor = 0, this.frontLeftMotor = 0, + this.updateFrontRightMotor = 0, this.frontRightMotor = 0, + this.updateBackLeftMotor = 0, this.backLeftMotor = 0, + this.updateBackRightMotor = 0, this.backRightMotor = 0, - this.drive = 0, + this.updateArm = 0, this.arm = 0, + this.updateScience = 0, this.science = 0, - this.physicalOverride = 0, + this.updateDrive = 0, + this.drive = 0, }); - /// Creates a clone of this [RelayStateMessage] with the non-null values replaced - RelayStateMessage copyWith({ + /// Creates a clone of this [RelaySetStateMessage] with the non-null values replaced + RelaySetStateMessage copyWith({ + num? updateFrontLeftMotor, num? frontLeftMotor, + num? updateFrontRightMotor, num? frontRightMotor, + num? updateBackLeftMotor, num? backLeftMotor, + num? updateBackRightMotor, num? backRightMotor, - num? drive, + num? updateArm, num? arm, + num? updateScience, num? science, - num? physicalOverride, - }) => RelayStateMessage( + num? updateDrive, + num? drive, + }) => RelaySetStateMessage( + updateFrontLeftMotor: updateFrontLeftMotor ?? this.updateFrontLeftMotor, frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, + updateFrontRightMotor: updateFrontRightMotor ?? this.updateFrontRightMotor, frontRightMotor: frontRightMotor ?? this.frontRightMotor, + updateBackLeftMotor: updateBackLeftMotor ?? this.updateBackLeftMotor, backLeftMotor: backLeftMotor ?? this.backLeftMotor, + updateBackRightMotor: updateBackRightMotor ?? this.updateBackRightMotor, backRightMotor: backRightMotor ?? this.backRightMotor, - drive: drive ?? this.drive, + updateArm: updateArm ?? this.updateArm, arm: arm ?? this.arm, + updateScience: updateScience ?? this.updateScience, science: science ?? this.science, - physicalOverride: physicalOverride ?? this.physicalOverride, + updateDrive: updateDrive ?? this.updateDrive, + drive: drive ?? this.drive, ); - factory RelayStateMessage.decode(List payload) { - final message = RelayStateMessage(); + factory RelaySetStateMessage.decode(List payload) { + final message = RelaySetStateMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + message.updateFrontLeftMotor = + message._updateFrontLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateFrontLeftMotorSignal.min); message.frontLeftMotor = message._frontLeftMotorSignal.decode(bitField) ?? $_math.max(0, message._frontLeftMotorSignal.min); + message.updateFrontRightMotor = + message._updateFrontRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateFrontRightMotorSignal.min); message.frontRightMotor = message._frontRightMotorSignal.decode(bitField) ?? $_math.max(0, message._frontRightMotorSignal.min); + message.updateBackLeftMotor = + message._updateBackLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateBackLeftMotorSignal.min); message.backLeftMotor = message._backLeftMotorSignal.decode(bitField) ?? $_math.max(0, message._backLeftMotorSignal.min); + message.updateBackRightMotor = + message._updateBackRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._updateBackRightMotorSignal.min); message.backRightMotor = message._backRightMotorSignal.decode(bitField) ?? $_math.max(0, message._backRightMotorSignal.min); - message.drive = - message._driveSignal.decode(bitField) ?? - $_math.max(0, message._driveSignal.min); + message.updateArm = + message._updateArmSignal.decode(bitField) ?? + $_math.max(0, message._updateArmSignal.min); message.arm = message._armSignal.decode(bitField) ?? $_math.max(0, message._armSignal.min); + message.updateScience = + message._updateScienceSignal.decode(bitField) ?? + $_math.max(0, message._updateScienceSignal.min); message.science = message._scienceSignal.decode(bitField) ?? $_math.max(0, message._scienceSignal.min); - message.physicalOverride = - message._physicalOverrideSignal.decode(bitField) ?? - $_math.max(0, message._physicalOverrideSignal.min); + message.updateDrive = + message._updateDriveSignal.decode(bitField) ?? + $_math.max(0, message._updateDriveSignal.min); + message.drive = + message._driveSignal.decode(bitField) ?? + $_math.max(0, message._driveSignal.min); return message; } - factory RelayStateMessage.fromJson(Map json) => - RelayStateMessage( + factory RelaySetStateMessage.fromJson(Map json) => + RelaySetStateMessage( + updateFrontLeftMotor: json['Update_Front_Left_Motor'] ?? 0, frontLeftMotor: json['Front_Left_Motor'] ?? 0, + updateFrontRightMotor: json['Update_Front_Right_Motor'] ?? 0, frontRightMotor: json['Front_Right_Motor'] ?? 0, + updateBackLeftMotor: json['Update_Back_Left_Motor'] ?? 0, backLeftMotor: json['Back_Left_Motor'] ?? 0, + updateBackRightMotor: json['Update_Back_Right_Motor'] ?? 0, backRightMotor: json['Back_Right_Motor'] ?? 0, - drive: json['Drive'] ?? 0, + updateArm: json['Update_Arm'] ?? 0, arm: json['Arm'] ?? 0, + updateScience: json['Update_Science'] ?? 0, science: json['Science'] ?? 0, - physicalOverride: json['Physical_Override'] ?? 0, + updateDrive: json['Update_Drive'] ?? 0, + drive: json['Drive'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { + _updateFrontLeftMotorSignal: updateFrontLeftMotor, _frontLeftMotorSignal: frontLeftMotor, + _updateFrontRightMotorSignal: updateFrontRightMotor, _frontRightMotorSignal: frontRightMotor, + _updateBackLeftMotorSignal: updateBackLeftMotor, _backLeftMotorSignal: backLeftMotor, + _updateBackRightMotorSignal: updateBackRightMotor, _backRightMotorSignal: backRightMotor, - _driveSignal: drive, + _updateArmSignal: updateArm, _armSignal: arm, + _updateScienceSignal: updateScience, _scienceSignal: science, - _physicalOverrideSignal: physicalOverride, + _updateDriveSignal: updateDrive, + _driveSignal: drive, }; return encodeWithValues(values); @@ -1965,71 +2168,77 @@ class RelayStateMessage extends $_dbc.DBCMessage { @override Map toJson() => { + 'Update_Front_Left_Motor': updateFrontLeftMotor, 'Front_Left_Motor': frontLeftMotor, + 'Update_Front_Right_Motor': updateFrontRightMotor, 'Front_Right_Motor': frontRightMotor, + 'Update_Back_Left_Motor': updateBackLeftMotor, 'Back_Left_Motor': backLeftMotor, + 'Update_Back_Right_Motor': updateBackRightMotor, 'Back_Right_Motor': backRightMotor, - 'Drive': drive, + 'Update_Arm': updateArm, 'Arm': arm, + 'Update_Science': updateScience, 'Science': science, - 'Physical_Override': physicalOverride, + 'Update_Drive': updateDrive, + 'Drive': drive, }; @override String toString() { - return 'Relay_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; + return 'Relay_Set_State(\n Update_Front_Left_Motor=$updateFrontLeftMotor\n Front_Left_Motor=$frontLeftMotor\n Update_Front_Right_Motor=$updateFrontRightMotor\n Front_Right_Motor=$frontRightMotor\n Update_Back_Left_Motor=$updateBackLeftMotor\n Back_Left_Motor=$backLeftMotor\n Update_Back_Right_Motor=$updateBackRightMotor\n Back_Right_Motor=$backRightMotor\n Update_Arm=$updateArm\n Arm=$arm\n Update_Science=$updateScience\n Science=$science\n Update_Drive=$updateDrive\n Drive=$drive\n)'; } } -class DriveSetSwivelMessage extends $_dbc.DBCMessage { +class RelayStateMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_SetSwivel'; + String messageName = 'Relay_State'; @override - int messageLength = 7; + int messageLength = 1; @override - int canId = 0x12; + int canId = 0x25; - /// Whether or not "Drive_SetSwivel" is multiplex + /// Whether or not "Relay_State" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_SetSwivel" + /// The multiplexor for "Relay_State" static const String multiplexor = ''; - /// Value of signal "Set_Front_Swivel" - num setFrontSwivel; + /// Value of signal "Front_Left_Motor" + num frontLeftMotor; - /// Value of signal "Set_Front_Tilt" - num setFrontTilt; + /// Value of signal "Front_Right_Motor" + num frontRightMotor; - /// Value of signal "Set_Rear_Swivel" - num setRearSwivel; + /// Value of signal "Back_Left_Motor" + num backLeftMotor; - /// Value of signal "Set_Rear_Tilt" - num setRearTilt; + /// Value of signal "Back_Right_Motor" + num backRightMotor; - /// Value of signal "Front_Swivel" - num frontSwivel; + /// Value of signal "Drive" + num drive; - /// Value of signal "Front_Tilt" - num frontTilt; + /// Value of signal "Arm" + num arm; - /// Value of signal "Rear_Swivel" - num rearSwivel; + /// Value of signal "Science" + num science; - /// Value of signal "Rear_Tilt" - num rearTilt; + /// Value of signal "Physical_Override" + num physicalOverride; - final $_dbc.DBCSignal _setFrontSwivelSignal = $_dbc.DBCSignal( - name: 'Set_Front_Swivel', + final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( + name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], factor: 1, offset: 0, @@ -2038,15 +2247,15 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _setFrontTiltSignal = $_dbc.DBCSignal( - name: 'Set_Front_Tilt', + final $_dbc.DBCSignal _frontRightMotorSignal = $_dbc.DBCSignal( + name: 'Front_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 1, length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 1, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], factor: 1, offset: 0, @@ -2055,15 +2264,15 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _setRearSwivelSignal = $_dbc.DBCSignal( - name: 'Set_Rear_Swivel', + final $_dbc.DBCSignal _backLeftMotorSignal = $_dbc.DBCSignal( + name: 'Back_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 2, length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 1, 0, 0, 0, 0, 0], mappingIndexes: [2], factor: 1, offset: 0, @@ -2072,15 +2281,15 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _setRearTiltSignal = $_dbc.DBCSignal( - name: 'Set_Rear_Tilt', + final $_dbc.DBCSignal _backRightMotorSignal = $_dbc.DBCSignal( + name: 'Back_Right_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 1, 0, 0, 0, 0], mappingIndexes: [3], factor: 1, offset: 0, @@ -2089,174 +2298,174 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( - name: 'Front_Swivel', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + final $_dbc.DBCSignal _driveSignal = $_dbc.DBCSignal( + name: 'Drive', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 4, - length: 12, - mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.044, + multiplexGroup: -1, + start: 4, + length: 1, + mapping: [0, 0, 0, 0, 1, 0, 0, 0], + mappingIndexes: [4], + factor: 1, offset: 0, - min: -90, - max: 90, - unit: '°', + min: 0, + max: 1, + unit: '', ); - final $_dbc.DBCSignal _frontTiltSignal = $_dbc.DBCSignal( - name: 'Front_Tilt', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + final $_dbc.DBCSignal _armSignal = $_dbc.DBCSignal( + name: 'Arm', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 16, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], - factor: 0.044, + start: 5, + length: 1, + mapping: [0, 0, 0, 0, 0, 1, 0, 0], + mappingIndexes: [5], + factor: 1, offset: 0, - min: -90, - max: 90, - unit: '°', + min: 0, + max: 1, + unit: '', ); - final $_dbc.DBCSignal _rearSwivelSignal = $_dbc.DBCSignal( - name: 'Rear_Swivel', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + final $_dbc.DBCSignal _scienceSignal = $_dbc.DBCSignal( + name: 'Science', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 28, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], - factor: 0.044, + start: 6, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 1, 0], + mappingIndexes: [6], + factor: 1, offset: 0, - min: -90, - max: 90, - unit: '°', + min: 0, + max: 1, + unit: '', ); - final $_dbc.DBCSignal _rearTiltSignal = $_dbc.DBCSignal( - name: 'Rear_Tilt', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, + final $_dbc.DBCSignal _physicalOverrideSignal = $_dbc.DBCSignal( + name: 'Physical_Override', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 40, - length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0], - mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], - factor: 0.044, + start: 7, + length: 1, + mapping: [0, 0, 0, 0, 0, 0, 0, 1], + mappingIndexes: [7], + factor: 1, offset: 0, - min: -90, - max: 90, - unit: '°', + min: 0, + max: 1, + unit: '', ); @override List<$_dbc.DBCSignal> get signals => [ - _setFrontSwivelSignal, - _setFrontTiltSignal, - _setRearSwivelSignal, - _setRearTiltSignal, - _frontSwivelSignal, - _frontTiltSignal, - _rearSwivelSignal, - _rearTiltSignal, + _frontLeftMotorSignal, + _frontRightMotorSignal, + _backLeftMotorSignal, + _backRightMotorSignal, + _driveSignal, + _armSignal, + _scienceSignal, + _physicalOverrideSignal, ]; - DriveSetSwivelMessage({ - this.setFrontSwivel = 0, - this.setFrontTilt = 0, - this.setRearSwivel = 0, - this.setRearTilt = 0, - this.frontSwivel = 0, - this.frontTilt = 0, - this.rearSwivel = 0, - this.rearTilt = 0, + RelayStateMessage({ + this.frontLeftMotor = 0, + this.frontRightMotor = 0, + this.backLeftMotor = 0, + this.backRightMotor = 0, + this.drive = 0, + this.arm = 0, + this.science = 0, + this.physicalOverride = 0, }); - /// Creates a clone of this [DriveSetSwivelMessage] with the non-null values replaced - DriveSetSwivelMessage copyWith({ - num? setFrontSwivel, - num? setFrontTilt, - num? setRearSwivel, - num? setRearTilt, - num? frontSwivel, - num? frontTilt, - num? rearSwivel, - num? rearTilt, - }) => DriveSetSwivelMessage( - setFrontSwivel: setFrontSwivel ?? this.setFrontSwivel, - setFrontTilt: setFrontTilt ?? this.setFrontTilt, - setRearSwivel: setRearSwivel ?? this.setRearSwivel, - setRearTilt: setRearTilt ?? this.setRearTilt, - frontSwivel: frontSwivel ?? this.frontSwivel, - frontTilt: frontTilt ?? this.frontTilt, - rearSwivel: rearSwivel ?? this.rearSwivel, - rearTilt: rearTilt ?? this.rearTilt, + /// Creates a clone of this [RelayStateMessage] with the non-null values replaced + RelayStateMessage copyWith({ + num? frontLeftMotor, + num? frontRightMotor, + num? backLeftMotor, + num? backRightMotor, + num? drive, + num? arm, + num? science, + num? physicalOverride, + }) => RelayStateMessage( + frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, + frontRightMotor: frontRightMotor ?? this.frontRightMotor, + backLeftMotor: backLeftMotor ?? this.backLeftMotor, + backRightMotor: backRightMotor ?? this.backRightMotor, + drive: drive ?? this.drive, + arm: arm ?? this.arm, + science: science ?? this.science, + physicalOverride: physicalOverride ?? this.physicalOverride, ); - factory DriveSetSwivelMessage.decode(List payload) { - final message = DriveSetSwivelMessage(); + factory RelayStateMessage.decode(List payload) { + final message = RelayStateMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.setFrontSwivel = - message._setFrontSwivelSignal.decode(bitField) ?? - $_math.max(0, message._setFrontSwivelSignal.min); - message.setFrontTilt = - message._setFrontTiltSignal.decode(bitField) ?? - $_math.max(0, message._setFrontTiltSignal.min); - message.setRearSwivel = - message._setRearSwivelSignal.decode(bitField) ?? - $_math.max(0, message._setRearSwivelSignal.min); - message.setRearTilt = - message._setRearTiltSignal.decode(bitField) ?? - $_math.max(0, message._setRearTiltSignal.min); - message.frontSwivel = - message._frontSwivelSignal.decode(bitField) ?? - $_math.max(0, message._frontSwivelSignal.min); - message.frontTilt = - message._frontTiltSignal.decode(bitField) ?? - $_math.max(0, message._frontTiltSignal.min); - message.rearSwivel = - message._rearSwivelSignal.decode(bitField) ?? - $_math.max(0, message._rearSwivelSignal.min); - message.rearTilt = - message._rearTiltSignal.decode(bitField) ?? - $_math.max(0, message._rearTiltSignal.min); + message.frontLeftMotor = + message._frontLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._frontLeftMotorSignal.min); + message.frontRightMotor = + message._frontRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._frontRightMotorSignal.min); + message.backLeftMotor = + message._backLeftMotorSignal.decode(bitField) ?? + $_math.max(0, message._backLeftMotorSignal.min); + message.backRightMotor = + message._backRightMotorSignal.decode(bitField) ?? + $_math.max(0, message._backRightMotorSignal.min); + message.drive = + message._driveSignal.decode(bitField) ?? + $_math.max(0, message._driveSignal.min); + message.arm = + message._armSignal.decode(bitField) ?? + $_math.max(0, message._armSignal.min); + message.science = + message._scienceSignal.decode(bitField) ?? + $_math.max(0, message._scienceSignal.min); + message.physicalOverride = + message._physicalOverrideSignal.decode(bitField) ?? + $_math.max(0, message._physicalOverrideSignal.min); return message; } - factory DriveSetSwivelMessage.fromJson(Map json) => - DriveSetSwivelMessage( - setFrontSwivel: json['Set_Front_Swivel'] ?? 0, - setFrontTilt: json['Set_Front_Tilt'] ?? 0, - setRearSwivel: json['Set_Rear_Swivel'] ?? 0, - setRearTilt: json['Set_Rear_Tilt'] ?? 0, - frontSwivel: json['Front_Swivel'] ?? 0, - frontTilt: json['Front_Tilt'] ?? 0, - rearSwivel: json['Rear_Swivel'] ?? 0, - rearTilt: json['Rear_Tilt'] ?? 0, + factory RelayStateMessage.fromJson(Map json) => + RelayStateMessage( + frontLeftMotor: json['Front_Left_Motor'] ?? 0, + frontRightMotor: json['Front_Right_Motor'] ?? 0, + backLeftMotor: json['Back_Left_Motor'] ?? 0, + backRightMotor: json['Back_Right_Motor'] ?? 0, + drive: json['Drive'] ?? 0, + arm: json['Arm'] ?? 0, + science: json['Science'] ?? 0, + physicalOverride: json['Physical_Override'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _setFrontSwivelSignal: setFrontSwivel, - _setFrontTiltSignal: setFrontTilt, - _setRearSwivelSignal: setRearSwivel, - _setRearTiltSignal: setRearTilt, - _frontSwivelSignal: frontSwivel, - _frontTiltSignal: frontTilt, - _rearSwivelSignal: rearSwivel, - _rearTiltSignal: rearTilt, + _frontLeftMotorSignal: frontLeftMotor, + _frontRightMotorSignal: frontRightMotor, + _backLeftMotorSignal: backLeftMotor, + _backRightMotorSignal: backRightMotor, + _driveSignal: drive, + _armSignal: arm, + _scienceSignal: science, + _physicalOverrideSignal: physicalOverride, }; return encodeWithValues(values); @@ -2264,19 +2473,19 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Set_Front_Swivel': setFrontSwivel, - 'Set_Front_Tilt': setFrontTilt, - 'Set_Rear_Swivel': setRearSwivel, - 'Set_Rear_Tilt': setRearTilt, - 'Front_Swivel': frontSwivel, - 'Front_Tilt': frontTilt, - 'Rear_Swivel': rearSwivel, - 'Rear_Tilt': rearTilt, + 'Front_Left_Motor': frontLeftMotor, + 'Front_Right_Motor': frontRightMotor, + 'Back_Left_Motor': backLeftMotor, + 'Back_Right_Motor': backRightMotor, + 'Drive': drive, + 'Arm': arm, + 'Science': science, + 'Physical_Override': physicalOverride, }; @override String toString() { - return 'Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; + return 'Relay_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; } } From 10fbb4e4b35edce0f96d052e7c04e29626fd9bf8 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 11 May 2025 19:50:27 -0400 Subject: [PATCH 19/30] Updated to new DBC --- subsystems/lib/src/devices/can_bus.dart | 32 ++-- .../lib/src/generated/rover_messages.dbc.dart | 176 +++++++++--------- 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index d01509f1..e77bb07a 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -61,7 +61,7 @@ extension on DeviceBroadcastMessage { Version(major: fwVersionMajor.toInt(), minor: fwVersionMinor.toInt()); } -extension on DriveAppliedOutputMessage { +extension on DriveAppliedOutputDataMessage { DriveData toDriveProto() => DriveData( throttle: throttle.toDouble(), left: leftSpeed.toDouble(), @@ -72,7 +72,7 @@ extension on DriveAppliedOutputMessage { ); } -extension on DriveBatteryMessage { +extension on DriveBatteryDataMessage { DriveData toDriveProto() => DriveData( batteryVoltage: voltage.toDouble(), batteryTemperature: temperature.toDouble(), @@ -80,12 +80,12 @@ extension on DriveBatteryMessage { ); } -extension on DriveLedMessage { +extension on DriveLedDataMessage { DriveData toDriveProto() => DriveData(color: ProtoColor.valueOf(color.toInt())); } -extension on DriveSwivelMessage { +extension on DriveSwivelDataMessage { DriveData toDriveProto() => DriveData( frontSwivel: frontSwivel.toDouble(), frontTilt: frontTilt.toDouble(), @@ -136,7 +136,7 @@ extension on DriveCommand { } } -extension on RelayStateMessage { +extension on RelayStateDataMessage { RelaysData toRelayProto() => RelaysData( frontLeftMotor: frontLeftMotor.boolState, frontRightMotor: frontRightMotor.boolState, @@ -255,7 +255,7 @@ extension on ArmCommand { moveSteps: elbow.moveSteps, ); - DBCMessage asSystemAction() => ArmSystemActionMessage( + DBCMessage asSystemAction() => ArmSetSystemActionMessage( stop: stop.intValue, calibrate: calibrate.intValue, jab: jab.intValue, @@ -576,25 +576,25 @@ class CanBus extends Service { case CanDataFrame(:final id, :final data): if (id == DeviceBroadcastMessage().canId) { _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); - } else if (id == DriveAppliedOutputMessage().canId) { + } else if (id == DriveAppliedOutputDataMessage().canId) { collection.server.sendMessage( - DriveAppliedOutputMessage.decode(data).toDriveProto(), + DriveAppliedOutputDataMessage.decode(data).toDriveProto(), ); - } else if (id == DriveBatteryMessage().canId) { + } else if (id == DriveBatteryDataMessage().canId) { collection.server.sendMessage( - DriveBatteryMessage.decode(data).toDriveProto(), + DriveBatteryDataMessage.decode(data).toDriveProto(), ); - } else if (id == DriveLedMessage().canId) { + } else if (id == DriveLedDataMessage().canId) { collection.server.sendMessage( - DriveLedMessage.decode(data).toDriveProto(), + DriveLedDataMessage.decode(data).toDriveProto(), ); - } else if (id == DriveSwivelMessage().canId) { + } else if (id == DriveSwivelDataMessage().canId) { collection.server.sendMessage( - DriveSwivelMessage.decode(data).toDriveProto(), + DriveSwivelDataMessage.decode(data).toDriveProto(), ); - } else if (id == RelayStateMessage().canId) { + } else if (id == RelayStateDataMessage().canId) { collection.server.sendMessage( - RelayStateMessage.decode(data).toRelayProto(), + RelayStateDataMessage.decode(data).toRelayProto(), ); } else if (id == ArmMotorMoveDataMessage().canId) { collection.server.sendMessage( diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 8023adf6..ff6ca261 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -19,7 +19,7 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { int messageLength = 1; @override - int canId = 0x0; + int canId = 0x1; /// Whether or not "Rover_Heartbeat" is multiplex static const bool isMultiplex = false; @@ -108,7 +108,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { int messageLength = 2; @override - int canId = 0x1; + int canId = 0x2; /// Whether or not "Device_Broadcast" is multiplex static const bool isMultiplex = false; @@ -490,7 +490,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { class DriveSetLedMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_SetLED'; + String messageName = 'Drive_Set_LED'; @override int messageLength = 1; @@ -498,10 +498,10 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { @override int canId = 0x11; - /// Whether or not "Drive_SetLED" is multiplex + /// Whether or not "Drive_Set_LED" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_SetLED" + /// The multiplexor for "Drive_Set_LED" static const String multiplexor = ''; /// Value of signal "Color" @@ -603,13 +603,13 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Drive_SetLED(\n Color=$color\n Blink=$blink\n)'; + return 'Drive_Set_LED(\n Color=$color\n Blink=$blink\n)'; } } class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_SetSwivel'; + String messageName = 'Drive_Set_Swivel'; @override int messageLength = 7; @@ -617,10 +617,10 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override int canId = 0x12; - /// Whether or not "Drive_SetSwivel" is multiplex + /// Whether or not "Drive_Set_Swivel" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_SetSwivel" + /// The multiplexor for "Drive_Set_Swivel" static const String multiplexor = ''; /// Value of signal "Set_Front_Swivel" @@ -902,13 +902,13 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Drive_SetSwivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; + return 'Drive_Set_Swivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } } -class DriveLedMessage extends $_dbc.DBCMessage { +class DriveLedDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_LED'; + String messageName = 'Drive_LED_Data'; @override int messageLength = 1; @@ -916,10 +916,10 @@ class DriveLedMessage extends $_dbc.DBCMessage { @override int canId = 0x17; - /// Whether or not "Drive_LED" is multiplex + /// Whether or not "Drive_LED_Data" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_LED" + /// The multiplexor for "Drive_LED_Data" static const String multiplexor = ''; /// Value of signal "Color" @@ -968,22 +968,22 @@ class DriveLedMessage extends $_dbc.DBCMessage { _blinkSignal, ]; - DriveLedMessage({ + DriveLedDataMessage({ this.color = 0, this.blink = 0, }); - /// Creates a clone of this [DriveLedMessage] with the non-null values replaced - DriveLedMessage copyWith({ + /// Creates a clone of this [DriveLedDataMessage] with the non-null values replaced + DriveLedDataMessage copyWith({ num? color, num? blink, - }) => DriveLedMessage( + }) => DriveLedDataMessage( color: color ?? this.color, blink: blink ?? this.blink, ); - factory DriveLedMessage.decode(List payload) { - final message = DriveLedMessage(); + factory DriveLedDataMessage.decode(List payload) { + final message = DriveLedDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); @@ -997,8 +997,8 @@ class DriveLedMessage extends $_dbc.DBCMessage { return message; } - factory DriveLedMessage.fromJson(Map json) => - DriveLedMessage( + factory DriveLedDataMessage.fromJson(Map json) => + DriveLedDataMessage( color: json['Color'] ?? 0, blink: json['Blink'] ?? 0, ); @@ -1021,13 +1021,13 @@ class DriveLedMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Drive_LED(\n Color=$color\n Blink=$blink\n)'; + return 'Drive_LED_Data(\n Color=$color\n Blink=$blink\n)'; } } -class DriveAppliedOutputMessage extends $_dbc.DBCMessage { +class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Applied_Output'; + String messageName = 'Drive_Applied_Output_Data'; @override int messageLength = 6; @@ -1035,10 +1035,10 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { @override int canId = 0x15; - /// Whether or not "Drive_Applied_Output" is multiplex + /// Whether or not "Drive_Applied_Output_Data" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_Applied_Output" + /// The multiplexor for "Drive_Applied_Output_Data" static const String multiplexor = ''; /// Value of signal "Throttle" @@ -1108,25 +1108,25 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { _rightSpeedSignal, ]; - DriveAppliedOutputMessage({ + DriveAppliedOutputDataMessage({ this.throttle = 0, this.leftSpeed = 0, this.rightSpeed = 0, }); - /// Creates a clone of this [DriveAppliedOutputMessage] with the non-null values replaced - DriveAppliedOutputMessage copyWith({ + /// Creates a clone of this [DriveAppliedOutputDataMessage] with the non-null values replaced + DriveAppliedOutputDataMessage copyWith({ num? throttle, num? leftSpeed, num? rightSpeed, - }) => DriveAppliedOutputMessage( + }) => DriveAppliedOutputDataMessage( throttle: throttle ?? this.throttle, leftSpeed: leftSpeed ?? this.leftSpeed, rightSpeed: rightSpeed ?? this.rightSpeed, ); - factory DriveAppliedOutputMessage.decode(List payload) { - final message = DriveAppliedOutputMessage(); + factory DriveAppliedOutputDataMessage.decode(List payload) { + final message = DriveAppliedOutputDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); @@ -1143,8 +1143,8 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { return message; } - factory DriveAppliedOutputMessage.fromJson(Map json) => - DriveAppliedOutputMessage( + factory DriveAppliedOutputDataMessage.fromJson(Map json) => + DriveAppliedOutputDataMessage( throttle: json['Throttle'] ?? 0, leftSpeed: json['Left_Speed'] ?? 0, rightSpeed: json['Right_Speed'] ?? 0, @@ -1170,13 +1170,13 @@ class DriveAppliedOutputMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Drive_Applied_Output(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; + return 'Drive_Applied_Output_Data(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; } } -class DriveBatteryMessage extends $_dbc.DBCMessage { +class DriveBatteryDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Battery'; + String messageName = 'Drive_Battery_Data'; @override int messageLength = 6; @@ -1184,10 +1184,10 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { @override int canId = 0x16; - /// Whether or not "Drive_Battery" is multiplex + /// Whether or not "Drive_Battery_Data" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_Battery" + /// The multiplexor for "Drive_Battery_Data" static const String multiplexor = ''; /// Value of signal "Voltage" @@ -1257,25 +1257,25 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { _currentSignal, ]; - DriveBatteryMessage({ + DriveBatteryDataMessage({ this.voltage = 0, this.temperature = 50, this.current = 0, }); - /// Creates a clone of this [DriveBatteryMessage] with the non-null values replaced - DriveBatteryMessage copyWith({ + /// Creates a clone of this [DriveBatteryDataMessage] with the non-null values replaced + DriveBatteryDataMessage copyWith({ num? voltage, num? temperature, num? current, - }) => DriveBatteryMessage( + }) => DriveBatteryDataMessage( voltage: voltage ?? this.voltage, temperature: temperature ?? this.temperature, current: current ?? this.current, ); - factory DriveBatteryMessage.decode(List payload) { - final message = DriveBatteryMessage(); + factory DriveBatteryDataMessage.decode(List payload) { + final message = DriveBatteryDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); @@ -1292,8 +1292,8 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { return message; } - factory DriveBatteryMessage.fromJson(Map json) => - DriveBatteryMessage( + factory DriveBatteryDataMessage.fromJson(Map json) => + DriveBatteryDataMessage( voltage: json['Voltage'] ?? 0, temperature: json['Temperature'] ?? 50, current: json['Current'] ?? 0, @@ -1319,13 +1319,13 @@ class DriveBatteryMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Drive_Battery(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; + return 'Drive_Battery_Data(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; } } -class DriveSwivelMessage extends $_dbc.DBCMessage { +class DriveSwivelDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Swivel'; + String messageName = 'Drive_Swivel_Data'; @override int messageLength = 6; @@ -1333,10 +1333,10 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { @override int canId = 0x18; - /// Whether or not "Drive_Swivel" is multiplex + /// Whether or not "Drive_Swivel_Data" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Drive_Swivel" + /// The multiplexor for "Drive_Swivel_Data" static const String multiplexor = ''; /// Value of signal "Front_Swivel" @@ -1427,28 +1427,28 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { _rearTiltSignal, ]; - DriveSwivelMessage({ + DriveSwivelDataMessage({ this.frontSwivel = 0, this.frontTilt = 0, this.rearSwivel = 0, this.rearTilt = 0, }); - /// Creates a clone of this [DriveSwivelMessage] with the non-null values replaced - DriveSwivelMessage copyWith({ + /// Creates a clone of this [DriveSwivelDataMessage] with the non-null values replaced + DriveSwivelDataMessage copyWith({ num? frontSwivel, num? frontTilt, num? rearSwivel, num? rearTilt, - }) => DriveSwivelMessage( + }) => DriveSwivelDataMessage( frontSwivel: frontSwivel ?? this.frontSwivel, frontTilt: frontTilt ?? this.frontTilt, rearSwivel: rearSwivel ?? this.rearSwivel, rearTilt: rearTilt ?? this.rearTilt, ); - factory DriveSwivelMessage.decode(List payload) { - final message = DriveSwivelMessage(); + factory DriveSwivelDataMessage.decode(List payload) { + final message = DriveSwivelDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); @@ -1468,8 +1468,8 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { return message; } - factory DriveSwivelMessage.fromJson(Map json) => - DriveSwivelMessage( + factory DriveSwivelDataMessage.fromJson(Map json) => + DriveSwivelDataMessage( frontSwivel: json['Front_Swivel'] ?? 0, frontTilt: json['Front_Tilt'] ?? 0, rearSwivel: json['Rear_Swivel'] ?? 0, @@ -1498,7 +1498,7 @@ class DriveSwivelMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Drive_Swivel(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; + return 'Drive_Swivel_Data(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } } @@ -2190,9 +2190,9 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { } } -class RelayStateMessage extends $_dbc.DBCMessage { +class RelayStateDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Relay_State'; + String messageName = 'Relay_State_Data'; @override int messageLength = 1; @@ -2200,10 +2200,10 @@ class RelayStateMessage extends $_dbc.DBCMessage { @override int canId = 0x25; - /// Whether or not "Relay_State" is multiplex + /// Whether or not "Relay_State_Data" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Relay_State" + /// The multiplexor for "Relay_State_Data" static const String multiplexor = ''; /// Value of signal "Front_Left_Motor" @@ -2378,7 +2378,7 @@ class RelayStateMessage extends $_dbc.DBCMessage { _physicalOverrideSignal, ]; - RelayStateMessage({ + RelayStateDataMessage({ this.frontLeftMotor = 0, this.frontRightMotor = 0, this.backLeftMotor = 0, @@ -2389,8 +2389,8 @@ class RelayStateMessage extends $_dbc.DBCMessage { this.physicalOverride = 0, }); - /// Creates a clone of this [RelayStateMessage] with the non-null values replaced - RelayStateMessage copyWith({ + /// Creates a clone of this [RelayStateDataMessage] with the non-null values replaced + RelayStateDataMessage copyWith({ num? frontLeftMotor, num? frontRightMotor, num? backLeftMotor, @@ -2399,7 +2399,7 @@ class RelayStateMessage extends $_dbc.DBCMessage { num? arm, num? science, num? physicalOverride, - }) => RelayStateMessage( + }) => RelayStateDataMessage( frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, frontRightMotor: frontRightMotor ?? this.frontRightMotor, backLeftMotor: backLeftMotor ?? this.backLeftMotor, @@ -2410,8 +2410,8 @@ class RelayStateMessage extends $_dbc.DBCMessage { physicalOverride: physicalOverride ?? this.physicalOverride, ); - factory RelayStateMessage.decode(List payload) { - final message = RelayStateMessage(); + factory RelayStateDataMessage.decode(List payload) { + final message = RelayStateDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); @@ -2443,8 +2443,8 @@ class RelayStateMessage extends $_dbc.DBCMessage { return message; } - factory RelayStateMessage.fromJson(Map json) => - RelayStateMessage( + factory RelayStateDataMessage.fromJson(Map json) => + RelayStateDataMessage( frontLeftMotor: json['Front_Left_Motor'] ?? 0, frontRightMotor: json['Front_Right_Motor'] ?? 0, backLeftMotor: json['Back_Left_Motor'] ?? 0, @@ -2485,7 +2485,7 @@ class RelayStateMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Relay_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; + return 'Relay_State_Data(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; } } @@ -3145,9 +3145,9 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { } } -class ArmSystemActionMessage extends $_dbc.DBCMessage { +class ArmSetSystemActionMessage extends $_dbc.DBCMessage { @override - String messageName = 'Arm_System_Action'; + String messageName = 'Arm_Set_System_Action'; @override int messageLength = 1; @@ -3155,10 +3155,10 @@ class ArmSystemActionMessage extends $_dbc.DBCMessage { @override int canId = 0x31; - /// Whether or not "Arm_System_Action" is multiplex + /// Whether or not "Arm_Set_System_Action" is multiplex static const bool isMultiplex = false; - /// The multiplexor for "Arm_System_Action" + /// The multiplexor for "Arm_Set_System_Action" static const String multiplexor = ''; /// Value of signal "Stop" @@ -3228,25 +3228,25 @@ class ArmSystemActionMessage extends $_dbc.DBCMessage { _jabSignal, ]; - ArmSystemActionMessage({ + ArmSetSystemActionMessage({ this.stop = 0, this.calibrate = 0, this.jab = 0, }); - /// Creates a clone of this [ArmSystemActionMessage] with the non-null values replaced - ArmSystemActionMessage copyWith({ + /// Creates a clone of this [ArmSetSystemActionMessage] with the non-null values replaced + ArmSetSystemActionMessage copyWith({ num? stop, num? calibrate, num? jab, - }) => ArmSystemActionMessage( + }) => ArmSetSystemActionMessage( stop: stop ?? this.stop, calibrate: calibrate ?? this.calibrate, jab: jab ?? this.jab, ); - factory ArmSystemActionMessage.decode(List payload) { - final message = ArmSystemActionMessage(); + factory ArmSetSystemActionMessage.decode(List payload) { + final message = ArmSetSystemActionMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); @@ -3263,8 +3263,8 @@ class ArmSystemActionMessage extends $_dbc.DBCMessage { return message; } - factory ArmSystemActionMessage.fromJson(Map json) => - ArmSystemActionMessage( + factory ArmSetSystemActionMessage.fromJson(Map json) => + ArmSetSystemActionMessage( stop: json['Stop'] ?? 0, calibrate: json['Calibrate'] ?? 0, jab: json['Jab'] ?? 0, @@ -3290,6 +3290,6 @@ class ArmSystemActionMessage extends $_dbc.DBCMessage { @override String toString() { - return 'Arm_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; + return 'Arm_Set_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; } } From 560679e1f4e2d0640910ff8e5c614b84d43c0856 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 18 May 2025 00:14:34 -0400 Subject: [PATCH 20/30] Catch error if can0 is not found --- subsystems/lib/src/devices/can_bus.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index e77bb07a..6da1790c 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -338,9 +338,17 @@ class CanBus extends Service { "bitrate", "500000", ]); - device = LinuxCan.instance.devices.singleWhere( - (device) => device.networkInterface.name == "can0", - ); + try { + device = LinuxCan.instance.devices.singleWhere( + (device) => device.networkInterface.name == "can0", + ); + } catch (e) { + if (e is StateError) { + logger.error("No CAN Interface found named can0"); + return false; + } + rethrow; + } if (!device!.isUp) { logger.error("CAN0 is not up", body: "Device state: ${device!.state}"); return false; From 012989ed1b1a77e76632bb9d9d02a9059b471749 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 18 May 2025 14:20:52 -0400 Subject: [PATCH 21/30] Regenerated DBC messages with new voltage length --- .../lib/src/generated/rover_messages.dbc.dart | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index ff6ca261..6c110b3f 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -1179,7 +1179,7 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { String messageName = 'Drive_Battery_Data'; @override - int messageLength = 6; + int messageLength = 5; @override int canId = 0x16; @@ -1206,13 +1206,13 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 0, - length: 16, - mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - factor: 0.00055, + length: 10, + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], + factor: 0.03548387097, offset: 0, min: 0, - max: 36, + max: 36.3, unit: 'V', ); @@ -1222,10 +1222,10 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 16, + start: 10, length: 12, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], factor: 0.09, offset: 50, min: -40, @@ -1239,10 +1239,10 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 28, + start: 22, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0], - mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0], + mappingIndexes: [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37], factor: 0.1, offset: 0, min: 0, From f7459b6fd434eb8b1d63047f3ffe7fd02b02c427 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sun, 18 May 2025 14:44:50 -0400 Subject: [PATCH 22/30] Update DBC for relays signals --- subsystems/lib/src/devices/can_bus.dart | 52 ++-- .../lib/src/generated/rover_messages.dbc.dart | 282 +++--------------- 2 files changed, 55 insertions(+), 279 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 6da1790c..ed70912e 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -9,18 +9,8 @@ import "package:subsystems/src/generated/rover_messages.dbc.dart"; import "package:subsystems/subsystems.dart" hide CanSocket; extension on num { - bool get boolValue => this == 1; - - BoolState get boolState => boolValue ? BoolState.YES : BoolState.NO; - - BoolState get armBoolState { - if (this == 1) { - return BoolState.YES; - } else if (this == 2) { - return BoolState.NO; - } - return BoolState.BOOL_UNDEFINED; - } + BoolState get armBoolState => + BoolState.valueOf(toInt()) ?? BoolState.BOOL_UNDEFINED; } extension on bool { @@ -137,33 +127,29 @@ extension on DriveCommand { } extension on RelayStateDataMessage { + BoolState intToBoolState(num value) => + value == 1 ? BoolState.YES : BoolState.NO; + RelaysData toRelayProto() => RelaysData( - frontLeftMotor: frontLeftMotor.boolState, - frontRightMotor: frontRightMotor.boolState, - backLeftMotor: backLeftMotor.boolState, - backRightMotor: backRightMotor.boolState, - arm: arm.boolState, - drive: drive.boolState, - science: science.boolState, + frontLeftMotor: intToBoolState(frontLeftMotor), + frontRightMotor: intToBoolState(frontRightMotor), + backLeftMotor: intToBoolState(backLeftMotor), + backRightMotor: intToBoolState(backRightMotor), + arm: intToBoolState(arm), + drive: intToBoolState(drive), + science: intToBoolState(science), ); } extension on RelaysCommand { DBCMessage get asSetState => RelaySetStateMessage( - updateArm: hasArm().intValue, - arm: arm.intValue, - updateFrontLeftMotor: hasFrontLeftMotor().intValue, - frontLeftMotor: frontLeftMotor.intValue, - updateFrontRightMotor: hasFrontRightMotor().intValue, - frontRightMotor: frontRightMotor.intValue, - updateBackLeftMotor: hasBackLeftMotor().intValue, - backLeftMotor: backLeftMotor.intValue, - updateBackRightMotor: hasBackRightMotor().intValue, - backRightMotor: backRightMotor.intValue, - updateDrive: hasDrive().intValue, - drive: drive.intValue, - updateScience: hasScience().intValue, - science: science.intValue, + arm: arm.value, + frontLeftMotor: frontLeftMotor.value, + frontRightMotor: frontRightMotor.value, + backLeftMotor: backLeftMotor.value, + backRightMotor: backRightMotor.value, + drive: drive.value, + science: science.value, ); List toDBC() => [asSetState]; diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 6c110b3f..9df5aa08 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -1727,96 +1727,41 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { /// The multiplexor for "Relay_Set_State" static const String multiplexor = ''; - /// Value of signal "Update_Front_Left_Motor" - num updateFrontLeftMotor; - /// Value of signal "Front_Left_Motor" num frontLeftMotor; - /// Value of signal "Update_Front_Right_Motor" - num updateFrontRightMotor; - /// Value of signal "Front_Right_Motor" num frontRightMotor; - /// Value of signal "Update_Back_Left_Motor" - num updateBackLeftMotor; - /// Value of signal "Back_Left_Motor" num backLeftMotor; - /// Value of signal "Update_Back_Right_Motor" - num updateBackRightMotor; - /// Value of signal "Back_Right_Motor" num backRightMotor; - /// Value of signal "Update_Arm" - num updateArm; - /// Value of signal "Arm" num arm; - /// Value of signal "Update_Science" - num updateScience; - /// Value of signal "Science" num science; - /// Value of signal "Update_Drive" - num updateDrive; - /// Value of signal "Drive" num drive; - final $_dbc.DBCSignal _updateFrontLeftMotorSignal = $_dbc.DBCSignal( - name: 'Update_Front_Left_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 0, - length: 1, - mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 1, - length: 1, - mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [1], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _updateFrontRightMotorSignal = $_dbc.DBCSignal( - name: 'Update_Front_Right_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 2, - length: 1, - mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [2], + start: 0, + length: 2, + mapping: [1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @@ -1826,31 +1771,14 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 3, - length: 1, - mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [3], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _updateBackLeftMotorSignal = $_dbc.DBCSignal( - name: 'Update_Back_Left_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 4, - length: 1, - mapping: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [4], + start: 2, + length: 2, + mapping: [0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [2, 3], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @@ -1860,31 +1788,14 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 5, - length: 1, - mapping: [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [5], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _updateBackRightMotorSignal = $_dbc.DBCSignal( - name: 'Update_Back_Right_Motor', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 6, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [6], + start: 4, + length: 2, + mapping: [0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [4, 5], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @@ -1894,31 +1805,14 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 7, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [7], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _updateArmSignal = $_dbc.DBCSignal( - name: 'Update_Arm', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 8, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [8], + start: 6, + length: 2, + mapping: [0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [6, 7], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @@ -1928,31 +1822,14 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 9, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], - mappingIndexes: [9], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _updateScienceSignal = $_dbc.DBCSignal( - name: 'Update_Science', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 10, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], - mappingIndexes: [10], + start: 8, + length: 2, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0], + mappingIndexes: [8, 9], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @@ -1962,31 +1839,14 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 11, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], - mappingIndexes: [11], - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _updateDriveSignal = $_dbc.DBCSignal( - name: 'Update_Drive', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 12, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], - mappingIndexes: [12], + start: 10, + length: 2, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0], + mappingIndexes: [10, 11], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @@ -1996,82 +1856,54 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 13, - length: 1, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], - mappingIndexes: [13], + start: 12, + length: 2, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0], + mappingIndexes: [12, 13], factor: 1, offset: 0, min: 0, - max: 1, + max: 3, unit: '', ); @override List<$_dbc.DBCSignal> get signals => [ - _updateFrontLeftMotorSignal, _frontLeftMotorSignal, - _updateFrontRightMotorSignal, _frontRightMotorSignal, - _updateBackLeftMotorSignal, _backLeftMotorSignal, - _updateBackRightMotorSignal, _backRightMotorSignal, - _updateArmSignal, _armSignal, - _updateScienceSignal, _scienceSignal, - _updateDriveSignal, _driveSignal, ]; RelaySetStateMessage({ - this.updateFrontLeftMotor = 0, this.frontLeftMotor = 0, - this.updateFrontRightMotor = 0, this.frontRightMotor = 0, - this.updateBackLeftMotor = 0, this.backLeftMotor = 0, - this.updateBackRightMotor = 0, this.backRightMotor = 0, - this.updateArm = 0, this.arm = 0, - this.updateScience = 0, this.science = 0, - this.updateDrive = 0, this.drive = 0, }); /// Creates a clone of this [RelaySetStateMessage] with the non-null values replaced RelaySetStateMessage copyWith({ - num? updateFrontLeftMotor, num? frontLeftMotor, - num? updateFrontRightMotor, num? frontRightMotor, - num? updateBackLeftMotor, num? backLeftMotor, - num? updateBackRightMotor, num? backRightMotor, - num? updateArm, num? arm, - num? updateScience, num? science, - num? updateDrive, num? drive, }) => RelaySetStateMessage( - updateFrontLeftMotor: updateFrontLeftMotor ?? this.updateFrontLeftMotor, frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, - updateFrontRightMotor: updateFrontRightMotor ?? this.updateFrontRightMotor, frontRightMotor: frontRightMotor ?? this.frontRightMotor, - updateBackLeftMotor: updateBackLeftMotor ?? this.updateBackLeftMotor, backLeftMotor: backLeftMotor ?? this.backLeftMotor, - updateBackRightMotor: updateBackRightMotor ?? this.updateBackRightMotor, backRightMotor: backRightMotor ?? this.backRightMotor, - updateArm: updateArm ?? this.updateArm, arm: arm ?? this.arm, - updateScience: updateScience ?? this.updateScience, science: science ?? this.science, - updateDrive: updateDrive ?? this.updateDrive, drive: drive ?? this.drive, ); @@ -2080,45 +1912,24 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { final typedBuffer = $_typed.Uint8List.fromList(payload); final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - message.updateFrontLeftMotor = - message._updateFrontLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateFrontLeftMotorSignal.min); message.frontLeftMotor = message._frontLeftMotorSignal.decode(bitField) ?? $_math.max(0, message._frontLeftMotorSignal.min); - message.updateFrontRightMotor = - message._updateFrontRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateFrontRightMotorSignal.min); message.frontRightMotor = message._frontRightMotorSignal.decode(bitField) ?? $_math.max(0, message._frontRightMotorSignal.min); - message.updateBackLeftMotor = - message._updateBackLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateBackLeftMotorSignal.min); message.backLeftMotor = message._backLeftMotorSignal.decode(bitField) ?? $_math.max(0, message._backLeftMotorSignal.min); - message.updateBackRightMotor = - message._updateBackRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._updateBackRightMotorSignal.min); message.backRightMotor = message._backRightMotorSignal.decode(bitField) ?? $_math.max(0, message._backRightMotorSignal.min); - message.updateArm = - message._updateArmSignal.decode(bitField) ?? - $_math.max(0, message._updateArmSignal.min); message.arm = message._armSignal.decode(bitField) ?? $_math.max(0, message._armSignal.min); - message.updateScience = - message._updateScienceSignal.decode(bitField) ?? - $_math.max(0, message._updateScienceSignal.min); message.science = message._scienceSignal.decode(bitField) ?? $_math.max(0, message._scienceSignal.min); - message.updateDrive = - message._updateDriveSignal.decode(bitField) ?? - $_math.max(0, message._updateDriveSignal.min); message.drive = message._driveSignal.decode(bitField) ?? $_math.max(0, message._driveSignal.min); @@ -2128,38 +1939,24 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { factory RelaySetStateMessage.fromJson(Map json) => RelaySetStateMessage( - updateFrontLeftMotor: json['Update_Front_Left_Motor'] ?? 0, frontLeftMotor: json['Front_Left_Motor'] ?? 0, - updateFrontRightMotor: json['Update_Front_Right_Motor'] ?? 0, frontRightMotor: json['Front_Right_Motor'] ?? 0, - updateBackLeftMotor: json['Update_Back_Left_Motor'] ?? 0, backLeftMotor: json['Back_Left_Motor'] ?? 0, - updateBackRightMotor: json['Update_Back_Right_Motor'] ?? 0, backRightMotor: json['Back_Right_Motor'] ?? 0, - updateArm: json['Update_Arm'] ?? 0, arm: json['Arm'] ?? 0, - updateScience: json['Update_Science'] ?? 0, science: json['Science'] ?? 0, - updateDrive: json['Update_Drive'] ?? 0, drive: json['Drive'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { - _updateFrontLeftMotorSignal: updateFrontLeftMotor, _frontLeftMotorSignal: frontLeftMotor, - _updateFrontRightMotorSignal: updateFrontRightMotor, _frontRightMotorSignal: frontRightMotor, - _updateBackLeftMotorSignal: updateBackLeftMotor, _backLeftMotorSignal: backLeftMotor, - _updateBackRightMotorSignal: updateBackRightMotor, _backRightMotorSignal: backRightMotor, - _updateArmSignal: updateArm, _armSignal: arm, - _updateScienceSignal: updateScience, _scienceSignal: science, - _updateDriveSignal: updateDrive, _driveSignal: drive, }; @@ -2168,25 +1965,18 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { @override Map toJson() => { - 'Update_Front_Left_Motor': updateFrontLeftMotor, 'Front_Left_Motor': frontLeftMotor, - 'Update_Front_Right_Motor': updateFrontRightMotor, 'Front_Right_Motor': frontRightMotor, - 'Update_Back_Left_Motor': updateBackLeftMotor, 'Back_Left_Motor': backLeftMotor, - 'Update_Back_Right_Motor': updateBackRightMotor, 'Back_Right_Motor': backRightMotor, - 'Update_Arm': updateArm, 'Arm': arm, - 'Update_Science': updateScience, 'Science': science, - 'Update_Drive': updateDrive, 'Drive': drive, }; @override String toString() { - return 'Relay_Set_State(\n Update_Front_Left_Motor=$updateFrontLeftMotor\n Front_Left_Motor=$frontLeftMotor\n Update_Front_Right_Motor=$updateFrontRightMotor\n Front_Right_Motor=$frontRightMotor\n Update_Back_Left_Motor=$updateBackLeftMotor\n Back_Left_Motor=$backLeftMotor\n Update_Back_Right_Motor=$updateBackRightMotor\n Back_Right_Motor=$backRightMotor\n Update_Arm=$updateArm\n Arm=$arm\n Update_Science=$updateScience\n Science=$science\n Update_Drive=$updateDrive\n Drive=$drive\n)'; + return 'Relay_Set_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Arm=$arm\n Science=$science\n Drive=$drive\n)'; } } From 77ff2fc328d1aa8dcb3d788036a204ce20c94921 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 20 May 2025 01:31:50 -0400 Subject: [PATCH 23/30] Refactor to use 1 message stream + cleanup --- subsystems/lib/src/devices/can_bus.dart | 223 ++++++++++++----------- subsystems/lib/src/devices/firmware.dart | 14 +- subsystems/lib/subsystems.dart | 10 + 3 files changed, 139 insertions(+), 108 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index ed70912e..4596b1f9 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -300,12 +300,10 @@ class CanBus extends Service { Timer? _sendHeartbeatTimer; Timer? _checkHeartbeatsTimer; + bool _shouldReset = false; + bool _heartbeatSendSuccessful = false; + StreamSubscription? _frameSubscription; - StreamSubscription? _driveSubscription; - StreamSubscription? _relaySubscription; - StreamSubscription? _armSubscription; - StreamSubscription? _gripperSubscription; - StreamSubscription? _scienceSubscription; @override Future init() async { @@ -318,12 +316,22 @@ class CanBus extends Service { "link", "set", "can0", - "up", "type", "can", "bitrate", "500000", ]); + final upResult = await Process.run("sudo", [ + "ip", + "link", + "set", + "can0", + "up", + ]); + if (upResult.exitCode != 0) { + logger.error("Could not set Can0 up", body: upResult.stderr); + return false; + } try { device = LinuxCan.instance.devices.singleWhere( (device) => device.networkInterface.name == "can0", @@ -352,37 +360,6 @@ class CanBus extends Service { heartbeatTimeout, (_) => checkHeartbeats(), ); - - _driveSubscription = collection.server.messages.onMessage( - name: DriveCommand().messageName, - constructor: DriveCommand.fromBuffer, - callback: sendDriveCommand, - ); - - _relaySubscription = collection.server.messages.onMessage( - name: RelaysCommand().messageName, - constructor: RelaysCommand.fromBuffer, - callback: sendRelaysCommand, - ); - - _armSubscription = collection.server.messages.onMessage( - name: ArmCommand().messageName, - constructor: ArmCommand.fromBuffer, - callback: sendArmCommand, - ); - - _gripperSubscription = collection.server.messages.onMessage( - name: GripperCommand().messageName, - constructor: GripperCommand.fromBuffer, - callback: sendGripperCommand, - ); - - _scienceSubscription = collection.server.messages.onMessage( - name: ScienceCommand().messageName, - constructor: ScienceCommand.fromBuffer, - callback: sendScienceCommand, - ); - return true; } @@ -394,110 +371,148 @@ class CanBus extends Service { await socket?.close(); socket = null; - await _driveSubscription?.cancel(); - await _relaySubscription?.cancel(); - await _armSubscription?.cancel(); - await _gripperSubscription?.cancel(); - await _scienceSubscription?.cancel(); await _frameSubscription?.cancel(); deviceHeartbeats.clear(); } - bool _deviceConnected(Device device) => deviceHeartbeats.containsKey(device); + /// Whether or not a broadcast message has been received from [device] within + /// the past [heartbeatTimeout] amount of time + bool deviceConnected(Device device) => deviceHeartbeats.containsKey(device); + + /// Sends the [dbcMessages] over the CAN bus only if a broadcast message has been + /// received from [device] and [override] is set to false + Future _sendDeviceCommand({ + required Device device, + required Iterable dbcMessages, + bool override = false, + }) async { + if ((!deviceConnected(device) || !_heartbeatSendSuccessful) && !override) { + return false; + } + return !(await Future.wait( + dbcMessages.map(sendDBCMessage), + )).contains(false); + } /// Sends a drive command over the CAN bus /// /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the drive device. The [override] should only /// be true if this is a stop command. - Future sendDriveCommand( + /// + /// Returs whether or not the command was sent over the bus + Future sendDriveCommand( DriveCommand command, { bool override = false, - }) async { - if (!_deviceConnected(Device.DRIVE) && !override) { - return; - } - return Future.forEach(command.toDBC(), sendDBCMessage); - } + }) => _sendDeviceCommand( + device: Device.DRIVE, + dbcMessages: command.toDBC(), + override: override, + ); /// Sends a relay command over the CAN bus /// /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the relay device. The [override] should only /// be true if this is a stop command. - Future sendRelaysCommand( + /// + /// Returs whether or not the command was sent over the bus + Future sendRelaysCommand( RelaysCommand command, { bool override = false, - }) async { - if (!_deviceConnected(Device.RELAY) && !override) { - return; - } - return Future.forEach(command.toDBC(), sendDBCMessage); - } + }) => _sendDeviceCommand( + device: Device.RELAY, + dbcMessages: command.toDBC(), + override: override, + ); /// Sends an arm command over the CAN bus /// /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the arm device. The [override] should only /// be true if this is a stop command. - Future sendArmCommand( - ArmCommand command, { - bool override = false, - }) async { - if (!_deviceConnected(Device.ARM) && !override) { - return; - } - return Future.forEach(command.toDBC(), sendDBCMessage); - } + /// + /// Returs whether or not the command was sent over the bus + Future sendArmCommand(ArmCommand command, {bool override = false}) => + _sendDeviceCommand( + device: Device.ARM, + dbcMessages: command.toDBC(), + override: override, + ); /// Sends a gripper command over the CAN bus /// /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the gripper device. The [override] should only /// be true if this is a stop command. - Future sendGripperCommand( + /// + /// Returs whether or not the command was sent over the bus + Future sendGripperCommand( GripperCommand command, { bool override = false, - }) async { - if (!_deviceConnected(Device.GRIPPER) && !override) { - return; - } - } + }) => _sendDeviceCommand( + device: Device.GRIPPER, + dbcMessages: [], + override: override, + ); /// Sends a science command over the CAN bus /// /// If [override] is set to false, the command will only be sent if the rover /// has received heartbeats from the science device. The [override] should only /// be true if this is a stop command. - Future sendScienceCommand( + /// + /// Returs whether or not the command was sent over the bus + Future sendScienceCommand( ScienceCommand command, { bool override = false, - }) async { - if (!_deviceConnected(Device.SCIENCE) && !override) { - return; + }) => _sendDeviceCommand( + device: Device.SCIENCE, + dbcMessages: [], + override: override, + ); + + /// Sends a wrapped message over the CAN bus, returns + /// whether or not the message was successfully sent + Future sendWrapper(WrappedMessage message) async { + if (message.name == DriveCommand().messageName) { + return sendMessage(DriveCommand.fromBuffer(message.data)); + } else if (message.name == RelaysCommand().messageName) { + return sendMessage(RelaysCommand.fromBuffer(message.data)); + } else if (message.name == ArmCommand().messageName) { + return sendMessage(ArmCommand.fromBuffer(message.data)); + } else if (message.name == GripperCommand().messageName) { + return sendMessage(GripperCommand.fromBuffer(message.data)); + } else if (message.name == ScienceCommand().messageName) { + return sendMessage(ScienceCommand.fromBuffer(message.data)); } + return false; } /// Sends a message's DBC equivalent over the CAN bus - Future send(Message message) async { - if (message is DriveCommand) { - return sendDriveCommand(message); - } else if (message is RelaysCommand) { - return sendRelaysCommand(message); - } else if (message is ArmCommand) { - return sendArmCommand(message); - } else if (message is GripperCommand) { - return sendGripperCommand(message); - } else if (message is ScienceCommand) { - return sendScienceCommand(message); - } - } + /// + /// Returns whether or not the message was sent over the bus + Future sendMessage(Message message) => switch (message) { + DriveCommand() => sendDriveCommand(message), + RelaysCommand() => sendRelaysCommand(message), + ArmCommand() => sendArmCommand(message), + GripperCommand() => sendGripperCommand(message), + ScienceCommand() => sendScienceCommand(message), + _ => Future.value(false), + }; /// Sends a heartbeat message over the CAN bus - Future sendHeartbeat() { + Future sendHeartbeat() async { + if (_shouldReset) { + await dispose(); + await Future.delayed(const Duration(milliseconds: 1000)); + await init(); + _shouldReset = false; + return false; + } final heartbeat = RoverHeartbeatMessage(); - return sendDBCMessage(heartbeat); + return _heartbeatSendSuccessful = await sendDBCMessage(heartbeat); } /// Checks all device's heartbeats and determines if they are still connected @@ -516,33 +531,35 @@ class CanBus extends Service { } /// Sends a DBC message over the CAN bus - Future sendDBCMessage(DBCMessage message) async { + /// + /// Returns whether or not the message was successfully sent + Future sendDBCMessage(DBCMessage message) async { if (socket == null) { - return; + return false; } - if (!(device?.isUp ?? false)) { + if (!(device?.isUp ?? true)) { logger.warning( "Device is not up while trying to send message, restarting CAN socket", ); - await dispose(); - await Future.delayed(const Duration(milliseconds: 1000)); - await init(); - return; + _shouldReset = true; + return false; } - return socket + var success = true; + await socket ?.send(CanFrame.standard(id: message.canId, data: message.encode())) - .catchError((Object e) async { + .catchError((Object e) { + success = false; if (e.toString().contains("No buffer space")) { logger.debug("Error when sending CAN message", body: e.toString()); } else { logger.error("Error when sending CAN message", body: e.toString()); } - if (!(device?.isUp ?? false)) { - await dispose(); - await init(); + if (!(device?.isUp ?? true)) { + _shouldReset = true; } }); + return success; } void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { diff --git a/subsystems/lib/src/devices/firmware.dart b/subsystems/lib/src/devices/firmware.dart index ee8acc9b..15e9c14d 100644 --- a/subsystems/lib/src/devices/firmware.dart +++ b/subsystems/lib/src/devices/firmware.dart @@ -24,7 +24,7 @@ final nameToDevice = { /// This service relies on the [BurtFirmwareSerial] class defined in `package:burt_network`. That /// class takes care of connecting to, identifying, and streaming from a firmware device. This /// service is responsible for routing incoming UDP messages to the correct firmware device -/// ([_sendToSerial]), and forwarding serial messages to the Dashboard ([RoverSocket.sendWrapper]). +/// ([sendToSerial]), and forwarding serial messages to the Dashboard ([RoverSocket.sendWrapper]). class FirmwareManager extends Service { /// Subscriptions to each of the firmware devices. final List> _subscriptions = []; @@ -35,13 +35,17 @@ class FirmwareManager extends Service { @override Future init() async { devices = await getFirmwareDevices(); - collection.server.messages.listen(_sendToSerial); var result = true; for (final device in devices) { logger.debug("Initializing device: ${device.port}"); result &= await device.init(); if (!device.isReady) continue; - final subscription = device.messages.listen(collection.server.sendWrapper); + final subscription = device.messages.listen((message) { + // Don't send data if the device is also connected via CAN + if (!collection.can.deviceConnected(device.device)) { + collection.server.sendWrapper(message); + } + }); _subscriptions.add(subscription); } return result; @@ -60,7 +64,7 @@ class FirmwareManager extends Service { /// Sends a [WrappedMessage] to the correct Serial device. /// /// The notes on [sendMessage] apply here as well. - void _sendToSerial(WrappedMessage wrapper) { + void sendToSerial(WrappedMessage wrapper) { final device = nameToDevice[wrapper.name]; if (device == null) return; final serial = devices.firstWhereOrNull((s) => s.device == device); @@ -73,5 +77,5 @@ class FirmwareManager extends Service { /// This does nothing if the appropriate device is not connected. Specifically, this is not an /// error because the Dashboard may be used during testing, when the hardware devices may not be /// assembled, connected, or functional yet. - void sendMessage(Message message) => _sendToSerial(message.wrap()); + void sendMessage(Message message) => sendToSerial(message.wrap()); } diff --git a/subsystems/lib/subsystems.dart b/subsystems/lib/subsystems.dart index 987ef9e5..03556afc 100644 --- a/subsystems/lib/subsystems.dart +++ b/subsystems/lib/subsystems.dart @@ -40,6 +40,8 @@ class SubsystemsCollection extends Service { /// Timer for sending the subsystems status Timer? dataSendTimer; + StreamSubscription? _messageSubscription; + @override Future init() async { await server.init(); @@ -49,6 +51,13 @@ class SubsystemsCollection extends Service { const Duration(milliseconds: 250), sendStatus, ); + _messageSubscription = server.messages.listen((message) async { + if (await can.sendWrapper(message)) { + return; + } else { + firmware.sendToSerial(message); + } + }); try { result &= await firmware.init(); result &= await gps.init(); @@ -71,6 +80,7 @@ class SubsystemsCollection extends Service { Future dispose() async { logger.info("Shutting down..."); await onDisconnect(); + await _messageSubscription?.cancel(); isReady = false; await firmware.dispose(); await imu.dispose(); From cbf8492be01e34c84670d1ca4d9045010bed9e08 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Sat, 31 May 2025 22:22:28 -0400 Subject: [PATCH 24/30] Check whether a CAN message can be sent before sending --- subsystems/lib/src/devices/can_bus.dart | 14 ++++++++++++++ subsystems/lib/src/devices/firmware.dart | 23 ++++++++++------------- subsystems/lib/subsystems.dart | 13 +++++++++++-- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 4596b1f9..72411115 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -502,6 +502,20 @@ class CanBus extends Service { _ => Future.value(false), }; + /// Whether or not [message] can be successfully sent over the bus + /// + /// If no broadcast has been received from the device corresponding to [message], + /// it will return false. If there was an error while sending a heartbeat, this + /// will also return false; + bool canSendWrapper(WrappedMessage message) { + if (!_heartbeatSendSuccessful || + !commandToDevice.containsKey(message.name)) { + return false; + } + + return deviceConnected(commandToDevice[message.name]!); + } + /// Sends a heartbeat message over the CAN bus Future sendHeartbeat() async { if (_shouldReset) { diff --git a/subsystems/lib/src/devices/firmware.dart b/subsystems/lib/src/devices/firmware.dart index 15e9c14d..e7426613 100644 --- a/subsystems/lib/src/devices/firmware.dart +++ b/subsystems/lib/src/devices/firmware.dart @@ -7,14 +7,6 @@ import "package:burt_network/burt_network.dart"; import "serial_utils.dart"; -/// Maps command names to [Device]s. -final nameToDevice = { - ArmCommand().messageName: Device.ARM, - DriveCommand().messageName: Device.DRIVE, - ScienceCommand().messageName: Device.SCIENCE, - RelaysCommand().messageName: Device.RELAY, -}; - /// A service to manage all the connected firmware. /// /// Firmware means any device using the [Firmware-Utilities](https://github.com/BinghamtonRover/Firmware-Utilities) @@ -64,12 +56,15 @@ class FirmwareManager extends Service { /// Sends a [WrappedMessage] to the correct Serial device. /// /// The notes on [sendMessage] apply here as well. - void sendToSerial(WrappedMessage wrapper) { - final device = nameToDevice[wrapper.name]; - if (device == null) return; + /// + /// Returns whether or not the device corresponding to the command is connected. + bool sendToSerial(WrappedMessage wrapper) { + final device = commandToDevice[wrapper.name]; + if (device == null) return false; final serial = devices.firstWhereOrNull((s) => s.device == device); - if (serial == null) return; + if (serial == null) return false; serial.sendBytes(wrapper.data); + return true; } /// Sends a [Message] to the appropriate firmware device. @@ -77,5 +72,7 @@ class FirmwareManager extends Service { /// This does nothing if the appropriate device is not connected. Specifically, this is not an /// error because the Dashboard may be used during testing, when the hardware devices may not be /// assembled, connected, or functional yet. - void sendMessage(Message message) => sendToSerial(message.wrap()); + /// + /// Returns whether or not the device for the message is connected + bool sendMessage(Message message) => sendToSerial(message.wrap()); } diff --git a/subsystems/lib/subsystems.dart b/subsystems/lib/subsystems.dart index 03556afc..d792d09b 100644 --- a/subsystems/lib/subsystems.dart +++ b/subsystems/lib/subsystems.dart @@ -17,6 +17,15 @@ export "src/can/socket_ffi.dart"; export "src/can/socket_interface.dart"; export "src/can/socket_stub.dart"; +/// Maps command names to [Device]s. +final commandToDevice = { + ArmCommand().messageName: Device.ARM, + GripperCommand().messageName: Device.GRIPPER, + DriveCommand().messageName: Device.DRIVE, + ScienceCommand().messageName: Device.SCIENCE, + RelaysCommand().messageName: Device.RELAY, +}; + /// Contains all the resources needed by the subsystems program. class SubsystemsCollection extends Service { /// Whether the subsystems is fully initialized. @@ -52,8 +61,8 @@ class SubsystemsCollection extends Service { sendStatus, ); _messageSubscription = server.messages.listen((message) async { - if (await can.sendWrapper(message)) { - return; + if (can.canSendWrapper(message)) { + await can.sendWrapper(message); } else { firmware.sendToSerial(message); } From 9e56d3d9efe0e69d957312e8616bc54e430bb7f7 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Thu, 31 Jul 2025 17:43:42 -0400 Subject: [PATCH 25/30] Huge cleanup - Move dbc <-> proto conversions to separate file - Use maps for conversion function lookup --- subsystems/lib/src/devices/can_bus.dart | 401 +++--------------- subsystems/lib/src/utils/dbc_conversions.dart | 244 +++++++++++ 2 files changed, 295 insertions(+), 350 deletions(-) create mode 100644 subsystems/lib/src/utils/dbc_conversions.dart diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 72411115..e0a30952 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -6,20 +6,37 @@ import "package:burt_network/service.dart"; import "package:dart_dbc_generator/dart_dbc_generator.dart"; import "package:linux_can/linux_can.dart"; import "package:subsystems/src/generated/rover_messages.dbc.dart"; +import "package:subsystems/src/utils/dbc_conversions.dart"; import "package:subsystems/subsystems.dart" hide CanSocket; -extension on num { - BoolState get armBoolState => - BoolState.valueOf(toInt()) ?? BoolState.BOOL_UNDEFINED; -} - -extension on bool { - int get intValue => this ? 1 : 0; -} - -extension on BoolState { - int get intValue => this == BoolState.YES ? 1 : 0; -} +/// Map of command names and a function to convert a message for that device into a list of DBC messages +final Map Function(Message message)> deviceToDBC = { + DriveCommand().messageName: (e) => (e as DriveCommand).toDBC(), + RelaysCommand().messageName: (e) => (e as RelaysCommand).toDBC(), + ArmCommand().messageName: (e) => (e as ArmCommand).toDBC(), + GripperCommand().messageName: (e) => [], + ScienceCommand().messageName: (e) => [], +}; + +/// A map of CAN IDs to a function to convert them into a protobuf message +final Map data)> canIDToMessage = { + DriveAppliedOutputDataMessage().canId: (data) => + DriveAppliedOutputDataMessage.decode(data).toDriveProto(), + DriveBatteryDataMessage().canId: (data) => + DriveBatteryDataMessage.decode(data).toDriveProto(), + DriveLedDataMessage().canId: (data) => + DriveLedDataMessage.decode(data).toDriveProto(), + DriveSwivelDataMessage().canId: (data) => + DriveSwivelDataMessage.decode(data).toDriveProto(), + RelayStateDataMessage().canId: (data) => + RelayStateDataMessage.decode(data).toRelayProto(), + ArmMotorMoveDataMessage().canId: (data) => + ArmMotorMoveDataMessage.decode(data).toArmProto(), + ArmMotorStepDataMessage().canId: (data) => + ArmMotorStepDataMessage.decode(data).toArmProto(), + ArmMotorAngleDataMessage().canId: (data) => + ArmMotorAngleDataMessage.decode(data).toArmProto(), +}; extension on DeviceBroadcastMessage { Message toDriveProto() => DriveData(version: version); @@ -51,223 +68,6 @@ extension on DeviceBroadcastMessage { Version(major: fwVersionMajor.toInt(), minor: fwVersionMinor.toInt()); } -extension on DriveAppliedOutputDataMessage { - DriveData toDriveProto() => DriveData( - throttle: throttle.toDouble(), - left: leftSpeed.toDouble(), - right: rightSpeed.toDouble(), - setLeft: true, - setRight: true, - setThrottle: true, - ); -} - -extension on DriveBatteryDataMessage { - DriveData toDriveProto() => DriveData( - batteryVoltage: voltage.toDouble(), - batteryTemperature: temperature.toDouble(), - batteryCurrent: current.toDouble(), - ); -} - -extension on DriveLedDataMessage { - DriveData toDriveProto() => - DriveData(color: ProtoColor.valueOf(color.toInt())); -} - -extension on DriveSwivelDataMessage { - DriveData toDriveProto() => DriveData( - frontSwivel: frontSwivel.toDouble(), - frontTilt: frontTilt.toDouble(), - rearSwivel: rearSwivel.toDouble(), - rearTilt: rearTilt.toDouble(), - ); -} - -extension on DriveCommand { - DBCMessage get asSetSpeeds => DriveSetSpeedsMessage( - shouldSetLeft: setLeft.intValue, - shouldSetRight: setRight.intValue, - shouldSetThrottle: setThrottle.intValue, - leftSpeed: left, - rightSpeed: right, - throttle: throttle, - ); - - DBCMessage get asSetLEDS => - DriveSetLedMessage(color: color.value, blink: blink.intValue); - - DBCMessage get asSetSwivels => DriveSetSwivelMessage( - setFrontSwivel: hasFrontSwivel().intValue, - setFrontTilt: hasFrontTilt().intValue, - setRearSwivel: hasRearSwivel().intValue, - setRearTilt: hasRearTilt().intValue, - frontSwivel: frontSwivel, - frontTilt: frontTilt, - rearSwivel: rearSwivel, - rearTilt: rearTilt, - ); - - List toDBC() { - final output = []; - if (setLeft || setRight || setThrottle) { - output.add(asSetSpeeds); - } - if (hasColor() || hasBlink()) { - output.add(asSetLEDS); - } - if (hasFrontSwivel() || - hasFrontTilt() || - hasRearSwivel() || - hasRearTilt()) { - output.add(asSetSwivels); - } - return output; - } -} - -extension on RelayStateDataMessage { - BoolState intToBoolState(num value) => - value == 1 ? BoolState.YES : BoolState.NO; - - RelaysData toRelayProto() => RelaysData( - frontLeftMotor: intToBoolState(frontLeftMotor), - frontRightMotor: intToBoolState(frontRightMotor), - backLeftMotor: intToBoolState(backLeftMotor), - backRightMotor: intToBoolState(backRightMotor), - arm: intToBoolState(arm), - drive: intToBoolState(drive), - science: intToBoolState(science), - ); -} - -extension on RelaysCommand { - DBCMessage get asSetState => RelaySetStateMessage( - arm: arm.value, - frontLeftMotor: frontLeftMotor.value, - frontRightMotor: frontRightMotor.value, - backLeftMotor: backLeftMotor.value, - backRightMotor: backRightMotor.value, - drive: drive.value, - science: science.value, - ); - - List toDBC() => [asSetState]; -} - -extension on ArmMotorMoveDataMessage { - MotorData toMotorData() => MotorData( - isMoving: isMoving.armBoolState, - isLimitSwitchPressed: isLimitSwitchPressed.armBoolState, - direction: MotorDirection.valueOf(motorDirection.toInt()), - ); - - ArmData toArmProto() { - final data = ArmData(); - - if (motorValue == ArmMotor.SWIVEL.value) { - data.base = toMotorData(); - } else if (motorValue == ArmMotor.SHOULDER.value) { - data.shoulder = toMotorData(); - } else if (motorValue == ArmMotor.ELBOW.value) { - data.elbow = toMotorData(); - } - - return data; - } -} - -extension on ArmMotorStepDataMessage { - MotorData toMotorData() => MotorData( - currentStep: currentStep.toInt(), - targetStep: targetStep.toInt(), - ); - - ArmData toArmProto() { - final data = ArmData(); - - if (motorValue == ArmMotor.SWIVEL.value) { - data.base = toMotorData(); - } else if (motorValue == ArmMotor.SHOULDER.value) { - data.shoulder = toMotorData(); - } else if (motorValue == ArmMotor.ELBOW.value) { - data.elbow = toMotorData(); - } - - return data; - } -} - -extension on ArmMotorAngleDataMessage { - MotorData toMotorData() => MotorData( - currentAngle: currentAngle.toDouble(), - targetAngle: targetAngle.toDouble(), - ); - - ArmData toArmProto() { - final data = ArmData(); - - if (motorValue == ArmMotor.SWIVEL.value) { - data.base = toMotorData(); - } else if (motorValue == ArmMotor.SHOULDER.value) { - data.shoulder = toMotorData(); - } else if (motorValue == ArmMotor.ELBOW.value) { - data.elbow = toMotorData(); - } - - return data; - } -} - -extension on ArmCommand { - DBCMessage asAsSetSwivel() => ArmSetMotorMessage( - motorValue: ArmMotor.SWIVEL.value, - angle: swivel.angle, - moveRadians: swivel.moveRadians, - moveSteps: swivel.moveSteps, - ); - - DBCMessage asAsSetShoulder() => ArmSetMotorMessage( - motorValue: ArmMotor.SHOULDER.value, - angle: shoulder.angle, - moveRadians: shoulder.moveRadians, - moveSteps: shoulder.moveSteps, - ); - - DBCMessage asAsSetElbow() => ArmSetMotorMessage( - motorValue: ArmMotor.ELBOW.value, - angle: elbow.angle, - moveRadians: elbow.moveRadians, - moveSteps: elbow.moveSteps, - ); - - DBCMessage asSystemAction() => ArmSetSystemActionMessage( - stop: stop.intValue, - calibrate: calibrate.intValue, - jab: jab.intValue, - ); - - List toDBC() { - final output = []; - - if (hasSwivel()) { - output.add(asAsSetSwivel()); - } - if (hasShoulder()) { - output.add(asAsSetShoulder()); - } - if (hasElbow()) { - output.add(asAsSetElbow()); - } - - if (stop == true || calibrate == true || jab == true) { - output.add(asSystemAction()); - } - - return output; - } -} - /// A service to forward messages between CAN and UDP /// /// Simliar to the firmware service, this service will stream incoming @@ -381,13 +181,16 @@ class CanBus extends Service { bool deviceConnected(Device device) => deviceHeartbeats.containsKey(device); /// Sends the [dbcMessages] over the CAN bus only if a broadcast message has been - /// received from [device] and [override] is set to false + /// received from [device] and a heartbeat has been successfully sent + /// + /// If [forceSend] is true, it will send the message regardless of connection + /// or heartbeat status Future _sendDeviceCommand({ required Device device, required Iterable dbcMessages, - bool override = false, + bool forceSend = false, }) async { - if ((!deviceConnected(device) || !_heartbeatSendSuccessful) && !override) { + if ((!deviceConnected(device) || !_heartbeatSendSuccessful) && !forceSend) { return false; } return !(await Future.wait( @@ -395,84 +198,6 @@ class CanBus extends Service { )).contains(false); } - /// Sends a drive command over the CAN bus - /// - /// If [override] is set to false, the command will only be sent if the rover - /// has received heartbeats from the drive device. The [override] should only - /// be true if this is a stop command. - /// - /// Returs whether or not the command was sent over the bus - Future sendDriveCommand( - DriveCommand command, { - bool override = false, - }) => _sendDeviceCommand( - device: Device.DRIVE, - dbcMessages: command.toDBC(), - override: override, - ); - - /// Sends a relay command over the CAN bus - /// - /// If [override] is set to false, the command will only be sent if the rover - /// has received heartbeats from the relay device. The [override] should only - /// be true if this is a stop command. - /// - /// Returs whether or not the command was sent over the bus - Future sendRelaysCommand( - RelaysCommand command, { - bool override = false, - }) => _sendDeviceCommand( - device: Device.RELAY, - dbcMessages: command.toDBC(), - override: override, - ); - - /// Sends an arm command over the CAN bus - /// - /// If [override] is set to false, the command will only be sent if the rover - /// has received heartbeats from the arm device. The [override] should only - /// be true if this is a stop command. - /// - /// Returs whether or not the command was sent over the bus - Future sendArmCommand(ArmCommand command, {bool override = false}) => - _sendDeviceCommand( - device: Device.ARM, - dbcMessages: command.toDBC(), - override: override, - ); - - /// Sends a gripper command over the CAN bus - /// - /// If [override] is set to false, the command will only be sent if the rover - /// has received heartbeats from the gripper device. The [override] should only - /// be true if this is a stop command. - /// - /// Returs whether or not the command was sent over the bus - Future sendGripperCommand( - GripperCommand command, { - bool override = false, - }) => _sendDeviceCommand( - device: Device.GRIPPER, - dbcMessages: [], - override: override, - ); - - /// Sends a science command over the CAN bus - /// - /// If [override] is set to false, the command will only be sent if the rover - /// has received heartbeats from the science device. The [override] should only - /// be true if this is a stop command. - /// - /// Returs whether or not the command was sent over the bus - Future sendScienceCommand( - ScienceCommand command, { - bool override = false, - }) => _sendDeviceCommand( - device: Device.SCIENCE, - dbcMessages: [], - override: override, - ); - /// Sends a wrapped message over the CAN bus, returns /// whether or not the message was successfully sent Future sendWrapper(WrappedMessage message) async { @@ -493,14 +218,18 @@ class CanBus extends Service { /// Sends a message's DBC equivalent over the CAN bus /// /// Returns whether or not the message was sent over the bus - Future sendMessage(Message message) => switch (message) { - DriveCommand() => sendDriveCommand(message), - RelaysCommand() => sendRelaysCommand(message), - ArmCommand() => sendArmCommand(message), - GripperCommand() => sendGripperCommand(message), - ScienceCommand() => sendScienceCommand(message), - _ => Future.value(false), - }; + Future sendMessage(Message message) { + if (!commandToDevice.containsKey(message.messageName) || + !deviceToDBC.containsKey(message.messageName)) { + return Future.value(false); + } + final device = commandToDevice[message.messageName]!; + + return _sendDeviceCommand( + device: device, + dbcMessages: deviceToDBC[message.messageName]!.call(message), + ); + } /// Whether or not [message] can be successfully sent over the bus /// @@ -601,38 +330,10 @@ class CanBus extends Service { case CanDataFrame(:final id, :final data): if (id == DeviceBroadcastMessage().canId) { _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); - } else if (id == DriveAppliedOutputDataMessage().canId) { - collection.server.sendMessage( - DriveAppliedOutputDataMessage.decode(data).toDriveProto(), - ); - } else if (id == DriveBatteryDataMessage().canId) { - collection.server.sendMessage( - DriveBatteryDataMessage.decode(data).toDriveProto(), - ); - } else if (id == DriveLedDataMessage().canId) { - collection.server.sendMessage( - DriveLedDataMessage.decode(data).toDriveProto(), - ); - } else if (id == DriveSwivelDataMessage().canId) { - collection.server.sendMessage( - DriveSwivelDataMessage.decode(data).toDriveProto(), - ); - } else if (id == RelayStateDataMessage().canId) { - collection.server.sendMessage( - RelayStateDataMessage.decode(data).toRelayProto(), - ); - } else if (id == ArmMotorMoveDataMessage().canId) { - collection.server.sendMessage( - ArmMotorMoveDataMessage.decode(data).toArmProto(), - ); - } else if (id == ArmMotorStepDataMessage().canId) { - collection.server.sendMessage( - ArmMotorStepDataMessage.decode(data).toArmProto(), - ); - } else if (id == ArmMotorAngleDataMessage().canId) { - collection.server.sendMessage( - ArmMotorAngleDataMessage.decode(data).toArmProto(), - ); + } else if (canIDToMessage.containsKey(id)) { + collection.server.sendMessage(canIDToMessage[id]!.call(data)); + } else { + logger.warning("Received message with unmapped ID: $id"); } case CanRemoteFrame _: break; diff --git a/subsystems/lib/src/utils/dbc_conversions.dart b/subsystems/lib/src/utils/dbc_conversions.dart new file mode 100644 index 00000000..f35fea3d --- /dev/null +++ b/subsystems/lib/src/utils/dbc_conversions.dart @@ -0,0 +1,244 @@ +import "package:burt_network/protobuf.dart"; +import "package:dart_dbc_generator/dart_dbc_generator.dart"; +import "package:subsystems/src/generated/rover_messages.dbc.dart"; + +/// Utility extension to convert a boolean to an integer +extension BoolToInt on bool { + /// The booleant's integer value, where 1 represents true, and 0 represents false + int get intValue => this ? 1 : 0; +} + +/// Utility extension to convert a [BoolState] into an integer +extension BoolStateToInt on BoolState { + /// The integer value of the [BoolState], where 1 represents [BoolState.YES], + /// and 0 represents [BoolState.NO]. If the bool state is [BoolState.BOOL_UNDEFINED], + /// it is assumed to be false. + int get intValue => this == BoolState.YES ? 1 : 0; +} + +/// Utility extension to convert a [DriveAppliedOutputDataMessage] into a [DriveData] message +extension DriveAppliedOutputToProto on DriveAppliedOutputDataMessage { + /// The applied output DBC message as a [DriveData] message + DriveData toDriveProto() => DriveData( + throttle: throttle.toDouble(), + left: leftSpeed.toDouble(), + right: rightSpeed.toDouble(), + setLeft: true, + setRight: true, + setThrottle: true, + ); +} + +/// Utility extension to convert a [DriveBatteryDataMessage] into a [DriveData] message +extension DriveBatteryToProto on DriveBatteryDataMessage { + /// The battery DBC message as a [DriveData] message + DriveData toDriveProto() => DriveData( + batteryVoltage: voltage.toDouble(), + batteryTemperature: temperature.toDouble(), + batteryCurrent: current.toDouble(), + ); +} + +/// Utility extension to convert a [DriveLedDataMessage] into a [DriveData] message +extension DriveLedToProto on DriveLedDataMessage { + /// The led DBC message as a [DriveData] message + DriveData toDriveProto() => + DriveData(color: ProtoColor.valueOf(color.toInt())); +} + +/// Utility extension to convert a [DriveSwivelDataMessage] into a [DriveData] message +extension DriveSwivelToProto on DriveSwivelDataMessage { + /// The swivel DBC message as a [DriveData] message + DriveData toDriveProto() => DriveData( + frontSwivel: frontSwivel.toDouble(), + frontTilt: frontTilt.toDouble(), + rearSwivel: rearSwivel.toDouble(), + rearTilt: rearTilt.toDouble(), + ); +} + +/// Utility extension to convert a [DriveCommand] message into its respective [DBCMessage] +extension DriveCommandToDBC on DriveCommand { + /// The drive command as a [DriveSetSpeedsMessage] DBC message + DBCMessage asSetSpeeds() => DriveSetSpeedsMessage( + shouldSetLeft: setLeft.intValue, + shouldSetRight: setRight.intValue, + shouldSetThrottle: setThrottle.intValue, + leftSpeed: left, + rightSpeed: right, + throttle: throttle, + ); + + /// The drive command as a [DriveSetLedMessage] DBC message + DBCMessage asSetLEDS() => + DriveSetLedMessage(color: color.value, blink: blink.intValue); + + /// The drive command as a [DriveSetSwivelMessage] DBC message + DBCMessage asSetSwivels() => DriveSetSwivelMessage( + setFrontSwivel: hasFrontSwivel().intValue, + setFrontTilt: hasFrontTilt().intValue, + setRearSwivel: hasRearSwivel().intValue, + setRearTilt: hasRearTilt().intValue, + frontSwivel: frontSwivel, + frontTilt: frontTilt, + rearSwivel: rearSwivel, + rearTilt: rearTilt, + ); + + /// The drive command as its respective [DBCMessage] messages + List toDBC() => [ + if (setLeft || setRight || setThrottle) asSetSpeeds(), + if (hasColor() || hasBlink()) asSetLEDS(), + if (hasFrontSwivel() || hasFrontTilt() || hasRearSwivel() || hasRearTilt()) + asSetSwivels(), + ]; +} + +/// Utility extension to convert a [RelayStateDataMessage] to a +extension RelayStateToProto on RelayStateDataMessage { + BoolState _intToBoolState(num value) => + value == 1 ? BoolState.YES : BoolState.NO; + + /// The relay state DBC message as a [RelaysData] message + RelaysData toRelayProto() => RelaysData( + frontLeftMotor: _intToBoolState(frontLeftMotor), + frontRightMotor: _intToBoolState(frontRightMotor), + backLeftMotor: _intToBoolState(backLeftMotor), + backRightMotor: _intToBoolState(backRightMotor), + arm: _intToBoolState(arm), + drive: _intToBoolState(drive), + science: _intToBoolState(science), + ); +} + +/// Utility extension to convert a [RelaysCommand] command into its respective [DBCMessage] +extension RelaysCommandToDBC on RelaysCommand { + /// The relays command as a [RelaySetStateMessage] DBC message + DBCMessage asSetState() => RelaySetStateMessage( + arm: arm.value, + frontLeftMotor: frontLeftMotor.value, + frontRightMotor: frontRightMotor.value, + backLeftMotor: backLeftMotor.value, + backRightMotor: backRightMotor.value, + drive: drive.value, + science: science.value, + ); + + /// The relays command as its respective [DBCMessage] messages + List toDBC() => [asSetState()]; +} + +/// Utility extension to convert an [ArmMotorMoveDataMessage] into a [ArmData] message +extension ArmMotorMoveToProto on ArmMotorMoveDataMessage { + /// The arm motor move data as a [MotorData] message + MotorData toMotorData() => MotorData( + isMoving: BoolState.valueOf(isMoving.toInt()), + isLimitSwitchPressed: BoolState.valueOf(isLimitSwitchPressed.toInt()), + direction: MotorDirection.valueOf(motorDirection.toInt()), + ); + + /// The arm motor move data as an [ArmData] message + ArmData toArmProto() { + final data = ArmData(); + + if (motorValue == ArmMotor.SWIVEL.value) { + data.base = toMotorData(); + } else if (motorValue == ArmMotor.SHOULDER.value) { + data.shoulder = toMotorData(); + } else if (motorValue == ArmMotor.ELBOW.value) { + data.elbow = toMotorData(); + } + + return data; + } +} + +/// Utility extension to convert a [ArmMotorStepDataMessage] into a [DriveData] message +extension ArmMotorStepToProto on ArmMotorStepDataMessage { + /// The motor steps DBC message as a [MotorData] message + MotorData toMotorData() => MotorData( + currentStep: currentStep.toInt(), + targetStep: targetStep.toInt(), + ); + + /// The motor steps DBC message as a [MotorData] message + ArmData toArmProto() { + final data = ArmData(); + + if (motorValue == ArmMotor.SWIVEL.value) { + data.base = toMotorData(); + } else if (motorValue == ArmMotor.SHOULDER.value) { + data.shoulder = toMotorData(); + } else if (motorValue == ArmMotor.ELBOW.value) { + data.elbow = toMotorData(); + } + + return data; + } +} + +/// Utility extension to convert a [ArmMotorAngleDataMessage] into a [ArmMotor] message +extension ArmMotorAngleToProto on ArmMotorAngleDataMessage { + /// The motor angle DBC message as a [MotorData] message + MotorData toMotorData() => MotorData( + currentAngle: currentAngle.toDouble(), + targetAngle: targetAngle.toDouble(), + ); + + /// The motor angle DBC message as an [ArmData] message + ArmData toArmProto() { + final data = ArmData(); + + if (motorValue == ArmMotor.SWIVEL.value) { + data.base = toMotorData(); + } else if (motorValue == ArmMotor.SHOULDER.value) { + data.shoulder = toMotorData(); + } else if (motorValue == ArmMotor.ELBOW.value) { + data.elbow = toMotorData(); + } + + return data; + } +} + +/// Utility extension to convert a [ArmCommand] message into its respective [DBCMessage] equivalents +extension ArmCommandToDBC on ArmCommand { + /// The arm command as a [ArmSetMotorMessage] DBC message + DBCMessage asSetSwivel() => ArmSetMotorMessage( + motorValue: ArmMotor.SWIVEL.value, + angle: swivel.angle, + moveRadians: swivel.moveRadians, + moveSteps: swivel.moveSteps, + ); + + /// The arm command as a [ArmSetMotorMessage] DBC message for the shoulder + DBCMessage asSetShoulder() => ArmSetMotorMessage( + motorValue: ArmMotor.SHOULDER.value, + angle: shoulder.angle, + moveRadians: shoulder.moveRadians, + moveSteps: shoulder.moveSteps, + ); + + /// The arm command as a [ArmSetMotorMessage] DBC message for the elbow + DBCMessage asSetElbow() => ArmSetMotorMessage( + motorValue: ArmMotor.ELBOW.value, + angle: elbow.angle, + moveRadians: elbow.moveRadians, + moveSteps: elbow.moveSteps, + ); + + /// The arm command as a [ArmSetSystemActionMessage] DBC message + DBCMessage asSystemAction() => ArmSetSystemActionMessage( + stop: stop.intValue, + calibrate: calibrate.intValue, + jab: jab.intValue, + ); + + /// The arm command as its respective [DBCMessage] messages + List toDBC() => [ + if (hasSwivel()) asSetSwivel(), + if (hasShoulder()) asSetShoulder(), + if (hasElbow()) asSetElbow(), + if (hasStop() || hasCalibrate() || hasJab()) asSystemAction(), + ]; +} From 86b46a3407fdbf83c5c674414f46ba506a8c5fdf Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Thu, 31 Jul 2025 21:25:19 -0400 Subject: [PATCH 26/30] Better logging and error handling --- subsystems/lib/src/devices/can_bus.dart | 129 ++++++++++++++---------- 1 file changed, 78 insertions(+), 51 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index e0a30952..e3fc56ea 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -79,6 +79,9 @@ extension on DeviceBroadcastMessage { /// rover, and so the rover can determine every device connected, and their /// firmware versions. class CanBus extends Service { + /// The CAN interface to send messages on + static const String canInterface = "can0"; + /// How often to send a rover heartbeat over the CAN bus static const Duration heartbeatPeriod = Duration(milliseconds: 100); @@ -100,51 +103,37 @@ class CanBus extends Service { Timer? _sendHeartbeatTimer; Timer? _checkHeartbeatsTimer; - bool _shouldReset = false; bool _heartbeatSendSuccessful = false; StreamSubscription? _frameSubscription; + Future? _resetFuture; + @override Future init() async { if (Platform.isWindows) { return true; } - await Process.run("sudo", ["ip", "link", "set", "can0", "down"]); - await Process.run("sudo", [ - "ip", - "link", - "set", - "can0", - "type", - "can", - "bitrate", - "500000", - ]); - final upResult = await Process.run("sudo", [ - "ip", - "link", - "set", - "can0", - "up", - ]); - if (upResult.exitCode != 0) { - logger.error("Could not set Can0 up", body: upResult.stderr); + + if (!await bringUpCAN(canInterface)) { return false; } try { device = LinuxCan.instance.devices.singleWhere( - (device) => device.networkInterface.name == "can0", + (device) => device.networkInterface.name == canInterface, ); } catch (e) { if (e is StateError) { - logger.error("No CAN Interface found named can0"); + logger.error("No CAN interface found named $canInterface"); return false; } rethrow; } if (!device!.isUp) { - logger.error("CAN0 is not up", body: "Device state: ${device!.state}"); + logger.error( + "$canInterface is not up", + body: "Device state: ${device!.state}", + ); return false; } logger.info( @@ -176,6 +165,39 @@ class CanBus extends Service { deviceHeartbeats.clear(); } + /// Initializes and brings up the CAN interface named [interfaceName] + /// + /// Returns whether or not the device was successfully brought up. + Future bringUpCAN(String interfaceName) async { + await Process.run("sudo", ["ip", "link", "set", interfaceName, "down"]); + await Process.run("sudo", [ + "ip", + "link", + "set", + interfaceName, + "type", + "can", + "bitrate", + "500000", + "restart-ms", + "100", + ]); + final upResult = await Process.run("sudo", [ + "ip", + "link", + "set", + interfaceName, + "up", + ]); + + if (upResult.exitCode != 0) { + logger.error("Could not set $canInterface up", body: upResult.stderr); + return false; + } + + return true; + } + /// Whether or not a broadcast message has been received from [device] within /// the past [heartbeatTimeout] amount of time bool deviceConnected(Device device) => deviceHeartbeats.containsKey(device); @@ -247,13 +269,6 @@ class CanBus extends Service { /// Sends a heartbeat message over the CAN bus Future sendHeartbeat() async { - if (_shouldReset) { - await dispose(); - await Future.delayed(const Duration(milliseconds: 1000)); - await init(); - _shouldReset = false; - return false; - } final heartbeat = RoverHeartbeatMessage(); return _heartbeatSendSuccessful = await sendDBCMessage(heartbeat); } @@ -277,32 +292,44 @@ class CanBus extends Service { /// /// Returns whether or not the message was successfully sent Future sendDBCMessage(DBCMessage message) async { - if (socket == null) { + if (socket == null || device == null || _resetFuture != null) { return false; } - if (!(device?.isUp ?? true)) { + + if (!device!.isUp) { logger.warning( - "Device is not up while trying to send message, restarting CAN socket", + "Device is not up while trying to send message", + body: "Restarting CAN interface", + ); + _resetFuture ??= Future(() async { + if (await bringUpCAN(canInterface)) { + // Wait a small amount after bringing up the device, for + // some reason device.isUp returns false for a short period + // of time after + await Future.delayed(const Duration(milliseconds: 100)); + } + }).whenComplete(() => _resetFuture = null); + return false; + } + + if (device!.state == CanState.busOff) { + logger.warning("Cannot send message, bus is off"); + return false; + } + + try { + await socket?.send( + CanFrame.standard(id: message.canId, data: message.encode()), ); - _shouldReset = true; + return true; + } catch (error) { + if (error.toString().contains("No buffer space")) { + logger.debug("Error when sending CAN message", body: error.toString()); + } else { + logger.error("Error when sending CAN message", body: error.toString()); + } return false; } - var success = true; - await socket - ?.send(CanFrame.standard(id: message.canId, data: message.encode())) - .catchError((Object e) { - success = false; - if (e.toString().contains("No buffer space")) { - logger.debug("Error when sending CAN message", body: e.toString()); - } else { - logger.error("Error when sending CAN message", body: e.toString()); - } - - if (!(device?.isUp ?? true)) { - _shouldReset = true; - } - }); - return success; } void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { From e430b04e1702da1ede92479fb0a849938637e85d Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Thu, 28 Aug 2025 16:02:03 -0400 Subject: [PATCH 27/30] Added support for drive motor data messages --- subsystems/lib/src/devices/can_bus.dart | 20 ++- .../lib/src/generated/rover_messages.dbc.dart | 162 +++++++++--------- subsystems/lib/src/utils/dbc_conversions.dart | 33 ++++ 3 files changed, 128 insertions(+), 87 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index e3fc56ea..879ea018 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -28,6 +28,8 @@ final Map data)> canIDToMessage = { DriveLedDataMessage.decode(data).toDriveProto(), DriveSwivelDataMessage().canId: (data) => DriveSwivelDataMessage.decode(data).toDriveProto(), + DriveMotorDataMessage().canId: (data) => + DriveMotorDataMessage.decode(data).toDriveProto(), RelayStateDataMessage().canId: (data) => RelayStateDataMessage.decode(data).toRelayProto(), ArmMotorMoveDataMessage().canId: (data) => @@ -50,15 +52,15 @@ extension on DeviceBroadcastMessage { Message toScienceProto() => ScienceData(version: version); Message? toProtoMessage() { - if (deviceValue.toInt() == Device.DRIVE.value) { + if (deviceValue == Device.DRIVE.value) { return toDriveProto(); - } else if (deviceValue.toInt() == Device.RELAY.value) { + } else if (deviceValue == Device.RELAY.value) { return toRelayProto(); - } else if (deviceValue.toInt() == Device.ARM.value) { + } else if (deviceValue == Device.ARM.value) { return toArmProto(); - } else if (deviceValue.toInt() == Device.GRIPPER.value) { + } else if (deviceValue == Device.GRIPPER.value) { return toGripperProto(); - } else if (deviceValue.toInt() == Device.SCIENCE.value) { + } else if (deviceValue == Device.SCIENCE.value) { return toScienceProto(); } return null; @@ -157,9 +159,13 @@ class CanBus extends Service { _sendHeartbeatTimer?.cancel(); _checkHeartbeatsTimer?.cancel(); + _heartbeatSendSuccessful = false; + await socket?.close(); socket = null; + device = null; + await _frameSubscription?.cancel(); deviceHeartbeats.clear(); @@ -360,7 +366,9 @@ class CanBus extends Service { } else if (canIDToMessage.containsKey(id)) { collection.server.sendMessage(canIDToMessage[id]!.call(data)); } else { - logger.warning("Received message with unmapped ID: $id"); + logger.warning( + "Received message with unmapped ID: 0x${id.toRadixString(16).padLeft(2, '0')}", + ); } case CanRemoteFrame _: break; diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 9df5aa08..0c3fbc28 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -1507,7 +1507,7 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { String messageName = 'Drive_Motor_Data'; @override - int messageLength = 8; + int messageLength = 6; @override int canId = 0x19; @@ -1521,17 +1521,17 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { /// Value of signal "Motor_Value" num motorValue; - /// Value of signal "Motor_Position" - num motorPosition; + /// Value of signal "Speed" + num speed; - /// Value of signal "Motor_Speed" - num motorSpeed; + /// Value of signal "Current" + num current; - /// Value of signal "Motor_Current" - num motorCurrent; + /// Value of signal "Temperature" + num temperature; - /// Value of signal "Motor_Temperature" - num motorTemperature; + /// Value of signal "Error_Code" + num errorCode; final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( name: 'Motor_Value', @@ -1541,7 +1541,7 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { multiplexGroup: -1, start: 0, length: 3, - mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], factor: 1, offset: 0, @@ -1550,33 +1550,16 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { unit: '', ); - final $_dbc.DBCSignal _motorPositionSignal = $_dbc.DBCSignal( - name: 'Motor_Position', + final $_dbc.DBCSignal _speedSignal = $_dbc.DBCSignal( + name: 'Speed', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, start: 3, length: 16, - mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], - factor: 0.1, - offset: 0, - min: -3200, - max: 3200, - unit: '°', - ); - - final $_dbc.DBCSignal _motorSpeedSignal = $_dbc.DBCSignal( - name: 'Motor_Speed', - signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, - start: 19, - length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], factor: 10, offset: 0, min: -320000, @@ -1584,16 +1567,16 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { unit: 'RPM', ); - final $_dbc.DBCSignal _motorCurrentSignal = $_dbc.DBCSignal( - name: 'Motor_Current', + final $_dbc.DBCSignal _currentSignal = $_dbc.DBCSignal( + name: 'Current', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 35, + start: 19, length: 16, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], factor: 0.01, offset: 0, min: -60, @@ -1601,16 +1584,16 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { unit: 'A', ); - final $_dbc.DBCSignal _motorTemperatureSignal = $_dbc.DBCSignal( - name: 'Motor_Temperature', + final $_dbc.DBCSignal _temperatureSignal = $_dbc.DBCSignal( + name: 'Temperature', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, multiplexGroup: -1, - start: 51, + start: 35, length: 8, - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0], - mappingIndexes: [51, 52, 53, 54, 55, 56, 57, 58], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0], + mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42], factor: 1, offset: 0, min: -20, @@ -1618,36 +1601,53 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { unit: '°C', ); + final $_dbc.DBCSignal _errorCodeSignal = $_dbc.DBCSignal( + name: 'Error_Code', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + multiplexGroup: -1, + start: 43, + length: 3, + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 0, 0], + mappingIndexes: [43, 44, 45], + factor: 1, + offset: 0, + min: 0, + max: 7, + unit: '', + ); + @override List<$_dbc.DBCSignal> get signals => [ _motorValueSignal, - _motorPositionSignal, - _motorSpeedSignal, - _motorCurrentSignal, - _motorTemperatureSignal, + _speedSignal, + _currentSignal, + _temperatureSignal, + _errorCodeSignal, ]; DriveMotorDataMessage({ this.motorValue = 0, - this.motorPosition = 0, - this.motorSpeed = 0, - this.motorCurrent = 0, - this.motorTemperature = 0, + this.speed = 0, + this.current = 0, + this.temperature = 0, + this.errorCode = 0, }); /// Creates a clone of this [DriveMotorDataMessage] with the non-null values replaced DriveMotorDataMessage copyWith({ num? motorValue, - num? motorPosition, - num? motorSpeed, - num? motorCurrent, - num? motorTemperature, + num? speed, + num? current, + num? temperature, + num? errorCode, }) => DriveMotorDataMessage( motorValue: motorValue ?? this.motorValue, - motorPosition: motorPosition ?? this.motorPosition, - motorSpeed: motorSpeed ?? this.motorSpeed, - motorCurrent: motorCurrent ?? this.motorCurrent, - motorTemperature: motorTemperature ?? this.motorTemperature, + speed: speed ?? this.speed, + current: current ?? this.current, + temperature: temperature ?? this.temperature, + errorCode: errorCode ?? this.errorCode, ); factory DriveMotorDataMessage.decode(List payload) { @@ -1658,18 +1658,18 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { message.motorValue = message._motorValueSignal.decode(bitField) ?? $_math.max(0, message._motorValueSignal.min); - message.motorPosition = - message._motorPositionSignal.decode(bitField) ?? - $_math.max(0, message._motorPositionSignal.min); - message.motorSpeed = - message._motorSpeedSignal.decode(bitField) ?? - $_math.max(0, message._motorSpeedSignal.min); - message.motorCurrent = - message._motorCurrentSignal.decode(bitField) ?? - $_math.max(0, message._motorCurrentSignal.min); - message.motorTemperature = - message._motorTemperatureSignal.decode(bitField) ?? - $_math.max(0, message._motorTemperatureSignal.min); + message.speed = + message._speedSignal.decode(bitField) ?? + $_math.max(0, message._speedSignal.min); + message.current = + message._currentSignal.decode(bitField) ?? + $_math.max(0, message._currentSignal.min); + message.temperature = + message._temperatureSignal.decode(bitField) ?? + $_math.max(0, message._temperatureSignal.min); + message.errorCode = + message._errorCodeSignal.decode(bitField) ?? + $_math.max(0, message._errorCodeSignal.min); return message; } @@ -1677,20 +1677,20 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { factory DriveMotorDataMessage.fromJson(Map json) => DriveMotorDataMessage( motorValue: json['Motor_Value'] ?? 0, - motorPosition: json['Motor_Position'] ?? 0, - motorSpeed: json['Motor_Speed'] ?? 0, - motorCurrent: json['Motor_Current'] ?? 0, - motorTemperature: json['Motor_Temperature'] ?? 0, + speed: json['Speed'] ?? 0, + current: json['Current'] ?? 0, + temperature: json['Temperature'] ?? 0, + errorCode: json['Error_Code'] ?? 0, ); @override $_typed.Uint8List encode() { final Map<$_dbc.DBCSignal, num> values = { _motorValueSignal: motorValue, - _motorPositionSignal: motorPosition, - _motorSpeedSignal: motorSpeed, - _motorCurrentSignal: motorCurrent, - _motorTemperatureSignal: motorTemperature, + _speedSignal: speed, + _currentSignal: current, + _temperatureSignal: temperature, + _errorCodeSignal: errorCode, }; return encodeWithValues(values); @@ -1699,15 +1699,15 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { @override Map toJson() => { 'Motor_Value': motorValue, - 'Motor_Position': motorPosition, - 'Motor_Speed': motorSpeed, - 'Motor_Current': motorCurrent, - 'Motor_Temperature': motorTemperature, + 'Speed': speed, + 'Current': current, + 'Temperature': temperature, + 'Error_Code': errorCode, }; @override String toString() { - return 'Drive_Motor_Data(\n Motor_Value=$motorValue\n Motor_Position=$motorPosition\n Motor_Speed=$motorSpeed\n Motor_Current=$motorCurrent\n Motor_Temperature=$motorTemperature\n)'; + return 'Drive_Motor_Data(\n Motor_Value=$motorValue\n Speed=$speed\n Current=$current\n Temperature=$temperature\n Error_Code=$errorCode\n)'; } } diff --git a/subsystems/lib/src/utils/dbc_conversions.dart b/subsystems/lib/src/utils/dbc_conversions.dart index f35fea3d..a8172751 100644 --- a/subsystems/lib/src/utils/dbc_conversions.dart +++ b/subsystems/lib/src/utils/dbc_conversions.dart @@ -57,6 +57,39 @@ extension DriveSwivelToProto on DriveSwivelDataMessage { ); } +/// Utility extension to convert a [DriveMotorDataMessage] into a [DriveData] message +extension DriveMotorToProto on DriveMotorDataMessage { + /// The drive motor data as a [DriveMotorData] message + DriveMotorData toMotorData() => DriveMotorData( + speed: speed.toDouble(), + current: current.toDouble(), + temperature: temperature.toInt(), + error: MotorErrorCode.valueOf(errorCode.toInt()), + ); + + /// The drive motor data as a [DriveData] message + DriveData toDriveProto() { + final data = DriveData(); + final motorData = toMotorData(); + + if (motorValue == DriveMotor.FRONT_LEFT.value) { + data.frontLeftMotor = motorData; + } else if (motorValue == DriveMotor.MIDDLE_LEFT.value) { + data.middleLeftMotor = motorData; + } else if (motorValue == DriveMotor.BACK_LEFT.value) { + data.backLeftMotor = motorData; + } else if (motorValue == DriveMotor.FRONT_RIGHT.value) { + data.frontRightMotor = motorData; + } else if (motorValue == DriveMotor.MIDDLE_RIGHT.value) { + data.middleRightMotor = motorData; + } else if (motorValue == DriveMotor.BACK_RIGHT.value) { + data.backRightMotor = motorData; + } + + return data; + } +} + /// Utility extension to convert a [DriveCommand] message into its respective [DBCMessage] extension DriveCommandToDBC on DriveCommand { /// The drive command as a [DriveSetSpeedsMessage] DBC message From dd3531e16901698e0849661cb7c0f59e2a82d025 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Thu, 28 Aug 2025 21:02:54 -0400 Subject: [PATCH 28/30] Regenerate DBC files updated dbc generator --- subsystems/lib/src/devices/can_bus.dart | 7 +- .../lib/src/generated/rover_messages.dbc.dart | 1033 ++++++++--------- subsystems/lib/src/utils/dbc_conversions.dart | 44 +- 3 files changed, 514 insertions(+), 570 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 879ea018..feb92eb1 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -66,8 +66,7 @@ extension on DeviceBroadcastMessage { return null; } - Version get version => - Version(major: fwVersionMajor.toInt(), minor: fwVersionMinor.toInt()); + Version get version => Version(major: fwVersionMajor, minor: fwVersionMinor); } /// A service to forward messages between CAN and UDP @@ -339,11 +338,11 @@ class CanBus extends Service { } void _handleDeviceBroadcast(DeviceBroadcastMessage broadcast) { - final device = Device.valueOf(broadcast.deviceValue.toInt()); + final device = Device.valueOf(broadcast.deviceValue); if (device == null) { logger.warning( "Unknown Device Number", - body: "Received broadcast from device ${broadcast.deviceValue.toInt()}", + body: "Received broadcast from device ${broadcast.deviceValue}", ); return; } diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 0c3fbc28..90a2a42f 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -6,7 +6,6 @@ // ignore_for_file: non_constant_identifier_names, prefer_final_fields // ignore_for_file: unnecessary_import, unnecessary_this, unused_import -import 'dart:math' as $_math; import 'dart:typed_data' as $_typed; import 'package:dart_dbc_generator/dart_dbc_generator.dart' as $_dbc; @@ -28,18 +27,19 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Rover_Status" - num roverStatus; + int roverStatus; final $_dbc.DBCSignal _roverStatusSignal = $_dbc.DBCSignal( name: 'Rover_Status', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 4, + // dart format off mapping: [1, 2, 4, 8, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3], + // dart format on factor: 1, offset: 0, min: 0, @@ -48,56 +48,42 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { ); @override - List<$_dbc.DBCSignal> get signals => [ - _roverStatusSignal, - ]; + List<$_dbc.DBCSignal> get signals => [_roverStatusSignal]; - RoverHeartbeatMessage({ - this.roverStatus = 0, - }); + RoverHeartbeatMessage({this.roverStatus = 0}); /// Creates a clone of this [RoverHeartbeatMessage] with the non-null values replaced - RoverHeartbeatMessage copyWith({ - num? roverStatus, - }) => RoverHeartbeatMessage( - roverStatus: roverStatus ?? this.roverStatus, - ); + RoverHeartbeatMessage copyWith({int? roverStatus}) => + RoverHeartbeatMessage(roverStatus: roverStatus ?? this.roverStatus); factory RoverHeartbeatMessage.decode(List payload) { final message = RoverHeartbeatMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); - message.roverStatus = - message._roverStatusSignal.decode(bitField) ?? - $_math.max(0, message._roverStatusSignal.min); + message.roverStatus = (message._roverStatusSignal.decode(bitField) ?? 0) + .toInt(); return message; } factory RoverHeartbeatMessage.fromJson(Map json) => - RoverHeartbeatMessage( - roverStatus: json['Rover_Status'] ?? 0, - ); + RoverHeartbeatMessage(roverStatus: json['Rover_Status'] ?? 0); @override $_typed.Uint8List encode() { - final Map<$_dbc.DBCSignal, num> values = { - _roverStatusSignal: roverStatus, - }; + final Map<$_dbc.DBCSignal, num> values = {_roverStatusSignal: roverStatus}; return encodeWithValues(values); } @override - Map toJson() => { - 'Rover_Status': roverStatus, - }; + Map toJson() => {'Rover_Status': roverStatus}; @override - String toString() { - return 'Rover_Heartbeat(\n Rover_Status=$roverStatus\n)'; - } + String toString() => 'Rover_Heartbeat(\n Rover_Status=$roverStatus\n)'; } class DeviceBroadcastMessage extends $_dbc.DBCMessage { @@ -117,24 +103,25 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Device_Value" - num deviceValue; + int deviceValue; /// Value of signal "FW_Version_Major" - num fwVersionMajor; + int fwVersionMajor; /// Value of signal "FW_Version_Minor" - num fwVersionMinor; + int fwVersionMinor; final $_dbc.DBCSignal _deviceValueSignal = $_dbc.DBCSignal( name: 'Device_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 5, + // dart format off mapping: [1, 2, 4, 8, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4], + // dart format on factor: 1, offset: 0, min: 0, @@ -147,11 +134,12 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 5, length: 4, + // dart format off mapping: [0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [5, 6, 7, 8], + // dart format on factor: 1, offset: 0, min: 1, @@ -164,11 +152,12 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 9, length: 4, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0], mappingIndexes: [9, 10, 11, 12], + // dart format on factor: 1, offset: 0, min: 0, @@ -191,9 +180,9 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DeviceBroadcastMessage] with the non-null values replaced DeviceBroadcastMessage copyWith({ - num? deviceValue, - num? fwVersionMajor, - num? fwVersionMinor, + int? deviceValue, + int? fwVersionMajor, + int? fwVersionMinor, }) => DeviceBroadcastMessage( deviceValue: deviceValue ?? this.deviceValue, fwVersionMajor: fwVersionMajor ?? this.fwVersionMajor, @@ -203,17 +192,16 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { factory DeviceBroadcastMessage.decode(List payload) { final message = DeviceBroadcastMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); - message.deviceValue = - message._deviceValueSignal.decode(bitField) ?? - $_math.max(0, message._deviceValueSignal.min); + message.deviceValue = (message._deviceValueSignal.decode(bitField) ?? 0) + .toInt(); message.fwVersionMajor = - message._fwVersionMajorSignal.decode(bitField) ?? - $_math.max(0, message._fwVersionMajorSignal.min); + (message._fwVersionMajorSignal.decode(bitField) ?? 1).toInt(); message.fwVersionMinor = - message._fwVersionMinorSignal.decode(bitField) ?? - $_math.max(0, message._fwVersionMinorSignal.min); + (message._fwVersionMinorSignal.decode(bitField) ?? 0).toInt(); return message; } @@ -244,9 +232,8 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Device_Broadcast(\n Device_Value=$deviceValue\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)'; - } + String toString() => + 'Device_Broadcast(\n Device_Value=$deviceValue\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)'; } class DriveSetSpeedsMessage extends $_dbc.DBCMessage { @@ -266,33 +253,34 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Should_Set_Left" - num shouldSetLeft; + int shouldSetLeft; /// Value of signal "Should_Set_Right" - num shouldSetRight; + int shouldSetRight; /// Value of signal "Should_Set_Throttle" - num shouldSetThrottle; + int shouldSetThrottle; /// Value of signal "Left_Speed" - num leftSpeed; + double leftSpeed; /// Value of signal "Right_Speed" - num rightSpeed; + double rightSpeed; /// Value of signal "Throttle" - num throttle; + double throttle; final $_dbc.DBCSignal _shouldSetLeftSignal = $_dbc.DBCSignal( name: 'Should_Set_Left', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 1, + // dart format off mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], + // dart format on factor: 1, offset: 0, min: 0, @@ -305,11 +293,12 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 1, length: 1, + // dart format off mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], + // dart format on factor: 1, offset: 0, min: 0, @@ -322,11 +311,12 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 2, length: 1, + // dart format off mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [2], + // dart format on factor: 1, offset: 0, min: 0, @@ -339,11 +329,12 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 16, + // dart format off mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], + // dart format on factor: 0.000062, offset: 0, min: -1, @@ -356,11 +347,12 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 19, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], + // dart format on factor: 0.000062, offset: 0, min: -1, @@ -373,11 +365,12 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 35, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], + // dart format on factor: 0.000016, offset: 0, min: 0, @@ -406,12 +399,12 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DriveSetSpeedsMessage] with the non-null values replaced DriveSetSpeedsMessage copyWith({ - num? shouldSetLeft, - num? shouldSetRight, - num? shouldSetThrottle, - num? leftSpeed, - num? rightSpeed, - num? throttle, + int? shouldSetLeft, + int? shouldSetRight, + int? shouldSetThrottle, + double? leftSpeed, + double? rightSpeed, + double? throttle, }) => DriveSetSpeedsMessage( shouldSetLeft: shouldSetLeft ?? this.shouldSetLeft, shouldSetRight: shouldSetRight ?? this.shouldSetRight, @@ -424,26 +417,22 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { factory DriveSetSpeedsMessage.decode(List payload) { final message = DriveSetSpeedsMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); - message.shouldSetLeft = - message._shouldSetLeftSignal.decode(bitField) ?? - $_math.max(0, message._shouldSetLeftSignal.min); + message.shouldSetLeft = (message._shouldSetLeftSignal.decode(bitField) ?? 0) + .toInt(); message.shouldSetRight = - message._shouldSetRightSignal.decode(bitField) ?? - $_math.max(0, message._shouldSetRightSignal.min); + (message._shouldSetRightSignal.decode(bitField) ?? 0).toInt(); message.shouldSetThrottle = - message._shouldSetThrottleSignal.decode(bitField) ?? - $_math.max(0, message._shouldSetThrottleSignal.min); - message.leftSpeed = - message._leftSpeedSignal.decode(bitField) ?? - $_math.max(0, message._leftSpeedSignal.min); - message.rightSpeed = - message._rightSpeedSignal.decode(bitField) ?? - $_math.max(0, message._rightSpeedSignal.min); - message.throttle = - message._throttleSignal.decode(bitField) ?? - $_math.max(0, message._throttleSignal.min); + (message._shouldSetThrottleSignal.decode(bitField) ?? 0).toInt(); + message.leftSpeed = (message._leftSpeedSignal.decode(bitField) ?? 0) + .toDouble(); + message.rightSpeed = (message._rightSpeedSignal.decode(bitField) ?? 0) + .toDouble(); + message.throttle = (message._throttleSignal.decode(bitField) ?? 0) + .toDouble(); return message; } @@ -483,9 +472,8 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Drive_Set_Speeds(\n Should_Set_Left=$shouldSetLeft\n Should_Set_Right=$shouldSetRight\n Should_Set_Throttle=$shouldSetThrottle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n Throttle=$throttle\n)'; - } + String toString() => + 'Drive_Set_Speeds(\n Should_Set_Left=$shouldSetLeft\n Should_Set_Right=$shouldSetRight\n Should_Set_Throttle=$shouldSetThrottle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n Throttle=$throttle\n)'; } class DriveSetLedMessage extends $_dbc.DBCMessage { @@ -505,21 +493,22 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Color" - num color; + int color; /// Value of signal "Blink" - num blink; + int blink; final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( name: 'Color', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 4, + // dart format off mapping: [1, 2, 4, 8, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3], + // dart format on factor: 1, offset: 0, min: 0, @@ -532,11 +521,12 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 4, length: 1, + // dart format off mapping: [0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [4], + // dart format on factor: 1, offset: 0, min: 0, @@ -545,21 +535,12 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { ); @override - List<$_dbc.DBCSignal> get signals => [ - _colorSignal, - _blinkSignal, - ]; + List<$_dbc.DBCSignal> get signals => [_colorSignal, _blinkSignal]; - DriveSetLedMessage({ - this.color = 0, - this.blink = 0, - }); + DriveSetLedMessage({this.color = 0, this.blink = 0}); /// Creates a clone of this [DriveSetLedMessage] with the non-null values replaced - DriveSetLedMessage copyWith({ - num? color, - num? blink, - }) => DriveSetLedMessage( + DriveSetLedMessage copyWith({int? color, int? blink}) => DriveSetLedMessage( color: color ?? this.color, blink: blink ?? this.blink, ); @@ -567,23 +548,18 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { factory DriveSetLedMessage.decode(List payload) { final message = DriveSetLedMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); - message.color = - message._colorSignal.decode(bitField) ?? - $_math.max(0, message._colorSignal.min); - message.blink = - message._blinkSignal.decode(bitField) ?? - $_math.max(0, message._blinkSignal.min); + message.color = (message._colorSignal.decode(bitField) ?? 0).toInt(); + message.blink = (message._blinkSignal.decode(bitField) ?? 0).toInt(); return message; } factory DriveSetLedMessage.fromJson(Map json) => - DriveSetLedMessage( - color: json['Color'] ?? 0, - blink: json['Blink'] ?? 0, - ); + DriveSetLedMessage(color: json['Color'] ?? 0, blink: json['Blink'] ?? 0); @override $_typed.Uint8List encode() { @@ -596,15 +572,10 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { } @override - Map toJson() => { - 'Color': color, - 'Blink': blink, - }; + Map toJson() => {'Color': color, 'Blink': blink}; @override - String toString() { - return 'Drive_Set_LED(\n Color=$color\n Blink=$blink\n)'; - } + String toString() => 'Drive_Set_LED(\n Color=$color\n Blink=$blink\n)'; } class DriveSetSwivelMessage extends $_dbc.DBCMessage { @@ -624,39 +595,40 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Set_Front_Swivel" - num setFrontSwivel; + int setFrontSwivel; /// Value of signal "Set_Front_Tilt" - num setFrontTilt; + int setFrontTilt; /// Value of signal "Set_Rear_Swivel" - num setRearSwivel; + int setRearSwivel; /// Value of signal "Set_Rear_Tilt" - num setRearTilt; + int setRearTilt; /// Value of signal "Front_Swivel" - num frontSwivel; + double frontSwivel; /// Value of signal "Front_Tilt" - num frontTilt; + double frontTilt; /// Value of signal "Rear_Swivel" - num rearSwivel; + double rearSwivel; /// Value of signal "Rear_Tilt" - num rearTilt; + double rearTilt; final $_dbc.DBCSignal _setFrontSwivelSignal = $_dbc.DBCSignal( name: 'Set_Front_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 1, + // dart format off mapping: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], + // dart format on factor: 1, offset: 0, min: 0, @@ -669,11 +641,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 1, length: 1, + // dart format off mapping: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], + // dart format on factor: 1, offset: 0, min: 0, @@ -686,11 +659,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 2, length: 1, + // dart format off mapping: [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [2], + // dart format on factor: 1, offset: 0, min: 0, @@ -703,11 +677,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 1, + // dart format off mapping: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3], + // dart format on factor: 1, offset: 0, min: 0, @@ -720,11 +695,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 4, length: 12, + // dart format off mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -737,11 +713,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 16, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -754,11 +731,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 28, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -771,11 +749,12 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 40, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0], mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -808,14 +787,14 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DriveSetSwivelMessage] with the non-null values replaced DriveSetSwivelMessage copyWith({ - num? setFrontSwivel, - num? setFrontTilt, - num? setRearSwivel, - num? setRearTilt, - num? frontSwivel, - num? frontTilt, - num? rearSwivel, - num? rearTilt, + int? setFrontSwivel, + int? setFrontTilt, + int? setRearSwivel, + int? setRearTilt, + double? frontSwivel, + double? frontTilt, + double? rearSwivel, + double? rearTilt, }) => DriveSetSwivelMessage( setFrontSwivel: setFrontSwivel ?? this.setFrontSwivel, setFrontTilt: setFrontTilt ?? this.setFrontTilt, @@ -830,32 +809,26 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { factory DriveSetSwivelMessage.decode(List payload) { final message = DriveSetSwivelMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); message.setFrontSwivel = - message._setFrontSwivelSignal.decode(bitField) ?? - $_math.max(0, message._setFrontSwivelSignal.min); - message.setFrontTilt = - message._setFrontTiltSignal.decode(bitField) ?? - $_math.max(0, message._setFrontTiltSignal.min); - message.setRearSwivel = - message._setRearSwivelSignal.decode(bitField) ?? - $_math.max(0, message._setRearSwivelSignal.min); - message.setRearTilt = - message._setRearTiltSignal.decode(bitField) ?? - $_math.max(0, message._setRearTiltSignal.min); - message.frontSwivel = - message._frontSwivelSignal.decode(bitField) ?? - $_math.max(0, message._frontSwivelSignal.min); - message.frontTilt = - message._frontTiltSignal.decode(bitField) ?? - $_math.max(0, message._frontTiltSignal.min); - message.rearSwivel = - message._rearSwivelSignal.decode(bitField) ?? - $_math.max(0, message._rearSwivelSignal.min); - message.rearTilt = - message._rearTiltSignal.decode(bitField) ?? - $_math.max(0, message._rearTiltSignal.min); + (message._setFrontSwivelSignal.decode(bitField) ?? 0).toInt(); + message.setFrontTilt = (message._setFrontTiltSignal.decode(bitField) ?? 0) + .toInt(); + message.setRearSwivel = (message._setRearSwivelSignal.decode(bitField) ?? 0) + .toInt(); + message.setRearTilt = (message._setRearTiltSignal.decode(bitField) ?? 0) + .toInt(); + message.frontSwivel = (message._frontSwivelSignal.decode(bitField) ?? 0) + .toDouble(); + message.frontTilt = (message._frontTiltSignal.decode(bitField) ?? 0) + .toDouble(); + message.rearSwivel = (message._rearSwivelSignal.decode(bitField) ?? 0) + .toDouble(); + message.rearTilt = (message._rearTiltSignal.decode(bitField) ?? 0) + .toDouble(); return message; } @@ -901,9 +874,8 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Drive_Set_Swivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; - } + String toString() => + 'Drive_Set_Swivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } class DriveLedDataMessage extends $_dbc.DBCMessage { @@ -923,21 +895,22 @@ class DriveLedDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Color" - num color; + int color; /// Value of signal "Blink" - num blink; + int blink; final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( name: 'Color', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 4, + // dart format off mapping: [1, 2, 4, 8, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3], + // dart format on factor: 1, offset: 0, min: 0, @@ -950,11 +923,12 @@ class DriveLedDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 4, length: 1, + // dart format off mapping: [0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [4], + // dart format on factor: 1, offset: 0, min: 0, @@ -963,21 +937,12 @@ class DriveLedDataMessage extends $_dbc.DBCMessage { ); @override - List<$_dbc.DBCSignal> get signals => [ - _colorSignal, - _blinkSignal, - ]; + List<$_dbc.DBCSignal> get signals => [_colorSignal, _blinkSignal]; - DriveLedDataMessage({ - this.color = 0, - this.blink = 0, - }); + DriveLedDataMessage({this.color = 0, this.blink = 0}); /// Creates a clone of this [DriveLedDataMessage] with the non-null values replaced - DriveLedDataMessage copyWith({ - num? color, - num? blink, - }) => DriveLedDataMessage( + DriveLedDataMessage copyWith({int? color, int? blink}) => DriveLedDataMessage( color: color ?? this.color, blink: blink ?? this.blink, ); @@ -985,23 +950,18 @@ class DriveLedDataMessage extends $_dbc.DBCMessage { factory DriveLedDataMessage.decode(List payload) { final message = DriveLedDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); - message.color = - message._colorSignal.decode(bitField) ?? - $_math.max(0, message._colorSignal.min); - message.blink = - message._blinkSignal.decode(bitField) ?? - $_math.max(0, message._blinkSignal.min); + message.color = (message._colorSignal.decode(bitField) ?? 0).toInt(); + message.blink = (message._blinkSignal.decode(bitField) ?? 0).toInt(); return message; } factory DriveLedDataMessage.fromJson(Map json) => - DriveLedDataMessage( - color: json['Color'] ?? 0, - blink: json['Blink'] ?? 0, - ); + DriveLedDataMessage(color: json['Color'] ?? 0, blink: json['Blink'] ?? 0); @override $_typed.Uint8List encode() { @@ -1014,15 +974,10 @@ class DriveLedDataMessage extends $_dbc.DBCMessage { } @override - Map toJson() => { - 'Color': color, - 'Blink': blink, - }; + Map toJson() => {'Color': color, 'Blink': blink}; @override - String toString() { - return 'Drive_LED_Data(\n Color=$color\n Blink=$blink\n)'; - } + String toString() => 'Drive_LED_Data(\n Color=$color\n Blink=$blink\n)'; } class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { @@ -1042,24 +997,25 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Throttle" - num throttle; + double throttle; /// Value of signal "Left_Speed" - num leftSpeed; + double leftSpeed; /// Value of signal "Right_Speed" - num rightSpeed; + double rightSpeed; final $_dbc.DBCSignal _throttleSignal = $_dbc.DBCSignal( name: 'Throttle', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 16, + // dart format off mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + // dart format on factor: 0.000016, offset: 0, min: 0, @@ -1072,11 +1028,12 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 16, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], + // dart format on factor: 0.000062, offset: 0, min: -1, @@ -1089,11 +1046,12 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 32, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], + // dart format on factor: 0.000062, offset: 0, min: -1, @@ -1116,9 +1074,9 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DriveAppliedOutputDataMessage] with the non-null values replaced DriveAppliedOutputDataMessage copyWith({ - num? throttle, - num? leftSpeed, - num? rightSpeed, + double? throttle, + double? leftSpeed, + double? rightSpeed, }) => DriveAppliedOutputDataMessage( throttle: throttle ?? this.throttle, leftSpeed: leftSpeed ?? this.leftSpeed, @@ -1128,17 +1086,16 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { factory DriveAppliedOutputDataMessage.decode(List payload) { final message = DriveAppliedOutputDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.throttle = - message._throttleSignal.decode(bitField) ?? - $_math.max(0, message._throttleSignal.min); - message.leftSpeed = - message._leftSpeedSignal.decode(bitField) ?? - $_math.max(0, message._leftSpeedSignal.min); - message.rightSpeed = - message._rightSpeedSignal.decode(bitField) ?? - $_math.max(0, message._rightSpeedSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.throttle = (message._throttleSignal.decode(bitField) ?? 0) + .toDouble(); + message.leftSpeed = (message._leftSpeedSignal.decode(bitField) ?? 0) + .toDouble(); + message.rightSpeed = (message._rightSpeedSignal.decode(bitField) ?? 0) + .toDouble(); return message; } @@ -1169,9 +1126,8 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Drive_Applied_Output_Data(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; - } + String toString() => + 'Drive_Applied_Output_Data(\n Throttle=$throttle\n Left_Speed=$leftSpeed\n Right_Speed=$rightSpeed\n)'; } class DriveBatteryDataMessage extends $_dbc.DBCMessage { @@ -1191,24 +1147,25 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Voltage" - num voltage; + double voltage; /// Value of signal "Temperature" - num temperature; + double temperature; /// Value of signal "Current" - num current; + double current; final $_dbc.DBCSignal _voltageSignal = $_dbc.DBCSignal( name: 'Voltage', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 10, + // dart format off mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], + // dart format on factor: 0.03548387097, offset: 0, min: 0, @@ -1221,11 +1178,12 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 10, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], + // dart format on factor: 0.09, offset: 50, min: -40, @@ -1238,11 +1196,12 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 22, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0], mappingIndexes: [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37], + // dart format on factor: 0.1, offset: 0, min: 0, @@ -1265,9 +1224,9 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DriveBatteryDataMessage] with the non-null values replaced DriveBatteryDataMessage copyWith({ - num? voltage, - num? temperature, - num? current, + double? voltage, + double? temperature, + double? current, }) => DriveBatteryDataMessage( voltage: voltage ?? this.voltage, temperature: temperature ?? this.temperature, @@ -1277,17 +1236,14 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { factory DriveBatteryDataMessage.decode(List payload) { final message = DriveBatteryDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.voltage = - message._voltageSignal.decode(bitField) ?? - $_math.max(0, message._voltageSignal.min); - message.temperature = - message._temperatureSignal.decode(bitField) ?? - $_math.max(0, message._temperatureSignal.min); - message.current = - message._currentSignal.decode(bitField) ?? - $_math.max(0, message._currentSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.voltage = (message._voltageSignal.decode(bitField) ?? 0).toDouble(); + message.temperature = (message._temperatureSignal.decode(bitField) ?? 0) + .toDouble(); + message.current = (message._currentSignal.decode(bitField) ?? 0).toDouble(); return message; } @@ -1318,9 +1274,8 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Drive_Battery_Data(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; - } + String toString() => + 'Drive_Battery_Data(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; } class DriveSwivelDataMessage extends $_dbc.DBCMessage { @@ -1340,27 +1295,28 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Front_Swivel" - num frontSwivel; + double frontSwivel; /// Value of signal "Front_Tilt" - num frontTilt; + double frontTilt; /// Value of signal "Rear_Swivel" - num rearSwivel; + double rearSwivel; /// Value of signal "Rear_Tilt" - num rearTilt; + double rearTilt; final $_dbc.DBCSignal _frontSwivelSignal = $_dbc.DBCSignal( name: 'Front_Swivel', signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 12, + // dart format off mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -1373,11 +1329,12 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 12, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -1390,11 +1347,12 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 24, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -1407,11 +1365,12 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 36, length: 12, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], + // dart format on factor: 0.044, offset: 0, min: -90, @@ -1436,10 +1395,10 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DriveSwivelDataMessage] with the non-null values replaced DriveSwivelDataMessage copyWith({ - num? frontSwivel, - num? frontTilt, - num? rearSwivel, - num? rearTilt, + double? frontSwivel, + double? frontTilt, + double? rearSwivel, + double? rearTilt, }) => DriveSwivelDataMessage( frontSwivel: frontSwivel ?? this.frontSwivel, frontTilt: frontTilt ?? this.frontTilt, @@ -1450,20 +1409,18 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { factory DriveSwivelDataMessage.decode(List payload) { final message = DriveSwivelDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.frontSwivel = - message._frontSwivelSignal.decode(bitField) ?? - $_math.max(0, message._frontSwivelSignal.min); - message.frontTilt = - message._frontTiltSignal.decode(bitField) ?? - $_math.max(0, message._frontTiltSignal.min); - message.rearSwivel = - message._rearSwivelSignal.decode(bitField) ?? - $_math.max(0, message._rearSwivelSignal.min); - message.rearTilt = - message._rearTiltSignal.decode(bitField) ?? - $_math.max(0, message._rearTiltSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.frontSwivel = (message._frontSwivelSignal.decode(bitField) ?? 0) + .toDouble(); + message.frontTilt = (message._frontTiltSignal.decode(bitField) ?? 0) + .toDouble(); + message.rearSwivel = (message._rearSwivelSignal.decode(bitField) ?? 0) + .toDouble(); + message.rearTilt = (message._rearTiltSignal.decode(bitField) ?? 0) + .toDouble(); return message; } @@ -1497,9 +1454,8 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Drive_Swivel_Data(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; - } + String toString() => + 'Drive_Swivel_Data(\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } class DriveMotorDataMessage extends $_dbc.DBCMessage { @@ -1519,30 +1475,31 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Motor_Value" - num motorValue; + int motorValue; /// Value of signal "Speed" - num speed; + double speed; /// Value of signal "Current" - num current; + double current; /// Value of signal "Temperature" - num temperature; + int temperature; /// Value of signal "Error_Code" - num errorCode; + int errorCode; final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( name: 'Motor_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 3, + // dart format off mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], + // dart format on factor: 1, offset: 0, min: 0, @@ -1555,11 +1512,12 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 16, + // dart format off mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], + // dart format on factor: 10, offset: 0, min: -320000, @@ -1572,11 +1530,12 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 19, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], + // dart format on factor: 0.01, offset: 0, min: -60, @@ -1589,11 +1548,12 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 35, length: 8, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 0, 0, 0, 0, 0], mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42], + // dart format on factor: 1, offset: 0, min: -20, @@ -1606,11 +1566,12 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 43, length: 3, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 0, 0], mappingIndexes: [43, 44, 45], + // dart format on factor: 1, offset: 0, min: 0, @@ -1637,11 +1598,11 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [DriveMotorDataMessage] with the non-null values replaced DriveMotorDataMessage copyWith({ - num? motorValue, - num? speed, - num? current, - num? temperature, - num? errorCode, + int? motorValue, + double? speed, + double? current, + int? temperature, + int? errorCode, }) => DriveMotorDataMessage( motorValue: motorValue ?? this.motorValue, speed: speed ?? this.speed, @@ -1653,23 +1614,18 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { factory DriveMotorDataMessage.decode(List payload) { final message = DriveMotorDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.motorValue = - message._motorValueSignal.decode(bitField) ?? - $_math.max(0, message._motorValueSignal.min); - message.speed = - message._speedSignal.decode(bitField) ?? - $_math.max(0, message._speedSignal.min); - message.current = - message._currentSignal.decode(bitField) ?? - $_math.max(0, message._currentSignal.min); - message.temperature = - message._temperatureSignal.decode(bitField) ?? - $_math.max(0, message._temperatureSignal.min); - message.errorCode = - message._errorCodeSignal.decode(bitField) ?? - $_math.max(0, message._errorCodeSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.motorValue = (message._motorValueSignal.decode(bitField) ?? 0) + .toInt(); + message.speed = (message._speedSignal.decode(bitField) ?? 0).toDouble(); + message.current = (message._currentSignal.decode(bitField) ?? 0).toDouble(); + message.temperature = (message._temperatureSignal.decode(bitField) ?? 0) + .toInt(); + message.errorCode = (message._errorCodeSignal.decode(bitField) ?? 0) + .toInt(); return message; } @@ -1706,9 +1662,8 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Drive_Motor_Data(\n Motor_Value=$motorValue\n Speed=$speed\n Current=$current\n Temperature=$temperature\n Error_Code=$errorCode\n)'; - } + String toString() => + 'Drive_Motor_Data(\n Motor_Value=$motorValue\n Speed=$speed\n Current=$current\n Temperature=$temperature\n Error_Code=$errorCode\n)'; } class RelaySetStateMessage extends $_dbc.DBCMessage { @@ -1728,36 +1683,37 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Front_Left_Motor" - num frontLeftMotor; + int frontLeftMotor; /// Value of signal "Front_Right_Motor" - num frontRightMotor; + int frontRightMotor; /// Value of signal "Back_Left_Motor" - num backLeftMotor; + int backLeftMotor; /// Value of signal "Back_Right_Motor" - num backRightMotor; + int backRightMotor; /// Value of signal "Arm" - num arm; + int arm; /// Value of signal "Science" - num science; + int science; /// Value of signal "Drive" - num drive; + int drive; final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 2, + // dart format off mapping: [1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1], + // dart format on factor: 1, offset: 0, min: 0, @@ -1770,11 +1726,12 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 2, length: 2, + // dart format off mapping: [0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [2, 3], + // dart format on factor: 1, offset: 0, min: 0, @@ -1787,11 +1744,12 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 4, length: 2, + // dart format off mapping: [0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4, 5], + // dart format on factor: 1, offset: 0, min: 0, @@ -1804,11 +1762,12 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 6, length: 2, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [6, 7], + // dart format on factor: 1, offset: 0, min: 0, @@ -1821,11 +1780,12 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 8, length: 2, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0], mappingIndexes: [8, 9], + // dart format on factor: 1, offset: 0, min: 0, @@ -1838,11 +1798,12 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 10, length: 2, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0], mappingIndexes: [10, 11], + // dart format on factor: 1, offset: 0, min: 0, @@ -1855,11 +1816,12 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 12, length: 2, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0], mappingIndexes: [12, 13], + // dart format on factor: 1, offset: 0, min: 0, @@ -1890,13 +1852,13 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { /// Creates a clone of this [RelaySetStateMessage] with the non-null values replaced RelaySetStateMessage copyWith({ - num? frontLeftMotor, - num? frontRightMotor, - num? backLeftMotor, - num? backRightMotor, - num? arm, - num? science, - num? drive, + int? frontLeftMotor, + int? frontRightMotor, + int? backLeftMotor, + int? backRightMotor, + int? arm, + int? science, + int? drive, }) => RelaySetStateMessage( frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, frontRightMotor: frontRightMotor ?? this.frontRightMotor, @@ -1910,29 +1872,21 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { factory RelaySetStateMessage.decode(List payload) { final message = RelaySetStateMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); message.frontLeftMotor = - message._frontLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._frontLeftMotorSignal.min); + (message._frontLeftMotorSignal.decode(bitField) ?? 0).toInt(); message.frontRightMotor = - message._frontRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._frontRightMotorSignal.min); - message.backLeftMotor = - message._backLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._backLeftMotorSignal.min); + (message._frontRightMotorSignal.decode(bitField) ?? 0).toInt(); + message.backLeftMotor = (message._backLeftMotorSignal.decode(bitField) ?? 0) + .toInt(); message.backRightMotor = - message._backRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._backRightMotorSignal.min); - message.arm = - message._armSignal.decode(bitField) ?? - $_math.max(0, message._armSignal.min); - message.science = - message._scienceSignal.decode(bitField) ?? - $_math.max(0, message._scienceSignal.min); - message.drive = - message._driveSignal.decode(bitField) ?? - $_math.max(0, message._driveSignal.min); + (message._backRightMotorSignal.decode(bitField) ?? 0).toInt(); + message.arm = (message._armSignal.decode(bitField) ?? 0).toInt(); + message.science = (message._scienceSignal.decode(bitField) ?? 0).toInt(); + message.drive = (message._driveSignal.decode(bitField) ?? 0).toInt(); return message; } @@ -1975,9 +1929,8 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Relay_Set_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Arm=$arm\n Science=$science\n Drive=$drive\n)'; - } + String toString() => + 'Relay_Set_State(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Arm=$arm\n Science=$science\n Drive=$drive\n)'; } class RelayStateDataMessage extends $_dbc.DBCMessage { @@ -1997,39 +1950,40 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Front_Left_Motor" - num frontLeftMotor; + int frontLeftMotor; /// Value of signal "Front_Right_Motor" - num frontRightMotor; + int frontRightMotor; /// Value of signal "Back_Left_Motor" - num backLeftMotor; + int backLeftMotor; /// Value of signal "Back_Right_Motor" - num backRightMotor; + int backRightMotor; /// Value of signal "Drive" - num drive; + int drive; /// Value of signal "Arm" - num arm; + int arm; /// Value of signal "Science" - num science; + int science; /// Value of signal "Physical_Override" - num physicalOverride; + int physicalOverride; final $_dbc.DBCSignal _frontLeftMotorSignal = $_dbc.DBCSignal( name: 'Front_Left_Motor', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 1, + // dart format off mapping: [1, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], + // dart format on factor: 1, offset: 0, min: 0, @@ -2042,11 +1996,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 1, length: 1, + // dart format off mapping: [0, 1, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], + // dart format on factor: 1, offset: 0, min: 0, @@ -2059,11 +2014,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 2, length: 1, + // dart format off mapping: [0, 0, 1, 0, 0, 0, 0, 0], mappingIndexes: [2], + // dart format on factor: 1, offset: 0, min: 0, @@ -2076,11 +2032,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 1, + // dart format off mapping: [0, 0, 0, 1, 0, 0, 0, 0], mappingIndexes: [3], + // dart format on factor: 1, offset: 0, min: 0, @@ -2093,11 +2050,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 4, length: 1, + // dart format off mapping: [0, 0, 0, 0, 1, 0, 0, 0], mappingIndexes: [4], + // dart format on factor: 1, offset: 0, min: 0, @@ -2110,11 +2068,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 5, length: 1, + // dart format off mapping: [0, 0, 0, 0, 0, 1, 0, 0], mappingIndexes: [5], + // dart format on factor: 1, offset: 0, min: 0, @@ -2127,11 +2086,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 6, length: 1, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 1, 0], mappingIndexes: [6], + // dart format on factor: 1, offset: 0, min: 0, @@ -2144,11 +2104,12 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 7, length: 1, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 1], mappingIndexes: [7], + // dart format on factor: 1, offset: 0, min: 0, @@ -2181,14 +2142,14 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [RelayStateDataMessage] with the non-null values replaced RelayStateDataMessage copyWith({ - num? frontLeftMotor, - num? frontRightMotor, - num? backLeftMotor, - num? backRightMotor, - num? drive, - num? arm, - num? science, - num? physicalOverride, + int? frontLeftMotor, + int? frontRightMotor, + int? backLeftMotor, + int? backRightMotor, + int? drive, + int? arm, + int? science, + int? physicalOverride, }) => RelayStateDataMessage( frontLeftMotor: frontLeftMotor ?? this.frontLeftMotor, frontRightMotor: frontRightMotor ?? this.frontRightMotor, @@ -2203,32 +2164,23 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { factory RelayStateDataMessage.decode(List payload) { final message = RelayStateDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); message.frontLeftMotor = - message._frontLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._frontLeftMotorSignal.min); + (message._frontLeftMotorSignal.decode(bitField) ?? 0).toInt(); message.frontRightMotor = - message._frontRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._frontRightMotorSignal.min); - message.backLeftMotor = - message._backLeftMotorSignal.decode(bitField) ?? - $_math.max(0, message._backLeftMotorSignal.min); + (message._frontRightMotorSignal.decode(bitField) ?? 0).toInt(); + message.backLeftMotor = (message._backLeftMotorSignal.decode(bitField) ?? 0) + .toInt(); message.backRightMotor = - message._backRightMotorSignal.decode(bitField) ?? - $_math.max(0, message._backRightMotorSignal.min); - message.drive = - message._driveSignal.decode(bitField) ?? - $_math.max(0, message._driveSignal.min); - message.arm = - message._armSignal.decode(bitField) ?? - $_math.max(0, message._armSignal.min); - message.science = - message._scienceSignal.decode(bitField) ?? - $_math.max(0, message._scienceSignal.min); + (message._backRightMotorSignal.decode(bitField) ?? 0).toInt(); + message.drive = (message._driveSignal.decode(bitField) ?? 0).toInt(); + message.arm = (message._armSignal.decode(bitField) ?? 0).toInt(); + message.science = (message._scienceSignal.decode(bitField) ?? 0).toInt(); message.physicalOverride = - message._physicalOverrideSignal.decode(bitField) ?? - $_math.max(0, message._physicalOverrideSignal.min); + (message._physicalOverrideSignal.decode(bitField) ?? 0).toInt(); return message; } @@ -2274,9 +2226,8 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Relay_State_Data(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; - } + String toString() => + 'Relay_State_Data(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; } class ArmSetMotorMessage extends $_dbc.DBCMessage { @@ -2296,27 +2247,28 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Motor_Value" - num motorValue; + int motorValue; /// Value of signal "Move_Steps" - num moveSteps; + int moveSteps; /// Value of signal "Move_Radians" - num moveRadians; + double moveRadians; /// Value of signal "Angle" - num angle; + double angle; final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( name: 'Motor_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 3, + // dart format off mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], + // dart format on factor: 1, offset: 0, min: 0, @@ -2329,11 +2281,12 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 24, + // dart format off mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26], + // dart format on factor: 1, offset: 0, min: -8388608, @@ -2346,11 +2299,12 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 27, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], + // dart format on factor: 0.0000958738, offset: 0, min: -3.1415, @@ -2363,11 +2317,12 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 43, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], + // dart format on factor: 0.0000958738, offset: 0, min: -3.1415, @@ -2392,10 +2347,10 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { /// Creates a clone of this [ArmSetMotorMessage] with the non-null values replaced ArmSetMotorMessage copyWith({ - num? motorValue, - num? moveSteps, - num? moveRadians, - num? angle, + int? motorValue, + int? moveSteps, + double? moveRadians, + double? angle, }) => ArmSetMotorMessage( motorValue: motorValue ?? this.motorValue, moveSteps: moveSteps ?? this.moveSteps, @@ -2406,20 +2361,17 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { factory ArmSetMotorMessage.decode(List payload) { final message = ArmSetMotorMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.motorValue = - message._motorValueSignal.decode(bitField) ?? - $_math.max(0, message._motorValueSignal.min); - message.moveSteps = - message._moveStepsSignal.decode(bitField) ?? - $_math.max(0, message._moveStepsSignal.min); - message.moveRadians = - message._moveRadiansSignal.decode(bitField) ?? - $_math.max(0, message._moveRadiansSignal.min); - message.angle = - message._angleSignal.decode(bitField) ?? - $_math.max(0, message._angleSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.motorValue = (message._motorValueSignal.decode(bitField) ?? 0) + .toInt(); + message.moveSteps = (message._moveStepsSignal.decode(bitField) ?? 0) + .toInt(); + message.moveRadians = (message._moveRadiansSignal.decode(bitField) ?? 0) + .toDouble(); + message.angle = (message._angleSignal.decode(bitField) ?? 0).toDouble(); return message; } @@ -2453,9 +2405,8 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Arm_Set_Motor(\n Motor_Value=$motorValue\n Move_Steps=$moveSteps\n Move_Radians=$moveRadians\n Angle=$angle\n)'; - } + String toString() => + 'Arm_Set_Motor(\n Motor_Value=$motorValue\n Move_Steps=$moveSteps\n Move_Radians=$moveRadians\n Angle=$angle\n)'; } class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { @@ -2475,27 +2426,28 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Motor_Value" - num motorValue; + int motorValue; /// Value of signal "Is_Moving" - num isMoving; + int isMoving; /// Value of signal "Is_Limit_Switch_Pressed" - num isLimitSwitchPressed; + int isLimitSwitchPressed; /// Value of signal "Motor_Direction" - num motorDirection; + int motorDirection; final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( name: 'Motor_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 3, + // dart format off mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], + // dart format on factor: 1, offset: 0, min: 0, @@ -2508,11 +2460,12 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 2, + // dart format off mapping: [0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4], + // dart format on factor: 1, offset: 0, min: 0, @@ -2525,11 +2478,12 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 5, length: 2, + // dart format off mapping: [0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [5, 6], + // dart format on factor: 1, offset: 0, min: 0, @@ -2542,11 +2496,12 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 7, length: 4, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 0, 0, 0, 0, 0], mappingIndexes: [7, 8, 9, 10], + // dart format on factor: 1, offset: 0, min: 0, @@ -2571,10 +2526,10 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [ArmMotorMoveDataMessage] with the non-null values replaced ArmMotorMoveDataMessage copyWith({ - num? motorValue, - num? isMoving, - num? isLimitSwitchPressed, - num? motorDirection, + int? motorValue, + int? isMoving, + int? isLimitSwitchPressed, + int? motorDirection, }) => ArmMotorMoveDataMessage( motorValue: motorValue ?? this.motorValue, isMoving: isMoving ?? this.isMoving, @@ -2585,20 +2540,17 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { factory ArmMotorMoveDataMessage.decode(List payload) { final message = ArmMotorMoveDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.motorValue = - message._motorValueSignal.decode(bitField) ?? - $_math.max(0, message._motorValueSignal.min); - message.isMoving = - message._isMovingSignal.decode(bitField) ?? - $_math.max(0, message._isMovingSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.motorValue = (message._motorValueSignal.decode(bitField) ?? 0) + .toInt(); + message.isMoving = (message._isMovingSignal.decode(bitField) ?? 0).toInt(); message.isLimitSwitchPressed = - message._isLimitSwitchPressedSignal.decode(bitField) ?? - $_math.max(0, message._isLimitSwitchPressedSignal.min); + (message._isLimitSwitchPressedSignal.decode(bitField) ?? 0).toInt(); message.motorDirection = - message._motorDirectionSignal.decode(bitField) ?? - $_math.max(0, message._motorDirectionSignal.min); + (message._motorDirectionSignal.decode(bitField) ?? 0).toInt(); return message; } @@ -2632,9 +2584,8 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Arm_Motor_Move_Data(\n Motor_Value=$motorValue\n Is_Moving=$isMoving\n Is_Limit_Switch_Pressed=$isLimitSwitchPressed\n Motor_Direction=$motorDirection\n)'; - } + String toString() => + 'Arm_Motor_Move_Data(\n Motor_Value=$motorValue\n Is_Moving=$isMoving\n Is_Limit_Switch_Pressed=$isLimitSwitchPressed\n Motor_Direction=$motorDirection\n)'; } class ArmMotorStepDataMessage extends $_dbc.DBCMessage { @@ -2654,24 +2605,25 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Motor_Value" - num motorValue; + int motorValue; /// Value of signal "Current_Step" - num currentStep; + int currentStep; /// Value of signal "Target_Step" - num targetStep; + int targetStep; final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( name: 'Motor_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 3, + // dart format off mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], + // dart format on factor: 1, offset: 0, min: 0, @@ -2684,11 +2636,12 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 26, + // dart format off mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28], + // dart format on factor: 1, offset: 0, min: -33554432, @@ -2701,11 +2654,12 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 29, length: 26, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 0], mappingIndexes: [29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54], + // dart format on factor: 1, offset: 0, min: -33554432, @@ -2728,9 +2682,9 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [ArmMotorStepDataMessage] with the non-null values replaced ArmMotorStepDataMessage copyWith({ - num? motorValue, - num? currentStep, - num? targetStep, + int? motorValue, + int? currentStep, + int? targetStep, }) => ArmMotorStepDataMessage( motorValue: motorValue ?? this.motorValue, currentStep: currentStep ?? this.currentStep, @@ -2740,17 +2694,16 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { factory ArmMotorStepDataMessage.decode(List payload) { final message = ArmMotorStepDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.motorValue = - message._motorValueSignal.decode(bitField) ?? - $_math.max(0, message._motorValueSignal.min); - message.currentStep = - message._currentStepSignal.decode(bitField) ?? - $_math.max(0, message._currentStepSignal.min); - message.targetStep = - message._targetStepSignal.decode(bitField) ?? - $_math.max(0, message._targetStepSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.motorValue = (message._motorValueSignal.decode(bitField) ?? 0) + .toInt(); + message.currentStep = (message._currentStepSignal.decode(bitField) ?? 0) + .toInt(); + message.targetStep = (message._targetStepSignal.decode(bitField) ?? 0) + .toInt(); return message; } @@ -2781,9 +2734,8 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Arm_Motor_Step_Data(\n Motor_Value=$motorValue\n Current_Step=$currentStep\n Target_Step=$targetStep\n)'; - } + String toString() => + 'Arm_Motor_Step_Data(\n Motor_Value=$motorValue\n Current_Step=$currentStep\n Target_Step=$targetStep\n)'; } class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { @@ -2803,24 +2755,25 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Motor_Value" - num motorValue; + int motorValue; /// Value of signal "Current_Angle" - num currentAngle; + double currentAngle; /// Value of signal "Target_Angle" - num targetAngle; + double targetAngle; final $_dbc.DBCSignal _motorValueSignal = $_dbc.DBCSignal( name: 'Motor_Value', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 3, + // dart format off mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], + // dart format on factor: 1, offset: 0, min: 0, @@ -2833,11 +2786,12 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 3, length: 16, + // dart format off mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], + // dart format on factor: 0.00009587379, offset: 0, min: -3.14159, @@ -2850,11 +2804,12 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 19, length: 16, + // dart format off mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], + // dart format on factor: 0.00009587379, offset: 0, min: -3.14159, @@ -2877,9 +2832,9 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { /// Creates a clone of this [ArmMotorAngleDataMessage] with the non-null values replaced ArmMotorAngleDataMessage copyWith({ - num? motorValue, - num? currentAngle, - num? targetAngle, + int? motorValue, + double? currentAngle, + double? targetAngle, }) => ArmMotorAngleDataMessage( motorValue: motorValue ?? this.motorValue, currentAngle: currentAngle ?? this.currentAngle, @@ -2889,17 +2844,16 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { factory ArmMotorAngleDataMessage.decode(List payload) { final message = ArmMotorAngleDataMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.motorValue = - message._motorValueSignal.decode(bitField) ?? - $_math.max(0, message._motorValueSignal.min); - message.currentAngle = - message._currentAngleSignal.decode(bitField) ?? - $_math.max(0, message._currentAngleSignal.min); - message.targetAngle = - message._targetAngleSignal.decode(bitField) ?? - $_math.max(0, message._targetAngleSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.motorValue = (message._motorValueSignal.decode(bitField) ?? 0) + .toInt(); + message.currentAngle = (message._currentAngleSignal.decode(bitField) ?? 0) + .toDouble(); + message.targetAngle = (message._targetAngleSignal.decode(bitField) ?? 0) + .toDouble(); return message; } @@ -2930,9 +2884,8 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Arm_Motor_Angle_Data(\n Motor_Value=$motorValue\n Current_Angle=$currentAngle\n Target_Angle=$targetAngle\n)'; - } + String toString() => + 'Arm_Motor_Angle_Data(\n Motor_Value=$motorValue\n Current_Angle=$currentAngle\n Target_Angle=$targetAngle\n)'; } class ArmSetSystemActionMessage extends $_dbc.DBCMessage { @@ -2952,24 +2905,25 @@ class ArmSetSystemActionMessage extends $_dbc.DBCMessage { static const String multiplexor = ''; /// Value of signal "Stop" - num stop; + int stop; /// Value of signal "Calibrate" - num calibrate; + int calibrate; /// Value of signal "Jab" - num jab; + int jab; final $_dbc.DBCSignal _stopSignal = $_dbc.DBCSignal( name: 'Stop', signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 0, length: 1, + // dart format off mapping: [1, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0], + // dart format on factor: 1, offset: 0, min: 0, @@ -2982,11 +2936,12 @@ class ArmSetSystemActionMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 1, length: 1, + // dart format off mapping: [0, 1, 0, 0, 0, 0, 0, 0], mappingIndexes: [1], + // dart format on factor: 1, offset: 0, min: 0, @@ -2999,11 +2954,12 @@ class ArmSetSystemActionMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - multiplexGroup: -1, start: 2, length: 1, + // dart format off mapping: [0, 0, 1, 0, 0, 0, 0, 0], mappingIndexes: [2], + // dart format on factor: 1, offset: 0, min: 0, @@ -3018,37 +2974,27 @@ class ArmSetSystemActionMessage extends $_dbc.DBCMessage { _jabSignal, ]; - ArmSetSystemActionMessage({ - this.stop = 0, - this.calibrate = 0, - this.jab = 0, - }); + ArmSetSystemActionMessage({this.stop = 0, this.calibrate = 0, this.jab = 0}); /// Creates a clone of this [ArmSetSystemActionMessage] with the non-null values replaced - ArmSetSystemActionMessage copyWith({ - num? stop, - num? calibrate, - num? jab, - }) => ArmSetSystemActionMessage( - stop: stop ?? this.stop, - calibrate: calibrate ?? this.calibrate, - jab: jab ?? this.jab, - ); + ArmSetSystemActionMessage copyWith({int? stop, int? calibrate, int? jab}) => + ArmSetSystemActionMessage( + stop: stop ?? this.stop, + calibrate: calibrate ?? this.calibrate, + jab: jab ?? this.jab, + ); factory ArmSetSystemActionMessage.decode(List payload) { final message = ArmSetSystemActionMessage(); final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from(typedBuffer.sublist(0, message.messageLength)); - - message.stop = - message._stopSignal.decode(bitField) ?? - $_math.max(0, message._stopSignal.min); - message.calibrate = - message._calibrateSignal.decode(bitField) ?? - $_math.max(0, message._calibrateSignal.min); - message.jab = - message._jabSignal.decode(bitField) ?? - $_math.max(0, message._jabSignal.min); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.stop = (message._stopSignal.decode(bitField) ?? 0).toInt(); + message.calibrate = (message._calibrateSignal.decode(bitField) ?? 0) + .toInt(); + message.jab = (message._jabSignal.decode(bitField) ?? 0).toInt(); return message; } @@ -3079,7 +3025,6 @@ class ArmSetSystemActionMessage extends $_dbc.DBCMessage { }; @override - String toString() { - return 'Arm_Set_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; - } + String toString() => + 'Arm_Set_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; } diff --git a/subsystems/lib/src/utils/dbc_conversions.dart b/subsystems/lib/src/utils/dbc_conversions.dart index a8172751..a0378b6a 100644 --- a/subsystems/lib/src/utils/dbc_conversions.dart +++ b/subsystems/lib/src/utils/dbc_conversions.dart @@ -20,9 +20,9 @@ extension BoolStateToInt on BoolState { extension DriveAppliedOutputToProto on DriveAppliedOutputDataMessage { /// The applied output DBC message as a [DriveData] message DriveData toDriveProto() => DriveData( - throttle: throttle.toDouble(), - left: leftSpeed.toDouble(), - right: rightSpeed.toDouble(), + throttle: throttle, + left: leftSpeed, + right: rightSpeed, setLeft: true, setRight: true, setThrottle: true, @@ -33,9 +33,9 @@ extension DriveAppliedOutputToProto on DriveAppliedOutputDataMessage { extension DriveBatteryToProto on DriveBatteryDataMessage { /// The battery DBC message as a [DriveData] message DriveData toDriveProto() => DriveData( - batteryVoltage: voltage.toDouble(), - batteryTemperature: temperature.toDouble(), - batteryCurrent: current.toDouble(), + batteryVoltage: voltage, + batteryTemperature: temperature, + batteryCurrent: current, ); } @@ -43,17 +43,17 @@ extension DriveBatteryToProto on DriveBatteryDataMessage { extension DriveLedToProto on DriveLedDataMessage { /// The led DBC message as a [DriveData] message DriveData toDriveProto() => - DriveData(color: ProtoColor.valueOf(color.toInt())); + DriveData(color: ProtoColor.valueOf(color)); } /// Utility extension to convert a [DriveSwivelDataMessage] into a [DriveData] message extension DriveSwivelToProto on DriveSwivelDataMessage { /// The swivel DBC message as a [DriveData] message DriveData toDriveProto() => DriveData( - frontSwivel: frontSwivel.toDouble(), - frontTilt: frontTilt.toDouble(), - rearSwivel: rearSwivel.toDouble(), - rearTilt: rearTilt.toDouble(), + frontSwivel: frontSwivel, + frontTilt: frontTilt, + rearSwivel: rearSwivel, + rearTilt: rearTilt, ); } @@ -61,10 +61,10 @@ extension DriveSwivelToProto on DriveSwivelDataMessage { extension DriveMotorToProto on DriveMotorDataMessage { /// The drive motor data as a [DriveMotorData] message DriveMotorData toMotorData() => DriveMotorData( - speed: speed.toDouble(), - current: current.toDouble(), - temperature: temperature.toInt(), - error: MotorErrorCode.valueOf(errorCode.toInt()), + speed: speed, + current: current, + temperature: temperature, + error: MotorErrorCode.valueOf(errorCode), ); /// The drive motor data as a [DriveData] message @@ -165,9 +165,9 @@ extension RelaysCommandToDBC on RelaysCommand { extension ArmMotorMoveToProto on ArmMotorMoveDataMessage { /// The arm motor move data as a [MotorData] message MotorData toMotorData() => MotorData( - isMoving: BoolState.valueOf(isMoving.toInt()), - isLimitSwitchPressed: BoolState.valueOf(isLimitSwitchPressed.toInt()), - direction: MotorDirection.valueOf(motorDirection.toInt()), + isMoving: BoolState.valueOf(isMoving), + isLimitSwitchPressed: BoolState.valueOf(isLimitSwitchPressed), + direction: MotorDirection.valueOf(motorDirection), ); /// The arm motor move data as an [ArmData] message @@ -190,8 +190,8 @@ extension ArmMotorMoveToProto on ArmMotorMoveDataMessage { extension ArmMotorStepToProto on ArmMotorStepDataMessage { /// The motor steps DBC message as a [MotorData] message MotorData toMotorData() => MotorData( - currentStep: currentStep.toInt(), - targetStep: targetStep.toInt(), + currentStep: currentStep, + targetStep: targetStep, ); /// The motor steps DBC message as a [MotorData] message @@ -214,8 +214,8 @@ extension ArmMotorStepToProto on ArmMotorStepDataMessage { extension ArmMotorAngleToProto on ArmMotorAngleDataMessage { /// The motor angle DBC message as a [MotorData] message MotorData toMotorData() => MotorData( - currentAngle: currentAngle.toDouble(), - targetAngle: targetAngle.toDouble(), + currentAngle: currentAngle, + targetAngle: targetAngle, ); /// The motor angle DBC message as an [ArmData] message From 067ec83ebce3151d0aebd89a7172b708db3f8226 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Mon, 8 Sep 2025 11:03:15 -0400 Subject: [PATCH 29/30] Regenerate messages and update heartbeat ID assignment --- subsystems/lib/src/devices/can_bus.dart | 6 +- .../lib/src/generated/rover_messages.dbc.dart | 754 +++++++++--------- 2 files changed, 380 insertions(+), 380 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index feb92eb1..92426e01 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -360,10 +360,10 @@ class CanBus extends Service { void _onCanFrame(CanFrame frame) { switch (frame) { case CanDataFrame(:final id, :final data): - if (id == DeviceBroadcastMessage().canId) { - _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); - } else if (canIDToMessage.containsKey(id)) { + if (canIDToMessage.containsKey(id)) { collection.server.sendMessage(canIDToMessage[id]!.call(data)); + } else if (id != 0 && id & 0x0FF == DeviceBroadcastMessage().canId) { + _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); } else { logger.warning( "Received message with unmapped ID: 0x${id.toRadixString(16).padLeft(2, '0')}", diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 90a2a42f..0e2db0ff 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -10,82 +10,6 @@ import 'dart:typed_data' as $_typed; import 'package:dart_dbc_generator/dart_dbc_generator.dart' as $_dbc; -class RoverHeartbeatMessage extends $_dbc.DBCMessage { - @override - String messageName = 'Rover_Heartbeat'; - - @override - int messageLength = 1; - - @override - int canId = 0x1; - - /// Whether or not "Rover_Heartbeat" is multiplex - static const bool isMultiplex = false; - - /// The multiplexor for "Rover_Heartbeat" - static const String multiplexor = ''; - - /// Value of signal "Rover_Status" - int roverStatus; - - final $_dbc.DBCSignal _roverStatusSignal = $_dbc.DBCSignal( - name: 'Rover_Status', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 0, - length: 4, - // dart format off - mapping: [1, 2, 4, 8, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3], - // dart format on - factor: 1, - offset: 0, - min: 0, - max: 5, - unit: '', - ); - - @override - List<$_dbc.DBCSignal> get signals => [_roverStatusSignal]; - - RoverHeartbeatMessage({this.roverStatus = 0}); - - /// Creates a clone of this [RoverHeartbeatMessage] with the non-null values replaced - RoverHeartbeatMessage copyWith({int? roverStatus}) => - RoverHeartbeatMessage(roverStatus: roverStatus ?? this.roverStatus); - - factory RoverHeartbeatMessage.decode(List payload) { - final message = RoverHeartbeatMessage(); - final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from( - typedBuffer.sublist(0, message.messageLength), - ); - - message.roverStatus = (message._roverStatusSignal.decode(bitField) ?? 0) - .toInt(); - - return message; - } - - factory RoverHeartbeatMessage.fromJson(Map json) => - RoverHeartbeatMessage(roverStatus: json['Rover_Status'] ?? 0); - - @override - $_typed.Uint8List encode() { - final Map<$_dbc.DBCSignal, num> values = {_roverStatusSignal: roverStatus}; - - return encodeWithValues(values); - } - - @override - Map toJson() => {'Rover_Status': roverStatus}; - - @override - String toString() => 'Rover_Heartbeat(\n Rover_Status=$roverStatus\n)'; -} - class DeviceBroadcastMessage extends $_dbc.DBCMessage { @override String messageName = 'Device_Broadcast'; @@ -94,7 +18,7 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { int messageLength = 2; @override - int canId = 0x2; + int canId = 0x0; /// Whether or not "Device_Broadcast" is multiplex static const bool isMultiplex = false; @@ -236,6 +160,82 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { 'Device_Broadcast(\n Device_Value=$deviceValue\n FW_Version_Major=$fwVersionMajor\n FW_Version_Minor=$fwVersionMinor\n)'; } +class RoverHeartbeatMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Rover_Heartbeat'; + + @override + int messageLength = 1; + + @override + int canId = 0x1; + + /// Whether or not "Rover_Heartbeat" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Rover_Heartbeat" + static const String multiplexor = ''; + + /// Value of signal "Rover_Status" + int roverStatus; + + final $_dbc.DBCSignal _roverStatusSignal = $_dbc.DBCSignal( + name: 'Rover_Status', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 0, + length: 4, + // dart format off + mapping: [1, 2, 4, 8, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + // dart format on + factor: 1, + offset: 0, + min: 0, + max: 5, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [_roverStatusSignal]; + + RoverHeartbeatMessage({this.roverStatus = 0}); + + /// Creates a clone of this [RoverHeartbeatMessage] with the non-null values replaced + RoverHeartbeatMessage copyWith({int? roverStatus}) => + RoverHeartbeatMessage(roverStatus: roverStatus ?? this.roverStatus); + + factory RoverHeartbeatMessage.decode(List payload) { + final message = RoverHeartbeatMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.roverStatus = (message._roverStatusSignal.decode(bitField) ?? 0) + .toInt(); + + return message; + } + + factory RoverHeartbeatMessage.fromJson(Map json) => + RoverHeartbeatMessage(roverStatus: json['Rover_Status'] ?? 0); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = {_roverStatusSignal: roverStatus}; + + return encodeWithValues(values); + } + + @override + Map toJson() => {'Rover_Status': roverStatus}; + + @override + String toString() => 'Rover_Heartbeat(\n Rover_Status=$roverStatus\n)'; +} + class DriveSetSpeedsMessage extends $_dbc.DBCMessage { @override String messageName = 'Drive_Set_Speeds'; @@ -244,7 +244,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { int messageLength = 7; @override - int canId = 0x10; + int canId = 0x101; /// Whether or not "Drive_Set_Speeds" is multiplex static const bool isMultiplex = false; @@ -335,7 +335,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], // dart format on - factor: 0.000062, + factor: 0.00003051850947599719, offset: 0, min: -1, max: 1, @@ -353,7 +353,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], // dart format on - factor: 0.000062, + factor: 0.00003051850947599719, offset: 0, min: -1, max: 1, @@ -371,7 +371,7 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50], // dart format on - factor: 0.000016, + factor: 0.000015259254737998596, offset: 0, min: 0, max: 1, @@ -484,7 +484,7 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { int messageLength = 1; @override - int canId = 0x11; + int canId = 0x102; /// Whether or not "Drive_Set_LED" is multiplex static const bool isMultiplex = false; @@ -586,7 +586,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { int messageLength = 7; @override - int canId = 0x12; + int canId = 0x103; /// Whether or not "Drive_Set_Swivel" is multiplex static const bool isMultiplex = false; @@ -701,7 +701,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -719,7 +719,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -737,7 +737,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -755,7 +755,7 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0], mappingIndexes: [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -878,108 +878,6 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { 'Drive_Set_Swivel(\n Set_Front_Swivel=$setFrontSwivel\n Set_Front_Tilt=$setFrontTilt\n Set_Rear_Swivel=$setRearSwivel\n Set_Rear_Tilt=$setRearTilt\n Front_Swivel=$frontSwivel\n Front_Tilt=$frontTilt\n Rear_Swivel=$rearSwivel\n Rear_Tilt=$rearTilt\n)'; } -class DriveLedDataMessage extends $_dbc.DBCMessage { - @override - String messageName = 'Drive_LED_Data'; - - @override - int messageLength = 1; - - @override - int canId = 0x17; - - /// Whether or not "Drive_LED_Data" is multiplex - static const bool isMultiplex = false; - - /// The multiplexor for "Drive_LED_Data" - static const String multiplexor = ''; - - /// Value of signal "Color" - int color; - - /// Value of signal "Blink" - int blink; - - final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( - name: 'Color', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 0, - length: 4, - // dart format off - mapping: [1, 2, 4, 8, 0, 0, 0, 0], - mappingIndexes: [0, 1, 2, 3], - // dart format on - factor: 1, - offset: 0, - min: 0, - max: 8, - unit: '', - ); - - final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( - name: 'Blink', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 4, - length: 1, - // dart format off - mapping: [0, 0, 0, 0, 1, 0, 0, 0], - mappingIndexes: [4], - // dart format on - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - @override - List<$_dbc.DBCSignal> get signals => [_colorSignal, _blinkSignal]; - - DriveLedDataMessage({this.color = 0, this.blink = 0}); - - /// Creates a clone of this [DriveLedDataMessage] with the non-null values replaced - DriveLedDataMessage copyWith({int? color, int? blink}) => DriveLedDataMessage( - color: color ?? this.color, - blink: blink ?? this.blink, - ); - - factory DriveLedDataMessage.decode(List payload) { - final message = DriveLedDataMessage(); - final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from( - typedBuffer.sublist(0, message.messageLength), - ); - - message.color = (message._colorSignal.decode(bitField) ?? 0).toInt(); - message.blink = (message._blinkSignal.decode(bitField) ?? 0).toInt(); - - return message; - } - - factory DriveLedDataMessage.fromJson(Map json) => - DriveLedDataMessage(color: json['Color'] ?? 0, blink: json['Blink'] ?? 0); - - @override - $_typed.Uint8List encode() { - final Map<$_dbc.DBCSignal, num> values = { - _colorSignal: color, - _blinkSignal: blink, - }; - - return encodeWithValues(values); - } - - @override - Map toJson() => {'Color': color, 'Blink': blink}; - - @override - String toString() => 'Drive_LED_Data(\n Color=$color\n Blink=$blink\n)'; -} - class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { @override String messageName = 'Drive_Applied_Output_Data'; @@ -988,7 +886,7 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { int messageLength = 6; @override - int canId = 0x15; + int canId = 0x105; /// Whether or not "Drive_Applied_Output_Data" is multiplex static const bool isMultiplex = false; @@ -1016,7 +914,7 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], // dart format on - factor: 0.000016, + factor: 0.000015259254737998596, offset: 0, min: 0, max: 1, @@ -1034,7 +932,7 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31], // dart format on - factor: 0.000062, + factor: 0.00003051850947599719, offset: 0, min: -1, max: 1, @@ -1052,7 +950,7 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768], mappingIndexes: [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], // dart format on - factor: 0.000062, + factor: 0.00003051850947599719, offset: 0, min: -1, max: 1, @@ -1138,7 +1036,7 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { int messageLength = 5; @override - int canId = 0x16; + int canId = 0x106; /// Whether or not "Drive_Battery_Data" is multiplex static const bool isMultiplex = false; @@ -1184,11 +1082,11 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], // dart format on - factor: 0.09, - offset: 50, + factor: 0.046409379579872984, + offset: 55, min: -40, max: 150, - unit: 'C', + unit: '°C', ); final $_dbc.DBCSignal _currentSignal = $_dbc.DBCSignal( @@ -1202,7 +1100,7 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0], mappingIndexes: [22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37], // dart format on - factor: 0.1, + factor: 0.0004577776421399579, offset: 0, min: 0, max: 30, @@ -1218,7 +1116,7 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { DriveBatteryDataMessage({ this.voltage = 0, - this.temperature = 50, + this.temperature = 55, this.current = 0, }); @@ -1251,7 +1149,7 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { factory DriveBatteryDataMessage.fromJson(Map json) => DriveBatteryDataMessage( voltage: json['Voltage'] ?? 0, - temperature: json['Temperature'] ?? 50, + temperature: json['Temperature'] ?? 55, current: json['Current'] ?? 0, ); @@ -1278,7 +1176,109 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { 'Drive_Battery_Data(\n Voltage=$voltage\n Temperature=$temperature\n Current=$current\n)'; } -class DriveSwivelDataMessage extends $_dbc.DBCMessage { +class DriveLedDataMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Drive_LED_Data'; + + @override + int messageLength = 1; + + @override + int canId = 0x107; + + /// Whether or not "Drive_LED_Data" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Drive_LED_Data" + static const String multiplexor = ''; + + /// Value of signal "Color" + int color; + + /// Value of signal "Blink" + int blink; + + final $_dbc.DBCSignal _colorSignal = $_dbc.DBCSignal( + name: 'Color', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 0, + length: 4, + // dart format off + mapping: [1, 2, 4, 8, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3], + // dart format on + factor: 1, + offset: 0, + min: 0, + max: 8, + unit: '', + ); + + final $_dbc.DBCSignal _blinkSignal = $_dbc.DBCSignal( + name: 'Blink', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 4, + length: 1, + // dart format off + mapping: [0, 0, 0, 0, 1, 0, 0, 0], + mappingIndexes: [4], + // dart format on + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [_colorSignal, _blinkSignal]; + + DriveLedDataMessage({this.color = 0, this.blink = 0}); + + /// Creates a clone of this [DriveLedDataMessage] with the non-null values replaced + DriveLedDataMessage copyWith({int? color, int? blink}) => DriveLedDataMessage( + color: color ?? this.color, + blink: blink ?? this.blink, + ); + + factory DriveLedDataMessage.decode(List payload) { + final message = DriveLedDataMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.color = (message._colorSignal.decode(bitField) ?? 0).toInt(); + message.blink = (message._blinkSignal.decode(bitField) ?? 0).toInt(); + + return message; + } + + factory DriveLedDataMessage.fromJson(Map json) => + DriveLedDataMessage(color: json['Color'] ?? 0, blink: json['Blink'] ?? 0); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _colorSignal: color, + _blinkSignal: blink, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => {'Color': color, 'Blink': blink}; + + @override + String toString() => 'Drive_LED_Data(\n Color=$color\n Blink=$blink\n)'; +} + +class DriveSwivelDataMessage extends $_dbc.DBCMessage { @override String messageName = 'Drive_Swivel_Data'; @@ -1286,7 +1286,7 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { int messageLength = 6; @override - int canId = 0x18; + int canId = 0x108; /// Whether or not "Drive_Swivel_Data" is multiplex static const bool isMultiplex = false; @@ -1317,7 +1317,7 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -1335,7 +1335,7 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -1353,7 +1353,7 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -1371,7 +1371,7 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048], mappingIndexes: [36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47], // dart format on - factor: 0.044, + factor: 0.04396678065461651, offset: 0, min: -90, max: 90, @@ -1466,7 +1466,7 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { int messageLength = 6; @override - int canId = 0x19; + int canId = 0x109; /// Whether or not "Drive_Motor_Data" is multiplex static const bool isMultiplex = false; @@ -1536,7 +1536,7 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], // dart format on - factor: 0.01, + factor: 0.1, offset: 0, min: -60, max: 60, @@ -1674,7 +1674,7 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { int messageLength = 2; @override - int canId = 0x20; + int canId = 0x201; /// Whether or not "Relay_Set_State" is multiplex static const bool isMultiplex = false; @@ -1941,7 +1941,7 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { int messageLength = 1; @override - int canId = 0x25; + int canId = 0x205; /// Whether or not "Relay_State_Data" is multiplex static const bool isMultiplex = false; @@ -2238,7 +2238,7 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { int messageLength = 8; @override - int canId = 0x30; + int canId = 0x301; /// Whether or not "Arm_Set_Motor" is multiplex static const bool isMultiplex = false; @@ -2289,8 +2289,8 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { // dart format on factor: 1, offset: 0, - min: -8388608, - max: 8388608, + min: -8388607, + max: 8388607, unit: '', ); @@ -2305,7 +2305,7 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42], // dart format on - factor: 0.0000958738, + factor: 0.00009587389751884518, offset: 0, min: -3.1415, max: 3.1415, @@ -2323,10 +2323,10 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], // dart format on - factor: 0.0000958738, + factor: 0.00009587389751884518, offset: 0, min: -3.1415, - max: -3.1415, + max: 3.1415, unit: '', ); @@ -2409,6 +2409,147 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { 'Arm_Set_Motor(\n Motor_Value=$motorValue\n Move_Steps=$moveSteps\n Move_Radians=$moveRadians\n Angle=$angle\n)'; } +class ArmSetSystemActionMessage extends $_dbc.DBCMessage { + @override + String messageName = 'Arm_Set_System_Action'; + + @override + int messageLength = 1; + + @override + int canId = 0x302; + + /// Whether or not "Arm_Set_System_Action" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Arm_Set_System_Action" + static const String multiplexor = ''; + + /// Value of signal "Stop" + int stop; + + /// Value of signal "Calibrate" + int calibrate; + + /// Value of signal "Jab" + int jab; + + final $_dbc.DBCSignal _stopSignal = $_dbc.DBCSignal( + name: 'Stop', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 0, + length: 1, + // dart format off + mapping: [1, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0], + // dart format on + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _calibrateSignal = $_dbc.DBCSignal( + name: 'Calibrate', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 1, + length: 1, + // dart format off + mapping: [0, 1, 0, 0, 0, 0, 0, 0], + mappingIndexes: [1], + // dart format on + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + final $_dbc.DBCSignal _jabSignal = $_dbc.DBCSignal( + name: 'Jab', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 2, + length: 1, + // dart format off + mapping: [0, 0, 1, 0, 0, 0, 0, 0], + mappingIndexes: [2], + // dart format on + factor: 1, + offset: 0, + min: 0, + max: 1, + unit: '', + ); + + @override + List<$_dbc.DBCSignal> get signals => [ + _stopSignal, + _calibrateSignal, + _jabSignal, + ]; + + ArmSetSystemActionMessage({this.stop = 0, this.calibrate = 0, this.jab = 0}); + + /// Creates a clone of this [ArmSetSystemActionMessage] with the non-null values replaced + ArmSetSystemActionMessage copyWith({int? stop, int? calibrate, int? jab}) => + ArmSetSystemActionMessage( + stop: stop ?? this.stop, + calibrate: calibrate ?? this.calibrate, + jab: jab ?? this.jab, + ); + + factory ArmSetSystemActionMessage.decode(List payload) { + final message = ArmSetSystemActionMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.stop = (message._stopSignal.decode(bitField) ?? 0).toInt(); + message.calibrate = (message._calibrateSignal.decode(bitField) ?? 0) + .toInt(); + message.jab = (message._jabSignal.decode(bitField) ?? 0).toInt(); + + return message; + } + + factory ArmSetSystemActionMessage.fromJson(Map json) => + ArmSetSystemActionMessage( + stop: json['Stop'] ?? 0, + calibrate: json['Calibrate'] ?? 0, + jab: json['Jab'] ?? 0, + ); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = { + _stopSignal: stop, + _calibrateSignal: calibrate, + _jabSignal: jab, + }; + + return encodeWithValues(values); + } + + @override + Map toJson() => { + 'Stop': stop, + 'Calibrate': calibrate, + 'Jab': jab, + }; + + @override + String toString() => + 'Arm_Set_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; +} + class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { @override String messageName = 'Arm_Motor_Move_Data'; @@ -2417,7 +2558,7 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { int messageLength = 2; @override - int canId = 0x35; + int canId = 0x305; /// Whether or not "Arm_Motor_Move_Data" is multiplex static const bool isMultiplex = false; @@ -2469,7 +2610,7 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 2, + max: 3, unit: '', ); @@ -2487,7 +2628,7 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { factor: 1, offset: 0, min: 0, - max: 2, + max: 3, unit: '', ); @@ -2593,10 +2734,10 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { String messageName = 'Arm_Motor_Step_Data'; @override - int messageLength = 7; + int messageLength = 8; @override - int canId = 0x36; + int canId = 0x306; /// Whether or not "Arm_Motor_Step_Data" is multiplex static const bool isMultiplex = false; @@ -2621,7 +2762,7 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { start: 0, length: 3, // dart format off - mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mapping: [1, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [0, 1, 2], // dart format on factor: 1, @@ -2637,15 +2778,15 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, start: 3, - length: 26, + length: 28, // dart format off - mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28], + mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30], // dart format on factor: 1, offset: 0, - min: -33554432, - max: 33554432, + min: -134217727, + max: 134217727, unit: '', ); @@ -2654,16 +2795,16 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { signalSignedness: $_dbc.DBCSignalSignedness.SIGNED, signalType: $_dbc.DBCSignalType.INTEL, signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 29, - length: 26, + start: 31, + length: 28, // dart format off - mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 0], - mappingIndexes: [29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54], + mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 0, 0, 0, 0, 0], + mappingIndexes: [31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58], // dart format on factor: 1, offset: 0, - min: -33554432, - max: 3355443208, + min: -134217727, + max: 134217727, unit: '', ); @@ -2746,7 +2887,7 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { int messageLength = 5; @override - int canId = 0x37; + int canId = 0x307; /// Whether or not "Arm_Motor_Angle_Data" is multiplex static const bool isMultiplex = false; @@ -2792,7 +2933,7 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mappingIndexes: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], // dart format on - factor: 0.00009587379, + factor: 0.00009587664418469802, offset: 0, min: -3.14159, max: 3.14159, @@ -2810,7 +2951,7 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { mapping: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 0, 0, 0, 0, 0], mappingIndexes: [19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34], // dart format on - factor: 0.00009587379, + factor: 0.00009587664418469802, offset: 0, min: -3.14159, max: 3.14159, @@ -2887,144 +3028,3 @@ class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { String toString() => 'Arm_Motor_Angle_Data(\n Motor_Value=$motorValue\n Current_Angle=$currentAngle\n Target_Angle=$targetAngle\n)'; } - -class ArmSetSystemActionMessage extends $_dbc.DBCMessage { - @override - String messageName = 'Arm_Set_System_Action'; - - @override - int messageLength = 1; - - @override - int canId = 0x31; - - /// Whether or not "Arm_Set_System_Action" is multiplex - static const bool isMultiplex = false; - - /// The multiplexor for "Arm_Set_System_Action" - static const String multiplexor = ''; - - /// Value of signal "Stop" - int stop; - - /// Value of signal "Calibrate" - int calibrate; - - /// Value of signal "Jab" - int jab; - - final $_dbc.DBCSignal _stopSignal = $_dbc.DBCSignal( - name: 'Stop', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 0, - length: 1, - // dart format off - mapping: [1, 0, 0, 0, 0, 0, 0, 0], - mappingIndexes: [0], - // dart format on - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _calibrateSignal = $_dbc.DBCSignal( - name: 'Calibrate', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 1, - length: 1, - // dart format off - mapping: [0, 1, 0, 0, 0, 0, 0, 0], - mappingIndexes: [1], - // dart format on - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - final $_dbc.DBCSignal _jabSignal = $_dbc.DBCSignal( - name: 'Jab', - signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, - signalType: $_dbc.DBCSignalType.INTEL, - signalMode: $_dbc.DBCSignalMode.SIGNAL, - start: 2, - length: 1, - // dart format off - mapping: [0, 0, 1, 0, 0, 0, 0, 0], - mappingIndexes: [2], - // dart format on - factor: 1, - offset: 0, - min: 0, - max: 1, - unit: '', - ); - - @override - List<$_dbc.DBCSignal> get signals => [ - _stopSignal, - _calibrateSignal, - _jabSignal, - ]; - - ArmSetSystemActionMessage({this.stop = 0, this.calibrate = 0, this.jab = 0}); - - /// Creates a clone of this [ArmSetSystemActionMessage] with the non-null values replaced - ArmSetSystemActionMessage copyWith({int? stop, int? calibrate, int? jab}) => - ArmSetSystemActionMessage( - stop: stop ?? this.stop, - calibrate: calibrate ?? this.calibrate, - jab: jab ?? this.jab, - ); - - factory ArmSetSystemActionMessage.decode(List payload) { - final message = ArmSetSystemActionMessage(); - final typedBuffer = $_typed.Uint8List.fromList(payload); - final bitField = $_dbc.BitField.from( - typedBuffer.sublist(0, message.messageLength), - ); - - message.stop = (message._stopSignal.decode(bitField) ?? 0).toInt(); - message.calibrate = (message._calibrateSignal.decode(bitField) ?? 0) - .toInt(); - message.jab = (message._jabSignal.decode(bitField) ?? 0).toInt(); - - return message; - } - - factory ArmSetSystemActionMessage.fromJson(Map json) => - ArmSetSystemActionMessage( - stop: json['Stop'] ?? 0, - calibrate: json['Calibrate'] ?? 0, - jab: json['Jab'] ?? 0, - ); - - @override - $_typed.Uint8List encode() { - final Map<$_dbc.DBCSignal, num> values = { - _stopSignal: stop, - _calibrateSignal: calibrate, - _jabSignal: jab, - }; - - return encodeWithValues(values); - } - - @override - Map toJson() => { - 'Stop': stop, - 'Calibrate': calibrate, - 'Jab': jab, - }; - - @override - String toString() => - 'Arm_Set_System_Action(\n Stop=$stop\n Calibrate=$calibrate\n Jab=$jab\n)'; -} From 9c2768f34778fcdc36c68c2a557d7b21f7b9cc90 Mon Sep 17 00:00:00 2001 From: Gold87 <91761103+Gold872@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:21:40 -0500 Subject: [PATCH 30/30] Cleanup and regenerate --- subsystems/lib/src/devices/can_bus.dart | 59 +++--- .../lib/src/generated/rover_messages.dbc.dart | 177 +++++++++++++----- subsystems/lib/src/utils/dbc_conversions.dart | 23 +-- subsystems/lib/subsystems.dart | 1 - 4 files changed, 167 insertions(+), 93 deletions(-) diff --git a/subsystems/lib/src/devices/can_bus.dart b/subsystems/lib/src/devices/can_bus.dart index 92426e01..a6191ea4 100644 --- a/subsystems/lib/src/devices/can_bus.dart +++ b/subsystems/lib/src/devices/can_bus.dart @@ -9,13 +9,13 @@ import "package:subsystems/src/generated/rover_messages.dbc.dart"; import "package:subsystems/src/utils/dbc_conversions.dart"; import "package:subsystems/subsystems.dart" hide CanSocket; -/// Map of command names and a function to convert a message for that device into a list of DBC messages -final Map Function(Message message)> deviceToDBC = { - DriveCommand().messageName: (e) => (e as DriveCommand).toDBC(), - RelaysCommand().messageName: (e) => (e as RelaysCommand).toDBC(), - ArmCommand().messageName: (e) => (e as ArmCommand).toDBC(), - GripperCommand().messageName: (e) => [], - ScienceCommand().messageName: (e) => [], +/// Utility method to convert a message into a list of DBC messages +List getDBCMessages(Message message) => switch (message) { + final DriveCommand m => m.toDBC(), + final RelaysCommand m => m.toDBC(), + final ArmCommand m => m.toDBC(), + final ScienceCommand _ => [], + _ => [], }; /// A map of CAN IDs to a function to convert them into a protobuf message @@ -32,6 +32,8 @@ final Map data)> canIDToMessage = { DriveMotorDataMessage.decode(data).toDriveProto(), RelayStateDataMessage().canId: (data) => RelayStateDataMessage.decode(data).toRelayProto(), + RelayBatteryDataMessage().canId: (data) => + RelayBatteryDataMessage.decode(data).toRelayProto(), ArmMotorMoveDataMessage().canId: (data) => ArmMotorMoveDataMessage.decode(data).toArmProto(), ArmMotorStepDataMessage().canId: (data) => @@ -47,8 +49,6 @@ extension on DeviceBroadcastMessage { Message toArmProto() => ArmData(version: version); - Message toGripperProto() => GripperData(version: version); - Message toScienceProto() => ScienceData(version: version); Message? toProtoMessage() { @@ -58,8 +58,6 @@ extension on DeviceBroadcastMessage { return toRelayProto(); } else if (deviceValue == Device.ARM.value) { return toArmProto(); - } else if (deviceValue == Device.GRIPPER.value) { - return toGripperProto(); } else if (deviceValue == Device.SCIENCE.value) { return toScienceProto(); } @@ -234,8 +232,6 @@ class CanBus extends Service { return sendMessage(RelaysCommand.fromBuffer(message.data)); } else if (message.name == ArmCommand().messageName) { return sendMessage(ArmCommand.fromBuffer(message.data)); - } else if (message.name == GripperCommand().messageName) { - return sendMessage(GripperCommand.fromBuffer(message.data)); } else if (message.name == ScienceCommand().messageName) { return sendMessage(ScienceCommand.fromBuffer(message.data)); } @@ -246,15 +242,14 @@ class CanBus extends Service { /// /// Returns whether or not the message was sent over the bus Future sendMessage(Message message) { - if (!commandToDevice.containsKey(message.messageName) || - !deviceToDBC.containsKey(message.messageName)) { + final device = commandToDevice[message.messageName]; + if (device == null) { return Future.value(false); } - final device = commandToDevice[message.messageName]!; return _sendDeviceCommand( device: device, - dbcMessages: deviceToDBC[message.messageName]!.call(message), + dbcMessages: getDBCMessages(message), ); } @@ -358,19 +353,23 @@ class CanBus extends Service { } void _onCanFrame(CanFrame frame) { - switch (frame) { - case CanDataFrame(:final id, :final data): - if (canIDToMessage.containsKey(id)) { - collection.server.sendMessage(canIDToMessage[id]!.call(data)); - } else if (id != 0 && id & 0x0FF == DeviceBroadcastMessage().canId) { - _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); - } else { - logger.warning( - "Received message with unmapped ID: 0x${id.toRadixString(16).padLeft(2, '0')}", - ); - } - case CanRemoteFrame _: - break; + if (frame is! CanDataFrame) return; + + final id = frame.id; + final data = frame.data; + + if (canIDToMessage[id] case final constructor?) { + collection.server.sendMessage(constructor(data)); + return; } + + if (id != 0 && (id & 0xFF) == DeviceBroadcastMessage().canId) { + _handleDeviceBroadcast(DeviceBroadcastMessage.decode(data)); + return; + } + + logger.warning( + "Received message with unmapped ID: 0x${id.toRadixString(16).padLeft(2, '0')}", + ); } } diff --git a/subsystems/lib/src/generated/rover_messages.dbc.dart b/subsystems/lib/src/generated/rover_messages.dbc.dart index 0e2db0ff..c03fb1cc 100644 --- a/subsystems/lib/src/generated/rover_messages.dbc.dart +++ b/subsystems/lib/src/generated/rover_messages.dbc.dart @@ -12,13 +12,13 @@ import 'package:dart_dbc_generator/dart_dbc_generator.dart' as $_dbc; class DeviceBroadcastMessage extends $_dbc.DBCMessage { @override - String messageName = 'Device_Broadcast'; + final String messageName = 'Device_Broadcast'; @override - int messageLength = 2; + final int messageLength = 2; @override - int canId = 0x0; + final int canId = 0x0; /// Whether or not "Device_Broadcast" is multiplex static const bool isMultiplex = false; @@ -162,13 +162,13 @@ class DeviceBroadcastMessage extends $_dbc.DBCMessage { class RoverHeartbeatMessage extends $_dbc.DBCMessage { @override - String messageName = 'Rover_Heartbeat'; + final String messageName = 'Rover_Heartbeat'; @override - int messageLength = 1; + final int messageLength = 1; @override - int canId = 0x1; + final int canId = 0x1; /// Whether or not "Rover_Heartbeat" is multiplex static const bool isMultiplex = false; @@ -238,13 +238,13 @@ class RoverHeartbeatMessage extends $_dbc.DBCMessage { class DriveSetSpeedsMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Set_Speeds'; + final String messageName = 'Drive_Set_Speeds'; @override - int messageLength = 7; + final int messageLength = 7; @override - int canId = 0x101; + final int canId = 0x101; /// Whether or not "Drive_Set_Speeds" is multiplex static const bool isMultiplex = false; @@ -478,13 +478,13 @@ class DriveSetSpeedsMessage extends $_dbc.DBCMessage { class DriveSetLedMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Set_LED'; + final String messageName = 'Drive_Set_LED'; @override - int messageLength = 1; + final int messageLength = 1; @override - int canId = 0x102; + final int canId = 0x102; /// Whether or not "Drive_Set_LED" is multiplex static const bool isMultiplex = false; @@ -580,13 +580,13 @@ class DriveSetLedMessage extends $_dbc.DBCMessage { class DriveSetSwivelMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Set_Swivel'; + final String messageName = 'Drive_Set_Swivel'; @override - int messageLength = 7; + final int messageLength = 7; @override - int canId = 0x103; + final int canId = 0x103; /// Whether or not "Drive_Set_Swivel" is multiplex static const bool isMultiplex = false; @@ -880,13 +880,13 @@ class DriveSetSwivelMessage extends $_dbc.DBCMessage { class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Applied_Output_Data'; + final String messageName = 'Drive_Applied_Output_Data'; @override - int messageLength = 6; + final int messageLength = 6; @override - int canId = 0x105; + final int canId = 0x105; /// Whether or not "Drive_Applied_Output_Data" is multiplex static const bool isMultiplex = false; @@ -1030,13 +1030,13 @@ class DriveAppliedOutputDataMessage extends $_dbc.DBCMessage { class DriveBatteryDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Battery_Data'; + final String messageName = 'Drive_Battery_Data'; @override - int messageLength = 5; + final int messageLength = 5; @override - int canId = 0x106; + final int canId = 0x106; /// Whether or not "Drive_Battery_Data" is multiplex static const bool isMultiplex = false; @@ -1178,13 +1178,13 @@ class DriveBatteryDataMessage extends $_dbc.DBCMessage { class DriveLedDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_LED_Data'; + final String messageName = 'Drive_LED_Data'; @override - int messageLength = 1; + final int messageLength = 1; @override - int canId = 0x107; + final int canId = 0x107; /// Whether or not "Drive_LED_Data" is multiplex static const bool isMultiplex = false; @@ -1280,13 +1280,13 @@ class DriveLedDataMessage extends $_dbc.DBCMessage { class DriveSwivelDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Swivel_Data'; + final String messageName = 'Drive_Swivel_Data'; @override - int messageLength = 6; + final int messageLength = 6; @override - int canId = 0x108; + final int canId = 0x108; /// Whether or not "Drive_Swivel_Data" is multiplex static const bool isMultiplex = false; @@ -1460,13 +1460,13 @@ class DriveSwivelDataMessage extends $_dbc.DBCMessage { class DriveMotorDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Drive_Motor_Data'; + final String messageName = 'Drive_Motor_Data'; @override - int messageLength = 6; + final int messageLength = 6; @override - int canId = 0x109; + final int canId = 0x109; /// Whether or not "Drive_Motor_Data" is multiplex static const bool isMultiplex = false; @@ -1668,13 +1668,13 @@ class DriveMotorDataMessage extends $_dbc.DBCMessage { class RelaySetStateMessage extends $_dbc.DBCMessage { @override - String messageName = 'Relay_Set_State'; + final String messageName = 'Relay_Set_State'; @override - int messageLength = 2; + final int messageLength = 2; @override - int canId = 0x201; + final int canId = 0x201; /// Whether or not "Relay_Set_State" is multiplex static const bool isMultiplex = false; @@ -1935,13 +1935,13 @@ class RelaySetStateMessage extends $_dbc.DBCMessage { class RelayStateDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Relay_State_Data'; + final String messageName = 'Relay_State_Data'; @override - int messageLength = 1; + final int messageLength = 1; @override - int canId = 0x205; + final int canId = 0x205; /// Whether or not "Relay_State_Data" is multiplex static const bool isMultiplex = false; @@ -2230,15 +2230,90 @@ class RelayStateDataMessage extends $_dbc.DBCMessage { 'Relay_State_Data(\n Front_Left_Motor=$frontLeftMotor\n Front_Right_Motor=$frontRightMotor\n Back_Left_Motor=$backLeftMotor\n Back_Right_Motor=$backRightMotor\n Drive=$drive\n Arm=$arm\n Science=$science\n Physical_Override=$physicalOverride\n)'; } +class RelayBatteryDataMessage extends $_dbc.DBCMessage { + @override + final String messageName = 'Relay_Battery_Data'; + + @override + final int messageLength = 2; + + @override + final int canId = 0x206; + + /// Whether or not "Relay_Battery_Data" is multiplex + static const bool isMultiplex = false; + + /// The multiplexor for "Relay_Battery_Data" + static const String multiplexor = ''; + + /// Value of signal "Voltage" + double voltage; + + final $_dbc.DBCSignal _voltageSignal = $_dbc.DBCSignal( + name: 'Voltage', + signalSignedness: $_dbc.DBCSignalSignedness.UNSIGNED, + signalType: $_dbc.DBCSignalType.INTEL, + signalMode: $_dbc.DBCSignalMode.SIGNAL, + start: 0, + length: 10, + // dart format off + mapping: [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 0, 0, 0, 0, 0, 0], + mappingIndexes: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], + // dart format on + factor: 0.03548387097, + offset: 0, + min: 0, + max: 36.3, + unit: 'V', + ); + + @override + List<$_dbc.DBCSignal> get signals => [_voltageSignal]; + + RelayBatteryDataMessage({this.voltage = 0}); + + /// Creates a clone of this [RelayBatteryDataMessage] with the non-null values replaced + RelayBatteryDataMessage copyWith({double? voltage}) => + RelayBatteryDataMessage(voltage: voltage ?? this.voltage); + + factory RelayBatteryDataMessage.decode(List payload) { + final message = RelayBatteryDataMessage(); + final typedBuffer = $_typed.Uint8List.fromList(payload); + final bitField = $_dbc.BitField.from( + typedBuffer.sublist(0, message.messageLength), + ); + + message.voltage = (message._voltageSignal.decode(bitField) ?? 0).toDouble(); + + return message; + } + + factory RelayBatteryDataMessage.fromJson(Map json) => + RelayBatteryDataMessage(voltage: json['Voltage'] ?? 0); + + @override + $_typed.Uint8List encode() { + final Map<$_dbc.DBCSignal, num> values = {_voltageSignal: voltage}; + + return encodeWithValues(values); + } + + @override + Map toJson() => {'Voltage': voltage}; + + @override + String toString() => 'Relay_Battery_Data(\n Voltage=$voltage\n)'; +} + class ArmSetMotorMessage extends $_dbc.DBCMessage { @override - String messageName = 'Arm_Set_Motor'; + final String messageName = 'Arm_Set_Motor'; @override - int messageLength = 8; + final int messageLength = 8; @override - int canId = 0x301; + final int canId = 0x301; /// Whether or not "Arm_Set_Motor" is multiplex static const bool isMultiplex = false; @@ -2411,13 +2486,13 @@ class ArmSetMotorMessage extends $_dbc.DBCMessage { class ArmSetSystemActionMessage extends $_dbc.DBCMessage { @override - String messageName = 'Arm_Set_System_Action'; + final String messageName = 'Arm_Set_System_Action'; @override - int messageLength = 1; + final int messageLength = 1; @override - int canId = 0x302; + final int canId = 0x302; /// Whether or not "Arm_Set_System_Action" is multiplex static const bool isMultiplex = false; @@ -2552,13 +2627,13 @@ class ArmSetSystemActionMessage extends $_dbc.DBCMessage { class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Arm_Motor_Move_Data'; + final String messageName = 'Arm_Motor_Move_Data'; @override - int messageLength = 2; + final int messageLength = 2; @override - int canId = 0x305; + final int canId = 0x305; /// Whether or not "Arm_Motor_Move_Data" is multiplex static const bool isMultiplex = false; @@ -2731,13 +2806,13 @@ class ArmMotorMoveDataMessage extends $_dbc.DBCMessage { class ArmMotorStepDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Arm_Motor_Step_Data'; + final String messageName = 'Arm_Motor_Step_Data'; @override - int messageLength = 8; + final int messageLength = 8; @override - int canId = 0x306; + final int canId = 0x306; /// Whether or not "Arm_Motor_Step_Data" is multiplex static const bool isMultiplex = false; @@ -2881,13 +2956,13 @@ class ArmMotorStepDataMessage extends $_dbc.DBCMessage { class ArmMotorAngleDataMessage extends $_dbc.DBCMessage { @override - String messageName = 'Arm_Motor_Angle_Data'; + final String messageName = 'Arm_Motor_Angle_Data'; @override - int messageLength = 5; + final int messageLength = 5; @override - int canId = 0x307; + final int canId = 0x307; /// Whether or not "Arm_Motor_Angle_Data" is multiplex static const bool isMultiplex = false; diff --git a/subsystems/lib/src/utils/dbc_conversions.dart b/subsystems/lib/src/utils/dbc_conversions.dart index a0378b6a..45ff7e5c 100644 --- a/subsystems/lib/src/utils/dbc_conversions.dart +++ b/subsystems/lib/src/utils/dbc_conversions.dart @@ -42,8 +42,7 @@ extension DriveBatteryToProto on DriveBatteryDataMessage { /// Utility extension to convert a [DriveLedDataMessage] into a [DriveData] message extension DriveLedToProto on DriveLedDataMessage { /// The led DBC message as a [DriveData] message - DriveData toDriveProto() => - DriveData(color: ProtoColor.valueOf(color)); + DriveData toDriveProto() => DriveData(color: ProtoColor.valueOf(color)); } /// Utility extension to convert a [DriveSwivelDataMessage] into a [DriveData] message @@ -127,7 +126,7 @@ extension DriveCommandToDBC on DriveCommand { ]; } -/// Utility extension to convert a [RelayStateDataMessage] to a +/// Utility extension to convert a [RelayStateDataMessage] to a [RelaysData] extension RelayStateToProto on RelayStateDataMessage { BoolState _intToBoolState(num value) => value == 1 ? BoolState.YES : BoolState.NO; @@ -144,6 +143,12 @@ extension RelayStateToProto on RelayStateDataMessage { ); } +/// Utilitiy extension to convert a [RelayBatteryDataMessage] to a [RelaysData] +extension RelayBatteryToProto on RelayBatteryDataMessage { + /// The relay battery DBC message as a [RelaysData] message + RelaysData toRelayProto() => RelaysData(); +} + /// Utility extension to convert a [RelaysCommand] command into its respective [DBCMessage] extension RelaysCommandToDBC on RelaysCommand { /// The relays command as a [RelaySetStateMessage] DBC message @@ -189,10 +194,8 @@ extension ArmMotorMoveToProto on ArmMotorMoveDataMessage { /// Utility extension to convert a [ArmMotorStepDataMessage] into a [DriveData] message extension ArmMotorStepToProto on ArmMotorStepDataMessage { /// The motor steps DBC message as a [MotorData] message - MotorData toMotorData() => MotorData( - currentStep: currentStep, - targetStep: targetStep, - ); + MotorData toMotorData() => + MotorData(currentStep: currentStep, targetStep: targetStep); /// The motor steps DBC message as a [MotorData] message ArmData toArmProto() { @@ -213,10 +216,8 @@ extension ArmMotorStepToProto on ArmMotorStepDataMessage { /// Utility extension to convert a [ArmMotorAngleDataMessage] into a [ArmMotor] message extension ArmMotorAngleToProto on ArmMotorAngleDataMessage { /// The motor angle DBC message as a [MotorData] message - MotorData toMotorData() => MotorData( - currentAngle: currentAngle, - targetAngle: targetAngle, - ); + MotorData toMotorData() => + MotorData(currentAngle: currentAngle, targetAngle: targetAngle); /// The motor angle DBC message as an [ArmData] message ArmData toArmProto() { diff --git a/subsystems/lib/subsystems.dart b/subsystems/lib/subsystems.dart index d792d09b..da13a682 100644 --- a/subsystems/lib/subsystems.dart +++ b/subsystems/lib/subsystems.dart @@ -20,7 +20,6 @@ export "src/can/socket_stub.dart"; /// Maps command names to [Device]s. final commandToDevice = { ArmCommand().messageName: Device.ARM, - GripperCommand().messageName: Device.GRIPPER, DriveCommand().messageName: Device.DRIVE, ScienceCommand().messageName: Device.SCIENCE, RelaysCommand().messageName: Device.RELAY,