You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2022/08/29 09:28:28 UTC

[GitHub] [mynewt-nimble] apache-mynewt-bot commented on pull request #1338: apps: Add ext_peripheral and ext_central samples

apache-mynewt-bot commented on PR #1338:
URL: https://github.com/apache/mynewt-nimble/pull/1338#issuecomment-1230015220

   
   <!-- style-bot -->
   
   ## Style check summary
   
   ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md)
   
   
   #### apps/ext_central/src/main.c
   <details>
   
   ```diff
   @@ -37,12 +37,12 @@
    static void ext_scan_uncoded(void);
    static void ext_scan_coded(void);
    
   -static void resume_scan(void)
   +static void
   +resume_scan(void)
    {
        if (current_scan == SCAN_FOR_CODED) {
            ext_scan_coded();
   -    }
   -    else {
   +    } else {
            ext_scan_uncoded();
        }
    }
   @@ -52,58 +52,58 @@
    conn_event(struct ble_gap_event *event, void *arg)
    {
        switch (event->type) {
   -        case BLE_GAP_EVENT_CONNECT:
   -            if (event->connect.status == 0) {
   -                MODLOG_DFLT(INFO,"Connection was established %d\n", current_scan);
   -                ble_gap_terminate(event->connect.conn_handle, 0x13);
   -            } else {
   -                MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
   +    case BLE_GAP_EVENT_CONNECT:
   +        if (event->connect.status == 0) {
   +            MODLOG_DFLT(INFO,"Connection was established %d\n", current_scan);
   +            ble_gap_terminate(event->connect.conn_handle, 0x13);
   +        } else {
   +            MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
                                event->connect.status);
   -                resume_scan();
   -            }
   -            break;
   -        case BLE_GAP_EVENT_DISCONNECT:
   -            MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
   +            resume_scan();
   +        }
   +        break;
   +    case BLE_GAP_EVENT_DISCONNECT:
   +        MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
                            event->disconnect.reason);
   -            if (current_scan == 2) {
   -                current_scan = 0;
   -            }
   -            else {
   -                ++current_scan;
   -            }
   -            resume_scan();
   -            break;
   -        case BLE_GAP_EVENT_CONN_UPDATE_REQ:
   -            MODLOG_DFLT(INFO,"Connection update request received\n");
   -            break;
   -        case BLE_GAP_EVENT_CONN_UPDATE:
   -            if (event->conn_update.status == 0) {
   -                MODLOG_DFLT(INFO,"Connection update successful\n");
   -            } else {
   -                MODLOG_DFLT(INFO,"Connection update failed; reason: %d\n",
   +        if (current_scan == 2) {
   +            current_scan = 0;
   +        } else {
   +            ++current_scan;
   +        }
   +        resume_scan();
   +        break;
   +    case BLE_GAP_EVENT_CONN_UPDATE_REQ:
   +        MODLOG_DFLT(INFO,"Connection update request received\n");
   +        break;
   +    case BLE_GAP_EVENT_CONN_UPDATE:
   +        if (event->conn_update.status == 0) {
   +            MODLOG_DFLT(INFO,"Connection update successful\n");
   +        } else {
   +            MODLOG_DFLT(INFO,"Connection update failed; reason: %d\n",
                                event->conn_update.status);
   -            }
   -            break;
   -        default:
   -            MODLOG_DFLT(INFO,"Connection event type not supported, %d\n",
   +        }
   +        break;
   +    default:
   +        MODLOG_DFLT(INFO,"Connection event type not supported, %d\n",
                            event->type);
   -            resume_scan();
   -            break;
   +        resume_scan();
   +        break;
        }
        return 0;
    }
    
    
    static int
   -scan_event(struct ble_gap_event *event, void *arg) {
   +scan_event(struct ble_gap_event *event, void *arg)
   +{
        /* predef_uuid array stores information about UUID of instances,
   -    that we connect to */
   +       that we connect to */
        const ble_uuid128_t predef_uuids[3] = {
   -            BLE_UUID128_INIT(0x2f, 0xce, 0xe2, 0x12, 0xb7, 0xa9, 0xdf, 0xaf,
   +        BLE_UUID128_INIT(0x2f, 0xce, 0xe2, 0x12, 0xb7, 0xa9, 0xdf, 0xaf,
                                 0xab, 0x4b, 0x99, 0x70, 0xe0, 0x69, 0x65, 0xb7),
   -            BLE_UUID128_INIT(0x89, 0x53, 0xff, 0x58, 0x00, 0x10, 0x2f, 0xb2,
   +        BLE_UUID128_INIT(0x89, 0x53, 0xff, 0x58, 0x00, 0x10, 0x2f, 0xb2,
                                 0xad, 0x4b, 0x9f, 0x35, 0xde, 0xac, 0x15, 0x79),
   -            BLE_UUID128_INIT(0x1d, 0x8e, 0x07, 0x24, 0xcb, 0x33, 0x0a, 0xa5,
   +        BLE_UUID128_INIT(0x1d, 0x8e, 0x07, 0x24, 0xcb, 0x33, 0x0a, 0xa5,
                                 0x89, 0x47, 0x1b, 0xef, 0x74, 0x51, 0x4e, 0xf7)
        };
        static struct ble_hs_adv_fields parsed_fields;
   @@ -115,62 +115,60 @@
        memset(&parsed_fields, 0, sizeof(parsed_fields));
    
        switch (event->type) {
   -        /* advertising report has been received during discovery procedure */
   -        case BLE_GAP_EVENT_EXT_DISC:
   -            if (event->ext_disc.data_status == BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE)
   -            {
   -                ble_hs_adv_parse_fields(&parsed_fields, event->ext_disc.data,
   +    /* advertising report has been received during discovery procedure */
   +    case BLE_GAP_EVENT_EXT_DISC:
   +        if (event->ext_disc.data_status == BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE) {
   +            ble_hs_adv_parse_fields(&parsed_fields, event->ext_disc.data,
                                            event->ext_disc.length_data);
    
   -                /* Predefined UUID is compared to received one;
   -                 *  if doesn't fit - end procedure and go back to scanning,
   -                 *  else - connect. */
   -                switch (current_scan) {
   -                    case SCAN_FOR_1M1M:
   -                        uuid_cmp_result = ble_uuid_cmp(&predef_uuids[SCAN_FOR_1M1M].u, &parsed_fields.uuids128->u);
   -                        break;
   -                    case SCAN_FOR_1M2M:
   -                        uuid_cmp_result = ble_uuid_cmp(&predef_uuids[SCAN_FOR_1M2M].u, &parsed_fields.uuids128->u);
   -                        break;
   -                    case SCAN_FOR_CODED:
   -                        uuid_cmp_result = ble_uuid_cmp(&predef_uuids[SCAN_FOR_CODED].u, &parsed_fields.uuids128->u);
   -                        break;
   -                    default:
   -                        return 0;
   -                }
   -
   -                if (uuid_cmp_result == 0) {
   -                    MODLOG_DFLT(INFO, "UUID fits, primary phy: %d, secondary phy: %d connecting...\n", event->ext_disc.prim_phy, event->ext_disc.sec_phy);
   -                    rc = ble_gap_disc_cancel();
   -                    MODLOG_DFLT(ERROR, "ble_gap_disc_cancel_rc = %d\n", rc);
   -                    if (current_scan == SCAN_FOR_CODED)
   -                    {
   -                        rc = ble_gap_ext_connect(g_own_addr_type, &(event->ext_disc.addr), 10000,
   +            /* Predefined UUID is compared to received one;
   +             *  if doesn't fit - end procedure and go back to scanning,
   +             *  else - connect. */
   +            switch (current_scan) {
   +            case SCAN_FOR_1M1M:
   +                uuid_cmp_result = ble_uuid_cmp(&predef_uuids[SCAN_FOR_1M1M].u, &parsed_fields.uuids128->u);
   +                break;
   +            case SCAN_FOR_1M2M:
   +                uuid_cmp_result = ble_uuid_cmp(&predef_uuids[SCAN_FOR_1M2M].u, &parsed_fields.uuids128->u);
   +                break;
   +            case SCAN_FOR_CODED:
   +                uuid_cmp_result = ble_uuid_cmp(&predef_uuids[SCAN_FOR_CODED].u, &parsed_fields.uuids128->u);
   +                break;
   +            default:
   +                return 0;
   +            }
   +
   +            if (uuid_cmp_result == 0) {
   +                MODLOG_DFLT(INFO, "UUID fits, primary phy: %d, secondary phy: %d connecting...\n",
   +                            event->ext_disc.prim_phy, event->ext_disc.sec_phy);
   +                rc = ble_gap_disc_cancel();
   +                MODLOG_DFLT(ERROR, "ble_gap_disc_cancel_rc = %d\n", rc);
   +                if (current_scan == SCAN_FOR_CODED) {
   +                    rc = ble_gap_ext_connect(g_own_addr_type, &(event->ext_disc.addr), 10000,
                                                     BLE_GAP_LE_PHY_CODED_MASK,
                                                     NULL, NULL, NULL, conn_event, NULL);
   -                    }
   -                    else {
   -                        rc = ble_gap_ext_connect(g_own_addr_type, &(event->ext_disc.addr), 10000,
   +                } else {
   +                    rc = ble_gap_ext_connect(g_own_addr_type, &(event->ext_disc.addr), 10000,
                                                     BLE_GAP_LE_PHY_1M_MASK,
                                                     NULL, NULL, NULL, conn_event, NULL);
   -                    }
   -                    MODLOG_DFLT(ERROR, "ble_gap_ext_connect_rc = %d\n", rc);
                    }
   +                MODLOG_DFLT(ERROR, "ble_gap_ext_connect_rc = %d\n", rc);
                }
   -            return 0;
   -
   -        /* discovery procedure has terminated */
   -        case BLE_GAP_EVENT_DISC_COMPLETE:
   -            MODLOG_DFLT(INFO, "Discovery completed, terminaton code: %d\n",
   +        }
   +        return 0;
   +
   +    /* discovery procedure has terminated */
   +    case BLE_GAP_EVENT_DISC_COMPLETE:
   +        MODLOG_DFLT(INFO, "Discovery completed, terminaton code: %d\n",
                            event->disc_complete.reason);
    
   -            console_printf("RESUME SCAN\n");
   -            resume_scan();
   -            return 0;
   -
   -        default:
   -            MODLOG_DFLT(ERROR, "Discovery event not handled\n");
   -            return 0;
   +        console_printf("RESUME SCAN\n");
   +        resume_scan();
   +        return 0;
   +
   +    default:
   +        MODLOG_DFLT(ERROR, "Discovery event not handled\n");
   +        return 0;
        }
    }
    
   ```
   
   </details>
   
   #### apps/ext_peripheral/src/main.c
   <details>
   
   ```diff
   @@ -43,14 +43,16 @@
        /* Connection handles for each of the advertising instances */
        uint16_t conn_handle;
    } conns[3] = {
   -        {.predef_uuid = BLE_UUID128_INIT(0x2f, 0xce, 0xe2, 0x12, 0xb7, 0xa9, 0xdf, 0xaf,
   +    {.predef_uuid = BLE_UUID128_INIT(0x2f, 0xce, 0xe2, 0x12, 0xb7, 0xa9, 0xdf, 0xaf,
                                                 0xab, 0x4b, 0x99, 0x70, 0xe0, 0x69, 0x65, 0xb7)},
   -        {
   -            .predef_uuid = BLE_UUID128_INIT(0x89, 0x53, 0xff, 0x58, 0x00, 0x10, 0x2f, 0xb2,
   -                                            0xad, 0x4b, 0x9f, 0x35, 0xde, 0xac, 0x15, 0x79)},
   -        {
   -            .predef_uuid = BLE_UUID128_INIT(0x1d, 0x8e, 0x07, 0x24, 0xcb, 0x33, 0x0a, 0xa5,
   -                                            0x89, 0x47, 0x1b, 0xef, 0x74, 0x51, 0x4e, 0xf7)}
   +    {
   +        .predef_uuid = BLE_UUID128_INIT(0x89, 0x53, 0xff, 0x58, 0x00, 0x10, 0x2f, 0xb2,
   +                                            0xad, 0x4b, 0x9f, 0x35, 0xde, 0xac, 0x15, 0x79)
   +    },
   +    {
   +        .predef_uuid = BLE_UUID128_INIT(0x1d, 0x8e, 0x07, 0x24, 0xcb, 0x33, 0x0a, 0xa5,
   +                                            0x89, 0x47, 0x1b, 0xef, 0x74, 0x51, 0x4e, 0xf7)
   +    }
    };
    
    /* ext_scan_event() calls these functions, so forward declaration is required */
   @@ -66,62 +68,59 @@
    ext_scan_event(struct ble_gap_event *event, void *arg)
    {
        switch (event->type) {
   -        case BLE_GAP_EVENT_CONNECT:
   -            /* A new connection was established or a connection attempt failed */
   -            console_printf("connection %s; status=%d\n",
   +    case BLE_GAP_EVENT_CONNECT:
   +        /* A new connection was established or a connection attempt failed */
   +        console_printf("connection %s; status=%d\n",
                            event->connect.status == 0 ? "established" : "failed",
                            event->connect.status);
    
   -            /* Save connection status to check in next callback (from BLE_GAP_EVENT_ADV_COMPLETE event)
   -             * if the connection was established */
   -            conn_status = event->connect.status;
   -            break;
   -
   -        case BLE_GAP_EVENT_ADV_COMPLETE:
   -            if (conn_status != 0) {
   -                /* Connection failed; resume advertising */
   -                switch (event->adv_complete.instance) {
   -                    case ADV_INSTANCE_HANDLE_1M1M:
   -                        start_1m1m_ext_adv();
   -                        conns[ADV_INSTANCE_HANDLE_1M1M].conn_handle = 0;
   -                        break;
   -                    case ADV_INSTANCE_HANDLE_1M2M:
   -                        start_1m2m_ext_adv();
   -                        conns[ADV_INSTANCE_HANDLE_1M2M].conn_handle = 0;
   -                        break;
   -                    case ADV_INSTANCE_HANDLE_CODED:
   -                        start_coded_ext_adv();
   -                        conns[ADV_INSTANCE_HANDLE_CODED].conn_handle = 0;
   -                        break;
   -                    default:
   -                        break;
   -                }
   +        /* Save connection status to check in next callback (from BLE_GAP_EVENT_ADV_COMPLETE event)
   +         * if the connection was established */
   +        conn_status = event->connect.status;
   +        break;
   +
   +    case BLE_GAP_EVENT_ADV_COMPLETE:
   +        if (conn_status != 0) {
   +            /* Connection failed; resume advertising */
   +            switch (event->adv_complete.instance) {
   +            case ADV_INSTANCE_HANDLE_1M1M:
   +                start_1m1m_ext_adv();
   +                conns[ADV_INSTANCE_HANDLE_1M1M].conn_handle = 0;
   +                break;
   +            case ADV_INSTANCE_HANDLE_1M2M:
   +                start_1m2m_ext_adv();
   +                conns[ADV_INSTANCE_HANDLE_1M2M].conn_handle = 0;
   +                break;
   +            case ADV_INSTANCE_HANDLE_CODED:
   +                start_coded_ext_adv();
   +                conns[ADV_INSTANCE_HANDLE_CODED].conn_handle = 0;
   +                break;
   +            default:
   +                break;
                }
   -            else {
   -                /* Instances are numbered 0 to 2, so they can also be used as array indexes */
   -                conns[event->adv_complete.instance].conn_handle = event->adv_complete.conn_handle;
   -            }
   -            console_printf("adv complete %d\n", conns[event->adv_complete.instance].conn_handle);
   -            break;
   -
   -        case BLE_GAP_EVENT_DISCONNECT:
   -            console_printf("disconnect; reason=%d\n", event->disconnect.reason);
   -            if (event->disconnect.conn.conn_handle == conns[ADV_INSTANCE_HANDLE_1M1M].conn_handle) {
   -                conns[ADV_INSTANCE_HANDLE_1M1M].conn_handle = BLE_HS_CONN_HANDLE_NONE;
   -                start_1m1m_ext_adv();
   -            }
   -            else if (event->disconnect.conn.conn_handle == conns[ADV_INSTANCE_HANDLE_1M2M].conn_handle) {
   -                conns[ADV_INSTANCE_HANDLE_1M2M].conn_handle = BLE_HS_CONN_HANDLE_NONE;
   -                start_1m2m_ext_adv();
   -            }
   -            else if (event->disconnect.conn.conn_handle == conns[ADV_INSTANCE_HANDLE_CODED].conn_handle) {
   -                conns[ADV_INSTANCE_HANDLE_CODED].conn_handle = BLE_HS_CONN_HANDLE_NONE;
   -                start_coded_ext_adv();
   -            }
   -            break;
   -
   -        default:
   -            break;
   +        } else   {
   +            /* Instances are numbered 0 to 2, so they can also be used as array indexes */
   +            conns[event->adv_complete.instance].conn_handle = event->adv_complete.conn_handle;
   +        }
   +        console_printf("adv complete %d\n", conns[event->adv_complete.instance].conn_handle);
   +        break;
   +
   +    case BLE_GAP_EVENT_DISCONNECT:
   +        console_printf("disconnect; reason=%d\n", event->disconnect.reason);
   +        if (event->disconnect.conn.conn_handle == conns[ADV_INSTANCE_HANDLE_1M1M].conn_handle) {
   +            conns[ADV_INSTANCE_HANDLE_1M1M].conn_handle = BLE_HS_CONN_HANDLE_NONE;
   +            start_1m1m_ext_adv();
   +        } else if (event->disconnect.conn.conn_handle == conns[ADV_INSTANCE_HANDLE_1M2M].conn_handle)   {
   +            conns[ADV_INSTANCE_HANDLE_1M2M].conn_handle = BLE_HS_CONN_HANDLE_NONE;
   +            start_1m2m_ext_adv();
   +        } else if (event->disconnect.conn.conn_handle == conns[ADV_INSTANCE_HANDLE_CODED].conn_handle)   {
   +            conns[ADV_INSTANCE_HANDLE_CODED].conn_handle = BLE_HS_CONN_HANDLE_NONE;
   +            start_coded_ext_adv();
   +        }
   +        break;
   +
   +    default:
   +        break;
        }
    
        return 0;
   @@ -158,7 +157,7 @@
        /* set random (NRPA) address for instance */
        rc = ble_hs_id_gen_rnd(1, &addr);
        assert (rc == 0);
   -    rc = ble_gap_ext_adv_set_addr(instance, &addr );
   +    rc = ble_gap_ext_adv_set_addr(instance, &addr);
        assert (rc == 0);
    
        /* Adding uuid to adv_fields */
   @@ -214,7 +213,7 @@
        rc = ble_hs_id_gen_rnd(1, &addr);
        assert (rc == 0);
    
   -    rc = ble_gap_ext_adv_set_addr(instance, &addr );
   +    rc = ble_gap_ext_adv_set_addr(instance, &addr);
        assert (rc == 0);
    
        /* Adding uuid to adv_fields */
   @@ -268,7 +267,7 @@
        /* set random (NRPA) address for instance */
        rc = ble_hs_id_gen_rnd(1, &addr);
        assert (rc == 0);
   -    rc = ble_gap_ext_adv_set_addr(instance, &addr );
   +    rc = ble_gap_ext_adv_set_addr(instance, &addr);
        assert (rc == 0);
    
        /* Adding uuid to adv_fields */
   ```
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@mynewt.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org