parseResponse method
Parse the response bytes from the device.
Implementation
@override
VtjCommandResult<GetDeviceStateResult> parseResponse(Uint8List response) {
if (response.isEmpty) {
return const VtjCommandResult.failure('Empty response', null);
}
if (response[0] != commandId) {
return VtjCommandResult.failure(
'Invalid command ID in response',
null,
);
}
if (response.length < 2) {
return const VtjCommandResult.failure('Invalid response length', null);
}
final status = response[1];
if (status != 0x00) {
return VtjCommandResult.failure(
'Command failed with status: 0x${status.toRadixString(16).padLeft(2, '0')}',
status,
);
}
try {
final result = GetDeviceStateResult.fromBytes(response.sublist(2));
return VtjCommandResult.success(result);
} catch (e) {
return VtjCommandResult.failure(
'Failed to parse device state: $e',
null,
);
}
}