[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-06-09 Thread GitBox


rymanluk commented on a change in pull request #796:
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r437590586



##
File path: apps/central/src/main.c
##
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+static uint32_t delay_ms = 2000;

Review comment:
   this delay is also not needed here - you ca put is as value where it is 
used





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.

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




[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-06-09 Thread GitBox


rymanluk commented on a change in pull request #796:
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r437589869



##
File path: apps/central/src/main.c
##
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+static uint32_t delay_ms = 2000;
+static os_time_t ticks;

Review comment:
   this is not needed anymore.





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.

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




[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-05-15 Thread GitBox


rymanluk commented on a change in pull request #796:
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r425629064



##
File path: apps/central/src/main.c
##
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );

Review comment:
   this seems to be unresolved.





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.

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




[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-22 Thread GitBox


rymanluk commented on a change in pull request #796:
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r413378943



##
File path: apps/central/src/main.c
##
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);

Review comment:
   Event is sent on  both sides.





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.

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




[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410023250
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
 
 Review comment:
   **BLE_ERR_REM_USER_CONN_TERM**


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410021105
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
+os_time_delay(ticks);
+scan();
+} else {
+MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+event->connect.status);
+}
+break;
+case BLE_GAP_EVENT_DISCONNECT:
+MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+event->disconnect.reason);
+default:
+MODLOG_DFLT(INFO,"Connection event type not supported\n");
+break;
+}
+return 0;
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+struct ble_hs_adv_fields parsed_fields;
+memset(_fields, 0, sizeof(parsed_fields));
+
+/*predef_uuid stores information about UUID of device, that we connect to*/
+const uint8_t predef_uuid[16] = {
+0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+};
+
+switch (event->type) {
+/* advertising report has been received during discovery procedure */
+case BLE_GAP_EVENT_DISC:
+MODLOG_DFLT(INFO, "Advertising report received! Checking UUID...\n");
+ble_hs_adv_parse_fields(_fields, event->disc.data,
+event->disc.length_data);
+/* Predefined UUID is compared to recieved one;
+   if doesn't fit - end procedure and go back to scanning,
+   else - connect. */
+for (int i = 0; i < sizeof(predef_uuid); i++) {
 
 Review comment:
   https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md
   
   local variable shall be on top


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410021918
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
+os_time_delay(ticks);
+scan();
+} else {
+MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+event->connect.status);
+}
+break;
+case BLE_GAP_EVENT_DISCONNECT:
+MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+event->disconnect.reason);
+default:
+MODLOG_DFLT(INFO,"Connection event type not supported\n");
+break;
+}
+return 0;
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+struct ble_hs_adv_fields parsed_fields;
+memset(_fields, 0, sizeof(parsed_fields));
+
+/*predef_uuid stores information about UUID of device, that we connect to*/
+const uint8_t predef_uuid[16] = {
+0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+};
+
+switch (event->type) {
+/* advertising report has been received during discovery procedure */
+case BLE_GAP_EVENT_DISC:
+MODLOG_DFLT(INFO, "Advertising report received! Checking UUID...\n");
+ble_hs_adv_parse_fields(_fields, event->disc.data,
+event->disc.length_data);
+/* Predefined UUID is compared to recieved one;
+   if doesn't fit - end procedure and go back to scanning,
+   else - connect. */
+for (int i = 0; i < sizeof(predef_uuid); i++) {
+if (parsed_fields.uuids128->value[i] != predef_uuid[i]) {
+MODLOG_DFLT(INFO, "doesn't fit\n");
+return 0;
+}
+}
+
+MODLOG_DFLT(INFO, "UUID ");
+for (int i = 0; i < sizeof(predef_uuid); i++) {
+MODLOG_DFLT(INFO, "%d, ", parsed_fields.uuids128->value[i]);
+}
+MODLOG_DFLT(INFO, "fits, connecting... \n");
+ble_gap_disc_cancel();
+ble_gap_connect(g_own_addr_type, &(event->disc.addr), 1,
+NULL, conn_event, NULL);
+break;
+/* discovery procedure has terminated */
+case BLE_GAP_EVENT_DISC_COMPLETE:
+MODLOG_DFLT(INFO,"Code of termination reason: %d\n",
 
 Review comment:
   "Discovery completed, reason: "


This is an automated message from the Apache Git Service.
To respond 

[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410019122
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
+os_time_delay(ticks);
+scan();
+} else {
+MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+event->connect.status);
+}
+break;
+case BLE_GAP_EVENT_DISCONNECT:
+MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+event->disconnect.reason);
+default:
+MODLOG_DFLT(INFO,"Connection event type not supported\n");
+break;
+}
+return 0;
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+struct ble_hs_adv_fields parsed_fields;
+memset(_fields, 0, sizeof(parsed_fields));
+
+/*predef_uuid stores information about UUID of device, that we connect to*/
+const uint8_t predef_uuid[16] = {
+0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+};
+
+switch (event->type) {
+/* advertising report has been received during discovery procedure */
+case BLE_GAP_EVENT_DISC:
+MODLOG_DFLT(INFO, "Advertising report received! Checking UUID...\n");
+ble_hs_adv_parse_fields(_fields, event->disc.data,
+event->disc.length_data);
+/* Predefined UUID is compared to recieved one;
+   if doesn't fit - end procedure and go back to scanning,
+   else - connect. */
+for (int i = 0; i < sizeof(predef_uuid); i++) {
+if (parsed_fields.uuids128->value[i] != predef_uuid[i]) {
+MODLOG_DFLT(INFO, "doesn't fit\n");
+return 0;
+}
+}
+
+MODLOG_DFLT(INFO, "UUID ");
+for (int i = 0; i < sizeof(predef_uuid); i++) {
+MODLOG_DFLT(INFO, "%d, ", parsed_fields.uuids128->value[i]);
+}
+MODLOG_DFLT(INFO, "fits, connecting... \n");
+ble_gap_disc_cancel();
+ble_gap_connect(g_own_addr_type, &(event->disc.addr), 1,
+NULL, conn_event, NULL);
+break;
+/* discovery procedure has terminated */
+case BLE_GAP_EVENT_DISC_COMPLETE:
+MODLOG_DFLT(INFO,"Code of termination reason: %d\n",
+event->disc_complete.reason);
+scan();
+break;
+default:
+MODLOG_DFLT(ERROR, "Discovery event not handled\n");
+break;
+}
+

[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410029832
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
 
 Review comment:
   os_time_delay(os_time_ms_to_ticks32(2000)); ?
   Also please write comment why it is here.


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410022133
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
 
 Review comment:
   nitpick: add empty line after declarations


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410024440
 
 

 ##
 File path: apps/central/syscfg.yml
 ##
 @@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Settings this app defines.
+syscfg.defs:
+BLEPRPH_LE_PHY_SUPPORT:
 
 Review comment:
   this seems to be some leftover


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410022355
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
 
 Review comment:
   "fully" not needed :)


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410026121
 
 

 ##
 File path: apps/central/pkg.yml
 ##
 @@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: "apps/central"
+pkg.type: app
+pkg.description: "Basic central application"
+pkg.author: "Krzysztof Kopyściński 

[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410023999
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
+os_time_delay(ticks);
+scan();
+} else {
+MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+event->connect.status);
+}
+break;
+case BLE_GAP_EVENT_DISCONNECT:
+MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+event->disconnect.reason);
 
 Review comment:
   missing break


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410019532
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
+os_time_delay(ticks);
+scan();
+} else {
+MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+event->connect.status);
+}
+break;
+case BLE_GAP_EVENT_DISCONNECT:
+MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+event->disconnect.reason);
+default:
+MODLOG_DFLT(INFO,"Connection event type not supported\n");
+break;
+}
+return 0;
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+struct ble_hs_adv_fields parsed_fields;
+memset(_fields, 0, sizeof(parsed_fields));
+
+/*predef_uuid stores information about UUID of device, that we connect to*/
+const uint8_t predef_uuid[16] = {
+0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
+};
+
+switch (event->type) {
+/* advertising report has been received during discovery procedure */
+case BLE_GAP_EVENT_DISC:
+MODLOG_DFLT(INFO, "Advertising report received! Checking UUID...\n");
+ble_hs_adv_parse_fields(_fields, event->disc.data,
+event->disc.length_data);
+/* Predefined UUID is compared to recieved one;
+   if doesn't fit - end procedure and go back to scanning,
+   else - connect. */
+for (int i = 0; i < sizeof(predef_uuid); i++) {
+if (parsed_fields.uuids128->value[i] != predef_uuid[i]) {
+MODLOG_DFLT(INFO, "doesn't fit\n");
+return 0;
+}
+}
+
+MODLOG_DFLT(INFO, "UUID ");
+for (int i = 0; i < sizeof(predef_uuid); i++) {
+MODLOG_DFLT(INFO, "%d, ", parsed_fields.uuids128->value[i]);
+}
+MODLOG_DFLT(INFO, "fits, connecting... \n");
+ble_gap_disc_cancel();
+ble_gap_connect(g_own_addr_type, &(event->disc.addr), 1,
+NULL, conn_event, NULL);
+break;
+/* discovery procedure has terminated */
+case BLE_GAP_EVENT_DISC_COMPLETE:
+MODLOG_DFLT(INFO,"Code of termination reason: %d\n",
+event->disc_complete.reason);
+scan();
+break;
+default:
+MODLOG_DFLT(ERROR, "Discovery event not handled\n");
+break;
+}
+

[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410024995
 
 

 ##
 File path: nimble/host/include/host/ble_gap.h
 ##
 @@ -1984,6 +1984,8 @@ int ble_gap_set_prefered_default_le_phy(uint8_t 
tx_phys_mask,
  *  - BLE_GAP_LE_PHY_CODED_S8
  *
  * @return   0 on success; nonzero on failure.
+ *
+ * When PHY is successfully changed, phy_updated event is occurs.
 
 Review comment:
   This could go up to the function description.
   
   We can even say what even exactly which is  
BLE_GAP_EVENT_PHY_UPDATE_COMPLETE. 
   
   Also this should go as separate patch


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410020093
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
+os_time_ms_to_ticks(delay_ms, );
+os_time_delay(ticks);
+scan();
+} else {
+MODLOG_DFLT(INFO,"Connection failed, error code: %i\n",
+event->connect.status);
+}
+break;
+case BLE_GAP_EVENT_DISCONNECT:
+MODLOG_DFLT(INFO,"Disconnected, reason code: %i\n",
+event->disconnect.reason);
+default:
+MODLOG_DFLT(INFO,"Connection event type not supported\n");
+break;
+}
+return 0;
+}
+
+static int
+scan_event(struct ble_gap_event *event, void *arg)
+{
+struct ble_hs_adv_fields parsed_fields;
+memset(_fields, 0, sizeof(parsed_fields));
+
+/*predef_uuid stores information about UUID of device, that we connect to*/
+const uint8_t predef_uuid[16] = {
 
 Review comment:
   declarations should be on top as per coding style guidelines


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [mynewt-nimble] rymanluk commented on a change in pull request #796: Apps: central added

2020-04-17 Thread GitBox
rymanluk commented on a change in pull request #796: Apps: central added
URL: https://github.com/apache/mynewt-nimble/pull/796#discussion_r410023741
 
 

 ##
 File path: apps/central/src/main.c
 ##
 @@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "sysinit/sysinit.h"
+#include "os/os.h"
+#include "console/console.h"
+#include "host/ble_hs.h"
+#include "host/util/util.h"
+#include "console/console.h"
+#include "log/log.h"
+
+static uint8_t g_own_addr_type;
+uint32_t delay_ms = 2000;
+os_time_t ticks;
+
+static void
+ble_app_set_addr(void)
+{
+ble_addr_t addr;
+int rc;
+
+/* generate new non-resolvable private address */
+rc = ble_hs_id_gen_rnd(0, );
+assert(rc == 0);
+
+/* set generated address */
+rc = ble_hs_id_set_rnd(addr.val);
+assert(rc == 0);
+}
+
+/* scan_event() calls scan(), so forward declaration is required */
+static void scan(void);
+
+/* connection has separate event handler from scan */
+static int
+conn_event(struct ble_gap_event *event, void *arg)
+{
+int rc;
+switch (event->type) {
+case BLE_GAP_EVENT_CONNECT:
+if (event->connect.status == 0) {
+MODLOG_DFLT(INFO,"Connection was fully established\n");
+/* Set PHY for established conection */
+rc = ble_gap_set_prefered_le_phy(event->connect.conn_handle,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_2M_MASK,
+ BLE_GAP_LE_PHY_CODED_ANY);
+if (rc == 0) {
+MODLOG_DFLT(INFO, "rx and tx PHYs set to 2M\n");
+} else {
+MODLOG_DFLT(INFO, "failed to set rx and tx PHYs\n");
+}
+ble_gap_terminate(event->connect.conn_handle, 0x13);
 
 Review comment:
   not sure what is a purpose of this app, but if we are changing PHY, maybe 
before disconnecting we could wait until PHY is really changed?
   
   BLE_GAP_EVENT_PHY_UPDATE_COMPLETE


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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services