Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PostCodeSerialMonitor/Assets/Resources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<comment>In Services/SerialService.cs</comment>
</data>
<data name="FailedFwVersion" xml:space="preserve">
<value>Falha ao processar a informação sobre a versão. Você está usando o firwmare v0.2.3 ou superior?</value>
<value>Falha na verificação da versão do firmware. Você está com o firmware mais recente do PicoDurangoPOST?</value>
<comment>In Services/SerialService.cs</comment>
</data>
<data name="FailedParseConfig" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion PostCodeSerialMonitor/Assets/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
<comment>In Services/SerialService.cs</comment>
</data>
<data name="FailedFwVersion" xml:space="preserve">
<value>Failed to parse version information. Are you on FW v0.2.3 or greater?</value>
<value>Firmware version check failed. Are you on latest PicoDurangoPOST FW?</value>
<comment>In Services/SerialService.cs</comment>
</data>
<data name="FailedParseConfig" xml:space="preserve">
Expand Down
18 changes: 17 additions & 1 deletion PostCodeSerialMonitor/Services/MetaUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class MetaUpdateService
private readonly HttpClient _httpClient;
private readonly ILogger<MetaUpdateService> _logger;
private const string META_FILENAME = "meta.json";
private const int SUPPORTED_META_FORMAT_VERSION = 2;
private MetaDefinition? _currentMeta;

public string LocalMetaPath => Path.Combine(_localPath, META_FILENAME);
Expand Down Expand Up @@ -130,6 +131,9 @@ private async Task DownloadMetaFilesAsync()
{
var json = await File.ReadAllTextAsync(LocalMetaPath);
var res = JsonSerializer.Deserialize<MetaDefinition>(json, _jsonSerializeOptions);
if (res != null && !IsSupportedFormatVersion(res))
return null;

_currentMeta = res;
return res;
}
Expand All @@ -148,12 +152,24 @@ private async Task DownloadMetaFilesAsync()
response.EnsureSuccessStatusCode();

var json = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<MetaDefinition>(json, _jsonSerializeOptions);
var res = JsonSerializer.Deserialize<MetaDefinition>(json, _jsonSerializeOptions);
return res != null && !IsSupportedFormatVersion(res) ? null : res;
}
catch (Exception ex)
{
_logger.LogError(ex, Assets.Resources.FailedDownloadMetaDefinition, Config.MetaJsonUrl);
return null;
}
}

private bool IsSupportedFormatVersion(MetaDefinition meta)
{
if (meta.FormatVersion == SUPPORTED_META_FORMAT_VERSION)
return true;

_logger.LogError(
"Metadata format version {ActualVersion} is not supported (expected {ExpectedVersion}). Please update the metadata.",
meta.FormatVersion, SUPPORTED_META_FORMAT_VERSION);
return false;
}
}
4 changes: 3 additions & 1 deletion PostCodeSerialMonitor/Services/SerialService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class SerialService : IDisposable
public event Action? DeviceStateChanged;
public event Action? DeviceConfigChanged;

public const string MinimumFirmwareVersion = "v0.4.0";

public string FirmwareVersion { get; private set; } = string.Empty;
public string BuildDate { get; private set; } = string.Empty;

Expand Down Expand Up @@ -167,7 +169,7 @@ public async Task ConnectAsync(string portName, int baudRate = 115200)
_serialPort.WriteLine("version");
Thread.Sleep(100);
success = await ParseVersionInfo();
if (!success)
if (!success || new SemanticVersion(FirmwareVersion) < new SemanticVersion(MinimumFirmwareVersion))
{
Disconnect();
throw new Exception(Assets.Resources.FailedFwVersion);
Expand Down
Loading