Skip to content

Commit bfe66ab

Browse files
authored
Merge pull request #18 from xboxoneresearch/fix/full_code_compatibility
fix: compatibility with new fw / full error codes
2 parents 44e1d61 + 027da9b commit bfe66ab

10 files changed

Lines changed: 32 additions & 48 deletions

File tree

PostCodeSerialMonitor.Tests/SerialDecoderTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ public class TestDataGenerator : IEnumerable<object[]>
1313
{
1414
private readonly List<object[]> _data = new List<object[]>
1515
{
16-
new object[] {"CPU (1): 0x14ff [2BL_FINAL_SUCCESS] (6683 ms)", new DecodedCode(){
16+
new object[] {"CPU: 0x14ff (+0.000 mS)", new DecodedCode(){
1717
Flavor = CodeFlavor.CPU,
18-
Index = 1,
1918
Code = 0x14ff
2019
}},
21-
new object[] {"SP (1): 0x0075 [BOOT_SUCCESS] (2423 ms)", new DecodedCode(){
20+
new object[] {"CPU: 0x14ff", new DecodedCode(){
21+
Flavor = CodeFlavor.CPU,
22+
Code = 0x14ff
23+
}},
24+
new object[] {"SP : 0x75 (+4252.064 mS)", new DecodedCode(){
25+
Flavor = CodeFlavor.SP,
26+
Code = 0x0075
27+
}},
28+
new object[] {"SP : 0x75", new DecodedCode(){
2229
Flavor = CodeFlavor.SP,
23-
Index = 1,
2430
Code = 0x0075
2531
}}
2632
};
@@ -86,7 +92,6 @@ public void TestDecoding(string input, DecodedCode expected)
8692
var result = _decoder.DecodeLine(input, ConsoleType.XboxOnePhat);
8793
Assert.NotNull(result);
8894
Assert.Equal(expected.Flavor, result.Flavor);
89-
Assert.Equal(expected.Index, result.Index);
9095
Assert.Equal(expected.Code, result.Code);
9196
}
9297
}

PostCodeSerialMonitor/Models/CsvConverters.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ public class HexNumberConverter : DefaultTypeConverter
1212
if (text == null || text == "")
1313
return null;
1414

15-
return Convert.ToUInt32(text, 16);
15+
return Convert.ToUInt64(text, 16);
1616
}
1717

1818
public override string? ConvertToString(object? value, IWriterRow row, MemberMapData memberMapData)
1919
{
2020
if (value == null)
2121
return null;
2222

23-
return $"0x{value:X4}";
23+
return $"0x{value:X8}";
2424
}
2525
}
2626

PostCodeSerialMonitor/Models/DecodedCode.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ namespace PostCodeSerialMonitor.Models;
44
public class DecodedCode
55
{
66
public CodeFlavor Flavor { get; set; }
7-
public int Index { get; set; }
8-
public int Code { get; set; }
7+
public UInt64 Code { get; set; }
98
public CodeSeverity SeverityLevel { get; set; } = CodeSeverity.Info;
109
public string Name { get; set; } = string.Empty;
1110
public string Description { get; set; } = string.Empty;
@@ -14,8 +13,7 @@ public override int GetHashCode()
1413
{
1514
var result = 0;
1615
result = (result * 397) ^ Convert.ToInt32(Flavor);
17-
result = (result * 397) ^ Index;
18-
result = (result * 397) ^ Code;
16+
result = (result * 397) ^ (int)Code;
1917
result = (result * 397) ^ Convert.ToInt32(SeverityLevel);
2018
return result;
2119
}
@@ -26,7 +24,6 @@ public bool Equals(DecodedCode obj)
2624
{
2725
return (
2826
this.Flavor == obj.Flavor
29-
&& this.Index == obj.Index
3027
&& this.Code == obj.Code
3128
&& this.SeverityLevel == obj.SeverityLevel
3229
);

PostCodeSerialMonitor/Models/ErrorMaskDefinition.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using CsvHelper.Configuration.Attributes;
23

34
namespace PostCodeSerialMonitor.Models;
@@ -12,10 +13,10 @@ public class ErrorMaskDefinition
1213
public CodeFlavor CodeFlavor { get; set; } = CodeFlavor.UNKNOWN;
1314

1415
[TypeConverter(typeof(HexNumberConverter))]
15-
public uint Bitmask { get; set; }
16+
public UInt64 Bitmask { get; set; }
1617

1718
[TypeConverter(typeof(HexNumberConverter))]
18-
public uint Code { get; set; }
19+
public UInt64 Code { get; set; }
1920

2021
public string Name { get; set; } = string.Empty;
2122
public string Description { get; set; } = string.Empty;

PostCodeSerialMonitor/Models/LogEntry.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public bool IsSelected
3131
public string CodeText => FormatCodeText();
3232
// Individual fields, for column-aligned display
3333
public string FlavorText => DecodedCode.Flavor.ToString();
34-
public string IndexText => $"({DecodedCode.Index}):";
3534
public string CodeHexText => $"{DecodedCode.Code:X4}";
3635
public string NameText => string.IsNullOrEmpty(DecodedCode?.Name) ? string.Empty : $"[{DecodedCode.Name}]";
3736
// Name + description on one line, for the truncated inline preview
@@ -48,7 +47,7 @@ public bool IsSelected
4847
private string FormatCodeText()
4948
{
5049
// Format flavor, index, and code with fixed spacing
51-
var formatted = $"{DecodedCode?.Flavor,-4} ({DecodedCode?.Index}): {DecodedCode?.Code,4:X4}";
50+
var formatted = $"{DecodedCode?.Flavor,-4}: {DecodedCode?.Code,4:X8}";
5251
if (!string.IsNullOrEmpty(DecodedCode?.Name))
5352
formatted += $" [{DecodedCode?.Name}]";
5453
return formatted;

PostCodeSerialMonitor/Models/OSErrorDefinition.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using CsvHelper.Configuration.Attributes;
23

34
namespace PostCodeSerialMonitor.Models;
@@ -13,7 +14,7 @@ public class OSErrorDefinition
1314
public CodeFlavor CodeFlavor { get; set; } = CodeFlavor.UNKNOWN;
1415

1516
[TypeConverter(typeof(HexNumberConverter))]
16-
public uint Code { get; set; }
17+
public UInt64 Code { get; set; }
1718

1819
public string Name { get; set; } = string.Empty;
1920
public string Description { get; set; } = string.Empty;

PostCodeSerialMonitor/Models/PostCodeDefinition.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using CsvHelper.Configuration.Attributes;
23

34
namespace PostCodeSerialMonitor.Models;
@@ -12,9 +13,9 @@ public class PostCodeDefinition
1213
public CodeFlavor CodeFlavor { get; set; } = CodeFlavor.UNKNOWN;
1314

1415
[TypeConverter(typeof(HexNumberConverter))]
15-
public uint Code { get; set; }
16+
public UInt64 Code { get; set; }
1617
[TypeConverter(typeof(HexNumberConverter))]
17-
public uint? Bitmask { get; set; }
18+
public UInt64? Bitmask { get; set; }
1819
public bool IsError { get; set; }
1920
public string Name { get; set; } = string.Empty;
2021
public string Description { get; set; } = string.Empty;

PostCodeSerialMonitor/Services/SerialLineDecoder.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class SerialLineDecoder
99
{
1010
private readonly MetaDefinitionService _metaDefinitionService;
1111
private readonly ILogger<SerialLineDecoder> _logger;
12-
private static readonly Regex regex = new Regex(@"^(SMC|SP|CPU|OS)\s+?\((\d)\)\s?\:\s?([x0-9a-fA-F]{6})");
12+
private static readonly Regex regex = new Regex(@"^(SMC|SP|CPU|OS)\s?\:\s?([x0-9a-fA-F]{4,})\s?");
1313

1414
public SerialLineDecoder(MetaDefinitionService metaDefinitionService, ILogger<SerialLineDecoder> logger)
1515
{
@@ -27,8 +27,7 @@ public SerialLineDecoder(MetaDefinitionService metaDefinitionService, ILogger<Se
2727
}
2828

2929
var codeFlavorStr = match.Groups[1].Value;
30-
var indexStr = match.Groups[2].Value;
31-
var codeStr = match.Groups[3].Value;
30+
var codeStr = match.Groups[2].Value;
3231

3332
var flavor = CodeFlavor.UNKNOWN;
3433
if (codeFlavorStr == "SMC")
@@ -40,24 +39,14 @@ public SerialLineDecoder(MetaDefinitionService metaDefinitionService, ILogger<Se
4039
else if (codeFlavorStr == "OS")
4140
flavor = CodeFlavor.OS;
4241

43-
var index = int.Parse(indexStr);
44-
var code = Convert.ToInt32(codeStr.Substring(2), 16);
42+
var code = Convert.ToUInt64(codeStr.Substring(2), 16);
4543

4644
var decoded = new DecodedCode()
4745
{
4846
Flavor = flavor,
49-
Index = index,
5047
Code = code
5148
};
5249

53-
// Until we have proper names for the E errors, bail out here early.
54-
if (flavor == CodeFlavor.OS && index == 1) {
55-
decoded.SeverityLevel = CodeSeverity.Error;
56-
decoded.Name = $"OS_ERROR_E{code}";
57-
decoded.Description = Assets.Resources.UemOsError;
58-
return decoded;
59-
}
60-
6150
// First: Try to find distinct code
6251
var postCode = _metaDefinitionService.PostCodes.FirstOrDefault(x =>
6352
x.Code == code &&

PostCodeSerialMonitor/ViewModels/DebugDialogViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void FillDummyData()
5454
{
5555
for (int i = 0; i < (int)EntryCount; i++)
5656
{
57-
var code = i * 0x11;
57+
var code = (UInt64)(i * 0x11);
5858
var segment = i % 4;
5959
var flavor = CodeFlavors[i % CodeFlavors.Count];
6060

@@ -65,7 +65,6 @@ private void FillDummyData()
6565
DecodedCode = new DecodedCode
6666
{
6767
Flavor = flavor,
68-
Index = segment,
6968
Code = code,
7069
SeverityLevel = (CodeSeverity)(i % 3),
7170
Name = $"DEBUG_CODE_{i}",
@@ -80,13 +79,13 @@ private void FillDummyData()
8079
[RelayCommand]
8180
private async Task DecodeStandaloneAsync()
8281
{
83-
int code;
82+
UInt64 code;
8483
try
8584
{
8685
var hex = CodeInput.Trim();
8786
if (hex.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
8887
hex = hex[2..];
89-
code = Convert.ToInt32(hex, 16) & 0xFFFF;
88+
code = Convert.ToUInt64(hex, 16);
9089
}
9190
catch (Exception)
9291
{

PostCodeSerialMonitor/Views/MainWindow.axaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,7 @@
229229
FontSize="16"
230230
Margin="0,0,4,0"
231231
VerticalAlignment="Top"/>
232-
<TextBlock Grid.Column="2" Text="{Binding IndexText}"
233-
Classes="logText"
234-
Classes.severity-warning="{Binding IsWarning}"
235-
Classes.severity-error="{Binding IsError}"
236-
FontFamily="Consolas,Menlo,Monospace"
237-
FontSize="16"
238-
Margin="0,0,4,0"
239-
VerticalAlignment="Top"/>
240-
<TextBlock Grid.Column="3" Text="{Binding CodeHexText}"
232+
<TextBlock Grid.Column="2" Text="{Binding CodeHexText}"
241233
Classes="logText"
242234
Classes.severity-warning="{Binding IsWarning}"
243235
Classes.severity-error="{Binding IsError}"
@@ -246,7 +238,7 @@
246238
Margin="0,0,4,0"
247239
VerticalAlignment="Top"/>
248240
<!-- NewLine / bottom-panel mode: just the name -->
249-
<TextBlock Grid.Column="4" Text="{Binding NameText}"
241+
<TextBlock Grid.Column="3" Text="{Binding NameText}"
250242
Classes="logText"
251243
Classes.severity-warning="{Binding IsWarning}"
252244
Classes.severity-error="{Binding IsError}"
@@ -256,7 +248,7 @@
256248
VerticalAlignment="Top"
257249
TextWrapping="Wrap"/>
258250
<!-- Inline mode: name + description, truncated with an ellipsis until expanded -->
259-
<TextBlock Grid.Column="4" Text="{Binding InlinePreviewText}"
251+
<TextBlock Grid.Column="3" Text="{Binding InlinePreviewText}"
260252
Classes="logText"
261253
Classes.severity-warning="{Binding IsWarning}"
262254
Classes.severity-error="{Binding IsError}"

0 commit comments

Comments
 (0)