Exemple #1
0
 public void TestStringAsAddress()
 {
     monotooth.BluetoothAddress ba =	new monotooth.BluetoothAddress("80:7F:7E:7D:7C:7B");
     byte[] comp = new byte[]{ 128, 127, 126, 125, 124, 123};
     monotooth.BluetoothAddress ba2 = new monotooth.BluetoothAddress(comp);
     monotooth.BluetoothAddress zeroaddr = new monotooth.BluetoothAddress();
     Assert.AreNotEqual(ba.Array, zeroaddr,"Should not return zero address with good bluetooth address!");
     Assert.AreEqual(ba2.Array,ba.Array, "Test data comparison failed!");
     monotooth.BluetoothAddress bogusba = new monotooth.BluetoothAddress("80LOL:FF:RFF:FFF:FFF:FFF:FF");
     Assert.AreEqual(zeroaddr.Array, bogusba.Array, "Bogus data accepted!");
     monotooth.BluetoothAddress toobigblocksba = new monotooth.BluetoothAddress("801322F:FF:FF:FFAF:FAF:5FF");
     Assert.AreEqual(zeroaddr.Array, toobigblocksba.Array,"Data with too big blocks accepted!");
 }
Exemple #2
0
 public void TestAddressAsString()
 {
     monotooth.BluetoothAddress batest = new monotooth.BluetoothAddress();
     batest.Array = new byte[]{128,127,126,125,124,123};
     string teststring = monotooth.BluetoothAddress.AddressAsString(batest);
     Assert.AreEqual("80:7F:7E:7D:7C:7B",teststring,"Good input address won't get in to a string!");
     batest.Array = new byte[]{1,10,13,14,15,11};
     string zeroes = monotooth.BluetoothAddress.AddressAsString(batest);
     Assert.AreEqual("01:0A:0D:0E:0F:0B",zeroes,"Good input address isn't produced correctly!");
     batest.Array = new byte[]{1,2,4,2,1};
     string tooshort = monotooth.BluetoothAddress.AddressAsString(batest);
     Assert.AreEqual("00:00:00:00:00",tooshort,"Too short array got in to a string!");
 }
Exemple #3
0
 public static void Main(string[] args)
 {
     monotooth.Device.ILocalDevice devi = monotooth.Device.LocalDevice.Default;
     monotooth.Device.DevicePool pool = devi.Inquire();
     monotooth.BluetoothAddress addr = new monotooth.BluetoothAddress("00:01:02:03:04:05");
     foreach(monotooth.Device.IRemoteDevice dev in pool)
     {
         Console.WriteLine("Name: "+ dev.FriendlyName + " Address:"+ monotooth.BluetoothAddress.AddressAsString(dev.Address)+"\n Now searching for services..");
         Console.WriteLine("Services in :"+dev.FriendlyName);
     }
     /*
     monotooth.Device.DeviceFactory fac = monotooth.Device.DeviceFactory.GetFactory();
     Console.WriteLine((fac is monotooth.Device.LinuxDeviceFactory));
     Console.WriteLine((fac is monotooth.Device.WindowsDeviceFactory));
     monotooth.Device.ILocalDevice devi = fac.CreateLocalDevice();
     Console.WriteLine("Information of the local device: ");
     Console.WriteLine("Name: "+devi.FriendlyName+ " Address: "+ devi.AddressAsString());
     Console.WriteLine("Searching for devices...");
     monotooth.Device.DevicePool pool = devi.Inquire();
     foreach(monotooth.Device.IRemoteDevice dev in pool)
     {
         Console.WriteLine("Name: "+ dev.FriendlyName + " Address:"+ dev.AddressAsString()+"\n Now searching for services..");
         dev.Services = dev.InquireServices((uint)0x0);
         Console.WriteLine("Services in :"+dev.FriendlyName);
         foreach(monotooth.Service.Service serv in dev.Services)
         {
             Console.WriteLine("Service name: "+serv.name+"\nService description: "+serv.description+"\nService Port: "+serv.rfcomm_port);
         }
     }
     monotooth.Connections.RFCommConnectionFactory connfac = monotooth.Connections.RFCommConnectionFactory.GetFactory();
     monotooth.Connections.RFCommConnection conn = connfac.CreateRFCommConnection(devi.Address,devi.Address);
     monotooth.Connections.ServiceConnectionFactory servfac = monotooth.Connections.ServiceConnectionFactory.GetFactory();
     monotooth.Connections.ServiceConnection servconn = servfac.CreateServiceConnection(conn);
     servconn.connect((uint)0xABCD);
     System.Text.StringBuilder bld = new System.Text.StringBuilder("Hello there!");
     servconn.Write(bld);
     bld = new System.Text.StringBuilder();
     bld.Capacity = 1024;
     servconn.Read(bld);
     Console.WriteLine(bld.ToString());
     monotooth.Socket.BluetoothStream bs = new monotooth.Socket.BluetoothStream(servconn.Connection);
     BinaryFormatter bin = new BinaryFormatter();
     System.String s = "Hello serialized bluetooth stream!";
     bin.Serialize(bs, s);
     bs.Close();			*/
 }
Exemple #4
0
 /// <summary> The default constructor for linux implementation </summary>
 public LinuxDevice()
 {
     this.dev_id = hci_get_route(IntPtr.Zero);
     if(this.dev_id != -1)
     {
     int dd = hci_open_dev(this.dev_id);
     this.address = new monotooth.BluetoothAddress();
     IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(monotooth.BluetoothAddress)));
     hci_devba(this.dev_id,ptr);
     Marshal.PtrToStructure(ptr,this.address);
     System.Text.StringBuilder bld = new System.Text.StringBuilder(248);
     hci_read_local_name(dd,bld.Capacity,bld,1000);
     this.name = bld.ToString();
     Marshal.FreeHGlobal(ptr);
     } else
     {
         throw new Exception("You do not have a bluetooth device on your system.");
     }
 }
 public WindowsRemoteDevice(monotooth.BluetoothAddress ba, String name)
 {
     this.address = ba;
     this.name = name;
 }
 public LinuxRemoteDevice(monotooth.BluetoothAddress ba, string name)
 {
     this.address = ba;
     this.name = name;
 }