/// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void BLEATTClientProcedureCompletedEvent(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(delegate
            {
                MessageWriter.LogWrite("ble_evt_attclient_procedure_completed: ", string.Format("connection={0}, result={1}, chrhandle={2}",
                                                                                                e.connection,
                                                                                                e.result,
                                                                                                e.chrhandle));

                BLEPeripheral peripheral;
                if (!connectedDevices.TryGetConnection(e.connection, out peripheral))
                {
                    MessageWriter.LogWrite("Unable to find connection " + e.connection);
                    return;
                }

                BLEPerformNextTask(peripheral);

                if (peripheral.Characteristics.ContainsKey("LPM"))
                {
                    if (e.chrhandle == peripheral.Characteristics["LPM"].ValueAttribute.Handle)
                    {
                        // Check sleep mode
                        cmd = bglib.BLECommandATTClientReadByHandle(e.connection, peripheral.Characteristics["LPM"].ValueAttribute.Handle);
                        MessageWriter.LogWrite("ble_cmd_att_client_read_by_handle: ", string.Format("connection={0}, handle={1}",
                                                                                                    e.connection, peripheral.Characteristics["LPM"].ValueAttribute.Handle));
                        bglib.SendCommand(SelectedPort, cmd);
                    }
                }
            });
        }
Exemple #2
0
        private void ATTClientProcedureCompletedEvent(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
        {
            String log = String.Format("ble_evt_attclient_procedure_completed: connection={0}, result={1}, chrhandle={2}" + Environment.NewLine,
                                       e.connection,
                                       e.result,
                                       e.chrhandle
                                       );

            Console.WriteLine("Sipp9X State: {0}", GetState());
            Console.WriteLine(log);

            // check if we just finished searching for services
            if (GetState() == STATE_FINDING_SERVICES)
            {
                if (GetHandleEnd() > 0)
                {
                    Byte[] cmd = NewFindInfoCmd(e.connection);
                    // DEBUG: display bytes written
                    Console.WriteLine(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine);

                    SendCmd(cmd);
                    //while (bglib.IsBusy()) ;

                    // update state
                    SetState(STATE_FINDING_ATTRIBUTES);
                }
                else
                {
                    Console.WriteLine("Could not find service" + Environment.NewLine);
                }
            }
            // check if we just finished searching for attributes within the heart rate service
            else if (GetState() == STATE_ENABLE_NOTIFICATION)
            {
                SetState(STATE_READY);
            }
            else if (GetState() == STATE_FINDING_ATTRIBUTES)
            {
                if (att_handle_measurement_ccc > 0)
                {
                    // found the measurement + client characteristic configuration, so enable notifications
                    // (this is done by writing 0x0001 to the client characteristic configuration attribute)
                    Byte[] cmd = NewWriteAttributeCmd(e.connection, att_handle_measurement_ccc, new Byte[] { 0x01, 0x00 });
                    // DEBUG: display bytes written
                    Console.WriteLine(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine);

                    SendCmd(cmd);
                    //while (bglib.IsBusy()) ;

                    // update state
                    SetState(STATE_ENABLE_NOTIFICATION);
                }
                else
                {
                    Console.WriteLine(String.Format("Could not find 'Sipp6X motion measurement' attribute with UUID {0}", att_handle_measurement_ccc) + Environment.NewLine);
                }
            }
        }
Exemple #3
0
        public void ATTClientProcedureCompletedEvent(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
        {
            String log = String.Format("ble_evt_attclient_procedure_completed: connection={0}, result={1}, chrhandle={2}" + Environment.NewLine,
                                       e.connection,
                                       e.result,
                                       e.chrhandle
                                       );

            Console.Write(log);
            ThreadSafeDelegate(delegate { txtLog.AppendText(log); });

            // check if we just finished searching for services
            if (app_state == STATE_FINDING_SERVICES)
            {
                if (att_handlesearch_end > 0)
                {
                    //print "Found 'Heart Rate' service with UUID 0x180D"

                    // found the Heart Rate service, so now search for the attributes inside
                    Byte[] cmd = bglib.BLECommandATTClientFindInformation(e.connection, att_handlesearch_start, att_handlesearch_end);
                    // DEBUG: display bytes written
                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); });
                    bglib.SendCommand(serialAPI, cmd);
                    //while (bglib.IsBusy()) ;

                    // update state
                    app_state = STATE_FINDING_ATTRIBUTES;
                }
                else
                {
                    ThreadSafeDelegate(delegate { txtLog.AppendText("Could not find 'Heart Rate' service with UUID 0x180D" + Environment.NewLine); });
                }
            }
            // check if we just finished searching for attributes within the heart rate service
            else if (app_state == STATE_FINDING_ATTRIBUTES)
            {
                if (att_handle_measurement_ccc > 0)
                {
                    //print "Found 'Heart Rate' measurement attribute with UUID 0x2A37"

                    // found the measurement + client characteristic configuration, so enable notifications
                    // (this is done by writing 0x01 to the client characteristic configuration attribute)
                    Byte[] cmd = bglib.BLECommandATTClientAttributeWrite(e.connection, att_handle_measurement_ccc, new Byte[] { 0x01 });
                    // DEBUG: display bytes written
                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); });
                    bglib.SendCommand(serialAPI, cmd);
                    //while (bglib.IsBusy()) ;

                    // update state
                    app_state = STATE_LISTENING_MEASUREMENTS;
                }
                else
                {
                    ThreadSafeDelegate(delegate { txtLog.AppendText("Could not find 'Heart Rate' measurement attribute with UUID 0x2A37" + Environment.NewLine); });
                }
            }
        }
Exemple #4
0
        public void ATTClientProcedureCompletedEvent(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
        {
            String log = String.Format("ble_evt_attclient_procedure_completed: connection={0}, result={1}, chrhandle={2}" + Environment.NewLine,
                                       e.connection,
                                       e.result,
                                       e.chrhandle
                                       );

            Console.Write(log);
            ThreadSafeDelegate(delegate { txtLog.AppendText(log); });

            if (app_state == STATE_FINDING_SERVICES)
            {
                if (att_handlesearch_end > 0)
                {
                    Byte[] cmd = bglib.BLECommandATTClientFindInformation(e.connection, att_handlesearch_start, att_handlesearch_end);
#if PRINT_DEBUG
                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); });
#endif
                    bglib.SendCommand(serialAPI, cmd);

                    // update state
                    app_state = STATE_FINDING_ATTRIBUTES;
                }
                else
                {
                    ThreadSafeDelegate(delegate { txtLog.AppendText("Could not find service" + Environment.NewLine); });
                }
            }
            else if (app_state == STATE_FINDING_ATTRIBUTES)
            {
                if (att_handle_measurement_ccc > 0)
                {
                    Byte[] cmd = bglib.BLECommandATTClientAttributeWrite(e.connection, (UInt16)(att_handle_measurement + 0x01), new Byte[] { 0x01, 0x00 });
#if PRINT_DEBUG
                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); });
#endif
                    bglib.SendCommand(serialAPI, cmd);
                    Byte[] cmd2 = bglib.BLECommandATTClientAttributeWrite(e.connection, (UInt16)(att_handle_measurement_ccc + 0x01), new Byte[] { 0x01, 0x00 });
#if PRINT_DEBUG
                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("=> TX ({0}) [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); });
#endif
                    bglib.SendCommand(serialAPI, cmd2);
                    app_state = STATE_LISTENING_MEASUREMENTS;
                }
                else
                {
                    ThreadSafeDelegate(delegate { txtLog.AppendText("Could not find 'Heart Rate' measurement attribute with UUID 0x2A37" + Environment.NewLine); });
                }
            }
        }
Exemple #5
0
 public void ATTClientProcedureCompletedEvent(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
 {
     // Ha Write parancsra érkezett, és sikeres a folyamat...
     if (e.connection == this.bleConnectionHndl)
     {
         if (e.chrhandle == BLETEMPPERIODHNDL || e.chrhandle == BLETEMPCONFIGHNDL || e.chrhandle == BLELIGHTPERIODHNDL || e.chrhandle == BLELIGHTCONFIGHNDL)
         {
             if (e.result == 0)
             {
                 this.bleSemaphore.Release();
             }
         }
     }
 }
Exemple #6
0
        public void EventProcedureCompleted(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
        {
            c_BleDev.Busy = false;
#if false
            if (c_BleDev.State == GhpBle.ACTIION_ATTR_PAIR_CHECK)
            {
                switch (e.result)
                {
                case 0x040F:
                case 0x0405:
                case 0x0408:
                    c_BleDev.NeedPair = true;
                    break;

                default:
                    c_BleDev.NeedPair = false;
                    break;
                }
            }
#endif
        }
Exemple #7
0
        /// <summary>
        ///  The last started procedure has completed. E.g. we ended searching attr. or serv.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">ProcedureCompletedEventArgs</param>
        public void ATTClientProcedureCompletedEvent(object sender, Bluegiga.BLE.Events.ATTClient.ProcedureCompletedEventArgs e)
        {
            lock (o)
            {
                String log = String.Format("procedure_completed: connection={0}, result={1}, chrhandle={2}" + Environment.NewLine,
                                           e.connection,
                                           e.result,
                                           e.chrhandle
                                           );
                Console.Write(log);
                ThreadSafeDelegate(delegate { txtLog.AppendText(log); });
                Byte[] cmd;
                // check if we just finished searching for attr in services
                switch (app_state)
                {
                case  STATE_SEARCH_PLATTFORM_SERVICE:
                    // set to value when new service found
                    if (att_handlesearch_end > 0)
                    {
                        // found a service, so now search for the attributes inside
                        cmd = bglib.BLECommandATTClientFindInformation(e.connection, (UInt16)att_handlesearch_start, (UInt16)att_handlesearch_end);
                        //  Byte[] cmd = bglib.BLECommandATTClientReadByType(e.connection, (ushort)att_handlesearch_start, (ushort)att_handlesearch_end, new byte[] { 0x03, 0x28 });

                        ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("Sending find information command \n =>   Length: ({0}) Data:   [ {1}]", cmd.Length, ByteArrayToHexString(cmd)) + Environment.NewLine); });
                        bglib.SendCommand(serialAPI, cmd);
                        //while (bglib.IsBusy()) ;

                        // update state
                        app_state = STATE_SEARCH_ATTRIBUTES;
                        att_handlesearch_start = 0;
                        att_handlesearch_end   = 0;
                    }
                    else
                    {
                        ThreadSafeDelegate(delegate { txtLog.AppendText("Could not find services" + Environment.NewLine); });
                    }
                    break;

                // characteristics search completed -- send notification command to first char
                case STATE_SEARCH_ATTRIBUTES:     // lasts ATTRccc val set in model - send notifications

                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("Set STATE to SET_CCC \n ==> SET CCC Command Handle {0} ", tmpCharContainer1.Handle_ccc) + Environment.NewLine); });

                    app_state = STATE_SET_ATTRIBUTES_CCC;

                    cmd = bglib.BLECommandATTClientAttributeWrite(e.connection, (UInt16)tmpCharContainer1.Handle_ccc, new Byte[] { 0x01 });

                    bglib.SendCommand(serialAPI, cmd);
                    break;

                case STATE_SET_ATTRIBUTES_CCC:

                    cmd = bglib.BLECommandATTClientAttributeWrite(e.connection, (UInt16)tmpCharContainer2.Handle_ccc, new Byte[] { 0x01 });
                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("STATE_SETATTR -- send last notify !!!!! to {0}", tmpCharContainer2.Handle_ccc) + Environment.NewLine); });

                    // we done notify for all characs
                    app_state = STATE_LISTEN_MEASUREMENTS;

                    readButton.Enabled = true;
                    bglib.SendCommand(serialAPI, cmd);

                    /*   // set the state to measure when all sensors connected
                     * if (att_Counter == SENSOR_COUNT)
                     * {
                     *     app_state = STATE_LISTENING_MEASUREMENTS;
                     * } */
                    break;

                case STATE_READ_ATTR_VAL:

                    ThreadSafeDelegate(delegate { txtLog.AppendText(String.Format("Setting appstate back to READ Measure" + Environment.NewLine)); });

                    break;

                default: ThreadSafeDelegate(delegate { txtLog.AppendText("!!! STATE NOT FOUND" + Environment.NewLine); });
                    break;
                }
            }
        }