George Djabarov
/
mbed-os-example-mesh-minimal
mbed Open Thread example with nRF52-DK (nRF52840 SoC).
main.cpp@120:e8a17278fb1a, 2019-01-04 (annotated)
- Committer:
- djabi
- Date:
- Fri Jan 04 23:55:03 2019 +0000
- Revision:
- 120:e8a17278fb1a
- Parent:
- 116:b2f0131722a0
Removed unused parts of the example code.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 52:27692043e962 | 1 | /* |
mbed_official | 52:27692043e962 | 2 | * Copyright (c) 2016 ARM Limited. All rights reserved. |
mbed_official | 52:27692043e962 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbed_official | 52:27692043e962 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbed_official | 52:27692043e962 | 5 | * not use this file except in compliance with the License. |
mbed_official | 52:27692043e962 | 6 | * You may obtain a copy of the License at |
mbed_official | 52:27692043e962 | 7 | * |
mbed_official | 52:27692043e962 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 52:27692043e962 | 9 | * |
mbed_official | 52:27692043e962 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 52:27692043e962 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbed_official | 52:27692043e962 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 52:27692043e962 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 52:27692043e962 | 14 | * limitations under the License. |
mbed_official | 52:27692043e962 | 15 | */ |
Seppo Takalo |
0:bde1843b9885 | 16 | #include "mbed.h" |
Seppo Takalo |
0:bde1843b9885 | 17 | #include "rtos.h" |
Seppo Takalo |
0:bde1843b9885 | 18 | #include "NanostackInterface.h" |
mbed_official | 52:27692043e962 | 19 | #include "mbed-trace/mbed_trace.h" |
mbed_official | 72:a7c594402382 | 20 | #include "mesh_nvm.h" |
mbed_official | 52:27692043e962 | 21 | |
mbed_official | 52:27692043e962 | 22 | |
mbed_official | 52:27692043e962 | 23 | void trace_printer(const char* str) { |
mbed_official | 52:27692043e962 | 24 | printf("%s\n", str); |
mbed_official | 52:27692043e962 | 25 | } |
Seppo Takalo |
0:bde1843b9885 | 26 | |
mbed_official | 105:0b691b27144a | 27 | MeshInterface *mesh; |
mbed_official | 16:22f072355a2c | 28 | |
mbed_official | 52:27692043e962 | 29 | static Mutex SerialOutMutex; |
mbed_official | 52:27692043e962 | 30 | |
mbed_official | 97:6dee44085a18 | 31 | void thread_eui64_trace() |
mbed_official | 97:6dee44085a18 | 32 | { |
mbed_official | 97:6dee44085a18 | 33 | uint8_t eui64[8] = {0}; |
mbed_official | 105:0b691b27144a | 34 | static_cast<ThreadInterface*>(mesh)->device_eui64_get(eui64); |
mbed_official | 97:6dee44085a18 | 35 | printf("Device EUI64 address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", eui64[0], eui64[1], eui64[2], eui64[3], eui64[4], eui64[5], eui64[6], eui64[7]); |
mbed_official | 97:6dee44085a18 | 36 | } |
mbed_official | 97:6dee44085a18 | 37 | |
mbed_official | 52:27692043e962 | 38 | void serial_out_mutex_wait() |
mbed_official | 52:27692043e962 | 39 | { |
mbed_official | 52:27692043e962 | 40 | SerialOutMutex.lock(); |
mbed_official | 52:27692043e962 | 41 | } |
mbed_official | 52:27692043e962 | 42 | |
mbed_official | 52:27692043e962 | 43 | void serial_out_mutex_release() |
mbed_official | 52:27692043e962 | 44 | { |
mbed_official | 52:27692043e962 | 45 | SerialOutMutex.unlock(); |
mbed_official | 52:27692043e962 | 46 | } |
mbed_official | 52:27692043e962 | 47 | |
Seppo Takalo |
0:bde1843b9885 | 48 | int main() |
Seppo Takalo |
0:bde1843b9885 | 49 | { |
mbed_official | 52:27692043e962 | 50 | mbed_trace_init(); |
mbed_official | 52:27692043e962 | 51 | mbed_trace_print_function_set(trace_printer); |
mbed_official | 52:27692043e962 | 52 | mbed_trace_mutex_wait_function_set( serial_out_mutex_wait ); |
mbed_official | 52:27692043e962 | 53 | mbed_trace_mutex_release_function_set( serial_out_mutex_release ); |
mbed_official | 105:0b691b27144a | 54 | |
mbed_official | 52:27692043e962 | 55 | printf("Start mesh-minimal application\n"); |
mbed_official | 105:0b691b27144a | 56 | |
mbed_official | 105:0b691b27144a | 57 | #define STR(s) #s |
mbed_official | 105:0b691b27144a | 58 | printf("Build: %s %s\nMesh type: %s\n", __DATE__, __TIME__, STR(MBED_CONF_NSAPI_DEFAULT_MESH_TYPE)); |
mbed_official | 97:6dee44085a18 | 59 | #ifdef MBED_MAJOR_VERSION |
mbed_official | 97:6dee44085a18 | 60 | printf("Mbed OS version: %d.%d.%d\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); |
mbed_official | 97:6dee44085a18 | 61 | #endif |
mbed_official | 4:567d72fb3d84 | 62 | |
mbed_official | 105:0b691b27144a | 63 | mesh = MeshInterface::get_default_instance(); |
mbed_official | 105:0b691b27144a | 64 | if (!mesh) { |
mbed_official | 105:0b691b27144a | 65 | printf("Error! MeshInterface not found!\n"); |
mbed_official | 105:0b691b27144a | 66 | return -1; |
mbed_official | 105:0b691b27144a | 67 | } |
mbed_official | 105:0b691b27144a | 68 | |
mbed_official | 97:6dee44085a18 | 69 | thread_eui64_trace(); |
mbed_official | 72:a7c594402382 | 70 | mesh_nvm_initialize(); |
mbed_official | 97:6dee44085a18 | 71 | printf("Connecting...\n"); |
mbed_official | 105:0b691b27144a | 72 | int error = mesh->connect(); |
mbed_official | 52:27692043e962 | 73 | if (error) { |
mbed_official | 52:27692043e962 | 74 | printf("Connection failed! %d\n", error); |
mbed_official | 52:27692043e962 | 75 | return error; |
Seppo Takalo |
0:bde1843b9885 | 76 | } |
Seppo Takalo |
0:bde1843b9885 | 77 | |
mbed_official | 105:0b691b27144a | 78 | while (NULL == mesh->get_ip_address()) |
mbed_official | 116:b2f0131722a0 | 79 | ThisThread::sleep_for(500); |
mbed_official | 17:ee2610e1cb78 | 80 | |
mbed_official | 105:0b691b27144a | 81 | printf("Connected. IP = %s\n", mesh->get_ip_address()); |
mbed_official | 1:24cff46332de | 82 | } |