Permalink
Browse files

fixed struct field offsets to work for raspbian / mono build

  • Loading branch information...
root
root committed Jul 9, 2015
1 parent 16e141c commit 1829bd3d2b3f6312389acd1955e61f525ccf45cd
Showing with 466 additions and 344 deletions.
  1. +7 −14 InTheHand.Net.Personal/InTheHand.Net.Personal.FX2.csproj
  2. +10 −0 InTheHand.Net.Personal/Net.Bluetooth.BlueZ/BluezClient.cs
  3. +0 −4 InTheHand.Net.Personal/Net.Bluetooth.BlueZ/BluezDbus.cs
  4. +75 −25 InTheHand.Net.Personal/Net.Bluetooth.BlueZ/BluezSdpQuery.cs
  5. +5 −1 InTheHand.Net.Personal/Net.Bluetooth.BlueZ/BluezUtils.cs
  6. +43 −29 InTheHand.Net.Personal/Net.Bluetooth.BlueZ/Structs.cs
  7. +12 −1 InTheHand.Net.Personal/Net.Bluetooth.Factory/BluetoothConnector.cs
  8. +17 −9 InTheHand.Net.Personal/Net.Bluetooth_Sdp2/ServiceRecordHelper.cs
  9. BIN InTheHand.Net.Personal/bin/Debug/InTheHand.Net.Personal.dll
  10. BIN InTheHand.Net.Personal/bin/Debug/InTheHand.Net.Personal.dll.mdb
  11. +7 −0 InTheHand.Net.Personal/obj/Debug/InTheHand.Net.Personal.FX2.csproj.FilesWrittenAbsolute.txt
  12. BIN InTheHand.Net.Personal/obj/Debug/InTheHand.Net.Personal.dll
  13. BIN InTheHand.Net.Personal/obj/Debug/InTheHand.Net.Personal.dll.mdb
  14. BIN InTheHand.Net.Personal/obj/Debug/InTheHand.Windows.Forms.SelectBluetoothDeviceForm.resources
  15. +5 −4 PebbleCmd/PebbleCmd.csproj
  16. +20 −12 PebbleCmd/Program.cs
  17. +1 −1 PebbleSharp.Core.NonPortable/PebbleSharp.Core.NonPortable.csproj
  18. BIN PebbleSharp.Core.NonPortable/bin/Debug/PebbleSharp.Core.NonPortable.dll
  19. BIN PebbleSharp.Core.NonPortable/bin/Debug/PebbleSharp.Core.NonPortable.dll.mdb
  20. +2 −0 PebbleSharp.Core.NonPortable/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
  21. +5 −0 PebbleSharp.Core.NonPortable/obj/Debug/PebbleSharp.Core.NonPortable.csproj.FilesWrittenAbsolute.txt
  22. BIN PebbleSharp.Core.NonPortable/obj/Debug/PebbleSharp.Core.NonPortable.dll
  23. BIN PebbleSharp.Core.NonPortable/obj/Debug/PebbleSharp.Core.NonPortable.dll.mdb
  24. +3 −3 PebbleSharp.Net45/PebbleSharp.Net45.csproj
  25. +238 −238 PebbleSharp.sln
  26. +12 −0 PebbleSharp.userprefs
  27. +4 −3 packages/repositories.config
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{98BDDE14-8F8C-40CC-9E45-5BAC73573EF4}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -44,8 +42,6 @@
<DefineConstants>TRACE;DEBUG;WinXP;V2;BlueZ;FX3_5</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <DocumentationFile>
- </DocumentationFile>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -68,23 +64,20 @@
<ErrorReport>prompt</ErrorReport>
<NoWarn>1591</NoWarn>
<CodeAnalysisRules>-Microsoft.Globalization#CA1304;-Microsoft.Globalization#CA1305;-Microsoft.Performance#CA1822</CodeAnalysisRules>
+ <WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
- <Reference Include="NDesk.DBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f6716e4f9b2ed099, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\ExternalLibs\Mono etc\NDesk.DBus.dll</HintPath>
- <Private>False</Private>
- </Reference>
<Reference Include="System" />
- <Reference Include="System.configuration" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
+ <Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
+ <Reference Include="System.Configuration" />
+ <Reference Include="NDesk.DBus">
+ <HintPath>NDesk.DBus.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FakeAttributes.cs" />
@@ -233,7 +233,17 @@ List<int> IUsesBluetoothConnectorImplementsServiceLookup.EndServiceDiscovery(IAs
throw new InvalidOperationException("Begin not called.");
}
var records = _sdpQuery.EndQuery(ar);
+
+ foreach (var record in records) {
+ Console.WriteLine ("Service Record:" + record.ToString());
+ }
+
var ports = BluetoothConnector.ListAllRfcommPortsInRecords(records);
+
+ foreach (var port in ports) {
+ Console.WriteLine ("Port:" + port);
+ }
+
return ports;
}
@@ -145,7 +145,6 @@ internal BluezDbusInterface.Device GetDevice(ObjectPath devicePath)
{
a = GetDefaultAdapter();
var addrStrIn = FromBluetoothAddress(address);
- Console.WriteLine("gonna FindDevice");
ObjectPath devicePath;
try {
devicePath = a.FindDevice(addrStrIn);
@@ -161,7 +160,6 @@ internal BluezDbusInterface.Device GetDevice(ObjectPath devicePath)
}
}
objectPath = devicePath;
- Console.WriteLine("gonna Get {0}", devicePath);
var d = FactoryBus.GetObject<BluezDbusInterface.Device>(Service, devicePath);
return d;
}
@@ -263,7 +261,6 @@ internal BluezDbusInterface.Adapter GetDefaultAdapter()
BluetoothAddress localAddress, out ObjectPath objectPath)
{
var mgr = FactoryBus.GetObject<BluezDbusInterface.Manager>(Service, ObjectPath.Root);
- Console.WriteLine("got Manager");
ObjectPath adapterPath = mgr.FindAdapter(FromBluetoothAddress(localAddress));
objectPath = adapterPath;
return GetAdapter(adapterPath);
@@ -272,7 +269,6 @@ internal BluezDbusInterface.Adapter GetDefaultAdapter()
internal BluezDbusInterface.Adapter GetAdapter(ObjectPath adapterPath)
{
var a = FactoryBus.GetObject<BluezDbusInterface.Adapter>(Service, adapterPath);
- Console.WriteLine("got Adapter");
return a;
}
@@ -21,6 +21,7 @@
using InTheHand.Net.Bluetooth.AttributeIds;
using System.Net.Sockets;
using System.Diagnostics.CodeAnalysis;
+using System.ComponentModel;
namespace InTheHand.Net.Bluetooth.BlueZ
{
@@ -82,7 +83,10 @@ internal List<ServiceRecord> EndQuery(IAsyncResult ar)
if (session.IsInvalid) {
//BluezUtils.Throw((BluezError)(-1), "sdp_connect");
const int WSASERVICE_NOT_FOUND = 10108;
+ throw new Win32Exception(Marshal.GetLastWin32Error());
+
throw new SocketException(WSASERVICE_NOT_FOUND);
+
}
try
{
@@ -102,6 +106,7 @@ internal List<ServiceRecord> EndQuery(IAsyncResult ar)
List<ServiceRecord> DoSdpQuery(NativeMethods.SdpSessionSafeHandle session,
Structs.uuid_t svcUuid, bool rfcommOnly)
{
+ Console.WriteLine("Size ="+Marshal.SizeOf(typeof(Structs.uuid_t)));
var listAllocs = new List<IntPtr>();
IntPtr searchList = BluezUtils.sdp_list_append(IntPtr.Zero, svcUuid, listAllocs);
@@ -122,28 +127,34 @@ internal List<ServiceRecord> EndQuery(IAsyncResult ar)
}
// Query
- Console.WriteLine("sdp_service_search_attr_req in:"
- + " {0}, attrid_list: {1}",
- searchList, attridList);
+// Console.WriteLine("sdp_service_search_attr_req in:"
+// + " {0}, attrid_list: {1}",
+// searchList, attridList);
IntPtr pResponseList;
BluezError ret = NativeMethods.sdp_service_search_attr_req(session,
searchList,
reqType, attridList,
out pResponseList);
- Console.WriteLine("sdp_service_search_attr_req ret: {0}, result: {1}",
- ret, pResponseList);
+ //Console.WriteLine("sdp_service_search_attr_req ret: {0}, result: {1}",ret, pResponseList);
BluezUtils.CheckAndThrow(ret, "sdp_service_search_attr_req");
-
- var rList = BuildRecordList(pResponseList);
- return rList;
+ var rList = BuildRecordList(pResponseList);
+
+ foreach (var record in rList) {
+ string output = ServiceRecordUtilities.Dump (record);
+ Console.WriteLine (output);
+ }
+
+
+ return rList;
}
//----
internal List<ServiceRecord> BuildRecordList(IntPtr pResponseList)
{
+ Console.WriteLine ("BuildRecordList");
var list = new List<ServiceRecord>();
if (pResponseList == IntPtr.Zero) {
- Console.WriteLine("Empty responseList.");
+ //Console.WriteLine("Empty responseList.");
return list;
}
int count = 0;
@@ -152,74 +163,107 @@ internal List<ServiceRecord> BuildRecordList(IntPtr pResponseList)
++count;
var item = (Structs.sdp_list_t)Marshal.PtrToStructure(
pCurR, typeof(Structs.sdp_list_t));
- //Console.WriteLine(" item next: 0x{0:X8}, data 0x{1:X8}", item.next, item.data);
+ //Console.WriteLine("\t"+count+" Record List item next: 0x{0:X8}, data 0x{1:X8}", item.next, item.data);
var r = (Structs.sdp_record_t)Marshal.PtrToStructure(
item.data, typeof(Structs.sdp_record_t));
//Console.WriteLine("rcd.Handle: 0x{0:X}", r.handle);
var x = BuildRecord(r);
- list.Add(x);
+ list.Add(x);
pCurR = item.next;
if (pCurR == IntPtr.Zero) {
break;
}
}//while
- Console.WriteLine("record count: {0}", count);
+ //Console.WriteLine("record count: {0}", count);
return list;
}
internal ServiceRecord BuildRecord(Structs.sdp_record_t rcdData)
{
+ Console.WriteLine ("BuildRecord");
var attrList = new List<ServiceAttribute>();
int count = 0;
IntPtr pCurAttr = rcdData.attrlist;
for (int HACK = 0; HACK < RestrictRunawayCount; ++HACK) {
++count;
var item = (Structs.sdp_list_t)Marshal.PtrToStructure(
pCurAttr, typeof(Structs.sdp_list_t));
- //Console.WriteLine(" item next: 0x{0:X8}, data 0x{1:X8}", item.next, item.data);
- var attrData = (Structs.sdp_data_struct__Bytes)Marshal.PtrToStructure(
- item.data, typeof(Structs.sdp_data_struct__Bytes));
- //Console.WriteLine(" attrId: 0x{0:X}", attrData.attrId);
var attr = BuildAttribute(item.data);
attrList.Add(attr);
// Next
pCurAttr = item.next;
- if (pCurAttr == IntPtr.Zero) {
+
+ if (pCurAttr == IntPtr.Zero) {
break;
}
}//while
Console.WriteLine("attr count: {0}", count);
var r = new ServiceRecord(attrList);
- return r;
+ return r;
}
private ServiceAttribute BuildAttribute(IntPtr pAttrData)
{
+ Console.WriteLine ("BuildAttribute");
var attrData = (Structs.sdp_data_struct__Bytes)Marshal.PtrToStructure(
pAttrData, typeof(Structs.sdp_data_struct__Bytes));
- ushort attrId0 = attrData.attrId;
- var attrId = unchecked((ServiceAttributeId)attrId0);
+ //ushort attrId0 = attrData.attrId;
+ //var attrId = unchecked((ServiceAttributeId)attrId0);
//Console.WriteLine("attrId: {0} = 0x{1:X}", attrId, attrId0);
- var elem = BuildElement(pAttrData);
- return new ServiceAttribute(attrId0, elem);
+
+ var elem = BuildElement(pAttrData);
+ Console.WriteLine ("Child Element of Attribute " + attrData.attrId + " is " + elem.ElementTypeDescriptor);
+
+
+ //return new ServiceAttribute(attrId0, elem);
+ return new ServiceAttribute(attrData.attrId, elem);
}
private ServiceElement BuildElement(IntPtr pElemData)
{
+ Console.WriteLine ("BuildElement");
var elemData = (Structs.sdp_data_struct__Bytes)Marshal.PtrToStructure(
pElemData, typeof(Structs.sdp_data_struct__Bytes));
var debug = (Structs.sdp_data_struct__Debug)Marshal.PtrToStructure(
pElemData, typeof(Structs.sdp_data_struct__Debug));
+
+ //Console.WriteLine ("dtd=" + elemData.dtd);
+
+ //Console.WriteLine ("ServiceElement length in bytes is " + debug.all.Length);
+ Console.WriteLine ("sdp_data_struct__Bytes length is measured at " + Marshal.SizeOf (typeof(Structs.sdp_data_struct__Bytes)));
+ string debugString = "";
+ foreach (var b in debug.all) {
+ debugString += b + ":";
+ }
+ Console.WriteLine (debugString);
+
+ string valString = "";
+ foreach (var b in elemData.val) {
+ valString += b + ":";
+ }
+
+
+ Console.WriteLine ("Debug sdp_data_struct__Bytes at "+pElemData.ToString()+" " + elemData.dtd + "," + elemData.attrId + ","+valString+"," + elemData.next.ToString() + "," + elemData.unitSize);
+
+
//
ElementTypeDescriptor etd; SizeIndex sizeIndex;
Map(elemData.dtd, out etd, out sizeIndex);
- //Console.WriteLine("BE: dtd: {0}, unitSize: {1}",
- // elemData.dtd, elemData.unitSize);
+ //Console.WriteLine("BE: dtd: {0}, unitSize: {1}",elemData.dtd, elemData.unitSize);
//
if (etd == ElementTypeDescriptor.ElementSequence
|| etd == ElementTypeDescriptor.ElementAlternative) {
+ Console.WriteLine ("ElementTypeDescriptor = ElementSequence or ElementAlternative");
+
+ var list = new List<ServiceElement> ();
IntPtr pCur = elemData.ReadIntPtr();
- var list = DoSequence(pCur);
+ if (pCur != IntPtr.Zero) {
+ list = DoSequence (pCur);
+ Console.WriteLine ("Element Child List Length=" + list.Count);
+ } else {
+ Console.WriteLine ("Element Child is null");
+ }
+ //Console.WriteLine ("list length=" + list.Count);
#if DEBUG
ElementTypeDescriptor cover;
if (etd == ElementTypeDescriptor.ElementAlternative) {
@@ -238,11 +282,13 @@ private ServiceElement BuildElement(IntPtr pElemData)
byte[] data;
if (etd == ElementTypeDescriptor.TextString
|| etd == ElementTypeDescriptor.Url) {
+ Console.WriteLine ("ElementTypeDescriptor = TextString or Url");
buf = new byte[elemData.unitSize];
IntPtr pStr = elemData.ReadIntPtr();
Marshal.Copy(pStr, buf, 0, buf.Length - 1);
//----
} else if (etd == ElementTypeDescriptor.Uuid) {
+ Console.WriteLine ("ElementTypeDescriptor = Uuid");
var elemDataUuid = (Structs.sdp_data_struct__uuid_t)Marshal.PtrToStructure(
pElemData, typeof(Structs.sdp_data_struct__uuid_t));
Debug.Assert(elemDataUuid.dtd == elemDataUuid.val.type, "uuid type");
@@ -252,6 +298,8 @@ private ServiceElement BuildElement(IntPtr pElemData)
Array.Copy(data, buf, buf.Length);
//----
} else {
+ Console.WriteLine ("ElementTypeDescriptor = ?");
+
int len = FromSizeIndex(sizeIndex);
buf = new byte[len];
data = elemData.val;
@@ -268,6 +316,7 @@ private ServiceElement BuildElement(IntPtr pElemData)
private List<ServiceElement> DoSequence(IntPtr pCur)
{
+ Console.WriteLine ("DoSequence");
List<ServiceElement> list = new List<ServiceElement>();
if (pCur != IntPtr.Zero) {
for (int HACK = 0; HACK < Math.Min(4, RestrictRunawayCount); ++HACK) {
@@ -283,6 +332,7 @@ private List<ServiceElement> DoSequence(IntPtr pCur)
}
}//for
}
+ //Console.WriteLine ("DoSequence list length=" + list.Count);
return list;
}
@@ -13,6 +13,7 @@
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Linq;
+using System.ComponentModel;
namespace InTheHand.Net.Bluetooth.BlueZ
{
@@ -36,7 +37,10 @@ internal static void CheckAndThrow(BluezError ret, string descr)
{
if (ret >= 0)
return;
- Throw(ret, descr);
+ var ex = new Win32Exception (Marshal.GetLastWin32Error());
+ Console.WriteLine ("BluezUtils.CheckAndThrow:" + ex.Message);
+ throw ex;
+ //Throw(ret, descr);
}
[DebuggerNonUserCode]
Oops, something went wrong.

0 comments on commit 1829bd3

Please sign in to comment.