Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

V3 bundles #5

Merged
merged 8 commits into from
Feb 20, 2016
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override async Task RefreshAsync()

private async Task LoadAppsAsync()
{
var appBankContents = await Pebble.GetAppbankContentsAsync();
var appBankContents = await Pebble.InstallClient.GetAppbankContentsAsync();
Apps.Clear();
if (appBankContents != null && appBankContents.AppBank != null && appBankContents.AppBank.Apps != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<ProjectReference Include="..\..\PebbleSharp.Core\PebbleSharp.Core.csproj">
<ProjectReference Include="..\..\..\PebbleSharp.Core\PebbleSharp.Core.csproj">
<Project>{ae0f69ff-97c2-4e55-a3c9-b73e68668dda}</Project>
<Name>PebbleSharp.Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\PebbleSharp.WinRT\PebbleSharp.WinRT.csproj">
<ProjectReference Include="..\..\..\PebbleSharp.WinRT\PebbleSharp.WinRT.csproj">
<Project>{c6f33ca9-eed4-4553-ae74-cd77e6bf3d75}</Project>
<Name>PebbleSharp.WinRT</Name>
</ProjectReference>
Expand Down
2 changes: 1 addition & 1 deletion Demo/PebbleSharp.WPF/PebbleSharp.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Messages\PebbleDisconnected.cs" />
<Compile Include="Util\NativeMethods.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="ViewModels\PebbleAppsViewModel.cs" />
Expand Down Expand Up @@ -100,7 +101,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Messages\PebbleConnected.cs" />
<Compile Include="Messages\PebbleDisconnected.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
Expand Down
8 changes: 5 additions & 3 deletions Demo/PebbleSharp.WPF/ViewModels/PebbleAppsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Input;
using GalaSoft.MvvmLight.Command;
using Microsoft.Win32;
using PebbleSharp.Core;
using PebbleSharp.Core.Bundles;
using PebbleSharp.WPF.Messages;
using PebbleSharp.Net45;
Expand Down Expand Up @@ -58,7 +59,7 @@ private async Task LoadAppsAsync()
return;

Loading = true;
var appBankContents = await _pebble.GetAppbankContentsAsync();
var appBankContents = await _pebble.InstallClient.GetAppbankContentsAsync();
_apps.Clear();
if ( appBankContents.Success )
foreach ( var app in appBankContents.AppBank.Apps )
Expand Down Expand Up @@ -91,12 +92,13 @@ private async void OnInstallApp()
var bundle = new AppBundle();
using (var zip = new Zip())
{
bundle.Load(openDialog.OpenFile(), zip);
zip.Open(openDialog.OpenFile());
bundle.Load(zip,_pebble.Firmware.HardwarePlatform.GetSoftwarePlatform());
}

if ( _pebble.IsAlive == false )
return;
await _pebble.InstallAppAsync( bundle );
await _pebble.InstallClient.InstallAppAsync( bundle );
await LoadAppsAsync();
}
}
Expand Down
5 changes: 3 additions & 2 deletions Demo/PebbleSharp.WPF/ViewModels/PebbleInfoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ private async void OnUpdateFirmware()
var bundle = new FirmwareBundle();
using (var zip = new Zip())
{
bundle.Load(openDialog.OpenFile(), zip);
zip.Open(openDialog.OpenFile());
bundle.Load(zip,_pebble.Firmware.HardwarePlatform.GetSoftwarePlatform());
}

if (_pebble.IsAlive == false)
return;
await _pebble.InstallFirmwareAsync(bundle);
await _pebble.InstallClient.InstallFirmwareAsync(bundle);
}
}

Expand Down
Binary file added PebbleCmd/AppMessageTest.pbw
Binary file not shown.
3 changes: 3 additions & 0 deletions PebbleCmd/PebbleCmd.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="AppMessageTest.pbw">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PebbleSharp.Core\PebbleSharp.Core.csproj">
Expand Down
132 changes: 131 additions & 1 deletion PebbleCmd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
using System.Threading.Tasks;
using PebbleSharp.Core;
using PebbleSharp.Core.Responses;
using System.IO;
using PebbleSharp.Net45;
using PebbleSharp.Core.Bundles;
using PebbleSharp.Core.AppMessage;

namespace PebbleCmd
{
Expand All @@ -29,6 +32,7 @@ private static async Task ShowPebbles()
if ( result >= 0 && result < pebbles.Count )
{
var selectedPebble = pebbles[result];
selectedPebble.RegisterCallback<AppMessagePacket>(ReceiveAppMessage);
Console.WriteLine( "Connecting to Pebble " + selectedPebble.PebbleID );
await selectedPebble.ConnectAsync();
Console.WriteLine( "Connected" );
Expand All @@ -44,7 +48,9 @@ private static async Task ShowPebbleMenu( Pebble pebble )
"Set Current Time",
"Get Firmware Info",
"Send Ping",
"Media Commands" );
"Media Commands",
"Install App",
"Send App Message");
while ( true )
{
switch ( menu.ShowMenu() )
Expand Down Expand Up @@ -72,8 +78,127 @@ private static async Task ShowPebbleMenu( Pebble pebble )
case 5:
ShowMediaCommands( pebble );
break;
case 6:
InstallApp(pebble);
break;
case 7:
SendAppMessage(pebble);
break;
}
}
}

private static string SelectApp()
{
string exePath = System.Reflection.Assembly.GetExecutingAssembly ().CodeBase;
//TODO: there has to be a better way to come up with a canonical path, but this combo seems to work on both windows and 'nix
if (exePath.StartsWith("file:"))
{
exePath = exePath.Substring(5);
}
if (exePath.StartsWith("///"))
{
exePath = exePath.Substring(3);
}
string exeDir = Path.GetDirectoryName (exePath);
var dir = new DirectoryInfo (exeDir);
var files = dir.GetFiles ("*.pbw");

if (files.Any())
{
if (files.Count() == 1)
{
return files.Single().FullName;
}
else
{
var fileMenu = new Menu(files.Select(x => x.Name).ToArray());
int index = fileMenu.ShowMenu();
return files[index].FullName;
}
}
else
{
Console.WriteLine("No .pbw files found");
return null;
}
}

private static void InstallApp(Pebble pebble)
{
var progress = new Progress<ProgressValue>(pv => Console.WriteLine(pv.ProgressPercentage + " " + pv.Message));

string appPath = SelectApp();

if (!string.IsNullOrEmpty(appPath) && File.Exists(appPath))
{
using (var stream = new FileStream(appPath, FileMode.Open))
{
using (var zip = new Zip())
{
zip.Open(stream);
var bundle = new AppBundle();
stream.Position = 0;
bundle.Load(zip,pebble.Firmware.HardwarePlatform.GetSoftwarePlatform());
pebble.InstallClient.InstallAppAsync(bundle, progress).Wait();

//for firmware v3, launch is done as part of the install
//Console.WriteLine("App Installed, launching...");
//var uuid=new UUID(bundle.AppInfo.UUID);
//pebble.LaunchApp(uuid);
//Console.WriteLine ("Launched");
}
}
}
else
{
Console.WriteLine("No .pbw");
}
}

private static void SendAppMessage(Pebble pebble)
{
string uuidAppPath = SelectApp();

if (!string.IsNullOrEmpty(uuidAppPath) && File.Exists(uuidAppPath))
{
using (var stream = new FileStream(uuidAppPath, FileMode.Open))
{
using (var zip = new Zip())
{
zip.Open(stream);
var bundle = new AppBundle();
stream.Position = 0;
bundle.Load(zip,pebble.Firmware.HardwarePlatform.GetSoftwarePlatform());

System.Console.Write("Enter Message:");
var messageText = System.Console.ReadLine();

//format a message
var rand = new Random().Next();
AppMessagePacket message = new AppMessagePacket();
message.Command = (byte)Command.Push;
message.Values.Add(new AppMessageUInt32() { Key=0,Value = (uint)rand });
message.Values.Add(new AppMessageString() { Key=1,Value = messageText });
message.ApplicationId = bundle.AppMetadata.UUID;
message.TransactionId = 255;


//send it
Console.WriteLine("Sending Status "+rand+" to " + bundle.AppMetadata.UUID.ToString());
var task = pebble.SendApplicationMessage(message);
task.Wait();
Console.WriteLine("Response received");
}
}



}
else
{
Console.WriteLine("No .pbw");
}
}

private static void ShowMediaCommands( Pebble pebble )
Expand Down Expand Up @@ -108,5 +233,10 @@ private static void DisplayResult<T>( T result, Func<T, string> successData )
Console.WriteLine( result.ErrorDetails.ToString() );
}
}

private static void ReceiveAppMessage(AppMessagePacket response)
{
System.Console.WriteLine("Recieved App Message");
}
}
}
4 changes: 2 additions & 2 deletions PebbleSharp.Core.Tests/AbstractTests/BaseCrc32Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public abstract class BaseCrc32Tests
protected void RunGeneratesCorrectChecksumForApp()
{
var bundle = new AppBundle();
bundle.Load(ResourceManager.GetAppBundle(), GetZip());
bundle.Load(GetZip(),SoftwarePlatform.UNKNOWN);

Assert.AreEqual(bundle.Manifest.Application.CRC, Crc32.Calculate(bundle.App));
}

protected void RunGeneratesCorrectChecksumForFirmware()
{
var bundle = new FirmwareBundle();
bundle.Load(ResourceManager.GetFirmwareBundle(), GetZip());
bundle.Load(GetZip(),SoftwarePlatform.UNKNOWN);

Assert.AreEqual(bundle.Manifest.Firmware.CRC, Crc32.Calculate(bundle.Firmware));
}
Expand Down
9 changes: 6 additions & 3 deletions PebbleSharp.Core.Tests/AbstractTests/BasePebbleBundleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ protected void RunCanLoadInformationFromAppBundle()
{
Stream testBundle = ResourceManager.GetAppBundle();
var bundle = new AppBundle();
bundle.Load( testBundle, GetZip() );
var zip = GetZip();
zip.Open(testBundle);
bundle.Load(zip,SoftwarePlatform.APLITE );

var manifest = bundle.Manifest;
Assert.IsNotNull( manifest );
Expand All @@ -40,7 +42,6 @@ protected void RunCanLoadInformationFromAppBundle()
Assert.AreEqual( (uint)0, bundle.AppMetadata.IconResourceID );
Assert.AreEqual( (uint)552, bundle.AppMetadata.Offset );
Assert.AreEqual( (uint)2, bundle.AppMetadata.RelocationListItemCount );
Assert.AreEqual( (uint)3860, bundle.AppMetadata.RelocationListStart );
Assert.AreEqual( 3, bundle.AppMetadata.SDKMajorVersion );
Assert.AreEqual( 1, bundle.AppMetadata.SDKMinorVersion );
Assert.AreEqual( "3.1", bundle.AppMetadata.SDKVersion );
Expand All @@ -57,7 +58,9 @@ protected void RunCanLoadInformationFromFirmwareBundle()
Stream testBundle = ResourceManager.GetFirmwareBundle();

var bundle = new FirmwareBundle();
bundle.Load( testBundle, GetZip() );
var zip = GetZip();
zip.Open(testBundle);
bundle.Load( zip,SoftwarePlatform.APLITE );

Assert.IsNotNull( bundle.Firmware );

Expand Down
1 change: 0 additions & 1 deletion PebbleSharp.Core.Tests/PebbleSharp.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<Compile Include="PebbleTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources\ResourceManager.cs" />
<Compile Include="Responses\ApplicationMessageResponseTests.cs" />
<Compile Include="Responses\ResponseGenerator.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions PebbleSharp.Core.Tests/PebbleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task InstallFirmwareAsyncRequiresBundle()
var bluetoothConnection = new Mock<IBluetoothConnection>();
var pebble = new TestPebble( bluetoothConnection.Object, TEST_PEBBLE_ID );

await pebble.InstallFirmwareAsync( null );
await pebble.InstallClient.InstallFirmwareAsync( null );
}

[TestMethod]
Expand Down Expand Up @@ -75,7 +75,7 @@ public async Task InstallFirmwareAsyncTest()

var pebble = new TestPebble( bluetoothConnection.Object, TEST_PEBBLE_ID );

bool success = await pebble.InstallFirmwareAsync( bundle.Object );
bool success = await pebble.InstallClient.InstallFirmwareAsync( bundle.Object );
Assert.IsTrue( success );
bluetoothConnection.Verify();
}
Expand Down
47 changes: 47 additions & 0 deletions PebbleSharp.Core/AppInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;

namespace PebbleSharp.Core
{
[DataContract]
public class AppInfo
{
//does exist in sdk3
[DataMember(Name = "versionCode", IsRequired = false)]
public int VersionCode { get; private set; }

[DataMember(Name = "sdkVersion", IsRequired = true)]
public string SdkVersion { get; private set; }

//[DataMember(Name = "capabilities", IsRequired = true)]
//public string[] Capabilities { get; private set; }

[DataMember(Name = "shortName", IsRequired = true)]
public string ShortName { get; private set; }

/// <summary> The manifest for the resources contained in this bundle. </summary>
//resources

//appKeys
//[DataMember(Name = "appKeys", IsRequired = true)]
//public Dictionary<string, int> AppKeys { get; set; }

[DataMember(Name = "uuid", IsRequired = true)]
public string UUID { get; private set; }

[DataMember(Name = "versionLabel", IsRequired = true)]
public string VersionLabel { get; private set; }

[DataMember(Name = "longName", IsRequired = true)]
public string LongName { get; private set; }

//watchapp

[DataMember(Name = "projectType", IsRequired = true)]
public string ProjectType { get; private set; }
}
}
Loading