Exemplo n.º 1
0
        public BluezServices(DBusConnection connection)
        {
            systemBus       = connection.System;
            this.connection = connection;

            UnixExitSignal exitClass = new UnixExitSignal();

            exitClass.Exit += OnExit;
        }
Exemplo n.º 2
0
        static void Run()
        {
            Init.WiringPiSetup();
            int           result     = Init.WiringPiSetupSys();
            int           device     = Serial.serialOpen("/dev/ttyS0", 9600);
            StringBuilder dataHolder = new StringBuilder();

            DBusConnection connection = new DBusConnection("org.GPSService");
            Application    app        = new Application(connection.System, "/org/bluez");

            app.AddService(new LocationService(connection.System, 0));

            MainAdvertisement ad = new MainAdvertisement(connection.System, 0);

            BluezServices bluezServices = new BluezServices(connection);

            if (bluezServices.IsLowEnergySupported())
            {
                bluezServices.SetDiscoverable(true);
                bluezServices.RegisterApplication(app);

                while (tries > 0)
                {
                    try
                    {
                        bluezServices.RegisterAdvertisement(ad);
                    }
                    catch
                    {
                        tries--;
                    }
                }
            }

            while (true)
            {
                Tuple <string, string> LatLng = SerialReader.ReadLatLng(dataHolder, device);

                if (LatLng.Item1 != null && LatLng.Item2 != null)
                {
                    Characteristic latchrc = app.services[0].characteristics[1];
                    Characteristic lngchrc = app.services[0].characteristics[2];
                    latchrc.Set(typeof(GattCharacteristic1).DBusInterfaceName(), "Value", LatLng.Item1);
                    lngchrc.Set(typeof(GattCharacteristic1).DBusInterfaceName(), "Value", LatLng.Item2);
                    Console.WriteLine("Lat: " + LatLng.Item1 + " Long: " + LatLng.Item2);
                }

                Thread.Sleep(50);
            }
        }