Skip to content

Commit

Permalink
release 1.7.3
Browse files Browse the repository at this point in the history
FOTA: flash top address configurable.
  • Loading branch information
zjli-2019 committed Apr 19, 2023
1 parent 5e2088d commit 13fbf0d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
13 changes: 10 additions & 3 deletions INGdemo/INGdemo/FOTA/OTA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ public enum OTAStatus
}

int FLASH_BASE { get { return (int)CurrentFlash.BaseAddr; } }
int FLASH_SIZE { get { return (int)CurrentFlash.TotalSize; } }
int FLASH_PAGE_SIZE { get { return (int)CurrentFlash.PageSize; } }
int FLASH_OTA_DATA_HIGH { get { return (int)CurrentFlash.BaseAddr + (int)CurrentFlash.TotalSize; } }

const int OTA_UPDATE_FLAG = 0x5A5A5A5A;
const int OTA_LOCK_FLAG = 0x5A5A5A5A;
Expand Down Expand Up @@ -245,11 +243,14 @@ public OTA(string url, IBleDriver driver)
this.driver = driver;
Bins = new List<OTABin>();
KeyUtils = new KeyUtils();
EmptyFlashTop = 0;
}

public bool Available { get { return driver.Available; } }
public OTAStatus Status { get => status; }

public uint EmptyFlashTop { get; set; }

public string UpdateInfo { get; set; }

public string LocalVersion { get { return Local != null ? Local.ToString() : "n/a"; } }
Expand Down Expand Up @@ -340,6 +341,12 @@ async Task CheckZipPack(byte []bytes)
SetStatus(OTAStatus.UpToDate);
}

public uint GetFlashTopAddress(int series)
{
var f = FlashInfos[series];
return f.BaseAddr + f.TotalSize;
}

async public Task CheckUpdateLocal(int series, byte[] bytes)
{
Latest = null;
Expand Down Expand Up @@ -464,7 +471,7 @@ async Task DecodePackage(byte []bytes)

protected virtual void MakeFlashProcedure()
{
int addr = FLASH_OTA_DATA_HIGH;
int addr = (int)EmptyFlashTop;
if (Bins.Count < 1)
return;

Expand Down
15 changes: 15 additions & 0 deletions INGdemo/INGdemo/FOTA/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,20 @@ public static string PrintHexTable(byte []v)
}
return string.Join("\n", r);
}

public static uint ParseInt(string s)
{
UInt32 r = 0;
if (s.StartsWith("0x") || s.StartsWith("0X"))
{
var hex = s.Substring(2);
r = UInt32.Parse(hex, NumberStyles.HexNumber);
}
else
{
UInt32.TryParse(s, out r);
}
return r;
}
}
}
28 changes: 26 additions & 2 deletions INGdemo/INGdemo/Models/OTAModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using INGota.FOTA;
using INGdemo.Models;
using System.Runtime.CompilerServices;

namespace INGota.Models
{
Expand Down Expand Up @@ -42,6 +43,7 @@ class ThermoFOTAViewer : ContentPage
IBleDriver driver;
WaitActivity Wait;
Entry urlInput;
Entry topAddressInput;
Picker seriesPicker;

async void InitUI(IDevice ADevice, IReadOnlyList<IService> services)
Expand All @@ -56,6 +58,10 @@ async void InitUI(IDevice ADevice, IReadOnlyList<IService> services)
server.Text = "FOTA Server";
server.Style = Device.Styles.TitleStyle;

var labelTopAddr = new Label();
labelTopAddr.Text = "Flash Top Address";
labelTopAddr.Style = Device.Styles.TitleStyle;

var secureInfo = new Label();

secureInfo.Style = Device.Styles.CaptionStyle;
Expand All @@ -82,12 +88,15 @@ await DisplayAlert("Alert",

urlInput = new Entry();
urlInput.Text = FOTA_SERVER;
topAddressInput = new Entry();
topAddressInput.Text = "0";

seriesPicker = new Picker { Title = "Select Chip Series:" };
seriesPicker.Items.Add("ING9188xx/ING9187xx");
seriesPicker.Items.Add("ING9168xx");
seriesPicker.SelectedIndex = 0;
seriesPicker.HorizontalOptions = LayoutOptions.FillAndExpand;
seriesPicker.SelectedIndexChanged += SeriesPicker_SelectedIndexChanged;

var seriesCont = new StackLayout();
seriesCont.Orientation = StackOrientation.Horizontal;
Expand All @@ -96,7 +105,9 @@ await DisplayAlert("Alert",
seriesCont.HorizontalOptions = LayoutOptions.FillAndExpand;

container.Margin = 10;
container.Children.Add(seriesCont);
container.Children.Add(seriesCont);
container.Children.Add(labelTopAddr);
container.Children.Add(topAddressInput);
container.Children.Add(server);
container.Children.Add(urlInput);

Expand Down Expand Up @@ -131,6 +142,18 @@ await DisplayAlert("Alert",
Summary.GestureRecognizers.Add(tapGestureRecognizer);
Summary_Tapped(null, null);
Action.Clicked += Action_Clicked;

UpdateFlashTopAddress();
}

private void UpdateFlashTopAddress()
{
topAddressInput.Text = "0x" + ota.GetFlashTopAddress(seriesPicker.SelectedIndex).ToString("X8");
}

private void SeriesPicker_SelectedIndexChanged(object sender, EventArgs e)
{
UpdateFlashTopAddress();
}

private async void Btn_Pressed(object sender, EventArgs e)
Expand Down Expand Up @@ -231,7 +254,7 @@ public ThermoFOTAViewer(IDevice ADevice, IReadOnlyList<IService> services)
ota.StatusChanged += Ota_StatusChanged;
ota.Progress += Ota_Progress;

InitUI(ADevice, services);
InitUI(ADevice, services);
}

private void Summary_Tapped(object sender, EventArgs e)
Expand Down Expand Up @@ -307,6 +330,7 @@ private async void Action_Clicked(object sender, EventArgs e)
{
BleDevice.UpdateConnectionInterval(ConnectionInterval.High);
int MtuSize = await BleDevice.RequestMtuAsync(250);
ota.EmptyFlashTop = Utils.ParseInt(topAddressInput.Text);
r = await ota.Update(Math.Max(23, MtuSize - 4));
}
finally
Expand Down
2 changes: 1 addition & 1 deletion INGdemo/INGdemo/Views/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<FormattedString.Spans>
<Span Text="ING BLE" FontAttributes="Bold" FontSize="22" />
<Span Text=" " />
<Span Text="1.7.2" ForegroundColor="{StaticResource LightTextColor}" />
<Span Text="1.7.3" ForegroundColor="{StaticResource LightTextColor}" />
</FormattedString.Spans>
</FormattedString>
</Label.FormattedText>
Expand Down

0 comments on commit 13fbf0d

Please sign in to comment.